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 /******************* MPEG transport format encoder library *********************
96
97 Author(s): Manuel Jander
98
99 Description: MPEG Transport data tables
100
101 *******************************************************************************/
102
103 #ifndef TP_DATA_H
104 #define TP_DATA_H
105
106 #include "machine_type.h"
107 #include "FDK_audio.h"
108 #include "FDK_bitstream.h"
109
110 /*
111 * Configuration
112 */
113
114 #define TP_USAC_MAX_SPEAKERS (24)
115
116 #define TP_USAC_MAX_EXT_ELEMENTS ((24))
117
118 #define TP_USAC_MAX_ELEMENTS ((24) + TP_USAC_MAX_EXT_ELEMENTS)
119
120 #define TP_USAC_MAX_CONFIG_LEN \
121 512 /* next power of two of maximum of escapedValue(hBs, 4, 4, 8) in \
122 AudioPreRoll() (285) */
123
124 #define TPDEC_USAC_NUM_CONFIG_CHANGE_FRAMES \
125 (1) /* Number of frames for config change in USAC */
126
127 enum {
128 TPDEC_FLUSH_OFF = 0,
129 TPDEC_RSV60_CFG_CHANGE_ATSC_FLUSH_ON = 1,
130 TPDEC_RSV60_DASH_IPF_ATSC_FLUSH_ON = 2,
131 TPDEC_USAC_DASH_IPF_FLUSH_ON = 3
132 };
133
134 enum {
135 TPDEC_BUILD_UP_OFF = 0,
136 TPDEC_RSV60_BUILD_UP_ON = 1,
137 TPDEC_RSV60_BUILD_UP_ON_IN_BAND = 2,
138 TPDEC_USAC_BUILD_UP_ON = 3,
139 TPDEC_RSV60_BUILD_UP_IDLE = 4,
140 TPDEC_RSV60_BUILD_UP_IDLE_IN_BAND = 5
141 };
142
143 /**
144 * ProgramConfig struct.
145 */
146 /* ISO/IEC 14496-3 4.4.1.1 Table 4.2 Program config element */
147 #define PC_FSB_CHANNELS_MAX 16 /* Front/Side/Back channels */
148 #define PC_LFE_CHANNELS_MAX 4
149 #define PC_ASSOCDATA_MAX 8
150 #define PC_CCEL_MAX 16 /* CC elements */
151 #define PC_COMMENTLENGTH 256
152 #define PC_NUM_HEIGHT_LAYER 3
153
154 typedef struct {
155 /* PCE bitstream elements: */
156 UCHAR ElementInstanceTag;
157 UCHAR Profile;
158 UCHAR SamplingFrequencyIndex;
159 UCHAR NumFrontChannelElements;
160 UCHAR NumSideChannelElements;
161 UCHAR NumBackChannelElements;
162 UCHAR NumLfeChannelElements;
163 UCHAR NumAssocDataElements;
164 UCHAR NumValidCcElements;
165
166 UCHAR MonoMixdownPresent;
167 UCHAR MonoMixdownElementNumber;
168
169 UCHAR StereoMixdownPresent;
170 UCHAR StereoMixdownElementNumber;
171
172 UCHAR MatrixMixdownIndexPresent;
173 UCHAR MatrixMixdownIndex;
174 UCHAR PseudoSurroundEnable;
175
176 UCHAR FrontElementIsCpe[PC_FSB_CHANNELS_MAX];
177 UCHAR FrontElementTagSelect[PC_FSB_CHANNELS_MAX];
178 UCHAR FrontElementHeightInfo[PC_FSB_CHANNELS_MAX];
179
180 UCHAR SideElementIsCpe[PC_FSB_CHANNELS_MAX];
181 UCHAR SideElementTagSelect[PC_FSB_CHANNELS_MAX];
182 UCHAR SideElementHeightInfo[PC_FSB_CHANNELS_MAX];
183
184 UCHAR BackElementIsCpe[PC_FSB_CHANNELS_MAX];
185 UCHAR BackElementTagSelect[PC_FSB_CHANNELS_MAX];
186 UCHAR BackElementHeightInfo[PC_FSB_CHANNELS_MAX];
187
188 UCHAR LfeElementTagSelect[PC_LFE_CHANNELS_MAX];
189
190 UCHAR AssocDataElementTagSelect[PC_ASSOCDATA_MAX];
191
192 UCHAR CcElementIsIndSw[PC_CCEL_MAX];
193 UCHAR ValidCcElementTagSelect[PC_CCEL_MAX];
194
195 UCHAR CommentFieldBytes;
196 UCHAR Comment[PC_COMMENTLENGTH];
197
198 /* Helper variables for administration: */
199 UCHAR isValid; /*!< Flag showing if PCE has been read successfully. */
200 UCHAR
201 NumChannels; /*!< Amount of audio channels summing all channel elements
202 including LFEs */
203 UCHAR NumEffectiveChannels; /*!< Amount of audio channels summing only SCEs
204 and CPEs */
205 UCHAR elCounter;
206
207 } CProgramConfig;
208
209 typedef enum {
210 ASCEXT_UNKOWN = -1,
211 ASCEXT_SBR = 0x2b7,
212 ASCEXT_PS = 0x548,
213 ASCEXT_MPS = 0x76a,
214 ASCEXT_SAOC = 0x7cb,
215 ASCEXT_LDMPS = 0x7cc
216
217 } TP_ASC_EXTENSION_ID;
218
219 /**
220 * GaSpecificConfig struct
221 */
222 typedef struct {
223 UINT m_frameLengthFlag;
224 UINT m_dependsOnCoreCoder;
225 UINT m_coreCoderDelay;
226
227 UINT m_extensionFlag;
228 UINT m_extensionFlag3;
229
230 UINT m_layer;
231 UINT m_numOfSubFrame;
232 UINT m_layerLength;
233
234 } CSGaSpecificConfig;
235
236 typedef enum {
237 ELDEXT_TERM = 0x0, /* Termination tag */
238 ELDEXT_SAOC = 0x1, /* SAOC config */
239 ELDEXT_LDSAC = 0x2, /* LD MPEG Surround config */
240 ELDEXT_DOWNSCALEINFO = 0x3 /* ELD sample rate adaptation */
241 /* reserved */
242 } ASC_ELD_EXT_TYPE;
243
244 typedef struct {
245 UCHAR m_frameLengthFlag;
246
247 UCHAR m_sbrPresentFlag;
248 UCHAR
249 m_useLdQmfTimeAlign; /* Use LD-MPS QMF in SBR to achive time alignment */
250 UCHAR m_sbrSamplingRate;
251 UCHAR m_sbrCrcFlag;
252 UINT m_downscaledSamplingFrequency;
253
254 } CSEldSpecificConfig;
255
256 typedef struct {
257 USAC_EXT_ELEMENT_TYPE usacExtElementType;
258 USHORT usacExtElementConfigLength;
259 USHORT usacExtElementDefaultLength;
260 UCHAR usacExtElementPayloadFrag;
261 UCHAR usacExtElementHasAudioPreRoll;
262 } CSUsacExtElementConfig;
263
264 typedef struct {
265 MP4_ELEMENT_ID usacElementType;
266 UCHAR m_noiseFilling;
267 UCHAR m_harmonicSBR;
268 UCHAR m_interTes;
269 UCHAR m_pvc;
270 UCHAR m_stereoConfigIndex;
271 CSUsacExtElementConfig extElement;
272 } CSUsacElementConfig;
273
274 typedef struct {
275 UCHAR m_frameLengthFlag;
276 UCHAR m_coreSbrFrameLengthIndex;
277 UCHAR m_sbrRatioIndex;
278 UCHAR m_nUsacChannels; /* number of audio channels signaled in
279 UsacDecoderConfig() / rsv603daDecoderConfig() via
280 numElements and usacElementType */
281 UCHAR m_channelConfigurationIndex;
282 UINT m_usacNumElements;
283 CSUsacElementConfig element[TP_USAC_MAX_ELEMENTS];
284
285 UCHAR numAudioChannels;
286 UCHAR m_usacConfigExtensionPresent;
287 UCHAR elementLengthPresent;
288 UCHAR UsacConfig[TP_USAC_MAX_CONFIG_LEN];
289 USHORT UsacConfigBits;
290 } CSUsacConfig;
291
292 /**
293 * Audio configuration struct, suitable for encoder and decoder configuration.
294 */
295 typedef struct {
296 /* XYZ Specific Data */
297 union {
298 CSGaSpecificConfig
299 m_gaSpecificConfig; /**< General audio specific configuration. */
300 CSEldSpecificConfig m_eldSpecificConfig; /**< ELD specific configuration. */
301 CSUsacConfig m_usacConfig; /**< USAC specific configuration */
302 } m_sc;
303
304 /* Common ASC parameters */
305 CProgramConfig m_progrConfigElement; /**< Program configuration. */
306
307 AUDIO_OBJECT_TYPE m_aot; /**< Audio Object Type. */
308 UINT m_samplingFrequency; /**< Samplerate. */
309 UINT m_samplesPerFrame; /**< Amount of samples per frame. */
310 UINT m_directMapping; /**< Document this please !! */
311
312 AUDIO_OBJECT_TYPE m_extensionAudioObjectType; /**< Audio object type */
313 UINT m_extensionSamplingFrequency; /**< Samplerate */
314
315 SCHAR m_channelConfiguration; /**< Channel configuration index */
316
317 SCHAR m_epConfig; /**< Error protection index */
318 SCHAR m_vcb11Flag; /**< aacSectionDataResilienceFlag */
319 SCHAR m_rvlcFlag; /**< aacScalefactorDataResilienceFlag */
320 SCHAR m_hcrFlag; /**< aacSpectralDataResilienceFlag */
321
322 SCHAR m_sbrPresentFlag; /**< Flag indicating the presence of SBR data in the
323 bitstream */
324 SCHAR
325 m_psPresentFlag; /**< Flag indicating the presence of parametric stereo
326 data in the bitstream */
327 UCHAR m_samplingFrequencyIndex; /**< Samplerate index */
328 UCHAR m_extensionSamplingFrequencyIndex; /**< Samplerate index */
329 SCHAR m_extensionChannelConfiguration; /**< Channel configuration index */
330
331 UCHAR
332 configMode; /**< The flag indicates if the callback shall work in memory
333 allocation mode or in config change detection mode */
334 UCHAR AacConfigChanged; /**< The flag will be set if at least one aac config
335 parameter has changed that requires a memory
336 reconfiguration, otherwise it will be cleared */
337 UCHAR SbrConfigChanged; /**< The flag will be set if at least one sbr config
338 parameter has changed that requires a memory
339 reconfiguration, otherwise it will be cleared */
340 UCHAR SacConfigChanged; /**< The flag will be set if at least one sac config
341 parameter has changed that requires a memory
342 reconfiguration, otherwise it will be cleared */
343
344 UCHAR
345 config[TP_USAC_MAX_CONFIG_LEN]; /**< Configuration stored as bitstream */
346 UINT configBits; /**< Configuration length in bits */
347
348 } CSAudioSpecificConfig;
349
350 typedef struct {
351 SCHAR flushCnt; /**< Flush frame counter */
352 UCHAR flushStatus; /**< Flag indicates flush mode: on|off */
353 SCHAR buildUpCnt; /**< Build up frame counter */
354 UCHAR buildUpStatus; /**< Flag indicates build up mode: on|off */
355 UCHAR cfgChanged; /**< Flag indicates that the config changed and the decoder
356 needs to be initialized again via callback. Make sure
357 that memory is freed before initialization. */
358 UCHAR contentChanged; /**< Flag indicates that the content changed i.e. a
359 right truncation occured before */
360 UCHAR forceCfgChange; /**< Flag indicates if config change has to be forced
361 even if new config is the same */
362 } CCtrlCFGChange;
363
364 typedef INT (*cbUpdateConfig_t)(void *, const CSAudioSpecificConfig *,
365 const UCHAR configMode, UCHAR *configChanged);
366 typedef INT (*cbFreeMem_t)(void *, const CSAudioSpecificConfig *);
367 typedef INT (*cbCtrlCFGChange_t)(void *, const CCtrlCFGChange *);
368 typedef INT (*cbSsc_t)(void *, HANDLE_FDK_BITSTREAM,
369 const AUDIO_OBJECT_TYPE coreCodec,
370 const INT samplingRate, const INT frameSize,
371 const INT stereoConfigIndex,
372 const INT coreSbrFrameLengthIndex, const INT configBytes,
373 const UCHAR configMode, UCHAR *configChanged);
374
375 typedef INT (*cbSbr_t)(void *self, HANDLE_FDK_BITSTREAM hBs,
376 const INT sampleRateIn, const INT sampleRateOut,
377 const INT samplesPerFrame,
378 const AUDIO_OBJECT_TYPE coreCodec,
379 const MP4_ELEMENT_ID elementID, const INT elementIndex,
380 const UCHAR harmonicSbr, const UCHAR stereoConfigIndex,
381 const UCHAR configMode, UCHAR *configChanged,
382 const INT downscaleFactor);
383
384 typedef INT (*cbUsac_t)(void *self, HANDLE_FDK_BITSTREAM hBs);
385
386 typedef INT (*cbUniDrc_t)(void *self, HANDLE_FDK_BITSTREAM hBs,
387 const INT fullPayloadLength, const INT payloadType,
388 const INT subStreamIndex, const INT payloadStart,
389 const AUDIO_OBJECT_TYPE);
390
391 typedef struct {
392 cbUpdateConfig_t cbUpdateConfig; /*!< Function pointer for Config change
393 notify callback. */
394 void *cbUpdateConfigData; /*!< User data pointer for Config change notify
395 callback. */
396 cbFreeMem_t cbFreeMem; /*!< Function pointer for free memory callback. */
397 void *cbFreeMemData; /*!< User data pointer for free memory callback. */
398 cbCtrlCFGChange_t cbCtrlCFGChange; /*!< Function pointer for config change
399 control callback. */
400 void *cbCtrlCFGChangeData; /*!< User data pointer for config change control
401 callback. */
402 cbSsc_t cbSsc; /*!< Function pointer for SSC parser callback. */
403 void *cbSscData; /*!< User data pointer for SSC parser callback. */
404 cbSbr_t cbSbr; /*!< Function pointer for SBR header parser callback. */
405 void *cbSbrData; /*!< User data pointer for SBR header parser callback. */
406 cbUsac_t cbUsac;
407 void *cbUsacData;
408 cbUniDrc_t cbUniDrc; /*!< Function pointer for uniDrcConfig and
409 loudnessInfoSet parser callback. */
410 void *cbUniDrcData; /*!< User data pointer for uniDrcConfig and
411 loudnessInfoSet parser callback. */
412 } CSTpCallBacks;
413
414 static const UINT SamplingRateTable[] = {
415 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025,
416 8000, 7350, 0, 0, 57600, 51200, 40000, 38400, 34150, 28800, 25600,
417 20000, 19200, 17075, 14400, 12800, 9600, 0, 0, 0, 0};
418
getSamplingRateIndex(UINT samplingRate,UINT nBits)419 static inline int getSamplingRateIndex(UINT samplingRate, UINT nBits) {
420 UINT sf_index;
421 UINT tableSize = (1 << nBits) - 1;
422
423 for (sf_index = 0; sf_index < tableSize; sf_index++) {
424 if (SamplingRateTable[sf_index] == samplingRate) break;
425 }
426
427 if (sf_index > tableSize) {
428 return tableSize - 1;
429 }
430
431 return sf_index;
432 }
433
434 /*
435 * Get Channel count from channel configuration
436 */
getNumberOfTotalChannels(int channelConfig)437 static inline int getNumberOfTotalChannels(int channelConfig) {
438 switch (channelConfig) {
439 case 1:
440 case 2:
441 case 3:
442 case 4:
443 case 5:
444 case 6:
445 return channelConfig;
446 case 7:
447 case 12:
448 case 14:
449 return 8;
450 case 11:
451 return 7;
452 case 13:
453 return 24;
454 default:
455 return 0;
456 }
457 }
458
getNumberOfEffectiveChannels(const int channelConfig)459 static inline int getNumberOfEffectiveChannels(
460 const int
461 channelConfig) { /* index: 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 */
462 const int n[] = {0, 1, 2, 3, 4, 5, 5, 7, 0, 0, 0, 6, 7, 22, 7, 0};
463 return n[channelConfig];
464 }
465
466 #endif /* TP_DATA_H */
467