adaptivedemux2: Handle loss of synchronization
authorEdward Hervey <edward@centricular.com>
Mon, 23 May 2022 13:43:04 +0000 (15:43 +0200)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 28 Jun 2022 17:59:23 +0000 (17:59 +0000)
Add a new custom GstFlowReturn so that subclasses can notify that they have lost
live synchronization.

When that happens, do a flushing seek back to the live position

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

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

index a0c4bf9..1194c11 100644 (file)
@@ -196,6 +196,8 @@ void gst_adaptive_demux_advance_period (GstAdaptiveDemux * demux);
 
 void gst_adaptive_demux2_stream_stop (GstAdaptiveDemux2Stream * stream);
 
+gboolean gst_adaptive_demux_handle_lost_sync (GstAdaptiveDemux * demux);
+
 typedef struct
 {
   GstMiniObject *item;
index a79cc1d..c331353 100644 (file)
@@ -1715,6 +1715,12 @@ gst_adaptive_demux2_stream_load_a_fragment (GstAdaptiveDemux2Stream * stream)
       GST_DEBUG_OBJECT (stream, "EOS, checking to stop download loop");
       gst_adaptive_demux2_stream_handle_playlist_eos (stream);
       return FALSE;
+    case GST_ADAPTIVE_DEMUX_FLOW_LOST_SYNC:
+      GST_DEBUG_OBJECT (stream, "Lost sync, asking reset to current position");
+      stream->state = GST_ADAPTIVE_DEMUX2_STREAM_STATE_STOPPED;
+      gst_adaptive_demux_loop_call (demux->priv->scheduler_task,
+          (GSourceFunc) gst_adaptive_demux_handle_lost_sync, demux, NULL);
+      return FALSE;
     case GST_FLOW_NOT_LINKED:
     {
       stream->state = GST_ADAPTIVE_DEMUX2_STREAM_STATE_EOS;
index 8452ea6..d4734d3 100644 (file)
@@ -2788,6 +2788,22 @@ gst_adaptive_demux_src_query (GstPad * pad, GstObject * parent,
   return ret;
 }
 
+gboolean
+gst_adaptive_demux_handle_lost_sync (GstAdaptiveDemux * demux)
+{
+  GstEvent *seek;
+
+  GST_WARNING_OBJECT (demux, "Lost synchronization, seeking back to live head");
+
+  seek =
+      gst_event_new_seek (1.0, GST_FORMAT_TIME,
+      GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT, GST_SEEK_TYPE_END, 0,
+      GST_SEEK_TYPE_NONE, 0);
+  gst_adaptive_demux_handle_seek_event (demux, seek);
+  return FALSE;
+}
+
+
 /* Called when the scheduler starts, to kick off manifest updates
  * and stream downloads */
 static gboolean
index 9a118ed..da1fe39 100644 (file)
@@ -105,6 +105,9 @@ typedef GstObjectClass GstAdaptiveDemux2StreamClass;
  */
 #define GST_ADAPTIVE_DEMUX_FLOW_RESTART_FRAGMENT GST_FLOW_CUSTOM_SUCCESS_2
 
+/* The live stream has lost synchronization and the demuxer needs to be resetted */
+#define GST_ADAPTIVE_DEMUX_FLOW_LOST_SYNC GST_FLOW_CUSTOM_ERROR_1
+
 typedef enum _GstAdaptiveDemux2StreamState GstAdaptiveDemux2StreamState;
 
 typedef struct _GstAdaptiveDemux2StreamFragment GstAdaptiveDemux2StreamFragment;