[vlc-devel] [PATCH 30/31] d3d11va: store the ID3D11DeviceContext in the video context

Steve Lhomme robux4 at ycbcr.xyz
Fri Jul 5 16:20:09 CEST 2019


We might store a reference to the VA module so the destructor of the module is
not called while the video context is used.
---
 include/vlc_picture.h            |  2 +-
 modules/codec/avcodec/d3d11va.c  | 12 ++++++++++--
 modules/video_chroma/d3d11_fmt.h | 10 ++++++++++
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/include/vlc_picture.h b/include/vlc_picture.h
index 7ef76d9f70..205fff4386 100644
--- a/include/vlc_picture.h
+++ b/include/vlc_picture.h
@@ -89,7 +89,7 @@ enum vlc_video_context_type
     VLC_VIDEO_CONTEXT_VAAPI,
     VLC_VIDEO_CONTEXT_VDPAU,
     VLC_VIDEO_CONTEXT_DXVA2, /**< private: d3d9_video_context_t* */
-    VLC_VIDEO_CONTEXT_D3D11VA,
+    VLC_VIDEO_CONTEXT_D3D11VA,  /**< private: d3d11_video_context_t* */
     VLC_VIDEO_CONTEXT_AWINDOW,
     VLC_VIDEO_CONTEXT_MMAL,
 };
diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index e066729cbb..3dcb606904 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -309,6 +309,12 @@ static void Close(vlc_va_t *va, void **ctx)
     free(sys);
 }
 
+static void ReleaseD3D11ContextPrivate(void *opaque, void *private)
+{
+    d3d11_video_context_t *octx = private;
+    ID3D11DeviceContext_Release(octx->device);
+}
+
 static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
                 const es_format_t *fmt, vlc_decoder_device *dec_device,
                 vlc_video_context **vctx_out, picture_sys_d3d11_t *p_sys)
@@ -370,7 +376,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
             if (sys->d3d_dev.context_mutex == INVALID_HANDLE_VALUE)
                 msg_Warn(va, "No mutex found to lock the decoder");
 
-            vlc_video_context *vctx = vlc_video_context_Create( dec_device, 0, VLC_VIDEO_CONTEXT_NONE, NULL, NULL );
+            vlc_video_context *vctx = vlc_video_context_Create( dec_device, sizeof(d3d11_video_context_t), VLC_VIDEO_CONTEXT_D3D11VA, NULL, ReleaseD3D11ContextPrivate );
             if (likely(vctx != NULL))
             {
                 void *d3dvidctx = NULL;
@@ -381,7 +387,9 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
                     vlc_video_context_Release( vctx );
                 } else {
                     sys->d3dvidctx = d3dvidctx;
-
+                    d3d11_video_context_t *priv = GetD3D11ContextPrivate(vctx);
+                    priv->device = sys->d3d_dev.d3dcontext;
+                    ID3D11DeviceContext_Release(priv->device);
                     *vctx_out = vctx;
 
                     if (p_sys != NULL)
diff --git a/modules/video_chroma/d3d11_fmt.h b/modules/video_chroma/d3d11_fmt.h
index 9d018b48fb..234be517fd 100644
--- a/modules/video_chroma/d3d11_fmt.h
+++ b/modules/video_chroma/d3d11_fmt.h
@@ -84,6 +84,11 @@ typedef struct
     ID3D11DeviceContext *device;
 } d3d11_decoder_device_t;
 
+typedef struct
+{
+    ID3D11DeviceContext *device;
+} d3d11_video_context_t;
+
 /* index to use for texture/resource that use a known DXGI format
  * (ie not DXGI_FORMAT_UNKNWON) */
 #define KNOWN_DXGI_INDEX   0
@@ -118,6 +123,11 @@ static inline d3d11_decoder_device_t *GetD3D11OpaqueContext(vlc_video_context *v
     return res;
 }
 
+static inline d3d11_video_context_t *GetD3D11ContextPrivate(vlc_video_context *vctx)
+{
+    return (d3d11_video_context_t *) vlc_video_context_GetPrivate( vctx, VLC_VIDEO_CONTEXT_D3D11VA );
+}
+
 void AcquireD3D11PictureSys(picture_sys_d3d11_t *p_sys);
 
 void ReleaseD3D11PictureSys(picture_sys_d3d11_t *p_sys);
-- 
2.17.1



More information about the vlc-devel mailing list