summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Schmidt <jan@centricular.com>2021-03-25 03:16:05 +1100
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>2021-03-31 13:34:40 +0000
commit3a3c80e7be1d03f016573700053e41107d641617 (patch)
tree9756d1ecb34b268dd4a070ea100d77d3c6ab8f29
parent7740ab9b86e140b68b26127b9dc22d26e41f509f (diff)
downloadgstreamer-plugins-bad-3a3c80e7be1d03f016573700053e41107d641617.tar.gz
mpegtsmux: Respect the start-time-selection property.
Use the start time provided by the aggregator base class for output times. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2105>
-rw-r--r--gst/mpegtsmux/gstbasetsmux.c31
-rw-r--r--gst/mpegtsmux/gstbasetsmux.h1
2 files changed, 31 insertions, 1 deletions
diff --git a/gst/mpegtsmux/gstbasetsmux.c b/gst/mpegtsmux/gstbasetsmux.c
index 8f024be4e..3fe7da4c1 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 b4970a94f..c0d678bca 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;
};
/**