Skip to content

Commit

Permalink
fix(HLS): Add subtitle role when there are no roles (#5357)
Browse files Browse the repository at this point in the history
Fixes #5355

Co-authored-by: Joey Parrish <[email protected]>
  • Loading branch information
officialbidisha and joeyparrish authored Jul 19, 2023
1 parent a909ed4 commit 7de6340
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2436,6 +2436,22 @@ shaka.hls.HlsParser = class {
// stream is lazy-loaded.
const mimeType = this.guessMimeTypeBeforeLoading_(type, codecs) ||
this.guessMimeTypeFallback_(type);
const roles = [];
if (characteristics) {
for (const characteristic of characteristics.split(',')) {
roles.push(characteristic);
}
}

const kind = (type == shaka.util.ManifestParserUtils.ContentType.TEXT) ?
shaka.util.ManifestParserUtils.TextStreamKind.SUBTITLE : undefined;

// If there are no roles, and we have defaulted to the subtitle "kind" for
// this track, add the implied subtitle role.
if (!roles.length &&
kind === shaka.util.ManifestParserUtils.TextStreamKind.SUBTITLE) {
roles.push(shaka.util.ManifestParserUtils.TextStreamKind.SUBTITLE);
}

return {
id: this.globalId_++,
Expand All @@ -2462,7 +2478,7 @@ shaka.hls.HlsParser = class {
width: undefined,
height: undefined,
bandwidth: undefined,
roles: characteristics ? characteristics.split(',') : [],
roles,
forced,
channelsCount,
audioSamplingRate: sampleRate,
Expand Down
69 changes: 69 additions & 0 deletions test/hls/hls_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,75 @@ describe('HlsParser', () => {
await testHlsParser(master, media, manifest);
});

it('adds subtitle role when characteristics are empty', async () => {
const master = [
'#EXTM3U\n',
'#EXT-X-STREAM-INF:BANDWIDTH=200,CODECS="avc1",',
'RESOLUTION=960x540,FRAME-RATE=60,AUDIO="aud1",SUBTITLES="sub1"\n',
'video\n',

'#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aud1",LANGUAGE="en",',
'NAME="English",URI="audio"\n',

'#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aud1",LANGUAGE="en",',
'CHARACTERISTICS="public.accessibility.describes-video,',
'public.accessibility.describes-music-and-sound",',
'NAME="English (describes-video)",URI="audio2"\n',

'#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="sub1",LANGUAGE="en",',
'NAME="English (subtitle)",DEFAULT=YES,AUTOSELECT=YES,',
'URI="text"\n',

'#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="sub1",LANGUAGE="en",',
'NAME="English (caption)",DEFAULT=YES,AUTOSELECT=YES,',
'CHARACTERISTICS="public.accessibility.describes-music-and-sound",',
'URI="text2"\n',
].join('');
const manifest = shaka.test.ManifestGenerator.generate((manifest) => {
manifest.anyTimeline();
manifest.addPartialVariant((variant) => {
variant.language = 'en';
variant.addPartialStream(ContentType.VIDEO);
variant.addPartialStream(ContentType.AUDIO, (stream) => {
stream.language = 'en';
stream.roles = [];
});
});
manifest.addPartialVariant((variant) => {
variant.language = 'en';
variant.addPartialStream(ContentType.VIDEO);
variant.addPartialStream(ContentType.AUDIO, (stream) => {
stream.language = 'en';
stream.roles = [
'public.accessibility.describes-video',
'public.accessibility.describes-music-and-sound',
];
});
});
manifest.addPartialTextStream((stream) => {
stream.language = 'en';
stream.kind = TextStreamKind.SUBTITLE;
stream.roles = [
'subtitle',
];
});
manifest.addPartialTextStream((stream) => {
stream.language = 'en';
stream.kind = TextStreamKind.SUBTITLE;
stream.roles = [
'public.accessibility.describes-music-and-sound',
];
});
manifest.sequenceMode = sequenceMode;
manifest.type = shaka.media.ManifestParser.HLS;
});

fakeNetEngine.setResponseText('test:/master', master);

const actual = await parser.start('test:/master', playerInterface);
expect(actual).toEqual(manifest);
});

it('parses characteristics from text tags', async () => {
const master = [
'#EXTM3U\n',
Expand Down

0 comments on commit 7de6340

Please sign in to comment.