/work/svt-av1/Source/Lib/Codec/pcs.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright(c) 2019 Intel Corporation |
3 | | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
4 | | * |
5 | | * This source code is subject to the terms of the BSD 2 Clause License and |
6 | | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
7 | | * was not distributed with this source code in the LICENSE file, you can |
8 | | * obtain it at https://www.aomedia.org/license/software-license. If the Alliance for Open |
9 | | * Media Patent License 1.0 was not distributed with this source code in the |
10 | | * PATENTS file, you can obtain it at https://www.aomedia.org/license/patent-license. |
11 | | */ |
12 | | |
13 | | #include <stdlib.h> |
14 | | |
15 | | #include "definitions.h" |
16 | | #include "pcs.h" |
17 | | #include "sequence_control_set.h" |
18 | | #include "pic_buffer_desc.h" |
19 | | #include "utility.h" |
20 | | #include "resource_coordination_process.h" |
21 | | #include "md_config_process.h" |
22 | | #include "enc_mode_config.h" |
23 | | |
24 | | void svt_aom_set_tile_info(PictureParentControlSet* pcs); |
25 | | |
26 | | EbErrorType svt_av1_alloc_restoration_buffers(PictureControlSet* pcs, Av1Common* cm); |
27 | | EbErrorType svt_av1_hash_table_create(HashTable* p_hash_table); |
28 | | |
29 | 0 | static void set_restoration_unit_size(int32_t width, int32_t height, int32_t sx, int32_t sy, RestorationInfo* rst) { |
30 | 0 | (void)width; |
31 | 0 | (void)height; |
32 | 0 | (void)sx; |
33 | 0 | (void)sy; |
34 | |
|
35 | 0 | int32_t s = 0; |
36 | |
|
37 | 0 | rst[0].restoration_unit_size = RESTORATION_UNITSIZE_MAX; |
38 | |
|
39 | 0 | rst[1].restoration_unit_size = rst[0].restoration_unit_size >> s; |
40 | 0 | rst[2].restoration_unit_size = rst[1].restoration_unit_size; |
41 | 0 | } |
42 | | |
43 | 1.79k | static void dg_detector_seg_dctor(EbPtr p) { |
44 | 1.79k | DGDetectorSeg* obj = (DGDetectorSeg*)p; |
45 | | |
46 | 1.79k | EB_DESTROY_SEMAPHORE(obj->frame_done_sem); |
47 | 1.79k | EB_DESTROY_MUTEX(obj->metrics_mutex); |
48 | 1.79k | } |
49 | | |
50 | 1.79k | EbErrorType svt_aom_dg_detector_seg_ctor(DGDetectorSeg* obj_ptr) { |
51 | 1.79k | obj_ptr->dctor = dg_detector_seg_dctor; |
52 | | |
53 | 1.79k | EB_CREATE_SEMAPHORE(obj_ptr->frame_done_sem, 0, 1); |
54 | 1.79k | EB_CREATE_MUTEX(obj_ptr->metrics_mutex); |
55 | 1.79k | return EB_ErrorNone; |
56 | 1.79k | } |
57 | | |
58 | 448 | static void segmentation_map_dctor(EbPtr p) { |
59 | 448 | SegmentationNeighborMap* obj = (SegmentationNeighborMap*)p; |
60 | 448 | EB_FREE_ARRAY(obj->data); |
61 | 448 | } |
62 | | |
63 | 0 | static void svt_pcs_sb_structs_dctor(EbPtr p) { |
64 | 0 | PictureParentControlSet* obj = (PictureParentControlSet*)p; |
65 | 0 | EB_FREE_ARRAY(obj->b64_geom); |
66 | 0 | free_sb_geoms(obj->sb_geom); |
67 | 0 | } |
68 | | |
69 | 448 | EbErrorType segmentation_map_ctor(SegmentationNeighborMap* seg_neighbor_map, uint16_t pic_width, uint16_t pic_height) { |
70 | 448 | uint32_t num_elements = (pic_width >> MI_SIZE_LOG2) * (pic_height >> MI_SIZE_LOG2); |
71 | | |
72 | 448 | seg_neighbor_map->dctor = segmentation_map_dctor; |
73 | | |
74 | 448 | seg_neighbor_map->map_size = num_elements; |
75 | 448 | EB_CALLOC_ARRAY(seg_neighbor_map->data, num_elements); |
76 | 448 | return EB_ErrorNone; |
77 | 448 | } |
78 | | |
79 | 0 | static void me_sb_results_dctor(EbPtr p) { |
80 | | // me_mv_array / me_candidate_array / total_me_candidate_index are borrowed from per-parent-PCS |
81 | | // pools (freed in the parent-PCS dctor). |
82 | 0 | (void)p; |
83 | 0 | } |
84 | | |
85 | | /* |
86 | | controls how many references are needed for ME results allocation |
87 | | */ |
88 | | void svt_aom_get_max_allocated_me_refs(uint8_t ref_count_used_list0, uint8_t ref_count_used_list1, |
89 | 448 | uint8_t* max_ref_to_alloc, uint8_t* max_cand_to_alloc) { |
90 | 448 | *max_ref_to_alloc = ref_count_used_list0 + ref_count_used_list1; |
91 | 448 | *max_cand_to_alloc = ref_count_used_list0 + ref_count_used_list1 + (ref_count_used_list0 * ref_count_used_list1) + |
92 | 448 | (ref_count_used_list0 - 1) + (ref_count_used_list1 == 3 ? 1 : 0); |
93 | 448 | } |
94 | | |
95 | | EbErrorType svt_aom_me_sb_results_ctor(MeSbResults* obj_ptr, PictureControlSetInitData* init_data_ptr, |
96 | 0 | MotionEstimationData* me_data, uint16_t sb_index, uint16_t all_sb) { |
97 | 0 | obj_ptr->dctor = me_sb_results_dctor; |
98 | |
|
99 | 0 | uint8_t max_ref_to_alloc, max_cand_to_alloc; |
100 | 0 | svt_aom_get_max_allocated_me_refs(init_data_ptr->ref_count_used_list0, |
101 | 0 | init_data_ptr->ref_count_used_list1, |
102 | 0 | &max_ref_to_alloc, |
103 | 0 | &max_cand_to_alloc); |
104 | 0 | ResolutionRange resolution; |
105 | 0 | svt_aom_derive_input_resolution(&resolution, init_data_ptr->picture_width * init_data_ptr->picture_height); |
106 | 0 | uint8_t number_of_pus = svt_aom_get_enable_me_16x16(init_data_ptr->enc_mode) |
107 | 0 | ? svt_aom_get_enable_me_8x8(init_data_ptr->enc_mode, resolution, init_data_ptr->static_config.rtc) |
108 | 0 | ? SQUARE_PU_COUNT |
109 | 0 | : MAX_SB64_PU_COUNT_NO_8X8 |
110 | 0 | : MAX_SB64_PU_COUNT_WO_16X16; |
111 | | |
112 | | // All SBs resolve to identical number_of_pus, so back the whole me_results array with one |
113 | | // allocation each (created on the first SB) and hand each SB a slice. |
114 | 0 | if (sb_index == 0) { |
115 | 0 | EB_MALLOC_ARRAY(me_data->me_sb_mv_pool, (size_t)all_sb * number_of_pus * max_ref_to_alloc); |
116 | 0 | EB_MALLOC_ARRAY(me_data->me_sb_cand_pool, (size_t)all_sb * number_of_pus * max_cand_to_alloc); |
117 | 0 | EB_MALLOC_ARRAY(me_data->me_sb_totidx_pool, (size_t)all_sb * number_of_pus); |
118 | 0 | } |
119 | 0 | obj_ptr->me_mv_array = me_data->me_sb_mv_pool + (size_t)sb_index * number_of_pus * max_ref_to_alloc; |
120 | 0 | obj_ptr->me_candidate_array = me_data->me_sb_cand_pool + (size_t)sb_index * number_of_pus * max_cand_to_alloc; |
121 | 0 | obj_ptr->total_me_candidate_index = me_data->me_sb_totidx_pool + (size_t)sb_index * number_of_pus; |
122 | 0 | return EB_ErrorNone; |
123 | 0 | } |
124 | | |
125 | 448 | void recon_coef_dctor(EbPtr p) { |
126 | 448 | EncDecSet* obj = (EncDecSet*)p; |
127 | 448 | EB_DELETE(obj->recon_pic_16bit); |
128 | 448 | EB_DELETE(obj->recon_pic); |
129 | | // quantized_coeff[] descriptors are borrowed from the pool; free the pool backing + |
130 | | // descriptor storage once, then the (alias) pointer array. |
131 | 448 | svt_aom_pic_buf_desc_pool_dctor(&obj->quantized_coeff_pool); |
132 | 448 | EB_FREE_ARRAY(obj->quantized_coeff); |
133 | 448 | } |
134 | | |
135 | 448 | static void picture_control_set_dctor(EbPtr p) { |
136 | 448 | PictureControlSet* obj = (PictureControlSet*)p; |
137 | 448 | uint16_t tile_cnt = obj->tile_row_count * obj->tile_column_count; |
138 | 448 | uint8_t depth; |
139 | 448 | svt_av1_hash_table_destroy(&obj->hash_table); |
140 | 448 | EB_FREE_ALIGNED_ARRAY(obj->tpl_mvs); |
141 | 448 | EB_DELETE_PTR_ARRAY(obj->enc_dec_segment_ctrl, tile_cnt); |
142 | 448 | EB_DELETE_PTR_ARRAY(obj->ep_luma_recon_na, tile_cnt); |
143 | 448 | EB_DELETE_PTR_ARRAY(obj->ep_cb_recon_na, tile_cnt); |
144 | 448 | EB_DELETE_PTR_ARRAY(obj->ep_cr_recon_na, tile_cnt); |
145 | 448 | EB_DELETE_PTR_ARRAY(obj->ep_luma_dc_sign_level_coeff_na, tile_cnt); |
146 | 448 | EB_DELETE_PTR_ARRAY(obj->ep_cb_dc_sign_level_coeff_na, tile_cnt); |
147 | 448 | EB_DELETE_PTR_ARRAY(obj->ep_cr_dc_sign_level_coeff_na, tile_cnt); |
148 | 448 | EB_DELETE_PTR_ARRAY(obj->ep_luma_dc_sign_level_coeff_na_update, tile_cnt); |
149 | 448 | EB_DELETE_PTR_ARRAY(obj->ep_cb_dc_sign_level_coeff_na_update, tile_cnt); |
150 | 448 | EB_DELETE_PTR_ARRAY(obj->ep_cr_dc_sign_level_coeff_na_update, tile_cnt); |
151 | 448 | EB_DELETE_PTR_ARRAY(obj->partition_context_na, tile_cnt); |
152 | 448 | EB_DELETE_PTR_ARRAY(obj->luma_dc_sign_level_coeff_na, tile_cnt); |
153 | 448 | EB_DELETE_PTR_ARRAY(obj->cr_dc_sign_level_coeff_na, tile_cnt); |
154 | 448 | EB_DELETE_PTR_ARRAY(obj->cb_dc_sign_level_coeff_na, tile_cnt); |
155 | 448 | EB_DELETE_PTR_ARRAY(obj->txfm_context_array, tile_cnt); |
156 | 448 | EB_DELETE(obj->segmentation_neighbor_map); // Jing, double check here |
157 | 448 | EB_DELETE_PTR_ARRAY(obj->ep_luma_recon_na_16bit, tile_cnt); |
158 | 448 | EB_DELETE_PTR_ARRAY(obj->ep_cb_recon_na_16bit, tile_cnt); |
159 | 448 | EB_DELETE_PTR_ARRAY(obj->ep_cr_recon_na_16bit, tile_cnt); |
160 | | // EB_DELETE(obj->ep_partition_context_na); //Jing: Double check here |
161 | 448 | EB_DELETE_PTR_ARRAY(obj->ep_partition_context_na, tile_cnt); |
162 | 448 | EB_DELETE_PTR_ARRAY(obj->ep_txfm_context_na, tile_cnt); |
163 | | |
164 | 1.79k | for (depth = 0; depth < NA_TOT_CNT; depth++) { |
165 | 1.34k | EB_DELETE_PTR_ARRAY(obj->mdleaf_partition_na[depth], tile_cnt); |
166 | | |
167 | 1.34k | EB_DELETE_PTR_ARRAY(obj->md_luma_recon_na_16bit[depth], tile_cnt); |
168 | 1.34k | EB_DELETE_PTR_ARRAY(obj->md_tx_depth_1_luma_recon_na_16bit[depth], tile_cnt); |
169 | 1.34k | EB_DELETE_PTR_ARRAY(obj->md_tx_depth_2_luma_recon_na_16bit[depth], tile_cnt); |
170 | 1.34k | EB_DELETE_PTR_ARRAY(obj->md_cb_recon_na_16bit[depth], tile_cnt); |
171 | 1.34k | EB_DELETE_PTR_ARRAY(obj->md_cr_recon_na_16bit[depth], tile_cnt); |
172 | | |
173 | 1.34k | EB_DELETE_PTR_ARRAY(obj->md_luma_recon_na[depth], tile_cnt); |
174 | 1.34k | EB_DELETE_PTR_ARRAY(obj->md_tx_depth_1_luma_recon_na[depth], tile_cnt); |
175 | 1.34k | EB_DELETE_PTR_ARRAY(obj->md_tx_depth_2_luma_recon_na[depth], tile_cnt); |
176 | 1.34k | EB_DELETE_PTR_ARRAY(obj->md_cb_recon_na[depth], tile_cnt); |
177 | 1.34k | EB_DELETE_PTR_ARRAY(obj->md_cr_recon_na[depth], tile_cnt); |
178 | | |
179 | 1.34k | EB_DELETE_PTR_ARRAY(obj->md_y_dcs_na[depth], tile_cnt); |
180 | 1.34k | EB_DELETE_PTR_ARRAY(obj->md_tx_depth_1_luma_dc_sign_level_coeff_na[depth], tile_cnt); |
181 | 1.34k | EB_DELETE_PTR_ARRAY(obj->md_cr_dc_sign_level_coeff_na[depth], tile_cnt); |
182 | 1.34k | EB_DELETE_PTR_ARRAY(obj->md_cb_dc_sign_level_coeff_na[depth], tile_cnt); |
183 | 1.34k | EB_DELETE_PTR_ARRAY(obj->md_txfm_context_array[depth], tile_cnt); |
184 | 1.34k | } |
185 | 448 | EB_DELETE_PTR_ARRAY(obj->sb_ptr_array, obj->sb_total_count_unscaled); |
186 | | // Per-SB pools backing the SuperBlock final_blk_arr / av1xd / ptree (borrowed by each SB). |
187 | 448 | EB_FREE_ARRAY(obj->sb_final_blk_arr_pool); |
188 | 448 | EB_FREE_ARRAY(obj->sb_av1xd_pool); |
189 | 448 | EB_FREE_ARRAY(obj->sb_ptree_pool); |
190 | 448 | EB_FREE_ARRAY(obj->sb_intra); |
191 | 448 | EB_FREE_ARRAY(obj->sb_skip); |
192 | 448 | EB_FREE_ARRAY(obj->sb_64x64_mvp); |
193 | 448 | EB_FREE_ARRAY(obj->b64_me_qindex); |
194 | 448 | EB_FREE_ARRAY(obj->sb_min_sq_size); |
195 | 448 | EB_FREE_ARRAY(obj->sb_max_sq_size); |
196 | 448 | EB_DELETE(obj->bitstream_ptr); |
197 | 448 | EB_DELETE_PTR_ARRAY(obj->ec_info, tile_cnt); |
198 | | |
199 | 448 | const int32_t num_planes = 3; // av1_num_planes(cm); |
200 | 1.79k | for (int32_t pl = 0; pl < num_planes; ++pl) { |
201 | 1.34k | RestorationInfo* ri = obj->rst_info + pl; |
202 | 1.34k | RestorationStripeBoundaries* boundaries = &ri->boundaries; |
203 | 1.34k | EB_FREE_ARRAY(ri->unit_info); |
204 | 1.34k | EB_FREE(boundaries->stripe_boundary_above); |
205 | 1.34k | EB_FREE(boundaries->stripe_boundary_below); |
206 | 1.34k | } |
207 | 448 | EB_FREE_ARRAY(obj->rusi_picture[0]); |
208 | 448 | EB_FREE_ARRAY(obj->rusi_picture[1]); |
209 | 448 | EB_FREE_ARRAY(obj->rusi_picture[2]); |
210 | 448 | EB_DELETE(obj->input_frame16bit); |
211 | | |
212 | 448 | EB_FREE_ARRAY(obj->mse_seg[0]); |
213 | 448 | EB_FREE_ARRAY(obj->mse_seg[1]); |
214 | 448 | EB_FREE_ARRAY(obj->skip_cdef_seg); |
215 | 448 | EB_FREE_ARRAY(obj->cdef_dir_data); |
216 | 448 | EB_FREE_ARRAY(obj->cdef_fb_list); |
217 | 448 | EB_FREE_ARRAY(obj->cdef_sb_index); |
218 | 448 | EB_FREE_ARRAY(obj->cdef_mse_ptr[0]); |
219 | 448 | EB_FREE_ARRAY(obj->cdef_mse_ptr[1]); |
220 | 448 | svt_aom_free(obj->cdef_row_cdef); |
221 | 1.79k | for (int cdef_p = 0; cdef_p < 3; cdef_p++) { |
222 | 1.34k | svt_aom_free(obj->cdef_linebuf[cdef_p]); |
223 | 1.34k | svt_aom_free(obj->cdef_colbuf[cdef_p]); |
224 | 1.34k | } |
225 | 448 | EB_FREE_ARRAY(obj->mi_grid_base); |
226 | 448 | EB_FREE_ARRAY(obj->mip); |
227 | 448 | EB_FREE_ARRAY(obj->md_rate_est_ctx); |
228 | 448 | EB_DESTROY_MUTEX(obj->entropy_coding_pic_mutex); |
229 | 448 | EB_DESTROY_MUTEX(obj->intra_mutex); |
230 | 448 | EB_DESTROY_MUTEX(obj->cdef_search_mutex); |
231 | 448 | EB_DESTROY_MUTEX(obj->rest_search_mutex); |
232 | 448 | } |
233 | | |
234 | | typedef struct InitData { |
235 | | NeighborArrayUnit** na_unit_dbl_ptr; |
236 | | uint32_t max_picture_width; |
237 | | uint32_t max_picture_height; |
238 | | uint32_t unit_size; |
239 | | uint8_t granularity_normal; |
240 | | uint8_t type_mask; |
241 | | } InitData; |
242 | | |
243 | 33.3k | #define DIM(array) (sizeof(array) / sizeof(array[0])) |
244 | | |
245 | 33.3k | static EbErrorType create_neighbor_array_units(InitData* data, size_t count) { |
246 | 267k | for (size_t i = 0; i < count; i++) { |
247 | 233k | EB_NEW(*data[i].na_unit_dbl_ptr, |
248 | 233k | svt_aom_neighbor_array_unit_ctor, |
249 | 233k | data[i].max_picture_width, |
250 | 233k | data[i].max_picture_height, |
251 | 233k | data[i].unit_size, |
252 | 233k | data[i].granularity_normal, |
253 | 233k | data[i].type_mask); |
254 | 233k | } |
255 | 33.3k | return EB_ErrorNone; |
256 | 33.3k | } |
257 | | |
258 | | /* |
259 | | recon_coef_update_param: update the parameters in EncDecSet for changing the resolution on the fly |
260 | | */ |
261 | 0 | EbErrorType recon_coef_update_param(EncDecSet* object_ptr, SequenceControlSet* scs) { |
262 | 0 | EbPictureBufferDescInitData input_pic_buf_desc_init_data; |
263 | 0 | bool is_16bit = scs->encoder_bit_depth > 8 ? true : false; |
264 | | // Init Picture Init data |
265 | 0 | input_pic_buf_desc_init_data.max_width = scs->max_input_luma_width; |
266 | 0 | input_pic_buf_desc_init_data.max_height = scs->max_input_luma_height; |
267 | 0 | input_pic_buf_desc_init_data.bit_depth = scs->encoder_bit_depth; |
268 | 0 | input_pic_buf_desc_init_data.buffer_enable_mask = PICTURE_BUFFER_DESC_FULL_MASK; |
269 | 0 | input_pic_buf_desc_init_data.color_format = scs->static_config.encoder_color_format; |
270 | 0 | uint16_t padding = scs->sb_size + 32; |
271 | 0 | if (scs->static_config.superres_mode > SUPERRES_NONE || scs->static_config.resize_mode > RESIZE_NONE) { |
272 | 0 | padding += scs->sb_size; |
273 | 0 | } |
274 | 0 | input_pic_buf_desc_init_data.border = padding; |
275 | 0 | input_pic_buf_desc_init_data.split_mode = false; |
276 | | |
277 | | // Reconstructed Picture Buffer |
278 | 0 | if (is_16bit) { |
279 | 0 | svt_recon_picture_buffer_desc_update(object_ptr->recon_pic_16bit, (EbPtr)&input_pic_buf_desc_init_data); |
280 | 0 | svt_recon_picture_buffer_desc_update(object_ptr->recon_pic, (EbPtr)&input_pic_buf_desc_init_data); |
281 | 0 | } else { |
282 | 0 | svt_recon_picture_buffer_desc_update(object_ptr->recon_pic, (EbPtr)&input_pic_buf_desc_init_data); |
283 | 0 | if (scs->is_16bit_pipeline) { |
284 | 0 | input_pic_buf_desc_init_data.bit_depth = EB_SIXTEEN_BIT; |
285 | 0 | svt_recon_picture_buffer_desc_update(object_ptr->recon_pic_16bit, (EbPtr)&input_pic_buf_desc_init_data); |
286 | 0 | } |
287 | 0 | } |
288 | | |
289 | | // SB Array |
290 | 0 | object_ptr->b64_total_count = scs->b64_total_count; |
291 | |
|
292 | 0 | return EB_ErrorNone; |
293 | 0 | } |
294 | | |
295 | 448 | static EbErrorType recon_coef_ctor(EncDecSet* object_ptr, EbPtr object_init_data_ptr) { |
296 | 448 | PictureControlSetInitData* init_data_ptr = (PictureControlSetInitData*)object_init_data_ptr; |
297 | | |
298 | 448 | EbPictureBufferDescInitData input_pic_buf_desc_init_data; |
299 | | |
300 | 448 | uint16_t sb_index; |
301 | 448 | bool is_16bit = init_data_ptr->bit_depth > 8 ? true : false; |
302 | | |
303 | | //object_ptr->tile_row_count = init_data_ptr->tile_row_count; |
304 | | //object_ptr->tile_column_count = init_data_ptr->tile_column_count; |
305 | | |
306 | 448 | object_ptr->dctor = recon_coef_dctor; |
307 | | |
308 | | // Init Picture Init data |
309 | 448 | input_pic_buf_desc_init_data.max_width = init_data_ptr->picture_width; |
310 | 448 | input_pic_buf_desc_init_data.max_height = init_data_ptr->picture_height; |
311 | 448 | input_pic_buf_desc_init_data.bit_depth = init_data_ptr->bit_depth; |
312 | 448 | input_pic_buf_desc_init_data.buffer_enable_mask = PICTURE_BUFFER_DESC_FULL_MASK; |
313 | 448 | input_pic_buf_desc_init_data.color_format = init_data_ptr->color_format; |
314 | 448 | uint16_t padding = init_data_ptr->sb_size + 32; |
315 | 448 | if (init_data_ptr->is_scale) { |
316 | 0 | padding += init_data_ptr->sb_size; |
317 | 0 | } |
318 | 448 | input_pic_buf_desc_init_data.border = padding; |
319 | 448 | input_pic_buf_desc_init_data.split_mode = false; |
320 | | |
321 | 448 | object_ptr->recon_pic_16bit = NULL; |
322 | 448 | object_ptr->recon_pic = NULL; // OMK |
323 | | // object_ptr->color_format = init_data_ptr->color_format; |
324 | | // Reconstructed Picture Buffer |
325 | 448 | if (is_16bit) { |
326 | 0 | EB_NEW(object_ptr->recon_pic_16bit, svt_recon_picture_buffer_desc_ctor, (EbPtr)&input_pic_buf_desc_init_data); |
327 | | // Need 8bit NREF recon buffer if bypassing EncDec when using 8bit MD to store RECON for |
328 | | // NREF picture INTRA prediction |
329 | | // TODO: Copy to a local buffer in MD instead |
330 | 0 | EB_NEW(object_ptr->recon_pic, svt_recon_picture_buffer_desc_ctor, (EbPtr)&input_pic_buf_desc_init_data); |
331 | 448 | } else { |
332 | 448 | EB_NEW(object_ptr->recon_pic, // OMK |
333 | 448 | svt_recon_picture_buffer_desc_ctor, |
334 | 448 | (EbPtr)&input_pic_buf_desc_init_data); |
335 | 448 | if (init_data_ptr->is_16bit_pipeline) { |
336 | 0 | input_pic_buf_desc_init_data.bit_depth = EB_SIXTEEN_BIT; |
337 | 0 | EB_NEW( |
338 | 0 | object_ptr->recon_pic_16bit, svt_recon_picture_buffer_desc_ctor, (EbPtr)&input_pic_buf_desc_init_data); |
339 | 0 | } |
340 | 448 | } |
341 | | |
342 | | // SB Array |
343 | 448 | const uint16_t picture_b64_width = (uint16_t)DIVIDE_AND_CEIL(init_data_ptr->picture_width, init_data_ptr->b64_size); |
344 | 448 | const uint16_t picture_b64_height = (uint16_t)DIVIDE_AND_CEIL(init_data_ptr->picture_height, |
345 | 448 | init_data_ptr->b64_size); |
346 | 448 | object_ptr->b64_total_count = picture_b64_width * picture_b64_height; |
347 | 448 | object_ptr->init_b64_total_count = object_ptr->b64_total_count; |
348 | 448 | EB_ALLOC_PTR_ARRAY(object_ptr->quantized_coeff, object_ptr->init_b64_total_count); |
349 | | |
350 | | //object_ptr->sb_total_count_pix = all_sb; |
351 | | |
352 | 448 | EbPictureBufferDescInitData coeff_init_data; |
353 | 448 | coeff_init_data.buffer_enable_mask = PICTURE_BUFFER_DESC_FULL_MASK; |
354 | 448 | coeff_init_data.max_width = init_data_ptr->sb_size; |
355 | 448 | coeff_init_data.max_height = init_data_ptr->sb_size; |
356 | 448 | coeff_init_data.bit_depth = EB_THIRTYTWO_BIT; |
357 | 448 | coeff_init_data.color_format = init_data_ptr->color_format; |
358 | 448 | coeff_init_data.border = 0; |
359 | 448 | coeff_init_data.split_mode = false; |
360 | 448 | coeff_init_data.is_16bit_pipeline = init_data_ptr->is_16bit_pipeline; |
361 | | // One backing allocation for all per-SB coeff descriptors (was one alloc per SB). |
362 | 448 | EbErrorType pool_err = svt_aom_pic_buf_desc_pool_ctor( |
363 | 448 | &object_ptr->quantized_coeff_pool, &coeff_init_data, object_ptr->init_b64_total_count); |
364 | 448 | if (pool_err != EB_ErrorNone) { |
365 | 0 | return pool_err; |
366 | 0 | } |
367 | 6.38k | for (sb_index = 0; sb_index < object_ptr->init_b64_total_count; ++sb_index) { |
368 | 5.93k | object_ptr->quantized_coeff[sb_index] = &object_ptr->quantized_coeff_pool.descs[sb_index]; |
369 | 5.93k | } |
370 | | |
371 | 448 | return EB_ErrorNone; |
372 | 448 | } |
373 | | |
374 | 448 | uint32_t svt_aom_get_out_buffer_size(uint32_t picture_width, uint32_t picture_height) { |
375 | | // Compressed frames are far smaller than the raw 4:2:0 frame, so start the bitstream |
376 | | // capacity at raw/4. The entropy writer grows on demand if a (pathological, very low-QP) |
377 | | // frame ever exceeds it, so this stays correct while cutting the previous over-provisioning. |
378 | 448 | return picture_width * picture_height * 3 / 2 / 4; // raw 4:2:0 frame size / 4 |
379 | 448 | } |
380 | | |
381 | | /* |
382 | | pcs_update_param: update the parameters in PictureParentControlSet for changing the resolution on the fly |
383 | | */ |
384 | 0 | EbErrorType pcs_update_param(PictureControlSet* pcs, int8_t enc_mode) { |
385 | 0 | SequenceControlSet* scs = pcs->scs; |
386 | 0 | const bool rtc_tune = scs->static_config.rtc; |
387 | 0 | const bool allintra = scs->allintra; |
388 | | // Max/Min CU Sizes |
389 | 0 | const uint32_t max_blk_size = scs->super_block_size; |
390 | | // SBs |
391 | 0 | uint16_t sb_index; |
392 | 0 | uint16_t sb_origin_x; |
393 | 0 | uint16_t sb_origin_y; |
394 | |
|
395 | 0 | bool is_16bit = scs->encoder_bit_depth > 8 ? true : false; |
396 | | // Init Picture Init data |
397 | 0 | EbPictureBufferDescInitData coeff_buffer_desc_init_data; |
398 | 0 | uint16_t padding = scs->super_block_size + 32; |
399 | |
|
400 | 0 | coeff_buffer_desc_init_data.max_width = scs->max_input_luma_width; |
401 | 0 | coeff_buffer_desc_init_data.max_height = scs->max_input_luma_height; |
402 | 0 | coeff_buffer_desc_init_data.bit_depth = EB_SIXTEEN_BIT; |
403 | 0 | coeff_buffer_desc_init_data.buffer_enable_mask = PICTURE_BUFFER_DESC_FULL_MASK; |
404 | 0 | coeff_buffer_desc_init_data.color_format = scs->static_config.encoder_color_format; |
405 | |
|
406 | 0 | coeff_buffer_desc_init_data.border = padding; |
407 | 0 | coeff_buffer_desc_init_data.split_mode = false; |
408 | 0 | coeff_buffer_desc_init_data.is_16bit_pipeline = scs->is_16bit_pipeline; |
409 | 0 | if ((is_16bit) || (scs->is_16bit_pipeline)) { |
410 | 0 | svt_picture_buffer_desc_update(pcs->input_frame16bit, (EbPtr)&coeff_buffer_desc_init_data); |
411 | 0 | } |
412 | 0 | if (allintra ? svt_aom_get_enable_restoration_allintra(enc_mode, scs->static_config.enable_restoration_filtering) |
413 | 0 | : rtc_tune ? svt_aom_get_enable_restoration_rtc(scs->static_config.enable_restoration_filtering, |
414 | 0 | scs->input_resolution, |
415 | 0 | scs->static_config.fast_decode) |
416 | 0 | : svt_aom_get_enable_restoration_default(enc_mode, |
417 | 0 | scs->static_config.enable_restoration_filtering, |
418 | 0 | scs->input_resolution, |
419 | 0 | scs->static_config.fast_decode)) { |
420 | 0 | set_restoration_unit_size(scs->max_input_luma_width, scs->max_input_luma_height, 1, 1, pcs->rst_info); |
421 | 0 | } |
422 | 0 | pcs->frame_width = scs->max_input_luma_width; |
423 | 0 | pcs->frame_height = scs->max_input_luma_height; |
424 | | // SB Array |
425 | 0 | pcs->b64_total_count = scs->b64_total_count; |
426 | 0 | sb_origin_x = 0; |
427 | 0 | sb_origin_y = 0; |
428 | |
|
429 | 0 | const uint16_t picture_sb_w = (uint16_t)DIVIDE_AND_CEIL(scs->max_input_luma_width, scs->sb_size); |
430 | 0 | const uint16_t picture_sb_h = (uint16_t)DIVIDE_AND_CEIL(scs->max_input_luma_height, scs->sb_size); |
431 | 0 | const uint16_t all_sb = picture_sb_w * picture_sb_h; |
432 | 0 | pcs->sb_total_count = scs->sb_total_count; |
433 | |
|
434 | 0 | for (sb_index = 0; sb_index < all_sb; ++sb_index) { |
435 | 0 | pcs->sb_ptr_array[sb_index]->org_x = (uint16_t)(sb_origin_x * max_blk_size); |
436 | 0 | pcs->sb_ptr_array[sb_index]->org_y = (uint16_t)(sb_origin_y * max_blk_size); |
437 | |
|
438 | 0 | pcs->sb_ptr_array[sb_index]->index = sb_index; |
439 | | // Increment the Order in coding order (Raster Scan Order) |
440 | 0 | sb_origin_y = (sb_origin_x == picture_sb_w - 1) ? sb_origin_y + 1 : sb_origin_y; |
441 | 0 | sb_origin_x = (sb_origin_x == picture_sb_w - 1) ? 0 : sb_origin_x + 1; |
442 | 0 | } |
443 | |
|
444 | 0 | uint32_t mi_stride = picture_sb_w * (scs->sb_size >> MI_SIZE_LOG2); |
445 | 0 | for (uint16_t mi_h = 0; mi_h < picture_sb_h * (scs->sb_size >> MI_SIZE_LOG2); mi_h++) { |
446 | 0 | for (uint16_t mi_w = 0; mi_w < picture_sb_w * (scs->sb_size >> MI_SIZE_LOG2); mi_w++) { |
447 | 0 | uint16_t mi_grid_idx = mi_h * mi_stride + mi_w; |
448 | 0 | uint16_t mip_idx = (mi_h >> (pcs->disallow_4x4_all_frames + pcs->disallow_8x8_all_frames)) * |
449 | 0 | (mi_stride >> (pcs->disallow_4x4_all_frames + pcs->disallow_8x8_all_frames)) + |
450 | 0 | (mi_w >> (pcs->disallow_4x4_all_frames + pcs->disallow_8x8_all_frames)); |
451 | 0 | pcs->mi_grid_base[mi_grid_idx] = pcs->mip + mip_idx; |
452 | 0 | } |
453 | 0 | } |
454 | 0 | pcs->mi_stride = picture_sb_w * (scs->sb_size >> MI_SIZE_LOG2); |
455 | 0 | return EB_ErrorNone; |
456 | 0 | } |
457 | | |
458 | 448 | static EbErrorType picture_control_set_ctor(PictureControlSet* object_ptr, EbPtr object_init_data_ptr) { |
459 | 448 | PictureControlSetInitData* init_data_ptr = (PictureControlSetInitData*)object_init_data_ptr; |
460 | | |
461 | 448 | const bool allintra = init_data_ptr->allintra; |
462 | 448 | const bool rtc_tune = init_data_ptr->rtc_tune; |
463 | 448 | EbPictureBufferDescInitData coeff_buffer_desc_init_data; |
464 | | |
465 | | // Max/Min CU Sizes |
466 | 448 | const uint32_t max_blk_size = init_data_ptr->sb_size; |
467 | 448 | uint16_t sb_index; |
468 | 448 | uint16_t sb_origin_x; |
469 | 448 | uint16_t sb_origin_y; |
470 | 448 | EbErrorType return_error; |
471 | | |
472 | 448 | bool is_16bit = init_data_ptr->bit_depth > 8 ? true : false; |
473 | 448 | const uint16_t subsampling_x = (init_data_ptr->color_format == EB_YUV444 ? 0 : 1); |
474 | 448 | const uint16_t subsampling_y = (init_data_ptr->color_format >= EB_YUV422 ? 0 : 1); |
475 | | |
476 | 448 | uint32_t total_tile_cnt = init_data_ptr->tile_row_count * init_data_ptr->tile_column_count; |
477 | 448 | uint32_t tile_idx = 0; |
478 | | |
479 | 448 | uint32_t output_buffer_size = svt_aom_get_out_buffer_size(init_data_ptr->picture_width, |
480 | 448 | init_data_ptr->picture_height); |
481 | 448 | object_ptr->frame_width = init_data_ptr->picture_width; |
482 | 448 | object_ptr->frame_height = init_data_ptr->picture_height; |
483 | 448 | object_ptr->tile_row_count = init_data_ptr->tile_row_count; |
484 | 448 | object_ptr->tile_column_count = init_data_ptr->tile_column_count; |
485 | | |
486 | 448 | object_ptr->dctor = picture_control_set_dctor; |
487 | | |
488 | 448 | object_ptr->hash_table.p_lookup_table = NULL; |
489 | | |
490 | | // Init Picture Init data |
491 | 448 | uint16_t padding = init_data_ptr->sb_size + 32; |
492 | | |
493 | 448 | coeff_buffer_desc_init_data.max_width = init_data_ptr->picture_width; |
494 | 448 | coeff_buffer_desc_init_data.max_height = init_data_ptr->picture_height; |
495 | 448 | coeff_buffer_desc_init_data.bit_depth = EB_SIXTEEN_BIT; |
496 | 448 | coeff_buffer_desc_init_data.buffer_enable_mask = PICTURE_BUFFER_DESC_FULL_MASK; |
497 | 448 | coeff_buffer_desc_init_data.color_format = init_data_ptr->color_format; |
498 | | |
499 | 448 | coeff_buffer_desc_init_data.border = padding; |
500 | 448 | coeff_buffer_desc_init_data.split_mode = false; |
501 | 448 | coeff_buffer_desc_init_data.is_16bit_pipeline = init_data_ptr->is_16bit_pipeline; |
502 | 448 | object_ptr->color_format = init_data_ptr->color_format; |
503 | 448 | object_ptr->temp_lf_recon_pic_16bit = NULL; |
504 | 448 | object_ptr->temp_lf_recon_pic = NULL; |
505 | 448 | object_ptr->scaled_input_pic = NULL; |
506 | 448 | bool enable_restoration = allintra |
507 | 448 | ? svt_aom_get_enable_restoration_allintra(init_data_ptr->enc_mode, |
508 | 448 | init_data_ptr->static_config.enable_restoration_filtering) |
509 | 448 | : rtc_tune ? svt_aom_get_enable_restoration_rtc(init_data_ptr->static_config.enable_restoration_filtering, |
510 | 0 | init_data_ptr->input_resolution, |
511 | 0 | init_data_ptr->static_config.fast_decode) |
512 | 0 | : svt_aom_get_enable_restoration_default(init_data_ptr->enc_mode, |
513 | 0 | init_data_ptr->static_config.enable_restoration_filtering, |
514 | 0 | init_data_ptr->input_resolution, |
515 | 0 | init_data_ptr->static_config.fast_decode); |
516 | 448 | if (enable_restoration) { |
517 | 0 | set_restoration_unit_size( |
518 | 0 | init_data_ptr->picture_width, init_data_ptr->picture_height, 1, 1, object_ptr->rst_info); |
519 | |
|
520 | 0 | if (svt_av1_alloc_restoration_buffers(object_ptr, init_data_ptr->av1_cm) != EB_ErrorNone) { |
521 | 0 | return EB_ErrorInsufficientResources; |
522 | 0 | } |
523 | | |
524 | 0 | int32_t ntiles[2]; |
525 | 0 | for (int32_t is_uv = 0; is_uv < 2; ++is_uv) { |
526 | 0 | ntiles[is_uv] = object_ptr->rst_info[is_uv].units_per_tile; //CHKN res_tiles_in_plane |
527 | 0 | } |
528 | 0 | assert(ntiles[1] <= ntiles[0]); |
529 | 0 | EB_CALLOC_ARRAY(object_ptr->rusi_picture[0], ntiles[0]); |
530 | 0 | EB_CALLOC_ARRAY(object_ptr->rusi_picture[1], ntiles[1]); |
531 | 0 | EB_CALLOC_ARRAY(object_ptr->rusi_picture[2], ntiles[1]); |
532 | 0 | } |
533 | | |
534 | 448 | if ((is_16bit) || (init_data_ptr->is_16bit_pipeline)) { |
535 | 0 | EB_NEW(object_ptr->input_frame16bit, svt_picture_buffer_desc_ctor, (EbPtr)&coeff_buffer_desc_init_data); |
536 | 0 | } |
537 | | // Entropy Coder |
538 | 448 | EB_ALLOC_PTR_ARRAY(object_ptr->ec_info, total_tile_cnt); |
539 | 5.21k | for (tile_idx = 0; tile_idx < total_tile_cnt; tile_idx++) { |
540 | 4.76k | EB_NEW(object_ptr->ec_info[tile_idx], svt_aom_entropy_tile_info_ctor, output_buffer_size / total_tile_cnt); |
541 | 4.76k | } |
542 | | |
543 | | // Packetization process Bitstream |
544 | 448 | EB_NEW(object_ptr->bitstream_ptr, svt_aom_bitstream_ctor, output_buffer_size); |
545 | | |
546 | | // GOP |
547 | 448 | object_ptr->picture_number = 0; |
548 | 448 | object_ptr->temporal_layer_index = 0; |
549 | | |
550 | | // SB Array |
551 | 448 | const uint16_t picture_b64_width = (uint16_t)DIVIDE_AND_CEIL(init_data_ptr->picture_width, init_data_ptr->b64_size); |
552 | 448 | const uint16_t picture_b64_height = (uint16_t)DIVIDE_AND_CEIL(init_data_ptr->picture_height, |
553 | 448 | init_data_ptr->b64_size); |
554 | 448 | object_ptr->b64_total_count = picture_b64_width * picture_b64_height; |
555 | 448 | object_ptr->init_b64_total_count = object_ptr->b64_total_count; |
556 | 448 | EB_MALLOC_ARRAY(object_ptr->sb_64x64_mvp, object_ptr->init_b64_total_count); |
557 | 448 | EB_MALLOC_ARRAY(object_ptr->b64_me_qindex, object_ptr->init_b64_total_count); |
558 | 448 | if (!allintra) { |
559 | 0 | EB_MALLOC_ARRAY(object_ptr->sb_intra, object_ptr->init_b64_total_count); |
560 | 0 | EB_MALLOC_ARRAY(object_ptr->sb_skip, object_ptr->init_b64_total_count); |
561 | 0 | EB_MALLOC_ARRAY(object_ptr->sb_min_sq_size, object_ptr->init_b64_total_count); |
562 | 0 | EB_MALLOC_ARRAY(object_ptr->sb_max_sq_size, object_ptr->init_b64_total_count); |
563 | 0 | } |
564 | 448 | sb_origin_x = 0; |
565 | 448 | sb_origin_y = 0; |
566 | | |
567 | 448 | const uint16_t picture_sb_w = (uint16_t)DIVIDE_AND_CEIL(init_data_ptr->picture_width, init_data_ptr->sb_size); |
568 | 448 | const uint16_t picture_sb_h = (uint16_t)DIVIDE_AND_CEIL(init_data_ptr->picture_height, init_data_ptr->sb_size); |
569 | 448 | const uint16_t all_sb = picture_sb_w * picture_sb_h; |
570 | | |
571 | 448 | object_ptr->sb_total_count = all_sb; |
572 | 448 | object_ptr->sb_total_count_unscaled = all_sb; |
573 | 448 | EB_ALLOC_PTR_ARRAY(object_ptr->sb_ptr_array, object_ptr->sb_total_count_unscaled); |
574 | 6.38k | for (sb_index = 0; sb_index < all_sb; ++sb_index) { |
575 | 5.93k | EB_NEW(object_ptr->sb_ptr_array[sb_index], |
576 | 5.93k | svt_aom_largest_coding_unit_ctor, |
577 | 5.93k | (uint8_t)init_data_ptr->sb_size, |
578 | 5.93k | (uint16_t)(sb_origin_x * max_blk_size), |
579 | 5.93k | (uint16_t)(sb_origin_y * max_blk_size), |
580 | 5.93k | (uint16_t)sb_index, |
581 | 5.93k | init_data_ptr->enc_mode, |
582 | 5.93k | init_data_ptr->static_config.rtc, |
583 | 5.93k | allintra, |
584 | 5.93k | object_ptr); |
585 | | |
586 | | // Increment the Order in coding order (Raster Scan Order) |
587 | 5.93k | sb_origin_y = (sb_origin_x == picture_sb_w - 1) ? sb_origin_y + 1 : sb_origin_y; |
588 | 5.93k | sb_origin_x = (sb_origin_x == picture_sb_w - 1) ? 0 : sb_origin_x + 1; |
589 | 5.93k | } |
590 | | // MD Rate Estimation Array |
591 | 448 | EB_MALLOC_ARRAY(object_ptr->md_rate_est_ctx, 1); |
592 | 448 | memset(object_ptr->md_rate_est_ctx, 0, sizeof(MdRateEstimationContext)); |
593 | 448 | if (init_data_ptr->hbd_md == DEFAULT) { |
594 | 0 | object_ptr->hbd_md = init_data_ptr->hbd_md = 2; |
595 | 448 | } else { |
596 | 448 | object_ptr->hbd_md = init_data_ptr->hbd_md; |
597 | 448 | } |
598 | | // Mode Decision Neighbor Arrays |
599 | 448 | uint8_t depth; |
600 | 1.79k | for (depth = 0; depth < NA_TOT_CNT; depth++) { |
601 | 1.34k | EB_ALLOC_PTR_ARRAY(object_ptr->mdleaf_partition_na[depth], total_tile_cnt); |
602 | 1.34k | EB_ALLOC_PTR_ARRAY(object_ptr->md_y_dcs_na[depth], total_tile_cnt); |
603 | 1.34k | EB_ALLOC_PTR_ARRAY(object_ptr->md_tx_depth_1_luma_dc_sign_level_coeff_na[depth], total_tile_cnt); |
604 | 1.34k | EB_ALLOC_PTR_ARRAY(object_ptr->md_cr_dc_sign_level_coeff_na[depth], total_tile_cnt); |
605 | 1.34k | EB_ALLOC_PTR_ARRAY(object_ptr->md_cb_dc_sign_level_coeff_na[depth], total_tile_cnt); |
606 | 1.34k | EB_ALLOC_PTR_ARRAY(object_ptr->md_txfm_context_array[depth], total_tile_cnt); |
607 | 1.34k | if (init_data_ptr->hbd_md != EB_10_BIT_MD) { |
608 | 1.34k | EB_ALLOC_PTR_ARRAY(object_ptr->md_luma_recon_na[depth], total_tile_cnt); |
609 | 1.34k | EB_ALLOC_PTR_ARRAY(object_ptr->md_tx_depth_1_luma_recon_na[depth], total_tile_cnt); |
610 | 1.34k | EB_ALLOC_PTR_ARRAY(object_ptr->md_tx_depth_2_luma_recon_na[depth], total_tile_cnt); |
611 | 1.34k | EB_ALLOC_PTR_ARRAY(object_ptr->md_cb_recon_na[depth], total_tile_cnt); |
612 | 1.34k | EB_ALLOC_PTR_ARRAY(object_ptr->md_cr_recon_na[depth], total_tile_cnt); |
613 | 1.34k | } |
614 | 1.34k | if (init_data_ptr->hbd_md > EB_8_BIT_MD) { |
615 | 0 | EB_ALLOC_PTR_ARRAY(object_ptr->md_luma_recon_na_16bit[depth], total_tile_cnt); |
616 | 0 | EB_ALLOC_PTR_ARRAY(object_ptr->md_tx_depth_1_luma_recon_na_16bit[depth], total_tile_cnt); |
617 | 0 | EB_ALLOC_PTR_ARRAY(object_ptr->md_tx_depth_2_luma_recon_na_16bit[depth], total_tile_cnt); |
618 | 0 | EB_ALLOC_PTR_ARRAY(object_ptr->md_cb_recon_na_16bit[depth], total_tile_cnt); |
619 | 0 | EB_ALLOC_PTR_ARRAY(object_ptr->md_cr_recon_na_16bit[depth], total_tile_cnt); |
620 | 0 | } |
621 | 1.34k | } |
622 | | |
623 | 448 | const uint32_t na_max_pic_w = init_data_ptr->picture_width + 2 * BLOCK_SIZE_64; |
624 | 448 | const uint32_t na_max_pic_h = init_data_ptr->picture_height + 2 * BLOCK_SIZE_64; |
625 | | |
626 | 5.21k | for (tile_idx = 0; tile_idx < total_tile_cnt; tile_idx++) { |
627 | 19.0k | for (depth = 0; depth < NA_TOT_CNT; depth++) { |
628 | 14.3k | InitData data0[] = { |
629 | 14.3k | { |
630 | 14.3k | &object_ptr->mdleaf_partition_na[depth][tile_idx], |
631 | 14.3k | na_max_pic_w, |
632 | 14.3k | na_max_pic_h, |
633 | 14.3k | sizeof(PartitionContextType), |
634 | 14.3k | PU_NEIGHBOR_ARRAY_GRANULARITY, |
635 | 14.3k | NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK, |
636 | 14.3k | }, |
637 | | // for each 4x4 |
638 | 14.3k | { |
639 | 14.3k | &object_ptr->md_y_dcs_na[depth][tile_idx], |
640 | 14.3k | na_max_pic_w, |
641 | 14.3k | na_max_pic_h, |
642 | 14.3k | sizeof(uint8_t), |
643 | 14.3k | PU_NEIGHBOR_ARRAY_GRANULARITY, |
644 | 14.3k | NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK, |
645 | 14.3k | }, |
646 | | // for each 4x4 |
647 | 14.3k | { |
648 | 14.3k | &object_ptr->md_tx_depth_1_luma_dc_sign_level_coeff_na[depth][tile_idx], |
649 | 14.3k | na_max_pic_w, |
650 | 14.3k | na_max_pic_h, |
651 | 14.3k | sizeof(uint8_t), |
652 | 14.3k | PU_NEIGHBOR_ARRAY_GRANULARITY, |
653 | 14.3k | NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK, |
654 | 14.3k | }, |
655 | | // for each 4x4 |
656 | 14.3k | { |
657 | 14.3k | &object_ptr->md_cr_dc_sign_level_coeff_na[depth][tile_idx], |
658 | 14.3k | na_max_pic_w, |
659 | 14.3k | na_max_pic_h, |
660 | 14.3k | sizeof(uint8_t), |
661 | 14.3k | PU_NEIGHBOR_ARRAY_GRANULARITY, |
662 | 14.3k | NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK, |
663 | 14.3k | }, |
664 | | // for each 4x4 |
665 | 14.3k | { |
666 | 14.3k | &object_ptr->md_cb_dc_sign_level_coeff_na[depth][tile_idx], |
667 | 14.3k | na_max_pic_w, |
668 | 14.3k | na_max_pic_h, |
669 | 14.3k | sizeof(uint8_t), |
670 | 14.3k | PU_NEIGHBOR_ARRAY_GRANULARITY, |
671 | 14.3k | NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK, |
672 | 14.3k | }, |
673 | 14.3k | { |
674 | 14.3k | &object_ptr->md_txfm_context_array[depth][tile_idx], |
675 | 14.3k | na_max_pic_w, |
676 | 14.3k | na_max_pic_h, |
677 | 14.3k | sizeof(TXFM_CONTEXT), |
678 | 14.3k | PU_NEIGHBOR_ARRAY_GRANULARITY, |
679 | 14.3k | NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK, |
680 | 14.3k | }, |
681 | 14.3k | }; |
682 | 14.3k | return_error = create_neighbor_array_units(data0, DIM(data0)); |
683 | 14.3k | if (return_error == EB_ErrorInsufficientResources) { |
684 | 0 | return EB_ErrorInsufficientResources; |
685 | 0 | } |
686 | 14.3k | if (init_data_ptr->hbd_md != EB_10_BIT_MD) { |
687 | 14.3k | InitData data[] = { |
688 | | |
689 | 14.3k | { |
690 | 14.3k | &object_ptr->md_luma_recon_na[depth][tile_idx], |
691 | 14.3k | na_max_pic_w, |
692 | 14.3k | na_max_pic_h, |
693 | 14.3k | sizeof(uint8_t), |
694 | 14.3k | SAMPLE_NEIGHBOR_ARRAY_GRANULARITY, |
695 | 14.3k | NEIGHBOR_ARRAY_UNIT_FULL_MASK, |
696 | 14.3k | }, |
697 | 14.3k | { |
698 | 14.3k | &object_ptr->md_tx_depth_1_luma_recon_na[depth][tile_idx], |
699 | 14.3k | na_max_pic_w, |
700 | 14.3k | na_max_pic_h, |
701 | 14.3k | sizeof(uint8_t), |
702 | 14.3k | SAMPLE_NEIGHBOR_ARRAY_GRANULARITY, |
703 | 14.3k | NEIGHBOR_ARRAY_UNIT_FULL_MASK, |
704 | 14.3k | }, |
705 | 14.3k | { |
706 | 14.3k | &object_ptr->md_tx_depth_2_luma_recon_na[depth][tile_idx], |
707 | 14.3k | na_max_pic_w, |
708 | 14.3k | na_max_pic_h, |
709 | 14.3k | sizeof(uint8_t), |
710 | 14.3k | SAMPLE_NEIGHBOR_ARRAY_GRANULARITY, |
711 | 14.3k | NEIGHBOR_ARRAY_UNIT_FULL_MASK, |
712 | 14.3k | }, |
713 | 14.3k | { |
714 | 14.3k | &object_ptr->md_cb_recon_na[depth][tile_idx], |
715 | 14.3k | na_max_pic_w >> subsampling_x, |
716 | 14.3k | na_max_pic_h >> subsampling_y, |
717 | 14.3k | sizeof(uint8_t), |
718 | 14.3k | SAMPLE_NEIGHBOR_ARRAY_GRANULARITY, |
719 | 14.3k | NEIGHBOR_ARRAY_UNIT_FULL_MASK, |
720 | 14.3k | }, |
721 | 14.3k | { |
722 | 14.3k | &object_ptr->md_cr_recon_na[depth][tile_idx], |
723 | 14.3k | na_max_pic_w >> subsampling_x, |
724 | 14.3k | na_max_pic_h >> subsampling_y, |
725 | 14.3k | sizeof(uint8_t), |
726 | 14.3k | SAMPLE_NEIGHBOR_ARRAY_GRANULARITY, |
727 | 14.3k | NEIGHBOR_ARRAY_UNIT_FULL_MASK, |
728 | 14.3k | } |
729 | | |
730 | 14.3k | }; |
731 | 14.3k | return_error = create_neighbor_array_units(data, DIM(data)); |
732 | 14.3k | if (return_error == EB_ErrorInsufficientResources) { |
733 | 0 | return EB_ErrorInsufficientResources; |
734 | 0 | } |
735 | 14.3k | } |
736 | 14.3k | if (init_data_ptr->hbd_md > EB_8_BIT_MD) { |
737 | 0 | InitData data[] = {{ |
738 | 0 | &object_ptr->md_luma_recon_na_16bit[depth][tile_idx], |
739 | 0 | na_max_pic_w, |
740 | 0 | na_max_pic_h, |
741 | 0 | sizeof(uint16_t), |
742 | 0 | SAMPLE_NEIGHBOR_ARRAY_GRANULARITY, |
743 | 0 | NEIGHBOR_ARRAY_UNIT_FULL_MASK, |
744 | 0 | }, |
745 | 0 | { |
746 | 0 | &object_ptr->md_tx_depth_1_luma_recon_na_16bit[depth][tile_idx], |
747 | 0 | na_max_pic_w, |
748 | 0 | na_max_pic_h, |
749 | 0 | sizeof(uint16_t), |
750 | 0 | SAMPLE_NEIGHBOR_ARRAY_GRANULARITY, |
751 | 0 | NEIGHBOR_ARRAY_UNIT_FULL_MASK, |
752 | 0 | }, |
753 | 0 | { |
754 | 0 | &object_ptr->md_tx_depth_2_luma_recon_na_16bit[depth][tile_idx], |
755 | 0 | na_max_pic_w, |
756 | 0 | na_max_pic_h, |
757 | 0 | sizeof(uint16_t), |
758 | 0 | SAMPLE_NEIGHBOR_ARRAY_GRANULARITY, |
759 | 0 | NEIGHBOR_ARRAY_UNIT_FULL_MASK, |
760 | 0 | }, |
761 | 0 | { |
762 | 0 | &object_ptr->md_cb_recon_na_16bit[depth][tile_idx], |
763 | 0 | na_max_pic_w >> subsampling_x, |
764 | 0 | na_max_pic_h >> subsampling_y, |
765 | 0 | sizeof(uint16_t), |
766 | 0 | SAMPLE_NEIGHBOR_ARRAY_GRANULARITY, |
767 | 0 | NEIGHBOR_ARRAY_UNIT_FULL_MASK, |
768 | 0 | }, |
769 | 0 | { |
770 | 0 | &object_ptr->md_cr_recon_na_16bit[depth][tile_idx], |
771 | 0 | na_max_pic_w >> subsampling_x, |
772 | 0 | na_max_pic_h >> subsampling_y, |
773 | 0 | sizeof(uint16_t), |
774 | 0 | SAMPLE_NEIGHBOR_ARRAY_GRANULARITY, |
775 | 0 | NEIGHBOR_ARRAY_UNIT_FULL_MASK, |
776 | 0 | }}; |
777 | 0 | return_error = create_neighbor_array_units(data, DIM(data)); |
778 | 0 | if (return_error == EB_ErrorInsufficientResources) { |
779 | 0 | return EB_ErrorInsufficientResources; |
780 | 0 | } |
781 | 0 | } |
782 | 14.3k | } |
783 | 4.76k | } |
784 | | // EncDec Neighbor |
785 | | //EncDec |
786 | 448 | EB_ALLOC_PTR_ARRAY(object_ptr->ep_luma_recon_na, total_tile_cnt); |
787 | 448 | EB_ALLOC_PTR_ARRAY(object_ptr->ep_cb_recon_na, total_tile_cnt); |
788 | 448 | EB_ALLOC_PTR_ARRAY(object_ptr->ep_cr_recon_na, total_tile_cnt); |
789 | 448 | EB_ALLOC_PTR_ARRAY(object_ptr->ep_luma_dc_sign_level_coeff_na, total_tile_cnt); |
790 | 448 | EB_ALLOC_PTR_ARRAY(object_ptr->ep_cb_dc_sign_level_coeff_na, total_tile_cnt); |
791 | 448 | EB_ALLOC_PTR_ARRAY(object_ptr->ep_cr_dc_sign_level_coeff_na, total_tile_cnt); |
792 | 448 | EB_ALLOC_PTR_ARRAY(object_ptr->ep_luma_dc_sign_level_coeff_na_update, total_tile_cnt); |
793 | 448 | EB_ALLOC_PTR_ARRAY(object_ptr->ep_cb_dc_sign_level_coeff_na_update, total_tile_cnt); |
794 | 448 | EB_ALLOC_PTR_ARRAY(object_ptr->ep_cr_dc_sign_level_coeff_na_update, total_tile_cnt); |
795 | 448 | EB_ALLOC_PTR_ARRAY(object_ptr->ep_partition_context_na, total_tile_cnt); |
796 | 448 | EB_ALLOC_PTR_ARRAY(object_ptr->ep_txfm_context_na, total_tile_cnt); |
797 | | // Entropy |
798 | 448 | EB_ALLOC_PTR_ARRAY(object_ptr->partition_context_na, total_tile_cnt); |
799 | 448 | EB_ALLOC_PTR_ARRAY(object_ptr->luma_dc_sign_level_coeff_na, total_tile_cnt); |
800 | 448 | EB_ALLOC_PTR_ARRAY(object_ptr->cr_dc_sign_level_coeff_na, total_tile_cnt); |
801 | 448 | EB_ALLOC_PTR_ARRAY(object_ptr->cb_dc_sign_level_coeff_na, total_tile_cnt); |
802 | 448 | EB_ALLOC_PTR_ARRAY(object_ptr->txfm_context_array, total_tile_cnt); |
803 | 448 | if ((is_16bit) || (init_data_ptr->is_16bit_pipeline)) { |
804 | 0 | EB_ALLOC_PTR_ARRAY(object_ptr->ep_luma_recon_na_16bit, total_tile_cnt); |
805 | 0 | EB_ALLOC_PTR_ARRAY(object_ptr->ep_cb_recon_na_16bit, total_tile_cnt); |
806 | 0 | EB_ALLOC_PTR_ARRAY(object_ptr->ep_cr_recon_na_16bit, total_tile_cnt); |
807 | 0 | } |
808 | | |
809 | 5.21k | for (tile_idx = 0; tile_idx < total_tile_cnt; tile_idx++) { |
810 | 4.76k | InitData data0[] = { |
811 | 4.76k | { |
812 | 4.76k | &object_ptr->ep_luma_recon_na[tile_idx], |
813 | 4.76k | na_max_pic_w, |
814 | 4.76k | na_max_pic_h, |
815 | 4.76k | sizeof(uint8_t), |
816 | 4.76k | SAMPLE_NEIGHBOR_ARRAY_GRANULARITY, |
817 | 4.76k | NEIGHBOR_ARRAY_UNIT_FULL_MASK, |
818 | 4.76k | }, |
819 | 4.76k | { |
820 | 4.76k | &object_ptr->ep_cb_recon_na[tile_idx], |
821 | 4.76k | na_max_pic_w >> subsampling_x, |
822 | 4.76k | na_max_pic_h >> subsampling_y, |
823 | 4.76k | sizeof(uint8_t), |
824 | 4.76k | SAMPLE_NEIGHBOR_ARRAY_GRANULARITY, |
825 | 4.76k | NEIGHBOR_ARRAY_UNIT_FULL_MASK, |
826 | 4.76k | }, |
827 | 4.76k | { |
828 | | |
829 | 4.76k | &object_ptr->ep_cr_recon_na[tile_idx], |
830 | 4.76k | na_max_pic_w >> subsampling_x, |
831 | 4.76k | na_max_pic_h >> subsampling_y, |
832 | 4.76k | sizeof(uint8_t), |
833 | 4.76k | SAMPLE_NEIGHBOR_ARRAY_GRANULARITY, |
834 | 4.76k | NEIGHBOR_ARRAY_UNIT_FULL_MASK, |
835 | 4.76k | }, |
836 | | // for each 4x4 |
837 | 4.76k | { |
838 | 4.76k | &object_ptr->ep_luma_dc_sign_level_coeff_na[tile_idx], |
839 | 4.76k | na_max_pic_w, |
840 | 4.76k | na_max_pic_h, |
841 | 4.76k | sizeof(uint8_t), |
842 | 4.76k | PU_NEIGHBOR_ARRAY_GRANULARITY, |
843 | 4.76k | NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK, |
844 | 4.76k | }, |
845 | | // for each 4x4 |
846 | 4.76k | { |
847 | 4.76k | &object_ptr->ep_cb_dc_sign_level_coeff_na[tile_idx], |
848 | 4.76k | na_max_pic_w, |
849 | 4.76k | na_max_pic_h, |
850 | 4.76k | sizeof(uint8_t), |
851 | 4.76k | PU_NEIGHBOR_ARRAY_GRANULARITY, |
852 | 4.76k | NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK, |
853 | 4.76k | }, |
854 | | // for each 4x4 |
855 | 4.76k | { |
856 | 4.76k | &object_ptr->ep_cr_dc_sign_level_coeff_na[tile_idx], |
857 | 4.76k | na_max_pic_w, |
858 | 4.76k | na_max_pic_h, |
859 | 4.76k | sizeof(uint8_t), |
860 | 4.76k | PU_NEIGHBOR_ARRAY_GRANULARITY, |
861 | 4.76k | NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK, |
862 | 4.76k | }, |
863 | | // for each 4x4 |
864 | 4.76k | { |
865 | 4.76k | &object_ptr->ep_luma_dc_sign_level_coeff_na_update[tile_idx], |
866 | 4.76k | na_max_pic_w, |
867 | 4.76k | na_max_pic_h, |
868 | 4.76k | sizeof(uint8_t), |
869 | 4.76k | PU_NEIGHBOR_ARRAY_GRANULARITY, |
870 | 4.76k | NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK, |
871 | 4.76k | }, |
872 | | // for each 4x4 |
873 | 4.76k | { |
874 | 4.76k | &object_ptr->ep_cb_dc_sign_level_coeff_na_update[tile_idx], |
875 | 4.76k | na_max_pic_w, |
876 | 4.76k | na_max_pic_h, |
877 | 4.76k | sizeof(uint8_t), |
878 | 4.76k | PU_NEIGHBOR_ARRAY_GRANULARITY, |
879 | 4.76k | NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK, |
880 | 4.76k | }, |
881 | | // for each 4x4 |
882 | 4.76k | { |
883 | 4.76k | &object_ptr->ep_cr_dc_sign_level_coeff_na_update[tile_idx], |
884 | 4.76k | na_max_pic_w, |
885 | 4.76k | na_max_pic_h, |
886 | 4.76k | sizeof(uint8_t), |
887 | 4.76k | PU_NEIGHBOR_ARRAY_GRANULARITY, |
888 | 4.76k | NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK, |
889 | 4.76k | }, |
890 | | // Encode pass partition neighbor array |
891 | 4.76k | { |
892 | 4.76k | &object_ptr->ep_partition_context_na[tile_idx], |
893 | 4.76k | na_max_pic_w, |
894 | 4.76k | na_max_pic_h, |
895 | 4.76k | sizeof(PartitionContextType), |
896 | 4.76k | PU_NEIGHBOR_ARRAY_GRANULARITY, |
897 | 4.76k | NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK, |
898 | 4.76k | }, |
899 | | // Encode pass txfm neighbor array |
900 | 4.76k | { |
901 | 4.76k | &object_ptr->ep_txfm_context_na[tile_idx], |
902 | 4.76k | na_max_pic_w, |
903 | 4.76k | na_max_pic_h, |
904 | 4.76k | sizeof(TXFM_CONTEXT), |
905 | 4.76k | PU_NEIGHBOR_ARRAY_GRANULARITY, |
906 | 4.76k | NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK, |
907 | 4.76k | }, |
908 | | // Entropy Coding Neighbor Arrays |
909 | 4.76k | { |
910 | 4.76k | &object_ptr->partition_context_na[tile_idx], |
911 | 4.76k | na_max_pic_w, |
912 | 4.76k | na_max_pic_h, |
913 | 4.76k | sizeof(PartitionContextType), |
914 | 4.76k | PU_NEIGHBOR_ARRAY_GRANULARITY, |
915 | 4.76k | NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK, |
916 | 4.76k | }, |
917 | | // for each 4x4 |
918 | 4.76k | { |
919 | 4.76k | &object_ptr->luma_dc_sign_level_coeff_na[tile_idx], |
920 | 4.76k | na_max_pic_w, |
921 | 4.76k | na_max_pic_h, |
922 | 4.76k | sizeof(uint8_t), |
923 | 4.76k | PU_NEIGHBOR_ARRAY_GRANULARITY, |
924 | 4.76k | NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK, |
925 | 4.76k | }, |
926 | | // for each 4x4 |
927 | 4.76k | { |
928 | 4.76k | &object_ptr->cr_dc_sign_level_coeff_na[tile_idx], |
929 | 4.76k | na_max_pic_w, |
930 | 4.76k | na_max_pic_h, |
931 | 4.76k | sizeof(uint8_t), |
932 | 4.76k | PU_NEIGHBOR_ARRAY_GRANULARITY, |
933 | 4.76k | NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK, |
934 | 4.76k | }, |
935 | | // for each 4x4 |
936 | 4.76k | { |
937 | 4.76k | &object_ptr->cb_dc_sign_level_coeff_na[tile_idx], |
938 | 4.76k | na_max_pic_w, |
939 | 4.76k | na_max_pic_h, |
940 | 4.76k | sizeof(uint8_t), |
941 | 4.76k | PU_NEIGHBOR_ARRAY_GRANULARITY, |
942 | 4.76k | NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK, |
943 | 4.76k | }, |
944 | 4.76k | { |
945 | 4.76k | &object_ptr->txfm_context_array[tile_idx], |
946 | 4.76k | na_max_pic_w, |
947 | 4.76k | na_max_pic_h, |
948 | 4.76k | sizeof(TXFM_CONTEXT), |
949 | 4.76k | PU_NEIGHBOR_ARRAY_GRANULARITY, |
950 | 4.76k | NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK, |
951 | 4.76k | }, |
952 | 4.76k | }; |
953 | 4.76k | return_error = create_neighbor_array_units(data0, DIM(data0)); |
954 | 4.76k | if (return_error == EB_ErrorInsufficientResources) { |
955 | 0 | return EB_ErrorInsufficientResources; |
956 | 0 | } |
957 | | |
958 | 4.76k | if ((is_16bit) || (init_data_ptr->is_16bit_pipeline)) { |
959 | 0 | InitData data[] = { |
960 | 0 | { |
961 | 0 | &object_ptr->ep_luma_recon_na_16bit[tile_idx], |
962 | 0 | na_max_pic_w, |
963 | 0 | na_max_pic_h, |
964 | 0 | sizeof(uint16_t), |
965 | 0 | SAMPLE_NEIGHBOR_ARRAY_GRANULARITY, |
966 | 0 | NEIGHBOR_ARRAY_UNIT_FULL_MASK, |
967 | 0 | }, |
968 | 0 | { |
969 | 0 | &object_ptr->ep_cb_recon_na_16bit[tile_idx], |
970 | 0 | na_max_pic_w >> subsampling_x, |
971 | 0 | na_max_pic_h >> subsampling_y, |
972 | 0 | sizeof(uint16_t), |
973 | 0 | SAMPLE_NEIGHBOR_ARRAY_GRANULARITY, |
974 | 0 | NEIGHBOR_ARRAY_UNIT_FULL_MASK, |
975 | 0 | }, |
976 | 0 | { |
977 | 0 | &object_ptr->ep_cr_recon_na_16bit[tile_idx], |
978 | 0 | na_max_pic_w >> subsampling_x, |
979 | 0 | na_max_pic_h >> subsampling_y, |
980 | 0 | sizeof(uint16_t), |
981 | 0 | SAMPLE_NEIGHBOR_ARRAY_GRANULARITY, |
982 | 0 | NEIGHBOR_ARRAY_UNIT_FULL_MASK, |
983 | 0 | }, |
984 | 0 | }; |
985 | 0 | return_error = create_neighbor_array_units(data, DIM(data)); |
986 | 0 | if (return_error == EB_ErrorInsufficientResources) { |
987 | 0 | return EB_ErrorInsufficientResources; |
988 | 0 | } |
989 | 4.76k | } else { |
990 | 4.76k | object_ptr->ep_luma_recon_na_16bit = 0; |
991 | 4.76k | object_ptr->ep_cb_recon_na_16bit = 0; |
992 | 4.76k | object_ptr->ep_cr_recon_na_16bit = 0; |
993 | 4.76k | } |
994 | 4.76k | } |
995 | | //Segmentation neighbor arrays |
996 | 448 | EB_NEW(object_ptr->segmentation_neighbor_map, |
997 | 448 | segmentation_map_ctor, |
998 | 448 | init_data_ptr->picture_width, |
999 | 448 | init_data_ptr->picture_height); |
1000 | | // Segments |
1001 | 448 | object_ptr->enc_dec_coded_sb_count = 0; |
1002 | | |
1003 | 448 | EB_MALLOC_ARRAY(object_ptr->enc_dec_segment_ctrl, total_tile_cnt); |
1004 | | |
1005 | 5.21k | for (tile_idx = 0; tile_idx < total_tile_cnt; tile_idx++) { |
1006 | 4.76k | EB_NEW(object_ptr->enc_dec_segment_ctrl[tile_idx], |
1007 | 4.76k | svt_aom_enc_dec_segments_ctor, |
1008 | 4.76k | init_data_ptr->enc_dec_segment_col, |
1009 | 4.76k | init_data_ptr->enc_dec_segment_row); |
1010 | 4.76k | } |
1011 | | |
1012 | | // Entropy Rows |
1013 | 448 | EB_CREATE_MUTEX(object_ptr->entropy_coding_pic_mutex); |
1014 | | |
1015 | 448 | EB_CREATE_MUTEX(object_ptr->intra_mutex); |
1016 | | |
1017 | 448 | EB_CREATE_MUTEX(object_ptr->cdef_search_mutex); |
1018 | | |
1019 | 448 | EB_MALLOC_ARRAY(object_ptr->mse_seg[0], object_ptr->b64_total_count); |
1020 | 448 | EB_MALLOC_ARRAY(object_ptr->mse_seg[1], object_ptr->b64_total_count); |
1021 | 448 | EB_MALLOC_ARRAY(object_ptr->skip_cdef_seg, object_ptr->b64_total_count); |
1022 | 448 | EB_MALLOC_ARRAY(object_ptr->cdef_dir_data, object_ptr->b64_total_count); |
1023 | 448 | EB_MALLOC_ARRAY(object_ptr->cdef_fb_list, object_ptr->b64_total_count); |
1024 | 448 | EB_MALLOC_ARRAY(object_ptr->cdef_sb_index, object_ptr->b64_total_count); |
1025 | 448 | EB_MALLOC_ARRAY(object_ptr->cdef_mse_ptr[0], object_ptr->b64_total_count); |
1026 | 448 | EB_MALLOC_ARRAY(object_ptr->cdef_mse_ptr[1], object_ptr->b64_total_count); |
1027 | 448 | EB_CREATE_MUTEX(object_ptr->rest_search_mutex); |
1028 | | |
1029 | | //the granularity is 4x4 |
1030 | 448 | EB_MALLOC_ARRAY(object_ptr->mi_grid_base, |
1031 | 448 | all_sb * (init_data_ptr->sb_size >> MI_SIZE_LOG2) * (init_data_ptr->sb_size >> MI_SIZE_LOG2)); |
1032 | | |
1033 | | // If NSQ is allowed, then may need a 4x4 MI grid because 8x8 NSQ shapes will require 4x4 granularity |
1034 | 448 | bool disallow_4x4 = true; |
1035 | 448 | bool disallow_8x8 = true; |
1036 | 2.68k | for (uint8_t coeff_lvl = 0; coeff_lvl <= HIGH_LVL + 1; coeff_lvl++) { |
1037 | 2.24k | if (!disallow_4x4 && !disallow_8x8) { |
1038 | 0 | break; |
1039 | 0 | } |
1040 | 2.24k | uint8_t nsq_geom_lvl = allintra ? svt_aom_get_nsq_geom_level_allintra(init_data_ptr->enc_mode) |
1041 | 2.24k | : rtc_tune ? svt_aom_get_nsq_geom_level_rtc() |
1042 | 0 | : svt_aom_get_nsq_geom_level_default(init_data_ptr->enc_mode, coeff_lvl); |
1043 | | // nsq_geom_lvl level 0 means NSQ shapes are disallowed so don't adjust based on the level |
1044 | 2.24k | if (nsq_geom_lvl) { |
1045 | 0 | uint8_t allow_HVA_HVB, allow_HV4, min_nsq_bsize; |
1046 | 0 | svt_aom_set_nsq_geom_ctrls(NULL, nsq_geom_lvl, &allow_HVA_HVB, &allow_HV4, &min_nsq_bsize); |
1047 | 0 | if (min_nsq_bsize < 8 || (min_nsq_bsize < 16 && allow_HV4)) { |
1048 | 0 | disallow_4x4 = false; |
1049 | 0 | } |
1050 | 0 | if (min_nsq_bsize < 16 || (min_nsq_bsize < 32 && allow_HV4)) { |
1051 | 0 | disallow_8x8 = false; |
1052 | 0 | } |
1053 | 0 | } |
1054 | 2.24k | } |
1055 | | |
1056 | 448 | disallow_4x4 = allintra ? MIN(disallow_4x4, svt_aom_get_disallow_4x4_allintra(init_data_ptr->enc_mode)) |
1057 | 448 | : rtc_tune ? MIN(disallow_4x4, svt_aom_get_disallow_4x4_rtc()) |
1058 | 0 | : MIN(disallow_4x4, svt_aom_get_disallow_4x4_default(init_data_ptr->enc_mode)); |
1059 | | |
1060 | 448 | object_ptr->disallow_4x4_all_frames = disallow_4x4; |
1061 | 448 | disallow_8x8 = allintra ? MIN(disallow_8x8, svt_aom_get_disallow_8x8_allintra()) |
1062 | 448 | : rtc_tune ? MIN(disallow_8x8, |
1063 | 0 | svt_aom_get_disallow_8x8_rtc( |
1064 | 0 | init_data_ptr->enc_mode, init_data_ptr->picture_width, init_data_ptr->picture_height)) |
1065 | 0 | : MIN(disallow_8x8, svt_aom_get_disallow_8x8_default()); |
1066 | 448 | object_ptr->disallow_8x8_all_frames = disallow_8x8; |
1067 | | /* If 4x4 blocks are disallowed for all frames, the the MI blocks only need to be allocated for |
1068 | | 8x8 blocks. The mi_grid will still be 4x4 so that the data can be accessed the same way throughout |
1069 | | the code. */ |
1070 | 448 | EB_MALLOC_ARRAY(object_ptr->mip, |
1071 | 448 | all_sb * (init_data_ptr->sb_size >> (MI_SIZE_LOG2 + disallow_4x4 + disallow_8x8)) * |
1072 | 448 | (init_data_ptr->sb_size >> (MI_SIZE_LOG2 + disallow_4x4 + disallow_8x8))); |
1073 | | |
1074 | 448 | memset(object_ptr->mip, |
1075 | 448 | 0, |
1076 | 448 | sizeof(MbModeInfo) * all_sb * (init_data_ptr->sb_size >> (MI_SIZE_LOG2 + disallow_4x4 + disallow_8x8)) * |
1077 | 448 | (init_data_ptr->sb_size >> (MI_SIZE_LOG2 + disallow_4x4 + disallow_8x8))); |
1078 | | |
1079 | 448 | uint32_t mi_stride = picture_sb_w * (init_data_ptr->sb_size >> MI_SIZE_LOG2); |
1080 | 25.3k | for (uint32_t mi_h = 0; mi_h < picture_sb_h * (init_data_ptr->sb_size >> MI_SIZE_LOG2); mi_h++) { |
1081 | 1.54M | for (uint32_t mi_w = 0; mi_w < picture_sb_w * (init_data_ptr->sb_size >> MI_SIZE_LOG2); mi_w++) { |
1082 | 1.52M | uint32_t mi_grid_idx = mi_h * mi_stride + mi_w; |
1083 | 1.52M | uint32_t mip_idx = (mi_h >> (disallow_4x4 + disallow_8x8)) * (mi_stride >> (disallow_4x4 + disallow_8x8)) + |
1084 | 1.52M | (mi_w >> (disallow_4x4 + disallow_8x8)); |
1085 | 1.52M | object_ptr->mi_grid_base[mi_grid_idx] = object_ptr->mip + mip_idx; |
1086 | 1.52M | } |
1087 | 24.9k | } |
1088 | 448 | object_ptr->mi_stride = picture_sb_w * (init_data_ptr->sb_size >> MI_SIZE_LOG2); |
1089 | 448 | if (init_data_ptr->mfmv) { |
1090 | | //MFMV: map is 8x8 based. |
1091 | 448 | uint32_t mi_rows = init_data_ptr->picture_height >> MI_SIZE_LOG2; |
1092 | 448 | const int mem_size = ((mi_rows + MAX_MIB_SIZE) >> 1) * (object_ptr->mi_stride >> 1); |
1093 | | |
1094 | 448 | EB_CALLOC_ALIGNED_ARRAY(object_ptr->tpl_mvs, mem_size); |
1095 | 448 | } |
1096 | | |
1097 | 448 | return EB_ErrorNone; |
1098 | 448 | } |
1099 | | |
1100 | 448 | EbErrorType svt_aom_recon_coef_creator(EbPtr* object_dbl_ptr, EbPtr object_init_data_ptr) { |
1101 | 448 | EncDecSet* obj; |
1102 | | |
1103 | 448 | *object_dbl_ptr = NULL; |
1104 | 448 | EB_NEW(obj, recon_coef_ctor, object_init_data_ptr); |
1105 | 448 | *object_dbl_ptr = obj; |
1106 | | |
1107 | 448 | return EB_ErrorNone; |
1108 | 448 | } |
1109 | | |
1110 | 448 | EbErrorType svt_aom_picture_control_set_creator(EbPtr* object_dbl_ptr, EbPtr object_init_data_ptr) { |
1111 | 448 | PictureControlSet* obj; |
1112 | | |
1113 | 448 | *object_dbl_ptr = NULL; |
1114 | 448 | EB_NEW(obj, picture_control_set_ctor, object_init_data_ptr); |
1115 | 448 | *object_dbl_ptr = obj; |
1116 | | |
1117 | 448 | return EB_ErrorNone; |
1118 | 448 | } |
1119 | | |
1120 | 1.79k | static void picture_parent_control_set_dctor(EbPtr ptr) { |
1121 | 1.79k | PictureParentControlSet* obj = (PictureParentControlSet*)ptr; |
1122 | | |
1123 | 1.79k | if (obj->is_chroma_downsampled_picture_ptr_owner) { |
1124 | 0 | EB_DELETE(obj->chroma_downsampled_pic); |
1125 | 0 | } |
1126 | | |
1127 | 1.79k | if (obj->variance) { |
1128 | 1.79k | EB_FREE_2D(obj->variance); |
1129 | 1.79k | } |
1130 | | |
1131 | 1.79k | if (obj->picture_histogram) { |
1132 | 0 | for (int region_in_picture_width_index = 0; region_in_picture_width_index < MAX_NUMBER_OF_REGIONS_IN_WIDTH; |
1133 | 0 | region_in_picture_width_index++) { |
1134 | 0 | if (obj->picture_histogram[region_in_picture_width_index]) { |
1135 | 0 | for (int region_in_picture_height_index = 0; |
1136 | 0 | region_in_picture_height_index < MAX_NUMBER_OF_REGIONS_IN_HEIGHT; |
1137 | 0 | region_in_picture_height_index++) { |
1138 | 0 | EB_FREE_ARRAY( |
1139 | 0 | obj->picture_histogram[region_in_picture_width_index][region_in_picture_height_index]); |
1140 | 0 | } |
1141 | 0 | } |
1142 | 0 | EB_FREE_PTR_ARRAY(obj->picture_histogram[region_in_picture_width_index], MAX_NUMBER_OF_REGIONS_IN_HEIGHT); |
1143 | 0 | } |
1144 | 0 | EB_FREE_PTR_ARRAY(obj->picture_histogram, MAX_NUMBER_OF_REGIONS_IN_WIDTH); |
1145 | 0 | } |
1146 | 1.79k | EB_FREE_ARRAY(obj->rc_me_distortion); |
1147 | 1.79k | EB_FREE_ARRAY(obj->rc_me_allow_gm); |
1148 | 1.79k | EB_FREE_ARRAY(obj->me_64x64_distortion); |
1149 | 1.79k | EB_FREE_ARRAY(obj->me_32x32_distortion); |
1150 | 1.79k | EB_FREE_ARRAY(obj->me_16x16_distortion); |
1151 | 1.79k | EB_FREE_ARRAY(obj->me_8x8_distortion); |
1152 | | |
1153 | 1.79k | EB_FREE_ARRAY(obj->me_8x8_cost_variance); |
1154 | 1.79k | if (obj->av1_cm) { |
1155 | 1.79k | EB_FREE_ARRAY(obj->av1_cm->frame_to_show); |
1156 | 1.79k | if (obj->av1_cm->rst_frame.buffer_alloc_sz) { |
1157 | 0 | EB_FREE_ARRAY(obj->av1_cm->rst_frame.buffer_alloc); |
1158 | 0 | } |
1159 | 1.79k | EB_FREE_ARRAY(obj->av1_cm); |
1160 | 1.79k | } |
1161 | | |
1162 | 1.79k | EB_FREE_ARRAY(obj->av1x); |
1163 | 1.79k | EB_DESTROY_MUTEX(obj->me_processed_b64_mutex); |
1164 | 1.79k | EB_DESTROY_SEMAPHORE(obj->temp_filt_done_semaphore); |
1165 | 1.79k | EB_DESTROY_MUTEX(obj->temp_filt_mutex); |
1166 | 1.79k | EB_FREE_ARRAY(obj->tile_group_info); |
1167 | 1.79k | EB_DESTROY_MUTEX(obj->pa_me_done.mutex); |
1168 | 1.79k | if (obj->is_pcs_sb_params) { |
1169 | 0 | svt_pcs_sb_structs_dctor(obj); |
1170 | 0 | } |
1171 | 1.79k | if (obj->frame_superres_enabled || obj->frame_resize_enabled) { |
1172 | 0 | EB_DELETE(obj->enhanced_downscaled_pic); |
1173 | 0 | } |
1174 | 1.79k | EB_DESTROY_SEMAPHORE(obj->tpl_disp_done_semaphore); |
1175 | 1.79k | EB_DESTROY_MUTEX(obj->tpl_disp_mutex); |
1176 | 1.79k | uint16_t tile_cnt = 1; /*obj->tile_row_count * obj->tile_column_count;*/ |
1177 | 1.79k | EB_DELETE_PTR_ARRAY(obj->tpl_disp_segment_ctrl, tile_cnt); |
1178 | 1.79k | if (obj->dg_detector) { |
1179 | 1.79k | EB_DELETE(obj->dg_detector); |
1180 | 1.79k | } |
1181 | 1.79k | } |
1182 | | |
1183 | | /* |
1184 | | ppcs_update_param: update the parameters in PictureParentControlSet for changing the resolution on the fly |
1185 | | */ |
1186 | 0 | EbErrorType ppcs_update_param(PictureParentControlSet* ppcs) { |
1187 | 0 | EbErrorType return_error = EB_ErrorNone; |
1188 | 0 | SequenceControlSet* scs = ppcs->scs; |
1189 | |
|
1190 | 0 | if (ppcs->av1_cm->color_format >= EB_YUV422) { |
1191 | 0 | EbPictureBufferDescInitData input_pic_buf_desc_init_data; |
1192 | 0 | input_pic_buf_desc_init_data.max_width = scs->max_input_luma_width; |
1193 | 0 | input_pic_buf_desc_init_data.max_height = scs->max_input_luma_height; |
1194 | 0 | input_pic_buf_desc_init_data.bit_depth = 8; //Should be 8bit |
1195 | 0 | input_pic_buf_desc_init_data.buffer_enable_mask = PICTURE_BUFFER_DESC_CHROMA_MASK; |
1196 | 0 | input_pic_buf_desc_init_data.border = scs->border; |
1197 | 0 | input_pic_buf_desc_init_data.color_format = EB_YUV420; //set to 420 for MD |
1198 | 0 | input_pic_buf_desc_init_data.split_mode = false; |
1199 | 0 | svt_picture_buffer_desc_update(ppcs->chroma_downsampled_pic, (EbPtr)&input_pic_buf_desc_init_data); |
1200 | 0 | } |
1201 | | // GOP |
1202 | 0 | ppcs->b64_total_count = scs->b64_total_count; |
1203 | 0 | ppcs->av1_cm->mi_stride = scs->pic_width_in_b64 * (BLOCK_SIZE_64 / 4); |
1204 | |
|
1205 | 0 | ppcs->av1_cm->frm_size.frame_width = scs->max_input_luma_width - scs->max_input_pad_right; |
1206 | 0 | ppcs->av1_cm->frm_size.frame_height = scs->max_input_luma_height - scs->max_input_pad_bottom; |
1207 | 0 | ppcs->av1_cm->frm_size.superres_upscaled_width = scs->max_input_luma_width - scs->max_input_pad_right; |
1208 | 0 | ppcs->av1_cm->frm_size.superres_upscaled_height = scs->max_input_luma_height - scs->max_input_pad_bottom; |
1209 | 0 | ppcs->av1_cm->frm_size.superres_denominator = SCALE_NUMERATOR; |
1210 | 0 | ppcs->av1_cm->mi_cols = scs->max_input_luma_width >> MI_SIZE_LOG2; |
1211 | 0 | ppcs->av1_cm->mi_rows = scs->max_input_luma_height >> MI_SIZE_LOG2; |
1212 | |
|
1213 | 0 | ppcs->aligned_width = scs->max_input_luma_width; |
1214 | 0 | ppcs->aligned_height = scs->max_input_luma_height; |
1215 | 0 | ppcs->frame_width = scs->max_input_luma_width; |
1216 | 0 | ppcs->frame_height = scs->max_input_luma_height; |
1217 | 0 | ppcs->render_width = scs->max_input_luma_width; |
1218 | 0 | ppcs->render_height = scs->max_input_luma_height; |
1219 | |
|
1220 | 0 | return return_error; |
1221 | 0 | } |
1222 | | |
1223 | 1.79k | static EbErrorType picture_parent_control_set_ctor(PictureParentControlSet* object_ptr, EbPtr object_init_data_ptr) { |
1224 | 1.79k | PictureControlSetInitData* init_data_ptr = (PictureControlSetInitData*)object_init_data_ptr; |
1225 | | |
1226 | 1.79k | EbErrorType return_error = EB_ErrorNone; |
1227 | 1.79k | const uint16_t subsampling_x = (init_data_ptr->color_format == EB_YUV444 ? 0 : 1); |
1228 | 1.79k | const uint16_t subsampling_y = (init_data_ptr->color_format >= EB_YUV422 ? 0 : 1); |
1229 | | |
1230 | 1.79k | object_ptr->dctor = picture_parent_control_set_dctor; |
1231 | | |
1232 | 1.79k | object_ptr->input_pic_wrapper = NULL; |
1233 | 1.79k | object_ptr->ref_pic_wrapper = NULL; |
1234 | 1.79k | object_ptr->enhanced_pic = NULL; |
1235 | 1.79k | object_ptr->enhanced_downscaled_pic = NULL; |
1236 | 1.79k | object_ptr->enhanced_unscaled_pic = NULL; |
1237 | | |
1238 | 1.79k | if (init_data_ptr->color_format >= EB_YUV422) { |
1239 | 0 | EbPictureBufferDescInitData input_pic_buf_desc_init_data; |
1240 | 0 | input_pic_buf_desc_init_data.max_width = init_data_ptr->picture_width; |
1241 | 0 | input_pic_buf_desc_init_data.max_height = init_data_ptr->picture_height; |
1242 | 0 | input_pic_buf_desc_init_data.bit_depth = 8; //Should be 8bit |
1243 | 0 | input_pic_buf_desc_init_data.buffer_enable_mask = PICTURE_BUFFER_DESC_CHROMA_MASK; |
1244 | 0 | input_pic_buf_desc_init_data.border = init_data_ptr->border; |
1245 | 0 | input_pic_buf_desc_init_data.color_format = EB_YUV420; //set to 420 for MD |
1246 | 0 | input_pic_buf_desc_init_data.split_mode = false; |
1247 | 0 | EB_NEW(object_ptr->chroma_downsampled_pic, svt_picture_buffer_desc_ctor, (EbPtr)&input_pic_buf_desc_init_data); |
1248 | 0 | object_ptr->is_chroma_downsampled_picture_ptr_owner = true; |
1249 | 1.79k | } else if (init_data_ptr->color_format == EB_YUV420) { |
1250 | 1.79k | object_ptr->chroma_downsampled_pic = NULL; |
1251 | 1.79k | } else { |
1252 | 0 | return EB_ErrorBadParameter; |
1253 | 0 | } |
1254 | | // GOP |
1255 | 1.79k | object_ptr->pred_struct_index = 0; |
1256 | 1.79k | object_ptr->picture_number = 0; |
1257 | 1.79k | object_ptr->idr_flag = false; |
1258 | 1.79k | object_ptr->temporal_layer_index = 0; |
1259 | 1.79k | object_ptr->total_num_bits = 0; |
1260 | 1.79k | object_ptr->last_idr_picture = 0; |
1261 | 1.79k | object_ptr->is_pcs_sb_params = false; |
1262 | | |
1263 | 1.79k | const uint16_t picture_b64_width = (uint16_t)DIVIDE_AND_CEIL(init_data_ptr->picture_width, init_data_ptr->b64_size); |
1264 | 1.79k | const uint16_t picture_b64_height = (uint16_t)DIVIDE_AND_CEIL(init_data_ptr->picture_height, |
1265 | 1.79k | init_data_ptr->b64_size); |
1266 | 1.79k | object_ptr->b64_total_count = picture_b64_width * picture_b64_height; |
1267 | | |
1268 | 1.79k | if (init_data_ptr->calculate_variance) { |
1269 | 1.79k | uint8_t block_count; |
1270 | 1.79k | if (init_data_ptr->allintra || init_data_ptr->aq_mode == 1 || init_data_ptr->variance_octile) { |
1271 | 1.79k | block_count = 85; |
1272 | 1.79k | } else { |
1273 | 0 | block_count = 1; |
1274 | 0 | } |
1275 | 1.79k | EB_MALLOC_2D(object_ptr->variance, object_ptr->b64_total_count, block_count); |
1276 | 1.79k | } |
1277 | 1.79k | if (init_data_ptr->calc_hist) { |
1278 | 0 | EB_ALLOC_PTR_ARRAY(object_ptr->picture_histogram, MAX_NUMBER_OF_REGIONS_IN_WIDTH); |
1279 | | |
1280 | 0 | for (uint32_t region_in_picture_width_index = 0; region_in_picture_width_index < MAX_NUMBER_OF_REGIONS_IN_WIDTH; |
1281 | 0 | region_in_picture_width_index++) { // loop over horizontal regions |
1282 | 0 | EB_ALLOC_PTR_ARRAY(object_ptr->picture_histogram[region_in_picture_width_index], |
1283 | 0 | MAX_NUMBER_OF_REGIONS_IN_HEIGHT); |
1284 | 0 | for (uint32_t region_in_picture_height_index = 0; |
1285 | 0 | region_in_picture_height_index < MAX_NUMBER_OF_REGIONS_IN_HEIGHT; |
1286 | 0 | region_in_picture_height_index++) { |
1287 | 0 | EB_MALLOC_ARRAY( |
1288 | 0 | object_ptr->picture_histogram[region_in_picture_width_index][region_in_picture_height_index], |
1289 | 0 | HISTOGRAM_NUMBER_OF_BINS); |
1290 | 0 | } |
1291 | 0 | } |
1292 | 0 | } |
1293 | | |
1294 | 1.79k | object_ptr->r0 = 0; |
1295 | | |
1296 | 1.79k | EB_MALLOC_ARRAY(object_ptr->rc_me_distortion, object_ptr->b64_total_count); |
1297 | 1.79k | EB_MALLOC_ARRAY(object_ptr->rc_me_allow_gm, object_ptr->b64_total_count); |
1298 | 1.79k | EB_MALLOC_ARRAY(object_ptr->me_64x64_distortion, object_ptr->b64_total_count); |
1299 | 1.79k | EB_MALLOC_ARRAY(object_ptr->me_32x32_distortion, object_ptr->b64_total_count); |
1300 | 1.79k | EB_MALLOC_ARRAY(object_ptr->me_16x16_distortion, object_ptr->b64_total_count); |
1301 | 1.79k | EB_MALLOC_ARRAY(object_ptr->me_8x8_distortion, object_ptr->b64_total_count); |
1302 | | |
1303 | 1.79k | EB_MALLOC_ARRAY(object_ptr->me_8x8_cost_variance, object_ptr->b64_total_count); |
1304 | | // SB noise variance array |
1305 | 1.79k | EB_CREATE_MUTEX(object_ptr->me_processed_b64_mutex); |
1306 | 1.79k | EB_CREATE_SEMAPHORE(object_ptr->temp_filt_done_semaphore, 0, 1); |
1307 | 1.79k | EB_CREATE_MUTEX(object_ptr->temp_filt_mutex); |
1308 | 1.79k | EB_MALLOC_ARRAY(object_ptr->av1_cm, 1); |
1309 | | |
1310 | 1.79k | EB_CREATE_MUTEX(object_ptr->pa_me_done.mutex); |
1311 | | |
1312 | 1.79k | EB_CREATE_SEMAPHORE(object_ptr->tpl_disp_done_semaphore, 0, 1); |
1313 | 1.79k | EB_CREATE_MUTEX(object_ptr->tpl_disp_mutex); |
1314 | | |
1315 | 1.79k | EB_MALLOC_ARRAY(object_ptr->tpl_disp_segment_ctrl, 1); |
1316 | 3.58k | for (uint32_t tile_idx = 0; tile_idx < 1; tile_idx++) { |
1317 | 1.79k | EB_NEW(object_ptr->tpl_disp_segment_ctrl[tile_idx], |
1318 | 1.79k | svt_aom_enc_dec_segments_ctor, |
1319 | 1.79k | init_data_ptr->enc_dec_segment_col, |
1320 | 1.79k | init_data_ptr->enc_dec_segment_row); |
1321 | 1.79k | } |
1322 | 1.79k | object_ptr->av1_cm->mi_stride = picture_b64_width * (BLOCK_SIZE_64 / 4); |
1323 | | |
1324 | 1.79k | EB_MALLOC_ARRAY(object_ptr->av1_cm->frame_to_show, 1); |
1325 | | |
1326 | 1.79k | object_ptr->av1_cm->use_highbitdepth = ((init_data_ptr->bit_depth > 8) || (init_data_ptr->is_16bit_pipeline)) ? 1 |
1327 | 1.79k | : 0; |
1328 | 1.79k | object_ptr->av1_cm->bit_depth = init_data_ptr->bit_depth; |
1329 | 1.79k | object_ptr->av1_cm->color_format = init_data_ptr->color_format; |
1330 | 1.79k | object_ptr->av1_cm->subsampling_x = subsampling_x; |
1331 | 1.79k | object_ptr->av1_cm->subsampling_y = subsampling_y; |
1332 | 1.79k | object_ptr->av1_cm->frm_size.frame_width = init_data_ptr->picture_width - init_data_ptr->non_m8_pad_w; |
1333 | 1.79k | object_ptr->av1_cm->frm_size.frame_height = init_data_ptr->picture_height - init_data_ptr->non_m8_pad_h; |
1334 | 1.79k | object_ptr->av1_cm->frm_size.superres_upscaled_width = init_data_ptr->picture_width - init_data_ptr->non_m8_pad_w; |
1335 | 1.79k | ; |
1336 | 1.79k | object_ptr->av1_cm->frm_size.superres_upscaled_height = init_data_ptr->picture_height - init_data_ptr->non_m8_pad_h; |
1337 | | |
1338 | 1.79k | object_ptr->av1_cm->frm_size.superres_denominator = SCALE_NUMERATOR; |
1339 | | |
1340 | 1.79k | object_ptr->av1_cm->mi_cols = init_data_ptr->picture_width >> MI_SIZE_LOG2; |
1341 | 1.79k | object_ptr->av1_cm->mi_rows = init_data_ptr->picture_height >> MI_SIZE_LOG2; |
1342 | | |
1343 | 1.79k | object_ptr->av1_cm->byte_alignment = 0; |
1344 | 1.79k | memset(&object_ptr->av1_cm->rst_frame, 0, sizeof(Yv12BufferConfig)); |
1345 | | |
1346 | 1.79k | EB_MALLOC_ARRAY(object_ptr->av1x, 1); |
1347 | | |
1348 | | //Jing: need to know the tile split info at pcs initialize stage |
1349 | 1.79k | object_ptr->log2_tile_rows = init_data_ptr->log2_tile_rows; |
1350 | 1.79k | object_ptr->log2_tile_cols = init_data_ptr->log2_tile_cols; |
1351 | 1.79k | object_ptr->log2_sb_size = init_data_ptr->log2_sb_size; |
1352 | 1.79k | svt_aom_set_tile_info(object_ptr); |
1353 | 1.79k | EB_MALLOC_ARRAY(object_ptr->tile_group_info, |
1354 | 1.79k | (object_ptr->av1_cm->tiles_info.tile_rows * object_ptr->av1_cm->tiles_info.tile_cols)); |
1355 | | |
1356 | 1.79k | object_ptr->frame_superres_enabled = false; |
1357 | 1.79k | object_ptr->aligned_width = init_data_ptr->picture_width; |
1358 | 1.79k | object_ptr->aligned_height = init_data_ptr->picture_height; |
1359 | 1.79k | object_ptr->frame_width = init_data_ptr->picture_width; |
1360 | 1.79k | object_ptr->frame_height = init_data_ptr->picture_height; |
1361 | 1.79k | object_ptr->render_width = init_data_ptr->picture_width; |
1362 | 1.79k | object_ptr->render_height = init_data_ptr->picture_height; |
1363 | | |
1364 | 1.79k | object_ptr->superres_denom = SCALE_NUMERATOR; |
1365 | 1.79k | object_ptr->superres_total_recode_loop = 0; |
1366 | 1.79k | object_ptr->superres_recode_loop = 0; |
1367 | 1.79k | memset(&object_ptr->superres_rdcost, 0, sizeof(object_ptr->superres_rdcost)); |
1368 | 1.79k | memset(&object_ptr->superres_denom_array, 0, sizeof(object_ptr->superres_denom_array)); |
1369 | | |
1370 | 1.79k | object_ptr->frame_resize_enabled = false; |
1371 | 1.79k | object_ptr->resize_denom = SCALE_NUMERATOR; |
1372 | | |
1373 | | // Loop variables |
1374 | 1.79k | object_ptr->loop_count = 0; |
1375 | 1.79k | object_ptr->overshoot_seen = 0; |
1376 | 1.79k | object_ptr->undershoot_seen = 0; |
1377 | 1.79k | object_ptr->low_cr_seen = 0; |
1378 | 1.79k | EB_NEW(object_ptr->dg_detector, svt_aom_dg_detector_seg_ctor); |
1379 | 1.79k | return return_error; |
1380 | 1.79k | } |
1381 | | |
1382 | 448 | static void me_dctor(EbPtr p) { |
1383 | 448 | MotionEstimationData* obj = (MotionEstimationData*)p; |
1384 | 448 | EB_DELETE_PTR_ARRAY(obj->me_results, obj->init_b64_total_count); |
1385 | | // Per-SB ME pools backing the MeSbResults arrays (borrowed by each SB). |
1386 | 448 | EB_FREE_ARRAY(obj->me_sb_mv_pool); |
1387 | 448 | EB_FREE_ARRAY(obj->me_sb_cand_pool); |
1388 | 448 | EB_FREE_ARRAY(obj->me_sb_totidx_pool); |
1389 | 448 | if (obj->tpl_stats) { |
1390 | 0 | EB_FREE_2D(obj->tpl_stats); |
1391 | 0 | } |
1392 | 448 | if (obj->tpl_beta) { |
1393 | 0 | EB_FREE_ARRAY(obj->tpl_beta); |
1394 | 0 | } |
1395 | 448 | if (obj->tpl_rdmult_scaling_factors) { |
1396 | 0 | EB_FREE_ARRAY(obj->tpl_rdmult_scaling_factors); |
1397 | 0 | } |
1398 | 448 | if (obj->tpl_sb_rdmult_scaling_factors) { |
1399 | 0 | EB_FREE_ARRAY(obj->tpl_sb_rdmult_scaling_factors); |
1400 | 0 | } |
1401 | 448 | if (obj->tpl_src_stats_buffer) { |
1402 | 0 | EB_FREE_ARRAY(obj->tpl_src_stats_buffer); |
1403 | 0 | } |
1404 | 448 | if (obj->ssim_rdmult_scaling_factors) { |
1405 | 0 | EB_FREE_ARRAY(obj->ssim_rdmult_scaling_factors); |
1406 | 0 | } |
1407 | 448 | } |
1408 | | |
1409 | | /* |
1410 | | me_update_param: update the parameters in MotionEstimationData for changing the resolution on the fly |
1411 | | */ |
1412 | 448 | EbErrorType me_update_param(MotionEstimationData* me_data, SequenceControlSet* scs) { |
1413 | 448 | EbErrorType return_error = EB_ErrorNone; |
1414 | 448 | me_data->b64_total_count = scs->b64_total_count; |
1415 | | |
1416 | 448 | return return_error; |
1417 | 448 | } |
1418 | | |
1419 | 448 | static EbErrorType me_ctor(MotionEstimationData* object_ptr, EbPtr object_init_data_ptr) { |
1420 | 448 | PictureControlSetInitData* init_data_ptr = (PictureControlSetInitData*)object_init_data_ptr; |
1421 | | |
1422 | 448 | EbErrorType return_error = EB_ErrorNone; |
1423 | 448 | object_ptr->dctor = me_dctor; |
1424 | | |
1425 | 448 | const uint16_t picture_b64_width = (uint16_t)DIVIDE_AND_CEIL(init_data_ptr->picture_width, init_data_ptr->b64_size); |
1426 | 448 | const uint16_t picture_b64_height = (uint16_t)DIVIDE_AND_CEIL(init_data_ptr->picture_height, |
1427 | 448 | init_data_ptr->b64_size); |
1428 | 448 | uint32_t sb_total_count = picture_b64_width * picture_b64_height; |
1429 | 448 | object_ptr->b64_total_count = sb_total_count; |
1430 | 448 | object_ptr->init_b64_total_count = sb_total_count; |
1431 | | |
1432 | 448 | if (!init_data_ptr->allintra) { |
1433 | 0 | EB_ALLOC_PTR_ARRAY(object_ptr->me_results, sb_total_count); |
1434 | | |
1435 | 0 | for (uint16_t sb_index = 0; sb_index < sb_total_count; ++sb_index) { |
1436 | 0 | EB_NEW(object_ptr->me_results[sb_index], |
1437 | 0 | svt_aom_me_sb_results_ctor, |
1438 | 0 | init_data_ptr, |
1439 | 0 | object_ptr, |
1440 | 0 | sb_index, |
1441 | 0 | sb_total_count); |
1442 | 0 | } |
1443 | 0 | } |
1444 | 448 | uint16_t adaptive_picture_width_in_mb = (uint16_t)((init_data_ptr->picture_width + 15) / 16); |
1445 | 448 | uint16_t adaptive_picture_height_in_mb = (uint16_t)((init_data_ptr->picture_height + 15) / 16); |
1446 | 448 | if (init_data_ptr->static_config.tune == TUNE_SSIM || init_data_ptr->static_config.tune == TUNE_IQ || |
1447 | 448 | init_data_ptr->static_config.tune == TUNE_MS_SSIM) { |
1448 | 0 | EB_MALLOC_ARRAY(object_ptr->ssim_rdmult_scaling_factors, |
1449 | 0 | adaptive_picture_width_in_mb * adaptive_picture_height_in_mb); |
1450 | 448 | } else { |
1451 | 448 | object_ptr->ssim_rdmult_scaling_factors = NULL; |
1452 | 448 | } |
1453 | 448 | if (init_data_ptr->enable_tpl_la) { |
1454 | 0 | const uint16_t picture_width_in_mb = (uint16_t)((init_data_ptr->picture_width + 15) / 16); |
1455 | 0 | const uint16_t picture_height_in_mb = (uint16_t)((init_data_ptr->picture_height + 15) / 16); |
1456 | 0 | if (init_data_ptr->tpl_synth_size == 8) { |
1457 | 0 | adaptive_picture_width_in_mb = adaptive_picture_width_in_mb << 1; |
1458 | 0 | adaptive_picture_height_in_mb = adaptive_picture_height_in_mb << 1; |
1459 | 0 | } else if (init_data_ptr->tpl_synth_size == 32) { |
1460 | 0 | adaptive_picture_width_in_mb = (uint16_t)((init_data_ptr->picture_width + 31) / 32); |
1461 | 0 | adaptive_picture_height_in_mb = (uint16_t)((init_data_ptr->picture_height + 31) / 32); |
1462 | 0 | } |
1463 | 0 | EB_MALLOC_2D( |
1464 | 0 | object_ptr->tpl_stats, (uint32_t)((adaptive_picture_width_in_mb) * (adaptive_picture_height_in_mb)), 1); |
1465 | 0 | if (init_data_ptr->tpl_lad_mg > 0) { |
1466 | 0 | EB_MALLOC_ARRAY(object_ptr->tpl_src_stats_buffer, |
1467 | 0 | (uint32_t)picture_width_in_mb * (uint32_t)picture_height_in_mb); |
1468 | 0 | } else { |
1469 | 0 | object_ptr->tpl_src_stats_buffer = NULL; |
1470 | 0 | } |
1471 | 0 | EB_MALLOC_ARRAY(object_ptr->tpl_beta, sb_total_count); |
1472 | 0 | EB_MALLOC_ARRAY(object_ptr->tpl_rdmult_scaling_factors, |
1473 | 0 | adaptive_picture_width_in_mb * adaptive_picture_height_in_mb); |
1474 | 0 | EB_MALLOC_ARRAY(object_ptr->tpl_sb_rdmult_scaling_factors, |
1475 | 0 | adaptive_picture_width_in_mb * adaptive_picture_height_in_mb); |
1476 | 448 | } else { |
1477 | 448 | object_ptr->tpl_stats = NULL; |
1478 | 448 | object_ptr->tpl_beta = NULL; |
1479 | 448 | object_ptr->tpl_rdmult_scaling_factors = NULL; |
1480 | 448 | object_ptr->tpl_sb_rdmult_scaling_factors = NULL; |
1481 | 448 | object_ptr->tpl_src_stats_buffer = NULL; |
1482 | 448 | } |
1483 | 448 | return return_error; |
1484 | 448 | } |
1485 | | |
1486 | 448 | EbErrorType b64_geom_init(SequenceControlSet* scs, uint16_t width, uint16_t height, B64Geom** b64_geoms) { |
1487 | 448 | EbErrorType return_error = EB_ErrorNone; |
1488 | | |
1489 | 448 | uint8_t b64_size = scs->b64_size; |
1490 | 448 | uint16_t picture_b64_width = DIVIDE_AND_CEIL(width, b64_size); |
1491 | 448 | uint16_t picture_b64_height = DIVIDE_AND_CEIL(height, b64_size); |
1492 | | |
1493 | 448 | EB_FREE_ARRAY(*b64_geoms); |
1494 | 448 | EB_MALLOC_ARRAY(*b64_geoms, picture_b64_width * picture_b64_height); |
1495 | | |
1496 | 6.38k | for (int b64_idx = 0; b64_idx < picture_b64_width * picture_b64_height; ++b64_idx) { |
1497 | 5.93k | B64Geom* b64_geom = &(*b64_geoms)[b64_idx]; |
1498 | 5.93k | uint16_t horizontal_index = (uint16_t)(b64_idx % picture_b64_width); |
1499 | 5.93k | uint16_t vertical_index = (uint16_t)(b64_idx / picture_b64_width); |
1500 | 5.93k | b64_geom->org_x = horizontal_index * b64_size; |
1501 | 5.93k | b64_geom->org_y = vertical_index * b64_size; |
1502 | 5.93k | b64_geom->width = (uint8_t)MIN(width - b64_geom->org_x, b64_size); |
1503 | 5.93k | b64_geom->height = (uint8_t)MIN(height - b64_geom->org_y, b64_size); |
1504 | 5.93k | b64_geom->is_complete_b64 = (b64_geom->width == b64_size && b64_geom->height == b64_size) ? 1 : 0; |
1505 | 5.93k | } |
1506 | | |
1507 | 448 | return return_error; |
1508 | 448 | } |
1509 | | |
1510 | 896 | EbErrorType alloc_sb_geoms(SbGeom** geom, int width, int height) { |
1511 | 896 | SbGeom* tmp; |
1512 | 896 | EB_MALLOC_ARRAY(tmp, width * height); |
1513 | 896 | *geom = tmp; |
1514 | | |
1515 | 896 | return EB_ErrorNone; |
1516 | 896 | } |
1517 | | |
1518 | 5.37k | void free_sb_geoms(SbGeom* geom) { |
1519 | 5.37k | if (geom) { |
1520 | 896 | EB_FREE_ARRAY(geom); |
1521 | 896 | } |
1522 | 5.37k | } |
1523 | | |
1524 | 448 | void copy_sb_geoms(SbGeom* dst_geom, SbGeom* src_geom, uint16_t width, uint16_t height) { |
1525 | 6.38k | for (int i = 0; i < width * height; i++) { |
1526 | 5.93k | dst_geom[i] = src_geom[i]; |
1527 | 5.93k | } |
1528 | 448 | } |
1529 | | |
1530 | 448 | EbErrorType sb_geom_init(SequenceControlSet* scs, uint16_t width, uint16_t height, SbGeom** sb_geoms) { |
1531 | 448 | uint16_t picture_sb_width = DIVIDE_AND_CEIL(width, scs->sb_size); |
1532 | 448 | uint16_t picture_sb_height = DIVIDE_AND_CEIL(height, scs->sb_size); |
1533 | 448 | free_sb_geoms(*sb_geoms); |
1534 | 448 | EbErrorType ret = alloc_sb_geoms(sb_geoms, picture_sb_width, picture_sb_height); |
1535 | 448 | if (ret != EB_ErrorNone) { |
1536 | 0 | return ret; |
1537 | 0 | } |
1538 | | |
1539 | 6.38k | for (int sb_index = 0; sb_index < picture_sb_width * picture_sb_height; ++sb_index) { |
1540 | 5.93k | SbGeom* sb_geom = &(*sb_geoms)[sb_index]; |
1541 | 5.93k | uint16_t hor_index = sb_index % picture_sb_width; |
1542 | 5.93k | uint16_t ver_index = sb_index / picture_sb_width; |
1543 | 5.93k | sb_geom->org_x = hor_index * scs->sb_size; |
1544 | 5.93k | sb_geom->org_y = ver_index * scs->sb_size; |
1545 | 5.93k | sb_geom->width = (uint8_t)MIN(width - sb_geom->org_x, scs->sb_size); |
1546 | 5.93k | sb_geom->height = (uint8_t)MIN(height - sb_geom->org_y, scs->sb_size); |
1547 | 5.93k | } |
1548 | | |
1549 | 448 | return EB_ErrorNone; |
1550 | 448 | } |
1551 | | |
1552 | 1.79k | EbErrorType svt_aom_picture_parent_control_set_creator(EbPtr* object_dbl_ptr, EbPtr object_init_data_ptr) { |
1553 | 1.79k | PictureParentControlSet* obj; |
1554 | | |
1555 | 1.79k | *object_dbl_ptr = NULL; |
1556 | 1.79k | EB_NEW(obj, picture_parent_control_set_ctor, object_init_data_ptr); |
1557 | 1.79k | *object_dbl_ptr = obj; |
1558 | | |
1559 | 1.79k | return EB_ErrorNone; |
1560 | 1.79k | } |
1561 | | |
1562 | 448 | EbErrorType svt_aom_me_creator(EbPtr* object_dbl_ptr, EbPtr object_init_data_ptr) { |
1563 | 448 | MotionEstimationData* obj; |
1564 | | |
1565 | 448 | *object_dbl_ptr = NULL; |
1566 | 448 | EB_NEW(obj, me_ctor, object_init_data_ptr); |
1567 | 448 | *object_dbl_ptr = obj; |
1568 | | |
1569 | 448 | return EB_ErrorNone; |
1570 | 448 | } |