[vlc-commits] dxva: don't store the external pool flag in the dxva helper

Steve Lhomme git at videolan.org
Mon Sep 2 15:43:17 CEST 2019


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Mon Sep  2 09:44:21 2019 +0200| [b06db7571789d6143eb744651dc4bb5b8ec4ee8b] | committer: Steve Lhomme

dxva: don't store the external pool flag in the dxva helper

It's only used with D3D11VA and will go away with push.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b06db7571789d6143eb744651dc4bb5b8ec4ee8b
---

 modules/codec/avcodec/d3d11va.c             | 28 ++++++++++-----------
 modules/codec/avcodec/directx_va.c          |  2 +-
 modules/codec/avcodec/directx_va.h          |  1 -
 modules/codec/avcodec/dxva2.c               | 39 +++++++++++++----------------
 modules/codec/avcodec/va_surface.c          |  8 +++---
 modules/codec/avcodec/va_surface_internal.h |  4 ++-
 6 files changed, 38 insertions(+), 44 deletions(-)

diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index 8ffbbd8f51..676c90b3b2 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -138,14 +138,12 @@ static int DxCreateDecoderSurfaces(vlc_va_t *, int codec_id,
                                    const video_format_t *fmt, unsigned surface_count);
 static void DxDestroySurfaces(vlc_va_sys_t *);
 
-static void SetupAVCodecContext(vlc_va_sys_t *sys)
+static void SetupAVCodecContext(vlc_va_sys_t *sys, unsigned surfaces)
 {
-    directx_sys_t *dx_sys = &sys->dx_sys;
-
     sys->hw.video_context = sys->d3dvidctx;
     sys->hw.decoder = sys->dxdecoder;
     sys->hw.cfg = &sys->cfg;
-    sys->hw.surface_count = dx_sys->va_pool.surface_count;
+    sys->hw.surface_count = surfaces;
     sys->hw.surface = sys->hw_surface;
     sys->hw.context_mutex = sys->d3d_dev.context_mutex;
 
@@ -249,7 +247,7 @@ static int Get(vlc_va_t *va, picture_t *pic, uint8_t **data)
     vlc_va_sys_t *sys = va->sys;
     picture_sys_d3d11_t *p_sys = pic->p_sys;
 #if D3D11_DIRECT_DECODE
-    if (sys->dx_sys.can_extern_pool)
+    if (sys->dx_sys.va_pool.can_extern_pool)
     {
         /* copy the original picture_sys_d3d11_t in the va_pic_context */
         if (!pic->context)
@@ -623,7 +621,7 @@ static int DxSetupOutput(vlc_va_t *va, const GUID *input, const video_format_t *
         if ( sys->render == processorInput[idx] && sys->totalTextureSlices > 4)
         {
             if (CanUseVoutPool(&sys->d3d_dev, sys->totalTextureSlices))
-                dx_sys->can_extern_pool = true;
+                dx_sys->va_pool.can_extern_pool = true;
             else
                 msg_Warn( va, "use internal pool" );
         }
@@ -685,7 +683,7 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id,
     {
         msg_Dbg(va, "mismatching external pool sizes use the internal one %dx%d vs %dx%d",
                 sys->textureWidth, sys->textureHeight, fmt->i_width, fmt->i_height);
-        dx_sys->can_extern_pool = false;
+        dx_sys->va_pool.can_extern_pool = false;
         sys->textureWidth  = fmt->i_width;
         sys->textureHeight = fmt->i_height;
     }
@@ -693,7 +691,7 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id,
     {
         msg_Warn(va, "not enough decoding slices in the texture (%d/%d)",
                  sys->totalTextureSlices, surface_count);
-        dx_sys->can_extern_pool = false;
+        dx_sys->va_pool.can_extern_pool = false;
     }
 #if VLC_WINSTORE_APP
     /* On the Xbox 1/S, any decoding of H264 with one dimension over 2304
@@ -729,7 +727,7 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id,
         return VLC_EGENERIC;
     }
 
-    if (dx_sys->can_extern_pool)
+    if (dx_sys->va_pool.can_extern_pool)
     {
 #if !D3D11_DIRECT_DECODE
         size_t surface_idx;
@@ -740,7 +738,7 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id,
             if (pic==NULL)
             {
                 msg_Warn(va, "not enough decoder pictures %d out of %d", surface_idx, surface_count);
-                dx_sys->can_extern_pool = false;
+                dx_sys->va_pool.can_extern_pool = false;
                 break;
             }
 
@@ -755,7 +753,7 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id,
             {
                 msg_Warn(va, "d3d11va requires decoding slices to be the first in the texture (%d/%d)",
                          p_sys->slice_index, surface_idx);
-                dx_sys->can_extern_pool = false;
+                dx_sys->va_pool.can_extern_pool = false;
                 break;
             }
 #endif
@@ -767,7 +765,7 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id,
                                                                  &p_sys->decoder );
             if (FAILED(hr)) {
                 msg_Warn(va, "CreateVideoDecoderOutputView %d failed. (hr=0x%lX)", surface_idx, hr);
-                dx_sys->can_extern_pool = false;
+                dx_sys->va_pool.can_extern_pool = false;
                 break;
             }
 
@@ -776,7 +774,7 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id,
             sys->hw_surface[surface_idx] = p_sys->decoder;
         }
 
-        if (!dx_sys->can_extern_pool)
+        if (!dx_sys->va_pool.can_extern_pool)
         {
             for (size_t i = 0; i < surface_idx; ++i)
             {
@@ -799,7 +797,7 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id,
             msg_Dbg(va, "using external surface pool");
     }
 
-    if (!dx_sys->can_extern_pool)
+    if (!dx_sys->va_pool.can_extern_pool)
     {
         D3D11_TEXTURE2D_DESC texDesc;
         ZeroMemory(&texDesc, sizeof(texDesc));
@@ -923,7 +921,7 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id,
 static void DxDestroySurfaces(vlc_va_sys_t *sys)
 {
     directx_sys_t *dx_sys = &sys->dx_sys;
-    if (dx_sys->va_pool.surface_count && !dx_sys->can_extern_pool) {
+    if (dx_sys->va_pool.surface_count && !dx_sys->va_pool.can_extern_pool) {
         ID3D11Resource *p_texture;
         ID3D11VideoDecoderOutputView_GetResource( sys->hw_surface[0], &p_texture );
         ID3D11Resource_Release(p_texture);
diff --git a/modules/codec/avcodec/directx_va.c b/modules/codec/avcodec/directx_va.c
index 768b048953..918813af93 100644
--- a/modules/codec/avcodec/directx_va.c
+++ b/modules/codec/avcodec/directx_va.c
@@ -326,7 +326,7 @@ int directx_va_Setup(vlc_va_t *va, directx_sys_t *dx_sys, const AVCodecContext *
     int err = va_pool_SetupDecoder(va, &dx_sys->va_pool, avctx, surface_count, surface_alignment);
     if (err != VLC_SUCCESS)
         return err;
-    if (dx_sys->can_extern_pool)
+    if (dx_sys->va_pool.can_extern_pool)
         return VLC_SUCCESS;
     return va_pool_SetupSurfaces(va, &dx_sys->va_pool, surface_count);
 }
diff --git a/modules/codec/avcodec/directx_va.h b/modules/codec/avcodec/directx_va.h
index 000ea907a4..962b6753ed 100644
--- a/modules/codec/avcodec/directx_va.h
+++ b/modules/codec/avcodec/directx_va.h
@@ -53,7 +53,6 @@ typedef struct input_list_t {
 typedef struct
 {
     va_pool_t             va_pool;
-    bool                  can_extern_pool;
 
     /**
      * Read the list of possible input GUIDs
diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index ef88bee6f6..f2136f71fc 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -147,13 +147,11 @@ static int DxCreateVideoDecoder(vlc_va_t *, int codec_id,
                                 const video_format_t *, unsigned surface_count);
 static void DxDestroyVideoDecoder(vlc_va_sys_t *);
 
-static void SetupAVCodecContext(vlc_va_sys_t *sys)
+static void SetupAVCodecContext(vlc_va_sys_t *sys, unsigned surfaces)
 {
-    directx_sys_t *dx_sys = &sys->dx_sys;
-
     sys->hw.decoder = sys->dxdecoder;
     sys->hw.cfg = &sys->cfg;
-    sys->hw.surface_count = dx_sys->va_pool.surface_count;
+    sys->hw.surface_count = surfaces;
     sys->hw.surface = sys->hw_surface;
 
     if (IsEqualGUID(&sys->decoder_guid, &DXVA_Intel_H264_NoFGT_ClearVideo))
@@ -524,19 +522,18 @@ static int DxSetupOutput(vlc_va_t *va, const GUID *input, const video_format_t *
 static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id,
                                 const video_format_t *fmt, unsigned surface_count)
 {
-    vlc_va_sys_t *p_sys = va->sys;
-    directx_sys_t *sys = &p_sys->dx_sys;
+    vlc_va_sys_t *sys = va->sys;
     HRESULT hr;
 
-    hr = IDirectXVideoDecoderService_CreateSurface(p_sys->d3ddec,
+    hr = IDirectXVideoDecoderService_CreateSurface(sys->d3ddec,
                                                          fmt->i_width,
                                                          fmt->i_height,
                                                          surface_count - 1,
-                                                         p_sys->render,
+                                                         sys->render,
                                                          D3DPOOL_DEFAULT,
                                                          0,
                                                          DXVA2_VideoDecoderRenderTarget,
-                                                         p_sys->hw_surface,
+                                                         sys->hw_surface,
                                                          NULL);
     if (FAILED(hr)) {
         msg_Err(va, "IDirectXVideoAccelerationService_CreateSurface %d failed (hr=0x%lX)", surface_count - 1, hr);
@@ -546,11 +543,11 @@ static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id,
             surface_count, fmt->i_width, fmt->i_height);
 
     IDirect3DSurface9 *tstCrash;
-    hr = IDirectXVideoDecoderService_CreateSurface(p_sys->d3ddec,
+    hr = IDirectXVideoDecoderService_CreateSurface(sys->d3ddec,
                                                          fmt->i_width,
                                                          fmt->i_height,
                                                          0,
-                                                         p_sys->render,
+                                                         sys->render,
                                                          D3DPOOL_DEFAULT,
                                                          0,
                                                          DXVA2_VideoDecoderRenderTarget,
@@ -567,7 +564,7 @@ static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id,
     ZeroMemory(&dsc, sizeof(dsc));
     dsc.SampleWidth     = fmt->i_width;
     dsc.SampleHeight    = fmt->i_height;
-    dsc.Format          = p_sys->render;
+    dsc.Format          = sys->render;
     if (fmt->i_frame_rate > 0 && fmt->i_frame_rate_base > 0) {
         dsc.InputSampleFreq.Numerator   = fmt->i_frame_rate;
         dsc.InputSampleFreq.Denominator = fmt->i_frame_rate_base;
@@ -592,8 +589,8 @@ static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id,
     /* List all configurations available for the decoder */
     UINT                      cfg_count = 0;
     DXVA2_ConfigPictureDecode *cfg_list = NULL;
-    hr = IDirectXVideoDecoderService_GetDecoderConfigurations(p_sys->d3ddec,
-                                                              &p_sys->decoder_guid,
+    hr = IDirectXVideoDecoderService_GetDecoderConfigurations(sys->d3ddec,
+                                                              &sys->decoder_guid,
                                                               &dsc,
                                                               NULL,
                                                               &cfg_count,
@@ -625,7 +622,7 @@ static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id,
             score += 16;
 
         if (cfg_score < score) {
-            p_sys->cfg = *cfg;
+            sys->cfg = *cfg;
             cfg_score = score;
         }
     }
@@ -637,13 +634,13 @@ static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id,
 
     /* Create the decoder */
     /* adds a reference on each decoder surface */
-    if (FAILED(IDirectXVideoDecoderService_CreateVideoDecoder(p_sys->d3ddec,
-                                                              &p_sys->decoder_guid,
+    if (FAILED(IDirectXVideoDecoderService_CreateVideoDecoder(sys->d3ddec,
+                                                              &sys->decoder_guid,
                                                               &dsc,
-                                                              &p_sys->cfg,
-                                                              p_sys->hw_surface,
+                                                              &sys->cfg,
+                                                              sys->hw_surface,
                                                               surface_count,
-                                                              &p_sys->dxdecoder))) {
+                                                              &sys->hw.decoder))) {
         msg_Err(va, "IDirectXVideoDecoderService_CreateVideoDecoder failed");
         goto error;
     }
@@ -652,7 +649,7 @@ static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id,
     return VLC_SUCCESS;
 error:
     for (unsigned i = 0; i < surface_count; i++)
-        IDirect3DSurface9_Release( p_sys->hw_surface[i] );
+        IDirect3DSurface9_Release( sys->hw_surface[i] );
     return VLC_EGENERIC;
 }
 
diff --git a/modules/codec/avcodec/va_surface.c b/modules/codec/avcodec/va_surface.c
index 88fe55ba90..6311d39491 100644
--- a/modules/codec/avcodec/va_surface.c
+++ b/modules/codec/avcodec/va_surface.c
@@ -107,7 +107,7 @@ int va_pool_SetupDecoder(vlc_va_t *va, va_pool_t *va_pool, const AVCodecContext
 done:
     va_pool->surface_count = i;
     if (err == VLC_SUCCESS)
-        va_pool->callbacks->pf_setup_avcodec_ctx(va->sys);
+        va_pool->callbacks->pf_setup_avcodec_ctx(va->sys, count);
 
     return err;
 }
@@ -115,9 +115,8 @@ done:
 int va_pool_SetupSurfaces(vlc_va_t *va, va_pool_t *va_pool, unsigned count)
 {
     int err = VLC_ENOMEM;
-    unsigned i = va_pool->surface_count;
 
-    for (i = 0; i < count; i++) {
+    for (unsigned i = 0; i < va_pool->surface_count; i++) {
         struct vlc_va_surface_t *p_surface = malloc(sizeof(*p_surface));
         if (unlikely(p_surface==NULL))
             goto done;
@@ -133,9 +132,8 @@ int va_pool_SetupSurfaces(vlc_va_t *va, va_pool_t *va_pool, unsigned count)
     err = VLC_SUCCESS;
 
 done:
-    va_pool->surface_count = i;
     if (err == VLC_SUCCESS)
-        va_pool->callbacks->pf_setup_avcodec_ctx(va->sys);
+        va_pool->callbacks->pf_setup_avcodec_ctx(va->sys, count);
 
     return err;
 }
diff --git a/modules/codec/avcodec/va_surface_internal.h b/modules/codec/avcodec/va_surface_internal.h
index ed379901cf..efbf772eb3 100644
--- a/modules/codec/avcodec/va_surface_internal.h
+++ b/modules/codec/avcodec/va_surface_internal.h
@@ -45,6 +45,8 @@ typedef struct
 
     const struct va_pool_cfg *callbacks;
 
+    bool                  can_extern_pool;
+
 } va_pool_t;
 
 struct va_pool_cfg {
@@ -64,7 +66,7 @@ struct va_pool_cfg {
     /**
      * Set the avcodec hw context after the decoder is created
      */
-    void (*pf_setup_avcodec_ctx)(vlc_va_sys_t *);
+    void (*pf_setup_avcodec_ctx)(vlc_va_sys_t *, unsigned surfaces);
 
     /**
      * Create a new context for the surface being acquired



More information about the vlc-commits mailing list