From f13517e6aac31c0d0ed16ba366a69ca660c51d3c Mon Sep 17 00:00:00 2001 From: Daniel Kang Date: Thu, 9 Aug 2012 18:25:29 -0700 Subject: [PATCH] Refactor to remove some arguments from vp8_rd_pick_inter_mode Change-Id: I8e72279cc68f34d269705f06cdaf8f3d06eed635 --- vp8/encoder/encodeframe.c | 20 ++++------- vp8/encoder/onyx_int.h | 2 +- vp8/encoder/rdopt.c | 84 +++++++++++++++++++---------------------------- vp8/encoder/rdopt.h | 3 +- 4 files changed, 42 insertions(+), 67 deletions(-) diff --git a/vp8/encoder/encodeframe.c b/vp8/encoder/encodeframe.c index 5352de7..507659d 100644 --- a/vp8/encoder/encodeframe.c +++ b/vp8/encoder/encodeframe.c @@ -1146,7 +1146,7 @@ static void encode_frame_internal(VP8_COMP *cpi) { // re-initencode frame context. 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->comp_pred_count, 0, sizeof(cpi->comp_pred_count)); @@ -1211,8 +1211,7 @@ static int check_dual_ref_flags(VP8_COMP *cpi) { void vp8_encode_frame(VP8_COMP *cpi) { if (cpi->sf.RD) { - int frame_type, pred_type; - int single_diff, comp_diff, hybrid_diff; + int i, frame_type, pred_type; /* * This code does a single RD pass over the whole frame assuming @@ -1250,20 +1249,15 @@ void vp8_encode_frame(VP8_COMP *cpi) { cpi->common.comp_pred_mode = pred_type; encode_frame_internal(cpi); - single_diff = cpi->rd_single_diff / cpi->common.MBs; - cpi->rd_prediction_type_threshes[frame_type][0] += single_diff; - cpi->rd_prediction_type_threshes[frame_type][0] >>= 1; - comp_diff = cpi->rd_comp_diff / cpi->common.MBs; - 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; + for (i = 0; i < NB_PREDICTION_TYPES; ++i) { + int diff = cpi->rd_comp_pred_diff[i] / cpi->common.MBs; + cpi->rd_prediction_type_threshes[frame_type][i] += diff; + cpi->rd_prediction_type_threshes[frame_type][i] >>= 1; + } if (cpi->common.comp_pred_mode == HYBRID_PREDICTION) { int single_count_zero = 0; int comp_count_zero = 0; - int i; for (i = 0; i < COMP_PRED_CONTEXTS; i++) { single_count_zero += cpi->single_pred_count[i]; diff --git a/vp8/encoder/onyx_int.h b/vp8/encoder/onyx_int.h index 6b6167b..d8b7d13 100644 --- a/vp8/encoder/onyx_int.h +++ b/vp8/encoder/onyx_int.h @@ -445,7 +445,7 @@ typedef struct VP8_COMP { int rd_thresh_mult[MAX_MODES]; int rd_baseline_thresh[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 comp_pred_count[COMP_PRED_CONTEXTS]; int single_pred_count[COMP_PRED_CONTEXTS]; diff --git a/vp8/encoder/rdopt.c b/vp8/encoder/rdopt.c index 0c16653..f62d786 100644 --- a/vp8/encoder/rdopt.c +++ b/vp8/encoder/rdopt.c @@ -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, - 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) { + int *returnrate, int *returndistortion, int64_t *returnintra) { VP8_COMMON *cm = &cpi->common; BLOCK *b = &x->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 int mdcounts[4]; int rate, distortion; 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_comp_rd = INT64_MAX; - int64_t best_single_rd = INT64_MAX; - int64_t best_hybrid_rd = INT64_MAX; #if CONFIG_PRED_FILTER int64_t best_overall_rd = INT64_MAX; #endif @@ -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++) 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++) { int j, k; @@ -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) { #endif int64_t this_rd = INT64_MAX; + int is_comp_pred; int disable_skip = 0; int other_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 mbmi->uv_mode = DC_PRED; mbmi->ref_frame = vp8_mode_order[mode_index].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 mbmi->ref_mv = ref_mv[mbmi->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 break; case I8X8_PRED: { int64_t tmp_rd; - tmp_rd = rd_pick_intra8x8mby_modes(cpi, - x, &rate, &rate_y, &distortion, - best_yrd); + tmp_rd = rd_pick_intra8x8mby_modes(cpi, x, &rate, &rate_y, + &distortion, best_yrd); rate2 += rate; distortion2 += distortion; @@ -3037,7 +3037,6 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int // special case it. else if (this_mode == SPLITMV) { 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; this_rd_thresh = @@ -3081,7 +3080,6 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int mbmi->mode = this_mode; } 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; int flag; 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 *returnintra = distortion2; } - if (!disable_skip && mbmi->ref_frame == INTRA_FRAME) { - best_comp_rd = MIN(best_comp_rd, this_rd); - best_single_rd = MIN(best_single_rd, this_rd); - best_hybrid_rd = MIN(best_hybrid_rd, this_rd); - } + if (!disable_skip && mbmi->ref_frame == INTRA_FRAME) + for (i = 0; i < NB_PREDICTION_TYPES; ++i) + best_pred_rd[i] = MIN(best_pred_rd[i], this_rd); #if CONFIG_PRED_FILTER // 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 hybrid_rd = RDCOST(x->rdmult, x->rddiv, hybrid_rate, distortion2); if (mbmi->second_ref_frame == INTRA_FRAME && - single_rd < best_single_rd) { - best_single_rd = single_rd; + single_rd < best_pred_rd[SINGLE_PREDICTION_ONLY]) { + best_pred_rd[SINGLE_PREDICTION_ONLY] = single_rd; } else if (mbmi->second_ref_frame != INTRA_FRAME && - single_rd < best_comp_rd) { - best_comp_rd = single_rd; + single_rd < best_pred_rd[COMP_PREDICTION_ONLY]) { + best_pred_rd[COMP_PREDICTION_ONLY] = single_rd; } - if (hybrid_rd < best_hybrid_rd) - best_hybrid_rd = hybrid_rd; + if (hybrid_rd < best_pred_rd[HYBRID_PREDICTION]) + best_pred_rd[HYBRID_PREDICTION] = hybrid_rd; } #if CONFIG_PRED_FILTER } @@ -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; mbmi->partitioning = 0; - *best_single_rd_diff = *best_comp_rd_diff = *best_hybrid_rd_diff = 0; - - 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; + vpx_memset(best_pred_diff, 0, sizeof(best_pred_diff)); + goto end; } // macroblock modes @@ -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; } - if (best_single_rd == INT64_MAX) - *best_single_rd_diff = INT_MIN; - else - *best_single_rd_diff = best_rd - best_single_rd; - if (best_comp_rd == INT64_MAX) - *best_comp_rd_diff = INT_MIN; - else - *best_comp_rd_diff = best_rd - best_comp_rd; - if (best_hybrid_rd == INT64_MAX) - *best_hybrid_rd_diff = INT_MIN; - else - *best_hybrid_rd_diff = best_rd - best_hybrid_rd; + for (i = 0; i < NB_PREDICTION_TYPES; ++i) { + if (best_pred_rd[i] == INT64_MAX) + best_pred_diff[i] = INT_MIN; + else + best_pred_diff[i] = best_rd - best_pred_rd[i]; + } + +end: + // TODO Save these to add in only if MB coding mode is selected? + for (i = 0; i < NB_PREDICTION_TYPES; ++i) + cpi->rd_comp_pred_diff[i] += best_pred_diff[i]; store_coding_context(x, xd->mb_index, best_mode_index, &best_partition, &frame_best_ref_mv[mbmi->ref_frame], @@ -3683,8 +3672,7 @@ int vp8cx_pick_mode_inter_macroblock(VP8_COMP *cpi, MACROBLOCK *x, VP8_COMMON *cm = &cpi->common; MACROBLOCKD *const xd = &x->e_mbd; MB_MODE_INFO * mbmi = &x->e_mbd.mode_info_context->mbmi; - int rate; - int distortion; + int rate, distortion; int64_t intra_error = 0; unsigned char *segment_id = &mbmi->segment_id; @@ -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 { 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, - &distortion, &intra_error, &single, &compound, - &hybrid); + &distortion, &intra_error); - // 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) { unsigned char pred_context; diff --git a/vp8/encoder/rdopt.h b/vp8/encoder/rdopt.h index c26708c..2b5928d 100644 --- a/vp8/encoder/rdopt.h +++ b/vp8/encoder/rdopt.h @@ -17,8 +17,7 @@ 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, - 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); + int *returnrate, int *returndistortion, int64_t *returnintra); extern int vp8_rd_pick_intra_mode(VP8_COMP *cpi, MACROBLOCK *x); extern void vp8_mv_pred -- 2.7.4