Coverage Report

Created: 2026-11-12 08:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/aom/av1/encoder/encoder_alloc.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2020, Alliance for Open Media. All rights reserved.
3
 *
4
 * This source code is subject to the terms of the BSD 2 Clause License and
5
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6
 * was not distributed with this source code in the LICENSE file, you can
7
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8
 * Media Patent License 1.0 was not distributed with this source code in the
9
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10
 */
11
12
#ifndef AOM_AV1_ENCODER_ENCODER_ALLOC_H_
13
#define AOM_AV1_ENCODER_ENCODER_ALLOC_H_
14
15
#include "av1/encoder/block.h"
16
#include "av1/encoder/encodeframe_utils.h"
17
#include "av1/encoder/encoder.h"
18
#include "av1/encoder/encoder_utils.h"
19
#include "av1/encoder/encodetxb.h"
20
#include "av1/encoder/ethread.h"
21
#include "av1/encoder/global_motion_facade.h"
22
#include "av1/encoder/intra_mode_search_utils.h"
23
#include "av1/encoder/pickcdef.h"
24
25
#ifdef __cplusplus
26
extern "C" {
27
#endif
28
29
static inline void dealloc_context_buffers_ext(
30
0
    MBMIExtFrameBufferInfo *mbmi_ext_info) {
31
0
  aom_free(mbmi_ext_info->frame_base);
32
0
  mbmi_ext_info->frame_base = NULL;
33
0
  mbmi_ext_info->alloc_size = 0;
34
0
}
Unexecuted instantiation: compound_type.c:dealloc_context_buffers_ext
Unexecuted instantiation: encode_strategy.c:dealloc_context_buffers_ext
Unexecuted instantiation: encoder.c:dealloc_context_buffers_ext
Unexecuted instantiation: encoder_utils.c:dealloc_context_buffers_ext
Unexecuted instantiation: ethread.c:dealloc_context_buffers_ext
Unexecuted instantiation: superres_scale.c:dealloc_context_buffers_ext
Unexecuted instantiation: svc_layercontext.c:dealloc_context_buffers_ext
Unexecuted instantiation: av1_cx_iface.c:dealloc_context_buffers_ext
35
36
static inline void alloc_context_buffers_ext(
37
0
    AV1_COMMON *cm, MBMIExtFrameBufferInfo *mbmi_ext_info) {
38
0
  const CommonModeInfoParams *const mi_params = &cm->mi_params;
39
40
0
  const int mi_alloc_size_1d = mi_size_wide[mi_params->mi_alloc_bsize];
41
0
  const int mi_alloc_rows =
42
0
      (mi_params->mi_rows + mi_alloc_size_1d - 1) / mi_alloc_size_1d;
43
0
  const int mi_alloc_cols =
44
0
      (mi_params->mi_cols + mi_alloc_size_1d - 1) / mi_alloc_size_1d;
45
0
  const int new_ext_mi_size = mi_alloc_rows * mi_alloc_cols;
46
47
0
  if (new_ext_mi_size > mbmi_ext_info->alloc_size) {
48
0
    dealloc_context_buffers_ext(mbmi_ext_info);
49
0
    CHECK_MEM_ERROR(
50
0
        cm, mbmi_ext_info->frame_base,
51
0
        aom_malloc(new_ext_mi_size * sizeof(*mbmi_ext_info->frame_base)));
52
0
    mbmi_ext_info->alloc_size = new_ext_mi_size;
53
0
  }
54
  // The stride needs to be updated regardless of whether new allocation
55
  // happened or not.
56
0
  mbmi_ext_info->stride = mi_alloc_cols;
57
0
}
Unexecuted instantiation: compound_type.c:alloc_context_buffers_ext
Unexecuted instantiation: encode_strategy.c:alloc_context_buffers_ext
Unexecuted instantiation: encoder.c:alloc_context_buffers_ext
Unexecuted instantiation: encoder_utils.c:alloc_context_buffers_ext
Unexecuted instantiation: ethread.c:alloc_context_buffers_ext
Unexecuted instantiation: superres_scale.c:alloc_context_buffers_ext
Unexecuted instantiation: svc_layercontext.c:alloc_context_buffers_ext
Unexecuted instantiation: av1_cx_iface.c:alloc_context_buffers_ext
58
59
0
static inline void alloc_compressor_data(AV1_COMP *cpi) {
60
0
  AV1_COMMON *cm = &cpi->common;
61
0
  CommonModeInfoParams *const mi_params = &cm->mi_params;
62
63
  // Setup mi_params
64
0
  mi_params->set_mb_mi(mi_params, cm->width, cm->height,
65
0
                       cpi->sf.part_sf.default_min_partition_size);
66
67
0
  if (!is_stat_generation_stage(cpi)) av1_alloc_txb_buf(cpi);
68
69
0
  aom_free(cpi->td.mv_costs_alloc);
70
0
  cpi->td.mv_costs_alloc = NULL;
71
  // Avoid the memory allocation of 'mv_costs_alloc' for allintra encoding
72
  // mode.
73
0
  if (cpi->oxcf.kf_cfg.key_freq_max != 0) {
74
0
    CHECK_MEM_ERROR(cm, cpi->td.mv_costs_alloc,
75
0
                    (MvCosts *)aom_calloc(1, sizeof(*cpi->td.mv_costs_alloc)));
76
0
    cpi->td.mb.mv_costs = cpi->td.mv_costs_alloc;
77
0
  }
78
79
0
  av1_setup_shared_coeff_buffer(cm->seq_params, &cpi->td.shared_coeff_buf,
80
0
                                cm->error);
81
0
  if (av1_setup_sms_tree(cpi, &cpi->td)) {
82
0
    aom_internal_error(cm->error, AOM_CODEC_MEM_ERROR,
83
0
                       "Failed to allocate SMS tree");
84
0
  }
85
0
  if (is_stat_generation_stage(cpi) || cpi->ppi->lap_enabled) {
86
0
    cpi->td.firstpass_ctx =
87
0
        av1_alloc_pmc(cpi, BLOCK_16X16, &cpi->td.shared_coeff_buf);
88
0
    if (!cpi->td.firstpass_ctx)
89
0
      aom_internal_error(cm->error, AOM_CODEC_MEM_ERROR,
90
0
                         "Failed to allocate PICK_MODE_CONTEXT");
91
0
  }
92
0
}
Unexecuted instantiation: compound_type.c:alloc_compressor_data
Unexecuted instantiation: encode_strategy.c:alloc_compressor_data
Unexecuted instantiation: encoder.c:alloc_compressor_data
Unexecuted instantiation: encoder_utils.c:alloc_compressor_data
Unexecuted instantiation: ethread.c:alloc_compressor_data
Unexecuted instantiation: superres_scale.c:alloc_compressor_data
Unexecuted instantiation: svc_layercontext.c:alloc_compressor_data
Unexecuted instantiation: av1_cx_iface.c:alloc_compressor_data
93
94
// Allocate mbmi buffers which are used to store mode information at block
95
// level.
96
0
static inline void alloc_mb_mode_info_buffers(AV1_COMP *const cpi) {
97
0
  AV1_COMMON *const cm = &cpi->common;
98
0
  if (av1_alloc_context_buffers(cm, cm->width, cm->height,
99
0
                                cpi->sf.part_sf.default_min_partition_size)) {
100
0
    aom_internal_error(cm->error, AOM_CODEC_MEM_ERROR,
101
0
                       "Failed to allocate context buffers");
102
0
  }
103
104
0
  if (!is_stat_generation_stage(cpi))
105
0
    alloc_context_buffers_ext(cm, &cpi->mbmi_ext_info);
106
0
}
Unexecuted instantiation: compound_type.c:alloc_mb_mode_info_buffers
Unexecuted instantiation: encode_strategy.c:alloc_mb_mode_info_buffers
Unexecuted instantiation: encoder.c:alloc_mb_mode_info_buffers
Unexecuted instantiation: encoder_utils.c:alloc_mb_mode_info_buffers
Unexecuted instantiation: ethread.c:alloc_mb_mode_info_buffers
Unexecuted instantiation: superres_scale.c:alloc_mb_mode_info_buffers
Unexecuted instantiation: svc_layercontext.c:alloc_mb_mode_info_buffers
Unexecuted instantiation: av1_cx_iface.c:alloc_mb_mode_info_buffers
107
108
0
static inline void realloc_segmentation_maps(AV1_COMP *cpi) {
109
0
  AV1_COMMON *const cm = &cpi->common;
110
0
  CommonModeInfoParams *const mi_params = &cm->mi_params;
111
0
  int max_mi_cols = mi_params->mi_cols;
112
0
  int max_mi_rows = mi_params->mi_rows;
113
0
  if (cpi->oxcf.frm_dim_cfg.forced_max_frame_width) {
114
0
    max_mi_cols = size_in_mi(cpi->oxcf.frm_dim_cfg.forced_max_frame_width);
115
0
  }
116
0
  if (cpi->oxcf.frm_dim_cfg.forced_max_frame_height) {
117
0
    max_mi_rows = size_in_mi(cpi->oxcf.frm_dim_cfg.forced_max_frame_height);
118
0
  }
119
120
  // Create the encoder segmentation map and set all entries to 0
121
0
  aom_free(cpi->enc_seg.map);
122
0
  CHECK_MEM_ERROR(cm, cpi->enc_seg.map,
123
0
                  aom_calloc(max_mi_rows * max_mi_cols, 1));
124
125
  // Create a map used for cyclic background refresh.
126
0
  if (cpi->cyclic_refresh) av1_cyclic_refresh_free(cpi->cyclic_refresh);
127
0
  CHECK_MEM_ERROR(cm, cpi->cyclic_refresh,
128
0
                  av1_cyclic_refresh_alloc(max_mi_rows, max_mi_cols));
129
130
  // Create a map used to mark inactive areas.
131
0
  aom_free(cpi->active_map.map);
132
0
  CHECK_MEM_ERROR(cm, cpi->active_map.map,
133
0
                  aom_calloc(max_mi_rows * max_mi_cols, 1));
134
0
}
Unexecuted instantiation: compound_type.c:realloc_segmentation_maps
Unexecuted instantiation: encode_strategy.c:realloc_segmentation_maps
Unexecuted instantiation: encoder.c:realloc_segmentation_maps
Unexecuted instantiation: encoder_utils.c:realloc_segmentation_maps
Unexecuted instantiation: ethread.c:realloc_segmentation_maps
Unexecuted instantiation: superres_scale.c:realloc_segmentation_maps
Unexecuted instantiation: svc_layercontext.c:realloc_segmentation_maps
Unexecuted instantiation: av1_cx_iface.c:realloc_segmentation_maps
135
136
// Allocates the per-block RD multiplier scaling factors (and, with
137
// CONFIG_SALIENCY_MAP, the saliency map they are derived from) for the same
138
// maximum frame size as the other frame size dependent buffers. They are
139
// written for every block of the current frame, so they must be reallocated
140
// whenever that maximum grows.
141
0
static inline void alloc_rdmult_scaling_factors(AV1_COMP *cpi) {
142
0
  AV1_COMMON *const cm = &cpi->common;
143
0
  const CommonModeInfoParams *const mi_params = &cm->mi_params;
144
0
  int max_mi_cols = mi_params->mi_cols;
145
0
  int max_mi_rows = mi_params->mi_rows;
146
0
  if (cpi->oxcf.frm_dim_cfg.forced_max_frame_width) {
147
0
    max_mi_cols = size_in_mi(cpi->oxcf.frm_dim_cfg.forced_max_frame_width);
148
0
  }
149
0
  if (cpi->oxcf.frm_dim_cfg.forced_max_frame_height) {
150
0
    max_mi_rows = size_in_mi(cpi->oxcf.frm_dim_cfg.forced_max_frame_height);
151
0
  }
152
0
  const BLOCK_SIZE bsize = BLOCK_16X16;
153
0
  const int w = mi_size_wide[bsize];
154
0
  const int h = mi_size_high[bsize];
155
0
  const int num_cols = (max_mi_cols + w - 1) / w;
156
0
  const int num_rows = (max_mi_rows + h - 1) / h;
157
158
0
  aom_free(cpi->ssim_rdmult_scaling_factors);
159
0
  cpi->ssim_rdmult_scaling_factors = NULL;
160
0
  CHECK_MEM_ERROR(cm, cpi->ssim_rdmult_scaling_factors,
161
0
                  aom_malloc(num_rows * num_cols *
162
0
                             sizeof(*cpi->ssim_rdmult_scaling_factors)));
163
0
  aom_free(cpi->tpl_rdmult_scaling_factors);
164
0
  cpi->tpl_rdmult_scaling_factors = NULL;
165
0
  if (cpi->oxcf.mode != ALLINTRA) {
166
0
    CHECK_MEM_ERROR(cm, cpi->tpl_rdmult_scaling_factors,
167
0
                    aom_calloc(num_rows * num_cols,
168
0
                               sizeof(*cpi->tpl_rdmult_scaling_factors)));
169
0
  }
170
171
#if CONFIG_TUNE_VMAF
172
  {
173
    const BLOCK_SIZE vmaf_bsize = BLOCK_64X64;
174
    const int vmaf_w = mi_size_wide[vmaf_bsize];
175
    const int vmaf_h = mi_size_high[vmaf_bsize];
176
    const int vmaf_num_cols = (max_mi_cols + vmaf_w - 1) / vmaf_w;
177
    const int vmaf_num_rows = (max_mi_rows + vmaf_h - 1) / vmaf_h;
178
    aom_free(cpi->vmaf_info.rdmult_scaling_factors);
179
    cpi->vmaf_info.rdmult_scaling_factors = NULL;
180
    CHECK_MEM_ERROR(cm, cpi->vmaf_info.rdmult_scaling_factors,
181
                    aom_calloc(vmaf_num_rows * vmaf_num_cols,
182
                               sizeof(*cpi->vmaf_info.rdmult_scaling_factors)));
183
  }
184
#endif  // CONFIG_TUNE_VMAF
185
186
#if CONFIG_TUNE_BUTTERAUGLI
187
  {
188
    const int ba_w = mi_size_wide[butteraugli_rdo_bsize];
189
    const int ba_h = mi_size_high[butteraugli_rdo_bsize];
190
    const int ba_num_cols = (max_mi_cols + ba_w - 1) / ba_w;
191
    const int ba_num_rows = (max_mi_rows + ba_h - 1) / ba_h;
192
    aom_free(cpi->butteraugli_info.rdmult_scaling_factors);
193
    cpi->butteraugli_info.rdmult_scaling_factors = NULL;
194
    CHECK_MEM_ERROR(
195
        cm, cpi->butteraugli_info.rdmult_scaling_factors,
196
        aom_malloc(ba_num_rows * ba_num_cols *
197
                   sizeof(*cpi->butteraugli_info.rdmult_scaling_factors)));
198
  }
199
#endif  // CONFIG_TUNE_BUTTERAUGLI
200
201
#if CONFIG_SALIENCY_MAP
202
  {
203
    const int max_width = cpi->oxcf.frm_dim_cfg.forced_max_frame_width
204
                              ? cpi->oxcf.frm_dim_cfg.forced_max_frame_width
205
                              : cm->width;
206
    const int max_height = cpi->oxcf.frm_dim_cfg.forced_max_frame_height
207
                               ? cpi->oxcf.frm_dim_cfg.forced_max_frame_height
208
                               : cm->height;
209
    aom_free(cpi->saliency_map);
210
    cpi->saliency_map = NULL;
211
    CHECK_MEM_ERROR(cm, cpi->saliency_map,
212
                    (uint8_t *)aom_calloc(max_height * max_width,
213
                                          sizeof(*cpi->saliency_map)));
214
    // Buffer initialization based on MIN_MIB_SIZE_LOG2 to ensure that
215
    // cpi->sm_scaling_factor buffer is allocated big enough, since we have no
216
    // idea of the actual superblock size we are going to use yet.
217
    const int min_mi_w_sb = (1 << MIN_MIB_SIZE_LOG2);
218
    const int min_mi_h_sb = (1 << MIN_MIB_SIZE_LOG2);
219
    const int max_sb_cols = (max_mi_cols + min_mi_w_sb - 1) / min_mi_w_sb;
220
    const int max_sb_rows = (max_mi_rows + min_mi_h_sb - 1) / min_mi_h_sb;
221
    aom_free(cpi->sm_scaling_factor);
222
    cpi->sm_scaling_factor = NULL;
223
    CHECK_MEM_ERROR(cm, cpi->sm_scaling_factor,
224
                    (double *)aom_calloc(max_sb_rows * max_sb_cols,
225
                                         sizeof(*cpi->sm_scaling_factor)));
226
  }
227
#endif  // CONFIG_SALIENCY_MAP
228
0
}
Unexecuted instantiation: compound_type.c:alloc_rdmult_scaling_factors
Unexecuted instantiation: encode_strategy.c:alloc_rdmult_scaling_factors
Unexecuted instantiation: encoder.c:alloc_rdmult_scaling_factors
Unexecuted instantiation: encoder_utils.c:alloc_rdmult_scaling_factors
Unexecuted instantiation: ethread.c:alloc_rdmult_scaling_factors
Unexecuted instantiation: superres_scale.c:alloc_rdmult_scaling_factors
Unexecuted instantiation: svc_layercontext.c:alloc_rdmult_scaling_factors
Unexecuted instantiation: av1_cx_iface.c:alloc_rdmult_scaling_factors
229
230
static inline void alloc_obmc_buffers(OBMCBuffer *obmc_buffer,
231
0
                                      struct aom_internal_error_info *error) {
232
0
  AOM_CHECK_MEM_ERROR(
233
0
      error, obmc_buffer->wsrc,
234
0
      (int32_t *)aom_memalign(16, MAX_SB_SQUARE * sizeof(*obmc_buffer->wsrc)));
235
0
  AOM_CHECK_MEM_ERROR(
236
0
      error, obmc_buffer->mask,
237
0
      (int32_t *)aom_memalign(16, MAX_SB_SQUARE * sizeof(*obmc_buffer->mask)));
238
0
  AOM_CHECK_MEM_ERROR(
239
0
      error, obmc_buffer->above_pred,
240
0
      (uint8_t *)aom_memalign(
241
0
          16, MAX_MB_PLANE * MAX_SB_SQUARE * sizeof(*obmc_buffer->above_pred)));
242
0
  AOM_CHECK_MEM_ERROR(
243
0
      error, obmc_buffer->left_pred,
244
0
      (uint8_t *)aom_memalign(
245
0
          16, MAX_MB_PLANE * MAX_SB_SQUARE * sizeof(*obmc_buffer->left_pred)));
246
0
}
Unexecuted instantiation: compound_type.c:alloc_obmc_buffers
Unexecuted instantiation: encode_strategy.c:alloc_obmc_buffers
Unexecuted instantiation: encoder.c:alloc_obmc_buffers
Unexecuted instantiation: encoder_utils.c:alloc_obmc_buffers
Unexecuted instantiation: ethread.c:alloc_obmc_buffers
Unexecuted instantiation: superres_scale.c:alloc_obmc_buffers
Unexecuted instantiation: svc_layercontext.c:alloc_obmc_buffers
Unexecuted instantiation: av1_cx_iface.c:alloc_obmc_buffers
247
248
0
static inline void release_obmc_buffers(OBMCBuffer *obmc_buffer) {
249
0
  aom_free(obmc_buffer->mask);
250
0
  aom_free(obmc_buffer->above_pred);
251
0
  aom_free(obmc_buffer->left_pred);
252
0
  aom_free(obmc_buffer->wsrc);
253
254
0
  obmc_buffer->mask = NULL;
255
0
  obmc_buffer->above_pred = NULL;
256
0
  obmc_buffer->left_pred = NULL;
257
0
  obmc_buffer->wsrc = NULL;
258
0
}
Unexecuted instantiation: compound_type.c:release_obmc_buffers
Unexecuted instantiation: encode_strategy.c:release_obmc_buffers
Unexecuted instantiation: encoder.c:release_obmc_buffers
Unexecuted instantiation: encoder_utils.c:release_obmc_buffers
Unexecuted instantiation: ethread.c:release_obmc_buffers
Unexecuted instantiation: superres_scale.c:release_obmc_buffers
Unexecuted instantiation: svc_layercontext.c:release_obmc_buffers
Unexecuted instantiation: av1_cx_iface.c:release_obmc_buffers
259
260
static inline void alloc_compound_type_rd_buffers(
261
0
    struct aom_internal_error_info *error, CompoundTypeRdBuffers *const bufs) {
262
0
  AOM_CHECK_MEM_ERROR(
263
0
      error, bufs->pred0,
264
0
      (uint8_t *)aom_memalign(16, 2 * MAX_SB_SQUARE * sizeof(*bufs->pred0)));
265
0
  AOM_CHECK_MEM_ERROR(
266
0
      error, bufs->pred1,
267
0
      (uint8_t *)aom_memalign(16, 2 * MAX_SB_SQUARE * sizeof(*bufs->pred1)));
268
0
  AOM_CHECK_MEM_ERROR(
269
0
      error, bufs->residual1,
270
0
      (int16_t *)aom_memalign(32, MAX_SB_SQUARE * sizeof(*bufs->residual1)));
271
0
  AOM_CHECK_MEM_ERROR(
272
0
      error, bufs->diff10,
273
0
      (int16_t *)aom_memalign(32, MAX_SB_SQUARE * sizeof(*bufs->diff10)));
274
0
  AOM_CHECK_MEM_ERROR(error, bufs->tmp_best_mask_buf,
275
0
                      (uint8_t *)aom_malloc(2 * MAX_SB_SQUARE *
276
0
                                            sizeof(*bufs->tmp_best_mask_buf)));
277
0
}
Unexecuted instantiation: compound_type.c:alloc_compound_type_rd_buffers
Unexecuted instantiation: encode_strategy.c:alloc_compound_type_rd_buffers
Unexecuted instantiation: encoder.c:alloc_compound_type_rd_buffers
Unexecuted instantiation: encoder_utils.c:alloc_compound_type_rd_buffers
Unexecuted instantiation: ethread.c:alloc_compound_type_rd_buffers
Unexecuted instantiation: superres_scale.c:alloc_compound_type_rd_buffers
Unexecuted instantiation: svc_layercontext.c:alloc_compound_type_rd_buffers
Unexecuted instantiation: av1_cx_iface.c:alloc_compound_type_rd_buffers
278
279
static inline void release_compound_type_rd_buffers(
280
0
    CompoundTypeRdBuffers *const bufs) {
281
0
  aom_free(bufs->pred0);
282
0
  aom_free(bufs->pred1);
283
0
  aom_free(bufs->residual1);
284
0
  aom_free(bufs->diff10);
285
0
  aom_free(bufs->tmp_best_mask_buf);
286
0
  av1_zero(*bufs);  // Set all pointers to NULL for safety.
287
0
}
Unexecuted instantiation: compound_type.c:release_compound_type_rd_buffers
Unexecuted instantiation: encode_strategy.c:release_compound_type_rd_buffers
Unexecuted instantiation: encoder.c:release_compound_type_rd_buffers
Unexecuted instantiation: encoder_utils.c:release_compound_type_rd_buffers
Unexecuted instantiation: ethread.c:release_compound_type_rd_buffers
Unexecuted instantiation: superres_scale.c:release_compound_type_rd_buffers
Unexecuted instantiation: svc_layercontext.c:release_compound_type_rd_buffers
Unexecuted instantiation: av1_cx_iface.c:release_compound_type_rd_buffers
288
289
0
static inline void dealloc_compressor_data(AV1_COMP *cpi) {
290
0
  AV1_COMMON *const cm = &cpi->common;
291
0
  TokenInfo *token_info = &cpi->token_info;
292
0
  const int num_planes = av1_num_planes(cm);
293
0
  dealloc_context_buffers_ext(&cpi->mbmi_ext_info);
294
295
0
  aom_free(cpi->tile_data);
296
0
  cpi->tile_data = NULL;
297
0
  cpi->allocated_tiles = 0;
298
299
  // Delete sementation map
300
0
  aom_free(cpi->enc_seg.map);
301
0
  cpi->enc_seg.map = NULL;
302
303
0
  av1_cyclic_refresh_free(cpi->cyclic_refresh);
304
0
  cpi->cyclic_refresh = NULL;
305
306
0
  aom_free(cpi->active_map.map);
307
0
  cpi->active_map.map = NULL;
308
309
0
  aom_free(cpi->roi.roi_map);
310
0
  cpi->roi.roi_map = NULL;
311
312
0
  aom_free(cpi->ssim_rdmult_scaling_factors);
313
0
  cpi->ssim_rdmult_scaling_factors = NULL;
314
315
0
  aom_free(cpi->tpl_rdmult_scaling_factors);
316
0
  cpi->tpl_rdmult_scaling_factors = NULL;
317
318
#if CONFIG_TUNE_VMAF
319
  aom_free(cpi->vmaf_info.rdmult_scaling_factors);
320
  cpi->vmaf_info.rdmult_scaling_factors = NULL;
321
  aom_close_vmaf_model(cpi->vmaf_info.vmaf_model);
322
#endif
323
324
#if CONFIG_TUNE_BUTTERAUGLI
325
  aom_free(cpi->butteraugli_info.rdmult_scaling_factors);
326
  cpi->butteraugli_info.rdmult_scaling_factors = NULL;
327
  aom_free_frame_buffer(&cpi->butteraugli_info.source);
328
  aom_free_frame_buffer(&cpi->butteraugli_info.resized_source);
329
#endif
330
331
#if CONFIG_SALIENCY_MAP
332
  aom_free(cpi->saliency_map);
333
  aom_free(cpi->sm_scaling_factor);
334
#endif
335
336
0
  release_obmc_buffers(&cpi->td.mb.obmc_buffer);
337
338
0
  aom_free(cpi->td.mv_costs_alloc);
339
0
  cpi->td.mv_costs_alloc = NULL;
340
0
  aom_free(cpi->td.dv_costs_alloc);
341
0
  cpi->td.dv_costs_alloc = NULL;
342
343
0
  aom_free(cpi->td.mb.sb_stats_cache);
344
0
  cpi->td.mb.sb_stats_cache = NULL;
345
346
0
  aom_free(cpi->td.mb.sb_fp_stats);
347
0
  cpi->td.mb.sb_fp_stats = NULL;
348
349
#if CONFIG_PARTITION_SEARCH_ORDER
350
  aom_free(cpi->td.mb.rdcost);
351
  cpi->td.mb.rdcost = NULL;
352
#endif
353
354
0
  av1_free_pc_tree_recursive(cpi->td.pc_root, num_planes, 0, 0,
355
0
                             cpi->sf.part_sf.partition_search_type);
356
0
  cpi->td.pc_root = NULL;
357
358
0
  for (int i = 0; i < 2; i++) {
359
0
    aom_free(cpi->td.mb.intrabc_hash_info.hash_value_buffer[i]);
360
0
    cpi->td.mb.intrabc_hash_info.hash_value_buffer[i] = NULL;
361
0
  }
362
363
0
  av1_hash_tables_destroy(&cpi->td.mb.intrabc_hash_info);
364
365
0
  aom_free(cm->tpl_mvs);
366
0
  cm->tpl_mvs = NULL;
367
368
0
  aom_free(cpi->td.pixel_gradient_info);
369
0
  cpi->td.pixel_gradient_info = NULL;
370
371
0
  aom_free(cpi->td.src_var_info_of_4x4_sub_blocks);
372
0
  cpi->td.src_var_info_of_4x4_sub_blocks = NULL;
373
374
0
  aom_free(cpi->td.vt64x64);
375
0
  cpi->td.vt64x64 = NULL;
376
377
0
  av1_free_pmc(cpi->td.firstpass_ctx, num_planes);
378
0
  cpi->td.firstpass_ctx = NULL;
379
380
0
  const int is_highbitdepth = cpi->tf_ctx.is_highbitdepth;
381
  // This call ensures that the buffers allocated by tf_alloc_and_reset_data()
382
  // in av1_temporal_filter() for single-threaded encode are freed in case an
383
  // error is encountered during temporal filtering (due to early termination
384
  // tf_dealloc_data() in av1_temporal_filter() would not be invoked).
385
0
  tf_dealloc_data(&cpi->td.tf_data, is_highbitdepth);
386
387
  // This call ensures that tpl_tmp_buffers for single-threaded encode are freed
388
  // in case of an error during tpl.
389
0
  tpl_dealloc_temp_buffers(&cpi->td.tpl_tmp_buffers);
390
391
  // This call ensures that the global motion (gm) data buffers for
392
  // single-threaded encode are freed in case of an error during gm.
393
0
  gm_dealloc_data(&cpi->td.gm_data);
394
395
  // This call ensures that CDEF search context buffers are deallocated in case
396
  // of an error during cdef search.
397
0
  av1_cdef_dealloc_data(cpi->cdef_search_ctx);
398
0
  aom_free(cpi->cdef_search_ctx);
399
0
  cpi->cdef_search_ctx = NULL;
400
401
0
  av1_dealloc_mb_data(&cpi->td.mb, num_planes);
402
403
0
  av1_dealloc_mb_wiener_var_pred_buf(&cpi->td);
404
405
0
  av1_free_txb_buf(cpi);
406
0
  av1_free_context_buffers(cm);
407
408
0
  aom_free_frame_buffer(&cpi->last_frame_uf);
409
0
#if !CONFIG_REALTIME_ONLY
410
0
  av1_free_restoration_buffers(cm);
411
0
  av1_free_firstpass_data(&cpi->firstpass_data);
412
0
#endif
413
414
0
  if (!is_stat_generation_stage(cpi)) {
415
0
    av1_free_cdef_buffers(cm, &cpi->ppi->p_mt_info.cdef_worker,
416
0
                          &cpi->mt_info.cdef_sync);
417
0
  }
418
419
0
  for (int plane = 0; plane < num_planes; plane++) {
420
0
    aom_free(cpi->pick_lr_ctxt.rusi[plane]);
421
0
    cpi->pick_lr_ctxt.rusi[plane] = NULL;
422
0
  }
423
0
  aom_free(cpi->pick_lr_ctxt.dgd_avg);
424
0
  cpi->pick_lr_ctxt.dgd_avg = NULL;
425
426
0
  aom_free_frame_buffer(&cpi->trial_frame_rst);
427
0
  aom_free_frame_buffer(&cpi->scaled_source);
428
0
  aom_free_frame_buffer(&cpi->scaled_last_source);
429
0
  aom_free_frame_buffer(&cpi->orig_source);
430
0
  aom_free_frame_buffer(&cpi->svc.source_last_TL0);
431
432
0
  free_token_info(token_info);
433
434
0
  av1_free_shared_coeff_buffer(&cpi->td.shared_coeff_buf);
435
0
  av1_free_sms_tree(&cpi->td);
436
437
0
  aom_free(cpi->td.mb.palette_buffer);
438
0
  release_compound_type_rd_buffers(&cpi->td.mb.comp_rd_buffer);
439
0
  aom_free(cpi->td.mb.tmp_conv_dst);
440
0
  aom_free(cpi->td.mb.upsample_pred);
441
0
  for (int j = 0; j < 2; ++j) {
442
0
    aom_free(cpi->td.mb.tmp_pred_bufs[j]);
443
0
  }
444
445
0
#if CONFIG_DENOISE && !CONFIG_REALTIME_ONLY
446
0
  if (cpi->denoise_and_model) {
447
0
    aom_denoise_and_model_free(cpi->denoise_and_model);
448
0
    cpi->denoise_and_model = NULL;
449
0
  }
450
0
#endif
451
0
#if !CONFIG_REALTIME_ONLY
452
0
  if (cpi->film_grain_table) {
453
0
    aom_film_grain_table_free(cpi->film_grain_table);
454
0
    aom_free(cpi->film_grain_table);
455
0
    cpi->film_grain_table = NULL;
456
0
  }
457
0
#endif
458
459
0
  if (cpi->ppi->use_svc) av1_free_svc_cyclic_refresh(cpi);
460
0
  aom_free(cpi->svc.layer_context);
461
0
  cpi->svc.layer_context = NULL;
462
463
0
  aom_free(cpi->consec_zero_mv);
464
0
  cpi->consec_zero_mv = NULL;
465
0
  cpi->consec_zero_mv_alloc_size = 0;
466
467
0
  aom_free(cpi->src_sad_blk_64x64);
468
0
  cpi->src_sad_blk_64x64 = NULL;
469
470
0
  aom_free(cpi->mb_weber_stats);
471
0
  cpi->mb_weber_stats = NULL;
472
0
  cpi->mb_weber_stats_alloc_size = 0;
473
474
0
  if (cpi->oxcf.enable_rate_guide_deltaq) {
475
0
    aom_free(cpi->prep_rate_estimates);
476
0
    cpi->prep_rate_estimates = NULL;
477
478
0
    aom_free(cpi->ext_rate_distribution);
479
0
    cpi->ext_rate_distribution = NULL;
480
0
  }
481
482
0
  aom_free(cpi->mb_delta_q);
483
0
  cpi->mb_delta_q = NULL;
484
0
  cpi->mb_delta_q_alloc_size = 0;
485
486
0
#if !CONFIG_REALTIME_ONLY
487
0
  av1_free_tpl_gop_stats(&cpi->extrc_tpl_gop_stats);
488
0
#endif
489
0
}
Unexecuted instantiation: compound_type.c:dealloc_compressor_data
Unexecuted instantiation: encode_strategy.c:dealloc_compressor_data
Unexecuted instantiation: encoder.c:dealloc_compressor_data
Unexecuted instantiation: encoder_utils.c:dealloc_compressor_data
Unexecuted instantiation: ethread.c:dealloc_compressor_data
Unexecuted instantiation: superres_scale.c:dealloc_compressor_data
Unexecuted instantiation: svc_layercontext.c:dealloc_compressor_data
Unexecuted instantiation: av1_cx_iface.c:dealloc_compressor_data
490
491
0
static inline void allocate_gradient_info_for_hog(AV1_COMP *cpi) {
492
0
  if (!is_gradient_caching_for_hog_enabled(cpi)) return;
493
494
0
  PixelLevelGradientInfo *pixel_gradient_info = cpi->td.pixel_gradient_info;
495
0
  if (!pixel_gradient_info) {
496
0
    const AV1_COMMON *const cm = &cpi->common;
497
0
    const int plane_types = PLANE_TYPES >> cm->seq_params->monochrome;
498
0
    CHECK_MEM_ERROR(
499
0
        cm, pixel_gradient_info,
500
0
        aom_malloc(sizeof(*pixel_gradient_info) * plane_types * MAX_SB_SQUARE));
501
0
    cpi->td.pixel_gradient_info = pixel_gradient_info;
502
0
  }
503
504
0
  cpi->td.mb.pixel_gradient_info = pixel_gradient_info;
505
0
}
Unexecuted instantiation: compound_type.c:allocate_gradient_info_for_hog
Unexecuted instantiation: encode_strategy.c:allocate_gradient_info_for_hog
Unexecuted instantiation: encoder.c:allocate_gradient_info_for_hog
Unexecuted instantiation: encoder_utils.c:allocate_gradient_info_for_hog
Unexecuted instantiation: ethread.c:allocate_gradient_info_for_hog
Unexecuted instantiation: superres_scale.c:allocate_gradient_info_for_hog
Unexecuted instantiation: svc_layercontext.c:allocate_gradient_info_for_hog
Unexecuted instantiation: av1_cx_iface.c:allocate_gradient_info_for_hog
506
507
0
static inline void allocate_src_var_of_4x4_sub_block_buf(AV1_COMP *cpi) {
508
0
  if (!is_src_var_for_4x4_sub_blocks_caching_enabled(cpi)) return;
509
510
0
  Block4x4VarInfo *source_variance_info =
511
0
      cpi->td.src_var_info_of_4x4_sub_blocks;
512
0
  if (!source_variance_info) {
513
0
    const AV1_COMMON *const cm = &cpi->common;
514
0
    const BLOCK_SIZE sb_size = cm->seq_params->sb_size;
515
0
    const int mi_count_in_sb = mi_size_wide[sb_size] * mi_size_high[sb_size];
516
0
    CHECK_MEM_ERROR(cm, source_variance_info,
517
0
                    aom_malloc(sizeof(*source_variance_info) * mi_count_in_sb));
518
0
    cpi->td.src_var_info_of_4x4_sub_blocks = source_variance_info;
519
0
  }
520
521
0
  cpi->td.mb.src_var_info_of_4x4_sub_blocks = source_variance_info;
522
0
}
Unexecuted instantiation: compound_type.c:allocate_src_var_of_4x4_sub_block_buf
Unexecuted instantiation: encode_strategy.c:allocate_src_var_of_4x4_sub_block_buf
Unexecuted instantiation: encoder.c:allocate_src_var_of_4x4_sub_block_buf
Unexecuted instantiation: encoder_utils.c:allocate_src_var_of_4x4_sub_block_buf
Unexecuted instantiation: ethread.c:allocate_src_var_of_4x4_sub_block_buf
Unexecuted instantiation: superres_scale.c:allocate_src_var_of_4x4_sub_block_buf
Unexecuted instantiation: svc_layercontext.c:allocate_src_var_of_4x4_sub_block_buf
Unexecuted instantiation: av1_cx_iface.c:allocate_src_var_of_4x4_sub_block_buf
523
524
0
static inline void variance_partition_alloc(AV1_COMP *cpi) {
525
0
  AV1_COMMON *const cm = &cpi->common;
526
0
  const int num_64x64_blocks = (cm->seq_params->sb_size == BLOCK_64X64) ? 1 : 4;
527
0
  if (cpi->td.vt64x64) {
528
0
    if (num_64x64_blocks != cpi->td.num_64x64_blocks) {
529
0
      aom_free(cpi->td.vt64x64);
530
0
      cpi->td.vt64x64 = NULL;
531
0
    }
532
0
  }
533
0
  if (!cpi->td.vt64x64) {
534
0
    CHECK_MEM_ERROR(cm, cpi->td.vt64x64,
535
0
                    aom_malloc(sizeof(*cpi->td.vt64x64) * num_64x64_blocks));
536
0
    cpi->td.num_64x64_blocks = num_64x64_blocks;
537
0
  }
538
0
}
Unexecuted instantiation: compound_type.c:variance_partition_alloc
Unexecuted instantiation: encode_strategy.c:variance_partition_alloc
Unexecuted instantiation: encoder.c:variance_partition_alloc
Unexecuted instantiation: encoder_utils.c:variance_partition_alloc
Unexecuted instantiation: ethread.c:variance_partition_alloc
Unexecuted instantiation: superres_scale.c:variance_partition_alloc
Unexecuted instantiation: svc_layercontext.c:variance_partition_alloc
Unexecuted instantiation: av1_cx_iface.c:variance_partition_alloc
539
540
static inline YV12_BUFFER_CONFIG *realloc_and_scale_source(AV1_COMP *cpi,
541
                                                           int scaled_width,
542
0
                                                           int scaled_height) {
543
0
  AV1_COMMON *cm = &cpi->common;
544
0
  const int num_planes = av1_num_planes(cm);
545
546
0
  if (scaled_width == cpi->unscaled_source->y_crop_width &&
547
0
      scaled_height == cpi->unscaled_source->y_crop_height) {
548
0
    return cpi->unscaled_source;
549
0
  }
550
551
0
  if (aom_realloc_frame_buffer(
552
0
          &cpi->scaled_source, scaled_width, scaled_height,
553
0
          cm->seq_params->subsampling_x, cm->seq_params->subsampling_y,
554
0
          cm->seq_params->use_highbitdepth, AOM_BORDER_IN_PIXELS,
555
0
          cm->features.byte_alignment, NULL, NULL, NULL, cpi->alloc_pyramid, 0))
556
0
    aom_internal_error(cm->error, AOM_CODEC_MEM_ERROR,
557
0
                       "Failed to reallocate scaled source buffer");
558
0
  assert(cpi->scaled_source.y_crop_width == scaled_width);
559
0
  assert(cpi->scaled_source.y_crop_height == scaled_height);
560
0
  if (!av1_resize_and_extend_frame_nonnormative(
561
0
          cpi->unscaled_source, &cpi->scaled_source,
562
0
          (int)cm->seq_params->bit_depth, num_planes))
563
0
    aom_internal_error(cm->error, AOM_CODEC_MEM_ERROR,
564
0
                       "Failed to reallocate buffers during resize");
565
0
  return &cpi->scaled_source;
566
0
}
Unexecuted instantiation: compound_type.c:realloc_and_scale_source
Unexecuted instantiation: encode_strategy.c:realloc_and_scale_source
Unexecuted instantiation: encoder.c:realloc_and_scale_source
Unexecuted instantiation: encoder_utils.c:realloc_and_scale_source
Unexecuted instantiation: ethread.c:realloc_and_scale_source
Unexecuted instantiation: superres_scale.c:realloc_and_scale_source
Unexecuted instantiation: svc_layercontext.c:realloc_and_scale_source
Unexecuted instantiation: av1_cx_iface.c:realloc_and_scale_source
567
568
// Deallocate allocated thread_data.
569
0
static inline void free_thread_data(AV1_PRIMARY *ppi) {
570
0
  PrimaryMultiThreadInfo *const p_mt_info = &ppi->p_mt_info;
571
0
  const int num_tf_workers =
572
0
      AOMMIN(p_mt_info->num_mod_workers[MOD_TF], p_mt_info->num_workers);
573
0
  const int num_tpl_workers =
574
0
      AOMMIN(p_mt_info->num_mod_workers[MOD_TPL], p_mt_info->num_workers);
575
0
  const int is_highbitdepth = ppi->seq_params.use_highbitdepth;
576
0
  const int num_planes = ppi->seq_params.monochrome ? 1 : MAX_MB_PLANE;
577
0
  for (int t = 1; t < p_mt_info->num_workers; ++t) {
578
0
    EncWorkerData *const thread_data = &p_mt_info->tile_thr_data[t];
579
0
    thread_data->td = thread_data->original_td;
580
0
    ThreadData *const td = thread_data->td;
581
0
    if (!td) continue;
582
0
    aom_free(td->tctx);
583
0
    aom_free(td->palette_buffer);
584
0
    aom_free(td->tmp_conv_dst);
585
0
    aom_free(td->upsample_pred);
586
0
    release_compound_type_rd_buffers(&td->comp_rd_buffer);
587
0
    for (int j = 0; j < 2; ++j) {
588
0
      aom_free(td->tmp_pred_bufs[j]);
589
0
    }
590
0
    aom_free(td->pixel_gradient_info);
591
0
    aom_free(td->src_var_info_of_4x4_sub_blocks);
592
0
    release_obmc_buffers(&td->obmc_buffer);
593
0
    aom_free(td->vt64x64);
594
595
0
    for (int x = 0; x < 2; x++) {
596
0
      aom_free(td->hash_value_buffer[x]);
597
0
      td->hash_value_buffer[x] = NULL;
598
0
    }
599
0
    aom_free(td->mv_costs_alloc);
600
0
    td->mv_costs_alloc = NULL;
601
0
    aom_free(td->dv_costs_alloc);
602
0
    td->dv_costs_alloc = NULL;
603
0
    aom_free(td->counts);
604
0
    av1_free_pmc(td->firstpass_ctx, num_planes);
605
0
    td->firstpass_ctx = NULL;
606
0
    av1_free_shared_coeff_buffer(&td->shared_coeff_buf);
607
0
    av1_free_sms_tree(td);
608
    // This call ensures that the buffers allocated by tf_alloc_and_reset_data()
609
    // in prepare_tf_workers() for MT encode are freed in case an error is
610
    // encountered during temporal filtering (due to early termination
611
    // tf_dealloc_thread_data() in av1_tf_do_filtering_mt() would not be
612
    // invoked).
613
0
    if (t < num_tf_workers) tf_dealloc_data(&td->tf_data, is_highbitdepth);
614
    // This call ensures that tpl_tmp_buffers for MT encode are freed in case of
615
    // an error during tpl.
616
0
    if (t < num_tpl_workers) tpl_dealloc_temp_buffers(&td->tpl_tmp_buffers);
617
    // This call ensures that the buffers in gm_data for MT encode are freed in
618
    // case of an error during gm.
619
0
    gm_dealloc_data(&td->gm_data);
620
0
    av1_dealloc_mb_data(&td->mb, num_planes);
621
0
    aom_free(td->mb.sb_stats_cache);
622
0
    td->mb.sb_stats_cache = NULL;
623
0
    aom_free(td->mb.sb_fp_stats);
624
0
    td->mb.sb_fp_stats = NULL;
625
#if CONFIG_PARTITION_SEARCH_ORDER
626
    aom_free(td->mb.rdcost);
627
    td->mb.rdcost = NULL;
628
#endif
629
0
    av1_free_pc_tree_recursive(td->pc_root, num_planes, 0, 0, SEARCH_PARTITION);
630
0
    td->pc_root = NULL;
631
0
    av1_dealloc_mb_wiener_var_pred_buf(td);
632
0
    aom_free(td);
633
0
    thread_data->td = NULL;
634
    thread_data->original_td = NULL;
635
0
  }
636
0
}
Unexecuted instantiation: compound_type.c:free_thread_data
Unexecuted instantiation: encode_strategy.c:free_thread_data
Unexecuted instantiation: encoder.c:free_thread_data
Unexecuted instantiation: encoder_utils.c:free_thread_data
Unexecuted instantiation: ethread.c:free_thread_data
Unexecuted instantiation: superres_scale.c:free_thread_data
Unexecuted instantiation: svc_layercontext.c:free_thread_data
Unexecuted instantiation: av1_cx_iface.c:free_thread_data
637
638
#ifdef __cplusplus
639
}  // extern "C"
640
#endif
641
642
#endif  // AOM_AV1_ENCODER_ENCODER_ALLOC_H_