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