Skip to content

Commit

Permalink
fix: Re-add initDataTransform config
Browse files Browse the repository at this point in the history
Some FairPlay providers still need this part, so we should never have removed it.

The default is to do no transformation.
  • Loading branch information
Alvaro Velad committed May 17, 2022
1 parent 80e81f1 commit 147a37b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
11 changes: 11 additions & 0 deletions externs/shaka/player.js
Expand Up @@ -618,6 +618,9 @@ shaka.extern.AdvancedDrmConfiguration;
* clearKeys: !Object.<string, string>,
* delayLicenseRequestUntilPlayed: boolean,
* advanced: Object.<string, shaka.extern.AdvancedDrmConfiguration>,
* initDataTransform:
* ((function(!Uint8Array, string, ?shaka.extern.DrmInfo):!Uint8Array)|
* undefined),
* logLicenseExchange: boolean,
* updateExpirationTime: number,
* preferredKeySystems: !Array.<string>
Expand All @@ -641,6 +644,14 @@ shaka.extern.AdvancedDrmConfiguration;
* <i>Optional.</i> <br>
* A dictionary which maps key system IDs to advanced DRM configuration for
* those key systems.
* @property
* {((function(!Uint8Array, string, ?shaka.extern.DrmInfo):!Uint8Array)|
* undefined)}
* initDataTransform
* <i>Optional.</i><br>
* If given, this function is called with the init data from the
* manifest/media and should return the (possibly transformed) init data to
* pass to the browser.
* @property {boolean} logLicenseExchange
* <i>Optional.</i><br>
* If set to <code>true</code>, prints logs containing the license exchange.
Expand Down
16 changes: 16 additions & 0 deletions lib/media/drm_engine.js
Expand Up @@ -1253,6 +1253,22 @@ shaka.media.DrmEngine = class {
};
this.activeSessions_.set(session, metadata);

try {
initData = this.config_.initDataTransform(
initData, initDataType, this.currentDrmInfo_);
} catch (error) {
let shakaError = error;
if (!(error instanceof shaka.util.Error)) {
shakaError = new shaka.util.Error(
shaka.util.Error.Severity.CRITICAL,
shaka.util.Error.Category.DRM,
shaka.util.Error.Code.INIT_DATA_TRANSFORM_ERROR,
error);
}
this.onError_(shakaError);
return;
}

if (this.config_.logLicenseExchange) {
const str = shaka.util.Uint8ArrayUtils.toBase64(initData);
shaka.log.info('EME init data: type=', initDataType, 'data=', str);
Expand Down
3 changes: 3 additions & 0 deletions lib/util/player_configuration.js
Expand Up @@ -74,6 +74,9 @@ shaka.util.PlayerConfiguration = class {
clearKeys: {}, // key is arbitrary key system ID, value must be string
advanced: {}, // key is arbitrary key system ID, value is a record type
delayLicenseRequestUntilPlayed: false,
initDataTransform: (initData, initDataType, drmInfo) => {
return initData;
},
logLicenseExchange: false,
updateExpirationTime: 1,
preferredKeySystems: [],
Expand Down

0 comments on commit 147a37b

Please sign in to comment.