From 190fa3fc6b1649d192a5a6785212cbc174d98229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Fri, 28 Jun 2024 09:15:14 +0200 Subject: [PATCH] fix: Only request initialization segment when it's necessary (#6929) According to https://w3c.github.io/media-source/#dom-sourcebuffer-remove Deleting a range from the source buffer does not delete the initialization segment, so this change will prevent the initialization segment from being requested when it is not needed. --- lib/media/streaming_engine.js | 1 - test/media/streaming_engine_unit.js | 7 ++++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/media/streaming_engine.js b/lib/media/streaming_engine.js index b36fcead25..947155c7c3 100644 --- a/lib/media/streaming_engine.js +++ b/lib/media/streaming_engine.js @@ -2575,7 +2575,6 @@ shaka.media.StreamingEngine = class { mediaState.clearBufferSafeMargin = 0; mediaState.clearingBuffer = true; mediaState.lastSegmentReference = null; - mediaState.lastInitSegmentReference = null; mediaState.segmentIterator = null; shaka.log.debug(logPrefix, 'clearing buffer'); diff --git a/test/media/streaming_engine_unit.js b/test/media/streaming_engine_unit.js index 4adcb5596a..3510b498a7 100644 --- a/test/media/streaming_engine_unit.js +++ b/test/media/streaming_engine_unit.js @@ -1179,12 +1179,13 @@ describe('StreamingEngine', () => { const segmentType = shaka.net.NetworkingEngine.RequestType.SEGMENT; const segmentContext = { - type: shaka.net.NetworkingEngine.AdvancedRequestType.INIT_SEGMENT, + type: shaka.net.NetworkingEngine.AdvancedRequestType.MEDIA_SEGMENT, }; - // Quickly switching back to text1, and text init segment should be + // Quickly switching back to text1, and text init segment shouldn't be // fetched again. - netEngine.expectRequest('text-20-init', segmentType, segmentContext); + netEngine.expectRequest('text-20-0.mp4', segmentType, segmentContext); + netEngine.expectNoRequest('text-20-init', segmentType, segmentContext); netEngine.expectNoRequest('text-21-init', segmentType, segmentContext); // TODO: huh? });