From 49a28ccf121890814b356b19af0a3f746c4889c2 Mon Sep 17 00:00:00 2001 From: Vidhya V P <100825@ittiam.com> Date: Tue, 2 May 2023 17:11:19 +0530 Subject: [PATCH 1/4] Fix for crash issue #391 for SBA mode --- lib_com/ivas_dirac_com.c | 4 +- lib_com/ivas_stat_com.h | 3 + lib_com/options.h | 1 + lib_dec/ivas_dirac_dec.c | 163 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 169 insertions(+), 2 deletions(-) diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c index 172dbc5365..ba36229d3e 100644 --- a/lib_com/ivas_dirac_com.c +++ b/lib_com/ivas_dirac_com.c @@ -137,7 +137,9 @@ ivas_error ivas_dirac_config( } hConfig->enc_param_start_band = 0; hConfig->dec_param_estim = FALSE; - +#ifdef FIX_391_SBA + hConfig->dec_param_estim_old = hConfig->dec_param_estim; +#endif if ( ivas_format == SBA_FORMAT ) /* skip for MASA decoder */ { if ( ( error = ivas_dirac_sba_config( hQMetaData, nchan_transport, nSCE, nCPE, element_mode, ivas_total_brate, sba_order, sba_mode, hConfig->nbands - spar_dirac_split_band ) ) != IVAS_ERR_OK ) diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 22feb9b164..9f1fafff27 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -174,6 +174,9 @@ typedef struct ivas_dirac_config_data_struct { int16_t enc_param_start_band; int16_t dec_param_estim; +#ifdef FIX_391_SBA + int16_t dec_param_estim_old; +#endif int16_t nbands; } DIRAC_CONFIG_DATA, *DIRAC_CONFIG_DATA_HANDLE; diff --git a/lib_com/options.h b/lib_com/options.h index f6cee9d9e1..f4a02da9d0 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -176,6 +176,7 @@ /*#define LBR_SBA_PLANAR*/ /* Converting low bitrate SBA modes to Planar */ #define LBR_ADAP_SMOOTHING #endif +#define FIX_391_SBA /* Dlb: Fix for issue 391 for SBA */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ #endif diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index dfeb946a02..358e1c00ca 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -813,7 +813,12 @@ ivas_error ivas_dirac_dec_config( } mvs2s( DirAC_block_grouping, hDirAC->block_grouping, MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); - +#ifdef FIX_391_SBA + if ( flag_config == DIRAC_OPEN ) + { + hDirAC->hConfig->dec_param_estim_old = hDirAC->hConfig->dec_param_estim; + } +#endif if ( flag_config == DIRAC_OPEN ) { hDirAC->dirac_md_buffer_length = 0; @@ -984,7 +989,163 @@ ivas_error ivas_dirac_dec_config( hDirAC->dithering_seed = DIRAC_DITH_SEED; st_ivas->hDirAC = hDirAC; } +#ifdef FIX_391_SBA + else if ( ( hDirAC->hConfig->dec_param_estim_old != hDirAC->hConfig->dec_param_estim ) && ( st_ivas->hHeadTrackData ) ) + { + int16_t num_slots_in_subfr; + num_slots_in_subfr = hDirAC->hConfig->dec_param_estim ? CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES : 1; + if ( st_ivas->sba_mode == SBA_MODE_SPAR ) + { + if ( ( hDirAC->hConfig->dec_param_estim_old != hDirAC->hConfig->dec_param_estim ) ) + { + + for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) + { + if ( hDirAC->azimuth[i] != NULL ) + { + free( hDirAC->azimuth[i] ); + hDirAC->azimuth[i] = NULL; + } + + if ( hDirAC->elevation[i] != NULL ) + { + free( hDirAC->elevation[i] ); + hDirAC->elevation[i] = NULL; + } + if ( hDirAC->diffuseness_vector[i] != NULL ) + { + free( hDirAC->diffuseness_vector[i] ); + hDirAC->diffuseness_vector[i] = NULL; + } + } + if ( hDirAC->azimuth != NULL ) + { + free( hDirAC->azimuth ); + hDirAC->azimuth = NULL; + } + if ( hDirAC->elevation != NULL ) + { + free( hDirAC->elevation ); + hDirAC->elevation = NULL; + } + if ( hDirAC->diffuseness_vector != NULL ) + { + free( hDirAC->diffuseness_vector ); + hDirAC->diffuseness_vector = NULL; + } + if ( hDirAC->energy_ratio1 != NULL ) + { + for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) + { + if ( hDirAC->energy_ratio1[i] != NULL ) + { + free( hDirAC->energy_ratio1[i] ); + hDirAC->energy_ratio1[i] = NULL; + } + } + free( hDirAC->energy_ratio1 ); + hDirAC->energy_ratio1 = NULL; + } + if ( hDirAC->spreadCoherence != NULL ) + { + for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) + { + if ( hDirAC->spreadCoherence[i] != NULL ) + { + free( hDirAC->spreadCoherence[i] ); + hDirAC->spreadCoherence[i] = NULL; + } + } + free( hDirAC->spreadCoherence ); + hDirAC->spreadCoherence = NULL; + } + if ( hDirAC->surroundingCoherence != NULL ) + { + for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) + { + if ( hDirAC->surroundingCoherence[i] != NULL ) + { + free( hDirAC->surroundingCoherence[i] ); + hDirAC->surroundingCoherence[i] = NULL; + } + } + free( hDirAC->surroundingCoherence ); + hDirAC->surroundingCoherence = NULL; + } + } + hDirAC->dirac_md_buffer_length = ( MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_DIRAC_PARAM_DEC_SFR ) * num_slots_in_subfr; + hDirAC->dirac_bs_md_write_idx = DELAY_DIRAC_PARAM_DEC_SFR * num_slots_in_subfr; + hDirAC->spar_to_dirac_write_idx = DELAY_DIRAC_PARAM_DEC_SFR * num_slots_in_subfr; + if ( ( hDirAC->azimuth = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + if ( ( hDirAC->elevation = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + if ( ( hDirAC->diffuseness_vector = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + if ( ( hDirAC->energy_ratio1 = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + if ( ( hDirAC->spreadCoherence = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + if ( ( hDirAC->surroundingCoherence = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) + { + if ( ( hDirAC->azimuth[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set_s( hDirAC->azimuth[i], 0, hDirAC->num_freq_bands ); + + if ( ( hDirAC->elevation[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set_s( hDirAC->elevation[i], 0, hDirAC->num_freq_bands ); + + if ( ( hDirAC->diffuseness_vector[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set_f( hDirAC->diffuseness_vector[i], 1.0f, hDirAC->num_freq_bands ); + + if ( ( hDirAC->energy_ratio1[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set_f( hDirAC->energy_ratio1[i], 0.0f, hDirAC->num_freq_bands ); + + if ( ( hDirAC->spreadCoherence[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set_f( hDirAC->spreadCoherence[i], 0.0f, hDirAC->num_freq_bands ); + + if ( ( hDirAC->surroundingCoherence[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set_f( hDirAC->surroundingCoherence[i], 0.0f, hDirAC->num_freq_bands ); + } + } + } +#endif return error; } -- GitLab From b79e0febcd8070ac10d3af2c0e0d0bb7f695c66f Mon Sep 17 00:00:00 2001 From: Vidhya V P <100825@ittiam.com> Date: Tue, 2 May 2023 19:01:21 +0530 Subject: [PATCH 2/4] Minor changes --- lib_dec/ivas_dirac_dec.c | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 358e1c00ca..dd0a0ff175 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -1006,7 +1006,6 @@ ivas_error ivas_dirac_dec_config( free( hDirAC->azimuth[i] ); hDirAC->azimuth[i] = NULL; } - if ( hDirAC->elevation[i] != NULL ) { free( hDirAC->elevation[i] ); @@ -1017,6 +1016,21 @@ ivas_error ivas_dirac_dec_config( free( hDirAC->diffuseness_vector[i] ); hDirAC->diffuseness_vector[i] = NULL; } + if ( hDirAC->energy_ratio1[i] != NULL ) + { + free( hDirAC->energy_ratio1[i] ); + hDirAC->energy_ratio1[i] = NULL; + } + if ( hDirAC->spreadCoherence[i] != NULL ) + { + free( hDirAC->spreadCoherence[i] ); + hDirAC->spreadCoherence[i] = NULL; + } + if ( hDirAC->surroundingCoherence[i] != NULL ) + { + free( hDirAC->surroundingCoherence[i] ); + hDirAC->surroundingCoherence[i] = NULL; + } } if ( hDirAC->azimuth != NULL ) { @@ -1035,40 +1049,16 @@ ivas_error ivas_dirac_dec_config( } if ( hDirAC->energy_ratio1 != NULL ) { - for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) - { - if ( hDirAC->energy_ratio1[i] != NULL ) - { - free( hDirAC->energy_ratio1[i] ); - hDirAC->energy_ratio1[i] = NULL; - } - } free( hDirAC->energy_ratio1 ); hDirAC->energy_ratio1 = NULL; } if ( hDirAC->spreadCoherence != NULL ) { - for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) - { - if ( hDirAC->spreadCoherence[i] != NULL ) - { - free( hDirAC->spreadCoherence[i] ); - hDirAC->spreadCoherence[i] = NULL; - } - } free( hDirAC->spreadCoherence ); hDirAC->spreadCoherence = NULL; } if ( hDirAC->surroundingCoherence != NULL ) { - for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) - { - if ( hDirAC->surroundingCoherence[i] != NULL ) - { - free( hDirAC->surroundingCoherence[i] ); - hDirAC->surroundingCoherence[i] = NULL; - } - } free( hDirAC->surroundingCoherence ); hDirAC->surroundingCoherence = NULL; } -- GitLab From a64fdc879fafbffd6957d3688a7870453618fdc5 Mon Sep 17 00:00:00 2001 From: Vidhya V P <100825@ittiam.com> Date: Wed, 3 May 2023 09:24:49 +0530 Subject: [PATCH 3/4] One more minor modification. --- lib_dec/ivas_dirac_dec.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index dd0a0ff175..303ce75da4 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -813,19 +813,16 @@ ivas_error ivas_dirac_dec_config( } mvs2s( DirAC_block_grouping, hDirAC->block_grouping, MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); -#ifdef FIX_391_SBA - if ( flag_config == DIRAC_OPEN ) - { - hDirAC->hConfig->dec_param_estim_old = hDirAC->hConfig->dec_param_estim; - } -#endif + if ( flag_config == DIRAC_OPEN ) { hDirAC->dirac_md_buffer_length = 0; hDirAC->dirac_bs_md_write_idx = 0; hDirAC->dirac_read_idx = 0; hDirAC->spar_to_dirac_write_idx = 0; - +#ifdef FIX_391_SBA + hDirAC->hConfig->dec_param_estim_old = hDirAC->hConfig->dec_param_estim; +#endif if ( st_ivas->mc_mode == MC_MODE_MCMASA ) { hDirAC->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES; -- GitLab From 6d00944f40675698336eb11ddacefce458f45454 Mon Sep 17 00:00:00 2001 From: Vidhya V P <100825@ittiam.com> Date: Thu, 4 May 2023 10:26:15 +0530 Subject: [PATCH 4/4] Added change to make the fix generic --- lib_dec/ivas_dirac_dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 303ce75da4..446ed23bb3 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -987,7 +987,7 @@ ivas_error ivas_dirac_dec_config( st_ivas->hDirAC = hDirAC; } #ifdef FIX_391_SBA - else if ( ( hDirAC->hConfig->dec_param_estim_old != hDirAC->hConfig->dec_param_estim ) && ( st_ivas->hHeadTrackData ) ) + else if ( hDirAC->hConfig->dec_param_estim_old != hDirAC->hConfig->dec_param_estim ) { int16_t num_slots_in_subfr; num_slots_in_subfr = hDirAC->hConfig->dec_param_estim ? CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES : 1; -- GitLab