adaptivedemux2: stream: Set period has_next_period flag before EOS
authorJan Schmidt <jan@centricular.com>
Mon, 11 Jul 2022 15:55:54 +0000 (01:55 +1000)
committerTim-Philipp Müller <tim@centricular.com>
Thu, 4 Aug 2022 12:43:51 +0000 (13:43 +0100)
Before sending EOS, update the period's has_next_period
flag and/or create the next period. This closes a race
where the output loop might receive the EOS event
and either push it downstream (causing premature EOS),
or receive it and try and switch to the next period
before that period is completely set up.

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

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

index 3e40d24..c9dc24f 100644 (file)
@@ -1518,6 +1518,19 @@ gst_adaptive_demux2_stream_end_of_manifest (GstAdaptiveDemux2Stream * stream)
 
   GST_DEBUG_OBJECT (stream, "Combined flow %s", gst_flow_get_name (combined));
 
+  if (gst_adaptive_demux_has_next_period (demux)) {
+    if (combined == GST_FLOW_EOS) {
+      GST_DEBUG_OBJECT (stream, "Next period available, advancing");
+      gst_adaptive_demux_advance_period (demux);
+    } else {
+      /* Ensure the 'has_next_period' flag is set on the period before
+       * pushing EOS to the stream, so that the output loop knows not
+       * to actually output the event */
+      GST_DEBUG_OBJECT (stream, "Marking current period has a next one");
+      demux->input_period->has_next_period = TRUE;
+    }
+  }
+
   if (demux->priv->outputs) {
     GstEvent *eos = gst_event_new_eos ();
 
@@ -1530,11 +1543,6 @@ gst_adaptive_demux2_stream_end_of_manifest (GstAdaptiveDemux2Stream * stream)
     GST_ERROR_OBJECT (demux, "Can't push EOS on non-exposed pad");
     gst_adaptive_demux2_stream_error (stream);
   }
-
-  if (combined == GST_FLOW_EOS && gst_adaptive_demux_has_next_period (demux)) {
-    GST_DEBUG_OBJECT (stream, "Next period available, advancing");
-    gst_adaptive_demux_advance_period (demux);
-  }
 }
 
 static gboolean