aacdecoder_lib.h 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082
  1. /* -----------------------------------------------------------------------------
  2. Software License for The Fraunhofer FDK AAC Codec Library for Android
  3. © Copyright 1995 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten
  4. Forschung e.V. All rights reserved.
  5. 1. INTRODUCTION
  6. The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
  7. that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
  8. scheme for digital audio. This FDK AAC Codec software is intended to be used on
  9. a wide variety of Android devices.
  10. AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
  11. general perceptual audio codecs. AAC-ELD is considered the best-performing
  12. full-bandwidth communications codec by independent studies and is widely
  13. deployed. AAC has been standardized by ISO and IEC as part of the MPEG
  14. specifications.
  15. Patent licenses for necessary patent claims for the FDK AAC Codec (including
  16. those of Fraunhofer) may be obtained through Via Licensing
  17. (www.vialicensing.com) or through the respective patent owners individually for
  18. the purpose of encoding or decoding bit streams in products that are compliant
  19. with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
  20. Android devices already license these patent claims through Via Licensing or
  21. directly from the patent owners, and therefore FDK AAC Codec software may
  22. already be covered under those patent licenses when it is used for those
  23. licensed purposes only.
  24. Commercially-licensed AAC software libraries, including floating-point versions
  25. with enhanced sound quality, are also available from Fraunhofer. Users are
  26. encouraged to check the Fraunhofer website for additional applications
  27. information and documentation.
  28. 2. COPYRIGHT LICENSE
  29. Redistribution and use in source and binary forms, with or without modification,
  30. are permitted without payment of copyright license fees provided that you
  31. satisfy the following conditions:
  32. You must retain the complete text of this software license in redistributions of
  33. the FDK AAC Codec or your modifications thereto in source code form.
  34. You must retain the complete text of this software license in the documentation
  35. and/or other materials provided with redistributions of the FDK AAC Codec or
  36. your modifications thereto in binary form. You must make available free of
  37. charge copies of the complete source code of the FDK AAC Codec and your
  38. modifications thereto to recipients of copies in binary form.
  39. The name of Fraunhofer may not be used to endorse or promote products derived
  40. from this library without prior written permission.
  41. You may not charge copyright license fees for anyone to use, copy or distribute
  42. the FDK AAC Codec software or your modifications thereto.
  43. Your modified versions of the FDK AAC Codec must carry prominent notices stating
  44. that you changed the software and the date of any change. For modified versions
  45. of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
  46. must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
  47. AAC Codec Library for Android."
  48. 3. NO PATENT LICENSE
  49. NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
  50. limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
  51. Fraunhofer provides no warranty of patent non-infringement with respect to this
  52. software.
  53. You may use this FDK AAC Codec software or modifications thereto only for
  54. purposes that are authorized by appropriate patent licenses.
  55. 4. DISCLAIMER
  56. This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
  57. holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
  58. including but not limited to the implied warranties of merchantability and
  59. fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  60. CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
  61. or consequential damages, including but not limited to procurement of substitute
  62. goods or services; loss of use, data, or profits, or business interruption,
  63. however caused and on any theory of liability, whether in contract, strict
  64. liability, or tort (including negligence), arising in any way out of the use of
  65. this software, even if advised of the possibility of such damage.
  66. 5. CONTACT INFORMATION
  67. Fraunhofer Institute for Integrated Circuits IIS
  68. Attention: Audio and Multimedia Departments - FDK AAC LL
  69. Am Wolfsmantel 33
  70. 91058 Erlangen, Germany
  71. www.iis.fraunhofer.de/amm
  72. amm-info@iis.fraunhofer.de
  73. ----------------------------------------------------------------------------- */
  74. /**************************** AAC decoder library ******************************
  75. Author(s): Manuel Jander
  76. Description:
  77. *******************************************************************************/
  78. #ifndef AACDECODER_LIB_H
  79. #define AACDECODER_LIB_H
  80. /**
  81. * \file aacdecoder_lib.h
  82. * \brief FDK AAC decoder library interface header file.
  83. *
  84. \page INTRO Introduction
  85. \section SCOPE Scope
  86. This document describes the high-level application interface and usage of the
  87. ISO/MPEG-2/4 AAC Decoder library developed by the Fraunhofer Institute for
  88. Integrated Circuits (IIS). Depending on the library configuration, decoding of
  89. AAC-LC (Low-Complexity), HE-AAC (High-Efficiency AAC v1 and v2), AAC-LD
  90. (Low-Delay) and AAC-ELD (Enhanced Low-Delay) is implemented.
  91. All references to SBR (Spectral Band Replication) are only applicable to HE-AAC
  92. and AAC-ELD configurations of the FDK library. All references to PS (Parametric
  93. Stereo) are only applicable to HE-AAC v2 decoder configuration of the library.
  94. \section DecoderBasics Decoder Basics
  95. This document can only give a rough overview about the ISO/MPEG-2, ISO/MPEG-4
  96. AAC audio and MPEG-D USAC coding standards. To understand all details referenced
  97. in this document, you are encouraged to read the following documents.
  98. - ISO/IEC 13818-7 (MPEG-2 AAC) Standard, defines the syntax of MPEG-2 AAC audio
  99. bitstreams.
  100. - ISO/IEC 14496-3 (MPEG-4 AAC, subpart 1 and 4) Standard, defines the syntax of
  101. MPEG-4 AAC audio bitstreams.
  102. - ISO/IEC 23003-3 (MPEG-D USAC), defines MPEG-D USAC unified speech and audio
  103. codec.
  104. - Lutzky, Schuller, Gayer, Krämer, Wabnik, "A guideline to audio codec
  105. delay", 116th AES Convention, May 8, 2004
  106. In short, MPEG Advanced Audio Coding is based on a time-to-frequency mapping of
  107. the signal. The signal is partitioned into overlapping time portions and
  108. transformed into frequency domain. The spectral components are then quantized
  109. and coded using a highly efficient coding scheme.\n Encoded MPEG-2 and MPEG-4
  110. AAC audio bitstreams are composed of frames. Contrary to MPEG-1/2 Layer-3 (mp3),
  111. the length of individual frames is not restricted to a fixed number of bytes,
  112. but can take any length between 1 and 768 bytes.
  113. In addition to the above mentioned frequency domain coding mode, MPEG-D USAC
  114. also employs a time domain Algebraic Code-Excited Linear Prediction (ACELP)
  115. speech coder core. This operating mode is selected by the encoder in order to
  116. achieve the optimum audio quality for different content type. Several
  117. enhancements allow achieving higher quality at lower bit rates compared to
  118. MPEG-4 HE-AAC.
  119. \page LIBUSE Library Usage
  120. \section InterfaceDescritpion API Description
  121. All API header files are located in the folder /include of the release package.
  122. The contents of each file is described in detail in this document. All header
  123. files are provided for usage in specific C/C++ programs. The main AAC decoder
  124. library API functions are located in aacdecoder_lib.h header file.
  125. \section Calling_Sequence Calling Sequence
  126. The following sequence is necessary for proper decoding of ISO/MPEG-2/4 AAC,
  127. HE-AAC v2, or MPEG-D USAC bitstreams. In the following description, input stream
  128. read and output write function details are left out, since they may be
  129. implemented in a variety of configurations depending on the user's specific
  130. requirements.
  131. -# Call aacDecoder_Open() to open and retrieve a handle to a new AAC decoder
  132. instance. \code aacDecoderInfo = aacDecoder_Open(transportType, nrOfLayers);
  133. \endcode
  134. -# If out-of-band config data (Audio Specific Config (ASC) or Stream Mux Config
  135. (SMC)) is available, call aacDecoder_ConfigRaw() to pass this data to the
  136. decoder before beginning the decoding process. If this data is not available in
  137. advance, the decoder will configure itself while decoding, during the
  138. aacDecoder_DecodeFrame() function call.
  139. -# Begin decoding loop.
  140. \code
  141. do {
  142. \endcode
  143. -# Read data from bitstream file or stream buffer in to the driver program
  144. working memory (a client-supplied input buffer "inBuffer" in framework). This
  145. buffer will be used to load AAC bitstream data to the decoder. Only when all
  146. data in this buffer has been processed will the decoder signal an empty buffer.
  147. -# Call aacDecoder_Fill() to fill the decoder's internal bitstream input buffer
  148. with the client-supplied bitstream input buffer. Note, if the data loaded in to
  149. the internal buffer is not sufficient to decode a frame,
  150. aacDecoder_DecodeFrame() will return ::AAC_DEC_NOT_ENOUGH_BITS until a
  151. sufficient amount of data is loaded in to the internal buffer. For streaming
  152. formats (ADTS, LOAS), it is acceptable to load more than one frame to the
  153. decoder. However, for packed based formats, only one frame may be loaded to the
  154. decoder per aacDecoder_DecodeFrame() call. For least amount of communication
  155. delay, fill and decode should be performed on a frame by frame basis. \code
  156. ErrorStatus = aacDecoder_Fill(aacDecoderInfo, inBuffer, bytesRead,
  157. bytesValid); \endcode
  158. -# Call aacDecoder_DecodeFrame(). This function decodes one frame and writes
  159. decoded PCM audio data to a client-supplied buffer. It is the client's
  160. responsibility to allocate a buffer which is large enough to hold the decoded
  161. output data. \code ErrorStatus = aacDecoder_DecodeFrame(aacDecoderInfo,
  162. TimeData, OUT_BUF_SIZE, flags); \endcode If the bitstream configuration (number
  163. of channels, sample rate, frame size) is not known a priori, you may call
  164. aacDecoder_GetStreamInfo() to retrieve a structure that contains this
  165. information. You may use this data to initialize an audio output device. \code
  166. p_si = aacDecoder_GetStreamInfo(aacDecoderInfo);
  167. \endcode
  168. -# Repeat steps 5 to 7 until no data is available to decode any more, or in case
  169. of error. \code } while (bytesRead[0] > 0 || doFlush || doBsFlush ||
  170. forceContinue); \endcode
  171. -# Call aacDecoder_Close() to de-allocate all AAC decoder and transport layer
  172. structures. \code aacDecoder_Close(aacDecoderInfo); \endcode
  173. \image latex decode.png "Decode calling sequence" width=11cm
  174. \image latex change_source.png "Change data source sequence" width=5cm
  175. \image latex conceal.png "Error concealment sequence" width=14cm
  176. \subsection Error_Concealment_Sequence Error Concealment Sequence
  177. There are different strategies to handle bit stream errors. Depending on the
  178. system properties the product designer might choose to take different actions in
  179. case a bit error occurs. In many cases the decoder might be able to do
  180. reasonable error concealment without the need of any additional actions from the
  181. system. But in some cases its not even possible to know how many decoded PCM
  182. output samples are required to fill the gap due to the data error, then the
  183. software surrounding the decoder must deal with the situation. The most simple
  184. way would be to just stop audio playback and resume once enough bit stream data
  185. and/or buffered output samples are available. More sophisticated designs might
  186. also be able to deal with sender/receiver clock drifts or data drop outs by
  187. using a closed loop control of FIFO fulness levels. The chosen strategy depends
  188. on the final product requirements.
  189. The error concealment sequence diagram illustrates the general execution paths
  190. for error handling.
  191. The macro IS_OUTPUT_VALID(err) can be used to identify if the audio output
  192. buffer contains valid audio either from error free bit stream data or successful
  193. error concealment. In case the result is false, the decoder output buffer does
  194. not contain meaningful audio samples and should not be passed to any output as
  195. it is. Most likely in case that a continuous audio output PCM stream is
  196. required, the output buffer must be filled with audio data from the calling
  197. framework. This might be e.g. an appropriate number of samples all zero.
  198. If error code ::AAC_DEC_TRANSPORT_SYNC_ERROR is returned by the decoder, under
  199. some particular conditions it is possible to estimate lost frames due to the bit
  200. stream error. In that case the bit stream is required to have a constant
  201. bitrate, and compatible transport type. Audio samples for the lost frames can be
  202. obtained by calling aacDecoder_DecodeFrame() with flag ::AACDEC_CONCEAL set
  203. n-times where n is the count of lost frames. Please note that the decoder has to
  204. have encountered valid configuration data at least once to be able to generate
  205. concealed data, because at the minimum the sampling rate, frame size and amount
  206. of audio channels needs to be known.
  207. If it is not possible to get an estimation of lost frames then a constant
  208. fullness of the audio output buffer can be achieved by implementing different
  209. FIFO control techniques e.g. just stop taking of samples from the buffer to
  210. avoid underflow or stop filling new data to the buffer to avoid overflow. But
  211. this techniques are out of scope of this document.
  212. For a detailed description of a specific error code please refer also to
  213. ::AAC_DECODER_ERROR.
  214. \section BufferSystem Buffer System
  215. There are three main buffers in an AAC decoder application. One external input
  216. buffer to hold bitstream data from file I/O or elsewhere, one decoder-internal
  217. input buffer, and one to hold the decoded output PCM sample data. In resource
  218. limited applications, the output buffer may be reused as an external input
  219. buffer prior to the subsequence aacDecoder_Fill() function call.
  220. To feed the data to the decoder-internal input buffer, use the
  221. function aacDecoder_Fill(). This function returns important information
  222. regarding the number of bytes in the external input buffer that have not yet
  223. been copied into the internal input buffer (variable bytesValid). Once the
  224. external buffer has been fully copied, it can be completely re-filled again. In
  225. case you wish to refill the buffer while there are unprocessed bytes (bytesValid
  226. is unequal 0), you should preserve the unconsumed data. However, we recommend to
  227. refill the buffer only when bytesValid returns 0.
  228. The bytesValid parameter is an input and output parameter to the FDK decoder. As
  229. an input, it signals how many valid bytes are available in the external buffer.
  230. After consumption of the external buffer using aacDecoder_Fill() function, the
  231. bytesValid parameter indicates if any of the bytes in the external buffer were
  232. not consumed.
  233. \image latex dec_buffer.png "Life cycle of the external input buffer" width=9cm
  234. \page OutputFormat Decoder audio output
  235. \section OutputFormatObtaining Obtaining channel mapping information
  236. The decoded audio output format is indicated by a set of variables of the
  237. CStreamInfo structure. While the struct members sampleRate, frameSize and
  238. numChannels might be self explanatory, pChannelType and pChannelIndices require
  239. some further explanation.
  240. These two arrays indicate the configuration of channel data within the output
  241. buffer. Both arrays have CStreamInfo::numChannels number of cells. Each cell of
  242. pChannelType indicates the channel type, which is described in the enum
  243. ::AUDIO_CHANNEL_TYPE (defined in FDK_audio.h). The cells of pChannelIndices
  244. indicate the sub index among the channels starting with 0 among channels of the
  245. same audio channel type.
  246. The indexing scheme is structured as defined in MPEG-2/4 Standards. Indices
  247. start from the front direction (a center channel if available, will always be
  248. index 0) and increment, starting with the left side, pairwise (e.g. L, R) and
  249. from front to back (Front L, Front R, Surround L, Surround R). For detailed
  250. explanation, please refer to ISO/IEC 13818-7:2005(E), chapter 8.5.3.2.
  251. In case a Program Config is included in the audio configuration, the channel
  252. mapping described within it will be adopted.
  253. The examples below explain these aspects in detail.
  254. \section OutputFormatChange Changing the audio output format
  255. For MPEG-4 audio the channel order can be changed at runtime through the
  256. parameter
  257. ::AAC_PCM_OUTPUT_CHANNEL_MAPPING. See the description of those
  258. parameters and the decoder library function aacDecoder_SetParam() for more
  259. detail.
  260. \section OutputFormatExample Channel mapping examples
  261. The following examples illustrate the location of individual audio samples in
  262. the audio buffer that is passed to aacDecoder_DecodeFrame() and the expected
  263. data in the CStreamInfo structure which can be obtained by calling
  264. aacDecoder_GetStreamInfo().
  265. \subsection ExamplesStereo Stereo
  266. In case of ::AAC_PCM_OUTPUT_CHANNEL_MAPPING set to 1,
  267. a AAC-LC bit stream which has channelConfiguration = 2 in its audio specific
  268. config would lead to the following values in CStreamInfo:
  269. CStreamInfo::numChannels = 2
  270. CStreamInfo::pChannelType = { ::ACT_FRONT, ::ACT_FRONT }
  271. CStreamInfo::pChannelIndices = { 0, 1 }
  272. The output buffer will be formatted as follows:
  273. \verbatim
  274. <left sample 0> <left sample 1> <left sample 2> ... <left sample N>
  275. <right sample 0> <right sample 1> <right sample 2> ... <right sample N>
  276. \endverbatim
  277. Where N equals to CStreamInfo::frameSize .
  278. \subsection ExamplesSurround Surround 5.1
  279. In case of ::AAC_PCM_OUTPUT_CHANNEL_MAPPING set to 1,
  280. a AAC-LC bit stream which has channelConfiguration = 6 in its audio specific
  281. config, would lead to the following values in CStreamInfo:
  282. CStreamInfo::numChannels = 6
  283. CStreamInfo::pChannelType = { ::ACT_FRONT, ::ACT_FRONT, ::ACT_FRONT, ::ACT_LFE,
  284. ::ACT_BACK, ::ACT_BACK }
  285. CStreamInfo::pChannelIndices = { 1, 2, 0, 0, 0, 1 }
  286. Since ::AAC_PCM_OUTPUT_CHANNEL_MAPPING is 1, WAV file channel ordering will be
  287. used. For a 5.1 channel scheme, thus the channels would be: front left, front
  288. right, center, LFE, surround left, surround right. Thus the third channel is the
  289. center channel, receiving the index 0. The other front channels are front left,
  290. front right being placed as first and second channels with indices 1 and 2
  291. correspondingly. There is only one LFE, placed as the fourth channel and index
  292. 0. Finally both surround channels get the type definition ACT_BACK, and the
  293. indices 0 and 1.
  294. The output buffer will be formatted as follows:
  295. \verbatim
  296. <front left sample 0> <front right sample 0>
  297. <center sample 0> <LFE sample 0>
  298. <surround left sample 0> <surround right sample 0>
  299. <front left sample 1> <front right sample 1>
  300. <center sample 1> <LFE sample 1>
  301. <surround left sample 1> <surround right sample 1>
  302. ...
  303. <front left sample N> <front right sample N>
  304. <center sample N> <LFE sample N>
  305. <surround left sample N> <surround right sample N>
  306. \endverbatim
  307. Where N equals to CStreamInfo::frameSize .
  308. \subsection ExamplesArib ARIB coding mode 2/1
  309. In case of ::AAC_PCM_OUTPUT_CHANNEL_MAPPING set to 1,
  310. in case of a ARIB bit stream using coding mode 2/1 as described in ARIB STD-B32
  311. Part 2 Version 2.1-E1, page 61, would lead to the following values in
  312. CStreamInfo:
  313. CStreamInfo::numChannels = 3
  314. CStreamInfo::pChannelType = { ::ACT_FRONT, ::ACT_FRONT, ::ACT_BACK }
  315. CStreamInfo::pChannelIndices = { 0, 1, 0 }
  316. The audio channels will be placed as follows in the audio output buffer:
  317. \verbatim
  318. <front left sample 0> <front right sample 0> <mid surround sample 0>
  319. <front left sample 1> <front right sample 1> <mid surround sample 1>
  320. ...
  321. <front left sample N> <front right sample N> <mid surround sample N>
  322. Where N equals to CStreamInfo::frameSize .
  323. \endverbatim
  324. */
  325. #include "machine_type.h"
  326. #include "FDK_audio.h"
  327. #define AACDECODER_LIB_VL0 3
  328. #define AACDECODER_LIB_VL1 2
  329. #define AACDECODER_LIB_VL2 0
  330. #include "genericStds.h"
  331. /**
  332. * \brief AAC decoder error codes.
  333. */
  334. typedef enum {
  335. AAC_DEC_OK =
  336. 0x0000, /*!< No error occurred. Output buffer is valid and error free. */
  337. AAC_DEC_OUT_OF_MEMORY =
  338. 0x0002, /*!< Heap returned NULL pointer. Output buffer is invalid. */
  339. AAC_DEC_UNKNOWN =
  340. 0x0005, /*!< Error condition is of unknown reason, or from a another
  341. module. Output buffer is invalid. */
  342. /* Synchronization errors. Output buffer is invalid. */
  343. aac_dec_sync_error_start = 0x1000,
  344. AAC_DEC_TRANSPORT_SYNC_ERROR = 0x1001, /*!< The transport decoder had
  345. synchronization problems. Do not
  346. exit decoding. Just feed new
  347. bitstream data. */
  348. AAC_DEC_NOT_ENOUGH_BITS = 0x1002, /*!< The input buffer ran out of bits. */
  349. aac_dec_sync_error_end = 0x1FFF,
  350. /* Initialization errors. Output buffer is invalid. */
  351. aac_dec_init_error_start = 0x2000,
  352. AAC_DEC_INVALID_HANDLE =
  353. 0x2001, /*!< The handle passed to the function call was invalid (NULL). */
  354. AAC_DEC_UNSUPPORTED_AOT =
  355. 0x2002, /*!< The AOT found in the configuration is not supported. */
  356. AAC_DEC_UNSUPPORTED_FORMAT =
  357. 0x2003, /*!< The bitstream format is not supported. */
  358. AAC_DEC_UNSUPPORTED_ER_FORMAT =
  359. 0x2004, /*!< The error resilience tool format is not supported. */
  360. AAC_DEC_UNSUPPORTED_EPCONFIG =
  361. 0x2005, /*!< The error protection format is not supported. */
  362. AAC_DEC_UNSUPPORTED_MULTILAYER =
  363. 0x2006, /*!< More than one layer for AAC scalable is not supported. */
  364. AAC_DEC_UNSUPPORTED_CHANNELCONFIG =
  365. 0x2007, /*!< The channel configuration (either number or arrangement) is
  366. not supported. */
  367. AAC_DEC_UNSUPPORTED_SAMPLINGRATE = 0x2008, /*!< The sample rate specified in
  368. the configuration is not
  369. supported. */
  370. AAC_DEC_INVALID_SBR_CONFIG =
  371. 0x2009, /*!< The SBR configuration is not supported. */
  372. AAC_DEC_SET_PARAM_FAIL = 0x200A, /*!< The parameter could not be set. Either
  373. the value was out of range or the
  374. parameter does not exist. */
  375. AAC_DEC_NEED_TO_RESTART = 0x200B, /*!< The decoder needs to be restarted,
  376. since the required configuration change
  377. cannot be performed. */
  378. AAC_DEC_OUTPUT_BUFFER_TOO_SMALL =
  379. 0x200C, /*!< The provided output buffer is too small. */
  380. aac_dec_init_error_end = 0x2FFF,
  381. /* Decode errors. Output buffer is valid but concealed. */
  382. aac_dec_decode_error_start = 0x4000,
  383. AAC_DEC_TRANSPORT_ERROR =
  384. 0x4001, /*!< The transport decoder encountered an unexpected error. */
  385. AAC_DEC_PARSE_ERROR = 0x4002, /*!< Error while parsing the bitstream. Most
  386. probably it is corrupted, or the system
  387. crashed. */
  388. AAC_DEC_UNSUPPORTED_EXTENSION_PAYLOAD =
  389. 0x4003, /*!< Error while parsing the extension payload of the bitstream.
  390. The extension payload type found is not supported. */
  391. AAC_DEC_DECODE_FRAME_ERROR = 0x4004, /*!< The parsed bitstream value is out of
  392. range. Most probably the bitstream is
  393. corrupt, or the system crashed. */
  394. AAC_DEC_CRC_ERROR = 0x4005, /*!< The embedded CRC did not match. */
  395. AAC_DEC_INVALID_CODE_BOOK = 0x4006, /*!< An invalid codebook was signaled.
  396. Most probably the bitstream is corrupt,
  397. or the system crashed. */
  398. AAC_DEC_UNSUPPORTED_PREDICTION =
  399. 0x4007, /*!< Predictor found, but not supported in the AAC Low Complexity
  400. profile. Most probably the bitstream is corrupt, or has a wrong
  401. format. */
  402. AAC_DEC_UNSUPPORTED_CCE = 0x4008, /*!< A CCE element was found which is not
  403. supported. Most probably the bitstream is
  404. corrupt, or has a wrong format. */
  405. AAC_DEC_UNSUPPORTED_LFE = 0x4009, /*!< A LFE element was found which is not
  406. supported. Most probably the bitstream is
  407. corrupt, or has a wrong format. */
  408. AAC_DEC_UNSUPPORTED_GAIN_CONTROL_DATA =
  409. 0x400A, /*!< Gain control data found but not supported. Most probably the
  410. bitstream is corrupt, or has a wrong format. */
  411. AAC_DEC_UNSUPPORTED_SBA =
  412. 0x400B, /*!< SBA found, but currently not supported in the BSAC profile.
  413. */
  414. AAC_DEC_TNS_READ_ERROR = 0x400C, /*!< Error while reading TNS data. Most
  415. probably the bitstream is corrupt or the
  416. system crashed. */
  417. AAC_DEC_RVLC_ERROR =
  418. 0x400D, /*!< Error while decoding error resilient data. */
  419. aac_dec_decode_error_end = 0x4FFF,
  420. /* Ancillary data errors. Output buffer is valid. */
  421. aac_dec_anc_data_error_start = 0x8000,
  422. AAC_DEC_ANC_DATA_ERROR =
  423. 0x8001, /*!< Non severe error concerning the ancillary data handling. */
  424. AAC_DEC_TOO_SMALL_ANC_BUFFER = 0x8002, /*!< The registered ancillary data
  425. buffer is too small to receive the
  426. parsed data. */
  427. AAC_DEC_TOO_MANY_ANC_ELEMENTS = 0x8003, /*!< More than the allowed number of
  428. ancillary data elements should be
  429. written to buffer. */
  430. aac_dec_anc_data_error_end = 0x8FFF
  431. } AAC_DECODER_ERROR;
  432. /** Macro to identify initialization errors. Output buffer is invalid. */
  433. #define IS_INIT_ERROR(err) \
  434. ((((err) >= aac_dec_init_error_start) && ((err) <= aac_dec_init_error_end)) \
  435. ? 1 \
  436. : 0)
  437. /** Macro to identify decode errors. Output buffer is valid but concealed. */
  438. #define IS_DECODE_ERROR(err) \
  439. ((((err) >= aac_dec_decode_error_start) && \
  440. ((err) <= aac_dec_decode_error_end)) \
  441. ? 1 \
  442. : 0)
  443. /**
  444. * Macro to identify if the audio output buffer contains valid samples after
  445. * calling aacDecoder_DecodeFrame(). Output buffer is valid but can be
  446. * concealed.
  447. */
  448. #define IS_OUTPUT_VALID(err) (((err) == AAC_DEC_OK) || IS_DECODE_ERROR(err))
  449. /*! \enum AAC_MD_PROFILE
  450. * \brief The available metadata profiles which are mostly related to downmixing. The values define the arguments
  451. * for the use with parameter ::AAC_METADATA_PROFILE.
  452. */
  453. typedef enum {
  454. AAC_MD_PROFILE_MPEG_STANDARD =
  455. 0, /*!< The standard profile creates a mixdown signal based on the
  456. advanced downmix metadata (from a DSE). The equations and default
  457. values are defined in ISO/IEC 14496:3 Ammendment 4. Any other
  458. (legacy) downmix metadata will be ignored. No other parameter will
  459. be modified. */
  460. AAC_MD_PROFILE_MPEG_LEGACY =
  461. 1, /*!< This profile behaves identical to the standard profile if advanced
  462. downmix metadata (from a DSE) is available. If not, the
  463. matrix_mixdown information embedded in the program configuration
  464. element (PCE) will be applied. If neither is the case, the module
  465. creates a mixdown using the default coefficients as defined in
  466. ISO/IEC 14496:3 AMD 4. The profile can be used to support legacy
  467. digital TV (e.g. DVB) streams. */
  468. AAC_MD_PROFILE_MPEG_LEGACY_PRIO =
  469. 2, /*!< Similar to the ::AAC_MD_PROFILE_MPEG_LEGACY profile but if both
  470. the advanced (ISO/IEC 14496:3 AMD 4) and the legacy (PCE) MPEG
  471. downmix metadata are available the latter will be applied.
  472. */
  473. AAC_MD_PROFILE_ARIB_JAPAN =
  474. 3 /*!< Downmix creation as described in ABNT NBR 15602-2. But if advanced
  475. downmix metadata (ISO/IEC 14496:3 AMD 4) is available it will be
  476. preferred because of the higher resolutions. In addition the
  477. metadata expiry time will be set to the value defined in the ARIB
  478. standard (see ::AAC_METADATA_EXPIRY_TIME).
  479. */
  480. } AAC_MD_PROFILE;
  481. /*! \enum AAC_DRC_DEFAULT_PRESENTATION_MODE_OPTIONS
  482. * \brief Options for handling of DRC parameters, if presentation mode is not indicated in bitstream
  483. */
  484. typedef enum {
  485. AAC_DRC_PARAMETER_HANDLING_DISABLED = -1, /*!< DRC parameter handling
  486. disabled, all parameters are
  487. applied as requested. */
  488. AAC_DRC_PARAMETER_HANDLING_ENABLED =
  489. 0, /*!< Apply changes to requested DRC parameters to prevent clipping. */
  490. AAC_DRC_PRESENTATION_MODE_1_DEFAULT =
  491. 1, /*!< Use DRC presentation mode 1 as default (e.g. for Nordig) */
  492. AAC_DRC_PRESENTATION_MODE_2_DEFAULT =
  493. 2 /*!< Use DRC presentation mode 2 as default (e.g. for DTG DBook) */
  494. } AAC_DRC_DEFAULT_PRESENTATION_MODE_OPTIONS;
  495. /**
  496. * \brief AAC decoder setting parameters
  497. */
  498. typedef enum {
  499. AAC_PCM_DUAL_CHANNEL_OUTPUT_MODE =
  500. 0x0002, /*!< Defines how the decoder processes two channel signals: \n
  501. 0: Leave both signals as they are (default). \n
  502. 1: Create a dual mono output signal from channel 1. \n
  503. 2: Create a dual mono output signal from channel 2. \n
  504. 3: Create a dual mono output signal by mixing both channels
  505. (L' = R' = 0.5*Ch1 + 0.5*Ch2). */
  506. AAC_PCM_OUTPUT_CHANNEL_MAPPING =
  507. 0x0003, /*!< Output buffer channel ordering. 0: MPEG PCE style order, 1:
  508. WAV file channel order (default). */
  509. AAC_PCM_LIMITER_ENABLE =
  510. 0x0004, /*!< Enable signal level limiting. \n
  511. -1: Auto-config. Enable limiter for all
  512. non-lowdelay configurations by default. \n
  513. 0: Disable limiter in general. \n
  514. 1: Enable limiter always.
  515. It is recommended to call the decoder
  516. with a AACDEC_CLRHIST flag to reset all
  517. states when the limiter switch is changed
  518. explicitly. */
  519. AAC_PCM_LIMITER_ATTACK_TIME = 0x0005, /*!< Signal level limiting attack time
  520. in ms. Default configuration is 15
  521. ms. Adjustable range from 1 ms to 15
  522. ms. */
  523. AAC_PCM_LIMITER_RELEAS_TIME = 0x0006, /*!< Signal level limiting release time
  524. in ms. Default configuration is 50
  525. ms. Adjustable time must be larger
  526. than 0 ms. */
  527. AAC_PCM_MIN_OUTPUT_CHANNELS =
  528. 0x0011, /*!< Minimum number of PCM output channels. If higher than the
  529. number of encoded audio channels, a simple channel extension is
  530. applied (see note 4 for exceptions). \n -1, 0: Disable channel
  531. extension feature. The decoder output contains the same number
  532. of channels as the encoded bitstream. \n 1: This value is
  533. currently needed only together with the mix-down feature. See
  534. ::AAC_PCM_MAX_OUTPUT_CHANNELS and note 2 below. \n
  535. 2: Encoded mono signals will be duplicated to achieve a
  536. 2/0/0.0 channel output configuration. \n 6: The decoder
  537. tries to reorder encoded signals with less than six channels to
  538. achieve a 3/0/2.1 channel output signal. Missing channels will
  539. be filled with a zero signal. If reordering is not possible the
  540. empty channels will simply be appended. Only available if
  541. instance is configured to support multichannel output. \n 8:
  542. The decoder tries to reorder encoded signals with less than
  543. eight channels to achieve a 3/0/4.1 channel output signal.
  544. Missing channels will be filled with a zero signal. If
  545. reordering is not possible the empty channels will simply be
  546. appended. Only available if instance is configured to
  547. support multichannel output.\n NOTE: \n
  548. 1. The channel signaling (CStreamInfo::pChannelType and
  549. CStreamInfo::pChannelIndices) will not be modified. Added empty
  550. channels will be signaled with channel type
  551. AUDIO_CHANNEL_TYPE::ACT_NONE. \n
  552. 2. If the parameter value is greater than that of
  553. ::AAC_PCM_MAX_OUTPUT_CHANNELS both will be set to the same
  554. value. \n
  555. 3. This parameter will be ignored if the number of encoded
  556. audio channels is greater than 8. */
  557. AAC_PCM_MAX_OUTPUT_CHANNELS =
  558. 0x0012, /*!< Maximum number of PCM output channels. If lower than the
  559. number of encoded audio channels, downmixing is applied
  560. accordingly (see note 5 for exceptions). If dedicated metadata
  561. is available in the stream it will be used to achieve better
  562. mixing results. \n -1, 0: Disable downmixing feature. The
  563. decoder output contains the same number of channels as the
  564. encoded bitstream. \n 1: All encoded audio configurations
  565. with more than one channel will be mixed down to one mono
  566. output signal. \n 2: The decoder performs a stereo mix-down
  567. if the number encoded audio channels is greater than two. \n 6:
  568. If the number of encoded audio channels is greater than six the
  569. decoder performs a mix-down to meet the target output
  570. configuration of 3/0/2.1 channels. Only available if instance
  571. is configured to support multichannel output. \n 8: This
  572. value is currently needed only together with the channel
  573. extension feature. See ::AAC_PCM_MIN_OUTPUT_CHANNELS and note 2
  574. below. Only available if instance is configured to support
  575. multichannel output. \n NOTE: \n
  576. 1. Down-mixing of any seven or eight channel configuration
  577. not defined in ISO/IEC 14496-3 PDAM 4 is not supported by this
  578. software version. \n
  579. 2. If the parameter value is greater than zero but smaller
  580. than ::AAC_PCM_MIN_OUTPUT_CHANNELS both will be set to same
  581. value. \n
  582. 3. This parameter will be ignored if the number of encoded
  583. audio channels is greater than 8. */
  584. AAC_METADATA_PROFILE =
  585. 0x0020, /*!< See ::AAC_MD_PROFILE for all available values. */
  586. AAC_METADATA_EXPIRY_TIME = 0x0021, /*!< Defines the time in ms after which all
  587. the bitstream associated meta-data (DRC,
  588. downmix coefficients, ...) will be reset
  589. to default if no update has been
  590. received. Negative values disable the
  591. feature. */
  592. AAC_CONCEAL_METHOD = 0x0100, /*!< Error concealment: Processing method. \n
  593. 0: Spectral muting. \n
  594. 1: Noise substitution (see ::CONCEAL_NOISE).
  595. \n 2: Energy interpolation (adds additional
  596. signal delay of one frame, see
  597. ::CONCEAL_INTER. only some AOTs are
  598. supported). \n */
  599. AAC_DRC_BOOST_FACTOR =
  600. 0x0200, /*!< MPEG-4 / MPEG-D Dynamic Range Control (DRC): Scaling factor
  601. for boosting gain values. Defines how the boosting DRC factors
  602. (conveyed in the bitstream) will be applied to the decoded
  603. signal. The valid values range from 0 (don't apply boost
  604. factors) to 127 (fully apply boost factors). Default value is 0
  605. for MPEG-4 DRC and 127 for MPEG-D DRC. */
  606. AAC_DRC_ATTENUATION_FACTOR = 0x0201, /*!< MPEG-4 / MPEG-D DRC: Scaling factor
  607. for attenuating gain values. Same as
  608. ::AAC_DRC_BOOST_FACTOR but for
  609. attenuating DRC factors. */
  610. AAC_DRC_REFERENCE_LEVEL =
  611. 0x0202, /*!< MPEG-4 / MPEG-D DRC: Target reference level / decoder target
  612. loudness.\n Defines the level below full-scale (quantized in
  613. steps of 0.25dB) to which the output audio signal will be
  614. normalized to by the DRC module.\n The parameter controls
  615. loudness normalization for both MPEG-4 DRC and MPEG-D DRC. The
  616. valid values range from 40 (-10 dBFS) to 127 (-31.75 dBFS).\n
  617. Example values:\n
  618. 124 (-31 dBFS) for audio/video receivers (AVR) or other
  619. devices allowing audio playback with high dynamic range,\n 96
  620. (-24 dBFS) for TV sets or equivalent devices (default),\n 64
  621. (-16 dBFS) for mobile devices where the dynamic range of audio
  622. playback is restricted.\n Any value smaller than 0 switches off
  623. loudness normalization and MPEG-4 DRC. */
  624. AAC_DRC_HEAVY_COMPRESSION =
  625. 0x0203, /*!< MPEG-4 DRC: En-/Disable DVB specific heavy compression (aka
  626. RF mode). If set to 1, the decoder will apply the compression
  627. values from the DVB specific ancillary data field. At the same
  628. time the MPEG-4 Dynamic Range Control tool will be disabled. By
  629. default, heavy compression is disabled. */
  630. AAC_DRC_DEFAULT_PRESENTATION_MODE =
  631. 0x0204, /*!< MPEG-4 DRC: Default presentation mode (DRC parameter
  632. handling). \n Defines the handling of the DRC parameters boost
  633. factor, attenuation factor and heavy compression, if no
  634. presentation mode is indicated in the bitstream.\n For options,
  635. see ::AAC_DRC_DEFAULT_PRESENTATION_MODE_OPTIONS.\n Default:
  636. ::AAC_DRC_PARAMETER_HANDLING_DISABLED */
  637. AAC_DRC_ENC_TARGET_LEVEL =
  638. 0x0205, /*!< MPEG-4 DRC: Encoder target level for light (i.e. not heavy)
  639. compression.\n If known, this declares the target reference
  640. level that was assumed at the encoder for calculation of
  641. limiting gains. The valid values range from 0 (full-scale) to
  642. 127 (31.75 dB below full-scale). This parameter is used only
  643. with ::AAC_DRC_PARAMETER_HANDLING_ENABLED and ignored
  644. otherwise.\n Default: 127 (worst-case assumption).\n */
  645. AAC_UNIDRC_SET_EFFECT = 0x0206, /*!< MPEG-D DRC: Request a DRC effect type for
  646. selection of a DRC set.\n Supported indices
  647. are:\n -1: DRC off. Completely disables
  648. MPEG-D DRC.\n 0: None (default). Disables
  649. MPEG-D DRC, but automatically enables DRC
  650. if necessary to prevent clipping.\n 1: Late
  651. night\n 2: Noisy environment\n 3: Limited
  652. playback range\n 4: Low playback level\n 5:
  653. Dialog enhancement\n 6: General
  654. compression. Used for generally enabling
  655. MPEG-D DRC without particular request.\n */
  656. AAC_UNIDRC_ALBUM_MODE =
  657. 0x0207, /*!< MPEG-D DRC: Enable album mode. 0: Disabled (default), 1:
  658. Enabled.\n Disabled album mode leads to application of gain
  659. sequences for fading in and out, if provided in the
  660. bitstream.\n Enabled album mode makes use of dedicated album
  661. loudness information, if provided in the bitstream.\n */
  662. AAC_QMF_LOWPOWER =
  663. 0x0300, /*!< Quadrature Mirror Filter (QMF) Bank processing mode. \n
  664. -1: Use internal default. \n
  665. 0: Use complex QMF data mode. \n
  666. 1: Use real (low power) QMF data mode. \n */
  667. AAC_TPDEC_CLEAR_BUFFER =
  668. 0x0603 /*!< Clear internal bit stream buffer of transport layers. The
  669. decoder will start decoding at new data passed after this event
  670. and any previous data is discarded. */
  671. } AACDEC_PARAM;
  672. /**
  673. * \brief This structure gives information about the currently decoded audio
  674. * data. All fields are read-only.
  675. */
  676. typedef struct {
  677. /* These five members are the only really relevant ones for the user. */
  678. INT sampleRate; /*!< The sample rate in Hz of the decoded PCM audio signal. */
  679. INT frameSize; /*!< The frame size of the decoded PCM audio signal. \n
  680. Typically this is: \n
  681. 1024 or 960 for AAC-LC \n
  682. 2048 or 1920 for HE-AAC (v2) \n
  683. 512 or 480 for AAC-LD and AAC-ELD \n
  684. 768, 1024, 2048 or 4096 for USAC */
  685. INT numChannels; /*!< The number of output audio channels before the rendering
  686. module, i.e. the original channel configuration. */
  687. AUDIO_CHANNEL_TYPE
  688. *pChannelType; /*!< Audio channel type of each output audio channel. */
  689. UCHAR *pChannelIndices; /*!< Audio channel index for each output audio
  690. channel. See ISO/IEC 13818-7:2005(E), 8.5.3.2
  691. Explicit channel mapping using a
  692. program_config_element() */
  693. /* Decoder internal members. */
  694. INT aacSampleRate; /*!< Sampling rate in Hz without SBR (from configuration
  695. info) divided by a (ELD) downscale factor if present. */
  696. INT profile; /*!< MPEG-2 profile (from file header) (-1: not applicable (e. g.
  697. MPEG-4)). */
  698. AUDIO_OBJECT_TYPE
  699. aot; /*!< Audio Object Type (from ASC): is set to the appropriate value
  700. for MPEG-2 bitstreams (e. g. 2 for AAC-LC). */
  701. INT channelConfig; /*!< Channel configuration (0: PCE defined, 1: mono, 2:
  702. stereo, ... */
  703. INT bitRate; /*!< Instantaneous bit rate. */
  704. INT aacSamplesPerFrame; /*!< Samples per frame for the AAC core (from ASC)
  705. divided by a (ELD) downscale factor if present. \n
  706. Typically this is (with a downscale factor of 1):
  707. \n 1024 or 960 for AAC-LC \n 512 or 480 for
  708. AAC-LD and AAC-ELD */
  709. INT aacNumChannels; /*!< The number of audio channels after AAC core
  710. processing (before PS or MPS processing). CAUTION: This
  711. are not the final number of output channels! */
  712. AUDIO_OBJECT_TYPE extAot; /*!< Extension Audio Object Type (from ASC) */
  713. INT extSamplingRate; /*!< Extension sampling rate in Hz (from ASC) divided by
  714. a (ELD) downscale factor if present. */
  715. UINT outputDelay; /*!< The number of samples the output is additionally
  716. delayed by.the decoder. */
  717. UINT flags; /*!< Copy of internal flags. Only to be written by the decoder,
  718. and only to be read externally. */
  719. SCHAR epConfig; /*!< epConfig level (from ASC): only level 0 supported, -1
  720. means no ER (e. g. AOT=2, MPEG-2 AAC, etc.) */
  721. /* Statistics */
  722. INT numLostAccessUnits; /*!< This integer will reflect the estimated amount of
  723. lost access units in case aacDecoder_DecodeFrame()
  724. returns AAC_DEC_TRANSPORT_SYNC_ERROR. It will be
  725. < 0 if the estimation failed. */
  726. INT64 numTotalBytes; /*!< This is the number of total bytes that have passed
  727. through the decoder. */
  728. INT64
  729. numBadBytes; /*!< This is the number of total bytes that were considered
  730. with errors from numTotalBytes. */
  731. INT64
  732. numTotalAccessUnits; /*!< This is the number of total access units that
  733. have passed through the decoder. */
  734. INT64 numBadAccessUnits; /*!< This is the number of total access units that
  735. were considered with errors from numTotalBytes. */
  736. /* Metadata */
  737. SCHAR drcProgRefLev; /*!< DRC program reference level. Defines the reference
  738. level below full-scale. It is quantized in steps of
  739. 0.25dB. The valid values range from 0 (0 dBFS) to 127
  740. (-31.75 dBFS). It is used to reflect the average
  741. loudness of the audio in LKFS according to ITU-R BS
  742. 1770. If no level has been found in the bitstream the
  743. value is -1. */
  744. SCHAR
  745. drcPresMode; /*!< DRC presentation mode. According to ETSI TS 101 154,
  746. this field indicates whether light (MPEG-4 Dynamic Range
  747. Control tool) or heavy compression (DVB heavy
  748. compression) dynamic range control shall take priority
  749. on the outputs. For details, see ETSI TS 101 154, table
  750. C.33. Possible values are: \n -1: No corresponding
  751. metadata found in the bitstream \n 0: DRC presentation
  752. mode not indicated \n 1: DRC presentation mode 1 \n 2:
  753. DRC presentation mode 2 \n 3: Reserved */
  754. INT outputLoudness; /*!< Audio output loudness in steps of -0.25 dB. Range: 0
  755. (0 dBFS) to 231 (-57.75 dBFS).\n A value of -1
  756. indicates that no loudness metadata is present.\n If
  757. loudness normalization is active, the value corresponds
  758. to the target loudness value set with
  759. ::AAC_DRC_REFERENCE_LEVEL.\n If loudness normalization
  760. is not active, the output loudness value corresponds to
  761. the loudness metadata given in the bitstream.\n
  762. Loudness metadata can originate from MPEG-4 DRC or
  763. MPEG-D DRC. */
  764. } CStreamInfo;
  765. typedef struct AAC_DECODER_INSTANCE
  766. *HANDLE_AACDECODER; /*!< Pointer to a AAC decoder instance. */
  767. #ifdef __cplusplus
  768. extern "C" {
  769. #endif
  770. /**
  771. * \brief Initialize ancillary data buffer.
  772. *
  773. * \param self AAC decoder handle.
  774. * \param buffer Pointer to (external) ancillary data buffer.
  775. * \param size Size of the buffer pointed to by buffer.
  776. * \return Error code.
  777. */
  778. LINKSPEC_H AAC_DECODER_ERROR aacDecoder_AncDataInit(HANDLE_AACDECODER self,
  779. UCHAR *buffer, int size);
  780. /**
  781. * \brief Get one ancillary data element.
  782. *
  783. * \param self AAC decoder handle.
  784. * \param index Index of the ancillary data element to get.
  785. * \param ptr Pointer to a buffer receiving a pointer to the requested
  786. * ancillary data element.
  787. * \param size Pointer to a buffer receiving the length of the requested
  788. * ancillary data element.
  789. * \return Error code.
  790. */
  791. LINKSPEC_H AAC_DECODER_ERROR aacDecoder_AncDataGet(HANDLE_AACDECODER self,
  792. int index, UCHAR **ptr,
  793. int *size);
  794. /**
  795. * \brief Set one single decoder parameter.
  796. *
  797. * \param self AAC decoder handle.
  798. * \param param Parameter to be set.
  799. * \param value Parameter value.
  800. * \return Error code.
  801. */
  802. LINKSPEC_H AAC_DECODER_ERROR aacDecoder_SetParam(const HANDLE_AACDECODER self,
  803. const AACDEC_PARAM param,
  804. const INT value);
  805. /**
  806. * \brief Get free bytes inside decoder internal buffer.
  807. * \param self Handle of AAC decoder instance.
  808. * \param pFreeBytes Pointer to variable receiving amount of free bytes inside
  809. * decoder internal buffer.
  810. * \return Error code.
  811. */
  812. LINKSPEC_H AAC_DECODER_ERROR
  813. aacDecoder_GetFreeBytes(const HANDLE_AACDECODER self, UINT *pFreeBytes);
  814. /**
  815. * \brief Open an AAC decoder instance.
  816. * \param transportFmt The transport type to be used.
  817. * \param nrOfLayers Number of transport layers.
  818. * \return AAC decoder handle.
  819. */
  820. LINKSPEC_H HANDLE_AACDECODER aacDecoder_Open(TRANSPORT_TYPE transportFmt,
  821. UINT nrOfLayers);
  822. /**
  823. * \brief Explicitly configure the decoder by passing a raw AudioSpecificConfig
  824. * (ASC) or a StreamMuxConfig (SMC), contained in a binary buffer. This is
  825. * required for MPEG-4 and Raw Packets file format bitstreams as well as for
  826. * LATM bitstreams with no in-band SMC. If the transport format is LATM with or
  827. * without LOAS, configuration is assumed to be an SMC, for all other file
  828. * formats an ASC.
  829. *
  830. * \param self AAC decoder handle.
  831. * \param conf Pointer to an unsigned char buffer containing the binary
  832. * configuration buffer (either ASC or SMC).
  833. * \param length Length of the configuration buffer in bytes.
  834. * \return Error code.
  835. */
  836. LINKSPEC_H AAC_DECODER_ERROR aacDecoder_ConfigRaw(HANDLE_AACDECODER self,
  837. UCHAR *conf[],
  838. const UINT length[]);
  839. /**
  840. * \brief Submit raw ISO base media file format boxes to decoder for parsing
  841. * (only some box types are recognized).
  842. *
  843. * \param self AAC decoder handle.
  844. * \param buffer Pointer to an unsigned char buffer containing the binary box
  845. * data (including size and type, can be a sequence of multiple boxes).
  846. * \param length Length of the data in bytes.
  847. * \return Error code.
  848. */
  849. LINKSPEC_H AAC_DECODER_ERROR aacDecoder_RawISOBMFFData(HANDLE_AACDECODER self,
  850. UCHAR *buffer,
  851. UINT length);
  852. /**
  853. * \brief Fill AAC decoder's internal input buffer with bitstream data from the
  854. * external input buffer. The function only copies such data as long as the
  855. * decoder-internal input buffer is not full. So it grabs whatever it can from
  856. * pBuffer and returns information (bytesValid) so that at a subsequent call of
  857. * %aacDecoder_Fill(), the right position in pBuffer can be determined to grab
  858. * the next data.
  859. *
  860. * \param self AAC decoder handle.
  861. * \param pBuffer Pointer to external input buffer.
  862. * \param bufferSize Size of external input buffer. This argument is required
  863. * because decoder-internally we need the information to calculate the offset to
  864. * pBuffer, where the next available data is, which is then
  865. * fed into the decoder-internal buffer (as much as
  866. * possible). Our example framework implementation fills the
  867. * buffer at pBuffer again, once it contains no available valid bytes anymore
  868. * (meaning bytesValid equal 0).
  869. * \param bytesValid Number of bitstream bytes in the external bitstream buffer
  870. * that have not yet been copied into the decoder's internal bitstream buffer by
  871. * calling this function. The value is updated according to
  872. * the amount of newly copied bytes.
  873. * \return Error code.
  874. */
  875. LINKSPEC_H AAC_DECODER_ERROR aacDecoder_Fill(HANDLE_AACDECODER self,
  876. UCHAR *pBuffer[],
  877. const UINT bufferSize[],
  878. UINT *bytesValid);
  879. /** Flag for aacDecoder_DecodeFrame(): Trigger the built-in error concealment
  880. * module to generate a substitute signal for one lost frame. New input data
  881. * will not be considered.
  882. */
  883. #define AACDEC_CONCEAL 1
  884. /** Flag for aacDecoder_DecodeFrame(): Flush all filterbanks to get all delayed
  885. * audio without having new input data. Thus new input data will not be
  886. * considered.
  887. */
  888. #define AACDEC_FLUSH 2
  889. /** Flag for aacDecoder_DecodeFrame(): Signal an input bit stream data
  890. * discontinuity. Resync any internals as necessary.
  891. */
  892. #define AACDEC_INTR 4
  893. /** Flag for aacDecoder_DecodeFrame(): Clear all signal delay lines and history
  894. * buffers. CAUTION: This can cause discontinuities in the output signal.
  895. */
  896. #define AACDEC_CLRHIST 8
  897. /**
  898. * \brief Decode one audio frame
  899. *
  900. * \param self AAC decoder handle.
  901. * \param pTimeData Pointer to external output buffer where the decoded PCM
  902. * samples will be stored into.
  903. * \param timeDataSize Size of external output buffer in PCM samples.
  904. * \param flags Bit field with flags for the decoder: \n
  905. * (flags & AACDEC_CONCEAL) == 1: Do concealment. \n
  906. * (flags & AACDEC_FLUSH) == 2: Discard input data. Flush
  907. * filter banks (output delayed audio). \n (flags & AACDEC_INTR) == 4: Input
  908. * data is discontinuous. Resynchronize any internals as
  909. * necessary. \n (flags & AACDEC_CLRHIST) == 8: Clear all signal delay lines and
  910. * history buffers.
  911. * \return Error code.
  912. */
  913. LINKSPEC_H AAC_DECODER_ERROR aacDecoder_DecodeFrame(HANDLE_AACDECODER self,
  914. INT_PCM *pTimeData,
  915. const INT timeDataSize,
  916. const UINT flags);
  917. /**
  918. * \brief De-allocate all resources of an AAC decoder instance.
  919. *
  920. * \param self AAC decoder handle.
  921. * \return void.
  922. */
  923. LINKSPEC_H void aacDecoder_Close(HANDLE_AACDECODER self);
  924. /**
  925. * \brief Get CStreamInfo handle from decoder.
  926. *
  927. * \param self AAC decoder handle.
  928. * \return Reference to requested CStreamInfo.
  929. */
  930. LINKSPEC_H CStreamInfo *aacDecoder_GetStreamInfo(HANDLE_AACDECODER self);
  931. /**
  932. * \brief Get decoder library info.
  933. *
  934. * \param info Pointer to an allocated LIB_INFO structure.
  935. * \return 0 on success.
  936. */
  937. LINKSPEC_H INT aacDecoder_GetLibInfo(LIB_INFO *info);
  938. #ifdef __cplusplus
  939. }
  940. #endif
  941. #endif /* AACDECODER_LIB_H */