@ -239,13 +239,17 @@ int ff_iamf_add_audio_element(IAMFContext *iamf, const AVStreamGroup *stg, void
audio_element - > codec_config_id = ret ;
audio_element - > codec_config_id = ret ;
audio_element - > substreams = av_calloc ( stg - > nb_streams , sizeof ( * audio_element - > substreams ) ) ;
audio_element - > substreams = av_calloc ( stg - > nb_streams , sizeof ( * audio_element - > substreams ) ) ;
if ( ! audio_element - > substreams )
if ( ! audio_element - > substreams ) {
return AVERROR ( ENOMEM ) ;
ret = AVERROR ( ENOMEM ) ;
goto fail ;
}
audio_element - > nb_substreams = stg - > nb_streams ;
audio_element - > nb_substreams = stg - > nb_streams ;
audio_element - > layers = av_calloc ( iamf_audio_element - > nb_layers , sizeof ( * audio_element - > layers ) ) ;
audio_element - > layers = av_calloc ( iamf_audio_element - > nb_layers , sizeof ( * audio_element - > layers ) ) ;
if ( ! audio_element - > layers )
if ( ! audio_element - > layers ) {
return AVERROR ( ENOMEM ) ;
ret = AVERROR ( ENOMEM ) ;
goto fail ;
}
for ( int i = 0 , j = 0 ; i < iamf_audio_element - > nb_layers ; i + + ) {
for ( int i = 0 , j = 0 ; i < iamf_audio_element - > nb_layers ; i + + ) {
int nb_channels = iamf_audio_element - > layers [ i ] - > ch_layout . nb_channels ;
int nb_channels = iamf_audio_element - > layers [ i ] - > ch_layout . nb_channels ;
@ -266,7 +270,8 @@ int ff_iamf_add_audio_element(IAMFContext *iamf, const AVStreamGroup *stg, void
if ( nb_channels ) {
if ( nb_channels ) {
av_log ( log_ctx , AV_LOG_ERROR , " Invalid channel count across substreams in layer %u from stream group %u \n " ,
av_log ( log_ctx , AV_LOG_ERROR , " Invalid channel count across substreams in layer %u from stream group %u \n " ,
i , stg - > index ) ;
i , stg - > index ) ;
return AVERROR ( EINVAL ) ;
ret = AVERROR ( EINVAL ) ;
goto fail ;
}
}
}
}
@ -276,13 +281,14 @@ int ff_iamf_add_audio_element(IAMFContext *iamf, const AVStreamGroup *stg, void
if ( param - > nb_subblocks ! = 1 ) {
if ( param - > nb_subblocks ! = 1 ) {
av_log ( log_ctx , AV_LOG_ERROR , " nb_subblocks in demixing_info for stream group %u is not 1 \n " , stg - > index ) ;
av_log ( log_ctx , AV_LOG_ERROR , " nb_subblocks in demixing_info for stream group %u is not 1 \n " , stg - > index ) ;
return AVERROR ( EINVAL ) ;
ret = AVERROR ( EINVAL ) ;
goto fail ;
}
}
if ( ! param_definition ) {
if ( ! param_definition ) {
ret = add_param_definition ( iamf , param , audio_element , log_ctx ) ;
ret = add_param_definition ( iamf , param , audio_element , log_ctx ) ;
if ( ret < 0 )
if ( ret < 0 )
return ret ;
goto fail ;
}
}
}
}
if ( iamf_audio_element - > recon_gain_info ) {
if ( iamf_audio_element - > recon_gain_info ) {
@ -291,24 +297,30 @@ int ff_iamf_add_audio_element(IAMFContext *iamf, const AVStreamGroup *stg, void
if ( param - > nb_subblocks ! = 1 ) {
if ( param - > nb_subblocks ! = 1 ) {
av_log ( log_ctx , AV_LOG_ERROR , " nb_subblocks in recon_gain_info for stream group %u is not 1 \n " , stg - > index ) ;
av_log ( log_ctx , AV_LOG_ERROR , " nb_subblocks in recon_gain_info for stream group %u is not 1 \n " , stg - > index ) ;
return AVERROR ( EINVAL ) ;
ret = AVERROR ( EINVAL ) ;
goto fail ;
}
}
if ( ! param_definition ) {
if ( ! param_definition ) {
ret = add_param_definition ( iamf , param , audio_element , log_ctx ) ;
ret = add_param_definition ( iamf , param , audio_element , log_ctx ) ;
if ( ret < 0 )
if ( ret < 0 )
return ret ;
goto fail ;
}
}
}
}
tmp = av_realloc_array ( iamf - > audio_elements , iamf - > nb_audio_elements + 1 , sizeof ( * iamf - > audio_elements ) ) ;
tmp = av_realloc_array ( iamf - > audio_elements , iamf - > nb_audio_elements + 1 , sizeof ( * iamf - > audio_elements ) ) ;
if ( ! tmp )
if ( ! tmp ) {
return AVERROR ( ENOMEM ) ;
ret = AVERROR ( ENOMEM ) ;
goto fail ;
}
iamf - > audio_elements = tmp ;
iamf - > audio_elements = tmp ;
iamf - > audio_elements [ iamf - > nb_audio_elements + + ] = audio_element ;
iamf - > audio_elements [ iamf - > nb_audio_elements + + ] = audio_element ;
return 0 ;
return 0 ;
fail :
ff_iamf_free_audio_element ( & audio_element ) ;
return ret ;
}
}
int ff_iamf_add_mix_presentation ( IAMFContext * iamf , const AVStreamGroup * stg , void * log_ctx )
int ff_iamf_add_mix_presentation ( IAMFContext * iamf , const AVStreamGroup * stg , void * log_ctx )
@ -341,14 +353,15 @@ int ff_iamf_add_mix_presentation(IAMFContext *iamf, const AVStreamGroup *stg, vo
if ( ! param ) {
if ( ! param ) {
av_log ( log_ctx , AV_LOG_ERROR , " output_mix_config is not present in submix %u from "
av_log ( log_ctx , AV_LOG_ERROR , " output_mix_config is not present in submix %u from "
" Mix Presentation ID % " PRId64 " \n " , i , stg - > id ) ;
" Mix Presentation ID % " PRId64 " \n " , i , stg - > id ) ;
return AVERROR ( EINVAL ) ;
ret = AVERROR ( EINVAL ) ;
goto fail ;
}
}
param_definition = ff_iamf_get_param_definition ( iamf , param - > parameter_id ) ;
param_definition = ff_iamf_get_param_definition ( iamf , param - > parameter_id ) ;
if ( ! param_definition ) {
if ( ! param_definition ) {
ret = add_param_definition ( iamf , param , NULL , log_ctx ) ;
ret = add_param_definition ( iamf , param , NULL , log_ctx ) ;
if ( ret < 0 )
if ( ret < 0 )
return ret ;
goto fail ;
}
}
for ( int j = 0 ; j < submix - > nb_elements ; j + + ) {
for ( int j = 0 ; j < submix - > nb_elements ; j + + ) {
@ -358,25 +371,31 @@ int ff_iamf_add_mix_presentation(IAMFContext *iamf, const AVStreamGroup *stg, vo
if ( ! param ) {
if ( ! param ) {
av_log ( log_ctx , AV_LOG_ERROR , " element_mix_config is not present for element %u in submix %u from "
av_log ( log_ctx , AV_LOG_ERROR , " element_mix_config is not present for element %u in submix %u from "
" Mix Presentation ID % " PRId64 " \n " , j , i , stg - > id ) ;
" Mix Presentation ID % " PRId64 " \n " , j , i , stg - > id ) ;
return AVERROR ( EINVAL ) ;
ret = AVERROR ( EINVAL ) ;
goto fail ;
}
}
param_definition = ff_iamf_get_param_definition ( iamf , param - > parameter_id ) ;
param_definition = ff_iamf_get_param_definition ( iamf , param - > parameter_id ) ;
if ( ! param_definition ) {
if ( ! param_definition ) {
ret = add_param_definition ( iamf , param , NULL , log_ctx ) ;
ret = add_param_definition ( iamf , param , NULL , log_ctx ) ;
if ( ret < 0 )
if ( ret < 0 )
return ret ;
goto fail ;
}
}
}
}
}
}
tmp = av_realloc_array ( iamf - > mix_presentations , iamf - > nb_mix_presentations + 1 , sizeof ( * iamf - > mix_presentations ) ) ;
tmp = av_realloc_array ( iamf - > mix_presentations , iamf - > nb_mix_presentations + 1 , sizeof ( * iamf - > mix_presentations ) ) ;
if ( ! tmp )
if ( ! tmp ) {
return AVERROR ( ENOMEM ) ;
ret = AVERROR ( ENOMEM ) ;
goto fail ;
}
iamf - > mix_presentations = tmp ;
iamf - > mix_presentations = tmp ;
iamf - > mix_presentations [ iamf - > nb_mix_presentations + + ] = mix_presentation ;
iamf - > mix_presentations [ iamf - > nb_mix_presentations + + ] = mix_presentation ;
return 0 ;
return 0 ;
fail :
ff_iamf_free_mix_presentation ( & mix_presentation ) ;
return ret ;
}
}
static int iamf_write_codec_config ( const IAMFContext * iamf ,
static int iamf_write_codec_config ( const IAMFContext * iamf ,