Libav
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/buffer.h"
31 #include "libavutil/internal.h"
32 
33 #include "avcodec.h"
34 #include "thread.h"
35 #include "vp56.h"
36 
37 enum TxfmMode {
45 };
46 
47 enum TxfmType {
53 };
54 
72 };
73 
74 enum FilterMode {
80 };
81 
83  PARTITION_NONE, // [ ] <-.
84  PARTITION_H, // [-] |
85  PARTITION_V, // [|] |
86  PARTITION_SPLIT, // [+] --'
87 };
88 
90  NEARESTMV = 10,
91  NEARMV = 11,
92  ZEROMV = 12,
93  NEWMV = 13,
94 };
95 
96 enum MVJoint {
101 };
102 
103 typedef struct ProbContext {
105  uint8_t uv_mode[10][9];
112  uint8_t tx32p[2][3];
113  uint8_t tx16p[2][2];
117  struct {
126  } mv_comp[2];
127  uint8_t partition[4][4][3];
128 } ProbContext;
129 
130 typedef void (*vp9_mc_func)(uint8_t *dst, const uint8_t *ref,
131  ptrdiff_t dst_stride,
132  ptrdiff_t ref_stride,
133  int h, int mx, int my);
134 
135 typedef struct VP9DSPContext {
136  /*
137  * dimension 1: 0=4x4, 1=8x8, 2=16x16, 3=32x32
138  * dimension 2: intra prediction modes
139  *
140  * dst/left/top is aligned by transform-size (i.e. 4, 8, 16 or 32 pixels)
141  * stride is aligned by 16 pixels
142  * top[-1] is top/left; top[4,7] is top-right for 4x4
143  */
144  // FIXME(rbultje) maybe replace left/top pointers with HAVE_TOP/
145  // HAVE_LEFT/HAVE_TOPRIGHT flags instead, and then handle it in-place?
146  // also needs to fit in with what H.264/VP8/etc do
148  ptrdiff_t stride,
149  const uint8_t *left,
150  const uint8_t *top);
151 
152  /*
153  * dimension 1: 0=4x4, 1=8x8, 2=16x16, 3=32x32, 4=lossless (3-4=dct only)
154  * dimension 2: 0=dct/dct, 1=dct/adst, 2=adst/dct, 3=adst/adst
155  *
156  * dst is aligned by transform-size (i.e. 4, 8, 16 or 32 pixels)
157  * stride is aligned by 16 pixels
158  * block is 16-byte aligned
159  * eob indicates the position (+1) of the last non-zero coefficient,
160  * in scan-order. This can be used to write faster versions, e.g. a
161  * dc-only 4x4/8x8/16x16/32x32, or a 4x4-only (eob<10) 8x8/16x16/32x32,
162  * etc.
163  */
164  // FIXME also write idct_add_block() versions for whole (inter) pred
165  // blocks, so we can do 2 4x4s at once
166  void (*itxfm_add[N_TXFM_SIZES + 1][N_TXFM_TYPES])(uint8_t *dst,
167  ptrdiff_t stride,
168  int16_t *block, int eob);
169 
170  /*
171  * dimension 1: width of filter (0=4, 1=8, 2=16)
172  * dimension 2: 0=col-edge filter (h), 1=row-edge filter (v)
173  *
174  * dst/stride are aligned by 8
175  */
176  void (*loop_filter_8[3][2])(uint8_t *dst, ptrdiff_t stride,
177  int mb_lim, int lim, int hev_thr);
178 
179  /*
180  * dimension 1: 0=col-edge filter (h), 1=row-edge filter (v)
181  *
182  * The width of filter is assumed to be 16; dst/stride are aligned by 16
183  */
184  void (*loop_filter_16[2])(uint8_t *dst, ptrdiff_t stride,
185  int mb_lim, int lim, int hev_thr);
186 
187  /*
188  * dimension 1/2: width of filter (0=4, 1=8) for each filter half
189  * dimension 3: 0=col-edge filter (h), 1=row-edge filter (v)
190  *
191  * dst/stride are aligned by operation size
192  * this basically calls loop_filter[d1][d3][0](), followed by
193  * loop_filter[d2][d3][0]() on the next 8 pixels
194  * mb_lim/lim/hev_thr contain two values in the lowest two bytes of the
195  * integer.
196  */
197  // FIXME perhaps a mix4 that operates on 32px (for AVX2)
198  void (*loop_filter_mix2[2][2][2])(uint8_t *dst, ptrdiff_t stride,
199  int mb_lim, int lim, int hev_thr);
200 
201  /*
202  * dimension 1: hsize (0: 64, 1: 32, 2: 16, 3: 8, 4: 4)
203  * dimension 2: filter type (0: smooth, 1: regular, 2: sharp, 3: bilin)
204  * dimension 3: averaging type (0: put, 1: avg)
205  * dimension 4: x subpel interpolation (0: none, 1: 8tap/bilin)
206  * dimension 5: y subpel interpolation (1: none, 1: 8tap/bilin)
207  *
208  * dst/stride are aligned by hsize
209  */
210  vp9_mc_func mc[5][4][2][2][2];
211 } VP9DSPContext;
212 
217 };
218 
219 typedef struct VP9MVRefPair {
220  VP56mv mv[2];
221  int8_t ref[2];
222 } VP9MVRefPair;
223 
224 typedef struct VP9Filter {
225  uint8_t level[8 * 8];
226  uint8_t /* bit=col */ mask[2 /* 0=y, 1=uv */][2 /* 0=col, 1=row */]
227  [8 /* rows */][4 /* 0=16, 1=8, 2=4, 3=inner4 */];
228 } VP9Filter;
229 
230 typedef struct VP9Frame {
232 
235 
238 } VP9Frame;
239 
245 };
246 
247 enum BlockSize {
262 };
263 
264 typedef struct VP9Block {
265  uint8_t seg_id, intra, comp, ref[2], mode[4], uvmode, skip;
267  VP56mv mv[4 /* b_idx */][2 /* ref */];
268  enum BlockSize bs;
269  enum TxfmMode tx, uvtx;
270 
271  int row, row7, col, col7;
272  uint8_t *dst[3];
273  ptrdiff_t y_stride, uv_stride;
274 
275  enum BlockLevel bl;
276  enum BlockPartition bp;
277 } VP9Block;
278 
279 typedef struct VP9Context {
285  unsigned c_b_size;
288 
291 
292  int pass;
296 
297  // bitstream header
311  enum FilterMode filtermode;
317  uint8_t refidx[3];
318  uint8_t signbias[3];
319  uint8_t varcompref[2];
320 
321  ThreadFrame refs[8];
322 
323 #define CUR_FRAME 0
324 #define LAST_FRAME 1
326 
327  struct {
329  int8_t sharpness;
330  uint8_t lim_lut[64];
331  uint8_t mblim_lut[64];
332  } filter;
333  struct {
335  int8_t mode[2];
336  int8_t ref[4];
337  } lf_delta;
339  int8_t ydc_qdelta, uvdc_qdelta, uvac_qdelta;
341  struct {
342  uint8_t enabled;
346  #define MAX_SEGMENT 8
347  struct {
353  int16_t q_val;
354  int8_t lf_val;
355  int16_t qmul[2][2];
356  uint8_t lflvl[4][2];
357  } feat[MAX_SEGMENT];
358  } segmentation;
359  struct {
360  unsigned log2_tile_cols, log2_tile_rows;
361  unsigned tile_cols, tile_rows;
362  unsigned tile_row_start, tile_row_end, tile_col_start, tile_col_end;
363  } tiling;
364  unsigned sb_cols, sb_rows, rows, cols;
365  struct {
367  uint8_t coef[4][2][2][6][6][3];
368  } prob_ctx[4];
369  struct {
370  ProbContext p;
371  uint8_t coef[4][2][2][6][6][11];
372  uint8_t seg[7];
373  uint8_t segpred[3];
374  } prob;
375  struct {
376  unsigned y_mode[4][10];
377  unsigned uv_mode[10][10];
378  unsigned filter[4][3];
379  unsigned mv_mode[7][4];
380  unsigned intra[4][2];
381  unsigned comp[5][2];
382  unsigned single_ref[5][2][2];
383  unsigned comp_ref[5][2];
384  unsigned tx32p[2][4];
385  unsigned tx16p[2][3];
386  unsigned tx8p[2][2];
387  unsigned skip[3][2];
388  unsigned mv_joint[4];
389  struct {
390  unsigned sign[2];
391  unsigned classes[11];
392  unsigned class0[2];
393  unsigned bits[10][2];
394  unsigned class0_fp[2][4];
395  unsigned fp[4];
396  unsigned class0_hp[2];
397  unsigned hp[2];
398  } mv_comp[2];
399  unsigned partition[4][4][4];
400  unsigned coef[4][2][2][6][6][3];
401  unsigned eob[4][2][2][6][6][2];
402  } counts;
403  enum TxfmMode txfmmode;
404  enum CompPredMode comppredmode;
405 
406  // contextual (left/above) cache
407  uint8_t left_partition_ctx[8], *above_partition_ctx;
408  uint8_t left_mode_ctx[16], *above_mode_ctx;
409  // FIXME maybe merge some of the below in a flags field?
410  uint8_t left_y_nnz_ctx[16], *above_y_nnz_ctx;
411  uint8_t left_uv_nnz_ctx[2][8], *above_uv_nnz_ctx[2];
412  uint8_t left_skip_ctx[8], *above_skip_ctx; // 1bit
413  uint8_t left_txfm_ctx[8], *above_txfm_ctx; // 2bit
414  uint8_t left_segpred_ctx[8], *above_segpred_ctx; // 1bit
415  uint8_t left_intra_ctx[8], *above_intra_ctx; // 1bit
416  uint8_t left_comp_ctx[8], *above_comp_ctx; // 1bit
417  uint8_t left_ref_ctx[8], *above_ref_ctx; // 2bit
418  uint8_t left_filter_ctx[8], *above_filter_ctx;
419  VP56mv left_mv_ctx[16][2], (*above_mv_ctx)[2];
420 
421  // whole-frame cache
422  uint8_t *intra_pred_data[3];
424  DECLARE_ALIGNED(32, uint8_t, edge_emu_buffer)[71 * 80];
425 
426  // block reconstruction intermediates
427  int16_t *block_base, *block, *uvblock_base[2], *uvblock[2];
428  uint8_t *eob_base, *uveob_base[2], *eob, *uveob[2];
429  struct { int x, y; } min_mv, max_mv;
430  DECLARE_ALIGNED(32, uint8_t, tmp_y)[64 * 64];
431  DECLARE_ALIGNED(32, uint8_t, tmp_uv)[2][32 * 32];
432 } VP9Context;
433 
434 void ff_vp9dsp_init(VP9DSPContext *dsp);
435 
437 
438 void ff_vp9_fill_mv(VP9Context *s, VP56mv *mv, int mode, int sb);
439 
441 
442 int ff_vp9_decode_block(AVCodecContext *avctx, int row, int col,
443  VP9Filter *lflvl, ptrdiff_t yoff, ptrdiff_t uvoff,
444  enum BlockLevel bl, enum BlockPartition bp);
445 
446 #endif /* AVCODEC_VP9_H */
Definition: vp9.h:90
Definition: vp9.h:250
ThreadFrame tf
Definition: vp9.h:231
uint8_t resetctx
Definition: vp9.h:308
struct ProbContext::@100 mv_comp[2]
Definition: vp9.h:57
uint8_t lossless
Definition: vp9.h:340
int alloc_height
Definition: vp9.h:290
Definition: vp9.h:252
Definition: vp9.h:243
uint8_t * segmentation_map
Definition: vp9.h:233
int row7
Definition: vp9.h:271
VP9Block * b
Definition: vp9.h:286
VP5 and VP6 compatible video decoder (common features)
VP9MVRefPair * mv
Definition: vp9.h:234
VideoDSPContext vdsp
Definition: vp9.h:281
BlockPartition
Definition: vp9.h:82
ProbContext p
Definition: vp9.h:366
uint8_t last_keyframe
Definition: vp9.h:299
uint8_t tx32p[2][3]
Definition: vp9.h:112
#define DECLARE_ALIGNED(n, t, v)
Definition: mem.h:58
Definition: vp9.h:248
Definition: vp9.h:242
BlockLevel
Definition: vp9.h:240
Definition: vp9.h:93
uint8_t lf_enabled
Definition: vp9.h:349
ptrdiff_t y_stride
Definition: vp9.h:273
VP9Filter * lflvl
Definition: vp9.h:423
Definition: vp9.h:264
uint8_t parallelmode
Definition: vp9.h:315
#define MAX_SEGMENT
Definition: vp9.h:346
int stride
Definition: mace.c:144
uint8_t comp_ref[5]
Definition: vp9.h:111
uint8_t update_map
Definition: vp9.h:345
Definition: vp9.h:39
uint8_t errorres
Definition: vp9.h:302
int y
Definition: vp9.h:429
static int16_t block[64]
Definition: dct.c:97
Definition: vp9.h:98
uint8_t
uint8_t colorspace
Definition: vp9.h:303
TxfmType
Definition: vp9.h:47
Multithreading support functions.
Definition: vp9.h:56
InterPredMode
Definition: vp9.h:89
unsigned log2_tile_rows
Definition: vp9.h:360
uint8_t sub_x
Definition: vp9.h:304
uint8_t skip[3]
Definition: vp9.h:115
VP9DSPContext dsp
Definition: vp9.h:280
Definition: vp9.h:48
Definition: vp9.h:224
Definition: vp9.h:40
uint8_t uv_mode[10][9]
Definition: vp9.h:105
uint8_t fixcompref
Definition: vp9.h:313
Definition: vp9.h:38
uint8_t partition[4][4][3]
Definition: vp9.h:127
uint8_t hp
Definition: vp9.h:125
uint8_t sign
Definition: vp9.h:118
uint8_t allowcompinter
Definition: vp9.h:312
int8_t sharpness
Definition: vp9.h:329
static const uint16_t mask[17]
Definition: lzw.c:38
GetBitContext gb
Definition: vp9.h:282
uint8_t fp[3]
Definition: vp9.h:123
Definition: vp9.h:49
Definition: vp9.h:251
unsigned tile_row_start
Definition: vp9.h:362
Definition: vp9.h:51
Definition: vp9.h:259
TxfmMode
Definition: vp9.h:37
uint8_t intra[4]
Definition: vp9.h:108
uint8_t use_last_frame_mvs
Definition: vp9.h:301
int ff_vp9_decode_block(AVCodecContext *avctx, int row, int col, VP9Filter *lflvl, ptrdiff_t yoff, ptrdiff_t uvoff, enum BlockLevel bl, enum BlockPartition bp)
Definition: vp9block.c:1572
Definition: vp9.h:241
unsigned tile_rows
Definition: vp9.h:361
void ff_vp9dsp_init_x86(VP9DSPContext *dsp)
Definition: vp9dsp_init.c:222
common internal API header
uint8_t comp[5]
Definition: vp9.h:109
Definition: vp9.h:254
unsigned c_b_size
Definition: vp9.h:285
uint8_t yac_qi
Definition: vp9.h:338
uint8_t framectxid
Definition: vp9.h:316
Definition: vp9.h:244
Definition: vp9.h:99
uint8_t tx16p[2][2]
Definition: vp9.h:113
CompPredMode
Definition: vp9.h:213
uint8_t class0_hp
Definition: vp9.h:124
uint8_t ref_val
Definition: vp9.h:352
uint8_t profile
Definition: vp9.h:298
uint8_t uvmode
Definition: vp9.h:265
uint8_t mv_mode[7][3]
Definition: vp9.h:107
int frames
Definition: movenc.c:65
static av_always_inline void FUNC() intra_pred(HEVCContext *s, int x0, int y0, int log2_size, int c_idx)
Definition: vp9.h:92
Definition: vp9.h:258
static const int8_t mv[256][2]
Definition: 4xm.c:75
uint8_t enabled
Definition: vp9.h:334
Definition: vp9.h:253
FilterMode
Definition: vp9.h:74
Libavcodec external API header.
uint8_t ref_enabled
Definition: vp9.h:350
AVBufferRef * segmentation_map_buf
Definition: vp9.h:236
uint8_t filter[4][2]
Definition: vp9.h:106
uint8_t class0_fp[2][3]
Definition: vp9.h:122
uint8_t level
Definition: vp9.h:328
int pass
Definition: vp9.h:292
BlockSize
Definition: vp9.h:247
main external API structure.
Definition: avcodec.h:1409
static void(WINAPI *cond_broadcast)(pthread_cond_t *cond)
int16_t q_val
Definition: vp9.h:353
VP56RangeCoder * c_b
Definition: vp9.h:284
Definition: vp9.h:255
uint8_t invisible
Definition: vp9.h:300
uint8_t sub_y
Definition: vp9.h:305
void ff_vp9_fill_mv(VP9Context *s, VP56mv *mv, int mode, int sb)
Definition: vp9mvs.c:284
void ff_vp9_adapt_probs(VP9Context *s)
Definition: vp9prob.c:46
uint8_t temporal
Definition: vp9.h:343
uint8_t tx8p[2]
Definition: vp9.h:114
uint8_t y_mode[4][9]
Definition: vp9.h:104
refcounted data buffer API
uint8_t intraonly
Definition: vp9.h:307
IntraPredMode
Definition: hevc.h:206
int uses_2pass
Definition: vp9.h:293
uint8_t single_ref[5][2]
Definition: vp9.h:110
Definition: vp56.h:66
Definition: vp9.h:249
Definition: vp9.h:260
int setup_finished
Definition: vp9.h:295
uint8_t bits[10]
Definition: vp9.h:121
uint8_t refreshctx
Definition: vp9.h:314
uint8_t level
Definition: svq3.c:204
uint8_t fullrange
Definition: vp9.h:306
Definition: vp9.h:91
Definition: vp9.h:58
int8_t ydc_qdelta
Definition: vp9.h:339
uint8_t highprecisionmvs
Definition: vp9.h:310
A reference to a data buffer.
Definition: buffer.h:81
void(* vp9_mc_func)(uint8_t *dst, const uint8_t *ref, ptrdiff_t dst_stride, ptrdiff_t ref_stride, int h, int mx, int my)
Definition: vp9.h:130
Definition: vp9.h:256
unsigned sb_rows
Definition: vp9.h:364
uint8_t mv_joint[3]
Definition: vp9.h:116
uint8_t class0
Definition: vp9.h:120
Definition: vp9.h:41
uint8_t absolute_vals
Definition: vp9.h:344
AVBufferRef * mv_buf
Definition: vp9.h:237
int8_t lf_val
Definition: vp9.h:354
VP9Block * b_base
Definition: vp9.h:287
Definition: vp9.h:230
int alloc_width
Definition: vp9.h:289
int last_uses_2pass
Definition: vp9.h:294
Definition: vp9.h:257
uint8_t q_enabled
Definition: vp9.h:348
Definition: vp9.h:50
MVJoint
Definition: vp9.h:96
uint8_t classes[10]
Definition: vp9.h:119
uint8_t refreshrefmask
Definition: vp9.h:309
uint8_t skip_enabled
Definition: vp9.h:351
void ff_vp9dsp_init(VP9DSPContext *dsp)
Definition: vp9dsp.c:2165
VP56RangeCoder c
Definition: vp9.h:283