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
…shaka-project#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 shaka-project#5197
  • Loading branch information
caridley committed Apr 28, 2023
1 parent 62ca694 commit 05aa931
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/media/drm_engine.js
Expand Up @@ -139,6 +139,9 @@ shaka.media.DrmEngine = class {

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

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

/** @override */
Expand Down Expand Up @@ -498,18 +501,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.storedPersistentSessions_.size) {
await this.attachMediaKeys_();
Expand All @@ -525,7 +528,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.storedPersistentSessions_.size &&
if (!this.manifestInitData_ && !this.storedPersistentSessions_.size &&
!this.config_.parseInbandPsshEnabled) {
this.eventManager_.listen(
this.video_, 'encrypted', (e) => this.onEncryptedEvent_(e));
Expand Down Expand Up @@ -2496,7 +2499,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 05aa931

Please sign in to comment.