[vlc-commits] directx_va: type the common variables for D3D11VA and DXVA2

Steve Lhomme git at videolan.org
Tue Jun 13 14:59:51 CEST 2017


vlc | branch: master | Steve Lhomme <robux4 at videolabs.io> | Wed May 24 17:39:11 2017 +0200| [b6fae848b413a30570cc4e3498450ab4c88c45bd] | committer: Jean-Baptiste Kempf

directx_va: type the common variables for D3D11VA and DXVA2

This will avoid a lot of casts.

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 modules/codec/avcodec/d3d11va.c    | 78 ++++++++++++++++++++------------------
 modules/codec/avcodec/directx_va.c |  4 ++
 modules/codec/avcodec/directx_va.h |  8 ++--
 modules/codec/avcodec/dxva2.c      | 46 ++++++++++++----------
 4 files changed, 74 insertions(+), 62 deletions(-)

diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index 0b72e43741..1da216ae27 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -43,8 +43,6 @@
 #include <vlc_charset.h>
 #include <vlc_codec.h>
 
-#include "directx_va.h"
-
 #define COBJMACROS
 #include <initguid.h>
 #include <d3d11.h>
@@ -52,6 +50,12 @@
 
 #include "../../video_chroma/d3d11_fmt.h"
 
+#define D3D_Device          ID3D11Device
+#define D3D_DecoderType     ID3D11VideoDecoder
+#define D3D_DecoderDevice   ID3D11VideoDevice
+#define D3D_DecoderSurface  ID3D11VideoDecoderOutputView
+#include "directx_va.h"
+
 static int Open(vlc_va_t *, AVCodecContext *, enum PixelFormat,
                 const es_format_t *, picture_sys_t *p_sys);
 static void Close(vlc_va_t *, AVCodecContext *);
@@ -165,10 +169,10 @@ void SetupAVCodecContext(vlc_va_t *va)
     directx_sys_t *dx_sys = &sys->dx_sys;
 
     sys->hw.video_context = sys->d3dvidctx;
-    sys->hw.decoder = (ID3D11VideoDecoder*) dx_sys->decoder;
+    sys->hw.decoder = dx_sys->decoder;
     sys->hw.cfg = &sys->cfg;
     sys->hw.surface_count = dx_sys->surface_count;
-    sys->hw.surface = (ID3D11VideoDecoderOutputView**) dx_sys->hw_surface;
+    sys->hw.surface = dx_sys->hw_surface;
     sys->hw.context_mutex = sys->context_mutex;
 
     if (IsEqualGUID(&dx_sys->input, &DXVA_Intel_H264_NoFGT_ClearVideo))
@@ -203,11 +207,11 @@ static int Extract(vlc_va_t *va, picture_t *output, uint8_t *data)
                 .ViewDimension = D3D11_VPOV_DIMENSION_TEXTURE2D,
             };
 
-            HRESULT hr = ID3D11VideoDevice_CreateVideoProcessorOutputView((ID3D11VideoDevice*) sys->dx_sys.d3ddec,
+            HRESULT hr = ID3D11VideoDevice_CreateVideoProcessorOutputView(sys->dx_sys.d3ddec,
                                                              p_sys_out->resource[KNOWN_DXGI_INDEX],
                                                              sys->procEnumerator,
                                                              &outDesc,
-                                                             (ID3D11VideoProcessorOutputView**) &p_sys_out->decoder);
+                                                             &p_sys_out->decoder);
             if (FAILED(hr))
             {
                 msg_Err(va, "Failed to create the processor output. (hr=0x%lX)", hr);
@@ -222,7 +226,7 @@ static int Extract(vlc_va_t *va, picture_t *output, uint8_t *data)
         };
 
         HRESULT hr = ID3D11VideoContext_VideoProcessorBlt(sys->d3dvidctx, sys->videoProcessor,
-                                                  (ID3D11VideoProcessorOutputView*) p_sys_out->decoder,
+                                                  p_sys_out->decoder,
                                                   0, 1, &stream);
         if (FAILED(hr))
         {
@@ -319,7 +323,7 @@ static int Get(vlc_va_t *va, picture_t *pic, uint8_t **data)
         viewDesc.ViewDimension = D3D11_VDOV_DIMENSION_TEXTURE2D;
         viewDesc.Texture2D.ArraySlice = p_sys->slice_index;
 
-        hr = ID3D11VideoDevice_CreateVideoDecoderOutputView( (ID3D11VideoDevice*) dx_sys->d3ddec,
+        hr = ID3D11VideoDevice_CreateVideoDecoderOutputView( dx_sys->d3ddec,
                                                              p_sys->resource[KNOWN_DXGI_INDEX],
                                                              &viewDesc,
                                                              &p_sys->decoder );
@@ -425,10 +429,10 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
         if (FAILED(hr)) {
            msg_Err(va, "Could not Query ID3D11VideoDevice Interface from the picture. (hr=0x%lX)", hr);
         } else {
-            ID3D11DeviceContext_GetDevice( p_sys->context, (ID3D11Device**) &dx_sys->d3ddev );
+            ID3D11DeviceContext_GetDevice( p_sys->context, &dx_sys->d3ddev );
             HANDLE context_lock = INVALID_HANDLE_VALUE;
             UINT dataSize = sizeof(context_lock);
-            hr = ID3D11Device_GetPrivateData((ID3D11Device*)dx_sys->d3ddev, &GUID_CONTEXT_MUTEX, &dataSize, &context_lock);
+            hr = ID3D11Device_GetPrivateData(dx_sys->d3ddev, &GUID_CONTEXT_MUTEX, &dataSize, &context_lock);
             if (FAILED(hr))
                 msg_Warn(va, "No mutex found to lock the decoder");
             sys->context_mutex = context_lock;
@@ -517,7 +521,7 @@ static int D3dCreateDevice(vlc_va_t *va)
         msg_Err(va, "D3D11CreateDevice failed. (hr=0x%lX)", hr);
         return VLC_EGENERIC;
     }
-    dx_sys->d3ddev = (IUnknown*) d3ddev;
+    dx_sys->d3ddev = d3ddev;
     va->sys->d3dctx = d3dctx;
 
     ID3D11VideoContext *d3dvidctx = NULL;
@@ -577,7 +581,7 @@ static char *DxDescribe(directx_sys_t *dx_sys)
         { 0, "" }
     };
 
-    IDXGIAdapter *p_adapter = D3D11DeviceAdapter((ID3D11Device*) dx_sys->d3ddev);
+    IDXGIAdapter *p_adapter = D3D11DeviceAdapter(dx_sys->d3ddev);
     if (!p_adapter) {
        return NULL;
     }
@@ -639,7 +643,7 @@ static int D3dCreateDeviceManager(vlc_va_t *va)
     sys->devmng = devmng;
     msg_Info(va, "obtained IDirect3DDeviceManager9");
 
-    HRESULT hr = IDirect3DDeviceManager9_ResetDevice(devmng, (ID3D11Device*) dx_sys->d3ddev, token);
+    HRESULT hr = IDirect3DDeviceManager9_ResetDevice(devmng, dx_sys->d3ddev, token);
     if (FAILED(hr)) {
         msg_Err(va, "IDirect3DDeviceManager9_ResetDevice failed: %08x", (unsigned)hr);
         return VLC_EGENERIC;
@@ -667,12 +671,12 @@ static int DxCreateVideoService(vlc_va_t *va)
     directx_sys_t *dx_sys = &va->sys->dx_sys;
 
     ID3D11VideoDevice *d3dviddev = NULL;
-    HRESULT hr = ID3D11Device_QueryInterface( (ID3D11Device*) dx_sys->d3ddev, &IID_ID3D11VideoDevice, (void **)&d3dviddev);
+    HRESULT hr = ID3D11Device_QueryInterface( dx_sys->d3ddev, &IID_ID3D11VideoDevice, (void **)&d3dviddev);
     if (FAILED(hr)) {
        msg_Err(va, "Could not Query ID3D11VideoDevice Interface. (hr=0x%lX)", hr);
        return VLC_EGENERIC;
     }
-    dx_sys->d3ddec = (IUnknown*) d3dviddev;
+    dx_sys->d3ddec = d3dviddev;
 
     return VLC_SUCCESS;
 }
@@ -695,7 +699,7 @@ static int DxGetInputList(vlc_va_t *va, input_list_t *p_list)
     directx_sys_t *dx_sys = &va->sys->dx_sys;
     HRESULT hr;
 
-    UINT input_count = ID3D11VideoDevice_GetVideoDecoderProfileCount((ID3D11VideoDevice*) dx_sys->d3ddec);
+    UINT input_count = ID3D11VideoDevice_GetVideoDecoderProfileCount(dx_sys->d3ddec);
 
     p_list->count = input_count;
     p_list->list = calloc(input_count, sizeof(*p_list->list));
@@ -705,7 +709,7 @@ static int DxGetInputList(vlc_va_t *va, input_list_t *p_list)
     p_list->pf_release = ReleaseInputList;
 
     for (unsigned i = 0; i < input_count; i++) {
-        hr = ID3D11VideoDevice_GetVideoDecoderProfile((ID3D11VideoDevice*) dx_sys->d3ddec, i, &p_list->list[i]);
+        hr = ID3D11VideoDevice_GetVideoDecoderProfile(dx_sys->d3ddec, i, &p_list->list[i]);
         if (FAILED(hr))
         {
             msg_Err(va, "GetVideoDecoderProfile %d failed. (hr=0x%lX)", i, hr);
@@ -737,7 +741,7 @@ static bool SetupProcessor(vlc_va_t *va, const video_format_t *fmt)
         .OutputHeight = fmt->i_height,
         .Usage = D3D11_VIDEO_USAGE_PLAYBACK_NORMAL,
     };
-    hr = ID3D11VideoDevice_CreateVideoProcessorEnumerator((ID3D11VideoDevice*) dx_sys->d3ddec, &processorDesc, &processorEnumerator);
+    hr = ID3D11VideoDevice_CreateVideoProcessorEnumerator(dx_sys->d3ddec, &processorDesc, &processorEnumerator);
     if ( processorEnumerator == NULL )
     {
         msg_Dbg(va, "Can't get a video processor for the video.");
@@ -770,7 +774,7 @@ static bool SetupProcessor(vlc_va_t *va, const video_format_t *fmt)
         // check if we can create render texture of that format
         // check the decoder can output to that format
         const d3d_format_t *found;
-        found = FindD3D11Format( (ID3D11Device*) dx_sys->d3ddev, 0, 0, true,
+        found = FindD3D11Format( dx_sys->d3ddev, 0, 0, true,
                                  D3D11_FORMAT_SUPPORT_SHADER_LOAD | D3D11_FORMAT_SUPPORT_VIDEO_PROCESSOR_OUTPUT);
         if (found)
             processorOutput = found->formatTexture;
@@ -784,7 +788,7 @@ static bool SetupProcessor(vlc_va_t *va, const video_format_t *fmt)
 
         for (UINT type = 0; type < processorCaps.RateConversionCapsCount; ++type)
         {
-            hr = ID3D11VideoDevice_CreateVideoProcessor((ID3D11VideoDevice*) dx_sys->d3ddec,
+            hr = ID3D11VideoDevice_CreateVideoProcessor(dx_sys->d3ddec,
                                                         processorEnumerator, type, &sys->videoProcessor);
             if (SUCCEEDED(hr))
                 break;
@@ -811,7 +815,7 @@ static int DxSetupOutput(vlc_va_t *va, const GUID *input, const video_format_t *
 #ifndef NDEBUG
     BOOL bSupported = false;
     for (int format = 0; format < 188; format++) {
-        hr = ID3D11VideoDevice_CheckVideoDecoderFormat((ID3D11VideoDevice*) dx_sys->d3ddec, input, format, &bSupported);
+        hr = ID3D11VideoDevice_CheckVideoDecoderFormat(dx_sys->d3ddec, input, format, &bSupported);
         if (SUCCEEDED(hr) && bSupported)
             msg_Dbg(va, "format %s is supported for output", DxgiFormatToStr(format));
     }
@@ -831,7 +835,7 @@ static int DxSetupOutput(vlc_va_t *va, const GUID *input, const video_format_t *
     for (idx = 0; processorInput[idx] != DXGI_FORMAT_UNKNOWN; ++idx)
     {
         BOOL is_supported = false;
-        hr = ID3D11VideoDevice_CheckVideoDecoderFormat((ID3D11VideoDevice*) dx_sys->d3ddec, input, processorInput[idx], &is_supported);
+        hr = ID3D11VideoDevice_CheckVideoDecoderFormat(dx_sys->d3ddec, input, processorInput[idx], &is_supported);
         if (SUCCEEDED(hr) && is_supported)
             msg_Dbg(va, "%s output is supported for decoder %s.", DxgiFormatToStr(processorInput[idx]), psz_decoder_name);
         else
@@ -842,7 +846,7 @@ static int DxSetupOutput(vlc_va_t *va, const GUID *input, const video_format_t *
 
        // check if we can create render texture of that format
        // check the decoder can output to that format
-       if ( !DeviceSupportsFormat((ID3D11Device*) dx_sys->d3ddev, processorInput[idx],
+       if ( !DeviceSupportsFormat(dx_sys->d3ddev, processorInput[idx],
                                   D3D11_FORMAT_SUPPORT_SHADER_LOAD) )
        {
            msg_Dbg(va, "Format %s needs a processor", DxgiFormatToStr(processorInput[idx]));
@@ -863,7 +867,7 @@ static int DxSetupOutput(vlc_va_t *va, const GUID *input, const video_format_t *
         decoderDesc.OutputFormat = processorInput[idx];
 
         UINT cfg_count = 0;
-        hr = ID3D11VideoDevice_GetVideoDecoderConfigCount( (ID3D11VideoDevice*) dx_sys->d3ddec, &decoderDesc, &cfg_count );
+        hr = ID3D11VideoDevice_GetVideoDecoderConfigCount( dx_sys->d3ddec, &decoderDesc, &cfg_count );
         if (FAILED(hr))
         {
             msg_Err( va, "Failed to get configuration for decoder %s. (hr=0x%lX)", psz_decoder_name, hr );
@@ -897,7 +901,7 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id, const video_forma
     HRESULT hr;
 
     ID3D10Multithread *pMultithread;
-    hr = ID3D11Device_QueryInterface( (ID3D11Device*) dx_sys->d3ddev, &IID_ID3D10Multithread, (void **)&pMultithread);
+    hr = ID3D11Device_QueryInterface( dx_sys->d3ddev, &IID_ID3D10Multithread, (void **)&pMultithread);
     if (SUCCEEDED(hr)) {
         ID3D10Multithread_SetMultithreadProtected(pMultithread, TRUE);
         ID3D10Multithread_Release(pMultithread);
@@ -908,7 +912,7 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id, const video_forma
      * crashes totally the device */
     if (codec_id == AV_CODEC_ID_H264 &&
         (dx_sys->surface_width > 2304 || dx_sys->surface_height > 2304) &&
-        isXboxHardware((ID3D11Device*) dx_sys->d3ddev))
+        isXboxHardware(dx_sys->d3ddev))
     {
         msg_Warn(va, "%dx%d resolution not supported by your hardware", dx_sys->surface_width, dx_sys->surface_height);
         dx_sys->surface_count = 0;
@@ -961,7 +965,7 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id, const video_forma
 #endif
 
             viewDesc.Texture2D.ArraySlice = pic->p_sys->slice_index;
-            hr = ID3D11VideoDevice_CreateVideoDecoderOutputView( (ID3D11VideoDevice*) dx_sys->d3ddec,
+            hr = ID3D11VideoDevice_CreateVideoDecoderOutputView( dx_sys->d3ddec,
                                                                  pic->p_sys->resource[KNOWN_DXGI_INDEX],
                                                                  &viewDesc,
                                                                  &pic->p_sys->decoder );
@@ -1011,7 +1015,7 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id, const video_forma
         texDesc.CPUAccessFlags = 0;
 
         ID3D11Texture2D *p_texture;
-        hr = ID3D11Device_CreateTexture2D( (ID3D11Device*) dx_sys->d3ddev, &texDesc, NULL, &p_texture );
+        hr = ID3D11Device_CreateTexture2D( dx_sys->d3ddev, &texDesc, NULL, &p_texture );
         if (FAILED(hr)) {
             msg_Err(va, "CreateTexture2D %d failed. (hr=0x%0lx)", dx_sys->surface_count, hr);
             dx_sys->surface_count = 0;
@@ -1023,10 +1027,10 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id, const video_forma
             sys->extern_pics[dx_sys->surface_count] = NULL;
             viewDesc.Texture2D.ArraySlice = dx_sys->surface_count;
 
-            hr = ID3D11VideoDevice_CreateVideoDecoderOutputView( (ID3D11VideoDevice*) dx_sys->d3ddec,
+            hr = ID3D11VideoDevice_CreateVideoDecoderOutputView( dx_sys->d3ddec,
                                                                  (ID3D11Resource*) p_texture,
                                                                  &viewDesc,
-                                                                 (ID3D11VideoDecoderOutputView**) &dx_sys->hw_surface[dx_sys->surface_count] );
+                                                                 &dx_sys->hw_surface[dx_sys->surface_count] );
             if (FAILED(hr)) {
                 msg_Err(va, "CreateVideoDecoderOutputView %d failed. (hr=0x%0lx)", dx_sys->surface_count, hr);
                 ID3D11Texture2D_Release(p_texture);
@@ -1045,7 +1049,7 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id, const video_forma
     decoderDesc.OutputFormat = sys->render;
 
     UINT cfg_count;
-    hr = ID3D11VideoDevice_GetVideoDecoderConfigCount( (ID3D11VideoDevice*) dx_sys->d3ddec, &decoderDesc, &cfg_count );
+    hr = ID3D11VideoDevice_GetVideoDecoderConfigCount( dx_sys->d3ddec, &decoderDesc, &cfg_count );
     if (FAILED(hr)) {
         msg_Err(va, "GetVideoDecoderConfigCount failed. (hr=0x%lX)", hr);
         return VLC_EGENERIC;
@@ -1054,7 +1058,7 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id, const video_forma
     /* List all configurations available for the decoder */
     D3D11_VIDEO_DECODER_CONFIG cfg_list[cfg_count];
     for (unsigned i = 0; i < cfg_count; i++) {
-        hr = ID3D11VideoDevice_GetVideoDecoderConfig( (ID3D11VideoDevice*) dx_sys->d3ddec, &decoderDesc, i, &cfg_list[i] );
+        hr = ID3D11VideoDevice_GetVideoDecoderConfig( dx_sys->d3ddec, &decoderDesc, i, &cfg_list[i] );
         if (FAILED(hr)) {
             msg_Err(va, "GetVideoDecoderConfig failed. (hr=0x%lX)", hr);
             return VLC_EGENERIC;
@@ -1095,13 +1099,13 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id, const video_forma
 
     /* Create the decoder */
     ID3D11VideoDecoder *decoder;
-    hr = ID3D11VideoDevice_CreateVideoDecoder( (ID3D11VideoDevice*) dx_sys->d3ddec, &decoderDesc, &sys->cfg, &decoder );
+    hr = ID3D11VideoDevice_CreateVideoDecoder( dx_sys->d3ddec, &decoderDesc, &sys->cfg, &decoder );
     if (FAILED(hr)) {
         msg_Err(va, "ID3D11VideoDevice_CreateVideoDecoder failed. (hr=0x%lX)", hr);
         dx_sys->decoder = NULL;
         return VLC_EGENERIC;
     }
-    dx_sys->decoder = (IUnknown*) decoder;
+    dx_sys->decoder = decoder;
 
     msg_Dbg(va, "DxCreateDecoderSurfaces succeed");
     return VLC_SUCCESS;
@@ -1112,7 +1116,7 @@ static void DxDestroySurfaces(vlc_va_t *va)
     directx_sys_t *dx_sys = &va->sys->dx_sys;
     if (dx_sys->surface_count && !va->sys->b_extern_pool) {
         ID3D11Resource *p_texture;
-        ID3D11VideoDecoderOutputView_GetResource( (ID3D11VideoDecoderOutputView*) dx_sys->hw_surface[0], &p_texture );
+        ID3D11VideoDecoderOutputView_GetResource( dx_sys->hw_surface[0], &p_texture );
         ID3D11Resource_Release(p_texture);
         ID3D11Resource_Release(p_texture);
     }
@@ -1138,7 +1142,7 @@ static picture_t *DxAllocPicture(vlc_va_t *va, const video_format_t *fmt, unsign
     if (unlikely(pic_sys == NULL))
         return NULL;
 
-    pic_sys->decoder  = (ID3D11VideoDecoderOutputView*) sys->dx_sys.hw_surface[index];
+    pic_sys->decoder = sys->dx_sys.hw_surface[index];
     ID3D11VideoDecoderOutputView_GetResource(pic_sys->decoder, &pic_sys->resource[KNOWN_DXGI_INDEX]);
     pic_sys->context  = sys->d3dctx;
 
@@ -1151,7 +1155,7 @@ static picture_t *DxAllocPicture(vlc_va_t *va, const video_format_t *fmt, unsign
             .Texture2D.ArraySlice = index,
         };
 
-        HRESULT hr = ID3D11VideoDevice_CreateVideoProcessorInputView((ID3D11VideoDevice*) sys->dx_sys.d3ddec,
+        HRESULT hr = ID3D11VideoDevice_CreateVideoProcessorInputView(sys->dx_sys.d3ddec,
                                                         pic_sys->resource[KNOWN_DXGI_INDEX],
                                                         sys->procEnumerator,
                                                         &inDesc,
diff --git a/modules/codec/avcodec/directx_va.c b/modules/codec/avcodec/directx_va.c
index 4c86ad10a5..2a4c3e4868 100644
--- a/modules/codec/avcodec/directx_va.c
+++ b/modules/codec/avcodec/directx_va.c
@@ -36,6 +36,10 @@
 
 #define COBJMACROS
 
+#define D3D_Device          IUnknown
+#define D3D_DecoderType     IUnknown
+#define D3D_DecoderDevice   IUnknown
+#define D3D_DecoderSurface  IUnknown
 #include "directx_va.h"
 
 #include "avcodec.h"
diff --git a/modules/codec/avcodec/directx_va.h b/modules/codec/avcodec/directx_va.h
index 8bc296550e..be139ad06f 100644
--- a/modules/codec/avcodec/directx_va.h
+++ b/modules/codec/avcodec/directx_va.h
@@ -67,14 +67,14 @@ typedef struct
     const TCHAR           *psz_decoder_dll;
 
     /* Direct3D */
-    IUnknown              *d3ddev;
+    D3D_Device            *d3ddev;
 
     /* Video service */
     GUID                   input;
-    IUnknown               *d3ddec;
+    D3D_DecoderDevice      *d3ddec;
 
     /* Video decoder */
-    IUnknown               *decoder;
+    D3D_DecoderType        *decoder;
 
     /* */
     int          surface_count;
@@ -86,7 +86,7 @@ typedef struct
 
     vlc_mutex_t      surface_lock;
     vlc_va_surface_t surface[MAX_SURFACE_COUNT];
-    IUnknown         *hw_surface[MAX_SURFACE_COUNT];
+    D3D_DecoderSurface  *hw_surface[MAX_SURFACE_COUNT];
 
     /**
      * Check that the decoder device is still available
diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index ff87d3a693..74ee567466 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -33,13 +33,17 @@
 #include <vlc_picture.h>
 #include <vlc_plugin.h>
 
-#include "directx_va.h"
-
 #define DXVA2API_USE_BITFIELDS
 #define COBJMACROS
 #include <libavcodec/dxva2.h>
 #include "../../video_chroma/d3d9_fmt.h"
 
+#define D3D_Device          IDirect3DDevice9
+#define D3D_DecoderType     IDirectXVideoDecoder
+#define D3D_DecoderDevice   IDirectXVideoDecoderService
+#define D3D_DecoderSurface  IDirect3DSurface9
+#include "directx_va.h"
+
 static int Open(vlc_va_t *, AVCodecContext *, enum PixelFormat,
                 const es_format_t *, picture_sys_t *p_sys);
 static void Close(vlc_va_t *, AVCodecContext *);
@@ -163,10 +167,10 @@ void SetupAVCodecContext(vlc_va_t *va)
     vlc_va_sys_t *sys = va->sys;
     directx_sys_t *dx_sys = &sys->dx_sys;
 
-    sys->hw.decoder = (IDirectXVideoDecoder*) dx_sys->decoder;
+    sys->hw.decoder = dx_sys->decoder;
     sys->hw.cfg = &sys->cfg;
     sys->hw.surface_count = dx_sys->surface_count;
-    sys->hw.surface = (LPDIRECT3DSURFACE9*) dx_sys->hw_surface;
+    sys->hw.surface = dx_sys->hw_surface;
 
     if (IsEqualGUID(&dx_sys->input, &DXVA_Intel_H264_NoFGT_ClearVideo))
         sys->hw.workaround |= FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO;
@@ -193,7 +197,7 @@ static int Extract(vlc_va_t *va, picture_t *picture, uint8_t *data)
     visibleSource.top = 0;
     visibleSource.right = picture->format.i_visible_width;
     visibleSource.bottom = picture->format.i_visible_height;
-    hr = IDirect3DDevice9_StretchRect( (IDirect3DDevice9*) dx_sys->d3ddev, d3d, &visibleSource, output, &visibleSource, D3DTEXF_NONE);
+    hr = IDirect3DDevice9_StretchRect( dx_sys->d3ddev, d3d, &visibleSource, output, &visibleSource, D3DTEXF_NONE);
     if (FAILED(hr)) {
         msg_Err(va, "Failed to copy the hw surface to the decoder surface (hr=0x%0lx)", hr );
         return VLC_EGENERIC;
@@ -308,7 +312,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
         D3DSURFACE_DESC src;
         if (SUCCEEDED(IDirect3DSurface9_GetDesc(p_sys->surface, &src)))
             sys->render = src.Format;
-        IDirect3DSurface9_GetDevice(p_sys->surface, (IDirect3DDevice9**) &dx_sys->d3ddev );
+        IDirect3DSurface9_GetDevice(p_sys->surface, &dx_sys->d3ddev );
     }
 
     sys->i_chroma = d3d9va_fourcc(ctx->sw_pix_fmt);
@@ -402,7 +406,7 @@ static int D3dCreateDevice(vlc_va_t *va)
         msg_Err(va, "IDirect3D9_CreateDevice failed");
         return VLC_EGENERIC;
     }
-    sys->dx_sys.d3ddev = (IUnknown*) d3ddev;
+    sys->dx_sys.d3ddev = d3ddev;
 
     return VLC_SUCCESS;
 }
@@ -478,7 +482,7 @@ static int D3dCreateDeviceManager(vlc_va_t *va)
     sys->devmng = devmng;
     msg_Info(va, "obtained IDirect3DDeviceManager9");
 
-    HRESULT hr = IDirect3DDeviceManager9_ResetDevice(devmng, (IDirect3DDevice9*) dx_sys->d3ddev, token);
+    HRESULT hr = IDirect3DDeviceManager9_ResetDevice(devmng, dx_sys->d3ddev, token);
     if (FAILED(hr)) {
         msg_Err(va, "IDirect3DDeviceManager9_ResetDevice failed: %08x", (unsigned)hr);
         return VLC_EGENERIC;
@@ -555,7 +559,7 @@ static int DxGetInputList(vlc_va_t *va, input_list_t *p_list)
     directx_sys_t *dx_sys = &va->sys->dx_sys;
     UINT input_count = 0;
     GUID *input_list = NULL;
-    if (FAILED(IDirectXVideoDecoderService_GetDecoderDeviceGuids((IDirectXVideoDecoderService*) dx_sys->d3ddec,
+    if (FAILED(IDirectXVideoDecoderService_GetDecoderDeviceGuids(dx_sys->d3ddec,
                                                                  &input_count,
                                                                  &input_list))) {
         msg_Err(va, "IDirectXVideoDecoderService_GetDecoderDeviceGuids failed");
@@ -574,7 +578,7 @@ static int DxSetupOutput(vlc_va_t *va, const GUID *input, const video_format_t *
     int err = VLC_EGENERIC;
     UINT      output_count = 0;
     D3DFORMAT *output_list = NULL;
-    if (FAILED(IDirectXVideoDecoderService_GetDecoderRenderTargets((IDirectXVideoDecoderService*) va->sys->dx_sys.d3ddec,
+    if (FAILED(IDirectXVideoDecoderService_GetDecoderRenderTargets(va->sys->dx_sys.d3ddec,
                                                                    input,
                                                                    &output_count,
                                                                    &output_list))) {
@@ -628,7 +632,7 @@ static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id, const video_format_t
     directx_sys_t *sys = &va->sys->dx_sys;
     HRESULT hr;
 
-    hr = IDirectXVideoDecoderService_CreateSurface((IDirectXVideoDecoderService*) sys->d3ddec,
+    hr = IDirectXVideoDecoderService_CreateSurface(sys->d3ddec,
                                                          sys->surface_width,
                                                          sys->surface_height,
                                                          sys->surface_count - 1,
@@ -636,7 +640,7 @@ static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id, const video_format_t
                                                          D3DPOOL_DEFAULT,
                                                          0,
                                                          DXVA2_VideoDecoderRenderTarget,
-                                                         (LPDIRECT3DSURFACE9*) sys->hw_surface,
+                                                         sys->hw_surface,
                                                          NULL);
     if (FAILED(hr)) {
         msg_Err(va, "IDirectXVideoAccelerationService_CreateSurface %d failed (hr=0x%0lx)", sys->surface_count - 1, hr);
@@ -647,7 +651,7 @@ static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id, const video_format_t
             sys->surface_count, sys->surface_width, sys->surface_height);
 
     IDirect3DSurface9 *tstCrash;
-    hr = IDirectXVideoDecoderService_CreateSurface((IDirectXVideoDecoderService*) sys->d3ddec,
+    hr = IDirectXVideoDecoderService_CreateSurface(sys->d3ddec,
                                                          sys->surface_width,
                                                          sys->surface_height,
                                                          0,
@@ -660,7 +664,7 @@ static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id, const video_format_t
     if (FAILED(hr)) {
         msg_Err(va, "extra buffer impossible, avoid a crash (hr=0x%0lx)", hr);
         for (int i = 0; i < sys->surface_count; i++)
-            IDirect3DSurface9_Release( (IDirect3DSurface9*) sys->hw_surface[i] );
+            IDirect3DSurface9_Release( sys->hw_surface[i] );
         sys->surface_count = 0;
         return VLC_EGENERIC;
     }
@@ -696,7 +700,7 @@ static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id, const video_format_t
     /* List all configurations available for the decoder */
     UINT                      cfg_count = 0;
     DXVA2_ConfigPictureDecode *cfg_list = NULL;
-    if (FAILED(IDirectXVideoDecoderService_GetDecoderConfigurations((IDirectXVideoDecoderService*) sys->d3ddec,
+    if (FAILED(IDirectXVideoDecoderService_GetDecoderConfigurations(sys->d3ddec,
                                                                     &sys->input,
                                                                     &dsc,
                                                                     NULL,
@@ -704,7 +708,7 @@ static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id, const video_format_t
                                                                     &cfg_list))) {
         msg_Err(va, "IDirectXVideoDecoderService_GetDecoderConfigurations failed");
         for (int i = 0; i < sys->surface_count; i++)
-            IDirect3DSurface9_Release( (IDirect3DSurface9*) sys->hw_surface[i] );
+            IDirect3DSurface9_Release( sys->hw_surface[i] );
         sys->surface_count = 0;
         return VLC_EGENERIC;
     }
@@ -743,20 +747,20 @@ static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id, const video_format_t
 
     /* Create the decoder */
     IDirectXVideoDecoder *decoder;
-    if (FAILED(IDirectXVideoDecoderService_CreateVideoDecoder((IDirectXVideoDecoderService*) sys->d3ddec,
+    if (FAILED(IDirectXVideoDecoderService_CreateVideoDecoder(sys->d3ddec,
                                                               &sys->input,
                                                               &dsc,
                                                               &p_sys->cfg,
-                                                              (LPDIRECT3DSURFACE9*) sys->hw_surface,
+                                                              sys->hw_surface,
                                                               sys->surface_count,
                                                               &decoder))) {
         msg_Err(va, "IDirectXVideoDecoderService_CreateVideoDecoder failed");
         for (int i = 0; i < sys->surface_count; i++)
-            IDirect3DSurface9_Release( (IDirect3DSurface9*) sys->hw_surface[i] );
+            IDirect3DSurface9_Release( sys->hw_surface[i] );
         sys->surface_count = 0;
         return VLC_EGENERIC;
     }
-    sys->decoder = (IUnknown*) decoder;
+    sys->decoder = decoder;
 
     msg_Dbg(va, "IDirectXVideoDecoderService_CreateVideoDecoder succeed");
     return VLC_SUCCESS;
@@ -780,7 +784,7 @@ static picture_t *DxAllocPicture(vlc_va_t *va, const video_format_t *fmt, unsign
     picture_sys_t *pic_sys = calloc(1, sizeof(*pic_sys));
     if (unlikely(pic_sys == NULL))
         return NULL;
-    pic_sys->surface = (LPDIRECT3DSURFACE9) va->sys->dx_sys.hw_surface[index];
+    pic_sys->surface = va->sys->dx_sys.hw_surface[index];
 
     picture_resource_t res = {
         .p_sys = pic_sys,



More information about the vlc-commits mailing list