xref: /OK3568_Linux_fs/external/rockit/tgi/sdk/include/rt_common.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright 2018 Rockchip Electronics Co. LTD
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * author: martin.cheng@rock-chips.com
17  *   date: 20180704
18  */
19 
20 #ifndef INCLUDE_RT_BASE_RT_COMMON_H_
21 #define INCLUDE_RT_BASE_RT_COMMON_H_
22 
23 #define RT_TAG_SIZE            32
24 
25 #define RT_ABS(x)              ((x) < (0) ? -(x) : (x))
26 
27 #define RT_MAX(a, b)           ((a) > (b) ? (a) : (b))
28 #define RT_MAX3(a, b, c)       RT_MAX(RT_MAX(a, b) , c)
29 #define RT_MAX4(a, b, c, d)    RT_MAX((a), RT_MAX3((b), (c), (d)))
30 
31 #define RT_CLIP(a, l, h)       ((a) < (l) ? (l) : ((a) > (h) ? (h) : (a)))
32 
33 #define RT_MIN(a, b)            ((a) > (b) ? (b) : (a))
34 #define RT_MIN3(a, b, c)       RT_MIN(MPP_MIN(a, b), c)
35 #define RT_MIN4(a, b, c, d)    RT_MIN((a), RT_MIN3((b), (c), (d)))
36 
37 #define RT_SWAP(type, a, b) \
38     do { \
39         type SWAP_tmp = b; \
40         b = a; \
41         a = SWAP_tmp; \
42     } while (0)
43 
44 #define RT_ARRAY_ELEMS(a)      (sizeof(a) / sizeof((a)[0]))
45 #define RT_ALIGN(x, a)         (((x) + (a) - 1) & ~((a) - 1))
46 #define RT_ALIGN_ODD(x, a)     (RT_ALIGN(x, a) | a)
47 #define RT_ALIGN_16(x)         RT_ALIGN(x, 16)
48 #define RT_ALIGN_64(x)         RT_ALIGN(x, 64)
49 #define RT_ALIGN_256(x)        RT_ALIGN(x, 256)
50 #define RT_ALIGN_256_ODD(x)    (RT_ALIGN(x, 256) | 256)
51 
52 #define RT_VSWAP(a, b)         { a ^= b; b ^= a; a ^= b; }
53 
54 #define RT_MERGE_INT64(a, b)   (((INT64)a << 32) + b)
55 
56 #ifndef RT_INT64_MIN
57 #define RT_INT64_MIN       (-0x7fffffffffffffffLL-1)
58 #define RT_NOPTS_VALUE     (-0x7fffffffffffffffLL-1)
59 #endif
60 
61 #ifndef RT_INT64_MAX
62 #define RT_INT64_MAX        INT64_C(9223372036854775807)
63 #endif
64 
65 #ifndef RT_INT32_MAX
66 #define RT_INT32_MAX        (2147483647)
67 #endif
68 
69 #ifndef RT_SEEK_SIZE
70 #define RT_SEEK_SIZE        0x10000
71 #endif
72 
73 #ifndef RT_ERROR_EOF
74 #define RT_ERROR_EOF        (-(int)MKTAG('E','O','F',' ')) // NOLINT  End of file
75 #endif
76 
77 #ifndef RT_ERROR
78 #define RT_ERROR(e)         (-(e))   // NOLINT
79 #endif
80 
81 #define RT_PTS_IS_VALID(pts)    (pts != RT_NOPTS_VALUE)
82 
83 #define RT_FOURCC(f)                                                 \
84     f & 0xFF, (f >> 8) & 0xFF, (f >> 16) & 0xFF, (f >> 24) & 0xFF
85 
86 #endif  // INCLUDE_RT_BASE_RT_COMMON_H_
87