• 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 __HI_COMM_VDEC_H__
17 #define __HI_COMM_VDEC_H__
18 #include "hi_type.h"
19 #include "hi_common.h"
20 #include "hi_errno.h"
21 #include "hi_comm_video.h"
22 #include "hi_comm_vb.h"
23 #include "hi_defines.h"
24 
25 #ifdef __cplusplus
26 #if __cplusplus
27 extern "C" {
28 #endif
29 #endif /* End of #ifdef __cplusplus */
30 
31 #define HI_IO_BLOCK               HI_TRUE
32 #define HI_IO_NOBLOCK             HI_FALSE
33 
34 typedef enum hiVIDEO_MODE_E {
35     VIDEO_MODE_STREAM = 0, /* send by stream */
36     VIDEO_MODE_FRAME, /* send by frame  */
37     VIDEO_MODE_COMPAT, /* One frame supports multiple packets sending. */
38     /* The current frame is considered to end when bEndOfFrame is equal to HI_TRUE */
39     VIDEO_MODE_BUTT
40 } VIDEO_MODE_E;
41 
42 typedef struct hiVDEC_ATTR_VIDEO_S {
43     HI_U32 u32RefFrameNum; /* RW, Range: [0, 16]; reference frame num. */
44     HI_BOOL bTemporalMvpEnable; /* RW; */
45     /* specifies whether temporal motion vector predictors can be used for inter prediction */
46     HI_U32 u32TmvBufSize; /* RW; tmv buffer size(Byte) */
47 } VDEC_ATTR_VIDEO_S;
48 
49 typedef struct hiVDEC_CHN_ATTR_S {
50     PAYLOAD_TYPE_E enType; /* RW; video type to be decoded   */
51     VIDEO_MODE_E enMode; /* RW; send by stream or by frame */
52     HI_U32 u32PicWidth; /* RW; max pic width */
53     HI_U32 u32PicHeight; /* RW; max pic height */
54     HI_U32 u32StreamBufSize; /* RW; stream buffer size(Byte) */
55     HI_U32 u32FrameBufSize; /* RW; frame buffer size(Byte) */
56     HI_U32 u32FrameBufCnt;
57     union {
58         VDEC_ATTR_VIDEO_S stVdecVideoAttr; /* structure with video ( h264/h265) */
59     };
60 } VDEC_CHN_ATTR_S;
61 
62 typedef struct hiVDEC_STREAM_S {
63     HI_U32 u32Len; /* W; stream len */
64     HI_U64 u64PTS; /* W; time stamp */
65     HI_BOOL bEndOfFrame; /* W; is the end of a frame */
66     HI_BOOL bEndOfStream; /* W; is the end of all stream */
67     HI_BOOL bDisplay; /* W; is the current frame displayed. only valid by VIDEO_MODE_FRAME */
68     HI_U8 *ATTRIBUTE pu8Addr; /* W; stream address */
69 } VDEC_STREAM_S;
70 
71 typedef struct hiVDEC_USERDATA_S {
72     HI_U64 u64PhyAddr; /* R; userdata data phy address */
73     HI_U32 u32Len; /* R; userdata data len */
74     HI_BOOL bValid; /* R; is valid? */
75     HI_U8 *ATTRIBUTE pu8Addr; /* R; userdata data vir address */
76 } VDEC_USERDATA_S;
77 
78 typedef struct hi_VDEC_DECODE_ERROR_S {
79     HI_S32 s32FormatErr; /* R; format error. eg: do not support filed */
80     HI_S32 s32PicSizeErrSet; /* R; picture width or height is larger than chnnel width or height */
81     HI_S32 s32StreamUnsprt; /* R; unsupport the stream specification */
82     HI_S32 s32PackErr; /* R; stream package error */
83     HI_S32 s32PrtclNumErrSet; /* R; protocol num is not enough. eg: slice, pps, sps */
84     HI_S32 s32RefErrSet; /* R; refrence num is not enough */
85     HI_S32 s32PicBufSizeErrSet; /* R; the buffer size of picture is not enough */
86     HI_S32 s32StreamSizeOver; /* R; the stream size is too big and force discard stream */
87     HI_S32 s32VdecStreamNotRelease; /* R; the stream not released for too long time */
88 } VDEC_DECODE_ERROR_S;
89 
90 typedef struct hiVDEC_CHN_STATUS_S {
91     PAYLOAD_TYPE_E enType; /* R; video type to be decoded */
92     HI_U32 u32LeftStreamBytes; /* R; left stream bytes waiting for decode */
93     HI_U32 u32LeftStreamFrames; /* R; left frames waiting for decode,only valid for VIDEO_MODE_FRAME */
94     HI_U32 u32LeftPics; /* R; pics waiting for output */
95     HI_BOOL bStartRecvStream; /* R; had started recv stream? */
96     HI_U32 u32RecvStreamFrames; /* R; how many frames of stream has been received. valid when send by frame. */
97     HI_U32 u32DecodeStreamFrames; /* R; how many frames of stream has been decoded. valid when send by frame. */
98     VDEC_DECODE_ERROR_S stVdecDecErr; /* R; information about decode error */
99     HI_U32 u32Width; /* R; the width of the currently decoded stream */
100     HI_U32 u32Height; /* R; the height of the currently decoded stream */
101 } VDEC_CHN_STATUS_S;
102 
103 typedef enum hiVIDEO_DEC_MODE_E {
104     VIDEO_DEC_MODE_IPB = 0,
105     VIDEO_DEC_MODE_IP,
106     VIDEO_DEC_MODE_I,
107     VIDEO_DEC_MODE_BUTT
108 } VIDEO_DEC_MODE_E;
109 
110 typedef enum hiVIDEO_OUTPUT_ORDER_E {
111     VIDEO_OUTPUT_ORDER_DISP = 0,
112     VIDEO_OUTPUT_ORDER_DEC,
113     VIDEO_OUTPUT_ORDER_BUTT
114 } VIDEO_OUTPUT_ORDER_E;
115 
116 typedef struct hiVDEC_PARAM_VIDEO_S {
117     HI_S32 s32ErrThreshold; /* RW, Range: [0, 100]; */
118     /* threshold for stream error process, 0: discard with any error, 100 : keep data with any error */
119     VIDEO_DEC_MODE_E enDecMode; /* RW; */
120     /* decode mode , 0: deocde IPB frames, 1: only decode I frame & P frame , 2: only decode I frame */
121     VIDEO_OUTPUT_ORDER_E enOutputOrder; /* RW; */
122     /* frames output order ,0: the same with display order , 1: the same width decoder order */
123     COMPRESS_MODE_E enCompressMode; /* RW; compress mode */
124     VIDEO_FORMAT_E enVideoFormat; /* RW; video format */
125     HI_BOOL bCompositeDecEnable; /* RW; HI_FALSE: output base layer; HI_TRUE: output enhance layer; default: HI_FALSE */
126 } VDEC_PARAM_VIDEO_S;
127 
128 typedef struct hiVDEC_PARAM_PICTURE_S {
129     PIXEL_FORMAT_E enPixelFormat; /* RW; out put pixel format */
130     HI_U32 u32Alpha; /* RW, Range: [0, 255]; value 0 is transparent. */
131     /* [0 ,127]   is deemed to transparent when enPixelFormat is ARGB1555 or ABGR1555
132      * [128 ,256] is deemed to non-transparent when enPixelFormat is ARGB1555 or ABGR1555
133      */
134 } VDEC_PARAM_PICTURE_S;
135 
136 typedef struct hiVDEC_CHN_PARAM_S {
137     PAYLOAD_TYPE_E enType; /* RW; video type to be decoded   */
138     HI_U32 u32DisplayFrameNum; /* RW, Range: [0, 16]; display frame num */
139     union {
140         VDEC_PARAM_VIDEO_S stVdecVideoParam; /* structure with video ( h265/h264) */
141         VDEC_PARAM_PICTURE_S stVdecPictureParam; /* structure with picture (jpeg/mjpeg ) */
142     };
143 } VDEC_CHN_PARAM_S;
144 
145 typedef struct hiH264_PRTCL_PARAM_S {
146     HI_S32 s32MaxSliceNum; /* RW; max slice num support */
147     HI_S32 s32MaxSpsNum; /* RW; max sps num support */
148     HI_S32 s32MaxPpsNum; /* RW; max pps num support */
149 } H264_PRTCL_PARAM_S;
150 
151 typedef struct hiH265_PRTCL_PARAM_S {
152     HI_S32 s32MaxSliceSegmentNum; /* RW; max slice segmnet num support */
153     HI_S32 s32MaxVpsNum; /* RW; max vps num support */
154     HI_S32 s32MaxSpsNum; /* RW; max sps num support */
155     HI_S32 s32MaxPpsNum; /* RW; max pps num support */
156 } H265_PRTCL_PARAM_S;
157 
158 typedef struct hiVDEC_PRTCL_PARAM_S {
159     PAYLOAD_TYPE_E enType; /* RW; video type to be decoded, only h264 and h265 supported */
160     union {
161         H264_PRTCL_PARAM_S stH264PrtclParam; /* protocol param structure for h264 */
162         H265_PRTCL_PARAM_S stH265PrtclParam; /* protocol param structure for h265 */
163     };
164 } VDEC_PRTCL_PARAM_S;
165 
166 typedef struct hiVDEC_CHN_POOL_S {
167     VB_POOL hPicVbPool; /* RW;  vb pool id for pic buffer */
168     VB_POOL hTmvVbPool; /* RW;  vb pool id for tmv buffer */
169 } VDEC_CHN_POOL_S;
170 
171 typedef enum hiVDEC_EVNT_E {
172     VDEC_EVNT_STREAM_ERR = 1,
173     VDEC_EVNT_UNSUPPORT,
174     VDEC_EVNT_OVER_REFTHR,
175     VDEC_EVNT_REF_NUM_OVER,
176     VDEC_EVNT_SLICE_NUM_OVER,
177     VDEC_EVNT_SPS_NUM_OVER,
178     VDEC_EVNT_PPS_NUM_OVER,
179     VDEC_EVNT_PICBUF_SIZE_ERR,
180     VDEC_EVNT_SIZE_OVER,
181     VDEC_EVNT_IMG_SIZE_CHANGE,
182     VDEC_EVNT_VPS_NUM_OVER,
183     VDEC_EVNT_BUTT
184 } VDEC_EVNT_E;
185 
186 typedef enum hiVDEC_CAPACITY_STRATEGY_E {
187     VDEC_CAPACITY_STRATEGY_BY_MOD = 0,
188     VDEC_CAPACITY_STRATEGY_BY_CHN = 1,
189     VDEC_CAPACITY_STRATEGY_BUTT
190 } VDEC_CAPACITY_STRATEGY_E;
191 
192 typedef struct hiVDEC_VIDEO_MOD_PARAM_S {
193     HI_U32 u32MaxPicWidth;
194     HI_U32 u32MaxPicHeight;
195     HI_U32 u32MaxSliceNum;
196     HI_U32 u32VdhMsgNum;
197     HI_U32 u32VdhBinSize;
198     HI_U32 u32VdhExtMemLevel;
199 } VDEC_VIDEO_MOD_PARAM_S;
200 
201 typedef struct hiVDEC_PICTURE_MOD_PARAM_S {
202     HI_U32 u32MaxPicWidth;
203     HI_U32 u32MaxPicHeight;
204     HI_BOOL bSupportProgressive;
205     HI_BOOL bDynamicAllocate;
206     VDEC_CAPACITY_STRATEGY_E enCapStrategy;
207 } VDEC_PICTURE_MOD_PARAM_S;
208 
209 typedef struct hiVDEC_MOD_PARAM_S {
210     VB_SOURCE_E enVdecVBSource; /* RW, Range: [1, 3];  frame buffer mode  */
211     HI_U32 u32MiniBufMode; /* RW, Range: [0, 1];  stream buffer mode */
212     HI_U32 u32ParallelMode; /* RW, Range: [0, 1];  VDH working mode   */
213     VDEC_VIDEO_MOD_PARAM_S stVideoModParam;
214     VDEC_PICTURE_MOD_PARAM_S stPictureModParam;
215 } VDEC_MOD_PARAM_S;
216 
217 typedef struct hiVDEC_USER_DATA_ATTR_S {
218     HI_BOOL bEnable;
219     HI_U32  u32MaxUserDataLen;
220 } VDEC_USER_DATA_ATTR_S;
221 
222 /*********************************************************************************************/
223 /* invlalid channel ID */
224 #define HI_ERR_VDEC_INVALID_CHNID HI_DEF_ERR(HI_ID_VDEC, EN_ERR_LEVEL_ERROR, EN_ERR_INVALID_CHNID)
225 /* at lease one parameter is illagal ,eg, an illegal enumeration value  */
226 #define HI_ERR_VDEC_ILLEGAL_PARAM HI_DEF_ERR(HI_ID_VDEC, EN_ERR_LEVEL_ERROR, EN_ERR_ILLEGAL_PARAM)
227 /* channel exists */
228 #define HI_ERR_VDEC_EXIST         HI_DEF_ERR(HI_ID_VDEC, EN_ERR_LEVEL_ERROR, EN_ERR_EXIST)
229 /* using a NULL point */
230 #define HI_ERR_VDEC_NULL_PTR      HI_DEF_ERR(HI_ID_VDEC, EN_ERR_LEVEL_ERROR, EN_ERR_NULL_PTR)
231 /* try to enable or initialize system,device or channel, before configing attribute */
232 #define HI_ERR_VDEC_NOT_CONFIG    HI_DEF_ERR(HI_ID_VDEC, EN_ERR_LEVEL_ERROR, EN_ERR_NOT_CONFIG)
233 /* operation is not supported by NOW */
234 #define HI_ERR_VDEC_NOT_SUPPORT   HI_DEF_ERR(HI_ID_VDEC, EN_ERR_LEVEL_ERROR, EN_ERR_NOT_SUPPORT)
235 /* operation is not permitted ,eg, try to change stati attribute */
236 #define HI_ERR_VDEC_NOT_PERM      HI_DEF_ERR(HI_ID_VDEC, EN_ERR_LEVEL_ERROR, EN_ERR_NOT_PERM)
237 /* the channle is not existed  */
238 #define HI_ERR_VDEC_UNEXIST       HI_DEF_ERR(HI_ID_VDEC, EN_ERR_LEVEL_ERROR, EN_ERR_UNEXIST)
239 /* failure caused by malloc memory */
240 #define HI_ERR_VDEC_NOMEM         HI_DEF_ERR(HI_ID_VDEC, EN_ERR_LEVEL_ERROR, EN_ERR_NOMEM)
241 /* failure caused by malloc buffer */
242 #define HI_ERR_VDEC_NOBUF         HI_DEF_ERR(HI_ID_VDEC, EN_ERR_LEVEL_ERROR, EN_ERR_NOBUF)
243 /* no data in buffer */
244 #define HI_ERR_VDEC_BUF_EMPTY     HI_DEF_ERR(HI_ID_VDEC, EN_ERR_LEVEL_ERROR, EN_ERR_BUF_EMPTY)
245 /* no buffer for new data */
246 #define HI_ERR_VDEC_BUF_FULL      HI_DEF_ERR(HI_ID_VDEC, EN_ERR_LEVEL_ERROR, EN_ERR_BUF_FULL)
247 /* system is not ready,had not initialed or loaded */
248 #define HI_ERR_VDEC_SYS_NOTREADY  HI_DEF_ERR(HI_ID_VDEC, EN_ERR_LEVEL_ERROR, EN_ERR_SYS_NOTREADY)
249 /* system busy */
250 #define HI_ERR_VDEC_BUSY          HI_DEF_ERR(HI_ID_VDEC, EN_ERR_LEVEL_ERROR, EN_ERR_BUSY)
251 
252 /* bad address,  eg. used for copy_from_user & copy_to_user   */
253 #define HI_ERR_VDEC_BADADDR       HI_DEF_ERR(HI_ID_VDEC, EN_ERR_LEVEL_ERROR, EN_ERR_BADADDR)
254 
255 #ifdef __cplusplus
256 #if __cplusplus
257 }
258 #endif
259 #endif /* End of #ifdef __cplusplus */
260 
261 #endif /* End of #ifndef  __HI_COMM_VDEC_H__ */
262 
263