From 0b713f8c18f6695f882ad9a469ddba6842c3fa9e Mon Sep 17 00:00:00 2001 From: Paul Wilkins Date: Tue, 21 May 2013 13:57:29 +0100 Subject: [PATCH] Merge CONFIG_COMP_INTER_JOINT_SEARCH. Merge this experiment so that it is under a speed feature flag not a configuration flag. Change-Id: I536f7f125a4ff5149bb3a64f791e835c324535fd --- configure | 1 - vp9/encoder/vp9_mcomp.c | 5 +- vp9/encoder/vp9_mcomp.h | 2 - vp9/encoder/vp9_onyx_if.c | 4 +- vp9/encoder/vp9_onyx_int.h | 2 +- vp9/encoder/vp9_rdopt.c | 279 +++++++++++++++++++++++---------------------- vp9/encoder/vp9_variance.h | 2 - 7 files changed, 145 insertions(+), 150 deletions(-) diff --git a/configure b/configure index 1f68f6c..c95b58f 100755 --- a/configure +++ b/configure @@ -247,7 +247,6 @@ EXPERIMENT_LIST=" non420 alpha ab4x4 - comp_inter_joint_search " CONFIG_LIST=" external_build diff --git a/vp9/encoder/vp9_mcomp.c b/vp9/encoder/vp9_mcomp.c index 75e6e67..2e99736 100644 --- a/vp9/encoder/vp9_mcomp.c +++ b/vp9/encoder/vp9_mcomp.c @@ -414,7 +414,6 @@ int vp9_find_best_sub_pixel_step_iteratively(MACROBLOCK *x, return besterr; } -#if CONFIG_COMP_INTER_JOINT_SEARCH #undef DIST /* returns subpixel variance error function */ #define DIST(r, c) \ @@ -606,7 +605,7 @@ int vp9_find_best_sub_pixel_comp(MACROBLOCK *x, return besterr; } -#endif // CONFIG_COMP_INTER_JOINT_SEARCH + #undef MVC #undef PRE @@ -2327,7 +2326,6 @@ int vp9_refining_search_sadx4(MACROBLOCK *x, return INT_MAX; } -#if CONFIG_COMP_INTER_JOINT_SEARCH /* This function is called when we do joint motion search in comp_inter_inter * mode. */ @@ -2429,4 +2427,3 @@ int vp9_refining_search_8p_c(MACROBLOCK *x, return INT_MAX; } } -#endif // CONFIG_COMP_INTER_JOINT_SEARCH diff --git a/vp9/encoder/vp9_mcomp.h b/vp9/encoder/vp9_mcomp.h index 33e688b..28b2efd 100644 --- a/vp9/encoder/vp9_mcomp.h +++ b/vp9/encoder/vp9_mcomp.h @@ -75,7 +75,6 @@ typedef int (*vp9_diamond_search_fn_t)(MACROBLOCK *x, int *mvjcost, int *mvcost[2], int_mv *center_mv); -#if CONFIG_COMP_INTER_JOINT_SEARCH int vp9_find_best_sub_pixel_comp(MACROBLOCK *x, int_mv *bestmv, int_mv *ref_mv, int error_per_bit, @@ -91,5 +90,4 @@ int vp9_refining_search_8p_c(MACROBLOCK *x, int *mvjcost, int *mvcost[2], int_mv *center_mv, const uint8_t *second_pred, int w, int h); -#endif // CONFIG_COMP_INTER_JOINT_SEARCH #endif // VP9_ENCODER_VP9_MCOMP_H_ diff --git a/vp9/encoder/vp9_onyx_if.c b/vp9/encoder/vp9_onyx_if.c index 5a98c62..a8e1a17 100644 --- a/vp9/encoder/vp9_onyx_if.c +++ b/vp9/encoder/vp9_onyx_if.c @@ -778,6 +778,7 @@ void vp9_set_speed_features(VP9_COMP *cpi) { sf->optimize_coefficients = !cpi->oxcf.lossless; sf->first_step = 0; sf->max_step_search_steps = MAX_MVSEARCH_STEPS; + sf->comp_inter_joint_serach = 1; #if CONFIG_MULTIPLE_ARF // Switch segmentation off. sf->static_segmentation = 0; @@ -788,7 +789,6 @@ void vp9_set_speed_features(VP9_COMP *cpi) { sf->static_segmentation = 0; #endif #endif - sf->splitmode_breakout = 0; sf->mb16_breakout = 0; switch (mode) { @@ -807,13 +807,13 @@ void vp9_set_speed_features(VP9_COMP *cpi) { sf->static_segmentation = 0; #endif #endif - sf->splitmode_breakout = 1; sf->mb16_breakout = 0; if (speed > 0) { /* Disable coefficient optimization above speed 0 */ sf->optimize_coefficients = 0; sf->no_skip_block4x4_search = 0; + sf->comp_inter_joint_serach = 0; sf->first_step = 1; diff --git a/vp9/encoder/vp9_onyx_int.h b/vp9/encoder/vp9_onyx_int.h index d1204d4..e3e95ed 100644 --- a/vp9/encoder/vp9_onyx_int.h +++ b/vp9/encoder/vp9_onyx_int.h @@ -224,9 +224,9 @@ typedef struct { int optimize_coefficients; int no_skip_block4x4_search; int search_best_filter; - int splitmode_breakout; int mb16_breakout; int static_segmentation; + int comp_inter_joint_serach; } SPEED_FEATURES; enum BlockSize { diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c index c6d58df..ea57319 100644 --- a/vp9/encoder/vp9_rdopt.c +++ b/vp9/encoder/vp9_rdopt.c @@ -2083,157 +2083,160 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, ref_mv[1] = mbmi->ref_mvs[refs[1]][0]; if (is_comp_pred) { -#if CONFIG_COMP_INTER_JOINT_SEARCH - const int b_sz[BLOCK_SIZE_TYPES][2] = { - {4, 4}, - {8, 8}, - {8, 16}, - {16, 8}, - {16, 16}, - {16, 32}, - {32, 16}, - {32, 32}, - {32, 64}, - {64, 32}, - {64, 64} - }; - - int ite; - // Prediction buffer from second frame. - uint8_t *second_pred = vpx_memalign(16, b_sz[bsize][0] * - b_sz[bsize][1] * sizeof(uint8_t)); - - // Do joint motion search in compound mode to get more accurate mv. - struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0}}; - struct buf_2d backup_second_yv12[MAX_MB_PLANE] = {{0}}; - struct buf_2d scaled_first_yv12; - int last_besterr[2] = {INT_MAX, INT_MAX}; - - if (scaled_ref_frame[0]) { - int i; - - // Swap out the reference frame for a version that's been scaled to - // match the resolution of the current frame, allowing the existing - // motion search code to be used without additional modifications. - for (i = 0; i < MAX_MB_PLANE; i++) - backup_yv12[i] = xd->plane[i].pre[0]; - - setup_pre_planes(xd, scaled_ref_frame[0], NULL, mi_row, mi_col, - NULL, NULL); - } - - if (scaled_ref_frame[1]) { - int i; - - for (i = 0; i < MAX_MB_PLANE; i++) - backup_second_yv12[i] = xd->plane[i].pre[1]; - - setup_pre_planes(xd, scaled_ref_frame[1], NULL, mi_row, mi_col, - NULL, NULL); - } - xd->scale_factor[0].set_scaled_offsets(&xd->scale_factor[0], - mi_row, mi_col); - xd->scale_factor[1].set_scaled_offsets(&xd->scale_factor[1], - mi_row, mi_col); - - scaled_first_yv12 = xd->plane[0].pre[0]; - - // Initialize mv using single prediction mode result. - frame_mv[NEWMV][refs[0]].as_int = single_newmv[refs[0]].as_int; - frame_mv[NEWMV][refs[1]].as_int = single_newmv[refs[1]].as_int; - - // Allow joint search multiple times iteratively for each ref frame, and - // break out the search loop if it couldn't find better mv. - for (ite = 0; ite < 4; ite++) { - struct buf_2d ref_yv12[2] = {xd->plane[0].pre[0], - xd->plane[0].pre[1]}; - int bestsme = INT_MAX; - int sadpb = x->sadperbit16; - int_mv tmp_mv; - int search_range = 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; - int id = ite % 2; - - // Get pred block from second frame. - vp9_build_inter_predictor(ref_yv12[!id].buf, - ref_yv12[!id].stride, - second_pred, b_sz[bsize][0], - &frame_mv[NEWMV][refs[!id]], - &xd->scale_factor[!id], - b_sz[bsize][0], b_sz[bsize][1], 0, - &xd->subpix); - - // Compound motion search on first ref frame. - if (id) - xd->plane[0].pre[0] = ref_yv12[id]; - vp9_clamp_mv_min_max(x, &ref_mv[id]); - - // Use mv result from single mode as mvp. - tmp_mv.as_int = frame_mv[NEWMV][refs[id]].as_int; - - tmp_mv.as_mv.col >>= 3; - tmp_mv.as_mv.row >>= 3; - - // Small-range full-pixel motion search - bestsme = vp9_refining_search_8p_c(x, &tmp_mv, sadpb, - search_range, - &cpi->fn_ptr[block_size], - x->nmvjointcost, x->mvcost, - &ref_mv[id], second_pred, - b_sz[bsize][0], b_sz[bsize][1]); + if (cpi->sf.comp_inter_joint_serach) { + const int b_sz[BLOCK_SIZE_TYPES][2] = { + {4, 4}, + {8, 8}, + {8, 16}, + {16, 8}, + {16, 16}, + {16, 32}, + {32, 16}, + {32, 32}, + {32, 64}, + {64, 32}, + {64, 64} + }; + + int ite; + // Prediction buffer from second frame. + uint8_t *second_pred = vpx_memalign(16, b_sz[bsize][0] * + b_sz[bsize][1] * sizeof(uint8_t)); + + // Do joint motion search in compound mode to get more accurate mv. + struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0}}; + struct buf_2d backup_second_yv12[MAX_MB_PLANE] = {{0}}; + struct buf_2d scaled_first_yv12; + int last_besterr[2] = {INT_MAX, INT_MAX}; + + if (scaled_ref_frame[0]) { + int i; + + // Swap out the reference frame for a version that's been scaled to + // match the resolution of the current frame, allowing the existing + // motion search code to be used without additional modifications. + for (i = 0; i < MAX_MB_PLANE; i++) + backup_yv12[i] = xd->plane[i].pre[0]; + + setup_pre_planes(xd, scaled_ref_frame[0], NULL, mi_row, mi_col, + NULL, NULL); + } - 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; + if (scaled_ref_frame[1]) { + int i; - if (bestsme < INT_MAX) { - int dis; /* TODO: use dis in distortion calculation later. */ - unsigned int sse; + for (i = 0; i < MAX_MB_PLANE; i++) + backup_second_yv12[i] = xd->plane[i].pre[1]; - bestsme = vp9_find_best_sub_pixel_comp(x, &tmp_mv, - &ref_mv[id], - x->errorperbit, - &cpi->fn_ptr[block_size], - x->nmvjointcost, x->mvcost, - &dis, &sse, second_pred, - b_sz[bsize][0], - b_sz[bsize][1]); + setup_pre_planes(xd, scaled_ref_frame[1], NULL, mi_row, mi_col, + NULL, NULL); } + xd->scale_factor[0].set_scaled_offsets(&xd->scale_factor[0], + mi_row, mi_col); + xd->scale_factor[1].set_scaled_offsets(&xd->scale_factor[1], + mi_row, mi_col); + + scaled_first_yv12 = xd->plane[0].pre[0]; + + // Initialize mv using single prediction mode result. + frame_mv[NEWMV][refs[0]].as_int = single_newmv[refs[0]].as_int; + frame_mv[NEWMV][refs[1]].as_int = single_newmv[refs[1]].as_int; + + // Allow joint search multiple times iteratively for each ref frame + // and break out the search loop if it couldn't find better mv. + for (ite = 0; ite < 4; ite++) { + struct buf_2d ref_yv12[2]; + int bestsme = INT_MAX; + int sadpb = x->sadperbit16; + int_mv tmp_mv; + int search_range = 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; + int id = ite % 2; + + // Initialized here because of compiler problem in Visual Studio. + ref_yv12[0] = xd->plane[0].pre[0]; + ref_yv12[1] = xd->plane[0].pre[1]; + + // Get pred block from second frame. + vp9_build_inter_predictor(ref_yv12[!id].buf, + ref_yv12[!id].stride, + second_pred, b_sz[bsize][0], + &frame_mv[NEWMV][refs[!id]], + &xd->scale_factor[!id], + b_sz[bsize][0], b_sz[bsize][1], 0, + &xd->subpix); + + // Compound motion search on first ref frame. + if (id) + xd->plane[0].pre[0] = ref_yv12[id]; + vp9_clamp_mv_min_max(x, &ref_mv[id]); + + // Use mv result from single mode as mvp. + tmp_mv.as_int = frame_mv[NEWMV][refs[id]].as_int; + + tmp_mv.as_mv.col >>= 3; + tmp_mv.as_mv.row >>= 3; + + // Small-range full-pixel motion search + bestsme = vp9_refining_search_8p_c(x, &tmp_mv, sadpb, + search_range, + &cpi->fn_ptr[block_size], + x->nmvjointcost, x->mvcost, + &ref_mv[id], second_pred, + b_sz[bsize][0], b_sz[bsize][1]); + + 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; + + if (bestsme < INT_MAX) { + int dis; /* TODO: use dis in distortion calculation later. */ + unsigned int sse; + + bestsme = vp9_find_best_sub_pixel_comp(x, &tmp_mv, + &ref_mv[id], + x->errorperbit, + &cpi->fn_ptr[block_size], + x->nmvjointcost, x->mvcost, + &dis, &sse, second_pred, + b_sz[bsize][0], + b_sz[bsize][1]); + } - if (id) - xd->plane[0].pre[0] = scaled_first_yv12; + if (id) + xd->plane[0].pre[0] = scaled_first_yv12; - if (bestsme < last_besterr[id]) { + if (bestsme < last_besterr[id]) { frame_mv[NEWMV][refs[id]].as_int = - xd->mode_info_context->bmi[0].as_mv[1].as_int = tmp_mv.as_int; - last_besterr[id] = bestsme; - } else { - break; + xd->mode_info_context->bmi[0].as_mv[1].as_int = tmp_mv.as_int; + last_besterr[id] = bestsme; + } else { + break; + } } - } - // restore the predictor - if (scaled_ref_frame[0]) { - int i; + // restore the predictor + if (scaled_ref_frame[0]) { + int i; - for (i = 0; i < MAX_MB_PLANE; i++) - xd->plane[i].pre[0] = backup_yv12[i]; - } + for (i = 0; i < MAX_MB_PLANE; i++) + xd->plane[i].pre[0] = backup_yv12[i]; + } - if (scaled_ref_frame[1]) { - int i; + if (scaled_ref_frame[1]) { + int i; - for (i = 0; i < MAX_MB_PLANE; i++) - xd->plane[i].pre[1] = backup_second_yv12[i]; - } + for (i = 0; i < MAX_MB_PLANE; i++) + xd->plane[i].pre[1] = backup_second_yv12[i]; + } - vpx_free(second_pred); -#endif // CONFIG_COMP_INTER_JOINT_SEARCH + vpx_free(second_pred); + } if (frame_mv[NEWMV][refs[0]].as_int == INVALID_MV || frame_mv[NEWMV][refs[1]].as_int == INVALID_MV) diff --git a/vp9/encoder/vp9_variance.h b/vp9/encoder/vp9_variance.h index 306476b..aaa43ef 100644 --- a/vp9/encoder/vp9_variance.h +++ b/vp9/encoder/vp9_variance.h @@ -86,7 +86,6 @@ typedef struct vp9_variance_vtable { vp9_sad_multi_d_fn_t sdx4df; } vp9_variance_fn_ptr_t; -// #if CONFIG_COMP_INTER_JOINT_SEARCH static void comp_avg_pred(uint8_t *comp_pred, const uint8_t *pred, int weight, int height, uint8_t *ref, int ref_stride) { int i, j; @@ -102,5 +101,4 @@ static void comp_avg_pred(uint8_t *comp_pred, const uint8_t *pred, int weight, ref += ref_stride; } } -// #endif // CONFIG_COMP_INTER_JOINT_SEARCH #endif // VP9_ENCODER_VP9_VARIANCE_H_ -- 2.7.4