From fe748ddf62f98f923d79629c4ba8414d90b8b1e5 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Wed, 20 Sep 2023 17:45:52 +0200 Subject: [PATCH] avcodec/h264_cavlc: 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 --- libavcodec/h264_cavlc.c | 190 +++++++++++++++++----------------------- 1 file changed, 80 insertions(+), 110 deletions(-) diff --git a/libavcodec/h264_cavlc.c b/libavcodec/h264_cavlc.c index de223611c6..994e10dd0a 100644 --- a/libavcodec/h264_cavlc.c +++ b/libavcodec/h264_cavlc.c @@ -234,38 +234,6 @@ static const uint8_t run_bits[7][16]={ {7,6,5,4,3,2,1,1,1,1,1,1,1,1,1}, }; -static VLC coeff_token_vlc[4]; -static VLCElem coeff_token_vlc_tables[520+332+280+256]; -static const int coeff_token_vlc_tables_size[4]={520,332,280,256}; - -static VLC chroma_dc_coeff_token_vlc; -static VLCElem chroma_dc_coeff_token_vlc_table[256]; -static const int chroma_dc_coeff_token_vlc_table_size = 256; - -static VLC chroma422_dc_coeff_token_vlc; -static VLCElem chroma422_dc_coeff_token_vlc_table[8192]; -static const int chroma422_dc_coeff_token_vlc_table_size = 8192; - -static VLC total_zeros_vlc[15+1]; -static VLCElem total_zeros_vlc_tables[15][512]; -static const int total_zeros_vlc_tables_size = 512; - -static VLC chroma_dc_total_zeros_vlc[3+1]; -static VLCElem chroma_dc_total_zeros_vlc_tables[3][8]; -static const int chroma_dc_total_zeros_vlc_tables_size = 8; - -static VLC chroma422_dc_total_zeros_vlc[7+1]; -static VLCElem chroma422_dc_total_zeros_vlc_tables[7][32]; -static const int chroma422_dc_total_zeros_vlc_tables_size = 32; - -static VLC run_vlc[6+1]; -static VLCElem run_vlc_tables[6][8]; -static const int run_vlc_tables_size = 8; - -static VLC run7_vlc; -static VLCElem run7_vlc_table[96]; -static const int run7_vlc_table_size = 96; - #define LEVEL_TAB_BITS 8 static int8_t cavlc_level_tab[7][1<>2; }else{ if(n >= LUMA_DC_BLOCK_INDEX){ total_coeff= pred_non_zero_count(h, sl, (n - LUMA_DC_BLOCK_INDEX)*16); - coeff_token= get_vlc2(gb, coeff_token_vlc[ coeff_token_table_index[total_coeff] ].table, COEFF_TOKEN_VLC_BITS, 2); + coeff_token = get_vlc2(gb, coeff_token_vlc[coeff_token_table_index[total_coeff]], + COEFF_TOKEN_VLC_BITS, 2); total_coeff= coeff_token>>2; }else{ total_coeff= pred_non_zero_count(h, sl, n); - coeff_token= get_vlc2(gb, coeff_token_vlc[ coeff_token_table_index[total_coeff] ].table, COEFF_TOKEN_VLC_BITS, 2); + coeff_token = get_vlc2(gb, coeff_token_vlc[coeff_token_table_index[total_coeff]], + COEFF_TOKEN_VLC_BITS, 2); total_coeff= coeff_token>>2; } } @@ -563,13 +532,14 @@ static int decode_residual(const H264Context *h, H264SliceContext *sl, else{ if (max_coeff <= 8) { if (max_coeff == 4) - zeros_left = get_vlc2(gb, chroma_dc_total_zeros_vlc[total_coeff].table, + zeros_left = get_vlc2(gb, chroma_dc_total_zeros_vlc[total_coeff], CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 1); else - zeros_left = get_vlc2(gb, chroma422_dc_total_zeros_vlc[total_coeff].table, + zeros_left = get_vlc2(gb, chroma422_dc_total_zeros_vlc[total_coeff], CHROMA422_DC_TOTAL_ZEROS_VLC_BITS, 1); } else { - zeros_left= get_vlc2(gb, total_zeros_vlc[ total_coeff ].table, TOTAL_ZEROS_VLC_BITS, 1); + zeros_left = get_vlc2(gb, total_zeros_vlc[total_coeff], + TOTAL_ZEROS_VLC_BITS, 1); } } @@ -579,9 +549,9 @@ static int decode_residual(const H264Context *h, H264SliceContext *sl, ((type*)block)[*scantable] = level[0]; \ for(i=1;i 0;i++) { \ if(zeros_left < 7) \ - run_before= get_vlc2(gb, run_vlc[zeros_left].table, RUN_VLC_BITS, 1); \ + run_before = get_vlc2(gb, run_vlc[zeros_left], RUN_VLC_BITS, 1); \ else \ - run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2); \ + run_before = get_vlc2(gb, run7_vlc_table, RUN7_VLC_BITS, 2); \ zeros_left -= run_before; \ scantable -= 1 + run_before; \ ((type*)block)[*scantable]= level[i]; \ @@ -594,9 +564,9 @@ static int decode_residual(const H264Context *h, H264SliceContext *sl, ((type*)block)[*scantable] = ((int)(level[0] * qmul[*scantable] + 32))>>6; \ for(i=1;i 0;i++) { \ if(zeros_left < 7) \ - run_before= get_vlc2(gb, run_vlc[zeros_left].table, RUN_VLC_BITS, 1); \ + run_before = get_vlc2(gb, run_vlc[zeros_left], RUN_VLC_BITS, 1); \ else \ - run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2); \ + run_before = get_vlc2(gb, run7_vlc_table, RUN7_VLC_BITS, 2); \ zeros_left -= run_before; \ scantable -= 1 + run_before; \ ((type*)block)[*scantable]= ((int)(level[i] * qmul[*scantable] + 32))>>6; \