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

fix(HLS): Detect spatial audio when using Dolby AC-4 #8223

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1925,10 +1925,11 @@ shaka.hls.HlsParser = class {
/**
* Get the spatial audio information for an HLS audio track.
* In HLS the channels field indicates the number of audio channels that the
* stream has (eg: 2). In the case of Dolby Atmos, the complexity is
* stream has (eg: 2). In the case of Dolby Atmos (EAC-3), the complexity is
* expressed with the number of channels followed by the word JOC
* (eg: 16/JOC), so 16 would be the number of channels (eg: 7.3.6 layout),
* and JOC indicates that the stream has spatial audio.
* and JOC indicates that the stream has spatial audio. For Dolby AC-4 ATMOS,
* it's necessary search ATMOS word.
* @see https://developer.apple.com/documentation/http_live_streaming/hls_authoring_specification_for_apple_devices/hls_authoring_specification_for_apple_devices_appendixes
*
* @param {!shaka.hls.Tag} tag
Expand All @@ -1940,7 +1941,11 @@ shaka.hls.HlsParser = class {
if (!channels) {
return false;
}
return channels.includes('/JOC');
const channelsParts = channels.split('/');
if (channelsParts.length != 2) {
return false;
}
return channelsParts[1] === 'JOC' || channelsParts[1].includes('ATMOS');
}

/**
Expand Down
54 changes: 54 additions & 0 deletions test/hls/hls_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,60 @@ describe('HlsParser', () => {
expect(actual).toEqual(manifest);
});

it('Detect spatial audio in Dolby AC-4', async () => {
const master = [
'#EXTM3U\n',
'#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aud1",LANGUAGE="eng",',
'CHANNELS="10/ATMOS",SAMPLE-RATE="48000",URI="audio"\n',
'#EXT-X-STREAM-INF:BANDWIDTH=200,CODECS="avc1,ac-4",',
'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 manifest = shaka.test.ManifestGenerator.generate((manifest) => {
manifest.sequenceMode = sequenceMode;
manifest.type = shaka.media.ManifestParser.HLS;
manifest.anyTimeline();
manifest.addPartialVariant((variant) => {
variant.language = 'en';
variant.bandwidth = 200;
variant.addPartialStream(ContentType.VIDEO, (stream) => {
stream.frameRate = 60;
stream.mime('video/mp4', 'avc1');
stream.size(960, 540);
});
variant.addPartialStream(ContentType.AUDIO, (stream) => {
stream.language = 'en';
stream.originalLanguage = 'eng';
stream.channelsCount = 10;
stream.audioSamplingRate = 48000;
stream.spatialAudio = true;
stream.mime('audio/mp4', 'ac-4');
});
});
});

fakeNetEngine
.setResponseText('test:/master', master)
.setResponseText('test:/audio', media)
.setResponseText('test:/video', media)
.setResponseValue('test:/init.mp4', initSegmentData)
.setResponseValue('test:/main.mp4', segmentData);

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

it('prioritize AVERAGE-BANDWIDTH to BANDWIDTH', async () => {
const master = [
'#EXTM3U\n',
Expand Down
Loading