Skip to content

Commit

Permalink
fix(HLS): Recognize CEA subtitles when CLOSED-CAPTIONS attribute is m…
Browse files Browse the repository at this point in the history
…issing (#5916)

Fixes #5915
  • Loading branch information
avelad committed Nov 22, 2023
1 parent c898364 commit 58d4597
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/hls/hls_parser.js
Expand Up @@ -1672,9 +1672,15 @@ shaka.hls.HlsParser = class {
// the value NONE. If the value is a quoted-string, it MUST match the
// value of the GROUP-ID attribute of an EXT-X-MEDIA tag elsewhere in the
// Playlist whose TYPE attribute is CLOSED-CAPTIONS.
if (type == ContentType.VIDEO && closedCaptionsAttr &&
closedCaptionsAttr != 'NONE') {
return this.groupIdToClosedCaptionsMap_.get(closedCaptionsAttr);
if (type == ContentType.VIDEO) {
if (closedCaptionsAttr && closedCaptionsAttr != 'NONE') {
return this.groupIdToClosedCaptionsMap_.get(closedCaptionsAttr);
} else if (!closedCaptionsAttr &&
this.groupIdToClosedCaptionsMap_.size) {
for (const key of this.groupIdToClosedCaptionsMap_.keys()) {
return this.groupIdToClosedCaptionsMap_.get(key);
}
}
}
return null;
}
Expand Down
40 changes: 40 additions & 0 deletions test/hls/hls_parser_unit.js
Expand Up @@ -750,6 +750,46 @@ describe('HlsParser', () => {
await testHlsParser(master, media, manifest);
});

it('parses audio+video variant with global closed captions', async () => {
const master = [
'#EXTM3U\n',
'#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aud1",LANGUAGE="eng",CHANNELS="2",',
'URI="audio"\n',
'#EXT-X-MEDIA:TYPE=CLOSED-CAPTIONS,GROUP-ID="cap1",LANGUAGE="eng",',
'INSTREAM-ID="CC1"\n',
'#EXT-X-STREAM-INF:BANDWIDTH=200,CODECS="avc1,mp4a",',
'RESOLUTION=960x540,FRAME-RATE=60,AUDIO="aud1"\n',
'video\n',
].join('');

const media = [
'#EXTM3U\n',
'#EXT-X-PLAYLIST-TYPE:VOD\n',
'#EXT-X-MAP:URI="init.mp4",BYTERANGE="616@0"\n',
'#EXTINF:5,\n',
'#EXT-X-BYTERANGE:121090@616\n',
'main.mp4',
].join('');

const closedCaptions = new Map([['CC1', 'en']]);
const manifest = shaka.test.ManifestGenerator.generate((manifest) => {
manifest.anyTimeline();
manifest.addPartialVariant((variant) => {
variant.addPartialStream(ContentType.VIDEO, (stream) => {
stream.closedCaptions = closedCaptions;
stream.mime('video/mp4', 'avc1');
});
variant.addPartialStream(ContentType.AUDIO, (stream) => {
stream.mime('audio/mp4', 'mp4a');
});
});
manifest.sequenceMode = sequenceMode;
manifest.type = shaka.media.ManifestParser.HLS;
});

await testHlsParser(master, media, manifest);
});

it('parses audio+video variant with no closed captions', async () => {
const master = [
'#EXTM3U\n',
Expand Down

0 comments on commit 58d4597

Please sign in to comment.