From 95422b17d62964f45528061b678651081910c184 Mon Sep 17 00:00:00 2001 From: theodab Date: Tue, 4 Jun 2024 05:29:43 -0700 Subject: [PATCH] fix(preload): Fix preload error reporting (#6746) --- lib/media/preload_manager.js | 29 +++-------------------------- lib/player.js | 14 +++++--------- 2 files changed, 8 insertions(+), 35 deletions(-) diff --git a/lib/media/preload_manager.js b/lib/media/preload_manager.js index 6b6b529657..a5c324e69e 100644 --- a/lib/media/preload_manager.js +++ b/lib/media/preload_manager.js @@ -132,13 +132,7 @@ shaka.media.PreloadManager = class extends shaka.util.FakeEventTarget { this.stats_ = new shaka.util.Stats(); /** @private {!shaka.util.PublicPromise} */ - this.manifestPromise_ = new shaka.util.PublicPromise(); - - /** @private {!shaka.util.PublicPromise} */ - this.drmPromise_ = new shaka.util.PublicPromise(); - - /** @private {!shaka.util.PublicPromise} */ - this.chooseInitialVariantPromise_ = new shaka.util.PublicPromise(); + this.successPromise_ = new shaka.util.PublicPromise(); /** @private {!shaka.util.PublicPromise} */ this.destroyPromise_ = new shaka.util.PublicPromise(); @@ -353,21 +347,6 @@ shaka.media.PreloadManager = class extends shaka.util.FakeEventTarget { return this.segmentPrefetchById_; } - /** @return {!Promise} */ - waitForManifest() { - return this.manifestPromise_; - } - - /** @return {!Promise} */ - waitForDrm() { - return this.drmPromise_; - } - - /** @return {!Promise} */ - waitForChooseInitialVariant() { - return this.chooseInitialVariantPromise_; - } - /** * @param {?shaka.extern.AbrManager} abrManager * @param {?shaka.extern.AbrManager.Factory} abrFactory @@ -410,17 +389,15 @@ shaka.media.PreloadManager = class extends shaka.util.FakeEventTarget { if (this.isDestroyed()) { return; } - this.manifestPromise_.resolve(); await this.initializeDrmInner_(); if (this.isDestroyed()) { return; } - this.drmPromise_.resolve(); await this.chooseInitialVariantInner_(); if (this.isDestroyed()) { return; } - this.chooseInitialVariantPromise_.resolve(); + this.successPromise_.resolve(); } catch (error) { this.destroyPromise_.reject(error); throw error; @@ -716,7 +693,7 @@ shaka.media.PreloadManager = class extends shaka.util.FakeEventTarget { */ waitForFinish() { return Promise.race([ - this.chooseInitialVariantPromise_, + this.successPromise_, this.destroyPromise_, ]); } diff --git a/lib/player.js b/lib/player.js index aa4c3ae96c..73d463aae9 100644 --- a/lib/player.js +++ b/lib/player.js @@ -1622,9 +1622,12 @@ shaka.Player = class extends shaka.util.FakeEventTarget { }, 'initializeMediaSourceEngineInner_'); } + // Wait for the preload manager to do all of the loading it can do. + await mutexWrapOperation(async () => { + await preloadManager.waitForFinish(); + }, 'waitForFinish'); + // Get manifest and associated values from preloader. - await mutexWrapOperation( - () => preloadManager.waitForManifest(), 'waitForManifest'); this.config_ = preloadManager.getConfiguration(); this.manifestFilterer_ = preloadManager.getManifestFilterer(); this.parserFactory_ = preloadManager.getParserFactory(); @@ -1648,18 +1651,11 @@ shaka.Player = class extends shaka.util.FakeEventTarget { } // Get drm engine from preloader, then finalize it. - await mutexWrapOperation( - () => preloadManager.waitForDrm(), 'waitForDrm'); this.drmEngine_ = preloadManager.receiveDrmEngine(); await mutexWrapOperation(async () => { await this.drmEngine_.attach(this.video_); }, 'drmEngine_.attach'); - // Choose an initial variant. - await mutexWrapOperation( - () => preloadManager.waitForChooseInitialVariant(), - 'waitForChooseInitialVariant'); - // Also get the ABR manager, which has special logic related to being // received. const abrManagerFactory = preloadManager.getAbrManagerFactory();