FFmpeg
vp9dec.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 FFmpeg.
8  *
9  * FFmpeg 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  * FFmpeg 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 FFmpeg; 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_VP9DEC_H
25 #define AVCODEC_VP9DEC_H
26 
27 #include <stddef.h>
28 #include <stdint.h>
29 #include <stdatomic.h>
30 
31 #include "libavutil/buffer.h"
32 #include "libavutil/thread.h"
33 #include "libavutil/internal.h"
34 
35 #include "vp9.h"
36 #include "vp9dsp.h"
37 #include "vp9shared.h"
38 
39 #define REF_INVALID_SCALE 0xFFFF
40 
41 enum MVJoint {
46 };
47 
48 typedef struct ProbContext {
49  uint8_t y_mode[4][9];
50  uint8_t uv_mode[10][9];
51  uint8_t filter[4][2];
57  uint8_t tx32p[2][3];
58  uint8_t tx16p[2][2];
62  struct {
68  uint8_t fp[3];
71  } mv_comp[2];
72  uint8_t partition[4][4][3];
73 } ProbContext;
74 
75 typedef struct VP9Filter {
76  uint8_t level[8 * 8];
77  uint8_t /* bit=col */ mask[2 /* 0=y, 1=uv */][2 /* 0=col, 1=row */]
78  [8 /* rows */][4 /* 0=16, 1=8, 2=4, 3=inner4 */];
79 } VP9Filter;
80 
81 typedef struct VP9Block {
82  uint8_t seg_id, intra, comp, ref[2], mode[4], uvmode, skip;
84  VP56mv mv[4 /* b_idx */][2 /* ref */];
85  enum BlockSize bs;
86  enum TxfmMode tx, uvtx;
87  enum BlockLevel bl;
88  enum BlockPartition bp;
89 } VP9Block;
90 
91 typedef struct VP9TileData VP9TileData;
92 
93 typedef struct VP9Context {
96 
101  int pass, active_tile_cols;
102 
103 #if HAVE_THREADS
104  pthread_mutex_t progress_mutex;
105  pthread_cond_t progress_cond;
106  atomic_int *entries;
107 #endif
108 
109  uint8_t ss_h, ss_v;
110  uint8_t last_bpp, bpp_index, bytesperpixel;
112  // sb_cols/rows, rows/cols and last_fmt are used for allocating all internal
113  // arrays, and are thus per-thread. w/h and gf_fmt are synced between threads
114  // and are therefore per-stream. pix_fmt represents the value in the header
115  // of the currently processed frame.
116  int w, h;
117  enum AVPixelFormat pix_fmt, last_fmt, gf_fmt;
118  unsigned sb_cols, sb_rows, rows, cols;
119  ThreadFrame next_refs[8];
120 
121  struct {
122  uint8_t lim_lut[64];
123  uint8_t mblim_lut[64];
124  } filter_lut;
125  struct {
127  uint8_t coef[4][2][2][6][6][3];
128  } prob_ctx[4];
129  struct {
130  ProbContext p;
131  uint8_t coef[4][2][2][6][6][11];
132  } prob;
133 
134  // contextual (above) cache
137  // FIXME maybe merge some of the below in a flags field?
139  uint8_t *above_uv_nnz_ctx[2];
147  VP56mv (*above_mv_ctx)[2];
148 
149  // whole-frame cache
150  uint8_t *intra_pred_data[3];
152 
153  // block reconstruction intermediates
155  uint16_t mvscale[3][2];
156  uint8_t mvstep[3][2];
157 
158  // frame specific buffer pools
161 } VP9Context;
162 
163 struct VP9TileData {
164  //VP9Context should be const, but because of the threading API(generates
165  //a lot of warnings) it's not.
169  int row, row7, col, col7;
170  uint8_t *dst[3];
171  ptrdiff_t y_stride, uv_stride;
173  unsigned tile_col_start;
174 
175  struct {
176  unsigned y_mode[4][10];
177  unsigned uv_mode[10][10];
178  unsigned filter[4][3];
179  unsigned mv_mode[7][4];
180  unsigned intra[4][2];
181  unsigned comp[5][2];
182  unsigned single_ref[5][2][2];
183  unsigned comp_ref[5][2];
184  unsigned tx32p[2][4];
185  unsigned tx16p[2][3];
186  unsigned tx8p[2][2];
187  unsigned skip[3][2];
188  unsigned mv_joint[4];
189  struct {
190  unsigned sign[2];
191  unsigned classes[11];
192  unsigned class0[2];
193  unsigned bits[10][2];
194  unsigned class0_fp[2][4];
195  unsigned fp[4];
196  unsigned class0_hp[2];
197  unsigned hp[2];
198  } mv_comp[2];
199  unsigned partition[4][4][4];
200  unsigned coef[4][2][2][6][6][3];
201  unsigned eob[4][2][2][6][6][2];
202  } counts;
203 
204  // whole-frame cache
205  DECLARE_ALIGNED(32, uint8_t, edge_emu_buffer)[135 * 144 * 2];
206 
207  // contextual (left) cache
208  DECLARE_ALIGNED(16, uint8_t, left_y_nnz_ctx)[16];
209  DECLARE_ALIGNED(16, uint8_t, left_mode_ctx)[16];
210  DECLARE_ALIGNED(16, VP56mv, left_mv_ctx)[16][2];
211  DECLARE_ALIGNED(16, uint8_t, left_uv_nnz_ctx)[2][16];
212  DECLARE_ALIGNED(8, uint8_t, left_partition_ctx)[8];
213  DECLARE_ALIGNED(8, uint8_t, left_skip_ctx)[8];
214  DECLARE_ALIGNED(8, uint8_t, left_txfm_ctx)[8];
215  DECLARE_ALIGNED(8, uint8_t, left_segpred_ctx)[8];
216  DECLARE_ALIGNED(8, uint8_t, left_intra_ctx)[8];
217  DECLARE_ALIGNED(8, uint8_t, left_comp_ctx)[8];
218  DECLARE_ALIGNED(8, uint8_t, left_ref_ctx)[8];
219  DECLARE_ALIGNED(8, uint8_t, left_filter_ctx)[8];
220  // block reconstruction intermediates
221  DECLARE_ALIGNED(32, uint8_t, tmp_y)[64 * 64 * 2];
222  DECLARE_ALIGNED(32, uint8_t, tmp_uv)[2][64 * 64 * 2];
223  struct { int x, y; } min_mv, max_mv;
224  int16_t *block_base, *block, *uvblock_base[2], *uvblock[2];
225  uint8_t *eob_base, *uveob_base[2], *eob, *uveob[2];
226 
227  // error message
229  struct {
230  unsigned int row:13;
231  unsigned int col:13;
232  unsigned int block_size_idx_x:2;
233  unsigned int block_size_idx_y:2;
234  } *block_structure;
235  unsigned int nb_block_structure;
236 };
237 
238 void ff_vp9_fill_mv(VP9TileData *td, VP56mv *mv, int mode, int sb);
239 
241 
242 void ff_vp9_decode_block(VP9TileData *td, int row, int col,
243  VP9Filter *lflvl, ptrdiff_t yoff, ptrdiff_t uvoff,
244  enum BlockLevel bl, enum BlockPartition bp);
245 
246 void ff_vp9_loopfilter_sb(AVCodecContext *avctx, VP9Filter *lflvl,
247  int row, int col, ptrdiff_t yoff, ptrdiff_t uvoff);
248 
250  ptrdiff_t y_off, ptrdiff_t uv_off);
252  ptrdiff_t y_off, ptrdiff_t uv_off);
255 
256 #endif /* AVCODEC_VP9DEC_H */
static enum AVPixelFormat pix_fmt
struct ProbContext::@175 mv_comp[2]
uint8_t * above_skip_ctx
Definition: vp9dec.h:140
VP9Context * s
Definition: vp9dec.h:166
VideoDSPContext vdsp
Definition: vp9dec.h:98
ProbContext p
Definition: vp9dec.h:126
uint8_t last_keyframe
Definition: vp9dec.h:111
uint8_t ss_v
Definition: vp9dec.h:109
uint8_t tx32p[2][3]
Definition: vp9dec.h:57
VP9Filter * lflvl
Definition: vp9dec.h:151
intptr_t atomic_int
Definition: stdatomic.h:55
uint8_t comp_ref[5]
Definition: vp9dec.h:56
void ff_vp9_intra_recon_8bpp(VP9TileData *td, ptrdiff_t y_off, ptrdiff_t uv_off)
Definition: vp9recon.c:288
The exact code depends on how similar the blocks are and how related they are to the block
uint8_t
void ff_vp9_adapt_probs(VP9Context *s)
Definition: vp9prob.c:46
void ff_vp9_inter_recon_8bpp(VP9TileData *td)
Definition: vp9recon.c:646
void ff_vp9_intra_recon_16bpp(VP9TileData *td, ptrdiff_t y_off, ptrdiff_t uv_off)
Definition: vp9recon.c:293
VP9Block * b_base
Definition: vp9dec.h:172
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
Definition: mem.h:112
VP56RangeCoder * c_b
Definition: vp9dec.h:167
uint8_t skip[3]
Definition: vp9dec.h:60
VP9DSPContext dsp
Definition: vp9dec.h:97
int row7
Definition: vp9dec.h:169
uint8_t * above_txfm_ctx
Definition: vp9dec.h:141
The buffer pool.
uint8_t uv_mode[10][9]
Definition: vp9dec.h:50
#define prob(name, subs,...)
Definition: cbs_vp9.c:373
void ff_vp9_loopfilter_sb(AVCodecContext *avctx, VP9Filter *lflvl, int row, int col, ptrdiff_t yoff, ptrdiff_t uvoff)
Definition: vp9lpf.c:178
uint8_t partition[4][4][3]
Definition: vp9dec.h:72
uint8_t hp
Definition: vp9dec.h:70
unsigned tile_col_start
Definition: vp9dec.h:173
#define td
Definition: regdef.h:70
uint8_t sign
Definition: vp9dec.h:63
static const uint16_t mask[17]
Definition: lzw.c:38
GetBitContext gb
Definition: vp9dec.h:99
uint8_t fp[3]
Definition: vp9dec.h:68
int frame_extradata_pool_size
Definition: vp9dec.h:160
TxfmMode
Definition: vp9.h:27
uint8_t intra[4]
Definition: vp9dec.h:53
VP56RangeCoder * c
Definition: vp9dec.h:168
void ff_vp9_inter_recon_16bpp(VP9TileData *td)
Definition: vp9recon.c:651
uint8_t * above_filter_ctx
Definition: vp9dec.h:146
common internal API header
uint8_t comp[5]
Definition: vp9dec.h:54
#define b
Definition: input.c:41
VP9TileData * td
Definition: vp9dec.h:95
BlockSize
Definition: vp9shared.h:77
uint8_t tx16p[2][2]
Definition: vp9dec.h:58
uint8_t class0_hp
Definition: vp9dec.h:69
#define s(width, name)
Definition: cbs_vp9.c:257
VP9SharedContext s
Definition: vp9dec.h:94
uint8_t uvmode
Definition: vp9dec.h:82
uint8_t * above_partition_ctx
Definition: vp9dec.h:135
uint8_t mv_mode[7][3]
Definition: vp9dec.h:52
MVJoint
Definition: vp9dec.h:41
uint8_t * above_segpred_ctx
Definition: vp9dec.h:142
static const int8_t mv[256][2]
Definition: 4xm.c:77
FilterMode
Definition: vp9.h:64
BlockLevel
Definition: vp9shared.h:70
uint8_t filter[4][2]
Definition: vp9dec.h:51
uint8_t class0_fp[2][3]
Definition: vp9dec.h:67
int pass
Definition: vp9dec.h:101
main external API structure.
Definition: avcodec.h:526
uint8_t * above_y_nnz_ctx
Definition: vp9dec.h:138
uint8_t tx8p[2]
Definition: vp9dec.h:59
uint8_t y_mode[4][9]
Definition: vp9dec.h:49
void ff_vp9_fill_mv(VP9TileData *td, VP56mv *mv, int mode, int sb)
Definition: vp9mvs.c:291
refcounted data buffer API
uint8_t last_bpp
Definition: vp9dec.h:110
uint8_t * above_intra_ctx
Definition: vp9dec.h:143
unsigned int nb_block_structure
Definition: vp9dec.h:235
uint8_t * above_mode_ctx
Definition: vp9dec.h:136
uint8_t single_ref[5][2]
Definition: vp9dec.h:55
Definition: vp56.h:66
uint8_t bits[10]
Definition: vp9dec.h:66
uint8_t level
Definition: svq3.c:209
_fmutex pthread_mutex_t
Definition: os2threads.h:53
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
int w
Definition: vp9dec.h:116
unsigned sb_rows
Definition: vp9dec.h:118
uint8_t mv_joint[3]
Definition: vp9dec.h:61
uint8_t class0
Definition: vp9dec.h:65
void ff_vp9_decode_block(VP9TileData *td, int row, int col, VP9Filter *lflvl, ptrdiff_t yoff, ptrdiff_t uvoff, enum BlockLevel bl, enum BlockPartition bp)
Definition: vp9block.c:1263
int error_info
Definition: vp9dec.h:228
ptrdiff_t y_stride
Definition: vp9dec.h:171
uint8_t * above_ref_ctx
Definition: vp9dec.h:145
BlockPartition
Definition: vp9shared.h:34
uint8_t classes[10]
Definition: vp9dec.h:64
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
mode
Use these values in ebur128_init (or&#39;ed).
Definition: ebur128.h:83
uint8_t * above_comp_ctx
Definition: vp9dec.h:144
int block_alloc_using_2pass
Definition: vp9dec.h:154
AVBufferPool * frame_extradata_pool
Definition: vp9dec.h:159
VP56RangeCoder c
Definition: vp9dec.h:100