FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/vc1.c
Date: 2022-11-28 23:49:43
Exec Total Coverage
Lines: 698 868 80.4%
Branches: 394 634 62.1%

Line Branch Exec Source
1 /*
2 * VC-1 and WMV3 decoder common code
3 * Copyright (c) 2011 Mashiat Sarker Shakkhar
4 * Copyright (c) 2006-2007 Konstantin Shishkov
5 * Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, Michael Niedermayer
6 *
7 * This file is part of FFmpeg.
8 *
9 * FFmpeg is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * FFmpeg is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with FFmpeg; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 /**
25 * @file
26 * VC-1 and WMV3 decoder common code
27 */
28
29 #include "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 192 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 575 times.
✓ Branch 1 taken 192 times.
767 for (y = 0; y < height; y++) {
56
2/2
✓ Branch 1 taken 277 times.
✓ Branch 2 taken 298 times.
575 if (!get_bits1(gb)) //rowskip
57 277 memset(plane, 0, width);
58 else
59
2/2
✓ Branch 0 taken 7271 times.
✓ Branch 1 taken 298 times.
7569 for (x = 0; x < width; x++)
60 7271 plane[x] = get_bits1(gb);
61 575 plane += stride;
62 }
63 192 }
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 117 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 736 times.
✓ Branch 1 taken 117 times.
853 for (x = 0; x < width; x++) {
78
2/2
✓ Branch 1 taken 251 times.
✓ Branch 2 taken 485 times.
736 if (!get_bits1(gb)) //colskip
79
2/2
✓ Branch 0 taken 8780 times.
✓ Branch 1 taken 251 times.
9031 for (y = 0; y < height; y++)
80 8780 plane[y*stride] = 0;
81 else
82
2/2
✓ Branch 0 taken 6280 times.
✓ Branch 1 taken 485 times.
6765 for (y = 0; y < height; y++)
83 6280 plane[y*stride] = get_bits1(gb);
84 736 plane ++;
85 }
86 117 }
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 1098 static int bitplane_decoding(uint8_t* data, int *raw_flag, VC1Context *v)
96 {
97 1098 GetBitContext *gb = &v->s.gb;
98
99 int imode, x, y, code, offset;
100 1098 uint8_t invert, *planep = data;
101 int width, height, stride;
102
103 1098 width = v->s.mb_width;
104 1098 height = v->s.mb_height >> v->field_mode;
105 1098 stride = v->s.mb_stride;
106 1098 invert = get_bits1(gb);
107 1098 imode = get_vlc2(gb, ff_vc1_imode_vlc.table, VC1_IMODE_VLC_BITS, 1);
108
109 1098 *raw_flag = 0;
110
5/6
✓ Branch 0 taken 632 times.
✓ Branch 1 taken 164 times.
✓ Branch 2 taken 246 times.
✓ Branch 3 taken 33 times.
✓ Branch 4 taken 23 times.
✗ Branch 5 not taken.
1098 switch (imode) {
111 632 case IMODE_RAW:
112 //Data is actually read in the MB layer (same for all tests == "raw")
113 632 *raw_flag = 1; //invert ignored
114 632 return invert;
115 164 case IMODE_DIFF2:
116 case IMODE_NORM2:
117
2/2
✓ Branch 0 taken 112 times.
✓ Branch 1 taken 52 times.
164 if ((height * width) & 1) {
118 112 *planep++ = get_bits1(gb);
119 112 y = offset = 1;
120
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 112 times.
112 if (offset == width) {
121 offset = 0;
122 planep += stride - width;
123 }
124 }
125 else
126 52 y = offset = 0;
127 // decode bitplane as one long line
128
2/2
✓ Branch 0 taken 41722 times.
✓ Branch 1 taken 164 times.
41886 for (; y < height * width; y += 2) {
129 41722 code = get_vlc2(gb, ff_vc1_norm2_vlc.table, VC1_NORM2_VLC_BITS, 1);
130 41722 *planep++ = code & 1;
131 41722 offset++;
132
2/2
✓ Branch 0 taken 529 times.
✓ Branch 1 taken 41193 times.
41722 if (offset == width) {
133 529 offset = 0;
134 529 planep += stride - width;
135 }
136 41722 *planep++ = code >> 1;
137 41722 offset++;
138
2/2
✓ Branch 0 taken 1417 times.
✓ Branch 1 taken 40305 times.
41722 if (offset == width) {
139 1417 offset = 0;
140 1417 planep += stride - width;
141 }
142 }
143 164 break;
144 246 case IMODE_DIFF6:
145 case IMODE_NORM6:
146
4/4
✓ Branch 0 taken 89 times.
✓ Branch 1 taken 157 times.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 72 times.
246 if (!(height % 3) && (width % 3)) { // use 2x3 decoding
147
2/2
✓ Branch 0 taken 75 times.
✓ Branch 1 taken 17 times.
92 for (y = 0; y < height; y += 3) {
148
2/2
✓ Branch 0 taken 675 times.
✓ Branch 1 taken 75 times.
750 for (x = width & 1; x < width; x += 2) {
149 675 code = get_vlc2(gb, ff_vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2);
150
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 675 times.
675 if (code < 0) {
151 av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");
152 return -1;
153 }
154 675 planep[x + 0] = (code >> 0) & 1;
155 675 planep[x + 1] = (code >> 1) & 1;
156 675 planep[x + 0 + stride] = (code >> 2) & 1;
157 675 planep[x + 1 + stride] = (code >> 3) & 1;
158 675 planep[x + 0 + stride * 2] = (code >> 4) & 1;
159 675 planep[x + 1 + stride * 2] = (code >> 5) & 1;
160 }
161 75 planep += stride * 3;
162 }
163
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 12 times.
17 if (width & 1)
164 5 decode_colskip(data, 1, height, stride, &v->s.gb);
165 } else { // 3x2
166 229 planep += (height & 1) * stride;
167
2/2
✓ Branch 0 taken 1961 times.
✓ Branch 1 taken 229 times.
2190 for (y = height & 1; y < height; y += 2) {
168
2/2
✓ Branch 0 taken 30895 times.
✓ Branch 1 taken 1961 times.
32856 for (x = width % 3; x < width; x += 3) {
169 30895 code = get_vlc2(gb, ff_vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2);
170
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30895 times.
30895 if (code < 0) {
171 av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");
172 return -1;
173 }
174 30895 planep[x + 0] = (code >> 0) & 1;
175 30895 planep[x + 1] = (code >> 1) & 1;
176 30895 planep[x + 2] = (code >> 2) & 1;
177 30895 planep[x + 0 + stride] = (code >> 3) & 1;
178 30895 planep[x + 1 + stride] = (code >> 4) & 1;
179 30895 planep[x + 2 + stride] = (code >> 5) & 1;
180 }
181 1961 planep += stride * 2;
182 }
183 229 x = width % 3;
184
2/2
✓ Branch 0 taken 89 times.
✓ Branch 1 taken 140 times.
229 if (x)
185 89 decode_colskip(data, x, height, stride, &v->s.gb);
186
2/2
✓ Branch 0 taken 159 times.
✓ Branch 1 taken 70 times.
229 if (height & 1)
187 159 decode_rowskip(data + x, width - x, 1, stride, &v->s.gb);
188 }
189 246 break;
190 33 case IMODE_ROWSKIP:
191 33 decode_rowskip(data, width, height, stride, &v->s.gb);
192 33 break;
193 23 case IMODE_COLSKIP:
194 23 decode_colskip(data, width, height, stride, &v->s.gb);
195 23 break;
196 default:
197 break;
198 }
199
200 /* Applying diff operator */
201
4/4
✓ Branch 0 taken 400 times.
✓ Branch 1 taken 66 times.
✓ Branch 2 taken 56 times.
✓ Branch 3 taken 344 times.
466 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 41 times.
✓ Branch 1 taken 303 times.
344 } else if (invert) {
215 41 planep = data;
216
2/2
✓ Branch 0 taken 13354 times.
✓ Branch 1 taken 41 times.
13395 for (x = 0; x < stride * height; x++)
217 13354 planep[x] = !planep[x]; //FIXME stride
218 }
219 466 return (imode << 1) + invert;
220 }
221
222 /** @} */ //Bitplane group
223
224 /***********************************************************************/
225 /** VOP Dquant decoding
226 * @param v VC-1 Context
227 */
228 146 static int vop_dquant_decoding(VC1Context *v)
229 {
230 146 GetBitContext *gb = &v->s.gb;
231 int pqdiff;
232
233 //variable size
234
1/2
✓ Branch 0 taken 146 times.
✗ Branch 1 not taken.
146 if (v->dquant != 2) {
235 146 v->dquantfrm = get_bits1(gb);
236
2/2
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 81 times.
146 if (!v->dquantfrm)
237 65 return 0;
238
239 81 v->dqprofile = get_bits(gb, 2);
240
2/3
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
81 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 19 case DQPROFILE_ALL_MBS:
246 19 v->dqbilevel = get_bits1(gb);
247
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 18 times.
19 if (!v->dqbilevel) {
248 1 v->halfpq = 0;
249 1 return 0;
250 }
251 default:
252 18 break; //Forbidden ?
253 }
254 }
255
256 80 pqdiff = get_bits(gb, 3);
257
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 62 times.
80 if (pqdiff == 7)
258 18 v->altpq = get_bits(gb, 5);
259 else
260 62 v->altpq = v->pq + pqdiff + 1;
261
262 80 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 24 v->psf = get_bits1(gb);
422
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (v->psf) { //PsF, 6.1.13
423 av_log(v->s.avctx, AV_LOG_ERROR, "Progressive Segmented Frame mode: not supported (yet)\n");
424 return -1;
425 }
426 24 v->s.max_b_frames = v->s.avctx->max_b_frames = 7;
427
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 if (get_bits1(gb)) { //Display Info - decoding is not affected by it
428 24 int w, h, ar = 0;
429 24 av_log(v->s.avctx, AV_LOG_DEBUG, "Display extended info:\n");
430 24 w = get_bits(gb, 14) + 1;
431 24 h = get_bits(gb, 14) + 1;
432 24 av_log(v->s.avctx, AV_LOG_DEBUG, "Display dimensions: %ix%i\n", w, h);
433
2/2
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 15 times.
24 if (get_bits1(gb))
434 9 ar = get_bits(gb, 4);
435
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) {
436 3 v->s.avctx->sample_aspect_ratio = ff_vc1_pixel_aspect[ar];
437
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 15 times.
21 } else if (ar == 15) {
438 6 w = get_bits(gb, 8) + 1;
439 6 h = get_bits(gb, 8) + 1;
440 6 v->s.avctx->sample_aspect_ratio = (AVRational){w, h};
441 } else {
442
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
15 if (v->s.avctx->width > v->max_coded_width ||
443
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 v->s.avctx->height > v->max_coded_height) {
444 avpriv_request_sample(v->s.avctx, "Huge resolution");
445 } else
446 15 av_reduce(&v->s.avctx->sample_aspect_ratio.num,
447 15 &v->s.avctx->sample_aspect_ratio.den,
448 15 v->s.avctx->height * w,
449 15 v->s.avctx->width * h,
450 1 << 30);
451 }
452 24 ff_set_sar(v->s.avctx, v->s.avctx->sample_aspect_ratio);
453 24 av_log(v->s.avctx, AV_LOG_DEBUG, "Aspect: %i:%i\n",
454 24 v->s.avctx->sample_aspect_ratio.num,
455 24 v->s.avctx->sample_aspect_ratio.den);
456
457
2/2
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 15 times.
24 if (get_bits1(gb)) { //framerate stuff
458
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
9 if (get_bits1(gb)) {
459 v->s.avctx->framerate.den = 32;
460 v->s.avctx->framerate.num = get_bits(gb, 16) + 1;
461 } else {
462 int nr, dr;
463 9 nr = get_bits(gb, 8);
464 9 dr = get_bits(gb, 4);
465
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) {
466 9 v->s.avctx->framerate.den = ff_vc1_fps_dr[dr - 1];
467 9 v->s.avctx->framerate.num = ff_vc1_fps_nr[nr - 1] * 1000;
468 }
469 }
470
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (v->broadcast) { // Pulldown may be present
471 9 v->s.avctx->ticks_per_frame = 2;
472 }
473 }
474
475
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
24 if (get_bits1(gb)) {
476 v->color_prim = get_bits(gb, 8);
477 v->transfer_char = get_bits(gb, 8);
478 v->matrix_coef = get_bits(gb, 8);
479 }
480 }
481
482 24 v->hrd_param_flag = get_bits1(gb);
483
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 6 times.
24 if (v->hrd_param_flag) {
484 int i;
485 18 v->hrd_num_leaky_buckets = get_bits(gb, 5);
486 18 skip_bits(gb, 4); //bitrate exponent
487 18 skip_bits(gb, 4); //buffer size exponent
488
2/2
✓ Branch 0 taken 258 times.
✓ Branch 1 taken 18 times.
276 for (i = 0; i < v->hrd_num_leaky_buckets; i++) {
489 258 skip_bits(gb, 16); //hrd_rate[n]
490 258 skip_bits(gb, 16); //hrd_buffer[n]
491 }
492 }
493 24 return 0;
494 }
495
496 52 int ff_vc1_decode_entry_point(AVCodecContext *avctx, VC1Context *v, GetBitContext *gb)
497 {
498 int i;
499 int w,h;
500 int ret;
501
502 52 av_log(avctx, AV_LOG_DEBUG, "Entry point: %08X\n", show_bits_long(gb, 32));
503 52 v->broken_link = get_bits1(gb);
504 52 v->closed_entry = get_bits1(gb);
505 52 v->panscanflag = get_bits1(gb);
506 52 v->refdist_flag = get_bits1(gb);
507 52 v->s.loop_filter = get_bits1(gb);
508
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 52 times.
52 if (v->s.avctx->skip_loop_filter >= AVDISCARD_ALL)
509 v->s.loop_filter = 0;
510 52 v->fastuvmc = get_bits1(gb);
511 52 v->extended_mv = get_bits1(gb);
512 52 v->dquant = get_bits(gb, 2);
513 52 v->vstransform = get_bits1(gb);
514 52 v->overlap = get_bits1(gb);
515 52 v->quantizer_mode = get_bits(gb, 2);
516
517
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 8 times.
52 if (v->hrd_param_flag) {
518
2/2
✓ Branch 0 taken 684 times.
✓ Branch 1 taken 44 times.
728 for (i = 0; i < v->hrd_num_leaky_buckets; i++) {
519 684 skip_bits(gb, 8); //hrd_full[n]
520 }
521 }
522
523
2/2
✓ Branch 1 taken 40 times.
✓ Branch 2 taken 12 times.
52 if(get_bits1(gb)){
524 40 w = (get_bits(gb, 12)+1)<<1;
525 40 h = (get_bits(gb, 12)+1)<<1;
526 } else {
527 12 w = v->max_coded_width;
528 12 h = v->max_coded_height;
529 }
530
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 52 times.
52 if ((ret = ff_set_dimensions(avctx, w, h)) < 0) {
531 av_log(avctx, AV_LOG_ERROR, "Failed to set dimensions %d %d\n", w, h);
532 return ret;
533 }
534
535
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 40 times.
52 if (v->extended_mv)
536 12 v->extended_dmv = get_bits1(gb);
537
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 52 times.
52 if ((v->range_mapy_flag = get_bits1(gb))) {
538 av_log(avctx, AV_LOG_ERROR, "Luma scaling is not supported, expect wrong picture\n");
539 v->range_mapy = get_bits(gb, 3);
540 }
541
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 52 times.
52 if ((v->range_mapuv_flag = get_bits1(gb))) {
542 av_log(avctx, AV_LOG_ERROR, "Chroma scaling is not supported, expect wrong picture\n");
543 v->range_mapuv = get_bits(gb, 3);
544 }
545
546 52 av_log(avctx, AV_LOG_DEBUG, "Entry point info:\n"
547 "BrokenLink=%i, ClosedEntry=%i, PanscanFlag=%i\n"
548 "RefDist=%i, Postproc=%i, FastUVMC=%i, ExtMV=%i\n"
549 "DQuant=%i, VSTransform=%i, Overlap=%i, Qmode=%i\n",
550 52 v->broken_link, v->closed_entry, v->panscanflag, v->refdist_flag, v->s.loop_filter,
551 v->fastuvmc, v->extended_mv, v->dquant, v->vstransform, v->overlap, v->quantizer_mode);
552
553 52 return 0;
554 }
555
556 /* fill lookup tables for intensity compensation */
557 #define INIT_LUT(lumscale, lumshift, luty, lutuv, chain) do { \
558 int scale, shift, i; \
559 if (!lumscale) { \
560 scale = -64; \
561 shift = (255 - lumshift * 2) * 64; \
562 if (lumshift > 31) \
563 shift += 128 << 6; \
564 } else { \
565 scale = lumscale + 32; \
566 if (lumshift > 31) \
567 shift = (lumshift - 64) * 64; \
568 else \
569 shift = lumshift << 6; \
570 } \
571 for (i = 0; i < 256; i++) { \
572 int iy = chain ? luty[i] : i; \
573 int iu = chain ? lutuv[i] : i; \
574 luty[i] = av_clip_uint8((scale * iy + shift + 32) >> 6); \
575 lutuv[i] = av_clip_uint8((scale * (iu - 128) + 128*64 + 32) >> 6);\
576 } \
577 } while(0)
578
579 409 static void rotate_luts(VC1Context *v)
580 {
581 #define ROTATE(DEF, L, N, C, A) do { \
582 if (v->s.pict_type == AV_PICTURE_TYPE_BI || v->s.pict_type == AV_PICTURE_TYPE_B) { \
583 C = A; \
584 } else { \
585 DEF; \
586 memcpy(&tmp, L , sizeof(tmp)); \
587 memcpy(L , N , sizeof(tmp)); \
588 memcpy(N , &tmp, sizeof(tmp)); \
589 C = N; \
590 } \
591 } while(0)
592
593
3/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 91 times.
✓ Branch 3 taken 318 times.
409 ROTATE(int tmp, &v->last_use_ic, &v->next_use_ic, v->curr_use_ic, &v->aux_use_ic);
594
3/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 91 times.
✓ Branch 3 taken 318 times.
409 ROTATE(uint8_t tmp[2][256], v->last_luty, v->next_luty, v->curr_luty, v->aux_luty);
595
3/4
✓ Branch 0 taken 409 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 91 times.
✓ Branch 3 taken 318 times.
409 ROTATE(uint8_t tmp[2][256], v->last_lutuv, v->next_lutuv, v->curr_lutuv, v->aux_lutuv);
596
597
2/2
✓ Branch 0 taken 104704 times.
✓ Branch 1 taken 409 times.
105113 INIT_LUT(32, 0, v->curr_luty[0], v->curr_lutuv[0], 0);
598
2/2
✓ Branch 0 taken 104704 times.
✓ Branch 1 taken 409 times.
105113 INIT_LUT(32, 0, v->curr_luty[1], v->curr_lutuv[1], 0);
599 409 *v->curr_use_ic = 0;
600 409 }
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 259 int ff_vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)
618 {
619 int pqindex, lowquant, status;
620
621 259 v->field_mode = 0;
622 259 v->fcm = PROGRESSIVE;
623
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 259 times.
259 if (v->finterpflag)
624 v->interpfrm = get_bits1(gb);
625
2/2
✓ Branch 0 taken 81 times.
✓ Branch 1 taken 178 times.
259 if (v->s.avctx->codec_id == AV_CODEC_ID_MSS2)
626 81 v->respic =
627 81 v->rangered =
628 81 v->multires = get_bits(gb, 2) == 1;
629 else
630 178 skip_bits(gb, 2); //framecnt unused
631 259 v->rangeredfrm = 0;
632
2/2
✓ Branch 0 taken 53 times.
✓ Branch 1 taken 206 times.
259 if (v->rangered)
633 53 v->rangeredfrm = get_bits1(gb);
634
2/2
✓ Branch 1 taken 163 times.
✓ Branch 2 taken 96 times.
259 if (get_bits1(gb)) {
635 163 v->s.pict_type = AV_PICTURE_TYPE_P;
636 } else {
637
4/4
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 84 times.
✓ Branch 3 taken 11 times.
✓ Branch 4 taken 1 times.
96 if (v->s.avctx->max_b_frames && !get_bits1(gb)) {
638 11 v->s.pict_type = AV_PICTURE_TYPE_B;
639 } else
640 85 v->s.pict_type = AV_PICTURE_TYPE_I;
641 }
642
643 259 v->bi_type = 0;
644
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 248 times.
259 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 174 times.
✓ Branch 1 taken 85 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 174 times.
259 if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)
652 85 skip_bits(gb, 7); // skip buffer fullness
653
654
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 259 times.
259 if (v->parse_only)
655 return 0;
656
657 /* calculate RND */
658
3/4
✓ Branch 0 taken 174 times.
✓ Branch 1 taken 85 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 174 times.
259 if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)
659 85 v->rnd = 1;
660
2/2
✓ Branch 0 taken 163 times.
✓ Branch 1 taken 96 times.
259 if (v->s.pict_type == AV_PICTURE_TYPE_P)
661 163 v->rnd ^= 1;
662
663
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 259 times.
259 if (get_bits_left(gb) < 5)
664 return AVERROR_INVALIDDATA;
665 /* Quantizer stuff */
666 259 pqindex = get_bits(gb, 5);
667
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 259 times.
259 if (!pqindex)
668 return -1;
669
1/2
✓ Branch 0 taken 259 times.
✗ Branch 1 not taken.
259 if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
670 259 v->pq = ff_vc1_pquant_table[0][pqindex];
671 else
672 v->pq = ff_vc1_pquant_table[1][pqindex];
673 259 v->pqindex = pqindex;
674
2/2
✓ Branch 0 taken 167 times.
✓ Branch 1 taken 92 times.
259 if (pqindex < 9)
675 167 v->halfpq = get_bits1(gb);
676 else
677 92 v->halfpq = 0;
678
1/4
✓ Branch 0 taken 259 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
259 switch (v->quantizer_mode) {
679 259 case QUANT_FRAME_IMPLICIT:
680 259 v->pquantizer = pqindex < 9;
681 259 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 259 v->dquantfrm = 0;
693
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 259 times.
259 if (v->extended_mv == 1)
694 v->mvrange = get_unary(gb, 0, 3);
695 259 v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
696 259 v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
697 259 v->range_x = 1 << (v->k_x - 1);
698 259 v->range_y = 1 << (v->k_y - 1);
699
3/4
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 181 times.
✓ Branch 2 taken 78 times.
✗ Branch 3 not taken.
259 if (v->multires && v->s.pict_type != AV_PICTURE_TYPE_B)
700 78 v->respic = get_bits(gb, 2);
701
702
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 259 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
259 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 259 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 178 times.
✓ Branch 1 taken 81 times.
259 if (v->first_pic_header_flag)
711 178 rotate_luts(v);
712
713
3/3
✓ Branch 0 taken 163 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 85 times.
259 switch (v->s.pict_type) {
714 163 case AV_PICTURE_TYPE_P:
715 163 v->tt_index = (v->pq > 4) + (v->pq > 12);
716
717 163 lowquant = (v->pq > 12) ? 0 : 1;
718 163 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 142 times.
163 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 163 v->qs_last = v->s.quarter_sample;
729
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 142 times.
163 if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
730
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 3 times.
39 v->s.quarter_sample = (v->mv_mode2 != MV_PMODE_1MV_HPEL &&
731
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 3 times.
18 v->mv_mode2 != MV_PMODE_1MV_HPEL_BILIN);
732 21 v->s.mspel = (v->mv_mode2 != MV_PMODE_1MV_HPEL_BILIN);
733 } else {
734
2/2
✓ Branch 0 taken 137 times.
✓ Branch 1 taken 5 times.
279 v->s.quarter_sample = (v->mv_mode != MV_PMODE_1MV_HPEL &&
735
2/2
✓ Branch 0 taken 113 times.
✓ Branch 1 taken 24 times.
137 v->mv_mode != MV_PMODE_1MV_HPEL_BILIN);
736 142 v->s.mspel = (v->mv_mode != MV_PMODE_1MV_HPEL_BILIN);
737 }
738
739
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 142 times.
163 if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
740
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 v->mv_mode2 == MV_PMODE_MIXED_MV) ||
741
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 151 times.
163 v->mv_mode == MV_PMODE_MIXED_MV) {
742 12 status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v);
743
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (status < 0)
744 return -1;
745 12 av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
746 "Imode: %i, Invert: %i\n", status>>1, status&1);
747 } else {
748 151 v->mv_type_is_raw = 0;
749 151 memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height);
750 }
751 163 status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
752
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 163 times.
163 if (status < 0)
753 return -1;
754 163 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
755 "Imode: %i, Invert: %i\n", status>>1, status&1);
756
757
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 163 times.
163 if (get_bits_left(gb) < 4)
758 return AVERROR_INVALIDDATA;
759
760 /* Hopefully this is correct for P-frames */
761 163 v->s.mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables
762 163 v->cbptab = get_bits(gb, 2);
763 163 v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[v->cbptab];
764
765
2/2
✓ Branch 0 taken 127 times.
✓ Branch 1 taken 36 times.
163 if (v->dquant) {
766 127 av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
767 127 vop_dquant_decoding(v);
768 }
769
770
2/2
✓ Branch 0 taken 139 times.
✓ Branch 1 taken 24 times.
163 if (v->vstransform) {
771 139 v->ttmbf = get_bits1(gb);
772
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 134 times.
139 if (v->ttmbf) {
773 5 v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
774 } else
775 134 v->ttfrm = 0; //FIXME Is that so ?
776 } else {
777 24 v->ttmbf = 1;
778 24 v->ttfrm = TT_8X8;
779 }
780 163 break;
781 11 case AV_PICTURE_TYPE_B:
782 11 v->tt_index = (v->pq > 4) + (v->pq > 12);
783
784 11 v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;
785 11 v->qs_last = v->s.quarter_sample;
786 11 v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV);
787 11 v->s.mspel = v->s.quarter_sample;
788
789 11 status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);
790
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (status < 0)
791 return -1;
792 11 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "
793 "Imode: %i, Invert: %i\n", status>>1, status&1);
794 11 status = bitplane_decoding(v->s.mbskip_table, &v->skip_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 Skip plane encoding: "
798 "Imode: %i, Invert: %i\n", status>>1, status&1);
799
800 11 v->s.mv_table_index = get_bits(gb, 2);
801 11 v->cbptab = get_bits(gb, 2);
802 11 v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[v->cbptab];
803
804
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (v->dquant) {
805 av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
806 vop_dquant_decoding(v);
807 }
808
809
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (v->vstransform) {
810 11 v->ttmbf = get_bits1(gb);
811
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (v->ttmbf) {
812 v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
813 } else
814 11 v->ttfrm = 0;
815 } else {
816 v->ttmbf = 1;
817 v->ttfrm = TT_8X8;
818 }
819 11 break;
820 }
821
822
1/2
✓ Branch 0 taken 259 times.
✗ Branch 1 not taken.
259 if (!v->x8_type) {
823 /* AC Syntax */
824 259 v->c_ac_table_index = decode012(gb);
825
3/4
✓ Branch 0 taken 174 times.
✓ Branch 1 taken 85 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 174 times.
259 if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI) {
826 85 v->y_ac_table_index = decode012(gb);
827 }
828 /* DC Syntax */
829 259 v->s.dc_table_index = get_bits1(gb);
830 }
831
832
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 259 times.
259 if (v->s.pict_type == AV_PICTURE_TYPE_BI) {
833 v->s.pict_type = AV_PICTURE_TYPE_B;
834 v->bi_type = 1;
835 }
836 259 return 0;
837 }
838
839 910 int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
840 {
841 int pqindex, lowquant;
842 int status;
843 int field_mode, fcm;
844
845 910 v->numref = 0;
846 910 v->p_frame_skipped = 0;
847
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 874 times.
910 if (v->second_field) {
848
2/4
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 36 times.
36 if (v->fcm != ILACE_FIELD || v->field_mode!=1)
849 return -1;
850
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 18 times.
36 if (v->fptype & 4)
851
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;
852 else
853
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 v->s.pict_type = (v->fptype & 1) ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
854 36 v->s.current_picture_ptr->f->pict_type = v->s.pict_type;
855
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if (!v->pic_header_flag)
856 36 goto parse_common_info;
857 }
858
859 874 field_mode = 0;
860
2/2
✓ Branch 0 taken 87 times.
✓ Branch 1 taken 787 times.
874 if (v->interlace) {
861 87 fcm = decode012(gb);
862
1/2
✓ Branch 0 taken 87 times.
✗ Branch 1 not taken.
87 if (fcm) {
863
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 15 times.
87 if (fcm == ILACE_FIELD)
864 72 field_mode = 1;
865 }
866 } else {
867 787 fcm = PROGRESSIVE;
868 }
869
3/4
✓ Branch 0 taken 271 times.
✓ Branch 1 taken 603 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 271 times.
874 if (!v->first_pic_header_flag && v->field_mode != field_mode)
870 return AVERROR_INVALIDDATA;
871 874 v->field_mode = field_mode;
872 874 v->fcm = fcm;
873
874
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 874 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
874 av_assert0( v->s.mb_height == v->s.height + 15 >> 4
875 || v->s.mb_height == FFALIGN(v->s.height + 15 >> 4, 2));
876
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 802 times.
874 if (v->field_mode) {
877 72 v->s.mb_height = FFALIGN(v->s.height + 15 >> 4, 2);
878 72 v->fptype = get_bits(gb, 3);
879
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 36 times.
72 if (v->fptype & 4) // B-picture
880
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;
881 else
882
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 2 times.
36 v->s.pict_type = (v->fptype & 2) ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
883 } else {
884 802 v->s.mb_height = v->s.height + 15 >> 4;
885
4/6
✓ Branch 1 taken 524 times.
✓ Branch 2 taken 125 times.
✓ Branch 3 taken 17 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 136 times.
✗ Branch 6 not taken.
802 switch (get_unary(gb, 0, 4)) {
886 524 case 0:
887 524 v->s.pict_type = AV_PICTURE_TYPE_P;
888 524 break;
889 125 case 1:
890 125 v->s.pict_type = AV_PICTURE_TYPE_B;
891 125 break;
892 17 case 2:
893 17 v->s.pict_type = AV_PICTURE_TYPE_I;
894 17 break;
895 case 3:
896 v->s.pict_type = AV_PICTURE_TYPE_BI;
897 break;
898 136 case 4:
899 136 v->s.pict_type = AV_PICTURE_TYPE_P; // skipped pic
900 136 v->p_frame_skipped = 1;
901 136 break;
902 }
903 }
904
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 874 times.
874 if (v->tfcntrflag)
905 skip_bits(gb, 8);
906
1/2
✓ Branch 0 taken 874 times.
✗ Branch 1 not taken.
874 if (v->broadcast) {
907
3/4
✓ Branch 0 taken 87 times.
✓ Branch 1 taken 787 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 87 times.
874 if (!v->interlace || v->psf) {
908 787 v->rptfrm = get_bits(gb, 2);
909 } else {
910 87 v->tff = get_bits1(gb);
911 87 v->rff = get_bits1(gb);
912 }
913 } else {
914 v->tff = 1;
915 }
916
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 874 times.
874 if (v->panscanflag) {
917 avpriv_report_missing_feature(v->s.avctx, "Pan-scan");
918 //...
919 }
920
2/2
✓ Branch 0 taken 136 times.
✓ Branch 1 taken 738 times.
874 if (v->p_frame_skipped) {
921 136 return 0;
922 }
923 738 v->rnd = get_bits1(gb);
924
2/2
✓ Branch 0 taken 87 times.
✓ Branch 1 taken 651 times.
738 if (v->interlace)
925 87 v->uvsamp = get_bits1(gb);
926
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 666 times.
738 if (v->field_mode) {
927
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if (!v->refdist_flag)
928 v->refdist = 0;
929
3/4
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 36 times.
✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
72 else if ((v->s.pict_type != AV_PICTURE_TYPE_B) && (v->s.pict_type != AV_PICTURE_TYPE_BI)) {
930 36 v->refdist = get_bits(gb, 2);
931
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 if (v->refdist == 3)
932 v->refdist += get_unary(gb, 0, 14);
933
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 if (v->refdist > 16)
934 return AVERROR_INVALIDDATA;
935 }
936
3/4
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 36 times.
72 if ((v->s.pict_type == AV_PICTURE_TYPE_B) || (v->s.pict_type == AV_PICTURE_TYPE_BI)) {
937
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
36 if (read_bfraction(v, gb) < 0)
938 return AVERROR_INVALIDDATA;
939 36 v->frfd = (v->bfraction * v->refdist) >> 8;
940 36 v->brfd = v->refdist - v->frfd - 1;
941
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 if (v->brfd < 0)
942 v->brfd = 0;
943 }
944 72 goto parse_common_info;
945 }
946
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 651 times.
666 if (v->fcm == PROGRESSIVE) {
947
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 651 times.
651 if (v->finterpflag)
948 v->interpfrm = get_bits1(gb);
949
2/2
✓ Branch 0 taken 535 times.
✓ Branch 1 taken 116 times.
651 if (v->s.pict_type == AV_PICTURE_TYPE_B) {
950
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
116 if (read_bfraction(v, gb) < 0)
951 return AVERROR_INVALIDDATA;
952
1/2
✓ Branch 0 taken 116 times.
✗ Branch 1 not taken.
116 if (v->bfraction == 0) {
953 v->s.pict_type = AV_PICTURE_TYPE_BI; /* XXX: should not happen here */
954 }
955 }
956 }
957
958 666 parse_common_info:
959
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 666 times.
774 if (v->field_mode)
960 108 v->cur_field_type = !(v->tff ^ v->second_field);
961 774 pqindex = get_bits(gb, 5);
962
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 774 times.
774 if (!pqindex)
963 return -1;
964
2/2
✓ Branch 0 taken 497 times.
✓ Branch 1 taken 277 times.
774 if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
965 497 v->pq = ff_vc1_pquant_table[0][pqindex];
966 else
967 277 v->pq = ff_vc1_pquant_table[1][pqindex];
968 774 v->pqindex = pqindex;
969
2/2
✓ Branch 0 taken 739 times.
✓ Branch 1 taken 35 times.
774 if (pqindex < 9)
970 739 v->halfpq = get_bits1(gb);
971 else
972 35 v->halfpq = 0;
973
2/4
✓ Branch 0 taken 497 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 277 times.
774 switch (v->quantizer_mode) {
974 497 case QUANT_FRAME_IMPLICIT:
975 497 v->pquantizer = pqindex < 9;
976 497 break;
977 case QUANT_NON_UNIFORM:
978 v->pquantizer = 0;
979 break;
980 case QUANT_FRAME_EXPLICIT:
981 v->pquantizer = get_bits1(gb);
982 break;
983 277 default:
984 277 v->pquantizer = 1;
985 277 break;
986 }
987 774 v->dquantfrm = 0;
988
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 774 times.
774 if (v->postprocflag)
989 v->postproc = get_bits(gb, 2);
990
991
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 538 times.
774 if (v->parse_only)
992 236 return 0;
993
994
2/2
✓ Branch 0 taken 231 times.
✓ Branch 1 taken 307 times.
538 if (v->first_pic_header_flag)
995 231 rotate_luts(v);
996
997
3/4
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 430 times.
✓ Branch 2 taken 98 times.
✗ Branch 3 not taken.
538 switch (v->s.pict_type) {
998 10 case AV_PICTURE_TYPE_I:
999 case AV_PICTURE_TYPE_BI:
1000
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9 times.
10 if (v->fcm == ILACE_FRAME) { //interlace frame picture
1001 1 status = bitplane_decoding(v->fieldtx_plane, &v->fieldtx_is_raw, v);
1002
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (status < 0)
1003 return -1;
1004 1 av_log(v->s.avctx, AV_LOG_DEBUG, "FIELDTX plane encoding: "
1005 "Imode: %i, Invert: %i\n", status>>1, status&1);
1006 } else
1007 9 v->fieldtx_is_raw = 0;
1008 10 status = bitplane_decoding(v->acpred_plane, &v->acpred_is_raw, v);
1009
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (status < 0)
1010 return -1;
1011 10 av_log(v->s.avctx, AV_LOG_DEBUG, "ACPRED plane encoding: "
1012 "Imode: %i, Invert: %i\n", status>>1, status&1);
1013 10 v->condover = CONDOVER_NONE;
1014
3/4
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
10 if (v->overlap && v->pq <= 8) {
1015 7 v->condover = decode012(gb);
1016
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 5 times.
7 if (v->condover == CONDOVER_SELECT) {
1017 2 status = bitplane_decoding(v->over_flags_plane, &v->overflg_is_raw, v);
1018
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (status < 0)
1019 return -1;
1020 2 av_log(v->s.avctx, AV_LOG_DEBUG, "CONDOVER plane encoding: "
1021 "Imode: %i, Invert: %i\n", status>>1, status&1);
1022 }
1023 }
1024 10 break;
1025 430 case AV_PICTURE_TYPE_P:
1026
2/2
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 395 times.
430 if (v->field_mode) {
1027 35 v->numref = get_bits1(gb);
1028
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
35 if (!v->numref) {
1029 v->reffield = get_bits1(gb);
1030 v->ref_field_type[0] = v->reffield ^ !v->cur_field_type;
1031 }
1032 }
1033
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 364 times.
430 if (v->extended_mv)
1034 66 v->mvrange = get_unary(gb, 0, 3);
1035 else
1036 364 v->mvrange = 0;
1037
2/2
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 393 times.
430 if (v->interlace) {
1038
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37 times.
37 if (v->extended_dmv)
1039 v->dmvrange = get_unary(gb, 0, 3);
1040 else
1041 37 v->dmvrange = 0;
1042
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 35 times.
37 if (v->fcm == ILACE_FRAME) { // interlaced frame picture
1043 2 v->fourmvswitch = get_bits1(gb);
1044 2 v->intcomp = get_bits1(gb);
1045
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (v->intcomp) {
1046 v->lumscale = get_bits(gb, 6);
1047 v->lumshift = get_bits(gb, 6);
1048 INIT_LUT(v->lumscale, v->lumshift, v->last_luty[0], v->last_lutuv[0], 1);
1049 INIT_LUT(v->lumscale, v->lumshift, v->last_luty[1], v->last_lutuv[1], 1);
1050 v->last_use_ic = 1;
1051 }
1052 2 status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
1053
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (status < 0)
1054 return -1;
1055 2 av_log(v->s.avctx, AV_LOG_DEBUG, "SKIPMB plane encoding: "
1056 "Imode: %i, Invert: %i\n", status>>1, status&1);
1057 2 v->mbmodetab = get_bits(gb, 2);
1058
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (v->fourmvswitch)
1059 2 v->mbmode_vlc = &ff_vc1_intfr_4mv_mbmode_vlc[v->mbmodetab];
1060 else
1061 v->mbmode_vlc = &ff_vc1_intfr_non4mv_mbmode_vlc[v->mbmodetab];
1062 2 v->imvtab = get_bits(gb, 2);
1063 2 v->imv_vlc = &ff_vc1_1ref_mvdata_vlc[v->imvtab];
1064 // interlaced p-picture cbpcy range is [1, 63]
1065 2 v->icbptab = get_bits(gb, 3);
1066 2 v->cbpcy_vlc = &ff_vc1_icbpcy_vlc[v->icbptab];
1067 2 v->twomvbptab = get_bits(gb, 2);
1068 2 v->twomvbp_vlc = &ff_vc1_2mv_block_pattern_vlc[v->twomvbptab];
1069
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (v->fourmvswitch) {
1070 2 v->fourmvbptab = get_bits(gb, 2);
1071 2 v->fourmvbp_vlc = &ff_vc1_4mv_block_pattern_vlc[v->fourmvbptab];
1072 }
1073 }
1074 }
1075 430 v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
1076 430 v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
1077 430 v->range_x = 1 << (v->k_x - 1);
1078 430 v->range_y = 1 << (v->k_y - 1);
1079
1080 430 v->tt_index = (v->pq > 4) + (v->pq > 12);
1081
2/2
✓ Branch 0 taken 428 times.
✓ Branch 1 taken 2 times.
430 if (v->fcm != ILACE_FRAME) {
1082 int mvmode;
1083 428 mvmode = get_unary(gb, 1, 4);
1084 428 lowquant = (v->pq > 12) ? 0 : 1;
1085 428 v->mv_mode = ff_vc1_mv_pmode_table[lowquant][mvmode];
1086
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 428 times.
428 if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
1087 int mvmode2;
1088 mvmode2 = get_unary(gb, 1, 3);
1089 v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][mvmode2];
1090 if (v->field_mode) {
1091 v->intcompfield = decode210(gb) ^ 3;
1092 } else
1093 v->intcompfield = 3;
1094
1095 v->lumscale2 = v->lumscale = 32;
1096 v->lumshift2 = v->lumshift = 0;
1097 if (v->intcompfield & 1) {
1098 v->lumscale = get_bits(gb, 6);
1099 v->lumshift = get_bits(gb, 6);
1100 }
1101 if ((v->intcompfield & 2) && v->field_mode) {
1102 v->lumscale2 = get_bits(gb, 6);
1103 v->lumshift2 = get_bits(gb, 6);
1104 } else if(!v->field_mode) {
1105 v->lumscale2 = v->lumscale;
1106 v->lumshift2 = v->lumshift;
1107 }
1108 if (v->field_mode && v->second_field) {
1109 if (v->cur_field_type) {
1110 INIT_LUT(v->lumscale , v->lumshift , v->curr_luty[v->cur_field_type^1], v->curr_lutuv[v->cur_field_type^1], 0);
1111 INIT_LUT(v->lumscale2, v->lumshift2, v->last_luty[v->cur_field_type ], v->last_lutuv[v->cur_field_type ], 1);
1112 } else {
1113 INIT_LUT(v->lumscale2, v->lumshift2, v->curr_luty[v->cur_field_type^1], v->curr_lutuv[v->cur_field_type^1], 0);
1114 INIT_LUT(v->lumscale , v->lumshift , v->last_luty[v->cur_field_type ], v->last_lutuv[v->cur_field_type ], 1);
1115 }
1116 v->next_use_ic = *v->curr_use_ic = 1;
1117 } else {
1118 INIT_LUT(v->lumscale , v->lumshift , v->last_luty[0], v->last_lutuv[0], 1);
1119 INIT_LUT(v->lumscale2, v->lumshift2, v->last_luty[1], v->last_lutuv[1], 1);
1120 }
1121 v->last_use_ic = 1;
1122 }
1123 428 v->qs_last = v->s.quarter_sample;
1124
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 428 times.
428 if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
1125 v->s.quarter_sample = (v->mv_mode2 != MV_PMODE_1MV_HPEL &&
1126 v->mv_mode2 != MV_PMODE_1MV_HPEL_BILIN);
1127 v->s.mspel = (v->mv_mode2 != MV_PMODE_1MV_HPEL_BILIN);
1128 } else {
1129
1/2
✓ Branch 0 taken 428 times.
✗ Branch 1 not taken.
856 v->s.quarter_sample = (v->mv_mode != MV_PMODE_1MV_HPEL &&
1130
2/2
✓ Branch 0 taken 424 times.
✓ Branch 1 taken 4 times.
428 v->mv_mode != MV_PMODE_1MV_HPEL_BILIN);
1131 428 v->s.mspel = (v->mv_mode != MV_PMODE_1MV_HPEL_BILIN);
1132 }
1133 }
1134
2/2
✓ Branch 0 taken 393 times.
✓ Branch 1 taken 37 times.
430 if (v->fcm == PROGRESSIVE) { // progressive
1135
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 393 times.
393 if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
1136 v->mv_mode2 == MV_PMODE_MIXED_MV)
1137
2/2
✓ Branch 0 taken 333 times.
✓ Branch 1 taken 60 times.
393 || v->mv_mode == MV_PMODE_MIXED_MV) {
1138 333 status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v);
1139
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 333 times.
333 if (status < 0)
1140 return -1;
1141 333 av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
1142 "Imode: %i, Invert: %i\n", status>>1, status&1);
1143 } else {
1144 60 v->mv_type_is_raw = 0;
1145 60 memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height);
1146 }
1147 393 status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
1148
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 393 times.
393 if (status < 0)
1149 return -1;
1150 393 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
1151 "Imode: %i, Invert: %i\n", status>>1, status&1);
1152
1153 /* Hopefully this is correct for P-frames */
1154 393 v->s.mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables
1155 393 v->cbptab = get_bits(gb, 2);
1156 393 v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[v->cbptab];
1157
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 35 times.
37 } else if (v->fcm == ILACE_FRAME) { // frame interlaced
1158 2 v->qs_last = v->s.quarter_sample;
1159 2 v->s.quarter_sample = 1;
1160 2 v->s.mspel = 1;
1161 } else { // field interlaced
1162 35 v->mbmodetab = get_bits(gb, 3);
1163 35 v->imvtab = get_bits(gb, 2 + v->numref);
1164
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
35 if (!v->numref)
1165 v->imv_vlc = &ff_vc1_1ref_mvdata_vlc[v->imvtab];
1166 else
1167 35 v->imv_vlc = &ff_vc1_2ref_mvdata_vlc[v->imvtab];
1168 35 v->icbptab = get_bits(gb, 3);
1169 35 v->cbpcy_vlc = &ff_vc1_icbpcy_vlc[v->icbptab];
1170
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
35 if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
1171
2/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 31 times.
✓ Branch 3 taken 4 times.
35 v->mv_mode2 == MV_PMODE_MIXED_MV) || v->mv_mode == MV_PMODE_MIXED_MV) {
1172 31 v->fourmvbptab = get_bits(gb, 2);
1173 31 v->fourmvbp_vlc = &ff_vc1_4mv_block_pattern_vlc[v->fourmvbptab];
1174 31 v->mbmode_vlc = &ff_vc1_if_mmv_mbmode_vlc[v->mbmodetab];
1175 } else {
1176 4 v->mbmode_vlc = &ff_vc1_if_1mv_mbmode_vlc[v->mbmodetab];
1177 }
1178 }
1179
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 424 times.
430 if (v->dquant) {
1180 6 av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
1181 6 vop_dquant_decoding(v);
1182 }
1183
1184
2/2
✓ Branch 0 taken 416 times.
✓ Branch 1 taken 14 times.
430 if (v->vstransform) {
1185 416 v->ttmbf = get_bits1(gb);
1186
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 416 times.
416 if (v->ttmbf) {
1187 v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
1188 } else
1189 416 v->ttfrm = 0; //FIXME Is that so ?
1190 } else {
1191 14 v->ttmbf = 1;
1192 14 v->ttfrm = TT_8X8;
1193 }
1194 430 break;
1195 98 case AV_PICTURE_TYPE_B:
1196
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 94 times.
98 if (v->fcm == ILACE_FRAME) {
1197
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 if (read_bfraction(v, gb) < 0)
1198 return AVERROR_INVALIDDATA;
1199
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (v->bfraction == 0) {
1200 return -1;
1201 }
1202 }
1203
2/2
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 28 times.
98 if (v->extended_mv)
1204 70 v->mvrange = get_unary(gb, 0, 3);
1205 else
1206 28 v->mvrange = 0;
1207 98 v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
1208 98 v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
1209 98 v->range_x = 1 << (v->k_x - 1);
1210 98 v->range_y = 1 << (v->k_y - 1);
1211
1212 98 v->tt_index = (v->pq > 4) + (v->pq > 12);
1213
1214
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 62 times.
98 if (v->field_mode) {
1215 int mvmode;
1216 36 av_log(v->s.avctx, AV_LOG_DEBUG, "B Fields\n");
1217
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 if (v->extended_dmv)
1218 v->dmvrange = get_unary(gb, 0, 3);
1219 36 mvmode = get_unary(gb, 1, 3);
1220 36 lowquant = (v->pq > 12) ? 0 : 1;
1221 36 v->mv_mode = ff_vc1_mv_pmode_table2[lowquant][mvmode];
1222 36 v->qs_last = v->s.quarter_sample;
1223
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);
1224 36 v->s.mspel = (v->mv_mode != MV_PMODE_1MV_HPEL_BILIN);
1225 36 status = bitplane_decoding(v->forward_mb_plane, &v->fmb_is_raw, v);
1226
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 if (status < 0)
1227 return -1;
1228 36 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Forward Type plane encoding: "
1229 "Imode: %i, Invert: %i\n", status>>1, status&1);
1230 36 v->mbmodetab = get_bits(gb, 3);
1231
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 8 times.
36 if (v->mv_mode == MV_PMODE_MIXED_MV)
1232 28 v->mbmode_vlc = &ff_vc1_if_mmv_mbmode_vlc[v->mbmodetab];
1233 else
1234 8 v->mbmode_vlc = &ff_vc1_if_1mv_mbmode_vlc[v->mbmodetab];
1235 36 v->imvtab = get_bits(gb, 3);
1236 36 v->imv_vlc = &ff_vc1_2ref_mvdata_vlc[v->imvtab];
1237 36 v->icbptab = get_bits(gb, 3);
1238 36 v->cbpcy_vlc = &ff_vc1_icbpcy_vlc[v->icbptab];
1239
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 8 times.
36 if (v->mv_mode == MV_PMODE_MIXED_MV) {
1240 28 v->fourmvbptab = get_bits(gb, 2);
1241 28 v->fourmvbp_vlc = &ff_vc1_4mv_block_pattern_vlc[v->fourmvbptab];
1242 }
1243 36 v->numref = 1; // interlaced field B pictures are always 2-ref
1244
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 58 times.
62 } else if (v->fcm == ILACE_FRAME) {
1245
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (v->extended_dmv)
1246 v->dmvrange = get_unary(gb, 0, 3);
1247
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 if (get_bits1(gb)) /* intcomp - present but shall always be 0 */
1248 av_log(v->s.avctx, AV_LOG_WARNING, "Intensity compensation set for B picture\n");
1249 4 v->intcomp = 0;
1250 4 v->mv_mode = MV_PMODE_1MV;
1251 4 v->fourmvswitch = 0;
1252 4 v->qs_last = v->s.quarter_sample;
1253 4 v->s.quarter_sample = 1;
1254 4 v->s.mspel = 1;
1255 4 status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);
1256
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (status < 0)
1257 return -1;
1258 4 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "
1259 "Imode: %i, Invert: %i\n", status>>1, status&1);
1260 4 status = bitplane_decoding(v->s.mbskip_table, &v->skip_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 Skip plane encoding: "
1264 "Imode: %i, Invert: %i\n", status>>1, status&1);
1265 4 v->mbmodetab = get_bits(gb, 2);
1266 4 v->mbmode_vlc = &ff_vc1_intfr_non4mv_mbmode_vlc[v->mbmodetab];
1267 4 v->imvtab = get_bits(gb, 2);
1268 4 v->imv_vlc = &ff_vc1_1ref_mvdata_vlc[v->imvtab];
1269 // interlaced p/b-picture cbpcy range is [1, 63]
1270 4 v->icbptab = get_bits(gb, 3);
1271 4 v->cbpcy_vlc = &ff_vc1_icbpcy_vlc[v->icbptab];
1272 4 v->twomvbptab = get_bits(gb, 2);
1273 4 v->twomvbp_vlc = &ff_vc1_2mv_block_pattern_vlc[v->twomvbptab];
1274 4 v->fourmvbptab = get_bits(gb, 2);
1275 4 v->fourmvbp_vlc = &ff_vc1_4mv_block_pattern_vlc[v->fourmvbptab];
1276 } else {
1277 58 v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;
1278 58 v->qs_last = v->s.quarter_sample;
1279 58 v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV);
1280 58 v->s.mspel = v->s.quarter_sample;
1281 58 status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);
1282
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
58 if (status < 0)
1283 return -1;
1284 58 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "
1285 "Imode: %i, Invert: %i\n", status>>1, status&1);
1286 58 status = bitplane_decoding(v->s.mbskip_table, &v->skip_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 Skip plane encoding: "
1290 "Imode: %i, Invert: %i\n", status>>1, status&1);
1291 58 v->s.mv_table_index = get_bits(gb, 2);
1292 58 v->cbptab = get_bits(gb, 2);
1293 58 v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[v->cbptab];
1294 }
1295
1296
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 86 times.
98 if (v->dquant) {
1297 12 av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
1298 12 vop_dquant_decoding(v);
1299 }
1300
1301
1/2
✓ Branch 0 taken 98 times.
✗ Branch 1 not taken.
98 if (v->vstransform) {
1302 98 v->ttmbf = get_bits1(gb);
1303
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 98 times.
98 if (v->ttmbf) {
1304 v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
1305 } else
1306 98 v->ttfrm = 0;
1307 } else {
1308 v->ttmbf = 1;
1309 v->ttfrm = TT_8X8;
1310 }
1311 98 break;
1312 }
1313
1314
1315 /* AC Syntax */
1316 538 v->c_ac_table_index = decode012(gb);
1317
3/4
✓ Branch 0 taken 528 times.
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 528 times.
538 if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI) {
1318 10 v->y_ac_table_index = decode012(gb);
1319 }
1320
4/4
✓ Branch 0 taken 77 times.
✓ Branch 1 taken 451 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 65 times.
528 else if (v->fcm != PROGRESSIVE && !v->s.quarter_sample) {
1321 12 v->range_x <<= 1;
1322 12 v->range_y <<= 1;
1323 }
1324
1325 /* DC Syntax */
1326 538 v->s.dc_table_index = get_bits1(gb);
1327
3/4
✓ Branch 0 taken 528 times.
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 528 times.
538 if ((v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)
1328
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9 times.
10 && v->dquant) {
1329 1 av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
1330 1 vop_dquant_decoding(v);
1331 }
1332
1333 538 v->bi_type = (v->s.pict_type == AV_PICTURE_TYPE_BI);
1334
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 538 times.
538 if (v->bi_type)
1335 v->s.pict_type = AV_PICTURE_TYPE_B;
1336
1337 538 return 0;
1338 }
1339