ref: 1fa82a911731e47bf9679950c2dd588d46dd0683
parent: e5f2e06a20a9c9040ca1ae080ade70d88c93e3f6
author: Jingning Han <jingning@google.com>
date: Tue Apr 30 06:54:17 EDT 2019
Refactor perceptual aq control Move the activation control to vpxenc interface using aq-mode. Change-Id: Iae406d4f7e74bdc7bfd3b149f0811093454f879e
--- a/vp9/encoder/vp9_encodeframe.c
+++ b/vp9/encoder/vp9_encodeframe.c
@@ -231,6 +231,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
}
// 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;
--- a/vp9/encoder/vp9_encoder.c
+++ b/vp9/encoder/vp9_encoder.c
@@ -2387,13 +2387,12 @@
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 @@
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 @@
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();
--- a/vp9/encoder/vp9_firstpass.c
+++ b/vp9/encoder/vp9_firstpass.c
@@ -3379,7 +3379,8 @@
// 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;
--- a/vp9/encoder/vp9_speed_features.c
+++ b/vp9/encoder/vp9_speed_features.c
@@ -955,10 +955,6 @@
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;
--- a/vp9/encoder/vp9_speed_features.h
+++ b/vp9/encoder/vp9_speed_features.h
@@ -288,9 +288,6 @@
// 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;