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 all 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
3 changes: 3 additions & 0 deletions lib/drm/drm_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,9 @@ shaka.drm.DrmEngine = class {
* @return {!Promise}
*/
async attach(video) {
if (this.video_ === video) {
return;
}
if (!this.mediaKeys_) {
// Unencrypted, or so we think. We listen for encrypted events in order
// to warn when the stream is encrypted, even though the manifest does
Expand Down
27 changes: 18 additions & 9 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 @@ -396,17 +397,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 @@ -559,13 +564,13 @@ shaka.media.PreloadManager = class extends shaka.util.FakeEventTarget {

/**
* Initializes the DRM engine.
*
* @param {?HTMLMediaElement=} media
* @return {!Promise}
* @private
*/
async initializeDrmInner_() {
goog.asserts.assert(
this.manifest_, 'The manifest should already be parsed.');
async initializeDrm(media) {
if (!this.manifest_ || this.drmEngine_) {
return;
}

this.makeStateChangeEvent_('drm-engine');

Expand All @@ -592,6 +597,10 @@ shaka.media.PreloadManager = class extends shaka.util.FakeEventTarget {
playableVariants,
this.manifest_.offlineSessionIds);
this.throwIfDestroyed_();
if (media) {
await this.drmEngine_.attach(media);
this.throwIfDestroyed_();
}

// 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
7 changes: 7 additions & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1822,6 +1822,13 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
this.configure('manifest.disableVideo', true);
}

// Init DRM engine if it's not created yet (happens on polyfilled EME).
if (!preloadManager.getDrmEngine()) {
await mutexWrapOperation(async () => {
await preloadManager.initializeDrm(this.video_);
}, 'drmEngine_.init');
}

// Get drm engine from preloader, then finalize it.
this.drmEngine_ = preloadManager.receiveDrmEngine();
await mutexWrapOperation(async () => {
Expand Down
Loading