Group tuning related config in AV1EncoderConfig
This CL groups the configuration parameters related to tune in
AV1EncoderConfig into a new struct TuneCfg, and adds relevant
documentation.
BUG=aomedia:2701
Change-Id: I63b40f2f890312a25d9079e81fb360b104204d3d
diff --git a/av1/av1_cx_iface.c b/av1/av1_cx_iface.c
index 2a79aa4..4abc7b9 100644
--- a/av1/av1_cx_iface.c
+++ b/av1/av1_cx_iface.c
@@ -700,6 +700,8 @@
update_default_encoder_config(&cfg->encoder_cfg, extra_cfg);
}
+ TuneCfg *const tune_cfg = &oxcf->tune_cfg;
+
FrameDimensionCfg *const frm_dim_cfg = &oxcf->frm_dim_cfg;
TileConfig *const tile_cfg = &oxcf->tile_cfg;
@@ -943,15 +945,16 @@
gf_cfg->gf_min_pyr_height = extra_cfg->gf_min_pyr_height;
gf_cfg->gf_max_pyr_height = extra_cfg->gf_max_pyr_height;
- oxcf->tuning = extra_cfg->tuning;
- oxcf->vmaf_model_path = extra_cfg->vmaf_model_path;
- oxcf->content = extra_cfg->content;
+ // Set tune related configuration.
+ tune_cfg->tuning = extra_cfg->tuning;
+ tune_cfg->vmaf_model_path = extra_cfg->vmaf_model_path;
+ tune_cfg->content = extra_cfg->content;
if (cfg->large_scale_tile) {
- oxcf->film_grain_test_vector = 0;
- oxcf->film_grain_table_filename = NULL;
+ tune_cfg->film_grain_test_vector = 0;
+ tune_cfg->film_grain_table_filename = NULL;
} else {
- oxcf->film_grain_test_vector = extra_cfg->film_grain_test_vector;
- oxcf->film_grain_table_filename = extra_cfg->film_grain_table_filename;
+ tune_cfg->film_grain_test_vector = extra_cfg->film_grain_test_vector;
+ tune_cfg->film_grain_table_filename = extra_cfg->film_grain_table_filename;
}
#if CONFIG_DENOISE
oxcf->noise_level = extra_cfg->noise_level;
diff --git a/av1/encoder/aq_cyclicrefresh.c b/av1/encoder/aq_cyclicrefresh.c
index 667532d..e982fa9 100644
--- a/av1/encoder/aq_cyclicrefresh.c
+++ b/av1/encoder/aq_cyclicrefresh.c
@@ -291,8 +291,8 @@
int mi_col = sb_col_index * cm->seq_params.mib_size;
// TODO(any): Ensure the population of
// cpi->common.features.allow_screen_content_tools and use the same instead
- // of cpi->oxcf.content == AOM_CONTENT_SCREEN
- int qindex_thresh = cpi->oxcf.content == AOM_CONTENT_SCREEN
+ // of cpi->oxcf.tune_cfg.content == AOM_CONTENT_SCREEN
+ int qindex_thresh = cpi->oxcf.tune_cfg.content == AOM_CONTENT_SCREEN
? av1_get_qindex(&cm->seg, CR_SEGMENT_ID_BOOST2,
cm->quant_params.base_qindex)
: 0;
diff --git a/av1/encoder/av1_noise_estimate.c b/av1/encoder/av1_noise_estimate.c
index edf1358..1da03d7 100644
--- a/av1/encoder/av1_noise_estimate.c
+++ b/av1/encoder/av1_noise_estimate.c
@@ -73,7 +73,7 @@
if (cpi->oxcf.pass == 0 && cpi->oxcf.rc_cfg.mode == AOM_CBR &&
cpi->oxcf.q_cfg.aq_mode == CYCLIC_REFRESH_AQ && cpi->oxcf.speed >= 5 &&
resize_pending == 0 && !cpi->use_svc &&
- cpi->oxcf.content != AOM_CONTENT_SCREEN &&
+ cpi->oxcf.tune_cfg.content != AOM_CONTENT_SCREEN &&
cpi->common.width * cpi->common.height >= 640 * 360)
return 1;
else
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index d04ec3d..1cc3369 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -234,12 +234,12 @@
av1_get_hier_tpl_rdmult(cpi, x, bsize, mi_row, mi_col, x->rdmult);
}
- if (cpi->oxcf.tuning == AOM_TUNE_SSIM) {
+ if (cpi->oxcf.tune_cfg.tuning == AOM_TUNE_SSIM) {
av1_set_ssim_rdmult(cpi, &x->mv_costs, bsize, mi_row, mi_col, &x->rdmult);
}
#if CONFIG_TUNE_VMAF
- if (cpi->oxcf.tuning == AOM_TUNE_VMAF_WITHOUT_PREPROCESSING ||
- cpi->oxcf.tuning == AOM_TUNE_VMAF_MAX_GAIN) {
+ if (cpi->oxcf.tune_cfg.tuning == AOM_TUNE_VMAF_WITHOUT_PREPROCESSING ||
+ cpi->oxcf.tune_cfg.tuning == AOM_TUNE_VMAF_MAX_GAIN) {
av1_set_vmaf_rdmult(cpi, x, bsize, mi_row, mi_col, &x->rdmult);
}
#endif
diff --git a/av1/encoder/encodeframe_utils.c b/av1/encoder/encodeframe_utils.c
index f8c7ef9..8572304 100644
--- a/av1/encoder/encodeframe_utils.c
+++ b/av1/encoder/encodeframe_utils.c
@@ -42,7 +42,7 @@
double num_of_mi = 0.0;
double geom_mean_of_scale = 0.0;
- assert(cpi->oxcf.tuning == AOM_TUNE_SSIM);
+ assert(cpi->oxcf.tune_cfg.tuning == AOM_TUNE_SSIM);
aom_clear_system_state();
for (row = mi_row / num_mi_w;
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 3d09cc1..ec0ba09 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -1621,7 +1621,7 @@
return;
}
- if (cpi->oxcf.content == AOM_CONTENT_SCREEN) {
+ if (cpi->oxcf.tune_cfg.content == AOM_CONTENT_SCREEN) {
features->allow_screen_content_tools = features->allow_intrabc = 1;
return;
}
@@ -2264,9 +2264,9 @@
av1_scale_references(cpi, EIGHTTAP_REGULAR, 0, 0);
}
#if CONFIG_TUNE_VMAF
- if (oxcf->tuning == AOM_TUNE_VMAF_WITH_PREPROCESSING ||
- oxcf->tuning == AOM_TUNE_VMAF_WITHOUT_PREPROCESSING ||
- oxcf->tuning == AOM_TUNE_VMAF_MAX_GAIN) {
+ if (oxcf->tune_cfg.tuning == AOM_TUNE_VMAF_WITH_PREPROCESSING ||
+ oxcf->tune_cfg.tuning == AOM_TUNE_VMAF_WITHOUT_PREPROCESSING ||
+ oxcf->tune_cfg.tuning == AOM_TUNE_VMAF_MAX_GAIN) {
av1_set_quantizer(cm, q_cfg->qm_minlevel, q_cfg->qm_maxlevel,
av1_get_vmaf_base_qindex(cpi, q),
q_cfg->enable_chroma_deltaq);
@@ -2837,11 +2837,12 @@
}
}
- if (oxcf->tuning == AOM_TUNE_SSIM) av1_set_mb_ssim_rdmult_scaling(cpi);
+ if (oxcf->tune_cfg.tuning == AOM_TUNE_SSIM)
+ av1_set_mb_ssim_rdmult_scaling(cpi);
#if CONFIG_TUNE_VMAF
- if (oxcf->tuning == AOM_TUNE_VMAF_WITHOUT_PREPROCESSING ||
- oxcf->tuning == AOM_TUNE_VMAF_MAX_GAIN) {
+ if (oxcf->tune_cfg.tuning == AOM_TUNE_VMAF_WITHOUT_PREPROCESSING ||
+ oxcf->tune_cfg.tuning == AOM_TUNE_VMAF_MAX_GAIN) {
av1_set_mb_vmaf_rdmult_scaling(cpi);
}
#endif
@@ -3127,11 +3128,11 @@
#if CONFIG_TUNE_VMAF
if (!is_stat_generation_stage(cpi) &&
- cpi->oxcf.tuning == AOM_TUNE_VMAF_WITH_PREPROCESSING) {
+ cpi->oxcf.tune_cfg.tuning == AOM_TUNE_VMAF_WITH_PREPROCESSING) {
av1_vmaf_frame_preprocessing(cpi, sd);
}
if (!is_stat_generation_stage(cpi) &&
- cpi->oxcf.tuning == AOM_TUNE_VMAF_MAX_GAIN) {
+ cpi->oxcf.tune_cfg.tuning == AOM_TUNE_VMAF_MAX_GAIN) {
av1_vmaf_blk_preprocessing(cpi, sd);
}
#endif
@@ -3343,9 +3344,9 @@
#if CONFIG_TUNE_VMAF
if (!is_stat_generation_stage(cpi) &&
- (oxcf->tuning == AOM_TUNE_VMAF_WITH_PREPROCESSING ||
- oxcf->tuning == AOM_TUNE_VMAF_WITHOUT_PREPROCESSING ||
- oxcf->tuning == AOM_TUNE_VMAF_MAX_GAIN)) {
+ (oxcf->tune_cfg.tuning == AOM_TUNE_VMAF_WITH_PREPROCESSING ||
+ oxcf->tune_cfg.tuning == AOM_TUNE_VMAF_WITHOUT_PREPROCESSING ||
+ oxcf->tune_cfg.tuning == AOM_TUNE_VMAF_MAX_GAIN)) {
av1_update_vmaf_curve(cpi, cpi->source, &cpi->common.cur_frame->buf);
}
#endif
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h
index 75732a6..334e4a7 100644
--- a/av1/encoder/encoder.h
+++ b/av1/encoder/encoder.h
@@ -573,6 +573,19 @@
} UnitTestCfg;
typedef struct {
+ // Indicates the file path to the VMAF model.
+ const char *vmaf_model_path;
+ // Indicates the path to the film grain parameters.
+ const char *film_grain_table_filename;
+ // Indicates the visual tuning metric.
+ aom_tune_metric tuning;
+ // Indicates if the current content is screen or default type.
+ aom_tune_content content;
+ // Indicates the film grain parameters.
+ int film_grain_test_vector;
+} TuneCfg;
+
+typedef struct {
// Indicates the framerate of the input video.
double init_framerate;
// Indicates the bit-depth of the input video.
@@ -753,13 +766,11 @@
int max_threads;
- aom_tune_metric tuning;
- const char *vmaf_model_path;
- aom_tune_content content;
int use_highbitdepth;
aom_chroma_sample_position_t chroma_sample_position;
- int film_grain_test_vector;
- const char *film_grain_table_filename;
+
+ // Configuration related to Tune.
+ TuneCfg tune_cfg;
// Configuration related to color.
ColorCfg color_cfg;
diff --git a/av1/encoder/encoder_utils.c b/av1/encoder/encoder_utils.c
index 1cb09ee..8f3b1cf 100644
--- a/av1/encoder/encoder_utils.c
+++ b/av1/encoder/encoder_utils.c
@@ -594,6 +594,7 @@
const AV1EncoderConfig *oxcf) {
AV1_COMMON *const cm = &cpi->common;
cpi->oxcf = *oxcf;
+ const TuneCfg *const tune_cfg = &oxcf->tune_cfg;
if (cpi->film_grain_table) {
aom_film_grain_table_free(cpi->film_grain_table);
@@ -601,11 +602,11 @@
cpi->film_grain_table = NULL;
}
- if (oxcf->film_grain_test_vector) {
+ if (tune_cfg->film_grain_test_vector) {
cm->seq_params.film_grain_params_present = 1;
if (cm->current_frame.frame_type == KEY_FRAME) {
memcpy(&cm->film_grain_params,
- film_grain_test_vectors + oxcf->film_grain_test_vector - 1,
+ film_grain_test_vectors + tune_cfg->film_grain_test_vector - 1,
sizeof(cm->film_grain_params));
if (oxcf->tool_cfg.enable_monochrome)
reset_film_grain_chroma_params(&cm->film_grain_params);
@@ -614,14 +615,14 @@
cm->film_grain_params.clip_to_restricted_range = 0;
}
}
- } else if (oxcf->film_grain_table_filename) {
+ } else if (tune_cfg->film_grain_table_filename) {
cm->seq_params.film_grain_params_present = 1;
cpi->film_grain_table = aom_malloc(sizeof(*cpi->film_grain_table));
memset(cpi->film_grain_table, 0, sizeof(aom_film_grain_table_t));
aom_film_grain_table_read(cpi->film_grain_table,
- oxcf->film_grain_table_filename, &cm->error);
+ tune_cfg->film_grain_table_filename, &cm->error);
} else {
#if CONFIG_DENOISE
cm->seq_params.film_grain_params_present = (cpi->oxcf.noise_level > 0);
@@ -967,9 +968,9 @@
for (int pass = 0; pass < 2; ++pass) {
set_encoding_params_for_screen_content(cpi, pass);
#if CONFIG_TUNE_VMAF
- if (oxcf->tuning == AOM_TUNE_VMAF_WITH_PREPROCESSING ||
- oxcf->tuning == AOM_TUNE_VMAF_WITHOUT_PREPROCESSING ||
- oxcf->tuning == AOM_TUNE_VMAF_MAX_GAIN) {
+ if (oxcf->tune_cfg.tuning == AOM_TUNE_VMAF_WITH_PREPROCESSING ||
+ oxcf->tune_cfg.tuning == AOM_TUNE_VMAF_WITHOUT_PREPROCESSING ||
+ oxcf->tune_cfg.tuning == AOM_TUNE_VMAF_MAX_GAIN) {
av1_set_quantizer(
cm, q_cfg->qm_minlevel, q_cfg->qm_maxlevel,
av1_get_vmaf_base_qindex(cpi, q_for_screen_content_quick_run),
diff --git a/av1/encoder/ratectrl.c b/av1/encoder/ratectrl.c
index bb656e3..bfe0f19 100644
--- a/av1/encoder/ratectrl.c
+++ b/av1/encoder/ratectrl.c
@@ -2169,7 +2169,7 @@
const int num_mi_rows = cm->mi_params.mi_rows;
int num_zero_temp_sad = 0;
uint32_t min_thresh = 10000;
- if (cpi->oxcf.content != AOM_CONTENT_SCREEN) min_thresh = 100000;
+ if (cpi->oxcf.tune_cfg.content != AOM_CONTENT_SCREEN) min_thresh = 100000;
const BLOCK_SIZE bsize = BLOCK_64X64;
int full_sampling = (cm->width * cm->height < 640 * 360) ? 1 : 0;
// Loop over sub-sample of frame, compute average sad over 64x64 blocks.
@@ -2386,7 +2386,7 @@
int thresh_qp = 7 * (rc->worst_quality >> 3);
// Lower thresh_qp for video (more overshoot at lower Q) to be
// more conservative for video.
- if (cpi->oxcf.content != AOM_CONTENT_SCREEN)
+ if (cpi->oxcf.tune_cfg.content != AOM_CONTENT_SCREEN)
thresh_qp = 3 * (rc->worst_quality >> 2);
if (sf->rt_sf.overshoot_detection_cbr == FAST_DETECTION_MAXQ &&
cm->quant_params.base_qindex < thresh_qp) {
diff --git a/av1/encoder/tune_vmaf.c b/av1/encoder/tune_vmaf.c
index 6044e5a..3481a90 100644
--- a/av1/encoder/tune_vmaf.c
+++ b/av1/encoder/tune_vmaf.c
@@ -160,8 +160,8 @@
YV12_BUFFER_CONFIG *const sharpened) {
const int bit_depth = cpi->td.mb.e_mbd.bd;
double new_vmaf;
- aom_calc_vmaf(cpi->oxcf.vmaf_model_path, source, sharpened, bit_depth,
- &new_vmaf);
+ aom_calc_vmaf(cpi->oxcf.tune_cfg.vmaf_model_path, source, sharpened,
+ bit_depth, &new_vmaf);
const double sharpened_var = frame_average_variance(cpi, sharpened);
return source_variance / sharpened_var * (new_vmaf - kBaselineVmaf);
}
@@ -555,7 +555,7 @@
frame_data.row = 0;
frame_data.col = 0;
frame_data.bit_depth = bit_depth;
- aom_calc_vmaf_multi_frame(&frame_data, cpi->oxcf.vmaf_model_path,
+ aom_calc_vmaf_multi_frame(&frame_data, cpi->oxcf.tune_cfg.vmaf_model_path,
update_frame, resized_y_width, resized_y_height,
bit_depth, scores);
@@ -796,7 +796,7 @@
void av1_update_vmaf_curve(AV1_COMP *cpi, YV12_BUFFER_CONFIG *source,
YV12_BUFFER_CONFIG *recon) {
const int bit_depth = cpi->td.mb.e_mbd.bd;
- aom_calc_vmaf(cpi->oxcf.vmaf_model_path, source, recon, bit_depth,
+ aom_calc_vmaf(cpi->oxcf.tune_cfg.vmaf_model_path, source, recon, bit_depth,
&cpi->vmaf_info.last_frame_vmaf);
if (cpi->common.seq_params.use_highbitdepth) {
assert(source->flags & YV12_FLAG_HIGHBITDEPTH);