From 7d1ed0ffe65bc665d266a88389c401eafe6785a1 Mon Sep 17 00:00:00 2001 From: Stefan Bayer Date: Mon, 2 Oct 2023 13:43:26 +0200 Subject: [PATCH 1/4] fix #834, #839, make sure that the number of channels allocated on the heap stays correct in case of rate switching --- lib_com/options.h | 2 +- lib_dec/ivas_init_dec.c | 6 ++++++ lib_dec/ivas_ism_dec.c | 8 +++++++- lib_dec/ivas_mct_dec.c | 39 ++++++++++++++++++++++++++++++++++++++- lib_dec/ivas_omasa_dec.c | 8 +++++++- lib_dec/ivas_sba_dec.c | 8 +++++++- lib_dec/ivas_stat_dec.h | 3 +++ 7 files changed, 69 insertions(+), 5 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 3ccf81b46b..ee2abe49f8 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -189,7 +189,7 @@ #define NONBE_FIX_730_DPID_NOT_SET_CORRECTLY /* Eri: issue 730: write dpid read from file in correct index, print informative error message when DPID specified is not found. */ #define NONBE_FIX_825_SBA_JBM_MONO_STEREO_OUTPUT /* FhG: issue #825: Resolve "JBM SBA: AGC and PCA run twice for MONO and STEREO output" */ #define NONBE_FIX_808_JBM_PARAMUPMIX_RS /* FhG: Issue 808: fix JBM MC rate switching */ - +#define NONBE_FIX_834_839_HEAP_CHANNEL_COUNT /* FhG: Issues #834, #839: problems with reallocation of the channels on the heap */ /* ##################### End NON-BE switches ########################### */ /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 82ae35936f..0cda451f60 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -2247,6 +2247,9 @@ ivas_error ivas_init_decoder( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point output audio buffer!\n" ) ); } } +#ifdef NONBE_FIX_834_839_HEAP_CHANNEL_COUNT + st_ivas->n_output_buffer_channels = n; +#endif } else { @@ -2511,6 +2514,9 @@ void ivas_initialize_handles_dec( { st_ivas->p_output_f[i] = NULL; } +#ifdef NONBE_FIX_834_839_HEAP_CHANNEL_COUNT + st_ivas->n_output_buffer_channels = 0; +#endif return; } diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index 39c7c667d9..0b381b5201 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -81,7 +81,11 @@ static ivas_error ivas_ism_bitrate_switching_dec( st_ivas->ism_mode = last_ism_mode; ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); st_ivas->ism_mode = ism_mode; +#ifdef NONBE_FIX_834_839_HEAP_CHANNEL_COUNT + nchan_out_buff_old = st_ivas->n_output_buffer_channels; +#else nchan_out_buff_old = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); +#endif if ( ( error = ivas_ism_config( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->nchan_ism, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ) != IVAS_ERR_OK ) { @@ -332,7 +336,9 @@ static ivas_error ivas_ism_bitrate_switching_dec( if ( !st_ivas->hDecoderConfig->Opt_5ms ) { nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); - +#ifdef NONBE_FIX_834_839_HEAP_CHANNEL_COUNT + st_ivas->n_output_buffer_channels = nchan_out_buff; +#endif if ( nchan_out_buff > nchan_out_buff_old ) { for ( ch = nchan_out_buff_old; ch < nchan_out_buff; ch++ ) diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 1fb4db5eb8..de0fbd6179 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -739,11 +739,16 @@ static ivas_error ivas_mc_dec_reconfig( int16_t tc_granularity_new; AUDIO_CONFIG intern_config_old; IVAS_OUTPUT_SETUP hIntSetupOld; - +#ifdef NONBE_FIX_834_839_HEAP_CHANNEL_COUNT + int16_t nchan_out_buf_old; +#endif error = IVAS_ERR_OK; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; nchan_transport_old = st_ivas->nchan_transport; +#ifdef NONBE_FIX_834_839_HEAP_CHANNEL_COUNT + nchan_out_buf_old = st_ivas->n_output_buffer_channels; +#endif last_mc_mode = ivas_mc_mode_select( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ), st_ivas->hDecoderConfig->last_ivas_total_brate ); /* NB: this assumes that LS config remains the same between frames */ @@ -1390,5 +1395,37 @@ static ivas_error ivas_mc_dec_reconfig( } } + /*-----------------------------------------------------------------* + * floating-point output audio buffers + *-----------------------------------------------------------------*/ +#ifdef NONBE_FIX_834_839_HEAP_CHANNEL_COUNT + if ( !st_ivas->hDecoderConfig->Opt_5ms ) + { + int16_t nchan_out_buff, ch; + nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + + st_ivas->n_output_buffer_channels = nchan_out_buff; + if ( nchan_out_buff > nchan_out_buf_old ) + { + for ( ch = nchan_out_buf_old; ch < nchan_out_buff; ch++ ) + { + /* note: these are intra-frame heap memories */ + if ( ( st_ivas->p_output_f[ch] = (float *) malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( float ) ) ) == NULL ) /* note: 32000 == max internal sampling rate */ + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point output audio buffer!\n" ) ); + } + } + } + else + { + for ( ch = nchan_out_buff; ch < nchan_out_buf_old; ch++ ) + { + free( st_ivas->p_output_f[ch] ); + st_ivas->p_output_f[ch] = NULL; + } + } + } +#endif + return error; } diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index b6846dfe93..6d74e4972c 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -180,7 +180,11 @@ ivas_error ivas_omasa_dec_config( ivas_format_orig = st_ivas->ivas_format; st_ivas->ivas_format = st_ivas->last_ivas_format; ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); +#ifdef NONBE_FIX_834_839_HEAP_CHANNEL_COUNT + nchan_out_buff_old = st_ivas->n_output_buffer_channels; +#else nchan_out_buff_old = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); +#endif st_ivas->ivas_format = ivas_format_orig; @@ -415,7 +419,9 @@ ivas_error ivas_omasa_dec_config( if ( !st_ivas->hDecoderConfig->Opt_5ms ) { nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); - +#ifdef NONBE_FIX_834_839_HEAP_CHANNEL_COUNT + st_ivas->n_output_buffer_channels = nchan_out_buff; +#endif if ( nchan_out_buff > nchan_out_buff_old ) { for ( k = nchan_out_buff_old; k < nchan_out_buff; k++ ) diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 7b2b73977d..4d7c6791c0 100755 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -148,7 +148,11 @@ ivas_error ivas_sba_dec_reconfigure( * Set SBA high-level parameters * Save old SBA high-level parameters *-----------------------------------------------------------------*/ +#ifdef NONBE_FIX_834_839_HEAP_CHANNEL_COUNT + nchan_out_buff_old = st_ivas->n_output_buffer_channels; +#else nchan_out_buff_old = ivas_get_nchan_buffers_dec( st_ivas, sba_analysis_order_old, last_ivas_total_brate ); +#endif ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); nchan_hp20_old = getNumChanSynthesis( st_ivas ); @@ -738,7 +742,9 @@ ivas_error ivas_sba_dec_reconfigure( if ( !st_ivas->hDecoderConfig->Opt_5ms ) { nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); - +#ifdef NONBE_FIX_834_839_HEAP_CHANNEL_COUNT + st_ivas->n_output_buffer_channels = nchan_out_buff; +#endif if ( nchan_out_buff > nchan_out_buff_old ) { for ( ch = nchan_out_buff_old; ch < nchan_out_buff; ch++ ) diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index ceab947f3f..ba7d2bdae9 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1065,6 +1065,9 @@ typedef struct Decoder_Struct IVAS_LIMITER_HANDLE hLimiter; /* Limiter handle */ float *p_output_f[MAX_OUTPUT_CHANNELS+MAX_NUM_OBJECTS]; /* floating-point output audio buffers */ +#ifdef NONBE_FIX_834_839_HEAP_CHANNEL_COUNT + int16_t n_output_buffer_channels; +#endif /* core-decoder modules */ int16_t nSCE; /* number of total SCEs */ -- GitLab From 43e9f83b54d9f2689af86d346ac09c74c29d8406 Mon Sep 17 00:00:00 2001 From: Stefan Bayer Date: Mon, 2 Oct 2023 13:53:17 +0200 Subject: [PATCH 2/4] fix linux compiler warning --- lib_dec/ivas_sba_dec.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 4d7c6791c0..4e43585b08 100755 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -122,7 +122,9 @@ ivas_error ivas_sba_dec_reconfigure( int32_t last_ivas_total_brate; int16_t num_channels, num_md_sub_frames; int16_t ch, nchan_out_buff, nchan_out_buff_old; +#ifndef NONBE_FIX_834_839_HEAP_CHANNEL_COUNT int16_t sba_analysis_order_old; +#endif #ifdef JBM_FOR_OSBA int16_t sba_analysis_order_old_flush; #endif @@ -142,7 +144,9 @@ ivas_error ivas_sba_dec_reconfigure( #ifdef JBM_FOR_OSBA sba_analysis_order_old_flush = st_ivas->sba_analysis_order; #endif +#ifndef NONBE_FIX_834_839_HEAP_CHANNEL_COUNT sba_analysis_order_old = ivas_sba_get_analysis_order( last_ivas_total_brate, st_ivas->sba_order ); +#endif /*-----------------------------------------------------------------* * Set SBA high-level parameters -- GitLab From cad82d5ae2a9a0c7c3ecb26e08459198575c9505 Mon Sep 17 00:00:00 2001 From: Stefan Bayer Date: Mon, 9 Oct 2023 08:51:16 +0200 Subject: [PATCH 3/4] reduce to fix only the missing channel realloc in MC RS --- lib_com/options.h | 2 +- lib_dec/ivas_init_dec.c | 6 ------ lib_dec/ivas_ism_dec.c | 8 +------- lib_dec/ivas_mct_dec.c | 9 ++++----- lib_dec/ivas_omasa_dec.c | 8 +------- lib_dec/ivas_sba_dec.c | 12 +----------- lib_dec/ivas_stat_dec.h | 3 --- 7 files changed, 8 insertions(+), 40 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index ee2abe49f8..42afcda2de 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -189,7 +189,7 @@ #define NONBE_FIX_730_DPID_NOT_SET_CORRECTLY /* Eri: issue 730: write dpid read from file in correct index, print informative error message when DPID specified is not found. */ #define NONBE_FIX_825_SBA_JBM_MONO_STEREO_OUTPUT /* FhG: issue #825: Resolve "JBM SBA: AGC and PCA run twice for MONO and STEREO output" */ #define NONBE_FIX_808_JBM_PARAMUPMIX_RS /* FhG: Issue 808: fix JBM MC rate switching */ -#define NONBE_FIX_834_839_HEAP_CHANNEL_COUNT /* FhG: Issues #834, #839: problems with reallocation of the channels on the heap */ +#define NONBE_FIX_839_MC_RS_CHANNEL_ALLOC /* FhG: Issues #839: problems with reallocation of the channels on the heap in case of MC RS */ /* ##################### End NON-BE switches ########################### */ /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 0cda451f60..82ae35936f 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -2247,9 +2247,6 @@ ivas_error ivas_init_decoder( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point output audio buffer!\n" ) ); } } -#ifdef NONBE_FIX_834_839_HEAP_CHANNEL_COUNT - st_ivas->n_output_buffer_channels = n; -#endif } else { @@ -2514,9 +2511,6 @@ void ivas_initialize_handles_dec( { st_ivas->p_output_f[i] = NULL; } -#ifdef NONBE_FIX_834_839_HEAP_CHANNEL_COUNT - st_ivas->n_output_buffer_channels = 0; -#endif return; } diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index 0b381b5201..39c7c667d9 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -81,11 +81,7 @@ static ivas_error ivas_ism_bitrate_switching_dec( st_ivas->ism_mode = last_ism_mode; ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); st_ivas->ism_mode = ism_mode; -#ifdef NONBE_FIX_834_839_HEAP_CHANNEL_COUNT - nchan_out_buff_old = st_ivas->n_output_buffer_channels; -#else nchan_out_buff_old = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); -#endif if ( ( error = ivas_ism_config( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->nchan_ism, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ) != IVAS_ERR_OK ) { @@ -336,9 +332,7 @@ static ivas_error ivas_ism_bitrate_switching_dec( if ( !st_ivas->hDecoderConfig->Opt_5ms ) { nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); -#ifdef NONBE_FIX_834_839_HEAP_CHANNEL_COUNT - st_ivas->n_output_buffer_channels = nchan_out_buff; -#endif + if ( nchan_out_buff > nchan_out_buff_old ) { for ( ch = nchan_out_buff_old; ch < nchan_out_buff; ch++ ) diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index de0fbd6179..0871421bcd 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -739,15 +739,15 @@ static ivas_error ivas_mc_dec_reconfig( int16_t tc_granularity_new; AUDIO_CONFIG intern_config_old; IVAS_OUTPUT_SETUP hIntSetupOld; -#ifdef NONBE_FIX_834_839_HEAP_CHANNEL_COUNT +#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC int16_t nchan_out_buf_old; #endif error = IVAS_ERR_OK; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; nchan_transport_old = st_ivas->nchan_transport; -#ifdef NONBE_FIX_834_839_HEAP_CHANNEL_COUNT - nchan_out_buf_old = st_ivas->n_output_buffer_channels; +#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC + nchan_out_buf_old = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); #endif last_mc_mode = ivas_mc_mode_select( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ), st_ivas->hDecoderConfig->last_ivas_total_brate ); /* NB: this assumes that LS config remains the same between frames */ @@ -1398,13 +1398,12 @@ static ivas_error ivas_mc_dec_reconfig( /*-----------------------------------------------------------------* * floating-point output audio buffers *-----------------------------------------------------------------*/ -#ifdef NONBE_FIX_834_839_HEAP_CHANNEL_COUNT +#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC if ( !st_ivas->hDecoderConfig->Opt_5ms ) { int16_t nchan_out_buff, ch; nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); - st_ivas->n_output_buffer_channels = nchan_out_buff; if ( nchan_out_buff > nchan_out_buf_old ) { for ( ch = nchan_out_buf_old; ch < nchan_out_buff; ch++ ) diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 6d74e4972c..b6846dfe93 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -180,11 +180,7 @@ ivas_error ivas_omasa_dec_config( ivas_format_orig = st_ivas->ivas_format; st_ivas->ivas_format = st_ivas->last_ivas_format; ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); -#ifdef NONBE_FIX_834_839_HEAP_CHANNEL_COUNT - nchan_out_buff_old = st_ivas->n_output_buffer_channels; -#else nchan_out_buff_old = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); -#endif st_ivas->ivas_format = ivas_format_orig; @@ -419,9 +415,7 @@ ivas_error ivas_omasa_dec_config( if ( !st_ivas->hDecoderConfig->Opt_5ms ) { nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); -#ifdef NONBE_FIX_834_839_HEAP_CHANNEL_COUNT - st_ivas->n_output_buffer_channels = nchan_out_buff; -#endif + if ( nchan_out_buff > nchan_out_buff_old ) { for ( k = nchan_out_buff_old; k < nchan_out_buff; k++ ) diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 4e43585b08..7b2b73977d 100755 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -122,9 +122,7 @@ ivas_error ivas_sba_dec_reconfigure( int32_t last_ivas_total_brate; int16_t num_channels, num_md_sub_frames; int16_t ch, nchan_out_buff, nchan_out_buff_old; -#ifndef NONBE_FIX_834_839_HEAP_CHANNEL_COUNT int16_t sba_analysis_order_old; -#endif #ifdef JBM_FOR_OSBA int16_t sba_analysis_order_old_flush; #endif @@ -144,19 +142,13 @@ ivas_error ivas_sba_dec_reconfigure( #ifdef JBM_FOR_OSBA sba_analysis_order_old_flush = st_ivas->sba_analysis_order; #endif -#ifndef NONBE_FIX_834_839_HEAP_CHANNEL_COUNT sba_analysis_order_old = ivas_sba_get_analysis_order( last_ivas_total_brate, st_ivas->sba_order ); -#endif /*-----------------------------------------------------------------* * Set SBA high-level parameters * Save old SBA high-level parameters *-----------------------------------------------------------------*/ -#ifdef NONBE_FIX_834_839_HEAP_CHANNEL_COUNT - nchan_out_buff_old = st_ivas->n_output_buffer_channels; -#else nchan_out_buff_old = ivas_get_nchan_buffers_dec( st_ivas, sba_analysis_order_old, last_ivas_total_brate ); -#endif ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); nchan_hp20_old = getNumChanSynthesis( st_ivas ); @@ -746,9 +738,7 @@ ivas_error ivas_sba_dec_reconfigure( if ( !st_ivas->hDecoderConfig->Opt_5ms ) { nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); -#ifdef NONBE_FIX_834_839_HEAP_CHANNEL_COUNT - st_ivas->n_output_buffer_channels = nchan_out_buff; -#endif + if ( nchan_out_buff > nchan_out_buff_old ) { for ( ch = nchan_out_buff_old; ch < nchan_out_buff; ch++ ) diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index ba7d2bdae9..ceab947f3f 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1065,9 +1065,6 @@ typedef struct Decoder_Struct IVAS_LIMITER_HANDLE hLimiter; /* Limiter handle */ float *p_output_f[MAX_OUTPUT_CHANNELS+MAX_NUM_OBJECTS]; /* floating-point output audio buffers */ -#ifdef NONBE_FIX_834_839_HEAP_CHANNEL_COUNT - int16_t n_output_buffer_channels; -#endif /* core-decoder modules */ int16_t nSCE; /* number of total SCEs */ -- GitLab From b6b20319d113ba2d6fde5c3bcce711883db34b5c Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 9 Oct 2023 10:55:22 +0200 Subject: [PATCH 4/4] updates within NONBE_FIX_839_MC_RS_CHANNEL_ALLOC: introduce function ivas_output_buff_dec() and simplify call of ivas_get_nchan_buffers_dec() --- lib_com/ivas_prot.h | 8 +++++++ lib_dec/ivas_ism_dec.c | 17 ++++++++++++++ lib_dec/ivas_mc_paramupmix_dec.c | 4 ++++ lib_dec/ivas_mct_dec.c | 19 +++++++++++---- lib_dec/ivas_omasa_dec.c | 13 +++++++++++ lib_dec/ivas_sba_dec.c | 11 +++++++++ lib_rend/ivas_output_init.c | 40 ++++++++++++++++++++++++++++++++ 7 files changed, 107 insertions(+), 5 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 5656733f5f..543c0adc9d 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -294,6 +294,14 @@ ivas_error ivas_init_decoder( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); +#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC +ivas_error ivas_output_buff_dec( + float *p_output_f[], /* i/o: output audio buffers */ + const int16_t nchan_out_buff_old, /* i : previous frame number of output channels*/ + const int16_t nchan_out_buff /* i : number of output channels */ +); +#endif + ivas_error stereo_dmx_evs_init_encoder( STEREO_DMX_EVS_ENC_HANDLE *hStereoDmxEVS, /* o : Stereo downmix for EVS encoder handle */ const int32_t input_Fs /* i : input sampling rate */ diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index 39c7c667d9..5378cdf666 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -67,7 +67,11 @@ static ivas_error ivas_ism_bitrate_switching_dec( int16_t tc_nchan_tc_new; int16_t tc_nchan_allocate_new; int16_t tc_granularity_new; +#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC + int16_t nchan_out_buff, nchan_out_buff_old; +#else int16_t ch, nchan_out_buff, nchan_out_buff_old; +#endif AUDIO_CONFIG intern_config_old; IVAS_OUTPUT_SETUP hIntSetupOld; RENDERER_TYPE renderer_type_old; @@ -81,7 +85,11 @@ static ivas_error ivas_ism_bitrate_switching_dec( st_ivas->ism_mode = last_ism_mode; ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); st_ivas->ism_mode = ism_mode; +#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC + nchan_out_buff_old = ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ); +#else nchan_out_buff_old = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); +#endif if ( ( error = ivas_ism_config( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->nchan_ism, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ) != IVAS_ERR_OK ) { @@ -331,6 +339,14 @@ static ivas_error ivas_ism_bitrate_switching_dec( if ( !st_ivas->hDecoderConfig->Opt_5ms ) { +#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC + nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ); + + if ( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) + { + return error; + } +#else nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); if ( nchan_out_buff > nchan_out_buff_old ) @@ -352,6 +368,7 @@ static ivas_error ivas_ism_bitrate_switching_dec( st_ivas->p_output_f[ch] = NULL; } } +#endif } /*-----------------------------------------------------------------* diff --git a/lib_dec/ivas_mc_paramupmix_dec.c b/lib_dec/ivas_mc_paramupmix_dec.c index df15270c8b..b4c8b39a08 100644 --- a/lib_dec/ivas_mc_paramupmix_dec.c +++ b/lib_dec/ivas_mc_paramupmix_dec.c @@ -443,7 +443,11 @@ void ivas_mc_paramupmix_dec( } } +#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC + for ( ch = first_empty_channel; ch < ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ); ch++ ) +#else for ( ch = first_empty_channel; ch < ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); ch++ ) +#endif { set_f( output_f[ch], 0.0f, output_frame ); } diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index fd5986d365..8243c19710 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -732,16 +732,15 @@ static ivas_error ivas_mc_dec_reconfig( AUDIO_CONFIG intern_config_old; IVAS_OUTPUT_SETUP hIntSetupOld; #ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC - int16_t nchan_out_buf_old; + int16_t nchan_out_buff_old, nchan_out_buff; #endif - error = IVAS_ERR_OK; + error = IVAS_ERR_OK; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; nchan_transport_old = st_ivas->nchan_transport; #ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC - nchan_out_buf_old = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + nchan_out_buff_old = ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ); #endif - last_mc_mode = ivas_mc_mode_select( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ), st_ivas->hDecoderConfig->last_ivas_total_brate ); /* NB: this assumes that LS config remains the same between frames */ /* we have to temporally set the current mc_mode back to the previous one to make sure the following call to @@ -1391,12 +1390,21 @@ static ivas_error ivas_mc_dec_reconfig( } } +#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC /*-----------------------------------------------------------------* * floating-point output audio buffers *-----------------------------------------------------------------*/ -#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC + if ( !st_ivas->hDecoderConfig->Opt_5ms ) { +#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC + nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ); + + if ( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) + { + return error; + } +#else int16_t nchan_out_buff, ch; nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); @@ -1419,6 +1427,7 @@ static ivas_error ivas_mc_dec_reconfig( st_ivas->p_output_f[ch] = NULL; } } +#endif } #endif diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index b6846dfe93..adb1597cfd 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -180,7 +180,11 @@ ivas_error ivas_omasa_dec_config( ivas_format_orig = st_ivas->ivas_format; st_ivas->ivas_format = st_ivas->last_ivas_format; ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); +#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC + nchan_out_buff_old = ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ); +#else nchan_out_buff_old = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); +#endif st_ivas->ivas_format = ivas_format_orig; @@ -414,6 +418,14 @@ ivas_error ivas_omasa_dec_config( if ( !st_ivas->hDecoderConfig->Opt_5ms ) { +#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC + nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ); + + if ( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) + { + return error; + } +#else nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); if ( nchan_out_buff > nchan_out_buff_old ) @@ -435,6 +447,7 @@ ivas_error ivas_omasa_dec_config( st_ivas->p_output_f[k] = NULL; } } +#endif } } diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 7bdba95d8e..a88e1b408a 100755 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -121,7 +121,11 @@ ivas_error ivas_sba_dec_reconfigure( int32_t ivas_total_brate; int32_t last_ivas_total_brate; int16_t num_channels, num_md_sub_frames; +#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC + int16_t nchan_out_buff, nchan_out_buff_old; +#else int16_t ch, nchan_out_buff, nchan_out_buff_old; +#endif int16_t sba_analysis_order_old; #ifdef JBM_FOR_OSBA int16_t sba_analysis_order_old_flush; @@ -736,6 +740,12 @@ ivas_error ivas_sba_dec_reconfigure( { nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); +#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC + if ( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( nchan_out_buff > nchan_out_buff_old ) { for ( ch = nchan_out_buff_old; ch < nchan_out_buff; ch++ ) @@ -755,6 +765,7 @@ ivas_error ivas_sba_dec_reconfigure( st_ivas->p_output_f[ch] = NULL; } } +#endif } return error; diff --git a/lib_rend/ivas_output_init.c b/lib_rend/ivas_output_init.c index 9ffa67978c..9b3b55e20d 100644 --- a/lib_rend/ivas_output_init.c +++ b/lib_rend/ivas_output_init.c @@ -409,3 +409,43 @@ int16_t ivas_get_nchan_buffers_dec( return nchan_out_buff; } + + +#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC +/*-------------------------------------------------------------------* + * ivas_output_buff_dec() + * + * Allocate/reallocate output audio buffers + *-------------------------------------------------------------------*/ + +ivas_error ivas_output_buff_dec( + float *p_output_f[], /* i/o: output audio buffers */ + const int16_t nchan_out_buff_old, /* i : previous frame number of output channels */ + const int16_t nchan_out_buff /* i : number of output channels */ +) +{ + int16_t ch; + + if ( nchan_out_buff > nchan_out_buff_old ) + { + for ( ch = nchan_out_buff_old; ch < nchan_out_buff; ch++ ) + { + /* note: these are intra-frame heap memories */ + if ( ( p_output_f[ch] = (float *) malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( float ) ) ) == NULL ) /* note: 32000 == max internal sampling rate */ + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point output audio buffer!\n" ) ); + } + } + } + else + { + for ( ch = nchan_out_buff; ch < nchan_out_buff_old; ch++ ) + { + free( p_output_f[ch] ); + p_output_f[ch] = NULL; + } + } + + return IVAS_ERR_OK; +} +#endif -- GitLab