rtspsrc: create and add pads outside of lock
authorWim Taymans <wim.taymans@collabora.co.uk>
Fri, 16 Nov 2012 12:31:04 +0000 (13:31 +0100)
committerWim Taymans <wim.taymans@collabora.co.uk>
Fri, 16 Nov 2012 12:33:44 +0000 (13:33 +0100)
Create and add the ghostpad for the new stream outside of the lock because it
is not needed and causes deadlocks.

gst/rtsp/gstrtspsrc.c

index 0018e56..799edfe 100644 (file)
@@ -2227,7 +2227,7 @@ new_manager_pad (GstElement * manager, GstPad * pad, GstRTSPSrc * src)
   gchar *name;
   GstPadTemplate *template;
   gint id, ssrc, pt;
-  GList *lstream;
+  GList *ostreams;
   GstRTSPStream *stream;
   gboolean all_added;
 
@@ -2239,41 +2239,43 @@ new_manager_pad (GstElement * manager, GstPad * pad, GstRTSPSrc * src)
   if (sscanf (name, "recv_rtp_src_%u_%u_%u", &id, &ssrc, &pt) != 3)
     goto unknown_stream;
 
-  GST_DEBUG_OBJECT (src, "stream: %u, SSRC %d, PT %d", id, ssrc, pt);
+  GST_DEBUG_OBJECT (src, "stream: %u, SSRC %08x, PT %d", id, ssrc, pt);
 
   stream = find_stream (src, &id, (gpointer) find_stream_by_id);
   if (stream == NULL)
     goto unknown_stream;
 
-  /* create a new pad we will use to stream to */
-  template = gst_static_pad_template_get (&rtptemplate);
-  stream->srcpad = gst_ghost_pad_new_from_template (name, pad, template);
-  gst_object_unref (template);
-  g_free (name);
-
+  /* we'll add it later see below */
   stream->added = TRUE;
-  gst_pad_set_event_function (stream->srcpad, gst_rtspsrc_handle_src_event);
-  gst_pad_set_query_function (stream->srcpad, gst_rtspsrc_handle_src_query);
-  gst_pad_set_active (stream->srcpad, TRUE);
-  gst_element_add_pad (GST_ELEMENT_CAST (src), stream->srcpad);
 
   /* check if we added all streams */
   all_added = TRUE;
-  for (lstream = src->streams; lstream; lstream = g_list_next (lstream)) {
-    stream = (GstRTSPStream *) lstream->data;
+  for (ostreams = src->streams; ostreams; ostreams = g_list_next (ostreams)) {
+    GstRTSPStream *ostream = (GstRTSPStream *) ostreams->data;
 
     GST_DEBUG_OBJECT (src, "stream %p, container %d, disabled %d, added %d",
-        stream, stream->container, stream->disabled, stream->added);
+        ostream, ostream->container, ostream->disabled, ostream->added);
 
     /* a container stream only needs one pad added. Also disabled streams don't
      * count */
-    if (!stream->container && !stream->disabled && !stream->added) {
+    if (!ostream->container && !ostream->disabled && !ostream->added) {
       all_added = FALSE;
       break;
     }
   }
   GST_RTSP_STATE_UNLOCK (src);
 
+  /* create a new pad we will use to stream to */
+  template = gst_static_pad_template_get (&rtptemplate);
+  stream->srcpad = gst_ghost_pad_new_from_template (name, pad, template);
+  gst_object_unref (template);
+  g_free (name);
+
+  gst_pad_set_event_function (stream->srcpad, gst_rtspsrc_handle_src_event);
+  gst_pad_set_query_function (stream->srcpad, gst_rtspsrc_handle_src_query);
+  gst_pad_set_active (stream->srcpad, TRUE);
+  gst_element_add_pad (GST_ELEMENT_CAST (src), stream->srcpad);
+
   if (all_added) {
     GST_DEBUG_OBJECT (src, "We added all streams");
     /* when we get here, all stream are added and we can fire the no-more-pads