Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(hls): make a head request if hls subtitles have no extension #4140

Merged
merged 2 commits into from Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/hls/hls_parser.js
Expand Up @@ -2252,11 +2252,10 @@ shaka.hls.HlsParser = class {

if (contentType == ContentType.TEXT) {
// The extension map didn't work.
if (!codecs || codecs == 'vtt' || codecs == 'wvtt') {
if (codecs == 'vtt' || codecs == 'wvtt') {
// If codecs is 'vtt', it's WebVTT.
// If there was no codecs string, assume HLS text streams are WebVTT.
return 'text/vtt';
} else {
} else if (codecs && codecs !== '') {
// Otherwise, assume MP4-embedded text, since text-based formats tend
// not to have a codecs string at all.
return 'application/mp4';
Expand All @@ -2281,6 +2280,11 @@ shaka.hls.HlsParser = class {
const contentMimeType = response.headers['content-type'];

if (!contentMimeType) {
if (contentType == ContentType.TEXT) {
// If there was no codecs string and no content-type, assume HLS text
// streams are WebVTT.
return 'text/vtt';
}
// If the HLS content is lacking in both MIME type metadata and
// segment file extensions, we fall back to assuming it's MP4.
const fallbackMimeType = map['mp4'];
Expand Down
63 changes: 63 additions & 0 deletions test/hls/hls_parser_unit.js
Expand Up @@ -1138,6 +1138,69 @@ describe('HlsParser', () => {
expect(actual).toEqual(manifest);
});

it('gets mime type of SUBTITLES from header request', async () => {
const master = [
'#EXTM3U\n',
'#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aud1",LANGUAGE="eng",',
'URI="audio"\n',
'#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="sub1",LANGUAGE="eng",',
'URI="text"\n',
'#EXT-X-STREAM-INF:BANDWIDTH=200,CODECS="avc1,mp4a",',
'RESOLUTION=960x540,FRAME-RATE=60,AUDIO="aud1",SUBTITLES="sub1"\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 textMedia = [
'#EXTM3U\n',
'#EXT-X-PLAYLIST-TYPE:VOD\n',
'#EXTINF:5,\n',
'#EXT-X-BYTERANGE:121090@616\n',
'main.subs',
].join('');

const manifest = shaka.test.ManifestGenerator.generate((manifest) => {
manifest.anyTimeline();
manifest.addPartialVariant((variant) => {
variant.addPartialStream(ContentType.VIDEO, (stream) => {
stream.mime('video/mp4', 'avc1');
});
variant.addPartialStream(ContentType.AUDIO, (stream) => {
stream.mime('audio/mp4', 'mp4a');
});
});
manifest.addPartialTextStream((stream) => {
stream.language = 'en';
stream.kind = TextStreamKind.SUBTITLE;
stream.mime('application/mp4', '');
});
manifest.sequenceMode = true;
});

fakeNetEngine
.setResponseText('test:/master', master)
.setResponseText('test:/audio', media)
.setResponseText('test:/video', media)
.setResponseText('test:/text', textMedia)
.setResponseText('test:/main.subs', vttText)
.setHeaders('test:/main.subs', {
'content-type': 'application/mp4; foo=bar',
Copy link
Member

Choose a reason for hiding this comment

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

Would it be more realistic to give this a codec string? Perhaps something like TTML, which wouldn't otherwise be guessed by default?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The function that has been modified only allows obtaining the mimetype, so entering codec information would not help.

})
.setResponseValue('test:/init.mp4', initSegmentData)
.setResponseValue('test:/main.mp4', segmentData);

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

it('parses manifest with FORCED SUBTITLES', async () => {
const master = [
'#EXTM3U\n',
Expand Down