Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(794)

Unified Diff: libvpx/source/libvpx/vp8/encoder/rdopt.c

Issue 7624054: Revert r97185 "Update libvpx snapshot to v0.9.7-p1 (Cayuga)." (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « libvpx/source/libvpx/vp8/encoder/rdopt.h ('k') | libvpx/source/libvpx/vp8/encoder/sad_c.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: libvpx/source/libvpx/vp8/encoder/rdopt.c
diff --git a/libvpx/source/libvpx/vp8/encoder/rdopt.c b/libvpx/source/libvpx/vp8/encoder/rdopt.c
index 992df71c29e83ff6924a90e34c889dcb8ddd1559..a125cc4819f2615bc11dc409aa32d46cdf64598d 100644
--- a/libvpx/source/libvpx/vp8/encoder/rdopt.c
+++ b/libvpx/source/libvpx/vp8/encoder/rdopt.c
@@ -31,7 +31,7 @@
#include "vp8/common/g_common.h"
#include "variance.h"
#include "mcomp.h"
-#include "rdopt.h"
+
#include "vpx_mem/vpx_mem.h"
#include "dct.h"
#include "vp8/common/systemdependent.h"
@@ -46,8 +46,13 @@
extern void vp8cx_mb_init_quantizer(VP8_COMP *cpi, MACROBLOCK *x);
extern void vp8_update_zbin_extra(VP8_COMP *cpi, MACROBLOCK *x);
+
+#define RDCOST(RM,DM,R,D) ( ((128+(R)*(RM)) >> 8) + (DM)*(D) )
+
#define MAXF(a,b) (((a) > (b)) ? (a) : (b))
+
+
static const int auto_speed_thresh[17] =
{
1000,
@@ -134,8 +139,8 @@ const MV_REFERENCE_FRAME vp8_ref_frame_order[MAX_MODES] =
};
static void fill_token_costs(
- unsigned int c [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS],
- const vp8_prob p [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES]
+ unsigned int c [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [vp8_coef_tokens],
+ const vp8_prob p [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [vp8_coef_tokens-1]
)
{
int i, j, k;
@@ -155,44 +160,45 @@ static int rd_iifactor [ 32 ] = { 4, 4, 3, 2, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
+
/* values are now correlated to quantizer */
static int sad_per_bit16lut[QINDEX_RANGE] =
{
- 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2,
- 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 3, 4, 4,
- 4, 4, 4, 4, 4, 4, 4, 4,
- 4, 4, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 6, 6,
- 6, 6, 6, 6, 6, 6, 6, 6,
- 6, 6, 7, 7, 7, 7, 7, 7,
- 7, 7, 7, 7, 7, 7, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 9, 9, 9, 9, 9, 9,
- 9, 9, 9, 9, 9, 9, 10, 10,
- 10, 10, 10, 10, 10, 10, 11, 11,
- 11, 11, 11, 11, 12, 12, 12, 12,
- 12, 12, 13, 13, 13, 13, 14, 14
+ 6, 6, 6, 6, 6, 7, 7, 7,
+ 7, 7, 7, 7, 8, 8, 8, 8,
+ 8, 8, 8, 8, 8, 8, 9, 9,
+ 9, 9, 9, 9, 10, 10, 10, 10,
+ 10, 10, 11, 11, 11, 11, 11, 11,
+ 12, 12, 12, 12, 12, 12, 12, 13,
+ 13, 13, 13, 13, 13, 14, 14, 14,
+ 14, 14, 15, 15, 15, 15, 15, 15,
+ 16, 16, 16, 16, 16, 16, 17, 17,
+ 17, 17, 17, 17, 17, 18, 18, 18,
+ 18, 18, 19, 19, 19, 19, 19, 19,
+ 20, 20, 20, 21, 21, 21, 21, 22,
+ 22, 22, 23, 23, 23, 24, 24, 24,
+ 25, 25, 26, 26, 27, 27, 27, 28,
+ 28, 28, 29, 29, 30, 30, 31, 31
};
static int sad_per_bit4lut[QINDEX_RANGE] =
{
- 2, 2, 2, 2, 2, 2, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 4, 4, 4, 4,
- 4, 4, 4, 4, 4, 4, 5, 5,
- 5, 5, 5, 5, 6, 6, 6, 6,
- 6, 6, 6, 6, 6, 6, 6, 6,
- 7, 7, 7, 7, 7, 7, 7, 7,
+ 5, 5, 5, 5, 5, 5, 7, 7,
7, 7, 7, 7, 7, 8, 8, 8,
- 8, 8, 9, 9, 9, 9, 9, 9,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 11, 11, 11, 11, 11, 11, 11, 11,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 13, 13, 13, 13, 13, 13, 13, 14,
- 14, 14, 14, 14, 15, 15, 15, 15,
- 16, 16, 16, 16, 17, 17, 17, 18,
- 18, 18, 19, 19, 19, 20, 20, 20,
+ 8, 8, 8, 8, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 11, 11,
+ 11, 11, 11, 11, 13, 13, 13, 13,
+ 13, 13, 14, 14, 14, 14, 14, 14,
+ 16, 16, 16, 16, 16, 16, 16, 17,
+ 17, 17, 17, 17, 17, 19, 19, 19,
+ 19, 19, 20, 20, 20, 20, 20, 20,
+ 22, 22, 22, 22, 22, 22, 23, 23,
+ 23, 23, 23, 23, 23, 25, 25, 25,
+ 25, 25, 26, 26, 26, 26, 26, 26,
+ 28, 28, 28, 29, 29, 29, 29, 31,
+ 31, 31, 32, 32, 32, 34, 34, 34,
+ 35, 35, 37, 37, 38, 38, 38, 40,
+ 40, 40, 41, 41, 43, 43, 44, 44,
};
void vp8cx_initialize_me_consts(VP8_COMP *cpi, int QIndex)
@@ -206,7 +212,7 @@ void vp8_initialize_rd_consts(VP8_COMP *cpi, int Qvalue)
int q;
int i;
double capped_q = (Qvalue < 160) ? (double)Qvalue : 160.0;
- double rdconst = 2.70;
+ double rdconst = 3.00;
vp8_clear_system_state(); //__asm emms;
@@ -231,18 +237,20 @@ void vp8_initialize_rd_consts(VP8_COMP *cpi, int Qvalue)
if (cpi->pass == 2 && (cpi->common.frame_type != KEY_FRAME))
{
- if (cpi->twopass.next_iiratio > 31)
+ if (cpi->next_iiratio > 31)
cpi->RDMULT += (cpi->RDMULT * rd_iifactor[31]) >> 4;
else
- cpi->RDMULT +=
- (cpi->RDMULT * rd_iifactor[cpi->twopass.next_iiratio]) >> 4;
+ cpi->RDMULT += (cpi->RDMULT * rd_iifactor[cpi->next_iiratio]) >> 4;
}
- cpi->mb.errorperbit = (cpi->RDMULT / 110);
+ cpi->mb.errorperbit = (cpi->RDMULT / 100);
cpi->mb.errorperbit += (cpi->mb.errorperbit==0);
vp8_set_speed_features(cpi);
+ if (cpi->common.simpler_lpf)
+ cpi->common.filter_type = SIMPLE_LOOPFILTER;
+
q = (int)pow(Qvalue, 1.25);
if (q < 8)
@@ -297,6 +305,8 @@ void vp8_initialize_rd_consts(VP8_COMP *cpi, int Qvalue)
void vp8_auto_select_speed(VP8_COMP *cpi)
{
+ int used = cpi->oxcf.cpu_used;
+
int milliseconds_for_compress = (int)(1000000 / cpi->oxcf.frame_rate);
milliseconds_for_compress = milliseconds_for_compress * (16 - cpi->oxcf.cpu_used) / 16;
@@ -317,10 +327,10 @@ void vp8_auto_select_speed(VP8_COMP *cpi)
/*
// this is done during parameter valid check
- if( cpi->oxcf.cpu_used > 16)
- cpi->oxcf.cpu_used = 16;
- if( cpi->oxcf.cpu_used < -16)
- cpi->oxcf.cpu_used = -16;
+ if( used > 16)
+ used = 16;
+ if( used < -16)
+ used = -16;
*/
if (cpi->avg_pick_mode_time < milliseconds_for_compress && (cpi->avg_encode_time - cpi->avg_pick_mode_time) < milliseconds_for_compress)
@@ -455,24 +465,22 @@ int VP8_UVSSE(MACROBLOCK *x, const vp8_variance_rtcd_vtable_t *rtcd)
if ((mv_row | mv_col) & 7)
{
- VARIANCE_INVOKE(rtcd, subpixvar8x8)(uptr, pre_stride,
- mv_col & 7, mv_row & 7, upred_ptr, uv_stride, &sse2);
- VARIANCE_INVOKE(rtcd, subpixvar8x8)(vptr, pre_stride,
- mv_col & 7, mv_row & 7, vpred_ptr, uv_stride, &sse1);
+ VARIANCE_INVOKE(rtcd, subpixvar8x8)(uptr, pre_stride, mv_col & 7, mv_row & 7, upred_ptr, uv_stride, &sse2);
+ VARIANCE_INVOKE(rtcd, subpixvar8x8)(vptr, pre_stride, mv_col & 7, mv_row & 7, vpred_ptr, uv_stride, &sse1);
sse2 += sse1;
}
else
{
- VARIANCE_INVOKE(rtcd, var8x8)(uptr, pre_stride,
- upred_ptr, uv_stride, &sse2);
- VARIANCE_INVOKE(rtcd, var8x8)(vptr, pre_stride,
- vpred_ptr, uv_stride, &sse1);
+ VARIANCE_INVOKE(rtcd, subpixvar8x8)(uptr, pre_stride, mv_col & 7, mv_row & 7, upred_ptr, uv_stride, &sse2);
+ VARIANCE_INVOKE(rtcd, subpixvar8x8)(vptr, pre_stride, mv_col & 7, mv_row & 7, vpred_ptr, uv_stride, &sse1);
sse2 += sse1;
}
+
return sse2;
}
+#if !(CONFIG_REALTIME_ONLY)
static int cost_coeffs(MACROBLOCK *mb, BLOCKD *b, int type, ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l)
{
int c = !type; /* start at coef 0, unless Y with Y2 */
@@ -543,8 +551,8 @@ static void macro_block_yrd( MACROBLOCK *mb,
BLOCK *beptr;
int d;
- ENCODEMB_INVOKE(rtcd, submby)( mb->src_diff, *(mb->block[0].base_src),
- mb->e_mbd.predictor, mb->block[0].src_stride );
+ ENCODEMB_INVOKE(rtcd, submby)( mb->src_diff, mb->src.y_buffer,
+ mb->e_mbd.predictor, mb->src.y_stride );
// Fdct and building the 2nd order block
for (beptr = mb->block; beptr < mb->block + 16; beptr += 2)
@@ -621,8 +629,7 @@ static int rd_pick_intra4x4block(
rate = bmode_costs[mode];
- RECON_INVOKE(&cpi->rtcd.common->recon, intra4x4_predict)
- (b, mode, b->predictor);
+ vp8_predict_intra4x4(b, mode, b->predictor);
ENCODEMB_INVOKE(IF_RTCD(&cpi->rtcd.encodemb), subb)(be, b, 16);
x->vp8_short_fdct4x4(be->src_diff, be->coeff, 32);
x->quantize_b(be, b);
@@ -649,7 +656,8 @@ static int rd_pick_intra4x4block(
vpx_memcpy(best_dqcoeff, b->dqcoeff, 32);
}
}
- b->bmi.as_mode = (B_PREDICTION_MODE)(*best_mode);
+
+ b->bmi.mode = (B_PREDICTION_MODE)(*best_mode);
IDCT_INVOKE(IF_RTCD(&cpi->rtcd.common->idct), idct16)(best_dqcoeff, b->diff, 32);
RECON_INVOKE(IF_RTCD(&cpi->rtcd.common->recon), recon)(best_predictor, b->diff, *(b->base_dst) + b->dst, b->dst_stride);
@@ -657,15 +665,15 @@ static int rd_pick_intra4x4block(
return best_rd;
}
-static int rd_pick_intra4x4mby_modes(VP8_COMP *cpi, MACROBLOCK *mb, int *Rate,
- int *rate_y, int *Distortion, int best_rd)
+int vp8_rd_pick_intra4x4mby_modes(VP8_COMP *cpi, MACROBLOCK *mb, int *Rate,
+ int *rate_y, int *Distortion, int best_rd)
{
MACROBLOCKD *const xd = &mb->e_mbd;
int i;
int cost = mb->mbmode_cost [xd->frame_type] [B_PRED];
int distortion = 0;
int tot_rate_y = 0;
- int64_t total_rd = 0;
+ long long total_rd = 0;
ENTROPY_CONTEXT_PLANES t_above, t_left;
ENTROPY_CONTEXT *ta;
ENTROPY_CONTEXT *tl;
@@ -690,8 +698,8 @@ static int rd_pick_intra4x4mby_modes(VP8_COMP *cpi, MACROBLOCK *mb, int *Rate,
if (mb->e_mbd.frame_type == KEY_FRAME)
{
- const B_PREDICTION_MODE A = above_block_mode(mic, i, mis);
- const B_PREDICTION_MODE L = left_block_mode(mic, i);
+ const B_PREDICTION_MODE A = vp8_above_bmi(mic, i, mis)->mode;
+ const B_PREDICTION_MODE L = vp8_left_bmi(mic, i)->mode;
bmode_costs = mb->bmode_costs[A][L];
}
@@ -704,14 +712,13 @@ static int rd_pick_intra4x4mby_modes(VP8_COMP *cpi, MACROBLOCK *mb, int *Rate,
cost += r;
distortion += d;
tot_rate_y += ry;
+ mic->bmi[i].mode = xd->block[i].bmi.mode = best_mode;
- mic->bmi[i].as_mode = best_mode;
-
- if(total_rd >= (int64_t)best_rd)
+ if(total_rd >= (long long)best_rd)
break;
}
- if(total_rd >= (int64_t)best_rd)
+ if(total_rd >= (long long)best_rd)
return INT_MAX;
*Rate = cost;
@@ -720,13 +727,11 @@ static int rd_pick_intra4x4mby_modes(VP8_COMP *cpi, MACROBLOCK *mb, int *Rate,
return RDCOST(mb->rdmult, mb->rddiv, cost, distortion);
}
-
-
-static int rd_pick_intra16x16mby_mode(VP8_COMP *cpi,
- MACROBLOCK *x,
- int *Rate,
- int *rate_y,
- int *Distortion)
+int vp8_rd_pick_intra16x16mby_mode(VP8_COMP *cpi,
+ MACROBLOCK *x,
+ int *Rate,
+ int *rate_y,
+ int *Distortion)
{
MB_PREDICTION_MODE mode;
MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected);
@@ -798,7 +803,7 @@ static int vp8_rd_inter_uv(VP8_COMP *cpi, MACROBLOCK *x, int *rate, int *distort
return RDCOST(x->rdmult, x->rddiv, *rate, *distortion);
}
-static void rd_pick_intra_mbuv_mode(VP8_COMP *cpi, MACROBLOCK *x, int *rate, int *rate_tokenonly, int *distortion)
+int vp8_rd_pick_intra_mbuv_mode(VP8_COMP *cpi, MACROBLOCK *x, int *rate, int *rate_tokenonly, int *distortion)
{
MB_PREDICTION_MODE mode;
MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected);
@@ -813,8 +818,7 @@ static void rd_pick_intra_mbuv_mode(VP8_COMP *cpi, MACROBLOCK *x, int *rate, int
int this_rd;
x->e_mbd.mode_info_context->mbmi.uv_mode = mode;
- RECON_INVOKE(&cpi->rtcd.common->recon, build_intra_predictors_mbuv)
- (&x->e_mbd);
+ vp8_build_intra_predictors_mbuv(&x->e_mbd);
ENCODEMB_INVOKE(IF_RTCD(&cpi->rtcd.encodemb), submbuv)(x->src_diff,
x->src.u_buffer, x->src.v_buffer, x->e_mbd.predictor,
x->src.uv_stride);
@@ -842,7 +846,9 @@ static void rd_pick_intra_mbuv_mode(VP8_COMP *cpi, MACROBLOCK *x, int *rate, int
*distortion = d;
x->e_mbd.mode_info_context->mbmi.uv_mode = mode_selected;
+ return best_rd;
}
+#endif
int vp8_cost_mv_ref(MB_PREDICTION_MODE m, const int near_mv_ref_ct[4])
{
@@ -853,17 +859,29 @@ int vp8_cost_mv_ref(MB_PREDICTION_MODE m, const int near_mv_ref_ct[4])
vp8_mv_ref_encoding_array - NEARESTMV + m);
}
-void vp8_set_mbmode_and_mvs(MACROBLOCK *x, MB_PREDICTION_MODE mb, int_mv *mv)
+void vp8_set_mbmode_and_mvs(MACROBLOCK *x, MB_PREDICTION_MODE mb, MV *mv)
{
+ int i;
+
x->e_mbd.mode_info_context->mbmi.mode = mb;
- x->e_mbd.mode_info_context->mbmi.mv.as_int = mv->as_int;
+ x->e_mbd.mode_info_context->mbmi.mv.as_mv.row = mv->row;
+ x->e_mbd.mode_info_context->mbmi.mv.as_mv.col = mv->col;
+
+ for (i = 0; i < 16; i++)
+ {
+ B_MODE_INFO *bmi = &x->e_mbd.block[i].bmi;
+ bmi->mode = (B_PREDICTION_MODE) mb;
+ bmi->mv.as_mv.row = mv->row;
+ bmi->mv.as_mv.col = mv->col;
+ }
}
+#if !(CONFIG_REALTIME_ONLY)
static int labels2mode(
MACROBLOCK *x,
int const *labelings, int which_label,
B_PREDICTION_MODE this_mode,
- int_mv *this_mv, int_mv *best_ref_mv,
+ MV *this_mv, MV *best_ref_mv,
int *mvcost[2]
)
{
@@ -904,13 +922,13 @@ static int labels2mode(
thismvcost = vp8_mv_bit_cost(this_mv, best_ref_mv, mvcost, 102);
break;
case LEFT4X4:
- this_mv->as_int = col ? d[-1].bmi.mv.as_int : left_block_mv(mic, i);
+ *this_mv = col ? d[-1].bmi.mv.as_mv : vp8_left_bmi(mic, i)->mv.as_mv;
break;
case ABOVE4X4:
- this_mv->as_int = row ? d[-4].bmi.mv.as_int : above_block_mv(mic, i, mis);
+ *this_mv = row ? d[-4].bmi.mv.as_mv : vp8_above_bmi(mic, i, mis)->mv.as_mv;
break;
case ZERO4X4:
- this_mv->as_int = 0;
+ this_mv->row = this_mv->col = 0;
break;
default:
break;
@@ -918,22 +936,17 @@ static int labels2mode(
if (m == ABOVE4X4) // replace above with left if same
{
- int_mv left_mv;
-
- left_mv.as_int = col ? d[-1].bmi.mv.as_int :
- left_block_mv(mic, i);
+ const MV mv = col ? d[-1].bmi.mv.as_mv : vp8_left_bmi(mic, i)->mv.as_mv;
- if (left_mv.as_int == this_mv->as_int)
+ if (mv.row == this_mv->row && mv.col == this_mv->col)
m = LEFT4X4;
}
cost = x->inter_bmode_costs[ m];
}
- d->bmi.mv.as_int = this_mv->as_int;
-
- x->partition_info->bmi[i].mode = m;
- x->partition_info->bmi[i].mv.as_int = this_mv->as_int;
+ d->bmi.mode = m;
+ d->bmi.mv.as_mv = *this_mv;
}
while (++i < 16);
@@ -993,8 +1006,8 @@ static const unsigned int segmentation_to_sseshift[4] = {3, 3, 2, 0};
typedef struct
{
- int_mv *ref_mv;
- int_mv mvp;
+ MV *ref_mv;
+ MV *mvp;
int segment_rd;
int segment_num;
@@ -1008,7 +1021,7 @@ typedef struct
int mvthresh;
int *mdcounts;
- int_mv sv_mvp[4]; // save 4 mvp from 8x8
+ MV sv_mvp[4]; // save 4 mvp from 8x8
int sv_istep[2]; // save 2 initial step_param for 16x8/8x16
} BEST_SEG_INFO;
@@ -1070,7 +1083,7 @@ static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
for (i = 0; i < label_count; i++)
{
- int_mv mode_mv[B_MODE_COUNT];
+ MV mode_mv[B_MODE_COUNT];
int best_label_rd = INT_MAX;
B_PREDICTION_MODE mode_selected = ZERO4X4;
int bestlabelyrate = 0;
@@ -1100,7 +1113,7 @@ static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
int n;
int thissme;
int bestsme = INT_MAX;
- int_mv temp_mv;
+ MV temp_mv;
BLOCK *c;
BLOCKD *e;
@@ -1112,9 +1125,8 @@ static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
{
if (segmentation == BLOCK_8X16 || segmentation == BLOCK_16X8)
{
- bsi->mvp.as_int = bsi->sv_mvp[i].as_int;
- if (i==1 && segmentation == BLOCK_16X8)
- bsi->mvp.as_int = bsi->sv_mvp[2].as_int;
+ bsi->mvp = &bsi->sv_mvp[i];
+ if (i==1 && segmentation == BLOCK_16X8) bsi->mvp = &bsi->sv_mvp[2];
step_param = bsi->sv_istep[i];
}
@@ -1122,9 +1134,8 @@ static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
// use previous block's result as next block's MV predictor.
if (segmentation == BLOCK_4X4 && i>0)
{
- bsi->mvp.as_int = x->e_mbd.block[i-1].bmi.mv.as_int;
- if (i==4 || i==8 || i==12)
- bsi->mvp.as_int = x->e_mbd.block[i-4].bmi.mv.as_int;
+ bsi->mvp = &(x->e_mbd.block[i-1].bmi.mv.as_mv);
+ if (i==4 || i==8 || i==12) bsi->mvp = &(x->e_mbd.block[i-4].bmi.mv.as_mv);
step_param = 2;
}
}
@@ -1133,10 +1144,6 @@ static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
{
int sadpb = x->sadperbit4;
- int_mv mvp_full;
-
- mvp_full.as_mv.row = bsi->mvp.as_mv.row >>3;
- mvp_full.as_mv.col = bsi->mvp.as_mv.col >>3;
// find first label
n = vp8_mbsplit_offset[segmentation][i];
@@ -1144,11 +1151,15 @@ static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
c = &x->block[n];
e = &x->e_mbd.block[n];
+ if (cpi->sf.search_method == HEX)
+ bestsme = vp8_hex_search(x, c, e, bsi->ref_mv,
+ &mode_mv[NEW4X4], step_param, sadpb, &num00, v_fn_ptr, x->mvsadcost, x->mvcost, bsi->ref_mv);
+
+ else
{
- bestsme = cpi->diamond_search_sad(x, c, e, &mvp_full,
- &mode_mv[NEW4X4], step_param,
- sadpb, &num00, v_fn_ptr,
- x->mvcost, bsi->ref_mv);
+ bestsme = cpi->diamond_search_sad(x, c, e, bsi->mvp,
+ &mode_mv[NEW4X4], step_param,
+ sadpb / 2, &num00, v_fn_ptr, x->mvsadcost, x->mvcost, bsi->ref_mv);
n = num00;
num00 = 0;
@@ -1161,16 +1172,15 @@ static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
num00--;
else
{
- thissme = cpi->diamond_search_sad(x, c, e,
- &mvp_full, &temp_mv,
- step_param + n, sadpb,
- &num00, v_fn_ptr,
- x->mvcost, bsi->ref_mv);
+ thissme = cpi->diamond_search_sad(x, c, e, bsi->mvp,
+ &temp_mv, step_param + n,
+ sadpb / 2, &num00, v_fn_ptr, x->mvsadcost, x->mvcost, bsi->ref_mv);
if (thissme < bestsme)
{
bestsme = thissme;
- mode_mv[NEW4X4].as_int = temp_mv.as_int;
+ mode_mv[NEW4X4].row = temp_mv.row;
+ mode_mv[NEW4X4].col = temp_mv.col;
}
}
}
@@ -1181,34 +1191,30 @@ static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
// Should we do a full search (best quality only)
if ((cpi->compressor_speed == 0) && (bestsme >> sseshift) > 4000)
{
- /* Check if mvp_full is within the range. */
- vp8_clamp_mv(&mvp_full, x->mv_col_min, x->mv_col_max, x->mv_row_min, x->mv_row_max);
-
- thissme = cpi->full_search_sad(x, c, e, &mvp_full,
- sadpb, 16, v_fn_ptr,
- x->mvcost, bsi->ref_mv);
+ thissme = cpi->full_search_sad(x, c, e, bsi->mvp,
+ sadpb / 4, 16, v_fn_ptr, x->mvcost, x->mvsadcost,bsi->ref_mv);
if (thissme < bestsme)
{
bestsme = thissme;
- mode_mv[NEW4X4].as_int = e->bmi.mv.as_int;
+ mode_mv[NEW4X4] = e->bmi.mv.as_mv;
}
else
{
// The full search result is actually worse so re-instate the previous best vector
- e->bmi.mv.as_int = mode_mv[NEW4X4].as_int;
+ e->bmi.mv.as_mv = mode_mv[NEW4X4];
}
}
}
if (bestsme < INT_MAX)
{
- int distortion;
- unsigned int sse;
- cpi->find_fractional_mv_step(x, c, e, &mode_mv[NEW4X4],
- bsi->ref_mv, x->errorperbit, v_fn_ptr, x->mvcost,
- &distortion, &sse);
-
+ if (!cpi->common.full_pixel)
+ cpi->find_fractional_mv_step(x, c, e, &mode_mv[NEW4X4],
+ bsi->ref_mv, x->errorperbit / 2, v_fn_ptr, x->mvcost);
+ else
+ vp8_skip_fractional_mv_step(x, c, e, &mode_mv[NEW4X4],
+ bsi->ref_mv, x->errorperbit, v_fn_ptr, x->mvcost);
}
} /* NEW4X4 */
@@ -1216,8 +1222,8 @@ static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
bsi->ref_mv, x->mvcost);
// Trap vectors that reach beyond the UMV borders
- if (((mode_mv[this_mode].as_mv.row >> 3) < x->mv_row_min) || ((mode_mv[this_mode].as_mv.row >> 3) > x->mv_row_max) ||
- ((mode_mv[this_mode].as_mv.col >> 3) < x->mv_col_min) || ((mode_mv[this_mode].as_mv.col >> 3) > x->mv_col_max))
+ if (((mode_mv[this_mode].row >> 3) < x->mv_row_min) || ((mode_mv[this_mode].row >> 3) > x->mv_row_max) ||
+ ((mode_mv[this_mode].col >> 3) < x->mv_col_min) || ((mode_mv[this_mode].col >> 3) > x->mv_col_max))
{
continue;
}
@@ -1272,8 +1278,8 @@ static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
{
BLOCKD *bd = &x->e_mbd.block[i];
- bsi->mvs[i].as_mv = x->partition_info->bmi[i].mv.as_mv;
- bsi->modes[i] = x->partition_info->bmi[i].mode;
+ bsi->mvs[i].as_mv = bd->bmi.mv.as_mv;
+ bsi->modes[i] = bd->bmi.mode;
bsi->eobs[i] = bd->eob;
}
}
@@ -1294,7 +1300,7 @@ void vp8_cal_step_param(int sr, int *sp)
}
static int vp8_rd_pick_best_mbsegmentation(VP8_COMP *cpi, MACROBLOCK *x,
- int_mv *best_ref_mv, int best_rd,
+ MV *best_ref_mv, int best_rd,
int *mdcounts, int *returntotrate,
int *returnyrate, int *returndistortion,
int mvthresh)
@@ -1306,7 +1312,7 @@ static int vp8_rd_pick_best_mbsegmentation(VP8_COMP *cpi, MACROBLOCK *x,
bsi.segment_rd = best_rd;
bsi.ref_mv = best_ref_mv;
- bsi.mvp.as_int = best_ref_mv->as_int;
+ bsi.mvp = best_ref_mv;
bsi.mvthresh = mvthresh;
bsi.mdcounts = mdcounts;
@@ -1332,10 +1338,10 @@ static int vp8_rd_pick_best_mbsegmentation(VP8_COMP *cpi, MACROBLOCK *x,
if (bsi.segment_rd < best_rd)
{
- int col_min = (best_ref_mv->as_mv.col>>3) - MAX_FULL_PEL_VAL + ((best_ref_mv->as_mv.col & 7)?1:0);
- int row_min = (best_ref_mv->as_mv.row>>3) - MAX_FULL_PEL_VAL + ((best_ref_mv->as_mv.row & 7)?1:0);
- int col_max = (best_ref_mv->as_mv.col>>3) + MAX_FULL_PEL_VAL;
- int row_max = (best_ref_mv->as_mv.row>>3) + MAX_FULL_PEL_VAL;
+ 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;
@@ -1353,18 +1359,18 @@ static int vp8_rd_pick_best_mbsegmentation(VP8_COMP *cpi, MACROBLOCK *x,
x->mv_row_max = row_max;
/* Get 8x8 result */
- bsi.sv_mvp[0].as_int = bsi.mvs[0].as_int;
- bsi.sv_mvp[1].as_int = bsi.mvs[2].as_int;
- bsi.sv_mvp[2].as_int = bsi.mvs[8].as_int;
- bsi.sv_mvp[3].as_int = bsi.mvs[10].as_int;
+ bsi.sv_mvp[0] = bsi.mvs[0].as_mv;
+ bsi.sv_mvp[1] = bsi.mvs[2].as_mv;
+ bsi.sv_mvp[2] = bsi.mvs[8].as_mv;
+ bsi.sv_mvp[3] = bsi.mvs[10].as_mv;
/* Use 8x8 result as 16x8/8x16's predictor MV. Adjust search range according to the closeness of 2 MV. */
/* block 8X16 */
{
- sr = MAXF((abs(bsi.sv_mvp[0].as_mv.row - bsi.sv_mvp[2].as_mv.row))>>3, (abs(bsi.sv_mvp[0].as_mv.col - bsi.sv_mvp[2].as_mv.col))>>3);
+ sr = MAXF((abs(bsi.sv_mvp[0].row - bsi.sv_mvp[2].row))>>3, (abs(bsi.sv_mvp[0].col - bsi.sv_mvp[2].col))>>3);
vp8_cal_step_param(sr, &bsi.sv_istep[0]);
- sr = MAXF((abs(bsi.sv_mvp[1].as_mv.row - bsi.sv_mvp[3].as_mv.row))>>3, (abs(bsi.sv_mvp[1].as_mv.col - bsi.sv_mvp[3].as_mv.col))>>3);
+ sr = MAXF((abs(bsi.sv_mvp[1].row - bsi.sv_mvp[3].row))>>3, (abs(bsi.sv_mvp[1].col - bsi.sv_mvp[3].col))>>3);
vp8_cal_step_param(sr, &bsi.sv_istep[1]);
rd_check_segment(cpi, x, &bsi, BLOCK_8X16);
@@ -1372,10 +1378,10 @@ static int vp8_rd_pick_best_mbsegmentation(VP8_COMP *cpi, MACROBLOCK *x,
/* block 16X8 */
{
- sr = MAXF((abs(bsi.sv_mvp[0].as_mv.row - bsi.sv_mvp[1].as_mv.row))>>3, (abs(bsi.sv_mvp[0].as_mv.col - bsi.sv_mvp[1].as_mv.col))>>3);
+ sr = MAXF((abs(bsi.sv_mvp[0].row - bsi.sv_mvp[1].row))>>3, (abs(bsi.sv_mvp[0].col - bsi.sv_mvp[1].col))>>3);
vp8_cal_step_param(sr, &bsi.sv_istep[0]);
- sr = MAXF((abs(bsi.sv_mvp[2].as_mv.row - bsi.sv_mvp[3].as_mv.row))>>3, (abs(bsi.sv_mvp[2].as_mv.col - bsi.sv_mvp[3].as_mv.col))>>3);
+ sr = MAXF((abs(bsi.sv_mvp[2].row - bsi.sv_mvp[3].row))>>3, (abs(bsi.sv_mvp[2].col - bsi.sv_mvp[3].col))>>3);
vp8_cal_step_param(sr, &bsi.sv_istep[1]);
rd_check_segment(cpi, x, &bsi, BLOCK_16X8);
@@ -1385,7 +1391,7 @@ static int vp8_rd_pick_best_mbsegmentation(VP8_COMP *cpi, MACROBLOCK *x,
/* Not skip 4x4 if speed=0 (good quality) */
if (cpi->sf.no_skip_block4x4_search || bsi.segment_num == BLOCK_8X8) /* || (sv_segment_rd8x8-bsi.segment_rd) < sv_segment_rd8x8>>5) */
{
- bsi.mvp.as_int = bsi.sv_mvp[0].as_int;
+ bsi.mvp = &bsi.sv_mvp[0];
rd_check_segment(cpi, x, &bsi, BLOCK_4X4);
}
@@ -1402,7 +1408,8 @@ static int vp8_rd_pick_best_mbsegmentation(VP8_COMP *cpi, MACROBLOCK *x,
{
BLOCKD *bd = &x->e_mbd.block[i];
- bd->bmi.mv.as_int = bsi.mvs[i].as_int;
+ bd->bmi.mv.as_mv = bsi.mvs[i].as_mv;
+ bd->bmi.mode = bsi.modes[i];
bd->eob = bsi.eobs[i];
}
@@ -1420,66 +1427,94 @@ static int vp8_rd_pick_best_mbsegmentation(VP8_COMP *cpi, MACROBLOCK *x,
j = vp8_mbsplit_offset[bsi.segment_num][i];
- x->partition_info->bmi[i].mode = bsi.modes[j];
- x->partition_info->bmi[i].mv.as_mv = bsi.mvs[j].as_mv;
+ x->partition_info->bmi[i].mode = x->e_mbd.block[j].bmi.mode;
+ x->partition_info->bmi[i].mv.as_mv = x->e_mbd.block[j].bmi.mv.as_mv;
}
- /*
- * used to set x->e_mbd.mode_info_context->mbmi.mv.as_int
- */
- x->partition_info->bmi[15].mv.as_int = bsi.mvs[15].as_int;
return bsi.segment_rd;
}
+#endif
-static void insertsortmv(int arr[], int len)
+static void swap(int *x,int *y)
{
- int i, j, k;
+ int tmp;
- for ( i = 1 ; i <= len-1 ; i++ )
- {
- for ( j = 0 ; j < i ; j++ )
- {
- if ( arr[j] > arr[i] )
- {
- int temp;
-
- temp = arr[i];
-
- for ( k = i; k >j; k--)
- arr[k] = arr[k - 1] ;
-
- arr[j] = temp ;
- }
- }
- }
+ tmp = *x;
+ *x = *y;
+ *y = tmp;
}
-static void insertsortsad(int arr[],int idx[], int len)
+static void quicksortmv(int arr[],int left, int right)
{
- int i, j, k;
-
- for ( i = 1 ; i <= len-1 ; i++ )
- {
- for ( j = 0 ; j < i ; j++ )
- {
- if ( arr[j] > arr[i] )
- {
- int temp, tempi;
-
- temp = arr[i];
- tempi = idx[i];
-
- for ( k = i; k >j; k--)
- {
- arr[k] = arr[k - 1] ;
- idx[k] = idx[k - 1];
- }
+ int lidx,ridx,pivot;
+
+ lidx = left;
+ ridx = right;
+
+ if( left < right)
+ {
+ pivot = (left + right)/2;
+
+ while(lidx <=pivot && ridx >=pivot)
+ {
+ while(arr[lidx] < arr[pivot] && lidx <= pivot)
+ lidx++;
+ while(arr[ridx] > arr[pivot] && ridx >= pivot)
+ ridx--;
+ swap(&arr[lidx], &arr[ridx]);
+ lidx++;
+ ridx--;
+ if(lidx-1 == pivot)
+ {
+ ridx++;
+ pivot = ridx;
+ }
+ else if(ridx+1 == pivot)
+ {
+ lidx--;
+ pivot = lidx;
+ }
+ }
+ quicksortmv(arr, left, pivot - 1);
+ quicksortmv(arr, pivot + 1, right);
+ }
+}
- arr[j] = temp ;
- idx[j] = tempi;
- }
- }
- }
+static void quicksortsad(int arr[],int idx[], int left, int right)
+{
+ int lidx,ridx,pivot;
+
+ lidx = left;
+ ridx = right;
+
+ if( left < right)
+ {
+ pivot = (left + right)/2;
+
+ while(lidx <=pivot && ridx >=pivot)
+ {
+ while(arr[lidx] < arr[pivot] && lidx <= pivot)
+ lidx++;
+ while(arr[ridx] > arr[pivot] && ridx >= pivot)
+ ridx--;
+ swap(&arr[lidx], &arr[ridx]);
+ swap(&idx[lidx], &idx[ridx]);
+ lidx++;
+ ridx--;
+ if(lidx-1 == pivot)
+ {
+ ridx++;
+ pivot = ridx;
+ }
+ else if(ridx+1 == pivot)
+ {
+ lidx--;
+ pivot = lidx;
+ }
+ }
+ quicksortsad(arr, idx, left, pivot - 1);
+ quicksortsad(arr, idx, pivot + 1, right);
+ }
}
//The improved MV prediction
@@ -1488,7 +1523,7 @@ void vp8_mv_pred
VP8_COMP *cpi,
MACROBLOCKD *xd,
const MODE_INFO *here,
- int_mv *mvp,
+ MV *mvp,
int refframe,
int *ref_frame_sign_bias,
int *sr,
@@ -1615,8 +1650,8 @@ void vp8_mv_pred
mvy[i] = near_mvs[i].as_mv.col;
}
- insertsortmv(mvx, vcnt);
- insertsortmv(mvy, vcnt);
+ quicksortmv (mvx, 0, vcnt-1);
+ quicksortmv (mvy, 0, vcnt-1);
mv.as_mv.row = mvx[vcnt/2];
mv.as_mv.col = mvy[vcnt/2];
@@ -1627,16 +1662,14 @@ void vp8_mv_pred
}
/* Set up return values */
- mvp->as_int = mv.as_int;
- vp8_clamp_mv2(mvp, xd);
+ *mvp = mv.as_mv;
+ vp8_clamp_mv(mvp, xd);
}
void vp8_cal_sad(VP8_COMP *cpi, MACROBLOCKD *xd, MACROBLOCK *x, int recon_yoffset, int near_sadidx[])
{
int near_sad[8] = {0}; // 0-cf above, 1-cf left, 2-cf aboveleft, 3-lf current, 4-lf above, 5-lf left, 6-lf right, 7-lf below
- BLOCK *b = &x->block[0];
- unsigned char *src_y_ptr = *(b->base_src);
//calculate sad for current frame 3 nearby MBs.
if( xd->mb_to_top_edge==0 && xd->mb_to_left_edge ==0)
@@ -1645,16 +1678,16 @@ void vp8_cal_sad(VP8_COMP *cpi, MACROBLOCKD *xd, MACROBLOCK *x, int recon_yoffse
}else if(xd->mb_to_top_edge==0)
{ //only has left MB for sad calculation.
near_sad[0] = near_sad[2] = INT_MAX;
- near_sad[1] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, xd->dst.y_buffer - 16,xd->dst.y_stride, 0x7fffffff);
+ near_sad[1] = cpi->fn_ptr[BLOCK_16X16].sdf(x->src.y_buffer, x->src.y_stride, xd->dst.y_buffer - 16,xd->dst.y_stride, 0x7fffffff);
}else if(xd->mb_to_left_edge ==0)
{ //only has left MB for sad calculation.
near_sad[1] = near_sad[2] = INT_MAX;
- near_sad[0] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, xd->dst.y_buffer - xd->dst.y_stride *16,xd->dst.y_stride, 0x7fffffff);
+ near_sad[0] = cpi->fn_ptr[BLOCK_16X16].sdf(x->src.y_buffer, x->src.y_stride, xd->dst.y_buffer - xd->dst.y_stride *16,xd->dst.y_stride, 0x7fffffff);
}else
{
- near_sad[0] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, xd->dst.y_buffer - xd->dst.y_stride *16,xd->dst.y_stride, 0x7fffffff);
- near_sad[1] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, xd->dst.y_buffer - 16,xd->dst.y_stride, 0x7fffffff);
- near_sad[2] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, xd->dst.y_buffer - xd->dst.y_stride *16 -16,xd->dst.y_stride, 0x7fffffff);
+ near_sad[0] = cpi->fn_ptr[BLOCK_16X16].sdf(x->src.y_buffer, x->src.y_stride, xd->dst.y_buffer - xd->dst.y_stride *16,xd->dst.y_stride, 0x7fffffff);
+ near_sad[1] = cpi->fn_ptr[BLOCK_16X16].sdf(x->src.y_buffer, x->src.y_stride, xd->dst.y_buffer - 16,xd->dst.y_stride, 0x7fffffff);
+ near_sad[2] = cpi->fn_ptr[BLOCK_16X16].sdf(x->src.y_buffer, x->src.y_stride, xd->dst.y_buffer - xd->dst.y_stride *16 -16,xd->dst.y_stride, 0x7fffffff);
}
if(cpi->common.last_frame_type != KEY_FRAME)
@@ -1669,61 +1702,36 @@ void vp8_cal_sad(VP8_COMP *cpi, MACROBLOCKD *xd, MACROBLOCK *x, int recon_yoffse
if(xd->mb_to_bottom_edge==0) near_sad[7] = INT_MAX;
if(near_sad[4] != INT_MAX)
- near_sad[4] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, pre_y_buffer - pre_y_stride *16, pre_y_stride, 0x7fffffff);
+ near_sad[4] = cpi->fn_ptr[BLOCK_16X16].sdf(x->src.y_buffer, x->src.y_stride, pre_y_buffer - pre_y_stride *16, pre_y_stride, 0x7fffffff);
if(near_sad[5] != INT_MAX)
- near_sad[5] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, pre_y_buffer - 16, pre_y_stride, 0x7fffffff);
- near_sad[3] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, pre_y_buffer, pre_y_stride, 0x7fffffff);
+ near_sad[5] = cpi->fn_ptr[BLOCK_16X16].sdf(x->src.y_buffer, x->src.y_stride, pre_y_buffer - 16, pre_y_stride, 0x7fffffff);
+ near_sad[3] = cpi->fn_ptr[BLOCK_16X16].sdf(x->src.y_buffer, x->src.y_stride, pre_y_buffer, pre_y_stride, 0x7fffffff);
if(near_sad[6] != INT_MAX)
- near_sad[6] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, pre_y_buffer + 16, pre_y_stride, 0x7fffffff);
+ near_sad[6] = cpi->fn_ptr[BLOCK_16X16].sdf(x->src.y_buffer, x->src.y_stride, pre_y_buffer + 16, pre_y_stride, 0x7fffffff);
if(near_sad[7] != INT_MAX)
- near_sad[7] = cpi->fn_ptr[BLOCK_16X16].sdf(src_y_ptr, b->src_stride, pre_y_buffer + pre_y_stride *16, pre_y_stride, 0x7fffffff);
+ near_sad[7] = cpi->fn_ptr[BLOCK_16X16].sdf(x->src.y_buffer, x->src.y_stride, pre_y_buffer + pre_y_stride *16, pre_y_stride, 0x7fffffff);
}
if(cpi->common.last_frame_type != KEY_FRAME)
{
- insertsortsad(near_sad, near_sadidx, 8);
+ quicksortsad(near_sad, near_sadidx, 0, 7);
}else
{
- insertsortsad(near_sad, near_sadidx, 3);
+ quicksortsad(near_sad, near_sadidx, 0, 2);
}
}
-static void rd_update_mvcount(VP8_COMP *cpi, MACROBLOCK *x, int_mv *best_ref_mv)
-{
- if (x->e_mbd.mode_info_context->mbmi.mode == SPLITMV)
- {
- int i;
-
- for (i = 0; i < x->partition_info->count; i++)
- {
- if (x->partition_info->bmi[i].mode == NEW4X4)
- {
- cpi->MVcount[0][mv_max+((x->partition_info->bmi[i].mv.as_mv.row
- - best_ref_mv->as_mv.row) >> 1)]++;
- cpi->MVcount[1][mv_max+((x->partition_info->bmi[i].mv.as_mv.col
- - best_ref_mv->as_mv.col) >> 1)]++;
- }
- }
- }
- else if (x->e_mbd.mode_info_context->mbmi.mode == NEWMV)
- {
- cpi->MVcount[0][mv_max+((x->e_mbd.mode_info_context->mbmi.mv.as_mv.row
- - best_ref_mv->as_mv.row) >> 1)]++;
- cpi->MVcount[1][mv_max+((x->e_mbd.mode_info_context->mbmi.mv.as_mv.col
- - best_ref_mv->as_mv.col) >> 1)]++;
- }
-}
-
-void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int recon_uvoffset, int *returnrate, int *returndistortion, int *returnintra)
+#if !(CONFIG_REALTIME_ONLY)
+int vp8_rd_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];
BLOCKD *d = &x->e_mbd.block[0];
MACROBLOCKD *xd = &x->e_mbd;
- union b_mode_info best_bmodes[16];
+ B_MODE_INFO best_bmodes[16];
MB_MODE_INFO best_mbmode;
PARTITION_INFO best_partition;
- int_mv best_ref_mv;
- int_mv mode_mv[MB_MODE_COUNT];
+ MV best_ref_mv;
+ MV mode_mv[MB_MODE_COUNT];
MB_PREDICTION_MODE this_mode;
int num00;
int best_mode_index = 0;
@@ -1733,8 +1741,8 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
int mdcounts[4];
int rate;
int distortion;
- int best_rd = INT_MAX;
- int best_intra_rd = INT_MAX;
+ int best_rd = INT_MAX; // 1 << 30;
+ int ref_frame_cost[MAX_REF_FRAMES];
int rate2, distortion2;
int uv_intra_rate, uv_intra_distortion, uv_intra_rate_tokenonly;
int rate_y, UNINITIALIZED_IS_SAFE(rate_uv);
@@ -1747,14 +1755,17 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
//int intermodecost[MAX_MODES];
MB_PREDICTION_MODE uv_intra_mode;
- int_mv mvp;
+
+ int force_no_skip = 0;
+
+ 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)
- int_mv frame_nearest_mv[4];
- int_mv frame_near_mv[4];
- int_mv frame_best_ref_mv[4];
+ MV frame_nearest_mv[4];
+ MV frame_near_mv[4];
+ MV frame_best_ref_mv[4];
int frame_mdcounts[4][4];
int frame_lf_or_gf[4];
unsigned char *y_buffer[4];
@@ -1762,7 +1773,6 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
unsigned char *v_buffer[4];
vpx_memset(&best_mbmode, 0, sizeof(best_mbmode));
- vpx_memset(&best_bmodes, 0, sizeof(best_bmodes));
if (cpi->ref_frame_flags & VP8_LAST_FLAG)
{
@@ -1811,10 +1821,36 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
x->skip = 0;
+ ref_frame_cost[INTRA_FRAME] = vp8_cost_zero(cpi->prob_intra_coded);
+
+ // Special case treatment when GF and ARF are not sensible options for reference
+ if (cpi->ref_frame_flags == VP8_LAST_FLAG)
+ {
+ ref_frame_cost[LAST_FRAME] = vp8_cost_one(cpi->prob_intra_coded)
+ + vp8_cost_zero(255);
+ ref_frame_cost[GOLDEN_FRAME] = vp8_cost_one(cpi->prob_intra_coded)
+ + vp8_cost_one(255)
+ + vp8_cost_zero(128);
+ ref_frame_cost[ALTREF_FRAME] = vp8_cost_one(cpi->prob_intra_coded)
+ + vp8_cost_one(255)
+ + vp8_cost_one(128);
+ }
+ else
+ {
+ ref_frame_cost[LAST_FRAME] = vp8_cost_one(cpi->prob_intra_coded)
+ + vp8_cost_zero(cpi->prob_last_coded);
+ ref_frame_cost[GOLDEN_FRAME] = vp8_cost_one(cpi->prob_intra_coded)
+ + vp8_cost_one(cpi->prob_last_coded)
+ + vp8_cost_zero(cpi->prob_gf_coded);
+ ref_frame_cost[ALTREF_FRAME] = vp8_cost_one(cpi->prob_intra_coded)
+ + vp8_cost_one(cpi->prob_last_coded)
+ + vp8_cost_one(cpi->prob_gf_coded);
+ }
+
vpx_memset(mode_mv, 0, sizeof(mode_mv));
x->e_mbd.mode_info_context->mbmi.ref_frame = INTRA_FRAME;
- rd_pick_intra_mbuv_mode(cpi, x, &uv_intra_rate, &uv_intra_rate_tokenonly, &uv_intra_distortion);
+ vp8_rd_pick_intra_mbuv_mode(cpi, x, &uv_intra_rate, &uv_intra_rate_tokenonly, &uv_intra_distortion);
uv_intra_mode = x->e_mbd.mode_info_context->mbmi.uv_mode;
for (mode_index = 0; mode_index < MAX_MODES; mode_index++)
@@ -1824,6 +1860,8 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
int disable_skip = 0;
int other_cost = 0;
+ force_no_skip = 0;
+
// Experimental debug code.
// Record of rd values recorded for this MB. -1 indicates not measured
//all_rds[mode_index] = -1;
@@ -1867,6 +1905,28 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
lf_or_gf = frame_lf_or_gf[x->e_mbd.mode_info_context->mbmi.ref_frame];
}
+ 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;
+ }
+
// Check to see if the testing frequency for this mode is at its max
// If so then prevent it from being tested and increase the threshold for its testing
if (cpi->mode_test_hit_counts[mode_index] && (cpi->mode_check_freq[mode_index] > 1))
@@ -1918,7 +1978,7 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
int tmp_rd;
// Note the rate value returned here includes the cost of coding the BPRED mode : x->mbmode_cost[x->e_mbd.frame_type][BPRED];
- tmp_rd = rd_pick_intra4x4mby_modes(cpi, x, &rate, &rate_y, &distortion, best_yrd);
+ tmp_rd = vp8_rd_pick_intra4x4mby_modes(cpi, x, &rate, &rate_y, &distortion, best_yrd);
rate2 += rate;
distortion2 += distortion;
@@ -1985,197 +2045,228 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
break;
case NEWMV:
- {
- int thissme;
- int bestsme = INT_MAX;
- int step_param = cpi->sf.first_step;
- int further_steps;
- int n;
- int do_refine=1; /* If last step (1-away) of n-step search doesn't pick the center point as the best match,
- we will do a final 1-away diamond refining search */
-
- int sadpb = x->sadperbit16;
- int_mv mvp_full;
-
- int col_min = (best_ref_mv.as_mv.col>>3) - MAX_FULL_PEL_VAL + ((best_ref_mv.as_mv.col & 7)?1:0);
- int row_min = (best_ref_mv.as_mv.row>>3) - MAX_FULL_PEL_VAL + ((best_ref_mv.as_mv.row & 7)?1:0);
- int col_max = (best_ref_mv.as_mv.col>>3) + MAX_FULL_PEL_VAL;
- int row_max = (best_ref_mv.as_mv.row>>3) + MAX_FULL_PEL_VAL;
- 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;
+ // Decrement full search counter
+ if (cpi->check_freq[lf_or_gf] > 0)
+ cpi->check_freq[lf_or_gf] --;
- if(!saddone)
{
- vp8_cal_sad(cpi,xd,x, recon_yoffset ,&near_sadidx[0] );
- saddone = 1;
- }
+ int thissme;
+ int bestsme = INT_MAX;
+ int step_param = cpi->sf.first_step;
+ int search_range;
+ int further_steps;
+ int n;
- 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]);
+ 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;
+
+ //adjust search range according to sr from mv prediction
+ if(sr > step_param)
+ step_param = sr;
+
+ // Work out how long a search we should do
+ search_range = MAXF(abs(best_ref_mv.col), abs(best_ref_mv.row)) >> 3;
+
+ if (search_range >= x->vector_range)
+ x->vector_range = search_range;
+ else if (x->vector_range > cpi->sf.min_fs_radius)
+ x->vector_range--;
+
+ // Initial step/diamond search
+ {
+ int sadpb = x->sadperbit16;
- mvp_full.as_mv.col = mvp.as_mv.col>>3;
- mvp_full.as_mv.row = mvp.as_mv.row>>3;
+ if (cpi->sf.search_method == HEX)
+ {
+ 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, &best_ref_mv);
+ 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, &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;
- // 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;
+ // Further step/diamond searches as necessary
+ n = 0;
+ further_steps = (cpi->sf.max_step_search_steps - 1) - step_param;
- //adjust search range according to sr from mv prediction
- if(sr > step_param)
- step_param = sr;
+ n = num00;
+ num00 = 0;
- // Initial step/diamond search
- {
- bestsme = cpi->diamond_search_sad(x, b, d, &mvp_full, &d->bmi.mv,
- step_param, sadpb, &num00,
- &cpi->fn_ptr[BLOCK_16X16],
- x->mvcost, &best_ref_mv);
- mode_mv[NEWMV].as_int = d->bmi.mv.as_int;
+ while (n < further_steps)
+ {
+ n++;
- // Further step/diamond searches as necessary
- n = 0;
- further_steps = (cpi->sf.max_step_search_steps - 1) - step_param;
+ if (num00)
+ num00--;
+ else
+ {
+ 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
- n = num00;
- num00 = 0;
+ 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;
+ }
+ }
+ }
+ }
- /* If there won't be more n-step search, check to see if refining search is needed. */
- if (n > further_steps)
- do_refine = 0;
+ }
- while (n < further_steps)
+ // Should we do a full search
+ if (!cpi->check_freq[lf_or_gf] || cpi->do_full[lf_or_gf])
{
- n++;
+ int thissme;
+ int full_flag_thresh = 0;
+ MV full_mvp;
+
+ full_mvp.row = d->bmi.mv.as_mv.row <<3; // use diamond search result as full search staring point
+ full_mvp.col = d->bmi.mv.as_mv.col <<3;
+
+ // Update x->vector_range based on best vector found in step search
+ search_range = MAXF(abs((mvp.row>>3) - d->bmi.mv.as_mv.row), abs((mvp.col>>3) - d->bmi.mv.as_mv.col));
+ //search_range *= 1.4; //didn't improve PSNR
- if (num00)
- num00--;
+ if (search_range > x->vector_range)
+ x->vector_range = search_range;
else
+ search_range = x->vector_range;
+
+ // Apply limits
+ search_range = (search_range > cpi->sf.max_fs_radius) ? cpi->sf.max_fs_radius : search_range;
+
+ //add this to reduce full search range.
+ if(sr<=3 && search_range > 8) search_range = 8;
+
{
- thissme = cpi->diamond_search_sad(x, b, d, &mvp_full,
- &d->bmi.mv, step_param + n, sadpb, &num00,
- &cpi->fn_ptr[BLOCK_16X16], x->mvcost,
- &best_ref_mv);
+ int sadpb = x->sadperbit16 >> 2;
+ thissme = cpi->full_search_sad(x, b, d, &full_mvp, sadpb, search_range, &cpi->fn_ptr[BLOCK_16X16], x->mvcost, x->mvsadcost,&best_ref_mv);
+ }
- /* check to see if refining search is needed. */
- if (num00 > (further_steps-n))
- do_refine = 0;
+ // Barrier threshold to initiating full search
+ // full_flag_thresh = 10 + (thissme >> 7);
+ if ((thissme + full_flag_thresh) < bestsme)
+ {
+ cpi->do_full[lf_or_gf] ++;
+ bestsme = thissme;
+ }
+ else if (thissme < bestsme)
+ bestsme = thissme;
+ else
+ {
+ cpi->do_full[lf_or_gf] = cpi->do_full[lf_or_gf] >> 1;
+ cpi->check_freq[lf_or_gf] = cpi->sf.full_freq[lf_or_gf];
- if (thissme < bestsme)
- {
- bestsme = thissme;
- mode_mv[NEWMV].as_int = d->bmi.mv.as_int;
- }
- else
- {
- d->bmi.mv.as_int = mode_mv[NEWMV].as_int;
- }
+ // The full search result is actually worse so re-instate the previous best vector
+ d->bmi.mv.as_mv.row = mode_mv[NEWMV].row;
+ d->bmi.mv.as_mv.col = mode_mv[NEWMV].col;
}
}
- }
-
- /* final 1-away diamond refining search */
- if (do_refine == 1)
- {
- int search_range;
- //It seems not a good way to set search_range. Need further investigation.
- //search_range = MAXF(abs((mvp.row>>3) - d->bmi.mv.as_mv.row), abs((mvp.col>>3) - d->bmi.mv.as_mv.col));
- search_range = 8;
+ 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;
- //thissme = cpi->full_search_sad(x, b, d, &d->bmi.mv.as_mv, sadpb, search_range, &cpi->fn_ptr[BLOCK_16X16], x->mvcost, &best_ref_mv);
- thissme = cpi->refining_search_sad(x, b, d, &d->bmi.mv, sadpb,
- search_range, &cpi->fn_ptr[BLOCK_16X16],
- x->mvcost, &best_ref_mv);
+ if (bestsme < INT_MAX)
+ // cpi->find_fractional_mv_step(x,b,d,&d->bmi.mv.as_mv,&best_ref_mv,x->errorperbit/2,cpi->fn_ptr.svf,cpi->fn_ptr.vf,x->mvcost); // normal mvc=11
+ cpi->find_fractional_mv_step(x, b, d, &d->bmi.mv.as_mv, &best_ref_mv, x->errorperbit / 4, &cpi->fn_ptr[BLOCK_16X16], x->mvcost);
- if (thissme < bestsme)
- {
- bestsme = thissme;
- mode_mv[NEWMV].as_int = d->bmi.mv.as_int;
- }
- else
- {
- d->bmi.mv.as_int = mode_mv[NEWMV].as_int;
- }
- }
+ mode_mv[NEWMV].row = d->bmi.mv.as_mv.row;
+ mode_mv[NEWMV].col = d->bmi.mv.as_mv.col;
- 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;
+ // Add the new motion vector cost to our rolling cost variable
+ rate2 += vp8_mv_bit_cost(&mode_mv[NEWMV], &best_ref_mv, x->mvcost, 96);
- if (bestsme < INT_MAX)
- {
- int dis; /* TODO: use dis in distortion calculation later. */
- unsigned int sse;
- cpi->find_fractional_mv_step(x, b, d, &d->bmi.mv, &best_ref_mv,
- x->errorperbit,
- &cpi->fn_ptr[BLOCK_16X16],
- x->mvcost, &dis, &sse);
}
- mode_mv[NEWMV].as_int = d->bmi.mv.as_int;
-
- // Add the new motion vector cost to our rolling cost variable
- rate2 += vp8_mv_bit_cost(&mode_mv[NEWMV], &best_ref_mv, x->mvcost, 96);
- }
-
case NEARESTMV:
case NEARMV:
+
// Clip "next_nearest" so that it does not extend to far out of image
- vp8_clamp_mv2(&mode_mv[this_mode], xd);
+ if (mode_mv[this_mode].col < (xd->mb_to_left_edge - LEFT_TOP_MARGIN))
+ mode_mv[this_mode].col = xd->mb_to_left_edge - LEFT_TOP_MARGIN;
+ else if (mode_mv[this_mode].col > xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN)
+ mode_mv[this_mode].col = xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN;
+
+ if (mode_mv[this_mode].row < (xd->mb_to_top_edge - LEFT_TOP_MARGIN))
+ mode_mv[this_mode].row = xd->mb_to_top_edge - LEFT_TOP_MARGIN;
+ else if (mode_mv[this_mode].row > xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN)
+ mode_mv[this_mode].row = xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN;
// Do not bother proceeding if the vector (from newmv,nearest or near) is 0,0 as this should then be coded using the zeromv mode.
- if (((this_mode == NEARMV) || (this_mode == NEARESTMV)) && (mode_mv[this_mode].as_int == 0))
+ if (((this_mode == NEARMV) || (this_mode == NEARESTMV)) &&
+ ((mode_mv[this_mode].row == 0) && (mode_mv[this_mode].col == 0)))
continue;
case ZEROMV:
+ mv_selected:
+
// Trap vectors that reach beyond the UMV borders
// Note that ALL New MV, Nearest MV Near MV and Zero MV code drops through to this point
// because of the lack of break statements in the previous two cases.
- if (((mode_mv[this_mode].as_mv.row >> 3) < x->mv_row_min) || ((mode_mv[this_mode].as_mv.row >> 3) > x->mv_row_max) ||
- ((mode_mv[this_mode].as_mv.col >> 3) < x->mv_col_min) || ((mode_mv[this_mode].as_mv.col >> 3) > x->mv_col_max))
+ if (((mode_mv[this_mode].row >> 3) < x->mv_row_min) || ((mode_mv[this_mode].row >> 3) > x->mv_row_max) ||
+ ((mode_mv[this_mode].col >> 3) < x->mv_col_min) || ((mode_mv[this_mode].col >> 3) > x->mv_col_max))
continue;
vp8_set_mbmode_and_mvs(x, this_mode, &mode_mv[this_mode]);
- vp8_build_inter16x16_predictors_mby(&x->e_mbd);
+ vp8_build_inter_predictors_mby(&x->e_mbd);
if (cpi->active_map_enabled && x->active_ptr[0] == 0) {
x->skip = 1;
}
else if (x->encode_breakout)
{
- unsigned int sse;
- unsigned int var;
+ int sum, sse;
int threshold = (xd->block[0].dequant[1]
* xd->block[0].dequant[1] >>4);
if(threshold < x->encode_breakout)
threshold = x->encode_breakout;
- var = VARIANCE_INVOKE(&cpi->rtcd.variance, var16x16)
- (*(b->base_src), b->src_stride,
- x->e_mbd.predictor, 16, &sse);
+ VARIANCE_INVOKE(&cpi->rtcd.variance, get16x16var)
+ (x->src.y_buffer, x->src.y_stride,
+ x->e_mbd.predictor, 16, (unsigned int *)(&sse), &sum);
if (sse < threshold)
{
- unsigned int q2dc = xd->block[24].dequant[0];
+ // Check u and v to make sure skip is ok
+ int sse2 = 0;
/* If theres is no codeable 2nd order dc
or a very small uniform pixel change change */
- if ((sse - var < q2dc * q2dc >>4) ||
- (sse /2 > var && sse-var < 64))
+ if (abs(sum) < (xd->block[24].dequant[0]<<2)||
+ ((sum * sum>>8) > sse && abs(sum) <128))
{
- // Check u and v to make sure skip is ok
- int sse2= VP8_UVSSE(x, IF_RTCD(&cpi->rtcd.variance));
+ sse2 = VP8_UVSSE(x, IF_RTCD(&cpi->rtcd.variance));
+
if (sse2 * 2 < threshold)
{
x->skip = 1;
@@ -2187,7 +2278,8 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
distortion_uv = sse2;
disable_skip = 1;
- this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2);
+ this_rd = RDCOST(x->rdmult, x->rddiv, rate2,
+ distortion2);
break;
}
@@ -2225,11 +2317,8 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
rate2 += other_cost;
}
- /* Estimate the reference frame signaling cost and add it
- * to the rolling cost variable.
- */
- rate2 +=
- x->e_mbd.ref_frame_cost[x->e_mbd.mode_info_context->mbmi.ref_frame];
+ // Estimate the reference frame signaling cost and add it to the rolling cost variable.
+ rate2 += ref_frame_cost[x->e_mbd.mode_info_context->mbmi.ref_frame];
if (!disable_skip)
{
@@ -2272,12 +2361,9 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
//all_rates[mode_index] = rate2;
//all_dist[mode_index] = distortion2;
- // Keep record of best intra distortion
- if ((x->e_mbd.mode_info_context->mbmi.ref_frame == INTRA_FRAME) &&
- (this_rd < best_intra_rd) )
+ if ((x->e_mbd.mode_info_context->mbmi.ref_frame == INTRA_FRAME) && (this_rd < *returnintra))
{
- best_intra_rd = this_rd;
- *returnintra = distortion2 ;
+ *returnintra = this_rd ;
}
// Did this mode help.. i.i is it the new best mode
@@ -2285,16 +2371,14 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
{
// Note index of best mode so far
best_mode_index = mode_index;
+ x->e_mbd.mode_info_context->mbmi.force_no_skip = force_no_skip;
if (this_mode <= B_PRED)
{
x->e_mbd.mode_info_context->mbmi.uv_mode = uv_intra_mode;
- /* required for left and above block mv */
- x->e_mbd.mode_info_context->mbmi.mv.as_int = 0;
}
- other_cost +=
- x->e_mbd.ref_frame_cost[x->e_mbd.mode_info_context->mbmi.ref_frame];
+ other_cost += ref_frame_cost[x->e_mbd.mode_info_context->mbmi.ref_frame];
/* Calculate the final y RD estimate for this mode */
best_yrd = RDCOST(x->rdmult, x->rddiv, (rate2-rate_uv-other_cost),
@@ -2306,12 +2390,10 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
vpx_memcpy(&best_mbmode, &x->e_mbd.mode_info_context->mbmi, sizeof(MB_MODE_INFO));
vpx_memcpy(&best_partition, x->partition_info, sizeof(PARTITION_INFO));
- if ((this_mode == B_PRED) || (this_mode == SPLITMV))
- for (i = 0; i < 16; i++)
- {
- best_bmodes[i] = x->e_mbd.block[i].bmi;
- }
-
+ for (i = 0; i < 16; i++)
+ {
+ vpx_memcpy(&best_bmodes[i], &x->e_mbd.block[i].bmi, sizeof(B_MODE_INFO));
+ }
// Testing this mode gave rise to an improvement in best error score. Lower threshold a bit for next time
cpi->rd_thresh_mult[mode_index] = (cpi->rd_thresh_mult[mode_index] >= (MIN_THRESHMULT + 2)) ? cpi->rd_thresh_mult[mode_index] - 2 : MIN_THRESHMULT;
@@ -2360,81 +2442,68 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
}
- // Note how often each mode chosen as best
- cpi->mode_chosen_counts[best_mode_index] ++;
-
-
- if (cpi->is_src_frame_alt_ref &&
- (best_mbmode.mode != ZEROMV || best_mbmode.ref_frame != ALTREF_FRAME))
+ // If we have chosen new mv or split then decay the full search check count more quickly.
+ if ((vp8_mode_order[best_mode_index] == NEWMV) || (vp8_mode_order[best_mode_index] == SPLITMV))
{
- x->e_mbd.mode_info_context->mbmi.mode = ZEROMV;
- x->e_mbd.mode_info_context->mbmi.ref_frame = ALTREF_FRAME;
- x->e_mbd.mode_info_context->mbmi.mv.as_int = 0;
- x->e_mbd.mode_info_context->mbmi.uv_mode = DC_PRED;
- x->e_mbd.mode_info_context->mbmi.mb_skip_coeff =
- (cpi->common.mb_no_coeff_skip) ? 1 : 0;
- x->e_mbd.mode_info_context->mbmi.partitioning = 0;
+ int lf_or_gf = (vp8_ref_frame_order[best_mode_index] == LAST_FRAME) ? 0 : 1;
- return;
+ if (cpi->check_freq[lf_or_gf] && !cpi->do_full[lf_or_gf])
+ {
+ cpi->check_freq[lf_or_gf] --;
+ }
}
+ // Keep a record of best mode index that we chose
+ cpi->last_best_mode_index = best_mode_index;
- // macroblock modes
- vpx_memcpy(&x->e_mbd.mode_info_context->mbmi, &best_mbmode, sizeof(MB_MODE_INFO));
+ // Note how often each mode chosen as best
+ cpi->mode_chosen_counts[best_mode_index] ++;
- if (best_mbmode.mode == B_PRED)
- {
- for (i = 0; i < 16; i++)
- x->e_mbd.block[i].bmi.as_mode = best_bmodes[i].as_mode;
- }
- if (best_mbmode.mode == SPLITMV)
+ if (cpi->is_src_frame_alt_ref && (best_mbmode.mode != ZEROMV || best_mbmode.ref_frame != ALTREF_FRAME))
{
- for (i = 0; i < 16; i++)
- x->e_mbd.block[i].bmi.mv.as_int = best_bmodes[i].mv.as_int;
-
+ best_mbmode.mode = ZEROMV;
+ best_mbmode.ref_frame = ALTREF_FRAME;
+ best_mbmode.mv.as_int = 0;
+ best_mbmode.uv_mode = 0;
+ best_mbmode.mb_skip_coeff = (cpi->common.mb_no_coeff_skip) ? 1 : 0;
+ best_mbmode.partitioning = 0;
+ best_mbmode.dc_diff = 0;
+
+ vpx_memcpy(&x->e_mbd.mode_info_context->mbmi, &best_mbmode, sizeof(MB_MODE_INFO));
vpx_memcpy(x->partition_info, &best_partition, sizeof(PARTITION_INFO));
- x->e_mbd.mode_info_context->mbmi.mv.as_int =
- x->partition_info->bmi[15].mv.as_int;
- }
-
- rd_update_mvcount(cpi, x, &frame_best_ref_mv[xd->mode_info_context->mbmi.ref_frame]);
-
-}
-
-void vp8_rd_pick_intra_mode(VP8_COMP *cpi, MACROBLOCK *x, int *rate_)
-{
- int error4x4, error16x16;
- int rate4x4, rate16x16 = 0, rateuv;
- int dist4x4, dist16x16, distuv;
- int rate;
- int rate4x4_tokenonly = 0;
- int rate16x16_tokenonly = 0;
- int rateuv_tokenonly = 0;
-
- x->e_mbd.mode_info_context->mbmi.ref_frame = INTRA_FRAME;
+ for (i = 0; i < 16; i++)
+ {
+ vpx_memset(&x->e_mbd.block[i].bmi, 0, sizeof(B_MODE_INFO));
+ }
- rd_pick_intra_mbuv_mode(cpi, x, &rateuv, &rateuv_tokenonly, &distuv);
- rate = rateuv;
+ x->e_mbd.mode_info_context->mbmi.mv.as_int = 0;
- error16x16 = rd_pick_intra16x16mby_mode(cpi, x,
- &rate16x16, &rate16x16_tokenonly,
- &dist16x16);
+ return best_rd;
+ }
- error4x4 = rd_pick_intra4x4mby_modes(cpi, x,
- &rate4x4, &rate4x4_tokenonly,
- &dist4x4, error16x16);
- if (error4x4 < error16x16)
+ if(best_mbmode.mode <= B_PRED)
{
- x->e_mbd.mode_info_context->mbmi.mode = B_PRED;
- rate += rate4x4;
+ int i;
+ for (i = 0; i < 16; i++)
+ {
+ best_bmodes[i].mv.as_int = 0;
+ }
}
- else
+
+ // macroblock modes
+ vpx_memcpy(&x->e_mbd.mode_info_context->mbmi, &best_mbmode, sizeof(MB_MODE_INFO));
+ vpx_memcpy(x->partition_info, &best_partition, sizeof(PARTITION_INFO));
+
+ for (i = 0; i < 16; i++)
{
- rate += rate16x16;
+ vpx_memcpy(&x->e_mbd.block[i].bmi, &best_bmodes[i], sizeof(B_MODE_INFO));
}
- *rate_ = rate;
+ x->e_mbd.mode_info_context->mbmi.mv.as_mv = x->e_mbd.block[15].bmi.mv.as_mv;
+
+ return best_rd;
}
+#endif
« no previous file with comments | « libvpx/source/libvpx/vp8/encoder/rdopt.h ('k') | libvpx/source/libvpx/vp8/encoder/sad_c.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698