Optimize allocation of altref,util frame buffers
altref and util buffers are not used in the stats generation stage
(firstpass/LAP), however, those buffers are allocated memory.
Removed unneeded memory allocations to those buffers.
Observed memory footprint reduction in singlepass AOM_Q.
Resolution Memory
Single
Thread
1920x1080 ~3.2%
Memory measuring command:
$ command time -v ./aomenc ...
Change-Id: Ia803f677fa2ce35ec567f1719e863cba758a3af6
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 63a1c4c..260bb1c 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -4221,6 +4221,9 @@
av1_superres_scaled(cm))
? y_stride
: cpi->lookahead->buf->img.y_stride;
+ int fpf_y_stride = cm->cur_frame != NULL ? cm->cur_frame->buf.y_stride
+ : cpi->scaled_source.y_stride;
+
// Update if ss_cfg is uninitialized or the current frame has a new stride
const int should_update = !cpi->ss_cfg[SS_CFG_SRC].stride ||
!cpi->ss_cfg[SS_CFG_LOOKAHEAD].stride ||
@@ -4238,7 +4241,7 @@
av1_init3smotion_compensation(&cpi->ss_cfg[SS_CFG_SRC], y_stride);
av1_init3smotion_compensation(&cpi->ss_cfg[SS_CFG_LOOKAHEAD], y_stride_src);
}
- av1_init_motion_fpf(&cpi->ss_cfg[SS_CFG_FPF], y_stride);
+ av1_init_motion_fpf(&cpi->ss_cfg[SS_CFG_FPF], fpf_y_stride);
}
#define COUPLED_CHROMA_FROM_LUMA_RESTORATION 0
@@ -4290,9 +4293,11 @@
av1_set_speed_features_framesize_independent(cpi, cpi->oxcf.speed);
av1_set_speed_features_framesize_dependent(cpi, cpi->oxcf.speed);
- alloc_altref_frame_buffer(cpi);
+ if (!is_stat_generation_stage(cpi)) {
+ alloc_altref_frame_buffer(cpi);
+ alloc_util_frame_buffers(cpi);
+ }
init_ref_frame_bufs(cpi);
- alloc_util_frame_buffers(cpi);
init_motion_estimation(cpi); // TODO(agrange) This can be removed.
@@ -4381,7 +4386,7 @@
cm->rst_info[i].frame_restoration_type = RESTORE_NONE;
av1_alloc_restoration_buffers(cm);
- alloc_util_frame_buffers(cpi);
+ if (!is_stat_generation_stage(cpi)) alloc_util_frame_buffers(cpi);
init_motion_estimation(cpi);
for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {