1 /*
2 * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef OSD_IMG_H
17 #define OSD_IMG_H
18
19 #include <stdbool.h>
20 #include <stdint.h>
21 #include <pthread.h>
22 #include "hi_comm_region.h"
23 #include "hi_common.h"
24
25 #if __cplusplus
26 extern "C" {
27 #endif
28
29 /* Maximum OSD Count */
30 #define HI_OSD_MAX_CNT (16)
31
32 /* Maximum Display Count for Each OSD */
33 #define HI_OSD_MAX_DISP_CNT (2)
34
35 /* String OSD Maximum Length */
36 #define HI_OSD_MAX_STR_LEN (64)
37
38 /* typedef */
39 typedef HI_S32 HI_ERRNO;
40
41 /* common error code */
42 #define HI_ERRNO_COMMON_BASE 0
43 #define HI_ERRNO_COMMON_COUNT 256
44
45 #define HI_EUNKNOWN (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 1)
46 #define HI_EOTHER (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 2)
47 #define HI_EINTER (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 3)
48 #define HI_EVERSION (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 4)
49 #define HI_EPAERM (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 5)
50 #define HI_EINVAL (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 6)
51 #define HI_ENOINIT (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 7)
52 #define HI_ENOTREADY (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 8)
53 #define HI_ENORES (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 9)
54 #define HI_EEXIST (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 10)
55 #define HI_ELOST (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 11)
56 #define HI_ENOOP (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 12)
57 #define HI_EBUSY (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 13)
58 #define HI_EIDLE (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 14)
59 #define HI_EFULL (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 15)
60 #define HI_EEMPTY (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 16)
61 #define HI_EUNDERFLOW (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 17)
62 #define HI_EOVERFLOW (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 18)
63 #define HI_EACCES (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 19)
64 #define HI_EINTR (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 20)
65 #define HI_ECONTINUE (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 21)
66 #define HI_EOVER (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 22)
67 #define HI_ERRNO_COMMON_BOTTOM (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 23)
68
69 /* custom error code */
70 #define HI_ERRNO_BASE (HI_ERRNO)(HI_ERRNO_COMMON_BASE + HI_ERRNO_COMMON_COUNT)
71 #define HI_EINITIALIZED (HI_ERRNO)(HI_ERRNO_BASE + 1) // Repeated initialization
72 #define HI_ERRNO_CUSTOM_BOTTOM (HI_ERRNO)(HI_ERRNO_BASE + 2) // Number of error numbers that have been defined
73
74 /* pthread mutex lock */
MutexLock(pthread_mutex_t * mutex)75 static inline void MutexLock(pthread_mutex_t* mutex)
76 {
77 if (pthread_mutex_lock(mutex) != 0) {
78 HI_ASSERT(0);
79 }
80 }
81
82 /* pthread mutex lock */
MutexUnlock(pthread_mutex_t * mutex)83 static inline void MutexUnlock(pthread_mutex_t* mutex)
84 {
85 if (pthread_mutex_unlock(mutex) != 0) {
86 HI_ASSERT(0);
87 }
88 }
89
90 typedef HI_S32 (*HI_OSD_GETFONTMOD_CALLBACK_FN_PTR)(HI_CHAR* Character, HI_U8** FontMod, HI_S32* FontModLen);
91
92 /* OSD Fonts Lib */
93 typedef struct hiOSD_FONTS_S {
94 /* OSD Lib Font Size, in pixel */
95 HI_U32 u32FontWidth;
96 HI_U32 u32FontHeight;
97 HI_OSD_GETFONTMOD_CALLBACK_FN_PTR pfnGetFontMod;
98 } HI_OSD_FONTS_S;
99
100 /* osd pixel format enum */
101 typedef enum hiOSD_PIXEL_FMT_E {
102 HI_OSD_PIXEL_FMT_RGB1555 = 0,
103 HI_OSD_PIXEL_FMT_BUTT
104 } HI_OSD_PIXEL_FMT_E;
105
106 /* OSD Bitmap Attribute */
107 typedef struct hiOSD_BITMAP_ATTR_S {
108 HI_OSD_PIXEL_FMT_E enPixelFormat;
109 HI_U32 u32Width;
110 HI_U32 u32Height;
111 HI_U64 u64PhyAddr;
112 HI_VOID* pvData;
113 } HI_OSD_BITMAP_ATTR_S;
114
115 /* OSD Type Enum */
116 typedef enum hiOSD_TYPE_E {
117 HI_OSD_TYPE_TIME = 0,
118 HI_OSD_TYPE_STRING,
119 HI_OSD_TYPE_BITMAP,
120 HI_OSD_TYPE_BUTT
121 } HI_OSD_TYPE_E;
122
123 /* OSD Time Format Enum */
124 typedef enum hiOSD_TIMEFMT_E {
125 HI_OSD_TIMEFMT_YMD24H = 0, // eg. 2017-03-10 23:00:59
126 HI_OSD_TIMEFMT_BUTT
127 } HI_OSD_TIMEFMT_E;
128
129 /* OSD Binded Module enum */
130 typedef enum hiOSD_BIND_MOD_E {
131 HI_OSD_BINDMOD_VI = 0,
132 HI_OSD_BINDMOD_VPSS,
133 HI_OSD_BINDMOD_AVS,
134 HI_OSD_BINDMOD_VENC,
135 HI_OSD_BINDMOD_VO,
136 HI_OSD_BINDMOD_BUTT
137 } HI_OSD_BIND_MOD_E;
138
139 typedef enum hiOSD_COORDINATE_E {
140 HI_OSD_COORDINATE_RATIO_COOR = 0,
141 HI_OSD_COORDINATE_ABS_COOR
142 } HI_OSD_COORDINATE_E;
143
144 /** OSD Display Attribute */
145 typedef struct hiOSD_DISP_ATTR_S {
146 HI_BOOL bShow;
147 HI_OSD_BIND_MOD_E enBindedMod;
148 HI_HANDLE ModHdl;
149 HI_HANDLE ChnHdl;
150 HI_U32 u32FgAlpha;
151 HI_U32 u32BgAlpha;
152 HI_OSD_COORDINATE_E enCoordinate; // Coordinate mode of the osd start Position
153 POINT_S stStartPos; // OSD Start Position
154 ATTACH_DEST_E enAttachDest; // only for venc
155 HI_S32 s32Batch;
156 } HI_OSD_DISP_ATTR_S;
157
158 /* OSD Content */
159 typedef struct hiOSD_CONTENT_S {
160 HI_OSD_TYPE_E enType;
161 HI_OSD_TIMEFMT_E enTimeFmt;
162 HI_U32 u32Color; // string color
163 HI_U32 u32BgColor;
164 HI_CHAR szStr[HI_OSD_MAX_STR_LEN];
165 SIZE_S stFontSize;
166 HI_OSD_BITMAP_ATTR_S stBitmap; // Pixel Format: Only Support RGB1555 for now
167 } HI_OSD_CONTENT_S;
168
169 /* OSD Parameter */
170 typedef struct hiOSD_ATTR_S {
171 HI_U32 u32DispNum; /* 1Binded Display Number for this OSD */
172 HI_OSD_DISP_ATTR_S astDispAttr[HI_OSD_MAX_DISP_CNT];
173 HI_OSD_CONTENT_S stContent;
174 } HI_OSD_ATTR_S;
175
176 /* OSD Parameter */
177 typedef struct tagOSD_PARAM_S {
178 HI_OSD_ATTR_S stAttr;
179 SIZE_S stMaxSize;
180 pthread_mutex_t mutexLock;
181 HI_BOOL bInit; /* OSD Attribute Set or not, Canbe modified only HI_OSD_SetAttr */
182 HI_BOOL bOn; /* OSD On/Off Flag, Canbe modified only by HI_OSD_Start/HI_OSD_Stop */
183 } OSD_PARAM_S;
184
185 typedef struct hiOSD_TEXTBITMAP_S {
186 RGN_HANDLE rgnHdl;
187 HI_OSD_CONTENT_S pstContent;
188 RGN_CANVAS_INFO_S stCanvasInfo;
189 } HI_OSD_TEXTBITMAP_S;
190
191 /* OSD region set */
192 struct OsdSet {
193 // OSD Binded Module: Static
194 HI_OSD_BIND_MOD_E bindMod;
195 // Binded Module Handle: Static eg.VcapPipeHdl, VpssHdl, StitchHdl, DispHdl, 0
196 HI_U32 modHnd;
197 // Binded Channel Handle: Static eg.PipeChnHdl, VPortHdl, StitchPortHdl, WndHdl, VencHdl
198 HI_U32 chnHnd;
199 };
200
201 typedef struct OsdSet OsdSet;
202
203 /* Create a region in OsdSet */
204 int OsdsCreateRgn(OsdSet* self);
205
206 /* Set the attribute value of the text region */
207 int TxtRgnInit(HI_OSD_ATTR_S* rgnAttr, const char* str, uint32_t begX, uint32_t begY, uint32_t color);
208
209 /* Destroy all regions in OsdSet */
210 void OsdsClear(OsdSet* self);
211
212 /* Set attributes for the specified region in OsdSet */
213 int OsdsSetRgn(OsdSet* self, int rgnHnd, const HI_OSD_ATTR_S* rgnAttr);
214
215 /* Creat OsdSet */
216 OsdSet* OsdsCreate(HI_OSD_BIND_MOD_E bindMod, HI_U32 modHnd, HI_U32 chnHnd);
217
218 /* Destory OsdSet */
219 void OsdsDestroy(OsdSet* self);
220
221 /* Initialize OsdSet lib */
222 int OsdLibInit(void);
223
224 #ifdef __cplusplus
225 }
226 #endif
227 #endif