[vlc-devel] [PATCH 14/14] directx_va: move the DXVA2 loading outside of directx_va

Steve Lhomme robux4 at videolabs.io
Sat Nov 18 14:29:28 CET 2017


For D3D11 the same DLL used to create the device is used to create the decoder.
For DXVA2 we need an extra DLL but we don't need to make this code generic.
---
 modules/codec/avcodec/directx_va.c | 12 ------------
 modules/codec/avcodec/directx_va.h |  4 ----
 modules/codec/avcodec/dxva2.c      | 17 ++++++++++++++---
 3 files changed, 14 insertions(+), 19 deletions(-)

diff --git a/modules/codec/avcodec/directx_va.c b/modules/codec/avcodec/directx_va.c
index 7554604b51..9b4f20cf72 100644
--- a/modules/codec/avcodec/directx_va.c
+++ b/modules/codec/avcodec/directx_va.c
@@ -330,22 +330,10 @@ int directx_va_Setup(vlc_va_t *va, directx_sys_t *dx_sys, const AVCodecContext *
 void directx_va_Close(vlc_va_t *va, directx_sys_t *dx_sys)
 {
     va_pool_Close(va, &dx_sys->va_pool);
-    if (dx_sys->hdecoder_dll)
-        FreeLibrary(dx_sys->hdecoder_dll);
 }
 
 int directx_va_Open(vlc_va_t *va, directx_sys_t *dx_sys)
 {
-    if (dx_sys->psz_decoder_dll) {
-        /* Load dll*/
-        dx_sys->hdecoder_dll = LoadLibrary(dx_sys->psz_decoder_dll);
-        if (!dx_sys->hdecoder_dll) {
-            msg_Warn(va, "cannot load DirectX decoder DLL");
-            goto error;
-        }
-        msg_Dbg(va, "DLLs loaded");
-    }
-
     if (va_pool_Open(va, &dx_sys->va_pool) != VLC_SUCCESS)
         goto error;
 
diff --git a/modules/codec/avcodec/directx_va.h b/modules/codec/avcodec/directx_va.h
index 4219394e53..7dbef97abb 100644
--- a/modules/codec/avcodec/directx_va.h
+++ b/modules/codec/avcodec/directx_va.h
@@ -59,10 +59,6 @@ typedef struct
     /* for pre allocation */
     D3D_DecoderSurface     *hw_surface[MAX_SURFACE_COUNT];
 
-    /* DLL */
-    HINSTANCE             hdecoder_dll;
-    const TCHAR           *psz_decoder_dll;
-
     /* Video service */
     GUID                   input;
     D3D_DecoderDevice      *d3ddec;
diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index fc9a1cae49..f6ecc020e7 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -115,6 +115,9 @@ struct vlc_va_sys_t
     d3d9_handle_t          hd3d;
     d3d9_device_t          d3d_dev;
 
+    /* DLL */
+    HINSTANCE              dxva2_dll;
+
     /* Device manager */
     IDirect3DDeviceManager9  *devmng;
     HANDLE                   device;
@@ -241,6 +244,9 @@ static void Close(vlc_va_t *va, void **ctx)
 
     directx_va_Close(va, &sys->dx_sys);
 
+    if (sys->dxva2_dll)
+        FreeLibrary(sys->dxva2_dll);
+
     free((char *)va->description);
     free(sys);
 }
@@ -266,6 +272,13 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
         goto error;
     }
 
+    /* Load dll*/
+    sys->dxva2_dll = LoadLibrary(TEXT("DXVA2.DLL"));
+    if (!sys->dxva2_dll) {
+        msg_Warn(va, "cannot load DXVA2 decoder DLL");
+        goto error;
+    }
+
     dx_sys = &sys->dx_sys;
 
     dx_sys->va_pool.pf_create_device           = D3dCreateDevice;
@@ -280,7 +293,6 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
     dx_sys->va_pool.pf_new_surface_context     = NewSurfacePicContext;
     dx_sys->pf_get_input_list          = DxGetInputList;
     dx_sys->pf_setup_output            = DxSetupOutput;
-    dx_sys->psz_decoder_dll            = TEXT("DXVA2.DLL");
 
     va->sys = sys;
 
@@ -391,12 +403,11 @@ static char *DxDescribe(vlc_va_sys_t *sys)
 static int D3dCreateDeviceManager(vlc_va_t *va)
 {
     vlc_va_sys_t *sys = va->sys;
-    directx_sys_t *dx_sys = &va->sys->dx_sys;
 
     HRESULT (WINAPI *CreateDeviceManager9)(UINT *pResetToken,
                                            IDirect3DDeviceManager9 **);
     CreateDeviceManager9 =
-      (void *)GetProcAddress(dx_sys->hdecoder_dll,
+      (void *)GetProcAddress(sys->dxva2_dll,
                              "DXVA2CreateDirect3DDeviceManager9");
 
     if (!CreateDeviceManager9) {
-- 
2.14.2



More information about the vlc-devel mailing list