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];
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 */