Allocate dual buffer sets for encoding
Allocate memory space of dual buffer sets that store the coeff, qcoeff, dqcoeff, and eobs. Connect the pointers of macroblock_plane and macroblockd_plane to the actual buffer in use accordingly. Change-Id: I2f0b5f482ca879fae39095013eaf8901db20a5a4
This commit is contained in:
parent
6f9549381d
commit
3b3aea6834
@ -27,6 +27,17 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
MODE_INFO mic;
|
MODE_INFO mic;
|
||||||
uint8_t *zcoeff_blk;
|
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 num_4x4_blk;
|
||||||
int skip;
|
int skip;
|
||||||
int_mv best_ref_mv;
|
int_mv best_ref_mv;
|
||||||
@ -57,7 +68,7 @@ typedef struct {
|
|||||||
|
|
||||||
struct macroblock_plane {
|
struct macroblock_plane {
|
||||||
DECLARE_ALIGNED(16, int16_t, src_diff[64 * 64]);
|
DECLARE_ALIGNED(16, int16_t, src_diff[64 * 64]);
|
||||||
DECLARE_ALIGNED(16, int16_t, coeff[64 * 64]);
|
int16_t *coeff;
|
||||||
struct buf_2d src;
|
struct buf_2d src;
|
||||||
|
|
||||||
// Quantizer setings
|
// Quantizer setings
|
||||||
|
@ -367,6 +367,8 @@ static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx,
|
|||||||
VP9_COMMON *const cm = &cpi->common;
|
VP9_COMMON *const cm = &cpi->common;
|
||||||
MACROBLOCK *const x = &cpi->mb;
|
MACROBLOCK *const x = &cpi->mb;
|
||||||
MACROBLOCKD *const xd = &x->e_mbd;
|
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;
|
MODE_INFO *mi = &ctx->mic;
|
||||||
MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi;
|
MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi;
|
||||||
MODE_INFO *mi_addr = xd->mi_8x8[0];
|
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;
|
*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
|
// Restore the coding context of the MB to that that was in place
|
||||||
// when the mode was picked for it
|
// when the mode was picked for it
|
||||||
for (y = 0; y < mi_height; y++)
|
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;
|
VP9_COMMON *const cm = &cpi->common;
|
||||||
MACROBLOCK *const x = &cpi->mb;
|
MACROBLOCK *const x = &cpi->mb;
|
||||||
MACROBLOCKD *const xd = &x->e_mbd;
|
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;
|
int orig_rdmult = x->rdmult;
|
||||||
double rdmult_ratio;
|
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);
|
set_offsets(cpi, tile, mi_row, mi_col, bsize);
|
||||||
xd->mi_8x8[0]->mbmi.sb_type = 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
|
// Set to zero to make sure we do not use the previous encoded frame stats
|
||||||
xd->mi_8x8[0]->mbmi.skip_coeff = 0;
|
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;
|
VP9_COMMON *const cm = &cpi->common;
|
||||||
MACROBLOCKD *const xd = &x->e_mbd;
|
MACROBLOCKD *const xd = &x->e_mbd;
|
||||||
TileInfo tile;
|
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;
|
int recon_yoffset, recon_uvoffset;
|
||||||
const int lst_yv12_idx = cm->ref_frame_map[cpi->lst_fb_idx];
|
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);
|
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
|
// Initialise the MV cost table to the defaults
|
||||||
// if( cm->current_video_frame == 0)
|
// if( cm->current_video_frame == 0)
|
||||||
// if ( 0 )
|
// if ( 0 )
|
||||||
|
@ -1436,6 +1436,49 @@ static void cal_nmvsadcosts_hp(int *mvsadcost[2]) {
|
|||||||
} while (++i <= MV_MAX);
|
} 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) {
|
static void init_pick_mode_context(VP9_COMP *cpi) {
|
||||||
int i;
|
int i;
|
||||||
MACROBLOCK *x = &cpi->mb;
|
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->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) {
|
for (xd->b_index = 0; xd->b_index < 16 / num_4x4_blk; ++xd->b_index) {
|
||||||
PICK_MODE_CONTEXT *ctx = get_block_context(x, i);
|
PICK_MODE_CONTEXT *ctx = get_block_context(x, i);
|
||||||
ctx->num_4x4_blk = num_4x4_blk;
|
alloc_mode_context(cm, num_4x4_blk, ctx);
|
||||||
CHECK_MEM_ERROR(cm, ctx->zcoeff_blk,
|
|
||||||
vpx_calloc(num_4x4_blk, sizeof(uint8_t)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1463,22 +1504,19 @@ static void init_pick_mode_context(VP9_COMP *cpi) {
|
|||||||
++xd->mb_index) {
|
++xd->mb_index) {
|
||||||
PICK_MODE_CONTEXT *ctx = get_block_context(x, i);
|
PICK_MODE_CONTEXT *ctx = get_block_context(x, i);
|
||||||
ctx->num_4x4_blk = num_4x4_blk;
|
ctx->num_4x4_blk = num_4x4_blk;
|
||||||
CHECK_MEM_ERROR(cm, ctx->zcoeff_blk,
|
alloc_mode_context(cm, num_4x4_blk, ctx);
|
||||||
vpx_calloc(num_4x4_blk, sizeof(uint8_t)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (i < BLOCK_64X64) {
|
} else if (i < BLOCK_64X64) {
|
||||||
for (xd->sb_index = 0; xd->sb_index < 256 / num_4x4_blk; ++xd->sb_index) {
|
for (xd->sb_index = 0; xd->sb_index < 256 / num_4x4_blk; ++xd->sb_index) {
|
||||||
PICK_MODE_CONTEXT *ctx = get_block_context(x, i);
|
PICK_MODE_CONTEXT *ctx = get_block_context(x, i);
|
||||||
ctx->num_4x4_blk = num_4x4_blk;
|
ctx->num_4x4_blk = num_4x4_blk;
|
||||||
CHECK_MEM_ERROR(cm, ctx->zcoeff_blk,
|
alloc_mode_context(cm, num_4x4_blk, ctx);
|
||||||
vpx_calloc(num_4x4_blk, sizeof(uint8_t)));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
PICK_MODE_CONTEXT *ctx = get_block_context(x, i);
|
PICK_MODE_CONTEXT *ctx = get_block_context(x, i);
|
||||||
ctx->num_4x4_blk = num_4x4_blk;
|
ctx->num_4x4_blk = num_4x4_blk;
|
||||||
CHECK_MEM_ERROR(cm, ctx->zcoeff_blk,
|
alloc_mode_context(cm, num_4x4_blk, ctx);
|
||||||
vpx_calloc(num_4x4_blk, sizeof(uint8_t)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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->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) {
|
for (xd->b_index = 0; xd->b_index < 16 / num_4x4_blk; ++xd->b_index) {
|
||||||
PICK_MODE_CONTEXT *ctx = get_block_context(x, i);
|
PICK_MODE_CONTEXT *ctx = get_block_context(x, i);
|
||||||
vpx_free(ctx->zcoeff_blk);
|
free_mode_context(ctx);
|
||||||
ctx->zcoeff_blk = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1506,35 +1543,21 @@ static void free_pick_mode_context(MACROBLOCK *x) {
|
|||||||
for (xd->mb_index = 0; xd->mb_index < 64 / num_4x4_blk;
|
for (xd->mb_index = 0; xd->mb_index < 64 / num_4x4_blk;
|
||||||
++xd->mb_index) {
|
++xd->mb_index) {
|
||||||
PICK_MODE_CONTEXT *ctx = get_block_context(x, i);
|
PICK_MODE_CONTEXT *ctx = get_block_context(x, i);
|
||||||
vpx_free(ctx->zcoeff_blk);
|
free_mode_context(ctx);
|
||||||
ctx->zcoeff_blk = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (i < BLOCK_64X64) {
|
} else if (i < BLOCK_64X64) {
|
||||||
for (xd->sb_index = 0; xd->sb_index < 256 / num_4x4_blk; ++xd->sb_index) {
|
for (xd->sb_index = 0; xd->sb_index < 256 / num_4x4_blk; ++xd->sb_index) {
|
||||||
PICK_MODE_CONTEXT *ctx = get_block_context(x, i);
|
PICK_MODE_CONTEXT *ctx = get_block_context(x, i);
|
||||||
vpx_free(ctx->zcoeff_blk);
|
free_mode_context(ctx);
|
||||||
ctx->zcoeff_blk = 0;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
PICK_MODE_CONTEXT *ctx = get_block_context(x, i);
|
PICK_MODE_CONTEXT *ctx = get_block_context(x, i);
|
||||||
vpx_free(ctx->zcoeff_blk);
|
free_mode_context(ctx);
|
||||||
ctx->zcoeff_blk = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
VP9_PTR vp9_create_compressor(VP9_CONFIG *oxcf) {
|
||||||
int i, j;
|
int i, j;
|
||||||
volatile union {
|
volatile union {
|
||||||
@ -1573,8 +1596,6 @@ VP9_PTR vp9_create_compressor(VP9_CONFIG *oxcf) {
|
|||||||
|
|
||||||
init_pick_mode_context(cpi);
|
init_pick_mode_context(cpi);
|
||||||
|
|
||||||
init_macroblock(cpi);
|
|
||||||
|
|
||||||
cm->current_video_frame = 0;
|
cm->current_video_frame = 0;
|
||||||
cpi->kf_overspend_bits = 0;
|
cpi->kf_overspend_bits = 0;
|
||||||
cpi->kf_bitrate_adjustment = 0;
|
cpi->kf_bitrate_adjustment = 0;
|
||||||
|
@ -312,11 +312,6 @@ typedef struct VP9_COMP {
|
|||||||
VP9_COMMON common;
|
VP9_COMMON common;
|
||||||
VP9_CONFIG oxcf;
|
VP9_CONFIG oxcf;
|
||||||
struct rdcost_block_args rdcost_stack;
|
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_ctx *lookahead;
|
||||||
struct lookahead_entry *source;
|
struct lookahead_entry *source;
|
||||||
#if CONFIG_MULTIPLE_ARF
|
#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,
|
bsi->ref_mv, bsi->second_ref_mv, x->nmvjointcost,
|
||||||
x->mvcost, cpi);
|
x->mvcost, cpi);
|
||||||
|
|
||||||
|
|
||||||
bsi->rdstat[i][mode_idx].mvs[0].as_int = mode_mv[this_mode].as_int;
|
bsi->rdstat[i][mode_idx].mvs[0].as_int = mode_mv[this_mode].as_int;
|
||||||
if (num_4x4_blocks_wide > 1)
|
if (num_4x4_blocks_wide > 1)
|
||||||
bsi->rdstat[i + 1][mode_idx].mvs[0].as_int =
|
bsi->rdstat[i + 1][mode_idx].mvs[0].as_int =
|
||||||
|
Loading…
Reference in New Issue
Block a user