From 1fa82a911731e47bf9679950c2dd588d46dd0683 Mon Sep 17 00:00:00 2001 From: Jingning Han Date: Tue, 30 Apr 2019 10:54:17 -0700 Subject: [PATCH] Refactor perceptual aq control Move the activation control to vpxenc interface using aq-mode. Change-Id: Iae406d4f7e74bdc7bfd3b149f0811093454f879e --- vp9/encoder/vp9_encodeframe.c | 22 ++++++++-------------- vp9/encoder/vp9_encoder.c | 17 +++++++---------- vp9/encoder/vp9_firstpass.c | 3 ++- vp9/encoder/vp9_speed_features.c | 4 ---- vp9/encoder/vp9_speed_features.h | 3 --- 5 files changed, 17 insertions(+), 32 deletions(-) diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c index 9f9abd20f..28a900514 100644 --- a/vp9/encoder/vp9_encodeframe.c +++ b/vp9/encoder/vp9_encodeframe.c @@ -231,6 +231,7 @@ static void set_segment_index(VP9_COMP *cpi, MACROBLOCK *const x, int mi_row, mi->segment_id = get_segment_id(cm, map, bsize, mi_row, mi_col); break; case PSNR_AQ: mi->segment_id = segment_index; break; + case PERCEPTUAL_AQ: mi->segment_id = x->segment_id; break; default: // NO_AQ or PSNR_AQ break; @@ -240,8 +241,6 @@ static void set_segment_index(VP9_COMP *cpi, MACROBLOCK *const x, int mi_row, if (cpi->roi.enabled) mi->segment_id = get_segment_id(cm, map, bsize, mi_row, mi_col); - if (cpi->sf.enable_wiener_variance) mi->segment_id = x->segment_id; - vp9_init_plane_quantizers(cpi, x); } @@ -1944,8 +1943,9 @@ static void set_segment_rdmult(VP9_COMP *const cpi, MACROBLOCK *const x, vpx_clear_system_state(); if (aq_mode == NO_AQ || aq_mode == PSNR_AQ) { - if (cpi->sf.enable_tpl_model || cpi->sf.enable_wiener_variance) - x->rdmult = x->cb_rdmult; + if (cpi->sf.enable_tpl_model) x->rdmult = x->cb_rdmult; + } else if (aq_mode == PERCEPTUAL_AQ) { + x->rdmult = x->cb_rdmult; } else if (aq_mode == CYCLIC_REFRESH_AQ) { // If segment is boosted, use rdmult for that segment. if (cyclic_refresh_segment_id_boosted( @@ -1953,12 +1953,6 @@ static void set_segment_rdmult(VP9_COMP *const cpi, MACROBLOCK *const x, x->rdmult = vp9_cyclic_refresh_get_rdmult(cpi->cyclic_refresh); } else { x->rdmult = vp9_compute_rd_mult(cpi, cm->base_qindex + cm->y_dc_delta_q); - if (cpi->sf.enable_wiener_variance && cm->show_frame) { - if (cm->seg.enabled) - x->rdmult = vp9_compute_rd_mult( - cpi, vp9_get_qindex(&cm->seg, x->e_mbd.mi[0]->segment_id, - cm->base_qindex)); - } } if (oxcf->tuning == VP8_TUNE_SSIM) { @@ -2200,8 +2194,8 @@ static void encode_b(VP9_COMP *cpi, const TileInfo *const tile, ThreadData *td, MACROBLOCK *const x = &td->mb; set_offsets(cpi, tile, x, mi_row, mi_col, bsize); - if ((cpi->sf.enable_tpl_model || cpi->sf.enable_wiener_variance) && - cpi->oxcf.aq_mode == NO_AQ) { + if (cpi->sf.enable_tpl_model && + (cpi->oxcf.aq_mode == NO_AQ || cpi->oxcf.aq_mode == PERCEPTUAL_AQ)) { const VP9EncoderConfig *const oxcf = &cpi->oxcf; x->rdmult = x->cb_rdmult; if (oxcf->tuning == VP8_TUNE_SSIM) { @@ -4423,7 +4417,7 @@ static void encode_rd_sb_row(VP9_COMP *cpi, ThreadData *td, x->cb_rdmult = dr; } - if (cpi->sf.enable_wiener_variance && cm->show_frame) { + if (cpi->oxcf.aq_mode == PERCEPTUAL_AQ && cm->show_frame) { x->segment_id = wiener_var_segment(cpi, BLOCK_64X64, mi_row, mi_col); x->cb_rdmult = vp9_compute_rd_mult( cpi, vp9_get_qindex(&cm->seg, x->segment_id, cm->base_qindex)); @@ -5987,7 +5981,7 @@ static void encode_frame_internal(VP9_COMP *cpi) { } // Frame segmentation - if (cpi->sf.enable_wiener_variance) build_kmeans_segmentation(cpi); + if (cpi->oxcf.aq_mode == PERCEPTUAL_AQ) build_kmeans_segmentation(cpi); { struct vpx_usec_timer emr_timer; diff --git a/vp9/encoder/vp9_encoder.c b/vp9/encoder/vp9_encoder.c index 55cfd13c6..2e58edc67 100644 --- a/vp9/encoder/vp9_encoder.c +++ b/vp9/encoder/vp9_encoder.c @@ -2387,13 +2387,12 @@ VP9_COMP *vp9_create_compressor(VP9EncoderConfig *oxcf, vp9_set_speed_features_framesize_independent(cpi, oxcf->speed); vp9_set_speed_features_framesize_dependent(cpi, oxcf->speed); - if (cpi->sf.enable_wiener_variance) { - CHECK_MEM_ERROR(cm, cpi->stack_rank_buffer, - vpx_calloc(UINT16_MAX, sizeof(*cpi->stack_rank_buffer))); - CHECK_MEM_ERROR(cm, cpi->mb_wiener_variance, - vpx_calloc(cm->mb_rows * cm->mb_cols, - sizeof(*cpi->mb_wiener_variance))); - } + // TODO(jingning): The buffer allocation will be refactored next. + CHECK_MEM_ERROR(cm, cpi->stack_rank_buffer, + vpx_calloc(UINT16_MAX, sizeof(*cpi->stack_rank_buffer))); + CHECK_MEM_ERROR( + cm, cpi->mb_wiener_variance, + vpx_calloc(cm->mb_rows * cm->mb_cols, sizeof(*cpi->mb_wiener_variance))); { const int bsize = BLOCK_64X64; @@ -4867,8 +4866,6 @@ static void set_mb_wiener_variance(VP9_COMP *cpi) { const int coeff_count = block_size * block_size; const TX_SIZE tx_size = TX_16X16; - if (cpi->sf.enable_wiener_variance == 0) return; - #if CONFIG_VP9_HIGHBITDEPTH xd->cur_buf = cpi->Source; if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { @@ -5027,7 +5024,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi, size_t *size, if (oxcf->tuning == VP8_TUNE_SSIM) set_mb_ssim_rdmult_scaling(cpi); - set_mb_wiener_variance(cpi); + if (oxcf->aq_mode == PERCEPTUAL_AQ) set_mb_wiener_variance(cpi); vpx_clear_system_state(); diff --git a/vp9/encoder/vp9_firstpass.c b/vp9/encoder/vp9_firstpass.c index 97c6e8cd7..726724ec5 100644 --- a/vp9/encoder/vp9_firstpass.c +++ b/vp9/encoder/vp9_firstpass.c @@ -3379,7 +3379,8 @@ void vp9_twopass_postencode_update(VP9_COMP *cpi) { // Extend min or Max Q range to account for imbalance from the base // value when using AQ. - if (cpi->oxcf.aq_mode != NO_AQ) { + if (cpi->oxcf.aq_mode != NO_AQ && cpi->oxcf.aq_mode != PSNR_AQ && + cpi->oxcf.aq_mode != PERCEPTUAL_AQ) { if (cm->seg.aq_av_offset < 0) { // The balance of the AQ map tends towarda lowering the average Q. aq_extend_min = 0; diff --git a/vp9/encoder/vp9_speed_features.c b/vp9/encoder/vp9_speed_features.c index b12364f6d..18130dded 100644 --- a/vp9/encoder/vp9_speed_features.c +++ b/vp9/encoder/vp9_speed_features.c @@ -955,10 +955,6 @@ void vp9_set_speed_features_framesize_independent(VP9_COMP *cpi, int speed) { sf->tx_size_search_breakout = 1; sf->tx_size_search_depth = 2; - // Manually turn this on during experimentation. Off by default to disable its - // effect on the baseline encoder. - sf->enable_wiener_variance = 0; - sf->exhaustive_searches_thresh = (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ? (1 << 20) : INT_MAX; diff --git a/vp9/encoder/vp9_speed_features.h b/vp9/encoder/vp9_speed_features.h index 6b04a3ad4..eb0628199 100644 --- a/vp9/encoder/vp9_speed_features.h +++ b/vp9/encoder/vp9_speed_features.h @@ -288,9 +288,6 @@ typedef struct SPEED_FEATURES { // level within a frame. int allow_skip_recode; - // Enable Wiener filter based block complexity analysis. - int enable_wiener_variance; - // Coefficient probability model approximation step size int coeff_prob_appx_step; -- 2.40.0