Skip to content

Commit

Permalink
fix(fairplay): Re-add initDataTransform config (shaka-project#4231)
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.

Co-authored-by: Joey Parrish <[email protected]>
  • Loading branch information
Álvaro Velad Galván and joeyparrish authored May 17, 2022
1 parent 4ae3a08 commit ff310e9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
3 changes: 1 addition & 2 deletions docs/tutorials/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ application:
`manifest.defaultPresentationDelay` (deprecated in v3.0.0)
- Configuration of factories should be plain factory functions, not
constructors; these will not be invoked with `new` (deprecated in v3.1.0)
- `drm.initDataTransform` has been removed (no longer needed since the
minimum supported version of iOS is now 13)
- `drm.initDataTransform` now defaults to a no-op
- `streaming.smallGapLimit` and `streaming.jumpLargeGaps` have been removed;
all gaps will now be jumped
- `manifest.hls.useFullSegmentsForStartTime` has been removed; this setting
Expand Down
11 changes: 11 additions & 0 deletions externs/shaka/player.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
5 changes: 5 additions & 0 deletions lib/util/player_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ 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 shaka.util.ConfigUtils.referenceParametersAndReturn(
[initData, initDataType, drmInfo],
initData);
},
logLicenseExchange: false,
updateExpirationTime: 1,
preferredKeySystems: [],
Expand Down

0 comments on commit ff310e9

Please sign in to comment.