Commit 97096f5f authored by Ronald S. Bultje's avatar Ronald S. Bultje Committed by Gerrit Code Review
Browse files

Merge changes I02e7f64a,Ide954b00,Idc8b5977 into experimental

* changes:
  Fix another typo in 4x4-transform-for-i8x8-intra-pred coeff contexts.
  8x8 transform support in splitmv.
  Use SPLITMV_PARTITIONING instead of a plain integer type.
parents 7906ed09 f72fdf1c
......@@ -175,6 +175,14 @@ typedef enum {
#define VP8_BINTRAMODES (B_HU_PRED + 1) /* 10 */
#define VP8_SUBMVREFS (1 + NEW4X4 - LEFT4X4)
typedef enum {
PARTITIONING_16X8 = 0,
PARTITIONING_8X16,
PARTITIONING_8X8,
PARTITIONING_4X4,
NB_PARTITIONINGS,
} SPLITMV_PARTITIONING_TYPE;
/* For keyframes, intra block modes are predicted by the (already decoded)
modes for the Y blocks to the left and above us; for interframes, there
is a single probability table. */
......@@ -216,7 +224,7 @@ typedef struct {
int mv_ref_index[MAX_REF_FRAMES];
#endif
unsigned char partitioning;
SPLITMV_PARTITIONING_TYPE partitioning;
unsigned char mb_skip_coeff; /* does this mb has coefficients at all, 1=no coefficients, 0=need decode tokens */
unsigned char need_to_clamp_mvs;
unsigned char need_to_clamp_secondmv;
......
......@@ -215,9 +215,9 @@ const vp8_tree_index vp8_uv_mode_tree[VP8_UV_MODES * 2 - 2] = {
};
const vp8_tree_index vp8_mbsplit_tree[6] = {
-3, 2,
-2, 4,
-0, -1
-PARTITIONING_4X4, 2,
-PARTITIONING_8X8, 4,
-PARTITIONING_16X8, -PARTITIONING_8X16,
};
const vp8_tree_index vp8_mv_ref_tree[8] = {
......
......@@ -783,7 +783,7 @@ int vp8_post_proc_frame(VP8_COMMON *oci, YV12_BUFFER_CONFIG *dest, vp8_ppflags_t
if (mi->mbmi.mode == SPLITMV) {
switch (mi->mbmi.partitioning) {
case 0 : { /* mv_top_bottom */
case PARTITIONING_16X8 : { /* mv_top_bottom */
union b_mode_info *bmi = &mi->bmi[0];
MV *mv = &bmi->mv.as_mv;
......@@ -803,7 +803,7 @@ int vp8_post_proc_frame(VP8_COMMON *oci, YV12_BUFFER_CONFIG *dest, vp8_ppflags_t
break;
}
case 1 : { /* mv_left_right */
case PARTITIONING_8X16 : { /* mv_left_right */
union b_mode_info *bmi = &mi->bmi[0];
MV *mv = &bmi->mv.as_mv;
......@@ -823,7 +823,7 @@ int vp8_post_proc_frame(VP8_COMMON *oci, YV12_BUFFER_CONFIG *dest, vp8_ppflags_t
break;
}
case 2 : { /* mv_quarters */
case PARTITIONING_8X8 : { /* mv_quarters */
union b_mode_info *bmi = &mi->bmi[0];
MV *mv = &bmi->mv.as_mv;
......@@ -858,6 +858,7 @@ int vp8_post_proc_frame(VP8_COMMON *oci, YV12_BUFFER_CONFIG *dest, vp8_ppflags_t
vp8_blit_line(x0 + 12, x1, y0 + 12, y1, y_buffer, y_stride);
break;
}
case PARTITIONING_4X4:
default : {
union b_mode_info *bmi = mi->bmi;
int bx0, by0;
......
......@@ -965,7 +965,7 @@ static void build_inter4x4_predictors_mb(MACROBLOCKD *xd) {
MB_MODE_INFO * mbmi = &xd->mode_info_context->mbmi;
BLOCKD *blockd = xd->block;
if (xd->mode_info_context->mbmi.partitioning < 3) {
if (xd->mode_info_context->mbmi.partitioning != PARTITIONING_4X4) {
blockd[ 0].bmi = xd->mode_info_context->bmi[ 0];
blockd[ 2].bmi = xd->mode_info_context->bmi[ 2];
blockd[ 8].bmi = xd->mode_info_context->bmi[ 8];
......
......@@ -1285,10 +1285,12 @@ static void read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
#if CONFIG_TX_SELECT
if (cm->txfm_mode == TX_MODE_SELECT && mbmi->mb_skip_coeff == 0 &&
((mbmi->ref_frame == INTRA_FRAME && mbmi->mode <= I8X8_PRED) ||
(mbmi->ref_frame != INTRA_FRAME && mbmi->mode != SPLITMV))) {
(mbmi->ref_frame != INTRA_FRAME && !(mbmi->mode == SPLITMV &&
mbmi->partitioning == PARTITIONING_4X4)))) {
// FIXME(rbultje) code ternary symbol once all experiments are merged
mbmi->txfm_size = vp8_read(bc, cm->prob_tx[0]);
if (mbmi->txfm_size != TX_4X4 && mbmi->mode != I8X8_PRED)
if (mbmi->txfm_size != TX_4X4 && mbmi->mode != I8X8_PRED &&
mbmi->mode != SPLITMV)
mbmi->txfm_size += vp8_read(bc, cm->prob_tx[1]);
} else
#endif
......@@ -1297,8 +1299,9 @@ static void read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
(mbmi->ref_frame != INTRA_FRAME && mbmi->mode != SPLITMV))) {
mbmi->txfm_size = TX_16X16;
} else if (cm->txfm_mode >= ALLOW_8X8 &&
((mbmi->ref_frame == INTRA_FRAME && mbmi->mode != B_PRED) ||
(mbmi->ref_frame != INTRA_FRAME && mbmi->mode != SPLITMV))) {
(!(mbmi->ref_frame == INTRA_FRAME && mbmi->mode == B_PRED) &&
!(mbmi->ref_frame != INTRA_FRAME && mbmi->mode == SPLITMV &&
mbmi->partitioning == PARTITIONING_4X4))) {
mbmi->txfm_size = TX_8X8;
} else {
mbmi->txfm_size = TX_4X4;
......
......@@ -384,10 +384,16 @@ static void decode_macroblock(VP8D_COMP *pbi, MACROBLOCKD *xd,
}
}
} else if (mode == SPLITMV) {
DEQUANT_INVOKE(&pbi->dequant, idct_add_y_block)
(xd->qcoeff, xd->block[0].dequant,
xd->predictor, xd->dst.y_buffer,
xd->dst.y_stride, xd->eobs);
if (tx_size == TX_8X8) {
vp8_dequant_idct_add_y_block_8x8_c(xd->qcoeff, xd->block[0].dequant,
xd->predictor, xd->dst.y_buffer,
xd->dst.y_stride, xd->eobs, xd);
} else {
DEQUANT_INVOKE(&pbi->dequant,
idct_add_y_block)(xd->qcoeff, xd->block[0].dequant,
xd->predictor, xd->dst.y_buffer,
xd->dst.y_stride, xd->eobs);
}
} else {
BLOCKD *b = &xd->block[24];
......@@ -489,8 +495,10 @@ static void decode_macroblock(VP8D_COMP *pbi, MACROBLOCKD *xd,
if (!xd->mode_info_context->mbmi.encoded_as_sb) {
#endif
if ((tx_size == TX_8X8 &&
xd->mode_info_context->mbmi.mode != I8X8_PRED)
|| tx_size == TX_16X16)
xd->mode_info_context->mbmi.mode != I8X8_PRED &&
xd->mode_info_context->mbmi.mode != SPLITMV)
|| tx_size == TX_16X16
)
DEQUANT_INVOKE(&pbi->dequant, idct_add_uv_block_8x8) //
(xd->qcoeff + 16 * 16, xd->block[16].dequant,
xd->predictor + 16 * 16, xd->dst.u_buffer, xd->dst.v_buffer,
......
......@@ -493,7 +493,8 @@ int vp8_decode_mb_tokens_8x8(VP8D_COMP *pbi, MACROBLOCKD *xd,
INT16 *qcoeff_ptr = &xd->qcoeff[0];
TX_TYPE tx_type = DCT_DCT;
int bufthred = (xd->mode_info_context->mbmi.mode == I8X8_PRED) ? 16 : 24;
int bufthred = (xd->mode_info_context->mbmi.mode == I8X8_PRED ||
xd->mode_info_context->mbmi.mode == SPLITMV) ? 16 : 24;
if (xd->mode_info_context->mbmi.mode != B_PRED &&
xd->mode_info_context->mbmi.mode != SPLITMV &&
xd->mode_info_context->mbmi.mode != I8X8_PRED) {
......
......@@ -1219,7 +1219,8 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi, vp8_writer *const bc) {
#if CONFIG_TX_SELECT
if (((rf == INTRA_FRAME && mode <= I8X8_PRED) ||
(rf != INTRA_FRAME && mode != SPLITMV)) &&
(rf != INTRA_FRAME && !(mode == SPLITMV &&
mi->partitioning == PARTITIONING_4X4))) &&
pc->txfm_mode == TX_MODE_SELECT &&
!((pc->mb_no_coeff_skip && mi->mb_skip_coeff) ||
(segfeature_active(xd, segment_id, SEG_LVL_EOB) &&
......@@ -1227,7 +1228,7 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi, vp8_writer *const bc) {
TX_SIZE sz = mi->txfm_size;
// FIXME(rbultje) code ternary symbol once all experiments are merged
vp8_write(bc, sz != TX_4X4, pc->prob_tx[0]);
if (sz != TX_4X4 && mode != I8X8_PRED)
if (sz != TX_4X4 && mode != I8X8_PRED && mode != SPLITMV)
vp8_write(bc, sz != TX_8X8, pc->prob_tx[1]);
}
#endif
......
......@@ -2161,7 +2161,9 @@ void vp8cx_encode_inter_macroblock (VP8_COMP *cpi, MACROBLOCK *x,
if (mbmi->mode != B_PRED && mbmi->mode != I8X8_PRED &&
mbmi->mode != SPLITMV) {
cpi->txfm_count[mbmi->txfm_size]++;
} else if (mbmi->mode == I8X8_PRED) {
} else if (mbmi->mode == I8X8_PRED ||
(mbmi->mode == SPLITMV &&
mbmi->partitioning != PARTITIONING_4X4)) {
cpi->txfm_count_8x8p[mbmi->txfm_size]++;
}
} else
......@@ -2169,8 +2171,10 @@ void vp8cx_encode_inter_macroblock (VP8_COMP *cpi, MACROBLOCK *x,
if (mbmi->mode != B_PRED && mbmi->mode != I8X8_PRED &&
mbmi->mode != SPLITMV && cpi->common.txfm_mode >= ALLOW_16X16) {
mbmi->txfm_size = TX_16X16;
} else if (mbmi->mode != B_PRED && mbmi->mode != SPLITMV &&
cpi->common.txfm_mode >= ALLOW_8X8) {
} else if (mbmi->mode != B_PRED &&
!(mbmi->mode == SPLITMV &&
mbmi->partitioning == PARTITIONING_4X4) &&
cpi->common.txfm_mode >= ALLOW_8X8) {
mbmi->txfm_size = TX_8X8;
} else {
mbmi->txfm_size = TX_4X4;
......
......@@ -636,6 +636,7 @@ void vp8_optimize_mby_8x8(MACROBLOCK *x, const VP8_ENCODER_RTCD *rtcd) {
ENTROPY_CONTEXT_PLANES t_above, t_left;
ENTROPY_CONTEXT *ta;
ENTROPY_CONTEXT *tl;
int has_2nd_order = x->e_mbd.mode_info_context->mbmi.mode != SPLITMV;
if (!x->e_mbd.above_context || !x->e_mbd.left_context)
return;
......@@ -645,7 +646,7 @@ void vp8_optimize_mby_8x8(MACROBLOCK *x, const VP8_ENCODER_RTCD *rtcd) {
ta = (ENTROPY_CONTEXT *)&t_above;
tl = (ENTROPY_CONTEXT *)&t_left;
type = PLANE_TYPE_Y_NO_DC;
type = has_2nd_order ? PLANE_TYPE_Y_NO_DC : PLANE_TYPE_Y_WITH_DC;
for (b = 0; b < 16; b += 4) {
optimize_b(x, b, type,
ta + vp8_block2above_8x8[b], tl + vp8_block2left_8x8[b],
......@@ -655,8 +656,11 @@ void vp8_optimize_mby_8x8(MACROBLOCK *x, const VP8_ENCODER_RTCD *rtcd) {
}
// 8x8 always have 2nd roder haar block
check_reset_8x8_2nd_coeffs(&x->e_mbd,
ta + vp8_block2above_8x8[24], tl + vp8_block2left_8x8[24]);
if (has_2nd_order) {
check_reset_8x8_2nd_coeffs(&x->e_mbd,
ta + vp8_block2above_8x8[24],
tl + vp8_block2left_8x8[24]);
}
}
void vp8_optimize_mbuv_8x8(MACROBLOCK *x, const VP8_ENCODER_RTCD *rtcd) {
......@@ -896,11 +900,25 @@ void vp8_encode_inter16x16(const VP8_ENCODER_RTCD *rtcd, MACROBLOCK *x) {
optimize_mb_16x16(x, rtcd);
vp8_inverse_transform_mb_16x16(IF_RTCD(&rtcd->common->idct), xd);
} else if (tx_size == TX_8X8) {
vp8_transform_mb_8x8(x);
vp8_quantize_mb_8x8(x);
if (x->optimize)
optimize_mb_8x8(x, rtcd);
vp8_inverse_transform_mb_8x8(IF_RTCD(&rtcd->common->idct), xd);
if (xd->mode_info_context->mbmi.mode == SPLITMV) {
assert(xd->mode_info_context->mbmi.partitioning != PARTITIONING_4X4);
vp8_transform_mby_8x8(x);
vp8_transform_mbuv_4x4(x);
vp8_quantize_mby_8x8(x);
vp8_quantize_mbuv_4x4(x);
if (x->optimize) {
vp8_optimize_mby_8x8(x, rtcd);
vp8_optimize_mbuv_4x4(x, rtcd);
}
vp8_inverse_transform_mby_8x8(IF_RTCD(&rtcd->common->idct), xd);
vp8_inverse_transform_mbuv_4x4(IF_RTCD(&rtcd->common->idct), xd);
} else {
vp8_transform_mb_8x8(x);
vp8_quantize_mb_8x8(x);
if (x->optimize)
optimize_mb_8x8(x, rtcd);
vp8_inverse_transform_mb_8x8(IF_RTCD(&rtcd->common->idct), xd);
}
} else {
transform_mb_4x4(x);
vp8_quantize_mb_4x4(x);
......
......@@ -366,10 +366,10 @@ typedef struct VP8_ENCODER_RTCD {
} VP8_ENCODER_RTCD;
enum {
BLOCK_16X8,
BLOCK_8X16,
BLOCK_8X8,
BLOCK_4X4,
BLOCK_16X8 = PARTITIONING_16X8,
BLOCK_8X16 = PARTITIONING_8X16,
BLOCK_8X8 = PARTITIONING_8X8,
BLOCK_4X4 = PARTITIONING_4X4,
BLOCK_16X16,
BLOCK_MAX_SEGMENTS,
BLOCK_32X32 = BLOCK_MAX_SEGMENTS,
......
......@@ -1583,8 +1583,8 @@ static int64_t rd_pick_intra8x8block(VP8_COMP *cpi, MACROBLOCK *x, int ib,
} else {
*(a + vp8_block2above[ib]) = besta0;
*(a + vp8_block2above[ib + 1]) = besta1;
*(l + vp8_block2above[ib]) = bestl0;
*(l + vp8_block2above[ib + 4]) = bestl1;
*(l + vp8_block2left[ib]) = bestl0;
*(l + vp8_block2left[ib + 4]) = bestl1;
}
return best_rd;
......@@ -2178,12 +2178,22 @@ static int64_t encode_inter_mb_segment_8x8(MACROBLOCK *x,
int which_label,
int *labelyrate,
int *distortion,
int64_t *otherrd,
ENTROPY_CONTEXT *ta,
ENTROPY_CONTEXT *tl,
const VP8_ENCODER_RTCD *rtcd) {
int i, j;
MACROBLOCKD *xd = &x->e_mbd;
const int iblock[4] = { 0, 1, 4, 5 };
int othercost = 0, otherdist = 0;
ENTROPY_CONTEXT_PLANES tac, tlc;
ENTROPY_CONTEXT *tacp = (ENTROPY_CONTEXT *) &tac,
*tlcp = (ENTROPY_CONTEXT *) &tlc;
if (otherrd) {
memcpy(&tac, ta, sizeof(ENTROPY_CONTEXT_PLANES));
memcpy(&tlc, tl, sizeof(ENTROPY_CONTEXT_PLANES));
}
*distortion = 0;
*labelyrate = 0;
......@@ -2191,8 +2201,9 @@ static int64_t encode_inter_mb_segment_8x8(MACROBLOCK *x,
int ib = vp8_i8x8_block[i];
if (labels[ib] == which_label) {
BLOCKD *bd = &xd->block[ib];
BLOCK *be = &x->block[ib];
int idx = (ib & 8) + ((ib & 2) << 1);
BLOCKD *bd = &xd->block[ib], *bd2 = &xd->block[idx];
BLOCK *be = &x->block[ib], *be2 = &x->block[idx];
int thisdistortion;
vp8_build_inter_predictors4b(xd, bd, 16);
......@@ -2200,24 +2211,66 @@ static int64_t encode_inter_mb_segment_8x8(MACROBLOCK *x,
vp8_build_2nd_inter_predictors4b(xd, bd, 16);
vp8_subtract_4b_c(be, bd, 16);
for (j = 0; j < 4; j += 2) {
bd = &xd->block[ib + iblock[j]];
be = &x->block[ib + iblock[j]];
x->vp8_short_fdct8x4(be->src_diff, be->coeff, 32);
x->quantize_b_4x4_pair(be, be + 1, bd, bd + 1);
thisdistortion = vp8_block_error_c(be->coeff, bd->dqcoeff, 32);
if (xd->mode_info_context->mbmi.txfm_size == TX_4X4) {
if (otherrd) {
x->vp8_short_fdct8x8(be->src_diff, be2->coeff, 32);
x->quantize_b_8x8(be2, bd2);
thisdistortion = vp8_block_error_c(be2->coeff, bd2->dqcoeff, 64);
otherdist += thisdistortion;
othercost += cost_coeffs(x, bd2, PLANE_TYPE_Y_WITH_DC,
tacp + vp8_block2above_8x8[idx],
tlcp + vp8_block2left_8x8[idx], TX_8X8);
}
for (j = 0; j < 4; j += 2) {
bd = &xd->block[ib + iblock[j]];
be = &x->block[ib + iblock[j]];
x->vp8_short_fdct8x4(be->src_diff, be->coeff, 32);
x->quantize_b_4x4_pair(be, be + 1, bd, bd + 1);
thisdistortion = vp8_block_error_c(be->coeff, bd->dqcoeff, 32);
*distortion += thisdistortion;
*labelyrate += cost_coeffs(x, bd, PLANE_TYPE_Y_WITH_DC,
ta + vp8_block2above[ib + iblock[j]],
tl + vp8_block2left[ib + iblock[j]],
TX_4X4);
*labelyrate += cost_coeffs(x, bd + 1, PLANE_TYPE_Y_WITH_DC,
ta + vp8_block2above[ib + iblock[j] + 1],
tl + vp8_block2left[ib + iblock[j]],
TX_4X4);
}
} else /* 8x8 */ {
if (otherrd) {
for (j = 0; j < 4; j += 2) {
BLOCKD *bd3 = &xd->block[ib + iblock[j]];
BLOCK *be3 = &x->block[ib + iblock[j]];
x->vp8_short_fdct8x4(be3->src_diff, be3->coeff, 32);
x->quantize_b_4x4_pair(be3, be3 + 1, bd3, bd3 + 1);
thisdistortion = vp8_block_error_c(be3->coeff, bd3->dqcoeff, 32);
otherdist += thisdistortion;
othercost += cost_coeffs(x, bd3, PLANE_TYPE_Y_WITH_DC,
tacp + vp8_block2above[ib + iblock[j]],
tlcp + vp8_block2left[ib + iblock[j]],
TX_4X4);
othercost += cost_coeffs(x, bd3 + 1, PLANE_TYPE_Y_WITH_DC,
tacp + vp8_block2above[ib + iblock[j] + 1],
tlcp + vp8_block2left[ib + iblock[j]],
TX_4X4);
}
}
x->vp8_short_fdct8x8(be->src_diff, be2->coeff, 32);
x->quantize_b_8x8(be2, bd2);
thisdistortion = vp8_block_error_c(be2->coeff, bd2->dqcoeff, 64);
*distortion += thisdistortion;
*labelyrate += cost_coeffs(x, bd, PLANE_TYPE_Y_WITH_DC,
ta + vp8_block2above[ib + iblock[j]],
tl + vp8_block2left[ib + iblock[j]], TX_4X4);
*labelyrate += cost_coeffs(x, bd + 1, PLANE_TYPE_Y_WITH_DC,
ta + vp8_block2above[ib + iblock[j] + 1],
tl + vp8_block2left[ib + iblock[j]],
TX_4X4);
*labelyrate += cost_coeffs(x, bd2, PLANE_TYPE_Y_WITH_DC,
ta + vp8_block2above_8x8[idx],
tl + vp8_block2left_8x8[idx], TX_8X8);
}
}
}
*distortion >>= 2;
if (otherrd) {
othercost >>= 2;
*otherrd = RDCOST(x->rdmult, x->rddiv, othercost, otherdist);
}
return RDCOST(x->rdmult, x->rddiv, *labelyrate, *distortion);
}
......@@ -2229,7 +2282,8 @@ typedef struct {
int_mv mvp;
int64_t segment_rd;
int segment_num;
SPLITMV_PARTITIONING_TYPE segment_num;
TX_SIZE txfm_size;
int r;
int d;
int segment_yrate;
......@@ -2255,9 +2309,14 @@ int mv_check_bounds(MACROBLOCK *x, int_mv *mv) {
return r;
}
static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
BEST_SEG_INFO *bsi, unsigned int segmentation,
int_mv seg_mvs[16 /* n_blocks */][MAX_REF_FRAMES - 1]) {
static void rd_check_segment_txsize(VP8_COMP *cpi, MACROBLOCK *x,
BEST_SEG_INFO *bsi,
SPLITMV_PARTITIONING_TYPE segmentation,
TX_SIZE tx_size, int64_t *otherrds,
int64_t *rds, int *completed,
/* 16 = n_blocks */
int_mv seg_mvs[16 /* n_blocks */]
[MAX_REF_FRAMES - 1]) {
int i, j;
int const *labels;
int br = 0, bd = 0;
......@@ -2265,12 +2324,12 @@ static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
MB_MODE_INFO * mbmi = &x->e_mbd.mode_info_context->mbmi;
int label_count;
int64_t this_segment_rd = 0;
int64_t this_segment_rd = 0, other_segment_rd;
int label_mv_thresh;
int rate = 0;
int sbr = 0, sbd = 0;
int segmentyrate = 0;
uint8_t best_eobs[16];
uint8_t best_eobs[16] = { 0 };
vp8_variance_fn_ptr_t *v_fn_ptr;
......@@ -2298,20 +2357,23 @@ static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
label_mv_thresh = 1 * bsi->mvthresh / label_count;
// Segmentation method overheads
rate = vp8_cost_token(vp8_mbsplit_tree, vp8_mbsplit_probs, vp8_mbsplit_encodings + segmentation);
rate = vp8_cost_token(vp8_mbsplit_tree, vp8_mbsplit_probs,
vp8_mbsplit_encodings + segmentation);
rate += vp8_cost_mv_ref(cpi, SPLITMV, bsi->mdcounts);
this_segment_rd += RDCOST(x->rdmult, x->rddiv, rate, 0);
br += rate;
other_segment_rd = this_segment_rd;
for (i = 0; i < label_count; i++) {
mbmi->txfm_size = tx_size;
for (i = 0; i < label_count && this_segment_rd < bsi->segment_rd; i++) {
int_mv mode_mv[B_MODE_COUNT], second_mode_mv[B_MODE_COUNT];
int64_t best_label_rd = INT64_MAX;
int64_t best_label_rd = INT64_MAX, best_other_rd = INT64_MAX;
B_PREDICTION_MODE mode_selected = ZERO4X4;
int bestlabelyrate = 0;
// search for the best motion vector on this segment
for (this_mode = LEFT4X4; this_mode <= NEW4X4; this_mode ++) {
int64_t this_rd;
int64_t this_rd, other_rd;
int distortion;
int labelyrate;
ENTROPY_CONTEXT_PLANES t_above_s, t_left_s;
......@@ -2333,21 +2395,23 @@ static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
BLOCK *c;
BLOCKD *e;
// Is the best so far sufficiently good that we cant justify doing and new motion search.
/* Is the best so far sufficiently good that we cant justify doing
* and new motion search. */
if (best_label_rd < label_mv_thresh)
break;
if (cpi->compressor_speed) {
if (segmentation == BLOCK_8X16 || segmentation == BLOCK_16X8) {
if (segmentation == PARTITIONING_8X16 ||
segmentation == PARTITIONING_16X8) {
bsi->mvp.as_int = bsi->sv_mvp[i].as_int;
if (i == 1 && segmentation == BLOCK_16X8)
if (i == 1 && segmentation == PARTITIONING_16X8)
bsi->mvp.as_int = bsi->sv_mvp[2].as_int;
step_param = bsi->sv_istep[i];
}
// use previous block's result as next block's MV predictor.
if (segmentation == BLOCK_4X4 && i > 0) {
if (segmentation == PARTITIONING_4X4 && i > 0) {
bsi->mvp.as_int = x->e_mbd.block[i - 1].bmi.as_mv.first.as_int;
if (i == 4 || i == 8 || i == 12)
bsi->mvp.as_int = x->e_mbd.block[i - 4].bmi.as_mv.first.as_int;
......@@ -2379,7 +2443,8 @@ 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);
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,
......@@ -2389,7 +2454,8 @@ static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
bestsme = thissme;
mode_mv[NEW4X4].as_int = e->bmi.as_mv.first.as_int;
} else {
// The full search result is actually worse so re-instate the previous best vector
/* The full search result is actually worse so re-instate the
* previous best vector */
e->bmi.as_mv.first.as_int = mode_mv[NEW4X4].as_int;
}
}
......@@ -2399,15 +2465,16 @@ static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
int distortion;
unsigned int sse;
cpi->find_fractional_mv_step(x, c, e, &mode_mv[NEW4X4],
bsi->ref_mv, x->errorperbit, v_fn_ptr, XMVCOST,
&distortion, &sse);
bsi->ref_mv, x->errorperbit, v_fn_ptr,
XMVCOST, &distortion, &sse);
// safe motion search result for use in compound prediction
seg_mvs[i][mbmi->ref_frame - 1].as_int = mode_mv[NEW4X4].as_int;
}
} /* NEW4X4 */
else if (mbmi->second_ref_frame && this_mode == NEW4X4) {
// motion search not completed? Then skip newmv for this block with comppred
/* motion search not completed? Then skip newmv for this block with
* comppred */
if (seg_mvs[i][mbmi->second_ref_frame - 1].as_int == INVALID_MV ||
seg_mvs[i][mbmi->ref_frame - 1].as_int == INVALID_MV) {
continue;
......@@ -2429,14 +2496,15 @@ static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
mv_check_bounds(x, &second_mode_mv[this_mode]))
continue;
if (segmentation == BLOCK_4X4) {
if (segmentation == PARTITIONING_4X4) {
this_rd = encode_inter_mb_segment(x, labels, i, &labelyrate,
&distortion,
ta_s, tl_s, IF_RTCD(&cpi->rtcd));
other_rd = this_rd;
} else {
this_rd = encode_inter_mb_segment_8x8(x, labels, i, &labelyrate,
&distortion, ta_s, tl_s,
IF_RTCD(&cpi->rtcd));
&distortion, &other_rd,
ta_s, tl_s, IF_RTCD(&cpi->rtcd));
}
this_rd += RDCOST(x->rdmult, x->rddiv, rate, 0);
rate += labelyrate;
......@@ -2447,9 +2515,20 @@ static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
bestlabelyrate = labelyrate;
mode_selected = this_mode;
best_label_rd = this_rd;
for (j = 0; j < 16; j++)
if (labels[j] == i)
best_eobs[j] = x->e_mbd.block[j].eob;
if (x->e_mbd.mode_info_context->mbmi.txfm_size == TX_4X4) {
for (j = 0; j < 16; j++)
if (labels[j] == i)
best_eobs[j] = x->e_mbd.block[j].eob;
} else {
for (j = 0; j < 4; j++) {
int ib = vp8_i8x8_block[j], idx = j * 4;
if (labels[ib] == i)
best_eobs[idx] = x->e_mbd.block[idx].eob;
}
}
if (other_rd < best_other_rd)
best_other_rd = other_rd;
vpx_memcpy(ta_b, ta_s, sizeof(ENTROPY_CONTEXT_PLANES));
vpx_memcpy(tl_b, tl_s, sizeof(ENTROPY_CONTEXT_PLANES));
......@@ -2461,18 +2540,18 @@ static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
vpx_memcpy(tl, tl_b, sizeof(ENTROPY_CONTEXT_PLANES));
labels2mode(x, labels, i, mode_selected, &mode_mv[mode_selected],
&second_mode_mv[mode_selected], seg_mvs[i], bsi->ref_mv, bsi->second_ref_mv, XMVCOST);
&second_mode_mv[mode_selected], seg_mvs[i],
bsi->ref_mv, bsi->second_ref_mv, XMVCOST);
br += sbr;
bd += sbd;
segmentyrate += bestlabelyrate;
this_segment_rd += best_label_rd;
if (this_segment_rd >= bsi->segment_rd) {