1 /* -----------------------------------------------------------------------------
2 Software License for The Fraunhofer FDK AAC Codec Library for Android
3
4 © Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
5 Forschung e.V. All rights reserved.
6
7 1. INTRODUCTION
8 The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
9 that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
10 scheme for digital audio. This FDK AAC Codec software is intended to be used on
11 a wide variety of Android devices.
12
13 AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
14 general perceptual audio codecs. AAC-ELD is considered the best-performing
15 full-bandwidth communications codec by independent studies and is widely
16 deployed. AAC has been standardized by ISO and IEC as part of the MPEG
17 specifications.
18
19 Patent licenses for necessary patent claims for the FDK AAC Codec (including
20 those of Fraunhofer) may be obtained through Via Licensing
21 (www.vialicensing.com) or through the respective patent owners individually for
22 the purpose of encoding or decoding bit streams in products that are compliant
23 with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
24 Android devices already license these patent claims through Via Licensing or
25 directly from the patent owners, and therefore FDK AAC Codec software may
26 already be covered under those patent licenses when it is used for those
27 licensed purposes only.
28
29 Commercially-licensed AAC software libraries, including floating-point versions
30 with enhanced sound quality, are also available from Fraunhofer. Users are
31 encouraged to check the Fraunhofer website for additional applications
32 information and documentation.
33
34 2. COPYRIGHT LICENSE
35
36 Redistribution and use in source and binary forms, with or without modification,
37 are permitted without payment of copyright license fees provided that you
38 satisfy the following conditions:
39
40 You must retain the complete text of this software license in redistributions of
41 the FDK AAC Codec or your modifications thereto in source code form.
42
43 You must retain the complete text of this software license in the documentation
44 and/or other materials provided with redistributions of the FDK AAC Codec or
45 your modifications thereto in binary form. You must make available free of
46 charge copies of the complete source code of the FDK AAC Codec and your
47 modifications thereto to recipients of copies in binary form.
48
49 The name of Fraunhofer may not be used to endorse or promote products derived
50 from this library without prior written permission.
51
52 You may not charge copyright license fees for anyone to use, copy or distribute
53 the FDK AAC Codec software or your modifications thereto.
54
55 Your modified versions of the FDK AAC Codec must carry prominent notices stating
56 that you changed the software and the date of any change. For modified versions
57 of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
58 must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
59 AAC Codec Library for Android."
60
61 3. NO PATENT LICENSE
62
63 NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
64 limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
65 Fraunhofer provides no warranty of patent non-infringement with respect to this
66 software.
67
68 You may use this FDK AAC Codec software or modifications thereto only for
69 purposes that are authorized by appropriate patent licenses.
70
71 4. DISCLAIMER
72
73 This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
74 holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
75 including but not limited to the implied warranties of merchantability and
76 fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
77 CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
78 or consequential damages, including but not limited to procurement of substitute
79 goods or services; loss of use, data, or profits, or business interruption,
80 however caused and on any theory of liability, whether in contract, strict
81 liability, or tort (including negligence), arising in any way out of the use of
82 this software, even if advised of the possibility of such damage.
83
84 5. CONTACT INFORMATION
85
86 Fraunhofer Institute for Integrated Circuits IIS
87 Attention: Audio and Multimedia Departments - FDK AAC LL
88 Am Wolfsmantel 33
89 91058 Erlangen, Germany
90
91 www.iis.fraunhofer.de/amm
92 amm-info@iis.fraunhofer.de
93 ----------------------------------------------------------------------------- */
94
95 /************************* System integration library **************************
96
97 Author(s): Thomas Dietzen
98
99 Description:
100
101 *******************************************************************************/
102
103 /** \file syslib_channelMapDescr.cpp
104 * \brief Implementation of routines that handle the channel map descriptor.
105 */
106
107 #include "syslib_channelMapDescr.h"
108
109 #define DFLT_CH_MAP_TAB_LEN \
110 (15) /* Length of the default channel map info table. */
111
112 /**
113 * \brief The following arrays provide a channel map for each channel config (0
114 * to 14).
115 *
116 * The i-th channel will be mapped to the postion a[i-1]+1
117 * with i>0 and a[] is one of the following mapping arrays.
118 */
119 static const UCHAR mapFallback[] = {0, 1, 2, 3, 4, 5, 6, 7,
120 8, 9, 10, 11, 12, 13, 14, 15,
121 16, 17, 18, 19, 20, 21, 22, 23};
122 static const UCHAR mapCfg1[] = {0, 1};
123 static const UCHAR mapCfg2[] = {0, 1};
124 static const UCHAR mapCfg3[] = {2, 0, 1};
125 static const UCHAR mapCfg4[] = {2, 0, 1, 3};
126 static const UCHAR mapCfg5[] = {2, 0, 1, 3, 4};
127 static const UCHAR mapCfg6[] = {2, 0, 1, 4, 5, 3};
128 static const UCHAR mapCfg7[] = {2, 6, 7, 0, 1, 4, 5, 3};
129 static const UCHAR mapCfg11[] = {2, 0, 1, 4, 5, 6, 3};
130 static const UCHAR mapCfg12[] = {2, 0, 1, 6, 7, 4, 5, 3};
131 static const UCHAR mapCfg13[] = {2, 6, 7, 0, 1, 10, 11, 4,
132 5, 8, 3, 9, 14, 12, 13, 18,
133 19, 15, 16, 17, 20, 21, 22, 23};
134 static const UCHAR mapCfg14[] = {2, 0, 1, 4, 5, 3, 6, 7};
135
136 /**
137 * \brief Default table comprising channel map information for each channel
138 * config (0 to 14).
139 */
140 static const CHANNEL_MAP_INFO mapInfoTabDflt[DFLT_CH_MAP_TAB_LEN] =
141 {/* chCfg, map, numCh */
142 /* 0 */ {mapFallback, 24},
143 /* 1 */ {mapCfg1, 2},
144 /* 2 */ {mapCfg2, 2},
145 /* 3 */ {mapCfg3, 3},
146 /* 4 */ {mapCfg4, 4},
147 /* 5 */ {mapCfg5, 5},
148 /* 6 */ {mapCfg6, 6},
149 /* 7 */ {mapCfg7, 8},
150 /* 8 */ {mapFallback, 24},
151 /* 9 */ {mapFallback, 24},
152 /* 10 */ {mapFallback, 24},
153 /* 11 */ {mapCfg11, 7},
154 /* 12 */ {mapCfg12, 8},
155 /* 13 */ {mapCfg13, 24},
156 /* 14 */ {mapCfg14, 8}};
157
158 /**
159 * Get the mapping value for a specific channel and map index.
160 */
FDK_chMapDescr_getMapValue(const FDK_channelMapDescr * const pMapDescr,const UCHAR chIdx,const UINT mapIdx)161 UCHAR FDK_chMapDescr_getMapValue(const FDK_channelMapDescr* const pMapDescr,
162 const UCHAR chIdx, const UINT mapIdx) {
163 UCHAR mapValue = chIdx; /* Pass through by default. */
164
165 FDK_ASSERT(pMapDescr != NULL);
166
167 if ((pMapDescr->fPassThrough == 0) && (pMapDescr->pMapInfoTab != NULL) &&
168 (pMapDescr->mapInfoTabLen > mapIdx)) { /* Nest sanity check to avoid
169 possible memory access
170 violation. */
171 if (chIdx < pMapDescr->pMapInfoTab[mapIdx].numChannels) {
172 mapValue = pMapDescr->pMapInfoTab[mapIdx].pChannelMap[chIdx];
173 }
174 }
175 return mapValue;
176 }
177
178 /**
179 * \brief Evaluate whether single channel map is reasonable or not.
180 *
181 * \param pMapInfo Pointer to channel map.
182 * \return Value unequal to zero if map is valid, otherwise zero.
183 */
fdk_chMapDescr_isValidMap(const CHANNEL_MAP_INFO * const pMapInfo)184 static int fdk_chMapDescr_isValidMap(const CHANNEL_MAP_INFO* const pMapInfo) {
185 int result = 1;
186 UINT i;
187
188 if (pMapInfo == NULL) {
189 result = 0;
190 } else {
191 UINT numChannels = pMapInfo->numChannels;
192
193 /* Check for all map values if they are inside the range 0 to numChannels-1
194 * and unique. */
195 if (numChannels < 32) { /* Optimized version for less than 32 channels.
196 Needs only one loop. */
197 UINT mappedChMask = 0x0;
198 for (i = 0; i < numChannels; i += 1) {
199 mappedChMask |= 1 << pMapInfo->pChannelMap[i];
200 }
201 if (mappedChMask != (((UINT)1 << numChannels) - 1)) {
202 result = 0;
203 }
204 } else { /* General case that can handle all number of channels but needs
205 one more loop. */
206 for (i = 0; (i < numChannels) && result; i += 1) {
207 UINT j;
208 UCHAR value0 = pMapInfo->pChannelMap[i];
209
210 if (value0 > numChannels - 1) { /* out of range? */
211 result = 0;
212 }
213 for (j = numChannels - 1; (j > i) && result; j -= 1) {
214 if (value0 == pMapInfo->pChannelMap[j]) { /* not unique */
215 result = 0;
216 }
217 }
218 }
219 }
220 }
221
222 return result;
223 }
224
225 /**
226 * Evaluate whether channel map descriptor is reasonable or not.
227 */
FDK_chMapDescr_isValid(const FDK_channelMapDescr * const pMapDescr)228 int FDK_chMapDescr_isValid(const FDK_channelMapDescr* const pMapDescr) {
229 int result = 0;
230 UINT i;
231
232 if (pMapDescr != NULL) {
233 result = 1;
234 for (i = 0; (i < pMapDescr->mapInfoTabLen) && result; i += 1) {
235 if (!fdk_chMapDescr_isValidMap(&pMapDescr->pMapInfoTab[i])) {
236 result = 0;
237 }
238 }
239 }
240 return result;
241 }
242
243 /**
244 * Initialize the complete channel map descriptor.
245 */
FDK_chMapDescr_init(FDK_channelMapDescr * const pMapDescr,const CHANNEL_MAP_INFO * const pMapInfoTab,const UINT mapInfoTabLen,const UINT fPassThrough)246 void FDK_chMapDescr_init(FDK_channelMapDescr* const pMapDescr,
247 const CHANNEL_MAP_INFO* const pMapInfoTab,
248 const UINT mapInfoTabLen, const UINT fPassThrough) {
249 if (pMapDescr != NULL) {
250 int useDefaultTab = 1;
251
252 pMapDescr->fPassThrough = (fPassThrough == 0) ? 0 : 1;
253
254 if ((pMapInfoTab != NULL) && (mapInfoTabLen > 0)) {
255 /* Set the valid custom mapping table. */
256 pMapDescr->pMapInfoTab = pMapInfoTab;
257 pMapDescr->mapInfoTabLen = mapInfoTabLen;
258 /* Validate the complete descriptor. */
259 useDefaultTab = (FDK_chMapDescr_isValid(pMapDescr) == 0) ? 1 : 0;
260 }
261 if (useDefaultTab != 0) {
262 /* Set default table. */
263 pMapDescr->pMapInfoTab = mapInfoTabDflt;
264 pMapDescr->mapInfoTabLen = DFLT_CH_MAP_TAB_LEN;
265 }
266 }
267 }
268
269 /**
270 * Set channel mapping bypass flag in a given channel map descriptor.
271 */
FDK_chMapDescr_setPassThrough(FDK_channelMapDescr * const pMapDescr,UINT fPassThrough)272 int FDK_chMapDescr_setPassThrough(FDK_channelMapDescr* const pMapDescr,
273 UINT fPassThrough) {
274 int err = 1;
275
276 if (pMapDescr != NULL) {
277 if ((pMapDescr->pMapInfoTab != NULL) && (pMapDescr->mapInfoTabLen > 0)) {
278 pMapDescr->fPassThrough = (fPassThrough == 0) ? 0 : 1;
279 err = 0;
280 }
281 }
282
283 return err;
284 }
285