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