diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 0016a77f66be8903b95d323adb719c61e0b532bf..c4e93a9545eba3a0c55d39301e5fe83c5467dcba 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 */ diff --git a/lib_com/options.h b/lib_com/options.h index dede5c14808229cca8cbf7b9d3dd16780d48c40c..54d2700014e27b7aee360d2470ced52d1e312f11 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -147,8 +147,9 @@ /*#define FIX_I1_113*/ /* under review : MCT bit distribution optimization for SBA high bitrates*/ #define SPAR_SCALING_HARMONIZATION /* Issue 80: Changes to harmonize scaling in spar */ - #define SBA_INTERN_CONFIG_FIX_HOA2 /* Issue 99 : Fix for incorrect internal_config when output format is HOA2 or FOA*/ +#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 5235413411ddf410230c2dc3fb3c13d8e0f4c72e..87b48cd0d897783610979384798c7a5882e2fcc9 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 @@ -679,6 +679,7 @@ ivas_error ivas_init_decoder( } } +#ifndef FIX_I98_HANDLES_TO_NULL #if 0 /*-----------------------------------------------------------------* * Dummy pointers to decoder handles @@ -732,7 +733,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 +870,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 ); } } @@ -1504,9 +1505,14 @@ void ivas_initialize_handles_dec( st_ivas->hCPE[i] = NULL; } +#ifdef FIX_I98_HANDLES_TO_NULL + st_ivas->bit_stream = NULL; +#else 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++ ) @@ -1515,7 +1521,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; @@ -1539,7 +1547,6 @@ 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; @@ -2015,11 +2022,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 78b9f901aaf2d9d1ec8800d70234e89f7d2c66fa..2d4194556359110ba2ce16f924e5b091dd2ef029 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,48 +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; - /* initialize pointers to handles */ - ivas_initialize_handles_dec( hIvasDec->st_ivas ); + /* initialize Decoder Config. handle */ + init_decoder_config( hIvasDec->st_ivas->hDecoderConfig, orientation_tracking, no_diegetic_pan ); + + /* initialize pointers to handles to NULL */ + ivas_initialize_handles_dec( st_ivas ); - /* high-level set parameters */ + /* 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; + 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; - hIvasDec->st_ivas->ism_mode = ISM_MODE_NONE; - hIvasDec->st_ivas->sba_mode = SBA_MODE_NONE; - hIvasDec->st_ivas->mc_mode = MC_MODE_NONE; + st_ivas->ism_mode = ISM_MODE_NONE; + st_ivas->sba_mode = SBA_MODE_NONE; + 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->sba_order = 0; + st_ivas->sba_planar = 0; + st_ivas->sba_analysis_order = 0; return IVAS_ERR_OK; } @@ -252,6 +268,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 +278,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 ); } diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 33f0f7da02acec0c7347a9cc79b005d06dfb538b..34868ebefc8e6f8773dabba3160534f72960e440 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -237,6 +237,69 @@ 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; + } + + st_ivas->mem_hp20_in = 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 +338,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 +389,7 @@ ivas_error ivas_init_encoder( /* LFE handle */ st_ivas->hLFE = NULL; +#endif /*-----------------------------------------------------------------* * Allocate and initialize SCE/CPE and other handles @@ -986,3 +1053,4 @@ void ivas_destroy_enc( return; } + diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 104a8ca388a363a73eafda5c32b31b00a6cef0d0..cf2c5aa4670ce20e3b77a59ca92edbd9cdff983c 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; @@ -105,6 +104,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 +117,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 +149,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 +948,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 +966,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 +2047,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;