[vlc-commits] dxva2: use the d3d9_device_t from the decoder device

Steve Lhomme git at videolan.org
Thu Nov 21 13:51:20 CET 2019


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Thu Nov 21 10:18:24 2019 +0100| [4d8254e0c2daa0a54bc2fb86e404b3898779a3d1] | committer: Steve Lhomme

dxva2: use the d3d9_device_t from the decoder device

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

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

diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index b67e9cefa0..8180d9373a 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -113,8 +113,6 @@ static const d3d9_format_t *D3dFindFormat(D3DFORMAT format)
 struct vlc_va_sys_t
 {
     /* Direct3D */
-    d3d9_device_t          d3d_dev;
-
     vlc_video_context      *vctx;
 
     /* DLL */
@@ -259,6 +257,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, const AVPixFmtDescriptor *des
     d3d9_decoder_device_t *d3d9_decoder = GetD3D9OpaqueDevice( dec_device );
     if ( d3d9_decoder == NULL )
         return VLC_EGENERIC;
+    assert(d3d9_decoder->d3ddev.dev != NULL); // coming from the decoder device
 
     ctx->hwaccel_context = NULL;
 
@@ -266,23 +265,15 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, const AVPixFmtDescriptor *des
     if (unlikely(sys == NULL))
         return VLC_ENOMEM;
 
-    HRESULT hr = D3D9_CreateDevice(va, &d3d9_decoder->hd3d, d3d9_decoder->d3ddev.adapterId, &sys->d3d_dev);
-    if ( FAILED(hr) )
-    {
-        free( sys );
-        return VLC_EGENERIC;
-    }
-
     sys->vctx = vlc_video_context_Create( dec_device, VLC_VIDEO_CONTEXT_DXVA2,
                                           sizeof(d3d9_video_context_t), &d3d9_vctx_ops );
     if (likely(sys->vctx == NULL))
     {
-        D3D9_ReleaseDevice(&sys->d3d_dev);
         free( sys );
         return VLC_EGENERIC;
     }
     d3d9_video_context_t *octx = GetD3D9ContextPrivate(sys->vctx);
-    octx->dev = sys->d3d_dev.dev;
+    octx->dev = d3d9_decoder->d3ddev.dev;
     IDirect3DDevice9_AddRef(octx->dev);
 
     va->sys = sys;
@@ -340,7 +331,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, const AVPixFmtDescriptor *des
 
     D3DADAPTER_IDENTIFIER9 d3dai;
     if (SUCCEEDED(IDirect3D9_GetAdapterIdentifier(d3d9_decoder->hd3d.obj,
-                                               sys->d3d_dev.adapterId, 0, &d3dai))) {
+                                               d3d9_decoder->d3ddev.adapterId, 0, &d3dai))) {
         msg_Info(va, "Using DXVA2 (%.*s, vendor %s(%lx), device %lx, revision %lx)",
                     (int)sizeof(d3dai.Description), d3dai.Description,
                     DxgiVendorStr(d3dai.VendorId), d3dai.VendorId, d3dai.DeviceId, d3dai.Revision);
@@ -366,7 +357,7 @@ static int D3dCreateDevice(vlc_va_t *va)
 {
     vlc_va_sys_t *sys = va->sys;
 
-    assert(sys->d3d_dev.dev); // coming from the decoder device
+    d3d9_decoder_device_t *d3d9_decoder = GetD3D9OpaqueContext(sys->vctx);
 
     HRESULT (WINAPI *CreateDeviceManager9)(UINT *pResetToken,
                                            IDirect3DDeviceManager9 **);
@@ -387,7 +378,7 @@ static int D3dCreateDevice(vlc_va_t *va)
     }
     msg_Dbg(va, "obtained IDirect3DDeviceManager9");
 
-    HRESULT hr = IDirect3DDeviceManager9_ResetDevice(sys->devmng, sys->d3d_dev.dev, token);
+    HRESULT hr = IDirect3DDeviceManager9_ResetDevice(sys->devmng, d3d9_decoder->d3ddev.dev, token);
     if (FAILED(hr)) {
         msg_Err(va, "IDirect3DDeviceManager9_ResetDevice failed: 0x%lX)", hr);
         IDirect3DDeviceManager9_Release(sys->devmng);
@@ -446,7 +437,7 @@ static int DxSetupOutput(vlc_va_t *va, const directx_va_mode_t *mode, const vide
     d3d9_decoder_device_t *d3d9_decoder = GetD3D9OpaqueContext(sys->vctx);
 
     D3DADAPTER_IDENTIFIER9 identifier;
-    HRESULT hr = IDirect3D9_GetAdapterIdentifier(d3d9_decoder->hd3d.obj, sys->d3d_dev.adapterId, 0, &identifier);
+    HRESULT hr = IDirect3D9_GetAdapterIdentifier(d3d9_decoder->hd3d.obj, d3d9_decoder->d3ddev.adapterId, 0, &identifier);
     if (FAILED(hr))
         return VLC_EGENERIC;
 
@@ -662,7 +653,6 @@ static void DxDestroyVideoDecoder(void *opaque)
     IDirect3DDeviceManager9_CloseDeviceHandle(sys->devmng, sys->device);
     IDirectXVideoDecoderService_Release(sys->d3ddec);
     IDirect3DDeviceManager9_Release(sys->devmng);
-    D3D9_ReleaseDevice(&sys->d3d_dev);
     if (sys->dxva2_dll)
         FreeLibrary(sys->dxva2_dll);
 



More information about the vlc-commits mailing list