Line data Source code
1 : /*
2 : * Copyright(c) 2019 Intel Corporation
3 : * SPDX - License - Identifier: BSD - 2 - Clause - Patent
4 : */
5 :
6 : /*
7 : * Copyright (c) 2016, Alliance for Open Media. All rights reserved
8 : *
9 : * This source code is subject to the terms of the BSD 2 Clause License and
10 : * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
11 : * was not distributed with this source code in the LICENSE file, you can
12 : * obtain it at www.aomedia.org/license/software. If the Alliance for Open
13 : * Media Patent License 1.0 was not distributed with this source code in the
14 : * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
15 : */
16 :
17 : #include <stdlib.h>
18 :
19 : #include "EbDefinitions.h"
20 : #include "EbPictureControlSet.h"
21 : #include "EbPictureBufferDesc.h"
22 :
23 : void *eb_aom_memalign(size_t align, size_t size);
24 : void eb_aom_free(void *memblk);
25 : void *eb_aom_malloc(size_t size);
26 :
27 : EbErrorType eb_av1_alloc_restoration_buffers(Av1Common *cm);
28 :
29 : EbErrorType av1_hash_table_create(HashTable *p_hash_table);
30 :
31 144 : static void set_restoration_unit_size(int32_t width, int32_t height, int32_t sx, int32_t sy,
32 : RestorationInfo *rst) {
33 : (void)width;
34 : (void)height;
35 : (void)sx;
36 : (void)sy;
37 :
38 144 : int32_t s = 0;
39 :
40 144 : if (width * height > 352 * 288)
41 144 : rst[0].restoration_unit_size = RESTORATION_UNITSIZE_MAX;
42 : else
43 0 : rst[0].restoration_unit_size = (RESTORATION_UNITSIZE_MAX >> 1);
44 144 : rst[1].restoration_unit_size = rst[0].restoration_unit_size >> s;
45 144 : rst[2].restoration_unit_size = rst[1].restoration_unit_size;
46 144 : }
47 :
48 6 : void segmentation_map_dctor(EbPtr p)
49 : {
50 6 : SegmentationNeighborMap *obj = (SegmentationNeighborMap*)p;
51 6 : EB_FREE_ARRAY(obj->data);
52 6 : }
53 :
54 6 : EbErrorType segmentation_map_ctor(SegmentationNeighborMap *seg_neighbor_map,
55 : uint16_t pic_width, uint16_t pic_height){
56 :
57 6 : uint32_t num_elements = (pic_width >> MI_SIZE_LOG2) * (pic_height >> MI_SIZE_LOG2);
58 :
59 6 : seg_neighbor_map->dctor = segmentation_map_dctor;
60 :
61 6 : seg_neighbor_map->map_size = num_elements;
62 6 : EB_CALLOC_ARRAY(seg_neighbor_map->data, num_elements);
63 6 : return EB_ErrorNone;
64 : }
65 :
66 8640 : static void me_sb_results_dctor(EbPtr p)
67 : {
68 8640 : MeLcuResults* obj = (MeLcuResults*)p;
69 :
70 8640 : EB_FREE_ARRAY(obj->me_candidate);
71 8640 : if (obj->me_mv_array) {
72 8640 : EB_FREE_ARRAY(obj->me_mv_array[0]);
73 : }
74 8640 : EB_FREE_ARRAY(obj->me_mv_array);
75 8640 : EB_FREE_ARRAY(obj->me_candidate_array);
76 8640 : EB_FREE_ARRAY(obj->total_me_candidate_index);
77 :
78 8640 : EB_FREE_ARRAY(obj->me_nsq_0);
79 8640 : EB_FREE_ARRAY(obj->me_nsq_1);
80 8640 : }
81 :
82 8640 : EbErrorType me_sb_results_ctor(
83 : MeLcuResults *objectPtr,
84 : uint32_t maxNumberOfPusPerLcu,
85 : uint8_t mrp_mode,
86 : uint32_t maxNumberOfMeCandidatesPerPU){
87 : uint32_t puIndex;
88 :
89 8640 : size_t count = ((mrp_mode == 0) ? ME_MV_MRP_MODE_0 : ME_MV_MRP_MODE_1);
90 8640 : objectPtr->dctor = me_sb_results_dctor;
91 8640 : objectPtr->max_number_of_pus_per_lcu = maxNumberOfPusPerLcu;
92 :
93 8640 : EB_MALLOC_ARRAY(objectPtr->me_candidate, maxNumberOfPusPerLcu);
94 8640 : EB_MALLOC_ARRAY(objectPtr->me_mv_array, maxNumberOfPusPerLcu);
95 : #if ALIGN_MEM
96 : objectPtr->meCandidateArray = (MeCandidate_t*)EB_aligned_malloc(sizeof(MeCandidate_t) * maxNumberOfPusPerLcu * maxNumberOfMeCandidatesPerPU, 64);
97 : #else
98 8640 : EB_MALLOC_ARRAY(objectPtr->me_candidate_array, maxNumberOfPusPerLcu * maxNumberOfMeCandidatesPerPU);
99 : #endif
100 8640 : EB_MALLOC_ARRAY(objectPtr->me_mv_array[0], maxNumberOfPusPerLcu * count);
101 :
102 1278720 : for (puIndex = 0; puIndex < maxNumberOfPusPerLcu; ++puIndex) {
103 1270080 : objectPtr->me_candidate[puIndex] = &objectPtr->me_candidate_array[puIndex * maxNumberOfMeCandidatesPerPU];
104 :
105 1270080 : objectPtr->me_candidate[puIndex][0].ref_idx_l0 = 0;
106 1270080 : objectPtr->me_candidate[puIndex][0].ref_idx_l1 = 0;
107 1270080 : objectPtr->me_candidate[puIndex][1].ref_idx_l0 = 0;
108 1270080 : objectPtr->me_candidate[puIndex][1].ref_idx_l1 = 0;
109 1270080 : objectPtr->me_candidate[puIndex][2].ref_idx_l0 = 0;
110 1270080 : objectPtr->me_candidate[puIndex][2].ref_idx_l1 = 0;
111 :
112 1270080 : objectPtr->me_candidate[puIndex][0].direction = 0;
113 1270080 : objectPtr->me_candidate[puIndex][1].direction = 1;
114 1270080 : objectPtr->me_candidate[puIndex][2].direction = 2;
115 1270080 : objectPtr->me_mv_array[puIndex] = objectPtr->me_mv_array[0] + puIndex * count;
116 : }
117 8640 : EB_MALLOC_ARRAY(objectPtr->total_me_candidate_index, maxNumberOfPusPerLcu);
118 :
119 8640 : EB_MALLOC_ARRAY(objectPtr->me_nsq_0, maxNumberOfPusPerLcu);
120 8640 : EB_MALLOC_ARRAY(objectPtr->me_nsq_1, maxNumberOfPusPerLcu);
121 :
122 : //objectPtr->lcuDistortion = 0;
123 8640 : return EB_ErrorNone;
124 : }
125 :
126 6 : void picture_control_set_dctor(EbPtr p)
127 : {
128 6 : PictureControlSet* obj = (PictureControlSet*)p;
129 : uint8_t depth;
130 6 : av1_hash_table_destroy(&obj->hash_table);
131 6 : EB_FREE_ALIGNED_ARRAY(obj->tpl_mvs);
132 6 : EB_DELETE(obj->enc_dec_segment_ctrl);
133 6 : EB_DELETE(obj->ep_intra_luma_mode_neighbor_array);
134 6 : EB_DELETE(obj->ep_intra_chroma_mode_neighbor_array);
135 6 : EB_DELETE(obj->ep_mv_neighbor_array);
136 6 : EB_DELETE(obj->ep_skip_flag_neighbor_array);
137 6 : EB_DELETE(obj->ep_mode_type_neighbor_array);
138 6 : EB_DELETE(obj->ep_leaf_depth_neighbor_array);
139 6 : EB_DELETE(obj->ep_luma_recon_neighbor_array);
140 6 : EB_DELETE(obj->ep_cb_recon_neighbor_array);
141 6 : EB_DELETE(obj->ep_cr_recon_neighbor_array);
142 6 : EB_DELETE(obj->ep_luma_dc_sign_level_coeff_neighbor_array);
143 6 : EB_DELETE(obj->ep_cb_dc_sign_level_coeff_neighbor_array);
144 6 : EB_DELETE(obj->ep_cr_dc_sign_level_coeff_neighbor_array);
145 6 : EB_DELETE(obj->mode_type_neighbor_array);
146 6 : EB_DELETE(obj->partition_context_neighbor_array);
147 6 : EB_DELETE(obj->skip_flag_neighbor_array);
148 6 : EB_DELETE(obj->skip_coeff_neighbor_array);
149 6 : EB_DELETE(obj->luma_dc_sign_level_coeff_neighbor_array);
150 6 : EB_DELETE(obj->cr_dc_sign_level_coeff_neighbor_array);
151 6 : EB_DELETE(obj->cb_dc_sign_level_coeff_neighbor_array);
152 6 : EB_DELETE(obj->inter_pred_dir_neighbor_array);
153 6 : EB_DELETE(obj->ref_frame_type_neighbor_array);
154 6 : EB_DELETE(obj->intra_luma_mode_neighbor_array);
155 6 : EB_DELETE(obj->txfm_context_array);
156 6 : EB_DELETE(obj->segmentation_id_pred_array);
157 6 : EB_DELETE(obj->segmentation_neighbor_map);
158 6 : EB_DELETE(obj->ep_luma_recon_neighbor_array16bit);
159 6 : EB_DELETE(obj->ep_cb_recon_neighbor_array16bit);
160 6 : EB_DELETE(obj->ep_cr_recon_neighbor_array16bit);
161 6 : EB_DELETE(obj->interpolation_type_neighbor_array);
162 :
163 30 : for (depth = 0; depth < NEIGHBOR_ARRAY_TOTAL_COUNT; depth++) {
164 24 : EB_DELETE(obj->md_intra_luma_mode_neighbor_array[depth]);
165 24 : EB_DELETE(obj->md_intra_chroma_mode_neighbor_array[depth]);
166 24 : EB_DELETE(obj->md_mv_neighbor_array[depth]);
167 24 : EB_DELETE(obj->md_skip_flag_neighbor_array[depth]);
168 24 : EB_DELETE(obj->md_mode_type_neighbor_array[depth]);
169 24 : EB_DELETE(obj->md_leaf_depth_neighbor_array[depth]);
170 24 : EB_DELETE(obj->mdleaf_partition_neighbor_array[depth]);
171 :
172 : #if !HBD_CLEAN_UP // md_luma_recon_neighbor_array16bit md_tx_depth_1_luma_recon_neighbor_array16bit
173 : if (obj->hbd_mode_decision) {
174 : #else
175 24 : if (obj->hbd_mode_decision > EB_8_BIT_MD){
176 : #endif
177 0 : EB_DELETE(obj->md_luma_recon_neighbor_array16bit[depth]);
178 0 : EB_DELETE(obj->md_tx_depth_1_luma_recon_neighbor_array16bit[depth]);
179 0 : EB_DELETE(obj->md_cb_recon_neighbor_array16bit[depth]);
180 0 : EB_DELETE(obj->md_cr_recon_neighbor_array16bit[depth]);
181 : }
182 : #if HBD_CLEAN_UP
183 24 : if (obj->hbd_mode_decision != EB_10_BIT_MD){
184 : #else
185 : else {
186 : #endif
187 24 : EB_DELETE(obj->md_luma_recon_neighbor_array[depth]);
188 24 : EB_DELETE(obj->md_tx_depth_1_luma_recon_neighbor_array[depth]);
189 24 : EB_DELETE(obj->md_cb_recon_neighbor_array[depth]);
190 24 : EB_DELETE(obj->md_cr_recon_neighbor_array[depth]);
191 : }
192 :
193 24 : EB_DELETE(obj->md_skip_coeff_neighbor_array[depth]);
194 24 : EB_DELETE(obj->md_luma_dc_sign_level_coeff_neighbor_array[depth]);
195 24 : EB_DELETE(obj->md_tx_depth_1_luma_dc_sign_level_coeff_neighbor_array[depth]);
196 24 : EB_DELETE(obj->md_cr_dc_sign_level_coeff_neighbor_array[depth]);
197 24 : EB_DELETE(obj->md_cb_dc_sign_level_coeff_neighbor_array[depth]);
198 24 : EB_DELETE(obj->md_txfm_context_array[depth]);
199 24 : EB_DELETE(obj->md_inter_pred_dir_neighbor_array[depth]);
200 24 : EB_DELETE(obj->md_ref_frame_type_neighbor_array[depth]);
201 24 : EB_DELETE(obj->md_interpolation_type_neighbor_array[depth]);
202 : }
203 366 : EB_DELETE_PTR_ARRAY(obj->sb_ptr_array, obj->sb_total_count);
204 6 : EB_DELETE(obj->coeff_est_entropy_coder_ptr);
205 6 : EB_DELETE(obj->bitstream_ptr);
206 6 : EB_DELETE(obj->entropy_coder_ptr);
207 6 : EB_DELETE(obj->recon_picture32bit_ptr);
208 6 : EB_DELETE(obj->recon_picture16bit_ptr);
209 6 : EB_DELETE(obj->recon_picture_ptr);
210 6 : EB_DELETE(obj->film_grain_picture16bit_ptr);
211 6 : EB_DELETE(obj->film_grain_picture_ptr);
212 6 : EB_DELETE(obj->input_frame16bit);
213 :
214 :
215 6 : EB_FREE_ARRAY(obj->mse_seg[0]);
216 6 : EB_FREE_ARRAY(obj->mse_seg[1]);
217 :
218 6 : EB_FREE_ARRAY(obj->mi_grid_base);
219 6 : EB_FREE_ARRAY(obj->mip);
220 6 : EB_FREE_ARRAY(obj->md_rate_estimation_array);
221 6 : EB_FREE_ARRAY(obj->ec_ctx_array);
222 6 : EB_FREE_ARRAY(obj->rate_est_array);
223 : #if PAL_SUP
224 6 : if(obj->tile_tok[0][0])
225 6 : EB_FREE_ARRAY(obj->tile_tok[0][0]);
226 : #endif
227 6 : EB_FREE_ARRAY(obj->mdc_sb_array);
228 6 : EB_FREE_ARRAY(obj->qp_array);
229 6 : EB_DESTROY_MUTEX(obj->entropy_coding_mutex);
230 6 : EB_DESTROY_MUTEX(obj->intra_mutex);
231 6 : EB_DESTROY_MUTEX(obj->cdef_search_mutex);
232 6 : EB_DESTROY_MUTEX(obj->rest_search_mutex);
233 :
234 6 : }
235 : #if PAL_SUP
236 : // Token buffer is only used for palette tokens.
237 6 : static INLINE unsigned int get_token_alloc(int mb_rows, int mb_cols,
238 : int sb_size_log2,
239 : const int num_planes) {
240 : // Calculate the maximum number of max superblocks in the image.
241 6 : const int shift = sb_size_log2 - 4;
242 6 : const int sb_size = 1 << sb_size_log2;
243 6 : const int sb_size_square = sb_size * sb_size;
244 6 : const int sb_rows = ALIGN_POWER_OF_TWO(mb_rows, shift) >> shift;
245 6 : const int sb_cols = ALIGN_POWER_OF_TWO(mb_cols, shift) >> shift;
246 :
247 : // One palette token for each pixel. There can be palettes on two planes.
248 6 : const int sb_palette_toks = AOMMIN(2, num_planes) * sb_size_square;
249 :
250 6 : return sb_rows * sb_cols * sb_palette_toks;
251 : }
252 : #endif
253 :
254 : typedef struct InitData {
255 : NeighborArrayUnit **na_unit_dbl_ptr;
256 : uint32_t max_picture_width;
257 : uint32_t max_picture_height;
258 : uint32_t unit_size;
259 : uint32_t granularity_normal;
260 : uint32_t granularity_top_left;
261 : uint32_t type_mask;
262 : } InitData;
263 :
264 : #define DIM(array) (sizeof(array) / sizeof(array[0]))
265 54 : EbErrorType create_neighbor_array_units(InitData* data, size_t count)
266 : {
267 654 : for (size_t i = 0; i < count; i++) {
268 600 : EB_NEW(
269 : *data[i].na_unit_dbl_ptr,
270 : neighbor_array_unit_ctor,
271 : data[i].max_picture_width,
272 : data[i].max_picture_height,
273 : data[i].unit_size,
274 : data[i].granularity_normal,
275 : data[i].granularity_top_left,
276 : data[i].type_mask);
277 : }
278 54 : return EB_ErrorNone;
279 : }
280 :
281 6 : EbErrorType picture_control_set_ctor(
282 : PictureControlSet *object_ptr,
283 : EbPtr object_init_data_ptr)
284 : {
285 6 : PictureControlSetInitData *initDataPtr = (PictureControlSetInitData*)object_init_data_ptr;
286 :
287 : EbPictureBufferDescInitData input_picture_buffer_desc_init_data;
288 : EbPictureBufferDescInitData coeffBufferDescInitData;
289 :
290 : // Max/Min CU Sizes
291 6 : const uint32_t maxCuSize = initDataPtr->sb_size_pix;
292 : // LCUs
293 6 : const uint16_t pictureLcuWidth = (uint16_t)((initDataPtr->picture_width + initDataPtr->sb_sz - 1) / initDataPtr->sb_sz);
294 6 : const uint16_t pictureLcuHeight = (uint16_t)((initDataPtr->picture_height + initDataPtr->sb_sz - 1) / initDataPtr->sb_sz);
295 : uint16_t sb_index;
296 : uint16_t sb_origin_x;
297 : uint16_t sb_origin_y;
298 6 : EbErrorType return_error = EB_ErrorNone;
299 :
300 6 : EbBool is16bit = initDataPtr->bit_depth > 8 ? EB_TRUE : EB_FALSE;
301 6 : const uint16_t subsampling_x = (initDataPtr->color_format == EB_YUV444 ? 1 : 2) - 1;
302 6 : const uint16_t subsampling_y = (initDataPtr->color_format >= EB_YUV422 ? 1 : 2) - 1;
303 :
304 6 : object_ptr->dctor = picture_control_set_dctor;
305 :
306 : // Init Picture Init data
307 6 : input_picture_buffer_desc_init_data.max_width = initDataPtr->picture_width;
308 6 : input_picture_buffer_desc_init_data.max_height = initDataPtr->picture_height;
309 6 : input_picture_buffer_desc_init_data.bit_depth = initDataPtr->bit_depth;
310 6 : input_picture_buffer_desc_init_data.buffer_enable_mask = PICTURE_BUFFER_DESC_FULL_MASK;
311 6 : input_picture_buffer_desc_init_data.color_format = initDataPtr->color_format;
312 :
313 6 : input_picture_buffer_desc_init_data.left_padding = PAD_VALUE;
314 6 : input_picture_buffer_desc_init_data.right_padding = PAD_VALUE;
315 6 : input_picture_buffer_desc_init_data.top_padding = PAD_VALUE;
316 6 : input_picture_buffer_desc_init_data.bot_padding = PAD_VALUE;
317 :
318 6 : input_picture_buffer_desc_init_data.split_mode = EB_FALSE;
319 :
320 6 : coeffBufferDescInitData.max_width = initDataPtr->picture_width;
321 6 : coeffBufferDescInitData.max_height = initDataPtr->picture_height;
322 6 : coeffBufferDescInitData.bit_depth = EB_16BIT;
323 6 : coeffBufferDescInitData.buffer_enable_mask = PICTURE_BUFFER_DESC_FULL_MASK;
324 6 : coeffBufferDescInitData.color_format = initDataPtr->color_format;
325 :
326 6 : coeffBufferDescInitData.left_padding = PAD_VALUE;
327 6 : coeffBufferDescInitData.right_padding = PAD_VALUE;
328 6 : coeffBufferDescInitData.top_padding = PAD_VALUE;
329 6 : coeffBufferDescInitData.bot_padding = PAD_VALUE;
330 :
331 6 : coeffBufferDescInitData.split_mode = EB_FALSE;
332 :
333 6 : object_ptr->sequence_control_set_wrapper_ptr = (EbObjectWrapper *)EB_NULL;
334 :
335 6 : object_ptr->recon_picture16bit_ptr = (EbPictureBufferDesc *)EB_NULL;
336 6 : object_ptr->recon_picture_ptr = (EbPictureBufferDesc *)EB_NULL;
337 6 : object_ptr->color_format = initDataPtr->color_format;
338 :
339 : EbPictureBufferDescInitData coeffBufferDes32bitInitData;
340 6 : coeffBufferDes32bitInitData.max_width = initDataPtr->picture_width;
341 6 : coeffBufferDes32bitInitData.max_height = initDataPtr->picture_height;
342 6 : coeffBufferDes32bitInitData.bit_depth = EB_32BIT;
343 6 : coeffBufferDes32bitInitData.buffer_enable_mask = PICTURE_BUFFER_DESC_FULL_MASK;
344 6 : coeffBufferDes32bitInitData.color_format = initDataPtr->color_format;
345 6 : coeffBufferDes32bitInitData.left_padding = 0;
346 6 : coeffBufferDes32bitInitData.right_padding = 0;
347 6 : coeffBufferDes32bitInitData.top_padding = 0;
348 6 : coeffBufferDes32bitInitData.bot_padding = 0;
349 6 : coeffBufferDes32bitInitData.split_mode = EB_FALSE;
350 :
351 6 : object_ptr->recon_picture32bit_ptr = (EbPictureBufferDesc *)EB_NULL;
352 6 : EB_NEW(
353 : object_ptr->recon_picture32bit_ptr,
354 : eb_recon_picture_buffer_desc_ctor,
355 : (EbPtr)&coeffBufferDes32bitInitData);
356 :
357 : // Reconstructed Picture Buffer
358 6 : if (is16bit) {
359 0 : EB_NEW(
360 : object_ptr->recon_picture16bit_ptr,
361 : eb_recon_picture_buffer_desc_ctor,
362 : (EbPtr)&coeffBufferDescInitData);
363 : }
364 : else
365 : {
366 6 : EB_NEW(
367 : object_ptr->recon_picture_ptr,
368 : eb_recon_picture_buffer_desc_ctor,
369 : (EbPtr)&input_picture_buffer_desc_init_data);
370 : }
371 : // Film Grain Picture Buffer
372 6 : if (initDataPtr->film_grain_noise_level) {
373 0 : if (is16bit) {
374 0 : EB_NEW(
375 : object_ptr->film_grain_picture16bit_ptr,
376 : eb_recon_picture_buffer_desc_ctor,
377 : (EbPtr)&coeffBufferDescInitData);
378 : }
379 : else
380 : {
381 0 : EB_NEW(
382 : object_ptr->film_grain_picture_ptr,
383 : eb_recon_picture_buffer_desc_ctor,
384 : (EbPtr)&input_picture_buffer_desc_init_data);
385 : }
386 : }
387 :
388 6 : if (is16bit) {
389 0 : EB_NEW(
390 : object_ptr->input_frame16bit,
391 : eb_picture_buffer_desc_ctor,
392 : (EbPtr)&coeffBufferDescInitData);
393 : }
394 : // Entropy Coder
395 6 : EB_NEW(
396 : object_ptr->entropy_coder_ptr,
397 : entropy_coder_ctor,
398 : SEGMENT_ENTROPY_BUFFER_SIZE);
399 :
400 : // Packetization process Bitstream
401 6 : EB_NEW(
402 : object_ptr->bitstream_ptr,
403 : bitstream_ctor,
404 : PACKETIZATION_PROCESS_BUFFER_SIZE);
405 :
406 6 : if (return_error == EB_ErrorInsufficientResources)
407 0 : return EB_ErrorInsufficientResources;
408 : // Rate estimation entropy coder
409 6 : EB_NEW(
410 : object_ptr->coeff_est_entropy_coder_ptr,
411 : entropy_coder_ctor,
412 : SEGMENT_ENTROPY_BUFFER_SIZE);
413 : // GOP
414 6 : object_ptr->picture_number = 0;
415 6 : object_ptr->temporal_layer_index = 0;
416 :
417 : // SB Array
418 6 : object_ptr->sb_max_depth = (uint8_t)initDataPtr->max_depth;
419 6 : object_ptr->sb_total_count = pictureLcuWidth * pictureLcuHeight;
420 6 : EB_ALLOC_PTR_ARRAY(object_ptr->sb_ptr_array, object_ptr->sb_total_count);
421 :
422 6 : sb_origin_x = 0;
423 6 : sb_origin_y = 0;
424 :
425 6 : const uint16_t picture_sb_w = (uint16_t)((initDataPtr->picture_width + initDataPtr->sb_size_pix - 1) / initDataPtr->sb_size_pix);
426 6 : const uint16_t picture_sb_h = (uint16_t)((initDataPtr->picture_height + initDataPtr->sb_size_pix - 1) / initDataPtr->sb_size_pix);
427 6 : const uint16_t all_sb = picture_sb_w * picture_sb_h;
428 :
429 366 : for (sb_index = 0; sb_index < all_sb; ++sb_index) {
430 360 : EB_NEW(
431 : object_ptr->sb_ptr_array[sb_index],
432 : largest_coding_unit_ctor,
433 : (uint8_t)initDataPtr->sb_size_pix,
434 : (uint16_t)(sb_origin_x * maxCuSize),
435 : (uint16_t)(sb_origin_y * maxCuSize),
436 : (uint16_t)sb_index,
437 : object_ptr);
438 : // Increment the Order in coding order (Raster Scan Order)
439 360 : sb_origin_y = (sb_origin_x == picture_sb_w - 1) ? sb_origin_y + 1 : sb_origin_y;
440 360 : sb_origin_x = (sb_origin_x == picture_sb_w - 1) ? 0 : sb_origin_x + 1;
441 : }
442 : // MD Rate Estimation Array
443 6 : EB_MALLOC_ARRAY(object_ptr->md_rate_estimation_array, 1);
444 6 : memset(object_ptr->md_rate_estimation_array, 0, sizeof(MdRateEstimationContext));
445 :
446 6 : EB_MALLOC_ARRAY(object_ptr->ec_ctx_array, all_sb);
447 6 : EB_MALLOC_ARRAY(object_ptr->rate_est_array, all_sb);
448 :
449 : #if PAL_SUP
450 6 : if (initDataPtr->cfg_palette){
451 6 : uint32_t mi_cols = initDataPtr->picture_width >> MI_SIZE_LOG2;
452 6 : uint32_t mi_rows = initDataPtr->picture_height >> MI_SIZE_LOG2;
453 6 : uint32_t mb_cols = (mi_cols + 2) >> 2;
454 6 : uint32_t mb_rows = (mi_rows + 2) >> 2;
455 : unsigned int tokens =
456 6 : get_token_alloc(mb_rows, mb_cols, MAX_SB_SIZE_LOG2, 2);
457 6 : EB_CALLOC_ARRAY(object_ptr->tile_tok[0][0], tokens);
458 : }
459 : else
460 0 : object_ptr->tile_tok[0][0] = NULL;
461 : #endif
462 : // Mode Decision Control config
463 6 : EB_MALLOC_ARRAY(object_ptr->mdc_sb_array, object_ptr->sb_total_count);
464 6 : object_ptr->qp_array_stride = (uint16_t)((initDataPtr->picture_width + MIN_BLOCK_SIZE - 1) / MIN_BLOCK_SIZE);
465 6 : object_ptr->qp_array_size = ((initDataPtr->picture_width + MIN_BLOCK_SIZE - 1) / MIN_BLOCK_SIZE) *
466 6 : ((initDataPtr->picture_height + MIN_BLOCK_SIZE - 1) / MIN_BLOCK_SIZE);
467 :
468 : // Allocate memory for qp array (used by DLF)
469 6 : EB_MALLOC_ARRAY(object_ptr->qp_array, object_ptr->qp_array_size);
470 :
471 6 : object_ptr->hbd_mode_decision = initDataPtr->hbd_mode_decision;
472 : // Mode Decision Neighbor Arrays
473 : uint8_t depth;
474 30 : for (depth = 0; depth < NEIGHBOR_ARRAY_TOTAL_COUNT; depth++) {
475 24 : InitData data[] = {
476 : {
477 24 : &object_ptr->md_intra_luma_mode_neighbor_array[depth],
478 : MAX_PICTURE_WIDTH_SIZE,
479 : MAX_PICTURE_HEIGHT_SIZE,
480 : sizeof(uint8_t),
481 : PU_NEIGHBOR_ARRAY_GRANULARITY,
482 : PU_NEIGHBOR_ARRAY_GRANULARITY,
483 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK
484 : },
485 : {
486 24 : &object_ptr->md_intra_chroma_mode_neighbor_array[depth],
487 24 : MAX_PICTURE_WIDTH_SIZE >> subsampling_x,
488 24 : MAX_PICTURE_HEIGHT_SIZE >> subsampling_y,
489 : sizeof(uint8_t),
490 : PU_NEIGHBOR_ARRAY_GRANULARITY,
491 : PU_NEIGHBOR_ARRAY_GRANULARITY,
492 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
493 : },
494 : {
495 24 : &object_ptr->md_mv_neighbor_array[depth],
496 : MAX_PICTURE_WIDTH_SIZE,
497 : MAX_PICTURE_HEIGHT_SIZE,
498 : sizeof(MvUnit),
499 : PU_NEIGHBOR_ARRAY_GRANULARITY,
500 : PU_NEIGHBOR_ARRAY_GRANULARITY,
501 : NEIGHBOR_ARRAY_UNIT_FULL_MASK,
502 : },
503 : {
504 24 : &object_ptr->md_skip_flag_neighbor_array[depth],
505 : MAX_PICTURE_WIDTH_SIZE,
506 : MAX_PICTURE_HEIGHT_SIZE,
507 : sizeof(uint8_t),
508 : PU_NEIGHBOR_ARRAY_GRANULARITY,
509 : PU_NEIGHBOR_ARRAY_GRANULARITY,
510 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
511 : },
512 : {
513 24 : &object_ptr->md_mode_type_neighbor_array[depth],
514 : MAX_PICTURE_WIDTH_SIZE,
515 : MAX_PICTURE_HEIGHT_SIZE,
516 : sizeof(uint8_t),
517 : PU_NEIGHBOR_ARRAY_GRANULARITY,
518 : PU_NEIGHBOR_ARRAY_GRANULARITY,
519 : NEIGHBOR_ARRAY_UNIT_FULL_MASK,
520 : },
521 : {
522 24 : &object_ptr->md_leaf_depth_neighbor_array[depth],
523 : MAX_PICTURE_WIDTH_SIZE,
524 : MAX_PICTURE_HEIGHT_SIZE,
525 : sizeof(uint8_t),
526 : PU_NEIGHBOR_ARRAY_GRANULARITY,
527 : PU_NEIGHBOR_ARRAY_GRANULARITY,
528 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
529 : },
530 : {
531 24 : &object_ptr->mdleaf_partition_neighbor_array[depth],
532 : MAX_PICTURE_WIDTH_SIZE,
533 : MAX_PICTURE_HEIGHT_SIZE,
534 : sizeof(struct PartitionContext),
535 : PU_NEIGHBOR_ARRAY_GRANULARITY,
536 : PU_NEIGHBOR_ARRAY_GRANULARITY,
537 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
538 : },
539 : {
540 24 : &object_ptr->md_skip_coeff_neighbor_array[depth],
541 : MAX_PICTURE_WIDTH_SIZE,
542 : MAX_PICTURE_HEIGHT_SIZE,
543 : sizeof(uint8_t),
544 : PU_NEIGHBOR_ARRAY_GRANULARITY,
545 : PU_NEIGHBOR_ARRAY_GRANULARITY,
546 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
547 : },
548 : // for each 4x4
549 : {
550 24 : &object_ptr->md_luma_dc_sign_level_coeff_neighbor_array[depth],
551 : MAX_PICTURE_WIDTH_SIZE,
552 : MAX_PICTURE_HEIGHT_SIZE,
553 : sizeof(uint8_t),
554 : PU_NEIGHBOR_ARRAY_GRANULARITY,
555 : PU_NEIGHBOR_ARRAY_GRANULARITY,
556 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
557 : },
558 : // for each 4x4
559 : {
560 24 : &object_ptr->md_tx_depth_1_luma_dc_sign_level_coeff_neighbor_array[depth],
561 : MAX_PICTURE_WIDTH_SIZE,
562 : MAX_PICTURE_HEIGHT_SIZE,
563 : sizeof(uint8_t),
564 : PU_NEIGHBOR_ARRAY_GRANULARITY,
565 : PU_NEIGHBOR_ARRAY_GRANULARITY,
566 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
567 : },
568 : // for each 4x4
569 : {
570 24 : &object_ptr->md_cr_dc_sign_level_coeff_neighbor_array[depth],
571 : MAX_PICTURE_WIDTH_SIZE,
572 : MAX_PICTURE_HEIGHT_SIZE,
573 : sizeof(uint8_t),
574 : PU_NEIGHBOR_ARRAY_GRANULARITY,
575 : PU_NEIGHBOR_ARRAY_GRANULARITY,
576 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
577 : },
578 : // for each 4x4
579 : {
580 24 : &object_ptr->md_cb_dc_sign_level_coeff_neighbor_array[depth],
581 : MAX_PICTURE_WIDTH_SIZE,
582 : MAX_PICTURE_HEIGHT_SIZE,
583 : sizeof(uint8_t),
584 : PU_NEIGHBOR_ARRAY_GRANULARITY,
585 : PU_NEIGHBOR_ARRAY_GRANULARITY,
586 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
587 : },
588 : {
589 24 : &object_ptr->md_txfm_context_array[depth],
590 : MAX_PICTURE_WIDTH_SIZE,
591 : MAX_PICTURE_HEIGHT_SIZE,
592 : sizeof(TXFM_CONTEXT),
593 : PU_NEIGHBOR_ARRAY_GRANULARITY,
594 : PU_NEIGHBOR_ARRAY_GRANULARITY,
595 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
596 : },
597 : {
598 24 : &object_ptr->md_inter_pred_dir_neighbor_array[depth],
599 : MAX_PICTURE_WIDTH_SIZE,
600 : MAX_PICTURE_HEIGHT_SIZE,
601 : sizeof(uint8_t),
602 : PU_NEIGHBOR_ARRAY_GRANULARITY,
603 : PU_NEIGHBOR_ARRAY_GRANULARITY,
604 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
605 : },
606 : {
607 24 : &object_ptr->md_ref_frame_type_neighbor_array[depth],
608 : MAX_PICTURE_WIDTH_SIZE,
609 : MAX_PICTURE_HEIGHT_SIZE,
610 : sizeof(uint8_t),
611 : PU_NEIGHBOR_ARRAY_GRANULARITY,
612 : PU_NEIGHBOR_ARRAY_GRANULARITY,
613 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
614 : }
615 : };
616 24 : return_error = create_neighbor_array_units(data, DIM(data));
617 24 : if (return_error == EB_ErrorInsufficientResources)
618 0 : return EB_ErrorInsufficientResources;
619 : #if HBD_CLEAN_UP //md_luma_recon_neighbor_array
620 24 : if (initDataPtr->hbd_mode_decision != EB_10_BIT_MD) {
621 : #else
622 : if (!initDataPtr->hbd_mode_decision) {
623 : #endif
624 24 : InitData data[] = {
625 :
626 : {
627 24 : &object_ptr->md_luma_recon_neighbor_array[depth],
628 : MAX_PICTURE_WIDTH_SIZE,
629 : MAX_PICTURE_HEIGHT_SIZE,
630 : sizeof(uint8_t),
631 : SAMPLE_NEIGHBOR_ARRAY_GRANULARITY,
632 : SAMPLE_NEIGHBOR_ARRAY_GRANULARITY,
633 : NEIGHBOR_ARRAY_UNIT_FULL_MASK,
634 : },
635 : {
636 24 : &object_ptr->md_tx_depth_1_luma_recon_neighbor_array[depth],
637 : MAX_PICTURE_WIDTH_SIZE,
638 : MAX_PICTURE_HEIGHT_SIZE,
639 : sizeof(uint8_t),
640 : SAMPLE_NEIGHBOR_ARRAY_GRANULARITY,
641 : SAMPLE_NEIGHBOR_ARRAY_GRANULARITY,
642 : NEIGHBOR_ARRAY_UNIT_FULL_MASK,
643 : },
644 : {
645 24 : &object_ptr->md_cb_recon_neighbor_array[depth],
646 24 : MAX_PICTURE_WIDTH_SIZE >> subsampling_x,
647 24 : MAX_PICTURE_HEIGHT_SIZE >> subsampling_y,
648 : sizeof(uint8_t),
649 : SAMPLE_NEIGHBOR_ARRAY_GRANULARITY,
650 : SAMPLE_NEIGHBOR_ARRAY_GRANULARITY,
651 : NEIGHBOR_ARRAY_UNIT_FULL_MASK,
652 : },
653 : {
654 24 : &object_ptr->md_cr_recon_neighbor_array[depth],
655 24 : MAX_PICTURE_WIDTH_SIZE >> subsampling_x,
656 24 : MAX_PICTURE_HEIGHT_SIZE >> subsampling_y,
657 : sizeof(uint8_t),
658 : SAMPLE_NEIGHBOR_ARRAY_GRANULARITY,
659 : SAMPLE_NEIGHBOR_ARRAY_GRANULARITY,
660 : NEIGHBOR_ARRAY_UNIT_FULL_MASK,
661 : }
662 :
663 : };
664 24 : return_error = create_neighbor_array_units(data, DIM(data));
665 24 : if (return_error == EB_ErrorInsufficientResources)
666 0 : return EB_ErrorInsufficientResources;
667 : }
668 : #if HBD_CLEAN_UP
669 :
670 24 : if (initDataPtr->hbd_mode_decision > EB_8_BIT_MD) {
671 : #else
672 : else {
673 : #endif
674 0 : InitData data[] = {
675 : {
676 0 : &object_ptr->md_luma_recon_neighbor_array16bit[depth],
677 : MAX_PICTURE_WIDTH_SIZE,
678 : MAX_PICTURE_HEIGHT_SIZE,
679 : sizeof(uint16_t),
680 : SAMPLE_NEIGHBOR_ARRAY_GRANULARITY,
681 : SAMPLE_NEIGHBOR_ARRAY_GRANULARITY,
682 : NEIGHBOR_ARRAY_UNIT_FULL_MASK,
683 : },
684 : {
685 0 : &object_ptr->md_tx_depth_1_luma_recon_neighbor_array16bit[depth],
686 : MAX_PICTURE_WIDTH_SIZE,
687 : MAX_PICTURE_HEIGHT_SIZE,
688 : sizeof(uint16_t),
689 : SAMPLE_NEIGHBOR_ARRAY_GRANULARITY,
690 : SAMPLE_NEIGHBOR_ARRAY_GRANULARITY,
691 : NEIGHBOR_ARRAY_UNIT_FULL_MASK,
692 : },
693 : {
694 0 : &object_ptr->md_cb_recon_neighbor_array16bit[depth],
695 0 : MAX_PICTURE_WIDTH_SIZE >> subsampling_x,
696 0 : MAX_PICTURE_HEIGHT_SIZE >> subsampling_y,
697 : sizeof(uint16_t),
698 : SAMPLE_NEIGHBOR_ARRAY_GRANULARITY,
699 : SAMPLE_NEIGHBOR_ARRAY_GRANULARITY,
700 : NEIGHBOR_ARRAY_UNIT_FULL_MASK,
701 : },
702 : {
703 0 : &object_ptr->md_cr_recon_neighbor_array16bit[depth],
704 0 : MAX_PICTURE_WIDTH_SIZE >> subsampling_x,
705 0 : MAX_PICTURE_HEIGHT_SIZE >> subsampling_y,
706 : sizeof(uint16_t),
707 : SAMPLE_NEIGHBOR_ARRAY_GRANULARITY,
708 : SAMPLE_NEIGHBOR_ARRAY_GRANULARITY,
709 : NEIGHBOR_ARRAY_UNIT_FULL_MASK,
710 : }
711 : };
712 0 : return_error = create_neighbor_array_units(data, DIM(data));
713 0 : if (return_error == EB_ErrorInsufficientResources)
714 0 : return EB_ErrorInsufficientResources;
715 : }
716 :
717 24 : EB_NEW(
718 : object_ptr->md_interpolation_type_neighbor_array[depth],
719 : neighbor_array_unit_ctor32,
720 : MAX_PICTURE_WIDTH_SIZE,
721 : MAX_PICTURE_HEIGHT_SIZE,
722 : sizeof(uint32_t),
723 : PU_NEIGHBOR_ARRAY_GRANULARITY,
724 : PU_NEIGHBOR_ARRAY_GRANULARITY,
725 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK);
726 : }
727 : {
728 6 : InitData data[] = {
729 : {
730 6 : &object_ptr->ep_intra_luma_mode_neighbor_array,
731 : MAX_PICTURE_WIDTH_SIZE,
732 : MAX_PICTURE_HEIGHT_SIZE,
733 : sizeof(uint8_t),
734 : PU_NEIGHBOR_ARRAY_GRANULARITY,
735 : PU_NEIGHBOR_ARRAY_GRANULARITY,
736 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
737 : },
738 : // Encode Pass Neighbor Arrays
739 : {
740 6 : &object_ptr->ep_intra_chroma_mode_neighbor_array,
741 6 : MAX_PICTURE_WIDTH_SIZE >> subsampling_x,
742 6 : MAX_PICTURE_HEIGHT_SIZE >> subsampling_y,
743 : sizeof(uint8_t),
744 : PU_NEIGHBOR_ARRAY_GRANULARITY,
745 : PU_NEIGHBOR_ARRAY_GRANULARITY,
746 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
747 : },
748 : {
749 6 : &object_ptr->ep_mv_neighbor_array,
750 : MAX_PICTURE_WIDTH_SIZE,
751 : MAX_PICTURE_HEIGHT_SIZE,
752 : sizeof(MvUnit),
753 : PU_NEIGHBOR_ARRAY_GRANULARITY,
754 : PU_NEIGHBOR_ARRAY_GRANULARITY,
755 : NEIGHBOR_ARRAY_UNIT_FULL_MASK,
756 : },
757 : {
758 6 : &object_ptr->ep_skip_flag_neighbor_array,
759 : MAX_PICTURE_WIDTH_SIZE,
760 : MAX_PICTURE_HEIGHT_SIZE,
761 : sizeof(uint8_t),
762 : CU_NEIGHBOR_ARRAY_GRANULARITY,
763 : CU_NEIGHBOR_ARRAY_GRANULARITY,
764 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
765 : },
766 : {
767 6 : &object_ptr->ep_mode_type_neighbor_array,
768 : MAX_PICTURE_WIDTH_SIZE,
769 : MAX_PICTURE_HEIGHT_SIZE,
770 : sizeof(uint8_t),
771 : PU_NEIGHBOR_ARRAY_GRANULARITY,
772 : PU_NEIGHBOR_ARRAY_GRANULARITY,
773 : NEIGHBOR_ARRAY_UNIT_FULL_MASK,
774 : },
775 : {
776 6 : &object_ptr->ep_leaf_depth_neighbor_array,
777 : MAX_PICTURE_WIDTH_SIZE,
778 : MAX_PICTURE_HEIGHT_SIZE,
779 : sizeof(uint8_t),
780 : PU_NEIGHBOR_ARRAY_GRANULARITY,
781 : PU_NEIGHBOR_ARRAY_GRANULARITY,
782 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
783 : },
784 : {
785 6 : &object_ptr->ep_luma_recon_neighbor_array,
786 : MAX_PICTURE_WIDTH_SIZE,
787 : MAX_PICTURE_HEIGHT_SIZE,
788 : sizeof(uint8_t),
789 : SAMPLE_NEIGHBOR_ARRAY_GRANULARITY,
790 : SAMPLE_NEIGHBOR_ARRAY_GRANULARITY,
791 : NEIGHBOR_ARRAY_UNIT_FULL_MASK,
792 : },
793 : {
794 6 : &object_ptr->ep_cb_recon_neighbor_array,
795 6 : MAX_PICTURE_WIDTH_SIZE >> subsampling_x,
796 6 : MAX_PICTURE_HEIGHT_SIZE >> subsampling_y,
797 : sizeof(uint8_t),
798 : SAMPLE_NEIGHBOR_ARRAY_GRANULARITY,
799 : SAMPLE_NEIGHBOR_ARRAY_GRANULARITY,
800 : NEIGHBOR_ARRAY_UNIT_FULL_MASK,
801 : },
802 : {
803 6 : &object_ptr->ep_cr_recon_neighbor_array,
804 6 : MAX_PICTURE_WIDTH_SIZE >> subsampling_x,
805 6 : MAX_PICTURE_HEIGHT_SIZE >> subsampling_y,
806 : sizeof(uint8_t),
807 : SAMPLE_NEIGHBOR_ARRAY_GRANULARITY,
808 : SAMPLE_NEIGHBOR_ARRAY_GRANULARITY,
809 : NEIGHBOR_ARRAY_UNIT_FULL_MASK,
810 : },
811 : // for each 4x4
812 : {
813 6 : &object_ptr->ep_luma_dc_sign_level_coeff_neighbor_array,
814 : MAX_PICTURE_WIDTH_SIZE,
815 : MAX_PICTURE_HEIGHT_SIZE,
816 : sizeof(uint8_t),
817 : PU_NEIGHBOR_ARRAY_GRANULARITY,
818 : PU_NEIGHBOR_ARRAY_GRANULARITY,
819 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
820 : },
821 : // for each 4x4
822 : {
823 6 : &object_ptr->ep_cb_dc_sign_level_coeff_neighbor_array,
824 : MAX_PICTURE_WIDTH_SIZE,
825 : MAX_PICTURE_HEIGHT_SIZE,
826 : sizeof(uint8_t),
827 : PU_NEIGHBOR_ARRAY_GRANULARITY,
828 : PU_NEIGHBOR_ARRAY_GRANULARITY,
829 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
830 : },
831 : // for each 4x4
832 : {
833 6 : &object_ptr->ep_cr_dc_sign_level_coeff_neighbor_array,
834 : MAX_PICTURE_WIDTH_SIZE,
835 : MAX_PICTURE_HEIGHT_SIZE,
836 : sizeof(uint8_t),
837 : PU_NEIGHBOR_ARRAY_GRANULARITY,
838 : PU_NEIGHBOR_ARRAY_GRANULARITY,
839 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
840 : },
841 :
842 : // Entropy Coding Neighbor Arrays
843 : {
844 6 : &object_ptr->mode_type_neighbor_array,
845 : MAX_PICTURE_WIDTH_SIZE,
846 : MAX_PICTURE_HEIGHT_SIZE,
847 : sizeof(uint8_t),
848 : PU_NEIGHBOR_ARRAY_GRANULARITY,
849 : PU_NEIGHBOR_ARRAY_GRANULARITY,
850 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
851 : },
852 : {
853 6 : &object_ptr->partition_context_neighbor_array,
854 : MAX_PICTURE_WIDTH_SIZE,
855 : MAX_PICTURE_HEIGHT_SIZE,
856 : sizeof(struct PartitionContext),
857 : PU_NEIGHBOR_ARRAY_GRANULARITY,
858 : PU_NEIGHBOR_ARRAY_GRANULARITY,
859 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
860 : },
861 : {
862 6 : &object_ptr->skip_flag_neighbor_array,
863 : MAX_PICTURE_WIDTH_SIZE,
864 : MAX_PICTURE_HEIGHT_SIZE,
865 : sizeof(uint8_t),
866 : PU_NEIGHBOR_ARRAY_GRANULARITY,
867 : PU_NEIGHBOR_ARRAY_GRANULARITY,
868 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
869 : },
870 : {
871 6 : &object_ptr->skip_coeff_neighbor_array,
872 : MAX_PICTURE_WIDTH_SIZE,
873 : MAX_PICTURE_HEIGHT_SIZE,
874 : sizeof(uint8_t),
875 : PU_NEIGHBOR_ARRAY_GRANULARITY,
876 : PU_NEIGHBOR_ARRAY_GRANULARITY,
877 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
878 : },
879 : // for each 4x4
880 : {
881 6 : &object_ptr->luma_dc_sign_level_coeff_neighbor_array,
882 : MAX_PICTURE_WIDTH_SIZE,
883 : MAX_PICTURE_HEIGHT_SIZE,
884 : sizeof(uint8_t),
885 : PU_NEIGHBOR_ARRAY_GRANULARITY,
886 : PU_NEIGHBOR_ARRAY_GRANULARITY,
887 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
888 : },
889 : // for each 4x4
890 : {
891 6 : &object_ptr->cr_dc_sign_level_coeff_neighbor_array,
892 : MAX_PICTURE_WIDTH_SIZE,
893 : MAX_PICTURE_HEIGHT_SIZE,
894 : sizeof(uint8_t),
895 : PU_NEIGHBOR_ARRAY_GRANULARITY,
896 : PU_NEIGHBOR_ARRAY_GRANULARITY,
897 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
898 : },
899 : // for each 4x4
900 : {
901 6 : &object_ptr->cb_dc_sign_level_coeff_neighbor_array,
902 : MAX_PICTURE_WIDTH_SIZE,
903 : MAX_PICTURE_HEIGHT_SIZE,
904 : sizeof(uint8_t),
905 : PU_NEIGHBOR_ARRAY_GRANULARITY,
906 : PU_NEIGHBOR_ARRAY_GRANULARITY,
907 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
908 : },
909 : {
910 6 : &object_ptr->inter_pred_dir_neighbor_array,
911 : MAX_PICTURE_WIDTH_SIZE,
912 : MAX_PICTURE_HEIGHT_SIZE,
913 : sizeof(uint8_t),
914 : PU_NEIGHBOR_ARRAY_GRANULARITY,
915 : PU_NEIGHBOR_ARRAY_GRANULARITY,
916 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
917 : },
918 : {
919 6 : &object_ptr->ref_frame_type_neighbor_array,
920 : MAX_PICTURE_WIDTH_SIZE,
921 : MAX_PICTURE_HEIGHT_SIZE,
922 : sizeof(uint8_t),
923 : PU_NEIGHBOR_ARRAY_GRANULARITY,
924 : PU_NEIGHBOR_ARRAY_GRANULARITY,
925 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
926 : },
927 : {
928 6 : &object_ptr->intra_luma_mode_neighbor_array,
929 : MAX_PICTURE_WIDTH_SIZE,
930 : MAX_PICTURE_HEIGHT_SIZE,
931 : sizeof(uint8_t),
932 : PU_NEIGHBOR_ARRAY_GRANULARITY,
933 : PU_NEIGHBOR_ARRAY_GRANULARITY,
934 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
935 : },
936 : {
937 6 : &object_ptr->txfm_context_array,
938 : MAX_PICTURE_WIDTH_SIZE,
939 : MAX_PICTURE_HEIGHT_SIZE,
940 : sizeof(TXFM_CONTEXT),
941 : PU_NEIGHBOR_ARRAY_GRANULARITY,
942 : PU_NEIGHBOR_ARRAY_GRANULARITY,
943 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK,
944 : },
945 : {
946 6 : &object_ptr->segmentation_id_pred_array,
947 : MAX_PICTURE_WIDTH_SIZE,
948 : MAX_PICTURE_HEIGHT_SIZE,
949 : sizeof(uint8_t),
950 : PU_NEIGHBOR_ARRAY_GRANULARITY,
951 : PU_NEIGHBOR_ARRAY_GRANULARITY,
952 : NEIGHBOR_ARRAY_UNIT_FULL_MASK,
953 : },
954 : };
955 6 : return_error = create_neighbor_array_units(data, DIM(data));
956 6 : if (return_error == EB_ErrorInsufficientResources)
957 0 : return EB_ErrorInsufficientResources;
958 : }
959 6 : if (is16bit) {
960 0 : InitData data[] = {
961 : {
962 0 : &object_ptr->ep_luma_recon_neighbor_array16bit,
963 : MAX_PICTURE_WIDTH_SIZE,
964 : MAX_PICTURE_HEIGHT_SIZE,
965 : sizeof(uint16_t),
966 : SAMPLE_NEIGHBOR_ARRAY_GRANULARITY,
967 : SAMPLE_NEIGHBOR_ARRAY_GRANULARITY,
968 : NEIGHBOR_ARRAY_UNIT_FULL_MASK,
969 : },
970 : {
971 0 : &object_ptr->ep_cb_recon_neighbor_array16bit,
972 0 : MAX_PICTURE_WIDTH_SIZE >> subsampling_x,
973 0 : MAX_PICTURE_HEIGHT_SIZE >> subsampling_y,
974 : sizeof(uint16_t),
975 : SAMPLE_NEIGHBOR_ARRAY_GRANULARITY,
976 : SAMPLE_NEIGHBOR_ARRAY_GRANULARITY,
977 : NEIGHBOR_ARRAY_UNIT_FULL_MASK,
978 : },
979 : {
980 0 : &object_ptr->ep_cr_recon_neighbor_array16bit,
981 0 : MAX_PICTURE_WIDTH_SIZE >> subsampling_x,
982 0 : MAX_PICTURE_HEIGHT_SIZE >> subsampling_y,
983 : sizeof(uint16_t),
984 : SAMPLE_NEIGHBOR_ARRAY_GRANULARITY,
985 : SAMPLE_NEIGHBOR_ARRAY_GRANULARITY,
986 : NEIGHBOR_ARRAY_UNIT_FULL_MASK,
987 : },
988 : };
989 0 : return_error = create_neighbor_array_units(data, DIM(data));
990 0 : if (return_error == EB_ErrorInsufficientResources)
991 0 : return EB_ErrorInsufficientResources;
992 : }
993 : else {
994 6 : object_ptr->ep_luma_recon_neighbor_array16bit = 0;
995 6 : object_ptr->ep_cb_recon_neighbor_array16bit = 0;
996 6 : object_ptr->ep_cr_recon_neighbor_array16bit = 0;
997 : }
998 6 : EB_NEW(
999 : object_ptr->interpolation_type_neighbor_array,
1000 : neighbor_array_unit_ctor32,
1001 : MAX_PICTURE_WIDTH_SIZE,
1002 : MAX_PICTURE_HEIGHT_SIZE,
1003 : sizeof(uint32_t),
1004 : PU_NEIGHBOR_ARRAY_GRANULARITY,
1005 : PU_NEIGHBOR_ARRAY_GRANULARITY,
1006 : NEIGHBOR_ARRAY_UNIT_TOP_AND_LEFT_ONLY_MASK);
1007 :
1008 : //Segmentation neighbor arrays
1009 6 : EB_NEW(
1010 : object_ptr->segmentation_neighbor_map,
1011 : segmentation_map_ctor,
1012 : initDataPtr->picture_width, initDataPtr->picture_height);
1013 :
1014 : // Note - non-zero offsets are not supported (to be fixed later in DLF chroma filtering)
1015 6 : object_ptr->cb_qp_offset = 0;
1016 6 : object_ptr->cr_qp_offset = 0;
1017 :
1018 6 : object_ptr->slice_level_chroma_qp_flag = EB_TRUE;
1019 : // slice level chroma QP offsets
1020 6 : object_ptr->slice_cb_qp_offset = 0;
1021 6 : object_ptr->slice_cr_qp_offset = 0;
1022 :
1023 : //object_ptr->total_num_bits = 0;
1024 :
1025 : // Error Resilience
1026 6 : object_ptr->constrained_intra_flag = EB_FALSE;
1027 :
1028 : // Segments
1029 6 : EB_NEW(
1030 : object_ptr->enc_dec_segment_ctrl,
1031 : enc_dec_segments_ctor,
1032 : initDataPtr->enc_dec_segment_col,
1033 : initDataPtr->enc_dec_segment_row);
1034 : // Entropy Rows
1035 6 : EB_CREATE_MUTEX(object_ptr->entropy_coding_mutex);
1036 :
1037 6 : EB_CREATE_MUTEX(object_ptr->intra_mutex);
1038 :
1039 6 : EB_CREATE_MUTEX(object_ptr->cdef_search_mutex);
1040 :
1041 : //object_ptr->mse_seg[0] = (uint64_t(*)[64])eb_aom_malloc(sizeof(**object_ptr->mse_seg) * pictureLcuWidth * pictureLcuHeight);
1042 : // object_ptr->mse_seg[1] = (uint64_t(*)[64])eb_aom_malloc(sizeof(**object_ptr->mse_seg) * pictureLcuWidth * pictureLcuHeight);
1043 :
1044 6 : EB_MALLOC_ARRAY(object_ptr->mse_seg[0], pictureLcuWidth * pictureLcuHeight);
1045 6 : EB_MALLOC_ARRAY(object_ptr->mse_seg[1], pictureLcuWidth * pictureLcuHeight);
1046 :
1047 6 : EB_CREATE_MUTEX(object_ptr->rest_search_mutex);
1048 :
1049 : //the granularity is 4x4
1050 6 : EB_MALLOC_ARRAY(object_ptr->mi_grid_base, all_sb*(initDataPtr->sb_size_pix >> MI_SIZE_LOG2)*(initDataPtr->sb_size_pix >> MI_SIZE_LOG2));
1051 :
1052 6 : EB_MALLOC_ARRAY(object_ptr->mip, all_sb*(initDataPtr->sb_size_pix >> MI_SIZE_LOG2)*(initDataPtr->sb_size_pix >> MI_SIZE_LOG2));
1053 :
1054 6 : memset(object_ptr->mip, 0, sizeof(ModeInfo) * all_sb*(initDataPtr->sb_size_pix >> MI_SIZE_LOG2)*(initDataPtr->sb_size_pix >> MI_SIZE_LOG2));
1055 :
1056 : uint32_t miIdx;
1057 92166 : for (miIdx = 0; miIdx < all_sb*(initDataPtr->sb_size_pix >> MI_SIZE_LOG2)*(initDataPtr->sb_size_pix >> MI_SIZE_LOG2); ++miIdx)
1058 92160 : object_ptr->mi_grid_base[miIdx] = object_ptr->mip + miIdx;
1059 6 : object_ptr->mi_stride = picture_sb_w * (initDataPtr->sb_size_pix >> MI_SIZE_LOG2);
1060 6 : if (initDataPtr->mfmv)
1061 : {
1062 : //MFMV: map is 8x8 based.
1063 3 : uint32_t mi_rows = initDataPtr->picture_height >> MI_SIZE_LOG2;
1064 3 : const int mem_size = ((mi_rows + MAX_MIB_SIZE) >> 1) * (object_ptr->mi_stride >> 1);
1065 :
1066 3 : EB_CALLOC_ALIGNED_ARRAY(object_ptr->tpl_mvs, mem_size);
1067 : }
1068 6 : object_ptr->hash_table.p_lookup_table = NULL;
1069 6 : av1_hash_table_create(&object_ptr->hash_table);
1070 6 : return EB_ErrorNone;
1071 : }
1072 :
1073 6 : EbErrorType picture_control_set_creator(
1074 : EbPtr *object_dbl_ptr,
1075 : EbPtr object_init_data_ptr)
1076 : {
1077 : PictureControlSet* obj;
1078 :
1079 6 : *object_dbl_ptr = NULL;
1080 6 : EB_NEW(obj, picture_control_set_ctor, object_init_data_ptr);
1081 6 : *object_dbl_ptr = obj;
1082 :
1083 6 : return EB_ErrorNone;
1084 : }
1085 :
1086 144 : static void picture_parent_control_set_dctor(EbPtr p)
1087 : {
1088 144 : PictureParentControlSet *obj = (PictureParentControlSet*)p;
1089 : uint32_t regionInPictureWidthIndex;
1090 : uint32_t regionInPictureHeightIndex;
1091 :
1092 144 : EB_DELETE(obj->denoise_and_model);
1093 :
1094 8784 : EB_DELETE_PTR_ARRAY(obj->me_results, obj->sb_total_count);
1095 144 : if (obj->is_chroma_downsampled_picture_ptr_owner)
1096 0 : EB_DELETE(obj->chroma_downsampled_picture_ptr);
1097 :
1098 144 : EB_FREE_2D(obj->variance);
1099 144 : EB_FREE_2D(obj->y_mean);
1100 144 : EB_FREE_2D(obj->cbMean);
1101 144 : EB_FREE_2D(obj->crMean);
1102 :
1103 144 : if (obj->picture_histogram) {
1104 720 : for (regionInPictureWidthIndex = 0; regionInPictureWidthIndex < MAX_NUMBER_OF_REGIONS_IN_WIDTH; regionInPictureWidthIndex++) {
1105 576 : if (obj->picture_histogram[regionInPictureWidthIndex]) {
1106 2880 : for (regionInPictureHeightIndex = 0; regionInPictureHeightIndex < MAX_NUMBER_OF_REGIONS_IN_HEIGHT; regionInPictureHeightIndex++) {
1107 2304 : EB_FREE_2D(obj->picture_histogram[regionInPictureWidthIndex][regionInPictureHeightIndex]);
1108 : }
1109 : }
1110 2880 : EB_FREE_PTR_ARRAY(obj->picture_histogram[regionInPictureWidthIndex], MAX_NUMBER_OF_REGIONS_IN_HEIGHT);
1111 : }
1112 720 : EB_FREE_PTR_ARRAY(obj->picture_histogram, MAX_NUMBER_OF_REGIONS_IN_WIDTH);
1113 : }
1114 :
1115 144 : EB_FREE_2D(obj->ois_sb_results);
1116 144 : EB_FREE_2D(obj->ois_candicate);
1117 144 : EB_FREE_ARRAY(obj->rc_me_distortion);
1118 : // ME and OIS Distortion Histograms
1119 144 : EB_FREE_ARRAY(obj->me_distortion_histogram);
1120 144 : EB_FREE_ARRAY(obj->ois_distortion_histogram);
1121 144 : EB_FREE_ARRAY(obj->intra_sad_interval_index);
1122 144 : EB_FREE_ARRAY(obj->inter_sad_interval_index);
1123 : // Non moving index array
1124 144 : EB_FREE_ARRAY(obj->non_moving_index_array);
1125 : // SB noise variance array
1126 144 : EB_FREE_ARRAY(obj->sb_flat_noise_array);
1127 144 : EB_FREE_ARRAY(obj->edge_results_ptr);
1128 :
1129 144 : EB_FREE_ARRAY(obj->sharp_edge_sb_flag);
1130 144 : EB_FREE_ARRAY(obj->sb_stat_array);
1131 :
1132 144 : EB_FREE_ARRAY(obj->complex_sb_array);
1133 :
1134 144 : EB_FREE_ARRAY(obj->sb_depth_mode_array);
1135 :
1136 : {
1137 144 : const int32_t num_planes = 3;// av1_num_planes(cm);
1138 576 : for (int32_t p = 0; p < num_planes; ++p) {
1139 432 : RestorationInfo* ri =obj->av1_cm->rst_info + p;
1140 432 : RestorationStripeBoundaries *boundaries = &ri->boundaries;
1141 432 : EB_FREE_ARRAY(ri->unit_info);
1142 432 : EB_FREE(boundaries->stripe_boundary_above);
1143 432 : EB_FREE(boundaries->stripe_boundary_below);
1144 : }
1145 : }
1146 :
1147 144 : EB_FREE_ARRAY(obj->av1_cm->frame_to_show);
1148 144 : EB_FREE_ALIGNED(obj->av1_cm->rst_tmpbuf);
1149 144 : EB_FREE_ARRAY(obj->av1_cm);
1150 144 : EB_FREE_ARRAY(obj->rusi_picture[0]);
1151 144 : EB_FREE_ARRAY(obj->rusi_picture[1]);
1152 144 : EB_FREE_ARRAY(obj->rusi_picture[2]);
1153 :
1154 144 : EB_FREE_ARRAY(obj->av1x);
1155 :
1156 144 : EB_DESTROY_MUTEX(obj->rc_distortion_histogram_mutex);
1157 144 : EB_DESTROY_SEMAPHORE(obj->temp_filt_done_semaphore);
1158 144 : EB_DESTROY_MUTEX(obj->temp_filt_mutex);
1159 144 : EB_DESTROY_MUTEX(obj->debug_mutex);
1160 144 : }
1161 144 : EbErrorType picture_parent_control_set_ctor(
1162 : PictureParentControlSet *object_ptr,
1163 : EbPtr object_init_data_ptr)
1164 : {
1165 144 : PictureControlSetInitData *initDataPtr = (PictureControlSetInitData*)object_init_data_ptr;
1166 144 : EbErrorType return_error = EB_ErrorNone;
1167 144 : const uint16_t pictureLcuWidth = (uint16_t)((initDataPtr->picture_width + initDataPtr->sb_sz - 1) / initDataPtr->sb_sz);
1168 144 : const uint16_t pictureLcuHeight = (uint16_t)((initDataPtr->picture_height + initDataPtr->sb_sz - 1) / initDataPtr->sb_sz);
1169 144 : const uint16_t subsampling_x = (initDataPtr->color_format == EB_YUV444 ? 1 : 2) - 1;
1170 144 : const uint16_t subsampling_y = (initDataPtr->color_format >= EB_YUV422 ? 1 : 2) - 1;
1171 : uint16_t sb_index;
1172 : uint32_t regionInPictureWidthIndex;
1173 : uint32_t regionInPictureHeightIndex;
1174 :
1175 144 : object_ptr->dctor = picture_parent_control_set_dctor;
1176 :
1177 144 : object_ptr->sequence_control_set_wrapper_ptr = (EbObjectWrapper *)EB_NULL;
1178 144 : object_ptr->input_picture_wrapper_ptr = (EbObjectWrapper *)EB_NULL;
1179 144 : object_ptr->reference_picture_wrapper_ptr = (EbObjectWrapper *)EB_NULL;
1180 144 : object_ptr->enhanced_picture_ptr = (EbPictureBufferDesc *)EB_NULL;
1181 :
1182 144 : if (initDataPtr->color_format >= EB_YUV422) {
1183 : EbPictureBufferDescInitData input_picture_buffer_desc_init_data;
1184 0 : input_picture_buffer_desc_init_data.max_width = initDataPtr->picture_width;
1185 0 : input_picture_buffer_desc_init_data.max_height = initDataPtr->picture_height;
1186 0 : input_picture_buffer_desc_init_data.bit_depth = 8; //Should be 8bit
1187 0 : input_picture_buffer_desc_init_data.buffer_enable_mask = PICTURE_BUFFER_DESC_CHROMA_MASK;
1188 0 : input_picture_buffer_desc_init_data.left_padding = initDataPtr->left_padding;
1189 0 : input_picture_buffer_desc_init_data.right_padding = initDataPtr->right_padding;
1190 0 : input_picture_buffer_desc_init_data.top_padding = initDataPtr->top_padding;
1191 0 : input_picture_buffer_desc_init_data.bot_padding = initDataPtr->bot_padding;
1192 0 : input_picture_buffer_desc_init_data.color_format = EB_YUV420; //set to 420 for MD
1193 0 : input_picture_buffer_desc_init_data.split_mode = EB_FALSE;
1194 0 : EB_NEW(
1195 : object_ptr->chroma_downsampled_picture_ptr,
1196 : eb_picture_buffer_desc_ctor,
1197 : (EbPtr) &input_picture_buffer_desc_init_data);
1198 0 : object_ptr->is_chroma_downsampled_picture_ptr_owner = EB_TRUE;
1199 144 : } else if(initDataPtr->color_format == EB_YUV420) {
1200 144 : object_ptr->chroma_downsampled_picture_ptr = NULL;
1201 : } else
1202 0 : return EB_ErrorBadParameter;
1203 : // GOP
1204 144 : object_ptr->pred_struct_index = 0;
1205 144 : object_ptr->picture_number = 0;
1206 144 : object_ptr->idr_flag = EB_FALSE;
1207 144 : object_ptr->temporal_layer_index = 0;
1208 144 : object_ptr->total_num_bits = 0;
1209 144 : object_ptr->last_idr_picture = 0;
1210 144 : object_ptr->sb_total_count = pictureLcuWidth * pictureLcuHeight;
1211 :
1212 144 : object_ptr->data_ll_head_ptr = (EbLinkedListNode *)EB_NULL;
1213 144 : object_ptr->app_out_data_ll_head_ptr = (EbLinkedListNode *)EB_NULL;
1214 8640 : EB_MALLOC_2D(object_ptr->variance, object_ptr->sb_total_count, MAX_ME_PU_COUNT);
1215 8640 : EB_MALLOC_2D(object_ptr->y_mean, object_ptr->sb_total_count, MAX_ME_PU_COUNT);
1216 8640 : EB_MALLOC_2D(object_ptr->cbMean, object_ptr->sb_total_count, 21);
1217 8640 : EB_MALLOC_2D(object_ptr->crMean, object_ptr->sb_total_count, 21);
1218 :
1219 :
1220 144 : EB_ALLOC_PTR_ARRAY(object_ptr->picture_histogram, MAX_NUMBER_OF_REGIONS_IN_WIDTH);
1221 :
1222 720 : for (regionInPictureWidthIndex = 0; regionInPictureWidthIndex < MAX_NUMBER_OF_REGIONS_IN_WIDTH; regionInPictureWidthIndex++) { // loop over horizontal regions
1223 576 : EB_ALLOC_PTR_ARRAY(object_ptr->picture_histogram[regionInPictureWidthIndex], MAX_NUMBER_OF_REGIONS_IN_HEIGHT);
1224 2880 : for (regionInPictureHeightIndex = 0; regionInPictureHeightIndex < MAX_NUMBER_OF_REGIONS_IN_HEIGHT; regionInPictureHeightIndex++) {
1225 6912 : EB_MALLOC_2D(object_ptr->picture_histogram[regionInPictureWidthIndex][regionInPictureHeightIndex], 3, HISTOGRAM_NUMBER_OF_BINS);
1226 : }
1227 : }
1228 :
1229 8640 : EB_MALLOC_2D(object_ptr->ois_sb_results, object_ptr->sb_total_count, 1);
1230 8640 : EB_MALLOC_2D(object_ptr->ois_candicate, object_ptr->sb_total_count, MAX_OIS_CANDIDATES * CU_MAX_COUNT);
1231 :
1232 8784 : for (sb_index = 0; sb_index < object_ptr->sb_total_count; ++sb_index) {
1233 : uint32_t cuIdx;
1234 743040 : for (cuIdx = 0; cuIdx < CU_MAX_COUNT; ++cuIdx)
1235 734400 : object_ptr->ois_sb_results[sb_index]->ois_candidate_array[cuIdx] = &object_ptr->ois_candicate[sb_index][cuIdx*MAX_OIS_CANDIDATES];
1236 : }
1237 :
1238 144 : object_ptr->max_number_of_candidates_per_block = (initDataPtr->mrp_mode == 0) ?
1239 : ME_RES_CAND_MRP_MODE_0 : // [Single Ref = 7] + [BiDir = 12 = 3*4 ] + [UniDir = 4 = 3+1]
1240 : ME_RES_CAND_MRP_MODE_1 ; // [BiDir = 1] + [UniDir = 2 = 1 + 1]
1241 :
1242 144 : EB_ALLOC_PTR_ARRAY(object_ptr->me_results, object_ptr->sb_total_count);
1243 :
1244 8784 : for (sb_index = 0; sb_index < object_ptr->sb_total_count; ++sb_index) {
1245 8640 : EB_NEW(
1246 : object_ptr->me_results[sb_index],
1247 : me_sb_results_ctor,
1248 : (initDataPtr->nsq_present) ? MAX_ME_PU_COUNT : SQUARE_PU_COUNT,
1249 : initDataPtr->mrp_mode,
1250 : object_ptr->max_number_of_candidates_per_block);
1251 : }
1252 :
1253 144 : EB_MALLOC_ARRAY(object_ptr->rc_me_distortion, object_ptr->sb_total_count);
1254 : // ME and OIS Distortion Histograms
1255 144 : EB_MALLOC_ARRAY(object_ptr->me_distortion_histogram, NUMBER_OF_SAD_INTERVALS);
1256 144 : EB_MALLOC_ARRAY(object_ptr->ois_distortion_histogram, NUMBER_OF_INTRA_SAD_INTERVALS);
1257 144 : EB_MALLOC_ARRAY(object_ptr->intra_sad_interval_index, object_ptr->sb_total_count);
1258 144 : EB_MALLOC_ARRAY(object_ptr->inter_sad_interval_index, object_ptr->sb_total_count);
1259 : // Non moving index array
1260 144 : EB_MALLOC_ARRAY(object_ptr->non_moving_index_array, object_ptr->sb_total_count);
1261 : // SB noise variance array
1262 144 : EB_MALLOC_ARRAY(object_ptr->sb_flat_noise_array, object_ptr->sb_total_count);
1263 144 : EB_MALLOC_ARRAY(object_ptr->edge_results_ptr, object_ptr->sb_total_count);
1264 :
1265 144 : EB_MALLOC_ARRAY(object_ptr->sharp_edge_sb_flag, object_ptr->sb_total_count);
1266 144 : EB_MALLOC_ARRAY(object_ptr->sb_stat_array, object_ptr->sb_total_count);
1267 :
1268 144 : EB_MALLOC_ARRAY(object_ptr->complex_sb_array, object_ptr->sb_total_count);
1269 :
1270 144 : EB_CREATE_MUTEX(object_ptr->rc_distortion_histogram_mutex);
1271 :
1272 144 : EB_MALLOC_ARRAY(object_ptr->sb_depth_mode_array, object_ptr->sb_total_count);
1273 :
1274 144 : EB_CREATE_SEMAPHORE(object_ptr->temp_filt_done_semaphore, 0, 1);
1275 144 : EB_CREATE_MUTEX(object_ptr->temp_filt_mutex);
1276 144 : EB_CREATE_MUTEX(object_ptr->debug_mutex);
1277 :
1278 144 : EB_MALLOC_ARRAY(object_ptr->av1_cm, 1);
1279 :
1280 144 : object_ptr->av1_cm->interp_filter = SWITCHABLE;
1281 :
1282 144 : object_ptr->av1_cm->mi_stride = pictureLcuWidth * (BLOCK_SIZE_64 / 4);
1283 :
1284 144 : object_ptr->av1_cm->p_pcs_ptr = object_ptr;
1285 :
1286 144 : EB_MALLOC_ARRAY(object_ptr->av1_cm->frame_to_show, 1);
1287 :
1288 144 : object_ptr->av1_cm->use_highbitdepth = (initDataPtr->bit_depth > 8 ? 1 : 0);
1289 144 : object_ptr->av1_cm->bit_depth = initDataPtr->bit_depth;
1290 144 : object_ptr->av1_cm->color_format = initDataPtr->color_format;
1291 144 : object_ptr->av1_cm->subsampling_x = subsampling_x;
1292 144 : object_ptr->av1_cm->subsampling_y = subsampling_y;
1293 144 : object_ptr->av1_cm->frm_size.frame_width = initDataPtr->picture_width;
1294 144 : object_ptr->av1_cm->frm_size.frame_height = initDataPtr->picture_height;
1295 144 : object_ptr->av1_cm->frm_size.superres_upscaled_width = initDataPtr->picture_width;
1296 144 : object_ptr->av1_cm->frm_size.superres_upscaled_height = initDataPtr->picture_height;
1297 :
1298 144 : object_ptr->av1_cm->mi_cols = initDataPtr->picture_width >> MI_SIZE_LOG2;
1299 144 : object_ptr->av1_cm->mi_rows = initDataPtr->picture_height >> MI_SIZE_LOG2;
1300 :
1301 144 : object_ptr->av1_cm->byte_alignment = 0;
1302 :
1303 144 : set_restoration_unit_size(initDataPtr->picture_width, initDataPtr->picture_height, 1, 1, object_ptr->av1_cm->rst_info);
1304 :
1305 144 : return_error = eb_av1_alloc_restoration_buffers(object_ptr->av1_cm);
1306 :
1307 144 : memset(&object_ptr->av1_cm->rst_frame, 0, sizeof(Yv12BufferConfig));
1308 :
1309 : int32_t ntiles[2];
1310 432 : for (int32_t is_uv = 0; is_uv < 2; ++is_uv)
1311 288 : ntiles[is_uv] = object_ptr->av1_cm->rst_info[is_uv].units_per_tile; //CHKN res_tiles_in_plane
1312 :
1313 : assert(ntiles[1] <= ntiles[0]);
1314 :
1315 144 : EB_CALLOC_ARRAY(object_ptr->rusi_picture[0], ntiles[0]);
1316 144 : EB_CALLOC_ARRAY(object_ptr->rusi_picture[1], ntiles[1]);
1317 144 : EB_CALLOC_ARRAY(object_ptr->rusi_picture[2], ntiles[1]);
1318 :
1319 144 : EB_MALLOC_ARRAY(object_ptr->av1x, 1);
1320 :
1321 : // Film grain noise model if film grain is applied
1322 144 : if (initDataPtr->film_grain_noise_level) {
1323 : denoise_and_model_init_data_t fg_init_data;
1324 0 : fg_init_data.encoder_bit_depth = initDataPtr->bit_depth;
1325 0 : fg_init_data.encoder_color_format = initDataPtr->color_format;
1326 0 : fg_init_data.noise_level = initDataPtr->film_grain_noise_level;
1327 0 : fg_init_data.width = initDataPtr->picture_width;
1328 0 : fg_init_data.height = initDataPtr->picture_height;
1329 0 : fg_init_data.stride_y = initDataPtr->picture_width + initDataPtr->left_padding + initDataPtr->right_padding;
1330 0 : fg_init_data.stride_cb = fg_init_data.stride_cr = fg_init_data.stride_y >> subsampling_x;
1331 :
1332 0 : EB_NEW(object_ptr->denoise_and_model, denoise_and_model_ctor,
1333 : (EbPtr)&fg_init_data);
1334 : }
1335 :
1336 144 : return return_error;
1337 : }
1338 :
1339 144 : EbErrorType picture_parent_control_set_creator(
1340 : EbPtr *object_dbl_ptr,
1341 : EbPtr object_init_data_ptr)
1342 : {
1343 : PictureParentControlSet* obj;
1344 :
1345 144 : *object_dbl_ptr = NULL;
1346 144 : EB_NEW(obj, picture_parent_control_set_ctor, object_init_data_ptr);
1347 144 : *object_dbl_ptr = obj;
1348 :
1349 144 : return EB_ErrorNone;
1350 : }
|