[vlc-commits] avcodec: va: allow the VA to provide pictures directly
Steve Lhomme
git at videolan.org
Mon Oct 21 15:11:31 CEST 2019
vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Mon Jun 17 16:06:48 2019 +0200| [2e4cd8756db3b396ddedbd7d622ebd67122a34e0] | committer: Steve Lhomme
avcodec: va: allow the VA to provide pictures directly
Instead of filling the picture context during get().
We can't just allocate the picture in the generic VA code and fill
the picture->context and picsys data as we need to handle the destructor
for each picture and release the resources when the picture is last
released.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2e4cd8756db3b396ddedbd7d622ebd67122a34e0
---
modules/codec/avcodec/d3d11va.c | 2 +-
modules/codec/avcodec/dxva2.c | 2 +-
modules/codec/avcodec/va.h | 11 +++++++++++
modules/codec/avcodec/vaapi.c | 2 +-
modules/codec/avcodec/video.c | 5 ++++-
modules/hw/vdpau/avcodec.c | 2 +-
6 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index c0e419e9b5..265408dce1 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -251,7 +251,7 @@ static void Close(vlc_va_t *va)
vlc_video_context_Release(sys->vctx);
}
-static const struct vlc_va_operations ops = { Get, Close, };
+static const struct vlc_va_operations ops = { Get, NULL, Close, };
static int Open(vlc_va_t *va, AVCodecContext *ctx, const AVPixFmtDescriptor *desc,
enum PixelFormat pix_fmt,
diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index 6b632b28a9..d50b887cf5 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -244,7 +244,7 @@ static void Close(vlc_va_t *va)
vlc_video_context_Release(sys->vctx);
}
-static const struct vlc_va_operations ops = { Get, Close, };
+static const struct vlc_va_operations ops = { Get, NULL, Close, };
static int Open(vlc_va_t *va, AVCodecContext *ctx, const AVPixFmtDescriptor *desc,
enum PixelFormat pix_fmt,
diff --git a/modules/codec/avcodec/va.h b/modules/codec/avcodec/va.h
index b10cab7e0b..d139d608b8 100644
--- a/modules/codec/avcodec/va.h
+++ b/modules/codec/avcodec/va.h
@@ -33,6 +33,7 @@ typedef struct vlc_video_context vlc_video_context;
struct vlc_va_operations {
int (*get)(vlc_va_t *, picture_t *pic, uint8_t **surface);
+ picture_t *(*get_picture)(vlc_va_t *, const video_format_t *);
void (*close)(vlc_va_t *);
};
@@ -97,6 +98,16 @@ static inline int vlc_va_Get(vlc_va_t *va, picture_t *pic, uint8_t **surface)
return va->ops->get(va, pic, surface);
}
+/**
+ * Can be called from any thread
+ */
+static inline picture_t *vlc_va_GetPicture(vlc_va_t *va, const video_format_t *fmt)
+{
+ if (va->ops->get_picture)
+ return va->ops->get_picture(va, fmt);
+ return NULL;
+}
+
/**
* Destroys a libavcodec hardware acceleration back-end.
* All allocated surfaces shall have been released beforehand.
diff --git a/modules/codec/avcodec/vaapi.c b/modules/codec/avcodec/vaapi.c
index d6fd893b45..df7260a8ec 100644
--- a/modules/codec/avcodec/vaapi.c
+++ b/modules/codec/avcodec/vaapi.c
@@ -146,7 +146,7 @@ static void Delete(vlc_va_t *va)
free(sys);
}
-static const struct vlc_va_operations ops = { Get, Delete, };
+static const struct vlc_va_operations ops = { Get, NULL /* TODO */, Delete, };
static int Create(vlc_va_t *va, AVCodecContext *ctx, const AVPixFmtDescriptor *desc,
enum PixelFormat pix_fmt,
diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c
index 0c0b539cdc..d1d331800e 100644
--- a/modules/codec/avcodec/video.c
+++ b/modules/codec/avcodec/video.c
@@ -1471,7 +1471,10 @@ static int lavc_va_GetFrame(struct AVCodecContext *ctx, AVFrame *frame)
decoder_sys_t *p_sys = dec->p_sys;
vlc_va_t *va = p_sys->p_va;
- picture_t *pic = decoder_NewPicture(dec);
+ picture_t *pic;
+ pic = vlc_va_GetPicture(va, &dec->fmt_out.video);
+ if (pic == NULL)
+ pic = decoder_NewPicture(dec);
if (pic == NULL)
return -1;
diff --git a/modules/hw/vdpau/avcodec.c b/modules/hw/vdpau/avcodec.c
index ae10789249..f7cca8efa8 100644
--- a/modules/hw/vdpau/avcodec.c
+++ b/modules/hw/vdpau/avcodec.c
@@ -133,7 +133,7 @@ static void Close(vlc_va_t *va)
free(sys);
}
-static const struct vlc_va_operations ops = { Lock, Close, };
+static const struct vlc_va_operations ops = { Lock, NULL, Close, };
static int Open(vlc_va_t *va, AVCodecContext *avctx, const AVPixFmtDescriptor *desc,
enum PixelFormat pix_fmt,
More information about the vlc-commits
mailing list