• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define HI_OSD_MAX_CNT  (16) // Maximum OSD Count
30 #define HI_OSD_MAX_DISP_CNT (2) // Maximum Display Count for Each OSD
31 #define HI_OSD_MAX_STR_LEN  (64) // String OSD Maximum Length
32 
33 typedef HI_S32 HI_ERRNO;
34 
35 /*
36  * 常见的错误码
37  * Common error code
38  */
39 #define HI_ERRNO_COMMON_BASE  0
40 #define HI_ERRNO_COMMON_COUNT 256
41 
42 #define HI_EUNKNOWN            (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 1)
43 #define HI_EOTHER              (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 2)
44 #define HI_EINTER              (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 3)
45 #define HI_EVERSION            (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 4)
46 #define HI_EPAERM              (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 5)
47 #define HI_EINVAL              (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 6)
48 #define HI_ENOINIT             (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 7)
49 #define HI_ENOTREADY           (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 8)
50 #define HI_ENORES              (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 9)
51 #define HI_EEXIST              (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 10)
52 #define HI_ELOST               (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 11)
53 #define HI_ENOOP               (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 12)
54 #define HI_EBUSY               (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 13)
55 #define HI_EIDLE               (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 14)
56 #define HI_EFULL               (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 15)
57 #define HI_EEMPTY              (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 16)
58 #define HI_EUNDERFLOW          (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 17)
59 #define HI_EOVERFLOW           (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 18)
60 #define HI_EACCES              (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 19)
61 #define HI_EINTR               (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 20)
62 #define HI_ECONTINUE           (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 21)
63 #define HI_EOVER               (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 22)
64 #define HI_ERRNO_COMMON_BOTTOM (HI_ERRNO)(HI_ERRNO_COMMON_BASE + 23)
65 
66 /*
67  * 自定义错误码
68  * Custom error code
69  */
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 /*
75  * pthread互斥锁
76  * pthread mutex lock
77  */
MutexLock(pthread_mutex_t * mutex)78 static inline void MutexLock(pthread_mutex_t* mutex)
79 {
80     if (pthread_mutex_lock(mutex) != 0) {
81         HI_ASSERT(0);
82     }
83 }
84 
85 /*
86  * 解除锁定mutex所指向的互斥锁
87  * pthread mutex unlock
88  */
MutexUnlock(pthread_mutex_t * mutex)89 static inline void MutexUnlock(pthread_mutex_t* mutex)
90 {
91     if (pthread_mutex_unlock(mutex) != 0) {
92         HI_ASSERT(0);
93     }
94 }
95 
96 typedef HI_S32 (*HI_OSD_GETFONTMOD_CALLBACK_FN_PTR)(HI_CHAR* Character, HI_U8** FontMod, HI_S32* FontModLen);
97 
98 /*
99  * OSD字体库
100  * OSD Fonts Lib
101  */
102 typedef struct hiOSD_FONTS_S {
103     /* OSD Lib Font Size, in pixel */
104     HI_U32 u32FontWidth;
105     HI_U32 u32FontHeight;
106     HI_OSD_GETFONTMOD_CALLBACK_FN_PTR pfnGetFontMod;
107 } HI_OSD_FONTS_S;
108 
109 /*
110  * OSD像素格式枚举
111  * OSD pixel format enum
112  */
113 typedef enum hiOSD_PIXEL_FMT_E {
114     HI_OSD_PIXEL_FMT_RGB1555 = 0,
115     HI_OSD_PIXEL_FMT_BUTT
116 } HI_OSD_PIXEL_FMT_E;
117 
118 /*
119  * OSD位图属性
120  * OSD Bitmap Attribute
121  */
122 typedef struct hiOSD_BITMAP_ATTR_S {
123     HI_OSD_PIXEL_FMT_E enPixelFormat;
124     HI_U32             u32Width;
125     HI_U32             u32Height;
126     HI_U64             u64PhyAddr;
127     HI_VOID*           pvData;
128 } HI_OSD_BITMAP_ATTR_S;
129 
130 /*
131  * OSD类型枚举
132  * OSD Type Enum
133  */
134 typedef enum hiOSD_TYPE_E {
135     HI_OSD_TYPE_TIME = 0,
136     HI_OSD_TYPE_STRING,
137     HI_OSD_TYPE_BITMAP,
138     HI_OSD_TYPE_BUTT
139 } HI_OSD_TYPE_E;
140 
141 /*
142  * OSD时间格式枚举
143  * OSD Time Format Enum
144  */
145 typedef enum hiOSD_TIMEFMT_E {
146     HI_OSD_TIMEFMT_YMD24H = 0, // eg. 2017-03-10 23:00:59
147     HI_OSD_TIMEFMT_BUTT
148 } HI_OSD_TIMEFMT_E;
149 
150 /*
151  * OSD绑定模块枚举
152  * OSD Binded Module enum
153  */
154 typedef enum hiOSD_BIND_MOD_E {
155     HI_OSD_BINDMOD_VI = 0,
156     HI_OSD_BINDMOD_VPSS,
157     HI_OSD_BINDMOD_AVS,
158     HI_OSD_BINDMOD_VENC,
159     HI_OSD_BINDMOD_VO,
160     HI_OSD_BINDMOD_BUTT
161 } HI_OSD_BIND_MOD_E;
162 
163 typedef enum hiOSD_COORDINATE_E {
164     HI_OSD_COORDINATE_RATIO_COOR = 0,
165     HI_OSD_COORDINATE_ABS_COOR
166 } HI_OSD_COORDINATE_E;
167 
168 /*
169  * OSD显示属性
170  * OSD Display Attribute
171  */
172 typedef struct hiOSD_DISP_ATTR_S {
173     HI_BOOL bShow;
174     HI_OSD_BIND_MOD_E enBindedMod;
175     HI_HANDLE ModHdl;
176     HI_HANDLE ChnHdl;
177     HI_U32  u32FgAlpha;
178     HI_U32  u32BgAlpha;
179     HI_OSD_COORDINATE_E enCoordinate; // Coordinate mode of the osd start Position
180     POINT_S stStartPos; // OSD Start Position
181     ATTACH_DEST_E enAttachDest; // only for venc
182     HI_S32 s32Batch;
183 } HI_OSD_DISP_ATTR_S;
184 
185 /*
186  * OSD内容
187  * OSD Content
188  */
189 typedef struct hiOSD_CONTENT_S {
190     HI_OSD_TYPE_E enType;
191     HI_OSD_TIMEFMT_E enTimeFmt;
192     HI_U32  u32Color; // string color
193     HI_U32  u32BgColor;
194     HI_CHAR szStr[HI_OSD_MAX_STR_LEN];
195     SIZE_S  stFontSize;
196     HI_OSD_BITMAP_ATTR_S stBitmap; // Pixel Format: Only Support RGB1555 for now
197 } HI_OSD_CONTENT_S;
198 
199 /*
200  * OSD属性
201  * OSD attribution
202  */
203 typedef struct hiOSD_ATTR_S {
204     HI_U32 u32DispNum; /* 1Binded Display Number for this OSD */
205     HI_OSD_DISP_ATTR_S astDispAttr[HI_OSD_MAX_DISP_CNT];
206     HI_OSD_CONTENT_S stContent;
207 } HI_OSD_ATTR_S;
208 
209 /*
210  * OSD参数
211  * OSD Parameter
212  */
213 typedef struct tagOSD_PARAM_S {
214     HI_OSD_ATTR_S stAttr;
215     SIZE_S stMaxSize;
216     pthread_mutex_t  mutexLock;
217     HI_BOOL bInit; /* OSD Attribute Set or not, Canbe modified only HI_OSD_SetAttr */
218     HI_BOOL bOn; /* OSD On/Off Flag, Canbe modified only by HI_OSD_Start/HI_OSD_Stop */
219 } OSD_PARAM_S;
220 
221 typedef struct hiOSD_TEXTBITMAP_S {
222     RGN_HANDLE rgnHdl;
223     HI_OSD_CONTENT_S pstContent;
224     RGN_CANVAS_INFO_S stCanvasInfo;
225 } HI_OSD_TEXTBITMAP_S;
226 
227 /*
228  * OSD区域设置
229  * OSD region set
230  */
231 struct OsdSet {
232     // OSD Binded Module: Static
233     HI_OSD_BIND_MOD_E bindMod;
234     // Binded Module Handle: Static eg.VcapPipeHdl, VpssHdl, StitchHdl, DispHdl, 0
235     HI_U32 modHnd;
236     // Binded Channel Handle: Static eg.PipeChnHdl, VPortHdl, StitchPortHdl, WndHdl, VencHdl
237     HI_U32 chnHnd;
238 };
239 
240 typedef struct OsdSet OsdSet;
241 
242 /*
243  * 在OsdSet中创建区域
244  * Create a region in OsdSet
245  */
246 int OsdsCreateRgn(OsdSet* self);
247 
248 /*
249  * 设置文本区域的属性值
250  * Set the attribute value of the text region
251  */
252 int TxtRgnInit(HI_OSD_ATTR_S* rgnAttr, const char* str, uint32_t begX, uint32_t begY, uint32_t color);
253 
254 /*
255  * 销毁OsdSet中的所有区域
256  * Destroy all regions in OsdSet
257  */
258 void OsdsClear(OsdSet* self);
259 
260 /*
261  * 在OsdSet中设置指定区域的属性
262  * Set attributes for the specified region in OsdSet
263  */
264 int OsdsSetRgn(OsdSet* self, int rgnHnd, const HI_OSD_ATTR_S* rgnAttr);
265 
266 /*
267  * 创建OsdSet
268  * Creat OsdSet
269  */
270 OsdSet* OsdsCreate(HI_OSD_BIND_MOD_E bindMod, HI_U32 modHnd, HI_U32 chnHnd);
271 
272 /*
273  * 销毁OsdSet
274  * Destory OsdSet
275  */
276 void OsdsDestroy(OsdSet* self);
277 
278 /*
279  * 初始化OsdSet库
280  * Initialize OsdSet lib
281  */
282 int OsdLibInit(void);
283 
284 #ifdef __cplusplus
285 }
286 #endif
287 #endif