Skip to content
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
37 changes: 26 additions & 11 deletions lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1478,20 +1478,31 @@ shaka.hls.HlsParser = class {
// Create text stream for each Subtitle media tag.
const subtitleTags =
shaka.hls.Utils.filterTagsByType(mediaTags, 'SUBTITLES');
const textStreams = subtitleTags.map((tag) => {
const disableText = this.config_.disableText;
if (disableText) {
return null;

const groupedTags = {};
for (const tag of subtitleTags) {
const key = tag.getTagKey(!this.contentSteeringManager_);
if (!groupedTags[key]) {
groupedTags[key] = [tag];
} else {
groupedTags[key].push(tag);
Comment on lines +1482 to +1488
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use shaka.util.MultiMap for grouping.

}
try {
return this.createStreamInfoFromMediaTags_([tag], new Map()).stream;
} catch (e) {
if (this.config_.hls.ignoreTextStreamFailures) {
return null;
}

const textStreams = [];
if (!this.config_.disableText) {
for (const key in groupedTags) {
try {
textStreams.push(this.createStreamInfoFromMediaTags_(
groupedTags[key], new Map()).stream);
} catch (e) {
if (this.config_.hls.ignoreTextStreamFailures) {
continue;
}
throw e;
}
throw e;
}
});
}

const type = shaka.util.ManifestParserUtils.ContentType.TEXT;

Expand Down Expand Up @@ -2384,6 +2395,10 @@ shaka.hls.HlsParser = class {
verbatimMediaPlaylistUris.push(uri);
globalGroupIds.push(groupId);
groupIdUriMapping.set(groupId, uri);
const pathwayId = tag.getAttributeValue('PATHWAY-ID');
if (pathwayId) {
groupIdPathwayIdMapping.set(groupId, pathwayId);
}
}

const globalGroupId = globalGroupIds.sort().join(',');
Expand Down
21 changes: 19 additions & 2 deletions test/hls/hls_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6210,15 +6210,19 @@ describe('HlsParser', () => {
'#EXTM3U\n',
'#EXT-X-CONTENT-STEERING:SERVER-URI="http://contentsteering",',
'PATHWAY-ID="a"\n',
'#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subsA",LANGUAGE="eng",',
'NAME="English",PATHWAY-ID="a",URI="subs/a/media.m3u8"\n',
'#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subsB",LANGUAGE="eng",',
'NAME="English",PATHWAY-ID="b",URI="subs/b/media.m3u8"\n',
'#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="a",LANGUAGE="eng",',
'URI="audio/a/media.m3u8"\n',
'#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="b",LANGUAGE="eng",',
'URI="audio/b/media.m3u8"\n',
'#EXT-X-STREAM-INF:BANDWIDTH=200,CODECS="avc,mp4a",',
'AUDIO="a",PATHWAY-ID="a",CLOSED-CAPTIONS=NONE\n',
'AUDIO="a",PATHWAY-ID="a",CLOSED-CAPTIONS=NONE,SUBTITLES="subsA"\n',
'a/media.m3u8\n',
'#EXT-X-STREAM-INF:BANDWIDTH=200,CODECS="avc,mp4a",',
'AUDIO="b",PATHWAY-ID="b",CLOSED-CAPTIONS=NONE\n',
'AUDIO="b",PATHWAY-ID="b",CLOSED-CAPTIONS=NONE,SUBTITLES="subsB"\n',
'b/media.m3u8',
].join('');

Expand Down Expand Up @@ -6248,6 +6252,8 @@ describe('HlsParser', () => {
.setResponseText('http://master/b/media.m3u8', media)
.setResponseText('http://master/audio/a/media.m3u8', media)
.setResponseText('http://master/audio/b/media.m3u8', media)
.setResponseText('http://master/subs/a/media.m3u8', media)
.setResponseText('http://master/subs/b/media.m3u8', media)
.setMaxUris(2);

/** @type {shaka.extern.Manifest} */
Expand All @@ -6273,6 +6279,17 @@ describe('HlsParser', () => {

expect(videoUri0).toBe('http://master/b/main.mp4');
expect(videoUri1).toBe('http://master/a/main.mp4');

expect(manifest.textStreams.length).toBe(1);
const text = manifest.textStreams[0];
await text.createSegmentIndex();
goog.asserts.assert(text.segmentIndex, 'Null segmentIndex!');
const textSegment0 = Array.from(text.segmentIndex)[0];
const textUri0 = textSegment0.getUris()[0];
const textUri1 = textSegment0.getUris()[1];

expect(textUri0).toBe('http://master/subs/b/main.mp4');
expect(textUri1).toBe('http://master/subs/a/main.mp4');
});

describe('EXT-X-DATERANGE', () => {
Expand Down