hlsdemux2: Fix getting starting segment on live playlists

When dealing with live streams, the function was assuming that all segments of
the playlist had valid stream_time. But that isn't TRUE, for example in the case
of failing to synchronize playlists.

Fixes losing sync due to not being able to match playlist on updates

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6961>
This commit is contained in:
Edward Hervey 2024-04-08 16:13:13 +02:00 committed by GStreamer Marge Bot
parent 0ca5517d80
commit 59582e2ffe

View file

@ -2124,37 +2124,40 @@ gst_hls_media_playlist_get_starting_segment (GstHLSMediaPlaylist * self,
} }
if (GST_CLOCK_TIME_IS_VALID (hold_back)) { if (GST_CLOCK_TIME_IS_VALID (hold_back)) {
GstSeekFlags flags =
GST_SEEK_FLAG_SNAP_BEFORE | GST_SEEK_FLAG_KEY_UNIT |
GST_HLS_M3U8_SEEK_FLAG_ALLOW_PARTIAL;
GstM3U8MediaSegment *last_seg = GstM3U8MediaSegment *last_seg =
g_ptr_array_index (self->segments, self->segments->len - 1); g_ptr_array_index (self->segments, self->segments->len - 1);
GstClockTime playlist_duration =
last_seg->stream_time + last_seg->duration;
GstClockTime target_ts;
/* Clamp the hold back so we don't go below zero */ if (GST_CLOCK_STIME_IS_VALID (last_seg->stream_time)) {
if (hold_back > playlist_duration) GstSeekFlags flags =
hold_back = playlist_duration; GST_SEEK_FLAG_SNAP_BEFORE | GST_SEEK_FLAG_KEY_UNIT |
GST_HLS_M3U8_SEEK_FLAG_ALLOW_PARTIAL;
GstClockTime playlist_duration =
last_seg->stream_time + last_seg->duration;
GstClockTime target_ts;
target_ts = playlist_duration - hold_back; /* Clamp the hold back so we don't go below zero */
if (hold_back > playlist_duration)
hold_back = playlist_duration;
GST_DEBUG ("Hold back is %" GST_TIME_FORMAT target_ts = playlist_duration - hold_back;
" Looking for a segment before %" GST_TIME_FORMAT,
GST_TIME_ARGS (hold_back), GST_TIME_ARGS (target_ts));
if (gst_hls_media_playlist_seek (self, TRUE, flags, target_ts, GST_DEBUG ("Hold back is %" GST_TIME_FORMAT
seek_result)) { " Looking for a segment before %" GST_TIME_FORMAT,
GST_TIME_ARGS (hold_back), GST_TIME_ARGS (target_ts));
if (gst_hls_media_playlist_seek (self, TRUE, flags, target_ts,
seek_result)) {
#ifndef GST_DISABLE_GST_DEBUG #ifndef GST_DISABLE_GST_DEBUG
GstClockTime distance_from_edge = GstClockTime distance_from_edge =
playlist_duration - seek_result->stream_time; playlist_duration - seek_result->stream_time;
GST_DEBUG ("Found starting position %" GST_TIME_FORMAT " which is %" GST_DEBUG ("Found starting position %" GST_TIME_FORMAT " which is %"
GST_TIME_FORMAT " from the live edge", GST_TIME_FORMAT " from the live edge",
GST_TIME_ARGS (seek_result->stream_time), GST_TIME_ARGS (seek_result->stream_time),
GST_TIME_ARGS (distance_from_edge)); GST_TIME_ARGS (distance_from_edge));
#endif #endif
return TRUE; return TRUE;
}
} }
} }