adaptivedemux2: Initialize and use stream start/current position
authorEdward Hervey <edward@centricular.com>
Tue, 17 May 2022 05:07:23 +0000 (07:07 +0200)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 28 Jun 2022 17:59:23 +0000 (17:59 +0000)
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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2679>

subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-stream.c
subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.c

index 38f36db..a79cc1d 100644 (file)
@@ -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);
 }
 
index bd7aa36..490399a 100644 (file)
@@ -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;