Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * RV30/40 decoder common data | ||
3 | * Copyright (c) 2007 Mike Melanson, Konstantin Shishkov | ||
4 | * | ||
5 | * This file is part of FFmpeg. | ||
6 | * | ||
7 | * FFmpeg is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU Lesser General Public | ||
9 | * License as published by the Free Software Foundation; either | ||
10 | * version 2.1 of the License, or (at your option) any later version. | ||
11 | * | ||
12 | * FFmpeg is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * Lesser General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU Lesser General Public | ||
18 | * License along with FFmpeg; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | */ | ||
21 | |||
22 | /** | ||
23 | * @file | ||
24 | * RV30/40 decoder common data | ||
25 | */ | ||
26 | |||
27 | #include "libavutil/avassert.h" | ||
28 | #include "libavutil/imgutils.h" | ||
29 | #include "libavutil/internal.h" | ||
30 | #include "libavutil/mem_internal.h" | ||
31 | #include "libavutil/thread.h" | ||
32 | |||
33 | #include "avcodec.h" | ||
34 | #include "decode.h" | ||
35 | #include "error_resilience.h" | ||
36 | #include "mpegutils.h" | ||
37 | #include "mpegvideo.h" | ||
38 | #include "mpegvideodec.h" | ||
39 | #include "golomb.h" | ||
40 | #include "mathops.h" | ||
41 | #include "mpeg_er.h" | ||
42 | #include "qpeldsp.h" | ||
43 | #include "rectangle.h" | ||
44 | #include "thread.h" | ||
45 | #include "threadframe.h" | ||
46 | |||
47 | #include "rv34vlc.h" | ||
48 | #include "rv34data.h" | ||
49 | #include "rv34.h" | ||
50 | |||
51 | 456145 | static inline void ZERO8x2(void* dst, int stride) | |
52 | { | ||
53 | 456145 | fill_rectangle(dst, 1, 2, stride, 0, 4); | |
54 | 456145 | fill_rectangle(((uint8_t*)(dst))+4, 1, 2, stride, 0, 4); | |
55 | 456145 | } | |
56 | |||
57 | /** translation of RV30/40 macroblock types to lavc ones */ | ||
58 | static const int rv34_mb_type_to_lavc[12] = { | ||
59 | MB_TYPE_INTRA, | ||
60 | MB_TYPE_INTRA16x16 | MB_TYPE_SEPARATE_DC, | ||
61 | MB_TYPE_16x16 | MB_TYPE_L0, | ||
62 | MB_TYPE_8x8 | MB_TYPE_L0, | ||
63 | MB_TYPE_16x16 | MB_TYPE_L0, | ||
64 | MB_TYPE_16x16 | MB_TYPE_L1, | ||
65 | MB_TYPE_SKIP, | ||
66 | MB_TYPE_DIRECT2 | MB_TYPE_16x16, | ||
67 | MB_TYPE_16x8 | MB_TYPE_L0, | ||
68 | MB_TYPE_8x16 | MB_TYPE_L0, | ||
69 | MB_TYPE_16x16 | MB_TYPE_L0L1, | ||
70 | MB_TYPE_16x16 | MB_TYPE_L0 | MB_TYPE_SEPARATE_DC | ||
71 | }; | ||
72 | |||
73 | |||
74 | static RV34VLC intra_vlcs[NUM_INTRA_TABLES], inter_vlcs[NUM_INTER_TABLES]; | ||
75 | |||
76 | static int rv34_decode_mv(RV34DecContext *r, int block_type); | ||
77 | |||
78 | /** | ||
79 | * @name RV30/40 VLC generating functions | ||
80 | * @{ | ||
81 | */ | ||
82 | |||
83 | static VLCElem table_data[117592]; | ||
84 | |||
85 | /** | ||
86 | * Generate VLC from codeword lengths. | ||
87 | * @param bits codeword lengths (zeroes are accepted) | ||
88 | * @param size length of input data | ||
89 | * @param vlc output VLC | ||
90 | * @param insyms symbols for input codes (NULL for default ones) | ||
91 | * @param num VLC table number (for static initialization) | ||
92 | */ | ||
93 | 895 | static av_cold void rv34_gen_vlc_ext(const uint8_t *bits, int size, VLC *vlc, | |
94 | const uint8_t *syms, int *offset) | ||
95 | { | ||
96 | 895 | int counts[17] = {0}, codes[17]; | |
97 | uint16_t cw[MAX_VLC_SIZE]; | ||
98 | int maxbits; | ||
99 | |||
100 |
2/2✓ Branch 0 taken 290320 times.
✓ Branch 1 taken 895 times.
|
291215 | for (int i = 0; i < size; i++) |
101 | 290320 | counts[bits[i]]++; | |
102 | |||
103 | /* bits[0] is zero for some tables, i.e. syms actually starts at 1. | ||
104 | * So we reset it here. The code assigned to this element is 0x00. */ | ||
105 | 895 | codes[0] = counts[0] = 0; | |
106 |
2/2✓ Branch 0 taken 14320 times.
✓ Branch 1 taken 895 times.
|
15215 | for (int i = 0; i < 16; i++) { |
107 | 14320 | codes[i+1] = (codes[i] + counts[i]) << 1; | |
108 |
2/2✓ Branch 0 taken 8095 times.
✓ Branch 1 taken 6225 times.
|
14320 | if (counts[i]) |
109 | 8095 | maxbits = i; | |
110 | } | ||
111 |
2/2✓ Branch 0 taken 290320 times.
✓ Branch 1 taken 895 times.
|
291215 | for (int i = 0; i < size; i++) |
112 | 290320 | cw[i] = codes[bits[i]]++; | |
113 | |||
114 | 895 | vlc->table = &table_data[*offset]; | |
115 | 895 | vlc->table_allocated = FF_ARRAY_ELEMS(table_data) - *offset; | |
116 | 895 | ff_vlc_init_sparse(vlc, FFMIN(maxbits, 9), size, | |
117 | bits, 1, 1, | ||
118 | cw, 2, 2, | ||
119 | syms, !!syms, !!syms, VLC_INIT_STATIC_OVERLONG); | ||
120 | 895 | *offset += vlc->table_size; | |
121 | 895 | } | |
122 | |||
123 | 555 | static av_cold void rv34_gen_vlc(const uint8_t *bits, int size, const VLCElem **vlcp, | |
124 | int *offset) | ||
125 | { | ||
126 | 555 | VLC vlc = { 0 }; | |
127 | 555 | rv34_gen_vlc_ext(bits, size, &vlc, NULL, offset); | |
128 | 555 | *vlcp = vlc.table; | |
129 | 555 | } | |
130 | |||
131 | /** | ||
132 | * Initialize all tables. | ||
133 | */ | ||
134 | 5 | static av_cold void rv34_init_tables(void) | |
135 | { | ||
136 | 5 | int i, j, k, offset = 0; | |
137 | |||
138 |
2/2✓ Branch 0 taken 25 times.
✓ Branch 1 taken 5 times.
|
30 | for(i = 0; i < NUM_INTRA_TABLES; i++){ |
139 |
2/2✓ Branch 0 taken 50 times.
✓ Branch 1 taken 25 times.
|
75 | for(j = 0; j < 2; j++){ |
140 | 50 | rv34_gen_vlc(rv34_table_intra_cbppat [i][j], CBPPAT_VLC_SIZE, | |
141 | &intra_vlcs[i].cbppattern[j], &offset); | ||
142 | 50 | rv34_gen_vlc(rv34_table_intra_secondpat[i][j], OTHERBLK_VLC_SIZE, | |
143 | &intra_vlcs[i].second_pattern[j], &offset); | ||
144 | 50 | rv34_gen_vlc(rv34_table_intra_thirdpat [i][j], OTHERBLK_VLC_SIZE, | |
145 | &intra_vlcs[i].third_pattern[j], &offset); | ||
146 |
2/2✓ Branch 0 taken 200 times.
✓ Branch 1 taken 50 times.
|
250 | for(k = 0; k < 4; k++){ |
147 | 200 | rv34_gen_vlc_ext(rv34_table_intra_cbp[i][j+k*2], CBP_VLC_SIZE, | |
148 | &intra_vlcs[i].cbp[j][k], rv34_cbp_code, &offset); | ||
149 | } | ||
150 | } | ||
151 |
2/2✓ Branch 0 taken 100 times.
✓ Branch 1 taken 25 times.
|
125 | for(j = 0; j < 4; j++){ |
152 | 100 | rv34_gen_vlc(rv34_table_intra_firstpat[i][j], FIRSTBLK_VLC_SIZE, | |
153 | &intra_vlcs[i].first_pattern[j], &offset); | ||
154 | } | ||
155 | 25 | rv34_gen_vlc(rv34_intra_coeff[i], COEFF_VLC_SIZE, | |
156 | &intra_vlcs[i].coefficient, &offset); | ||
157 | } | ||
158 | |||
159 |
2/2✓ Branch 0 taken 35 times.
✓ Branch 1 taken 5 times.
|
40 | for(i = 0; i < NUM_INTER_TABLES; i++){ |
160 | 35 | rv34_gen_vlc(rv34_inter_cbppat[i], CBPPAT_VLC_SIZE, | |
161 | &inter_vlcs[i].cbppattern[0], &offset); | ||
162 |
2/2✓ Branch 0 taken 140 times.
✓ Branch 1 taken 35 times.
|
175 | for(j = 0; j < 4; j++){ |
163 | 140 | rv34_gen_vlc_ext(rv34_inter_cbp[i][j], CBP_VLC_SIZE, | |
164 | &inter_vlcs[i].cbp[0][j], rv34_cbp_code, &offset); | ||
165 | } | ||
166 |
2/2✓ Branch 0 taken 70 times.
✓ Branch 1 taken 35 times.
|
105 | for(j = 0; j < 2; j++){ |
167 | 70 | rv34_gen_vlc(rv34_table_inter_firstpat [i][j], FIRSTBLK_VLC_SIZE, | |
168 | &inter_vlcs[i].first_pattern[j], &offset); | ||
169 | 70 | rv34_gen_vlc(rv34_table_inter_secondpat[i][j], OTHERBLK_VLC_SIZE, | |
170 | &inter_vlcs[i].second_pattern[j], &offset); | ||
171 | 70 | rv34_gen_vlc(rv34_table_inter_thirdpat [i][j], OTHERBLK_VLC_SIZE, | |
172 | &inter_vlcs[i].third_pattern[j], &offset); | ||
173 | } | ||
174 | 35 | rv34_gen_vlc(rv34_inter_coeff[i], COEFF_VLC_SIZE, | |
175 | &inter_vlcs[i].coefficient, &offset); | ||
176 | } | ||
177 | 5 | } | |
178 | |||
179 | /** @} */ // vlc group | ||
180 | |||
181 | /** | ||
182 | * @name RV30/40 4x4 block decoding functions | ||
183 | * @{ | ||
184 | */ | ||
185 | |||
186 | /** | ||
187 | * Decode coded block pattern. | ||
188 | */ | ||
189 | 129797 | static int rv34_decode_cbp(GetBitContext *gb, const RV34VLC *vlc, int table) | |
190 | { | ||
191 | 129797 | int pattern, code, cbp=0; | |
192 | int ones; | ||
193 | static const int cbp_masks[3] = {0x100000, 0x010000, 0x110000}; | ||
194 | static const int shifts[4] = { 0, 2, 8, 10 }; | ||
195 | 129797 | const int *curshift = shifts; | |
196 | int i, t, mask; | ||
197 | |||
198 | 129797 | code = get_vlc2(gb, vlc->cbppattern[table], 9, 2); | |
199 | 129797 | pattern = code & 0xF; | |
200 | 129797 | code >>= 4; | |
201 | |||
202 | 129797 | ones = rv34_count_ones[pattern]; | |
203 | |||
204 |
2/2✓ Branch 0 taken 519188 times.
✓ Branch 1 taken 129797 times.
|
648985 | for(mask = 8; mask; mask >>= 1, curshift++){ |
205 |
2/2✓ Branch 0 taken 182266 times.
✓ Branch 1 taken 336922 times.
|
519188 | if(pattern & mask) |
206 | 182266 | cbp |= get_vlc2(gb, vlc->cbp[table][ones].table, vlc->cbp[table][ones].bits, 1) << curshift[0]; | |
207 | } | ||
208 | |||
209 |
2/2✓ Branch 0 taken 519188 times.
✓ Branch 1 taken 129797 times.
|
648985 | for(i = 0; i < 4; i++){ |
210 | 519188 | t = (modulo_three_table[code] >> (6 - 2*i)) & 3; | |
211 |
2/2✓ Branch 0 taken 121686 times.
✓ Branch 1 taken 397502 times.
|
519188 | if(t == 1) |
212 | 121686 | cbp |= cbp_masks[get_bits1(gb)] << i; | |
213 |
2/2✓ Branch 0 taken 59528 times.
✓ Branch 1 taken 459660 times.
|
519188 | if(t == 2) |
214 | 59528 | cbp |= cbp_masks[2] << i; | |
215 | } | ||
216 | 129797 | return cbp; | |
217 | } | ||
218 | |||
219 | /** | ||
220 | * Get one coefficient value from the bitstream and store it. | ||
221 | */ | ||
222 | 2281776 | static inline void decode_coeff(int16_t *dst, int coef, int esc, GetBitContext *gb, | |
223 | const VLCElem *vlc, int q) | ||
224 | { | ||
225 |
2/2✓ Branch 0 taken 1164928 times.
✓ Branch 1 taken 1116848 times.
|
2281776 | if(coef){ |
226 |
2/2✓ Branch 0 taken 159313 times.
✓ Branch 1 taken 1005615 times.
|
1164928 | if(coef == esc){ |
227 | 159313 | coef = get_vlc2(gb, vlc, 9, 2); | |
228 |
2/2✓ Branch 0 taken 139 times.
✓ Branch 1 taken 159174 times.
|
159313 | if(coef > 23){ |
229 | 139 | coef -= 23; | |
230 | 139 | coef = 22 + ((1 << coef) | get_bits(gb, coef)); | |
231 | } | ||
232 | 159313 | coef += esc; | |
233 | } | ||
234 |
2/2✓ Branch 1 taken 575045 times.
✓ Branch 2 taken 589883 times.
|
1164928 | if(get_bits1(gb)) |
235 | 575045 | coef = -coef; | |
236 | 1164928 | *dst = (coef*q + 8) >> 4; | |
237 | } | ||
238 | 2281776 | } | |
239 | |||
240 | /** | ||
241 | * Decode 2x2 subblock of coefficients. | ||
242 | */ | ||
243 | 135049 | static inline void decode_subblock(int16_t *dst, int code, const int is_block2, | |
244 | GetBitContext *gb, const VLCElem *vlc, int q) | ||
245 | { | ||
246 | 135049 | int flags = modulo_three_table[code]; | |
247 | |||
248 | 135049 | decode_coeff( dst+0*4+0, (flags >> 6) , 3, gb, vlc, q); | |
249 |
2/2✓ Branch 0 taken 83836 times.
✓ Branch 1 taken 51213 times.
|
135049 | if(is_block2){ |
250 | 83836 | decode_coeff(dst+1*4+0, (flags >> 4) & 3, 2, gb, vlc, q); | |
251 | 83836 | decode_coeff(dst+0*4+1, (flags >> 2) & 3, 2, gb, vlc, q); | |
252 | }else{ | ||
253 | 51213 | decode_coeff(dst+0*4+1, (flags >> 4) & 3, 2, gb, vlc, q); | |
254 | 51213 | decode_coeff(dst+1*4+0, (flags >> 2) & 3, 2, gb, vlc, q); | |
255 | } | ||
256 | 135049 | decode_coeff( dst+1*4+1, (flags >> 0) & 3, 2, gb, vlc, q); | |
257 | 135049 | } | |
258 | |||
259 | /** | ||
260 | * Decode a single coefficient. | ||
261 | */ | ||
262 | 406616 | static inline void decode_subblock1(int16_t *dst, int code, GetBitContext *gb, | |
263 | const VLCElem *vlc, int q) | ||
264 | { | ||
265 | 406616 | int coeff = modulo_three_table[code] >> 6; | |
266 | 406616 | decode_coeff(dst, coeff, 3, gb, vlc, q); | |
267 | 406616 | } | |
268 | |||
269 | 333741 | static inline void decode_subblock3(int16_t *dst, int code, GetBitContext *gb, | |
270 | const VLCElem *vlc, | ||
271 | int q_dc, int q_ac1, int q_ac2) | ||
272 | { | ||
273 | 333741 | int flags = modulo_three_table[code]; | |
274 | |||
275 | 333741 | decode_coeff(dst+0*4+0, (flags >> 6) , 3, gb, vlc, q_dc); | |
276 | 333741 | decode_coeff(dst+0*4+1, (flags >> 4) & 3, 2, gb, vlc, q_ac1); | |
277 | 333741 | decode_coeff(dst+1*4+0, (flags >> 2) & 3, 2, gb, vlc, q_ac1); | |
278 | 333741 | decode_coeff(dst+1*4+1, (flags >> 0) & 3, 2, gb, vlc, q_ac2); | |
279 | 333741 | } | |
280 | |||
281 | /** | ||
282 | * Decode coefficients for 4x4 block. | ||
283 | * | ||
284 | * This is done by filling 2x2 subblocks with decoded coefficients | ||
285 | * in this order (the same for subblocks and subblock coefficients): | ||
286 | * o--o | ||
287 | * / | ||
288 | * / | ||
289 | * o--o | ||
290 | */ | ||
291 | |||
292 | 740357 | static int rv34_decode_block(int16_t *dst, GetBitContext *gb, const RV34VLC *rvlc, | |
293 | int fc, int sc, int q_dc, int q_ac1, int q_ac2) | ||
294 | { | ||
295 | 740357 | int code, pattern, has_ac = 1; | |
296 | |||
297 | 740357 | code = get_vlc2(gb, rvlc->first_pattern[fc], 9, 2); | |
298 | |||
299 | 740357 | pattern = code & 0x7; | |
300 | |||
301 | 740357 | code >>= 3; | |
302 | |||
303 |
2/2✓ Branch 0 taken 333741 times.
✓ Branch 1 taken 406616 times.
|
740357 | if (modulo_three_table[code] & 0x3F) { |
304 | 333741 | decode_subblock3(dst, code, gb, rvlc->coefficient, q_dc, q_ac1, q_ac2); | |
305 | } else { | ||
306 | 406616 | decode_subblock1(dst, code, gb, rvlc->coefficient, q_dc); | |
307 |
2/2✓ Branch 0 taken 365422 times.
✓ Branch 1 taken 41194 times.
|
406616 | if (!pattern) |
308 | 365422 | return 0; | |
309 | 41194 | has_ac = 0; | |
310 | } | ||
311 | |||
312 |
2/2✓ Branch 0 taken 44969 times.
✓ Branch 1 taken 329966 times.
|
374935 | if(pattern & 4){ |
313 | 44969 | code = get_vlc2(gb, rvlc->second_pattern[sc], 9, 2); | |
314 | 44969 | decode_subblock(dst + 4*0+2, code, 0, gb, rvlc->coefficient, q_ac2); | |
315 | } | ||
316 |
2/2✓ Branch 0 taken 83836 times.
✓ Branch 1 taken 291099 times.
|
374935 | if(pattern & 2){ // Looks like coefficients 1 and 2 are swapped for this block |
317 | 83836 | code = get_vlc2(gb, rvlc->second_pattern[sc], 9, 2); | |
318 | 83836 | decode_subblock(dst + 4*2+0, code, 1, gb, rvlc->coefficient, q_ac2); | |
319 | } | ||
320 |
2/2✓ Branch 0 taken 6244 times.
✓ Branch 1 taken 368691 times.
|
374935 | if(pattern & 1){ |
321 | 6244 | code = get_vlc2(gb, rvlc->third_pattern[sc], 9, 2); | |
322 | 6244 | decode_subblock(dst + 4*2+2, code, 0, gb, rvlc->coefficient, q_ac2); | |
323 | } | ||
324 | 374935 | return has_ac | pattern; | |
325 | } | ||
326 | |||
327 | /** | ||
328 | * @name RV30/40 bitstream parsing | ||
329 | * @{ | ||
330 | */ | ||
331 | |||
332 | /** | ||
333 | * Decode starting slice position. | ||
334 | * @todo Maybe replace with ff_h263_decode_mba() ? | ||
335 | */ | ||
336 | 2782 | int ff_rv34_get_start_offset(GetBitContext *gb, int mb_size) | |
337 | { | ||
338 | int i; | ||
339 |
1/2✓ Branch 0 taken 10416 times.
✗ Branch 1 not taken.
|
10416 | for(i = 0; i < 5; i++) |
340 |
2/2✓ Branch 0 taken 2782 times.
✓ Branch 1 taken 7634 times.
|
10416 | if(rv34_mb_max_sizes[i] >= mb_size - 1) |
341 | 2782 | break; | |
342 | 2782 | return rv34_mb_bits_sizes[i]; | |
343 | } | ||
344 | |||
345 | /** | ||
346 | * Select VLC set for decoding from current quantizer, modifier and frame type. | ||
347 | */ | ||
348 | 130895 | static inline RV34VLC* choose_vlc_set(int quant, int mod, int type) | |
349 | { | ||
350 |
4/4✓ Branch 0 taken 60858 times.
✓ Branch 1 taken 70037 times.
✓ Branch 2 taken 60381 times.
✓ Branch 3 taken 477 times.
|
130895 | if(mod == 2 && quant < 19) quant += 10; |
351 |
3/4✓ Branch 0 taken 24464 times.
✓ Branch 1 taken 46050 times.
✓ Branch 2 taken 24464 times.
✗ Branch 3 not taken.
|
70514 | else if(mod && quant < 26) quant += 5; |
352 | av_assert2(quant >= 0 && quant < 32); | ||
353 | 98339 | return type ? &inter_vlcs[rv34_quant_to_vlc_set[1][quant]] | |
354 |
2/2✓ Branch 0 taken 98339 times.
✓ Branch 1 taken 32556 times.
|
130895 | : &intra_vlcs[rv34_quant_to_vlc_set[0][quant]]; |
355 | } | ||
356 | |||
357 | /** | ||
358 | * Decode intra macroblock header and return CBP in case of success, -1 otherwise. | ||
359 | */ | ||
360 | 7640 | static int rv34_decode_intra_mb_header(RV34DecContext *r, int8_t *intra_types) | |
361 | { | ||
362 | 7640 | MpegEncContext *s = &r->s; | |
363 | 7640 | GetBitContext *gb = &s->gb; | |
364 | 7640 | int mb_pos = s->mb_x + s->mb_y * s->mb_stride; | |
365 | int t; | ||
366 | |||
367 | 7640 | r->is16 = get_bits1(gb); | |
368 |
2/2✓ Branch 0 taken 5830 times.
✓ Branch 1 taken 1810 times.
|
7640 | if(r->is16){ |
369 | 5830 | s->current_picture_ptr->mb_type[mb_pos] = MB_TYPE_INTRA16x16; | |
370 | 5830 | r->block_type = RV34_MB_TYPE_INTRA16x16; | |
371 | 5830 | t = get_bits(gb, 2); | |
372 | 5830 | fill_rectangle(intra_types, 4, 4, r->intra_types_stride, t, sizeof(intra_types[0])); | |
373 | 5830 | r->luma_vlc = 2; | |
374 | }else{ | ||
375 |
2/2✓ Branch 0 taken 467 times.
✓ Branch 1 taken 1343 times.
|
1810 | if(!r->rv30){ |
376 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 467 times.
|
467 | if(!get_bits1(gb)) |
377 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Need DQUANT\n"); | |
378 | } | ||
379 | 1810 | s->current_picture_ptr->mb_type[mb_pos] = MB_TYPE_INTRA; | |
380 | 1810 | r->block_type = RV34_MB_TYPE_INTRA; | |
381 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1810 times.
|
1810 | if(r->decode_intra_types(r, gb, intra_types) < 0) |
382 | ✗ | return -1; | |
383 | 1810 | r->luma_vlc = 1; | |
384 | } | ||
385 | |||
386 | 7640 | r->chroma_vlc = 0; | |
387 | 7640 | r->cur_vlcs = choose_vlc_set(r->si.quant, r->si.vlc_set, 0); | |
388 | |||
389 | 7640 | return rv34_decode_cbp(gb, r->cur_vlcs, r->is16); | |
390 | } | ||
391 | |||
392 | /** | ||
393 | * Decode inter macroblock header and return CBP in case of success, -1 otherwise. | ||
394 | */ | ||
395 | 286080 | static int rv34_decode_inter_mb_header(RV34DecContext *r, int8_t *intra_types) | |
396 | { | ||
397 | 286080 | MpegEncContext *s = &r->s; | |
398 | 286080 | GetBitContext *gb = &s->gb; | |
399 | 286080 | int mb_pos = s->mb_x + s->mb_y * s->mb_stride; | |
400 | int i, t; | ||
401 | |||
402 | 286080 | r->block_type = r->decode_mb_info(r); | |
403 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 286080 times.
|
286080 | if(r->block_type == -1) |
404 | ✗ | return -1; | |
405 | 286080 | s->current_picture_ptr->mb_type[mb_pos] = rv34_mb_type_to_lavc[r->block_type]; | |
406 | 286080 | r->mb_type[mb_pos] = r->block_type; | |
407 |
2/2✓ Branch 0 taken 163923 times.
✓ Branch 1 taken 122157 times.
|
286080 | if(r->block_type == RV34_MB_SKIP){ |
408 |
2/2✓ Branch 0 taken 31715 times.
✓ Branch 1 taken 132208 times.
|
163923 | if(s->pict_type == AV_PICTURE_TYPE_P) |
409 | 31715 | r->mb_type[mb_pos] = RV34_MB_P_16x16; | |
410 |
2/2✓ Branch 0 taken 132208 times.
✓ Branch 1 taken 31715 times.
|
163923 | if(s->pict_type == AV_PICTURE_TYPE_B) |
411 | 132208 | r->mb_type[mb_pos] = RV34_MB_B_DIRECT; | |
412 | } | ||
413 | 286080 | r->is16 = !!IS_INTRA16x16(s->current_picture_ptr->mb_type[mb_pos]); | |
414 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 286080 times.
|
286080 | if (rv34_decode_mv(r, r->block_type) < 0) |
415 | ✗ | return -1; | |
416 |
2/2✓ Branch 0 taken 163923 times.
✓ Branch 1 taken 122157 times.
|
286080 | if(r->block_type == RV34_MB_SKIP){ |
417 | 163923 | fill_rectangle(intra_types, 4, 4, r->intra_types_stride, 0, sizeof(intra_types[0])); | |
418 | 163923 | return 0; | |
419 | } | ||
420 | 122157 | r->chroma_vlc = 1; | |
421 | 122157 | r->luma_vlc = 0; | |
422 | |||
423 |
2/2✓ Branch 0 taken 24367 times.
✓ Branch 1 taken 97790 times.
|
122157 | if(IS_INTRA(s->current_picture_ptr->mb_type[mb_pos])){ |
424 |
2/2✓ Branch 0 taken 11048 times.
✓ Branch 1 taken 13319 times.
|
24367 | if(r->is16){ |
425 | 11048 | t = get_bits(gb, 2); | |
426 | 11048 | fill_rectangle(intra_types, 4, 4, r->intra_types_stride, t, sizeof(intra_types[0])); | |
427 | 11048 | r->luma_vlc = 2; | |
428 | }else{ | ||
429 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 13319 times.
|
13319 | if(r->decode_intra_types(r, gb, intra_types) < 0) |
430 | ✗ | return -1; | |
431 | 13319 | r->luma_vlc = 1; | |
432 | } | ||
433 | 24367 | r->chroma_vlc = 0; | |
434 | 24367 | r->cur_vlcs = choose_vlc_set(r->si.quant, r->si.vlc_set, 0); | |
435 | }else{ | ||
436 |
2/2✓ Branch 0 taken 1564640 times.
✓ Branch 1 taken 97790 times.
|
1662430 | for(i = 0; i < 16; i++) |
437 | 1564640 | intra_types[(i & 3) + (i>>2) * r->intra_types_stride] = 0; | |
438 | 97790 | r->cur_vlcs = choose_vlc_set(r->si.quant, r->si.vlc_set, 1); | |
439 |
2/2✓ Branch 0 taken 549 times.
✓ Branch 1 taken 97241 times.
|
97790 | if(r->mb_type[mb_pos] == RV34_MB_P_MIX16x16){ |
440 | 549 | r->is16 = 1; | |
441 | 549 | r->chroma_vlc = 1; | |
442 | 549 | r->luma_vlc = 2; | |
443 | 549 | r->cur_vlcs = choose_vlc_set(r->si.quant, r->si.vlc_set, 0); | |
444 | } | ||
445 | } | ||
446 | |||
447 | 122157 | return rv34_decode_cbp(gb, r->cur_vlcs, r->is16); | |
448 | } | ||
449 | |||
450 | /** @} */ //bitstream functions | ||
451 | |||
452 | /** | ||
453 | * @name motion vector related code (prediction, reconstruction, motion compensation) | ||
454 | * @{ | ||
455 | */ | ||
456 | |||
457 | /** macroblock partition width in 8x8 blocks */ | ||
458 | static const uint8_t part_sizes_w[RV34_MB_TYPES] = { 2, 2, 2, 1, 2, 2, 2, 2, 2, 1, 2, 2 }; | ||
459 | |||
460 | /** macroblock partition height in 8x8 blocks */ | ||
461 | static const uint8_t part_sizes_h[RV34_MB_TYPES] = { 2, 2, 2, 1, 2, 2, 2, 2, 1, 2, 2, 2 }; | ||
462 | |||
463 | /** availability index for subblocks */ | ||
464 | static const uint8_t avail_indexes[4] = { 6, 7, 10, 11 }; | ||
465 | |||
466 | /** | ||
467 | * motion vector prediction | ||
468 | * | ||
469 | * Motion prediction performed for the block by using median prediction of | ||
470 | * motion vectors from the left, top and right top blocks but in corner cases | ||
471 | * some other vectors may be used instead. | ||
472 | */ | ||
473 | 42942 | static void rv34_pred_mv(RV34DecContext *r, int block_type, int subblock_no, int dmv_no) | |
474 | { | ||
475 | 42942 | MpegEncContext *s = &r->s; | |
476 | 42942 | int mv_pos = s->mb_x * 2 + s->mb_y * 2 * s->b8_stride; | |
477 | 42942 | int A[2] = {0}, B[2], C[2]; | |
478 | int i, j; | ||
479 | int mx, my; | ||
480 | 42942 | int* avail = r->avail_cache + avail_indexes[subblock_no]; | |
481 | 42942 | int c_off = part_sizes_w[block_type]; | |
482 | |||
483 | 42942 | mv_pos += (subblock_no & 1) + (subblock_no >> 1)*s->b8_stride; | |
484 |
2/2✓ Branch 0 taken 4544 times.
✓ Branch 1 taken 38398 times.
|
42942 | if(subblock_no == 3) |
485 | 4544 | c_off = -1; | |
486 | |||
487 |
2/2✓ Branch 0 taken 41455 times.
✓ Branch 1 taken 1487 times.
|
42942 | if(avail[-1]){ |
488 | 41455 | A[0] = s->current_picture_ptr->motion_val[0][mv_pos-1][0]; | |
489 | 41455 | A[1] = s->current_picture_ptr->motion_val[0][mv_pos-1][1]; | |
490 | } | ||
491 |
2/2✓ Branch 0 taken 30578 times.
✓ Branch 1 taken 12364 times.
|
42942 | if(avail[-4]){ |
492 | 30578 | B[0] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride][0]; | |
493 | 30578 | B[1] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride][1]; | |
494 | }else{ | ||
495 | 12364 | B[0] = A[0]; | |
496 | 12364 | B[1] = A[1]; | |
497 | } | ||
498 |
2/2✓ Branch 0 taken 14048 times.
✓ Branch 1 taken 28894 times.
|
42942 | if(!avail[c_off-4]){ |
499 |
5/6✓ Branch 0 taken 1883 times.
✓ Branch 1 taken 12165 times.
✓ Branch 2 taken 52 times.
✓ Branch 3 taken 1831 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 52 times.
|
14048 | if(avail[-4] && (avail[-1] || r->rv30)){ |
500 | 1831 | C[0] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride-1][0]; | |
501 | 1831 | C[1] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride-1][1]; | |
502 | }else{ | ||
503 | 12217 | C[0] = A[0]; | |
504 | 12217 | C[1] = A[1]; | |
505 | } | ||
506 | }else{ | ||
507 | 28894 | C[0] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride+c_off][0]; | |
508 | 28894 | C[1] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride+c_off][1]; | |
509 | } | ||
510 | 42942 | mx = mid_pred(A[0], B[0], C[0]); | |
511 | 42942 | my = mid_pred(A[1], B[1], C[1]); | |
512 | 42942 | mx += r->dmv[dmv_no][0]; | |
513 | 42942 | my += r->dmv[dmv_no][1]; | |
514 |
2/2✓ Branch 0 taken 64988 times.
✓ Branch 1 taken 42942 times.
|
107930 | for(j = 0; j < part_sizes_h[block_type]; j++){ |
515 |
2/2✓ Branch 0 taken 101864 times.
✓ Branch 1 taken 64988 times.
|
166852 | for(i = 0; i < part_sizes_w[block_type]; i++){ |
516 | 101864 | s->current_picture_ptr->motion_val[0][mv_pos + i + j*s->b8_stride][0] = mx; | |
517 | 101864 | s->current_picture_ptr->motion_val[0][mv_pos + i + j*s->b8_stride][1] = my; | |
518 | } | ||
519 | } | ||
520 | 42942 | } | |
521 | |||
522 | #define GET_PTS_DIFF(a, b) (((a) - (b) + 8192) & 0x1FFF) | ||
523 | |||
524 | /** | ||
525 | * Calculate motion vector component that should be added for direct blocks. | ||
526 | */ | ||
527 | 806848 | static int calc_add_mv(RV34DecContext *r, int dir, int val) | |
528 | { | ||
529 |
2/2✓ Branch 0 taken 403424 times.
✓ Branch 1 taken 403424 times.
|
806848 | int mul = dir ? -r->mv_weight2 : r->mv_weight1; |
530 | |||
531 | 806848 | return (int)(val * (SUINT)mul + 0x2000) >> 14; | |
532 | } | ||
533 | |||
534 | /** | ||
535 | * Predict motion vector for B-frame macroblock. | ||
536 | */ | ||
537 | 47292 | static inline void rv34_pred_b_vector(int A[2], int B[2], int C[2], | |
538 | int A_avail, int B_avail, int C_avail, | ||
539 | int *mx, int *my) | ||
540 | { | ||
541 |
2/2✓ Branch 0 taken 34544 times.
✓ Branch 1 taken 12748 times.
|
47292 | if(A_avail + B_avail + C_avail != 3){ |
542 | 34544 | *mx = A[0] + B[0] + C[0]; | |
543 | 34544 | *my = A[1] + B[1] + C[1]; | |
544 |
2/2✓ Branch 0 taken 11663 times.
✓ Branch 1 taken 22881 times.
|
34544 | if(A_avail + B_avail + C_avail == 2){ |
545 | 11663 | *mx /= 2; | |
546 | 11663 | *my /= 2; | |
547 | } | ||
548 | }else{ | ||
549 | 12748 | *mx = mid_pred(A[0], B[0], C[0]); | |
550 | 12748 | *my = mid_pred(A[1], B[1], C[1]); | |
551 | } | ||
552 | 47292 | } | |
553 | |||
554 | /** | ||
555 | * motion vector prediction for B-frames | ||
556 | */ | ||
557 | 47292 | static void rv34_pred_mv_b(RV34DecContext *r, int block_type, int dir) | |
558 | { | ||
559 | 47292 | MpegEncContext *s = &r->s; | |
560 | 47292 | int mb_pos = s->mb_x + s->mb_y * s->mb_stride; | |
561 | 47292 | int mv_pos = s->mb_x * 2 + s->mb_y * 2 * s->b8_stride; | |
562 | 47292 | int A[2] = { 0 }, B[2] = { 0 }, C[2] = { 0 }; | |
563 | 47292 | int has_A = 0, has_B = 0, has_C = 0; | |
564 | int mx, my; | ||
565 | int i, j; | ||
566 | 47292 | Picture *cur_pic = s->current_picture_ptr; | |
567 |
2/2✓ Branch 0 taken 24483 times.
✓ Branch 1 taken 22809 times.
|
47292 | const int mask = dir ? MB_TYPE_L1 : MB_TYPE_L0; |
568 | 47292 | int type = cur_pic->mb_type[mb_pos]; | |
569 | |||
570 |
2/2✓ Branch 0 taken 29730 times.
✓ Branch 1 taken 17562 times.
|
47292 | if((r->avail_cache[6-1] & type) & mask){ |
571 | 29730 | A[0] = cur_pic->motion_val[dir][mv_pos - 1][0]; | |
572 | 29730 | A[1] = cur_pic->motion_val[dir][mv_pos - 1][1]; | |
573 | 29730 | has_A = 1; | |
574 | } | ||
575 |
2/2✓ Branch 0 taken 24178 times.
✓ Branch 1 taken 23114 times.
|
47292 | if((r->avail_cache[6-4] & type) & mask){ |
576 | 24178 | B[0] = cur_pic->motion_val[dir][mv_pos - s->b8_stride][0]; | |
577 | 24178 | B[1] = cur_pic->motion_val[dir][mv_pos - s->b8_stride][1]; | |
578 | 24178 | has_B = 1; | |
579 | } | ||
580 |
4/4✓ Branch 0 taken 40737 times.
✓ Branch 1 taken 6555 times.
✓ Branch 2 taken 22080 times.
✓ Branch 3 taken 18657 times.
|
47292 | if(r->avail_cache[6-4] && (r->avail_cache[6-2] & type) & mask){ |
581 | 22080 | C[0] = cur_pic->motion_val[dir][mv_pos - s->b8_stride + 2][0]; | |
582 | 22080 | C[1] = cur_pic->motion_val[dir][mv_pos - s->b8_stride + 2][1]; | |
583 | 22080 | has_C = 1; | |
584 |
4/4✓ Branch 0 taken 918 times.
✓ Branch 1 taken 24294 times.
✓ Branch 2 taken 391 times.
✓ Branch 3 taken 527 times.
|
25212 | }else if((s->mb_x+1) == s->mb_width && (r->avail_cache[6-5] & type) & mask){ |
585 | 391 | C[0] = cur_pic->motion_val[dir][mv_pos - s->b8_stride - 1][0]; | |
586 | 391 | C[1] = cur_pic->motion_val[dir][mv_pos - s->b8_stride - 1][1]; | |
587 | 391 | has_C = 1; | |
588 | } | ||
589 | |||
590 | 47292 | rv34_pred_b_vector(A, B, C, has_A, has_B, has_C, &mx, &my); | |
591 | |||
592 | 47292 | mx += r->dmv[dir][0]; | |
593 | 47292 | my += r->dmv[dir][1]; | |
594 | |||
595 |
2/2✓ Branch 0 taken 94584 times.
✓ Branch 1 taken 47292 times.
|
141876 | for(j = 0; j < 2; j++){ |
596 |
2/2✓ Branch 0 taken 189168 times.
✓ Branch 1 taken 94584 times.
|
283752 | for(i = 0; i < 2; i++){ |
597 | 189168 | cur_pic->motion_val[dir][mv_pos + i + j*s->b8_stride][0] = mx; | |
598 | 189168 | cur_pic->motion_val[dir][mv_pos + i + j*s->b8_stride][1] = my; | |
599 | } | ||
600 | } | ||
601 |
4/4✓ Branch 0 taken 32118 times.
✓ Branch 1 taken 15174 times.
✓ Branch 2 taken 13500 times.
✓ Branch 3 taken 18618 times.
|
47292 | if(block_type == RV34_MB_B_BACKWARD || block_type == RV34_MB_B_FORWARD){ |
602 | 28674 | ZERO8x2(cur_pic->motion_val[!dir][mv_pos], s->b8_stride); | |
603 | } | ||
604 | 47292 | } | |
605 | |||
606 | /** | ||
607 | * motion vector prediction - RV3 version | ||
608 | */ | ||
609 | 9134 | static void rv34_pred_mv_rv3(RV34DecContext *r, int block_type, int dir) | |
610 | { | ||
611 | 9134 | MpegEncContext *s = &r->s; | |
612 | 9134 | int mv_pos = s->mb_x * 2 + s->mb_y * 2 * s->b8_stride; | |
613 | 9134 | int A[2] = {0}, B[2], C[2]; | |
614 | int i, j, k; | ||
615 | int mx, my; | ||
616 | 9134 | int* avail = r->avail_cache + avail_indexes[0]; | |
617 | |||
618 |
2/2✓ Branch 0 taken 8666 times.
✓ Branch 1 taken 468 times.
|
9134 | if(avail[-1]){ |
619 | 8666 | A[0] = s->current_picture_ptr->motion_val[0][mv_pos - 1][0]; | |
620 | 8666 | A[1] = s->current_picture_ptr->motion_val[0][mv_pos - 1][1]; | |
621 | } | ||
622 |
2/2✓ Branch 0 taken 8618 times.
✓ Branch 1 taken 516 times.
|
9134 | if(avail[-4]){ |
623 | 8618 | B[0] = s->current_picture_ptr->motion_val[0][mv_pos - s->b8_stride][0]; | |
624 | 8618 | B[1] = s->current_picture_ptr->motion_val[0][mv_pos - s->b8_stride][1]; | |
625 | }else{ | ||
626 | 516 | B[0] = A[0]; | |
627 | 516 | B[1] = A[1]; | |
628 | } | ||
629 |
2/2✓ Branch 0 taken 950 times.
✓ Branch 1 taken 8184 times.
|
9134 | if(!avail[-4 + 2]){ |
630 |
3/4✓ Branch 0 taken 434 times.
✓ Branch 1 taken 516 times.
✓ Branch 2 taken 434 times.
✗ Branch 3 not taken.
|
950 | if(avail[-4] && (avail[-1])){ |
631 | 434 | C[0] = s->current_picture_ptr->motion_val[0][mv_pos - s->b8_stride - 1][0]; | |
632 | 434 | C[1] = s->current_picture_ptr->motion_val[0][mv_pos - s->b8_stride - 1][1]; | |
633 | }else{ | ||
634 | 516 | C[0] = A[0]; | |
635 | 516 | C[1] = A[1]; | |
636 | } | ||
637 | }else{ | ||
638 | 8184 | C[0] = s->current_picture_ptr->motion_val[0][mv_pos - s->b8_stride + 2][0]; | |
639 | 8184 | C[1] = s->current_picture_ptr->motion_val[0][mv_pos - s->b8_stride + 2][1]; | |
640 | } | ||
641 | 9134 | mx = mid_pred(A[0], B[0], C[0]); | |
642 | 9134 | my = mid_pred(A[1], B[1], C[1]); | |
643 | 9134 | mx += r->dmv[0][0]; | |
644 | 9134 | my += r->dmv[0][1]; | |
645 |
2/2✓ Branch 0 taken 18268 times.
✓ Branch 1 taken 9134 times.
|
27402 | for(j = 0; j < 2; j++){ |
646 |
2/2✓ Branch 0 taken 36536 times.
✓ Branch 1 taken 18268 times.
|
54804 | for(i = 0; i < 2; i++){ |
647 |
2/2✓ Branch 0 taken 73072 times.
✓ Branch 1 taken 36536 times.
|
109608 | for(k = 0; k < 2; k++){ |
648 | 73072 | s->current_picture_ptr->motion_val[k][mv_pos + i + j*s->b8_stride][0] = mx; | |
649 | 73072 | s->current_picture_ptr->motion_val[k][mv_pos + i + j*s->b8_stride][1] = my; | |
650 | } | ||
651 | } | ||
652 | } | ||
653 | 9134 | } | |
654 | |||
655 | static const int chroma_coeffs[3] = { 0, 3, 5 }; | ||
656 | |||
657 | /** | ||
658 | * generic motion compensation function | ||
659 | * | ||
660 | * @param r decoder context | ||
661 | * @param block_type type of the current block | ||
662 | * @param xoff horizontal offset from the start of the current block | ||
663 | * @param yoff vertical offset from the start of the current block | ||
664 | * @param mv_off offset to the motion vector information | ||
665 | * @param width width of the current partition in 8x8 blocks | ||
666 | * @param height height of the current partition in 8x8 blocks | ||
667 | * @param dir motion compensation direction (i.e. from the last or the next reference frame) | ||
668 | * @param thirdpel motion vectors are specified in 1/3 of pixel | ||
669 | * @param qpel_mc a set of functions used to perform luma motion compensation | ||
670 | * @param chroma_mc a set of functions used to perform chroma motion compensation | ||
671 | */ | ||
672 | 514595 | static inline void rv34_mc(RV34DecContext *r, const int block_type, | |
673 | const int xoff, const int yoff, int mv_off, | ||
674 | const int width, const int height, int dir, | ||
675 | const int thirdpel, int weighted, | ||
676 | qpel_mc_func (*qpel_mc)[16], | ||
677 | h264_chroma_mc_func (*chroma_mc)) | ||
678 | { | ||
679 | 514595 | MpegEncContext *s = &r->s; | |
680 | uint8_t *Y, *U, *V, *srcY, *srcU, *srcV; | ||
681 | int dxy, mx, my, umx, umy, lx, ly, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y; | ||
682 | 514595 | int mv_pos = s->mb_x * 2 + s->mb_y * 2 * s->b8_stride + mv_off; | |
683 | 514595 | int is16x16 = 1; | |
684 | 514595 | int emu = 0; | |
685 | |||
686 |
2/2✓ Branch 0 taken 127708 times.
✓ Branch 1 taken 386887 times.
|
514595 | if(thirdpel){ |
687 | int chroma_mx, chroma_my; | ||
688 | 127708 | mx = (s->current_picture_ptr->motion_val[dir][mv_pos][0] + (3 << 24)) / 3 - (1 << 24); | |
689 | 127708 | my = (s->current_picture_ptr->motion_val[dir][mv_pos][1] + (3 << 24)) / 3 - (1 << 24); | |
690 | 127708 | lx = (s->current_picture_ptr->motion_val[dir][mv_pos][0] + (3 << 24)) % 3; | |
691 | 127708 | ly = (s->current_picture_ptr->motion_val[dir][mv_pos][1] + (3 << 24)) % 3; | |
692 | 127708 | chroma_mx = s->current_picture_ptr->motion_val[dir][mv_pos][0] / 2; | |
693 | 127708 | chroma_my = s->current_picture_ptr->motion_val[dir][mv_pos][1] / 2; | |
694 | 127708 | umx = (chroma_mx + (3 << 24)) / 3 - (1 << 24); | |
695 | 127708 | umy = (chroma_my + (3 << 24)) / 3 - (1 << 24); | |
696 | 127708 | uvmx = chroma_coeffs[(chroma_mx + (3 << 24)) % 3]; | |
697 | 127708 | uvmy = chroma_coeffs[(chroma_my + (3 << 24)) % 3]; | |
698 | }else{ | ||
699 | int cx, cy; | ||
700 | 386887 | mx = s->current_picture_ptr->motion_val[dir][mv_pos][0] >> 2; | |
701 | 386887 | my = s->current_picture_ptr->motion_val[dir][mv_pos][1] >> 2; | |
702 | 386887 | lx = s->current_picture_ptr->motion_val[dir][mv_pos][0] & 3; | |
703 | 386887 | ly = s->current_picture_ptr->motion_val[dir][mv_pos][1] & 3; | |
704 | 386887 | cx = s->current_picture_ptr->motion_val[dir][mv_pos][0] / 2; | |
705 | 386887 | cy = s->current_picture_ptr->motion_val[dir][mv_pos][1] / 2; | |
706 | 386887 | umx = cx >> 2; | |
707 | 386887 | umy = cy >> 2; | |
708 | 386887 | uvmx = (cx & 3) << 1; | |
709 | 386887 | uvmy = (cy & 3) << 1; | |
710 | //due to some flaw RV40 uses the same MC compensation routine for H2V2 and H3V3 | ||
711 |
4/4✓ Branch 0 taken 34910 times.
✓ Branch 1 taken 351977 times.
✓ Branch 2 taken 7463 times.
✓ Branch 3 taken 27447 times.
|
386887 | if(uvmx == 6 && uvmy == 6) |
712 | 7463 | uvmx = uvmy = 4; | |
713 | } | ||
714 | |||
715 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 514595 times.
|
514595 | if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME)) { |
716 | /* wait for the referenced mb row to be finished */ | ||
717 | ✗ | int mb_row = s->mb_y + ((yoff + my + 5 + 8 * height) >> 4); | |
718 | ✗ | const ThreadFrame *f = dir ? &s->next_picture_ptr->tf : &s->last_picture_ptr->tf; | |
719 | ✗ | ff_thread_await_progress(f, mb_row, 0); | |
720 | } | ||
721 | |||
722 | 514595 | dxy = ly*4 + lx; | |
723 |
2/2✓ Branch 0 taken 221659 times.
✓ Branch 1 taken 292936 times.
|
514595 | srcY = dir ? s->next_picture_ptr->f->data[0] : s->last_picture_ptr->f->data[0]; |
724 |
2/2✓ Branch 0 taken 221659 times.
✓ Branch 1 taken 292936 times.
|
514595 | srcU = dir ? s->next_picture_ptr->f->data[1] : s->last_picture_ptr->f->data[1]; |
725 |
2/2✓ Branch 0 taken 221659 times.
✓ Branch 1 taken 292936 times.
|
514595 | srcV = dir ? s->next_picture_ptr->f->data[2] : s->last_picture_ptr->f->data[2]; |
726 | 514595 | src_x = s->mb_x * 16 + xoff + mx; | |
727 | 514595 | src_y = s->mb_y * 16 + yoff + my; | |
728 | 514595 | uvsrc_x = s->mb_x * 8 + (xoff >> 1) + umx; | |
729 | 514595 | uvsrc_y = s->mb_y * 8 + (yoff >> 1) + umy; | |
730 | 514595 | srcY += src_y * s->linesize + src_x; | |
731 | 514595 | srcU += uvsrc_y * s->uvlinesize + uvsrc_x; | |
732 | 514595 | srcV += uvsrc_y * s->uvlinesize + uvsrc_x; | |
733 |
2/4✓ Branch 0 taken 514595 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 514595 times.
✗ Branch 3 not taken.
|
514595 | if(s->h_edge_pos - (width << 3) < 6 || s->v_edge_pos - (height << 3) < 6 || |
734 |
6/6✓ Branch 0 taken 166878 times.
✓ Branch 1 taken 347717 times.
✓ Branch 2 taken 166878 times.
✓ Branch 3 taken 347717 times.
✓ Branch 4 taken 498480 times.
✓ Branch 5 taken 16115 times.
|
514595 | (unsigned)(src_x - !!lx*2) > s->h_edge_pos - !!lx*2 - (width <<3) - 4 || |
735 |
6/6✓ Branch 0 taken 144037 times.
✓ Branch 1 taken 354443 times.
✓ Branch 2 taken 144037 times.
✓ Branch 3 taken 354443 times.
✓ Branch 4 taken 27692 times.
✓ Branch 5 taken 470788 times.
|
498480 | (unsigned)(src_y - !!ly*2) > s->v_edge_pos - !!ly*2 - (height<<3) - 4) { |
736 | 43807 | srcY -= 2 + 2*s->linesize; | |
737 | 43807 | s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, srcY, | |
738 | s->linesize, s->linesize, | ||
739 | 43807 | (width << 3) + 6, (height << 3) + 6, | |
740 | src_x - 2, src_y - 2, | ||
741 | s->h_edge_pos, s->v_edge_pos); | ||
742 | 43807 | srcY = s->sc.edge_emu_buffer + 2 + 2*s->linesize; | |
743 | 43807 | emu = 1; | |
744 | } | ||
745 |
2/2✓ Branch 0 taken 231619 times.
✓ Branch 1 taken 282976 times.
|
514595 | if(!weighted){ |
746 | 231619 | Y = s->dest[0] + xoff + yoff *s->linesize; | |
747 | 231619 | U = s->dest[1] + (xoff>>1) + (yoff>>1)*s->uvlinesize; | |
748 | 231619 | V = s->dest[2] + (xoff>>1) + (yoff>>1)*s->uvlinesize; | |
749 | }else{ | ||
750 | 282976 | Y = r->tmp_b_block_y [dir] + xoff + yoff *s->linesize; | |
751 | 282976 | U = r->tmp_b_block_uv[dir*2] + (xoff>>1) + (yoff>>1)*s->uvlinesize; | |
752 | 282976 | V = r->tmp_b_block_uv[dir*2+1] + (xoff>>1) + (yoff>>1)*s->uvlinesize; | |
753 | } | ||
754 | |||
755 |
2/2✓ Branch 0 taken 2720 times.
✓ Branch 1 taken 511875 times.
|
514595 | if(block_type == RV34_MB_P_16x8){ |
756 | 2720 | qpel_mc[1][dxy](Y, srcY, s->linesize); | |
757 | 2720 | Y += 8; | |
758 | 2720 | srcY += 8; | |
759 |
2/2✓ Branch 0 taken 4968 times.
✓ Branch 1 taken 506907 times.
|
511875 | }else if(block_type == RV34_MB_P_8x16){ |
760 | 4968 | qpel_mc[1][dxy](Y, srcY, s->linesize); | |
761 | 4968 | Y += 8 * s->linesize; | |
762 | 4968 | srcY += 8 * s->linesize; | |
763 | } | ||
764 |
6/6✓ Branch 0 taken 404843 times.
✓ Branch 1 taken 109752 times.
✓ Branch 2 taken 402123 times.
✓ Branch 3 taken 2720 times.
✓ Branch 4 taken 397155 times.
✓ Branch 5 taken 4968 times.
|
514595 | is16x16 = (block_type != RV34_MB_P_8x8) && (block_type != RV34_MB_P_16x8) && (block_type != RV34_MB_P_8x16); |
765 |
2/2✓ Branch 0 taken 117440 times.
✓ Branch 1 taken 397155 times.
|
514595 | qpel_mc[!is16x16][dxy](Y, srcY, s->linesize); |
766 |
2/2✓ Branch 0 taken 43807 times.
✓ Branch 1 taken 470788 times.
|
514595 | if (emu) { |
767 | 43807 | uint8_t *uvbuf = s->sc.edge_emu_buffer; | |
768 | |||
769 | 43807 | s->vdsp.emulated_edge_mc(uvbuf, srcU, | |
770 | s->uvlinesize, s->uvlinesize, | ||
771 | 43807 | (width << 2) + 1, (height << 2) + 1, | |
772 | uvsrc_x, uvsrc_y, | ||
773 | 43807 | s->h_edge_pos >> 1, s->v_edge_pos >> 1); | |
774 | 43807 | srcU = uvbuf; | |
775 | 43807 | uvbuf += 9*s->uvlinesize; | |
776 | |||
777 | 43807 | s->vdsp.emulated_edge_mc(uvbuf, srcV, | |
778 | s->uvlinesize, s->uvlinesize, | ||
779 | 43807 | (width << 2) + 1, (height << 2) + 1, | |
780 | uvsrc_x, uvsrc_y, | ||
781 | 43807 | s->h_edge_pos >> 1, s->v_edge_pos >> 1); | |
782 | 43807 | srcV = uvbuf; | |
783 | } | ||
784 | 514595 | chroma_mc[2-width] (U, srcU, s->uvlinesize, height*4, uvmx, uvmy); | |
785 | 514595 | chroma_mc[2-width] (V, srcV, s->uvlinesize, height*4, uvmx, uvmy); | |
786 | 514595 | } | |
787 | |||
788 | 112465 | static void rv34_mc_1mv(RV34DecContext *r, const int block_type, | |
789 | const int xoff, const int yoff, int mv_off, | ||
790 | const int width, const int height, int dir) | ||
791 | { | ||
792 | 112465 | rv34_mc(r, block_type, xoff, yoff, mv_off, width, height, dir, r->rv30, 0, | |
793 | 112465 | r->rdsp.put_pixels_tab, | |
794 | 112465 | r->rdsp.put_chroma_pixels_tab); | |
795 | 112465 | } | |
796 | |||
797 | 116417 | static void rv4_weight(RV34DecContext *r) | |
798 | { | ||
799 | 116417 | r->rdsp.rv40_weight_pixels_tab[r->scaled_weight][0](r->s.dest[0], | |
800 | r->tmp_b_block_y[0], | ||
801 | r->tmp_b_block_y[1], | ||
802 | r->weight1, | ||
803 | r->weight2, | ||
804 | r->s.linesize); | ||
805 | 116417 | r->rdsp.rv40_weight_pixels_tab[r->scaled_weight][1](r->s.dest[1], | |
806 | r->tmp_b_block_uv[0], | ||
807 | r->tmp_b_block_uv[2], | ||
808 | r->weight1, | ||
809 | r->weight2, | ||
810 | r->s.uvlinesize); | ||
811 | 116417 | r->rdsp.rv40_weight_pixels_tab[r->scaled_weight][1](r->s.dest[2], | |
812 | r->tmp_b_block_uv[1], | ||
813 | r->tmp_b_block_uv[3], | ||
814 | r->weight1, | ||
815 | r->weight2, | ||
816 | r->s.uvlinesize); | ||
817 | 116417 | } | |
818 | |||
819 | 155277 | static void rv34_mc_2mv(RV34DecContext *r, const int block_type) | |
820 | { | ||
821 |
5/6✓ Branch 0 taken 117369 times.
✓ Branch 1 taken 37908 times.
✓ Branch 2 taken 108060 times.
✓ Branch 3 taken 9309 times.
✓ Branch 4 taken 108060 times.
✗ Branch 5 not taken.
|
155277 | int weighted = !r->rv30 && block_type != RV34_MB_B_BIDIR && r->weight1 != 8192; |
822 | |||
823 | 155277 | rv34_mc(r, block_type, 0, 0, 0, 2, 2, 0, r->rv30, weighted, | |
824 | 155277 | r->rdsp.put_pixels_tab, | |
825 | 155277 | r->rdsp.put_chroma_pixels_tab); | |
826 |
2/2✓ Branch 0 taken 47217 times.
✓ Branch 1 taken 108060 times.
|
155277 | if(!weighted){ |
827 | 47217 | rv34_mc(r, block_type, 0, 0, 0, 2, 2, 1, r->rv30, 0, | |
828 | 47217 | r->rdsp.avg_pixels_tab, | |
829 | 47217 | r->rdsp.avg_chroma_pixels_tab); | |
830 | }else{ | ||
831 | 108060 | rv34_mc(r, block_type, 0, 0, 0, 2, 2, 1, r->rv30, 1, | |
832 | 108060 | r->rdsp.put_pixels_tab, | |
833 | 108060 | r->rdsp.put_chroma_pixels_tab); | |
834 | 108060 | rv4_weight(r); | |
835 | } | ||
836 | 155277 | } | |
837 | |||
838 | 11447 | static void rv34_mc_2mv_skip(RV34DecContext *r) | |
839 | { | ||
840 | int i, j; | ||
841 |
3/4✓ Branch 0 taken 8357 times.
✓ Branch 1 taken 3090 times.
✓ Branch 2 taken 8357 times.
✗ Branch 3 not taken.
|
11447 | int weighted = !r->rv30 && r->weight1 != 8192; |
842 | |||
843 |
2/2✓ Branch 0 taken 22894 times.
✓ Branch 1 taken 11447 times.
|
34341 | for(j = 0; j < 2; j++) |
844 |
2/2✓ Branch 0 taken 45788 times.
✓ Branch 1 taken 22894 times.
|
68682 | for(i = 0; i < 2; i++){ |
845 | 45788 | rv34_mc(r, RV34_MB_P_8x8, i*8, j*8, i+j*r->s.b8_stride, 1, 1, 0, r->rv30, | |
846 | weighted, | ||
847 | 45788 | r->rdsp.put_pixels_tab, | |
848 | 45788 | r->rdsp.put_chroma_pixels_tab); | |
849 |
4/4✓ Branch 0 taken 33428 times.
✓ Branch 1 taken 12360 times.
✓ Branch 2 taken 33428 times.
✓ Branch 3 taken 12360 times.
|
45788 | rv34_mc(r, RV34_MB_P_8x8, i*8, j*8, i+j*r->s.b8_stride, 1, 1, 1, r->rv30, |
850 | weighted, | ||
851 | weighted ? r->rdsp.put_pixels_tab : r->rdsp.avg_pixels_tab, | ||
852 | weighted ? r->rdsp.put_chroma_pixels_tab : r->rdsp.avg_chroma_pixels_tab); | ||
853 | } | ||
854 |
2/2✓ Branch 0 taken 8357 times.
✓ Branch 1 taken 3090 times.
|
11447 | if(weighted) |
855 | 8357 | rv4_weight(r); | |
856 | 11447 | } | |
857 | |||
858 | /** number of motion vectors in each macroblock type */ | ||
859 | static const int num_mvs[RV34_MB_TYPES] = { 0, 0, 1, 4, 1, 1, 0, 0, 2, 2, 2, 1 }; | ||
860 | |||
861 | /** | ||
862 | * Decode motion vector differences | ||
863 | * and perform motion vector reconstruction and motion compensation. | ||
864 | */ | ||
865 | 286080 | static int rv34_decode_mv(RV34DecContext *r, int block_type) | |
866 | { | ||
867 | 286080 | MpegEncContext *s = &r->s; | |
868 | 286080 | GetBitContext *gb = &s->gb; | |
869 | int i, j, k, l; | ||
870 | 286080 | int mv_pos = s->mb_x * 2 + s->mb_y * 2 * s->b8_stride; | |
871 | int next_bt; | ||
872 | |||
873 | 286080 | memset(r->dmv, 0, sizeof(r->dmv)); | |
874 |
2/2✓ Branch 0 taken 99368 times.
✓ Branch 1 taken 286080 times.
|
385448 | for(i = 0; i < num_mvs[block_type]; i++){ |
875 | 99368 | r->dmv[i][0] = get_interleaved_se_golomb(gb); | |
876 | 99368 | r->dmv[i][1] = get_interleaved_se_golomb(gb); | |
877 |
1/2✓ Branch 0 taken 99368 times.
✗ Branch 1 not taken.
|
99368 | if (r->dmv[i][0] == INVALID_VLC || |
878 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 99368 times.
|
99368 | r->dmv[i][1] == INVALID_VLC) { |
879 | ✗ | r->dmv[i][0] = r->dmv[i][1] = 0; | |
880 | ✗ | return AVERROR_INVALIDDATA; | |
881 | } | ||
882 | } | ||
883 |
8/9✓ Branch 0 taken 24367 times.
✓ Branch 1 taken 163923 times.
✓ Branch 2 taken 25207 times.
✓ Branch 3 taken 17078 times.
✓ Branch 4 taken 37808 times.
✓ Branch 5 taken 3844 times.
✓ Branch 6 taken 9309 times.
✓ Branch 7 taken 4544 times.
✗ Branch 8 not taken.
|
286080 | switch(block_type){ |
884 | 24367 | case RV34_MB_TYPE_INTRA: | |
885 | case RV34_MB_TYPE_INTRA16x16: | ||
886 | 24367 | ZERO8x2(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride); | |
887 | 24367 | return 0; | |
888 | 163923 | case RV34_MB_SKIP: | |
889 |
2/2✓ Branch 0 taken 31715 times.
✓ Branch 1 taken 132208 times.
|
163923 | if(s->pict_type == AV_PICTURE_TYPE_P){ |
890 | 31715 | ZERO8x2(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride); | |
891 | 31715 | rv34_mc_1mv (r, block_type, 0, 0, 0, 2, 2, 0); | |
892 | 31715 | break; | |
893 | } | ||
894 | case RV34_MB_B_DIRECT: | ||
895 | //surprisingly, it uses motion scheme from next reference frame | ||
896 | /* wait for the current mb row to be finished */ | ||
897 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 157415 times.
|
157415 | if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME)) |
898 | ✗ | ff_thread_await_progress(&s->next_picture_ptr->tf, FFMAX(0, s->mb_y-1), 0); | |
899 | |||
900 | 157415 | next_bt = s->next_picture_ptr->mb_type[s->mb_x + s->mb_y * s->mb_stride]; | |
901 |
4/4✓ Branch 0 taken 143748 times.
✓ Branch 1 taken 13667 times.
✓ Branch 2 taken 93320 times.
✓ Branch 3 taken 50428 times.
|
157415 | if(IS_INTRA(next_bt) || IS_SKIP(next_bt)){ |
902 | 106987 | ZERO8x2(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride); | |
903 | 106987 | ZERO8x2(s->current_picture_ptr->motion_val[1][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride); | |
904 | }else | ||
905 |
2/2✓ Branch 0 taken 100856 times.
✓ Branch 1 taken 50428 times.
|
151284 | for(j = 0; j < 2; j++) |
906 |
2/2✓ Branch 0 taken 201712 times.
✓ Branch 1 taken 100856 times.
|
302568 | for(i = 0; i < 2; i++) |
907 |
2/2✓ Branch 0 taken 403424 times.
✓ Branch 1 taken 201712 times.
|
605136 | for(k = 0; k < 2; k++) |
908 |
2/2✓ Branch 0 taken 806848 times.
✓ Branch 1 taken 403424 times.
|
1210272 | for(l = 0; l < 2; l++) |
909 | 806848 | s->current_picture_ptr->motion_val[l][mv_pos + i + j*s->b8_stride][k] = calc_add_mv(r, l, s->next_picture_ptr->motion_val[0][mv_pos + i + j*s->b8_stride][k]); | |
910 |
6/6✓ Branch 0 taken 155273 times.
✓ Branch 1 taken 2142 times.
✓ Branch 2 taken 152111 times.
✓ Branch 3 taken 3162 times.
✓ Branch 4 taken 145968 times.
✓ Branch 5 taken 6143 times.
|
157415 | if(!(IS_16X8(next_bt) || IS_8X16(next_bt) || IS_8X8(next_bt))) //we can use whole macroblock MC |
911 | 145968 | rv34_mc_2mv(r, block_type); | |
912 | else | ||
913 | 11447 | rv34_mc_2mv_skip(r); | |
914 | 157415 | ZERO8x2(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride); | |
915 | 157415 | break; | |
916 | 17078 | case RV34_MB_P_16x16: | |
917 | case RV34_MB_P_MIX16x16: | ||
918 | 17078 | rv34_pred_mv(r, block_type, 0, 0); | |
919 | 17078 | rv34_mc_1mv (r, block_type, 0, 0, 0, 2, 2, 0); | |
920 | 17078 | break; | |
921 | 37808 | case RV34_MB_B_FORWARD: | |
922 | case RV34_MB_B_BACKWARD: | ||
923 | 37808 | r->dmv[1][0] = r->dmv[0][0]; | |
924 | 37808 | r->dmv[1][1] = r->dmv[0][1]; | |
925 |
2/2✓ Branch 0 taken 9134 times.
✓ Branch 1 taken 28674 times.
|
37808 | if(r->rv30) |
926 | 9134 | rv34_pred_mv_rv3(r, block_type, block_type == RV34_MB_B_BACKWARD); | |
927 | else | ||
928 | 28674 | rv34_pred_mv_b (r, block_type, block_type == RV34_MB_B_BACKWARD); | |
929 | 37808 | rv34_mc_1mv (r, block_type, 0, 0, 0, 2, 2, block_type == RV34_MB_B_BACKWARD); | |
930 | 37808 | break; | |
931 | 3844 | case RV34_MB_P_16x8: | |
932 | case RV34_MB_P_8x16: | ||
933 | 3844 | rv34_pred_mv(r, block_type, 0, 0); | |
934 |
2/2✓ Branch 0 taken 1360 times.
✓ Branch 1 taken 2484 times.
|
3844 | rv34_pred_mv(r, block_type, 1 + (block_type == RV34_MB_P_16x8), 1); |
935 |
2/2✓ Branch 0 taken 1360 times.
✓ Branch 1 taken 2484 times.
|
3844 | if(block_type == RV34_MB_P_16x8){ |
936 | 1360 | rv34_mc_1mv(r, block_type, 0, 0, 0, 2, 1, 0); | |
937 | 1360 | rv34_mc_1mv(r, block_type, 0, 8, s->b8_stride, 2, 1, 0); | |
938 | } | ||
939 |
2/2✓ Branch 0 taken 2484 times.
✓ Branch 1 taken 1360 times.
|
3844 | if(block_type == RV34_MB_P_8x16){ |
940 | 2484 | rv34_mc_1mv(r, block_type, 0, 0, 0, 1, 2, 0); | |
941 | 2484 | rv34_mc_1mv(r, block_type, 8, 0, 1, 1, 2, 0); | |
942 | } | ||
943 | 3844 | break; | |
944 | 9309 | case RV34_MB_B_BIDIR: | |
945 | 9309 | rv34_pred_mv_b (r, block_type, 0); | |
946 | 9309 | rv34_pred_mv_b (r, block_type, 1); | |
947 | 9309 | rv34_mc_2mv (r, block_type); | |
948 | 9309 | break; | |
949 | 4544 | case RV34_MB_P_8x8: | |
950 |
2/2✓ Branch 0 taken 18176 times.
✓ Branch 1 taken 4544 times.
|
22720 | for(i=0;i< 4;i++){ |
951 | 18176 | rv34_pred_mv(r, block_type, i, i); | |
952 | 18176 | rv34_mc_1mv (r, block_type, (i&1)<<3, (i&2)<<2, (i&1)+(i>>1)*s->b8_stride, 1, 1, 0); | |
953 | } | ||
954 | 4544 | break; | |
955 | } | ||
956 | |||
957 | 261713 | return 0; | |
958 | } | ||
959 | /** @} */ // mv group | ||
960 | |||
961 | /** | ||
962 | * @name Macroblock reconstruction functions | ||
963 | * @{ | ||
964 | */ | ||
965 | /** mapping of RV30/40 intra prediction types to standard H.264 types */ | ||
966 | static const int ittrans[9] = { | ||
967 | DC_PRED, VERT_PRED, HOR_PRED, DIAG_DOWN_RIGHT_PRED, DIAG_DOWN_LEFT_PRED, | ||
968 | VERT_RIGHT_PRED, VERT_LEFT_PRED, HOR_UP_PRED, HOR_DOWN_PRED, | ||
969 | }; | ||
970 | |||
971 | /** mapping of RV30/40 intra 16x16 prediction types to standard H.264 types */ | ||
972 | static const int ittrans16[4] = { | ||
973 | DC_PRED8x8, VERT_PRED8x8, HOR_PRED8x8, PLANE_PRED8x8, | ||
974 | }; | ||
975 | |||
976 | /** | ||
977 | * Perform 4x4 intra prediction. | ||
978 | */ | ||
979 | 363096 | static void rv34_pred_4x4_block(RV34DecContext *r, uint8_t *dst, int stride, int itype, int up, int left, int down, int right) | |
980 | { | ||
981 | 363096 | uint8_t *prev = dst - stride + 4; | |
982 | uint32_t topleft; | ||
983 | |||
984 |
4/4✓ Branch 0 taken 44632 times.
✓ Branch 1 taken 318464 times.
✓ Branch 2 taken 906 times.
✓ Branch 3 taken 43726 times.
|
363096 | if(!up && !left) |
985 | 906 | itype = DC_128_PRED; | |
986 |
2/2✓ Branch 0 taken 43726 times.
✓ Branch 1 taken 318464 times.
|
362190 | else if(!up){ |
987 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 43726 times.
|
43726 | if(itype == VERT_PRED) itype = HOR_PRED; |
988 |
2/2✓ Branch 0 taken 25536 times.
✓ Branch 1 taken 18190 times.
|
43726 | if(itype == DC_PRED) itype = LEFT_DC_PRED; |
989 |
2/2✓ Branch 0 taken 5318 times.
✓ Branch 1 taken 313146 times.
|
318464 | }else if(!left){ |
990 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5318 times.
|
5318 | if(itype == HOR_PRED) itype = VERT_PRED; |
991 |
2/2✓ Branch 0 taken 3700 times.
✓ Branch 1 taken 1618 times.
|
5318 | if(itype == DC_PRED) itype = TOP_DC_PRED; |
992 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5318 times.
|
5318 | if(itype == DIAG_DOWN_LEFT_PRED) itype = DIAG_DOWN_LEFT_PRED_RV40_NODOWN; |
993 | } | ||
994 |
2/2✓ Branch 0 taken 289785 times.
✓ Branch 1 taken 73311 times.
|
363096 | if(!down){ |
995 |
2/2✓ Branch 0 taken 16270 times.
✓ Branch 1 taken 273515 times.
|
289785 | if(itype == DIAG_DOWN_LEFT_PRED) itype = DIAG_DOWN_LEFT_PRED_RV40_NODOWN; |
996 |
2/2✓ Branch 0 taken 9069 times.
✓ Branch 1 taken 280716 times.
|
289785 | if(itype == HOR_UP_PRED) itype = HOR_UP_PRED_RV40_NODOWN; |
997 |
2/2✓ Branch 0 taken 23196 times.
✓ Branch 1 taken 266589 times.
|
289785 | if(itype == VERT_LEFT_PRED) itype = VERT_LEFT_PRED_RV40_NODOWN; |
998 | } | ||
999 |
4/4✓ Branch 0 taken 120385 times.
✓ Branch 1 taken 242711 times.
✓ Branch 2 taken 76137 times.
✓ Branch 3 taken 44248 times.
|
363096 | if(!right && up){ |
1000 | 76137 | topleft = dst[-stride + 3] * 0x01010101u; | |
1001 | 76137 | prev = (uint8_t*)&topleft; | |
1002 | } | ||
1003 | 363096 | r->h.pred4x4[itype](dst, prev, stride); | |
1004 | 363096 | } | |
1005 | |||
1006 | 33756 | static inline int adjust_pred16(int itype, int up, int left) | |
1007 | { | ||
1008 |
4/4✓ Branch 0 taken 5834 times.
✓ Branch 1 taken 27922 times.
✓ Branch 2 taken 54 times.
✓ Branch 3 taken 5780 times.
|
33756 | if(!up && !left) |
1009 | 54 | itype = DC_128_PRED8x8; | |
1010 |
2/2✓ Branch 0 taken 5780 times.
✓ Branch 1 taken 27922 times.
|
33702 | else if(!up){ |
1011 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5780 times.
|
5780 | if(itype == PLANE_PRED8x8)itype = HOR_PRED8x8; |
1012 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5780 times.
|
5780 | if(itype == VERT_PRED8x8) itype = HOR_PRED8x8; |
1013 |
2/2✓ Branch 0 taken 3780 times.
✓ Branch 1 taken 2000 times.
|
5780 | if(itype == DC_PRED8x8) itype = LEFT_DC_PRED8x8; |
1014 |
2/2✓ Branch 0 taken 840 times.
✓ Branch 1 taken 27082 times.
|
27922 | }else if(!left){ |
1015 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 840 times.
|
840 | if(itype == PLANE_PRED8x8)itype = VERT_PRED8x8; |
1016 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 840 times.
|
840 | if(itype == HOR_PRED8x8) itype = VERT_PRED8x8; |
1017 |
2/2✓ Branch 0 taken 684 times.
✓ Branch 1 taken 156 times.
|
840 | if(itype == DC_PRED8x8) itype = TOP_DC_PRED8x8; |
1018 | } | ||
1019 | 33756 | return itype; | |
1020 | } | ||
1021 | |||
1022 | 708606 | static inline void rv34_process_block(RV34DecContext *r, | |
1023 | uint8_t *pdst, int stride, | ||
1024 | int fc, int sc, int q_dc, int q_ac) | ||
1025 | { | ||
1026 | 708606 | MpegEncContext *s = &r->s; | |
1027 | 708606 | int16_t *ptr = s->block[0]; | |
1028 | 708606 | int has_ac = rv34_decode_block(ptr, &s->gb, r->cur_vlcs, | |
1029 | fc, sc, q_dc, q_ac, q_ac); | ||
1030 |
2/2✓ Branch 0 taken 352387 times.
✓ Branch 1 taken 356219 times.
|
708606 | if(has_ac){ |
1031 | 352387 | r->rdsp.rv34_idct_add(pdst, stride, ptr); | |
1032 | }else{ | ||
1033 | 356219 | r->rdsp.rv34_idct_dc_add(pdst, stride, ptr[0]); | |
1034 | 356219 | ptr[0] = 0; | |
1035 | } | ||
1036 | 708606 | } | |
1037 | |||
1038 | 16878 | static void rv34_output_i16x16(RV34DecContext *r, int8_t *intra_types, int cbp) | |
1039 | { | ||
1040 | 16878 | LOCAL_ALIGNED_16(int16_t, block16, [16]); | |
1041 | 16878 | MpegEncContext *s = &r->s; | |
1042 | 16878 | GetBitContext *gb = &s->gb; | |
1043 | 16878 | int q_dc = rv34_qscale_tab[ r->luma_dc_quant_i[s->qscale] ], | |
1044 | 16878 | q_ac = rv34_qscale_tab[s->qscale]; | |
1045 | 16878 | uint8_t *dst = s->dest[0]; | |
1046 | 16878 | int16_t *ptr = s->block[0]; | |
1047 | int i, j, itype, has_ac; | ||
1048 | |||
1049 | 16878 | memset(block16, 0, 16 * sizeof(*block16)); | |
1050 | |||
1051 | 16878 | has_ac = rv34_decode_block(block16, gb, r->cur_vlcs, 3, 0, q_dc, q_dc, q_ac); | |
1052 |
2/2✓ Branch 0 taken 7956 times.
✓ Branch 1 taken 8922 times.
|
16878 | if(has_ac) |
1053 | 7956 | r->rdsp.rv34_inv_transform(block16); | |
1054 | else | ||
1055 | 8922 | r->rdsp.rv34_inv_transform_dc(block16); | |
1056 | |||
1057 | 16878 | itype = ittrans16[intra_types[0]]; | |
1058 | 16878 | itype = adjust_pred16(itype, r->avail_cache[6-4], r->avail_cache[6-1]); | |
1059 | 16878 | r->h.pred16x16[itype](dst, s->linesize); | |
1060 | |||
1061 |
2/2✓ Branch 0 taken 67512 times.
✓ Branch 1 taken 16878 times.
|
84390 | for(j = 0; j < 4; j++){ |
1062 |
2/2✓ Branch 0 taken 270048 times.
✓ Branch 1 taken 67512 times.
|
337560 | for(i = 0; i < 4; i++, cbp >>= 1){ |
1063 | 270048 | int dc = block16[i + j*4]; | |
1064 | |||
1065 |
2/2✓ Branch 0 taken 14318 times.
✓ Branch 1 taken 255730 times.
|
270048 | if(cbp & 1){ |
1066 | 14318 | has_ac = rv34_decode_block(ptr, gb, r->cur_vlcs, r->luma_vlc, 0, q_ac, q_ac, q_ac); | |
1067 | }else | ||
1068 | 255730 | has_ac = 0; | |
1069 | |||
1070 |
2/2✓ Branch 0 taken 14318 times.
✓ Branch 1 taken 255730 times.
|
270048 | if(has_ac){ |
1071 | 14318 | ptr[0] = dc; | |
1072 | 14318 | r->rdsp.rv34_idct_add(dst+4*i, s->linesize, ptr); | |
1073 | }else | ||
1074 | 255730 | r->rdsp.rv34_idct_dc_add(dst+4*i, s->linesize, dc); | |
1075 | } | ||
1076 | |||
1077 | 67512 | dst += 4*s->linesize; | |
1078 | } | ||
1079 | |||
1080 | 16878 | itype = ittrans16[intra_types[0]]; | |
1081 |
2/2✓ Branch 0 taken 1214 times.
✓ Branch 1 taken 15664 times.
|
16878 | if(itype == PLANE_PRED8x8) itype = DC_PRED8x8; |
1082 | 16878 | itype = adjust_pred16(itype, r->avail_cache[6-4], r->avail_cache[6-1]); | |
1083 | |||
1084 | 16878 | q_dc = rv34_qscale_tab[rv34_chroma_quant[1][s->qscale]]; | |
1085 | 16878 | q_ac = rv34_qscale_tab[rv34_chroma_quant[0][s->qscale]]; | |
1086 | |||
1087 |
2/2✓ Branch 0 taken 33756 times.
✓ Branch 1 taken 16878 times.
|
50634 | for(j = 1; j < 3; j++){ |
1088 | 33756 | dst = s->dest[j]; | |
1089 | 33756 | r->h.pred8x8[itype](dst, s->uvlinesize); | |
1090 |
2/2✓ Branch 0 taken 135024 times.
✓ Branch 1 taken 33756 times.
|
168780 | for(i = 0; i < 4; i++, cbp >>= 1){ |
1091 | uint8_t *pdst; | ||
1092 |
2/2✓ Branch 0 taken 110244 times.
✓ Branch 1 taken 24780 times.
|
135024 | if(!(cbp & 1)) continue; |
1093 | 24780 | pdst = dst + (i&1)*4 + (i&2)*2*s->uvlinesize; | |
1094 | |||
1095 | 24780 | rv34_process_block(r, pdst, s->uvlinesize, | |
1096 | r->chroma_vlc, 1, q_dc, q_ac); | ||
1097 | } | ||
1098 | } | ||
1099 | 16878 | } | |
1100 | |||
1101 | 15129 | static void rv34_output_intra(RV34DecContext *r, int8_t *intra_types, int cbp) | |
1102 | { | ||
1103 | 15129 | MpegEncContext *s = &r->s; | |
1104 | 15129 | uint8_t *dst = s->dest[0]; | |
1105 | 15129 | int avail[6*8] = {0}; | |
1106 | int i, j, k; | ||
1107 | int idx, q_ac, q_dc; | ||
1108 | |||
1109 | // Set neighbour information. | ||
1110 |
2/2✓ Branch 0 taken 8929 times.
✓ Branch 1 taken 6200 times.
|
15129 | if(r->avail_cache[1]) |
1111 | 8929 | avail[0] = 1; | |
1112 |
2/2✓ Branch 0 taken 9550 times.
✓ Branch 1 taken 5579 times.
|
15129 | if(r->avail_cache[2]) |
1113 | 9550 | avail[1] = avail[2] = 1; | |
1114 |
2/2✓ Branch 0 taken 9550 times.
✓ Branch 1 taken 5579 times.
|
15129 | if(r->avail_cache[3]) |
1115 | 9550 | avail[3] = avail[4] = 1; | |
1116 |
2/2✓ Branch 0 taken 9514 times.
✓ Branch 1 taken 5615 times.
|
15129 | if(r->avail_cache[4]) |
1117 | 9514 | avail[5] = 1; | |
1118 |
2/2✓ Branch 0 taken 14351 times.
✓ Branch 1 taken 778 times.
|
15129 | if(r->avail_cache[5]) |
1119 | 14351 | avail[8] = avail[16] = 1; | |
1120 |
2/2✓ Branch 0 taken 14351 times.
✓ Branch 1 taken 778 times.
|
15129 | if(r->avail_cache[9]) |
1121 | 14351 | avail[24] = avail[32] = 1; | |
1122 | |||
1123 | 15129 | q_ac = rv34_qscale_tab[s->qscale]; | |
1124 |
2/2✓ Branch 0 taken 60516 times.
✓ Branch 1 taken 15129 times.
|
75645 | for(j = 0; j < 4; j++){ |
1125 | 60516 | idx = 9 + j*8; | |
1126 |
2/2✓ Branch 0 taken 242064 times.
✓ Branch 1 taken 60516 times.
|
302580 | for(i = 0; i < 4; i++, cbp >>= 1, dst += 4, idx++){ |
1127 | 242064 | rv34_pred_4x4_block(r, dst, s->linesize, ittrans[intra_types[i]], avail[idx-8], avail[idx-1], avail[idx+7], avail[idx-7]); | |
1128 | 242064 | avail[idx] = 1; | |
1129 |
2/2✓ Branch 0 taken 93479 times.
✓ Branch 1 taken 148585 times.
|
242064 | if(!(cbp & 1)) continue; |
1130 | |||
1131 | 148585 | rv34_process_block(r, dst, s->linesize, | |
1132 | r->luma_vlc, 0, q_ac, q_ac); | ||
1133 | } | ||
1134 | 60516 | dst += s->linesize * 4 - 4*4; | |
1135 | 60516 | intra_types += r->intra_types_stride; | |
1136 | } | ||
1137 | |||
1138 | 15129 | intra_types -= r->intra_types_stride * 4; | |
1139 | |||
1140 | 15129 | q_dc = rv34_qscale_tab[rv34_chroma_quant[1][s->qscale]]; | |
1141 | 15129 | q_ac = rv34_qscale_tab[rv34_chroma_quant[0][s->qscale]]; | |
1142 | |||
1143 |
2/2✓ Branch 0 taken 30258 times.
✓ Branch 1 taken 15129 times.
|
45387 | for(k = 0; k < 2; k++){ |
1144 | 30258 | dst = s->dest[1+k]; | |
1145 | 30258 | fill_rectangle(r->avail_cache + 6, 2, 2, 4, 0, 4); | |
1146 | |||
1147 |
2/2✓ Branch 0 taken 60516 times.
✓ Branch 1 taken 30258 times.
|
90774 | for(j = 0; j < 2; j++){ |
1148 | 60516 | int* acache = r->avail_cache + 6 + j*4; | |
1149 |
2/2✓ Branch 0 taken 121032 times.
✓ Branch 1 taken 60516 times.
|
181548 | for(i = 0; i < 2; i++, cbp >>= 1, acache++){ |
1150 | 121032 | int itype = ittrans[intra_types[i*2+j*2*r->intra_types_stride]]; | |
1151 |
4/4✓ Branch 0 taken 60516 times.
✓ Branch 1 taken 60516 times.
✓ Branch 2 taken 30258 times.
✓ Branch 3 taken 30258 times.
|
121032 | rv34_pred_4x4_block(r, dst+4*i, s->uvlinesize, itype, acache[-4], acache[-1], !i && !j, acache[-3]); |
1152 | 121032 | acache[0] = 1; | |
1153 | |||
1154 |
2/2✓ Branch 0 taken 49869 times.
✓ Branch 1 taken 71163 times.
|
121032 | if(!(cbp&1)) continue; |
1155 | |||
1156 | 71163 | rv34_process_block(r, dst + 4*i, s->uvlinesize, | |
1157 | r->chroma_vlc, 1, q_dc, q_ac); | ||
1158 | } | ||
1159 | |||
1160 | 60516 | dst += 4*s->uvlinesize; | |
1161 | } | ||
1162 | } | ||
1163 | 15129 | } | |
1164 | |||
1165 | 2257744 | static int is_mv_diff_gt_3(int16_t (*motion_val)[2], int step) | |
1166 | { | ||
1167 | int d; | ||
1168 | 2257744 | d = motion_val[0][0] - motion_val[-step][0]; | |
1169 |
4/4✓ Branch 0 taken 2164788 times.
✓ Branch 1 taken 92956 times.
✓ Branch 2 taken 96398 times.
✓ Branch 3 taken 2068390 times.
|
2257744 | if(d < -3 || d > 3) |
1170 | 189354 | return 1; | |
1171 | 2068390 | d = motion_val[0][1] - motion_val[-step][1]; | |
1172 |
4/4✓ Branch 0 taken 2053961 times.
✓ Branch 1 taken 14429 times.
✓ Branch 2 taken 17585 times.
✓ Branch 3 taken 2036376 times.
|
2068390 | if(d < -3 || d > 3) |
1173 | 32014 | return 1; | |
1174 | 2036376 | return 0; | |
1175 | } | ||
1176 | |||
1177 | 286080 | static int rv34_set_deblock_coef(RV34DecContext *r) | |
1178 | { | ||
1179 | 286080 | MpegEncContext *s = &r->s; | |
1180 | 286080 | int hmvmask = 0, vmvmask = 0, i, j; | |
1181 | 286080 | int midx = s->mb_x * 2 + s->mb_y * 2 * s->b8_stride; | |
1182 | 286080 | int16_t (*motion_val)[2] = &s->current_picture_ptr->motion_val[0][midx]; | |
1183 |
2/2✓ Branch 0 taken 572160 times.
✓ Branch 1 taken 286080 times.
|
858240 | for(j = 0; j < 16; j += 8){ |
1184 |
2/2✓ Branch 0 taken 1144320 times.
✓ Branch 1 taken 572160 times.
|
1716480 | for(i = 0; i < 2; i++){ |
1185 |
2/2✓ Branch 1 taken 107013 times.
✓ Branch 2 taken 1037307 times.
|
1144320 | if(is_mv_diff_gt_3(motion_val + i, 1)) |
1186 | 107013 | vmvmask |= 0x11 << (j + i*2); | |
1187 |
6/6✓ Branch 0 taken 572160 times.
✓ Branch 1 taken 572160 times.
✓ Branch 2 taken 541264 times.
✓ Branch 3 taken 30896 times.
✓ Branch 5 taken 114355 times.
✓ Branch 6 taken 999069 times.
|
1144320 | if((j || s->mb_y) && is_mv_diff_gt_3(motion_val + i, s->b8_stride)) |
1188 | 114355 | hmvmask |= 0x03 << (j + i*2); | |
1189 | } | ||
1190 | 572160 | motion_val += s->b8_stride; | |
1191 | } | ||
1192 |
2/2✓ Branch 0 taken 42563 times.
✓ Branch 1 taken 243517 times.
|
286080 | if(s->first_slice_line) |
1193 | 42563 | hmvmask &= ~0x000F; | |
1194 |
2/2✓ Branch 0 taken 9160 times.
✓ Branch 1 taken 276920 times.
|
286080 | if(!s->mb_x) |
1195 | 9160 | vmvmask &= ~0x1111; | |
1196 |
2/2✓ Branch 0 taken 68640 times.
✓ Branch 1 taken 217440 times.
|
286080 | if(r->rv30){ //RV30 marks both subblocks on the edge for filtering |
1197 | 68640 | vmvmask |= (vmvmask & 0x4444) >> 1; | |
1198 | 68640 | hmvmask |= (hmvmask & 0x0F00) >> 4; | |
1199 |
2/2✓ Branch 0 taken 65520 times.
✓ Branch 1 taken 3120 times.
|
68640 | if(s->mb_x) |
1200 | 65520 | r->deblock_coefs[s->mb_x - 1 + s->mb_y*s->mb_stride] |= (vmvmask & 0x1111) << 3; | |
1201 |
2/2✓ Branch 0 taken 61878 times.
✓ Branch 1 taken 6762 times.
|
68640 | if(!s->first_slice_line) |
1202 | 61878 | r->deblock_coefs[s->mb_x + (s->mb_y - 1)*s->mb_stride] |= (hmvmask & 0xF) << 12; | |
1203 | } | ||
1204 | 286080 | return hmvmask | vmvmask; | |
1205 | } | ||
1206 | |||
1207 | 286080 | static int rv34_decode_inter_macroblock(RV34DecContext *r, int8_t *intra_types) | |
1208 | { | ||
1209 | 286080 | MpegEncContext *s = &r->s; | |
1210 | 286080 | GetBitContext *gb = &s->gb; | |
1211 | 286080 | uint8_t *dst = s->dest[0]; | |
1212 | 286080 | int16_t *ptr = s->block[0]; | |
1213 | 286080 | int mb_pos = s->mb_x + s->mb_y * s->mb_stride; | |
1214 | int cbp, cbp2; | ||
1215 | int q_dc, q_ac, has_ac; | ||
1216 | int i, j; | ||
1217 | int dist; | ||
1218 | |||
1219 | // Calculate which neighbours are available. Maybe it's worth optimizing too. | ||
1220 | 286080 | memset(r->avail_cache, 0, sizeof(r->avail_cache)); | |
1221 | 286080 | fill_rectangle(r->avail_cache + 6, 2, 2, 4, 1, 4); | |
1222 | 286080 | dist = (s->mb_x - s->resync_mb_x) + (s->mb_y - s->resync_mb_y) * s->mb_width; | |
1223 |
4/4✓ Branch 0 taken 276920 times.
✓ Branch 1 taken 9160 times.
✓ Branch 2 taken 276415 times.
✓ Branch 3 taken 505 times.
|
286080 | if(s->mb_x && dist) |
1224 | 276415 | r->avail_cache[5] = | |
1225 | 276415 | r->avail_cache[9] = s->current_picture_ptr->mb_type[mb_pos - 1]; | |
1226 |
2/2✓ Branch 0 taken 243517 times.
✓ Branch 1 taken 42563 times.
|
286080 | if(dist >= s->mb_width) |
1227 | 243517 | r->avail_cache[2] = | |
1228 | 243517 | r->avail_cache[3] = s->current_picture_ptr->mb_type[mb_pos - s->mb_stride]; | |
1229 |
4/4✓ Branch 0 taken 276920 times.
✓ Branch 1 taken 9160 times.
✓ Branch 2 taken 236121 times.
✓ Branch 3 taken 40799 times.
|
286080 | if(((s->mb_x+1) < s->mb_width) && dist >= s->mb_width - 1) |
1230 | 236121 | r->avail_cache[4] = s->current_picture_ptr->mb_type[mb_pos - s->mb_stride + 1]; | |
1231 |
4/4✓ Branch 0 taken 276920 times.
✓ Branch 1 taken 9160 times.
✓ Branch 2 taken 235192 times.
✓ Branch 3 taken 41728 times.
|
286080 | if(s->mb_x && dist > s->mb_width) |
1232 | 235192 | r->avail_cache[1] = s->current_picture_ptr->mb_type[mb_pos - s->mb_stride - 1]; | |
1233 | |||
1234 | 286080 | s->qscale = r->si.quant; | |
1235 | 286080 | cbp = cbp2 = rv34_decode_inter_mb_header(r, intra_types); | |
1236 | 286080 | r->cbp_luma [mb_pos] = cbp; | |
1237 | 286080 | r->cbp_chroma[mb_pos] = cbp >> 16; | |
1238 | 286080 | r->deblock_coefs[mb_pos] = rv34_set_deblock_coef(r) | r->cbp_luma[mb_pos]; | |
1239 | 286080 | s->current_picture_ptr->qscale_table[mb_pos] = s->qscale; | |
1240 | |||
1241 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 286080 times.
|
286080 | if(cbp == -1) |
1242 | ✗ | return -1; | |
1243 | |||
1244 |
2/2✓ Branch 0 taken 24367 times.
✓ Branch 1 taken 261713 times.
|
286080 | if (IS_INTRA(s->current_picture_ptr->mb_type[mb_pos])){ |
1245 |
2/2✓ Branch 0 taken 11048 times.
✓ Branch 1 taken 13319 times.
|
24367 | if(r->is16) rv34_output_i16x16(r, intra_types, cbp); |
1246 | 13319 | else rv34_output_intra(r, intra_types, cbp); | |
1247 | 24367 | return 0; | |
1248 | } | ||
1249 | |||
1250 |
2/2✓ Branch 0 taken 549 times.
✓ Branch 1 taken 261164 times.
|
261713 | if(r->is16){ |
1251 | // Only for RV34_MB_P_MIX16x16 | ||
1252 | 549 | LOCAL_ALIGNED_16(int16_t, block16, [16]); | |
1253 | 549 | memset(block16, 0, 16 * sizeof(*block16)); | |
1254 | 549 | q_dc = rv34_qscale_tab[ r->luma_dc_quant_p[s->qscale] ]; | |
1255 | 549 | q_ac = rv34_qscale_tab[s->qscale]; | |
1256 |
2/2✓ Branch 1 taken 268 times.
✓ Branch 2 taken 281 times.
|
549 | if (rv34_decode_block(block16, gb, r->cur_vlcs, 3, 0, q_dc, q_dc, q_ac)) |
1257 | 268 | r->rdsp.rv34_inv_transform(block16); | |
1258 | else | ||
1259 | 281 | r->rdsp.rv34_inv_transform_dc(block16); | |
1260 | |||
1261 | 549 | q_ac = rv34_qscale_tab[s->qscale]; | |
1262 | |||
1263 |
2/2✓ Branch 0 taken 2196 times.
✓ Branch 1 taken 549 times.
|
2745 | for(j = 0; j < 4; j++){ |
1264 |
2/2✓ Branch 0 taken 8784 times.
✓ Branch 1 taken 2196 times.
|
10980 | for(i = 0; i < 4; i++, cbp >>= 1){ |
1265 | 8784 | int dc = block16[i + j*4]; | |
1266 | |||
1267 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 8778 times.
|
8784 | if(cbp & 1){ |
1268 | 6 | has_ac = rv34_decode_block(ptr, gb, r->cur_vlcs, r->luma_vlc, 0, q_ac, q_ac, q_ac); | |
1269 | }else | ||
1270 | 8778 | has_ac = 0; | |
1271 | |||
1272 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 8778 times.
|
8784 | if(has_ac){ |
1273 | 6 | ptr[0] = dc; | |
1274 | 6 | r->rdsp.rv34_idct_add(dst+4*i, s->linesize, ptr); | |
1275 | }else | ||
1276 | 8778 | r->rdsp.rv34_idct_dc_add(dst+4*i, s->linesize, dc); | |
1277 | } | ||
1278 | |||
1279 | 2196 | dst += 4*s->linesize; | |
1280 | } | ||
1281 | |||
1282 | 549 | r->cur_vlcs = choose_vlc_set(r->si.quant, r->si.vlc_set, 1); | |
1283 | }else{ | ||
1284 | 261164 | q_ac = rv34_qscale_tab[s->qscale]; | |
1285 | |||
1286 |
2/2✓ Branch 0 taken 1044656 times.
✓ Branch 1 taken 261164 times.
|
1305820 | for(j = 0; j < 4; j++){ |
1287 |
2/2✓ Branch 0 taken 4178624 times.
✓ Branch 1 taken 1044656 times.
|
5223280 | for(i = 0; i < 4; i++, cbp >>= 1){ |
1288 |
2/2✓ Branch 0 taken 3859345 times.
✓ Branch 1 taken 319279 times.
|
4178624 | if(!(cbp & 1)) continue; |
1289 | |||
1290 | 319279 | rv34_process_block(r, dst + 4*i, s->linesize, | |
1291 | r->luma_vlc, 0, q_ac, q_ac); | ||
1292 | } | ||
1293 | 1044656 | dst += 4*s->linesize; | |
1294 | } | ||
1295 | } | ||
1296 | |||
1297 | 261713 | q_dc = rv34_qscale_tab[rv34_chroma_quant[1][s->qscale]]; | |
1298 | 261713 | q_ac = rv34_qscale_tab[rv34_chroma_quant[0][s->qscale]]; | |
1299 | |||
1300 |
2/2✓ Branch 0 taken 523426 times.
✓ Branch 1 taken 261713 times.
|
785139 | for(j = 1; j < 3; j++){ |
1301 | 523426 | dst = s->dest[j]; | |
1302 |
2/2✓ Branch 0 taken 2093704 times.
✓ Branch 1 taken 523426 times.
|
2617130 | for(i = 0; i < 4; i++, cbp >>= 1){ |
1303 | uint8_t *pdst; | ||
1304 |
2/2✓ Branch 0 taken 1948905 times.
✓ Branch 1 taken 144799 times.
|
2093704 | if(!(cbp & 1)) continue; |
1305 | 144799 | pdst = dst + (i&1)*4 + (i&2)*2*s->uvlinesize; | |
1306 | |||
1307 | 144799 | rv34_process_block(r, pdst, s->uvlinesize, | |
1308 | r->chroma_vlc, 1, q_dc, q_ac); | ||
1309 | } | ||
1310 | } | ||
1311 | |||
1312 | 261713 | return 0; | |
1313 | } | ||
1314 | |||
1315 | 7640 | static int rv34_decode_intra_macroblock(RV34DecContext *r, int8_t *intra_types) | |
1316 | { | ||
1317 | 7640 | MpegEncContext *s = &r->s; | |
1318 | int cbp, dist; | ||
1319 | 7640 | int mb_pos = s->mb_x + s->mb_y * s->mb_stride; | |
1320 | |||
1321 | // Calculate which neighbours are available. Maybe it's worth optimizing too. | ||
1322 | 7640 | memset(r->avail_cache, 0, sizeof(r->avail_cache)); | |
1323 | 7640 | fill_rectangle(r->avail_cache + 6, 2, 2, 4, 1, 4); | |
1324 | 7640 | dist = (s->mb_x - s->resync_mb_x) + (s->mb_y - s->resync_mb_y) * s->mb_width; | |
1325 |
4/4✓ Branch 0 taken 7352 times.
✓ Branch 1 taken 288 times.
✓ Branch 2 taken 7325 times.
✓ Branch 3 taken 27 times.
|
7640 | if(s->mb_x && dist) |
1326 | 7325 | r->avail_cache[5] = | |
1327 | 7325 | r->avail_cache[9] = s->current_picture_ptr->mb_type[mb_pos - 1]; | |
1328 |
2/2✓ Branch 0 taken 6133 times.
✓ Branch 1 taken 1507 times.
|
7640 | if(dist >= s->mb_width) |
1329 | 6133 | r->avail_cache[2] = | |
1330 | 6133 | r->avail_cache[3] = s->current_picture_ptr->mb_type[mb_pos - s->mb_stride]; | |
1331 |
4/4✓ Branch 0 taken 7352 times.
✓ Branch 1 taken 288 times.
✓ Branch 2 taken 5928 times.
✓ Branch 3 taken 1424 times.
|
7640 | if(((s->mb_x+1) < s->mb_width) && dist >= s->mb_width - 1) |
1332 | 5928 | r->avail_cache[4] = s->current_picture_ptr->mb_type[mb_pos - s->mb_stride + 1]; | |
1333 |
4/4✓ Branch 0 taken 7352 times.
✓ Branch 1 taken 288 times.
✓ Branch 2 taken 5878 times.
✓ Branch 3 taken 1474 times.
|
7640 | if(s->mb_x && dist > s->mb_width) |
1334 | 5878 | r->avail_cache[1] = s->current_picture_ptr->mb_type[mb_pos - s->mb_stride - 1]; | |
1335 | |||
1336 | 7640 | s->qscale = r->si.quant; | |
1337 | 7640 | cbp = rv34_decode_intra_mb_header(r, intra_types); | |
1338 | 7640 | r->cbp_luma [mb_pos] = cbp; | |
1339 | 7640 | r->cbp_chroma[mb_pos] = cbp >> 16; | |
1340 | 7640 | r->deblock_coefs[mb_pos] = 0xFFFF; | |
1341 | 7640 | s->current_picture_ptr->qscale_table[mb_pos] = s->qscale; | |
1342 | |||
1343 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7640 times.
|
7640 | if(cbp == -1) |
1344 | ✗ | return -1; | |
1345 | |||
1346 |
2/2✓ Branch 0 taken 5830 times.
✓ Branch 1 taken 1810 times.
|
7640 | if(r->is16){ |
1347 | 5830 | rv34_output_i16x16(r, intra_types, cbp); | |
1348 | 5830 | return 0; | |
1349 | } | ||
1350 | |||
1351 | 1810 | rv34_output_intra(r, intra_types, cbp); | |
1352 | 1810 | return 0; | |
1353 | } | ||
1354 | |||
1355 | 295111 | static int check_slice_end(RV34DecContext *r, MpegEncContext *s) | |
1356 | { | ||
1357 | int bits; | ||
1358 |
2/2✓ Branch 0 taken 528 times.
✓ Branch 1 taken 294583 times.
|
295111 | if(s->mb_y >= s->mb_height) |
1359 | 528 | return 1; | |
1360 |
2/2✓ Branch 0 taken 863 times.
✓ Branch 1 taken 293720 times.
|
294583 | if(!s->mb_num_left) |
1361 | 863 | return 1; | |
1362 |
2/2✓ Branch 0 taken 129066 times.
✓ Branch 1 taken 164654 times.
|
293720 | if(r->s.mb_skip_run > 1) |
1363 | 129066 | return 0; | |
1364 | 164654 | bits = get_bits_left(&s->gb); | |
1365 |
4/6✓ Branch 0 taken 164654 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 169 times.
✓ Branch 3 taken 164485 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 169 times.
|
164654 | if(bits <= 0 || (bits < 8 && !show_bits(&s->gb, bits))) |
1366 | ✗ | return 1; | |
1367 | 164654 | return 0; | |
1368 | } | ||
1369 | |||
1370 | |||
1371 | 9 | static void rv34_decoder_free(RV34DecContext *r) | |
1372 | { | ||
1373 | 9 | av_freep(&r->intra_types_hist); | |
1374 | 9 | r->intra_types = NULL; | |
1375 | 9 | av_freep(&r->tmp_b_block_base); | |
1376 | 9 | av_freep(&r->mb_type); | |
1377 | 9 | av_freep(&r->cbp_luma); | |
1378 | 9 | av_freep(&r->cbp_chroma); | |
1379 | 9 | av_freep(&r->deblock_coefs); | |
1380 | 9 | } | |
1381 | |||
1382 | |||
1383 | 9 | static int rv34_decoder_alloc(RV34DecContext *r) | |
1384 | { | ||
1385 | 9 | r->intra_types_stride = r->s.mb_width * 4 + 4; | |
1386 | |||
1387 | 9 | r->cbp_chroma = av_mallocz(r->s.mb_stride * r->s.mb_height * | |
1388 | sizeof(*r->cbp_chroma)); | ||
1389 | 9 | r->cbp_luma = av_mallocz(r->s.mb_stride * r->s.mb_height * | |
1390 | sizeof(*r->cbp_luma)); | ||
1391 | 9 | r->deblock_coefs = av_mallocz(r->s.mb_stride * r->s.mb_height * | |
1392 | sizeof(*r->deblock_coefs)); | ||
1393 | 9 | r->intra_types_hist = av_malloc(r->intra_types_stride * 4 * 2 * | |
1394 | sizeof(*r->intra_types_hist)); | ||
1395 | 9 | r->mb_type = av_mallocz(r->s.mb_stride * r->s.mb_height * | |
1396 | sizeof(*r->mb_type)); | ||
1397 | |||
1398 |
3/6✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
|
9 | if (!(r->cbp_chroma && r->cbp_luma && r->deblock_coefs && |
1399 |
2/4✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
|
9 | r->intra_types_hist && r->mb_type)) { |
1400 | ✗ | r->s.context_reinit = 1; | |
1401 | ✗ | rv34_decoder_free(r); | |
1402 | ✗ | return AVERROR(ENOMEM); | |
1403 | } | ||
1404 | |||
1405 | 9 | r->intra_types = r->intra_types_hist + r->intra_types_stride * 4; | |
1406 | |||
1407 | 9 | return 0; | |
1408 | } | ||
1409 | |||
1410 | |||
1411 | ✗ | static int rv34_decoder_realloc(RV34DecContext *r) | |
1412 | { | ||
1413 | ✗ | rv34_decoder_free(r); | |
1414 | ✗ | return rv34_decoder_alloc(r); | |
1415 | } | ||
1416 | |||
1417 | |||
1418 | 1391 | static int rv34_decode_slice(RV34DecContext *r, int end, const uint8_t* buf, int buf_size) | |
1419 | { | ||
1420 | 1391 | MpegEncContext *s = &r->s; | |
1421 | 1391 | GetBitContext *gb = &s->gb; | |
1422 | int mb_pos, slice_type; | ||
1423 | int res; | ||
1424 | |||
1425 | 1391 | init_get_bits(&r->s.gb, buf, buf_size*8); | |
1426 | 1391 | res = r->parse_slice_header(r, gb, &r->si); | |
1427 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1391 times.
|
1391 | if(res < 0){ |
1428 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Incorrect or unknown slice header\n"); | |
1429 | ✗ | return -1; | |
1430 | } | ||
1431 | |||
1432 |
2/2✓ Branch 0 taken 1332 times.
✓ Branch 1 taken 59 times.
|
1391 | slice_type = r->si.type ? r->si.type : AV_PICTURE_TYPE_I; |
1433 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1391 times.
|
1391 | if (slice_type != s->pict_type) { |
1434 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Slice type mismatch\n"); | |
1435 | ✗ | return AVERROR_INVALIDDATA; | |
1436 | } | ||
1437 |
2/4✓ Branch 0 taken 1391 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1391 times.
|
1391 | if (s->width != r->si.width || s->height != r->si.height) { |
1438 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Size mismatch\n"); | |
1439 | ✗ | return AVERROR_INVALIDDATA; | |
1440 | } | ||
1441 | |||
1442 | 1391 | r->si.end = end; | |
1443 | 1391 | s->qscale = r->si.quant; | |
1444 | 1391 | s->mb_num_left = r->si.end - r->si.start; | |
1445 | 1391 | r->s.mb_skip_run = 0; | |
1446 | |||
1447 | 1391 | mb_pos = s->mb_x + s->mb_y * s->mb_width; | |
1448 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1391 times.
|
1391 | if(r->si.start != mb_pos){ |
1449 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Slice indicates MB offset %d, got %d\n", r->si.start, mb_pos); | |
1450 | ✗ | s->mb_x = r->si.start % s->mb_width; | |
1451 | ✗ | s->mb_y = r->si.start / s->mb_width; | |
1452 | } | ||
1453 | 1391 | memset(r->intra_types_hist, -1, r->intra_types_stride * 4 * 2 * sizeof(*r->intra_types_hist)); | |
1454 | 1391 | s->first_slice_line = 1; | |
1455 | 1391 | s->resync_mb_x = s->mb_x; | |
1456 | 1391 | s->resync_mb_y = s->mb_y; | |
1457 | |||
1458 | 1391 | ff_init_block_index(s); | |
1459 |
2/2✓ Branch 1 taken 293720 times.
✓ Branch 2 taken 1391 times.
|
295111 | while(!check_slice_end(r, s)) { |
1460 | 293720 | ff_update_block_index(s, 8, 0, 1); | |
1461 | |||
1462 |
2/2✓ Branch 0 taken 286080 times.
✓ Branch 1 taken 7640 times.
|
293720 | if(r->si.type) |
1463 | 286080 | res = rv34_decode_inter_macroblock(r, r->intra_types + s->mb_x * 4 + 4); | |
1464 | else | ||
1465 | 7640 | res = rv34_decode_intra_macroblock(r, r->intra_types + s->mb_x * 4 + 4); | |
1466 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 293720 times.
|
293720 | if(res < 0){ |
1467 | ✗ | ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_ERROR); | |
1468 | ✗ | return -1; | |
1469 | } | ||
1470 |
2/2✓ Branch 0 taken 9448 times.
✓ Branch 1 taken 284272 times.
|
293720 | if (++s->mb_x == s->mb_width) { |
1471 | 9448 | s->mb_x = 0; | |
1472 | 9448 | s->mb_y++; | |
1473 | 9448 | ff_init_block_index(s); | |
1474 | |||
1475 | 9448 | memmove(r->intra_types_hist, r->intra_types, r->intra_types_stride * 4 * sizeof(*r->intra_types_hist)); | |
1476 | 9448 | memset(r->intra_types, -1, r->intra_types_stride * 4 * sizeof(*r->intra_types_hist)); | |
1477 | |||
1478 |
3/4✓ Branch 0 taken 9448 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8920 times.
✓ Branch 3 taken 528 times.
|
9448 | if(r->loop_filter && s->mb_y >= 2) |
1479 | 8920 | r->loop_filter(r, s->mb_y - 2); | |
1480 | |||
1481 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9448 times.
|
9448 | if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME)) |
1482 | ✗ | ff_thread_report_progress(&s->current_picture_ptr->tf, | |
1483 | ✗ | s->mb_y - 2, 0); | |
1484 | |||
1485 | } | ||
1486 |
2/2✓ Branch 0 taken 9069 times.
✓ Branch 1 taken 284651 times.
|
293720 | if(s->mb_x == s->resync_mb_x) |
1487 | 9069 | s->first_slice_line=0; | |
1488 | 293720 | s->mb_num_left--; | |
1489 | } | ||
1490 | 1391 | ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END); | |
1491 | |||
1492 | 1391 | return s->mb_y == s->mb_height; | |
1493 | } | ||
1494 | |||
1495 | /** @} */ // reconstruction group end | ||
1496 | |||
1497 | /** | ||
1498 | * Initialize decoder. | ||
1499 | */ | ||
1500 | 9 | av_cold int ff_rv34_decode_init(AVCodecContext *avctx) | |
1501 | { | ||
1502 | static AVOnce init_static_once = AV_ONCE_INIT; | ||
1503 | 9 | RV34DecContext *r = avctx->priv_data; | |
1504 | 9 | MpegEncContext *s = &r->s; | |
1505 | int ret; | ||
1506 | |||
1507 | 9 | ff_mpv_decode_init(s, avctx); | |
1508 | 9 | s->out_format = FMT_H263; | |
1509 | |||
1510 | 9 | avctx->pix_fmt = AV_PIX_FMT_YUV420P; | |
1511 | 9 | avctx->has_b_frames = 1; | |
1512 | 9 | s->low_delay = 0; | |
1513 | |||
1514 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
|
9 | if ((ret = ff_mpv_common_init(s)) < 0) |
1515 | ✗ | return ret; | |
1516 | |||
1517 | 9 | ff_h264_pred_init(&r->h, AV_CODEC_ID_RV40, 8, 1); | |
1518 | |||
1519 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
|
9 | if ((ret = rv34_decoder_alloc(r)) < 0) { |
1520 | ✗ | ff_mpv_common_end(&r->s); | |
1521 | ✗ | return ret; | |
1522 | } | ||
1523 | |||
1524 | 9 | ff_thread_once(&init_static_once, rv34_init_tables); | |
1525 | |||
1526 | 9 | return 0; | |
1527 | } | ||
1528 | |||
1529 | ✗ | int ff_rv34_decode_update_thread_context(AVCodecContext *dst, const AVCodecContext *src) | |
1530 | { | ||
1531 | ✗ | RV34DecContext *r = dst->priv_data, *r1 = src->priv_data; | |
1532 | ✗ | MpegEncContext * const s = &r->s, * const s1 = &r1->s; | |
1533 | int err; | ||
1534 | |||
1535 | ✗ | if (dst == src || !s1->context_initialized) | |
1536 | ✗ | return 0; | |
1537 | |||
1538 | ✗ | if (s->height != s1->height || s->width != s1->width || s->context_reinit) { | |
1539 | ✗ | s->height = s1->height; | |
1540 | ✗ | s->width = s1->width; | |
1541 | ✗ | if ((err = ff_mpv_common_frame_size_change(s)) < 0) | |
1542 | ✗ | return err; | |
1543 | ✗ | if ((err = rv34_decoder_realloc(r)) < 0) | |
1544 | ✗ | return err; | |
1545 | } | ||
1546 | |||
1547 | ✗ | r->cur_pts = r1->cur_pts; | |
1548 | ✗ | r->last_pts = r1->last_pts; | |
1549 | ✗ | r->next_pts = r1->next_pts; | |
1550 | |||
1551 | ✗ | memset(&r->si, 0, sizeof(r->si)); | |
1552 | |||
1553 | // Do no call ff_mpeg_update_thread_context on a partially initialized | ||
1554 | // decoder context. | ||
1555 | ✗ | if (!s1->context_initialized) | |
1556 | ✗ | return 0; | |
1557 | |||
1558 | ✗ | return ff_mpeg_update_thread_context(dst, src); | |
1559 | } | ||
1560 | |||
1561 | 4174 | static int get_slice_offset(AVCodecContext *avctx, const uint8_t *buf, int n, int slice_count, int buf_size) | |
1562 | { | ||
1563 |
2/2✓ Branch 0 taken 3287 times.
✓ Branch 1 taken 887 times.
|
4174 | if (n < slice_count) { |
1564 |
1/2✓ Branch 0 taken 3287 times.
✗ Branch 1 not taken.
|
3287 | return AV_RL32(buf + n*8 - 4) == 1 ? AV_RL32(buf + n*8) : AV_RB32(buf + n*8); |
1565 | } else | ||
1566 | 887 | return buf_size; | |
1567 | } | ||
1568 | |||
1569 | 528 | static int finish_frame(AVCodecContext *avctx, AVFrame *pict) | |
1570 | { | ||
1571 | 528 | RV34DecContext *r = avctx->priv_data; | |
1572 | 528 | MpegEncContext *s = &r->s; | |
1573 | 528 | int got_picture = 0, ret; | |
1574 | |||
1575 | 528 | ff_er_frame_end(&s->er, NULL); | |
1576 | 528 | ff_mpv_frame_end(s); | |
1577 | 528 | s->mb_num_left = 0; | |
1578 | |||
1579 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 528 times.
|
528 | if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME)) |
1580 | ✗ | ff_thread_report_progress(&s->current_picture_ptr->tf, INT_MAX, 0); | |
1581 | |||
1582 |
2/2✓ Branch 0 taken 388 times.
✓ Branch 1 taken 140 times.
|
528 | if (s->pict_type == AV_PICTURE_TYPE_B) { |
1583 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 388 times.
|
388 | if ((ret = av_frame_ref(pict, s->current_picture_ptr->f)) < 0) |
1584 | ✗ | return ret; | |
1585 | 388 | ff_print_debug_info(s, s->current_picture_ptr, pict); | |
1586 | 388 | ff_mpv_export_qp_table(s, pict, s->current_picture_ptr, FF_MPV_QSCALE_TYPE_MPEG1); | |
1587 | 388 | got_picture = 1; | |
1588 |
2/2✓ Branch 0 taken 131 times.
✓ Branch 1 taken 9 times.
|
140 | } else if (s->last_picture_ptr) { |
1589 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 131 times.
|
131 | if ((ret = av_frame_ref(pict, s->last_picture_ptr->f)) < 0) |
1590 | ✗ | return ret; | |
1591 | 131 | ff_print_debug_info(s, s->last_picture_ptr, pict); | |
1592 | 131 | ff_mpv_export_qp_table(s, pict, s->last_picture_ptr, FF_MPV_QSCALE_TYPE_MPEG1); | |
1593 | 131 | got_picture = 1; | |
1594 | } | ||
1595 | |||
1596 | 528 | return got_picture; | |
1597 | } | ||
1598 | |||
1599 | ✗ | static AVRational update_sar(int old_w, int old_h, AVRational sar, int new_w, int new_h) | |
1600 | { | ||
1601 | // attempt to keep aspect during typical resolution switches | ||
1602 | ✗ | if (!sar.num) | |
1603 | ✗ | sar = (AVRational){1, 1}; | |
1604 | |||
1605 | ✗ | sar = av_mul_q(sar, av_mul_q((AVRational){new_h, new_w}, (AVRational){old_w, old_h})); | |
1606 | ✗ | return sar; | |
1607 | } | ||
1608 | |||
1609 | 532 | int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict, | |
1610 | int *got_picture_ptr, AVPacket *avpkt) | ||
1611 | { | ||
1612 | 532 | const uint8_t *buf = avpkt->data; | |
1613 | 532 | int buf_size = avpkt->size; | |
1614 | 532 | RV34DecContext *r = avctx->priv_data; | |
1615 | 532 | MpegEncContext *s = &r->s; | |
1616 | SliceInfo si; | ||
1617 | int i, ret; | ||
1618 | int slice_count; | ||
1619 | 532 | const uint8_t *slices_hdr = NULL; | |
1620 | 532 | int last = 0; | |
1621 | 532 | int faulty_b = 0; | |
1622 | int offset; | ||
1623 | |||
1624 | /* no supplementary picture */ | ||
1625 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 528 times.
|
532 | if (buf_size == 0) { |
1626 | /* special case for last picture */ | ||
1627 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | if (s->next_picture_ptr) { |
1628 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | if ((ret = av_frame_ref(pict, s->next_picture_ptr->f)) < 0) |
1629 | ✗ | return ret; | |
1630 | 2 | s->next_picture_ptr = NULL; | |
1631 | |||
1632 | 2 | *got_picture_ptr = 1; | |
1633 | } | ||
1634 | 4 | return 0; | |
1635 | } | ||
1636 | |||
1637 | 528 | slice_count = (*buf++) + 1; | |
1638 | 528 | slices_hdr = buf + 4; | |
1639 | 528 | buf += 8 * slice_count; | |
1640 | 528 | buf_size -= 1 + 8 * slice_count; | |
1641 | |||
1642 | 528 | offset = get_slice_offset(avctx, slices_hdr, 0, slice_count, buf_size); | |
1643 | //parse first slice header to check whether this frame can be decoded | ||
1644 |
2/4✓ Branch 0 taken 528 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 528 times.
|
528 | if(offset < 0 || offset > buf_size){ |
1645 | ✗ | av_log(avctx, AV_LOG_ERROR, "Slice offset is invalid\n"); | |
1646 | ✗ | return AVERROR_INVALIDDATA; | |
1647 | } | ||
1648 | 528 | init_get_bits(&s->gb, buf+offset, (buf_size-offset)*8); | |
1649 |
2/4✓ Branch 1 taken 528 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 528 times.
|
528 | if(r->parse_slice_header(r, &r->s.gb, &si) < 0 || si.start){ |
1650 | ✗ | av_log(avctx, AV_LOG_ERROR, "First slice header is incorrect\n"); | |
1651 | ✗ | return AVERROR_INVALIDDATA; | |
1652 | } | ||
1653 |
3/4✓ Branch 0 taken 515 times.
✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 515 times.
|
528 | if ((!s->last_picture_ptr || !s->last_picture_ptr->f->data[0]) && |
1654 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
|
13 | si.type == AV_PICTURE_TYPE_B) { |
1655 | ✗ | av_log(avctx, AV_LOG_ERROR, "Invalid decoder state: B-frame without " | |
1656 | "reference data.\n"); | ||
1657 | ✗ | faulty_b = 1; | |
1658 | } | ||
1659 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 528 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
528 | if( (avctx->skip_frame >= AVDISCARD_NONREF && si.type==AV_PICTURE_TYPE_B) |
1660 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 528 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
528 | || (avctx->skip_frame >= AVDISCARD_NONKEY && si.type!=AV_PICTURE_TYPE_I) |
1661 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 528 times.
|
528 | || avctx->skip_frame >= AVDISCARD_ALL) |
1662 | ✗ | return avpkt->size; | |
1663 | |||
1664 | /* first slice */ | ||
1665 |
1/2✓ Branch 0 taken 528 times.
✗ Branch 1 not taken.
|
528 | if (si.start == 0) { |
1666 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 528 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
528 | if (s->mb_num_left > 0 && s->current_picture_ptr) { |
1667 | ✗ | av_log(avctx, AV_LOG_ERROR, "New frame but still %d MB left.\n", | |
1668 | s->mb_num_left); | ||
1669 | ✗ | if (!s->context_reinit) | |
1670 | ✗ | ff_er_frame_end(&s->er, NULL); | |
1671 | ✗ | ff_mpv_frame_end(s); | |
1672 | } | ||
1673 | |||
1674 |
3/6✓ Branch 0 taken 528 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 528 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 528 times.
|
528 | if (s->width != si.width || s->height != si.height || s->context_reinit) { |
1675 | int err; | ||
1676 | |||
1677 | ✗ | av_log(s->avctx, AV_LOG_WARNING, "Changing dimensions to %dx%d\n", | |
1678 | si.width, si.height); | ||
1679 | |||
1680 | ✗ | if (av_image_check_size(si.width, si.height, 0, s->avctx)) | |
1681 | ✗ | return AVERROR_INVALIDDATA; | |
1682 | |||
1683 | ✗ | s->avctx->sample_aspect_ratio = update_sar( | |
1684 | ✗ | s->width, s->height, s->avctx->sample_aspect_ratio, | |
1685 | si.width, si.height); | ||
1686 | ✗ | s->width = si.width; | |
1687 | ✗ | s->height = si.height; | |
1688 | |||
1689 | ✗ | err = ff_set_dimensions(s->avctx, s->width, s->height); | |
1690 | ✗ | if (err < 0) | |
1691 | ✗ | return err; | |
1692 | ✗ | if ((err = ff_mpv_common_frame_size_change(s)) < 0) | |
1693 | ✗ | return err; | |
1694 | ✗ | if ((err = rv34_decoder_realloc(r)) < 0) | |
1695 | ✗ | return err; | |
1696 | } | ||
1697 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 528 times.
|
528 | if (faulty_b) |
1698 | ✗ | return AVERROR_INVALIDDATA; | |
1699 |
2/2✓ Branch 0 taken 510 times.
✓ Branch 1 taken 18 times.
|
528 | s->pict_type = si.type ? si.type : AV_PICTURE_TYPE_I; |
1700 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 528 times.
|
528 | if (ff_mpv_frame_start(s, s->avctx) < 0) |
1701 | ✗ | return -1; | |
1702 | 528 | ff_mpeg_er_frame_start(s); | |
1703 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 519 times.
|
528 | if (!r->tmp_b_block_base) { |
1704 | int i; | ||
1705 | |||
1706 | 9 | r->tmp_b_block_base = av_malloc(s->linesize * 48); | |
1707 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (!r->tmp_b_block_base) |
1708 | ✗ | return AVERROR(ENOMEM); | |
1709 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
|
27 | for (i = 0; i < 2; i++) |
1710 | 18 | r->tmp_b_block_y[i] = r->tmp_b_block_base | |
1711 | 18 | + i * 16 * s->linesize; | |
1712 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 9 times.
|
45 | for (i = 0; i < 4; i++) |
1713 | 36 | r->tmp_b_block_uv[i] = r->tmp_b_block_base + 32 * s->linesize | |
1714 | 36 | + (i >> 1) * 8 * s->uvlinesize | |
1715 | 36 | + (i & 1) * 16; | |
1716 | } | ||
1717 | 528 | r->cur_pts = si.pts; | |
1718 |
2/2✓ Branch 0 taken 140 times.
✓ Branch 1 taken 388 times.
|
528 | if (s->pict_type != AV_PICTURE_TYPE_B) { |
1719 | 140 | r->last_pts = r->next_pts; | |
1720 | 140 | r->next_pts = r->cur_pts; | |
1721 | } else { | ||
1722 | 388 | int refdist = GET_PTS_DIFF(r->next_pts, r->last_pts); | |
1723 | 388 | int dist0 = GET_PTS_DIFF(r->cur_pts, r->last_pts); | |
1724 | 388 | int dist1 = GET_PTS_DIFF(r->next_pts, r->cur_pts); | |
1725 | |||
1726 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 388 times.
|
388 | if(!refdist){ |
1727 | ✗ | r->mv_weight1 = r->mv_weight2 = r->weight1 = r->weight2 = 8192; | |
1728 | ✗ | r->scaled_weight = 0; | |
1729 | }else{ | ||
1730 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 388 times.
|
388 | if (FFMAX(dist0, dist1) > refdist) |
1731 | ✗ | av_log(avctx, AV_LOG_TRACE, "distance overflow\n"); | |
1732 | |||
1733 | 388 | r->mv_weight1 = (dist0 << 14) / refdist; | |
1734 | 388 | r->mv_weight2 = (dist1 << 14) / refdist; | |
1735 |
2/2✓ Branch 0 taken 350 times.
✓ Branch 1 taken 38 times.
|
388 | if((r->mv_weight1|r->mv_weight2) & 511){ |
1736 | 350 | r->weight1 = r->mv_weight1; | |
1737 | 350 | r->weight2 = r->mv_weight2; | |
1738 | 350 | r->scaled_weight = 0; | |
1739 | }else{ | ||
1740 | 38 | r->weight1 = r->mv_weight1 >> 9; | |
1741 | 38 | r->weight2 = r->mv_weight2 >> 9; | |
1742 | 38 | r->scaled_weight = 1; | |
1743 | } | ||
1744 | } | ||
1745 | } | ||
1746 | 528 | s->mb_x = s->mb_y = 0; | |
1747 | 528 | ff_thread_finish_setup(s->avctx); | |
1748 | ✗ | } else if (s->context_reinit) { | |
1749 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Decoder needs full frames to " | |
1750 | "reinitialize (start MB is %d).\n", si.start); | ||
1751 | ✗ | return AVERROR_INVALIDDATA; | |
1752 | ✗ | } else if (HAVE_THREADS && | |
1753 | ✗ | (s->avctx->active_thread_type & FF_THREAD_FRAME)) { | |
1754 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Decoder needs full frames in frame " | |
1755 | "multithreading mode (start MB is %d).\n", si.start); | ||
1756 | ✗ | return AVERROR_INVALIDDATA; | |
1757 | } | ||
1758 | |||
1759 |
1/2✓ Branch 0 taken 1391 times.
✗ Branch 1 not taken.
|
1391 | for(i = 0; i < slice_count; i++){ |
1760 | 1391 | int offset = get_slice_offset(avctx, slices_hdr, i , slice_count, buf_size); | |
1761 | 1391 | int offset1 = get_slice_offset(avctx, slices_hdr, i+1, slice_count, buf_size); | |
1762 | int size; | ||
1763 | |||
1764 |
3/6✓ Branch 0 taken 1391 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1391 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1391 times.
|
1391 | if(offset < 0 || offset > offset1 || offset1 > buf_size){ |
1765 | ✗ | av_log(avctx, AV_LOG_ERROR, "Slice offset is invalid\n"); | |
1766 | ✗ | break; | |
1767 | } | ||
1768 | 1391 | size = offset1 - offset; | |
1769 | |||
1770 | 1391 | r->si.end = s->mb_width * s->mb_height; | |
1771 | 1391 | s->mb_num_left = r->s.mb_x + r->s.mb_y*r->s.mb_width - r->si.start; | |
1772 | |||
1773 |
2/2✓ Branch 0 taken 864 times.
✓ Branch 1 taken 527 times.
|
1391 | if(i+1 < slice_count){ |
1774 | 864 | int offset2 = get_slice_offset(avctx, slices_hdr, i+2, slice_count, buf_size); | |
1775 |
2/4✓ Branch 0 taken 864 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 864 times.
|
864 | if (offset2 < offset1 || offset2 > buf_size) { |
1776 | ✗ | av_log(avctx, AV_LOG_ERROR, "Slice offset is invalid\n"); | |
1777 | ✗ | break; | |
1778 | } | ||
1779 | 864 | init_get_bits(&s->gb, buf+offset1, (buf_size-offset1)*8); | |
1780 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 863 times.
|
864 | if(r->parse_slice_header(r, &r->s.gb, &si) < 0){ |
1781 | 1 | size = offset2 - offset; | |
1782 | }else | ||
1783 | 863 | r->si.end = si.start; | |
1784 | } | ||
1785 |
2/4✓ Branch 0 taken 1391 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1391 times.
|
1391 | av_assert0 (size >= 0 && size <= buf_size - offset); |
1786 | 1391 | last = rv34_decode_slice(r, r->si.end, buf + offset, size); | |
1787 |
2/2✓ Branch 0 taken 528 times.
✓ Branch 1 taken 863 times.
|
1391 | if(last) |
1788 | 528 | break; | |
1789 | } | ||
1790 | |||
1791 |
1/2✓ Branch 0 taken 528 times.
✗ Branch 1 not taken.
|
528 | if (s->current_picture_ptr) { |
1792 |
1/2✓ Branch 0 taken 528 times.
✗ Branch 1 not taken.
|
528 | if (last) { |
1793 |
1/2✓ Branch 0 taken 528 times.
✗ Branch 1 not taken.
|
528 | if(r->loop_filter) |
1794 | 528 | r->loop_filter(r, s->mb_height - 1); | |
1795 | |||
1796 | 528 | ret = finish_frame(avctx, pict); | |
1797 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 528 times.
|
528 | if (ret < 0) |
1798 | ✗ | return ret; | |
1799 | 528 | *got_picture_ptr = ret; | |
1800 | ✗ | } else if (HAVE_THREADS && | |
1801 | ✗ | (s->avctx->active_thread_type & FF_THREAD_FRAME)) { | |
1802 | ✗ | av_log(avctx, AV_LOG_INFO, "marking unfished frame as finished\n"); | |
1803 | /* always mark the current frame as finished, frame-mt supports | ||
1804 | * only complete frames */ | ||
1805 | ✗ | ff_er_frame_end(&s->er, NULL); | |
1806 | ✗ | ff_mpv_frame_end(s); | |
1807 | ✗ | s->mb_num_left = 0; | |
1808 | ✗ | ff_thread_report_progress(&s->current_picture_ptr->tf, INT_MAX, 0); | |
1809 | ✗ | return AVERROR_INVALIDDATA; | |
1810 | } | ||
1811 | } | ||
1812 | |||
1813 | 528 | return avpkt->size; | |
1814 | } | ||
1815 | |||
1816 | 9 | av_cold int ff_rv34_decode_end(AVCodecContext *avctx) | |
1817 | { | ||
1818 | 9 | RV34DecContext *r = avctx->priv_data; | |
1819 | |||
1820 | 9 | ff_mpv_common_end(&r->s); | |
1821 | 9 | rv34_decoder_free(r); | |
1822 | |||
1823 | 9 | return 0; | |
1824 | } | ||
1825 |