Line data Source code
1 : /* 2 : * Copyright(c) 2019 Intel Corporation 3 : * SPDX - License - Identifier: BSD - 2 - Clause - Patent 4 : */ 5 : 6 : #include <stdlib.h> 7 : #include <string.h> 8 : 9 : #include "EbMotionEstimationContext.h" 10 : 11 22628 : void MotionEstimetionPredUnitCtor( 12 : MePredUnit *pu) 13 : { 14 22628 : pu->distortion = 0xFFFFFFFFull; 15 : 16 22628 : pu->prediction_direction = UNI_PRED_LIST_0; 17 22628 : return; 18 : } 19 : 20 8 : static void me_context_dctor(EbPtr p) 21 : { 22 8 : MeContext *obj = (MeContext*)p; 23 : uint32_t listIndex; 24 : uint32_t refPicIndex; 25 8 : EB_FREE_ALIGNED_ARRAY(obj->quarter_sb_buffer); 26 : 27 8 : EB_FREE_ARRAY(obj->mvd_bits_array); 28 : 29 24 : for (listIndex = 0; listIndex < MAX_NUM_OF_REF_PIC_LIST; listIndex++) { 30 80 : for (refPicIndex = 0; refPicIndex < MAX_REF_IDX; refPicIndex++) { 31 64 : EB_FREE_ARRAY(obj->pos_b_buffer[listIndex][refPicIndex]); 32 64 : EB_FREE_ARRAY(obj->pos_h_buffer[listIndex][refPicIndex]); 33 64 : EB_FREE_ARRAY(obj->pos_j_buffer[listIndex][refPicIndex]); 34 : } 35 : } 36 : 37 8 : EB_FREE_ARRAY(obj->one_d_intermediate_results_buf0); 38 8 : EB_FREE_ARRAY(obj->one_d_intermediate_results_buf1); 39 8 : EB_FREE_ARRAY(obj->me_candidate); 40 8 : EB_FREE_ARRAY(obj->avctemp_buffer); 41 8 : EB_FREE_ARRAY(obj->p_eight_pos_sad16x16); 42 8 : EB_FREE_ALIGNED_ARRAY(obj->sixteenth_sb_buffer); 43 8 : EB_FREE_ALIGNED_ARRAY(obj->sb_buffer); 44 8 : } 45 8 : EbErrorType me_context_ctor( 46 : MeContext *object_ptr, 47 : uint16_t max_input_luma_width, 48 : uint16_t max_input_luma_height, 49 : uint8_t nsq_present, 50 : uint8_t mrp_mode) 51 : { 52 : uint32_t listIndex; 53 : uint32_t refPicIndex; 54 : uint32_t pu_index; 55 : uint32_t meCandidateIndex; 56 : 57 8 : object_ptr->dctor = me_context_dctor; 58 : 59 : // Intermediate LCU-sized buffer to retain the input samples 60 8 : object_ptr->sb_buffer_stride = BLOCK_SIZE_64; 61 8 : EB_MALLOC_ALIGNED_ARRAY(object_ptr->sb_buffer, BLOCK_SIZE_64 * object_ptr->sb_buffer_stride); 62 : 63 8 : object_ptr->quarter_sb_buffer_stride = (BLOCK_SIZE_64 >> 1); 64 8 : EB_MALLOC_ALIGNED_ARRAY(object_ptr->quarter_sb_buffer, (BLOCK_SIZE_64 >> 1) * object_ptr->quarter_sb_buffer_stride); 65 : 66 8 : object_ptr->sixteenth_sb_buffer_stride = (BLOCK_SIZE_64 >> 2); 67 8 : EB_MALLOC_ALIGNED_ARRAY(object_ptr->sixteenth_sb_buffer, (BLOCK_SIZE_64 >> 2) * object_ptr->sixteenth_sb_buffer_stride); 68 8 : object_ptr->interpolated_stride = MIN((uint16_t)MAX_SEARCH_AREA_WIDTH, (uint16_t)(max_input_luma_width + (PAD_VALUE << 1))); 69 : 70 8 : uint16_t max_search_area_height = MIN((uint16_t)MAX_PICTURE_HEIGHT_SIZE, (uint16_t)(max_input_luma_height + (PAD_VALUE << 1))); 71 8 : EB_MEMSET(object_ptr->sb_buffer, 0, sizeof(uint8_t) * BLOCK_SIZE_64 * object_ptr->sb_buffer_stride); 72 8 : EB_MALLOC_ARRAY(object_ptr->mvd_bits_array, NUMBER_OF_MVD_CASES); 73 : // 15 intermediate buffers to retain the interpolated reference samples 74 : 75 : // 0 1 2 3 76 : // 0 A a b c 77 : // 1 d e f g 78 : // 2 h i j k 79 : // 3 n p q r 80 : 81 : // _____________ 82 : // | | 83 : // --I samples --> |Interpolation|-- O samples --> 84 : // | ____________| 85 : 86 : // Before Interpolation: 2 x 3 87 : // I I 88 : // I I 89 : // I I 90 : 91 : // After 1-D Horizontal Interpolation: (2 + 1) x 3 - a, b, and c 92 : // O I O I O 93 : // O I O I O 94 : // O I O I O 95 : 96 : // After 1-D Vertical Interpolation: 2 x (3 + 1) - d, h, and n 97 : // O O 98 : // I I 99 : // O O 100 : // I I 101 : // O O 102 : // I I 103 : // O O 104 : 105 : // After 2-D (Horizontal/Vertical) Interpolation: (2 + 1) x (3 + 1) - e, f, g, i, j, k, n, p, q, and r 106 : // O O O 107 : // I I 108 : // O O O 109 : // I I 110 : // O O O 111 : // I I 112 : // O O O 113 : 114 24 : for (listIndex = 0; listIndex < MAX_NUM_OF_REF_PIC_LIST; listIndex++) { 115 80 : for (refPicIndex = 0; refPicIndex < MAX_REF_IDX; refPicIndex++) { 116 64 : EB_MALLOC_ARRAY(object_ptr->pos_b_buffer[listIndex][refPicIndex], object_ptr->interpolated_stride * max_search_area_height); 117 64 : EB_MALLOC_ARRAY(object_ptr->pos_h_buffer[listIndex][refPicIndex], object_ptr->interpolated_stride * max_search_area_height); 118 64 : EB_MALLOC_ARRAY(object_ptr->pos_j_buffer[listIndex][refPicIndex], object_ptr->interpolated_stride * max_search_area_height); 119 : } 120 : } 121 : 122 8 : EB_MALLOC_ARRAY(object_ptr->one_d_intermediate_results_buf0, BLOCK_SIZE_64*BLOCK_SIZE_64); 123 : 124 8 : EB_MALLOC_ARRAY(object_ptr->one_d_intermediate_results_buf1, BLOCK_SIZE_64*BLOCK_SIZE_64); 125 : 126 8 : EB_MALLOC_ARRAY(object_ptr->me_candidate, ((mrp_mode == 0) ? ME_RES_CAND_MRP_MODE_0 : ME_RES_CAND_MRP_MODE_1)); 127 1184 : for (pu_index = 0; pu_index < (uint32_t)(nsq_present ? MAX_ME_PU_COUNT : SQUARE_PU_COUNT); pu_index++) { 128 23804 : for (meCandidateIndex = 0; meCandidateIndex < (uint32_t)((mrp_mode == 0) ? ME_RES_CAND_MRP_MODE_0 : ME_RES_CAND_MRP_MODE_1); meCandidateIndex++) { 129 22628 : MotionEstimetionPredUnitCtor(&(object_ptr->me_candidate[meCandidateIndex]).pu[pu_index]); 130 : } 131 : } 132 : 133 8 : EB_MALLOC_ARRAY(object_ptr->avctemp_buffer, object_ptr->interpolated_stride * max_search_area_height); 134 8 : EB_MALLOC_ARRAY(object_ptr->p_eight_pos_sad16x16, 8 * 16);//16= 16 16x16 blocks in a LCU. 8=8search points 135 : 136 : // Initialize Alt-Ref parameters 137 8 : object_ptr->me_alt_ref = EB_FALSE; 138 : 139 8 : return EB_ErrorNone; 140 : }