[vlc-devel] [PATCH 25/31] decoder: get the vlc_video_context created by the VA

Steve Lhomme robux4 at ycbcr.xyz
Fri Jul 5 16:20:04 CEST 2019


For now they don't create one so we use the default one.
---
 modules/codec/avcodec/d3d11va.c | 5 +++--
 modules/codec/avcodec/dxva2.c   | 5 +++--
 modules/codec/avcodec/va.c      | 8 +++++---
 modules/codec/avcodec/va.h      | 2 ++
 modules/codec/avcodec/vaapi.c   | 3 ++-
 modules/codec/avcodec/video.c   | 7 +++++++
 modules/hw/vdpau/avcodec.c      | 3 ++-
 7 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index c18bd23983..3ee0c5d1b7 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -59,7 +59,7 @@ typedef picture_sys_d3d11_t VA_PICSYS;
 #include "directx_va.h"
 
 static int Open(vlc_va_t *, AVCodecContext *, enum PixelFormat,
-                const es_format_t *, vlc_decoder_device *, picture_sys_d3d11_t *p_sys);
+                const es_format_t *, vlc_decoder_device *, vlc_video_context **, picture_sys_d3d11_t *p_sys);
 static void Close(vlc_va_t *, void **);
 
 vlc_module_begin()
@@ -310,7 +310,8 @@ static void Close(vlc_va_t *va, void **ctx)
 }
 
 static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
-                const es_format_t *fmt, vlc_decoder_device *dec_device, picture_sys_d3d11_t *p_sys)
+                const es_format_t *fmt, vlc_decoder_device *dec_device,
+                vlc_video_context **vctx_out, picture_sys_d3d11_t *p_sys)
 {
     int err = VLC_EGENERIC;
     directx_sys_t *dx_sys;
diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index a94ca6eaca..28e6405ab3 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -47,7 +47,7 @@ typedef picture_sys_d3d9_t VA_PICSYS;
 #include "directx_va.h"
 
 static int Open(vlc_va_t *, AVCodecContext *, enum PixelFormat,
-                const es_format_t *, vlc_decoder_device *, picture_sys_d3d9_t *p_sys);
+                const es_format_t *, vlc_decoder_device *, vlc_video_context **, picture_sys_d3d9_t *p_sys);
 static void Close(vlc_va_t *, void **);
 
 vlc_module_begin()
@@ -256,7 +256,8 @@ static void Close(vlc_va_t *va, void **ctx)
 }
 
 static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
-                const es_format_t *fmt, vlc_decoder_device *dec_device, picture_sys_d3d9_t *p_sys)
+                const es_format_t *fmt, vlc_decoder_device *dec_device,
+                vlc_video_context **vctx_out, picture_sys_d3d9_t *p_sys)
 {
     int err = VLC_EGENERIC;
     directx_sys_t *dx_sys;
diff --git a/modules/codec/avcodec/va.c b/modules/codec/avcodec/va.c
index f0d2005cbf..df7edc79ce 100644
--- a/modules/codec/avcodec/va.c
+++ b/modules/codec/avcodec/va.c
@@ -96,12 +96,13 @@ static int vlc_va_Start(void *func, bool forced, va_list ap)
     enum PixelFormat pix_fmt = va_arg(ap, enum PixelFormat);
     const es_format_t *fmt = va_arg(ap, const es_format_t *);
     vlc_decoder_device *device = va_arg(ap, vlc_decoder_device *);
+    vlc_video_context **vctx_out = va_arg(ap, vlc_video_context **);
     void *p_sys = va_arg(ap, void *);
     int (*open)(vlc_va_t *, AVCodecContext *, enum PixelFormat,
-                const es_format_t *, vlc_decoder_device *, void *) = func;
+                const es_format_t *, vlc_decoder_device *, vlc_video_context **, void *) = func;
 
     (void) forced;
-    return open(va, ctx, pix_fmt, fmt, device, p_sys);
+    return open(va, ctx, pix_fmt, fmt, device, vctx_out, p_sys);
 }
 
 static void vlc_va_Stop(void *func, va_list ap)
@@ -121,6 +122,7 @@ struct vlc_va_priv {
 vlc_va_t *vlc_va_New(vlc_object_t *obj, AVCodecContext *avctx,
                      enum PixelFormat pix_fmt, const es_format_t *fmt,
                      vlc_decoder_device *device,
+                     vlc_video_context **vctx_out,
                      void *sys)
 {
     struct vlc_va_priv *priv = vlc_object_create(obj, sizeof (*priv));
@@ -131,7 +133,7 @@ vlc_va_t *vlc_va_New(vlc_object_t *obj, AVCodecContext *avctx,
     char *modlist = var_InheritString(obj, "avcodec-hw");
 
     priv->module = vlc_module_load(va, "hw decoder", modlist, true,
-                                   vlc_va_Start, va, avctx, pix_fmt, fmt, device, sys);
+                                   vlc_va_Start, va, avctx, pix_fmt, fmt, device, vctx_out, sys);
     free(modlist);
     if (priv->module == NULL)
     {
diff --git a/modules/codec/avcodec/va.h b/modules/codec/avcodec/va.h
index 6b9d99d818..dc49b743a9 100644
--- a/modules/codec/avcodec/va.h
+++ b/modules/codec/avcodec/va.h
@@ -49,11 +49,13 @@ vlc_fourcc_t vlc_va_GetChroma(enum PixelFormat hwfmt, enum PixelFormat swfmt);
  * @param obj parent VLC object
  * @param fmt VLC format of the content to decode
  * @param device use to create the decoder context
+ * @param vctx_out the video context created by the VA [OUT]
  * @return a new VLC object on success, NULL on error.
  */
 vlc_va_t *vlc_va_New(vlc_object_t *obj, AVCodecContext *,
                      enum PixelFormat, const es_format_t *fmt,
                      vlc_decoder_device *device,
+                     vlc_video_context **vctx_out,
                      void *p_sys);
 
 /**
diff --git a/modules/codec/avcodec/vaapi.c b/modules/codec/avcodec/vaapi.c
index da90ddd1ab..ba18a2c01b 100644
--- a/modules/codec/avcodec/vaapi.c
+++ b/modules/codec/avcodec/vaapi.c
@@ -146,7 +146,8 @@ static void Delete(vlc_va_t *va, void *hwctx)
 }
 
 static int Create(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
-                  const es_format_t *fmt, vlc_decoder_device *device, void *p_sys)
+                  const es_format_t *fmt, vlc_decoder_device *device,
+                  vlc_video_context **vctx_out, void *p_sys)
 {
     if (pix_fmt != AV_PIX_FMT_VAAPI_VLD || p_sys == NULL)
         return VLC_EGENERIC;
diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c
index a2d7755c1e..9949c2e01e 100644
--- a/modules/codec/avcodec/video.c
+++ b/modules/codec/avcodec/video.c
@@ -1674,6 +1674,12 @@ static enum PixelFormat ffmpeg_GetFormat( AVCodecContext *p_context,
         }
 
 no_reuse:
+    if ( p_dec->vctx_out )
+    {
+        vlc_video_context_Release( p_dec->vctx_out );
+        p_dec->vctx_out = NULL;
+    }
+
     if (p_sys->p_va != NULL)
     {
         msg_Err(p_dec, "existing hardware acceleration cannot be reused");
@@ -1739,6 +1745,7 @@ no_reuse:
         vlc_va_t *va = vlc_va_New(VLC_OBJECT(p_dec), p_context, hwfmt,
                                   &p_dec->fmt_in,
                                   p_dec->init_device,
+                                  &p_dec->vctx_out,
                                   test_pic ? test_pic->p_sys : NULL);
         if (test_pic)
             picture_Release(test_pic);
diff --git a/modules/hw/vdpau/avcodec.c b/modules/hw/vdpau/avcodec.c
index 2f9df8fd4d..59f8b0b749 100644
--- a/modules/hw/vdpau/avcodec.c
+++ b/modules/hw/vdpau/avcodec.c
@@ -118,7 +118,8 @@ static int Lock(vlc_va_t *va, picture_t *pic, uint8_t **data)
 }
 
 static int Open(vlc_va_t *va, AVCodecContext *avctx, enum PixelFormat pix_fmt,
-                const es_format_t *fmt, vlc_decoder_device *device, void *p_sys)
+                const es_format_t *fmt, vlc_decoder_device *device,
+                vlc_video_context **vctx_out, void *p_sys)
 {
     if (pix_fmt != AV_PIX_FMT_VDPAU)
         return VLC_EGENERIC;
-- 
2.17.1



More information about the vlc-devel mailing list