aggregator: Protect the srcpad caps negotiation with the stream lock
authorOlivier Crête <olivier.crete@collabora.com>
Thu, 22 Jan 2015 00:35:25 +0000 (19:35 -0500)
committerTim-Philipp Müller <tim@centricular.com>
Sat, 2 Dec 2017 15:10:26 +0000 (15:10 +0000)
Instead of adding another lock, use the srcpad stream lock, which is already
taken anyway to push out the new caps if needed.

https://bugzilla.gnome.org/show_bug.cgi?id=742684

libs/gst/base/gstaggregator.c

index 102173c..a225310 100644 (file)
@@ -110,21 +110,6 @@ GST_DEBUG_CATEGORY_STATIC (aggregator_debug);
   g_cond_broadcast(&(((GstAggregatorPad* )pad)->priv->event_cond));    \
   } G_STMT_END
 
-#define GST_AGGREGATOR_SETCAPS_LOCK(self)   G_STMT_START {        \
-  GST_TRACE_OBJECT (self, "Taking SETCAPS lock from thread %p",   \
-        g_thread_self());                                         \
-  g_mutex_lock(&self->priv->setcaps_lock);                        \
-  GST_TRACE_OBJECT (self, "Took SETCAPS lock from thread %p",     \
-        g_thread_self());                                         \
-  } G_STMT_END
-
-#define GST_AGGREGATOR_SETCAPS_UNLOCK(self)   G_STMT_START {        \
-  GST_TRACE_OBJECT (self, "Releasing SETCAPS lock from thread %p",  \
-        g_thread_self());                                           \
-  g_mutex_unlock(&self->priv->setcaps_lock);                        \
-  GST_TRACE_OBJECT (self, "Took SETCAPS lock from thread %p",       \
-        g_thread_self());                                           \
-  } G_STMT_END
 
 #define PAD_STREAM_LOCK(pad)   G_STMT_START {                           \
   GST_TRACE_OBJECT (pad, "Taking lock from thread %p",                  \
@@ -229,15 +214,12 @@ struct _GstAggregatorPrivate
   gboolean send_eos;            /* protected by srcpad stream lock */
   GstFlowReturn flow_return;    /* protected by object lock */
 
-  GstCaps *srccaps;
+  GstCaps *srccaps;             /* protected by the srcpad stream lock */
 
   /* protected by object lock */
   GstTagList *tags;
   gboolean tags_changed;
 
-  /* Lock to prevent two src setcaps from happening at the same time  */
-  GMutex setcaps_lock;
-
   gboolean latency_live;
   GstClockTime latency_min;
   GstClockTime latency_max;
@@ -473,10 +455,10 @@ gst_aggregator_push_mandatory_events (GstAggregator * self)
 void
 gst_aggregator_set_src_caps (GstAggregator * self, GstCaps * caps)
 {
-  GST_AGGREGATOR_SETCAPS_LOCK (self);
+  GST_PAD_STREAM_LOCK (self->srcpad);
   gst_caps_replace (&self->priv->srccaps, caps);
   gst_aggregator_push_mandatory_events (self);
-  GST_AGGREGATOR_SETCAPS_UNLOCK (self);
+  GST_PAD_STREAM_UNLOCK (self->srcpad);
 }
 
 /**
@@ -1549,7 +1531,6 @@ gst_aggregator_finalize (GObject * object)
 {
   GstAggregator *self = (GstAggregator *) object;
 
-  g_mutex_clear (&self->priv->setcaps_lock);
   g_mutex_clear (&self->priv->src_lock);
   g_cond_clear (&self->priv->src_cond);
 
@@ -1734,7 +1715,6 @@ gst_aggregator_init (GstAggregator * self, GstAggregatorClass * klass)
 
   self->priv->latency = DEFAULT_LATENCY;
 
-  g_mutex_init (&self->priv->setcaps_lock);
   g_mutex_init (&self->priv->src_lock);
   g_cond_init (&self->priv->src_cond);
 }