mpegdemux: Update the last_ts correctly if we have no DTS

If we have no DTS but a PTS then this means both are the same, and we
should update the last_ts with the PTS. Only if both are unknown then we
don't know the current position and should not update it at all.

Previously we would always update the last_ts to GST_CLOCK_TIME_NONE if
the DTS is unknown, which caused the position to jump around and to
cause spurious gap events to be sent.
This commit is contained in:
Sebastian Dröge 2020-01-21 16:50:22 +02:00 committed by Jan Schmidt
parent e3ebebc20b
commit 287f9b18b0

View file

@ -646,6 +646,7 @@ gst_ps_demux_send_data (GstPsDemux * demux, GstPsStream * stream,
{
GstFlowReturn result;
GstClockTime pts = GST_CLOCK_TIME_NONE, dts = GST_CLOCK_TIME_NONE;
GstClockTime ts;
if (stream == NULL)
goto no_stream;
@ -662,14 +663,21 @@ gst_ps_demux_send_data (GstPsDemux * demux, GstPsStream * stream,
GST_BUFFER_PTS (buf) = pts;
GST_BUFFER_DTS (buf) = dts;
/* If we have no DTS but a PTS that means both are the same,
* if we have neither than we don't know the current position */
ts = dts;
if (ts == GST_CLOCK_TIME_NONE)
ts = pts;
/* update position in the segment */
if (stream->last_ts == GST_CLOCK_TIME_NONE || stream->last_ts < dts) {
if (ts != GST_CLOCK_TIME_NONE && (stream->last_ts == GST_CLOCK_TIME_NONE
|| stream->last_ts < ts)) {
GST_LOG_OBJECT (demux,
"last_ts update on pad %s to time %" GST_TIME_FORMAT
", current scr is %" GST_TIME_FORMAT, GST_PAD_NAME (stream->pad),
GST_TIME_ARGS (dts),
GST_TIME_ARGS (ts),
GST_TIME_ARGS (MPEGTIME_TO_GSTTIME (demux->current_scr)));
stream->last_ts = dts;
stream->last_ts = ts;
if (demux->src_segment.position == GST_CLOCK_TIME_NONE
|| stream->last_ts > demux->src_segment.position)
gst_segment_set_position (&demux->src_segment, GST_FORMAT_TIME,