From 55637565ace71ae0ca5fb4060728ab4851d363ad Mon Sep 17 00:00:00 2001 From: Cedric Tio Date: Sat, 23 Apr 2022 06:28:27 +0800 Subject: [PATCH] Issue #10159 : DASH DTS Digital Surround Passthrough Fails in recent Exoplayer Versions --- .../dash/manifest/DashManifestParser.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestParser.java b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestParser.java index aeeb2459e89..bb14ffd793c 100644 --- a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestParser.java +++ b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestParser.java @@ -1463,6 +1463,13 @@ protected int parseAudioChannelConfiguration(XmlPullParser xpp) case "urn:mpeg:mpegB:cicp:ChannelConfiguration": audioChannels = parseMpegChannelConfiguration(xpp); break; + case "urn:dts:dash:audio_channel_configuration:2012": + case "tag:dts.com,2014:dash:audio_channel_configuration:2012": + audioChannels = parseDtsChannelConfiguration(xpp); + break; + case "tag:dts.com,2018:uhd:audio_channel_configuration": + audioChannels = parseDtsxChannelConfiguration(xpp); + break; case "tag:dolby.com,2014:dash:audio_channel_configuration:2011": case "urn:dolby:dash:audio_channel_configuration:2011": audioChannels = parseDolbyChannelConfiguration(xpp); @@ -1880,6 +1887,58 @@ protected static int parseMpegChannelConfiguration(XmlPullParser xpp) { : Format.NO_VALUE; } + /** + * Parses the number of channels from the value attribute of an AudioElementConfiguration with + * schemeIdUri as defined by Annex G (3.2) in ETSI TS 102 114 V1.6.1 + * + * @param xpp The parser from which to read. + * @return The parsed number of channels, or {@link Format#NO_VALUE} if the channel count could + * not be parsed. + */ + protected static int parseDtsChannelConfiguration(XmlPullParser xpp) { + @Nullable String value = xpp.getAttributeValue(null, "value"); + if (value == null) { + return Format.NO_VALUE; + } else { + int channelCount = Integer.decode(value); + if ((channelCount > 0) && (channelCount < 33)) { + return channelCount; + } else { + return Format.NO_VALUE; + } + } + } + + /** + * Parses the number of channels from the value attribute of an AudioElementConfiguration with + * schemeIdUri as defined by table B-5 in ETSI TS 103 491 v1.2.1. + * + * @param xpp The parser from which to read. + * @return The parsed number of channels, or {@link Format#NO_VALUE} if the channel count could + * not be parsed. + */ + protected static int parseDtsxChannelConfiguration(XmlPullParser xpp) { + @Nullable String value = xpp.getAttributeValue(null, "value"); + if (value == null) { + return Format.NO_VALUE; + } + + int channelMask = Integer.parseInt(value, 16); + + if (channelMask == 0) { + return Format.NO_VALUE; + } else { + // Determines Channel Count by summing the number of bits + // set in the channelMask. + int channelCount; // c accumulates the total bits set in v + + for (channelCount = 0; channelMask > 0; channelMask >>= 1) { + channelCount += channelMask & 1; + } + return channelCount; + } + } + /** * Parses the number of channels from the value attribute of an AudioElementConfiguration with * schemeIdUri "tag:dolby.com,2014:dash:audio_channel_configuration:2011", as defined by table E.5