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

Merge "Enable dynamic ref motion vector mode for compound inter block" into nextgenv2

parents 1c8fa6a5 28e0393f
......@@ -1056,11 +1056,12 @@ static void read_inter_block_mode_info(VP10Decoder *const pbi,
#endif // CONFIG_REF_MV && CONFIG_EXT_INTER
r, mode_ctx);
#if CONFIG_REF_MV
if (mbmi->mode == NEARMV && !is_compound) {
if (xd->ref_mv_count[mbmi->ref_frame[0]] > 2) {
if (mbmi->mode == NEARMV) {
uint8_t ref_frame_type = vp10_ref_frame_type(mbmi->ref_frame);
if (xd->ref_mv_count[ref_frame_type] > 2) {
if (vpx_read_bit(r)) {
mbmi->ref_mv_idx = 1;
if (xd->ref_mv_count[mbmi->ref_frame[0]] > 3)
if (xd->ref_mv_count[ref_frame_type] > 3)
if (vpx_read_bit(r))
mbmi->ref_mv_idx = 2;
}
......@@ -1138,10 +1139,11 @@ static void read_inter_block_mode_info(VP10Decoder *const pbi,
#else
if (xd->ref_mv_count[ref_frame_type] > 1) {
int i;
int ref_mv_idx = 1 + mbmi->ref_mv_idx;
nearestmv[0] = xd->ref_mv_stack[ref_frame_type][0].this_mv;
nearestmv[1] = xd->ref_mv_stack[ref_frame_type][0].comp_mv;
nearmv[0] = xd->ref_mv_stack[ref_frame_type][1].this_mv;
nearmv[1] = xd->ref_mv_stack[ref_frame_type][1].comp_mv;
nearmv[0] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].this_mv;
nearmv[1] = xd->ref_mv_stack[ref_frame_type][ref_mv_idx].comp_mv;
for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i) {
lower_mv_precision(&nearestmv[i].as_mv, allow_hp);
......
......@@ -994,10 +994,11 @@ static void pack_inter_mode_mvs(VP10_COMP *cpi, const MODE_INFO *mi,
mode_ctx);
#if CONFIG_REF_MV
if (mode == NEARMV && mbmi->ref_frame[1] == NONE) {
if (mbmi_ext->ref_mv_count[mbmi->ref_frame[0]] > 2) {
if (mode == NEARMV) {
uint8_t ref_frame_type = vp10_ref_frame_type(mbmi->ref_frame);
if (mbmi_ext->ref_mv_count[ref_frame_type] > 2) {
vpx_write_bit(w, mbmi->ref_mv_idx != 0);
if (mbmi_ext->ref_mv_count[mbmi->ref_frame[0]] > 3 &&
if (mbmi_ext->ref_mv_count[ref_frame_type] > 3 &&
mbmi->ref_mv_idx > 0)
vpx_write_bit(w, mbmi->ref_mv_idx != 1);
}
......
......@@ -5214,8 +5214,9 @@ static int64_t handle_inter_mode(VP10_COMP *cpi, MACROBLOCK *x,
if (this_mode == NEARMV && is_comp_pred) {
uint8_t ref_frame_type = vp10_ref_frame_type(mbmi->ref_frame);
if (mbmi_ext->ref_mv_count[ref_frame_type] > 1) {
cur_mv[0] = mbmi_ext->ref_mv_stack[ref_frame_type][1].this_mv;
cur_mv[1] = mbmi_ext->ref_mv_stack[ref_frame_type][1].comp_mv;
int ref_mv_idx = mbmi->ref_mv_idx + 1;
cur_mv[0] = mbmi_ext->ref_mv_stack[ref_frame_type][ref_mv_idx].this_mv;
cur_mv[1] = mbmi_ext->ref_mv_stack[ref_frame_type][ref_mv_idx].comp_mv;
for (i = 0; i < 2; ++i) {
lower_mv_precision(&cur_mv[i].as_mv, cm->allow_high_precision_mv);
......@@ -5792,7 +5793,7 @@ void vp10_rd_pick_inter_mode_sb(VP10_COMP *cpi,
int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS];
MB_MODE_INFO best_mbmode;
#if CONFIG_REF_MV
uint8_t best_ref_mv_idx[MAX_REF_FRAMES] = { 0 };
uint8_t best_ref_mv_idx[MODE_CTX_REF_FRAMES] = { 0 };
#endif
int best_mode_skippable = 0;
int midx, best_mode_index = -1;
......@@ -6023,6 +6024,9 @@ void vp10_rd_pick_inter_mode_sb(VP10_COMP *cpi,
int this_skip2 = 0;
int64_t total_sse = INT64_MAX;
int early_term = 0;
#if CONFIG_REF_MV
uint8_t ref_frame_type;
#endif
this_mode = vp10_mode_order[mode_index].mode;
ref_frame = vp10_mode_order[mode_index].ref_frame[0];
......@@ -6345,6 +6349,10 @@ void vp10_rd_pick_inter_mode_sb(VP10_COMP *cpi,
rate2 += intra_cost_penalty;
distortion2 = distortion_y + distortion_uv;
} else {
#if CONFIG_REF_MV
mbmi->ref_mv_idx = 0;
ref_frame_type = vp10_ref_frame_type(mbmi->ref_frame);
#endif
this_rd = handle_inter_mode(cpi, x, bsize,
&rate2, &distortion2, &skippable,
&rate_y, &rate_uv,
......@@ -6360,19 +6368,18 @@ void vp10_rd_pick_inter_mode_sb(VP10_COMP *cpi,
&mask_filter, filter_cache);
#if CONFIG_REF_MV
mbmi->ref_mv_idx = 0;
// TODO(jingning): This needs some refactoring to improve code quality
// and reduce redundant steps.
if (!comp_pred && mbmi->mode == NEARMV &&
mbmi_ext->ref_mv_count[ref_frame] > 2) {
if (mbmi->mode == NEARMV &&
mbmi_ext->ref_mv_count[ref_frame_type] > 2) {
int_mv backup_mv = frame_mv[NEARMV][ref_frame];
int_mv cur_mv = mbmi_ext->ref_mv_stack[ref_frame][2].this_mv;
MB_MODE_INFO backup_mbmi = *mbmi;
int64_t tmp_ref_rd = this_rd;
int ref_idx;
int ref_set = VPXMIN(2, mbmi_ext->ref_mv_count[ref_frame] - 2);
int ref_set = VPXMIN(2, mbmi_ext->ref_mv_count[ref_frame_type] - 2);
rate2 += vp10_cost_bit(128, 0);
if (this_rd < INT64_MAX) {
......@@ -6413,6 +6420,8 @@ void vp10_rd_pick_inter_mode_sb(VP10_COMP *cpi,
#endif
mbmi->ref_mv_idx = 1 + ref_idx;
frame_mv[NEARMV][ref_frame] = cur_mv;
tmp_alt_rd = handle_inter_mode(cpi, x, bsize,
&tmp_rate, &tmp_dist, &tmp_skip,
......@@ -6432,7 +6441,7 @@ void vp10_rd_pick_inter_mode_sb(VP10_COMP *cpi,
}
tmp_rate += vp10_cost_bit(128, 1);
if (mbmi_ext->ref_mv_count[ref_frame] > 3)
if (mbmi_ext->ref_mv_count[ref_frame_type] > 3)
tmp_rate += vp10_cost_bit(128, ref_idx);
if (tmp_alt_rd < INT64_MAX) {
......@@ -6457,9 +6466,8 @@ void vp10_rd_pick_inter_mode_sb(VP10_COMP *cpi,
rate_uv = tmp_rate_uv;
total_sse = tmp_sse;
this_rd = tmp_alt_rd;
mbmi->ref_mv_idx = 1 + ref_idx;
// Indicator of the effective nearmv reference motion vector.
best_ref_mv_idx[ref_frame] = 1 + ref_idx;
best_ref_mv_idx[ref_frame_type] = 1 + ref_idx;
tmp_ref_rd = tmp_alt_rd;
backup_mbmi = *mbmi;
} else {
......@@ -6711,8 +6719,9 @@ void vp10_rd_pick_inter_mode_sb(VP10_COMP *cpi,
}
if (mbmi_ext->ref_mv_count[rf_type] > 1) {
nearmv[0] = mbmi_ext->ref_mv_stack[rf_type][1].this_mv;
nearmv[1] = mbmi_ext->ref_mv_stack[rf_type][1].comp_mv;
int ref_mv_idx = best_ref_mv_idx[rf_type] + 1;
nearmv[0] = mbmi_ext->ref_mv_stack[rf_type][ref_mv_idx].this_mv;
nearmv[1] = mbmi_ext->ref_mv_stack[rf_type][ref_mv_idx].comp_mv;
}
for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i) {
......@@ -6801,8 +6810,10 @@ void vp10_rd_pick_inter_mode_sb(VP10_COMP *cpi,
best_mbmode.mode = ZEROMV;
}
if (best_mbmode.mode == NEARMV && best_mbmode.ref_frame[1] == NONE)
best_mbmode.ref_mv_idx = best_ref_mv_idx[best_mbmode.ref_frame[0]];
if (best_mbmode.mode == NEARMV) {
uint8_t ref_frame_type = vp10_ref_frame_type(best_mbmode.ref_frame);
best_mbmode.ref_mv_idx = best_ref_mv_idx[ref_frame_type];
}
#endif
if (best_mode_index < 0 || best_rd >= best_rd_so_far) {
......
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