FFmpeg
Loading...
Searching...
No Matches
vc1.c
Go to the documentation of this file.
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 */
50static void decode_rowskip(uint8_t* plane, int width, int height, int stride,
51 GetBitContext *gb)
52{
53 int x, y;
54
55 for (y = 0; y < height; y++) {
56 if (!get_bits1(gb)) //rowskip
57 memset(plane, 0, width);
58 else
59 for (x = 0; x < width; x++)
60 plane[x] = get_bits1(gb);
61 plane += stride;
62 }
63}
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 */
72static void decode_colskip(uint8_t* plane, int width, int height, int stride,
73 GetBitContext *gb)
74{
75 int x, y;
76
77 for (x = 0; x < width; x++) {
78 if (!get_bits1(gb)) //colskip
79 for (y = 0; y < height; y++)
80 plane[y*stride] = 0;
81 else
82 for (y = 0; y < height; y++)
83 plane[y*stride] = get_bits1(gb);
84 plane ++;
85 }
86}
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 */
95static int bitplane_decoding(uint8_t* data, int *raw_flag, VC1Context *v)
96{
97 GetBitContext *const gb = &v->gb;
98
99 int imode, x, y, code, offset;
100 uint8_t invert, *planep = data;
101 int width, height, stride;
102
103 width = v->s.mb_width;
104 height = v->s.mb_height >> v->field_mode;
105 stride = v->s.mb_stride;
106 invert = get_bits1(gb);
108
109 *raw_flag = 0;
110 switch (imode) {
111 case IMODE_RAW:
112 //Data is actually read in the MB layer (same for all tests == "raw")
113 *raw_flag = 1; //invert ignored
114 return invert;
115 case IMODE_DIFF2:
116 case IMODE_NORM2:
117 if ((height * width) & 1) {
118 *planep++ = get_bits1(gb);
119 y = offset = 1;
120 if (offset == width) {
121 offset = 0;
122 planep += stride - width;
123 }
124 }
125 else
126 y = offset = 0;
127 // decode bitplane as one long line
128 for (; y < height * width; y += 2) {
130 *planep++ = code & 1;
131 offset++;
132 if (offset == width) {
133 offset = 0;
134 planep += stride - width;
135 }
136 *planep++ = code >> 1;
137 offset++;
138 if (offset == width) {
139 offset = 0;
140 planep += stride - width;
141 }
142 }
143 break;
144 case IMODE_DIFF6:
145 case IMODE_NORM6:
146 if (!(height % 3) && (width % 3)) { // use 2x3 decoding
147 for (y = 0; y < height; y += 3) {
148 for (x = width & 1; x < width; x += 2) {
150 if (code < 0) {
151 av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");
152 return -1;
153 }
154 planep[x + 0] = (code >> 0) & 1;
155 planep[x + 1] = (code >> 1) & 1;
156 planep[x + 0 + stride] = (code >> 2) & 1;
157 planep[x + 1 + stride] = (code >> 3) & 1;
158 planep[x + 0 + stride * 2] = (code >> 4) & 1;
159 planep[x + 1 + stride * 2] = (code >> 5) & 1;
160 }
161 planep += stride * 3;
162 }
163 if (width & 1)
165 } else { // 3x2
166 planep += (height & 1) * stride;
167 for (y = height & 1; y < height; y += 2) {
168 for (x = width % 3; x < width; x += 3) {
170 if (code < 0) {
171 av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");
172 return -1;
173 }
174 planep[x + 0] = (code >> 0) & 1;
175 planep[x + 1] = (code >> 1) & 1;
176 planep[x + 2] = (code >> 2) & 1;
177 planep[x + 0 + stride] = (code >> 3) & 1;
178 planep[x + 1 + stride] = (code >> 4) & 1;
179 planep[x + 2 + stride] = (code >> 5) & 1;
180 }
181 planep += stride * 2;
182 }
183 x = width % 3;
184 if (x)
186 if (height & 1)
187 decode_rowskip(data + x, width - x, 1, stride, &v->gb);
188 }
189 break;
190 case IMODE_ROWSKIP:
192 break;
193 case IMODE_COLSKIP:
195 break;
196 default:
197 break;
198 }
199
200 /* Applying diff operator */
201 if (imode == IMODE_DIFF2 || imode == IMODE_DIFF6) {
202 planep = data;
203 planep[0] ^= invert;
204 for (x = 1; x < width; x++)
205 planep[x] ^= planep[x-1];
206 for (y = 1; y < height; y++) {
207 planep += stride;
208 planep[0] ^= planep[-stride];
209 for (x = 1; x < width; x++) {
210 if (planep[x-1] != planep[x-stride]) planep[x] ^= invert;
211 else planep[x] ^= planep[x-1];
212 }
213 }
214 } else if (invert) {
215 planep = data;
216 for (x = 0; x < stride * height; x++)
217 planep[x] = !planep[x]; //FIXME stride
218 }
219 return (imode << 1) + invert;
220}
221
222/** @} */ //Bitplane group
223
224/***********************************************************************/
225/** VOP Dquant decoding
226 * @param v VC-1 Context
227 */
229{
230 GetBitContext *const gb = &v->gb;
231 int pqdiff;
232
233 //variable size
234 if (v->dquant != 2) {
235 v->dquantfrm = get_bits1(gb);
236 if (!v->dquantfrm)
237 return 0;
238
239 v->dqprofile = get_bits(gb, 2);
240 switch (v->dqprofile) {
243 v->dqsbedge = get_bits(gb, 2);
244 break;
246 v->dqbilevel = get_bits1(gb);
247 if (!v->dqbilevel) {
248 v->halfpq = 0;
249 return 0;
250 }
251 break;
252 default:
253 break; //Forbidden ?
254 }
255 }
256
257 pqdiff = get_bits(gb, 3);
258 if (pqdiff == 7)
259 v->altpq = get_bits(gb, 5);
260 else
261 v->altpq = v->pq + pqdiff + 1;
262
263 return 0;
264}
265
267
268/**
269 * Decode Simple/Main Profiles sequence header
270 * @see Figure 7-8, p16-17
271 * @param avctx Codec context
272 * @param gb GetBit context initialized from Codec context extra_data
273 * @return Status
274 */
276{
277 av_log(avctx, AV_LOG_DEBUG, "Header: %0X\n", show_bits_long(gb, 32));
278 v->profile = get_bits(gb, 2);
279 if (v->profile == PROFILE_COMPLEX) {
280 av_log(avctx, AV_LOG_WARNING, "WMV3 Complex Profile is not fully supported\n");
281 }
282
283 if (v->profile == PROFILE_ADVANCED) {
286 return decode_sequence_header_adv(v, gb);
287 } else {
288 v->chromaformat = 1;
291 v->res_y411 = get_bits1(gb);
292 v->res_sprite = get_bits1(gb);
293 if (v->res_y411) {
294 av_log(avctx, AV_LOG_ERROR,
295 "Old interlaced mode is not supported\n");
296 return -1;
297 }
298 }
299
300 // (fps-2)/4 (->30)
301 v->frmrtq_postproc = get_bits(gb, 3); //common
302 // (bitrate-32kbps)/64kbps
303 v->bitrtq_postproc = get_bits(gb, 5); //common
304 v->loop_filter = get_bits1(gb); //common
305 if (v->loop_filter == 1 && v->profile == PROFILE_SIMPLE) {
306 av_log(avctx, AV_LOG_ERROR,
307 "LOOPFILTER shall not be enabled in Simple Profile\n");
308 }
310 v->loop_filter = 0;
311
312 v->res_x8 = get_bits1(gb); //reserved
313 v->multires = get_bits1(gb);
314 v->res_fasttx = get_bits1(gb);
315
316 v->fastuvmc = get_bits1(gb); //common
317 if (!v->profile && !v->fastuvmc) {
318 av_log(avctx, AV_LOG_ERROR,
319 "FASTUVMC unavailable in Simple Profile\n");
320 return -1;
321 }
322 v->extended_mv = get_bits1(gb); //common
323 if (!v->profile && v->extended_mv) {
324 av_log(avctx, AV_LOG_ERROR,
325 "Extended MVs unavailable in Simple Profile\n");
326 return -1;
327 }
328 v->dquant = get_bits(gb, 2); //common
329 v->vstransform = get_bits1(gb); //common
330
331 v->res_transtab = get_bits1(gb);
332 if (v->res_transtab) {
333 av_log(avctx, AV_LOG_ERROR,
334 "1 for reserved RES_TRANSTAB is forbidden\n");
335 return -1;
336 }
337
338 v->overlap = get_bits1(gb); //common
339
340 v->resync_marker = get_bits1(gb);
341 v->rangered = get_bits1(gb);
342 if (v->rangered && v->profile == PROFILE_SIMPLE) {
343 av_log(avctx, AV_LOG_INFO,
344 "RANGERED should be set to 0 in Simple Profile\n");
345 }
346
347 v->max_b_frames = avctx->max_b_frames = get_bits(gb, 3); //common
348 v->quantizer_mode = get_bits(gb, 2); //common
349
350 v->finterpflag = get_bits1(gb); //common
351
352 if (v->res_sprite) {
353 int w = get_bits(gb, 11);
354 int h = get_bits(gb, 11);
355 int ret = ff_set_dimensions(v->s.avctx, w, h);
356 if (ret < 0) {
357 av_log(avctx, AV_LOG_ERROR, "Failed to set dimensions %d %d\n", w, h);
358 return ret;
359 }
360 skip_bits(gb, 5); //frame rate
361 v->res_x8 = get_bits1(gb);
362 if (get_bits1(gb)) { // something to do with DC VLC selection
363 av_log(avctx, AV_LOG_ERROR, "Unsupported sprite feature\n");
364 return -1;
365 }
366 skip_bits(gb, 3); //slice code
367 v->res_rtm_flag = 0;
368 } else {
369 v->res_rtm_flag = get_bits1(gb); //reserved
370 }
371 //TODO: figure out what they mean (always 0x402F)
372 if (!v->res_fasttx)
373 skip_bits(gb, 16);
374 av_log(avctx, AV_LOG_DEBUG,
375 "Profile %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n"
376 "LoopFilter=%i, MultiRes=%i, FastUVMC=%i, Extended MV=%i\n"
377 "Rangered=%i, VSTransform=%i, Overlap=%i, SyncMarker=%i\n"
378 "DQuant=%i, Quantizer mode=%i, Max B-frames=%i\n",
382 v->dquant, v->quantizer_mode, avctx->max_b_frames);
383 return 0;
384}
385
387{
388 v->res_rtm_flag = 1;
389 v->level = get_bits(gb, 3);
390 if (v->level >= 5) {
391 av_log(v->s.avctx, AV_LOG_ERROR, "Reserved LEVEL %i\n",v->level);
392 }
393 v->chromaformat = get_bits(gb, 2);
394 if (v->chromaformat != 1) {
396 "Only 4:2:0 chroma format supported\n");
397 return -1;
398 }
399
400 // (fps-2)/4 (->30)
401 v->frmrtq_postproc = get_bits(gb, 3); //common
402 // (bitrate-32kbps)/64kbps
403 v->bitrtq_postproc = get_bits(gb, 5); //common
404 v->postprocflag = get_bits1(gb); //common
405
406 v->max_coded_width = (get_bits(gb, 12) + 1) << 1;
407 v->max_coded_height = (get_bits(gb, 12) + 1) << 1;
408 v->broadcast = get_bits1(gb);
409 v->interlace = get_bits1(gb);
410 v->tfcntrflag = get_bits1(gb);
411 v->finterpflag = get_bits1(gb);
412 skip_bits1(gb); // reserved
413
415 "Advanced Profile level %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n"
416 "LoopFilter=%i, ChromaFormat=%i, Pulldown=%i, Interlace: %i\n"
417 "TFCTRflag=%i, FINTERPflag=%i\n",
420 v->tfcntrflag, v->finterpflag);
421
422 v->psf = get_bits1(gb);
423 if (v->psf) { //PsF, 6.1.13
424 av_log(v->s.avctx, AV_LOG_ERROR, "Progressive Segmented Frame mode: not supported (yet)\n");
425 return -1;
426 }
427 v->max_b_frames = v->s.avctx->max_b_frames = 7;
428 if (get_bits1(gb)) { //Display Info - decoding is not affected by it
429 int w, h, ar = 0;
430 av_log(v->s.avctx, AV_LOG_DEBUG, "Display extended info:\n");
431 w = get_bits(gb, 14) + 1;
432 h = get_bits(gb, 14) + 1;
433 av_log(v->s.avctx, AV_LOG_DEBUG, "Display dimensions: %ix%i\n", w, h);
434 if (get_bits1(gb))
435 ar = get_bits(gb, 4);
436 if (ar && ar < 14) {
438 } else if (ar == 15) {
439 w = get_bits(gb, 8) + 1;
440 h = get_bits(gb, 8) + 1;
442 } else {
443 if (v->s.avctx->width > v->max_coded_width ||
444 v->s.avctx->height > v->max_coded_height) {
445 avpriv_request_sample(v->s.avctx, "Huge resolution");
446 } else
449 v->s.avctx->height * w,
450 v->s.avctx->width * h,
451 1 << 30);
452 }
454 av_log(v->s.avctx, AV_LOG_DEBUG, "Aspect: %i:%i\n",
457
458 if (get_bits1(gb)) { //framerate stuff
459 if (get_bits1(gb)) {
460 v->s.avctx->framerate.den = 32;
461 v->s.avctx->framerate.num = get_bits(gb, 16) + 1;
462 } else {
463 int nr, dr;
464 nr = get_bits(gb, 8);
465 dr = get_bits(gb, 4);
466 if (nr > 0 && nr < 8 && dr > 0 && dr < 3) {
467 v->s.avctx->framerate.den = ff_vc1_fps_dr[dr - 1];
468 v->s.avctx->framerate.num = ff_vc1_fps_nr[nr - 1] * 1000;
469 }
470 }
471 }
472
473 if (get_bits1(gb)) {
474 v->color_prim = get_bits(gb, 8);
475 v->transfer_char = get_bits(gb, 8);
476 v->matrix_coef = get_bits(gb, 8);
477 }
478 }
479
480 v->hrd_param_flag = get_bits1(gb);
481 if (v->hrd_param_flag) {
482 int i;
484 skip_bits(gb, 4); //bitrate exponent
485 skip_bits(gb, 4); //buffer size exponent
486 for (i = 0; i < v->hrd_num_leaky_buckets; i++) {
487 skip_bits(gb, 16); //hrd_rate[n]
488 skip_bits(gb, 16); //hrd_buffer[n]
489 }
490 }
491 return 0;
492}
493
495{
496 int i;
497 int w,h;
498 int ret;
499
500 av_log(avctx, AV_LOG_DEBUG, "Entry point: %08X\n", show_bits_long(gb, 32));
501 v->broken_link = get_bits1(gb);
502 v->closed_entry = get_bits1(gb);
503 v->panscanflag = get_bits1(gb);
504 v->refdist_flag = get_bits1(gb);
505 v->loop_filter = get_bits1(gb);
507 v->loop_filter = 0;
508 v->fastuvmc = get_bits1(gb);
509 v->extended_mv = get_bits1(gb);
510 v->dquant = get_bits(gb, 2);
511 v->vstransform = get_bits1(gb);
512 v->overlap = get_bits1(gb);
513 v->quantizer_mode = get_bits(gb, 2);
514
515 if (v->hrd_param_flag) {
516 for (i = 0; i < v->hrd_num_leaky_buckets; i++) {
517 skip_bits(gb, 8); //hrd_full[n]
518 }
519 }
520
521 if(get_bits1(gb)){
522 w = (get_bits(gb, 12)+1)<<1;
523 h = (get_bits(gb, 12)+1)<<1;
524 } else {
525 w = v->max_coded_width;
526 h = v->max_coded_height;
527 }
528 if ((ret = ff_set_dimensions(avctx, w, h)) < 0) {
529 av_log(avctx, AV_LOG_ERROR, "Failed to set dimensions %d %d\n", w, h);
530 return ret;
531 }
532
533 if (v->extended_mv)
534 v->extended_dmv = get_bits1(gb);
535 if ((v->range_mapy_flag = get_bits1(gb))) {
536 av_log(avctx, AV_LOG_ERROR, "Luma scaling is not supported, expect wrong picture\n");
537 v->range_mapy = get_bits(gb, 3);
538 }
539 if ((v->range_mapuv_flag = get_bits1(gb))) {
540 av_log(avctx, AV_LOG_ERROR, "Chroma scaling is not supported, expect wrong picture\n");
541 v->range_mapuv = get_bits(gb, 3);
542 }
543
544 av_log(avctx, AV_LOG_DEBUG, "Entry point info:\n"
545 "BrokenLink=%i, ClosedEntry=%i, PanscanFlag=%i\n"
546 "RefDist=%i, Postproc=%i, FastUVMC=%i, ExtMV=%i\n"
547 "DQuant=%i, VSTransform=%i, Overlap=%i, Qmode=%i\n",
550
551 return 0;
552}
553
554/* fill lookup tables for intensity compensation */
555#define INIT_LUT(lumscale, lumshift, luty, lutuv, chain) do { \
556 int scale, shift, i; \
557 if (!lumscale) { \
558 scale = -64; \
559 shift = (255 - lumshift * 2) * 64; \
560 if (lumshift > 31) \
561 shift += 128 << 6; \
562 } else { \
563 scale = lumscale + 32; \
564 if (lumshift > 31) \
565 shift = (lumshift - 64) * 64; \
566 else \
567 shift = lumshift << 6; \
568 } \
569 for (i = 0; i < 256; i++) { \
570 int iy = chain ? luty[i] : i; \
571 int iu = chain ? lutuv[i] : i; \
572 luty[i] = av_clip_uint8((scale * iy + shift + 32) >> 6); \
573 lutuv[i] = av_clip_uint8((scale * (iu - 128) + 128*64 + 32) >> 6);\
574 } \
575 } while(0)
576
577static void rotate_luts(VC1Context *v)
578{
580 v->curr_use_ic = &v->aux_use_ic;
581 v->curr_luty = v->aux_luty;
582 v->curr_lutuv = v->aux_lutuv;
583 } else {
584#define ROTATE(DEF, L, N, C) do { \
585 DEF; \
586 memcpy(&tmp, L , sizeof(tmp)); \
587 memcpy(L , N , sizeof(tmp)); \
588 memcpy(N , &tmp, sizeof(tmp)); \
589 C = N; \
590 } while(0)
591
592 ROTATE(int tmp, &v->last_use_ic, &v->next_use_ic, v->curr_use_ic);
593 ROTATE(uint8_t tmp[2][256], v->last_luty, v->next_luty, v->curr_luty);
594 ROTATE(uint8_t tmp[2][256], v->last_lutuv, v->next_lutuv, v->curr_lutuv);
595 }
596
597 INIT_LUT(32, 0, v->curr_luty[0], v->curr_lutuv[0], 0);
598 INIT_LUT(32, 0, v->curr_luty[1], v->curr_lutuv[1], 0);
599 *v->curr_use_ic = 0;
600}
601
603 int bfraction_lut_index = get_bits(gb, 3);
604
605 if (bfraction_lut_index == 7)
606 bfraction_lut_index = 7 + get_bits(gb, 4);
607
608 if (bfraction_lut_index == 21) {
609 av_log(v->s.avctx, AV_LOG_ERROR, "bfraction invalid\n");
610 return AVERROR_INVALIDDATA;
611 }
612 v->bfraction_lut_index = bfraction_lut_index;
614 return 0;
615}
616
618{
619 int pqindex, lowquant, status;
620
621 v->field_mode = 0;
622 v->fcm = PROGRESSIVE;
623 if (v->finterpflag)
624 v->interpfrm = get_bits1(gb);
625 if (v->s.avctx->codec_id == AV_CODEC_ID_MSS2)
626 v->respic =
627 v->rangered =
628 v->multires = get_bits(gb, 2) == 1;
629 else
630 skip_bits(gb, 2); //framecnt unused
631 v->rangeredfrm = 0;
632 if (v->rangered)
633 v->rangeredfrm = get_bits1(gb);
634 if (get_bits1(gb)) {
636 } else {
637 if (v->s.avctx->max_b_frames && !get_bits1(gb)) {
639 } else
641 }
642
643 v->bi_type = 0;
644 if (v->s.pict_type == AV_PICTURE_TYPE_B) {
645 if (read_bfraction(v, gb) < 0)
646 return AVERROR_INVALIDDATA;
647 if (v->bfraction == 0) {
649 }
650 }
652 skip_bits(gb, 7); // skip buffer fullness
653
654 if (v->parse_only)
655 return 0;
656
657 /* calculate RND */
659 v->rnd = 1;
660 if (v->s.pict_type == AV_PICTURE_TYPE_P)
661 v->rnd ^= 1;
662
663 if (get_bits_left(gb) < 5)
664 return AVERROR_INVALIDDATA;
665 /* Quantizer stuff */
666 pqindex = get_bits(gb, 5);
667 if (!pqindex)
668 return -1;
670 v->pq = ff_vc1_pquant_table[0][pqindex];
671 else
672 v->pq = ff_vc1_pquant_table[1][pqindex];
673 v->pqindex = pqindex;
674 if (pqindex < 9)
675 v->halfpq = get_bits1(gb);
676 else
677 v->halfpq = 0;
678 switch (v->quantizer_mode) {
680 v->pquantizer = pqindex < 9;
681 break;
683 v->pquantizer = 0;
684 break;
686 v->pquantizer = get_bits1(gb);
687 break;
688 default:
689 v->pquantizer = 1;
690 break;
691 }
692 v->dquantfrm = 0;
693 if (v->extended_mv == 1)
694 v->mvrange = get_unary(gb, 0, 3);
695 v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
696 v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
697 v->range_x = 1 << (v->k_x - 1);
698 v->range_y = 1 << (v->k_y - 1);
699 if (v->multires && v->s.pict_type != AV_PICTURE_TYPE_B)
700 v->respic = get_bits(gb, 2);
701
702 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 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
711 rotate_luts(v);
712
713 switch (v->s.pict_type) {
715 v->tt_index = (v->pq > 4) + (v->pq > 12);
716
717 lowquant = (v->pq > 12) ? 0 : 1;
718 v->mv_mode = ff_vc1_mv_pmode_table[lowquant][get_unary(gb, 1, 4)];
720 v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][get_unary(gb, 1, 3)];
721 v->lumscale = get_bits(gb, 6);
722 v->lumshift = get_bits(gb, 6);
723 v->last_use_ic = 1;
724 /* fill lookup tables for intensity compensation */
725 INIT_LUT(v->lumscale, v->lumshift, v->last_luty[0], v->last_lutuv[0], 1);
726 INIT_LUT(v->lumscale, v->lumshift, v->last_luty[1], v->last_lutuv[1], 1);
727 }
732 } else {
736 }
737
738 if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
742 if (status < 0)
743 return -1;
744 av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
745 "Imode: %i, Invert: %i\n", status>>1, status&1);
746 } else {
747 v->mv_type_is_raw = 0;
748 memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height);
749 }
750 status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
751 if (status < 0)
752 return -1;
753 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
754 "Imode: %i, Invert: %i\n", status>>1, status&1);
755
756 if (get_bits_left(gb) < 4)
757 return AVERROR_INVALIDDATA;
758
759 /* Hopefully this is correct for P-frames */
760 v->mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables
761 v->cbptab = get_bits(gb, 2);
763
764 if (v->dquant) {
765 av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
767 }
768
769 if (v->vstransform) {
770 v->ttmbf = get_bits1(gb);
771 if (v->ttmbf) {
772 v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
773 } else
774 v->ttfrm = 0; //FIXME Is that so ?
775 } else {
776 v->ttmbf = 1;
777 v->ttfrm = TT_8X8;
778 }
779 break;
781 v->tt_index = (v->pq > 4) + (v->pq > 12);
782
785 v->s.mspel = v->s.quarter_sample;
786
787 status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);
788 if (status < 0)
789 return -1;
790 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "
791 "Imode: %i, Invert: %i\n", status>>1, status&1);
792 status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
793 if (status < 0)
794 return -1;
795 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
796 "Imode: %i, Invert: %i\n", status>>1, status&1);
797
798 v->mv_table_index = get_bits(gb, 2);
799 v->cbptab = get_bits(gb, 2);
801
802 if (v->dquant) {
803 av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
805 }
806
807 if (v->vstransform) {
808 v->ttmbf = get_bits1(gb);
809 if (v->ttmbf) {
810 v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
811 } else
812 v->ttfrm = 0;
813 } else {
814 v->ttmbf = 1;
815 v->ttfrm = TT_8X8;
816 }
817 break;
818 }
819
820 if (!v->x8_type) {
821 /* AC Syntax */
825 }
826 /* DC Syntax */
827 v->dc_table_index = get_bits1(gb);
828 }
829
830 if (v->s.pict_type == AV_PICTURE_TYPE_BI) {
832 v->bi_type = 1;
833 }
834 return 0;
835}
836
838{
839 int pqindex, lowquant;
840 int status;
841 int field_mode, fcm;
842
843 v->numref = 0;
844 v->p_frame_skipped = 0;
845 if (v->second_field) {
846 if (v->fcm != ILACE_FIELD || v->field_mode!=1)
847 return -1;
848 if (v->fptype & 4)
850 else
852 v->s.cur_pic.ptr->f->pict_type = v->s.pict_type;
853 if (!v->pic_header_flag)
854 goto parse_common_info;
855 }
856
857 field_mode = 0;
858 if (v->interlace) {
859 fcm = decode012(gb);
860 if (fcm) {
861 if (fcm == ILACE_FIELD)
862 field_mode = 1;
863 }
864 } else {
865 fcm = PROGRESSIVE;
866 }
867 if (!v->first_pic_header_flag && v->field_mode != field_mode)
868 return AVERROR_INVALIDDATA;
869 v->field_mode = field_mode;
870 v->fcm = fcm;
871
872 av_assert0( v->s.mb_height == v->s.height + 15 >> 4
873 || v->s.mb_height == FFALIGN(v->s.height + 15 >> 4, 2));
874 if (v->field_mode) {
875 v->s.mb_height = FFALIGN(v->s.height + 15 >> 4, 2);
876 v->fptype = get_bits(gb, 3);
877 if (v->fptype & 4) // B-picture
879 else
881 } else {
882 v->s.mb_height = v->s.height + 15 >> 4;
883 switch (get_unary(gb, 0, 4)) {
884 case 0:
886 break;
887 case 1:
889 break;
890 case 2:
892 break;
893 case 3:
895 break;
896 case 4:
897 v->s.pict_type = AV_PICTURE_TYPE_P; // skipped pic
898 v->p_frame_skipped = 1;
899 break;
900 }
901 }
902 if (v->tfcntrflag)
903 skip_bits(gb, 8);
904 if (v->broadcast) {
905 if (!v->interlace || v->psf) {
906 v->rptfrm = get_bits(gb, 2);
907 } else {
908 v->tff = get_bits1(gb);
909 v->rff = get_bits1(gb);
910 }
911 } else {
912 v->tff = 1;
913 }
914 if (v->panscanflag) {
915 avpriv_report_missing_feature(v->s.avctx, "Pan-scan");
916 //...
917 }
918 if (v->p_frame_skipped) {
919 return 0;
920 }
921 v->rnd = get_bits1(gb);
922 if (v->interlace)
923 v->uvsamp = get_bits1(gb);
924 if (v->field_mode) {
925 if (!v->refdist_flag)
926 v->refdist = 0;
927 else if ((v->s.pict_type != AV_PICTURE_TYPE_B) && (v->s.pict_type != AV_PICTURE_TYPE_BI)) {
928 v->refdist = get_bits(gb, 2);
929 if (v->refdist == 3)
930 v->refdist += get_unary(gb, 0, 14);
931 if (v->refdist > 16)
932 return AVERROR_INVALIDDATA;
933 }
935 if (read_bfraction(v, gb) < 0)
936 return AVERROR_INVALIDDATA;
937 v->frfd = (v->bfraction * v->refdist) >> 8;
938 v->brfd = v->refdist - v->frfd - 1;
939 if (v->brfd < 0)
940 v->brfd = 0;
941 }
942 goto parse_common_info;
943 }
944 if (v->fcm == PROGRESSIVE) {
945 if (v->finterpflag)
946 v->interpfrm = get_bits1(gb);
947 if (v->s.pict_type == AV_PICTURE_TYPE_B) {
948 if (read_bfraction(v, gb) < 0)
949 return AVERROR_INVALIDDATA;
950 if (v->bfraction == 0) {
951 v->s.pict_type = AV_PICTURE_TYPE_BI; /* XXX: should not happen here */
952 }
953 }
954 }
955
956 parse_common_info:
957 if (v->field_mode)
958 v->cur_field_type = !(v->tff ^ v->second_field);
959 pqindex = get_bits(gb, 5);
960 if (!pqindex)
961 return -1;
963 v->pq = ff_vc1_pquant_table[0][pqindex];
964 else
965 v->pq = ff_vc1_pquant_table[1][pqindex];
966 v->pqindex = pqindex;
967 if (pqindex < 9)
968 v->halfpq = get_bits1(gb);
969 else
970 v->halfpq = 0;
971 switch (v->quantizer_mode) {
973 v->pquantizer = pqindex < 9;
974 break;
976 v->pquantizer = 0;
977 break;
979 v->pquantizer = get_bits1(gb);
980 break;
981 default:
982 v->pquantizer = 1;
983 break;
984 }
985 v->dquantfrm = 0;
986 if (v->postprocflag)
987 v->postproc = get_bits(gb, 2);
988
989 if (v->parse_only)
990 return 0;
991
993 rotate_luts(v);
994
995 switch (v->s.pict_type) {
998 if (v->fcm == ILACE_FRAME) { //interlace frame picture
1000 if (status < 0)
1001 return -1;
1002 av_log(v->s.avctx, AV_LOG_DEBUG, "FIELDTX plane encoding: "
1003 "Imode: %i, Invert: %i\n", status>>1, status&1);
1004 } else
1005 v->fieldtx_is_raw = 0;
1006 status = bitplane_decoding(v->acpred_plane, &v->acpred_is_raw, v);
1007 if (status < 0)
1008 return -1;
1009 av_log(v->s.avctx, AV_LOG_DEBUG, "ACPRED plane encoding: "
1010 "Imode: %i, Invert: %i\n", status>>1, status&1);
1012 if (v->overlap && v->pq <= 8) {
1013 v->condover = decode012(gb);
1014 if (v->condover == CONDOVER_SELECT) {
1016 if (status < 0)
1017 return -1;
1018 av_log(v->s.avctx, AV_LOG_DEBUG, "CONDOVER plane encoding: "
1019 "Imode: %i, Invert: %i\n", status>>1, status&1);
1020 }
1021 }
1022 break;
1023 case AV_PICTURE_TYPE_P:
1024 if (v->field_mode) {
1025 v->numref = get_bits1(gb);
1026 if (!v->numref) {
1027 v->reffield = get_bits1(gb);
1028 v->ref_field_type[0] = v->reffield ^ !v->cur_field_type;
1029 }
1030 }
1031 if (v->extended_mv)
1032 v->mvrange = get_unary(gb, 0, 3);
1033 else
1034 v->mvrange = 0;
1035 if (v->interlace) {
1036 if (v->extended_dmv)
1037 v->dmvrange = get_unary(gb, 0, 3);
1038 else
1039 v->dmvrange = 0;
1040 if (v->fcm == ILACE_FRAME) { // interlaced frame picture
1041 v->fourmvswitch = get_bits1(gb);
1042 v->intcomp = get_bits1(gb);
1043 if (v->intcomp) {
1044 v->lumscale = get_bits(gb, 6);
1045 v->lumshift = get_bits(gb, 6);
1046 INIT_LUT(v->lumscale, v->lumshift, v->last_luty[0], v->last_lutuv[0], 1);
1047 INIT_LUT(v->lumscale, v->lumshift, v->last_luty[1], v->last_lutuv[1], 1);
1048 v->last_use_ic = 1;
1049 }
1050 status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
1051 if (status < 0)
1052 return -1;
1053 av_log(v->s.avctx, AV_LOG_DEBUG, "SKIPMB plane encoding: "
1054 "Imode: %i, Invert: %i\n", status>>1, status&1);
1055 v->mbmodetab = get_bits(gb, 2);
1056 if (v->fourmvswitch)
1058 else
1060 v->imvtab = get_bits(gb, 2);
1062 // interlaced p-picture cbpcy range is [1, 63]
1063 v->icbptab = get_bits(gb, 3);
1065 v->twomvbptab = get_bits(gb, 2);
1067 if (v->fourmvswitch) {
1068 v->fourmvbptab = get_bits(gb, 2);
1070 }
1071 }
1072 }
1073 v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
1074 v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
1075 v->range_x = 1 << (v->k_x - 1);
1076 v->range_y = 1 << (v->k_y - 1);
1077
1078 v->tt_index = (v->pq > 4) + (v->pq > 12);
1079 if (v->fcm != ILACE_FRAME) {
1080 int mvmode;
1081 mvmode = get_unary(gb, 1, 4);
1082 lowquant = (v->pq > 12) ? 0 : 1;
1083 v->mv_mode = ff_vc1_mv_pmode_table[lowquant][mvmode];
1084 if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
1085 int mvmode2;
1086 mvmode2 = get_unary(gb, 1, 3);
1087 v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][mvmode2];
1088 if (v->field_mode) {
1089 v->intcompfield = decode210(gb) ^ 3;
1090 } else
1091 v->intcompfield = 3;
1092
1093 v->lumscale2 = v->lumscale = 32;
1094 v->lumshift2 = v->lumshift = 0;
1095 if (v->intcompfield & 1) {
1096 v->lumscale = get_bits(gb, 6);
1097 v->lumshift = get_bits(gb, 6);
1098 }
1099 if ((v->intcompfield & 2) && v->field_mode) {
1100 v->lumscale2 = get_bits(gb, 6);
1101 v->lumshift2 = get_bits(gb, 6);
1102 } else if(!v->field_mode) {
1103 v->lumscale2 = v->lumscale;
1104 v->lumshift2 = v->lumshift;
1105 }
1106 if (v->field_mode && v->second_field) {
1107 if (v->cur_field_type) {
1110 } else {
1113 }
1114 v->next_use_ic = *v->curr_use_ic = 1;
1115 } else {
1116 INIT_LUT(v->lumscale , v->lumshift , v->last_luty[0], v->last_lutuv[0], 1);
1117 INIT_LUT(v->lumscale2, v->lumshift2, v->last_luty[1], v->last_lutuv[1], 1);
1118 }
1119 v->last_use_ic = 1;
1120 }
1121 if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {
1125 } else {
1129 }
1130 }
1131 if (v->fcm == PROGRESSIVE) { // progressive
1132 if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
1134 || v->mv_mode == MV_PMODE_MIXED_MV) {
1136 if (status < 0)
1137 return -1;
1138 av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
1139 "Imode: %i, Invert: %i\n", status>>1, status&1);
1140 } else {
1141 v->mv_type_is_raw = 0;
1142 memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height);
1143 }
1144 status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
1145 if (status < 0)
1146 return -1;
1147 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
1148 "Imode: %i, Invert: %i\n", status>>1, status&1);
1149
1150 /* Hopefully this is correct for P-frames */
1151 v->mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables
1152 v->cbptab = get_bits(gb, 2);
1154 } else if (v->fcm == ILACE_FRAME) { // frame interlaced
1155 v->s.quarter_sample = 1;
1156 v->s.mspel = 1;
1157 } else { // field interlaced
1158 v->mbmodetab = get_bits(gb, 3);
1159 v->imvtab = get_bits(gb, 2 + v->numref);
1160 if (!v->numref)
1162 else
1164 v->icbptab = get_bits(gb, 3);
1166 if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
1168 v->fourmvbptab = get_bits(gb, 2);
1171 } else {
1173 }
1174 }
1175 if (v->dquant) {
1176 av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
1178 }
1179
1180 if (v->vstransform) {
1181 v->ttmbf = get_bits1(gb);
1182 if (v->ttmbf) {
1183 v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
1184 } else
1185 v->ttfrm = 0; //FIXME Is that so ?
1186 } else {
1187 v->ttmbf = 1;
1188 v->ttfrm = TT_8X8;
1189 }
1190 break;
1191 case AV_PICTURE_TYPE_B:
1192 if (v->fcm == ILACE_FRAME) {
1193 if (read_bfraction(v, gb) < 0)
1194 return AVERROR_INVALIDDATA;
1195 if (v->bfraction == 0) {
1196 return -1;
1197 }
1198 }
1199 if (v->extended_mv)
1200 v->mvrange = get_unary(gb, 0, 3);
1201 else
1202 v->mvrange = 0;
1203 v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
1204 v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
1205 v->range_x = 1 << (v->k_x - 1);
1206 v->range_y = 1 << (v->k_y - 1);
1207
1208 v->tt_index = (v->pq > 4) + (v->pq > 12);
1209
1210 if (v->field_mode) {
1211 int mvmode;
1212 av_log(v->s.avctx, AV_LOG_DEBUG, "B Fields\n");
1213 if (v->extended_dmv)
1214 v->dmvrange = get_unary(gb, 0, 3);
1215 mvmode = get_unary(gb, 1, 3);
1216 lowquant = (v->pq > 12) ? 0 : 1;
1217 v->mv_mode = ff_vc1_mv_pmode_table2[lowquant][mvmode];
1220 status = bitplane_decoding(v->forward_mb_plane, &v->fmb_is_raw, v);
1221 if (status < 0)
1222 return -1;
1223 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Forward Type plane encoding: "
1224 "Imode: %i, Invert: %i\n", status>>1, status&1);
1225 v->mbmodetab = get_bits(gb, 3);
1226 if (v->mv_mode == MV_PMODE_MIXED_MV)
1228 else
1230 v->imvtab = get_bits(gb, 3);
1232 v->icbptab = get_bits(gb, 3);
1234 if (v->mv_mode == MV_PMODE_MIXED_MV) {
1235 v->fourmvbptab = get_bits(gb, 2);
1237 }
1238 v->numref = 1; // interlaced field B pictures are always 2-ref
1239 } else if (v->fcm == ILACE_FRAME) {
1240 if (v->extended_dmv)
1241 v->dmvrange = get_unary(gb, 0, 3);
1242 if (get_bits1(gb)) /* intcomp - present but shall always be 0 */
1243 av_log(v->s.avctx, AV_LOG_WARNING, "Intensity compensation set for B picture\n");
1244 v->intcomp = 0;
1245 v->mv_mode = MV_PMODE_1MV;
1246 v->fourmvswitch = 0;
1247 v->s.quarter_sample = 1;
1248 v->s.mspel = 1;
1249 status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);
1250 if (status < 0)
1251 return -1;
1252 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "
1253 "Imode: %i, Invert: %i\n", status>>1, status&1);
1254 status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
1255 if (status < 0)
1256 return -1;
1257 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
1258 "Imode: %i, Invert: %i\n", status>>1, status&1);
1259 v->mbmodetab = get_bits(gb, 2);
1261 v->imvtab = get_bits(gb, 2);
1263 // interlaced p/b-picture cbpcy range is [1, 63]
1264 v->icbptab = get_bits(gb, 3);
1266 v->twomvbptab = get_bits(gb, 2);
1268 v->fourmvbptab = get_bits(gb, 2);
1270 } else {
1272 v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV);
1273 v->s.mspel = v->s.quarter_sample;
1274 status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);
1275 if (status < 0)
1276 return -1;
1277 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "
1278 "Imode: %i, Invert: %i\n", status>>1, status&1);
1279 status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
1280 if (status < 0)
1281 return -1;
1282 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
1283 "Imode: %i, Invert: %i\n", status>>1, status&1);
1284 v->mv_table_index = get_bits(gb, 2);
1285 v->cbptab = get_bits(gb, 2);
1287 }
1288
1289 if (v->dquant) {
1290 av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
1292 }
1293
1294 if (v->vstransform) {
1295 v->ttmbf = get_bits1(gb);
1296 if (v->ttmbf) {
1297 v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
1298 } else
1299 v->ttfrm = 0;
1300 } else {
1301 v->ttmbf = 1;
1302 v->ttfrm = TT_8X8;
1303 }
1304 break;
1305 }
1306
1307
1308 /* AC Syntax */
1309 v->c_ac_table_index = decode012(gb);
1311 v->y_ac_table_index = decode012(gb);
1312 }
1313 else if (v->fcm != PROGRESSIVE && !v->s.quarter_sample) {
1314 v->range_x <<= 1;
1315 v->range_y <<= 1;
1316 }
1317
1318 /* DC Syntax */
1319 v->dc_table_index = get_bits1(gb);
1321 && v->dquant) {
1322 av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
1324 }
1325
1327 if (v->bi_type)
1329
1330 return 0;
1331}
static void invert(float *h, int n)
Definition asrc_sinc.c:186
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
Libavcodec external API header.
static int BS_FUNC decode012(BSCTX *bc)
Return decoded truncated unary code for the values 0, 1, 2.
static int BS_FUNC decode210(BSCTX *bc)
Return decoded truncated unary code for the values 2, 1, 0.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
Definition utils.c:106
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Definition utils.c:91
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
Definition get_bits.h:498
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
Definition get_bits.h:645
static int get_bits_left(GetBitContext *gb)
Definition get_bits.h:688
static unsigned int get_bits1(GetBitContext *s)
Definition get_bits.h:391
static void skip_bits(GetBitContext *s, int n)
Definition get_bits.h:383
static void skip_bits1(GetBitContext *s)
Definition get_bits.h:416
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition get_bits.h:337
@ AV_CODEC_ID_MSS2
Definition codec_id.h:216
@ AVDISCARD_ALL
discard all
Definition defs.h:232
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_INFO
Standard information.
Definition log.h:221
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition rational.c:35
@ AV_PICTURE_TYPE_I
Intra.
Definition avutil.h:278
@ AV_PICTURE_TYPE_BI
BI type.
Definition avutil.h:284
@ AV_PICTURE_TYPE_P
Predicted.
Definition avutil.h:279
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
Definition avutil.h:280
unsigned offset
Definition libaomenc.c:763
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
uint8_t w
Definition llvidencdsp.c:39
#define FFALIGN(x, a)
Definition macros.h:78
mpegvideo header.
const char data[16]
Definition mxf.c:149
const uint8_t * code
Definition spdifenc.c:433
main external API structure.
Definition avcodec.h:443
int width
picture width / height.
Definition avcodec.h:604
int max_b_frames
maximum number of B-frames between non-B-frames Note: The output will be delayed by max_b_frames+1 re...
Definition avcodec.h:781
AVRational framerate
Definition avcodec.h:563
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
Definition avcodec.h:628
enum AVDiscard skip_loop_filter
Skip loop filtering for selected frames.
Definition avcodec.h:1653
enum AVCodecID codec_id
Definition avcodec.h:453
enum AVPictureType pict_type
Picture type of the frame.
Definition frame.h:564
Rational number (pair of numerator and denominator).
Definition rational.h:58
int num
Numerator.
Definition rational.h:59
int den
Denominator.
Definition rational.h:60
struct AVFrame * f
Definition mpegpicture.h:59
MPVPicture * ptr
RefStruct reference.
Definition mpegpicture.h:99
int mb_stride
mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11
Definition mpegvideo.h:97
struct AVCodecContext * avctx
Definition mpegvideo.h:82
int mb_height
number of MBs horizontally & vertically
Definition mpegvideo.h:96
int quarter_sample
1->qpel, 0->half pel ME/MC
Definition mpegvideo.h:230
int height
picture size. must be a multiple of 16
Definition mpegvideo.h:84
enum AVPictureType pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
Definition mpegvideo.h:154
uint8_t * mbskip_table
used to avoid copy if macroblock skipped (for black regions for example) and used for B-frame encodin...
Definition mpegvideo.h:144
MPVWorkPicture cur_pic
copy of the current picture structure.
Definition mpegvideo.h:132
The VC1 Context.
Definition vc1.h:176
int loop_filter
Definition vc1.h:223
uint8_t lumshift2
Definition vc1.h:343
int pqindex
raw pqindex used in coding set selection
Definition vc1.h:269
int tfcntrflag
TFCNTR present.
Definition vc1.h:204
int twomvbptab
Definition vc1.h:376
uint8_t uvsamp
Definition vc1.h:322
int transfer_char
8 bits, Opto-electronic transfer characteristics
Definition vc1.h:209
uint8_t((* curr_lutuv)[256]
Definition vc1.h:304
int profile
Sequence header data for all Profiles TODO: choose between ints, uint8_ts and monobit flags.
Definition vc1.h:220
int tt_index
Index for Transform Type tables (to decode TTMB)
Definition vc1.h:292
int imvtab
Definition vc1.h:375
int cbptab
Definition vc1.h:308
int range_x
Definition vc1.h:241
int * curr_use_ic
Definition vc1.h:305
int res_x8
reserved
Definition vc1.h:187
int k_x
Number of bits for MVs (depends on MV range)
Definition vc1.h:239
uint8_t * over_flags_plane
Overflags bitplane.
Definition vc1.h:329
int range_y
MV range.
Definition vc1.h:241
uint8_t * direct_mb_plane
bitplane for "direct" MBs
Definition vc1.h:295
int pic_header_flag
Definition vc1.h:372
uint8_t last_luty[2][256]
Definition vc1.h:301
const VLCElem * fourmvbp_vlc
Definition vc1.h:347
int first_pic_header_flag
Definition vc1.h:371
uint8_t bfraction_lut_index
Index for BFRACTION value (see Table 40, reproduced into ff_vc1_bfraction_lut[])
Definition vc1.h:397
int max_coded_width
Definition vc1.h:224
int brfd
reference frame distance (forward or backward)
Definition vc1.h:370
uint8_t lumshift
Definition vc1.h:277
uint8_t interpfrm
Definition vc1.h:313
int p_frame_skipped
Definition vc1.h:388
int skip_is_raw
skip mb plane is not coded
Definition vc1.h:300
int dquant
How qscale varies with MBs, 2 bits (not in Simple)
Definition vc1.h:227
uint8_t tff
Definition vc1.h:321
int reffield
if numref = 0 (1 reference) then reffield decides which
Definition vc1.h:362
int multires
frame-level RESPIC syntax element present
Definition vc1.h:188
const uint8_t * zz_4x8
Zigzag scan table for TT_4x8 coding mode.
Definition vc1.h:246
uint8_t ttmbf
Transform type flag.
Definition vc1.h:265
int fieldtx_is_raw
Definition vc1.h:351
const VLCElem * cbpcy_vlc
CBPCY VLC table.
Definition vc1.h:291
int ref_field_type[2]
forward and backward reference field type (top or bottom)
Definition vc1.h:367
int finterpflag
INTERPFRM present.
Definition vc1.h:232
uint8_t range_mapuv_flag
Definition vc1.h:333
int extended_mv
Ext MV in P/B (not in Simple)
Definition vc1.h:226
uint8_t range_mapy_flag
Definition vc1.h:332
uint8_t pquantizer
Uniform (over sequence) quantizer in use.
Definition vc1.h:290
int bi_type
Definition vc1.h:389
int acpred_is_raw
Definition vc1.h:328
int icbptab
Definition vc1.h:374
int second_field
Definition vc1.h:358
int fourmvswitch
Definition vc1.h:340
uint8_t range_mapy
Definition vc1.h:334
uint8_t pq
Definition vc1.h:242
uint8_t altpq
Current/alternate frame quantizer scale.
Definition vc1.h:242
int extended_dmv
Additional extended dmv range at P/B-frame-level.
Definition vc1.h:207
uint8_t dqbilevel
Definition vc1.h:252
int panscanflag
NUMPANSCANWIN, TOPLEFT{X,Y}, BOTRIGHT{X,Y} present.
Definition vc1.h:205
int parse_only
Context is used within parser.
Definition vc1.h:403
uint8_t mv_mode2
Secondary MV coding mode (B-frames)
Definition vc1.h:238
const VLCElem * imv_vlc
Definition vc1.h:345
int psf
Progressive Segmented Frame.
Definition vc1.h:213
int res_rtm_flag
reserved, set to 1
Definition vc1.h:193
int res_fasttx
reserved, always 1
Definition vc1.h:189
int refdist
distance of the current picture from reference
Definition vc1.h:359
int field_mode
1 for interlaced field pictures
Definition vc1.h:356
uint8_t broken_link
Broken link flag (BROKEN_LINK syntax element)
Definition vc1.h:398
int16_t bfraction
Relative position % anchors=> how to scale MVs.
Definition vc1.h:279
uint8_t rangeredfrm
Frame decoding info for S/M profiles only.
Definition vc1.h:312
int res_sprite
Simple/Main Profile sequence header.
Definition vc1.h:185
int quantizer_mode
2 bits, quantizer mode used for sequence, see QUANT_*
Definition vc1.h:231
uint8_t next_luty[2][256]
Definition vc1.h:303
int broadcast
TFF/RFF present.
Definition vc1.h:202
int res_y411
reserved, old interlaced mode
Definition vc1.h:186
int refdist_flag
REFDIST syntax element present in II, IP, PI or PP field picture headers.
Definition vc1.h:206
int frfd
Definition vc1.h:370
int max_b_frames
max number of B-frames
Definition vc1.h:230
uint8_t * fieldtx_plane
Definition vc1.h:350
int chromaformat
2 bits, 2=4:2:0, only defined
Definition vc1.h:200
uint8_t * mv_type_mb_plane
bitplane for mv_type == (4MV)
Definition vc1.h:294
MpegEncContext s
Definition vc1.h:177
int dc_table_index
Definition vc1.h:254
int overlap
overlapped transforms in use
Definition vc1.h:229
int fmb_is_raw
forward mb plane is raw
Definition vc1.h:299
int color_prim
8 bits, chroma coordinates of the color primaries
Definition vc1.h:208
int aux_use_ic
Definition vc1.h:305
GetBitContext gb
Definition vc1.h:178
uint8_t closed_entry
Closed entry point flag (CLOSED_ENTRY syntax element)
Definition vc1.h:399
uint8_t * acpred_plane
AC prediction flags bitplane.
Definition vc1.h:327
const VLCElem * mbmode_vlc
Definition vc1.h:344
int x8_type
Definition vc1.h:390
int fourmvbptab
Definition vc1.h:377
int rnd
rounding control
Definition vc1.h:307
uint8_t mvrange
Ranges:
Definition vc1.h:289
int intcompfield
which of the two fields to be intensity compensated
Definition vc1.h:364
uint8_t next_lutuv[2][256]
lookup tables used for intensity compensation
Definition vc1.h:303
uint8_t dmvrange
Frame decoding info for interlaced picture.
Definition vc1.h:339
int hrd_num_leaky_buckets
Definition vc1.h:324
uint8_t range_mapuv
Definition vc1.h:335
int res_transtab
reserved, always 0
Definition vc1.h:190
int bitrtq_postproc
5 bits, quantized framerate-based postprocessing strength
Definition vc1.h:222
int level
Advanced Profile.
Definition vc1.h:199
uint8_t rff
Definition vc1.h:321
uint8_t mv_mode
Frame decoding info for all profiles.
Definition vc1.h:237
uint8_t dquantfrm
pquant parameters
Definition vc1.h:249
int dmb_is_raw
direct mb plane is raw
Definition vc1.h:298
int k_y
Number of bits for MVs (depends on MV range)
Definition vc1.h:240
int hrd_param_flag
Presence of Hypothetical Reference Decoder parameters.
Definition vc1.h:211
int cur_field_type
0: top, 1: bottom
Definition vc1.h:366
int postprocflag
Per-frame processing suggestion flag present.
Definition vc1.h:201
int last_use_ic
Definition vc1.h:305
enum FrameCodingMode fcm
Frame decoding info for Advanced profile.
Definition vc1.h:318
int interlace
Progressive/interlaced (RPTFTM syntax element)
Definition vc1.h:203
uint8_t(* curr_luty)[256]
Definition vc1.h:304
uint8_t lumscale
Luma compensation parameters.
Definition vc1.h:276
int c_ac_table_index
AC coding set indexes.
Definition vc1.h:259
const uint8_t * zz_8x4
Zigzag scan table for TT_8x4 coding mode.
Definition vc1.h:245
uint8_t lumscale2
for interlaced field P picture
Definition vc1.h:342
int mbmodetab
Definition vc1.h:373
int next_use_ic
Definition vc1.h:305
int resync_marker
could this stream contain resync markers
Definition vc1.h:404
int fptype
Definition vc1.h:357
int ttfrm
Transform type info present at frame level.
Definition vc1.h:264
uint8_t dqprofile
Definition vc1.h:250
int y_ac_table_index
Luma index from AC2FRM element.
Definition vc1.h:260
uint8_t last_lutuv[2][256]
lookup tables used for intensity compensation
Definition vc1.h:301
const VLCElem * twomvbp_vlc
Definition vc1.h:346
uint8_t halfpq
Uniform quant over image and qp+.5.
Definition vc1.h:280
uint8_t * forward_mb_plane
bitplane for "forward" MBs
Definition vc1.h:296
uint8_t aux_lutuv[2][256]
lookup tables used for intensity compensation
Definition vc1.h:302
int mv_table_index
Definition vc1.h:293
uint8_t condover
Definition vc1.h:331
int matrix_coef
8 bits, Color primaries->YCbCr transform matrix
Definition vc1.h:210
uint8_t respic
Frame-level flag for resized images.
Definition vc1.h:281
int fastuvmc
Rounding of qpel vector to hpel ? (not in Simple)
Definition vc1.h:225
int overflg_is_raw
Definition vc1.h:330
uint8_t dqsbedge
Definition vc1.h:251
int mv_type_is_raw
mv type mb plane is not coded
Definition vc1.h:297
uint8_t postproc
Definition vc1.h:323
uint8_t aux_luty[2][256]
Definition vc1.h:302
uint8_t rptfrm
Definition vc1.h:321
int frmrtq_postproc
3 bits,
Definition vc1.h:221
int numref
number of past field pictures used as reference
Definition vc1.h:360
int max_coded_height
Definition vc1.h:224
int intcomp
Definition vc1.h:341
int rangered
RANGEREDFRM (range reduction) syntax element present at frame level.
Definition vc1.h:191
int vstransform
variable-size [48]x[48] transform type + info
Definition vc1.h:228
#define stride
#define ff_dlog(a,...)
#define avpriv_request_sample(...)
#define av_log(a,...)
static uint8_t tmp[40]
Definition aes_ctr.c:52
#define height
Definition dsp.h:89
#define width
Definition dsp.h:89
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
Definition unary.h:46
int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext *gb)
Definition vc1.c:837
static int bitplane_decoding(uint8_t *data, int *raw_flag, VC1Context *v)
Decode a bitplane's bits.
Definition vc1.c:95
int ff_vc1_decode_sequence_header(AVCodecContext *avctx, VC1Context *v, GetBitContext *gb)
Decode Simple/Main Profiles sequence header.
Definition vc1.c:275
static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb)
Definition vc1.c:386
int ff_vc1_parse_frame_header(VC1Context *v, GetBitContext *gb)
Definition vc1.c:617
int ff_vc1_decode_entry_point(AVCodecContext *avctx, VC1Context *v, GetBitContext *gb)
Definition vc1.c:494
#define ROTATE(DEF, L, N, C)
static void decode_colskip(uint8_t *plane, int width, int height, int stride, GetBitContext *gb)
Decode columns by checking if they are skipped.
Definition vc1.c:72
static void decode_rowskip(uint8_t *plane, int width, int height, int stride, GetBitContext *gb)
Decode rows by checking if they are skipped.
Definition vc1.c:50
static int vop_dquant_decoding(VC1Context *v)
VOP Dquant decoding.
Definition vc1.c:228
static void rotate_luts(VC1Context *v)
Definition vc1.c:577
#define INIT_LUT(lumscale, lumshift, luty, lutuv, chain)
Definition vc1.c:555
static int read_bfraction(VC1Context *v, GetBitContext *gb)
Definition vc1.c:602
@ CONDOVER_NONE
Definition vc1.h:140
@ CONDOVER_SELECT
Definition vc1.h:142
@ TT_8X8
Definition vc1.h:115
@ IMODE_RAW
Definition vc1.h:162
@ IMODE_DIFF6
Definition vc1.h:166
@ IMODE_DIFF2
Definition vc1.h:164
@ IMODE_COLSKIP
Definition vc1.h:168
@ IMODE_NORM6
Definition vc1.h:165
@ IMODE_ROWSKIP
Definition vc1.h:167
@ IMODE_NORM2
Definition vc1.h:163
@ PROGRESSIVE
in the bitstream is reported as 00b
Definition vc1.h:152
@ ILACE_FIELD
in the bitstream is reported as 11b
Definition vc1.h:154
@ ILACE_FRAME
in the bitstream is reported as 10b
Definition vc1.h:153
@ QUANT_FRAME_EXPLICIT
Explicitly specified at frame level.
Definition vc1.h:42
@ QUANT_FRAME_IMPLICIT
Implicitly specified at frame level.
Definition vc1.h:41
@ QUANT_NON_UNIFORM
Non-uniform quant used for all frames.
Definition vc1.h:43
@ MV_PMODE_INTENSITY_COMP
Definition vc1.h:86
@ MV_PMODE_1MV_HPEL
Definition vc1.h:84
@ MV_PMODE_1MV
Definition vc1.h:83
@ MV_PMODE_1MV_HPEL_BILIN
Definition vc1.h:82
@ MV_PMODE_MIXED_MV
Definition vc1.h:85
@ DQPROFILE_DOUBLE_EDGES
Definition vc1.h:52
@ DQPROFILE_SINGLE_EDGE
Definition vc1.h:53
@ DQPROFILE_ALL_MBS
Definition vc1.h:54
@ PROFILE_ADVANCED
Definition vc1_common.h:52
@ PROFILE_COMPLEX
TODO: WMV9 specific.
Definition vc1_common.h:51
@ PROFILE_SIMPLE
Definition vc1_common.h:49
const VLCElem * ff_vc1_2ref_mvdata_vlc[8]
Definition vc1data.c:122
const AVRational ff_vc1_pixel_aspect[16]
Definition vc1data.c:154
const VLCElem * ff_vc1_icbpcy_vlc[8]
Definition vc1data.c:112
const int ff_vc1_ttfrm_to_tt[4]
Definition vc1data.c:40
VLCElem ff_vc1_norm6_vlc[556]
Definition vc1data.c:107
const int ff_vc1_fps_dr[2]
Definition vc1data.c:88
const int16_t ff_vc1_bfraction_lut[23]
Definition vc1data.c:142
const uint8_t ff_vc1_mv_pmode_table[2][5]
MV P mode - the 5th element is only used for mode 1.
Definition vc1data.c:43
const uint8_t ff_vc1_mv_pmode_table2[2][4]
Definition vc1data.c:47
VLCElem ff_vc1_imode_vlc[1<< VC1_IMODE_VLC_BITS]
Definition vc1data.c:105
VLCElem ff_vc1_norm2_vlc[1<< VC1_NORM2_VLC_BITS]
Definition vc1data.c:106
const VLCElem * ff_vc1_if_1mv_mbmode_vlc[8]
Definition vc1data.c:120
const uint8_t ff_vc1_adv_progressive_4x8_zz[32]
Definition vc1data.c:196
const uint8_t ff_vc1_pquant_table[3][32]
Definition vc1data.c:89
const VLCElem * ff_vc1_if_mmv_mbmode_vlc[8]
Definition vc1data.c:119
const int ff_vc1_fps_nr[7]
Definition vc1data.c:87
const VLCElem * ff_vc1_intfr_4mv_mbmode_vlc[4]
Definition vc1data.c:117
const VLCElem * ff_vc1_intfr_non4mv_mbmode_vlc[4]
Definition vc1data.c:118
const VLCElem * ff_vc1_2mv_block_pattern_vlc[4]
Definition vc1data.c:114
const VLCElem * ff_vc1_1ref_mvdata_vlc[4]
Definition vc1data.c:121
const VLCElem * ff_vc1_4mv_block_pattern_vlc[4]
Definition vc1data.c:113
const VLCElem * ff_vc1_cbpcy_p_vlc[4]
Definition vc1data.c:111
const uint8_t ff_vc1_adv_progressive_8x4_zz[32]
Definition vc1data.c:189
VC-1 tables.
#define VC1_NORM6_VLC_BITS
Definition vc1data.h:62
#define VC1_IMODE_VLC_BITS
Definition vc1data.h:58
#define VC1_NORM2_VLC_BITS
Definition vc1data.h:60
const uint8_t ff_wmv2_scantableA[64]
Definition wmv2data.c:23
const uint8_t ff_wmv2_scantableB[64]
Definition wmv2data.c:30