Skip to content

Commit

Permalink
fix: Fix usage of keySystemsMapping (#7736)
Browse files Browse the repository at this point in the history
Related to #7613
  • Loading branch information
avelad authored Dec 10, 2024
1 parent 426090d commit 79a481e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
18 changes: 12 additions & 6 deletions lib/media/drm_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -934,14 +934,16 @@ shaka.media.DrmEngine = class {
'Got MediaKeySystemAccess with configuration',
realConfig);

const keySystem =
this.config_.keySystemsMapping[mediaKeySystemAccess.keySystem] ||
mediaKeySystemAccess.keySystem;

if (variants.length) {
this.currentDrmInfo_ = this.createDrmInfoByInfos_(
mediaKeySystemAccess.keySystem,
drmInfosByKeySystem.get(mediaKeySystemAccess.keySystem));
keySystem, drmInfosByKeySystem.get(keySystem));
} else {
this.currentDrmInfo_ = shaka.media.DrmEngine.createDrmInfoByConfigs_(
mediaKeySystemAccess.keySystem,
configsByKeySystem.get(mediaKeySystemAccess.keySystem));
keySystem, configsByKeySystem.get(keySystem));
}
if (!this.currentDrmInfo_.licenseServerUri) {
throw new shaka.util.Error(
Expand Down Expand Up @@ -1056,8 +1058,12 @@ shaka.media.DrmEngine = class {
if (!decodingInfo.supported || !decodingInfo.keySystemAccess) {
continue;
}
const drmInfos =
drmInfosByKeySystem.get(decodingInfo.keySystemAccess.keySystem);
const originalKeySystem = decodingInfo.keySystemAccess.keySystem;
let drmInfos = drmInfosByKeySystem.get(originalKeySystem);
if (!drmInfos && this.config_.keySystemsMapping[originalKeySystem]) {
drmInfos = drmInfosByKeySystem.get(
this.config_.keySystemsMapping[originalKeySystem]);
}
for (const info of drmInfos) {
if (!!info.licenseServerUri == shouldHaveLicenseServer) {
return decodingInfo.keySystemAccess;
Expand Down
3 changes: 2 additions & 1 deletion lib/media/manifest_filterer.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ shaka.media.ManifestFilterer = class {
async filterManifest(manifest) {
goog.asserts.assert(manifest, 'Manifest should exist!');
await shaka.util.StreamUtils.filterManifest(this.drmEngine_, manifest,
this.config_.drm.preferredKeySystems);
this.config_.drm.preferredKeySystems,
this.config_.drm.keySystemsMapping);
if (!this.config_.streaming.dontChooseCodecs) {
shaka.util.StreamUtils.chooseCodecsAndFilterManifest(
manifest,
Expand Down
2 changes: 1 addition & 1 deletion lib/offline/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ shaka.offline.Storage = class {
// to play later (no point storing something we can't play).
await shaka.util.StreamUtils.filterManifestByMediaCapabilities(
drmEngine, manifest, config.offline.usePersistentLicense,
config.drm.preferredKeySystems);
config.drm.preferredKeySystems, config.drm.keySystemsMapping);

// Gather all tracks.
const allTracks = [];
Expand Down
21 changes: 15 additions & 6 deletions lib/util/stream_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,13 @@ shaka.util.StreamUtils = class {
* @param {shaka.media.DrmEngine} drmEngine
* @param {shaka.extern.Manifest} manifest
* @param {!Array<string>=} preferredKeySystems
* @param {!Object.<string, string>=} keySystemsMapping
*/
static async filterManifest(drmEngine, manifest, preferredKeySystems = []) {
static async filterManifest(drmEngine, manifest, preferredKeySystems = [],
keySystemsMapping = {}) {
await shaka.util.StreamUtils.filterManifestByMediaCapabilities(
drmEngine, manifest, manifest.offlineSessionIds.length > 0,
preferredKeySystems);
preferredKeySystems, keySystemsMapping);
shaka.util.StreamUtils.filterTextStreams_(manifest);
await shaka.util.StreamUtils.filterImageStreams_(manifest);
}
Expand All @@ -411,9 +413,11 @@ shaka.util.StreamUtils = class {
* @param {shaka.extern.Manifest} manifest
* @param {boolean} usePersistentLicenses
* @param {!Array<string>} preferredKeySystems
* @param {!Object.<string, string>} keySystemsMapping
*/
static async filterManifestByMediaCapabilities(
drmEngine, manifest, usePersistentLicenses, preferredKeySystems) {
drmEngine, manifest, usePersistentLicenses, preferredKeySystems,
keySystemsMapping) {
goog.asserts.assert(navigator.mediaCapabilities,
'MediaCapabilities should be valid.');

Expand All @@ -435,7 +439,8 @@ shaka.util.StreamUtils = class {
const StreamUtils = shaka.util.StreamUtils;

manifest.variants = manifest.variants.filter((variant) => {
const supported = StreamUtils.checkVariantSupported_(variant, keySystem);
const supported = StreamUtils.checkVariantSupported_(
variant, keySystem, keySystemsMapping);
// Filter out all unsupported variants.
if (!supported) {
shaka.log.debug('Dropping variant - not compatible with platform',
Expand Down Expand Up @@ -485,18 +490,22 @@ shaka.util.StreamUtils = class {
/**
* @param {!shaka.extern.Variant} variant
* @param {?string} keySystem
* @param {!Object.<string, string>} keySystemsMapping
* @return {boolean}
* @private
*/
static checkVariantSupported_(variant, keySystem) {
static checkVariantSupported_(variant, keySystem, keySystemsMapping) {
const variantSupported = variant.decodingInfos.some((decodingInfo) => {
if (!decodingInfo.supported) {
return false;
}
if (keySystem) {
const keySystemAccess = decodingInfo.keySystemAccess;
if (keySystemAccess) {
if (keySystemAccess.keySystem != keySystem) {
const currentKeySystem =
keySystemsMapping[keySystemAccess.keySystem] ||
keySystemAccess.keySystem;
if (currentKeySystem != keySystem) {
return false;
}
}
Expand Down

0 comments on commit 79a481e

Please sign in to comment.