Commit e9d17711 authored by multrus's avatar multrus
Browse files

[cleanup] accept NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC

parent 05f93dc7
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -163,7 +163,6 @@
/* all switches in this category should start with "NONBE_" */

#define NONBE_FIX_856_TCX_LTP_SYNTH_FILTER                    /* FhG: issue 856: correct filtering length for tcx-ltp synth filtering*/
#define NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC                /* DLB: issue 862 : UBSAN: out-of-bound error in SPAR for OSBA bitrate switching with PLC*/
#define NONBE_FIX_DISCRETE_ISM_NOISE_SEED_HANDLING            /* FhG: fix handling of common and differing noise seeds in SCEs for ISM DTX */
#define NONBE_FIX_913_OMASA_BITBUDGET_VIOLATION               /* VA/Nok: issue 913: Resolve "Crash in OMASA encoder - DFT-Stereo bit-budget violated" */
#define NONBE_FIX_855_JBM_FLUSH_OFFSET                        /* FhG: issue #855: add missing switch here for the code in JBM flushing                 */
+0 −8
Original line number Diff line number Diff line
@@ -64,10 +64,8 @@ ivas_error ivas_corecoder_dec_reconfig(
    MC_MODE last_mc_mode;
    DECODER_CONFIG_HANDLE hDecoderConfig;
    ivas_error error;
#ifdef NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC
    int16_t prev_bfi;
    Decoder_State *st0;
#endif

    /*-----------------------------------------------------------------*
     * Initialization
@@ -145,10 +143,8 @@ ivas_error ivas_corecoder_dec_reconfig(
    }
    else
    {
#ifdef NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC
        st0 = ( nSCE_old > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0];
        prev_bfi = st0->prev_bfi;
#endif
        nSCE_existing = min( nSCE_old, st_ivas->nSCE );
        nCPE_existing = min( nCPE_old, st_ivas->nCPE );

@@ -221,9 +217,7 @@ ivas_error ivas_corecoder_dec_reconfig(
            {
                return error;
            }
#ifdef NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC
            st_ivas->hSCE[sce_id]->hCoreCoder[0]->prev_bfi = prev_bfi;
#endif
        }
        if ( st_ivas->sba_dirac_stereo_flag && sba_dirac_stereo_flag_old && st_ivas->nchan_transport == 1 && nSCE_old == 0 )
        {
@@ -252,10 +246,8 @@ ivas_error ivas_corecoder_dec_reconfig(
            {
                return error;
            }
#ifdef NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC
            st_ivas->hCPE[cpe_id]->hCoreCoder[0]->prev_bfi = prev_bfi;
            st_ivas->hCPE[cpe_id]->hCoreCoder[1]->prev_bfi = prev_bfi;
#endif
        }

        if ( st_ivas->nCPE > 1 && nCPE_old <= 1 )
+0 −158
Original line number Diff line number Diff line
@@ -76,9 +76,7 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix( ivas_spar_md_dec_state_

static void ivas_spar_md_fill_invalid_bands( ivas_spar_dec_matrices_t *pSpar_coeffs, ivas_spar_dec_matrices_t *pSpar_coeffs_prev, const int16_t *valid_bands, int16_t *base_band_age, const int16_t num_bands, const int16_t numch_out, const int16_t num_md_sub_frames );

#ifdef NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC
static void ivas_spar_md_fill_invalid_bandcoeffs( ivas_band_coeffs_t *pBand_coeffs, ivas_band_coeffs_t *pBand_coeffs_prev, const int16_t *valid_bands, int16_t *base_band_age, int16_t *first_valid_frame, const int16_t num_bands );
#endif
static ivas_error ivas_spar_set_dec_config( ivas_spar_md_dec_state_t *hMdDec, const int16_t nchan_transport, float *pFC );

static void ivas_parse_parameter_bitstream_dtx( ivas_spar_md_t *pSpar_md, Decoder_State *st, const int16_t bw, const int16_t num_bands, int16_t *num_dmx_per_band, int16_t *num_dec_per_band );
@@ -86,10 +84,6 @@ static void ivas_parse_parameter_bitstream_dtx( ivas_spar_md_t *pSpar_md, Decode
static ivas_error ivas_deindex_real_index( const int16_t *index, const int16_t q_levels, const float min_value, const float max_value, float *quant, const int16_t num_ch_dim2 );

static void ivas_spar_dec_parse_md_bs( ivas_spar_md_dec_state_t *hMdDec, Decoder_State *st, int16_t *nB, int16_t *bands_bw, int16_t *dtx_vad, const int32_t ivas_total_brate, const int16_t sba_inactive_mode
#ifndef NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC
                                       ,
                                       const int32_t last_active_brate
#endif
);


@@ -111,12 +105,10 @@ ivas_error ivas_spar_md_dec_matrix_open(
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for band_coeffs in SPAR MD" );
    }
#ifdef NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC
    if ( ( hMdDec->band_coeffs_prev = (ivas_band_coeffs_t *) malloc( IVAS_MAX_NUM_BANDS * sizeof( ivas_band_coeffs_t ) ) ) == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for band_coeffs in SPAR MD" );
    }
#endif
    if ( ( hMdDec->mixer_mat = (float ***) malloc( num_channels * sizeof( float ** ) ) ) == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" );
@@ -379,13 +371,11 @@ void ivas_spar_md_dec_matrix_close(
        free( hMdDecoder->spar_md.band_coeffs );
        hMdDecoder->spar_md.band_coeffs = NULL;
    }
#ifdef NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC
    if ( hMdDecoder->band_coeffs_prev != NULL )
    {
        free( hMdDecoder->band_coeffs_prev );
        hMdDecoder->band_coeffs_prev = NULL;
    }
#endif

    if ( hMdDecoder->mixer_mat != NULL )
    {
@@ -564,17 +554,13 @@ ivas_error ivas_spar_md_dec_init(
    /* initialize PLC state */
    set_s( hMdDec->valid_bands, 0, IVAS_MAX_NUM_BANDS );
    set_s( hMdDec->base_band_age, 0, IVAS_MAX_NUM_BANDS );
#ifdef NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC
    set_s( hMdDec->base_band_coeffs_age, 0, IVAS_MAX_NUM_BANDS );
#endif
    hMdDec->spar_plc_num_lost_frames = 0;
    hMdDec->spar_plc_enable_fadeout_flag = 1;
    hMdDec->dtx_md_smoothing_cntr = 1;

    ivas_clear_band_coeffs( hMdDec->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS );
#ifdef NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC
    ivas_clear_band_coeffs( hMdDec->band_coeffs_prev, IVAS_MAX_NUM_BANDS );
#endif
    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 );
@@ -598,9 +584,7 @@ ivas_error ivas_spar_md_dec_init(
            set_zero( hMdDec->mixer_mat_prev2[i][j], IVAS_MAX_NUM_BANDS );
        }
    }
#ifdef NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC
    hMdDec->first_valid_frame = 1;
#endif

    return IVAS_ERR_OK;
}
@@ -783,13 +767,8 @@ 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
#ifndef NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC
                               ,
                               st_ivas->last_active_ivas_total_brate
#endif
    );

#ifdef NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC
    assert( nB == hMdDec->spar_md.num_bands );
    assert( bw == 1 );
    ivas_spar_md_fill_invalid_bandcoeffs(
@@ -799,7 +778,6 @@ void ivas_spar_md_dec_process(
        &hMdDec->base_band_coeffs_age[0],
        &hMdDec->first_valid_frame,
        nB );
#endif

    ivas_dec_mono_sba_handling( st_ivas );

@@ -811,12 +789,6 @@ void ivas_spar_md_dec_process(

    /* set correct number of bands*/
    nB = IVAS_MAX_NUM_BANDS;
#ifndef NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC
    if ( bw == IVAS_RED_BAND_FACT )
    {
        nB = nB >> 1;
    }
#endif
#ifdef DEBUG_LBR_SBA
    /* Dumping SPAR Coefficients */
    char f_name[100];
@@ -888,17 +860,6 @@ void ivas_spar_md_dec_process(
        }
        fprintf( fid, "%.6f\n", hMdDec->mixer_mat[1][0][band] );
    }
#endif
#ifndef NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC
    if ( bw == IVAS_RED_BAND_FACT )
    {
        nB = nB << 1;
    }

    for ( b = nB; b < num_bands_out; b++ )
    {
        hMdDec->valid_bands[b] = 1;
    }
#endif
    ivas_spar_md_fill_invalid_bands( &hMdDec->spar_coeffs, &hMdDec->spar_coeffs_prev, &hMdDec->valid_bands[0], &hMdDec->base_band_age[0], num_bands_out, num_md_chs, num_md_sub_frames );

@@ -1512,7 +1473,6 @@ void ivas_spar_dec_gen_umx_mat(
    return;
}

#ifdef NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC
static void ivas_spar_md_band_upmix(
    ivas_band_coeffs_t *band_coeffs,
    int16_t *nB,
@@ -1554,7 +1514,6 @@ static void ivas_spar_md_band_upmix(

    return;
}
#endif

/*-----------------------------------------------------------------------------------------*
 * Function ivas_spar_dec_parse_md_bs()
@@ -1570,28 +1529,16 @@ static void ivas_spar_dec_parse_md_bs(
    int16_t *dtx_vad,
    const int32_t ivas_total_brate,
    const int16_t sba_inactive_mode
#ifndef NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC
    ,
    const int32_t last_active_brate
#endif
)
{
    int16_t i, j, k, num_bands;
#ifndef NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC
    int16_t ii, jj, ndec, ndm, b, idx;
#else
    int16_t ii, jj, ndec, ndm;
#endif
    uint16_t qsi;
    ivas_quant_strat_t qs;
    int16_t strat, no_ec;
    int16_t do_diff[IVAS_MAX_NUM_BANDS];
    float quant[IVAS_SPAR_MAX_C_COEFF];
    int16_t do_repeat[IVAS_MAX_NUM_BANDS];
#ifndef NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC
    int16_t bw_final, bw_fact;
    int32_t active_brate;
#endif
    *dtx_vad = 1;
    *bands_bw = 1;
    qsi = 0;
@@ -1663,7 +1610,6 @@ static void ivas_spar_dec_parse_md_bs(

        ivas_parse_parameter_bitstream_dtx( &hMdDec->spar_md, st0, *bands_bw, *nB, hMdDec->spar_md_cfg.num_dmx_chans_per_band, hMdDec->spar_md_cfg.num_decorr_per_band );

#ifdef NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC
        if ( *bands_bw != 1 )
        {
            ndec = hMdDec->spar_md_cfg.num_decorr_per_band[0];
@@ -1678,42 +1624,6 @@ static void ivas_spar_dec_parse_md_bs(
                ndm );
        }

#else
        active_brate = ( ivas_total_brate > IVAS_SID_5k2 ) ? ivas_total_brate : last_active_brate;

        if ( active_brate >= IVAS_24k4 )
        {
            bw_final = 1;
        }
        else
        {
            bw_final = 2;
        }

        bw_fact = *bands_bw / bw_final;

        for ( i = *nB - 1; i >= 0; i-- )
        {
            ndec = hMdDec->spar_md_cfg.num_decorr_per_band[bw_fact * i];

            for ( b = bw_fact - 1; b >= 0; b-- )
            {
                idx = i * bw_fact + b;
                for ( j = 0; j < FOA_CHANNELS - 1; j++ )
                {
                    hMdDec->spar_md.band_coeffs[idx].pred_re[j] = hMdDec->spar_md.band_coeffs[i].pred_re[j];
                }
                for ( j = 0; j < ndec; j++ )
                {
                    hMdDec->spar_md.band_coeffs[idx].P_re[j] = hMdDec->spar_md.band_coeffs[i].P_re[j];
                }
                hMdDec->valid_bands[idx] = 1;
            }
        }

        *bands_bw = bw_final;
        *nB = num_bands / bw_final;
#endif
        return;
    }

@@ -1765,14 +1675,10 @@ static void ivas_spar_dec_parse_md_bs(
            do_diff[i] = ( ( ( i + 1 ) & 3 ) != strat - 4 );
            do_repeat[i] = 0;
        }
#ifdef NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC
        if ( hMdDec->spar_md_cfg.prev_quant_idx >= 0 )
        {
#endif
            ivas_map_prior_coeffs_quant( &hMdDec->spar_md_prev, &hMdDec->spar_md_cfg, qsi, *nB );
#ifdef NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC
        }
#endif
    }
#ifdef SPAR_HOA_DBG
    fprintf( stdout, "\n\n no_ec = %d, strat = %d\n", no_ec, strat );
@@ -1832,18 +1738,9 @@ static void ivas_spar_dec_parse_md_bs(
        {
            hMdDec->spar_md_prev.band_coeffs_idx[i].decd_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].decd_index_re[j];
        }
#ifndef NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC
        hMdDec->valid_bands[*bands_bw * i] |= ( do_diff[i] == 0 && do_repeat[i] == 0 ) ? 1 : 0;
        for ( j = 1; j < *bands_bw; j++ )
        {
            hMdDec->valid_bands[*bands_bw * i + j] = hMdDec->valid_bands[*bands_bw * i];
        }
#else
        hMdDec->valid_bands[i] |= ( do_diff[i] == 0 && do_repeat[i] == 0 ) ? 1 : 0;
#endif
    }

#ifdef NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC
    ndec = hMdDec->spar_md_cfg.num_decorr_per_band[0];
    ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[0];
    if ( *bands_bw != 1 )
@@ -1858,7 +1755,6 @@ static void ivas_spar_dec_parse_md_bs(
            ndm );
    }

#endif

    return;
}
@@ -2131,7 +2027,6 @@ static void ivas_decode_huffman_bs(
    return;
}

#ifdef NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC
static void ivas_spar_plc_get_band_age(
    const int16_t *valid_bands,
    int16_t *base_band_age,
@@ -2200,7 +2095,6 @@ static void ivas_spar_get_plc_interp_weights(
    }
    return;
}
#endif

/*-----------------------------------------------------------------------------------------*
 * Function ivas_spar_md_fill_invalid_bands()
@@ -2221,34 +2115,8 @@ static void ivas_spar_md_fill_invalid_bands(
    int16_t valid_band_idx[IVAS_MAX_NUM_BANDS], idx = -1;
    int16_t last_valid_band_idx[IVAS_MAX_NUM_BANDS];
    float w = 0;
#ifdef NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC
    ivas_spar_plc_get_band_age( valid_bands, base_band_age, num_bands,
                                last_valid_band_idx, valid_band_idx, &all_valid, &idx );
#else
    set_s( valid_band_idx, 0, IVAS_MAX_NUM_BANDS );
    set_s( last_valid_band_idx, 0, IVAS_MAX_NUM_BANDS );

    all_valid = 1;
    for ( b = 0; b < num_bands; b++ )
    {
        if ( valid_bands[b] != 0 )
        {
            base_band_age[b] = 0; /* reset band age */
            idx++;
            valid_band_idx[idx] = b;
        }
        else
        {
            base_band_age[b] += 1; /* increment the age of invalid bands */

            if ( base_band_age[b] > 3 )
            {
                last_valid_band_idx[b] = idx;
            }
            all_valid = 0;
        }
    }
#endif
    assert( idx > 0 ); /* some bands should be valid */

    if ( all_valid == 0 )
@@ -2258,33 +2126,9 @@ static void ivas_spar_md_fill_invalid_bands(
            /* check against non zero in if and else if */
            if ( base_band_age[b] > 3 ) /* old invalid bands */
            {
#ifdef NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC
                int16_t id0, id1;
                ivas_spar_get_plc_interp_weights( valid_band_idx, last_valid_band_idx[b],
                                                  idx, b, &w, &id0, &id1 );
#else
                int16_t tmp_id, id0, id1;

                tmp_id = last_valid_band_idx[b];
                if ( tmp_id < 0 ) /* Extrapolation */
                {
                    id1 = valid_band_idx[0];
                    id0 = 0;
                    w = 1;
                }
                else if ( tmp_id == idx ) /* Extrapolation */
                {
                    id1 = valid_band_idx[tmp_id];
                    id0 = valid_band_idx[tmp_id];
                    w = 0;
                }
                else /* Interpolation */
                {
                    id0 = valid_band_idx[tmp_id];
                    id1 = valid_band_idx[tmp_id + 1];
                    w = ( (float) ( b - id0 ) ) / ( id1 - id0 );
                }
#endif
                for ( i = 0; i < num_channels; i++ )
                {
                    for ( j = 0; j < num_channels; j++ )
@@ -2330,7 +2174,6 @@ static void ivas_spar_md_fill_invalid_bands(
    return;
}

#ifdef NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC
static void ivas_spar_md_fill_invalid_bandcoeffs(
    ivas_band_coeffs_t *pBand_coeffs,
    ivas_band_coeffs_t *pBand_coeffs_prev,
@@ -2410,7 +2253,6 @@ static void ivas_spar_md_fill_invalid_bandcoeffs(

    return;
}
#endif


/*-----------------------------------------------------------------------------------------*
+0 −2
Original line number Diff line number Diff line
@@ -603,11 +603,9 @@ typedef struct ivas_spar_md_dec_state_t
    float smooth_buf[IVAS_MAX_NUM_BANDS][2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1];
    float smooth_fac[IVAS_MAX_NUM_BANDS];
    float mixer_mat_prev2[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS];
#ifdef NONBE_FIX_862_UBSAN_SPAR_DEC_BR_SW_PLC
    int16_t first_valid_frame;
    ivas_band_coeffs_t *band_coeffs_prev;
    int16_t base_band_coeffs_age[IVAS_MAX_NUM_BANDS];
#endif
} ivas_spar_md_dec_state_t;