Skip to content

Commit

Permalink
Made some changes to fix merge with shaka-project#6204
Browse files Browse the repository at this point in the history
  • Loading branch information
theodab committed Feb 1, 2024
1 parent 323eae1 commit 0e93d59
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
35 changes: 23 additions & 12 deletions lib/media/manifest_filterer.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ shaka.media.ManifestFilterer = class {
}


/**
* @param {?shaka.extern.Manifest} manifest
* @return {boolean} tracksChanged
*/
applyRestrictions(manifest) {
return shaka.util.StreamUtils.applyRestrictions(
manifest.variants, this.config_.restrictions, this.maxHwRes_);
}


/**
* Apply the restrictions configuration to the manifest, and check if there's
* a variant that meets the restrictions.
Expand All @@ -72,20 +82,21 @@ shaka.media.ManifestFilterer = class {
* @return {boolean} tracksChanged
*/
filterManifestWithRestrictions(manifest) {
const tracksChanged = shaka.util.StreamUtils.applyRestrictions(
manifest.variants, this.config_.restrictions, this.maxHwRes_);

// We may need to create new sessions for any new init data.
const currentDrmInfo =
this.drmEngine_ ? this.drmEngine_.getDrmInfo() : null;
// DrmEngine.newInitData() requires mediaKeys to be available.
if (currentDrmInfo && this.drmEngine_.getMediaKeys()) {
for (const variant of manifest.variants) {
this.processDrmInfos(currentDrmInfo.keySystem, variant.video);
this.processDrmInfos(currentDrmInfo.keySystem, variant.audio);
const tracksChanged = this.applyRestrictions(manifest);

if (manifest) {
// We may need to create new sessions for any new init data.
const currentDrmInfo =
this.drmEngine_ ? this.drmEngine_.getDrmInfo() : null;
// DrmEngine.newInitData() requires mediaKeys to be available.
if (currentDrmInfo && this.drmEngine_.getMediaKeys()) {
for (const variant of manifest.variants) {
this.processDrmInfos(currentDrmInfo.keySystem, variant.video);
this.processDrmInfos(currentDrmInfo.keySystem, variant.audio);
}
}
this.checkRestrictedVariants(manifest);
}
this.checkRestrictedVariants(manifest);

return tracksChanged;
}
Expand Down
20 changes: 17 additions & 3 deletions lib/media/preload_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,9 @@ shaka.media.PreloadManager = class extends shaka.util.FakeEventTarget {
* @private
*/
async initializeDrmInner_() {
goog.asserts.assert(
this.manifest_, 'The manifest should already be parsed.');

this.makeStateChangeEvent_('drm-engine');

this.startTimeOfDrm_ = Date.now() / 1000;
Expand All @@ -532,16 +535,27 @@ shaka.media.PreloadManager = class extends shaka.util.FakeEventTarget {

this.drmEngine_.configure(this.config_.drm);

const tracksChangedInitial = this.manifestFilterer_.applyRestrictions(
this.manifest_);
if (tracksChangedInitial) {
const event = this.makeEvent_(
shaka.util.FakeEvent.EventName.TracksChanged);
await Promise.resolve();
this.dispatchEvent(event);
}

const playableVariants = shaka.util.StreamUtils.getPlayableVariants(
this.manifest_.variants);
await this.drmEngine_.initForPlayback(
this.manifest_.variants,
playableVariants,
this.manifest_.offlineSessionIds);

// Now that we have drm information, filter the manifest (again) so that
// we can ensure we only use variants with the selected key system.
// const tracksChanged =
const tracksChanged = await this.manifestFilterer_.filterManifest(
const tracksChangedAfter = await this.manifestFilterer_.filterManifest(
this.manifest_);
if (tracksChanged) {
if (tracksChangedAfter) {
const event = this.makeEvent_(
shaka.util.FakeEvent.EventName.TracksChanged);
await Promise.resolve();
Expand Down

0 comments on commit 0e93d59

Please sign in to comment.