tpenc_lib.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /* -----------------------------------------------------------------------------------------------------------
  2. Software License for The Fraunhofer FDK AAC Codec Library for Android
  3. © Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V.
  4. All rights reserved.
  5. 1. INTRODUCTION
  6. The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software that implements
  7. the MPEG Advanced Audio Coding ("AAC") encoding and decoding scheme for digital audio.
  8. This FDK AAC Codec software is intended to be used on a wide variety of Android devices.
  9. AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient general perceptual
  10. audio codecs. AAC-ELD is considered the best-performing full-bandwidth communications codec by
  11. independent studies and is widely deployed. AAC has been standardized by ISO and IEC as part
  12. of the MPEG specifications.
  13. Patent licenses for necessary patent claims for the FDK AAC Codec (including those of Fraunhofer)
  14. may be obtained through Via Licensing (www.vialicensing.com) or through the respective patent owners
  15. individually for the purpose of encoding or decoding bit streams in products that are compliant with
  16. the ISO/IEC MPEG audio standards. Please note that most manufacturers of Android devices already license
  17. these patent claims through Via Licensing or directly from the patent owners, and therefore FDK AAC Codec
  18. software may already be covered under those patent licenses when it is used for those licensed purposes only.
  19. Commercially-licensed AAC software libraries, including floating-point versions with enhanced sound quality,
  20. are also available from Fraunhofer. Users are encouraged to check the Fraunhofer website for additional
  21. applications information and documentation.
  22. 2. COPYRIGHT LICENSE
  23. Redistribution and use in source and binary forms, with or without modification, are permitted without
  24. payment of copyright license fees provided that you satisfy the following conditions:
  25. You must retain the complete text of this software license in redistributions of the FDK AAC Codec or
  26. your modifications thereto in source code form.
  27. You must retain the complete text of this software license in the documentation and/or other materials
  28. provided with redistributions of the FDK AAC Codec or your modifications thereto in binary form.
  29. You must make available free of charge copies of the complete source code of the FDK AAC Codec and your
  30. modifications thereto to recipients of copies in binary form.
  31. The name of Fraunhofer may not be used to endorse or promote products derived from this library without
  32. prior written permission.
  33. You may not charge copyright license fees for anyone to use, copy or distribute the FDK AAC Codec
  34. software or your modifications thereto.
  35. Your modified versions of the FDK AAC Codec must carry prominent notices stating that you changed the software
  36. and the date of any change. For modified versions of the FDK AAC Codec, the term
  37. "Fraunhofer FDK AAC Codec Library for Android" must be replaced by the term
  38. "Third-Party Modified Version of the Fraunhofer FDK AAC Codec Library for Android."
  39. 3. NO PATENT LICENSE
  40. NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without limitation the patents of Fraunhofer,
  41. ARE GRANTED BY THIS SOFTWARE LICENSE. Fraunhofer provides no warranty of patent non-infringement with
  42. respect to this software.
  43. You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized
  44. by appropriate patent licenses.
  45. 4. DISCLAIMER
  46. This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright holders and contributors
  47. "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, including but not limited to the implied warranties
  48. of merchantability and fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  49. CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, or consequential damages,
  50. including but not limited to procurement of substitute goods or services; loss of use, data, or profits,
  51. or business interruption, however caused and on any theory of liability, whether in contract, strict
  52. liability, or tort (including negligence), arising in any way out of the use of this software, even if
  53. advised of the possibility of such damage.
  54. 5. CONTACT INFORMATION
  55. Fraunhofer Institute for Integrated Circuits IIS
  56. Attention: Audio and Multimedia Departments - FDK AAC LL
  57. Am Wolfsmantel 33
  58. 91058 Erlangen, Germany
  59. www.iis.fraunhofer.de/amm
  60. [email protected]
  61. ----------------------------------------------------------------------------------------------------------- */
  62. /************************** MPEG-4 Transport Encoder ************************
  63. Author(s): Manuel Jander
  64. Description: MPEG Transport encode
  65. ******************************************************************************/
  66. #ifndef __TPENC_LIB_H__
  67. #define __TPENC_LIB_H__
  68. #include "tp_data.h"
  69. #include "FDK_bitstream.h"
  70. #define TRANSPORTENC_INBUF_SIZE 8192
  71. typedef enum {
  72. TRANSPORTENC_OK = 0, /*!< All fine. */
  73. TRANSPORTENC_NO_MEM, /*!< Out of memory. */
  74. TRANSPORTENC_UNKOWN_ERROR = 1, /*!< Unknown error (embarrasing). */
  75. TRANSPORTENC_INVALID_PARAMETER, /*!< An invalid parameter was passed to a function . */
  76. TRANSPORTENC_PARSE_ERROR, /*!< Bitstream data contained inconsistencies (wrong syntax). */
  77. TRANSPORTENC_UNSUPPORTED_FORMAT, /*!< Unsupported transport format. */
  78. TRANSPORTENC_NOT_ENOUGH_BITS, /*!< Out of bits. Provide more bits and try again. */
  79. TRANSPORTENC_INVALID_CONFIG, /*!< Error in configuration. */
  80. TRANSPORTENC_LATM_INVALID_NR_OF_SUBFRAMES, /*!< LATM: number of subframes out of range. */
  81. TRANSPORTENC_LOAS_NOT_AVAILABLE, /*!< LOAS format not supported. */
  82. TRANSPORTENC_INVALID_LATM_ALIGNMENT, /*!< AudioMuxElement length not aligned to 1 byte. */
  83. TRANSPORTENC_INVALID_TRANSMISSION_FRAME_LENGTH, /*!< Invalid transmission frame length (< 0). */
  84. TRANSPORTENC_INVALID_CELP_FRAME_LENGTH, /*!< Invalid CELP frame length found (>= 62). */
  85. TRANSPORTENC_INVALID_FRAME_BITS, /*!< Frame bits is not 40 and not 80. */
  86. TRANSPORTENC_INVALID_AOT, /*!< Unknown AOT found. */
  87. TRANSPORTENC_INVALID_AU_LENGTH /*!< Invalid Access Unit length (not byte-aligned). */
  88. } TRANSPORTENC_ERROR;
  89. typedef struct TRANSPORTENC *HANDLE_TRANSPORTENC;
  90. /**
  91. * \brief Determine a reasonable channel configuration on the basis of channel_mode.
  92. * \param noChannels Number of audio channels.
  93. * \return CHANNEL_MODE value that matches the given amount of audio channels.
  94. */
  95. CHANNEL_MODE transportEnc_GetChannelMode( int noChannels );
  96. /**
  97. * \brief Register SBR heaqder writer callback.
  98. * \param hTp Handle of transport decoder.
  99. * \param cbUpdateConfig Pointer to a callback function to handle SBR header writing.
  100. * \param user_data void pointer for user data passed to the callback as first parameter.
  101. * \return 0 on success.
  102. */
  103. int transportEnc_RegisterSbrCallback (
  104. HANDLE_TRANSPORTENC hTpEnc,
  105. const cbSbr_t cbSbr,
  106. void* user_data
  107. );
  108. /**
  109. * \brief Register SSC writer callback.
  110. * \param hTp Handle of transport decoder.
  111. * \param cbUpdateConfig Pointer to a callback function to handle SSC writing.
  112. * \param user_data void pointer for user data passed to the callback as first parameter.
  113. * \return 0 on success.
  114. */
  115. int transportEnc_RegisterSscCallback (
  116. HANDLE_TRANSPORTENC hTpEnc,
  117. const cbSsc_t cbSsc,
  118. void* user_data
  119. );
  120. /**
  121. * \brief Write ASC from given parameters.
  122. * \param asc A HANDLE_FDK_BITSTREAM where the ASC is written to.
  123. * \param config Structure containing the codec configuration settings.
  124. * \param cb callback information structure.
  125. * \return 0 on success.
  126. */
  127. int transportEnc_writeASC (
  128. HANDLE_FDK_BITSTREAM asc,
  129. CODER_CONFIG *config,
  130. CSTpCallBacks *cb
  131. );
  132. /* Defintion of flags that can be passed to transportEnc_Open() */
  133. #define TP_FLAG_MPEG4 1 /** MPEG4 (instead of MPEG2) */
  134. #define TP_FLAG_LATM_AMV 2 /** LATM AudioMuxVersion */
  135. #define TP_FLAG_LATM_AMVA 4 /** LATM AudioMuxVersionA */
  136. /**
  137. * \brief Allocate transport encoder.
  138. * \param phTpEnc Pointer to transport encoder handle.
  139. * \return Error code.
  140. */
  141. TRANSPORTENC_ERROR transportEnc_Open( HANDLE_TRANSPORTENC *phTpEnc );
  142. /**
  143. * \brief Init transport encoder.
  144. * \param bsBuffer Pointer to transport encoder.
  145. * \param bsBuffer Pointer to bitstream buffer.
  146. * \param bsBufferSize Size in bytes of bsBuffer.
  147. * \param transportFmt Format of the transport to be written.
  148. * \param config Pointer to a valid CODER_CONFIG struct.
  149. * \param flags Transport encoder flags.
  150. * \return Error code.
  151. */
  152. TRANSPORTENC_ERROR transportEnc_Init(
  153. HANDLE_TRANSPORTENC hTpEnc,
  154. UCHAR *bsBuffer,
  155. INT bsBufferSize,
  156. TRANSPORT_TYPE transportFmt,
  157. CODER_CONFIG *config,
  158. UINT flags
  159. );
  160. /**
  161. * \brief Get transport encoder bitstream.
  162. * \param hTp Pointer to a transport encoder handle.
  163. * \return The handle to the requested FDK bitstream.
  164. */
  165. HANDLE_FDK_BITSTREAM transportEnc_GetBitstream( HANDLE_TRANSPORTENC hTp );
  166. /**
  167. * \brief Get amount of bits required by the transport headers.
  168. * \param hTp Handle of transport encoder.
  169. * \param auBits Amount of payload bits required for the current subframe.
  170. * \return Error code.
  171. */
  172. INT transportEnc_GetStaticBits( HANDLE_TRANSPORTENC hTp, int auBits );
  173. /**
  174. * \brief Close transport encoder. This function assures that all allocated memory is freed.
  175. * \param phTp Pointer to a previously allocated transport encoder handle.
  176. */
  177. void transportEnc_Close( HANDLE_TRANSPORTENC *phTp );
  178. /**
  179. * \brief Write one access unit.
  180. * \param hTp Handle of transport encoder.
  181. * \param total_bits Amount of total access unit bits.
  182. * \param bufferFullness Value of current buffer fullness in bits.
  183. * \param noConsideredChannels Number of bitrate wise considered channels (all minus LFE channels).
  184. * \return Error code.
  185. */
  186. TRANSPORTENC_ERROR transportEnc_WriteAccessUnit( HANDLE_TRANSPORTENC hTp,
  187. INT total_bits,
  188. int bufferFullness,
  189. int noConsideredChannels );
  190. /**
  191. * \brief Inform the transportEnc layer that writing of access unit has finished. This function
  192. * is required to be called when the encoder has finished writing one Access
  193. * one Access Unit for bitstream housekeeping.
  194. * \param hTp Transport handle.
  195. * \param pBits Pointer to an int, where the current amount of frame bits is passed
  196. * and where the current amount of subframe bits is returned.
  197. *
  198. * OR: This integer is modified by the amount of extra bit alignment that may occurr.
  199. *
  200. * \return Error code.
  201. */
  202. TRANSPORTENC_ERROR transportEnc_EndAccessUnit( HANDLE_TRANSPORTENC hTp, int *pBits);
  203. /*
  204. * \brief Get a payload frame.
  205. * \param hTpEnc Transport encoder handle.
  206. * \param nBytes Pointer to an int to hold the frame size in bytes. Returns zero
  207. * if currently there is no complete frame for output (number of sub frames > 1).
  208. * \return Error code.
  209. */
  210. TRANSPORTENC_ERROR transportEnc_GetFrame(HANDLE_TRANSPORTENC hTpEnc, int *nbytes);
  211. /* ADTS CRC support */
  212. /**
  213. * \brief Set current bitstream position as start of a new data region.
  214. * \param hTpEnc Transport encoder handle.
  215. * \param mBits Size in bits of the data region. Set to 0 if it should not be of a fixed size.
  216. * \return Data region ID, which should be used when calling transportEnc_CrcEndReg().
  217. */
  218. int transportEnc_CrcStartReg(HANDLE_TRANSPORTENC hTpEnc, int mBits);
  219. /**
  220. * \brief Set end of data region.
  221. * \param hTpEnc Transport encoder handle.
  222. * \param reg Data region ID, opbtained from transportEnc_CrcStartReg().
  223. * \return void
  224. */
  225. void transportEnc_CrcEndReg(HANDLE_TRANSPORTENC hTpEnc, int reg);
  226. /**
  227. * \brief Get AudioSpecificConfig or StreamMuxConfig from transport encoder handle and write it to dataBuffer.
  228. * \param hTpEnc Transport encoder handle.
  229. * \param cc Pointer to the current and valid configuration contained in a CODER_CONFIG struct.
  230. * \param dataBuffer Bitbuffer holding binary configuration.
  231. * \param confType Pointer to an UINT where the configuration type is returned (0:ASC, 1:SMC).
  232. * \return Error code.
  233. */
  234. TRANSPORTENC_ERROR transportEnc_GetConf( HANDLE_TRANSPORTENC hTpEnc,
  235. CODER_CONFIG *cc,
  236. FDK_BITSTREAM *dataBuffer,
  237. UINT *confType );
  238. /**
  239. * \brief Get information (version among other things) of the transport encoder library.
  240. * \param info Pointer to an allocated LIB_INFO struct.
  241. * \return Error code.
  242. */
  243. TRANSPORTENC_ERROR transportEnc_GetLibInfo( LIB_INFO *info );
  244. #endif /* #ifndef __TPENC_LIB_H__ */