[vlc-devel] [PATCH 29/31] dxva2: create a video context for the VA

Steve Lhomme robux4 at ycbcr.xyz
Mon Sep 23 17:01:34 CEST 2019


---
 modules/codec/avcodec/dxva2.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index b13e339fc32..1e7b165e5a1 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -110,6 +110,8 @@ struct vlc_va_sys_t
     d3d9_handle_t          hd3d;
     d3d9_device_t          d3d_dev;
 
+    vlc_video_context      *vctx;
+
     /* DLL */
     HINSTANCE              dxva2_dll;
 
@@ -235,6 +237,9 @@ static void Close(vlc_va_t *va)
 
     va_pool_Close(va, &sys->va_pool);
 
+    if (sys->vctx)
+        vlc_video_context_Release(sys->vctx);
+
     if (sys->dxva2_dll)
         FreeLibrary(sys->dxva2_dll);
 
@@ -261,13 +266,18 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
     d3d9_decoder_device_t *d3d9_decoder = GetD3D9OpaqueDevice( dec_device );
     if ( d3d9_decoder != NULL )
     {
-        D3D9_CloneExternal(&sys->hd3d, d3d9_decoder->device);
-        HRESULT hr = D3D9_CreateDevice(va, &sys->hd3d, d3d9_decoder->adapter, &sys->d3d_dev);
-        if ( FAILED(hr) )
+        sys->vctx = vlc_video_context_Create( dec_device, 0, NULL );
+        if (likely(sys->vctx != NULL))
         {
-            D3D9_Destroy(&sys->hd3d);
-            free( sys );
-            return VLC_EGENERIC;
+            D3D9_CloneExternal(&sys->hd3d, d3d9_decoder->device);
+            HRESULT hr = D3D9_CreateDevice(va, &sys->hd3d, d3d9_decoder->adapter, &sys->d3d_dev);
+            if ( FAILED(hr) )
+            {
+                vlc_video_context_Release(sys->vctx);
+                D3D9_Destroy(&sys->hd3d);
+                free( sys );
+                return VLC_EGENERIC;
+            }
         }
     }
     else if (D3D9_Create(va, &sys->hd3d) != VLC_SUCCESS) {
@@ -280,6 +290,8 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
     sys->dxva2_dll = LoadLibrary(TEXT("DXVA2.DLL"));
     if (!sys->dxva2_dll) {
         msg_Warn(va, "cannot load DXVA2 decoder DLL");
+        if (sys->vctx)
+            vlc_video_context_Release(sys->vctx);
         D3D9_Destroy( &sys->hd3d );
         free( sys );
         return VLC_EGENERIC;
@@ -321,9 +333,12 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
     ctx->hwaccel_context = &sys->hw;
 
     va->ops = &ops;
+    *vtcx_out = sys->vctx;
     return VLC_SUCCESS;
 
 error:
+    if (sys->vctx)
+        vlc_video_context_Release(sys->vctx);
     Close(va);
     return VLC_EGENERIC;
 }
-- 
2.17.1



More information about the vlc-devel mailing list