Statistics
| Branch: | Revision:

ffmpeg / libavcodec / vc1.h @ 58683d27

History | View | Annotate | Download (11.7 KB)

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 FFmpeg.
7
 *
8
 * FFmpeg 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
 * FFmpeg 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 FFmpeg; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
 */
22

    
23
/** Markers used in VC-1 AP frame data */
24
//@{
25
enum VC1Code{
26
    VC1_CODE_RES0       = 0x00000100,
27
    VC1_CODE_ENDOFSEQ   = 0x0000010A,
28
    VC1_CODE_SLICE,
29
    VC1_CODE_FIELD,
30
    VC1_CODE_FRAME,
31
    VC1_CODE_ENTRYPOINT,
32
    VC1_CODE_SEQHDR,
33
};
34
//@}
35

    
36
#define IS_MARKER(x) (((x) & ~0xFF) == VC1_CODE_RES0)
37

    
38
#ifndef VC1_PARSER_ONLY
39
/** Available Profiles */
40
//@{
41
enum Profile {
42
    PROFILE_SIMPLE,
43
    PROFILE_MAIN,
44
    PROFILE_COMPLEX, ///< TODO: WMV9 specific
45
    PROFILE_ADVANCED
46
};
47
//@}
48

    
49
/** Sequence quantizer mode */
50
//@{
51
enum QuantMode {
52
    QUANT_FRAME_IMPLICIT,    ///< Implicitly specified at frame level
53
    QUANT_FRAME_EXPLICIT,    ///< Explicitly specified at frame level
54
    QUANT_NON_UNIFORM,       ///< Non-uniform quant used for all frames
55
    QUANT_UNIFORM            ///< Uniform quant used for all frames
56
};
57
//@}
58

    
59
/** Where quant can be changed */
60
//@{
61
enum DQProfile {
62
    DQPROFILE_FOUR_EDGES,
63
    DQPROFILE_DOUBLE_EDGES,
64
    DQPROFILE_SINGLE_EDGE,
65
    DQPROFILE_ALL_MBS
66
};
67
//@}
68

    
69
/** @name Where quant can be changed
70
 */
71
//@{
72
enum DQSingleEdge {
73
    DQSINGLE_BEDGE_LEFT,
74
    DQSINGLE_BEDGE_TOP,
75
    DQSINGLE_BEDGE_RIGHT,
76
    DQSINGLE_BEDGE_BOTTOM
77
};
78
//@}
79

    
80
/** Which pair of edges is quantized with ALTPQUANT */
81
//@{
82
enum DQDoubleEdge {
83
    DQDOUBLE_BEDGE_TOPLEFT,
84
    DQDOUBLE_BEDGE_TOPRIGHT,
85
    DQDOUBLE_BEDGE_BOTTOMRIGHT,
86
    DQDOUBLE_BEDGE_BOTTOMLEFT
87
};
88
//@}
89

    
90
/** MV modes for P frames */
91
//@{
92
enum MVModes {
93
    MV_PMODE_1MV_HPEL_BILIN,
94
    MV_PMODE_1MV,
95
    MV_PMODE_1MV_HPEL,
96
    MV_PMODE_MIXED_MV,
97
    MV_PMODE_INTENSITY_COMP
98
};
99
//@}
100

    
101
/** @name MV types for B frames */
102
//@{
103
enum BMVTypes {
104
    BMV_TYPE_BACKWARD,
105
    BMV_TYPE_FORWARD,
106
    BMV_TYPE_INTERPOLATED
107
};
108
//@}
109

    
110
/** @name Block types for P/B frames */
111
//@{
112
enum TransformTypes {
113
    TT_8X8,
114
    TT_8X4_BOTTOM,
115
    TT_8X4_TOP,
116
    TT_8X4, //Both halves
117
    TT_4X8_RIGHT,
118
    TT_4X8_LEFT,
119
    TT_4X8, //Both halves
120
    TT_4X4
121
};
122
//@}
123

    
124
/** Table for conversion between TTBLK and TTMB */
125
static const int ttblk_to_tt[3][8] = {
126
  { TT_8X4, TT_4X8, TT_8X8, TT_4X4, TT_8X4_TOP, TT_8X4_BOTTOM, TT_4X8_RIGHT, TT_4X8_LEFT },
127
  { TT_8X8, TT_4X8_RIGHT, TT_4X8_LEFT, TT_4X4, TT_8X4, TT_4X8, TT_8X4_BOTTOM, TT_8X4_TOP },
128
  { TT_8X8, TT_4X8, TT_4X4, TT_8X4_BOTTOM, TT_4X8_RIGHT, TT_4X8_LEFT, TT_8X4, TT_8X4_TOP }
129
};
130

    
131
static const int ttfrm_to_tt[4] = { TT_8X8, TT_8X4, TT_4X8, TT_4X4 };
132

    
133
/** MV P mode - the 5th element is only used for mode 1 */
134
static const uint8_t mv_pmode_table[2][5] = {
135
  { MV_PMODE_1MV_HPEL_BILIN, MV_PMODE_1MV, MV_PMODE_1MV_HPEL, MV_PMODE_INTENSITY_COMP, MV_PMODE_MIXED_MV },
136
  { MV_PMODE_1MV, MV_PMODE_MIXED_MV, MV_PMODE_1MV_HPEL, MV_PMODE_INTENSITY_COMP, MV_PMODE_1MV_HPEL_BILIN }
137
};
138
static const uint8_t mv_pmode_table2[2][4] = {
139
  { MV_PMODE_1MV_HPEL_BILIN, MV_PMODE_1MV, MV_PMODE_1MV_HPEL, MV_PMODE_MIXED_MV },
140
  { MV_PMODE_1MV, MV_PMODE_MIXED_MV, MV_PMODE_1MV_HPEL, MV_PMODE_1MV_HPEL_BILIN }
141
};
142

    
143
/** One more frame type */
144
#define BI_TYPE 7
145

    
146
static const int fps_nr[5] = { 24, 25, 30, 50, 60 },
147
  fps_dr[2] = { 1000, 1001 };
148
static const uint8_t pquant_table[3][32] = {
149
  {  /* Implicit quantizer */
150
     0,  1,  2,  3,  4,  5,  6,  7,  8,  6,  7,  8,  9, 10, 11, 12,
151
    13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 29, 31
152
  },
153
  {  /* Explicit quantizer, pquantizer uniform */
154
     0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
155
    16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
156
  },
157
  {  /* Explicit quantizer, pquantizer non-uniform */
158
     0,  1,  1,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13,
159
    14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 31
160
  }
161
};
162

    
163
/** @name VC-1 VLC tables and defines
164
 *  @todo TODO move this into the context
165
 */
166
//@{
167
#define VC1_BFRACTION_VLC_BITS 7
168
static VLC vc1_bfraction_vlc;
169
#define VC1_IMODE_VLC_BITS 4
170
static VLC vc1_imode_vlc;
171
#define VC1_NORM2_VLC_BITS 3
172
static VLC vc1_norm2_vlc;
173
#define VC1_NORM6_VLC_BITS 9
174
static VLC vc1_norm6_vlc;
175
/* Could be optimized, one table only needs 8 bits */
176
#define VC1_TTMB_VLC_BITS 9 //12
177
static VLC vc1_ttmb_vlc[3];
178
#define VC1_MV_DIFF_VLC_BITS 9 //15
179
static VLC vc1_mv_diff_vlc[4];
180
#define VC1_CBPCY_P_VLC_BITS 9 //14
181
static VLC vc1_cbpcy_p_vlc[4];
182
#define VC1_4MV_BLOCK_PATTERN_VLC_BITS 6
183
static VLC vc1_4mv_block_pattern_vlc[4];
184
#define VC1_TTBLK_VLC_BITS 5
185
static VLC vc1_ttblk_vlc[3];
186
#define VC1_SUBBLKPAT_VLC_BITS 6
187
static VLC vc1_subblkpat_vlc[3];
188

    
189
static VLC vc1_ac_coeff_table[8];
190
//@}
191

    
192
enum CodingSet {
193
    CS_HIGH_MOT_INTRA = 0,
194
    CS_HIGH_MOT_INTER,
195
    CS_LOW_MOT_INTRA,
196
    CS_LOW_MOT_INTER,
197
    CS_MID_RATE_INTRA,
198
    CS_MID_RATE_INTER,
199
    CS_HIGH_RATE_INTRA,
200
    CS_HIGH_RATE_INTER
201
};
202

    
203
/** @name Overlap conditions for Advanced Profile */
204
//@{
205
enum COTypes {
206
    CONDOVER_NONE = 0,
207
    CONDOVER_ALL,
208
    CONDOVER_SELECT
209
};
210
//@}
211

    
212

    
213
/** The VC1 Context
214
 * @fixme Change size wherever another size is more efficient
215
 * Many members are only used for Advanced Profile
216
 */
217
typedef struct VC1Context{
218
    MpegEncContext s;
219

    
220
    int bits;
221

    
222
    /** Simple/Main Profile sequence header */
223
    //@{
224
    int res_sm;           ///< reserved, 2b
225
    int res_x8;           ///< reserved
226
    int multires;         ///< frame-level RESPIC syntax element present
227
    int res_fasttx;       ///< reserved, always 1
228
    int res_transtab;     ///< reserved, always 0
229
    int rangered;         ///< RANGEREDFRM (range reduction) syntax element present
230
                          ///< at frame level
231
    int res_rtm_flag;     ///< reserved, set to 1
232
    int reserved;         ///< reserved
233
    //@}
234

    
235
    /** Advanced Profile */
236
    //@{
237
    int level;            ///< 3bits, for Advanced/Simple Profile, provided by TS layer
238
    int chromaformat;     ///< 2bits, 2=4:2:0, only defined
239
    int postprocflag;     ///< Per-frame processing suggestion flag present
240
    int broadcast;        ///< TFF/RFF present
241
    int interlace;        ///< Progressive/interlaced (RPTFTM syntax element)
242
    int tfcntrflag;       ///< TFCNTR present
243
    int panscanflag;      ///< NUMPANSCANWIN, TOPLEFT{X,Y}, BOTRIGHT{X,Y} present
244
    int extended_dmv;     ///< Additional extended dmv range at P/B frame-level
245
    int color_prim;       ///< 8bits, chroma coordinates of the color primaries
246
    int transfer_char;    ///< 8bits, Opto-electronic transfer characteristics
247
    int matrix_coef;      ///< 8bits, Color primaries->YCbCr transform matrix
248
    int hrd_param_flag;   ///< Presence of Hypothetical Reference
249
                          ///< Decoder parameters
250
    int psf;              ///< Progressive Segmented Frame
251
    //@}
252

    
253
    /** Sequence header data for all Profiles
254
     * TODO: choose between ints, uint8_ts and monobit flags
255
     */
256
    //@{
257
    int profile;          ///< 2bits, Profile
258
    int frmrtq_postproc;  ///< 3bits,
259
    int bitrtq_postproc;  ///< 5bits, quantized framerate-based postprocessing strength
260
    int fastuvmc;         ///< Rounding of qpel vector to hpel ? (not in Simple)
261
    int extended_mv;      ///< Ext MV in P/B (not in Simple)
262
    int dquant;           ///< How qscale varies with MBs, 2bits (not in Simple)
263
    int vstransform;      ///< variable-size [48]x[48] transform type + info
264
    int overlap;          ///< overlapped transforms in use
265
    int quantizer_mode;   ///< 2bits, quantizer mode used for sequence, see QUANT_*
266
    int finterpflag;      ///< INTERPFRM present
267
    //@}
268

    
269
    /** Frame decoding info for all profiles */
270
    //@{
271
    uint8_t mv_mode;      ///< MV coding monde
272
    uint8_t mv_mode2;     ///< Secondary MV coding mode (B frames)
273
    int k_x;              ///< Number of bits for MVs (depends on MV range)
274
    int k_y;              ///< Number of bits for MVs (depends on MV range)
275
    int range_x, range_y; ///< MV range
276
    uint8_t pq, altpq;    ///< Current/alternate frame quantizer scale
277
    /** pquant parameters */
278
    //@{
279
    uint8_t dquantfrm;
280
    uint8_t dqprofile;
281
    uint8_t dqsbedge;
282
    uint8_t dqbilevel;
283
    //@}
284
    /** AC coding set indexes
285
     * @see 8.1.1.10, p(1)10
286
     */
287
    //@{
288
    int c_ac_table_index; ///< Chroma index from ACFRM element
289
    int y_ac_table_index; ///< Luma index from AC2FRM element
290
    //@}
291
    int ttfrm;            ///< Transform type info present at frame level
292
    uint8_t ttmbf;        ///< Transform type flag
293
    uint8_t ttblk4x4;     ///< Value of ttblk which indicates a 4x4 transform
294
    int codingset;        ///< index of current table set from 11.8 to use for luma block decoding
295
    int codingset2;       ///< index of current table set from 11.8 to use for chroma block decoding
296
    int pqindex;          ///< raw pqindex used in coding set selection
297
    int a_avail, c_avail;
298
    uint8_t *mb_type_base, *mb_type[3];
299

    
300

    
301
    /** Luma compensation parameters */
302
    //@{
303
    uint8_t lumscale;
304
    uint8_t lumshift;
305
    //@}
306
    int16_t bfraction;    ///< Relative position % anchors=> how to scale MVs
307
    uint8_t halfpq;       ///< Uniform quant over image and qp+.5
308
    uint8_t respic;       ///< Frame-level flag for resized images
309
    int buffer_fullness;  ///< HRD info
310
    /** Ranges:
311
     * -# 0 -> [-64n 63.f] x [-32, 31.f]
312
     * -# 1 -> [-128, 127.f] x [-64, 63.f]
313
     * -# 2 -> [-512, 511.f] x [-128, 127.f]
314
     * -# 3 -> [-1024, 1023.f] x [-256, 255.f]
315
     */
316
    uint8_t mvrange;
317
    uint8_t pquantizer;           ///< Uniform (over sequence) quantizer in use
318
    VLC *cbpcy_vlc;               ///< CBPCY VLC table
319
    int tt_index;                 ///< Index for Transform Type tables
320
    uint8_t* mv_type_mb_plane;    ///< bitplane for mv_type == (4MV)
321
    uint8_t* direct_mb_plane;     ///< bitplane for "direct" MBs
322
    int mv_type_is_raw;           ///< mv type mb plane is not coded
323
    int dmb_is_raw;               ///< direct mb plane is raw
324
    int skip_is_raw;              ///< skip mb plane is not coded
325
    uint8_t luty[256], lutuv[256]; // lookup tables used for intensity compensation
326
    int use_ic;                   ///< use intensity compensation in B-frames
327
    int rnd;                      ///< rounding control
328

    
329
    /** Frame decoding info for S/M profiles only */
330
    //@{
331
    uint8_t rangeredfrm; ///< out_sample = CLIP((in_sample-128)*2+128)
332
    uint8_t interpfrm;
333
    //@}
334

    
335
    /** Frame decoding info for Advanced profile */
336
    //@{
337
    uint8_t fcm; ///< 0->Progressive, 2->Frame-Interlace, 3->Field-Interlace
338
    uint8_t numpanscanwin;
339
    uint8_t tfcntr;
340
    uint8_t rptfrm, tff, rff;
341
    uint16_t topleftx;
342
    uint16_t toplefty;
343
    uint16_t bottomrightx;
344
    uint16_t bottomrighty;
345
    uint8_t uvsamp;
346
    uint8_t postproc;
347
    int hrd_num_leaky_buckets;
348
    uint8_t bit_rate_exponent;
349
    uint8_t buffer_size_exponent;
350
    uint8_t* acpred_plane;       ///< AC prediction flags bitplane
351
    int acpred_is_raw;
352
    uint8_t* over_flags_plane;   ///< Overflags bitplane
353
    int overflg_is_raw;
354
    uint8_t condover;
355
    uint16_t *hrd_rate, *hrd_buffer;
356
    uint8_t *hrd_fullness;
357
    uint8_t range_mapy_flag;
358
    uint8_t range_mapuv_flag;
359
    uint8_t range_mapy;
360
    uint8_t range_mapuv;
361
    //@}
362

    
363
    int p_frame_skipped;
364
    int bi_type;
365
} VC1Context;
366
#endif