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