From 4eac7f0e064a9a587a49364026f0f73626c9012b Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Tue, 17 May 2022 07:07:23 +0200 Subject: [PATCH] adaptivedemux2: Initialize and use stream start/current position The stream start and current position would be properly set when seeking or activating a stream after playback started. But it would never be properly initialized. Set it to NONE initially to indicate to subclasses that no position has been tracked yet. This will allow them to detect initial stream usage. Futhermore, once the initial streams setup is done, make sure that it is set to a valid initial value: * The minimum stream time in live * Or else the period start Part-of: --- .../ext/adaptivedemux2/gstadaptivedemux-stream.c | 2 ++ .../ext/adaptivedemux2/gstadaptivedemux.c | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-stream.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-stream.c index 38f36dba7d..a79cc1d8a7 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-stream.c +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-stream.c @@ -63,6 +63,8 @@ gst_adaptive_demux2_stream_init (GstAdaptiveDemux2Stream * stream) stream->fragment_bitrates = g_malloc0 (sizeof (guint64) * NUM_LOOKBACK_FRAGMENTS); + stream->start_position = stream->current_position = GST_CLOCK_TIME_NONE; + gst_segment_init (&stream->parse_segment, GST_FORMAT_TIME); } diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.c index bd7aa360ed..490399a138 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.c +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.c @@ -1812,6 +1812,16 @@ gst_adaptive_demux_prepare_streams (GstAdaptiveDemux * demux, GST_TIME_ARGS (period_start), GST_STIME_ARGS (min_stream_time), &demux->segment); + /* Synchronize stream start/current positions */ + if (min_stream_time == GST_CLOCK_STIME_NONE) + min_stream_time = period_start; + else + min_stream_time += period_start; + for (iter = new_streams; iter; iter = g_list_next (iter)) { + GstAdaptiveDemux2Stream *stream = iter->data; + stream->start_position = stream->current_position = min_stream_time; + } + for (iter = new_streams; iter; iter = g_list_next (iter)) { GstAdaptiveDemux2Stream *stream = iter->data; stream->compute_segment = TRUE;