From 3a3c80e7be1d03f016573700053e41107d641617 Mon Sep 17 00:00:00 2001 From: Jan Schmidt Date: Thu, 25 Mar 2021 03:16:05 +1100 Subject: [PATCH] mpegtsmux: Respect the start-time-selection property. Use the start time provided by the aggregator base class for output times. Part-of: --- gst/mpegtsmux/gstbasetsmux.c | 31 ++++++++++++++++++++++++++++++- gst/mpegtsmux/gstbasetsmux.h | 1 + 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/gst/mpegtsmux/gstbasetsmux.c b/gst/mpegtsmux/gstbasetsmux.c index 8f024be..3fe7da4 100644 --- a/gst/mpegtsmux/gstbasetsmux.c +++ b/gst/mpegtsmux/gstbasetsmux.c @@ -328,6 +328,7 @@ gst_base_ts_mux_reset (GstBaseTsMux * mux, gboolean alloc) if (mux->out_adapter) gst_adapter_clear (mux->out_adapter); + mux->output_ts_offset = GST_CLOCK_TIME_NONE; if (mux->tsmux) { if (mux->tsmux->si_sections) @@ -1080,15 +1081,43 @@ static gboolean new_packet_cb (GstBuffer * buf, void *user_data, gint64 new_pcr) { GstBaseTsMux *mux = (GstBaseTsMux *) user_data; + GstAggregator *agg = GST_AGGREGATOR (mux); GstBaseTsMuxClass *klass = GST_BASE_TS_MUX_GET_CLASS (mux); GstMapInfo map; + GstSegment *agg_segment = &GST_AGGREGATOR_PAD (agg->srcpad)->segment; g_assert (klass->output_packet); gst_buffer_map (buf, &map, GST_MAP_READWRITE); - if (!GST_CLOCK_TIME_IS_VALID (GST_BUFFER_PTS (buf))) + if (!GST_CLOCK_TIME_IS_VALID (GST_BUFFER_PTS (buf))) { + /* tsmux isn't generating timestamps. Use the input times */ GST_BUFFER_PTS (buf) = mux->last_ts; + } + + if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_PTS (buf))) { + if (!GST_CLOCK_TIME_IS_VALID (mux->output_ts_offset)) { + GstClockTime output_start_time = agg_segment->position; + if (agg_segment->position == -1 + || agg_segment->position < agg_segment->start) { + output_start_time = agg_segment->start; + } + + mux->output_ts_offset = + GST_CLOCK_DIFF (GST_BUFFER_PTS (buf), output_start_time); + + GST_DEBUG_OBJECT (mux, "New output ts offset %" GST_STIME_FORMAT, + GST_STIME_ARGS (mux->output_ts_offset)); + } + + if (GST_CLOCK_TIME_IS_VALID (mux->output_ts_offset)) { + GST_BUFFER_PTS (buf) += mux->output_ts_offset; + } + } + + if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_PTS (buf))) { + agg_segment->position = GST_BUFFER_PTS (buf); + } /* do common init (flags and streamheaders) */ new_packet_common_init (mux, buf, map.data, map.size); diff --git a/gst/mpegtsmux/gstbasetsmux.h b/gst/mpegtsmux/gstbasetsmux.h index b4970a9..c0d678b 100644 --- a/gst/mpegtsmux/gstbasetsmux.h +++ b/gst/mpegtsmux/gstbasetsmux.h @@ -197,6 +197,7 @@ struct GstBaseTsMux { /* output buffer aggregation */ GstAdapter *out_adapter; GstBuffer *out_buffer; + GstClockTimeDiff output_ts_offset; }; /** -- 2.7.4