From 182ebcc774fc567198129b255a265d0de708817f Mon Sep 17 00:00:00 2001 From: Saketh Sathuvalli <87962845+SakethSathuvalli@users.noreply.github.com> Date: Wed, 11 Oct 2023 09:58:59 +0530 Subject: [PATCH] Added support for parsing "btrt" box. (#70) * Add support for parsing btrt box [x] Added parsing logic for fields of btrt box [x] Fix to handle streams with DRC data and ASI data - #54 (#71) [x] Also includes fixes related to applying DRC. Testing: [x] Conformance tested. --- decoder/ia_core_coder_decode_main.c | 41 ++++++++++++++++++++--------- decoder/ia_core_coder_struct_def.h | 1 + decoder/impd_drc_static_payload.c | 10 +++---- decoder/impeghd_api.c | 15 ++++++++--- decoder/impeghd_config_params.h | 2 +- decoder/impeghd_mhas_parse.c | 2 +- decoder/impeghd_uni_drc_struct.h | 6 ++--- test/impeghd_main.c | 1 + test/mp4/impeghd_mp4_init.c | 20 +++++++++----- 9 files changed, 62 insertions(+), 36 deletions(-) diff --git a/decoder/ia_core_coder_decode_main.c b/decoder/ia_core_coder_decode_main.c index 0e6c64f..5f6c9d5 100644 --- a/decoder/ia_core_coder_decode_main.c +++ b/decoder/ia_core_coder_decode_main.c @@ -1743,15 +1743,19 @@ IA_ERRORCODE ia_core_coder_dec_process_frame_zero(VOID *temp_handle, WORD32 *num { case ID_EXT_ELE_UNI_DRC: { - pstr_dec_data->str_drc_payload.pstr_drc_config = - &pstr_dec_data->str_frame_data.str_audio_specific_config.str_usac_config.uni_drc_cfg; - err_code = - impeghd_uni_drc_dec_init(pstr_asc, pstr_dec_data, target_loudness, loudness_norm_flag, - drc_effect_type, mpegh_dec_handle->p_config->i_preset_id, - mpegh_dec_handle->p_config->ui_cicp_layout_idx, ele_idx); - if (err_code) + if (handle->mpeghd_config.drc_apply == 1) { - return err_code; + pstr_dec_data->str_drc_payload.pstr_drc_config = + &pstr_asc->str_usac_config.uni_drc_cfg; + err_code = + impeghd_uni_drc_dec_init(pstr_asc, pstr_dec_data, target_loudness, + loudness_norm_flag, drc_effect_type, + mpegh_dec_handle->p_config->i_preset_id, + mpegh_dec_handle->p_config->ui_cicp_layout_idx, ele_idx); + if (err_code) + { + return err_code; + } } } break; @@ -2109,7 +2113,8 @@ IA_ERRORCODE ia_core_coder_dec_ext_ele_proc(VOID *temp_handle, WORD32 *num_chann for (ele = 0; ele < num_elements; ele++) { if ((ID_EXT_ELE_UNI_DRC == pstr_usac_dec_cfg->ia_ext_ele_payload_type[ele]) && - (pstr_usac_dec_cfg->usac_ext_ele_payload_present[ele])) + (pstr_usac_dec_cfg->usac_ext_ele_payload_present[ele]) && + (handle->mpeghd_config.drc_apply == 1)) { // domain switcher UWORD32 dom_swi_flag = pstr_asc->str_usac_config.signals_3d.domain_switcher_enable; @@ -2468,6 +2473,16 @@ IA_ERRORCODE ia_core_coder_dec_main(VOID *temp_handle, WORD8 *inbuffer, WORD8 *o ((handle->mpeghd_config.ui_target_loudness_set) || (pstr_dec_data->str_drc_payload.pstr_drc_config != NULL))) { + WORD32 index = 0; + for (WORD32 i = 0; i < MAX_ELEMENTS_USAC; i++) + { + if (ID_EXT_ELE_UNI_DRC == + pstr_asc->str_usac_config.str_usac_dec_config.ia_ext_ele_payload_type[i]) + { + index = i; + break; + } + } memset(&pstr_dec_data->str_drc_payload.str_select_proc, 0, sizeof(pstr_dec_data->str_drc_payload.str_select_proc)); pstr_dec_data->str_drc_payload.pstr_drc_config = @@ -2475,7 +2490,7 @@ IA_ERRORCODE ia_core_coder_dec_main(VOID *temp_handle, WORD8 *inbuffer, WORD8 *o err_code = impeghd_uni_drc_dec_init(pstr_asc, pstr_dec_data, target_loudness, loudness_norm_flag, drc_effect_type, mpegh_dec_handle->p_config->i_preset_id, - mpegh_dec_handle->p_config->ui_cicp_layout_idx, 0); + mpegh_dec_handle->p_config->ui_cicp_layout_idx, index); if (err_code) { return err_code; @@ -3305,7 +3320,7 @@ IA_ERRORCODE impeghd_uni_drc_dec_init(ia_audio_specific_config_struct *pstr_audi pstr_dec_data->str_drc_payload.str_bitstream_dec.ia_drc_params_struct; err_code = impd_drc_parse_config(pstr_dec_data->str_drc_payload.pstr_drc_config, &pstr_usac_cfg->str_loudness_info, &it_bit_buff, - &pstr_usac_cfg->uni_drc_bs_params, pstr_mae_asi); + &pstr_usac_cfg->uni_drc_bs_params); if (err_code != IA_MPEGH_DEC_NO_ERROR) { return err_code; @@ -3321,7 +3336,7 @@ IA_ERRORCODE impeghd_uni_drc_dec_init(ia_audio_specific_config_struct *pstr_audi pstr_dec_data->str_drc_payload.str_bitstream_dec.ia_drc_params_struct; err_code = impd_drc_parse_config(pstr_dec_data->str_drc_payload.pstr_drc_config, &pstr_usac_cfg->str_loudness_info, &it_bit_buff, - &pstr_usac_cfg->uni_drc_bs_params, pstr_mae_asi); + &pstr_usac_cfg->uni_drc_bs_params); if (err_code != IA_MPEGH_DEC_NO_ERROR) { @@ -3338,7 +3353,7 @@ IA_ERRORCODE impeghd_uni_drc_dec_init(ia_audio_specific_config_struct *pstr_audi it_bit_buff.xmpeghd_jmp_buf = pstr_dec_data->dec_bit_buf.xmpeghd_jmp_buf; err_code = impd_drc_mpegh3da_parse_loudness_info_set(&pstr_drc_payload->str_loud_info, - &it_bit_buff, pstr_mae_asi); + &it_bit_buff); if (err_code != IA_MPEGH_DEC_NO_ERROR) { return err_code; diff --git a/decoder/ia_core_coder_struct_def.h b/decoder/ia_core_coder_struct_def.h index 74a0ba0..71aad0b 100644 --- a/decoder/ia_core_coder_struct_def.h +++ b/decoder/ia_core_coder_struct_def.h @@ -75,6 +75,7 @@ typedef struct WORD32 ui_effect_type; WORD32 ui_target_loudness; WORD32 ui_target_loudness_set; + WORD32 drc_apply; WORD32 ui_loud_norm_flag; WORD32 ui_cicp_layout_idx; UWORD32 header_dec_done; diff --git a/decoder/impd_drc_static_payload.c b/decoder/impd_drc_static_payload.c index 66e514f..c5cbce5 100644 --- a/decoder/impd_drc_static_payload.c +++ b/decoder/impd_drc_static_payload.c @@ -477,8 +477,7 @@ impd_drc_parse_loudness_info_set_ext(ia_drc_loudness_info_set_struct *pstr_loudn */ IA_ERRORCODE impd_drc_mpegh3da_parse_loudness_info_set(ia_drc_loudness_info_set_struct *pstr_loudness_info_set, - ia_bit_buf_struct *pstr_it_bit_buff, - ia_mae_audio_scene_info *pstr_mae_asi) + ia_bit_buf_struct *pstr_it_bit_buff) { IA_ERRORCODE err_code = IA_MPEGH_DEC_NO_ERROR; WORD32 cnt; @@ -1548,8 +1547,7 @@ IA_ERRORCODE impd_drc_parse_config(ia_drc_config *pstr_drc_config, ia_drc_loudness_info_set_struct *pstr_loudness_info_set, ia_bit_buf_struct *pstr_it_bit_buff, - ia_drc_params_bs_dec_struct *pstr_ia_drc_params, - ia_mae_audio_scene_info *pstr_mae_asi) + ia_drc_params_bs_dec_struct *pstr_ia_drc_params) { IA_ERRORCODE err_code = IA_MPEGH_DEC_NO_ERROR; WORD32 cnt, version = 0; @@ -1634,8 +1632,8 @@ impd_drc_parse_config(ia_drc_config *pstr_drc_config, if (1 == pstr_drc_config->loudness_infoset_present) { - err_code = impd_drc_mpegh3da_parse_loudness_info_set(pstr_loudness_info_set, pstr_it_bit_buff, - pstr_mae_asi); + err_code = impd_drc_mpegh3da_parse_loudness_info_set(pstr_loudness_info_set, + pstr_it_bit_buff); if (err_code) return (err_code); } diff --git a/decoder/impeghd_api.c b/decoder/impeghd_api.c index 30dd08f..a0d7b86 100644 --- a/decoder/impeghd_api.c +++ b/decoder/impeghd_api.c @@ -222,6 +222,7 @@ static VOID impeghd_set_default_config(ia_mpegh_dec_api_struct *p_obj_mpegh_dec) p_obj_mpegh_dec->mpeghd_config.ui_pcm_wdsz = IMPEGHD_CONFIG_PARAM_PCM_WD_SZ_DFLT_VAL; p_obj_mpegh_dec->mpeghd_config.ui_effect_type = IMPEGHD_CONFIG_PARAM_EFFECT_TYPE_DFLT_VAL; p_obj_mpegh_dec->mpeghd_config.ui_target_loudness = IMPEGHD_CONFIG_PARAM_TGT_LOUDNESS_DFLT_VAL; + p_obj_mpegh_dec->mpeghd_config.drc_apply = 0; p_obj_mpegh_dec->mpeghd_config.ui_loud_norm_flag = IMPEGHD_CONFIG_PARAM_LOUD_NORM_FLG_DFLT_VAL; p_obj_mpegh_dec->mpeghd_config.ui_cicp_layout_idx = IMPEGHD_CONFIG_PARAM_CICP_IDX_DFLT_VAL; p_obj_mpegh_dec->mpeghd_config.i_preset_id = IMPEGHD_CONFIG_PARAM_PRESET_ID_DFLT_VAL; @@ -289,24 +290,30 @@ static IA_ERRORCODE impeghd_set_config_params(ia_mpegh_dec_api_struct *p_obj_mpe p_obj_mpegh_dec->mpeghd_config.resample_output = 1; p_obj_mpegh_dec->mpeghd_config.out_samp_freq = ptr_input_config->out_samp_freq; } - if ((ptr_input_config->ui_effect > 8) || (ptr_input_config->ui_effect < 0)) + if (ptr_input_config->ui_effect != IMPEGHD_CONFIG_PARAM_EFFECT_TYPE_DFLT_VAL) { - p_obj_mpegh_dec->mpeghd_config.ui_effect_type = 0; - return (IA_MPEGH_DEC_CONFIG_NONFATAL_INVALID_EFFECT_TYPE); + if ((ptr_input_config->ui_effect > 8) || (ptr_input_config->ui_effect < 0)) + { + p_obj_mpegh_dec->mpeghd_config.ui_effect_type = 0; + p_obj_mpegh_dec->mpeghd_config.drc_apply = 1; + return (IA_MPEGH_DEC_CONFIG_NONFATAL_INVALID_EFFECT_TYPE); + } + p_obj_mpegh_dec->mpeghd_config.ui_effect_type = ptr_input_config->ui_effect; } - p_obj_mpegh_dec->mpeghd_config.ui_effect_type = ptr_input_config->ui_effect; if (ptr_input_config->ui_target_loudness[0] == 1) { if (ptr_input_config->ui_target_loudness[1] >= 0) { p_obj_mpegh_dec->mpeghd_config.ui_loud_norm_flag = 1; + p_obj_mpegh_dec->mpeghd_config.drc_apply = 1; } ptr_input_config->ui_target_loudness[1] = -(ptr_input_config->ui_target_loudness[1] >> 2); if (((ptr_input_config->ui_target_loudness[1]) > 0) || ((ptr_input_config->ui_target_loudness[1]) < -63)) { p_obj_mpegh_dec->mpeghd_config.ui_target_loudness = 0; + p_obj_mpegh_dec->mpeghd_config.drc_apply = 0; return (IA_MPEGH_DEC_CONFIG_NONFATAL_INVALID_TARGET_LOUDNESS); } p_obj_mpegh_dec->mpeghd_config.ui_target_loudness = ptr_input_config->ui_target_loudness[1]; diff --git a/decoder/impeghd_config_params.h b/decoder/impeghd_config_params.h index 2d253fa..7df5caa 100644 --- a/decoder/impeghd_config_params.h +++ b/decoder/impeghd_config_params.h @@ -39,7 +39,7 @@ #define IMPEGHD_CONFIG_PARAM_PCM_WD_SZ_DFLT_VAL (16) #define IMPEGHD_CONFIG_PARAM_MAX_CHANS_DFLT_VAL (24) #define IMPEGHD_CONFIG_PARAM_MHAS_FLAG_DFLT_VAL (1) -#define IMPEGHD_CONFIG_PARAM_EFFECT_TYPE_DFLT_VAL (-1) +#define IMPEGHD_CONFIG_PARAM_EFFECT_TYPE_DFLT_VAL (0) #define IMPEGHD_CONFIG_PARAM_CICP_IDX_DFLT_VAL (0) #define IMPEGHD_CONFIG_PARAM_TGT_LOUDNESS_DFLT_VAL (-24) #define IMPEGHD_CONFIG_PARAM_LOUD_NORM_FLG_DFLT_VAL (0) diff --git a/decoder/impeghd_mhas_parse.c b/decoder/impeghd_mhas_parse.c index 9abc89d..ea09fb6 100644 --- a/decoder/impeghd_mhas_parse.c +++ b/decoder/impeghd_mhas_parse.c @@ -1364,7 +1364,7 @@ IA_ERRORCODE impeghd_mhas_parse(ia_mhas_pac_info *pstr_pac_info, { ia_drc_payload_struct str_drc_payload; err_code = impd_drc_mpegh3da_parse_loudness_info_set(&str_drc_payload.str_loud_info, - pstr_bit_buf, pstr_mae_asi); + pstr_bit_buf); } break; default: diff --git a/decoder/impeghd_uni_drc_struct.h b/decoder/impeghd_uni_drc_struct.h index a8761c4..fbe1fa2 100644 --- a/decoder/impeghd_uni_drc_struct.h +++ b/decoder/impeghd_uni_drc_struct.h @@ -63,11 +63,9 @@ IA_ERRORCODE impd_drc_read_uni_drc_gain(ia_drc_gain_struct *pstr_uni_drc_gain, ia_drc_bits_dec_struct *pstr_drc_uni_bs_dec); IA_ERRORCODE impd_drc_parse_config(ia_drc_config *, ia_drc_loudness_info_set_struct *, - ia_bit_buf_struct *, ia_drc_params_bs_dec_struct *, - ia_mae_audio_scene_info *); + ia_bit_buf_struct *, ia_drc_params_bs_dec_struct *); IA_ERRORCODE impd_drc_mpegh3da_parse_loudness_info_set(ia_drc_loudness_info_set_struct *, - ia_bit_buf_struct *, - ia_mae_audio_scene_info *); + ia_bit_buf_struct *); #endif /* IMPEGHD_UNI_DRC_STRUCT_H */ diff --git a/test/impeghd_main.c b/test/impeghd_main.c index 1fcffc4..b568cc0 100644 --- a/test/impeghd_main.c +++ b/test/impeghd_main.c @@ -515,6 +515,7 @@ IA_ERRORCODE impeghd_main_process(WORD32 argc, pWORD8 argv[]) str_dec_api.input_config.ui_mhas_flag = IMPEGHD_CONFIG_PARAM_MHAS_FLAG_DFLT_VAL; str_dec_api.input_config.ui_pcm_wd_sz = IMPEGHD_CONFIG_PARAM_PCM_WD_SZ_DFLT_VAL; str_dec_api.input_config.ui_cicp_layout_idx = IMPEGHD_CONFIG_PARAM_CICP_IDX_DFLT_VAL; + str_dec_api.input_config.ui_effect = IMPEGHD_CONFIG_PARAM_EFFECT_TYPE_DFLT_VAL; str_dec_api.input_config.i_preset_id = IMPEGHD_CONFIG_PARAM_PRESET_ID_DFLT_VAL; str_dec_api.input_config.ei_info_flag = IMPEGHD_CONFIG_PARAM_EI_FLAG_DFLT_VAL; str_dec_api.input_config.lsi_info_flag = IMPEGHD_CONFIG_PARAM_EI_FLAG_DFLT_VAL; diff --git a/test/mp4/impeghd_mp4_init.c b/test/mp4/impeghd_mp4_init.c index 50c008c..0473ba4 100644 --- a/test/mp4/impeghd_mp4_init.c +++ b/test/mp4/impeghd_mp4_init.c @@ -2961,19 +2961,26 @@ WORD32 impeghd_mp4_read_samples(pVOID fp, ia_mp4_sample_entry **n, ia_mp4_mem_no // BTRT Changes if ((*n)->es.type == IT_BTRT) { - impeghd_mp4_fseek(fp, (*n)->es.size - 8, SEEK_CUR); - ret = impeghd_mp4_fread(charbuf, 1, 4, fp); + //bufferSizeDB + impeghd_mp4_fread(charbuf, 1, 4, fp); if (ret < 4) { return IT_ERROR; } - (*n)->es.size = impeghd_mp4_rev32(*data_size); - ret = impeghd_mp4_fread(charbuf, 1, 4, fp); + //maxBitrate + impeghd_mp4_fread(charbuf, 1, 4, fp); + if (ret < 4) + { + return IT_ERROR; + } + // avgBitrate + impeghd_mp4_fread(charbuf, 1, 4, fp); if (ret < 4) { return IT_ERROR; } - (*n)->es.type = impeghd_mp4_rev32(*data_size); + if (tag_mhm1) + return IT_OK; } len -= 8; @@ -2997,7 +3004,6 @@ WORD32 impeghd_mp4_read_samples(pVOID fp, ia_mp4_sample_entry **n, ia_mp4_mem_no { if ((*n)->es.type == IT_BTRT) { - impeghd_mp4_fseek(fp, (*n)->es.size - 8, SEEK_CUR); if (tag_mhaC == 0) goto search_mhaC; return IT_OK; @@ -3452,7 +3458,7 @@ WORD32 impeghd_mp4_get_es(pVOID fp, ia_mp4_es_desc **n, ia_mp4_mem_node **m, tra (*n)->ipmp_desc_ptr = ptr2; ptr2->next = NULL; - while ((*n)->length - count) + while ((*n)->length > count) { switch (tag) {