matroskademux: fix decoder glitches with H264 content
authorStéphane Cerveau <scerveau@collabora.com>
Wed, 5 May 2021 11:20:04 +0000 (13:20 +0200)
committerStéphane Cerveau <scerveau@collabora.com>
Thu, 20 May 2021 13:07:07 +0000 (15:07 +0200)
To avoid decoder starvation causing glitches on screen,
the demuxer shall clip only when the buffer is a key frame
and the lace time is greater than the stop time.

Fixes gst-editing-services#128

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/973>

gst/matroska/matroska-demux.c

index ca74c86..940f842 100644 (file)
@@ -4799,11 +4799,15 @@ gst_matroska_demux_parse_blockgroup_or_simpleblock (GstMatroskaDemux * demux,
       if (GST_CLOCK_TIME_IS_VALID (lace_time)) {
         GstClockTime last_stop_end;
 
-        /* Check if this stream is after segment stop */
-        if (GST_CLOCK_TIME_IS_VALID (demux->common.segment.stop) &&
-            lace_time >= demux->common.segment.stop) {
+        /* Check if this stream is after segment stop,
+         * but only terminate if we hit the next keyframe,
+         * to make sure that all frames potentially inside the segment
+         * are available to the decoder for decoding / reordering.*/
+        if (!delta_unit && GST_CLOCK_TIME_IS_VALID (demux->common.segment.stop)
+            && lace_time >= demux->common.segment.stop) {
           GST_DEBUG_OBJECT (demux,
-              "Stream %d after segment stop %" GST_TIME_FORMAT, stream->index,
+              "Stream %d lace time: %" GST_TIME_FORMAT " after segment stop: %"
+              GST_TIME_FORMAT, stream->index, GST_TIME_ARGS (lace_time),
               GST_TIME_ARGS (demux->common.segment.stop));
           gst_buffer_unref (sub);
           goto eos;