Such abstraction is unnecessary for this library/plugin.
Use WIN32 API directly instead of GLib wrappers.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2848>
GstVideoOrientationMethod video_direction;
- GMutex prop_lock;
+ SRWLOCK prop_lock;
/* properties */
gint src_x;
{
self->priv = (GstD3D11ConverterPrivate *)
gst_d3d11_converter_get_instance_private (self);
- g_mutex_init (&self->priv->prop_lock);
}
static void
g_free (priv->in_cll_str);
g_free (priv->out_cll_str);
- g_mutex_clear (&priv->prop_lock);
-
G_OBJECT_CLASS (parent_class)->finalize (object);
}
GstD3D11Converter *self = GST_D3D11_CONVERTER (object);
GstD3D11ConverterPrivate *priv = self->priv;
- g_mutex_lock (&priv->prop_lock);
+ GstD3D11SRWLockGuard (&priv->prop_lock);
switch (prop_id) {
case PROP_SRC_X:
update_src_rect (self, &priv->src_x, value);
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
- g_mutex_unlock (&priv->prop_lock);
}
static void
GstD3D11Converter *self = GST_D3D11_CONVERTER (object);
GstD3D11ConverterPrivate *priv = self->priv;
- g_mutex_lock (&priv->prop_lock);
+ GstD3D11SRWLockGuard (&priv->prop_lock);
switch (prop_id) {
case PROP_SRC_X:
g_value_set_int (value, priv->src_x);
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
- g_mutex_unlock (&priv->prop_lock);
}
static gboolean
UINT offsets = 0;
UINT vertex_stride = sizeof (VertexData);
ID3D11ShaderResourceView *clear_view[GST_VIDEO_MAX_PLANES] = { nullptr, };
- gboolean ret = TRUE;
priv = self->priv;
cinfo = &priv->convert_info;
resource.As (&texture);
texture->GetDesc (&desc);
- g_mutex_lock (&priv->prop_lock);
if (priv->update_dest_rect && !gst_d3d11_converter_update_dest_rect (self)) {
GST_ERROR_OBJECT (self, "Failed to update dest rect");
- ret = FALSE;
- goto out;
+ return FALSE;
}
if (priv->update_src_rect ||
if (!gst_d3d11_converter_update_src_rect (self)) {
GST_ERROR_OBJECT (self, "Cannot update src rect");
- ret = FALSE;
- goto out;
+ return FALSE;
}
}
if (!gst_d3d11_result (hr, self->device)) {
GST_ERROR_OBJECT (self,
"Couldn't map constant buffer, hr: 0x%x", (guint) hr);
- ret = FALSE;
- goto out;
+ return FALSE;
}
const_buffer = (PSConstBuffer *) map.pData;
context->PSSetShaderResources (0, 4, clear_view);
context->OMSetRenderTargets (0, nullptr, nullptr);
-out:
- g_mutex_unlock (&priv->prop_lock);
-
- return ret;
+ return TRUE;
}
static gboolean
return FALSE;
}
- g_mutex_lock (&priv->prop_lock);
+ GstD3D11SRWLockGuard (&priv->prop_lock);
gst_d3d11_converter_update_hdr10_meta (self);
if (priv->blend && priv->blend_desc.RenderTarget[0].BlendEnable) {
if (use_processor) {
if (!pov) {
GST_ERROR_OBJECT (self, "POV is unavailable");
- g_mutex_unlock (&priv->prop_lock);
goto out;
}
if (!piv) {
if (!gst_d3d11_converter_ensure_fallback_inbuf (self, in_buf, in_info)) {
GST_ERROR_OBJECT (self, "Couldn't copy into fallback texture");
- g_mutex_unlock (&priv->prop_lock);
goto out;
}
if (!gst_d3d11_converter_map_buffer (self,
in_buf, in_info, (GstMapFlags) (GST_MAP_READ | GST_MAP_D3D11))) {
GST_ERROR_OBJECT (self, "Couldn't map fallback buffer");
- g_mutex_unlock (&priv->prop_lock);
in_buf = nullptr;
goto out;
}
priv->video_device, priv->enumerator);
if (!piv) {
GST_ERROR_OBJECT (self, "Couldn't get POV from fallback buffer");
- g_mutex_unlock (&priv->prop_lock);
goto out;
}
}
if (priv->update_dest_rect && !gst_d3d11_converter_update_dest_rect (self)) {
GST_ERROR_OBJECT (self, "Failed to update dest rect");
- g_mutex_unlock (&priv->prop_lock);
goto out;
}
if (priv->update_src_rect && !gst_d3d11_converter_update_src_rect (self)) {
GST_ERROR_OBJECT (self, "Cannot update src rect");
- g_mutex_unlock (&priv->prop_lock);
goto out;
}
GST_TRACE_OBJECT (self, "Converting using processor");
hr = video_ctx->VideoProcessorBlt (proc, pov, 0, 1, &stream);
- g_mutex_unlock (&priv->prop_lock);
- ret = gst_d3d11_result (hr, self->device);;
+ ret = gst_d3d11_result (hr, self->device);
goto out;
}
- g_mutex_unlock (&priv->prop_lock);
-
if ((priv->supported_backend & GST_D3D11_CONVERTER_BACKEND_SHADER) == 0) {
GST_ERROR_OBJECT (self, "Conversion is not supported");
goto out;
GArray *format_table;
CRITICAL_SECTION extern_lock;
- GMutex resource_lock;
+ SRWLOCK resource_lock;
LARGE_INTEGER frequency;
sizeof (GstD3D11Format), GST_D3D11_N_FORMATS);
InitializeCriticalSection (&priv->extern_lock);
- g_mutex_init (&priv->resource_lock);
self->priv = priv;
}
g_array_unref (priv->format_table);
DeleteCriticalSection (&priv->extern_lock);
- g_mutex_clear (&priv->resource_lock);
g_free (priv->description);
G_OBJECT_CLASS (parent_class)->finalize (object);
g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), NULL);
priv = device->priv;
- g_mutex_lock (&priv->resource_lock);
+ GstD3D11SRWLockGuard lk (&priv->resource_lock);
if (!priv->video_device) {
HRESULT hr;
ID3D11VideoDevice *video_device = NULL;
if (gst_d3d11_result (hr, device))
priv->video_device = video_device;
}
- g_mutex_unlock (&priv->resource_lock);
return priv->video_device;
}
g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), NULL);
priv = device->priv;
- g_mutex_lock (&priv->resource_lock);
+ GstD3D11SRWLockGuard lk (&priv->resource_lock);
if (!priv->video_context) {
HRESULT hr;
ID3D11VideoContext *video_context = NULL;
if (gst_d3d11_result (hr, device))
priv->video_context = video_context;
}
- g_mutex_unlock (&priv->resource_lock);
return priv->video_context;
}
/* method previously selected and used for negotiation */
GstVideoOrientationMethod active_method;
- GMutex lock;
+ SRWLOCK lock;
};
/**
"d3d11convert"));
static void gst_d3d11_base_convert_dispose (GObject * object);
-static void gst_d3d11_base_convert_finalize (GObject * object);
static GstCaps *gst_d3d11_base_convert_transform_caps (GstBaseTransform *
trans, GstPadDirection direction, GstCaps * caps, GstCaps * filter);
static GstCaps *gst_d3d11_base_convert_fixate_caps (GstBaseTransform *
GstCaps *caps;
gobject_class->dispose = gst_d3d11_base_convert_dispose;
- gobject_class->finalize = gst_d3d11_base_convert_finalize;
caps = gst_d3d11_get_updated_template_caps (&sink_template_caps);
gst_element_class_add_pad_template (element_class,
self->border_color = DEFAULT_BORDER_COLOR;
self->gamma_mode = DEFAULT_GAMMA_MODE;
self->primaries_mode = DEFAULT_PRIMARIES_MODE;
-
- g_mutex_init (&self->lock);
}
static void
{
GstD3D11BaseConvert *self = GST_D3D11_BASE_CONVERT (object);
- g_mutex_lock (&self->lock);
gst_clear_object (&self->converter);
- g_mutex_unlock (&self->lock);
G_OBJECT_CLASS (parent_class)->dispose (object);
}
-static void
-gst_d3d11_base_convert_finalize (GObject * object)
-{
- GstD3D11BaseConvert *self = GST_D3D11_BASE_CONVERT (object);
-
- g_mutex_clear (&self->lock);
-
- G_OBJECT_CLASS (parent_class)->finalize (object);
-}
-
static GstCaps *
gst_d3d11_base_convert_transform_caps (GstBaseTransform *
trans, GstPadDirection direction, GstCaps * caps, GstCaps * filter)
* assume that missing PAR on the sinkpad means 1/1 and
* missing PAR on the srcpad means undefined
*/
- g_mutex_lock (&self->lock);
+ GstD3D11SRWLockGuard lk (&self->lock);
switch (self->selected_method) {
case GST_VIDEO_ORIENTATION_90R:
case GST_VIDEO_ORIENTATION_90L:
g_value_unset (&fpar);
if (to_par == &tpar)
g_value_unset (&tpar);
- g_mutex_unlock (&self->lock);
return othercaps;
}
gint in_width, in_height, in_par_n, in_par_d;
GstStructure *config;
- g_mutex_lock (&self->lock);
+ GstD3D11SRWLockGuard lk (&self->lock);
self->active_method = self->selected_method;
if (self->active_method != GST_VIDEO_ORIENTATION_IDENTITY)
if (!need_flip && gst_caps_is_equal (incaps, outcaps)) {
self->same_caps = TRUE;
- g_mutex_unlock (&self->lock);
return TRUE;
} else {
self->same_caps = FALSE;
/* if present, these must match */
if (in_info->interlace_mode != out_info->interlace_mode) {
GST_ERROR_OBJECT (self, "input and output formats do not match");
- g_mutex_unlock (&self->lock);
return FALSE;
}
self->borders_h == 0 && !need_flip &&
!gst_d3d11_base_convert_needs_color_convert (self, in_info, out_info)) {
self->same_caps = TRUE;
- g_mutex_unlock (&self->lock);
return TRUE;
}
config);
if (!self->converter) {
GST_ERROR_OBJECT (self, "Couldn't create converter");
- g_mutex_unlock (&self->lock);
return FALSE;
}
self->border_color, nullptr);
}
- g_mutex_unlock (&self->lock);
-
return TRUE;
}
gst_d3d11_base_convert_set_border_color (GstD3D11BaseConvert * self,
guint64 border_color)
{
- g_mutex_lock (&self->lock);
+ GstD3D11SRWLockGuard lk (&self->lock);
self->border_color = border_color;
if (self->converter)
g_object_set (self->converter, "border-color", self->border_color, nullptr);
- g_mutex_unlock (&self->lock);
}
static void
return;
}
- g_mutex_lock (&self->lock);
+ GstD3D11SRWLockGuard lk (&self->lock);
if (from_tag)
self->tag_method = method;
else
gst_base_transform_reconfigure_src (GST_BASE_TRANSFORM (self));
}
-
- g_mutex_unlock (&self->lock);
}
static void
gst_d3d11_base_convert_set_gamma_mode (GstD3D11BaseConvert * self,
GstVideoGammaMode mode)
{
- g_mutex_lock (&self->lock);
+ GstD3D11SRWLockGuard lk (&self->lock);
if (self->gamma_mode != mode) {
GST_DEBUG_OBJECT (self, "Gamma mode %d -> %d", self->gamma_mode, mode);
self->gamma_mode = mode;
gst_base_transform_reconfigure_src (GST_BASE_TRANSFORM (self));
}
- g_mutex_unlock (&self->lock);
}
static void
gst_d3d11_base_convert_set_primaries_mode (GstD3D11BaseConvert * self,
GstVideoPrimariesMode mode)
{
- g_mutex_lock (&self->lock);
+ GstD3D11SRWLockGuard lk (&self->lock);
if (self->primaries_mode != mode) {
gboolean prev_enabled = TRUE;
gboolean new_enabled = TRUE;
if (prev_enabled != new_enabled)
gst_base_transform_reconfigure_src (GST_BASE_TRANSFORM (self));
}
- g_mutex_unlock (&self->lock);
}
/**
GstVideoCodecState *output_state;
/* Protect internal pool */
- GMutex internal_pool_lock;
+ SRWLOCK internal_pool_lock;
GstBufferPool *internal_pool;
/* Internal pool params */
static void
gst_d3d11_decoder_init (GstD3D11Decoder * self)
{
- g_mutex_init (&self->internal_pool_lock);
}
static void
static void
gst_d3d11_decoder_clear_resource (GstD3D11Decoder * self)
{
- g_mutex_lock (&self->internal_pool_lock);
+ GstD3D11SRWLockGuard lk (&self->internal_pool_lock);
if (self->internal_pool) {
gst_buffer_pool_set_active (self->internal_pool, FALSE);
gst_clear_object (&self->internal_pool);
}
- g_mutex_unlock (&self->internal_pool_lock);
GST_D3D11_CLEAR_COM (self->decoder_handle);
GST_D3D11_CLEAR_COM (self->staging);
static void
gst_d3d11_decoder_finalize (GObject * obj)
{
+#if HAVE_WINMM
GstD3D11Decoder *self = GST_D3D11_DECODER (obj);
-#if HAVE_WINMM
/* Restore clock precision */
if (self->timer_resolution)
timeEndPeriod (self->timer_resolution);
#endif
- g_mutex_clear (&self->internal_pool_lock);
-
G_OBJECT_CLASS (parent_class)->finalize (obj);
}
GstVideoInfo *info = &self->info;
guint pool_size;
- g_mutex_lock (&self->internal_pool_lock);
+ GstD3D11SRWLockGuard lk (&self->internal_pool_lock);
if (self->internal_pool) {
gst_buffer_pool_set_active (self->internal_pool, FALSE);
gst_clear_object (&self->internal_pool);
}
- g_mutex_unlock (&self->internal_pool_lock);
if (!self->use_array_of_texture) {
alloc_flags = GST_D3D11_ALLOCATION_FLAG_TEXTURE_ARRAY;
goto error;
}
- g_mutex_lock (&self->internal_pool_lock);
self->internal_pool = pool;
- g_mutex_unlock (&self->internal_pool_lock);
return TRUE;
{
g_return_val_if_fail (GST_IS_D3D11_DECODER (decoder), FALSE);
- g_mutex_lock (&decoder->internal_pool_lock);
+ GstD3D11SRWLockGuard lk (&decoder->internal_pool_lock);
if (decoder->internal_pool)
gst_buffer_pool_set_flushing (decoder->internal_pool, flushing);
- g_mutex_unlock (&decoder->internal_pool_lock);
return TRUE;
}
{
GstD3D11Window parent;
- GMutex lock;
- GCond cond;
+ SRWLOCK lock;
+ CONDITION_VARIABLE cond;
GMainContext *main_context;
GMainLoop *loop;
static void gst_d3d11_window_win32_constructed (GObject * object);
static void gst_d3d11_window_win32_dispose (GObject * object);
-static void gst_d3d11_window_win32_finalize (GObject * object);
static void gst_d3d11_window_win32_show (GstD3D11Window * window);
static void gst_d3d11_window_win32_update_swap_chain (GstD3D11Window * window);
gobject_class->constructed = gst_d3d11_window_win32_constructed;
gobject_class->dispose = gst_d3d11_window_win32_dispose;
- gobject_class->finalize = gst_d3d11_window_win32_finalize;
window_class->show = GST_DEBUG_FUNCPTR (gst_d3d11_window_win32_show);
window_class->update_swap_chain =
static void
gst_d3d11_window_win32_init (GstD3D11WindowWin32 * self)
{
- g_mutex_init (&self->lock);
- g_cond_init (&self->cond);
-
self->main_context = g_main_context_new ();
}
goto done;
}
- g_mutex_lock (&self->lock);
+ AcquireSRWLockExclusive (&self->lock);
self->loop = g_main_loop_new (self->main_context, FALSE);
self->thread = g_thread_new ("GstD3D11WindowWin32",
(GThreadFunc) gst_d3d11_window_win32_thread_func, self);
while (!g_main_loop_is_running (self->loop))
- g_cond_wait (&self->cond, &self->lock);
- g_mutex_unlock (&self->lock);
+ SleepConditionVariableSRW (&self->cond, &self->lock, INFINITE, 0);
+ ReleaseSRWLockExclusive (&self->lock);
done:
G_OBJECT_CLASS (parent_class)->constructed (object);
}
}
-static void
-gst_d3d11_window_win32_finalize (GObject * object)
-{
- GstD3D11WindowWin32 *self = GST_D3D11_WINDOW_WIN32 (object);
-
- g_mutex_clear (&self->lock);
- g_cond_clear (&self->cond);
-
- G_OBJECT_CLASS (parent_class)->finalize (object);
-}
-
static gboolean
running_cb (gpointer user_data)
{
GST_TRACE_OBJECT (self, "Main loop running now");
- g_mutex_lock (&self->lock);
- g_cond_signal (&self->cond);
- g_mutex_unlock (&self->lock);
+ AcquireSRWLockExclusive (&self->lock);
+ WakeConditionVariable (&self->cond);
+ ReleaseSRWLockExclusive (&self->lock);
return G_SOURCE_REMOVE;
}
MoveWindow (self->internal_hwnd, 0, 0, LOWORD (lParam), HIWORD (lParam),
FALSE);
} else if (uMsg == WM_CLOSE || uMsg == WM_DESTROY) {
- g_mutex_lock (&self->lock);
+ GstD3D11SRWLockGuard lk (&self->lock);
GST_WARNING_OBJECT (self, "external window is closing");
gst_d3d11_window_win32_release_external_handle (self->external_hwnd);
self->external_hwnd = NULL;
self->internal_hwnd_thread = NULL;
self->overlay_state = GST_D3D11_WINDOW_WIN32_OVERLAY_STATE_CLOSED;
- g_mutex_unlock (&self->lock);
} else {
gst_d3d11_window_win32_handle_window_proc (self, hWnd, uMsg, wParam,
lParam);