Skip to content

Commit

Permalink
fix(Widevine): Add default audio/video robustness for Widevine (#7808)
Browse files Browse the repository at this point in the history
The following bug is avoided in Chromium: `It is recommended that a
robustness level be specified. Not specifying the robustness level could
result in unexpected behavior.Understand this warningAI`

It also prevents errors when initializing EME on Android.

Fixes #7760
  • Loading branch information
avelad authored Dec 27, 2024
1 parent fab3faf commit a018f53
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 2 deletions.
16 changes: 15 additions & 1 deletion demo/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ shakaDemo.Config = class {

/** @private */
addDrmSection_() {
const widevineRobustnessLevels = {
'': '',
'SW_SECURE_CRYPTO': 'SW_SECURE_CRYPTO',
'SW_SECURE_DECODE': 'SW_SECURE_DECODE',
'HW_SECURE_CRYPTO': 'HW_SECURE_CRYPTO',
'HW_SECURE_DECODE': 'HW_SECURE_DECODE',
'HW_SECURE_ALL': 'HW_SECURE_ALL',
};
const docLink = this.resolveExternLink_('.DrmConfiguration');
this.addSection_('DRM', docLink)
.addBoolInput_('Delay License Request Until Played',
Expand All @@ -137,7 +145,13 @@ shakaDemo.Config = class {
'drm.parseInbandPsshEnabled')
.addTextInput_('Min HDCP version', 'drm.minHdcpVersion')
.addBoolInput_('Ignore duplicate init data',
'drm.ignoreDuplicateInitData');
'drm.ignoreDuplicateInitData')
.addSelectInput_('Default audio robustness for Widevine',
'drm.defaultAudioRobustnessForWidevine',
widevineRobustnessLevels, widevineRobustnessLevels)
.addSelectInput_('Default video robustness for Widevine',
'drm.defaultVideoRobustnessForWidevine',
widevineRobustnessLevels, widevineRobustnessLevels);
const advanced = shakaDemoMain.getConfiguration().drm.advanced || {};
const addDRMAdvancedField = (name, valueName, suggestions,
arrayString = false) => {
Expand Down
14 changes: 13 additions & 1 deletion externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,9 @@ shaka.extern.PersistentSessionMetadata;
* keySystemsMapping: !Object.<string, string>,
* parseInbandPsshEnabled: boolean,
* minHdcpVersion: string,
* ignoreDuplicateInitData: boolean
* ignoreDuplicateInitData: boolean,
* defaultAudioRobustnessForWidevine: string,
* defaultVideoRobustnessForWidevine: string
* }}
*
* @property {shaka.extern.RetryParameters} retryParameters
Expand Down Expand Up @@ -1025,6 +1027,16 @@ shaka.extern.PersistentSessionMetadata;
* <br>
* Defaults to <code>false</code> on Tizen 2, and <code>true</code> for all
* other browsers.
* @property {string} defaultAudioRobustnessForWidevine
* Specify the default audio security level for Widevine when audio robustness
* is not specified.
* <br>
* Defaults to <code>'SW_SECURE_CRYPTO'</code>.
* @property {string} defaultVideoRobustnessForWidevine
* Specify the default video security level for Widevine when video robustness
* is not specified.
* <br>
* Defaults to <code>'SW_SECURE_DECODE'</code>.
* @exportDoc
*/
shaka.extern.DrmConfiguration;
Expand Down
12 changes: 12 additions & 0 deletions lib/drm/drm_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@ shaka.drm.DrmEngine = class {
*
* robustness can be either a single item as a string or multiple items as
* an array of strings.
*
* @param {!Array.<shaka.extern.DrmInfo>} drmInfos
* @param {string} robustnessType
* @return {!Array.<shaka.extern.DrmInfo>}
*/
const expandRobustness = (drmInfos, robustnessType) => {
const newDrmInfos = [];
Expand All @@ -427,6 +431,14 @@ shaka.drm.DrmEngine = class {
(this.config_.advanced &&
this.config_.advanced[drmInfo.keySystem] &&
this.config_.advanced[drmInfo.keySystem][robustnessType]) || '';
if (items == '' &&
shaka.drm.DrmUtils.isWidevineKeySystem(drmInfo.keySystem)) {
if (robustnessType == 'audioRobustness') {
items = [this.config_.defaultAudioRobustnessForWidevine];
} else if (robustnessType == 'videoRobustness') {
items = [this.config_.defaultVideoRobustnessForWidevine];
}
}
if (typeof items === 'string') {
// if drmInfo's robustness has already been expanded,
// use the drmInfo directly.
Expand Down
12 changes: 12 additions & 0 deletions lib/drm/drm_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ shaka.drm.DrmUtils = class {
return drmInfo ? drmInfo.keySystem : '';
}

/**
* @param {?string} keySystem
* @return {boolean}
*/
static isWidevineKeySystem(keySystem) {
if (keySystem) {
return !!keySystem.match(/^com\.widevine\.alpha/);
}

return false;
}

/**
* @param {?string} keySystem
* @return {boolean}
Expand Down
2 changes: 2 additions & 0 deletions lib/util/player_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ shaka.util.PlayerConfiguration = class {
parseInbandPsshEnabled: shaka.util.Platform.isXboxOne(),
minHdcpVersion: '',
ignoreDuplicateInitData: !shaka.util.Platform.isTizen2(),
defaultAudioRobustnessForWidevine: 'SW_SECURE_CRYPTO',
defaultVideoRobustnessForWidevine: 'SW_SECURE_DECODE',
};

// The Xbox One and PS4 only support the Playready DRM, so they should
Expand Down
16 changes: 16 additions & 0 deletions test/drm/drm_utils_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,22 @@ describe('DrmUtils', () => {
});
}); // describe('getCommonDrmInfos')

describe('isWidevineKeySystem', () => {
it('should return true for Widevine', () => {
expect(shaka.drm.DrmUtils.isWidevineKeySystem(
'com.widevine.alpha')).toBe(true);
expect(shaka.drm.DrmUtils.isWidevineKeySystem(
'com.widevine.alpha.anything')).toBe(true);
});

it('should return false for non-Widevine key systems', () => {
expect(shaka.drm.DrmUtils.isWidevineKeySystem(
'com.microsoft.playready')).toBe(false);
expect(shaka.drm.DrmUtils.isWidevineKeySystem(
'com.apple.fps')).toBe(false);
});
});

describe('isPlayReadyKeySystem', () => {
it('should return true for MS & Chromecast PlayReady', () => {
expect(shaka.drm.DrmUtils.isPlayReadyKeySystem(
Expand Down

0 comments on commit a018f53

Please sign in to comment.