• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef __AACDEC_H__
17 #define __AACDEC_H__
18 
19 #include "hi_type.h"
20 
21 #ifdef __cplusplus
22 #if __cplusplus
23 extern "C" {
24 #endif /* __cpluscplus */
25 #endif /* __cpluscplus */
26 
27 /********************************Macro Definition********************************/
28 /** \addtogroup      AACDEC */
29 /** @{ */ /** <!-- [AACDEC] */
30 
31 #ifndef AAC_MAX_NCHANS
32 #define AAC_MAX_NCHANS 2
33 #endif
34 #define AAC_MAX_NSAMPS   1024
35 /*
36  * according to spec (13818-7 section 8.2.2, 14496-3 section 4.5.3),
37  * 6144 bits =  768 bytes per SCE or CCE-I,12288 bits = 1536 bytes per CPE
38  */
39 #define AAC_MAINBUF_SIZE (768 * AAC_MAX_NCHANS)
40 
41 #define AAC_NUM_PROFILES 3
42 #define AAC_PROFILE_MP   0
43 #define AAC_PROFILE_LC   1
44 #define AAC_PROFILE_SSR  2
45 
46 #define AACDEC_VERSION_MAX_BYTE 64 /* version max byte size */
47 
48 #ifndef HI_SUCCESS
49 #define HI_SUCCESS 0
50 #endif
51 /** @} */ /** <!-- ==== Macro Definition end ==== */
52 
53 /*************************** Structure Definition ****************************/
54 /** \addtogroup      AACDEC */
55 /** @{ */ /** <!-- [AACDEC] */
56 
57 /** Defines AACDEC error code */
58 typedef enum {
59     ERR_AAC_NONE                          =   0,        /* no decode error */
60     ERR_AAC_INDATA_UNDERFLOW              =  -1,        /* not enough input data */
61     ERR_AAC_NULL_POINTER                  =  -2,        /* null pointer */
62     ERR_AAC_INVALID_ADTS_HEADER           =  -3,        /* invalid adts header */
63     ERR_AAC_INVALID_ADIF_HEADER           =  -4,        /* invalid adif header */
64     ERR_AAC_INVALID_FRAME                 =  -5,        /* invalid frame */
65     ERR_AAC_MPEG4_UNSUPPORTED             =  -6,        /* upsupport mpeg4 format */
66     ERR_AAC_CHANNEL_MAP                   =  -7,        /* channel map error */
67     ERR_AAC_SYNTAX_ELEMENT                =  -8,        /* element error */
68     ERR_AAC_DEQUANT                       =  -9,        /* dequant error */
69     ERR_AAC_STEREO_PROCESS                = -10,        /* stereo process error */
70     ERR_AAC_PNS                           = -11,        /* pns process error */
71     ERR_AAC_SHORT_BLOCK_DEINT             = -12,        /* reserved */
72     ERR_AAC_TNS                           = -13,        /* TNS process error */
73     ERR_AAC_IMDCT                         = -14,        /* IMDCT process error */
74     ERR_AAC_NCHANS_TOO_HIGH               = -15,        /* unsupport mutil channel */
75     ERR_AAC_SBR_INIT                      = -16,        /* SBR init error */
76     ERR_AAC_SBR_BITSTREAM                 = -17,        /* SBR bitstream error */
77     ERR_AAC_SBR_DATA                      = -18,        /* SBR data error */
78     ERR_AAC_SBR_PCM_FORMAT                = -19,        /* SBR pcm data error */
79     ERR_AAC_SBR_NCHANS_TOO_HIGH           = -20,        /* unsupport SBR multi channel */
80     ERR_AAC_SBR_SINGLERATE_UNSUPPORTED    = -21,        /* SBR invalid samplerate */
81     ERR_AAC_RAWBLOCK_PARAMS               = -22,        /* invalid RawBlock params */
82     ERR_AAC_PS_INIT                       = -23,        /* PS init error */
83     ERR_AAC_CH_MAPPING                    = -24,
84     ERR_UNKNOWN                           = -9999,      /* reserved */
85     ERR_AAC_OUT_OF_MEMORY                 = 2,          /* Heap returned NULL pointer.
86                                                            Output buffer is invalid. */
87     ERR_AAC_UNKNOWN                       = 5,          /* Error condition is of unknown reason, or from a another
88                                                            module. Output buffer is invalid. */
89     ERR_AAC_TRANSPORT_SYNC_ERROR          = 4097,       /* The transport decoder had syncronisation problems.
90                                                            Do not exit decoding. Just feed new bitstream data. */
91     ERR_AAC_NOT_ENOUGH_BITS               = 4098,       /* The input buffer ran out of bits. */
92     ERR_AAC_TRANSPORT_FATAL_ERROR         = 4099,       /* The transport decoder occut fatal error. Reset Tranport */
93     ERR_AAC_INVALID_HANDLE                = 8193,       /* The handle passed to the function call
94                                                            was invalid (NULL). */
95     ERR_AAC_UNSUPPORTED_AOT               = 8194,       /* The AOT found in the configuration is not supported. */
96     ERR_AAC_UNSUPPORTED_FORMAT            = 8195,       /* The bitstream format is not supported.  */
97     ERR_AAC_UNSUPPORTED_ER_FORMAT         = 8196,       /* The error resilience tool format is not supported. */
98     ERR_AAC_UNSUPPORTED_EPCONFIG          = 8197,       /* The error protection format is not supported. */
99     ERR_AAC_UNSUPPORTED_MULTILAYER        = 8198,       /* More than one layer for AAC scalable is not supported. */
100     ERR_AAC_UNSUPPORTED_CHANNELCONFIG     = 8199,       /* The channel configuration (either number or arrangement)
101                                                            is not supported. */
102     ERR_AAC_UNSUPPORTED_SAMPLINGRATE      = 8200,       /* The sample rate specified in the configuration
103                                                            is not supported. */
104     ERR_AAC_INVALID_SBR_CONFIG            = 8201,       /* The SBR configuration is not supported. */
105     ERR_AAC_SET_PARAM_FAIL                = 8202,       /* The parameter could not be set. Either the value was out
106                                                            of range or the parameter does not exist. */
107     ERR_AAC_NEED_TO_RESTART               = 8203,       /* The decoder needs to be restarted, since the requiered
108                                                            configuration change cannot be performed. */
109     ERR_AAC_TRANSPORT_ERROR               = 16385,      /* The transport decoder encountered an unexpected error. */
110     ERR_AAC_PARSE_ERROR                   = 16386,      /* Error while parsing the bitstream. Most probably it is
111                                                            corrupted, or the system crashed. */
112     ERR_AAC_UNSUPPORTED_EXTENSION_PAYLOAD = 16387,      /* Error while parsing the extension payload of the bitstream.
113                                                            The extension payload type found is not supported. */
114     ERR_AAC_DECODE_FRAME_ERROR            = 16388,      /* The parsed bitstream value is out of range. Most probably
115                                                            the bitstream is corrupt, or the system crashed. */
116     ERR_AAC_CRC_ERROR                     = 16389,      /* The embedded CRC did not match. */
117     ERR_AAC_INVALID_CODE_BOOK             = 16390,      /* An invalid codebook was signalled. Most probably the
118                                                            bitstream is corrupt, or the system crashed. */
119     ERR_AAC_UNSUPPORTED_PREDICTION        = 16391,      /* Predictor found, but not supported in the AAC Low
120                                                            Complexity profile. Most probably the bitstream is
121                                                            corrupt, or has a wrong format. */
122     ERR_AAC_UNSUPPORTED_CCE               = 16392,      /* A CCE element was found which is not supported.
123                                                            Most probably the bitstream is corrupt,
124                                                            or has a wrong format. */
125     ERR_AAC_UNSUPPORTED_LFE               = 16393,      /* A LFE element was found which is not supported.
126                                                            Most probably the bitstream is corrupt,
127                                                            or has a wrong format. */
128     ERR_AAC_UNSUPPORTED_GAIN_CONTROL_DATA = 16394,      /* Gain control data found but not supported.
129                                                            Most probably the bitstream is corrupt,
130                                                            or has a wrong format. */
131     ERR_AAC_UNSUPPORTED_SBA               = 16395,      /* SBA found, but currently not supported
132                                                            in the BSAC profile. */
133     ERR_AAC_TNS_READ_ERROR                = 16396,      /* Error while reading TNS data. Most probably
134                                                            the bitstream is corrupt or the system crashed. */
135     ERR_AAC_RVLC_ERROR                    = 16397,      /* Error while decoding error resillient data. */
136     ERR_AAC_ANC_DATA_ERROR                = 32769,      /* Non severe error concerning the ancillary data handling. */
137     ERR_AAC_TOO_SMALL_ANC_BUFFER          = 32770,      /* The registered ancillary data buffer is too small
138                                                            to receive the parsed data. */
139     ERR_AAC_TOO_MANY_ANC_ELEMENTS         = 32771,      /* More than the allowed number of ancillary data elements
140                                                            should be written to buffer. */
141 } HI_AACDEC_ERR_E;
142 
143 typedef struct _AACFrameInfo {
144     int bitRate;
145     int nChans;        /* channels,range:1,2 */
146     int sampRateCore;  /* inner sample rate */
147     int sampRateOut;   /* output samplerate */
148     int bitsPerSample; /* bitwidth ,range:16 */
149     int outputSamps;   /* output samples */
150     int profile;       /* profile */
151     int tnsUsed;       /* tns tools */
152     int pnsUsed;       /* pns tools */
153 } AACFrameInfo;
154 
155 typedef enum {
156     AACDEC_ADTS = 0,
157     AACDEC_LOAS = 1,
158     AACDEC_LATM_MCP1 = 2,
159 } AACDECTransportType;
160 
161 typedef void *HAACDecoder;
162 
163 typedef struct hiAACDEC_VERSION_S {
164     HI_U8 aVersion[AACDEC_VERSION_MAX_BYTE];
165 } AACDEC_VERSION_S;
166 
167 /** @} */ /** <!-- ==== Structure Definition End ==== */
168 
169 /******************************* API declaration *****************************/
170 /** \addtogroup      AACDEC */
171 /** @{ */ /** <!--  [AACDEC] */
172 
173 /**
174 \brief Get version information.
175 \attention \n
176 N/A
177 \param[in] pVersion    :   version describe struct
178 \retval ::HI_SUCCESS   :   Success
179 \retval ::HI_FAILURE   :   pVersion is NULL, return HI_FAILURE
180 \see \n
181 N/A
182 */
183 HI_S32 HI_AACDEC_GetVersion(AACDEC_VERSION_S *pVersion);
184 
185 /**
186 \brief create and initial decoder device.
187 \attention \n
188 N/A
189 \param[in] enTranType   : transport type
190 \retval ::HAACDecoder   : init success, return non-NULL handle.
191 \retval ::NULL          : init failure, return NULL
192 \see \n
193 N/A
194 */
195 HAACDecoder AACInitDecoder(AACDECTransportType enTranType);
196 
197 /**
198 \brief destroy AAC-Decoder, free the memory.
199 \attention \n
200 N/A
201 \param[in] hAACDecoder  : AAC-Decoder handle
202 \see \n
203 N/A
204 */
205 HI_VOID AACFreeDecoder(HAACDecoder hAACDecoder);
206 
207 /**
208 \brief set RawMode before decode Raw Format aac bitstream(Reserved API, unused now.)
209 \attention \n
210 N/A
211 \param[in] hAACDecoder  : AAC-Decoder handle
212 \param[in] nChans       : inout channels
213 \param[in] sampRate     : input sampelrate
214 \retval ::HI_FAILURE    : RESERVED API, always return HI_FAILURE.
215 \see \n
216 N/A
217 */
218 HI_S32 AACSetRawMode(HAACDecoder hAACDecoder, HI_S32 nChans, HI_S32 sampRate);
219 
220 /**
221 \brief look for valid AAC sync header
222 \attention \n
223 N/A
224 \param[in] hAACDecoder      : AAC-Decoder handle
225 \param[in/out] ppInbufPtr   : address of the pointer of start-point of the bitstream
226 \param[in/out] pBytesLeft   : pointer to BytesLeft that indicates bitstream numbers at input buffer
227 \retval ::<0                : err, always return ERR_AAC_INDATA_UNDERFLOW
228 \retval ::other             : Success, return number bytes of current frame
229 \see \n
230 N/A
231 */
232 HI_S32 AACDecodeFindSyncHeader(HAACDecoder hAACDecoder, HI_U8 **ppInbufPtr, HI_S32 *pBytesLeft);
233 
234 /**
235 \brief decoding AAC frame and output 1024(LC) OR 2048(HEAAC/eAAC/eAAC+) 16bit PCM samples per channel.
236 \attention \n
237 \param[in] hAACDecoder       : AAC-Decoder handle
238 \param[in] ppInbufPtr        : address of the pointer of start-point of the bitstream
239 \param[in/out] pBytesLeft    : pointer to BytesLeft that indicates bitstream numbers at input buffer,
240                                indicates the left bytes
241 \param[in] pOutPcm           : the address of the out pcm buffer,pcm data in noninterlaced fotmat: L/L/L/... R/R/R/...
242 \retval :: SUCCESS           : Success
243 \retval :: ERROR_CODE        : FAILURE, return error_code.
244 \see \n
245 N/A
246 */
247 HI_S32 AACDecodeFrame(HAACDecoder hAACDecoder, HI_U8 **ppInbufPtr, HI_S32 *pBytesLeft, HI_S16 *pOutPcm);
248 
249 /**
250 \brief get the frame information.
251 \attention \n
252 \param[in] hAACDecoder       : AAC-Decoder handle
253 \param[out] aacFrameInfo     : frame information
254 \retval :: HI_SUCCESS        : Success
255 \retval :: ERROR_CODE        : FAILURE, return error_code.
256 \see \n
257 N/A
258 */
259 HI_S32 AACGetLastFrameInfo(HAACDecoder hAACDecoder, AACFrameInfo *aacFrameInfo);
260 
261 /**
262 \brief set eosflag.
263 \attention \n
264 \param[in] hAACDecoder       : AAC-Decoder handle
265 \param[in] s32Eosflag        : end flag
266 \retval :: HI_SUCCESS        : Success
267 \retval :: ERROR_CODE        : FAILURE, return error_code.
268 \see \n
269 N/A
270 */
271 HI_S32 AACDecoderSetEosFlag(HAACDecoder hAACDecoder, HI_S32 s32Eosflag);
272 
273 /**
274 \brief flush internal codec state (after seeking, for example)
275 \attention \n
276 \param[in] hAACDecoder       : AAC-Decoder handle
277 \retval :: HI_SUCCESS        : Success
278 \retval :: ERROR_CODE        : FAILURE, return error_code.
279 \see \n
280 N/A
281 */
282 HI_S32 AACFlushCodec(HAACDecoder hAACDecoder);
283 
284 /**
285 \brief register sbrdec module
286 \attention \n
287 N/A
288 \param[in] pModuleHandle     : pointer to WorkHandle of sbrdec module
289 \retval :: HI_SUCCESS        : Success
290 \retval :: ERROR_CODE        : FAILURE, return error_code.
291 \see \n
292 N/A
293 */
294 HI_S32 AACDecoderRegisterModule(HI_VOID *pModuleHandle);
295 
296 /**
297 \brief Get WorkHandle of sbrdec module
298 \attention \n
299 N/A
300 \retval :: HI_VOID *          : pointer to WorkHandle of sbrdec module
301 \see \n
302 N/A
303 */
304 HI_VOID *HI_AAC_SBRDEC_GetHandle(HI_VOID);
305 
306 /** @} */ /** <!-- ==== API declaration end ==== */
307 
308 #ifdef __cplusplus
309 #if __cplusplus
310 }
311 #endif /* __cpluscplus */
312 #endif /* __cpluscplus */
313 
314 #endif /* __AACDEC_H__ */
315