ax_comm_vdec.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. /**********************************************************************************
  2. *
  3. * Copyright (c) 2019-2020 Beijing AXera Technology Co., Ltd. All Rights Reserved.
  4. *
  5. * This source file is the property of Beijing AXera Technology Co., Ltd. and
  6. * may not be copied or distributed in any isomorphic form without the prior
  7. * written consent of Beijing AXera Technology Co., Ltd.
  8. *
  9. **********************************************************************************/
  10. #ifndef _AX_COMMON_VDEC_H_
  11. #define _AX_COMMON_VDEC_H_
  12. #include "ax_base_type.h"
  13. #include "ax_global_type.h"
  14. #include "ax_comm_codec.h"
  15. #include "ax_pool_type.h"
  16. #include "ax_sys_api.h"
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #define AX_VDEC_MAX_GRP_SIZE 16
  21. #define AX_VDEC_ALIGN_NUM 8
  22. #define H264_MAX_WIDTH 1920
  23. #define H264_MAX_HEIGHT 1088
  24. #define H264_MIN_HEIGHT 48
  25. #define H264_MIN_WIDTH 48
  26. #define JPEG_MAX_WIDTH 16384
  27. #define JPEG_MAX_HEIGHT 16384
  28. #define JPEG_MIN_HEIGHT 48
  29. #define JPEG_MIN_WIDTH 48
  30. #define ATTRIBUTE __attribute__((aligned (AX_VDEC_ALIGN_NUM)))
  31. typedef AX_S32 AX_VDEC_GRP;
  32. typedef enum {
  33. AX_ID_VDEC_NULL = 0x01,
  34. AX_ID_VDEC_BUTT,
  35. } AX_VDEC_SUB_ID_E;
  36. typedef enum axVIDEO_MODE_E
  37. {
  38. /* send by stream */
  39. VIDEO_MODE_STREAM = 0,
  40. /* send by frame */
  41. VIDEO_MODE_FRAME,
  42. /* One frame supports multiple packets sending. The current frame is
  43. considered to end when bEndOfFrame is equal to HI_TRUE */
  44. VIDEO_MODE_COMPAT,
  45. VIDEO_MODE_BUTT
  46. }AX_VDEC_MODE_E;
  47. typedef enum axVIDEO_OUTPUT_ORDER_E
  48. {
  49. VIDEO_OUTPUT_ORDER_DISP = 0,
  50. VIDEO_OUTPUT_ORDER_DEC,
  51. VIDEO_OUTPUT_ORDER_BUTT
  52. }AX_VDEC_OUTPUT_ORDER_E;
  53. typedef struct axVDEC_ATTR_VIDEO_S
  54. {
  55. /* RW, Range: [0, 16]; reference frame num. */
  56. AX_U32 u32RefFrameNum;
  57. /* RW; specifies whether temporal motion vector predictors
  58. can be used for inter prediction */
  59. AX_BOOL bTemporalMvpEnable;
  60. /* RW; tmv buffer size(Byte) */
  61. AX_U32 u32TmvBufSize;
  62. AX_VDEC_OUTPUT_ORDER_E eOutOrder;
  63. }AX_VDEC_ATTR_VIDEO_S;
  64. typedef struct axVDEC_GRP_ATTR_S
  65. {
  66. /* RW; video type(H.264/IPEG) to be decoded */
  67. AX_PAYLOAD_TYPE_E enType;
  68. /* RW; send by stream or by frame */
  69. AX_VDEC_MODE_E enMode;
  70. /* RW; frame to next module mode */
  71. AX_LINK_MODE_E enLinkMode;
  72. /* RW; effective pic width (pixels) */
  73. AX_U32 u32PicWidth;
  74. /* RW; effective pic height (lines) */
  75. AX_U32 u32PicHeight;
  76. /* RW; frame height = pic height + padding size(lines) */
  77. AX_U32 u32FrameHeight;
  78. /* RW; stream buffer size(Byte) */
  79. AX_U32 u32StreamBufSize;
  80. /* RW; frame buffer size(Byte) */
  81. AX_U32 u32FrameBufSize;
  82. /* RW; frame buffer number*/
  83. AX_U32 u32FrameBufCnt;
  84. /* RW; wait for output queue empty before executing destroy */
  85. AX_S32 s32DestroyTimeout;
  86. /* structure with video ( h264/h265) */
  87. union
  88. {
  89. AX_VDEC_ATTR_VIDEO_S stVdecVideoAttr;
  90. };
  91. }AX_VDEC_GRP_ATTR_S;
  92. typedef struct axVDEC_STREAM_S
  93. {
  94. /* W; stream len */
  95. AX_U32 u32Len;
  96. /* W; time stamp */
  97. AX_U64 u64PTS;
  98. /* W; is the end of a frame */
  99. AX_BOOL bEndOfFrame;
  100. /* W; is the end of all stream */
  101. AX_BOOL bEndOfStream;
  102. /* W; is the current frame displayed. only valid by VIDEO_MODE_FRAME */
  103. AX_BOOL bDisplay;
  104. /* W; stream address */
  105. AX_U8* ATTRIBUTE pu8Addr;
  106. }AX_VDEC_STREAM_S;
  107. typedef struct axVDEC_USERDATA_S
  108. {
  109. /* R; userdata data phy address */
  110. AX_U64 u64PhyAddr;
  111. /* R; userdata data len */
  112. AX_U32 u32Len;
  113. AX_BOOL bValid;
  114. /* R; userdata data vir address */
  115. AX_U8* ATTRIBUTE pu8Addr;
  116. }AX_VDEC_USERDATA_S;
  117. typedef struct axJPEG_DECODE_ONCE_PARAMS
  118. {
  119. /* stream info */
  120. /* W; stream phy address */
  121. AX_U64 u64StreamPhyAddr;
  122. /* W; stream vir address */
  123. AX_U8* pu8StreamVirAddr;
  124. /* W; stream len */
  125. AX_U32 u32StreamLen;
  126. /* frame info */
  127. /* RW; output phy address */
  128. AX_U64 u64PhyAddr[3];
  129. /* RW; output virtual address */
  130. AX_U64 u64VirAddr[3];
  131. /* W; output mem size */
  132. AX_U32 u32Len[3];
  133. /* R; effective pic width (pixels) */
  134. AX_U32 u32PicWidth;
  135. /* R; effective pic height (lines) */
  136. AX_U32 u32PicHeight;
  137. /* R; */
  138. AX_IMG_FORMAT_E enImgFormat;
  139. /* R; */
  140. AX_U32 u32PicStride[3];
  141. }AX_JPEG_DECODE_ONCE_PARAMS;
  142. typedef struct ax_VDEC_DECODE_ERROR_S
  143. {
  144. /* R; format error. eg: do not support filed */
  145. AX_S32 s32FormatErr;
  146. /* R; picture width or height is larger than chnnel width or height*/
  147. AX_S32 s32PicSizeErrSet;
  148. /* R; unsupport the stream specification */
  149. AX_S32 s32StreamUnsprt;
  150. /* R; stream package error */
  151. AX_S32 s32PackErr;
  152. /* R; protocol num is not enough. eg: slice, pps, sps */
  153. AX_S32 s32PrtclNumErrSet;
  154. /* R; refrence num is not enough */
  155. AX_S32 s32RefErrSet;
  156. /* R; the buffer size of picture is not enough */
  157. AX_S32 s32PicBufSizeErrSet;
  158. /* R; the stream size is too big and and force discard stream */
  159. AX_S32 s32StreamSizeOver;
  160. /* R; the stream not released for too long time */
  161. AX_S32 s32VdecStreamNotRelease;
  162. }AX_VDEC_DECODE_ERROR_S;
  163. typedef struct axVDEC_GRP_STATUS_S
  164. {
  165. /* R; video type to be decoded */
  166. AX_PAYLOAD_TYPE_E enType;
  167. /* R; left stream bytes waiting for decode */
  168. AX_U32 u32LeftStreamBytes;
  169. /* R; left frames waiting for decode,only valid for VIDEO_MODE_FRAME*/
  170. AX_U32 u32LeftStreamFrames;
  171. /* R; pics waiting for output */
  172. AX_U32 u32LeftPics;
  173. /* R; had started recv stream? */
  174. AX_BOOL bStartRecvStream;
  175. /* R; how many frames of stream has been received. valid when send by frame. */
  176. AX_U32 u32RecvStreamFrames;
  177. /* R; how many frames of stream has been decoded. valid when send by frame. */
  178. AX_U32 u32DecodeStreamFrames;
  179. /* R; information about decode error */
  180. AX_VDEC_DECODE_ERROR_S stVdecDecErr;
  181. }AX_VDEC_GRP_STATUS_S;
  182. typedef enum axVIDEO_DEC_MODE_E
  183. {
  184. VIDEO_DEC_MODE_IPB = 0,
  185. VIDEO_DEC_MODE_IP,
  186. VIDEO_DEC_MODE_I,
  187. VIDEO_DEC_MODE_BUTT
  188. }AX_VDEC_DEC_MODE_E;
  189. typedef struct axVDEC_PARAM_VIDEO_S
  190. {
  191. /* RW, Range: [0, 100]; threshold for stream error process,
  192. 0: discard with any error, 100 : keep data with any error */
  193. AX_S32 s32ErrThreshold;
  194. /* RW; decode mode , 0: deocde IPB frames,
  195. 1: only decode I frame & P frame , 2: only decode I frame */
  196. AX_VDEC_DEC_MODE_E enDecMode;
  197. /* RW; frames output order ,0: the same with display order,
  198. 1: the same width decoder order */
  199. AX_VDEC_OUTPUT_ORDER_E enOutputOrder;
  200. /* RW; compress mode */
  201. AX_COMPRESS_MODE_E enCompressMode;
  202. /* RW; video format */
  203. AX_VSCAN_FORMAT_E enVideoFormat;
  204. }AX_VDEC_PARAM_VIDEO_S;
  205. typedef struct axVDEC_PARAM_PICTURE_S
  206. {
  207. /* RW; out put pixel format */
  208. AX_IMG_FORMAT_E enPixelFormat;
  209. /* RW, Range: [0, 255]; value 0 is transparent.
  210. [0 ,127] is deemed to transparent when enPixelFormat is ARGB1555 or ABGR1555
  211. [128 ,256] is deemed to non-transparent when enPixelFormat is ARGB1555 or ABGR1555 */
  212. AX_U32 u32Alpha;
  213. }AX_VDEC_PARAM_PICTURE_S;
  214. typedef struct axVDEC_GRP_PARAM_S
  215. {
  216. /* RW; video type to be decoded */
  217. AX_PAYLOAD_TYPE_E enType;
  218. /* RW, Range: [0, 16]; display frame num */
  219. AX_U32 u32DisplayFrameNum;
  220. union
  221. {
  222. /* structure with video ( h265/h264) */
  223. AX_VDEC_PARAM_VIDEO_S stVdecVideoParam;
  224. /* structure with picture (jpeg/mjpeg )*/
  225. AX_VDEC_PARAM_PICTURE_S stVdecPictureParam;
  226. };
  227. }AX_VDEC_GRP_PARAM_S;
  228. typedef struct axH264_PRTCL_PARAM_S
  229. {
  230. /* RW; max slice num support */
  231. AX_S32 s32MaxSliceNum;
  232. /* RW; max sps num support */
  233. AX_S32 s32MaxSpsNum;
  234. /* RW; max pps num support */
  235. AX_S32 s32MaxPpsNum;
  236. }AX_VDEC_H264_PRTCL_PARAM_S;
  237. typedef struct axH265_PRTCL_PARAM_S
  238. {
  239. /* RW; max slice segmnet num support */
  240. AX_S32 s32MaxSliceSegmentNum;
  241. /* RW; max vps num support */
  242. AX_S32 s32MaxVpsNum;
  243. /* RW; max sps num support */
  244. AX_S32 s32MaxSpsNum;
  245. /* RW; max pps num support */
  246. AX_S32 s32MaxPpsNum;
  247. }AX_VDEC_H265_PRTCL_PARAM_S;
  248. typedef struct axVDEC_PRTCL_PARAM_S
  249. {
  250. /* RW; video type to be decoded, only h264 and h265 supported*/
  251. AX_PAYLOAD_TYPE_E enType;
  252. union
  253. {
  254. /* protocol param structure for h264 */
  255. AX_VDEC_H264_PRTCL_PARAM_S stH264PrtclParam;
  256. /* protocol param structure for h265 */
  257. AX_VDEC_H265_PRTCL_PARAM_S stH265PrtclParam;
  258. };
  259. }AX_VDEC_PRTCL_PARAM_S;
  260. typedef enum axVDEC_EVNT_E
  261. {
  262. VDEC_EVNT_STREAM_ERR = 1,
  263. VDEC_EVNT_UNSUPPORT,
  264. VDEC_EVNT_OVER_REFTHR,
  265. VDEC_EVNT_REF_NUM_OVER,
  266. VDEC_EVNT_SLICE_NUM_OVER,
  267. VDEC_EVNT_SPS_NUM_OVER,
  268. VDEC_EVNT_PPS_NUM_OVER,
  269. VDEC_EVNT_PICBUF_SIZE_ERR,
  270. VDEC_EVNT_SIZE_OVER,
  271. VDEC_EVNT_IMG_SIZE_CHANGE,
  272. VDEC_EVNT_VPS_NUM_OVER,
  273. VDEC_EVNT_BUTT
  274. } AX_VDEC_EVNT_E;
  275. typedef struct axVDEC_VIDEO_MOD_PARAM_S
  276. {
  277. AX_U32 u32MaxPicWidth;
  278. AX_U32 u32MaxPicHeight;
  279. AX_U32 u32MaxSliceNum;
  280. AX_U32 u32VdhMsgNum;
  281. AX_U32 u32VdhBinSize;
  282. AX_U32 u32VdhExtMemLevel;
  283. } AX_VDEC_VIDEO_MOD_PARAM_S;
  284. typedef enum axVIDEO_DISPLAY_MODE_E
  285. {
  286. VIDEO_DISPLAY_MODE_PREVIEW = 0x0,
  287. VIDEO_DISPLAY_MODE_PLAYBACK = 0x1,
  288. VIDEO_DISPLAY_MODE_BUTT
  289. } AX_VDEC_DISPLAY_MODE_E;
  290. /************************************************************************************************************************/
  291. #ifndef AX_SUCCESS
  292. #define AX_SUCCESS 0
  293. #endif
  294. /* invlalid channel ID */
  295. #define AX_ERR_VDEC_INVALID_CHNID AX_DEF_ERR(AX_ID_VDEC, AX_ID_VDEC_NULL, 0x4)
  296. /* at lease one parameter is illegal ,eg, out of range */
  297. #define AX_ERR_VDEC_ILLEGAL_PARAM AX_DEF_ERR(AX_ID_VDEC, AX_ID_VDEC_NULL, 0xA)
  298. /* using a NULL pointer */
  299. #define AX_ERR_VDEC_NULL_PTR AX_DEF_ERR(AX_ID_VDEC, AX_ID_VDEC_NULL, 0xB)
  300. /* bad address, eg. used for copy_from_user & copy_to_user */
  301. #define AX_ERR_VDEC_BAD_ADDR AX_DEF_ERR(AX_ID_VDEC, AX_ID_VDEC_NULL, 0xC)
  302. /* system is not ready, not properly initialized or loaded driver */
  303. #define AX_ERR_VDEC_SYS_NOTREADY AX_DEF_ERR(AX_ID_VDEC, AX_ID_VDEC_NULL, 0x10)
  304. /*system busy, cannot share use or destroy */
  305. #define AX_ERR_VDEC_BUSY AX_DEF_ERR(AX_ID_VDEC, AX_ID_VDEC_NULL, 0x11)
  306. /* init error or not init at all */
  307. #define AX_ERR_VDEC_NOT_INIT AX_DEF_ERR(AX_ID_VDEC, AX_ID_VDEC_NULL, 0x12)
  308. /* configuration required before using a system/device/channel */
  309. #define AX_ERR_VDEC_NOT_CONFIG AX_DEF_ERR(AX_ID_VDEC, AX_ID_VDEC_NULL, 0x13)
  310. /* operation is not (yet) supported on this platform */
  311. #define AX_ERR_VDEC_NOT_SUPPORT AX_DEF_ERR(AX_ID_VDEC, AX_ID_VDEC_NULL, 0x14)
  312. /* operation is not permitted, eg, try to change a static attribute, or start without init */
  313. #define AX_ERR_VDEC_NOT_PERM AX_DEF_ERR(AX_ID_VDEC, AX_ID_VDEC_NULL, 0x15)
  314. /* channel already exists */
  315. #define AX_ERR_VDEC_EXIST AX_DEF_ERR(AX_ID_VDEC, AX_ID_VDEC_NULL, 0x16)
  316. /* the channle is not existing */
  317. #define AX_ERR_VDEC_UNEXIST AX_DEF_ERR(AX_ID_VDEC, AX_ID_VDEC_NULL, 0x17)
  318. /* failure caused by malloc memory from heap*/
  319. #define AX_ERR_VDEC_NOMEM AX_DEF_ERR(AX_ID_VDEC, AX_ID_VDEC_NULL, 0x18)
  320. /* failure caused by borrow buffer from pool*/
  321. #define AX_ERR_VDEC_NOBUF AX_DEF_ERR(AX_ID_VDEC, AX_ID_VDEC_NULL, 0x19)
  322. /* no data in buffer */
  323. #define AX_ERR_VDEC_BUF_EMPTY AX_DEF_ERR(AX_ID_VDEC, AX_ID_VDEC_NULL, 0x20)
  324. /* no buffer for new data */
  325. #define AX_ERR_VDEC_BUF_FULL AX_DEF_ERR(AX_ID_VDEC, AX_ID_VDEC_NULL, 0x21)
  326. /* wait timeout failed */
  327. #define AX_ERR_VDEC_TIMED_OUT AX_DEF_ERR(AX_ID_VDEC, AX_ID_VDEC_NULL, 0x27)
  328. /* process termination */
  329. #define AX_ERR_VDEC_FLOW_END AX_DEF_ERR(AX_ID_VDEC, AX_ID_VDEC_NULL, 0x28)
  330. /*for vdec unknown error*/
  331. #define AX_ERR_VDEC_UNKNOWN AX_DEF_ERR(AX_ID_VDEC, AX_ID_VDEC_NULL, 0x29)
  332. /* run error */
  333. #define AX_ERR_VDEC_RUN_ERROR AX_DEF_ERR(AX_ID_VDEC, AX_ID_VDEC_NULL, 0x80)
  334. /* stream error */
  335. #define AX_ERR_VDEC_STRM_ERROR AX_DEF_ERR(AX_ID_VDEC, AX_ID_VDEC_NULL, 0x81)
  336. #ifdef __cplusplus
  337. }
  338. #endif
  339. #endif