2 * VP9 compatible video decoder
4 * Copyright (C) 2013 Ronald S. Bultje <rsbultje gmail com>
5 * Copyright (C) 2013 Clément Bœsch <u pkh me>
7 * This file is part of FFmpeg.
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.
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.
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
24 #ifndef AVCODEC_VP9DEC_H
25 #define AVCODEC_VP9DEC_H
30 #include "libavutil/buffer.h"
31 #include "libavutil/internal.h"
35 #include "vp9shared.h"
44 typedef struct ProbContext {
46 uint8_t uv_mode[10][9];
48 uint8_t mv_mode[7][3];
51 uint8_t single_ref[5][2];
63 uint8_t class0_fp[2][3];
68 uint8_t partition[4][4][3];
71 typedef struct VP9Filter {
73 uint8_t /* bit=col */ mask[2 /* 0=y, 1=uv */][2 /* 0=col, 1=row */]
74 [8 /* rows */][4 /* 0=16, 1=8, 2=4, 3=inner4 */];
77 typedef struct VP9Block {
78 uint8_t seg_id, intra, comp, ref[2], mode[4], uvmode, skip;
79 enum FilterMode filter;
80 VP56mv mv[4 /* b_idx */][2 /* ref */];
82 enum TxfmMode tx, uvtx;
84 enum BlockPartition bp;
87 typedef struct VP9Context {
98 int row, row7, col, col7;
100 ptrdiff_t y_stride, uv_stride;
103 uint8_t last_bpp, bpp_index, bytesperpixel;
104 uint8_t last_keyframe;
105 // sb_cols/rows, rows/cols and last_fmt are used for allocating all internal
106 // arrays, and are thus per-thread. w/h and gf_fmt are synced between threads
107 // and are therefore per-stream. pix_fmt represents the value in the header
108 // of the currently processed frame.
110 enum AVPixelFormat pix_fmt, last_fmt, gf_fmt;
111 unsigned sb_cols, sb_rows, rows, cols;
112 ThreadFrame next_refs[8];
116 uint8_t mblim_lut[64];
118 unsigned tile_row_start, tile_row_end, tile_col_start, tile_col_end;
121 uint8_t coef[4][2][2][6][6][3];
125 uint8_t coef[4][2][2][6][6][11];
128 unsigned y_mode[4][10];
129 unsigned uv_mode[10][10];
130 unsigned filter[4][3];
131 unsigned mv_mode[7][4];
132 unsigned intra[4][2];
134 unsigned single_ref[5][2][2];
135 unsigned comp_ref[5][2];
136 unsigned tx32p[2][4];
137 unsigned tx16p[2][3];
140 unsigned mv_joint[4];
143 unsigned classes[11];
145 unsigned bits[10][2];
146 unsigned class0_fp[2][4];
148 unsigned class0_hp[2];
151 unsigned partition[4][4][4];
152 unsigned coef[4][2][2][6][6][3];
153 unsigned eob[4][2][2][6][6][2];
156 // contextual (left/above) cache
157 DECLARE_ALIGNED(16, uint8_t, left_y_nnz_ctx)[16];
158 DECLARE_ALIGNED(16, uint8_t, left_mode_ctx)[16];
159 DECLARE_ALIGNED(16, VP56mv, left_mv_ctx)[16][2];
160 DECLARE_ALIGNED(16, uint8_t, left_uv_nnz_ctx)[2][16];
161 DECLARE_ALIGNED(8, uint8_t, left_partition_ctx)[8];
162 DECLARE_ALIGNED(8, uint8_t, left_skip_ctx)[8];
163 DECLARE_ALIGNED(8, uint8_t, left_txfm_ctx)[8];
164 DECLARE_ALIGNED(8, uint8_t, left_segpred_ctx)[8];
165 DECLARE_ALIGNED(8, uint8_t, left_intra_ctx)[8];
166 DECLARE_ALIGNED(8, uint8_t, left_comp_ctx)[8];
167 DECLARE_ALIGNED(8, uint8_t, left_ref_ctx)[8];
168 DECLARE_ALIGNED(8, uint8_t, left_filter_ctx)[8];
169 uint8_t *above_partition_ctx;
170 uint8_t *above_mode_ctx;
171 // FIXME maybe merge some of the below in a flags field?
172 uint8_t *above_y_nnz_ctx;
173 uint8_t *above_uv_nnz_ctx[2];
174 uint8_t *above_skip_ctx; // 1bit
175 uint8_t *above_txfm_ctx; // 2bit
176 uint8_t *above_segpred_ctx; // 1bit
177 uint8_t *above_intra_ctx; // 1bit
178 uint8_t *above_comp_ctx; // 1bit
179 uint8_t *above_ref_ctx; // 2bit
180 uint8_t *above_filter_ctx;
181 VP56mv (*above_mv_ctx)[2];
184 uint8_t *intra_pred_data[3];
186 DECLARE_ALIGNED(32, uint8_t, edge_emu_buffer)[135 * 144 * 2];
188 // block reconstruction intermediates
189 int block_alloc_using_2pass;
190 int16_t *block_base, *block, *uvblock_base[2], *uvblock[2];
191 uint8_t *eob_base, *uveob_base[2], *eob, *uveob[2];
192 struct { int x, y; } min_mv, max_mv;
193 DECLARE_ALIGNED(32, uint8_t, tmp_y)[64 * 64 * 2];
194 DECLARE_ALIGNED(32, uint8_t, tmp_uv)[2][64 * 64 * 2];
195 uint16_t mvscale[3][2];
196 uint8_t mvstep[3][2];
199 void ff_vp9_fill_mv(VP9Context *s, VP56mv *mv, int mode, int sb);
201 void ff_vp9_adapt_probs(VP9Context *s);
203 void ff_vp9_decode_block(AVCodecContext *ctx, int row, int col,
204 VP9Filter *lflvl, ptrdiff_t yoff, ptrdiff_t uvoff,
205 enum BlockLevel bl, enum BlockPartition bp);
207 void ff_vp9_loopfilter_sb(AVCodecContext *avctx, VP9Filter *lflvl,
208 int row, int col, ptrdiff_t yoff, ptrdiff_t uvoff);
210 void ff_vp9_intra_recon_8bpp(AVCodecContext *avctx,
211 ptrdiff_t y_off, ptrdiff_t uv_off);
212 void ff_vp9_intra_recon_16bpp(AVCodecContext *avctx,
213 ptrdiff_t y_off, ptrdiff_t uv_off);
214 void ff_vp9_inter_recon_8bpp(AVCodecContext *avctx);
215 void ff_vp9_inter_recon_16bpp(AVCodecContext *avctx);
217 #endif /* AVCODEC_VP9DEC_H */