From 778ec421e7f5d75e360fa5e67e25fbf9d1714ca3 Mon Sep 17 00:00:00 2001 From: Paul Wilkins Date: Fri, 7 Sep 2012 14:21:22 +0100 Subject: Partial merge of NEWBESTREFMV and NEW_MVREF. This commit merges those parts of the CONFIG_NEW_MVREF that specifically relate to choosing a better set of candidate MV references into the NEWBESTREFMV experiment. CONFIG_NEW_MVREF will then be used for changes relating to the explicit coding of a cost optimized MV reference in the bitstream as part of MV coding. Change-Id: Ied982c0ad72093eab29e38b8cd74d5c3d7458b10 --- vp8/common/blockd.h | 18 ++---------- vp8/common/findnearmv.c | 75 ----------------------------------------------- vp8/common/mvref_common.c | 29 +++++++++--------- vp8/common/mvref_common.h | 2 +- vp8/decoder/decodemv.c | 12 -------- vp8/encoder/bitstream.c | 2 +- vp8/encoder/encodeframe.c | 3 +- vp8/encoder/onyx_if.c | 21 ++----------- vp8/encoder/onyx_int.h | 11 +------ vp8/encoder/rdopt.c | 45 +--------------------------- 10 files changed, 23 insertions(+), 195 deletions(-) (limited to 'vp8') diff --git a/vp8/common/blockd.h b/vp8/common/blockd.h index aa46aa5e3..96345c2bd 100644 --- a/vp8/common/blockd.h +++ b/vp8/common/blockd.h @@ -44,7 +44,7 @@ void vpx_log(const char *format, ...); /* Segment Feature Masks */ #define SEGMENT_DELTADATA 0 #define SEGMENT_ABSDATA 1 -#if CONFIG_NEW_MVREF +#if CONFIG_NEWBESTREFMV || CONFIG_NEW_MVREF #define MAX_MV_REFS 19 #endif @@ -186,14 +186,6 @@ typedef enum { B_MODE_COUNT } B_PREDICTION_MODE; -#if CONFIG_NEW_MVREF -// Segment level features. -typedef enum { - FIRST_REF = 0, - SECOND_REF = 1 -} MV_REF_TYPE; -#endif - #if CONFIG_HYBRIDTRANSFORM8X8 || CONFIG_HYBRIDTRANSFORM16X16 // convert MB_PREDICTION_MODE to B_PREDICTION_MODE static B_PREDICTION_MODE pred_mode_conv(MB_PREDICTION_MODE mode) { @@ -283,10 +275,8 @@ typedef struct { MV_REFERENCE_FRAME ref_frame, second_ref_frame; TX_SIZE txfm_size; int_mv mv[2]; // for each reference frame used -#if CONFIG_NEWBESTREFMV || CONFIG_NEW_MVREF +#if CONFIG_NEWBESTREFMV int_mv ref_mv, second_ref_mv; -#endif -#if CONFIG_NEW_MVREF int_mv ref_mvs[MAX_REF_FRAMES][MAX_MV_REFS]; int mv_ref_index[MAX_REF_FRAMES]; #endif @@ -454,11 +444,7 @@ typedef struct MacroBlockD { int mb_index; // Index of the MB in the SB (0..3) #if CONFIG_NEWBESTREFMV -#if CONFIG_NEW_MVREF int_mv ref_mv[MAX_MV_REFS]; -#else - int_mv ref_mv[4]; -#endif #endif #if CONFIG_HYBRIDTRANSFORM || CONFIG_HYBRIDTRANSFORM8X8 || CONFIG_HYBRIDTRANSFORM16X16 diff --git a/vp8/common/findnearmv.c b/vp8/common/findnearmv.c index d2a7769ca..3363d46ca 100644 --- a/vp8/common/findnearmv.c +++ b/vp8/common/findnearmv.c @@ -201,8 +201,6 @@ vp8_prob *vp8_mv_ref_probs(VP8_COMMON *pc, * score to use as ref motion vector */ -#if CONFIG_NEW_MVREF - void vp8_find_best_ref_mvs(MACROBLOCKD *xd, unsigned char *ref_y_buffer, int ref_y_stride, @@ -310,77 +308,4 @@ void vp8_find_best_ref_mvs(MACROBLOCKD *xd, vp8_clamp_mv2(best_mv, xd); } -#else // !CONFIG_NEW_MVREF - -void vp8_find_best_ref_mvs(MACROBLOCKD *xd, - unsigned char *ref_y_buffer, - int ref_y_stride, - int_mv *mvlist, - int_mv *best_mv, - int_mv *nearest, - int_mv *near) { - int bestsad = INT_MAX; - int i; - unsigned char *above_src; - unsigned char *left_src; - unsigned char *above_ref; - unsigned char *left_ref; - int sad; - - above_src = xd->dst.y_buffer - xd->dst.y_stride * 2; - left_src = xd->dst.y_buffer - 2; - above_ref = ref_y_buffer - ref_y_stride * 2; - left_ref = ref_y_buffer - 2; - - bestsad = vp8_sad16x2_c(above_src, xd->dst.y_stride, - above_ref, ref_y_stride, - INT_MAX); - bestsad += vp8_sad2x16_c(left_src, xd->dst.y_stride, - left_ref, ref_y_stride, - INT_MAX); - best_mv->as_int = 0; - - for(i = 0; i < 4; ++i) { - if (mvlist[i].as_int) { - int_mv this_mv; - int offset=0; - int row_offset, col_offset; - this_mv.as_int = mvlist[i].as_int; - vp8_clamp_mv(&this_mv, - xd->mb_to_left_edge - LEFT_TOP_MARGIN + 16, - xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN, - xd->mb_to_top_edge - LEFT_TOP_MARGIN + 16, - xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN); - - row_offset = (this_mv.as_mv.row > 0) ? - ((this_mv.as_mv.row + 3) >> 3):((this_mv.as_mv.row + 4) >> 3); - col_offset = (this_mv.as_mv.col > 0) ? - ((this_mv.as_mv.col + 3) >> 3):((this_mv.as_mv.col + 4) >> 3); - offset = ref_y_stride * row_offset + col_offset; - - sad = vp8_sad16x2_c(above_src, xd->dst.y_stride, - above_ref + offset, ref_y_stride, INT_MAX); - - sad += vp8_sad2x16_c(left_src, xd->dst.y_stride, - left_ref + offset, ref_y_stride, INT_MAX); - - if (sad < bestsad) { - bestsad = sad; - best_mv->as_int = this_mv.as_int; - } - } - } - if (!xd->allow_high_precision_mv) - lower_mv_precision(best_mv); - - vp8_clamp_mv2(best_mv, xd); - - if (best_mv->as_int != 0 && - (best_mv->as_mv.row >> 3) != (nearest->as_mv.row >>3 ) && - (best_mv->as_mv.col >> 3) != (nearest->as_mv.col >>3 )) { - near->as_int = nearest->as_int; - nearest->as_int = best_mv->as_int; - } -} -#endif // CONFIG_NEW_MVREF #endif // CONFIG_NEWBESTREFMV diff --git a/vp8/common/mvref_common.c b/vp8/common/mvref_common.c index 0b632e0d5..b6040cd59 100644 --- a/vp8/common/mvref_common.c +++ b/vp8/common/mvref_common.c @@ -10,14 +10,13 @@ #include "mvref_common.h" -#if CONFIG_NEW_MVREF +#if CONFIG_NEWBESTREFMV #define MVREF_NEIGHBOURS 8 static int mv_ref_search[MVREF_NEIGHBOURS][2] = { {0,-1},{-1,0},{-1,-1},{0,-2},{-2,0},{-1,-2},{-2,-1},{-2,-2} }; static int ref_distance_weight[MVREF_NEIGHBOURS] = { 3,3,2,1,1,1,1,1 }; - //{ 4,4,2,1,1,1,1,1 }; // clamp_mv #define MV_BORDER (16 << 3) // Allow 16 pels in 1/8th pel units @@ -59,50 +58,50 @@ int get_candidate_mvref( // Target ref frame matches candidate first ref frame if (ref_frame == candidate_mi->mbmi.ref_frame) { - c_mv->as_int = candidate_mi->mbmi.mv[FIRST_REF].as_int; + c_mv->as_int = candidate_mi->mbmi.mv[0].as_int; *c_ref_frame = ref_frame; ret_val = TRUE; // Is there a second non zero vector we can use. if ((candidate_mi->mbmi.second_ref_frame != INTRA_FRAME) && - (candidate_mi->mbmi.mv[SECOND_REF].as_int != 0) && - (candidate_mi->mbmi.mv[SECOND_REF].as_int != c_mv->as_int)) { - c2_mv->as_int = candidate_mi->mbmi.mv[SECOND_REF].as_int; + (candidate_mi->mbmi.mv[1].as_int != 0) && + (candidate_mi->mbmi.mv[1].as_int != c_mv->as_int)) { + c2_mv->as_int = candidate_mi->mbmi.mv[1].as_int; *c2_ref_frame = candidate_mi->mbmi.second_ref_frame; } // Target ref frame matches candidate second ref frame } else if (ref_frame == candidate_mi->mbmi.second_ref_frame) { - c_mv->as_int = candidate_mi->mbmi.mv[SECOND_REF].as_int; + c_mv->as_int = candidate_mi->mbmi.mv[1].as_int; *c_ref_frame = ref_frame; ret_val = TRUE; // Is there a second non zero vector we can use. if ((candidate_mi->mbmi.ref_frame != INTRA_FRAME) && - (candidate_mi->mbmi.mv[FIRST_REF].as_int != 0) && - (candidate_mi->mbmi.mv[FIRST_REF].as_int != c_mv->as_int)) { - c2_mv->as_int = candidate_mi->mbmi.mv[FIRST_REF].as_int; + (candidate_mi->mbmi.mv[0].as_int != 0) && + (candidate_mi->mbmi.mv[0].as_int != c_mv->as_int)) { + c2_mv->as_int = candidate_mi->mbmi.mv[0].as_int; *c2_ref_frame = candidate_mi->mbmi.ref_frame; } // No ref frame matches so use first ref mv as first choice } else if (candidate_mi->mbmi.ref_frame != INTRA_FRAME) { - c_mv->as_int = candidate_mi->mbmi.mv[FIRST_REF].as_int; + c_mv->as_int = candidate_mi->mbmi.mv[0].as_int; *c_ref_frame = candidate_mi->mbmi.ref_frame; ret_val = TRUE; // Is there a second non zero vector we can use. if ((candidate_mi->mbmi.second_ref_frame != INTRA_FRAME) && - (candidate_mi->mbmi.mv[SECOND_REF].as_int != 0) && - (candidate_mi->mbmi.mv[SECOND_REF].as_int != c_mv->as_int)) { - c2_mv->as_int = candidate_mi->mbmi.mv[SECOND_REF].as_int; + (candidate_mi->mbmi.mv[1].as_int != 0) && + (candidate_mi->mbmi.mv[1].as_int != c_mv->as_int)) { + c2_mv->as_int = candidate_mi->mbmi.mv[1].as_int; *c2_ref_frame = candidate_mi->mbmi.second_ref_frame; } // If only the second ref mv is valid:- (Should not trigger in current code // base given current possible compound prediction options). } else if (candidate_mi->mbmi.second_ref_frame != INTRA_FRAME) { - c_mv->as_int = candidate_mi->mbmi.mv[SECOND_REF].as_int; + c_mv->as_int = candidate_mi->mbmi.mv[1].as_int; *c_ref_frame = candidate_mi->mbmi.second_ref_frame; ret_val = TRUE; } diff --git a/vp8/common/mvref_common.h b/vp8/common/mvref_common.h index 33db7b7e2..3f19ddbdb 100644 --- a/vp8/common/mvref_common.h +++ b/vp8/common/mvref_common.h @@ -12,7 +12,7 @@ #include "blockd.h" // MR reference entropy header file. -#if CONFIG_NEW_MVREF +#if CONFIG_NEWBESTREFMV #ifndef __INC_MVREF_COMMON_H #define __INC_MVREF_COMMON_H diff --git a/vp8/decoder/decodemv.c b/vp8/decoder/decodemv.c index 403d13529..8d0f94e65 100644 --- a/vp8/decoder/decodemv.c +++ b/vp8/decoder/decodemv.c @@ -838,7 +838,6 @@ static void read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi, xd->pre.u_buffer = cm->yv12_fb[ref_fb_idx].u_buffer + recon_uvoffset; xd->pre.v_buffer = cm->yv12_fb[ref_fb_idx].v_buffer + recon_uvoffset; -#if CONFIG_NEW_MVREF // Update stats on relative distance of chosen vector to the // possible best reference vectors. { @@ -846,16 +845,11 @@ static void read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi, ref_frame, mbmi->ref_mvs[ref_frame], cm->ref_frame_sign_bias ); } -#endif vp8_find_best_ref_mvs(xd, xd->pre.y_buffer, recon_y_stride, -#if CONFIG_NEW_MVREF mbmi->ref_mvs[ref_frame], -#else - xd->ref_mv, -#endif &best_mv, &nearest, &nearby); } #endif @@ -938,7 +932,6 @@ static void read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi, mbmi->second_ref_frame, cm->ref_frame_sign_bias); -#if CONFIG_NEW_MVREF // Update stats on relative distance of chosen vector to the // possible best reference vectors. { @@ -948,16 +941,11 @@ static void read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi, ref_frame, mbmi->ref_mvs[ref_frame], cm->ref_frame_sign_bias ); } -#endif vp8_find_best_ref_mvs(xd, xd->second_pre.y_buffer, recon_y_stride, -#if CONFIG_NEW_MVREF mbmi->ref_mvs[mbmi->second_ref_frame], -#else - xd->ref_mv, -#endif &best_mv_second, &nearest_second, &nearby_second); diff --git a/vp8/encoder/bitstream.c b/vp8/encoder/bitstream.c index 7875cf93b..a4df16fee 100644 --- a/vp8/encoder/bitstream.c +++ b/vp8/encoder/bitstream.c @@ -29,7 +29,7 @@ #include "vp8/common/entropy.h" #include "vp8/encoder/encodemv.h" -#if CONFIG_NEW_MVREF +#if CONFIG_NEWBESTREFMV #include "vp8/common/mvref_common.h" #endif diff --git a/vp8/encoder/encodeframe.c b/vp8/encoder/encodeframe.c index 4670c314d..bbbbc7870 100644 --- a/vp8/encoder/encodeframe.c +++ b/vp8/encoder/encodeframe.c @@ -34,7 +34,7 @@ #include "vp8/common/pred_common.h" #define DBG_PRNT_SEGMAP 0 -#if CONFIG_NEW_MVREF +#if CONFIG_NEWBESTREFMV #include "vp8/common/mvref_common.h" #endif @@ -1304,7 +1304,6 @@ static void encode_frame_internal(VP8_COMP *cpi) { #if CONFIG_NEW_MVREF // temp stats reset - vp8_zero( cpi->mv_ref_sum_distance ); vp8_zero( cpi->best_ref_index_counts ); #endif diff --git a/vp8/encoder/onyx_if.c b/vp8/encoder/onyx_if.c index ea6e45d83..ca6570e68 100644 --- a/vp8/encoder/onyx_if.c +++ b/vp8/encoder/onyx_if.c @@ -40,7 +40,7 @@ #include "bitstream.h" #include "ratectrl.h" -#if CONFIG_NEW_MVREF +#if CONFIG_NEWBESTREFMV #include "vp8/common/mvref_common.h" #endif @@ -3874,25 +3874,10 @@ static void encode_frame_to_data_rate // in this frame. update_base_skip_probs(cpi); - -#if CONFIG_NEW_MVREF -#if 0 && CONFIG_INTERNAL_STATS +#if 0 //CONFIG_NEW_MVREF && CONFIG_INTERNAL_STATS { FILE *f = fopen("mv_ref_dist.stt", "a"); unsigned int i; - //fprintf(f, "%10d %10d %10d %10d %10d %10d %10d %10d %10d %10d\n", - /*fprintf(f, "%10d %10d %10d %10d %10d %10d %10d %10d %10d %10d", - cpi->common.current_video_frame, - cpi->mv_ref_sum_distance[1][0], - cpi->mv_ref_sum_distance[1][1], - cpi->mv_ref_sum_distance[1][2], - cpi->mv_ref_sum_distance[2][0], - cpi->mv_ref_sum_distance[2][1], - cpi->mv_ref_sum_distance[2][2], - cpi->mv_ref_sum_distance[3][0], - cpi->mv_ref_sum_distance[3][1], - cpi->mv_ref_sum_distance[3][2] );*/ - for (i = 0; i < MAX_MV_REFS; ++i) { fprintf(f, "%10d", cpi->best_ref_index_counts[i] ); } @@ -3901,8 +3886,6 @@ static void encode_frame_to_data_rate fclose(f); } #endif -#endif - #if 0// 1 && CONFIG_INTERNAL_STATS { diff --git a/vp8/encoder/onyx_int.h b/vp8/encoder/onyx_int.h index 0bdc07fc2..159cb8527 100644 --- a/vp8/encoder/onyx_int.h +++ b/vp8/encoder/onyx_int.h @@ -59,13 +59,6 @@ #define VP8_TEMPORAL_ALT_REF 1 -#if CONFIG_NEW_MVREF -// temp. relate to mv_ref_sum_distance stats -#define CUR_BEST 0 -#define NEW_BEST 1 -#define BEST_SELECTED 2 -#endif - typedef struct { #if CONFIG_NEWMVENTROPY nmv_context nmvc; @@ -771,9 +764,7 @@ typedef struct VP8_COMP { #endif #if CONFIG_NEW_MVREF - // temp stats [REF_FRAME]{REF_METHOD] - unsigned int mv_ref_sum_distance[4][3]; - unsigned int best_ref_index_counts[17]; + unsigned int best_ref_index_counts[MAX_MV_REFS]; #endif } VP8_COMP; diff --git a/vp8/encoder/rdopt.c b/vp8/encoder/rdopt.c index 673d631b1..a9a78e7e0 100644 --- a/vp8/encoder/rdopt.c +++ b/vp8/encoder/rdopt.c @@ -42,7 +42,7 @@ #include "vp8/common/seg_common.h" #include "vp8/common/pred_common.h" -#if CONFIG_NEW_MVREF +#if CONFIG_NEWBESTREFMV #include "vp8/common/mvref_common.h" #endif @@ -3045,7 +3045,6 @@ void setup_buffer_inter(VP8_COMP *cpi, MACROBLOCK *x, int idx, int frame_type, v_buffer[frame_type] = yv12->v_buffer + recon_uvoffset; #if CONFIG_NEWBESTREFMV -#if CONFIG_NEW_MVREF // Update stats on relative distance of chosen vector to the // possible best reference vectors. { @@ -3055,15 +3054,10 @@ void setup_buffer_inter(VP8_COMP *cpi, MACROBLOCK *x, int idx, int frame_type, mbmi->ref_mvs[frame_type], cpi->common.ref_frame_sign_bias ); } -#endif vp8_find_best_ref_mvs(xd, y_buffer[frame_type], yv12->y_stride, -#if CONFIG_NEW_MVREF mbmi->ref_mvs[frame_type], -#else - xd->ref_mv, -#endif &frame_best_ref_mv[frame_type], &frame_nearest_mv[frame_type], &frame_near_mv[frame_type]); @@ -3574,43 +3568,6 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int d->bmi.as_mv.first.as_int = tmp_mv.as_int; frame_mv[NEWMV][refs[0]].as_int = d->bmi.as_mv.first.as_int; -#if 0 //CONFIG_NEW_MVREF - // Update stats on relative distance of chosen vector to the - // possible best reference vectors. - { - unsigned int distance; - MV_REFERENCE_FRAME ref = mbmi->ref_frame; - int_mv selected_best_ref; - unsigned int best_index = 0; - - find_mv_refs(xd, xd->mode_info_context, - xd->prev_mode_info_context, - ref, - mbmi->ref_mvs[ref], - cpi->common.ref_frame_sign_bias ); - - distance = mv_distance(&tmp_mv, &best_ref_mv); - cpi->mv_ref_sum_distance[ref][CUR_BEST] += distance; - - distance = - mv_distance(&tmp_mv, - &mbmi->ref_mvs[ref][0]); - cpi->mv_ref_sum_distance[ref][NEW_BEST] += distance; - - best_index = pick_best_mv_ref(x, tmp_mv, mbmi->ref_mvs[ref], - &selected_best_ref); - - distance = mv_distance(&tmp_mv, &selected_best_ref); - mbmi->mv_ref_index[ref] = best_index; - cpi->mv_ref_sum_distance[ref][BEST_SELECTED] += distance; - cpi->best_ref_index_counts[best_index]++; - - // Temp - //mbmi->mv_ref_index[ref] = 0; - //mbmi->ref_mvs[ref][0].as_int = best_ref_mv.as_int; - } -#endif - // Add the new motion vector cost to our rolling cost variable rate2 += vp8_mv_bit_cost(&tmp_mv, &best_ref_mv, XMVCOST, 96, -- cgit v1.2.3