From b027ec607df02535897ae9eb60aa84f8fadbc572 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 8 Sep 2022 09:54:10 +0200 Subject: [PATCH 1/6] fix Issue 98: do the setting of all handles to NULL in one place; under FIX_I98_HANDLES_TO_NULL --- lib_com/ivas_prot.h | 3 +- lib_com/options.h | 2 +- lib_dec/ivas_init_dec.c | 94 +++++++++++++++++++++++++++++++++++++---- lib_dec/lib_dec.c | 5 ++- 4 files changed, 93 insertions(+), 11 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 0016a77f66..57926a5404 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -352,10 +352,11 @@ void ivas_destroy_dec( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); +#ifndef FIX_I98_HANDLES_TO_NULL void ivas_initialize_handles_dec( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); - +#endif ivas_error ivas_core_enc( SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ diff --git a/lib_com/options.h b/lib_com/options.h index 9a564035bf..2958fd6e4d 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -149,7 +149,7 @@ #define FIX_ADAP_STEFI_SHIFT /* Issue 89: fix bug in parameter shift of adaptive stereo filling */ #define SPAR_SCALING_HARMONIZATION /* Issue 80: Changes to harmonize scaling in spar */ #define FIX_I2_BWD /* Issue 2: BWD fix to more quickly react to WB -> SWB/FB change */ - +#define FIX_I98_HANDLES_TO_NULL /* Issue 98: do the setting of all handles to NULL in one place */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index d8c14257bd..d1a243eb03 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -103,7 +103,7 @@ ivas_error ivas_dec_setup( /* read the number of objects */ st_ivas->nchan_transport = 1; num_obj = 1; - k = (int16_t) ( ( ivas_total_brate / FRAMES_PER_SEC ) - 1 ); + k = ( int16_t )( ( ivas_total_brate / FRAMES_PER_SEC ) - 1 ); while ( st_ivas->bit_stream[k] && num_obj < MAX_NUM_OBJECTS ) { num_obj++; @@ -409,7 +409,7 @@ static ivas_error ivas_read_format( else if ( !st_ivas->bfi && ivas_total_brate == IVAS_SID_5k ) { int16_t tc_mode_offset; - tc_mode_offset = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC - 1 ); + tc_mode_offset = ( int16_t )( ivas_total_brate / FRAMES_PER_SEC - 1 ); idx = st_ivas->bit_stream[tc_mode_offset]; // TBD: needs more work for HOA @@ -508,9 +508,79 @@ ivas_error ivas_init_decoder_front( ) { ivas_error error; +#ifdef FIX_I98_HANDLES_TO_NULL + int16_t i; +#endif error = IVAS_ERR_OK; +#ifdef FIX_I98_HANDLES_TO_NULL + /*-----------------------------------------------------------------* + * Dummy pointers to decoder handles + *-----------------------------------------------------------------*/ + + /* SCE handles */ + for ( i = 0; i < MAX_SCE; i++ ) + { + st_ivas->hSCE[i] = NULL; + } + + /* CPE handles */ + for ( i = 0; i < MAX_CPE; i++ ) + { + st_ivas->hCPE[i] = NULL; + } + + st_ivas->mem_hp20_out = NULL; + st_ivas->hLimiter = NULL; + + /* CLDFB handles */ + for ( i = 0; i < MAX_INTERN_CHANNELS; i++ ) + { + st_ivas->cldfbAnaDec[i] = NULL; + } + + for ( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) + { + st_ivas->cldfbSynDec[i] = NULL; + } + + /* ISM metadata handles */ + for ( i = 0; i < MAX_NUM_OBJECTS; i++ ) + { + st_ivas->hIsmMetaData[i] = NULL; + } + + /* spatial coding handles */ + st_ivas->hDirAC = NULL; + st_ivas->hSpar = NULL; + st_ivas->hMasa = NULL; + st_ivas->hQMetaData = NULL; + st_ivas->hMCT = NULL; + st_ivas->hParamMC = NULL; + st_ivas->hLFE = NULL; + + /* rendering handles */ + st_ivas->hBinRenderer = NULL; + st_ivas->hDiracDecBin = NULL; + st_ivas->hLsSetUpConversion = NULL; + st_ivas->hEFAPdata = NULL; + st_ivas->hVBAPdata = NULL; + st_ivas->hIsmRendererData = NULL; + st_ivas->hBinRendererTd = NULL; + st_ivas->hMonoDmxRenderer = NULL; + st_ivas->hIsmRendererData = NULL; + st_ivas->hCrend = NULL; + st_ivas->hHrtf = NULL; + st_ivas->hoa_dec_mtx = NULL; + + /* external data handles */ + st_ivas->hHeadTrackData = NULL; + st_ivas->hHrtfTD = NULL; + st_ivas->hLsSetupCustom = NULL; + st_ivas->hRenderConfig = NULL; +#endif + /*-----------------------------------------------------------------* * Resets *-----------------------------------------------------------------*/ @@ -524,7 +594,7 @@ ivas_error ivas_init_decoder_front( st_ivas->sba_mode = SBA_MODE_NONE; st_ivas->sba_dirac_stereo_flag = 0; - + /* HRTF binauralization latency in ns */ st_ivas->binaural_latency_ns = 0; @@ -679,6 +749,7 @@ ivas_error ivas_init_decoder( } } +#ifndef FIX_I98_HANDLES_TO_NULL #if 0 /*-----------------------------------------------------------------* * Dummy pointers to decoder handles @@ -732,7 +803,7 @@ ivas_error ivas_init_decoder( st_ivas->hHrtf = NULL; /* Crend hrtf data */ st_ivas->hCrend = NULL; /* Crend renderer */ #endif - +#endif /*-----------------------------------------------------------------* * Allocate and initalize SCE/CPE and other handles *-----------------------------------------------------------------*/ @@ -869,7 +940,7 @@ ivas_error ivas_init_decoder( st_ivas->hSpar->enc_param_start_band = min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); - ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, (int16_t) ( st_ivas->hDecoderConfig->output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ), + ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, ( int16_t )( st_ivas->hDecoderConfig->output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ), st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0 ); } } @@ -1469,7 +1540,7 @@ void destroy_core_dec( return; } - +#ifndef FIX_I98_HANDLES_TO_NULL /*------------------------------------------------------------------------- * ivas_initialize_handles_dec() * @@ -1545,7 +1616,7 @@ void ivas_initialize_handles_dec( return; } - +#endif /*------------------------------------------------------------------------- * ivas_destroy_dec() @@ -2015,11 +2086,18 @@ static ivas_error doSanityChecks_IVAS( #endif #ifdef DEBUGGING +#ifdef FIX_I98_HANDLES_TO_NULL + if ( ( st_ivas->hDecoderConfig->Opt_HRTF_binary || st_ivas->hDecoderConfig->force_rend == FORCE_TD_RENDERER ) && ( ( st_ivas->ivas_format != MC_FORMAT && st_ivas->ivas_format != ISM_FORMAT ) || output_config != AUDIO_CONFIG_BINAURAL || ( st_ivas->ivas_format == ISM_FORMAT && st_ivas->ism_mode == ISM_MODE_PARAM ) || ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode != MC_MODE_MCT ) ) ) +#else if ( ( st_ivas->hHrtfTD != NULL || st_ivas->hDecoderConfig->force_rend == FORCE_TD_RENDERER ) && ( ( st_ivas->ivas_format != MC_FORMAT && st_ivas->ivas_format != ISM_FORMAT ) || output_config != AUDIO_CONFIG_BINAURAL || ( st_ivas->ivas_format == ISM_FORMAT && st_ivas->ism_mode == ISM_MODE_PARAM ) || ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode != MC_MODE_MCT ) ) ) +#endif +#else +#ifdef FIX_I98_HANDLES_TO_NULL + if ( st_ivas->hDecoderConfig->Opt_HRTF_binary && ( ( st_ivas->ivas_format != MC_FORMAT && st_ivas->ivas_format != ISM_FORMAT ) || output_config != AUDIO_CONFIG_BINAURAL || ( st_ivas->ivas_format == ISM_FORMAT && st_ivas->ism_mode == ISM_MODE_PARAM ) ) ) #else if ( st_ivas->hHrtfTD != NULL && ( ( st_ivas->ivas_format != MC_FORMAT && st_ivas->ivas_format != ISM_FORMAT ) || output_config != AUDIO_CONFIG_BINAURAL || ( st_ivas->ivas_format == ISM_FORMAT && st_ivas->ism_mode == ISM_MODE_PARAM ) ) ) #endif - +#endif { return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration: Time Domain object renderer not supported in this configuration" ); } diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 78b9f901aa..4a4f69b334 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -146,8 +146,10 @@ ivas_error IVAS_DEC_Open( hIvasDec->prev_ft_speech = 1; /* RXDTX handeler previous frametype flag for G.192 format AMRWB SID_FIRST detection */ hIvasDec->CNG = 0; /* RXDTX handler CNG = 1, no CNG = 0*/ +#ifndef FIX_I98_HANDLES_TO_NULL /* initialize pointers to handles */ ivas_initialize_handles_dec( hIvasDec->st_ivas ); +#endif /* high-level set parameters */ if ( mode == IVAS_DEC_MODE_EVS ) @@ -252,6 +254,7 @@ void IVAS_DEC_Close( ( *phIvasDec )->st_ivas->hDecoderConfig = NULL; } +#ifndef FIX_I98_HANDLES_TO_NULL if ( ( *phIvasDec )->st_ivas->hHeadTrackData != NULL ) { count_free( ( *phIvasDec )->st_ivas->hHeadTrackData ); @@ -261,7 +264,7 @@ void IVAS_DEC_Close( ivas_render_config_close( &( ( *phIvasDec )->st_ivas->hRenderConfig ) ); ivas_HRTF_binary_close( &( *phIvasDec )->st_ivas->hHrtfTD ); - +#endif count_free( ( *phIvasDec )->st_ivas ); } -- GitLab From 259d99f14205a86fda8495fb4d94aca7c22b826f Mon Sep 17 00:00:00 2001 From: Kacper Sagnowski Date: Mon, 12 Sep 2022 10:43:18 +0200 Subject: [PATCH 2/6] Initialize decoder struct earlier to avoid unititalized pointers --- lib_dec/lib_dec.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 4a4f69b334..9cb303d1f3 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -110,6 +110,9 @@ ivas_error IVAS_DEC_Open( float no_diegetic_pan ) { IVAS_DEC_HANDLE hIvasDec; +#ifdef FIX_I98_HANDLES_TO_NULL + ivas_error error; +#endif if ( phIvasDec == NULL ) { @@ -146,7 +149,13 @@ ivas_error IVAS_DEC_Open( hIvasDec->prev_ft_speech = 1; /* RXDTX handeler previous frametype flag for G.192 format AMRWB SID_FIRST detection */ hIvasDec->CNG = 0; /* RXDTX handler CNG = 1, no CNG = 0*/ -#ifndef FIX_I98_HANDLES_TO_NULL +#ifdef FIX_I98_HANDLES_TO_NULL + /* Set decoder parameters to initial values */ + if ( ( error = ivas_init_decoder_front( hIvasDec->st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#else /* initialize pointers to handles */ ivas_initialize_handles_dec( hIvasDec->st_ivas ); #endif @@ -455,11 +464,13 @@ ivas_error IVAS_DEC_Configure( hDecoderConfig->Opt_Headrotation = enableHeadRotation; hDecoderConfig->Opt_HRTF_binary = hrtfReaderEnabled; +#ifndef FIX_I98_HANDLES_TO_NULL /* Set decoder parameters to initial values */ if ( ( error = ivas_init_decoder_front( st_ivas ) ) != IVAS_ERR_OK ) { return error; } +#endif if ( hIvasDec->mode == IVAS_DEC_MODE_EVS ) { -- GitLab From 190d88c2c8c5e1709e7a4a54ce138b8de7031e1c Mon Sep 17 00:00:00 2001 From: Kacper Sagnowski Date: Mon, 12 Sep 2022 11:29:03 +0200 Subject: [PATCH 3/6] Revert "Initialize decoder struct earlier to avoid unititalized pointers" This reverts commit 259d99f14205a86fda8495fb4d94aca7c22b826f. --- lib_dec/lib_dec.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 9cb303d1f3..4a4f69b334 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -110,9 +110,6 @@ ivas_error IVAS_DEC_Open( float no_diegetic_pan ) { IVAS_DEC_HANDLE hIvasDec; -#ifdef FIX_I98_HANDLES_TO_NULL - ivas_error error; -#endif if ( phIvasDec == NULL ) { @@ -149,13 +146,7 @@ ivas_error IVAS_DEC_Open( hIvasDec->prev_ft_speech = 1; /* RXDTX handeler previous frametype flag for G.192 format AMRWB SID_FIRST detection */ hIvasDec->CNG = 0; /* RXDTX handler CNG = 1, no CNG = 0*/ -#ifdef FIX_I98_HANDLES_TO_NULL - /* Set decoder parameters to initial values */ - if ( ( error = ivas_init_decoder_front( hIvasDec->st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } -#else +#ifndef FIX_I98_HANDLES_TO_NULL /* initialize pointers to handles */ ivas_initialize_handles_dec( hIvasDec->st_ivas ); #endif @@ -464,13 +455,11 @@ ivas_error IVAS_DEC_Configure( hDecoderConfig->Opt_Headrotation = enableHeadRotation; hDecoderConfig->Opt_HRTF_binary = hrtfReaderEnabled; -#ifndef FIX_I98_HANDLES_TO_NULL /* Set decoder parameters to initial values */ if ( ( error = ivas_init_decoder_front( st_ivas ) ) != IVAS_ERR_OK ) { return error; } -#endif if ( hIvasDec->mode == IVAS_DEC_MODE_EVS ) { -- GitLab From 27a7321e2052a4e399f3f5527baefadc665c5d59 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 12 Sep 2022 17:49:35 +0200 Subject: [PATCH 4/6] updates within FIX_I98_HANDLES_TO_NULL: initialize handles right after their allocation; introduce the same mechanism to the encoder -> ivas_initialize_handles_enc() --- lib_com/ivas_prot.h | 9 ++++- lib_dec/ivas_init_dec.c | 12 ++++-- lib_dec/lib_dec.c | 82 ++++++++++++++++++++++++----------------- lib_enc/ivas_init_enc.c | 66 +++++++++++++++++++++++++++++++++ lib_enc/lib_enc.c | 70 +++++++++++++++++++++++------------ 5 files changed, 175 insertions(+), 64 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 57926a5404..c4e93a9545 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -238,6 +238,12 @@ uint32_t ivas_syn_output( int16_t *synth_out /* o : integer 16 bits synthesis signal */ ); +#ifdef FIX_I98_HANDLES_TO_NULL +void ivas_initialize_handles_enc( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); +#endif + ivas_error ivas_init_encoder( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ Indice ind_list[][MAX_NUM_INDICES], /* i : indices list */ @@ -352,11 +358,10 @@ void ivas_destroy_dec( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); -#ifndef FIX_I98_HANDLES_TO_NULL void ivas_initialize_handles_dec( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); -#endif + ivas_error ivas_core_enc( SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index d1a243eb03..44607faaa9 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -551,7 +551,7 @@ ivas_error ivas_init_decoder_front( st_ivas->hIsmMetaData[i] = NULL; } - /* spatial coding handles */ + /* spatial coding handles */ st_ivas->hDirAC = NULL; st_ivas->hSpar = NULL; st_ivas->hMasa = NULL; @@ -1540,7 +1540,7 @@ void destroy_core_dec( return; } -#ifndef FIX_I98_HANDLES_TO_NULL + /*------------------------------------------------------------------------- * ivas_initialize_handles_dec() * @@ -1575,9 +1575,12 @@ void ivas_initialize_handles_dec( st_ivas->hCPE[i] = NULL; } +#ifndef FIX_I98_HANDLES_TO_NULL st_ivas->nSCE = 0; st_ivas->nCPE = 0; +#endif st_ivas->mem_hp20_out = NULL; + st_ivas->hLimiter = NULL; /* ISM metadata handles */ for ( i = 0; i < MAX_NUM_OBJECTS; i++ ) @@ -1586,7 +1589,9 @@ void ivas_initialize_handles_dec( } /* spatial coding handles */ +#ifndef FIX_I98_HANDLES_TO_NULL st_ivas->hIsmRendererData = NULL; +#endif st_ivas->hDirAC = NULL; st_ivas->hSpar = NULL; st_ivas->hMasa = NULL; @@ -1610,13 +1615,12 @@ void ivas_initialize_handles_dec( st_ivas->hHeadTrackData = NULL; st_ivas->hHrtfTD = NULL; - st_ivas->hLimiter = NULL; st_ivas->hLsSetupCustom = NULL; st_ivas->hRenderConfig = NULL; return; } -#endif + /*------------------------------------------------------------------------- * ivas_destroy_dec() diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 4a4f69b334..2d41945563 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -110,12 +110,17 @@ ivas_error IVAS_DEC_Open( float no_diegetic_pan ) { IVAS_DEC_HANDLE hIvasDec; + Decoder_Struct *st_ivas; if ( phIvasDec == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } + /*-----------------------------------------------------------------* + * Allocate and initialize IVAS application decoder handle + *-----------------------------------------------------------------*/ + if ( ( *phIvasDec = (IVAS_DEC_HANDLE) count_malloc( sizeof( struct IVAS_DEC ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS decoder handle" ); @@ -128,6 +133,16 @@ ivas_error IVAS_DEC_Open( hIvasDec->mode = mode; + hIvasDec->bitstreamformat = G192; + hIvasDec->Opt_VOIP = 0; + hIvasDec->amrwb_rfc4867_flag = -1; + hIvasDec->prev_ft_speech = 1; /* RXDTX handler previous frametype flag for G.192 format AMRWB SID_FIRST detection */ + hIvasDec->CNG = 0; /* RXDTX handler CNG = 1, no CNG = 0*/ + + /*-----------------------------------------------------------------* + * Initialize IVAS-codec decoder state + *-----------------------------------------------------------------*/ + if ( ( hIvasDec->st_ivas = (Decoder_Struct *) count_malloc( sizeof( Decoder_Struct ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS decoder structure" ); @@ -138,50 +153,49 @@ ivas_error IVAS_DEC_Open( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for Decoder config structure" ); } - init_decoder_config( hIvasDec->st_ivas->hDecoderConfig, orientation_tracking, no_diegetic_pan ); + /*-----------------------------------------------------------------* + * Initialize IVAS-codec decoder state + *-----------------------------------------------------------------*/ - hIvasDec->bitstreamformat = G192; - hIvasDec->Opt_VOIP = 0; - hIvasDec->amrwb_rfc4867_flag = -1; - hIvasDec->prev_ft_speech = 1; /* RXDTX handeler previous frametype flag for G.192 format AMRWB SID_FIRST detection */ - hIvasDec->CNG = 0; /* RXDTX handler CNG = 1, no CNG = 0*/ + st_ivas = hIvasDec->st_ivas; -#ifndef FIX_I98_HANDLES_TO_NULL - /* initialize pointers to handles */ - ivas_initialize_handles_dec( hIvasDec->st_ivas ); -#endif + /* initialize Decoder Config. handle */ + init_decoder_config( hIvasDec->st_ivas->hDecoderConfig, orientation_tracking, no_diegetic_pan ); - /* high-level set parameters */ + /* initialize pointers to handles to NULL */ + ivas_initialize_handles_dec( st_ivas ); + + /* set high-level parameters */ if ( mode == IVAS_DEC_MODE_EVS ) { - hIvasDec->st_ivas->codec_mode = 0; /* unknown before first frame */ - hIvasDec->st_ivas->element_mode_init = EVS_MONO; - hIvasDec->st_ivas->ivas_format = MONO_FORMAT; - hIvasDec->st_ivas->transport_config = AUDIO_CONFIG_INVALID; - hIvasDec->st_ivas->intern_config = AUDIO_CONFIG_INVALID; - hIvasDec->st_ivas->writeFECoffset = 0; + st_ivas->codec_mode = 0; /* unknown before first frame */ + st_ivas->element_mode_init = EVS_MONO; + st_ivas->ivas_format = MONO_FORMAT; + st_ivas->transport_config = AUDIO_CONFIG_INVALID; + st_ivas->intern_config = AUDIO_CONFIG_INVALID; + st_ivas->writeFECoffset = 0; return IVAS_ERR_OK; } else if ( mode == IVAS_DEC_MODE_IVAS ) { - hIvasDec->st_ivas->codec_mode = 0; /* unknown before first frame */ - hIvasDec->st_ivas->element_mode_init = -1; - hIvasDec->st_ivas->ivas_format = UNDEFINED_FORMAT; - hIvasDec->st_ivas->transport_config = AUDIO_CONFIG_INVALID; - hIvasDec->st_ivas->intern_config = AUDIO_CONFIG_INVALID; - hIvasDec->st_ivas->renderer_type = RENDERER_DISABLE; - hIvasDec->st_ivas->ini_frame = 0; - hIvasDec->st_ivas->ini_active_frame = 0; - hIvasDec->st_ivas->writeFECoffset = 0; - - hIvasDec->st_ivas->ism_mode = ISM_MODE_NONE; - hIvasDec->st_ivas->sba_mode = SBA_MODE_NONE; - hIvasDec->st_ivas->mc_mode = MC_MODE_NONE; - - hIvasDec->st_ivas->sba_order = 0; - hIvasDec->st_ivas->sba_planar = 0; - hIvasDec->st_ivas->sba_analysis_order = 0; + st_ivas->codec_mode = 0; /* unknown before first frame */ + st_ivas->element_mode_init = -1; + st_ivas->ivas_format = UNDEFINED_FORMAT; + st_ivas->transport_config = AUDIO_CONFIG_INVALID; + st_ivas->intern_config = AUDIO_CONFIG_INVALID; + st_ivas->renderer_type = RENDERER_DISABLE; + st_ivas->ini_frame = 0; + st_ivas->ini_active_frame = 0; + st_ivas->writeFECoffset = 0; + + st_ivas->ism_mode = ISM_MODE_NONE; + st_ivas->sba_mode = SBA_MODE_NONE; + st_ivas->mc_mode = MC_MODE_NONE; + + st_ivas->sba_order = 0; + st_ivas->sba_planar = 0; + st_ivas->sba_analysis_order = 0; return IVAS_ERR_OK; } diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 33f0f7da02..4ccb10e6f6 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -237,6 +237,67 @@ void copy_encoder_config( } +#ifdef FIX_I98_HANDLES_TO_NULL +/*------------------------------------------------------------------------- + * ivas_initialize_handles_enc() + * + * NULL initialization of handles + *-------------------------------------------------------------------------*/ + +void ivas_initialize_handles_enc( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +) +{ + int16_t i; + + for ( i = 0; i < MAX_SCE; i++ ) + { + st_ivas->hSCE[i] = NULL; + } + + for ( i = 0; i < MAX_CPE; i++ ) + { + st_ivas->hCPE[i] = NULL; + } + + /* ISm metadata handles */ + for ( i = 0; i < MAX_NUM_OBJECTS; i++ ) + { + st_ivas->hIsmMetaData[i] = NULL; + } + + /* Q Metadata handle */ + st_ivas->hQMetaData = NULL; + + /* DirAC handle */ + st_ivas->hDirAC = NULL; + + /* SPAR handle */ + st_ivas->hSpar = NULL; + + /* MASA encoder handle */ + st_ivas->hMasa = NULL; + + /* MCT handle */ + st_ivas->hMCT = NULL; + + /* Parametric MC handle */ + st_ivas->hParamMC = NULL; + + /* Multi-channel MASA handle */ + st_ivas->hMcMasa = NULL; + + /* Stereo downmix for EVS encoder handle */ + st_ivas->hStereoDmxEVS = NULL; + + /* LFE handle */ + st_ivas->hLFE = NULL; + + return; +} +#endif + + /*-------------------------------------------------------------------* * ivas_init_encoder() * @@ -275,6 +336,9 @@ ivas_error ivas_init_encoder( st_ivas->mc_mode = MC_MODE_NONE; st_ivas->sba_mode = SBA_MODE_NONE; +#ifdef FIX_I98_HANDLES_TO_NULL + st_ivas->nchan_transport = -1; +#else /*-----------------------------------------------------------------* * Dummy pointers to max. number of SCEs and CPEs *-----------------------------------------------------------------*/ @@ -323,6 +387,7 @@ ivas_error ivas_init_encoder( /* LFE handle */ st_ivas->hLFE = NULL; +#endif /*-----------------------------------------------------------------* * Allocate and initialize SCE/CPE and other handles @@ -986,3 +1051,4 @@ void ivas_destroy_enc( return; } + diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 104a8ca388..aea9646d6c 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -105,6 +105,10 @@ ivas_error IVAS_ENC_Open( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } + /*-----------------------------------------------------------------* + * Allocate and initialize IVAS application encoder handle + *-----------------------------------------------------------------*/ + #ifdef BITSTREAM_INDICES_MEMORY if ( ( *phIvasEnc = (IVAS_ENC_HANDLE) dynamic_malloc( sizeof( struct IVAS_ENC ) ) ) == NULL ) #else @@ -114,15 +118,14 @@ ivas_error IVAS_ENC_Open( return IVAS_ERR_FAILED_ALLOC; } - if ( ( ( *phIvasEnc )->st_ivas = (Encoder_Struct *) count_malloc( sizeof( Encoder_Struct ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS encoder structure" ); - } - - if ( ( ( *phIvasEnc )->st_ivas->hEncoderConfig = (ENCODER_CONFIG_HANDLE) count_malloc( sizeof( ENCODER_CONFIG ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for Encoder config structure" ); - } + ( *phIvasEnc )->hCoreCoder = NULL; + ( *phIvasEnc )->isConfigured = false; +#ifdef DEBUGGING + ( *phIvasEnc )->cmd_stereo = false; +#endif + ( *phIvasEnc )->switchingActive = false; + ( *phIvasEnc )->maxBandwidthUser = false; + resetIsmMetadataProvidedFlags( *phIvasEnc ); /*-----------------------------------------------------------------* * Initialize indices @@ -147,31 +150,43 @@ ivas_error IVAS_ENC_Open( } /*-----------------------------------------------------------------* - * Initialize encoder state + * Allocate IVAS-codec encoder state + *-----------------------------------------------------------------*/ + + if ( ( ( *phIvasEnc )->st_ivas = (Encoder_Struct *) count_malloc( sizeof( Encoder_Struct ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS encoder structure" ); + } + + if ( ( ( *phIvasEnc )->st_ivas->hEncoderConfig = (ENCODER_CONFIG_HANDLE) count_malloc( sizeof( ENCODER_CONFIG ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for Encoder config structure" ); + } + + /*-----------------------------------------------------------------* + * Initialize IVAS-codec encoder state *-----------------------------------------------------------------*/ st_ivas = ( *phIvasEnc )->st_ivas; + + /* initialize encoder Config. handle */ + init_encoder_config( st_ivas->hEncoderConfig ); + +#ifdef FIX_I98_HANDLES_TO_NULL + /* initialize pointers to handles to NULL */ + ivas_initialize_handles_enc( st_ivas ); +#else st_ivas->hEncoderConfig->ivas_total_brate = ACELP_12k65; st_ivas->hEncoderConfig->Opt_SC_VBR = 0; st_ivas->hEncoderConfig->last_Opt_SC_VBR = 0; +#endif + /* set high-level parameters */ st_ivas->mc_mode = MC_MODE_NONE; st_ivas->ism_mode = ISM_MODE_NONE; st_ivas->sba_mode = SBA_MODE_NONE; st_ivas->sba_analysis_order = 0; - init_encoder_config( st_ivas->hEncoderConfig ); - - ( *phIvasEnc )->hCoreCoder = NULL; - ( *phIvasEnc )->isConfigured = false; -#ifdef DEBUGGING - ( *phIvasEnc )->cmd_stereo = false; -#endif - ( *phIvasEnc )->switchingActive = false; - ( *phIvasEnc )->maxBandwidthUser = false; - resetIsmMetadataProvidedFlags( *phIvasEnc ); - - return IVAS_ERR_OK; } @@ -934,7 +949,7 @@ ivas_error IVAS_ENC_GetDelay( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - *delay = NS2SA( hEncoderConfig->input_Fs, (int32_t) ( get_delay( ENC, hEncoderConfig->input_Fs, hEncoderConfig->ivas_format, NULL, RENDERER_DISABLE, 0 ) + 0.5f ) ); + *delay = NS2SA( hEncoderConfig->input_Fs, ( int32_t )( get_delay( ENC, hEncoderConfig->input_Fs, hEncoderConfig->ivas_format, NULL, RENDERER_DISABLE, 0 ) + 0.5f ) ); *delay *= hEncoderConfig->nchan_inp; @@ -952,7 +967,7 @@ static int16_t getInputBufferSize( const Encoder_Struct *st_ivas /* i : IVAS encoder handle */ ) { - return (int16_t) ( st_ivas->hEncoderConfig->input_Fs * st_ivas->hEncoderConfig->nchan_inp / FRAMES_PER_SEC ); + return ( int16_t )( st_ivas->hEncoderConfig->input_Fs * st_ivas->hEncoderConfig->nchan_inp / FRAMES_PER_SEC ); } @@ -2033,11 +2048,18 @@ static void init_encoder_config( ENCODER_CONFIG_HANDLE hEncoderConfig /* o : configuration structure */ ) { +#ifdef FIX_I98_HANDLES_TO_NULL + hEncoderConfig->ivas_total_brate = ACELP_12k65; +#endif hEncoderConfig->max_bwidth = SWB; hEncoderConfig->input_Fs = 16000; hEncoderConfig->nchan_inp = 1; hEncoderConfig->element_mode_init = EVS_MONO; hEncoderConfig->ivas_format = UNDEFINED_FORMAT; +#ifdef FIX_I98_HANDLES_TO_NULL + hEncoderConfig->Opt_SC_VBR = 0; + hEncoderConfig->last_Opt_SC_VBR = 0; +#endif hEncoderConfig->Opt_AMR_WB = 0; hEncoderConfig->Opt_DTX_ON = 0; hEncoderConfig->Opt_RF_ON = 0; -- GitLab From 382da23a45e52e3afb33ec96a242305012e5dbf6 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 12 Sep 2022 18:12:07 +0200 Subject: [PATCH 5/6] set more pointers to NULL --- lib_dec/ivas_init_dec.c | 4 +++- lib_enc/ivas_init_enc.c | 2 ++ lib_enc/lib_enc.c | 1 - 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 44607faaa9..45ee1edf10 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1575,7 +1575,9 @@ void ivas_initialize_handles_dec( st_ivas->hCPE[i] = NULL; } -#ifndef FIX_I98_HANDLES_TO_NULL +#ifdef FIX_I98_HANDLES_TO_NULL + st_ivas->bit_stream = NULL; +#else st_ivas->nSCE = 0; st_ivas->nCPE = 0; #endif diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 4ccb10e6f6..34868ebefc 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -260,6 +260,8 @@ void ivas_initialize_handles_enc( st_ivas->hCPE[i] = NULL; } + st_ivas->mem_hp20_in = NULL; + /* ISm metadata handles */ for ( i = 0; i < MAX_NUM_OBJECTS; i++ ) { diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index aea9646d6c..cf2c5aa467 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -54,7 +54,6 @@ struct IVAS_ENC Indice ind_list[MAX_NUM_DATA][MAX_NUM_INDICES]; /* list of indices */ Indice ind_list_metadata[MAX_NUM_METADATA][MAX_BITS_METADATA]; /* list of indices for metadata */ ENC_CORE_HANDLE hCoreCoder; - /* Some of these can be moved to Encoder_Struct, but for now leave them here to keep merging simpler */ bool isConfigured; #ifdef DEBUGGING bool cmd_stereo; -- GitLab From 51c905bd116ff4fc1a562f45475072d7fcc1bc85 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 13 Sep 2022 15:58:50 +0200 Subject: [PATCH 6/6] remove redundant code --- lib_dec/ivas_init_dec.c | 70 ----------------------------------------- 1 file changed, 70 deletions(-) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 45ee1edf10..87b48cd0d8 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -508,79 +508,9 @@ ivas_error ivas_init_decoder_front( ) { ivas_error error; -#ifdef FIX_I98_HANDLES_TO_NULL - int16_t i; -#endif error = IVAS_ERR_OK; -#ifdef FIX_I98_HANDLES_TO_NULL - /*-----------------------------------------------------------------* - * Dummy pointers to decoder handles - *-----------------------------------------------------------------*/ - - /* SCE handles */ - for ( i = 0; i < MAX_SCE; i++ ) - { - st_ivas->hSCE[i] = NULL; - } - - /* CPE handles */ - for ( i = 0; i < MAX_CPE; i++ ) - { - st_ivas->hCPE[i] = NULL; - } - - st_ivas->mem_hp20_out = NULL; - st_ivas->hLimiter = NULL; - - /* CLDFB handles */ - for ( i = 0; i < MAX_INTERN_CHANNELS; i++ ) - { - st_ivas->cldfbAnaDec[i] = NULL; - } - - for ( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) - { - st_ivas->cldfbSynDec[i] = NULL; - } - - /* ISM metadata handles */ - for ( i = 0; i < MAX_NUM_OBJECTS; i++ ) - { - st_ivas->hIsmMetaData[i] = NULL; - } - - /* spatial coding handles */ - st_ivas->hDirAC = NULL; - st_ivas->hSpar = NULL; - st_ivas->hMasa = NULL; - st_ivas->hQMetaData = NULL; - st_ivas->hMCT = NULL; - st_ivas->hParamMC = NULL; - st_ivas->hLFE = NULL; - - /* rendering handles */ - st_ivas->hBinRenderer = NULL; - st_ivas->hDiracDecBin = NULL; - st_ivas->hLsSetUpConversion = NULL; - st_ivas->hEFAPdata = NULL; - st_ivas->hVBAPdata = NULL; - st_ivas->hIsmRendererData = NULL; - st_ivas->hBinRendererTd = NULL; - st_ivas->hMonoDmxRenderer = NULL; - st_ivas->hIsmRendererData = NULL; - st_ivas->hCrend = NULL; - st_ivas->hHrtf = NULL; - st_ivas->hoa_dec_mtx = NULL; - - /* external data handles */ - st_ivas->hHeadTrackData = NULL; - st_ivas->hHrtfTD = NULL; - st_ivas->hLsSetupCustom = NULL; - st_ivas->hRenderConfig = NULL; -#endif - /*-----------------------------------------------------------------* * Resets *-----------------------------------------------------------------*/ -- GitLab