/src/libxaac/fuzzer/xaac_dec_fuzzer.cpp
Line | Count | Source |
1 | | /****************************************************************************** |
2 | | * |
3 | | * Copyright (C) 2019 The Android Open Source Project |
4 | | * |
5 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
6 | | * you may not use this file except in compliance with the License. |
7 | | * You may obtain a copy of the License at: |
8 | | * |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | * limitations under the License. |
16 | | * |
17 | | ***************************************************************************** |
18 | | * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore |
19 | | */ |
20 | | |
21 | | #include <stddef.h> |
22 | | #include <stdint.h> |
23 | | #include <stdio.h> |
24 | | #include <stdlib.h> |
25 | | #include <string.h> |
26 | | |
27 | | #include <vector> |
28 | | |
29 | | #include "ixheaac_type_def.h" |
30 | | #include "ixheaac_error_standards.h" |
31 | | #include "ixheaacd_error_handler.h" |
32 | | #include "ixheaacd_apicmd_standards.h" |
33 | | #include "ixheaacd_memory_standards.h" |
34 | | #include "ixheaacd_aac_config.h" |
35 | | |
36 | | #include "impd_apicmd_standards.h" |
37 | | #include "impd_drc_config_params.h" |
38 | | |
39 | | /* 64*-0.25dB = -16 dB below full scale for mobile conf */ |
40 | | #define DRC_DEFAULT_MOBILE_REF_LEVEL 64 |
41 | | /* maximum compression of dynamic range for mobile conf */ |
42 | | #define DRC_DEFAULT_MOBILE_DRC_CUT 127 |
43 | | /* maximum compression of dynamic range for mobile conf */ |
44 | | #define DRC_DEFAULT_MOBILE_DRC_BOOST 127 |
45 | | /* switch for heavy compression for mobile conf */ |
46 | | #define DRC_DEFAULT_MOBILE_DRC_HEAVY 1 |
47 | | /* encoder target level; -1 => the value is unknown, otherwise dB \ |
48 | | step value (e.g. 64 for -16 dB) */ |
49 | | #define DRC_DEFAULT_MOBILE_ENC_LEVEL (-1) |
50 | | |
51 | 18.7k | #define MAX_CHANNEL_COUNT 8 |
52 | | |
53 | | #define MAX_MEM_ALLOCS 100 |
54 | | |
55 | 37.4k | #define IA_MAX_OUTPUT_PCM_SIZE (3) |
56 | 37.4k | #define IA_MAX_USAC_CH (2) |
57 | 37.4k | #define IA_MAX_OUT_SAMPLES_PER_FRAME (4096) |
58 | | |
59 | | #define IA_DRC_DEC_IN_OUT_BUF_SIZE \ |
60 | 37.4k | (IA_MAX_USAC_CH * IA_MAX_OUT_SAMPLES_PER_FRAME * IA_MAX_OUTPUT_PCM_SIZE) |
61 | | |
62 | | class Codec { |
63 | | public: |
64 | | IA_ERRORCODE initDecoder(const uint8_t* data, size_t size, bool isADTS); |
65 | | IA_ERRORCODE initXAACDecoder(bool isADTS); |
66 | | IA_ERRORCODE initXAACDrc(const uint8_t* data, size_t size); |
67 | | IA_ERRORCODE deInitXAACDecoder(); |
68 | | IA_ERRORCODE deInitMPEGDDDrc(); |
69 | | IA_ERRORCODE configXAACDecoder(uint8_t* inBuffer, uint32_t inBufferLength, |
70 | | int32_t* bytesConsumed); |
71 | | IA_ERRORCODE initMPEGDDDrc(); |
72 | | int configMPEGDDrc(); |
73 | | IA_ERRORCODE decodeXAACStream(uint8_t* inBuffer, uint32_t inBufferLength, |
74 | | int32_t* bytesConsumed, int32_t* outBytes); |
75 | | IA_ERRORCODE getXAACStreamInfo(); |
76 | | IA_ERRORCODE setXAACDRCInfo(int32_t drcCut, int32_t drcBoost, |
77 | | int32_t drcRefLevel, int32_t drcHeavyCompression, |
78 | | int32_t drEffectType); |
79 | | |
80 | | private: |
81 | | void* mXheaacCodecHandle; |
82 | | void* mMpegDDrcHandle; |
83 | | uint32_t mInputBufferSize; |
84 | | uint32_t mOutputFrameLength; |
85 | | int8_t* mInputBuffer; |
86 | | int8_t* mOutputBuffer; |
87 | | int32_t mSampFreq; |
88 | | int32_t mNumChannels; |
89 | | int32_t mPcmWdSz; |
90 | | int32_t mChannelMask; |
91 | | bool mIsCodecInitialized; |
92 | | bool mIsCodecConfigFlushRequired; |
93 | | int8_t* mDrcInBuf; |
94 | | int8_t* mDrcOutBuf; |
95 | | int32_t mMpegDDRCPresent; |
96 | | int32_t mDRCFlag; |
97 | | |
98 | | std::vector<void*> mMemoryVec; |
99 | | std::vector<void*> mDrcMemoryVec; |
100 | | }; |
101 | | |
102 | | extern "C" IA_ERRORCODE ixheaacd_dec_api(pVOID p_ia_module_obj, WORD32 i_cmd, |
103 | | WORD32 i_idx, pVOID pv_value); |
104 | | extern "C" IA_ERRORCODE ia_drc_dec_api(pVOID p_ia_module_obj, WORD32 i_cmd, |
105 | | WORD32 i_idx, pVOID pv_value); |
106 | | extern "C" IA_ERRORCODE ixheaacd_get_config_param(pVOID p_ia_process_api_obj, |
107 | | pWORD32 pi_samp_freq, |
108 | | pWORD32 pi_num_chan, |
109 | | pWORD32 pi_pcm_wd_sz, |
110 | | pWORD32 pi_channel_mask); |
111 | | |
112 | 21.7k | IA_ERRORCODE Codec::initXAACDecoder(bool isADTS) { |
113 | | /* First part */ |
114 | | /* Error Handler Init */ |
115 | | /* Get Library Name, Library Version and API Version */ |
116 | | /* Initialize API structure + Default config set */ |
117 | | /* Set config params from user */ |
118 | | /* Initialize memory tables */ |
119 | | /* Get memory information and allocate memory */ |
120 | | |
121 | 21.7k | mInputBufferSize = 0; |
122 | 21.7k | mInputBuffer = nullptr; |
123 | 21.7k | mOutputBuffer = nullptr; |
124 | | /* Process struct initing end */ |
125 | | |
126 | | /* ******************************************************************/ |
127 | | /* Initialize API structure and set config params to default */ |
128 | | /* ******************************************************************/ |
129 | | /* API size */ |
130 | 21.7k | uint32_t pui_api_size; |
131 | | /* Get the API size */ |
132 | 21.7k | IA_ERRORCODE err_code = |
133 | 21.7k | ixheaacd_dec_api(nullptr, IA_API_CMD_GET_API_SIZE, 0, &pui_api_size); |
134 | | |
135 | | /* Allocate memory for API */ |
136 | 21.7k | mXheaacCodecHandle = malloc(pui_api_size); |
137 | 21.7k | if (!mXheaacCodecHandle) { |
138 | 0 | return IA_FATAL_ERROR; |
139 | 0 | } |
140 | 21.7k | mMemoryVec.push_back(mXheaacCodecHandle); |
141 | | |
142 | | /* Set the config params to default values */ |
143 | 21.7k | err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_INIT, |
144 | 21.7k | IA_CMD_TYPE_INIT_API_PRE_CONFIG_PARAMS, nullptr); |
145 | | |
146 | | /* Get the API size */ |
147 | 21.7k | err_code = ia_drc_dec_api(nullptr, IA_API_CMD_GET_API_SIZE, 0, &pui_api_size); |
148 | | |
149 | | /* Allocate memory for API */ |
150 | 21.7k | mMpegDDrcHandle = malloc(pui_api_size); |
151 | 21.7k | if (!mMpegDDrcHandle) { |
152 | 0 | return IA_FATAL_ERROR; |
153 | 0 | } |
154 | 21.7k | mMemoryVec.push_back(mMpegDDrcHandle); |
155 | | |
156 | | /* Set the config params to default values */ |
157 | 21.7k | err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT, |
158 | 21.7k | IA_CMD_TYPE_INIT_API_PRE_CONFIG_PARAMS, nullptr); |
159 | | |
160 | | /* ******************************************************************/ |
161 | | /* Set config parameters */ |
162 | | /* ******************************************************************/ |
163 | 21.7k | uint32_t ui_mp4_flag = isADTS ? 0 : 1; |
164 | 21.7k | err_code = |
165 | 21.7k | ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM, |
166 | 21.7k | IA_ENHAACPLUS_DEC_CONFIG_PARAM_ISMP4, &ui_mp4_flag); |
167 | | |
168 | | /* ******************************************************************/ |
169 | | /* Initialize Memory info tables */ |
170 | | /* ******************************************************************/ |
171 | 21.7k | uint32_t ui_proc_mem_tabs_size; |
172 | 21.7k | pVOID pv_alloc_ptr; |
173 | | /* Get memory info tables size */ |
174 | 21.7k | err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_MEMTABS_SIZE, |
175 | 21.7k | 0, &ui_proc_mem_tabs_size); |
176 | | |
177 | 21.7k | pv_alloc_ptr = malloc(ui_proc_mem_tabs_size); |
178 | 21.7k | if (!pv_alloc_ptr) { |
179 | 0 | return IA_FATAL_ERROR; |
180 | 0 | } |
181 | 21.7k | mMemoryVec.push_back(pv_alloc_ptr); |
182 | | |
183 | | /* Set pointer for process memory tables */ |
184 | 21.7k | err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_MEMTABS_PTR, 0, |
185 | 21.7k | pv_alloc_ptr); |
186 | | |
187 | | /* initialize the API, post config, fill memory tables */ |
188 | 21.7k | err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_INIT, |
189 | 21.7k | IA_CMD_TYPE_INIT_API_POST_CONFIG_PARAMS, nullptr); |
190 | | |
191 | | /* ******************************************************************/ |
192 | | /* Allocate Memory with info from library */ |
193 | | /* ******************************************************************/ |
194 | | /* There are four different types of memories, that needs to be allocated */ |
195 | | /* persistent,scratch,input and output */ |
196 | 108k | for (int i = 0; i < 4; i++) { |
197 | 87.1k | int ui_size = 0, ui_alignment = 0, ui_type = 0; |
198 | | |
199 | | /* Get memory size */ |
200 | 87.1k | err_code = ixheaacd_dec_api(mXheaacCodecHandle, |
201 | 87.1k | IA_API_CMD_GET_MEM_INFO_SIZE, i, &ui_size); |
202 | | |
203 | | /* Get memory alignment */ |
204 | 87.1k | err_code = |
205 | 87.1k | ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_MEM_INFO_ALIGNMENT, |
206 | 87.1k | i, &ui_alignment); |
207 | | |
208 | | /* Get memory type */ |
209 | 87.1k | err_code = ixheaacd_dec_api(mXheaacCodecHandle, |
210 | 87.1k | IA_API_CMD_GET_MEM_INFO_TYPE, i, &ui_type); |
211 | | |
212 | 87.1k | pv_alloc_ptr = NULL; |
213 | 87.1k | ui_alignment = (ui_alignment + sizeof(void *) - 1) / sizeof(void *); |
214 | 87.1k | ui_alignment = ui_alignment * sizeof(void *); |
215 | 87.1k | if (0 != posix_memalign(&pv_alloc_ptr, ui_alignment, ui_size)) { |
216 | 0 | return IA_FATAL_ERROR; |
217 | 0 | } |
218 | 87.1k | if (!pv_alloc_ptr) { |
219 | 0 | return IA_FATAL_ERROR; |
220 | 0 | } |
221 | 87.1k | mMemoryVec.push_back(pv_alloc_ptr); |
222 | | |
223 | | /* Set the buffer pointer */ |
224 | 87.1k | err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_MEM_PTR, i, |
225 | 87.1k | pv_alloc_ptr); |
226 | | |
227 | 87.1k | if (ui_type == IA_MEMTYPE_INPUT) { |
228 | 21.7k | mInputBuffer = (pWORD8)pv_alloc_ptr; |
229 | 21.7k | mInputBufferSize = ui_size; |
230 | 21.7k | } |
231 | 87.1k | if (ui_type == IA_MEMTYPE_OUTPUT) mOutputBuffer = (pWORD8)pv_alloc_ptr; |
232 | 87.1k | } |
233 | | /* End first part */ |
234 | | |
235 | 21.7k | return IA_NO_ERROR; |
236 | 21.7k | } |
237 | | enum { |
238 | | DRC_TARGET_LEVEL_OFFSET = 6, |
239 | | DRC_ATTENUATION_OFFSET, |
240 | | DRC_BOOST_OFFSET, |
241 | | DRC_COMPRESS_OFFSET, |
242 | | DRC_EFFECT_OFFSET |
243 | | #ifdef LOUDNESS_LEVELING_SUPPORT |
244 | | , |
245 | | DRC_LOUDNESS_LEVELING_OFFSET |
246 | | #endif |
247 | | }; |
248 | | |
249 | 21.7k | IA_ERRORCODE Codec::initXAACDrc(const uint8_t* data, size_t size) { |
250 | 21.7k | IA_ERRORCODE err_code = IA_NO_ERROR; |
251 | 21.7k | unsigned int ui_drc_val; |
252 | | // DRC_PRES_MODE_WRAP_DESIRED_TARGET |
253 | 21.7k | size_t targetLevelOffset = |
254 | 21.7k | std::min((size_t)DRC_TARGET_LEVEL_OFFSET, size - 1); |
255 | 21.7k | int32_t targetRefLevel = data[targetLevelOffset]; |
256 | | |
257 | 21.7k | ui_drc_val = (unsigned int)targetRefLevel; |
258 | 21.7k | err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM, |
259 | 21.7k | IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_TARGET_LEVEL, |
260 | 21.7k | &ui_drc_val); |
261 | | |
262 | | /* Use ui_drc_val from PROP_DRC_OVERRIDE_REF_LEVEL or |
263 | | * DRC_DEFAULT_MOBILE_REF_LEVEL |
264 | | * for IA_ENHAACPLUS_DEC_DRC_TARGET_LOUDNESS too */ |
265 | 21.7k | err_code = |
266 | 21.7k | ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM, |
267 | 21.7k | IA_ENHAACPLUS_DEC_DRC_TARGET_LOUDNESS, &ui_drc_val); |
268 | | |
269 | 21.7k | size_t attenuationOffset = std::min((size_t)DRC_ATTENUATION_OFFSET, size - 1); |
270 | 21.7k | int32_t attenuationFactor = data[attenuationOffset]; |
271 | | |
272 | 21.7k | ui_drc_val = (unsigned int)attenuationFactor; |
273 | 21.7k | err_code = |
274 | 21.7k | ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM, |
275 | 21.7k | IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_CUT, &ui_drc_val); |
276 | | |
277 | | // DRC_PRES_MODE_WRAP_DESIRED_BOOST_FACTOR |
278 | 21.7k | size_t boostOffset = std::min((size_t)DRC_BOOST_OFFSET, size - 1); |
279 | 21.7k | int32_t boostFactor = data[boostOffset]; |
280 | | |
281 | 21.7k | ui_drc_val = (unsigned int)boostFactor; |
282 | 21.7k | err_code = |
283 | 21.7k | ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM, |
284 | 21.7k | IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_BOOST, &ui_drc_val); |
285 | | |
286 | | // DRC_PRES_MODE_WRAP_DESIRED_HEAVY |
287 | 21.7k | size_t compressOffset = std::min((size_t)DRC_COMPRESS_OFFSET, size - 1); |
288 | 21.7k | int32_t compressMode = data[compressOffset]; |
289 | 21.7k | ui_drc_val = (unsigned int)compressMode; |
290 | | |
291 | 21.7k | err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM, |
292 | 21.7k | IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_HEAVY_COMP, |
293 | 21.7k | &ui_drc_val); |
294 | | |
295 | | // AAC_UNIDRC_SET_EFFECT |
296 | 21.7k | size_t effectOffset = std::min((size_t)DRC_EFFECT_OFFSET, size - 1); |
297 | 21.7k | int32_t effectType = data[effectOffset]; |
298 | 21.7k | ui_drc_val = (unsigned int)effectType; |
299 | 21.7k | err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM, |
300 | 21.7k | IA_ENHAACPLUS_DEC_DRC_EFFECT_TYPE, &ui_drc_val); |
301 | | |
302 | 21.7k | #ifdef LOUDNESS_LEVELING_SUPPORT |
303 | | // DRC_LOUDNESS_LEVELING_FLAG |
304 | 21.7k | size_t flagOffset = std::min((size_t)DRC_LOUDNESS_LEVELING_OFFSET, size - 1); |
305 | 21.7k | uint8_t loudnessFlag = data[flagOffset]; |
306 | 21.7k | ui_drc_val = (unsigned int)loudnessFlag; |
307 | 21.7k | err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM, |
308 | 21.7k | IA_XHEAAC_DEC_CONFIG_PARAM_DRC_LOUDNESS_LEVELING, &ui_drc_val); |
309 | 21.7k | #endif |
310 | | |
311 | 21.7k | return IA_NO_ERROR; |
312 | 21.7k | } |
313 | | |
314 | 21.7k | IA_ERRORCODE Codec::deInitXAACDecoder() { |
315 | | /* Error code */ |
316 | 21.7k | IA_ERRORCODE err_code = IA_NO_ERROR; |
317 | | |
318 | 21.7k | if (mXheaacCodecHandle) { |
319 | | /* Tell that the input is over in this buffer */ |
320 | 21.7k | err_code = |
321 | 21.7k | ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_INPUT_OVER, 0, nullptr); |
322 | 21.7k | } |
323 | | |
324 | | /* Irrespective of error returned in IA_API_CMD_INPUT_OVER, free allocated |
325 | | * memory */ |
326 | 171k | for (void* buf : mMemoryVec) { |
327 | 171k | if (buf) free(buf); |
328 | 171k | } |
329 | 21.7k | mMemoryVec.clear(); |
330 | 21.7k | mXheaacCodecHandle = nullptr; |
331 | | |
332 | 21.7k | return err_code; |
333 | 21.7k | } |
334 | | |
335 | 40.5k | IA_ERRORCODE Codec::deInitMPEGDDDrc() { |
336 | 74.9k | for (void* buf : mDrcMemoryVec) { |
337 | 74.9k | if (buf) free(buf); |
338 | 74.9k | } |
339 | 40.5k | mDrcMemoryVec.clear(); |
340 | 40.5k | return IA_NO_ERROR; |
341 | 40.5k | } |
342 | | |
343 | | IA_ERRORCODE Codec::configXAACDecoder(uint8_t* inBuffer, |
344 | | uint32_t inBufferLength, |
345 | 35.0k | int32_t* bytesConsumed) { |
346 | 35.0k | if (mInputBufferSize < inBufferLength) { |
347 | 2.43k | inBufferLength = mInputBufferSize; |
348 | 2.43k | } |
349 | | /* Copy the buffer passed by Android plugin to codec input buffer */ |
350 | 35.0k | memcpy(mInputBuffer, inBuffer, inBufferLength); |
351 | | |
352 | | /* Set number of bytes to be processed */ |
353 | 35.0k | IA_ERRORCODE err_code = ixheaacd_dec_api( |
354 | 35.0k | mXheaacCodecHandle, IA_API_CMD_SET_INPUT_BYTES, 0, &inBufferLength); |
355 | | |
356 | 35.0k | if (mIsCodecConfigFlushRequired) { |
357 | | /* If codec is already initialized, then GA header is passed again */ |
358 | | /* Need to call the Flush API instead of INIT_PROCESS */ |
359 | 0 | mIsCodecInitialized = |
360 | 0 | false; /* Codec needs to be Reinitialized after flush */ |
361 | 0 | err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_INIT, |
362 | 0 | IA_CMD_TYPE_GA_HDR, nullptr); |
363 | |
|
364 | 35.0k | } else { |
365 | | /* Initialize the process */ |
366 | 35.0k | err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_INIT, |
367 | 35.0k | IA_CMD_TYPE_INIT_PROCESS, nullptr); |
368 | 35.0k | } |
369 | | |
370 | 35.0k | uint32_t ui_init_done; |
371 | | /* Checking for end of initialization */ |
372 | 35.0k | err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_INIT, |
373 | 35.0k | IA_CMD_TYPE_INIT_DONE_QUERY, &ui_init_done); |
374 | | |
375 | | /* How much buffer is used in input buffers */ |
376 | 35.0k | err_code = ixheaacd_dec_api( |
377 | 35.0k | mXheaacCodecHandle, IA_API_CMD_GET_CURIDX_INPUT_BUF, 0, bytesConsumed); |
378 | | |
379 | 35.0k | if (ui_init_done) { |
380 | 18.7k | err_code = getXAACStreamInfo(); |
381 | | |
382 | 18.7k | mIsCodecInitialized = true; |
383 | | |
384 | 18.7k | err_code = configMPEGDDrc(); |
385 | 18.7k | } |
386 | | |
387 | 35.0k | return IA_NO_ERROR; |
388 | 35.0k | } |
389 | 18.7k | IA_ERRORCODE Codec::initMPEGDDDrc() { |
390 | 18.7k | IA_ERRORCODE err_code = IA_NO_ERROR; |
391 | | |
392 | 56.1k | for (int i = 0; i < (WORD32)2; i++) { |
393 | 37.4k | WORD32 ui_size, ui_alignment, ui_type; |
394 | 37.4k | pVOID pv_alloc_ptr; |
395 | | |
396 | | /* Get memory size */ |
397 | 37.4k | err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_GET_MEM_INFO_SIZE, i, |
398 | 37.4k | &ui_size); |
399 | | |
400 | | /* Get memory alignment */ |
401 | 37.4k | err_code = ia_drc_dec_api( |
402 | 37.4k | mMpegDDrcHandle, IA_API_CMD_GET_MEM_INFO_ALIGNMENT, i, &ui_alignment); |
403 | | |
404 | | /* Get memory type */ |
405 | 37.4k | err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_GET_MEM_INFO_TYPE, i, |
406 | 37.4k | &ui_type); |
407 | | |
408 | 37.4k | pv_alloc_ptr = malloc(ui_size); |
409 | 37.4k | if (pv_alloc_ptr == nullptr) { |
410 | 0 | return IA_FATAL_ERROR; |
411 | 0 | } |
412 | 37.4k | mDrcMemoryVec.push_back(pv_alloc_ptr); |
413 | | |
414 | | /* Set the buffer pointer */ |
415 | 37.4k | err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_MEM_PTR, i, |
416 | 37.4k | pv_alloc_ptr); |
417 | 37.4k | } |
418 | | |
419 | 18.7k | mDrcInBuf = (int8_t*)malloc(IA_DRC_DEC_IN_OUT_BUF_SIZE); |
420 | 18.7k | if (mDrcInBuf == nullptr) { |
421 | 0 | return IA_FATAL_ERROR; |
422 | 0 | } |
423 | 18.7k | mDrcMemoryVec.push_back(mDrcInBuf); |
424 | | |
425 | 18.7k | err_code = |
426 | 18.7k | ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_MEM_PTR, 2, mDrcInBuf); |
427 | | |
428 | 18.7k | mDrcOutBuf = (int8_t*)malloc(IA_DRC_DEC_IN_OUT_BUF_SIZE); |
429 | 18.7k | if (mDrcOutBuf == nullptr) { |
430 | 0 | return IA_FATAL_ERROR; |
431 | 0 | } |
432 | 18.7k | mDrcMemoryVec.push_back(mDrcOutBuf); |
433 | | |
434 | 18.7k | err_code = |
435 | 18.7k | ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_MEM_PTR, 3, mDrcOutBuf); |
436 | | |
437 | 18.7k | return IA_NO_ERROR; |
438 | 18.7k | } |
439 | 18.7k | int Codec::configMPEGDDrc() { |
440 | 18.7k | IA_ERRORCODE err_code = IA_NO_ERROR; |
441 | 18.7k | int i_effect_type; |
442 | 18.7k | int i_loud_norm; |
443 | 18.7k | int i_target_loudness; |
444 | 18.7k | unsigned int i_sbr_mode; |
445 | 18.7k | uint32_t ui_proc_mem_tabs_size = 0; |
446 | 18.7k | pVOID pv_alloc_ptr = NULL; |
447 | | |
448 | | /* Sampling Frequency */ |
449 | 18.7k | err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM, |
450 | 18.7k | IA_DRC_DEC_CONFIG_PARAM_SAMP_FREQ, &mSampFreq); |
451 | | |
452 | | /* Total Number of Channels */ |
453 | 18.7k | err_code = |
454 | 18.7k | ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM, |
455 | 18.7k | IA_DRC_DEC_CONFIG_PARAM_NUM_CHANNELS, &mNumChannels); |
456 | | |
457 | | /* PCM word size */ |
458 | 18.7k | err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM, |
459 | 18.7k | IA_DRC_DEC_CONFIG_PARAM_PCM_WDSZ, &mPcmWdSz); |
460 | | |
461 | | /*Set Effect Type*/ |
462 | 18.7k | err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM, |
463 | 18.7k | IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_EFFECT_TYPE, |
464 | 18.7k | &i_effect_type); |
465 | | |
466 | 18.7k | err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM, |
467 | 18.7k | IA_DRC_DEC_CONFIG_DRC_EFFECT_TYPE, &i_effect_type); |
468 | | |
469 | | /*Set target loudness */ |
470 | 18.7k | err_code = ixheaacd_dec_api( |
471 | 18.7k | mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM, |
472 | 18.7k | IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_TARGET_LOUDNESS, &i_target_loudness); |
473 | | |
474 | 18.7k | err_code = |
475 | 18.7k | ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM, |
476 | 18.7k | IA_DRC_DEC_CONFIG_DRC_TARGET_LOUDNESS, &i_target_loudness); |
477 | | |
478 | | /*Set loud_norm_flag*/ |
479 | 18.7k | err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM, |
480 | 18.7k | IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_LOUD_NORM, |
481 | 18.7k | &i_loud_norm); |
482 | | |
483 | 18.7k | err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM, |
484 | 18.7k | IA_DRC_DEC_CONFIG_DRC_LOUD_NORM, &i_loud_norm); |
485 | | |
486 | 18.7k | err_code = |
487 | 18.7k | ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM, |
488 | 18.7k | IA_ENHAACPLUS_DEC_CONFIG_PARAM_SBR_MODE, &i_sbr_mode); |
489 | | |
490 | | /* Get memory info tables size */ |
491 | 18.7k | err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_GET_MEMTABS_SIZE, 0, |
492 | 18.7k | &ui_proc_mem_tabs_size); |
493 | | |
494 | 18.7k | pv_alloc_ptr = malloc(ui_proc_mem_tabs_size); |
495 | 18.7k | if (pv_alloc_ptr == NULL) { |
496 | 0 | return IA_FATAL_ERROR; |
497 | 0 | } |
498 | 18.7k | memset(pv_alloc_ptr, 0, ui_proc_mem_tabs_size); |
499 | 18.7k | mMemoryVec.push_back(pv_alloc_ptr); |
500 | | |
501 | | /* Set pointer for process memory tables */ |
502 | 18.7k | err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_MEMTABS_PTR, 0, |
503 | 18.7k | pv_alloc_ptr); |
504 | | |
505 | 18.7k | err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT, |
506 | 18.7k | IA_CMD_TYPE_INIT_API_POST_CONFIG_PARAMS, nullptr); |
507 | | |
508 | | /* Free any memory that is allocated for MPEG D Drc so far */ |
509 | 18.7k | deInitMPEGDDDrc(); |
510 | | |
511 | 18.7k | err_code = initMPEGDDDrc(); |
512 | 18.7k | if (err_code != IA_NO_ERROR) { |
513 | 0 | deInitMPEGDDDrc(); |
514 | 0 | return err_code; |
515 | 0 | } |
516 | | |
517 | | /* DRC buffers |
518 | | buf[0] - contains extension element pay load loudness related |
519 | | buf[1] - contains extension element pay load*/ |
520 | 18.7k | { |
521 | 18.7k | VOID* p_array[2][16]; |
522 | 18.7k | WORD32 ii; |
523 | 18.7k | WORD32 buf_sizes[2][16]; |
524 | 18.7k | WORD32 num_elements; |
525 | 18.7k | WORD32 num_config_ext; |
526 | 18.7k | WORD32 bit_str_fmt = 1; |
527 | | |
528 | 18.7k | WORD32 uo_num_chan; |
529 | | |
530 | 18.7k | memset(buf_sizes, 0, 32 * sizeof(WORD32)); |
531 | | |
532 | 18.7k | err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM, |
533 | 18.7k | IA_ENHAACPLUS_DEC_CONFIG_EXT_ELE_BUF_SIZES, |
534 | 18.7k | &buf_sizes[0][0]); |
535 | | |
536 | 18.7k | err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM, |
537 | 18.7k | IA_ENHAACPLUS_DEC_CONFIG_EXT_ELE_PTR, &p_array); |
538 | | |
539 | 18.7k | err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT, |
540 | 18.7k | IA_CMD_TYPE_INIT_SET_BUFF_PTR, nullptr); |
541 | | |
542 | 18.7k | err_code = |
543 | 18.7k | ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM, |
544 | 18.7k | IA_ENHAACPLUS_DEC_CONFIG_NUM_ELE, &num_elements); |
545 | | |
546 | 18.7k | err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM, |
547 | 18.7k | IA_ENHAACPLUS_DEC_CONFIG_NUM_CONFIG_EXT, |
548 | 18.7k | &num_config_ext); |
549 | | |
550 | 27.9k | for (ii = 0; ii < num_config_ext; ii++) { |
551 | | /*copy loudness bitstream*/ |
552 | 9.19k | if (buf_sizes[0][ii] > 0) { |
553 | 1.21k | memcpy(mDrcInBuf, p_array[0][ii], buf_sizes[0][ii]); |
554 | | |
555 | | /*Set bitstream_split_format */ |
556 | 1.21k | err_code = |
557 | 1.21k | ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM, |
558 | 1.21k | IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT, &bit_str_fmt); |
559 | | |
560 | | /* Set number of bytes to be processed */ |
561 | 1.21k | err_code = |
562 | 1.21k | ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_INPUT_BYTES_IL_BS, 0, |
563 | 1.21k | &buf_sizes[0][ii]); |
564 | | |
565 | | /* Execute process */ |
566 | 1.21k | err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT, |
567 | 1.21k | IA_CMD_TYPE_INIT_CPY_IL_BSF_BUFF, nullptr); |
568 | | |
569 | 1.21k | mDRCFlag = 1; |
570 | 1.21k | } |
571 | 9.19k | } |
572 | | |
573 | 36.3k | for (ii = 0; ii < num_elements; ii++) { |
574 | | /*copy config bitstream*/ |
575 | 17.6k | if (buf_sizes[1][ii] > 0) { |
576 | 1.57k | memcpy(mDrcInBuf, p_array[1][ii], buf_sizes[1][ii]); |
577 | | /* Set number of bytes to be processed */ |
578 | | |
579 | | /*Set bitstream_split_format */ |
580 | 1.57k | err_code = |
581 | 1.57k | ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM, |
582 | 1.57k | IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT, &bit_str_fmt); |
583 | | |
584 | 1.57k | err_code = |
585 | 1.57k | ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_INPUT_BYTES_IC_BS, 0, |
586 | 1.57k | &buf_sizes[1][ii]); |
587 | | |
588 | | /* Execute process */ |
589 | 1.57k | err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT, |
590 | 1.57k | IA_CMD_TYPE_INIT_CPY_IC_BSF_BUFF, nullptr); |
591 | | |
592 | 1.57k | mDRCFlag = 1; |
593 | 1.57k | } |
594 | 17.6k | } |
595 | | |
596 | 18.7k | if (mDRCFlag == 1) { |
597 | 2.02k | mMpegDDRCPresent = 1; |
598 | 16.7k | } else { |
599 | 16.7k | mMpegDDRCPresent = 0; |
600 | 16.7k | } |
601 | | |
602 | | /*Read interface buffer config file bitstream*/ |
603 | 18.7k | if (mMpegDDRCPresent == 1) { |
604 | 2.02k | WORD32 interface_is_present = 1; |
605 | | |
606 | 2.02k | if (i_sbr_mode != 0) { |
607 | 920 | if (i_sbr_mode == 1) { |
608 | 891 | mOutputFrameLength = 2048; |
609 | 891 | } else if (i_sbr_mode == 3) { |
610 | 29 | mOutputFrameLength = 4096; |
611 | 29 | } else { |
612 | 0 | mOutputFrameLength = 1024; |
613 | 0 | } |
614 | 1.10k | } else { |
615 | 1.10k | mOutputFrameLength = 4096; |
616 | 1.10k | } |
617 | | |
618 | 2.02k | err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM, |
619 | 2.02k | IA_DRC_DEC_CONFIG_PARAM_FRAME_SIZE, |
620 | 2.02k | (WORD32*)&mOutputFrameLength); |
621 | | |
622 | 2.02k | err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM, |
623 | 2.02k | IA_DRC_DEC_CONFIG_PARAM_INT_PRESENT, |
624 | 2.02k | &interface_is_present); |
625 | | |
626 | | /* Execute process */ |
627 | 2.02k | err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT, |
628 | 2.02k | IA_CMD_TYPE_INIT_CPY_IN_BSF_BUFF, nullptr); |
629 | | |
630 | 2.02k | err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT, |
631 | 2.02k | IA_CMD_TYPE_INIT_PROCESS, nullptr); |
632 | | |
633 | 2.02k | err_code = |
634 | 2.02k | ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_GET_CONFIG_PARAM, |
635 | 2.02k | IA_DRC_DEC_CONFIG_PARAM_NUM_CHANNELS, &uo_num_chan); |
636 | 2.02k | } |
637 | 18.7k | } |
638 | | |
639 | 18.7k | return err_code; |
640 | 18.7k | } |
641 | 21.7k | IA_ERRORCODE Codec::initDecoder(const uint8_t* data, size_t size, bool isADTS) { |
642 | 21.7k | IA_ERRORCODE err_code = IA_NO_ERROR; |
643 | | |
644 | 21.7k | err_code = initXAACDecoder(isADTS); |
645 | 21.7k | if (err_code != IA_NO_ERROR) { |
646 | | /* Call deInit to free any allocated memory */ |
647 | 0 | deInitXAACDecoder(); |
648 | 0 | return IA_FATAL_ERROR; |
649 | 0 | } |
650 | | |
651 | 21.7k | err_code = initXAACDrc(data, size); |
652 | | |
653 | 21.7k | return IA_NO_ERROR; |
654 | 21.7k | } |
655 | | IA_ERRORCODE Codec::decodeXAACStream(uint8_t* inBuffer, uint32_t inBufferLength, |
656 | | int32_t* bytesConsumed, |
657 | 542k | int32_t* outBytes) { |
658 | 542k | if (mInputBufferSize < inBufferLength) { |
659 | 234k | inBufferLength = mInputBufferSize; |
660 | 234k | } |
661 | | /* If codec is not initialized, call configXAACDecoder decoder again */ |
662 | 542k | if (!mIsCodecInitialized) { |
663 | 13.2k | configXAACDecoder(inBuffer, inBufferLength, bytesConsumed); |
664 | 13.2k | } |
665 | | /* Copy the buffer passed by Android plugin to codec input buffer */ |
666 | 542k | memcpy(mInputBuffer, inBuffer, inBufferLength); |
667 | | |
668 | | /* Set number of bytes to be processed */ |
669 | 542k | IA_ERRORCODE err_code = ixheaacd_dec_api( |
670 | 542k | mXheaacCodecHandle, IA_API_CMD_SET_INPUT_BYTES, 0, &inBufferLength); |
671 | | |
672 | | /* Execute process */ |
673 | 542k | err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_EXECUTE, |
674 | 542k | IA_CMD_TYPE_DO_EXECUTE, nullptr); |
675 | | |
676 | | /* Checking for end of processing */ |
677 | 542k | uint32_t ui_exec_done; |
678 | 542k | err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_EXECUTE, |
679 | 542k | IA_CMD_TYPE_DONE_QUERY, &ui_exec_done); |
680 | | |
681 | 542k | if (ui_exec_done != 1) { |
682 | 542k | VOID* p_array; // ITTIAM:buffer to handle gain payload |
683 | 542k | WORD32 buf_size = 0; // ITTIAM:gain payload length |
684 | 542k | WORD32 bit_str_fmt = 1; |
685 | 542k | WORD32 gain_stream_flag = 1; |
686 | | |
687 | 542k | err_code = |
688 | 542k | ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM, |
689 | 542k | IA_ENHAACPLUS_DEC_CONFIG_GAIN_PAYLOAD_LEN, &buf_size); |
690 | | |
691 | 542k | err_code = |
692 | 542k | ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM, |
693 | 542k | IA_ENHAACPLUS_DEC_CONFIG_GAIN_PAYLOAD_BUF, &p_array); |
694 | | |
695 | 542k | if (buf_size > 0) { |
696 | | /*Set bitstream_split_format */ |
697 | 3.21k | err_code = |
698 | 3.21k | ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM, |
699 | 3.21k | IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT, &bit_str_fmt); |
700 | | |
701 | 3.21k | memcpy(mDrcInBuf, p_array, buf_size); |
702 | | /* Set number of bytes to be processed */ |
703 | 3.21k | err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_INPUT_BYTES_BS, |
704 | 3.21k | 0, &buf_size); |
705 | | |
706 | 3.21k | err_code = |
707 | 3.21k | ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM, |
708 | 3.21k | IA_DRC_DEC_CONFIG_GAIN_STREAM_FLAG, &gain_stream_flag); |
709 | | |
710 | | /* Execute process */ |
711 | 3.21k | err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT, |
712 | 3.21k | IA_CMD_TYPE_INIT_CPY_BSF_BUFF, nullptr); |
713 | | |
714 | 3.21k | mMpegDDRCPresent = 1; |
715 | 3.21k | } |
716 | 542k | } |
717 | | |
718 | | /* How much buffer is used in input buffers */ |
719 | 542k | err_code = ixheaacd_dec_api( |
720 | 542k | mXheaacCodecHandle, IA_API_CMD_GET_CURIDX_INPUT_BUF, 0, bytesConsumed); |
721 | | |
722 | | /* Get the output bytes */ |
723 | 542k | err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_OUTPUT_BYTES, |
724 | 542k | 0, outBytes); |
725 | | |
726 | 542k | if (mMpegDDRCPresent == 1) { |
727 | 45.7k | memcpy(mDrcInBuf, mOutputBuffer, *outBytes); |
728 | 45.7k | err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_INPUT_BYTES, 0, |
729 | 45.7k | outBytes); |
730 | | |
731 | 45.7k | err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_EXECUTE, |
732 | 45.7k | IA_CMD_TYPE_DO_EXECUTE, nullptr); |
733 | | |
734 | 45.7k | memcpy(mOutputBuffer, mDrcOutBuf, *outBytes); |
735 | 45.7k | } |
736 | 542k | return IA_NO_ERROR; |
737 | 542k | } |
738 | | |
739 | 18.7k | IA_ERRORCODE Codec::getXAACStreamInfo() { |
740 | 18.7k | IA_ERRORCODE err_code = IA_NO_ERROR; |
741 | | |
742 | | /* Sampling frequency */ |
743 | 18.7k | err_code = |
744 | 18.7k | ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM, |
745 | 18.7k | IA_ENHAACPLUS_DEC_CONFIG_PARAM_SAMP_FREQ, &mSampFreq); |
746 | | |
747 | | /* Total Number of Channels */ |
748 | 18.7k | err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM, |
749 | 18.7k | IA_ENHAACPLUS_DEC_CONFIG_PARAM_NUM_CHANNELS, |
750 | 18.7k | &mNumChannels); |
751 | | |
752 | 18.7k | if (mNumChannels > MAX_CHANNEL_COUNT) { |
753 | 0 | return IA_FATAL_ERROR; |
754 | 0 | } |
755 | | |
756 | | /* PCM word size */ |
757 | 18.7k | err_code = |
758 | 18.7k | ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM, |
759 | 18.7k | IA_ENHAACPLUS_DEC_CONFIG_PARAM_PCM_WDSZ, &mPcmWdSz); |
760 | | |
761 | 18.7k | if ((mPcmWdSz / 8) != 2) { |
762 | 0 | return IA_FATAL_ERROR; |
763 | 0 | } |
764 | | |
765 | | /* channel mask to tell the arrangement of channels in bit stream */ |
766 | 18.7k | err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM, |
767 | 18.7k | IA_ENHAACPLUS_DEC_CONFIG_PARAM_CHANNEL_MASK, |
768 | 18.7k | &mChannelMask); |
769 | | |
770 | | /* Channel mode to tell MONO/STEREO/DUAL-MONO/NONE_OF_THESE */ |
771 | 18.7k | uint32_t ui_channel_mode; |
772 | 18.7k | err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM, |
773 | 18.7k | IA_ENHAACPLUS_DEC_CONFIG_PARAM_CHANNEL_MODE, |
774 | 18.7k | &ui_channel_mode); |
775 | | |
776 | | /* Channel mode to tell SBR PRESENT/NOT_PRESENT */ |
777 | 18.7k | uint32_t ui_sbr_mode; |
778 | 18.7k | err_code = |
779 | 18.7k | ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM, |
780 | 18.7k | IA_ENHAACPLUS_DEC_CONFIG_PARAM_SBR_MODE, &ui_sbr_mode); |
781 | | |
782 | | /* mOutputFrameLength = 1024 * (1 + SBR_MODE) for AAC */ |
783 | | /* For USAC it could be 1024 * 3 , support to query */ |
784 | | /* not yet added in codec */ |
785 | 18.7k | mOutputFrameLength = 1024 * (1 + ui_sbr_mode); |
786 | | |
787 | 18.7k | return IA_NO_ERROR; |
788 | 18.7k | } |
789 | | |
790 | | IA_ERRORCODE Codec::setXAACDRCInfo(int32_t drcCut, int32_t drcBoost, |
791 | | int32_t drcRefLevel, |
792 | | int32_t drcHeavyCompression, |
793 | 0 | int32_t drEffectType) { |
794 | 0 | IA_ERRORCODE err_code = IA_NO_ERROR; |
795 | |
|
796 | 0 | int32_t ui_drc_enable = 1; |
797 | 0 | err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM, |
798 | 0 | IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_ENABLE, |
799 | 0 | &ui_drc_enable); |
800 | |
|
801 | 0 | if (drcCut != -1) { |
802 | 0 | err_code = |
803 | 0 | ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM, |
804 | 0 | IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_CUT, &drcCut); |
805 | 0 | } |
806 | |
|
807 | 0 | if (drcBoost != -1) { |
808 | 0 | err_code = |
809 | 0 | ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM, |
810 | 0 | IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_BOOST, &drcBoost); |
811 | 0 | } |
812 | |
|
813 | 0 | if (drcRefLevel != -1) { |
814 | 0 | err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM, |
815 | 0 | IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_TARGET_LEVEL, |
816 | 0 | &drcRefLevel); |
817 | 0 | } |
818 | |
|
819 | 0 | if (drcRefLevel != -1) { |
820 | 0 | err_code = |
821 | 0 | ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM, |
822 | 0 | IA_ENHAACPLUS_DEC_DRC_TARGET_LOUDNESS, &drcRefLevel); |
823 | 0 | } |
824 | |
|
825 | 0 | if (drcHeavyCompression != -1) { |
826 | 0 | err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM, |
827 | 0 | IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_HEAVY_COMP, |
828 | 0 | &drcHeavyCompression); |
829 | 0 | } |
830 | |
|
831 | 0 | err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM, |
832 | 0 | IA_ENHAACPLUS_DEC_DRC_EFFECT_TYPE, &drEffectType); |
833 | |
|
834 | 0 | int32_t i_effect_type, i_target_loudness, i_loud_norm; |
835 | | /*Set Effect Type*/ |
836 | 0 | err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM, |
837 | 0 | IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_EFFECT_TYPE, |
838 | 0 | &i_effect_type); |
839 | |
|
840 | 0 | err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM, |
841 | 0 | IA_DRC_DEC_CONFIG_DRC_EFFECT_TYPE, &i_effect_type); |
842 | | |
843 | | /*Set target loudness */ |
844 | 0 | err_code = ixheaacd_dec_api( |
845 | 0 | mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM, |
846 | 0 | IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_TARGET_LOUDNESS, &i_target_loudness); |
847 | |
|
848 | 0 | err_code = |
849 | 0 | ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM, |
850 | 0 | IA_DRC_DEC_CONFIG_DRC_TARGET_LOUDNESS, &i_target_loudness); |
851 | | |
852 | | /*Set loud_norm_flag*/ |
853 | 0 | err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM, |
854 | 0 | IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_LOUD_NORM, |
855 | 0 | &i_loud_norm); |
856 | |
|
857 | 0 | err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM, |
858 | 0 | IA_DRC_DEC_CONFIG_DRC_LOUD_NORM, &i_loud_norm); |
859 | |
|
860 | 0 | return IA_NO_ERROR; |
861 | 0 | } |
862 | | |
863 | 21.7k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
864 | 21.7k | int status; |
865 | 21.7k | int num_proc_iterations = 0; |
866 | 21.7k | if (size < 1) return 0; |
867 | 21.7k | Codec* codec = new Codec(); |
868 | 21.7k | bool isADTS = false; |
869 | 21.7k | if (size >= 2) { |
870 | 21.7k | if ((data[0] == 0xFF) && ((data[1] & 0xF0) == 0xF0)) { |
871 | 19.4k | isADTS = true; |
872 | 19.4k | } |
873 | 21.7k | } |
874 | 21.7k | status = codec->initDecoder(data, size, isADTS); |
875 | 21.7k | if (0 == status) { |
876 | 21.7k | int32_t bytesConsumed = 0; |
877 | 21.7k | status = codec->configXAACDecoder((uint8_t*)data, size, &bytesConsumed); |
878 | 563k | while ((int32_t)size > bytesConsumed) { |
879 | 542k | int32_t numOutBytes; |
880 | 542k | size -= bytesConsumed; |
881 | 542k | data += bytesConsumed; |
882 | 542k | status = codec->decodeXAACStream((uint8_t*)data, size, &bytesConsumed, |
883 | 542k | &numOutBytes); |
884 | 542k | num_proc_iterations++; |
885 | | /* Stop processing after 500 frames */ |
886 | 542k | if (num_proc_iterations > 500) |
887 | 60 | break; |
888 | | |
889 | | /* If decoder doesn't consume any bytes, advance by 4 bytes */ |
890 | 542k | if (0 == bytesConsumed) bytesConsumed = 4; |
891 | 542k | } |
892 | 21.7k | } |
893 | 21.7k | status = codec->deInitXAACDecoder(); |
894 | 21.7k | status = codec->deInitMPEGDDDrc(); |
895 | 21.7k | delete codec; |
896 | 21.7k | return 0; |
897 | 21.7k | } |