From e22befad2ed3a411e73aa03f2b014ada9d953b5c Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Sat, 20 Mar 2021 16:26:21 +0900 Subject: [PATCH] mfvideoenc: Enable Direct3D multi-thread protection As documented by MS. See also https://docs.microsoft.com/en-us/windows/win32/medfound/supporting-direct3d-11-video-decoding-in-media-foundation#open-a-device-handle Part-of: --- sys/mediafoundation/gstmfvideoenc.cpp | 17 +++++++++++++++++ sys/mediafoundation/meson.build | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/sys/mediafoundation/gstmfvideoenc.cpp b/sys/mediafoundation/gstmfvideoenc.cpp index 3b92855..8bedc5f 100644 --- a/sys/mediafoundation/gstmfvideoenc.cpp +++ b/sys/mediafoundation/gstmfvideoenc.cpp @@ -28,6 +28,10 @@ #include "gstmfvideobuffer.h" #include +#if GST_MF_HAVE_D3D11 +#include +#endif + using namespace Microsoft::WRL; G_BEGIN_DECLS @@ -135,6 +139,7 @@ gst_mf_video_enc_open (GstVideoEncoder * enc) if (device_caps->d3d11_aware) { HRESULT hr; ID3D11Device *device_handle; + ComPtr multi_thread; GstD3D11Device *device; if (!gst_d3d11_ensure_element_data (GST_ELEMENT_CAST (self), @@ -164,6 +169,18 @@ gst_mf_video_enc_open (GstVideoEncoder * enc) } device_handle = gst_d3d11_device_get_device_handle (device); + /* Enable multi thread protection as this device will be shared with + * MFT */ + hr = device_handle->QueryInterface (IID_PPV_ARGS (&multi_thread)); + if (!gst_d3d11_result (hr, device)) { + GST_WARNING_OBJECT (self, + "device doesn't suport ID3D10Multithread interface"); + gst_clear_object (&self->other_d3d11_device); + gst_clear_object (&self->d3d11_device); + } + + multi_thread->SetMultithreadProtected (TRUE); + hr = self->device_manager->ResetDevice ((IUnknown *) device_handle, self->reset_token); if (!gst_mf_result (hr)) { diff --git a/sys/mediafoundation/meson.build b/sys/mediafoundation/meson.build index 0747d63..8289549 100644 --- a/sys/mediafoundation/meson.build +++ b/sys/mediafoundation/meson.build @@ -127,7 +127,7 @@ if winapi_desktop # Since MFTEnum2 is desktop only we don't support d3d11 interop for UWP build # And because MFTEnum2 is Windows 10 API, we will load MFTEnum2 symbol # by using g_module_open() so that keep supporting old OS versions - if gstd3d11_dep.found() and cc.has_header('d3d11_4.h') + if gstd3d11_dep.found() and cc.has_header('d3d11_4.h') and cc.has_header('d3d10.h') have_mf_d3d11 = true mf_lib_deps += [gstd3d11_dep, gmodule_dep] extra_c_args += ['-DGST_USE_UNSTABLE_API'] -- 2.7.4