From bc8afc8e0d4fea1e7aa24f958649b9aac6cbcb72 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 23 Aug 2023 10:14:41 +0200 Subject: [PATCH 01/20] - call memory allocate/reallocation from the application - encoder side #define MEM_ALLOC_APP /* VA: */ #define MEM_ALLOC_APP_NONBE --- apps/encoder.c | 17 +++ lib_com/ivas_prot.h | 6 ++ lib_com/options.h | 3 + lib_enc/ivas_enc.c | 33 ++++-- lib_enc/ivas_init_enc.c | 64 +++++++++++ lib_enc/ivas_mct_enc.c | 5 +- lib_enc/ivas_omasa_enc.c | 3 +- lib_enc/lib_enc.c | 223 +++++++++++++++++++++++++++++++++++++++ lib_enc/lib_enc.h | 13 +++ 9 files changed, 359 insertions(+), 8 deletions(-) diff --git a/apps/encoder.c b/apps/encoder.c index 2b4016bcb8..f808f0f7b2 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -467,6 +467,15 @@ int main( goto cleanup; } +#ifdef MEM_ALLOC_APP_NONBE + /* Initialize IVAS encoder handles and allocate the memory */ + if ( ( error = IVAS_ENC_Initialize( hIvasEnc ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_ENC_Initialize failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } +#endif + 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 ) ); @@ -778,6 +787,14 @@ int main( } } +#ifdef MEM_ALLOC_APP_NONBE + /* Reconfigure IVAS encoder handles and reallocate the memory if IVAS total bitrate has changed */ + if ( ( error = IVAS_ENC_Reconfigure( hIvasEnc ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif + /* *** Encode one frame *** */ if ( ( error = IVAS_ENC_EncodeFrameToSerial( hIvasEnc, pcmBuf, pcmBufSize, bitStream, &numBits ) ) != IVAS_ERR_OK ) { diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index a9fba371ab..eb4fd3d074 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -282,6 +282,12 @@ void ivas_destroy_enc( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); +#ifdef MEM_ALLOC_APP +ivas_error ivas_reconfig_enc( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); +#endif + ivas_error ivas_init_decoder_front( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); diff --git a/lib_com/options.h b/lib_com/options.h index be3261f808..224caaf8eb 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -169,6 +169,9 @@ #define FIX_719_CRASH_IN_CLEANUP /* VA: issue 719: fix Decoder crash after call to goto to cleanup */ +#define MEM_ALLOC_APP /* VA: call memory allocate/reallocation from the application */ +#define MEM_ALLOC_APP_NONBE + /* ################## End BE DEVELOPMENT switches ######################### */ /* #################### Start NON-BE CR switches ########################## */ diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 8096199382..a206764429 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -148,6 +148,15 @@ ivas_error ivas_enc( } #endif +#ifndef MEM_ALLOC_APP_NONBE +#ifdef MEM_ALLOC_APP + if ( ( error = ivas_reconfig_enc( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif +#endif + /*----------------------------------------------------------------* * write IVAS format signaling *----------------------------------------------------------------*/ @@ -168,12 +177,13 @@ ivas_error ivas_enc( } else if ( ivas_format == ISM_FORMAT ) { +#ifndef MEM_ALLOC_APP /* select ISM format mode; reconfigure the ISM format encoder */ if ( ( error = ivas_ism_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { return error; } - +#endif if ( st_ivas->ism_mode == ISM_MODE_PARAM ) { ivas_param_ism_enc( st_ivas, data_f, input_frame ); @@ -203,11 +213,12 @@ ivas_error ivas_enc( /* SBA/MASA configuration */ if ( ivas_format == SBA_FORMAT ) { +#ifndef MEM_ALLOC_APP if ( ( error = ivas_sba_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) { return error; } - +#endif st = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0]; /* Write SBA planar flag */ @@ -216,10 +227,12 @@ ivas_error ivas_enc( /* Write SBA order */ push_indice( st->hBstr, IND_SMODE, hEncoderConfig->sba_order, SBA_ORDER_BITS ); } +#ifndef MEM_ALLOC_APP else { ivas_masa_enc_reconfigure( st_ivas ); } +#endif /* SBA/MASA metadata encoding and SBA/MASA metadata bitstream writing */ hMetaData = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData : st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; @@ -228,10 +241,12 @@ ivas_error ivas_enc( { ivas_masa_estimate_energy( st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport ); /* energy-estimation uses TF-resolution: 4x24 */ +#ifndef MEM_ALLOC_APP if ( ( error = ivas_masa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { return error; } +#endif if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK ) @@ -293,11 +308,12 @@ ivas_error ivas_enc( /* Estimate TF-tile energy for the input MASA stream */ ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport ); +#ifndef MEM_ALLOC_APP if ( ( error = ivas_omasa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { return error; } - +#endif set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); idx_separated_object = 0; data_separated_object = data_f[hEncoderConfig->nchan_ism + CPE_CHANNELS]; @@ -368,9 +384,9 @@ ivas_error ivas_enc( } else if ( ivas_format == SBA_ISM_FORMAT ) { - +#ifndef MEM_ALLOC_APP ivas_osba_enc_reconfig( st_ivas ); - +#endif /* Analyze objects and determine needed audio signals */ ivas_osba_enc( st_ivas->hOSba, st_ivas->hIsmMetaData, data_f, input_frame, hEncoderConfig->nchan_ism, st_ivas->ism_mode, st_ivas->sba_analysis_order, hEncoderConfig->input_Fs ); @@ -493,12 +509,17 @@ ivas_error ivas_enc( } else if ( ivas_format == MC_FORMAT ) { +#ifdef MEM_ALLOC_APP + /* write MC LS setup */ + st = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0]; + push_indice( st->hBstr, IND_SMODE, st_ivas->hEncoderConfig->mc_input_setup, MC_LS_SETUP_BITS ); +#else /* select MC format mode; write MC LS setup; reconfigure the MC format encoder */ if ( ( error = ivas_mc_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { return error; } - +#endif hMetaData = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData : st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; /* LFE low pass filter */ diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 4a870d5977..7b46438e63 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -1222,3 +1222,67 @@ void ivas_destroy_enc( return; } + + +#ifdef MEM_ALLOC_APP +/*------------------------------------------------------------------------- + * ivas_reconfig_enc() + * + * Reconfigure IVAS encoder handles and reallocate the memory based on + * changes of 'hEncoderConfig' parameters, typically ivas_total_brate + *-------------------------------------------------------------------------*/ + +ivas_error ivas_reconfig_enc( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +) +{ + ivas_error error; + IVAS_FORMAT ivas_format; + + ivas_format = st_ivas->hEncoderConfig->ivas_format; + + if ( ivas_format == STEREO_FORMAT ) + { + /* stereo_memory_enc() is called from ivas_cpe_enc() */ + return IVAS_ERR_OK; + } + else if ( ivas_format == ISM_FORMAT ) + { + /* select ISM format mode; reconfigure the ISM format encoder */ + error = ivas_ism_enc_config( st_ivas ); + } + else if ( ivas_format == SBA_FORMAT ) + { + /* reconfigure the SBA format encoder */ + error = ivas_sba_enc_reconfigure( st_ivas ); + } + else if ( ivas_format == MASA_FORMAT ) + { + ivas_masa_enc_reconfigure( st_ivas ); + + /* reconfigure the SBA format encoder */ + error = ivas_masa_enc_config( st_ivas ); + } + else if ( ivas_format == SBA_ISM_FORMAT ) + { + /* select ISM format mode; reconfigure the OSBA format encoder */ + error = ivas_osba_enc_reconfig( st_ivas ); + } + else if ( ivas_format == MASA_ISM_FORMAT ) + { + /* select ISM format mode; reconfigure the OMASA format encoder */ + error = ivas_omasa_enc_config( st_ivas ); + } + else if ( ivas_format == MC_FORMAT ) + { + /* select MC format mode; reconfigure the MC format encoder */ + error = ivas_mc_enc_config( st_ivas ); + } + else + { + return IVAS_ERROR( IVAS_ERR_INVALID_INPUT_FORMAT, "Error: unsupported input audio format" ); + } + + return error; +} +#endif diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 895e864797..44c1768a5e 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -611,7 +611,9 @@ ivas_error ivas_mc_enc_config( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) { +#ifndef MEM_ALLOC_APP Encoder_State *st0; /* used for bitstream handling */ +#endif MC_MODE last_mc_mode; ivas_error error; @@ -622,10 +624,11 @@ ivas_error ivas_mc_enc_config( /* select MC format mode */ st_ivas->mc_mode = ivas_mc_mode_select( st_ivas->hEncoderConfig->mc_input_setup, st_ivas->hEncoderConfig->ivas_total_brate ); +#ifndef MEM_ALLOC_APP /* write MC LS setup */ st0 = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0]; push_indice( st0->hBstr, IND_SMODE, st_ivas->hEncoderConfig->mc_input_setup, MC_LS_SETUP_BITS ); - +#endif /* MC format switching */ if ( st_ivas->hEncoderConfig->last_ivas_total_brate != st_ivas->hEncoderConfig->ivas_total_brate || st_ivas->mc_mode != last_mc_mode ) { diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 5f232d8168..5684c91eb3 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -254,6 +254,7 @@ ivas_error ivas_omasa_enc_config( return error; } +#ifndef MEM_ALLOC_APP /* re-write IVAS format signalling - actual 'ism_mode' was not known before */ if ( st_ivas->nSCE > 0 ) { @@ -265,7 +266,7 @@ ivas_error ivas_omasa_enc_config( } ivas_write_format( st_ivas ); - +#endif if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->hOMasa == NULL ) { if ( ( error = ivas_omasa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index c1c8b047e8..c4f1759ae3 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -729,6 +729,217 @@ ivas_error IVAS_ENC_ConfigureForMultichannel( } +#ifdef MEM_ALLOC_APP_NONBE +/*---------------------------------------------------------------------* + * IVAS_ENC_Initialize() + * + * Initialize IVAS encoder handles and allocate the memory + *---------------------------------------------------------------------*/ + +/*! r: error code */ +ivas_error IVAS_ENC_Initialize( + IVAS_ENC_HANDLE hIvasEnc /* i/o: IVAS encoder handle */ +) +{ + Encoder_Struct *st_ivas; + ivas_error error; + + if ( hIvasEnc == NULL || hIvasEnc->st_ivas == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + st_ivas = hIvasEnc->st_ivas; + + if ( ( error = ivas_init_encoder( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( st_ivas->hEncoderConfig->ivas_format == MONO_FORMAT ) + { + hIvasEnc->hCoreCoder = st_ivas->hSCE[0]->hCoreCoder[0]; /* Note: this is needed for switching in EVS mono */ + } + else + { + hIvasEnc->hCoreCoder = NULL; + } + + return IVAS_ERR_OK; +} + + +/*---------------------------------------------------------------------* + * IVAS_ENC_ReconfigureIVAS() + * + * Reconfigure IVAS encoder handles and reallocate the memory based on + * changes of 'hEncoderConfig' parameters, typically ivas_total_brate + *---------------------------------------------------------------------*/ + +/*! r: error code */ +ivas_error IVAS_ENC_Reconfigure( + IVAS_ENC_HANDLE hIvasEnc /* i/o: IVAS encoder handle */ +) +{ + Encoder_Struct *st_ivas; + ENCODER_CONFIG_HANDLE hEncoderConfig; + ENC_CORE_HANDLE hCoreCoder; + int16_t i, ch, n; + ivas_error error; + + error = IVAS_ERR_OK; + + if ( !hIvasEnc->isConfigured ) + { + return IVAS_ERR_NOT_CONFIGURED; + } + + st_ivas = hIvasEnc->st_ivas; + hEncoderConfig = st_ivas->hEncoderConfig; + hCoreCoder = hIvasEnc->hCoreCoder; + + if ( ( error = sanitizeBandwidth( hIvasEnc ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( ( hEncoderConfig->Opt_RF_ON && ( hEncoderConfig->ivas_total_brate != ACELP_13k20 || hEncoderConfig->input_Fs == 8000 || hEncoderConfig->max_bwidth == NB ) ) || hEncoderConfig->rf_fec_offset == 0 ) + { + if ( hEncoderConfig->ivas_total_brate == ACELP_13k20 && hEncoderConfig->ivas_format == MONO_FORMAT ) + { + st_ivas->codec_mode = MODE1; + reset_rf_indices( hCoreCoder->hRF, hCoreCoder->L_frame, &( hCoreCoder->rf_target_bits_write ) ); + } + hEncoderConfig->Opt_RF_ON = 0; + hEncoderConfig->rf_fec_offset = 0; + hIvasEnc->switchingActive = true; + } + + if ( hIvasEnc->Opt_RF_ON_loc && hIvasEnc->rf_fec_offset_loc != 0 && L_sub( hEncoderConfig->ivas_total_brate, ACELP_13k20 ) == 0 && L_sub( hEncoderConfig->input_Fs, 8000 ) != 0 && hEncoderConfig->max_bwidth != NB ) + { + st_ivas->codec_mode = MODE2; + if ( hEncoderConfig->Opt_RF_ON == 0 && hEncoderConfig->ivas_format == MONO_FORMAT ) + { + reset_rf_indices( hCoreCoder->hRF, hCoreCoder->L_frame, &( hCoreCoder->rf_target_bits_write ) ); + } + hEncoderConfig->Opt_RF_ON = 1; + hEncoderConfig->rf_fec_offset = hIvasEnc->rf_fec_offset_loc; + hIvasEnc->switchingActive = true; + } + + /* in case of 8kHz sampling rate or when in "max_band NB" mode, limit the total bitrate to 24.40 kbps */ + if ( ( ( hEncoderConfig->input_Fs == 8000 ) || ( hEncoderConfig->max_bwidth == NB ) ) && ( hEncoderConfig->ivas_total_brate > ACELP_24k40 ) ) + { + hEncoderConfig->ivas_total_brate = ACELP_24k40; + st_ivas->codec_mode = MODE2; + hIvasEnc->switchingActive = true; + } + + /*-----------------------------------------------------------------* + * Reconfigure IVAS encoder handles and reallocate the memory + * if IVAS total bitrate has changed + *-----------------------------------------------------------------*/ + + if ( hEncoderConfig->ivas_format != MONO_FORMAT ) + { + if ( ( error = ivas_reconfig_enc( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /*-----------------------------------------------------------------* + * Re-allocate and re-initialize buffer of indices if IVAS total bitrate has changed + *-----------------------------------------------------------------*/ + + if ( hEncoderConfig->ivas_total_brate != hEncoderConfig->last_ivas_total_brate ) + { + /* de-allocate old buffer of indices */ + free( st_ivas->ind_list ); + + /* set the maximum allowed number of indices in the list */ + st_ivas->ivas_max_num_indices = get_ivas_max_num_indices( hEncoderConfig->ivas_format, hEncoderConfig->ivas_total_brate ); + + /* allocate new buffer of indices */ + if ( ( st_ivas->ind_list = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices * sizeof( Indice ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of indices!\n" ) ); + } + + /* reset the list of indices */ + for ( i = 0; i < st_ivas->ivas_max_num_indices; i++ ) + { + st_ivas->ind_list[i].nb_bits = -1; + } + + /* de-allocate old buffer of metadata indices */ + if ( st_ivas->ind_list_metadata != NULL ) + { + free( st_ivas->ind_list_metadata ); + } + + /* set the maximum allowed number of metadata indices in the list */ + st_ivas->ivas_max_num_indices_metadata = get_ivas_max_num_indices_metadata( hEncoderConfig->ivas_format, hEncoderConfig->ivas_total_brate ); + + if ( st_ivas->ivas_max_num_indices_metadata > 0 ) + { + /* allocate new buffer of metadata indices */ + if ( ( st_ivas->ind_list_metadata = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices_metadata * sizeof( Indice ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of metadata indices!\n" ) ); + } + + /* reset the list of metadata indices */ + for ( i = 0; i < st_ivas->ivas_max_num_indices_metadata; i++ ) + { + st_ivas->ind_list_metadata[i].nb_bits = -1; + } + } + else + { + st_ivas->ind_list_metadata = NULL; + } + + /* set pointers to the new buffers of indices in each element */ + for ( n = 0; n < st_ivas->nSCE; n++ ) + { + st_ivas->hSCE[n]->hCoreCoder[0]->hBstr->ind_list = st_ivas->ind_list; + st_ivas->hSCE[n]->hCoreCoder[0]->hBstr->ivas_ind_list_zero = &st_ivas->ind_list; + + if ( st_ivas->hSCE[n]->hMetaData != NULL ) + { + st_ivas->hSCE[n]->hMetaData->ind_list = st_ivas->ind_list_metadata; + st_ivas->hSCE[n]->hMetaData->ivas_ind_list_zero = &st_ivas->ind_list_metadata; + } + } + + for ( n = 0; n < st_ivas->nCPE; n++ ) + { + for ( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + st_ivas->hCPE[n]->hCoreCoder[ch]->hBstr->ind_list = st_ivas->ind_list; + st_ivas->hCPE[n]->hCoreCoder[ch]->hBstr->ivas_ind_list_zero = &st_ivas->ind_list; + } + + if ( st_ivas->hCPE[n]->hMetaData != NULL ) + { + st_ivas->hCPE[n]->hMetaData->ind_list = st_ivas->ind_list_metadata; + st_ivas->hCPE[n]->hMetaData->ivas_ind_list_zero = &st_ivas->ind_list_metadata; + } + } + } + + if ( hIvasEnc->switchingActive && hEncoderConfig->ivas_format == MONO_FORMAT ) + { + copy_encoder_config( st_ivas, hCoreCoder, 0 ); + hEncoderConfig->last_ivas_total_brate = hEncoderConfig->ivas_total_brate; + } + + return IVAS_ERR_OK; +} +#endif + + /*---------------------------------------------------------------------* * configureEncoder() * @@ -1009,6 +1220,7 @@ static ivas_error configureEncoder( return IVAS_ERROR( IVAS_ERR_NOT_SUPPORTED_OPTION, "'-binaural' option is supported only with '-stereo' or '-stereo_dmx_evs'" ); } +#ifndef MEM_ALLOC_APP_NONBE /*-----------------------------------------------------------------* * Finalize initialization *-----------------------------------------------------------------*/ @@ -1026,7 +1238,12 @@ static ivas_error configureEncoder( { hIvasEnc->hCoreCoder = NULL; } +#else + /*-----------------------------------------------------------------* + * Final updates + *-----------------------------------------------------------------*/ +#endif hIvasEnc->Opt_RF_ON_loc = hEncoderConfig->Opt_RF_ON; hIvasEnc->rf_fec_offset_loc = hEncoderConfig->rf_fec_offset; @@ -1157,7 +1374,9 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( ENCODER_CONFIG_HANDLE hEncoderConfig; ENC_CORE_HANDLE hCoreCoder; int16_t i; +#ifndef MEM_ALLOC_APP_NONBE int16_t n, ch; +#endif ivas_error error; error = IVAS_ERR_OK; @@ -1176,10 +1395,12 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( return IVAS_ERR_INVALID_INPUT_BUFFER_SIZE; } +#ifndef MEM_ALLOC_APP_NONBE if ( ( error = sanitizeBandwidth( hIvasEnc ) ) != IVAS_ERR_OK ) { return error; } +#endif if ( hEncoderConfig->ivas_format == ISM_FORMAT ) { @@ -1193,6 +1414,7 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( resetIsmMetadataProvidedFlags( hIvasEnc ); } +#ifndef MEM_ALLOC_APP_NONBE if ( ( hEncoderConfig->Opt_RF_ON && ( hEncoderConfig->ivas_total_brate != ACELP_13k20 || hEncoderConfig->input_Fs == 8000 || hEncoderConfig->max_bwidth == NB ) ) || hEncoderConfig->rf_fec_offset == 0 ) { if ( hEncoderConfig->ivas_total_brate == ACELP_13k20 && hEncoderConfig->ivas_format == MONO_FORMAT ) @@ -1311,6 +1533,7 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( copy_encoder_config( st_ivas, hCoreCoder, 0 ); hEncoderConfig->last_ivas_total_brate = hEncoderConfig->ivas_total_brate; } +#endif /* run the main encoding routine */ if ( hEncoderConfig->ivas_format == MONO_FORMAT ) /* EVS mono */ diff --git a/lib_enc/lib_enc.h b/lib_enc/lib_enc.h index b7582ed9e4..b7712876cf 100644 --- a/lib_enc/lib_enc.h +++ b/lib_enc/lib_enc.h @@ -271,6 +271,19 @@ void IVAS_ENC_Close( IVAS_ENC_HANDLE *phIvasEnc /* i/o: pointer to IVAS encoder handle */ ); +#ifdef MEM_ALLOC_APP_NONBE +/*! r: error code */ +ivas_error IVAS_ENC_Initialize( + IVAS_ENC_HANDLE hIvasEnc /* i/o: IVAS encoder handle */ +); + +/*! r: error code */ +ivas_error IVAS_ENC_Reconfigure( + IVAS_ENC_HANDLE hIvasEnc /* i/o: IVAS encoder handle */ +); +#endif + + /* Encoding functions - should be called with a configured encoder handle */ /*! r: error code */ -- GitLab From d2c58bd4f30b9611db7bbd53296b76df24f27347 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 11 Sep 2023 10:07:04 +0200 Subject: [PATCH 02/20] correct merge --- lib_com/options.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 14a19ae5d2..b890541527 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -167,9 +167,9 @@ /* #################### End BE switches ################################## */ - - -/* ################## End BE DEVELOPMENT switches ######################### */ +/* #################### Start NON-BE switches ############################ */ +/* any switch which is non-be wrt selection floating point code */ +/* all switches in this category should start with "NONBE_" */ #define NONBE_FIX_736_FOA_BR_SWITCH /* FhG/Dlb : Issue 736: FOA bitrate switching decoding crashes in in ivas_spar_to_dirac */ #define NONBE_FIX_746_NONDIEGETIC_MD /* Eri: Issue 746: The non-diegetic panning flag affects the encoder bitstream even if extended metadata is not enabled. Crashes the decoder.*/ -- GitLab From 28e362681145cd3c8ce543b15d7184c630f81463 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 22 Sep 2023 09:50:56 +0200 Subject: [PATCH 03/20] clang=format --- lib_com/ivas_prot.h | 26 +++++++++++++------------- lib_enc/ivas_init_enc.c | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index e40744fd87..9879bbabb2 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5717,31 +5717,31 @@ ivas_error ivas_osba_data_open( #else ivas_error ivas_masa_ism_data_open( #endif - Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ ); #ifndef FIX_782_OSBA_FUNCTION_NAMES ivas_error ivas_sba_ism_separate_object_renderer_open( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); #endif ivas_error ivas_osba_dirac_td_binaural( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - float *output[], /* o : output synthesis signal */ - const int16_t output_frame /* i : output frame length per channel */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + float *output[], /* o : output synthesis signal */ + const int16_t output_frame /* i : output frame length per channel */ ); ivas_error ivas_osba_ism_metadata_dec( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const int32_t ism_total_brate, /* i : ISM total bitrate */ - int16_t *nchan_ism, /* o : number of ISM separated channels */ - int16_t nb_bits_metadata[] /* o : number of ISM metadata bits */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const int32_t ism_total_brate, /* i : ISM total bitrate */ + int16_t *nchan_ism, /* o : number of ISM separated channels */ + int16_t nb_bits_metadata[] /* o : number of ISM metadata bits */ ); ivas_error ivas_osba_render( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - float *output_f[], /* i/o: core-coder transport channels/object output */ - const int16_t output_frame /* i : output frame length per channel */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + float *output_f[], /* i/o: core-coder transport channels/object output */ + const int16_t output_frame /* i : output frame length per channel */ ); #ifdef FIX_782_OSBA_FUNCTION_NAMES @@ -5750,7 +5750,7 @@ void ivas_osba_data_close( ); #else void ivas_masa_ism_data_close( - MASA_ISM_DATA_HANDLE *hMasaIsmData /* i/o: MASA_ISM rendering handle */ + MASA_ISM_DATA_HANDLE *hMasaIsmData /* i/o: MASA_ISM rendering handle */ ); #endif diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 85bb67538a..008b2c4a23 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -1235,7 +1235,7 @@ void ivas_destroy_enc( /*------------------------------------------------------------------------- * ivas_reconfig_enc() * - * Reconfigure IVAS encoder handles and reallocate the memory based on + * Reconfigure IVAS encoder handles and reallocate the memory based on * changes of 'hEncoderConfig' parameters, typically ivas_total_brate *-------------------------------------------------------------------------*/ -- GitLab From 25af05fb0111b5ba41c0e4a68cd736af4d5010ef Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 22 Sep 2023 12:50:25 +0200 Subject: [PATCH 04/20] fix MSAN error in MASA --- lib_com/ivas_prot.h | 6 ++ lib_enc/ivas_enc.c | 4 +- lib_enc/ivas_masa_enc.c | 139 +++++++++++++++++++++++++++++++++++++- lib_enc/ivas_mcmasa_enc.c | 3 + lib_enc/ivas_omasa_enc.c | 4 ++ 5 files changed, 153 insertions(+), 3 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 9879bbabb2..3bc8fbd56c 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5053,6 +5053,12 @@ ivas_error ivas_masa_enc_config( Encoder_Struct* st_ivas /* i/o: IVAS encoder structure */ ); +#ifdef MEM_ALLOC_APP +void ivas_masa_enc_init( + Encoder_Struct* st_ivas /* i/o: IVAS encoder structure */ +); +#endif + void ivas_masa_set_elements( const int32_t ivas_total_brate, /* i : codec total bitrate */ const int16_t mc_mode, /* i : MC format mode */ diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index a13d0885b1..006edd955b 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -253,7 +253,9 @@ ivas_error ivas_enc( { ivas_masa_estimate_energy( st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport ); /* energy-estimation uses TF-resolution: 4x24 */ -#ifndef MEM_ALLOC_APP +#ifdef MEM_ALLOC_APP + ivas_masa_enc_init( st_ivas ); +#else if ( ( error = ivas_masa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { return error; diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 52e03fc409..208ea09459 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -677,14 +677,17 @@ ivas_error ivas_masa_enc_config( uint8_t coherencePresent; uint8_t isActualTwoDir; /* Flag to tell that when there are two directions present in metadata, they both contain meaningful information. */ int32_t ivas_total_brate; +#ifndef MEM_ALLOC_APP uint8_t maxBand; int16_t maxBin, sf; +#endif ivas_error error; int32_t ism_total_brate; +#ifndef MEM_ALLOC_APP int32_t masa_total_brate; +#endif error = IVAS_ERR_OK; - hMasa = st_ivas->hMasa; hQMetaData = st_ivas->hQMetaData; ivas_format = st_ivas->hEncoderConfig->ivas_format; @@ -791,6 +794,7 @@ ivas_error ivas_masa_enc_config( return error; } +#ifndef MEM_ALLOC_APP for ( i = 0; i < hQMetaData->no_directions; i++ ) { hQMetaData->q_direction[i].cfg.nbands = hMasa->config.numCodingBands; @@ -881,10 +885,141 @@ ivas_error ivas_masa_enc_config( st_ivas->hMasa->data.hOmasaData->lp_noise_CPE = ( st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise + st_ivas->hCPE[0]->hCoreCoder[1]->lp_noise ) / CPE_CHANNELS; } } - +#endif return error; } +#ifdef MEM_ALLOC_APP + +/*-----------------------------------------------------------------------* + * ivas_masa_enc_init() + * + * Frame-by-frame configuration of MASA encoder + *-----------------------------------------------------------------------*/ + +void ivas_masa_enc_init( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +) +{ + int16_t i; + MASA_ENCODER_HANDLE hMasa; + IVAS_QMETADATA_HANDLE hQMetaData; + IVAS_FORMAT ivas_format; + int32_t ivas_total_brate; + uint8_t maxBand; + int16_t maxBin, sf; + int32_t ism_total_brate; + int32_t masa_total_brate; + + hMasa = st_ivas->hMasa; + hQMetaData = st_ivas->hQMetaData; + ivas_format = st_ivas->hEncoderConfig->ivas_format; + ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; + + ism_total_brate = 0; + if ( ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) ) + { + for ( i = 0; i < st_ivas->nSCE; i++ ) + { + ism_total_brate += st_ivas->hSCE[i]->element_brate; + } + } + + for ( i = 0; i < hQMetaData->no_directions; i++ ) + { + hQMetaData->q_direction[i].cfg.nbands = hMasa->config.numCodingBands; + hQMetaData->q_direction[i].cfg.nblocks = hMasa->config.joinedSubframes == TRUE ? 1 : 4; + + if ( ivas_format == MC_FORMAT ) + { + hQMetaData->q_direction[i].cfg.mc_ls_setup = st_ivas->hEncoderConfig->mc_input_setup; + } + else + { + /* Just to be sure that this default value is maintained */ + hQMetaData->q_direction[i].cfg.mc_ls_setup = MC_LS_SETUP_INVALID; + } + } + + hQMetaData->all_coherence_zero = !hMasa->config.coherencePresent; + + ivas_set_qmetadata_maxbit_req( hQMetaData, ivas_format ); + + /* Find maximum band usable */ + maxBin = (int16_t) ( st_ivas->hEncoderConfig->input_Fs * INV_CLDFB_BANDWIDTH ); + maxBand = 0; + while ( maxBand <= MASA_FREQUENCY_BANDS && MASA_band_grouping_24[maxBand] <= maxBin ) + { + maxBand++; + } + maxBand--; + + st_ivas->hQMetaData->q_direction->cfg.inactiveBands = 0; + masa_total_brate = ivas_total_brate; + if ( ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + masa_total_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, ivas_total_brate, st_ivas->hEncoderConfig->nchan_ism ); + } + if ( masa_total_brate >= IVAS_384k && ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) ) + { + int16_t continueLoop; + continueLoop = 1; + while ( maxBand > 5 && continueLoop ) + { + for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + if ( hMasa->data.energy[sf][maxBand - 1] > 100000 ) + { + continueLoop = 0; + break; + } + } + if ( continueLoop ) + { + maxBand--; + } + } + + if ( maxBand < MASA_MAXIMUM_CODING_SUBBANDS ) + { + st_ivas->hQMetaData->q_direction->cfg.inactiveBands = MASA_MAXIMUM_CODING_SUBBANDS - maxBand; + } + else + { + st_ivas->hQMetaData->q_direction->cfg.inactiveBands = 0; + } + } + + masa_sample_rate_band_correction( &( hMasa->config ), hMasa->data.band_mapping, hQMetaData, maxBand, masa_total_brate >= IVAS_384k, NULL ); + + if ( hMasa->config.numTwoDirBands >= hMasa->config.numCodingBands ) + { + hMasa->config.numTwoDirBands = hMasa->config.numCodingBands; + set_c( (int8_t *) hMasa->data.twoDirBands, 1, hMasa->config.numCodingBands ); + } + + /* Transmit stereo signals using a mono downmix at lowest bitrates */ + if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) && st_ivas->nCPE == 1 && st_ivas->hCPE[0]->hStereoDft != NULL && st_ivas->hCPE[0]->hStereoDft->hConfig != NULL ) + { + st_ivas->hCPE[0]->hStereoDft->hConfig->force_mono_transmission = ( ivas_total_brate - ism_total_brate < MASA_STEREO_MIN_BITRATE ) ? 1 : 0; + } + + if ( ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) + { + if ( st_ivas->hCPE[0]->element_mode == IVAS_CPE_DFT || st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt < OMASA_STEREO_SW_CNT_MAX ) + { + st_ivas->hMasa->data.hOmasaData->lp_noise_CPE = st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise; + } + else + { + st_ivas->hMasa->data.hOmasaData->lp_noise_CPE = ( st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise + st_ivas->hCPE[0]->hCoreCoder[1]->lp_noise ) / CPE_CHANNELS; + } + } + + return; +} + +#endif /*-----------------------------------------------------------------------* * ivas_masa_surrcoh_signicant() diff --git a/lib_enc/ivas_mcmasa_enc.c b/lib_enc/ivas_mcmasa_enc.c index 3df783ad05..1a598e3328 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -133,6 +133,9 @@ ivas_error ivas_mcmasa_enc_open( return error; } +#ifdef MEM_ALLOC_APP + ivas_masa_enc_init( st_ivas ); +#endif /* Determine the number of bands */ hMcMasa->nbands = st_ivas->hMasa->config.numCodingBands; diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 6bd930bd91..3f5907863f 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -301,6 +301,10 @@ ivas_error ivas_omasa_enc_config( return error; } +#ifdef MEM_ALLOC_APP + ivas_masa_enc_init( st_ivas ); +#endif + if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) { /* Configure oMASA analysis based on MASA config */ -- GitLab From e743feb2f8581671213fa3dc07bf3341dc16a125 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 22 Sep 2023 13:31:17 +0200 Subject: [PATCH 05/20] fix MSAN error in OMASA --- lib_enc/ivas_enc.c | 4 +++- lib_enc/ivas_masa_enc.c | 1 + lib_enc/ivas_omasa_enc.c | 4 ---- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 006edd955b..c915e36676 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -321,7 +321,9 @@ ivas_error ivas_enc( /* Estimate TF-tile energy for the input MASA stream */ ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport ); -#ifndef MEM_ALLOC_APP +#ifdef MEM_ALLOC_APP + ivas_masa_enc_init( st_ivas ); +#else if ( ( error = ivas_omasa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { return error; diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 208ea09459..01fdaebb54 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -960,6 +960,7 @@ void ivas_masa_enc_init( { masa_total_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, ivas_total_brate, st_ivas->hEncoderConfig->nchan_ism ); } + if ( masa_total_brate >= IVAS_384k && ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) ) { int16_t continueLoop; diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 3f5907863f..6bd930bd91 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -301,10 +301,6 @@ ivas_error ivas_omasa_enc_config( return error; } -#ifdef MEM_ALLOC_APP - ivas_masa_enc_init( st_ivas ); -#endif - if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) { /* Configure oMASA analysis based on MASA config */ -- GitLab From fe61d8594951fbeb328da56b37b8f6f998f98453 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 22 Sep 2023 14:39:05 +0200 Subject: [PATCH 06/20] rearrangements arount ivas_masa_enc_config() --- lib_com/ivas_prot.h | 4 ++ lib_enc/ivas_enc.c | 2 - lib_enc/ivas_init_enc.c | 6 +-- lib_enc/ivas_masa_enc.c | 83 +++++++++++++++++++++++++++++++++++---- lib_enc/ivas_mcmasa_enc.c | 4 ++ lib_enc/ivas_omasa_enc.c | 4 ++ 6 files changed, 89 insertions(+), 14 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 3bc8fbd56c..1053c777f1 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5049,7 +5049,11 @@ void ivas_masa_estimate_energy( const int16_t nchan_transport /* i : number of MASA input/transport channels */ ); +#ifdef MEM_ALLOC_APP +ivas_error ivas_masa_enc_config_memory( +#else ivas_error ivas_masa_enc_config( +#endif Encoder_Struct* st_ivas /* i/o: IVAS encoder structure */ ); diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index c915e36676..e23667c666 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -239,12 +239,10 @@ ivas_error ivas_enc( push_indice( st->hBstr, IND_SMODE, hEncoderConfig->sba_order, SBA_ORDER_BITS ); #endif } -#ifndef MEM_ALLOC_APP else { ivas_masa_enc_reconfigure( st_ivas ); } -#endif /* SBA/MASA metadata encoding and SBA/MASA metadata bitstream writing */ hMetaData = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData : st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 008b2c4a23..9cc534da3b 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -1265,10 +1265,8 @@ ivas_error ivas_reconfig_enc( } else if ( ivas_format == MASA_FORMAT ) { - ivas_masa_enc_reconfigure( st_ivas ); - - /* reconfigure the SBA format encoder */ - error = ivas_masa_enc_config( st_ivas ); + /* reconfigure the MASA format encoder */ + error = ivas_masa_enc_config_memory( st_ivas ); } else if ( ivas_format == SBA_ISM_FORMAT ) { diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 01fdaebb54..c229e4ad70 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -659,17 +659,31 @@ void ivas_masa_estimate_energy( } +#ifdef MEM_ALLOC_APP +/*-----------------------------------------------------------------------* + * ivas_masa_enc_config_memory() + * + * Frame-by-frame configuration of MASA encoder memory + *-----------------------------------------------------------------------*/ +#else /*-----------------------------------------------------------------------* * ivas_masa_enc_config() * * Frame-by-frame configuration of MASA encoder *-----------------------------------------------------------------------*/ +#endif +#ifdef MEM_ALLOC_APP +ivas_error ivas_masa_enc_config_memory( +#else ivas_error ivas_masa_enc_config( +#endif Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) { +#ifndef MEM_ALLOC_APP int16_t i; +#endif MASA_ENCODER_HANDLE hMasa; IVAS_QMETADATA_HANDLE hQMetaData; IVAS_FORMAT ivas_format; @@ -682,8 +696,8 @@ ivas_error ivas_masa_enc_config( int16_t maxBin, sf; #endif ivas_error error; - int32_t ism_total_brate; #ifndef MEM_ALLOC_APP + int32_t ism_total_brate; int32_t masa_total_brate; #endif @@ -693,6 +707,7 @@ ivas_error ivas_masa_enc_config( ivas_format = st_ivas->hEncoderConfig->ivas_format; ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; +#ifndef MEM_ALLOC_APP ism_total_brate = 0; if ( ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) ) { @@ -703,7 +718,7 @@ ivas_error ivas_masa_enc_config( } ivas_masa_set_elements( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, hQMetaData, &st_ivas->hEncoderConfig->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE, ivas_format, st_ivas->ism_mode, ism_total_brate ); - +#endif hQMetaData->is_masa_ivas_format = 1; if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) @@ -740,6 +755,7 @@ ivas_error ivas_masa_enc_config( ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, ivas_total_brate, st_ivas->nchan_transport, ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) ); } +#ifndef MEM_ALLOC_APP /* Setup importance weights for two-direction band selection. */ if ( hMasa->config.numberOfDirections == 2 ) { @@ -787,6 +803,7 @@ ivas_error ivas_masa_enc_config( { set_c( (int8_t *) hMasa->data.twoDirBands, 0, hMasa->config.numCodingBands ); } +#endif /* Set qmeta to correct values */ if ( ( error = ivas_qmetadata_allocate_memory( hQMetaData, hMasa->config.numCodingBands, hMasa->config.numberOfDirections == 2 && hMasa->config.numTwoDirBands != 0 ? 2 : 1, hMasa->config.useCoherence ) ) != IVAS_ERR_OK ) @@ -925,6 +942,56 @@ void ivas_masa_enc_init( } } + ivas_masa_set_elements( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, hQMetaData, &st_ivas->hEncoderConfig->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE, ivas_format, st_ivas->ism_mode, ism_total_brate ); + + /* Setup importance weights for two-direction band selection. */ + if ( hMasa->config.numberOfDirections == 2 ) + { + set_f( hMasa->data.importanceWeight, 1.0f, hMasa->config.numCodingBands ); + + if ( hMasa->config.numCodingBands == 5 ) + { + hMasa->data.importanceWeight[4] = 0.7f; + } + else if ( hMasa->config.numCodingBands == 8 ) + { + hMasa->data.importanceWeight[7] = 0.7f; + } + else if ( hMasa->config.numCodingBands == 10 ) + { + hMasa->data.importanceWeight[8] = 0.7f; + hMasa->data.importanceWeight[9] = 0.1f; + } + else if ( hMasa->config.numCodingBands == 12 ) + { + hMasa->data.importanceWeight[10] = 0.7f; + hMasa->data.importanceWeight[11] = 0.1f; + } + else if ( hMasa->config.numCodingBands == 18 ) + { + hMasa->data.importanceWeight[14] = 0.8f; + hMasa->data.importanceWeight[15] = 0.5f; + hMasa->data.importanceWeight[16] = 0.2f; + hMasa->data.importanceWeight[17] = 0.0f; + } + else if ( hMasa->config.numCodingBands == 24 ) + { + hMasa->data.importanceWeight[20] = 0.8f; + hMasa->data.importanceWeight[21] = 0.5f; + hMasa->data.importanceWeight[22] = 0.2f; + hMasa->data.importanceWeight[23] = 0.0f; + } + + if ( hMasa->config.numTwoDirBands == hMasa->config.numCodingBands ) + { + set_c( (int8_t *) hMasa->data.twoDirBands, 1, hMasa->config.numCodingBands ); + } + } + else + { + set_c( (int8_t *) hMasa->data.twoDirBands, 0, hMasa->config.numCodingBands ); + } + for ( i = 0; i < hQMetaData->no_directions; i++ ) { hQMetaData->q_direction[i].cfg.nbands = hMasa->config.numCodingBands; @@ -954,7 +1021,7 @@ void ivas_masa_enc_init( } maxBand--; - st_ivas->hQMetaData->q_direction->cfg.inactiveBands = 0; + hQMetaData->q_direction->cfg.inactiveBands = 0; masa_total_brate = ivas_total_brate; if ( ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { @@ -983,11 +1050,11 @@ void ivas_masa_enc_init( if ( maxBand < MASA_MAXIMUM_CODING_SUBBANDS ) { - st_ivas->hQMetaData->q_direction->cfg.inactiveBands = MASA_MAXIMUM_CODING_SUBBANDS - maxBand; + hQMetaData->q_direction->cfg.inactiveBands = MASA_MAXIMUM_CODING_SUBBANDS - maxBand; } else { - st_ivas->hQMetaData->q_direction->cfg.inactiveBands = 0; + hQMetaData->q_direction->cfg.inactiveBands = 0; } } @@ -1007,13 +1074,13 @@ void ivas_masa_enc_init( if ( ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) { - if ( st_ivas->hCPE[0]->element_mode == IVAS_CPE_DFT || st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt < OMASA_STEREO_SW_CNT_MAX ) + if ( st_ivas->hCPE[0]->element_mode == IVAS_CPE_DFT || hMasa->data.hOmasaData->omasa_stereo_sw_cnt < OMASA_STEREO_SW_CNT_MAX ) { - st_ivas->hMasa->data.hOmasaData->lp_noise_CPE = st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise; + hMasa->data.hOmasaData->lp_noise_CPE = st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise; } else { - st_ivas->hMasa->data.hOmasaData->lp_noise_CPE = ( st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise + st_ivas->hCPE[0]->hCoreCoder[1]->lp_noise ) / CPE_CHANNELS; + hMasa->data.hOmasaData->lp_noise_CPE = ( st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise + st_ivas->hCPE[0]->hCoreCoder[1]->lp_noise ) / CPE_CHANNELS; } } diff --git a/lib_enc/ivas_mcmasa_enc.c b/lib_enc/ivas_mcmasa_enc.c index 1a598e3328..0b9eb82d44 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -128,7 +128,11 @@ ivas_error ivas_mcmasa_enc_open( } /* With McMASA, we config MASA encoder only in init as we know the input and there are no frame-by-frame changes currently. */ +#ifdef MEM_ALLOC_APP + if ( ( error = ivas_masa_enc_config_memory( st_ivas ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_masa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 6bd930bd91..b207e5a9a0 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -296,7 +296,11 @@ ivas_error ivas_omasa_enc_config( } /* Configure MASA encoder based on frame parameters */ +#ifdef MEM_ALLOC_APP + if ( ( error = ivas_masa_enc_config_memory( st_ivas ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_masa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) +#endif { return error; } -- GitLab From 13f10ef3adb4eb36698a43dab59e715f6e2bd2b2 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 25 Mar 2024 13:54:45 +0100 Subject: [PATCH 07/20] MEM_ALLOC_APP_DEC, decoder part except of JBM --- apps/decoder.c | 38 +++++++++++++++ lib_com/options.h | 1 + lib_dec/lib_dec.c | 119 +++++++++++++++++++++++++++++++++++++++++++--- lib_dec/lib_dec.h | 12 +++++ 4 files changed, 163 insertions(+), 7 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index d993eb4144..88ec3c8bb2 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -807,6 +807,19 @@ int main( } } +#ifdef MEM_ALLOC_APP +#if 0 + /*------------------------------------------------------------------------------------------* + * Initialize (allocate memory for static variables) the decoder + *------------------------------------------------------------------------------------------*/ + + if ( ( error = IVAS_DEC_Setup( hIvasDec, NULL ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_Setup failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } +#endif +#endif /*------------------------------------------------------------------------------------------* * Allocate output data buffer *------------------------------------------------------------------------------------------*/ @@ -2344,6 +2357,15 @@ static ivas_error decodeG192( } } +#ifdef MEM_ALLOC_APP + /* Reconfigure IVAS decoder handles and reallocate the memory if IVAS total bitrate has changed */ + if ( ( error = IVAS_DEC_Setup( hIvasDec, NULL ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_Setup failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } +#endif + #ifdef SPLIT_REND_WITH_HEAD_ROT if ( arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) { @@ -3217,6 +3239,22 @@ static ivas_error decodeVoIP( break; } +#ifdef MEM_ALLOC_APP_DEC +#if 0 + // VE: TBC!!! + //if () + { + hIvasDec->hasBeenFedFrame = true; + } + + /* Reconfigure IVAS decoder handles and reallocate the memory if IVAS total bitrate has changed */ + if ( ( error = IVAS_DEC_Setup( hIvasDec, NULL ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_Setup failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } +#endif +#endif /* decode and get samples */ diff --git a/lib_com/options.h b/lib_com/options.h index da97075d2e..0135ccd220 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -163,6 +163,7 @@ #define FIX_1035_HT_OSBA /* Dlb: issue 1035: Issue with headtracking in OSBA*/ #define MEM_ALLOC_APP /* VA: call memory allocate/reallocation from the application */ +#define MEM_ALLOC_APP_DEC /* VA: call memory allocate/reallocation from the application, decoder part */ /* #################### End BE switches ################################## */ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index aeb8f84303..86e89614d1 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -108,11 +108,13 @@ static ivas_error evs_dec_main( Decoder_Struct *st_ivas, const int16_t nOutSampl static ivas_error input_format_API_to_internal( IVAS_DEC_INPUT_FORMAT input_format, int16_t *bitstream_format_internal, int16_t *sdp_hf_only, const bool is_voip_enabled ); static void init_decoder_config( DECODER_CONFIG_HANDLE hDecoderConfig ); static ivas_error IVAS_DEC_VoIP_reconfigure( IVAS_DEC_HANDLE hIvasDec, const uint16_t nTransportChannels, const uint16_t l_ts ); +#ifndef MEM_ALLOC_APP_DEC #ifdef SPLIT_REND_WITH_HEAD_ROT static ivas_error IVAS_DEC_Setup( IVAS_DEC_HANDLE hIvasDec, uint16_t *nTcBufferGranularity, uint8_t *nTransportChannels, uint8_t *nOutChannels, uint16_t *nSamplesRendered, const IVAS_DEC_PCM_TYPE pcmType, void *data ); #else static ivas_error IVAS_DEC_Setup( IVAS_DEC_HANDLE hIvasDec, uint16_t *nTcBufferGranularity, uint8_t *nTransportChannels, uint8_t *nOutChannels, uint16_t *nSamplesRendered, int16_t *data ); #endif +#endif static ivas_error IVAS_DEC_GetTcSamples( IVAS_DEC_HANDLE hIvasDec, float *pcmBuf, int16_t *nOutSamples ); static ivas_error IVAS_DEC_RendererFeedTcSamples( IVAS_DEC_HANDLE hIvasDec, const int16_t nSamplesForRendering, int16_t *nSamplesResidual, float *pcmBuf ); #ifdef SPLIT_REND_WITH_HEAD_ROT @@ -850,6 +852,9 @@ ivas_error IVAS_DEC_GetSamples( ) { ivas_error error; +#ifdef MEM_ALLOC_APP_DEC + Decoder_Struct *st_ivas; +#endif int16_t nOutSamplesElse, nSamplesToRender; uint16_t nSamplesRendered, nSamplesRendered_loop, l_ts, nTimeScalerOutSamples; uint8_t nTransportChannels, nOutChannels; @@ -865,6 +870,10 @@ ivas_error IVAS_DEC_GetSamples( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } +#ifdef MEM_ALLOC_APP_DEC + st_ivas = hIvasDec->st_ivas; + +#endif if ( hIvasDec->updateOrientation ) { /*----------------------------------------------------------------* @@ -918,6 +927,40 @@ ivas_error IVAS_DEC_GetSamples( /* check if we need to run the setup function */ if ( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) { +#ifdef MEM_ALLOC_APP_DEC + if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) // ToDo: TBD for JBM + { +#ifdef SPLIT_REND_WITH_HEAD_ROT + if ( ( error = IVAS_DEC_Setup( hIvasDec, pcmType, pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ) ) ) != IVAS_ERR_OK ) +#else + if ( ( error = IVAS_DEC_Setup( hIvasDec, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ) +#endif + { + return error; + } + } + + if ( hIvasDec->mode == IVAS_DEC_MODE_EVS ) + { + if ( st_ivas->renderer_type == RENDERER_NON_DIEGETIC_DOWNMIX ) + { + nTransportChannels = MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN; + nOutChannels = MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN; + } + else + { + nTransportChannels = 1; + nOutChannels = 1; + } + } + else + { + l_ts = st_ivas->hTcBuffer->n_samples_granularity; + nTransportChannels = (uint8_t) st_ivas->hTcBuffer->nchan_transport_jbm; + nOutChannels = (uint8_t) st_ivas->hDecoderConfig->nchan_out; + nSamplesRendered_loop = hIvasDec->nSamplesRendered; + } +#else /* setup */ #ifdef SPLIT_REND_WITH_HEAD_ROT @@ -925,10 +968,10 @@ ivas_error IVAS_DEC_GetSamples( #else if ( ( error = IVAS_DEC_Setup( hIvasDec, &l_ts, &nTransportChannels, &nOutChannels, &nSamplesRendered_loop, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ) #endif - { return error; } +#endif #ifdef SPLIT_REND_WITH_HEAD_ROT /* :TODO: change nSamplesAsked also if we are in 5ms 0dof split rendering... */ #endif @@ -1196,13 +1239,75 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( * * *---------------------------------------------------------------------*/ +#ifdef MEM_ALLOC_APP_DEC + +ivas_error IVAS_DEC_Setup( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ +#ifdef SPLIT_REND_WITH_HEAD_ROT + const IVAS_DEC_PCM_TYPE pcmType, /* i : type for the decoded PCM resolution */ + void *data /* o : output synthesis signal */ +#else + int16_t *data /* o : output synthesis signal */ +#endif +) +{ + ivas_error error; + uint16_t nSamplesRendered = 0; + + if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + if ( !hIvasDec->hasBeenFedFrame && hIvasDec->nSamplesAvailableNext == 0 ) + { + /* no frame was fed, do nothing */ + return IVAS_ERR_OK; + } + + if ( hIvasDec->mode == IVAS_DEC_MODE_EVS ) + { + /* EVS decoding, do nothing */ + return IVAS_ERR_OK; + } + else + { + Decoder_Struct *st_ivas; + + st_ivas = hIvasDec->st_ivas; + + /*----------------------------------------------------------------* + * IVAS decoder setup + * - read IVAS format signaling + * - read IVAS format specific signaling + * - initialize decoder in the first frame based on IVAS format and number of transport channels + * - reconfigure the decoder when the number of TC or IVAS total bitrate change + *----------------------------------------------------------------*/ + + if ( st_ivas->bfi == 0 ) + { +#ifdef SPLIT_REND_WITH_HEAD_ROT + if ( ( error = ivas_dec_setup( st_ivas, &nSamplesRendered, pcm_type_API_to_internal( pcmType ), data ) ) != IVAS_ERR_OK ) +#else + if ( ( error = ivas_dec_setup( st_ivas, &nSamplesRendered, data ) ) != IVAS_ERR_OK ) +#endif + { + return error; + } + } + } + + return IVAS_ERR_OK; +} + +#else /* MEM_ALLOC_APP_DEC */ static ivas_error IVAS_DEC_Setup( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - uint16_t *nTcBufferGranularity, /* o : granularity of the TC Buffer */ - uint8_t *nTransportChannels, /* o : number of decoded transport PCM channels */ - uint8_t *nOutChannels, /* o : number of decoded out channels (PCM or CLDFB) */ - uint16_t *nSamplesRendered, /* o : number of samples flushed from the last frame */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + uint16_t *nTcBufferGranularity, /* o : granularity of the TC Buffer */ + uint8_t *nTransportChannels, /* o : number of decoded transport PCM channels */ + uint8_t *nOutChannels, /* o : number of decoded out channels (PCM or CLDFB) */ + uint16_t *nSamplesRendered, /* o : number of samples flushed from the last frame */ #ifdef SPLIT_REND_WITH_HEAD_ROT const IVAS_DEC_PCM_TYPE pcmType, /* i : type for the decoded PCM resolution */ void *data /* o : output synthesis signal */ @@ -1261,7 +1366,7 @@ static ivas_error IVAS_DEC_Setup( return IVAS_ERR_OK; } - +#endif /* MEM_ALLOC_APP_DEC */ /*---------------------------------------------------------------------* * IVAS_DEC_GetTcSamples( ) diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 2dccb45525..f5b884ad17 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -143,6 +143,18 @@ void IVAS_DEC_Close( IVAS_DEC_HANDLE *phIvasDec /* i/o: pointer to IVAS decoder handle */ ); +#ifdef MEM_ALLOC_APP_DEC +/*! r: error code */ +ivas_error IVAS_DEC_Setup( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ +#ifdef SPLIT_REND_WITH_HEAD_ROT + const IVAS_DEC_PCM_TYPE pcmType, /* i : type for the decoded PCM resolution */ + void *data /* o : output synthesis signal */ +#else + int16_t *data /* o : output synthesis signal */ +#endif +); +#endif /* Decoding functions - should be called with a configured decoder handle */ -- GitLab From 5d50bf824e0ceef03f5b3b016751f4e2a354bde3 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 25 Mar 2024 14:48:36 +0100 Subject: [PATCH 08/20] fix SR build --- apps/decoder.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/decoder.c b/apps/decoder.c index 88ec3c8bb2..2fcfc718be 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -2359,7 +2359,11 @@ static ivas_error decodeG192( #ifdef MEM_ALLOC_APP /* Reconfigure IVAS decoder handles and reallocate the memory if IVAS total bitrate has changed */ +#ifdef SPLIT_REND_WITH_HEAD_ROT + if ( ( error = IVAS_DEC_Setup( hIvasDec, IVAS_DEC_PCM_INT16, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ) +#else if ( ( error = IVAS_DEC_Setup( hIvasDec, NULL ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nIVAS_DEC_Setup failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; -- GitLab From 8bf6e8c9c37e79f83b57c3424c894e75b7e82355 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 26 Mar 2024 10:28:47 +0100 Subject: [PATCH 09/20] fix JBM --- apps/decoder.c | 6 +++--- lib_dec/lib_dec.c | 21 +++++++++++++-------- lib_dec/lib_dec.h | 1 + 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 2fcfc718be..4146ad308a 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -807,7 +807,7 @@ int main( } } -#ifdef MEM_ALLOC_APP +#ifdef MEM_ALLOC_APP_DEC #if 0 /*------------------------------------------------------------------------------------------* * Initialize (allocate memory for static variables) the decoder @@ -2357,12 +2357,12 @@ static ivas_error decodeG192( } } -#ifdef MEM_ALLOC_APP +#ifdef MEM_ALLOC_APP_DEC /* Reconfigure IVAS decoder handles and reallocate the memory if IVAS total bitrate has changed */ #ifdef SPLIT_REND_WITH_HEAD_ROT if ( ( error = IVAS_DEC_Setup( hIvasDec, IVAS_DEC_PCM_INT16, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ) #else - if ( ( error = IVAS_DEC_Setup( hIvasDec, NULL ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_Setup( hIvasDec, NULL, NULL ) ) != IVAS_ERR_OK ) #endif { fprintf( stderr, "\nIVAS_DEC_Setup failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 86e89614d1..888f09611a 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -931,9 +931,9 @@ ivas_error IVAS_DEC_GetSamples( if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) // ToDo: TBD for JBM { #ifdef SPLIT_REND_WITH_HEAD_ROT - if ( ( error = IVAS_DEC_Setup( hIvasDec, pcmType, pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ) ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_Setup( hIvasDec, &nSamplesRendered, pcmType, pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ) ) ) != IVAS_ERR_OK ) #else - if ( ( error = IVAS_DEC_Setup( hIvasDec, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_Setup( hIvasDec, &nSamplesRendered, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ) #endif { return error; @@ -1242,7 +1242,8 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( #ifdef MEM_ALLOC_APP_DEC ivas_error IVAS_DEC_Setup( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + uint16_t *nSamplesRendered, /* o : number of samples flushed from the last frame */ #ifdef SPLIT_REND_WITH_HEAD_ROT const IVAS_DEC_PCM_TYPE pcmType, /* i : type for the decoded PCM resolution */ void *data /* o : output synthesis signal */ @@ -1252,7 +1253,7 @@ ivas_error IVAS_DEC_Setup( ) { ivas_error error; - uint16_t nSamplesRendered = 0; + uint16_t nSamplesRendered_loc = 0; if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { @@ -1270,7 +1271,7 @@ ivas_error IVAS_DEC_Setup( /* EVS decoding, do nothing */ return IVAS_ERR_OK; } - else + else if ( data != NULL ) // ToDo: TBD for JBM { Decoder_Struct *st_ivas; @@ -1287,16 +1288,20 @@ ivas_error IVAS_DEC_Setup( if ( st_ivas->bfi == 0 ) { #ifdef SPLIT_REND_WITH_HEAD_ROT - if ( ( error = ivas_dec_setup( st_ivas, &nSamplesRendered, pcm_type_API_to_internal( pcmType ), data ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_dec_setup( st_ivas, &nSamplesRendered_loc, pcm_type_API_to_internal( pcmType ), data ) ) != IVAS_ERR_OK ) #else - if ( ( error = ivas_dec_setup( st_ivas, &nSamplesRendered, data ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_dec_setup( st_ivas, &nSamplesRendered_loc, data ) ) != IVAS_ERR_OK ) #endif { return error; } } - } + if ( nSamplesRendered != NULL ) + { + *nSamplesRendered = nSamplesRendered_loc; + } + } return IVAS_ERR_OK; } diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index f5b884ad17..54e5fa74f0 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -147,6 +147,7 @@ void IVAS_DEC_Close( /*! r: error code */ ivas_error IVAS_DEC_Setup( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + uint16_t *nSamplesRendered, /* o : number of samples flushed from the last frame */ #ifdef SPLIT_REND_WITH_HEAD_ROT const IVAS_DEC_PCM_TYPE pcmType, /* i : type for the decoded PCM resolution */ void *data /* o : output synthesis signal */ -- GitLab From cdc7585918a1ab75abfbf0fb34c66b4af9308213 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 26 Mar 2024 10:31:22 +0100 Subject: [PATCH 10/20] fix SR build --- apps/decoder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/decoder.c b/apps/decoder.c index 4146ad308a..b4f128aca1 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -2360,7 +2360,7 @@ static ivas_error decodeG192( #ifdef MEM_ALLOC_APP_DEC /* Reconfigure IVAS decoder handles and reallocate the memory if IVAS total bitrate has changed */ #ifdef SPLIT_REND_WITH_HEAD_ROT - if ( ( error = IVAS_DEC_Setup( hIvasDec, IVAS_DEC_PCM_INT16, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_Setup( hIvasDec, NULL, IVAS_DEC_PCM_INT16, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ) #else if ( ( error = IVAS_DEC_Setup( hIvasDec, NULL, NULL ) ) != IVAS_ERR_OK ) #endif -- GitLab From bf3cd517ea039e64f990772ec60c6618d1b36051 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 26 Mar 2024 12:20:49 +0100 Subject: [PATCH 11/20] updates for MEM_ALLOC_APP_DEC_JBM (deactivated) --- apps/decoder.c | 34 ++++++++++++++-------------------- lib_com/options.h | 1 + lib_dec/lib_dec.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 20 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index b4f128aca1..4b0827ac6e 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -807,19 +807,7 @@ int main( } } -#ifdef MEM_ALLOC_APP_DEC -#if 0 - /*------------------------------------------------------------------------------------------* - * Initialize (allocate memory for static variables) the decoder - *------------------------------------------------------------------------------------------*/ - if ( ( error = IVAS_DEC_Setup( hIvasDec, NULL ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nIVAS_DEC_Setup failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } -#endif -#endif /*------------------------------------------------------------------------------------------* * Allocate output data buffer *------------------------------------------------------------------------------------------*/ @@ -2081,7 +2069,12 @@ static ivas_error decodeG192( IVAS_DEC_BS_FORMAT bsFormat = IVAS_DEC_BS_UNKOWN; uint16_t nSamplesAvailableNext; bool needNewFrame; +#ifdef MEM_ALLOC_APP_DEC + uint16_t nSamplesRendered; + int16_t nSamplesRendered_loop, nSamplesToRender; +#else int16_t nSamplesRendered, nSamplesRendered_loop, nSamplesToRender; +#endif #ifdef DEBUGGING #ifdef VARIABLE_SPEED_DECODING TsmScaleFileReader *tsmScaleFileReader = NULL; @@ -2362,7 +2355,7 @@ static ivas_error decodeG192( #ifdef SPLIT_REND_WITH_HEAD_ROT if ( ( error = IVAS_DEC_Setup( hIvasDec, NULL, IVAS_DEC_PCM_INT16, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ) #else - if ( ( error = IVAS_DEC_Setup( hIvasDec, NULL, NULL ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_Setup( hIvasDec, NULL, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ) #endif { fprintf( stderr, "\nIVAS_DEC_Setup failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); @@ -3245,19 +3238,20 @@ static ivas_error decodeVoIP( #ifdef MEM_ALLOC_APP_DEC #if 0 - // VE: TBC!!! - //if () - { - hIvasDec->hasBeenFedFrame = true; - } - +#ifndef MEM_ALLOC_APP_DEC_JBM + uint16_t nSamplesRendered = 0; /* Reconfigure IVAS decoder handles and reallocate the memory if IVAS total bitrate has changed */ - if ( ( error = IVAS_DEC_Setup( hIvasDec, NULL ) ) != IVAS_ERR_OK ) +#ifdef SPLIT_REND_WITH_HEAD_ROT + if ( ( error = IVAS_DEC_Setup( hIvasDec, &nSamplesRendered, IVAS_DEC_PCM_INT16, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ) +#else + if ( ( error = IVAS_DEC_Setup( hIvasDec, NULL, NULL ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nIVAS_DEC_Setup failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } #endif +#endif #endif /* decode and get samples */ diff --git a/lib_com/options.h b/lib_com/options.h index 732b116934..c89feb023c 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -165,6 +165,7 @@ #define MEM_ALLOC_APP /* VA: call memory allocate/reallocation from the application */ #define MEM_ALLOC_APP_DEC /* VA: call memory allocate/reallocation from the application, decoder part */ +//#define MEM_ALLOC_APP_DEC_JBM /* #################### End BE switches ################################## */ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 888f09611a..6a556f7fee 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -88,6 +88,9 @@ struct IVAS_DEC bool updateOrientation; uint16_t nSamplesAvailableNext; int16_t nSamplesRendered; +#ifdef MEM_ALLOC_APP_DEC + int16_t nSamplesRendered_flush; +#endif int16_t nTransportChannelsOld; int16_t amrwb_rfc4867_flag; /* MIME from rfc4867 is used */ int16_t sdp_hf_only; /* RTP payload format parameter: only Header-Full format without zero padding for size collision avoidance */ @@ -171,6 +174,9 @@ ivas_error IVAS_DEC_Open( hIvasDec->nTransportChannelsOld = 0; hIvasDec->nSamplesAvailableNext = 0; hIvasDec->nSamplesRendered = 0; +#ifdef MEM_ALLOC_APP_DEC + hIvasDec->nSamplesRendered_flush = 0; +#endif hIvasDec->nSamplesFrame = 0; hIvasDec->hasBeenFedFrame = false; hIvasDec->hasBeenFedFirstGoodFrame = false; @@ -478,6 +484,9 @@ ivas_error IVAS_DEC_Configure( hIvasDec->nSamplesFrame = (uint16_t) ( hDecoderConfig->output_Fs / FRAMES_PER_SEC ); hIvasDec->nSamplesAvailableNext = 0; hIvasDec->nSamplesRendered = 0; +#ifdef MEM_ALLOC_APP_DEC + hIvasDec->nSamplesRendered_flush = 0; +#endif hIvasDec->tsm_scale = 100; hIvasDec->tsm_max_scaling = 0; hIvasDec->tsm_quality = 1.0f; @@ -825,6 +834,9 @@ ivas_error IVAS_DEC_FeedFrame_Serial( hIvasDec->needNewFrame = false; hIvasDec->hasBeenFedFrame = true; hIvasDec->nSamplesRendered = 0; +#ifdef MEM_ALLOC_APP_DEC + hIvasDec->nSamplesRendered_flush = 0; +#endif hIvasDec->nSamplesAvailableNext = hIvasDec->nSamplesFrame; return IVAS_ERR_OK; @@ -928,6 +940,7 @@ ivas_error IVAS_DEC_GetSamples( if ( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) { #ifdef MEM_ALLOC_APP_DEC +#ifndef MEM_ALLOC_APP_DEC_JBM if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) // ToDo: TBD for JBM { #ifdef SPLIT_REND_WITH_HEAD_ROT @@ -939,6 +952,7 @@ ivas_error IVAS_DEC_GetSamples( return error; } } +#endif if ( hIvasDec->mode == IVAS_DEC_MODE_EVS ) { @@ -959,6 +973,7 @@ ivas_error IVAS_DEC_GetSamples( nTransportChannels = (uint8_t) st_ivas->hTcBuffer->nchan_transport_jbm; nOutChannels = (uint8_t) st_ivas->hDecoderConfig->nchan_out; nSamplesRendered_loop = hIvasDec->nSamplesRendered; + nSamplesRendered = hIvasDec->nSamplesRendered_flush; } #else /* setup */ @@ -1301,7 +1316,9 @@ ivas_error IVAS_DEC_Setup( { *nSamplesRendered = nSamplesRendered_loc; } + hIvasDec->nSamplesRendered_flush = nSamplesRendered_loc; } + return IVAS_ERR_OK; } @@ -2695,6 +2712,20 @@ ivas_error IVAS_DEC_VoIP_GetSamples( } } +#ifdef MEM_ALLOC_APP_DEC_JBM + uint16_t nSamplesRendered2 = 0; + /* Reconfigure IVAS decoder handles and reallocate the memory if IVAS total bitrate has changed */ +#ifdef SPLIT_REND_WITH_HEAD_ROT + if ( ( error = IVAS_DEC_Setup( hIvasDec, &nSamplesRendered, IVAS_DEC_PCM_INT16, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ) +#else + if ( ( error = IVAS_DEC_Setup( hIvasDec, &nSamplesRendered2, pcmBuf + nSamplesRendered2 * nOutChannels ) ) != IVAS_ERR_OK ) +#endif + { + fprintf( stderr, "\nIVAS_DEC_Setup failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + return error; + } +#endif + #ifdef SUPPORT_JBM_TRACEFILE /* jbmWriterFn and jbmWriter may be NULL if tracefile writing was not requested on CLI */ if ( jbmWriterFn != NULL && jbmWriter != NULL ) -- GitLab From ad7d89957c647c4b3912a8a25f195d3c0509ad3c Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 27 Mar 2024 09:52:12 +0100 Subject: [PATCH 12/20] fix "-fr 5" decoding --- apps/decoder.c | 34 ++++++++-------------------------- lib_dec/lib_dec.c | 27 +++++++++++++-------------- 2 files changed, 21 insertions(+), 40 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 4b0827ac6e..e5fb99ac91 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -2348,20 +2348,20 @@ static ivas_error decodeG192( fprintf( stderr, "\nError: could not feed frame to decoder: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } - } #ifdef MEM_ALLOC_APP_DEC - /* Reconfigure IVAS decoder handles and reallocate the memory if IVAS total bitrate has changed */ + /* Reconfigure IVAS decoder handles and reallocate the memory if IVAS total bitrate has changed */ #ifdef SPLIT_REND_WITH_HEAD_ROT - if ( ( error = IVAS_DEC_Setup( hIvasDec, NULL, IVAS_DEC_PCM_INT16, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_Setup( hIvasDec, NULL, IVAS_DEC_PCM_INT16, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ) #else - if ( ( error = IVAS_DEC_Setup( hIvasDec, NULL, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_Setup( hIvasDec, NULL, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ) #endif - { - fprintf( stderr, "\nIVAS_DEC_Setup failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } + { + fprintf( stderr, "\nIVAS_DEC_Setup failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } #endif + } #ifdef SPLIT_REND_WITH_HEAD_ROT if ( arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) @@ -3236,24 +3236,6 @@ static ivas_error decodeVoIP( break; } -#ifdef MEM_ALLOC_APP_DEC -#if 0 -#ifndef MEM_ALLOC_APP_DEC_JBM - uint16_t nSamplesRendered = 0; - /* Reconfigure IVAS decoder handles and reallocate the memory if IVAS total bitrate has changed */ -#ifdef SPLIT_REND_WITH_HEAD_ROT - if ( ( error = IVAS_DEC_Setup( hIvasDec, &nSamplesRendered, IVAS_DEC_PCM_INT16, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ) -#else - if ( ( error = IVAS_DEC_Setup( hIvasDec, NULL, NULL ) ) != IVAS_ERR_OK ) -#endif - { - fprintf( stderr, "\nIVAS_DEC_Setup failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } -#endif -#endif -#endif - /* decode and get samples */ #ifdef SPLIT_REND_WITH_HEAD_ROT diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 6a556f7fee..8d00dc07f3 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -2712,20 +2712,6 @@ ivas_error IVAS_DEC_VoIP_GetSamples( } } -#ifdef MEM_ALLOC_APP_DEC_JBM - uint16_t nSamplesRendered2 = 0; - /* Reconfigure IVAS decoder handles and reallocate the memory if IVAS total bitrate has changed */ -#ifdef SPLIT_REND_WITH_HEAD_ROT - if ( ( error = IVAS_DEC_Setup( hIvasDec, &nSamplesRendered, IVAS_DEC_PCM_INT16, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ) -#else - if ( ( error = IVAS_DEC_Setup( hIvasDec, &nSamplesRendered2, pcmBuf + nSamplesRendered2 * nOutChannels ) ) != IVAS_ERR_OK ) -#endif - { - fprintf( stderr, "\nIVAS_DEC_Setup failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - return error; - } -#endif - #ifdef SUPPORT_JBM_TRACEFILE /* jbmWriterFn and jbmWriter may be NULL if tracefile writing was not requested on CLI */ if ( jbmWriterFn != NULL && jbmWriter != NULL ) @@ -2761,6 +2747,19 @@ ivas_error IVAS_DEC_VoIP_GetSamples( } } +#ifdef MEM_ALLOC_APP_DEC_JBM + uint16_t nSamplesRendered2 = 0; + /* Reconfigure IVAS decoder handles and reallocate the memory if IVAS total bitrate has changed */ +#ifdef SPLIT_REND_WITH_HEAD_ROT + if ( ( error = IVAS_DEC_Setup( hIvasDec, &nSamplesRendered, IVAS_DEC_PCM_INT16, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ) +#else + if ( ( error = IVAS_DEC_Setup( hIvasDec, &nSamplesRendered2, pcmBuf + nSamplesRendered2 * nOutChannels ) ) != IVAS_ERR_OK ) +#endif + { + fprintf( stderr, "\nIVAS_DEC_Setup failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + return error; + } +#endif /* decode */ if ( !hIvasDec->hasBeenFedFirstGoodFrame ) { -- GitLab From bbe31ed1b4ee9c70645f18ba681d2763fa53f7bf Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 3 Jun 2024 18:19:03 +0200 Subject: [PATCH 13/20] comment --- lib_dec/lib_dec.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index f2ee77de5f..1d18e0822c 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -2936,10 +2936,10 @@ ivas_error IVAS_DEC_VoIP_GetSamples( } #ifdef MEM_ALLOC_APP_DEC_JBM - uint16_t nSamplesRendered2 = 0; - /* Reconfigure IVAS decoder handles and reallocate the memory if IVAS total bitrate has changed */ + uint16_t nSamplesRendered2 = 0; // VE: todo - verify use for EVS + /* Reconfigure IVAS decoder handles and reallocate the memory if IVAS total bitrate has changed */ #ifdef SPLIT_REND_WITH_HEAD_ROT - if ( ( error = IVAS_DEC_Setup( hIvasDec, &nSamplesRendered, IVAS_DEC_PCM_INT16, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_Setup( hIvasDec, &nSamplesRendered2, IVAS_DEC_PCM_INT16, pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ) ) ) != IVAS_ERR_OK ) #else if ( ( error = IVAS_DEC_Setup( hIvasDec, &nSamplesRendered2, pcmBuf + nSamplesRendered2 * nOutChannels ) ) != IVAS_ERR_OK ) #endif -- GitLab From f2ae2d87ccf054996c17fb6487cf1308664c735c Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 6 Jun 2024 14:58:09 +0200 Subject: [PATCH 14/20] fix JBM decoding --- apps/decoder.c | 4 +++ lib_com/options.h | 2 +- lib_dec/lib_dec.c | 74 +++++++++++++++++++++++++++++++++++++---------- lib_dec/lib_dec.h | 3 ++ 4 files changed, 66 insertions(+), 17 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 120298e5c1..6b7d07e516 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -2620,7 +2620,11 @@ static ivas_error decodeG192( { #endif #ifdef SPLIT_REND_WITH_HEAD_ROT +#ifdef MEM_ALLOC_APP_DEC_JBM + if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, IVAS_DEC_PCM_INT16, (void *) ( pcmBuf + nOutChannels * nSamplesRendered ), &nSamplesRendered_loop, &needNewFrame, 1 ) ) != IVAS_ERR_OK ) +#else if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, IVAS_DEC_PCM_INT16, (void *) ( pcmBuf + nOutChannels * nSamplesRendered ), &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK ) +#endif #else if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, ( pcmBuf + nOutChannels * nSamplesRendered ), &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK ) diff --git a/lib_com/options.h b/lib_com/options.h index 37bad2eb56..7891875d1c 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -180,7 +180,7 @@ #define MEM_ALLOC_APP /* VA: call memory allocate/reallocation from the application */ #define MEM_ALLOC_APP_DEC /* VA: call memory allocate/reallocation from the application, decoder part */ -//#define MEM_ALLOC_APP_DEC_JBM +#define MEM_ALLOC_APP_DEC_JBM /* #################### End BE switches ################################## */ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 1d18e0822c..32a9a33418 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -931,6 +931,10 @@ ivas_error IVAS_DEC_GetSamples( #endif int16_t *nOutSamples, /* o : number of samples per channel written to output buffer */ bool *needNewFrame /* o :indication that the decoder needs a new frame */ +#ifdef MEM_ALLOC_APP_DEC_JBM + , + const int16_t flag_decode +#endif ) { ivas_error error; @@ -1009,6 +1013,15 @@ ivas_error IVAS_DEC_GetSamples( /* check if we need to run the setup function */ if ( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) { +#ifdef MEM_ALLOC_APP_DEC_JBM + if ( flag_decode == 0 ) + { + *nOutSamples = -1; // TBD + + return IVAS_ERR_OK; + } +#endif + #ifdef MEM_ALLOC_APP_DEC #ifndef MEM_ALLOC_APP_DEC_JBM if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) // ToDo: TBD for JBM @@ -1066,6 +1079,7 @@ ivas_error IVAS_DEC_GetSamples( if ( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) { int16_t nResidualSamples, nSamplesTcsScaled; + nSamplesRendered += nSamplesRendered_loop; if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm && nTransportChannels != hIvasDec->nTransportChannelsOld ) @@ -1239,7 +1253,11 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( /* Decode and render */ +#ifdef MEM_ALLOC_APP_DEC_JBM + if ( ( error = IVAS_DEC_GetSamples( hIvasDec, numSamplesPerChannelToDecode, IVAS_DEC_PCM_FLOAT, pcmBuf, nOutSamples, needNewFrame, 1 ) ) != IVAS_ERR_OK ) +#else if ( ( error = IVAS_DEC_GetSamples( hIvasDec, numSamplesPerChannelToDecode, IVAS_DEC_PCM_FLOAT, pcmBuf, nOutSamples, needNewFrame ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -2935,19 +2953,6 @@ ivas_error IVAS_DEC_VoIP_GetSamples( } } -#ifdef MEM_ALLOC_APP_DEC_JBM - uint16_t nSamplesRendered2 = 0; // VE: todo - verify use for EVS - /* Reconfigure IVAS decoder handles and reallocate the memory if IVAS total bitrate has changed */ -#ifdef SPLIT_REND_WITH_HEAD_ROT - if ( ( error = IVAS_DEC_Setup( hIvasDec, &nSamplesRendered2, IVAS_DEC_PCM_INT16, pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ) ) ) != IVAS_ERR_OK ) -#else - if ( ( error = IVAS_DEC_Setup( hIvasDec, &nSamplesRendered2, pcmBuf + nSamplesRendered2 * nOutChannels ) ) != IVAS_ERR_OK ) -#endif - { - fprintf( stderr, "\nIVAS_DEC_Setup failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - return error; - } -#endif /* decode */ if ( !hIvasDec->hasBeenFedFirstGoodFrame ) { @@ -2971,20 +2976,57 @@ ivas_error IVAS_DEC_VoIP_GetSamples( nSamplesToRender = nSamplesPerChannel - nSamplesRendered; /* render IVAS frames directly to the output buffer */ -#ifdef SPLIT_REND_WITH_HEAD_ROT - if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, pcmType, pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ), &nSamplesRendered_loop, &tmp ) ) != IVAS_ERR_OK ) +#ifdef MEM_ALLOC_APP_DEC_JBM + if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, pcmType, pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ), &nSamplesRendered_loop, &tmp, 0 ) ) != IVAS_ERR_OK ) #else - if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, pcmBuf + nSamplesRendered * nOutChannels, &nSamplesRendered_loop, &tmp ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, pcmType, pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ), &nSamplesRendered_loop, &tmp ) ) != IVAS_ERR_OK ) #endif { return error; } +#ifdef MEM_ALLOC_APP_DEC_JBM + if ( nSamplesRendered_loop == -1 ) + { + break; + } +#endif + nSamplesRendered += nSamplesRendered_loop; update_voip_rendered20ms( hIvasDec, nSamplesRendered_loop ); } } +#ifdef MEM_ALLOC_APP_DEC_JBM + if ( hIvasDec->hasBeenFedFirstGoodFrame ) + { + if ( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) + { + uint16_t nSamplesRendered2 = 0; // VE: todo - verify use for EVS + + /* Reconfigure IVAS decoder handles and reallocate the memory if IVAS total bitrate has changed */ + if ( ( error = IVAS_DEC_Setup( hIvasDec, &nSamplesRendered2, IVAS_DEC_PCM_INT16, pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ) ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_Setup failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + return error; + } + } + + int16_t nSamplesToRender, nSamplesRendered_loop; + bool tmp; + nSamplesToRender = nSamplesPerChannel - nSamplesRendered; + + /* render IVAS frames directly to the output buffer */ + if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, pcmType, pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ), &nSamplesRendered_loop, &tmp, 1 ) ) != IVAS_ERR_OK ) + { + return error; + } + + nSamplesRendered += nSamplesRendered_loop; + update_voip_rendered20ms( hIvasDec, nSamplesRendered_loop ); + } +#endif + return IVAS_ERR_OK; } diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index a12a3cd5c6..b0b9a3a4ba 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -179,6 +179,9 @@ ivas_error IVAS_DEC_GetSamples( #endif int16_t *nOutSamples, /* o : number of samples per channel written to output buffer */ bool *needNewFrame /* o : indication that the decoder needs a new frame */ +#ifdef MEM_ALLOC_APP_DEC_JBM + ,const int16_t flag_decode +#endif ); #ifdef SPLIT_REND_WITH_HEAD_ROT -- GitLab From 900a498b9a4576914bf26f5a1227b43750e19235 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 6 Jun 2024 17:08:31 +0200 Subject: [PATCH 15/20] introduce IVAS_DEC_GetSamples_wrapper() and move IVAS_DEC_Setup() to decoder app. --- apps/decoder.c | 30 ++++++++++++++++++++++ lib_dec/lib_dec.c | 65 ++++++++++++++++++++++++++++++++--------------- lib_dec/lib_dec.h | 14 ++++++++++ 3 files changed, 89 insertions(+), 20 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 6b7d07e516..40639c6d7c 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -3477,10 +3477,22 @@ static ivas_error decodeVoIP( #ifdef SPLIT_REND_WITH_HEAD_ROT #ifdef SUPPORT_JBM_TRACEFILE +#ifdef MEM_ALLOC_APP_DEC_JBM + int16_t nSamplesRendered_pre = 0; + + if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, systemTime_ms, &nSamplesRendered_pre, writeJbmTraceFileFrameWrapper, jbmTraceWriter ) ) != IVAS_ERR_OK ) +#else if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, systemTime_ms, writeJbmTraceFileFrameWrapper, jbmTraceWriter ) ) != IVAS_ERR_OK ) +#endif +#else +#ifdef MEM_ALLOC_APP_DEC_JBM + int16_t nSamplesRendered_pre = 0; + + if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, systemTime_ms, &nSamplesRendered_pre ) ) != IVAS_ERR_OK ) #else if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, systemTime_ms ) ) != IVAS_ERR_OK ) #endif +#endif #else #ifdef SUPPORT_JBM_TRACEFILE if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, pcmBuf, systemTime_ms, writeJbmTraceFileFrameWrapper, jbmTraceWriter ) ) != IVAS_ERR_OK ) @@ -3493,6 +3505,24 @@ static ivas_error decodeVoIP( goto cleanup; } +#ifdef MEM_ALLOC_APP_DEC_JBM + /* Reconfigure IVAS decoder handles and reallocate the memory if IVAS total bitrate has changed */ + uint16_t nSamplesRendered2 = 0; + if ( ( error = IVAS_DEC_Setup( hIvasDec, &nSamplesRendered2, IVAS_DEC_PCM_INT16, pcmBuf + nSamplesRendered_pre * nOutChannels ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_Setup failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + return error; + } + + /* decode frame and get samples */ + if ( ( error = IVAS_DEC_GetSamples_wrapper( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, pcmBuf, nSamplesRendered_pre ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in IVAS_DEC_GetSamples_wrapper: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } +#endif + + /* write JBM Offset file entry */ if ( jbmOffsetWriter != NULL ) { diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 32a9a33418..f62c14cc32 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1016,7 +1016,7 @@ ivas_error IVAS_DEC_GetSamples( #ifdef MEM_ALLOC_APP_DEC_JBM if ( flag_decode == 0 ) { - *nOutSamples = -1; // TBD + *nOutSamples = -1; return IVAS_ERR_OK; } @@ -1401,6 +1401,14 @@ ivas_error IVAS_DEC_Setup( return IVAS_ERR_OK; } +#ifdef MEM_ALLOC_APP_DEC_JBM + if ( !( hIvasDec->hasBeenFedFirstGoodFrame && ( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) ) ) + { + /* no frame was fed, do nothing */ + return IVAS_ERR_OK; + } +#endif + if ( hIvasDec->mode == IVAS_DEC_MODE_EVS ) { /* EVS decoding, do nothing */ @@ -2808,6 +2816,10 @@ ivas_error IVAS_DEC_VoIP_GetSamples( int16_t *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ #endif const uint32_t systemTimestamp_ms /* i : current system timestamp */ +#ifdef MEM_ALLOC_APP_DEC_JBM + , + int16_t *nSamplesRendered_pre +#endif #ifdef SUPPORT_JBM_TRACEFILE , JbmTraceFileWriterFn jbmWriterFn, @@ -2988,6 +3000,8 @@ ivas_error IVAS_DEC_VoIP_GetSamples( #ifdef MEM_ALLOC_APP_DEC_JBM if ( nSamplesRendered_loop == -1 ) { + *nSamplesRendered_pre = nSamplesRendered; + break; } #endif @@ -2997,39 +3011,50 @@ ivas_error IVAS_DEC_VoIP_GetSamples( } } + return IVAS_ERR_OK; +} + #ifdef MEM_ALLOC_APP_DEC_JBM - if ( hIvasDec->hasBeenFedFirstGoodFrame ) - { - if ( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) - { - uint16_t nSamplesRendered2 = 0; // VE: todo - verify use for EVS - /* Reconfigure IVAS decoder handles and reallocate the memory if IVAS total bitrate has changed */ - if ( ( error = IVAS_DEC_Setup( hIvasDec, &nSamplesRendered2, IVAS_DEC_PCM_INT16, pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ) ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nIVAS_DEC_Setup failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - return error; - } - } +/*---------------------------------------------------------------------* + * IVAS_DEC_GetSamples_wrapper( ) + * + * Main function to decode one frame in VoIP + *---------------------------------------------------------------------*/ - int16_t nSamplesToRender, nSamplesRendered_loop; - bool tmp; - nSamplesToRender = nSamplesPerChannel - nSamplesRendered; +ivas_error IVAS_DEC_GetSamples_wrapper( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const int16_t nSamplesAsked, /* i : number of samples wanted by the caller */ + const IVAS_DEC_PCM_TYPE pcmType, /* i : type for the decoded PCM resolution */ + void *pcmBuf, /* o : output synthesis signal */ + const int16_t nSamplesRendered_pre /* i : number of samples already rendered */ +) +{ + ivas_error error; + int16_t nOutChannels; + int16_t nSamplesToRender, nSamplesRendered_loop; + bool tmp; - /* render IVAS frames directly to the output buffer */ - if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, pcmType, pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ), &nSamplesRendered_loop, &tmp, 1 ) ) != IVAS_ERR_OK ) + nOutChannels = hIvasDec->st_ivas->hDecoderConfig->nchan_out; + nSamplesToRender = nSamplesAsked - nSamplesRendered_pre; + + if ( hIvasDec->hasBeenFedFirstGoodFrame ) + { + /* render IVAS frames directly to the output buffer */ + if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, pcmType, pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered_pre * nOutChannels ), &nSamplesRendered_loop, &tmp, 1 ) ) != IVAS_ERR_OK ) { return error; } - nSamplesRendered += nSamplesRendered_loop; + //nSamplesRendered_pre += nSamplesRendered_loop; update_voip_rendered20ms( hIvasDec, nSamplesRendered_loop ); } -#endif return IVAS_ERR_OK; } +#endif + /*---------------------------------------------------------------------* * update_voip_rendered20ms( ) * diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index b0b9a3a4ba..3e7486ffda 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -310,12 +310,26 @@ ivas_error IVAS_DEC_VoIP_GetSamples( int16_t *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ #endif const uint32_t systemTimestamp_ms /* i : current system timestamp */ +#ifdef MEM_ALLOC_APP_DEC_JBM + , + int16_t *nSamplesRendered_pre +#endif #ifdef SUPPORT_JBM_TRACEFILE , JbmTraceFileWriterFn jbmWriterFn, void* jbmWriter #endif ); +#ifdef MEM_ALLOC_APP_DEC_JBM +ivas_error IVAS_DEC_GetSamples_wrapper( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const int16_t nSamplesAsked, /* i : number of samples wanted by the caller */ + const IVAS_DEC_PCM_TYPE pcmType, /* i : type for the decoded PCM resolution */ + void *pcmBuf, /* o : output synthesis signal */ + const int16_t nSamplesRendered_pre /* i : number of samples already rendered */ +); + +#endif ivas_error IVAS_DEC_Flush( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const int16_t nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ -- GitLab From 1c2c2e4a886874f21f661f4ffa4523312c2ee871 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 6 Jun 2024 17:35:49 +0200 Subject: [PATCH 16/20] clang-format --- lib_dec/lib_dec.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index b6ef23281b..f92e12b487 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1375,7 +1375,7 @@ ivas_error IVAS_DEC_Setup( const IVAS_DEC_PCM_TYPE pcmType, /* i : type for the decoded PCM resolution */ void *data /* o : output synthesis signal */ #else - int16_t *data /* o : output synthesis signal */ + int16_t *data /* o : output synthesis signal */ #endif ) { @@ -1422,20 +1422,40 @@ ivas_error IVAS_DEC_Setup( if ( st_ivas->bfi == 0 ) { -#ifdef SPLIT_REND_WITH_HEAD_ROT if ( ( error = ivas_dec_setup( st_ivas, &nSamplesRendered_loc, pcm_type_API_to_internal( pcmType ), data ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_dec_setup( st_ivas, &nSamplesRendered_loc, data ) ) != IVAS_ERR_OK ) -#endif { return error; } } + /*-----------------------------------------------------------------* + * ISAR: + * - initialize ISAR handle at the first frame + * - reconfigure the ISAR handle in case of bitrate switching (renderer might change) + *-----------------------------------------------------------------*/ + + if ( st_ivas->ini_frame == 0 && ( is_split_rendering_enabled( st_ivas->hDecoderConfig, st_ivas->hRenderConfig ) ) ) + { + if ( ( error = ivas_dec_init_split_rend( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) + { + if ( ( error = ivas_dec_reconfig_split_rend( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /* Final updates */ if ( nSamplesRendered != NULL ) { *nSamplesRendered = nSamplesRendered_loc; } + hIvasDec->nSamplesRendered_flush = nSamplesRendered_loc; } @@ -3040,7 +3060,7 @@ ivas_error IVAS_DEC_GetSamples_wrapper( return error; } - //nSamplesRendered_pre += nSamplesRendered_loop; + // nSamplesRendered_pre += nSamplesRendered_loop; update_voip_rendered20ms( hIvasDec, nSamplesRendered_loop ); } -- GitLab From dc0c2d28262fb8f56a3d69711f56f50c6afbc4b7 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 7 Jun 2024 12:16:02 +0200 Subject: [PATCH 17/20] fix split-rendering decoder --- apps/decoder.c | 10 ++++++++++ lib_dec/lib_dec.c | 31 +++++++++++++++++++++++++++++++ lib_dec/lib_dec.h | 7 +++++++ 3 files changed, 48 insertions(+) diff --git a/apps/decoder.c b/apps/decoder.c index 34a073e679..e667517d4f 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -2548,6 +2548,16 @@ static ivas_error decodeG192( } #ifdef MEM_ALLOC_APP_DEC + /* setup ISAR */ + if ( isSplitRend ) + { + if ( ( error = IVAS_DEC_split_rend_setup( hIvasDec, splitRendBits ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_split_rend_setup failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + } + /* Reconfigure IVAS decoder handles and reallocate the memory if IVAS total bitrate has changed */ #ifdef SPLIT_REND_WITH_HEAD_ROT if ( ( error = IVAS_DEC_Setup( hIvasDec, NULL, IVAS_DEC_PCM_INT16, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index f92e12b487..e7182ef1e0 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1164,6 +1164,35 @@ ivas_error IVAS_DEC_GetSamples( #ifdef SPLIT_REND_WITH_HEAD_ROT +#ifdef MEM_ALLOC_APP_DEC +/*---------------------------------------------------------------------* + * IVAS_DEC_split_rend_setup( ) + * + * + *---------------------------------------------------------------------*/ +// VE: todo - this could be moved to isar_lib +ivas_error IVAS_DEC_split_rend_setup( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + ISAR_SPLIT_REND_BITS_DATA *splitRendBits /* o : output split rendering bits */ +) +{ + Decoder_Struct *st_ivas; + ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE hSplitBinRend; + ivas_error error; + + st_ivas = hIvasDec->st_ivas; + hSplitBinRend = st_ivas->hSplitBinRend; + + if ( ( error = isar_set_split_rend_setup( hSplitBinRend, &st_ivas->hRenderConfig->split_rend_config, st_ivas->hCombinedOrientationData, splitRendBits ) ) != IVAS_ERR_OK ) + { + return error; + } + + return error; +} + +#endif + /*---------------------------------------------------------------------* * IVAS_DEC_GetSplitBinauralBitstream( ) * @@ -1206,12 +1235,14 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( *needNewFrame = false; hSplitBinRend = st_ivas->hSplitBinRend; +#ifndef MEM_ALLOC_APP_DEC if ( ( error = isar_set_split_rend_setup( hSplitBinRend, &st_ivas->hRenderConfig->split_rend_config, st_ivas->hCombinedOrientationData, splitRendBits ) ) != IVAS_ERR_OK ) { return error; } +#endif numPoses = hSplitBinRend->splitrend.multiBinPoseData.num_poses; if ( st_ivas->hDecoderConfig->render_framesize != IVAS_RENDER_FRAMESIZE_20MS && diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 36a619db04..011d6308e0 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -185,6 +185,13 @@ ivas_error IVAS_DEC_GetSamples( ); #ifdef SPLIT_REND_WITH_HEAD_ROT +#ifdef MEM_ALLOC_APP_DEC +ivas_error IVAS_DEC_split_rend_setup( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + ISAR_SPLIT_REND_BITS_DATA *splitRendBits /* o : output split rendering bits */ +); + +#endif ivas_error IVAS_DEC_GetSplitBinauralBitstream( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ void *pcmBuf_out, /* o : output synthesis signal for BINAURAL_SPLIT_PCM */ -- GitLab From c03c7ff374d955dbdd781908d8a055da0718a268 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 7 Jun 2024 13:49:20 +0200 Subject: [PATCH 18/20] fix (that caused EVS JBM non-BE) --- apps/decoder.c | 2 +- lib_dec/lib_dec.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index e667517d4f..21c5490b19 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -2548,7 +2548,7 @@ static ivas_error decodeG192( } #ifdef MEM_ALLOC_APP_DEC - /* setup ISAR */ + /* Setup ISAR handle */ if ( isSplitRend ) { if ( ( error = IVAS_DEC_split_rend_setup( hIvasDec, splitRendBits ) ) != IVAS_ERR_OK ) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index e7182ef1e0..ef8ac90c1f 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -3083,7 +3083,7 @@ ivas_error IVAS_DEC_GetSamples_wrapper( nOutChannels = hIvasDec->st_ivas->hDecoderConfig->nchan_out; nSamplesToRender = nSamplesAsked - nSamplesRendered_pre; - if ( hIvasDec->hasBeenFedFirstGoodFrame ) + if ( hIvasDec->hasBeenFedFirstGoodFrame && hIvasDec->hasBeenFedFrame ) { /* render IVAS frames directly to the output buffer */ if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, pcmType, pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered_pre * nOutChannels ), &nSamplesRendered_loop, &tmp, 1 ) ) != IVAS_ERR_OK ) -- GitLab From 4c06fea62ef2e5a4ea9ae015f9a1b88e2dd27936 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 7 Jun 2024 15:14:35 +0200 Subject: [PATCH 19/20] fix split-rendering -fr 5 --- apps/decoder.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/apps/decoder.c b/apps/decoder.c index 21c5490b19..ebc8035993 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -2570,6 +2570,20 @@ static ivas_error decodeG192( } #endif } +#ifdef MEM_ALLOC_APP_DEC + else + { + /* Setup ISAR handle */ + if ( isSplitRend ) + { + if ( ( error = IVAS_DEC_split_rend_setup( hIvasDec, splitRendBits ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_split_rend_setup failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + } + } +#endif #ifdef SPLIT_REND_WITH_HEAD_ROT if ( isSplitRend ) -- GitLab From 6a9ab0a3d6eeff5dd868ac3f61fee4b723de646a Mon Sep 17 00:00:00 2001 From: vaclav Date: Sun, 9 Jun 2024 17:49:22 +0200 Subject: [PATCH 20/20] merge MEM_ALLOC_APP_DEC_JBM into MEM_ALLOC_APP_DEC --- apps/decoder.c | 8 ++++---- lib_com/options.h | 2 +- lib_dec/lib_dec.c | 51 +++++++++++++++++++---------------------------- lib_dec/lib_dec.h | 15 ++++++++------ 4 files changed, 34 insertions(+), 42 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 18def76c1d..85f625fe13 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -2474,7 +2474,7 @@ static ivas_error decodeG192( } else { -#ifdef MEM_ALLOC_APP_DEC_JBM +#ifdef MEM_ALLOC_APP_DEC if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, IVAS_DEC_PCM_INT16, (void *) ( pcmBuf + nOutChannels * nSamplesRendered ), &nSamplesRendered_loop, &needNewFrame, 1 ) ) != IVAS_ERR_OK ) #else if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, IVAS_DEC_PCM_INT16, (void *) ( pcmBuf + nOutChannels * nSamplesRendered ), &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK ) @@ -3290,7 +3290,7 @@ static ivas_error decodeVoIP( /* decode and get samples */ #ifdef SUPPORT_JBM_TRACEFILE -#ifdef MEM_ALLOC_APP_DEC_JBM +#ifdef MEM_ALLOC_APP_DEC int16_t nSamplesRendered_pre = 0; if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, systemTime_ms, &nSamplesRendered_pre, writeJbmTraceFileFrameWrapper, jbmTraceWriter ) ) != IVAS_ERR_OK ) @@ -3298,7 +3298,7 @@ static ivas_error decodeVoIP( if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, systemTime_ms, writeJbmTraceFileFrameWrapper, jbmTraceWriter ) ) != IVAS_ERR_OK ) #endif #else -#ifdef MEM_ALLOC_APP_DEC_JBM +#ifdef MEM_ALLOC_APP_DEC int16_t nSamplesRendered_pre = 0; if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, systemTime_ms, &nSamplesRendered_pre ) ) != IVAS_ERR_OK ) @@ -3311,7 +3311,7 @@ static ivas_error decodeVoIP( goto cleanup; } -#ifdef MEM_ALLOC_APP_DEC_JBM +#ifdef MEM_ALLOC_APP_DEC /* Reconfigure IVAS decoder handles and reallocate the memory if IVAS total bitrate has changed */ uint16_t nSamplesRendered2 = 0; if ( ( error = IVAS_DEC_Setup( hIvasDec, &nSamplesRendered2, IVAS_DEC_PCM_INT16, pcmBuf + nSamplesRendered_pre * nOutChannels ) ) != IVAS_ERR_OK ) diff --git a/lib_com/options.h b/lib_com/options.h index f43bf19546..0e506b36d2 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -166,7 +166,7 @@ #define MEM_ALLOC_APP /* VA: call memory allocate/reallocation from the application */ #define MEM_ALLOC_APP_DEC /* VA: call memory allocate/reallocation from the application, decoder part */ -#define MEM_ALLOC_APP_DEC_JBM + /* #################### End BE switches ################################## */ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 83105ae7e2..7f0b2bf0b0 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -891,17 +891,17 @@ ivas_error IVAS_DEC_FeedFrame_Serial( * Main function to decode to PCM data *---------------------------------------------------------------------*/ - ivas_error IVAS_DEC_GetSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const int16_t nSamplesAsked, /* i : number of samples wanted by the caller */ const IVAS_DEC_PCM_TYPE pcmType, /* i : type for the decoded PCM resolution */ void *pcmBuf, /* o : output synthesis signal */ int16_t *nOutSamples, /* o : number of samples per channel written to output buffer */ - bool *needNewFrame /* o : indication that the decoder needs a new frame */ -#ifdef MEM_ALLOC_APP_DEC_JBM - , - const int16_t flag_decode +#ifdef MEM_ALLOC_APP_DEC + bool *needNewFrame, /* o : indication that the decoder needs a new frame */ + const int16_t flag_decode /* i : flag to indicate decoding */ +#else + bool *needNewFrame /* o : indication that the decoder needs a new frame */ #endif ) { @@ -979,25 +979,14 @@ ivas_error IVAS_DEC_GetSamples( /* check if we need to run the setup function */ if ( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) { -#ifdef MEM_ALLOC_APP_DEC_JBM +#ifdef MEM_ALLOC_APP_DEC if ( flag_decode == 0 ) { + /* do not run decoder */ *nOutSamples = -1; return IVAS_ERR_OK; } -#endif - -#ifdef MEM_ALLOC_APP_DEC -#ifndef MEM_ALLOC_APP_DEC_JBM - if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) // ToDo: TBD for JBM - { - if ( ( error = IVAS_DEC_Setup( hIvasDec, &nSamplesRendered, pcmType, pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ) ) ) != IVAS_ERR_OK ) - { - return error; - } - } -#endif if ( hIvasDec->mode == IVAS_DEC_MODE_EVS ) { @@ -1232,7 +1221,7 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( } /* Decode and render */ -#ifdef MEM_ALLOC_APP_DEC_JBM +#ifdef MEM_ALLOC_APP_DEC if ( ( error = IVAS_DEC_GetSamples( hIvasDec, numSamplesPerChannelToDecode, IVAS_DEC_PCM_FLOAT, pcmBuf, nOutSamples, needNewFrame, 1 ) ) != IVAS_ERR_OK ) #else if ( ( error = IVAS_DEC_GetSamples( hIvasDec, numSamplesPerChannelToDecode, IVAS_DEC_PCM_FLOAT, pcmBuf, nOutSamples, needNewFrame ) ) != IVAS_ERR_OK ) @@ -1386,8 +1375,6 @@ static /* no frame was fed, do nothing */ return IVAS_ERR_OK; } -#endif -#ifdef MEM_ALLOC_APP_DEC_JBM if ( !( hIvasDec->hasBeenFedFirstGoodFrame && ( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) ) ) { @@ -2695,14 +2682,15 @@ ivas_error IVAS_DEC_TSM_SetQuality( *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_VoIP_GetSamples( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - uint16_t nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ - const IVAS_DEC_PCM_TYPE pcmType, /* i : type for the decoded PCM resolution */ - void *pcmBuf, /* o : output synthesis signal */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + uint16_t nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ + const IVAS_DEC_PCM_TYPE pcmType, /* i : type for the decoded PCM resolution */ + void *pcmBuf, /* o : output synthesis signal */ +#ifdef MEM_ALLOC_APP_DEC + const uint32_t systemTimestamp_ms, /* i : current system timestamp */ + int16_t *nSamplesRendered_pre /* o : number of already rendered samples */ +#else const uint32_t systemTimestamp_ms /* i : current system timestamp */ -#ifdef MEM_ALLOC_APP_DEC_JBM - , - int16_t *nSamplesRendered_pre #endif #ifdef SUPPORT_JBM_TRACEFILE , @@ -2868,7 +2856,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( nSamplesToRender = nSamplesPerChannel - nSamplesRendered; /* render IVAS frames directly to the output buffer */ -#ifdef MEM_ALLOC_APP_DEC_JBM +#ifdef MEM_ALLOC_APP_DEC if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, pcmType, pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ), &nSamplesRendered_loop, &tmp, 0 ) ) != IVAS_ERR_OK ) #else if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, pcmType, pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ), &nSamplesRendered_loop, &tmp ) ) != IVAS_ERR_OK ) @@ -2877,9 +2865,10 @@ ivas_error IVAS_DEC_VoIP_GetSamples( return error; } -#ifdef MEM_ALLOC_APP_DEC_JBM +#ifdef MEM_ALLOC_APP_DEC if ( nSamplesRendered_loop == -1 ) { + /* stop the rendering for now */ *nSamplesRendered_pre = nSamplesRendered; break; @@ -2894,7 +2883,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( return IVAS_ERR_OK; } -#ifdef MEM_ALLOC_APP_DEC_JBM +#ifdef MEM_ALLOC_APP_DEC /*---------------------------------------------------------------------* * IVAS_DEC_GetSamples_wrapper( ) diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 9ca4846786..6571feb318 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -168,9 +168,11 @@ ivas_error IVAS_DEC_GetSamples( const IVAS_DEC_PCM_TYPE pcmType, /* i : type for the decoded PCM resolution */ void *pcmBuf, /* o : output synthesis signal */ int16_t *nOutSamples, /* o : number of samples per channel written to output buffer */ +#ifdef MEM_ALLOC_APP_DEC + bool *needNewFrame, /* o : indication that the decoder needs a new frame */ + const int16_t flag_decode /* i : flag to indicate decoding */ +#else bool *needNewFrame /* o : indication that the decoder needs a new frame */ -#ifdef MEM_ALLOC_APP_DEC_JBM - ,const int16_t flag_decode #endif ); @@ -296,10 +298,11 @@ ivas_error IVAS_DEC_VoIP_GetSamples( uint16_t nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ const IVAS_DEC_PCM_TYPE pcmType, /* i : type for the decoded PCM resolution */ void *pcmBuf, /* o : output synthesis signal */ +#ifdef MEM_ALLOC_APP_DEC + const uint32_t systemTimestamp_ms, /* i : current system timestamp */ + int16_t *nSamplesRendered_pre /* o : number of already rendered samples */ +#else const uint32_t systemTimestamp_ms /* i : current system timestamp */ -#ifdef MEM_ALLOC_APP_DEC_JBM - , - int16_t *nSamplesRendered_pre #endif #ifdef SUPPORT_JBM_TRACEFILE , JbmTraceFileWriterFn jbmWriterFn, @@ -307,7 +310,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( #endif ); -#ifdef MEM_ALLOC_APP_DEC_JBM +#ifdef MEM_ALLOC_APP_DEC ivas_error IVAS_DEC_GetSamples_wrapper( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const int16_t nSamplesAsked, /* i : number of samples wanted by the caller */ -- GitLab