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 static void FN(inter_pred)(AVCodecContext *ctx)
26 static const uint8_t bwlog_tab[2][N_BS_SIZES] = {
27 { 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4 },
28 { 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4 },
30 VP9Context *s = ctx->priv_data;
32 int row = s->row, col = s->col;
33 ThreadFrame *tref1 = &s->refs[s->refidx[b->ref[0]]], *tref2;
34 AVFrame *ref1 = tref1->f, *ref2;
35 int w1 = ref1->width, h1 = ref1->height, w2, h2;
36 ptrdiff_t ls_y = s->y_stride, ls_uv = s->uv_stride;
39 tref2 = &s->refs[s->refidx[b->ref[1]]];
47 if (b->bs == BS_8x4) {
48 mc_luma_dir(s, mc[3][b->filter][0], s->dst[0], ls_y,
49 ref1->data[0], ref1->linesize[0], tref1,
50 row << 3, col << 3, &b->mv[0][0], 8, 4, w1, h1, 0);
51 mc_luma_dir(s, mc[3][b->filter][0],
52 s->dst[0] + 4 * ls_y, ls_y,
53 ref1->data[0], ref1->linesize[0], tref1,
54 (row << 3) + 4, col << 3, &b->mv[2][0], 8, 4, w1, h1, 0);
57 mc_luma_dir(s, mc[3][b->filter][1], s->dst[0], ls_y,
58 ref2->data[0], ref2->linesize[0], tref2,
59 row << 3, col << 3, &b->mv[0][1], 8, 4, w2, h2, 1);
60 mc_luma_dir(s, mc[3][b->filter][1],
61 s->dst[0] + 4 * ls_y, ls_y,
62 ref2->data[0], ref2->linesize[0], tref2,
63 (row << 3) + 4, col << 3, &b->mv[2][1], 8, 4, w2, h2, 1);
65 } else if (b->bs == BS_4x8) {
66 mc_luma_dir(s, mc[4][b->filter][0], s->dst[0], ls_y,
67 ref1->data[0], ref1->linesize[0], tref1,
68 row << 3, col << 3, &b->mv[0][0], 4, 8, w1, h1, 0);
69 mc_luma_dir(s, mc[4][b->filter][0], s->dst[0] + 4, ls_y,
70 ref1->data[0], ref1->linesize[0], tref1,
71 row << 3, (col << 3) + 4, &b->mv[1][0], 4, 8, w1, h1, 0);
74 mc_luma_dir(s, mc[4][b->filter][1], s->dst[0], ls_y,
75 ref2->data[0], ref2->linesize[0], tref2,
76 row << 3, col << 3, &b->mv[0][1], 4, 8, w2, h2, 1);
77 mc_luma_dir(s, mc[4][b->filter][1], s->dst[0] + 4, ls_y,
78 ref2->data[0], ref2->linesize[0], tref2,
79 row << 3, (col << 3) + 4, &b->mv[1][1], 4, 8, w2, h2, 1);
82 av_assert2(b->bs == BS_4x4);
84 // FIXME if two horizontally adjacent blocks have the same MV,
85 // do a w8 instead of a w4 call
86 mc_luma_dir(s, mc[4][b->filter][0], s->dst[0], ls_y,
87 ref1->data[0], ref1->linesize[0], tref1,
88 row << 3, col << 3, &b->mv[0][0], 4, 4, w1, h1, 0);
89 mc_luma_dir(s, mc[4][b->filter][0], s->dst[0] + 4, ls_y,
90 ref1->data[0], ref1->linesize[0], tref1,
91 row << 3, (col << 3) + 4, &b->mv[1][0], 4, 4, w1, h1, 0);
92 mc_luma_dir(s, mc[4][b->filter][0],
93 s->dst[0] + 4 * ls_y, ls_y,
94 ref1->data[0], ref1->linesize[0], tref1,
95 (row << 3) + 4, col << 3, &b->mv[2][0], 4, 4, w1, h1, 0);
96 mc_luma_dir(s, mc[4][b->filter][0],
97 s->dst[0] + 4 * ls_y + 4, ls_y,
98 ref1->data[0], ref1->linesize[0], tref1,
99 (row << 3) + 4, (col << 3) + 4, &b->mv[3][0], 4, 4, w1, h1, 0);
102 mc_luma_dir(s, mc[4][b->filter][1], s->dst[0], ls_y,
103 ref2->data[0], ref2->linesize[0], tref2,
104 row << 3, col << 3, &b->mv[0][1], 4, 4, w2, h2, 1);
105 mc_luma_dir(s, mc[4][b->filter][1], s->dst[0] + 4, ls_y,
106 ref2->data[0], ref2->linesize[0], tref2,
107 row << 3, (col << 3) + 4, &b->mv[1][1], 4, 4, w2, h2, 1);
108 mc_luma_dir(s, mc[4][b->filter][1],
109 s->dst[0] + 4 * ls_y, ls_y,
110 ref2->data[0], ref2->linesize[0], tref2,
111 (row << 3) + 4, col << 3, &b->mv[2][1], 4, 4, w2, h2, 1);
112 mc_luma_dir(s, mc[4][b->filter][1],
113 s->dst[0] + 4 * ls_y + 4, ls_y,
114 ref2->data[0], ref2->linesize[0], tref2,
115 (row << 3) + 4, (col << 3) + 4, &b->mv[3][1], 4, 4, w2, h2, 1);
119 int bwl = bwlog_tab[0][b->bs];
120 int bw = bwh_tab[0][b->bs][0] * 4, bh = bwh_tab[0][b->bs][1] * 4;
122 mc_luma_dir(s, mc[bwl][b->filter][0], s->dst[0], ls_y,
123 ref1->data[0], ref1->linesize[0], tref1,
124 row << 3, col << 3, &b->mv[0][0],bw, bh, w1, h1, 0);
127 mc_luma_dir(s, mc[bwl][b->filter][1], s->dst[0], ls_y,
128 ref2->data[0], ref2->linesize[0], tref2,
129 row << 3, col << 3, &b->mv[0][1], bw, bh, w2, h2, 1);
134 int bwl = bwlog_tab[1][b->bs];
135 int bw = bwh_tab[1][b->bs][0] * 4, bh = bwh_tab[1][b->bs][1] * 4;
144 if (b->bs > BS_8x8) {
145 mvuv.x = ROUNDED_DIV(b->mv[0][0].x + b->mv[1][0].x + b->mv[2][0].x + b->mv[3][0].x, 4);
146 mvuv.y = ROUNDED_DIV(b->mv[0][0].y + b->mv[1][0].y + b->mv[2][0].y + b->mv[3][0].y, 4);
151 mc_chroma_dir(s, mc[bwl][b->filter][0],
152 s->dst[1], s->dst[2], ls_uv,
153 ref1->data[1], ref1->linesize[1],
154 ref1->data[2], ref1->linesize[2], tref1,
155 row << 2, col << 2, &mvuv, bw, bh, w1, h1, 0);
158 if (b->bs > BS_8x8) {
159 mvuv.x = ROUNDED_DIV(b->mv[0][1].x + b->mv[1][1].x + b->mv[2][1].x + b->mv[3][1].x, 4);
160 mvuv.y = ROUNDED_DIV(b->mv[0][1].y + b->mv[1][1].y + b->mv[2][1].y + b->mv[3][1].y, 4);
164 mc_chroma_dir(s, mc[bwl][b->filter][1],
165 s->dst[1], s->dst[2], ls_uv,
166 ref2->data[1], ref2->linesize[1],
167 ref2->data[2], ref2->linesize[2], tref2,
168 row << 2, col << 2, &mvuv, bw, bh, w2, h2, 1);