tsdemux: Improve gap detection
authorEdward Hervey <edward@centricular.com>
Fri, 1 Oct 2021 12:36:48 +0000 (14:36 +0200)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Mon, 18 Oct 2021 11:23:25 +0000 (11:23 +0000)
We should also take into account whether data is currently pending when checking
for gap on streams. It could very well be that some streams have very low
bitrate (and spread out) data. For those we don't want to push out a gap event.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1179>

subprojects/gst-plugins-bad/gst/mpegtsdemux/tsdemux.c

index bf6ad58..4faabcc 100644 (file)
@@ -2887,9 +2887,10 @@ gst_ts_demux_check_and_sync_streams (GstTSDemux * demux, GstClockTime time)
    * This means we can detect buffers passing without PTSes fine and still generate
    * gaps.
    *
-   * If there haven't been any buffers pushed on this stream since the last
-   * gap check, push a gap event updating to the indicated input PCR time
-   * and update the pad's tracking.
+   * If there haven't been any buffers pushed on this stream since the last gap
+   * check *AND* there is no pending data (stream->current_size), push a gap
+   * event updating to the indicated input PCR time and update the pad's
+   * tracking.
    *
    * If there have been buffers pushed, update the reference buffer count
    * and but don't push a gap event
@@ -2898,15 +2899,16 @@ gst_ts_demux_check_and_sync_streams (GstTSDemux * demux, GstClockTime time)
     TSDemuxStream *ps = (TSDemuxStream *) tmp->data;
     GST_DEBUG_OBJECT (ps->pad,
         "0x%04x, PTS:%" GST_TIME_FORMAT " REFPTS:%" GST_TIME_FORMAT " Gap:%"
-        GST_TIME_FORMAT " nb_buffers: %d (ref:%d)",
+        GST_TIME_FORMAT " nb_buffers: %d (ref:%d) pending_data size %u",
         ((MpegTSBaseStream *) ps)->pid, GST_TIME_ARGS (ps->pts),
         GST_TIME_ARGS (ps->gap_ref_pts),
         GST_TIME_ARGS (ps->pts - ps->gap_ref_pts), ps->nb_out_buffers,
-        ps->gap_ref_buffers);
+        ps->gap_ref_buffers, ps->current_size);
     if (ps->pad == NULL)
       continue;
 
-    if (ps->nb_out_buffers == ps->gap_ref_buffers && ps->gap_ref_pts != ps->pts) {
+    if (ps->nb_out_buffers == ps->gap_ref_buffers && ps->current_size == 0
+        && ps->gap_ref_pts != ps->pts) {
       /* Do initial setup of pad if needed - segment etc */
       GST_DEBUG_OBJECT (ps->pad,
           "Stream needs update. Pushing GAP event to TS %" GST_TIME_FORMAT,