| Index: source/libvpx/vp9/encoder/vp9_rdopt.c
|
| ===================================================================
|
| --- source/libvpx/vp9/encoder/vp9_rdopt.c (revision 292072)
|
| +++ source/libvpx/vp9/encoder/vp9_rdopt.c (working copy)
|
| @@ -41,10 +41,15 @@
|
| #define RD_THRESH_MAX_FACT 64
|
| #define RD_THRESH_INC 1
|
|
|
| -#define LAST_FRAME_MODE_MASK 0xFFEDCD60
|
| -#define GOLDEN_FRAME_MODE_MASK 0xFFDA3BB0
|
| -#define ALT_REF_MODE_MASK 0xFFC648D0
|
| +#define LAST_FRAME_MODE_MASK ((1 << GOLDEN_FRAME) | (1 << ALTREF_FRAME) | \
|
| + (1 << INTRA_FRAME))
|
| +#define GOLDEN_FRAME_MODE_MASK ((1 << LAST_FRAME) | (1 << ALTREF_FRAME) | \
|
| + (1 << INTRA_FRAME))
|
| +#define ALT_REF_MODE_MASK ((1 << LAST_FRAME) | (1 << GOLDEN_FRAME) | \
|
| + (1 << INTRA_FRAME))
|
|
|
| +#define SECOND_REF_FRAME_MASK ((1 << ALTREF_FRAME) | 0x01)
|
| +
|
| #define MIN_EARLY_TERM_INDEX 3
|
|
|
| typedef struct {
|
| @@ -86,6 +91,12 @@
|
|
|
| {NEARMV, {LAST_FRAME, NONE}},
|
| {NEARMV, {ALTREF_FRAME, NONE}},
|
| + {NEARMV, {GOLDEN_FRAME, NONE}},
|
| +
|
| + {ZEROMV, {LAST_FRAME, NONE}},
|
| + {ZEROMV, {GOLDEN_FRAME, NONE}},
|
| + {ZEROMV, {ALTREF_FRAME, NONE}},
|
| +
|
| {NEARESTMV, {LAST_FRAME, ALTREF_FRAME}},
|
| {NEARESTMV, {GOLDEN_FRAME, ALTREF_FRAME}},
|
|
|
| @@ -93,13 +104,9 @@
|
|
|
| {NEARMV, {LAST_FRAME, ALTREF_FRAME}},
|
| {NEWMV, {LAST_FRAME, ALTREF_FRAME}},
|
| - {NEARMV, {GOLDEN_FRAME, NONE}},
|
| {NEARMV, {GOLDEN_FRAME, ALTREF_FRAME}},
|
| {NEWMV, {GOLDEN_FRAME, ALTREF_FRAME}},
|
|
|
| - {ZEROMV, {LAST_FRAME, NONE}},
|
| - {ZEROMV, {GOLDEN_FRAME, NONE}},
|
| - {ZEROMV, {ALTREF_FRAME, NONE}},
|
| {ZEROMV, {LAST_FRAME, ALTREF_FRAME}},
|
| {ZEROMV, {GOLDEN_FRAME, ALTREF_FRAME}},
|
|
|
| @@ -169,7 +176,7 @@
|
| int i;
|
| int64_t rate_sum = 0;
|
| int64_t dist_sum = 0;
|
| - const int ref = xd->mi[0]->mbmi.ref_frame[0];
|
| + const int ref = xd->mi[0].src_mi->mbmi.ref_frame[0];
|
| unsigned int sse;
|
| unsigned int var = 0;
|
| unsigned int sum_sse = 0;
|
| @@ -244,7 +251,7 @@
|
| *out_dist_sum = dist_sum << 4;
|
| }
|
|
|
| -int64_t vp9_block_error_c(const int16_t *coeff, const int16_t *dqcoeff,
|
| +int64_t vp9_block_error_c(const tran_low_t *coeff, const tran_low_t *dqcoeff,
|
| intptr_t block_size, int64_t *ssz) {
|
| int i;
|
| int64_t error = 0, sqcoeff = 0;
|
| @@ -277,13 +284,13 @@
|
| const int16_t *scan, const int16_t *nb,
|
| int use_fast_coef_costing) {
|
| MACROBLOCKD *const xd = &x->e_mbd;
|
| - MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
|
| + MB_MODE_INFO *mbmi = &xd->mi[0].src_mi->mbmi;
|
| const struct macroblock_plane *p = &x->plane[plane];
|
| const struct macroblockd_plane *pd = &xd->plane[plane];
|
| const PLANE_TYPE type = pd->plane_type;
|
| const int16_t *band_count = &band_counts[tx_size][1];
|
| const int eob = p->eobs[block];
|
| - const int16_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block);
|
| + const tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block);
|
| unsigned int (*token_costs)[2][COEFF_CONTEXTS][ENTROPY_TOKENS] =
|
| x->token_costs[tx_size][type][is_inter_block(mbmi)];
|
| uint8_t token_cache[32 * 32];
|
| @@ -353,13 +360,13 @@
|
| const struct macroblockd_plane *const pd = &xd->plane[plane];
|
| int64_t this_sse;
|
| int shift = tx_size == TX_32X32 ? 0 : 2;
|
| - int16_t *const coeff = BLOCK_OFFSET(p->coeff, block);
|
| - int16_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
|
| + tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block);
|
| + tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
|
| args->dist = vp9_block_error(coeff, dqcoeff, 16 << ss_txfrm_size,
|
| &this_sse) >> shift;
|
| args->sse = this_sse >> shift;
|
|
|
| - if (x->skip_encode && !is_inter_block(&xd->mi[0]->mbmi)) {
|
| + if (x->skip_encode && !is_inter_block(&xd->mi[0].src_mi->mbmi)) {
|
| // TODO(jingning): tune the model to better capture the distortion.
|
| int64_t p = (pd->dequant[1] * pd->dequant[1] *
|
| (1 << ss_txfrm_size)) >> (shift + 2);
|
| @@ -384,7 +391,7 @@
|
| struct rdcost_block_args *args = arg;
|
| MACROBLOCK *const x = args->x;
|
| MACROBLOCKD *const xd = &x->e_mbd;
|
| - MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
|
| + MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi;
|
| int64_t rd1, rd2, rd;
|
|
|
| if (args->skip)
|
| @@ -400,8 +407,8 @@
|
| dist_block(plane, block, tx_size, args);
|
| } else if (x->skip_txfm[(plane << 2) + (block >> (tx_size << 1))] == 2) {
|
| // compute DC coefficient
|
| - int16_t *const coeff = BLOCK_OFFSET(x->plane[plane].coeff, block);
|
| - int16_t *const dqcoeff = BLOCK_OFFSET(xd->plane[plane].dqcoeff, block);
|
| + tran_low_t *const coeff = BLOCK_OFFSET(x->plane[plane].coeff, block);
|
| + tran_low_t *const dqcoeff = BLOCK_OFFSET(xd->plane[plane].dqcoeff, block);
|
| vp9_xform_quant_dc(x, plane, block, plane_bsize, tx_size);
|
| args->sse = x->bsse[(plane << 2) + (block >> (tx_size << 1))] << 4;
|
| args->dist = args->sse;
|
| @@ -456,7 +463,7 @@
|
| args.use_fast_coef_costing = use_fast_coef_casting;
|
|
|
| if (plane == 0)
|
| - xd->mi[0]->mbmi.tx_size = tx_size;
|
| + xd->mi[0].src_mi->mbmi.tx_size = tx_size;
|
|
|
| vp9_get_entropy_contexts(bsize, tx_size, pd, args.t_above, args.t_left);
|
|
|
| @@ -486,7 +493,7 @@
|
| VP9_COMMON *const cm = &cpi->common;
|
| const TX_SIZE largest_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode];
|
| MACROBLOCKD *const xd = &x->e_mbd;
|
| - MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
|
| + MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi;
|
|
|
| mbmi->tx_size = MIN(max_tx_size, largest_tx_size);
|
|
|
| @@ -506,7 +513,7 @@
|
| const TX_SIZE max_tx_size = max_txsize_lookup[bs];
|
| VP9_COMMON *const cm = &cpi->common;
|
| MACROBLOCKD *const xd = &x->e_mbd;
|
| - MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
|
| + MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi;
|
| vp9_prob skip_prob = vp9_get_skip_prob(cm, xd);
|
| int r[TX_SIZES][2], s[TX_SIZES];
|
| int64_t d[TX_SIZES], sse[TX_SIZES];
|
| @@ -593,7 +600,7 @@
|
| int64_t sse;
|
| int64_t *ret_sse = psse ? psse : &sse;
|
|
|
| - assert(bs == xd->mi[0]->mbmi.sb_type);
|
| + assert(bs == xd->mi[0].src_mi->mbmi.sb_type);
|
|
|
| if (cpi->sf.tx_size_search_method == USE_LARGESTALL || xd->lossless) {
|
| vpx_memset(txfm_cache, 0, TX_MODES * sizeof(int64_t));
|
| @@ -657,7 +664,7 @@
|
|
|
| vpx_memcpy(ta, a, sizeof(ta));
|
| vpx_memcpy(tl, l, sizeof(tl));
|
| - xd->mi[0]->mbmi.tx_size = TX_4X4;
|
| + xd->mi[0].src_mi->mbmi.tx_size = TX_4X4;
|
|
|
| for (mode = DC_PRED; mode <= TM_PRED; ++mode) {
|
| int64_t this_rd;
|
| @@ -685,8 +692,8 @@
|
| uint8_t *const dst = &dst_init[idx * 4 + idy * 4 * dst_stride];
|
| int16_t *const src_diff = raster_block_offset_int16(BLOCK_8X8, block,
|
| p->src_diff);
|
| - int16_t *const coeff = BLOCK_OFFSET(x->plane[0].coeff, block);
|
| - xd->mi[0]->bmi[block].as_mode = mode;
|
| + tran_low_t *const coeff = BLOCK_OFFSET(x->plane[0].coeff, block);
|
| + xd->mi[0].src_mi->bmi[block].as_mode = mode;
|
| vp9_predict_intra_block(xd, block, 1,
|
| TX_4X4, mode,
|
| x->skip_encode ? src : dst,
|
| @@ -759,10 +766,10 @@
|
| int64_t best_rd) {
|
| int i, j;
|
| const MACROBLOCKD *const xd = &mb->e_mbd;
|
| - MODE_INFO *const mic = xd->mi[0];
|
| - const MODE_INFO *above_mi = xd->mi[-xd->mi_stride];
|
| - const MODE_INFO *left_mi = xd->left_available ? xd->mi[-1] : NULL;
|
| - const BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type;
|
| + MODE_INFO *const mic = xd->mi[0].src_mi;
|
| + const MODE_INFO *above_mi = xd->mi[-xd->mi_stride].src_mi;
|
| + const MODE_INFO *left_mi = xd->left_available ? xd->mi[-1].src_mi : NULL;
|
| + const BLOCK_SIZE bsize = xd->mi[0].src_mi->mbmi.sb_type;
|
| const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize];
|
| const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize];
|
| int idx, idy;
|
| @@ -829,7 +836,7 @@
|
| PREDICTION_MODE mode;
|
| PREDICTION_MODE mode_selected = DC_PRED;
|
| MACROBLOCKD *const xd = &x->e_mbd;
|
| - MODE_INFO *const mic = xd->mi[0];
|
| + MODE_INFO *const mic = xd->mi[0].src_mi;
|
| int this_rate, this_rate_tokenonly, s;
|
| int64_t this_distortion, this_rd;
|
| TX_SIZE best_tx = TX_4X4;
|
| @@ -843,8 +850,8 @@
|
| /* Y Search for intra prediction mode */
|
| for (mode = DC_PRED; mode <= TM_PRED; mode++) {
|
| int64_t local_tx_cache[TX_MODES];
|
| - MODE_INFO *above_mi = xd->mi[-xd->mi_stride];
|
| - MODE_INFO *left_mi = xd->left_available ? xd->mi[-1] : NULL;
|
| + MODE_INFO *above_mi = xd->mi[-xd->mi_stride].src_mi;
|
| + MODE_INFO *left_mi = xd->left_available ? xd->mi[-1].src_mi : NULL;
|
|
|
| if (cpi->common.frame_type == KEY_FRAME) {
|
| const PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, 0);
|
| @@ -895,7 +902,7 @@
|
| int64_t *sse, BLOCK_SIZE bsize,
|
| int64_t ref_best_rd) {
|
| MACROBLOCKD *const xd = &x->e_mbd;
|
| - MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
|
| + MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi;
|
| const TX_SIZE uv_tx_size = get_uv_tx_size(mbmi, &xd->plane[1]);
|
| int plane;
|
| int pnrate = 0, pnskip = 1;
|
| @@ -952,7 +959,7 @@
|
| if (!(cpi->sf.intra_uv_mode_mask[max_tx_size] & (1 << mode)))
|
| continue;
|
|
|
| - xd->mi[0]->mbmi.uv_mode = mode;
|
| + xd->mi[0].src_mi->mbmi.uv_mode = mode;
|
|
|
| super_block_uvrd(cpi, x, &this_rate_tokenonly,
|
| &this_distortion, &s, &this_sse, bsize, best_rd);
|
| @@ -974,7 +981,7 @@
|
| }
|
| }
|
|
|
| - xd->mi[0]->mbmi.uv_mode = mode_selected;
|
| + xd->mi[0].src_mi->mbmi.uv_mode = mode_selected;
|
| return best_rd;
|
| }
|
|
|
| @@ -985,7 +992,7 @@
|
| const VP9_COMMON *cm = &cpi->common;
|
| int64_t unused;
|
|
|
| - x->e_mbd.mi[0]->mbmi.uv_mode = DC_PRED;
|
| + x->e_mbd.mi[0].src_mi->mbmi.uv_mode = DC_PRED;
|
| super_block_uvrd(cpi, x, rate_tokenonly, distortion,
|
| skippable, &unused, bsize, INT64_MAX);
|
| *rate = *rate_tokenonly + cpi->intra_uv_mode_cost[cm->frame_type][DC_PRED];
|
| @@ -1011,7 +1018,7 @@
|
| rate_uv, rate_uv_tokenonly, dist_uv, skip_uv,
|
| bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize, max_tx_size);
|
| }
|
| - *mode_uv = x->e_mbd.mi[0]->mbmi.uv_mode;
|
| + *mode_uv = x->e_mbd.mi[0].src_mi->mbmi.uv_mode;
|
| }
|
|
|
| static int cost_mv_ref(const VP9_COMP *cpi, PREDICTION_MODE mode,
|
| @@ -1033,7 +1040,7 @@
|
| int_mv seg_mvs[MAX_REF_FRAMES],
|
| int_mv *best_ref_mv[2], const int *mvjcost,
|
| int *mvcost[2]) {
|
| - MODE_INFO *const mic = xd->mi[0];
|
| + MODE_INFO *const mic = xd->mi[0].src_mi;
|
| const MB_MODE_INFO *const mbmi = &mic->mbmi;
|
| int thismvcost = 0;
|
| int idx, idy;
|
| @@ -1095,7 +1102,7 @@
|
| MACROBLOCKD *xd = &x->e_mbd;
|
| struct macroblockd_plane *const pd = &xd->plane[0];
|
| struct macroblock_plane *const p = &x->plane[0];
|
| - MODE_INFO *const mi = xd->mi[0];
|
| + MODE_INFO *const mi = xd->mi[0].src_mi;
|
| const BLOCK_SIZE plane_bsize = get_plane_block_size(mi->mbmi.sb_type, pd);
|
| const int width = 4 * num_4x4_blocks_wide_lookup[plane_bsize];
|
| const int height = 4 * num_4x4_blocks_high_lookup[plane_bsize];
|
| @@ -1132,7 +1139,7 @@
|
| for (idy = 0; idy < height / 4; ++idy) {
|
| for (idx = 0; idx < width / 4; ++idx) {
|
| int64_t ssz, rd, rd1, rd2;
|
| - int16_t* coeff;
|
| + tran_low_t* coeff;
|
|
|
| k += (idy * 2 + idx);
|
| coeff = BLOCK_OFFSET(p->coeff, k);
|
| @@ -1194,7 +1201,7 @@
|
| }
|
|
|
| static INLINE void mi_buf_shift(MACROBLOCK *x, int i) {
|
| - MB_MODE_INFO *const mbmi = &x->e_mbd.mi[0]->mbmi;
|
| + MB_MODE_INFO *const mbmi = &x->e_mbd.mi[0].src_mi->mbmi;
|
| struct macroblock_plane *const p = &x->plane[0];
|
| struct macroblockd_plane *const pd = &x->e_mbd.plane[0];
|
|
|
| @@ -1209,7 +1216,7 @@
|
|
|
| static INLINE void mi_buf_restore(MACROBLOCK *x, struct buf_2d orig_src,
|
| struct buf_2d orig_pre[2]) {
|
| - MB_MODE_INFO *mbmi = &x->e_mbd.mi[0]->mbmi;
|
| + MB_MODE_INFO *mbmi = &x->e_mbd.mi[0].src_mi->mbmi;
|
| x->plane[0].src = orig_src;
|
| x->e_mbd.plane[0].pre[0] = orig_pre[0];
|
| if (has_second_ref(mbmi))
|
| @@ -1224,11 +1231,9 @@
|
| // TODO(aconverse): Find out if this is still productive then clean up or remove
|
| static int check_best_zero_mv(
|
| const VP9_COMP *cpi, const uint8_t mode_context[MAX_REF_FRAMES],
|
| - int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES],
|
| - int inter_mode_mask, int this_mode,
|
| + int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES], int this_mode,
|
| const MV_REFERENCE_FRAME ref_frames[2]) {
|
| - if ((inter_mode_mask & (1 << ZEROMV)) &&
|
| - (this_mode == NEARMV || this_mode == NEARESTMV || this_mode == ZEROMV) &&
|
| + if ((this_mode == NEARMV || this_mode == NEARESTMV || this_mode == ZEROMV) &&
|
| frame_mv[this_mode][ref_frames[0]].as_int == 0 &&
|
| (ref_frames[1] == NONE ||
|
| frame_mv[this_mode][ref_frames[1]].as_int == 0)) {
|
| @@ -1274,7 +1279,7 @@
|
| int i;
|
| BEST_SEG_INFO *bsi = bsi_buf + filter_idx;
|
| MACROBLOCKD *xd = &x->e_mbd;
|
| - MODE_INFO *mi = xd->mi[0];
|
| + MODE_INFO *mi = xd->mi[0].src_mi;
|
| MB_MODE_INFO *mbmi = &mi->mbmi;
|
| int mode_idx;
|
| int k, br = 0, idx, idy;
|
| @@ -1346,7 +1351,6 @@
|
| continue;
|
|
|
| if (!check_best_zero_mv(cpi, mbmi->mode_context, frame_mv,
|
| - inter_mode_mask,
|
| this_mode, mbmi->ref_frame))
|
| continue;
|
|
|
| @@ -1716,7 +1720,7 @@
|
| ctx->skip = x->skip;
|
| ctx->skippable = skippable;
|
| ctx->best_mode_index = mode_index;
|
| - ctx->mic = *xd->mi[0];
|
| + ctx->mic = *xd->mi[0].src_mi;
|
| ctx->single_pred_diff = (int)comp_pred_diff[SINGLE_REFERENCE];
|
| ctx->comp_pred_diff = (int)comp_pred_diff[COMPOUND_REFERENCE];
|
| ctx->hybrid_pred_diff = (int)comp_pred_diff[REFERENCE_MODE_SELECT];
|
| @@ -1737,7 +1741,7 @@
|
| const VP9_COMMON *cm = &cpi->common;
|
| const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame);
|
| MACROBLOCKD *const xd = &x->e_mbd;
|
| - MODE_INFO *const mi = xd->mi[0];
|
| + MODE_INFO *const mi = xd->mi[0].src_mi;
|
| int_mv *const candidates = mi->mbmi.ref_mvs[ref_frame];
|
| const struct scale_factors *const sf = &cm->frame_refs[ref_frame - 1].sf;
|
|
|
| @@ -1767,7 +1771,7 @@
|
| int_mv *tmp_mv, int *rate_mv) {
|
| MACROBLOCKD *xd = &x->e_mbd;
|
| const VP9_COMMON *cm = &cpi->common;
|
| - MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
|
| + MB_MODE_INFO *mbmi = &xd->mi[0].src_mi->mbmi;
|
| struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0, 0}};
|
| int bestsme = INT_MAX;
|
| int step_param;
|
| @@ -1894,7 +1898,7 @@
|
| const int pw = 4 * num_4x4_blocks_wide_lookup[bsize];
|
| const int ph = 4 * num_4x4_blocks_high_lookup[bsize];
|
| MACROBLOCKD *xd = &x->e_mbd;
|
| - MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
|
| + MB_MODE_INFO *mbmi = &xd->mi[0].src_mi->mbmi;
|
| const int refs[2] = { mbmi->ref_frame[0],
|
| mbmi->ref_frame[1] < 0 ? 0 : mbmi->ref_frame[1] };
|
| int_mv ref_mv[2];
|
| @@ -2136,7 +2140,7 @@
|
| VP9_COMMON *cm = &cpi->common;
|
| RD_OPT *rd_opt = &cpi->rd;
|
| MACROBLOCKD *xd = &x->e_mbd;
|
| - MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
|
| + MB_MODE_INFO *mbmi = &xd->mi[0].src_mi->mbmi;
|
| const int is_comp_pred = has_second_ref(mbmi);
|
| const int this_mode = mbmi->mode;
|
| int_mv *frame_mv = mode_mv[this_mode];
|
| @@ -2165,9 +2169,9 @@
|
| if (pred_filter_search) {
|
| INTERP_FILTER af = SWITCHABLE, lf = SWITCHABLE;
|
| if (xd->up_available)
|
| - af = xd->mi[-xd->mi_stride]->mbmi.interp_filter;
|
| + af = xd->mi[-xd->mi_stride].src_mi->mbmi.interp_filter;
|
| if (xd->left_available)
|
| - lf = xd->mi[-1]->mbmi.interp_filter;
|
| + lf = xd->mi[-1].src_mi->mbmi.interp_filter;
|
|
|
| if ((this_mode != NEWMV) || (af == lf))
|
| best_filter = af;
|
| @@ -2212,7 +2216,7 @@
|
| return INT64_MAX;
|
| *rate2 += rate_mv;
|
| frame_mv[refs[0]].as_int =
|
| - xd->mi[0]->bmi[0].as_mv[0].as_int = tmp_mv.as_int;
|
| + xd->mi[0].src_mi->bmi[0].as_mv[0].as_int = tmp_mv.as_int;
|
| single_newmv[refs[0]].as_int = tmp_mv.as_int;
|
| }
|
| }
|
| @@ -2464,7 +2468,7 @@
|
| TX_SIZE max_uv_tx_size;
|
| x->skip_encode = 0;
|
| ctx->skip = 0;
|
| - xd->mi[0]->mbmi.ref_frame[0] = INTRA_FRAME;
|
| + xd->mi[0].src_mi->mbmi.ref_frame[0] = INTRA_FRAME;
|
|
|
| if (bsize >= BLOCK_8X8) {
|
| if (rd_pick_intra_sby_mode(cpi, x, &rate_y, &rate_y_tokenonly,
|
| @@ -2473,7 +2477,7 @@
|
| *returnrate = INT_MAX;
|
| return;
|
| }
|
| - max_uv_tx_size = get_uv_tx_size_impl(xd->mi[0]->mbmi.tx_size, bsize,
|
| + max_uv_tx_size = get_uv_tx_size_impl(xd->mi[0].src_mi->mbmi.tx_size, bsize,
|
| pd[1].subsampling_x,
|
| pd[1].subsampling_y);
|
| rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv, &rate_uv_tokenonly,
|
| @@ -2485,7 +2489,7 @@
|
| *returnrate = INT_MAX;
|
| return;
|
| }
|
| - max_uv_tx_size = get_uv_tx_size_impl(xd->mi[0]->mbmi.tx_size, bsize,
|
| + max_uv_tx_size = get_uv_tx_size_impl(xd->mi[0].src_mi->mbmi.tx_size, bsize,
|
| pd[1].subsampling_x,
|
| pd[1].subsampling_y);
|
| rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv, &rate_uv_tokenonly,
|
| @@ -2510,7 +2514,7 @@
|
| }
|
| }
|
|
|
| - ctx->mic = *xd->mi[0];
|
| + ctx->mic = *xd->mi[0].src_mi;
|
| }
|
|
|
| // Updating rd_thresh_freq_fact[] here means that the different
|
| @@ -2547,7 +2551,7 @@
|
| VP9_COMMON *const cm = &cpi->common;
|
| RD_OPT *const rd_opt = &cpi->rd;
|
| MACROBLOCKD *const xd = &x->e_mbd;
|
| - MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
|
| + MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi;
|
| const struct segmentation *const seg = &cm->seg;
|
| struct macroblockd_plane *const pd = xd->plane;
|
| PREDICTION_MODE this_mode;
|
| @@ -2570,28 +2574,29 @@
|
| int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS];
|
| MB_MODE_INFO best_mbmode;
|
| int best_mode_skippable = 0;
|
| - int mode_index, best_mode_index = -1;
|
| + int midx, best_mode_index = -1;
|
| unsigned int ref_costs_single[MAX_REF_FRAMES], ref_costs_comp[MAX_REF_FRAMES];
|
| vp9_prob comp_mode_p;
|
| int64_t best_intra_rd = INT64_MAX;
|
| - int64_t best_inter_rd = INT64_MAX;
|
| + unsigned int best_pred_sse = UINT_MAX;
|
| PREDICTION_MODE best_intra_mode = DC_PRED;
|
| - MV_REFERENCE_FRAME best_inter_ref_frame = LAST_FRAME;
|
| int rate_uv_intra[TX_SIZES], rate_uv_tokenonly[TX_SIZES];
|
| int64_t dist_uv[TX_SIZES];
|
| int skip_uv[TX_SIZES];
|
| PREDICTION_MODE mode_uv[TX_SIZES];
|
| - int intra_cost_penalty = 20 * vp9_dc_quant(cm->base_qindex, cm->y_dc_delta_q);
|
| + const int intra_cost_penalty =
|
| + 20 * vp9_dc_quant(cm->base_qindex, cm->y_dc_delta_q, cm->bit_depth);
|
| int best_skip2 = 0;
|
| - int mode_skip_mask = 0;
|
| + uint8_t ref_frame_skip_mask[2] = { 0 };
|
| + uint16_t mode_skip_mask[MAX_REF_FRAMES] = { 0 };
|
| int mode_skip_start = cpi->sf.mode_skip_start + 1;
|
| const int *const rd_threshes = rd_opt->threshes[segment_id][bsize];
|
| const int *const rd_thresh_freq_fact = rd_opt->thresh_freq_fact[bsize];
|
| + int mode_threshold[MAX_MODES];
|
| + int *mode_map = rd_opt->mode_map[bsize];
|
| const int mode_search_skip_flags = cpi->sf.mode_search_skip_flags;
|
| - const int intra_y_mode_mask =
|
| - cpi->sf.intra_y_mode_mask[max_txsize_lookup[bsize]];
|
| - int inter_mode_mask = cpi->sf.inter_mode_mask[bsize];
|
| vp9_zero(best_mbmode);
|
| +
|
| x->skip_encode = cpi->sf.skip_encode_frame && x->q_index < QIDX_SKIP_THRESH;
|
|
|
| estimate_ref_frame_costs(cm, xd, segment_id, ref_costs_single, ref_costs_comp,
|
| @@ -2627,23 +2632,17 @@
|
| }
|
|
|
| for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
|
| - // All modes from vp9_mode_order that use this frame as any ref
|
| - static const int ref_frame_mask_all[] = {
|
| - 0x0, 0x123291, 0x25c444, 0x39b722
|
| - };
|
| - // Fixed mv modes (NEARESTMV, NEARMV, ZEROMV) from vp9_mode_order that use
|
| - // this frame as their primary ref
|
| - static const int ref_frame_mask_fixedmv[] = {
|
| - 0x0, 0x121281, 0x24c404, 0x080102
|
| - };
|
| if (!(cpi->ref_frame_flags & flag_list[ref_frame])) {
|
| - // Skip modes for missing references
|
| - mode_skip_mask |= ref_frame_mask_all[ref_frame];
|
| + // Skip checking missing references in both single and compound reference
|
| + // modes. Note that a mode will be skipped iff both reference frames
|
| + // are masked out.
|
| + ref_frame_skip_mask[0] |= (1 << ref_frame);
|
| + ref_frame_skip_mask[1] |= SECOND_REF_FRAME_MASK;
|
| } else if (cpi->sf.reference_masking) {
|
| for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) {
|
| // Skip fixed mv modes for poor references
|
| if ((x->pred_mv_sad[ref_frame] >> 2) > x->pred_mv_sad[i]) {
|
| - mode_skip_mask |= ref_frame_mask_fixedmv[ref_frame];
|
| + mode_skip_mask[ref_frame] |= INTER_NEAREST_NEAR_ZERO;
|
| break;
|
| }
|
| }
|
| @@ -2652,7 +2651,8 @@
|
| // then do nothing if the current ref frame is not allowed..
|
| if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) &&
|
| vp9_get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) != (int)ref_frame) {
|
| - mode_skip_mask |= ref_frame_mask_all[ref_frame];
|
| + ref_frame_skip_mask[0] |= (1 << ref_frame);
|
| + ref_frame_skip_mask[1] |= SECOND_REF_FRAME_MASK;
|
| }
|
| }
|
|
|
| @@ -2665,24 +2665,51 @@
|
| // an unfiltered alternative. We allow near/nearest as well
|
| // because they may result in zero-zero MVs but be cheaper.
|
| if (cpi->rc.is_src_frame_alt_ref && (cpi->oxcf.arnr_max_frames == 0)) {
|
| - mode_skip_mask =
|
| - ~((1 << THR_NEARESTA) | (1 << THR_NEARA) | (1 << THR_ZEROA));
|
| + ref_frame_skip_mask[0] = (1 << LAST_FRAME) | (1 << GOLDEN_FRAME);
|
| + ref_frame_skip_mask[1] = SECOND_REF_FRAME_MASK;
|
| + mode_skip_mask[ALTREF_FRAME] = ~INTER_NEAREST_NEAR_ZERO;
|
| if (frame_mv[NEARMV][ALTREF_FRAME].as_int != 0)
|
| - mode_skip_mask |= (1 << THR_NEARA);
|
| + mode_skip_mask[ALTREF_FRAME] |= (1 << NEARMV);
|
| if (frame_mv[NEARESTMV][ALTREF_FRAME].as_int != 0)
|
| - mode_skip_mask |= (1 << THR_NEARESTA);
|
| + mode_skip_mask[ALTREF_FRAME] |= (1 << NEARESTMV);
|
| }
|
| }
|
|
|
| + if (cpi->rc.is_src_frame_alt_ref) {
|
| + if (cpi->sf.alt_ref_search_fp) {
|
| + mode_skip_mask[ALTREF_FRAME] = 0;
|
| + ref_frame_skip_mask[0] = ~(1 << ALTREF_FRAME);
|
| + ref_frame_skip_mask[1] = SECOND_REF_FRAME_MASK;
|
| + }
|
| + }
|
| +
|
| if (bsize > cpi->sf.max_intra_bsize) {
|
| - const int all_intra_modes = (1 << THR_DC) | (1 << THR_TM) |
|
| - (1 << THR_H_PRED) | (1 << THR_V_PRED) | (1 << THR_D135_PRED) |
|
| - (1 << THR_D207_PRED) | (1 << THR_D153_PRED) | (1 << THR_D63_PRED) |
|
| - (1 << THR_D117_PRED) | (1 << THR_D45_PRED);
|
| - mode_skip_mask |= all_intra_modes;
|
| + ref_frame_skip_mask[0] |= (1 << INTRA_FRAME);
|
| + ref_frame_skip_mask[1] |= (1 << INTRA_FRAME);
|
| }
|
|
|
| - for (mode_index = 0; mode_index < MAX_MODES; ++mode_index) {
|
| + mode_skip_mask[INTRA_FRAME] |=
|
| + ~(cpi->sf.intra_y_mode_mask[max_txsize_lookup[bsize]]);
|
| +
|
| + for (i = 0; i < MAX_MODES; ++i)
|
| + mode_threshold[i] = ((int64_t)rd_threshes[i] * rd_thresh_freq_fact[i]) >> 5;
|
| +
|
| + midx = cpi->sf.schedule_mode_search ? mode_skip_start : 0;
|
| + while (midx > 4) {
|
| + uint8_t end_pos = 0;
|
| + for (i = 5; i < midx; ++i) {
|
| + if (mode_threshold[mode_map[i - 1]] > mode_threshold[mode_map[i]]) {
|
| + uint8_t tmp = mode_map[i];
|
| + mode_map[i] = mode_map[i - 1];
|
| + mode_map[i - 1] = tmp;
|
| + end_pos = i;
|
| + }
|
| + }
|
| + midx = end_pos;
|
| + }
|
| +
|
| + for (midx = 0; midx < MAX_MODES; ++midx) {
|
| + int mode_index = mode_map[midx];
|
| int mode_excluded = 0;
|
| int64_t this_rd = INT64_MAX;
|
| int disable_skip = 0;
|
| @@ -2691,31 +2718,30 @@
|
| int64_t distortion2 = 0, distortion_y = 0, distortion_uv = 0;
|
| int skippable = 0;
|
| int64_t tx_cache[TX_MODES];
|
| - int i;
|
| int this_skip2 = 0;
|
| int64_t total_sse = INT64_MAX;
|
| int early_term = 0;
|
|
|
| this_mode = vp9_mode_order[mode_index].mode;
|
| ref_frame = vp9_mode_order[mode_index].ref_frame[0];
|
| - if (ref_frame != INTRA_FRAME && !(inter_mode_mask & (1 << this_mode)))
|
| - continue;
|
| second_ref_frame = vp9_mode_order[mode_index].ref_frame[1];
|
|
|
| // Look at the reference frame of the best mode so far and set the
|
| // skip mask to look at a subset of the remaining modes.
|
| - if (mode_index == mode_skip_start && best_mode_index >= 0) {
|
| - switch (vp9_mode_order[best_mode_index].ref_frame[0]) {
|
| + if (midx == mode_skip_start && best_mode_index >= 0) {
|
| + switch (best_mbmode.ref_frame[0]) {
|
| case INTRA_FRAME:
|
| break;
|
| case LAST_FRAME:
|
| - mode_skip_mask |= LAST_FRAME_MODE_MASK;
|
| + ref_frame_skip_mask[0] |= LAST_FRAME_MODE_MASK;
|
| + ref_frame_skip_mask[1] |= SECOND_REF_FRAME_MASK;
|
| break;
|
| case GOLDEN_FRAME:
|
| - mode_skip_mask |= GOLDEN_FRAME_MODE_MASK;
|
| + ref_frame_skip_mask[0] |= GOLDEN_FRAME_MODE_MASK;
|
| + ref_frame_skip_mask[1] |= SECOND_REF_FRAME_MASK;
|
| break;
|
| case ALTREF_FRAME:
|
| - mode_skip_mask |= ALT_REF_MODE_MASK;
|
| + ref_frame_skip_mask[0] |= ALT_REF_MODE_MASK;
|
| break;
|
| case NONE:
|
| case MAX_REF_FRAMES:
|
| @@ -2724,18 +2750,18 @@
|
| }
|
| }
|
|
|
| - if (cpi->sf.alt_ref_search_fp && cpi->rc.is_src_frame_alt_ref) {
|
| - mode_skip_mask = 0;
|
| - if (!(ref_frame == ALTREF_FRAME && second_ref_frame == NONE))
|
| - continue;
|
| - }
|
| + if (ref_frame_skip_mask[0] & (1 << ref_frame) &&
|
| + ref_frame_skip_mask[1] & (1 << MAX(0, second_ref_frame)))
|
| + continue;
|
|
|
| - if (mode_skip_mask & (1 << mode_index))
|
| + if (mode_skip_mask[ref_frame] & (1 << this_mode))
|
| continue;
|
|
|
| // Test best rd so far against threshold for trying this mode.
|
| - if (rd_less_than_thresh(best_rd, rd_threshes[mode_index],
|
| - rd_thresh_freq_fact[mode_index]))
|
| + if (best_mode_skippable && cpi->sf.schedule_mode_search)
|
| + mode_threshold[mode_index] <<= 1;
|
| +
|
| + if (best_rd < mode_threshold[mode_index])
|
| continue;
|
|
|
| if (cpi->sf.motion_field_mode_search) {
|
| @@ -2754,10 +2780,10 @@
|
| ref_mv.as_int = INVALID_MV;
|
|
|
| if ((mi_row - 1) >= tile->mi_row_start) {
|
| - ref_mv = xd->mi[-xd->mi_stride]->mbmi.mv[0];
|
| - rf = xd->mi[-xd->mi_stride]->mbmi.ref_frame[0];
|
| + ref_mv = xd->mi[-xd->mi_stride].src_mi->mbmi.mv[0];
|
| + rf = xd->mi[-xd->mi_stride].src_mi->mbmi.ref_frame[0];
|
| for (i = 0; i < mi_width; ++i) {
|
| - ref_mbmi = &xd->mi[-xd->mi_stride + i]->mbmi;
|
| + ref_mbmi = &xd->mi[-xd->mi_stride + i].src_mi->mbmi;
|
| const_motion &= (ref_mv.as_int == ref_mbmi->mv[0].as_int) &&
|
| (ref_frame == ref_mbmi->ref_frame[0]);
|
| skip_ref_frame &= (rf == ref_mbmi->ref_frame[0]);
|
| @@ -2766,11 +2792,11 @@
|
|
|
| if ((mi_col - 1) >= tile->mi_col_start) {
|
| if (ref_mv.as_int == INVALID_MV)
|
| - ref_mv = xd->mi[-1]->mbmi.mv[0];
|
| + ref_mv = xd->mi[-1].src_mi->mbmi.mv[0];
|
| if (rf == NONE)
|
| - rf = xd->mi[-1]->mbmi.ref_frame[0];
|
| + rf = xd->mi[-1].src_mi->mbmi.ref_frame[0];
|
| for (i = 0; i < mi_height; ++i) {
|
| - ref_mbmi = &xd->mi[i * xd->mi_stride - 1]->mbmi;
|
| + ref_mbmi = &xd->mi[i * xd->mi_stride - 1].src_mi->mbmi;
|
| const_motion &= (ref_mv.as_int == ref_mbmi->mv[0].as_int) &&
|
| (ref_frame == ref_mbmi->ref_frame[0]);
|
| skip_ref_frame &= (rf == ref_mbmi->ref_frame[0]);
|
| @@ -2792,14 +2818,19 @@
|
| if (!cm->allow_comp_inter_inter)
|
| continue;
|
|
|
| + // Skip compound inter modes if ARF is not available.
|
| + if (!(cpi->ref_frame_flags & flag_list[second_ref_frame]))
|
| + continue;
|
| +
|
| + // Do not allow compound prediction if the segment level reference frame
|
| + // feature is in use as in this case there can only be one reference.
|
| + if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME))
|
| + continue;
|
| +
|
| if ((mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) &&
|
| - best_mode_index >=0 &&
|
| - vp9_mode_order[best_mode_index].ref_frame[0] == INTRA_FRAME)
|
| + best_mode_index >= 0 && best_mbmode.ref_frame[0] == INTRA_FRAME)
|
| continue;
|
| - if ((mode_search_skip_flags & FLAG_SKIP_COMP_REFMISMATCH) &&
|
| - ref_frame != best_inter_ref_frame &&
|
| - second_ref_frame != best_inter_ref_frame)
|
| - continue;
|
| +
|
| mode_excluded = cm->reference_mode == SINGLE_REFERENCE;
|
| } else {
|
| if (ref_frame != INTRA_FRAME)
|
| @@ -2808,11 +2839,9 @@
|
|
|
| if (ref_frame == INTRA_FRAME) {
|
| if (cpi->sf.adaptive_mode_search)
|
| - if ((x->source_variance << num_pels_log2_lookup[bsize]) > best_intra_rd)
|
| + if ((x->source_variance << num_pels_log2_lookup[bsize]) > best_pred_sse)
|
| continue;
|
|
|
| - if (!(intra_y_mode_mask & (1 << this_mode)))
|
| - continue;
|
| if (this_mode != DC_PRED) {
|
| // Disable intra modes other than DC_PRED for blocks with low variance
|
| // Threshold for intra skipping based on source variance
|
| @@ -2826,7 +2855,7 @@
|
| if ((mode_search_skip_flags & FLAG_SKIP_INTRA_BESTINTER) &&
|
| (this_mode >= D45_PRED && this_mode <= TM_PRED)) {
|
| if (best_mode_index >= 0 &&
|
| - vp9_mode_order[best_mode_index].ref_frame[0] > INTRA_FRAME)
|
| + best_mbmode.ref_frame[0] > INTRA_FRAME)
|
| continue;
|
| }
|
| if (mode_search_skip_flags & FLAG_SKIP_INTRA_DIRMISMATCH) {
|
| @@ -2837,7 +2866,7 @@
|
| } else {
|
| const MV_REFERENCE_FRAME ref_frames[2] = {ref_frame, second_ref_frame};
|
| if (!check_best_zero_mv(cpi, mbmi->mode_context, frame_mv,
|
| - inter_mode_mask, this_mode, ref_frames))
|
| + this_mode, ref_frames))
|
| continue;
|
| }
|
|
|
| @@ -2918,18 +2947,11 @@
|
|
|
| if (!disable_skip) {
|
| if (skippable) {
|
| - vp9_prob skip_prob = vp9_get_skip_prob(cm, xd);
|
| -
|
| // Back out the coefficient coding costs
|
| rate2 -= (rate_y + rate_uv);
|
| - // for best yrd calculation
|
| - rate_uv = 0;
|
|
|
| // Cost the skip mb case
|
| - if (skip_prob) {
|
| - int prob_skip_cost = vp9_cost_bit(skip_prob, 1);
|
| - rate2 += prob_skip_cost;
|
| - }
|
| + rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1);
|
| } else if (ref_frame != INTRA_FRAME && !xd->lossless) {
|
| if (RDCOST(x->rdmult, x->rddiv, rate_y + rate_uv, distortion2) <
|
| RDCOST(x->rdmult, x->rddiv, 0, total_sse)) {
|
| @@ -2941,8 +2963,6 @@
|
| distortion2 = total_sse;
|
| assert(total_sse >= 0);
|
| rate2 -= (rate_y + rate_uv);
|
| - rate_y = 0;
|
| - rate_uv = 0;
|
| this_skip2 = 1;
|
| }
|
| } else {
|
| @@ -2960,12 +2980,6 @@
|
| best_intra_rd = this_rd;
|
| best_intra_mode = mbmi->mode;
|
| }
|
| - } else {
|
| - // Keep record of best inter rd with single reference
|
| - if (!comp_pred && !mode_excluded && this_rd < best_inter_rd) {
|
| - best_inter_rd = this_rd;
|
| - best_inter_ref_frame = ref_frame;
|
| - }
|
| }
|
|
|
| if (!disable_skip && ref_frame == INTRA_FRAME) {
|
| @@ -2987,7 +3001,7 @@
|
| mbmi->mv[0].as_int = 0;
|
| max_plane = 1;
|
| } else {
|
| - best_intra_rd = x->pred_sse[ref_frame];
|
| + best_pred_sse = x->pred_sse[ref_frame];
|
| }
|
|
|
| *returnrate = rate2;
|
| @@ -3037,13 +3051,11 @@
|
| hybrid_rd = RDCOST(x->rdmult, x->rddiv, hybrid_rate, distortion2);
|
|
|
| if (!comp_pred) {
|
| - if (single_rd < best_pred_rd[SINGLE_REFERENCE]) {
|
| + if (single_rd < best_pred_rd[SINGLE_REFERENCE])
|
| best_pred_rd[SINGLE_REFERENCE] = single_rd;
|
| - }
|
| } else {
|
| - if (single_rd < best_pred_rd[COMPOUND_REFERENCE]) {
|
| + if (single_rd < best_pred_rd[COMPOUND_REFERENCE])
|
| best_pred_rd[COMPOUND_REFERENCE] = single_rd;
|
| - }
|
| }
|
| if (hybrid_rd < best_pred_rd[REFERENCE_MODE_SELECT])
|
| best_pred_rd[REFERENCE_MODE_SELECT] = hybrid_rd;
|
| @@ -3124,7 +3136,7 @@
|
| // If we used an estimate for the uv intra rd in the loop above...
|
| if (cpi->sf.use_uv_intra_rd_estimate) {
|
| // Do Intra UV best rd mode selection if best mode choice above was intra.
|
| - if (vp9_mode_order[best_mode_index].ref_frame[0] == INTRA_FRAME) {
|
| + if (best_mbmode.ref_frame[0] == INTRA_FRAME) {
|
| TX_SIZE uv_tx_size;
|
| *mbmi = best_mbmode;
|
| uv_tx_size = get_uv_tx_size(mbmi, &xd->plane[1]);
|
| @@ -3141,7 +3153,8 @@
|
| (cm->interp_filter == best_mbmode.interp_filter) ||
|
| !is_inter_block(&best_mbmode));
|
|
|
| - update_rd_thresh_fact(cpi, bsize, best_mode_index);
|
| + if (!cpi->rc.is_src_frame_alt_ref)
|
| + update_rd_thresh_fact(cpi, bsize, best_mode_index);
|
|
|
| // macroblock modes
|
| *mbmi = best_mbmode;
|
| @@ -3174,7 +3187,10 @@
|
| vp9_zero(best_tx_diff);
|
| }
|
|
|
| - set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]);
|
| + // TODO(yunqingwang): Moving this line in front of the above best_filter_diff
|
| + // updating code causes PSNR loss. Need to figure out the confliction.
|
| + x->skip |= best_mode_skippable;
|
| +
|
| store_coding_context(x, ctx, best_mode_index, best_pred_diff,
|
| best_tx_diff, best_filter_diff, best_mode_skippable);
|
|
|
| @@ -3190,7 +3206,7 @@
|
| VP9_COMMON *const cm = &cpi->common;
|
| RD_OPT *const rd_opt = &cpi->rd;
|
| MACROBLOCKD *const xd = &x->e_mbd;
|
| - MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
|
| + MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi;
|
| unsigned char segment_id = mbmi->segment_id;
|
| const int comp_pred = 0;
|
| int i;
|
| @@ -3297,7 +3313,7 @@
|
| VP9_COMMON *const cm = &cpi->common;
|
| RD_OPT *const rd_opt = &cpi->rd;
|
| MACROBLOCKD *const xd = &x->e_mbd;
|
| - MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
|
| + MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi;
|
| const struct segmentation *const seg = &cm->seg;
|
| MV_REFERENCE_FRAME ref_frame, second_ref_frame;
|
| unsigned char segment_id = mbmi->segment_id;
|
| @@ -3317,18 +3333,17 @@
|
| int ref_index, best_ref_index = 0;
|
| unsigned int ref_costs_single[MAX_REF_FRAMES], ref_costs_comp[MAX_REF_FRAMES];
|
| vp9_prob comp_mode_p;
|
| - int64_t best_inter_rd = INT64_MAX;
|
| - MV_REFERENCE_FRAME best_inter_ref_frame = LAST_FRAME;
|
| INTERP_FILTER tmp_best_filter = SWITCHABLE;
|
| int rate_uv_intra, rate_uv_tokenonly;
|
| int64_t dist_uv;
|
| int skip_uv;
|
| PREDICTION_MODE mode_uv = DC_PRED;
|
| - int intra_cost_penalty = 20 * vp9_dc_quant(cm->base_qindex, cm->y_dc_delta_q);
|
| + const int intra_cost_penalty =
|
| + 20 * vp9_dc_quant(cm->base_qindex, cm->y_dc_delta_q, cm->bit_depth);
|
| int_mv seg_mvs[4][MAX_REF_FRAMES];
|
| b_mode_info best_bmodes[4];
|
| int best_skip2 = 0;
|
| - int mode_skip_mask = 0;
|
| + int ref_frame_skip_mask[2] = { 0 };
|
|
|
| x->skip_encode = cpi->sf.skip_encode_frame && x->q_index < QIDX_SKIP_THRESH;
|
| vpx_memset(x->zcoeff_blk[TX_4X4], 0, 4);
|
| @@ -3357,6 +3372,9 @@
|
| ref_frame, bsize, mi_row, mi_col,
|
| frame_mv[NEARESTMV], frame_mv[NEARMV],
|
| yv12_mb);
|
| + } else {
|
| + ref_frame_skip_mask[0] |= (1 << ref_frame);
|
| + ref_frame_skip_mask[1] |= SECOND_REF_FRAME_MASK;
|
| }
|
| frame_mv[NEWMV][ref_frame].as_int = INVALID_MV;
|
| frame_mv[ZEROMV][ref_frame].as_int = 0;
|
| @@ -3382,18 +3400,19 @@
|
| // skip mask to look at a subset of the remaining modes.
|
| if (ref_index > 2 && cpi->sf.mode_skip_start < MAX_MODES) {
|
| if (ref_index == 3) {
|
| - switch (vp9_ref_order[best_ref_index].ref_frame[0]) {
|
| + switch (best_mbmode.ref_frame[0]) {
|
| case INTRA_FRAME:
|
| - mode_skip_mask = 0;
|
| break;
|
| case LAST_FRAME:
|
| - mode_skip_mask = 0x0010;
|
| + ref_frame_skip_mask[0] |= (1 << GOLDEN_FRAME) | (1 << ALTREF_FRAME);
|
| + ref_frame_skip_mask[1] |= SECOND_REF_FRAME_MASK;
|
| break;
|
| case GOLDEN_FRAME:
|
| - mode_skip_mask = 0x0008;
|
| + ref_frame_skip_mask[0] |= (1 << LAST_FRAME) | (1 << ALTREF_FRAME);
|
| + ref_frame_skip_mask[1] |= SECOND_REF_FRAME_MASK;
|
| break;
|
| case ALTREF_FRAME:
|
| - mode_skip_mask = 0x0000;
|
| + ref_frame_skip_mask[0] |= (1 << GOLDEN_FRAME) | (1 << LAST_FRAME);
|
| break;
|
| case NONE:
|
| case MAX_REF_FRAMES:
|
| @@ -3401,39 +3420,32 @@
|
| break;
|
| }
|
| }
|
| - if (mode_skip_mask & (1 << ref_index))
|
| - continue;
|
| }
|
|
|
| + if (ref_frame_skip_mask[0] & (1 << ref_frame) &&
|
| + ref_frame_skip_mask[1] & (1 << MAX(0, second_ref_frame)))
|
| + continue;
|
| +
|
| // Test best rd so far against threshold for trying this mode.
|
| if (rd_less_than_thresh(best_rd,
|
| rd_opt->threshes[segment_id][bsize][ref_index],
|
| rd_opt->thresh_freq_fact[bsize][ref_index]))
|
| continue;
|
|
|
| - if (ref_frame > INTRA_FRAME &&
|
| - !(cpi->ref_frame_flags & flag_list[ref_frame])) {
|
| - continue;
|
| - }
|
| -
|
| comp_pred = second_ref_frame > INTRA_FRAME;
|
| if (comp_pred) {
|
| if (!cm->allow_comp_inter_inter)
|
| continue;
|
| -
|
| if (!(cpi->ref_frame_flags & flag_list[second_ref_frame]))
|
| continue;
|
| // Do not allow compound prediction if the segment level reference frame
|
| // feature is in use as in this case there can only be one reference.
|
| if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME))
|
| continue;
|
| +
|
| if ((cpi->sf.mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) &&
|
| - vp9_ref_order[best_ref_index].ref_frame[0] == INTRA_FRAME)
|
| + best_mbmode.ref_frame[0] == INTRA_FRAME)
|
| continue;
|
| - if ((cpi->sf.mode_search_skip_flags & FLAG_SKIP_COMP_REFMISMATCH) &&
|
| - ref_frame != best_inter_ref_frame &&
|
| - second_ref_frame != best_inter_ref_frame)
|
| - continue;
|
| }
|
|
|
| // TODO(jingning, jkoleszar): scaling reference frame not supported for
|
| @@ -3454,14 +3466,12 @@
|
| // If the segment reference frame feature is enabled....
|
| // then do nothing if the current ref frame is not allowed..
|
| if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) &&
|
| - vp9_get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) !=
|
| - (int)ref_frame) {
|
| + vp9_get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) != (int)ref_frame) {
|
| continue;
|
| // Disable this drop out case if the ref frame
|
| // segment level feature is enabled for this segment. This is to
|
| // prevent the possibility that we end up unable to pick any mode.
|
| - } else if (!vp9_segfeature_active(seg, segment_id,
|
| - SEG_LVL_REF_FRAME)) {
|
| + } else if (!vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) {
|
| // Only consider ZEROMV/ALTREF_FRAME for alt ref frame,
|
| // unless ARNR filtering is enabled in which case we want
|
| // an unfiltered alternative. We allow near/nearest as well
|
| @@ -3590,7 +3600,7 @@
|
| tmp_best_skippable = skippable;
|
| tmp_best_mbmode = *mbmi;
|
| for (i = 0; i < 4; i++) {
|
| - tmp_best_bmodes[i] = xd->mi[0]->bmi[i];
|
| + tmp_best_bmodes[i] = xd->mi[0].src_mi->bmi[i];
|
| x->zcoeff_blk[TX_4X4][i] = !x->plane[0].eobs[i];
|
| }
|
| pred_exists = 1;
|
| @@ -3634,7 +3644,7 @@
|
| skippable = tmp_best_skippable;
|
| *mbmi = tmp_best_mbmode;
|
| for (i = 0; i < 4; i++)
|
| - xd->mi[0]->bmi[i] = tmp_best_bmodes[i];
|
| + xd->mi[0].src_mi->bmi[i] = tmp_best_bmodes[i];
|
| }
|
|
|
| rate2 += rate;
|
| @@ -3708,15 +3718,6 @@
|
| this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2);
|
| }
|
|
|
| - // Keep record of best inter rd with single reference
|
| - if (is_inter_block(mbmi) &&
|
| - !has_second_ref(mbmi) &&
|
| - !mode_excluded &&
|
| - this_rd < best_inter_rd) {
|
| - best_inter_rd = this_rd;
|
| - best_inter_ref_frame = ref_frame;
|
| - }
|
| -
|
| if (!disable_skip && ref_frame == INTRA_FRAME) {
|
| for (i = 0; i < REFERENCE_MODES; ++i)
|
| best_pred_rd[i] = MIN(best_pred_rd[i], this_rd);
|
| @@ -3750,7 +3751,7 @@
|
| sizeof(uint8_t) * ctx->num_4x4_blk);
|
|
|
| for (i = 0; i < 4; i++)
|
| - best_bmodes[i] = xd->mi[0]->bmi[i];
|
| + best_bmodes[i] = xd->mi[0].src_mi->bmi[i];
|
|
|
| // TODO(debargha): enhance this test with a better distortion prediction
|
| // based on qp, activity mask and history
|
| @@ -3786,11 +3787,11 @@
|
| single_rd = RDCOST(x->rdmult, x->rddiv, single_rate, distortion2);
|
| hybrid_rd = RDCOST(x->rdmult, x->rddiv, hybrid_rate, distortion2);
|
|
|
| - if (!comp_pred && single_rd < best_pred_rd[SINGLE_REFERENCE]) {
|
| + if (!comp_pred && single_rd < best_pred_rd[SINGLE_REFERENCE])
|
| best_pred_rd[SINGLE_REFERENCE] = single_rd;
|
| - } else if (comp_pred && single_rd < best_pred_rd[COMPOUND_REFERENCE]) {
|
| + else if (comp_pred && single_rd < best_pred_rd[COMPOUND_REFERENCE])
|
| best_pred_rd[COMPOUND_REFERENCE] = single_rd;
|
| - }
|
| +
|
| if (hybrid_rd < best_pred_rd[REFERENCE_MODE_SELECT])
|
| best_pred_rd[REFERENCE_MODE_SELECT] = hybrid_rd;
|
| }
|
| @@ -3831,7 +3832,7 @@
|
| // If we used an estimate for the uv intra rd in the loop above...
|
| if (cpi->sf.use_uv_intra_rd_estimate) {
|
| // Do Intra UV best rd mode selection if best mode choice above was intra.
|
| - if (vp9_ref_order[best_ref_index].ref_frame[0] == INTRA_FRAME) {
|
| + if (best_mbmode.ref_frame[0] == INTRA_FRAME) {
|
| *mbmi = best_mbmode;
|
| rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv_intra,
|
| &rate_uv_tokenonly,
|
| @@ -3858,13 +3859,14 @@
|
| x->skip |= best_skip2;
|
| if (!is_inter_block(&best_mbmode)) {
|
| for (i = 0; i < 4; i++)
|
| - xd->mi[0]->bmi[i].as_mode = best_bmodes[i].as_mode;
|
| + xd->mi[0].src_mi->bmi[i].as_mode = best_bmodes[i].as_mode;
|
| } else {
|
| for (i = 0; i < 4; ++i)
|
| - vpx_memcpy(&xd->mi[0]->bmi[i], &best_bmodes[i], sizeof(b_mode_info));
|
| + vpx_memcpy(&xd->mi[0].src_mi->bmi[i], &best_bmodes[i],
|
| + sizeof(b_mode_info));
|
|
|
| - mbmi->mv[0].as_int = xd->mi[0]->bmi[3].as_mv[0].as_int;
|
| - mbmi->mv[1].as_int = xd->mi[0]->bmi[3].as_mv[1].as_int;
|
| + mbmi->mv[0].as_int = xd->mi[0].src_mi->bmi[3].as_mv[0].as_int;
|
| + mbmi->mv[1].as_int = xd->mi[0].src_mi->bmi[3].as_mv[1].as_int;
|
| }
|
|
|
| for (i = 0; i < REFERENCE_MODES; ++i) {
|
| @@ -3887,9 +3889,9 @@
|
| vp9_zero(best_filter_diff);
|
| }
|
|
|
| - set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]);
|
| store_coding_context(x, ctx, best_ref_index,
|
| best_pred_diff, best_tx_diff, best_filter_diff, 0);
|
|
|
| return best_rd;
|
| }
|
| +
|
|
|