diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2019-04-03 00:36:27 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-04-03 00:36:27 +0000 |
commit | c99fe20ffc3580a7a7eeea191811931187cd6297 (patch) | |
tree | 83181fdab21764308d2f749cbbdfd497d700d2fb | |
parent | 360bd4fd755b7b15f54bbbb6a3485cfd697c557e (diff) | |
parent | ce6d37faa22fbb1a99b74f8578b40a4b79fb42ec (diff) | |
download | libxaac-c99fe20ffc3580a7a7eeea191811931187cd6297.tar.gz |
Merge "Fix for testbench crash due to invalid file handle"
-rw-r--r-- | test/ixheaacd_main.c | 417 |
1 files changed, 82 insertions, 335 deletions
diff --git a/test/ixheaacd_main.c b/test/ixheaacd_main.c index fef904e..889d238 100644 --- a/test/ixheaacd_main.c +++ b/test/ixheaacd_main.c @@ -60,7 +60,6 @@ extern ia_error_info_struct ixheaacd_error_info; #define IA_MAX_CMD_LINE_LENGTH 300 #define IA_MAX_ARGS 20 #define IA_SCREEN_WIDTH 80 -#define PARAMFILE "paramfilesimple.txt" /*****************************************************************************/ /* Error codes for the testbench */ @@ -99,8 +98,7 @@ WORD g_w_malloc_count; FILE *g_pf_out; FileWrapperPtr g_pf_inp; /* file pointer to bitstream file (mp4) */ -FILE *g_pf_interface; -WORD32 interface_file_present = 0; +WORD32 mpeg_d_drc_on = 0; metadata_info meta_info; // metadata pointer; WORD32 ixheaacd_i_bytes_to_read; @@ -595,15 +593,21 @@ IA_ERRORCODE ixheaacd_set_config_param(WORD32 argc, pWORD8 argv[], (*p_ia_process_api)(p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, IA_ENHAACPLUS_DEC_DRC_EFFECT_TYPE, &ui_effect); _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); + mpeg_d_drc_on = 1; } /*For MPEG-D DRC target loudness*/ if (!strncmp((pCHAR8)argv[i], "-target_loudness:", 17)) { pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 17); WORD32 ui_target_loudness = atoi(pb_arg_val); + if ((ui_target_loudness > 0) || (ui_target_loudness < -63)) { + ui_target_loudness = 0; + } + ui_target_loudness = -(ui_target_loudness << 2); err_code = (*p_ia_process_api)( p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, IA_ENHAACPLUS_DEC_DRC_TARGET_LOUDNESS, &ui_target_loudness); _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); + mpeg_d_drc_on = 1; } if (!strncmp((pCHAR8)argv[i], "-ld_testing:", 12)) { pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 12); @@ -1261,7 +1265,7 @@ int ixheaacd_main_process(WORD32 argc, pWORD8 argv[]) { } while (!ui_init_done); - if (interface_file_present == 1) { + if (mpeg_d_drc_on == 1) { err_code = (*p_get_config_param)(pv_ia_process_api_obj, &i_samp_freq, &i_num_chan, &i_pcm_wd_sz, &i_channel_mask); @@ -1653,7 +1657,7 @@ int ixheaacd_main_process(WORD32 argc, pWORD8 argv[]) { _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - if (interface_file_present == 1) { + if (mpeg_d_drc_on == 1) { if (ui_exec_done != 1) { VOID *p_array; // ITTIAM:buffer to handle gain payload WORD32 buf_size = 0; // ITTIAM:gain payload length @@ -1976,366 +1980,109 @@ void print_usage() { /*******************************************************************************/ int main(WORD32 argc, char *argv[]) { - FILE *param_file_id; - - WORD8 curr_cmd[IA_MAX_CMD_LINE_LENGTH]; - WORD32 fargc, curpos; - WORD32 processcmd = 0; - - WORD8 fargv[IA_MAX_ARGS][IA_MAX_CMD_LINE_LENGTH]; - - pWORD8 pargv[IA_MAX_ARGS]; - - WORD8 pb_input_file_path[IA_MAX_CMD_LINE_LENGTH] = ""; - WORD8 pb_output_file_path[IA_MAX_CMD_LINE_LENGTH] = ""; + WORD32 i, err_code = IA_NO_ERROR; ia_testbench_error_handler_init(); - if (argc == 1) { - param_file_id = fopen(PARAMFILE, "r"); - if (param_file_id == NULL) { - print_usage(); - return IA_NO_ERROR; - } - - /* Process one line at a time */ - while (fgets((char *)curr_cmd, IA_MAX_CMD_LINE_LENGTH, param_file_id)) { - curpos = 0; - fargc = 0; - /* if it is not a param_file command and if */ - /* CLP processing is not enabled */ - if (curr_cmd[0] != '@' && !processcmd) { /* skip it */ - continue; - } + g_pf_inp = NULL; + g_pf_meta = NULL; + g_pf_out = NULL; - while (sscanf((char *)curr_cmd + curpos, "%s", fargv[fargc]) != EOF) { - if (fargv[0][0] == '/' && fargv[0][1] == '/') break; - if (strcmp((const char *)fargv[0], "@echo") == 0) break; - if (strcmp((const char *)fargv[fargc], "@New_line") == 0) { - fgets((char *)curr_cmd + curpos, IA_MAX_CMD_LINE_LENGTH, - param_file_id); - continue; - } - curpos += strlen((const char *)fargv[fargc]); - while (*(curr_cmd + curpos) == ' ' || *(curr_cmd + curpos) == '\t') - curpos++; - fargc++; - } + for (i = 1; i < argc; i++) { + printf("%s ", argv[i]); - if (fargc < 1) /* for blank lines etc. */ - continue; + if (!strncmp((const char *)argv[i], "-ifile:", 7)) { + pWORD8 pb_arg_val = (pWORD8)argv[i] + 7; - if (strcmp((const char *)fargv[0], "@Output_path") == 0) { - if (fargc > 1) - strcpy((char *)pb_output_file_path, (const char *)fargv[1]); - else - strcpy((char *)pb_output_file_path, ""); - continue; + g_pf_inp = FileWrapper_Open((char *)pb_arg_val); + if (g_pf_inp == NULL) { + err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; + ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, + (pWORD8) "Input File", err_code); + exit(1); } + raw_testing = 0; + } - if (strcmp((const char *)fargv[0], "@Input_path") == 0) { - if (fargc > 1) - strcpy((char *)pb_input_file_path, (const char *)fargv[1]); - else - strcpy((char *)pb_input_file_path, ""); - continue; - } + if (!strncmp((const char *)argv[i], "-imeta:", 7)) { + pWORD8 pb_arg_val = (pWORD8)argv[i] + 7; - if (strcmp((const char *)fargv[0], "@Start") == 0) { - processcmd = 1; - continue; - } + g_pf_meta = fopen((const char *)pb_arg_val, "r"); - if (strcmp((const char *)fargv[0], "@Stop") == 0) { - processcmd = 0; - continue; + if (g_pf_meta == NULL) { + err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; + ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, + (pWORD8) "Metadata File", err_code); + exit(1); } - /* otherwise if this a normal command and its enabled for execution */ - if (processcmd) { - int i; - int err_code = IA_NO_ERROR; - int file_count = 0; - - for (i = 0; i < fargc; i++) { - printf("%s ", fargv[i]); - pargv[i] = fargv[i]; - - if (!strncmp((const char *)fargv[i], "-ifile:", 7)) { - pWORD8 pb_arg_val = fargv[i] + 7; - WORD8 pb_input_file_name[IA_MAX_CMD_LINE_LENGTH] = ""; - - strcat((char *)pb_input_file_name, - (const char *)pb_input_file_path); - strcat((char *)pb_input_file_name, (const char *)pb_arg_val); - - g_pf_inp = NULL; - g_pf_inp = FileWrapper_Open((char *)pb_input_file_name); - - if (g_pf_inp == NULL) { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "Input File", err_code); - exit(1); - } - file_count++; - raw_testing = 0; - } - - if (!strncmp((const char *)fargv[i], "-imeta:", 7)) { - pWORD8 pb_arg_val = fargv[i] + 7; - WORD8 pb_metadata_file_name[IA_MAX_CMD_LINE_LENGTH] = ""; - - strcat((char *)pb_metadata_file_name, - (const char *)pb_input_file_path); - strcat((char *)pb_metadata_file_name, (const char *)pb_arg_val); - - g_pf_meta = fopen((const char *)pb_metadata_file_name, "r"); - - if (g_pf_meta == NULL) { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "Metadata File", err_code); - exit(1); - } - - err_code = ixheaacd_read_metadata_info(g_pf_meta, &meta_info); - - if (err_code == -1) exit(1); + err_code = ixheaacd_read_metadata_info(g_pf_meta, &meta_info); - raw_testing = 1; - - file_count++; - } - - if (!strncmp((const char *)fargv[i], "-ofile:", 7)) { - pWORD8 pb_arg_val = fargv[i] + 7; - WORD8 pb_output_file_name[IA_MAX_CMD_LINE_LENGTH] = ""; - - strcat((char *)pb_output_file_name, - (const char *)pb_output_file_path); - strcat((char *)pb_output_file_name, (const char *)pb_arg_val); - - g_pf_out = NULL; - g_pf_out = fopen((const char *)pb_output_file_name, "wb"); - if (g_pf_out == NULL) { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "Output File", err_code); - exit(1); - } - file_count++; - } - if (!strncmp((const char *)fargv[i], "-infile:", 8)) { - pWORD8 pb_arg_val = fargv[i] + 8; - WORD8 pb_interface_file_name[IA_MAX_CMD_LINE_LENGTH] = ""; - - strcat((char *)pb_interface_file_name, - (const char *)pb_input_file_path); - strcat((char *)pb_interface_file_name, (const char *)pb_arg_val); - - g_pf_interface = NULL; - g_pf_interface = fopen((const char *)pb_interface_file_name, "rb"); - - if (g_pf_interface == NULL) { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "DRC Interface File", err_code); - exit(1); - } - interface_file_present = 1; - file_count++; - } - } - g_w_malloc_count = 0; - - printf("\n"); - - if (file_count != 4 && file_count != 3 && file_count != 2) { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "Input or Output File", err_code); - } - - if (err_code == IA_NO_ERROR) { - if (g_pf_inp->isMp4File == 1) { - strcpy((pCHAR8)fargv[fargc], "-mp4:1"); - pargv[fargc] = fargv[fargc]; - fargc++; - } - - for (i = 0; i < fargc; i++) { - if (strcmp((pCHAR8)fargv[i], "-eld_testing:1")) - eld_testing = 0; - else { - eld_testing = 1; - break; - } - } - - ixheaacd_main_process(fargc, pargv); - } - - for (i = 0; i < g_w_malloc_count; i++) { - if (g_pv_arr_alloc_memory[i]) free(g_pv_arr_alloc_memory[i]); - } - if (g_pf_out) fclose(g_pf_out); - - if (g_pf_meta) { - raw_testing = 0; - fclose(g_pf_meta); - metadata_mp4_stsz_size_free(&meta_info); - g_pf_meta = NULL; - } - FileWrapper_Close(g_pf_inp); - - if (g_pf_interface) { - fclose(g_pf_interface); - interface_file_present = 0; - } + if (err_code == -1) { + exit(1); } + raw_testing = 1; } - } else { - int i; - int err_code = IA_NO_ERROR; - int file_count = 0; - - for (i = 1; i < argc; i++) { - pargv[i] = fargv[i]; - strcpy((pCHAR8)fargv[i], (pCHAR8)argv[i]); - printf("%s ", pargv[i]); - - if (!strncmp((const char *)pargv[i], "-ifile:", 7)) { - pWORD8 pb_arg_val = pargv[i] + 7; - WORD8 pb_input_file_name[IA_MAX_CMD_LINE_LENGTH] = ""; - - err_code = IA_NO_ERROR; - strcat((char *)pb_input_file_name, (const char *)pb_input_file_path); - strcat((char *)pb_input_file_name, (const char *)pb_arg_val); - - g_pf_inp = NULL; - g_pf_inp = FileWrapper_Open((char *)pb_input_file_name); - if (g_pf_inp == NULL) { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "Input File", err_code); - exit(1); - } - file_count++; - raw_testing = 0; - } - - if (!strncmp((const char *)fargv[i], "-imeta:", 7)) { - pWORD8 pb_arg_val = fargv[i] + 7; - WORD8 pb_metadata_file_name[IA_MAX_CMD_LINE_LENGTH] = ""; - - strcat((char *)pb_metadata_file_name, (const char *)pb_input_file_path); - strcat((char *)pb_metadata_file_name, (const char *)pb_arg_val); - g_pf_meta = NULL; - g_pf_meta = fopen((const char *)pb_metadata_file_name, "r"); - - if (g_pf_meta == NULL) { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "Metadata File", err_code); - exit(1); - } + if (!strncmp((const char *)argv[i], "-ofile:", 7)) { + pWORD8 pb_arg_val = (pWORD8)argv[i] + 7; - err_code = ixheaacd_read_metadata_info(g_pf_meta, &meta_info); - - if (err_code == -1) { - exit(1); - } - - raw_testing = 1; - - file_count++; - } - - if (!strncmp((const char *)pargv[i], "-ofile:", 7)) { - pWORD8 pb_arg_val = pargv[i] + 7; - WORD8 pb_output_file_name[IA_MAX_CMD_LINE_LENGTH] = ""; - - strcat((char *)pb_output_file_name, (const char *)pb_output_file_path); - strcat((char *)pb_output_file_name, (const char *)pb_arg_val); - - g_pf_out = NULL; - g_pf_out = fopen((const char *)pb_output_file_name, "wb"); - if (g_pf_out == NULL) { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "Output File", err_code); - exit(1); - } - file_count++; + g_pf_out = fopen((const char *)pb_arg_val, "wb"); + if (g_pf_out == NULL) { + err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; + ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, + (pWORD8) "Output File", err_code); + exit(1); } + } + } - if (!strncmp((const char *)fargv[i], "-infile:", 8)) { - pWORD8 pb_arg_val = fargv[i] + 8; - WORD8 pb_interface_file_name[IA_MAX_CMD_LINE_LENGTH] = ""; + if ((g_pf_inp == NULL) || (g_pf_out == NULL)) { + print_usage(); + err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; + ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, + (pWORD8) "Input or Output File", err_code); + exit(1); + } - strcat((char *)pb_interface_file_name, - (const char *)pb_input_file_path); - strcat((char *)pb_interface_file_name, (const char *)pb_arg_val); + g_w_malloc_count = 0; - g_pf_interface = NULL; - g_pf_interface = fopen((const char *)pb_interface_file_name, "rb"); + printf("\n"); - if (g_pf_interface == NULL) { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "DRC Interface File", err_code); - exit(1); - } - interface_file_present = 1; - file_count++; + for (i = 0; i < argc; i++) { + if (!strcmp((pCHAR8)argv[i], "-mp4:1")) { + if (g_pf_meta == NULL) { + print_usage(); + err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; + ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, + (pWORD8) "Metadata File", err_code); + exit(1); } } - g_w_malloc_count = 0; - - printf("\n"); + } - if (file_count != 4 && file_count != 3 && file_count != 2) { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "Input or Output File", err_code); + for (i = 0; i < argc; i++) { + if (strcmp((pCHAR8)argv[i], "-eld_testing:1")) + eld_testing = 0; + else { + eld_testing = 1; + break; } + } - if (err_code == IA_NO_ERROR) { - if (g_pf_inp->isMp4File == 1) { - strcpy((pCHAR8)fargv[argc], "-mp4:1"); - pargv[argc] = fargv[argc]; - argc++; - } - - for (i = 0; i < argc; i++) { - if (strcmp((pCHAR8)fargv[i], "-eld_testing:1")) - eld_testing = 0; - else { - eld_testing = 1; - break; - } - } - - ixheaacd_main_process(argc - 1, &pargv[1]); - } + ixheaacd_main_process(argc - 1, (pWORD8 *)(&argv[1])); - for (i = 0; i < g_w_malloc_count; i++) { - if (g_pv_arr_alloc_memory[i]) free(g_pv_arr_alloc_memory[i]); - } - if (g_pf_out) fclose(g_pf_out); + for (i = 0; i < g_w_malloc_count; i++) { + if (g_pv_arr_alloc_memory[i]) free(g_pv_arr_alloc_memory[i]); + } + if (g_pf_out) fclose(g_pf_out); - if (g_pf_meta) { - fclose(g_pf_meta); - metadata_mp4_stsz_size_free(&meta_info); - } - FileWrapper_Close(g_pf_inp); - if (g_pf_interface) { - fclose(g_pf_interface); - interface_file_present = 0; - } + if (g_pf_meta) { + fclose(g_pf_meta); + metadata_mp4_stsz_size_free(&meta_info); } + FileWrapper_Close(g_pf_inp); + mpeg_d_drc_on = 0; return IA_NO_ERROR; } /* end ixheaacd_main */ |