Commit 745cf829 authored by Adam Mills's avatar Adam Mills
Browse files

Merge branch '698-Fix-SBA-MSAN-issue-properly' into 'main'

[Non-BE] Fixing the SBA MSAN issue properly, with non-BE Switch in the right place

See merge request !986
parents 0b3fbb86 bc8e22fa
Loading
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -4522,8 +4522,11 @@ void ivas_spar_update_md_hist(
);

int16_t ivas_spar_chk_zero_coefs(
    Decoder_Struct *st_ivas,                                    /* i/o: IVAS decoder handle                     */
    Decoder_Struct *st_ivas                                    /* i/o: IVAS decoder handle                     */
#ifndef NONBE_FIX_698_SBA_MSAN
    ,
    const int16_t sba_order                                     /* i  : Ambisonic (SBA) order                   */
#endif
);

void ivas_spar_smooth_md_dtx(
@@ -4929,9 +4932,7 @@ void ivas_copy_band_coeffs_idx_to_arr(

void ivas_clear_band_coeffs( 
    ivas_band_coeffs_t *pband_coeffs,
    const uint16_t num_bands,
    const uint16_t num_ts

    const uint16_t num_bands
);

void ivas_clear_band_coeff_idx( 
+9 −14
Original line number Diff line number Diff line
@@ -293,23 +293,18 @@ void ivas_copy_band_coeffs_idx_to_arr(

void ivas_clear_band_coeffs(
    ivas_band_coeffs_t *pband_coeffs,
    const uint16_t num_bands,
    const uint16_t num_ts )
    const uint16_t num_bands )
{
    uint16_t i, j;
    uint16_t i;

    for ( j = 0; j < num_ts; j++ )
    {
    for ( i = 0; i < num_bands; i++ )
    {
            set_zero( (float *) pband_coeffs[i + j * num_bands].C_re, ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) );
            set_zero( (float *) pband_coeffs[i + j * num_bands].P_re, ( IVAS_SPAR_MAX_CH - 1 ) );
            set_zero( (float *) pband_coeffs[i + j * num_bands].C_quant_re, ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) );
            set_zero( (float *) pband_coeffs[i + j * num_bands].P_quant_re, ( IVAS_SPAR_MAX_CH - 1 ) );
            set_zero( pband_coeffs[i + j * num_bands].pred_re, ( IVAS_SPAR_MAX_CH - 1 ) );

            set_zero( pband_coeffs[i + j * num_bands].pred_quant_re, ( IVAS_SPAR_MAX_CH - 1 ) );
        }
        set_zero( (float *) pband_coeffs[i].C_re, ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) );
        set_zero( (float *) pband_coeffs[i].P_re, ( IVAS_SPAR_MAX_CH - 1 ) );
        set_zero( (float *) pband_coeffs[i].C_quant_re, ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) );
        set_zero( (float *) pband_coeffs[i].P_quant_re, ( IVAS_SPAR_MAX_CH - 1 ) );
        set_zero( pband_coeffs[i].pred_re, ( IVAS_SPAR_MAX_CH - 1 ) );
        set_zero( pband_coeffs[i].pred_quant_re, ( IVAS_SPAR_MAX_CH - 1 ) );
    }

    return;
+1 −0
Original line number Diff line number Diff line
@@ -175,6 +175,7 @@
#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.*/
#define NONBE_FIX_729_ASAN_2ISM_ACELP                         /* VA: issue 729: fix ASAN ACELP errors with 2 ISM coding using LTV */
#define NONBE_FIX_698_SBA_MSAN                                /* Dlb: issue 698: Uninitialized memory read in SBA init */
#define NONBE_FIX_694_OMASA_ACELP                             /* Nokia: Issue #694: OMASA crash in ACELP with extreme item */
#define NONBE_FIX_770_PLANAR_SBA_JBM                          /* FhG  : Issue #770: Crash in planar FOA decoding with JBM caused by uninitialized value */
#define NONBE_FIX_760_COHERENCE_MASA                          /* Nokia: Issue 760: fixes decoder crash for some cases when all energy ratios are 1 */
+47 −17
Original line number Diff line number Diff line
@@ -498,7 +498,7 @@ ivas_error ivas_spar_md_dec_init(
)
{
    int16_t i, j;
    int16_t nchan_transport, num_md_sub_frames;
    int16_t nchan_transport;
    float pFC[IVAS_MAX_NUM_BANDS], PR_minmax[2];

    ivas_sba_get_spar_hoa_md_flag( sba_order, hDecoderConfig->ivas_total_brate, &hMdDec->spar_hoa_md_flag, &hMdDec->spar_hoa_dirac2spar_md_flag );
@@ -541,9 +541,7 @@ ivas_error ivas_spar_md_dec_init(
    hMdDec->spar_plc_enable_fadeout_flag = 1;
    hMdDec->dtx_md_smoothing_cntr = 1;

    num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, hDecoderConfig->ivas_total_brate, hDecoderConfig->ivas_total_brate );

    ivas_clear_band_coeffs( hMdDec->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS, num_md_sub_frames );
    ivas_clear_band_coeffs( hMdDec->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS );
    ivas_clear_band_coeff_idx( hMdDec->spar_md.band_coeffs_idx, IVAS_MAX_NUM_BANDS );
    ivas_clear_band_coeff_idx( hMdDec->spar_md_prev.band_coeffs_idx, IVAS_MAX_NUM_BANDS );
    ivas_clear_band_coeff_idx( hMdDec->spar_md_prev.band_coeffs_idx_mapped, IVAS_MAX_NUM_BANDS );
@@ -638,8 +636,11 @@ static ivas_error ivas_spar_set_dec_config(
 *-----------------------------------------------------------------------------------------*/

static void ivas_dec_mono_sba_handling(
    Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle                                */
    Decoder_Struct *st_ivas /* i/o: IVAS decoder handle                                 */
#ifndef NONBE_FIX_698_SBA_MSAN
    ,
    const int16_t sba_order /* i  : Ambisonic (SBA) order                              */
#endif
)
{
    int16_t mono_flag, b, block;
@@ -663,7 +664,11 @@ static void ivas_dec_mono_sba_handling(
        }
    }
/* Combine the SPAR prediction coefs flag with the azimuth, elevation and energy ratio flag.*/
#ifdef NONBE_FIX_698_SBA_MSAN
    mono_flag = mono_flag && ivas_spar_chk_zero_coefs( st_ivas );
#else
    mono_flag = mono_flag && ivas_spar_chk_zero_coefs( st_ivas, sba_order );
#endif

    if ( mono_flag )
    {
@@ -748,7 +753,11 @@ void ivas_spar_md_dec_process(
    ivas_spar_dec_parse_md_bs( hMdDec, st0, &nB, &bw, &dtx_vad, st_ivas->hDecoderConfig->ivas_total_brate,
                               st_ivas->hQMetaData->sba_inactive_mode, st_ivas->last_active_ivas_total_brate );

#ifdef NONBE_FIX_698_SBA_MSAN
    ivas_dec_mono_sba_handling( st_ivas );
#else
    ivas_dec_mono_sba_handling( st_ivas, sba_order );
#endif

    /* SPAR to DirAC conversion */
    if ( hMdDec->spar_hoa_dirac2spar_md_flag == 1 )
@@ -860,31 +869,42 @@ void ivas_spar_md_dec_process(
 *-----------------------------------------------------------------------------------------*/

int16_t ivas_spar_chk_zero_coefs(
    Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle        */
    Decoder_Struct *st_ivas /* i/o: IVAS decoder handle        */
#ifndef NONBE_FIX_698_SBA_MSAN
    ,
    const int16_t sba_order /* i  : Ambisonic (SBA) order      */
#endif
)
{
#ifdef NONBE_FIX_698_SBA_MSAN
    int16_t j, k, b;
#else
    int16_t j, k, b, i_ts;
    ivas_spar_md_dec_state_t *hMdDec;
    int16_t num_md_sub_frames;
#endif
    ivas_spar_md_dec_state_t *hMdDec;
    int16_t mono = 1;
    int16_t ndec, ndm;

    hMdDec = st_ivas->hSpar->hMdDec;

    num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, st_ivas->hDecoderConfig->ivas_total_brate,
                                                            st_ivas->last_active_ivas_total_brate );

    ndec = hMdDec->spar_md_cfg.num_decorr_per_band[0];
    ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[0];

#ifndef NONBE_FIX_698_SBA_MSAN
    num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, st_ivas->hDecoderConfig->ivas_total_brate,
                                                            st_ivas->last_active_ivas_total_brate );
    for ( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ )
    {
#endif
        for ( b = 0; b < min( hMdDec->spar_md.num_bands, SPAR_DIRAC_SPLIT_START_BAND ); b++ )
        {
            for ( j = 0; j < ndm + ndec - 1; j++ )
            {
#ifdef NONBE_FIX_698_SBA_MSAN
                if ( hMdDec->spar_md.band_coeffs[b].pred_re[j] != 0.0f )
#else
            if ( hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re[j] != 0.0f )
#endif
                {
                    mono = 0;
                }
@@ -893,7 +913,11 @@ int16_t ivas_spar_chk_zero_coefs(
            {
                for ( k = 0; k < ndm - 1; k++ )
                {
#ifdef NONBE_FIX_698_SBA_MSAN
                    if ( hMdDec->spar_md.band_coeffs[b].C_re[j][k] != 0.0f )
#else
                if ( hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re[j][k] != 0.0f )
#endif
                    {
                        mono = 0;
                    }
@@ -901,13 +925,19 @@ int16_t ivas_spar_chk_zero_coefs(
            }
            for ( j = 0; j < ndec; j++ )
            {
#ifdef NONBE_FIX_698_SBA_MSAN
                if ( hMdDec->spar_md.band_coeffs[b].P_re[j] != 0.0f )
#else
            if ( hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re[j] != 0.0f )
#endif
                {
                    mono = 0;
                }
            }
        }
#ifndef NONBE_FIX_698_SBA_MSAN
    }
#endif
    return mono;
}

+1 −1
Original line number Diff line number Diff line
@@ -303,7 +303,7 @@ ivas_error ivas_spar_md_enc_init(
        }
    }

    ivas_clear_band_coeffs( hMdEnc->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS, 1 );
    ivas_clear_band_coeffs( hMdEnc->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS );
    ivas_clear_band_coeff_idx( hMdEnc->spar_md.band_coeffs_idx, IVAS_MAX_NUM_BANDS );
    ivas_clear_band_coeff_idx( hMdEnc->spar_md_prior.band_coeffs_idx, IVAS_MAX_NUM_BANDS );
    ivas_clear_band_coeff_idx( hMdEnc->spar_md_prior.band_coeffs_idx_mapped, IVAS_MAX_NUM_BANDS );