1 /*
2 * Copyright(c) 2018 Intel Corporation
3 * SPDX - License - Identifier: BSD - 2 - Clause - Patent
4 */
5 
6 #ifndef EbDefinitions_h
7 #define EbDefinitions_h
8 
9 #include "EbApi.h"
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 //#define BENCHMARK 0
15 #define LATENCY_PROFILE 0
16 //#define DEBUG_LIFE_CYCLE 0
17 // Internal Marcos
18 #define NON_AVX512_SUPPORT
19 
20 #ifdef __cplusplus
21 #define EB_EXTERN extern "C"
22 #else
23 #define EB_EXTERN
24 #endif // __cplusplus
25 
26 #ifdef _MSC_VER
27 // Windows Compiler
28 #elif __INTEL_COMPILER
29 #else
30 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
31 #pragma GCC diagnostic ignored "-Wuninitialized"
32 #pragma GCC diagnostic ignored "-Wunused-function"
33 #pragma GCC diagnostic ignored "-Wformat-zero-length"
34 #if   (__GNUC__ > 6)
35 #pragma GCC diagnostic ignored "-Wimplicit-fallthrough="
36 #endif
37 #endif
38 
39 #ifdef __GNUC__
40 #define AVX512_FUNC_TARGET __attribute__(( target( "avx512f,avx512dq,avx512bw,avx512vl" ) ))
41 #define AVX2_FUNC_TARGET   __attribute__(( target( "avx2" ) ))
42 #else
43 #define AVX512_FUNC_TARGET
44 #define AVX2_FUNC_TARGET
45 #endif // __GNUC__
46 
47 #ifndef _RSIZE_T_DEFINED
48     typedef size_t rsize_t;
49 #define _RSIZE_T_DEFINED
50 #endif  /* _RSIZE_T_DEFINED */
51 
52 #ifndef _ERRNO_T_DEFINED
53 #define _ERRNO_T_DEFINED
54     typedef int errno_t;
55 #endif  /* _ERRNO_T_DEFINED */
56 
57 
58 
59 
60 //Maximum 8192x4320
61 #define EB_TILE_COLUMN_MAX_COUNT                    20u
62 #define EB_TILE_ROW_MAX_COUNT                       22u
63 #define EB_TILE_MAX_COUNT                           440u
64 
65 #define EB_MIN(a,b)             (((a) < (b)) ? (a) : (b))
66 
67 #ifdef _WIN32
68 #ifndef __cplusplus
69 #define inline __inline
70 #endif
71 #elif __GNUC__
72 #define inline __inline__
73 #else
74 #error OS not supported
75 #endif
76 
77 #ifdef	_MSC_VER
78 #define FORCE_INLINE            __forceinline
79 #pragma warning( disable : 4068 ) // unknown pragma
80 #else
81 #ifdef __cplusplus
82 #define FORCE_INLINE            inline   __attribute__((always_inline))
83 #else
84 #define FORCE_INLINE            __inline __attribute__((always_inline))
85 #endif
86 #endif
87 
88 #define INPUT_SIZE_576p_TH				0x90000     // 0.58 Million
89 #define INPUT_SIZE_1080i_TH				0xB71B0     // 0.75 Million
90 #define INPUT_SIZE_1080p_TH				0x1AB3F0    // 1.75 Million
91 #define INPUT_SIZE_4K_TH				0x29F630    // 2.75 Million
92 #define INPUT_SIZE_8K_TH				0xB71B00    // 12 Million
93 
94 #define EB_INPUT_RESOLUTION             EB_U8
95 #define INPUT_SIZE_576p_RANGE_OR_LOWER	 0
96 #define INPUT_SIZE_1080i_RANGE			 1
97 #define INPUT_SIZE_1080p_RANGE	         2
98 #define INPUT_SIZE_4K_RANGE			     3
99 
100 /** The EB_GOP type is used to describe the hierarchical coding structure of
101 Groups of Pictures (GOP) units.
102 */
103 #define EB_PRED                 EB_U8
104 #define EB_PRED_LOW_DELAY_P     0
105 #define EB_PRED_LOW_DELAY_B     1
106 #define EB_PRED_RANDOM_ACCESS   2
107 #define EB_PRED_TOTAL_COUNT     3
108 #define EB_PRED_INVALID         0xFF
109 
110 // *Note - This work around is needed for the windows visual studio compiler
111 //  (MSVC) because it doesn't support the C99 header file stdint.h.
112 //  All other compilers should support the stdint.h C99 standard types.
113 #ifdef _MSC_VER
114 
115 	/** EB_U8 is an 8 bit unsigned quantity that is byte aligned */
116 	typedef unsigned __int8     EB_U8;
117 	/** EB_U16 is an 16 bit unsigned quantity that is byte aligned */
118 	typedef unsigned __int16    EB_U16;
119 	/** EB_U32 is an 32 bit unsigned quantity that is byte aligned */
120 	typedef unsigned __int32    EB_U32;
121 	/** EB_U64 is an 64 bit unsigned quantity that is byte aligned */
122 	typedef unsigned __int64    EB_U64;
123 
124 	/** EB_S8 is an 8 bit signed quantity that is byte aligned */
125 	typedef signed __int8         EB_S8;
126 	/** EB_S16 is an 16 bit signed quantity that is byte aligned */
127 	typedef signed __int16         EB_S16;
128 	/** EB_S32 is an 32 bit signed quantity that is byte aligned */
129 	typedef signed __int32        EB_S32;
130 	/** EB_S64 is an 64 bit signed quantity that is byte aligned */
131 	typedef signed __int64        EB_S64;
132 
133 #else
134 
135 #include <stdint.h>
136 
137 	/** EB_U8 is an 8 bit unsigned quantity that is byte aligned */
138 	typedef uint8_t             EB_U8;
139 	/** EB_U16 is an 16 bit unsigned quantity that is byte aligned */
140 	typedef uint16_t            EB_U16;
141 	/** EB_U32 is an 32 bit unsigned quantity that is byte aligned */
142 	typedef uint32_t            EB_U32;
143 	/** EB_U64 is an 64 bit unsigned quantity that is byte aligned */
144 	typedef uint64_t            EB_U64;
145 
146 	/** EB_S8 is an 8 bit signed quantity that is byte aligned */
147 	typedef int8_t                 EB_S8;
148 	/** EB_S16 is an 16 bit signed quantity that is byte aligned */
149 	typedef int16_t                EB_S16;
150 	/** EB_S32 is an 32 bit signed quantity that is byte aligned */
151 	typedef int32_t                EB_S32;
152 	/** EB_S64 is an 64 bit signed quantity that is byte aligned */
153 	typedef int64_t             EB_S64;
154 
155 #endif // _WIN32
156 typedef enum EB_ASM {
157     EB_ASM_C,
158     EB_ASM_AUTO,
159     EB_ASM_TYPE_TOTAL,
160     EB_ASM_TYPE_INVALID = ~0
161 } EB_ASM;
162 
163 /** The EB_BOOL type is intended to be used to represent a true or a false
164 value when passing parameters to and from the svt API.  The
165 EB_BOOL is a 32 bit quantity and is aligned on a 32 bit word boundary.
166 */
167 
168 #define EB_BOOL   EB_U8
169 #define EB_FALSE  0
170 #define EB_TRUE   1
171 
172 /** The EB_HANDLETYPE type is intended to be used to pass pointers to and from the svt
173 API.  This is a 32 bit pointer and is aligned on a 32 bit word boundary.
174 */
175 typedef void* EB_HANDLETYPE;
176 
177 /** The EB_BYTE type is intended to be used to pass arrays of bytes such as
178 buffers to and from the svt API.  The EB_BYTE type is a 32 bit pointer.
179 The pointer is word aligned and the buffer is byte aligned.
180 */
181 typedef EB_U8 * EB_BYTE;
182 
183 /** The EB_BITDEPTH type is used to describe the bitdepth of video data.
184 */
185 typedef enum EB_BITDEPTH {
186 	EB_8BIT = 8,
187 	EB_10BIT = 10,
188 	EB_12BIT = 12,
189 	EB_14BIT = 14,
190 	EB_16BIT = 16
191 } EB_BITDEPTH;
192 
193 typedef enum EB_RDOQ_PMCORE_TYPE {
194     EB_NO_RDOQ = 0,
195     EB_RDOQ,
196     EB_PMCORE,
197     EB_LIGHT,
198 } EB_RDOQ_PMCORE_TYPE;
199 
200 
201 /** The EB_PTR type is intended to be used to pass pointers to and from the svt
202 API.  This is a 32 bit pointer and is aligned on a 32 bit word boundary.
203 */
204 typedef void * EB_PTR;
205 
206 /** The EB_NULL type is used to define NULL pointer.
207 */
208 #ifdef __cplusplus
209 #define EB_NULL nullptr
210 #else
211 #define EB_NULL ((void*) 0)
212 #endif
213 
214 
215 typedef struct EB_PARAM_PORTDEFINITIONTYPE {
216     EB_U32 nFrameWidth;
217     EB_U32 nFrameHeight;
218     EB_S32 nStride;
219     EB_U32 nSize;
220 } EB_PARAM_PORTDEFINITIONTYPE;
221 
222 
223 /********************************************************************************************
224 * faster memcopy for <= 64B blocks, great w/ inlining and size known at compile time (or w/ PGO)
225 * THIS NEEDS TO STAY IN A HEADER FOR BEST PERFORMANCE
226 ********************************************************************************************/
227 
228 #include <immintrin.h>
229 
230 #if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
231 __attribute__((optimize("unroll-loops")))
232 #endif
eb_memcpy_small(void * dst_ptr,void const * src_ptr,size_t size)233 FORCE_INLINE void eb_memcpy_small(void* dst_ptr, void const* src_ptr, size_t size)
234 {
235     const char* src = (const char*)src_ptr;
236     char*       dst = (char*)dst_ptr;
237     size_t      i = 0;
238 
239 #ifdef _INTEL_COMPILER
240 #pragma unroll
241 #endif
242     while ((i + 16) <= size)
243     {
244         _mm_storeu_ps((float*)(dst + i), _mm_loadu_ps((const float*)(src + i)));
245         i += 16;
246     }
247 
248     if ((i + 8) <= size)
249     {
250         _mm_store_sd((double*)(dst + i), _mm_load_sd((const double*)(src + i)));
251         i += 8;
252     }
253 
254     for (; i < size; ++i)
255         dst[i] = src[i];
256 }
257 
eb_memcpy_SSE(void * dst_ptr,void const * src_ptr,size_t size)258 FORCE_INLINE void eb_memcpy_SSE(void* dst_ptr, void const* src_ptr, size_t size)
259 {
260     const char* src = (const char*)src_ptr;
261     char*       dst = (char*)dst_ptr;
262     size_t      i = 0;
263     size_t align_cnt = EB_MIN((64 - ((size_t)dst & 63)), size);
264 
265 
266     // align dest to a $line
267     if (align_cnt != 64)
268     {
269         eb_memcpy_small(dst, src, align_cnt);
270         dst += align_cnt;
271         src += align_cnt;
272         size -= align_cnt;
273     }
274 
275     // copy a $line at a time
276     // dst aligned to a $line
277     size_t cline_cnt = (size & ~(size_t)63);
278     for (i = 0; i < cline_cnt; i += 64)
279     {
280 
281         __m128 c0 = _mm_loadu_ps((const float*)(src + i));
282         __m128 c1 = _mm_loadu_ps((const float*)(src + i + sizeof(c0)));
283         __m128 c2 = _mm_loadu_ps((const float*)(src + i + sizeof(c0) * 2));
284         __m128 c3 = _mm_loadu_ps((const float*)(src + i + sizeof(c0) * 3));
285 
286         _mm_storeu_ps((float*)(dst + i), c0);
287         _mm_storeu_ps((float*)(dst + i + sizeof(c0)), c1);
288         _mm_storeu_ps((float*)(dst + i + sizeof(c0) * 2), c2);
289         _mm_storeu_ps((float*)(dst + i + sizeof(c0) * 3), c3);
290 
291     }
292 
293     // copy the remainder
294     if (i < size)
295         eb_memcpy_small(dst + i, src + i, size - i);
296 }
297 
eb_memcpy(void * dstPtr,void * srcPtr,size_t size)298 FORCE_INLINE void eb_memcpy(void  *dstPtr, void  *srcPtr, size_t size)
299 {
300     if (size > 64) {
301         eb_memcpy_SSE(dstPtr, srcPtr, size);
302     }
303     else
304     {
305         eb_memcpy_small(dstPtr, srcPtr, size);
306     }
307 }
308 
309 #define EB_MEMCPY(dst, src, size) \
310 	eb_memcpy(dst, src, size)
311 
312 #define EB_MEMSET(dst, val, count) \
313 	memset(dst, val, count)
314 
315 // Used to hide GCC warnings for unused function tables
316 #ifdef __GNUC__
317 #define FUNC_TABLE __attribute__ ((unused))
318 #else
319 #define FUNC_TABLE
320 #endif
321 #define EB_MAX_TEMPORAL_LAYERS                  MAX_TEMPORAL_LAYERS
322 
323 
324 // Reserved types for lib's internal use. Must be less than EB_EXT_TYPE_BASE
325 #define       EB_TYPE_UNREG_USER_DATA_SEI    3
326 #define       EB_TYPE_REG_USER_DATA_SEI      4
327 #define       EB_TYPE_PIC_STRUCT             5             // It is a requirement (for the application) that if pictureStruct is present for 1 picture it shall be present for every picture
328 
329 
330 #define	Log2f					          EbHevcLog2f_SSE2
331 extern EB_U32 Log2f(EB_U32 x);
332 
333 
334 /** The EB_PICT_STRUCT type is used to describe the picture structure.
335 */
336 #define EB_PICT_STRUCT           EB_U8
337 #define PROGRESSIVE_PICT_STRUCT  0
338 #define TOP_FIELD_PICT_STRUCT    1
339 #define BOTTOM_FIELD_PICT_STRUCT 2
340 
341 
342 /** The EB_MODETYPE type is used to describe the PU type.
343 */
344 typedef EB_U8 EB_MODETYPE;
345 #define INTER_MODE 1
346 #define INTRA_MODE 2
347 
348 #define INVALID_MODE 0xFFu
349 
350 #define PREAVX2_MASK    1
351 #define AVX2_MASK       2
352 #ifndef NON_AVX512_SUPPORT
353 #define AVX512_MASK     4
354 #endif
355 #define ASM_AVX2_BIT    3
356 
357 #define BIT(nr)         (1UL << (nr))
358 
359 /** INTRA_4x4 offsets
360 */
361 static const EB_U8 INTRA_4x4_OFFSET_X[4] = { 0, 4, 0, 4 };
362 static const EB_U8 INTRA_4x4_OFFSET_Y[4] = { 0, 0, 4, 4 };
363 
364 extern EB_U32 ASM_TYPES;
365 
366 /** Depth offsets
367 */
368 static const EB_U8 DepthOffset[4]       = { 85, 21, 5, 1 };
369 
370 /** ME 2Nx2N offsets
371 */
372 static const EB_U32 me2Nx2NOffset[4]    = { 0, 1, 5, 21 };
373 
374 /** The EB_ENC_MODE type is used to describe the encoder mode .
375 */
376 
377 #define EB_ENC_MODE         EB_U8
378 #define ENC_MODE_0          0
379 #define ENC_MODE_1          1
380 #define ENC_MODE_2          2
381 #define ENC_MODE_3          3
382 #define ENC_MODE_4          4
383 #define ENC_MODE_5          5
384 #define ENC_MODE_6          6
385 #define ENC_MODE_7          7
386 #define ENC_MODE_8          8
387 #define ENC_MODE_9          9
388 #define ENC_MODE_10         10
389 #define ENC_MODE_11         11
390 
391 #define MAX_SUPPORTED_MODES 12
392 
393 #define MAX_SUPPORTED_MODES_SUB1080P    10
394 #define MAX_SUPPORTED_MODES_1080P       11
395 #define MAX_SUPPORTED_MODES_4K_OQ       12
396 
397 #define SPEED_CONTROL_INIT_MOD ENC_MODE_5;
398 
399 
400 /** The EB_TUID type is used to identify a TU within a CU.
401 */
402 
403 #define EB_REFLIST            EB_U8
404 #define REF_LIST_0             0
405 #define REF_LIST_1             1
406 #define TOTAL_NUM_OF_REF_LISTS 2
407 #define INVALID_LIST           0xFF
408 
409 #define EB_PREDDIRECTION         EB_U8
410 #define UNI_PRED_LIST_0          0
411 #define UNI_PRED_LIST_1          1
412 #define BI_PRED                  2
413 #define EB_PREDDIRECTION_TOTAL   3
414 #define INVALID_PRED_DIRECTION   0xFF
415 
416 
417 #define UNI_PRED_LIST_0_MASK    (1 << UNI_PRED_LIST_0)
418 #define UNI_PRED_LIST_1_MASK    (1 << UNI_PRED_LIST_1)
419 #define BI_PRED_MASK            (1 << BI_PRED)
420 
421 
422 // The EB_QP_OFFSET_MODE type is used to describe the QP offset
423 #define EB_FRAME_CARACTERICTICS EB_U8
424 #define EB_FRAME_CARAC_0           0
425 #define EB_FRAME_CARAC_1           1
426 #define EB_FRAME_CARAC_2           2
427 #define EB_FRAME_CARAC_3           3
428 #define EB_FRAME_CARAC_4           4
429 
430 
431 /** The EB_PART_MODE type is used to describe the CU partition size.
432 */
433 typedef EB_U8 EB_PART_MODE;
434 #define SIZE_2Nx2N 0
435 #define SIZE_2NxN  1
436 #define SIZE_Nx2N  2
437 #define SIZE_NxN   3
438 #define SIZE_2NxnU 4
439 #define SIZE_2NxnD 5
440 #define SIZE_nLx2N 6
441 #define SIZE_nRx2N 7
442 #define SIZE_PART_MODE 8
443 
444 // Rate Control
445 #define THRESHOLD1QPINCREASE     0
446 #define THRESHOLD2QPINCREASE     1
447 
448 #define EB_IOS_POINT            EB_U8
449 #define OIS_VERY_FAST_MODE       0
450 #define OIS_FAST_MODE            1
451 #define OIS_MEDUIM_MODE          2
452 #define OIS_COMPLEX_MODE         3
453 #define OIS_VERY_COMPLEX_MODE    4
454 
455 #define _MVXT(mv) ( (EB_S16)((mv) &  0xFFFF) )
456 #define _MVYT(mv) ( (EB_S16)((mv) >> 16    ) )
457 
458 //WEIGHTED PREDICTION
459 
460 #define  WP_SHIFT1D_10BIT      2
461 #define  WP_OFFSET1D_10BIT     (-32768)
462 
463 #define  WP_SHIFT2D_10BIT      6
464 #define  WP_OFFSET2D_10BIT     0
465 
466 #define  WP_IF_OFFSET_10BIT    8192//2^(14-1)
467 
468 #define  WP_SHIFT_10BIT        4   // 14 - 10
469 #define  WP_BI_SHIFT_10BIT     5
470 
471 // Will contain the EbEncApi which will live in the EncHandle class
472 // Modifiable during encode time.
473 typedef struct EB_H265_DYN_ENC_CONFIGURATION
474 {
475     // Define the settings
476 
477     // Rate Control
478     EB_U32              availableTargetBitRate;
479 
480 
481 } EB_H265_DYN_ENC_CONFIGURATION;
482 
483 
484 /** The EB_INTRA_REFRESH_TYPE is used to describe the intra refresh type.
485 */
486 typedef enum EB_INTRA_REFRESH_TYPE {
487     CRA_REFRESH = -1,
488     IDR_REFRESH = 0
489 }EB_INTRA_REFRESH_TYPE;
490 
491 #if defined(_MSC_VER)
492 #define EB_ALIGN(n) __declspec(align(n))
493 #elif defined(__GNUC__)
494 #define EB_ALIGN(n) __attribute__((__aligned__(n)))
495 #else
496 #define EB_ALIGN(n)
497 #endif
498 
499 /** The EB_HANDLE type is used to define OS object handles for threads,
500 semaphores, mutexs, etc.
501 */
502 typedef void * EB_HANDLE;
503 
504 #define MAX_NUM_PTR                (0x1312D00 << 2) //0x4C4B4000            // Maximum number of pointers to be allocated for the library
505 
506 #define ALVALUE                     32
507 
508 // Debug Macros
509 #define OVERSHOOT_STAT_PRINT             0  // Do not remove.
510                                             // For printing overshooting percentages for both RC and fixed QP.
511                                             // Target rate and and max buffer size should be set properly even for fixed QP.
512                                             // Disabled by default.
513 #define DEADLOCK_DEBUG                   0
514 #if DEADLOCK_DEBUG
515 #include <limits.h>
516 // The recommended steps to debug encoding dead lock (hang) issue:
517 // 1. Track the POCs in the entrance and exit of the encoding pipeline,
518 //    by forcibly printing the 1st DEADLOCK_DEBUG log in RC, and the
519 //    last DEADLOCK_DEBUG log in PK;
520 // 2. Reorder the POC numbers of RC and PK separately, to check the
521 //    1st POC which couldn't be outputted from PK;
522 // 3. Open the DEADLOCK_DEBUG switch, and change the MIN_POC & MAX_POC
523 //    values clamping the range where that POC locates;
524 // 4. Check the specific stage where that POC can't go through.
525 #define MIN_POC 0
526 #define MAX_POC UINT_MAX
527 #endif
528 
529 #define LIB_PRINTF_ENABLE                1
530 #if LIB_PRINTF_ENABLE
531 #define SVT_LOG printf
532 #else
533 #if _MSC_VER
534 #define SVT_LOG(s, ...) printf("")
535 #else
536 #define SVT_LOG(s, ...) printf("",##__VA_ARGS__)
537 #endif
538 #endif
539 
540 #define EB_CREATE_SEMAPHORE(pointer, initialCount, maxCount) \
541     do { \
542         pointer = EbCreateSemaphore(initialCount, maxCount); \
543         EB_ADD_MEM(pointer, 1, EB_SEMAPHORE); \
544     } while (0)
545 
546 #define EB_DESTROY_SEMAPHORE(pointer) \
547     do { \
548         if (pointer) { \
549             EbDestroySemaphore(pointer); \
550             EB_REMOVE_MEM_ENTRY(pointer, EB_SEMAPHORE); \
551             pointer = NULL; \
552         } \
553     } while (0)
554 
555 
556 #define EB_CREATE_MUTEX(pointer) \
557     do { \
558         pointer = EbCreateMutex(); \
559         EB_ADD_MEM(pointer, 1, EB_MUTEX); \
560      } while (0)
561 
562 
563 #define EB_DESTROY_MUTEX(pointer) \
564     do { \
565         if (pointer) { \
566             EbDestroyMutex(pointer); \
567             EB_REMOVE_MEM_ENTRY(pointer, EB_MUTEX); \
568             pointer = NULL; \
569         } \
570     } while (0)
571 
572 #define EB_STRDUP(dst, src) \
573     EB_MALLOC_(char*, dst, strlen(src)+1, EB_N_PTR); \
574     strcpy_ss((char*)dst, strlen(src)+1, src);
575 
576 #define EB_SEND_END_OBJ(fifoPtrArray, count) \
577    for (unsigned int i = 0; i < count; i++) { \
578         EbObjectWrapper_t *outputWrapperPtr; \
579         EbGetEmptyObject(fifoPtrArray[0], &outputWrapperPtr); \
580         outputWrapperPtr->quitSignal = EB_TRUE; \
581         EbPostFullObject(outputWrapperPtr); \
582     }
583 
584 #define EB_CHECK_END_OBJ(wrapperPtr) \
585     if (wrapperPtr->quitSignal == EB_TRUE) { \
586         break; \
587     }
588 
589 #ifdef _WIN32
590 #define EB_SCANF sscanf_s
591 #else
592 #define EB_SCANF sscanf
593 #endif
594 
595 #ifdef _WIN32
596 #define FOPEN(f,s,m) fopen_s(&f,s,m)
597 #else
598 #define FOPEN(f,s,m) f=fopen(s,m)
599 #endif
600 
601 #ifdef _WIN32
602 #define EB_STRTOK(str,delim,next) strtok_s((char*)str,(const char*)delim,(char**)next)
603 #else
604 #define EB_STRTOK(str,delim,next) strtok_r((char*)str,(const char*)delim,(char**)next)
605 #endif
606 
607 /** The EB_CREATOR type is used to define the svt object constructors.
608 objectDblPtr is a EB_PTR to the object being constructed.
609 objectInitDataPtr is a EB_PTR to a data structure used to initialize the object.
610 */
611 typedef EB_ERRORTYPE(*EB_CREATOR)(
612     EB_PTR *objectDblPtr,
613     EB_PTR objectInitDataPtr);
614 
615 /**************************************
616 * Callback Functions
617 **************************************/
618 typedef struct EbCallback_s
619 {
620     EB_PTR                                 appPrivateData;
621     EB_PTR                                 handle;
622     void(*ErrorHandler)(
623         EB_PTR handle,
624         EB_U32 errorCode);
625 } EbCallback_t;
626 
627 
628 /** NAL UNIT TYPES
629 */
630 typedef enum NalUnitType
631 {
632 
633     NAL_UNIT_CODED_SLICE_TRAIL_N = 0, // 0
634     NAL_UNIT_CODED_SLICE_TRAIL_R,     // 1
635 
636     NAL_UNIT_CODED_SLICE_TSA_N,       // 2
637     NAL_UNIT_CODED_SLICE_TLA_R,       // 3
638 
639     NAL_UNIT_CODED_SLICE_STSA_N,      // 4
640     NAL_UNIT_CODED_SLICE_STSA_R,      // 5
641 
642     NAL_UNIT_CODED_SLICE_RADL_N,      // 6
643     NAL_UNIT_CODED_SLICE_RADL_R,      // 7
644 
645     NAL_UNIT_CODED_SLICE_RASL_N,      // 8
646     NAL_UNIT_CODED_SLICE_RASL_R,      // 9
647 
648     NAL_UNIT_RESERVED_VCL_N10,
649     NAL_UNIT_RESERVED_VCL_R11,
650     NAL_UNIT_RESERVED_VCL_N12,
651     NAL_UNIT_RESERVED_VCL_R13,
652     NAL_UNIT_RESERVED_VCL_N14,
653     NAL_UNIT_RESERVED_VCL_R15,
654 
655     NAL_UNIT_CODED_SLICE_BLA_W_LP,    // 16
656     NAL_UNIT_CODED_SLICE_BLA_W_RADL,  // 17
657     NAL_UNIT_CODED_SLICE_BLA_N_LP,    // 18
658     NAL_UNIT_CODED_SLICE_IDR_W_RADL,  // 19
659     NAL_UNIT_CODED_SLICE_IDR_N_LP,    // 20
660     NAL_UNIT_CODED_SLICE_CRA,         // 21
661     NAL_UNIT_RESERVED_IRAP_VCL22,
662     NAL_UNIT_RESERVED_IRAP_VCL23,
663 
664     NAL_UNIT_RESERVED_VCL24,
665     NAL_UNIT_RESERVED_VCL25,
666     NAL_UNIT_RESERVED_VCL26,
667     NAL_UNIT_RESERVED_VCL27,
668     NAL_UNIT_RESERVED_VCL28,
669     NAL_UNIT_RESERVED_VCL29,
670     NAL_UNIT_RESERVED_VCL30,
671     NAL_UNIT_RESERVED_VCL31,
672 
673     NAL_UNIT_VPS,                     // 32
674     NAL_UNIT_SPS,                     // 33
675     NAL_UNIT_PPS,                     // 34
676     NAL_UNIT_ACCESS_UNIT_DELIMITER,   // 35
677     NAL_UNIT_EOS,                     // 36
678     NAL_UNIT_EOB,                     // 37
679     NAL_UNIT_FILLER_DATA,             // 38
680     NAL_UNIT_PREFIX_SEI,              // 39
681     NAL_UNIT_SUFFIX_SEI,              // 40
682     NAL_UNIT_RESERVED_NVCL41,
683     NAL_UNIT_RESERVED_NVCL42,
684     NAL_UNIT_RESERVED_NVCL43,
685     NAL_UNIT_RESERVED_NVCL44,
686     NAL_UNIT_RESERVED_NVCL45,
687     NAL_UNIT_RESERVED_NVCL46,
688     NAL_UNIT_RESERVED_NVCL47,
689     NAL_UNIT_UNSPECIFIED_48,
690     NAL_UNIT_UNSPECIFIED_49,
691     NAL_UNIT_UNSPECIFIED_50,
692     NAL_UNIT_UNSPECIFIED_51,
693     NAL_UNIT_UNSPECIFIED_52,
694     NAL_UNIT_UNSPECIFIED_53,
695     NAL_UNIT_UNSPECIFIED_54,
696     NAL_UNIT_UNSPECIFIED_55,
697     NAL_UNIT_UNSPECIFIED_56,
698     NAL_UNIT_UNSPECIFIED_57,
699     NAL_UNIT_UNSPECIFIED_58,
700     NAL_UNIT_UNSPECIFIED_59,
701     NAL_UNIT_UNSPECIFIED_60,
702     NAL_UNIT_UNSPECIFIED_61,
703     NAL_UNIT_UNSPECIFIED_62,
704     NAL_UNIT_UNSPECIFIED_63,
705     NAL_UNIT_INVALID,
706 
707 } NalUnitType;
708 
709 typedef enum DIST_CALC_TYPE {
710     DIST_CALC_RESIDUAL = 0,    // SSE(Coefficients - ReconCoefficients)
711     DIST_CALC_PREDICTION = 1,    // SSE(Coefficients) *Note - useful in modes that don't send residual coeff bits
712     DIST_CALC_TOTAL = 2
713 } DIST_CALC_TYPE;
714 #define BLKSIZE 64
715 
716 typedef enum EB_SEI {
717 
718     BUFFERING_PERIOD = 0,
719     PICTURE_TIMING = 1,
720     REG_USER_DATA = 4,
721     UNREG_USER_DATA = 5,
722     RECOVERY_POINT = 6,
723     DECODED_PICTURE_HASH = 132,
724     PAN_SCAN_RECT = 2,
725     FILLER_PAYLOAD = 3,
726     USER_DATA_REGISTERED_ITU_T_T35 = 4,
727     USER_DATA_UNREGISTERED = 5,
728     SCENE_INFO = 9,
729     FULL_FRAME_SNAPSHOT = 15,
730     PROGRESSIVE_REFINEMENT_SEGMENT_START = 16,
731     PROGRESSIVE_REFINEMENT_SEGMENT_END = 17,
732     FILM_GRAIN_CHARACTERISTICS = 19,
733     POST_FILTER_HINT = 22,
734     TONE_MAPPING_INFO = 23,
735     FRAME_PACKING = 45,
736     DISPLAY_ORIENTATION = 47,
737     SOP_DESCRIPTION = 128,
738     ACTIVE_PARAMETER_SETS = 129,
739     DECODING_UNIT_INFO = 130,
740     TEMPORAL_LEVEL0_INDEX = 131,
741     SCALABLE_NESTING = 133,
742     REGION_REFRESH_INFO = 134,
743     MASTERING_DISPLAY_INFO = 137,
744     CONTENT_LIGHT_LEVEL_INFO = 144
745 
746 } EB_SEI;
747 
748 
749 #define INTERPOLATION_FREE_PATH     0
750 #define INTERPOLATION_METHOD_HEVC   1
751 
752 
753 #define ME_FILTER_TAP                    4
754 
755 
756 #define    SUB_SAD_SEARCH   0
757 #define    FULL_SAD_SEARCH  1
758 #define    SSD_SEARCH       2
759 
760 
761 #define EB_INPUT_CLASS          EB_U8
762 #define INPUT_CLASS_C			 0
763 #define INPUT_CLASS_B			 1
764 #define INPUT_CLASS_TO_REMOVE	 2
765 #define INPUT_CLASS_A			 3
766 
767 
768 //***Profile, tier, level***
769 #define TOTAL_LEVEL_COUNT                           13
770 
771 #define C1_TRSHLF_N       1
772 #define C1_TRSHLF_D       1
773 #define C2_TRSHLF_N       16
774 #define C2_TRSHLF_D       10
775 
776 
777 #define CHANGE_LAMBDA_FOR_AURA   0x01
778 
779 #define ANTI_CONTOURING_TH_0     16 * 16
780 #define ANTI_CONTOURING_TH_1     32 * 32
781 #define ANTI_CONTOURING_TH_2 2 * 32 * 32
782 
783 #define ANTI_CONTOURING_DELTA_QP_0  -3
784 #define ANTI_CONTOURING_DELTA_QP_1  -9
785 #define ANTI_CONTOURING_DELTA_QP_2  -11
786 
787 #define ANTI_CONTOURING_LUMA_T1                40
788 #define ANTI_CONTOURING_LUMA_T2                180
789 
790 
791 #define VAR_BASED_DETAIL_PRESERVATION_SELECTOR_THRSLHD         (64*64)
792 
793 #define PM_DC_TRSHLD1                       10 // The threshold for DC to disable masking for DC
794 
795 #define MAX_BITS_PER_FRAME            8000000
796 
797 #define MEAN_DIFF_THRSHOLD              10
798 #define VAR_DIFF_THRSHOLD               10
799 
800 #define SC_FRAMES_TO_IGNORE             100 // The speed control algorith starts after SC_FRAMES_TO_IGNORE number frames.
801 #define SC_FRAMES_INTERVAL_SPEED        60 // The speed control Interval To Check the speed
802 #define SC_FRAMES_INTERVAL_T1           60 // The speed control Interval Threshold1
803 #define SC_FRAMES_INTERVAL_T2          180 // The speed control Interval Threshold2
804 #define SC_FRAMES_INTERVAL_T3          120 // The speed control Interval Threshold3
805 
806 #define EB_CMPLX_CLASS           EB_U8
807 #define CMPLX_LOW                0
808 #define CMPLX_MEDIUM             1
809 #define CMPLX_HIGH               2
810 #define CMPLX_VHIGH              3
811 #define CMPLX_NOISE              4
812 
813 #define YBITS_THSHLD_1(x)                  ((x < MAX_SUPPORTED_MODES) ? 80 : 120)
814 #define YDC_THSHLD_1                        10
815 #define MASK_THSHLD_1                        1
816 
817 //***Encoding Parameters***
818 
819 #define MAX_PICTURE_WIDTH_SIZE                      9344u
820 #define MAX_PICTURE_HEIGHT_SIZE                     5120u
821 
822 #define FILLER_DATA_OVERHEAD                        6
823 
824 #define INTERNAL_BIT_DEPTH                          8 // to be modified
825 #define MAX_SAMPLE_VALUE                            ((1 << INTERNAL_BIT_DEPTH) - 1)
826 #define MAX_SAMPLE_VALUE_10BIT                      0x3FF
827 #define MAX_LCU_SIZE                                64u
828 #define MAX_LCU_SIZE_MINUS_1                        63u
829 #define LOG2F_MAX_LCU_SIZE                          6u
830 #define MAX_LCU_SIZE_REMAINING                      56u
831 #define MAX_LCU_SIZE_CHROMA                         32u
832 #define MAX_LOG2_LCU_SIZE                           6 // log2(MAX_LCU_SIZE)
833 #define MAX_LEVEL_COUNT                             5 // log2(MAX_LCU_SIZE) - log2(MIN_CU_SIZE)
834 #define MAX_TU_SIZE                                 32
835 #define MIN_TU_SIZE                                 4
836 #define MAX_TU_LEVEL_COUNT                          4 // log2(MAX_TU_SIZE) - log2(MIN_TU_SIZE)
837 #define MAX_TU_DEPTH                                2
838 #define LOG_MIN_CU_SIZE                             3
839 #define MIN_CU_SIZE                                 (1 << LOG_MIN_CU_SIZE)
840 #define MAX_CU_SIZE                                 64u
841 #define MAX_INTRA_SIZE                              32
842 #define MIN_INTRA_SIZE                              8
843 #define LOG_MIN_PU_SIZE                             2
844 #define MIN_PU_SIZE                                 (1 << LOG_MIN_PU_SIZE)
845 #define MAX_NUM_OF_PU_PER_CU                        1
846 #define MAX_NUM_OF_REF_PIC_LIST                     2
847 #define MAX_NUM_OF_PART_SIZE                        8
848 #define EB_MAX_LCU_DEPTH                            (((MAX_LCU_SIZE / MIN_CU_SIZE) == 1) ? 1 : \
849                                                      ((MAX_LCU_SIZE / MIN_CU_SIZE) == 2) ? 2 : \
850                                                      ((MAX_LCU_SIZE / MIN_CU_SIZE) == 4) ? 3 : \
851                                                      ((MAX_LCU_SIZE / MIN_CU_SIZE) == 8) ? 4 : \
852                                                      ((MAX_LCU_SIZE / MIN_CU_SIZE) == 16) ? 5 : \
853                                                      ((MAX_LCU_SIZE / MIN_CU_SIZE) == 32) ? 6 : 7)
854 #define MIN_CU_BLK_COUNT                            ((MAX_LCU_SIZE / MIN_CU_SIZE) * (MAX_LCU_SIZE / MIN_CU_SIZE))
855 #define MAX_NUM_OF_TU_PER_CU                        21
856 #define MIN_NUM_OF_TU_PER_CU                        5
857 #define MAX_LCU_ROWS                                ((MAX_PICTURE_HEIGHT_SIZE) / (MAX_LCU_SIZE))
858 
859 #define MAX_NUMBER_OF_TREEBLOCKS_PER_PICTURE       ((MAX_PICTURE_WIDTH_SIZE + MAX_LCU_SIZE - 1) / MAX_LCU_SIZE) * \
860                                                    ((MAX_PICTURE_HEIGHT_SIZE + MAX_LCU_SIZE - 1) / MAX_LCU_SIZE)
861 
862 #define MAX_AMVP_CANDIDATES_PER_REF_LIST            3
863 #define ZERO                                        0
864 #define AMVP0                                       1
865 #define AMVP1                                       2
866 
867 
868 //***Prediction Structure***
869 #define MAX_TEMPORAL_LAYERS                         6
870 #define MAX_HIERARCHICAL_LEVEL                      6
871 #define MAX_REF_IDX                                 1        // Set MAX_REF_IDX as 1 to avoid sending extra refPicIdc for each PU in IPPP flat GOP structure.
872 #define INVALID_POC                                 (((EB_U32) (~0)) - (((EB_U32) (~0)) >> 1))
873 #define MAX_ELAPSED_IDR_COUNT                       1024
874 
875 //***Segments***
876 #define EB_SEGMENT_MIN_COUNT                        1
877 #define EB_SEGMENT_MAX_COUNT                        64
878 
879 //***HME***
880 #define EB_HME_SEARCH_AREA_COLUMN_MAX_COUNT         2
881 #define EB_HME_SEARCH_AREA_ROW_MAX_COUNT            2
882 
883 //***TMVP***
884 #define LOG_MV_COMPRESS_UNIT_SIZE                   4
885 #define MAX_TMVP_CAND_PER_LCU                       (MAX_LCU_SIZE >> LOG_MV_COMPRESS_UNIT_SIZE)*(MAX_LCU_SIZE >> LOG_MV_COMPRESS_UNIT_SIZE)
886 
887 //***MV Merge***
888 #define MAX_NUM_OF_MV_MERGE_CANDIDATE               5
889 
890 //***AMVP***
891 #define MAX_NUM_OF_AMVP_CANDIDATES                  2
892 
893 //***Mode Decision Candidate List***
894 #define MAX_MODE_DECISION_CATEGORY_NUM              6
895 #define LOG_MAX_AMVP_MODE_DECISION_CANDIDATE_NUM    2
896 #define MAX_AMVP_MODE_DECISION_CANDIDATE_NUM        (1 << LOG_MAX_AMVP_MODE_DECISION_CANDIDATE_NUM)
897 
898 #define CU_MAX_COUNT                                85
899 
900 #define EB_EVENT_MAX_COUNT                          20
901 
902 #define MAX_INTRA_REFERENCE_SAMPLES                 (MAX_LCU_SIZE << 2) + 1
903 
904 #define MAX_INTRA_MODES                             35
905 
906 #define _MVXT(mv) ( (EB_S16)((mv) &  0xFFFF) )
907 #define _MVYT(mv) ( (EB_S16)((mv) >> 16    ) )
908 
909 
910 //***MCP***
911 #define MaxChromaFilterTag          4
912 #define MaxVerticalLumaFliterTag    8
913 #define MaxHorizontalLumaFliterTag  8
914 
915 #define MCPXPaddingOffset           16                                    // to be modified
916 #define MCPYPaddingOffset           16                                    // to be modified
917 
918 #define InternalBitDepth            8                                     // to be modified
919 #define MAX_Sample_Value            ((1 << InternalBitDepth) - 1)
920 #define IF_Shift                    6                                     // to be modified
921 #define IF_Prec                     14                                    // to be modified
922 #define IF_Negative_Offset          (IF_Prec - 1)                         // to be modified
923 #define InternalBitDepthIncrement   (InternalBitDepth - 8)
924 
925 
926 //***SAO***
927 #define SAO_BO_INTERVALS                                32
928 #define SAO_BO_LEN                                      4
929 #define SAO_EO_TYPES                                    4
930 #define SAO_EO_CATEGORIES                               4
931 #define MIN_SAO_OFFSET_VALUE                          -31// -7
932 #define MAX_SAO_OFFSET_VALUE                           31// 7
933 #define NUMBER_SAO_OFFSETS                              4
934 #define SAO_COMPONENT_LUMA                              0
935 #define SAO_COMPONENT_CHROMA                            1
936 #define SAO_COMPONENT_CHROMA_CB                         2
937 #define SAO_COMPONENT_CHROMA_CR                         3
938 
939 
940 #define MIN_QP_VALUE                     0
941 #define MAX_QP_VALUE                    51
942 #define MAX_CHROMA_MAP_QP_VALUE         57
943 
944 
945 //***Transforms***
946 #define TRANSFORMS_LUMA_FLAG        0
947 #define TRANSFORMS_CHROMA_FLAG      1
948 #define TRANSFORMS_COLOR_LEN        2
949 #define TRANSFORMS_LUMA_MASK        (1 << TRANSFORMS_LUMA_FLAG)
950 #define TRANSFORMS_CHROMA_MASK      (1 << TRANSFORMS_CHROMA_FLAG)
951 #define TRANSFORMS_FULL_MASK        ((1 << TRANSFORMS_LUMA_FLAG) | (1 << TRANSFORMS_CHROMA_FLAG))
952 
953 #define TRANSFORMS_SIZE_32_FLAG     0
954 #define TRANSFORMS_SIZE_16_FLAG     1
955 #define TRANSFORMS_SIZE_8_FLAG      2
956 #define TRANSFORMS_SIZE_4_FLAG      3
957 #define TRANSFORMS_SIZE_LEN         4
958 
959 #define TRANSFORM_MAX_SIZE          32
960 #define TRANSFORM_MIN_SIZE          4
961 
962 #define QP_BD_OFFSET           12 //2x(bitDepth-8) 12 for 10 bit case
963 #define BIT_INCREMENT_10BIT    2
964 #define BIT_INCREMENT_8BIT     0
965 
966 #define TRANS_BIT_INCREMENT    0
967 #define QUANT_IQUANT_SHIFT     20 // Q(QP%6) * IQ(QP%6) = 2^20
968 #define QUANT_SHIFT            14 // Q(4) = 2^14
969 #define SCALE_BITS             15 // Inherited from TMuC, pressumably for fractional bit estimates in RDOQ
970 #define MAX_TR_DYNAMIC_RANGE   15 // Maximum transform dynamic range (excluding sign bit)
971 #define MAX_POS_16BIT_NUM      32767
972 #define MIN_NEG_16BIT_NUM      -32768
973 #define QUANT_OFFSET_I         171
974 #define QUANT_OFFSET_P         85
975 #define LOW_LCU_VARIANCE		10
976 #define MEDIUM_LCU_VARIANCE		50
977 
978 //HRD constants
979 #define BR_SHIFT               6
980 #define CPB_SHIFT              4
981 
982 // INTRA restriction for global motion
983 #define INTRA_GLOBAL_MOTION_NON_MOVING_INDEX_TH  2
984 #define INTRA_GLOBAL_MOTION_DARK_LCU_TH         50
985 
986 /*********************************************************
987 * used for the first time, but not the last time interpolation filter
988 *********************************************************/
989 #define Shift1       InternalBitDepthIncrement
990 #define MinusOffset1 (1 << (IF_Negative_Offset + InternalBitDepthIncrement))
991 #if (InternalBitDepthIncrement == 0)
992 #define ChromaMinusOffset1 0
993 #else
994 #define ChromaMinusOffset1 MinusOffset1
995 #endif
996 
997 /*********************************************************
998 * used for neither the first time nor the last time interpolation filter
999 *********************************************************/
1000 #define Shift2       IF_Shift
1001 
1002 /*********************************************************
1003 * used for the first time, and also the last time interpolation filter
1004 *********************************************************/
1005 #define Shift3       IF_Shift
1006 #define Offset3      (1<<(Shift3-1))
1007 
1008 /*********************************************************
1009 * used for not the first time, but the last time interpolation filter
1010 *********************************************************/
1011 #define Shift4       (IF_Shift + IF_Shift - InternalBitDepthIncrement)
1012 #define Offset4      ((1 << (IF_Shift + IF_Negative_Offset)) + (1 << (Shift4 - 1)))
1013 #if (InternalBitDepthIncrement == 0)
1014 #define ChromaOffset4 (1 << (Shift4 - 1))
1015 #else
1016 #define ChromaOffset4 Offset4
1017 #endif
1018 
1019 /*********************************************************
1020 * used for weighted sample prediction
1021 *********************************************************/
1022 #define Shift5       (IF_Shift - InternalBitDepthIncrement + 1)
1023 #define Offset5      ((1 << (Shift5 - 1)) + (1 << (IF_Negative_Offset + 1)))
1024 #if (InternalBitDepthIncrement == 0)
1025 #define ChromaOffset5 (1 << (Shift5 - 1))
1026 #else
1027 #define ChromaOffset5 Offset5
1028 #endif
1029 
1030 /*********************************************************
1031 * used for biPredCopy()
1032 *********************************************************/
1033 #define Shift6       (IF_Shift - InternalBitDepthIncrement)
1034 #define MinusOffset6 (1 << IF_Negative_Offset)
1035 #if (InternalBitDepthIncrement == 0)
1036 #define ChromaMinusOffset6 0
1037 #else
1038 #define ChromaMinusOffset6 MinusOffset6
1039 #endif
1040 
1041 /*********************************************************
1042 * 10bit case
1043 *********************************************************/
1044 
1045 #define  SHIFT1D_10BIT      6
1046 #define  OFFSET1D_10BIT     32
1047 
1048 #define  SHIFT2D1_10BIT     2
1049 #define  OFFSET2D1_10BIT    (-32768)
1050 
1051 #define  SHIFT2D2_10BIT     10
1052 #define  OFFSET2D2_10BIT    524800
1053 
1054     //BIPRED
1055 #define  BI_SHIFT_10BIT         4
1056 #define  BI_OFFSET_10BIT        8192//2^(14-1)
1057 
1058 #define  BI_AVG_SHIFT_10BIT     5
1059 #define  BI_AVG_OFFSET_10BIT    16400
1060 
1061 #define  BI_SHIFT2D2_10BIT      6
1062 #define  BI_OFFSET2D2_10BIT     0
1063 
1064 // Noise detection
1065 #define  NOISE_VARIANCE_TH				390
1066 
1067 
1068 
1069 #define  EB_PICNOISE_CLASS    EB_U8
1070 #define  PIC_NOISE_CLASS_INV  0 //not computed
1071 #define  PIC_NOISE_CLASS_1    1 //No Noise
1072 #define  PIC_NOISE_CLASS_2    2
1073 #define  PIC_NOISE_CLASS_3    3
1074 #define  PIC_NOISE_CLASS_3_1  4
1075 #define  PIC_NOISE_CLASS_4    5
1076 #define  PIC_NOISE_CLASS_5    6
1077 #define  PIC_NOISE_CLASS_6    7
1078 #define  PIC_NOISE_CLASS_7    8
1079 #define  PIC_NOISE_CLASS_8    9
1080 #define  PIC_NOISE_CLASS_9    10
1081 #define  PIC_NOISE_CLASS_10   11 //Extreme Noise
1082 
1083 // Intrinisc
1084 #define INTRINSIC_SSE2								1
1085 
1086 // Enhance background macros for decimated 64x64
1087 #define BEA_CLASS_0_0_DEC_TH 16 * 16	// 16x16 block size * 1
1088 #define BEA_CLASS_0_DEC_TH	 16 * 16 * 2	// 16x16 block size * 2
1089 #define BEA_CLASS_1_DEC_TH	 16 * 16 * 4	// 16x16 block size * 4
1090 #define BEA_CLASS_2_DEC_TH	 16 * 16 * 8	// 16x16 block size * 8
1091 
1092 // Enhance background macros
1093 #define BEA_CLASS_0_0_TH 8 * 8    	// 8x8 block size * 1
1094 
1095 #define BEA_CLASS_0_TH	8 * 8 * 2	// 8x8 block size * 2
1096 #define BEA_CLASS_1_TH	8 * 8 * 4	// 8x8 block size * 4
1097 #define BEA_CLASS_2_TH	8 * 8 * 8	// 8x8 block size * 8
1098 
1099 #define UNCOVERED_AREA_ZZ_TH 4 * 4 * 14
1100 
1101 #define BEA_CLASS_0_ZZ_COST	 0
1102 #define BEA_CLASS_0_1_ZZ_COST	 3
1103 
1104 #define BEA_CLASS_1_ZZ_COST	10
1105 #define BEA_CLASS_2_ZZ_COST	20
1106 #define BEA_CLASS_3_ZZ_COST	30
1107 #define INVALID_ZZ_COST	(EB_U8) ~0
1108 #define PM_NON_MOVING_INDEX_TH 23
1109 #define QP_OFFSET_LCU_SCORE_0	0
1110 #define QP_OFFSET_LCU_SCORE_1	50
1111 #define QP_OFFSET_LCU_SCORE_2	100
1112 #define UNCOVERED_AREA_ZZ_COST_TH 8
1113 #define BEA_MIN_DELTA_QP_T00 1
1114 #define BEA_MIN_DELTA_QP_T0  3
1115 #define BEA_MIN_DELTA_QP_T1  5
1116 #define BEA_MIN_DELTA_QP_T2  5
1117 #define BEA_DISTANSE_RATIO_T0 900
1118 #define BEA_DISTANSE_RATIO_T1 600
1119 #define ACTIVE_PICTURE_ZZ_COST_TH 29
1120 
1121 
1122 #define BEA_MAX_DELTA_QP 1
1123 
1124 #define FAILING_MOTION_DELTA_QP			-5
1125 #define FAILING_MOTION_VAR_THRSLHD		50
1126 static const EB_U8 INTRA_AREA_TH_CLASS_1[MAX_HIERARCHICAL_LEVEL][MAX_TEMPORAL_LAYERS] = { // [Highest Temporal Layer] [Temporal Layer Index]
1127     { 20 },
1128     { 30, 20 },
1129     { 40, 30, 20 },
1130 	{ 50, 40, 30, 20 },
1131 	{ 50, 40, 30, 20, 10 },
1132 	{ 50, 40, 30, 20, 10, 10 }
1133 };
1134 
1135 // Picture split into regions for analysis (SCD, Dynamic GOP)
1136 #define CLASS_SUB_0_REGION_SPLIT_PER_WIDTH	1
1137 #define CLASS_SUB_0_REGION_SPLIT_PER_HEIGHT	1
1138 
1139 #define CLASS_1_REGION_SPLIT_PER_WIDTH		2
1140 #define CLASS_1_REGION_SPLIT_PER_HEIGHT		2
1141 
1142 #define HIGHER_THAN_CLASS_1_REGION_SPLIT_PER_WIDTH		4
1143 #define HIGHER_THAN_CLASS_1_REGION_SPLIT_PER_HEIGHT		4
1144 
1145 // Dynamic GOP activity TH - to tune
1146 
1147 #define DYNAMIC_GOP_SUB_1080P_L6_VS_L5_COST_TH		11
1148 #define DYNAMIC_GOP_SUB_1080P_L5_VS_L4_COST_TH		19
1149 #define DYNAMIC_GOP_SUB_1080P_L4_VS_L3_COST_TH		30	// No L4_VS_L3 - 25 is the TH after 1st round of tuning
1150 
1151 #define DYNAMIC_GOP_ABOVE_1080P_L6_VS_L5_COST_TH	15//25//5//
1152 #define DYNAMIC_GOP_ABOVE_1080P_L5_VS_L4_COST_TH	25//28//9//
1153 #define DYNAMIC_GOP_ABOVE_1080P_L4_VS_L3_COST_TH	30	// No L4_VS_L3 - 28 is the TH after 1st round of tuning
1154 
1155 
1156 #define DYNAMIC_GOP_SUB_480P_L6_VS_L5_COST_TH        9
1157 
1158 #define GRADUAL_LUMINOSITY_CHANGE_TH		 3
1159 #define FADED_LCU_PERCENTAGE_TH				10
1160 #define FADED_PICTURES_TH					15
1161 #define CLASS_SUB_0_PICTURE_ACTIVITY_REGIONS_TH			1
1162 #define CLASS_1_SIZE_PICTURE_ACTIVITY_REGIONS_TH		2
1163 #define HIGHER_THAN_CLASS_1_PICTURE_ACTIVITY_REGIONS_TH	8
1164 
1165 #define IS_COMPLEX_LCU_VARIANCE_TH						100
1166 #define IS_COMPLEX_LCU_FLAT_VARIANCE_TH					 10
1167 #define IS_COMPLEX_LCU_VARIANCE_DEVIATION_TH			 13
1168 #define IS_COMPLEX_LCU_ZZ_SAD_FACTOR_TH					 25
1169 
1170 // The EB_AURA_STATUS type is used to describe the aura status
1171 #define EB_AURA_STATUS       EB_U8
1172 #define AURA_STATUS_0        0
1173 #define AURA_STATUS_1        1
1174 #define AURA_STATUS_2        2
1175 #define AURA_STATUS_3        3
1176 #define INVALID_AURA_STATUS  128
1177 
1178 // Aura detection definitions
1179 #define	AURA_4K_DISTORTION_TH	25
1180 #define	AURA_4K_DISTORTION_TH_6L 20
1181 
1182 
1183 
1184 static const EB_S32 GLOBAL_MOTION_THRESHOLD[MAX_HIERARCHICAL_LEVEL][MAX_TEMPORAL_LAYERS] = { // [Highest Temporal Layer] [Temporal Layer Index]
1185 	{ 2 },
1186 	{ 4, 2 },
1187 	{ 8, 4, 2 },
1188 	{ 16, 8, 4, 2 },
1189 	{ 32, 16, 8, 4, 2 },	// Derived by analogy from 4-layer settings
1190 	{ 64, 32, 16, 8, 4, 2 }
1191 };
1192 
1193 
1194 // The EB_4L_PRED_ERROR_CLASS type is used to inform about the prediction error compared to 4L
1195 #define EB_4L_PRED_ERROR_CLASS    EB_U8
1196 #define PRED_ERROR_CLASS_0          0
1197 #define PRED_ERROR_CLASS_1          1
1198 #define INVALID_PRED_ERROR_CLASS    128
1199 
1200 #define EB_SCD_MODE EB_U8
1201 #define SCD_MODE_0   0	 // SCD OFF
1202 #define SCD_MODE_1   1	 // Light SCD (histograms generation on the 1/16 decimated input)
1203 #define SCD_MODE_2   2	 // Full SCD
1204 
1205 
1206 #define EB_NOISE_DETECT_MODE EB_U8
1207 #define NOISE_DETECT_HALF_PRECISION      0	 // Use Half-pel decimated input to detect noise
1208 #define NOISE_DETECT_QUARTER_PRECISION   1	 // Use Quarter-pel decimated input to detect noise
1209 #define NOISE_DETECT_FULL_PRECISION      2	 // Use Full-pel decimated input to detect noise
1210 
1211 #define EB_PM_MODE EB_U8
1212 #define PM_MODE_0  1	 // 2-stage PM 4K
1213 #define PM_MODE_1  2	 // 2-stage PM Sub 4K
1214 
1215 
1216 
1217 #define EB_ZZ_SAD_MODE EB_U8
1218 #define ZZ_SAD_MODE_0  0		// ZZ SAD on Decimated resolution
1219 #define ZZ_SAD_MODE_1  1		// ZZ SAD on Full resolution
1220 
1221 #define EB_PF_MODE EB_U8
1222 #define PF_OFF  0
1223 #define PF_N2   1
1224 #define PF_N4   2
1225 
1226 #define NUM_QPS   52
1227 
1228 #define TH_BIAS_DARK_LCU 37
1229 
1230 typedef enum EB_CHROMA_MODE {
1231     CHROMA_MODE_FULL = 1,   // 0: Full Search Chroma for All
1232     CHROMA_MODE_BEST = 2    // 1: Chroma OFF if I_SLICE, Chroma for only MV_Merge if P/B_SLICE
1233 } EB_CHROMA_MODE;
1234 
1235 #define EB_LCU_COMPLEXITY_STATUS EB_U8
1236 #define LCU_COMPLEXITY_STATUS_0                  0
1237 #define LCU_COMPLEXITY_STATUS_1                  1
1238 #define LCU_COMPLEXITY_STATUS_2                  2
1239 #define LCU_COMPLEXITY_STATUS_INVALID   (EB_U8) ~0
1240 
1241 #define LCU_COMPLEXITY_NON_MOVING_INDEX_TH_0 30
1242 #define LCU_COMPLEXITY_NON_MOVING_INDEX_TH_1 29
1243 #define LCU_COMPLEXITY_NON_MOVING_INDEX_TH_2 23
1244 
1245 typedef enum EB_SAO_MODE {
1246     SAO_MODE_0 = 0,
1247     SAO_MODE_1 = 1
1248 } EB_SAO_MODE;
1249 
1250 typedef enum EB_CU_16x16_MODE {
1251 	CU_16x16_MODE_0 = 0,  // Perform OIS, Full_Search, Fractional_Search & Bipred for CU_16x16
1252 	CU_16x16_MODE_1 = 1   // Perform OIS and only Full_Search for CU_16x16
1253 } EB_CU_16x16_MODE;
1254 
1255 typedef enum EB_CU_8x8_MODE {
1256 	CU_8x8_MODE_0 = 0,  // Perform OIS, Full_Search, Fractional_Search & Bipred for CU_8x8
1257 	CU_8x8_MODE_1 = 1   // Do not perform OIS @ P/B Slices and only Full_Search for CU_8x8
1258 } EB_CU_8x8_MODE;
1259 
1260 typedef enum EB_PICTURE_DEPTH_MODE {
1261 
1262     PICT_LCU_SWITCH_DEPTH_MODE          = 0,
1263     PICT_FULL85_DEPTH_MODE              = 1,
1264     PICT_FULL84_DEPTH_MODE              = 2,
1265     PICT_BDP_DEPTH_MODE                 = 3,
1266     PICT_LIGHT_BDP_DEPTH_MODE           = 4,
1267     PICT_OPEN_LOOP_DEPTH_MODE           = 5
1268 } EB_PICTURE_DEPTH_MODE;
1269 
1270 #define EB_LCU_DEPTH_MODE EB_U8
1271 #define LCU_FULL85_DEPTH_MODE                1
1272 #define LCU_FULL84_DEPTH_MODE                2
1273 #define LCU_BDP_DEPTH_MODE                   3
1274 #define LCU_LIGHT_BDP_DEPTH_MODE             4
1275 #define LCU_OPEN_LOOP_DEPTH_MODE             5
1276 #define LCU_LIGHT_OPEN_LOOP_DEPTH_MODE       6
1277 #define LCU_AVC_DEPTH_MODE                   7
1278 #define LCU_LIGHT_AVC_DEPTH_MODE             8
1279 #define LCU_PRED_OPEN_LOOP_DEPTH_MODE        9
1280 #define LCU_PRED_OPEN_LOOP_1_NFL_DEPTH_MODE 10
1281 
1282 
1283 typedef enum EB_INTRA4x4_SEARCH_METHOD {
1284     INTRA4x4_OFF               = 0,
1285     INTRA4x4_INLINE_SEARCH     = 1,
1286     INTRA4x4_REFINEMENT_SEARCH = 2,
1287 } EB_INTRA4x4_SEARCH_METHOD;
1288 
1289 
1290 
1291 typedef enum EB_ADP_DEPTH_SENSITIVE_PIC_CLASS {
1292     DEPTH_SENSITIVE_PIC_CLASS_0 = 0,    // Normal picture
1293     DEPTH_SENSITIVE_PIC_CLASS_1 = 1,    // High complex picture
1294     DEPTH_SENSITIVE_PIC_CLASS_2 = 2     // Moderate complex picture
1295 } EB_ADP_DEPTH_SENSITIVE_PIC_CLASS;
1296 
1297 
1298 typedef enum EB_ADP_REFINEMENT_MODE {
1299     ADP_REFINMENT_OFF = 0,  // Off
1300     ADP_MODE_0        = 1,  // Light AVC (only 16x16)
1301     ADP_MODE_1        = 2   // AVC (only 8x8 & 16x16 @ the Open Loop Search)
1302 } EB_ADP_REFINEMENT_MODE;
1303 
1304 typedef enum EB_MD_STAGE {
1305 
1306 	MDC_STAGE = 0,
1307 	BDP_PILLAR_STAGE = 1,
1308 	BDP_64X64_32X32_REF_STAGE = 2,
1309 	BDP_16X16_8X8_REF_STAGE = 3,
1310 	BDP_MVMERGE_STAGE = 4
1311 
1312 } EB_MD_STAGE;
1313 
1314 #define EB_TRANS_COEFF_SHAPE EB_U8
1315 
1316 #define DEFAULT_SHAPE 0
1317 #define N2_SHAPE      1
1318 #define N4_SHAPE      2
1319 #define ONLY_DC_SHAPE 3
1320 
1321 
1322 static const EB_S32 HME_LEVEL_0_SEARCH_AREA_MULTIPLIER_X[MAX_HIERARCHICAL_LEVEL][MAX_TEMPORAL_LAYERS] = { // [Highest Temporal Layer] [Temporal Layer Index]
1323 	{ 100 },
1324 	{ 100, 100 },
1325 	{ 100, 100, 100 },
1326 	{ 200, 140, 100,  70 },
1327 	{ 350, 200, 100, 100, 100 },
1328 	{ 525, 350, 200, 100, 100, 100 }
1329 };
1330 
1331 static const EB_S32 HME_LEVEL_0_SEARCH_AREA_MULTIPLIER_Y[MAX_HIERARCHICAL_LEVEL][MAX_TEMPORAL_LAYERS] = { // [Highest Temporal Layer] [Temporal Layer Index]
1332 	{ 100 },
1333 	{ 100, 100 },
1334 	{ 100, 100, 100 },
1335 	{ 200, 140, 100, 70 },
1336 	{ 350, 200, 100, 100, 100 },
1337 	{ 525, 350, 200, 100, 100, 100 }
1338 };
1339 
1340 typedef enum RASTER_SCAN_CU_INDEX {
1341 
1342 	 // 2Nx2N [85 partitions]
1343 	 RASTER_SCAN_CU_INDEX_64x64 = 0,
1344 	 RASTER_SCAN_CU_INDEX_32x32_0 = 1,
1345 	 RASTER_SCAN_CU_INDEX_32x32_1 = 2,
1346 	 RASTER_SCAN_CU_INDEX_32x32_2 = 3,
1347 	 RASTER_SCAN_CU_INDEX_32x32_3 = 4,
1348 	 RASTER_SCAN_CU_INDEX_16x16_0 = 5,
1349 	 RASTER_SCAN_CU_INDEX_16x16_1 = 6,
1350 	 RASTER_SCAN_CU_INDEX_16x16_2 = 7,
1351 	 RASTER_SCAN_CU_INDEX_16x16_3 = 8,
1352 	 RASTER_SCAN_CU_INDEX_16x16_4 = 9,
1353 	 RASTER_SCAN_CU_INDEX_16x16_5 = 10,
1354 	 RASTER_SCAN_CU_INDEX_16x16_6 = 11,
1355 	 RASTER_SCAN_CU_INDEX_16x16_7 = 12,
1356 	 RASTER_SCAN_CU_INDEX_16x16_8 = 13,
1357 	 RASTER_SCAN_CU_INDEX_16x16_9 = 14,
1358 	 RASTER_SCAN_CU_INDEX_16x16_10 = 15,
1359 	 RASTER_SCAN_CU_INDEX_16x16_11 = 16,
1360 	 RASTER_SCAN_CU_INDEX_16x16_12 = 17,
1361 	 RASTER_SCAN_CU_INDEX_16x16_13 = 18,
1362 	 RASTER_SCAN_CU_INDEX_16x16_14 = 19,
1363 	 RASTER_SCAN_CU_INDEX_16x16_15 = 20,
1364 	 RASTER_SCAN_CU_INDEX_8x8_0 = 21,
1365 	 RASTER_SCAN_CU_INDEX_8x8_1 = 22,
1366 	 RASTER_SCAN_CU_INDEX_8x8_2 = 23,
1367 	 RASTER_SCAN_CU_INDEX_8x8_3 = 24,
1368 	 RASTER_SCAN_CU_INDEX_8x8_4 = 25,
1369 	 RASTER_SCAN_CU_INDEX_8x8_5 = 26,
1370 	 RASTER_SCAN_CU_INDEX_8x8_6 = 27,
1371 	 RASTER_SCAN_CU_INDEX_8x8_7 = 28,
1372 	 RASTER_SCAN_CU_INDEX_8x8_8 = 29,
1373 	 RASTER_SCAN_CU_INDEX_8x8_9 = 30,
1374 	 RASTER_SCAN_CU_INDEX_8x8_10 = 31,
1375 	 RASTER_SCAN_CU_INDEX_8x8_11 = 32,
1376 	 RASTER_SCAN_CU_INDEX_8x8_12 = 33,
1377 	 RASTER_SCAN_CU_INDEX_8x8_13 = 34,
1378 	 RASTER_SCAN_CU_INDEX_8x8_14 = 35,
1379 	 RASTER_SCAN_CU_INDEX_8x8_15 = 36,
1380 	 RASTER_SCAN_CU_INDEX_8x8_16 = 37,
1381 	 RASTER_SCAN_CU_INDEX_8x8_17 = 38,
1382 	 RASTER_SCAN_CU_INDEX_8x8_18 = 39,
1383 	 RASTER_SCAN_CU_INDEX_8x8_19 = 40,
1384 	 RASTER_SCAN_CU_INDEX_8x8_20 = 41,
1385 	 RASTER_SCAN_CU_INDEX_8x8_21 = 42,
1386 	 RASTER_SCAN_CU_INDEX_8x8_22 = 43,
1387 	 RASTER_SCAN_CU_INDEX_8x8_23 = 44,
1388 	 RASTER_SCAN_CU_INDEX_8x8_24 = 45,
1389 	 RASTER_SCAN_CU_INDEX_8x8_25 = 46,
1390 	 RASTER_SCAN_CU_INDEX_8x8_26 = 47,
1391 	 RASTER_SCAN_CU_INDEX_8x8_27 = 48,
1392 	 RASTER_SCAN_CU_INDEX_8x8_28 = 49,
1393 	 RASTER_SCAN_CU_INDEX_8x8_29 = 50,
1394 	 RASTER_SCAN_CU_INDEX_8x8_30 = 51,
1395 	 RASTER_SCAN_CU_INDEX_8x8_31 = 52,
1396 	 RASTER_SCAN_CU_INDEX_8x8_32 = 53,
1397 	 RASTER_SCAN_CU_INDEX_8x8_33 = 54,
1398 	 RASTER_SCAN_CU_INDEX_8x8_34 = 55,
1399 	 RASTER_SCAN_CU_INDEX_8x8_35 = 56,
1400 	 RASTER_SCAN_CU_INDEX_8x8_36 = 57,
1401 	 RASTER_SCAN_CU_INDEX_8x8_37 = 58,
1402 	 RASTER_SCAN_CU_INDEX_8x8_38 = 59,
1403 	 RASTER_SCAN_CU_INDEX_8x8_39 = 60,
1404 	 RASTER_SCAN_CU_INDEX_8x8_40 = 61,
1405 	 RASTER_SCAN_CU_INDEX_8x8_41 = 62,
1406 	 RASTER_SCAN_CU_INDEX_8x8_42 = 63,
1407 	 RASTER_SCAN_CU_INDEX_8x8_43 = 64,
1408 	 RASTER_SCAN_CU_INDEX_8x8_44 = 65,
1409 	 RASTER_SCAN_CU_INDEX_8x8_45 = 66,
1410 	 RASTER_SCAN_CU_INDEX_8x8_46 = 67,
1411 	 RASTER_SCAN_CU_INDEX_8x8_47 = 68,
1412 	 RASTER_SCAN_CU_INDEX_8x8_48 = 69,
1413 	 RASTER_SCAN_CU_INDEX_8x8_49 = 70,
1414 	 RASTER_SCAN_CU_INDEX_8x8_50 = 71,
1415 	 RASTER_SCAN_CU_INDEX_8x8_51 = 72,
1416 	 RASTER_SCAN_CU_INDEX_8x8_52 = 73,
1417 	 RASTER_SCAN_CU_INDEX_8x8_53 = 74,
1418 	 RASTER_SCAN_CU_INDEX_8x8_54 = 75,
1419 	 RASTER_SCAN_CU_INDEX_8x8_55 = 76,
1420 	 RASTER_SCAN_CU_INDEX_8x8_56 = 77,
1421 	 RASTER_SCAN_CU_INDEX_8x8_57 = 78,
1422 	 RASTER_SCAN_CU_INDEX_8x8_58 = 79,
1423 	 RASTER_SCAN_CU_INDEX_8x8_59 = 80,
1424 	 RASTER_SCAN_CU_INDEX_8x8_60 = 81,
1425 	 RASTER_SCAN_CU_INDEX_8x8_61 = 82,
1426 	 RASTER_SCAN_CU_INDEX_8x8_62 = 83,
1427 	 RASTER_SCAN_CU_INDEX_8x8_63 = 84
1428 } RASTER_SCAN_CU_INDEX;
1429 
1430 static const EB_U32 RASTER_SCAN_CU_X[CU_MAX_COUNT] =
1431 {
1432 	0,
1433 	0, 32,
1434 	0, 32,
1435 	0, 16, 32, 48,
1436 	0, 16, 32, 48,
1437 	0, 16, 32, 48,
1438 	0, 16, 32, 48,
1439 	0, 8, 16, 24, 32, 40, 48, 56,
1440 	0, 8, 16, 24, 32, 40, 48, 56,
1441 	0, 8, 16, 24, 32, 40, 48, 56,
1442 	0, 8, 16, 24, 32, 40, 48, 56,
1443 	0, 8, 16, 24, 32, 40, 48, 56,
1444 	0, 8, 16, 24, 32, 40, 48, 56,
1445 	0, 8, 16, 24, 32, 40, 48, 56,
1446 	0, 8, 16, 24, 32, 40, 48, 56
1447 };
1448 
1449 static const EB_U32 RASTER_SCAN_CU_Y[CU_MAX_COUNT] =
1450 {
1451 	0,
1452 	0, 0,
1453 	32, 32,
1454 	0, 0, 0, 0,
1455 	16, 16, 16, 16,
1456 	32, 32, 32, 32,
1457 	48, 48, 48, 48,
1458 	0, 0, 0, 0, 0, 0, 0, 0,
1459 	8, 8, 8, 8, 8, 8, 8, 8,
1460 	16, 16, 16, 16, 16, 16, 16, 16,
1461 	24, 24, 24, 24, 24, 24, 24, 24,
1462 	32, 32, 32, 32, 32, 32, 32, 32,
1463 	40, 40, 40, 40, 40, 40, 40, 40,
1464 	48, 48, 48, 48, 48, 48, 48, 48,
1465 	56, 56, 56, 56, 56, 56, 56, 56
1466 };
1467 
1468 static const EB_U32 RASTER_SCAN_CU_SIZE[CU_MAX_COUNT] =
1469 {	64,
1470 	32, 32,
1471 	32, 32,
1472 	16, 16, 16, 16,
1473 	16, 16, 16, 16,
1474 	16, 16, 16, 16,
1475 	16, 16, 16, 16,
1476 	8, 8, 8, 8, 8, 8, 8, 8,
1477 	8, 8, 8, 8, 8, 8, 8, 8,
1478 	8, 8, 8, 8, 8, 8, 8, 8,
1479 	8, 8, 8, 8, 8, 8, 8, 8,
1480 	8, 8, 8, 8, 8, 8, 8, 8,
1481 	8, 8, 8, 8, 8, 8, 8, 8,
1482 	8, 8, 8, 8, 8, 8, 8, 8,
1483 	8, 8, 8, 8, 8, 8, 8, 8
1484 };
1485 
1486 static const EB_U32 RASTER_SCAN_CU_DEPTH[CU_MAX_COUNT] =
1487 {	0,
1488 	1, 1,
1489 	1, 1,
1490 	2, 2, 2, 2,
1491 	2, 2, 2, 2,
1492 	2, 2, 2, 2,
1493 	2, 2, 2, 2,
1494 	3, 3, 3, 3, 3, 3, 3, 3,
1495 	3, 3, 3, 3, 3, 3, 3, 3,
1496 	3, 3, 3, 3, 3, 3, 3, 3,
1497 	3, 3, 3, 3, 3, 3, 3, 3,
1498 	3, 3, 3, 3, 3, 3, 3, 3,
1499 	3, 3, 3, 3, 3, 3, 3, 3,
1500 	3, 3, 3, 3, 3, 3, 3, 3,
1501 	3, 3, 3, 3, 3, 3, 3, 3
1502 };
1503 
1504 static const EB_U32 RASTER_SCAN_TO_MD_SCAN[CU_MAX_COUNT] =
1505 {
1506 	0,
1507 	1, 22,
1508 	43, 64,
1509 	2, 7, 23, 28,
1510 	12, 17, 33, 38,
1511 	44, 49, 65, 70,
1512 	54, 59, 75, 80,
1513 	3, 4, 8, 9, 24, 25, 29, 30,
1514 	5, 6, 10, 11, 26, 27, 31, 32,
1515 	13, 14, 18, 19, 34, 35, 39, 40,
1516 	15, 16, 20, 21, 36, 37, 41, 42,
1517 	45, 46, 50, 51, 66, 67, 71, 72,
1518 	47, 48, 52, 53, 68, 69, 73, 74,
1519 	55, 56, 60, 61, 76, 77, 81, 82,
1520 	57, 58, 62, 63, 78, 79, 83, 84
1521 };
1522 
1523 static const EB_U32 ParentBlockIndex[85] = { 0, 0, 0, 2, 2, 2, 2, 0, 7, 7, 7, 7, 0, 12, 12, 12, 12, 0, 17, 17, 17, 17, 0, 0,
1524 23, 23, 23, 23, 0, 28, 28, 28, 28, 0, 33, 33, 33, 33, 0, 38, 38, 38, 38, 0, 0,
1525 44, 44, 44, 44, 0, 49, 49, 49, 49, 0, 54, 54, 54, 54, 0, 59, 59, 59, 59, 0, 0,
1526 65, 65, 65, 65, 0, 70, 70, 70, 70, 0, 75, 75, 75, 75, 0, 80, 80, 80, 80 };
1527 
1528 static const EB_U32 MD_SCAN_TO_RASTER_SCAN[CU_MAX_COUNT] =
1529 {
1530 	0,
1531 	1,
1532 	5, 21, 22, 29, 30,
1533 	6, 23, 24, 31, 32,
1534 	9, 37, 38, 45, 46,
1535 	10, 39, 40, 47, 48,
1536 	2,
1537 	7, 25, 26, 33, 34,
1538 	8, 27, 28, 35, 36,
1539 	11, 41, 42, 49, 50,
1540 	12, 43, 44, 51, 52,
1541 	3,
1542 	13, 53, 54, 61, 62,
1543 	14, 55, 56, 63, 64,
1544 	17, 69, 70, 77, 78,
1545 	18, 71, 72, 79, 80,
1546 	4,
1547 	15, 57, 58, 65, 66,
1548 	16, 59, 60, 67, 68,
1549 	19, 73, 74, 81, 82,
1550 	20, 75, 76, 83, 84
1551 };
1552 
1553 static const EB_U32 RASTER_SCAN_CU_PARENT_INDEX[CU_MAX_COUNT] =
1554 { 0,
1555 0, 0,
1556 0, 0,
1557 1, 1, 2, 2,
1558 1, 1, 2, 2,
1559 3, 3, 4, 4,
1560 3, 3, 4, 4,
1561 5, 5, 6, 6, 7, 7, 8, 8,
1562 5, 5, 6, 6, 7, 7, 8, 8,
1563 9, 9, 10, 10, 11, 11, 12, 12,
1564 9, 9, 10, 10, 11, 11, 12, 12,
1565 13, 13, 14, 14, 15, 15, 16, 16,
1566 13, 13, 14, 14, 15, 15, 16, 16,
1567 17, 17, 18, 18, 19, 19, 20, 20,
1568 17, 17, 18, 18, 19, 19, 20, 20
1569 };
1570 
1571 
1572 #define UNCOMPRESS_SAD(x) ( ((x) & 0x1FFF)<<(((x)>>13) & 7) )
1573 
1574 static const EB_U32 MD_SCAN_TO_OIS_32x32_SCAN[CU_MAX_COUNT] =
1575 {
1576 /*0  */0,
1577 /*1  */0,
1578 /*2  */0,
1579 /*3  */0,
1580 /*4  */0,
1581 /*5  */0,
1582 /*6  */0,
1583 /*7  */0,
1584 /*8  */0,
1585 /*9  */0,
1586 /*10 */0,
1587 /*11 */0,
1588 /*12 */0,
1589 /*13 */0,
1590 /*14 */0,
1591 /*15 */0,
1592 /*16 */0,
1593 /*17 */0,
1594 /*18 */0,
1595 /*19 */0,
1596 /*20 */0,
1597 /*21 */0,
1598 /*22 */1,
1599 /*23 */1,
1600 /*24 */1,
1601 /*25 */1,
1602 /*26 */1,
1603 /*27 */1,
1604 /*28 */1,
1605 /*29 */1,
1606 /*30 */1,
1607 /*31 */1,
1608 /*32 */1,
1609 /*33 */1,
1610 /*34 */1,
1611 /*35 */1,
1612 /*36 */1,
1613 /*37 */1,
1614 /*38 */1,
1615 /*39 */1,
1616 /*40 */1,
1617 /*41 */1,
1618 /*42 */1,
1619 /*43 */2,
1620 /*44 */2,
1621 /*45 */2,
1622 /*46 */2,
1623 /*47 */2,
1624 /*48 */2,
1625 /*49 */2,
1626 /*50 */2,
1627 /*51 */2,
1628 /*52 */2,
1629 /*53 */2,
1630 /*54 */2,
1631 /*55 */2,
1632 /*56 */2,
1633 /*57 */2,
1634 /*58 */2,
1635 /*59 */2,
1636 /*60 */2,
1637 /*61 */2,
1638 /*62 */2,
1639 /*63 */2,
1640 /*64 */3,
1641 /*65 */3,
1642 /*66 */3,
1643 /*67 */3,
1644 /*68 */3,
1645 /*69 */3,
1646 /*70 */3,
1647 /*71 */3,
1648 /*72 */3,
1649 /*73 */3,
1650 /*74 */3,
1651 /*75 */3,
1652 /*76 */3,
1653 /*77 */3,
1654 /*78 */3,
1655 /*79 */3,
1656 /*80 */3,
1657 /*81 */3,
1658 /*82 */3,
1659 /*83 */3,
1660 /*84 */3,
1661 };
1662 /******************************************************************************
1663                             ME/HME settings OQ
1664 *******************************************************************************/
1665 //     M0    M1    M2    M3    M4    M5    M6    M7    M8    M9    M10   M11
1666 static const EB_U8 EnableHmeLevel0FlagOq[5][MAX_SUPPORTED_MODES] = {
1667 	{   1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1 },      // INPUT_SIZE_576p_RANGE_OR_LOWER
1668 	{   1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1 },      // INPUT_SIZE_720P_RANGE
1669 	{   1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1 },      // INPUT_SIZE_1080i_RANGE
1670 	{   1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1 },      // INPUT_SIZE_1080p_RANGE
1671 	{   1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1 },      // INPUT_SIZE_4K_RANGE
1672 };
1673 static const EB_U16 HmeLevel0TotalSearchAreaWidthOq[5][MAX_SUPPORTED_MODES] = {
1674 	{  48,   48,   48,   48,   48,   48,   48,   48,   48,   32,   32,   32 },
1675 	{  64,   64,   64,   64,   64,   64,   64,   48,   48,   48,   48,   48 },
1676 	{  96,   96,   96,   96,   96,   96,   96,   64,   64,   48,   48,   48 },
1677 	{  96,   96,   96,   96,   96,   96,   96,   64,   64,   48,   48,   48 },
1678 	{ 128,  128,  128,  128,   64,   64,   64,   64,   64,   64,   64,   64 }
1679 };
1680 
1681 static const EB_U16 HmeLevel0SearchAreaInWidthArrayLeftOq[5][MAX_SUPPORTED_MODES] = {
1682 	{  24,   24,   24,   24,   24,   24,   24,   24,   24,   16,   16,   16 },
1683 	{  32,   32,   32,   32,   32,   32,   32,   24,   24,   24,   24,   24 },
1684 	{  48,   48,   48,   48,   48,   48,   48,   32,   32,   24,   24,   24 },
1685 	{  48,   48,   48,   48,   48,   48,   48,   32,   32,   24,   24,   24 },
1686 	{  64,   64,   64,   64,   32,   32,   32,   32,   32,   32,   32,   32 }
1687 };
1688 static const EB_U16 HmeLevel0SearchAreaInWidthArrayRightOq[5][MAX_SUPPORTED_MODES] = {
1689 	{  24,   24,   24,   24,   24,   24,   24,   24,   24,   16,   16,   16 },
1690 	{  32,   32,   32,   32,   32,   32,   32,   24,   24,   24,   24,   24 },
1691 	{  48,   48,   48,   48,   48,   48,   48,   32,   32,   24,   24,   24 },
1692 	{  48,   48,   48,   48,   48,   48,   48,   32,   32,   24,   24,   24 },
1693 	{  64,   64,   64,   64,   32,   32,   32,   32,   32,   32,   32,   32 }
1694 };
1695 static const EB_U16 HmeLevel0TotalSearchAreaHeightOq[5][MAX_SUPPORTED_MODES] = {
1696 	{  40,   40,   40,   40,   40,   32,   32,   32,   32,   24,   24,   24 },
1697 	{  48,   48,   48,   48,   48,   40,   40,   40,   40,   32,   32,   32 },
1698 	{  48,   48,   48,   48,   48,   32,   32,   32,   32,   32,   32,   32 },
1699 	{  48,   48,   48,   48,   48,   48,   48,   48,   48,   40,   40,   40 },
1700 	{  80,   80,   80,   80,   32,   32,   32,   32,   32,   32,   32,   32 }
1701 };
1702 static const EB_U16 HmeLevel0SearchAreaInHeightArrayTopOq[5][MAX_SUPPORTED_MODES] = {
1703 	{  20,   20,   20,   20,   20,   16,   16,   16,   16,   12,   12,   12 },
1704 	{  24,   24,   24,   24,   24,   20,   20,   20,   20,   16,   16,   16 },
1705 	{  24,   24,   24,   24,   24,   16,   16,   16,   16,   16,   16,   16 },
1706 	{  24,   24,   24,   24,   24,   24,   24,   24,   24,   20,   20,   20 },
1707 	{  40,   40,   40,   40,   16,   16,   16,   16,   16,   16,   16,   16 }
1708 };
1709 static const EB_U16 HmeLevel0SearchAreaInHeightArrayBottomOq[5][MAX_SUPPORTED_MODES] = {
1710 	{  20,   20,   20,   20,   20,   16,   16,   16,   16,   12,   12,   12 },
1711 	{  24,   24,   24,   24,   24,   20,   20,   20,   20,   16,   16,   16 },
1712 	{  24,   24,   24,   24,   24,   16,   16,   16,   16,   16,   16,   16 },
1713 	{  24,   24,   24,   24,   24,   24,   24,   24,   24,   20,   20,   20 },
1714 	{  40,   40,   40,   40,   16,   16,   16,   16,   16,   16,   16,   16 }
1715 };
1716 
1717 // HME LEVEL 1
1718 //     M0    M1    M2    M3    M4    M5    M6    M7    M8    M9    M10   M11
1719 static const EB_U8 EnableHmeLevel1FlagOq[5][MAX_SUPPORTED_MODES] = {
1720 	{   1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1 },      // INPUT_SIZE_576p_RANGE_OR_LOWER
1721 	{   1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1 },      // INPUT_SIZE_720P_RANGE
1722 	{   1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1 },      // INPUT_SIZE_1080i_RANGE
1723 	{   1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1 },      // INPUT_SIZE_1080p_RANGE
1724 	{   1,    1,    1,    1,    1,    1,    1,    1,    0,    0,    0,    0 }       // INPUT_SIZE_4K_RANGE
1725 };
1726 static const EB_U16 HmeLevel1SearchAreaInWidthArrayLeftOq[5][MAX_SUPPORTED_MODES] = {
1727 	{  16,   16,   16,   16,    8,    8,    8,    8,    8,    4,    4,    4 },
1728 	{  16,   16,   16,   16,    8,    8,    8,    4,    4,    4,    4,    4 },
1729 	{  16,   16,   16,   16,    8,    8,    8,    4,    4,    4,    4,    4 },
1730 	{  16,   16,   16,   16,    8,    8,    8,    4,    4,    4,    4,    4 },
1731 	{  16,   16,   16,   16,    4,    4,    4,    4,    0,    0,    0,    0 }
1732 };
1733 static const EB_U16 HmeLevel1SearchAreaInWidthArrayRightOq[5][MAX_SUPPORTED_MODES] = {
1734 	{  16,   16,   16,   16,    8,    8,    8,    8,    8,    4,    4,    4 },
1735 	{  16,   16,   16,   16,    8,    8,    8,    4,    4,    4,    4,    4 },
1736 	{  16,   16,   16,   16,    8,    8,    8,    4,    4,    4,    4,    4 },
1737 	{  16,   16,   16,   16,    8,    8,    8,    4,    4,    4,    4,    4 },
1738     {  16,   16,   16,   16,    4,    4,    4,    4,    0,    0,    0,    0 }
1739 };
1740 static const EB_U16 HmeLevel1SearchAreaInHeightArrayTopOq[5][MAX_SUPPORTED_MODES] = {
1741     {  16,   16,   16,   16,    8,    8,    8,    8,    8,    4,    2,    2 },
1742     {  16,   16,   16,   16,    8,    8,    8,    4,    4,    4,    4,    4 },
1743     {  16,   16,   16,   16,    8,    4,    4,    4,    4,    2,    2,    2 },
1744     {  16,   16,   16,   16,    8,    8,    8,    4,    4,    4,    4,    4 },
1745     {  16,   16,   16,   16,    4,    4,    4,    4,    0,    0,    0,    0 }
1746 };
1747 static const EB_U16 HmeLevel1SearchAreaInHeightArrayBottomOq[5][MAX_SUPPORTED_MODES] = {
1748     {  16,   16,   16,   16,    8,    8,    8,    8,    8,    4,    2,    2 },
1749     {  16,   16,   16,   16,    8,    8,    8,    4,    4,    4,    4,    4 },
1750     {  16,   16,   16,   16,    8,    4,    4,    4,    4,    2,    2,    2 },
1751     {  16,   16,   16,   16,    8,    8,    8,    4,    4,    4,    4,    4 },
1752     {  16,   16,   16,   16,    4,    4,    4,    4,    0,    0,    0,    0 }
1753 };
1754 // HME LEVEL 2
1755 //     M0    M1    M2    M3    M4    M5    M6    M7    M8    M9    M10   M11
1756 static const EB_U8 EnableHmeLevel2FlagOq[5][MAX_SUPPORTED_MODES] = {
1757 	{   1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    0,    0 },      // INPUT_SIZE_576p_RANGE_OR_LOWER
1758 	{   1,    1,    1,    1,    1,    1,    1,    1,    1,    0,    0,    0 },      // INPUT_SIZE_720P_RANGE
1759 	{   1,    1,    1,    1,    1,    1,    1,    1,    1,    0,    0,    0 },      // INPUT_SIZE_1080i_RANGE
1760 	{   1,    1,    1,    1,    1,    1,    1,    1,    1,    0,    0,    0 },      // INPUT_SIZE_1080p_RANGE
1761 	{   1,    1,    1,    1,    0,    0,    0,    0,    0,    0,    0,    0 }       // INPUT_SIZE_4K_RANGE
1762 };
1763 static const EB_U16 HmeLevel2SearchAreaInWidthArrayLeftOq[5][MAX_SUPPORTED_MODES] = {
1764 	{   8,    8,    8,    8,    4,    4,    4,    4,    4,    4,    0,    0 },
1765 	{   8,    8,    8,    8,    4,    4,    4,    4,    4,    0,    0,    0 },
1766 	{   8,    8,    8,    8,    4,    4,    4,    4,    4,    0,    0,    0 },
1767 	{   8,    8,    8,    8,    4,    4,    4,    4,    4,    0,    0,    0 },
1768 	{   8,    8,    8,    8,    0,    0,    0,    0,    0,    0,    0,    0 }
1769 };
1770 static const EB_U16 HmeLevel2SearchAreaInWidthArrayRightOq[5][MAX_SUPPORTED_MODES] = {
1771 	{   8,    8,    8,    8,    4,    4,    4,    4,    4,    4,    0,    0 },
1772 	{   8,    8,    8,    8,    4,    4,    4,    4,    4,    0,    0,    0 },
1773 	{   8,    8,    8,    8,    4,    4,    4,    4,    4,    0,    0,    0 },
1774 	{   8,    8,    8,    8,    4,    4,    4,    4,    4,    0,    0,    0 },
1775 	{   8,    8,    8,    8,    0,    0,    0,    0,    0,    0,    0,    0 }
1776 };
1777 static const EB_U16 HmeLevel2SearchAreaInHeightArrayTopOq[5][MAX_SUPPORTED_MODES] = {
1778 	{   8,    8,    8,    8,    4,    4,    4,    4,    4,    2,    0,    0 },
1779 	{   8,    8,    8,    8,    4,    4,    4,    2,    2,    0,    0,    0 },
1780 	{   8,    8,    8,    8,    4,    2,    2,    2,    2,    0,    0,    0 },
1781 	{   8,    8,    8,    8,    4,    4,    4,    2,    2,    0,    0,    0 },
1782 	{   8,    8,    8,    8,    0,    0,    0,    0,    0,    0,    0,    0 }
1783 };
1784 static const EB_U16 HmeLevel2SearchAreaInHeightArrayBottomOq[5][MAX_SUPPORTED_MODES] = {
1785 	{   8,    8,    8,    8,    4,    4,    4,    4,    4,    2,    0,    0 },
1786 	{   8,    8,    8,    8,    4,    4,    4,    2,    2,    0,    0,    0 },
1787 	{   8,    8,    8,    8,    4,    2,    2,    2,    2,    0,    0,    0 },
1788 	{   8,    8,    8,    8,    4,    4,    4,    2,    2,    0,    0,    0 },
1789 	{   8,    8,    8,    8,    0,    0,    0,    0,    0,    0,    0,    0 }
1790 };
1791 
1792 static const EB_U8 SearchAreaWidthOq[5][MAX_SUPPORTED_MODES] = {
1793 	{  64,   64,   64,   64,   16,   16,   16,   16,   16,   16,    8,    8 },
1794 	{  64,   64,   64,   64,   16,   16,   16,   16,   16,    8,    8,    8 },
1795 	{  64,   64,   64,   64,   16,   16,   16,   16,   16,    8,    8,    8 },
1796 	{  64,   64,   64,   64,   16,   16,   16,   16,   16,    8,    8,    8 },
1797 	{  64,   64,   64,   64,   16,   16,   16,   16,    8,    8,    8,    8 }
1798 };
1799 
1800 static const EB_U8 SearchAreaHeightOq[5][MAX_SUPPORTED_MODES] = {
1801 	{  64,   64,   64,   64,   16,    9,    9,    9,    9,    7,    7,    7 },
1802 	{  64,   64,   64,   64,   16,   13,   13,    9,    9,    7,    7,    7 },
1803 	{  64,   64,   64,   64,   16,    9,    9,    7,    7,    7,    7,    7 },
1804 	{  64,   64,   64,   64,   16,   13,   13,    9,    9,    7,    7,    7 },
1805 	{  64,   64,   64,   64,    9,    9,    9,    9,    7,    7,    7,    5 }
1806 };
1807 
1808 #define MAX_SUPPORTED_SEGMENTS       7
1809 
1810 #ifdef __cplusplus
1811 }
1812 #endif
1813 #endif // EbDefinitions_h
1814 /* File EOF */
1815