diff --git a/apps/decoder.c b/apps/decoder.c index c47d8eadb30893f277ac09c45a63f9799ba6b9d7..c31d4cd5cde0286a920d17b1f72e9f1ac8cb7287 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -55,13 +55,7 @@ #ifdef IVAS_RTPDUMP #include "ivas_rtp_file.h" #endif -#ifdef IVAS_RTPDUMP_ACOUSTIC_ENVIRONMENT -#include "ivas_cnst.h" -#endif -#ifdef FIXED_RTP_SEQUENCE_NUM -#define RANDOM_INITSEED_DEC ( 0xFEEDFADE ) -#endif #define WMC_TOOL_SKIP @@ -74,6 +68,10 @@ static #endif int32_t frame = 0; /* Counter of frames */ +#ifdef FIXED_RTP_SEQUENCE_NUM +#define RANDOM_INITSEED_DEC ( 0xFEEDFADE ) +#endif + #ifdef DEBUGGING #define MIN_NUM_BITS_ACTIVE_FRAME 56 #define NUM_BITS_SID_IVAS_5K2 104 @@ -201,11 +199,11 @@ static ivas_error decodeVoIP( 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 ); static void do_object_editing_fx( 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 ); +static ivas_error restartDecoder( IVAS_DEC_HANDLE *phIvasDec, const IVAS_DEC_MODE decMode, DecArguments *arg, IVAS_RENDER_CONFIG_DATA *renderConfig, IVAS_CUSTOM_LS_DATA *hLsCustomData ); #endif + /*------------------------------------------------------------------------------------------* * main() * @@ -506,7 +504,6 @@ int main( fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } - #ifndef IVAS_RTPDUMP arg.enableHeadRotation = true; #endif @@ -571,6 +568,7 @@ int main( fprintf( stderr, "Failed to read renderer configuration from file %s\n\n", arg.renderConfigFilename ); goto cleanup; } + #ifdef IVAS_RTPDUMP_ACOUSTIC_ENVIRONMENT aeCount = RenderConfigReader_getAcousticEnvironmentCount( renderConfigReader ); if ( aeCount > 0 ) @@ -1785,6 +1783,10 @@ static void usage_dec( void ) fprintf( stdout, "-rvf File : Reference vector specified by external trajectory File\n" ); fprintf( stdout, " works only in combination with '-otr ref_vec' and 'ref_vec_lev' modes\n" ); fprintf( stdout, "-render_config File : Renderer configuration File\n" ); +#ifdef FIX_1318_ROOM_SIZE_CMD_LINE + fprintf( stdout, "-room_size (S|M|L) : Selects default reverb based on a room size (S - small | M - medium | L - large)\n" ); + fprintf( stdout, " for BINAURAL_ROOM_REVERB output configuration,\n" ); +#endif fprintf( stdout, "-om File : Metadata output File for BINAURAL_SPLIT_PCM OutputConf (only for Fs = 48 kHz)\n" ); fprintf( stdout, "-non_diegetic_pan P : panning mono non-diegetic sound to stereo with panning P, -90<= P <=90,\n" ); fprintf( stdout, " left or l or 90->left, right or r or -90->right, center or c or 0->middle\n" ); @@ -1802,10 +1804,6 @@ static void usage_dec( void ) fprintf( stdout, "-obj_edit File : Object editing instructions file or NULL for built-in example\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 FIX_1318_ROOM_SIZE_CMD_LINE - fprintf( stdout, "-room_size (S|M|L) : Selects default reverb based on a room size (S - small | M - medium | L - large)\n" ); - fprintf( stdout, " for BINAURAL_ROOM_REVERB output configuration\n" ); -#endif fprintf( stdout, "-q : Quiet mode, no frame counter\n" ); fprintf( stdout, " default is deactivated\n" ); fprintf( stdout, "\n" ); @@ -1889,6 +1887,7 @@ static ivas_error initOnFirstGoodFrame( ISAR_SPLIT_REND_POSE_CORRECTION_MODE poseCorrection; int16_t splitRendIsarFrameSizeMs; int16_t lc3plusHighRes; + #ifdef FIXED_RTP_SEQUENCE_NUM /* Ideally ssrc is negotiated via SDP and sequence number is radomized but we use fixed seed for random num generator for regression based tests. Any realtime @@ -2427,7 +2426,7 @@ static ivas_error decodeG192( fprintf( stderr, "\nIVAS_DEC_GetNumOrientationSubframes failed: \n" ); goto cleanup; } - /* Head-tracking input simulation */ + /* Head-tracking input simulation */ if ( arg.enableHeadRotation ) { @@ -3066,6 +3065,7 @@ static ivas_error decodeVoIP( int16_t i; #ifdef DECODER_FORMAT_SWITCHING IVAS_DEC_HANDLE hIvasDec = *phIvasDec; + bool restartNeeded; #endif #ifdef IVAS_RTPDUMP IVAS_RTP ivasRtp = { 0 }; @@ -3268,25 +3268,26 @@ static ivas_error decodeVoIP( nSamplesRendered = 0; #ifdef DECODER_FORMAT_SWITCHING + /* restart decoder in case of 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, + IVAS_DEC_MODE newDecModeInPacket = ( ivasRtp.codecId == IVAS_RTP_EVS ) ? IVAS_DEC_MODE_EVS : IVAS_DEC_MODE_IVAS; + if ( ( error = restartDecoder( + &hIvasDec, + newDecModeInPacket, + &arg, #ifdef FIX_SPLIT_RENDERING_ON_DECODER_RESTART - renderConfig, + renderConfig, #else - NULL, /* ToDo : Provide rendererConfig */ + NULL, /* ToDo : Provide rendererConfig */ #endif - NULL /* ToDo : Provide LS Custom Data */ - ); - if ( error != IVAS_ERR_OK ) + NULL /* ToDo : Provide LS Custom Data */ + ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nFailed to restart decoder from %d to %d\n", arg.decMode, newCodecInPacket ); + fprintf( stderr, "\nFailed to restart decoder from %d to %d\n", arg.decMode, newDecModeInPacket ); goto cleanup; } + *phIvasDec = hIvasDec; /* Update for main()' s free */ ivasRtp.restartNeeded = false; } @@ -3325,6 +3326,7 @@ static ivas_error decodeVoIP( goto cleanup; } } + int16_t num_subframes; if ( ( error = IVAS_DEC_GetNumOrientationSubframes( hIvasDec, &num_subframes ) ) != IVAS_ERR_OK ) { @@ -3332,7 +3334,6 @@ static ivas_error decodeVoIP( goto cleanup; } - /* Head-tracking input simulation */ /* Head-tracking input simulation */ if ( arg.enableHeadRotation ) { @@ -3475,12 +3476,17 @@ static ivas_error decodeVoIP( /* we are finished when all packets have been received and jitter buffer is empty */ /* also stop when the input file contains less than two frames, because JBM cannot calculate a delay value and won't start decoding */ /* last clause should make sure that for BE tests we end up with the same number of samples...*/ - if ( nextPacketRcvTime_ms == (uint32_t) ( -1 ) && ( IVAS_DEC_VoIP_IsEmpty( hIvasDec, nOutSamples ) || nFramesFed < 2 ) ) + bool isEmpty; + if ( ( error = IVAS_DEC_VoIP_IsEmpty( hIvasDec, nOutSamples, &isEmpty ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + if ( nextPacketRcvTime_ms == (uint32_t) ( -1 ) && ( isEmpty || nFramesFed < 2 ) ) { break; } - /* decode and get samples */ while ( nSamplesRendered < nOutSamples ) { @@ -3497,7 +3503,7 @@ static ivas_error decodeVoIP( numPiData++; } - if ( ( error = IVAS_RTP_FeedPiDataToDecoder( hIvasDec, &ivasRtp.piData[ivasRtp.nProcPiData], numPiData ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_FeedPiDataToDecoder( hIvasDec, &ivasRtp.piData[ivasRtp.nProcPiData], numPiData ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; @@ -3506,6 +3512,7 @@ static ivas_error decodeVoIP( ivasRtp.nProcPiData += numPiData; } #endif + #ifdef FIX_1119_SPLIT_RENDERING_VOIP if ( isSplitRend ) { @@ -3545,34 +3552,42 @@ static ivas_error decodeVoIP( return error; } - /* Placeholder for memory reallocation */ - /* ... */ #ifdef DECODER_FORMAT_SWITCHING - if ( IVAS_DEC_isRestartNeeded( hIvasDec ) ) + /* restart decoder in case of format switching */ + if ( ( error = IVAS_DEC_isRestartNeeded( hIvasDec, &restartNeeded ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( restartNeeded ) { - IVAS_DEC_BS_FORMAT tempFormat; - if ( ( error = IVAS_DEC_GetFormat( hIvasDec, &tempFormat ) ) != IVAS_ERR_OK ) + IVAS_DEC_BS_FORMAT tempBsFormat; + if ( ( error = IVAS_DEC_GetFormat( hIvasDec, &tempBsFormat ) ) != 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 ) + + IVAS_DEC_MODE newDecModeInPacket = ( tempBsFormat == IVAS_DEC_BS_MONO ) ? IVAS_DEC_MODE_EVS : IVAS_DEC_MODE_IVAS; + if ( ( error = restartDecoder( + &hIvasDec, + newDecModeInPacket, + &arg, + NULL, /* ToDo : Provide rendererConfig */ + NULL /* ToDo : Provide LS Custom Data */ + ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nFailed to restart decoder\n" ); goto cleanup; } + *phIvasDec = hIvasDec; /* Update for main()' s free */ } #endif + /* Placeholder for memory reallocation */ + /* ... */ + /* Load HRTF binary file data */ if ( arg.hrtfReaderEnabled ) { @@ -3891,7 +3906,6 @@ static ivas_error decodeVoIP( } } - /*------------------------------------------------------------------------------------------* * Add zeros at the end to have equal length of synthesized signals *------------------------------------------------------------------------------------------*/ @@ -4354,9 +4368,15 @@ static ivas_error load_hrtf_from_file( #ifdef DECODER_FORMAT_SWITCHING -ivas_error restartDecoder( +/*---------------------------------------------------------------------* + * restartDecoder() + * + * Restart decoder in case of IVAS format switching + *---------------------------------------------------------------------*/ + +static ivas_error restartDecoder( IVAS_DEC_HANDLE *phIvasDec, - IVAS_DEC_MODE codec, + const IVAS_DEC_MODE decMode, DecArguments *arg, IVAS_RENDER_CONFIG_DATA *renderConfig, IVAS_CUSTOM_LS_DATA *hLsCustomData ) @@ -4374,19 +4394,19 @@ ivas_error restartDecoder( IVAS_DEC_Close( phIvasDec ); } - if ( ( error = IVAS_DEC_Open( phIvasDec, codec ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_Open( phIvasDec, decMode ) ) != IVAS_ERR_OK ) { fprintf( stderr, "Open failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } - arg->decMode = codec; + arg->decMode = decMode; 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; + IVAS_AUDIO_CONFIG outputConfig = ( decMode == IVAS_DEC_MODE_IVAS ) ? arg->outputConfig : IVAS_AUDIO_CONFIG_MONO; #ifdef FIX_1318_ROOM_SIZE_CMD_LINE 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->roomSize, arg->non_diegetic_pan_enabled, @@ -4472,6 +4492,7 @@ ivas_error restartDecoder( cleanup: IVAS_DEC_Close( phIvasDec ); + return error; } diff --git a/apps/encoder.c b/apps/encoder.c index fe64442e1dc0dc4e13783e6a47cef407f3ce2254..3e2bd77781c80b22eaf8918622debc9aa67b37ae 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -63,10 +63,6 @@ #endif #endif -#ifdef FIXED_RTP_SEQUENCE_NUM -#define RANDOM_INITSEED_ENC ( 0xFEEDDEAF ) -#endif - #define WMC_TOOL_SKIP /*------------------------------------------------------------------------------------------* @@ -78,6 +74,10 @@ static #endif int32_t frame = 0; /* Counter of frames */ +#ifdef FIXED_RTP_SEQUENCE_NUM +#define RANDOM_INITSEED_ENC ( 0xFEEDDEAF ) +#endif + #define DEFAULT_FIXED_SID_RATE 8 /* DTX SID rate */ /* Additional config info for each input format */ @@ -468,14 +468,14 @@ int main( 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 ); + goto cleanup; } 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 ); + goto cleanup; } break; default: @@ -672,6 +672,10 @@ int main( } #endif + /*------------------------------------------------------------------------------------------* + * Run the encoder + *------------------------------------------------------------------------------------------*/ + int16_t numSamplesRead = 0; uint16_t bitStream[IVAS_MAX_BITS_PER_FRAME]; uint16_t numBits = 0; @@ -1841,6 +1845,7 @@ static bool parseCmdlIVAS_enc( { i++; arg->rtpdumpOutput = true; + if ( i < argc - 4 ) { if ( !is_digits_only( argv[i] ) ) @@ -1857,6 +1862,7 @@ static bool parseCmdlIVAS_enc( } } } + fprintf( stdout, "Output format: RTPDump using %d frames/packet \n", arg->numFramesPerPacket ); } diff --git a/apps/encoder_fmtsw.c b/apps/encoder_fmtsw.c index 74efb401fa3cd749c63780fd5d3d430fa79aeebe..df8236361dbec101e7c3a460ddee187702c44a99 100644 --- a/apps/encoder_fmtsw.c +++ b/apps/encoder_fmtsw.c @@ -63,10 +63,6 @@ #endif #endif -#ifdef FIXED_RTP_SEQUENCE_NUM -#define RANDOM_INITSEED_ENC ( 0xFEEDDEAF ) -#endif - #define WMC_TOOL_SKIP /*------------------------------------------------------------------------------------------* @@ -81,6 +77,10 @@ static #endif int32_t frame = 0; /* Counter of frames */ +#ifdef FIXED_RTP_SEQUENCE_NUM +#define RANDOM_INITSEED_ENC ( 0xFEEDDEAF ) +#endif + #define DEFAULT_FIXED_SID_RATE 8 /* DTX SID rate */ /* Additional config info for each input format */ @@ -199,13 +199,14 @@ static int encoder_main( int argc, char *argv[] ); * main() * * Main IVAS encoder function for command-line interface - * supporting format switching + * supporting IVAS format switching *------------------------------------------------------------------------------------------*/ int main( int argc, char *argv[] ) { + bool mainFailed = true; /* Assume main failed until cleanup is reached without errors */ FILE *FmtSWFile = NULL; char line[2048]; int argc_local = 0; @@ -221,15 +222,15 @@ int main( 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, "where format_switching_file is a text file containing a valid encoder command line in each line\n\n" ); + goto cleanup; } 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 ); + goto cleanup; } while ( fgets( line, sizeof( line ), FmtSWFile ) ) @@ -238,11 +239,15 @@ int main( 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 ); + if ( encoder_main( argc_local, argv_local, &ivasRtp, 0 ) != 0 ) + { + goto cleanup; + } } else { @@ -250,8 +255,13 @@ int main( { IVAS_RTP_Term( &ivasRtp ); } + /* write in separate Rtp file */ - encoder_main( argc_local, argv_local, &ivasRtp, 1 ); + if ( encoder_main( argc_local, argv_local, &ivasRtp, 1 ) != 0 ) + { + goto cleanup; + } + rtp_term = 1; } strcpy( (char *) prev_outputBitstreamFilename, argv_local[argc_local - 1] ); @@ -259,11 +269,24 @@ int main( encoder_main( argc_local, argv_local ); #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: + #ifdef IVAS_RTPDUMP IVAS_RTP_Term( &ivasRtp ); #endif - fclose( FmtSWFile ); - exit( 0 ); + if ( FmtSWFile ) + { + fclose( FmtSWFile ); + } + + return mainFailed ? -1 : 0; } @@ -568,14 +591,14 @@ int encoder_main( 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 ); + goto cleanup; } 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 ); + goto cleanup; } break; default: @@ -772,6 +795,10 @@ int encoder_main( } #endif + /*------------------------------------------------------------------------------------------* + * Run the encoder + *------------------------------------------------------------------------------------------*/ + int16_t numSamplesRead = 0; uint16_t bitStream[IVAS_MAX_BITS_PER_FRAME]; uint16_t numBits = 0; diff --git a/lib_com/bitstream_fx.c b/lib_com/bitstream_fx.c index a80929e687ba8ca5c13d94a09c412582b1832660..ea576255a6642b622038be557aac1e0c25671b0c 100644 --- a/lib_com/bitstream_fx.c +++ b/lib_com/bitstream_fx.c @@ -3860,6 +3860,7 @@ void convertSerialToBytestream_fx( UWord8 bitinbyte2, bytestream_tmp; assert( num_bits <= MAX_16 ); /* 512 kbps = 10240 bits, num_bits should always fits Word16 */ #endif + FOR( i = 0; i < num_bits; ++i ) { IF( EQ_32( serial[i], 0x0001 ) ) diff --git a/lib_com/common_api_types.h b/lib_com/common_api_types.h index 3c3c6b2b73d765019731138b6c0f2a55856a6fd3..27290eb18a741f71e6957e070cfcf9a7f227797f 100644 --- a/lib_com/common_api_types.h +++ b/lib_com/common_api_types.h @@ -62,6 +62,9 @@ #define IVAS_REVERB_PREDELAY_MAX 20 /* Max input delay for reverb module */ #define IVAS_ER_LIST_HEIGHT 1.6f #define IVAS_ER_LIST_HEIGHT_FX 6710886 /* 1.6f in Q.22 */ +#ifdef IVAS_RTPDUMP_ACOUSTIC_ENVIRONMENT +#define IVAS_DEFAULT_AEID 65535 +#endif /* JBM constants for adaptive-playout */ #define IVAS_TIME_SCALE_MIN 50 /* min. time-scaling [%] */ diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index a41ff84f5743aa388c32bcfddb5ca5665e9ea188..b8415b7fd28d70214bf80f153a9130b0d2428291 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1663,9 +1663,6 @@ typedef enum #else #define IVAS_REVERB_DEFAULT_N_BANDS 31 #endif -#ifdef IVAS_RTPDUMP_ACOUSTIC_ENVIRONMENT -#define IVAS_DEFAULT_AEID ( 65535 ) -#endif #define LR_IAC_LENGTH_NR_FC ( RV_LENGTH_NR_FC ) #define LR_IAC_LENGTH_NR_FC_16KHZ ( RV_LENGTH_NR_FC_16KHZ ) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 1adc3d5de24fe3ce9fca12ef2e56146831ecb8bb..b75b3813733be9bd945bc824afe53d0c7ff2c9f0 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -4005,16 +4005,11 @@ ivas_error ivas_output_buff_dec_fx( ); ivas_error ivas_dec_get_format_fx( -#ifdef DECODER_FORMAT_SWITCHING - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const bool isVoipMode /* i : voip mode indicator */ -#else Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -#endif ); ivas_error ivas_dec_setup( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); ivas_error create_mct_dec_fx( diff --git a/lib_dec/ivas_init_dec_fx.c b/lib_dec/ivas_init_dec_fx.c index 90b5c7baae66b76fc7c7c7c2dca960e7990415ce..b6e7a558ec79902eaad55d95ecb0afbcde14eab5 100644 --- a/lib_dec/ivas_init_dec_fx.c +++ b/lib_dec/ivas_init_dec_fx.c @@ -104,18 +104,17 @@ static AUDIO_CONFIG ivas_set_audio_config_from_sba_order( *---------------------------------------------------------------------*/ ivas_error ivas_dec_get_format_fx( -#ifdef DECODER_FORMAT_SWITCHING - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const bool isVoipMode /* i : voip mode indicator */ -#else Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -#endif ) { Word16 k, idx, num_bits_read; Word16 nchan_ism, element_mode_flag; Word16 sba_order, sba_planar, sba_analysis_order; Word32 ivas_total_brate; +#ifdef DECODER_FORMAT_SWITCHING + int16_t Opt_tsm; +#endif + UWord16 *bit_stream_orig; AUDIO_CONFIG signaled_config; ivas_error error; @@ -127,6 +126,10 @@ ivas_error ivas_dec_get_format_fx( ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; move32(); +#ifdef DECODER_FORMAT_SWITCHING + Opt_tsm = st_ivas->hDecoderConfig->Opt_tsm; + move16(); +#endif bit_stream_orig = st_ivas->bit_stream; /*-------------------------------------------------------------------* @@ -148,10 +151,11 @@ ivas_error ivas_dec_get_format_fx( !( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->last_ivas_format, MASA_FORMAT ) ) ) { #ifdef DECODER_FORMAT_SWITCHING - IF( isVoipMode ) + IF( Opt_tsm ) { st_ivas->restartNeeded = 1; move16(); + return IVAS_ERR_OK; } ELSE @@ -205,10 +209,11 @@ ivas_error ivas_dec_get_format_fx( IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ) { #ifdef DECODER_FORMAT_SWITCHING - IF( isVoipMode ) + IF( Opt_tsm ) { st_ivas->restartNeeded = 1; move16(); + return IVAS_ERR_OK; } ELSE @@ -248,10 +253,11 @@ ivas_error ivas_dec_get_format_fx( IF( st_ivas->ini_frame > 0 && NE_16( sba_planar, st_ivas->sba_planar ) ) { #ifdef DECODER_FORMAT_SWITCHING - IF( isVoipMode ) + IF( Opt_tsm ) { st_ivas->restartNeeded = 1; move16(); + return IVAS_ERR_OK; } ELSE @@ -278,10 +284,11 @@ ivas_error ivas_dec_get_format_fx( IF( st_ivas->ini_frame > 0 && NE_16( sba_order, st_ivas->sba_order ) ) { #ifdef DECODER_FORMAT_SWITCHING - IF( isVoipMode ) + IF( Opt_tsm ) { st_ivas->restartNeeded = 1; move16(); + return IVAS_ERR_OK; } ELSE @@ -315,7 +322,7 @@ ivas_error ivas_dec_get_format_fx( { #ifdef DECODER_FORMAT_SWITCHING test(); - IF( st_ivas->nchan_transport == 1 && isVoipMode ) + if ( st_ivas->nchan_transport == 1 && Opt_tsm ) { masaRestartCandidate = 1; move16(); @@ -330,7 +337,7 @@ ivas_error ivas_dec_get_format_fx( { #ifdef DECODER_FORMAT_SWITCHING test(); - IF( st_ivas->nchan_transport == 2 && isVoipMode ) + if ( st_ivas->nchan_transport == 2 && Opt_tsm ) { masaRestartCandidate = 1; move16(); @@ -374,6 +381,7 @@ ivas_error ivas_dec_get_format_fx( { st_ivas->restartNeeded = 1; move16(); + return IVAS_ERR_OK; } #endif @@ -382,10 +390,11 @@ ivas_error ivas_dec_get_format_fx( IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ) { #ifdef DECODER_FORMAT_SWITCHING - IF( isVoipMode ) + IF( Opt_tsm ) { st_ivas->restartNeeded = 1; move16(); + return IVAS_ERR_OK; } ELSE @@ -420,10 +429,11 @@ ivas_error ivas_dec_get_format_fx( IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ) { #ifdef DECODER_FORMAT_SWITCHING - IF( isVoipMode ) + IF( Opt_tsm ) { st_ivas->restartNeeded = 1; move16(); + return IVAS_ERR_OK; } ELSE @@ -454,10 +464,11 @@ ivas_error ivas_dec_get_format_fx( IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ) { #ifdef DECODER_FORMAT_SWITCHING - IF( isVoipMode ) + IF( Opt_tsm ) { st_ivas->restartNeeded = 1; move16(); + return IVAS_ERR_OK; } ELSE @@ -501,10 +512,11 @@ ivas_error ivas_dec_get_format_fx( IF( st_ivas->ini_frame > 0 && NE_16( sba_order, st_ivas->sba_order ) ) { #ifdef DECODER_FORMAT_SWITCHING - IF( isVoipMode ) + IF( Opt_tsm ) { st_ivas->restartNeeded = 1; move16(); + return IVAS_ERR_OK; } ELSE @@ -547,10 +559,11 @@ ivas_error ivas_dec_get_format_fx( IF( st_ivas->ini_frame > 0 && NE_32( st_ivas->transport_config, signaled_config ) ) { #ifdef DECODER_FORMAT_SWITCHING - IF( isVoipMode ) + IF( Opt_tsm ) { st_ivas->restartNeeded = 1; move16(); + return IVAS_ERR_OK; } ELSE @@ -665,10 +678,11 @@ ivas_error ivas_dec_get_format_fx( IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ) { #ifdef DECODER_FORMAT_SWITCHING - IF( isVoipMode ) + IF( Opt_tsm ) { st_ivas->restartNeeded = 1; move16(); + return IVAS_ERR_OK; } ELSE @@ -3676,6 +3690,15 @@ void ivas_destroy_dec_fx( /* Config. Renderer */ ivas_render_config_close_fx( &( st_ivas->hRenderConfig ) ); +#ifdef IVAS_RTPDUMP_ACOUSTIC_ENVIRONMENT + /* Acoustic environments */ + IF( st_ivas->pAcousticEnvironments != NULL ) + { + free( st_ivas->pAcousticEnvironments ); + st_ivas->pAcousticEnvironments = NULL; + } +#endif + /* Limiter struct */ ivas_limiter_close_fx( &( st_ivas->hLimiter ) ); @@ -3701,16 +3724,6 @@ void ivas_destroy_dec_fx( st_ivas->p_output_fx[i] = NULL; } -#ifdef IVAS_RTPDUMP_ACOUSTIC_ENVIRONMENT - /* Acoustic environments */ - IF( st_ivas->pAcousticEnvironments != NULL ) - { - free( st_ivas->pAcousticEnvironments ); - st_ivas->pAcousticEnvironments = NULL; - } -#endif - - /* main IVAS handle */ free( st_ivas ); diff --git a/lib_dec/ivas_output_config_fx.c b/lib_dec/ivas_output_config_fx.c index 0cec1b914cdbad99aa158e3030dbcf0ea1723967..9c988937ba3853b55ae29de06c96db525bd5d07d 100644 --- a/lib_dec/ivas_output_config_fx.c +++ b/lib_dec/ivas_output_config_fx.c @@ -119,9 +119,7 @@ void ivas_renderer_select( #ifdef FIX_1419_MONO_STEREO_UMX IF( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) || EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) ) { - ms_bin_upmix_renderer_select( st_ivas->ivas_format, - internal_config, - renderer_type ); + ms_bin_upmix_renderer_select( st_ivas->ivas_format, internal_config, renderer_type ); } ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) #else diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index b2e5ecc9ba71cb0bc4b5ffbe613cb4ae092d5157..c3c16166809a7b5b01eee301b8101df3dd8cc4d9 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1209,14 +1209,14 @@ typedef struct Decoder_Struct JBM_METADATA_HANDLE hJbmMetadata; /* Structure for metadata buffering in JBM */ Word32 last_active_ivas_total_brate; - Word16 ism_extmeta_active; /* Extended metadata active in decoder */ - Word16 ism_extmeta_cnt; /* Change frame counter for extended metadata */ + Word16 ism_extmeta_active; /* Extended metadata active in decoder */ + Word16 ism_extmeta_cnt; /* Change frame counter for extended metadata */ #ifdef TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR Word16 flushing; #endif #ifdef DECODER_FORMAT_SWITCHING - UWord8 restartNeeded; /* Flag to check if the decoder requires a restart */ + Word16 restartNeeded; /* Flag to signal decoder restart */ #endif } Decoder_Struct; diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 44fdfc5ced55f99730922542162321d44974f7ff..698ca55a6e843a9a21d9d6775caedd63e63ba487 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -90,6 +90,7 @@ typedef enum _IVAS_DEC_BS_FORMAT } IVAS_DEC_BS_FORMAT; typedef struct IVAS_DEC *IVAS_DEC_HANDLE; +typedef struct pidata_ts_struct *hPiDataTs; #ifdef SUPPORT_JBM_TRACEFILE /* Callback function for JBM tracefile writing */ @@ -292,7 +293,7 @@ ivas_error IVAS_DEC_VoIP_SetScale( #ifdef VARIABLE_SPEED_DECODING ivas_error IVAS_DEC_EnableTsm( - IVAS_DEC_HANDLE hIvasDec /* i/o: IVAS decoder handle */ + IVAS_DEC_HANDLE hIvasDec /* i/o: IVAS decoder handle */ ); ivas_error IVAS_DEC_TSM_SetQuality( @@ -342,11 +343,13 @@ ivas_error IVAS_DEC_Flush( ); #ifdef DECODER_FORMAT_SWITCHING -bool IVAS_DEC_isRestartNeeded( - IVAS_DEC_HANDLE hIvasDec /* i/o: IVAS decoder handle */ +ivas_error IVAS_DEC_isRestartNeeded( + IVAS_DEC_HANDLE hIvasDec, /* i : IVAS decoder handle */ + bool *restartNeeded /* o : flag to signal decoder restart */ ); #endif + /* Setter functions - apply changes to decoder configuration */ /*! r: error code */ @@ -463,14 +466,14 @@ ivas_error IVAS_DEC_HRTF_binary_close( #ifdef IVAS_RTPDUMP_ACOUSTIC_ENVIRONMENT ivas_error IVAS_DEC_AddAcousticEnvironment( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const IVAS_ROOM_ACOUSTICS_CONFIG_DATA roomAcousticsConfig /* i : Room acoustic configuration */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const IVAS_ROOM_ACOUSTICS_CONFIG_DATA roomAcousticsConfig /* i: Room acoustic configuration */ ); ivas_error IVAS_DEC_GetAcousticEnvironment( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - UWord16 aeID, /* i : Acoustic environment ID */ - IVAS_ROOM_ACOUSTICS_CONFIG_DATA *pAcEnv /* o : Room acoustic environment data pointer */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + UWord16 aeID, /* i : Acoustic environment ID */ + IVAS_ROOM_ACOUSTICS_CONFIG_DATA *pAcEnv /* o : Room acoustic environment data pointer */ ); #endif @@ -505,9 +508,10 @@ ivas_error IVAS_DEC_HasDecodedFirstGoodFrame( ); /*! r: true if decoder has no data in VoIP jitter buffer */ -bool IVAS_DEC_VoIP_IsEmpty( +ivas_error IVAS_DEC_VoIP_IsEmpty( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const Word16 nSamplesAsked + const Word16 nSamplesAsked, /* i : number of output samples asked */ + bool *isEmpty /* o : isEmpty flag */ ); ivas_error IVAS_DEC_VoIP_Get_CA_offset( @@ -523,6 +527,14 @@ ivas_error IVAS_DEC_GetJbmData( ); #endif +#ifdef IVAS_RTPDUMP +ivas_error IVAS_DEC_FeedPiDataToDecoder( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + hPiDataTs piData, /* i : PI data received in rtp packet */ + UWord32 numPiData /* i : number of PI data received in rtp packet */ +); +#endif + /* Utility functions */ /*! r: pointer to an error message string */ @@ -540,13 +552,6 @@ void IVAS_DEC_PrintDisclaimer( void ); -#ifdef IVAS_RTPDUMP -#ifndef IVAS_RTPDUMP_ACOUSTIC_ENVIRONMENT -#include "ivas_rtp_pi_data.h" -#endif -ivas_error IVAS_RTP_FeedPiDataToDecoder( IVAS_DEC_HANDLE hIvasDec, PIDATA_TS *piData, UWord32 numPiData ); -#endif - /* clang-format on */ #endif diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index dec6a92422e82d5ac6b3deb477ef26d7a35e8b3b..8ac73cb85eca3bf2d44dd62f3442138820786b1c 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -41,6 +41,9 @@ #include "jbm_jb4sb.h" #include "jbm_pcmdsp_apa.h" #include "jbm_pcmdsp_fifo.h" +#ifdef IVAS_RTPDUMP +#include "ivas_rtp_pi_data.h" +#endif #include #include #ifdef DEBUGGING @@ -2977,6 +2980,7 @@ ivas_error IVAS_DEC_HRTF_binary_close( return IVAS_ERR_OK; } + #ifdef IVAS_RTPDUMP_ACOUSTIC_ENVIRONMENT /*---------------------------------------------------------------------* * IVAS_DEC_AddAcousticEnvironment( ) @@ -3017,13 +3021,59 @@ ivas_error IVAS_DEC_AddAcousticEnvironment( /* If not found */ IF( pAE == NULL ) { - IVAS_ROOM_ACOUSTICS_CONFIG_DATA *ppAE = realloc( st_ivas->pAcousticEnvironments, ( st_ivas->acousticEnvironmentsCount + 1 ) * sizeof( IVAS_ROOM_ACOUSTICS_CONFIG_DATA ) ); + IVAS_ROOM_ACOUSTICS_CONFIG_DATA *ppAE = malloc( ( st_ivas->acousticEnvironmentsCount + 1 ) * sizeof( IVAS_ROOM_ACOUSTICS_CONFIG_DATA ) ); IF( ppAE == NULL ) { return IVAS_ERR_FAILED_ALLOC; } + + FOR( n = 0; n < st_ivas->acousticEnvironmentsCount; n++ ) + { + pAE = &ppAE[n]; + pAE->aeID = st_ivas->pAcousticEnvironments[n].aeID; + pAE->nBands = st_ivas->pAcousticEnvironments[n].nBands; + pAE->acousticPreDelay_fx = st_ivas->pAcousticEnvironments[n].acousticPreDelay_fx; + pAE->inputPreDelay_fx = st_ivas->pAcousticEnvironments[n].inputPreDelay_fx; + + Copy32( st_ivas->pAcousticEnvironments[n].pFc_input_fx, pAE->pFc_input_fx, CLDFB_NO_CHANNELS_MAX ); // Q16 + Copy32( st_ivas->pAcousticEnvironments[n].pAcoustic_rt60_fx, pAE->pAcoustic_rt60_fx, CLDFB_NO_CHANNELS_MAX ); // Q26 + Copy32( st_ivas->pAcousticEnvironments[n].pAcoustic_dsr_fx, pAE->pAcoustic_dsr_fx, CLDFB_NO_CHANNELS_MAX ); // Q30 + + pAE->use_er = st_ivas->pAcousticEnvironments[n].use_er; + + move16(); + move16(); + move32(); + move32(); + move16(); + + IF( EQ_16( pAE->use_er, 1 ) ) + { + pAE->lowComplexity = st_ivas->pAcousticEnvironments[n].lowComplexity; + move32(); + + pAE->dimensions.x_fx = st_ivas->pAcousticEnvironments[n].dimensions.x_fx; + pAE->dimensions.y_fx = st_ivas->pAcousticEnvironments[n].dimensions.y_fx; + pAE->dimensions.z_fx = st_ivas->pAcousticEnvironments[n].dimensions.z_fx; + move32(); + move32(); + move32(); + + pAE->ListenerOrigin.x_fx = st_ivas->pAcousticEnvironments[n].ListenerOrigin.x_fx; + pAE->ListenerOrigin.y_fx = st_ivas->pAcousticEnvironments[n].ListenerOrigin.y_fx; + pAE->ListenerOrigin.z_fx = st_ivas->pAcousticEnvironments[n].ListenerOrigin.z_fx; + move32(); + move32(); + move32(); + + Copy32( st_ivas->pAcousticEnvironments[n].AbsCoeff_fx, pAE->AbsCoeff_fx, IVAS_ROOM_ABS_COEFF ); + } + } + + free( st_ivas->pAcousticEnvironments ); st_ivas->pAcousticEnvironments = ppAE; + n = st_ivas->acousticEnvironmentsCount++; pAE = &st_ivas->pAcousticEnvironments[n]; move32(); @@ -3048,7 +3098,7 @@ ivas_error IVAS_DEC_AddAcousticEnvironment( move32(); move16(); - IF( pAE->use_er == 1 ) + IF( EQ_16( pAE->use_er, 1 ) ) { pAE->lowComplexity = roomAcousticsConfig.lowComplexity; move32(); @@ -3073,11 +3123,13 @@ ivas_error IVAS_DEC_AddAcousticEnvironment( return IVAS_ERR_OK; } + /*---------------------------------------------------------------------* * IVAS_DEC_GetAcousticEnvironment( ) * * Gets acoustic environment configuration with a given ID *---------------------------------------------------------------------*/ + ivas_error IVAS_DEC_GetAcousticEnvironment( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ UWord16 aeID, /* i : Acoustic environment ID */ @@ -3086,7 +3138,7 @@ ivas_error IVAS_DEC_GetAcousticEnvironment( { Word16 n, m; Word16 found = 0; - + move16(); Decoder_Struct *st_ivas; test(); @@ -3094,6 +3146,7 @@ ivas_error IVAS_DEC_GetAcousticEnvironment( { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } + st_ivas = hIvasDec->st_ivas; move32(); @@ -3101,7 +3154,7 @@ ivas_error IVAS_DEC_GetAcousticEnvironment( test(); IF( aeID == (UWord16) IVAS_DEFAULT_AEID && st_ivas->acousticEnvironmentsCount > 0 ) { - aeID = (UWord16) st_ivas->pAcousticEnvironments[0].aeID; + aeID = st_ivas->pAcousticEnvironments[0].aeID; move32(); } @@ -3133,6 +3186,7 @@ ivas_error IVAS_DEC_GetAcousticEnvironment( /* If ER are allocated then propagate parameters */ pAcEnv->use_er = ae.use_er; move16(); + IF( ae.use_er != 0 ) { pAcEnv->lowComplexity = ae.lowComplexity; @@ -3157,8 +3211,16 @@ ivas_error IVAS_DEC_GetAcousticEnvironment( } } - return found ? IVAS_ERR_OK : IVAS_ERR_ACOUSTIC_ENVIRONMENT_MISSING; + IF( found == 0 ) + { + return IVAS_ERR_ACOUSTIC_ENVIRONMENT_MISSING; + } + ELSE + { + return IVAS_ERR_OK; + } } + #endif /*---------------------------------------------------------------------* @@ -3378,13 +3440,14 @@ ivas_error IVAS_DEC_FeedRenderConfig( } #ifdef IVAS_RTPDUMP_ACOUSTIC_ENVIRONMENT + /*---------------------------------------------------------------------* - * IVAS_DEC_FeedAcousticEnvPI( ) + * feedAcousticEnvPI( ) * * Set acoustic environment from the PI data *---------------------------------------------------------------------*/ -static ivas_error IVAS_DEC_FeedAcousticEnvPI( +static ivas_error feedAcousticEnvPI( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const IVAS_PIDATA_ACOUSTIC_ENV hAcoustEnvPI /* i : Render configuration struct */ ) @@ -3406,7 +3469,7 @@ static ivas_error IVAS_DEC_FeedAcousticEnvPI( move32(); /* Ignore if AE ID already in use */ - IF( hRenderConfig->roomAcoustics.aeID == hAcoustEnvPI.aeid ) + IF( EQ_16( hRenderConfig->roomAcoustics.aeID, hAcoustEnvPI.aeid ) ) { return IVAS_ERR_OK; } @@ -3457,11 +3520,7 @@ static ivas_error IVAS_DEC_FeedAcousticEnvPI( move32(); move32(); - FOR( Word16 i = 0; i < IVAS_ROOM_ABS_COEFF; i++ ) - { - hRenderConfig->roomAcoustics.AbsCoeff[i] = hAcoustEnvPI.absorbCoeffs[i]; - move16(); - } + Copy32( hAcoustEnvPI.absorbCoeffs_fx, hRenderConfig->roomAcoustics.AbsCoeff_fx, IVAS_ROOM_ABS_COEFF ); } IF( ( error = IVAS_DEC_AddAcousticEnvironment( hIvasDec, acEnv ) ) != IVAS_ERR_OK ) @@ -3525,6 +3584,7 @@ static ivas_error IVAS_DEC_FeedAcousticEnvPI( return IVAS_ERR_OK; } + #endif /*---------------------------------------------------------------------* @@ -4035,17 +4095,13 @@ ivas_error IVAS_DEC_ReadFormat( IF( st_ivas->bfi == 0 ) { -#ifdef DECODER_FORMAT_SWITCHING - IF( NE_32( error = ivas_dec_get_format_fx( st_ivas, hIvasDec->hVoIP != NULL ), IVAS_ERR_OK ) ) -#else IF( NE_32( error = ivas_dec_get_format_fx( st_ivas ), IVAS_ERR_OK ) ) -#endif { return error; } #ifdef DECODER_FORMAT_SWITCHING - IF( st_ivas->restartNeeded > 0 ) + IF( EQ_16( st_ivas->restartNeeded, 1 ) ) { return IVAS_ERR_OK; } @@ -5590,11 +5646,26 @@ ivas_error IVAS_DEC_Flush( * *---------------------------------------------------------------------*/ -bool IVAS_DEC_isRestartNeeded( - IVAS_DEC_HANDLE hIvasDec /* i/o: IVAS decoder handle */ +ivas_error IVAS_DEC_isRestartNeeded( + IVAS_DEC_HANDLE hIvasDec, /* i : IVAS decoder handle */ + bool *restartNeeded /* o : flag to signal decoder restart */ ) { - return hIvasDec->st_ivas->restartNeeded > 0; + test(); + IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + *restartNeeded = false; + move16(); + if ( EQ_16( hIvasDec->st_ivas->restartNeeded, 1 ) ) + { + *restartNeeded = true; + move16(); + } + + return IVAS_ERR_OK; } @@ -5602,12 +5673,13 @@ bool IVAS_DEC_isRestartNeeded( /*---------------------------------------------------------------------* * IVAS_DEC_VoIP_IsEmpty( ) * - * + * Returns 'true' if decoder has no data in VoIP jitter buffer *---------------------------------------------------------------------*/ -bool IVAS_DEC_VoIP_IsEmpty( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const Word16 nSamplesAsked /* i : number of output samples asked */ +ivas_error IVAS_DEC_VoIP_IsEmpty( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const Word16 nSamplesAsked, /* i : number of output samples asked */ + bool *isEmpty /* o : isEmpty flag */ ) { test(); @@ -5616,8 +5688,16 @@ bool IVAS_DEC_VoIP_IsEmpty( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } + *isEmpty = false; + move16(); test(); - return ( JB4_bufferedDataUnits( hIvasDec->hVoIP->hJBM ) == 0 && LT_16( hIvasDec->nSamplesAvailableNext, nSamplesAsked ) ); + if ( ( JB4_bufferedDataUnits( hIvasDec->hVoIP->hJBM ) == 0 ) && LT_16( hIvasDec->nSamplesAvailableNext, nSamplesAsked ) ) + { + *isEmpty = true; + move16(); + } + + return IVAS_ERR_OK; } @@ -6833,35 +6913,45 @@ ivas_error IVAS_DEC_is_split_rendering_coded_out( } #ifdef IVAS_RTPDUMP + /*---------------------------------------------------------------------* - * IVAS_DEC_feedSinglePIorientation( ) + * feedSinglePIorientation( ) * * Feed a single orientation PI data to external orientation handle. *---------------------------------------------------------------------*/ -static ivas_error IVAS_DEC_feedSinglePIorientation( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - bool isOrientationSaved, /* i : flag to indicate if an orientation for this PI type was previously saved */ - IVAS_QUATERNION *savedOrientation /* i : previously saved orientation for this PI type */ +static ivas_error feedSinglePIorientation( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const bool isOrientationSaved, /* i : flag to indicate if an orientation for this PI type was previously saved */ + IVAS_QUATERNION *savedOrientation /* i : previously saved orientation for this PI type */ ) { Word16 i; - ivas_error error = IVAS_ERR_OK; + ivas_error error; + Decoder_Struct *st_ivas; IVAS_QUATERNION savedInvOrientation; + test(); + IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + st_ivas = hIvasDec->st_ivas; + IF( isOrientationSaved ) { - IF( !hIvasDec->st_ivas->hExtOrientationData ) + IF( !st_ivas->hExtOrientationData ) { - IF( NE_32( error = ivas_external_orientation_open_fx( &( hIvasDec->st_ivas->hExtOrientationData ), hIvasDec->st_ivas->hDecoderConfig->render_framesize ), IVAS_ERR_OK ) ) + IF( NE_32( error = ivas_external_orientation_open_fx( &( st_ivas->hExtOrientationData ), st_ivas->hDecoderConfig->render_framesize ), IVAS_ERR_OK ) ) { return error; } } - IF( !hIvasDec->st_ivas->hCombinedOrientationData ) + IF( !st_ivas->hCombinedOrientationData ) { - IF( NE_32( error = ivas_combined_orientation_open_fx( &( hIvasDec->st_ivas->hCombinedOrientationData ), hIvasDec->st_ivas->hDecoderConfig->output_Fs, hIvasDec->st_ivas->hDecoderConfig->render_framesize ), IVAS_ERR_OK ) ) + IF( NE_32( error = ivas_combined_orientation_open_fx( &( st_ivas->hCombinedOrientationData ), st_ivas->hDecoderConfig->output_Fs, st_ivas->hDecoderConfig->render_framesize ), IVAS_ERR_OK ) ) { return error; } @@ -6870,57 +6960,86 @@ static ivas_error IVAS_DEC_feedSinglePIorientation( QuaternionInverse_fx( *savedOrientation, &savedInvOrientation ); /* use the new PI orientation or the previously saved orientation in processing */ - FOR( i = 0; i < hIvasDec->st_ivas->hExtOrientationData->num_subframes; i++ ) + FOR( i = 0; i < st_ivas->hExtOrientationData->num_subframes; i++ ) { - QuaternionProduct_fx( hIvasDec->st_ivas->hExtOrientationData->Quaternions[i], savedInvOrientation, - &hIvasDec->st_ivas->hExtOrientationData->Quaternions[i] ); - hIvasDec->st_ivas->hExtOrientationData->enableExternalOrientation[i] = true; + QuaternionProduct_fx( st_ivas->hExtOrientationData->Quaternions[i], savedInvOrientation, + &st_ivas->hExtOrientationData->Quaternions[i] ); + st_ivas->hExtOrientationData->enableExternalOrientation[i] = true; move16(); } + hIvasDec->updateOrientation = true; move16(); } - return error; + + return IVAS_ERR_OK; } + #endif #ifdef RTP_S4_251135_CR26253_0016_REV1 + /*---------------------------------------------------------------------* - * IVAS_DEC_setDiegeticInput( ) + * setDiegeticInput( ) * * Set isDiegeticInput flag for combined orientation handle based on PI data. *---------------------------------------------------------------------*/ -static void IVAS_DEC_setDiegeticInputPI( +static void setDiegeticInputPI( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const bool *diegeticPIValues /* i : diegetic values for the input stream */ ) { + Word16 i; + IF( hIvasDec->st_ivas->hCombinedOrientationData != NULL ) { - Word8 i; FOR( i = 0; i < ( 1 + IVAS_MAX_NUM_OBJECTS ); i++ ) { hIvasDec->st_ivas->hCombinedOrientationData->isDiegeticInputPI[i] = diegeticPIValues[i]; move16(); } + hIvasDec->st_ivas->hCombinedOrientationData->isDiegeticInputPISet = true; move16(); } + + return; } + #endif #ifdef IVAS_RTPDUMP -ivas_error IVAS_RTP_FeedPiDataToDecoder( IVAS_DEC_HANDLE hIvasDec, PIDATA_TS *piData, UWord32 numPiData ) +/*---------------------------------------------------------------------* + * IVAS_DEC_FeedPiDataToDecoder( ) + * + * + *---------------------------------------------------------------------*/ + +ivas_error IVAS_DEC_FeedPiDataToDecoder( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + hPiDataTs piData, /* i : PI data received in rtp packet */ + UWord32 numPiData /* i : number of PI data received in rtp packet */ +) { + UWord32 i; + Decoder_Struct *st_ivas; ivas_error error = IVAS_ERR_OK; move32(); - UWord32 i; + + test(); + IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + st_ivas = hIvasDec->st_ivas; + FOR( i = 0; i < numPiData; i++ ) { UWord32 piDataType = piData->data.noPiData.piDataType; move32(); - numPiData = UL_subNsD( numPiData, 1 ); /* Subtraction of WHILE variable */ + SWITCH( piDataType ) { case IVAS_PI_SCENE_ORIENTATION: @@ -6933,7 +7052,7 @@ ivas_error IVAS_RTP_FeedPiDataToDecoder( IVAS_DEC_HANDLE hIvasDec, PIDATA_TS *pi fixedToFloat( quat->y_fx, Q15 ), fixedToFloat( quat->z_fx, Q15 ) ); #endif - error = IVAS_DEC_feedSinglePIorientation( hIvasDec, true, quat ); + error = feedSinglePIorientation( hIvasDec, true, quat ); } BREAK; @@ -6947,7 +7066,7 @@ ivas_error IVAS_RTP_FeedPiDataToDecoder( IVAS_DEC_HANDLE hIvasDec, PIDATA_TS *pi fixedToFloat( quat->y_fx, Q15 ), fixedToFloat( quat->z_fx, Q15 ) ); #endif - error = IVAS_DEC_feedSinglePIorientation( hIvasDec, true, quat ); + error = feedSinglePIorientation( hIvasDec, true, quat ); } BREAK; @@ -6962,9 +7081,9 @@ ivas_error IVAS_RTP_FeedPiDataToDecoder( IVAS_DEC_HANDLE hIvasDec, PIDATA_TS *pi #endif test(); test(); - IF( piData->data.acousticEnv.availLateReverb && hIvasDec->st_ivas->hRenderConfig != NULL && aeid != hIvasDec->st_ivas->hRenderConfig->roomAcoustics.aeID ) + IF( piData->data.acousticEnv.availLateReverb && st_ivas->hRenderConfig != NULL && aeid != st_ivas->hRenderConfig->roomAcoustics.aeID ) { - error = IVAS_DEC_FeedAcousticEnvPI( hIvasDec, piData->data.acousticEnv ); + error = feedAcousticEnvPI( hIvasDec, piData->data.acousticEnv ); } } BREAK; @@ -6976,7 +7095,7 @@ ivas_error IVAS_RTP_FeedPiDataToDecoder( IVAS_DEC_HANDLE hIvasDec, PIDATA_TS *pi #ifdef DEBUGGING fprintf( stdout, "PI_DIEGETIC_TYPE : %d, %d, %d, %d, %d\n", piData->data.digeticIndicator.isDiegetic[0], piData->data.digeticIndicator.isDiegetic[1], piData->data.digeticIndicator.isDiegetic[2], piData->data.digeticIndicator.isDiegetic[3], piData->data.digeticIndicator.isDiegetic[4] ); #endif - IVAS_DEC_setDiegeticInputPI( hIvasDec, piData->data.digeticIndicator.isDiegetic ); + setDiegeticInputPI( hIvasDec, piData->data.digeticIndicator.isDiegetic ); } BREAK; #endif @@ -6987,12 +7106,15 @@ ivas_error IVAS_RTP_FeedPiDataToDecoder( IVAS_DEC_HANDLE hIvasDec, PIDATA_TS *pi } BREAK; } + IF( NE_32( error, IVAS_ERR_OK ) ) { return error; } + piData++; } - return error; + + return IVAS_ERR_OK; } #endif diff --git a/lib_rend/ivas_render_config_fx.c b/lib_rend/ivas_render_config_fx.c index e8258930a33b4ab8293a533b6783e77e9e741063..e4c6f62f73a8eadb65bd80b56f32b8d766753e22 100644 --- a/lib_rend/ivas_render_config_fx.c +++ b/lib_rend/ivas_render_config_fx.c @@ -119,7 +119,7 @@ ivas_error ivas_render_config_init_from_rom_fx( return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "Unexpected null pointer while attempting to fill renderer configuration from ROM" ); } #ifdef IVAS_RTPDUMP_ACOUSTIC_ENVIRONMENT - ( *hRenderConfig )->roomAcoustics.aeID = (UWord16) IVAS_DEFAULT_AEID; + ( *hRenderConfig )->roomAcoustics.aeID = IVAS_DEFAULT_AEID; move16(); #endif #ifdef FIX_1318_ROOM_SIZE_CMD_LINE diff --git a/lib_rend/ivas_rotation_fx.c b/lib_rend/ivas_rotation_fx.c index d45002320996d82c9a193755235dbb70fff6740f..c05ed40c38c22f118b07a0f742c3981a1ae16013 100644 --- a/lib_rend/ivas_rotation_fx.c +++ b/lib_rend/ivas_rotation_fx.c @@ -1797,6 +1797,7 @@ ivas_error combine_external_and_head_orientations( } } } + test(); IF( hExtOrientationData != NULL && headRotQuaternions != NULL ) { @@ -1897,6 +1898,7 @@ ivas_error combine_external_and_head_orientations( } } } + test(); IF( headRotQuaternions != NULL || hExtOrientationData != NULL ) { @@ -1919,6 +1921,7 @@ ivas_error combine_external_and_head_orientations( hCombinedOrientationData->Quaternion_prev_extOrientation = identity; } } + IF( headRotQuaternions != NULL ) { FOR( i = 0; i < hCombinedOrientationData->num_subframes; i++ ) @@ -1926,6 +1929,7 @@ ivas_error combine_external_and_head_orientations( hCombinedOrientationData->listenerPos[i] = listenerPos[i]; } } + /* Check if combined orientation is enabled */ test(); test(); @@ -2034,6 +2038,7 @@ ivas_error combine_external_and_head_orientations( } } #endif + return IVAS_ERR_OK; } diff --git a/lib_util/ivas_rtp_pi_data.h b/lib_util/ivas_rtp_pi_data.h index cc238d97e07cf940fb7b991280b3157bfa75a82b..2bce92fa704845b469f382cc2e31c7452dd84bb5 100644 --- a/lib_util/ivas_rtp_pi_data.h +++ b/lib_util/ivas_rtp_pi_data.h @@ -531,7 +531,7 @@ typedef union IVAS_PIDATA_NO_DATA noPiData; } PIDATA; -typedef struct +typedef struct pidata_ts_struct { PIDATA data; uint32_t timestamp; diff --git a/readme.txt b/readme.txt index c7bbcc4f24d11544f7a0b3c5ad4ae19c58253d42..5834999933b040efeb04673ab7e1012c90b2b913 100644 --- a/readme.txt +++ b/readme.txt @@ -33,13 +33,14 @@ These files represent the 3GPP EVS Codec Extension for Immersive Voice and Audio Services (IVAS) BASOP C simulation. All code is writtten -in ISO/IEC C99. The system is implemented as five separate programs: +in ISO/IEC C99. The system is implemented as six separate programs: IVAS_cod IVAS Encoder IVAS_dec IVAS Decoder IVAS_rend IVAS External Renderer ISAR_post_rend ISAR Post Renderer - ambi_converter Ambisonics format converter + IVAS_cod_fmtsw IVAS Encoder with support for format switching + ambi_converter example program for Ambisonics format conversion For encoding using the coder program, the input is a binary audio file (*.8k, *.16k, *.32k, *.48k) and the output is a binary @@ -123,32 +124,39 @@ should have the following structure: . `-- c-code + |-- readme.txt |-- Makefile |-- Workspace_msvc |-- apps + |-- lib_basop |-- lib_com |-- lib_debug |-- lib_dec |-- lib_enc |-- lib_isar |-- lib_lc3plus - |-- lib_rend + |-- lib_rend |-- lib_util - |-- readme.txt - |-- .clang-format + |-- scripts The package includes a Makefile for gcc, which has been verified on 32-bit Linux systems. The code can be compiled by entering the directory "c-code" and typing the command: make. The resulting encoder/decoder/renderer/ ISAR_post_renderer executables are named "IVAS_cod", "IVAS_dec", "IVAS_rend", -and "ISAR_post_rend". All reside in the c-code directory. +and "ISAR_post_rend". All reside in the c-code directory. In addition, this +directory will contain a version of the encoder with support for format switching +(named "IVAS_cod_fmtsw") and an example program for Ambisonics format conversion +(named "ambi_converter"). The package also includes a solution-file for Microsoft Visual Studio 2017 (x86). To compile the code, please open "Workspace_msvc\Workspace_msvc.sln" and build "encoder" for the encoder, "decoder" for the decoder, and "renderer" for the renderer executable. The resulting encoder/decoder/renderer/ISAR_post_renderer executables are "IVAS_cod.exe", "IVAS_dec.exe", "IVAS_rend.exe", and -"ISAR_post_rend.exe". All reside in the c-code main directory. +"ISAR_post_rend.exe". All reside in the c-code main directory. In addition, this +directory will contain a version of the encoder with support for format switching +(named "IVAS_cod_fmtsw.exe") and an example program for Ambisonics format conversion +(named "ambi_converter.exe"). @@ -176,7 +184,7 @@ some potential race conditions. The usage of the "IVAS_cod" program is as follows: -------------------------------------------------- -Usage: IVAS_cod.exe [Options] R Fs input_file bitstream_file +Usage: IVAS_cod [Options] R Fs input_file bitstream_file Mandatory parameters: --------------------- @@ -261,9 +269,9 @@ EVS mono is default, for IVAS choose one of the following: -stereo, -ism, -sba, The usage of the "IVAS_dec" program is as follows: -------------------------------------------------- -Usage for EVS: IVAS_dec.exe [Options] Fs bitstream_file output_file +Usage for EVS: IVAS_dec [Options] Fs bitstream_file output_file OR usage for IVAS (below) with -evs option and OutputConf -Usage for IVAS: IVAS_dec.exe [Options] OutputConf Fs bitstream_file output_file +Usage for IVAS: IVAS_dec [Options] OutputConf Fs bitstream_file output_file Mandatory parameters: --------------------- @@ -310,6 +318,8 @@ Options: -rvf File : Reference vector specified by external trajectory File works only in combination with '-otr ref_vec' and 'ref_vec_lev' modes -render_config File : Binaural renderer configuration parameters in File (only for binaural outputs) +-room_size (S|M|L) : Selects default reverb based on a room size (S - small | M - medium | L - large) + for BINAURAL_ROOM_REVERB output configuration -non_diegetic_pan P : panning mono non-diegetic sound to stereo -90<= P <=90, left or l or 90->left, right or r or -90->right, center or c or 0->middle -exof File : External orientation trajectory File for simulation of external orientations @@ -344,8 +354,9 @@ Options: -rf File : Reference rotation trajectory File for simulation of head tracking (only for binaural outputs) -rvf File : Reference vector trajectory File for simulation of head tracking (only for binaural outputs) -render_config File : Binaural renderer configuration parameters in File (only for binaural outputs) +-room_size (S|M|L) : Selects default reverb based on a room size (S - small | M - medium | L - large) -non_diegetic_pan P : Panning mono non-diegetic sound to stereo -90<= P <= 90 - left or l or 90->left, right or r or -90->right, center or c or 0 ->middle + left or l or 90->left, right or r or -90->right, center or c or 0 ->middle -exof File : External orientation trajectory File for simulation of external orientations -dpid ID : Directivity pattern ID(s) (space-separated list of up to 4 numbers can be specified) for binaural output configuration @@ -356,10 +367,10 @@ Options: for BINAURAL_ROOM_REVERB output configuration. -lp Position : Output LFE position. Comma-delimited triplet of [gain, azimuth, elevation] where gain is linear (like --gain, -g) and azimuth, elevation are in degrees. - If specified, overrides the default behavior which attempts to map input to output LFE channel(s) + If specified, overrides the default behavior which attempts to map input to output LFE channel(s) -lm File : LFE panning matrix File (CSV table) containing a matrix of dimensions [ num_input_lfe x num_output_channels ] with elements specifying linear routing gain (like --gain, -g). - If specified, overrides the output LFE position option and the default behavior which attempts to map input to output LFE channel(s) + If specified, overrides the output LFE position option and the default behavior which attempts to map input to output LFE channel(s) -no_delay_cmp : Turn off delay compensation -g : Input gain (linear, not in dB) to be applied to input audio file -l : List supported audio formats @@ -370,8 +381,8 @@ Options: -q : Quiet mode, limit printouts to terminal, default is deactivated -The usage of the "ISAR_post_rend" program: ------------------------------------------- +The usage of the "ISAR_post_rend" program is as follows: +-------------------------------------------------------- Usage: ISAR_post_rend [options] @@ -385,8 +396,8 @@ Options: -prbfi File : BFI File -The usage of the "ambi_converter" program: ------------------------------------------- +The usage of the "ambi_converter" program is as follows: +-------------------------------------------------------- Usage: ambi_converter input_file output_file input_convention output_convention @@ -399,7 +410,17 @@ the following conventions are supported: 4 : SID-SN3D 5 : SID-N3D -Either the input or the output convention must always be ACN-SN3D! +Either the input or the output convention must always be ACN-SN3D. + +The usage of the "IVAS_cod_fmtsw" program is as follows: +-------------------------------------------------------- + +Usage: IVAS_cod_fmtsw format_switching_file + +Mandatory parameters: +--------------------- +format_switching_file: Text file containing a valid encoder command line in each line + MULTICHANNEL LOUDSPEAKER INPUT / OUTPUT CONFIGURATIONS @@ -684,3 +705,15 @@ obj__relele=0|1 if 1, obj__ele is interpreted as a relative modific If a parameter is not specified, that parameter is not edited. An empty line in the file corresponds to not editing any parameter in the item. Example files are available in folder /scripts/object_edit. + + +RTP streaming file +------------------- +IVAS supports a simple packing and unpacking for streaming file for the RTP. In this format a single RTP_streaming_packet +contains the length of an RTP packet followed by the actual RTP packet which is recorded as-is. This format is produced +by the encoder when using the -rtpdump switch and the decoder assumes this format in the input when -VOIP_hf_only=1 is set. + +typedef struct { + u_int32 length; /* size of the RTP packet in bytes */ + (u_int8 * length) RTP_packet; /* RTP packet (sized length * byte) */ +} RTP_streaming_packet;