From 22990bb9ea7c37a557a9edb1c8549b794a079155 Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Fri, 4 Dec 2020 03:40:17 +0900 Subject: [PATCH] d3d11: Protect ID3D11VideoContext with lock Likewise d3d11 immediate context (i.e., ID3D11DeviceContext), ID3D11VideoContext API is not thread safe. It must be protected therefore. Part-of: --- sys/d3d11/gstd3d11colorconvert.c | 2 ++ sys/d3d11/gstd3d11window.cpp | 17 +++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/sys/d3d11/gstd3d11colorconvert.c b/sys/d3d11/gstd3d11colorconvert.c index 7487299..5143acc 100644 --- a/sys/d3d11/gstd3d11colorconvert.c +++ b/sys/d3d11/gstd3d11colorconvert.c @@ -1523,6 +1523,7 @@ gst_d3d11_convert_set_info (GstD3D11BaseFilter * filter, gboolean hardware = FALSE; GstD3D11VideoProcessor *processor = NULL; + gst_d3d11_device_lock (filter->device); g_object_get (filter->device, "hardware", &hardware, NULL); if (hardware) { processor = gst_d3d11_video_processor_new (filter->device, @@ -1566,6 +1567,7 @@ gst_d3d11_convert_set_info (GstD3D11BaseFilter * filter, } self->processor = processor; + gst_d3d11_device_unlock (filter->device); } #endif diff --git a/sys/d3d11/gstd3d11window.cpp b/sys/d3d11/gstd3d11window.cpp index 29180b6..e4714a1 100644 --- a/sys/d3d11/gstd3d11window.cpp +++ b/sys/d3d11/gstd3d11window.cpp @@ -544,11 +544,8 @@ gst_d3d11_window_prepare (GstD3D11Window * window, guint display_width, GST_ERROR_OBJECT (window, "Cannot create swapchain"); g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_FAILED, "Cannot create swapchain"); - gst_d3d11_device_unlock (window->device); - - return FALSE; + goto error; } - gst_d3d11_device_unlock (window->device); /* this rect struct will be used to calculate render area */ window->render_rect.left = 0; @@ -737,8 +734,7 @@ gst_d3d11_window_prepare (GstD3D11Window * window, guint display_width, GST_ERROR_OBJECT (window, "Cannot create converter"); g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_FAILED, "Cannot create converter"); - - return FALSE; + goto error; } window->compositor = @@ -747,9 +743,9 @@ gst_d3d11_window_prepare (GstD3D11Window * window, guint display_width, GST_ERROR_OBJECT (window, "Cannot create overlay compositor"); g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_FAILED, "Cannot create overlay compositor"); - - return FALSE; + goto error; } + gst_d3d11_device_unlock (window->device); /* call resize to allocated resources */ klass->on_resize (window, display_width, display_height); @@ -761,6 +757,11 @@ gst_d3d11_window_prepare (GstD3D11Window * window, guint display_width, GST_DEBUG_OBJECT (window, "New swap chain 0x%p created", window->swap_chain); return TRUE; + +error: + gst_d3d11_device_unlock (window->device); + + return FALSE; } void -- 2.7.4