Commit f13517e6 authored by Daniel Kang's avatar Daniel Kang
Browse files

Refactor to remove some arguments from vp8_rd_pick_inter_mode

Change-Id: I8e72279cc68f34d269705f06cdaf8f3d06eed635
parent 4d5b81a8
...@@ -1146,7 +1146,7 @@ static void encode_frame_internal(VP8_COMP *cpi) { ...@@ -1146,7 +1146,7 @@ static void encode_frame_internal(VP8_COMP *cpi) {
// re-initencode frame context. // re-initencode frame context.
init_encode_frame_mb_context(cpi); init_encode_frame_mb_context(cpi);
cpi->rd_single_diff = cpi->rd_comp_diff = cpi->rd_hybrid_diff = 0; vpx_memset(cpi->rd_comp_pred_diff, 0, sizeof(cpi->rd_comp_pred_diff));
vpx_memset(cpi->single_pred_count, 0, sizeof(cpi->single_pred_count)); vpx_memset(cpi->single_pred_count, 0, sizeof(cpi->single_pred_count));
vpx_memset(cpi->comp_pred_count, 0, sizeof(cpi->comp_pred_count)); vpx_memset(cpi->comp_pred_count, 0, sizeof(cpi->comp_pred_count));
...@@ -1211,8 +1211,7 @@ static int check_dual_ref_flags(VP8_COMP *cpi) { ...@@ -1211,8 +1211,7 @@ static int check_dual_ref_flags(VP8_COMP *cpi) {
void vp8_encode_frame(VP8_COMP *cpi) { void vp8_encode_frame(VP8_COMP *cpi) {
if (cpi->sf.RD) { if (cpi->sf.RD) {
int frame_type, pred_type; int i, frame_type, pred_type;
int single_diff, comp_diff, hybrid_diff;
/* /*
* This code does a single RD pass over the whole frame assuming * This code does a single RD pass over the whole frame assuming
...@@ -1250,20 +1249,15 @@ void vp8_encode_frame(VP8_COMP *cpi) { ...@@ -1250,20 +1249,15 @@ void vp8_encode_frame(VP8_COMP *cpi) {
cpi->common.comp_pred_mode = pred_type; cpi->common.comp_pred_mode = pred_type;
encode_frame_internal(cpi); encode_frame_internal(cpi);
single_diff = cpi->rd_single_diff / cpi->common.MBs; for (i = 0; i < NB_PREDICTION_TYPES; ++i) {
cpi->rd_prediction_type_threshes[frame_type][0] += single_diff; int diff = cpi->rd_comp_pred_diff[i] / cpi->common.MBs;
cpi->rd_prediction_type_threshes[frame_type][0] >>= 1; cpi->rd_prediction_type_threshes[frame_type][i] += diff;
comp_diff = cpi->rd_comp_diff / cpi->common.MBs; cpi->rd_prediction_type_threshes[frame_type][i] >>= 1;
cpi->rd_prediction_type_threshes[frame_type][1] += comp_diff; }
cpi->rd_prediction_type_threshes[frame_type][1] >>= 1;
hybrid_diff = cpi->rd_hybrid_diff / cpi->common.MBs;
cpi->rd_prediction_type_threshes[frame_type][2] += hybrid_diff;
cpi->rd_prediction_type_threshes[frame_type][2] >>= 1;
if (cpi->common.comp_pred_mode == HYBRID_PREDICTION) { if (cpi->common.comp_pred_mode == HYBRID_PREDICTION) {
int single_count_zero = 0; int single_count_zero = 0;
int comp_count_zero = 0; int comp_count_zero = 0;
int i;
for (i = 0; i < COMP_PRED_CONTEXTS; i++) { for (i = 0; i < COMP_PRED_CONTEXTS; i++) {
single_count_zero += cpi->single_pred_count[i]; single_count_zero += cpi->single_pred_count[i];
......
...@@ -445,7 +445,7 @@ typedef struct VP8_COMP { ...@@ -445,7 +445,7 @@ typedef struct VP8_COMP {
int rd_thresh_mult[MAX_MODES]; int rd_thresh_mult[MAX_MODES];
int rd_baseline_thresh[MAX_MODES]; int rd_baseline_thresh[MAX_MODES];
int rd_threshes[MAX_MODES]; int rd_threshes[MAX_MODES];
int64_t rd_single_diff, rd_comp_diff, rd_hybrid_diff; int64_t rd_comp_pred_diff[NB_PREDICTION_TYPES];
int rd_prediction_type_threshes[4][NB_PREDICTION_TYPES]; int rd_prediction_type_threshes[4][NB_PREDICTION_TYPES];
int comp_pred_count[COMP_PRED_CONTEXTS]; int comp_pred_count[COMP_PRED_CONTEXTS];
int single_pred_count[COMP_PRED_CONTEXTS]; int single_pred_count[COMP_PRED_CONTEXTS];
......
...@@ -2658,9 +2658,7 @@ void setup_buffer_inter(VP8_COMP *cpi, MACROBLOCK *x, int idx, int frame_type, ...@@ -2658,9 +2658,7 @@ void setup_buffer_inter(VP8_COMP *cpi, MACROBLOCK *x, int idx, int frame_type,
} }
void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int recon_uvoffset, void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int recon_uvoffset,
int *returnrate, int *returndistortion, int64_t *returnintra, int *returnrate, int *returndistortion, int64_t *returnintra) {
int64_t *best_single_rd_diff, int64_t *best_comp_rd_diff,
int64_t *best_hybrid_rd_diff) {
VP8_COMMON *cm = &cpi->common; VP8_COMMON *cm = &cpi->common;
BLOCK *b = &x->block[0]; BLOCK *b = &x->block[0];
BLOCKD *d = &x->e_mbd.block[0]; BLOCKD *d = &x->e_mbd.block[0];
...@@ -2679,10 +2677,9 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int ...@@ -2679,10 +2677,9 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
int mdcounts[4]; int mdcounts[4];
int rate, distortion; int rate, distortion;
int rate2, distortion2; int rate2, distortion2;
int64_t best_pred_diff[NB_PREDICTION_TYPES];
int64_t best_pred_rd[NB_PREDICTION_TYPES];
int64_t best_rd = INT64_MAX, best_intra_rd = INT64_MAX; int64_t best_rd = INT64_MAX, best_intra_rd = INT64_MAX;
int64_t best_comp_rd = INT64_MAX;
int64_t best_single_rd = INT64_MAX;
int64_t best_hybrid_rd = INT64_MAX;
#if CONFIG_PRED_FILTER #if CONFIG_PRED_FILTER
int64_t best_overall_rd = INT64_MAX; int64_t best_overall_rd = INT64_MAX;
#endif #endif
...@@ -2727,6 +2724,8 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int ...@@ -2727,6 +2724,8 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
for (i = 0; i < MAX_REF_FRAMES; i++) for (i = 0; i < MAX_REF_FRAMES; i++)
frame_mv[NEWMV][i].as_int = INVALID_MV; frame_mv[NEWMV][i].as_int = INVALID_MV;
for (i = 0; i < NB_PREDICTION_TYPES; ++i)
best_pred_rd[i] = INT64_MAX;
for (i = 0; i < BLOCK_MAX_SEGMENTS - 1; i++) { for (i = 0; i < BLOCK_MAX_SEGMENTS - 1; i++) {
int j, k; int j, k;
...@@ -2801,6 +2800,7 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int ...@@ -2801,6 +2800,7 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
for (mode_index = 0; mode_index < MAX_MODES; ++mode_index) { for (mode_index = 0; mode_index < MAX_MODES; ++mode_index) {
#endif #endif
int64_t this_rd = INT64_MAX; int64_t this_rd = INT64_MAX;
int is_comp_pred;
int disable_skip = 0; int disable_skip = 0;
int other_cost = 0; int other_cost = 0;
int compmode_cost = 0; int compmode_cost = 0;
...@@ -2817,6 +2817,7 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int ...@@ -2817,6 +2817,7 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
mbmi->uv_mode = DC_PRED; mbmi->uv_mode = DC_PRED;
mbmi->ref_frame = vp8_mode_order[mode_index].ref_frame; mbmi->ref_frame = vp8_mode_order[mode_index].ref_frame;
mbmi->second_ref_frame = vp8_mode_order[mode_index].second_ref_frame; mbmi->second_ref_frame = vp8_mode_order[mode_index].second_ref_frame;
is_comp_pred = x->e_mbd.mode_info_context->mbmi.second_ref_frame != 0;
#if CONFIG_NEWBESTREFMV #if CONFIG_NEWBESTREFMV
mbmi->ref_mv = ref_mv[mbmi->ref_frame]; mbmi->ref_mv = ref_mv[mbmi->ref_frame];
mbmi->second_ref_mv = ref_mv[mbmi->second_ref_frame]; mbmi->second_ref_mv = ref_mv[mbmi->second_ref_frame];
...@@ -3001,9 +3002,8 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int ...@@ -3001,9 +3002,8 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
break; break;
case I8X8_PRED: { case I8X8_PRED: {
int64_t tmp_rd; int64_t tmp_rd;
tmp_rd = rd_pick_intra8x8mby_modes(cpi, tmp_rd = rd_pick_intra8x8mby_modes(cpi, x, &rate, &rate_y,
x, &rate, &rate_y, &distortion, &distortion, best_yrd);
best_yrd);
rate2 += rate; rate2 += rate;
distortion2 += distortion; distortion2 += distortion;
...@@ -3037,7 +3037,6 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int ...@@ -3037,7 +3037,6 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
// special case it. // special case it.
else if (this_mode == SPLITMV) { else if (this_mode == SPLITMV) {
int64_t tmp_rd, this_rd_thresh; int64_t tmp_rd, this_rd_thresh;
int is_comp_pred = mbmi->second_ref_frame != 0;
int_mv *second_ref = is_comp_pred ? &second_best_ref_mv : NULL; int_mv *second_ref = is_comp_pred ? &second_best_ref_mv : NULL;
this_rd_thresh = this_rd_thresh =
...@@ -3081,7 +3080,6 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int ...@@ -3081,7 +3080,6 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
mbmi->mode = this_mode; mbmi->mode = this_mode;
} }
else { else {
const int is_comp_pred = x->e_mbd.mode_info_context->mbmi.second_ref_frame != 0;
const int num_refs = is_comp_pred ? 2 : 1; const int num_refs = is_comp_pred ? 2 : 1;
int flag; int flag;
int refs[2] = {x->e_mbd.mode_info_context->mbmi.ref_frame, int refs[2] = {x->e_mbd.mode_info_context->mbmi.ref_frame,
...@@ -3355,11 +3353,9 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int ...@@ -3355,11 +3353,9 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
*returnintra = distortion2; *returnintra = distortion2;
} }
if (!disable_skip && mbmi->ref_frame == INTRA_FRAME) { if (!disable_skip && mbmi->ref_frame == INTRA_FRAME)
best_comp_rd = MIN(best_comp_rd, this_rd); for (i = 0; i < NB_PREDICTION_TYPES; ++i)
best_single_rd = MIN(best_single_rd, this_rd); best_pred_rd[i] = MIN(best_pred_rd[i], this_rd);
best_hybrid_rd = MIN(best_hybrid_rd, this_rd);
}
#if CONFIG_PRED_FILTER #if CONFIG_PRED_FILTER
// Keep track of the best mode irrespective of prediction filter state // Keep track of the best mode irrespective of prediction filter state
...@@ -3449,14 +3445,14 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int ...@@ -3449,14 +3445,14 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
hybrid_rd = RDCOST(x->rdmult, x->rddiv, hybrid_rate, distortion2); hybrid_rd = RDCOST(x->rdmult, x->rddiv, hybrid_rate, distortion2);
if (mbmi->second_ref_frame == INTRA_FRAME && if (mbmi->second_ref_frame == INTRA_FRAME &&
single_rd < best_single_rd) { single_rd < best_pred_rd[SINGLE_PREDICTION_ONLY]) {
best_single_rd = single_rd; best_pred_rd[SINGLE_PREDICTION_ONLY] = single_rd;
} else if (mbmi->second_ref_frame != INTRA_FRAME && } else if (mbmi->second_ref_frame != INTRA_FRAME &&
single_rd < best_comp_rd) { single_rd < best_pred_rd[COMP_PREDICTION_ONLY]) {
best_comp_rd = single_rd; best_pred_rd[COMP_PREDICTION_ONLY] = single_rd;
} }
if (hybrid_rd < best_hybrid_rd) if (hybrid_rd < best_pred_rd[HYBRID_PREDICTION])
best_hybrid_rd = hybrid_rd; best_pred_rd[HYBRID_PREDICTION] = hybrid_rd;
} }
#if CONFIG_PRED_FILTER #if CONFIG_PRED_FILTER
} }
...@@ -3514,14 +3510,8 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int ...@@ -3514,14 +3510,8 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
(cpi->common.mb_no_coeff_skip) ? 1 : 0; (cpi->common.mb_no_coeff_skip) ? 1 : 0;
mbmi->partitioning = 0; mbmi->partitioning = 0;
*best_single_rd_diff = *best_comp_rd_diff = *best_hybrid_rd_diff = 0; vpx_memset(best_pred_diff, 0, sizeof(best_pred_diff));
goto end;
store_coding_context(x, xd->mb_index, best_mode_index, &best_partition,
&frame_best_ref_mv[mbmi->ref_frame],
&frame_best_ref_mv[mbmi->second_ref_frame]
);
return;
} }
// macroblock modes // macroblock modes
...@@ -3553,18 +3543,17 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int ...@@ -3553,18 +3543,17 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
mbmi->mv[1].as_int = x->partition_info->bmi[15].second_mv.as_int; mbmi->mv[1].as_int = x->partition_info->bmi[15].second_mv.as_int;
} }
if (best_single_rd == INT64_MAX) for (i = 0; i < NB_PREDICTION_TYPES; ++i) {
*best_single_rd_diff = INT_MIN; if (best_pred_rd[i] == INT64_MAX)
else best_pred_diff[i] = INT_MIN;
*best_single_rd_diff = best_rd - best_single_rd; else
if (best_comp_rd == INT64_MAX) best_pred_diff[i] = best_rd - best_pred_rd[i];
*best_comp_rd_diff = INT_MIN; }
else
*best_comp_rd_diff = best_rd - best_comp_rd; end:
if (best_hybrid_rd == INT64_MAX) // TODO Save these to add in only if MB coding mode is selected?
*best_hybrid_rd_diff = INT_MIN; for (i = 0; i < NB_PREDICTION_TYPES; ++i)
else cpi->rd_comp_pred_diff[i] += best_pred_diff[i];
*best_hybrid_rd_diff = best_rd - best_hybrid_rd;
store_coding_context(x, xd->mb_index, best_mode_index, &best_partition, store_coding_context(x, xd->mb_index, best_mode_index, &best_partition,
&frame_best_ref_mv[mbmi->ref_frame], &frame_best_ref_mv[mbmi->ref_frame],
...@@ -3683,8 +3672,7 @@ int vp8cx_pick_mode_inter_macroblock(VP8_COMP *cpi, MACROBLOCK *x, ...@@ -3683,8 +3672,7 @@ int vp8cx_pick_mode_inter_macroblock(VP8_COMP *cpi, MACROBLOCK *x,
VP8_COMMON *cm = &cpi->common; VP8_COMMON *cm = &cpi->common;
MACROBLOCKD *const xd = &x->e_mbd; MACROBLOCKD *const xd = &x->e_mbd;
MB_MODE_INFO * mbmi = &x->e_mbd.mode_info_context->mbmi; MB_MODE_INFO * mbmi = &x->e_mbd.mode_info_context->mbmi;
int rate; int rate, distortion;
int distortion;
int64_t intra_error = 0; int64_t intra_error = 0;
unsigned char *segment_id = &mbmi->segment_id; unsigned char *segment_id = &mbmi->segment_id;
...@@ -3697,16 +3685,10 @@ int vp8cx_pick_mode_inter_macroblock(VP8_COMP *cpi, MACROBLOCK *x, ...@@ -3697,16 +3685,10 @@ int vp8cx_pick_mode_inter_macroblock(VP8_COMP *cpi, MACROBLOCK *x,
// For now this codebase is limited to a single rd encode path // For now this codebase is limited to a single rd encode path
{ {
int zbin_mode_boost_enabled = cpi->zbin_mode_boost_enabled; int zbin_mode_boost_enabled = cpi->zbin_mode_boost_enabled;
int64_t single, compound, hybrid;
vp8_rd_pick_inter_mode(cpi, x, recon_yoffset, recon_uvoffset, &rate, vp8_rd_pick_inter_mode(cpi, x, recon_yoffset, recon_uvoffset, &rate,
&distortion, &intra_error, &single, &compound, &distortion, &intra_error);
&hybrid);
// TODO Save these to add in only if MB coding mode is selected?
cpi->rd_single_diff += single;
cpi->rd_comp_diff += compound;
cpi->rd_hybrid_diff += hybrid;
if (mbmi->ref_frame) { if (mbmi->ref_frame) {
unsigned char pred_context; unsigned char pred_context;
......
...@@ -17,8 +17,7 @@ ...@@ -17,8 +17,7 @@
extern void vp8_initialize_rd_consts(VP8_COMP *cpi, int Qvalue); extern void vp8_initialize_rd_consts(VP8_COMP *cpi, int Qvalue);
extern void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int recon_uvoffset, extern void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int recon_uvoffset,
int *returnrate, int *returndistortion, int64_t *returnintra, int *returnrate, int *returndistortion, int64_t *returnintra);
int64_t *best_single_rd_diff, int64_t *best_comp_rd_diff, int64_t *best_hybrid_rd_diff);
extern int vp8_rd_pick_intra_mode(VP8_COMP *cpi, MACROBLOCK *x); extern int vp8_rd_pick_intra_mode(VP8_COMP *cpi, MACROBLOCK *x);
extern void vp8_mv_pred extern void vp8_mv_pred
......
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