Coverage Report

Created: 2026-10-28 08:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fdk-aac/cpp/libSYS/src/syslib_channelMapDescr.cpp
Line
Count
Source
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
12.7k
  (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
static const UCHAR mapWg4Cfg1[]  = {0, 1};
160
static const UCHAR mapWg4Cfg2[]  = {0, 1};
161
static const UCHAR mapWg4Cfg3[]  = {2, 0, 1};
162
static const UCHAR mapWg4Cfg4[]  = {3, 0, 1, 2};
163
static const UCHAR mapWg4Cfg5[]  = {4, 0, 1, 2, 3};
164
static const UCHAR mapWg4Cfg6[]  = {4, 0, 1, 2, 3, 5};
165
static const UCHAR mapWg4Cfg7[]  = {6, 0, 1, 2, 3, 4, 5, 7};
166
static const UCHAR mapWg4Cfg14[] = {6, 0, 1, 2, 3, 4, 5, 7};
167
168
const CHANNEL_MAP_INFO FDK_mapInfoTabWg4[] =
169
    {/* chCfg,  map,         numCh */
170
     /*  0 */ {mapFallback, 24},
171
     /*  1 */ {mapWg4Cfg1, 2},
172
     /*  2 */ {mapWg4Cfg2, 2},
173
     /*  3 */ {mapWg4Cfg3, 3},
174
     /*  4 */ {mapWg4Cfg4, 4},
175
     /*  5 */ {mapWg4Cfg5, 5},
176
     /*  6 */ {mapWg4Cfg6, 6},
177
     /*  7 */ {mapWg4Cfg7, 8},
178
     /*  8 */ {mapFallback, 24},
179
     /*  9 */ {mapFallback, 24},
180
     /* 10 */ {mapFallback, 24},
181
     /* 11 */ {mapFallback, 24},  // Unhandled for Wg4 yet
182
     /* 12 */ {mapFallback, 24},  // Unhandled for Wg4 yet
183
     /* 13 */ {mapFallback, 24},  // Unhandled for Wg4 yet
184
     /* 14 */ {mapFallback, 24}}; // Unhandled for Wg4 yet
185
186
const UINT FDK_mapInfoTabLenWg4 = sizeof(FDK_mapInfoTabWg4)/sizeof(FDK_mapInfoTabWg4[0]);
187
188
189
/**
190
 * Get the mapping value for a specific channel and map index.
191
 */
192
UCHAR FDK_chMapDescr_getMapValue(const FDK_channelMapDescr* const pMapDescr,
193
22.5M
                                 const UCHAR chIdx, const UINT mapIdx) {
194
22.5M
  UCHAR mapValue = chIdx; /* Pass through by default. */
195
196
22.5M
  FDK_ASSERT(pMapDescr != NULL);
197
198
22.5M
  if ((pMapDescr->fPassThrough == 0) && (pMapDescr->pMapInfoTab != NULL) &&
199
22.5M
      (pMapDescr->mapInfoTabLen > mapIdx)) { /* Nest sanity check to avoid
200
                                                possible memory access
201
                                                violation. */
202
22.5M
    if (chIdx < pMapDescr->pMapInfoTab[mapIdx].numChannels) {
203
22.5M
      mapValue = pMapDescr->pMapInfoTab[mapIdx].pChannelMap[chIdx];
204
22.5M
    }
205
22.5M
  }
206
22.5M
  return mapValue;
207
22.5M
}
208
209
/**
210
 * \brief  Evaluate whether single channel map is reasonable or not.
211
 *
212
 * \param  pMapInfo  Pointer to channel map.
213
 * \return           Value unequal to zero if map is valid, otherwise zero.
214
 */
215
104M
static int fdk_chMapDescr_isValidMap(const CHANNEL_MAP_INFO* const pMapInfo) {
216
104M
  int result = 1;
217
104M
  UINT i;
218
219
104M
  if (pMapInfo == NULL) {
220
0
    result = 0;
221
104M
  } else {
222
104M
    UINT numChannels = pMapInfo->numChannels;
223
224
    /* Check for all map values if they are inside the range 0 to numChannels-1
225
     * and unique. */
226
104M
    if (numChannels < 32) { /* Optimized version for less than 32 channels.
227
                               Needs only one loop. */
228
104M
      UINT mappedChMask = 0x0;
229
1.31G
      for (i = 0; i < numChannels; i += 1) {
230
1.21G
        mappedChMask |= 1 << pMapInfo->pChannelMap[i];
231
1.21G
      }
232
104M
      if (mappedChMask != (((UINT)1 << numChannels) - 1)) {
233
0
        result = 0;
234
0
      }
235
104M
    } else { /* General case that can handle all number of channels but needs
236
                one more loop. */
237
0
      for (i = 0; (i < numChannels) && result; i += 1) {
238
0
        UINT j;
239
0
        UCHAR value0 = pMapInfo->pChannelMap[i];
240
241
0
        if (value0 > numChannels - 1) { /* out of range? */
242
0
          result = 0;
243
0
        }
244
0
        for (j = numChannels - 1; (j > i) && result; j -= 1) {
245
0
          if (value0 == pMapInfo->pChannelMap[j]) { /* not unique */
246
0
            result = 0;
247
0
          }
248
0
        }
249
0
      }
250
0
    }
251
104M
  }
252
253
104M
  return result;
254
104M
}
255
256
/**
257
 * Evaluate whether channel map descriptor is reasonable or not.
258
 */
259
6.99M
int FDK_chMapDescr_isValid(const FDK_channelMapDescr* const pMapDescr) {
260
6.99M
  int result = 0;
261
6.99M
  UINT i;
262
263
6.99M
  if (pMapDescr != NULL) {
264
6.99M
    result = 1;
265
111M
    for (i = 0; (i < pMapDescr->mapInfoTabLen) && result; i += 1) {
266
104M
      if (!fdk_chMapDescr_isValidMap(&pMapDescr->pMapInfoTab[i])) {
267
0
        result = 0;
268
0
      }
269
104M
    }
270
6.99M
  }
271
6.99M
  return result;
272
6.99M
}
273
274
/**
275
 * Initialize the complete channel map descriptor.
276
 */
277
void FDK_chMapDescr_init(FDK_channelMapDescr* const pMapDescr,
278
                         const CHANNEL_MAP_INFO* const pMapInfoTab,
279
12.7k
                         const UINT mapInfoTabLen, const UINT fPassThrough) {
280
12.7k
  if (pMapDescr != NULL) {
281
12.7k
    int useDefaultTab = 1;
282
283
12.7k
    pMapDescr->fPassThrough = (fPassThrough == 0) ? 0 : 1;
284
285
12.7k
    if ((pMapInfoTab != NULL) && (mapInfoTabLen > 0)) {
286
      /* Set the valid custom mapping table. */
287
0
      pMapDescr->pMapInfoTab = pMapInfoTab;
288
0
      pMapDescr->mapInfoTabLen = mapInfoTabLen;
289
      /* Validate the complete descriptor. */
290
0
      useDefaultTab = (FDK_chMapDescr_isValid(pMapDescr) == 0) ? 1 : 0;
291
0
    }
292
12.7k
    if (useDefaultTab != 0) {
293
      /* Set default table. */
294
12.7k
      pMapDescr->pMapInfoTab = mapInfoTabDflt;
295
12.7k
      pMapDescr->mapInfoTabLen = DFLT_CH_MAP_TAB_LEN;
296
12.7k
    }
297
12.7k
  }
298
12.7k
}
299
300
/**
301
 * Set channel mapping bypass flag in a given channel map descriptor.
302
 */
303
int FDK_chMapDescr_setPassThrough(FDK_channelMapDescr* const pMapDescr,
304
0
                                  UINT fPassThrough) {
305
0
  int err = 1;
306
307
0
  if (pMapDescr != NULL) {
308
0
    if ((pMapDescr->pMapInfoTab != NULL) && (pMapDescr->mapInfoTabLen > 0)) {
309
0
      pMapDescr->fPassThrough = (fPassThrough == 0) ? 0 : 1;
310
0
      err = 0;
311
0
    }
312
0
  }
313
314
0
  return err;
315
0
}