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