vc1.h
Go to the documentation of this file.
1 /*
2  * VC-1 and WMV3 decoder
3  * Copyright (c) 2006-2007 Konstantin Shishkov
4  * Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, Michael Niedermayer
5  *
6  * This file is part of Libav.
7  *
8  * Libav is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * Libav is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with Libav; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #ifndef AVCODEC_VC1_H
24 #define AVCODEC_VC1_H
25 
26 #include "avcodec.h"
27 #include "mpegvideo.h"
28 #include "intrax8.h"
29 #include "vc1dsp.h"
30 
31 #define AC_VLC_BITS 9
32 
35 enum VC1Code {
36  VC1_CODE_RES0 = 0x00000100,
37  VC1_CODE_ENDOFSEQ = 0x0000010A,
43 };
45 
46 #define IS_MARKER(x) (((x) & ~0xFF) == VC1_CODE_RES0)
47 
50 enum Profile {
55 };
57 
60 enum QuantMode {
65 };
67 
70 enum DQProfile {
75 };
77 
86 };
88 
96 };
98 
101 enum MVModes {
107 };
109 
119 };
121 
124 enum BMVTypes {
129 };
131 
138  TT_8X4, // both halves
141  TT_4X8, // both halves
143 };
145 
146 enum CodingSet {
155 };
156 
159 enum COTypes {
163 };
165 
175 };
176 
181 typedef struct VC1Context{
185 
186  int bits;
187 
191  int res_y411;
192  int res_x8;
193  int multires;
196  int rangered;
197 
199  int reserved;
200 
201 
204  int level;
207  int broadcast;
208  int interlace;
217 
218  int psf;
219 
220 
225  int profile;
228  int fastuvmc;
230  int dquant;
232  int overlap;
235 
236 
239  uint8_t mv_mode;
240  uint8_t mv_mode2;
241  int k_x;
242  int k_y;
244  uint8_t pq, altpq;
245  uint8_t zz_8x8[4][64];
247  const uint8_t* zz_8x4;
248  const uint8_t* zz_4x8;
249 
251  uint8_t dquantfrm;
252  uint8_t dqprofile;
253  uint8_t dqsbedge;
254  uint8_t dqbilevel;
256 
262 
263  int ttfrm;
264  uint8_t ttmbf;
265  int *ttblk_base, *ttblk;
266  int codingset;
268  int pqindex;
270  uint8_t *mb_type_base, *mb_type[3];
271 
272 
275  uint8_t lumscale;
276  uint8_t lumshift;
278  int16_t bfraction;
279  uint8_t halfpq;
280  uint8_t respic;
282 
288  uint8_t mvrange;
289  uint8_t pquantizer;
291  int tt_index;
292  uint8_t* mv_type_mb_plane;
293  uint8_t* direct_mb_plane;
294  uint8_t* forward_mb_plane;
299  uint8_t luty[256], lutuv[256];
300  int use_ic;
301  int rnd;
302 
305  uint8_t rangeredfrm;
306  uint8_t interpfrm;
308 
312  uint8_t numpanscanwin;
313  uint8_t tfcntr;
314  uint8_t rptfrm, tff, rff;
315  uint16_t topleftx;
316  uint16_t toplefty;
317  uint16_t bottomrightx;
318  uint16_t bottomrighty;
319  uint8_t uvsamp;
320  uint8_t postproc;
324  uint8_t* acpred_plane;
326  uint8_t* over_flags_plane;
328  uint8_t condover;
329  uint16_t *hrd_rate, *hrd_buffer;
330  uint8_t *hrd_fullness;
333  uint8_t range_mapy;
334  uint8_t range_mapuv;
336 
338  uint8_t dmvrange;
340  int intcomp;
341  uint8_t lumscale2;
342  uint8_t lumshift2;
343  uint8_t luty2[256], lutuv2[256]; // lookup tables used for intensity compensation
348  uint8_t twomvbp;
349  uint8_t fourmvbp;
350  uint8_t* fieldtx_plane;
352  int8_t zzi_8x8[64];
354  uint8_t *mv_f_base, *mv_f[2];
355  uint8_t *mv_f_last_base, *mv_f_last[2];
356  uint8_t *mv_f_next_base, *mv_f_next[2];
358  int fptype;
360  int refdist;
361  int numref;
362  // 0 corresponds to 1 and 1 corresponds to 2 references
363  int reffield;
364  // field to use among the two fields from previous frame
366  // 0: both fields, 1: bottom field, 2: top field
368  int ref_field_type[2];
370  int qs_last;
371  int bmvtype;
372  int frfd, brfd;
374 
381  uint8_t* sr_rows[2][2];
382 
383 
385  int bi_type;
386  int x8_type;
387 
388  DCTELEM (*block)[6][64];
390  uint32_t *cbp_base, *cbp;
392  int16_t (*luma_mv_base)[2], (*luma_mv)[2];
394  uint8_t broken_link;
395  uint8_t closed_entry;
396 
398 
400 } VC1Context;
401 
405 static av_always_inline const uint8_t* find_next_marker(const uint8_t *src, const uint8_t *end)
406 {
407  uint32_t mrk = 0xFFFFFFFF;
408 
409  if (end-src < 4)
410  return end;
411  while (src < end) {
412  mrk = (mrk << 8) | *src++;
413  if (IS_MARKER(mrk))
414  return src - 4;
415  }
416  return end;
417 }
418 
419 static av_always_inline int vc1_unescape_buffer(const uint8_t *src, int size, uint8_t *dst)
420 {
421  int dsize = 0, i;
422 
423  if (size < 4) {
424  for (dsize = 0; dsize < size; dsize++)
425  *dst++ = *src++;
426  return size;
427  }
428  for (i = 0; i < size; i++, src++) {
429  if (src[0] == 3 && i >= 2 && !src[-1] && !src[-2] && i < size-1 && src[1] < 4) {
430  dst[dsize++] = src[1];
431  src++;
432  i++;
433  } else
434  dst[dsize++] = *src;
435  }
436  return dsize;
437 }
438 
447 
449 
453 
454 #endif /* AVCODEC_VC1_H */