Coverage Report

Created: 2025-07-23 06:43

/src/aac/libSYS/src/syslib_channelMapDescr.cpp
Line
Count
Source (jump to first uncovered line)
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
29.6k
  (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
 */
161
UCHAR FDK_chMapDescr_getMapValue(const FDK_channelMapDescr* const pMapDescr,
162
15.8M
                                 const UCHAR chIdx, const UINT mapIdx) {
163
15.8M
  UCHAR mapValue = chIdx; /* Pass through by default. */
164
165
15.8M
  FDK_ASSERT(pMapDescr != NULL);
166
167
15.8M
  if ((pMapDescr->fPassThrough == 0) && (pMapDescr->pMapInfoTab != NULL) &&
168
15.8M
      (pMapDescr->mapInfoTabLen > mapIdx)) { /* Nest sanity check to avoid
169
                                                possible memory access
170
                                                violation. */
171
15.8M
    if (chIdx < pMapDescr->pMapInfoTab[mapIdx].numChannels) {
172
15.8M
      mapValue = pMapDescr->pMapInfoTab[mapIdx].pChannelMap[chIdx];
173
15.8M
    }
174
15.8M
  }
175
15.8M
  return mapValue;
176
15.8M
}
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
 */
184
22.8M
static int fdk_chMapDescr_isValidMap(const CHANNEL_MAP_INFO* const pMapInfo) {
185
22.8M
  int result = 1;
186
22.8M
  UINT i;
187
188
22.8M
  if (pMapInfo == NULL) {
189
0
    result = 0;
190
22.8M
  } else {
191
22.8M
    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
22.8M
    if (numChannels < 32) { /* Optimized version for less than 32 channels.
196
                               Needs only one loop. */
197
22.8M
      UINT mappedChMask = 0x0;
198
285M
      for (i = 0; i < numChannels; i += 1) {
199
263M
        mappedChMask |= 1 << pMapInfo->pChannelMap[i];
200
263M
      }
201
22.8M
      if (mappedChMask != (((UINT)1 << numChannels) - 1)) {
202
0
        result = 0;
203
0
      }
204
22.8M
    } else { /* General case that can handle all number of channels but needs
205
                one more loop. */
206
0
      for (i = 0; (i < numChannels) && result; i += 1) {
207
0
        UINT j;
208
0
        UCHAR value0 = pMapInfo->pChannelMap[i];
209
210
0
        if (value0 > numChannels - 1) { /* out of range? */
211
0
          result = 0;
212
0
        }
213
0
        for (j = numChannels - 1; (j > i) && result; j -= 1) {
214
0
          if (value0 == pMapInfo->pChannelMap[j]) { /* not unique */
215
0
            result = 0;
216
0
          }
217
0
        }
218
0
      }
219
0
    }
220
22.8M
  }
221
222
22.8M
  return result;
223
22.8M
}
224
225
/**
226
 * Evaluate whether channel map descriptor is reasonable or not.
227
 */
228
1.52M
int FDK_chMapDescr_isValid(const FDK_channelMapDescr* const pMapDescr) {
229
1.52M
  int result = 0;
230
1.52M
  UINT i;
231
232
1.52M
  if (pMapDescr != NULL) {
233
1.52M
    result = 1;
234
24.3M
    for (i = 0; (i < pMapDescr->mapInfoTabLen) && result; i += 1) {
235
22.8M
      if (!fdk_chMapDescr_isValidMap(&pMapDescr->pMapInfoTab[i])) {
236
0
        result = 0;
237
0
      }
238
22.8M
    }
239
1.52M
  }
240
1.52M
  return result;
241
1.52M
}
242
243
/**
244
 * Initialize the complete channel map descriptor.
245
 */
246
void FDK_chMapDescr_init(FDK_channelMapDescr* const pMapDescr,
247
                         const CHANNEL_MAP_INFO* const pMapInfoTab,
248
29.6k
                         const UINT mapInfoTabLen, const UINT fPassThrough) {
249
29.6k
  if (pMapDescr != NULL) {
250
29.6k
    int useDefaultTab = 1;
251
252
29.6k
    pMapDescr->fPassThrough = (fPassThrough == 0) ? 0 : 1;
253
254
29.6k
    if ((pMapInfoTab != NULL) && (mapInfoTabLen > 0)) {
255
      /* Set the valid custom mapping table. */
256
0
      pMapDescr->pMapInfoTab = pMapInfoTab;
257
0
      pMapDescr->mapInfoTabLen = mapInfoTabLen;
258
      /* Validate the complete descriptor. */
259
0
      useDefaultTab = (FDK_chMapDescr_isValid(pMapDescr) == 0) ? 1 : 0;
260
0
    }
261
29.6k
    if (useDefaultTab != 0) {
262
      /* Set default table. */
263
29.6k
      pMapDescr->pMapInfoTab = mapInfoTabDflt;
264
29.6k
      pMapDescr->mapInfoTabLen = DFLT_CH_MAP_TAB_LEN;
265
29.6k
    }
266
29.6k
  }
267
29.6k
}
268
269
/**
270
 * Set channel mapping bypass flag in a given channel map descriptor.
271
 */
272
int FDK_chMapDescr_setPassThrough(FDK_channelMapDescr* const pMapDescr,
273
0
                                  UINT fPassThrough) {
274
0
  int err = 1;
275
276
0
  if (pMapDescr != NULL) {
277
0
    if ((pMapDescr->pMapInfoTab != NULL) && (pMapDescr->mapInfoTabLen > 0)) {
278
0
      pMapDescr->fPassThrough = (fPassThrough == 0) ? 0 : 1;
279
0
      err = 0;
280
0
    }
281
0
  }
282
283
0
  return err;
284
0
}