Skip to content

Commit

Permalink
fix(HLS): Fix support for mixed AES-128/NONE decryption (shaka-projec…
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed Jan 9, 2023
1 parent 1762267 commit 452694d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2639,9 +2639,12 @@ shaka.hls.HlsParser = class {

// Apply new AES-128 tags as you see them, keeping a running total.
for (const drmTag of item.tags) {
if (drmTag.name == 'EXT-X-KEY' &&
drmTag.getRequiredAttrValue('METHOD') == 'AES-128') {
hlsAes128Key = this.parseAES128DrmTag_(drmTag, playlist);
if (drmTag.name == 'EXT-X-KEY') {
if (drmTag.getRequiredAttrValue('METHOD') == 'AES-128') {
hlsAes128Key = this.parseAES128DrmTag_(drmTag, playlist);
} else {
hlsAes128Key = undefined;
}
}
}

Expand Down
30 changes: 30 additions & 0 deletions test/hls/hls_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2669,6 +2669,9 @@ describe('HlsParser', () => {
'#EXT-X-MAP:URI="init.mp4",BYTERANGE="616@0"\n',
'#EXTINF:5,\n',
'#EXT-X-BYTERANGE:121090@616\n',
'main.mp4\n',
'#EXTINF:5,\n',
'#EXT-X-BYTERANGE:121090@616\n',
'main.mp4',
].join('');

Expand All @@ -2680,6 +2683,10 @@ describe('HlsParser', () => {
'#EXT-X-MAP:URI="init.mp4",BYTERANGE="616@0"\n',
'#EXTINF:5,\n',
'#EXT-X-BYTERANGE:121090@616\n',
'main.mp4\n',
'#EXTINF:5,\n',
'#EXT-X-BYTERANGE:121090@616\n',
'#EXT-X-KEY:METHOD=NONE\n',
'main.mp4',
].join('');

Expand All @@ -2689,6 +2696,9 @@ describe('HlsParser', () => {
'#EXT-X-KEY:METHOD=AES-128,',
'URI="800k.key"\n',
'#EXTINF:5,\n',
'main.ts\n',
'#EXTINF:5,\n',
'#EXT-X-KEY:METHOD=NONE\n',
'main.ts',
].join('');

Expand Down Expand Up @@ -2742,6 +2752,26 @@ describe('HlsParser', () => {
const actual = await parser.start('test:/master', playerInterface);
await loadAllStreamsFor(actual);
expect(actual).toEqual(manifest);

const mp4AesEncryptionVideo = actual.variants[1].video;
await mp4AesEncryptionVideo.createSegmentIndex();
goog.asserts.assert(mp4AesEncryptionVideo.segmentIndex != null,
'Null segmentIndex!');

const firstMp4Segment = mp4AesEncryptionVideo.segmentIndex.get(0);
expect(firstMp4Segment.hlsAes128Key).toBeDefined();
const secondMp4Segment = mp4AesEncryptionVideo.segmentIndex.get(1);
expect(secondMp4Segment.hlsAes128Key).toBeNull();

const tsAesEncryptionVideo = actual.variants[2].video;
await tsAesEncryptionVideo.createSegmentIndex();
goog.asserts.assert(tsAesEncryptionVideo.segmentIndex != null,
'Null segmentIndex!');

const firstTsSegment = tsAesEncryptionVideo.segmentIndex.get(0);
expect(firstTsSegment.hlsAes128Key).toBeDefined();
const secondTsSegment = tsAesEncryptionVideo.segmentIndex.get(1);
expect(secondTsSegment.hlsAes128Key).toBeNull();
});

it('fails on AES-128 if WebCrypto APIs are not available', async () => {
Expand Down

0 comments on commit 452694d

Please sign in to comment.