diff options
Diffstat (limited to 'vp9/encoder')
-rw-r--r-- | vp9/encoder/vp9_aq_cyclicrefresh.c | 7 | ||||
-rw-r--r-- | vp9/encoder/vp9_encodeframe.c | 52 | ||||
-rw-r--r-- | vp9/encoder/vp9_firstpass.c | 27 | ||||
-rw-r--r-- | vp9/encoder/vp9_mcomp.c | 39 | ||||
-rw-r--r-- | vp9/encoder/vp9_mcomp.h | 4 | ||||
-rw-r--r-- | vp9/encoder/vp9_onyx_if.c | 152 | ||||
-rw-r--r-- | vp9/encoder/vp9_onyx_int.h | 56 | ||||
-rw-r--r-- | vp9/encoder/vp9_pickmode.c | 4 | ||||
-rw-r--r-- | vp9/encoder/vp9_ratectrl.c | 34 | ||||
-rw-r--r-- | vp9/encoder/vp9_rdopt.c | 94 |
10 files changed, 229 insertions, 240 deletions
diff --git a/vp9/encoder/vp9_aq_cyclicrefresh.c b/vp9/encoder/vp9_aq_cyclicrefresh.c index 787909142..e55881ffc 100644 --- a/vp9/encoder/vp9_aq_cyclicrefresh.c +++ b/vp9/encoder/vp9_aq_cyclicrefresh.c @@ -200,6 +200,7 @@ void vp9_cyclic_refresh_setup(VP9_COMP *const cpi) { // Rate target ratio to set q delta. const float rate_ratio_qdelta = 2.0; + const double q = vp9_convert_qindex_to_q(cm->base_qindex); vp9_clear_system_state(); // Some of these parameters may be set via codec-control function later. cr->max_sbs_perframe = 10; @@ -209,14 +210,12 @@ void vp9_cyclic_refresh_setup(VP9_COMP *const cpi) { // Set rate threshold to some fraction of target (and scaled by 256). cr->thresh_rate_sb = (rc->sb64_target_rate * 256) >> 2; // Distortion threshold, quadratic in Q, scale factor to be adjusted. - cr->thresh_dist_sb = 8 * (int)(vp9_convert_qindex_to_q(cm->base_qindex) * - vp9_convert_qindex_to_q(cm->base_qindex)); + cr->thresh_dist_sb = 8 * (int)(q * q); if (cpi->sf.use_nonrd_pick_mode) { // May want to be more conservative with thresholds in non-rd mode for now // as rate/distortion are derived from model based on prediction residual. cr->thresh_rate_sb = (rc->sb64_target_rate * 256) >> 3; - cr->thresh_dist_sb = 4 * (int)(vp9_convert_qindex_to_q(cm->base_qindex) * - vp9_convert_qindex_to_q(cm->base_qindex)); + cr->thresh_dist_sb = 4 * (int)(q * q); } cr->num_seg_blocks = 0; diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c index 34ea88ccb..83c6a33c7 100644 --- a/vp9/encoder/vp9_encodeframe.c +++ b/vp9/encoder/vp9_encodeframe.c @@ -243,8 +243,8 @@ static void set_offsets(VP9_COMP *cpi, const TileInfo *const tile, vp9_setup_src_planes(x, cpi->Source, mi_row, mi_col); // R/D setup. - x->rddiv = cpi->RDDIV; - x->rdmult = cpi->RDMULT; + x->rddiv = cpi->rd.RDDIV; + x->rdmult = cpi->rd.RDMULT; // Setup segment ID. if (seg->enabled) { @@ -819,6 +819,7 @@ static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx, int output_enabled) { int i, x_idx, y; VP9_COMMON *const cm = &cpi->common; + RD_OPT *const rd_opt = &cpi->rd; MACROBLOCK *const x = &cpi->mb; MACROBLOCKD *const xd = &x->e_mbd; struct macroblock_plane *const p = x->plane; @@ -904,7 +905,7 @@ static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx, if (!vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { for (i = 0; i < TX_MODES; i++) - cpi->rd_tx_select_diff[i] += ctx->tx_rd_diff[i]; + rd_opt->tx_select_diff[i] += ctx->tx_rd_diff[i]; } #if CONFIG_INTERNAL_STATS @@ -937,12 +938,12 @@ static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx, } } - cpi->rd_comp_pred_diff[SINGLE_REFERENCE] += ctx->single_pred_diff; - cpi->rd_comp_pred_diff[COMPOUND_REFERENCE] += ctx->comp_pred_diff; - cpi->rd_comp_pred_diff[REFERENCE_MODE_SELECT] += ctx->hybrid_pred_diff; + rd_opt->comp_pred_diff[SINGLE_REFERENCE] += ctx->single_pred_diff; + rd_opt->comp_pred_diff[COMPOUND_REFERENCE] += ctx->comp_pred_diff; + rd_opt->comp_pred_diff[REFERENCE_MODE_SELECT] += ctx->hybrid_pred_diff; for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i) - cpi->rd_filter_diff[i] += ctx->best_filter_diff[i]; + rd_opt->filter_diff[i] += ctx->best_filter_diff[i]; } } @@ -2658,9 +2659,10 @@ static TX_MODE select_tx_mode(const VP9_COMP *cpi) { if (cpi->sf.tx_size_search_method == USE_LARGESTALL) { return ALLOW_32X32; } else if (cpi->sf.tx_size_search_method == USE_FULL_RD) { + const RD_OPT *const rd_opt = &cpi->rd; const MV_REFERENCE_FRAME frame_type = get_frame_type(cpi); - return cpi->rd_tx_select_threshes[frame_type][ALLOW_32X32] > - cpi->rd_tx_select_threshes[frame_type][TX_MODE_SELECT] ? + return rd_opt->tx_select_threshes[frame_type][ALLOW_32X32] > + rd_opt->tx_select_threshes[frame_type][TX_MODE_SELECT] ? ALLOW_32X32 : TX_MODE_SELECT; } else { unsigned int total = 0; @@ -3224,6 +3226,7 @@ static void encode_nonrd_sb_row(VP9_COMP *cpi, const TileInfo *const tile, static void encode_frame_internal(VP9_COMP *cpi) { SPEED_FEATURES *const sf = &cpi->sf; + RD_OPT *const rd_opt = &cpi->rd; MACROBLOCK *const x = &cpi->mb; VP9_COMMON *const cm = &cpi->common; MACROBLOCKD *const xd = &x->e_mbd; @@ -3234,10 +3237,10 @@ static void encode_frame_internal(VP9_COMP *cpi) { vp9_zero(cm->counts); vp9_zero(cpi->coef_counts); vp9_zero(cpi->tx_stepdown_count); - vp9_zero(cpi->rd_comp_pred_diff); - vp9_zero(cpi->rd_filter_diff); - vp9_zero(cpi->rd_tx_select_diff); - vp9_zero(cpi->rd_tx_select_threshes); + vp9_zero(rd_opt->comp_pred_diff); + vp9_zero(rd_opt->filter_diff); + vp9_zero(rd_opt->tx_select_diff); + vp9_zero(rd_opt->tx_select_threshes); cm->tx_mode = select_tx_mode(cpi); @@ -3356,6 +3359,7 @@ static void encode_frame_internal(VP9_COMP *cpi) { void vp9_encode_frame(VP9_COMP *cpi) { VP9_COMMON *const cm = &cpi->common; + RD_OPT *const rd_opt = &cpi->rd; // In the longer term the encoder should be generalized to match the // decoder such that we allow compound where one of the 3 buffers has a @@ -3388,8 +3392,8 @@ void vp9_encode_frame(VP9_COMP *cpi) { // that for subsequent frames. // It does the same analysis for transform size selection also. const MV_REFERENCE_FRAME frame_type = get_frame_type(cpi); - const int64_t *mode_thresh = cpi->rd_prediction_type_threshes[frame_type]; - const int64_t *filter_thresh = cpi->rd_filter_threshes[frame_type]; + const int64_t *mode_thresh = rd_opt->prediction_type_threshes[frame_type]; + const int64_t *filter_thresh = rd_opt->filter_threshes[frame_type]; /* prediction (compound, single or hybrid) mode selection */ if (frame_type == ALTREF_FRAME || !cm->allow_comp_inter_inter) @@ -3422,25 +3426,25 @@ void vp9_encode_frame(VP9_COMP *cpi) { encode_frame_internal(cpi); for (i = 0; i < REFERENCE_MODES; ++i) { - const int diff = (int) (cpi->rd_comp_pred_diff[i] / cm->MBs); - cpi->rd_prediction_type_threshes[frame_type][i] += diff; - cpi->rd_prediction_type_threshes[frame_type][i] >>= 1; + const int diff = (int) (rd_opt->comp_pred_diff[i] / cm->MBs); + rd_opt->prediction_type_threshes[frame_type][i] += diff; + rd_opt->prediction_type_threshes[frame_type][i] >>= 1; } for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { - const int64_t diff = cpi->rd_filter_diff[i] / cm->MBs; - cpi->rd_filter_threshes[frame_type][i] = - (cpi->rd_filter_threshes[frame_type][i] + diff) / 2; + const int64_t diff = rd_opt->filter_diff[i] / cm->MBs; + rd_opt->filter_threshes[frame_type][i] = + (rd_opt->filter_threshes[frame_type][i] + diff) / 2; } for (i = 0; i < TX_MODES; ++i) { - int64_t pd = cpi->rd_tx_select_diff[i]; + int64_t pd = rd_opt->tx_select_diff[i]; int diff; if (i == TX_MODE_SELECT) pd -= RDCOST(cpi->mb.rdmult, cpi->mb.rddiv, 2048 * (TX_SIZES - 1), 0); diff = (int) (pd / cm->MBs); - cpi->rd_tx_select_threshes[frame_type][i] += diff; - cpi->rd_tx_select_threshes[frame_type][i] /= 2; + rd_opt->tx_select_threshes[frame_type][i] += diff; + rd_opt->tx_select_threshes[frame_type][i] /= 2; } if (cm->reference_mode == REFERENCE_MODE_SELECT) { diff --git a/vp9/encoder/vp9_firstpass.c b/vp9/encoder/vp9_firstpass.c index 3324b9c60..c0bce05c8 100644 --- a/vp9/encoder/vp9_firstpass.c +++ b/vp9/encoder/vp9_firstpass.c @@ -376,15 +376,12 @@ static vp9_variance_fn_t get_block_variance_fn(BLOCK_SIZE bsize) { } } -static unsigned int zz_motion_search(const MACROBLOCK *x) { - const MACROBLOCKD *const xd = &x->e_mbd; - const uint8_t *const src = x->plane[0].src.buf; - const int src_stride = x->plane[0].src.stride; - const uint8_t *const ref = xd->plane[0].pre[0].buf; - const int ref_stride = xd->plane[0].pre[0].stride; +static unsigned int get_prediction_error(BLOCK_SIZE bsize, + const struct buf_2d *src, + const struct buf_2d *ref) { unsigned int sse; - vp9_variance_fn_t fn = get_block_variance_fn(xd->mi[0]->mbmi.sb_type); - fn(src, src_stride, ref, ref_stride, &sse); + const vp9_variance_fn_t fn = get_block_variance_fn(bsize); + fn(src->buf, src->stride, ref->buf, ref->stride, &sse); return sse; } @@ -416,9 +413,7 @@ static void first_pass_motion_search(VP9_COMP *cpi, MACROBLOCK *x, // Center the initial step/diamond search on best mv. tmp_err = cpi->diamond_search_sad(x, &ref_mv_full, &tmp_mv, step_param, - x->sadperbit16, &num00, &v_fn_ptr, - x->nmvjointcost, - x->mvcost, ref_mv); + x->sadperbit16, &num00, &v_fn_ptr, ref_mv); if (tmp_err < INT_MAX) tmp_err = vp9_get_mvpred_var(x, &tmp_mv, ref_mv, &v_fn_ptr, 1); if (tmp_err < INT_MAX - new_mv_mode_penalty) @@ -442,9 +437,7 @@ static void first_pass_motion_search(VP9_COMP *cpi, MACROBLOCK *x, } else { tmp_err = cpi->diamond_search_sad(x, &ref_mv_full, &tmp_mv, step_param + n, x->sadperbit16, - &num00, &v_fn_ptr, - x->nmvjointcost, - x->mvcost, ref_mv); + &num00, &v_fn_ptr, ref_mv); if (tmp_err < INT_MAX) tmp_err = vp9_get_mvpred_var(x, &tmp_mv, ref_mv, &v_fn_ptr, 1); if (tmp_err < INT_MAX - new_mv_mode_penalty) @@ -632,7 +625,8 @@ void vp9_first_pass(VP9_COMP *cpi) { int_mv mv, tmp_mv; xd->plane[0].pre[0].buf = first_ref_buf->y_buffer + recon_yoffset; - motion_error = zz_motion_search(x); + motion_error = get_prediction_error(bsize, &x->plane[0].src, + &xd->plane[0].pre[0]); // Assume 0,0 motion with no mv overhead. mv.as_int = tmp_mv.as_int = 0; @@ -668,7 +662,8 @@ void vp9_first_pass(VP9_COMP *cpi) { int gf_motion_error; xd->plane[0].pre[0].buf = gld_yv12->y_buffer + recon_yoffset; - gf_motion_error = zz_motion_search(x); + gf_motion_error = get_prediction_error(bsize, &x->plane[0].src, + &xd->plane[0].pre[0]); first_pass_motion_search(cpi, x, &zero_mv, &tmp_mv.as_mv, &gf_motion_error); diff --git a/vp9/encoder/vp9_mcomp.c b/vp9/encoder/vp9_mcomp.c index 37201a933..f5511ffa3 100644 --- a/vp9/encoder/vp9_mcomp.c +++ b/vp9/encoder/vp9_mcomp.c @@ -170,14 +170,13 @@ static INLINE int sp(int x) { return (x & 7) << 1; } -static INLINE const uint8_t *pre(const uint8_t *buf, int stride, int r, int c, - int offset) { - return &buf[(r >> 3) * stride + (c >> 3) - offset]; +static INLINE const uint8_t *pre(const uint8_t *buf, int stride, int r, int c) { + return &buf[(r >> 3) * stride + (c >> 3)]; } /* returns subpixel variance error function */ #define DIST(r, c) \ - vfp->svf(pre(y, y_stride, r, c, offset), y_stride, sp(c), sp(r), z, \ + vfp->svf(pre(y, y_stride, r, c), y_stride, sp(c), sp(r), z, \ src_stride, &sse) /* checks if (r, c) has better score than previous best */ @@ -270,7 +269,7 @@ int vp9_find_best_sub_pixel_tree(const MACROBLOCK *x, int *mvjcost, int *mvcost[2], int *distortion, unsigned int *sse1) { - const uint8_t *z = x->plane[0].src.buf; + const uint8_t *const z = x->plane[0].src.buf; const int src_stride = x->plane[0].src.stride; const MACROBLOCKD *xd = &x->e_mbd; unsigned int besterr = INT_MAX; @@ -283,7 +282,7 @@ int vp9_find_best_sub_pixel_tree(const MACROBLOCK *x, const int y_stride = xd->plane[0].pre[0].stride; const int offset = bestmv->row * y_stride + bestmv->col; - const uint8_t *y = xd->plane[0].pre[0].buf + offset; + const uint8_t *const y = xd->plane[0].pre[0].buf; int rr = ref_mv->row; int rc = ref_mv->col; @@ -303,7 +302,7 @@ int vp9_find_best_sub_pixel_tree(const MACROBLOCK *x, bestmv->col *= 8; // calculate central point error - besterr = vfp->vf(y, y_stride, z, src_stride, sse1); + besterr = vfp->vf(y + offset, y_stride, z, src_stride, sse1); *distortion = besterr; besterr += mv_err_cost(bestmv, ref_mv, mvjcost, mvcost, error_per_bit); @@ -353,7 +352,7 @@ int vp9_find_best_sub_pixel_tree(const MACROBLOCK *x, #undef DIST /* returns subpixel variance error function */ #define DIST(r, c) \ - vfp->svaf(pre(y, y_stride, r, c, offset), y_stride, sp(c), sp(r), \ + vfp->svaf(pre(y, y_stride, r, c), y_stride, sp(c), sp(r), \ z, src_stride, &sse, second_pred) int vp9_find_best_sub_pixel_comp_tree(const MACROBLOCK *x, @@ -368,7 +367,7 @@ int vp9_find_best_sub_pixel_comp_tree(const MACROBLOCK *x, unsigned int *sse1, const uint8_t *second_pred, int w, int h) { - const uint8_t *z = x->plane[0].src.buf; + const uint8_t *const z = x->plane[0].src.buf; const int src_stride = x->plane[0].src.stride; const MACROBLOCKD *xd = &x->e_mbd; unsigned int besterr = INT_MAX; @@ -382,7 +381,7 @@ int vp9_find_best_sub_pixel_comp_tree(const MACROBLOCK *x, DECLARE_ALIGNED_ARRAY(16, uint8_t, comp_pred, 64 * 64); const int y_stride = xd->plane[0].pre[0].stride; const int offset = bestmv->row * y_stride + bestmv->col; - const uint8_t *y = xd->plane[0].pre[0].buf + offset; + const uint8_t *const y = xd->plane[0].pre[0].buf; int rr = ref_mv->row; int rc = ref_mv->col; @@ -404,7 +403,7 @@ int vp9_find_best_sub_pixel_comp_tree(const MACROBLOCK *x, // calculate central point error // TODO(yunqingwang): central pointer error was already calculated in full- // pixel search, and can be passed in this function. - vp9_comp_avg_pred(comp_pred, second_pred, w, h, y, y_stride); + vp9_comp_avg_pred(comp_pred, second_pred, w, h, y + offset, y_stride); besterr = vfp->vf(comp_pred, w, z, src_stride, sse1); *distortion = besterr; besterr += mv_err_cost(bestmv, ref_mv, mvjcost, mvcost, error_per_bit); @@ -880,7 +879,6 @@ int vp9_fast_dia_search(const MACROBLOCK *x, int vp9_full_range_search_c(const MACROBLOCK *x, MV *ref_mv, MV *best_mv, int search_param, int sad_per_bit, int *num00, const vp9_variance_fn_ptr_t *fn_ptr, - int *mvjcost, int *mvcost[2], const MV *center_mv) { const MACROBLOCKD *const xd = &x->e_mbd; const uint8_t *what = x->plane[0].src.buf; @@ -979,7 +977,6 @@ int vp9_diamond_search_sad_c(const MACROBLOCK *x, MV *ref_mv, MV *best_mv, int search_param, int sad_per_bit, int *num00, const vp9_variance_fn_ptr_t *fn_ptr, - int *mvjcost, int *mvcost[2], const MV *center_mv) { const MACROBLOCKD *const xd = &x->e_mbd; const struct buf_2d *const what = &x->plane[0].src; @@ -1072,7 +1069,6 @@ int vp9_diamond_search_sadx4(const MACROBLOCK *x, MV *ref_mv, MV *best_mv, int search_param, int sad_per_bit, int *num00, const vp9_variance_fn_ptr_t *fn_ptr, - int *mvjcost, int *mvcost[2], const MV *center_mv) { int i, j, step; @@ -1232,8 +1228,7 @@ int vp9_full_pixel_diamond(const VP9_COMP *cpi, MACROBLOCK *x, int thissme, n, num00 = 0; int bestsme = cpi->diamond_search_sad(x, mvp_full, &temp_mv, step_param, sadpb, &n, - fn_ptr, x->nmvjointcost, - x->mvcost, ref_mv); + fn_ptr, ref_mv); if (bestsme < INT_MAX) bestsme = vp9_get_mvpred_var(x, &temp_mv, ref_mv, fn_ptr, 1); *dst_mv = temp_mv; @@ -1251,8 +1246,7 @@ int vp9_full_pixel_diamond(const VP9_COMP *cpi, MACROBLOCK *x, } else { thissme = cpi->diamond_search_sad(x, mvp_full, &temp_mv, step_param + n, sadpb, &num00, - fn_ptr, x->nmvjointcost, x->mvcost, - ref_mv); + fn_ptr, ref_mv); if (thissme < INT_MAX) thissme = vp9_get_mvpred_var(x, &temp_mv, ref_mv, fn_ptr, 1); @@ -1272,8 +1266,7 @@ int vp9_full_pixel_diamond(const VP9_COMP *cpi, MACROBLOCK *x, const int search_range = 8; MV best_mv = *dst_mv; thissme = cpi->refining_search_sad(x, &best_mv, sadpb, search_range, - fn_ptr, x->nmvjointcost, x->mvcost, - ref_mv); + fn_ptr, ref_mv); if (thissme < INT_MAX) thissme = vp9_get_mvpred_var(x, &best_mv, ref_mv, fn_ptr, 1); if (thissme < bestsme) { @@ -1287,7 +1280,6 @@ int vp9_full_pixel_diamond(const VP9_COMP *cpi, MACROBLOCK *x, int vp9_full_search_sad_c(const MACROBLOCK *x, const MV *ref_mv, int sad_per_bit, int distance, const vp9_variance_fn_ptr_t *fn_ptr, - int *mvjcost, int *mvcost[2], const MV *center_mv, MV *best_mv) { int r, c; const MACROBLOCKD *const xd = &x->e_mbd; @@ -1325,7 +1317,6 @@ int vp9_full_search_sad_c(const MACROBLOCK *x, const MV *ref_mv, int vp9_full_search_sadx3(const MACROBLOCK *x, const MV *ref_mv, int sad_per_bit, int distance, const vp9_variance_fn_ptr_t *fn_ptr, - int *mvjcost, int *mvcost[2], const MV *center_mv, MV *best_mv) { const MACROBLOCKD *const xd = &x->e_mbd; const uint8_t *const what = x->plane[0].src.buf; @@ -1417,7 +1408,6 @@ int vp9_full_search_sadx3(const MACROBLOCK *x, const MV *ref_mv, int vp9_full_search_sadx8(const MACROBLOCK *x, const MV *ref_mv, int sad_per_bit, int distance, const vp9_variance_fn_ptr_t *fn_ptr, - int *mvjcost, int *mvcost[2], const MV *center_mv, MV *best_mv) { const MACROBLOCKD *const xd = &x->e_mbd; const uint8_t *const what = x->plane[0].src.buf; @@ -1537,7 +1527,6 @@ int vp9_refining_search_sad_c(const MACROBLOCK *x, MV *ref_mv, int error_per_bit, int search_range, const vp9_variance_fn_ptr_t *fn_ptr, - int *mvjcost, int *mvcost[2], const MV *center_mv) { const MV neighbors[4] = {{ -1, 0}, {0, -1}, {0, 1}, {1, 0}}; const MACROBLOCKD *const xd = &x->e_mbd; @@ -1587,7 +1576,6 @@ int vp9_refining_search_sadx4(const MACROBLOCK *x, MV *ref_mv, int error_per_bit, int search_range, const vp9_variance_fn_ptr_t *fn_ptr, - int *mvjcost, int *mvcost[2], const MV *center_mv) { const MACROBLOCKD *const xd = &x->e_mbd; const MV neighbors[4] = {{ -1, 0}, {0, -1}, {0, 1}, {1, 0}}; @@ -1673,7 +1661,6 @@ int vp9_refining_search_8p_c(const MACROBLOCK *x, MV *ref_mv, int error_per_bit, int search_range, const vp9_variance_fn_ptr_t *fn_ptr, - int *mvjcost, int *mvcost[2], const MV *center_mv, const uint8_t *second_pred, int w, int h) { const MV neighbors[8] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}, diff --git a/vp9/encoder/vp9_mcomp.h b/vp9/encoder/vp9_mcomp.h index f7b7c5e49..70d7985e4 100644 --- a/vp9/encoder/vp9_mcomp.h +++ b/vp9/encoder/vp9_mcomp.h @@ -110,14 +110,12 @@ typedef int (*vp9_full_search_fn_t)(const MACROBLOCK *x, const MV *ref_mv, int sad_per_bit, int distance, const vp9_variance_fn_ptr_t *fn_ptr, - int *mvjcost, int *mvcost[2], const MV *center_mv, MV *best_mv); typedef int (*vp9_refining_search_fn_t)(const MACROBLOCK *x, MV *ref_mv, int sad_per_bit, int distance, const vp9_variance_fn_ptr_t *fn_ptr, - int *mvjcost, int *mvcost[2], const MV *center_mv); typedef int (*vp9_diamond_search_fn_t)(const MACROBLOCK *x, @@ -125,14 +123,12 @@ typedef int (*vp9_diamond_search_fn_t)(const MACROBLOCK *x, int search_param, int sad_per_bit, int *num00, const vp9_variance_fn_ptr_t *fn_ptr, - int *mvjcost, int *mvcost[2], const MV *center_mv); int vp9_refining_search_8p_c(const MACROBLOCK *x, MV *ref_mv, int error_per_bit, int search_range, const vp9_variance_fn_ptr_t *fn_ptr, - int *mvjcost, int *mvcost[2], const MV *center_mv, const uint8_t *second_pred, int w, int h); #ifdef __cplusplus diff --git a/vp9/encoder/vp9_onyx_if.c b/vp9/encoder/vp9_onyx_if.c index 871d057c1..721ce48bb 100644 --- a/vp9/encoder/vp9_onyx_if.c +++ b/vp9/encoder/vp9_onyx_if.c @@ -386,117 +386,119 @@ static int is_slowest_mode(int mode) { static void set_rd_speed_thresholds(VP9_COMP *cpi) { int i; + RD_OPT *const rd = &cpi->rd; // Set baseline threshold values for (i = 0; i < MAX_MODES; ++i) - cpi->rd_thresh_mult[i] = is_slowest_mode(cpi->oxcf.mode) ? -500 : 0; - - cpi->rd_thresh_mult[THR_NEARESTMV] = 0; - cpi->rd_thresh_mult[THR_NEARESTG] = 0; - cpi->rd_thresh_mult[THR_NEARESTA] = 0; - - cpi->rd_thresh_mult[THR_DC] += 1000; - - cpi->rd_thresh_mult[THR_NEWMV] += 1000; - cpi->rd_thresh_mult[THR_NEWA] += 1000; - cpi->rd_thresh_mult[THR_NEWG] += 1000; - - cpi->rd_thresh_mult[THR_NEARMV] += 1000; - cpi->rd_thresh_mult[THR_NEARA] += 1000; - cpi->rd_thresh_mult[THR_COMP_NEARESTLA] += 1000; - cpi->rd_thresh_mult[THR_COMP_NEARESTGA] += 1000; - - cpi->rd_thresh_mult[THR_TM] += 1000; - - cpi->rd_thresh_mult[THR_COMP_NEARLA] += 1500; - cpi->rd_thresh_mult[THR_COMP_NEWLA] += 2000; - cpi->rd_thresh_mult[THR_NEARG] += 1000; - cpi->rd_thresh_mult[THR_COMP_NEARGA] += 1500; - cpi->rd_thresh_mult[THR_COMP_NEWGA] += 2000; - - cpi->rd_thresh_mult[THR_ZEROMV] += 2000; - cpi->rd_thresh_mult[THR_ZEROG] += 2000; - cpi->rd_thresh_mult[THR_ZEROA] += 2000; - cpi->rd_thresh_mult[THR_COMP_ZEROLA] += 2500; - cpi->rd_thresh_mult[THR_COMP_ZEROGA] += 2500; - - cpi->rd_thresh_mult[THR_H_PRED] += 2000; - cpi->rd_thresh_mult[THR_V_PRED] += 2000; - cpi->rd_thresh_mult[THR_D45_PRED ] += 2500; - cpi->rd_thresh_mult[THR_D135_PRED] += 2500; - cpi->rd_thresh_mult[THR_D117_PRED] += 2500; - cpi->rd_thresh_mult[THR_D153_PRED] += 2500; - cpi->rd_thresh_mult[THR_D207_PRED] += 2500; - cpi->rd_thresh_mult[THR_D63_PRED] += 2500; + rd->thresh_mult[i] = is_slowest_mode(cpi->oxcf.mode) ? -500 : 0; + + rd->thresh_mult[THR_NEARESTMV] = 0; + rd->thresh_mult[THR_NEARESTG] = 0; + rd->thresh_mult[THR_NEARESTA] = 0; + + rd->thresh_mult[THR_DC] += 1000; + + rd->thresh_mult[THR_NEWMV] += 1000; + rd->thresh_mult[THR_NEWA] += 1000; + rd->thresh_mult[THR_NEWG] += 1000; + + rd->thresh_mult[THR_NEARMV] += 1000; + rd->thresh_mult[THR_NEARA] += 1000; + rd->thresh_mult[THR_COMP_NEARESTLA] += 1000; + rd->thresh_mult[THR_COMP_NEARESTGA] += 1000; + + rd->thresh_mult[THR_TM] += 1000; + + rd->thresh_mult[THR_COMP_NEARLA] += 1500; + rd->thresh_mult[THR_COMP_NEWLA] += 2000; + rd->thresh_mult[THR_NEARG] += 1000; + rd->thresh_mult[THR_COMP_NEARGA] += 1500; + rd->thresh_mult[THR_COMP_NEWGA] += 2000; + + rd->thresh_mult[THR_ZEROMV] += 2000; + rd->thresh_mult[THR_ZEROG] += 2000; + rd->thresh_mult[THR_ZEROA] += 2000; + rd->thresh_mult[THR_COMP_ZEROLA] += 2500; + rd->thresh_mult[THR_COMP_ZEROGA] += 2500; + + rd->thresh_mult[THR_H_PRED] += 2000; + rd->thresh_mult[THR_V_PRED] += 2000; + rd->thresh_mult[THR_D45_PRED ] += 2500; + rd->thresh_mult[THR_D135_PRED] += 2500; + rd->thresh_mult[THR_D117_PRED] += 2500; + rd->thresh_mult[THR_D153_PRED] += 2500; + rd->thresh_mult[THR_D207_PRED] += 2500; + rd->thresh_mult[THR_D63_PRED] += 2500; /* disable frame modes if flags not set */ if (!(cpi->ref_frame_flags & VP9_LAST_FLAG)) { - cpi->rd_thresh_mult[THR_NEWMV ] = INT_MAX; - cpi->rd_thresh_mult[THR_NEARESTMV] = INT_MAX; - cpi->rd_thresh_mult[THR_ZEROMV ] = INT_MAX; - cpi->rd_thresh_mult[THR_NEARMV ] = INT_MAX; + rd->thresh_mult[THR_NEWMV ] = INT_MAX; + rd->thresh_mult[THR_NEARESTMV] = INT_MAX; + rd->thresh_mult[THR_ZEROMV ] = INT_MAX; + rd->thresh_mult[THR_NEARMV ] = INT_MAX; } if (!(cpi->ref_frame_flags & VP9_GOLD_FLAG)) { - cpi->rd_thresh_mult[THR_NEARESTG ] = INT_MAX; - cpi->rd_thresh_mult[THR_ZEROG ] = INT_MAX; - cpi->rd_thresh_mult[THR_NEARG ] = INT_MAX; - cpi->rd_thresh_mult[THR_NEWG ] = INT_MAX; + rd->thresh_mult[THR_NEARESTG ] = INT_MAX; + rd->thresh_mult[THR_ZEROG ] = INT_MAX; + rd->thresh_mult[THR_NEARG ] = INT_MAX; + rd->thresh_mult[THR_NEWG ] = INT_MAX; } if (!(cpi->ref_frame_flags & VP9_ALT_FLAG)) { - cpi->rd_thresh_mult[THR_NEARESTA ] = INT_MAX; - cpi->rd_thresh_mult[THR_ZEROA ] = INT_MAX; - cpi->rd_thresh_mult[THR_NEARA ] = INT_MAX; - cpi->rd_thresh_mult[THR_NEWA ] = INT_MAX; + rd->thresh_mult[THR_NEARESTA ] = INT_MAX; + rd->thresh_mult[THR_ZEROA ] = INT_MAX; + rd->thresh_mult[THR_NEARA ] = INT_MAX; + rd->thresh_mult[THR_NEWA ] = INT_MAX; } if ((cpi->ref_frame_flags & (VP9_LAST_FLAG | VP9_ALT_FLAG)) != (VP9_LAST_FLAG | VP9_ALT_FLAG)) { - cpi->rd_thresh_mult[THR_COMP_ZEROLA ] = INT_MAX; - cpi->rd_thresh_mult[THR_COMP_NEARESTLA] = INT_MAX; - cpi->rd_thresh_mult[THR_COMP_NEARLA ] = INT_MAX; - cpi->rd_thresh_mult[THR_COMP_NEWLA ] = INT_MAX; + rd->thresh_mult[THR_COMP_ZEROLA ] = INT_MAX; + rd->thresh_mult[THR_COMP_NEARESTLA] = INT_MAX; + rd->thresh_mult[THR_COMP_NEARLA ] = INT_MAX; + rd->thresh_mult[THR_COMP_NEWLA ] = INT_MAX; } if ((cpi->ref_frame_flags & (VP9_GOLD_FLAG | VP9_ALT_FLAG)) != (VP9_GOLD_FLAG | VP9_ALT_FLAG)) { - cpi->rd_thresh_mult[THR_COMP_ZEROGA ] = INT_MAX; - cpi->rd_thresh_mult[THR_COMP_NEARESTGA] = INT_MAX; - cpi->rd_thresh_mult[THR_COMP_NEARGA ] = INT_MAX; - cpi->rd_thresh_mult[THR_COMP_NEWGA ] = INT_MAX; + rd->thresh_mult[THR_COMP_ZEROGA ] = INT_MAX; + rd->thresh_mult[THR_COMP_NEARESTGA] = INT_MAX; + rd->thresh_mult[THR_COMP_NEARGA ] = INT_MAX; + rd->thresh_mult[THR_COMP_NEWGA ] = INT_MAX; } } static void set_rd_speed_thresholds_sub8x8(VP9_COMP *cpi) { const SPEED_FEATURES *const sf = &cpi->sf; + RD_OPT *const rd = &cpi->rd; int i; for (i = 0; i < MAX_REFS; ++i) - cpi->rd_thresh_mult_sub8x8[i] = is_slowest_mode(cpi->oxcf.mode) ? -500 : 0; + rd->thresh_mult_sub8x8[i] = is_slowest_mode(cpi->oxcf.mode) ? -500 : 0; - cpi->rd_thresh_mult_sub8x8[THR_LAST] += 2500; - cpi->rd_thresh_mult_sub8x8[THR_GOLD] += 2500; - cpi->rd_thresh_mult_sub8x8[THR_ALTR] += 2500; - cpi->rd_thresh_mult_sub8x8[THR_INTRA] += 2500; - cpi->rd_thresh_mult_sub8x8[THR_COMP_LA] += 4500; - cpi->rd_thresh_mult_sub8x8[THR_COMP_GA] += 4500; + rd->thresh_mult_sub8x8[THR_LAST] += 2500; + rd->thresh_mult_sub8x8[THR_GOLD] += 2500; + rd->thresh_mult_sub8x8[THR_ALTR] += 2500; + rd->thresh_mult_sub8x8[THR_INTRA] += 2500; + rd->thresh_mult_sub8x8[THR_COMP_LA] += 4500; + rd->thresh_mult_sub8x8[THR_COMP_GA] += 4500; // Check for masked out split cases. for (i = 0; i < MAX_REFS; i++) if (sf->disable_split_mask & (1 << i)) - cpi->rd_thresh_mult_sub8x8[i] = INT_MAX; + rd->thresh_mult_sub8x8[i] = INT_MAX; // disable mode test if frame flag is not set if (!(cpi->ref_frame_flags & VP9_LAST_FLAG)) - cpi->rd_thresh_mult_sub8x8[THR_LAST] = INT_MAX; + rd->thresh_mult_sub8x8[THR_LAST] = INT_MAX; if (!(cpi->ref_frame_flags & VP9_GOLD_FLAG)) - cpi->rd_thresh_mult_sub8x8[THR_GOLD] = INT_MAX; + rd->thresh_mult_sub8x8[THR_GOLD] = INT_MAX; if (!(cpi->ref_frame_flags & VP9_ALT_FLAG)) - cpi->rd_thresh_mult_sub8x8[THR_ALTR] = INT_MAX; + rd->thresh_mult_sub8x8[THR_ALTR] = INT_MAX; if ((cpi->ref_frame_flags & (VP9_LAST_FLAG | VP9_ALT_FLAG)) != (VP9_LAST_FLAG | VP9_ALT_FLAG)) - cpi->rd_thresh_mult_sub8x8[THR_COMP_LA] = INT_MAX; + rd->thresh_mult_sub8x8[THR_COMP_LA] = INT_MAX; if ((cpi->ref_frame_flags & (VP9_GOLD_FLAG | VP9_ALT_FLAG)) != (VP9_GOLD_FLAG | VP9_ALT_FLAG)) - cpi->rd_thresh_mult_sub8x8[THR_COMP_GA] = INT_MAX; + rd->thresh_mult_sub8x8[THR_COMP_GA] = INT_MAX; } static void set_speed_features(VP9_COMP *cpi) { @@ -1276,9 +1278,9 @@ VP9_COMP *vp9_create_compressor(VP9_CONFIG *oxcf) { // Default rd threshold factors for mode selection for (i = 0; i < BLOCK_SIZES; ++i) { for (j = 0; j < MAX_MODES; ++j) - cpi->rd_thresh_freq_fact[i][j] = 32; + cpi->rd.thresh_freq_fact[i][j] = 32; for (j = 0; j < MAX_REFS; ++j) - cpi->rd_thresh_freq_sub8x8[i][j] = 32; + cpi->rd.thresh_freq_sub8x8[i][j] = 32; } #define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SVFHH, SVFHV, SVFHHV, \ @@ -2537,7 +2539,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi, vp9_clear_system_state(); - vp9_zero(cpi->rd_tx_select_threshes); + vp9_zero(cpi->rd.tx_select_threshes); #if CONFIG_VP9_POSTPROC if (cpi->oxcf.noise_sensitivity > 0) { diff --git a/vp9/encoder/vp9_onyx_int.h b/vp9/encoder/vp9_onyx_int.h index 126711e02..9ad6ae49e 100644 --- a/vp9/encoder/vp9_onyx_int.h +++ b/vp9/encoder/vp9_onyx_int.h @@ -185,6 +185,7 @@ typedef enum { AQ_MODE_COUNT // This should always be the last member of the enum } AQ_MODE; + typedef struct VP9_CONFIG { BITSTREAM_PROFILE profile; BIT_DEPTH bit_depth; @@ -281,6 +282,35 @@ typedef struct VP9_CONFIG { vp8e_tuning tuning; } VP9_CONFIG; + +typedef struct RD_OPT { + // Thresh_mult is used to set a threshold for the rd score. A higher value + // means that we will accept the best mode so far more often. This number + // is used in combination with the current block size, and thresh_freq_fact + // to pick a threshold. + int thresh_mult[MAX_MODES]; + int thresh_mult_sub8x8[MAX_REFS]; + + int threshes[MAX_SEGMENTS][BLOCK_SIZES][MAX_MODES]; + int thresh_freq_fact[BLOCK_SIZES][MAX_MODES]; + int thresh_sub8x8[MAX_SEGMENTS][BLOCK_SIZES][MAX_REFS]; + int thresh_freq_sub8x8[BLOCK_SIZES][MAX_REFS]; + + int64_t comp_pred_diff[REFERENCE_MODES]; + int64_t prediction_type_threshes[MAX_REF_FRAMES][REFERENCE_MODES]; + int64_t tx_select_diff[TX_MODES]; + // FIXME(rbultje) can this overflow? + int tx_select_threshes[MAX_REF_FRAMES][TX_MODES]; + + int64_t filter_diff[SWITCHABLE_FILTER_CONTEXTS]; + int64_t filter_threshes[MAX_REF_FRAMES][SWITCHABLE_FILTER_CONTEXTS]; + int64_t filter_cache[SWITCHABLE_FILTER_CONTEXTS]; + int64_t mask_filter; + + int RDMULT; + int RDDIV; +} RD_OPT; + typedef struct VP9_COMP { QUANTS quants; MACROBLOCK mb; @@ -343,31 +373,7 @@ typedef struct VP9_COMP { // Ambient reconstruction err target for force key frames int ambient_err; - // Thresh_mult is used to set a threshold for the rd score. A higher value - // means that we will accept the best mode so far more often. This number - // is used in combination with the current block size, and thresh_freq_fact - // to pick a threshold. - int rd_thresh_mult[MAX_MODES]; - int rd_thresh_mult_sub8x8[MAX_REFS]; - - int rd_threshes[MAX_SEGMENTS][BLOCK_SIZES][MAX_MODES]; - int rd_thresh_freq_fact[BLOCK_SIZES][MAX_MODES]; - int rd_thresh_sub8x8[MAX_SEGMENTS][BLOCK_SIZES][MAX_REFS]; - int rd_thresh_freq_sub8x8[BLOCK_SIZES][MAX_REFS]; - - int64_t rd_comp_pred_diff[REFERENCE_MODES]; - int64_t rd_prediction_type_threshes[MAX_REF_FRAMES][REFERENCE_MODES]; - int64_t rd_tx_select_diff[TX_MODES]; - // FIXME(rbultje) can this overflow? - int rd_tx_select_threshes[MAX_REF_FRAMES][TX_MODES]; - - int64_t rd_filter_diff[SWITCHABLE_FILTER_CONTEXTS]; - int64_t rd_filter_threshes[MAX_REF_FRAMES][SWITCHABLE_FILTER_CONTEXTS]; - int64_t rd_filter_cache[SWITCHABLE_FILTER_CONTEXTS]; - int64_t mask_filter_rd; - - int RDMULT; - int RDDIV; + RD_OPT rd; CODING_CONTEXT coding_context; diff --git a/vp9/encoder/vp9_pickmode.c b/vp9/encoder/vp9_pickmode.c index f3fe99cdb..3d398edc9 100644 --- a/vp9/encoder/vp9_pickmode.c +++ b/vp9/encoder/vp9_pickmode.c @@ -233,8 +233,8 @@ int64_t vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, const int64_t intra_mode_cost = 50; unsigned char segment_id = mbmi->segment_id; - const int *const rd_threshes = cpi->rd_threshes[segment_id][bsize]; - const int *const rd_thresh_freq_fact = cpi->rd_thresh_freq_fact[bsize]; + const int *const rd_threshes = cpi->rd.threshes[segment_id][bsize]; + const int *const rd_thresh_freq_fact = cpi->rd.thresh_freq_fact[bsize]; // Mode index conversion form THR_MODES to MB_PREDICTION_MODE for a ref frame. int mode_idx[MB_MODE_COUNT] = {0}; INTERP_FILTER filter_ref = SWITCHABLE; diff --git a/vp9/encoder/vp9_ratectrl.c b/vp9/encoder/vp9_ratectrl.c index 3fd99171b..b1ef08291 100644 --- a/vp9/encoder/vp9_ratectrl.c +++ b/vp9/encoder/vp9_ratectrl.c @@ -1094,6 +1094,7 @@ void vp9_rc_postencode_update(VP9_COMP *cpi, uint64_t bytes_used) { const VP9_COMMON *const cm = &cpi->common; const VP9_CONFIG *const oxcf = &cpi->oxcf; RATE_CONTROL *const rc = &cpi->rc; + const int qindex = cm->base_qindex; // Update rate control heuristics rc->projected_frame_size = (int)(bytes_used << 3); @@ -1105,25 +1106,24 @@ void vp9_rc_postencode_update(VP9_COMP *cpi, uint64_t bytes_used) { // Keep a record of last Q and ambient average Q. if (cm->frame_type == KEY_FRAME) { - rc->last_q[KEY_FRAME] = cm->base_qindex; - rc->avg_frame_qindex[KEY_FRAME] = ROUND_POWER_OF_TWO( - 3 * rc->avg_frame_qindex[KEY_FRAME] + cm->base_qindex, 2); + rc->last_q[KEY_FRAME] = qindex; + rc->avg_frame_qindex[KEY_FRAME] = + ROUND_POWER_OF_TWO(3 * rc->avg_frame_qindex[KEY_FRAME] + qindex, 2); } else if (!rc->is_src_frame_alt_ref && - (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame) && - !(cpi->use_svc && oxcf->end_usage == USAGE_STREAM_FROM_SERVER)) { - rc->last_q[2] = cm->base_qindex; - rc->avg_frame_qindex[2] = ROUND_POWER_OF_TWO( - 3 * rc->avg_frame_qindex[2] + cm->base_qindex, 2); + (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame) && + !(cpi->use_svc && oxcf->end_usage == USAGE_STREAM_FROM_SERVER)) { + rc->last_q[2] = qindex; + rc->avg_frame_qindex[2] = + ROUND_POWER_OF_TWO(3 * rc->avg_frame_qindex[2] + qindex, 2); } else { - rc->last_q[INTER_FRAME] = cm->base_qindex; - rc->avg_frame_qindex[INTER_FRAME] = ROUND_POWER_OF_TWO( - 3 * rc->avg_frame_qindex[INTER_FRAME] + cm->base_qindex, 2); + rc->last_q[INTER_FRAME] = qindex; + rc->avg_frame_qindex[INTER_FRAME] = + ROUND_POWER_OF_TWO(3 * rc->avg_frame_qindex[INTER_FRAME] + qindex, 2); rc->ni_frames++; - rc->tot_q += vp9_convert_qindex_to_q(cm->base_qindex); - rc->avg_q = rc->tot_q / (double)rc->ni_frames; - + rc->tot_q += vp9_convert_qindex_to_q(qindex); + rc->avg_q = rc->tot_q / rc->ni_frames; // Calculate the average Q for normal inter frames (not key or GFU frames). - rc->ni_tot_qi += cm->base_qindex; + rc->ni_tot_qi += qindex; rc->ni_av_qi = rc->ni_tot_qi / rc->ni_frames; } @@ -1132,11 +1132,11 @@ void vp9_rc_postencode_update(VP9_COMP *cpi, uint64_t bytes_used) { // If all mbs in this group are skipped only update if the Q value is // better than that already stored. // This is used to help set quality in forced key frames to reduce popping - if ((cm->base_qindex < rc->last_boosted_qindex) || + if ((qindex < rc->last_boosted_qindex) || ((cpi->static_mb_pct < 100) && ((cm->frame_type == KEY_FRAME) || cpi->refresh_alt_ref_frame || (cpi->refresh_golden_frame && !rc->is_src_frame_alt_ref)))) { - rc->last_boosted_qindex = cm->base_qindex; + rc->last_boosted_qindex = qindex; } update_buffer_level(cpi, rc->projected_frame_size); diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c index f8ec15e6e..d498f4c7f 100644 --- a/vp9/encoder/vp9_rdopt.c +++ b/vp9/encoder/vp9_rdopt.c @@ -245,6 +245,7 @@ void vp9_initialize_me_consts(VP9_COMP *cpi, int qindex) { static void set_block_thresholds(VP9_COMP *cpi) { const VP9_COMMON *const cm = &cpi->common; + RD_OPT *const rd = &cpi->rd; int i, bsize, segment_id; for (segment_id = 0; segment_id < MAX_SEGMENTS; ++segment_id) { @@ -260,14 +261,14 @@ static void set_block_thresholds(VP9_COMP *cpi) { const int thresh_max = INT_MAX / t; for (i = 0; i < MAX_MODES; ++i) - cpi->rd_threshes[segment_id][bsize][i] = - cpi->rd_thresh_mult[i] < thresh_max ? cpi->rd_thresh_mult[i] * t / 4 + rd->threshes[segment_id][bsize][i] = + rd->thresh_mult[i] < thresh_max ? rd->thresh_mult[i] * t / 4 : INT_MAX; for (i = 0; i < MAX_REFS; ++i) { - cpi->rd_thresh_sub8x8[segment_id][bsize][i] = - cpi->rd_thresh_mult_sub8x8[i] < thresh_max - ? cpi->rd_thresh_mult_sub8x8[i] * t / 4 + rd->thresh_sub8x8[segment_id][bsize][i] = + rd->thresh_mult_sub8x8[i] < thresh_max + ? rd->thresh_mult_sub8x8[i] * t / 4 : INT_MAX; } } @@ -281,10 +282,10 @@ void vp9_initialize_rd_consts(VP9_COMP *cpi) { vp9_clear_system_state(); - cpi->RDDIV = RDDIV_BITS; // in bits (to multiply D by 128) - cpi->RDMULT = vp9_compute_rd_mult(cpi, cm->base_qindex + cm->y_dc_delta_q); + cpi->rd.RDDIV = RDDIV_BITS; // in bits (to multiply D by 128) + cpi->rd.RDMULT = vp9_compute_rd_mult(cpi, cm->base_qindex + cm->y_dc_delta_q); - x->errorperbit = cpi->RDMULT / RD_MULT_EPB_RATIO; + x->errorperbit = cpi->rd.RDMULT / RD_MULT_EPB_RATIO; x->errorperbit += (x->errorperbit == 0); x->select_txfm_size = (cpi->sf.tx_size_search_method == USE_LARGESTALL && @@ -1891,7 +1892,6 @@ static void rd_check_segment_txsize(VP9_COMP *cpi, MACROBLOCK *x, x->mv_row_min, x->mv_row_max); thissme = cpi->full_search_sad(x, &mvp_full, sadpb, 16, v_fn_ptr, - x->nmvjointcost, x->mvcost, &bsi->ref_mv[0]->as_mv, &best_mv->as_mv); if (thissme < bestsme) { @@ -2618,7 +2618,6 @@ static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, bestsme = vp9_refining_search_8p_c(x, &tmp_mv, sadpb, search_range, &cpi->fn_ptr[bsize], - x->nmvjointcost, x->mvcost, &ref_mv[id].as_mv, second_pred, pw, ph); if (bestsme < INT_MAX) @@ -2699,6 +2698,7 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, int64_t *psse, const int64_t ref_best_rd) { VP9_COMMON *cm = &cpi->common; + RD_OPT *rd_opt = &cpi->rd; MACROBLOCKD *xd = &x->e_mbd; MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; const int is_comp_pred = has_second_ref(mbmi); @@ -2796,14 +2796,13 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, // Search for best switchable filter by checking the variance of // pred error irrespective of whether the filter will be used - cpi->mask_filter_rd = 0; + rd_opt->mask_filter = 0; for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i) - cpi->rd_filter_cache[i] = INT64_MAX; + rd_opt->filter_cache[i] = INT64_MAX; if (cm->interp_filter != BILINEAR) { *best_filter = EIGHTTAP; - if (x->source_variance < - cpi->sf.disable_filter_search_var_thresh) { + if (x->source_variance < cpi->sf.disable_filter_search_var_thresh) { *best_filter = EIGHTTAP; } else { int newbest; @@ -2819,12 +2818,12 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, if (i > 0 && intpel_mv) { rd = RDCOST(x->rdmult, x->rddiv, tmp_rate_sum, tmp_dist_sum); - cpi->rd_filter_cache[i] = rd; - cpi->rd_filter_cache[SWITCHABLE_FILTERS] = - MIN(cpi->rd_filter_cache[SWITCHABLE_FILTERS], rd + rs_rd); + rd_opt->filter_cache[i] = rd; + rd_opt->filter_cache[SWITCHABLE_FILTERS] = + MIN(rd_opt->filter_cache[SWITCHABLE_FILTERS], rd + rs_rd); if (cm->interp_filter == SWITCHABLE) rd += rs_rd; - cpi->mask_filter_rd = MAX(cpi->mask_filter_rd, rd); + rd_opt->mask_filter = MAX(rd_opt->mask_filter, rd); } else { int rate_sum = 0; int64_t dist_sum = 0; @@ -2844,12 +2843,12 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, model_rd_for_sb(cpi, bsize, x, xd, &rate_sum, &dist_sum); rd = RDCOST(x->rdmult, x->rddiv, rate_sum, dist_sum); - cpi->rd_filter_cache[i] = rd; - cpi->rd_filter_cache[SWITCHABLE_FILTERS] = - MIN(cpi->rd_filter_cache[SWITCHABLE_FILTERS], rd + rs_rd); + rd_opt->filter_cache[i] = rd; + rd_opt->filter_cache[SWITCHABLE_FILTERS] = + MIN(rd_opt->filter_cache[SWITCHABLE_FILTERS], rd + rs_rd); if (cm->interp_filter == SWITCHABLE) rd += rs_rd; - cpi->mask_filter_rd = MAX(cpi->mask_filter_rd, rd); + rd_opt->mask_filter = MAX(rd_opt->mask_filter, rd); if (i == 0 && intpel_mv) { tmp_rate_sum = rate_sum; @@ -3126,6 +3125,7 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, PICK_MODE_CONTEXT *ctx, int64_t best_rd_so_far) { 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; const struct segmentation *const seg = &cm->seg; @@ -3165,8 +3165,8 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, int best_skip2 = 0; int mode_skip_mask = 0; int mode_skip_start = cpi->sf.mode_skip_start + 1; - const int *const rd_threshes = cpi->rd_threshes[segment_id][bsize]; - const int *const rd_thresh_freq_fact = cpi->rd_thresh_freq_fact[bsize]; + const int *const rd_threshes = rd_opt->threshes[segment_id][bsize]; + const int *const rd_thresh_freq_fact = rd_opt->thresh_freq_fact[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]]; @@ -3611,21 +3611,21 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, /* keep record of best filter type */ if (!mode_excluded && cm->interp_filter != BILINEAR) { - int64_t ref = cpi->rd_filter_cache[cm->interp_filter == SWITCHABLE ? + int64_t ref = rd_opt->filter_cache[cm->interp_filter == SWITCHABLE ? SWITCHABLE_FILTERS : cm->interp_filter]; for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { int64_t adj_rd; if (ref == INT64_MAX) adj_rd = 0; - else if (cpi->rd_filter_cache[i] == INT64_MAX) + else if (rd_opt->filter_cache[i] == INT64_MAX) // when early termination is triggered, the encoder does not have // access to the rate-distortion cost. it only knows that the cost // should be above the maximum valid value. hence it takes the known // maximum plus an arbitrary constant as the rate-distortion cost. - adj_rd = cpi->mask_filter_rd - ref + 10; + adj_rd = rd_opt->mask_filter - ref + 10; else - adj_rd = cpi->rd_filter_cache[i] - ref; + adj_rd = rd_opt->filter_cache[i] - ref; adj_rd += this_rd; best_filter_rd[i] = MIN(best_filter_rd[i], adj_rd); @@ -3687,7 +3687,7 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, // combination that wins out. if (cpi->sf.adaptive_rd_thresh) { for (mode_index = 0; mode_index < MAX_MODES; ++mode_index) { - int *const fact = &cpi->rd_thresh_freq_fact[bsize][mode_index]; + int *const fact = &rd_opt->thresh_freq_fact[bsize][mode_index]; if (mode_index == best_mode_index) { *fact -= (*fact >> 3); @@ -3759,6 +3759,7 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x, PICK_MODE_CONTEXT *ctx, int64_t best_rd_so_far) { 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; const struct segmentation *const seg = &cm->seg; @@ -3880,9 +3881,9 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x, // Test best rd so far against threshold for trying this mode. if ((best_rd < - ((int64_t)cpi->rd_thresh_sub8x8[segment_id][bsize][mode_index] * - cpi->rd_thresh_freq_sub8x8[bsize][mode_index] >> 5)) || - cpi->rd_thresh_sub8x8[segment_id][bsize][mode_index] == INT_MAX) + ((int64_t)rd_opt->thresh_sub8x8[segment_id][bsize][mode_index] * + rd_opt->thresh_freq_sub8x8[bsize][mode_index] >> 5)) || + rd_opt->thresh_sub8x8[segment_id][bsize][mode_index] == INT_MAX) continue; if (ref_frame > INTRA_FRAME && @@ -4011,14 +4012,13 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x, int uv_skippable; this_rd_thresh = (ref_frame == LAST_FRAME) ? - cpi->rd_thresh_sub8x8[segment_id][bsize][THR_LAST] : - cpi->rd_thresh_sub8x8[segment_id][bsize][THR_ALTR]; + rd_opt->thresh_sub8x8[segment_id][bsize][THR_LAST] : + rd_opt->thresh_sub8x8[segment_id][bsize][THR_ALTR]; this_rd_thresh = (ref_frame == GOLDEN_FRAME) ? - cpi->rd_thresh_sub8x8[segment_id][bsize][THR_GOLD] : this_rd_thresh; - - cpi->mask_filter_rd = 0; + rd_opt->thresh_sub8x8[segment_id][bsize][THR_GOLD] : this_rd_thresh; + rd_opt->mask_filter = 0; for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i) - cpi->rd_filter_cache[i] = INT64_MAX; + rd_opt->filter_cache[i] = INT64_MAX; if (cm->interp_filter != BILINEAR) { tmp_best_filter = EIGHTTAP; @@ -4051,14 +4051,14 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x, continue; rs = vp9_get_switchable_rate(x); rs_rd = RDCOST(x->rdmult, x->rddiv, rs, 0); - cpi->rd_filter_cache[switchable_filter_index] = tmp_rd; - cpi->rd_filter_cache[SWITCHABLE_FILTERS] = - MIN(cpi->rd_filter_cache[SWITCHABLE_FILTERS], + rd_opt->filter_cache[switchable_filter_index] = tmp_rd; + rd_opt->filter_cache[SWITCHABLE_FILTERS] = + MIN(rd_opt->filter_cache[SWITCHABLE_FILTERS], tmp_rd + rs_rd); if (cm->interp_filter == SWITCHABLE) tmp_rd += rs_rd; - cpi->mask_filter_rd = MAX(cpi->mask_filter_rd, tmp_rd); + rd_opt->mask_filter = MAX(rd_opt->mask_filter, tmp_rd); newbest = (tmp_rd < tmp_best_rd); if (newbest) { @@ -4292,20 +4292,20 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x, /* keep record of best filter type */ if (!mode_excluded && !disable_skip && ref_frame != INTRA_FRAME && cm->interp_filter != BILINEAR) { - int64_t ref = cpi->rd_filter_cache[cm->interp_filter == SWITCHABLE ? + int64_t ref = rd_opt->filter_cache[cm->interp_filter == SWITCHABLE ? SWITCHABLE_FILTERS : cm->interp_filter]; int64_t adj_rd; for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { if (ref == INT64_MAX) adj_rd = 0; - else if (cpi->rd_filter_cache[i] == INT64_MAX) + else if (rd_opt->filter_cache[i] == INT64_MAX) // when early termination is triggered, the encoder does not have // access to the rate-distortion cost. it only knows that the cost // should be above the maximum valid value. hence it takes the known // maximum plus an arbitrary constant as the rate-distortion cost. - adj_rd = cpi->mask_filter_rd - ref + 10; + adj_rd = rd_opt->mask_filter - ref + 10; else - adj_rd = cpi->rd_filter_cache[i] - ref; + adj_rd = rd_opt->filter_cache[i] - ref; adj_rd += this_rd; best_filter_rd[i] = MIN(best_filter_rd[i], adj_rd); @@ -4352,7 +4352,7 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x, // combination that wins out. if (cpi->sf.adaptive_rd_thresh) { for (mode_index = 0; mode_index < MAX_REFS; ++mode_index) { - int *const fact = &cpi->rd_thresh_freq_sub8x8[bsize][mode_index]; + int *const fact = &rd_opt->thresh_freq_sub8x8[bsize][mode_index]; if (mode_index == best_mode_index) { *fact -= (*fact >> 3); |