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
246#define RUN_VLC_BITS 3246#define RUN_VLC_BITS 3
247#define RUN7_VLC_BITS 6247#define RUN7_VLC_BITS 6
248 248
249static const VLCElem *coeff_token_vlc[4];249/// 17 pointers to only four different VLCs
250static const VLCElem *coeff_token_vlc[17];
250 251
251static VLCElem chroma_dc_coeff_token_vlc_table[256];252static VLCElem chroma_dc_coeff_token_vlc_table[256];
252 253
@@ -313,6 +314,7 @@ static av_cold void init_cavlc_level_tab(void){ · 60 unmodified lines
313 314
314av_cold void ff_h264_decode_init_vlc(void)315av_cold void ff_h264_decode_init_vlc(void)
315{316{
317 const VLCElem *coeff_token_vlc_original[4];
316 VLCInitState state = VLC_INIT_STATE(run7_vlc_table);318 VLCInitState state = VLC_INIT_STATE(run7_vlc_table);
317 319
318 VLC_INIT_STATIC_TABLE(chroma_dc_coeff_token_vlc_table,320 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
336 }338 }
337 339
338 for (int i = 0; i < 4; i++) {340 for (int i = 0; i < 4; i++) {
339 coeff_token_vlc[i] =341 coeff_token_vlc_original[i] =
340 ff_vlc_init_tables(&state, COEFF_TOKEN_VLC_BITS, 4*17,342 ff_vlc_init_tables(&state, COEFF_TOKEN_VLC_BITS, 4*17,
341 &coeff_token_len [i][0], 1, 1,343 &coeff_token_len [i][0], 1, 1,
342 &coeff_token_bits[i][0], 1, 1, 0);344 &coeff_token_bits[i][0], 1, 1, 0);
343 }345 }
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 }
344 352
345 for (int i = 0; i < 3; i++) {353 for (int i = 0; i < 3; i++) {
346 chroma_dc_total_zeros_vlc[i + 1] =354 chroma_dc_total_zeros_vlc[i + 1] =
@@ -399,7 +407,6 @@ static int decode_residual(const H264Context *h, H264SliceContext *sl, · 52 unmodified lines
399 const uint8_t *scantable, const uint32_t *qmul,407 const uint8_t *scantable, const uint32_t *qmul,
400 int max_coeff)408 int max_coeff)
401{409{
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};
403 int level[16];410 int level[16];
404 int zeros_left, coeff_token, total_coeff, i, trailing_ones, run_before;411 int zeros_left, coeff_token, total_coeff, i, trailing_ones, run_before;
405 412
@@ -416,12 +423,12 @@ static int decode_residual(const H264Context *h, H264SliceContext *sl, · 10 unmodified lines
416 }else{423 }else{
417 if(n >= LUMA_DC_BLOCK_INDEX){424 if(n >= LUMA_DC_BLOCK_INDEX){
418 total_coeff= pred_non_zero_count(h, sl, (n - LUMA_DC_BLOCK_INDEX)*16);425 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],
420 COEFF_TOKEN_VLC_BITS, 2);427 COEFF_TOKEN_VLC_BITS, 2);
421 total_coeff= coeff_token>>2;428 total_coeff= coeff_token>>2;
422 }else{429 }else{
423 total_coeff= pred_non_zero_count(h, sl, n);430 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],
425 COEFF_TOKEN_VLC_BITS, 2);432 COEFF_TOKEN_VLC_BITS, 2);
426 total_coeff= coeff_token>>2;433 total_coeff= coeff_token>>2;
427 }434 }

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