[vlc-devel] [PATCH 14/23] directx_va: don't pass the AVCodecContext and es_format_t to directx_va_Open

Steve Lhomme robux4 at videolabs.io
Wed Jun 21 14:14:59 CEST 2017


Only to directx_va_Setup (and va_pool_Setup)
---
 modules/codec/avcodec/d3d11va.c             |  8 +++++---
 modules/codec/avcodec/directx_va.c          | 31 +++++++++++++++--------------
 modules/codec/avcodec/directx_va.h          |  4 ++--
 modules/codec/avcodec/dxva2.c               |  6 ++++--
 modules/codec/avcodec/va_surface.c          |  6 ++----
 modules/codec/avcodec/va_surface_internal.h |  6 ++----
 6 files changed, 31 insertions(+), 30 deletions(-)

diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index 1ffd4a97e6..923266c741 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -355,6 +355,8 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
     int err = VLC_EGENERIC;
     directx_sys_t *dx_sys;
 
+    ctx->hwaccel_context = NULL;
+
     if (pix_fmt != AV_PIX_FMT_D3D11VA_VLD)
         return VLC_EGENERIC;
 
@@ -412,14 +414,14 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
     sys->i_chroma = d3d11va_fourcc(ctx->sw_pix_fmt);
 
 #if VLC_WINSTORE_APP
-    err = directx_va_Open(va, &sys->dx_sys, ctx, fmt, false);
+    err = directx_va_Open(va, &sys->dx_sys, false);
 #else
-    err = directx_va_Open(va, &sys->dx_sys, ctx, fmt, dx_sys->d3ddev == NULL || va->sys->d3dctx == NULL);
+    err = directx_va_Open(va, &sys->dx_sys, dx_sys->d3ddev == NULL || va->sys->d3dctx == NULL);
 #endif
     if (err!=VLC_SUCCESS)
         goto error;
 
-    err = directx_va_Setup(va, &sys->dx_sys, ctx);
+    err = directx_va_Setup(va, &sys->dx_sys, ctx, fmt);
     if (err != VLC_SUCCESS)
         goto error;
 
diff --git a/modules/codec/avcodec/directx_va.c b/modules/codec/avcodec/directx_va.c
index d40f285733..d68368e6fc 100644
--- a/modules/codec/avcodec/directx_va.c
+++ b/modules/codec/avcodec/directx_va.c
@@ -159,7 +159,7 @@ DEFINE_GUID(DXVA_ModeVP9_VLD_Profile0,              0x463707f8, 0xa1d0, 0x4585,
 typedef struct {
     const char   *name;
     const GUID   *guid;
-    int          codec;
+    enum AVCodecID codec;
     const int    *p_profiles; // NULL or ends with 0
 } directx_va_mode_t;
 
@@ -261,7 +261,7 @@ static const directx_va_mode_t DXVA_MODES[] = {
     { NULL, NULL, 0, NULL }
 };
 
-static int FindVideoServiceConversion(vlc_va_t *, directx_sys_t *, const es_format_t *fmt);
+static int FindVideoServiceConversion(vlc_va_t *, directx_sys_t *, const es_format_t *, const AVCodecContext *);
 
 char *directx_va_GetDecoderName(const GUID *guid)
 {
@@ -277,12 +277,19 @@ char *directx_va_GetDecoderName(const GUID *guid)
 }
 
 /* */
-int directx_va_Setup(vlc_va_t *va, directx_sys_t *dx_sys, AVCodecContext *avctx)
+int directx_va_Setup(vlc_va_t *va, directx_sys_t *dx_sys, const AVCodecContext *avctx,
+                     const es_format_t *fmt)
 {
+    /* */
+    if (FindVideoServiceConversion(va, dx_sys, fmt, avctx)) {
+        msg_Err(va, "FindVideoServiceConversion failed");
+        return VLC_EGENERIC;
+    }
+
     int surface_alignment = 16;
     unsigned surface_count = 2;
 
-    switch ( dx_sys->va_pool.codec_id )
+    switch ( avctx->codec_id )
     {
     case AV_CODEC_ID_MPEG2VIDEO:
         /* decoding MPEG-2 requires additional alignment on some Intel GPUs,
@@ -317,8 +324,7 @@ void directx_va_Close(vlc_va_t *va, directx_sys_t *dx_sys)
         FreeLibrary(dx_sys->hdecoder_dll);
 }
 
-int directx_va_Open(vlc_va_t *va, directx_sys_t *dx_sys,
-                    AVCodecContext *ctx, const es_format_t *fmt, bool b_dll)
+int directx_va_Open(vlc_va_t *va, directx_sys_t *dx_sys, bool b_dll)
 {
     if (b_dll) {
         /* Load dll*/
@@ -330,15 +336,9 @@ int directx_va_Open(vlc_va_t *va, directx_sys_t *dx_sys,
         msg_Dbg(va, "DLLs loaded");
     }
 
-    if (va_pool_Open(va, &dx_sys->va_pool, ctx) != VLC_SUCCESS)
+    if (va_pool_Open(va, &dx_sys->va_pool) != VLC_SUCCESS)
         goto error;
 
-    /* */
-    if (FindVideoServiceConversion(va, dx_sys, fmt)) {
-        msg_Err(va, "FindVideoServiceConversion failed");
-        goto error;
-    }
-
     return VLC_SUCCESS;
 
 error:
@@ -381,7 +381,8 @@ static bool profile_supported(const directx_va_mode_t *mode, const es_format_t *
 /**
  * Find the best suited decoder mode GUID and render format.
  */
-static int FindVideoServiceConversion(vlc_va_t *va, directx_sys_t *dx_sys, const es_format_t *fmt)
+static int FindVideoServiceConversion(vlc_va_t *va, directx_sys_t *dx_sys,
+                                      const es_format_t *fmt, const AVCodecContext *avctx)
 {
     input_list_t p_list = { 0 };
     int err = dx_sys->pf_get_input_list(va, &p_list);
@@ -404,7 +405,7 @@ static int FindVideoServiceConversion(vlc_va_t *va, directx_sys_t *dx_sys, const
     /* Try all supported mode by our priority */
     const directx_va_mode_t *mode = DXVA_MODES;
     for (; mode->name; ++mode) {
-        if (!mode->codec || mode->codec != dx_sys->va_pool.codec_id)
+        if (!mode->codec || mode->codec != avctx->codec_id)
             continue;
 
         /* */
diff --git a/modules/codec/avcodec/directx_va.h b/modules/codec/avcodec/directx_va.h
index 43a40a1af8..4aa872f3ce 100644
--- a/modules/codec/avcodec/directx_va.h
+++ b/modules/codec/avcodec/directx_va.h
@@ -81,9 +81,9 @@ typedef struct
 
 } directx_sys_t;
 
-int directx_va_Open(vlc_va_t *, directx_sys_t *, AVCodecContext *ctx, const es_format_t *fmt, bool b_dll);
+int directx_va_Open(vlc_va_t *, directx_sys_t *, bool b_dll);
 void directx_va_Close(vlc_va_t *, directx_sys_t *);
-int directx_va_Setup(vlc_va_t *, directx_sys_t *, AVCodecContext *avctx);
+int directx_va_Setup(vlc_va_t *, directx_sys_t *, const AVCodecContext *avctx, const es_format_t *);
 char *directx_va_GetDecoderName(const GUID *guid);
 
 #endif /* AVCODEC_DIRECTX_VA_H */
diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index a9e83f48b7..b793cb6c42 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -294,6 +294,8 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
     if (pix_fmt != AV_PIX_FMT_DXVA2_VLD)
         return VLC_EGENERIC;
 
+    ctx->hwaccel_context = NULL;
+
     vlc_va_sys_t *sys = calloc(1, sizeof (*sys));
     if (unlikely(sys == NULL))
         return VLC_ENOMEM;
@@ -334,11 +336,11 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
 
     sys->i_chroma = d3d9va_fourcc(ctx->sw_pix_fmt);
 
-    err = directx_va_Open(va, &sys->dx_sys, ctx, fmt, true);
+    err = directx_va_Open(va, &sys->dx_sys, true);
     if (err!=VLC_SUCCESS)
         goto error;
 
-    err = directx_va_Setup(va, &sys->dx_sys, ctx);
+    err = directx_va_Setup(va, &sys->dx_sys, ctx, fmt);
     if (err != VLC_SUCCESS)
         goto error;
 
diff --git a/modules/codec/avcodec/va_surface.c b/modules/codec/avcodec/va_surface.c
index e7e65ab30e..324a823d5d 100644
--- a/modules/codec/avcodec/va_surface.c
+++ b/modules/codec/avcodec/va_surface.c
@@ -48,7 +48,7 @@ static void DestroyVideoDecoder(vlc_va_t *va, va_pool_t *va_pool)
 }
 
 /* */
-int va_pool_Setup(vlc_va_t *va, va_pool_t *va_pool, AVCodecContext *avctx, unsigned count, int alignment)
+int va_pool_Setup(vlc_va_t *va, va_pool_t *va_pool, const AVCodecContext *avctx, unsigned count, int alignment)
 {
     int err = VLC_ENOMEM;
     unsigned i = va_pool->surface_count;
@@ -169,10 +169,8 @@ void va_pool_Close(vlc_va_t *va, va_pool_t *va_pool)
     va_pool->pf_destroy_device(va);
 }
 
-int va_pool_Open(vlc_va_t *va, va_pool_t *va_pool, AVCodecContext *ctx)
+int va_pool_Open(vlc_va_t *va, va_pool_t *va_pool)
 {
-    va_pool->codec_id = ctx->codec_id;
-
     /* */
     if (va_pool->pf_create_device(va)) {
         msg_Err(va, "Failed to create device");
diff --git a/modules/codec/avcodec/va_surface_internal.h b/modules/codec/avcodec/va_surface_internal.h
index 9b8223f45e..caa3679590 100644
--- a/modules/codec/avcodec/va_surface_internal.h
+++ b/modules/codec/avcodec/va_surface_internal.h
@@ -35,8 +35,6 @@
 #define MAX_SURFACE_COUNT (64)
 typedef struct
 {
-    int          codec_id;
-
     /* */
     unsigned     surface_count;
     int          surface_width;
@@ -76,9 +74,9 @@ typedef struct
 
 } va_pool_t;
 
-int va_pool_Open(vlc_va_t *, va_pool_t *, AVCodecContext *);
+int va_pool_Open(vlc_va_t *, va_pool_t *);
 void va_pool_Close(vlc_va_t *va, va_pool_t *);
-int va_pool_Setup(vlc_va_t *, va_pool_t *, AVCodecContext *, unsigned count, int alignment);
+int va_pool_Setup(vlc_va_t *, va_pool_t *, const AVCodecContext *, unsigned count, int alignment);
 int va_pool_Get(vlc_va_t *, picture_t *, va_pool_t *);
 void va_surface_AddRef(vlc_va_surface_t *surface);
 void va_surface_Release(vlc_va_surface_t *surface);
-- 
2.12.1



More information about the vlc-devel mailing list