From 610756a20429b2e9660b9c9219a0b6364e0f0cf1 Mon Sep 17 00:00:00 2001 From: Kacper Sagnowski Date: Tue, 26 Aug 2025 11:05:47 +0200 Subject: [PATCH 1/2] Manually revert commit that caused assert to be triggered in JBM during rate switching --- lib_com/options.h | 1 + lib_dec/ivas_ism_dec.c | 21 +++++++++++++++++++++ lib_dec/ivas_masa_dec.c | 19 +++++++++++++++++++ lib_dec/ivas_mct_dec.c | 21 +++++++++++++++++++++ lib_dec/ivas_sba_dec.c | 22 ++++++++++++++++++++++ lib_dec/lib_dec.c | 2 ++ 6 files changed, 86 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index 42f17f9081..90f3950615 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -182,6 +182,7 @@ #define NONBE_SVD_OPTIMIZATION #define NONBE_1328_FIX_NON_LINEARITY /* VA: Fix possible issue when computing bwe_exc_extended and previous frame were almost 0 */ +#define NONBE_1321_JBM_ASSERT_BITRATE_SWITCHING /* FhG: Fix assert being hit in JBM code during rate switching */ /* ##################### End NON-BE switches ########################### */ /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index 6e46c4b89d..000b5f6ca5 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -128,6 +128,25 @@ static ivas_error ivas_ism_bitrate_switching_dec( mvs2s( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } +#ifdef NONBE_1321_JBM_ASSERT_BITRATE_SWITCHING + /* JBM: when granularity goes down (e.g. Discrete ISM with TD Obj Renderer -> ParamISM with binaural fastconv + render what still fits in the new granularity */ + tc_granularity_new = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, RENDERER_DISABLE, st_ivas->hDecoderConfig->output_Fs ); + + if ( tc_granularity_new < st_ivas->hTcBuffer->n_samples_granularity ) + { + /* flush already done in IVAS_DEC_ReadFormat() */ + } + /* JBM: when granularity goes up set samples to discard at the beginning of the frame */ + else if ( tc_granularity_new > st_ivas->hTcBuffer->n_samples_granularity ) + { + if ( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + +#endif if ( st_ivas->ism_mode != last_ism_mode ) { /* EFAP handle */ @@ -295,7 +314,9 @@ static ivas_error ivas_ism_bitrate_switching_dec( tc_nchan_tc_new = ivas_jbm_dec_get_num_tc_channels( st_ivas ); tc_nchan_allocate_new = tc_nchan_tc_new; tc_nchan_full_new = tc_nchan_tc_new; +#ifndef NONBE_1321_JBM_ASSERT_BITRATE_SWITCHING tc_granularity_new = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, RENDERER_DISABLE, st_ivas->hDecoderConfig->output_Fs ); +#endif if ( st_ivas->ism_mode == ISM_MODE_PARAM && ( st_ivas->renderer_type != RENDERER_MONO_DOWNMIX && st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) { diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 6886d550a8..5f4634c383 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -1509,6 +1509,25 @@ ivas_error ivas_masa_dec_reconfigure( tc_nchan_to_allocate = 2 * BINAURAL_CHANNELS; } } +#ifdef NONBE_1321_JBM_ASSERT_BITRATE_SWITCHING + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC && st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + if ( n_samples_granularity > st_ivas->hTcBuffer->n_samples_granularity ) + { + if ( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + else if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC && st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + { + if ( n_samples_granularity < st_ivas->hTcBuffer->n_samples_granularity ) + { + /* flush already done in IVAS_DEC_ReadFormat() */ + } + } +#endif } else if ( st_ivas->nchan_transport == 1 && ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) ) { diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 84bf52456d..d7639e8ce5 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -795,6 +795,25 @@ static ivas_error ivas_mc_dec_reconfig( } } +#ifdef NONBE_1321_JBM_ASSERT_BITRATE_SWITCHING + /* JBM: when granularity goes down (e.g. MCT with CREND -> ParamMC with binaural fastconv + render what still fits in the new granularity */ + tc_granularity_new = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, RENDERER_DISABLE, st_ivas->hDecoderConfig->output_Fs ); + + if ( tc_granularity_new < st_ivas->hTcBuffer->n_samples_granularity ) + { + /* flush already done in IVAS_DEC_ReadFormat() */ + } + /* JBM: when granularity goes up set samples to discard at the beginning of the frame */ + else if ( tc_granularity_new > st_ivas->hTcBuffer->n_samples_granularity ) + { + if ( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + +#endif if ( st_ivas->mc_mode == MC_MODE_MCT ) { st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ) ); @@ -1303,7 +1322,9 @@ static ivas_error ivas_mc_dec_reconfig( tc_nchan_tc_new = ivas_jbm_dec_get_num_tc_channels( st_ivas ); tc_nchan_allocate_new = tc_nchan_tc_new; tc_nchan_full_new = tc_nchan_tc_new; +#ifndef NONBE_1321_JBM_ASSERT_BITRATE_SWITCHING tc_granularity_new = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, RENDERER_DISABLE, st_ivas->hDecoderConfig->output_Fs ); +#endif if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) { diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index abeb19243d..a11fb37d54 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -173,6 +173,27 @@ ivas_error ivas_sba_dec_reconfigure( /* determine new granularity */ granularity_new = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, ivas_renderer_secondary_select( st_ivas ), st_ivas->hDecoderConfig->output_Fs ); +#ifdef NONBE_1321_JBM_ASSERT_BITRATE_SWITCHING + /* flush renderer on granularity change form 5ms to 1.25ms, again only possible for binaural rendering */ + if ( granularity_new < st_ivas->hTcBuffer->n_samples_granularity ) + { + /* flush already done in IVAS_DEC_ReadFormat() */ + } + else if ( granularity_new > st_ivas->hTcBuffer->n_samples_granularity ) + { + if ( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* make sure the changed number of slots in the last subframe is not lost in the following steps */ + if ( st_ivas->hSpatParamRendCom != NULL ) + { + st_ivas->hSpatParamRendCom->subframe_nbslots[st_ivas->hSpatParamRendCom->nb_subframes - 1] = st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1]; + } + st_ivas->hSpar->subframe_nbslots[st_ivas->hSpar->nb_subframes - 1] = st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1]; + } +#else if ( granularity_new > st_ivas->hTcBuffer->n_samples_granularity ) { /* make sure the changed number of slots in the last subframe is not lost in the following steps */ @@ -182,6 +203,7 @@ ivas_error ivas_sba_dec_reconfigure( } st_ivas->hSpar->subframe_nbslots[st_ivas->hSpar->nb_subframes - 1] = st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1]; } +#endif } /* save old */ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 0e04971fc3..41feeafec2 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1080,6 +1080,7 @@ ivas_error IVAS_DEC_ReadFormat( return error; } } +#ifndef NONBE_1321_JBM_ASSERT_BITRATE_SWITCHING /* when granularity goes up, discard samples at the beginning of the frame */ else if ( tc_granularity_new > st_ivas->hTcBuffer->n_samples_granularity ) { @@ -1088,6 +1089,7 @@ ivas_error IVAS_DEC_ReadFormat( return error; } } +#endif } } -- GitLab From 3d52d0a9fae5e760532cee1e6b6180660d1c3ea5 Mon Sep 17 00:00:00 2001 From: Kacper Sagnowski Date: Tue, 26 Aug 2025 15:26:00 +0200 Subject: [PATCH 2/2] Fix formatting --- lib_dec/ivas_mct_dec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index d7639e8ce5..2ea644dbd2 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -796,8 +796,8 @@ static ivas_error ivas_mc_dec_reconfig( } #ifdef NONBE_1321_JBM_ASSERT_BITRATE_SWITCHING - /* JBM: when granularity goes down (e.g. MCT with CREND -> ParamMC with binaural fastconv - render what still fits in the new granularity */ + /* JBM: when granularity goes down (e.g. MCT with CREND -> ParamMC with binaural fastconv + render what still fits in the new granularity */ tc_granularity_new = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, RENDERER_DISABLE, st_ivas->hDecoderConfig->output_Fs ); if ( tc_granularity_new < st_ivas->hTcBuffer->n_samples_granularity ) -- GitLab