Skip to content

Commit

Permalink
fix: Fix encryptionScheme for FairPlay (#6483)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad authored Apr 26, 2024
1 parent 5a0e60a commit bf9787a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
17 changes: 16 additions & 1 deletion lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4167,13 +4167,28 @@ shaka.hls.HlsParser = class {
.HLS_MSE_ENCRYPTED_LEGACY_APPLE_MEDIA_KEYS_NOT_SUPPORTED);
}

const method = drmTag.getRequiredAttrValue('METHOD');
const VALID_METHODS = ['SAMPLE-AES', 'SAMPLE-AES-CTR'];
if (!VALID_METHODS.includes(method)) {
shaka.log.error('FairPlay in HLS is only supported with [',
VALID_METHODS.join(', '), '], not', method);
return null;
}

let encryptionScheme = 'cenc';
if (method == 'SAMPLE-AES') {
// It should be 'cbcs-1-9' but Safari doesn't support it.
// See: https://github.com/WebKit/WebKit/blob/main/Source/WebCore/Modules/encryptedmedia/MediaKeyEncryptionScheme.idl
encryptionScheme = 'cbcs';
}

/*
* Even if we're not able to construct initData through the HLS tag, adding
* a DRMInfo will allow DRM Engine to request a media key system access
* with the correct keySystem and initDataType
*/
const drmInfo = shaka.util.ManifestParserUtils.createDrmInfo(
'com.apple.fps', /* encryptionScheme= */ 'cbcs-1-9', [
'com.apple.fps', encryptionScheme, [
{initDataType: 'sinf', initData: new Uint8Array(0), keyId: null},
]);

Expand Down
6 changes: 3 additions & 3 deletions test/hls/hls_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3630,7 +3630,7 @@ describe('HlsParser', () => {
stream.encrypted = true;
stream.addDrmInfo('com.apple.fps', (drmInfo) => {
drmInfo.addInitData('sinf', new Uint8Array(0));
drmInfo.encryptionScheme = 'cbcs-1-9';
drmInfo.encryptionScheme = 'cenc';
});
});
});
Expand Down Expand Up @@ -3900,15 +3900,15 @@ describe('HlsParser', () => {
variant.addPartialStream(ContentType.VIDEO, (stream) => {
stream.addDrmInfo('com.apple.fps', (drmInfo) => {
drmInfo.addInitData('sinf', new Uint8Array(0));
drmInfo.encryptionScheme = 'cbcs-1-9';
drmInfo.encryptionScheme = 'cenc';
});
});
});
manifest.addPartialVariant((variant) => {
variant.addPartialStream(ContentType.VIDEO, (stream) => {
stream.addDrmInfo('com.apple.fps', (drmInfo) => {
drmInfo.addInitData('sinf', new Uint8Array(0));
drmInfo.encryptionScheme = 'cbcs-1-9';
drmInfo.encryptionScheme = 'cenc';
});
});
});
Expand Down

0 comments on commit bf9787a

Please sign in to comment.