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 #ifndef SAMPLE_COMM_IVE_H 16 #define SAMPLE_COMM_IVE_H 17 18 #include <stdio.h> 19 #include <stdlib.h> 20 #include <string.h> 21 #include <errno.h> 22 #include <fcntl.h> 23 #include <sys/mman.h> 24 #include <sys/stat.h> 25 #include <sys/types.h> 26 #include <unistd.h> 27 #include <signal.h> 28 #include <limits.h> 29 30 #include "hi_debug.h" 31 #include "hi_comm_ive.h" 32 #include "mpi_ive.h" 33 #include "sample_comm.h" 34 35 #define VIDEO_WIDTH 352 36 #define VIDEO_HEIGHT 288 37 #define IVE_ALIGN 16 38 #define IVE_CHAR_CALW 8 39 #define IVE_CHAR_CALH 8 40 #define IVE_CHAR_NUM (IVE_CHAR_CALW * IVE_CHAR_CALH) 41 #define IVE_FILE_NAME_LEN 256 42 #define IVE_RECT_NUM 64 43 #define VPSS_CHN_NUM 2 44 #define IVE_MASK_NUM_25 25 45 #define IVE_D1_WIDTH 720 46 #define IVE_D1_HEIGHT 576 47 #define IVE_CIF_WIDTH 352 48 #define IVE_CIF_HEIGHT 288 49 50 #define IVE_QUERY_SLEEP_TIME 100 51 #define SAMPLE_IVE_FRM_TIMEOUT 20000 52 53 #define SAMPLE_ALIGN_BACK(x, a) ((a) * (((x) / (a)))) 54 55 typedef struct hiSAMPLE_IVE_SWITCH_S { 56 HI_BOOL bVenc; 57 HI_BOOL bVo; 58 } SAMPLE_IVE_SWITCH_S; 59 60 typedef struct hiSAMPLE_IVE_RECT_S { 61 POINT_S astPoint[4]; 62 } SAMPLE_IVE_RECT_S; 63 64 typedef struct hiSAMPLE_RECT_ARRAY_S { 65 HI_U16 u16Num; 66 SAMPLE_IVE_RECT_S astRect[IVE_RECT_NUM]; 67 } SAMPLE_RECT_ARRAY_S; 68 69 typedef struct hiIVE_LINEAR_DATA_S { 70 HI_S32 s32LinearNum; 71 HI_S32 s32ThreshNum; 72 POINT_S *pstLinearPoint; 73 } IVE_LINEAR_DATA_S; 74 75 typedef struct hiSAMPLE_IVE_DRAW_RECT_MSG_S { 76 VIDEO_FRAME_INFO_S stFrameInfo; 77 SAMPLE_RECT_ARRAY_S stRegion; 78 } SAMPLE_IVE_DRAW_RECT_MSG_S; 79 80 #define IVE_MMZ_FREE(phy, vir) \ 81 do { \ 82 if (((phy) != 0) && ((vir) != 0)) { \ 83 HI_MPI_SYS_MmzFree((phy), (HI_VOID *)(HI_UINTPTR_T)(vir)); \ 84 (phy) = 0; \ 85 (vir) = 0; \ 86 } \ 87 } while (0) 88 89 #define IVE_CLOSE_FILE(fp) \ 90 do { \ 91 if ((fp) != NULL) { \ 92 (void)fclose((fp)); \ 93 (fp) = NULL; \ 94 } \ 95 } while (0) 96 97 #define SAMPLE_PAUSE() \ 98 do { \ 99 printf("---------------press Enter key to exit!---------------\n"); \ 100 (void)getchar(); \ 101 } while (0) 102 #define SAMPLE_CHECK_EXPR_RET(expr, ret, fmt...) \ 103 do { \ 104 if (expr) { \ 105 SAMPLE_PRT(fmt); \ 106 return (ret); \ 107 } \ 108 } while (0) 109 110 #define SAMPLE_CHECK_EXPR_RET_VOID(expr, fmt...) \ 111 do { \ 112 if (expr) { \ 113 SAMPLE_PRT(fmt); \ 114 return; \ 115 } \ 116 } while (0) 117 118 #define SAMPLE_CHECK_EXPR_GOTO(expr, label, fmt...) \ 119 do { \ 120 if (expr) { \ 121 SAMPLE_PRT(fmt); \ 122 goto label; \ 123 } \ 124 } while (0) 125 126 #define SAMPLE_COMM_IVE_CONVERT_64BIT_ADDR(Type, Addr) (Type *)(HI_UINTPTR_T)(Addr) 127 128 129 HI_VOID SAMPLE_COMM_IVE_CheckIveMpiInit(HI_VOID); 130 131 HI_S32 SAMPLE_COMM_IVE_IveMpiExit(HI_VOID); 132 133 HI_S32 SAMPLE_COMM_IVE_ReadFile(IVE_IMAGE_S *pstImg, FILE *pFp); 134 135 HI_S32 SAMPLE_COMM_IVE_WriteFile(IVE_IMAGE_S *pstImg, FILE *pFp); 136 137 HI_U16 SAMPLE_COMM_IVE_CalcStride(HI_U32 u32Width, HI_U8 u8Align); 138 139 HI_VOID SAMPLE_COMM_IVE_BlobToRect(IVE_CCBLOB_S *pstBlob, SAMPLE_RECT_ARRAY_S *pstRect, HI_U16 u16RectMaxNum, 140 HI_U16 u16AreaThrStep, HI_U32 u32SrcWidth, HI_U32 u32SrcHeight, HI_U32 u32DstWidth, HI_U32 u32DstHeight); 141 142 HI_S32 SAMPLE_COMM_IVE_CreateImage(IVE_IMAGE_S *pstImg, IVE_IMAGE_TYPE_E enType, HI_U32 u32Width, HI_U32 u32Height); 143 144 HI_S32 SAMPLE_COMM_IVE_CreateMemInfo(IVE_MEM_INFO_S *pstMemInfo, HI_U32 u32Size); 145 146 HI_S32 SAMPLE_COMM_IVE_CreateImageByCached(IVE_IMAGE_S *pstImg, IVE_IMAGE_TYPE_E enType, HI_U32 u32Width, 147 HI_U32 u32Height); 148 149 HI_S32 SAMPLE_COMM_IVE_CreateData(IVE_DATA_S *pstData, HI_U32 u32Width, HI_U32 u32Height); 150 151 HI_S32 SAMPLE_COMM_IVE_VbInit(PIC_SIZE_E *paenSize, SIZE_S *pastSize, HI_U32 u32VpssChnNum); 152 153 HI_S32 SAMPLE_COMM_IVE_DmaImage(VIDEO_FRAME_INFO_S *pstFrameInfo, IVE_DST_IMAGE_S *pstDst, HI_BOOL bInstant); 154 155 HI_S32 SAMPLE_COMM_VGS_FillRect(VIDEO_FRAME_INFO_S *pstFrmInfo, SAMPLE_RECT_ARRAY_S *pstRect, HI_U32 u32Color); 156 157 HI_S32 SAMPLE_COMM_IVE_StartVpss(SIZE_S *pastSize, HI_U32 u32VpssChnNum); 158 159 HI_VOID SAMPLE_COMM_IVE_StopVpss(HI_U32 u32VpssChnNum); 160 161 HI_S32 SAMPLE_COMM_IVE_StartVo(HI_VOID); 162 163 HI_VOID SAMPLE_COMM_IVE_StopVo(HI_VOID); 164 165 HI_S32 SAMPLE_COMM_IVE_StartViVpssVencVo(SAMPLE_VI_CONFIG_S *pstViConfig, SAMPLE_IVE_SWITCH_S *pstSwitch, 166 PIC_SIZE_E *penExtPicSize); 167 168 HI_VOID SAMPLE_COMM_IVE_StopViVpssVencVo(SAMPLE_VI_CONFIG_S *pstViConfig, SAMPLE_IVE_SWITCH_S *pstSwitch); 169 170 #endif 171