Commit bc6e0b64 authored by Ronald S. Bultje's avatar Ronald S. Bultje Committed by Anton Khirnov

vp9: split last/cur_frame from the reference buffers.

We need more information from last/cur_frame than from reference
buffers, so we can use a simplified structure for reference buffers,
and then store mvs and segmentation map information in last/cur.

This prepares the decoder for frame threading support.
Signed-off-by: 's avatarAnton Khirnov <anton@khirnov.net>
parent 04763c6f
This diff is collapsed.
...@@ -27,9 +27,11 @@ ...@@ -27,9 +27,11 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include "libavutil/buffer.h"
#include "libavutil/internal.h" #include "libavutil/internal.h"
#include "avcodec.h" #include "avcodec.h"
#include "thread.h"
#include "vp56.h" #include "vp56.h"
enum TxfmMode { enum TxfmMode {
...@@ -225,6 +227,16 @@ typedef struct VP9Filter { ...@@ -225,6 +227,16 @@ typedef struct VP9Filter {
[8 /* rows */][4 /* 0=16, 1=8, 2=4, 3=inner4 */]; [8 /* rows */][4 /* 0=16, 1=8, 2=4, 3=inner4 */];
} VP9Filter; } VP9Filter;
typedef struct VP9Frame {
ThreadFrame tf;
uint8_t *segmentation_map;
VP9MVRefPair *mv;
AVBufferRef *segmentation_map_buf;
AVBufferRef *mv_buf;
} VP9Frame;
enum BlockLevel { enum BlockLevel {
BL_64X64, BL_64X64,
BL_32X32, BL_32X32,
...@@ -293,8 +305,12 @@ typedef struct VP9Context { ...@@ -293,8 +305,12 @@ typedef struct VP9Context {
uint8_t refidx[3]; uint8_t refidx[3];
uint8_t signbias[3]; uint8_t signbias[3];
uint8_t varcompref[2]; uint8_t varcompref[2];
AVFrame *refs[8];
AVFrame *cur_frame; ThreadFrame refs[8];
#define CUR_FRAME 0
#define LAST_FRAME 1
VP9Frame frames[2];
struct { struct {
uint8_t level; uint8_t level;
...@@ -392,8 +408,6 @@ typedef struct VP9Context { ...@@ -392,8 +408,6 @@ typedef struct VP9Context {
// whole-frame cache // whole-frame cache
uint8_t *intra_pred_data[3]; uint8_t *intra_pred_data[3];
uint8_t *segmentation_map;
VP9MVRefPair *mv[2];
VP9Filter *lflvl; VP9Filter *lflvl;
DECLARE_ALIGNED(32, uint8_t, edge_emu_buffer)[71 * 80]; DECLARE_ALIGNED(32, uint8_t, edge_emu_buffer)[71 * 80];
......
...@@ -70,13 +70,14 @@ static void decode_mode(VP9Context *s, VP9Block *const b) ...@@ -70,13 +70,14 @@ static void decode_mode(VP9Context *s, VP9Block *const b)
vp56_rac_get_prob_branchy(&s->c, vp56_rac_get_prob_branchy(&s->c,
s->prob.segpred[s->above_segpred_ctx[col] + s->prob.segpred[s->above_segpred_ctx[col] +
s->left_segpred_ctx[row7]]))) { s->left_segpred_ctx[row7]]))) {
uint8_t *refsegmap = s->frames[LAST_FRAME].segmentation_map;
int pred = MAX_SEGMENT - 1; int pred = MAX_SEGMENT - 1;
int x; int x;
for (y = 0; y < h4; y++) for (y = 0; y < h4; y++)
for (x = 0; x < w4; x++) for (x = 0; x < w4; x++)
pred = FFMIN(pred, pred = FFMIN(pred,
s->segmentation_map[(y + row) * 8 * s->sb_cols + x + col]); refsegmap[(y + row) * 8 * s->sb_cols + x + col]);
b->seg_id = pred; b->seg_id = pred;
memset(&s->above_segpred_ctx[col], 1, w4); memset(&s->above_segpred_ctx[col], 1, w4);
...@@ -89,8 +90,10 @@ static void decode_mode(VP9Context *s, VP9Block *const b) ...@@ -89,8 +90,10 @@ static void decode_mode(VP9Context *s, VP9Block *const b)
memset(&s->left_segpred_ctx[row7], 0, h4); memset(&s->left_segpred_ctx[row7], 0, h4);
} }
if ((s->segmentation.enabled && s->segmentation.update_map) || s->keyframe) { if ((s->segmentation.enabled && s->segmentation.update_map) || s->keyframe) {
uint8_t *segmap = s->frames[CUR_FRAME].segmentation_map;
for (y = 0; y < h4; y++) for (y = 0; y < h4; y++)
memset(&s->segmentation_map[(y + row) * 8 * s->sb_cols + col], memset(&segmap[(y + row) * 8 * s->sb_cols + col],
b->seg_id, w4); b->seg_id, w4);
} }
...@@ -684,24 +687,25 @@ static void decode_mode(VP9Context *s, VP9Block *const b) ...@@ -684,24 +687,25 @@ static void decode_mode(VP9Context *s, VP9Block *const b)
// FIXME kinda ugly // FIXME kinda ugly
for (y = 0; y < h4; y++) { for (y = 0; y < h4; y++) {
int x, o = (row + y) * s->sb_cols * 8 + col; int x, o = (row + y) * s->sb_cols * 8 + col;
VP9MVRefPair *mv = &s->frames[CUR_FRAME].mv[o];
if (b->intra) { if (b->intra) {
for (x = 0; x < w4; x++) { for (x = 0; x < w4; x++) {
s->mv[0][o + x].ref[0] = mv[x].ref[0] =
s->mv[0][o + x].ref[1] = -1; mv[x].ref[1] = -1;
} }
} else if (b->comp) { } else if (b->comp) {
for (x = 0; x < w4; x++) { for (x = 0; x < w4; x++) {
s->mv[0][o + x].ref[0] = b->ref[0]; mv[x].ref[0] = b->ref[0];
s->mv[0][o + x].ref[1] = b->ref[1]; mv[x].ref[1] = b->ref[1];
AV_COPY32(&s->mv[0][o + x].mv[0], &b->mv[3][0]); AV_COPY32(&mv[x].mv[0], &b->mv[3][0]);
AV_COPY32(&s->mv[0][o + x].mv[1], &b->mv[3][1]); AV_COPY32(&mv[x].mv[1], &b->mv[3][1]);
} }
} else { } else {
for (x = 0; x < w4; x++) { for (x = 0; x < w4; x++) {
s->mv[0][o + x].ref[0] = b->ref[0]; mv[x].ref[0] = b->ref[0];
s->mv[0][o + x].ref[1] = -1; mv[x].ref[1] = -1;
AV_COPY32(&s->mv[0][o + x].mv[0], &b->mv[3][0]); AV_COPY32(&mv[x].mv[0], &b->mv[3][0]);
} }
} }
} }
...@@ -1071,6 +1075,7 @@ static void intra_recon(AVCodecContext *avctx, ptrdiff_t y_off, ptrdiff_t uv_off ...@@ -1071,6 +1075,7 @@ static void intra_recon(AVCodecContext *avctx, ptrdiff_t y_off, ptrdiff_t uv_off
{ {
VP9Context *s = avctx->priv_data; VP9Context *s = avctx->priv_data;
VP9Block *const b = &s->b; VP9Block *const b = &s->b;
AVFrame *f = s->frames[CUR_FRAME].tf.f;
int row = b->row, col = b->col; int row = b->row, col = b->col;
int w4 = bwh_tab[1][b->bs][0] << 1, step1d = 1 << b->tx, n; int w4 = bwh_tab[1][b->bs][0] << 1, step1d = 1 << b->tx, n;
int h4 = bwh_tab[1][b->bs][1] << 1, x, y, step = 1 << (b->tx * 2); int h4 = bwh_tab[1][b->bs][1] << 1, x, y, step = 1 << (b->tx * 2);
...@@ -1078,7 +1083,7 @@ static void intra_recon(AVCodecContext *avctx, ptrdiff_t y_off, ptrdiff_t uv_off ...@@ -1078,7 +1083,7 @@ static void intra_recon(AVCodecContext *avctx, ptrdiff_t y_off, ptrdiff_t uv_off
int end_y = FFMIN(2 * (s->rows - row), h4); int end_y = FFMIN(2 * (s->rows - row), h4);
int tx = 4 * s->lossless + b->tx, uvtx = b->uvtx + 4 * s->lossless; int tx = 4 * s->lossless + b->tx, uvtx = b->uvtx + 4 * s->lossless;
int uvstep1d = 1 << b->uvtx, p; int uvstep1d = 1 << b->uvtx, p;
uint8_t *dst = b->dst[0], *dst_r = s->cur_frame->data[0] + y_off; uint8_t *dst = b->dst[0], *dst_r = f->data[0] + y_off;
for (n = 0, y = 0; y < end_y; y += step1d) { for (n = 0, y = 0; y < end_y; y += step1d) {
uint8_t *ptr = dst, *ptr_r = dst_r; uint8_t *ptr = dst, *ptr_r = dst_r;
...@@ -1092,7 +1097,7 @@ static void intra_recon(AVCodecContext *avctx, ptrdiff_t y_off, ptrdiff_t uv_off ...@@ -1092,7 +1097,7 @@ static void intra_recon(AVCodecContext *avctx, ptrdiff_t y_off, ptrdiff_t uv_off
int eob = b->tx > TX_8X8 ? AV_RN16A(&s->eob[n]) : s->eob[n]; int eob = b->tx > TX_8X8 ? AV_RN16A(&s->eob[n]) : s->eob[n];
mode = check_intra_mode(s, mode, &a, ptr_r, mode = check_intra_mode(s, mode, &a, ptr_r,
s->cur_frame->linesize[0], f->linesize[0],
ptr, b->y_stride, l, ptr, b->y_stride, l,
col, x, w4, row, y, b->tx, 0); col, x, w4, row, y, b->tx, 0);
s->dsp.intra_pred[b->tx][mode](ptr, b->y_stride, l, a); s->dsp.intra_pred[b->tx][mode](ptr, b->y_stride, l, a);
...@@ -1100,7 +1105,7 @@ static void intra_recon(AVCodecContext *avctx, ptrdiff_t y_off, ptrdiff_t uv_off ...@@ -1100,7 +1105,7 @@ static void intra_recon(AVCodecContext *avctx, ptrdiff_t y_off, ptrdiff_t uv_off
s->dsp.itxfm_add[tx][txtp](ptr, b->y_stride, s->dsp.itxfm_add[tx][txtp](ptr, b->y_stride,
s->block + 16 * n, eob); s->block + 16 * n, eob);
} }
dst_r += 4 * s->cur_frame->linesize[0] * step1d; dst_r += 4 * f->linesize[0] * step1d;
dst += 4 * b->y_stride * step1d; dst += 4 * b->y_stride * step1d;
} }
...@@ -1112,7 +1117,7 @@ static void intra_recon(AVCodecContext *avctx, ptrdiff_t y_off, ptrdiff_t uv_off ...@@ -1112,7 +1117,7 @@ static void intra_recon(AVCodecContext *avctx, ptrdiff_t y_off, ptrdiff_t uv_off
step = 1 << (b->uvtx * 2); step = 1 << (b->uvtx * 2);
for (p = 0; p < 2; p++) { for (p = 0; p < 2; p++) {
dst = b->dst[1 + p]; dst = b->dst[1 + p];
dst_r = s->cur_frame->data[1 + p] + uv_off; dst_r = f->data[1 + p] + uv_off;
for (n = 0, y = 0; y < end_y; y += uvstep1d) { for (n = 0, y = 0; y < end_y; y += uvstep1d) {
uint8_t *ptr = dst, *ptr_r = dst_r; uint8_t *ptr = dst, *ptr_r = dst_r;
for (x = 0; x < end_x; for (x = 0; x < end_x;
...@@ -1125,7 +1130,7 @@ static void intra_recon(AVCodecContext *avctx, ptrdiff_t y_off, ptrdiff_t uv_off ...@@ -1125,7 +1130,7 @@ static void intra_recon(AVCodecContext *avctx, ptrdiff_t y_off, ptrdiff_t uv_off
: s->uveob[p][n]; : s->uveob[p][n];
mode = check_intra_mode(s, mode, &a, ptr_r, mode = check_intra_mode(s, mode, &a, ptr_r,
s->cur_frame->linesize[1], f->linesize[1],
ptr, b->uv_stride, l, ptr, b->uv_stride, l,
col, x, w4, row, y, b->uvtx, p + 1); col, x, w4, row, y, b->uvtx, p + 1);
s->dsp.intra_pred[b->uvtx][mode](ptr, b->uv_stride, l, a); s->dsp.intra_pred[b->uvtx][mode](ptr, b->uv_stride, l, a);
...@@ -1134,7 +1139,7 @@ static void intra_recon(AVCodecContext *avctx, ptrdiff_t y_off, ptrdiff_t uv_off ...@@ -1134,7 +1139,7 @@ static void intra_recon(AVCodecContext *avctx, ptrdiff_t y_off, ptrdiff_t uv_off
s->uvblock[p] + 16 * n, s->uvblock[p] + 16 * n,
eob); eob);
} }
dst_r += 4 * uvstep1d * s->cur_frame->linesize[1]; dst_r += 4 * uvstep1d * f->linesize[1];
dst += 4 * uvstep1d * b->uv_stride; dst += 4 * uvstep1d * b->uv_stride;
} }
} }
...@@ -1224,8 +1229,12 @@ static int inter_recon(AVCodecContext *avctx) ...@@ -1224,8 +1229,12 @@ static int inter_recon(AVCodecContext *avctx)
VP9Context *s = avctx->priv_data; VP9Context *s = avctx->priv_data;
VP9Block *const b = &s->b; VP9Block *const b = &s->b;
int row = b->row, col = b->col; int row = b->row, col = b->col;
AVFrame *ref1 = s->refs[s->refidx[b->ref[0]]];
AVFrame *ref2 = b->comp ? s->refs[s->refidx[b->ref[1]]] : NULL; ThreadFrame *tref1 = &s->refs[s->refidx[b->ref[0]]];
ThreadFrame *tref2 = b->comp ? &s->refs[s->refidx[b->ref[1]]] : NULL;
AVFrame *ref1 = tref1->f;
AVFrame *ref2 = tref2 ? tref2->f : NULL;
int w = avctx->width, h = avctx->height; int w = avctx->width, h = avctx->height;
ptrdiff_t ls_y = b->y_stride, ls_uv = b->uv_stride; ptrdiff_t ls_y = b->y_stride, ls_uv = b->uv_stride;
...@@ -1547,6 +1556,7 @@ int ff_vp9_decode_block(AVCodecContext *avctx, int row, int col, ...@@ -1547,6 +1556,7 @@ int ff_vp9_decode_block(AVCodecContext *avctx, int row, int col,
{ {
VP9Context *s = avctx->priv_data; VP9Context *s = avctx->priv_data;
VP9Block *const b = &s->b; VP9Block *const b = &s->b;
AVFrame *f = s->frames[CUR_FRAME].tf.f;
enum BlockSize bs = bl * 3 + bp; enum BlockSize bs = bl * 3 + bp;
int ret, y, w4 = bwh_tab[1][bs][0], h4 = bwh_tab[1][bs][1], lvl; int ret, y, w4 = bwh_tab[1][bs][0], h4 = bwh_tab[1][bs][1], lvl;
int emu[2]; int emu[2];
...@@ -1582,25 +1592,25 @@ int ff_vp9_decode_block(AVCodecContext *avctx, int row, int col, ...@@ -1582,25 +1592,25 @@ int ff_vp9_decode_block(AVCodecContext *avctx, int row, int col,
/* Emulated overhangs if the stride of the target buffer can't hold. /* Emulated overhangs if the stride of the target buffer can't hold.
* This allows to support emu-edge and so on even if we have large * This allows to support emu-edge and so on even if we have large
* block overhangs. */ * block overhangs. */
emu[0] = (col + w4) * 8 > s->cur_frame->linesize[0] || emu[0] = (col + w4) * 8 > f->linesize[0] ||
(row + h4) > s->rows; (row + h4) > s->rows;
emu[1] = (col + w4) * 4 > s->cur_frame->linesize[1] || emu[1] = (col + w4) * 4 > f->linesize[1] ||
(row + h4) > s->rows; (row + h4) > s->rows;
if (emu[0]) { if (emu[0]) {
b->dst[0] = s->tmp_y; b->dst[0] = s->tmp_y;
b->y_stride = 64; b->y_stride = 64;
} else { } else {
b->dst[0] = s->cur_frame->data[0] + yoff; b->dst[0] = f->data[0] + yoff;
b->y_stride = s->cur_frame->linesize[0]; b->y_stride = f->linesize[0];
} }
if (emu[1]) { if (emu[1]) {
b->dst[1] = s->tmp_uv[0]; b->dst[1] = s->tmp_uv[0];
b->dst[2] = s->tmp_uv[1]; b->dst[2] = s->tmp_uv[1];
b->uv_stride = 32; b->uv_stride = 32;
} else { } else {
b->dst[1] = s->cur_frame->data[1] + uvoff; b->dst[1] = f->data[1] + uvoff;
b->dst[2] = s->cur_frame->data[2] + uvoff; b->dst[2] = f->data[2] + uvoff;
b->uv_stride = s->cur_frame->linesize[1]; b->uv_stride = f->linesize[1];
} }
if (b->intra) { if (b->intra) {
intra_recon(avctx, yoff, uvoff); intra_recon(avctx, yoff, uvoff);
...@@ -1618,9 +1628,9 @@ int ff_vp9_decode_block(AVCodecContext *avctx, int row, int col, ...@@ -1618,9 +1628,9 @@ int ff_vp9_decode_block(AVCodecContext *avctx, int row, int col,
av_assert2(n <= 4); av_assert2(n <= 4);
if (w & bw) { if (w & bw) {
s->dsp.mc[n][0][0][0][0](s->cur_frame->data[0] + yoff + o, s->dsp.mc[n][0][0][0][0](f->data[0] + yoff + o,
s->tmp_y + o, s->tmp_y + o,
s->cur_frame->linesize[0], f->linesize[0],
64, h, 0, 0); 64, h, 0, 0);
o += bw; o += bw;
} }
...@@ -1636,13 +1646,13 @@ int ff_vp9_decode_block(AVCodecContext *avctx, int row, int col, ...@@ -1636,13 +1646,13 @@ int ff_vp9_decode_block(AVCodecContext *avctx, int row, int col,
av_assert2(n <= 4); av_assert2(n <= 4);
if (w & bw) { if (w & bw) {
s->dsp.mc[n][0][0][0][0](s->cur_frame->data[1] + uvoff + o, s->dsp.mc[n][0][0][0][0](f->data[1] + uvoff + o,
s->tmp_uv[0] + o, s->tmp_uv[0] + o,
s->cur_frame->linesize[1], f->linesize[1],
32, h, 0, 0); 32, h, 0, 0);
s->dsp.mc[n][0][0][0][0](s->cur_frame->data[2] + uvoff + o, s->dsp.mc[n][0][0][0][0](f->data[2] + uvoff + o,
s->tmp_uv[1] + o, s->tmp_uv[1] + o,
s->cur_frame->linesize[2], f->linesize[2],
32, h, 0, 0); 32, h, 0, 0);
o += bw; o += bw;
} }
......
...@@ -125,7 +125,7 @@ static void find_ref_mvs(VP9Context *s, ...@@ -125,7 +125,7 @@ static void find_ref_mvs(VP9Context *s,
} while (0) } while (0)
if (row > 0) { if (row > 0) {
VP9MVRefPair *mv = &s->mv[0][(row - 1) * s->sb_cols * 8 + col]; VP9MVRefPair *mv = &s->frames[CUR_FRAME].mv[(row - 1) * s->sb_cols * 8 + col];
if (mv->ref[0] == ref) if (mv->ref[0] == ref)
RETURN_MV(s->above_mv_ctx[2 * col + (sb & 1)][0]); RETURN_MV(s->above_mv_ctx[2 * col + (sb & 1)][0]);
...@@ -133,7 +133,7 @@ static void find_ref_mvs(VP9Context *s, ...@@ -133,7 +133,7 @@ static void find_ref_mvs(VP9Context *s,
RETURN_MV(s->above_mv_ctx[2 * col + (sb & 1)][1]); RETURN_MV(s->above_mv_ctx[2 * col + (sb & 1)][1]);
} }
if (col > s->tiling.tile_col_start) { if (col > s->tiling.tile_col_start) {
VP9MVRefPair *mv = &s->mv[0][row * s->sb_cols * 8 + col - 1]; VP9MVRefPair *mv = &s->frames[CUR_FRAME].mv[row * s->sb_cols * 8 + col - 1];
if (mv->ref[0] == ref) if (mv->ref[0] == ref)
RETURN_MV(s->left_mv_ctx[2 * row7 + (sb >> 1)][0]); RETURN_MV(s->left_mv_ctx[2 * row7 + (sb >> 1)][0]);
...@@ -151,7 +151,7 @@ static void find_ref_mvs(VP9Context *s, ...@@ -151,7 +151,7 @@ static void find_ref_mvs(VP9Context *s,
if (c >= s->tiling.tile_col_start && c < s->cols && if (c >= s->tiling.tile_col_start && c < s->cols &&
r >= 0 && r < s->rows) { r >= 0 && r < s->rows) {
VP9MVRefPair *mv = &s->mv[0][r * s->sb_cols * 8 + c]; VP9MVRefPair *mv = &s->frames[CUR_FRAME].mv[r * s->sb_cols * 8 + c];
if (mv->ref[0] == ref) if (mv->ref[0] == ref)
RETURN_MV(mv->mv[0]); RETURN_MV(mv->mv[0]);
...@@ -162,7 +162,7 @@ static void find_ref_mvs(VP9Context *s, ...@@ -162,7 +162,7 @@ static void find_ref_mvs(VP9Context *s,
// MV at this position in previous frame, using same reference frame // MV at this position in previous frame, using same reference frame
if (s->use_last_frame_mvs) { if (s->use_last_frame_mvs) {
VP9MVRefPair *mv = &s->mv[1][row * s->sb_cols * 8 + col]; VP9MVRefPair *mv = &s->frames[LAST_FRAME].mv[row * s->sb_cols * 8 + col];
if (mv->ref[0] == ref) if (mv->ref[0] == ref)
RETURN_MV(mv->mv[0]); RETURN_MV(mv->mv[0]);
...@@ -186,7 +186,7 @@ static void find_ref_mvs(VP9Context *s, ...@@ -186,7 +186,7 @@ static void find_ref_mvs(VP9Context *s,
if (c >= s->tiling.tile_col_start && c < s->cols && if (c >= s->tiling.tile_col_start && c < s->cols &&
r >= 0 && r < s->rows) { r >= 0 && r < s->rows) {
VP9MVRefPair *mv = &s->mv[0][r * s->sb_cols * 8 + c]; VP9MVRefPair *mv = &s->frames[CUR_FRAME].mv[r * s->sb_cols * 8 + c];
if (mv->ref[0] != ref && mv->ref[0] >= 0) if (mv->ref[0] != ref && mv->ref[0] >= 0)
RETURN_SCALE_MV(mv->mv[0], RETURN_SCALE_MV(mv->mv[0],
...@@ -203,7 +203,7 @@ static void find_ref_mvs(VP9Context *s, ...@@ -203,7 +203,7 @@ static void find_ref_mvs(VP9Context *s,
// MV at this position in previous frame, using different reference frame // MV at this position in previous frame, using different reference frame
if (s->use_last_frame_mvs) { if (s->use_last_frame_mvs) {
VP9MVRefPair *mv = &s->mv[1][row * s->sb_cols * 8 + col]; VP9MVRefPair *mv = &s->frames[LAST_FRAME].mv[row * s->sb_cols * 8 + col];
if (mv->ref[0] != ref && mv->ref[0] >= 0) if (mv->ref[0] != ref && mv->ref[0] >= 0)
RETURN_SCALE_MV(mv->mv[0], RETURN_SCALE_MV(mv->mv[0],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment