From 9efc75cc1fa2bf7cdcd94dd3bb0a8336c04253b5 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 14 Oct 2025 09:25:21 +0200 Subject: [PATCH 1/2] port NONBE_1293_CRASH_FIRST_FRAME_LOST --- apps/isar_post_rend.c | 22 +++++++++- lib_com/options.h | 1 + lib_dec/lib_dec.c | 54 +++++++++++++++++++++---- lib_isar/lib_isar_post_rend.c | 12 ++++++ lib_util/split_render_file_read_write.c | 17 ++++++++ lib_util/split_render_file_read_write.h | 9 +++++ 6 files changed, 106 insertions(+), 9 deletions(-) diff --git a/apps/isar_post_rend.c b/apps/isar_post_rend.c index 92d9e1f0a..fc93d9375 100644 --- a/apps/isar_post_rend.c +++ b/apps/isar_post_rend.c @@ -953,6 +953,9 @@ int main( while ( 1 ) { +#ifdef NONBE_1293_CRASH_FIRST_FRAME_LOST + int16_t bfi = 0; +#endif int16_t num_in_channels; num_in_channels = inBuffer.config.numChannels; @@ -961,7 +964,11 @@ int main( { ivas_error error_tmp; numSamplesRead = (int16_t) inBufferSize; +#ifdef NONBE_1293_CRASH_FIRST_FRAME_LOST + error_tmp = split_rend_read_bits_from_file( hSplitRendFileReadWrite, bitsBuffer.bits, &bitsBuffer.config.bitsRead, &bitsBuffer.config.bitsWritten, &bfi ); +#else error_tmp = split_rend_read_bits_from_file( hSplitRendFileReadWrite, bitsBuffer.bits, &bitsBuffer.config.bitsRead, &bitsBuffer.config.bitsWritten ); +#endif if ( error_tmp != IVAS_ERR_OK ) { if ( error_tmp == IVAS_ERR_END_OF_FILE ) @@ -1028,19 +1035,32 @@ int main( /* Read from split renderer bfi file if specified */ if ( splitRendBFIReader != NULL && splitBinNeedsNewFrame ) { +#ifndef NONBE_1293_CRASH_FIRST_FRAME_LOST int16_t bfi; +#endif if ( ( error = SplitRendBFIFileReading( splitRendBFIReader, &bfi ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError in SplitRendBFIFileReading(): %s\n", ivas_error_to_string( error ) ); goto cleanup; } - +#ifndef NONBE_1293_CRASH_FIRST_FRAME_LOST + if ( ( error = ISAR_POST_REND_SetSplitRendBFI( hIsarPostRend, bfi ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError in ISAR_POST_REND_SetSplitRendBFI(): %s\n", ivas_error_to_string( error ) ); + goto cleanup; + } +#endif + } +#ifdef NONBE_1293_CRASH_FIRST_FRAME_LOST + if ( splitBinNeedsNewFrame ) + { if ( ( error = ISAR_POST_REND_SetSplitRendBFI( hIsarPostRend, bfi ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError in ISAR_POST_REND_SetSplitRendBFI(): %s\n", ivas_error_to_string( error ) ); goto cleanup; } } +#endif for ( i = 0; i < args.inConfig.numBinBuses; ++i ) { diff --git a/lib_com/options.h b/lib_com/options.h index 53f000e8f..be5ac3943 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -209,6 +209,7 @@ #define FIX_1349_TNS_CRASH /* FhG: Fix crash in TNS entropy coding, in case order of joint TNS coding is reduced to 0 */ #define NONBE_FIX_1180_HQMDCT_PHECU_LT_MUTING /* Ericsson: issue 1180, corrected long term mute loop attnuation after 200ms in PhECU-PLC */ #define NONBE_1200_ISM_JBM_BRATE_SW_FLUSH /* VA: issue 1200: fix bug in renderer flush in ISM JBM bitrate switching */ +#define NONBE_1293_CRASH_FIRST_FRAME_LOST /* VA: issue 1293: fix G.192 decoder crash when first frame is lost */ #define FIX_1384_MSAN_stereo_tcx_core_enc /* VA: issue 1384: fix use-of-uninitialized value in stereo_tcx_core_enc() */ // object-editing feature porting diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 6f0567d16..045b23e0b 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1270,6 +1270,13 @@ ivas_error IVAS_DEC_GetSamplesDecoder( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } +#ifdef NONBE_1293_CRASH_FIRST_FRAME_LOST + if ( !hIvasDec->hasBeenFedFirstGoodFrame && !hIvasDec->isInitialized ) /* note: 'isInitialized' is related to EVS decoder */ + { + return IVAS_ERR_OK; + } +#endif + /* If TSM is generally enabled, we have to wait for the first good frame. Otherwise, we directly decode the first frame in any case. */ #ifdef FIX_HRTF_LOAD @@ -1428,6 +1435,15 @@ ivas_error IVAS_DEC_GetEditableParameters( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } +#ifdef NONBE_1293_CRASH_FIRST_FRAME_LOST + if ( !hIvasDec->hasBeenFedFirstGoodFrame ) + { + hIvasEditableParameters->num_obj = 0; + + return IVAS_ERR_OK; + } +#endif + hIvasEditableParameters->gain_bed = 1.0f; hIvasEditableParameters->num_obj = hIvasDec->st_ivas->nchan_ism; if ( hIvasDec->st_ivas->ivas_format == ISM_FORMAT || hIvasDec->st_ivas->ivas_format == SBA_ISM_FORMAT ) @@ -1501,6 +1517,13 @@ ivas_error IVAS_DEC_SetEditableParameters( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } +#ifdef NONBE_1293_CRASH_FIRST_FRAME_LOST + if ( !hIvasDec->hasBeenFedFirstGoodFrame ) + { + return IVAS_ERR_OK; + } +#endif + error = IVAS_ERR_OK; #ifdef DEBUGGING @@ -1557,18 +1580,21 @@ ivas_error IVAS_DEC_SetEditableParameters( ivas_error IVAS_DEC_PrepareRenderer( IVAS_DEC_HANDLE hIvasDec ) { - ivas_error error; - - error = IVAS_ERR_OK; - - if ( hIvasDec == NULL ) + if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - ivas_jbm_dec_prepare_renderer( hIvasDec->st_ivas ); +#ifdef NONBE_1293_CRASH_FIRST_FRAME_LOST + if ( hIvasDec->hasBeenFedFirstGoodFrame || hIvasDec->isInitialized ) /* note: 'isInitialized' is related to EVS decoder */ +#endif + { + ivas_jbm_dec_prepare_renderer( hIvasDec->st_ivas ); + } + hIvasDec->hasBeenPreparedRendering = true; - return error; + + return IVAS_ERR_OK; } #endif @@ -1797,11 +1823,16 @@ ivas_error IVAS_DEC_GetSamples( { *needNewFrame = false; } + +#ifdef NONBE_1293_CRASH_FIRST_FRAME_LOST + *nOutSamples = nSamplesRendered; +#endif } } +#ifndef NONBE_1293_CRASH_FIRST_FRAME_LOST *nOutSamples = nSamplesRendered; - +#endif return IVAS_ERR_OK; } @@ -1909,6 +1940,13 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( return error; } +#ifdef NONBE_1293_CRASH_FIRST_FRAME_LOST + if ( !hIvasDec->hasBeenFedFirstGoodFrame ) + { + return IVAS_ERR_OK; + } +#endif + /* change buffer layout */ for ( i = 0; i < numSamplesPerChannelToDecode; ++i ) { diff --git a/lib_isar/lib_isar_post_rend.c b/lib_isar/lib_isar_post_rend.c index 8b946834d..6f2ea96d9 100644 --- a/lib_isar/lib_isar_post_rend.c +++ b/lib_isar/lib_isar_post_rend.c @@ -1545,6 +1545,18 @@ static ivas_error renderSplitBinauralWithPostRot( } else { +#ifdef NONBE_1293_CRASH_FIRST_FRAME_LOST + if ( splitBinInput->numCachedSamples == 0 ) + { + numSamplesPerChannelCacheSize = (int16_t) ( *splitBinInput->base.ctx.pOutSampleRate * bits.isar_frame_size_ms / 1000 ) - outAudio.config.numSamplesPerChannel; + splitBinInput->numCachedSamples = numSamplesPerChannelCacheSize; + } + else + { + splitBinInput->numCachedSamples -= outAudio.config.numSamplesPerChannel; + } +#endif + if ( splitBinInput->base.inConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) { for ( ch_idx = 0; ch_idx < BINAURAL_CHANNELS; ch_idx++ ) diff --git a/lib_util/split_render_file_read_write.c b/lib_util/split_render_file_read_write.c index f57721edb..4a72bc4d3 100644 --- a/lib_util/split_render_file_read_write.c +++ b/lib_util/split_render_file_read_write.c @@ -323,11 +323,20 @@ ivas_error split_rend_write_bitstream_to_file( * *-----------------------------------------------------------------------------------------*/ +#ifdef NONBE_1293_CRASH_FIRST_FRAME_LOST +ivas_error split_rend_read_bits_from_file( + SplitFileReadWrite *hSplitRendFileReadWrite, + uint8_t *bits, + int32_t *bits_read, + int32_t *bits_written, + int16_t *bfi ) +#else ivas_error split_rend_read_bits_from_file( SplitFileReadWrite *hSplitRendFileReadWrite, uint8_t *bits, int32_t *bits_read, int32_t *bits_written ) +#endif { char header[SPLIT_RENDERER_FRAME_HEADER_LEN] = "SPLIT_FRAME"; char header_read[SPLIT_RENDERER_FRAME_HEADER_LEN]; @@ -391,6 +400,14 @@ ivas_error split_rend_read_bits_from_file( *bits_read = 0; *bits_written = bit_len; +#ifdef NONBE_1293_CRASH_FIRST_FRAME_LOST + *bfi = 0; + if ( bit_len == 0 ) + { + *bfi = 1; + } +#endif + return IVAS_ERR_OK; } diff --git a/lib_util/split_render_file_read_write.h b/lib_util/split_render_file_read_write.h index 2895dd426..294d2efa1 100644 --- a/lib_util/split_render_file_read_write.h +++ b/lib_util/split_render_file_read_write.h @@ -75,11 +75,20 @@ ivas_error split_rend_write_bitstream_to_file( int32_t *bits_written ); /* read split rend coded bits from file */ +#ifdef NONBE_1293_CRASH_FIRST_FRAME_LOST +ivas_error split_rend_read_bits_from_file( + SplitFileReadWrite *hSplitRendFileReadWrite, + uint8_t *bits, + int32_t *bits_read, + int32_t *bits_written, + int16_t *bfi ); +#else ivas_error split_rend_read_bits_from_file( SplitFileReadWrite *hSplitRendFileReadWrite, uint8_t *bits, int32_t *bits_read, int32_t *bits_written ); +#endif /* read split pre rend delay */ ivas_error split_rend_read_pre_rend_delay_ns( -- GitLab From 0f63ac97ad7b48b0c5e73774d63dfab5ff619ea7 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 14 Oct 2025 10:37:45 +0200 Subject: [PATCH 2/2] port NONBE_1293_CRASH_FIRST_FRAME_LOST, !2071 part --- lib_dec/lib_dec.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 045b23e0b..fbf7c729b 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1683,14 +1683,20 @@ ivas_error IVAS_DEC_GetSamples( { hIvasDec->hasBeenFedFrame = false; set_s( pcmBuf, 0, hIvasDec->st_ivas->hDecoderConfig->nchan_out * nSamplesAsked ); +#ifdef NONBE_1293_CRASH_FIRST_FRAME_LOST + nSamplesRendered = nSamplesAsked; +#else hIvasDec->nSamplesRendered += nSamplesAsked; *nOutSamples = nSamplesAsked; +#endif hIvasDec->nSamplesAvailableNext -= nSamplesAsked; +#ifndef NONBE_1293_CRASH_FIRST_FRAME_LOST if ( hIvasDec->nSamplesAvailableNext == 0 ) { hIvasDec->needNewFrame = true; *needNewFrame = true; } +#endif } else { @@ -1813,6 +1819,7 @@ ivas_error IVAS_DEC_GetSamples( } nSamplesRendered += nSamplesRendered_loop; +#ifndef NONBE_1293_CRASH_FIRST_FRAME_LOST nSamplesToRender -= nSamplesRendered_loop; if ( hIvasDec->nSamplesAvailableNext == 0 ) { @@ -1823,16 +1830,24 @@ ivas_error IVAS_DEC_GetSamples( { *needNewFrame = false; } - -#ifdef NONBE_1293_CRASH_FIRST_FRAME_LOST - *nOutSamples = nSamplesRendered; #endif } } -#ifndef NONBE_1293_CRASH_FIRST_FRAME_LOST - *nOutSamples = nSamplesRendered; +#ifdef NONBE_1293_CRASH_FIRST_FRAME_LOST + if ( hIvasDec->nSamplesAvailableNext == 0 ) + { + *needNewFrame = true; + hIvasDec->needNewFrame = true; + } + else + { + *needNewFrame = false; + } #endif + + *nOutSamples = nSamplesRendered; + return IVAS_ERR_OK; } -- GitLab