Skip to content

Commit

Permalink
fix(preload): Fix preload error reporting (#6746)
Browse files Browse the repository at this point in the history
  • Loading branch information
theodab authored Jun 4, 2024
1 parent f8cf146 commit 95422b1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 35 deletions.
29 changes: 3 additions & 26 deletions lib/media/preload_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -716,7 +693,7 @@ shaka.media.PreloadManager = class extends shaka.util.FakeEventTarget {
*/
waitForFinish() {
return Promise.race([
this.chooseInitialVariantPromise_,
this.successPromise_,
this.destroyPromise_,
]);
}
Expand Down
14 changes: 5 additions & 9 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit 95422b1

Please sign in to comment.