[vlc-devel] [PATCH 3/3] d3d11va: use the picture from the decoder pool directly

Steve Lhomme robux4 at videolabs.io
Thu Dec 1 18:04:56 CET 2016


No need to extract into a secondary one to send to the vout and so a
CopySubresourceRegion() for every frame decoded.

--
This code will be activated once the necessary patches are merged in libavcodec
---
 modules/codec/avcodec/d3d11va.c         | 41 +++++++++++++++++++++++++++++++++
 modules/video_output/win32/direct3d11.c |  2 ++
 2 files changed, 43 insertions(+)

diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index d840ba7..ff53247 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -305,6 +305,9 @@ static int Extract(vlc_va_t *va, picture_t *output, uint8_t *data)
                 goto done;
             }
         }
+#endif
+#if !LIBAVCODEC_VERSION_CHECK( 57, 28, 5, 66, 109 )
+#ifdef ID3D11VideoContext_VideoProcessorBlt
         else
 #endif
         {
@@ -328,6 +331,7 @@ static int Extract(vlc_va_t *va, picture_t *output, uint8_t *data)
                                                       viewDesc.Texture2D.ArraySlice,
                                                       &copyBox);
         }
+#endif
     }
         break;
     case VLC_CODEC_YV12:
@@ -370,7 +374,36 @@ static int CheckDevice(vlc_va_t *va)
 
 static int Get(vlc_va_t *va, picture_t *pic, void **data)
 {
+#if LIBAVCODEC_VERSION_CHECK( 57, 28, 5, 66, 109 )
+    picture_sys_t *p_sys = pic->p_sys;
+    if (p_sys->decoder == NULL)
+    {
+        HRESULT hr;
+
+        directx_sys_t *dx_sys = &va->sys->dx_sys;
+
+        D3D11_VIDEO_DECODER_OUTPUT_VIEW_DESC viewDesc;
+        ZeroMemory(&viewDesc, sizeof(viewDesc));
+        viewDesc.DecodeProfile = dx_sys->input;
+        viewDesc.ViewDimension = D3D11_VDOV_DIMENSION_TEXTURE2D;
+        viewDesc.Texture2D.ArraySlice = p_sys->slice_index;
+
+        hr = ID3D11VideoDevice_CreateVideoDecoderOutputView( (ID3D11VideoDevice*) dx_sys->d3ddec,
+                                                             (ID3D11Resource*) p_sys->texture,
+                                                             &viewDesc,
+                                                             &p_sys->decoder );
+        if (FAILED(hr)) {
+            msg_Warn(va, "CreateVideoDecoderOutputView %d failed. (hr=0x%0lx)", p_sys->slice_index, hr);
+            p_sys->decoder = NULL;
+        }
+    }
+    if (p_sys->decoder == NULL)
+        return VLC_EGENERIC;
+    *data = p_sys->decoder;
+    return VLC_SUCCESS;
+#else
     return directx_va_Get(va, &va->sys->dx_sys, pic, data);
+#endif
 }
 
 static void Close(vlc_va_t *va, AVCodecContext *ctx)
@@ -501,7 +534,11 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
     va->description = DxDescribe(dx_sys);
     va->setup   = Setup;
     va->get     = Get;
+#if LIBAVCODEC_VERSION_CHECK( 57, 28, 5, 66, 109 )
+    va->release = NULL;
+#else
     va->release = directx_va_Release;
+#endif
     va->extract = Extract;
 
     return VLC_SUCCESS;
@@ -973,6 +1010,9 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id, const video_forma
 
     if (sys->b_extern_pool)
     {
+#if LIBAVCODEC_VERSION_CHECK( 57, 28, 5, 66, 109 )
+        dx_sys->surface_count = 0;
+#else
         size_t surface_idx;
         for (surface_idx = 0; surface_idx < dx_sys->surface_count; surface_idx++) {
             picture_t *pic = decoder_NewPicture( (decoder_t*) va->obj.parent );
@@ -1038,6 +1078,7 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id, const video_forma
             }
         }
         else
+#endif
             msg_Dbg(va, "using external surface pool");
     }
 
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index 973b8b0..f207a2c 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -639,6 +639,8 @@ static void DestroyDisplayPoolPicture(picture_t *picture)
 {
     picture_sys_t *p_sys = (picture_sys_t*) picture->p_sys;
 
+    if (p_sys->decoder)
+        ID3D11VideoDecoderOutputView_Release(p_sys->decoder);
     if (p_sys->texture)
         ID3D11Texture2D_Release(p_sys->texture);
     if (p_sys->context)
-- 
2.10.1



More information about the vlc-devel mailing list