From c924e4cc1eba9854eec2caf979c5209cc53fb6c4 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Tue, 28 May 2024 13:04:20 +0200 Subject: [PATCH] hlsdemux2: Minor refactoring of starting segment check Part-of: --- .../ext/adaptivedemux2/hls/m3u8.c | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/m3u8.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/m3u8.c index ceee066cb1..83028d5bbe 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/m3u8.c +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/m3u8.c @@ -2110,6 +2110,10 @@ gst_hls_media_playlist_get_starting_segment (GstHLSMediaPlaylist * self, res = g_ptr_array_index (self->segments, 0); } else { GstClockTime hold_back = GST_CLOCK_TIME_NONE; + GstM3U8MediaSegment *last_seg; + g_assert (self->segments->len); + last_seg = g_ptr_array_index (self->segments, self->segments->len - 1); + /* Live playlist. If low-latency, use the PART-HOLD-BACK specified distance * from the end, otherwise HOLD-BACK distance */ if (GST_CLOCK_TIME_IS_VALID (self->part_hold_back)) @@ -2135,41 +2139,37 @@ gst_hls_media_playlist_get_starting_segment (GstHLSMediaPlaylist * self, hold_back = GST_M3U8_LIVE_MIN_FRAGMENT_DISTANCE * self->targetduration; } - if (GST_CLOCK_TIME_IS_VALID (hold_back)) { - GstM3U8MediaSegment *last_seg = - g_ptr_array_index (self->segments, self->segments->len - 1); + if (GST_CLOCK_TIME_IS_VALID (hold_back) + && GST_CLOCK_STIME_IS_VALID (last_seg->stream_time)) { + GstSeekFlags flags = + 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; - if (GST_CLOCK_STIME_IS_VALID (last_seg->stream_time)) { - GstSeekFlags flags = - 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; + /* Clamp the hold back so we don't go below zero */ + if (hold_back > playlist_duration) + hold_back = playlist_duration; - /* Clamp the hold back so we don't go below zero */ - if (hold_back > playlist_duration) - hold_back = playlist_duration; + target_ts = playlist_duration - hold_back; - target_ts = playlist_duration - hold_back; + GST_DEBUG ("Hold back is %" GST_TIME_FORMAT + " Looking for a segment before %" GST_TIME_FORMAT, + GST_TIME_ARGS (hold_back), GST_TIME_ARGS (target_ts)); - GST_DEBUG ("Hold back is %" GST_TIME_FORMAT - " 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)) { + if (gst_hls_media_playlist_seek (self, TRUE, flags, target_ts, + seek_result)) { #ifndef GST_DISABLE_GST_DEBUG - GstClockTime distance_from_edge = - playlist_duration - seek_result->stream_time; + GstClockTime distance_from_edge = + playlist_duration - seek_result->stream_time; - GST_DEBUG ("Found starting position %" GST_TIME_FORMAT " which is %" - GST_TIME_FORMAT " from the live edge", - GST_TIME_ARGS (seek_result->stream_time), - GST_TIME_ARGS (distance_from_edge)); + GST_DEBUG ("Found starting position %" GST_TIME_FORMAT " which is %" + GST_TIME_FORMAT " from the live edge", + GST_TIME_ARGS (seek_result->stream_time), + GST_TIME_ARGS (distance_from_edge)); #endif - return TRUE; - } + return TRUE; } }