diff --git a/sys/mediafoundation/gstmfvideoenc.cpp b/sys/mediafoundation/gstmfvideoenc.cpp index 3b92855abd..8bedc5f605 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 0747d637f9..8289549097 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']