FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/vc1.c
Date: 2024-04-12 08:31:17
Exec Total Coverage
Lines: 698 868 80.4%
Functions: 11 11 100.0%
Branches: 395 634 62.3%

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