From d60523bc28280d6fe54603d10c7248bd337a8876 Mon Sep 17 00:00:00 2001 From: Geza Lore Date: Thu, 9 Jun 2016 15:12:27 +0100 Subject: [PATCH] Refactor variance aq. Explicitly signal when the segment map is being refreshed when using VARIANE_AQ. This simplifies decisions about when the segment id needs to be set from the previous segment map vs based on the current variance. Change-Id: Ieb12c950e9cfbc3f53f4d184880071dea805563c --- vp10/encoder/aq_variance.c | 2 ++ vp10/encoder/encodeframe.c | 25 ++++++++----------------- vp10/encoder/encoder.c | 2 ++ vp10/encoder/encoder.h | 3 +++ 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/vp10/encoder/aq_variance.c b/vp10/encoder/aq_variance.c index 45dc8b8f1..e99310f79 100644 --- a/vp10/encoder/aq_variance.c +++ b/vp10/encoder/aq_variance.c @@ -52,6 +52,8 @@ void vp10_vaq_frame_setup(VP10_COMP *cpi) { if (frame_is_intra_only(cm) || cm->error_resilient_mode || cpi->refresh_alt_ref_frame || (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref)) { + cpi->vaq_refresh = 1; + vp10_enable_segmentation(seg); vp10_clearall_segfeatures(seg); diff --git a/vp10/encoder/encodeframe.c b/vp10/encoder/encodeframe.c index c751e6725..40301b3d1 100644 --- a/vp10/encoder/encodeframe.c +++ b/vp10/encoder/encodeframe.c @@ -313,7 +313,7 @@ static void set_offsets(VP10_COMP *cpi, const TileInfo *const tile, // Setup segment ID. if (seg->enabled) { - if (cpi->oxcf.aq_mode != VARIANCE_AQ) { + if (!cpi->vaq_refresh) { const uint8_t *const map = seg->update_map ? cpi->segmentation_map : cm->last_frame_seg_map; mbmi->segment_id = get_segment_id(cm, map, bsize, mi_row, mi_col); @@ -388,7 +388,7 @@ static void set_offsets_extend(VP10_COMP *cpi, ThreadData *td, // Setup segment ID. if (seg->enabled) { - if (cpi->oxcf.aq_mode != VARIANCE_AQ) { + if (!cpi->vaq_refresh) { const uint8_t *const map = seg->update_map ? cpi->segmentation_map : cm->last_frame_seg_map; mbmi->segment_id = get_segment_id(cm, map, bsize_ori, @@ -1727,26 +1727,17 @@ static void rd_pick_sb_modes(VP10_COMP *cpi, orig_rdmult = x->rdmult; if (aq_mode == VARIANCE_AQ) { - const int energy = bsize <= BLOCK_16X16 ? x->mb_energy - : vp10_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)) { + if (cpi->vaq_refresh) { + const int energy = bsize <= BLOCK_16X16 ? + x->mb_energy : vp10_block_energy(cpi, x, bsize); mbmi->segment_id = vp10_vaq_segment_id(energy); - } else { - const uint8_t *const map = cm->seg.update_map ? cpi->segmentation_map - : cm->last_frame_seg_map; - mbmi->segment_id = get_segment_id(cm, map, bsize, mi_row, mi_col); } x->rdmult = set_segment_rdmult(cpi, x, mbmi->segment_id); } else if (aq_mode == COMPLEXITY_AQ) { x->rdmult = set_segment_rdmult(cpi, x, mbmi->segment_id); } else if (aq_mode == CYCLIC_REFRESH_AQ) { - const uint8_t *const map = cm->seg.update_map ? cpi->segmentation_map - : cm->last_frame_seg_map; // If segment is boosted, use rdmult for that segment. - if (cyclic_refresh_segment_id_boosted( - get_segment_id(cm, map, bsize, mi_row, mi_col))) + if (cyclic_refresh_segment_id_boosted(mbmi->segment_id)) x->rdmult = vp10_cyclic_refresh_get_rdmult(cpi->cyclic_refresh); } @@ -2556,7 +2547,7 @@ static void rd_use_partition(VP10_COMP *cpi, save_context(x, &x_ctx, mi_row, mi_col, bsize); - if (bsize == BLOCK_16X16 && cpi->oxcf.aq_mode) { + if (bsize == BLOCK_16X16 && cpi->vaq_refresh) { set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize); x->mb_energy = vp10_block_energy(cpi, x, bsize); } @@ -3440,7 +3431,7 @@ static void rd_pick_partition(VP10_COMP *cpi, ThreadData *td, set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize); - if (bsize == BLOCK_16X16 && cpi->oxcf.aq_mode) + if (bsize == BLOCK_16X16 && cpi->vaq_refresh) x->mb_energy = vp10_block_energy(cpi, x, bsize); if (cpi->sf.cb_partition_search && bsize == BLOCK_16X16) { diff --git a/vp10/encoder/encoder.c b/vp10/encoder/encoder.c index b043ec118..fa44e3c53 100644 --- a/vp10/encoder/encoder.c +++ b/vp10/encoder/encoder.c @@ -296,6 +296,8 @@ static void setup_frame(VP10_COMP *cpi) { vp10_zero(cpi->interp_filter_selected[0]); } + cpi->vaq_refresh = 0; + set_sb_size(cm, select_sb_size(cpi)); } diff --git a/vp10/encoder/encoder.h b/vp10/encoder/encoder.h index 037866d75..fc699e603 100644 --- a/vp10/encoder/encoder.h +++ b/vp10/encoder/encoder.h @@ -598,6 +598,9 @@ typedef struct VP10_COMP { int64_t vbp_threshold_sad; BLOCK_SIZE vbp_bsize_min; + // VARIANCE_AQ segment map refresh + int vaq_refresh; + // Multi-threading int num_workers; VPxWorker *workers; -- 2.50.0