• 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 __AACENC_H__
17 #define __AACENC_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      AACENC */
29 /** @{ */ /** <!-- [AACENC] */
30 
31 #ifdef MONO_ONLY
32 #define MAX_CHANNELS 1 /* aacenc encoder channels */
33 #else
34 #define MAX_CHANNELS 2
35 #endif
36 
37 #define AACENC_BLOCKSIZE 1024 /* aacenc blocksize */
38 
39 #define AACENC_VERSION_MAX_BYTE 64 /* version max byte size */
40 
41 /** @} */                     /** <!-- ==== Macro Definition end ==== */
42 
43 /*************************** Structure Definition ****************************/
44 /** \addtogroup      AACENC */
45 /** @{ */ /** <!-- [AACENC] */
46 
47 typedef enum {
48     HI_AACENC_OK                     = 0x0000,  /* No error happened. All fine. */
49 
50     HI_AACENC_INVALID_HANDLE         = 0x0020,  /* Handle passed to function call was invalid. */
51     HI_AACENC_MEMORY_ERROR           = 0x0021,  /* Memory allocation failed. */
52     HI_AACENC_UNSUPPORTED_PARAMETER  = 0x0022,  /* Parameter not available. */
53     HI_AACENC_INVALID_CONFIG         = 0x0023,  /* Configuration not provided. */
54 
55     HI_AACENC_INIT_ERROR             = 0x0040,  /* General initialization error. */
56     HI_AACENC_INIT_AAC_ERROR         = 0x0041,  /* AAC library initialization error. */
57     HI_AACENC_INIT_SBR_ERROR         = 0x0042,  /* SBR library initialization error. */
58     HI_AACENC_INIT_TP_ERROR          = 0x0043,  /* Transport library initialization error. */
59     HI_AACENC_INIT_META_ERROR        = 0x0044,  /* Meta data library initialization error. */
60 
61     HI_AACENC_ENCODE_ERROR           = 0x0060,  /* The encoding process was interrupted by an unexpected error. */
62 
63     HI_AACENC_ENCODE_EOF             = 0x0080   /* End of file reached. */
64 } HI_AACENC_ERROR_E;
65 
66 /** Defines AACENC quality */
67 typedef enum {
68     AU_QualityExcellent = 0,
69     AU_QualityHigh = 1,
70     AU_QualityMedium = 2,
71     AU_QualityLow = 3,
72 } AuQuality;
73 
74 /** Defines AACENC format */
75 typedef enum {
76     AACLC = 0,    /* AAC-LC format */
77     EAAC = 1,     /* HEAAC or AAC+  or aacPlusV1 */
78     EAACPLUS = 2, /* AAC++ or aacPlusV2 */
79     AACLD = 3,    /* AAC LD(Low Delay) */
80     AACELD = 4,   /* AAC ELD(Low Delay) */
81 } AuEncoderFormat;
82 
83 /** Defines AACENC container */
84 typedef enum {
85     AACENC_ADTS = 0,
86     AACENC_LOAS = 1,
87     AACENC_LATM_MCP1 = 2,
88 } AACENCTransportType;
89 
90 /** Defines AACENC configuration */
91 typedef struct {
92     AuQuality quality;
93     AuEncoderFormat coderFormat;
94     HI_S16 bitsPerSample;
95     HI_S32 sampleRate;   /* audio file sample rate */
96     HI_S32 bitRate;      /* encoder bit rate in bits/sec */
97     HI_S16 nChannelsIn;  /* number of channels on input (1,2) */
98     HI_S16 nChannelsOut; /* number of channels on output (1,2) */
99     HI_S16 bandWidth;    /* targeted audio bandwidth in Hz */
100     AACENCTransportType transtype;
101 } AACENC_CONFIG;
102 
103 /* Defines AACENC version */
104 typedef struct hiAACENC_VERSION_S {
105     HI_U8 aVersion[AACENC_VERSION_MAX_BYTE];
106 } AACENC_VERSION_S;
107 
108 typedef HI_U32 AAC_ENCODER_S;
109 
110 /** @} */ /** <!-- ==== Structure Definition End ==== */
111 
112 /******************************* API declaration *****************************/
113 /** \addtogroup      AACENC */
114 /** @{ */ /** <!--  [AACENC] */
115 
116 /**
117 \brief Get version information.
118 \attention \n
119 N/A
120 \param[in] pVersion       version describe struct
121 \retval ::HI_SUCCESS   : Success
122 \retval ::HI_FAILURE          : FAILURE
123 \see \n
124 N/A
125 */
126 HI_S32 HI_AACENC_GetVersion(AACENC_VERSION_S *pVersion);
127 
128 /**
129 \brief get reasonable default configuration.
130 \attention \n
131 N/A
132 \param[in] pstConfig    pointer to an configuration information structure
133 \retval ::HI_SUCCESS   : Success
134 \retval ::HI_FAILURE          : FAILURE
135 \see \n
136 N/A
137 */
138 HI_S32 AACInitDefaultConfig(AACENC_CONFIG *pstConfig);
139 
140 /**
141 \brief allocate and initialize a new encoder instance.
142 \attention \n
143 N/A
144 \param[in] phAacPlusEnc    pointer to an configuration information structure
145 \param[in] pstConfig    pointer to an configuration information structure
146 \retval ::HI_SUCCESS   : Success
147 \retval ::HI_FAILURE   : FAILURE
148 \see \n
149 N/A
150 */
151 HI_S32 AACEncoderOpen(AAC_ENCODER_S **phAacPlusEnc, const AACENC_CONFIG *pstConfig);
152 
153 /**
154 \brief allocate and initialize a new encoder instance
155 \attention \n
156 N/A
157 \param[in] hAacPlusEnc    pointer to an configuration information structure
158 \param[in] ps16PcmBuf    BLOCKSIZE*nChannels audio samples,interleaved
159 \param[in] pu8Outbuf    pointer to output buffer,(must be 6144/8*MAX_CHANNELS bytes large)
160 \param[in] ps32NumOutBytes    number of bytes in output buffer after processing
161 \retval ::HI_SUCCESS   : Success
162 \retval ::HI_FAILURE   : FAILURE
163 \see \n
164 N/A
165 */
166 HI_S32 AACEncoderFrame(AAC_ENCODER_S *hAacPlusEnc, HI_S16 *ps16PcmBuf,
167                        HI_U8 *pu8Outbuf, HI_S32 *ps32NumOutBytes);
168 
169 /**
170 \brief close encoder device.
171 \attention \n
172 N/A
173 \param[in] hAacPlusEnc    pointer to an configuration information structure
174 \retval N/A
175 \see \n
176 N/A
177 */
178 HI_VOID AACEncoderClose(AAC_ENCODER_S *hAacPlusEnc);
179 
180 /**
181 \brief register sbrenc module.
182 \attention \n
183 N/A
184 \param[in] pModuleHandle  pointer to WorkHandle of sbrenc module
185 \retval ::HI_SUCCESS   : Success
186 \retval ::HI_FAILURE   : FAILURE
187 \see \n
188 N/A
189 */
190 HI_S32 AACEncoderRegisterModule(HI_VOID *pModuleHandle);
191 
192 /**
193 \brief Get WorkHandle of sbrenc module.
194 \attention \n
195 N/A
196 \retval ::HI_VOID *    : pointer to WorkHandle of sbrenc module
197 \see \n
198 N/A
199 */
200 HI_VOID *HI_AAC_SBRENC_GetHandle(HI_VOID);
201 
202 /** @} */ /** <!-- ==== API declaration end ==== */
203 
204 #ifdef __cplusplus
205 #if __cplusplus
206 }
207 #endif /* __cpluscplus */
208 #endif /* __cpluscplus */
209 
210 #endif /* __AACENC_H__ */
211