1 /******************************************************************************
2 * *
3 * Copyright (C) 2018 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 #include <string.h>
21 #include <stdlib.h>
22 #include <stdio.h>
23
24 #define AOSP_CHANGE
25
26 #include "ixheaacd_fileifc.h"
27 #include "ixheaacd_type_def.h"
28 #include "ixheaacd_error_standards.h"
29 #include "ixheaacd_error_handler.h"
30 #include "ixheaacd_apicmd_standards.h"
31 #include "ixheaacd_memory_standards.h"
32 #include "ixheaacd_aac_config.h"
33 #include "ixheaacd_metadata_read.h"
34 #include "impd_drc_config_params.h"
35
36 IA_ERRORCODE ixheaacd_dec_api(pVOID p_ia_module_obj, WORD32 i_cmd, WORD32 i_idx,
37 pVOID pv_value);
38
39 IA_ERRORCODE ia_drc_dec_api(pVOID p_ia_module_obj, WORD32 i_cmd, WORD32 i_idx,
40 pVOID pv_value);
41
42 VOID ixheaacd_error_handler_init();
43 VOID ia_testbench_error_handler_init();
44 VOID metadata_mp4_stsz_size_free(metadata_info *meta_info);
45
46 extern ia_error_info_struct ixheaacd_ia_testbench_error_info;
47 extern ia_error_info_struct ixheaacd_error_info;
48
49 /*****************************************************************************/
50 /* Process select hash defines */
51 /*****************************************************************************/
52 #define WAV_HEADER
53 #define DISPLAY_MESSAGE
54
55 /*****************************************************************************/
56 /* Constant hash defines */
57 /*****************************************************************************/
58 #define MAX_STACK_PROC 10
59 #define MAX_MEM_ALLOCS 100
60 #define IA_MAX_CMD_LINE_LENGTH 300
61 #define IA_MAX_ARGS 20
62 #define IA_SCREEN_WIDTH 80
63
64 /*****************************************************************************/
65 /* Error codes for the testbench */
66 /*****************************************************************************/
67 #define IA_TESTBENCH_MFMAN_FATAL_MEM_ALLOC_FAILED 0xFFFF8000
68 #define IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED 0xFFFF8001
69
70 #define IA_HE_AAC_DEC_TABLE_RELOCATABLE_ENABLE 0
71
72 #ifdef ARM_PROFILE_HW
73 #include <sys/time.h>
74 #define CLK_FREQ_BOARD_MHZ 716 // a9 omap4430 board
75 //#define CLK_FREQ_BOARD_MHZ 1555 //Nexus6P
76 //#define CLK_FREQ_BOARD_MHZ 2035 //Tegra Board
77 //#define CLK_FREQ_BOARD_MHZ 550 //a8 board
78 //#define CLK_FREQ_BOARD_MHZ 297 //dm365 board
79 //#define CLK_FREQ_BOARD_MHZ 1209.6 //a5 board
80 #endif
81 #ifdef ARM_PROFILE_HW
itGetMs(void)82 long long itGetMs(void) {
83 struct timeval t;
84 long long currTime;
85
86 if (gettimeofday(&t, NULL) == -1) {
87 printf("Error in gettimeofday. It has returned -1. \n");
88 }
89 currTime = ((t.tv_sec * 1000 * 1000) + (t.tv_usec));
90 return currTime;
91 }
92 #endif
93 /*****************************************************************************/
94 /* Global variables */
95 /*****************************************************************************/
96 pVOID g_pv_arr_alloc_memory[MAX_MEM_ALLOCS];
97 WORD g_w_malloc_count;
98 FILE *g_pf_out;
99 FileWrapperPtr g_pf_inp; /* file pointer to bitstream file (mp4) */
100
101 WORD32 mpeg_d_drc_on = 0;
102
103 metadata_info meta_info; // metadata pointer;
104 WORD32 ixheaacd_i_bytes_to_read;
105 WORD32 prev_i_bytes_to_read;
106 WORD32 flush_frame = 0;
107 FILE *g_pf_meta;
108
109 WORD32 raw_testing = 0;
110 WORD32 eld_testing = 0;
111 WORD32 ec_enable = 0;
112
113 #define _IA_PRINT_ERROR(p_mod_err_info, context, e) \
114 if ((e) != IA_NO_ERROR) { \
115 ixheaacd_error_handler((p_mod_err_info), (context), (e)); \
116 }
117
118 #ifndef WIN32
ia_fwrite(pVOID buffer[],int size,int nwords,FILE * fp)119 int ia_fwrite(pVOID buffer[], int size, int nwords, FILE *fp) {
120 int i, j;
121 pWORD8 pb_buf = (pWORD8)buffer;
122
123 for (i = 0; i < nwords; i++) {
124 for (j = 0; j < size; j++) {
125 putc(pb_buf[i * size + j], fp);
126 }
127 }
128 return 1;
129 }
130
131 #endif
132
133 #ifdef WAV_HEADER
134 #ifndef ARM_PROFILE_BOARD
135 /*****************************************************************************/
136 /* */
137 /* Function name : ixheaacd_write16_bits_lh */
138 /* */
139 /* Description : write 16 bits low high (always little endian) */
140 /* */
141 /* Inputs : none */
142 /* */
143 /* Globals : pVOID g_pv_arr_alloc_memory[MAX_MEM_ALLOCS]; */
144 /* WORD g_w_malloc_count; */
145 /* FILE *g_pf_inp, *g_pf_out; */
146 /* */
147 /* Processing : write 16 bits low high (always little endian) */
148 /* */
149 /* Outputs : none */
150 /* */
151 /* Returns : none */
152 /* */
153 /* Issues : none */
154 /* */
155 /* Revision history : */
156 /* */
157 /* DD MM YYYY Author Changes */
158 /* 29 07 2005 Ittiam Created */
159 /* */
160 /*****************************************************************************/
161
ixheaacd_write16_bits_lh(FILE * fp,WORD32 i)162 static VOID ixheaacd_write16_bits_lh(FILE *fp, WORD32 i) {
163 putc(i & 0xff, fp);
164 putc((i >> 8) & 0xff, fp);
165 }
166
167 /*****************************************************************************/
168 /* */
169 /* Function name : ixheaacd_write32_bits_lh */
170 /* */
171 /* Description : write 32 bits low high (always little endian) */
172 /* */
173 /* Inputs : none */
174 /* */
175 /* Globals : FILE* fp (file to write) */
176 /* WORD32 i (value to write) */
177 /* */
178 /* Processing : write 32 bits low high (always little endian) */
179 /* */
180 /* Outputs : none */
181 /* */
182 /* Returns : none */
183 /* */
184 /* Issues : none */
185 /* */
186 /* Revision history : */
187 /* */
188 /* DD MM YYYY Author Changes */
189 /* 29 07 2005 Ittiam Created */
190 /* */
191 /*****************************************************************************/
192
ixheaacd_write32_bits_lh(FILE * fp,WORD32 i)193 static VOID ixheaacd_write32_bits_lh(FILE *fp, WORD32 i) {
194 ixheaacd_write16_bits_lh(fp, (WORD32)(i & 0xffffL));
195 ixheaacd_write16_bits_lh(fp, (WORD32)((i >> 16) & 0xffffL));
196 }
197
198 /*****************************************************************************/
199 /* */
200 /* Function name : write_wav_header */
201 /* */
202 /* Description : Write wav header to a wav file */
203 /* */
204 /* Inputs : none */
205 /* */
206 /* Globals : FILE* fp (file to write) */
207 /* WORD32 pcmbytes (total bytes in wav file) */
208 /* WORD32 freq (sampling freq) */
209 /* WORD32 channels (output channels) */
210 /* WORD32 bits (bits per sample) */
211 /* */
212 /* Processing : Write wav header */
213 /* */
214 /* Outputs : none */
215 /* */
216 /* Returns : none */
217 /* */
218 /* Issues : none */
219 /* */
220 /* Revision history : */
221 /* */
222 /* DD MM YYYY Author Changes */
223 /* 29 07 2005 Ittiam Created */
224 /* */
225 /*****************************************************************************/
226
write_wav_header(FILE * fp,WORD32 pcmbytes,WORD32 freq,WORD32 channels,WORD32 bits,WORD32 i_channel_mask)227 WORD32 write_wav_header(FILE *fp, WORD32 pcmbytes, WORD32 freq, WORD32 channels,
228 WORD32 bits, WORD32 i_channel_mask) {
229 if (channels > 2) {
230 WORD32 bytes = (bits + 7) / 8;
231 fwrite("RIFF", 1, 4, fp); /* label */
232 ixheaacd_write32_bits_lh(
233 fp, pcmbytes + 44 - 8); /* length in bytes without header */
234 fwrite("WAVEfmt ", 2, 4, fp); /* 2 labels */
235 /* tag for WAVE_FORMAT_EXTENSIBLE */
236 if (channels > 2) {
237 ixheaacd_write16_bits_lh(fp, 0x28);
238 ixheaacd_write16_bits_lh(fp, 0x00);
239 ixheaacd_write16_bits_lh(fp, 0xfffe);
240 } else {
241 ixheaacd_write32_bits_lh(
242 fp, 2 + 2 + 4 + 4 + 2 + 2); /* length of PCM format decl area */
243 ixheaacd_write16_bits_lh(fp, 1); /* is pcm? */
244 }
245
246 ixheaacd_write16_bits_lh(fp, channels);
247 ixheaacd_write32_bits_lh(fp, freq);
248 ixheaacd_write32_bits_lh(fp, freq * channels * bytes); /* bps */
249 ixheaacd_write16_bits_lh(fp, channels * bytes);
250 ixheaacd_write16_bits_lh(fp, bits);
251
252 /* tag for WAVE_FORMAT_EXTENSIBLE */
253 if (channels > 2) {
254 ixheaacd_write16_bits_lh(fp, 0x16);
255 ixheaacd_write16_bits_lh(fp, 0x10); /*Samples.wReserved*/
256 ixheaacd_write32_bits_lh(fp, i_channel_mask); /* dwChannelMask */
257
258 ixheaacd_write32_bits_lh(fp, 0x0001); /* SubFormat.Data1 */
259 ixheaacd_write32_bits_lh(
260 fp, 0x00100000); /* SubFormat.Data2 and SubFormat.Data3 */
261
262 ixheaacd_write16_bits_lh(fp, 0x0080);
263 ixheaacd_write16_bits_lh(fp, 0xAA00);
264
265 ixheaacd_write16_bits_lh(fp, 0x3800);
266 ixheaacd_write16_bits_lh(fp, 0x719b);
267 }
268
269 fwrite("data", 1, 4, fp);
270 ixheaacd_write32_bits_lh(fp, pcmbytes);
271
272 return (ferror(fp) ? -1 : 0);
273
274 } else {
275 WORD32 bytes = (bits + 7) / 8;
276 fwrite("RIFF", 1, 4, fp); /* label */
277 ixheaacd_write32_bits_lh(
278 fp, pcmbytes + 44 - 8); /* length in bytes without header */
279 fwrite("WAVEfmt ", 2, 4, fp); /* 2 labels */
280 ixheaacd_write32_bits_lh(
281 fp, 2 + 2 + 4 + 4 + 2 + 2); /* length of PCM format decl area */
282 ixheaacd_write16_bits_lh(fp, 1); /* is pcm? */
283 ixheaacd_write16_bits_lh(fp, channels);
284 ixheaacd_write32_bits_lh(fp, freq);
285 ixheaacd_write32_bits_lh(fp, freq * channels * bytes); /* bps */
286 ixheaacd_write16_bits_lh(fp, channels * bytes);
287 ixheaacd_write16_bits_lh(fp, bits);
288 fwrite("data", 1, 4, fp);
289 ixheaacd_write32_bits_lh(fp, pcmbytes);
290
291 return (ferror(fp) ? -1 : 0);
292 }
293 }
294 #endif /* WAV_HEADER */
295 #endif /*ARM_PROFILE_BOARD*/
296
297 #ifdef DISPLAY_MESSAGE
298
299 /*****************************************************************************/
300 /* */
301 /* Function name : ia_display_id_message */
302 /* */
303 /* Description : Display the ID message of the process */
304 /* */
305 /* Inputs : WORD8 lib_name[] (library name) */
306 /* WORD8 lib_version[] (library version) */
307 /* WORD8 api_version[] (API version) */
308 /* */
309 /* Globals : none */
310 /* */
311 /* Processing : Display all the information about the process */
312 /* */
313 /* Outputs : none */
314 /* */
315 /* Returns : none */
316 /* */
317 /* Issues : none */
318 /* */
319 /* Revision history : */
320 /* */
321 /* DD MM YYYY Author Changes */
322 /* 29 07 2005 Tejaswi/Vishal Created */
323 /* */
324 /*****************************************************************************/
325
ia_display_id_message(WORD8 lib_name[],WORD8 lib_version[])326 VOID ia_display_id_message(WORD8 lib_name[], WORD8 lib_version[]) {
327 WORD8 str[4][IA_SCREEN_WIDTH] = {"ITTIAM SYSTEMS PVT LTD, BANGALORE\n",
328 "http:\\\\www.ittiam.com\n", "", ""};
329 WORD8 spaces[IA_SCREEN_WIDTH / 2 + 1];
330 WORD32 i, spclen;
331
332 strcpy((pCHAR8)str[2], (pCHAR8)lib_name);
333 strcat((pCHAR8)str[2], (pCHAR8)lib_version);
334 strcat((pCHAR8)str[2], "\n");
335 strcat((pCHAR8)str[4 - 1], "\n");
336
337 for (i = 0; i < IA_SCREEN_WIDTH / 2 + 1; i++) {
338 spaces[i] = ' ';
339 }
340
341 for (i = 0; i < 4; i++) {
342 spclen = IA_SCREEN_WIDTH / 2 - strlen((pCHAR8)str[i]) / 2;
343 spaces[spclen] = '\0';
344 printf("%s", (pCHAR8)spaces);
345 spaces[spclen] = ' ';
346 printf("%s", (pCHAR8)str[i]);
347 }
348 }
349 #endif /* DISPLAY_MESSAGE */
350
351 /*****************************************************************************/
352 /* */
353 /* Function name : ixheaacd_set_config_param */
354 /* */
355 /* Description : Set config parameters */
356 /* */
357 /* Inputs : pVOID p_ia_process_api_obj (process API obj) */
358 /* WORD32 argc (Arguments count) */
359 /* pWORD8 argv[] (Argument strings) */
360 /* */
361 /* Globals : none */
362 /* */
363 /* Processing : Set config params inside API */
364 /* */
365 /* Outputs : none */
366 /* */
367 /* Returns : IA_ERRORCODE error_value (Error value) */
368 /* */
369 /* Issues : none */
370 /* */
371 /* Revision history : */
372 /* */
373 /* DD MM YYYY Author Changes */
374 /* 29 07 2005 Ittiam Created */
375 /* */
376 /*****************************************************************************/
377
ixheaacd_set_config_param(WORD32 argc,pWORD8 argv[],pVOID p_ia_process_api_obj)378 IA_ERRORCODE ixheaacd_set_config_param(WORD32 argc, pWORD8 argv[],
379 pVOID p_ia_process_api_obj) {
380 LOOPIDX i;
381 IA_ERRORCODE err_code = IA_NO_ERROR;
382 /* the process API function */
383 IA_ERRORCODE(*p_ia_process_api)
384 (pVOID p_ia_process_api_obj, WORD32 i_cmd, WORD32 i_idx, pVOID pv_value) =
385 ixheaacd_dec_api;
386 ia_error_info_struct *p_proc_err_info = &ixheaacd_error_info;
387
388 for (i = 0; i < argc; i++) {
389 /* To indicate if its a MP4 file or not. */
390 if (!strncmp((pCHAR8)argv[i], "-mp4:", 5)) {
391 pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 5);
392 UWORD32 ui_mp4_flag = atoi(pb_arg_val);
393 err_code = (*p_ia_process_api)(
394 p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
395 IA_XHEAAC_DEC_CONFIG_PARAM_MP4FLAG, &ui_mp4_flag);
396 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
397 }
398 /* PCM WORD Size (For single input file) */
399 if (!strncmp((pCHAR8)argv[i], "-pcmsz:", 7)) {
400 pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 7);
401 UWORD32 ui_pcm_wd_sz = atoi(pb_arg_val);
402 err_code = (*p_ia_process_api)(
403 p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
404 IA_XHEAAC_DEC_CONFIG_PARAM_PCM_WDSZ, &ui_pcm_wd_sz);
405 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
406 }
407 /* Down-mix stereo to mono. */
408 if (!strncmp((pCHAR8)argv[i], "-dmix:", 6)) {
409 pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 6);
410 UWORD32 ui_down_mix = atoi(pb_arg_val);
411 err_code = (*p_ia_process_api)(
412 p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
413 IA_XHEAAC_DEC_CONFIG_PARAM_DOWNMIX, &ui_down_mix);
414 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
415 }
416 if (!strncmp((pCHAR8)argv[i], "-esbr_hq:", 9)) {
417 pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 9);
418 UWORD32 ui_esbr_hq = atoi(pb_arg_val);
419 err_code = (*p_ia_process_api)(
420 p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
421 IA_XHEAAC_DEC_CONFIG_PARAM_HQ_ESBR, &ui_esbr_hq);
422 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
423 }
424 if (!strncmp((pCHAR8)argv[i], "-esbr_ps:", 9)) {
425 pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 9);
426 UWORD32 ui_esbr_ps = atoi(pb_arg_val);
427 err_code = (*p_ia_process_api)(
428 p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
429 IA_XHEAAC_DEC_CONFIG_PARAM_PS_ENABLE, &ui_esbr_ps);
430 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
431 }
432 #ifdef RESAMPLE_SUPPORT
433 /* Resample the output to 8 kHz. */
434 if (!strncmp((pCHAR8)argv[i], "-f08:", 5)) {
435 pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 5);
436 UWORD32 ui_08khz_out = atoi(pb_arg_val);
437 err_code = (*p_ia_process_api)(
438 p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
439 IA_ENHAACPLUS_DEC_CONFIG_PARAM_OUT08KHZ, &ui_08khz_out);
440 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
441 }
442 /* Resample the output to 16 kHz. */
443 if (!strncmp((pCHAR8)argv[i], "-f16:", 5)) {
444 pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 5);
445 UWORD32 ui_16khz_out = atoi(pb_arg_val);
446 err_code = (*p_ia_process_api)(
447 p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
448 IA_ENHAACPLUS_DEC_CONFIG_PARAM_OUT16KHZ, &ui_16khz_out);
449 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
450 }
451 #endif
452 /* Interleave mono output to stereo */
453 if (!strncmp((pCHAR8)argv[i], "-tostereo:", 10)) {
454 pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 10);
455 UWORD32 ui_to_stereo = atoi(pb_arg_val);
456 err_code = (*p_ia_process_api)(
457 p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
458 IA_XHEAAC_DEC_CONFIG_PARAM_TOSTEREO, &ui_to_stereo);
459 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
460 }
461 /* Downsampled synthesis to be used */
462 if (!strncmp((pCHAR8)argv[i], "-dsample:", 9)) {
463 pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 9);
464 UWORD32 ui_dsample = atoi(pb_arg_val);
465 err_code = (*p_ia_process_api)(
466 p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
467 IA_XHEAAC_DEC_CONFIG_PARAM_DSAMPLE, &ui_dsample);
468 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
469 }
470
471 #ifdef HEAACV2_AS_AACLC
472 /* To indicate if its a MP4 file or not. */
473 if (!strncmp((pCHAR8)argv[i], "-aac_lc_only:", 13)) {
474 pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 13);
475 UWORD32 ui_aac_lc_only = atoi(pb_arg_val);
476 err_code = (*p_ia_process_api)(
477 p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
478 IA_ENHAACPLUS_DEC_CONFIG_PARAM_AAC_ONLY, &ui_aac_lc_only);
479 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
480 }
481 #endif
482
483 #ifdef LATM_LOAS
484 /* To indicate if its a LOAS file or not. */
485 if (!strncmp((pCHAR8)argv[i], "-isLOAS:", 8)) {
486 pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 8);
487 UWORD32 ui_loas_flag = atoi(pb_arg_val);
488 err_code = (*p_ia_process_api)(
489 p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
490 IA_ENHAACPLUS_DEC_CONFIG_PARAM_ISLOAS, &ui_loas_flag);
491 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
492 }
493
494 #endif
495
496 #ifdef DRC_ENABLE
497 if (!strncmp((pCHAR8)argv[i], "-drc_cut_fac:", 13)) {
498 pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 13);
499 UWORD32 ui_drc_cut = atoi(pb_arg_val);
500 err_code = (*p_ia_process_api)(
501 p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
502 IA_XHEAAC_DEC_CONFIG_PARAM_DRC_CUT, &ui_drc_cut);
503 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
504 }
505 if (!strncmp((pCHAR8)argv[i], "-drc_boost_fac:", 15)) {
506 pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 15);
507 UWORD32 ui_drc_boost = atoi(pb_arg_val);
508 err_code = (*p_ia_process_api)(
509 p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
510 IA_XHEAAC_DEC_CONFIG_PARAM_DRC_BOOST, &ui_drc_boost);
511 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
512 }
513 if (!strncmp((pCHAR8)argv[i], "-drc_target_level:", 18)) {
514 pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 18);
515 UWORD32 ui_drc_target = atoi(pb_arg_val);
516 err_code = (*p_ia_process_api)(
517 p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
518 IA_XHEAAC_DEC_CONFIG_PARAM_DRC_TARGET_LEVEL, &ui_drc_target);
519 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
520 }
521 if (!strncmp((pCHAR8)argv[i], "-drc_heavy_comp:", 16)) {
522 pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 16);
523 UWORD32 ui_drc_heavy_comp = atoi(pb_arg_val);
524 err_code = (*p_ia_process_api)(
525 p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
526 IA_XHEAAC_DEC_CONFIG_PARAM_DRC_HEAVY_COMP, &ui_drc_heavy_comp);
527 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
528 }
529
530 #endif
531 /* For MPEG-D DRC effect type */
532 if (!strncmp((pCHAR8)argv[i], "-effect:", 8)) {
533 pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 8);
534 WORD32 ui_effect = atoi(pb_arg_val);
535 err_code =
536 (*p_ia_process_api)(p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
537 IA_XHEAAC_DEC_CONFIG_PARAM_DRC_EFFECT_TYPE, &ui_effect);
538 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
539 mpeg_d_drc_on = 1;
540 }
541 /* For MPEG-D DRC target loudness */
542 if (!strncmp((pCHAR8)argv[i], "-target_loudness:", 17)) {
543 pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 17);
544 WORD32 ui_target_loudness = atoi(pb_arg_val);
545 if ((ui_target_loudness > 0) || (ui_target_loudness < -63)) {
546 ui_target_loudness = 0;
547 }
548 ui_target_loudness = -(ui_target_loudness << 2);
549 err_code = (*p_ia_process_api)(
550 p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
551 IA_XHEAAC_DEC_CONFIG_PARAM_DRC_TARGET_LOUDNESS, &ui_target_loudness);
552 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
553 mpeg_d_drc_on = 1;
554 }
555 /* To indicate if its a MP4 file or not. */
556 if (!strncmp((pCHAR8)argv[i], "-nosync:", 8)) {
557 pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 8);
558 UWORD32 ui_disable_sync = atoi(pb_arg_val);
559 err_code = (*p_ia_process_api)(
560 p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
561 IA_XHEAAC_DEC_CONFIG_DISABLE_SYNC, &ui_disable_sync);
562 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
563 }
564 /* To indicate SBR upsampling. */
565 if (!strncmp((pCHAR8)argv[i], "-sbrup:", 7)) {
566 pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 7);
567 UWORD32 ui_auto_sbr_upsample = atoi(pb_arg_val);
568 err_code =
569 (*p_ia_process_api)(p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
570 IA_XHEAAC_DEC_CONFIG_PARAM_AUTO_SBR_UPSAMPLE,
571 &ui_auto_sbr_upsample);
572 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
573 }
574 /* To indicate frame length for a RAW bit-stream. */
575 if (!strncmp((pCHAR8)argv[i], "-flflag:", 8)) {
576 pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 8);
577 UWORD32 ui_fl_flag = atoi(pb_arg_val);
578 err_code =
579 (*p_ia_process_api)(p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
580 IA_XHEAAC_DEC_CONFIG_PARAM_FRAMELENGTH_FLAG,
581 &ui_fl_flag);
582 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
583 }
584
585 /* To indicate sample rate for a RAW bit-stream. */
586 if (!strncmp((pCHAR8)argv[i], "-fs:", 4)) {
587 pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 4);
588 UWORD32 ui_samp_freq = atoi(pb_arg_val);
589 err_code = (*p_ia_process_api)(
590 p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
591 IA_XHEAAC_DEC_CONFIG_PARAM_SAMP_FREQ, &ui_samp_freq);
592 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
593 }
594 /* To indicate the number of maximum channels */
595 if (!strncmp((pCHAR8)argv[i], "-maxchannel:", 12)) {
596 pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 12);
597 UWORD32 ui_max_channel = atoi(pb_arg_val);
598 err_code = (*p_ia_process_api)(
599 p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
600 IA_XHEAAC_DEC_CONFIG_PARAM_MAX_CHANNEL, &ui_max_channel);
601 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
602 }
603
604 /* To indicate the number of coupling channels to be used for coupling */
605 if (!strncmp((pCHAR8)argv[i], "-coupchannel:", 13)) {
606 pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 13);
607 UWORD32 ui_coupling_channel = atoi(pb_arg_val);
608 err_code = (*p_ia_process_api)(
609 p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
610 IA_XHEAAC_DEC_CONFIG_PARAM_COUP_CHANNEL, &ui_coupling_channel);
611 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
612 }
613
614 /* Down-mix N.1 to stereo */
615 if (!strncmp((pCHAR8)argv[i], "-downmix:", 9)) {
616 pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 9);
617 UWORD32 ui_downmix = atoi(pb_arg_val);
618 err_code = (*p_ia_process_api)(
619 p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
620 IA_XHEAAC_DEC_CONFIG_PARAM_DOWNMIX_STEREO, &ui_downmix);
621 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
622 }
623
624 /* For LD files, to indicate */
625 if (!strncmp((pCHAR8)argv[i], "-fs480:", 7)) {
626 pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 7);
627 UWORD32 ui_fs480 = atoi(pb_arg_val);
628 err_code = (*p_ia_process_api)(
629 p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
630 IA_XHEAAC_DEC_CONFIG_PARAM_FRAMESIZE, &ui_fs480);
631 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
632 }
633
634 if (!strncmp((pCHAR8)argv[i], "-ld_testing:", 12)) {
635 pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 12);
636 UWORD32 ld_testing = atoi(pb_arg_val);
637 err_code = (*p_ia_process_api)(
638 p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
639 IA_XHEAAC_DEC_CONFIG_PARAM_LD_TESTING, &ld_testing);
640 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
641 }
642 if (!strncmp((pCHAR8)argv[i], "-peak_limiter_off:", 18))
643 {
644 pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 18);
645 UWORD32 peak_limiter_flag = atoi(pb_arg_val);
646 err_code = (*p_ia_process_api)(p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
647 IA_XHEAAC_DEC_CONFIG_PARAM_PEAK_LIMITER, &peak_limiter_flag);
648 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
649 }
650 /* For Error concealment */
651 if (!strncmp((pCHAR8)argv[i], "-err_conceal:", 13))
652 {
653 pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 13);
654 UWORD32 ui_err_conceal = atoi(pb_arg_val);
655 err_code = (*p_ia_process_api)(p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
656 IA_XHEAAC_DEC_CONFIG_ERROR_CONCEALMENT, &ui_err_conceal);
657 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
658 ec_enable = ui_err_conceal;
659 }
660 }
661
662 return IA_NO_ERROR;
663 }
664
665 /*****************************************************************************/
666 /* */
667 /* Function name : ixheaacd_get_config_param */
668 /* */
669 /* Description : Get config parameters */
670 /* */
671 /* Inputs : pVOID p_ia_process_api_obj (process API obj) */
672 /* pWORD32 pi_samp_freq (Ptr for samp freq param) */
673 /* pWORD32 pi_num_chan (Ptr for num chan param) */
674 /* pWORD32 pi_pcm_wd_sz (Ptr for PCM WORD size param) */
675 /* */
676 /* Globals : none */
677 /* */
678 /* Processing : Get config params from API */
679 /* */
680 /* Outputs : none */
681 /* */
682 /* Returns : IA_ERRORCODE error_value (Error value) */
683 /* */
684 /* Issues : none */
685 /* */
686 /* Revision history : */
687 /* */
688 /* DD MM YYYY Author Changes */
689 /* 29 07 2005 Ittiam Created */
690 /* */
691 /*****************************************************************************/
692
ixheaacd_get_config_param(pVOID p_ia_process_api_obj,pWORD32 pi_samp_freq,pWORD32 pi_num_chan,pWORD32 pi_pcm_wd_sz,pWORD32 pi_channel_mask,pWORD32 pi_sbr_mode,pWORD32 pi_aot)693 IA_ERRORCODE ixheaacd_get_config_param(pVOID p_ia_process_api_obj,
694 pWORD32 pi_samp_freq,
695 pWORD32 pi_num_chan,
696 pWORD32 pi_pcm_wd_sz,
697 pWORD32 pi_channel_mask,
698 pWORD32 pi_sbr_mode,
699 pWORD32 pi_aot) {
700 IA_ERRORCODE err_code = IA_NO_ERROR;
701 /* the process API function */
702 IA_ERRORCODE(*p_ia_process_api)
703 (pVOID p_ia_process_api_obj, WORD32 i_cmd, WORD32 i_idx, pVOID pv_value) =
704 ixheaacd_dec_api;
705 ia_error_info_struct *p_proc_err_info = &ixheaacd_error_info;
706
707 /* Sampling frequency */
708 {
709 err_code = (*p_ia_process_api)(
710 p_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM,
711 IA_XHEAAC_DEC_CONFIG_PARAM_SAMP_FREQ, pi_samp_freq);
712 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
713 }
714 /* Total Number of Channels */
715 {
716 err_code = (*p_ia_process_api)(
717 p_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM,
718 IA_XHEAAC_DEC_CONFIG_PARAM_NUM_CHANNELS, pi_num_chan);
719 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
720 }
721 /* PCM word size */
722 {
723 err_code = (*p_ia_process_api)(
724 p_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM,
725 IA_XHEAAC_DEC_CONFIG_PARAM_PCM_WDSZ, pi_pcm_wd_sz);
726 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
727 }
728 /* channel mask to tell the arrangement of channels in bit stream */
729 {
730 err_code = (*p_ia_process_api)(
731 p_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM,
732 IA_XHEAAC_DEC_CONFIG_PARAM_CHANNEL_MASK, pi_channel_mask);
733 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
734 }
735
736 /* Channel mode to tell MONO/STEREO/DUAL-MONO/NONE_OF_THESE */
737 {
738 UWORD32 ui_channel_mode;
739 err_code = (*p_ia_process_api)(
740 p_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM,
741 IA_XHEAAC_DEC_CONFIG_PARAM_CHANNEL_MODE, &ui_channel_mode);
742 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
743 if (ui_channel_mode == 0)
744 printf("Channel Mode: MONO_OR_PS\n");
745 else if (ui_channel_mode == 1)
746 printf("Channel Mode: STEREO\n");
747 else if (ui_channel_mode == 2)
748 printf("Channel Mode: DUAL-MONO\n");
749 else
750 printf("Channel Mode: NONE_OF_THESE or MULTICHANNEL\n");
751 }
752
753 /* Channel mode to tell SBR PRESENT/NOT_PRESENT */
754 {
755 UWORD32 ui_sbr_mode;
756 err_code = (*p_ia_process_api)(
757 p_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM,
758 IA_XHEAAC_DEC_CONFIG_PARAM_SBR_MODE, &ui_sbr_mode);
759 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
760 if (ui_sbr_mode == 0)
761 printf("SBR Mode: NOT_PRESENT\n");
762 else if (ui_sbr_mode == 1)
763 printf("SBR Mode: UPSAMPLING FACTOR 2 or 8/3\n");
764 else if (ui_sbr_mode == 2)
765 printf("SBR Mode: ILLEGAL\n");
766 else if (ui_sbr_mode == 3)
767 printf("ESBR Mode: UPSAMPLING FACTOR 4\n");
768 else
769 printf("ui_sbr_mode not vaild\n");
770 *pi_sbr_mode = ui_sbr_mode;
771 }
772 {
773 UWORD32 ui_aot;
774 err_code = (*p_ia_process_api)(
775 p_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM,
776 IA_XHEAAC_DEC_CONFIG_PARAM_AOT, &ui_aot);
777 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
778 *pi_aot = ui_aot;
779 }
780 return IA_NO_ERROR;
781 }
782
783 int counter_bl;
784 /*****************************************************************************/
785 /* */
786 /* Function name : ixheaacd_main_process */
787 /* */
788 /* Description : Stacked processing with function pointer selection */
789 /* */
790 /* Inputs : WORD32 argc (Arguments count) */
791 /* pWORD8 argv[] (Argument strings) */
792 /* */
793 /* Globals : pVOID g_pv_arr_alloc_memory[MAX_MEM_ALLOCS]; */
794 /* WORD g_w_malloc_count; */
795 /* FILE *g_pf_inp, *g_pf_out; */
796 /* */
797 /* Processing : Stacked processing of multiple components */
798 /* Loop1: Set params + Mem alloc */
799 /* Loop2: Set params + Init process + Get params */
800 /* Loop3: Execute */
801 /* */
802 /* Outputs : None */
803 /* */
804 /* Returns : IA_ERRORCODE error_value (Error value) */
805 /* */
806 /* Issues : none */
807 /* */
808 /* Revision history : */
809 /* */
810 /* DD MM YYYY Author Changes */
811 /* 29 07 2005 Tejaswi/Vishal Created */
812 /* */
813 /*****************************************************************************/
814
ixheaacd_main_process(WORD32 argc,pWORD8 argv[])815 int ixheaacd_main_process(WORD32 argc, pWORD8 argv[]) {
816 LOOPIDX i;
817 WORD frame_counter = 0;
818 #ifdef DISPLAY_MESSAGE
819 /* Library Info and Identification strings */
820 WORD8 pb_process_name[IA_SCREEN_WIDTH] = "";
821 WORD8 pb_lib_version[IA_SCREEN_WIDTH] = "";
822 #endif
823
824 /* Error code */
825 IA_ERRORCODE err_code = IA_NO_ERROR;
826 IA_ERRORCODE err_code_reinit = IA_NO_ERROR;
827
828 /* API obj */
829 pVOID pv_ia_process_api_obj;
830
831 pVOID pv_ia_drc_process_api_obj;
832 UWORD32 pui_api_size;
833
834 /* First part */
835 /* Error Handler Init */
836 /* Get Library Name, Library Version and API Version */
837 /* Initialize API structure + Default config set */
838 /* Set config params from user */
839 /* Initialize memory tables */
840 /* Get memory information and allocate memory */
841
842 UWORD8 drc_ip_buf[4096 * 4 * 8];
843 UWORD8 drc_op_buf[4096 * 4 * 8];
844
845 /* Memory variables */
846 UWORD32 n_mems, ui_rem;
847 UWORD32 ui_proc_mem_tabs_size;
848 /* API size */
849 UWORD32 pui_ap_isize;
850 /* Process initing done query variable */
851 UWORD32 ui_init_done, ui_exec_done;
852 pWORD8 pb_inp_buf = 0, pb_out_buf = 0;
853
854 /* Number of Prerolls variable */
855 WORD32 num_preroll = 0;
856
857 // pWORD16 litt2big;
858
859 UWORD32 ui_inp_size = 0;
860 WORD32 i_bytes_consumed, i_bytes_read;
861 WORD32 i_buff_size;
862 WORD32 prev_sampling_rate = 0;
863 WORD32 skip_samples = 0;
864 WORD32 total_samples = 0;
865 WORD32 write_flag = 1;
866 WORD32 bytes_to_write = 0;
867 WORD32 ixheaacd_drc_offset = 0;
868 WORD32 current_samples = 0;
869 WORD32 samples_written = 0;
870 WORD32 init_iteration = 1;
871
872 WORD32 fatal_error_chk;
873
874 #ifdef ARM_PROFILE_HW
875 int frame_count_b = 0;
876 long long cycles_b = 0;
877 long long start1_b, stop1_b;
878 double Curr_b, Ave_b = 0, Sum_b = 0;
879 double Peak_b = 0;
880 WORD32 Peak_frame_b = 0;
881 #endif
882 WORD32 i_out_bytes, i_total_bytes = 0;
883 WORD32 i_samp_freq, i_num_chan, i_pcm_wd_sz, i_channel_mask;
884
885 WORD32 i_sbr_mode;
886 WORD32 i_effect_type = 0;
887 WORD32 i_target_loudness = 0;
888 WORD32 i_loud_norm = 0;
889 WORD32 drc_flag = 0;
890 WORD32 mpegd_drc_present = 0;
891 WORD32 uo_num_chan;
892
893 /* The process API function */
894 IA_ERRORCODE(*p_ia_process_api)
895 (pVOID p_ia_process_api_obj, WORD32 i_cmd, WORD32 i_idx, pVOID pv_value);
896
897 /* The set config from argc argv */
898 IA_ERRORCODE(*p_set_config_param)
899 (WORD32 argc, pWORD8 argv[], pVOID p_ia_process_api_obj);
900
901 /* The get config from API */
902 IA_ERRORCODE(*p_get_config_param)
903 (pVOID p_ia_process_api_obj, pWORD32 pi_samp_freq, pWORD32 pi_num_chan,
904 pWORD32 pi_pcm_wd_sz, pWORD32 pi_channel_mask, pWORD32 pi_sbr_mode, pWORD32 pi_aot);
905 WORD32 ui_aot = 0;
906
907 /* The error init function */
908 VOID (*p_error_init)();
909
910 /* The process error info structure */
911 ia_error_info_struct *p_proc_err_info;
912
913 /* Process struct initing */
914 p_ia_process_api = ixheaacd_dec_api;
915 p_set_config_param = ixheaacd_set_config_param;
916 p_get_config_param = ixheaacd_get_config_param;
917 p_error_init = ixheaacd_error_handler_init;
918 p_proc_err_info = &ixheaacd_error_info;
919 /* Process struct initing end */
920
921 /* ******************************************************************/
922 /* Initialize the error handler */
923 /* ******************************************************************/
924 (*p_error_init)();
925
926 /* ******************************************************************/
927 /* Get the library name, library version and API version */
928 /* ******************************************************************/
929
930 #ifdef DISPLAY_MESSAGE
931 /* Get the library name string */
932 err_code = (*p_ia_process_api)(NULL, IA_API_CMD_GET_LIB_ID_STRINGS,
933 IA_CMD_TYPE_LIB_NAME, pb_process_name);
934
935 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
936
937 /* Get the library version string */
938 err_code = (*p_ia_process_api)(NULL, IA_API_CMD_GET_LIB_ID_STRINGS,
939 IA_CMD_TYPE_LIB_VERSION, pb_lib_version);
940
941 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
942
943 /* Display the ittiam identification message */
944 ia_display_id_message(pb_process_name, pb_lib_version);
945 #endif
946
947 /* ******************************************************************/
948 /* Initialize API structure and set config params to default */
949 /* ******************************************************************/
950
951 /* Get the API size */
952 err_code =
953 (*p_ia_process_api)(NULL, IA_API_CMD_GET_API_SIZE, 0, &pui_ap_isize);
954 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
955
956 /* Allocate memory for API */
957 g_pv_arr_alloc_memory[g_w_malloc_count] = malloc(pui_ap_isize + 4);
958
959 if (g_pv_arr_alloc_memory[g_w_malloc_count] == NULL) {
960 err_code = IA_TESTBENCH_MFMAN_FATAL_MEM_ALLOC_FAILED;
961 _IA_HANDLE_ERROR(&ixheaacd_ia_testbench_error_info,
962 (pWORD8) "API struct alloc", err_code);
963 }
964
965 /* API object requires 4 bytes (WORD32) alignment */
966 ui_rem = ((SIZE_T)g_pv_arr_alloc_memory[g_w_malloc_count] & 3);
967 /* Set API object with the memory allocated */
968 pv_ia_process_api_obj =
969 (pVOID)((WORD8 *)g_pv_arr_alloc_memory[g_w_malloc_count] + 4 - ui_rem);
970
971 g_w_malloc_count++;
972
973 /* Set the config params to default values */
974 err_code = (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_INIT,
975 IA_CMD_TYPE_INIT_API_PRE_CONFIG_PARAMS, NULL);
976
977 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
978
979 /*ITTIAM: Get API size for DRC*/
980
981 /* Get the API size */
982 err_code = ia_drc_dec_api(NULL, IA_API_CMD_GET_API_SIZE, 0, &pui_api_size);
983
984 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
985
986 /* Allocate memory for API */
987 g_pv_arr_alloc_memory[g_w_malloc_count] = malloc(pui_api_size + 4);
988 if (g_pv_arr_alloc_memory[g_w_malloc_count] == NULL) {
989 _IA_HANDLE_ERROR(&ixheaacd_ia_testbench_error_info,
990 (pWORD8) "API struct alloc", err_code);
991 }
992
993 /* API object requires 4 bytes (WORD32) alignment */
994 ui_rem = ((SIZE_T)g_pv_arr_alloc_memory[g_w_malloc_count] & 3);
995 /* Set API object with the memory allocated */
996 pv_ia_drc_process_api_obj =
997 (pVOID)((WORD8 *)g_pv_arr_alloc_memory[g_w_malloc_count] + 4 - ui_rem);
998
999 g_w_malloc_count++;
1000
1001 err_code = ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_INIT,
1002 IA_CMD_TYPE_INIT_API_PRE_CONFIG_PARAMS, NULL);
1003
1004 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1005
1006 /* ******************************************************************/
1007 /* Set config parameters got from the user present in argc argv */
1008 /* ******************************************************************/
1009
1010 err_code = (*p_set_config_param)(argc, argv, pv_ia_process_api_obj);
1011 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1012
1013 /* ******************************************************************/
1014 /* Table Relocatibility */
1015 /* ******************************************************************/
1016 #if IA_HE_AAC_DEC_TABLE_RELOCATABLE_ENABLE
1017
1018 /* Get number of tables required */
1019 err_code = (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_GET_N_TABLES,
1020 0, &n_mems);
1021 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1022
1023 for (i = 0; i < (WORD32)n_mems; i++) {
1024 int ui_size, ui_alignment;
1025 pVOID pv_alloc_ptr = NULL, pv_curr_ptr = NULL;
1026 LOOPIDX k;
1027
1028 /* Get table size */
1029 err_code = (*p_ia_process_api)(pv_ia_process_api_obj,
1030 IA_API_CMD_GET_TABLE_INFO_SIZE, i, &ui_size);
1031 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1032
1033 /* Get table alignment */
1034 err_code = (*p_ia_process_api)(pv_ia_process_api_obj,
1035 IA_API_CMD_GET_TABLE_INFO_ALIGNMENT, i,
1036 &ui_alignment);
1037
1038 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1039
1040 g_pv_arr_alloc_memory[g_w_malloc_count] = malloc(ui_size + ui_alignment);
1041
1042 if (g_pv_arr_alloc_memory[g_w_malloc_count] == NULL) {
1043 _IA_HANDLE_ERROR(&ixheaacd_ia_testbench_error_info,
1044 (pWORD8) "Mem for table relocation alloc",
1045 IA_TESTBENCH_MFMAN_FATAL_MEM_ALLOC_FAILED);
1046 }
1047
1048 ui_rem = ((SIZE_T)g_pv_arr_alloc_memory[g_w_malloc_count] % ui_alignment);
1049 pv_alloc_ptr = (pVOID)((WORD8 *)g_pv_arr_alloc_memory[g_w_malloc_count] +
1050 ui_alignment - ui_rem);
1051
1052 g_w_malloc_count++;
1053
1054 /* Get the current table pointer */
1055 err_code = (*p_ia_process_api)(pv_ia_process_api_obj,
1056 IA_API_CMD_GET_TABLE_PTR, i, &pv_curr_ptr);
1057
1058 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1059
1060 for (k = 0; k < ui_size; k++) {
1061 ((pWORD8)pv_alloc_ptr)[k] = ((pWORD8)pv_curr_ptr)[k];
1062 /* Disabled for multiple files running
1063 ((pWORD8)pv_curr_ptr)[k] = (WORD8)0xab; */
1064 }
1065
1066 /* Set the relocated table pointer */
1067 err_code = (*p_ia_process_api)(pv_ia_process_api_obj,
1068 IA_API_CMD_SET_TABLE_PTR, i, pv_alloc_ptr);
1069
1070 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1071 }
1072 #endif
1073 /* ******************************************************************/
1074 /* Initialize Memory info tables */
1075 /* ******************************************************************/
1076
1077 /* Get memory info tables size */
1078 err_code =
1079 (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_GET_MEMTABS_SIZE, 0,
1080 &ui_proc_mem_tabs_size);
1081 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1082
1083 g_pv_arr_alloc_memory[g_w_malloc_count] = malloc(ui_proc_mem_tabs_size + 4);
1084
1085 if (g_pv_arr_alloc_memory[g_w_malloc_count] == NULL) {
1086 err_code = IA_TESTBENCH_MFMAN_FATAL_MEM_ALLOC_FAILED;
1087 _IA_HANDLE_ERROR(&ixheaacd_ia_testbench_error_info,
1088 (pWORD8) "Mem tables alloc", err_code);
1089 }
1090
1091 /* API object requires 4 bytes (WORD32) alignment */
1092 ui_rem = ((SIZE_T)g_pv_arr_alloc_memory[g_w_malloc_count] & 3);
1093
1094 /* Set pointer for process memory tables */
1095 err_code = (*p_ia_process_api)(
1096 pv_ia_process_api_obj, IA_API_CMD_SET_MEMTABS_PTR, 0,
1097 (pVOID)((WORD8 *)g_pv_arr_alloc_memory[g_w_malloc_count] + 4 - ui_rem));
1098
1099 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1100
1101 g_w_malloc_count++;
1102
1103 /* initialize the API, post config, fill memory tables */
1104 err_code = (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_INIT,
1105 IA_CMD_TYPE_INIT_API_POST_CONFIG_PARAMS, NULL);
1106
1107 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1108
1109 /* ******************************************************************/
1110 /* Allocate Memory with info from library */
1111 /* ******************************************************************/
1112
1113 /* Get number of memory tables required */
1114 err_code = (*p_ia_process_api)(pv_ia_process_api_obj,
1115 IA_API_CMD_GET_N_MEMTABS, 0, &n_mems);
1116
1117 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1118
1119 for (i = 0; i < (WORD32)n_mems; i++) {
1120 int ui_size, ui_alignment, ui_type;
1121 pVOID pv_alloc_ptr;
1122
1123 /* Get memory size */
1124 err_code = (*p_ia_process_api)(pv_ia_process_api_obj,
1125 IA_API_CMD_GET_MEM_INFO_SIZE, i, &ui_size);
1126 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1127
1128 /* Get memory alignment */
1129 err_code = (*p_ia_process_api)(pv_ia_process_api_obj,
1130 IA_API_CMD_GET_MEM_INFO_ALIGNMENT, i,
1131 &ui_alignment);
1132
1133 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1134
1135 /* Get memory type */
1136 err_code = (*p_ia_process_api)(pv_ia_process_api_obj,
1137 IA_API_CMD_GET_MEM_INFO_TYPE, i, &ui_type);
1138
1139 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1140
1141 err_code =
1142 (*p_get_config_param)(pv_ia_process_api_obj, &i_samp_freq, &i_num_chan,
1143 &i_pcm_wd_sz, &i_channel_mask, &i_sbr_mode, &ui_aot);
1144 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1145
1146 g_pv_arr_alloc_memory[g_w_malloc_count] = malloc(ui_size + ui_alignment);
1147
1148 if (g_pv_arr_alloc_memory[g_w_malloc_count] == NULL) {
1149 err_code = IA_TESTBENCH_MFMAN_FATAL_MEM_ALLOC_FAILED;
1150 _IA_HANDLE_ERROR(&ixheaacd_ia_testbench_error_info,
1151 (pWORD8) "Mem tables alloc", err_code);
1152 }
1153
1154 ui_rem = ((SIZE_T)g_pv_arr_alloc_memory[g_w_malloc_count] % ui_alignment);
1155 pv_alloc_ptr = (pVOID)((WORD8 *)g_pv_arr_alloc_memory[g_w_malloc_count] +
1156 ui_alignment - ui_rem);
1157
1158 g_w_malloc_count++;
1159
1160 /* Set the buffer pointer */
1161 err_code = (*p_ia_process_api)(pv_ia_process_api_obj,
1162 IA_API_CMD_SET_MEM_PTR, i, pv_alloc_ptr);
1163
1164 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1165 if (ui_type == IA_MEMTYPE_INPUT) {
1166 pb_inp_buf = pv_alloc_ptr;
1167 ui_inp_size = ui_size;
1168 }
1169 if (ui_type == IA_MEMTYPE_OUTPUT) {
1170 pb_out_buf = pv_alloc_ptr;
1171 }
1172 }
1173
1174 /* End first part */
1175
1176 /* Second part */
1177 /* Initialize process */
1178 /* Get config params */
1179
1180 /* ******************************************************************/
1181 /* Initialize process in a loop (to handle junk data at beginning) */
1182 /* ******************************************************************/
1183
1184 i_bytes_consumed = ui_inp_size;
1185 i_buff_size = ui_inp_size;
1186
1187 do {
1188 i_bytes_read = 0;
1189
1190 if ((ui_inp_size - (i_buff_size - i_bytes_consumed)) > 0) {
1191 for (i = 0; i < (i_buff_size - i_bytes_consumed); i++) {
1192 pb_inp_buf[i] = pb_inp_buf[i + i_bytes_consumed];
1193 }
1194
1195 FileWrapper_Read(g_pf_inp, (unsigned char *)(pb_inp_buf + i_buff_size -
1196 i_bytes_consumed),
1197 (ui_inp_size - (i_buff_size - i_bytes_consumed)),
1198 (pUWORD32)&i_bytes_read);
1199
1200 i_buff_size = i_buff_size - (i_bytes_consumed - i_bytes_read);
1201
1202 /* Tell input is over, if algorithm returns with insufficient input and
1203 there is no
1204 more input left in the bitstream*/
1205 if ((i_buff_size <= 0) ||
1206 ((err_code_reinit == 0x00001804) && i_bytes_read == 0))
1207
1208 {
1209 i_buff_size = 0;
1210 /* Tell that the input is over in this buffer */
1211 err_code = (*p_ia_process_api)(pv_ia_process_api_obj,
1212 IA_API_CMD_INPUT_OVER, 0, NULL);
1213
1214 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1215 }
1216 }
1217
1218 if ((i_buff_size <= 0) ||
1219 ((err_code_reinit == 0x00001804) && i_bytes_read == 0)) {
1220 i_buff_size = 0;
1221 /* Tell that the input is over in this buffer */
1222 err_code = (*p_ia_process_api)(pv_ia_process_api_obj,
1223 IA_API_CMD_INPUT_OVER, 0, NULL);
1224
1225 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1226 #ifdef WAV_HEADER
1227 #ifndef ARM_PROFILE_BOARD
1228 /* ******************************************************************/
1229 /* Get config params from API */
1230 /* ******************************************************************/
1231
1232 err_code =
1233 (*p_get_config_param)(pv_ia_process_api_obj, &i_samp_freq,
1234 &i_num_chan, &i_pcm_wd_sz, &i_channel_mask,
1235 &i_sbr_mode, &ui_aot);
1236 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1237
1238 // This is done in those cases, where file decodes ends at init time
1239 // Since init is incomplete, sampling freq might be zero and will result
1240 // in
1241 // writing invalid wave header
1242
1243 if (i_samp_freq == 0) i_samp_freq = prev_sampling_rate;
1244
1245 if (!fseek(g_pf_out, 0, SEEK_SET))
1246 write_wav_header(g_pf_out, i_total_bytes, i_samp_freq, i_num_chan,
1247 i_pcm_wd_sz, i_channel_mask);
1248 #endif
1249 #endif
1250 return 1;
1251 }
1252
1253 if (init_iteration == 1) {
1254 if (raw_testing)
1255 ixheaacd_i_bytes_to_read = get_metadata_dec_info_init(meta_info);
1256 else
1257 ixheaacd_i_bytes_to_read = i_buff_size;
1258
1259 /* Set number of bytes to be processed */
1260 err_code =
1261 (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_SET_INPUT_BYTES,
1262 0, &ixheaacd_i_bytes_to_read);
1263 init_iteration++;
1264
1265 } else {
1266 if (raw_testing) {
1267 ixheaacd_i_bytes_to_read =
1268 get_metadata_dec_exec(meta_info, frame_counter);
1269
1270 if (ixheaacd_i_bytes_to_read > (WORD32)ui_inp_size)
1271 return IA_FATAL_ERROR;
1272
1273 if (ixheaacd_i_bytes_to_read <= 0) {
1274 err_code = (*p_ia_process_api)(pv_ia_process_api_obj,
1275 IA_API_CMD_INPUT_OVER, 0, NULL);
1276
1277 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1278
1279 return IA_NO_ERROR;
1280 }
1281
1282 /* Set number of bytes to be processed */
1283 err_code = (*p_ia_process_api)(pv_ia_process_api_obj,
1284 IA_API_CMD_SET_INPUT_BYTES, 0,
1285 &ixheaacd_i_bytes_to_read);
1286 init_iteration++;
1287 } else {
1288 /* Set number of bytes to be processed */
1289 err_code = (*p_ia_process_api)(
1290 pv_ia_process_api_obj, IA_API_CMD_SET_INPUT_BYTES, 0, &i_buff_size);
1291 }
1292 }
1293
1294 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1295
1296 /* Initialize the process */
1297 err_code = (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_INIT,
1298 IA_CMD_TYPE_INIT_PROCESS, NULL);
1299 err_code_reinit = err_code;
1300
1301 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1302
1303 /* Checking for end of initialization */
1304 err_code = (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_INIT,
1305 IA_CMD_TYPE_INIT_DONE_QUERY, &ui_init_done);
1306
1307 if (init_iteration > 2 && ui_init_done == 0) {
1308 frame_counter++;
1309 }
1310
1311 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1312
1313 /* How much buffer is used in input buffers */
1314 err_code = (*p_ia_process_api)(pv_ia_process_api_obj,
1315 IA_API_CMD_GET_CURIDX_INPUT_BUF, 0,
1316 &i_bytes_consumed);
1317
1318 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1319
1320 } while (!ui_init_done);
1321 if (ec_enable == 1) {
1322 mpeg_d_drc_on = 0;
1323 }
1324 if (mpeg_d_drc_on == 1) {
1325 err_code = (*p_ia_process_api)(
1326 pv_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM,
1327 IA_XHEAAC_DEC_CONFIG_PARAM_SBR_MODE, &i_sbr_mode);
1328 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1329
1330 if (i_sbr_mode != 0) {
1331 WORD32 frame_length;
1332 if (i_sbr_mode == 1) {
1333 frame_length = 2048;
1334 } else if (i_sbr_mode == 3) {
1335 frame_length = 4096;
1336 } else {
1337 frame_length = 1024;
1338 }
1339
1340 err_code =
1341 ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
1342 IA_DRC_DEC_CONFIG_PARAM_FRAME_SIZE, &frame_length);
1343 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1344 }
1345
1346 err_code =
1347 (*p_get_config_param)(pv_ia_process_api_obj, &i_samp_freq, &i_num_chan,
1348 &i_pcm_wd_sz, &i_channel_mask, &i_sbr_mode, &ui_aot);
1349 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1350
1351 /* Sampling Frequency */
1352 {
1353 err_code =
1354 ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
1355 IA_DRC_DEC_CONFIG_PARAM_SAMP_FREQ, &i_samp_freq);
1356 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1357 }
1358 /* Total Number of Channels */
1359 {
1360 err_code =
1361 ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
1362 IA_DRC_DEC_CONFIG_PARAM_NUM_CHANNELS, &i_num_chan);
1363 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1364 }
1365
1366 /* PCM word size */
1367 {
1368 err_code =
1369 ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
1370 IA_DRC_DEC_CONFIG_PARAM_PCM_WDSZ, &i_pcm_wd_sz);
1371 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1372 }
1373
1374 /*Set Effect Type*/
1375
1376 {
1377 err_code = (*p_ia_process_api)(
1378 pv_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM,
1379 IA_XHEAAC_DEC_CONFIG_PARAM_DRC_EFFECT_TYPE, &i_effect_type);
1380 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1381
1382 err_code =
1383 ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
1384 IA_DRC_DEC_CONFIG_DRC_EFFECT_TYPE, &i_effect_type);
1385 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1386 }
1387
1388 /*Set target loudness */
1389
1390 {
1391 err_code = (*p_ia_process_api)(
1392 pv_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM,
1393 IA_XHEAAC_DEC_CONFIG_PARAM_DRC_TARGET_LOUDNESS,
1394 &i_target_loudness);
1395 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1396
1397 err_code = ia_drc_dec_api(
1398 pv_ia_drc_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
1399 IA_DRC_DEC_CONFIG_DRC_TARGET_LOUDNESS, &i_target_loudness);
1400 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1401 }
1402
1403 /*Set loud_norm_flag*/
1404 {
1405 err_code = (*p_ia_process_api)(
1406 pv_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM,
1407 IA_XHEAAC_DEC_CONFIG_PARAM_DRC_LOUD_NORM, &i_loud_norm);
1408 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1409
1410 err_code =
1411 ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
1412 IA_DRC_DEC_CONFIG_DRC_LOUD_NORM, &i_loud_norm);
1413 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1414 }
1415
1416 /* Get memory info tables size */
1417 err_code =
1418 ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_GET_MEMTABS_SIZE,
1419 0, &ui_proc_mem_tabs_size);
1420 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1421
1422 g_pv_arr_alloc_memory[g_w_malloc_count] = malloc(ui_proc_mem_tabs_size);
1423
1424 if (g_pv_arr_alloc_memory[g_w_malloc_count] == NULL) {
1425 err_code = IA_TESTBENCH_MFMAN_FATAL_MEM_ALLOC_FAILED;
1426 _IA_HANDLE_ERROR(&ixheaacd_ia_testbench_error_info,
1427 (pWORD8) "Mem tables alloc", err_code);
1428 }
1429
1430 /* Set pointer for process memory tables */
1431 err_code = ia_drc_dec_api(
1432 pv_ia_drc_process_api_obj, IA_API_CMD_SET_MEMTABS_PTR, 0,
1433 (pVOID)((WORD8 *)g_pv_arr_alloc_memory[g_w_malloc_count]));
1434
1435 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1436
1437 g_w_malloc_count++;
1438
1439 err_code = ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_INIT,
1440 IA_CMD_TYPE_INIT_API_POST_CONFIG_PARAMS, NULL);
1441
1442 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1443
1444 /* Get number of memory tables required */
1445 err_code = ia_drc_dec_api(pv_ia_drc_process_api_obj,
1446 IA_API_CMD_GET_N_MEMTABS, 0, &n_mems);
1447
1448 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1449
1450 for (i = 0; i < (WORD32)n_mems - 2; i++) {
1451 WORD32 ui_size, ui_alignment, ui_type;
1452 pVOID pv_alloc_ptr;
1453
1454 /* Get memory size */
1455 err_code = ia_drc_dec_api(pv_ia_drc_process_api_obj,
1456 IA_API_CMD_GET_MEM_INFO_SIZE, i, &ui_size);
1457
1458 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1459
1460 /* Get memory alignment */
1461 err_code =
1462 ia_drc_dec_api(pv_ia_drc_process_api_obj,
1463 IA_API_CMD_GET_MEM_INFO_ALIGNMENT, i, &ui_alignment);
1464
1465 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1466
1467 /* Get memory type */
1468 err_code = ia_drc_dec_api(pv_ia_drc_process_api_obj,
1469 IA_API_CMD_GET_MEM_INFO_TYPE, i, &ui_type);
1470
1471 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1472
1473 g_pv_arr_alloc_memory[g_w_malloc_count] = malloc(ui_size + ui_alignment);
1474
1475 if (g_pv_arr_alloc_memory[g_w_malloc_count] == NULL) {
1476 _IA_HANDLE_ERROR(&ixheaacd_ia_testbench_error_info,
1477 (pWORD8) "Mem tables alloc", err_code);
1478 }
1479
1480 ui_rem = ((SIZE_T)g_pv_arr_alloc_memory[g_w_malloc_count] % ui_alignment);
1481 pv_alloc_ptr = (pVOID)((WORD8 *)g_pv_arr_alloc_memory[g_w_malloc_count] +
1482 ui_alignment - ui_rem);
1483
1484 g_w_malloc_count++;
1485
1486 /* Set the buffer pointer */
1487 err_code = ia_drc_dec_api(pv_ia_drc_process_api_obj,
1488 IA_API_CMD_SET_MEM_PTR, i, pv_alloc_ptr);
1489
1490 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1491 }
1492 err_code = ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_SET_MEM_PTR,
1493 2, drc_ip_buf);
1494 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1495
1496 err_code = ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_SET_MEM_PTR,
1497 3, drc_op_buf);
1498 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1499
1500 /*ITTIAM: DRC buffers
1501 buf[0] - contains extension element pay load loudness related
1502 buf[1] - contains extension element pay load*/
1503 {
1504 VOID *p_array[2][16];
1505 WORD32 ii;
1506 WORD32 buf_sizes[2][16];
1507 WORD32 num_elements;
1508 WORD32 num_config_ext;
1509 WORD32 bit_str_fmt = 1;
1510
1511 memset(buf_sizes, 0, 32 * sizeof(WORD32));
1512
1513 err_code = (*p_ia_process_api)(
1514 pv_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM,
1515 IA_ENHAACPLUS_DEC_CONFIG_EXT_ELE_BUF_SIZES, &buf_sizes[0][0]);
1516 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1517
1518 err_code = (*p_ia_process_api)(
1519 pv_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM,
1520 IA_ENHAACPLUS_DEC_CONFIG_EXT_ELE_PTR, &p_array);
1521 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1522
1523 err_code = ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_INIT,
1524 IA_CMD_TYPE_INIT_SET_BUFF_PTR, 0);
1525
1526 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1527
1528 err_code = (*p_ia_process_api)(
1529 pv_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM,
1530 IA_ENHAACPLUS_DEC_CONFIG_NUM_ELE, &num_elements);
1531 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1532
1533 err_code = (*p_ia_process_api)(
1534 pv_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM,
1535 IA_ENHAACPLUS_DEC_CONFIG_NUM_CONFIG_EXT, &num_config_ext);
1536 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1537
1538 for (ii = 0; ii < num_config_ext; ii++) {
1539 /*copy loudness bitstream*/
1540 if (buf_sizes[0][ii] > 0) {
1541 memcpy(drc_ip_buf, p_array[0][ii], buf_sizes[0][ii]);
1542
1543 /*Set bitstream_split_format */
1544 err_code = ia_drc_dec_api(
1545 pv_ia_drc_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
1546 IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT, &bit_str_fmt);
1547
1548 /* Set number of bytes to be processed */
1549 err_code = ia_drc_dec_api(pv_ia_drc_process_api_obj,
1550 IA_API_CMD_SET_INPUT_BYTES_IL_BS, 0,
1551 &buf_sizes[0][ii]);
1552
1553 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1554
1555 /* Execute process */
1556 err_code = ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_INIT,
1557 IA_CMD_TYPE_INIT_CPY_IL_BSF_BUFF, NULL);
1558
1559 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1560
1561 drc_flag = 1;
1562 }
1563 }
1564
1565 for (ii = 0; ii < num_elements; ii++) {
1566 /*copy config bitstream*/
1567 if (buf_sizes[1][ii] > 0) {
1568 memcpy(drc_ip_buf, p_array[1][ii], buf_sizes[1][ii]);
1569 /* Set number of bytes to be processed */
1570
1571 /*Set bitstream_split_format */
1572 err_code = ia_drc_dec_api(
1573 pv_ia_drc_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
1574 IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT, &bit_str_fmt);
1575
1576 err_code = ia_drc_dec_api(pv_ia_drc_process_api_obj,
1577 IA_API_CMD_SET_INPUT_BYTES_IC_BS, 0,
1578 &buf_sizes[1][ii]);
1579
1580 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1581
1582 /* Execute process */
1583 err_code = ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_INIT,
1584 IA_CMD_TYPE_INIT_CPY_IC_BSF_BUFF, NULL);
1585
1586 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1587
1588 drc_flag = 1;
1589 }
1590 }
1591
1592 if (drc_flag == 1) {
1593 mpegd_drc_present = 1;
1594 } else {
1595 mpegd_drc_present = 0;
1596 }
1597
1598 /*Read interface buffer config file bitstream*/
1599
1600 if (mpegd_drc_present == 1) {
1601 WORD32 interface_is_present = 1;
1602
1603 err_code = ia_drc_dec_api(
1604 pv_ia_drc_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
1605 IA_DRC_DEC_CONFIG_PARAM_INT_PRESENT, &interface_is_present);
1606 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1607
1608 /* Execute process */
1609 err_code = ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_INIT,
1610 IA_CMD_TYPE_INIT_CPY_IN_BSF_BUFF, NULL);
1611
1612 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1613
1614 err_code = ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_INIT,
1615 IA_CMD_TYPE_INIT_PROCESS, NULL);
1616
1617 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1618
1619 err_code = ia_drc_dec_api(
1620 pv_ia_drc_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM,
1621 IA_DRC_DEC_CONFIG_PARAM_NUM_CHANNELS, &uo_num_chan);
1622 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1623 }
1624 }
1625 }
1626
1627 /* ******************************************************************/
1628 /* Get config params from API */
1629 /* ******************************************************************/
1630
1631 err_code = (*p_get_config_param)(pv_ia_process_api_obj, &i_samp_freq,
1632 &i_num_chan, &i_pcm_wd_sz, &i_channel_mask,
1633 &i_sbr_mode, &ui_aot);
1634 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1635
1636 if (raw_testing) {
1637 skip_samples = get_start_offset_in_samples(meta_info);
1638 if (ui_aot >= 23) {
1639 skip_samples = skip_samples - 2048;
1640 if (skip_samples < 0) {
1641 skip_samples = 0;
1642 }
1643 }
1644 if (eld_testing == 0) total_samples = get_play_time_in_samples(meta_info);
1645 }
1646
1647 /* End second part */
1648
1649 #ifdef WAV_HEADER
1650 // This condition is added so as to avoid re-writing wave header in
1651 // middle of wave file in case of errors and when we are not opening
1652 // new file in case of errors.
1653
1654 #ifndef ARM_PROFILE_BOARD
1655
1656 write_wav_header(g_pf_out, 0, i_samp_freq, i_num_chan, i_pcm_wd_sz,
1657 i_channel_mask);
1658 #endif
1659 #endif
1660 prev_sampling_rate = i_samp_freq;
1661
1662 do {
1663 if (((WORD32)ui_inp_size - (WORD32)(i_buff_size - i_bytes_consumed)) > 0) {
1664 if (i_sbr_mode && (ui_aot < 23)) {
1665 if (meta_info.ia_mp4_stsz_entries != frame_counter) {
1666 for (i = 0; i < (i_buff_size - i_bytes_consumed); i++) {
1667 pb_inp_buf[i] = pb_inp_buf[i + i_bytes_consumed];
1668 }
1669
1670 FileWrapper_Read(
1671 g_pf_inp,
1672 (unsigned char *)(pb_inp_buf + i_buff_size - i_bytes_consumed),
1673 ((WORD32)ui_inp_size - (WORD32)(i_buff_size - i_bytes_consumed)),
1674 (pUWORD32)&i_bytes_read);
1675
1676 i_buff_size = i_buff_size - (i_bytes_consumed - i_bytes_read);
1677
1678 if ((i_buff_size <= 0) ||
1679 ((err_code_reinit == 0x00001804) && i_bytes_read == 0)) {
1680 i_buff_size = 0;
1681 raw_testing = 0;
1682 /* Tell that the input is over in this buffer */
1683 err_code = (*p_ia_process_api)(pv_ia_process_api_obj,
1684 IA_API_CMD_INPUT_OVER, 0, NULL);
1685
1686 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1687 }
1688 }
1689 } else {
1690 for (i = 0; i < (i_buff_size - i_bytes_consumed); i++) {
1691 pb_inp_buf[i] = pb_inp_buf[i + i_bytes_consumed];
1692 }
1693
1694 FileWrapper_Read(g_pf_inp, (unsigned char *)(pb_inp_buf + i_buff_size -
1695 i_bytes_consumed),
1696 ((WORD32)ui_inp_size - (WORD32)(i_buff_size - i_bytes_consumed)),
1697 (pUWORD32)&i_bytes_read);
1698
1699 i_buff_size = i_buff_size - (i_bytes_consumed - i_bytes_read);
1700
1701 if ((i_buff_size <= 0) ||
1702 ((err_code_reinit == 0x00001804) && i_bytes_read == 0)) {
1703 i_buff_size = 0;
1704 raw_testing = 0;
1705
1706 err_code = (*p_ia_process_api)(pv_ia_process_api_obj,
1707 IA_API_CMD_INPUT_OVER, 0, NULL);
1708
1709 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1710 }
1711 }
1712 }
1713 if (i_sbr_mode && (ui_aot < 23)) {
1714 if (meta_info.ia_mp4_stsz_entries != frame_counter) {
1715 if (raw_testing) {
1716 ixheaacd_i_bytes_to_read =
1717 get_metadata_dec_exec(meta_info, frame_counter);
1718
1719 if (ixheaacd_i_bytes_to_read > (WORD32)ui_inp_size)
1720 return IA_FATAL_ERROR;
1721 if (ixheaacd_i_bytes_to_read <= 0 && ec_enable == 0) {
1722 err_code = (*p_ia_process_api)(pv_ia_process_api_obj,
1723 IA_API_CMD_INPUT_OVER, 0, NULL);
1724
1725 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1726
1727 return IA_NO_ERROR;
1728 }
1729 err_code =
1730 (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_SET_INPUT_BYTES,
1731 0, &ixheaacd_i_bytes_to_read);
1732 } else {
1733 err_code = (*p_ia_process_api)(
1734 pv_ia_process_api_obj, IA_API_CMD_SET_INPUT_BYTES, 0, &i_buff_size);
1735 }
1736 }
1737 } else {
1738 if (raw_testing) {
1739 ixheaacd_i_bytes_to_read =
1740 get_metadata_dec_exec(meta_info, frame_counter);
1741
1742 if (ixheaacd_i_bytes_to_read > (WORD32)ui_inp_size) return IA_FATAL_ERROR;
1743
1744 if (ixheaacd_i_bytes_to_read <= 0 && ec_enable == 0) {
1745 err_code = (*p_ia_process_api)(pv_ia_process_api_obj,
1746 IA_API_CMD_INPUT_OVER, 0, NULL);
1747
1748 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1749
1750 return IA_NO_ERROR;
1751 }
1752
1753 if (ec_enable == 1) {
1754 if (ixheaacd_i_bytes_to_read != 0) {
1755 err_code = (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_SET_INPUT_BYTES, 0,
1756 &ixheaacd_i_bytes_to_read);
1757 } else {
1758 if (i_buff_size != 0) {
1759 err_code = (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_SET_INPUT_BYTES, 0,
1760 &i_buff_size);
1761 }
1762 }
1763 } else {
1764 err_code = (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_SET_INPUT_BYTES, 0,
1765 &ixheaacd_i_bytes_to_read);
1766 }
1767 } else {
1768 /* Set number of bytes to be processed */
1769 err_code = (*p_ia_process_api)(
1770 pv_ia_process_api_obj, IA_API_CMD_SET_INPUT_BYTES, 0, &i_buff_size);
1771
1772 if (i_buff_size <= 0)
1773 {
1774 err_code = (*p_ia_process_api)(
1775 pv_ia_process_api_obj, IA_API_CMD_INPUT_OVER, 0, NULL);
1776
1777 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1778 }
1779 }
1780 }
1781
1782 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1783
1784 #ifdef ARM_PROFILE_HW
1785 start1_b = itGetMs();
1786 #endif
1787
1788 /* Execute process */
1789
1790 counter_bl = frame_counter;
1791
1792 err_code = (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_EXECUTE,
1793 IA_CMD_TYPE_DO_EXECUTE, NULL);
1794
1795 err_code_reinit = err_code;
1796
1797 #ifdef ARM_PROFILE_HW
1798 stop1_b = itGetMs();
1799 cycles_b = (stop1_b - start1_b);
1800 #endif
1801
1802 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1803
1804 fatal_error_chk = err_code & IA_FATAL_ERROR;
1805
1806 /* Checking for end of processing */
1807 err_code = (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_EXECUTE,
1808 IA_CMD_TYPE_DONE_QUERY, &ui_exec_done);
1809
1810 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1811
1812 err_code = (*p_ia_process_api)(
1813 pv_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM,
1814 IA_ENHAACPLUS_DEC_CONFIG_GET_NUM_PRE_ROLL_FRAMES, &num_preroll);
1815 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1816 {
1817 WORD32 preroll_frame_offset = 0;
1818 do {
1819 if (mpeg_d_drc_on == 1) {
1820 if (ui_exec_done != 1) {
1821 VOID *p_array; // ITTIAM:buffer to handle gain payload
1822 WORD32 buf_size = 0; // ITTIAM:gain payload length
1823 WORD32 bit_str_fmt = 1;
1824 WORD32 gain_stream_flag = 1;
1825
1826 err_code = (*p_ia_process_api)(
1827 pv_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM,
1828 IA_ENHAACPLUS_DEC_CONFIG_GAIN_PAYLOAD_LEN, &buf_size);
1829 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1830
1831 err_code = (*p_ia_process_api)(
1832 pv_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM,
1833 IA_ENHAACPLUS_DEC_CONFIG_GAIN_PAYLOAD_BUF, &p_array);
1834 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1835
1836 if (buf_size > 0) {
1837 /*Set bitstream_split_format */
1838 err_code = ia_drc_dec_api(
1839 pv_ia_drc_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
1840 IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT, &bit_str_fmt);
1841
1842 memcpy(drc_ip_buf, p_array, buf_size);
1843 /* Set number of bytes to be processed */
1844 err_code =
1845 ia_drc_dec_api(pv_ia_drc_process_api_obj,
1846 IA_API_CMD_SET_INPUT_BYTES_BS, 0, &buf_size);
1847
1848 err_code = ia_drc_dec_api(
1849 pv_ia_drc_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
1850 IA_DRC_DEC_CONFIG_GAIN_STREAM_FLAG, &gain_stream_flag);
1851
1852 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1853
1854 /* Execute process */
1855 err_code =
1856 ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_INIT,
1857 IA_CMD_TYPE_INIT_CPY_BSF_BUFF, NULL);
1858
1859 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1860
1861 mpegd_drc_present = 1;
1862 }
1863 }
1864 }
1865 /* How much buffer is used in input buffers */
1866 err_code = (*p_ia_process_api)(pv_ia_process_api_obj,
1867 IA_API_CMD_GET_CURIDX_INPUT_BUF, 0,
1868 &i_bytes_consumed);
1869
1870 // printf("bytes_consumed: %d \n", i_bytes_consumed);
1871 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1872
1873 /* Get the output bytes */
1874 err_code =
1875 (*p_ia_process_api)(pv_ia_process_api_obj,
1876 IA_API_CMD_GET_OUTPUT_BYTES, 0, &i_out_bytes);
1877
1878 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1879
1880 if (err_code_reinit != 0) memset(pb_out_buf, 0, i_out_bytes);
1881
1882 if (i_sbr_mode && (ui_aot < 23)) {
1883 if (frame_counter > 0)
1884 i_total_bytes += i_out_bytes;
1885 } else {
1886 i_total_bytes += i_out_bytes;
1887 }
1888 if (mpegd_drc_present == 1) {
1889 WORD32 is_config_changed = 0, apply_crossfade = 0;
1890
1891 err_code = (*p_ia_process_api)(
1892 pv_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM,
1893 IA_XHEAAC_DEC_CONFIG_PARAM_SBR_MODE, &i_sbr_mode);
1894 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1895
1896 if (i_sbr_mode != 0) {
1897 WORD32 frame_length;
1898 if (i_sbr_mode == 1) {
1899 frame_length = 2048;
1900 } else if (i_sbr_mode == 3) {
1901 frame_length = 4096;
1902 } else {
1903 frame_length = 1024;
1904 }
1905
1906 err_code = ia_drc_dec_api(
1907 pv_ia_drc_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
1908 IA_DRC_DEC_CONFIG_PARAM_FRAME_SIZE, &frame_length);
1909 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1910 }
1911
1912 err_code =
1913 ia_drc_dec_api(pv_ia_drc_process_api_obj,
1914 IA_API_CMD_SET_INPUT_BYTES, 0, &i_out_bytes);
1915
1916 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1917
1918 err_code = (*p_ia_process_api)(
1919 pv_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM,
1920 IA_ENHAACPLUS_DEC_DRC_IS_CONFIG_CHANGED, &is_config_changed);
1921
1922 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1923
1924 err_code = ia_drc_dec_api(
1925 pv_ia_drc_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
1926 IA_DRC_DEC_CONFIG_PARAM_CONFIG_CHANGED, &is_config_changed);
1927 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1928
1929 err_code = (*p_ia_process_api)(
1930 pv_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM,
1931 IA_ENHAACPLUS_DEC_DRC_APPLY_CROSSFADE, &apply_crossfade);
1932
1933 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1934
1935 err_code = ia_drc_dec_api(
1936 pv_ia_drc_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
1937 IA_DRC_DEC_CONFIG_PARAM_APPLY_CROSSFADE, &apply_crossfade);
1938 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1939
1940 if (is_config_changed == 1) {
1941 VOID *p_array[2][16];
1942 WORD32 ii;
1943 WORD32 num_elements;
1944 WORD32 num_config_ext;
1945 WORD32 buf_sizes[2][16];
1946 WORD32 bit_str_fmt = 1;
1947
1948 memset(buf_sizes, 0, 32 * sizeof(WORD32));
1949
1950 err_code = (*p_ia_process_api)(
1951 pv_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM,
1952 IA_ENHAACPLUS_DEC_CONFIG_EXT_ELE_BUF_SIZES, &buf_sizes[0][0]);
1953 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1954
1955 err_code = (*p_ia_process_api)(
1956 pv_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM,
1957 IA_ENHAACPLUS_DEC_CONFIG_EXT_ELE_PTR, &p_array);
1958 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1959
1960 err_code =
1961 ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_INIT,
1962 IA_CMD_TYPE_INIT_SET_BUFF_PTR, 0);
1963
1964 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1965
1966 err_code = (*p_ia_process_api)(
1967 pv_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM,
1968 IA_ENHAACPLUS_DEC_CONFIG_NUM_ELE, &num_elements);
1969 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1970
1971 err_code = (*p_ia_process_api)(
1972 pv_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM,
1973 IA_ENHAACPLUS_DEC_CONFIG_NUM_CONFIG_EXT, &num_config_ext);
1974 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1975
1976 for (ii = 0; ii < num_config_ext; ii++) {
1977 /*copy loudness bitstream*/
1978 if (buf_sizes[0][ii] > 0) {
1979 memcpy(drc_ip_buf, p_array[0][ii], buf_sizes[0][ii]);
1980
1981 /*Set bitstream_split_format */
1982 err_code = ia_drc_dec_api(
1983 pv_ia_drc_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
1984 IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT, &bit_str_fmt);
1985
1986 /* Set number of bytes to be processed */
1987 err_code = ia_drc_dec_api(pv_ia_drc_process_api_obj,
1988 IA_API_CMD_SET_INPUT_BYTES_IL_BS, 0,
1989 &buf_sizes[0][ii]);
1990
1991 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1992
1993 /* Execute process */
1994 err_code =
1995 ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_INIT,
1996 IA_CMD_TYPE_INIT_CPY_IL_BSF_BUFF, NULL);
1997
1998 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
1999
2000 drc_flag = 1;
2001 }
2002 }
2003
2004 for (ii = 0; ii < num_elements; ii++) {
2005 /*copy config bitstream*/
2006 if (buf_sizes[1][ii] > 0) {
2007 memcpy(drc_ip_buf, p_array[1][ii], buf_sizes[1][ii]);
2008
2009 /*Set bitstream_split_format */
2010 err_code = ia_drc_dec_api(
2011 pv_ia_drc_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM,
2012 IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT, &bit_str_fmt);
2013
2014 /* Set number of bytes to be processed */
2015 err_code = ia_drc_dec_api(pv_ia_drc_process_api_obj,
2016 IA_API_CMD_SET_INPUT_BYTES_IC_BS, 0,
2017 &buf_sizes[1][ii]);
2018
2019 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
2020
2021 /* Execute process */
2022 err_code =
2023 ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_INIT,
2024 IA_CMD_TYPE_INIT_CPY_IC_BSF_BUFF, NULL);
2025
2026 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
2027
2028 drc_flag = 1;
2029 }
2030 }
2031 }
2032
2033 memcpy(drc_ip_buf, pb_out_buf + preroll_frame_offset, i_out_bytes);
2034 preroll_frame_offset += i_out_bytes;
2035
2036 err_code =
2037 ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_EXECUTE,
2038 IA_CMD_TYPE_DO_EXECUTE, NULL);
2039
2040 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
2041
2042 memcpy(pb_out_buf, drc_op_buf, i_out_bytes);
2043 } else {
2044 memmove(pb_out_buf, pb_out_buf + preroll_frame_offset, i_out_bytes);
2045 preroll_frame_offset += i_out_bytes;
2046 }
2047
2048 num_preroll--;
2049 } while (num_preroll > 0);
2050 }
2051
2052 if (total_samples != 0) // Usac stream
2053 {
2054 if (raw_testing) {
2055 if (i_total_bytes <= skip_samples * i_num_chan * (i_pcm_wd_sz >> 3)) {
2056 err_code =
2057 (*p_get_config_param)(pv_ia_process_api_obj, &i_samp_freq,
2058 &i_num_chan, &i_pcm_wd_sz, &i_channel_mask,
2059 &i_sbr_mode, &ui_aot);
2060
2061 write_flag = 0;
2062 } else {
2063 write_flag = 1;
2064 bytes_to_write =
2065 i_total_bytes - skip_samples * i_num_chan * (i_pcm_wd_sz >> 3);
2066 if (bytes_to_write < i_out_bytes) {
2067 ixheaacd_drc_offset = i_out_bytes - bytes_to_write;
2068 i_out_bytes = bytes_to_write;
2069 current_samples =
2070 bytes_to_write / (i_num_chan * (i_pcm_wd_sz >> 3));
2071 } else {
2072 ixheaacd_drc_offset = 0;
2073 current_samples = i_out_bytes / (i_num_chan * (i_pcm_wd_sz >> 3));
2074 }
2075 }
2076 }
2077
2078 if (raw_testing) {
2079 samples_written += current_samples;
2080
2081 if (samples_written > total_samples) {
2082 i_out_bytes = (total_samples - (samples_written - current_samples)) *
2083 (i_num_chan * (i_pcm_wd_sz >> 3)); // hack
2084 if (i_out_bytes < 0) i_out_bytes = 0;
2085 }
2086 }
2087 }
2088
2089 if (write_flag) {
2090 #ifndef WIN32
2091 #ifndef ARM_PROFILE_BOARD
2092 ia_fwrite((pVOID)(pb_out_buf + ixheaacd_drc_offset), (i_pcm_wd_sz / 8),
2093 i_out_bytes / (i_pcm_wd_sz / 8), g_pf_out);
2094 #endif
2095 #else
2096 #ifndef ARM_PROFILE_BOARD
2097 if (i_sbr_mode && (ui_aot < 23)) {
2098 if (frame_counter != 0) {
2099 fwrite(pb_out_buf + ixheaacd_drc_offset, sizeof(WORD8), i_out_bytes,
2100 g_pf_out);
2101 fflush(g_pf_out);
2102 }
2103 } else {
2104 fwrite(pb_out_buf + ixheaacd_drc_offset, sizeof(WORD8), i_out_bytes,
2105 g_pf_out);
2106 fflush(g_pf_out);
2107 }
2108 #endif
2109 #endif
2110 }
2111
2112 frame_counter++;
2113
2114 #ifdef ARM_PROFILE_HW
2115 if (i_out_bytes != 0) {
2116 int i_out_samples = i_out_bytes >> 2;
2117 if (frame_count_b) {
2118 double i_out_samples_per_ch =
2119 (i_out_bytes) / ((i_pcm_wd_sz / 8) * i_num_chan);
2120 Curr_b = (((double)cycles_b / 1000000) * CLK_FREQ_BOARD_MHZ) /
2121 (i_out_samples_per_ch / i_samp_freq);
2122 frame_count_b++;
2123 // fprintf(stderr, "Microseconds: %d\t", cycles_b);
2124 // fprintf(stderr, "MCPS: %f\n", Curr_b);
2125 Sum_b += Curr_b;
2126 Ave_b = Sum_b / frame_count_b;
2127 if (Peak_b < Curr_b) {
2128 Peak_b = Curr_b;
2129 Peak_frame_b = frame_count_b;
2130 }
2131 } else {
2132 frame_count_b++;
2133 }
2134
2135 cycles_b = 0;
2136 }
2137 #endif
2138
2139 /* Do till the process execution is done */
2140 } while (!ui_exec_done && !fatal_error_chk);
2141
2142 #ifdef ARM_PROFILE_HW
2143 fprintf(stdout, "\n Peak MCPS = %f\n", Peak_b);
2144 fprintf(stdout, " Avg MCPS = %f\n", Ave_b);
2145 fprintf(stdout, " Peak frame = %d\n", Peak_frame_b);
2146 #endif
2147 fprintf(stderr, "TOTAL FRAMES : [%5d] \n", frame_counter);
2148 err_code = (*p_get_config_param)(pv_ia_process_api_obj, &i_samp_freq,
2149 &i_num_chan, &i_pcm_wd_sz, &i_channel_mask,
2150 &i_sbr_mode, &ui_aot);
2151 _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
2152
2153 #ifdef WAV_HEADER
2154 #ifndef ARM_PROFILE_BOARD
2155 if (!fseek(g_pf_out, 0, SEEK_SET))
2156 write_wav_header(g_pf_out, i_total_bytes, i_samp_freq, i_num_chan,
2157 i_pcm_wd_sz, i_channel_mask);
2158 #endif
2159 #endif
2160
2161 return IA_NO_ERROR;
2162 }
2163
2164 /*****************************************************************************/
2165 /* */
2166 /* Function Name : ixheaacd_main */
2167 /* */
2168 /* Description : Main function */
2169 /* */
2170 /* Inputs : None */
2171 /* */
2172 /* Globals : None */
2173 /* */
2174 /* Processing : Parse the parameter file and run the ixheaacd_main process
2175 */
2176 /* */
2177 /* Outputs : None */
2178 /* */
2179 /* Returns : 0 on success, -1 on error */
2180 /* */
2181 /* Issues : None */
2182 /* */
2183 /* Revision history : */
2184 /* */
2185 /* DD MM YYYY Author Changes */
2186 /* 04 09 2005 Ittiam Created */
2187 /* */
2188 /*****************************************************************************/
2189
print_usage()2190 void print_usage() {
2191 #ifdef DISPLAY_MESSAGE
2192 ia_lib_info_struct str_lib_info = {0};
2193 ixheaacd_get_lib_id_strings(&str_lib_info);
2194
2195 ia_display_id_message(str_lib_info.p_lib_name, str_lib_info.p_version_num);
2196 #endif
2197 printf("\n Usage \n");
2198 printf("\n <executable> -ifile:<input_file> -imeta:<meta_data_file> -ofile:<output_file> "
2199 "[options]\n");
2200 printf("\n[options] can be,");
2201 printf("\n[-mp4:<mp4_flag>]");
2202 printf("\n[-pcmsz:<pcmwordsize>]");
2203 printf("\n[-dmix:<down_mix>]");
2204 printf("\n[-esbr_hq:<esbr_hq_flag>]");
2205 printf("\n[-esbr_ps:<esbr_ps_flag>]");
2206 printf("\n[-tostereo:<interleave_to_stereo>]");
2207 printf("\n[-dsample:<down_sample_sbr>]");
2208 printf("\n[-drc_cut_fac:<drc_cut_factor>]");
2209 printf("\n[-drc_boost_fac:<drc_boost_factor>]");
2210 printf("\n[-drc_target_level:<drc_target_level>]");
2211 printf("\n[-drc_heavy_comp:<drc_heavy_compression>]");
2212 printf("\n[-effect:<effect_type>]");
2213 printf("\n[-target_loudness:<target_loudness>]");
2214 printf("\n[-nosync:<disable_sync>]");
2215 printf("\n[-sbrup:<auto_sbr_upsample>]");
2216 printf("\n[-flflag:<framelength_flag>}");
2217 printf("\n[-fs:<RAW_sample_rate>]");
2218 printf("\n[-maxchannel:<maximum_num_channels>]");
2219 #ifdef MULTICHANNEL_ENABLE
2220 printf("\n[-coupchannel:<coupling_channel>]");
2221 printf("\n[-downmix:<down_mix_stereo>]");
2222 #endif
2223 printf("\n[-fs480:<ld_frame_size>]");
2224 printf("\n[-ld_testing:<ld_testing_flag>]");
2225 printf("\n[-peak_limiter_off:<peak_limiter_off_flag>]");
2226 printf("\n[-err_conceal:<error_concealment_flag>]");
2227 printf("\n\nwhere, \n <input_file> is the input AAC/HEAACv1/HEAACv2/USAC file name");
2228 printf("\n <meta_data_file> is a text file which contains metadata.");
2229 printf("\n To be given when -mp4:1 is enabled");
2230 printf("\n <output_file> is the output file name");
2231 printf("\n <mp4_flag> is a flag that should be set to 1 when passing ");
2232 printf("\n raw stream along with meta data text file ");
2233 printf("\n <pcmwordsize> is the bits per sample info. 16/24");
2234 printf("\n <down_mix> is to enable/disable always mono output. Default 1");
2235 printf("\n <esbr_hq_flag> is to enable/disable high quality eSBR. Default 0");
2236 printf("\n <esbr_ps_flag> is to indicate eSBR with PS. Default 0");
2237 printf("\n <interleave_to_stereo> is to enable/disable always ");
2238 printf("\n interleaved to stereo output. Default 1 ");
2239 printf("\n <down_sample_sbr> is to enable/disable down-sampled SBR ");
2240 printf("\n output. Default auto identification from header");
2241 printf("\n <drc_cut_factor> is to set DRC cut factor value. Default value is 0");
2242 printf("\n <drc_boost_factor> is to set DRC boost factor. Default value is 0");
2243 printf("\n <drc_target_level> is to set DRC target reference level.");
2244 printf("\n Default value is 108");
2245 printf("\n <drc_heavy_compression> is to enable / disable DRC heavy compression.");
2246 printf("\n Default value is 0");
2247 printf("\n <effect_type> is set DRC effect type. Default value is 0");
2248 printf("\n <target_loudness> is to set target loudness level.");
2249 printf("\n Default value is -24");
2250 printf("\n <disable_sync> is to disable the ADTS/ADIF sync search i.e");
2251 printf("\n when enabled the decoder expects the header to ");
2252 printf("\n be at the start of input buffer. Default 0");
2253 printf("\n <auto_sbr_upsample> is to enable(1) or disable(0) auto SBR "
2254 "upsample ");
2255 printf("\n in case of stream changing from SBR present to SBR not present. "
2256 "Default 1");
2257 printf("\n <framelength_flag> is flag for decoding framelength of 1024 or 960.");
2258 printf("\n 1 to decode 960 frame length, 0 to decode 1024 frame length");
2259 printf("\n Frame length value in the GA header will override this option.");
2260 printf("\n Default 0 ");
2261 printf("\n <RAW_sample_rate> is to indicate the core AAC sample rate for");
2262 printf("\n a RAW stream. If this is specified no other file format");
2263 printf("\n headers are searched for.");
2264 printf("\n <maximum_num_channels> is the number of maxiumum ");
2265 printf("\n channels the input may have. Default is 6 ");
2266 printf("\n for multichannel libraries and 2 for stereo libraries");
2267 #ifdef MULTICHANNEL_ENABLE
2268 printf("\n <coupling_channel> is element instance tag of ");
2269 printf("\n independent coupling channel to be mixed. Default is 0");
2270 printf("\n <down_mix_stereo> is flag for Downmix. Give 1 to");
2271 printf("\n get stereo (downmix) output. Default is 0");
2272 #endif
2273 printf("\n <ld_frame_size> is to indicate ld frame size.");
2274 printf("\n 0 is for 512 frame length, 1 is for 480 frame length.");
2275 printf("\n Default value is 512 (0)");
2276 printf("\n <ld_testing_flag> is to enable / disable ld decoder testing.");
2277 printf("\n Default value is 0");
2278 printf("\n <peak_limiter_off_flag> is to enable / disable peak limiter.");
2279 printf("\n Default value is 0");
2280 printf("\n <error_concealment_flag> is to enable / disable error concealment.");
2281 printf("\n Default value is 0\n\n");
2282 }
2283
2284 /*******************************************************************************/
2285 /* */
2286 /* Function Name : ixheaacd_main */
2287 /* */
2288 /* Description : Main function */
2289 /* */
2290 /* Inputs : None */
2291 /* */
2292 /* Globals : None */
2293 /* */
2294 /* Processing : Parse the parameter file and run the ixheaacd_main_process
2295 */
2296 /* */
2297 /* Outputs : None */
2298 /* */
2299 /* Returns : 0 on success, -1 on error */
2300 /* */
2301 /* Issues : None */
2302 /* */
2303 /* Revision history : */
2304 /* */
2305 /* DD MM YYYY Author Changes */
2306 /* 04 09 2005 Ittiam Created */
2307 /* */
2308 /* */
2309 /*******************************************************************************/
2310
main(WORD32 argc,char * argv[])2311 int main(WORD32 argc, char *argv[]) {
2312 WORD32 i, err_code = IA_NO_ERROR;
2313
2314 ia_testbench_error_handler_init();
2315
2316 g_pf_inp = NULL;
2317 g_pf_meta = NULL;
2318 g_pf_out = NULL;
2319
2320 for (i = 1; i < argc; i++) {
2321 printf("%s ", argv[i]);
2322
2323 if (!strncmp((const char *)argv[i], "-ifile:", 7)) {
2324 pWORD8 pb_arg_val = (pWORD8)argv[i] + 7;
2325
2326 g_pf_inp = FileWrapper_Open((char *)pb_arg_val);
2327 if (g_pf_inp == NULL) {
2328 err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED;
2329 ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info,
2330 (pWORD8) "Input File", err_code);
2331 exit(1);
2332 }
2333 raw_testing = 0;
2334 }
2335
2336 if (!strncmp((const char *)argv[i], "-imeta:", 7)) {
2337 pWORD8 pb_arg_val = (pWORD8)argv[i] + 7;
2338
2339 g_pf_meta = fopen((const char *)pb_arg_val, "r");
2340
2341 if (g_pf_meta == NULL) {
2342 err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED;
2343 ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info,
2344 (pWORD8) "Metadata File", err_code);
2345 exit(1);
2346 }
2347
2348 err_code = ixheaacd_read_metadata_info(g_pf_meta, &meta_info);
2349
2350 if (err_code == -1) {
2351 exit(1);
2352 }
2353 raw_testing = 1;
2354 }
2355
2356 if (!strncmp((const char *)argv[i], "-ofile:", 7)) {
2357 pWORD8 pb_arg_val = (pWORD8)argv[i] + 7;
2358
2359 g_pf_out = fopen((const char *)pb_arg_val, "wb");
2360 if (g_pf_out == NULL) {
2361 err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED;
2362 ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info,
2363 (pWORD8) "Output File", err_code);
2364 exit(1);
2365 }
2366 }
2367 }
2368
2369 if ((g_pf_inp == NULL) || (g_pf_out == NULL)) {
2370 print_usage();
2371 err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED;
2372 ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info,
2373 (pWORD8) "Input or Output File", err_code);
2374 exit(1);
2375 }
2376
2377 g_w_malloc_count = 0;
2378
2379 printf("\n");
2380
2381 for (i = 0; i < argc; i++) {
2382 if (!strcmp((pCHAR8)argv[i], "-mp4:1")) {
2383 if (g_pf_meta == NULL) {
2384 print_usage();
2385 err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED;
2386 ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info,
2387 (pWORD8) "Metadata File", err_code);
2388 exit(1);
2389 }
2390 }
2391 }
2392
2393 for (i = 0; i < argc; i++) {
2394 if (strcmp((pCHAR8)argv[i], "-eld_testing:1"))
2395 eld_testing = 0;
2396 else {
2397 eld_testing = 1;
2398 break;
2399 }
2400 }
2401
2402 ixheaacd_main_process(argc - 1, (pWORD8 *)(&argv[1]));
2403
2404 for (i = 0; i < g_w_malloc_count; i++) {
2405 if (g_pv_arr_alloc_memory[i]) free(g_pv_arr_alloc_memory[i]);
2406 }
2407 if (g_pf_out) fclose(g_pf_out);
2408
2409 if (g_pf_meta) {
2410 fclose(g_pf_meta);
2411 metadata_mp4_stsz_size_free(&meta_info);
2412 }
2413 FileWrapper_Close(g_pf_inp);
2414 mpeg_d_drc_on = 0;
2415
2416 return IA_NO_ERROR;
2417 } /* end ixheaacd_main */