[vlc-commits] d3d11va: store the ID3D11DeviceContext in the video context
Steve Lhomme
git at videolan.org
Fri Oct 18 09:47:28 CEST 2019
vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Tue Sep 24 10:32:47 2019 +0200| [579a40a48dec44d589c5baa2c6858ac0a366faa1] | committer: Steve Lhomme
d3d11va: store the ID3D11DeviceContext in the video context
We might store a reference to the VA module so the destructor of the module is
not called while the video context is used.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=579a40a48dec44d589c5baa2c6858ac0a366faa1
---
include/vlc_picture.h | 2 +-
modules/codec/avcodec/d3d11va.c | 5 ++++-
modules/video_chroma/d3d11_fmt.c | 10 ++++++++++
modules/video_chroma/d3d11_fmt.h | 12 ++++++++++++
4 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/include/vlc_picture.h b/include/vlc_picture.h
index 92a8594725..3298630e02 100644
--- a/include/vlc_picture.h
+++ b/include/vlc_picture.h
@@ -94,7 +94,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_NVDEC,
VLC_VIDEO_CONTEXT_CVPX,
diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index a85d21859f..91e065a360 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -368,7 +368,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, const AVPixFmtDescriptor *des
if (sys->d3d_dev.context_mutex == INVALID_HANDLE_VALUE)
msg_Warn(va, "No mutex found to lock the decoder");
- sys->vctx = vlc_video_context_Create( dec_device, VLC_VIDEO_CONTEXT_D3D11VA, 0, NULL );
+ sys->vctx = vlc_video_context_Create( dec_device, VLC_VIDEO_CONTEXT_D3D11VA, sizeof(d3d11_video_context_t), &d3d11_vctx_ops );
if (likely(sys->vctx != NULL))
{
void *d3dvidctx = NULL;
@@ -380,6 +380,9 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, const AVPixFmtDescriptor *des
sys->vctx = NULL;
} else {
sys->hw.video_context = d3dvidctx;
+ d3d11_video_context_t *priv = GetD3D11ContextPrivate(sys->vctx);
+ priv->device = sys->d3d_dev.d3dcontext;
+ ID3D11DeviceContext_Release(priv->device);
}
}
}
diff --git a/modules/video_chroma/d3d11_fmt.c b/modules/video_chroma/d3d11_fmt.c
index 542149002d..5ebec70a54 100644
--- a/modules/video_chroma/d3d11_fmt.c
+++ b/modules/video_chroma/d3d11_fmt.c
@@ -792,6 +792,16 @@ void D3D11_Destroy(d3d11_handle_t *hd3d)
#endif
}
+static void ReleaseD3D11ContextPrivate(void *private)
+{
+ d3d11_video_context_t *octx = private;
+ ID3D11DeviceContext_Release(octx->device);
+}
+
+const struct vlc_video_context_operations d3d11_vctx_ops = {
+ ReleaseD3D11ContextPrivate,
+};
+
void d3d11_pic_context_destroy(picture_context_t *ctx)
{
struct d3d11_pic_context *pic_ctx = D3D11_PICCONTEXT_FROM_PICCTX(ctx);
diff --git a/modules/video_chroma/d3d11_fmt.h b/modules/video_chroma/d3d11_fmt.h
index d0bed25785..8974845cb8 100644
--- a/modules/video_chroma/d3d11_fmt.h
+++ b/modules/video_chroma/d3d11_fmt.h
@@ -92,6 +92,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
@@ -104,6 +109,8 @@ static inline bool is_d3d11_opaque(vlc_fourcc_t chroma)
chroma == VLC_CODEC_D3D11_OPAQUE_BGRA;
}
+const struct vlc_video_context_operations d3d11_vctx_ops;
+
#define D3D11_PICCONTEXT_FROM_PICCTX(pic_ctx) \
container_of((pic_ctx), struct d3d11_pic_context, s)
@@ -131,6 +138,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);
More information about the vlc-commits
mailing list