1 /* GPL-2.0 WITH Linux-syscall-note OR Apache 2.0 */ 2 /* Copyright (c) 2021 Fuzhou Rockchip Electronics Co., Ltd */ 3 4 #ifndef INCLUDE_RT_MPI_RK_COMM_VI_H_ 5 #define INCLUDE_RT_MPI_RK_COMM_VI_H_ 6 7 #include "rk_common.h" 8 #include "rk_errno.h" 9 #include "rk_comm_video.h" 10 11 #ifdef __cplusplus 12 #if __cplusplus 13 extern "C" { 14 #endif 15 #endif /* __cplusplus */ 16 17 #define VI_CHN0 0 18 #define VI_CHN1 1 19 #define VI_CHN2 2 20 #define VI_CHN3 3 21 #define VI_CHN4 4 22 #define VI_CHN5 5 23 24 #define MAX_VI_FILE_PATH_LEN 256 25 #define MAX_VI_FILE_NAME_LEN 256 26 #define MAX_VI_ENTITY_NAME_LEN 32 27 #define MAX_VI_BIND_PIPE_NUM 16 28 29 /* interface mode of video input */ 30 typedef enum rkVI_INTF_MODE_E { 31 VI_MODE_BT656 = 0, /* ITU-R BT.656 YUV4:2:2 */ 32 VI_MODE_BT601, /* ITU-R BT.601 YUV4:2:2 */ 33 VI_MODE_DIGITAL_CAMERA, /* digatal camera mode */ 34 VI_MODE_BT1120_STANDARD, /* BT.1120 progressive mode */ 35 VI_MODE_BT1120_INTERLEAVED, /* BT.1120 interstage mode */ 36 VI_MODE_MIPI, /* MIPI RAW mode */ 37 VI_MODE_MIPI_YUV420_NORMAL, /* MIPI YUV420 normal mode */ 38 VI_MODE_MIPI_YUV420_LEGACY, /* MIPI YUV420 legacy mode */ 39 VI_MODE_MIPI_YUV422, /* MIPI YUV422 mode */ 40 VI_MODE_LVDS, /* LVDS mode */ 41 VI_MODE_SPI, /* SPi mode */ 42 VI_MODE_SLVS, /* SLVS mode */ 43 44 VI_MODE_BUTT 45 } VI_INTF_MODE_E; 46 47 /* Input mode */ 48 typedef enum rkVI_INPUT_MODE_E { 49 VI_INPUT_MODE_BT656 = 0, /* ITU-R BT.656 YUV4:2:2 */ 50 VI_INPUT_MODE_BT601, /* ITU-R BT.601 YUV4:2:2 */ 51 VI_INPUT_MODE_DIGITAL_CAMERA, /* digatal camera mode */ 52 VI_INPUT_MODE_INTERLEAVED, /* interstage mode */ 53 VI_INPUT_MODE_MIPI, /* MIPI mode */ 54 VI_INPUT_MODE_LVDS, /* LVDS mode */ 55 VI_INPUT_MODE_SPI, /* SPi mode */ 56 VI_INPUT_MODE_SLVS, /* SLVS mode */ 57 58 VI_INPUT_MODE_BUTT 59 } VI_INPUT_MODE_E; 60 61 /* Work mode */ 62 typedef enum rkVI_WORK_MODE_E { 63 VI_WORK_MODE_1Multiplex = 0, /* 1 Multiplex mode */ 64 VI_WORK_MODE_2Multiplex, /* 2 Multiplex mode */ 65 VI_WORK_MODE_3Multiplex, /* 3 Multiplex mode */ 66 VI_WORK_MODE_4Multiplex, /* 4 Multiplex mode */ 67 68 VI_WORK_MODE_BUTT 69 } VI_WORK_MODE_E; 70 71 /* Sequence of YUV data */ 72 typedef enum rkVI_YUV_DATA_SEQ_E { 73 /* 74 * The input sequence of the second component 75 * (only contains u and v) in BT.1120 mode is VUVU 76 */ 77 VI_DATA_SEQ_VUVU = 0, 78 /* 79 * The input sequence of the second component 80 * (only contains u and v) in BT.1120 mode is UVUV 81 */ 82 VI_DATA_SEQ_UVUV, 83 84 VI_DATA_SEQ_UYVY, /* The input sequence of YUV is UYVY */ 85 VI_DATA_SEQ_VYUY, /* The input sequence of YUV is VYUY */ 86 VI_DATA_SEQ_YUYV, /* The input sequence of YUV is YUYV */ 87 VI_DATA_SEQ_YVYU, /* The input sequence of YUV is YVYU */ 88 89 VI_DATA_SEQ_BUTT 90 } VI_YUV_DATA_SEQ_E; 91 92 /* Input data type */ 93 typedef enum rkVI_DATA_TYPE_E { 94 VI_DATA_TYPE_YUV = 0, 95 VI_DATA_TYPE_RGB, 96 97 VI_DATA_TYPE_BUTT 98 } VI_DATA_TYPE_E; 99 100 /* The attributes of a VI device */ 101 typedef struct rkVI_DEV_ATTR_S { 102 /* RW;Interface mode */ 103 VI_INTF_MODE_E enIntfMode; 104 /* RW;Work mode */ 105 VI_WORK_MODE_E enWorkMode; 106 /* The below members must be configured in BT.601 mode or DC mode and are invalid in other modes */ 107 /* RW;Input data sequence (only the YUV format is supported) */ 108 VI_YUV_DATA_SEQ_E enDataSeq; 109 /* RW;RGB: CSC-709 or CSC-601, PT YUV444 disable; YUV: default yuv CSC coef PT YUV444 enable. */ 110 VI_DATA_TYPE_E enInputDataType; 111 /* RW;Input max size */ 112 SIZE_S stMaxSize; 113 /* RW;Data rate of Device */ 114 DATA_RATE_E enDataRate; 115 } VI_DEV_ATTR_S; 116 117 /* The status of chn */ 118 typedef struct rkVI_DEV_STATUS_S { 119 SIZE_S stSize; /* RO;chn output size */ 120 RK_BOOL bProbeOk; /* RO;whether sensor is probed success */ 121 } VI_DEV_STATUS_S; 122 123 /* Information of pipe binded to device */ 124 typedef struct rkVI_DEV_BIND_PIPE_S { 125 RK_U32 u32Num; /* RW;Range [1,VI_MAX_PHY_PIPE_NUM] */ 126 VI_PIPE PipeId[MAX_VI_BIND_PIPE_NUM]; /* RW;Array of pipe ID */ 127 } VI_DEV_BIND_PIPE_S; 128 129 /* The attributes of pipe */ 130 typedef struct rkVI_PIPE_ATTR_S { 131 /* RW;Range:[0,1];ISP bypass enable */ 132 RK_BOOL bIspBypass; 133 /* RW;Range:[0,1];Range[VI_PIPE_MIN_WIDTH,VI_PIPE_MAX_WIDTH];Maximum width */ 134 RK_U32 u32MaxW; 135 /* RW;Range[VI_PIPE_MIN_HEIGHT,VI_PIPE_MAX_HEIGHT];Maximum height */ 136 RK_U32 u32MaxH; 137 /* RW;Pixel format */ 138 PIXEL_FORMAT_E enPixFmt; 139 /* RW;Range:[0,4];Compress mode.*/ 140 COMPRESS_MODE_E enCompressMode; 141 /* RW;Range:[0,4];Bit width*/ 142 DATA_BITWIDTH_E enBitWidth; 143 /* RW;Frame rate */ 144 FRAME_RATE_CTRL_S stFrameRate; 145 } VI_PIPE_ATTR_S; 146 147 typedef enum rkVI_ALLOC_BUF_TYPE_E { 148 VI_ALLOC_BUF_TYPE_INTERNAL, 149 VI_ALLOC_BUF_TYPE_EXTERNAL 150 } VI_ALLOC_BUF_TYPE_E; 151 152 typedef enum rkVI_V4L2_CAPTURE_TYPE { 153 VI_V4L2_CAPTURE_TYPE_VIDEO_CAPTURE = 1, 154 VI_V4L2_CAPTURE_TYPE_VBI_CAPTURE = 4, 155 VI_V4L2_CAPTURE_TYPE_SLICED_VBI_CAPTURE = 6, 156 VI_V4L2_CAPTURE_TYPE_VIDEO_CAPTURE_MPLANE = 9, 157 VI_V4L2_CAPTURE_TYPE_SDR_CAPTURE = 11, 158 VI_V4L2_CAPTURE_TYPE_META_CAPTURE = 13, 159 /* Deprecated, do not use */ 160 VI_V4L2_CAPTURE_TYPE_PRIVATE = 0x80, 161 } VI_V4L2_CAPTURE_TYPE; 162 163 typedef enum rkVI_V4L2_MEMORY_TYPE { 164 VI_V4L2_MEMORY_TYPE_MMAP = 1, 165 VI_V4L2_MEMORY_TYPE_USERPTR = 2, 166 VI_V4L2_MEMORY_TYPE_OVERLAY = 3, 167 VI_V4L2_MEMORY_TYPE_DMABUF = 4, 168 } VI_V4L2_MEMORY_TYPE; 169 170 /* The attributes of channel for isp opt */ 171 typedef struct rkVI_ISP_OPT_S { 172 RK_U32 u32BufCount; /* RW;isp buf count */ 173 RK_U32 u32BufSize; /* R;isp buf size */ 174 VI_V4L2_CAPTURE_TYPE enCaptureType; /* RW;isp capture type */ 175 VI_V4L2_MEMORY_TYPE enMemoryType; /* RW;isp buf memory type */ 176 RK_CHAR aEntityName[MAX_VI_ENTITY_NAME_LEN]; /* RW;isp capture entity name*/ 177 RK_BOOL bNoUseLibV4L2; /* RW;is no use libv4l2 */ 178 SIZE_S stMaxSize; /* RW;isp bypass resolution */ 179 } VI_ISP_OPT_S; 180 181 /* The attributes of channel */ 182 typedef struct rkVI_CHN_ATTR_S { 183 SIZE_S stSize; /* RW;Channel out put size */ 184 PIXEL_FORMAT_E enPixelFormat; /* RW;Pixel format */ 185 DYNAMIC_RANGE_E enDynamicRange; /* RW;Dynamic Range */ 186 VIDEO_FORMAT_E enVideoFormat; /* RW;Video format */ 187 COMPRESS_MODE_E enCompressMode; /* RW;256B Segment compress or no compress. */ 188 RK_BOOL bMirror; /* RW;Mirror enable */ 189 RK_BOOL bFlip; /* RW;Flip enable */ 190 RK_U32 u32Depth; /* RW; Range: [0, 8]; User get list depth.*/ 191 FRAME_RATE_CTRL_S stFrameRate; /* RW;Frame rate */ 192 VI_ALLOC_BUF_TYPE_E enAllocBufType; /* RW;channel alloc buf opt */ 193 VI_ISP_OPT_S stIspOpt; /* RW;isp opt */ 194 } VI_CHN_ATTR_S; 195 196 /* The status of chn */ 197 typedef struct rkVI_CHN_STATUS_S { 198 RK_BOOL bEnable; /* RO;Whether this channel is enabled */ 199 RK_U32 u32FrameRate; /* RO;current frame rate */ 200 RK_U32 u32CurFrameID; /* RO;current frame id */ 201 RK_U32 u32InputLostFrame; /* RO;input lost frame count */ 202 RK_U32 u32OutputLostFrame; /* RO;output lost frame count */ 203 RK_U32 u32VbFail; /* RO;Video buffer malloc failure */ 204 SIZE_S stSize; /* RO;chn output size */ 205 } VI_CHN_STATUS_S; 206 207 /* Defines the configure parameters of VI saving file. */ 208 typedef struct rkVI_SAVE_FILE_INFO_S { 209 RK_BOOL bCfg; 210 RK_CHAR aFilePath[MAX_VI_FILE_PATH_LEN]; 211 RK_CHAR aFileName[MAX_VI_FILE_NAME_LEN]; 212 RK_U32 u32FileSize; /*in KB*/ 213 } VI_SAVE_FILE_INFO_S; 214 215 typedef struct rkVI_CHN_BUF_WRAP_S { 216 RK_BOOL bEnable; 217 RK_U32 u32BufLine; /* RW; Range: [128, H]; Chn buffer allocated by line. */ 218 RK_U32 u32WrapBufferSize; /* RW; Whether to allocate buffer according to compression. */ 219 } VI_CHN_BUF_WRAP_S; 220 221 /* struct rkisp_mirror_flip 222 * mirror: global for all output stream 223 * flip: independent for all output stream 224 */ 225 typedef struct rkISP_MIRROR_FLIP_S { 226 RK_U8 mirror; 227 RK_U8 flip; 228 } __attribute__((packed)) VI_ISP_MIRROR_FLIP_S; 229 230 typedef enum rkVI_CROP_COORDINATE_E { 231 VI_CROP_RATIO_COOR = 0, 232 VI_CROP_ABS_COOR, 233 VI_CROP_BUTT 234 } VI_CROP_COORDINATE_E; 235 236 typedef struct rkVI_CROP_INFO_S { 237 RK_BOOL bEnable; 238 VI_CROP_COORDINATE_E enCropCoordinate; 239 RECT_S stCropRect; 240 } VI_CROP_INFO_S; 241 242 /* User picture mode */ 243 typedef enum rk_VI_USERPIC_MODE_E { 244 VI_USERPIC_MODE_PIC = 0, 245 VI_USERPIC_MODE_BGC, 246 VI_USERPIC_MODE_BUTT, 247 } VI_USERPIC_MODE_E; 248 249 /* User picture background color */ 250 typedef struct rkVI_USERPIC_BGC_S { 251 RK_U32 u32BgColor; 252 } VI_USERPIC_BGC_S; 253 254 /* User picture attr */ 255 typedef struct rkVI_USERPIC_ATTR_S { 256 VI_USERPIC_MODE_E enUsrPicMode; 257 union { 258 VIDEO_FRAME_INFO_S stUsrPicFrm; 259 VI_USERPIC_BGC_S stUsrPicBg; 260 } unUsrPic; 261 } VI_USERPIC_ATTR_S; 262 263 typedef enum rkVI_CONNECT_STATE_E { 264 VI_CONNECT_STATE_UNKNOWN = 0, 265 VI_CONNECT_STATE_CONNECT, 266 VI_CONNECT_STATE_DISCONNECT, 267 VI_CONNECT_STATE_BUTT 268 } VI_CONNECT_STATE_E; 269 270 typedef struct rkVI_CONNECT_INFO_S { 271 RK_U32 u32Width; 272 RK_U32 u32Height; 273 RK_FLOAT f32FrameRate; 274 PIXEL_FORMAT_E enPixFmt; 275 VI_CONNECT_STATE_E enConnect; 276 } VI_CONNECT_INFO_S; 277 278 typedef struct rkVI_EDID_S { 279 RK_U32 u32Pad; 280 RK_U32 u32StartBlock; 281 RK_U32 u32Blocks; 282 RK_U32 au32Reserved[5]; 283 RK_U8 *pu8Edid; 284 } VI_EDID_S; 285 286 typedef struct rkVI_STREAM_S { 287 MB_BLK pMbBlk; 288 RK_U32 u32Len; 289 RK_U32 u32Seq; 290 RK_U64 u64PTS; 291 } VI_STREAM_S; 292 293 typedef enum rkVI_EVENT_E { 294 VI_EVENT_CONNECT_CHANGE = 1 << 0, 295 VI_EVENT_SOURCE_CHANGE = 1 << 1, 296 } VI_EVENT_E; 297 298 typedef struct rkVI_CB_INFO_S { 299 RK_U32 u32Event; 300 } VI_CB_INFO_S; 301 302 /** change event handling callback function */ 303 typedef void (*RK_VI_EventCallback)(RK_VOID *pPrivateData, VI_CB_INFO_S *pstInfo); 304 305 typedef struct rkVI_EVENT_CALL_BACK_S { 306 RK_VI_EventCallback pfnCallback; 307 RK_VOID *pPrivateData; 308 } VI_EVENT_CALL_BACK_S; 309 310 #define RK_ERR_VI_INVALID_PARA RK_DEF_ERR(RK_ID_VI, RK_ERR_LEVEL_ERROR, RK_ERR_ILLEGAL_PARAM) 311 #define RK_ERR_VI_INVALID_DEVID RK_DEF_ERR(RK_ID_VI, RK_ERR_LEVEL_ERROR, RK_ERR_INVALID_DEVID) 312 #define RK_ERR_VI_INVALID_PIPEID RK_DEF_ERR(RK_ID_VI, RK_ERR_LEVEL_ERROR, RK_ERR_INVALID_PIPEID) 313 #define RK_ERR_VI_INVALID_CHNID RK_DEF_ERR(RK_ID_VI, RK_ERR_LEVEL_ERROR, RK_ERR_INVALID_CHNID) 314 #define RK_ERR_VI_INVALID_NULL_PTR RK_DEF_ERR(RK_ID_VI, RK_ERR_LEVEL_ERROR, RK_ERR_NULL_PTR) 315 #define RK_ERR_VI_FAILED_NOTCONFIG RK_DEF_ERR(RK_ID_VI, RK_ERR_LEVEL_ERROR, RK_ERR_NOT_CONFIG) 316 #define RK_ERR_VI_SYS_NOTREADY RK_DEF_ERR(RK_ID_VI, RK_ERR_LEVEL_ERROR, RK_ERR_NOTREADY) 317 #define RK_ERR_VI_BUF_EMPTY RK_DEF_ERR(RK_ID_VI, RK_ERR_LEVEL_ERROR, RK_ERR_BUF_EMPTY) 318 #define RK_ERR_VI_BUF_FULL RK_DEF_ERR(RK_ID_VI, RK_ERR_LEVEL_ERROR, RK_ERR_BUF_FULL) 319 #define RK_ERR_VI_NOMEM RK_DEF_ERR(RK_ID_VI, RK_ERR_LEVEL_ERROR, RK_ERR_NOMEM) 320 #define RK_ERR_VI_NOT_SUPPORT RK_DEF_ERR(RK_ID_VI, RK_ERR_LEVEL_ERROR, RK_ERR_NOT_SUPPORT) 321 #define RK_ERR_VI_BUSY RK_DEF_ERR(RK_ID_VI, RK_ERR_LEVEL_ERROR, RK_ERR_BUSY) 322 #define RK_ERR_VI_NOT_PERM RK_DEF_ERR(RK_ID_VI, RK_ERR_LEVEL_ERROR, RK_ERR_NOT_PERM) 323 /* try to enable or initialize system,device or pipe or channel, before configing attribute */ 324 #define RK_ERR_VI_NOT_CONFIG RK_DEF_ERR(RK_ID_VI, RK_ERR_LEVEL_ERROR, RK_ERR_NOT_CONFIG) 325 /* channel exists */ 326 #define RK_ERR_VI_EXIST RK_DEF_ERR(RK_ID_VI, RK_ERR_LEVEL_ERROR, RK_ERR_EXIST) 327 /* the channel is not existed */ 328 #define RK_ERR_VI_UNEXIST RK_DEF_ERR(RK_ID_VI, RK_ERR_LEVEL_ERROR, RK_ERR_UNEXIST) 329 330 #ifdef __cplusplus 331 #if __cplusplus 332 } 333 #endif 334 #endif /* __cplusplus */ 335 336 #endif /* End of #ifndef INCLUDE_RT_MPI_RK_COMM_VI_H_ */ 337