Skip to content

Commit

Permalink
fix: calculations of channel count for DASH AudioChannelConfiguration…
Browse files Browse the repository at this point in the history
… elements. (#7421)

Fix tag:dolby.com,2014:dash:audio_channel_configuration:2011 scheme to
correctly handle bits that represent channel pairs according to document
at
[dolby.com](https://ott.dolby.com/OnDelKits/DDP/Dolby_Digital_Plus_Online_Delivery_Kit_v1.5/Documentation/Content_Creation/SDM/help_files/topics/ddp_mpeg_dash_c_mpd_auchlconfig.html)

Add tag:dolby.com,2015:dash:audio_channel_configuration:2015 scheme
according to ETSI TS 103 190-2 v1.2.1, Annex G.3

Test stream is available here:
[manifest.mpd](https://content.media24.link/ac4_512/manifest.mpd)
  • Loading branch information
gmcgarry authored and joeyparrish committed Oct 21, 2024
1 parent 7b89040 commit 916a1f6
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 13 deletions.
44 changes: 35 additions & 9 deletions lib/dash/dash_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2750,25 +2750,51 @@ shaka.dash.DashParser = class {
return intValue;
}

case 'tag:dolby.com,2015:dash:audio_channel_configuration:2015': {
// ETSI TS 103 190-2 v1.2.1, Annex G.3
// LSB-to-MSB order
const channelCountMapping =
[2, 1, 2, 2, 2, 2, 1, 2, 2, 1, 1, 1, 1, 2, 1, 1, 2, 2];
const hexValue = parseInt(value, 16);
if (!hexValue) { // 0 or NaN
shaka.log.warning('Channel parsing failure! ' +
'Ignoring scheme and value', scheme, value);
continue;
}
let numBits = 0;
for (let i = 0; i < channelCountMapping.length; i++) {
if (hexValue & (1<<i)) {
numBits += channelCountMapping[i];
}
}
if (numBits) {
return numBits;
}
continue;
}

case 'tag:dolby.com,2014:dash:audio_channel_configuration:2011':
case 'urn:dolby:dash:audio_channel_configuration:2011': {
// A hex-encoded 16-bit integer, in which each bit represents a
// channel.
let hexValue = parseInt(value, 16);
// Defined by https://ott.dolby.com/OnDelKits/DDP/Dolby_Digital_Plus_Online_Delivery_Kit_v1.5/Documentation/Content_Creation/SDM/help_files/topics/ddp_mpeg_dash_c_mpd_auchlconfig.html
// keep list in order of the spec; reverse for LSB-to-MSB order
const channelCountMapping =
[1, 1, 1, 1, 1, 2, 2, 1, 1, 2, 2, 2, 1, 2, 1, 1].reverse();
const hexValue = parseInt(value, 16);
if (!hexValue) { // 0 or NaN
shaka.log.warning('Channel parsing failure! ' +
'Ignoring scheme and value', scheme, value);
continue;
}
// Count the 1-bits in hexValue.
let numBits = 0;
while (hexValue) {
if (hexValue & 1) {
++numBits;
for (let i = 0; i < channelCountMapping.length; i++) {
if (hexValue & (1<<i)) {
numBits += channelCountMapping[i];
}
hexValue >>= 1;
}
return numBits;
if (numBits) {
return numBits;
}
continue;
}

// Defined by https://dashif.org/identifiers/audio_source_metadata/ and clause 8.2, in ISO/IEC 23001-8.
Expand Down
45 changes: 41 additions & 4 deletions test/dash/dash_parser_manifest_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1488,18 +1488,55 @@ describe('DashParser Manifest', () => {
});

it('parses dolby scheme', async () => {
// Parses a hex value in which each 1-bit is a channel.
// L,R,C,LFE,Ls,Rs (5.1)
await testAudioChannelConfiguration(6,
{'tag:dolby.com,2014:dash:audio_channel_configuration:2011':
'F801'});
'F801'});

// This scheme seems to use the same format.
// L,R,C,LFE,Ls,Rs,Lrs,Rrs (7.1)
await testAudioChannelConfiguration(8,
{'tag:dolby.com,2014:dash:audio_channel_configuration:2011':
'FA01'});

// L,R,C,LFE,Ls,Rs,Ltm,Rtm (5.1.2)
await testAudioChannelConfiguration(8,
{'tag:dolby.com,2014:dash:audio_channel_configuration:2011':
'F805'});

// L,R,C,LFE,Ls,Rs (5.1)
await testAudioChannelConfiguration(6,
{'urn:dolby:dash:audio_channel_configuration:2011': 'F801'});

// L,R,C,LFE,Ls,Rs,Lrs,Rrs (7.1)
await testAudioChannelConfiguration(8,
{'urn:dolby:dash:audio_channel_configuration:2011': 'FA01'});

// L,R,C,LFE,Ls,Rs,Ltm,Rtm (5.1.2)
await testAudioChannelConfiguration(8,
{'urn:dolby:dash:audio_channel_configuration:2011': '7037'});
{'urn:dolby:dash:audio_channel_configuration:2011': 'F805'});

// Results in null if the value is not a valid hex number.
await testAudioChannelConfiguration(null,
{'urn:dolby:dash:audio_channel_configuration:2011': 'x'});

// L,R,C,LFE,Ls,Rs (5.1)
await testAudioChannelConfiguration(6,
{'tag:dolby.com,2015:dash:audio_channel_configuration:2015':
'000047'});

// L,R,C,LFE,Ls,Rs,Lrs,Rrs (7.1)
await testAudioChannelConfiguration(8,
{'tag:dolby.com,2015:dash:audio_channel_configuration:2015':
'00004F'});

// L,R,C,LFE,Ls,Rs,Ltm,Rtm (5.1.2)
await testAudioChannelConfiguration(8,
{'tag:dolby.com,2015:dash:audio_channel_configuration:2015':
'0000c7'});

// Results in null if the value is not a valid hex number.
await testAudioChannelConfiguration(null,
{'tag:dolby.com,2015:dash:audio_channel_configuration:2015': 'x'});
});

it('parses MPEG channel configuration scheme', async () => {
Expand Down

0 comments on commit 916a1f6

Please sign in to comment.