Commit e5741c56 authored by Jingning Han's avatar Jingning Han Committed by Gerrit Code Review
Browse files

Merge "Allocate dual buffer sets for encoding"

parents 84581e56 3b3aea68
......@@ -27,6 +27,17 @@ typedef struct {
typedef struct {
MODE_INFO mic;
uint8_t *zcoeff_blk;
int16_t *coeff[MAX_MB_PLANE][2];
int16_t *qcoeff[MAX_MB_PLANE][2];
int16_t *dqcoeff[MAX_MB_PLANE][2];
uint16_t *eobs[MAX_MB_PLANE][2];
// dual buffer pointers
int16_t *coeff_pbuf[MAX_MB_PLANE][2];
int16_t *qcoeff_pbuf[MAX_MB_PLANE][2];
int16_t *dqcoeff_pbuf[MAX_MB_PLANE][2];
uint16_t *eobs_pbuf[MAX_MB_PLANE][2];
int num_4x4_blk;
int skip;
int_mv best_ref_mv;
......@@ -57,7 +68,7 @@ typedef struct {
struct macroblock_plane {
DECLARE_ALIGNED(16, int16_t, src_diff[64 * 64]);
DECLARE_ALIGNED(16, int16_t, coeff[64 * 64]);
int16_t *coeff;
struct buf_2d src;
// Quantizer setings
......
......@@ -367,6 +367,8 @@ static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx,
VP9_COMMON *const cm = &cpi->common;
MACROBLOCK *const x = &cpi->mb;
MACROBLOCKD *const xd = &x->e_mbd;
struct macroblock_plane *const p = x->plane;
struct macroblockd_plane *const pd = xd->plane;
MODE_INFO *mi = &ctx->mic;
MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi;
MODE_INFO *mi_addr = xd->mi_8x8[0];
......@@ -383,6 +385,13 @@ static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx,
*mi_addr = *mi;
for (i = 0; i < MAX_MB_PLANE; ++i) {
p[i].coeff = ctx->coeff_pbuf[i][1];
pd[i].qcoeff = ctx->qcoeff_pbuf[i][1];
pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][1];
pd[i].eobs = ctx->eobs_pbuf[i][1];
}
// Restore the coding context of the MB to that that was in place
// when the mode was picked for it
for (y = 0; y < mi_height; y++)
......@@ -578,6 +587,9 @@ static void pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile,
VP9_COMMON *const cm = &cpi->common;
MACROBLOCK *const x = &cpi->mb;
MACROBLOCKD *const xd = &x->e_mbd;
struct macroblock_plane *const p = x->plane;
struct macroblockd_plane *const pd = xd->plane;
int i;
int orig_rdmult = x->rdmult;
double rdmult_ratio;
......@@ -600,6 +612,13 @@ static void pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile,
set_offsets(cpi, tile, mi_row, mi_col, bsize);
xd->mi_8x8[0]->mbmi.sb_type = bsize;
for (i = 0; i < MAX_MB_PLANE; ++i) {
p[i].coeff = ctx->coeff_pbuf[i][1];
pd[i].qcoeff = ctx->qcoeff_pbuf[i][1];
pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][1];
pd[i].eobs = ctx->eobs_pbuf[i][1];
}
// Set to zero to make sure we do not use the previous encoded frame stats
xd->mi_8x8[0]->mbmi.skip_coeff = 0;
......
......@@ -482,6 +482,10 @@ void vp9_first_pass(VP9_COMP *cpi) {
VP9_COMMON *const cm = &cpi->common;
MACROBLOCKD *const xd = &x->e_mbd;
TileInfo tile;
struct macroblock_plane *const p = x->plane;
struct macroblockd_plane *const pd = xd->plane;
PICK_MODE_CONTEXT *ctx = &x->sb64_context;
int i;
int recon_yoffset, recon_uvoffset;
const int lst_yv12_idx = cm->ref_frame_map[cpi->lst_fb_idx];
......@@ -525,6 +529,14 @@ void vp9_first_pass(VP9_COMP *cpi) {
vp9_frame_init_quantizer(cpi);
for (i = 0; i < MAX_MB_PLANE; ++i) {
p[i].coeff = ctx->coeff_pbuf[i][1];
pd[i].qcoeff = ctx->qcoeff_pbuf[i][1];
pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][1];
pd[i].eobs = ctx->eobs_pbuf[i][1];
}
// Initialise the MV cost table to the defaults
// if( cm->current_video_frame == 0)
// if ( 0 )
......
......@@ -1436,6 +1436,49 @@ static void cal_nmvsadcosts_hp(int *mvsadcost[2]) {
} while (++i <= MV_MAX);
}
static void alloc_mode_context(VP9_COMMON *cm, int num_4x4_blk,
PICK_MODE_CONTEXT *ctx) {
int num_pix = num_4x4_blk << 4;
int i, k;
ctx->num_4x4_blk = num_4x4_blk;
CHECK_MEM_ERROR(cm, ctx->zcoeff_blk,
vpx_calloc(num_4x4_blk, sizeof(uint8_t)));
for (i = 0; i < MAX_MB_PLANE; ++i) {
for (k = 0; k < 2; ++k) {
CHECK_MEM_ERROR(cm, ctx->coeff[i][k],
vpx_memalign(16, num_pix * sizeof(int16_t)));
CHECK_MEM_ERROR(cm, ctx->qcoeff[i][k],
vpx_memalign(16, num_pix * sizeof(int16_t)));
CHECK_MEM_ERROR(cm, ctx->dqcoeff[i][k],
vpx_memalign(16, num_pix * sizeof(int16_t)));
CHECK_MEM_ERROR(cm, ctx->eobs[i][k],
vpx_memalign(16, num_pix * sizeof(uint16_t)));
ctx->coeff_pbuf[i][k] = ctx->coeff[i][k];
ctx->qcoeff_pbuf[i][k] = ctx->qcoeff[i][k];
ctx->dqcoeff_pbuf[i][k] = ctx->dqcoeff[i][k];
ctx->eobs_pbuf[i][k] = ctx->eobs[i][k];
}
}
}
static void free_mode_context(PICK_MODE_CONTEXT *ctx) {
int i, k;
vpx_free(ctx->zcoeff_blk);
ctx->zcoeff_blk = 0;
for (i = 0; i < MAX_MB_PLANE; ++i) {
for (k = 0; k < 2; ++k) {
vpx_free(ctx->coeff[i][k]);
ctx->coeff[i][k] = 0;
vpx_free(ctx->qcoeff[i][k]);
ctx->qcoeff[i][k] = 0;
vpx_free(ctx->dqcoeff[i][k]);
ctx->dqcoeff[i][k] = 0;
vpx_free(ctx->eobs[i][k]);
ctx->eobs[i][k] = 0;
}
}
}
static void init_pick_mode_context(VP9_COMP *cpi) {
int i;
MACROBLOCK *x = &cpi->mb;
......@@ -1451,9 +1494,7 @@ static void init_pick_mode_context(VP9_COMP *cpi) {
for (xd->mb_index = 0; xd->mb_index < 4; ++xd->mb_index) {
for (xd->b_index = 0; xd->b_index < 16 / num_4x4_blk; ++xd->b_index) {
PICK_MODE_CONTEXT *ctx = get_block_context(x, i);
ctx->num_4x4_blk = num_4x4_blk;
CHECK_MEM_ERROR(cm, ctx->zcoeff_blk,
vpx_calloc(num_4x4_blk, sizeof(uint8_t)));
alloc_mode_context(cm, num_4x4_blk, ctx);
}
}
}
......@@ -1463,22 +1504,19 @@ static void init_pick_mode_context(VP9_COMP *cpi) {
++xd->mb_index) {
PICK_MODE_CONTEXT *ctx = get_block_context(x, i);
ctx->num_4x4_blk = num_4x4_blk;
CHECK_MEM_ERROR(cm, ctx->zcoeff_blk,
vpx_calloc(num_4x4_blk, sizeof(uint8_t)));
alloc_mode_context(cm, num_4x4_blk, ctx);
}
}
} else if (i < BLOCK_64X64) {
for (xd->sb_index = 0; xd->sb_index < 256 / num_4x4_blk; ++xd->sb_index) {
PICK_MODE_CONTEXT *ctx = get_block_context(x, i);
ctx->num_4x4_blk = num_4x4_blk;
CHECK_MEM_ERROR(cm, ctx->zcoeff_blk,
vpx_calloc(num_4x4_blk, sizeof(uint8_t)));
alloc_mode_context(cm, num_4x4_blk, ctx);
}
} else {
PICK_MODE_CONTEXT *ctx = get_block_context(x, i);
ctx->num_4x4_blk = num_4x4_blk;
CHECK_MEM_ERROR(cm, ctx->zcoeff_blk,
vpx_calloc(num_4x4_blk, sizeof(uint8_t)));
alloc_mode_context(cm, num_4x4_blk, ctx);
}
}
}
......@@ -1496,8 +1534,7 @@ static void free_pick_mode_context(MACROBLOCK *x) {
for (xd->mb_index = 0; xd->mb_index < 4; ++xd->mb_index) {
for (xd->b_index = 0; xd->b_index < 16 / num_4x4_blk; ++xd->b_index) {
PICK_MODE_CONTEXT *ctx = get_block_context(x, i);
vpx_free(ctx->zcoeff_blk);
ctx->zcoeff_blk = 0;
free_mode_context(ctx);
}
}
}
......@@ -1506,35 +1543,21 @@ static void free_pick_mode_context(MACROBLOCK *x) {
for (xd->mb_index = 0; xd->mb_index < 64 / num_4x4_blk;
++xd->mb_index) {
PICK_MODE_CONTEXT *ctx = get_block_context(x, i);
vpx_free(ctx->zcoeff_blk);
ctx->zcoeff_blk = 0;
free_mode_context(ctx);
}
}
} else if (i < BLOCK_64X64) {
for (xd->sb_index = 0; xd->sb_index < 256 / num_4x4_blk; ++xd->sb_index) {
PICK_MODE_CONTEXT *ctx = get_block_context(x, i);
vpx_free(ctx->zcoeff_blk);
ctx->zcoeff_blk = 0;
free_mode_context(ctx);
}
} else {
PICK_MODE_CONTEXT *ctx = get_block_context(x, i);
vpx_free(ctx->zcoeff_blk);
ctx->zcoeff_blk = 0;
free_mode_context(ctx);
}
}
}
static void init_macroblock(VP9_COMP *const cpi) {
MACROBLOCKD *xd = &cpi->mb.e_mbd;
struct macroblockd_plane *const pd = xd->plane;
int i;
for (i = 0; i < MAX_MB_PLANE; ++i) {
pd[i].qcoeff = cpi->qcoeff[i];
pd[i].dqcoeff = cpi->dqcoeff[i];
pd[i].eobs = cpi->eobs[i];
}
}
VP9_PTR vp9_create_compressor(VP9_CONFIG *oxcf) {
int i, j;
volatile union {
......@@ -1573,8 +1596,6 @@ VP9_PTR vp9_create_compressor(VP9_CONFIG *oxcf) {
init_pick_mode_context(cpi);
init_macroblock(cpi);
cm->current_video_frame = 0;
cpi->kf_overspend_bits = 0;
cpi->kf_bitrate_adjustment = 0;
......
......@@ -312,11 +312,6 @@ typedef struct VP9_COMP {
VP9_COMMON common;
VP9_CONFIG oxcf;
struct rdcost_block_args rdcost_stack;
DECLARE_ALIGNED(16, int16_t, qcoeff[MAX_MB_PLANE][64 * 64]);
DECLARE_ALIGNED(16, int16_t, dqcoeff[MAX_MB_PLANE][64 * 64]);
DECLARE_ALIGNED(16, uint16_t, eobs[MAX_MB_PLANE][256]);
struct lookahead_ctx *lookahead;
struct lookahead_entry *source;
#if CONFIG_MULTIPLE_ARF
......
......@@ -1901,6 +1901,7 @@ static void rd_check_segment_txsize(VP9_COMP *cpi, MACROBLOCK *x,
bsi->ref_mv, bsi->second_ref_mv, x->nmvjointcost,
x->mvcost, cpi);
bsi->rdstat[i][mode_idx].mvs[0].as_int = mode_mv[this_mode].as_int;
if (num_4x4_blocks_wide > 1)
bsi->rdstat[i + 1][mode_idx].mvs[0].as_int =
......
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