Source code
Revision control
Copy as Markdown
Other Tools
/*
* VP9 compatible video decoder
*
* Copyright (C) 2013 Ronald S. Bultje <rsbultje gmail com>
* Copyright (C) 2013 Clément Bœsch <u pkh me>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/avassert.h"
#include "libavutil/frame.h"
#include "progressframe.h"
#include "vp89_rac.h"
#include "vp9.h"
#include "vp9data.h"
#include "vp9dec.h"
#include "vpx_rac.h"
static av_always_inline void setctx_2d(uint8_t *ptr, int w, int h,
ptrdiff_t stride, int v)
{
switch (w) {
case 1:
do {
*ptr = v;
ptr += stride;
} while (--h);
break;
case 2: {
int v16 = v * 0x0101;
do {
AV_WN16A(ptr, v16);
ptr += stride;
} while (--h);
break;
}
case 4: {
uint32_t v32 = v * 0x01010101;
do {
AV_WN32A(ptr, v32);
ptr += stride;
} while (--h);
break;
}
case 8: {
#if HAVE_FAST_64BIT
uint64_t v64 = v * 0x0101010101010101ULL;
do {
AV_WN64A(ptr, v64);
ptr += stride;
} while (--h);
#else
uint32_t v32 = v * 0x01010101;
do {
AV_WN32A(ptr, v32);
AV_WN32A(ptr + 4, v32);
ptr += stride;
} while (--h);
#endif
break;
}
}
}
static void decode_mode(VP9TileData *td)
{
static const uint8_t left_ctx[N_BS_SIZES] = {
0x0, 0x8, 0x0, 0x8, 0xc, 0x8, 0xc, 0xe, 0xc, 0xe, 0xf, 0xe, 0xf
};
static const uint8_t above_ctx[N_BS_SIZES] = {
0x0, 0x0, 0x8, 0x8, 0x8, 0xc, 0xc, 0xc, 0xe, 0xe, 0xe, 0xf, 0xf
};
static const uint8_t max_tx_for_bl_bp[N_BS_SIZES] = {
TX_32X32, TX_32X32, TX_32X32, TX_32X32, TX_16X16, TX_16X16,
TX_16X16, TX_8X8, TX_8X8, TX_8X8, TX_4X4, TX_4X4, TX_4X4
};
const VP9Context *s = td->s;
VP9Block *b = td->b;
int row = td->row, col = td->col, row7 = td->row7;
enum TxfmMode max_tx = max_tx_for_bl_bp[b->bs];
int bw4 = ff_vp9_bwh_tab[1][b->bs][0], w4 = FFMIN(s->cols - col, bw4);
int bh4 = ff_vp9_bwh_tab[1][b->bs][1], h4 = FFMIN(s->rows - row, bh4), y;
int have_a = row > 0, have_l = col > td->tile_col_start;
int vref, filter_id;
if (!s->s.h.segmentation.enabled) {
b->seg_id = 0;
} else if (s->s.h.keyframe || s->s.h.intraonly) {
b->seg_id = !s->s.h.segmentation.update_map ? 0 :
vp89_rac_get_tree(td->c, ff_vp9_segmentation_tree,
s->s.h.segmentation.prob);
} else if (!s->s.h.segmentation.update_map ||
(s->s.h.segmentation.temporal &&
vpx_rac_get_prob_branchy(td->c,
s->s.h.segmentation.pred_prob[s->above_segpred_ctx[col] +
td->left_segpred_ctx[row7]]))) {
if (!s->s.h.errorres && s->s.frames[REF_FRAME_SEGMAP].segmentation_map) {
int pred = 8, x;
uint8_t *refsegmap = s->s.frames[REF_FRAME_SEGMAP].segmentation_map;
if (!s->s.frames[REF_FRAME_SEGMAP].uses_2pass)
ff_progress_frame_await(&s->s.frames[REF_FRAME_SEGMAP].tf, row >> 3);
for (y = 0; y < h4; y++) {
int idx_base = (y + row) * 8 * s->sb_cols + col;
for (x = 0; x < w4; x++)
pred = FFMIN(pred, refsegmap[idx_base + x]);
}
av_assert1(pred < 8);
b->seg_id = pred;
} else {
b->seg_id = 0;
}
memset(&s->above_segpred_ctx[col], 1, w4);
memset(&td->left_segpred_ctx[row7], 1, h4);
} else {
b->seg_id = vp89_rac_get_tree(td->c, ff_vp9_segmentation_tree,
s->s.h.segmentation.prob);
memset(&s->above_segpred_ctx[col], 0, w4);
memset(&td->left_segpred_ctx[row7], 0, h4);
}
if (s->s.h.segmentation.enabled &&
(s->s.h.segmentation.update_map || s->s.h.keyframe || s->s.h.intraonly)) {
setctx_2d(&s->s.frames[CUR_FRAME].segmentation_map[row * 8 * s->sb_cols + col],
bw4, bh4, 8 * s->sb_cols, b->seg_id);
}
b->skip = s->s.h.segmentation.enabled &&
s->s.h.segmentation.feat[b->seg_id].skip_enabled;
if (!b->skip) {
int c = td->left_skip_ctx[row7] + s->above_skip_ctx[col];
b->skip = vpx_rac_get_prob(td->c, s->prob.p.skip[c]);
td->counts.skip[c][b->skip]++;
}
if (s->s.h.keyframe || s->s.h.intraonly) {
b->intra = 1;
} else if (s->s.h.segmentation.enabled && s->s.h.segmentation.feat[b->seg_id].ref_enabled) {
b->intra = !s->s.h.segmentation.feat[b->seg_id].ref_val;
} else {
int c, bit;
if (have_a && have_l) {
c = s->above_intra_ctx[col] + td->left_intra_ctx[row7];
c += (c == 2);
} else {
c = have_a ? 2 * s->above_intra_ctx[col] :
have_l ? 2 * td->left_intra_ctx[row7] : 0;
}
bit = vpx_rac_get_prob(td->c, s->prob.p.intra[c]);
td->counts.intra[c][bit]++;
b->intra = !bit;
}
if ((b->intra || !b->skip) && s->s.h.txfmmode == TX_SWITCHABLE) {
int c;
if (have_a) {
if (have_l) {
c = (s->above_skip_ctx[col] ? max_tx :
s->above_txfm_ctx[col]) +
(td->left_skip_ctx[row7] ? max_tx :
td->left_txfm_ctx[row7]) > max_tx;
} else {
c = s->above_skip_ctx[col] ? 1 :
(s->above_txfm_ctx[col] * 2 > max_tx);
}
} else if (have_l) {
c = td->left_skip_ctx[row7] ? 1 :
(td->left_txfm_ctx[row7] * 2 > max_tx);
} else {
c = 1;
}
switch (max_tx) {
case TX_32X32:
b->tx = vpx_rac_get_prob(td->c, s->prob.p.tx32p[c][0]);
if (b->tx) {
b->tx += vpx_rac_get_prob(td->c, s->prob.p.tx32p[c][1]);
if (b->tx == 2)
b->tx += vpx_rac_get_prob(td->c, s->prob.p.tx32p[c][2]);
}
td->counts.tx32p[c][b->tx]++;
break;
case TX_16X16:
b->tx = vpx_rac_get_prob(td->c, s->prob.p.tx16p[c][0]);
if (b->tx)
b->tx += vpx_rac_get_prob(td->c, s->prob.p.tx16p[c][1]);
td->counts.tx16p[c][b->tx]++;
break;
case TX_8X8:
b->tx = vpx_rac_get_prob(td->c, s->prob.p.tx8p[c]);
td->counts.tx8p[c][b->tx]++;
break;
case TX_4X4:
b->tx = TX_4X4;
break;
}
} else {
b->tx = FFMIN(max_tx, s->s.h.txfmmode);
}
if (s->s.h.keyframe || s->s.h.intraonly) {
uint8_t *a = &s->above_mode_ctx[col * 2];
uint8_t *l = &td->left_mode_ctx[(row7) << 1];
b->comp = 0;
if (b->bs > BS_8x8) {
// FIXME the memory storage intermediates here aren't really
// necessary, they're just there to make the code slightly
// simpler for now
b->mode[0] =
a[0] = vp89_rac_get_tree(td->c, ff_vp9_intramode_tree,
ff_vp9_default_kf_ymode_probs[a[0]][l[0]]);
if (b->bs != BS_8x4) {
b->mode[1] = vp89_rac_get_tree(td->c, ff_vp9_intramode_tree,
ff_vp9_default_kf_ymode_probs[a[1]][b->mode[0]]);
l[0] =
a[1] = b->mode[1];
} else {
l[0] =
a[1] =
b->mode[1] = b->mode[0];
}
if (b->bs != BS_4x8) {
b->mode[2] =
a[0] = vp89_rac_get_tree(td->c, ff_vp9_intramode_tree,
ff_vp9_default_kf_ymode_probs[a[0]][l[1]]);
if (b->bs != BS_8x4) {
b->mode[3] = vp89_rac_get_tree(td->c, ff_vp9_intramode_tree,
ff_vp9_default_kf_ymode_probs[a[1]][b->mode[2]]);
l[1] =
a[1] = b->mode[3];
} else {
l[1] =
a[1] =
b->mode[3] = b->mode[2];
}
} else {
b->mode[2] = b->mode[0];
l[1] =
a[1] =
b->mode[3] = b->mode[1];
}
} else {
b->mode[0] = vp89_rac_get_tree(td->c, ff_vp9_intramode_tree,
ff_vp9_default_kf_ymode_probs[*a][*l]);
b->mode[3] =
b->mode[2] =
b->mode[1] = b->mode[0];
// FIXME this can probably be optimized
memset(a, b->mode[0], ff_vp9_bwh_tab[0][b->bs][0]);
memset(l, b->mode[0], ff_vp9_bwh_tab[0][b->bs][1]);
}
b->uvmode = vp89_rac_get_tree(td->c, ff_vp9_intramode_tree,
ff_vp9_default_kf_uvmode_probs[b->mode[3]]);
} else if (b->intra) {
b->comp = 0;
if (b->bs > BS_8x8) {
b->mode[0] = vp89_rac_get_tree(td->c, ff_vp9_intramode_tree,
s->prob.p.y_mode[0]);
td->counts.y_mode[0][b->mode[0]]++;
if (b->bs != BS_8x4) {
b->mode[1] = vp89_rac_get_tree(td->c, ff_vp9_intramode_tree,
s->prob.p.y_mode[0]);
td->counts.y_mode[0][b->mode[1]]++;
} else {
b->mode[1] = b->mode[0];
}
if (b->bs != BS_4x8) {
b->mode[2] = vp89_rac_get_tree(td->c, ff_vp9_intramode_tree,
s->prob.p.y_mode[0]);
td->counts.y_mode[0][b->mode[2]]++;
if (b->bs != BS_8x4) {
b->mode[3] = vp89_rac_get_tree(td->c, ff_vp9_intramode_tree,
s->prob.p.y_mode[0]);
td->counts.y_mode[0][b->mode[3]]++;
} else {
b->mode[3] = b->mode[2];
}
} else {
b->mode[2] = b->mode[0];
b->mode[3] = b->mode[1];
}
} else {
static const uint8_t size_group[10] = {
3, 3, 3, 3, 2, 2, 2, 1, 1, 1
};
int sz = size_group[b->bs];
b->mode[0] = vp89_rac_get_tree(td->c, ff_vp9_intramode_tree,
s->prob.p.y_mode[sz]);
b->mode[1] =
b->mode[2] =
b->mode[3] = b->mode[0];
td->counts.y_mode[sz][b->mode[3]]++;
}
b->uvmode = vp89_rac_get_tree(td->c, ff_vp9_intramode_tree,
s->prob.p.uv_mode[b->mode[3]]);
td->counts.uv_mode[b->mode[3]][b->uvmode]++;
} else {
static const uint8_t inter_mode_ctx_lut[14][14] = {
{ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
{ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
{ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
{ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
{ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
{ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
{ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
{ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
{ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
{ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
{ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 2, 2, 1, 3 },
{ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 2, 2, 1, 3 },
{ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 0, 3 },
{ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 3, 3, 4 },
};
if (s->s.h.segmentation.enabled && s->s.h.segmentation.feat[b->seg_id].ref_enabled) {
av_assert2(s->s.h.segmentation.feat[b->seg_id].ref_val != 0);
b->comp = 0;
b->ref[0] = s->s.h.segmentation.feat[b->seg_id].ref_val - 1;
} else {
// read comp_pred flag
if (s->s.h.comppredmode != PRED_SWITCHABLE) {
b->comp = s->s.h.comppredmode == PRED_COMPREF;
} else {
int c;
// FIXME add intra as ref=0xff (or -1) to make these easier?
if (have_a) {
if (have_l) {
if (s->above_comp_ctx[col] && td->left_comp_ctx[row7]) {
c = 4;
} else if (s->above_comp_ctx[col]) {
c = 2 + (td->left_intra_ctx[row7] ||
td->left_ref_ctx[row7] == s->s.h.fixcompref);
} else if (td->left_comp_ctx[row7]) {
c = 2 + (s->above_intra_ctx[col] ||
s->above_ref_ctx[col] == s->s.h.fixcompref);
} else {
c = (!s->above_intra_ctx[col] &&
s->above_ref_ctx[col] == s->s.h.fixcompref) ^
(!td->left_intra_ctx[row7] &&
td->left_ref_ctx[row & 7] == s->s.h.fixcompref);
}
} else {
c = s->above_comp_ctx[col] ? 3 :
(!s->above_intra_ctx[col] && s->above_ref_ctx[col] == s->s.h.fixcompref);
}
} else if (have_l) {
c = td->left_comp_ctx[row7] ? 3 :
(!td->left_intra_ctx[row7] && td->left_ref_ctx[row7] == s->s.h.fixcompref);
} else {
c = 1;
}
b->comp = vpx_rac_get_prob(td->c, s->prob.p.comp[c]);
td->counts.comp[c][b->comp]++;
}
// read actual references
// FIXME probably cache a few variables here to prevent repetitive
// memory accesses below
if (b->comp) { /* two references */
int fix_idx = s->s.h.signbias[s->s.h.fixcompref], var_idx = !fix_idx, c, bit;
b->ref[fix_idx] = s->s.h.fixcompref;
// FIXME can this codeblob be replaced by some sort of LUT?
if (have_a) {
if (have_l) {
if (s->above_intra_ctx[col]) {
if (td->left_intra_ctx[row7]) {
c = 2;
} else {
c = 1 + 2 * (td->left_ref_ctx[row7] != s->s.h.varcompref[1]);
}
} else if (td->left_intra_ctx[row7]) {
c = 1 + 2 * (s->above_ref_ctx[col] != s->s.h.varcompref[1]);
} else {
int refl = td->left_ref_ctx[row7], refa = s->above_ref_ctx[col];
if (refl == refa && refa == s->s.h.varcompref[1]) {
c = 0;
} else if (!td->left_comp_ctx[row7] && !s->above_comp_ctx[col]) {
if ((refa == s->s.h.fixcompref && refl == s->s.h.varcompref[0]) ||
(refl == s->s.h.fixcompref && refa == s->s.h.varcompref[0])) {
c = 4;
} else {
c = (refa == refl) ? 3 : 1;
}
} else if (!td->left_comp_ctx[row7]) {
if (refa == s->s.h.varcompref[1] && refl != s->s.h.varcompref[1]) {
c = 1;
} else {
c = (refl == s->s.h.varcompref[1] &&
refa != s->s.h.varcompref[1]) ? 2 : 4;
}
} else if (!s->above_comp_ctx[col]) {
if (refl == s->s.h.varcompref[1] && refa != s->s.h.varcompref[1]) {
c = 1;
} else {
c = (refa == s->s.h.varcompref[1] &&
refl != s->s.h.varcompref[1]) ? 2 : 4;
}
} else {
c = (refl == refa) ? 4 : 2;
}
}
} else {
if (s->above_intra_ctx[col]) {
c = 2;
} else if (s->above_comp_ctx[col]) {
c = 4 * (s->above_ref_ctx[col] != s->s.h.varcompref[1]);
} else {
c = 3 * (s->above_ref_ctx[col] != s->s.h.varcompref[1]);
}
}
} else if (have_l) {
if (td->left_intra_ctx[row7]) {
c = 2;
} else if (td->left_comp_ctx[row7]) {
c = 4 * (td->left_ref_ctx[row7] != s->s.h.varcompref[1]);
} else {
c = 3 * (td->left_ref_ctx[row7] != s->s.h.varcompref[1]);
}
} else {
c = 2;
}
bit = vpx_rac_get_prob(td->c, s->prob.p.comp_ref[c]);
b->ref[var_idx] = s->s.h.varcompref[bit];
td->counts.comp_ref[c][bit]++;
} else /* single reference */ {
int bit, c;
if (have_a && !s->above_intra_ctx[col]) {
if (have_l && !td->left_intra_ctx[row7]) {
if (td->left_comp_ctx[row7]) {
if (s->above_comp_ctx[col]) {
c = 1 + (!s->s.h.fixcompref || !td->left_ref_ctx[row7] ||
!s->above_ref_ctx[col]);
} else {
c = (3 * !s->above_ref_ctx[col]) +
(!s->s.h.fixcompref || !td->left_ref_ctx[row7]);
}
} else if (s->above_comp_ctx[col]) {
c = (3 * !td->left_ref_ctx[row7]) +
(!s->s.h.fixcompref || !s->above_ref_ctx[col]);
} else {
c = 2 * !td->left_ref_ctx[row7] + 2 * !s->above_ref_ctx[col];
}
} else if (s->above_intra_ctx[col]) {
c = 2;
} else if (s->above_comp_ctx[col]) {
c = 1 + (!s->s.h.fixcompref || !s->above_ref_ctx[col]);
} else {
c = 4 * (!s->above_ref_ctx[col]);
}
} else if (have_l && !td->left_intra_ctx[row7]) {
if (td->left_intra_ctx[row7]) {
c = 2;
} else if (td->left_comp_ctx[row7]) {
c = 1 + (!s->s.h.fixcompref || !td->left_ref_ctx[row7]);
} else {
c = 4 * (!td->left_ref_ctx[row7]);
}
} else {
c = 2;
}
bit = vpx_rac_get_prob(td->c, s->prob.p.single_ref[c][0]);
td->counts.single_ref[c][0][bit]++;
if (!bit) {
b->ref[0] = 0;
} else {
// FIXME can this codeblob be replaced by some sort of LUT?
if (have_a) {
if (have_l) {
if (td->left_intra_ctx[row7]) {
if (s->above_intra_ctx[col]) {
c = 2;
} else if (s->above_comp_ctx[col]) {
c = 1 + 2 * (s->s.h.fixcompref == 1 ||
s->above_ref_ctx[col] == 1);
} else if (!s->above_ref_ctx[col]) {
c = 3;
} else {
c = 4 * (s->above_ref_ctx[col] == 1);
}
} else if (s->above_intra_ctx[col]) {
if (td->left_intra_ctx[row7]) {
c = 2;
} else if (td->left_comp_ctx[row7]) {
c = 1 + 2 * (s->s.h.fixcompref == 1 ||
td->left_ref_ctx[row7] == 1);
} else if (!td->left_ref_ctx[row7]) {
c = 3;
} else {
c = 4 * (td->left_ref_ctx[row7] == 1);
}
} else if (s->above_comp_ctx[col]) {
if (td->left_comp_ctx[row7]) {
if (td->left_ref_ctx[row7] == s->above_ref_ctx[col]) {
c = 3 * (s->s.h.fixcompref == 1 ||
td->left_ref_ctx[row7] == 1);
} else {
c = 2;
}
} else if (!td->left_ref_ctx[row7]) {
c = 1 + 2 * (s->s.h.fixcompref == 1 ||
s->above_ref_ctx[col] == 1);
} else {
c = 3 * (td->left_ref_ctx[row7] == 1) +
(s->s.h.fixcompref == 1 || s->above_ref_ctx[col] == 1);
}
} else if (td->left_comp_ctx[row7]) {
if (!s->above_ref_ctx[col]) {
c = 1 + 2 * (s->s.h.fixcompref == 1 ||
td->left_ref_ctx[row7] == 1);
} else {
c = 3 * (s->above_ref_ctx[col] == 1) +
(s->s.h.fixcompref == 1 || td->left_ref_ctx[row7] == 1);
}
} else if (!s->above_ref_ctx[col]) {
if (!td->left_ref_ctx[row7]) {
c = 3;
} else {
c = 4 * (td->left_ref_ctx[row7] == 1);
}
} else if (!td->left_ref_ctx[row7]) {
c = 4 * (s->above_ref_ctx[col] == 1);
} else {
c = 2 * (td->left_ref_ctx[row7] == 1) +
2 * (s->above_ref_ctx[col] == 1);
}
} else {
if (s->above_intra_ctx[col] ||
(!s->above_comp_ctx[col] && !s->above_ref_ctx[col])) {
c = 2;
} else if (s->above_comp_ctx[col]) {
c = 3 * (s->s.h.fixcompref == 1 || s->above_ref_ctx[col] == 1);
} else {
c = 4 * (s->above_ref_ctx[col] == 1);
}
}
} else if (have_l) {
if (td->left_intra_ctx[row7] ||
(!td->left_comp_ctx[row7] && !td->left_ref_ctx[row7])) {
c = 2;
} else if (td->left_comp_ctx[row7]) {
c = 3 * (s->s.h.fixcompref == 1 || td->left_ref_ctx[row7] == 1);
} else {
c = 4 * (td->left_ref_ctx[row7] == 1);
}
} else {
c = 2;
}
bit = vpx_rac_get_prob(td->c, s->prob.p.single_ref[c][1]);
td->counts.single_ref[c][1][bit]++;
b->ref[0] = 1 + bit;
}
}
}
if (b->bs <= BS_8x8) {
if (s->s.h.segmentation.enabled && s->s.h.segmentation.feat[b->seg_id].skip_enabled) {
b->mode[0] =
b->mode[1] =
b->mode[2] =
b->mode[3] = ZEROMV;
} else {
static const uint8_t off[10] = {
3, 0, 0, 1, 0, 0, 0, 0, 0, 0
};
// FIXME this needs to use the LUT tables from find_ref_mvs
// because not all are -1,0/0,-1
int c = inter_mode_ctx_lut[s->above_mode_ctx[col + off[b->bs]]]
[td->left_mode_ctx[row7 + off[b->bs]]];
b->mode[0] = vp89_rac_get_tree(td->c, ff_vp9_inter_mode_tree,
s->prob.p.mv_mode[c]);
b->mode[1] =
b->mode[2] =
b->mode[3] = b->mode[0];
td->counts.mv_mode[c][b->mode[0] - 10]++;
}
}
if (s->s.h.filtermode == FILTER_SWITCHABLE) {
int c;
if (have_a && s->above_mode_ctx[col] >= NEARESTMV) {
if (have_l && td->left_mode_ctx[row7] >= NEARESTMV) {
c = s->above_filter_ctx[col] == td->left_filter_ctx[row7] ?
td->left_filter_ctx[row7] : 3;
} else {
c = s->above_filter_ctx[col];
}
} else if (have_l && td->left_mode_ctx[row7] >= NEARESTMV) {
c = td->left_filter_ctx[row7];
} else {
c = 3;
}
filter_id = vp89_rac_get_tree(td->c, ff_vp9_filter_tree,
s->prob.p.filter[c]);
td->counts.filter[c][filter_id]++;
b->filter = ff_vp9_filter_lut[filter_id];
} else {
b->filter = s->s.h.filtermode;
}
if (b->bs > BS_8x8) {
int c = inter_mode_ctx_lut[s->above_mode_ctx[col]][td->left_mode_ctx[row7]];
b->mode[0] = vp89_rac_get_tree(td->c, ff_vp9_inter_mode_tree,
s->prob.p.mv_mode[c]);
td->counts.mv_mode[c][b->mode[0] - 10]++;
ff_vp9_fill_mv(td, b->mv[0], b->mode[0], 0);
if (b->bs != BS_8x4) {
b->mode[1] = vp89_rac_get_tree(td->c, ff_vp9_inter_mode_tree,
s->prob.p.mv_mode[c]);
td->counts.mv_mode[c][b->mode[1] - 10]++;
ff_vp9_fill_mv(td, b->mv[1], b->mode[1], 1);
} else {
b->mode[1] = b->mode[0];
AV_COPY32(&b->mv[1][0], &b->mv[0][0]);
AV_COPY32(&b->mv[1][1], &b->mv[0][1]);
}
if (b->bs != BS_4x8) {
b->mode[2] = vp89_rac_get_tree(td->c, ff_vp9_inter_mode_tree,
s->prob.p.mv_mode[c]);
td->counts.mv_mode[c][b->mode[2] - 10]++;
ff_vp9_fill_mv(td, b->mv[2], b->mode[2], 2);
if (b->bs != BS_8x4) {
b->mode[3] = vp89_rac_get_tree(td->c, ff_vp9_inter_mode_tree,
s->prob.p.mv_mode[c]);
td->counts.mv_mode[c][b->mode[3] - 10]++;
ff_vp9_fill_mv(td, b->mv[3], b->mode[3], 3);
} else {
b->mode[3] = b->mode[2];
AV_COPY32(&b->mv[3][0], &b->mv[2][0]);
AV_COPY32(&b->mv[3][1], &b->mv[2][1]);
}
} else {
b->mode[2] = b->mode[0];
AV_COPY32(&b->mv[2][0], &b->mv[0][0]);
AV_COPY32(&b->mv[2][1], &b->mv[0][1]);
b->mode[3] = b->mode[1];
AV_COPY32(&b->mv[3][0], &b->mv[1][0]);
AV_COPY32(&b->mv[3][1], &b->mv[1][1]);
}
} else {
ff_vp9_fill_mv(td, b->mv[0], b->mode[0], -1);
AV_COPY32(&b->mv[1][0], &b->mv[0][0]);
AV_COPY32(&b->mv[2][0], &b->mv[0][0]);
AV_COPY32(&b->mv[3][0], &b->mv[0][0]);
AV_COPY32(&b->mv[1][1], &b->mv[0][1]);
AV_COPY32(&b->mv[2][1], &b->mv[0][1]);
AV_COPY32(&b->mv[3][1], &b->mv[0][1]);
}
vref = b->ref[b->comp ? s->s.h.signbias[s->s.h.varcompref[0]] : 0];
}
#if HAVE_FAST_64BIT
#define SPLAT_CTX(var, val, n) \
switch (n) { \
case 1: var = val; break; \
case 2: AV_WN16A(&var, val * 0x0101); break; \
case 4: AV_WN32A(&var, val * 0x01010101); break; \
case 8: AV_WN64A(&var, val * 0x0101010101010101ULL); break; \
case 16: { \
uint64_t v64 = val * 0x0101010101010101ULL; \
AV_WN64A( &var, v64); \
AV_WN64A(&((uint8_t *) &var)[8], v64); \
break; \
} \
}
#else
#define SPLAT_CTX(var, val, n) \
switch (n) { \
case 1: var = val; break; \
case 2: AV_WN16A(&var, val * 0x0101); break; \
case 4: AV_WN32A(&var, val * 0x01010101); break; \
case 8: { \
uint32_t v32 = val * 0x01010101; \
AV_WN32A( &var, v32); \
AV_WN32A(&((uint8_t *) &var)[4], v32); \
break; \
} \
case 16: { \
uint32_t v32 = val * 0x01010101; \
AV_WN32A( &var, v32); \
AV_WN32A(&((uint8_t *) &var)[4], v32); \
AV_WN32A(&((uint8_t *) &var)[8], v32); \
AV_WN32A(&((uint8_t *) &var)[12], v32); \
break; \
} \
}
#endif
switch (ff_vp9_bwh_tab[1][b->bs][0]) {
#define SET_CTXS(perf, dir, off, n) \
do { \
SPLAT_CTX(perf->dir##_skip_ctx[off], b->skip, n); \
SPLAT_CTX(perf->dir##_txfm_ctx[off], b->tx, n); \
SPLAT_CTX(perf->dir##_partition_ctx[off], dir##_ctx[b->bs], n); \
if (!s->s.h.keyframe && !s->s.h.intraonly) { \
SPLAT_CTX(perf->dir##_intra_ctx[off], b->intra, n); \
SPLAT_CTX(perf->dir##_comp_ctx[off], b->comp, n); \
SPLAT_CTX(perf->dir##_mode_ctx[off], b->mode[3], n); \
if (!b->intra) { \
SPLAT_CTX(perf->dir##_ref_ctx[off], vref, n); \
if (s->s.h.filtermode == FILTER_SWITCHABLE) { \
SPLAT_CTX(perf->dir##_filter_ctx[off], filter_id, n); \
} \
} \
} \
} while (0)
case 1: SET_CTXS(s, above, col, 1); break;
case 2: SET_CTXS(s, above, col, 2); break;
case 4: SET_CTXS(s, above, col, 4); break;
case 8: SET_CTXS(s, above, col, 8); break;
}
switch (ff_vp9_bwh_tab[1][b->bs][1]) {
case 1: SET_CTXS(td, left, row7, 1); break;
case 2: SET_CTXS(td, left, row7, 2); break;
case 4: SET_CTXS(td, left, row7, 4); break;
case 8: SET_CTXS(td, left, row7, 8); break;
}
#undef SPLAT_CTX
#undef SET_CTXS