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;
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);
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);
}
int64_t segment_rd;
SPLITMV_PARTITIONING_TYPE segment_num;
+ TX_SIZE txfm_size;
int r;
int d;
int segment_yrate;
return r;
}
-static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
- BEST_SEG_INFO *bsi,
- SPLITMV_PARTITIONING_TYPE 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;
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;
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;
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;
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;
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));
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) {
- break;
- }
-
-
+ other_segment_rd += best_other_rd;
+ if (rds)
+ rds[i] = this_segment_rd;
+ if (otherrds)
+ rds[i] = other_segment_rd;
} /* for each label */
if (this_segment_rd < bsi->segment_rd) {
bsi->segment_yrate = segmentyrate;
bsi->segment_rd = this_segment_rd;
bsi->segment_num = segmentation;
+ bsi->txfm_size = mbmi->txfm_size;
// store everything needed to come back to this!!
for (i = 0; i < 16; i++) {
bsi->eobs[i] = best_eobs[i];
}
}
+
+ if (completed) {
+ *completed = i;
+ }
+}
+
+static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x,
+ BEST_SEG_INFO *bsi,
+ unsigned int segmentation,
+ /* 16 = n_blocks */
+ int_mv seg_mvs[16][MAX_REF_FRAMES - 1],
+ int64_t txfm_cache[NB_TXFM_MODES]) {
+#if CONFIG_TX_SELECT
+ int i, n, c = vp8_mbsplit_count[segmentation];
+
+ if (segmentation == PARTITIONING_4X4) {
+ int64_t rd[16];
+
+ rd_check_segment_txsize(cpi, x, bsi, segmentation, TX_4X4, NULL,
+ rd, &n, seg_mvs);
+ if (n == c) {
+ for (i = 0; i < NB_TXFM_MODES; i++) {
+ if (rd[c - 1] < txfm_cache[i])
+ txfm_cache[i] = rd[c - 1];
+ }
+ }
+ } else {
+ int64_t diff, base_rd;
+ int cost4x4 = vp8_cost_bit(cpi->common.prob_tx[0], 0);
+ int cost8x8 = vp8_cost_bit(cpi->common.prob_tx[0], 1);
+
+ if (cpi->common.txfm_mode == TX_MODE_SELECT) {
+ int64_t rd4x4[4], rd8x8[4];
+ int n4x4, n8x8, nmin;
+ BEST_SEG_INFO bsi4x4, bsi8x8;
+
+ /* factor in cost of cost4x4/8x8 in decision */
+ vpx_memcpy(&bsi4x4, bsi, sizeof(*bsi));
+ vpx_memcpy(&bsi8x8, bsi, sizeof(*bsi));
+ rd_check_segment_txsize(cpi, x, &bsi4x4, segmentation,
+ TX_4X4, NULL, rd4x4, &n4x4, seg_mvs);
+ rd_check_segment_txsize(cpi, x, &bsi8x8, segmentation,
+ TX_8X8, NULL, rd8x8, &n8x8, seg_mvs);
+ if (bsi4x4.segment_num == segmentation) {
+ bsi4x4.segment_rd += RDCOST(x->rdmult, x->rddiv, cost4x4, 0);
+ if (bsi4x4.segment_rd < bsi->segment_rd)
+ vpx_memcpy(bsi, &bsi4x4, sizeof(*bsi));
+ }
+ if (bsi8x8.segment_num == segmentation) {
+ bsi8x8.segment_rd += RDCOST(x->rdmult, x->rddiv, cost8x8, 0);
+ if (bsi8x8.segment_rd < bsi->segment_rd)
+ vpx_memcpy(bsi, &bsi8x8, sizeof(*bsi));
+ }
+ n = n4x4 > n8x8 ? n4x4 : n8x8;
+ if (n == c) {
+ nmin = n4x4 < n8x8 ? n4x4 : n8x8;
+ diff = rd8x8[nmin - 1] - rd4x4[nmin - 1];
+ if (n == n4x4) {
+ base_rd = rd4x4[c - 1];
+ } else {
+ base_rd = rd8x8[c - 1] - diff;
+ }
+ }
+ } else {
+ int64_t rd[4], otherrd[4];
+
+ if (cpi->common.txfm_mode == ONLY_4X4) {
+ rd_check_segment_txsize(cpi, x, bsi, segmentation, TX_4X4, otherrd,
+ rd, &n, seg_mvs);
+ if (n == c) {
+ base_rd = rd[c - 1];
+ diff = otherrd[c - 1] - rd[c - 1];
+ }
+ } else /* use 8x8 transform */ {
+ rd_check_segment_txsize(cpi, x, bsi, segmentation, TX_8X8, otherrd,
+ rd, &n, seg_mvs);
+ if (n == c) {
+ diff = rd[c - 1] - otherrd[c - 1];
+ base_rd = otherrd[c - 1];
+ }
+ }
+ }
+
+ if (n == c) {
+ if (base_rd < txfm_cache[ONLY_4X4]) {
+ txfm_cache[ONLY_4X4] = base_rd;
+ }
+ if (base_rd + diff < txfm_cache[1]) {
+ txfm_cache[ALLOW_8X8] = txfm_cache[ALLOW_16X16] = base_rd + diff;
+ }
+ if (diff < 0) {
+ base_rd += diff + RDCOST(x->rdmult, x->rddiv, cost8x8, 0);
+ } else {
+ base_rd += RDCOST(x->rdmult, x->rddiv, cost4x4, 0);
+ }
+ if (base_rd < txfm_cache[TX_MODE_SELECT]) {
+ txfm_cache[TX_MODE_SELECT] = base_rd;
+ }
+ }
+ }
+#else
+ rd_check_segment_txsize(cpi, x, bsi, segmentation,
+ (segmentation == PARTITIONING_4X4 ||
+ cpi->common.txfm_mode == ONLY_4X4) ? TX_4X4 : TX_8X8,
+ NULL, NULL, NULL, seg_mvs);
+#endif
}
static __inline
int *skippable, int mvthresh,
int_mv seg_mvs[NB_PARTITIONINGS]
[16 /* n_blocks */]
- [MAX_REF_FRAMES - 1]) {
+ [MAX_REF_FRAMES - 1],
+ int64_t txfm_cache[NB_TXFM_MODES]) {
int i;
BEST_SEG_INFO bsi;
MB_MODE_INFO * mbmi = &x->e_mbd.mode_info_context->mbmi;
vpx_memset(&bsi, 0, sizeof(bsi));
+ for (i = 0; i < NB_TXFM_MODES; i++)
+ txfm_cache[i] = INT64_MAX;
bsi.segment_rd = best_rd;
bsi.ref_mv = best_ref_mv;
bsi.mvp.as_int = best_ref_mv->as_int;
bsi.mvthresh = mvthresh;
bsi.mdcounts = mdcounts;
+ bsi.txfm_size = TX_4X4;
for (i = 0; i < 16; i++)
bsi.modes[i] = ZERO4X4;
/* for now, we will keep the original segmentation order
when in best quality mode */
rd_check_segment(cpi, x, &bsi, PARTITIONING_16X8,
- seg_mvs[PARTITIONING_16X8]);
+ seg_mvs[PARTITIONING_16X8], txfm_cache);
rd_check_segment(cpi, x, &bsi, PARTITIONING_8X16,
- seg_mvs[PARTITIONING_8X16]);
+ seg_mvs[PARTITIONING_8X16], txfm_cache);
rd_check_segment(cpi, x, &bsi, PARTITIONING_8X8,
- seg_mvs[PARTITIONING_8X8]);
+ seg_mvs[PARTITIONING_8X8], txfm_cache);
rd_check_segment(cpi, x, &bsi, PARTITIONING_4X4,
- seg_mvs[PARTITIONING_4X4]);
+ seg_mvs[PARTITIONING_4X4], txfm_cache);
} else {
int sr;
rd_check_segment(cpi, x, &bsi, PARTITIONING_8X8,
- seg_mvs[PARTITIONING_8X8]);
-
+ seg_mvs[PARTITIONING_8X8], txfm_cache);
if (bsi.segment_rd < best_rd) {
int tmp_col_min = x->mv_col_min;
/* 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);
vp8_cal_step_param(sr, &bsi.sv_istep[0]);
vp8_cal_step_param(sr, &bsi.sv_istep[1]);
rd_check_segment(cpi, x, &bsi, PARTITIONING_8X16,
- seg_mvs[PARTITIONING_8X16]);
+ seg_mvs[PARTITIONING_8X16], txfm_cache);
+ /* 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);
vp8_cal_step_param(sr, &bsi.sv_istep[0]);
vp8_cal_step_param(sr, &bsi.sv_istep[1]);
rd_check_segment(cpi, x, &bsi, PARTITIONING_16X8,
- seg_mvs[PARTITIONING_16X8]);
+ seg_mvs[PARTITIONING_16X8], txfm_cache);
/* If 8x8 is better than 16x8/8x16, then do 4x4 search */
/* Not skip 4x4 if speed=0 (good quality) */
- if (cpi->sf.no_skip_block4x4_search || bsi.segment_num == BLOCK_8X8) {
+ if (cpi->sf.no_skip_block4x4_search ||
+ bsi.segment_num == PARTITIONING_8X8) {
/* || (sv_segment_rd8x8-bsi.segment_rd) < sv_segment_rd8x8>>5) */
bsi.mvp.as_int = bsi.sv_mvp[0].as_int;
rd_check_segment(cpi, x, &bsi, PARTITIONING_4X4,
- seg_mvs[PARTITIONING_4X4]);
+ seg_mvs[PARTITIONING_4X4], txfm_cache);
}
/* restore UMV window */
*returntotrate = bsi.r;
*returndistortion = bsi.d;
*returnyrate = bsi.segment_yrate;
- *skippable = mby_is_skippable_4x4(&x->e_mbd, 0);
+ *skippable = bsi.txfm_size == TX_4X4 ?
+ mby_is_skippable_4x4(&x->e_mbd, 0) :
+ mby_is_skippable_8x8(&x->e_mbd, 0);
/* save partitions */
+ mbmi->txfm_size = bsi.txfm_size;
mbmi->partitioning = bsi.segment_num;
x->partition_info->count = vp8_mbsplit_count[bsi.segment_num];
(mbmi->ref_frame == GOLDEN_FRAME) ?
cpi->rd_threshes[THR_NEWG] : this_rd_thresh;
- mbmi->txfm_size = TX_4X4; // FIXME use 8x8 in case of 8x8/8x16/16x8
tmp_rd = rd_pick_best_mbsegmentation(cpi, x, &best_ref_mv,
second_ref, best_yrd, mdcounts,
&rate, &rate_y, &distortion,
&skippable,
- this_rd_thresh, seg_mvs);
+ this_rd_thresh, seg_mvs,
+ txfm_cache);
rate2 += rate;
distortion2 += distortion;
if (!mode_excluded && this_rd != INT64_MAX) {
for (i = 0; i < NB_TXFM_MODES; i++) {
int64_t adj_rd;
- if (this_mode != B_PRED && this_mode != SPLITMV) {
+ if (this_mode != B_PRED) {
adj_rd = this_rd + txfm_cache[i] - txfm_cache[cm->txfm_mode];
} else {
adj_rd = this_rd;