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,