Skip to content

Commit

Permalink
[DashTree] Improved channels parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
CastagnaIT committed Aug 17, 2023
1 parent 3184734 commit 9dfe58e
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions src/parser/DASHTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1364,18 +1364,48 @@ uint32_t adaptive::CDashTree::ParseAudioChannelConfig(pugi::xml_node node)
std::string_view value = XML::GetAttrib(node, "value");
uint32_t channels{0};

if (schemeIdUri == "urn:mpeg:dash:23003:3:audio_channel_configuration:2011" ||
schemeIdUri == "urn:mpeg:mpegB:cicp:ChannelConfiguration")
if (schemeIdUri == "urn:mpeg:dash:outputChannelPositionList:2012")
{
// A space-separated list of speaker positions,
// the number of channels is the length of the list
return static_cast<uint32_t>(STRING::SplitToVec(value, ' ').size());
}
else if (schemeIdUri == "urn:mpeg:dash:23003:3:audio_channel_configuration:2011" ||
schemeIdUri == "urn:dts:dash:audio_channel_configuration:2012")
{
// The value is the number of channels
channels = STRING::ToUint32(value);
}
else if (schemeIdUri == "urn:dolby:dash:audio_channel_configuration:2011" ||
schemeIdUri == "tag:dolby.com,2014:dash:audio_channel_configuration:2011")
{
if (value == "F801")
channels = 6;
else if (value == "FE01")
channels = 8;
// A hex-encoded 16-bit integer, each bit represents a channel
uint32_t hexVal = STRING::HexStrToUint(value);
uint32_t numBits{0};
while (hexVal)
{
if (hexVal & 1)
{
++numBits;
}
hexVal = hexVal >> 1;
}
channels = numBits;
}
else if (schemeIdUri == "urn:mpeg:mpegB:cicp:ChannelConfiguration")
{
// Defined by https://dashif.org/identifiers/audio_source_metadata/
static const size_t mapSize = 21;
static const int channelCountMapping[mapSize]{
0, 1, 2, 3, 4, 5, 6, 8, 2, 3, /* 0--9 */
4, 7, 8, 24, 8, 12, 10, 12, 14, 12, /* 10--19 */
14, /* 20 */
};
uint32_t pos = STRING::ToUint32(value);
if (pos > 0 && pos < mapSize)
{
channels = channelCountMapping[pos];
}
}
if (channels == 0)
{
Expand Down

0 comments on commit 9dfe58e

Please sign in to comment.