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 
33 enum VC1Code {
34  VC1_CODE_RES0 = 0x00000100,
35  VC1_CODE_ENDOFSEQ = 0x0000010A,
41 };
43 
44 #define IS_MARKER(x) (((x) & ~0xFF) == VC1_CODE_RES0)
45 
48 enum Profile {
53 };
55 
58 enum QuantMode {
63 };
65 
68 enum DQProfile {
73 };
75 
84 };
86 
94 };
96 
99 enum MVModes {
105 };
107 
117 };
119 
122 enum BMVTypes {
127 };
129 
136  TT_8X4, // both halves
139  TT_4X8, // both halves
141 };
143 
144 enum CodingSet {
153 };
154 
157 enum COTypes {
161 };
163 
173 };
174 
179 typedef struct VC1Context{
183 
184  int bits;
185 
189  int res_y411;
190  int res_x8;
191  int multires;
194  int rangered;
195 
197  int reserved;
198 
199 
202  int level;
205  int broadcast;
206  int interlace;
215 
216  int psf;
217 
218 
223  int profile;
226  int fastuvmc;
228  int dquant;
230  int overlap;
233 
234 
237  uint8_t mv_mode;
238  uint8_t mv_mode2;
239  int k_x;
240  int k_y;
242  uint8_t pq, altpq;
243  uint8_t zz_8x8[4][64];
245  const uint8_t* zz_8x4;
246  const uint8_t* zz_4x8;
247 
249  uint8_t dquantfrm;
250  uint8_t dqprofile;
251  uint8_t dqsbedge;
252  uint8_t dqbilevel;
254 
260 
261  int ttfrm;
262  uint8_t ttmbf;
263  int *ttblk_base, *ttblk;
264  int codingset;
266  int pqindex;
268  uint8_t *mb_type_base, *mb_type[3];
269 
270 
273  uint8_t lumscale;
274  uint8_t lumshift;
276  int16_t bfraction;
277  uint8_t halfpq;
278  uint8_t respic;
280 
286  uint8_t mvrange;
287  uint8_t pquantizer;
289  int tt_index;
290  uint8_t* mv_type_mb_plane;
291  uint8_t* direct_mb_plane;
292  uint8_t* forward_mb_plane;
297  uint8_t luty[256], lutuv[256];
298  int use_ic;
299  int rnd;
300 
303  uint8_t rangeredfrm;
304  uint8_t interpfrm;
306 
310  uint8_t numpanscanwin;
311  uint8_t tfcntr;
312  uint8_t rptfrm, tff, rff;
313  uint16_t topleftx;
314  uint16_t toplefty;
315  uint16_t bottomrightx;
316  uint16_t bottomrighty;
317  uint8_t uvsamp;
318  uint8_t postproc;
322  uint8_t* acpred_plane;
324  uint8_t* over_flags_plane;
326  uint8_t condover;
327  uint16_t *hrd_rate, *hrd_buffer;
328  uint8_t *hrd_fullness;
331  uint8_t range_mapy;
332  uint8_t range_mapuv;
334 
336  uint8_t dmvrange;
338  int intcomp;
339  uint8_t lumscale2;
340  uint8_t lumshift2;
341  uint8_t luty2[256], lutuv2[256]; // lookup tables used for intensity compensation
346  uint8_t twomvbp;
347  uint8_t fourmvbp;
348  uint8_t* fieldtx_plane;
350  int8_t zzi_8x8[64];
352  uint8_t *mv_f_base, *mv_f[2];
353  uint8_t *mv_f_last_base, *mv_f_last[2];
354  uint8_t *mv_f_next_base, *mv_f_next[2];
356  int fptype;
358  int refdist;
359  int numref;
360  // 0 corresponds to 1 and 1 corresponds to 2 references
361  int reffield;
362  // field to use among the two fields from previous frame
364  // 0: both fields, 1: bottom field, 2: top field
366  int ref_field_type[2];
368  int qs_last;
369  int bmvtype;
370  int frfd, brfd;
372 
379  uint8_t* sr_rows[2][2];
380 
381 
383  int bi_type;
384  int x8_type;
385 
386  DCTELEM (*block)[6][64];
388  uint32_t *cbp_base, *cbp;
390  int16_t (*luma_mv_base)[2], (*luma_mv)[2];
392  uint8_t broken_link;
393  uint8_t closed_entry;
394 
396 
398 } VC1Context;
399 
403 static av_always_inline const uint8_t* find_next_marker(const uint8_t *src, const uint8_t *end)
404 {
405  uint32_t mrk = 0xFFFFFFFF;
406 
407  if (end-src < 4)
408  return end;
409  while (src < end) {
410  mrk = (mrk << 8) | *src++;
411  if (IS_MARKER(mrk))
412  return src - 4;
413  }
414  return end;
415 }
416 
417 static av_always_inline int vc1_unescape_buffer(const uint8_t *src, int size, uint8_t *dst)
418 {
419  int dsize = 0, i;
420 
421  if (size < 4) {
422  for (dsize = 0; dsize < size; dsize++)
423  *dst++ = *src++;
424  return size;
425  }
426  for (i = 0; i < size; i++, src++) {
427  if (src[0] == 3 && i >= 2 && !src[-1] && !src[-2] && i < size-1 && src[1] < 4) {
428  dst[dsize++] = src[1];
429  src++;
430  i++;
431  } else
432  dst[dsize++] = *src;
433  }
434  return dsize;
435 }
436 
445 
447 
451 
452 #endif /* AVCODEC_VC1_H */