From 95ff949eff70d5fd9f84e3f7e9546f03d91106f1 Mon Sep 17 00:00:00 2001 From: "Jan Alexander Steffens (heftig)" Date: Mon, 7 Mar 2022 18:46:55 +0100 Subject: [PATCH] mpegtsmux: Start last_ts with GST_CLOCK_TIME_NONE And use the output segment position for the outgoing timestamp while it is. This is needed to delay the calculation of `output_ts_offset` until we actually have a usable timestamp, as tsmux will output a few initial packets while `last_ts` is still unset. Without this, the calculation would use the initial `0` value, which did not have the intended effect of making VBR mode behave like CBR mode, but always calculated an offset equal to the selected start time. Part-of: --- subprojects/gst-plugins-bad/gst/mpegtsmux/gstbasetsmux.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/subprojects/gst-plugins-bad/gst/mpegtsmux/gstbasetsmux.c b/subprojects/gst-plugins-bad/gst/mpegtsmux/gstbasetsmux.c index 56b22bb..aa56908 100644 --- a/subprojects/gst-plugins-bad/gst/mpegtsmux/gstbasetsmux.c +++ b/subprojects/gst-plugins-bad/gst/mpegtsmux/gstbasetsmux.c @@ -310,7 +310,7 @@ gst_base_ts_mux_reset (GstBaseTsMux * mux, gboolean alloc) mux->first = TRUE; mux->last_flow_ret = GST_FLOW_OK; - mux->last_ts = 0; + mux->last_ts = GST_CLOCK_TIME_NONE; mux->is_delta = TRUE; mux->is_header = FALSE; @@ -1148,10 +1148,13 @@ new_packet_cb (GstBuffer * buf, void *user_data, gint64 new_pcr) } 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); + } else if (agg_segment->position == -1 + || agg_segment->position < agg_segment->start) { + GST_BUFFER_PTS (buf) = agg_segment->start; + } else { + GST_BUFFER_PTS (buf) = agg_segment->position; } /* do common init (flags and streamheaders) */ -- 2.7.4