media: ignore spurious ASYNC_DONE messages
authorWim Taymans <wim.taymans@collabora.co.uk>
Sat, 11 Dec 2010 16:31:44 +0000 (17:31 +0100)
committerWim Taymans <wim.taymans@gmail.com>
Sat, 11 Dec 2010 17:04:34 +0000 (18:04 +0100)
When we are dynamically adding pads, the addition of the udpsrc elements will
trigger an ASYNC_DONE. We have to ignore this because we only want to react to
the real ASYNC_DONE when everything is prerolled.

gst/rtsp-server/rtsp-media.c
gst/rtsp-server/rtsp-media.h

index 1e02c00..9649472 100644 (file)
@@ -1387,10 +1387,17 @@ default_handle_message (GstRTSPMedia * media, GstMessage * message)
     case GST_MESSAGE_STREAM_STATUS:
       break;
     case GST_MESSAGE_ASYNC_DONE:
-      GST_INFO ("%p: got ASYNC_DONE", media);
-      collect_media_stats (media);
-
-      gst_rtsp_media_set_status (media, GST_RTSP_MEDIA_STATUS_PREPARED);
+      if (!media->adding) {
+        /* when we are dynamically adding pads, the addition of the udpsrc will
+         * temporarily produce ASYNC_DONE messages. We have to ignore them and
+         * wait for the final ASYNC_DONE after everything prerolled */
+        GST_INFO ("%p: got ASYNC_DONE", media);
+        collect_media_stats (media);
+
+        gst_rtsp_media_set_status (media, GST_RTSP_MEDIA_STATUS_PREPARED);
+      } else {
+        GST_INFO ("%p: ignoring ASYNC_DONE", media);
+      }
       break;
     case GST_MESSAGE_EOS:
       GST_INFO ("%p: got EOS", media);
@@ -1442,6 +1449,8 @@ pad_added_cb (GstElement * element, GstPad * pad, GstRTSPMedia * media)
 
   name = g_strdup_printf ("dynpay%d", i);
 
+  media->adding = TRUE;
+
   /* ghost the pad of the payloader to the element */
   stream->srcpad = gst_ghost_pad_new (name, pad);
   gst_pad_set_active (stream->srcpad, TRUE);
@@ -1460,6 +1469,7 @@ pad_added_cb (GstElement * element, GstPad * pad, GstRTSPMedia * media)
     gst_element_set_state (stream->selector[i], GST_STATE_PAUSED);
     gst_element_set_state (stream->appsrc[i], GST_STATE_PAUSED);
   }
+  media->adding = FALSE;
 }
 
 static void
@@ -1542,6 +1552,8 @@ gst_rtsp_media_prepare (GstRTSPMedia * media)
   for (walk = media->dynamic; walk; walk = g_list_next (walk)) {
     GstElement *elem = walk->data;
 
+    GST_INFO ("adding callbacks for dynamic element %p", elem);
+
     g_signal_connect (elem, "pad-added", (GCallback) pad_added_cb, media);
     g_signal_connect (elem, "no-more-pads", (GCallback) no_more_pads_cb, media);
 
index 06c299d..45fa22e 100644 (file)
@@ -207,6 +207,7 @@ struct _GstRTSPMedia {
   GstRTSPMediaStatus status;
   gint               active;
   gboolean           eos_pending;
+  gboolean           adding;
 
   /* the pipeline for the media */
   GstElement        *pipeline;