From e06bcde922210f3570d00db7258c1a8c7fb2e4e8 Mon Sep 17 00:00:00 2001 From: Alvaro Velad Galvan Date: Mon, 12 Jun 2023 13:25:16 +0200 Subject: [PATCH 1/2] fix(HLS): Avoid HLS resync when there is a gap in the stream --- lib/media/streaming_engine.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/media/streaming_engine.js b/lib/media/streaming_engine.js index ead1d24937..3285f1d845 100644 --- a/lib/media/streaming_engine.js +++ b/lib/media/streaming_engine.js @@ -671,10 +671,18 @@ shaka.media.StreamingEngine = class { const mediaState = this.mediaStates_.get(type); const logPrefix = shaka.media.StreamingEngine.logPrefix_(mediaState); - // Always clear the iterator since we need to start streaming from the - // new time. This also happens in clearBuffer_, but if we don't clear, - // we still want to reset the iterator. - mediaState.segmentIterator = null; + let segment = null; + if (mediaState.segmentIterator) { + segment = mediaState.segmentIterator.current(); + } + if (!segment || segment.startTime > presentationTime || + segment.endTime < presentationTime) { + // Always clear the iterator (if the seek is not produced by a gap) + // since we need to start streaming from the new time. This also + // happens in clearBuffer_, but if we don't clear, we still want to + // reset the iterator. + mediaState.segmentIterator = null; + } if (!newTimeIsBuffered(type)) { const bufferEnd = From 424e687e577fd7507a8f93c030673cd6db0e167e Mon Sep 17 00:00:00 2001 From: Alvaro Velad Galvan Date: Mon, 12 Jun 2023 18:07:25 +0200 Subject: [PATCH 2/2] Update comment --- lib/media/streaming_engine.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/media/streaming_engine.js b/lib/media/streaming_engine.js index 3285f1d845..b706251a89 100644 --- a/lib/media/streaming_engine.js +++ b/lib/media/streaming_engine.js @@ -675,12 +675,9 @@ shaka.media.StreamingEngine = class { if (mediaState.segmentIterator) { segment = mediaState.segmentIterator.current(); } + // Only reset the iterator if we seek outside the current segment. if (!segment || segment.startTime > presentationTime || segment.endTime < presentationTime) { - // Always clear the iterator (if the seek is not produced by a gap) - // since we need to start streaming from the new time. This also - // happens in clearBuffer_, but if we don't clear, we still want to - // reset the iterator. mediaState.segmentIterator = null; }