[vlc-commits] direct3d11: always use a mutex to protect the context with hardware decoding

Steve Lhomme git at videolan.org
Mon Aug 1 10:00:45 CEST 2016


vlc | branch: master | Steve Lhomme <robUx4 at videolabs.io> | Mon Aug  1 09:12:15 2016 +0200| [63a5f658729bc7b7915644e51ec06ee6c1f0d3e9] | committer: Jean-Baptiste Kempf

direct3d11: always use a mutex to protect the context with hardware decoding

Even when using a single thread for decoding it's still not in the same thread
as the vout so we must protect it anyway.

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

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

 modules/codec/avcodec/d3d11va.c         | 12 ++++--------
 modules/video_output/win32/common.h     |  5 +++--
 modules/video_output/win32/direct3d11.c | 18 ++++++++----------
 3 files changed, 15 insertions(+), 20 deletions(-)

diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index d403819..294587d 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -116,7 +116,7 @@ struct vlc_va_sys_t
     DXGI_FORMAT                  render;
 
     ID3D11DeviceContext          *d3dctx;
-#if VLC_WINSTORE_APP && LIBAVCODEC_VERSION_CHECK(57, 2, 0, 3, 100)
+#if LIBAVCODEC_VERSION_CHECK(57, 2, 0, 3, 100)
     HANDLE                       context_mutex;
 #endif
 
@@ -182,11 +182,7 @@ void SetupAVCodecContext(vlc_va_t *va)
     sys->hw.surface_count = dx_sys->surface_count;
     sys->hw.surface = (ID3D11VideoDecoderOutputView**) dx_sys->hw_surface;
 #if LIBAVCODEC_VERSION_CHECK(57, 2, 0, 3, 100)
-#if VLC_WINSTORE_APP
     sys->hw.context_mutex = sys->context_mutex;
-#else
-    sys->hw.context_mutex = INVALID_HANDLE_VALUE;
-#endif
 #endif
 
     if (IsEqualGUID(&dx_sys->input, &DXVA_Intel_H264_NoFGT_ClearVideo))
@@ -265,7 +261,7 @@ static int Extract(vlc_va_t *va, picture_t *output, uint8_t *data)
         assert(p_sys_out->texture != NULL);
         assert(p_sys_in->decoder == src);
 
-#if VLC_WINSTORE_APP && LIBAVCODEC_VERSION_CHECK(57, 2, 0, 3, 100)
+#if LIBAVCODEC_VERSION_CHECK(57, 2, 0, 3, 100)
         if( sys->context_mutex > 0 ) {
             WaitForSingleObjectEx( sys->context_mutex, INFINITE, FALSE );
         }
@@ -337,7 +333,7 @@ static int Extract(vlc_va_t *va, picture_t *output, uint8_t *data)
 
 
 done:
-#if VLC_WINSTORE_APP && LIBAVCODEC_VERSION_CHECK(57, 2, 0, 3, 100)
+#if LIBAVCODEC_VERSION_CHECK(57, 2, 0, 3, 100)
     if( sys->context_mutex > 0 ) {
         ReleaseMutex( sys->context_mutex );
     }
@@ -449,7 +445,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
            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 );
-#if VLC_WINSTORE_APP && LIBAVCODEC_VERSION_CHECK(57, 2, 0, 3, 100)
+#if LIBAVCODEC_VERSION_CHECK(57, 2, 0, 3, 100)
             HANDLE context_lock = INVALID_HANDLE_VALUE;
             UINT dataSize = sizeof(context_lock);
             hr = ID3D11Device_GetPrivateData((ID3D11Device*)dx_sys->d3ddev, &GUID_CONTEXT_MUTEX, &dataSize, &context_lock);
diff --git a/modules/video_output/win32/common.h b/modules/video_output/win32/common.h
index 0e654e0..e626035 100644
--- a/modules/video_output/win32/common.h
+++ b/modules/video_output/win32/common.h
@@ -177,9 +177,10 @@ struct vout_display_sys_t
     PFN_D3D11_CREATE_DEVICE_AND_SWAP_CHAIN OurD3D11CreateDeviceAndSwapChain;
     PFN_D3D11_CREATE_DEVICE                OurD3D11CreateDevice;
     pD3DCompile                            OurD3DCompile;
-#else
+#endif
+#if defined(HAVE_ID3D11VIDEODECODER)
     HANDLE                   context_lock;     /* D3D11 Context lock necessary
-                                                  for hw decoding on WinRT */
+                                                  for hw decoding */
 #endif
     IDXGISwapChain1          *dxgiswapChain;   /* DXGI 1.1 swap chain */
     ID3D11Device             *d3ddevice;       /* D3D device */
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index d359650..4a05c7b 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -793,7 +793,7 @@ static void Manage(vout_display_t *vd)
     if (RECTWidth(size_before)  != RECTWidth(sys->rect_dest_clipped) ||
         RECTHeight(size_before) != RECTHeight(sys->rect_dest_clipped))
     {
-#if defined(HAVE_ID3D11VIDEODECODER) && VLC_WINSTORE_APP
+#if defined(HAVE_ID3D11VIDEODECODER)
         if( sys->context_lock > 0 )
         {
             WaitForSingleObjectEx( sys->context_lock, INFINITE, FALSE );
@@ -805,7 +805,7 @@ static void Manage(vout_display_t *vd)
         UpdateBackBuffer(vd);
 
         UpdatePicQuadPosition(vd);
-#if defined(HAVE_ID3D11VIDEODECODER) && VLC_WINSTORE_APP
+#if defined(HAVE_ID3D11VIDEODECODER)
         if( sys->context_lock > 0 )
         {
             ReleaseMutex( sys->context_lock );
@@ -846,12 +846,10 @@ static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpic
 
 #ifdef HAVE_ID3D11VIDEODECODER
     if (is_d3d11_opaque(picture->format.i_chroma)) {
-#if VLC_WINSTORE_APP
         if( sys->context_lock > 0 )
         {
             WaitForSingleObjectEx( sys->context_lock, INFINITE, FALSE );
         }
-#endif
         D3D11_BOX box;
         box.left   = picture->format.i_x_offset;
         box.right  = picture->format.i_x_offset + picture->format.i_visible_width;
@@ -930,7 +928,7 @@ static void Display(vout_display_t *vd, picture_t *picture, subpicture_t *subpic
     {
         /* TODO device lost */
     }
-#if defined(HAVE_ID3D11VIDEODECODER) && VLC_WINSTORE_APP
+#if defined(HAVE_ID3D11VIDEODECODER)
     if( is_d3d11_opaque(picture->format.i_chroma) && sys->context_lock > 0) {
         ReleaseMutex( sys->context_lock );
     }
@@ -1299,14 +1297,14 @@ static int Direct3D11Open(vout_display_t *vd, video_format_t *fmt)
     UpdateRects(vd, NULL, NULL, true);
     UncropStagingFormat( vd, &core_source );
 
-#if defined(HAVE_ID3D11VIDEODECODER) && VLC_WINSTORE_APP
+#if defined(HAVE_ID3D11VIDEODECODER)
     if( sys->context_lock > 0 )
     {
         WaitForSingleObjectEx( sys->context_lock, INFINITE, FALSE );
     }
 #endif
     if (Direct3D11CreateResources(vd, fmt)) {
-#if defined(HAVE_ID3D11VIDEODECODER) && VLC_WINSTORE_APP
+#if defined(HAVE_ID3D11VIDEODECODER)
         if( sys->context_lock > 0 )
         {
             ReleaseMutex( sys->context_lock );
@@ -1316,7 +1314,7 @@ static int Direct3D11Open(vout_display_t *vd, video_format_t *fmt)
         Direct3D11DestroyResources(vd);
         return VLC_EGENERIC;
     }
-#if defined(HAVE_ID3D11VIDEODECODER) && VLC_WINSTORE_APP
+#if defined(HAVE_ID3D11VIDEODECODER)
     if( sys->context_lock > 0 )
     {
         ReleaseMutex( sys->context_lock );
@@ -1389,7 +1387,7 @@ static int Direct3D11CreateResources(vout_display_t *vd, video_format_t *fmt)
     vout_display_sys_t *sys = vd->sys;
     HRESULT hr;
 
-#if defined(HAVE_ID3D11VIDEODECODER) && VLC_WINSTORE_APP
+#if defined(HAVE_ID3D11VIDEODECODER)
     sys->context_lock = CreateMutexEx( NULL, NULL, 0, SYNCHRONIZE );
     ID3D11Device_SetPrivateData( sys->d3ddevice, &GUID_CONTEXT_MUTEX, sizeof( sys->context_lock ), &sys->context_lock );
 #endif
@@ -1848,7 +1846,7 @@ static void Direct3D11DestroyResources(vout_display_t *vd)
         ID3D11VertexShader_Release(sys->pSPUPixelShader);
         sys->pSPUPixelShader = NULL;
     }
-#if defined(HAVE_ID3D11VIDEODECODER) && VLC_WINSTORE_APP
+#if defined(HAVE_ID3D11VIDEODECODER)
     if( sys->context_lock > 0 )
     {
         CloseHandle( sys->context_lock );



More information about the vlc-commits mailing list