FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/vc1.c
Date: 2026-05-02 03:33:10
Exec Total Coverage
Lines: 695 865 80.3%
Functions: 11 11 100.0%
Branches: 388 624 62.2%

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