Skip to content

Commit

Permalink
fix: unnecessary parsing of in-band pssh when pssh is in the manifest (
Browse files Browse the repository at this point in the history
…#5198)

When pssh is provided in the manifest we do not need to parse in-band pssh even if the drm.parseInbandPssh setting is true.

Fixes #5197

Cherry-picked to v4.2.x
  • Loading branch information
caridley authored and joeyparrish committed May 30, 2023
1 parent 0147b94 commit 889cc68
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/media/drm_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ shaka.media.DrmEngine = class {

/** @private {Promise} */
this.mediaKeysAttached_ = null;

/** @private {?shaka.extern.InitDataOverride} */
this.manifestInitData_ = null;
}

/** @override */
Expand Down Expand Up @@ -480,18 +483,18 @@ shaka.media.DrmEngine = class {
() => this.closeOpenSessions_());
}

const manifestInitData = this.currentDrmInfo_ ?
this.currentDrmInfo_.initData.find(
this.manifestInitData_ = this.currentDrmInfo_ ?
(this.currentDrmInfo_.initData.find(
(initDataOverride) => initDataOverride.initData.length > 0,
) : null;
) || null) : null;

/**
* We can attach media keys before the playback actually begins when:
* - If we are not using FairPlay Modern EME
* - Some initData already has been generated (through the manifest)
* - In case of an offline session
*/
if (manifestInitData ||
if (this.manifestInitData_ ||
this.currentDrmInfo_.keySystem !== 'com.apple.fps' ||
this.offlineSessionIds_.length) {
await this.attachMediaKeys_();
Expand All @@ -504,7 +507,7 @@ shaka.media.DrmEngine = class {
// Also suppress 'encrypted' events when parsing in-band ppsh
// from media segments because that serves the same purpose as the
// 'encrypted' events.
if (!manifestInitData && !this.offlineSessionIds_.length &&
if (!this.manifestInitData_ && !this.offlineSessionIds_.length &&
!this.config_.parseInbandPsshEnabled) {
this.eventManager_.listen(
this.video_, 'encrypted', (e) => this.onEncryptedEvent_(e));
Expand Down Expand Up @@ -2353,7 +2356,7 @@ shaka.media.DrmEngine = class {
* @return {!Promise<void>}
*/
parseInbandPssh(contentType, mediaSegment) {
if (!this.config_.parseInbandPsshEnabled) {
if (!this.config_.parseInbandPsshEnabled || this.manifestInitData_) {
return Promise.resolve();
}

Expand Down

0 comments on commit 889cc68

Please sign in to comment.