diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11_private.h b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11_private.h index 872b1698e3..c6ab986835 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11_private.h +++ b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11_private.h @@ -19,12 +19,13 @@ #pragma once -#include -#include -#include #include #include + +#include +#include #include +#include G_BEGIN_DECLS @@ -112,3 +113,24 @@ static const GstD3D11Format _gst_d3d11_default_format_map[] = { G_END_DECLS +#ifdef __cplusplus +class GstD3D11DeviceLockGuard +{ +public: + explicit GstD3D11DeviceLockGuard(GstD3D11Device * device) : device_ (device) + { + gst_d3d11_device_lock (device_); + } + + ~GstD3D11DeviceLockGuard() + { + gst_d3d11_device_unlock (device_); + } + + GstD3D11DeviceLockGuard(const GstD3D11DeviceLockGuard&) = delete; + GstD3D11DeviceLockGuard& operator=(const GstD3D11DeviceLockGuard&) = delete; + +private: + GstD3D11Device *device_; +}; +#endif diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11memory.cpp b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11memory.cpp index bf7b42e42c..684d452c07 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11memory.cpp +++ b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11memory.cpp @@ -383,8 +383,8 @@ gst_d3d11_memory_map_full (GstMemory * mem, GstMapInfo * info, gsize maxsize) GstD3D11MemoryPrivate *priv = dmem->priv; GstMapFlags flags = info->flags; gpointer ret = NULL; + GstD3D11DeviceLockGuard lk (dmem->device); - gst_d3d11_device_lock (dmem->device); GST_D3D11_MEMORY_LOCK (dmem); memset (info->user_data, 0, sizeof (info->user_data)); @@ -448,7 +448,6 @@ gst_d3d11_memory_map_full (GstMemory * mem, GstMapInfo * info, gsize maxsize) out: GST_D3D11_MEMORY_UNLOCK (dmem); - gst_d3d11_device_unlock (dmem->device); return ret; } @@ -469,8 +468,8 @@ gst_d3d11_memory_unmap_full (GstMemory * mem, GstMapInfo * info) { GstD3D11Memory *dmem = GST_D3D11_MEMORY_CAST (mem); GstD3D11MemoryPrivate *priv = dmem->priv; + GstD3D11DeviceLockGuard lk (dmem->device); - gst_d3d11_device_lock (dmem->device); GST_D3D11_MEMORY_LOCK (dmem); if ((info->flags & GST_MAP_D3D11) == GST_MAP_D3D11) { @@ -491,7 +490,6 @@ gst_d3d11_memory_unmap_full (GstMemory * mem, GstMapInfo * info) out: GST_D3D11_MEMORY_UNLOCK (dmem); - gst_d3d11_device_unlock (dmem->device); } static GstMemory * @@ -521,7 +519,8 @@ gst_d3d11_memory_update_size (GstMemory * mem) } } - gst_d3d11_device_lock (dmem->device); + GstD3D11DeviceLockGuard lk (dmem->device); + if (!gst_d3d11_memory_map_cpu_access (dmem, D3D11_MAP_READ_WRITE)) { GST_ERROR_OBJECT (mem->allocator, "Couldn't map staging texture"); return FALSE; @@ -540,7 +539,6 @@ gst_d3d11_memory_update_size (GstMemory * mem) out: GST_D3D11_CLEAR_COM (priv->staging); - gst_d3d11_device_unlock (dmem->device); return ret; } @@ -1326,10 +1324,10 @@ gst_d3d11_memory_copy (GstMemory * mem, gssize offset, gssize size) return priv->fallback_copy (mem, offset, size); } - gst_d3d11_device_lock (device); + GstD3D11DeviceLockGuard lk (device); + if (!gst_memory_map (mem, &info, (GstMapFlags) (GST_MAP_READ | GST_MAP_D3D11))) { - gst_d3d11_device_unlock (device); GST_WARNING_OBJECT (alloc, "Failed to map memory, try fallback copy"); @@ -1362,7 +1360,6 @@ gst_d3d11_memory_copy (GstMemory * mem, gssize offset, gssize size) copy = gst_d3d11_allocator_alloc_internal (alloc, device, &dst_desc, nullptr); if (!copy) { gst_memory_unmap (mem, &info); - gst_d3d11_device_unlock (device); GST_WARNING_OBJECT (alloc, "Failed to allocate new d3d11 map memory, try fallback copy"); @@ -1375,7 +1372,6 @@ gst_d3d11_memory_copy (GstMemory * mem, gssize offset, gssize size) dmem->priv->texture, dmem->priv->subresource_index, NULL); copy->maxsize = copy->size = mem->maxsize; gst_memory_unmap (mem, &info); - gst_d3d11_device_unlock (device); /* newly allocated memory holds valid image data. We need download this * pixel data into staging memory for CPU access */ @@ -1541,9 +1537,8 @@ gst_d3d11_allocator_alloc_internal (GstD3D11Allocator * self, return mem; context_handle = gst_d3d11_device_get_device_context_handle (device); - gst_d3d11_device_lock (device); + GstD3D11DeviceLockGuard lk (device); clear_func (context_handle, rtv); - gst_d3d11_device_unlock (device); return mem; } diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11compositor.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11compositor.cpp index 1f04cb8258..b8d0a0c0bd 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11compositor.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11compositor.cpp @@ -2046,29 +2046,26 @@ gst_d3d11_compositor_aggregate_frames (GstVideoAggregator * vagg, ID3D11RenderTargetView *rtv[GST_VIDEO_MAX_PLANES] = { nullptr, }; GstVideoFrame target_frame; guint num_rtv = GST_VIDEO_INFO_N_PLANES (&vagg->info); + GstD3D11DeviceLockGuard lk (self->device); if (!self->downstream_supports_d3d11) target_buf = self->fallback_buf; - gst_d3d11_device_lock (self->device); if (!gst_video_frame_map (&target_frame, &vagg->info, target_buf, (GstMapFlags) (GST_MAP_WRITE | GST_MAP_D3D11))) { GST_ERROR_OBJECT (self, "Failed to map render target frame"); - gst_d3d11_device_unlock (self->device); return GST_FLOW_ERROR; } if (!gst_d3d11_buffer_get_render_target_view (target_buf, rtv)) { GST_ERROR_OBJECT (self, "RTV is unavailable"); gst_video_frame_unmap (&target_frame); - gst_d3d11_device_unlock (self->device); return GST_FLOW_ERROR; } if (!gst_d3d11_compositor_draw_background (self, rtv, num_rtv)) { GST_ERROR_OBJECT (self, "Couldn't draw background"); gst_video_frame_unmap (&target_frame); - gst_d3d11_device_unlock (self->device); return GST_FLOW_ERROR; } @@ -2098,7 +2095,6 @@ gst_d3d11_compositor_aggregate_frames (GstVideoAggregator * vagg, } } GST_OBJECT_UNLOCK (self); - gst_d3d11_device_unlock (self->device); if (ret != GST_FLOW_OK) return ret; diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11convert.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11convert.cpp index 747a6c6e55..3cbe16c02b 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11convert.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11convert.cpp @@ -1596,7 +1596,6 @@ gst_d3d11_base_convert_crop_and_copy (GstD3D11BaseConvert * self, guint in_subresource; guint out_subresource; ID3D11Texture2D *in_tex, *out_tex; - gboolean ret = FALSE; /* Copy into output memory */ in_mem = gst_buffer_peek_memory (inbuf, 0); @@ -1636,18 +1635,18 @@ gst_d3d11_base_convert_crop_and_copy (GstD3D11BaseConvert * self, in_subresource = gst_d3d11_memory_get_subresource_index (in_dmem); out_subresource = gst_d3d11_memory_get_subresource_index (out_dmem); - gst_d3d11_device_lock (device); + GstD3D11DeviceLockGuard lk (device); if (!gst_memory_map (in_mem, &in_map, (GstMapFlags) (GST_MAP_READ | GST_MAP_D3D11))) { GST_ERROR_OBJECT (self, "Failed to map input memory"); - goto out; + return FALSE; } if (!gst_memory_map (out_mem, &out_map, (GstMapFlags) (GST_MAP_WRITE | GST_MAP_D3D11))) { GST_ERROR_OBJECT (self, "Failed to map output memory"); gst_memory_unmap (in_mem, &in_map); - goto out; + return FALSE; } in_tex = (ID3D11Texture2D *) in_map.data; @@ -1658,10 +1657,8 @@ gst_d3d11_base_convert_crop_and_copy (GstD3D11BaseConvert * self, gst_memory_unmap (in_mem, &in_map); gst_memory_unmap (out_mem, &out_map); - if (gst_buffer_n_memory (inbuf) == 1) { - gst_d3d11_device_unlock (device); + if (gst_buffer_n_memory (inbuf) == 1) return TRUE; - } /* Non-native DXGI format YUV cases, copy UV plane(s) */ switch (format) { @@ -1698,7 +1695,7 @@ gst_d3d11_base_convert_crop_and_copy (GstD3D11BaseConvert * self, default: GST_ERROR_OBJECT (self, "Unexpected format %s", gst_video_format_to_string (format)); - goto out; + return FALSE; } GST_TRACE_OBJECT (self, "UV left:top:right:bottom = %d, %d, %d, %d", @@ -1710,12 +1707,12 @@ gst_d3d11_base_convert_crop_and_copy (GstD3D11BaseConvert * self, if (!gst_is_d3d11_memory (in_mem)) { GST_ERROR_OBJECT (self, "Input is not a d3d11 memory"); - goto out; + return FALSE; } if (!gst_is_d3d11_memory (out_mem)) { GST_ERROR_OBJECT (self, "Output is not a d3d11 memory"); - goto out; + return FALSE; } in_dmem = GST_D3D11_MEMORY_CAST (in_mem); @@ -1723,7 +1720,7 @@ gst_d3d11_base_convert_crop_and_copy (GstD3D11BaseConvert * self, if (in_dmem->device != out_dmem->device) { GST_ERROR_OBJECT (self, "Different device"); - goto out; + return FALSE; } in_subresource = gst_d3d11_memory_get_subresource_index (in_dmem); @@ -1732,14 +1729,14 @@ gst_d3d11_base_convert_crop_and_copy (GstD3D11BaseConvert * self, if (!gst_memory_map (in_mem, &in_map, (GstMapFlags) (GST_MAP_READ | GST_MAP_D3D11))) { GST_ERROR_OBJECT (self, "Failed to map input memory"); - goto out; + return FALSE; } if (!gst_memory_map (out_mem, &out_map, (GstMapFlags) (GST_MAP_WRITE | GST_MAP_D3D11))) { GST_ERROR_OBJECT (self, "Failed to map output memory"); gst_memory_unmap (in_mem, &in_map); - goto out; + return FALSE; } in_tex = (ID3D11Texture2D *) in_map.data; @@ -1751,11 +1748,7 @@ gst_d3d11_base_convert_crop_and_copy (GstD3D11BaseConvert * self, gst_memory_unmap (out_mem, &out_map); } - ret = TRUE; - -out: - gst_d3d11_device_unlock (device); - return ret; + return TRUE; } static GstFlowReturn diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11converter.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11converter.cpp index 01a1ec0b64..b6730a7241 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11converter.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11converter.cpp @@ -1264,13 +1264,12 @@ gst_d3d11_color_convert_setup_shader (GstD3D11Converter * self, return FALSE; } - gst_d3d11_device_lock (device); + GstD3D11DeviceLockGuard lk (device); hr = context_handle->Map (const_buffer.Get (), 0, D3D11_MAP_WRITE_DISCARD, 0, &map); if (!gst_d3d11_result (hr, device)) { GST_ERROR_OBJECT (self, "Couldn't map constant buffer, hr: 0x%x", (guint) hr); - gst_d3d11_device_unlock (device); return FALSE; } @@ -1281,7 +1280,6 @@ gst_d3d11_color_convert_setup_shader (GstD3D11Converter * self, &map); if (!gst_d3d11_result (hr, device)) { GST_ERROR_OBJECT (self, "Couldn't map vertex buffer, hr: 0x%x", (guint) hr); - gst_d3d11_device_unlock (device); return FALSE; } @@ -1292,7 +1290,6 @@ gst_d3d11_color_convert_setup_shader (GstD3D11Converter * self, if (!gst_d3d11_result (hr, device)) { GST_ERROR_OBJECT (self, "Couldn't map index buffer, hr: 0x%x", (guint) hr); context_handle->Unmap (vertex_buffer.Get (), 0); - gst_d3d11_device_unlock (device); return FALSE; } @@ -1337,7 +1334,6 @@ gst_d3d11_color_convert_setup_shader (GstD3D11Converter * self, context_handle->Unmap (vertex_buffer.Get (), 0); context_handle->Unmap (index_buffer.Get (), 0); - gst_d3d11_device_unlock (device); /* holds vertex buffer for crop rect update */ priv->vertex_buffer = vertex_buffer.Detach (); @@ -2811,7 +2807,7 @@ gst_d3d11_converter_setup_processor (GstD3D11Converter * self) return FALSE; } - gst_d3d11_device_lock (device); + GstD3D11DeviceLockGuard lk (device); /* We don't want auto processing by driver */ video_context1->VideoProcessorSetStreamAutoProcessingMode (processor.Get (), 0, FALSE); @@ -2819,7 +2815,6 @@ gst_d3d11_converter_setup_processor (GstD3D11Converter * self) 0, (DXGI_COLOR_SPACE_TYPE) in_space.dxgi_color_space_type); video_context1->VideoProcessorSetOutputColorSpace1 (processor.Get (), (DXGI_COLOR_SPACE_TYPE) in_space.dxgi_color_space_type); - gst_d3d11_device_unlock (device); priv->video_device = video_device; video_device->AddRef (); @@ -3795,18 +3790,14 @@ gboolean gst_d3d11_converter_convert_buffer (GstD3D11Converter * converter, GstBuffer * in_buf, GstBuffer * out_buf) { - gboolean ret; - g_return_val_if_fail (GST_IS_D3D11_CONVERTER (converter), FALSE); g_return_val_if_fail (GST_IS_BUFFER (in_buf), FALSE); g_return_val_if_fail (GST_IS_BUFFER (out_buf), FALSE); - gst_d3d11_device_lock (converter->device); - ret = gst_d3d11_converter_convert_buffer_internal (converter, - in_buf, out_buf); - gst_d3d11_device_unlock (converter->device); + GstD3D11DeviceLockGuard lk (converter->device); - return ret; + return gst_d3d11_converter_convert_buffer_internal (converter, + in_buf, out_buf); } gboolean diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11decoder.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11decoder.cpp index 7f332d6320..fd000c04c8 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11decoder.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11decoder.cpp @@ -833,6 +833,7 @@ gst_d3d11_decoder_open (GstD3D11Decoder * self) GstD3D11DeviceVendor vendor; ID3D11VideoDevice *video_device; GstVideoInfo *info = &self->info; + GstD3D11DeviceLockGuard lk (self->device); if (self->opened) return TRUE; @@ -844,7 +845,6 @@ gst_d3d11_decoder_open (GstD3D11Decoder * self) video_device = self->video_device; - gst_d3d11_device_lock (self->device); if (!gst_d3d11_decoder_get_supported_decoder_profile (self->device, self->codec, GST_VIDEO_INFO_FORMAT (info), &selected_profile)) { goto error; @@ -1001,7 +1001,6 @@ gst_d3d11_decoder_open (GstD3D11Decoder * self) self->wait_on_pool_full = FALSE; self->opened = TRUE; - gst_d3d11_device_unlock (self->device); gst_d3d11_decoder_enable_high_precision_timer (self); @@ -1009,7 +1008,6 @@ gst_d3d11_decoder_open (GstD3D11Decoder * self) error: gst_d3d11_decoder_reset (self); - gst_d3d11_device_unlock (self->device); return FALSE; } @@ -1175,12 +1173,9 @@ gst_d3d11_decoder_decode_frame (GstD3D11Decoder * decoder, buffer_desc_size++; } - gst_d3d11_device_lock (decoder->device); - if (!gst_d3d11_decoder_begin_frame (decoder, output_view, 0, nullptr)) { - gst_d3d11_device_unlock (decoder->device); - + GstD3D11DeviceLockGuard lk (decoder->device); + if (!gst_d3d11_decoder_begin_frame (decoder, output_view, 0, nullptr)) return FALSE; - } if (!gst_d3d11_decoder_get_decoder_buffer (decoder, D3D11_VIDEO_DECODER_BUFFER_PICTURE_PARAMETERS, &d3d11_buffer_size, @@ -1293,18 +1288,13 @@ gst_d3d11_decoder_decode_frame (GstD3D11Decoder * decoder, goto error; } - if (!gst_d3d11_decoder_end_frame (decoder)) { - gst_d3d11_device_unlock (decoder->device); + if (!gst_d3d11_decoder_end_frame (decoder)) return FALSE; - } - - gst_d3d11_device_unlock (decoder->device); return TRUE; error: gst_d3d11_decoder_end_frame (decoder); - gst_d3d11_device_unlock (decoder->device); return FALSE; } @@ -1415,6 +1405,7 @@ gst_d3d11_decoder_crop_and_copy_texture (GstD3D11Decoder * self, ID3D11DeviceContext *context = gst_d3d11_device_get_device_context_handle (device); D3D11_BOX src_box = { 0, }; + GstD3D11DeviceLockGuard lk (device); src_box.left = self->offset_x; src_box.top = self->offset_y; @@ -1423,10 +1414,8 @@ gst_d3d11_decoder_crop_and_copy_texture (GstD3D11Decoder * self, src_box.front = 0; src_box.back = 1; - gst_d3d11_device_lock (device); context->CopySubresourceRegion (dst_texture, dst_subresource, 0, 0, 0, src_texture, src_subresource, &src_box); - gst_d3d11_device_unlock (device); } static gboolean @@ -1472,6 +1461,7 @@ gst_d3d11_decoder_crop_and_copy_buffer (GstD3D11Decoder * self, if (!gst_d3d11_decoder_ensure_staging_texture (self)) return FALSE; + GstD3D11DeviceLockGuard lk (device); if (!gst_video_frame_map (&frame, &self->output_info, dst, GST_MAP_WRITE)) { GST_ERROR_OBJECT (self, "Failed to map output buffer"); return FALSE; @@ -1480,11 +1470,9 @@ gst_d3d11_decoder_crop_and_copy_buffer (GstD3D11Decoder * self, gst_d3d11_decoder_crop_and_copy_texture (self, src_texture, src_subresource, self->staging, 0); - gst_d3d11_device_lock (device); hr = context->Map (self->staging, 0, D3D11_MAP_READ, 0, &d3d11_map); if (!gst_d3d11_result (hr, device)) { GST_ERROR_OBJECT (self, "Failed to map staging texture"); - gst_d3d11_device_unlock (device); gst_video_frame_unmap (&frame); return FALSE; } @@ -1507,7 +1495,6 @@ gst_d3d11_decoder_crop_and_copy_buffer (GstD3D11Decoder * self, } context->Unmap (self->staging, 0); - gst_d3d11_device_unlock (device); gst_video_frame_unmap (&frame); return TRUE; diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11deinterlace.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11deinterlace.cpp index 2ff2b2961c..366f0777d9 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11deinterlace.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11deinterlace.cpp @@ -1210,7 +1210,7 @@ gst_d3d11_deinterlace_set_caps (GstBaseTransform * trans, if (self->method == GST_D3D11_DEINTERLACE_METHOD_BLEND) output_rate = D3D11_VIDEO_PROCESSOR_OUTPUT_RATE_HALF; - gst_d3d11_device_lock (self->device); + GstD3D11DeviceLockGuard lk (self->device); self->video_context->VideoProcessorSetStreamSourceRect (self->video_proc, 0, TRUE, &rect); self->video_context->VideoProcessorSetStreamDestRect (self->video_proc, @@ -1221,7 +1221,6 @@ gst_d3d11_deinterlace_set_caps (GstBaseTransform * trans, VideoProcessorSetStreamAutoProcessingMode (self->video_proc, 0, FALSE); self->video_context->VideoProcessorSetStreamOutputRate (self->video_proc, 0, output_rate, TRUE, NULL); - gst_d3d11_device_unlock (self->device); return TRUE; } @@ -1755,13 +1754,12 @@ gst_d3d11_deinterlace_transform (GstBaseTransform * trans, GstBuffer * inbuf, proc_stream.ppPastSurfaces = past_surfaces; } - gst_d3d11_device_lock (self->device); + GstD3D11DeviceLockGuard lk (self->device); self->video_context->VideoProcessorSetStreamFrameFormat (self->video_proc, 0, frame_foramt); hr = self->video_context->VideoProcessorBlt (self->video_proc, pov, 0, 1, &proc_stream); - gst_d3d11_device_unlock (self->device); if (!gst_d3d11_result (hr, self->device)) { GST_ERROR_OBJECT (self, "Failed to perform deinterlacing"); diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11overlaycompositor.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11overlaycompositor.cpp index eb80fb4707..8bbcb5e1f4 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11overlaycompositor.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11overlaycompositor.cpp @@ -254,13 +254,12 @@ gst_d3d11_composition_overlay_new (GstD3D11OverlayCompositor * self, return nullptr; } - gst_d3d11_device_lock (device); + GstD3D11DeviceLockGuard lk (device); hr = context_handle->Map (vertex_buffer.Get (), 0, D3D11_MAP_WRITE_DISCARD, 0, &map); if (!gst_d3d11_result (hr, device)) { GST_ERROR_OBJECT (self, "Couldn't map vertex buffer, hr: 0x%x", (guint) hr); - gst_d3d11_device_unlock (device); return nullptr; } @@ -310,7 +309,6 @@ gst_d3d11_composition_overlay_new (GstD3D11OverlayCompositor * self, vertex_data[3].texture.v = 1.0f; context_handle->Unmap (vertex_buffer.Get (), 0); - gst_d3d11_device_unlock (device); overlay = g_new0 (GstD3D11CompositionOverlay, 1); overlay->overlay_rect = gst_video_overlay_rectangle_ref (overlay_rect); @@ -441,13 +439,12 @@ gst_d3d11_overlay_compositor_setup_shader (GstD3D11OverlayCompositor * self) return FALSE; } - gst_d3d11_device_lock (device); + GstD3D11DeviceLockGuard lk (device); hr = context_handle->Map (index_buffer.Get (), 0, D3D11_MAP_WRITE_DISCARD, 0, &map); if (!gst_d3d11_result (hr, device)) { GST_ERROR_OBJECT (self, "Couldn't map index buffer, hr: 0x%x", (guint) hr); - gst_d3d11_device_unlock (device); return FALSE; } @@ -463,7 +460,6 @@ gst_d3d11_overlay_compositor_setup_shader (GstD3D11OverlayCompositor * self) indices[5] = 2; /* top right */ context_handle->Unmap (index_buffer.Get (), 0); - gst_d3d11_device_unlock (device); priv->ps = ps.Detach (); priv->vs = vs.Detach (); @@ -623,16 +619,11 @@ gboolean gst_d3d11_overlay_compositor_draw (GstD3D11OverlayCompositor * compositor, ID3D11RenderTargetView * rtv[GST_VIDEO_MAX_PLANES]) { - gboolean ret = TRUE; - g_return_val_if_fail (compositor != nullptr, FALSE); g_return_val_if_fail (rtv != nullptr, FALSE); - gst_d3d11_device_lock (compositor->device); - ret = gst_d3d11_overlay_compositor_draw_unlocked (compositor, rtv); - gst_d3d11_device_unlock (compositor->device); - - return ret; + GstD3D11DeviceLockGuard lk (compositor->device); + return gst_d3d11_overlay_compositor_draw_unlocked (compositor, rtv); } gboolean diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.cpp index dee92a6a2d..bb0f50f51a 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.cpp @@ -948,10 +948,9 @@ gst_d3d11_buffer_copy_into (GstBuffer * dst, GstBuffer * src, dst_subidx = gst_d3d11_memory_get_subresource_index (dst_dmem); src_subidx = gst_d3d11_memory_get_subresource_index (src_dmem); - gst_d3d11_device_lock (device); + GstD3D11DeviceLockGuard lk (device); device_context->CopySubresourceRegion (dst_texture, dst_subidx, 0, 0, 0, src_texture, src_subidx, &src_box); - gst_d3d11_device_unlock (device); gst_memory_unmap (src_mem, &src_info); gst_memory_unmap (dst_mem, &dst_info); diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11testsrc.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11testsrc.cpp index 71e74c3470..4389d727fa 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11testsrc.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11testsrc.cpp @@ -405,12 +405,11 @@ setup_snow_render (GstD3D11TestSrc * self, GstD3D11TestSrcRender * render, return FALSE; } - gst_d3d11_device_lock (self->device); + GstD3D11DeviceLockGuard lk (self->device); hr = context_handle->Map (vertex_buffer.Get (), 0, D3D11_MAP_WRITE_DISCARD, 0, &map); if (!gst_d3d11_result (hr, self->device)) { GST_ERROR_OBJECT (self, "Failed to map vertex buffer"); - gst_d3d11_device_unlock (self->device); return FALSE; } vertex_data = (UvVertexData *) map.pData; @@ -420,7 +419,6 @@ setup_snow_render (GstD3D11TestSrc * self, GstD3D11TestSrcRender * render, if (!gst_d3d11_result (hr, self->device)) { GST_ERROR_OBJECT (self, "Failed to map index buffer"); context_handle->Unmap (vertex_buffer.Get (), 0); - gst_d3d11_device_unlock (self->device); return FALSE; } indices = (WORD *) map.pData; @@ -506,7 +504,6 @@ setup_snow_render (GstD3D11TestSrc * self, GstD3D11TestSrcRender * render, context_handle->Unmap (vertex_buffer.Get (), 0); context_handle->Unmap (index_buffer.Get (), 0); - gst_d3d11_device_unlock (self->device); quad = g_new0 (GstD3D11TestSrcQuad, 1); if (on_smpte) @@ -602,12 +599,11 @@ setup_smpte_render (GstD3D11TestSrc * self, GstD3D11TestSrcRender * render) return FALSE; } - gst_d3d11_device_lock (self->device); + GstD3D11DeviceLockGuard lk (self->device); hr = context_handle->Map (vertex_buffer.Get (), 0, D3D11_MAP_WRITE_DISCARD, 0, &map); if (!gst_d3d11_result (hr, self->device)) { GST_ERROR_OBJECT (self, "Failed to map vertex buffer"); - gst_d3d11_device_unlock (self->device); return FALSE; } vertex_data = (ColorVertexData *) map.pData; @@ -617,7 +613,6 @@ setup_smpte_render (GstD3D11TestSrc * self, GstD3D11TestSrcRender * render) if (!gst_d3d11_result (hr, self->device)) { GST_ERROR_OBJECT (self, "Failed to map index buffer"); context_handle->Unmap (vertex_buffer.Get (), 0); - gst_d3d11_device_unlock (self->device); return FALSE; } indices = (WORD *) map.pData; @@ -849,7 +844,6 @@ setup_smpte_render (GstD3D11TestSrc * self, GstD3D11TestSrcRender * render) context_handle->Unmap (vertex_buffer.Get (), 0); context_handle->Unmap (index_buffer.Get (), 0); - gst_d3d11_device_unlock (self->device); render->quad[0] = quad = g_new0 (GstD3D11TestSrcQuad, 1); @@ -943,12 +937,11 @@ setup_checker_render (GstD3D11TestSrc * self, GstD3D11TestSrcRender * render, return FALSE; } - gst_d3d11_device_lock (self->device); + GstD3D11DeviceLockGuard lk (self->device); hr = context_handle->Map (vertex_buffer.Get (), 0, D3D11_MAP_WRITE_DISCARD, 0, &map); if (!gst_d3d11_result (hr, self->device)) { GST_ERROR_OBJECT (self, "Failed to map vertex buffer"); - gst_d3d11_device_unlock (self->device); return FALSE; } vertex_data = (UvVertexData *) map.pData; @@ -958,7 +951,6 @@ setup_checker_render (GstD3D11TestSrc * self, GstD3D11TestSrcRender * render, if (!gst_d3d11_result (hr, self->device)) { GST_ERROR_OBJECT (self, "Failed to map index buffer"); context_handle->Unmap (vertex_buffer.Get (), 0); - gst_d3d11_device_unlock (self->device); return FALSE; } indices = (WORD *) map.pData; @@ -1001,7 +993,6 @@ setup_checker_render (GstD3D11TestSrc * self, GstD3D11TestSrcRender * render, context_handle->Unmap (vertex_buffer.Get (), 0); context_handle->Unmap (index_buffer.Get (), 0); - gst_d3d11_device_unlock (self->device); render->quad[0] = quad = g_new0 (GstD3D11TestSrcQuad, 1); @@ -1698,6 +1689,7 @@ gst_d3d11_test_src_create (GstBaseSrc * bsrc, guint64 offset, GstD3D11Memory *dmem; ID3D11RenderTargetView *pattern_rtv; gboolean convert_ret; + GstD3D11DeviceLockGuard lk (self->device); ret = GST_BASE_SRC_CLASS (parent_class)->alloc (bsrc, offset, size, &buffer); if (ret != GST_FLOW_OK) @@ -1720,11 +1712,9 @@ gst_d3d11_test_src_create (GstBaseSrc * bsrc, guint64 offset, mem = gst_buffer_peek_memory (render_buffer, 0); - gst_d3d11_device_lock (self->device); if (!gst_memory_map (mem, &render_info, (GstMapFlags) (GST_MAP_WRITE | GST_MAP_D3D11))) { GST_ERROR_OBJECT (self, "Failed to map render buffer"); - gst_d3d11_device_unlock (self->device); goto error; } @@ -1733,7 +1723,6 @@ gst_d3d11_test_src_create (GstBaseSrc * bsrc, guint64 offset, if (!pattern_rtv) { GST_ERROR_OBJECT (self, "RTV is not available"); gst_memory_unmap (mem, &render_info); - gst_d3d11_device_unlock (self->device); goto error; } @@ -1741,7 +1730,6 @@ gst_d3d11_test_src_create (GstBaseSrc * bsrc, guint64 offset, gst_memory_unmap (mem, &render_info); convert_ret = gst_d3d11_converter_convert_buffer_unlocked (self->converter, render_buffer, convert_buffer); - gst_d3d11_device_unlock (self->device); if (!convert_ret) { GST_ERROR_OBJECT (self, "Failed to convert buffer"); diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11window.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11window.cpp index 7b3b35b07c..6a35b59e12 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11window.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11window.cpp @@ -282,12 +282,11 @@ gst_d3d11_window_on_resize_default (GstD3D11Window * self, guint width, GstD3D11Memory *dmem; ID3D11RenderTargetView *rtv; gsize size; - - gst_d3d11_device_lock (device); + GstD3D11DeviceLockGuard lk (device); gst_clear_buffer (&self->backbuffer); if (!self->swap_chain) - goto done; + return; swap_chain = self->swap_chain; swap_chain->GetDesc (&swap_desc); @@ -295,14 +294,14 @@ gst_d3d11_window_on_resize_default (GstD3D11Window * self, guint width, swap_desc.Flags); if (!gst_d3d11_result (hr, device)) { GST_ERROR_OBJECT (self, "Couldn't resize buffers, hr: 0x%x", (guint) hr); - goto done; + return; } hr = swap_chain->GetBuffer (0, IID_PPV_ARGS (&backbuffer)); if (!gst_d3d11_result (hr, device)) { GST_ERROR_OBJECT (self, "Cannot get backbuffer from swapchain, hr: 0x%x", (guint) hr); - goto done; + return; } backbuffer->GetDesc (&desc); @@ -320,7 +319,7 @@ gst_d3d11_window_on_resize_default (GstD3D11Window * self, guint width, self->device, backbuffer.Get (), size, nullptr, nullptr); if (!mem) { GST_ERROR_OBJECT (self, "Couldn't allocate wrapped memory"); - goto done; + return; } dmem = GST_D3D11_MEMORY_CAST (mem); @@ -328,7 +327,7 @@ gst_d3d11_window_on_resize_default (GstD3D11Window * self, guint width, if (!rtv) { GST_ERROR_OBJECT (self, "RTV is unavailable"); gst_memory_unref (mem); - goto done; + return; } self->backbuffer = gst_buffer_new (); @@ -379,9 +378,6 @@ gst_d3d11_window_on_resize_default (GstD3D11Window * self, guint width, /* redraw the last scene if cached buffer exits */ if (self->cached_buffer) gst_d3d111_window_present (self, self->cached_buffer, self->backbuffer); - -done: - gst_d3d11_device_unlock (device); } void @@ -557,7 +553,7 @@ gst_d3d11_window_prepare_default (GstD3D11Window * window, guint display_width, if (SUCCEEDED (hr) && allow_tearing) window->allow_tearing = allow_tearing; - gst_d3d11_device_lock (device); + GstD3D11DeviceLockGuard lk (device); window->dxgi_format = chosen_format->dxgi_format; klass = GST_D3D11_WINDOW_GET_CLASS (window); @@ -568,7 +564,7 @@ gst_d3d11_window_prepare_default (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"); - goto error; + return FALSE; } /* this rect struct will be used to calculate render area */ @@ -675,7 +671,7 @@ gst_d3d11_window_prepare_default (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"); - goto error; + return FALSE; } if (have_hdr10_meta) { @@ -693,9 +689,8 @@ gst_d3d11_window_prepare_default (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"); - goto error; + return FALSE; } - gst_d3d11_device_unlock (window->device); /* call resize to allocated resources */ klass->on_resize (window, display_width, display_height); @@ -706,11 +701,6 @@ gst_d3d11_window_prepare_default (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 @@ -850,19 +840,14 @@ gst_d3d111_window_present (GstD3D11Window * self, GstBuffer * buffer, GstFlowReturn gst_d3d11_window_render (GstD3D11Window * window, GstBuffer * buffer) { - GstFlowReturn ret; - g_return_val_if_fail (GST_IS_D3D11_WINDOW (window), GST_FLOW_ERROR); - gst_d3d11_device_lock (window->device); + GstD3D11DeviceLockGuard lk (window->device); if (buffer) gst_buffer_replace (&window->cached_buffer, buffer); - ret = gst_d3d111_window_present (window, window->cached_buffer, + return gst_d3d111_window_present (window, window->cached_buffer, window->backbuffer); - gst_d3d11_device_unlock (window->device); - - return ret; } GstFlowReturn @@ -886,17 +871,15 @@ gst_d3d11_window_render_on_shared_handle (GstD3D11Window * window, data.acquire_key = acquire_key; data.release_key = release_key; - gst_d3d11_device_lock (window->device); + GstD3D11DeviceLockGuard (window->device); if (!klass->open_shared_handle (window, &data)) { GST_ERROR_OBJECT (window, "Couldn't open shared handle"); - gst_d3d11_device_unlock (window->device); return GST_FLOW_OK; } ret = gst_d3d111_window_present (window, buffer, data.render_target); klass->release_shared_handle (window, &data); - gst_d3d11_device_unlock (window->device); return ret; } @@ -930,9 +913,8 @@ gst_d3d11_window_unlock_stop (GstD3D11Window * window) if (klass->unlock_stop) ret = klass->unlock_stop (window); - gst_d3d11_device_lock (window->device); + GstD3D11DeviceLockGuard lk (window->device); gst_clear_buffer (&window->cached_buffer); - gst_d3d11_device_unlock (window->device); return ret; } @@ -1007,7 +989,7 @@ gst_d3d11_window_set_orientation (GstD3D11Window * window, return; } - gst_d3d11_device_lock (window->device); + GstD3D11DeviceLockGuard lk (window->device); if (window->method != method) { window->method = method; if (window->swap_chain) { @@ -1016,5 +998,4 @@ gst_d3d11_window_set_orientation (GstD3D11Window * window, klass->on_resize (window, window->surface_width, window->surface_height); } } - gst_d3d11_device_unlock (window->device); } diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11window_corewindow.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11window_corewindow.cpp index a2b4e5b3d3..2da1433a68 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11window_corewindow.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11window_corewindow.cpp @@ -390,10 +390,9 @@ create_swap_chain_for_core_window (GstD3D11WindowCoreWindow * self, return NULL; } - gst_d3d11_device_lock (device); + GstD3D11DeviceLockGuard lk (device); hr = factory2->CreateSwapChainForCoreWindow (device_handle, (IUnknown *) core_window, desc, output, &swap_chain); - gst_d3d11_device_unlock (device); if (!gst_d3d11_result (hr, device)) { GST_WARNING_OBJECT (self, "Cannot create SwapChain Object: 0x%x", diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11window_dummy.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11window_dummy.cpp index 595e40a17e..86fc88c443 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11window_dummy.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11window_dummy.cpp @@ -117,7 +117,7 @@ gst_d3d11_window_dummy_prepare (GstD3D11Window * window, window->render_info.colorimetry.transfer = GST_VIDEO_TRANSFER_BT709; window->render_info.colorimetry.range = GST_VIDEO_COLOR_RANGE_0_255; - gst_d3d11_device_lock (window->device); + GstD3D11DeviceLockGuard lk (window->device); window->converter = gst_d3d11_converter_new (window->device, &window->info, &window->render_info, &method); @@ -125,7 +125,7 @@ gst_d3d11_window_dummy_prepare (GstD3D11Window * window, GST_ERROR_OBJECT (window, "Cannot create converter"); g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_FAILED, "Cannot create converter"); - goto error; + return FALSE; } window->compositor = @@ -134,17 +134,10 @@ gst_d3d11_window_dummy_prepare (GstD3D11Window * window, GST_ERROR_OBJECT (window, "Cannot create overlay compositor"); g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_FAILED, "Cannot create overlay compositor"); - goto error; + return FALSE; } - gst_d3d11_device_unlock (window->device); - return TRUE; - -error: - gst_d3d11_device_unlock (window->device); - - return FALSE; } static void diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11window_swapchainpanel.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11window_swapchainpanel.cpp index 2e6773a260..26ad2eb7a9 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11window_swapchainpanel.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11window_swapchainpanel.cpp @@ -363,10 +363,9 @@ create_swap_chain_for_composition (GstD3D11WindowSwapChainPanel * self, return NULL; } - gst_d3d11_device_lock (device); + GstD3D11DeviceLockGuard lk (device); hr = factory2->CreateSwapChainForComposition (device_handle, desc, output, &swap_chain); - gst_d3d11_device_unlock (device); if (!gst_d3d11_result (hr, device)) { GST_WARNING_OBJECT (self, "Cannot create SwapChain Object: 0x%x", diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11window_win32.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11window_win32.cpp index 8d98cb3b89..ea8b9dff14 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11window_win32.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11window_win32.cpp @@ -888,9 +888,8 @@ create_swap_chain (GstD3D11WindowWin32 * self, GstD3D11Device * device, ID3D11Device *device_handle = gst_d3d11_device_get_device_handle (device); IDXGIFactory1 *factory = gst_d3d11_device_get_dxgi_factory_handle (device); - gst_d3d11_device_lock (device); + GstD3D11DeviceLockGuard lk (device); hr = factory->CreateSwapChain (device_handle, desc, &swap_chain); - gst_d3d11_device_unlock (device); if (!gst_d3d11_result (hr, device)) { GST_WARNING_OBJECT (self, "Cannot create SwapChain Object: 0x%x", @@ -918,10 +917,9 @@ create_swap_chain_for_hwnd (GstD3D11WindowWin32 * self, GstD3D11Device * device, return NULL; } - gst_d3d11_device_lock (device); + GstD3D11DeviceLockGuard lk (device); hr = factory2->CreateSwapChainForHwnd (device_handle, hwnd, desc, fullscreen_desc, output, &swap_chain); - gst_d3d11_device_unlock (device); if (!gst_d3d11_result (hr, device)) { GST_WARNING_OBJECT (self, "Cannot create SwapChain Object: 0x%x", @@ -1008,10 +1006,9 @@ gst_d3d11_window_win32_create_swap_chain (GstD3D11Window * window, } /* disable alt+enter here. It should be manually handled */ - gst_d3d11_device_lock (device); + GstD3D11DeviceLockGuard lk (device); gst_d3d11_window_win32_disable_alt_enter (self, device, new_swapchain, desc.OutputWindow); - gst_d3d11_device_unlock (device); *swap_chain = new_swapchain;