Mercurial > libavcodec.hg
comparison rv34.c @ 9568:976a7ad342af libavcodec
Revert changing VLC initialization type for RV3/4 decoder.
While using large static table is not good (especially for embedded devices and
CPUs with small cache), other alternatives are not very good either.
author | kostya |
---|---|
date | Mon, 27 Apr 2009 05:30:22 +0000 |
parents | 6900e4f82110 |
children | 305536ce781f |
comparison
equal
deleted
inserted
replaced
9567:d98ad4678fb0 | 9568:976a7ad342af |
---|---|
59 /** | 59 /** |
60 * @defgroup vlc RV30/40 VLC generating functions | 60 * @defgroup vlc RV30/40 VLC generating functions |
61 * @{ | 61 * @{ |
62 */ | 62 */ |
63 | 63 |
64 static const int table_offs[] = { | |
65 0, 1818, 3622, 4144, 4698, 5234, 5804, 5868, 5900, 5932, | |
66 5996, 6252, 6316, 6348, 6380, 7674, 8944, 10274, 11668, 12250, | |
67 14060, 15846, 16372, 16962, 17512, 18148, 18180, 18212, 18244, 18308, | |
68 18564, 18628, 18660, 18692, 20036, 21314, 22648, 23968, 24614, 26384, | |
69 28190, 28736, 29366, 29938, 30608, 30640, 30672, 30704, 30768, 31024, | |
70 31088, 31120, 31184, 32570, 33898, 35236, 36644, 37286, 39020, 40802, | |
71 41368, 42052, 42692, 43348, 43380, 43412, 43444, 43476, 43604, 43668, | |
72 43700, 43732, 45100, 46430, 47778, 49160, 49802, 51550, 53340, 53972, | |
73 54648, 55348, 55994, 56122, 56154, 56186, 56218, 56346, 56410, 56442, | |
74 56474, 57878, 59290, 60636, 62036, 62682, 64460, 64524, 64588, 64716, | |
75 64844, 66076, 67466, 67978, 68542, 69064, 69648, 70296, 72010, 72074, | |
76 72138, 72202, 72330, 73572, 74936, 75454, 76030, 76566, 77176, 77822, | |
77 79582, 79646, 79678, 79742, 79870, 81180, 82536, 83064, 83672, 84242, | |
78 84934, 85576, 87384, 87448, 87480, 87544, 87672, 88982, 90340, 90902, | |
79 91598, 92182, 92846, 93488, 95246, 95278, 95310, 95374, 95502, 96878, | |
80 98266, 98848, 99542, 100234, 100884, 101524, 103320, 103352, 103384, 103416, | |
81 103480, 104874, 106222, 106910, 107584, 108258, 108902, 109544, 111366, 111398, | |
82 111430, 111462, 111494, 112878, 114320, 114988, 115660, 116310, 116950, 117592 | |
83 }; | |
84 | |
85 static VLC_TYPE table_data[117592][2]; | |
86 | |
64 /** | 87 /** |
65 * Generate VLC from codeword lengths. | 88 * Generate VLC from codeword lengths. |
66 * @param bits codeword lengths (zeroes are accepted) | 89 * @param bits codeword lengths (zeroes are accepted) |
67 * @param size length of input data | 90 * @param size length of input data |
68 * @param vlc output VLC | 91 * @param vlc output VLC |
69 * @param insyms symbols for input codes (NULL for default ones) | 92 * @param insyms symbols for input codes (NULL for default ones) |
70 * @param num VLC table number (for static initialization) | 93 * @param num VLC table number (for static initialization) |
71 */ | 94 */ |
72 static void rv34_gen_vlc(const uint8_t *bits, int size, VLC *vlc, const uint8_t *insyms) | 95 static void rv34_gen_vlc(const uint8_t *bits, int size, VLC *vlc, const uint8_t *insyms, |
96 const int num) | |
73 { | 97 { |
74 int i; | 98 int i; |
75 int counts[17] = {0}, codes[17]; | 99 int counts[17] = {0}, codes[17]; |
76 uint16_t cw[size], syms[size]; | 100 uint16_t cw[size], syms[size]; |
77 uint8_t bits2[size]; | 101 uint8_t bits2[size]; |
91 for(i = 0; i < 16; i++) | 115 for(i = 0; i < 16; i++) |
92 codes[i+1] = (codes[i] + counts[i]) << 1; | 116 codes[i+1] = (codes[i] + counts[i]) << 1; |
93 for(i = 0; i < realsize; i++) | 117 for(i = 0; i < realsize; i++) |
94 cw[i] = codes[bits2[i]]++; | 118 cw[i] = codes[bits2[i]]++; |
95 | 119 |
120 vlc->table = &table_data[table_offs[num]]; | |
121 vlc->table_allocated = table_offs[num + 1] - table_offs[num]; | |
96 init_vlc_sparse(vlc, FFMIN(maxbits, 9), realsize, | 122 init_vlc_sparse(vlc, FFMIN(maxbits, 9), realsize, |
97 bits2, 1, 1, | 123 bits2, 1, 1, |
98 cw, 2, 2, | 124 cw, 2, 2, |
99 syms, 2, 2, 0); | 125 syms, 2, 2, INIT_VLC_USE_NEW_STATIC); |
100 } | 126 } |
101 | 127 |
102 /** | 128 /** |
103 * Initialize all tables. | 129 * Initialize all tables. |
104 */ | 130 */ |
106 { | 132 { |
107 int i, j, k; | 133 int i, j, k; |
108 | 134 |
109 for(i = 0; i < NUM_INTRA_TABLES; i++){ | 135 for(i = 0; i < NUM_INTRA_TABLES; i++){ |
110 for(j = 0; j < 2; j++){ | 136 for(j = 0; j < 2; j++){ |
111 rv34_gen_vlc(rv34_table_intra_cbppat [i][j], CBPPAT_VLC_SIZE, &intra_vlcs[i].cbppattern[j], NULL); | 137 rv34_gen_vlc(rv34_table_intra_cbppat [i][j], CBPPAT_VLC_SIZE, &intra_vlcs[i].cbppattern[j], NULL, 19*i + 0 + j); |
112 rv34_gen_vlc(rv34_table_intra_secondpat[i][j], OTHERBLK_VLC_SIZE, &intra_vlcs[i].second_pattern[j], NULL); | 138 rv34_gen_vlc(rv34_table_intra_secondpat[i][j], OTHERBLK_VLC_SIZE, &intra_vlcs[i].second_pattern[j], NULL, 19*i + 2 + j); |
113 rv34_gen_vlc(rv34_table_intra_thirdpat [i][j], OTHERBLK_VLC_SIZE, &intra_vlcs[i].third_pattern[j], NULL); | 139 rv34_gen_vlc(rv34_table_intra_thirdpat [i][j], OTHERBLK_VLC_SIZE, &intra_vlcs[i].third_pattern[j], NULL, 19*i + 4 + j); |
114 for(k = 0; k < 4; k++){ | 140 for(k = 0; k < 4; k++){ |
115 rv34_gen_vlc(rv34_table_intra_cbp[i][j+k*2], CBP_VLC_SIZE, &intra_vlcs[i].cbp[j][k], rv34_cbp_code); | 141 rv34_gen_vlc(rv34_table_intra_cbp[i][j+k*2], CBP_VLC_SIZE, &intra_vlcs[i].cbp[j][k], rv34_cbp_code, 19*i + 6 + j*4 + k); |
116 } | 142 } |
117 } | 143 } |
118 for(j = 0; j < 4; j++){ | 144 for(j = 0; j < 4; j++){ |
119 rv34_gen_vlc(rv34_table_intra_firstpat[i][j], FIRSTBLK_VLC_SIZE, &intra_vlcs[i].first_pattern[j], NULL); | 145 rv34_gen_vlc(rv34_table_intra_firstpat[i][j], FIRSTBLK_VLC_SIZE, &intra_vlcs[i].first_pattern[j], NULL, 19*i + 14 + j); |
120 } | 146 } |
121 rv34_gen_vlc(rv34_intra_coeff[i], COEFF_VLC_SIZE, &intra_vlcs[i].coefficient, NULL); | 147 rv34_gen_vlc(rv34_intra_coeff[i], COEFF_VLC_SIZE, &intra_vlcs[i].coefficient, NULL, 19*i + 18); |
122 } | 148 } |
123 | 149 |
124 for(i = 0; i < NUM_INTER_TABLES; i++){ | 150 for(i = 0; i < NUM_INTER_TABLES; i++){ |
125 rv34_gen_vlc(rv34_inter_cbppat[i], CBPPAT_VLC_SIZE, &inter_vlcs[i].cbppattern[0], NULL); | 151 rv34_gen_vlc(rv34_inter_cbppat[i], CBPPAT_VLC_SIZE, &inter_vlcs[i].cbppattern[0], NULL, i*12 + 95); |
126 for(j = 0; j < 4; j++){ | 152 for(j = 0; j < 4; j++){ |
127 rv34_gen_vlc(rv34_inter_cbp[i][j], CBP_VLC_SIZE, &inter_vlcs[i].cbp[0][j], rv34_cbp_code); | 153 rv34_gen_vlc(rv34_inter_cbp[i][j], CBP_VLC_SIZE, &inter_vlcs[i].cbp[0][j], rv34_cbp_code, i*12 + 96 + j); |
128 } | 154 } |
129 for(j = 0; j < 2; j++){ | 155 for(j = 0; j < 2; j++){ |
130 rv34_gen_vlc(rv34_table_inter_firstpat [i][j], FIRSTBLK_VLC_SIZE, &inter_vlcs[i].first_pattern[j], NULL); | 156 rv34_gen_vlc(rv34_table_inter_firstpat [i][j], FIRSTBLK_VLC_SIZE, &inter_vlcs[i].first_pattern[j], NULL, i*12 + 100 + j); |
131 rv34_gen_vlc(rv34_table_inter_secondpat[i][j], OTHERBLK_VLC_SIZE, &inter_vlcs[i].second_pattern[j], NULL); | 157 rv34_gen_vlc(rv34_table_inter_secondpat[i][j], OTHERBLK_VLC_SIZE, &inter_vlcs[i].second_pattern[j], NULL, i*12 + 102 + j); |
132 rv34_gen_vlc(rv34_table_inter_thirdpat [i][j], OTHERBLK_VLC_SIZE, &inter_vlcs[i].third_pattern[j], NULL); | 158 rv34_gen_vlc(rv34_table_inter_thirdpat [i][j], OTHERBLK_VLC_SIZE, &inter_vlcs[i].third_pattern[j], NULL, i*12 + 104 + j); |
133 } | 159 } |
134 rv34_gen_vlc(rv34_inter_coeff[i], COEFF_VLC_SIZE, &inter_vlcs[i].coefficient, NULL); | 160 rv34_gen_vlc(rv34_inter_coeff[i], COEFF_VLC_SIZE, &inter_vlcs[i].coefficient, NULL, i*12 + 106); |
135 } | |
136 } | |
137 | |
138 /** | |
139 * Initialize all tables. | |
140 */ | |
141 static av_cold void rv34_free_tables(void) | |
142 { | |
143 int i, j, k; | |
144 | |
145 for(i = 0; i < NUM_INTRA_TABLES; i++){ | |
146 for(j = 0; j < 2; j++){ | |
147 free_vlc(&intra_vlcs[i].cbppattern[j]); | |
148 free_vlc(&intra_vlcs[i].second_pattern[j]); | |
149 free_vlc(&intra_vlcs[i].third_pattern[j]); | |
150 for(k = 0; k < 4; k++){ | |
151 free_vlc(&intra_vlcs[i].cbp[j][k]); | |
152 } | |
153 } | |
154 for(j = 0; j < 4; j++){ | |
155 free_vlc(&intra_vlcs[i].first_pattern[j]); | |
156 } | |
157 free_vlc(&intra_vlcs[i].coefficient); | |
158 } | |
159 | |
160 for(i = 0; i < NUM_INTER_TABLES; i++){ | |
161 free_vlc(&inter_vlcs[i].cbppattern[0]); | |
162 for(j = 0; j < 4; j++){ | |
163 free_vlc(&inter_vlcs[i].cbp[0][j]); | |
164 } | |
165 for(j = 0; j < 2; j++){ | |
166 free_vlc(&inter_vlcs[i].first_pattern[j]); | |
167 free_vlc(&inter_vlcs[i].second_pattern[j]); | |
168 free_vlc(&inter_vlcs[i].third_pattern[j]); | |
169 } | |
170 free_vlc(&inter_vlcs[i].coefficient); | |
171 } | 161 } |
172 } | 162 } |
173 | 163 |
174 /** @} */ // vlc group | 164 /** @} */ // vlc group |
175 | 165 |
1394 | 1384 |
1395 r->cbp_luma = av_malloc(r->s.mb_stride * r->s.mb_height * sizeof(*r->cbp_luma)); | 1385 r->cbp_luma = av_malloc(r->s.mb_stride * r->s.mb_height * sizeof(*r->cbp_luma)); |
1396 r->cbp_chroma = av_malloc(r->s.mb_stride * r->s.mb_height * sizeof(*r->cbp_chroma)); | 1386 r->cbp_chroma = av_malloc(r->s.mb_stride * r->s.mb_height * sizeof(*r->cbp_chroma)); |
1397 r->deblock_coefs = av_malloc(r->s.mb_stride * r->s.mb_height * sizeof(*r->deblock_coefs)); | 1387 r->deblock_coefs = av_malloc(r->s.mb_stride * r->s.mb_height * sizeof(*r->deblock_coefs)); |
1398 | 1388 |
1399 rv34_init_tables(); | 1389 if(!intra_vlcs[0].cbppattern[0].bits) |
1390 rv34_init_tables(); | |
1400 | 1391 |
1401 return 0; | 1392 return 0; |
1402 } | 1393 } |
1403 | 1394 |
1404 static int get_slice_offset(AVCodecContext *avctx, const uint8_t *buf, int n) | 1395 static int get_slice_offset(AVCodecContext *avctx, const uint8_t *buf, int n) |
1516 av_cold int ff_rv34_decode_end(AVCodecContext *avctx) | 1507 av_cold int ff_rv34_decode_end(AVCodecContext *avctx) |
1517 { | 1508 { |
1518 RV34DecContext *r = avctx->priv_data; | 1509 RV34DecContext *r = avctx->priv_data; |
1519 | 1510 |
1520 MPV_common_end(&r->s); | 1511 MPV_common_end(&r->s); |
1521 rv34_free_tables(); | |
1522 | 1512 |
1523 av_freep(&r->intra_types_hist); | 1513 av_freep(&r->intra_types_hist); |
1524 r->intra_types = NULL; | 1514 r->intra_types = NULL; |
1525 av_freep(&r->mb_type); | 1515 av_freep(&r->mb_type); |
1526 av_freep(&r->cbp_luma); | 1516 av_freep(&r->cbp_luma); |