History

avcodec/h264_cavlc: Avoid indirection for coefficient table VLCs

Andreas Rheinhardt committed 3 years ago

Commit bd4c7781 parent fe748dd1 file · +12 −5Browse files

Unified · Split

libavcodec/h264_cavlc.c+12−5
@@ -246,7 +246,8 @@ static int8_t cavlc_level_tab[7][1<<LEVEL_TAB_BITS][2]; · 245 unmodified lines
246246 #define RUN_VLC_BITS 3
247247 #define RUN7_VLC_BITS 6
248248
249−static const VLCElem *coeff_token_vlc[4];
249+/// 17 pointers to only four different VLCs
250+static const VLCElem *coeff_token_vlc[17];
250251
251252 static VLCElem chroma_dc_coeff_token_vlc_table[256];
252253
@@ -313,6 +314,7 @@ static av_cold void init_cavlc_level_tab(void){ · 60 unmodified lines
313314
314315 av_cold void ff_h264_decode_init_vlc(void)
315316 {
317+ const VLCElem *coeff_token_vlc_original[4];
316318 VLCInitState state = VLC_INIT_STATE(run7_vlc_table);
317319
318320 VLC_INIT_STATIC_TABLE(chroma_dc_coeff_token_vlc_table,
@@ -336,11 +338,17 @@ av_cold void ff_h264_decode_init_vlc(void) · 17 unmodified lines
336338 }
337339
338340 for (int i = 0; i < 4; i++) {
339− coeff_token_vlc[i] =
341+ coeff_token_vlc_original[i] =
340342 ff_vlc_init_tables(&state, COEFF_TOKEN_VLC_BITS, 4*17,
341343 &coeff_token_len [i][0], 1, 1,
342344 &coeff_token_bits[i][0], 1, 1, 0);
343345 }
346+ for (int i = 0; i < FF_ARRAY_ELEMS(coeff_token_vlc); i++) {
347+ static const uint8_t coeff_token_table_index[17] = {
348+ 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3
349+ };
350+ coeff_token_vlc[i] = coeff_token_vlc_original[coeff_token_table_index[i]];
351+ }
344352
345353 for (int i = 0; i < 3; i++) {
346354 chroma_dc_total_zeros_vlc[i + 1] =
@@ -399,7 +407,6 @@ static int decode_residual(const H264Context *h, H264SliceContext *sl, · 52 unmodified lines
399407 const uint8_t *scantable, const uint32_t *qmul,
400408 int max_coeff)
401409 {
402− static const int coeff_token_table_index[17]= {0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3};
403410 int level[16];
404411 int zeros_left, coeff_token, total_coeff, i, trailing_ones, run_before;
405412
@@ -416,12 +423,12 @@ static int decode_residual(const H264Context *h, H264SliceContext *sl, · 10 unmodified lines
416423 }else{
417424 if(n >= LUMA_DC_BLOCK_INDEX){
418425 total_coeff= pred_non_zero_count(h, sl, (n - LUMA_DC_BLOCK_INDEX)*16);
419− coeff_token = get_vlc2(gb, coeff_token_vlc[coeff_token_table_index[total_coeff]],
426+ coeff_token = get_vlc2(gb, coeff_token_vlc[total_coeff],
420427 COEFF_TOKEN_VLC_BITS, 2);
421428 total_coeff= coeff_token>>2;
422429 }else{
423430 total_coeff= pred_non_zero_count(h, sl, n);
424− coeff_token = get_vlc2(gb, coeff_token_vlc[coeff_token_table_index[total_coeff]],
431+ coeff_token = get_vlc2(gb, coeff_token_vlc[total_coeff],
425432 COEFF_TOKEN_VLC_BITS, 2);
426433 total_coeff= coeff_token>>2;
427434 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t