Main Page
Related Pages
Modules
Data Structures
Files
Examples
File List
Globals
libavcodec
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,
36
VC1_CODE_SLICE
,
37
VC1_CODE_FIELD
,
38
VC1_CODE_FRAME
,
39
VC1_CODE_ENTRYPOINT
,
40
VC1_CODE_SEQHDR
,
41
};
43
44
#define IS_MARKER(x) (((x) & ~0xFF) == VC1_CODE_RES0)
45
48
enum
Profile
{
49
PROFILE_SIMPLE
,
50
PROFILE_MAIN
,
51
PROFILE_COMPLEX
,
52
PROFILE_ADVANCED
53
};
55
58
enum
QuantMode
{
59
QUANT_FRAME_IMPLICIT
,
60
QUANT_FRAME_EXPLICIT
,
61
QUANT_NON_UNIFORM
,
62
QUANT_UNIFORM
63
};
65
68
enum
DQProfile
{
69
DQPROFILE_FOUR_EDGES
,
70
DQPROFILE_DOUBLE_EDGES
,
71
DQPROFILE_SINGLE_EDGE
,
72
DQPROFILE_ALL_MBS
73
};
75
79
enum
DQSingleEdge
{
80
DQSINGLE_BEDGE_LEFT
,
81
DQSINGLE_BEDGE_TOP
,
82
DQSINGLE_BEDGE_RIGHT
,
83
DQSINGLE_BEDGE_BOTTOM
84
};
86
89
enum
DQDoubleEdge
{
90
DQDOUBLE_BEDGE_TOPLEFT
,
91
DQDOUBLE_BEDGE_TOPRIGHT
,
92
DQDOUBLE_BEDGE_BOTTOMRIGHT
,
93
DQDOUBLE_BEDGE_BOTTOMLEFT
94
};
96
99
enum
MVModes
{
100
MV_PMODE_1MV_HPEL_BILIN
,
101
MV_PMODE_1MV
,
102
MV_PMODE_1MV_HPEL
,
103
MV_PMODE_MIXED_MV
,
104
MV_PMODE_INTENSITY_COMP
105
};
107
110
enum
MBModesIntfr
{
111
MV_PMODE_INTFR_1MV
,
112
MV_PMODE_INTFR_2MV_FIELD
,
113
MV_PMODE_INTFR_2MV
,
114
MV_PMODE_INTFR_4MV_FIELD
,
115
MV_PMODE_INTFR_4MV
,
116
MV_PMODE_INTFR_INTRA
,
117
};
119
122
enum
BMVTypes
{
123
BMV_TYPE_BACKWARD
,
124
BMV_TYPE_FORWARD
,
125
BMV_TYPE_INTERPOLATED
,
126
BMV_TYPE_DIRECT
127
};
129
132
enum
TransformTypes
{
133
TT_8X8
,
134
TT_8X4_BOTTOM
,
135
TT_8X4_TOP
,
136
TT_8X4
,
// both halves
137
TT_4X8_RIGHT
,
138
TT_4X8_LEFT
,
139
TT_4X8
,
// both halves
140
TT_4X4
141
};
143
144
enum
CodingSet
{
145
CS_HIGH_MOT_INTRA
= 0,
146
CS_HIGH_MOT_INTER
,
147
CS_LOW_MOT_INTRA
,
148
CS_LOW_MOT_INTER
,
149
CS_MID_RATE_INTRA
,
150
CS_MID_RATE_INTER
,
151
CS_HIGH_RATE_INTRA
,
152
CS_HIGH_RATE_INTER
153
};
154
157
enum
COTypes
{
158
CONDOVER_NONE
= 0,
159
CONDOVER_ALL
,
160
CONDOVER_SELECT
161
};
163
169
enum
FrameCodingMode
{
170
PROGRESSIVE
= 0,
171
ILACE_FRAME
,
172
ILACE_FIELD
173
};
174
179
typedef
struct
VC1Context
{
180
MpegEncContext
s
;
181
IntraX8Context
x8
;
182
VC1DSPContext
vc1dsp
;
183
184
int
bits
;
185
188
int
res_sprite
;
189
int
res_y411
;
190
int
res_x8
;
191
int
multires
;
192
int
res_fasttx
;
193
int
res_transtab
;
194
int
rangered
;
195
196
int
res_rtm_flag
;
197
int
reserved
;
198
199
202
int
level
;
203
int
chromaformat
;
204
int
postprocflag
;
205
int
broadcast
;
206
int
interlace
;
207
int
tfcntrflag
;
208
int
panscanflag
;
209
int
refdist_flag
;
210
int
extended_dmv
;
211
int
color_prim
;
212
int
transfer_char
;
213
int
matrix_coef
;
214
int
hrd_param_flag
;
215
216
int
psf
;
217
218
223
int
profile
;
224
int
frmrtq_postproc
;
225
int
bitrtq_postproc
;
226
int
fastuvmc
;
227
int
extended_mv
;
228
int
dquant
;
229
int
vstransform
;
230
int
overlap
;
231
int
quantizer_mode
;
232
int
finterpflag
;
233
234
237
uint8_t
mv_mode
;
238
uint8_t
mv_mode2
;
239
int
k_x
;
240
int
k_y
;
241
int
range_x
,
range_y
;
242
uint8_t
pq
,
altpq
;
243
uint8_t
zz_8x8
[4][64];
244
int
left_blk_sh
,
top_blk_sh
;
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
258
int
c_ac_table_index
;
259
int
y_ac_table_index
;
260
261
int
ttfrm
;
262
uint8_t
ttmbf
;
263
int
*
ttblk_base
, *
ttblk
;
264
int
codingset
;
265
int
codingset2
;
266
int
pqindex
;
267
int
a_avail
,
c_avail
;
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
;
279
int
buffer_fullness
;
280
286
uint8_t
mvrange
;
287
uint8_t
pquantizer
;
288
VLC
*
cbpcy_vlc
;
289
int
tt_index
;
290
uint8_t*
mv_type_mb_plane
;
291
uint8_t*
direct_mb_plane
;
292
uint8_t*
forward_mb_plane
;
293
int
mv_type_is_raw
;
294
int
dmb_is_raw
;
295
int
fmb_is_raw
;
296
int
skip_is_raw
;
297
uint8_t
luty
[256],
lutuv
[256];
298
int
use_ic
;
299
int
rnd
;
300
303
uint8_t
rangeredfrm
;
304
uint8_t
interpfrm
;
306
309
enum
FrameCodingMode
fcm
;
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
;
319
int
hrd_num_leaky_buckets
;
320
uint8_t
bit_rate_exponent
;
321
uint8_t
buffer_size_exponent
;
322
uint8_t*
acpred_plane
;
323
int
acpred_is_raw
;
324
uint8_t*
over_flags_plane
;
325
int
overflg_is_raw
;
326
uint8_t
condover
;
327
uint16_t *
hrd_rate
, *
hrd_buffer
;
328
uint8_t *
hrd_fullness
;
329
uint8_t
range_mapy_flag
;
330
uint8_t
range_mapuv_flag
;
331
uint8_t
range_mapy
;
332
uint8_t
range_mapuv
;
334
336
uint8_t
dmvrange
;
337
int
fourmvswitch
;
338
int
intcomp
;
339
uint8_t
lumscale2
;
340
uint8_t
lumshift2
;
341
uint8_t
luty2
[256],
lutuv2
[256];
// lookup tables used for intensity compensation
342
VLC
*
mbmode_vlc
;
343
VLC
*
imv_vlc
;
344
VLC
*
twomvbp_vlc
;
345
VLC
*
fourmvbp_vlc
;
346
uint8_t
twomvbp
;
347
uint8_t
fourmvbp
;
348
uint8_t*
fieldtx_plane
;
349
int
fieldtx_is_raw
;
350
int8_t
zzi_8x8
[64];
351
uint8_t *
blk_mv_type_base
, *
blk_mv_type
;
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];
355
int
field_mode
;
356
int
fptype
;
357
int
second_field
;
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
363
int
intcompfield
;
364
// 0: both fields, 1: bottom field, 2: top field
365
int
cur_field_type
;
366
int
ref_field_type
[2];
367
int
blocks_off
,
mb_off
;
368
int
qs_last
;
369
int
bmvtype
;
370
int
frfd
,
brfd
;
371
int
pic_header_flag
;
372
375
int
new_sprite
;
376
int
two_sprites
;
377
AVFrame
sprite_output_frame
;
378
int
output_width
,
output_height
,
sprite_width
,
sprite_height
;
379
uint8_t*
sr_rows
[2][2];
380
381
382
int
p_frame_skipped
;
383
int
bi_type
;
384
int
x8_type
;
385
386
DCTELEM
(*
block
)[6][64];
387
int
n_allocated_blks
,
cur_blk_idx
,
left_blk_idx
,
topleft_blk_idx
,
top_blk_idx
;
388
uint32_t *
cbp_base
, *
cbp
;
389
uint8_t *
is_intra_base
, *
is_intra
;
390
int16_t (*
luma_mv_base
)[2], (*luma_mv)[2];
391
uint8_t
bfraction_lut_index
;
392
uint8_t
broken_link
;
393
uint8_t
closed_entry
;
394
395
int
parse_only
;
396
397
int
warn_interlaced
;
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
444
int
vc1_decode_sequence_header
(
AVCodecContext
*avctx,
VC1Context
*
v
,
GetBitContext
*gb);
445
446
int
vc1_decode_entry_point
(
AVCodecContext
*avctx,
VC1Context
*
v
,
GetBitContext
*gb);
447
448
int
vc1_parse_frame_header
(
VC1Context
*
v
,
GetBitContext
*gb);
449
int
vc1_parse_frame_header_adv
(
VC1Context
*
v
,
GetBitContext
*gb);
450
int
ff_vc1_init_common
(
VC1Context
*
v
);
451
452
#endif
/* AVCODEC_VC1_H */