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
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 {
255  VP56mv mv[4 /* b_idx */][2 /* ref */];
256  enum BlockSize bs;
257  enum TxfmMode tx, uvtx;
258 
259  int row, row7, col, col7;
261  ptrdiff_t y_stride, uv_stride;
262 } VP9Block;
263 
264 typedef struct VP9Context {
270  unsigned c_b_size;
272 
273  // bitstream header
296 
297  struct {
299  int8_t sharpness;
302  } filter;
303  struct {
305  int8_t mode[2];
306  int8_t ref[4];
307  } lf_delta;
311  struct {
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 {
330  unsigned tile_cols, tile_rows;
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];
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;
374 
375  // contextual (left/above) cache
378  // FIXME maybe merge some of the below in a flags field?
388  VP56mv left_mv_ctx[16][2], (*above_mv_ctx)[2];
389 
390  // whole-frame cache
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
int col7
Definition: vp9.h:259
uint8_t resetctx
Definition: vp9.h:282
unsigned hp[2]
Definition: vp9.h:366
Definition: vp9.h:55
uint8_t lossless
Definition: vp9.h:310
struct VP9Context::@78::@81 mv_comp[2]
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
unsigned comp_ref[5][2]
Definition: vp9.h:352
uint8_t mblim_lut[64]
Definition: vp9.h:301
uint8_t left_segpred_ctx[8]
Definition: vp9.h:383
VP5 and VP6 compatible video decoder (common features)
struct VP9Context::@72 filter
uint8_t * above_y_nnz_ctx
Definition: vp9.h:379
struct VP9Context::@74 segmentation
VideoDSPContext vdsp
Definition: vp9.h:266
int8_t uvdc_qdelta
Definition: vp9.h:309
BlockPartition
Definition: vp9.h:80
ProbContext p
Definition: vp9.h:335
uint8_t last_keyframe
Definition: vp9.h:275
int16_t uvblock[2][1024]
Definition: vp9.h:399
uint8_t tx32p[2][3]
Definition: vp9.h:110
struct VP9Context::@76 prob_ctx[4]
#define DECLARE_ALIGNED(n, t, v)
Definition: mem.h:58
uint8_t left_uv_nnz_ctx[2][8]
Definition: vp9.h:380
unsigned skip[3][2]
Definition: vp9.h:356
Definition: vp9.h:236
Definition: vp9.h:230
BlockLevel
Definition: vp9.h:228
int row
Definition: vp9.h:259
unsigned tile_cols
Definition: vp9.h:330
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
void(* intra_pred[N_TXFM_SIZES][N_INTRA_PRED_MODES])(uint8_t *dst, ptrdiff_t stride, const uint8_t *left, const uint8_t *top)
Definition: vp9.h:145
Definition: vp9.h:252
uint8_t parallelmode
Definition: vp9.h:289
uint8_t * above_partition_ctx
Definition: vp9.h:376
unsigned cols
Definition: vp9.h:333
unsigned tile_col_end
Definition: vp9.h:331
uint8_t ref[2]
Definition: vp9.h:253
int stride
Definition: mace.c:144
uint8_t comp_ref[5]
Definition: vp9.h:109
uint8_t * above_ref_ctx
Definition: vp9.h:386
unsigned fp[4]
Definition: vp9.h:364
uint8_t update_map
Definition: vp9.h:315
Definition: vp9.h:37
uint8_t * intra_pred_data[3]
Definition: vp9.h:391
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
uint8_t errorres
Definition: vp9.h:278
int y
Definition: vp9.h:402
uint8_t * above_comp_ctx
Definition: vp9.h:385
uint8_t varcompref[2]
Definition: vp9.h:293
unsigned uv_mode[10][10]
Definition: vp9.h:346
vp9_mc_func mc[5][4][2][2][2]
Definition: vp9.h:208
uint8_t coef[4][2][2][6][6][3]
Definition: vp9.h:336
Definition: vp9.h:96
uint8_t
int16_t qmul[2][2]
Definition: vp9.h:324
uint8_t colorspace
Definition: vp9.h:279
unsigned y_mode[4][10]
Definition: vp9.h:345
TxfmType
Definition: vp9.h:45
uint8_t * above_mode_ctx
Definition: vp9.h:377
int col
Definition: vp9.h:259
Definition: vp9.h:54
InterPredMode
Definition: vp9.h:87
struct VP9Context::@79 max_mv
uint8_t uveob[2][64]
Definition: vp9.h:401
unsigned log2_tile_rows
Definition: vp9.h:329
uint8_t * above_segpred_ctx
Definition: vp9.h:383
AVFrame * cur_frame
Definition: vp9.h:295
uint8_t skip[3]
Definition: vp9.h:113
uint8_t tmp_y[64 *64]
Definition: vp9.h:403
VP9DSPContext dsp
Definition: vp9.h:265
uint8_t lim_lut[64]
Definition: vp9.h:300
unsigned sign[2]
Definition: vp9.h:359
Definition: vp9.h:46
struct VP9Context::@73 lf_delta
uint8_t mode[4]
Definition: vp9.h:253
Definition: vp9.h:222
uint8_t left_ref_ctx[8]
Definition: vp9.h:386
int x
Definition: vp9.h:402
int8_t ref[4]
Definition: vp9.h:306
Definition: vp9.h:38
uint8_t uv_mode[10][9]
Definition: vp9.h:103
uint8_t fixcompref
Definition: vp9.h:287
uint8_t mask[2][2][8][4]
Definition: vp9.h:225
Definition: vp9.h:36
uint8_t partition[4][4][3]
Definition: vp9.h:125
uint8_t keyframe
Definition: vp9.h:275
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
unsigned mv_mode[7][4]
Definition: vp9.h:348
enum CompPredMode comppredmode
Definition: vp9.h:373
uint8_t left_partition_ctx[8]
Definition: vp9.h:376
GetBitContext gb
Definition: vp9.h:267
uint8_t fp[3]
Definition: vp9.h:121
Definition: vp9.h:47
unsigned mv_joint[4]
Definition: vp9.h:357
Definition: vp9.h:239
unsigned tile_row_start
Definition: vp9.h:331
Definition: vp9.h:49
uint8_t intra
Definition: vp9.h:253
Definition: vp9.h:247
TxfmMode
Definition: vp9.h:35
uint8_t refidx[3]
Definition: vp9.h:291
uint8_t * above_txfm_ctx
Definition: vp9.h:382
uint8_t intra[4]
Definition: vp9.h:106
unsigned comp[5][2]
Definition: vp9.h:350
unsigned tx8p[2][2]
Definition: vp9.h:355
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
uint8_t * above_filter_ctx
Definition: vp9.h:387
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
unsigned class0_fp[2][4]
Definition: vp9.h:363
VP56mv left_mv_ctx[16][2]
Definition: vp9.h:388
uint8_t left_y_nnz_ctx[16]
Definition: vp9.h:379
Definition: vp9.h:232
uint8_t level[8 *8]
Definition: vp9.h:223
Definition: vp9.h:97
uint8_t left_mode_ctx[16]
Definition: vp9.h:377
unsigned eob[4][2][2][6][6][2]
Definition: vp9.h:370
void(* loop_filter_16[2])(uint8_t *dst, ptrdiff_t stride, int mb_lim, int lim, int hev_thr)
Definition: vp9.h:182
uint8_t tx16p[2][2]
Definition: vp9.h:111
CompPredMode
Definition: vp9.h:211
unsigned tx32p[2][4]
Definition: vp9.h:353
unsigned tx16p[2][3]
Definition: vp9.h:354
enum FilterMode filtermode
Definition: vp9.h:285
uint8_t class0_hp
Definition: vp9.h:122
uint8_t ref_val
Definition: vp9.h:321
uint8_t * dst[3]
Definition: vp9.h:260
uint8_t profile
Definition: vp9.h:274
uint8_t uvmode
Definition: vp9.h:253
uint8_t left_comp_ctx[8]
Definition: vp9.h:385
uint8_t mv_mode[7][3]
Definition: vp9.h:105
int16_t block[4096]
Definition: vp9.h:398
unsigned tile_col_start
Definition: vp9.h:331
unsigned intra[4][2]
Definition: vp9.h:349
unsigned rows
Definition: vp9.h:333
Definition: vp9.h:90
unsigned sb_cols
Definition: vp9.h:333
VP56mv mv[2]
Definition: vp9.h:218
Definition: vp9.h:246
static const int8_t mv[256][2]
Definition: 4xm.c:75
uint8_t enabled
Definition: vp9.h:304
void(* loop_filter_mix2[2][2][2])(uint8_t *dst, ptrdiff_t stride, int mb_lim, int lim, int hev_thr)
Definition: vp9.h:196
int8_t uvac_qdelta
Definition: vp9.h:309
Definition: vp9.h:241
FilterMode
Definition: vp9.h:72
void(* loop_filter_8[3][2])(uint8_t *dst, ptrdiff_t stride, int mb_lim, int lim, int hev_thr)
Definition: vp9.h:174
unsigned class0[2]
Definition: vp9.h:361
Libavcodec external API header.
uint8_t ref_enabled
Definition: vp9.h:319
struct VP9Context::@79 min_mv
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
uint8_t left_skip_ctx[8]
Definition: vp9.h:381
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
uint8_t left_txfm_ctx[8]
Definition: vp9.h:382
VP56RangeCoder * c_b
Definition: vp9.h:269
Definition: vp9.h:243
uint8_t invisible
Definition: vp9.h:276
enum TxfmMode tx uvtx
Definition: vp9.h:257
unsigned single_ref[5][2][2]
Definition: vp9.h:351
unsigned partition[4][4][4]
Definition: vp9.h:368
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 seg_id
Definition: vp9.h:253
uint8_t y_mode[4][9]
Definition: vp9.h:102
uint8_t left_filter_ctx[8]
Definition: vp9.h:387
uint8_t intraonly
Definition: vp9.h:281
IntraPredMode
Definition: hevc.h:205
uint8_t signbias[3]
Definition: vp9.h:292
enum BlockSize bs
Definition: vp9.h:256
struct VP9Context::@74::@80 feat[8]
uint8_t tmp_uv[2][32 *32]
Definition: vp9.h:404
VP56mv mv[4][2]
Definition: vp9.h:255
uint8_t * above_skip_ctx
Definition: vp9.h:381
struct ProbContext::@71 mv_comp[2]
enum TxfmMode txfmmode
Definition: vp9.h:372
uint8_t single_ref[5][2]
Definition: vp9.h:108
Definition: vp56.h:65
Definition: vp9.h:237
Definition: vp9.h:248
uint8_t comp
Definition: vp9.h:253
uint8_t bits[10]
Definition: vp9.h:119
uint8_t refreshctx
Definition: vp9.h:288
uint8_t fullrange
Definition: vp9.h:280
unsigned class0_hp[2]
Definition: vp9.h:365
Definition: vp9.h:89
Definition: vp9.h:56
ptrdiff_t uv_stride
Definition: vp9.h:261
uint8_t * segmentation_map
Definition: vp9.h:392
int8_t ydc_qdelta
Definition: vp9.h:309
uint8_t highprecisionmvs
Definition: vp9.h:284
void(* itxfm_add[N_TXFM_SIZES+1][N_TXFM_TYPES])(uint8_t *dst, ptrdiff_t stride, int16_t *block, int eob)
Definition: vp9.h:164
uint8_t seg[7]
Definition: vp9.h:341
uint8_t segpred[3]
Definition: vp9.h:342
Definition: vp9.h:244
unsigned sb_rows
Definition: vp9.h:333
uint8_t lflvl[4][2]
Definition: vp9.h:325
uint8_t edge_emu_buffer[71 *80]
Definition: vp9.h:395
int8_t ref[2]
Definition: vp9.h:219
uint8_t mv_joint[3]
Definition: vp9.h:114
unsigned bits[10][2]
Definition: vp9.h:362
uint8_t class0
Definition: vp9.h:118
VP9Block b
Definition: vp9.h:271
unsigned tile_row_end
Definition: vp9.h:331
enum FilterMode filter
Definition: vp9.h:254
Definition: vp9.h:39
uint8_t absolute_vals
Definition: vp9.h:314
uint8_t * above_intra_ctx
Definition: vp9.h:384
struct VP9Context::@77 prob
struct VP9Context::@78 counts
int8_t lf_val
Definition: vp9.h:323
struct VP9Context::@75 tiling
Definition: vp9.h:245
uint8_t skip
Definition: vp9.h:253
int8_t mode[2]
Definition: vp9.h:305
VP9MVRefPair * mv[2]
Definition: vp9.h:393
uint8_t q_enabled
Definition: vp9.h:317
Definition: vp9.h:48
MVJoint
Definition: vp9.h:94
uint8_t left_intra_ctx[8]
Definition: vp9.h:384
unsigned classes[11]
Definition: vp9.h:360
uint8_t classes[10]
Definition: vp9.h:117
uint8_t refreshrefmask
Definition: vp9.h:283
uint8_t * above_uv_nnz_ctx[2]
Definition: vp9.h:380
AVFrame * refs[8]
Definition: vp9.h:294
uint8_t skip_enabled
Definition: vp9.h:320
unsigned log2_tile_cols
Definition: vp9.h:329
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