diff --git a/CMakeLists.txt b/CMakeLists.txt index bae6fa624ebf843f67e5bad98d09961d4465519c..7beb46c45129b2cae7d076830f99cae494e417ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -192,6 +192,12 @@ if(WIN32) target_link_libraries(IVAS_cod Ws2_32) endif() +add_executable(IVAS_cod_fmtsw apps/encoder_fmtsw.c) +target_link_libraries(IVAS_cod_fmtsw lib_enc lib_util) +if(WIN32) + target_link_libraries(IVAS_cod_fmtsw Ws2_32) +endif() + add_executable(IVAS_dec apps/decoder.c) target_link_libraries(IVAS_dec lib_dec lib_util) if(WIN32) @@ -216,6 +222,7 @@ target_include_directories(ambi_converter PRIVATE lib_util) if(COPY_EXECUTABLES_FROM_BUILD_DIR) # Optionally copy executables to the same place where Make puts them (useful for tests that expect executables in specific places) add_custom_command(TARGET IVAS_cod POST_BUILD VERBATIM COMMAND "${CMAKE_COMMAND}" -E copy "$" "${CMAKE_CURRENT_SOURCE_DIR}/") + add_custom_command(TARGET IVAS_cod_fmtsw POST_BUILD VERBATIM COMMAND "${CMAKE_COMMAND}" -E copy "$" "${CMAKE_CURRENT_SOURCE_DIR}/") add_custom_command(TARGET IVAS_dec POST_BUILD VERBATIM COMMAND "${CMAKE_COMMAND}" -E copy "$" "${CMAKE_CURRENT_SOURCE_DIR}/") add_custom_command(TARGET IVAS_rend POST_BUILD VERBATIM COMMAND "${CMAKE_COMMAND}" -E copy "$" "${CMAKE_CURRENT_SOURCE_DIR}/") add_custom_command(TARGET ISAR_post_rend POST_BUILD VERBATIM COMMAND "${CMAKE_COMMAND}" -E copy "$" "${CMAKE_CURRENT_SOURCE_DIR}/") diff --git a/Makefile b/Makefile index c72aaacd8dbf36dbf8bc00552745d666a442b100..fa132c65572cc4f7438b7d6db75af7687badb5d1 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ SRC_DIRS = $(sort -u $(SRC_LIBCOM) $(SRC_LIBDEBUG) $(SRC_LIBDEC) $(SRC_LIBENC) # Name of CLI binaries CLI_APIDEC ?= IVAS_dec CLI_APIENC ?= IVAS_cod +CLI_APIENC_FMTSW ?= IVAS_cod_fmtsw CLI_APIREND ?= IVAS_rend CLI_APIPOSTREND ?= ISAR_post_rend CLI_AMBICONVERT ?= ambi_converter @@ -154,6 +155,7 @@ OBJS_LIBUTIL = $(addprefix $(OBJDIR)/,$(SRCS_LIBUTIL:.c=.o)) OBJS_AMBICONVERT = $(OBJDIR)/ambi_convert.o OBJS_CLI_APIDEC = $(OBJDIR)/decoder.o OBJS_CLI_APIENC = $(OBJDIR)/encoder.o +OBJS_CLI_APIENC_FMTSW = $(OBJDIR)/encoder_fmtsw.o OBJS_CLI_APPREND = $(OBJDIR)/renderer.o OBJS_CLI_APPPOSTREND = $(OBJDIR)/isar_post_rend.o OBJS_CLI_AMBICONVERT = $(OBJDIR)/ambi_converter.o @@ -166,7 +168,7 @@ DEPS = $(addprefix $(OBJDIR)/,$(SRCS_LIBCOM:.c=.P) $(SRCS_LIBDEBUG:.c=.P) $(SRCS .PHONY: all clean -all: $(CLI_APIENC) $(CLI_APIDEC) $(CLI_APIREND) $(CLI_APIPOSTREND) +all: $(CLI_APIENC) $(CLI_APIENC_FMTSW) $(CLI_APIDEC) $(CLI_APIREND) $(CLI_APIPOSTREND) $(OBJDIR): $(QUIET)mkdir -p $(OBJDIR) @@ -198,6 +200,9 @@ $(LIB_LIBUTIL): $(OBJS_LIBUTIL) $(CLI_APIENC): $(OBJS_CLI_APIENC) $(LIB_LIBENC) $(LIB_LIBCOM) $(LIB_LIBUTIL) $(LIB_LIBDEBUG) $(LIB_LC3PLUS) $(QUIET_LINK)$(CC) $(LDFLAGS) $(OBJS_CLI_APIENC) -L. -livasenc -livascom -livasutil -livasdebug $(LDLIBS) -o $(CLI_APIENC) +$(CLI_APIENC_FMTSW): $(OBJS_CLI_APIENC_FMTSW) $(LIB_LIBENC) $(LIB_LIBCOM) $(LIB_LIBUTIL) $(LIB_LIBDEBUG) $(LIB_LC3PLUS) + $(QUIET_LINK)$(CC) $(LDFLAGS) $(OBJS_CLI_APIENC_FMTSW) -L. -livasenc -livascom -livasutil -livasdebug $(LDLIBS) -o $(CLI_APIENC_FMTSW) + $(CLI_APIDEC): $(OBJS_CLI_APIDEC) $(LIB_LIBDEC) $(LIB_LIBCOM) $(LIB_LIBUTIL) $(LIB_LIBDEBUG) $(LIB_LC3PLUS) $(LIB_LIBISAR) $(QUIET_LINK)$(CC) $(LDFLAGS) $(OBJS_CLI_APIDEC) -L. -livasdec -livascom -livasutil -livasdebug -llc3plus $(LDLIBS) -o $(CLI_APIDEC) @@ -216,7 +221,7 @@ clean: $(QUIET)$(RM) $(OBJS_LIBENC) $(OBJS_LIBDEC) $(DEPS) $(QUIET)$(RM) $(DEPS:.P=.d) $(QUIET)test ! -d $(OBJDIR) || rm -rf $(OBJDIR) - $(QUIET)$(RM) $(CLI_APIENC) $(CLI_APIDEC) $(CLI_APIREND) $(CLI_APIPOSTREND) $(CLI_AMBICONVERT) $(LIB_LIBENC) $(LIB_LIBDEBUG) $(LIB_LIBCOM) $(LIB_LIBDEC) $(LIB_LIBUTIL) $(LIB_LIBREND) $(LIB_LIBISAR) $(LIB_LC3PLUS) + $(QUIET)$(RM) $(CLI_APIENC) $(CLI_APIENC_FMTSW) $(CLI_APIDEC) $(CLI_APIREND) $(CLI_APIPOSTREND) $(CLI_AMBICONVERT) $(LIB_LIBENC) $(LIB_LIBDEBUG) $(LIB_LIBCOM) $(LIB_LIBDEC) $(LIB_LIBUTIL) $(LIB_LIBREND) $(LIB_LIBISAR) $(LIB_LC3PLUS) $(OBJDIR)/%.o : %.c | $(OBJDIR) $(QUIET_CC)$(CC) $(CFLAGS) -c -MD -o $@ $< diff --git a/Workspace_msvc/Workspace_msvc.sln b/Workspace_msvc/Workspace_msvc.sln index 6a38a0e4304fea3680886ea0b2080bfd04630b34..b87f6c936635bc81342decbd647f7d9ca000c8ec 100644 --- a/Workspace_msvc/Workspace_msvc.sln +++ b/Workspace_msvc/Workspace_msvc.sln @@ -18,6 +18,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "decoder", "decoder.vcxproj" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "encoder", "encoder.vcxproj", "{B3FC9DFC-7268-8660-7C0D-B60BAF02C554}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "encoder_fmtsw", "encoder_fmtsw.vcxproj", "{CA7EA15E-09A4-4196-A8EA-2A5F6F84862B}" +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "renderer", "renderer.vcxproj", "{12B4C8A5-1E06-4E30-B443-D1F916F52B47}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lib_lc3plus", "lib_lc3plus.vcxproj", "{95030B82-70CD-4C6B-84D4-61096035BEA2}" @@ -89,6 +91,12 @@ Global {B3FC9DFC-7268-8660-7C0D-B60BAF02C554}.Release|Win32.ActiveCfg = Release|Win32 {B3FC9DFC-7268-8660-7C0D-B60BAF02C554}.Release|Win32.Build.0 = Release|Win32 {B3FC9DFC-7268-8660-7C0D-B60BAF02C554}.Release|x64.ActiveCfg = Release|Win32 + {CA7EA15E-09A4-4196-A8EA-2A5F6F84862B}.Debug|Win32.ActiveCfg = Debug|Win32 + {CA7EA15E-09A4-4196-A8EA-2A5F6F84862B}.Debug|Win32.Build.0 = Debug|Win32 + {CA7EA15E-09A4-4196-A8EA-2A5F6F84862B}.Debug|x64.ActiveCfg = Debug|Win32 + {CA7EA15E-09A4-4196-A8EA-2A5F6F84862B}.Release|Win32.ActiveCfg = Release|Win32 + {CA7EA15E-09A4-4196-A8EA-2A5F6F84862B}.Release|Win32.Build.0 = Release|Win32 + {CA7EA15E-09A4-4196-A8EA-2A5F6F84862B}.Release|x64.ActiveCfg = Release|Win32 {12B4C8A5-1E06-4E30-B443-D1F916F52B47}.Debug|Win32.ActiveCfg = Debug|Win32 {12B4C8A5-1E06-4E30-B443-D1F916F52B47}.Debug|Win32.Build.0 = Debug|Win32 {12B4C8A5-1E06-4E30-B443-D1F916F52B47}.Debug|x64.ActiveCfg = Debug|Win32 diff --git a/Workspace_msvc/encoder_fmtsw.vcxproj b/Workspace_msvc/encoder_fmtsw.vcxproj new file mode 100644 index 0000000000000000000000000000000000000000..c3a81b18f366001d4c8f6e4467230ea6ccd47400 --- /dev/null +++ b/Workspace_msvc/encoder_fmtsw.vcxproj @@ -0,0 +1,180 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + encoder_fmtsw + {CA7EA15E-09A4-4196-A8EA-2A5F6F84862B} + encoder_fmtsw + 10.0.17763.0 + + + + Application + v141 + false + MultiByte + + + Application + v141 + false + MultiByte + + + + + + + + + + + + + + + <_ProjectFileVersion>15.0.27428.2015 + + + ..\ + .\Debug_$(ProjectName)\ + false + false + IVAS_cod_fmtsw + + + ..\ + .\Release_$(ProjectName)\ + false + false + IVAS_cod_fmtsw + + + + + + + $(IntDir)$(ProjectName).tlb + + + + Disabled + ..\lib_enc;..\lib_com;..\lib_util;..\lib_debug;%(AdditionalIncludeDirectories) + _CRT_SECURE_NO_WARNINGS;WIN32;$(Macros);%(PreprocessorDefinitions) + + EnableFastChecks + MultiThreadedDebug + false + + + $(IntDir)$(ProjectName).pdb + Level4 + true + OldStyle + Default + %(DisableSpecificWarnings) + false + + + _DEBUG;%(PreprocessorDefinitions) + 0x0c0c + + + + $(OutDir)$(TargetName).exe + true + + false + true + $(IntDir)$(ProjectName).pdb + Console + + false + + MachineX86 + + + + + + + + + + + $(IntDir)$(ProjectName).tlb + + + + MaxSpeed + AnySuitable + false + Neither + false + false + ..\lib_enc;..\lib_com;..\lib_util;..\lib_debug;%(AdditionalIncludeDirectories) + _CRT_SECURE_NO_WARNINGS;$(Macros);%(PreprocessorDefinitions) + true + + Default + MultiThreaded + true + Precise + false + + + $(IntDir)$(ProjectName).pdb + Level4 + true + + Default + %(DisableSpecificWarnings) + false + + + NDEBUG;%(PreprocessorDefinitions) + 0x0c0c + + + $(OutDir)$(TargetName).exe + true + + false + $(IntDir)$(ProjectName).pdb + Console + false + + MachineX86 + + + + + + + + {824da4cf-06f0-45c9-929a-8792f0e19c3e} + false + + + {2fa8f384-0775-f3b7-f8c3-85209222fc70} + false + + + + + + + + + + + \ No newline at end of file diff --git a/apps/decoder.c b/apps/decoder.c index 2e65a53320b8ef53e7fa3ed89daeb5e99ddececb..2d4551ec4383888a9658665b12ee16cb1d3cf8e8 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -179,12 +179,40 @@ 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 *hHrtf, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ObjectEditFileReader *objectEditFileReader, ISAR_SPLIT_REND_BITS_DATA *splitRendBits, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf ); +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, +#ifdef DECODER_FORMAT_SWITCHING + IVAS_DEC_HANDLE *phIvasDec, +#else + IVAS_DEC_HANDLE hIvasDec, +#endif + int16_t *pcmBuf ); +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, #ifdef FIX_1119_SPLIT_RENDERING_VOIP -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 hIvasDec, int16_t *pcmBuf ); + ISAR_SPLIT_REND_BITS_DATA *splitRendBits, +#endif +#ifdef DECODER_FORMAT_SWITCHING + IVAS_DEC_HANDLE *phIvasDec, #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, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf ); + IVAS_DEC_HANDLE hIvasDec, #endif + int16_t *pcmBuf ); 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 ); @@ -192,6 +220,9 @@ static int16_t app_own_random( int16_t *seed ); #endif static void do_object_editing( IVAS_EDITABLE_PARAMETERS *editableParameters, ObjectEditFileReader *objectEditFileReader ); +#ifdef DECODER_FORMAT_SWITCHING +static ivas_error restartDecoder( IVAS_DEC_HANDLE *phIvasDec, IVAS_DEC_MODE codec, DecArguments *arg, IVAS_RENDER_CONFIG_DATA *renderConfig, IVAS_CUSTOM_LS_DATA *hLsCustomData ); +#endif /*------------------------------------------------------------------------------------------* * main() * @@ -745,16 +776,24 @@ int main( if ( arg.voipMode ) { - + error = decodeVoIP( arg, hBsReader, &hHrtfBinary, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, objectEditFileReader, #ifdef FIX_1119_SPLIT_RENDERING_VOIP - error = decodeVoIP( arg, hBsReader, &hHrtfBinary, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, objectEditFileReader, &splitRendBits, hIvasDec, pcmBuf ); + &splitRendBits, +#endif +#ifdef DECODER_FORMAT_SWITCHING + &hIvasDec, #else - error = decodeVoIP( arg, hBsReader, &hHrtfBinary, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, objectEditFileReader, hIvasDec, pcmBuf ); + hIvasDec, #endif + pcmBuf ); } else { +#ifdef DECODER_FORMAT_SWITCHING + error = decodeG192( arg, hBsReader, &hHrtfBinary, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, objectEditFileReader, &splitRendBits, &hIvasDec, pcmBuf ); +#else error = decodeG192( arg, hBsReader, &hHrtfBinary, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, objectEditFileReader, &splitRendBits, hIvasDec, pcmBuf ); +#endif } if ( error == IVAS_ERR_OK || error == IVAS_ERR_END_OF_FILE ) @@ -2079,7 +2118,11 @@ static ivas_error decodeG192( Vector3PairFileReader *referenceVectorReader, ObjectEditFileReader *objectEditFileReader, ISAR_SPLIT_REND_BITS_DATA *splitRendBits, +#ifdef DECODER_FORMAT_SWITCHING + IVAS_DEC_HANDLE *phIvasDec, +#else IVAS_DEC_HANDLE hIvasDec, +#endif int16_t *pcmBuf ) { @@ -2116,6 +2159,9 @@ static ivas_error decodeG192( int16_t vec_pos_update, vec_pos_len; SplitFileReadWrite *splitRendWriter = NULL; int16_t isSplitRend, isSplitCoded; +#ifdef DECODER_FORMAT_SWITCHING + IVAS_DEC_HANDLE hIvasDec = *phIvasDec; +#endif #ifdef VARIABLE_SPEED_DECODING if ( arg.tsmEnabled ) @@ -2465,6 +2511,31 @@ static ivas_error decodeG192( /* Placeholder for memory reallocation */ /* ... */ +#ifdef DECODER_FORMAT_SWITCHING + if ( IVAS_DEC_isRestartNeeded( hIvasDec ) ) + { + IVAS_DEC_BS_FORMAT tempFormat; + if ( ( error = IVAS_DEC_GetFormat( hIvasDec, &tempFormat ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in IVAS_DEC_GetFormat, code: %d\n", error ); + goto cleanup; + } + IVAS_DEC_MODE codecMode = ( tempFormat == IVAS_DEC_BS_MONO ) ? IVAS_DEC_MODE_EVS : IVAS_DEC_MODE_IVAS; + error = restartDecoder( + &hIvasDec, + codecMode, + &arg, + NULL, /* ToDo : Provide rendererConfig */ + NULL /* ToDo : Provide LS Custom Data */ + ); + if ( error != IVAS_ERR_OK ) + { + fprintf( stderr, "\nFailed to restart decoder\n" ); + goto cleanup; + } + *phIvasDec = hIvasDec; /* Update for main()' s free */ + } +#endif /* Load HRTF binary file data */ if ( arg.hrtfReaderEnabled ) @@ -3064,7 +3135,11 @@ static ivas_error decodeVoIP( #ifdef FIX_1119_SPLIT_RENDERING_VOIP ISAR_SPLIT_REND_BITS_DATA *splitRendBits, #endif +#ifdef DECODER_FORMAT_SWITCHING + IVAS_DEC_HANDLE *phIvasDec, +#else IVAS_DEC_HANDLE hIvasDec, +#endif int16_t *pcmBuf ) { bool decodingFailed = true; /* Assume failure until cleanup is reached without errors */ @@ -3096,6 +3171,9 @@ static ivas_error decodeVoIP( int16_t delayNumSamples = -1; int32_t delayTimeScale = -1; int16_t i; +#ifdef DECODER_FORMAT_SWITCHING + IVAS_DEC_HANDLE hIvasDec = *phIvasDec; +#endif #ifdef IVAS_RTPDUMP IVAS_RTP ivasRtp = { 0 }; int32_t initialTsOffsetSystemAndRTP = 0; @@ -3283,6 +3361,27 @@ static ivas_error decodeVoIP( { nSamplesRendered = 0; +#ifdef DECODER_FORMAT_SWITCHING + if ( ivasRtp.restartNeeded ) + { + IVAS_DEC_MODE newCodecInPacket = ( ivasRtp.codecId == IVAS_RTP_EVS ) ? IVAS_DEC_MODE_EVS : IVAS_DEC_MODE_IVAS; + error = restartDecoder( + &hIvasDec, + newCodecInPacket, + &arg, + NULL, /* ToDo : Provide rendererConfig */ + NULL /* ToDo : Provide LS Custom Data */ + ); + if ( error != IVAS_ERR_OK ) + { + fprintf( stderr, "\nFailed to restart decoder from %d to %d\n", arg.decMode, newCodecInPacket ); + goto cleanup; + } + *phIvasDec = hIvasDec; /* Update for main()' s free */ + ivasRtp.restartNeeded = false; + } +#endif + /* reference vector */ if ( arg.enableReferenceVectorTracking && vec_pos_update == 0 ) { @@ -3533,6 +3632,31 @@ static ivas_error decodeVoIP( /* Placeholder for memory reallocation */ /* ... */ +#ifdef DECODER_FORMAT_SWITCHING + if ( IVAS_DEC_isRestartNeeded( hIvasDec ) ) + { + IVAS_DEC_BS_FORMAT tempFormat; + if ( ( error = IVAS_DEC_GetFormat( hIvasDec, &tempFormat ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in IVAS_DEC_GetFormat, code: %d\n", error ); + goto cleanup; + } + IVAS_DEC_MODE codecMode = ( tempFormat == IVAS_DEC_BS_MONO ) ? IVAS_DEC_MODE_EVS : IVAS_DEC_MODE_IVAS; + error = restartDecoder( + &hIvasDec, + codecMode, + &arg, + NULL, /* ToDo : Provide rendererConfig */ + NULL /* ToDo : Provide LS Custom Data */ + ); + if ( error != IVAS_ERR_OK ) + { + fprintf( stderr, "\nFailed to restart decoder\n" ); + goto cleanup; + } + *phIvasDec = hIvasDec; /* Update for main()' s free */ + } +#endif /* Load HRTF binary file data */ if ( arg.hrtfReaderEnabled ) @@ -4184,4 +4308,111 @@ static ivas_error load_hrtf_from_file( return IVAS_ERR_OK; } +#ifdef DECODER_FORMAT_SWITCHING + +ivas_error restartDecoder( + IVAS_DEC_HANDLE *phIvasDec, + IVAS_DEC_MODE codec, + DecArguments *arg, + IVAS_RENDER_CONFIG_DATA *renderConfig, + IVAS_CUSTOM_LS_DATA *hLsCustomData ) +{ + ivas_error error = IVAS_ERR_OK; + IVAS_DEC_HANDLE hIvasDec; + + if ( phIvasDec == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + if ( NULL != *phIvasDec ) + { + IVAS_DEC_Close( phIvasDec ); + } + + if ( ( error = IVAS_DEC_Open( phIvasDec, codec ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Open failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + + arg->decMode = codec; + + hIvasDec = *phIvasDec; + + uint16_t aeID = arg->aeSequence.count > 0 ? arg->aeSequence.pID[0] : 65535; + + IVAS_AUDIO_CONFIG outputConfig = ( codec == IVAS_DEC_MODE_IVAS ) ? arg->outputConfig : IVAS_AUDIO_CONFIG_MONO; + if ( ( error = IVAS_DEC_Configure( hIvasDec, arg->output_Fs, outputConfig, arg->renderFramesize, arg->customLsOutputEnabled, arg->hrtfReaderEnabled, + arg->enableHeadRotation, arg->enableExternalOrientation, arg->orientation_tracking, arg->renderConfigEnabled, arg->non_diegetic_pan_enabled, + arg->non_diegetic_pan_gain, arg->dpidEnabled, aeID, arg->objEditEnabled, arg->delayCompensationEnabled ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + + if ( ( error = IVAS_DEC_GetRenderFramesize( hIvasDec, &arg->renderFramesize ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + + if ( arg->outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || arg->outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) + { + if ( ( error = IVAS_DEC_EnableSplitRendering( hIvasDec ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nSplit rendering configure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + + if ( ( error = IVAS_DEC_GetRenderFramesize( hIvasDec, &arg->renderFramesize ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + + arg->enableHeadRotation = true; + } + + if ( arg->voipMode ) + { + if ( ( error = IVAS_DEC_EnableVoIP( hIvasDec, 60, arg->inputFormat ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nCould not enable VOIP: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + } + + if ( ( error = IVAS_DEC_PrintConfig( hIvasDec, 1, arg->voipMode ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_PrintConfig failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + + if ( arg->renderConfigEnabled && renderConfig != NULL ) + { + if ( ( error = IVAS_DEC_FeedRenderConfig( hIvasDec, *renderConfig ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_FeedRenderConfig failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + } + + if ( arg->customLsOutputEnabled && hLsCustomData != NULL ) + { + if ( ( error = IVAS_DEC_FeedCustomLsData( hIvasDec, *hLsCustomData ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_FeedCustomLsData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + } + + return IVAS_ERR_OK; + +cleanup: + IVAS_DEC_Close( phIvasDec ); + return error; +} +#endif + #undef WMC_TOOL_SKIP diff --git a/apps/encoder_fmtsw.c b/apps/encoder_fmtsw.c new file mode 100644 index 0000000000000000000000000000000000000000..76f8625cdf57e095eeb0b2bb1a03f5b698d8db3b --- /dev/null +++ b/apps/encoder_fmtsw.c @@ -0,0 +1,2440 @@ +/****************************************************************************************************** + + (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ + +#include "lib_enc.h" +#include +#include "cmdl_tools.h" +#include "audio_file_reader.h" +#include "bitstream_writer.h" +#include "ism_file_reader.h" +#include "jbm_file_reader.h" +#include "masa_file_reader.h" +#ifdef IVAS_RTPDUMP +#include "rotation_file_reader.h" +#include "ivas_rtp_file.h" +#endif +#ifdef DEBUGGING +#include "debug.h" +#endif +#include "wmc_auto.h" +#ifdef FLP_EXCEPTION_TRAP +#include "flp_debug.h" +#endif + + +#define WMC_TOOL_SKIP + +/*------------------------------------------------------------------------------------------* + * Local constants, enums + *------------------------------------------------------------------------------------------*/ + +#define MAX_ARGV 20 /* maximum number of command line arguments that can be \ + in one line of the format switching file */ + +#if !defined( DEBUGGING ) && !defined( WMOPS ) +static +#endif + int32_t frame = 0; /* Counter of frames */ + +#define DEFAULT_FIXED_SID_RATE 8 /* DTX SID rate */ + +/* Additional config info for each input format */ +typedef union _EncInputFormatConfig +{ + /* MONO details */ + bool stereoToMonoDownmix; + +#ifdef DEBUGGING + /* STEREO details */ + IVAS_ENC_STEREO_MODE stereoMode; +#endif + + /* ISM details */ + struct EncIsmConfig + { + int16_t numObjects; + const char *metadataFiles[IVAS_MAX_NUM_OBJECTS]; + } ism; + + /* SBA details */ + struct EncSbaConfig + { + IVAS_ENC_SBA_ORDER order; + bool isPlanar; + } sba; + + /* MASA details */ + IVAS_ENC_MASA_VARIANT masaVariant; + + /* MC details */ + IVAS_ENC_MC_LAYOUT mcLayout; + + struct EncMasaIsmConfig + { + int16_t numObjects; + const char *metadataFiles[IVAS_MAX_NUM_OBJECTS]; + IVAS_ENC_MASA_VARIANT masaVariant; + } masa_ism; + + struct EncSbaIsmConfig + { + int16_t numObjects; + const char *metadataFiles[IVAS_MAX_NUM_OBJECTS]; + IVAS_ENC_SBA_ORDER order; + bool isPlanar; + } sba_ism; + +} EncInputFormatConfig; + + +/*------------------------------------------------------------------------------------------* + * Local structure for storing cmdln arguments + *------------------------------------------------------------------------------------------*/ + +typedef struct +{ + char *inputWavFilename; + char *outputBitstreamFilename; + int32_t inputFs; + IVAS_ENC_INPUT_FORMAT inputFormat; + bool is_binaural; + EncInputFormatConfig inputFormatConfig; + bool max_bwidth_user; + IVAS_ENC_BANDWIDTH maxBandwidth; + const char *bandwithProfileFile; + IVAS_ENC_DTX_CONFIG dtxConfig; + int32_t initBitrate; + const char *bitrateProfileFile; + bool quietModeEnabled; + bool delayCompensationEnabled; + const char *masaMetadataFile; + IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig; + const char *ca_config_file; + bool mimeOutput; + IVAS_ENC_COMPLEXITY_LEVEL complexityLevel; +#ifdef DEBUGGING + IVAS_ENC_FORCED_MODE forcedMode; + const char *forcedModeFile; +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION + IVAS_ENC_AGC agc; +#endif +#ifdef DEBUG_FOA_AGC + FILE *agcBitstream; /* temporary */ +#endif +#ifdef DEBUG_SBA + const char *dbg_file_tag; +#endif +#endif + bool pca; + bool ism_extended_metadata; +#ifdef IVAS_RTPDUMP + bool rtpdumpOutput; + uint32_t numFramesPerPacket; + char *sceneOrientationTrajFileName; + char *deviceOrientationTrajFileName; +#endif + +} EncArguments; + + +/*------------------------------------------------------------------------------------------* + * Local functions prototypes + *------------------------------------------------------------------------------------------*/ + +static bool parseCmdlIVAS_enc( int16_t argc, char *argv[], EncArguments *arg ); +static void usage_enc( void ); +static bool readBandwidth( FILE *file, IVAS_ENC_BANDWIDTH *bandwidth, int32_t *bandwidthFrameCounter ); +static bool readBitrate( FILE *file, int32_t *bitrate ); +#ifdef DEBUGGING +static ivas_error readForcedMode( FILE *file, IVAS_ENC_FORCED_MODE *forcedMode, int32_t *forceFrameCounter ); +static IVAS_ENC_FORCED_MODE parseForcedMode( char *forcedModeChar ); +#endif +static void str2arg( char *str, int *argc_local, char *argv_local[] ); +#ifdef IVAS_RTPDUMP +static int encoder_main( int argc, char *argv[], IVAS_RTP *ivasRtp, int init_RtpWriter ); +#else +static int encoder_main( int argc, char *argv[] ); +#endif + + +/*------------------------------------------------------------------------------------------* + * main() + * + * Main IVAS encoder function for command-line interface + * supporting format switching + *------------------------------------------------------------------------------------------*/ + + +int main( + int argc, + char *argv[] ) +{ + FILE *FmtSWFile = NULL; + char line[2048]; + int argc_local = 0; + char *argv_local[MAX_ARGV] = { 0 }; +#ifdef IVAS_RTPDUMP + IVAS_RTP ivasRtp = { 0 }; + char prev_outputBitstreamFilename[2048] = { 0 }; + int rtp_term = 0; +#endif + + IVAS_ENC_PrintDisclaimer(); + + if ( argc != 2 ) + { + fprintf( stdout, "Usage: IVAS_cod_fmtsw.exe format_switching_file\n\n" ); + fprintf( stdout, "where format_switching_file is a text file containg a valid encoder command line in each line\n\n" ); + exit( 0 ); + } + fprintf( stdout, "Input format switching file: %s\n", argv[1] ); + + if ( ( FmtSWFile = fopen( argv[1], "r" ) ) == NULL ) + { + fprintf( stdout, "error: cannot open format switching file %s\n", argv[1] ); + exit( 0 ); + } + + while ( fgets( line, sizeof( line ), FmtSWFile ) ) + { + /* remove trimming newline */ + line[strcspn( line, "\r\n" )] = 0; + printf( "Processing format switching commandline: %s\n", line ); + str2arg( line, &argc_local, argv_local ); +#ifdef IVAS_RTPDUMP + if ( strcmp( argv_local[argc_local - 1], (char *) prev_outputBitstreamFilename ) == 0 ) + { + /* append to last Rtp file */ + encoder_main( argc_local, argv_local, &ivasRtp, 0 ); + } + else + { + if ( rtp_term == 1 ) + { + IVAS_RTP_Term( &ivasRtp ); + } + /* write in separate Rtp file */ + encoder_main( argc_local, argv_local, &ivasRtp, 1 ); + rtp_term = 1; + } + strcpy( (char *) prev_outputBitstreamFilename, argv_local[argc_local - 1] ); +#else + encoder_main( argc_local, argv_local ); +#endif + } +#ifdef IVAS_RTPDUMP + IVAS_RTP_Term( &ivasRtp ); +#endif + fclose( FmtSWFile ); + exit( 0 ); +} + + +/*-------------------------------------------------------------------* + * Local functions + *-------------------------------------------------------------------*/ + +void str2arg( + char *str, /* input string */ + int *argc_local, /* number of argument */ + char *argv_local[] /* array of arguments */ +) +{ + int i = 0; + char *token = strtok( str, " " ); + while ( token && ( i < MAX_ARGV - 1 ) ) + { + argv_local[i++] = token; + token = strtok( 0, " " ); + } + argv_local[i] = 0; + *argc_local = i; + return; +} + +int encoder_main( + int argc, +#ifdef IVAS_RTPDUMP + char *argv[], + IVAS_RTP *ivasRtp, + int init_RtpWriter ) +#else + char *argv[] ) +#endif +{ + bool mainFailed = true; /* Assume main failed until cleanup is reached without errors */ + EncArguments arg; + int16_t i; + ivas_error error = IVAS_ERR_UNKNOWN; + + /* Any handles that require cleanup must be declared here and initialized to NULL */ + IVAS_ENC_HANDLE hIvasEnc = NULL; + BS_WRITER_HANDLE hBsWriter = NULL; + AudioFileReader *audioReader = NULL; + FILE *f_bitrateProfile = NULL; + FILE *f_bwProfile = NULL; + JbmFileReader *jbmReader = NULL; + MasaFileReader *masaReader = NULL; + IsmFileReader *ismReaders[IVAS_MAX_NUM_OBJECTS] = { NULL, NULL, NULL, NULL }; + int16_t *pcmBuf = NULL; +#ifdef IVAS_RTPDUMP + RotFileReader *sceneOrientationFileReader = NULL; + RotFileReader *deviceOrientationFileReader = NULL; +#endif +#ifdef DEBUGGING + FILE *f_forcedModeProfile = NULL; +#ifdef DEBUG_SBA + int16_t numTransportChannels = 1; +#endif + int32_t noClipping; + float maxOverload, minOverload; +#endif + +#ifdef DEBUGGING + dbgargs( &argc, argv ); +#endif +#ifdef WMOPS + reset_wmops(); + reset_mem( USE_BYTES ); +#endif +#ifdef FLP_EXCEPTION_TRAP + enable_float_exception_trap( FLE_MASK_DENORM | FLE_MASK_UNDERFLOW ); +#endif + +#ifdef IVAS_RTPDUMP + uint8_t au[IVAS_MAX_BITS_PER_FRAME / 8]; + /* IVAS_RTP ivasRtp = { 0 }; */ +#endif + + /*------------------------------------------------------------------------------------------* + * Parse command-line arguments + *------------------------------------------------------------------------------------------*/ + + + if ( !parseCmdlIVAS_enc( (int16_t) argc, argv, &arg ) ) + { + /* Error printout done internally in parseCmdlIVAS_enc() */ + goto cleanup; + } + + /*------------------------------------------------------------------------------------------* + * Open and initialize IVAS encoder + *------------------------------------------------------------------------------------------*/ + + if ( ( error = IVAS_ENC_Open( &hIvasEnc ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Opening IVAS encoder failed: %s\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + + /*------------------------------------------------------------------------------------------* + * Open output bitstream file + *------------------------------------------------------------------------------------------*/ + const BS_WRITER_FORMAT bsWriterFormat = arg.mimeOutput ? BS_WRITER_FORMAT_MIME : BS_WRITER_FORMAT_G192; + +#ifdef IVAS_RTPDUMP + if ( !arg.rtpdumpOutput && BS_Writer_Open_filename( &hBsWriter, arg.outputBitstreamFilename, bsWriterFormat ) != IVAS_ERR_OK ) +#else + if ( BS_Writer_Open_filename( &hBsWriter, arg.outputBitstreamFilename, bsWriterFormat ) != IVAS_ERR_OK ) +#endif + { + fprintf( stderr, "\nCan't open %s\n\n", arg.outputBitstreamFilename ); + goto cleanup; + } + + /*------------------------------------------------------------------------------------------* + * Print out file names + *------------------------------------------------------------------------------------------*/ + + if ( arg.inputFormat == IVAS_ENC_INPUT_ISM || arg.inputFormat == IVAS_ENC_INPUT_SBA_ISM ) + { + for ( i = 0; i < arg.inputFormatConfig.ism.numObjects; i++ ) + { + fprintf( stdout, "Object %d input metadata: %s\n", i + 1, arg.inputFormatConfig.ism.metadataFiles[i] ); + } + } + + if ( arg.masaMetadataFile != NULL ) + { + fprintf( stdout, "MASA inp. metadata file: %s\n", arg.masaMetadataFile ); + } + + fprintf( stdout, "Input audio file: %s\n", arg.inputWavFilename ); + fprintf( stdout, "Output bitstream file: %s\n\n", arg.outputBitstreamFilename ); + + /*------------------------------------------------------------------------------------------* + * Open auxiliary input files + *------------------------------------------------------------------------------------------*/ + + int32_t totalBitrate = arg.initBitrate; + + if ( arg.bitrateProfileFile ) + { + if ( ( f_bitrateProfile = fopen( arg.bitrateProfileFile, "rb" ) ) == NULL ) + { + fprintf( stderr, "Error: bitrate profile file %s could not be opened\n\n", arg.bitrateProfileFile ); + usage_enc(); + goto cleanup; + } + + if ( !readBitrate( f_bitrateProfile, &totalBitrate ) ) + { + fprintf( stderr, "Error: bitrate profile file %s could not be read\n\n", arg.bitrateProfileFile ); + goto cleanup; + } + rewind( f_bitrateProfile ); + + fprintf( stdout, "Bitrate switching file: %s\n", arg.bitrateProfileFile ); + } + + int32_t bandwidthFrameCounter = 0; + IVAS_ENC_BANDWIDTH bandwidth = arg.maxBandwidth; + + if ( arg.bandwithProfileFile ) + { + if ( ( f_bwProfile = fopen( arg.bandwithProfileFile, "rb" ) ) == NULL ) + { + fprintf( stderr, "Error: incorrect bandwidth specification or the bandwidth profile file could not be opened: %s\n\n", arg.bandwithProfileFile ); + usage_enc(); + goto cleanup; + } + fprintf( stdout, "Bandwidth switching file: %s\n", arg.bandwithProfileFile ); + + if ( !readBandwidth( f_bwProfile, &bandwidth, &bandwidthFrameCounter ) ) + { + fprintf( stderr, "Error: bandwidth switching file %s could not be read\n\n", arg.bandwithProfileFile ); + goto cleanup; + } + rewind( f_bwProfile ); + bandwidthFrameCounter = 0; + } + else + { + if ( bandwidth == IVAS_ENC_BANDWIDTH_NB && arg.inputFormat != IVAS_ENC_INPUT_MONO ) + { + fprintf( stdout, "\nNB coding not supported in IVAS. Switching to WB.\n\n" ); + } + else + { + switch ( bandwidth ) + { + case IVAS_ENC_BANDWIDTH_UNDEFINED: + break; + case IVAS_ENC_BANDWIDTH_NB: + fprintf( stdout, "Max. encoded bandwidth: NB\n" ); + break; + case IVAS_ENC_BANDWIDTH_WB: + fprintf( stdout, "Max. encoded bandwidth: WB\n" ); + break; + case IVAS_ENC_BANDWIDTH_SWB: + fprintf( stdout, "Max. encoded bandwidth: SWB\n" ); + break; + case IVAS_ENC_BANDWIDTH_FB: + fprintf( stdout, "Max. encoded bandwidth: FB\n" ); + break; + default: + fprintf( stderr, "Error: Invalid bandwidth value\n" ); + usage_enc(); + goto cleanup; + } + } + } + + /*------------------------------------------------------------------------------------------* + * Handle Channel-aware mode + *------------------------------------------------------------------------------------------*/ + + IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig = arg.caConfig; + + if ( arg.ca_config_file ) + { + if ( ( jbmReader = JbmFileReader_open( arg.ca_config_file ) ) == NULL ) + { + fprintf( stderr, "\nError: Channel aware configuration file could not be opened: %s\n\n", arg.ca_config_file ); + usage_enc(); + goto cleanup; + } + + fprintf( stdout, "Channel-aware mode: ON, config file: %s \n", arg.ca_config_file ); + } + else if ( caConfig.channelAwareModeEnabled ) + { + fprintf( stdout, "Channel-aware mode: ON, FEC indicator : %s FEC offset: %d \n\n", ( caConfig.fec_indicator == IVAS_ENC_FEC_LO ) ? "LO" : "HI", caConfig.fec_offset ); + } + + if ( arg.inputFormat != IVAS_ENC_INPUT_MONO && ( caConfig.channelAwareModeEnabled || arg.ca_config_file ) ) + { + fprintf( stderr, "Channel-aware mode is not supported in IVAS.\n\n" ); + usage_enc(); + goto cleanup; + } + + /*------------------------------------------------------------------------------------------* + * Configure and initialize (allocate memory for static variables) the encoder + *------------------------------------------------------------------------------------------*/ + + switch ( arg.inputFormat ) + { + case IVAS_ENC_INPUT_MONO: + if ( ( error = IVAS_ENC_ConfigureForMono( hIvasEnc, arg.inputFs, totalBitrate, arg.max_bwidth_user, bandwidth, arg.dtxConfig, caConfig, arg.inputFormatConfig.stereoToMonoDownmix, arg.is_binaural ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_ENC_ConfigureForMono failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + break; + case IVAS_ENC_INPUT_STEREO: +#ifdef DEBUGGING + if ( ( error = IVAS_ENC_ConfigureForStereo( hIvasEnc, arg.inputFs, totalBitrate, arg.max_bwidth_user, bandwidth, arg.dtxConfig, arg.is_binaural, arg.inputFormatConfig.stereoMode ) ) != IVAS_ERR_OK ) +#else + if ( ( error = IVAS_ENC_ConfigureForStereo( hIvasEnc, arg.inputFs, totalBitrate, arg.max_bwidth_user, bandwidth, arg.dtxConfig, arg.is_binaural ) ) != IVAS_ERR_OK ) +#endif + { + fprintf( stderr, "\nIVAS_ENC_ConfigureForStereo failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + break; + case IVAS_ENC_INPUT_ISM: + if ( ( error = IVAS_ENC_ConfigureForObjects( hIvasEnc, arg.inputFs, totalBitrate, arg.max_bwidth_user, bandwidth, arg.dtxConfig, arg.inputFormatConfig.ism.numObjects, arg.ism_extended_metadata ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_ENC_ConfigureForObjects failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + break; + case IVAS_ENC_INPUT_SBA: + if ( ( error = IVAS_ENC_ConfigureForAmbisonics( hIvasEnc, arg.inputFs, totalBitrate, arg.max_bwidth_user, bandwidth, arg.dtxConfig, arg.inputFormatConfig.sba.order, arg.inputFormatConfig.sba.isPlanar, +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION + arg.agc, +#endif + arg.pca +#ifdef DEBUG_SBA_AUDIO_DUMP + , + &numTransportChannels +#endif + ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_ENC_ConfigureForAmbisonics failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + + break; + case IVAS_ENC_INPUT_MASA: + if ( ( error = IVAS_ENC_ConfigureForMasa( hIvasEnc, arg.inputFs, totalBitrate, arg.max_bwidth_user, bandwidth, arg.dtxConfig, arg.inputFormatConfig.masaVariant ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_ENC_ConfigureForMasa failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + break; + case IVAS_ENC_INPUT_MC: + if ( ( error = IVAS_ENC_ConfigureForMultichannel( hIvasEnc, arg.inputFs, totalBitrate, arg.max_bwidth_user, bandwidth, arg.dtxConfig, arg.inputFormatConfig.mcLayout ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_ENC_ConfigureForMultichannel failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + break; + case IVAS_ENC_INPUT_SBA_ISM: + if ( ( error = IVAS_ENC_ConfigureForSBAObjects( hIvasEnc, arg.inputFs, totalBitrate, bandwidth, arg.dtxConfig, arg.inputFormatConfig.sba_ism.numObjects, arg.inputFormatConfig.sba_ism.order, arg.inputFormatConfig.sba_ism.isPlanar, arg.pca ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_ENC_ConfigureForSBAObjects failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + exit( -1 ); + } + break; + case IVAS_ENC_INPUT_MASA_ISM: + if ( ( error = IVAS_ENC_ConfigureForMASAObjects( hIvasEnc, arg.inputFs, totalBitrate, bandwidth, arg.dtxConfig, arg.inputFormatConfig.masa_ism.numObjects, arg.inputFormatConfig.masa_ism.masaVariant ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_ENC_ConfigureForMASAObjects failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + exit( -1 ); + } + break; + default: + fprintf( stderr, "\nInvalid input type\n\n" ); + goto cleanup; + } + + if ( ( error = IVAS_ENC_PrintConfig( hIvasEnc, caConfig.channelAwareModeEnabled ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\n IVAS_ENC_PrintConfig failed %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + + /*------------------------------------------------------------------------------------------* + * Open input audio file + *------------------------------------------------------------------------------------------*/ + + if ( AudioFileReader_open( &audioReader, arg.inputWavFilename ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nCan't open %s\n\n", arg.inputWavFilename ); + goto cleanup; + } + + /* Validate input sampling rate */ + int32_t inFileSampleRate = 0; + error = AudioFileReader_getSamplingRate( audioReader, &inFileSampleRate ); + switch ( error ) + { + case IVAS_ERR_OK: + if ( inFileSampleRate != arg.inputFs ) + { + fprintf( stderr, "\nSampling rate mismatch: %d Hz requested, but %d Hz found in file %s\n\n", arg.inputFs, inFileSampleRate, arg.inputWavFilename ); + goto cleanup; + } + break; + case IVAS_ERR_SAMPLING_RATE_UNKNOWN: + /* IVAS_ERR_SAMPLING_RATE_UNKNOWN will be returned for raw PCM files. + * Nothing to check here */ + break; + default: + fprintf( stderr, "\nError: %s\n", ivas_error_to_string( error ) ); + goto cleanup; + } + + /* Validate number of channels */ + int16_t encInNumChannels = 0; + if ( ( error = IVAS_ENC_GetNumInChannels( hIvasEnc, &encInNumChannels ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError: %s\n", ivas_error_to_string( error ) ); + goto cleanup; + } + + int16_t inFileNumChannels = 0; + error = AudioFileReader_getNumChannels( audioReader, &inFileNumChannels ); + switch ( error ) + { + case IVAS_ERR_OK: + if ( inFileNumChannels != encInNumChannels ) + { + fprintf( stderr, "\nNumber of input audio channels mismatch: %d accepted by encoder, but %d found in file %s\n\n", encInNumChannels, inFileNumChannels, arg.inputWavFilename ); + goto cleanup; + } + break; + case IVAS_ERR_NUM_CHANNELS_UNKNOWN: + /* IVAS_ERR_NUM_CHANNELS_UNKNOWN will be returned for raw PCM files. + * Nothing to check here */ + break; + default: + fprintf( stderr, "\nError: %s\n", ivas_error_to_string( error ) ); + goto cleanup; + } + + /*------------------------------------------------------------------------------------------* + * Open input metadata files + *------------------------------------------------------------------------------------------*/ + + if ( arg.masaMetadataFile ) + { + if ( ( masaReader = MasaFileReader_open( arg.masaMetadataFile ) ) == NULL ) + { + fprintf( stderr, "\nError: MASA input metadata file %s could not be opened\n\n", arg.masaMetadataFile ); + usage_enc(); + goto cleanup; + } + } + + const int16_t numIsmInputs = ( arg.inputFormat == IVAS_ENC_INPUT_ISM || arg.inputFormat == IVAS_ENC_INPUT_MASA_ISM || arg.inputFormat == IVAS_ENC_INPUT_SBA_ISM ) ? arg.inputFormatConfig.ism.numObjects : 0; + + for ( i = 0; i < numIsmInputs; ++i ) + { + if ( arg.inputFormatConfig.ism.metadataFiles[i] != NULL ) + { + if ( ( ismReaders[i] = IsmFileReader_open( arg.inputFormatConfig.ism.metadataFiles[i] ) ) == NULL ) + { + fprintf( stderr, "\nError: ISM input metadata file %s could not be opened\n\n", arg.inputFormatConfig.ism.metadataFiles[i] ); + usage_enc(); + goto cleanup; + } + } + } + +#ifdef DEBUGGING + IVAS_ENC_FORCED_MODE forcedMode = arg.forcedMode; + int32_t force_profile_cnt = 0; + + if ( arg.forcedModeFile ) + { + if ( ( f_forcedModeProfile = fopen( arg.forcedModeFile, "rb" ) ) == NULL ) + { + fprintf( stderr, "\nError: Incorrect mode specification or the profile file could not be opened: %s\n\n", arg.forcedModeFile ); + usage_enc(); + goto cleanup; + } + } +#endif + + /*------------------------------------------------------------------------------------------* + * Allocate input data buffer + *------------------------------------------------------------------------------------------*/ + + int16_t pcmBufSize; + if ( ( error = IVAS_ENC_GetInputBufferSize( hIvasEnc, &pcmBufSize ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nGetInputBufferSize failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + + pcmBuf = malloc( pcmBufSize * sizeof( int16_t ) ); + + /*------------------------------------------------------------------------------------------* + * Compensate for encoder delay (bitstream aligned with input signal) + *------------------------------------------------------------------------------------------*/ + + int16_t encDelayInSamples; + if ( ( error = IVAS_ENC_GetDelay( hIvasEnc, &encDelayInSamples ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nGetDelay failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + + if ( arg.delayCompensationEnabled && encDelayInSamples ) + { + /* read samples and throw them away */ + int16_t numSamplesRead = 0; + if ( ( error = AudioFileReader_read( audioReader, pcmBuf, encDelayInSamples, &numSamplesRead ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError reading from file %s\n%s\n", arg.inputWavFilename, IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + } + +#ifdef IVAS_RTPDUMP + /*------------------------------------------------------------------------------------------* + * RTPDump + *------------------------------------------------------------------------------------------*/ + + if ( arg.rtpdumpOutput && init_RtpWriter ) + { + if ( ( error = IVAS_RTP_WRITER_Init( ivasRtp, arg.outputBitstreamFilename, arg.numFramesPerPacket ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError: Can't open output bitstream file for RTP output %s \n\n", arg.outputBitstreamFilename ); + goto cleanup; + } + } + + /*------------------------------------------------------------------------------------------* + * Open scene orientation file + *------------------------------------------------------------------------------------------*/ + + if ( arg.sceneOrientationTrajFileName != NULL ) + { + if ( ( error = RotationFileReader_open( arg.sceneOrientationTrajFileName, &sceneOrientationFileReader ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError: Can't open scene orientation file %s \n\n", arg.sceneOrientationTrajFileName ); + goto cleanup; + } + } + + /*------------------------------------------------------------------------------------------* + * Open device orientation file + *------------------------------------------------------------------------------------------*/ + + if ( arg.deviceOrientationTrajFileName != NULL ) + { + if ( ( error = RotationFileReader_open( arg.deviceOrientationTrajFileName, &deviceOrientationFileReader ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError: Can't open device orientation file %s \n\n", arg.deviceOrientationTrajFileName ); + goto cleanup; + } + } +#endif + + int16_t numSamplesRead = 0; + uint16_t bitStream[IVAS_MAX_BITS_PER_FRAME]; + uint16_t numBits = 0; +#ifdef DEBUG_SBA +#ifdef DEBUG_AGC + ivas_open_agc_debug_files( (int16_t) arg.agc ); +#endif + ivas_open_sba_encoder_debug_files( arg.inputFs, numTransportChannels, arg.dbg_file_tag, arg.initBitrate, (int16_t) arg.dtxConfig.enabled ); +#endif + + if ( !arg.quietModeEnabled ) + { + fprintf( stdout, "\n------ Running the encoder ------\n\n" ); + fprintf( stdout, "Frames processed: " ); + } + else + { + fprintf( stdout, "\n\n-- Start the encoder (quiet mode) --\n\n" ); + } + +#ifdef WMOPS + reset_stack(); + reset_wmops(); +#endif + + /*------------------------------------------------------------------------------------------* + * Loop for every frame of input data + * - Read the input data + * - Process switching files + * - Read input metadata + * - Run the encoder + * - Write the parameters into output bitstream file + *------------------------------------------------------------------------------------------*/ + + while ( 1 ) + { + /* Read the input data */ + if ( ( error = AudioFileReader_read( audioReader, pcmBuf, pcmBufSize, &numSamplesRead ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError reading from file %s\n%s\n", arg.inputWavFilename, IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + + if ( numSamplesRead == 0 ) + { + /* end of input data */ + break; + } + + /* Zero-pad if not enough samples were read (expected in last frame) */ + if ( numSamplesRead < pcmBufSize ) + { + for ( i = numSamplesRead; i < pcmBufSize; ++i ) + { + pcmBuf[i] = 0; + } + } + + /* Process switching files */ + if ( f_bitrateProfile ) + { + if ( !readBitrate( f_bitrateProfile, &totalBitrate ) ) + { + fprintf( stderr, "Error: bitrate profile file %s could not be read\n\n", arg.bitrateProfileFile ); + goto cleanup; + } + + if ( ( error = IVAS_ENC_SetBitrate( hIvasEnc, totalBitrate ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_ENC_SetBitrate failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + } + + if ( f_bwProfile ) + { + if ( !readBandwidth( f_bwProfile, &bandwidth, &bandwidthFrameCounter ) ) + { + fprintf( stderr, "Error: bandwidth switching file %s could not be read\n\n", arg.bandwithProfileFile ); + goto cleanup; + } + + if ( ( error = IVAS_ENC_SetBandwidth( hIvasEnc, bandwidth ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_ENC_SetBandwidth failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + } + + if ( jbmReader ) + { + if ( ( error = JbmFileReader_readCAconfig( jbmReader, &caConfig ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError (%s) while reading Channel-Aware Config. from: %s\n\n", IVAS_ENC_GetErrorMessage( error ), JbmFileReader_getFilePath( jbmReader ) ); + goto cleanup; + } + + if ( ( error = IVAS_ENC_SetChannelAwareConfig( hIvasEnc, caConfig ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "IVAS_ENC_SetChannelAwareConfig failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + } + +#ifdef DEBUGGING + if ( f_forcedModeProfile ) + { + if ( ( error = readForcedMode( f_forcedModeProfile, &forcedMode, &force_profile_cnt ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError reading from file: %s\n%s\n", arg.forcedModeFile, IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + } + + /* Force mode not set when configuring, set in first frame even if not reading from file */ + if ( f_forcedModeProfile || frame == 0 ) + { + if ( ( error = IVAS_ENC_SetForcedMode( hIvasEnc, forcedMode ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_ENC_SetForcedMode failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + } +#endif + /* Read ISM input metadata */ + for ( i = 0; i < numIsmInputs; ++i ) + { + if ( ismReaders[i] == NULL ) + { + continue; + } + + IVAS_ISM_METADATA ismMetadata; + if ( ( error = IsmFileReader_readNextFrame( ismReaders[i], &ismMetadata ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError (%s) while reading ism metadata from: %s\n\n", IVAS_ENC_GetErrorMessage( error ), IsmFileReader_getFilePath( ismReaders[i] ) ); + goto cleanup; + } + + if ( ( error = IVAS_ENC_FeedObjectMetadata( hIvasEnc, i, ismMetadata ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nfeed_ISM_metadata failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + } + + /* Read MASA input metadata */ + if ( masaReader ) + { + if ( ( error = MasaFileReader_readNextFrame( masaReader ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError (%s) while reading masa metadata from: %s\n\n", IVAS_ENC_GetErrorMessage( error ), arg.masaMetadataFile ); + goto cleanup; + } + IVAS_MASA_METADATA_HANDLE hMetadata = MasaFileReader_getMetadataHandle( masaReader ); + + if ( ( error = IVAS_ENC_FeedMasaMetadata( hIvasEnc, hMetadata ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nfeed_MASA_frame failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + } + + /* *** Encode one frame *** */ +#ifdef IVAS_RTPDUMP + if ( ivasRtp->hPack ) + { + bool isMono = ( arg.inputFormat == IVAS_ENC_INPUT_MONO ); + bool forcePacket = ( numSamplesRead < pcmBufSize ); /* If EoF force Packet generation */ + + ivasRtp->nWrittenPiData = 0; + + /* scene orientation */ + if ( sceneOrientationFileReader ) + { + PIDATA_TS *piDataTs = &ivasRtp->piData[ivasRtp->nWrittenPiData++]; + IVAS_PIDATA_ORIENTATION *scene = &piDataTs->data.scene; + + memset( piDataTs, 0, sizeof( PIDATA_TS ) ); + scene->size = sizeof( IVAS_PIDATA_ORIENTATION ); + scene->piDataType = IVAS_PI_SCENE_ORIENTATION; + + if ( ( error = HeadRotationFileReading( sceneOrientationFileReader, &scene->orientation, NULL ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError %s while reading scene orientation from %s\n", IVAS_ENC_GetErrorMessage( error ), RotationFileReader_getFilePath( sceneOrientationFileReader ) ); + goto cleanup; + } + } + + /* device orientation */ + if ( deviceOrientationFileReader ) + { + PIDATA_TS *piDataTs = &ivasRtp->piData[ivasRtp->nWrittenPiData++]; + IVAS_PIDATA_ORIENTATION *device = &piDataTs->data.deviceUnCompensated; + + memset( piDataTs, 0, sizeof( PIDATA_TS ) ); + device->size = sizeof( IVAS_PIDATA_ORIENTATION ); + device->piDataType = IVAS_PI_DEVICE_ORIENTATION_COMPENSATED; + + if ( ( error = HeadRotationFileReading( deviceOrientationFileReader, &device->orientation, NULL ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError %s while reading device orientation from %s\n", IVAS_ENC_GetErrorMessage( error ), RotationFileReader_getFilePath( deviceOrientationFileReader ) ); + goto cleanup; + } + } + + if ( ( error = IVAS_ENC_EncodeFrameToCompact( hIvasEnc, pcmBuf, pcmBufSize, au, &numBits ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nencodeFrame failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + + if ( ( error = IVAS_RTP_WriteNextFrame( ivasRtp, au, numBits, isMono, forcePacket ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError %s while pushing audio frame to RTP pack\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + } + else + { +#endif + if ( ( error = IVAS_ENC_EncodeFrameToSerial( hIvasEnc, pcmBuf, pcmBufSize, bitStream, &numBits ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nencodeFrame failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + + /* write bitstream */ + if ( ( error = BS_Writer_WriteFrame_short( hBsWriter, bitStream, numBits, totalBitrate ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nBS_Writer_WriteFrame_short failed, error code %d\n\n", error ); + goto cleanup; + } +#ifdef IVAS_RTPDUMP + } +#endif + + frame++; + if ( !arg.quietModeEnabled ) + { + fprintf( stdout, "%-8d\b\b\b\b\b\b\b\b", frame ); + } + +#ifdef WMOPS + update_mem(); + update_wmops(); +#endif + } + + if ( arg.quietModeEnabled ) + { + fprintf( stdout, "Encoding finished\n" ); + } + else + { + fprintf( stdout, "\n\nEncoding of %d frames finished\n", frame ); + } + +#ifdef DEBUGGING + if ( ( noClipping = IVAS_ENC_GetNoCLipping( hIvasEnc, &maxOverload, &minOverload ) ) > 0 ) + { + fprintf( stdout, "Core input overload detected: %d samples!!!\n", noClipping ); + fprintf( stdout, "Max overload value: %f \n", maxOverload ); + fprintf( stdout, "Min overload value: %f \n\n", minOverload ); + } + print_snr(); +#endif + /*------------------------------------------------------------------------------------------* + * Close files and deallocate resources + *------------------------------------------------------------------------------------------*/ + + mainFailed = false; /* This will stay set to true if cleanup is reached via a goto due to an error */ + +cleanup: + + free( pcmBuf ); + + if ( ( error = BS_Writer_Close( &hBsWriter ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Can't close bitstream writer, error code %d\n", error ); + mainFailed = true; + } + + AudioFileReader_close( &audioReader ); + + if ( jbmReader ) + { + JbmFileReader_close( &jbmReader ); + } + + for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; ++i ) + { + if ( ismReaders[i] != NULL ) + { + IsmFileReader_close( &ismReaders[i] ); + } + } + + if ( masaReader ) + { + MasaFileReader_close( &masaReader ); + } + + if ( f_bwProfile ) + { + fclose( f_bwProfile ); + } + + if ( f_bitrateProfile ) + { + fclose( f_bitrateProfile ); + } + +#ifdef IVAS_RTPDUMP + if ( sceneOrientationFileReader ) + { + RotationFileReader_close( &sceneOrientationFileReader ); + } + + if ( deviceOrientationFileReader ) + { + RotationFileReader_close( &deviceOrientationFileReader ); + } + + /* IVAS_RTP_Term( &ivasRtp ); */ +#endif + + IVAS_ENC_Close( &hIvasEnc ); + +#ifdef WMOPS + print_wmops(); + print_mem( NULL ); +#endif +#ifdef DEBUGGING + dbgclose(); + + if ( f_forcedModeProfile ) + { + fclose( f_forcedModeProfile ); + } + +#ifdef DEBUG_SBA + ivas_close_sba_encoder_debug_files(); +#ifdef DEBUG_AGC + ivas_close_agc_debug_files(); +#endif +#endif +#endif + + return mainFailed ? -1 : 0; +} + +/*---------------------------------------------------------------------* + * parseCmdlIVAS_enc() + * + * Encoder command-line parsing + *---------------------------------------------------------------------*/ + +static bool parseCmdlIVAS_enc( + int16_t argc, + char *argv[], + EncArguments *arg ) +{ + int16_t i, j; + char argv_to_upper[FILENAME_MAX]; + char stmp[FILENAME_MAX]; + int32_t tmp; + + /*-----------------------------------------------------------------* + * Set default values + *-----------------------------------------------------------------*/ + + arg->inputWavFilename = NULL; + arg->outputBitstreamFilename = NULL; + arg->inputFs = IVAS_MAX_SAMPLING_RATE; + arg->inputFormat = IVAS_ENC_INPUT_MONO; + arg->is_binaural = false; + arg->inputFormatConfig.stereoToMonoDownmix = false; + arg->max_bwidth_user = false; + arg->maxBandwidth = IVAS_ENC_BANDWIDTH_UNDEFINED; + arg->bandwithProfileFile = NULL; + arg->dtxConfig = IVAS_ENC_GetDefaultDtxConfig(); + arg->initBitrate = 0; + arg->bitrateProfileFile = NULL; + arg->quietModeEnabled = false; + arg->delayCompensationEnabled = true; + arg->masaMetadataFile = NULL; + arg->caConfig = IVAS_ENC_GetDefaultChannelAwareConfig(); + arg->ca_config_file = NULL; + arg->mimeOutput = false; + arg->ism_extended_metadata = false; + arg->complexityLevel = IVAS_ENC_COMPLEXITY_LEVEL_THREE; +#ifdef IVAS_RTPDUMP + arg->rtpdumpOutput = false; + arg->sceneOrientationTrajFileName = NULL; + arg->deviceOrientationTrajFileName = NULL; +#endif + +#ifdef DEBUGGING + arg->forcedMode = IVAS_ENC_FORCE_UNFORCED; + arg->forcedModeFile = NULL; +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION + arg->agc = IVAS_ENC_AGC_UNDEFINED; +#endif +#ifdef DEBUG_FOA_AGC + arg->agcBitstream = NULL; +#endif +#ifdef DEBUG_SBA + arg->dbg_file_tag = NULL; +#endif +#endif + arg->pca = false; + + /*-----------------------------------------------------------------* + * Initialization + *-----------------------------------------------------------------*/ + + if ( argc < 5 ) + { + fprintf( stderr, "Error: Not enough input parameters. Exiting!\n\n" ); + usage_enc(); + return false; + } + + /*-----------------------------------------------------------------* + * Optional input arguments + *-----------------------------------------------------------------*/ + + i = 1; + while ( i < argc - 4 ) + { + strncpy( argv_to_upper, argv[i], sizeof( argv_to_upper ) - 1 ); + argv_to_upper[sizeof( argv_to_upper ) - 1] = '\0'; + to_upper( argv_to_upper ); + + /*-----------------------------------------------------------------* + * Bandwidth limitation + *-----------------------------------------------------------------*/ + + if ( strcmp( argv_to_upper, "-MAX_BAND" ) == 0 ) + { + arg->max_bwidth_user = true; + + strncpy( stmp, argv[i + 1], sizeof( stmp ) - 1 ); + stmp[sizeof( stmp ) - 1] = '\0'; + to_upper( stmp ); + + if ( strcmp( stmp, "-NB" ) == 0 || strcmp( stmp, "NB" ) == 0 ) + { + arg->maxBandwidth = IVAS_ENC_BANDWIDTH_NB; + } + else if ( strcmp( stmp, "-WB" ) == 0 || strcmp( stmp, "WB" ) == 0 ) + { + arg->maxBandwidth = IVAS_ENC_BANDWIDTH_WB; + } + else if ( strcmp( stmp, "-SWB" ) == 0 || strcmp( stmp, "SWB" ) == 0 ) + { + arg->maxBandwidth = IVAS_ENC_BANDWIDTH_SWB; + } + else if ( strcmp( stmp, "-FB" ) == 0 || strcmp( stmp, "FB" ) == 0 ) + { + arg->maxBandwidth = IVAS_ENC_BANDWIDTH_FB; + } + else + { + arg->bandwithProfileFile = argv[i + 1]; + } + + i += 2; + } + + /*-----------------------------------------------------------------* + * Quiet mode + *-----------------------------------------------------------------*/ + + else if ( strcmp( argv_to_upper, "-Q" ) == 0 ) + { + i++; + arg->quietModeEnabled = true; + } + + /*-----------------------------------------------------------------* + * DTX/CNG + *-----------------------------------------------------------------*/ + + else if ( strcmp( argv_to_upper, "-DTX" ) == 0 ) + { + i++; + if ( i < argc - 4 ) + { + if ( sscanf( argv[i], "%d", &tmp ) <= 0 ) + { + tmp = DEFAULT_FIXED_SID_RATE; + } + else + { + i++; + } + } + else + { + tmp = DEFAULT_FIXED_SID_RATE; + } + + arg->dtxConfig.enabled = true; + + if ( tmp == 0 ) + { + arg->dtxConfig.variable_SID_rate = true; + arg->dtxConfig.SID_interval = 0; + } + else if ( tmp >= 3 && tmp <= 100 ) + { + arg->dtxConfig.variable_SID_rate = false; + arg->dtxConfig.SID_interval = (int16_t) tmp; + } + else + { + fprintf( stderr, "Error: Incorrect SID update interval specified: %d (supported 3-100)\n\n", tmp ); + usage_enc(); + return false; + } + } + +#ifdef DEBUGGING + /*-----------------------------------------------------------------* + * Force specific mode + *-----------------------------------------------------------------*/ + + else if ( strcmp( argv_to_upper, "-FORCE" ) == 0 ) + { + strncpy( stmp, argv[i + 1], sizeof( stmp ) ); + + arg->forcedMode = parseForcedMode( stmp ); + + if ( arg->forcedMode == IVAS_ENC_FORCE_UNDEFINED ) + { + arg->forcedModeFile = argv[i + 1]; + fprintf( stdout, "Force switching file: %s\n", argv[i + 1] ); + } + else + { + fprintf( stdout, "Forcing codec to: %s\n", argv[i + 1] ); + } + + i += 2; + } +#ifdef DEBUG_MODE_INFO +#ifdef DEBUG_MODE_INFO_TWEAK + /*-----------------------------------------------------------------* + * Define additional subfolder for debug info output in ./res + *-----------------------------------------------------------------*/ + else if ( strcmp( argv_to_upper, "-INFO" ) == 0 ) + { + extern char infoFolder[FILENAME_MAX]; + strncpy( infoFolder, argv[i + 1], sizeof( infoFolder ) ); + i += 2; + } +#endif /* #ifdef DEBUG_MODE_INFO_TWEAK */ +#endif /* #ifdef DEBUG_MODE_INFO */ + +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION + /*-----------------------------------------------------------------* + * IVAS SPAR AGC option + *-----------------------------------------------------------------*/ + else if ( strcmp( argv_to_upper, "-AGC" ) == 0 ) + { + i++; + if ( i < argc - 4 ) + { + arg->agc = ( atoi( argv[i] ) ) ? IVAS_ENC_AGC_ENABLED : IVAS_ENC_AGC_DISABLED; + if ( argv[i] == NULL || atoi( argv[i] ) < 0 || atoi( argv[i] ) > 1 ) + { + fprintf( stderr, "Error: wrong adaptive gain control option specified (%d), expected 0 or 1\n\n", (int32_t) atoi( argv[i] ) ); + usage_enc(); + return false; + } + i++; + } + else + { + fprintf( stderr, "Error: unspecified adaptive gain control option\n\n" ); + usage_enc(); + return false; + } + } +#endif + +#ifdef DEBUG_SBA + /*-----------------------------------------------------------------* + * IVAS SPAR debug files tag + *-----------------------------------------------------------------*/ + else if ( strcmp( argv_to_upper, "-TAG" ) == 0 ) + { + i++; + if ( i < argc - 4 ) + { + arg->dbg_file_tag = argv[i]; + ++i; + } + else + { + fprintf( stderr, "Error: [IVAS SPAR Encoder] unspecified tag value \n\n" ); + usage_enc(); + return false; + } + } +#endif +#endif /* #ifdef DEBUGGING */ + + /*-----------------------------------------------------------------* + * deactivate delay compensation + *-----------------------------------------------------------------*/ + + else if ( strcmp( argv_to_upper, "-NO_DELAY_CMP" ) == 0 ) + { + arg->delayCompensationEnabled = false; + i++; + } + + /*-----------------------------------------------------------------* + * Activate channel-aware mode + *-----------------------------------------------------------------*/ + + else if ( strcmp( argv_to_upper, "-RF" ) == 0 ) + { + arg->caConfig.channelAwareModeEnabled = 1; + i++; + + if ( i < argc - 4 ) + { + strncpy( stmp, argv[i], sizeof( stmp ) ); + stmp[sizeof( stmp ) - 1] = '\0'; + to_upper( stmp ); + if ( strcmp( stmp, "LO" ) == 0 ) + { + arg->caConfig.fec_indicator = IVAS_ENC_FEC_LO; + } + else if ( strcmp( stmp, "HI" ) == 0 ) + { + arg->caConfig.fec_indicator = IVAS_ENC_FEC_HI; + } + else + { + arg->ca_config_file = argv[i]; + } + i++; + + if ( ( sscanf( argv[i], "%d", &tmp ) == 1 ) && ( i < argc - 4 ) ) + { + if ( tmp == 0 ) + { + arg->caConfig.channelAwareModeEnabled = 0; + arg->caConfig.fec_offset = 0; + i++; + } + else + { + arg->caConfig.fec_offset = (int16_t) tmp; + i++; + } + } + } + else + { + arg->caConfig.fec_indicator = IVAS_ENC_FEC_HI; + } + } + + /*-----------------------------------------------------------------* + * MIME output file format + *-----------------------------------------------------------------*/ + + else if ( strcmp( argv_to_upper, "-MIME" ) == 0 ) + { + arg->mimeOutput = true; + fprintf( stdout, "Output bitstream file format: MIME\n" ); + ++i; + } + + + /*-----------------------------------------------------------------* + * Complexity Level + *-----------------------------------------------------------------*/ + + /* actual parsing of level will be implemented after characterization */ + else if ( strcmp( argv_to_upper, "-LEVEL" ) == 0 ) + { + int16_t level; + + ++i; + level = (int16_t) atoi( argv[i++] ); + if ( level < IVAS_ENC_COMPLEXITY_LEVEL_ONE || level > IVAS_ENC_COMPLEXITY_LEVEL_THREE ) + { + fprintf( stdout, "Invalid complexity level specified.\n" ); + usage_enc(); + return false; + } + else if ( level == IVAS_ENC_COMPLEXITY_LEVEL_ONE || level == IVAS_ENC_COMPLEXITY_LEVEL_TWO ) + { + fprintf( stdout, "Complexity levels 1 and 2 will be defined after characterisation - default to level 3 (full functionality).\n" ); + } + } + + /*-----------------------------------------------------------------* + * IVAS Formats + *-----------------------------------------------------------------*/ + + else if ( strcmp( argv_to_upper, "-STEREO" ) == 0 ) + { + i++; + arg->inputFormat = IVAS_ENC_INPUT_STEREO; + +#ifdef DEBUGGING + if ( ( i < argc - 4 ) && argv[i][0] != 45 ) /* note: 45 corresponds to "-" */ + { + if ( sscanf( argv[i], "%d", &tmp ) > 0 ) + { + if ( tmp == 1 ) + { + arg->inputFormatConfig.stereoMode = IVAS_ENC_STEREO_MODE_DFT; + i++; + } + else if ( tmp == 2 ) + { + arg->inputFormatConfig.stereoMode = IVAS_ENC_STEREO_MODE_TD; + i++; + } + else if ( tmp == 3 ) + { + arg->inputFormatConfig.stereoMode = IVAS_ENC_STEREO_MODE_MDCT_DECISION; +#ifdef DEBUG_FORCE_MDCT_STEREO_MODE + i++; + + /* force mdct stereo mode for debugging purposes */ + if ( i < argc - 4 ) + { + if ( sscanf( argv[i], "%d", &tmp ) > 0 ) + { + if ( tmp == 0 ) + { + /* keep "DECISION" */ + arg->inputFormatConfig.stereoMode = IVAS_ENC_STEREO_MODE_MDCT_DECISION; + i++; + } + else if ( tmp == 1 ) + { + arg->inputFormatConfig.stereoMode = IVAS_ENC_STEREO_MODE_MDCT_FORCE_LR; + i++; + } + else if ( tmp == 2 ) + { + arg->inputFormatConfig.stereoMode = IVAS_ENC_STEREO_MODE_MDCT_FORCE_MS; + i++; + } + else + { + fprintf( stderr, "Error: Incorrect mdct stereo coding method (%d) specified\n\n", tmp ); + usage_enc(); + return false; + } + } + } +#endif + } + else + { + fprintf( stderr, "Error: Incorrect stereo mode (%d) specified\n\n", tmp ); + usage_enc(); + return false; + } + } + else + { + fprintf( stderr, "Error: Stereo mode not specified.\n\n" ); /* in the debugging stage */ + usage_enc(); + return false; + } + } + else + { + arg->inputFormatConfig.stereoMode = IVAS_ENC_STEREO_MODE_UNIFIED; + } +#endif /* DEBUGGING */ + } + else if ( strcmp( argv_to_upper, "-BINAURAL" ) == 0 ) + { + arg->is_binaural = true; + i++; + } + else if ( strcmp( argv_to_upper, "-ISM" ) == 0 ) + { + arg->inputFormat = IVAS_ENC_INPUT_ISM; + i++; + + if ( i < argc - 4 ) + { + if ( argv[i][0] == '+' ) + { + argv[i]++; + arg->ism_extended_metadata = true; + } + if ( !is_digits_only( argv[i] ) ) + { + fprintf( stderr, "Error: Number of ISM channels must be an integer number!\n\n" ); + usage_enc(); + return false; + } + + if ( sscanf( argv[i], "%d", &tmp ) > 0 ) + { + i++; + } + + if ( tmp <= 0 ) + { + fprintf( stderr, "Error: Too low number of ISM channels specified!\n\n" ); + usage_enc(); + return false; + } + else if ( tmp > IVAS_MAX_NUM_OBJECTS ) + { + fprintf( stderr, "Error: Too high number of ISM channels specified!\n\n" ); + usage_enc(); + return false; + } + else + { + arg->inputFormatConfig.ism.numObjects = (int16_t) tmp; + } + } + else + { + fprintf( stderr, "Error: Number of ISM channels not specified!\n\n" ); + usage_enc(); + return false; + } + + /* read input metadata files */ + for ( j = 0; j < arg->inputFormatConfig.ism.numObjects; j++ ) + { + if ( i < argc - 4 ) + { + if ( strcmp( argv[i], "NULL" ) == 0 || strcmp( argv[i], "null" ) == 0 ) + { + /* no metadata input file -> encode only audio streams */ + arg->inputFormatConfig.ism.metadataFiles[j] = NULL; + } + else + { + arg->inputFormatConfig.ism.metadataFiles[j] = argv[i]; + } + + i++; + } + else + { + fprintf( stderr, "Error: not enough metadata arguments specified!\n\n" ); + usage_enc(); + return false; + } + } + } + else if ( strcmp( argv_to_upper, "-SBA" ) == 0 ) + { + i++; + arg->inputFormat = IVAS_ENC_INPUT_SBA; + + /* SBA configuration */ + if ( i < argc - 4 && is_number( argv[i] ) && sscanf( argv[i], "%d", &tmp ) > 0 ) + { + i++; + } + else + { + tmp = -1; /* this is to avoid a compilation warning */ + fprintf( stderr, "Error: SBA order must be specified, expecting a number!\n\n" ); + usage_enc(); + return false; + } + + arg->inputFormatConfig.sba.isPlanar = ( tmp < 0 ); + + tmp = abs( tmp ); + switch ( tmp ) + { + case 1: + arg->inputFormatConfig.sba.order = IVAS_ENC_SBA_FOA; + break; + case 2: + arg->inputFormatConfig.sba.order = IVAS_ENC_SBA_HOA2; + break; + case 3: + arg->inputFormatConfig.sba.order = IVAS_ENC_SBA_HOA3; + break; + default: + fprintf( stderr, "Error: Wrong SBA order specified!\n\n" ); + usage_enc(); + return false; + } + } + else if ( strcmp( argv_to_upper, "-MASA" ) == 0 ) + { + arg->inputFormat = IVAS_ENC_INPUT_MASA; + i++; + + if ( i < argc - 4 ) + { + if ( !is_digits_only( argv[i] ) ) + { + fprintf( stderr, "Error: Number of MASA channels must be an integer number!\n\n" ); + usage_enc(); + return false; + } + + if ( sscanf( argv[i], "%d", &tmp ) > 0 ) + { + i++; + } + + switch ( tmp ) + { + case 1: + arg->inputFormatConfig.masaVariant = IVAS_ENC_MASA_1CH; + break; + case 2: + arg->inputFormatConfig.masaVariant = IVAS_ENC_MASA_2CH; + break; + default: + fprintf( stderr, "Error: MASA channels must be 1 or 2.\n\n" ); + usage_enc(); + return false; + } + } + + if ( i < argc - 4 ) + { + arg->masaMetadataFile = argv[i]; + i++; + } + else + { + fprintf( stderr, "Error: not enough MASA arguments\n\n" ); + usage_enc(); + return false; + } + } + else if ( strcmp( argv_to_upper, "-MC" ) == 0 ) + { + i++; + arg->inputFormat = IVAS_ENC_INPUT_MC; + + if ( i < argc - 4 ) + { + if ( strcmp( argv[i], "5_1" ) == 0 ) + { + arg->inputFormatConfig.mcLayout = IVAS_ENC_MC_5_1; + } + else if ( strcmp( argv[i], "7_1" ) == 0 ) + { + arg->inputFormatConfig.mcLayout = IVAS_ENC_MC_7_1; + } + else if ( strcmp( argv[i], "5_1_2" ) == 0 ) + { + arg->inputFormatConfig.mcLayout = IVAS_ENC_MC_5_1_2; + } + else if ( strcmp( argv[i], "5_1_4" ) == 0 ) + { + arg->inputFormatConfig.mcLayout = IVAS_ENC_MC_5_1_4; + } + else if ( strcmp( argv[i], "7_1_4" ) == 0 ) + { + arg->inputFormatConfig.mcLayout = IVAS_ENC_MC_7_1_4; + } + else + { + fprintf( stderr, "Error: Incorrect input configuration specified for Multi-channel\n\n" ); + usage_enc(); + return false; + } + i++; + } + else + { + fprintf( stderr, "Error: Multi-channel configuration not specified!\n\n" ); + usage_enc(); + return false; + } + } + else if ( strcmp( to_upper( argv[i] ), "-ISM_MASA" ) == 0 ) + { + arg->inputFormat = IVAS_ENC_INPUT_MASA_ISM; + i++; + + if ( i < argc - 5 ) + { + if ( sscanf( argv[i], "%d", &tmp ) > 0 ) + { + i++; + } + + if ( tmp <= 0 ) + { + fprintf( stderr, "Error: Too low number of ISM channels specified!\n\n" ); + usage_enc(); + return false; + } + else + { + if ( tmp <= IVAS_MAX_NUM_OBJECTS ) /* number of ISM channels */ + { + arg->inputFormatConfig.masa_ism.numObjects = (int16_t) tmp; + } + else + { + fprintf( stderr, "Error: Too high number of ISM channels!\n\n" ); + usage_enc(); + return false; + } + } + } + else + { + fprintf( stderr, "Error: Number of ISM channels not specified!\n\n" ); + usage_enc(); + return false; + } + if ( i < argc - 4 ) + { + if ( sscanf( argv[i], "%d", &tmp ) > 0 ) + { + i++; + } + + switch ( tmp ) + { + case 1: + arg->inputFormatConfig.masa_ism.masaVariant = IVAS_ENC_MASA_1CH; + break; + case 2: + arg->inputFormatConfig.masa_ism.masaVariant = IVAS_ENC_MASA_2CH; + break; + default: + fprintf( stderr, "Error: MASA channels must be 1 or 2.\n\n" ); + usage_enc(); + return false; + } + } + + /* read input metadata files */ + for ( j = 0; j < arg->inputFormatConfig.masa_ism.numObjects; j++ ) + { + if ( i < argc - 4 ) + { + if ( strcmp( argv[i], "NULL" ) == 0 || strcmp( argv[i], "null" ) == 0 ) + { + /* no metadata input file -> encode only audio streams */ + arg->inputFormatConfig.masa_ism.metadataFiles[j] = NULL; + } + else + { + arg->inputFormatConfig.masa_ism.metadataFiles[j] = argv[i]; + } + + i++; + } + else + { + fprintf( stderr, "Error: not enough arguments\n\n" ); + usage_enc(); + return false; + } + } + + if ( i < argc - 4 ) + { + arg->masaMetadataFile = argv[i]; + i++; + } + else + { + fprintf( stderr, "Error: not enough MASA arguments\n\n" ); + usage_enc(); + return false; + } + } + else if ( strcmp( to_upper( argv[i] ), "-ISM_SBA" ) == 0 ) + { + arg->inputFormat = IVAS_ENC_INPUT_SBA_ISM; + i++; + + if ( i < argc - 5 ) + { + if ( sscanf( argv[i], "%d", &tmp ) > 0 ) + { + i++; + } + + if ( tmp <= 0 ) + { + fprintf( stderr, "Error: Too low number of ISM channels specified!\n\n" ); + usage_enc(); + return false; + } + else + { + if ( tmp <= IVAS_MAX_NUM_OBJECTS ) /* number of ISM channels */ + { + arg->inputFormatConfig.sba_ism.numObjects = (int16_t) tmp; + } + else + { + fprintf( stderr, "Error: Too high number of ISM channels!\n\n" ); + usage_enc(); + return false; + } + } + } + else + { + fprintf( stderr, "Error: Number of ISM channels not specified!\n\n" ); + usage_enc(); + return false; + } + + if ( i < argc - 4 ) + { + if ( sscanf( argv[i], "%d", &tmp ) > 0 ) + { + i++; + } + + arg->inputFormatConfig.sba_ism.isPlanar = ( tmp < 0 ); + + tmp = abs( tmp ); + switch ( tmp ) + { + case 1: + arg->inputFormatConfig.sba_ism.order = IVAS_ENC_SBA_FOA; + break; + case 2: + arg->inputFormatConfig.sba_ism.order = IVAS_ENC_SBA_HOA2; + break; + case 3: + arg->inputFormatConfig.sba_ism.order = IVAS_ENC_SBA_HOA3; + break; + default: + fprintf( stderr, "Error: Wrong SBA order specified!\n\n" ); + usage_enc(); + return false; + } + } + + /* read input metadata files */ + for ( j = 0; j < arg->inputFormatConfig.sba_ism.numObjects; j++ ) + { + if ( i < argc - 4 ) + { + if ( strcmp( argv[i], "NULL" ) == 0 || strcmp( argv[i], "null" ) == 0 ) + { + /* no metadata input file -> encode only audio streams */ + arg->inputFormatConfig.sba_ism.metadataFiles[j] = NULL; + } + else + { + arg->inputFormatConfig.sba_ism.metadataFiles[j] = argv[i]; + } + + i++; + } + else + { + fprintf( stderr, "Error: not enough arguments\n\n" ); + usage_enc(); + return false; + } + } + } + else if ( strcmp( argv_to_upper, "-STEREO_DMX_EVS" ) == 0 ) + { + arg->inputFormat = IVAS_ENC_INPUT_MONO; + arg->inputFormatConfig.stereoToMonoDownmix = true; + + i++; + } + else if ( strcmp( argv_to_upper, "-PCA" ) == 0 ) + { + arg->pca = 1; + i++; + } + +#ifdef IVAS_RTPDUMP + /*-----------------------------------------------------------------* + * RTPDump output + *-----------------------------------------------------------------*/ + + else if ( strcmp( argv_to_upper, "-RTPDUMP" ) == 0 ) + { + i++; + arg->rtpdumpOutput = true; + if ( i < argc - 4 ) + { + if ( !is_digits_only( argv[i] ) ) + { + arg->numFramesPerPacket = 1; /* Default to 1 frame per packet */ + } + else + { + arg->numFramesPerPacket = atoi( argv[i++] ); + if ( arg->numFramesPerPacket > IVAS_MAX_FRAMES_PER_RTP_PACKET ) + { + fprintf( stderr, "numFramesPerPacket(%d) exceeds max frames per packet (%d) \n", arg->numFramesPerPacket, IVAS_MAX_FRAMES_PER_RTP_PACKET ); + arg->numFramesPerPacket = 1; + } + } + } + fprintf( stdout, "Output format: RTPDump using %d frames/packet \n", arg->numFramesPerPacket ); + } + + /*-----------------------------------------------------------------* + * Scene orientation + *-----------------------------------------------------------------*/ + + else if ( strcmp( argv_to_upper, "-SCENE_ORIENTATION" ) == 0 ) + { + i++; + if ( argc - i <= 4 || argv[i][0] == '-' ) + { + fprintf( stderr, "Error: Scene orientation file name not specified!\n\n" ); + usage_enc(); + return false; + } + + arg->sceneOrientationTrajFileName = argv[i]; + i++; + } + + /*-----------------------------------------------------------------* + * Device orientation + *-----------------------------------------------------------------*/ + + else if ( strcmp( argv_to_upper, "-DEVICE_ORIENTATION" ) == 0 ) + { + i++; + if ( argc - i <= 4 || argv[i][0] == '-' ) + { + fprintf( stderr, "Error: Device orientation file name not specified!\n\n" ); + usage_enc(); + return false; + } + + arg->deviceOrientationTrajFileName = argv[i]; + i++; + } + +#endif + /*-----------------------------------------------------------------* + * Option not recognized + *-----------------------------------------------------------------*/ + else + { + fprintf( stderr, "Error: option not recognized, %s\n\n", argv[i] ); + usage_enc(); + return false; + } + } /* end of while */ + +#ifdef IVAS_RTPDUMP + if ( arg->sceneOrientationTrajFileName != NULL && arg->rtpdumpOutput == false ) + { + fprintf( stderr, "Error: Scene orientations are only enabled with rtpdump output!\n\n" ); + usage_enc(); + return false; + } + if ( arg->deviceOrientationTrajFileName != NULL && arg->rtpdumpOutput == false ) + { + fprintf( stderr, "Error: Device orientations are only enabled with rtpdump output!\n\n" ); + usage_enc(); + return false; + } + +#endif + /*-----------------------------------------------------------------* + * Mandatory input arguments + *-----------------------------------------------------------------*/ + + /*-----------------------------------------------------------------* + * Bitrate + *-----------------------------------------------------------------*/ + + if ( i < argc - 2 ) + { + /* check if profile file has been entered instead of a fixed bitrate */ + if ( !is_digits_only( argv[i] ) ) + { + arg->bitrateProfileFile = argv[i]; + } + else + { + arg->initBitrate = atoi( argv[i] ); + } + + i++; + } + else + { + fprintf( stderr, "Error: no bitrate specified\n\n" ); + usage_enc(); + return false; + } + + /*-----------------------------------------------------------------* + * Input sampling frequency + *-----------------------------------------------------------------*/ + + if ( i < argc - 2 ) + { + arg->inputFs = atoi( argv[i] ) * 1000; + i++; + } + else + { + fprintf( stderr, "Error: no input sampling frequency specified\n\n" ); + usage_enc(); + return false; + } + + /* for EVS mono, restore default behavior, i.e. SWB as default maxBandwidth if not set by the user otherwise */ + if ( arg->max_bwidth_user == false ) + { + arg->maxBandwidth = IVAS_ENC_GetDefaultBandwidth( ( arg->inputFormat == IVAS_ENC_INPUT_MONO ) ? true : false ); + } + + /* Prevent maxBandwidth from being higher than inputFs/2 */ + if ( arg->inputFs == 8000 && arg->maxBandwidth > IVAS_ENC_BANDWIDTH_NB ) + { + arg->maxBandwidth = IVAS_ENC_BANDWIDTH_NB; + } + else if ( arg->inputFs == 16000 && arg->maxBandwidth > IVAS_ENC_BANDWIDTH_WB ) + { + arg->maxBandwidth = IVAS_ENC_BANDWIDTH_WB; + } + else if ( arg->inputFs == 32000 && arg->maxBandwidth > IVAS_ENC_BANDWIDTH_SWB ) + { + arg->maxBandwidth = IVAS_ENC_BANDWIDTH_SWB; + } + + /*-----------------------------------------------------------------* + * Input file + *-----------------------------------------------------------------*/ + + if ( i < argc - 1 ) + { + arg->inputWavFilename = argv[i]; + i++; + } + else + { + fprintf( stderr, "Error: no input file specified\n\n" ); + usage_enc(); + return false; + } + + /*-----------------------------------------------------------------* + * Output bitstream file + *-----------------------------------------------------------------*/ + + if ( i < argc ) + { + arg->outputBitstreamFilename = argv[i]; + i++; + } + else + { + fprintf( stderr, "Error: no output bitstream file specified\n\n" ); + usage_enc(); + return false; + } + + return true; +} + + +/*---------------------------------------------------------------------* + * usage_enc() + * + * Print the usage of the "ivas_cod" program + *---------------------------------------------------------------------*/ + +static void usage_enc( void ) +{ + fprintf( stdout, "Usage: IVAS_cod.exe [Options] R Fs input_file bitstream_file\n\n" ); + + fprintf( stdout, "Mandatory parameters:\n" ); + fprintf( stdout, "---------------------\n" ); + + fprintf( stdout, "R : Bitrate in bps, \n" ); + fprintf( stdout, " for EVS native modes R = (5900*, 7200, 8000, 9600, 13200, 16400,\n" ); + fprintf( stdout, " 24400, 32000, 48000, 64000, 96000, 128000) \n" ); + fprintf( stdout, " *VBR mode (average bitrate),\n" ); + fprintf( stdout, " for AMR-WB IO modes R = (6600, 8850, 12650, 14250, 15850, 18250,\n" ); + fprintf( stdout, " 19850, 23050, 23850) \n" ); + fprintf( stdout, " for IVAS stereo R = (13200, 16400, 24400, 32000, 48000, 64000, 80000, \n" ); + fprintf( stdout, " 96000, 128000, 160000, 192000, 256000) \n" ); + fprintf( stdout, " for IVAS ISM R = 13200 for 1 ISM, 16400 for 1 ISM and 2 ISM, \n" ); + fprintf( stdout, " (24400, 32000, 48000, 64000, 80000, 96000, 128000) \n" ); + fprintf( stdout, " for 2 ISM, 3 ISM and 4 ISM also 160000, 192000, 256000) \n" ); + fprintf( stdout, " for 3 ISM and 4 ISM also 384000 \n" ); + fprintf( stdout, " for 4 ISM also 512000 \n" ); + fprintf( stdout, " for IVAS SBA, MASA, MC, ISM-SBA, and ISM-MASA R=(13200, 16400, 24400, 32000, 48000, 64000,\n" ); + fprintf( stdout, " 80000, 96000, 128000, 160000, 192000, 256000, 384000, 512000) \n" ); + fprintf( stdout, " Alternatively, R can be a bitrate switching file which consists of R values\n" ); + fprintf( stdout, " indicating the bitrate for each frame in bps. These values are stored in\n" ); + fprintf( stdout, " binary format using 4 bytes per value\n" ); + fprintf( stdout, "Fs : Input sampling rate in kHz, Fs = (8, 16, 32 or 48) \n" ); + + fprintf( stdout, "input_file : Input audio filename \n" ); + fprintf( stdout, "bitstream_file : Output bitstream filename \n\n" ); + + fprintf( stdout, "Options:\n" ); + fprintf( stdout, "--------\n" ); + fprintf( stdout, "EVS mono is default, for IVAS choose one of the following: -stereo, -ism, -sba, -masa, -mc, -ism_sba, -ism_masa\n" ); + fprintf( stdout, "-stereo : Stereo format \n" ); + fprintf( stdout, "-ism (+)Ch Files : ISM format \n" ); + fprintf( stdout, " where Ch specifies the number of ISMs (1-4)\n" ); + fprintf( stdout, " where positive (+) indicates extended metadata (only 64 kbps and up) \n" ); + fprintf( stdout, " and Files specify input files containing metadata, one file per object\n" ); + fprintf( stdout, " (use NULL for no input metadata)\n" ); + fprintf( stdout, "-sba +/-Order : Scene Based Audio input format (Ambisonics ACN/SN3D),\n" ); + fprintf( stdout, " where Order specifies the Ambisionics order (1-3),\n" ); + fprintf( stdout, " where positive (+) means full 3D and negative (-) only 2D/planar components to be coded\n" ); + fprintf( stdout, "-masa Ch File : MASA format \n" ); + fprintf( stdout, " where Ch specifies the number of MASA input/transport channels (1 or 2): \n" ); + fprintf( stdout, " and File specifies input file containing parametric MASA metadata \n" ); + fprintf( stdout, "-ism_sba IsmCh +/-Order IsmFiles : SBA and ISM combined format\n" ); + fprintf( stdout, " where IsmCh specifies the number of ISMs (1-4)\n" ); + fprintf( stdout, " and Order specifies the SBA order (1 to 3) \n" ); + fprintf( stdout, " and IsmFiles specify input files containing ISM metadata, one file per object \n" ); + fprintf( stdout, "-ism_masa IsmCh MasaCh IsmFiles MasaFile : MASA and ISM combined format \n" ); + fprintf( stdout, " where IsmCh specifies the number of ISMs (1-4),\n" ); + fprintf( stdout, " MasaCh specifies the number of MASA input/transport channels (1-2), \n" ); + fprintf( stdout, " IsmFiles specify input files containing ISM metadata, one file per object, \n" ); + fprintf( stdout, " and MasaFile specifies input file containing parametric MASA metadata \n" ); + fprintf( stdout, "-mc InputConf : Multi-channel format\n" ); + fprintf( stdout, " where InputConf specifies the channel configuration: 5_1, 7_1, 5_1_2, 5_1_4, 7_1_4\n" ); + fprintf( stdout, " Loudspeaker positions are assumed to have azimuth and elevation as per \n" ); + fprintf( stdout, " ISO/IEC 23091-3:2018 Table 3. Channel order is as per ISO/IEC 23008-3:2015 Table 95.\n" ); + fprintf( stdout, " See readme.txt for details.\n" ); + fprintf( stdout, "-dtx D : Activate DTX mode, D = (0, 3-100) is the SID update rate\n" ); + fprintf( stdout, " where 0 = adaptive, 3-100 = fixed in number of frames,\n" ); + fprintf( stdout, " default is deactivated\n" ); + fprintf( stdout, "-dtx : Activate DTX mode with a SID update rate of 8 frames\n" ); + fprintf( stdout, " Note: DTX is supported in EVS, stereo, ISM, SBA up to 80kbps and MASA up to 128kbps \n" ); + fprintf( stdout, "-rf p o : Activate channel-aware mode for WB and SWB signal at 13.2kbps, \n" ); + fprintf( stdout, " where FEC indicator, p: LO or HI, and FEC offset, o: 2, 3, 5, or 7 in number of frames.\n" ); + fprintf( stdout, " Alternatively p and o can be replaced by a rf configuration file with each line \n" ); + fprintf( stdout, " contains the values of p and o separated by a space, \n" ); + fprintf( stdout, " default is deactivated \n" ); + fprintf( stdout, "-max_band B : Activate bandwidth limitation, B = (NB, WB, SWB or FB)\n" ); + fprintf( stdout, " alternatively, B can be a text file where each line contains \"nb_frames B\"\n" ); + fprintf( stdout, "-no_delay_cmp : Turn off delay compensation\n" ); + fprintf( stdout, "-stereo_dmx_evs : Activate stereo downmix function for EVS.\n" ); + fprintf( stdout, "-binaural : Optional indication that input is binaural audio (to be used with -stereo or -stereo_dmx_evs)\n" ); + fprintf( stdout, "-mime : Mime output bitstream file format\n" ); + fprintf( stdout, " The encoder produces TS26.445 Annex.2.6 Mime Storage Format, (not RFC4867 Mime Format).\n" ); + fprintf( stdout, " default output bitstream file format is G.192\n" ); + fprintf( stdout, "-pca : activate PCA in SBA format FOA at 256 kbps \n" ); + fprintf( stdout, "-level level : Complexity level, level = (1, 2, 3), will be defined after characterisation. \n" ); + fprintf( stdout, " Currently, all values default to level 3 (full functionality).\n" ); +#ifdef DEBUGGING + fprintf( stdout, "-force T : Force specific mode, T = (speech, music, ACELP, GSC, TCX, HQ),\n" ); + fprintf( stdout, " alternatively, T can be a text file where each line contains \"nb_frames T\"\n" ); +#ifdef DEBUG_SBA + fprintf( stdout, "-tag : Tag name for intermediate debug files\n" ); +#endif +#ifdef DEBUG_AGC_ENCODER_CMD_OPTION + fprintf( stdout, "-agc op : SBA Adaptive gain control, op = (0, 1). \n" ); + fprintf( stdout, " By default op is 1 (activated) for bitrates between 24400 and 32000,\n" ); + fprintf( stdout, " otherwise it is 0 (deactivated) for all other bitrates\n" ); +#endif +#ifdef DEBUG_MODE_INFO +#ifdef DEBUG_MODE_INFO_TWEAK + fprintf( stdout, "-info : specify subfolder name for debug output\n" ); +#endif +#endif +#endif + fprintf( stdout, "-q : Quiet mode, no frame counters\n" ); + fprintf( stdout, " default is deactivated\n" ); +#ifdef IVAS_RTPDUMP + fprintf( stdout, "-rtpdump : RTPDump output, hf_only=1 by default. The encoder will packetize the \n" ); + fprintf( stdout, " bitstream frames into TS26.253 Annex A IVAS RTP Payload Format packets and \n" ); + fprintf( stdout, " writes those to the output file. In EVS mono operating mode, TS26.445 Annex A.2.2 \n" ); + fprintf( stdout, " EVS RTP Payload Format is used. Optional N represents number of frames per RTP packet\n" ); + fprintf( stdout, "-scene_orientation : Scene orientation trajectory file. Only used with rtpdump output.\n" ); + fprintf( stdout, "-device_orientation : Device orientation trajectory file. Only used with rtpdump output.\n" ); +#endif + fprintf( stdout, "\n" ); + + return; +} + + +/*---------------------------------------------------------------------* + * readBandwidth() + * + * + *---------------------------------------------------------------------*/ + +static bool readBandwidth( + FILE *file, + IVAS_ENC_BANDWIDTH *bandwidth, + int32_t *bandwidthFrameCounter ) +{ + int16_t res; + char stmp[4]; + + if ( *bandwidthFrameCounter == 0 ) + { + /* read next bandwidth value and number of frames from the profile file */ + while ( ( res = (int16_t) fscanf( file, "%d %3s", bandwidthFrameCounter, stmp ) ) != 2 && feof( file ) ) + { + rewind( file ); + } + + ( *bandwidthFrameCounter )--; + + to_upper( stmp ); + + if ( strcmp( stmp, "NB" ) == 0 ) + { + *bandwidth = IVAS_ENC_BANDWIDTH_NB; + } + else if ( strcmp( stmp, "WB" ) == 0 ) + { + *bandwidth = IVAS_ENC_BANDWIDTH_WB; + } + else if ( strcmp( stmp, "SWB" ) == 0 ) + { + *bandwidth = IVAS_ENC_BANDWIDTH_SWB; + } + else if ( strcmp( stmp, "FB" ) == 0 ) + { + *bandwidth = IVAS_ENC_BANDWIDTH_FB; + } + else + { + fprintf( stderr, "Error: incorrect bandwidth specified (only NB, WB, SWB and FB are supported)\n\n" ); + usage_enc(); + return false; + } + } + else + { + /* current profile still active, only decrease the counter */ + ( *bandwidthFrameCounter )--; + } + + return true; +} + + +/*---------------------------------------------------------------------* + * readBitrate() + * + * + *---------------------------------------------------------------------*/ + +static bool readBitrate( + FILE *file, + int32_t *bitrate ) +{ + for ( int32_t i = 0; i < 2; ++i ) + { + if ( fread( bitrate, sizeof( int32_t ), 1, file ) == 1 ) + { + return true; + } + + rewind( file ); + } + + fprintf( stderr, "Error: cannot read the bitrate profile file\n\n" ); + usage_enc(); + return false; +} + + +#ifdef DEBUGGING +/*---------------------------------------------------------------------* + * parseForcedMode() + * + * + *---------------------------------------------------------------------*/ + +static IVAS_ENC_FORCED_MODE parseForcedMode( + char *forcedModeChar ) +{ + to_upper( forcedModeChar ); + + if ( ( strcmp( forcedModeChar, "SPEECH" ) == 0 ) || ( strcmp( forcedModeChar, "'SPEECH'" ) == 0 ) || + ( strcmp( forcedModeChar, "0" ) == 0 ) ) + { + return IVAS_ENC_FORCE_SPEECH; + } + if ( ( strcmp( forcedModeChar, "MUSIC" ) == 0 ) || ( strcmp( forcedModeChar, "'MUSIC'" ) == 0 ) || ( strcmp( forcedModeChar, "AUDIO" ) == 0 ) || ( strcmp( forcedModeChar, "'AUDIO'" ) == 0 ) || ( strcmp( forcedModeChar, "1" ) == 0 ) ) + { + return IVAS_ENC_FORCE_MUSIC; + } + if ( ( strcmp( forcedModeChar, "ACELP" ) == 0 ) || ( strcmp( forcedModeChar, "'ACELP'" ) == 0 ) ) + { + return IVAS_ENC_FORCE_ACELP; + } + if ( ( strcmp( forcedModeChar, "GSC" ) == 0 ) || ( strcmp( forcedModeChar, "'GSC'" ) == 0 ) ) + { + return IVAS_ENC_FORCE_GSC; + } + if ( ( strcmp( forcedModeChar, "TCX" ) == 0 ) || ( strcmp( forcedModeChar, "'TCX'" ) == 0 ) ) + { + return IVAS_ENC_FORCE_TCX; + } + if ( ( strcmp( forcedModeChar, "HQ" ) == 0 ) || ( strcmp( forcedModeChar, "'HQ'" ) == 0 ) ) + { + return IVAS_ENC_FORCE_HQ; + } + + return IVAS_ENC_FORCE_UNDEFINED; +} + + +/*---------------------------------------------------------------------* + * readForcedMode() + * + * + *---------------------------------------------------------------------*/ + +static ivas_error readForcedMode( + FILE *file, + IVAS_ENC_FORCED_MODE *forcedMode, + int32_t *forceFrameCounter ) +{ + int16_t res; + char stmp[8]; + + if ( *forceFrameCounter == 0 ) + { + /* read next force and number of frames from the profile file */ + while ( ( res = (int16_t) fscanf( file, "%d %7s", forceFrameCounter, stmp ) ) != 2 && feof( file ) ) + { + rewind( file ); + } + + *forcedMode = parseForcedMode( stmp ); + + if ( *forcedMode == IVAS_ENC_FORCE_UNDEFINED ) + { + fprintf( stderr, "Error: incorect mode specification or the force profile file could not be opened: %s\n\n", stmp ); + return IVAS_ERR_WRONG_PARAMS; + } + + if ( res != 2 && !feof( file ) ) + { + fprintf( stderr, "Error: incorrect format of the force profile file (please ensure that it does not contain any empty lines)\n\n" ); + return IVAS_ERR_WRONG_PARAMS; + } + } + + /* current profile still active, only decrease the counter */ + ( *forceFrameCounter )--; + + return IVAS_ERR_OK; +} +#endif + +#undef WMC_TOOL_SKIP diff --git a/lib_com/options.h b/lib_com/options.h index 682494ad64b4cd50e15f0382b960e89ceed17064..ab1471238cabbd3734d3b806baf98aeff1fad099 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -161,6 +161,7 @@ #define RTP_S4_251135_CR26253_0016_REV1 /* RTP Pack/Unpack API corresponding to CR 26253 */ #define IVAS_RTPDUMP /* RTPDUMP writing and reading for IVAS payloads */ +#define DECODER_FORMAT_SWITCHING /* Re-initialize the decoder when the format/subformat of the incoming stream is changed */ /* ################### Start BE switches ################################# */ /* only BE switches wrt selection floating point code */ diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 617a14b53fb53fae52ca0e142e235bc0211ee9bb..1072cfa6a9135bae212010afb3f538e0e9083b84 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -129,10 +129,15 @@ ivas_error ivas_dec_get_format( !( st_ivas->ivas_format == MASA_FORMAT && st_ivas->last_ivas_format == MASA_ISM_FORMAT ) && !( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->last_ivas_format == MASA_FORMAT ) ) { +#ifdef DECODER_FORMAT_SWITCHING + st_ivas->restartNeeded = 1; + return IVAS_ERR_OK; +#else #ifdef DEBUGGING fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); #endif return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); +#endif } /*-------------------------------------------------------------------* @@ -166,10 +171,15 @@ ivas_error ivas_dec_get_format( if ( st_ivas->ini_frame > 0 && nchan_ism != st_ivas->nchan_ism ) { +#ifdef DECODER_FORMAT_SWITCHING + st_ivas->restartNeeded = 1; + return IVAS_ERR_OK; +#else #ifdef DEBUGGING fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); #endif return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); +#endif } st_ivas->nchan_ism = nchan_ism; @@ -189,10 +199,15 @@ ivas_error ivas_dec_get_format( if ( st_ivas->ini_frame > 0 && sba_planar != st_ivas->sba_planar ) { +#ifdef DECODER_FORMAT_SWITCHING + st_ivas->restartNeeded = 1; + return IVAS_ERR_OK; +#else #ifdef DEBUGGING fprintf( stderr, "\nError: Changing the SBA planar/3D layout is not supported!\n" ); #endif return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA planar flag signalled!" ); +#endif } /* read Ambisonic (SBA) order */ @@ -201,10 +216,15 @@ ivas_error ivas_dec_get_format( if ( st_ivas->ini_frame > 0 && sba_order != st_ivas->sba_order ) { +#ifdef DECODER_FORMAT_SWITCHING + st_ivas->restartNeeded = 1; + return IVAS_ERR_OK; +#else #ifdef DEBUGGING fprintf( stderr, "\nError: Changing the SBA order is not supported!\n" ); #endif return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA order signalled!" ); +#endif } sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, sba_order ); @@ -215,11 +235,25 @@ ivas_error ivas_dec_get_format( /* read number of MASA transport channels */ if ( st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 1] ) { +#ifdef DECODER_FORMAT_SWITCHING + if ( st_ivas->nchan_transport == 1 ) + { + st_ivas->restartNeeded = 1; + return IVAS_ERR_OK; + } +#endif st_ivas->nchan_transport = 2; element_mode_flag = 1; } else { +#ifdef DECODER_FORMAT_SWITCHING + if ( st_ivas->nchan_transport == 2 ) + { + st_ivas->restartNeeded = 1; + return IVAS_ERR_OK; + } +#endif st_ivas->nchan_transport = 1; } @@ -250,10 +284,15 @@ ivas_error ivas_dec_get_format( if ( st_ivas->ini_frame > 0 && nchan_ism != st_ivas->nchan_ism ) { +#ifdef DECODER_FORMAT_SWITCHING + st_ivas->restartNeeded = 1; + return IVAS_ERR_OK; +#else #ifdef DEBUGGING fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); #endif return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); +#endif } st_ivas->nchan_ism = nchan_ism; @@ -268,10 +307,15 @@ ivas_error ivas_dec_get_format( if ( st_ivas->ini_frame > 0 && nchan_ism != st_ivas->nchan_ism ) { +#ifdef DECODER_FORMAT_SWITCHING + st_ivas->restartNeeded = 1; + return IVAS_ERR_OK; +#else #ifdef DEBUGGING fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); #endif return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); +#endif } st_ivas->nchan_ism = nchan_ism; @@ -283,10 +327,15 @@ ivas_error ivas_dec_get_format( if ( st_ivas->ini_frame > 0 && nchan_ism != st_ivas->nchan_ism ) { +#ifdef DECODER_FORMAT_SWITCHING + st_ivas->restartNeeded = 1; + return IVAS_ERR_OK; +#else #ifdef DEBUGGING fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); #endif return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); +#endif } st_ivas->nchan_ism = nchan_ism; @@ -310,10 +359,15 @@ ivas_error ivas_dec_get_format( if ( st_ivas->ini_frame > 0 && sba_order != st_ivas->sba_order ) { +#ifdef DECODER_FORMAT_SWITCHING + st_ivas->restartNeeded = 1; + return IVAS_ERR_OK; +#else #ifdef DEBUGGING fprintf( stderr, "\nError: Changing the SBA order is not supported!\n" ); #endif return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA order signalled!" ); +#endif } st_ivas->ism_mode = ivas_osba_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ); @@ -338,10 +392,15 @@ ivas_error ivas_dec_get_format( if ( st_ivas->ini_frame > 0 && st_ivas->transport_config != signaled_config ) { +#ifdef DECODER_FORMAT_SWITCHING + st_ivas->restartNeeded = 1; + return IVAS_ERR_OK; +#else #ifdef DEBUGGING fprintf( stderr, "\nError: Switching of MC configurations is not supported!\n" ); #endif return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "wrong MC configuration signalled!" ); +#endif } st_ivas->mc_mode = ivas_mc_mode_select( ivas_mc_map_output_config_to_mc_ls_setup( signaled_config ), st_ivas->hDecoderConfig->ivas_total_brate ); @@ -423,10 +482,15 @@ ivas_error ivas_dec_get_format( if ( st_ivas->ini_frame > 0 && nchan_ism != st_ivas->nchan_ism ) { +#ifdef DECODER_FORMAT_SWITCHING + st_ivas->restartNeeded = 1; + return IVAS_ERR_OK; +#else #ifdef DEBUGGING fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); #endif return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); +#endif } st_ivas->nchan_ism = nchan_ism; diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index f1efb32a1019670330be0bc7f647dbadc404a0d3..dfecc61a01f0959b714559c0d9e0e54de925daae 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1147,6 +1147,9 @@ typedef struct Decoder_Struct #ifdef TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR int16_t flushing; #endif +#ifdef DECODER_FORMAT_SWITCHING + int8_t restartNeeded; /* Flag to check if the decoder requires a restart */ +#endif } Decoder_Struct; diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index dc71db8e697e9a28720358b9f76ed13006681b3f..296f1618cfe10b01b524301ca3f2ee3356b6d545 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -222,6 +222,10 @@ ivas_error IVAS_DEC_Open( /* initialize pointers to handles to NULL */ ivas_initialize_handles_dec( st_ivas ); +#ifdef DECODER_FORMAT_SWITCHING + st_ivas->restartNeeded = 0; +#endif + /* set high-level parameters */ if ( mode == IVAS_DEC_MODE_EVS ) { @@ -1011,7 +1015,6 @@ ivas_error IVAS_DEC_ReadFormat( { ivas_error error; Decoder_Struct *st_ivas; - IVAS_FORMAT ivas_format_old; ISM_MODE ism_mode_old; MC_MODE mc_mode_old; int16_t nchan_transport_old; @@ -1024,7 +1027,6 @@ ivas_error IVAS_DEC_ReadFormat( } st_ivas = hIvasDec->st_ivas; - ivas_format_old = st_ivas->ivas_format; ism_mode_old = st_ivas->ism_mode; mc_mode_old = st_ivas->mc_mode; nchan_transport_old = st_ivas->nchan_transport; @@ -1047,10 +1049,17 @@ ivas_error IVAS_DEC_ReadFormat( return error; } +#ifdef DECODER_FORMAT_SWITCHING + if ( st_ivas->restartNeeded > 0 ) + { + return IVAS_ERR_OK; + } +#else if ( ivas_format_old != st_ivas->ivas_format && st_ivas->ini_frame > 0 && !( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT ) ) { return ( IVAS_ERROR( IVAS_ERR_INVALID_INPUT_FORMAT, "IVAS format switching is not allowed." ) ); } +#endif /* Select binaural renderer */ ivas_renderer_select( st_ivas ); @@ -2503,10 +2512,20 @@ ivas_error IVAS_DEC_GetFormat( *format = IVAS_DEC_BS_UNKOWN; } +#ifdef DECODER_FORMAT_SWITCHING + if ( *format == IVAS_DEC_BS_MASA && hIvasDec->st_ivas->hMasa != NULL ) + { + if ( hIvasDec->st_ivas->hMasa->config.input_ivas_format == MASA_ISM_FORMAT ) + { + *format = IVAS_DEC_BS_MASA_ISM; + } + } +#else if ( *format == IVAS_DEC_BS_MASA && hIvasDec->st_ivas->hMasa->config.input_ivas_format == MASA_ISM_FORMAT ) { *format = IVAS_DEC_BS_MASA_ISM; } +#endif return IVAS_ERR_OK; } @@ -4218,6 +4237,22 @@ ivas_error IVAS_DEC_Flush( } +#ifdef DECODER_FORMAT_SWITCHING +/*---------------------------------------------------------------------* + * IVAS_DEC_isRestartNeeded( ) + * + * + *---------------------------------------------------------------------*/ + +bool IVAS_DEC_isRestartNeeded( + IVAS_DEC_HANDLE hIvasDec /* i/o: IVAS decoder handle */ +) +{ + return hIvasDec->st_ivas->restartNeeded > 0; +} + + +#endif /*---------------------------------------------------------------------* * IVAS_DEC_VoIP_IsEmpty( ) * diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index f20984c5ee729157d075ed34cff6e3b3e4eac98f..915937526f00280fe72ab214e0a62c226923c4ed 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -339,6 +339,12 @@ ivas_error IVAS_DEC_Flush( int16_t *nSamplesFlushed /* o : number of samples flushed */ ); +#ifdef DECODER_FORMAT_SWITCHING +bool IVAS_DEC_isRestartNeeded( + IVAS_DEC_HANDLE hIvasDec /* i/o: IVAS decoder handle */ +); + +#endif /* Setter functions - apply changes to decoder configuration */ /*! r: error code */ diff --git a/lib_util/ivas_rtp_file.c b/lib_util/ivas_rtp_file.c index 8555480efd332900c9fceda25bd914b60bd9e18e..f2c804fe045f813f9a3181bac018c34c01cc60bf 100644 --- a/lib_util/ivas_rtp_file.c +++ b/lib_util/ivas_rtp_file.c @@ -31,6 +31,9 @@ *******************************************************************************************************/ #include #include +#include +#include // stat +#include // bool type #include "ivas_rtp_file.h" #include "ivas_error_utils.h" @@ -46,8 +49,10 @@ static ivas_error IvasRtpFile_Open( IVAS_RTP_FILE_HANDLE *phRtpFile /* o : pointer to an IVAS file reader handle */ ) { - const char *mode = isFileWriter ? "wb" : "rb"; - FILE *f_rtpstream = fopen( filePath, mode ); + FILE *f_rtpstream; + char *mode = isFileWriter ? "wb" : "rb"; + + f_rtpstream = fopen( filePath, mode ); if ( f_rtpstream == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_FILE_OPEN, "could not open: %s\n", filePath ); diff --git a/tests/conftest.py b/tests/conftest.py index 6f293b9502b058903416b4d99f4601055300c26e..9e2948ca23cdbab4136b6f93c357e1f9954ee0f9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -570,6 +570,7 @@ class EncoderFrontend: run_dir: Optional[Path] = None, stats_file: Optional[Path] = None, compare_enc_dmx: Optional[bool] = False, + fmtsw_command: Optional[bool] = False, ) -> None: command = [str(self._path)] @@ -593,12 +594,17 @@ class EncoderFrontend: command.extend(add_option_list) # add mandatory parameters - command += [ - str(bitrate), - str(input_sampling_rate), - str(input_path), - str(output_bitstream_path), - ] + if fmtsw_command: + command += [ + str(input_path), + ] + else: + command += [ + str(bitrate), + str(input_sampling_rate), + str(input_path), + str(output_bitstream_path), + ] cmd_str = textwrap.indent(" ".join(command), prefix="\t") log_dbg_msg(f"{self._type} encoder command:\n{cmd_str}") diff --git a/tests/create_short_testvectors.py b/tests/create_short_testvectors.py index a478e315e242bb62069152b47378eb163c8bf0cc..cadfd1d9b7154df7aee83c0a50345c4807b0a0db 100755 --- a/tests/create_short_testvectors.py +++ b/tests/create_short_testvectors.py @@ -38,7 +38,7 @@ import argparse import sys from pathlib import Path -from cut_pcm import cut_samples +from tests.cut_pcm import cut_samples HERE = Path(__file__).parent.resolve() TEST_VECTOR_DIR = HERE.joinpath("../scripts/testv").resolve() @@ -50,6 +50,7 @@ from pyaudio3dtools import audiofile CUT_FROM = "0.0" GAIN = "1.0" FILE_IDS = [ + "stv", "stvST", "stv51MC", "stv71MC", diff --git a/tests/rtp/ivasrtp.py b/tests/rtp/ivasrtp.py index bd13acaf565992ad17aeae6922c41ae2295d06d6..98dca3bf4e422b9e01988457c0f46f22411d2232 100644 --- a/tests/rtp/ivasrtp.py +++ b/tests/rtp/ivasrtp.py @@ -1446,55 +1446,57 @@ class IvasRtp: fd.write(json_output) def requestReader(self, timestamp: int) -> dict[str, any]: - tsList = sorted(self.requests.keys()) - if len(tsList) > 0: - lastTs = int(tsList[0]) - for ts in tsList: - if timestamp >= lastTs and timestamp < int(ts): - return self.requests[str(lastTs)] - lastTs = int(ts) + if self.requests is not None: + tsList = sorted(self.requests.keys()) + if len(tsList) > 0: + lastTs = int(tsList[0]) + for ts in tsList: + if timestamp >= lastTs and timestamp < int(ts): + return self.requests[str(lastTs)] + lastTs = int(ts) return dict() def piDataReader(self, startTimestamp: int, endTimestamp: int) -> list[PIDATA]: piDataList = list() - while startTimestamp < endTimestamp: - ts = str(startTimestamp) - if ts in self.piData.keys(): - for piTypes in self.piData[ts].keys(): - dataDict = self.piData[ts][piTypes] - if type(dataDict) != dict: - data = dataDict - elif piTypes == PIDATAS.ISM_ORIENTATION: - data = list() - for orientation in dataDict: - data.append(ORIENTATION(**orientation)) - elif ( - "ORIENTATION" in piTypes - or piTypes == PIDATAS.AUDIO_FOCUS_DIRECTION - ): - data = ORIENTATION(**dataDict) - elif piTypes == PIDATAS.ACOUSTIC_ENVIRONMENT: - data = ACOUSTIC_ENVIRONMENT(**dataDict) - elif piTypes == PIDATAS.AUDIO_DESCRIPTION: - data = list() - for desc in dataDict: - data.append(AUDIO_DESCRIPTION(**desc)) - elif piTypes == PIDATAS.DIEGETIC_TYPE: - data = DIEGETIC_TYPE(**dataDict) - elif ( - piTypes == PIDATAS.LISTENER_POSITION - or piTypes == PIDATAS.R_ISM_POSITION - ): - data = POSITION(**dataDict) - elif piTypes == PIDATAS.DYNAMIC_AUDIO_SUPPRESSION: - data = DYNAMIC_AUDIO_SUPPRESSION(**dataDict) - else: - assert False, "Unhandled PI Data" - piDataList.append( - PIDATA(timestamp=startTimestamp, type=piTypes, data=data) - ) - startTimestamp += 320 + if self.piData is not None: + while startTimestamp < endTimestamp: + ts = str(startTimestamp) + if ts in self.piData.keys(): + for piTypes in self.piData[ts].keys(): + dataDict = self.piData[ts][piTypes] + if type(dataDict) != dict: + data = dataDict + elif piTypes == PIDATAS.ISM_ORIENTATION: + data = list() + for orientation in dataDict: + data.append(ORIENTATION(**orientation)) + elif ( + "ORIENTATION" in piTypes + or piTypes == PIDATAS.AUDIO_FOCUS_DIRECTION + ): + data = ORIENTATION(**dataDict) + elif piTypes == PIDATAS.ACOUSTIC_ENVIRONMENT: + data = ACOUSTIC_ENVIRONMENT(**dataDict) + elif piTypes == PIDATAS.AUDIO_DESCRIPTION: + data = list() + for desc in dataDict: + data.append(AUDIO_DESCRIPTION(**desc)) + elif piTypes == PIDATAS.DIEGETIC_TYPE: + data = DIEGETIC_TYPE(**dataDict) + elif ( + piTypes == PIDATAS.LISTENER_POSITION + or piTypes == PIDATAS.R_ISM_POSITION + ): + data = POSITION(**dataDict) + elif piTypes == PIDATAS.DYNAMIC_AUDIO_SUPPRESSION: + data = DYNAMIC_AUDIO_SUPPRESSION(**dataDict) + else: + assert False, "Unhandled PI Data" + piDataList.append( + PIDATA(timestamp=startTimestamp, type=piTypes, data=data) + ) + startTimestamp += 320 return piDataList def packG192File( diff --git a/tests/rtp/test_format_switching.py b/tests/rtp/test_format_switching.py new file mode 100644 index 0000000000000000000000000000000000000000..54a16472fa2b2a822f772931cb3ab2b0d4ced9fe --- /dev/null +++ b/tests/rtp/test_format_switching.py @@ -0,0 +1,275 @@ +#!/usr/bin/env python3 + +__copyright__ = """ +(C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, +Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., +Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, +Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other +contributors to this repository. All Rights Reserved. + +This software is protected by copyright law and by international treaties. +The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, +Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., +Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, +Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other +contributors to this repository retain full ownership rights in their respective contributions in +the software. This notice grants no license of any kind, including but not limited to patent +license, nor is any license granted by implication, estoppel or otherwise. + +Contributors are required to enter into the IVAS codec Public Collaboration agreement before making +contributions. + +This software is provided "AS IS", without any express or implied warranties. The software is in the +development stage. It is intended exclusively for experts who have experience with such software and +solely for the purpose of inspection. All implied warranties of non-infringement, merchantability +and fitness for a particular purpose are hereby disclaimed and excluded. + +Any dispute, controversy or claim arising under or in relation to providing this software shall be +submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in +accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and +the United Nations Convention on Contracts on the International Sales of Goods. +""" + +__doc__ = """ +To configure test modules. +""" + +import pytest +import csv +import os +import sys +import random + +from tempfile import TemporaryDirectory +from pathlib import Path +import soundfile as sf +import numpy as np + +ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) +sys.path.append(ROOT_DIR) + +from tests.conftest import EncoderFrontend, DecoderFrontend +from tests.create_short_testvectors import create_short_testvectors +from tests.renderer.constants import ( + FORMAT_TO_FILE_COMPARETEST, + FORMAT_TO_METADATA_FILES, +) +from ivasrtp import * +import platform + +BIN_EXT = ".exe" if platform.system() == "Windows" else "" + +FORMAT_ARGUMENT_MAPPING = { + "MONO": [], + "STEREO": ["-stereo"], + "5_1": ["-mc", "5_1"], + "7_1": ["-mc", "7_1"], + "5_1_2": ["-mc", "5_1_2"], + "5_1_4": ["-mc", "5_1_4"], + "7_1_4": ["-mc", "7_1_4"], + "FOA": ["-sba", "+1"], + "HOA2": ["-sba", "+2"], + "HOA3": ["-sba", "+3"], + "ISM1": ["-ism", "1"], + "ISM2": ["-ism", "2"], + "ISM3": ["-ism", "3"], + "ISM4": ["-ism", "4"], + "MASA1": ["-masa", "1"], + "MASA2": ["-masa", "2"], + "ISM1MASA1": ["-ism_masa", "1", "1"], + "ISM2MASA1": ["-ism_masa", "2", "1"], + "ISM3MASA1": ["-ism_masa", "3", "1"], + "ISM4MASA1": ["-ism_masa", "4", "1"], + "ISM1MASA2": ["-ism_masa", "1", "2"], + "ISM2MASA2": ["-ism_masa", "2", "2"], + "ISM3MASA2": ["-ism_masa", "3", "2"], + "ISM4MASA2": ["-ism_masa", "4", "2"], + "ISM1SBA1": ["-ism_sba", "1", "+1"], + "ISM1SBA2": ["-ism_sba", "1", "+2"], + "ISM1SBA3": ["-ism_sba", "1", "+3"], + "ISM2SBA1": ["-ism_sba", "2", "+1"], + "ISM2SBA2": ["-ism_sba", "2", "+2"], + "ISM2SBA3": ["-ism_sba", "2", "+3"], + "ISM3SBA1": ["-ism_sba", "3", "+1"], + "ISM3SBA2": ["-ism_sba", "3", "+2"], + "ISM3SBA3": ["-ism_sba", "3", "+3"], + "ISM4SBA1": ["-ism_sba", "4", "+1"], + "ISM4SBA2": ["-ism_sba", "4", "+2"], + "ISM4SBA3": ["-ism_sba", "4", "+3"], +} + +def test_format_switching ( + dut_encoder_frontend: EncoderFrontend, + dut_decoder_frontend: DecoderFrontend +): + bitrate = 48000 + bandwidth = "FB" + outMode = "MONO" + + # Create 1s test files + cut_suffix = "_cut.wav" + test_file = Path( str(FORMAT_TO_FILE_COMPARETEST["MONO"]).replace(".wav", cut_suffix) ) + if not test_file.exists(): + create_short_testvectors(1.0, False, None) + + with TemporaryDirectory() as tmp_dir: + bitstreams = [] + rtpdumps = [] + codec=CODECS.IVAS + + #if key is "MONO": + # codec=CODECS.EVS + #else: + # codec=CODECS.IVAS + rtpPacker = IvasRtp(numFramesPerPacket=1, codec=codec) + piData = dict() + requestsData = dict() + + # Encode subformats + for key, audioFile in FORMAT_TO_FILE_COMPARETEST.items(): + if key in ["META", "16ch_8+4+4", "4d4", "t_design_4"]: + break + + encoder_args = [] + cutFile = Path( str(audioFile).replace(".wav", cut_suffix) ) + encoder_args += FORMAT_ARGUMENT_MAPPING[key] + if key in FORMAT_TO_METADATA_FILES: + encoder_args += FORMAT_TO_METADATA_FILES[key] + elif "SBA" in key: + # ISM metadata files for OSBA + encoder_args += FORMAT_TO_METADATA_FILES[key[:4]] + + temp_bitstream = Path(tmp_dir).joinpath(f"output-{bitrate}-{bandwidth}-{key}.bts").absolute() + temp_rtpdump = Path(tmp_dir).joinpath(f"output-{bitrate}-{bandwidth}-{key}.rtpdump").absolute() + + dut_encoder_frontend.run( + bitrate=bitrate, + input_sampling_rate=48, + input_path=cutFile, + output_bitstream_path=temp_bitstream, + sba_order=None, + dtx_mode=False, + max_band=bandwidth, + add_option_list=encoder_args + ) + bitstreams.append(temp_bitstream) + + # Combine bitstreams + cat_bitstream_no_evs = Path(tmp_dir).joinpath(f"output-{bitrate}-{bandwidth}-NO-EVS-CAT.bts").absolute() + cat_rtpdump = Path(tmp_dir).joinpath(f"output-{bitrate}-{bandwidth}-CAT.rtpdump").absolute() + cat_rtpdump_no_evs = Path(tmp_dir).joinpath(f"output-{bitrate}-{bandwidth}-NO-EVS-CAT.rtpdump").absolute() + catBsNoEVS = bytes() + catRTP = bytes() + catRTPnoEVS = bytes() + + for bsFile in bitstreams: + if "MONO" not in str(bsFile): + with open (bsFile, mode="rb") as fd: + catBsNoEVS += fd.read() + with open (cat_bitstream_no_evs, mode="wb") as outFile: + outFile.write(catBsNoEVS) + + # TODO: also pack EVS packets (while increasing timestamp and sequence number) + # Pack to RTP packets + rtpPacker.packG192File(g192File=cat_bitstream_no_evs, rtpDumpOut=cat_rtpdump_no_evs, piData=piData, requestsData=requestsData) + #rtpdumps.append(temp_rtpdump) + + #for rtpdumpFile in rtpdumps: + # with open (rtpdumpFile, mode="rb") as fd: + # tempBits = fd.read() + # catRTP += tempBits + # if "MONO" not in str(rtpdumpFile): + # catRTPnoEVS += tempBits + #with open (cat_rtpdump, mode="wb") as outFile: + # outFile.write(catRTP) + #with open (cat_rtpdump_no_evs, mode="wb") as outFile: + # outFile.write(catRTPnoEVS) + + # Decode the combined bitstreams + cat_output_no_evs = Path(tmp_dir).joinpath(f"output-{bitrate}-{bandwidth}-NO-EVS-CAT.wav").absolute() + cat_output_rtpdump = Path(tmp_dir).joinpath(f"output-{bitrate}-{bandwidth}.wav").absolute() + dut_decoder_frontend.run( + output_config=outMode, + output_sampling_rate=48, + input_bitstream_path=cat_bitstream_no_evs, + output_path=cat_output_no_evs, + add_option_list= [] + ) + dut_decoder_frontend.run( + output_config=outMode, + output_sampling_rate=48, + input_bitstream_path=cat_rtpdump, + output_path=cat_output_rtpdump, + add_option_list= ["-VOIP_HF_ONLY=1"] + ) + + +def test_format_switching_new_encoder ( + record_property, + dut_decoder_frontend: DecoderFrontend +): + bitrate = 48000 + fs = 48 + bandwidth = "FB" + outMode = "MONO" + + dut_encoder_path = Path(ROOT_DIR).joinpath(f"IVAS_cod{BIN_EXT}") + dut_encoder_fmtsw_path = Path(ROOT_DIR).joinpath(f"IVAS_cod_fmtsw{BIN_EXT}") + dut_encoder_fmtsw_frontend = EncoderFrontend( + dut_encoder_fmtsw_path, "DUT", record_property + ) + + # Create 1s test files + cut_suffix = "_cut.wav" + test_file = Path( str(FORMAT_TO_FILE_COMPARETEST["MONO"]).replace(".wav", cut_suffix) ) + if not test_file.exists(): + create_short_testvectors(1.0, False, None) + + with TemporaryDirectory() as tmp_dir: + + # Create file for encoding commands + temp_format_switching_file = Path(tmp_dir).joinpath("format_switching_input.txt").absolute() + temp_rtpdump = Path(tmp_dir).joinpath("output_concatenated.rtpdump").absolute() + with open (temp_format_switching_file, mode="a") as outFile: + for key, audioFile in FORMAT_TO_FILE_COMPARETEST.items(): + if key in ["META", "16ch_8+4+4", "4d4", "t_design_4"]: + break + + encoder_args = [] + encoder_args += [str(dut_encoder_path)] + encoder_args += ["-rtpdump", "1"] + encoder_args += FORMAT_ARGUMENT_MAPPING[key] + if key in FORMAT_TO_METADATA_FILES: + encoder_args += FORMAT_TO_METADATA_FILES[key] + elif "SBA" in key: + # ISM metadata files for OSBA + encoder_args += FORMAT_TO_METADATA_FILES[key[:4]] + encoder_args += [str(bitrate)] + encoder_args += [str(fs)] + cutFile = Path( str(audioFile).replace(".wav", cut_suffix) ) + encoder_args += [str(cutFile)] + encoder_args += [str(temp_rtpdump)] + + outFile.write(' '.join(encoder_args)) + outFile.write("\n") + + # Encode with the format switch encoder + dut_encoder_fmtsw_frontend.run( + bitrate='', + input_sampling_rate='', + input_path=temp_format_switching_file, + output_bitstream_path='', + quiet_mode=False, + fmtsw_command=True + ) + + # Decode the combined bitstreams + cat_output_rtpdump = Path(tmp_dir).joinpath(f"output_concatenated.wav").absolute() + + dut_decoder_frontend.run( + output_config=outMode, + output_sampling_rate=48, + input_bitstream_path=temp_rtpdump, + output_path=cat_output_rtpdump, + add_option_list= ["-VOIP_HF_ONLY=1"] + )