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