[vlc-commits] d3d11: Store context_mutex in the DeviceContext private data
Hugo Beauzée-Luyssen
git at videolan.org
Tue Aug 7 09:12:48 CEST 2018
vlc/vlc-3.0 | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Tue Mar 13 15:56:09 2018 +0100| [3bc4d221a6218c6a66fd69da2244a874d72207b0] | committer: Steve Lhomme
d3d11: Store context_mutex in the DeviceContext private data
And create it as soon as the DeviceContext is created so they have the same
lifetime.
(cherry picked from commit 0d7d3f6e7ab4fc3b1b962ed9d304d81d88df6a4e)
> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=3bc4d221a6218c6a66fd69da2244a874d72207b0
---
modules/codec/avcodec/d3d11va.c | 2 +-
modules/hw/d3d11/d3d11_deinterlace.c | 2 +-
modules/hw/d3d11/d3d11_filters.c | 2 +-
modules/video_chroma/d3d11_fmt.c | 20 ++++++++++++++++++++
modules/video_output/win32/direct3d11.c | 13 -------------
5 files changed, 23 insertions(+), 16 deletions(-)
diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index 596d3d70cb..5ab8fd2b8b 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -348,7 +348,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
ID3D11DeviceContext_GetDevice( p_sys->context, &sys->d3d_dev.d3ddevice );
HANDLE context_lock = INVALID_HANDLE_VALUE;
UINT dataSize = sizeof(context_lock);
- hr = ID3D11Device_GetPrivateData(sys->d3d_dev.d3ddevice, &GUID_CONTEXT_MUTEX, &dataSize, &context_lock);
+ hr = ID3D11DeviceContext_GetPrivateData(p_sys->context, &GUID_CONTEXT_MUTEX, &dataSize, &context_lock);
if (FAILED(hr))
msg_Warn(va, "No mutex found to lock the decoder");
sys->d3d_dev.context_mutex = context_lock;
diff --git a/modules/hw/d3d11/d3d11_deinterlace.c b/modules/hw/d3d11/d3d11_deinterlace.c
index 4eb4f1df1e..3d3ec0f393 100644
--- a/modules/hw/d3d11/d3d11_deinterlace.c
+++ b/modules/hw/d3d11/d3d11_deinterlace.c
@@ -379,7 +379,7 @@ int D3D11OpenDeinterlace(vlc_object_t *obj)
HANDLE context_lock = INVALID_HANDLE_VALUE;
UINT dataSize = sizeof(context_lock);
- hr = ID3D11Device_GetPrivateData(sys->d3d_dev.d3ddevice, &GUID_CONTEXT_MUTEX, &dataSize, &context_lock);
+ hr = ID3D11DeviceContext_GetPrivateData(sys->d3d_dev.d3dcontext, &GUID_CONTEXT_MUTEX, &dataSize, &context_lock);
if (FAILED(hr))
msg_Warn(filter, "No mutex found to lock the decoder");
sys->d3d_dev.context_mutex = context_lock;
diff --git a/modules/hw/d3d11/d3d11_filters.c b/modules/hw/d3d11/d3d11_filters.c
index 1ee51e2c9d..4a287681d5 100644
--- a/modules/hw/d3d11/d3d11_filters.c
+++ b/modules/hw/d3d11/d3d11_filters.c
@@ -380,7 +380,7 @@ static int D3D11OpenAdjust(vlc_object_t *obj)
HANDLE context_lock = INVALID_HANDLE_VALUE;
UINT dataSize = sizeof(context_lock);
- hr = ID3D11Device_GetPrivateData(sys->d3d_dev.d3ddevice, &GUID_CONTEXT_MUTEX, &dataSize, &context_lock);
+ hr = ID3D11DeviceContext_GetPrivateData(sys->d3d_dev.d3dcontext, &GUID_CONTEXT_MUTEX, &dataSize, &context_lock);
if (FAILED(hr))
msg_Warn(filter, "No mutex found to lock the decoder");
sys->d3d_dev.context_mutex = context_lock;
diff --git a/modules/video_chroma/d3d11_fmt.c b/modules/video_chroma/d3d11_fmt.c
index 18d9345f00..1eb44fe148 100644
--- a/modules/video_chroma/d3d11_fmt.c
+++ b/modules/video_chroma/d3d11_fmt.c
@@ -20,6 +20,11 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
+#if !defined(_WIN32_WINNT) || _WIN32_WINNT < _WIN32_WINNT_WIN7
+# undef _WIN32_WINNT
+# define _WIN32_WINNT _WIN32_WINNT_WIN7
+#endif
+
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
@@ -219,6 +224,13 @@ void D3D11_ReleaseDevice(d3d11_device_t *d3d_dev)
ID3D11Device_Release(d3d_dev->d3ddevice);
d3d_dev->d3ddevice = NULL;
}
+#if defined(HAVE_ID3D11VIDEODECODER)
+ if( d3d_dev->owner && d3d_dev->context_mutex != INVALID_HANDLE_VALUE )
+ {
+ CloseHandle( d3d_dev->context_mutex );
+ d3d_dev->context_mutex = INVALID_HANDLE_VALUE;
+ }
+#endif
}
#undef D3D11_CreateDevice
@@ -289,7 +301,15 @@ HRESULT D3D11_CreateDevice(vlc_object_t *obj, d3d11_handle_t *hd3d,
}
if (SUCCEEDED(hr))
+ {
+#if defined(HAVE_ID3D11VIDEODECODER)
+ out->context_mutex = CreateMutexEx( NULL, NULL, 0, SYNCHRONIZE );
+ ID3D11DeviceContext_SetPrivateData( out->d3dcontext, &GUID_CONTEXT_MUTEX,
+ sizeof( out->context_mutex ), &out->context_mutex );
+#endif
+
out->owner = true;
+ }
return hr;
}
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index 0e65436600..9939f4b929 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -2125,12 +2125,6 @@ static int Direct3D11CreateGenericResources(vout_display_t *vd)
vout_display_sys_t *sys = vd->sys;
HRESULT hr;
-#if defined(HAVE_ID3D11VIDEODECODER)
- sys->d3d_dev.context_mutex = CreateMutexEx( NULL, NULL, 0, SYNCHRONIZE );
- ID3D11Device_SetPrivateData( sys->d3d_dev.d3ddevice, &GUID_CONTEXT_MUTEX,
- sizeof( sys->d3d_dev.context_mutex ), &sys->d3d_dev.context_mutex );
-#endif
-
ID3D11BlendState *pSpuBlendState;
D3D11_BLEND_DESC spuBlendDesc = { 0 };
spuBlendDesc.RenderTarget[0].BlendEnable = TRUE;
@@ -3011,13 +3005,6 @@ static void Direct3D11DestroyResources(vout_display_t *vd)
ID3D11PixelShader_Release(sys->picQuadPixelShader);
sys->picQuadPixelShader = NULL;
}
-#if defined(HAVE_ID3D11VIDEODECODER)
- if( sys->d3d_dev.context_mutex != INVALID_HANDLE_VALUE )
- {
- CloseHandle( sys->d3d_dev.context_mutex );
- sys->d3d_dev.context_mutex = INVALID_HANDLE_VALUE;
- }
-#endif
msg_Dbg(vd, "Direct3D11 resources destroyed");
}
More information about the vlc-commits
mailing list