From 5ce048621e38ce286a6516190f7385e172718e5b Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 4 Oct 2023 12:29:34 +0200 Subject: [PATCH] issue 847: Allocate decoder output PCM buffer dynamically; under FIX_847_OUTPUT_PCM_BUFFER --- apps/decoder.c | 25 ++++++++++++++++- lib_com/ivas_error.h | 7 +++++ lib_com/options.h | 2 +- lib_dec/lib_dec.c | 66 ++++++++++++++++++++++++++++++++++++++++++++ lib_dec/lib_dec.h | 8 ++++++ 5 files changed, 106 insertions(+), 2 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index e09e8fe209..404cf940e7 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -197,7 +197,11 @@ int main( RotFileReader *refRotReader = NULL; Vector3PairFileReader *referenceVectorReader = NULL; ivas_error error = IVAS_ERR_UNKNOWN; +#ifdef FIX_847_OUTPUT_PCM_BUFFER + int16_t *pcmBuf = NULL; +#else int16_t pcmBuf[MAX_OUTPUT_PCM_BUFFER_SIZE]; +#endif #ifdef SPLIT_REND_WITH_HEAD_ROT uint8_t splitRendBitsBuf[IVAS_MAX_SPLIT_REND_BITS_BUFFER_SIZE_IN_BYTES]; #endif @@ -753,6 +757,21 @@ int main( } } +#ifdef FIX_847_OUTPUT_PCM_BUFFER + /*------------------------------------------------------------------------------------------* + * Allocate output data buffer + *------------------------------------------------------------------------------------------*/ + + int16_t pcmBufSize; + if ( ( error = IVAS_DEC_GetOutputBufferSize( hIvasDec, &pcmBufSize ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nGetOutputBufferSize failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + + pcmBuf = malloc( pcmBufSize * sizeof( int16_t ) ); + +#endif /*-----------------------------------------------------------------* * Decoding @@ -807,10 +826,14 @@ int main( cleanup: +#ifdef FIX_847_OUTPUT_PCM_BUFFER + free( pcmBuf ); +#endif + #ifdef DEBUG_SBA_AUDIO_DUMP IVAS_DEC_GetSbaDebugParams( hIvasDec, &numOutChannels, &numTransportChannels, &pca_ingest_channels ); -#endif +#endif if ( arg.hrtfReaderEnabled ) { IVAS_DEC_HRTF_HANDLE hHrtfTD = NULL; diff --git a/lib_com/ivas_error.h b/lib_com/ivas_error.h index 48bbde5e2a..7bb27ee926 100644 --- a/lib_com/ivas_error.h +++ b/lib_com/ivas_error.h @@ -65,6 +65,9 @@ typedef enum IVAS_ERR_INVALID_FEC_CONFIG, IVAS_ERR_INVALID_FEC_OFFSET, IVAS_ERR_INVALID_INPUT_BUFFER_SIZE, +#ifdef FIX_847_OUTPUT_PCM_BUFFER + IVAS_ERR_INVALID_OUTPUT_BUFFER_SIZE, +#endif IVAS_ERR_DTX_NOT_SUPPORTED, IVAS_ERR_UNEXPECTED_NULL_POINTER, IVAS_ERR_METADATA_NOT_EXPECTED, @@ -219,6 +222,10 @@ static inline const char *ivas_error_to_string( ivas_error error_code ) return "Invalid FEC offset"; case IVAS_ERR_INVALID_INPUT_BUFFER_SIZE: return "Invalid input buffer size"; +#ifdef FIX_847_OUTPUT_PCM_BUFFER + case IVAS_ERR_INVALID_OUTPUT_BUFFER_SIZE: + return "Invalid output buffer size"; +#endif case IVAS_ERR_DTX_NOT_SUPPORTED: return "DTX is not supported in this IVAS format and element mode"; case IVAS_ERR_UNEXPECTED_NULL_POINTER: diff --git a/lib_com/options.h b/lib_com/options.h index 2f14642cf5..71dd252530 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -166,7 +166,7 @@ #define FIX_812_DOUBLE_PREC_MCT /* FhG: Issue 812: Avoid double precision in MCT */ #define FIX_807_VARIABLE_SPEED_DECODING /* FhG: Issue 807: Resolve "Variable Speed Decoding broken" */ #define FIX_818_DOUBLE_PREC_KERNEN_SW /* FhG: Issue 818: Avoid double precision in kernel switching */ - +#define FIX_847_OUTPUT_PCM_BUFFER /* VA: issue 847: Allocate decoder output PCM buffer dynamically */ /* #################### End BE switches ################################## */ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 27839b824a..d7f1c742d1 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1423,6 +1423,72 @@ ivas_error IVAS_DEC_GetFormat( } +#ifdef FIX_847_OUTPUT_PCM_BUFFER +/*---------------------------------------------------------------------* + * getInputBufferSize() + * + * + *---------------------------------------------------------------------*/ + +static int16_t getOutputBufferSize( + const Decoder_Struct *st_ivas /* i : IVAS decoder handle */ +) +{ + if ( st_ivas->hDecoderConfig == NULL ) + { + return -1; + } + + if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) + { + return (int16_t) ( st_ivas->hDecoderConfig->output_Fs * ( IVAS_MAX_OUTPUT_CHANNELS + IVAS_MAX_NUM_OBJECTS ) / FRAMES_PER_SEC ); + } + else if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) + { + if ( st_ivas->hLsSetupCustom == NULL ) + { + return -1; + } + + return (int16_t) ( st_ivas->hDecoderConfig->output_Fs * ( st_ivas->hLsSetupCustom->num_spk + st_ivas->hLsSetupCustom->num_lfe ) / FRAMES_PER_SEC ); + } + else + { + return (int16_t) ( st_ivas->hDecoderConfig->output_Fs * st_ivas->hDecoderConfig->nchan_out / FRAMES_PER_SEC ); + } +} + + +/*---------------------------------------------------------------------* + * IVAS_DEC_GetOutputBufferSize() + * + * + *---------------------------------------------------------------------*/ + +ivas_error IVAS_DEC_GetOutputBufferSize( + const IVAS_DEC_HANDLE hIvasDec, /* i : IVAS decoder handle */ + int16_t *outputBufferSize /* o : total number of samples expected in the output buffer for current decoder configuration */ +) +{ + if ( outputBufferSize == NULL || hIvasDec == NULL || hIvasDec->st_ivas == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + *outputBufferSize = getOutputBufferSize( hIvasDec->st_ivas ); + + if ( *outputBufferSize == -1 ) + { + return IVAS_ERR_INVALID_OUTPUT_BUFFER_SIZE; + } + else + { + return IVAS_ERR_OK; + } +} +#endif + + /*---------------------------------------------------------------------* * IVAS_DEC_GetNumOutputChannels( ) * diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index f541e49d63..2a730ea083 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -360,6 +360,14 @@ ivas_error IVAS_DEC_GetFormat( IVAS_DEC_BS_FORMAT *format /* o : format detected from bitstream fed to the decoder */ ); +#ifdef FIX_847_OUTPUT_PCM_BUFFER +/*! r: error code */ +ivas_error IVAS_DEC_GetOutputBufferSize( + const IVAS_DEC_HANDLE hIvasDec, /* i : IVAS decoder handle */ + int16_t *outputBufferSize /* o : total number of samples expected in the output buffer for current decoder configuration */ +); +#endif + /*! r: error code */ ivas_error IVAS_DEC_GetNumOutputChannels( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ -- GitLab