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/internal.h"
31 
32 #include "avcodec.h"
33 #include "vp56.h"
34 
35 enum TxfmMode {
43 };
44 
45 enum TxfmType {
51 };
52 
70 };
71 
72 enum FilterMode {
78 };
79 
81  PARTITION_NONE, // [ ] <-.
82  PARTITION_H, // [-] |
83  PARTITION_V, // [|] |
84  PARTITION_SPLIT, // [+] --'
85 };
86 
88  NEARESTMV = 10,
89  NEARMV = 11,
90  ZEROMV = 12,
91  NEWMV = 13,
92 };
93 
94 enum MVJoint {
99 };
100 
101 typedef struct ProbContext {
103  uint8_t uv_mode[10][9];
110  uint8_t tx32p[2][3];
111  uint8_t tx16p[2][2];
115  struct {
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
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 
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 
233 };
234 
235 enum BlockSize {
250 };
251 
252 typedef struct VP9Block {
253  uint8_t seg_id, intra, comp, ref[2], mode[4], uvmode, skip;
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 {
270  unsigned c_b_size;
272 
273  // bitstream header
285  enum FilterMode filtermode;
291  uint8_t refidx[3];
292  uint8_t signbias[3];
293  uint8_t varcompref[2];
294  AVFrame *refs[8];
296 
297  struct {
299  int8_t sharpness;
300  uint8_t lim_lut[64];
301  uint8_t mblim_lut[64];
302  } filter;
303  struct {
305  int8_t mode[2];
306  int8_t ref[4];
307  } lf_delta;
309  int8_t ydc_qdelta, uvdc_qdelta, uvac_qdelta;
311  struct {
312  uint8_t enabled;
316  struct {
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 {
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];
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  struct { int x, y; } 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 
410 
411 void ff_vp9_fill_mv(VP9Context *s, VP56mv *mv, int mode, int sb);
412 
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 */
Definition: vp9.h:88
Definition: vp9.h:238
uint8_t resetctx
Definition: vp9.h:282
Definition: vp9.h:55
uint8_t lossless
Definition: vp9.h:310
Definition: vp9.h:240
Definition: vp9.h:231
This structure describes decoded (raw) audio or video data.
Definition: frame.h:135
int row7
Definition: vp9.h:259
VP5 and VP6 compatible video decoder (common features)
VideoDSPContext vdsp
Definition: vp9.h:266
BlockPartition
Definition: vp9.h:80
ProbContext p
Definition: vp9.h:335
uint8_t last_keyframe
Definition: vp9.h:275
uint8_t tx32p[2][3]
Definition: vp9.h:110
#define DECLARE_ALIGNED(n, t, v)
Definition: mem.h:58
Definition: vp9.h:236
Definition: vp9.h:230
BlockLevel
Definition: vp9.h:228
Definition: vp9.h:91
uint8_t lf_enabled
Definition: vp9.h:318
ptrdiff_t y_stride
Definition: vp9.h:261
VP9Filter * lflvl
Definition: vp9.h:394
Definition: vp9.h:252
uint8_t parallelmode
Definition: vp9.h:289
int stride
Definition: mace.c:144
uint8_t comp_ref[5]
Definition: vp9.h:109
uint8_t update_map
Definition: vp9.h:315
Definition: vp9.h:37
uint8_t errorres
Definition: vp9.h:278
int y
Definition: vp9.h:402
Definition: vp9.h:96
uint8_t
uint8_t colorspace
Definition: vp9.h:279
TxfmType
Definition: vp9.h:45
Definition: vp9.h:54
InterPredMode
Definition: vp9.h:87
unsigned log2_tile_rows
Definition: vp9.h:329
AVFrame * cur_frame
Definition: vp9.h:295
uint8_t skip[3]
Definition: vp9.h:113
VP9DSPContext dsp
Definition: vp9.h:265
Definition: vp9.h:46
Definition: vp9.h:222
Definition: vp9.h:38
uint8_t uv_mode[10][9]
Definition: vp9.h:103
uint8_t fixcompref
Definition: vp9.h:287
Definition: vp9.h:36
uint8_t partition[4][4][3]
Definition: vp9.h:125
uint8_t hp
Definition: vp9.h:123
uint8_t sign
Definition: vp9.h:116
uint8_t allowcompinter
Definition: vp9.h:286
int8_t sharpness
Definition: vp9.h:299
static const uint16_t mask[17]
Definition: lzw.c:38
GetBitContext gb
Definition: vp9.h:267
uint8_t fp[3]
Definition: vp9.h:121
Definition: vp9.h:47
Definition: vp9.h:239
unsigned tile_row_start
Definition: vp9.h:331
Definition: vp9.h:49
Definition: vp9.h:247
TxfmMode
Definition: vp9.h:35
uint8_t intra[4]
Definition: vp9.h:106
uint8_t use_last_frame_mvs
Definition: vp9.h:277
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:1544
Definition: vp9.h:229
unsigned tile_rows
Definition: vp9.h:330
void ff_vp9dsp_init_x86(VP9DSPContext *dsp)
Definition: vp9dsp_init.c:187
common internal API header
uint8_t comp[5]
Definition: vp9.h:107
Definition: vp9.h:242
unsigned c_b_size
Definition: vp9.h:270
uint8_t yac_qi
Definition: vp9.h:308
uint8_t framectxid
Definition: vp9.h:290
Definition: vp9.h:232
Definition: vp9.h:97
uint8_t tx16p[2][2]
Definition: vp9.h:111
CompPredMode
Definition: vp9.h:211
uint8_t class0_hp
Definition: vp9.h:122
uint8_t ref_val
Definition: vp9.h:321
uint8_t profile
Definition: vp9.h:274
uint8_t uvmode
Definition: vp9.h:253
uint8_t mv_mode[7][3]
Definition: vp9.h:105
static av_always_inline void FUNC() intra_pred(HEVCContext *s, int x0, int y0, int log2_size, int c_idx)
Definition: vp9.h:90
Definition: vp9.h:246
static const int8_t mv[256][2]
Definition: 4xm.c:75
uint8_t enabled
Definition: vp9.h:304
Definition: vp9.h:241
FilterMode
Definition: vp9.h:72
Libavcodec external API header.
uint8_t ref_enabled
Definition: vp9.h:319
uint8_t filter[4][2]
Definition: vp9.h:104
uint8_t class0_fp[2][3]
Definition: vp9.h:120
uint8_t level
Definition: vp9.h:298
BlockSize
Definition: vp9.h:235
main external API structure.
Definition: avcodec.h:1050
static void(WINAPI *cond_broadcast)(pthread_cond_t *cond)
int16_t q_val
Definition: vp9.h:322
VP56RangeCoder * c_b
Definition: vp9.h:269
Definition: vp9.h:243
uint8_t invisible
Definition: vp9.h:276
void ff_vp9_fill_mv(VP9Context *s, VP56mv *mv, int mode, int sb)
Definition: vp9mvs.c:280
void ff_vp9_adapt_probs(VP9Context *s)
Definition: vp9prob.c:46
uint8_t temporal
Definition: vp9.h:313
uint8_t tx8p[2]
Definition: vp9.h:112
uint8_t y_mode[4][9]
Definition: vp9.h:102
uint8_t intraonly
Definition: vp9.h:281
IntraPredMode
Definition: hevc.h:205
struct ProbContext::@71 mv_comp[2]
uint8_t single_ref[5][2]
Definition: vp9.h:108
Definition: vp56.h:65
Definition: vp9.h:237
Definition: vp9.h:248
uint8_t bits[10]
Definition: vp9.h:119
uint8_t refreshctx
Definition: vp9.h:288
uint8_t level
Definition: svq3.c:147
uint8_t fullrange
Definition: vp9.h:280
Definition: vp9.h:89
Definition: vp9.h:56
uint8_t * segmentation_map
Definition: vp9.h:392
int8_t ydc_qdelta
Definition: vp9.h:309
uint8_t highprecisionmvs
Definition: vp9.h:284
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:128
Definition: vp9.h:244
unsigned sb_rows
Definition: vp9.h:333
uint8_t mv_joint[3]
Definition: vp9.h:114
uint8_t class0
Definition: vp9.h:118
VP9Block b
Definition: vp9.h:271
Definition: vp9.h:39
uint8_t absolute_vals
Definition: vp9.h:314
int8_t lf_val
Definition: vp9.h:323
Definition: vp9.h:245
uint8_t q_enabled
Definition: vp9.h:317
Definition: vp9.h:48
MVJoint
Definition: vp9.h:94
uint8_t classes[10]
Definition: vp9.h:117
uint8_t refreshrefmask
Definition: vp9.h:283
uint8_t skip_enabled
Definition: vp9.h:320
void ff_vp9dsp_init(VP9DSPContext *dsp)
Definition: vp9dsp.c:2165
VP56RangeCoder c
Definition: vp9.h:268
static int16_t block[64]
Definition: dct-test.c:88