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 Libav.
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.
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.
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
30 #include "libavutil/internal.h"
41 TX_SWITCHABLE = N_TXFM_SIZES,
81 PARTITION_NONE, // [ ] <-.
84 PARTITION_SPLIT, // [+] --'
101 typedef struct ProbContext {
102 uint8_t y_mode[4][9];
103 uint8_t uv_mode[10][9];
104 uint8_t filter[4][2];
105 uint8_t mv_mode[7][3];
108 uint8_t single_ref[5][2];
120 uint8_t class0_fp[2][3];
125 uint8_t partition[4][4][3];
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);
133 typedef struct VP9DSPContext {
135 * dimension 1: 0=4x4, 1=8x8, 2=16x16, 3=32x32
136 * dimension 2: intra prediction modes
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
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
145 void (*intra_pred[N_TXFM_SIZES][N_INTRA_PRED_MODES])(uint8_t *dst,
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
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,
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,
166 int16_t *block, int eob);
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)
172 * dst/stride are aligned by 8
174 void (*loop_filter_8[3][2])(uint8_t *dst, ptrdiff_t stride,
175 int mb_lim, int lim, int hev_thr);
178 * dimension 1: 0=col-edge filter (h), 1=row-edge filter (v)
180 * The width of filter is assumed to be 16; dst/stride are aligned by 16
182 void (*loop_filter_16[2])(uint8_t *dst, ptrdiff_t stride,
183 int mb_lim, int lim, int hev_thr);
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)
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
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);
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)
206 * dst/stride are aligned by hsize
208 vp9_mc_func mc[5][4][2][2][2];
217 typedef struct VP9MVRefPair {
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 */];
252 typedef struct VP9Block {
253 uint8_t seg_id, intra, comp, ref[2], mode[4], uvmode, skip;
254 enum FilterMode filter;
255 VP56mv mv[4 /* b_idx */][2 /* ref */];
257 enum TxfmMode tx, uvtx;
259 int row, row7, col, col7;
261 ptrdiff_t y_stride, uv_stride;
264 typedef struct VP9Context {
266 VideoDSPContext vdsp;
275 uint8_t keyframe, last_keyframe;
277 uint8_t use_last_frame_mvs;
285 uint8_t refreshrefmask;
286 uint8_t highprecisionmvs;
287 enum FilterMode filtermode;
288 uint8_t allowcompinter;
291 uint8_t parallelmode;
295 uint8_t varcompref[2];
303 uint8_t mblim_lut[64];
311 int8_t ydc_qdelta, uvdc_qdelta, uvac_qdelta;
316 uint8_t absolute_vals;
318 #define MAX_SEGMENT 8
323 uint8_t skip_enabled;
332 unsigned log2_tile_cols, log2_tile_rows;
333 unsigned tile_cols, tile_rows;
334 unsigned tile_row_start, tile_row_end, tile_col_start, tile_col_end;
336 unsigned sb_cols, sb_rows, rows, cols;
339 uint8_t coef[4][2][2][6][6][3];
343 uint8_t coef[4][2][2][6][6][11];
348 unsigned y_mode[4][10];
349 unsigned uv_mode[10][10];
350 unsigned filter[4][3];
351 unsigned mv_mode[7][4];
352 unsigned intra[4][2];
354 unsigned single_ref[5][2][2];
355 unsigned comp_ref[5][2];
356 unsigned tx32p[2][4];
357 unsigned tx16p[2][3];
360 unsigned mv_joint[4];
363 unsigned classes[11];
365 unsigned bits[10][2];
366 unsigned class0_fp[2][4];
368 unsigned class0_hp[2];
371 unsigned partition[4][4][4];
372 unsigned coef[4][2][2][6][6][3];
373 unsigned eob[4][2][2][6][6][2];
375 enum TxfmMode txfmmode;
376 enum CompPredMode comppredmode;
378 // contextual (left/above) cache
379 uint8_t left_partition_ctx[8], *above_partition_ctx;
380 uint8_t left_mode_ctx[16], *above_mode_ctx;
381 // FIXME maybe merge some of the below in a flags field?
382 uint8_t left_y_nnz_ctx[16], *above_y_nnz_ctx;
383 uint8_t left_uv_nnz_ctx[2][8], *above_uv_nnz_ctx[2];
384 uint8_t left_skip_ctx[8], *above_skip_ctx; // 1bit
385 uint8_t left_txfm_ctx[8], *above_txfm_ctx; // 2bit
386 uint8_t left_segpred_ctx[8], *above_segpred_ctx; // 1bit
387 uint8_t left_intra_ctx[8], *above_intra_ctx; // 1bit
388 uint8_t left_comp_ctx[8], *above_comp_ctx; // 1bit
389 uint8_t left_ref_ctx[8], *above_ref_ctx; // 2bit
390 uint8_t left_filter_ctx[8], *above_filter_ctx;
391 VP56mv left_mv_ctx[16][2], (*above_mv_ctx)[2];
394 uint8_t *intra_pred_data[3];
395 uint8_t *segmentation_map;
398 DECLARE_ALIGNED(32, uint8_t, edge_emu_buffer)[71 * 80];
400 // block reconstruction intermediates
401 DECLARE_ALIGNED(32, int16_t, block)[4096];
402 DECLARE_ALIGNED(32, int16_t, uvblock)[2][1024];
404 uint8_t uveob[2][64];
405 VP56mv min_mv, max_mv;
406 DECLARE_ALIGNED(32, uint8_t, tmp_y)[64 * 64];
407 DECLARE_ALIGNED(32, uint8_t, tmp_uv)[2][32 * 32];
410 void ff_vp9dsp_init(VP9DSPContext *dsp);
412 void ff_vp9dsp_init_x86(VP9DSPContext *dsp);
414 void ff_vp9_fill_mv(VP9Context *s, VP56mv *mv, int mode, int sb);
416 void ff_vp9_adapt_probs(VP9Context *s);
418 int ff_vp9_decode_block(AVCodecContext *avctx, int row, int col,
419 VP9Filter *lflvl, ptrdiff_t yoff, ptrdiff_t uvoff,
420 enum BlockLevel bl, enum BlockPartition bp);
422 #endif /* AVCODEC_VP9_H */