From 482d8d43586bb8124a70b8cfd4d4b379f2867f43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Tue, 20 Aug 2024 11:36:23 +0200 Subject: [PATCH] fix(DASH): Allow play all time fastSwitching tracks (#7180) --- externs/shaka/abr_manager.js | 5 ++--- lib/abr/simple_abr_manager.js | 6 ++---- lib/media/preload_manager.js | 3 +-- lib/media/segment_prefetch.js | 4 ---- lib/player.js | 11 +++-------- 5 files changed, 8 insertions(+), 21 deletions(-) diff --git a/externs/shaka/abr_manager.js b/externs/shaka/abr_manager.js index 61bb230cb2..1a7b3a9932 100644 --- a/externs/shaka/abr_manager.js +++ b/externs/shaka/abr_manager.js @@ -60,12 +60,11 @@ shaka.extern.AbrManager = class { /** * Chooses one variant to switch to. Called by the Player. - * @param {boolean=} preferFastSwitching If not provided meant "avoid fast - * switching if possible". + * * @return {shaka.extern.Variant} * @exportDoc */ - chooseVariant(preferFastSwitching) {} + chooseVariant() {} /** * Enables automatic Variant choices from the last ones passed to setVariants. diff --git a/lib/abr/simple_abr_manager.js b/lib/abr/simple_abr_manager.js index 9d5fbbf42c..9a1c8898fc 100644 --- a/lib/abr/simple_abr_manager.js +++ b/lib/abr/simple_abr_manager.js @@ -167,12 +167,11 @@ shaka.abr.SimpleAbrManager = class { /** - * @param {boolean=} preferFastSwitching * @return {shaka.extern.Variant} * @override * @export */ - chooseVariant(preferFastSwitching = false) { + chooseVariant() { let maxHeight = Infinity; let maxWidth = Infinity; @@ -200,8 +199,7 @@ shaka.abr.SimpleAbrManager = class { } let variants = normalVariants; - if (preferFastSwitching && - normalVariants.length != this.variants_.length) { + if (normalVariants.length != this.variants_.length) { variants = this.variants_.filter((variant) => { return variant && shaka.util.StreamUtils.isFastSwitching(variant); }); diff --git a/lib/media/preload_manager.js b/lib/media/preload_manager.js index ab6d2e9e23..13029c1d15 100644 --- a/lib/media/preload_manager.js +++ b/lib/media/preload_manager.js @@ -634,8 +634,7 @@ shaka.media.PreloadManager = class extends shaka.util.FakeEventTarget { // Guess what the first variant will be, based on a SimpleAbrManager. this.abrManager_.configure(this.config_.abr); this.abrManager_.setVariants(Array.from(adaptationSet.values())); - const variant = - this.abrManager_.chooseVariant(/* preferFastSwitching= */ true); + const variant = this.abrManager_.chooseVariant(); if (variant) { this.prefetchedVariant_ = variant; if (variant.video) { diff --git a/lib/media/segment_prefetch.js b/lib/media/segment_prefetch.js index 384844c07e..31c0d0a3c8 100644 --- a/lib/media/segment_prefetch.js +++ b/lib/media/segment_prefetch.js @@ -120,10 +120,6 @@ shaka.media.SegmentPrefetch = class { segmentPrefetchOperation.dispatchFetch(reference, this.stream_); this.segmentPrefetchMap_.set(reference, segmentPrefetchOperation); } - if (this.stream_.fastSwitching && reference.isPartial() && - reference.isLastPartial()) { - break; - } } this.clearInitSegments_(); } diff --git a/lib/player.js b/lib/player.js index 70065d87f2..19158e3125 100644 --- a/lib/player.js +++ b/lib/player.js @@ -2458,7 +2458,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget { do { activeVariant = this.streamingEngine_.getCurrentVariant(); if (!activeVariant && !initialVariant) { - initialVariant = this.chooseVariant_(/* initialSelection= */ true); + initialVariant = this.chooseVariant_(); goog.asserts.assert(initialVariant, 'Must choose an initial variant!'); } @@ -3620,10 +3620,6 @@ shaka.Player = class extends shaka.util.FakeEventTarget { this.onSegmentAppended_( reference.startTime, reference.endTime, stream.type, stream.codecs.includes(',')); - if (this.abrManager_ && stream.fastSwitching && - reference.isPartial() && reference.isLastPartial()) { - this.abrManager_.trySuggestStreams(); - } }, onInitSegmentAppended: (position, initSegment) => { const mediaQuality = initSegment.getMediaQuality(); @@ -6760,13 +6756,12 @@ shaka.Player = class extends shaka.util.FakeEventTarget { * * On error, this dispatches an error event and returns null. * - * @param {boolean=} initialSelection * @return {?shaka.extern.Variant} * @private */ - chooseVariant_(initialSelection = false) { + chooseVariant_() { if (this.updateAbrManagerVariants_()) { - return this.abrManager_.chooseVariant(initialSelection); + return this.abrManager_.chooseVariant(); } else { return null; }