hlsdemux2: Detect synchronization loss
authorEdward Hervey <edward@centricular.com>
Mon, 23 May 2022 13:51:23 +0000 (15:51 +0200)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 28 Jun 2022 17:59:23 +0000 (17:59 +0000)
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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2679>

subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.c
subprojects/gst-plugins-good/ext/adaptivedemux2/hls/m3u8.c
subprojects/gst-plugins-good/ext/adaptivedemux2/hls/m3u8.h

index 8dfd989..23ee1ae 100644 (file)
@@ -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;
       }
 
index 6f4f8d8..0668139 100644 (file)
@@ -1386,6 +1386,29 @@ out:
 }
 
 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)
 {
index bdb82a4..c6a22a9 100644 (file)
@@ -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,