diff --git a/apps/decoder.c b/apps/decoder.c index e362972866613be95f6be0aef0287dc36fac3628..c25a282e1fe16a60520c2cc93c16cb5eb146938b 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -176,14 +176,22 @@ typedef struct static bool parseCmdlIVAS_dec( int16_t argc, char **argv, DecArguments *arg ); static void usage_dec( void ); static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtfBinary, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ObjectEditFileReader *objectEditFileReader, ISAR_SPLIT_REND_BITS_DATA *splitRendBits, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf ); +#ifdef FIX_FMSW_DEC +static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtf, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ObjectEditFileReader *objectEditFileReader, ISAR_SPLIT_REND_BITS_DATA *splitRendBits, IVAS_DEC_HANDLE *phIvasDec, int16_t *pcmBuf ); +#else static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtf, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ObjectEditFileReader *objectEditFileReader, ISAR_SPLIT_REND_BITS_DATA *splitRendBits, IVAS_RENDER_CONFIG_DATA *renderConfig, IVAS_DEC_HANDLE *phIvasDec, int16_t *pcmBuf ); +#endif static ivas_error load_hrtf_from_file( IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtfBinary, IVAS_DEC_HANDLE hIvasDec, const IVAS_AUDIO_CONFIG OutputConfig, const int32_t output_Fs ); #ifdef DEBUGGING static ivas_error printBitstreamInfoVoip( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HANDLE hIvasDec ); static int16_t app_own_random( int16_t *seed ); #endif static void do_object_editing( IVAS_EDITABLE_PARAMETERS *editableParameters, ObjectEditFileReader *objectEditFileReader ); +#ifdef FIX_FMSW_DEC +static ivas_error restartDecoder( IVAS_DEC_HANDLE *phIvasDec, const IVAS_DEC_MODE decMode, DecArguments *arg ); +#else static ivas_error restartDecoder( IVAS_DEC_HANDLE *phIvasDec, const IVAS_DEC_MODE decMode, DecArguments *arg, IVAS_RENDER_CONFIG_DATA *renderConfig, IVAS_CUSTOM_LS_DATA *hLsCustomData ); +#endif /*------------------------------------------------------------------------------------------* @@ -775,7 +783,11 @@ int main( if ( arg.voipMode ) { +#ifdef FIX_FMSW_DEC + error = decodeVoIP( arg, hBsReader, &hHrtfBinary, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, objectEditFileReader, &splitRendBits, &hIvasDec, pcmBuf ); +#else error = decodeVoIP( arg, hBsReader, &hHrtfBinary, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, objectEditFileReader, &splitRendBits, &renderConfig, &hIvasDec, pcmBuf ); +#endif } else { @@ -3165,7 +3177,9 @@ static ivas_error decodeVoIP( Vector3PairFileReader *referenceVectorReader, ObjectEditFileReader *objectEditFileReader, ISAR_SPLIT_REND_BITS_DATA *splitRendBits, +#ifndef FIX_FMSW_DEC IVAS_RENDER_CONFIG_DATA *renderConfig, +#endif IVAS_DEC_HANDLE *phIvasDec, int16_t *pcmBuf ) { @@ -3357,6 +3371,9 @@ static ivas_error decodeVoIP( if ( ivasRtp.restartNeeded ) { IVAS_DEC_MODE newDecModeInPacket = ( ivasRtp.codecId == IVAS_RTP_EVS ) ? IVAS_DEC_MODE_EVS : IVAS_DEC_MODE_IVAS; +#ifdef FIX_FMSW_DEC + if ( ( error = restartDecoder( &hIvasDec, newDecModeInPacket, &arg ) ) != IVAS_ERR_OK ) +#else if ( ( error = restartDecoder( &hIvasDec, newDecModeInPacket, @@ -3364,6 +3381,7 @@ static ivas_error decodeVoIP( renderConfig, NULL /* ToDo : Provide LS Custom Data */ ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nFailed to restart decoder from %d to %d\n", arg.decMode, newDecModeInPacket ); goto cleanup; @@ -3609,6 +3627,9 @@ static ivas_error decodeVoIP( } IVAS_DEC_MODE newDecModeInPacket = ( tempBsFormat == IVAS_DEC_BS_MONO ) ? IVAS_DEC_MODE_EVS : IVAS_DEC_MODE_IVAS; +#ifdef FIX_FMSW_DEC + if ( ( error = restartDecoder( &hIvasDec, newDecModeInPacket, &arg ) ) != IVAS_ERR_OK ) +#else if ( ( error = restartDecoder( &hIvasDec, newDecModeInPacket, @@ -3616,6 +3637,7 @@ static ivas_error decodeVoIP( NULL, /* ToDo : Provide rendererConfig */ NULL /* ToDo : Provide LS Custom Data */ ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nFailed to restart decoder\n" ); goto cleanup; @@ -4318,12 +4340,18 @@ static ivas_error load_hrtf_from_file( static ivas_error restartDecoder( IVAS_DEC_HANDLE *phIvasDec, const IVAS_DEC_MODE decMode, - DecArguments *arg, + DecArguments *arg +#ifndef FIX_FMSW_DEC + , IVAS_RENDER_CONFIG_DATA *renderConfig, - IVAS_CUSTOM_LS_DATA *hLsCustomData ) + IVAS_CUSTOM_LS_DATA *hLsCustomData +#endif +) { ivas_error error = IVAS_ERR_OK; +#ifndef FIX_FMSW_DEC IVAS_DEC_HANDLE hIvasDec; +#endif if ( phIvasDec == NULL ) { @@ -4343,6 +4371,7 @@ static ivas_error restartDecoder( arg->decMode = decMode; +#ifndef FIX_FMSW_DEC hIvasDec = *phIvasDec; uint16_t aeID = arg->aeSequence.count > 0 ? arg->aeSequence.pID[0] : IVAS_DEFAULT_AEID; @@ -4405,11 +4434,12 @@ static ivas_error restartDecoder( goto cleanup; } } - +#endif return IVAS_ERR_OK; cleanup: IVAS_DEC_Close( phIvasDec ); + return error; } diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 3201fd15bdb53daef1a7643fb2d9a0f98dbe5814..358d6535afc5fdd914b1c14bccef9d12cbc74b28 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -434,7 +434,11 @@ void destroy_core_dec( ); void ivas_destroy_dec( +#ifdef FIX_FMSW_DEC + Decoder_Struct **st_ivas /* i/o: IVAS decoder structure */ +#else Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#endif ); void ivas_initialize_handles_dec( diff --git a/lib_com/options.h b/lib_com/options.h index bbea3aa1534059d14c1f9b80304d8ebe81ea7d42..a44133370901ba18364e59d1f888fe56e5e2c3eb 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -169,6 +169,7 @@ /* any switch which is non-be wrt. TS 26.258 V3.0 */ #define FIX_1543_MID_LSF_BITS /* VA: float issue 1543: Resolve "MSAN: use-of-uninitialized-value in lib_enc/lsf_enc.c:262:5 for EVS encoder" */ +#define FIX_FMSW_DEC /* float issue 1542: fix JBM issue in format switching */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index b16a3160419d38c48b3543873cb459e3c23f222c..afbc724581c85b9237b75e8a044fade5296b285c 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1277,7 +1277,11 @@ ivas_error ivas_init_decoder_front( * Allocate and initialize Custom loudspeaker layout handle *--------------------------------------------------------------------*/ +#ifdef FIX_FMSW_DEC + if ( st_ivas->hDecoderConfig->Opt_LsCustom && st_ivas->hLsSetupCustom == NULL ) +#else if ( st_ivas->hDecoderConfig->Opt_LsCustom ) +#endif { if ( ( error = ivas_ls_custom_open( &( st_ivas->hLsSetupCustom ) ) ) != IVAS_ERR_OK ) { @@ -1289,7 +1293,11 @@ ivas_error ivas_init_decoder_front( * Allocate and initialize Head-Tracking handle *--------------------------------------------------------------------*/ +#ifdef FIX_FMSW_DEC + if ( st_ivas->hDecoderConfig->Opt_Headrotation && st_ivas->hHeadTrackData == NULL ) +#else if ( st_ivas->hDecoderConfig->Opt_Headrotation ) +#endif { if ( ( error = ivas_headTrack_open( &( st_ivas->hHeadTrackData ) ) ) != IVAS_ERR_OK ) { @@ -1305,7 +1313,11 @@ ivas_error ivas_init_decoder_front( * Allocate and initialize external orientation handle *--------------------------------------------------------------------*/ +#ifdef FIX_FMSW_DEC + if ( st_ivas->hDecoderConfig->Opt_ExternalOrientation && st_ivas->hExtOrientationData == NULL ) +#else if ( st_ivas->hDecoderConfig->Opt_ExternalOrientation ) +#endif { if ( ( error = ivas_external_orientation_open( &( st_ivas->hExtOrientationData ), st_ivas->hDecoderConfig->render_num_subframes ) ) != IVAS_ERR_OK ) { @@ -1317,7 +1329,11 @@ ivas_error ivas_init_decoder_front( * Allocate and initialize combined orientation handle *--------------------------------------------------------------------*/ +#ifdef FIX_FMSW_DEC + if ( ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) && st_ivas->hCombinedOrientationData == NULL ) +#else if ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) +#endif { if ( ( error = ivas_combined_orientation_open( &( st_ivas->hCombinedOrientationData ), st_ivas->hDecoderConfig->output_Fs, st_ivas->hDecoderConfig->render_num_subframes ) ) != IVAS_ERR_OK ) { @@ -1329,8 +1345,14 @@ ivas_error ivas_init_decoder_front( * Allocate and initialize Binaural Renderer configuration handle *--------------------------------------------------------------------*/ +#ifdef FIX_FMSW_DEC + if ( ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM || + ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO && st_ivas->hDecoderConfig->Opt_non_diegetic_pan ) ) && + st_ivas->hRenderConfig == NULL ) +#else if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM || ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO && st_ivas->hDecoderConfig->Opt_non_diegetic_pan ) ) +#endif { if ( ( error = ivas_render_config_open( &( st_ivas->hRenderConfig ) ) ) != IVAS_ERR_OK ) { @@ -2739,9 +2761,16 @@ void ivas_initialize_handles_dec( st_ivas->hCPE[i] = NULL; } - st_ivas->bit_stream = NULL; - st_ivas->mem_hp20_out = NULL; - st_ivas->hLimiter = NULL; +#ifdef FIX_FMSW_DEC + if ( st_ivas->restartNeeded == 0 ) + { +#endif + st_ivas->bit_stream = NULL; + st_ivas->mem_hp20_out = NULL; + st_ivas->hLimiter = NULL; +#ifdef FIX_FMSW_DEC + } +#endif /* ISM metadata handles */ for ( i = 0; i < MAX_NUM_OBJECTS; i++ ) @@ -2784,14 +2813,21 @@ void ivas_initialize_handles_dec( st_ivas->hMasaIsmData = NULL; st_ivas->hSbaIsmData = NULL; - st_ivas->hHeadTrackData = NULL; - st_ivas->hHrtfTD = NULL; - st_ivas->hLsSetupCustom = NULL; - st_ivas->hRenderConfig = NULL; - st_ivas->hExtOrientationData = NULL; - st_ivas->hCombinedOrientationData = NULL; - st_ivas->acousticEnvironmentsCount = 0; - st_ivas->pAcousticEnvironments = NULL; +#ifdef FIX_FMSW_DEC + if ( st_ivas->restartNeeded == 0 ) + { +#endif + st_ivas->hHeadTrackData = NULL; + st_ivas->hHrtfTD = NULL; + st_ivas->hLsSetupCustom = NULL; + st_ivas->hRenderConfig = NULL; + st_ivas->hExtOrientationData = NULL; + st_ivas->hCombinedOrientationData = NULL; + st_ivas->acousticEnvironmentsCount = 0; + st_ivas->pAcousticEnvironments = NULL; +#ifdef FIX_FMSW_DEC + } +#endif st_ivas->hSplitBinRend = NULL; for ( i = 0; i < MAX_HEAD_ROT_POSES - 1; ++i ) @@ -2819,10 +2855,17 @@ void ivas_initialize_handles_dec( *-------------------------------------------------------------------------*/ void ivas_destroy_dec( +#ifdef FIX_FMSW_DEC + Decoder_Struct **st_ivas_out /* i/o: IVAS decoder handle */ +#else Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ +#endif ) { int16_t i; +#ifdef FIX_FMSW_DEC + Decoder_Struct *st_ivas = *st_ivas_out; +#endif /* CLDFB handles */ for ( i = 0; i < MAX_INTERN_CHANNELS; i++ ) @@ -2867,17 +2910,24 @@ void ivas_destroy_dec( } } - /* HP20 filter handles */ - if ( st_ivas->mem_hp20_out != NULL ) +#ifdef FIX_FMSW_DEC + if ( st_ivas->restartNeeded == 0 ) { - for ( i = 0; i < getNumChanSynthesis( st_ivas ); i++ ) +#endif + /* HP20 filter handles */ + if ( st_ivas->mem_hp20_out != NULL ) { - free( st_ivas->mem_hp20_out[i] ); - st_ivas->mem_hp20_out[i] = NULL; + for ( i = 0; i < getNumChanSynthesis( st_ivas ); i++ ) + { + free( st_ivas->mem_hp20_out[i] ); + st_ivas->mem_hp20_out[i] = NULL; + } + free( st_ivas->mem_hp20_out ); + st_ivas->mem_hp20_out = NULL; } - free( st_ivas->mem_hp20_out ); - st_ivas->mem_hp20_out = NULL; +#ifdef FIX_FMSW_DEC } +#endif /* ISM metadata handles */ ivas_ism_metadata_close( st_ivas->hIsmMetaData, 0 ); @@ -2952,12 +3002,19 @@ void ivas_destroy_dec( /* LS config converter handle */ ivas_ls_setup_conversion_close( &st_ivas->hLsSetUpConversion ); - /* Custom LS configuration handle */ - if ( st_ivas->hLsSetupCustom != NULL ) +#ifdef FIX_FMSW_DEC + if ( st_ivas->restartNeeded == 0 ) { - free( st_ivas->hLsSetupCustom ); - st_ivas->hLsSetupCustom = NULL; +#endif + /* Custom LS configuration handle */ + if ( st_ivas->hLsSetupCustom != NULL ) + { + free( st_ivas->hLsSetupCustom ); + st_ivas->hLsSetupCustom = NULL; + } +#ifdef FIX_FMSW_DEC } +#endif /* Mono downmix structure */ ivas_mono_dmx_renderer_close( &st_ivas->hMonoDmxRenderer ); @@ -2994,25 +3051,40 @@ void ivas_destroy_dec( /* HRTF statistics */ ivas_HRTF_statistics_binary_close( &st_ivas->hHrtfStatistics ); - /* Config. Renderer */ - ivas_render_config_close( &( st_ivas->hRenderConfig ) ); - - /* Acoustic environments */ - if ( st_ivas->pAcousticEnvironments != NULL ) +#ifdef FIX_FMSW_DEC + if ( st_ivas->restartNeeded == 0 ) { - free( st_ivas->pAcousticEnvironments ); - st_ivas->pAcousticEnvironments = NULL; - } +#endif + /* Config. Renderer */ + ivas_render_config_close( &( st_ivas->hRenderConfig ) ); - /* Limiter struct */ - ivas_limiter_close( &( st_ivas->hLimiter ) ); + /* Acoustic environments */ + if ( st_ivas->pAcousticEnvironments != NULL ) + { + free( st_ivas->pAcousticEnvironments ); + st_ivas->pAcousticEnvironments = NULL; + } + + /* Limiter struct */ + ivas_limiter_close( &( st_ivas->hLimiter ) ); - /* Decoder configuration structure */ - if ( st_ivas->hDecoderConfig != NULL ) + /* Decoder configuration structure */ + if ( st_ivas->hDecoderConfig != NULL ) + { + free( st_ivas->hDecoderConfig ); + st_ivas->hDecoderConfig = NULL; + } +#ifdef FIX_FMSW_DEC + } + else { - free( st_ivas->hDecoderConfig ); - st_ivas->hDecoderConfig = NULL; + /* resets in case of format switching */ + st_ivas->nchan_ism = 0; + st_ivas->ism_mode = ISM_MODE_NONE; + st_ivas->mc_mode = MC_MODE_NONE; + st_ivas->sba_dirac_stereo_flag = 0; } +#endif /* TC buffer structure */ ivas_dec_tc_buffer_close( &st_ivas->hTcBuffer ); @@ -3030,7 +3102,15 @@ void ivas_destroy_dec( } /* main IVAS handle */ +#ifdef FIX_FMSW_DEC + if ( st_ivas->restartNeeded == 0 ) + { + free( *st_ivas_out ); + *st_ivas_out = NULL; + } +#else free( st_ivas ); +#endif return; } diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 0afec7310f1d418fba7b53751caff22a671d131a..7ba049791e91b1d7ef04456fc1116628c01efaf8 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -150,68 +150,83 @@ ivas_error IVAS_DEC_Open( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - /*-----------------------------------------------------------------* - * Allocate and initialize IVAS application decoder handle - *-----------------------------------------------------------------*/ - - if ( ( *phIvasDec = (IVAS_DEC_HANDLE) malloc( sizeof( struct IVAS_DEC ) ) ) == NULL ) +#ifdef FIX_FMSW_DEC + if ( ( *phIvasDec ) != NULL && ( *phIvasDec )->st_ivas != NULL && ( *phIvasDec )->st_ivas->restartNeeded != 0 ) { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS decoder handle" ); + hIvasDec = *phIvasDec; + + st_ivas = hIvasDec->st_ivas; } + else + { +#endif + /*-----------------------------------------------------------------* + * Allocate and initialize IVAS application decoder handle + *-----------------------------------------------------------------*/ - hIvasDec = *phIvasDec; - hIvasDec->hVoIP = NULL; - hIvasDec->hTimeScaler = NULL; - hIvasDec->tsm_scale = 100; - hIvasDec->tsm_max_scaling = 0; - hIvasDec->tsm_quality = 1.0f; - hIvasDec->timeScalingDone = 0; - hIvasDec->needNewFrame = false; - hIvasDec->nTransportChannelsOld = 0; - hIvasDec->nSamplesAvailableNext = 0; - hIvasDec->nSamplesFrame = 0; - hIvasDec->hasBeenFedFrame = false; - hIvasDec->hasBeenFedFirstGoodFrame = false; - hIvasDec->hasDecodedFirstGoodFrame = false; - hIvasDec->isInitialized = false; - hIvasDec->updateOrientation = false; - hIvasDec->flushbuffer = NULL; - hIvasDec->pcmType = IVAS_DEC_PCM_INVALID; - hIvasDec->nSamplesFlushed = 0; - hIvasDec->hasBeenPreparedRendering = false; + if ( ( *phIvasDec = (IVAS_DEC_HANDLE) malloc( sizeof( struct IVAS_DEC ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS decoder handle" ); + } - hIvasDec->mode = mode; + hIvasDec = *phIvasDec; + hIvasDec->hVoIP = NULL; + hIvasDec->hTimeScaler = NULL; + hIvasDec->tsm_scale = 100; + hIvasDec->tsm_max_scaling = 0; + hIvasDec->tsm_quality = 1.0f; + hIvasDec->timeScalingDone = 0; + hIvasDec->needNewFrame = false; + hIvasDec->nTransportChannelsOld = 0; + hIvasDec->nSamplesAvailableNext = 0; + hIvasDec->nSamplesFrame = 0; + hIvasDec->hasBeenFedFrame = false; + hIvasDec->hasBeenFedFirstGoodFrame = false; + hIvasDec->hasDecodedFirstGoodFrame = false; + hIvasDec->isInitialized = false; + hIvasDec->updateOrientation = false; + hIvasDec->flushbuffer = NULL; + hIvasDec->pcmType = IVAS_DEC_PCM_INVALID; + hIvasDec->nSamplesFlushed = 0; + hIvasDec->hasBeenPreparedRendering = false; - hIvasDec->bitstreamformat = G192; + hIvasDec->mode = mode; + + hIvasDec->bitstreamformat = G192; #ifdef DEBUGGING - hIvasDec->Opt_VOIP = 0; + hIvasDec->Opt_VOIP = 0; #endif - 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*/ + 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 - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Initialize IVAS-codec decoder state + *-----------------------------------------------------------------*/ - if ( ( hIvasDec->st_ivas = (Decoder_Struct *) malloc( sizeof( Decoder_Struct ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS decoder structure" ); - } + if ( ( hIvasDec->st_ivas = (Decoder_Struct *) malloc( sizeof( Decoder_Struct ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS decoder structure" ); + } - if ( ( hIvasDec->st_ivas->hDecoderConfig = (DECODER_CONFIG_HANDLE) malloc( sizeof( DECODER_CONFIG ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for Decoder config structure" ); - } + if ( ( hIvasDec->st_ivas->hDecoderConfig = (DECODER_CONFIG_HANDLE) malloc( sizeof( DECODER_CONFIG ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for Decoder config structure" ); + } - /*-----------------------------------------------------------------* - * Initialize IVAS-codec decoder state - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Initialize IVAS-codec decoder state + *-----------------------------------------------------------------*/ - st_ivas = hIvasDec->st_ivas; + st_ivas = hIvasDec->st_ivas; - /* initialize Decoder Config. handle */ - init_decoder_config( hIvasDec->st_ivas->hDecoderConfig ); + /* initialize Decoder Config. handle */ + init_decoder_config( hIvasDec->st_ivas->hDecoderConfig ); + +#ifdef FIX_FMSW_DEC + hIvasDec->st_ivas->restartNeeded = 0; + } +#endif /* initialize pointers to handles to NULL */ ivas_initialize_handles_dec( st_ivas ); @@ -336,7 +351,11 @@ void IVAS_DEC_Close( return; } +#ifdef FIX_FMSW_DEC + if ( ( *phIvasDec )->st_ivas->restartNeeded == 0 && ( *phIvasDec )->hVoIP ) +#else if ( ( *phIvasDec )->hVoIP ) +#endif { ivas_destroy_handle_VoIP( ( *phIvasDec )->hVoIP ); ( *phIvasDec )->hVoIP = NULL; @@ -348,20 +367,38 @@ void IVAS_DEC_Close( ivas_destroy_handle_isar( &( *phIvasDec )->st_ivas->hSplitBinRend ); /* destroy IVAS decoder handles */ +#ifdef FIX_FMSW_DEC + ivas_destroy_dec( &( *phIvasDec )->st_ivas ); +#else ivas_destroy_dec( ( *phIvasDec )->st_ivas ); - ( *phIvasDec )->st_ivas = NULL; +#ifdef FIX_FMSW_DEC + if ( ( *phIvasDec )->st_ivas->restartNeeded == 0 ) + { +#endif + ( *phIvasDec )->st_ivas = NULL; +#ifdef FIX_FMSW_DEC + } +#endif +#endif } - apa_exit( &( *phIvasDec )->hTimeScaler ); - - if ( ( *phIvasDec )->flushbuffer != NULL ) +#ifdef FIX_FMSW_DEC + if ( ( *phIvasDec )->st_ivas == NULL || ( *phIvasDec )->st_ivas->restartNeeded == 0 ) { - free( ( *phIvasDec )->flushbuffer ); - } +#endif + apa_exit( &( *phIvasDec )->hTimeScaler ); + + if ( ( *phIvasDec )->flushbuffer != NULL ) + { + free( ( *phIvasDec )->flushbuffer ); + } - free( *phIvasDec ); - *phIvasDec = NULL; - phIvasDec = NULL; + free( *phIvasDec ); + *phIvasDec = NULL; + phIvasDec = NULL; +#ifdef FIX_FMSW_DEC + } +#endif return; } diff --git a/lib_util/ivas_rtp_api.h b/lib_util/ivas_rtp_api.h index 6b23bd04e8ba77475d919976aa83b48da5988eec..0b2731ed39dce0a037b4589695abfebf4348db95 100644 --- a/lib_util/ivas_rtp_api.h +++ b/lib_util/ivas_rtp_api.h @@ -82,6 +82,9 @@ /* IVAS Codec Types */ typedef enum { +#ifdef FIX_FMSW_DEC + IVAS_RTP_UNDEF, /* undefined = Codec Type not set yet */ +#endif IVAS_RTP_EVS, /* EVS */ IVAS_RTP_IVAS /* IVAS */ } IVAS_RTP_CODEC; diff --git a/lib_util/ivas_rtp_file.c b/lib_util/ivas_rtp_file.c index 35733681c0249f1e198c3db1d2b994eb125659d0..679728b924ca4536a679cd1e07c1effba95fa864 100644 --- a/lib_util/ivas_rtp_file.c +++ b/lib_util/ivas_rtp_file.c @@ -867,6 +867,9 @@ ivas_error IVAS_RTP_READER_Init( rtp->unpackCfg.maxFramesPerPacket = IVAS_MAX_FRAMES_PER_RTP_PACKET; rtp->rtpPacket.buffer = rtp->packet; rtp->rtpPacket.capacity = sizeof( rtp->packet ); +#ifdef FIX_FMSW_DEC + rtp->codecId = IVAS_RTP_UNDEF; +#endif error = IVAS_RTP_UNPACK_Open( &rtp->hUnpack, &rtp->unpackCfg ); if ( error == IVAS_ERR_OK ) @@ -1041,15 +1044,19 @@ ivas_error IVAS_RTP_ReadNextFrame( } else { +#ifdef FIX_FMSW_DEC + if ( ( codecId != IVAS_RTP_UNDEF ) && ( ( rtp->codecId != codecId ) || ( codecId == IVAS_RTP_EVS && ( rtp->isAMRWB_IOmode != isAMRWB_IOmode ) ) ) ) +#else rtp->restartNeeded = ( rtp->codecId != codecId ) || ( codecId == IVAS_RTP_EVS && ( rtp->isAMRWB_IOmode != isAMRWB_IOmode ) ); +#endif - if ( rtp->restartNeeded ) - { - fprintf( stdout, "\nRTP packet codec changed %s -> %s\n", - ( rtp->codecId == IVAS_RTP_EVS ) ? ( rtp->isAMRWB_IOmode ? "AMRWB_IO" : "EVS" ) : "IVAS", - ( codecId == IVAS_RTP_EVS ) ? ( isAMRWB_IOmode ? "AMRWB_IO" : "EVS" ) : "IVAS" ); - } + if ( rtp->restartNeeded ) + { + fprintf( stdout, "\nRTP packet codec changed %s -> %s\n", + ( rtp->codecId == IVAS_RTP_EVS ) ? ( rtp->isAMRWB_IOmode ? "AMRWB_IO" : "EVS" ) : "IVAS", + ( codecId == IVAS_RTP_EVS ) ? ( isAMRWB_IOmode ? "AMRWB_IO" : "EVS" ) : "IVAS" ); + } rtp->codecId = codecId; rtp->isAMRWB_IOmode = isAMRWB_IOmode;