aggregator: fix start time selection first with force-live
authorMathieu Duponchelle <mathieu@centricular.com>
Fri, 25 Oct 2024 17:12:17 +0000 (19:12 +0200)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 29 Oct 2024 12:40:32 +0000 (12:40 +0000)
When force-live is true, we don't want to wait for a first buffer
to select a start time.

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/1783

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7778>

subprojects/gstreamer/libs/gst/base/gstaggregator.c

index a206b0c8447155c349eafa01fc85049c73dede7a..c93feef23d1e772cd9ae23dda7572f56b6b36577 100644 (file)
@@ -866,6 +866,25 @@ gst_aggregator_wait_and_check (GstAggregator * self, gboolean * timeout)
     return FALSE;
   }
 
+  if (self->priv->force_live && self->priv->first_buffer
+      && self->priv->start_time_selection ==
+      GST_AGGREGATOR_START_TIME_SELECTION_FIRST) {
+    GstClockTime start_time;
+    GstAggregatorPad *srcpad = GST_AGGREGATOR_PAD (self->srcpad);
+    start_time = gst_element_get_current_running_time (GST_ELEMENT (self));
+
+    if (GST_CLOCK_TIME_IS_VALID (start_time)) {
+      if (srcpad->segment.position == -1)
+        srcpad->segment.position = start_time;
+      else
+        srcpad->segment.position = MIN (start_time, srcpad->segment.position);
+
+      GST_DEBUG_OBJECT (self, "Selecting start time %" GST_TIME_FORMAT,
+          GST_TIME_ARGS (start_time));
+      self->priv->first_buffer = FALSE;
+    }
+  }
+
   start = gst_aggregator_get_next_time (self);
 
   /* If we're not live, or if we use the running time