1 /*
2 * Copyright(c) 2019 Intel Corporation
3 *
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at https://www.aomedia.org/license/software-license. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at https://www.aomedia.org/license/patent-license.
10 */
11 
12 #ifndef EbMotionEstimationContext_h
13 #define EbMotionEstimationContext_h
14 
15 #include "EbDefinitions.h"
16 #include "EbMdRateEstimation.h"
17 #include "EbCodingUnit.h"
18 #include "EbObject.h"
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 // 1-D interpolation shift value
23 #define if_shift 6
24 #define NUMBER_OF_SB_QUAD 4
25 #define VARIANCE_PRECISION 16
26 #define MEAN_PRECISION (VARIANCE_PRECISION >> 1)
27 #define HME_DECIM_FILTER_TAP 9
28 
29 // Quater pel refinement methods
30 typedef enum EbQuarterPelRefinementMethod {
31     EB_QUARTER_IN_FULL,
32     EB_QUARTER_IN_HALF_HORIZONTAL,
33     EB_QUARTER_IN_HALF_VERTICAL,
34     EB_QUARTER_IN_HALF_DIAGONAL
35 } EbQuarterPelInterpolationMethod;
36 
37 typedef struct MePredictionUnit {
38     uint64_t distortion;
39     int16_t  x_mv;
40     int16_t  y_mv;
41     uint32_t sub_pel_direction;
42 } MePredictionUnit;
43 
44 typedef enum EbMeType {
45     ME_CLOSE_LOOP = 0,
46     ME_MCTF       = 1,
47     ME_TPL        = 2,
48     ME_OPEN_LOOP  = 3,
49     ME_FIRST_PASS = 4
50 } EbMeType;
51 typedef enum EbMeTierZeroPu {
52     // 2Nx2N [85 partitions]
53     ME_TIER_ZERO_PU_64x64    = 0,
54     ME_TIER_ZERO_PU_32x32_0  = 1,
55     ME_TIER_ZERO_PU_32x32_1  = 2,
56     ME_TIER_ZERO_PU_32x32_2  = 3,
57     ME_TIER_ZERO_PU_32x32_3  = 4,
58     ME_TIER_ZERO_PU_16x16_0  = 5,
59     ME_TIER_ZERO_PU_16x16_1  = 6,
60     ME_TIER_ZERO_PU_16x16_2  = 7,
61     ME_TIER_ZERO_PU_16x16_3  = 8,
62     ME_TIER_ZERO_PU_16x16_4  = 9,
63     ME_TIER_ZERO_PU_16x16_5  = 10,
64     ME_TIER_ZERO_PU_16x16_6  = 11,
65     ME_TIER_ZERO_PU_16x16_7  = 12,
66     ME_TIER_ZERO_PU_16x16_8  = 13,
67     ME_TIER_ZERO_PU_16x16_9  = 14,
68     ME_TIER_ZERO_PU_16x16_10 = 15,
69     ME_TIER_ZERO_PU_16x16_11 = 16,
70     ME_TIER_ZERO_PU_16x16_12 = 17,
71     ME_TIER_ZERO_PU_16x16_13 = 18,
72     ME_TIER_ZERO_PU_16x16_14 = 19,
73     ME_TIER_ZERO_PU_16x16_15 = 20,
74     ME_TIER_ZERO_PU_8x8_0    = 21,
75     ME_TIER_ZERO_PU_8x8_1    = 22,
76     ME_TIER_ZERO_PU_8x8_2    = 23,
77     ME_TIER_ZERO_PU_8x8_3    = 24,
78     ME_TIER_ZERO_PU_8x8_4    = 25,
79     ME_TIER_ZERO_PU_8x8_5    = 26,
80     ME_TIER_ZERO_PU_8x8_6    = 27,
81     ME_TIER_ZERO_PU_8x8_7    = 28,
82     ME_TIER_ZERO_PU_8x8_8    = 29,
83     ME_TIER_ZERO_PU_8x8_9    = 30,
84     ME_TIER_ZERO_PU_8x8_10   = 31,
85     ME_TIER_ZERO_PU_8x8_11   = 32,
86     ME_TIER_ZERO_PU_8x8_12   = 33,
87     ME_TIER_ZERO_PU_8x8_13   = 34,
88     ME_TIER_ZERO_PU_8x8_14   = 35,
89     ME_TIER_ZERO_PU_8x8_15   = 36,
90     ME_TIER_ZERO_PU_8x8_16   = 37,
91     ME_TIER_ZERO_PU_8x8_17   = 38,
92     ME_TIER_ZERO_PU_8x8_18   = 39,
93     ME_TIER_ZERO_PU_8x8_19   = 40,
94     ME_TIER_ZERO_PU_8x8_20   = 41,
95     ME_TIER_ZERO_PU_8x8_21   = 42,
96     ME_TIER_ZERO_PU_8x8_22   = 43,
97     ME_TIER_ZERO_PU_8x8_23   = 44,
98     ME_TIER_ZERO_PU_8x8_24   = 45,
99     ME_TIER_ZERO_PU_8x8_25   = 46,
100     ME_TIER_ZERO_PU_8x8_26   = 47,
101     ME_TIER_ZERO_PU_8x8_27   = 48,
102     ME_TIER_ZERO_PU_8x8_28   = 49,
103     ME_TIER_ZERO_PU_8x8_29   = 50,
104     ME_TIER_ZERO_PU_8x8_30   = 51,
105     ME_TIER_ZERO_PU_8x8_31   = 52,
106     ME_TIER_ZERO_PU_8x8_32   = 53,
107     ME_TIER_ZERO_PU_8x8_33   = 54,
108     ME_TIER_ZERO_PU_8x8_34   = 55,
109     ME_TIER_ZERO_PU_8x8_35   = 56,
110     ME_TIER_ZERO_PU_8x8_36   = 57,
111     ME_TIER_ZERO_PU_8x8_37   = 58,
112     ME_TIER_ZERO_PU_8x8_38   = 59,
113     ME_TIER_ZERO_PU_8x8_39   = 60,
114     ME_TIER_ZERO_PU_8x8_40   = 61,
115     ME_TIER_ZERO_PU_8x8_41   = 62,
116     ME_TIER_ZERO_PU_8x8_42   = 63,
117     ME_TIER_ZERO_PU_8x8_43   = 64,
118     ME_TIER_ZERO_PU_8x8_44   = 65,
119     ME_TIER_ZERO_PU_8x8_45   = 66,
120     ME_TIER_ZERO_PU_8x8_46   = 67,
121     ME_TIER_ZERO_PU_8x8_47   = 68,
122     ME_TIER_ZERO_PU_8x8_48   = 69,
123     ME_TIER_ZERO_PU_8x8_49   = 70,
124     ME_TIER_ZERO_PU_8x8_50   = 71,
125     ME_TIER_ZERO_PU_8x8_51   = 72,
126     ME_TIER_ZERO_PU_8x8_52   = 73,
127     ME_TIER_ZERO_PU_8x8_53   = 74,
128     ME_TIER_ZERO_PU_8x8_54   = 75,
129     ME_TIER_ZERO_PU_8x8_55   = 76,
130     ME_TIER_ZERO_PU_8x8_56   = 77,
131     ME_TIER_ZERO_PU_8x8_57   = 78,
132     ME_TIER_ZERO_PU_8x8_58   = 79,
133     ME_TIER_ZERO_PU_8x8_59   = 80,
134     ME_TIER_ZERO_PU_8x8_60   = 81,
135     ME_TIER_ZERO_PU_8x8_61   = 82,
136     ME_TIER_ZERO_PU_8x8_62   = 83,
137     ME_TIER_ZERO_PU_8x8_63   = 84,
138     // H  [42 partitions]
139     ME_TIER_ZERO_PU_64x32_0 = 85,
140     ME_TIER_ZERO_PU_64x32_1 = 86,
141     ME_TIER_ZERO_PU_32x16_0 = 87,
142     ME_TIER_ZERO_PU_32x16_1 = 88,
143     ME_TIER_ZERO_PU_32x16_2 = 89,
144     ME_TIER_ZERO_PU_32x16_3 = 90,
145     ME_TIER_ZERO_PU_32x16_4 = 91,
146     ME_TIER_ZERO_PU_32x16_5 = 92,
147     ME_TIER_ZERO_PU_32x16_6 = 93,
148     ME_TIER_ZERO_PU_32x16_7 = 94,
149     ME_TIER_ZERO_PU_16x8_0  = 95,
150     ME_TIER_ZERO_PU_16x8_1  = 96,
151     ME_TIER_ZERO_PU_16x8_2  = 97,
152     ME_TIER_ZERO_PU_16x8_3  = 98,
153     ME_TIER_ZERO_PU_16x8_4  = 99,
154     ME_TIER_ZERO_PU_16x8_5  = 100,
155     ME_TIER_ZERO_PU_16x8_6  = 101,
156     ME_TIER_ZERO_PU_16x8_7  = 102,
157     ME_TIER_ZERO_PU_16x8_8  = 103,
158     ME_TIER_ZERO_PU_16x8_9  = 104,
159     ME_TIER_ZERO_PU_16x8_10 = 105,
160     ME_TIER_ZERO_PU_16x8_11 = 106,
161     ME_TIER_ZERO_PU_16x8_12 = 107,
162     ME_TIER_ZERO_PU_16x8_13 = 108,
163     ME_TIER_ZERO_PU_16x8_14 = 109,
164     ME_TIER_ZERO_PU_16x8_15 = 110,
165     ME_TIER_ZERO_PU_16x8_16 = 111,
166     ME_TIER_ZERO_PU_16x8_17 = 112,
167     ME_TIER_ZERO_PU_16x8_18 = 113,
168     ME_TIER_ZERO_PU_16x8_19 = 114,
169     ME_TIER_ZERO_PU_16x8_20 = 115,
170     ME_TIER_ZERO_PU_16x8_21 = 116,
171     ME_TIER_ZERO_PU_16x8_22 = 117,
172     ME_TIER_ZERO_PU_16x8_23 = 118,
173     ME_TIER_ZERO_PU_16x8_24 = 119,
174     ME_TIER_ZERO_PU_16x8_25 = 120,
175     ME_TIER_ZERO_PU_16x8_26 = 121,
176     ME_TIER_ZERO_PU_16x8_27 = 122,
177     ME_TIER_ZERO_PU_16x8_28 = 123,
178     ME_TIER_ZERO_PU_16x8_29 = 124,
179     ME_TIER_ZERO_PU_16x8_30 = 125,
180     ME_TIER_ZERO_PU_16x8_31 = 126,
181     // V  [42 partitions]
182     ME_TIER_ZERO_PU_32x64_0 = 127,
183     ME_TIER_ZERO_PU_32x64_1 = 128,
184     ME_TIER_ZERO_PU_16x32_0 = 129,
185     ME_TIER_ZERO_PU_16x32_1 = 130,
186     ME_TIER_ZERO_PU_16x32_2 = 131,
187     ME_TIER_ZERO_PU_16x32_3 = 132,
188     ME_TIER_ZERO_PU_16x32_4 = 133,
189     ME_TIER_ZERO_PU_16x32_5 = 134,
190     ME_TIER_ZERO_PU_16x32_6 = 135,
191     ME_TIER_ZERO_PU_16x32_7 = 136,
192     ME_TIER_ZERO_PU_8x16_0  = 137,
193     ME_TIER_ZERO_PU_8x16_1  = 138,
194     ME_TIER_ZERO_PU_8x16_2  = 139,
195     ME_TIER_ZERO_PU_8x16_3  = 140,
196     ME_TIER_ZERO_PU_8x16_4  = 141,
197     ME_TIER_ZERO_PU_8x16_5  = 142,
198     ME_TIER_ZERO_PU_8x16_6  = 143,
199     ME_TIER_ZERO_PU_8x16_7  = 144,
200     ME_TIER_ZERO_PU_8x16_8  = 145,
201     ME_TIER_ZERO_PU_8x16_9  = 146,
202     ME_TIER_ZERO_PU_8x16_10 = 147,
203     ME_TIER_ZERO_PU_8x16_11 = 148,
204     ME_TIER_ZERO_PU_8x16_12 = 149,
205     ME_TIER_ZERO_PU_8x16_13 = 150,
206     ME_TIER_ZERO_PU_8x16_14 = 151,
207     ME_TIER_ZERO_PU_8x16_15 = 152,
208     ME_TIER_ZERO_PU_8x16_16 = 153,
209     ME_TIER_ZERO_PU_8x16_17 = 154,
210     ME_TIER_ZERO_PU_8x16_18 = 155,
211     ME_TIER_ZERO_PU_8x16_19 = 156,
212     ME_TIER_ZERO_PU_8x16_20 = 157,
213     ME_TIER_ZERO_PU_8x16_21 = 158,
214     ME_TIER_ZERO_PU_8x16_22 = 159,
215     ME_TIER_ZERO_PU_8x16_23 = 160,
216     ME_TIER_ZERO_PU_8x16_24 = 161,
217     ME_TIER_ZERO_PU_8x16_25 = 162,
218     ME_TIER_ZERO_PU_8x16_26 = 163,
219     ME_TIER_ZERO_PU_8x16_27 = 164,
220     ME_TIER_ZERO_PU_8x16_28 = 165,
221     ME_TIER_ZERO_PU_8x16_29 = 166,
222     ME_TIER_ZERO_PU_8x16_30 = 167,
223     ME_TIER_ZERO_PU_8x16_31 = 168,
224     // H4 [16 partitions]
225     ME_TIER_ZERO_PU_32x8_0  = 169,
226     ME_TIER_ZERO_PU_32x8_1  = 170,
227     ME_TIER_ZERO_PU_32x8_2  = 171,
228     ME_TIER_ZERO_PU_32x8_3  = 172,
229     ME_TIER_ZERO_PU_32x8_4  = 173,
230     ME_TIER_ZERO_PU_32x8_5  = 174,
231     ME_TIER_ZERO_PU_32x8_6  = 175,
232     ME_TIER_ZERO_PU_32x8_7  = 176,
233     ME_TIER_ZERO_PU_32x8_8  = 177,
234     ME_TIER_ZERO_PU_32x8_9  = 178,
235     ME_TIER_ZERO_PU_32x8_10 = 179,
236     ME_TIER_ZERO_PU_32x8_11 = 180,
237     ME_TIER_ZERO_PU_32x8_12 = 181,
238     ME_TIER_ZERO_PU_32x8_13 = 182,
239     ME_TIER_ZERO_PU_32x8_14 = 183,
240     ME_TIER_ZERO_PU_32x8_15 = 184,
241     // V4 [16 partitions]
242     ME_TIER_ZERO_PU_8x32_0  = 185,
243     ME_TIER_ZERO_PU_8x32_1  = 186,
244     ME_TIER_ZERO_PU_8x32_2  = 187,
245     ME_TIER_ZERO_PU_8x32_3  = 188,
246     ME_TIER_ZERO_PU_8x32_4  = 189,
247     ME_TIER_ZERO_PU_8x32_5  = 190,
248     ME_TIER_ZERO_PU_8x32_6  = 191,
249     ME_TIER_ZERO_PU_8x32_7  = 192,
250     ME_TIER_ZERO_PU_8x32_8  = 193,
251     ME_TIER_ZERO_PU_8x32_9  = 194,
252     ME_TIER_ZERO_PU_8x32_10 = 195,
253     ME_TIER_ZERO_PU_8x32_11 = 196,
254     ME_TIER_ZERO_PU_8x32_12 = 197,
255     ME_TIER_ZERO_PU_8x32_13 = 198,
256     ME_TIER_ZERO_PU_8x32_14 = 199,
257     ME_TIER_ZERO_PU_8x32_15 = 200,
258     ME_TIER_ZERO_PU_64x16_0 = 201,
259     ME_TIER_ZERO_PU_64x16_1 = 202,
260     ME_TIER_ZERO_PU_64x16_2 = 203,
261     ME_TIER_ZERO_PU_64x16_3 = 204,
262     ME_TIER_ZERO_PU_16x64_0 = 205,
263     ME_TIER_ZERO_PU_16x64_1 = 206,
264     ME_TIER_ZERO_PU_16x64_2 = 207,
265     ME_TIER_ZERO_PU_16x64_3 = 208
266 } EbMeTierZeroPu;
267 
268 typedef struct IntraReferenceSamplesOpenLoop {
269     EbDctor  dctor;
270     uint8_t *y_intra_reference_array_reverse;
271 
272     // Scratch buffers used in the interpolaiton process
273     uint8_t reference_above_line_y[MAX_INTRA_REFERENCE_SAMPLES];
274     uint8_t reference_left_line_y[MAX_INTRA_REFERENCE_SAMPLES];
275     EbBool  above_ready_flag_y;
276     EbBool  left_ready_flag_y;
277 } IntraReferenceSamplesOpenLoop;
278 
279 typedef struct MeHmeRefPruneCtrls {
280     EbBool enable_me_hme_ref_pruning;
281     uint16_t
282         prune_ref_if_hme_sad_dev_bigger_than_th; // TH used to prune references based on hme sad deviation
283     uint16_t
284         prune_ref_if_me_sad_dev_bigger_than_th; // TH used to prune references based on me sad deviation
285     EbBool  protect_closest_refs; // if true, do not prune closest ref frames
286 } MeHmeRefPruneCtrls;
287 
288 typedef struct MeSrCtrls {
289     EbBool enable_me_sr_adjustment;
290     uint16_t
291         reduce_me_sr_based_on_mv_length_th; // reduce the ME search region if HME MVs and HME sad are small
292     uint16_t
293         stationary_hme_sad_abs_th; // reduce the ME search region if HME MVs and HME sad are small
294     uint16_t
295         stationary_me_sr_divisor; // Reduction factor for the ME search region if HME MVs and HME sad are small
296     uint16_t
297         reduce_me_sr_based_on_hme_sad_abs_th; // reduce the ME search region if HME sad is small
298     uint16_t
299         me_sr_divisor_for_low_hme_sad; // Reduction factor for the ME search region if HME sad is small
300     uint8_t distance_based_hme_resizing; // scale down the HME search area for high ref-indices
301 } MeSrCtrls;
302 
303 #define SEARCH_REGION_COUNT 2
304 typedef struct SearchArea {
305     uint16_t   width;  // search area width
306     uint16_t   height; // search area height
307 } SearchArea;
308 typedef struct SearchAreaMinMax {
309     SearchArea   sa_min;  // min search area
310     SearchArea   sa_max;  // max search area
311 } SearchAreaMinMax;
312 typedef struct SearchInfo {
313     SearchArea       sa;      // search area sizes
314     IntMv            best_mv; // best mv
315     uint64_t         sad;     // best sad
316 } SearchInfo;
317 
318 typedef struct PreHmeCtrls {
319     uint8_t enable;
320     SearchAreaMinMax   prehme_sa_cfg[SEARCH_REGION_COUNT];
321 } PreHmeCtrls;
322 
323 typedef struct HmeResults {
324     uint8_t  list_i; // list index of this ref
325     uint8_t  ref_i; // ref list index of this ref
326     int16_t  hme_sc_x; // hme search centre x
327     int16_t  hme_sc_y; // hme search centre y
328     uint64_t hme_sad; // hme sad
329     uint8_t  do_ref; // to process this ref in ME or not
330 } HmeResults;
331 typedef struct MeContext {
332     EbDctor dctor;
333     // Search region stride
334     uint32_t                  interpolated_full_stride[MAX_NUM_OF_REF_PIC_LIST][MAX_REF_IDX];
335     uint32_t me_distortion[SQUARE_PU_COUNT];
336 
337     uint8_t * sb_src_ptr;
338     uint32_t  sb_src_stride;
339     uint8_t * quarter_sb_buffer;
340     uint32_t  quarter_sb_buffer_stride;
341     uint8_t * sixteenth_sb_buffer;
342     uint32_t  sixteenth_sb_buffer_stride;
343     uint8_t * integer_buffer_ptr[MAX_NUM_OF_REF_PIC_LIST][MAX_REF_IDX];
344     uint32_t *p_best_sad_8x8;
345     uint32_t *p_best_sad_16x16;
346     uint32_t *p_best_sad_32x32;
347     uint32_t *p_best_sad_64x64;
348     uint32_t *p_best_mv8x8;
349     uint32_t *p_best_mv16x16;
350     uint32_t *p_best_mv32x32;
351     uint32_t *p_best_mv64x64;
352     EB_ALIGN(16) uint32_t p_sad32x32[4];
353     EB_ALIGN(64) uint32_t p_sad16x16[16];
354     EB_ALIGN(64) uint32_t p_sad8x8[64];
355     uint32_t  p_sb_best_sad[MAX_NUM_OF_REF_PIC_LIST][MAX_REF_IDX][SQUARE_PU_COUNT];
356     uint32_t  p_sb_best_mv[MAX_NUM_OF_REF_PIC_LIST][MAX_REF_IDX][SQUARE_PU_COUNT];
357     uint32_t *p_best_full_pel_mv8x8;
358     uint32_t *p_best_full_pel_mv16x16;
359     uint32_t *p_best_full_pel_mv32x32;
360     uint32_t *p_best_full_pel_mv64x64;
361     uint8_t   full_quarter_pel_refinement;
362     uint16_t *p_eight_pos_sad16x16;
363     EB_ALIGN(64) uint32_t p_eight_sad32x32[4][8];
364     EB_ALIGN(64) uint32_t p_eight_sad16x16[16][8];
365     EB_ALIGN(64) uint32_t p_eight_sad8x8[64][8];
366     EbBitFraction *mvd_bits_array;
367     uint64_t       lambda;
368     uint8_t        hme_search_method;
369     uint8_t        me_search_method;
370 
371     EbBool             enable_hme_flag;
372     EbBool             enable_hme_level0_flag;
373     EbBool             enable_hme_level1_flag;
374     EbBool             enable_hme_level2_flag;
375     MeHmeRefPruneCtrls me_hme_prune_ctrls;
376     MeSrCtrls          me_sr_adjustment_ctrls;
377     uint8_t            max_hme_sr_area_multipler;
378 
379     // ME
380     uint16_t search_area_width;
381     uint16_t search_area_height;
382     uint16_t max_me_search_width;
383     uint16_t max_me_search_height;
384     uint8_t  best_list_idx;
385     uint8_t  best_ref_idx;
386     // HME
387     uint16_t   number_hme_search_region_in_width;
388     uint16_t   number_hme_search_region_in_height;
389     uint16_t   hme_level0_total_search_area_width;
390     uint16_t   hme_level0_total_search_area_height;
391     uint16_t   hme_level0_search_area_in_width_array[EB_HME_SEARCH_AREA_COLUMN_MAX_COUNT];
392     uint16_t   hme_level0_search_area_in_height_array[EB_HME_SEARCH_AREA_ROW_MAX_COUNT];
393     uint16_t   hme_level0_max_total_search_area_width;
394     uint16_t   hme_level0_max_total_search_area_height;
395     uint16_t   hme_level0_max_search_area_in_width_array[EB_HME_SEARCH_AREA_COLUMN_MAX_COUNT];
396     uint16_t   hme_level0_max_search_area_in_height_array[EB_HME_SEARCH_AREA_ROW_MAX_COUNT];
397     uint16_t   hme_level1_search_area_in_width_array[EB_HME_SEARCH_AREA_COLUMN_MAX_COUNT];
398     uint16_t   hme_level1_search_area_in_height_array[EB_HME_SEARCH_AREA_ROW_MAX_COUNT];
399     uint16_t   hme_level2_search_area_in_width_array[EB_HME_SEARCH_AREA_COLUMN_MAX_COUNT];
400     uint16_t   hme_level2_search_area_in_height_array[EB_HME_SEARCH_AREA_ROW_MAX_COUNT];
401     uint8_t    hme_decimation;
402     HmeResults hme_results[MAX_NUM_OF_REF_PIC_LIST][REF_LIST_MAX_DEPTH];
403     uint32_t   reduce_me_sr_divisor[MAX_NUM_OF_REF_PIC_LIST][REF_LIST_MAX_DEPTH];
404 
405     SearchInfo         prehme_data[MAX_NUM_OF_REF_PIC_LIST][MAX_REF_IDX][SEARCH_REGION_COUNT];
406     PreHmeCtrls     prehme_ctrl;
407     int16_t    x_hme_level0_search_center[MAX_NUM_OF_REF_PIC_LIST][MAX_REF_IDX]
408                                       [EB_HME_SEARCH_AREA_COLUMN_MAX_COUNT]
409                                       [EB_HME_SEARCH_AREA_ROW_MAX_COUNT];
410     int16_t y_hme_level0_search_center[MAX_NUM_OF_REF_PIC_LIST][MAX_REF_IDX]
411                                       [EB_HME_SEARCH_AREA_COLUMN_MAX_COUNT]
412                                       [EB_HME_SEARCH_AREA_ROW_MAX_COUNT];
413     uint64_t hme_level0_sad[MAX_NUM_OF_REF_PIC_LIST][MAX_REF_IDX]
414                            [EB_HME_SEARCH_AREA_COLUMN_MAX_COUNT][EB_HME_SEARCH_AREA_ROW_MAX_COUNT];
415     int16_t x_hme_level1_search_center[MAX_NUM_OF_REF_PIC_LIST][MAX_REF_IDX]
416                                       [EB_HME_SEARCH_AREA_COLUMN_MAX_COUNT]
417                                       [EB_HME_SEARCH_AREA_ROW_MAX_COUNT];
418     int16_t y_hme_level1_search_center[MAX_NUM_OF_REF_PIC_LIST][MAX_REF_IDX]
419                                       [EB_HME_SEARCH_AREA_COLUMN_MAX_COUNT]
420                                       [EB_HME_SEARCH_AREA_ROW_MAX_COUNT];
421     uint64_t hme_level1_sad[MAX_NUM_OF_REF_PIC_LIST][MAX_REF_IDX]
422                            [EB_HME_SEARCH_AREA_COLUMN_MAX_COUNT][EB_HME_SEARCH_AREA_ROW_MAX_COUNT];
423     int16_t x_hme_level2_search_center[MAX_NUM_OF_REF_PIC_LIST][MAX_REF_IDX]
424                                       [EB_HME_SEARCH_AREA_COLUMN_MAX_COUNT]
425                                       [EB_HME_SEARCH_AREA_ROW_MAX_COUNT];
426     int16_t y_hme_level2_search_center[MAX_NUM_OF_REF_PIC_LIST][MAX_REF_IDX]
427                                       [EB_HME_SEARCH_AREA_COLUMN_MAX_COUNT]
428                                       [EB_HME_SEARCH_AREA_ROW_MAX_COUNT];
429     uint64_t hme_level2_sad[MAX_NUM_OF_REF_PIC_LIST][MAX_REF_IDX]
430                            [EB_HME_SEARCH_AREA_COLUMN_MAX_COUNT][EB_HME_SEARCH_AREA_ROW_MAX_COUNT];
431     int16_t adjust_hme_l1_factor[MAX_NUM_OF_REF_PIC_LIST][REF_LIST_MAX_DEPTH];
432     int16_t adjust_hme_l2_factor[MAX_NUM_OF_REF_PIC_LIST][REF_LIST_MAX_DEPTH];
433     int16_t hme_factor;
434     // ------- Context for Alt-Ref ME ------
435     uint16_t adj_search_area_width;
436     uint16_t adj_search_area_height;
437     void *   alt_ref_reference_ptr;
438     // Open Loop ME
439     EbMeType                    me_type;
440     EbDownScaledBufDescPtrArray mctf_ref_desc_ptr_array;
441 
442     uint8_t                     num_of_list_to_search;
443     uint8_t                     num_of_ref_pic_to_search[2];
444     uint8_t                     temporal_layer_index;
445     EbBool                      is_used_as_reference_flag;
446     EbDownScaledBufDescPtrArray me_ds_ref_array[MAX_NUM_OF_REF_PIC_LIST][REF_LIST_MAX_DEPTH];
447     // tf
448     uint8_t      tf_chroma;
449     int          tf_frame_index;
450     int          tf_index_center;
451     signed short tf_16x16_mv_x[16];
452     signed short tf_16x16_mv_y[16];
453     uint64_t     tf_16x16_block_error[16];
454 
455     signed short tf_32x32_mv_x[4];
456     signed short tf_32x32_mv_y[4];
457     uint64_t     tf_32x32_block_error[4];
458     int          tf_32x32_block_split_flag[4];
459     int          tf_16x16_search_do[4];
460     int          tf_block_row;
461     int          tf_block_col;
462     uint32_t idx_32x32;
463     uint16_t     min_frame_size;
464     int64_t prune_me_candidates_th;
465     uint8_t reduce_hme_l0_sr_th_min;
466     uint8_t reduce_hme_l0_sr_th_max;
467 } MeContext;
468 
469 typedef uint64_t (*EB_ME_DISTORTION_FUNC)(uint8_t *src, uint32_t src_stride, uint8_t *ref,
470                                           uint32_t ref_stride, uint32_t width, uint32_t height);
471 extern EbErrorType me_context_ctor(MeContext *object_ptr);
472 
473 #ifdef __cplusplus
474 }
475 #endif
476 #endif // EbMotionEstimationContext_h
477