FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/vc1.c
Date: 2026-09-22 20:02:34
Exec Total Coverage
Lines: 724 899 80.5%
Functions: 12 12 100.0%
Branches: 397 639 62.1%

Line Branch Exec Source
1 /*
2 * VC-1 and WMV3 decoder common code
3 * Copyright (c) 2011 Mashiat Sarker Shakkhar
4 * Copyright (c) 2006-2007 Konstantin Shishkov
5 * Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, Michael Niedermayer
6 *
7 * This file is part of FFmpeg.
8 *
9 * FFmpeg is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * FFmpeg is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with FFmpeg; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 /**
25 * @file
26 * VC-1 and WMV3 decoder common code
27 */
28
29 #include "libavutil/mem.h"
30 #include "avcodec.h"
31 #include "decode.h"
32 #include "mpegvideo.h"
33 #include "vc1.h"
34 #include "vc1data.h"
35 #include "wmv2data.h"
36 #include "unary.h"
37
38 /***********************************************************************/
39 /**
40 * @name VC-1 Bitplane decoding
41 * @see 8.7, p56
42 * @{
43 */
44
45 /** Decode rows by checking if they are skipped
46 * @param plane Buffer to store decoded bits
47 * @param[in] width Width of this buffer
48 * @param[in] height Height of this buffer
49 * @param[in] stride of this buffer
50 */
51 193 static void decode_rowskip(uint8_t* plane, int width, int height, int stride,
52 GetBitContext *gb)
53 {
54 int x, y;
55
56
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 193 times.
769 for (y = 0; y < height; y++) {
57
2/2
✓ Branch 1 taken 277 times.
✓ Branch 2 taken 299 times.
576 if (!get_bits1(gb)) //rowskip
58 277 memset(plane, 0, width);
59 else
60
2/2
✓ Branch 0 taken 7316 times.
✓ Branch 1 taken 299 times.
7615 for (x = 0; x < width; x++)
61 7316 plane[x] = get_bits1(gb);
62 576 plane += stride;
63 }
64 193 }
65
66 /** Decode columns by checking if they are skipped
67 * @param plane Buffer to store decoded bits
68 * @param[in] width Width of this buffer
69 * @param[in] height Height of this buffer
70 * @param[in] stride of this buffer
71 * @todo FIXME: Optimize
72 */
73 121 static void decode_colskip(uint8_t* plane, int width, int height, int stride,
74 GetBitContext *gb)
75 {
76 int x, y;
77
78
2/2
✓ Branch 0 taken 788 times.
✓ Branch 1 taken 121 times.
909 for (x = 0; x < width; x++) {
79
2/2
✓ Branch 1 taken 263 times.
✓ Branch 2 taken 525 times.
788 if (!get_bits1(gb)) //colskip
80
2/2
✓ Branch 0 taken 8912 times.
✓ Branch 1 taken 263 times.
9175 for (y = 0; y < height; y++)
81 8912 plane[y*stride] = 0;
82 else
83
2/2
✓ Branch 0 taken 6776 times.
✓ Branch 1 taken 525 times.
7301 for (y = 0; y < height; y++)
84 6776 plane[y*stride] = get_bits1(gb);
85 788 plane ++;
86 }
87 121 }
88
89 /** Decode a bitplane's bits
90 * @param data bitplane where to store the decode bits
91 * @param[out] raw_flag pointer to the flag indicating that this bitplane is not coded explicitly
92 * @param v VC-1 context for bit reading and logging
93 * @return Status
94 * @todo FIXME: Optimize
95 */
96 1112 static int bitplane_decoding(uint8_t* data, int *raw_flag, VC1Context *v)
97 {
98 1112 GetBitContext *const gb = &v->gb;
99
100 int imode, x, y, code, offset;
101 1112 uint8_t invert, *planep = data;
102 int width, height, stride;
103
104 1112 width = v->s.mb_width;
105 1112 height = v->s.mb_height >> v->field_mode;
106 1112 stride = v->s.mb_stride;
107 1112 invert = get_bits1(gb);
108 1112 imode = get_vlc2(gb, ff_vc1_imode_vlc, VC1_IMODE_VLC_BITS, 1);
109
110 1112 *raw_flag = 0;
111
5/6
✓ Branch 0 taken 636 times.
✓ Branch 1 taken 167 times.
✓ Branch 2 taken 250 times.
✓ Branch 3 taken 33 times.
✓ Branch 4 taken 26 times.
✗ Branch 5 not taken.
1112 switch (imode) {
112 636 case IMODE_RAW:
113 //Data is actually read in the MB layer (same for all tests == "raw")
114 636 *raw_flag = 1; //invert ignored
115 636 return invert;
116 167 case IMODE_DIFF2:
117 case IMODE_NORM2:
118
2/2
✓ Branch 0 taken 114 times.
✓ Branch 1 taken 53 times.
167 if ((height * width) & 1) {
119 114 *planep++ = get_bits1(gb);
120 114 y = offset = 1;
121
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 114 times.
114 if (offset == width) {
122 offset = 0;
123 planep += stride - width;
124 }
125 }
126 else
127 53 y = offset = 0;
128 // decode bitplane as one long line
129
2/2
✓ Branch 0 taken 45906 times.
✓ Branch 1 taken 167 times.
46073 for (; y < height * width; y += 2) {
130 45906 code = get_vlc2(gb, ff_vc1_norm2_vlc, VC1_NORM2_VLC_BITS, 1);
131 45906 *planep++ = code & 1;
132 45906 offset++;
133
2/2
✓ Branch 0 taken 535 times.
✓ Branch 1 taken 45371 times.
45906 if (offset == width) {
134 535 offset = 0;
135 535 planep += stride - width;
136 }
137 45906 *planep++ = code >> 1;
138 45906 offset++;
139
2/2
✓ Branch 0 taken 1493 times.
✓ Branch 1 taken 44413 times.
45906 if (offset == width) {
140 1493 offset = 0;
141 1493 planep += stride - width;
142 }
143 }
144 167 break;
145 250 case IMODE_DIFF6:
146 case IMODE_NORM6:
147
4/4
✓ Branch 0 taken 92 times.
✓ Branch 1 taken 158 times.
✓ Branch 2 taken 19 times.
✓ Branch 3 taken 73 times.
250 if (!(height % 3) && (width % 3)) { // use 2x3 decoding
148
2/2
✓ Branch 0 taken 83 times.
✓ Branch 1 taken 19 times.
102 for (y = 0; y < height; y += 3) {
149
2/2
✓ Branch 0 taken 740 times.
✓ Branch 1 taken 83 times.
823 for (x = width & 1; x < width; x += 2) {
150 740 code = get_vlc2(gb, ff_vc1_norm6_vlc, VC1_NORM6_VLC_BITS, 2);
151
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 740 times.
740 if (code < 0) {
152 av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");
153 return -1;
154 }
155 740 planep[x + 0] = (code >> 0) & 1;
156 740 planep[x + 1] = (code >> 1) & 1;
157 740 planep[x + 0 + stride] = (code >> 2) & 1;
158 740 planep[x + 1 + stride] = (code >> 3) & 1;
159 740 planep[x + 0 + stride * 2] = (code >> 4) & 1;
160 740 planep[x + 1 + stride * 2] = (code >> 5) & 1;
161 }
162 83 planep += stride * 3;
163 }
164
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 13 times.
19 if (width & 1)
165 6 decode_colskip(data, 1, height, stride, &v->gb);
166 } else { // 3x2
167 231 planep += (height & 1) * stride;
168
2/2
✓ Branch 0 taken 2002 times.
✓ Branch 1 taken 231 times.
2233 for (y = height & 1; y < height; y += 2) {
169
2/2
✓ Branch 0 taken 32360 times.
✓ Branch 1 taken 2002 times.
34362 for (x = width % 3; x < width; x += 3) {
170 32360 code = get_vlc2(gb, ff_vc1_norm6_vlc, VC1_NORM6_VLC_BITS, 2);
171
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32360 times.
32360 if (code < 0) {
172 av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");
173 return -1;
174 }
175 32360 planep[x + 0] = (code >> 0) & 1;
176 32360 planep[x + 1] = (code >> 1) & 1;
177 32360 planep[x + 2] = (code >> 2) & 1;
178 32360 planep[x + 0 + stride] = (code >> 3) & 1;
179 32360 planep[x + 1 + stride] = (code >> 4) & 1;
180 32360 planep[x + 2 + stride] = (code >> 5) & 1;
181 }
182 2002 planep += stride * 2;
183 }
184 231 x = width % 3;
185
2/2
✓ Branch 0 taken 89 times.
✓ Branch 1 taken 142 times.
231 if (x)
186 89 decode_colskip(data, x, height, stride, &v->gb);
187
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 71 times.
231 if (height & 1)
188 160 decode_rowskip(data + x, width - x, 1, stride, &v->gb);
189 }
190 250 break;
191 33 case IMODE_ROWSKIP:
192 33 decode_rowskip(data, width, height, stride, &v->gb);
193 33 break;
194 26 case IMODE_COLSKIP:
195 26 decode_colskip(data, width, height, stride, &v->gb);
196 26 break;
197 default:
198 break;
199 }
200
201 /* Applying diff operator */
202
4/4
✓ Branch 0 taken 410 times.
✓ Branch 1 taken 66 times.
✓ Branch 2 taken 56 times.
✓ Branch 3 taken 354 times.
476 if (imode == IMODE_DIFF2 || imode == IMODE_DIFF6) {
203 122 planep = data;
204 122 planep[0] ^= invert;
205
2/2
✓ Branch 0 taken 3651 times.
✓ Branch 1 taken 122 times.
3773 for (x = 1; x < width; x++)
206 3651 planep[x] ^= planep[x-1];
207
2/2
✓ Branch 0 taken 1815 times.
✓ Branch 1 taken 122 times.
1937 for (y = 1; y < height; y++) {
208 1815 planep += stride;
209 1815 planep[0] ^= planep[-stride];
210
2/2
✓ Branch 0 taken 95104 times.
✓ Branch 1 taken 1815 times.
96919 for (x = 1; x < width; x++) {
211
2/2
✓ Branch 0 taken 26817 times.
✓ Branch 1 taken 68287 times.
95104 if (planep[x-1] != planep[x-stride]) planep[x] ^= invert;
212 68287 else planep[x] ^= planep[x-1];
213 }
214 }
215
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 308 times.
354 } else if (invert) {
216 46 planep = data;
217
2/2
✓ Branch 0 taken 14890 times.
✓ Branch 1 taken 46 times.
14936 for (x = 0; x < stride * height; x++)
218 14890 planep[x] = !planep[x]; //FIXME stride
219 }
220 476 return (imode << 1) + invert;
221 }
222
223 /** @} */ //Bitplane group
224
225 /***********************************************************************/
226 /** VOP Dquant decoding
227 * @param v VC-1 Context
228 */
229 148 static int vop_dquant_decoding(VC1Context *v)
230 {
231 148 GetBitContext *const gb = &v->gb;
232 int pqdiff;
233
234 //variable size
235
1/2
✓ Branch 0 taken 148 times.
✗ Branch 1 not taken.
148 if (v->dquant != 2) {
236 148 v->dquantfrm = get_bits1(gb);
237
2/2
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 83 times.
148 if (!v->dquantfrm)
238 65 return 0;
239
240 83 v->dqprofile = get_bits(gb, 2);
241
3/3
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 1 times.
83 switch (v->dqprofile) {
242 62 case DQPROFILE_SINGLE_EDGE:
243 case DQPROFILE_DOUBLE_EDGES:
244 62 v->dqsbedge = get_bits(gb, 2);
245 62 break;
246 20 case DQPROFILE_ALL_MBS:
247 20 v->dqbilevel = get_bits1(gb);
248
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 18 times.
20 if (!v->dqbilevel) {
249 2 v->halfpq = 0;
250 2 return 0;
251 }
252 18 break;
253 1 default:
254 1 break; //Forbidden ?
255 }
256 }
257
258 81 pqdiff = get_bits(gb, 3);
259
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 63 times.
81 if (pqdiff == 7)
260 18 v->altpq = get_bits(gb, 5);
261 else
262 63 v->altpq = v->pq + pqdiff + 1;
263
264 81 return 0;
265 }
266
267 static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb);
268
269 /**
270 * Decode Simple/Main Profiles sequence header
271 * @see Figure 7-8, p16-17
272 * @param avctx Codec context
273 * @param gb GetBit context initialized from Codec context extra_data
274 * @return Status
275 */
276 33 int ff_vc1_decode_sequence_header(AVCodecContext *avctx, VC1Context *v, GetBitContext *gb)
277 {
278 33 av_log(avctx, AV_LOG_DEBUG, "Header: %0X\n", show_bits_long(gb, 32));
279 33 v->profile = get_bits(gb, 2);
280
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
33 if (v->profile == PROFILE_COMPLEX) {
281 av_log(avctx, AV_LOG_WARNING, "WMV3 Complex Profile is not fully supported\n");
282 }
283
284
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 7 times.
33 if (v->profile == PROFILE_ADVANCED) {
285 26 v->zz_8x4 = ff_vc1_adv_progressive_8x4_zz;
286 26 v->zz_4x8 = ff_vc1_adv_progressive_4x8_zz;
287 26 return decode_sequence_header_adv(v, gb);
288 } else {
289 7 v->chromaformat = 1;
290 7 v->zz_8x4 = ff_wmv2_scantableA;
291 7 v->zz_4x8 = ff_wmv2_scantableB;
292 7 v->res_y411 = get_bits1(gb);
293 7 v->res_sprite = get_bits1(gb);
294
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if (v->res_y411) {
295 av_log(avctx, AV_LOG_ERROR,
296 "Old interlaced mode is not supported\n");
297 return -1;
298 }
299 }
300
301 // (fps-2)/4 (->30)
302 7 v->frmrtq_postproc = get_bits(gb, 3); //common
303 // (bitrate-32kbps)/64kbps
304 7 v->bitrtq_postproc = get_bits(gb, 5); //common
305 7 v->loop_filter = get_bits1(gb); //common
306
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
7 if (v->loop_filter == 1 && v->profile == PROFILE_SIMPLE) {
307 av_log(avctx, AV_LOG_ERROR,
308 "LOOPFILTER shall not be enabled in Simple Profile\n");
309 }
310
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if (v->s.avctx->skip_loop_filter >= AVDISCARD_ALL)
311 v->loop_filter = 0;
312
313 7 v->res_x8 = get_bits1(gb); //reserved
314 7 v->multires = get_bits1(gb);
315 7 v->res_fasttx = get_bits1(gb);
316
317 7 v->fastuvmc = get_bits1(gb); //common
318
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
7 if (!v->profile && !v->fastuvmc) {
319 av_log(avctx, AV_LOG_ERROR,
320 "FASTUVMC unavailable in Simple Profile\n");
321 return -1;
322 }
323 7 v->extended_mv = get_bits1(gb); //common
324
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
7 if (!v->profile && v->extended_mv) {
325 av_log(avctx, AV_LOG_ERROR,
326 "Extended MVs unavailable in Simple Profile\n");
327 return -1;
328 }
329 7 v->dquant = get_bits(gb, 2); //common
330 7 v->vstransform = get_bits1(gb); //common
331
332 7 v->res_transtab = get_bits1(gb);
333
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if (v->res_transtab) {
334 av_log(avctx, AV_LOG_ERROR,
335 "1 for reserved RES_TRANSTAB is forbidden\n");
336 return -1;
337 }
338
339 7 v->overlap = get_bits1(gb); //common
340
341 7 v->resync_marker = get_bits1(gb);
342 7 v->rangered = get_bits1(gb);
343
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
7 if (v->rangered && v->profile == PROFILE_SIMPLE) {
344 av_log(avctx, AV_LOG_INFO,
345 "RANGERED should be set to 0 in Simple Profile\n");
346 }
347
348 7 v->max_b_frames = avctx->max_b_frames = get_bits(gb, 3); //common
349 7 v->quantizer_mode = get_bits(gb, 2); //common
350
351 7 v->finterpflag = get_bits1(gb); //common
352
353
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if (v->res_sprite) {
354 int w = get_bits(gb, 11);
355 int h = get_bits(gb, 11);
356 int ret = ff_set_dimensions(v->s.avctx, w, h);
357 if (ret < 0) {
358 av_log(avctx, AV_LOG_ERROR, "Failed to set dimensions %d %d\n", w, h);
359 return ret;
360 }
361 skip_bits(gb, 5); //frame rate
362 v->res_x8 = get_bits1(gb);
363 if (get_bits1(gb)) { // something to do with DC VLC selection
364 av_log(avctx, AV_LOG_ERROR, "Unsupported sprite feature\n");
365 return -1;
366 }
367 skip_bits(gb, 3); //slice code
368 v->res_rtm_flag = 0;
369 } else {
370 7 v->res_rtm_flag = get_bits1(gb); //reserved
371 }
372 //TODO: figure out what they mean (always 0x402F)
373
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if (!v->res_fasttx)
374 skip_bits(gb, 16);
375 7 av_log(avctx, AV_LOG_DEBUG,
376 "Profile %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n"
377 "LoopFilter=%i, MultiRes=%i, FastUVMC=%i, Extended MV=%i\n"
378 "Rangered=%i, VSTransform=%i, Overlap=%i, SyncMarker=%i\n"
379 "DQuant=%i, Quantizer mode=%i, Max B-frames=%i\n",
380 v->profile, v->frmrtq_postproc, v->bitrtq_postproc,
381 v->loop_filter, v->multires, v->fastuvmc, v->extended_mv,
382 v->rangered, v->vstransform, v->overlap, v->resync_marker,
383 v->dquant, v->quantizer_mode, avctx->max_b_frames);
384 7 return 0;
385 }
386
387 26 static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb)
388 {
389 26 v->res_rtm_flag = 1;
390 26 v->level = get_bits(gb, 3);
391
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
26 if (v->level >= 5) {
392 av_log(v->s.avctx, AV_LOG_ERROR, "Reserved LEVEL %i\n",v->level);
393 }
394 26 v->chromaformat = get_bits(gb, 2);
395
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
26 if (v->chromaformat != 1) {
396 av_log(v->s.avctx, AV_LOG_ERROR,
397 "Only 4:2:0 chroma format supported\n");
398 return -1;
399 }
400
401 // (fps-2)/4 (->30)
402 26 v->frmrtq_postproc = get_bits(gb, 3); //common
403 // (bitrate-32kbps)/64kbps
404 26 v->bitrtq_postproc = get_bits(gb, 5); //common
405 26 v->postprocflag = get_bits1(gb); //common
406
407 26 v->max_coded_width = (get_bits(gb, 12) + 1) << 1;
408 26 v->max_coded_height = (get_bits(gb, 12) + 1) << 1;
409 26 v->broadcast = get_bits1(gb);
410 26 v->interlace = get_bits1(gb);
411 26 v->tfcntrflag = get_bits1(gb);
412 26 v->finterpflag = get_bits1(gb);
413 26 skip_bits1(gb); // reserved
414
415 26 av_log(v->s.avctx, AV_LOG_DEBUG,
416 "Advanced Profile level %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n"
417 "LoopFilter=%i, ChromaFormat=%i, Pulldown=%i, Interlace: %i\n"
418 "TFCTRflag=%i, FINTERPflag=%i\n",
419 v->level, v->frmrtq_postproc, v->bitrtq_postproc,
420 v->loop_filter, v->chromaformat, v->broadcast, v->interlace,
421 v->tfcntrflag, v->finterpflag);
422
423 26 v->psf = get_bits1(gb);
424
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
26 if (v->psf) { //PsF, 6.1.13
425 av_log(v->s.avctx, AV_LOG_ERROR, "Progressive Segmented Frame mode: not supported (yet)\n");
426 return -1;
427 }
428 26 v->max_b_frames = v->s.avctx->max_b_frames = 7;
429
1/2
✓ Branch 1 taken 26 times.
✗ Branch 2 not taken.
26 if (get_bits1(gb)) { //Display Info - decoding is not affected by it
430 26 int w, h, ar = 0;
431 26 av_log(v->s.avctx, AV_LOG_DEBUG, "Display extended info:\n");
432 26 w = get_bits(gb, 14) + 1;
433 26 h = get_bits(gb, 14) + 1;
434 26 av_log(v->s.avctx, AV_LOG_DEBUG, "Display dimensions: %ix%i\n", w, h);
435
2/2
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 15 times.
26 if (get_bits1(gb))
436 11 ar = get_bits(gb, 4);
437
4/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 8 times.
26 if (ar && ar < 14) {
438 3 v->s.avctx->sample_aspect_ratio = ff_vc1_pixel_aspect[ar];
439
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 15 times.
23 } else if (ar == 15) {
440 8 w = get_bits(gb, 8) + 1;
441 8 h = get_bits(gb, 8) + 1;
442 8 v->s.avctx->sample_aspect_ratio = (AVRational){w, h};
443 } else {
444
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
15 if (v->s.avctx->width > v->max_coded_width ||
445
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 v->s.avctx->height > v->max_coded_height) {
446 avpriv_request_sample(v->s.avctx, "Huge resolution");
447 } else
448 15 av_reduce(&v->s.avctx->sample_aspect_ratio.num,
449 15 &v->s.avctx->sample_aspect_ratio.den,
450 15 v->s.avctx->height * w,
451 15 v->s.avctx->width * h,
452 1 << 30);
453 }
454 26 ff_set_sar(v->s.avctx, v->s.avctx->sample_aspect_ratio);
455 26 av_log(v->s.avctx, AV_LOG_DEBUG, "Aspect: %i:%i\n",
456 26 v->s.avctx->sample_aspect_ratio.num,
457 26 v->s.avctx->sample_aspect_ratio.den);
458
459
2/2
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 15 times.
26 if (get_bits1(gb)) { //framerate stuff
460
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
11 if (get_bits1(gb)) {
461 v->s.avctx->framerate.den = 32;
462 v->s.avctx->framerate.num = get_bits(gb, 16) + 1;
463 } else {
464 int nr, dr;
465 11 nr = get_bits(gb, 8);
466 11 dr = get_bits(gb, 4);
467
4/8
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11 times.
✗ Branch 7 not taken.
11 if (nr > 0 && nr < 8 && dr > 0 && dr < 3) {
468 11 v->s.avctx->framerate.den = ff_vc1_fps_dr[dr - 1];
469 11 v->s.avctx->framerate.num = ff_vc1_fps_nr[nr - 1] * 1000;
470 }
471 }
472 }
473
474
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 26 times.
26 if (get_bits1(gb)) {
475 v->color_prim = get_bits(gb, 8);
476 v->transfer_char = get_bits(gb, 8);
477 v->matrix_coef = get_bits(gb, 8);
478 }
479 }
480
481 26 v->hrd_param_flag = get_bits1(gb);
482
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 8 times.
26 if (v->hrd_param_flag) {
483 int i;
484 18 v->hrd_num_leaky_buckets = get_bits(gb, 5);
485 18 skip_bits(gb, 4); //bitrate exponent
486 18 skip_bits(gb, 4); //buffer size exponent
487
2/2
✓ Branch 0 taken 258 times.
✓ Branch 1 taken 18 times.
276 for (i = 0; i < v->hrd_num_leaky_buckets; i++) {
488 258 skip_bits(gb, 16); //hrd_rate[n]
489 258 skip_bits(gb, 16); //hrd_buffer[n]
490 }
491 }
492 26 return 0;
493 }
494
495 67 int ff_vc1_decode_entry_point(AVCodecContext *avctx, VC1Context *v, GetBitContext *gb)
496 {
497 int i;
498 int w,h;
499 int ret;
500
501 67 av_log(avctx, AV_LOG_DEBUG, "Entry point: %08X\n", show_bits_long(gb, 32));
502 67 v->broken_link = get_bits1(gb);
503 67 v->closed_entry = get_bits1(gb);
504 67 v->panscanflag = get_bits1(gb);
505 67 v->refdist_flag = get_bits1(gb);
506 67 v->loop_filter = get_bits1(gb);
507
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
67 if (v->s.avctx->skip_loop_filter >= AVDISCARD_ALL)
508 v->loop_filter = 0;
509 67 v->fastuvmc = get_bits1(gb);
510 67 v->extended_mv = get_bits1(gb);
511 67 v->dquant = get_bits(gb, 2);
512 67 v->vstransform = get_bits1(gb);
513 67 v->overlap = get_bits1(gb);
514 67 v->quantizer_mode = get_bits(gb, 2);
515
516
2/2
✓ Branch 0 taken 55 times.
✓ Branch 1 taken 12 times.
67 if (v->hrd_param_flag) {
517
2/2
✓ Branch 0 taken 855 times.
✓ Branch 1 taken 55 times.
910 for (i = 0; i < v->hrd_num_leaky_buckets; i++) {
518 855 skip_bits(gb, 8); //hrd_full[n]
519 }
520 }
521
522
2/2
✓ Branch 1 taken 50 times.
✓ Branch 2 taken 17 times.
67 if(get_bits1(gb)){
523 50 w = (get_bits(gb, 12)+1)<<1;
524 50 h = (get_bits(gb, 12)+1)<<1;
525 } else {
526 17 w = v->max_coded_width;
527 17 h = v->max_coded_height;
528 }
529
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 67 times.
67 if ((ret = ff_set_dimensions(avctx, w, h)) < 0) {
530 av_log(avctx, AV_LOG_ERROR, "Failed to set dimensions %d %d\n", w, h);
531 return ret;
532 }
533
534
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 50 times.
67 if (v->extended_mv)
535 17 v->extended_dmv = get_bits1(gb);
536
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 67 times.
67 if ((v->range_mapy_flag = get_bits1(gb))) {
537 av_log(avctx, AV_LOG_ERROR, "Luma scaling is not supported, expect wrong picture\n");
538 v->range_mapy = get_bits(gb, 3);
539 }
540
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 67 times.
67 if ((v->range_mapuv_flag = get_bits1(gb))) {
541 av_log(avctx, AV_LOG_ERROR, "Chroma scaling is not supported, expect wrong picture\n");
542 v->range_mapuv = get_bits(gb, 3);
543 }
544
545 67 av_log(avctx, AV_LOG_DEBUG, "Entry point info:\n"
546 "BrokenLink=%i, ClosedEntry=%i, PanscanFlag=%i\n"
547 "RefDist=%i, Postproc=%i, FastUVMC=%i, ExtMV=%i\n"
548 "DQuant=%i, VSTransform=%i, Overlap=%i, Qmode=%i\n",
549 67 v->broken_link, v->closed_entry, v->panscanflag, v->refdist_flag, v->loop_filter,
550 v->fastuvmc, v->extended_mv, v->dquant, v->vstransform, v->overlap, v->quantizer_mode);
551
552 67 return 0;
553 }
554
555 17 int ff_vc1_decode_extradata(AVCodecContext *avctx, VC1Context *v,
556 int *seq_initialized, int *ep_initialized)
557 {
558 17 const uint8_t *start = avctx->extradata;
559 17 const uint8_t *end = avctx->extradata + avctx->extradata_size;
560 const uint8_t *next;
561 uint8_t *buf2;
562 GetBitContext gb;
563 17 int ret = 0;
564
565 17 *seq_initialized = 0;
566 17 *ep_initialized = 0;
567
568 17 buf2 = av_mallocz(avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
569
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if (!buf2)
570 return AVERROR(ENOMEM);
571
572 17 start = find_next_marker(start, end); // in WVC1 extradata first byte is its size, but can be 0 in mkv
573 17 next = start;
574
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 17 times.
61 for (; next < end; start = next) {
575 int size, buf2_size;
576
577 44 next = find_next_marker(start + 4, end);
578 44 size = next - start - 4;
579
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
44 if (size <= 0)
580 continue;
581 44 buf2_size = v->vc1dsp.vc1_unescape_buffer(start + 4, size, buf2);
582 44 ret = init_get_bits8(&gb, buf2, buf2_size);
583
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
44 if (ret < 0)
584 break;
585
2/3
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 27 times.
✗ Branch 2 not taken.
44 switch (AV_RB32(start)) {
586 17 case VC1_CODE_SEQHDR:
587
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
17 if ((ret = ff_vc1_decode_sequence_header(avctx, v, &gb)) < 0)
588 goto end;
589 17 *seq_initialized = 1;
590 17 break;
591 27 case VC1_CODE_ENTRYPOINT:
592
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 27 times.
27 if ((ret = ff_vc1_decode_entry_point(avctx, v, &gb)) < 0)
593 goto end;
594 27 *ep_initialized = 1;
595 27 break;
596 }
597 }
598
599 17 end:
600 17 av_free(buf2);
601 17 return ret;
602 }
603
604 /* fill lookup tables for intensity compensation */
605 #define INIT_LUT(lumscale, lumshift, luty, lutuv, chain) do { \
606 int scale, shift, i; \
607 if (!lumscale) { \
608 scale = -64; \
609 shift = (255 - lumshift * 2) * 64; \
610 if (lumshift > 31) \
611 shift += 128 << 6; \
612 } else { \
613 scale = lumscale + 32; \
614 if (lumshift > 31) \
615 shift = (lumshift - 64) * 64; \
616 else \
617 shift = lumshift << 6; \
618 } \
619 for (i = 0; i < 256; i++) { \
620 int iy = chain ? luty[i] : i; \
621 int iu = chain ? lutuv[i] : i; \
622 luty[i] = av_clip_uint8((scale * iy + shift + 32) >> 6); \
623 lutuv[i] = av_clip_uint8((scale * (iu - 128) + 128*64 + 32) >> 6);\
624 } \
625 } while(0)
626
627 422 static void rotate_luts(VC1Context *v)
628 {
629
3/4
✓ Branch 0 taken 422 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 91 times.
✓ Branch 3 taken 331 times.
422 if (v->s.pict_type == AV_PICTURE_TYPE_BI || v->s.pict_type == AV_PICTURE_TYPE_B) {
630 91 v->curr_use_ic = &v->aux_use_ic;
631 91 v->curr_luty = v->aux_luty;
632 91 v->curr_lutuv = v->aux_lutuv;
633 } else {
634 #define ROTATE(DEF, L, N, C) do { \
635 DEF; \
636 memcpy(&tmp, L , sizeof(tmp)); \
637 memcpy(L , N , sizeof(tmp)); \
638 memcpy(N , &tmp, sizeof(tmp)); \
639 C = N; \
640 } while(0)
641
642 331 ROTATE(int tmp, &v->last_use_ic, &v->next_use_ic, v->curr_use_ic);
643 331 ROTATE(uint8_t tmp[2][256], v->last_luty, v->next_luty, v->curr_luty);
644 331 ROTATE(uint8_t tmp[2][256], v->last_lutuv, v->next_lutuv, v->curr_lutuv);
645 }
646
647
2/2
✓ Branch 0 taken 108032 times.
✓ Branch 1 taken 422 times.
108454 INIT_LUT(32, 0, v->curr_luty[0], v->curr_lutuv[0], 0);
648
2/2
✓ Branch 0 taken 108032 times.
✓ Branch 1 taken 422 times.
108454 INIT_LUT(32, 0, v->curr_luty[1], v->curr_lutuv[1], 0);
649 422 *v->curr_use_ic = 0;
650 422 }
651
652 167 static int read_bfraction(VC1Context *v, GetBitContext* gb) {
653 167 int bfraction_lut_index = get_bits(gb, 3);
654
655
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 167 times.
167 if (bfraction_lut_index == 7)
656 bfraction_lut_index = 7 + get_bits(gb, 4);
657
658
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 167 times.
167 if (bfraction_lut_index == 21) {
659 av_log(v->s.avctx, AV_LOG_ERROR, "bfraction invalid\n");
660 return AVERROR_INVALIDDATA;
661 }
662 167 v->bfraction_lut_index = bfraction_lut_index;
663 167 v->bfraction = ff_vc1_bfraction_lut[v->bfraction_lut_index];
664 167 return 0;
665 }
666
667 266 int ff_vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)
668 {
669 int pqindex, lowquant, status;
670
671 266 v->field_mode = 0;
672 266 v->fcm = PROGRESSIVE;
673
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 266 times.
266 if (v->finterpflag)
674 v->interpfrm = get_bits1(gb);
675
2/2
✓ Branch 0 taken 83 times.
✓ Branch 1 taken 183 times.
266 if (v->s.avctx->codec_id == AV_CODEC_ID_MSS2)
676 83 v->respic =
677 83 v->rangered =
678 83 v->multires = get_bits(gb, 2) == 1;
679 else
680 183 skip_bits(gb, 2); //framecnt unused
681 266 v->rangeredfrm = 0;
682
2/2
✓ Branch 0 taken 55 times.
✓ Branch 1 taken 211 times.
266 if (v->rangered)
683 55 v->rangeredfrm = get_bits1(gb);
684
2/2
✓ Branch 1 taken 164 times.
✓ Branch 2 taken 102 times.
266 if (get_bits1(gb)) {
685 164 v->s.pict_type = AV_PICTURE_TYPE_P;
686 } else {
687
4/4
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 89 times.
✓ Branch 3 taken 11 times.
✓ Branch 4 taken 2 times.
102 if (v->s.avctx->max_b_frames && !get_bits1(gb)) {
688 11 v->s.pict_type = AV_PICTURE_TYPE_B;
689 } else
690 91 v->s.pict_type = AV_PICTURE_TYPE_I;
691 }
692
693 266 v->bi_type = 0;
694
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 255 times.
266 if (v->s.pict_type == AV_PICTURE_TYPE_B) {
695
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
11 if (read_bfraction(v, gb) < 0)
696 return AVERROR_INVALIDDATA;
697
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (v->bfraction == 0) {
698 v->s.pict_type = AV_PICTURE_TYPE_BI;
699 }
700 }
701
3/4
✓ Branch 0 taken 175 times.
✓ Branch 1 taken 91 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 175 times.
266 if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)
702 91 skip_bits(gb, 7); // skip buffer fullness
703
704
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 266 times.
266 if (v->parse_only)
705 return 0;
706
707 /* calculate RND */
708
3/4
✓ Branch 0 taken 175 times.
✓ Branch 1 taken 91 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 175 times.
266 if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)
709 91 v->rnd = 1;
710
2/2
✓ Branch 0 taken 164 times.
✓ Branch 1 taken 102 times.
266 if (v->s.pict_type == AV_PICTURE_TYPE_P)
711 164 v->rnd ^= 1;
712
713
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 266 times.
266 if (get_bits_left(gb) < 5)
714 return AVERROR_INVALIDDATA;
715 /* Quantizer stuff */
716 266 pqindex = get_bits(gb, 5);
717
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 266 times.
266 if (!pqindex)
718 return -1;
719
1/2
✓ Branch 0 taken 266 times.
✗ Branch 1 not taken.
266 if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
720 266 v->pq = ff_vc1_pquant_table[0][pqindex];
721 else
722 v->pq = ff_vc1_pquant_table[1][pqindex];
723 266 v->pqindex = pqindex;
724
2/2
✓ Branch 0 taken 172 times.
✓ Branch 1 taken 94 times.
266 if (pqindex < 9)
725 172 v->halfpq = get_bits1(gb);
726 else
727 94 v->halfpq = 0;
728
1/4
✓ Branch 0 taken 266 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
266 switch (v->quantizer_mode) {
729 266 case QUANT_FRAME_IMPLICIT:
730 266 v->pquantizer = pqindex < 9;
731 266 break;
732 case QUANT_NON_UNIFORM:
733 v->pquantizer = 0;
734 break;
735 case QUANT_FRAME_EXPLICIT:
736 v->pquantizer = get_bits1(gb);
737 break;
738 default:
739 v->pquantizer = 1;
740 break;
741 }
742 266 v->dquantfrm = 0;
743
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 266 times.
266 if (v->extended_mv == 1)
744 v->mvrange = get_unary(gb, 0, 3);
745 266 v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
746 266 v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
747 266 v->range_x = 1 << (v->k_x - 1);
748 266 v->range_y = 1 << (v->k_y - 1);
749
3/4
✓ Branch 0 taken 81 times.
✓ Branch 1 taken 185 times.
✓ Branch 2 taken 81 times.
✗ Branch 3 not taken.
266 if (v->multires && v->s.pict_type != AV_PICTURE_TYPE_B)
750 81 v->respic = get_bits(gb, 2);
751
752
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 266 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
266 if (v->res_x8 && (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)) {
753 v->x8_type = get_bits1(gb);
754 } else
755 266 v->x8_type = 0;
756 ff_dlog(v->s.avctx, "%c Frame: QP=[%i]%i (+%i/2) %i\n",
757 (v->s.pict_type == AV_PICTURE_TYPE_P) ? 'P' : ((v->s.pict_type == AV_PICTURE_TYPE_I) ? 'I' : 'B'),
758 pqindex, v->pq, v->halfpq, v->rangeredfrm);
759
760
2/2
✓ Branch 0 taken 183 times.
✓ Branch 1 taken 83 times.
266 if (v->first_pic_header_flag)
761 183 rotate_luts(v);
762
763
3/3
✓ Branch 0 taken 164 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 91 times.
266 switch (v->s.pict_type) {
764 164 case AV_PICTURE_TYPE_P:
765 164 v->tt_index = (v->pq > 4) + (v->pq > 12);
766
767 164 lowquant = (v->pq > 12) ? 0 : 1;
768 164 v->mv_mode = ff_vc1_mv_pmode_table[lowquant][get_unary(gb, 1, 4)];
769
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 143 times.
164 if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
770 21 v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][get_unary(gb, 1, 3)];
771 21 v->lumscale = get_bits(gb, 6);
772 21 v->lumshift = get_bits(gb, 6);
773 21 v->last_use_ic = 1;
774 /* fill lookup tables for intensity compensation */
775
5/8
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 13 times.
✓ Branch 6 taken 5376 times.
✓ Branch 7 taken 21 times.
5397 INIT_LUT(v->lumscale, v->lumshift, v->last_luty[0], v->last_lutuv[0], 1);
776
5/8
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 13 times.
✓ Branch 6 taken 5376 times.
✓ Branch 7 taken 21 times.
5397 INIT_LUT(v->lumscale, v->lumshift, v->last_luty[1], v->last_lutuv[1], 1);
777 }
778
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 143 times.
164 if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
779
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 3 times.
39 v->s.quarter_sample = (v->mv_mode2 != MV_PMODE_1MV_HPEL &&
780
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 3 times.
18 v->mv_mode2 != MV_PMODE_1MV_HPEL_BILIN);
781 21 v->s.mspel = (v->mv_mode2 != MV_PMODE_1MV_HPEL_BILIN);
782 } else {
783
2/2
✓ Branch 0 taken 138 times.
✓ Branch 1 taken 5 times.
281 v->s.quarter_sample = (v->mv_mode != MV_PMODE_1MV_HPEL &&
784
2/2
✓ Branch 0 taken 114 times.
✓ Branch 1 taken 24 times.
138 v->mv_mode != MV_PMODE_1MV_HPEL_BILIN);
785 143 v->s.mspel = (v->mv_mode != MV_PMODE_1MV_HPEL_BILIN);
786 }
787
788
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 143 times.
164 if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
789
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 v->mv_mode2 == MV_PMODE_MIXED_MV) ||
790
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 152 times.
164 v->mv_mode == MV_PMODE_MIXED_MV) {
791 12 status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v);
792
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (status < 0)
793 return -1;
794 12 av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
795 "Imode: %i, Invert: %i\n", status>>1, status&1);
796 } else {
797 152 v->mv_type_is_raw = 0;
798 152 memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height);
799 }
800 164 status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
801
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 164 times.
164 if (status < 0)
802 return -1;
803 164 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
804 "Imode: %i, Invert: %i\n", status>>1, status&1);
805
806
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 164 times.
164 if (get_bits_left(gb) < 4)
807 return AVERROR_INVALIDDATA;
808
809 /* Hopefully this is correct for P-frames */
810 164 v->mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables
811 164 v->cbptab = get_bits(gb, 2);
812 164 v->cbpcy_vlc = ff_vc1_cbpcy_p_vlc[v->cbptab];
813
814
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 36 times.
164 if (v->dquant) {
815 128 av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
816 128 vop_dquant_decoding(v);
817 }
818
819
2/2
✓ Branch 0 taken 140 times.
✓ Branch 1 taken 24 times.
164 if (v->vstransform) {
820 140 v->ttmbf = get_bits1(gb);
821
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 134 times.
140 if (v->ttmbf) {
822 6 v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
823 } else
824 134 v->ttfrm = 0; //FIXME Is that so ?
825 } else {
826 24 v->ttmbf = 1;
827 24 v->ttfrm = TT_8X8;
828 }
829 164 break;
830 11 case AV_PICTURE_TYPE_B:
831 11 v->tt_index = (v->pq > 4) + (v->pq > 12);
832
833 11 v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;
834 11 v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV);
835 11 v->s.mspel = v->s.quarter_sample;
836
837 11 status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);
838
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (status < 0)
839 return -1;
840 11 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "
841 "Imode: %i, Invert: %i\n", status>>1, status&1);
842 11 status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
843
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (status < 0)
844 return -1;
845 11 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
846 "Imode: %i, Invert: %i\n", status>>1, status&1);
847
848 11 v->mv_table_index = get_bits(gb, 2);
849 11 v->cbptab = get_bits(gb, 2);
850 11 v->cbpcy_vlc = ff_vc1_cbpcy_p_vlc[v->cbptab];
851
852
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (v->dquant) {
853 av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
854 vop_dquant_decoding(v);
855 }
856
857
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (v->vstransform) {
858 11 v->ttmbf = get_bits1(gb);
859
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (v->ttmbf) {
860 v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
861 } else
862 11 v->ttfrm = 0;
863 } else {
864 v->ttmbf = 1;
865 v->ttfrm = TT_8X8;
866 }
867 11 break;
868 }
869
870
1/2
✓ Branch 0 taken 266 times.
✗ Branch 1 not taken.
266 if (!v->x8_type) {
871 /* AC Syntax */
872 266 v->c_ac_table_index = decode012(gb);
873
3/4
✓ Branch 0 taken 175 times.
✓ Branch 1 taken 91 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 175 times.
266 if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI) {
874 91 v->y_ac_table_index = decode012(gb);
875 }
876 /* DC Syntax */
877 266 v->dc_table_index = get_bits1(gb);
878 }
879
880
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 266 times.
266 if (v->s.pict_type == AV_PICTURE_TYPE_BI) {
881 v->s.pict_type = AV_PICTURE_TYPE_B;
882 v->bi_type = 1;
883 }
884 266 return 0;
885 }
886
887 921 int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
888 {
889 int pqindex, lowquant;
890 int status;
891 int field_mode, fcm;
892
893 921 v->numref = 0;
894 921 v->p_frame_skipped = 0;
895
2/2
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 884 times.
921 if (v->second_field) {
896
2/4
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 37 times.
37 if (v->fcm != ILACE_FIELD || v->field_mode!=1)
897 return -1;
898
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 19 times.
37 if (v->fptype & 4)
899
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 v->s.pict_type = (v->fptype & 1) ? AV_PICTURE_TYPE_BI : AV_PICTURE_TYPE_B;
900 else
901
1/2
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
19 v->s.pict_type = (v->fptype & 1) ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
902 37 v->s.cur_pic.ptr->f->pict_type = v->s.pict_type;
903
1/2
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
37 if (!v->pic_header_flag)
904 37 goto parse_common_info;
905 }
906
907 884 field_mode = 0;
908
2/2
✓ Branch 0 taken 89 times.
✓ Branch 1 taken 795 times.
884 if (v->interlace) {
909 89 fcm = decode012(gb);
910
1/2
✓ Branch 0 taken 89 times.
✗ Branch 1 not taken.
89 if (fcm) {
911
2/2
✓ Branch 0 taken 73 times.
✓ Branch 1 taken 16 times.
89 if (fcm == ILACE_FIELD)
912 73 field_mode = 1;
913 }
914 } else {
915 795 fcm = PROGRESSIVE;
916 }
917
3/4
✓ Branch 0 taken 273 times.
✓ Branch 1 taken 611 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 273 times.
884 if (!v->first_pic_header_flag && v->field_mode != field_mode)
918 return AVERROR_INVALIDDATA;
919 884 v->field_mode = field_mode;
920 884 v->fcm = fcm;
921
922
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 884 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
884 av_assert0( v->s.mb_height == v->s.height + 15 >> 4
923 || v->s.mb_height == FFALIGN(v->s.height + 15 >> 4, 2));
924
2/2
✓ Branch 0 taken 73 times.
✓ Branch 1 taken 811 times.
884 if (v->field_mode) {
925 73 v->s.mb_height = FFALIGN(v->s.height + 15 >> 4, 2);
926 73 v->fptype = get_bits(gb, 3);
927
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 37 times.
73 if (v->fptype & 4) // B-picture
928
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 v->s.pict_type = (v->fptype & 2) ? AV_PICTURE_TYPE_BI : AV_PICTURE_TYPE_B;
929 else
930
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 3 times.
37 v->s.pict_type = (v->fptype & 2) ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
931 } else {
932 811 v->s.mb_height = v->s.height + 15 >> 4;
933
4/6
✓ Branch 1 taken 524 times.
✓ Branch 2 taken 125 times.
✓ Branch 3 taken 26 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 136 times.
✗ Branch 6 not taken.
811 switch (get_unary(gb, 0, 4)) {
934 524 case 0:
935 524 v->s.pict_type = AV_PICTURE_TYPE_P;
936 524 break;
937 125 case 1:
938 125 v->s.pict_type = AV_PICTURE_TYPE_B;
939 125 break;
940 26 case 2:
941 26 v->s.pict_type = AV_PICTURE_TYPE_I;
942 26 break;
943 case 3:
944 v->s.pict_type = AV_PICTURE_TYPE_BI;
945 break;
946 136 case 4:
947 136 v->s.pict_type = AV_PICTURE_TYPE_P; // skipped pic
948 136 v->p_frame_skipped = 1;
949 136 break;
950 }
951 }
952
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 884 times.
884 if (v->tfcntrflag)
953 skip_bits(gb, 8);
954
1/2
✓ Branch 0 taken 884 times.
✗ Branch 1 not taken.
884 if (v->broadcast) {
955
3/4
✓ Branch 0 taken 89 times.
✓ Branch 1 taken 795 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 89 times.
884 if (!v->interlace || v->psf) {
956 795 v->rptfrm = get_bits(gb, 2);
957 } else {
958 89 v->tff = get_bits1(gb);
959 89 v->rff = get_bits1(gb);
960 }
961 } else {
962 v->tff = 1;
963 }
964
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 884 times.
884 if (v->panscanflag) {
965 avpriv_report_missing_feature(v->s.avctx, "Pan-scan");
966 //...
967 }
968
2/2
✓ Branch 0 taken 136 times.
✓ Branch 1 taken 748 times.
884 if (v->p_frame_skipped) {
969 136 return 0;
970 }
971 748 v->rnd = get_bits1(gb);
972
2/2
✓ Branch 0 taken 89 times.
✓ Branch 1 taken 659 times.
748 if (v->interlace)
973 89 v->uvsamp = get_bits1(gb);
974
2/2
✓ Branch 0 taken 73 times.
✓ Branch 1 taken 675 times.
748 if (v->field_mode) {
975
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 73 times.
73 if (!v->refdist_flag)
976 v->refdist = 0;
977
3/4
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 36 times.
✓ Branch 2 taken 37 times.
✗ Branch 3 not taken.
73 else if ((v->s.pict_type != AV_PICTURE_TYPE_B) && (v->s.pict_type != AV_PICTURE_TYPE_BI)) {
978 37 v->refdist = get_bits(gb, 2);
979
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37 times.
37 if (v->refdist == 3)
980 v->refdist += get_unary(gb, 0, 14);
981
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37 times.
37 if (v->refdist > 16)
982 return AVERROR_INVALIDDATA;
983 }
984
3/4
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 37 times.
73 if ((v->s.pict_type == AV_PICTURE_TYPE_B) || (v->s.pict_type == AV_PICTURE_TYPE_BI)) {
985
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
36 if (read_bfraction(v, gb) < 0)
986 return AVERROR_INVALIDDATA;
987 36 v->frfd = (v->bfraction * v->refdist) >> 8;
988 36 v->brfd = v->refdist - v->frfd - 1;
989
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 if (v->brfd < 0)
990 v->brfd = 0;
991 }
992 73 goto parse_common_info;
993 }
994
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 659 times.
675 if (v->fcm == PROGRESSIVE) {
995
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 659 times.
659 if (v->finterpflag)
996 v->interpfrm = get_bits1(gb);
997
2/2
✓ Branch 0 taken 543 times.
✓ Branch 1 taken 116 times.
659 if (v->s.pict_type == AV_PICTURE_TYPE_B) {
998
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
116 if (read_bfraction(v, gb) < 0)
999 return AVERROR_INVALIDDATA;
1000
1/2
✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
116 if (v->bfraction == 0) {
1001 v->s.pict_type = AV_PICTURE_TYPE_BI; /* XXX: should not happen here */
1002 }
1003 }
1004 }
1005
1006 675 parse_common_info:
1007
2/2
✓ Branch 0 taken 110 times.
✓ Branch 1 taken 675 times.
785 if (v->field_mode)
1008 110 v->cur_field_type = !(v->tff ^ v->second_field);
1009 785 pqindex = get_bits(gb, 5);
1010
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 785 times.
785 if (!pqindex)
1011 return -1;
1012
2/2
✓ Branch 0 taken 505 times.
✓ Branch 1 taken 280 times.
785 if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
1013 505 v->pq = ff_vc1_pquant_table[0][pqindex];
1014 else
1015 280 v->pq = ff_vc1_pquant_table[1][pqindex];
1016 785 v->pqindex = pqindex;
1017
2/2
✓ Branch 0 taken 750 times.
✓ Branch 1 taken 35 times.
785 if (pqindex < 9)
1018 750 v->halfpq = get_bits1(gb);
1019 else
1020 35 v->halfpq = 0;
1021
2/4
✓ Branch 0 taken 505 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 280 times.
785 switch (v->quantizer_mode) {
1022 505 case QUANT_FRAME_IMPLICIT:
1023 505 v->pquantizer = pqindex < 9;
1024 505 break;
1025 case QUANT_NON_UNIFORM:
1026 v->pquantizer = 0;
1027 break;
1028 case QUANT_FRAME_EXPLICIT:
1029 v->pquantizer = get_bits1(gb);
1030 break;
1031 280 default:
1032 280 v->pquantizer = 1;
1033 280 break;
1034 }
1035 785 v->dquantfrm = 0;
1036
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 785 times.
785 if (v->postprocflag)
1037 v->postproc = get_bits(gb, 2);
1038
1039
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 549 times.
785 if (v->parse_only)
1040 236 return 0;
1041
1042
2/2
✓ Branch 0 taken 239 times.
✓ Branch 1 taken 310 times.
549 if (v->first_pic_header_flag)
1043 239 rotate_luts(v);
1044
1045
3/4
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 431 times.
✓ Branch 2 taken 98 times.
✗ Branch 3 not taken.
549 switch (v->s.pict_type) {
1046 20 case AV_PICTURE_TYPE_I:
1047 case AV_PICTURE_TYPE_BI:
1048
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 18 times.
20 if (v->fcm == ILACE_FRAME) { //interlace frame picture
1049 2 status = bitplane_decoding(v->fieldtx_plane, &v->fieldtx_is_raw, v);
1050
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (status < 0)
1051 return -1;
1052 2 av_log(v->s.avctx, AV_LOG_DEBUG, "FIELDTX plane encoding: "
1053 "Imode: %i, Invert: %i\n", status>>1, status&1);
1054 } else
1055 18 v->fieldtx_is_raw = 0;
1056 20 status = bitplane_decoding(v->acpred_plane, &v->acpred_is_raw, v);
1057
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (status < 0)
1058 return -1;
1059 20 av_log(v->s.avctx, AV_LOG_DEBUG, "ACPRED plane encoding: "
1060 "Imode: %i, Invert: %i\n", status>>1, status&1);
1061 20 v->condover = CONDOVER_NONE;
1062
3/4
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
20 if (v->overlap && v->pq <= 8) {
1063 14 v->condover = decode012(gb);
1064
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 10 times.
14 if (v->condover == CONDOVER_SELECT) {
1065 4 status = bitplane_decoding(v->over_flags_plane, &v->overflg_is_raw, v);
1066
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (status < 0)
1067 return -1;
1068 4 av_log(v->s.avctx, AV_LOG_DEBUG, "CONDOVER plane encoding: "
1069 "Imode: %i, Invert: %i\n", status>>1, status&1);
1070 }
1071 }
1072 20 break;
1073 431 case AV_PICTURE_TYPE_P:
1074
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 395 times.
431 if (v->field_mode) {
1075 36 v->numref = get_bits1(gb);
1076
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 if (!v->numref) {
1077 v->reffield = get_bits1(gb);
1078 v->ref_field_type[0] = v->reffield ^ !v->cur_field_type;
1079 }
1080 }
1081
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 365 times.
431 if (v->extended_mv)
1082 66 v->mvrange = get_unary(gb, 0, 3);
1083 else
1084 365 v->mvrange = 0;
1085
2/2
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 393 times.
431 if (v->interlace) {
1086
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 38 times.
38 if (v->extended_dmv)
1087 v->dmvrange = get_unary(gb, 0, 3);
1088 else
1089 38 v->dmvrange = 0;
1090
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 36 times.
38 if (v->fcm == ILACE_FRAME) { // interlaced frame picture
1091 2 v->fourmvswitch = get_bits1(gb);
1092 2 v->intcomp = get_bits1(gb);
1093
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (v->intcomp) {
1094 v->lumscale = get_bits(gb, 6);
1095 v->lumshift = get_bits(gb, 6);
1096 INIT_LUT(v->lumscale, v->lumshift, v->last_luty[0], v->last_lutuv[0], 1);
1097 INIT_LUT(v->lumscale, v->lumshift, v->last_luty[1], v->last_lutuv[1], 1);
1098 v->last_use_ic = 1;
1099 }
1100 2 status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
1101
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (status < 0)
1102 return -1;
1103 2 av_log(v->s.avctx, AV_LOG_DEBUG, "SKIPMB plane encoding: "
1104 "Imode: %i, Invert: %i\n", status>>1, status&1);
1105 2 v->mbmodetab = get_bits(gb, 2);
1106
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (v->fourmvswitch)
1107 2 v->mbmode_vlc = ff_vc1_intfr_4mv_mbmode_vlc[v->mbmodetab];
1108 else
1109 v->mbmode_vlc = ff_vc1_intfr_non4mv_mbmode_vlc[v->mbmodetab];
1110 2 v->imvtab = get_bits(gb, 2);
1111 2 v->imv_vlc = ff_vc1_1ref_mvdata_vlc[v->imvtab];
1112 // interlaced p-picture cbpcy range is [1, 63]
1113 2 v->icbptab = get_bits(gb, 3);
1114 2 v->cbpcy_vlc = ff_vc1_icbpcy_vlc[v->icbptab];
1115 2 v->twomvbptab = get_bits(gb, 2);
1116 2 v->twomvbp_vlc = ff_vc1_2mv_block_pattern_vlc[v->twomvbptab];
1117
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (v->fourmvswitch) {
1118 2 v->fourmvbptab = get_bits(gb, 2);
1119 2 v->fourmvbp_vlc = ff_vc1_4mv_block_pattern_vlc[v->fourmvbptab];
1120 }
1121 }
1122 }
1123 431 v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
1124 431 v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
1125 431 v->range_x = 1 << (v->k_x - 1);
1126 431 v->range_y = 1 << (v->k_y - 1);
1127
1128 431 v->tt_index = (v->pq > 4) + (v->pq > 12);
1129
2/2
✓ Branch 0 taken 429 times.
✓ Branch 1 taken 2 times.
431 if (v->fcm != ILACE_FRAME) {
1130 int mvmode;
1131 429 mvmode = get_unary(gb, 1, 4);
1132 429 lowquant = (v->pq > 12) ? 0 : 1;
1133 429 v->mv_mode = ff_vc1_mv_pmode_table[lowquant][mvmode];
1134
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 429 times.
429 if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
1135 int mvmode2;
1136 mvmode2 = get_unary(gb, 1, 3);
1137 v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][mvmode2];
1138 if (v->field_mode) {
1139 v->intcompfield = decode210(gb) ^ 3;
1140 } else
1141 v->intcompfield = 3;
1142
1143 v->lumscale2 = v->lumscale = 32;
1144 v->lumshift2 = v->lumshift = 0;
1145 if (v->intcompfield & 1) {
1146 v->lumscale = get_bits(gb, 6);
1147 v->lumshift = get_bits(gb, 6);
1148 }
1149 if ((v->intcompfield & 2) && v->field_mode) {
1150 v->lumscale2 = get_bits(gb, 6);
1151 v->lumshift2 = get_bits(gb, 6);
1152 } else if(!v->field_mode) {
1153 v->lumscale2 = v->lumscale;
1154 v->lumshift2 = v->lumshift;
1155 }
1156 if (v->field_mode && v->second_field) {
1157 if (v->cur_field_type) {
1158 INIT_LUT(v->lumscale , v->lumshift , v->curr_luty[v->cur_field_type^1], v->curr_lutuv[v->cur_field_type^1], 0);
1159 INIT_LUT(v->lumscale2, v->lumshift2, v->last_luty[v->cur_field_type ], v->last_lutuv[v->cur_field_type ], 1);
1160 } else {
1161 INIT_LUT(v->lumscale2, v->lumshift2, v->curr_luty[v->cur_field_type^1], v->curr_lutuv[v->cur_field_type^1], 0);
1162 INIT_LUT(v->lumscale , v->lumshift , v->last_luty[v->cur_field_type ], v->last_lutuv[v->cur_field_type ], 1);
1163 }
1164 v->next_use_ic = *v->curr_use_ic = 1;
1165 } else {
1166 INIT_LUT(v->lumscale , v->lumshift , v->last_luty[0], v->last_lutuv[0], 1);
1167 INIT_LUT(v->lumscale2, v->lumshift2, v->last_luty[1], v->last_lutuv[1], 1);
1168 }
1169 v->last_use_ic = 1;
1170 }
1171
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 429 times.
429 if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
1172 v->s.quarter_sample = (v->mv_mode2 != MV_PMODE_1MV_HPEL &&
1173 v->mv_mode2 != MV_PMODE_1MV_HPEL_BILIN);
1174 v->s.mspel = (v->mv_mode2 != MV_PMODE_1MV_HPEL_BILIN);
1175 } else {
1176
1/2
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
858 v->s.quarter_sample = (v->mv_mode != MV_PMODE_1MV_HPEL &&
1177
2/2
✓ Branch 0 taken 425 times.
✓ Branch 1 taken 4 times.
429 v->mv_mode != MV_PMODE_1MV_HPEL_BILIN);
1178 429 v->s.mspel = (v->mv_mode != MV_PMODE_1MV_HPEL_BILIN);
1179 }
1180 }
1181
2/2
✓ Branch 0 taken 393 times.
✓ Branch 1 taken 38 times.
431 if (v->fcm == PROGRESSIVE) { // progressive
1182
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 393 times.
393 if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
1183 v->mv_mode2 == MV_PMODE_MIXED_MV)
1184
2/2
✓ Branch 0 taken 333 times.
✓ Branch 1 taken 60 times.
393 || v->mv_mode == MV_PMODE_MIXED_MV) {
1185 333 status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v);
1186
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 333 times.
333 if (status < 0)
1187 return -1;
1188 333 av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
1189 "Imode: %i, Invert: %i\n", status>>1, status&1);
1190 } else {
1191 60 v->mv_type_is_raw = 0;
1192 60 memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height);
1193 }
1194 393 status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
1195
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 393 times.
393 if (status < 0)
1196 return -1;
1197 393 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
1198 "Imode: %i, Invert: %i\n", status>>1, status&1);
1199
1200 /* Hopefully this is correct for P-frames */
1201 393 v->mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables
1202 393 v->cbptab = get_bits(gb, 2);
1203 393 v->cbpcy_vlc = ff_vc1_cbpcy_p_vlc[v->cbptab];
1204
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 36 times.
38 } else if (v->fcm == ILACE_FRAME) { // frame interlaced
1205 2 v->s.quarter_sample = 1;
1206 2 v->s.mspel = 1;
1207 } else { // field interlaced
1208 36 v->mbmodetab = get_bits(gb, 3);
1209 36 v->imvtab = get_bits(gb, 2 + v->numref);
1210
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 if (!v->numref)
1211 v->imv_vlc = ff_vc1_1ref_mvdata_vlc[v->imvtab];
1212 else
1213 36 v->imv_vlc = ff_vc1_2ref_mvdata_vlc[v->imvtab];
1214 36 v->icbptab = get_bits(gb, 3);
1215 36 v->cbpcy_vlc = ff_vc1_icbpcy_vlc[v->icbptab];
1216
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
1217
2/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
✓ Branch 3 taken 4 times.
36 v->mv_mode2 == MV_PMODE_MIXED_MV) || v->mv_mode == MV_PMODE_MIXED_MV) {
1218 32 v->fourmvbptab = get_bits(gb, 2);
1219 32 v->fourmvbp_vlc = ff_vc1_4mv_block_pattern_vlc[v->fourmvbptab];
1220 32 v->mbmode_vlc = ff_vc1_if_mmv_mbmode_vlc[v->mbmodetab];
1221 } else {
1222 4 v->mbmode_vlc = ff_vc1_if_1mv_mbmode_vlc[v->mbmodetab];
1223 }
1224 }
1225
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 425 times.
431 if (v->dquant) {
1226 6 av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
1227 6 vop_dquant_decoding(v);
1228 }
1229
1230
2/2
✓ Branch 0 taken 417 times.
✓ Branch 1 taken 14 times.
431 if (v->vstransform) {
1231 417 v->ttmbf = get_bits1(gb);
1232
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 417 times.
417 if (v->ttmbf) {
1233 v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
1234 } else
1235 417 v->ttfrm = 0; //FIXME Is that so ?
1236 } else {
1237 14 v->ttmbf = 1;
1238 14 v->ttfrm = TT_8X8;
1239 }
1240 431 break;
1241 98 case AV_PICTURE_TYPE_B:
1242
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 94 times.
98 if (v->fcm == ILACE_FRAME) {
1243
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 if (read_bfraction(v, gb) < 0)
1244 return AVERROR_INVALIDDATA;
1245
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (v->bfraction == 0) {
1246 return -1;
1247 }
1248 }
1249
2/2
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 28 times.
98 if (v->extended_mv)
1250 70 v->mvrange = get_unary(gb, 0, 3);
1251 else
1252 28 v->mvrange = 0;
1253 98 v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
1254 98 v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
1255 98 v->range_x = 1 << (v->k_x - 1);
1256 98 v->range_y = 1 << (v->k_y - 1);
1257
1258 98 v->tt_index = (v->pq > 4) + (v->pq > 12);
1259
1260
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 62 times.
98 if (v->field_mode) {
1261 int mvmode;
1262 36 av_log(v->s.avctx, AV_LOG_DEBUG, "B Fields\n");
1263
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 if (v->extended_dmv)
1264 v->dmvrange = get_unary(gb, 0, 3);
1265 36 mvmode = get_unary(gb, 1, 3);
1266 36 lowquant = (v->pq > 12) ? 0 : 1;
1267 36 v->mv_mode = ff_vc1_mv_pmode_table2[lowquant][mvmode];
1268
3/4
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
✓ Branch 3 taken 8 times.
36 v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV || v->mv_mode == MV_PMODE_MIXED_MV);
1269 36 v->s.mspel = (v->mv_mode != MV_PMODE_1MV_HPEL_BILIN);
1270 36 status = bitplane_decoding(v->forward_mb_plane, &v->fmb_is_raw, v);
1271
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 if (status < 0)
1272 return -1;
1273 36 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Forward Type plane encoding: "
1274 "Imode: %i, Invert: %i\n", status>>1, status&1);
1275 36 v->mbmodetab = get_bits(gb, 3);
1276
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 8 times.
36 if (v->mv_mode == MV_PMODE_MIXED_MV)
1277 28 v->mbmode_vlc = ff_vc1_if_mmv_mbmode_vlc[v->mbmodetab];
1278 else
1279 8 v->mbmode_vlc = ff_vc1_if_1mv_mbmode_vlc[v->mbmodetab];
1280 36 v->imvtab = get_bits(gb, 3);
1281 36 v->imv_vlc = ff_vc1_2ref_mvdata_vlc[v->imvtab];
1282 36 v->icbptab = get_bits(gb, 3);
1283 36 v->cbpcy_vlc = ff_vc1_icbpcy_vlc[v->icbptab];
1284
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 8 times.
36 if (v->mv_mode == MV_PMODE_MIXED_MV) {
1285 28 v->fourmvbptab = get_bits(gb, 2);
1286 28 v->fourmvbp_vlc = ff_vc1_4mv_block_pattern_vlc[v->fourmvbptab];
1287 }
1288 36 v->numref = 1; // interlaced field B pictures are always 2-ref
1289
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 58 times.
62 } else if (v->fcm == ILACE_FRAME) {
1290
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (v->extended_dmv)
1291 v->dmvrange = get_unary(gb, 0, 3);
1292
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 if (get_bits1(gb)) /* intcomp - present but shall always be 0 */
1293 av_log(v->s.avctx, AV_LOG_WARNING, "Intensity compensation set for B picture\n");
1294 4 v->intcomp = 0;
1295 4 v->mv_mode = MV_PMODE_1MV;
1296 4 v->fourmvswitch = 0;
1297 4 v->s.quarter_sample = 1;
1298 4 v->s.mspel = 1;
1299 4 status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);
1300
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (status < 0)
1301 return -1;
1302 4 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "
1303 "Imode: %i, Invert: %i\n", status>>1, status&1);
1304 4 status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
1305
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (status < 0)
1306 return -1;
1307 4 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
1308 "Imode: %i, Invert: %i\n", status>>1, status&1);
1309 4 v->mbmodetab = get_bits(gb, 2);
1310 4 v->mbmode_vlc = ff_vc1_intfr_non4mv_mbmode_vlc[v->mbmodetab];
1311 4 v->imvtab = get_bits(gb, 2);
1312 4 v->imv_vlc = ff_vc1_1ref_mvdata_vlc[v->imvtab];
1313 // interlaced p/b-picture cbpcy range is [1, 63]
1314 4 v->icbptab = get_bits(gb, 3);
1315 4 v->cbpcy_vlc = ff_vc1_icbpcy_vlc[v->icbptab];
1316 4 v->twomvbptab = get_bits(gb, 2);
1317 4 v->twomvbp_vlc = ff_vc1_2mv_block_pattern_vlc[v->twomvbptab];
1318 4 v->fourmvbptab = get_bits(gb, 2);
1319 4 v->fourmvbp_vlc = ff_vc1_4mv_block_pattern_vlc[v->fourmvbptab];
1320 } else {
1321 58 v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;
1322 58 v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV);
1323 58 v->s.mspel = v->s.quarter_sample;
1324 58 status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);
1325
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
58 if (status < 0)
1326 return -1;
1327 58 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "
1328 "Imode: %i, Invert: %i\n", status>>1, status&1);
1329 58 status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
1330
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
58 if (status < 0)
1331 return -1;
1332 58 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
1333 "Imode: %i, Invert: %i\n", status>>1, status&1);
1334 58 v->mv_table_index = get_bits(gb, 2);
1335 58 v->cbptab = get_bits(gb, 2);
1336 58 v->cbpcy_vlc = ff_vc1_cbpcy_p_vlc[v->cbptab];
1337 }
1338
1339
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 86 times.
98 if (v->dquant) {
1340 12 av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
1341 12 vop_dquant_decoding(v);
1342 }
1343
1344
1/2
✓ Branch 0 taken 98 times.
✗ Branch 1 not taken.
98 if (v->vstransform) {
1345 98 v->ttmbf = get_bits1(gb);
1346
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 98 times.
98 if (v->ttmbf) {
1347 v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
1348 } else
1349 98 v->ttfrm = 0;
1350 } else {
1351 v->ttmbf = 1;
1352 v->ttfrm = TT_8X8;
1353 }
1354 98 break;
1355 }
1356
1357
1358 /* AC Syntax */
1359 549 v->c_ac_table_index = decode012(gb);
1360
3/4
✓ Branch 0 taken 529 times.
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 529 times.
549 if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI) {
1361 20 v->y_ac_table_index = decode012(gb);
1362 }
1363
4/4
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 451 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 66 times.
529 else if (v->fcm != PROGRESSIVE && !v->s.quarter_sample) {
1364 12 v->range_x <<= 1;
1365 12 v->range_y <<= 1;
1366 }
1367
1368 /* DC Syntax */
1369 549 v->dc_table_index = get_bits1(gb);
1370
3/4
✓ Branch 0 taken 529 times.
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 529 times.
549 if ((v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)
1371
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 18 times.
20 && v->dquant) {
1372 2 av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
1373 2 vop_dquant_decoding(v);
1374 }
1375
1376 549 v->bi_type = (v->s.pict_type == AV_PICTURE_TYPE_BI);
1377
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 549 times.
549 if (v->bi_type)
1378 v->s.pict_type = AV_PICTURE_TYPE_B;
1379
1380 549 return 0;
1381 }
1382