Skip to content

Commit

Permalink
Added support for parsing "btrt" box. (#70)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
SakethSathuvalli authored Oct 11, 2023
1 parent cebf3df commit 182ebcc
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 36 deletions.
41 changes: 28 additions & 13 deletions decoder/ia_core_coder_decode_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2468,14 +2473,24 @@ 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 =
&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, 0);
mpegh_dec_handle->p_config->ui_cicp_layout_idx, index);
if (err_code)
{
return err_code;
Expand Down Expand Up @@ -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;
Expand All @@ -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)
{
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions decoder/ia_core_coder_struct_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 4 additions & 6 deletions decoder/impd_drc_static_payload.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
15 changes: 11 additions & 4 deletions decoder/impeghd_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion decoder/impeghd_config_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion decoder/impeghd_mhas_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 2 additions & 4 deletions decoder/impeghd_uni_drc_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
1 change: 1 addition & 0 deletions test/impeghd_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 13 additions & 7 deletions test/mp4/impeghd_mp4_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 182ebcc

Please sign in to comment.