mfvideoenc: Enable Direct3D multi-thread protection
authorSeungha Yang <seungha@centricular.com>
Sat, 20 Mar 2021 07:26:21 +0000 (16:26 +0900)
committerSeungha Yang <seungha@centricular.com>
Sat, 20 Mar 2021 08:54:04 +0000 (17:54 +0900)
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: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2095>

sys/mediafoundation/gstmfvideoenc.cpp
sys/mediafoundation/meson.build

index 3b92855..8bedc5f 100644 (file)
 #include "gstmfvideobuffer.h"
 #include <string.h>
 
+#if GST_MF_HAVE_D3D11
+#include <d3d10.h>
+#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<ID3D10Multithread> 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)) {
index 0747d63..8289549 100644 (file)
@@ -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']