[vlc-commits] direct3d11: create a helper function to create D3D11 video contexts

Steve Lhomme git at videolan.org
Fri Feb 7 15:59:01 CET 2020


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Thu Feb  6 10:11:09 2020 +0100| [2825a1b17a5fc2c0a40bcb760fe07585b4a0f916] | committer: Steve Lhomme

direct3d11: create a helper function to create D3D11 video contexts

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

 modules/codec/avcodec/d3d11va.c  |  6 +-----
 modules/hw/d3d11/d3d11_surface.c | 25 ++++++++++---------------
 modules/video_chroma/d3d11_fmt.c | 12 ++++++++++++
 modules/video_chroma/d3d11_fmt.h |  2 ++
 4 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index 5c03285577..24d6c370c3 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -310,8 +310,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat hwfmt, const
                 sys->d3d_dev->adapterDesc.VendorId, DxgiVendorStr(sys->d3d_dev->adapterDesc.VendorId),
                 sys->d3d_dev->adapterDesc.DeviceId, sys->d3d_dev->adapterDesc.Revision);
 
-    sys->vctx = vlc_video_context_Create( dec_device, VLC_VIDEO_CONTEXT_D3D11VA,
-                                          sizeof(d3d11_video_context_t), &d3d11_vctx_ops );
+    sys->vctx = D3D11CreateVideoContext(dec_device, sys->render_fmt->formatTexture);
     if (sys->vctx == NULL)
     {
         msg_Dbg(va, "no video context");
@@ -319,9 +318,6 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat hwfmt, const
         goto error;
     }
 
-    d3d11_video_context_t *priv = GetD3D11ContextPrivate(sys->vctx);
-    priv->format = sys->render_fmt->formatTexture;
-
     va->ops = &ops;
     *fmt_out = final_fmt;
     *vtcx_out = sys->vctx;
diff --git a/modules/hw/d3d11/d3d11_surface.c b/modules/hw/d3d11/d3d11_surface.c
index 98c14f00cf..9762ad3fac 100644
--- a/modules/hw/d3d11/d3d11_surface.c
+++ b/modules/hw/d3d11/d3d11_surface.c
@@ -773,33 +773,28 @@ int D3D11OpenCPUConverter( vlc_object_t *obj )
         return VLC_ENOMEM;
     }
 
-    p_filter->vctx_out = vlc_video_context_Create(dec_device, VLC_VIDEO_CONTEXT_D3D11VA,
-                                          sizeof(d3d11_video_context_t), &d3d11_vctx_ops);
-    vlc_decoder_device_Release(dec_device);
-
-    if ( p_filter->vctx_out == NULL )
-    {
-        msg_Dbg(p_filter, "no video context");
-        goto done;
-    }
-
-    d3d11_video_context_t *vctx_sys = GetD3D11ContextPrivate( p_filter->vctx_out );
+    DXGI_FORMAT vctx_fmt;
     switch( p_filter->fmt_in.video.i_chroma ) {
     case VLC_CODEC_I420:
     case VLC_CODEC_YV12:
     case VLC_CODEC_NV12:
-        vctx_sys->format = DXGI_FORMAT_NV12;
+        vctx_fmt = DXGI_FORMAT_NV12;
         break;
     case VLC_CODEC_I420_10L:
     case VLC_CODEC_P010:
-        vctx_sys->format = DXGI_FORMAT_P010;
+        vctx_fmt = DXGI_FORMAT_P010;
         break;
     default:
         vlc_assert_unreachable();
     }
-    p_filter->p_sys = p_sys;
+    p_filter->vctx_out = D3D11CreateVideoContext(dec_device, vctx_fmt);
+    if ( p_filter->vctx_out == NULL )
+    {
+        msg_Dbg(p_filter, "no video context");
+        goto done;
+    }
 
-    vlc_fourcc_t d3d_fourcc = DxgiFormatFourcc(vctx_sys->format);
+    vlc_fourcc_t d3d_fourcc = DxgiFormatFourcc(vctx_fmt);
 
     if ( p_filter->fmt_in.video.i_chroma != d3d_fourcc )
     {
diff --git a/modules/video_chroma/d3d11_fmt.c b/modules/video_chroma/d3d11_fmt.c
index bbea1cc081..25f987f902 100644
--- a/modules/video_chroma/d3d11_fmt.c
+++ b/modules/video_chroma/d3d11_fmt.c
@@ -778,6 +778,18 @@ const struct vlc_video_context_operations d3d11_vctx_ops = {
     NULL,
 };
 
+vlc_video_context *D3D11CreateVideoContext(vlc_decoder_device *dec_dev, DXGI_FORMAT vctx_fmt)
+{
+    vlc_video_context *vctx = vlc_video_context_Create( dec_dev, VLC_VIDEO_CONTEXT_D3D11VA,
+                                          sizeof(d3d11_video_context_t), &d3d11_vctx_ops );
+    if (unlikely(vctx == NULL))
+        return NULL;
+
+    d3d11_video_context_t *priv = GetD3D11ContextPrivate(vctx);
+    priv->format = vctx_fmt;
+    return vctx;
+}
+
 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 6d17cf57d2..79142a266e 100644
--- a/modules/video_chroma/d3d11_fmt.h
+++ b/modules/video_chroma/d3d11_fmt.h
@@ -139,6 +139,8 @@ static inline d3d11_video_context_t *GetD3D11ContextPrivate(vlc_video_context *v
     return (d3d11_video_context_t *) vlc_video_context_GetPrivate( vctx, VLC_VIDEO_CONTEXT_D3D11VA );
 }
 
+vlc_video_context *D3D11CreateVideoContext(vlc_decoder_device *, DXGI_FORMAT);
+
 void AcquireD3D11PictureSys(picture_sys_d3d11_t *p_sys);
 
 void ReleaseD3D11PictureSys(picture_sys_d3d11_t *p_sys);



More information about the vlc-commits mailing list