From e60b504c199ead5ddc140c56f7c5b66eaea9c6f1 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 9 Apr 2026 14:28:19 +0200 Subject: [PATCH 1/4] FIX_FMSW_DEC_EXT --- apps/decoder.c | 100 +++++++++++++++++++++++++++++++++++++++++++++- lib_com/options.h | 1 + 2 files changed, 100 insertions(+), 1 deletion(-) diff --git a/apps/decoder.c b/apps/decoder.c index 3d294790b..9be928b9a 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -188,6 +188,9 @@ static int16_t app_own_random( int16_t *seed ); #endif static void do_object_editing( IVAS_EDITABLE_PARAMETERS *editableParameters, ObjectEditFileReader *objectEditFileReader ); 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 ); +#ifdef FIX_FMSW_DEC_EXT +static ivas_error updateOnFormatSwitching( IVAS_DEC_HANDLE hIvasDec, IVAS_DEC_BS_FORMAT *pBsFormat, const char *outputWavFilename, MasaFileWriter **ppMasaWriter, IsmFileWriter *ismWriters[IVAS_MAX_NUM_OBJECTS], int16_t *pNumOutChannels, uint16_t *pNumObj, const bool delayCompensationEnabled ); +#endif /*------------------------------------------------------------------------------------------* @@ -2646,7 +2649,7 @@ static ivas_error decodeG192( fprintf( stderr, "\nFailed to restart decoder\n" ); goto cleanup; } - *phIvasDec = hIvasDec; /* Update for main()' s free */ + *phIvasDec = hIvasDec; /* Update for main()' s free */ } #endif @@ -3256,7 +3259,11 @@ static ivas_error decodeVoIP( int16_t i; IVAS_DEC_HANDLE hIvasDec = *phIvasDec; +#ifdef FIX_FMSW_DEC_EXT + bool restartNeeded = false; +#else bool restartNeeded; +#endif IVAS_RTP ivasRtp = { 0 }; IVAS_RTP srRtp = { 0 }; IVAS_RTP_SR_INFO srInfo = { true, false, 0, 20, IVAS_SR_TRANSPORT_LCLD }; @@ -3762,6 +3769,18 @@ static ivas_error decodeVoIP( } } +#ifdef FIX_FMSW_DEC_EXT + /* Output writing update in case of format switching and EXTERNAL output */ + if ( restartNeeded && arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL ) + { + if ( ( error = updateOnFormatSwitching( hIvasDec, &bsFormat, arg.outputWavFilename, &masaWriter, ismWriters, &nOutChannels, &numObj, arg.delayCompensationEnabled ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Error in updateOnFormatSwitching(): %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + } +#endif + /* Write current frame */ if ( !srRtp.hPack && decodedGoodFrame ) { @@ -4365,6 +4384,85 @@ static ivas_error load_hrtf_from_file( } +#ifdef FIX_FMSW_DEC_EXT +/*---------------------------------------------------------------------* + * restartDecoder() + * + * Update decoder in case of IVAS format switching and EXTERNAL output + *---------------------------------------------------------------------*/ + +static ivas_error updateOnFormatSwitching( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + IVAS_DEC_BS_FORMAT *pBsFormat, /* o : format of currently decoded bitstream */ + const char *outputWavFilename, /* i : name of the output audio file */ + MasaFileWriter **ppMasaWriter, /* o : MasaFileWriter handle */ + IsmFileWriter *ismWriters[IVAS_MAX_NUM_OBJECTS], /* o : 1-4 ismWriters handles */ + int16_t *pNumOutChannels, /* o : number of output channels */ + uint16_t *pNumObj, /* o : number of ISM objects */ + const bool delayCompensationEnabled /* i : is delay compensation enabled */ +) +{ + ivas_error error; + + if ( hIvasDec == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + /* in case of EXT output, the number of output audio channels can change */ + if ( ( error = IVAS_DEC_GetNumOutputChannels( hIvasDec, pNumOutChannels ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in IVAS_DEC_GetNumOutputChannels, code: %d\n", error ); + return error; + } + + /* Get the format of currently decoded bitstream */ + if ( ( error = IVAS_DEC_GetFormat( hIvasDec, pBsFormat ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in IVAS_DEC_GetFormat, code: %d\n", error ); + return error; + } + + *pNumObj = 0; + if ( *pBsFormat == IVAS_DEC_BS_OBJ || *pBsFormat == IVAS_DEC_BS_MASA_ISM || *pBsFormat == IVAS_DEC_BS_SBA_ISM ) + { + if ( ( error = IVAS_DEC_GetNumObjects( hIvasDec, pNumObj ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in IVAS_DEC_GetNumObjects: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + return error; + } + + /* If outputting ISM/OMASA/OSBA, ensure the output metadata files are opened */ + for ( int16_t i = 0; i < *pNumObj; ++i ) + { + if ( ismWriters[i] == NULL ) + { + if ( ( error = IsmFileWriter_open( outputWavFilename, i, &ismWriters[i] ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError: Error opening ISM decoded metadata file %s\n", IsmFileWriter_getFilePath( ismWriters[i] ) ); + return error; + } + } + } + } + + /* If outputting MASA, ensure the output file metadata is opened */ + if ( *pBsFormat == IVAS_DEC_BS_MASA || *pBsFormat == IVAS_DEC_BS_MASA_ISM ) + { + if ( ppMasaWriter != NULL ) + { + if ( ( error = MasaFileWriter_open( outputWavFilename, delayCompensationEnabled, ppMasaWriter ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError: Error opening MASA decoded metadata file %s\n", MasaFileWriter_getFilePath( *ppMasaWriter ) ); + return error; + } + } + } + + return IVAS_ERR_OK; +} +#endif + /*---------------------------------------------------------------------* * restartDecoder() * diff --git a/lib_com/options.h b/lib_com/options.h index c5197b92a..c8bb88ad6 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -178,6 +178,7 @@ #define FIX_1540_EXPOSE_PT_IN_RTP_HEADER_API /* Expose Payload Type setting in RTP Header */ #define FIX_1563_FIX_STEREO_SW /* VA: float issue 1563: fix clicks in stereo switching */ #define FIX_1562_DTX_CRASH_DECODER /* VA: float issue 1562: fix crash in stereo decoding in DTX and bitrate switching */ +#define FIX_FMSW_DEC_EXT /* float issue 1566: fix EXT output in format switching */ /* ##################### End NON-BE switches ########################### */ -- GitLab From 8dc1f0ac9686481fb54a9fb2b376b8904557a1b0 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 9 Apr 2026 14:30:03 +0200 Subject: [PATCH 2/4] comment --- apps/decoder.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 9be928b9a..ae65595c9 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -4386,9 +4386,10 @@ static ivas_error load_hrtf_from_file( #ifdef FIX_FMSW_DEC_EXT /*---------------------------------------------------------------------* - * restartDecoder() + * updateOnFormatSwitching() * - * Update decoder in case of IVAS format switching and EXTERNAL output + * In case of IVAS format switching and EXTERNAL output, + * update decoder wrt. output writing *---------------------------------------------------------------------*/ static ivas_error updateOnFormatSwitching( @@ -4404,11 +4405,6 @@ static ivas_error updateOnFormatSwitching( { ivas_error error; - if ( hIvasDec == NULL ) - { - return IVAS_ERR_UNEXPECTED_NULL_POINTER; - } - /* in case of EXT output, the number of output audio channels can change */ if ( ( error = IVAS_DEC_GetNumOutputChannels( hIvasDec, pNumOutChannels ) ) != IVAS_ERR_OK ) { -- GitLab From e15fd381e9a7d0c1e1c29a0ca62608aadb961c7a Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 9 Apr 2026 14:37:34 +0200 Subject: [PATCH 3/4] clang-format --- apps/decoder.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index ae65595c9..e19c7ce28 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -2649,7 +2649,7 @@ static ivas_error decodeG192( fprintf( stderr, "\nFailed to restart decoder\n" ); goto cleanup; } - *phIvasDec = hIvasDec; /* Update for main()' s free */ + *phIvasDec = hIvasDec; /* Update for main()' s free */ } #endif @@ -4388,7 +4388,7 @@ static ivas_error load_hrtf_from_file( /*---------------------------------------------------------------------* * updateOnFormatSwitching() * - * In case of IVAS format switching and EXTERNAL output, + * In case of IVAS format switching and EXTERNAL output, * update decoder wrt. output writing *---------------------------------------------------------------------*/ -- GitLab From 2ece6fccdd1282eda1100152e821c92407fe0ed5 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 13 Apr 2026 10:47:38 +0200 Subject: [PATCH 4/4] add updateOnFormatSwitching(0 to G.192 path --- apps/decoder.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/apps/decoder.c b/apps/decoder.c index e19c7ce28..45375f38e 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -2289,8 +2289,12 @@ static ivas_error decodeG192( SplitFileReadWrite *splitRendWriter = NULL; int16_t isSplitRend, isSplitCoded; #ifdef FIX_FLOAT_1539_G192_FORMAT_SWITCH +#ifdef FIX_FMSW_DEC_EXT + bool restartNeeded = false; +#else bool restartNeeded; #endif +#endif #ifdef VARIABLE_SPEED_DECODING if ( arg.tsmEnabled ) @@ -2777,6 +2781,18 @@ static ivas_error decodeG192( } } +#ifdef FIX_FMSW_DEC_EXT + /* Output writing update in case of format switching and EXTERNAL output */ + if ( restartNeeded && arg.outputConfig == IVAS_AUDIO_CONFIG_EXTERNAL ) + { + if ( ( error = updateOnFormatSwitching( hIvasDec, &bsFormat, arg.outputWavFilename, &masaWriter, ismWriters, &nOutChannels, &numObj, arg.delayCompensationEnabled ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Error in updateOnFormatSwitching(): %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + } +#endif + /* Write current frame */ if ( decodedGoodFrame ) { -- GitLab