From ab1f9054389dc14736d73c43101a0f882c120a33 Mon Sep 17 00:00:00 2001 From: Dmitry Kovalev Date: Mon, 10 Mar 2014 10:58:32 -0700 Subject: [PATCH] Cleaning up rd_pick_sb_modes() function. Changing aq_mode type from int to AQ_MODE enum. Change-Id: Ib7b5f0b70d02ded58a31dfade9c05a347f73beca --- vp9/encoder/vp9_encodeframe.c | 31 +++++++++++++++---------------- vp9/encoder/vp9_onyx_int.h | 6 +++--- vp9/vp9_cx_iface.c | 2 +- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c index 76ef2705c..11d4749ba 100644 --- a/vp9/encoder/vp9_encodeframe.c +++ b/vp9/encoder/vp9_encodeframe.c @@ -662,10 +662,11 @@ static void rd_pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile, VP9_COMMON *const cm = &cpi->common; MACROBLOCK *const x = &cpi->mb; MACROBLOCKD *const xd = &x->e_mbd; + MB_MODE_INFO *mbmi; struct macroblock_plane *const p = x->plane; struct macroblockd_plane *const pd = xd->plane; - int i; - int orig_rdmult = x->rdmult; + const AQ_MODE aq_mode = cpi->oxcf.aq_mode; + int i, orig_rdmult = x->rdmult; double rdmult_ratio; vp9_clear_system_state(); @@ -685,7 +686,8 @@ static void rd_pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile, } set_offsets(cpi, tile, mi_row, mi_col, bsize); - xd->mi_8x8[0]->mbmi.sb_type = bsize; + mbmi = &xd->mi_8x8[0]->mbmi; + mbmi->sb_type = bsize; for (i = 0; i < MAX_MB_PLANE; ++i) { p[i].coeff = ctx->coeff_pbuf[i][0]; @@ -697,23 +699,22 @@ static void rd_pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile, x->skip_recode = 0; // Set to zero to make sure we do not use the previous encoded frame stats - xd->mi_8x8[0]->mbmi.skip = 0; + mbmi->skip = 0; x->source_variance = get_sby_perpixel_variance(cpi, x, bsize); - if (cpi->oxcf.aq_mode == VARIANCE_AQ) { + if (aq_mode == VARIANCE_AQ) { const int energy = bsize <= BLOCK_16X16 ? x->mb_energy : vp9_block_energy(cpi, x, bsize); if (cm->frame_type == KEY_FRAME || cpi->refresh_alt_ref_frame || (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref)) { - xd->mi_8x8[0]->mbmi.segment_id = vp9_vaq_segment_id(energy); + mbmi->segment_id = vp9_vaq_segment_id(energy); } else { const uint8_t *const map = cm->seg.update_map ? cpi->segmentation_map : cm->last_frame_seg_map; - xd->mi_8x8[0]->mbmi.segment_id = - vp9_get_segment_id(cm, map, bsize, mi_row, mi_col); + mbmi->segment_id = vp9_get_segment_id(cm, map, bsize, mi_row, mi_col); } rdmult_ratio = vp9_vaq_rdmult_ratio(energy); @@ -723,18 +724,17 @@ static void rd_pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile, if (cpi->oxcf.tuning == VP8_TUNE_SSIM) activity_masking(cpi, x); - if (cpi->oxcf.aq_mode == VARIANCE_AQ) { + if (aq_mode == VARIANCE_AQ) { vp9_clear_system_state(); x->rdmult = (int)round(x->rdmult * rdmult_ratio); - } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { + } else if (aq_mode == COMPLEXITY_AQ) { const int mi_offset = mi_row * cm->mi_cols + mi_col; unsigned char complexity = cpi->complexity_map[mi_offset]; const int is_edge = (mi_row <= 1) || (mi_row >= (cm->mi_rows - 2)) || (mi_col <= 1) || (mi_col >= (cm->mi_cols - 2)); - if (!is_edge && (complexity > 128)) { - x->rdmult = x->rdmult + ((x->rdmult * (complexity - 128)) / 256); - } + if (!is_edge && (complexity > 128)) + x->rdmult += ((x->rdmult * (complexity - 128)) / 256); } // Find best coding mode & reconstruct the MB so it is available @@ -751,14 +751,13 @@ static void rd_pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile, totaldist, bsize, ctx, best_rd); } - if (cpi->oxcf.aq_mode == VARIANCE_AQ) { + if (aq_mode == VARIANCE_AQ) { x->rdmult = orig_rdmult; if (*totalrate != INT_MAX) { vp9_clear_system_state(); *totalrate = (int)round(*totalrate * rdmult_ratio); } - } - else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { + } else if (aq_mode == COMPLEXITY_AQ) { x->rdmult = orig_rdmult; } } diff --git a/vp9/encoder/vp9_onyx_int.h b/vp9/encoder/vp9_onyx_int.h index 4ee035b37..1540d6e26 100644 --- a/vp9/encoder/vp9_onyx_int.h +++ b/vp9/encoder/vp9_onyx_int.h @@ -484,8 +484,8 @@ typedef enum { NO_AQ = 0, VARIANCE_AQ = 1, COMPLEXITY_AQ = 2, - AQ_MODES_COUNT // This should always be the last member of the enum -} AQ_MODES; + AQ_MODE_COUNT // This should always be the last member of the enum +} AQ_MODE; typedef struct { int version; // 4 versions of bitstream defined: @@ -553,7 +553,7 @@ typedef struct { int best_allowed_q; int cq_level; int lossless; - int aq_mode; // Adaptive Quantization mode + AQ_MODE aq_mode; // Adaptive Quantization mode // two pass datarate control int two_pass_vbrbias; // two pass datarate control tweaks diff --git a/vp9/vp9_cx_iface.c b/vp9/vp9_cx_iface.c index 8d89e744e..895fa1629 100644 --- a/vp9/vp9_cx_iface.c +++ b/vp9/vp9_cx_iface.c @@ -156,7 +156,7 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx, RANGE_CHECK_HI(cfg, rc_max_quantizer, 0); RANGE_CHECK_HI(cfg, rc_min_quantizer, 0); } - RANGE_CHECK(vp8_cfg, aq_mode, 0, AQ_MODES_COUNT - 1); + RANGE_CHECK(vp8_cfg, aq_mode, 0, AQ_MODE_COUNT - 1); RANGE_CHECK_HI(cfg, g_threads, 64); RANGE_CHECK_HI(cfg, g_lag_in_frames, MAX_LAG_BUFFERS); -- 2.40.0