avcodec/rv40: Avoid superfluous VLC structures

Of all these VLCs here, only VLC.table was really used
after init, so use the ff_vlc_init_tables API
to get rid of them.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
release/7.0
Andreas Rheinhardt 1 year ago
parent 460c6ae597
commit e5e05fd3c8
  1. 57
      libavcodec/rv40.c

@ -40,22 +40,16 @@
#include "rv40vlc2.h" #include "rv40vlc2.h"
#include "rv40data.h" #include "rv40data.h"
static VLC aic_top_vlc; static VLCElem aic_top_vlc[23590];
static VLC aic_mode1_vlc[AIC_MODE1_NUM], aic_mode2_vlc[AIC_MODE2_NUM]; static const VLCElem *aic_mode1_vlc[AIC_MODE1_NUM], *aic_mode2_vlc[AIC_MODE2_NUM];
static VLC ptype_vlc[NUM_PTYPE_VLCS], btype_vlc[NUM_BTYPE_VLCS]; static const VLCElem *ptype_vlc[NUM_PTYPE_VLCS], *btype_vlc[NUM_BTYPE_VLCS];
static av_cold void rv40_init_table(VLC *vlc, unsigned *offset, int nb_bits, static av_cold const VLCElem *rv40_init_table(VLCInitState *state, int nb_bits,
int nb_codes, const uint8_t (*tab)[2]) int nb_codes, const uint8_t (*tab)[2])
{ {
static VLCElem vlc_buf[11776]; return ff_vlc_init_tables_from_lengths(state, nb_bits, nb_codes,
vlc->table = &vlc_buf[*offset];
vlc->table_allocated = 1 << nb_bits;
*offset += 1 << nb_bits;
ff_vlc_init_from_lengths(vlc, nb_bits, nb_codes,
&tab[0][1], 2, &tab[0][0], 2, 1, &tab[0][1], 2, &tab[0][0], 2, 1,
0, VLC_INIT_USE_STATIC, NULL); 0, 0);
} }
/** /**
@ -63,18 +57,19 @@ static av_cold void rv40_init_table(VLC *vlc, unsigned *offset, int nb_bits,
*/ */
static av_cold void rv40_init_tables(void) static av_cold void rv40_init_tables(void)
{ {
int i, offset = 0; VLCInitState state = VLC_INIT_STATE(aic_top_vlc);
static VLCElem aic_mode2_table[11814]; int i;
rv40_init_table(&aic_top_vlc, &offset, AIC_TOP_BITS, AIC_TOP_SIZE, rv40_init_table(&state, AIC_TOP_BITS, AIC_TOP_SIZE,
rv40_aic_top_vlc_tab); rv40_aic_top_vlc_tab);
for(i = 0; i < AIC_MODE1_NUM; i++){ for(i = 0; i < AIC_MODE1_NUM; i++){
// Every tenth VLC table is empty // Every tenth VLC table is empty
if((i % 10) == 9) continue; if((i % 10) == 9) continue;
rv40_init_table(&aic_mode1_vlc[i], &offset, AIC_MODE1_BITS, aic_mode1_vlc[i] =
rv40_init_table(&state, AIC_MODE1_BITS,
AIC_MODE1_SIZE, aic_mode1_vlc_tabs[i]); AIC_MODE1_SIZE, aic_mode1_vlc_tabs[i]);
} }
for (unsigned i = 0, offset = 0; i < AIC_MODE2_NUM; i++){ for (unsigned i = 0; i < AIC_MODE2_NUM; i++){
uint16_t syms[AIC_MODE2_SIZE]; uint16_t syms[AIC_MODE2_SIZE];
for (int j = 0; j < AIC_MODE2_SIZE; j++) { for (int j = 0; j < AIC_MODE2_SIZE; j++) {
@ -85,19 +80,19 @@ static av_cold void rv40_init_tables(void)
else else
syms[j] = first | (second << 8); syms[j] = first | (second << 8);
} }
aic_mode2_vlc[i].table = &aic_mode2_table[offset]; aic_mode2_vlc[i] =
aic_mode2_vlc[i].table_allocated = FF_ARRAY_ELEMS(aic_mode2_table) - offset; ff_vlc_init_tables_from_lengths(&state, AIC_MODE2_BITS, AIC_MODE2_SIZE,
ff_vlc_init_from_lengths(&aic_mode2_vlc[i], AIC_MODE2_BITS, AIC_MODE2_SIZE,
aic_mode2_vlc_bits[i], 1, aic_mode2_vlc_bits[i], 1,
syms, 2, 2, 0, VLC_INIT_STATIC_OVERLONG, NULL); syms, 2, 2, 0, 0);
offset += aic_mode2_vlc[i].table_size;
} }
for(i = 0; i < NUM_PTYPE_VLCS; i++){ for(i = 0; i < NUM_PTYPE_VLCS; i++){
rv40_init_table(&ptype_vlc[i], &offset, PTYPE_VLC_BITS, PTYPE_VLC_SIZE, ptype_vlc[i] =
rv40_init_table(&state, PTYPE_VLC_BITS, PTYPE_VLC_SIZE,
ptype_vlc_tabs[i]); ptype_vlc_tabs[i]);
} }
for(i = 0; i < NUM_BTYPE_VLCS; i++){ for(i = 0; i < NUM_BTYPE_VLCS; i++){
rv40_init_table(&btype_vlc[i], &offset, BTYPE_VLC_BITS, BTYPE_VLC_SIZE, btype_vlc[i] =
rv40_init_table(&state, BTYPE_VLC_BITS, BTYPE_VLC_SIZE,
btype_vlc_tabs[i]); btype_vlc_tabs[i]);
} }
} }
@ -178,7 +173,7 @@ static int rv40_decode_intra_types(RV34DecContext *r, GetBitContext *gb, int8_t
for(i = 0; i < 4; i++, dst += r->intra_types_stride){ for(i = 0; i < 4; i++, dst += r->intra_types_stride){
if(!i && s->first_slice_line){ if(!i && s->first_slice_line){
pattern = get_vlc2(gb, aic_top_vlc.table, AIC_TOP_BITS, 1); pattern = get_vlc2(gb, aic_top_vlc, AIC_TOP_BITS, 1);
dst[0] = (pattern >> 2) & 2; dst[0] = (pattern >> 2) & 2;
dst[1] = (pattern >> 1) & 2; dst[1] = (pattern >> 1) & 2;
dst[2] = pattern & 2; dst[2] = pattern & 2;
@ -201,12 +196,12 @@ static int rv40_decode_intra_types(RV34DecContext *r, GetBitContext *gb, int8_t
if(pattern == rv40_aic_table_index[k]) if(pattern == rv40_aic_table_index[k])
break; break;
if(j < 3 && k < MODE2_PATTERNS_NUM){ //pattern is found, decoding 2 coefficients if(j < 3 && k < MODE2_PATTERNS_NUM){ //pattern is found, decoding 2 coefficients
AV_WN16(ptr, get_vlc2(gb, aic_mode2_vlc[k].table, AIC_MODE2_BITS, 2)); AV_WN16(ptr, get_vlc2(gb, aic_mode2_vlc[k], AIC_MODE2_BITS, 2));
ptr += 2; ptr += 2;
j++; j++;
}else{ }else{
if(B != -1 && C != -1) if(B != -1 && C != -1)
v = get_vlc2(gb, aic_mode1_vlc[B + C*10].table, AIC_MODE1_BITS, 1); v = get_vlc2(gb, aic_mode1_vlc[B + C*10], AIC_MODE1_BITS, 1);
else{ // tricky decoding else{ // tricky decoding
v = 0; v = 0;
switch(C){ switch(C){
@ -270,17 +265,17 @@ static int rv40_decode_mb_info(RV34DecContext *r)
if(s->pict_type == AV_PICTURE_TYPE_P){ if(s->pict_type == AV_PICTURE_TYPE_P){
prev_type = block_num_to_ptype_vlc_num[prev_type]; prev_type = block_num_to_ptype_vlc_num[prev_type];
q = get_vlc2(gb, ptype_vlc[prev_type].table, PTYPE_VLC_BITS, 1); q = get_vlc2(gb, ptype_vlc[prev_type], PTYPE_VLC_BITS, 1);
if(q < PBTYPE_ESCAPE) if(q < PBTYPE_ESCAPE)
return q; return q;
q = get_vlc2(gb, ptype_vlc[prev_type].table, PTYPE_VLC_BITS, 1); q = get_vlc2(gb, ptype_vlc[prev_type], PTYPE_VLC_BITS, 1);
av_log(s->avctx, AV_LOG_ERROR, "Dquant for P-frame\n"); av_log(s->avctx, AV_LOG_ERROR, "Dquant for P-frame\n");
}else{ }else{
prev_type = block_num_to_btype_vlc_num[prev_type]; prev_type = block_num_to_btype_vlc_num[prev_type];
q = get_vlc2(gb, btype_vlc[prev_type].table, BTYPE_VLC_BITS, 1); q = get_vlc2(gb, btype_vlc[prev_type], BTYPE_VLC_BITS, 1);
if(q < PBTYPE_ESCAPE) if(q < PBTYPE_ESCAPE)
return q; return q;
q = get_vlc2(gb, btype_vlc[prev_type].table, BTYPE_VLC_BITS, 1); q = get_vlc2(gb, btype_vlc[prev_type], BTYPE_VLC_BITS, 1);
av_log(s->avctx, AV_LOG_ERROR, "Dquant for B-frame\n"); av_log(s->avctx, AV_LOG_ERROR, "Dquant for B-frame\n");
} }
return 0; return 0;

Loading…
Cancel
Save