Skip to content

Commit

Permalink
fix(HLS): Fix missing roles (#4760)
Browse files Browse the repository at this point in the history
Issue wasn't caught by the existing tests.

Closes #4759

Co-authored-by: Joey Parrish <joeyparrish@google.com>
  • Loading branch information
fredrik-telia and joeyparrish committed Dec 8, 2022
1 parent eea7858 commit d27f023
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 16 deletions.
19 changes: 3 additions & 16 deletions lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1677,8 +1677,6 @@ shaka.hls.HlsParser = class {
stream.encrypted = realStream.encrypted;
stream.drmInfos = realStream.drmInfos;
stream.keyIds = realStream.keyIds;
stream.kind = realStream.kind;
stream.roles = realStream.roles;
stream.mimeType = realStream.mimeType;
if (shaka.media.MediaSourceEngine.RAW_FORMATS.includes(stream.mimeType)) {
stream.codecs = '';
Expand Down Expand Up @@ -1944,16 +1942,6 @@ shaka.hls.HlsParser = class {
/** @type {!shaka.media.SegmentIndex} */
const segmentIndex = new shaka.media.SegmentIndex(segments);

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

const roles = [];
if (characteristics) {
for (const characteristic of characteristics.split(',')) {
roles.push(characteristic);
}
}

const serverControlTag = shaka.hls.Utils.getFirstTagWithName(
playlist.tags, 'EXT-X-SERVER-CONTROL');
const canSkipSegments = serverControlTag ?
Expand All @@ -1965,8 +1953,6 @@ shaka.hls.HlsParser = class {
stream.encrypted = encrypted;
stream.drmInfos = drmInfos;
stream.keyIds = keyIds;
stream.kind = kind;
stream.roles = roles;
stream.mimeType = mimeType;

return {
Expand Down Expand Up @@ -2016,7 +2002,8 @@ shaka.hls.HlsParser = class {
segmentIndex: null,
mimeType,
codecs,
kind: undefined,
kind: (type == shaka.util.ManifestParserUtils.ContentType.TEXT) ?
shaka.util.ManifestParserUtils.TextStreamKind.SUBTITLE : undefined,
encrypted: false,
drmInfos: [],
keyIds: new Set(),
Expand All @@ -2032,7 +2019,7 @@ shaka.hls.HlsParser = class {
width: undefined,
height: undefined,
bandwidth: undefined,
roles: [],
roles: characteristics ? characteristics.split(',') : [],
forced,
channelsCount,
audioSamplingRate: null,
Expand Down
71 changes: 71 additions & 0 deletions test/hls/hls_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,77 @@ describe('HlsParser', () => {
await testHlsParser(master, media, manifest);
});

// https://github.com/shaka-project/shaka-player/issues/4759
it('makes roles available without loading tracks', 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 (caption)",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-spoken-dialog,',
'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';
});
});
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;
});
manifest.addPartialTextStream((stream) => {
stream.language = 'en';
stream.kind = TextStreamKind.SUBTITLE;
stream.roles = [
'public.accessibility.describes-spoken-dialog',
'public.accessibility.describes-music-and-sound',
];
});
manifest.sequenceMode = true;
});

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

// NOTE: Not using testHlsParser here because that unconditionally loads all
// streams. We need to test the behavior specifically when streams are
// _not_ loaded.
const actual = await parser.start('test:/master', playerInterface);
expect(actual).toEqual(manifest);
});

it('gets mime type from header request', async () => {
const master = [
'#EXTM3U\n',
Expand Down

0 comments on commit d27f023

Please sign in to comment.