diff options
author | Jingning Han <jingning@google.com> | 2013-12-27 15:04:16 -0800 |
---|---|---|
committer | Gerrit Code Review <gerrit@gerrit.golo.chromium.org> | 2013-12-27 15:04:16 -0800 |
commit | cdc933ca0043b7944a4a45edb85d4c142f63fc56 (patch) | |
tree | 344653ec4ad14031d49149b4d71599fd9b11b2a5 | |
parent | 7eb09151bcf29c0cefc351c64abe2aaa6d037bd5 (diff) | |
parent | a4ce53f14d25ffea989fc83ee7f039762a142c83 (diff) | |
download | libvpx-cdc933ca0043b7944a4a45edb85d4c142f63fc56.tar libvpx-cdc933ca0043b7944a4a45edb85d4c142f63fc56.tar.gz libvpx-cdc933ca0043b7944a4a45edb85d4c142f63fc56.tar.bz2 libvpx-cdc933ca0043b7944a4a45edb85d4c142f63fc56.zip |
Merge "Adaptive motion control on ref and search range"
-rw-r--r-- | vp9/encoder/vp9_block.h | 3 | ||||
-rw-r--r-- | vp9/encoder/vp9_rdopt.c | 47 |
2 files changed, 41 insertions, 9 deletions
diff --git a/vp9/encoder/vp9_block.h b/vp9/encoder/vp9_block.h index 8300c9522..4b33f7a1f 100644 --- a/vp9/encoder/vp9_block.h +++ b/vp9/encoder/vp9_block.h @@ -118,7 +118,8 @@ struct macroblock { int mv_best_ref_index[MAX_REF_FRAMES]; unsigned int max_mv_context[MAX_REF_FRAMES]; unsigned int source_variance; - unsigned int pred_sse; + unsigned int pred_sse[MAX_REF_FRAMES]; + int pred_mv_sad[MAX_REF_FRAMES]; int nmvjointcost[MV_JOINTS]; int nmvcosts[2][MV_VALS]; diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c index 1dcb2af88..f3eb996ab 100644 --- a/vp9/encoder/vp9_rdopt.c +++ b/vp9/encoder/vp9_rdopt.c @@ -416,6 +416,8 @@ static void model_rd_for_sb(VP9_COMP *cpi, BLOCK_SIZE bsize, // Hence quantizer step is also 8 times. To get effective quantizer // we need to divide by 8 before sending to modeling function. int i, rate_sum = 0, dist_sum = 0; + int ref = xd->mi_8x8[0]->mbmi.ref_frame[0]; + unsigned int sse; for (i = 0; i < MAX_MB_PLANE; ++i) { struct macroblock_plane *const p = &x->plane[i]; @@ -424,9 +426,11 @@ static void model_rd_for_sb(VP9_COMP *cpi, BLOCK_SIZE bsize, int rate; int64_t dist; (void) cpi->fn_ptr[bs].vf(p->src.buf, p->src.stride, - pd->dst.buf, pd->dst.stride, &x->pred_sse); + pd->dst.buf, pd->dst.stride, &sse); + if (i == 0) + x->pred_sse[ref] = sse; // sse works better than var, since there is no dc prediction used - model_rd_from_var_lapndz(x->pred_sse, 1 << num_pels_log2_lookup[bs], + model_rd_from_var_lapndz(sse, 1 << num_pels_log2_lookup[bs], pd->dequant[1] >> 3, &rate, &dist); rate_sum += rate; @@ -1838,7 +1842,8 @@ static void rd_check_segment_txsize(VP9_COMP *cpi, MACROBLOCK *x, x->errorperbit, v_fn_ptr, 0, cpi->sf.subpel_iters_per_step, x->nmvjointcost, x->mvcost, - &distortion, &x->pred_sse); + &distortion, + &x->pred_sse[mbmi->ref_frame[0]]); // save motion search result for use in compound prediction seg_mvs[i][mbmi->ref_frame[0]].as_int = mode_mv[NEWMV].as_int; @@ -2133,6 +2138,7 @@ static void mv_pred(VP9_COMP *cpi, MACROBLOCK *x, // Note the index of the mv that worked best in the reference list. x->mv_best_ref_index[ref_frame] = best_index; x->max_mv_context[ref_frame] = max_mv; + x->pred_mv_sad[ref_frame] = best_sad; } static void estimate_ref_frame_costs(VP9_COMP *cpi, int segment_id, @@ -2380,6 +2386,30 @@ static void single_motion_search(VP9_COMP *cpi, MACROBLOCK *x, step_param = MAX(step_param, boffset); } + if (cpi->sf.adaptive_motion_search) { + int bwl = b_width_log2_lookup[bsize]; + int bhl = b_height_log2_lookup[bsize]; + int i; + int tlevel = x->pred_mv_sad[ref] >> (bwl + bhl + 4); + + if (tlevel < 5) + step_param += 2; + + for (i = LAST_FRAME; i <= ALTREF_FRAME && cpi->common.show_frame; ++i) { + if ((x->pred_mv_sad[ref] >> 3) > x->pred_mv_sad[i]) { + x->pred_mv[ref].as_int = 0; + tmp_mv->as_int = INVALID_MV; + + if (scaled_ref_frame) { + int i; + for (i = 0; i < MAX_MB_PLANE; i++) + xd->plane[i].pre[0] = backup_yv12[i]; + } + return; + } + } + } + mvp_full.as_int = x->mv_best_ref_index[ref] < MAX_MV_REF_CANDIDATES ? mbmi->ref_mvs[ref][x->mv_best_ref_index[ref]].as_int : x->pred_mv[ref].as_int; @@ -2428,7 +2458,7 @@ static void single_motion_search(VP9_COMP *cpi, MACROBLOCK *x, &cpi->fn_ptr[bsize], 0, cpi->sf.subpel_iters_per_step, x->nmvjointcost, x->mvcost, - &dis, &x->pred_sse); + &dis, &x->pred_sse[ref]); } *rate_mv = vp9_mv_bit_cost(&tmp_mv->as_mv, &ref_mv.as_mv, x->nmvjointcost, x->mvcost, MV_COST_WEIGHT); @@ -2490,7 +2520,6 @@ static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, for (ite = 0; ite < 4; ite++) { struct buf_2d ref_yv12[2]; int bestsme = INT_MAX; - unsigned int bestsse = INT_MAX; int sadpb = x->sadperbit16; int_mv tmp_mv; int search_range = 3; @@ -2541,6 +2570,7 @@ static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, if (bestsme < INT_MAX) { int dis; /* TODO: use dis in distortion calculation later. */ + unsigned int sse; bestsme = cpi->find_fractional_mv_step_comp( x, &tmp_mv.as_mv, &ref_mv[id].as_mv, @@ -2549,7 +2579,7 @@ static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, &cpi->fn_ptr[bsize], 0, cpi->sf.subpel_iters_per_step, x->nmvjointcost, x->mvcost, - &dis, &bestsse, second_pred, + &dis, &sse, second_pred, pw, ph); } @@ -2559,7 +2589,6 @@ static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, if (bestsme < last_besterr[id]) { frame_mv[refs[id]].as_int = tmp_mv.as_int; last_besterr[id] = bestsme; - x->pred_sse = bestsse; } else { break; } @@ -2851,7 +2880,6 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, vp9_build_inter_predictors_sb(xd, mi_row, mi_col, bsize); } - if (cpi->sf.use_rd_breakout && ref_best_rd < INT64_MAX) { int tmp_rate; int64_t tmp_dist; @@ -3146,6 +3174,8 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, best_filter_rd[i] = INT64_MAX; for (i = 0; i < TX_SIZES; i++) rate_uv_intra[i] = INT_MAX; + for (i = 0; i < MAX_REF_FRAMES; ++i) + x->pred_sse[i] = INT_MAX; *returnrate = INT_MAX; @@ -3183,6 +3213,7 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, } for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ref_frame++) { + x->pred_mv_sad[ref_frame] = INT_MAX; if (cpi->ref_frame_flags & flag_list[ref_frame]) { setup_buffer_inter(cpi, x, tile, idx_list[ref_frame], ref_frame, block_size, mi_row, mi_col, |