diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-private.h b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-private.h index a0c4bf9735..1194c11d1b 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-private.h +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-private.h @@ -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; diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-stream.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-stream.c index a79cc1d8a7..c331353336 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-stream.c +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-stream.c @@ -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; diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.c index 8452ea60e4..d4734d3372 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.c +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.c @@ -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 diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.h b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.h index 9a118ededf..da1fe3929c 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.h +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.h @@ -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;