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