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 /* bit constant */ 50 #define HI_BIT0 0x01U 51 #define HI_BIT1 0x02U 52 #define HI_BIT2 0x04U 53 #define HI_BIT3 0x08U 54 #define HI_BIT4 0x10U 55 #define HI_BIT5 0x20U 56 #define HI_BIT6 0x40U 57 #define HI_BIT7 0x80U 58 #define HI_BIT8 0x0100U 59 #define HI_BIT9 0x0200U 60 #define HI_BIT10 0x0400U 61 #define HI_BIT11 0x0800U 62 #define HI_BIT12 0x1000U 63 #define HI_BIT13 0x2000U 64 #define HI_BIT14 0x4000U 65 #define HI_BIT15 0x8000U 66 67 /* Flags to mark whether the component is enabled */ 68 #define MPP_VI HI_BIT0 69 #define MPP_VDEC HI_BIT1 70 #define MPP_VPSS HI_BIT2 71 #define MPP_VENC HI_BIT3 72 #define MPP_VO HI_BIT5 73 74 typedef SAMPLE_VI_CONFIG_S ViCfg; 75 typedef SAMPLE_VO_CONFIG_S VoCfg; 76 typedef VB_CONFIG_S VbCfg; 77 78 typedef struct SampleVoModeMux { 79 HI_U32 u32WndNum; 80 HI_U32 u32Square; 81 HI_U32 u32Row; 82 HI_U32 u32Col; 83 } SampleVoModeMux; 84 85 /* 86 * VPSS channel config. 87 * Used to set the attributes of a channel. 88 */ 89 typedef struct VpssChnCfg { 90 int id; // VpssChn ID 91 VPSS_CHN_ATTR_S attr; // VpssChn attributes 92 } VpssChnCfg; 93 94 /* 95 * VPSS config. 96 * Each VpssCfg corresponds to 1 VPSS group and 1 or more VPSS channels. 97 */ 98 typedef struct VpssCfg { 99 VPSS_GRP grpId; // VpssGrp ID 100 VPSS_GRP_ATTR_S grpAttr; // VpssGrp attributes 101 102 int chnNum; // Configure the number of chnnels used 103 VpssChnCfg chnCfgs[VPSS_MAX_PHY_CHN_NUM]; // pssChnCfg array, the first chnNum-1 elements are valid 104 } VpssCfg; 105 106 /* 107 * MppSess superset. 108 * The create() function corresponding to MppSess will copy the required cfg value to the object and start the session. 109 * MppSess does not provide a constructor. The user can only create an object through the create() function 110 * and destroy the object with MppSess_destroy(). 111 * MppSess defines the resource ID, vpssGrp, vpssChn0, vpssChn1, vdecChn, vencChn currently used by MppSess. 112 * These values are set by create(), and the corresponding IDs of components not identified by used will be set to -1. 113 * These resource IDs are obtained from the parameter xxxCfg passed in by create() 114 * and copied to the object to simplify APP use. 115 * There is currently no defined channel ID of the VI, it will always be used after being bound to the VPSS, 116 * and the VI data can be obtained through the VPSS chn. 117 */ 118 typedef struct MppSess { 119 uint32_t used; // The set of enabled components, set by the create() function 120 121 ViCfg viCfg; // Optional ViCfg 122 VpssCfg vpssCfg; // Optional VpssCfg 123 124 VPSS_GRP vpssGrp; // VPSS group ID, -1 means that the corresponding MPP component is not started. 125 VPSS_CHN vpssChn0; // VPSS channel[0] ID, -1 means that the corresponding MPP component is not started. 126 VPSS_CHN vpssChn1; // VPSS channel[1] ID, -1 means that the corresponding MPP component is not started. 127 } MppSess; 128 129 typedef struct AicMediaInfo { 130 VPSS_GRP vpssGrp; 131 VPSS_CHN vpssChn0; 132 VPSS_CHN vpssChn1; 133 VDEC_CHN vdecChn; 134 VENC_CHN vencChn; 135 136 ViCfg viCfg; 137 VpssCfg vpssCfg; 138 VoCfg voCfg; 139 VbCfg vbCfg; 140 141 // MppSess 142 MppSess *viSess; // VI(sensor)+VPSS 143 int vpssFd; 144 SIZE_S stSize; 145 PIC_SIZE_E enPicSize; 146 HI_U32 u32BlkSize; 147 148 OsdSet *osds; // OSD set for Plug to output OSD in resFrm 149 } AicMediaInfo; 150 151 HI_S32 SAMPLE_MEDIA_CNN_TRASH_CLASSIFY(HI_VOID); 152 HI_S32 SampleCommVoStartDevMipi(VO_DEV VoDev, VO_PUB_ATTR_S* pstPubAttr); 153 HI_S32 SAMPLE_MEDIA_HAND_CLASSIFY(HI_VOID); 154 155 /* init ViCfg */ 156 void ViCfgInit(ViCfg* self); 157 158 /* Initialize VpssCfg */ 159 void VpssCfgInit(VpssCfg* self); 160 161 /* Set up VPSS Group */ 162 void VpssCfgSetGrp(VpssCfg* self, 163 int grpId, const VPSS_GRP_ATTR_S* grpAttr, int maxWidth, int maxHeight); 164 165 /* Add a VPSS channel */ 166 VPSS_CHN_ATTR_S* VpssCfgAddChn(VpssCfg* self, 167 int chnId, const VPSS_CHN_ATTR_S* chnAttr, int width, int height); 168 169 /* Set VI DEV information */ 170 void ViCfgSetDev(ViCfg* self, int devId, WDR_MODE_E wdrMode); 171 172 /* Set the PIPE information of the VI */ 173 void ViCfgSetPipe(ViCfg* self, int pipe0Id, int pipe1Id, int pipe2Id, int pipe3Id); 174 175 /* Set up the VI channel */ 176 void ViCfgSetChn(ViCfg* self, int chnId, PIXEL_FORMAT_E pixFormat, 177 VIDEO_FORMAT_E videoFormat, DYNAMIC_RANGE_E dynamicRange); 178 179 /* Create and start {VI->VPSS}MppSess */ 180 int ViVpssCreate(MppSess** sess, const ViCfg* viCfg, const VpssCfg* vpssCfg); 181 182 /* Terminate VPSS started with VpssCfg */ 183 int VpssStop(const VpssCfg* cfg); 184 185 /* Terminate VIs started with ViCfg */ 186 int ViStop(const ViCfg* viCfg); 187 188 /* start vo to mipi lcd */ 189 HI_S32 SampleCommVoStartMipi(SAMPLE_VO_CONFIG_S *pstVoConfig); 190 191 /* onfig mipi */ 192 HI_S32 SAMPLE_VO_CONFIG_MIPI(HI_S32* mipiFD); 193 194 /* disable mipi tx */ 195 HI_S32 SAMPLE_VO_DISABLE_MIPITx(HI_S32 fd); 196 197 /* close mipi_tx device */ 198 HI_VOID SampleCloseMipiTxFd(HI_S32 fd); 199 200 #ifdef __cplusplus 201 #if __cplusplus 202 } 203 #endif 204 #endif /* End of #ifdef __cplusplus */ 205 206 #endif /* End of #ifndef __SAMPLE_MEDIA_AI_H__ */ 207