mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-26 00:58:12 +00:00
appsrc: Fix deadlock that may occur when multiple threads access appsrc at once
https://bugzilla.gnome.org/show_bug.cgi?id=711550
This commit is contained in:
parent
b55de48843
commit
360ac34425
1 changed files with 16 additions and 3 deletions
|
@ -941,6 +941,7 @@ gst_app_src_emit_need_data (GstAppSrc * appsrc, guint size)
|
||||||
/* we can be flushing now because we released the lock */
|
/* we can be flushing now because we released the lock */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* must be called with the appsrc mutex */
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_app_src_do_negotiate (GstBaseSrc * basesrc)
|
gst_app_src_do_negotiate (GstBaseSrc * basesrc)
|
||||||
{
|
{
|
||||||
|
@ -953,12 +954,16 @@ gst_app_src_do_negotiate (GstBaseSrc * basesrc)
|
||||||
caps = priv->caps ? gst_caps_ref (priv->caps) : NULL;
|
caps = priv->caps ? gst_caps_ref (priv->caps) : NULL;
|
||||||
GST_OBJECT_UNLOCK (basesrc);
|
GST_OBJECT_UNLOCK (basesrc);
|
||||||
|
|
||||||
|
/* Avoid deadlock by unlocking mutex
|
||||||
|
* otherwise we get deadlock between this and stream lock */
|
||||||
|
g_mutex_unlock (&priv->mutex);
|
||||||
if (caps) {
|
if (caps) {
|
||||||
result = gst_base_src_set_caps (basesrc, caps);
|
result = gst_base_src_set_caps (basesrc, caps);
|
||||||
gst_caps_unref (caps);
|
gst_caps_unref (caps);
|
||||||
} else {
|
} else {
|
||||||
result = GST_BASE_SRC_CLASS (parent_class)->negotiate (basesrc);
|
result = GST_BASE_SRC_CLASS (parent_class)->negotiate (basesrc);
|
||||||
}
|
}
|
||||||
|
g_mutex_lock (&priv->mutex);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -971,8 +976,8 @@ gst_app_src_negotiate (GstBaseSrc * basesrc)
|
||||||
gboolean result;
|
gboolean result;
|
||||||
|
|
||||||
g_mutex_lock (&priv->mutex);
|
g_mutex_lock (&priv->mutex);
|
||||||
result = gst_app_src_do_negotiate (basesrc);
|
|
||||||
priv->new_caps = FALSE;
|
priv->new_caps = FALSE;
|
||||||
|
result = gst_app_src_do_negotiate (basesrc);
|
||||||
g_mutex_unlock (&priv->mutex);
|
g_mutex_unlock (&priv->mutex);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -1029,10 +1034,18 @@ gst_app_src_create (GstBaseSrc * bsrc, guint64 offset, guint size,
|
||||||
guint buf_size;
|
guint buf_size;
|
||||||
|
|
||||||
if (priv->new_caps) {
|
if (priv->new_caps) {
|
||||||
gst_app_src_do_negotiate (bsrc);
|
|
||||||
priv->new_caps = FALSE;
|
priv->new_caps = FALSE;
|
||||||
}
|
gst_app_src_do_negotiate (bsrc);
|
||||||
|
|
||||||
|
/* Lock has released so now may need
|
||||||
|
*- flushing
|
||||||
|
*- new caps change
|
||||||
|
*- check queue has data */
|
||||||
|
if (G_UNLIKELY (priv->flushing))
|
||||||
|
goto flushing;
|
||||||
|
/* Contiue checks caps and queue */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
*buf = g_queue_pop_head (priv->queue);
|
*buf = g_queue_pop_head (priv->queue);
|
||||||
buf_size = gst_buffer_get_size (*buf);
|
buf_size = gst_buffer_get_size (*buf);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue