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