diff --git a/apps/decoder.c b/apps/decoder.c index d993eb4144fa850f22a3ecac9dd9dc74ec60274a..e5fb99ac91034f7bb73d15dba6cdffc721b52473 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -807,6 +807,7 @@ int main( } } + /*------------------------------------------------------------------------------------------* * Allocate output data buffer *------------------------------------------------------------------------------------------*/ @@ -2068,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; @@ -2342,6 +2348,19 @@ 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 */ +#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, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ) +#endif + { + fprintf( stderr, "\nIVAS_DEC_Setup failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } +#endif } #ifdef SPLIT_REND_WITH_HEAD_ROT @@ -3217,7 +3236,6 @@ static ivas_error decodeVoIP( break; } - /* decode and get samples */ #ifdef SPLIT_REND_WITH_HEAD_ROT diff --git a/apps/encoder.c b/apps/encoder.c index b00f4f75fdc85f3dc72e6ad1a0a9568e70e2a60d..914795202012375e150d70e06e97c16c84c71170 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -368,9 +368,15 @@ int main( goto cleanup; } +#ifdef MEM_ALLOC_APP + /*------------------------------------------------------------------------------------------* + * Configure the encoder + *------------------------------------------------------------------------------------------*/ +#else /*------------------------------------------------------------------------------------------* * Configure and initialize (allocate memory for static variables) the encoder *------------------------------------------------------------------------------------------*/ +#endif switch ( arg.inputFormat ) { @@ -449,6 +455,18 @@ int main( goto cleanup; } +#ifdef MEM_ALLOC_APP + /*------------------------------------------------------------------------------------------* + * Initialize (allocate memory for static variables) the encoder + *------------------------------------------------------------------------------------------*/ + + 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 ) ); @@ -756,6 +774,14 @@ int main( } } +#ifdef MEM_ALLOC_APP + /* 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 757db691e977c89e2a7d1041ca468fe585879ec5..1aa47c83e6fb58aa5c1197272bca38271721f2f3 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -278,6 +278,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_initialize_MD_bstr_enc( BSTR_ENC_HANDLE *hBstr, /* o : encoder MD bitstream handle */ Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ @@ -4944,10 +4950,20 @@ 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 */ ); +#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_com/options.h b/lib_com/options.h index baac6516076c16fa9fe61d9e1b1be0987de1209d..25563cdc4a501691dc86d6dad2b9a2c425c9ac68 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -158,6 +158,11 @@ #define FIX_1033_MEMORY_LEAK_OMASA /* Nokia / Orange: issue #1033: Memory leak in OMASA to BINAURAL with HRTF with bitrate switching */ + +#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 ################################## */ /* #################### Start NON-BE switches ############################ */ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index aeb8f84303e8ec6dac28f5c3e9ddecfe84829f8c..8d00dc07f34d880c9cf1410641ff65ea58abb9d8 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 */ @@ -108,11 +111,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 @@ -169,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; @@ -476,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; @@ -823,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; @@ -850,6 +864,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 +882,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 +939,43 @@ ivas_error IVAS_DEC_GetSamples( /* check if we need to run the setup function */ 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 + 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, &nSamplesRendered, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ) +#endif + { + return error; + } + } +#endif + + 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; + nSamplesRendered = hIvasDec->nSamplesRendered_flush; + } +#else /* setup */ #ifdef SPLIT_REND_WITH_HEAD_ROT @@ -925,10 +983,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 +1254,82 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( * * *---------------------------------------------------------------------*/ +#ifdef MEM_ALLOC_APP_DEC + +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 */ +#else + int16_t *data /* o : output synthesis signal */ +#endif +) +{ + ivas_error error; + uint16_t nSamplesRendered_loc = 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 if ( data != NULL ) // ToDo: TBD for JBM + { + 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_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; + } + } + + if ( nSamplesRendered != NULL ) + { + *nSamplesRendered = nSamplesRendered_loc; + } + hIvasDec->nSamplesRendered_flush = nSamplesRendered_loc; + } + + 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 +1388,7 @@ static ivas_error IVAS_DEC_Setup( return IVAS_ERR_OK; } - +#endif /* MEM_ALLOC_APP_DEC */ /*---------------------------------------------------------------------* * IVAS_DEC_GetTcSamples( ) @@ -2620,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 ) { diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 2dccb455256a25ef6f071d0a99d306deac1ba0c7..54e5fa74f0ccffdc8e57ff2c5b4d2fca4c548ead 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -143,6 +143,19 @@ 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 */ + 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 */ +#else + int16_t *data /* o : output synthesis signal */ +#endif +); +#endif /* Decoding functions - should be called with a configured decoder handle */ diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 5ddcf9a506727f7d37ba32b00a4c56c0dd393e91..51e67e0cbff9a1d28a30a5b9a76800bc16311fc5 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -125,6 +125,7 @@ ivas_error ivas_enc( #ifdef DEBUG_MODE_LFE dbgwrite( data_f[LFE_CHANNEL], sizeof( float ), n_samples_chan, 1, "./res/lfe_input" ); #endif +#ifndef MEM_ALLOC_APP if ( ivas_format == SBA_FORMAT ) { @@ -141,6 +142,7 @@ ivas_error ivas_enc( } } +#endif /*----------------------------------------------------------------* * HP filtering *----------------------------------------------------------------*/ @@ -182,12 +184,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 ); @@ -225,10 +228,14 @@ 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 */ +#ifdef MEM_ALLOC_APP + ivas_masa_enc_init( st_ivas ); +#else 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 ) @@ -290,10 +297,14 @@ 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 ); +#ifdef MEM_ALLOC_APP + ivas_masa_enc_init( st_ivas ); +#else 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; @@ -438,11 +449,23 @@ ivas_error ivas_enc( } else if ( ivas_format == MC_FORMAT ) { +#ifdef MEM_ALLOC_APP + /* write MC LS setup */ + if ( st_ivas->nSCE > 0 ) + { + push_indice( st_ivas->hSCE[0]->hCoreCoder[0]->hBstr, IND_SMODE, st_ivas->hEncoderConfig->mc_input_setup, MC_LS_SETUP_BITS ); + } + else + { + push_indice( st_ivas->hCPE[0]->hCoreCoder[0]->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; diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index a394f1609011619c4f1f25eea95279f8646622f2..71bd9ab790d3d370049b2484237bbd25a051913d 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -1211,6 +1211,69 @@ 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 ) + { + /* reconfigure the MASA format encoder */ + error = ivas_masa_enc_config_memory( 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 + + /*------------------------------------------------------------------------- * ivas_initialize_MD_bstr_enc() * diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index e4b536dbee95fdf5c3c1f8e9064d86b5312e184e..ca4d5f3facbb8edee37f35d2b6121b36ada18f6c 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -678,17 +678,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; @@ -696,19 +710,23 @@ 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; +#ifndef MEM_ALLOC_APP int32_t ism_total_brate; 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; 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 ) ) { @@ -719,7 +737,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 ) @@ -756,6 +774,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 ) { @@ -803,6 +822,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 ) @@ -810,6 +830,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; @@ -900,10 +921,192 @@ 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; + } + } + + 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; + 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--; + + 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 ) + { + hQMetaData->q_direction->cfg.inactiveBands = MASA_MAXIMUM_CODING_SUBBANDS - maxBand; + } + else + { + 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 || hMasa->data.hOmasaData->omasa_stereo_sw_cnt < OMASA_STEREO_SW_CNT_MAX ) + { + hMasa->data.hOmasaData->lp_noise_CPE = st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise; + } + else + { + 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 a08dcea74d2b3320e378a3679107d2aa08e697c4..9590e9b4ad789c638f7c9acd1f52b19a020a00ad 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -128,11 +128,18 @@ 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; } +#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_mct_enc.c b/lib_enc/ivas_mct_enc.c index 83c5f57c17e46b72e685477ea354e87ab2e46207..9b59eb4a9e67765adfb44ea51405c0e939aa30a5 100755 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -633,7 +633,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; @@ -644,10 +646,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 b9bb5981cd6be64318e93e7693de4a5e040b75fc..bf0711af93ee8cad5470c414d85da6d3e7b9e130 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -264,6 +264,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 ) { @@ -275,7 +276,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 ) @@ -302,7 +303,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; } diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 4a4be817345a9cedb37036c02ebdc5a9f0b66992..db8837a5ccb028706c26d3b36c419dab638e45e0 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -725,6 +725,217 @@ ivas_error IVAS_ENC_ConfigureForMultichannel( } +#ifdef MEM_ALLOC_APP +/*---------------------------------------------------------------------* + * 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() * @@ -1005,6 +1216,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 /*-----------------------------------------------------------------* * Finalize initialization *-----------------------------------------------------------------*/ @@ -1022,7 +1234,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; @@ -1153,7 +1370,9 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( ENCODER_CONFIG_HANDLE hEncoderConfig; ENC_CORE_HANDLE hCoreCoder; int16_t i; +#ifndef MEM_ALLOC_APP int16_t n, ch; +#endif ivas_error error; error = IVAS_ERR_OK; @@ -1172,10 +1391,12 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( return IVAS_ERR_INVALID_INPUT_BUFFER_SIZE; } +#ifndef MEM_ALLOC_APP if ( ( error = sanitizeBandwidth( hIvasEnc ) ) != IVAS_ERR_OK ) { return error; } +#endif if ( hEncoderConfig->ivas_format == ISM_FORMAT ) { @@ -1189,6 +1410,7 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( resetIsmMetadataProvidedFlags( hIvasEnc ); } +#ifndef MEM_ALLOC_APP 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 ) @@ -1308,6 +1530,7 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( 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 2f40c1ab1beda5b883618dbd755b2a68076989f0..bf8c7fcc817b38ac3053ad9f8c0673acc92e4fc9 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 +/*! 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 */