From ff310e91e564bcc4be340c47bf1be81a5323765a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Tue, 17 May 2022 20:53:52 +0200 Subject: [PATCH] fix(fairplay): Re-add initDataTransform config (#4231) 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 --- docs/tutorials/upgrade.md | 3 +-- externs/shaka/player.js | 11 +++++++++++ lib/media/drm_engine.js | 16 ++++++++++++++++ lib/util/player_configuration.js | 5 +++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/docs/tutorials/upgrade.md b/docs/tutorials/upgrade.md index 9a581e1c78..800bffbcaa 100644 --- a/docs/tutorials/upgrade.md +++ b/docs/tutorials/upgrade.md @@ -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 diff --git a/externs/shaka/player.js b/externs/shaka/player.js index d12f4ec07e..1b77b95782 100644 --- a/externs/shaka/player.js +++ b/externs/shaka/player.js @@ -618,6 +618,9 @@ shaka.extern.AdvancedDrmConfiguration; * clearKeys: !Object., * delayLicenseRequestUntilPlayed: boolean, * advanced: Object., + * initDataTransform: + * ((function(!Uint8Array, string, ?shaka.extern.DrmInfo):!Uint8Array)| + * undefined), * logLicenseExchange: boolean, * updateExpirationTime: number, * preferredKeySystems: !Array. @@ -641,6 +644,14 @@ shaka.extern.AdvancedDrmConfiguration; * Optional.
* 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 + * Optional.
+ * 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 * Optional.
* If set to true, prints logs containing the license exchange. diff --git a/lib/media/drm_engine.js b/lib/media/drm_engine.js index 594655928a..0603dd3416 100644 --- a/lib/media/drm_engine.js +++ b/lib/media/drm_engine.js @@ -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); diff --git a/lib/util/player_configuration.js b/lib/util/player_configuration.js index fc2e51d04f..ffa0e987ac 100644 --- a/lib/util/player_configuration.js +++ b/lib/util/player_configuration.js @@ -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: [],