diff --git a/apps/encoder.c b/apps/encoder.c index a23970a27071d0604fba171cc5c6345c93793c03..670a67d5a79995425c8a348acf274afdffee3726 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -139,13 +139,24 @@ typedef struct *------------------------------------------------------------------------------------------*/ static void initArgStruct( EncArguments *arg ); -static bool parseCmdlIVAS_enc( int16_t argc, char *argv[], EncArguments *arg ); +static bool parseCmdlIVAS_enc( int16_t argc, char *argv[], EncArguments *arg +#ifdef DEBUG_FORMAT_SWITCHING_ENC + , + const bool reconfig_flag +#endif +); 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 DEBUG_FORMAT_SWITCHING_ENC +static ivas_error configureEnc( const EncArguments arg, IVAS_ENC_HANDLE hIvasEnc, const int32_t totalBitrate, const IVAS_ENC_BANDWIDTH bandwidth, const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig ); +#endif #ifdef DEBUGGING static ivas_error readForcedMode( FILE *file, IVAS_ENC_FORCED_MODE *forcedMode, int32_t *forceFrameCounter ); static IVAS_ENC_FORCED_MODE parseForcedMode( char *forcedModeChar ); +#ifdef DEBUG_FORMAT_SWITCHING_ENC +static void simulate_input_format_switching( int16_t *argc_new, char *p_argv_new[10], bool *reinit_flag ); +#endif #endif @@ -179,6 +190,9 @@ int main( } int16_t *pcmBuf = NULL; #ifdef DEBUGGING +#ifdef DEBUG_FORMAT_SWITCHING_ENC + int16_t pcmBufSize_orig; +#endif FILE *f_forcedModeProfile = NULL; #ifdef DEBUG_SBA int16_t numTransportChannels = 1; @@ -201,7 +215,12 @@ int main( IVAS_ENC_PrintDisclaimer(); - if ( !parseCmdlIVAS_enc( (int16_t) argc, argv, &arg ) ) + if ( !parseCmdlIVAS_enc( (int16_t) argc, argv, &arg +#ifdef DEBUG_FORMAT_SWITCHING_ENC + , + false +#endif + ) ) { /* Error printout done internally in parseCmdlIVAS_enc() */ goto cleanup; @@ -217,7 +236,6 @@ int main( goto cleanup; } - /*------------------------------------------------------------------------------------------* * Open output bitstream file *------------------------------------------------------------------------------------------*/ @@ -361,6 +379,12 @@ int main( * Configure and initialize (allocate memory for static variables) the encoder *------------------------------------------------------------------------------------------*/ +#ifdef DEBUG_FORMAT_SWITCHING_ENC + if ( ( error = configureEnc( arg, hIvasEnc, totalBitrate, bandwidth, caConfig ) ) != IVAS_ERR_OK ) + { + goto cleanup; + } +#else switch ( arg.inputFormat ) { case IVAS_ENC_INPUT_MONO: @@ -432,6 +456,7 @@ int main( fprintf( stderr, "\nInvalid input type\n\n" ); goto cleanup; } +#endif if ( ( error = IVAS_ENC_PrintConfig( hIvasEnc, caConfig.channelAwareModeEnabled ) ) != IVAS_ERR_OK ) { @@ -552,6 +577,9 @@ int main( fprintf( stderr, "\nGetInputBufferSize failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); goto cleanup; } +#ifdef DEBUG_FORMAT_SWITCHING_ENC + pcmBufSize_orig = pcmBufSize; +#endif pcmBuf = malloc( pcmBufSize * sizeof( int16_t ) ); @@ -612,8 +640,58 @@ int main( * - Write the parameters into output bitstream file *------------------------------------------------------------------------------------------*/ +#ifdef DEBUG_FORMAT_SWITCHING_ENC + bool reinit_flag = false; + int16_t pcmBufSize_new = pcmBufSize; + char *p_argv_new[10]; + int16_t argc_new = -1; +#endif + while ( 1 ) { +#ifdef DEBUG_FORMAT_SWITCHING_ENC + /* simulate input format switching */ + simulate_input_format_switching( &argc_new, p_argv_new, &reinit_flag ); + + /* Reinitialization of the encoder in case of application parameter(s) change (e.g. change of IVAS input format) */ + if ( reinit_flag ) + { + IVAS_ENC_Close_Reinit( &hIvasEnc ); + + if ( !parseCmdlIVAS_enc( argc_new, p_argv_new, &arg, true ) ) + { + goto cleanup; + } + + /* Configure and initialize (allocate memory for static variables) the encoder */ + if ( ( error = configureEnc( arg, hIvasEnc, totalBitrate, bandwidth, caConfig ) ) != IVAS_ERR_OK ) + { + goto cleanup; + } + + /* Allocate input data buffer */ + if ( ( error = IVAS_ENC_GetInputBufferSize( hIvasEnc, &pcmBufSize_new ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nGetInputBufferSize failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + + if ( pcmBufSize_new != pcmBufSize ) + { + free( pcmBuf ); + pcmBuf = malloc( ( pcmBufSize_new > pcmBufSize_orig ? pcmBufSize_new : pcmBufSize_orig ) * sizeof( int16_t ) ); + } + } + + if ( pcmBufSize_new < pcmBufSize_orig ) + { + free( pcmBuf ); + pcmBuf = malloc( ( pcmBufSize_new > pcmBufSize_orig ? pcmBufSize_new : pcmBufSize_orig ) * sizeof( int16_t ) ); + } + + pcmBufSize = pcmBufSize_orig; +#endif + /* Read the input data */ if ( ( error = AudioFileReader_read( audioReader, pcmBuf, pcmBufSize, &numSamplesRead ) ) != IVAS_ERR_OK ) { @@ -621,6 +699,49 @@ int main( goto cleanup; } +#ifdef DEBUG_FORMAT_SWITCHING_ENC + if ( pcmBufSize_new > pcmBufSize_orig ) + { + /* keep only channels corresponding to input file channels and zero the others */ + int16_t tmp_buf[16 * 960]; + int16_t nchan = pcmBufSize_new / 960; + int16_t nchan_orig = pcmBufSize / 960; + memcpy( tmp_buf, pcmBuf, numSamplesRead * sizeof( int16_t ) ); + memset( pcmBuf, 0, pcmBufSize_new * sizeof( int16_t ) ); + int16_t k = 0; + for ( i = 0; i < 960; i++ ) + { + for ( int16_t j = 0; j < nchan_orig; j++ ) + { + pcmBuf[i * nchan + j] = tmp_buf[k++]; + } + } + + pcmBufSize = pcmBufSize_new; + numSamplesRead = pcmBufSize; + } + else if ( pcmBufSize_new < pcmBufSize_orig ) + { + int16_t tmp_buf[16 * 960]; + /* skip channels corresponding to non-read input file channels */ + memcpy( tmp_buf, pcmBuf, pcmBufSize * sizeof( int16_t ) ); + free( pcmBuf ); + pcmBuf = malloc( pcmBufSize_new * sizeof( int16_t ) ); + + int16_t fac = pcmBufSize / pcmBufSize_new; + int16_t k = 0; + for ( i = 0; i < pcmBufSize; i += fac ) + { + for ( int16_t j = 0; j < pcmBufSize / pcmBufSize_orig; j++ ) + { + pcmBuf[k++] = tmp_buf[i + j]; + } + } + + pcmBufSize = pcmBufSize_new; + } +#endif + if ( numSamplesRead == 0 ) { /* end of input data */ @@ -913,7 +1034,12 @@ static void initArgStruct( EncArguments *arg ) static bool parseCmdlIVAS_enc( int16_t argc, char *argv[], - EncArguments *arg ) + EncArguments *arg +#ifdef DEBUG_FORMAT_SWITCHING_ENC + , + const bool reconfig_flag +#endif +) { int16_t i, j; char argv_to_upper[FILENAME_MAX]; @@ -1553,6 +1679,17 @@ static bool parseCmdlIVAS_enc( } } /* end of while */ +#ifdef DEBUG_FORMAT_SWITCHING_ENC + /*-----------------------------------------------------------------* + * Return in case of reconfiguration + *-----------------------------------------------------------------*/ + + if ( reconfig_flag == true ) + { + return true; + } +#endif + /*-----------------------------------------------------------------* * Mandatory input arguments *-----------------------------------------------------------------*/ @@ -1841,6 +1978,92 @@ static bool readBitrate( } +#ifdef DEBUG_FORMAT_SWITCHING_ENC +/*---------------------------------------------------------------------* + * configureEnc() + * + * Configure and initialize the encoder + *---------------------------------------------------------------------*/ + +static ivas_error configureEnc( + const EncArguments arg, + IVAS_ENC_HANDLE hIvasEnc, + const int32_t totalBitrate, + const IVAS_ENC_BANDWIDTH bandwidth, + const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig ) +{ + ivas_error error = IVAS_ERR_UNKNOWN; + + 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 ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_ENC_ConfigureForMono failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + return error; + } + 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.inputFormatConfig.stereoMode ) ) != IVAS_ERR_OK ) +#else + if ( ( error = IVAS_ENC_ConfigureForStereo( hIvasEnc, arg.inputFs, totalBitrate, arg.max_bwidth_user, bandwidth, arg.dtxConfig ) ) != IVAS_ERR_OK ) +#endif + { + fprintf( stderr, "\nIVAS_ENC_ConfigureForStereo failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + return error; + } + 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 ) ); + return error; + } + 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 ) ); + return error; + } + + 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 ) ); + return error; + } + 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 ) ); + return error; + } + break; + default: + fprintf( stderr, "\nInvalid input type\n\n" ); + return error; + } + + return error; +} +#endif + + #ifdef DEBUGGING /*---------------------------------------------------------------------* * parseForcedMode() @@ -1925,4 +2148,60 @@ static ivas_error readForcedMode( return IVAS_ERR_OK; } + + +#ifdef DEBUG_FORMAT_SWITCHING_ENC +/*---------------------------------------------------------------------* + * simulate_input_format_switching() + * + * Simulation of IVAS input format switching + *---------------------------------------------------------------------*/ + +#define ENC_FORMAT_VARIANTS 7 + +char input_params[ENC_FORMAT_VARIANTS][6][50] = { + { "1", { "-stereo" } }, + { "4", { "-ism" }, { "2" }, { "NULL" }, { "NULL" } }, + { "2", { "-MC" }, { "5_1" } }, + { "2", { "-sba" }, { "3" } }, + { "3", { "-ism" }, { "1" }, { "NULL" } }, + { "2", { "-sba" }, { "-2" } }, + { "2", { "-MC" }, { "7_1_4" } }, +}; + +static void simulate_input_format_switching( + int16_t *argc_new, + char *p_argv_new[10], + bool *reinit_flag ) +{ + int16_t i; + static int16_t ff = -1; + + *reinit_flag = 0; + *argc_new = -1; + *p_argv_new = NULL; + + if ( frame % 20 == 0 ) + { + ff++; + if ( ff > ENC_FORMAT_VARIANTS - 1 ) + { + ff = 0; + } + *reinit_flag = 1; + } + + if ( *reinit_flag ) + { + *argc_new = (int16_t) atoi( input_params[ff][0] ); + for ( i = 0; i < *argc_new + 1; i++ ) + { + p_argv_new[i] = input_params[ff][i]; + } + *argc_new += 5; /* 4 mandatory parameters + executable name */ + } + + return; +} +#endif #endif diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 672b5a7441735223fbdc3befbf75c92c674bcefe..9647eadf4534b741a284fce0fcec93d62db47838 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -406,12 +406,23 @@ void destroy_core_dec( void ivas_destroy_dec( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#ifdef SWITCHING_FORMAT_DEC + , + const int16_t flag_all /* i : 1 == destroy external data handles */ +#endif ); void ivas_initialize_handles_dec( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); +#ifdef SWITCHING_FORMAT_DEC +void ivas_decoder_init_highlevel_params( + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); +#endif + ivas_error ivas_core_enc( SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ diff --git a/lib_com/options.h b/lib_com/options.h index de0967fc1a4eaf72aa4a75d8187157ffe645525e..649575a213e0a166b80960e589dcc20dbb58a5f4 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -211,6 +211,10 @@ #define FIX_DTX_428 /* FhG: fix for issue 428, crash with DTX and bitrate switching */ +#define SWITCHING_FORMAT_DEC /* VA: issue 326: Bitstream Switching (Decoder side) */ +/*#define DEBUG_FORMAT_SWITCHING_ENC*/ /* simulate Input format switching */ + + /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index ef9cbdf54bf9fe4e1237807f4f65175111bac9e3..ba807261a09e210e3999cb872ca1b1775fb6a498 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -75,6 +75,12 @@ ivas_error ivas_dec_setup( Decoder_State *st; int32_t ivas_total_brate; ivas_error error; +#ifdef SWITCHING_FORMAT_DEC + IVAS_FORMAT ivas_format_old; + + ivas_format_old = st_ivas->ivas_format; +#endif + error = IVAS_ERR_OK; num_bits_read = 0; @@ -88,17 +94,39 @@ ivas_error ivas_dec_setup( ivas_read_format( st_ivas, &num_bits_read ); +#ifdef SWITCHING_FORMAT_DEC + /*-------------------------------------------------------------------* + * Reinitialize the decoder in case of the IVAS format change + *-------------------------------------------------------------------*/ - if ( is_DTXrate( ivas_total_brate ) == 0 ) + if ( ivas_format_old != st_ivas->ivas_format && st_ivas->ini_frame > 0 ) // Note: for OMASA/OSBA, this condtion need to be changed!!! { - /*-------------------------------------------------------------------* - * Read IVAS format related signaling: - * - in ISM : read number of objects - * - in SBA : read SBA planar flag and SBA order - * - in MASA : read number of TC - * - in MC : read LS setup - *-------------------------------------------------------------------*/ + IVAS_FORMAT ivas_format_read = st_ivas->ivas_format; + + /* Destroy the decoder handle */ + st_ivas->ivas_format = ivas_format_old; + ivas_destroy_dec( st_ivas, 0 ); + + /* set decoder high level parameters */ + ivas_decoder_init_highlevel_params( ivas_format_read, st_ivas ); + + st_ivas->nSCE = 0; + st_ivas->nCPE = 0; + st_ivas->nchan_transport = -1; + st_ivas->sba_dirac_stereo_flag = 0; + } +#endif + + /*-------------------------------------------------------------------* + * Read IVAS format related signaling: + * - in ISM : read number of objects + * - in SBA : read SBA planar flag and SBA order + * - in MASA : read number of TC + * - in MC : read LS setup + *-------------------------------------------------------------------*/ + if ( is_DTXrate( ivas_total_brate ) == 0 ) + { if ( st_ivas->ivas_format == STEREO_FORMAT ) { element_mode_flag = 1; @@ -152,6 +180,10 @@ ivas_error ivas_dec_setup( } else { +#ifdef SWITCHING_FORMAT_DEC + st_ivas->sba_mode = ivas_sba_mode_select(); +#endif + ivas_sba_config( ivas_total_brate, st_ivas->sba_analysis_order, -1, &( st_ivas->nchan_transport ), st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init ); } } @@ -412,7 +444,9 @@ static ivas_error ivas_read_format( else { st_ivas->ivas_format = SBA_FORMAT; +#ifndef SWITCHING_FORMAT_DEC st_ivas->sba_mode = ivas_sba_mode_select(); +#endif } ( *num_bits_read )++; break; @@ -904,7 +938,6 @@ ivas_error ivas_init_decoder( } else if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT ) { - if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) { return error; @@ -919,6 +952,10 @@ ivas_error ivas_init_decoder( } else if ( st_ivas->ivas_format == SBA_FORMAT ) { +#ifdef SWITCHING_FORMAT_DEC + st_ivas->sba_mode = ivas_sba_mode_select(); +#endif + if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { if ( ( error = ivas_spar_dec_open( st_ivas, 0 ) ) != IVAS_ERR_OK ) @@ -1742,6 +1779,53 @@ void ivas_initialize_handles_dec( } +#ifdef SWITCHING_FORMAT_DEC +/*----------------------------------------------------------------- + * ivas_decoder_init_highlevel_params() + * + * Initialize high-level parameters + *-----------------------------------------------------------------*/ + +void ivas_decoder_init_highlevel_params( + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +) +{ + st_ivas->ivas_format = ivas_format; + + if ( ivas_format == MONO_FORMAT ) + { + st_ivas->codec_mode = 0; /* unknown before first frame */ + st_ivas->element_mode_init = EVS_MONO; + st_ivas->transport_config = AUDIO_CONFIG_INVALID; + st_ivas->intern_config = AUDIO_CONFIG_INVALID; + st_ivas->writeFECoffset = 0; + } + else + { + st_ivas->codec_mode = 0; /* unknown before first frame */ + st_ivas->element_mode_init = -1; + st_ivas->transport_config = AUDIO_CONFIG_INVALID; + st_ivas->intern_config = AUDIO_CONFIG_INVALID; + st_ivas->renderer_type = RENDERER_DISABLE; + st_ivas->ini_frame = 0; + st_ivas->ini_active_frame = 0; + st_ivas->writeFECoffset = 0; + + st_ivas->ism_mode = ISM_MODE_NONE; + st_ivas->sba_mode = SBA_MODE_NONE; + st_ivas->mc_mode = MC_MODE_NONE; + + st_ivas->sba_order = 0; + st_ivas->sba_planar = 0; + st_ivas->sba_analysis_order = 0; + } + + return; +} +#endif + + /*------------------------------------------------------------------------- * ivas_destroy_dec() * @@ -1750,6 +1834,10 @@ void ivas_initialize_handles_dec( void ivas_destroy_dec( Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ +#ifdef SWITCHING_FORMAT_DEC + , + const int16_t flag_all /* i : 1 == destroy external data handles */ +#endif ) { int16_t i; @@ -1897,48 +1985,58 @@ void ivas_destroy_dec( st_ivas->hMonoDmxRenderer = NULL; } - /* Head track data handle */ - ivas_headTrack_close( &st_ivas->hHeadTrackData ); - - /* Time Domain binaural renderer handle */ - if ( st_ivas->hBinRendererTd != NULL ) +#ifdef SWITCHING_FORMAT_DEC + if ( flag_all ) { - ivas_td_binaural_close( &st_ivas->hBinRendererTd ); - } - else if ( st_ivas->hHrtfTD != NULL ) - { - BSplineModelEvalDealloc( &st_ivas->hHrtfTD->ModelParams, &st_ivas->hHrtfTD->ModelEval ); +#endif + /* Head track data handle */ + ivas_headTrack_close( &st_ivas->hHeadTrackData ); - ivas_HRTF_binary_close( &st_ivas->hHrtfTD ); - } + /* Time Domain binaural renderer handle */ + if ( st_ivas->hBinRendererTd != NULL ) + { + ivas_td_binaural_close( &st_ivas->hBinRendererTd ); + } + else if ( st_ivas->hHrtfTD != NULL ) + { + BSplineModelEvalDealloc( &st_ivas->hHrtfTD->ModelParams, &st_ivas->hHrtfTD->ModelEval ); + + ivas_HRTF_binary_close( &st_ivas->hHrtfTD ); + } - /* CRend binaural renderer handle */ - ivas_HRTF_CRend_binary_close( &st_ivas->hSetOfHRTF ); + /* CRend binaural renderer handle */ + ivas_HRTF_CRend_binary_close( &st_ivas->hSetOfHRTF ); - /* Fastconv HRTF filters */ - ivas_HRTF_fastconv_binary_close( &st_ivas->hHrtfFastConv ); + /* Fastconv HRTF filters */ + ivas_HRTF_fastconv_binary_close( &st_ivas->hHrtfFastConv ); - /* Parametric binauralizer HRTF filters */ - ivas_HRTF_parambin_binary_close( &st_ivas->hHrtfParambin ); + /* Parametric binauralizer HRTF filters */ + ivas_HRTF_parambin_binary_close( &st_ivas->hHrtfParambin ); - /* Config. Renderer */ - ivas_render_config_close( &( st_ivas->hRenderConfig ) ); + /* Config. Renderer */ + ivas_render_config_close( &( st_ivas->hRenderConfig ) ); + +#ifdef SWITCHING_FORMAT_DEC + } +#endif + +#ifdef JBM_TSM_ON_TCS + ivas_jbm_dec_tc_buffer_close( &st_ivas->hTcBuffer ); +#endif /* Limiter struct */ ivas_limiter_close( &( st_ivas->hLimiter ) ); +#ifndef SWITCHING_FORMAT_DEC if ( st_ivas->hDecoderConfig != NULL ) { free( st_ivas->hDecoderConfig ); st_ivas->hDecoderConfig = NULL; } -#ifdef JBM_TSM_ON_TCS - ivas_jbm_dec_tc_buffer_close( &st_ivas->hTcBuffer ); -#endif - /* main IVAS handle */ free( st_ivas ); +#endif return; } diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 17c718bb48291022b3cd71862a3c2399c5c1f239..d49e029dad558e7b6d762ebc375d26ba12ae411f 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -207,6 +207,24 @@ ivas_error IVAS_DEC_Open( /* initialize pointers to handles to NULL */ ivas_initialize_handles_dec( st_ivas ); +#ifdef SWITCHING_FORMAT_DEC + /*-----------------------------------------------------------------* + * Initialize high-level parameters + *-----------------------------------------------------------------*/ + + if ( mode == IVAS_DEC_MODE_EVS ) + { + ivas_decoder_init_highlevel_params( MONO_FORMAT, st_ivas ); + + return IVAS_ERR_OK; + } + else if ( mode == IVAS_DEC_MODE_IVAS ) + { + ivas_decoder_init_highlevel_params( UNDEFINED_FORMAT, st_ivas ); + + return IVAS_ERR_OK; + } +#else /* set high-level parameters */ if ( mode == IVAS_DEC_MODE_EVS ) { @@ -241,6 +259,7 @@ ivas_error IVAS_DEC_Open( return IVAS_ERR_OK; } +#endif return IVAS_ERR_WRONG_PARAMS; } @@ -307,7 +326,20 @@ void IVAS_DEC_Close( if ( ( *phIvasDec )->st_ivas ) { +#ifdef SWITCHING_FORMAT_DEC + ivas_destroy_dec( ( *phIvasDec )->st_ivas, 1 ); + + if ( ( *phIvasDec )->st_ivas->hDecoderConfig != NULL ) + { + free( ( *phIvasDec )->st_ivas->hDecoderConfig ); + ( *phIvasDec )->st_ivas->hDecoderConfig = NULL; + } + + /* main IVAS handle */ + free( ( *phIvasDec )->st_ivas ); +#else ivas_destroy_dec( ( *phIvasDec )->st_ivas ); +#endif ( *phIvasDec )->st_ivas = NULL; } diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 6121bd588f83b350d7a127c33a79b355f61ea1c8..637a70f5bfccbf5064da8bf1e867f017b3e37046 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -396,6 +396,7 @@ ivas_error ivas_enc( hEncoderConfig->last_ivas_total_brate = ivas_total_brate; #ifdef DEBUG_MODE_INFO + dbgwrite( &ivas_format, sizeof( int16_t ), 1, input_frame, "res/ivas_format" ); { float tmpF = ivas_total_brate / 1000.0f; dbgwrite( &tmpF, sizeof( float ), 1, input_frame, "res/ivas_total_brate" ); diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index e858074445b286935945a97ae7f9c5f0168d8d03..ee069ec220b07b0c08fee072cc7530a55353b24a 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -1038,6 +1038,7 @@ void ivas_destroy_enc( /* Stereo downmix for EVS encoder handle */ stereo_dmx_evs_close_encoder( &( st_ivas->hStereoDmxEVS ) ); +#ifndef DEBUG_FORMAT_SWITCHING_ENC /* Encoder configuration handle */ if ( st_ivas->hEncoderConfig != NULL ) { @@ -1047,6 +1048,6 @@ void ivas_destroy_enc( /* main IVAS handle */ free( st_ivas ); - +#endif return; } diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 5c310ac30fcb3a66be6e666712db0a70fd870d67..4aaac56a8c8a457e385f5527b652bb457f55931b 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -176,6 +176,14 @@ ivas_error ivas_ism_enc( { vad_flag[sce_id] = st->vad_flag; } + +#ifdef DEBUG_MODE_INFO + if ( sce_id == 0 ) + { + dbgwrite( st->input - NS2SA( st->input_Fs, ACELP_LOOK_NS ), sizeof( float ), input_frame, 1, "res/input_DMX" ); + dbgwrite( &st->element_mode, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "element_mode", 0, st->id_element, ENC ) ); + } +#endif } /*------------------------------------------------------------------* diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index c0c23b8dd9cf7a725e55b22a37dd78d140bcc8a7..e038352671305deff9cda4e1d82618c7f7cb5660 100755 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -209,6 +209,7 @@ void IVAS_ENC_Close( { ivas_destroy_enc( ( *phIvasEnc )->st_ivas ); } +#ifndef DEBUG_FORMAT_SWITCHING_ENC else { if ( ( *phIvasEnc )->st_ivas->hEncoderConfig ) @@ -218,7 +219,19 @@ void IVAS_ENC_Close( } free( ( *phIvasEnc )->st_ivas ); } +#endif + +#ifdef DEBUG_FORMAT_SWITCHING_ENC + /* Encoder configuration handle */ + if ( ( *phIvasEnc )->st_ivas->hEncoderConfig ) + { + free( ( *phIvasEnc )->st_ivas->hEncoderConfig ); + ( *phIvasEnc )->st_ivas->hEncoderConfig = NULL; + } + /* main IVAS handle */ + free( ( *phIvasEnc )->st_ivas ); +#endif ( *phIvasEnc )->st_ivas = NULL; #ifdef BITSTREAM_INDICES_MEMORY @@ -236,6 +249,35 @@ void IVAS_ENC_Close( } +#ifdef DEBUG_FORMAT_SWITCHING_ENC +/*---------------------------------------------------------------------* + * IVAS_ENC_Close_Reinit() + * + * + *---------------------------------------------------------------------*/ + +void IVAS_ENC_Close_Reinit( + IVAS_ENC_HANDLE *phIvasEnc /* i/o: pointer to IVAS encoder handle */ +) +{ + /* Free all memory */ + if ( phIvasEnc == NULL || *phIvasEnc == NULL ) + { + return; + } + + if ( ( *phIvasEnc )->isConfigured ) + { + ivas_destroy_enc( ( *phIvasEnc )->st_ivas ); + } + + ( *phIvasEnc )->isConfigured = false; + + return; +} +#endif + + /*---------------------------------------------------------------------* * IVAS_ENC_ConfigureForMono() * @@ -1834,10 +1876,12 @@ static ivas_error doCommonConfigureChecks( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } +#ifndef DEBUG_FORMAT_SWITCHING_ENC if ( hIvasEnc->isConfigured ) { return IVAS_ERR_RECONFIGURE_NOT_SUPPORTED; } +#endif return IVAS_ERR_OK; } diff --git a/lib_enc/lib_enc.h b/lib_enc/lib_enc.h index 3a6a619f7368b2db1398edd65f3d5cb4f12d3a57..913a917b25e8f77d69a9daa10e6ca8f97645a4fe 100644 --- a/lib_enc/lib_enc.h +++ b/lib_enc/lib_enc.h @@ -239,6 +239,12 @@ void IVAS_ENC_Close( IVAS_ENC_HANDLE *phIvasEnc /* i/o: pointer to IVAS encoder handle */ ); +#ifdef DEBUG_FORMAT_SWITCHING_ENC +void IVAS_ENC_Close_Reinit( + IVAS_ENC_HANDLE *phIvasEnc /* i/o: pointer to IVAS encoder handle */ +); +#endif + /* Encoding functions - should be called with a configured encoder handle */ /*! r: error code */