rtpssrcdemux: Make the pads lock recursive and hold it across the signal emit
authorOlivier CrĂȘte <olivier.crete@collabora.com>
Tue, 24 May 2011 08:29:57 +0000 (11:29 +0300)
committerMark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>
Thu, 28 Jul 2011 12:50:59 +0000 (14:50 +0200)
We need to keep the lock held because we don't want a push before the "new-ssrc-pad"
handler has completed. But we may want to push an event from inside that handler, hence
the recursive mutex.

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

gst/rtpmanager/gstrtpssrcdemux.c
gst/rtpmanager/gstrtpssrcdemux.h

index 43369cf..46ed8b0 100644 (file)
@@ -83,8 +83,8 @@ GST_STATIC_PAD_TEMPLATE ("rtcp_src_%d",
     GST_STATIC_CAPS ("application/x-rtcp")
     );
 
-#define GST_PAD_LOCK(obj)   (g_mutex_lock ((obj)->padlock))
-#define GST_PAD_UNLOCK(obj) (g_mutex_unlock ((obj)->padlock))
+#define GST_PAD_LOCK(obj)   (g_static_rec_mutex_lock (&(obj)->padlock))
+#define GST_PAD_UNLOCK(obj) (g_static_rec_mutex_unlock (&(obj)->padlock))
 
 /* signals */
 enum
@@ -214,14 +214,14 @@ find_or_create_demux_pad_for_ssrc (GstRtpSsrcDemux * demux, guint32 ssrc)
       gst_rtp_ssrc_demux_iterate_internal_links_src);
   gst_pad_set_active (rtcp_pad, TRUE);
 
-  GST_PAD_UNLOCK (demux);
-
   gst_element_add_pad (GST_ELEMENT_CAST (demux), rtp_pad);
   gst_element_add_pad (GST_ELEMENT_CAST (demux), rtcp_pad);
 
   g_signal_emit (G_OBJECT (demux),
       gst_rtp_ssrc_demux_signals[SIGNAL_NEW_SSRC_PAD], 0, ssrc, rtp_pad);
 
+  GST_PAD_UNLOCK (demux);
+
   return demuxpad;
 }
 
@@ -336,7 +336,7 @@ gst_rtp_ssrc_demux_init (GstRtpSsrcDemux * demux,
       gst_rtp_ssrc_demux_iterate_internal_links_sink);
   gst_element_add_pad (GST_ELEMENT_CAST (demux), demux->rtcp_sink);
 
-  demux->padlock = g_mutex_new ();
+  g_static_rec_mutex_init (&demux->padlock);
 
   gst_segment_init (&demux->segment, GST_FORMAT_UNDEFINED);
 }
@@ -378,7 +378,7 @@ gst_rtp_ssrc_demux_finalize (GObject * object)
   GstRtpSsrcDemux *demux;
 
   demux = GST_RTP_SSRC_DEMUX (object);
-  g_mutex_free (demux->padlock);
+  g_static_rec_mutex_free (&demux->padlock);
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
index d5a13ca..6f792d9 100644 (file)
@@ -41,7 +41,7 @@ struct _GstRtpSsrcDemux
   GstPad *rtp_sink;
   GstPad *rtcp_sink;
 
-  GMutex *padlock;
+  GStaticRecMutex padlock;
   GSList *srcpads;
 };