Skip to content

Commit

Permalink
feat: Config to require a minimum HDCP version (shaka-project#4883)
Browse files Browse the repository at this point in the history
https://github.com/WICG/hdcp-detection/blob/main/explainer.md

Co-authored-by: Joey Parrish <joeyparrish@users.noreply.github.com>
  • Loading branch information
avelad and joeyparrish committed Jan 11, 2023
1 parent fc3d5c1 commit 61613cf
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 2 deletions.
1 change: 1 addition & 0 deletions demo/common/message_ids.js
Expand Up @@ -232,6 +232,7 @@ shakaDemo.MessageIds = {
MEDIA_SOURCE_SECTION_HEADER: 'DEMO_MEDIA_SOURCE_SECTION_HEADER',
MIN_BANDWIDTH: 'DEMO_MIN_BANDWIDTH',
MIN_BYTES: 'DEMO_MIN_BYTES',
MIN_HDCP_VERSION: 'DEMO_MIN_HDCP_VERSION',
MIN_FRAMERATE: 'DEMO_MIN_FRAMERATE',
MIN_HEIGHT: 'DEMO_MIN_HEIGHT',
MIN_PIXELS: 'DEMO_MIN_PIXELS',
Expand Down
4 changes: 3 additions & 1 deletion demo/config.js
Expand Up @@ -135,7 +135,9 @@ shakaDemo.Config = class {
/* canBeZero= */ false,
/* canBeUnset= */ true)
.addBoolInput_(MessageIds.PARSE_INBAND_PSSH_ENABLED,
'drm.parseInbandPsshEnabled');
'drm.parseInbandPsshEnabled')
.addTextInput_(MessageIds.MIN_HDCP_VERSION,
'drm.minHdcpVersion');
const advanced = shakaDemoMain.getConfiguration().drm.advanced || {};
const addDRMAdvancedField = (name, valueName, suggestions) => {
// All advanced fields of a given type are set at once.
Expand Down
1 change: 1 addition & 0 deletions demo/locales/en.json
Expand Up @@ -157,6 +157,7 @@
"DEMO_MIME_TYPE": "MIME Type",
"DEMO_MIN_BANDWIDTH": "Min Bandwidth",
"DEMO_MIN_BYTES": "Min Bytes",
"DEMO_MIN_HDCP_VERSION": "Min HDCP version",
"DEMO_MIN_FRAMERATE": "Min Framerate",
"DEMO_MIN_HEIGHT": "Min Height",
"DEMO_MIN_PIXELS": "Min Pixels",
Expand Down
4 changes: 4 additions & 0 deletions demo/locales/source.json
Expand Up @@ -631,6 +631,10 @@
"description": "The name of a configuration value.",
"message": "Min Bytes"
},
"DEMO_MIN_HDCP_VERSION": {
"description": "The name of a configuration value.",
"message": "Min HDCP version"
},
"DEMO_MIN_FRAMERATE": {
"description": "The name of a configuration value.",
"message": "Min Framerate"
Expand Down
18 changes: 18 additions & 0 deletions externs/mediakeys.js
@@ -0,0 +1,18 @@
/*! @license
* Shaka Player
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @fileoverview Externs for MediaKeys which were missing in the
* Closure compiler.
*
* @externs
*/

/**
* @param {Object} policy
* @return {!Promise.<string>}
*/
MediaKeys.prototype.getStatusForPolicy = function(policy) {};
7 changes: 6 additions & 1 deletion externs/shaka/player.js
Expand Up @@ -695,7 +695,8 @@ shaka.extern.AdvancedDrmConfiguration;
* updateExpirationTime: number,
* preferredKeySystems: !Array.<string>,
* keySystemsMapping: !Object.<string, string>,
* parseInbandPsshEnabled: boolean
* parseInbandPsshEnabled: boolean,
* minHdcpVersion: string
* }}
*
* @property {shaka.extern.RetryParameters} retryParameters
Expand Down Expand Up @@ -743,6 +744,10 @@ shaka.extern.AdvancedDrmConfiguration;
* When true parse DRM init data from pssh boxes in media and init segments
* and ignore 'encrypted' events.
* This is required when using in-band key rotation on Xbox One.
* @property {string} minHdcpVersion
* <i>By default (''), do not check the HDCP version.</i><br>
* Indicates the minimum version of HDCP to start the playback of encrypted
* streams. <b>May be ignored if not supported by the device.</b>
*
* @exportDoc
*/
Expand Down
21 changes: 21 additions & 0 deletions lib/media/drm_engine.js
Expand Up @@ -924,6 +924,27 @@ shaka.media.DrmEngine = class {
this.currentDrmInfo_.keySystem);

this.mediaKeys_ = mediaKeys;
if (this.config_.minHdcpVersion != '' &&
'getStatusForPolicy' in this.mediaKeys_) {
try {
const status = await this.mediaKeys_.getStatusForPolicy({
minHdcpVersion: this.config_.minHdcpVersion,
});
if (status != 'usable') {
throw new shaka.util.Error(
shaka.util.Error.Severity.CRITICAL,
shaka.util.Error.Category.DRM,
shaka.util.Error.Code.MIN_HDCP_VERSION_NOT_MATCH);
}
this.destroyer_.ensureNotDestroyed();
} catch (e) {
throw new shaka.util.Error(
shaka.util.Error.Severity.CRITICAL,
shaka.util.Error.Category.DRM,
shaka.util.Error.Code.ERROR_CHECKING_HDCP_VERSION,
e.message);
}
}
this.initialized_ = true;

await this.setServerCertificate();
Expand Down
5 changes: 5 additions & 0 deletions lib/polyfill/patchedmediakeys_apple.js
Expand Up @@ -457,6 +457,11 @@ shaka.polyfill.PatchedMediaKeysApple.MediaKeys = class {
return Promise.reject(exception);
}
}

/** @override */
getStatusForPolicy(policy) {
return Promise.resolve('usable');
}
};


Expand Down
5 changes: 5 additions & 0 deletions lib/polyfill/patchedmediakeys_nop.js
Expand Up @@ -108,6 +108,11 @@ shaka.polyfill.PatchedMediaKeysNop.MediaKeys = class {

/** @override */
setServerCertificate() {}

/** @override */
getStatusForPolicy(policy) {
return Promise.resolve('usable');
}
};


Expand Down
5 changes: 5 additions & 0 deletions lib/polyfill/patchedmediakeys_webkit.js
Expand Up @@ -417,6 +417,11 @@ shaka.polyfill.PatchedMediaKeysWebkit.MediaKeys = class {
return Promise.resolve(false);
}

/** @override */
getStatusForPolicy(policy) {
return Promise.resolve('usable');
}

/**
* @param {!MediaKeyEvent} event
* @suppress {constantProperty} We reassign what would be const on a real
Expand Down
11 changes: 11 additions & 0 deletions lib/util/error.js
Expand Up @@ -858,6 +858,17 @@ shaka.util.Error.Code = {
*/
'SERVER_CERTIFICATE_REQUEST_FAILED': 6017,

/**
* The HDCP version does not meet the requirements.
*/
'MIN_HDCP_VERSION_NOT_MATCH': 6018,

/**
* Error when checking HDCP version.
* <br> error.data[0] is an error message string from the browser.
*/
'ERROR_CHECKING_HDCP_VERSION': 6019,


/**
* The call to Player.load() was interrupted by a call to Player.unload()
Expand Down
1 change: 1 addition & 0 deletions lib/util/player_configuration.js
Expand Up @@ -87,6 +87,7 @@ shaka.util.PlayerConfiguration = class {
// change in the PSSH in media segments. We need to parse PSSH from media
// segments to detect key changes.
parseInbandPsshEnabled: shaka.util.Platform.isXboxOne(),
minHdcpVersion: '',
};

const manifest = {
Expand Down

0 comments on commit 61613cf

Please sign in to comment.