diff --git a/docs/tutorials/drm-config.md b/docs/tutorials/drm-config.md index 8e9f79767e..1f34196ce5 100644 --- a/docs/tutorials/drm-config.md +++ b/docs/tutorials/drm-config.md @@ -75,6 +75,22 @@ player.configure({ If the browser supports it and you configured a license server URL for it, we'll use it. +Alternative there are a config for make a mapping of keysystem if you know that +is broadly supported. For example, `com.microsoft.playready.recommendation`: + +```js +player.configure({ + drm: { + keySystemsMapping: { + 'com.microsoft.playready': 'com.microsoft.playready.recommendation', + } + } +}); +``` + +With the previous configuration you will choose the `recommendation` keySystem +when your manifest (HLS or DASH) uses PlayReady. + #### Clear Key diff --git a/externs/shaka/player.js b/externs/shaka/player.js index 1b77b95782..aaef33997a 100644 --- a/externs/shaka/player.js +++ b/externs/shaka/player.js @@ -623,7 +623,8 @@ shaka.extern.AdvancedDrmConfiguration; * undefined), * logLicenseExchange: boolean, * updateExpirationTime: number, - * preferredKeySystems: !Array. + * preferredKeySystems: !Array., + * keySystemsMapping: !Object. * }} * * @property {shaka.extern.RetryParameters} retryParameters @@ -664,6 +665,8 @@ shaka.extern.AdvancedDrmConfiguration; * @property {!Array.} preferredKeySystems * Defaults to an empty array.
* Specifies the priorties of available DRM key systems. + * @property {Object.} keySystemsMapping + * A map of key system name to key system name. * * @exportDoc */ diff --git a/lib/media/drm_engine.js b/lib/media/drm_engine.js index b3d6c343f4..71a3de3127 100644 --- a/lib/media/drm_engine.js +++ b/lib/media/drm_engine.js @@ -355,7 +355,8 @@ shaka.media.DrmEngine = class { shaka.media.DrmEngine.fillInDrmInfoDefaults_( info, shaka.util.MapUtils.asMap(this.config_.servers), - shaka.util.MapUtils.asMap(this.config_.advanced || {})); + shaka.util.MapUtils.asMap(this.config_.advanced || {}), + this.config_.keySystemsMapping); } } @@ -2224,16 +2225,20 @@ shaka.media.DrmEngine = class { * that the parser left blank. Before working with any drmInfo, it should be * passed through here as it is uncommon for drmInfo to be complete when * fetched from a manifest because most manifest formats do not have the - * required information. + * required information. Also applies the key systems mapping. * * @param {shaka.extern.DrmInfo} drmInfo * @param {!Map.} servers * @param {!Map.} * advancedConfigs + * @param {!Object.} keySystemsMapping * @private */ - static fillInDrmInfoDefaults_(drmInfo, servers, advancedConfigs) { - if (!drmInfo.keySystem) { + static fillInDrmInfoDefaults_(drmInfo, servers, advancedConfigs, + keySystemsMapping) { + const originalKeySystem = drmInfo.keySystem; + + if (!originalKeySystem) { // This is a placeholder from the manifest parser for an unrecognized key // system. Skip this entry, to avoid logging nonsensical errors. return; @@ -2254,14 +2259,14 @@ shaka.media.DrmEngine = class { // The only way to get license servers from the manifest is not to specify // any in your player config. - if (drmInfo.keySystem == 'org.w3.clearkey' && drmInfo.licenseServerUri) { + if (originalKeySystem == 'org.w3.clearkey' && drmInfo.licenseServerUri) { // Preference 1: Clear Key with pre-configured keys will have a data URI // assigned as its license server. Don't change anything. return; } else if (servers.size) { // Preference 2: If anything is configured at the application level, // override whatever was in the manifest. - const server = servers.get(drmInfo.keySystem) || ''; + const server = servers.get(originalKeySystem) || ''; drmInfo.licenseServerUri = server; } else { @@ -2273,7 +2278,7 @@ shaka.media.DrmEngine = class { drmInfo.keyIds = new Set(); } - const advancedConfig = advancedConfigs.get(drmInfo.keySystem); + const advancedConfig = advancedConfigs.get(originalKeySystem); if (advancedConfig) { if (!drmInfo.distinctiveIdentifierRequired) { @@ -2307,6 +2312,10 @@ shaka.media.DrmEngine = class { } } + if (keySystemsMapping[originalKeySystem]) { + drmInfo.keySystem = keySystemsMapping[originalKeySystem]; + } + // Chromecast has a variant of PlayReady that uses a different key // system ID. Since manifest parsers convert the standard PlayReady // UUID to the standard PlayReady key system ID, here we will switch @@ -2315,7 +2324,7 @@ shaka.media.DrmEngine = class { // player config uses the standard PlayReady ID for license server // configuration. if (window.cast && window.cast.__platform__) { - if (drmInfo.keySystem == 'com.microsoft.playready') { + if (originalKeySystem == 'com.microsoft.playready') { drmInfo.keySystem = 'com.chromecast.playready'; } } diff --git a/lib/util/player_configuration.js b/lib/util/player_configuration.js index ffa0e987ac..b61490eac7 100644 --- a/lib/util/player_configuration.js +++ b/lib/util/player_configuration.js @@ -74,6 +74,7 @@ shaka.util.PlayerConfiguration = class { logLicenseExchange: false, updateExpirationTime: 1, preferredKeySystems: [], + keySystemsMapping: {}, }; const manifest = { diff --git a/test/demo/demo_unit.js b/test/demo/demo_unit.js index 1b0828de45..e7b7b635e0 100644 --- a/test/demo/demo_unit.js +++ b/test/demo/demo_unit.js @@ -94,7 +94,8 @@ describe('Demo', () => { .add('playRangeStart') .add('playRangeEnd') .add('manifest.dash.keySystemsByURI') - .add('manifest.hls.mediaPlaylistFullMimeType'); + .add('manifest.hls.mediaPlaylistFullMimeType') + .add('drm.keySystemsMapping'); /** * @param {!Object} section