• 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 SAMPLE_MEDIA_AI_H
17 #define SAMPLE_MEDIA_AI_H
18 
19 #include "sample_comm.h"
20 #include "list.h"
21 #include "osd_img.h"
22 
23 #ifdef __cplusplus
24 #if __cplusplus
25 extern "C" {
26 #endif
27 #endif /* End of #ifdef __cplusplus */
28 
29 #ifndef SAMPLE_PRT
30 #define SAMPLE_PRT(fmt...) \
31     do { \
32         printf("[%s]-%d: ", __FUNCTION__, __LINE__); \
33         printf(fmt); \
34     } while (0)
35 #endif
36 
37 #define APIPE0    0
38 #define APIPE1    1
39 #define APIPE2    2
40 #define APIPE3    3
41 
42 #define AIC_VPSS_GRP            0 // default use VPSS group
43 #define AIC_VPSS_ZIN_CHN        0 // default use VPSS amplification channel
44 #define AIC_VPSS_ZOUT_CHN       1 // default use VPSS narrowing channel
45 
46 #define AICSTART_VI_OUTWIDTH    1920
47 #define AICSTART_VI_OUTHEIGHT   1080
48 
49 /*
50  * 比特常量
51  * Bit constant
52  */
53 #define HI_BIT0             0x01U
54 #define HI_BIT1             0x02U
55 #define HI_BIT2             0x04U
56 #define HI_BIT3             0x08U
57 #define HI_BIT4             0x10U
58 #define HI_BIT5             0x20U
59 #define HI_BIT6             0x40U
60 #define HI_BIT7             0x80U
61 #define HI_BIT8             0x0100U
62 #define HI_BIT9             0x0200U
63 #define HI_BIT10            0x0400U
64 #define HI_BIT11            0x0800U
65 #define HI_BIT12            0x1000U
66 #define HI_BIT13            0x2000U
67 #define HI_BIT14            0x4000U
68 #define HI_BIT15            0x8000U
69 
70 /*
71  * 标记组件,该组件是否启用
72  * Flags to mark whether the component is enabled
73  */
74 #define MPP_VI      HI_BIT0
75 #define MPP_VDEC    HI_BIT1
76 #define MPP_VPSS    HI_BIT2
77 #define MPP_VENC    HI_BIT3
78 #define MPP_VO      HI_BIT5
79 
80 typedef SAMPLE_VI_CONFIG_S ViCfg;
81 typedef SAMPLE_VO_CONFIG_S VoCfg;
82 typedef VB_CONFIG_S VbCfg;
83 
84 typedef struct SampleVoModeMux {
85     HI_U32 u32WndNum;
86     HI_U32 u32Square;
87     HI_U32 u32Row;
88     HI_U32 u32Col;
89 } SampleVoModeMux;
90 
91 /*
92  * VPSS通道配置
93  * 用以设置一个通道的属性
94  *
95  * VPSS channel config.
96  * Used to set the attributes of a channel.
97  */
98 typedef struct VpssChnCfg {
99     int id; // VpssChn ID
100     VPSS_CHN_ATTR_S attr; // VpssChn attributes
101 } VpssChnCfg;
102 
103 /*
104  * VPSS参数配置
105  * 每个VpssCfg对应1个VPSS组,及1个或多个VPSS通道
106  *
107  * VPSS param config.
108  * Each VpssCfg corresponds to 1 VPSS group and 1 or more VPSS channels.
109  */
110 typedef struct VpssCfg {
111     VPSS_GRP grpId; // VpssGrp ID
112     VPSS_GRP_ATTR_S grpAttr; // VpssGrp attributes
113 
114     int chnNum; // Configure the number of chnnels used
115     VpssChnCfg chnCfgs[VPSS_MAX_PHY_CHN_NUM]; // pssChnCfg array, the first chnNum-1 elements are valid
116 } VpssCfg;
117 
118 /*
119  * MppSess集合.
120  * MppSess对应的create()函数会将需要的cfg值复制到对象中,并启动session
121  * MppSess未提供构造函数,user只能通过create()函数创建对象,并用MppSess_destroy()销毁对象
122  * MppSess中定义了当前MppSess使用的资源ID,viCfg, vpssCfg, vpssGrp, vpssChn0, vpssChn1,
123  * 这些值由create()设置,used未标识的组件的对应ID会被置为-1.这些资源ID从create()传入的
124  * 参数xxxCfg中获取,复制到对象中可简化APP使用
125  * 目前没有定义VI的channel ID,其总是会与VPSS绑定后使用,通过VPSS chn即可获得VI的数据
126  *
127  * MppSess collection.
128  * The create() function corresponding to MppSess will copy the required cfg value to the object and start the session.
129  * MppSess does not provide a constructor. The user can only create an object through the create() function
130  * and destroy the object with MppSess_destroy().
131  * MppSess defines the resource ID, viCfg, vpssCfg, vpssGrp, vpssChn0, vpssChn1 currently used by MppSess.
132  * These values are set by create(), and the corresponding IDs of components not identified by used will be set to -1.
133  * These resource IDs are obtained from the parameter xxxCfg passed in by create()
134  * and copied to the object to simplify APP use.
135  * There is currently no defined channel ID of the VI, it will always be used after being bound to the VPSS,
136  * and the VI data can be obtained through the VPSS chn.
137  */
138 typedef struct MppSess {
139     uint32_t used; // The set of enabled components, set by the create() function
140 
141     ViCfg viCfg; // Optional ViCfg
142     VpssCfg vpssCfg; // Optional VpssCfg
143 
144     VPSS_GRP vpssGrp; // VPSS group ID, -1 means that the corresponding MPP component is not started.
145     VPSS_CHN vpssChn0; // VPSS channel[0] ID, -1 means that the corresponding MPP component is not started.
146     VPSS_CHN vpssChn1; // VPSS channel[1] ID, -1 means that the corresponding MPP component is not started.
147 } MppSess;
148 
149 typedef struct AicMediaInfo {
150     VPSS_GRP vpssGrp;
151     VPSS_CHN vpssChn0;
152     VPSS_CHN vpssChn1;
153     VDEC_CHN vdecChn;
154     VENC_CHN vencChn;
155 
156     ViCfg viCfg;
157     VpssCfg vpssCfg;
158     VoCfg voCfg;
159     VbCfg vbCfg;
160 
161     // MppSess
162     MppSess *viSess; // VI(sensor)+VPSS
163     int vpssFd;
164     SIZE_S stSize;
165     PIC_SIZE_E enPicSize;
166     HI_U32  u32BlkSize;
167 
168     OsdSet *osds; // OSD set for Plug to output OSD in resFrm
169 } AicMediaInfo;
170 
171 HI_S32 SAMPLE_MEDIA_CNN_TRASH_CLASSIFY(HI_VOID);
172 HI_S32 SampleCommVoStartDevMipi(VO_DEV VoDev, VO_PUB_ATTR_S* pstPubAttr);
173 HI_S32 SAMPLE_MEDIA_HAND_CLASSIFY(HI_VOID);
174 
175 /*
176  * 初始化vi配置
177  * Init ViCfg
178  */
179 void ViCfgInit(ViCfg* self);
180 
181 /*
182  * 初始化VPSS配置
183  * Init VpssCfg
184  */
185 void VpssCfgInit(VpssCfg* self);
186 
187 /*
188  * 设置VPSS组
189  * Set up VPSS Group
190  */
191 void VpssCfgSetGrp(VpssCfg* self,
192     int grpId, const VPSS_GRP_ATTR_S* grpAttr, int maxWidth, int maxHeight);
193 
194 /*
195  * 增加一个VPSS通道
196  * Add a VPSS channel
197  */
198 VPSS_CHN_ATTR_S* VpssCfgAddChn(VpssCfg* self,
199     int chnId, const VPSS_CHN_ATTR_S* chnAttr, int width, int height);
200 
201 /*
202  * 设置VI设备信息
203  * Set VI DEV information
204  */
205 void ViCfgSetDev(ViCfg* self, int devId, WDR_MODE_E wdrMode);
206 
207 /*
208  * 设置VI的PIPE信息
209  * Set the PIPE information of the VI
210  */
211 void ViCfgSetPipe(ViCfg* self, int pipe0Id, int pipe1Id, int pipe2Id, int pipe3Id);
212 
213 /*
214  * 设置VI通道
215  * Set up the VI channel
216  */
217 void ViCfgSetChn(ViCfg* self, int chnId, PIXEL_FORMAT_E pixFormat,
218     VIDEO_FORMAT_E videoFormat, DYNAMIC_RANGE_E dynamicRange);
219 
220 /*
221  * 创建并启动{VI->VPSS}MppSess
222  * Create and start {VI->VPSS}MppSess
223  */
224 int ViVpssCreate(MppSess** sess, const ViCfg* viCfg, const VpssCfg* vpssCfg);
225 
226 /*
227  * 停止使用VpssCfg启动的VPSS
228  * Terminate VPSS started with VpssCfg
229  */
230 int VpssStop(const VpssCfg* cfg);
231 
232 /*
233  * 终止使用ViCfg启动的VI
234  * Terminate VI started with ViCfg
235  */
236 int ViStop(const ViCfg* viCfg);
237 
238 /*
239  * 启动VO到MIPI lcd通路
240  * Start VO to MIPI lcd
241  */
242 HI_S32 SampleCommVoStartMipi(SAMPLE_VO_CONFIG_S *pstVoConfig);
243 
244 /*
245  * 设置VO至MIPI通路,获取MIPI设备
246  * Set VO config to MIPI, get MIPI device
247  */
248 HI_S32 SAMPLE_VO_CONFIG_MIPI(HI_S32* mipiFD);
249 
250 /*
251  * 禁用MIPI Tx设备
252  * Disable MIPI Tx device
253  */
254 HI_S32 SAMPLE_VO_DISABLE_MIPITx(HI_S32 fd);
255 
256 /*
257  * 关闭MIPI Tx设备
258  * Close MIPI Tx device
259  */
260 HI_VOID SampleCloseMipiTxFd(HI_S32 fd);
261 
262 #ifdef __cplusplus
263 #if __cplusplus
264 }
265 #endif
266 #endif /* End of #ifdef __cplusplus */
267 
268 #endif /* End of #ifndef __SAMPLE_MEDIA_AI_H__ */
269