Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(WebOS): Do not preload DRM on legacy EME #8083

Merged
merged 9 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions lib/media/preload_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ goog.require('shaka.util.FakeEvent');
goog.require('shaka.util.FakeEventTarget');
goog.require('shaka.util.IDestroyable');
goog.require('shaka.util.ObjectUtils');
goog.require('shaka.util.Platform');
goog.require('shaka.util.PlayerConfiguration');
goog.require('shaka.util.PublicPromise');
goog.require('shaka.util.Stats');
Expand Down Expand Up @@ -131,6 +132,9 @@ shaka.media.PreloadManager = class extends shaka.util.FakeEventTarget {
/** @private {!shaka.util.PublicPromise} */
this.manifestPromise_ = new shaka.util.PublicPromise();

/** @private {!shaka.util.PublicPromise} */
this.drmEnginePromise_ = new shaka.util.PublicPromise();

/** @private {!shaka.util.PublicPromise} */
this.successPromise_ = new shaka.util.PublicPromise();

Expand Down Expand Up @@ -396,17 +400,21 @@ shaka.media.PreloadManager = class extends shaka.util.FakeEventTarget {
await this.parseManifestInner_();
this.throwIfDestroyed_();

await this.initializeDrmInner_();
this.throwIfDestroyed_();
if (!shaka.util.Platform.isMediaKeysPolyfilled('webkit')) {
await this.initializeDrm();
this.throwIfDestroyed_();
}

await this.chooseInitialVariantAndPrefetchInner_();
this.throwIfDestroyed_();

// We don't need the drm keys to load completely for the initial variant
// to be chosen, but we won't mark the load as a success until it has
// been loaded. So wait for it here, not inside initializeDrmInner_.
await this.drmEngine_.waitForActiveRequests();
this.throwIfDestroyed_();
if (this.drmEngine_) {
await this.drmEngine_.waitForActiveRequests();
this.throwIfDestroyed_();
}

this.successPromise_.resolve();
} catch (error) {
Expand Down Expand Up @@ -561,11 +569,11 @@ shaka.media.PreloadManager = class extends shaka.util.FakeEventTarget {
* Initializes the DRM engine.
*
* @return {!Promise}
* @private
*/
async initializeDrmInner_() {
goog.asserts.assert(
this.manifest_, 'The manifest should already be parsed.');
async initializeDrm() {
if (!this.manifest_ || this.drmEngine_) {
return;
}

this.makeStateChangeEvent_('drm-engine');

Expand All @@ -592,6 +600,7 @@ shaka.media.PreloadManager = class extends shaka.util.FakeEventTarget {
playableVariants,
this.manifest_.offlineSessionIds);
this.throwIfDestroyed_();
this.drmEnginePromise_.resolve();

// Now that we have drm information, filter the manifest (again) so that
// we can ensure we only use variants with the selected key system.
Expand Down Expand Up @@ -766,6 +775,13 @@ shaka.media.PreloadManager = class extends shaka.util.FakeEventTarget {
return Promise.race(promises);
}

/**
* @return {!Promise}
*/
waitForDrmEngine() {
return this.drmEnginePromise_;
}

/**
* Releases or stops all non-entrusted resources.
*
Expand Down
7 changes: 6 additions & 1 deletion lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1823,8 +1823,13 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
}

// Get drm engine from preloader, then finalize it.
this.drmEngine_ = preloadManager.receiveDrmEngine();
await mutexWrapOperation(async () => {
if (!preloadManager.getDrmEngine()) {
preloadManager.initializeDrm();
}
await preloadManager.waitForDrmEngine();
this.drmEngine_ = preloadManager.receiveDrmEngine();
goog.asserts.assert(this.drmEngine_, 'Should have DRM Engine!');
await this.drmEngine_.attach(this.video_);
}, 'drmEngine_.attach');

Expand Down
Loading