Libav
Main Page
Related Pages
Modules
Data Structures
Files
Examples
File List
Globals
libavcodec
vp9.h
Go to the documentation of this file.
1
/*
2
* VP9 compatible video decoder
3
*
4
* Copyright (C) 2013 Ronald S. Bultje <rsbultje gmail com>
5
* Copyright (C) 2013 Clément Bœsch <u pkh me>
6
*
7
* This file is part of Libav.
8
*
9
* Libav 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
* Libav 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 Libav; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
*/
23
24
#ifndef AVCODEC_VP9_H
25
#define AVCODEC_VP9_H
26
27
#include <stddef.h>
28
#include <stdint.h>
29
30
#include "
libavutil/internal.h
"
31
32
#include "
avcodec.h
"
33
#include "
vp56.h
"
34
35
enum
TxfmMode
{
36
TX_4X4
,
37
TX_8X8
,
38
TX_16X16
,
39
TX_32X32
,
40
N_TXFM_SIZES
,
41
TX_SWITCHABLE
=
N_TXFM_SIZES
,
42
N_TXFM_MODES
43
};
44
45
enum
TxfmType
{
46
DCT_DCT
,
47
DCT_ADST
,
48
ADST_DCT
,
49
ADST_ADST
,
50
N_TXFM_TYPES
51
};
52
53
enum
IntraPredMode
{
54
VERT_PRED
,
55
HOR_PRED
,
56
DC_PRED
,
57
DIAG_DOWN_LEFT_PRED
,
58
DIAG_DOWN_RIGHT_PRED
,
59
VERT_RIGHT_PRED
,
60
HOR_DOWN_PRED
,
61
VERT_LEFT_PRED
,
62
HOR_UP_PRED
,
63
TM_VP8_PRED
,
64
LEFT_DC_PRED
,
65
TOP_DC_PRED
,
66
DC_128_PRED
,
67
DC_127_PRED
,
68
DC_129_PRED
,
69
N_INTRA_PRED_MODES
70
};
71
72
enum
FilterMode
{
73
FILTER_8TAP_SMOOTH
,
74
FILTER_8TAP_REGULAR
,
75
FILTER_8TAP_SHARP
,
76
FILTER_BILINEAR
,
77
FILTER_SWITCHABLE
,
78
};
79
80
enum
BlockPartition
{
81
PARTITION_NONE
,
// [ ] <-.
82
PARTITION_H
,
// [-] |
83
PARTITION_V
,
// [|] |
84
PARTITION_SPLIT
,
// [+] --'
85
};
86
87
enum
InterPredMode
{
88
NEARESTMV
= 10,
89
NEARMV
= 11,
90
ZEROMV
= 12,
91
NEWMV
= 13,
92
};
93
94
enum
MVJoint
{
95
MV_JOINT_ZERO
,
96
MV_JOINT_H
,
97
MV_JOINT_V
,
98
MV_JOINT_HV
,
99
};
100
101
typedef
struct
ProbContext
{
102
uint8_t
y_mode
[4][9];
103
uint8_t
uv_mode
[10][9];
104
uint8_t
filter
[4][2];
105
uint8_t
mv_mode
[7][3];
106
uint8_t
intra
[4];
107
uint8_t
comp
[5];
108
uint8_t
single_ref
[5][2];
109
uint8_t
comp_ref
[5];
110
uint8_t
tx32p
[2][3];
111
uint8_t
tx16p
[2][2];
112
uint8_t
tx8p
[2];
113
uint8_t
skip
[3];
114
uint8_t
mv_joint
[3];
115
struct
{
116
uint8_t
sign
;
117
uint8_t
classes
[10];
118
uint8_t
class0
;
119
uint8_t
bits
[10];
120
uint8_t
class0_fp
[2][3];
121
uint8_t
fp
[3];
122
uint8_t
class0_hp
;
123
uint8_t
hp
;
124
}
mv_comp
[2];
125
uint8_t
partition
[4][4][3];
126
}
ProbContext
;
127
128
typedef
void
(*
vp9_mc_func
)(
uint8_t
*dst,
const
uint8_t
*ref,
129
ptrdiff_t dst_stride,
130
ptrdiff_t ref_stride,
131
int
h,
int
mx,
int
my);
132
133
typedef
struct
VP9DSPContext
{
134
/*
135
* dimension 1: 0=4x4, 1=8x8, 2=16x16, 3=32x32
136
* dimension 2: intra prediction modes
137
*
138
* dst/left/top is aligned by transform-size (i.e. 4, 8, 16 or 32 pixels)
139
* stride is aligned by 16 pixels
140
* top[-1] is top/left; top[4,7] is top-right for 4x4
141
*/
142
// FIXME(rbultje) maybe replace left/top pointers with HAVE_TOP/
143
// HAVE_LEFT/HAVE_TOPRIGHT flags instead, and then handle it in-place?
144
// also needs to fit in with what h264/vp8/etc do
145
void
(*
intra_pred
[
N_TXFM_SIZES
][
N_INTRA_PRED_MODES
])(
uint8_t
*dst,
146
ptrdiff_t
stride
,
147
const
uint8_t
*left,
148
const
uint8_t
*top);
149
150
/*
151
* dimension 1: 0=4x4, 1=8x8, 2=16x16, 3=32x32, 4=lossless (3-4=dct only)
152
* dimension 2: 0=dct/dct, 1=dct/adst, 2=adst/dct, 3=adst/adst
153
*
154
* dst is aligned by transform-size (i.e. 4, 8, 16 or 32 pixels)
155
* stride is aligned by 16 pixels
156
* block is 16-byte aligned
157
* eob indicates the position (+1) of the last non-zero coefficient,
158
* in scan-order. This can be used to write faster versions, e.g. a
159
* dc-only 4x4/8x8/16x16/32x32, or a 4x4-only (eob<10) 8x8/16x16/32x32,
160
* etc.
161
*/
162
// FIXME also write idct_add_block() versions for whole (inter) pred
163
// blocks, so we can do 2 4x4s at once
164
void
(*
itxfm_add
[
N_TXFM_SIZES
+ 1][
N_TXFM_TYPES
])(
uint8_t
*dst,
165
ptrdiff_t
stride
,
166
int16_t *
block
,
int
eob);
167
168
/*
169
* dimension 1: width of filter (0=4, 1=8, 2=16)
170
* dimension 2: 0=col-edge filter (h), 1=row-edge filter (v)
171
*
172
* dst/stride are aligned by 8
173
*/
174
void
(*
loop_filter_8
[3][2])(
uint8_t
*dst, ptrdiff_t
stride
,
175
int
mb_lim,
int
lim,
int
hev_thr);
176
177
/*
178
* dimension 1: 0=col-edge filter (h), 1=row-edge filter (v)
179
*
180
* The width of filter is assumed to be 16; dst/stride are aligned by 16
181
*/
182
void
(*
loop_filter_16
[2])(
uint8_t
*dst, ptrdiff_t
stride
,
183
int
mb_lim,
int
lim,
int
hev_thr);
184
185
/*
186
* dimension 1/2: width of filter (0=4, 1=8) for each filter half
187
* dimension 3: 0=col-edge filter (h), 1=row-edge filter (v)
188
*
189
* dst/stride are aligned by operation size
190
* this basically calls loop_filter[d1][d3][0](), followed by
191
* loop_filter[d2][d3][0]() on the next 8 pixels
192
* mb_lim/lim/hev_thr contain two values in the lowest two bytes of the
193
* integer.
194
*/
195
// FIXME perhaps a mix4 that operates on 32px (for AVX2)
196
void
(*
loop_filter_mix2
[2][2][2])(
uint8_t
*dst, ptrdiff_t
stride
,
197
int
mb_lim,
int
lim,
int
hev_thr);
198
199
/*
200
* dimension 1: hsize (0: 64, 1: 32, 2: 16, 3: 8, 4: 4)
201
* dimension 2: filter type (0: smooth, 1: regular, 2: sharp, 3: bilin)
202
* dimension 3: averaging type (0: put, 1: avg)
203
* dimension 4: x subpel interpolation (0: none, 1: 8tap/bilin)
204
* dimension 5: y subpel interpolation (1: none, 1: 8tap/bilin)
205
*
206
* dst/stride are aligned by hsize
207
*/
208
vp9_mc_func
mc
[5][4][2][2][2];
209
}
VP9DSPContext
;
210
211
enum
CompPredMode
{
212
PRED_SINGLEREF
,
213
PRED_COMPREF
,
214
PRED_SWITCHABLE
,
215
};
216
217
typedef
struct
VP9MVRefPair
{
218
VP56mv
mv
[2];
219
int8_t
ref
[2];
220
}
VP9MVRefPair
;
221
222
typedef
struct
VP9Filter
{
223
uint8_t
level
[8 * 8];
224
uint8_t
/* bit=col */
mask
[2
/* 0=y, 1=uv */
][2
/* 0=col, 1=row */
]
225
[8
/* rows */
][4
/* 0=16, 1=8, 2=4, 3=inner4 */
];
226
}
VP9Filter
;
227
228
enum
BlockLevel
{
229
BL_64X64
,
230
BL_32X32
,
231
BL_16X16
,
232
BL_8X8
,
233
};
234
235
enum
BlockSize
{
236
BS_64x64
,
237
BS_64x32
,
238
BS_32x64
,
239
BS_32x32
,
240
BS_32x16
,
241
BS_16x32
,
242
BS_16x16
,
243
BS_16x8
,
244
BS_8x16
,
245
BS_8x8
,
246
BS_8x4
,
247
BS_4x8
,
248
BS_4x4
,
249
N_BS_SIZES
,
250
};
251
252
typedef
struct
VP9Block
{
253
uint8_t
seg_id
,
intra
,
comp
,
ref
[2],
mode
[4],
uvmode
,
skip
;
254
enum
FilterMode
filter
;
255
VP56mv
mv
[4
/* b_idx */
][2
/* ref */
];
256
enum
BlockSize
bs
;
257
enum
TxfmMode
tx,
uvtx
;
258
259
int
row
,
row7
,
col
,
col7
;
260
uint8_t
*
dst
[3];
261
ptrdiff_t
y_stride
,
uv_stride
;
262
}
VP9Block
;
263
264
typedef
struct
VP9Context
{
265
VP9DSPContext
dsp
;
266
VideoDSPContext
vdsp
;
267
GetBitContext
gb
;
268
VP56RangeCoder
c
;
269
VP56RangeCoder
*
c_b
;
270
unsigned
c_b_size
;
271
VP9Block
b
;
272
273
// bitstream header
274
uint8_t
profile
;
275
uint8_t
keyframe
,
last_keyframe
;
276
uint8_t
invisible
;
277
uint8_t
use_last_frame_mvs
;
278
uint8_t
errorres
;
279
uint8_t
colorspace
;
280
uint8_t
fullrange
;
281
uint8_t
intraonly
;
282
uint8_t
resetctx
;
283
uint8_t
refreshrefmask
;
284
uint8_t
highprecisionmvs
;
285
enum
FilterMode
filtermode
;
286
uint8_t
allowcompinter
;
287
uint8_t
fixcompref
;
288
uint8_t
refreshctx
;
289
uint8_t
parallelmode
;
290
uint8_t
framectxid
;
291
uint8_t
refidx
[3];
292
uint8_t
signbias
[3];
293
uint8_t
varcompref
[2];
294
AVFrame
*
refs
[8];
295
AVFrame
*
cur_frame
;
296
297
struct
{
298
uint8_t
level
;
299
int8_t
sharpness
;
300
uint8_t
lim_lut
[64];
301
uint8_t
mblim_lut
[64];
302
}
filter
;
303
struct
{
304
uint8_t
enabled
;
305
int8_t
mode
[2];
306
int8_t
ref
[4];
307
}
lf_delta
;
308
uint8_t
yac_qi
;
309
int8_t
ydc_qdelta
,
uvdc_qdelta
,
uvac_qdelta
;
310
uint8_t
lossless
;
311
struct
{
312
uint8_t
enabled
;
313
uint8_t
temporal
;
314
uint8_t
absolute_vals
;
315
uint8_t
update_map
;
316
struct
{
317
uint8_t
q_enabled
;
318
uint8_t
lf_enabled
;
319
uint8_t
ref_enabled
;
320
uint8_t
skip_enabled
;
321
uint8_t
ref_val
;
322
int16_t
q_val
;
323
int8_t
lf_val
;
324
int16_t
qmul
[2][2];
325
uint8_t
lflvl
[4][2];
326
}
feat
[8];
327
}
segmentation
;
328
struct
{
329
unsigned
log2_tile_cols
,
log2_tile_rows
;
330
unsigned
tile_cols
,
tile_rows
;
331
unsigned
tile_row_start
,
tile_row_end
,
tile_col_start
,
tile_col_end
;
332
}
tiling
;
333
unsigned
sb_cols
,
sb_rows
,
rows
,
cols
;
334
struct
{
335
ProbContext
p
;
336
uint8_t
coef
[4][2][2][6][6][3];
337
}
prob_ctx
[4];
338
struct
{
339
ProbContext
p
;
340
uint8_t
coef
[4][2][2][6][6][11];
341
uint8_t
seg
[7];
342
uint8_t
segpred
[3];
343
}
prob
;
344
struct
{
345
unsigned
y_mode
[4][10];
346
unsigned
uv_mode
[10][10];
347
unsigned
filter
[4][3];
348
unsigned
mv_mode
[7][4];
349
unsigned
intra
[4][2];
350
unsigned
comp
[5][2];
351
unsigned
single_ref
[5][2][2];
352
unsigned
comp_ref
[5][2];
353
unsigned
tx32p
[2][4];
354
unsigned
tx16p
[2][3];
355
unsigned
tx8p
[2][2];
356
unsigned
skip
[3][2];
357
unsigned
mv_joint
[4];
358
struct
{
359
unsigned
sign
[2];
360
unsigned
classes
[11];
361
unsigned
class0
[2];
362
unsigned
bits
[10][2];
363
unsigned
class0_fp
[2][4];
364
unsigned
fp
[4];
365
unsigned
class0_hp
[2];
366
unsigned
hp
[2];
367
}
mv_comp
[2];
368
unsigned
partition
[4][4][4];
369
unsigned
coef
[4][2][2][6][6][3];
370
unsigned
eob
[4][2][2][6][6][2];
371
}
counts
;
372
enum
TxfmMode
txfmmode
;
373
enum
CompPredMode
comppredmode
;
374
375
// contextual (left/above) cache
376
uint8_t
left_partition_ctx
[8], *
above_partition_ctx
;
377
uint8_t
left_mode_ctx
[16], *
above_mode_ctx
;
378
// FIXME maybe merge some of the below in a flags field?
379
uint8_t
left_y_nnz_ctx
[16], *
above_y_nnz_ctx
;
380
uint8_t
left_uv_nnz_ctx
[2][8], *
above_uv_nnz_ctx
[2];
381
uint8_t
left_skip_ctx
[8], *
above_skip_ctx
;
// 1bit
382
uint8_t
left_txfm_ctx
[8], *
above_txfm_ctx
;
// 2bit
383
uint8_t
left_segpred_ctx
[8], *
above_segpred_ctx
;
// 1bit
384
uint8_t
left_intra_ctx
[8], *
above_intra_ctx
;
// 1bit
385
uint8_t
left_comp_ctx
[8], *
above_comp_ctx
;
// 1bit
386
uint8_t
left_ref_ctx
[8], *
above_ref_ctx
;
// 2bit
387
uint8_t
left_filter_ctx
[8], *
above_filter_ctx
;
388
VP56mv
left_mv_ctx
[16][2], (*above_mv_ctx)[2];
389
390
// whole-frame cache
391
uint8_t
*
intra_pred_data
[3];
392
uint8_t
*
segmentation_map
;
393
VP9MVRefPair
*
mv
[2];
394
VP9Filter
*
lflvl
;
395
DECLARE_ALIGNED
(32,
uint8_t
,
edge_emu_buffer
)[71 * 80];
396
397
// block reconstruction intermediates
398
DECLARE_ALIGNED
(32, int16_t,
block
)[4096];
399
DECLARE_ALIGNED
(32, int16_t,
uvblock
)[2][1024];
400
uint8_t
eob
[256];
401
uint8_t
uveob
[2][64];
402
VP56mv
min_mv
,
max_mv
;
403
DECLARE_ALIGNED
(32,
uint8_t
,
tmp_y
)[64 * 64];
404
DECLARE_ALIGNED
(32,
uint8_t
,
tmp_uv
)[2][32 * 32];
405
}
VP9Context
;
406
407
void
ff_vp9dsp_init
(
VP9DSPContext
*dsp);
408
409
void
ff_vp9dsp_init_x86
(
VP9DSPContext
*dsp);
410
411
void
ff_vp9_fill_mv
(
VP9Context
*s,
VP56mv
*
mv
,
int
mode,
int
sb);
412
413
void
ff_vp9_adapt_probs
(
VP9Context
*s);
414
415
int
ff_vp9_decode_block
(
AVCodecContext
*avctx,
int
row,
int
col,
416
VP9Filter
*lflvl, ptrdiff_t yoff, ptrdiff_t uvoff,
417
enum
BlockLevel
bl,
enum
BlockPartition
bp);
418
419
#endif
/* AVCODEC_VP9_H */
Generated on Tue Mar 1 2016 21:14:47 for Libav by
1.8.4