mpegtsdemux: signal no-more-pads when appropriate
authorVincent Penquerc'h <vincent.penquerch@collabora.co.uk>
Mon, 26 Sep 2011 11:16:30 +0000 (12:16 +0100)
committerVincent Penquerc'h <vincent.penquerch@collabora.co.uk>
Mon, 28 Nov 2011 15:08:06 +0000 (15:08 +0000)
We track streams for which a data callback is set (and for which
pads will be added only when data is received), and signal
no-more-pads when the last pad is added.

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

gst/mpegdemux/gstmpegtsdemux.c
gst/mpegdemux/gstmpegtsdemux.h

index 648bc21..1fab2b0 100644 (file)
@@ -1245,7 +1245,12 @@ gst_mpegts_demux_data_cb (GstPESFilter * filter, gboolean first,
     /* activate and add */
     gst_pad_set_active (srcpad, TRUE);
     gst_element_add_pad (GST_ELEMENT_CAST (demux), srcpad);
-    demux->need_no_more_pads = TRUE;
+    demux->pending_pads--;
+    GST_DEBUG_OBJECT (demux,
+        "Adding pad due to received data, decreasing pending pads to %d",
+        demux->pending_pads);
+    if (demux->pending_pads == 0)
+      gst_element_no_more_pads (GST_ELEMENT (demux));
 
     stream->discont = TRUE;
 
@@ -1471,6 +1476,8 @@ gst_mpegts_stream_parse_pmt (GstMpegTSStream * stream,
     g_array_free (PMT->entries, TRUE);
   PMT->entries = g_array_new (FALSE, TRUE, sizeof (GstMpegTSPMTEntry));
 
+  GST_DEBUG_OBJECT (demux, "Resetting pending pads due to parsing the PMT");
+  demux->pending_pads = 0;
   while (entries > 0) {
     GstMpegTSPMTEntry entry;
     GstMpegTSStream *ES_stream;
@@ -1554,6 +1561,12 @@ gst_mpegts_stream_parse_pmt (GstMpegTSStream * stream,
             ES_stream->filter.gather_pes = TRUE;
           }
         }
+
+        ++demux->pending_pads;
+        GST_DEBUG_OBJECT (demux,
+            "Setting data callback, increasing pending pads to %d",
+            demux->pending_pads);
+
         gst_pes_filter_set_callbacks (&ES_stream->filter,
             (GstPESFilterData) gst_mpegts_demux_data_cb,
             (GstPESFilterResync) gst_mpegts_demux_resync_cb, ES_stream);
@@ -1585,6 +1598,11 @@ gst_mpegts_stream_parse_pmt (GstMpegTSStream * stream,
       gst_mpegts_activate_pmt (demux, stream);
   }
 
+  GST_DEBUG_OBJECT (demux, "Done parsing PMT, pending pads now %d",
+      demux->pending_pads);
+  if (demux->pending_pads == 0)
+    gst_element_no_more_pads (GST_ELEMENT (demux));
+
   return TRUE;
 
   /* ERRORS */
index d25e7fd..9a5db0e 100644 (file)
@@ -231,6 +231,9 @@ struct _GstMpegTSDemux {
 
   /* Detect when the source stops for a while, we will resync the interpolation gap */
   GstClockTime      last_buf_ts;
+
+  /* Number of expected pads which have not been added yet */
+  gint              pending_pads;
 };
 
 struct _GstMpegTSDemuxClass {