From 14a56b6964b87e66bc2e242ace03ac385bfe1e12 Mon Sep 17 00:00:00 2001 From: Jan Schmidt Date: Thu, 19 Dec 2013 23:00:12 +1100 Subject: [PATCH] mpegtsmux: Don't disrupt buffer state in the clip function Collectpads assumes that it can pass any buffer to the clip function for adjustment, some of which are artificially injected - so don't adjust global timestamp tracking there. Instead, only adjust the buffer timestamps and use them directly in the collection function. Fixes https://bugzilla.gnome.org/show_bug.cgi?id=698748 --- gst/mpegtsmux/mpegtsmux.c | 33 +++++++++++++-------------------- gst/mpegtsmux/mpegtsmux.h | 3 +-- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/gst/mpegtsmux/mpegtsmux.c b/gst/mpegtsmux/mpegtsmux.c index fa50f56f33..0247fcfc52 100644 --- a/gst/mpegtsmux/mpegtsmux.c +++ b/gst/mpegtsmux/mpegtsmux.c @@ -321,8 +321,7 @@ static void mpegtsmux_pad_reset (MpegTsPadData * pad_data) { pad_data->pid = 0; - pad_data->last_pts = GST_CLOCK_TIME_NONE; - pad_data->last_dts = GST_CLOCK_TIME_NONE; + pad_data->min_dts = GST_CLOCK_TIME_NONE; pad_data->prog_id = -1; #if 0 pad_data->prog_id = -1; @@ -1020,7 +1019,6 @@ mpegtsmux_clip_inc_running_time (GstCollectPads * pads, GST_LOG_OBJECT (cdata->pad, "buffer pts %" GST_TIME_FORMAT " -> %" GST_TIME_FORMAT " running time", GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)), GST_TIME_ARGS (time)); - pad_data->last_pts = time; buf = *outbuf = gst_buffer_make_writable (buf); GST_BUFFER_TIMESTAMP (*outbuf) = time; } @@ -1039,14 +1037,11 @@ mpegtsmux_clip_inc_running_time (GstCollectPads * pads, GST_LOG_OBJECT (cdata->pad, "buffer dts %" GST_TIME_FORMAT " -> %" GST_TIME_FORMAT " running time", GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)), GST_TIME_ARGS (time)); - if (GST_CLOCK_TIME_IS_VALID (pad_data->last_dts) && - time < pad_data->last_dts) { - /* FIXME DTS/PTS mess again; - * probably needs a whole lot more subtle handling (cf qtmux) */ + if (GST_CLOCK_TIME_IS_VALID (pad_data->min_dts) && + time < pad_data->min_dts) { + /* Ignore DTS going backward */ GST_WARNING_OBJECT (cdata->pad, "ignoring DTS going backward"); - time = pad_data->last_dts; - } else { - pad_data->last_dts = time; + time = pad_data->min_dts; } buf = *outbuf = gst_buffer_make_writable (buf); GST_BUFFER_DTS (*outbuf) = time; @@ -1154,18 +1149,16 @@ mpegtsmux_collected_buffer (GstCollectPads * pads, GstCollectData * data, GST_DEBUG_OBJECT (COLLECT_DATA_PAD (best), "Chose stream for output (PID: 0x%04x)", best->pid); - if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_PTS (buf)) && - GST_CLOCK_TIME_IS_VALID (best->last_pts)) { - pts = GSTTIME_TO_MPEGTIME (best->last_pts); + if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_PTS (buf))) { + pts = GSTTIME_TO_MPEGTIME (GST_BUFFER_PTS (buf)); GST_DEBUG_OBJECT (mux, "Buffer has PTS %" GST_TIME_FORMAT " pts %" - G_GINT64_FORMAT, GST_TIME_ARGS (best->last_pts), pts); + G_GINT64_FORMAT, GST_TIME_ARGS (GST_BUFFER_PTS (buf)), pts); } - if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DTS (buf)) && - GST_CLOCK_TIME_IS_VALID (best->last_dts)) { - dts = GSTTIME_TO_MPEGTIME (best->last_dts); + if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DTS (buf))) { + dts = GSTTIME_TO_MPEGTIME (GST_BUFFER_DTS (buf)); GST_DEBUG_OBJECT (mux, "Buffer has DTS %" GST_TIME_FORMAT " dts %" - G_GINT64_FORMAT, GST_TIME_ARGS (best->last_dts), dts); + G_GINT64_FORMAT, GST_TIME_ARGS (GST_BUFFER_DTS (buf)), dts); } /* should not have a DTS without PTS */ @@ -1197,8 +1190,8 @@ mpegtsmux_collected_buffer (GstCollectPads * pads, GstCollectData * data, if (prog->pcr_stream == best->stream) { /* prefer DTS if present for PCR as it should be monotone */ mux->last_ts = - GST_CLOCK_TIME_IS_VALID (best->last_dts) ? best->last_dts : best-> - last_pts; + GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DTS (buf)) ? + GST_BUFFER_DTS (buf) : GST_BUFFER_PTS (buf); } mux->is_delta = delta; diff --git a/gst/mpegtsmux/mpegtsmux.h b/gst/mpegtsmux/mpegtsmux.h index 52b291e7ab..c894e58579 100644 --- a/gst/mpegtsmux/mpegtsmux.h +++ b/gst/mpegtsmux/mpegtsmux.h @@ -185,8 +185,7 @@ struct MpegTsPadData { TsMuxStream *stream; /* most recent valid TS for this stream */ - GstClockTime last_pts; - GstClockTime last_dts; + GstClockTime min_dts; #if 0 /* (optional) index writing */