diff options
author | Yunqing Wang <yunqingwang@google.com> | 2011-01-28 10:00:20 -0500 |
---|---|---|
committer | Yunqing Wang <yunqingwang@google.com> | 2011-01-28 10:00:20 -0500 |
commit | 7cbe684ef529d922b0da738a6095774cdc1eb1be (patch) | |
tree | 1bcfaa9687c9b80aa103d40231fa374981b7caa5 /vp8/encoder/pickinter.c | |
parent | dcb23e2aaaef27a12d72f7e263f9629fdf68c266 (diff) | |
download | libvpx-7cbe684ef529d922b0da738a6095774cdc1eb1be.tar libvpx-7cbe684ef529d922b0da738a6095774cdc1eb1be.tar.gz libvpx-7cbe684ef529d922b0da738a6095774cdc1eb1be.tar.bz2 libvpx-7cbe684ef529d922b0da738a6095774cdc1eb1be.zip |
Improve MV prediction in vp8_pick_inter_mode() for speed>3
Applied same method used in vp8_rd_pick_inter_mode() to improve
the accuracy of MV prediction.
Change-Id: Ia50ae26208b18482695601f32febd99fe89fbc17
Diffstat (limited to 'vp8/encoder/pickinter.c')
-rw-r--r-- | vp8/encoder/pickinter.c | 141 |
1 files changed, 75 insertions, 66 deletions
diff --git a/vp8/encoder/pickinter.c b/vp8/encoder/pickinter.c index 2b0f57508..d60a5543e 100644 --- a/vp8/encoder/pickinter.c +++ b/vp8/encoder/pickinter.c @@ -24,7 +24,7 @@ #include "g_common.h" #include "variance.h" #include "mcomp.h" - +#include "rdopt.h" #include "vpx_mem/vpx_mem.h" #if CONFIG_RUNTIME_CPU_DETECT @@ -421,7 +421,6 @@ int vp8_pick_intra_mbuv_mode(MACROBLOCK *mb) } - int vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int recon_uvoffset, int *returnrate, int *returndistortion, int *returnintra) { BLOCK *b = &x->block[0]; @@ -430,7 +429,7 @@ int vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int rec B_MODE_INFO best_bmodes[16]; MB_MODE_INFO best_mbmode; PARTITION_INFO best_partition; - MV best_ref_mv1; + MV best_ref_mv; MV mode_mv[MB_MODE_COUNT]; MB_PREDICTION_MODE this_mode; int num00; @@ -448,9 +447,14 @@ int vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int rec int best_mode_index = 0; int sse = INT_MAX; + MV mvp; + int near_sadidx[8] = {0, 1, 2, 3, 4, 5, 6, 7}; + int saddone=0; + int sr=0; //search range got from mv_pred(). It uses step_param levels. (0-7) + MV nearest_mv[4]; MV near_mv[4]; - MV best_ref_mv[4]; + MV frame_best_ref_mv[4]; int MDCounts[4][4]; unsigned char *y_buffer[4]; unsigned char *u_buffer[4]; @@ -470,7 +474,7 @@ int vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int rec YV12_BUFFER_CONFIG *lst_yv12 = &cpi->common.yv12_fb[cpi->common.lst_fb_idx]; vp8_find_near_mvs(&x->e_mbd, x->e_mbd.mode_info_context, &nearest_mv[LAST_FRAME], &near_mv[LAST_FRAME], - &best_ref_mv[LAST_FRAME], MDCounts[LAST_FRAME], LAST_FRAME, cpi->common.ref_frame_sign_bias); + &frame_best_ref_mv[LAST_FRAME], MDCounts[LAST_FRAME], LAST_FRAME, cpi->common.ref_frame_sign_bias); y_buffer[LAST_FRAME] = lst_yv12->y_buffer + recon_yoffset; u_buffer[LAST_FRAME] = lst_yv12->u_buffer + recon_uvoffset; @@ -484,7 +488,7 @@ int vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int rec YV12_BUFFER_CONFIG *gld_yv12 = &cpi->common.yv12_fb[cpi->common.gld_fb_idx]; vp8_find_near_mvs(&x->e_mbd, x->e_mbd.mode_info_context, &nearest_mv[GOLDEN_FRAME], &near_mv[GOLDEN_FRAME], - &best_ref_mv[GOLDEN_FRAME], MDCounts[GOLDEN_FRAME], GOLDEN_FRAME, cpi->common.ref_frame_sign_bias); + &frame_best_ref_mv[GOLDEN_FRAME], MDCounts[GOLDEN_FRAME], GOLDEN_FRAME, cpi->common.ref_frame_sign_bias); y_buffer[GOLDEN_FRAME] = gld_yv12->y_buffer + recon_yoffset; u_buffer[GOLDEN_FRAME] = gld_yv12->u_buffer + recon_uvoffset; @@ -498,7 +502,7 @@ int vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int rec YV12_BUFFER_CONFIG *alt_yv12 = &cpi->common.yv12_fb[cpi->common.alt_fb_idx]; vp8_find_near_mvs(&x->e_mbd, x->e_mbd.mode_info_context, &nearest_mv[ALTREF_FRAME], &near_mv[ALTREF_FRAME], - &best_ref_mv[ALTREF_FRAME], MDCounts[ALTREF_FRAME], ALTREF_FRAME, cpi->common.ref_frame_sign_bias); + &frame_best_ref_mv[ALTREF_FRAME], MDCounts[ALTREF_FRAME], ALTREF_FRAME, cpi->common.ref_frame_sign_bias); y_buffer[ALTREF_FRAME] = alt_yv12->y_buffer + recon_yoffset; u_buffer[ALTREF_FRAME] = alt_yv12->u_buffer + recon_uvoffset; @@ -538,10 +542,6 @@ int vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int rec + vp8_cost_one(cpi->prob_gf_coded); } - - - best_rd = INT_MAX; - x->e_mbd.mode_info_context->mbmi.ref_frame = INTRA_FRAME; // if we encode a new mv this is important @@ -604,7 +604,7 @@ int vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int rec x->e_mbd.pre.v_buffer = v_buffer[x->e_mbd.mode_info_context->mbmi.ref_frame]; mode_mv[NEARESTMV] = nearest_mv[x->e_mbd.mode_info_context->mbmi.ref_frame]; mode_mv[NEARMV] = near_mv[x->e_mbd.mode_info_context->mbmi.ref_frame]; - best_ref_mv1 = best_ref_mv[x->e_mbd.mode_info_context->mbmi.ref_frame]; + best_ref_mv = frame_best_ref_mv[x->e_mbd.mode_info_context->mbmi.ref_frame]; memcpy(mdcounts, MDCounts[x->e_mbd.mode_info_context->mbmi.ref_frame], sizeof(mdcounts)); } @@ -617,6 +617,28 @@ int vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int rec continue; } + if(x->e_mbd.mode_info_context->mbmi.mode == NEWMV) + { + if(!saddone) + { + vp8_cal_sad(cpi,xd,x, recon_yoffset ,&near_sadidx[0] ); + saddone = 1; + } + + vp8_mv_pred(cpi, &x->e_mbd, x->e_mbd.mode_info_context, &mvp, + x->e_mbd.mode_info_context->mbmi.ref_frame, cpi->common.ref_frame_sign_bias, &sr, &near_sadidx[0]); + + /* adjust mvp to make sure it is within MV range */ + if(mvp.row > best_ref_mv.row + MAX_FULL_PEL_VAL) + mvp.row = best_ref_mv.row + MAX_FULL_PEL_VAL; + else if(mvp.row < best_ref_mv.row - MAX_FULL_PEL_VAL) + mvp.row = best_ref_mv.row - MAX_FULL_PEL_VAL; + if(mvp.col > best_ref_mv.col + MAX_FULL_PEL_VAL) + mvp.col = best_ref_mv.col + MAX_FULL_PEL_VAL; + else if(mvp.col < best_ref_mv.col - MAX_FULL_PEL_VAL) + mvp.col = best_ref_mv.col - MAX_FULL_PEL_VAL; + } + switch (this_mode) { case B_PRED: @@ -672,61 +694,46 @@ int vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int rec int n = 0; int sadpb = x->sadperbit16; - // Further step/diamond searches as necessary - if (cpi->Speed < 8) - { - step_param = cpi->sf.first_step + ((cpi->Speed > 5) ? 1 : 0); - further_steps = (cpi->sf.max_step_search_steps - 1) - step_param; - } - else - { - step_param = cpi->sf.first_step + 2; - further_steps = 0; - } - -#if 0 + int col_min = (best_ref_mv.col - MAX_FULL_PEL_VAL) >>3; + int col_max = (best_ref_mv.col + MAX_FULL_PEL_VAL) >>3; + int row_min = (best_ref_mv.row - MAX_FULL_PEL_VAL) >>3; + int row_max = (best_ref_mv.row + MAX_FULL_PEL_VAL) >>3; + + int tmp_col_min = x->mv_col_min; + int tmp_col_max = x->mv_col_max; + int tmp_row_min = x->mv_row_min; + int tmp_row_max = x->mv_row_max; + + // Get intersection of UMV window and valid MV window to reduce # of checks in diamond search. + if (x->mv_col_min < col_min ) + x->mv_col_min = col_min; + if (x->mv_col_max > col_max ) + x->mv_col_max = col_max; + if (x->mv_row_min < row_min ) + x->mv_row_min = row_min; + if (x->mv_row_max > row_max ) + x->mv_row_max = row_max; - // Initial step Search - bestsme = vp8_diamond_search_sad(x, b, d, &best_ref_mv1, &d->bmi.mv.as_mv, step_param, x->errorperbit, &num00, &cpi->fn_ptr, cpi->mb.mvsadcost, cpi->mb.mvcost, &best_ref_mv1); - mode_mv[NEWMV].row = d->bmi.mv.as_mv.row; - mode_mv[NEWMV].col = d->bmi.mv.as_mv.col; - - // Further step searches - while (n < further_steps) + // Further step/diamond searches as necessary { - n++; - - if (num00) - num00--; - else - { - thissme = vp8_diamond_search_sad(x, b, d, &best_ref_mv1, &d->bmi.mv.as_mv, step_param + n, x->errorperbit, &num00, &cpi->fn_ptr, cpi->mb.mvsadcost, x->mvcost, &best_ref_mv1); - - if (thissme < bestsme) - { - bestsme = thissme; - mode_mv[NEWMV].row = d->bmi.mv.as_mv.row; - mode_mv[NEWMV].col = d->bmi.mv.as_mv.col; - } - else - { - d->bmi.mv.as_mv.row = mode_mv[NEWMV].row; - d->bmi.mv.as_mv.col = mode_mv[NEWMV].col; - } - } + int speed_adjust = (cpi->Speed > 5) ? ((cpi->Speed >= 8)? 3 : 2) : 1; + step_param = cpi->sf.first_step + speed_adjust; + sr += speed_adjust; + //adjust search range according to sr from mv prediction + if(sr > step_param) + step_param = sr; + further_steps = (cpi->Speed >= 8)? 0: (cpi->sf.max_step_search_steps - 1 - step_param); } -#else - if (cpi->sf.search_method == HEX) { - bestsme = vp8_hex_search(x, b, d, &best_ref_mv1, &d->bmi.mv.as_mv, step_param, sadpb/*x->errorperbit*/, &num00, &cpi->fn_ptr[BLOCK_16X16], x->mvsadcost, x->mvcost); + bestsme = vp8_hex_search(x, b, d, &best_ref_mv, &d->bmi.mv.as_mv, step_param, sadpb/*x->errorperbit*/, &num00, &cpi->fn_ptr[BLOCK_16X16], x->mvsadcost, x->mvcost); mode_mv[NEWMV].row = d->bmi.mv.as_mv.row; mode_mv[NEWMV].col = d->bmi.mv.as_mv.col; } else { - bestsme = cpi->diamond_search_sad(x, b, d, &best_ref_mv1, &d->bmi.mv.as_mv, step_param, sadpb / 2/*x->errorperbit*/, &num00, &cpi->fn_ptr[BLOCK_16X16], x->mvsadcost, x->mvcost, &best_ref_mv1); //sadpb < 9 + bestsme = cpi->diamond_search_sad(x, b, d, &mvp, &d->bmi.mv.as_mv, step_param, sadpb / 2/*x->errorperbit*/, &num00, &cpi->fn_ptr[BLOCK_16X16], x->mvsadcost, x->mvcost, &best_ref_mv); //sadpb < 9 mode_mv[NEWMV].row = d->bmi.mv.as_mv.row; mode_mv[NEWMV].col = d->bmi.mv.as_mv.col; @@ -745,7 +752,7 @@ int vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int rec num00--; else { - thissme = cpi->diamond_search_sad(x, b, d, &best_ref_mv1, &d->bmi.mv.as_mv, step_param + n, sadpb / 4/*x->errorperbit*/, &num00, &cpi->fn_ptr[BLOCK_16X16], x->mvsadcost, x->mvcost, &best_ref_mv1); //sadpb = 9 + thissme = cpi->diamond_search_sad(x, b, d, &mvp, &d->bmi.mv.as_mv, step_param + n, sadpb / 4/*x->errorperbit*/, &num00, &cpi->fn_ptr[BLOCK_16X16], x->mvsadcost, x->mvcost, &best_ref_mv); //sadpb = 9 if (thissme < bestsme) { @@ -762,18 +769,20 @@ int vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int rec } } -#endif - } - - if (bestsme < INT_MAX) - cpi->find_fractional_mv_step(x, b, d, &d->bmi.mv.as_mv, &best_ref_mv1, x->errorperbit, &cpi->fn_ptr[BLOCK_16X16], cpi->mb.mvcost); + x->mv_col_min = tmp_col_min; + x->mv_col_max = tmp_col_max; + x->mv_row_min = tmp_row_min; + x->mv_row_max = tmp_row_max; - mode_mv[NEWMV].row = d->bmi.mv.as_mv.row; - mode_mv[NEWMV].col = d->bmi.mv.as_mv.col; + if (bestsme < INT_MAX) + cpi->find_fractional_mv_step(x, b, d, &d->bmi.mv.as_mv, &best_ref_mv, x->errorperbit, &cpi->fn_ptr[BLOCK_16X16], cpi->mb.mvcost); - // mv cost; - rate2 += vp8_mv_bit_cost(&mode_mv[NEWMV], &best_ref_mv1, cpi->mb.mvcost, 128); + mode_mv[NEWMV].row = d->bmi.mv.as_mv.row; + mode_mv[NEWMV].col = d->bmi.mv.as_mv.col; + // mv cost; + rate2 += vp8_mv_bit_cost(&mode_mv[NEWMV], &best_ref_mv, cpi->mb.mvcost, 128); + } case NEARESTMV: case NEARMV: |