Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(HLS): Fix init segment when EXT-X-MAP is preceded by EXT-X-BYTERANGE #5732

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2859,16 +2859,19 @@ shaka.hls.HlsParser = class {
if (!this.mapTagToInitSegmentRefMap_.has(mapTagKey)) {
/** @type {shaka.extern.aes128Key|undefined} */
let aes128Key = undefined;
let byteRangeTag = null;
for (const tag of tags) {
if (tag.name == 'EXT-X-KEY') {
if (tag.getRequiredAttrValue('METHOD') == 'AES-128' &&
tag.id < mapTag.id) {
aes128Key = this.parseAES128DrmTag_(tag, playlist);
}
} else if (tag.name == 'EXT-X-BYTERANGE' && tag.id < mapTag.id) {
byteRangeTag = tag;
}
}
const initSegmentRef = this.createInitSegmentReference_(
absoluteInitSegmentUri, mapTag, aes128Key);
absoluteInitSegmentUri, mapTag, byteRangeTag, aes128Key);
this.mapTagToInitSegmentRefMap_.set(mapTagKey, initSegmentRef);
}
return this.mapTagToInitSegmentRefMap_.get(mapTagKey);
Expand All @@ -2879,14 +2882,19 @@ shaka.hls.HlsParser = class {
* playlist.
* @param {string} absoluteInitSegmentUri
* @param {!shaka.hls.Tag} mapTag EXT-X-MAP
* @param {shaka.hls.Tag=} byteRangeTag EXT-X-BYTERANGE
* @param {shaka.extern.aes128Key=} aes128Key
* @return {!shaka.media.InitSegmentReference}
* @private
*/
createInitSegmentReference_(absoluteInitSegmentUri, mapTag, aes128Key) {
createInitSegmentReference_(absoluteInitSegmentUri, mapTag, byteRangeTag,
aes128Key) {
let startByte = 0;
let endByte = null;
const byterange = mapTag.getAttributeValue('BYTERANGE');
let byterange = mapTag.getAttributeValue('BYTERANGE');
if (!byterange && byteRangeTag) {
byterange = byteRangeTag.value;
}
// If a BYTERANGE attribute is not specified, the segment consists
// of the entire resource.
if (byterange) {
Expand Down
14 changes: 11 additions & 3 deletions test/hls/hls_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2976,7 +2976,8 @@ describe('HlsParser', () => {
const media = [
'#EXTM3U\n',
'#EXT-X-PLAYLIST-TYPE:VOD\n',
'#EXT-X-MAP:URI="init.mp4",BYTERANGE="616@0"\n',
'#EXT-X-BYTERANGE:616@0\n',
'#EXT-X-MAP:URI="init.mp4"\n',
'#EXTINF:5,\n',
'main.mp4\n',
'#EXT-X-MAP:URI="init2.mp4",BYTERANGE="616@0"\n',
Expand Down Expand Up @@ -3004,8 +3005,15 @@ describe('HlsParser', () => {
// uri.
const initSegments = Array.from(actualVideo.segmentIndex).map(
(seg) => seg.initSegmentReference);
expect(initSegments[0].getUris()[0]).toBe('test:/init.mp4');
expect(initSegments[1].getUris()[0]).toBe('test:/init2.mp4');
expect(initSegments.length).toBe(2);
const firstInitSegment = initSegments[0];
expect(firstInitSegment.getUris()[0]).toBe('test:/init.mp4');
expect(firstInitSegment.startByte).toBe(0);
expect(firstInitSegment.endByte).toBe(615);
const secondInitSegment = initSegments[1];
expect(secondInitSegment.getUris()[0]).toBe('test:/init2.mp4');
expect(secondInitSegment.startByte).toBe(0);
expect(secondInitSegment.endByte).toBe(615);
});

it('parses variants encrypted with AES-128', async () => {
Expand Down