From 73839c8002806983933de259cc051022c027aca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=B6glin?= Date: Wed, 23 Nov 2022 15:54:02 +0100 Subject: [PATCH 1/6] fix: respect characteristics when creating stream object --- lib/hls/hls_parser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/hls/hls_parser.js b/lib/hls/hls_parser.js index d7c393ccd7..c0b7e5d050 100644 --- a/lib/hls/hls_parser.js +++ b/lib/hls/hls_parser.js @@ -2032,7 +2032,7 @@ shaka.hls.HlsParser = class { width: undefined, height: undefined, bandwidth: undefined, - roles: [], + roles: characteristics ? [characteristics] : [], forced, channelsCount, audioSamplingRate: null, From cca43ca3ed481a5db585974ac1176fdc6dbc69fe Mon Sep 17 00:00:00 2001 From: Joey Parrish Date: Wed, 7 Dec 2022 13:56:52 -0800 Subject: [PATCH 2/6] Add regression test --- test/hls/hls_parser_unit.js | 80 +++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/test/hls/hls_parser_unit.js b/test/hls/hls_parser_unit.js index 751f9be0e0..828d90c4b4 100644 --- a/test/hls/hls_parser_unit.js +++ b/test/hls/hls_parser_unit.js @@ -1089,6 +1089,86 @@ 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 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 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', From 15dad6ccedd1d95fd7596b2766990102e09ba8b9 Mon Sep 17 00:00:00 2001 From: Joey Parrish Date: Wed, 7 Dec 2022 14:25:26 -0800 Subject: [PATCH 3/6] Fix build failure --- test/hls/hls_parser_unit.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/test/hls/hls_parser_unit.js b/test/hls/hls_parser_unit.js index 828d90c4b4..ff4a53aa4d 100644 --- a/test/hls/hls_parser_unit.js +++ b/test/hls/hls_parser_unit.js @@ -1116,15 +1116,6 @@ describe('HlsParser', () => { 'URI="text2"\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 manifest = shaka.test.ManifestGenerator.generate((manifest) => { manifest.anyTimeline(); manifest.addPartialVariant((variant) => { From ce09686c0dd1963e375f9fa3a1344e25f511f0b8 Mon Sep 17 00:00:00 2001 From: Joey Parrish Date: Wed, 7 Dec 2022 14:30:09 -0800 Subject: [PATCH 4/6] Fix characteristics (array, not string) and add missing kind field --- lib/hls/hls_parser.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/hls/hls_parser.js b/lib/hls/hls_parser.js index c0b7e5d050..65f2e1b50d 100644 --- a/lib/hls/hls_parser.js +++ b/lib/hls/hls_parser.js @@ -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 = ''; @@ -1949,9 +1947,7 @@ shaka.hls.HlsParser = class { const roles = []; if (characteristics) { - for (const characteristic of characteristics.split(',')) { - roles.push(characteristic); - } + roles = characteristics.split(','); } const serverControlTag = shaka.hls.Utils.getFirstTagWithName( @@ -2016,7 +2012,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(), @@ -2032,7 +2029,7 @@ shaka.hls.HlsParser = class { width: undefined, height: undefined, bandwidth: undefined, - roles: characteristics ? [characteristics] : [], + roles: characteristics ? characteristics.split(',') : [], forced, channelsCount, audioSamplingRate: null, From 4288d4986de4b0a281506869372a9d890360cfc5 Mon Sep 17 00:00:00 2001 From: Joey Parrish Date: Wed, 7 Dec 2022 14:32:56 -0800 Subject: [PATCH 5/6] Fix build error --- lib/hls/hls_parser.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/hls/hls_parser.js b/lib/hls/hls_parser.js index 65f2e1b50d..9c52a53259 100644 --- a/lib/hls/hls_parser.js +++ b/lib/hls/hls_parser.js @@ -1945,10 +1945,7 @@ shaka.hls.HlsParser = class { const kind = (type == shaka.util.ManifestParserUtils.ContentType.TEXT) ? shaka.util.ManifestParserUtils.TextStreamKind.SUBTITLE : undefined; - const roles = []; - if (characteristics) { - roles = characteristics.split(','); - } + const roles = characteristics ? characteristics.split(',') : []; const serverControlTag = shaka.hls.Utils.getFirstTagWithName( playlist.tags, 'EXT-X-SERVER-CONTROL'); From 23780ab8c1f2d9c6a4b4c765973d4e7be6e4db5a Mon Sep 17 00:00:00 2001 From: Joey Parrish Date: Wed, 7 Dec 2022 14:51:15 -0800 Subject: [PATCH 6/6] Remove redundant calculation of kind and roles --- lib/hls/hls_parser.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/hls/hls_parser.js b/lib/hls/hls_parser.js index 9c52a53259..278177b1e6 100644 --- a/lib/hls/hls_parser.js +++ b/lib/hls/hls_parser.js @@ -1942,11 +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 = characteristics ? characteristics.split(',') : []; - const serverControlTag = shaka.hls.Utils.getFirstTagWithName( playlist.tags, 'EXT-X-SERVER-CONTROL'); const canSkipSegments = serverControlTag ? @@ -1958,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 {