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 #ifndef __HI_COMM_REGION_H__ 16 #define __HI_COMM_REGION_H__ 17 18 #include "hi_common.h" 19 #include "hi_comm_video.h" 20 #include "hi_errno.h" 21 #include "hi_defines.h" 22 23 #ifdef __cplusplus 24 #if __cplusplus 25 extern "C" { 26 #endif 27 #endif 28 29 #define RGN_COLOR_LUT_NUM 2 30 #define RGN_MAX_BMP_UPDATE_NUM 16 31 #define RGN_BATCHHANDLE_MAX 24 32 33 typedef HI_U32 RGN_HANDLE; 34 typedef HI_U32 RGN_HANDLEGROUP; 35 36 /* type of video regions */ 37 typedef enum hiRGN_TYPE_E { 38 OVERLAY_RGN = 0, /* video overlay region */ 39 COVER_RGN, 40 COVEREX_RGN, 41 OVERLAYEX_RGN, 42 MOSAIC_RGN, 43 RGN_BUTT 44 } RGN_TYPE_E; 45 46 typedef enum hiINVERT_COLOR_MODE_E { 47 LESSTHAN_LUM_THRESH = 0, /* the lum of the video is less than the lum threshold which is set by u32LumThresh */ 48 MORETHAN_LUM_THRESH, /* the lum of the video is more than the lum threshold which is set by u32LumThresh */ 49 INVERT_COLOR_BUTT 50 } INVERT_COLOR_MODE_E; 51 52 typedef struct hiOVERLAY_QP_INFO_S { 53 HI_BOOL bAbsQp; 54 HI_S32 s32Qp; 55 HI_BOOL bQpDisable; 56 } OVERLAY_QP_INFO_S; 57 58 typedef struct hiOVERLAY_INVERT_COLOR_S { 59 SIZE_S stInvColArea; /* It must be multipe of 16 but not more than 64. */ 60 HI_U32 u32LumThresh; /* The threshold to decide whether invert the OSD's color or not. */ 61 INVERT_COLOR_MODE_E enChgMod; 62 HI_BOOL bInvColEn; /* The switch of inverting color. */ 63 } OVERLAY_INVERT_COLOR_S; 64 65 typedef enum hiATTACH_DEST_E { 66 ATTACH_JPEG_MAIN = 0, 67 ATTACH_JPEG_MPF0, 68 ATTACH_JPEG_MPF1, 69 ATTACH_JPEG_BUTT 70 } ATTACH_DEST_E; 71 72 typedef struct hiOVERLAY_ATTR_S { 73 /* bitmap pixel format,now only support ARGB1555 or ARGB4444 */ 74 PIXEL_FORMAT_E enPixelFmt; 75 76 /* background color, pixel format depends on "enPixelFmt" */ 77 HI_U32 u32BgColor; 78 79 /* region size,W:[2,RGN_OVERLAY_MAX_WIDTH],align:2,H:[2,RGN_OVERLAY_MAX_HEIGHT],align:2 */ 80 SIZE_S stSize; 81 HI_U32 u32CanvasNum; 82 } OVERLAY_ATTR_S; 83 84 typedef struct hiOVERLAY_CHN_ATTR_S { 85 /* X:[0,OVERLAY_MAX_X_VENC],align:2,Y:[0,OVERLAY_MAX_Y_VENC],align:2 */ 86 POINT_S stPoint; 87 88 /* 89 * background an foreground transparence when pixel format is ARGB1555 90 * the pixel format is ARGB1555,when the alpha bit is 1 this alpha is value! 91 * range:[0,128] 92 */ 93 HI_U32 u32FgAlpha; 94 95 /* 96 * background an foreground transparence when pixel format is ARGB1555 97 * the pixel format is ARGB1555,when the alpha bit is 0 this alpha is value! 98 * range:[0,128] 99 */ 100 HI_U32 u32BgAlpha; 101 102 HI_U32 u32Layer; /* OVERLAY region layer range:[0,7] */ 103 104 OVERLAY_QP_INFO_S stQpInfo; 105 106 OVERLAY_INVERT_COLOR_S stInvertColor; 107 108 ATTACH_DEST_E enAttachDest; 109 110 HI_U16 u16ColorLUT[RGN_COLOR_LUT_NUM]; 111 } OVERLAY_CHN_ATTR_S; 112 113 typedef enum hiRGN_AREA_TYPE_E { 114 AREA_RECT = 0, 115 AREA_QUAD_RANGLE, 116 AREA_BUTT 117 } RGN_AREA_TYPE_E; 118 119 typedef enum hiRGN_COORDINATE_E { 120 RGN_ABS_COOR = 0, /* Absolute coordinate */ 121 RGN_RATIO_COOR /* Ratio coordinate */ 122 } RGN_COORDINATE_E; 123 124 typedef struct hiRGN_QUADRANGLE_S { 125 HI_BOOL bSolid; /* whether solid or dashed quadrangle */ 126 HI_U32 u32Thick; /* Line Width of quadrangle, valid when dashed quadrangle */ 127 POINT_S stPoint[4]; /* quadrangle has 4 points */ 128 } RGN_QUADRANGLE_S; 129 130 typedef struct hiCOVER_CHN_ATTR_S { 131 RGN_AREA_TYPE_E enCoverType; /* rect or arbitary quadrilateral COVER */ 132 union { 133 RECT_S stRect; /* config of rect */ 134 RGN_QUADRANGLE_S stQuadRangle; /* config of arbitary quadrilateral COVER */ 135 }; 136 HI_U32 u32Color; 137 HI_U32 u32Layer; /* COVER region layer */ 138 RGN_COORDINATE_E enCoordinate; /* ratio coordiante or abs coordinate */ 139 } COVER_CHN_ATTR_S; 140 141 typedef struct hiCOVEREX_CHN_ATTR_S { 142 RGN_AREA_TYPE_E enCoverType; /* rect or arbitary quadrilateral COVER */ 143 union { 144 RECT_S stRect; /* config of rect */ 145 RGN_QUADRANGLE_S stQuadRangle; /* config of arbitary quadrilateral COVER */ 146 }; 147 HI_U32 u32Color; 148 HI_U32 u32Layer; /* COVEREX region layer range */ 149 } COVEREX_CHN_ATTR_S; 150 151 typedef enum hiMOSAIC_BLK_SIZE_E { 152 MOSAIC_BLK_SIZE_8 = 0, /* block size 8*8 of MOSAIC */ 153 MOSAIC_BLK_SIZE_16, /* block size 16*16 of MOSAIC */ 154 MOSAIC_BLK_SIZE_32, /* block size 32*32 of MOSAIC */ 155 MOSAIC_BLK_SIZE_64, /* block size 64*64 of MOSAIC */ 156 MOSAIC_BLK_SIZE_BUTT 157 } MOSAIC_BLK_SIZE_E; 158 159 typedef struct hiMOSAIC_CHN_ATTR_S { 160 RECT_S stRect; /* location of MOSAIC */ 161 MOSAIC_BLK_SIZE_E enBlkSize; /* block size of MOSAIC */ 162 HI_U32 u32Layer; /* MOSAIC region layer range:[0,3] */ 163 } MOSAIC_CHN_ATTR_S; 164 165 typedef struct hiOVERLAYEX_COMM_ATTR_S { 166 PIXEL_FORMAT_E enPixelFmt; 167 168 /* background color, pixel format depends on "enPixelFmt" */ 169 HI_U32 u32BgColor; 170 171 /* region size,W:[2,RGN_OVERLAY_MAX_WIDTH],align:2,H:[2,RGN_OVERLAY_MAX_HEIGHT],align:2 */ 172 SIZE_S stSize; 173 HI_U32 u32CanvasNum; 174 } OVERLAYEX_ATTR_S; 175 176 typedef struct hiOVERLAYEX_CHN_ATTR_S { 177 /* X:[0,RGN_OVERLAY_MAX_X],align:2,Y:[0,RGN_OVERLAY_MAX_Y],align:2 */ 178 POINT_S stPoint; 179 180 /* 181 * background an foreground transparence when pixel format is ARGB1555 182 * the pixel format is ARGB1555,when the alpha bit is 1 this alpha is value! 183 * range:[0,255] 184 */ 185 HI_U32 u32FgAlpha; 186 187 /* 188 * background an foreground transparence when pixel format is ARGB1555 189 * the pixel format is ARGB1555,when the alpha bit is 0 this alpha is value! 190 * range:[0,255] 191 */ 192 HI_U32 u32BgAlpha; 193 194 HI_U32 u32Layer; /* OVERLAYEX region layer range:[0,15] */ 195 196 HI_U16 u16ColorLUT[RGN_COLOR_LUT_NUM]; 197 } OVERLAYEX_CHN_ATTR_S; 198 199 typedef union hiRGN_ATTR_U { 200 OVERLAY_ATTR_S stOverlay; /* attribute of overlay region */ 201 OVERLAYEX_ATTR_S stOverlayEx; /* attribute of overlayex region */ 202 } RGN_ATTR_U; 203 204 typedef union hiRGN_CHN_ATTR_U { 205 OVERLAY_CHN_ATTR_S stOverlayChn; /* attribute of overlay region */ 206 COVER_CHN_ATTR_S stCoverChn; /* attribute of cover region */ 207 COVEREX_CHN_ATTR_S stCoverExChn; /* attribute of coverex region */ 208 OVERLAYEX_CHN_ATTR_S stOverlayExChn; /* attribute of overlayex region */ 209 MOSAIC_CHN_ATTR_S stMosaicChn; /* attribute of mosic region */ 210 } RGN_CHN_ATTR_U; 211 212 /* attribute of a region */ 213 typedef struct hiRGN_ATTR_S { 214 RGN_TYPE_E enType; /* region type */ 215 RGN_ATTR_U unAttr; /* region attribute */ 216 } RGN_ATTR_S; 217 218 /* attribute of a region */ 219 typedef struct hiRGN_CHN_ATTR_S { 220 HI_BOOL bShow; 221 RGN_TYPE_E enType; /* region type */ 222 RGN_CHN_ATTR_U unChnAttr; /* region attribute */ 223 } RGN_CHN_ATTR_S; 224 225 typedef struct hiRGN_BMP_UPDATE_S { 226 POINT_S stPoint; 227 BITMAP_S stBmp; 228 HI_U32 u32Stride; 229 } RGN_BMP_UPDATE_S; 230 231 typedef struct hiRGN_BMP_UPDATE_CFG_S { 232 HI_U32 u32BmpCnt; 233 RGN_BMP_UPDATE_S astBmpUpdate[RGN_MAX_BMP_UPDATE_NUM]; 234 } RGN_BMP_UPDATE_CFG_S; 235 236 typedef struct hiRGN_CANVAS_INFO_S { 237 HI_U64 u64PhyAddr; 238 HI_U64 u64VirtAddr; 239 SIZE_S stSize; 240 HI_U32 u32Stride; 241 PIXEL_FORMAT_E enPixelFmt; 242 } RGN_CANVAS_INFO_S; 243 244 /* PingPong buffer change when set attr, it needs to remap memory in mpi interface */ 245 #define HI_NOTICE_RGN_BUFFER_CHANGE HI_DEF_ERR(HI_ID_RGN, EN_ERR_LEVEL_NOTICE, HI_SUCCESS) 246 247 /* invlalid device ID */ 248 #define HI_ERR_RGN_INVALID_DEVID HI_DEF_ERR(HI_ID_RGN, EN_ERR_LEVEL_ERROR, EN_ERR_INVALID_DEVID) 249 /* invlalid channel ID */ 250 #define HI_ERR_RGN_INVALID_CHNID HI_DEF_ERR(HI_ID_RGN, EN_ERR_LEVEL_ERROR, EN_ERR_INVALID_CHNID) 251 /* at lease one parameter is illagal ,eg, an illegal enumeration value */ 252 #define HI_ERR_RGN_ILLEGAL_PARAM HI_DEF_ERR(HI_ID_RGN, EN_ERR_LEVEL_ERROR, EN_ERR_ILLEGAL_PARAM) 253 /* channel exists */ 254 #define HI_ERR_RGN_EXIST HI_DEF_ERR(HI_ID_RGN, EN_ERR_LEVEL_ERROR, EN_ERR_EXIST) 255 /* UN exist */ 256 #define HI_ERR_RGN_UNEXIST HI_DEF_ERR(HI_ID_RGN, EN_ERR_LEVEL_ERROR, EN_ERR_UNEXIST) 257 /* using a NULL point */ 258 #define HI_ERR_RGN_NULL_PTR HI_DEF_ERR(HI_ID_RGN, EN_ERR_LEVEL_ERROR, EN_ERR_NULL_PTR) 259 /* try to enable or initialize system,device or channel, before configing attribute */ 260 #define HI_ERR_RGN_NOT_CONFIG HI_DEF_ERR(HI_ID_RGN, EN_ERR_LEVEL_ERROR, EN_ERR_NOT_CONFIG) 261 /* operation is not supported by NOW */ 262 #define HI_ERR_RGN_NOT_SUPPORT HI_DEF_ERR(HI_ID_RGN, EN_ERR_LEVEL_ERROR, EN_ERR_NOT_SUPPORT) 263 /* operation is not permitted ,eg, try to change stati attribute */ 264 #define HI_ERR_RGN_NOT_PERM HI_DEF_ERR(HI_ID_RGN, EN_ERR_LEVEL_ERROR, EN_ERR_NOT_PERM) 265 /* failure caused by malloc memory */ 266 #define HI_ERR_RGN_NOMEM HI_DEF_ERR(HI_ID_RGN, EN_ERR_LEVEL_ERROR, EN_ERR_NOMEM) 267 /* failure caused by malloc buffer */ 268 #define HI_ERR_RGN_NOBUF HI_DEF_ERR(HI_ID_RGN, EN_ERR_LEVEL_ERROR, EN_ERR_NOBUF) 269 /* no data in buffer */ 270 #define HI_ERR_RGN_BUF_EMPTY HI_DEF_ERR(HI_ID_RGN, EN_ERR_LEVEL_ERROR, EN_ERR_BUF_EMPTY) 271 /* no buffer for new data */ 272 #define HI_ERR_RGN_BUF_FULL HI_DEF_ERR(HI_ID_RGN, EN_ERR_LEVEL_ERROR, EN_ERR_BUF_FULL) 273 /* bad address, eg. used for copy_from_user & copy_to_user */ 274 #define HI_ERR_RGN_BADADDR HI_DEF_ERR(HI_ID_RGN, EN_ERR_LEVEL_ERROR, EN_ERR_BADADDR) 275 /* resource is busy, eg. destroy a venc chn without unregistering it */ 276 #define HI_ERR_RGN_BUSY HI_DEF_ERR(HI_ID_RGN, EN_ERR_LEVEL_ERROR, EN_ERR_BUSY) 277 278 /* 279 * System is not ready,maybe not initialed or loaded. 280 * Returning the error code when opening a device file failed. 281 */ 282 #define HI_ERR_RGN_NOTREADY HI_DEF_ERR(HI_ID_RGN, EN_ERR_LEVEL_ERROR, EN_ERR_SYS_NOTREADY) 283 284 #ifdef __cplusplus 285 #if __cplusplus 286 } 287 #endif 288 #endif /* __cplusplus */ 289 #endif /* __HI_COMM_REGION_H__ */ 290