Commit ca8911fe authored by Shikha Shetgeri's avatar Shikha Shetgeri
Browse files

modified the coders to stop writing to the bitstream before running out of space

parent 0f3d7d7d
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -4377,7 +4377,11 @@ int16_t ivas_get_bits_to_encode(
void ivas_huffman_encode( ivas_huffman_cfg_t *huff_cfg, int16_t in, int16_t *hcode, int16_t *hlen );
void ivas_spar_huff_coeffs_com_init( ivas_huff_coeffs_t *pHuff_coeffs, ivas_spar_md_com_cfg *pSpar_cfg, const int16_t table_idx, const int16_t enc_dec );
void ivas_spar_arith_coeffs_com_init( ivas_arith_coeffs_t *pArith_coeffs, ivas_spar_md_com_cfg *pSpar_cfg, const int16_t table_idx, const int16_t enc_dec );
void ivas_arith_encode_cmplx_cell_array(ivas_arith_t *pArith_re, ivas_arith_t *pArith_re_diff, const int16_t *pDo_diff, const int16_t nB, int16_t *pSymbol_re, int16_t *pSymbol_old_re, ivas_cell_dim_t *pCell_dims, BSTR_ENC_HANDLE hMetaData, const int16_t any_diff);
void ivas_arith_encode_cmplx_cell_array(ivas_arith_t *pArith_re, ivas_arith_t *pArith_re_diff, const int16_t *pDo_diff, const int16_t nB, int16_t *pSymbol_re, int16_t *pSymbol_old_re, ivas_cell_dim_t *pCell_dims, BSTR_ENC_HANDLE hMetaData, const int16_t any_diff 
#ifdef ARITH_HUFF_CODER_CHANGES
  , int32_t wc_strat_arith
#endif
);
ivas_error ivas_huffman_decode( ivas_huffman_cfg_t *huff_cfg, Decoder_State *st0, int16_t *dec_out );
void ivas_arith_decode_cmplx_cell_array( ivas_arith_t *pArith_re, ivas_arith_t *pArith_re_diff, Decoder_State *st0, ivas_cell_dim_t *pCell_dims, int16_t *pDo_diff, const int16_t nB, int16_t *pSymbol_re, int16_t *pSymbol_re_old );

+0 −1
Original line number Diff line number Diff line
@@ -290,7 +290,6 @@ typedef struct ivas_arith_t
    int16_t range;
    int16_t num_models;
    float saved_dist_arr[IVAS_NUM_PROB_MODELS][IVAS_MAX_QUANT_LEVELS];

} ivas_arith_t;

typedef struct ivas_arith_coeffs_t
+54 −8
Original line number Diff line number Diff line
@@ -133,7 +133,12 @@ static void ivas_arith_encode_array(
    int16_t *pInput,
    ivas_arith_t *pArith,
    BSTR_ENC_HANDLE hMetaData,
    const int16_t in_len )
    const int16_t in_len
#ifdef ARITH_HUFF_CODER_CHANGES
    ,
    int32_t wc_strat_arith
#endif
)
{
    int16_t model_index, i, ind;
    int16_t *pCum_freq = NULL;
@@ -144,7 +149,18 @@ static void ivas_arith_encode_array(
        if ( pArith->dyn_model_bits > 0 )
        {
            ivas_get_dyn_freq_model( pInput, in_len, &model_index, pArith, &pCum_freq );
#ifdef ARITH_HUFF_CODER_CHANGES
            if ( hMetaData->nb_bits_tot <= wc_strat_arith )
            {
#endif
                push_next_indice( hMetaData, model_index, pArith->dyn_model_bits );
#ifdef ARITH_HUFF_CODER_CHANGES
            }
            else
            {
                return;
            }
#endif
        }
        else
        {
@@ -191,7 +207,12 @@ static void ivas_arithCoder_encode_array_diff(

        ivas_wrap_arround( pIn_old_scratch, pArith_diff->vals[0], pArith_diff->vals[pArith_diff->range - 1], length );

        ivas_arith_encode_array( pIn_old_scratch, pArith_diff, hMetaData, length );
        ivas_arith_encode_array( pIn_old_scratch, pArith_diff, hMetaData, length
#ifdef ARITH_HUFF_CODER_CHANGES
                                 ,
                                 MAX_NUM_INDICES
#endif
        );
    }

    return;
@@ -234,7 +255,12 @@ static void arith_encode_cell_array(
    BSTR_ENC_HANDLE hMetaData,
    const int16_t nB,
    ivas_arith_t *pArith,
    int16_t *pSymbol )
    int16_t *pSymbol
#ifdef ARITH_HUFF_CODER_CHANGES
    ,
    int32_t wc_strat_arith
#endif
)
{
    int16_t total_symbol_len = 0;
    int16_t i;
@@ -250,7 +276,12 @@ static void arith_encode_cell_array(
    {
        if ( pArith->range > 1 )
        {
            ivas_arith_encode_array( pSymbol, pArith, hMetaData, total_symbol_len );
            ivas_arith_encode_array( pSymbol, pArith, hMetaData, total_symbol_len
#ifdef ARITH_HUFF_CODER_CHANGES
                                     ,
                                     wc_strat_arith
#endif
            );
        }
    }

@@ -309,7 +340,12 @@ void ivas_arith_encode_cmplx_cell_array(
    int16_t *pSymbol_old_re,
    ivas_cell_dim_t *pCell_dims,
    BSTR_ENC_HANDLE hMetaData,
    const int16_t any_diff )
    const int16_t any_diff
#ifdef ARITH_HUFF_CODER_CHANGES
    ,
    int32_t wc_strat_arith
#endif
)
{
    int16_t input_old[IVAS_MAX_INPUT_LEN];
    int16_t input_new[IVAS_MAX_INPUT_LEN];
@@ -382,13 +418,23 @@ void ivas_arith_encode_cmplx_cell_array(
                     }*/
#endif

        arith_encode_cell_array( cell_dim, hMetaData, nB, pArith_re, input );
        arith_encode_cell_array( cell_dim, hMetaData, nB, pArith_re, input
#ifdef ARITH_HUFF_CODER_CHANGES
                                 ,
                                 wc_strat_arith
#endif
        );

        arith_encode_cell_array_diff( cell_dim_diff, hMetaData, nB, pArith_re_diff, input_old, input_new );
    }
    else
    {
        arith_encode_cell_array( pCell_dims, hMetaData, nB, pArith_re, pSymbol_re );
        arith_encode_cell_array( pCell_dims, hMetaData, nB, pArith_re, pSymbol_re
#ifdef ARITH_HUFF_CODER_CHANGES
                                 ,
                                 wc_strat_arith
#endif
        );
    }

    return;
+105 −13
Original line number Diff line number Diff line
@@ -116,6 +116,7 @@ ivas_error ivas_spar_md_enc_open(
    int16_t num_bands_arith_huff = IVAS_MAX_NUM_BANDS;
    int16_t n_input, n_dmx, n_dec = 0;
    int16_t table_idx, quant_strat = 0;
    int32_t table_cal_wc = 0;
#endif
    error = IVAS_ERR_OK;

@@ -225,6 +226,14 @@ ivas_error ivas_spar_md_enc_open(
    {
        quant_strat = QUANT_STRAT_2;
    }
    /*worst case table calculated value*/
    for ( i = 0; i < ivas_spar_br_table_consts[table_idx].nchan_transport; i++ )
    {
        table_cal_wc += ivas_spar_br_table_consts[table_idx].core_brs[i][1];
    }
    table_cal_wc = hEncoderConfig->ivas_total_brate - table_cal_wc;
    table_cal_wc = table_cal_wc / FRAMES_PER_SEC;

    n_input = ivas_sba_get_nchan_metadata( sba_order );
    n_dmx = ivas_spar_br_table_consts[table_idx].nchan_transport;
    n_dec = n_input - n_dmx;
@@ -234,6 +243,10 @@ ivas_error ivas_spar_md_enc_open(
    wc_coarse_strat = bits_PR + bits_C + bits_P;
    wc_coarse_strat = ( ( wc_coarse_strat * num_bands_arith_huff ) + ( IVAS_SBA_SIGNALING_OVERHEAD + hMdEnc->spar_md_cfg.quant_strat_bits ) ) * FRAMES_PER_SEC;
    wc_coarse_strat = wc_coarse_strat / FRAMES_PER_SEC;
    if ( wc_coarse_strat >= table_cal_wc )
    {
        printf("wc_coarse_strat is greater than table_cal_wc!");
    }
    hMdEnc->wc_strat = wc_coarse_strat;
    hMdEnc->wc_coarse_strat_buff = (Indice *)malloc(wc_coarse_strat * sizeof(Indice));
#endif
@@ -1325,7 +1338,18 @@ static void ivas_get_huffman_coded_bs(
            for ( j = pred_offset; j < pred_coeff_dim; j++ )
            {
                ivas_huffman_encode( &hMdEnc->huff_coeffs.pred_huff_re[qsi], hMdEnc->spar_md.band_coeffs_idx[i].pred_index_re[j], &code, &len );
#ifdef ARITH_HUFF_CODER_CHANGES
                if ( hMetaData->nb_bits_tot <= hMdEnc->wc_strat )
                {
#endif
                    push_next_indice( hMetaData, code, len );
#ifdef ARITH_HUFF_CODER_CHANGES
                }
                else
                {
                    return;
                }
#endif
            }

            for ( j = 0; j < ndec * ( ndm - 1 ); j++ )
@@ -1333,7 +1357,18 @@ static void ivas_get_huffman_coded_bs(
                if ( keep_planar[(int16_t) floor( j / ( ndm - 1 ) )] )
                {
                    ivas_huffman_encode( &hMdEnc->huff_coeffs.drct_huff_re[qsi], hMdEnc->spar_md.band_coeffs_idx[i].drct_index_re[j], &code, &len );
#ifdef ARITH_HUFF_CODER_CHANGES
                    if ( hMetaData->nb_bits_tot <= hMdEnc->wc_strat )
                    {
#endif
                        push_next_indice( hMetaData, code, len );
#ifdef ARITH_HUFF_CODER_CHANGES
                    }
                    else
                    {
                        return;
                    }
#endif
                }
            }

@@ -1342,7 +1377,18 @@ static void ivas_get_huffman_coded_bs(
                if ( keep_planar[j] )
                {
                    ivas_huffman_encode( &hMdEnc->huff_coeffs.decd_huff_re[qsi], hMdEnc->spar_md.band_coeffs_idx[i].decd_index_re[j], &code, &len );
#ifdef ARITH_HUFF_CODER_CHANGES
                    if ( hMetaData->nb_bits_tot <= hMdEnc->wc_strat )
                    {
#endif
                        push_next_indice( hMetaData, code, len );
#ifdef ARITH_HUFF_CODER_CHANGES
                    }
                    else
                    {
                        return;
                    }
#endif
                }
            }
        }
@@ -1351,19 +1397,52 @@ static void ivas_get_huffman_coded_bs(
            for ( j = pred_offset; j < pred_coeff_dim; j++ )
            {
                ivas_huffman_encode( &hMdEnc->huff_coeffs.pred_huff_re[qsi], hMdEnc->spar_md.band_coeffs_idx[i].pred_index_re[j], &code, &len );
#ifdef ARITH_HUFF_CODER_CHANGES
                if ( hMetaData->nb_bits_tot <= hMdEnc->wc_strat )
                {
#endif
                    push_next_indice( hMetaData, code, len );
#ifdef ARITH_HUFF_CODER_CHANGES
                }
                else
                {
                    return;
                }
#endif
            }

            for ( j = 0; j < ndec * ( ndm - 1 ); j++ )
            {
                ivas_huffman_encode( &hMdEnc->huff_coeffs.drct_huff_re[qsi], hMdEnc->spar_md.band_coeffs_idx[i].drct_index_re[j], &code, &len );
#ifdef ARITH_HUFF_CODER_CHANGES
                if ( hMetaData->nb_bits_tot <= hMdEnc->wc_strat )
                {
#endif
                    push_next_indice( hMetaData, code, len );
#ifdef ARITH_HUFF_CODER_CHANGES
                }
                else
                {
                    return;
                }
#endif
            }

            for ( j = 0; j < ndec; j++ )
            {
                ivas_huffman_encode( &hMdEnc->huff_coeffs.decd_huff_re[qsi], hMdEnc->spar_md.band_coeffs_idx[i].decd_index_re[j], &code, &len );
#ifdef ARITH_HUFF_CODER_CHANGES
                if ( hMetaData->nb_bits_tot <= hMdEnc->wc_strat )
                {
#endif
                    push_next_indice( hMetaData, code, len );
#ifdef ARITH_HUFF_CODER_CHANGES
                }
                else
                {
                    return;
                }
#endif
            }
        }
    }
@@ -1394,7 +1473,6 @@ static void ivas_get_arith_coded_bs(
    ivas_cell_dim_t decx_cell_dims[IVAS_MAX_NUM_BANDS];
    int16_t symbol_arr_re[IVAS_MAX_INPUT_LEN];
    int16_t symbol_arr_old_re[IVAS_MAX_INPUT_LEN];

    for ( i = 0; i < nB; i++ )
    {
        int16_t ndm, ndec;
@@ -1454,8 +1532,12 @@ static void ivas_get_arith_coded_bs(
    }

    ivas_arith_encode_cmplx_cell_array( &hMdEnc->arith_coeffs.pred_arith_re[qsi], &hMdEnc->arith_coeffs.pred_arith_re_diff[qsi], pDo_diff, nB,
                                        symbol_arr_re, symbol_arr_old_re, pred_cell_dims, hMetaData, any_diff );

                                        symbol_arr_re, symbol_arr_old_re, pred_cell_dims, hMetaData, any_diff
#ifdef ARITH_HUFF_CODER_CHANGES
                                        ,
                                        hMdEnc->wc_strat
#endif
    );
    if ( hMdEnc->spar_hoa_md_flag )
    {
        for ( i = 0; i < nB; i++ )
@@ -1497,7 +1579,12 @@ static void ivas_get_arith_coded_bs(
    }

    ivas_arith_encode_cmplx_cell_array( &hMdEnc->arith_coeffs.drct_arith_re[qsi], &hMdEnc->arith_coeffs.drct_arith_re_diff[qsi], pDo_diff, nB,
                                        symbol_arr_re, symbol_arr_old_re, drct_cell_dims, hMetaData, any_diff );
                                        symbol_arr_re, symbol_arr_old_re, drct_cell_dims, hMetaData, any_diff
#ifdef ARITH_HUFF_CODER_CHANGES
                                        ,
                                        hMdEnc->wc_strat
#endif
    );

    ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md.band_coeffs_idx, nB, symbol_arr_re, decd_cell_dims, DECD_COEFF, planarCP );

@@ -1515,7 +1602,12 @@ static void ivas_get_arith_coded_bs(
    }

    ivas_arith_encode_cmplx_cell_array( &hMdEnc->arith_coeffs.decd_arith_re[qsi], &hMdEnc->arith_coeffs.decd_arith_re_diff[qsi], pDo_diff, nB,
                                        symbol_arr_re, symbol_arr_old_re, decd_cell_dims, hMetaData, any_diff );
                                        symbol_arr_re, symbol_arr_old_re, decd_cell_dims, hMetaData, any_diff
#ifdef ARITH_HUFF_CODER_CHANGES
                                        ,
                                        hMdEnc->wc_strat
#endif
    );

    ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md.band_coeffs_idx, nB, symbol_arr_re, decx_cell_dims, DECX_COEFF, planarCP );