From 87ab729551168dc44da7d1aa0cd9c384419f2371 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Mon, 23 May 2022 15:51:23 +0200 Subject: [PATCH] hlsdemux2: Detect synchronization loss If we have been updating too slowly and have gone out of the current live window, inform the baseclass accordingly. This is different from the case where we have been updating quicker than what the server provides. Part-of: --- .../ext/adaptivedemux2/hls/gsthlsdemux.c | 8 +++++-- .../ext/adaptivedemux2/hls/m3u8.c | 23 +++++++++++++++++++ .../ext/adaptivedemux2/hls/m3u8.h | 4 ++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.c index 8dfd989948..23ee1ae223 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.c +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.c @@ -2105,6 +2105,11 @@ gst_hls_demux_update_fragment_info (GstAdaptiveDemux2Stream * stream) gst_hls_media_playlist_get_starting_segment (hlsdemux_stream->playlist); } else { + if (gst_hls_media_playlist_has_lost_sync (hlsdemux_stream->playlist, + stream->current_position)) { + GST_WARNING_OBJECT (stream, "Lost SYNC !"); + return GST_ADAPTIVE_DEMUX_FLOW_LOST_SYNC; + } GST_DEBUG_OBJECT (stream, "Looking up segment for position %" GST_TIME_FORMAT, GST_TIME_ARGS (stream->current_position)); @@ -2113,8 +2118,7 @@ gst_hls_demux_update_fragment_info (GstAdaptiveDemux2Stream * stream) GST_SEEK_FLAG_SNAP_NEAREST, stream->current_position); if (hlsdemux_stream->current_segment == NULL) { - GST_INFO_OBJECT (hlsdemux, - "This playlist doesn't contain more fragments"); + GST_INFO_OBJECT (stream, "At the end of the current media playlist"); return GST_FLOW_EOS; } diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/m3u8.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/m3u8.c index 6f4f8d860e..0668139ed0 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/m3u8.c +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/m3u8.c @@ -1385,6 +1385,29 @@ out: return ret; } +gboolean +gst_hls_media_playlist_has_lost_sync (GstHLSMediaPlaylist * m3u8, + GstClockTime position) +{ + GstM3U8MediaSegment *first; + + if (m3u8->segments->len < 1) + return TRUE; + first = g_ptr_array_index (m3u8->segments, 0); + + GST_DEBUG ("position %" GST_TIME_FORMAT " first %" GST_STIME_FORMAT + " duration %" GST_STIME_FORMAT, GST_TIME_ARGS (position), + GST_STIME_ARGS (first->stream_time), GST_STIME_ARGS (first->duration)); + + if (first->stream_time <= 0) + return FALSE; + + /* If we're definitely before the first fragment, we lost sync */ + if ((position + (first->duration / 2)) < first->stream_time) + return TRUE; + return FALSE; +} + gboolean gst_hls_media_playlist_get_seek_range (GstHLSMediaPlaylist * m3u8, gint64 * start, gint64 * stop) diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/m3u8.h b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/m3u8.h index bdb82a47dd..c6a22a91f3 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/m3u8.h +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/m3u8.h @@ -213,6 +213,10 @@ gst_hls_media_playlist_get_seek_range (GstHLSMediaPlaylist * m3u8, gint64 * start, gint64 * stop); +gboolean +gst_hls_media_playlist_has_lost_sync (GstHLSMediaPlaylist * m3u8, + GstClockTime position); + GstM3U8MediaSegment * gst_hls_media_playlist_seek (GstHLSMediaPlaylist *playlist, gboolean forward,