Allocate tf_buf_second_arf buffer when required
The buffer 'tf_buf_second_arf' holds the temporal filtered
data of second arf frame and was allocated unconditionally.
In this CL, the buffer is allocated only when required.
Peak memory reduction(%)
Resolution Single thread(good speed 6)
640x360 1.06
854x480 1.02
832x480 1.02
1280x720 1.10
1920x1080 1.09
HEAP memory reduction was measured using the following command.
$valgrind --tool=massif ./aomenc ...
Change-Id: I4d100a3205a307c620d8a9443d9406615af2aab7
diff --git a/av1/encoder/encode_strategy.c b/av1/encoder/encode_strategy.c
index 96ea687..6bce897 100644
--- a/av1/encoder/encode_strategy.c
+++ b/av1/encoder/encode_strategy.c
@@ -793,6 +793,18 @@
}
if (is_second_arf) {
+ // Allocate the memory for tf_buf_second_arf buffer, only when it is
+ // required.
+ int ret = aom_realloc_frame_buffer(
+ &cpi->ppi->tf_info.tf_buf_second_arf, oxcf->frm_dim_cfg.width,
+ oxcf->frm_dim_cfg.height, cm->seq_params->subsampling_x,
+ cm->seq_params->subsampling_y, cm->seq_params->use_highbitdepth,
+ cpi->oxcf.border_in_pixels, cm->features.byte_alignment, NULL, NULL,
+ NULL, cpi->oxcf.tool_cfg.enable_global_motion, 0);
+ if (ret)
+ aom_internal_error(cm->error, AOM_CODEC_MEM_ERROR,
+ "Failed to allocate tf_buf_second_arf");
+
YV12_BUFFER_CONFIG *tf_buf_second_arf =
&cpi->ppi->tf_info.tf_buf_second_arf;
// We didn't apply temporal filtering for second arf ahead in
diff --git a/av1/encoder/temporal_filter.c b/av1/encoder/temporal_filter.c
index 6f8b08c3..62a4d3b 100644
--- a/av1/encoder/temporal_filter.c
+++ b/av1/encoder/temporal_filter.c
@@ -1295,17 +1295,6 @@
"Failed to allocate tf_info");
}
}
-
- ret = aom_realloc_frame_buffer(
- &tf_info->tf_buf_second_arf, oxcf->frm_dim_cfg.width,
- oxcf->frm_dim_cfg.height, seq_params->subsampling_x,
- seq_params->subsampling_y, seq_params->use_highbitdepth,
- cpi->oxcf.border_in_pixels, cm->features.byte_alignment, NULL, NULL, NULL,
- cpi->oxcf.tool_cfg.enable_global_motion, 0);
- if (ret) {
- aom_internal_error(cm->error, AOM_CODEC_MEM_ERROR,
- "Failed to allocate tf_info");
- }
}
void av1_tf_info_free(TEMPORAL_FILTER_INFO *tf_info) {