ref: 7a4703e8a90cae5b3c021af949c7e1387aff7309
parent: 37c8030a2a79fc6aa8fab686fd60117d3833d1b2
author: Jingning Han <[email protected]>
date: Tue Apr 30 07:54:07 EDT 2019
Rework the wiener variance buffer Support the potential frame scaling use case. The operation flow now allows the codec to allocate the memory buffer only when perceptual AQ mode is enabled. Change-Id: I7529e63131276dbe3a29f910d3a227f20dbc94a2
--- a/vp9/encoder/vp9_encoder.c
+++ b/vp9/encoder/vp9_encoder.c
@@ -2381,14 +2381,13 @@
}
#endif // !CONFIG_REALTIME_ONLY
+ cpi->mb_wiener_var_cols = 0;
+ cpi->mb_wiener_var_rows = 0;
+ cpi->mb_wiener_variance = NULL;
+
vp9_set_speed_features_framesize_independent(cpi, oxcf->speed);
vp9_set_speed_features_framesize_dependent(cpi, oxcf->speed);
- // TODO(jingning): The buffer allocation will be refactored next.
- 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;
const int w = num_8x8_blocks_wide_lookup[bsize];
@@ -4836,6 +4835,23 @@
return 0;
}
+static void init_mb_wiener_var_buffer(VP9_COMP *cpi) {
+ VP9_COMMON *cm = &cpi->common;
+
+ if (cpi->mb_wiener_variance && cpi->mb_wiener_var_rows >= cm->mb_rows &&
+ cpi->mb_wiener_var_cols >= cm->mb_cols)
+ return;
+
+ vpx_free(cpi->mb_wiener_variance);
+ cpi->mb_wiener_variance = NULL;
+
+ CHECK_MEM_ERROR(
+ cm, cpi->mb_wiener_variance,
+ vpx_calloc(cm->mb_rows * cm->mb_cols, sizeof(*cpi->mb_wiener_variance)));
+ cpi->mb_wiener_var_rows = cm->mb_rows;
+ cpi->mb_wiener_var_cols = cm->mb_cols;
+}
+
static void set_mb_wiener_variance(VP9_COMP *cpi) {
VP9_COMMON *cm = &cpi->common;
uint8_t *buffer = cpi->Source->y_buffer;
@@ -5019,7 +5035,10 @@
if (oxcf->tuning == VP8_TUNE_SSIM) set_mb_ssim_rdmult_scaling(cpi);
- if (oxcf->aq_mode == PERCEPTUAL_AQ) set_mb_wiener_variance(cpi);
+ if (oxcf->aq_mode == PERCEPTUAL_AQ) {
+ init_mb_wiener_var_buffer(cpi);
+ set_mb_wiener_variance(cpi);
+ }
vpx_clear_system_state();
--- a/vp9/encoder/vp9_encoder.h
+++ b/vp9/encoder/vp9_encoder.h
@@ -644,6 +644,8 @@
int64_t norm_wiener_variance;
int64_t *mb_wiener_variance;
+ int mb_wiener_var_rows;
+ int mb_wiener_var_cols;
double *mi_ssim_rdmult_scaling_factors;
YV12_BUFFER_CONFIG last_frame_uf;