History

avcodec/msmpeg4_vc1_data: 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. Also combine the ff_msmp4_dc_(luma|chroma)_vlcs as well as the tables used to generate them to simplify the code.

Andreas Rheinhardt committed 3 years ago

Commit 7902c0d1 parent ff886fc6 files · +48 −84Browse files

Unified · Split

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

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