Imported Debian version 0.1.3.1
[deb_fdk-aac.git] / libMpegTPEnc / include / tpenc_lib.h
1
2 /* -----------------------------------------------------------------------------------------------------------
3 Software 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
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 Transport Encoder ************************
85
86 Author(s): Manuel Jander
87 Description: MPEG Transport encode
88
89 ******************************************************************************/
90
91 #ifndef __TPENC_LIB_H__
92 #define __TPENC_LIB_H__
93
94 #include "tp_data.h"
95 #include "FDK_bitstream.h"
96
97 #define TRANSPORTENC_INBUF_SIZE 8192
98
99 typedef enum {
100 TRANSPORTENC_OK = 0, /*!< All fine. */
101 TRANSPORTENC_NO_MEM, /*!< Out of memory. */
102 TRANSPORTENC_UNKOWN_ERROR = 1, /*!< Unknown error (embarrasing). */
103 TRANSPORTENC_INVALID_PARAMETER, /*!< An invalid parameter was passed to a function . */
104 TRANSPORTENC_PARSE_ERROR, /*!< Bitstream data contained inconsistencies (wrong syntax). */
105 TRANSPORTENC_UNSUPPORTED_FORMAT, /*!< Unsupported transport format. */
106 TRANSPORTENC_NOT_ENOUGH_BITS, /*!< Out of bits. Provide more bits and try again. */
107
108 TRANSPORTENC_INVALID_CONFIG, /*!< Error in configuration. */
109 TRANSPORTENC_LATM_INVALID_NR_OF_SUBFRAMES, /*!< LATM: number of subframes out of range. */
110 TRANSPORTENC_LOAS_NOT_AVAILABLE, /*!< LOAS format not supported. */
111 TRANSPORTENC_INVALID_LATM_ALIGNMENT, /*!< AudioMuxElement length not aligned to 1 byte. */
112
113 TRANSPORTENC_INVALID_TRANSMISSION_FRAME_LENGTH, /*!< Invalid transmission frame length (< 0). */
114 TRANSPORTENC_INVALID_CELP_FRAME_LENGTH, /*!< Invalid CELP frame length found (>= 62). */
115 TRANSPORTENC_INVALID_FRAME_BITS, /*!< Frame bits is not 40 and not 80. */
116 TRANSPORTENC_INVALID_AOT, /*!< Unknown AOT found. */
117 TRANSPORTENC_INVALID_AU_LENGTH /*!< Invalid Access Unit length (not byte-aligned). */
118
119 } TRANSPORTENC_ERROR;
120
121 typedef struct TRANSPORTENC *HANDLE_TRANSPORTENC;
122
123 /**
124 * \brief Determine a reasonable channel configuration on the basis of channel_mode.
125 * \param noChannels Number of audio channels.
126 * \return CHANNEL_MODE value that matches the given amount of audio channels.
127 */
128 CHANNEL_MODE transportEnc_GetChannelMode( int noChannels );
129
130 /**
131 * \brief Register SBR heaqder writer callback.
132 * \param hTp Handle of transport decoder.
133 * \param cbUpdateConfig Pointer to a callback function to handle SBR header writing.
134 * \param user_data void pointer for user data passed to the callback as first parameter.
135 * \return 0 on success.
136 */
137 int transportEnc_RegisterSbrCallback (
138 HANDLE_TRANSPORTENC hTpEnc,
139 const cbSbr_t cbSbr,
140 void* user_data
141 );
142
143 /**
144 * \brief Register SSC writer callback.
145 * \param hTp Handle of transport decoder.
146 * \param cbUpdateConfig Pointer to a callback function to handle SSC writing.
147 * \param user_data void pointer for user data passed to the callback as first parameter.
148 * \return 0 on success.
149 */
150 int transportEnc_RegisterSscCallback (
151 HANDLE_TRANSPORTENC hTpEnc,
152 const cbSsc_t cbSsc,
153 void* user_data
154 );
155
156 /**
157 * \brief Write ASC from given parameters.
158 * \param asc A HANDLE_FDK_BITSTREAM where the ASC is written to.
159 * \param config Structure containing the codec configuration settings.
160 * \param cb callback information structure.
161 * \return 0 on success.
162 */
163 int transportEnc_writeASC (
164 HANDLE_FDK_BITSTREAM asc,
165 CODER_CONFIG *config,
166 CSTpCallBacks *cb
167 );
168
169
170 /* Defintion of flags that can be passed to transportEnc_Open() */
171 #define TP_FLAG_MPEG4 1 /** MPEG4 (instead of MPEG2) */
172 #define TP_FLAG_LATM_AMV 2 /** LATM AudioMuxVersion */
173 #define TP_FLAG_LATM_AMVA 4 /** LATM AudioMuxVersionA */
174
175 /**
176 * \brief Allocate transport encoder.
177 * \param phTpEnc Pointer to transport encoder handle.
178 * \return Error code.
179 */
180 TRANSPORTENC_ERROR transportEnc_Open( HANDLE_TRANSPORTENC *phTpEnc );
181
182 /**
183 * \brief Init transport encoder.
184 * \param bsBuffer Pointer to transport encoder.
185 * \param bsBuffer Pointer to bitstream buffer.
186 * \param bsBufferSize Size in bytes of bsBuffer.
187 * \param transportFmt Format of the transport to be written.
188 * \param config Pointer to a valid CODER_CONFIG struct.
189 * \param flags Transport encoder flags.
190 * \return Error code.
191 */
192 TRANSPORTENC_ERROR transportEnc_Init(
193 HANDLE_TRANSPORTENC hTpEnc,
194 UCHAR *bsBuffer,
195 INT bsBufferSize,
196 TRANSPORT_TYPE transportFmt,
197 CODER_CONFIG *config,
198 UINT flags
199 );
200
201 /**
202 * \brief Get transport encoder bitstream.
203 * \param hTp Pointer to a transport encoder handle.
204 * \return The handle to the requested FDK bitstream.
205 */
206 HANDLE_FDK_BITSTREAM transportEnc_GetBitstream( HANDLE_TRANSPORTENC hTp );
207
208 /**
209 * \brief Get amount of bits required by the transport headers.
210 * \param hTp Handle of transport encoder.
211 * \param auBits Amount of payload bits required for the current subframe.
212 * \return Error code.
213 */
214 INT transportEnc_GetStaticBits( HANDLE_TRANSPORTENC hTp, int auBits );
215
216 /**
217 * \brief Close transport encoder. This function assures that all allocated memory is freed.
218 * \param phTp Pointer to a previously allocated transport encoder handle.
219 */
220 void transportEnc_Close( HANDLE_TRANSPORTENC *phTp );
221
222 /**
223 * \brief Write one access unit.
224 * \param hTp Handle of transport encoder.
225 * \param total_bits Amount of total access unit bits.
226 * \param bufferFullness Value of current buffer fullness in bits.
227 * \param noConsideredChannels Number of bitrate wise considered channels (all minus LFE channels).
228 * \return Error code.
229 */
230 TRANSPORTENC_ERROR transportEnc_WriteAccessUnit( HANDLE_TRANSPORTENC hTp,
231 INT total_bits,
232 int bufferFullness,
233 int noConsideredChannels );
234
235 /**
236 * \brief Inform the transportEnc layer that writing of access unit has finished. This function
237 * is required to be called when the encoder has finished writing one Access
238 * one Access Unit for bitstream housekeeping.
239 * \param hTp Transport handle.
240 * \param pBits Pointer to an int, where the current amount of frame bits is passed
241 * and where the current amount of subframe bits is returned.
242 *
243 * OR: This integer is modified by the amount of extra bit alignment that may occurr.
244 *
245 * \return Error code.
246 */
247 TRANSPORTENC_ERROR transportEnc_EndAccessUnit( HANDLE_TRANSPORTENC hTp, int *pBits);
248
249 /*
250 * \brief Get a payload frame.
251 * \param hTpEnc Transport encoder handle.
252 * \param nBytes Pointer to an int to hold the frame size in bytes. Returns zero
253 * if currently there is no complete frame for output (number of sub frames > 1).
254 * \return Error code.
255 */
256 TRANSPORTENC_ERROR transportEnc_GetFrame(HANDLE_TRANSPORTENC hTpEnc, int *nbytes);
257
258 /* ADTS CRC support */
259
260 /**
261 * \brief Set current bitstream position as start of a new data region.
262 * \param hTpEnc Transport encoder handle.
263 * \param mBits Size in bits of the data region. Set to 0 if it should not be of a fixed size.
264 * \return Data region ID, which should be used when calling transportEnc_CrcEndReg().
265 */
266 int transportEnc_CrcStartReg(HANDLE_TRANSPORTENC hTpEnc, int mBits);
267
268 /**
269 * \brief Set end of data region.
270 * \param hTpEnc Transport encoder handle.
271 * \param reg Data region ID, opbtained from transportEnc_CrcStartReg().
272 * \return void
273 */
274 void transportEnc_CrcEndReg(HANDLE_TRANSPORTENC hTpEnc, int reg);
275
276 /**
277 * \brief Get AudioSpecificConfig or StreamMuxConfig from transport encoder handle and write it to dataBuffer.
278 * \param hTpEnc Transport encoder handle.
279 * \param cc Pointer to the current and valid configuration contained in a CODER_CONFIG struct.
280 * \param dataBuffer Bitbuffer holding binary configuration.
281 * \param confType Pointer to an UINT where the configuration type is returned (0:ASC, 1:SMC).
282 * \return Error code.
283 */
284 TRANSPORTENC_ERROR transportEnc_GetConf( HANDLE_TRANSPORTENC hTpEnc,
285 CODER_CONFIG *cc,
286 FDK_BITSTREAM *dataBuffer,
287 UINT *confType );
288
289 /**
290 * \brief Get information (version among other things) of the transport encoder library.
291 * \param info Pointer to an allocated LIB_INFO struct.
292 * \return Error code.
293 */
294 TRANSPORTENC_ERROR transportEnc_GetLibInfo( LIB_INFO *info );
295
296 #endif /* #ifndef __TPENC_LIB_H__ */