Eliminate unneeded wavelet_energy calculation
While removing unused functions related to CNN gop structure, some
calculations were introduced by
https://aomedia-review.googlesource.com/c/aom/+/140623, which caused
encoder speed regression. This CL removed that code, and recovered
the speed loss. No bitstream change. Borg test result:
avg_psnr: ovr_psnr: ssim: speed:
speed 3:
lowres2: 0.000 0.000 0.000 0.221
midres2: 0.000 0.000 0.000 0.441
hdres2: 0.000 0.000 0.000 0.791
speed 6:
lowres2: 0.000 0.000 0.000 0.857
midres2: 0.000 0.000 0.000 1.469
hdres2: 0.000 0.000 0.000 2.570
Change-Id: Ia4aa5cc019c3ffcd780025e2378df1f761828d35
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index d6a316b..fdb0fa2 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -3075,39 +3075,6 @@
return err;
}
-#if !CONFIG_REALTIME_ONLY
-static void calculate_frame_avg_haar_energy(AV1_COMP *cpi) {
- TWO_PASS *const twopass = &cpi->ppi->twopass;
- const FIRSTPASS_STATS *const total_stats =
- twopass->stats_buf_ctx->total_stats;
-
- if (is_one_pass_rt_params(cpi) ||
- (cpi->oxcf.q_cfg.deltaq_mode != DELTA_Q_PERCEPTUAL) ||
- (is_fp_wavelet_energy_invalid(total_stats) == 0))
- return;
-
- const YV12_BUFFER_CONFIG *const unfiltered_source = cpi->unfiltered_source;
- const uint8_t *const src = unfiltered_source->y_buffer;
- const int hbd = unfiltered_source->flags & YV12_FLAG_HIGHBITDEPTH;
- const int stride = unfiltered_source->y_stride;
- const BLOCK_SIZE fp_block_size =
- get_fp_block_size(cpi->is_screen_content_type);
- const int fp_block_size_width = block_size_wide[fp_block_size];
- const int fp_block_size_height = block_size_high[fp_block_size];
- const int num_unit_cols =
- get_num_blocks(unfiltered_source->y_crop_width, fp_block_size_width);
- const int num_unit_rows =
- get_num_blocks(unfiltered_source->y_crop_height, fp_block_size_height);
- const int num_8x8_cols = num_unit_cols * (fp_block_size_width / 8);
- const int num_8x8_rows = num_unit_rows * (fp_block_size_height / 8);
- int64_t frame_avg_wavelet_energy = av1_haar_ac_sad_mxn_uint8_input(
- src, stride, hbd, num_8x8_rows, num_8x8_cols);
-
- twopass->frame_avg_haar_energy =
- log(((double)frame_avg_wavelet_energy) + 1.0);
-}
-#endif
-
// Process the wiener variance in 16x16 block basis.
static int qsort_comp(const void *elem1, const void *elem2) {
int a = *((const int *)elem1);
@@ -3384,10 +3351,6 @@
av1_set_screen_content_options(cpi, features);
}
-#if !CONFIG_REALTIME_ONLY
- calculate_frame_avg_haar_energy(cpi);
-#endif
-
// frame type has been decided outside of this function call
cm->cur_frame->frame_type = current_frame->frame_type;
diff --git a/av1/encoder/firstpass.c b/av1/encoder/firstpass.c
index 414671c..c2e3903 100644
--- a/av1/encoder/firstpass.c
+++ b/av1/encoder/firstpass.c
@@ -359,9 +359,6 @@
return raw_err_stdev;
}
-static AOM_INLINE int calc_wavelet_energy(const AV1EncoderConfig *oxcf) {
- return oxcf->q_cfg.deltaq_mode == DELTA_Q_PERCEPTUAL;
-}
typedef struct intra_pred_block_pass1_args {
const SequenceHeader *seq_params;
MACROBLOCK *x;
@@ -557,24 +554,6 @@
// Accumulate the intra error.
stats->intra_error += (int64_t)this_intra_error;
- // Stats based on wavelet energy is used in the following cases :
- // 1. ML model which predicts if a flat structure (golden-frame only structure
- // without ALT-REF and Internal-ARFs) is better. This ML model is enabled in
- // constant quality mode under certain conditions.
- // 2. Delta qindex mode is set as DELTA_Q_PERCEPTUAL.
- // Thus, wavelet energy calculation is enabled for the above cases.
- if (calc_wavelet_energy(&cpi->oxcf)) {
- const int hbd = is_cur_buf_hbd(xd);
- const int stride = x->plane[0].src.stride;
- const int num_8x8_rows = block_size_high[fp_block_size] / 8;
- const int num_8x8_cols = block_size_wide[fp_block_size] / 8;
- const uint8_t *buf = x->plane[0].src.buf;
- stats->frame_avg_wavelet_energy += av1_haar_ac_sad_mxn_uint8_input(
- buf, stride, hbd, num_8x8_rows, num_8x8_cols);
- } else {
- stats->frame_avg_wavelet_energy = INVALID_FP_STATS_TO_PREDICT_FLAT_GOP;
- }
-
return this_intra_error;
}
@@ -693,6 +672,8 @@
const int unit_width = mi_size_wide[fp_block_size];
const int unit_rows = get_unit_rows(fp_block_size, mi_params->mb_rows);
const int unit_cols = get_unit_cols(fp_block_size, mi_params->mb_cols);
+ (void)alt_ref_frame;
+ (void)alt_ref_frame_yoffset;
// Assume 0,0 motion with no mv overhead.
FULLPEL_MV mv = kZeroFullMv;
xd->plane[0].pre[0].buf = last_frame->y_buffer + recon_yoffset;
@@ -764,32 +745,9 @@
stats->sr_coded_error += motion_error;
}
- // Motion search in 3rd reference frame.
- int alt_motion_error = motion_error;
- if (alt_ref_frame != NULL) {
- FULLPEL_MV tmp_mv = kZeroFullMv;
- xd->plane[0].pre[0].buf = alt_ref_frame->y_buffer + alt_ref_frame_yoffset;
- xd->plane[0].pre[0].stride = alt_ref_frame->y_stride;
- alt_motion_error =
- get_prediction_error_bitdepth(is_high_bitdepth, bitdepth, bsize,
- &x->plane[0].src, &xd->plane[0].pre[0]);
- first_pass_motion_search(cpi, x, &kZeroMv, &tmp_mv, &alt_motion_error);
- }
- if (alt_motion_error < motion_error && alt_motion_error < gf_motion_error &&
- alt_motion_error < this_intra_error) {
- ++stats->third_ref_count;
- }
- // In accumulating a score for the 3rd reference frame take the
- // best of the motion predicted score and the intra coded error
- // (just as will be done for) accumulation of "coded_error" for
- // the last frame.
- if (alt_ref_frame != NULL) {
- stats->tr_coded_error += AOMMIN(alt_motion_error, this_intra_error);
- } else {
- // TODO(chengchen): I believe logically this should also be changed to
- // stats->tr_coded_error += AOMMIN(alt_motion_error, this_intra_error).
- stats->tr_coded_error += motion_error;
- }
+ // TODO(chengchen): I believe logically this should also be changed to
+ // stats->tr_coded_error += AOMMIN(alt_motion_error, this_intra_error).
+ stats->tr_coded_error += motion_error;
// Reset to last frame as reference buffer.
xd->plane[0].pre[0].buf = last_frame->y_buffer + recon_yoffset;
diff --git a/av1/encoder/firstpass.h b/av1/encoder/firstpass.h
index 860bf3b..d66671e 100644
--- a/av1/encoder/firstpass.h
+++ b/av1/encoder/firstpass.h
@@ -366,11 +366,6 @@
struct AV1EncoderConfig;
struct TileDataEnc;
-static INLINE int is_fp_wavelet_energy_invalid(
- const FIRSTPASS_STATS *fp_stats) {
- return (fp_stats->frame_avg_wavelet_energy < 0);
-}
-
static INLINE BLOCK_SIZE get_fp_block_size(int is_screen_content_type) {
return (is_screen_content_type ? BLOCK_8X8 : BLOCK_16X16);
}
diff --git a/av1/encoder/pass2_strategy.c b/av1/encoder/pass2_strategy.c
index e35f25a..fd9ae00 100644
--- a/av1/encoder/pass2_strategy.c
+++ b/av1/encoder/pass2_strategy.c
@@ -3355,13 +3355,6 @@
// applied when combining MB error values for the frame.
twopass->mb_av_energy = log((this_frame_ptr->intra_error) + 1.0);
- const FIRSTPASS_STATS *const total_stats =
- twopass->stats_buf_ctx->total_stats;
- if (is_fp_wavelet_energy_invalid(total_stats) == 0) {
- twopass->frame_avg_haar_energy =
- log((this_frame_ptr->frame_avg_wavelet_energy) + 1.0);
- }
-
// Set the frame content type flag.
if (this_frame_ptr->intra_skip_pct >= FC_ANIMATION_THRESH)
twopass->fr_content_type = FC_GRAPHICS_ANIMATION;