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