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. Also combine the ff_msmp4_dc_(luma|chroma)_vlcs as well as the tables used to generate them to simplify the code.
Showing the changes to libavcodec (6 of 6 files). Show all
Unified · Split
| @@ -32,28 +32,25 @@ · 31 unmodified lines | ||
| 32 | 32 | #include "libavutil/attributes.h" |
| 33 | 33 | #include "libavutil/thread.h" |
| 34 | 34 | |
| 35 | −VLC ff_msmp4_mb_i_vlc; | |
| 36 | −VLC ff_msmp4_dc_luma_vlc[2]; | |
| 37 | −VLC ff_msmp4_dc_chroma_vlc[2]; | |
| 35 | +VLCElem ff_msmp4_mb_i_vlc[536]; | |
| 36 | +const VLCElem *ff_msmp4_dc_vlc[2][2]; | |
| 38 | 37 | |
| 39 | 38 | static av_cold void msmp4_vc1_vlcs_init(void) |
| 40 | 39 | { |
| 41 | − VLC_INIT_STATIC(&ff_msmp4_dc_luma_vlc[0], MSMP4_DC_VLC_BITS, 120, | |
| 42 | − &ff_table0_dc_lum[0][1], 8, 4, | |
| 43 | − &ff_table0_dc_lum[0][0], 8, 4, 1158); | |
| 44 | − VLC_INIT_STATIC(&ff_msmp4_dc_chroma_vlc[0], MSMP4_DC_VLC_BITS, 120, | |
| 45 | − &ff_table0_dc_chroma[0][1], 8, 4, | |
| 46 | − &ff_table0_dc_chroma[0][0], 8, 4, 1118); | |
| 47 | − VLC_INIT_STATIC(&ff_msmp4_dc_luma_vlc[1], MSMP4_DC_VLC_BITS, 120, | |
| 48 | − &ff_table1_dc_lum[0][1], 8, 4, | |
| 49 | − &ff_table1_dc_lum[0][0], 8, 4, 1476); | |
| 50 | − VLC_INIT_STATIC(&ff_msmp4_dc_chroma_vlc[1], MSMP4_DC_VLC_BITS, 120, | |
| 51 | − &ff_table1_dc_chroma[0][1], 8, 4, | |
| 52 | − &ff_table1_dc_chroma[0][0], 8, 4, 1216); | |
| 40 | + static VLCElem vlc_buf[1158 + 1118 + 1476 + 1216]; | |
| 41 | + VLCInitState state = VLC_INIT_STATE(vlc_buf); | |
| 53 | 42 | |
| 54 | − VLC_INIT_STATIC(&ff_msmp4_mb_i_vlc, MSMP4_MB_INTRA_VLC_BITS, 64, | |
| 55 | − &ff_msmp4_mb_i_table[0][1], 4, 2, | |
| 56 | − &ff_msmp4_mb_i_table[0][0], 4, 2, 536); | |
| 43 | + for (int i = 0; i < 2; i++) { | |
| 44 | + for (int j = 0; j < 2; j++) { | |
| 45 | + ff_msmp4_dc_vlc[i][j] = | |
| 46 | + ff_vlc_init_tables(&state, MSMP4_DC_VLC_BITS, 120, | |
| 47 | + &ff_msmp4_dc_tables[i][j][0][1], 8, 4, | |
| 48 | + &ff_msmp4_dc_tables[i][j][0][0], 8, 4, 0); | |
| 49 | + } | |
| 50 | + } | |
| 51 | + VLC_INIT_STATIC_TABLE(ff_msmp4_mb_i_vlc, MSMP4_MB_INTRA_VLC_BITS, 64, | |
| 52 | + &ff_msmp4_mb_i_table[0][1], 4, 2, | |
| 53 | + &ff_msmp4_mb_i_table[0][0], 4, 2, 0); | |
| 57 | 54 | } |
| 58 | 55 | |
| 59 | 56 | av_cold void ff_msmp4_vc1_vlcs_init_once(void) |
| @@ -82,9 +79,11 @@ const uint16_t ff_msmp4_mb_i_table[64][2] = { · 22 unmodified lines | ||
| 82 | 79 | { 0xd, 8 }, { 0x713, 13 }, { 0x1da, 10 }, { 0x169, 10 }, |
| 83 | 80 | }; |
| 84 | 81 | |
| 85 | −/* dc table 0 */ | |
| 86 | 82 | |
| 87 | −const uint32_t ff_table0_dc_lum[120][2] = { | |
| 83 | +const uint32_t ff_msmp4_dc_tables[2][2][120][2] = { | |
| 84 | +{ | |
| 85 | + /* dc table 0 */ | |
| 86 | + { | |
| 88 | 87 | { 0x1, 1 }, { 0x1, 2 }, { 0x1, 4 }, { 0x1, 5 }, |
| 89 | 88 | { 0x5, 5 }, { 0x7, 5 }, { 0x8, 6 }, { 0xc, 6 }, |
| 90 | 89 | { 0x0, 7 }, { 0x2, 7 }, { 0x12, 7 }, { 0x1a, 7 }, |
| @@ -115,9 +114,8 @@ const uint32_t ff_table0_dc_lum[120][2] = { · 24 unmodified lines | ||
| 115 | 114 | { 0x60784, 24 }, { 0x60785, 24 }, { 0x60786, 24 }, { 0x60787, 24 }, |
| 116 | 115 | { 0x60788, 24 }, { 0x60789, 24 }, { 0x6078a, 24 }, { 0x6078b, 24 }, |
| 117 | 116 | { 0x6078c, 24 }, { 0x6078d, 24 }, { 0x6078e, 24 }, { 0x6078f, 24 }, |
| 118 | −}; | |
| 119 | − | |
| 120 | −const uint32_t ff_table0_dc_chroma[120][2] = { | |
| 117 | + }, | |
| 118 | + { | |
| 121 | 119 | { 0x0, 2 }, { 0x1, 2 }, { 0x5, 3 }, { 0x9, 4 }, |
| 122 | 120 | { 0xd, 4 }, { 0x11, 5 }, { 0x1d, 5 }, { 0x1f, 5 }, |
| 123 | 121 | { 0x21, 6 }, { 0x31, 6 }, { 0x38, 6 }, { 0x33, 6 }, |
| @@ -148,11 +146,11 @@ const uint32_t ff_table0_dc_chroma[120][2] = { · 24 unmodified lines | ||
| 148 | 146 | { 0x608884, 23 }, { 0x608885, 23 }, { 0x608886, 23 }, { 0x608887, 23 }, |
| 149 | 147 | { 0x608888, 23 }, { 0x608889, 23 }, { 0x60888a, 23 }, { 0x60888b, 23 }, |
| 150 | 148 | { 0x60888c, 23 }, { 0x60888d, 23 }, { 0x60888e, 23 }, { 0x60888f, 23 }, |
| 151 | −}; | |
| 152 | − | |
| 153 | −/* dc table 1 */ | |
| 154 | − | |
| 155 | −const uint32_t ff_table1_dc_lum[120][2] = { | |
| 149 | + } | |
| 150 | +}, | |
| 151 | +{ | |
| 152 | + /* dc table 1 */ | |
| 153 | + { | |
| 156 | 154 | { 0x2, 2 }, { 0x3, 2 }, { 0x3, 3 }, { 0x2, 4 }, |
| 157 | 155 | { 0x5, 4 }, { 0x1, 5 }, { 0x3, 5 }, { 0x8, 5 }, |
| 158 | 156 | { 0x0, 6 }, { 0x5, 6 }, { 0xd, 6 }, { 0xf, 6 }, |
| @@ -183,9 +181,8 @@ const uint32_t ff_table1_dc_lum[120][2] = { · 24 unmodified lines | ||
| 183 | 181 | { 0x1e695c, 26 }, { 0x1e695d, 26 }, { 0x1e695e, 26 }, { 0x1e695f, 26 }, |
| 184 | 182 | { 0x1e6960, 26 }, { 0x1e6961, 26 }, { 0x1e6962, 26 }, { 0x1e6963, 26 }, |
| 185 | 183 | { 0x1e6964, 26 }, { 0x1e6965, 26 }, { 0x1e6966, 26 }, { 0x1e6967, 26 }, |
| 186 | −}; | |
| 187 | − | |
| 188 | −const uint32_t ff_table1_dc_chroma[120][2] = { | |
| 184 | + }, | |
| 185 | + { | |
| 189 | 186 | { 0x0, 2 }, { 0x1, 2 }, { 0x4, 3 }, { 0x7, 3 }, |
| 190 | 187 | { 0xb, 4 }, { 0xd, 4 }, { 0x15, 5 }, { 0x28, 6 }, |
| 191 | 188 | { 0x30, 6 }, { 0x32, 6 }, { 0x52, 7 }, { 0x62, 7 }, |
| @@ -216,6 +213,8 @@ const uint32_t ff_table1_dc_chroma[120][2] = { · 24 unmodified lines | ||
| 216 | 213 | { 0x18f6484, 25 }, { 0x18f6485, 25 }, { 0x18f6486, 25 }, { 0x18f6487, 25 }, |
| 217 | 214 | { 0x18f6488, 25 }, { 0x18f6489, 25 }, { 0x18f648a, 25 }, { 0x18f648b, 25 }, |
| 218 | 215 | { 0x18f648c, 25 }, { 0x18f648d, 25 }, { 0x18f648e, 25 }, { 0x18f648f, 25 }, |
| 216 | + } | |
| 217 | +} | |
| 219 | 218 | }; |
| 220 | 219 | |
| 221 | 220 | const uint8_t ff_wmv1_scantable[WMV1_SCANTABLE_COUNT][64] = { |
| @@ -34,10 +34,9 @@ FF_VISIBILITY_PUSH_HIDDEN · 33 unmodified lines | ||
| 34 | 34 | void ff_msmp4_vc1_vlcs_init_once(void); |
| 35 | 35 | |
| 36 | 36 | #define MSMP4_MB_INTRA_VLC_BITS 9 |
| 37 | −extern VLC ff_msmp4_mb_i_vlc; | |
| 37 | +extern VLCElem ff_msmp4_mb_i_vlc[]; | |
| 38 | 38 | #define MSMP4_DC_VLC_BITS 9 |
| 39 | −extern VLC ff_msmp4_dc_luma_vlc[2]; | |
| 40 | −extern VLC ff_msmp4_dc_chroma_vlc[2]; | |
| 39 | +extern const VLCElem *ff_msmp4_dc_vlc[2 /* dc_table_index */][2 /* 0: luma, 1: chroma */]; | |
| 41 | 40 | |
| 42 | 41 | /* intra picture macroblock coded block pattern */ |
| 43 | 42 | extern const uint16_t ff_msmp4_mb_i_table[64][2]; |
| @@ -46,10 +45,7 @@ extern const uint16_t ff_msmp4_mb_i_table[64][2]; · 2 unmodified lines | ||
| 46 | 45 | |
| 47 | 46 | extern const uint8_t ff_wmv1_scantable[WMV1_SCANTABLE_COUNT][64]; |
| 48 | 47 | |
| 49 | −extern const uint32_t ff_table0_dc_lum[120][2]; | |
| 50 | −extern const uint32_t ff_table1_dc_lum[120][2]; | |
| 51 | −extern const uint32_t ff_table0_dc_chroma[120][2]; | |
| 52 | −extern const uint32_t ff_table1_dc_chroma[120][2]; | |
| 48 | +extern const uint32_t ff_msmp4_dc_tables[2 /* dc_table_index */][2 /* 0: luma, 1: chroma */][120][2]; | |
| 53 | 49 | FF_VISIBILITY_POP_HIDDEN |
| 54 | 50 | |
| 55 | 51 | #endif /* AVCODEC_MSMPEG4_VC1_DATA_H */ |
| @@ -237,7 +237,7 @@ static int msmpeg4v34_decode_mb(MpegEncContext *s, int16_t block[6][64]) · 236 unmodified lines | ||
| 237 | 237 | cbp = code & 0x3f; |
| 238 | 238 | } else { |
| 239 | 239 | s->mb_intra = 1; |
| 240 | − code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc.table, MSMP4_MB_INTRA_VLC_BITS, 2); | |
| 240 | + code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc, MSMP4_MB_INTRA_VLC_BITS, 2); | |
| 241 | 241 | /* predict coded block pattern */ |
| 242 | 242 | cbp = 0; |
| 243 | 243 | for(i=0;i<6;i++) { |
| @@ -582,14 +582,9 @@ static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr) · 338 unmodified lines | ||
| 582 | 582 | return -1; |
| 583 | 583 | } |
| 584 | 584 | level-=256; |
| 585 | − }else{ //FIXME optimize use unified tables & index | |
| 586 | − if (n < 4) { | |
| 587 | − level = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, | |
| 588 | − MSMP4_DC_VLC_BITS, 3); | |
| 589 | − } else { | |
| 590 | − level = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, | |
| 591 | − MSMP4_DC_VLC_BITS, 3); | |
| 592 | − } | |
| 585 | + } else { | |
| 586 | + level = get_vlc2(&s->gb, ff_msmp4_dc_vlc[s->dc_table_index][n >= 4], | |
| 587 | + MSMP4_DC_VLC_BITS, 3); | |
| 593 | 588 | |
| 594 | 589 | if (level == DC_MAX) { |
| 595 | 590 | level = get_bits(&s->gb, 8); |
| @@ -544,19 +544,8 @@ static void msmpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr · 543 unmodified lines | ||
| 544 | 544 | if (code > DC_MAX) |
| 545 | 545 | code = DC_MAX; |
| 546 | 546 | |
| 547 | − if (s->dc_table_index == 0) { | |
| 548 | − if (n < 4) { | |
| 549 | − put_bits(&s->pb, ff_table0_dc_lum[code][1], ff_table0_dc_lum[code][0]); | |
| 550 | − } else { | |
| 551 | − put_bits(&s->pb, ff_table0_dc_chroma[code][1], ff_table0_dc_chroma[code][0]); | |
| 552 | − } | |
| 553 | − } else { | |
| 554 | − if (n < 4) { | |
| 555 | − put_bits(&s->pb, ff_table1_dc_lum[code][1], ff_table1_dc_lum[code][0]); | |
| 556 | − } else { | |
| 557 | − put_bits(&s->pb, ff_table1_dc_chroma[code][1], ff_table1_dc_chroma[code][0]); | |
| 558 | − } | |
| 559 | − } | |
| 547 | + put_bits(&s->pb, ff_msmp4_dc_tables[s->dc_table_index][n >= 4][code][1], | |
| 548 | + ff_msmp4_dc_tables[s->dc_table_index][n >= 4][code][0]); | |
| 560 | 549 | |
| 561 | 550 | if (code == DC_MAX) |
| 562 | 551 | put_bits(&s->pb, 8, level); |
| @@ -592,13 +592,8 @@ static int vc1_decode_i_block(VC1Context *v, int16_t block[64], int n, · 591 unmodified lines | ||
| 592 | 592 | int dcdiff, scale; |
| 593 | 593 | |
| 594 | 594 | /* Get DC differential */ |
| 595 | − if (n < 4) { | |
| 596 | − dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, | |
| 597 | − MSMP4_DC_VLC_BITS, 3); | |
| 598 | − } else { | |
| 599 | − dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, | |
| 600 | − MSMP4_DC_VLC_BITS, 3); | |
| 601 | − } | |
| 595 | + dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_vlc[s->dc_table_index][n >= 4], | |
| 596 | + MSMP4_DC_VLC_BITS, 3); | |
| 602 | 597 | if (dcdiff) { |
| 603 | 598 | const int m = (v->pq == 1 || v->pq == 2) ? 3 - v->pq : 0; |
| 604 | 599 | if (dcdiff == 119 /* ESC index value */) { |
| @@ -738,13 +733,8 @@ static int vc1_decode_i_block_adv(VC1Context *v, int16_t block[64], int n, · 133 unmodified lines | ||
| 738 | 733 | int quant = FFABS(mquant); |
| 739 | 734 | |
| 740 | 735 | /* Get DC differential */ |
| 741 | − if (n < 4) { | |
| 742 | − dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, | |
| 743 | − MSMP4_DC_VLC_BITS, 3); | |
| 744 | − } else { | |
| 745 | − dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, | |
| 746 | − MSMP4_DC_VLC_BITS, 3); | |
| 747 | − } | |
| 736 | + dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_vlc[s->dc_table_index][n >= 4], | |
| 737 | + MSMP4_DC_VLC_BITS, 3); | |
| 748 | 738 | if (dcdiff) { |
| 749 | 739 | const int m = (quant == 1 || quant == 2) ? 3 - quant : 0; |
| 750 | 740 | if (dcdiff == 119 /* ESC index value */) { |
| @@ -940,13 +930,8 @@ static int vc1_decode_intra_block(VC1Context *v, int16_t block[64], int n, · 189 unmodified lines | ||
| 940 | 930 | s->c_dc_scale = s->c_dc_scale_table[quant]; |
| 941 | 931 | |
| 942 | 932 | /* Get DC differential */ |
| 943 | − if (n < 4) { | |
| 944 | − dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, | |
| 945 | − MSMP4_DC_VLC_BITS, 3); | |
| 946 | − } else { | |
| 947 | − dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, | |
| 948 | − MSMP4_DC_VLC_BITS, 3); | |
| 949 | − } | |
| 933 | + dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_vlc[s->dc_table_index][n >= 4], | |
| 934 | + MSMP4_DC_VLC_BITS, 3); | |
| 950 | 935 | if (dcdiff) { |
| 951 | 936 | const int m = (quant == 1 || quant == 2) ? 3 - quant : 0; |
| 952 | 937 | if (dcdiff == 119 /* ESC index value */) { |
| @@ -2591,7 +2576,7 @@ static void vc1_decode_i_blocks(VC1Context *v) · 1638 unmodified lines | ||
| 2591 | 2576 | } |
| 2592 | 2577 | |
| 2593 | 2578 | // do actual MB decoding and displaying |
| 2594 | − cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc.table, | |
| 2579 | + cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc, | |
| 2595 | 2580 | MSMP4_MB_INTRA_VLC_BITS, 2); |
| 2596 | 2581 | v->s.ac_pred = get_bits1(&v->s.gb); |
| 2597 | 2582 | |
| @@ -2727,7 +2712,7 @@ static int vc1_decode_i_blocks_adv(VC1Context *v) · 129 unmodified lines | ||
| 2727 | 2712 | return 0; |
| 2728 | 2713 | } |
| 2729 | 2714 | |
| 2730 | − cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc.table, | |
| 2715 | + cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc, | |
| 2731 | 2716 | MSMP4_MB_INTRA_VLC_BITS, 2); |
| 2732 | 2717 | if (v->acpred_is_raw) |
| 2733 | 2718 | v->s.ac_pred = get_bits1(&v->s.gb); |
| @@ -477,7 +477,7 @@ static int wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64]) · 476 unmodified lines | ||
| 477 | 477 | s->mb_intra = 1; |
| 478 | 478 | if (get_bits_left(&s->gb) <= 0) |
| 479 | 479 | return AVERROR_INVALIDDATA; |
| 480 | − code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc.table, | |
| 480 | + code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc, | |
| 481 | 481 | MSMP4_MB_INTRA_VLC_BITS, 2); |
| 482 | 482 | /* predict coded block pattern */ |
| 483 | 483 | cbp = 0; |