From 3744267281c69caa7f73ec3ce704b8ceeb1e13aa Mon Sep 17 00:00:00 2001
From: James Zern <[EMAIL REDACTED]>
Date: Mon, 19 Aug 2024 18:40:25 -0700
Subject: [PATCH] aq_variance.c: make some fns static w/CONFIG_REALTIME_ONLY=1
only av1_log_block_var() is needed with this config.
Bug: aomedia:3416
Change-Id: I43eea7767c3eba16a3e4bf40ad2eb0b007250b9d
---
av1/encoder/aq_variance.c | 104 +++++++++++++++++++-------------------
av1/encoder/aq_variance.h | 6 ++-
2 files changed, 58 insertions(+), 52 deletions(-)
diff --git a/av1/encoder/aq_variance.c b/av1/encoder/aq_variance.c
index 66e02c00ee..2dc2cd0c99 100644
--- a/av1/encoder/aq_variance.c
+++ b/av1/encoder/aq_variance.c
@@ -20,7 +20,9 @@
#include "av1/encoder/rd.h"
#include "av1/encoder/segmentation.h"
#include "av1/encoder/dwt.h"
+#include "config/aom_config.h"
+#if !CONFIG_REALTIME_ONLY
static const double rate_ratio[MAX_SEGMENTS] = { 2.2, 1.7, 1.3, 1.0,
0.9, .8, .7, .6 };
@@ -32,11 +34,6 @@ static const double deltaq_rate_ratio[MAX_SEGMENTS] = { 2.5, 2.0, 1.5, 1.0,
#define ENERGY_IN_BOUNDS(energy) \
assert((energy) >= ENERGY_MIN && (energy) <= ENERGY_MAX)
-DECLARE_ALIGNED(16, static const uint8_t, av1_all_zeros[MAX_SB_SIZE]) = { 0 };
-
-DECLARE_ALIGNED(16, static const uint16_t,
- av1_highbd_all_zeros[MAX_SB_SIZE]) = { 0 };
-
static const int segment_id[ENERGY_SPAN] = { 0, 1, 1, 2, 3, 4 };
#define SEGMENT_ID(i) segment_id[(i)-ENERGY_MIN]
@@ -92,52 +89,6 @@ void av1_vaq_frame_setup(AV1_COMP *cpi) {
}
}
-int av1_log_block_var(const AV1_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bs) {
- // This functions returns a score for the blocks local variance as calculated
- // by: sum of the log of the (4x4 variances) of each subblock to the current
- // block (x,bs)
- // * 32 / number of pixels in the block_size.
- // This is used for segmentation because to avoid situations in which a large
- // block with a gentle gradient gets marked high variance even though each
- // subblock has a low variance. This allows us to assign the same segment
- // number for the same sorts of area regardless of how the partitioning goes.
-
- MACROBLOCKD *xd = &x->e_mbd;
- double var = 0;
- unsigned int sse;
- int i, j;
-
- int right_overflow =
- (xd->mb_to_right_edge < 0) ? ((-xd->mb_to_right_edge) >> 3) : 0;
- int bottom_overflow =
- (xd->mb_to_bottom_edge < 0) ? ((-xd->mb_to_bottom_edge) >> 3) : 0;
-
- const int bw = MI_SIZE * mi_size_wide[bs] - right_overflow;
- const int bh = MI_SIZE * mi_size_high[bs] - bottom_overflow;
-
- for (i = 0; i < bh; i += 4) {
- for (j = 0; j < bw; j += 4) {
- if (is_cur_buf_hbd(xd)) {
- var += log1p(cpi->ppi->fn_ptr[BLOCK_4X4].vf(
- x->plane[0].src.buf + i * x->plane[0].src.stride + j,
- x->plane[0].src.stride,
- CONVERT_TO_BYTEPTR(av1_highbd_all_zeros), 0, &sse) /
- 16.0);
- } else {
- var += log1p(cpi->ppi->fn_ptr[BLOCK_4X4].vf(
- x->plane[0].src.buf + i * x->plane[0].src.stride + j,
- x->plane[0].src.stride, av1_all_zeros, 0, &sse) /
- 16.0);
- }
- }
- }
- // Use average of 4x4 log variance. The range for 8 bit 0 - 9.704121561.
- var /= (bw / 4 * bh / 4);
- if (var > 7) var = 7;
-
- return (int)(var);
-}
-
int av1_log_block_avg(const AV1_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bs,
int mi_row, int mi_col) {
// This functions returns the block average of luma block
@@ -218,3 +169,54 @@ int av1_compute_q_from_energy_level_deltaq_mode(const AV1_COMP *const cpi,
}
return base_qindex + qindex_delta;
}
+#endif // !CONFIG_REALTIME_ONLY
+
+int av1_log_block_var(const AV1_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bs) {
+ DECLARE_ALIGNED(16, static const uint16_t,
+ av1_highbd_all_zeros[MAX_SB_SIZE]) = { 0 };
+ DECLARE_ALIGNED(16, static const uint8_t, av1_all_zeros[MAX_SB_SIZE]) = { 0 };
+
+ // This function returns a score for the blocks local variance as calculated
+ // by: sum of the log of the (4x4 variances) of each subblock to the current
+ // block (x,bs)
+ // * 32 / number of pixels in the block_size.
+ // This is used for segmentation because to avoid situations in which a large
+ // block with a gentle gradient gets marked high variance even though each
+ // subblock has a low variance. This allows us to assign the same segment
+ // number for the same sorts of area regardless of how the partitioning goes.
+
+ MACROBLOCKD *xd = &x->e_mbd;
+ double var = 0;
+ unsigned int sse;
+ int i, j;
+
+ int right_overflow =
+ (xd->mb_to_right_edge < 0) ? ((-xd->mb_to_right_edge) >> 3) : 0;
+ int bottom_overflow =
+ (xd->mb_to_bottom_edge < 0) ? ((-xd->mb_to_bottom_edge) >> 3) : 0;
+
+ const int bw = MI_SIZE * mi_size_wide[bs] - right_overflow;
+ const int bh = MI_SIZE * mi_size_high[bs] - bottom_overflow;
+
+ for (i = 0; i < bh; i += 4) {
+ for (j = 0; j < bw; j += 4) {
+ if (is_cur_buf_hbd(xd)) {
+ var += log1p(cpi->ppi->fn_ptr[BLOCK_4X4].vf(
+ x->plane[0].src.buf + i * x->plane[0].src.stride + j,
+ x->plane[0].src.stride,
+ CONVERT_TO_BYTEPTR(av1_highbd_all_zeros), 0, &sse) /
+ 16.0);
+ } else {
+ var += log1p(cpi->ppi->fn_ptr[BLOCK_4X4].vf(
+ x->plane[0].src.buf + i * x->plane[0].src.stride + j,
+ x->plane[0].src.stride, av1_all_zeros, 0, &sse) /
+ 16.0);
+ }
+ }
+ }
+ // Use average of 4x4 log variance. The range for 8 bit 0 - 9.704121561.
+ var /= (bw / 4 * bh / 4);
+ if (var > 7) var = 7;
+
+ return (int)(var);
+}
diff --git a/av1/encoder/aq_variance.h b/av1/encoder/aq_variance.h
index 8d07cd95ba..2e9a73aec6 100644
--- a/av1/encoder/aq_variance.h
+++ b/av1/encoder/aq_variance.h
@@ -13,20 +13,24 @@
#define AOM_AV1_ENCODER_AQ_VARIANCE_H_
#include "av1/encoder/encoder.h"
+#include "config/aom_config.h"
#ifdef __cplusplus
extern "C" {
#endif
+#if !CONFIG_REALTIME_ONLY
void av1_vaq_frame_setup(AV1_COMP *cpi);
-int av1_log_block_var(const AV1_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bs);
int av1_log_block_avg(const AV1_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bs,
int mi_row, int mi_col);
int av1_compute_q_from_energy_level_deltaq_mode(const AV1_COMP *const cpi,
int block_var_level);
int av1_block_wavelet_energy_level(const AV1_COMP *cpi, MACROBLOCK *x,
BLOCK_SIZE bs);
+#endif // !CONFIG_REALTIME_ONLY
+
+int av1_log_block_var(const AV1_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bs);
#ifdef __cplusplus
} // extern "C"