Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Re-add initDataTransform config #4231

Merged
merged 3 commits into from May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions docs/tutorials/upgrade.md
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
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
5 changes: 5 additions & 0 deletions lib/util/player_configuration.js
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) => {
joeyparrish marked this conversation as resolved.
Show resolved Hide resolved
return shaka.util.ConfigUtils.referenceParametersAndReturn(
[initData, initDataType, drmInfo],
initData);
},
logLicenseExchange: false,
updateExpirationTime: 1,
preferredKeySystems: [],
Expand Down