Skip to content

Commit

Permalink
fix(WebOS): Do not preload DRM on legacy EME (#8083)
Browse files Browse the repository at this point in the history
Fixes #7770 
Webkit DRM heavily relies on video element, so it needs to be provided
in proper order to avoid any issues.

---------

Co-authored-by: Álvaro Velad Galván <[email protected]>
  • Loading branch information
tykus160 and avelad committed Feb 17, 2025
1 parent c6f8a35 commit 79f5151
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
3 changes: 3 additions & 0 deletions lib/media/drm_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,9 @@ shaka.media.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 @@ -28,6 +28,7 @@ goog.require('shaka.util.ConfigUtils');
goog.require('shaka.util.FakeEvent');
goog.require('shaka.util.FakeEventTarget');
goog.require('shaka.util.ObjectUtils');
goog.require('shaka.util.Platform');
goog.require('shaka.util.PlayerConfiguration');

/**
Expand Down Expand Up @@ -395,17 +396,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 @@ -545,13 +550,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 @@ -578,6 +583,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 @@ -1766,6 +1766,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

0 comments on commit 79f5151

Please sign in to comment.