|
1 | | -/** |
2 | | - * The copyright in this software is being made available under the BSD License, |
3 | | - * included below. This software may be subject to other third party and contributor |
4 | | - * rights, including patent rights, and no such rights are granted under this license. |
5 | | - * |
6 | | - * Copyright (c) 2025, Dash Industry Forum. |
7 | | - * All rights reserved. |
8 | | - * |
9 | | - * Redistribution and use in source and binary forms, with or without modification, |
10 | | - * are permitted provided that the following conditions are met: |
11 | | - * * Redistributions of source code must retain the above copyright notice, this |
12 | | - * list of conditions and the following disclaimer. |
13 | | - * * Redistributions in binary form must reproduce the above copyright notice, |
14 | | - * this list of conditions and the following disclaimer in the documentation and/or |
15 | | - * other materials provided with the distribution. |
16 | | - * * Neither the name of Dash Industry Forum nor the names of its |
17 | | - * contributors may be used to endorse or promote products derived from this software |
18 | | - * without specific prior written permission. |
19 | | - * |
20 | | - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY |
21 | | - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
22 | | - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
23 | | - * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
24 | | - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
25 | | - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF USE, DATA, OR |
26 | | - * PROFITS, OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
27 | | - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | | - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | | - * POSSIBILITY OF SUCH DAMAGE. |
30 | | - */ |
31 | | - |
32 | | - |
33 | | - |
34 | | -// derived from ISO/IEC 23091-3 |
35 | | -const _mapping_CICP = { |
36 | | - '0': undefined, |
37 | | - '1': 1, |
38 | | - '2': 2, |
39 | | - '3': 3, |
40 | | - '4': 4, |
41 | | - '5': 5, |
42 | | - '6': 5, |
43 | | - '7': 7, |
44 | | - '8': 2, |
45 | | - '9': 3, |
46 | | - '10': 4, |
47 | | - '11': 6, |
48 | | - '12': 7, |
49 | | - '13': 22, |
50 | | - '14': 7, |
51 | | - '15': 10, |
52 | | - '16': 9, |
53 | | - '17': 11, |
54 | | - '18': 13, |
55 | | - '19': 11, |
56 | | - '20': 13 |
57 | | -}; |
58 | | - |
59 | | -function _countBits(n) { |
60 | | - return n == 0 ? 0 : n.toString(2).match(/1/g).length; |
61 | | -} |
62 | | - |
63 | | -function _getNChanFromBitMask(value, masks) { |
64 | | - let nChan = undefined; |
65 | | - let intVal = parseInt('0x' + value, 16); |
66 | | - |
67 | | - let singleChannels = intVal & masks[0]; |
68 | | - let ChannelPairs = intVal & masks[1]; |
69 | | - nChan = _countBits(singleChannels) + 2 * _countBits(ChannelPairs); |
70 | | - |
71 | | - return nChan; |
72 | | -} |
73 | | - |
74 | | -function _getNChanDolby2011(value) { |
75 | | - if ( value.length !== 4 ) { |
76 | | - return undefined; |
77 | | - } |
78 | | - |
79 | | - // see ETSI TS 103190-1, table F.1: |
80 | | - // 0b1111100110001000: single channel flags |
81 | | - // 0b0000011001110000: channel pair flags |
82 | | - return _getNChanFromBitMask(value, [0b1111100110001000, 0b0000011001110000]); |
83 | | -} |
84 | | - |
85 | | -function _getNChanDolby2015(value) { |
86 | | - if ( value.length !== 6 ) { |
87 | | - return undefined; |
88 | | - } |
89 | | - |
90 | | - if ( value === '800000' ) { |
91 | | - // object audio |
92 | | - return 24; |
93 | | - } |
94 | | - |
95 | | - // see ETSI TS 103190-2, table A.27 |
96 | | - // 0b001101111000000010: single channel flags |
97 | | - // 0b110010000110111101: channel pair flags |
98 | | - return _getNChanFromBitMask(value, [0b001101111000000010, 0b110010000110111101]); |
99 | | -} |
100 | | - |
101 | | -function _getNChanDTSUHD(value) { |
102 | | - if ( value.length > 8 ) { |
103 | | - return undefined; |
104 | | - } |
105 | | - |
106 | | - // see ETSI TS 103491, table B-5 |
107 | | - // LFE to exclude: 0x00010000 + 0x00000020 |
108 | | - return _getNChanFromBitMask(value, [0xFFFEFFDF, 0x00000000]); |
109 | | -} |
110 | | - |
111 | | -function getNChanFromAudioChannelConfig(audioChannelConfiguration) { |
112 | | - let nChan = undefined; |
113 | | - |
114 | | - if ( !audioChannelConfiguration || !audioChannelConfiguration.schemeIdUri || !audioChannelConfiguration.value ) { |
115 | | - return undefined; |
116 | | - } |
117 | | - |
118 | | - const scheme = audioChannelConfiguration['schemeIdUri']; |
119 | | - const value = audioChannelConfiguration['value']; |
120 | | - |
121 | | - if (scheme === 'urn:mpeg:dash:23003:3:audio_channel_configuration:2011' || scheme === 'urn:mpeg:mpegB:cicp:ChannelConfiguration') { |
122 | | - // see ISO/IEC 23091-3 |
123 | | - nChan = _mapping_CICP[value]; |
124 | | - } else if (scheme === 'tag:dolby.com,2014:dash:audio_channel_configuration:2011') { |
125 | | - nChan = _getNChanDolby2011(value); |
126 | | - } else if (scheme === 'tag:dolby.com,2015:dash:audio_channel_configuration:2015') { |
127 | | - nChan = _getNChanDolby2015(value); |
128 | | - } else if (scheme === 'tag:dts.com,2014:dash:audio_channel_configuration:2012') { |
129 | | - nChan = parseInt(value); // per ETSI TS 102 114,table G.2, this includes LFE |
130 | | - } else if (scheme === 'tag:dts.com,2018:uhd:audio_channel_configuration') { |
131 | | - nChan = _getNChanDTSUHD(value); |
132 | | - } |
133 | | - return nChan; |
134 | | -} |
135 | | - |
136 | | -export default getNChanFromAudioChannelConfig; |
| 1 | +/** |
| 2 | + * The copyright in this software is being made available under the BSD License, |
| 3 | + * included below. This software may be subject to other third party and contributor |
| 4 | + * rights, including patent rights, and no such rights are granted under this license. |
| 5 | + * |
| 6 | + * Copyright (c) 2025, Dash Industry Forum. |
| 7 | + * All rights reserved. |
| 8 | + * |
| 9 | + * Redistribution and use in source and binary forms, with or without modification, |
| 10 | + * are permitted provided that the following conditions are met: |
| 11 | + * * Redistributions of source code must retain the above copyright notice, this |
| 12 | + * list of conditions and the following disclaimer. |
| 13 | + * * Redistributions in binary form must reproduce the above copyright notice, |
| 14 | + * this list of conditions and the following disclaimer in the documentation and/or |
| 15 | + * other materials provided with the distribution. |
| 16 | + * * Neither the name of Dash Industry Forum nor the names of its |
| 17 | + * contributors may be used to endorse or promote products derived from this software |
| 18 | + * without specific prior written permission. |
| 19 | + * |
| 20 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY |
| 21 | + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 22 | + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 23 | + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
| 24 | + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 25 | + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF USE, DATA, OR |
| 26 | + * PROFITS, OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 27 | + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 28 | + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 29 | + * POSSIBILITY OF SUCH DAMAGE. |
| 30 | + */ |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | +// derived from ISO/IEC 23091-3 |
| 35 | +const _mapping_CICP = { |
| 36 | + '0': undefined, |
| 37 | + '1': 1, |
| 38 | + '2': 2, |
| 39 | + '3': 3, |
| 40 | + '4': 4, |
| 41 | + '5': 5, |
| 42 | + '6': 5, |
| 43 | + '7': 7, |
| 44 | + '8': 2, |
| 45 | + '9': 3, |
| 46 | + '10': 4, |
| 47 | + '11': 6, |
| 48 | + '12': 7, |
| 49 | + '13': 22, |
| 50 | + '14': 7, |
| 51 | + '15': 10, |
| 52 | + '16': 9, |
| 53 | + '17': 11, |
| 54 | + '18': 13, |
| 55 | + '19': 11, |
| 56 | + '20': 13 |
| 57 | +}; |
| 58 | + |
| 59 | +function _countBits(n) { |
| 60 | + return n == 0 ? 0 : n.toString(2).match(/1/g).length; |
| 61 | +} |
| 62 | + |
| 63 | +function _getNChanFromBitMask(value, masks) { |
| 64 | + let nChan = undefined; |
| 65 | + let intVal = parseInt('0x' + value, 16); |
| 66 | + |
| 67 | + let singleChannels = intVal & masks[0]; |
| 68 | + let ChannelPairs = intVal & masks[1]; |
| 69 | + nChan = _countBits(singleChannels) + 2 * _countBits(ChannelPairs); |
| 70 | + |
| 71 | + return nChan; |
| 72 | +} |
| 73 | + |
| 74 | +function _getNChanDolby2011(value) { |
| 75 | + if ( value.length !== 4 ) { |
| 76 | + return undefined; |
| 77 | + } |
| 78 | + |
| 79 | + // see ETSI TS 103190-1, table F.1: |
| 80 | + // 0b1111100110001000: single channel flags |
| 81 | + // 0b0000011001110000: channel pair flags |
| 82 | + return _getNChanFromBitMask(value, [0b1111100110001000, 0b0000011001110000]); |
| 83 | +} |
| 84 | + |
| 85 | +function _getNChanDolby2015(value) { |
| 86 | + if ( value.length !== 6 ) { |
| 87 | + return undefined; |
| 88 | + } |
| 89 | + |
| 90 | + if ( value === '800000' ) { |
| 91 | + // object audio |
| 92 | + return 24; |
| 93 | + } |
| 94 | + |
| 95 | + // see ETSI TS 103190-2, table A.27 |
| 96 | + // 0b001101111000000010: single channel flags |
| 97 | + // 0b110010000110111101: channel pair flags |
| 98 | + return _getNChanFromBitMask(value, [0b001101111000000010, 0b110010000110111101]); |
| 99 | +} |
| 100 | + |
| 101 | +function _getNChanDTSUHD(value) { |
| 102 | + if ( value.length > 8 ) { |
| 103 | + return undefined; |
| 104 | + } |
| 105 | + |
| 106 | + // see ETSI TS 103491, table B-5 |
| 107 | + // LFE to exclude: 0x00010000 + 0x00000020 |
| 108 | + return _getNChanFromBitMask(value, [0xFFFEFFDF, 0x00000000]); |
| 109 | +} |
| 110 | + |
| 111 | +function getNChanFromAudioChannelConfig(audioChannelConfiguration) { |
| 112 | + let nChan = undefined; |
| 113 | + |
| 114 | + if ( !audioChannelConfiguration || !audioChannelConfiguration.schemeIdUri || !audioChannelConfiguration.value ) { |
| 115 | + return undefined; |
| 116 | + } |
| 117 | + |
| 118 | + const scheme = audioChannelConfiguration['schemeIdUri']; |
| 119 | + const value = audioChannelConfiguration['value']; |
| 120 | + |
| 121 | + if (scheme === 'urn:mpeg:dash:23003:3:audio_channel_configuration:2011' || scheme === 'urn:mpeg:mpegB:cicp:ChannelConfiguration') { |
| 122 | + // see ISO/IEC 23091-3 |
| 123 | + nChan = _mapping_CICP[value]; |
| 124 | + } else if (scheme === 'tag:dolby.com,2014:dash:audio_channel_configuration:2011') { |
| 125 | + nChan = _getNChanDolby2011(value); |
| 126 | + } else if (scheme === 'tag:dolby.com,2015:dash:audio_channel_configuration:2015') { |
| 127 | + nChan = _getNChanDolby2015(value); |
| 128 | + } else if (scheme === 'tag:dts.com,2014:dash:audio_channel_configuration:2012') { |
| 129 | + nChan = parseInt(value); // per ETSI TS 102 114,table G.2, this includes LFE |
| 130 | + } else if (scheme === 'tag:dts.com,2018:uhd:audio_channel_configuration') { |
| 131 | + nChan = _getNChanDTSUHD(value); |
| 132 | + } |
| 133 | + return nChan; |
| 134 | +} |
| 135 | + |
| 136 | +export default getNChanFromAudioChannelConfig; |
0 commit comments