[vlc-commits] d3d11_fmt: add helpers to lock/unlock the D3D11VideoContext

Steve Lhomme git at videolan.org
Tue Aug 7 09:12:47 CEST 2018


vlc/vlc-3.0 | branch: master | Steve Lhomme <robux4 at videolabs.io> | Thu Nov 30 14:20:47 2017 +0100| [fb14e6ed2046605d2b85233c3e153b4b6df4eb59] | committer: Steve Lhomme

d3d11_fmt: add helpers to lock/unlock the D3D11VideoContext

(cherry picked from commit 717daca1c62f298902db807ae6eee82a32d6890d)

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

 modules/hw/d3d11/d3d11_deinterlace.c    |  6 ++----
 modules/hw/d3d11/d3d11_filters.c        |  8 +++-----
 modules/video_chroma/d3d11_fmt.h        | 12 ++++++++++++
 modules/video_output/win32/direct3d11.c | 29 +++++++----------------------
 4 files changed, 24 insertions(+), 31 deletions(-)

diff --git a/modules/hw/d3d11/d3d11_deinterlace.c b/modules/hw/d3d11/d3d11_deinterlace.c
index 97a37360e7..4eb4f1df1e 100644
--- a/modules/hw/d3d11/d3d11_deinterlace.c
+++ b/modules/hw/d3d11/d3d11_deinterlace.c
@@ -226,13 +226,11 @@ static picture_t *Deinterlace(filter_t *p_filter, picture_t *p_pic)
 {
     filter_sys_t *p_sys = p_filter->p_sys;
 
-    if( p_sys->d3d_dev.context_mutex != INVALID_HANDLE_VALUE )
-        WaitForSingleObjectEx( p_sys->d3d_dev.context_mutex, INFINITE, FALSE );
+    d3d11_device_lock( &p_sys->d3d_dev );
 
     picture_t *res = DoDeinterlacing( p_filter, &p_sys->context, p_pic );
 
-    if( p_sys->d3d_dev.context_mutex  != INVALID_HANDLE_VALUE )
-        ReleaseMutex( p_sys->d3d_dev.context_mutex );
+    d3d11_device_unlock( &p_sys->d3d_dev );
 
     return res;
 }
diff --git a/modules/hw/d3d11/d3d11_filters.c b/modules/hw/d3d11/d3d11_filters.c
index 1ac8fcf663..1ee51e2c9d 100644
--- a/modules/hw/d3d11/d3d11_filters.c
+++ b/modules/hw/d3d11/d3d11_filters.c
@@ -245,9 +245,6 @@ static picture_t *Filter(filter_t *p_filter, picture_t *p_pic)
 
     picture_CopyProperties( p_outpic, p_pic );
 
-    if( p_sys->d3d_dev.context_mutex != INVALID_HANDLE_VALUE )
-        WaitForSingleObjectEx( p_sys->d3d_dev.context_mutex, INFINITE, FALSE );
-
     ID3D11VideoProcessorInputView *inputs[4] = {
         p_src_sys->processorInput,
         p_sys->procInput[0],
@@ -262,6 +259,8 @@ static picture_t *Filter(filter_t *p_filter, picture_t *p_pic)
         p_sys->procOutput[1]
     };
 
+    d3d11_device_lock( &p_sys->d3d_dev );
+
     size_t idx = 0, count = 0;
     /* contrast */
     if ( ApplyFilter( p_sys,
@@ -317,8 +316,7 @@ static picture_t *Filter(filter_t *p_filter, picture_t *p_pic)
                                                   NULL);
     }
 
-    if( p_sys->d3d_dev.context_mutex  != INVALID_HANDLE_VALUE )
-        ReleaseMutex( p_sys->d3d_dev.context_mutex );
+    d3d11_device_unlock( &p_sys->d3d_dev );
 
     picture_Release( p_pic );
     return p_outpic;
diff --git a/modules/video_chroma/d3d11_fmt.h b/modules/video_chroma/d3d11_fmt.h
index 0c2a3b04ef..8f1dc5ba0e 100644
--- a/modules/video_chroma/d3d11_fmt.h
+++ b/modules/video_chroma/d3d11_fmt.h
@@ -139,4 +139,16 @@ void D3D11_LogProcessorSupport(vlc_object_t*, ID3D11VideoProcessorEnumerator*);
 #define D3D11_LogProcessorSupport(a,b) D3D11_LogProcessorSupport( VLC_OBJECT(a), b )
 #endif
 
+static inline void d3d11_device_lock(d3d11_device_t *d3d_dev)
+{
+    if( d3d_dev->context_mutex != INVALID_HANDLE_VALUE )
+        WaitForSingleObjectEx( d3d_dev->context_mutex, INFINITE, FALSE );
+}
+
+static inline void d3d11_device_unlock(d3d11_device_t *d3d_dev)
+{
+    if( d3d_dev->context_mutex  != INVALID_HANDLE_VALUE )
+        ReleaseMutex( d3d_dev->context_mutex );
+}
+
 #endif /* include-guard */
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index 268f710db1..0e65436600 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -983,24 +983,14 @@ static void UpdateSize(vout_display_t *vd)
 
     UpdateBackBuffer(vd);
 
-#if defined(HAVE_ID3D11VIDEODECODER)
-    if( sys->d3d_dev.context_mutex != INVALID_HANDLE_VALUE )
-    {
-        WaitForSingleObjectEx( sys->d3d_dev.context_mutex, INFINITE, FALSE );
-    }
-#endif
+    d3d11_device_lock( &sys->d3d_dev );
 
     UpdatePicQuadPosition(vd);
 
     UpdateQuadPosition(vd, &sys->picQuad, &sys->sys.rect_src_clipped,
                        vd->fmt.orientation);
 
-#if defined(HAVE_ID3D11VIDEODECODER)
-    if( sys->d3d_dev.context_mutex != INVALID_HANDLE_VALUE )
-    {
-        ReleaseMutex( sys->d3d_dev.context_mutex );
-    }
-#endif
+    d3d11_device_unlock( &sys->d3d_dev );
 }
 
 static inline bool RectEquals(const RECT *r1, const RECT *r2)
@@ -1188,10 +1178,9 @@ static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpic
     {
         picture_sys_t *p_sys = ActivePictureSys(picture);
 
-#if defined(HAVE_ID3D11VIDEODECODER)
-        if (sys->d3d_dev.context_mutex != INVALID_HANDLE_VALUE && is_d3d11_opaque(picture->format.i_chroma))
-            WaitForSingleObjectEx( sys->d3d_dev.context_mutex, INFINITE, FALSE );
-#endif
+        if (is_d3d11_opaque(picture->format.i_chroma))
+            d3d11_device_lock( &sys->d3d_dev );
+
         if (!is_d3d11_opaque(picture->format.i_chroma) || sys->legacy_shader) {
             D3D11_TEXTURE2D_DESC srcDesc,texDesc;
             if (!is_d3d11_opaque(picture->format.i_chroma))
@@ -1295,12 +1284,8 @@ static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpic
         }
     }
 
-#if defined(HAVE_ID3D11VIDEODECODER)
-    if (sys->d3d_dev.context_mutex != INVALID_HANDLE_VALUE && is_d3d11_opaque(picture->format.i_chroma))
-    {
-        ReleaseMutex( sys->d3d_dev.context_mutex );
-    }
-#endif
+    if (is_d3d11_opaque(picture->format.i_chroma))
+        d3d11_device_unlock( &sys->d3d_dev );
 
     ID3D11DeviceContext_Flush(sys->d3d_dev.d3dcontext);
 }



More information about the vlc-commits mailing list