From 8140955d39ecff922b7666261556b0c3aba6dd1e Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Tue, 23 Dec 2008 17:49:38 +0000 Subject: [PATCH] unified CAVLC level decoding LUT. Quite a bit faster (HPCVMOLQ_BRCM_B.264 was 3% faster here) Originally committed as revision 16291 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/h264.c | 49 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/libavcodec/h264.c b/libavcodec/h264.c index db4f63ed52..76bed662a3 100644 --- a/libavcodec/h264.c +++ b/libavcodec/h264.c @@ -101,6 +101,9 @@ static const int left_block_options[4][8]={ {0,2,0,2,7,10,7,10} }; +#define LEVEL_TAB_BITS 8 +static int8_t cavlc_level_tab[7][1<s; const int mb_xy= h->mb_xy; @@ -1875,6 +1878,31 @@ static void hl_motion(H264Context *h, uint8_t *dest_y, uint8_t *dest_cb, uint8_t prefetch_motion(h, 1); } +static av_cold void init_cavlc_level_tab(void){ + int suffix_length, mask; + unsigned int i; + + for(suffix_length=0; suffix_length<7; suffix_length++){ + for(i=0; i<(1<>(LEVEL_TAB_BITS-prefix-1-suffix_length)) - (1<>1) ^ mask) - mask; + if(prefix + 1 + suffix_length <= LEVEL_TAB_BITS){ + cavlc_level_tab[suffix_length][i][0]= level_code; + cavlc_level_tab[suffix_length][i][1]= prefix + 1 + suffix_length; + }else if(prefix + 1 <= LEVEL_TAB_BITS){ + cavlc_level_tab[suffix_length][i][0]= prefix+100; + cavlc_level_tab[suffix_length][i][1]= prefix + 1; + }else{ + cavlc_level_tab[suffix_length][i][0]= LEVEL_TAB_BITS+100; + cavlc_level_tab[suffix_length][i][1]= LEVEL_TAB_BITS; + } + } + } +} + static av_cold void decode_init_vlc(void){ static int done = 0; @@ -1941,6 +1969,8 @@ static av_cold void decode_init_vlc(void){ &run_len [6][0], 1, 1, &run_bits[6][0], 1, 1, INIT_VLC_USE_NEW_STATIC); + + init_cavlc_level_tab(); } } @@ -4137,8 +4167,16 @@ static int decode_residual(H264Context *h, GetBitContext *gb, DCTELEM *block, in //remaining coefficients have suffix_length > 0 for(i=trailing_ones+1;i= 100){ + prefix= level_code - 100; + if(prefix == LEVEL_TAB_BITS){ + prefix += get_level_prefix(gb); + } if(prefix<15){ level_code = (prefix<>1) ^ mask) - mask; - if(level_code > suffix_limit[suffix_length]) + level_code= (((2+level_code)>>1) ^ mask) - mask; + } + level[i]= level_code; + + if(suffix_limit[suffix_length] + level_code > 2U*suffix_limit[suffix_length]) suffix_length++; } }