1 2 /* ----------------------------------------------------------------------------------------------------------- 3 Software License for The Fraunhofer FDK AAC Codec Library for Android 4 5 � Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur F�rderung der angewandten Forschung e.V. 6 All rights reserved. 7 8 1. INTRODUCTION 9 The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software that implements 10 the MPEG Advanced Audio Coding ("AAC") encoding and decoding scheme for digital audio. 11 This FDK AAC Codec software is intended to be used on a wide variety of Android devices. 12 13 AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient general perceptual 14 audio codecs. AAC-ELD is considered the best-performing full-bandwidth communications codec by 15 independent studies and is widely deployed. AAC has been standardized by ISO and IEC as part 16 of the MPEG specifications. 17 18 Patent licenses for necessary patent claims for the FDK AAC Codec (including those of Fraunhofer) 19 may be obtained through Via Licensing (www.vialicensing.com) or through the respective patent owners 20 individually for the purpose of encoding or decoding bit streams in products that are compliant with 21 the ISO/IEC MPEG audio standards. Please note that most manufacturers of Android devices already license 22 these patent claims through Via Licensing or directly from the patent owners, and therefore FDK AAC Codec 23 software may already be covered under those patent licenses when it is used for those licensed purposes only. 24 25 Commercially-licensed AAC software libraries, including floating-point versions with enhanced sound quality, 26 are also available from Fraunhofer. Users are encouraged to check the Fraunhofer website for additional 27 applications information and documentation. 28 29 2. COPYRIGHT LICENSE 30 31 Redistribution and use in source and binary forms, with or without modification, are permitted without 32 payment of copyright license fees provided that you satisfy the following conditions: 33 34 You must retain the complete text of this software license in redistributions of the FDK AAC Codec or 35 your modifications thereto in source code form. 36 37 You must retain the complete text of this software license in the documentation and/or other materials 38 provided with redistributions of the FDK AAC Codec or your modifications thereto in binary form. 39 You must make available free of charge copies of the complete source code of the FDK AAC Codec and your 40 modifications thereto to recipients of copies in binary form. 41 42 The name of Fraunhofer may not be used to endorse or promote products derived from this library without 43 prior written permission. 44 45 You may not charge copyright license fees for anyone to use, copy or distribute the FDK AAC Codec 46 software or your modifications thereto. 47 48 Your modified versions of the FDK AAC Codec must carry prominent notices stating that you changed the software 49 and the date of any change. For modified versions of the FDK AAC Codec, the term 50 "Fraunhofer FDK AAC Codec Library for Android" must be replaced by the term 51 "Third-Party Modified Version of the Fraunhofer FDK AAC Codec Library for Android." 52 53 3. NO PATENT LICENSE 54 55 NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without limitation the patents of Fraunhofer, 56 ARE GRANTED BY THIS SOFTWARE LICENSE. Fraunhofer provides no warranty of patent non-infringement with 57 respect to this software. 58 59 You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized 60 by appropriate patent licenses. 61 62 4. DISCLAIMER 63 64 This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright holders and contributors 65 "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, including but not limited to the implied warranties 66 of merchantability and fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 67 CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, or consequential damages, 68 including but not limited to procurement of substitute goods or services; loss of use, data, or profits, 69 or business interruption, however caused and on any theory of liability, whether in contract, strict 70 liability, or tort (including negligence), arising in any way out of the use of this software, even if 71 advised of the possibility of such damage. 72 73 5. CONTACT INFORMATION 74 75 Fraunhofer Institute for Integrated Circuits IIS 76 Attention: Audio and Multimedia Departments - FDK AAC LL 77 Am Wolfsmantel 33 78 91058 Erlangen, Germany 79 80 www.iis.fraunhofer.de/amm 81 amm-info@iis.fraunhofer.de 82 ----------------------------------------------------------------------------------------------------------- */ 83 84 /***************************** MPEG-4 AAC Decoder ************************** 85 86 Author(s): Josef Hoepfl 87 Description: 88 89 ******************************************************************************/ 90 91 #ifndef AACDECODER_H 92 #define AACDECODER_H 93 94 #include "common_fix.h" 95 96 #include "FDK_bitstream.h" 97 98 #include "channel.h" 99 100 #include "tpdec_lib.h" 101 #include "FDK_audio.h" 102 103 #include "block.h" 104 105 #include "genericStds.h" 106 107 108 #include "sbrdecoder.h" 109 110 111 #include "aacdec_drc.h" 112 113 #include "pcmutils_lib.h" 114 #include "limiter.h" 115 116 117 /* Capabilities flags */ 118 #define CAPF_AAC_LC 0x00000001 119 #define CAPF_AAC_LD 0x00000002 120 #define CAPF_AAC_SCAL 0x00000004 121 #define CAPF_AAC_ER 0x00000008 122 #define CAPF_AAC_480 0x00000010 123 #define CAPF_AAC_512 0x00000020 124 #define CAPF_AAC_960 0x00000040 125 #define CAPF_AAC_1024 0x00000080 126 #define CAPF_AAC_HCR 0x00000100 127 #define CAPF_AAC_VCB11 0x00000200 128 #define CAPF_AAC_RVLC 0x00000400 129 #define CAPF_AAC_MPEG4 0x00000800 /* PNS */ 130 #define CAPF_AAC_DRC 0x00001000 131 #define CAPF_AAC_CONCEAL 0x00002000 132 #define CAPF_AAC_DRM_BSFORMAT 0x00004000 133 #define CAPF_AAC_BSAC 0x00008000 134 135 typedef struct AAC_DECODER_INSTANCE *HANDLE_AACDECODER; 136 137 138 enum 139 { 140 L = 0, 141 R = 1 142 }; 143 144 typedef struct { 145 unsigned char *buffer; 146 int bufferSize; 147 int offset[8]; 148 int nrElements; 149 } CAncData; 150 151 typedef enum { 152 NOT_DEFINED = -1, 153 MODE_HQ = 0, 154 MODE_LP = 1 155 } QMF_MODE; 156 157 typedef struct { 158 int bsDelay; 159 } SBR_PARAMS; 160 161 162 /* AAC decoder (opaque toward userland) struct declaration */ 163 struct AAC_DECODER_INSTANCE { 164 INT aacChannels; /*!< Amount of AAC decoder channels allocated. */ 165 INT ascChannels; /*!< Amount of AAC decoder channels signalled in ASC. */ 166 INT blockNumber; /*!< frame counter */ 167 168 INT nrOfLayers; 169 170 INT outputInterleaved; /*!< PCM output format (interleaved/none interleaved). */ 171 172 HANDLE_TRANSPORTDEC hInput; /*!< Transport layer handle. */ 173 174 SamplingRateInfo samplingRateInfo; /*!< Sampling Rate information table */ 175 176 UCHAR frameOK; /*!< Will be unset if a consistency check, e.g. CRC etc. fails */ 177 178 UINT flags; /*!< Flags for internal decoder use. DO NOT USE self::streaminfo::flags ! */ 179 180 MP4_ELEMENT_ID elements[(8)]; /*!< Table where the element Id's are listed */ 181 UCHAR elTags[(8)]; /*!< Table where the elements id Tags are listed */ 182 UCHAR chMapping[(8)]; /*!< Table of MPEG canonical order to bitstream channel order mapping. */ 183 184 AUDIO_CHANNEL_TYPE channelType[(8)]; /*!< Audio channel type of each output audio channel (from 0 upto numChannels). */ 185 UCHAR channelIndices[(8)]; /*!< Audio channel index for each output audio channel (from 0 upto numChannels). */ 186 /* See ISO/IEC 13818-7:2005(E), 8.5.3.2 Explicit channel mapping using a program_config_element() */ 187 188 189 const UCHAR (*channelOutputMapping)[8]; /*!< Table for MPEG canonical order to output channel order mapping. */ 190 UCHAR chMapIndex; /*!< Index to access one line of the channelOutputMapping table. This is required 191 because not all 8 channel configurations have the same output mapping. */ 192 193 CProgramConfig pce; 194 CStreamInfo streamInfo; /*!< pointer to StreamInfo data (read from the bitstream) */ 195 CAacDecoderChannelInfo *pAacDecoderChannelInfo[(8)]; /*!< Temporal channel memory */ 196 CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo[(8)]; /*!< Persistent channel memory */ 197 198 CAacDecoderCommonData aacCommonData; /*!< Temporal shared data for all channels hooked into pAacDecoderChannelInfo */ 199 200 CConcealParams concealCommonData; 201 202 INT aacChannelsPrev; /*!< The amount of AAC core channels of the last successful decode call. */ 203 AUDIO_CHANNEL_TYPE channelTypePrev[(8)]; /*!< Array holding the channelType values of the last successful decode call. */ 204 UCHAR channelIndicesPrev[(8)]; /*!< Array holding the channelIndices values of the last successful decode call. */ 205 206 207 HANDLE_SBRDECODER hSbrDecoder; /*!< SBR decoder handle. */ 208 UCHAR sbrEnabled; /*!< flag to store if SBR has been detected */ 209 UCHAR sbrEnabledPrev; /*!< flag to store if SBR has been detected from previous frame */ 210 UCHAR psPossible; /*!< flag to store if PS is possible */ 211 SBR_PARAMS sbrParams; /*!< struct to store all sbr parameters */ 212 213 QMF_MODE qmfModeCurr; /*!< The current QMF mode */ 214 QMF_MODE qmfModeUser; /*!< The QMF mode requested by the library user */ 215 216 HANDLE_AAC_DRC hDrcInfo; /*!< handle to DRC data structure */ 217 218 219 CAncData ancData; /*!< structure to handle ancillary data */ 220 221 HANDLE_PCM_DOWNMIX hPcmUtils; /*!< privat data for the PCM utils. */ 222 TDLimiterPtr hLimiter; /*!< Handle of time domain limiter. */ 223 UCHAR limiterEnableUser; /*!< The limiter configuration requested by the library user */ 224 UCHAR limiterEnableCurr; /*!< The current limiter configuration. */ 225 226 FIXP_DBL extGain[1]; /*!< Gain that must be applied to the output signal. */ 227 UINT extGainDelay; /*!< Delay that must be accounted for extGain. */ 228 229 INT_PCM pcmOutputBuffer[(8)*(2048)]; 230 231 }; 232 233 234 #define AAC_DEBUG_EXTHLP "\ 235 --- AAC-Core ---\n\ 236 0x00010000 Header data\n\ 237 0x00020000 CRC data\n\ 238 0x00040000 Channel info\n\ 239 0x00080000 Section data\n\ 240 0x00100000 Scalefactor data\n\ 241 0x00200000 Pulse data\n\ 242 0x00400000 Tns data\n\ 243 0x00800000 Quantized spectrum\n\ 244 0x01000000 Requantized spectrum\n\ 245 0x02000000 Time output\n\ 246 0x04000000 Fatal errors\n\ 247 0x08000000 Buffer fullness\n\ 248 0x10000000 Average bitrate\n\ 249 0x20000000 Synchronization\n\ 250 0x40000000 Concealment\n\ 251 0x7FFF0000 all AAC-Core-Info\n\ 252 " 253 254 /** 255 * \brief Synchronise QMF mode for all modules using QMF data. 256 * \param self decoder handle 257 */ 258 void CAacDecoder_SyncQmfMode(HANDLE_AACDECODER self); 259 260 /** 261 * \brief Signal a bit stream interruption to the decoder 262 * \param self decoder handle 263 */ 264 void CAacDecoder_SignalInterruption(HANDLE_AACDECODER self); 265 266 /*! 267 \brief Initialize ancillary buffer 268 269 \ancData Pointer to ancillary data structure 270 \buffer Pointer to (external) anc data buffer 271 \size Size of the buffer pointed on by buffer 272 273 \return Error code 274 */ 275 AAC_DECODER_ERROR CAacDecoder_AncDataInit(CAncData *ancData, unsigned char *buffer, int size); 276 277 /*! 278 \brief Get one ancillary data element 279 280 \ancData Pointer to ancillary data structure 281 \index Index of the anc data element to get 282 \ptr Pointer to a buffer receiving a pointer to the requested anc data element 283 \size Pointer to a buffer receiving the length of the requested anc data element 284 285 \return Error code 286 */ 287 AAC_DECODER_ERROR CAacDecoder_AncDataGet(CAncData *ancData, int index, unsigned char **ptr, int *size); 288 289 290 /* initialization of aac decoder */ 291 LINKSPEC_H HANDLE_AACDECODER CAacDecoder_Open(TRANSPORT_TYPE bsFormat); 292 293 /* Initialization of stream-info elements */ 294 LINKSPEC_H AAC_DECODER_ERROR CAacDecoder_Init(HANDLE_AACDECODER self, 295 const CSAudioSpecificConfig *asc); 296 297 /*! 298 \brief Decodes one aac frame 299 300 The function decodes one aac frame. The decoding of coupling channel 301 elements are not supported. The transport layer might signal, that the 302 data of the current frame is invalid, e.g. as a result of a packet 303 loss in streaming mode. 304 The bitstream position of transportDec_GetBitstream(self->hInput) must 305 be exactly the end of the access unit, including all byte alignment bits. 306 For this purpose, the variable auStartAnchor is used. 307 308 \return error status 309 */ 310 LINKSPEC_H AAC_DECODER_ERROR CAacDecoder_DecodeFrame( 311 HANDLE_AACDECODER self, 312 const UINT flags, 313 INT_PCM *pTimeData, 314 const INT timeDataSize, 315 const INT interleaved 316 ); 317 318 /* Destroy aac decoder */ 319 LINKSPEC_H void CAacDecoder_Close ( HANDLE_AACDECODER self ); 320 321 /* get streaminfo handle from decoder */ 322 LINKSPEC_H CStreamInfo* CAacDecoder_GetStreamInfo ( HANDLE_AACDECODER self ); 323 324 325 #endif /* #ifndef AACDECODER_H */ 326