From 812c7e20a2c4171a636260a08978f48ff73d5244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Mon, 6 May 2024 20:02:31 +0200 Subject: [PATCH] fix: Fix init segment equality in Segment Prefetch (#6537) --- lib/media/segment_prefetch.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/media/segment_prefetch.js b/lib/media/segment_prefetch.js index b4f0b5b8c2..9643a24b8c 100644 --- a/lib/media/segment_prefetch.js +++ b/lib/media/segment_prefetch.js @@ -147,7 +147,12 @@ shaka.media.SegmentPrefetch = class { } // init segments are ignored from the prefetch limit - if (!this.initSegmentPrefetchMap_.has(initSegmentReference)) { + const initSegments = Array.from(this.initSegmentPrefetchMap_.keys()); + const someReference = initSegments.some((reference) => { + return shaka.media.InitSegmentReference.equal( + reference, initSegmentReference); + }); + if (!someReference) { const segmentPrefetchOperation = new shaka.media.SegmentPrefetchOperation(this.fetchDispatcher_); segmentPrefetchOperation.dispatchFetch( @@ -270,9 +275,11 @@ shaka.media.SegmentPrefetch = class { const segmentReferences = Array.from(this.segmentPrefetchMap_.keys()); for (const initSegmentReference of this.initSegmentPrefetchMap_.keys()) { // if no segment references this init segment, we should remove it. - if (!segmentReferences.some( - (segmentReference) => - segmentReference.initSegmentReference === initSegmentReference)) { + const someReference = segmentReferences.some((segmentReference) => { + return shaka.media.InitSegmentReference.equal( + segmentReference.initSegmentReference, initSegmentReference); + }); + if (!someReference) { this.abortPrefetchedSegment_(initSegmentReference); } }