1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright 2020 Rockchip Electronics Co. LTD
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Licensed under the Apache License, Version 2.0 (the "License");
5*4882a593Smuzhiyun * you may not use this file except in compliance with the License.
6*4882a593Smuzhiyun * You may obtain a copy of the License at
7*4882a593Smuzhiyun *
8*4882a593Smuzhiyun * http://www.apache.org/licenses/LICENSE-2.0
9*4882a593Smuzhiyun *
10*4882a593Smuzhiyun * Unless required by applicable law or agreed to in writing, software
11*4882a593Smuzhiyun * distributed under the License is distributed on an "AS IS" BASIS,
12*4882a593Smuzhiyun * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*4882a593Smuzhiyun * See the License for the specific language governing permissions and
14*4882a593Smuzhiyun * limitations under the License.
15*4882a593Smuzhiyun *
16*4882a593Smuzhiyun */
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun #include <stdio.h>
19*4882a593Smuzhiyun #include <sys/poll.h>
20*4882a593Smuzhiyun #include <errno.h>
21*4882a593Smuzhiyun #include <cstring>
22*4882a593Smuzhiyun #include <cstdlib>
23*4882a593Smuzhiyun #include <unistd.h>
24*4882a593Smuzhiyun #include <pthread.h>
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun #include "rk_defines.h"
27*4882a593Smuzhiyun #include "rk_debug.h"
28*4882a593Smuzhiyun #include "rk_mpi_vi.h"
29*4882a593Smuzhiyun #include "rk_mpi_mb.h"
30*4882a593Smuzhiyun #include "rk_mpi_sys.h"
31*4882a593Smuzhiyun #include "rk_mpi_venc.h"
32*4882a593Smuzhiyun #include "rk_mpi_vpss.h"
33*4882a593Smuzhiyun #include "rk_mpi_vo.h"
34*4882a593Smuzhiyun #include "rk_mpi_rgn.h"
35*4882a593Smuzhiyun #include "rk_common.h"
36*4882a593Smuzhiyun #include "rk_comm_rgn.h"
37*4882a593Smuzhiyun #include "rk_comm_vi.h"
38*4882a593Smuzhiyun #include "rk_comm_vo.h"
39*4882a593Smuzhiyun #include "test_common.h"
40*4882a593Smuzhiyun #include "test_comm_utils.h"
41*4882a593Smuzhiyun #include "test_comm_argparse.h"
42*4882a593Smuzhiyun #include "rk_mpi_cal.h"
43*4882a593Smuzhiyun #include "rk_mpi_mmz.h"
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun #define TEST_VENC_MAX 2
46*4882a593Smuzhiyun #define TEST_WITH_FD 0
47*4882a593Smuzhiyun #define TEST_WITH_FD_SWITCH 0
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun #undef DBG_MOD_ID
50*4882a593Smuzhiyun #define DBG_MOD_ID RK_ID_VI
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun // for 356x vo
53*4882a593Smuzhiyun #define RK356X_VO_DEV_HD0 0
54*4882a593Smuzhiyun #define RK356X_VO_DEV_HD1 1
55*4882a593Smuzhiyun #define RK356X_VOP_LAYER_CLUSTER_0 0
56*4882a593Smuzhiyun #define RK356X_VOP_LAYER_CLUSTER_1 2
57*4882a593Smuzhiyun #define RK356X_VOP_LAYER_ESMART_0 4
58*4882a593Smuzhiyun #define RK356X_VOP_LAYER_ESMART_1 5
59*4882a593Smuzhiyun #define RK356X_VOP_LAYER_SMART_0 6
60*4882a593Smuzhiyun #define RK356X_VOP_LAYER_SMART_1 7
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun #define TEST_VI_SENSOR_NUM 6
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun typedef struct _rkTestVencCfg {
65*4882a593Smuzhiyun RK_BOOL bOutDebugCfg;
66*4882a593Smuzhiyun VENC_CHN_ATTR_S stAttr;
67*4882a593Smuzhiyun RK_CHAR dstFilePath[128];
68*4882a593Smuzhiyun RK_CHAR dstFileName[128];
69*4882a593Smuzhiyun RK_S32 s32ChnId;
70*4882a593Smuzhiyun FILE *fp;
71*4882a593Smuzhiyun RK_S32 selectFd;
72*4882a593Smuzhiyun } TEST_VENC_CFG;
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun typedef struct rkVPSS_CFG_S {
75*4882a593Smuzhiyun const char *dstFilePath;
76*4882a593Smuzhiyun RK_S32 s32DevId;
77*4882a593Smuzhiyun RK_S32 s32ChnId;
78*4882a593Smuzhiyun RK_U32 u32VpssChnCnt;
79*4882a593Smuzhiyun VPSS_GRP_ATTR_S stGrpVpssAttr;
80*4882a593Smuzhiyun VPSS_CHN_ATTR_S stVpssChnAttr[VPSS_MAX_CHN_NUM];
81*4882a593Smuzhiyun } VPSS_CFG_S;
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun typedef struct rkRGN_CFG_S {
84*4882a593Smuzhiyun RGN_ATTR_S stRgnAttr;
85*4882a593Smuzhiyun RGN_CHN_ATTR_S stRgnChnAttr;
86*4882a593Smuzhiyun } RGN_CFG_S;
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun typedef enum rkTestVIMODE_E {
89*4882a593Smuzhiyun TEST_VI_MODE_VI_ONLY = 0,
90*4882a593Smuzhiyun TEST_VI_MODE_BIND_VENC = 1,
91*4882a593Smuzhiyun TEST_VI_MODE_BIND_VENC_MULTI = 2,
92*4882a593Smuzhiyun TEST_VI_MODE_BIND_VPSS_BIND_VENC = 3,
93*4882a593Smuzhiyun TEST_VI_MODE_BIND_VO = 4,
94*4882a593Smuzhiyun TEST_VI_MODE_MUTI_VI = 5,
95*4882a593Smuzhiyun } TEST_VI_MODE_E;
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun typedef struct _rkMpiVICtx {
98*4882a593Smuzhiyun RK_S32 width;
99*4882a593Smuzhiyun RK_S32 height;
100*4882a593Smuzhiyun RK_S32 devId;
101*4882a593Smuzhiyun RK_S32 pipeId;
102*4882a593Smuzhiyun RK_S32 channelId;
103*4882a593Smuzhiyun RK_S32 loopCountSet;
104*4882a593Smuzhiyun RK_S32 selectFd;
105*4882a593Smuzhiyun RK_BOOL bFreeze;
106*4882a593Smuzhiyun RK_BOOL bEnRgn;
107*4882a593Smuzhiyun RK_S32 s32RgnCnt;
108*4882a593Smuzhiyun RK_S32 rgnType;
109*4882a593Smuzhiyun RK_BOOL bUserPicEnabled;
110*4882a593Smuzhiyun RK_BOOL bGetConnecInfo;
111*4882a593Smuzhiyun RK_BOOL bGetEdid;
112*4882a593Smuzhiyun RK_BOOL bSetEdid;
113*4882a593Smuzhiyun COMPRESS_MODE_E enCompressMode;
114*4882a593Smuzhiyun VI_DEV_ATTR_S stDevAttr;
115*4882a593Smuzhiyun VI_DEV_BIND_PIPE_S stBindPipe;
116*4882a593Smuzhiyun VI_CHN_ATTR_S stChnAttr;
117*4882a593Smuzhiyun VI_SAVE_FILE_INFO_S stDebugFile;
118*4882a593Smuzhiyun VIDEO_FRAME_INFO_S stViFrame;
119*4882a593Smuzhiyun VI_CHN_STATUS_S stChnStatus;
120*4882a593Smuzhiyun VI_USERPIC_ATTR_S stUsrPic;
121*4882a593Smuzhiyun TEST_VI_MODE_E enMode;
122*4882a593Smuzhiyun const char *aEntityName;
123*4882a593Smuzhiyun // for vi
124*4882a593Smuzhiyun RGN_CFG_S stViRgn;
125*4882a593Smuzhiyun // for venc
126*4882a593Smuzhiyun TEST_VENC_CFG stVencCfg[TEST_VENC_MAX];
127*4882a593Smuzhiyun VENC_STREAM_S stFrame[TEST_VENC_MAX];
128*4882a593Smuzhiyun VPSS_CFG_S stVpssCfg;
129*4882a593Smuzhiyun // for vo
130*4882a593Smuzhiyun VO_LAYER s32VoLayer;
131*4882a593Smuzhiyun VO_DEV s32VoDev;
132*4882a593Smuzhiyun } TEST_VI_CTX_S;
133*4882a593Smuzhiyun
134*4882a593Smuzhiyun RK_U8 test_edid[2][128] = {
135*4882a593Smuzhiyun {
136*4882a593Smuzhiyun 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x49, 0x70, 0x88, 0x35, 0x01, 0x00, 0x00, 0x00,
137*4882a593Smuzhiyun 0x2d, 0x1f, 0x01, 0x03, 0x80, 0x78, 0x44, 0x78, 0x0a, 0xcf, 0x74, 0xa3, 0x57, 0x4c, 0xb0, 0x23,
138*4882a593Smuzhiyun 0x09, 0x48, 0x4c, 0x21, 0x08, 0x00, 0x61, 0x40, 0x01, 0x01, 0x81, 0x00, 0x95, 0x00, 0xa9, 0xc0,
139*4882a593Smuzhiyun 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x08, 0xe8, 0x00, 0x30, 0xf2, 0x70, 0x5a, 0x80, 0xb0, 0x58,
140*4882a593Smuzhiyun 0x8a, 0x00, 0xc4, 0x8e, 0x21, 0x00, 0x00, 0x1e, 0x02, 0x3a, 0x80, 0x18, 0x71, 0x38, 0x2d, 0x40,
141*4882a593Smuzhiyun 0x58, 0x2c, 0x45, 0x00, 0xb9, 0xa8, 0x42, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x52,
142*4882a593Smuzhiyun 0x4b, 0x2d, 0x55, 0x48, 0x44, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xfd,
143*4882a593Smuzhiyun 0x00, 0x3b, 0x46, 0x1f, 0x8c, 0x3c, 0x00, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0xa3
144*4882a593Smuzhiyun },
145*4882a593Smuzhiyun {
146*4882a593Smuzhiyun 0x02, 0x03, 0x39, 0xd2, 0x51, 0x07, 0x16, 0x14, 0x05, 0x01, 0x03, 0x12, 0x13, 0x84, 0x22, 0x1f,
147*4882a593Smuzhiyun 0x90, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x23, 0x09, 0x07, 0x07, 0x83, 0x01, 0x00, 0x00, 0x66, 0x03,
148*4882a593Smuzhiyun 0x0c, 0x00, 0x30, 0x00, 0x10, 0x67, 0xd8, 0x5d, 0xc4, 0x01, 0x78, 0xc8, 0x07, 0xe3, 0x05, 0x03,
149*4882a593Smuzhiyun 0x01, 0xe4, 0x0f, 0x00, 0xf0, 0x01, 0xe2, 0x00, 0xff, 0x08, 0xe8, 0x00, 0x30, 0xf2, 0x70, 0x5a,
150*4882a593Smuzhiyun 0x80, 0xb0, 0x58, 0x8a, 0x00, 0xc4, 0x8e, 0x21, 0x00, 0x00, 0x1e, 0x02, 0x3a, 0x80, 0x18, 0x71,
151*4882a593Smuzhiyun 0x38, 0x2d, 0x40, 0x58, 0x2c, 0x45, 0x00, 0xb9, 0xa8, 0x42, 0x00, 0x00, 0x9e, 0x00, 0x00, 0x00,
152*4882a593Smuzhiyun 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
153*4882a593Smuzhiyun 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd1
154*4882a593Smuzhiyun }
155*4882a593Smuzhiyun };
156*4882a593Smuzhiyun
create_vpss(VPSS_CFG_S * pstVpssCfg,RK_S32 s32Grp,RK_S32 s32OutChnNum)157*4882a593Smuzhiyun static RK_S32 create_vpss(VPSS_CFG_S *pstVpssCfg, RK_S32 s32Grp, RK_S32 s32OutChnNum) {
158*4882a593Smuzhiyun RK_S32 s32Ret = RK_SUCCESS;
159*4882a593Smuzhiyun VPSS_CHN VpssChn[VPSS_MAX_CHN_NUM] = { VPSS_CHN0, VPSS_CHN1, VPSS_CHN2, VPSS_CHN3 };
160*4882a593Smuzhiyun VPSS_CROP_INFO_S stCropInfo;
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun s32Ret = RK_MPI_VPSS_CreateGrp(s32Grp, &pstVpssCfg->stGrpVpssAttr);
163*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
164*4882a593Smuzhiyun return s32Ret;
165*4882a593Smuzhiyun }
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun for (RK_S32 i = 0; i < s32OutChnNum; i++) {
168*4882a593Smuzhiyun s32Ret = RK_MPI_VPSS_SetChnAttr(s32Grp, VpssChn[i], &pstVpssCfg->stVpssChnAttr[i]);
169*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
170*4882a593Smuzhiyun return s32Ret;
171*4882a593Smuzhiyun }
172*4882a593Smuzhiyun s32Ret = RK_MPI_VPSS_EnableChn(s32Grp, VpssChn[i]);
173*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
174*4882a593Smuzhiyun return s32Ret;
175*4882a593Smuzhiyun }
176*4882a593Smuzhiyun }
177*4882a593Smuzhiyun
178*4882a593Smuzhiyun s32Ret = RK_MPI_VPSS_EnableBackupFrame(s32Grp);
179*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
180*4882a593Smuzhiyun return s32Ret;
181*4882a593Smuzhiyun }
182*4882a593Smuzhiyun
183*4882a593Smuzhiyun s32Ret = RK_MPI_VPSS_StartGrp(s32Grp);
184*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
185*4882a593Smuzhiyun return s32Ret;
186*4882a593Smuzhiyun }
187*4882a593Smuzhiyun
188*4882a593Smuzhiyun return RK_SUCCESS;
189*4882a593Smuzhiyun }
190*4882a593Smuzhiyun
destory_vpss(RK_S32 s32Grp,RK_S32 s32OutChnNum)191*4882a593Smuzhiyun static RK_S32 destory_vpss(RK_S32 s32Grp, RK_S32 s32OutChnNum) {
192*4882a593Smuzhiyun RK_S32 s32Ret = RK_SUCCESS;
193*4882a593Smuzhiyun VPSS_CHN VpssChn[VPSS_MAX_CHN_NUM] = { VPSS_CHN0, VPSS_CHN1, VPSS_CHN2, VPSS_CHN3 };
194*4882a593Smuzhiyun
195*4882a593Smuzhiyun s32Ret = RK_MPI_VPSS_StopGrp(s32Grp);
196*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
197*4882a593Smuzhiyun return s32Ret;
198*4882a593Smuzhiyun }
199*4882a593Smuzhiyun
200*4882a593Smuzhiyun for (RK_S32 i = 0; i < s32OutChnNum; i++) {
201*4882a593Smuzhiyun s32Ret = RK_MPI_VPSS_DisableChn(s32Grp, VpssChn[i]);
202*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
203*4882a593Smuzhiyun return s32Ret;
204*4882a593Smuzhiyun }
205*4882a593Smuzhiyun }
206*4882a593Smuzhiyun
207*4882a593Smuzhiyun s32Ret = RK_MPI_VPSS_DisableBackupFrame(s32Grp);
208*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
209*4882a593Smuzhiyun return s32Ret;
210*4882a593Smuzhiyun }
211*4882a593Smuzhiyun
212*4882a593Smuzhiyun s32Ret = RK_MPI_VPSS_DestroyGrp(s32Grp);
213*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
214*4882a593Smuzhiyun return s32Ret;
215*4882a593Smuzhiyun }
216*4882a593Smuzhiyun
217*4882a593Smuzhiyun return RK_SUCCESS;
218*4882a593Smuzhiyun }
219*4882a593Smuzhiyun
create_venc(TEST_VI_CTX_S * ctx,RK_U32 u32Ch)220*4882a593Smuzhiyun static RK_S32 create_venc(TEST_VI_CTX_S *ctx, RK_U32 u32Ch) {
221*4882a593Smuzhiyun VENC_RECV_PIC_PARAM_S stRecvParam;
222*4882a593Smuzhiyun
223*4882a593Smuzhiyun stRecvParam.s32RecvPicNum = ctx->loopCountSet;
224*4882a593Smuzhiyun RK_MPI_VENC_CreateChn(u32Ch, &ctx->stVencCfg[u32Ch].stAttr);
225*4882a593Smuzhiyun RK_MPI_VENC_StartRecvFrame(u32Ch, &stRecvParam);
226*4882a593Smuzhiyun
227*4882a593Smuzhiyun return RK_SUCCESS;
228*4882a593Smuzhiyun }
229*4882a593Smuzhiyun
init_venc_cfg(TEST_VI_CTX_S * ctx,RK_U32 u32Ch,RK_CODEC_ID_E enType)230*4882a593Smuzhiyun void init_venc_cfg(TEST_VI_CTX_S *ctx, RK_U32 u32Ch, RK_CODEC_ID_E enType) {
231*4882a593Smuzhiyun ctx->stVencCfg[u32Ch].stAttr.stVencAttr.enType = enType;
232*4882a593Smuzhiyun ctx->stVencCfg[u32Ch].s32ChnId = u32Ch;
233*4882a593Smuzhiyun ctx->stVencCfg[u32Ch].stAttr.stVencAttr.enPixelFormat = ctx->stChnAttr.enPixelFormat;
234*4882a593Smuzhiyun ctx->stVencCfg[u32Ch].stAttr.stRcAttr.enRcMode = VENC_RC_MODE_H264CBR;
235*4882a593Smuzhiyun ctx->stVencCfg[u32Ch].stAttr.stRcAttr.stH264Cbr.u32Gop = 60;
236*4882a593Smuzhiyun ctx->stVencCfg[u32Ch].stAttr.stVencAttr.u32PicWidth = ctx->width;
237*4882a593Smuzhiyun ctx->stVencCfg[u32Ch].stAttr.stVencAttr.u32PicHeight = ctx->height;
238*4882a593Smuzhiyun ctx->stVencCfg[u32Ch].stAttr.stVencAttr.u32VirWidth = ctx->width;
239*4882a593Smuzhiyun ctx->stVencCfg[u32Ch].stAttr.stVencAttr.u32VirHeight = ctx->height;
240*4882a593Smuzhiyun ctx->stVencCfg[u32Ch].stAttr.stVencAttr.u32StreamBufCnt = 5;
241*4882a593Smuzhiyun ctx->stVencCfg[u32Ch].stAttr.stVencAttr.u32BufSize = ctx->width * ctx->height * 3 / 2;
242*4882a593Smuzhiyun }
243*4882a593Smuzhiyun
create_vo(TEST_VI_CTX_S * ctx,RK_U32 u32Ch)244*4882a593Smuzhiyun static RK_S32 create_vo(TEST_VI_CTX_S *ctx, RK_U32 u32Ch) {
245*4882a593Smuzhiyun /* Enable VO */
246*4882a593Smuzhiyun VO_PUB_ATTR_S VoPubAttr;
247*4882a593Smuzhiyun VO_VIDEO_LAYER_ATTR_S stLayerAttr;
248*4882a593Smuzhiyun RK_S32 s32Ret = RK_SUCCESS;
249*4882a593Smuzhiyun VO_CHN_ATTR_S stChnAttr;
250*4882a593Smuzhiyun VO_LAYER VoLayer = ctx->s32VoLayer;
251*4882a593Smuzhiyun VO_DEV VoDev = ctx->s32VoDev;
252*4882a593Smuzhiyun
253*4882a593Smuzhiyun RK_MPI_VO_DisableLayer(VoLayer);
254*4882a593Smuzhiyun RK_MPI_VO_DisableLayer(RK356X_VOP_LAYER_ESMART_0);
255*4882a593Smuzhiyun RK_MPI_VO_DisableLayer(RK356X_VOP_LAYER_ESMART_1);
256*4882a593Smuzhiyun RK_MPI_VO_DisableLayer(RK356X_VOP_LAYER_SMART_0);
257*4882a593Smuzhiyun RK_MPI_VO_DisableLayer(RK356X_VOP_LAYER_SMART_1);
258*4882a593Smuzhiyun RK_MPI_VO_Disable(VoDev);
259*4882a593Smuzhiyun
260*4882a593Smuzhiyun memset(&VoPubAttr, 0, sizeof(VO_PUB_ATTR_S));
261*4882a593Smuzhiyun memset(&stLayerAttr, 0, sizeof(VO_VIDEO_LAYER_ATTR_S));
262*4882a593Smuzhiyun
263*4882a593Smuzhiyun stLayerAttr.enPixFormat = RK_FMT_RGB888;
264*4882a593Smuzhiyun stLayerAttr.stDispRect.s32X = 0;
265*4882a593Smuzhiyun stLayerAttr.stDispRect.s32Y = 0;
266*4882a593Smuzhiyun stLayerAttr.u32DispFrmRt = 30;
267*4882a593Smuzhiyun stLayerAttr.stDispRect.u32Width = 1920;
268*4882a593Smuzhiyun stLayerAttr.stDispRect.u32Height = 1080;
269*4882a593Smuzhiyun stLayerAttr.stImageSize.u32Width = 1920;
270*4882a593Smuzhiyun stLayerAttr.stImageSize.u32Height = 1080;
271*4882a593Smuzhiyun
272*4882a593Smuzhiyun s32Ret = RK_MPI_VO_GetPubAttr(VoDev, &VoPubAttr);
273*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
274*4882a593Smuzhiyun return s32Ret;
275*4882a593Smuzhiyun }
276*4882a593Smuzhiyun
277*4882a593Smuzhiyun VoPubAttr.enIntfType = VO_INTF_HDMI;
278*4882a593Smuzhiyun VoPubAttr.enIntfSync = VO_OUTPUT_DEFAULT;
279*4882a593Smuzhiyun
280*4882a593Smuzhiyun s32Ret = RK_MPI_VO_SetPubAttr(VoDev, &VoPubAttr);
281*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
282*4882a593Smuzhiyun return s32Ret;
283*4882a593Smuzhiyun }
284*4882a593Smuzhiyun s32Ret = RK_MPI_VO_Enable(VoDev);
285*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
286*4882a593Smuzhiyun return s32Ret;
287*4882a593Smuzhiyun }
288*4882a593Smuzhiyun
289*4882a593Smuzhiyun s32Ret = RK_MPI_VO_BindLayer(VoLayer, VoDev, VO_LAYER_MODE_GRAPHIC);
290*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
291*4882a593Smuzhiyun RK_LOGE("RK_MPI_VO_BindLayer failed,s32Ret:%d\n", s32Ret);
292*4882a593Smuzhiyun return RK_FAILURE;
293*4882a593Smuzhiyun }
294*4882a593Smuzhiyun
295*4882a593Smuzhiyun s32Ret = RK_MPI_VO_SetLayerAttr(VoLayer, &stLayerAttr);
296*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
297*4882a593Smuzhiyun RK_LOGE("RK_MPI_VO_SetLayerAttr failed,s32Ret:%d\n", s32Ret);
298*4882a593Smuzhiyun return RK_FAILURE;
299*4882a593Smuzhiyun }
300*4882a593Smuzhiyun
301*4882a593Smuzhiyun s32Ret = RK_MPI_VO_EnableLayer(VoLayer);
302*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
303*4882a593Smuzhiyun RK_LOGE("RK_MPI_VO_EnableLayer failed,s32Ret:%d\n", s32Ret);
304*4882a593Smuzhiyun return RK_FAILURE;
305*4882a593Smuzhiyun }
306*4882a593Smuzhiyun
307*4882a593Smuzhiyun stChnAttr.stRect.s32X = 0;
308*4882a593Smuzhiyun stChnAttr.stRect.s32Y = 0;
309*4882a593Smuzhiyun stChnAttr.stRect.u32Width = stLayerAttr.stImageSize.u32Width;
310*4882a593Smuzhiyun stChnAttr.stRect.u32Height = stLayerAttr.stImageSize.u32Height;
311*4882a593Smuzhiyun stChnAttr.u32Priority = 0;
312*4882a593Smuzhiyun stChnAttr.u32FgAlpha = 128;
313*4882a593Smuzhiyun stChnAttr.u32BgAlpha = 0;
314*4882a593Smuzhiyun
315*4882a593Smuzhiyun s32Ret = RK_MPI_VO_SetChnAttr(VoLayer, u32Ch, &stChnAttr);
316*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
317*4882a593Smuzhiyun RK_LOGE("set chn Attr failed,s32Ret:%d\n", s32Ret);
318*4882a593Smuzhiyun return RK_FAILURE;
319*4882a593Smuzhiyun }
320*4882a593Smuzhiyun
321*4882a593Smuzhiyun return s32Ret;
322*4882a593Smuzhiyun }
323*4882a593Smuzhiyun
test_vi_poll_event(RK_S32 timeoutMsec,RK_S32 fd)324*4882a593Smuzhiyun RK_S32 test_vi_poll_event(RK_S32 timeoutMsec, RK_S32 fd) {
325*4882a593Smuzhiyun RK_S32 num_fds = 1;
326*4882a593Smuzhiyun struct pollfd pollFds[num_fds];
327*4882a593Smuzhiyun RK_S32 ret = 0;
328*4882a593Smuzhiyun
329*4882a593Smuzhiyun RK_ASSERT(fd > 0);
330*4882a593Smuzhiyun memset(pollFds, 0, sizeof(pollFds));
331*4882a593Smuzhiyun pollFds[0].fd = fd;
332*4882a593Smuzhiyun pollFds[0].events = (POLLPRI | POLLIN | POLLERR | POLLNVAL | POLLHUP);
333*4882a593Smuzhiyun
334*4882a593Smuzhiyun ret = poll(pollFds, num_fds, timeoutMsec);
335*4882a593Smuzhiyun
336*4882a593Smuzhiyun if (ret > 0 && (pollFds[0].revents & (POLLERR | POLLNVAL | POLLHUP))) {
337*4882a593Smuzhiyun RK_LOGE("fd:%d polled error", fd);
338*4882a593Smuzhiyun return -1;
339*4882a593Smuzhiyun }
340*4882a593Smuzhiyun
341*4882a593Smuzhiyun return ret;
342*4882a593Smuzhiyun }
343*4882a593Smuzhiyun
readFromPic(TEST_VI_CTX_S * ctx,VIDEO_FRAME_S * buffer)344*4882a593Smuzhiyun static RK_S32 readFromPic(TEST_VI_CTX_S *ctx, VIDEO_FRAME_S *buffer) {
345*4882a593Smuzhiyun FILE *fp = NULL;
346*4882a593Smuzhiyun RK_S32 s32Ret = RK_SUCCESS;
347*4882a593Smuzhiyun MB_BLK srcBlk = MB_INVALID_HANDLE;
348*4882a593Smuzhiyun PIC_BUF_ATTR_S stPicBufAttr;
349*4882a593Smuzhiyun MB_PIC_CAL_S stMbPicCalResult;
350*4882a593Smuzhiyun const char *user_picture_path = "/data/test_vi_user.yuv";
351*4882a593Smuzhiyun
352*4882a593Smuzhiyun stPicBufAttr.u32Width = ctx->width;
353*4882a593Smuzhiyun stPicBufAttr.u32Height = ctx->height;
354*4882a593Smuzhiyun stPicBufAttr.enCompMode = COMPRESS_MODE_NONE;
355*4882a593Smuzhiyun stPicBufAttr.enPixelFormat = RK_FMT_YUV420SP;
356*4882a593Smuzhiyun s32Ret = RK_MPI_CAL_VGS_GetPicBufferSize(&stPicBufAttr, &stMbPicCalResult);
357*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
358*4882a593Smuzhiyun RK_LOGE("get picture buffer size failed. err 0x%x", s32Ret);
359*4882a593Smuzhiyun return RK_NULL;
360*4882a593Smuzhiyun }
361*4882a593Smuzhiyun
362*4882a593Smuzhiyun RK_MPI_MMZ_Alloc(&srcBlk, stMbPicCalResult.u32MBSize, RK_MMZ_ALLOC_CACHEABLE);
363*4882a593Smuzhiyun
364*4882a593Smuzhiyun fp = fopen(user_picture_path, "rb");
365*4882a593Smuzhiyun if (NULL == fp) {
366*4882a593Smuzhiyun RK_LOGE("open %s fail", user_picture_path);
367*4882a593Smuzhiyun return RK_FAILURE;
368*4882a593Smuzhiyun } else {
369*4882a593Smuzhiyun fread(RK_MPI_MB_Handle2VirAddr(srcBlk), 1 , stMbPicCalResult.u32MBSize, fp);
370*4882a593Smuzhiyun fclose(fp);
371*4882a593Smuzhiyun RK_MPI_SYS_MmzFlushCache(srcBlk, RK_FALSE);
372*4882a593Smuzhiyun RK_LOGD("open %s success", user_picture_path);
373*4882a593Smuzhiyun }
374*4882a593Smuzhiyun
375*4882a593Smuzhiyun buffer->u32Width = ctx->width;
376*4882a593Smuzhiyun buffer->u32Height = ctx->height;
377*4882a593Smuzhiyun buffer->u32VirWidth = ctx->width;
378*4882a593Smuzhiyun buffer->u32VirHeight = ctx->height;
379*4882a593Smuzhiyun buffer->enPixelFormat = RK_FMT_YUV420SP;
380*4882a593Smuzhiyun buffer->u32TimeRef = 0;
381*4882a593Smuzhiyun buffer->u64PTS = 0;
382*4882a593Smuzhiyun buffer->enCompressMode = COMPRESS_MODE_NONE;
383*4882a593Smuzhiyun buffer->pMbBlk = srcBlk;
384*4882a593Smuzhiyun
385*4882a593Smuzhiyun RK_LOGD("readFromPic width = %d, height = %d size = %d pixFormat = %d",
386*4882a593Smuzhiyun ctx->width, ctx->height, stMbPicCalResult.u32MBSize, RK_FMT_YUV420SP);
387*4882a593Smuzhiyun return RK_SUCCESS;
388*4882a593Smuzhiyun }
389*4882a593Smuzhiyun
create_rgn(TEST_VI_CTX_S * ctx)390*4882a593Smuzhiyun static RK_S32 create_rgn(TEST_VI_CTX_S *ctx) {
391*4882a593Smuzhiyun RK_S32 i;
392*4882a593Smuzhiyun RK_S32 s32Ret = RK_SUCCESS;
393*4882a593Smuzhiyun RGN_ATTR_S stRgnAttr;
394*4882a593Smuzhiyun RGN_CHN_ATTR_S stRgnChnAttr;
395*4882a593Smuzhiyun RGN_HANDLE RgnHandle = 0;
396*4882a593Smuzhiyun MPP_CHN_S stMppChn;
397*4882a593Smuzhiyun RGN_TYPE_E rgnType = (RGN_TYPE_E)ctx->rgnType;
398*4882a593Smuzhiyun
399*4882a593Smuzhiyun /****************************************
400*4882a593Smuzhiyun step 1: create overlay regions
401*4882a593Smuzhiyun ****************************************/
402*4882a593Smuzhiyun for (i = 0; i < ctx->s32RgnCnt; i++) {
403*4882a593Smuzhiyun ctx->stViRgn.stRgnAttr.unAttr.stOverlay.u32ClutNum = 0;
404*4882a593Smuzhiyun ctx->stViRgn.stRgnAttr.unAttr.stOverlay.stSize.u32Width = 128;
405*4882a593Smuzhiyun ctx->stViRgn.stRgnAttr.unAttr.stOverlay.stSize.u32Height = 128;
406*4882a593Smuzhiyun RgnHandle = i;
407*4882a593Smuzhiyun s32Ret = RK_MPI_RGN_Create(RgnHandle, &ctx->stViRgn.stRgnAttr);
408*4882a593Smuzhiyun if (RK_SUCCESS != s32Ret) {
409*4882a593Smuzhiyun RK_LOGE("RK_MPI_RGN_Create (%d) failed with %#x!", RgnHandle, s32Ret);
410*4882a593Smuzhiyun RK_MPI_RGN_Destroy(RgnHandle);
411*4882a593Smuzhiyun return RK_FAILURE;
412*4882a593Smuzhiyun }
413*4882a593Smuzhiyun RK_LOGI("The handle: %d, create success!", RgnHandle);
414*4882a593Smuzhiyun }
415*4882a593Smuzhiyun
416*4882a593Smuzhiyun /*********************************************
417*4882a593Smuzhiyun step 2: display overlay regions to vi
418*4882a593Smuzhiyun *********************************************/
419*4882a593Smuzhiyun for (i = 0; i < ctx->s32RgnCnt; i++) {
420*4882a593Smuzhiyun stMppChn.enModId = RK_ID_VI;
421*4882a593Smuzhiyun stMppChn.s32DevId = ctx->devId;
422*4882a593Smuzhiyun stMppChn.s32ChnId = ctx->channelId;
423*4882a593Smuzhiyun RgnHandle = i;
424*4882a593Smuzhiyun
425*4882a593Smuzhiyun memset(&stRgnChnAttr, 0, sizeof(stRgnChnAttr));
426*4882a593Smuzhiyun stRgnChnAttr.bShow = RK_TRUE;
427*4882a593Smuzhiyun stRgnChnAttr.enType = rgnType;
428*4882a593Smuzhiyun
429*4882a593Smuzhiyun BITMAP_S stBitmap;
430*4882a593Smuzhiyun switch (rgnType) {
431*4882a593Smuzhiyun case COVER_RGN: {
432*4882a593Smuzhiyun RGN_CHN_ATTR_S stCoverChnAttr;
433*4882a593Smuzhiyun stCoverChnAttr.bShow = RK_TRUE;
434*4882a593Smuzhiyun stCoverChnAttr.enType = COVER_RGN;
435*4882a593Smuzhiyun stCoverChnAttr.unChnAttr.stCoverChn.stRect.s32X = 128 * i;
436*4882a593Smuzhiyun stCoverChnAttr.unChnAttr.stCoverChn.stRect.s32Y = 128 * i;
437*4882a593Smuzhiyun stCoverChnAttr.unChnAttr.stCoverChn.stRect.u32Width = 128;
438*4882a593Smuzhiyun stCoverChnAttr.unChnAttr.stCoverChn.stRect.u32Height = 128;
439*4882a593Smuzhiyun stCoverChnAttr.unChnAttr.stCoverChn.u32Color = 0xffffff; // white
440*4882a593Smuzhiyun stCoverChnAttr.unChnAttr.stCoverChn.enCoordinate = RGN_ABS_COOR;
441*4882a593Smuzhiyun stCoverChnAttr.unChnAttr.stCoverChn.u32Layer = i;
442*4882a593Smuzhiyun
443*4882a593Smuzhiyun s32Ret = RK_MPI_RGN_AttachToChn(RgnHandle, &stMppChn, &stCoverChnAttr);
444*4882a593Smuzhiyun if (RK_SUCCESS != s32Ret) {
445*4882a593Smuzhiyun RK_LOGE("failed with %#x!", s32Ret);
446*4882a593Smuzhiyun goto __EXIT;
447*4882a593Smuzhiyun }
448*4882a593Smuzhiyun s32Ret = RK_MPI_RGN_GetDisplayAttr(RgnHandle, &stMppChn, &stCoverChnAttr);
449*4882a593Smuzhiyun if (RK_SUCCESS != s32Ret) {
450*4882a593Smuzhiyun RK_LOGE("failed with %#x!", s32Ret);
451*4882a593Smuzhiyun goto __EXIT;
452*4882a593Smuzhiyun }
453*4882a593Smuzhiyun stCoverChnAttr.unChnAttr.stCoverChn.stRect.s32X = 128 * i;
454*4882a593Smuzhiyun stCoverChnAttr.unChnAttr.stCoverChn.stRect.s32Y = 128 * i;
455*4882a593Smuzhiyun stCoverChnAttr.unChnAttr.stCoverChn.stRect.u32Width = 128;
456*4882a593Smuzhiyun stCoverChnAttr.unChnAttr.stCoverChn.stRect.u32Height = 128;
457*4882a593Smuzhiyun stCoverChnAttr.unChnAttr.stCoverChn.u32Color = 0x0000ff; // blue
458*4882a593Smuzhiyun stCoverChnAttr.unChnAttr.stCoverChn.enCoordinate = RGN_ABS_COOR;
459*4882a593Smuzhiyun stCoverChnAttr.unChnAttr.stCoverChn.u32Layer = i;
460*4882a593Smuzhiyun // change cover channel attribute below.
461*4882a593Smuzhiyun s32Ret = RK_MPI_RGN_SetDisplayAttr(RgnHandle, &stMppChn, &stCoverChnAttr);
462*4882a593Smuzhiyun if (RK_SUCCESS != s32Ret) {
463*4882a593Smuzhiyun RK_LOGE("failed with %#x!", s32Ret);
464*4882a593Smuzhiyun goto __EXIT;
465*4882a593Smuzhiyun }
466*4882a593Smuzhiyun
467*4882a593Smuzhiyun RK_LOGI("the cover region:%d to <%d, %d, %d, %d>",
468*4882a593Smuzhiyun RgnHandle,
469*4882a593Smuzhiyun stCoverChnAttr.unChnAttr.stCoverChn.stRect.s32X,
470*4882a593Smuzhiyun stCoverChnAttr.unChnAttr.stCoverChn.stRect.s32Y,
471*4882a593Smuzhiyun stCoverChnAttr.unChnAttr.stCoverChn.stRect.u32Width,
472*4882a593Smuzhiyun stCoverChnAttr.unChnAttr.stCoverChn.stRect.u32Height);
473*4882a593Smuzhiyun } break;
474*4882a593Smuzhiyun case MOSAIC_RGN: {
475*4882a593Smuzhiyun RGN_CHN_ATTR_S stMoscaiChnAttr;
476*4882a593Smuzhiyun stMoscaiChnAttr.bShow = RK_TRUE;
477*4882a593Smuzhiyun stMoscaiChnAttr.enType = MOSAIC_RGN;
478*4882a593Smuzhiyun stMoscaiChnAttr.unChnAttr.stMosaicChn.stRect.s32X = 128 * i;
479*4882a593Smuzhiyun stMoscaiChnAttr.unChnAttr.stMosaicChn.stRect.s32Y = 128 * i;
480*4882a593Smuzhiyun stMoscaiChnAttr.unChnAttr.stMosaicChn.stRect.u32Width = 128;
481*4882a593Smuzhiyun stMoscaiChnAttr.unChnAttr.stMosaicChn.stRect.u32Height = 128;
482*4882a593Smuzhiyun stMoscaiChnAttr.unChnAttr.stMosaicChn.enBlkSize = MOSAIC_BLK_SIZE_8;
483*4882a593Smuzhiyun stMoscaiChnAttr.unChnAttr.stMosaicChn.u32Layer = i;
484*4882a593Smuzhiyun
485*4882a593Smuzhiyun s32Ret = RK_MPI_RGN_AttachToChn(RgnHandle, &stMppChn, &stMoscaiChnAttr);
486*4882a593Smuzhiyun if (RK_SUCCESS != s32Ret) {
487*4882a593Smuzhiyun RK_LOGE("failed with %#x!", s32Ret);
488*4882a593Smuzhiyun goto __EXIT;
489*4882a593Smuzhiyun }
490*4882a593Smuzhiyun s32Ret = RK_MPI_RGN_GetDisplayAttr(RgnHandle, &stMppChn, &stMoscaiChnAttr);
491*4882a593Smuzhiyun if (RK_SUCCESS != s32Ret) {
492*4882a593Smuzhiyun RK_LOGE("failed with %#x!", s32Ret);
493*4882a593Smuzhiyun goto __EXIT;
494*4882a593Smuzhiyun }
495*4882a593Smuzhiyun
496*4882a593Smuzhiyun stMoscaiChnAttr.unChnAttr.stMosaicChn.stRect.s32X = 128 * i;
497*4882a593Smuzhiyun stMoscaiChnAttr.unChnAttr.stMosaicChn.stRect.s32Y = 128 * i;
498*4882a593Smuzhiyun stMoscaiChnAttr.unChnAttr.stMosaicChn.stRect.u32Width = 128;
499*4882a593Smuzhiyun stMoscaiChnAttr.unChnAttr.stMosaicChn.stRect.u32Height = 128;
500*4882a593Smuzhiyun stMoscaiChnAttr.unChnAttr.stMosaicChn.enBlkSize = MOSAIC_BLK_SIZE_8;
501*4882a593Smuzhiyun stMoscaiChnAttr.unChnAttr.stMosaicChn.u32Layer = i;
502*4882a593Smuzhiyun
503*4882a593Smuzhiyun // change mosaic channel attribute below.
504*4882a593Smuzhiyun s32Ret = RK_MPI_RGN_SetDisplayAttr(RgnHandle, &stMppChn, &stMoscaiChnAttr);
505*4882a593Smuzhiyun if (RK_SUCCESS != s32Ret) {
506*4882a593Smuzhiyun RK_LOGE("failed with %#x!", s32Ret);
507*4882a593Smuzhiyun goto __EXIT;
508*4882a593Smuzhiyun }
509*4882a593Smuzhiyun RK_LOGI("the mosaic region:%d to <%d, %d, %d, %d>",
510*4882a593Smuzhiyun RgnHandle,
511*4882a593Smuzhiyun stMoscaiChnAttr.unChnAttr.stMosaicChn.stRect.s32X,
512*4882a593Smuzhiyun stMoscaiChnAttr.unChnAttr.stMosaicChn.stRect.s32Y,
513*4882a593Smuzhiyun stMoscaiChnAttr.unChnAttr.stMosaicChn.stRect.u32Width,
514*4882a593Smuzhiyun stMoscaiChnAttr.unChnAttr.stMosaicChn.stRect.u32Height);
515*4882a593Smuzhiyun } break;
516*4882a593Smuzhiyun default:
517*4882a593Smuzhiyun break;
518*4882a593Smuzhiyun }
519*4882a593Smuzhiyun }
520*4882a593Smuzhiyun
521*4882a593Smuzhiyun return RK_SUCCESS;
522*4882a593Smuzhiyun __EXIT:
523*4882a593Smuzhiyun for (i = 0; i < ctx->s32RgnCnt; i++) {
524*4882a593Smuzhiyun stMppChn.enModId = RK_ID_VI;
525*4882a593Smuzhiyun stMppChn.s32DevId = ctx->devId;
526*4882a593Smuzhiyun stMppChn.s32ChnId = ctx->channelId;
527*4882a593Smuzhiyun RgnHandle = i;
528*4882a593Smuzhiyun s32Ret = RK_MPI_RGN_DetachFromChn(RgnHandle, &stMppChn);
529*4882a593Smuzhiyun if (RK_SUCCESS != s32Ret) {
530*4882a593Smuzhiyun RK_LOGE("RK_MPI_RGN_DetachFrmChn (%d) failed with %#x!", RgnHandle, s32Ret);
531*4882a593Smuzhiyun return RK_FAILURE;
532*4882a593Smuzhiyun }
533*4882a593Smuzhiyun }
534*4882a593Smuzhiyun return RK_FAILURE;
535*4882a593Smuzhiyun }
536*4882a593Smuzhiyun
destory_rgn(TEST_VI_CTX_S * ctx)537*4882a593Smuzhiyun static RK_S32 destory_rgn(TEST_VI_CTX_S *ctx) {
538*4882a593Smuzhiyun RK_S32 i;
539*4882a593Smuzhiyun RK_S32 s32Ret = RK_SUCCESS;
540*4882a593Smuzhiyun RGN_HANDLE RgnHandle = 0;
541*4882a593Smuzhiyun
542*4882a593Smuzhiyun for (RK_S32 i = 0; i < ctx->s32RgnCnt; i++) {
543*4882a593Smuzhiyun RgnHandle = i;
544*4882a593Smuzhiyun s32Ret = RK_MPI_RGN_Destroy(RgnHandle);
545*4882a593Smuzhiyun if (RK_SUCCESS != s32Ret) {
546*4882a593Smuzhiyun RK_LOGE("RK_MPI_RGN_Destroy (%d) failed with %#x!", RgnHandle, s32Ret);
547*4882a593Smuzhiyun }
548*4882a593Smuzhiyun RK_LOGI("Destory handle:%d success", RgnHandle);
549*4882a593Smuzhiyun }
550*4882a593Smuzhiyun
551*4882a593Smuzhiyun RK_LOGD("vi RK_MPI_RGN_Destroy OK");
552*4882a593Smuzhiyun return RK_SUCCESS;
553*4882a593Smuzhiyun }
554*4882a593Smuzhiyun
test_vi_hdmi_rx_infomation(TEST_VI_CTX_S * ctx)555*4882a593Smuzhiyun static RK_S32 test_vi_hdmi_rx_infomation(TEST_VI_CTX_S *ctx) {
556*4882a593Smuzhiyun RK_S32 s32Ret = RK_FAILURE;
557*4882a593Smuzhiyun
558*4882a593Smuzhiyun /* test get connect info before enable chn(need after RK_MPI_VI_SetChnAttr)*/
559*4882a593Smuzhiyun if (ctx->bGetConnecInfo) {
560*4882a593Smuzhiyun VI_CONNECT_INFO_S stConnectInfo;
561*4882a593Smuzhiyun s32Ret = RK_MPI_VI_GetChnConnectInfo(ctx->pipeId, ctx->channelId, &stConnectInfo);
562*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_GetChnConnectInfo %x, w:%d,h:%d,fmt:0x%x,connect:%d", s32Ret,
563*4882a593Smuzhiyun stConnectInfo.u32Width, stConnectInfo.u32Height,
564*4882a593Smuzhiyun stConnectInfo.enPixFmt, stConnectInfo.enConnect);
565*4882a593Smuzhiyun }
566*4882a593Smuzhiyun if (ctx->bGetEdid) {
567*4882a593Smuzhiyun VI_EDID_S stEdid;
568*4882a593Smuzhiyun memset(&stEdid, 0, sizeof(VI_EDID_S));
569*4882a593Smuzhiyun stEdid.u32Blocks = 3;
570*4882a593Smuzhiyun stEdid.pu8Edid = (RK_U8 *)calloc(128 * stEdid.u32Blocks, 1);
571*4882a593Smuzhiyun s32Ret = RK_MPI_VI_GetChnEdid(ctx->pipeId, ctx->channelId, &stEdid);
572*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_GetChnEdid %x, stEdid.u32Blocks=%d "
573*4882a593Smuzhiyun "edid[0]:0x%x,edid[1]:0x%x,edid[2]:0x%x,edid[3]:0x%x,edid[126]:0x%x edid[127]:0x%x",
574*4882a593Smuzhiyun s32Ret, stEdid.u32Blocks,
575*4882a593Smuzhiyun stEdid.pu8Edid[0], stEdid.pu8Edid[1],
576*4882a593Smuzhiyun stEdid.pu8Edid[2], stEdid.pu8Edid[3],
577*4882a593Smuzhiyun stEdid.pu8Edid[126], stEdid.pu8Edid[127]);
578*4882a593Smuzhiyun free(stEdid.pu8Edid);
579*4882a593Smuzhiyun }
580*4882a593Smuzhiyun if (ctx->bSetEdid) {
581*4882a593Smuzhiyun VI_EDID_S stEdid;
582*4882a593Smuzhiyun memset(&stEdid, 0, sizeof(VI_EDID_S));
583*4882a593Smuzhiyun stEdid.u32Blocks = 2;
584*4882a593Smuzhiyun stEdid.pu8Edid = (RK_U8 *)test_edid;
585*4882a593Smuzhiyun s32Ret = RK_MPI_VI_SetChnEdid(ctx->pipeId, ctx->channelId, &stEdid);
586*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_SetChnEdid %x, edid[0]:0x%x,edid[1]:0x%x,edid[2]:0x%x,edid[3]:0x%x,"
587*4882a593Smuzhiyun "edid[126]:0x%x edid[127]:0x%x",
588*4882a593Smuzhiyun s32Ret,
589*4882a593Smuzhiyun stEdid.pu8Edid[0], stEdid.pu8Edid[1],
590*4882a593Smuzhiyun stEdid.pu8Edid[2], stEdid.pu8Edid[3],
591*4882a593Smuzhiyun stEdid.pu8Edid[126], stEdid.pu8Edid[127]);
592*4882a593Smuzhiyun }
593*4882a593Smuzhiyun
594*4882a593Smuzhiyun return s32Ret;
595*4882a593Smuzhiyun }
596*4882a593Smuzhiyun
597*4882a593Smuzhiyun
test_vi_init(TEST_VI_CTX_S * ctx)598*4882a593Smuzhiyun static RK_S32 test_vi_init(TEST_VI_CTX_S *ctx) {
599*4882a593Smuzhiyun RK_S32 s32Ret = RK_FAILURE;
600*4882a593Smuzhiyun
601*4882a593Smuzhiyun // 0. get dev config status
602*4882a593Smuzhiyun s32Ret = RK_MPI_VI_GetDevAttr(ctx->devId, &ctx->stDevAttr);
603*4882a593Smuzhiyun if (s32Ret == RK_ERR_VI_NOT_CONFIG) {
604*4882a593Smuzhiyun // 0-1.config dev
605*4882a593Smuzhiyun s32Ret = RK_MPI_VI_SetDevAttr(ctx->devId, &ctx->stDevAttr);
606*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
607*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_SetDevAttr %x", s32Ret);
608*4882a593Smuzhiyun goto __FAILED;
609*4882a593Smuzhiyun }
610*4882a593Smuzhiyun } else {
611*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_SetDevAttr already");
612*4882a593Smuzhiyun }
613*4882a593Smuzhiyun // 1.get dev enable status
614*4882a593Smuzhiyun s32Ret = RK_MPI_VI_GetDevIsEnable(ctx->devId);
615*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
616*4882a593Smuzhiyun // 1-2.enable dev
617*4882a593Smuzhiyun s32Ret = RK_MPI_VI_EnableDev(ctx->devId);
618*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
619*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_EnableDev %x", s32Ret);
620*4882a593Smuzhiyun goto __FAILED;
621*4882a593Smuzhiyun }
622*4882a593Smuzhiyun // 1-3.bind dev/pipe
623*4882a593Smuzhiyun ctx->stBindPipe.u32Num = ctx->pipeId;
624*4882a593Smuzhiyun ctx->stBindPipe.PipeId[0] = ctx->pipeId;
625*4882a593Smuzhiyun s32Ret = RK_MPI_VI_SetDevBindPipe(ctx->devId, &ctx->stBindPipe);
626*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
627*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_SetDevBindPipe %x", s32Ret);
628*4882a593Smuzhiyun goto __FAILED;
629*4882a593Smuzhiyun }
630*4882a593Smuzhiyun } else {
631*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_EnableDev already");
632*4882a593Smuzhiyun }
633*4882a593Smuzhiyun // 2.config channel
634*4882a593Smuzhiyun ctx->stChnAttr.stSize.u32Width = ctx->width;
635*4882a593Smuzhiyun ctx->stChnAttr.stSize.u32Height = ctx->height;
636*4882a593Smuzhiyun ctx->stChnAttr.enCompressMode = ctx->enCompressMode;
637*4882a593Smuzhiyun s32Ret = RK_MPI_VI_SetChnAttr(ctx->pipeId, ctx->channelId, &ctx->stChnAttr);
638*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
639*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_SetChnAttr %x", s32Ret);
640*4882a593Smuzhiyun goto __FAILED;
641*4882a593Smuzhiyun }
642*4882a593Smuzhiyun
643*4882a593Smuzhiyun /* test user picture */
644*4882a593Smuzhiyun if (ctx->bUserPicEnabled) {
645*4882a593Smuzhiyun ctx->stUsrPic.enUsrPicMode = VI_USERPIC_MODE_BGC;
646*4882a593Smuzhiyun // ctx->stUsrPic.enUsrPicMode = VI_USERPIC_MODE_PIC;
647*4882a593Smuzhiyun
648*4882a593Smuzhiyun if (ctx->stUsrPic.enUsrPicMode == VI_USERPIC_MODE_PIC) {
649*4882a593Smuzhiyun s32Ret = readFromPic(ctx, &ctx->stUsrPic.unUsrPic.stUsrPicFrm.stVFrame);
650*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
651*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_SetUserPic fail:%x", s32Ret);
652*4882a593Smuzhiyun goto __FAILED;
653*4882a593Smuzhiyun }
654*4882a593Smuzhiyun } else if (ctx->stUsrPic.enUsrPicMode == VI_USERPIC_MODE_BGC) {
655*4882a593Smuzhiyun /* set background color */
656*4882a593Smuzhiyun ctx->stUsrPic.unUsrPic.stUsrPicBg.u32BgColor = RGB(0, 0, 128);
657*4882a593Smuzhiyun }
658*4882a593Smuzhiyun
659*4882a593Smuzhiyun s32Ret = RK_MPI_VI_SetUserPic(ctx->pipeId, ctx->channelId, &ctx->stUsrPic);
660*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
661*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_SetUserPic fail:%x", s32Ret);
662*4882a593Smuzhiyun goto __FAILED;
663*4882a593Smuzhiyun }
664*4882a593Smuzhiyun
665*4882a593Smuzhiyun s32Ret = RK_MPI_VI_EnableUserPic(ctx->pipeId, ctx->channelId);
666*4882a593Smuzhiyun }
667*4882a593Smuzhiyun
668*4882a593Smuzhiyun test_vi_hdmi_rx_infomation(ctx);
669*4882a593Smuzhiyun
670*4882a593Smuzhiyun ctx->stViRgn.stRgnAttr.enType = (RGN_TYPE_E)ctx->rgnType;
671*4882a593Smuzhiyun ctx->stViRgn.stRgnChnAttr.bShow = RK_TRUE;
672*4882a593Smuzhiyun
673*4882a593Smuzhiyun // open fd before enable chn will be better
674*4882a593Smuzhiyun #if TEST_WITH_FD
675*4882a593Smuzhiyun ctx->selectFd = RK_MPI_VI_GetChnFd(ctx->pipeId, ctx->channelId);
676*4882a593Smuzhiyun RK_LOGE("ctx->pipeId=%d, ctx->channelId=%d, ctx->selectFd:%d ", ctx->pipeId, ctx->channelId, ctx->selectFd);
677*4882a593Smuzhiyun #endif
678*4882a593Smuzhiyun // 3.enable channel
679*4882a593Smuzhiyun s32Ret = RK_MPI_VI_EnableChn(ctx->pipeId, ctx->channelId);
680*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
681*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_EnableChn %x", s32Ret);
682*4882a593Smuzhiyun goto __FAILED;
683*4882a593Smuzhiyun }
684*4882a593Smuzhiyun
685*4882a593Smuzhiyun if (ctx->bEnRgn) {
686*4882a593Smuzhiyun s32Ret = create_rgn(ctx);
687*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
688*4882a593Smuzhiyun RK_LOGE("Error:create rgn failed!");
689*4882a593Smuzhiyun goto __FAILED;
690*4882a593Smuzhiyun }
691*4882a593Smuzhiyun }
692*4882a593Smuzhiyun
693*4882a593Smuzhiyun // 4.save debug file
694*4882a593Smuzhiyun if (ctx->stDebugFile.bCfg) {
695*4882a593Smuzhiyun s32Ret = RK_MPI_VI_ChnSaveFile(ctx->pipeId, ctx->channelId, &ctx->stDebugFile);
696*4882a593Smuzhiyun RK_LOGD("RK_MPI_VI_ChnSaveFile %x", s32Ret);
697*4882a593Smuzhiyun }
698*4882a593Smuzhiyun
699*4882a593Smuzhiyun __FAILED:
700*4882a593Smuzhiyun return s32Ret;
701*4882a593Smuzhiyun }
702*4882a593Smuzhiyun
test_vi_bind_vo_loop(TEST_VI_CTX_S * ctx)703*4882a593Smuzhiyun static RK_S32 test_vi_bind_vo_loop(TEST_VI_CTX_S *ctx) {
704*4882a593Smuzhiyun MPP_CHN_S stSrcChn, stDestChn;
705*4882a593Smuzhiyun RK_S32 loopCount = 0;
706*4882a593Smuzhiyun void *pData = RK_NULL;
707*4882a593Smuzhiyun RK_S32 s32Ret = RK_FAILURE;
708*4882a593Smuzhiyun RK_U32 i;
709*4882a593Smuzhiyun
710*4882a593Smuzhiyun s32Ret = test_vi_init(ctx);
711*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
712*4882a593Smuzhiyun RK_LOGE("vi %d:%d init failed:%x", ctx->devId, ctx->channelId, s32Ret);
713*4882a593Smuzhiyun goto __FAILED;
714*4882a593Smuzhiyun }
715*4882a593Smuzhiyun
716*4882a593Smuzhiyun // vo init and create
717*4882a593Smuzhiyun ctx->s32VoLayer = RK356X_VOP_LAYER_CLUSTER_0;
718*4882a593Smuzhiyun ctx->s32VoDev = RK356X_VO_DEV_HD0;
719*4882a593Smuzhiyun s32Ret = create_vo(ctx, 0);
720*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
721*4882a593Smuzhiyun RK_LOGE("create vo ch:%d failed", ctx->channelId);
722*4882a593Smuzhiyun goto __FAILED;
723*4882a593Smuzhiyun }
724*4882a593Smuzhiyun // bind vi to vo
725*4882a593Smuzhiyun stSrcChn.enModId = RK_ID_VI;
726*4882a593Smuzhiyun stSrcChn.s32DevId = ctx->devId;
727*4882a593Smuzhiyun stSrcChn.s32ChnId = ctx->channelId;
728*4882a593Smuzhiyun
729*4882a593Smuzhiyun stDestChn.enModId = RK_ID_VO;
730*4882a593Smuzhiyun stDestChn.s32DevId = ctx->s32VoLayer;
731*4882a593Smuzhiyun stDestChn.s32ChnId = 0;
732*4882a593Smuzhiyun
733*4882a593Smuzhiyun s32Ret = RK_MPI_SYS_Bind(&stSrcChn, &stDestChn);
734*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
735*4882a593Smuzhiyun RK_LOGE("vi band vo fail:%x", s32Ret);
736*4882a593Smuzhiyun goto __FAILED;
737*4882a593Smuzhiyun }
738*4882a593Smuzhiyun
739*4882a593Smuzhiyun // enable vo
740*4882a593Smuzhiyun s32Ret = RK_MPI_VO_EnableChn(ctx->s32VoLayer, 0);
741*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
742*4882a593Smuzhiyun RK_LOGE("Enalbe vo chn failed, s32Ret = %d\n", s32Ret);
743*4882a593Smuzhiyun goto __FAILED;
744*4882a593Smuzhiyun }
745*4882a593Smuzhiyun
746*4882a593Smuzhiyun while (loopCount < ctx->loopCountSet) {
747*4882a593Smuzhiyun loopCount++;
748*4882a593Smuzhiyun //RK_LOGE("loopCount:%d", loopCount);
749*4882a593Smuzhiyun // can not get the vo frameout count . so here regard as 33ms one frame.
750*4882a593Smuzhiyun usleep(33*1000);
751*4882a593Smuzhiyun }
752*4882a593Smuzhiyun
753*4882a593Smuzhiyun __FAILED:
754*4882a593Smuzhiyun s32Ret = RK_MPI_SYS_UnBind(&stSrcChn, &stDestChn);
755*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
756*4882a593Smuzhiyun RK_LOGE("RK_MPI_SYS_UnBind fail %x", s32Ret);
757*4882a593Smuzhiyun }
758*4882a593Smuzhiyun // disable vo
759*4882a593Smuzhiyun RK_MPI_VO_DisableLayer(ctx->s32VoLayer);
760*4882a593Smuzhiyun RK_MPI_VO_DisableLayer(RK356X_VOP_LAYER_ESMART_0);
761*4882a593Smuzhiyun RK_MPI_VO_DisableLayer(RK356X_VOP_LAYER_ESMART_1);
762*4882a593Smuzhiyun RK_MPI_VO_DisableLayer(RK356X_VOP_LAYER_SMART_0);
763*4882a593Smuzhiyun RK_MPI_VO_DisableLayer(RK356X_VOP_LAYER_SMART_1);
764*4882a593Smuzhiyun RK_MPI_VO_DisableChn(ctx->s32VoLayer, 0);
765*4882a593Smuzhiyun RK_MPI_VO_Disable(ctx->s32VoDev);
766*4882a593Smuzhiyun
767*4882a593Smuzhiyun // 5. disable one chn
768*4882a593Smuzhiyun s32Ret = RK_MPI_VI_DisableChn(ctx->pipeId, ctx->channelId);
769*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_DisableChn %x", s32Ret);
770*4882a593Smuzhiyun
771*4882a593Smuzhiyun RK_MPI_VO_DisableChn(ctx->s32VoLayer, 0);
772*4882a593Smuzhiyun
773*4882a593Smuzhiyun // 6.disable dev(will diabled all chn)
774*4882a593Smuzhiyun s32Ret = RK_MPI_VI_DisableDev(ctx->devId);
775*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_DisableDev %x", s32Ret);
776*4882a593Smuzhiyun
777*4882a593Smuzhiyun return s32Ret;
778*4882a593Smuzhiyun }
779*4882a593Smuzhiyun
test_vi_bind_vpss_venc_loop(TEST_VI_CTX_S * ctx)780*4882a593Smuzhiyun static RK_S32 test_vi_bind_vpss_venc_loop(TEST_VI_CTX_S *ctx) {
781*4882a593Smuzhiyun MPP_CHN_S stViChn, stVencChn[TEST_VENC_MAX], stVpssChn;
782*4882a593Smuzhiyun RK_S32 loopCount = 0;
783*4882a593Smuzhiyun void *pData = RK_NULL;
784*4882a593Smuzhiyun RK_S32 s32Ret = RK_FAILURE;
785*4882a593Smuzhiyun RK_U32 i;
786*4882a593Smuzhiyun RK_U32 u32DstCount = 1;
787*4882a593Smuzhiyun
788*4882a593Smuzhiyun s32Ret = test_vi_init(ctx);
789*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
790*4882a593Smuzhiyun RK_LOGE("vi %d:%d init failed:%x", ctx->devId, ctx->channelId, s32Ret);
791*4882a593Smuzhiyun goto __FAILED;
792*4882a593Smuzhiyun }
793*4882a593Smuzhiyun
794*4882a593Smuzhiyun /* vpss */
795*4882a593Smuzhiyun ctx->stVpssCfg.u32VpssChnCnt = 1;
796*4882a593Smuzhiyun ctx->stVpssCfg.stGrpVpssAttr.u32MaxW = 4096;
797*4882a593Smuzhiyun ctx->stVpssCfg.stGrpVpssAttr.u32MaxH = 4096;
798*4882a593Smuzhiyun ctx->stVpssCfg.stGrpVpssAttr.enPixelFormat = RK_FMT_YUV420SP;
799*4882a593Smuzhiyun ctx->stVpssCfg.stGrpVpssAttr.stFrameRate.s32SrcFrameRate = -1;
800*4882a593Smuzhiyun ctx->stVpssCfg.stGrpVpssAttr.stFrameRate.s32DstFrameRate = -1;
801*4882a593Smuzhiyun ctx->stVpssCfg.stGrpVpssAttr.enCompressMode = COMPRESS_MODE_NONE;
802*4882a593Smuzhiyun for (i = 0; i < VPSS_MAX_CHN_NUM; i ++) {
803*4882a593Smuzhiyun ctx->stVpssCfg.stVpssChnAttr[i].enChnMode = VPSS_CHN_MODE_PASSTHROUGH;
804*4882a593Smuzhiyun ctx->stVpssCfg.stVpssChnAttr[i].enDynamicRange = DYNAMIC_RANGE_SDR8;
805*4882a593Smuzhiyun ctx->stVpssCfg.stVpssChnAttr[i].enPixelFormat = RK_FMT_YUV420SP;
806*4882a593Smuzhiyun ctx->stVpssCfg.stVpssChnAttr[i].stFrameRate.s32SrcFrameRate = -1;
807*4882a593Smuzhiyun ctx->stVpssCfg.stVpssChnAttr[i].stFrameRate.s32DstFrameRate = -1;
808*4882a593Smuzhiyun ctx->stVpssCfg.stVpssChnAttr[i].u32Width = ctx->width;
809*4882a593Smuzhiyun ctx->stVpssCfg.stVpssChnAttr[i].u32Height = ctx->height;
810*4882a593Smuzhiyun ctx->stVpssCfg.stVpssChnAttr[i].enCompressMode = COMPRESS_MODE_NONE;
811*4882a593Smuzhiyun }
812*4882a593Smuzhiyun
813*4882a593Smuzhiyun // init vpss
814*4882a593Smuzhiyun s32Ret = create_vpss(&ctx->stVpssCfg, 0, ctx->stVpssCfg.u32VpssChnCnt);
815*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
816*4882a593Smuzhiyun RK_LOGE("creat 0 grp vpss failed!");
817*4882a593Smuzhiyun goto __FAILED;
818*4882a593Smuzhiyun }
819*4882a593Smuzhiyun // bind vi to vpss
820*4882a593Smuzhiyun stViChn.enModId = RK_ID_VI;
821*4882a593Smuzhiyun stViChn.s32DevId = ctx->devId;
822*4882a593Smuzhiyun stViChn.s32ChnId = ctx->channelId;
823*4882a593Smuzhiyun stVpssChn.enModId = RK_ID_VPSS;
824*4882a593Smuzhiyun stVpssChn.s32DevId = 0;
825*4882a593Smuzhiyun stVpssChn.s32ChnId = 0;
826*4882a593Smuzhiyun
827*4882a593Smuzhiyun RK_LOGD("vi to vpss ch %d vpss group %d", stVpssChn.s32ChnId , stVpssChn.s32DevId);
828*4882a593Smuzhiyun s32Ret = RK_MPI_SYS_Bind(&stViChn, &stVpssChn);
829*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
830*4882a593Smuzhiyun RK_LOGE("vi and vpss bind error ");
831*4882a593Smuzhiyun goto __FAILED;
832*4882a593Smuzhiyun }
833*4882a593Smuzhiyun
834*4882a593Smuzhiyun /* venc */
835*4882a593Smuzhiyun for (i = 0; i < u32DstCount; i++) {
836*4882a593Smuzhiyun // venc init and create
837*4882a593Smuzhiyun init_venc_cfg(ctx, i, RK_VIDEO_ID_AVC);
838*4882a593Smuzhiyun s32Ret = create_venc(ctx, ctx->stVencCfg[i].s32ChnId);
839*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
840*4882a593Smuzhiyun RK_LOGE("create %d ch venc failed", ctx->stVencCfg[i].s32ChnId);
841*4882a593Smuzhiyun return s32Ret;
842*4882a593Smuzhiyun }
843*4882a593Smuzhiyun // bind vpss to venc
844*4882a593Smuzhiyun stVencChn[i].enModId = RK_ID_VENC;
845*4882a593Smuzhiyun stVencChn[i].s32DevId = i;
846*4882a593Smuzhiyun stVencChn[i].s32ChnId = ctx->stVencCfg[i].s32ChnId;
847*4882a593Smuzhiyun
848*4882a593Smuzhiyun s32Ret = RK_MPI_SYS_Bind(&stVpssChn, &stVencChn[i]);
849*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
850*4882a593Smuzhiyun RK_LOGE("create %d ch venc failed", ctx->stVencCfg[i].s32ChnId);
851*4882a593Smuzhiyun goto __FAILED;
852*4882a593Smuzhiyun }
853*4882a593Smuzhiyun ctx->stFrame[i].pstPack = reinterpret_cast<VENC_PACK_S *>(malloc(sizeof(VENC_PACK_S)));
854*4882a593Smuzhiyun #if TEST_WITH_FD
855*4882a593Smuzhiyun ctx->stVencCfg[i].selectFd = RK_MPI_VENC_GetFd(ctx->stVencCfg[i].s32ChnId);
856*4882a593Smuzhiyun RK_LOGE("venc chn:%d, ctx->selectFd:%d ", ctx->stVencCfg[i].s32ChnId, ctx->stVencCfg[i].selectFd);
857*4882a593Smuzhiyun #endif
858*4882a593Smuzhiyun }
859*4882a593Smuzhiyun
860*4882a593Smuzhiyun while (loopCount < ctx->loopCountSet) {
861*4882a593Smuzhiyun for (i = 0; i < u32DstCount; i++) {
862*4882a593Smuzhiyun #if TEST_WITH_FD
863*4882a593Smuzhiyun test_vi_poll_event(-1, ctx->stVencCfg[i].selectFd);
864*4882a593Smuzhiyun #endif
865*4882a593Smuzhiyun
866*4882a593Smuzhiyun // freeze test
867*4882a593Smuzhiyun RK_MPI_VI_SetChnFreeze(ctx->pipeId, ctx->channelId, ctx->bFreeze);
868*4882a593Smuzhiyun
869*4882a593Smuzhiyun s32Ret = RK_MPI_VENC_GetStream(ctx->stVencCfg[i].s32ChnId, &ctx->stFrame[i], -1);
870*4882a593Smuzhiyun if (s32Ret == RK_SUCCESS) {
871*4882a593Smuzhiyun if (ctx->stVencCfg[i].bOutDebugCfg) {
872*4882a593Smuzhiyun pData = RK_MPI_MB_Handle2VirAddr(ctx->stFrame[i].pstPack->pMbBlk);
873*4882a593Smuzhiyun fwrite(pData, 1, ctx->stFrame[i].pstPack->u32Len, ctx->stVencCfg[i].fp);
874*4882a593Smuzhiyun fflush(ctx->stVencCfg[i].fp);
875*4882a593Smuzhiyun }
876*4882a593Smuzhiyun RK_LOGD("chn:%d, loopCount:%d enc->seq:%d wd:%d\n", i, loopCount,
877*4882a593Smuzhiyun ctx->stFrame[i].u32Seq, ctx->stFrame[i].pstPack->u32Len);
878*4882a593Smuzhiyun s32Ret = RK_MPI_VENC_ReleaseStream(ctx->stVencCfg[i].s32ChnId, &ctx->stFrame[i]);
879*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
880*4882a593Smuzhiyun RK_LOGE("RK_MPI_VENC_ReleaseStream fail %x", s32Ret);
881*4882a593Smuzhiyun }
882*4882a593Smuzhiyun loopCount++;
883*4882a593Smuzhiyun } else {
884*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_GetChnFrame fail %x", s32Ret);
885*4882a593Smuzhiyun }
886*4882a593Smuzhiyun }
887*4882a593Smuzhiyun usleep(10*1000);
888*4882a593Smuzhiyun }
889*4882a593Smuzhiyun
890*4882a593Smuzhiyun __FAILED:
891*4882a593Smuzhiyun // unbind vi->vpss
892*4882a593Smuzhiyun s32Ret = RK_MPI_SYS_UnBind(&stViChn, &stVpssChn);
893*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
894*4882a593Smuzhiyun RK_LOGE("RK_MPI_SYS_UnBind fail %x", s32Ret);
895*4882a593Smuzhiyun }
896*4882a593Smuzhiyun // unbind vpss->venc
897*4882a593Smuzhiyun for (i = 0; i < u32DstCount; i++) {
898*4882a593Smuzhiyun s32Ret = RK_MPI_SYS_UnBind(&stVpssChn, &stVencChn[i]);
899*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
900*4882a593Smuzhiyun RK_LOGE("RK_MPI_SYS_UnBind fail %x", s32Ret);
901*4882a593Smuzhiyun }
902*4882a593Smuzhiyun }
903*4882a593Smuzhiyun // destory vpss
904*4882a593Smuzhiyun s32Ret = destory_vpss(0, ctx->stVpssCfg.u32VpssChnCnt);
905*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
906*4882a593Smuzhiyun RK_LOGE("destory vpss error");
907*4882a593Smuzhiyun return s32Ret;
908*4882a593Smuzhiyun }
909*4882a593Smuzhiyun // 5. disable one chn
910*4882a593Smuzhiyun s32Ret = RK_MPI_VI_DisableChn(ctx->pipeId, ctx->channelId);
911*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_DisableChn %x", s32Ret);
912*4882a593Smuzhiyun
913*4882a593Smuzhiyun for (i = 0; i < u32DstCount; i++) {
914*4882a593Smuzhiyun s32Ret = RK_MPI_VENC_StopRecvFrame(ctx->stVencCfg[i].s32ChnId);
915*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
916*4882a593Smuzhiyun return s32Ret;
917*4882a593Smuzhiyun }
918*4882a593Smuzhiyun RK_LOGE("destroy enc chn:%d", ctx->stVencCfg[i].s32ChnId);
919*4882a593Smuzhiyun s32Ret = RK_MPI_VENC_DestroyChn(ctx->stVencCfg[i].s32ChnId);
920*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
921*4882a593Smuzhiyun RK_LOGE("RK_MPI_VDEC_DestroyChn fail %x", s32Ret);
922*4882a593Smuzhiyun }
923*4882a593Smuzhiyun }
924*4882a593Smuzhiyun
925*4882a593Smuzhiyun // 6.disable dev(will diabled all chn)
926*4882a593Smuzhiyun s32Ret = RK_MPI_VI_DisableDev(ctx->devId);
927*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_DisableDev %x", s32Ret);
928*4882a593Smuzhiyun for (i = 0; i < u32DstCount; i++) {
929*4882a593Smuzhiyun if (ctx->stFrame[i].pstPack)
930*4882a593Smuzhiyun free(ctx->stFrame[i].pstPack);
931*4882a593Smuzhiyun if (ctx->stVencCfg[i].fp)
932*4882a593Smuzhiyun fclose(ctx->stVencCfg[i].fp);
933*4882a593Smuzhiyun }
934*4882a593Smuzhiyun return s32Ret;
935*4882a593Smuzhiyun }
936*4882a593Smuzhiyun
test_vi_bind_venc_loop(TEST_VI_CTX_S * ctx)937*4882a593Smuzhiyun static RK_S32 test_vi_bind_venc_loop(TEST_VI_CTX_S *ctx) {
938*4882a593Smuzhiyun MPP_CHN_S stSrcChn, stDestChn[TEST_VENC_MAX];
939*4882a593Smuzhiyun RK_S32 loopCount = 0;
940*4882a593Smuzhiyun void *pData = RK_NULL;
941*4882a593Smuzhiyun RK_S32 s32Ret = RK_FAILURE;
942*4882a593Smuzhiyun RK_U32 i;
943*4882a593Smuzhiyun RK_U32 u32DstCount = ((ctx->enMode == TEST_VI_MODE_BIND_VENC_MULTI) ? 2 : 1);
944*4882a593Smuzhiyun
945*4882a593Smuzhiyun s32Ret = test_vi_init(ctx);
946*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
947*4882a593Smuzhiyun RK_LOGE("vi %d:%d init failed:%x", ctx->devId, ctx->channelId, s32Ret);
948*4882a593Smuzhiyun goto __FAILED;
949*4882a593Smuzhiyun }
950*4882a593Smuzhiyun
951*4882a593Smuzhiyun /* venc */
952*4882a593Smuzhiyun for (i = 0; i < u32DstCount; i++) {
953*4882a593Smuzhiyun // venc init and create
954*4882a593Smuzhiyun init_venc_cfg(ctx, i, RK_VIDEO_ID_AVC);
955*4882a593Smuzhiyun s32Ret = create_venc(ctx, ctx->stVencCfg[i].s32ChnId);
956*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
957*4882a593Smuzhiyun RK_LOGE("create %d ch venc failed", ctx->stVencCfg[i].s32ChnId);
958*4882a593Smuzhiyun return s32Ret;
959*4882a593Smuzhiyun }
960*4882a593Smuzhiyun // bind vi to venc
961*4882a593Smuzhiyun stSrcChn.enModId = RK_ID_VI;
962*4882a593Smuzhiyun stSrcChn.s32DevId = ctx->devId;
963*4882a593Smuzhiyun stSrcChn.s32ChnId = ctx->channelId;
964*4882a593Smuzhiyun
965*4882a593Smuzhiyun stDestChn[i].enModId = RK_ID_VENC;
966*4882a593Smuzhiyun stDestChn[i].s32DevId = i;
967*4882a593Smuzhiyun stDestChn[i].s32ChnId = ctx->stVencCfg[i].s32ChnId;
968*4882a593Smuzhiyun
969*4882a593Smuzhiyun s32Ret = RK_MPI_SYS_Bind(&stSrcChn, &stDestChn[i]);
970*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
971*4882a593Smuzhiyun RK_LOGE("create %d ch venc failed", ctx->stVencCfg[i].s32ChnId);
972*4882a593Smuzhiyun goto __FAILED;
973*4882a593Smuzhiyun }
974*4882a593Smuzhiyun ctx->stFrame[i].pstPack = reinterpret_cast<VENC_PACK_S *>(malloc(sizeof(VENC_PACK_S)));
975*4882a593Smuzhiyun #if TEST_WITH_FD
976*4882a593Smuzhiyun ctx->stVencCfg[i].selectFd = RK_MPI_VENC_GetFd(ctx->stVencCfg[i].s32ChnId);
977*4882a593Smuzhiyun RK_LOGE("venc chn:%d, ctx->selectFd:%d ", ctx->stVencCfg[i].s32ChnId, ctx->stVencCfg[i].selectFd);
978*4882a593Smuzhiyun #endif
979*4882a593Smuzhiyun }
980*4882a593Smuzhiyun
981*4882a593Smuzhiyun while (loopCount < ctx->loopCountSet) {
982*4882a593Smuzhiyun for (i = 0; i < u32DstCount; i++) {
983*4882a593Smuzhiyun #if TEST_WITH_FD
984*4882a593Smuzhiyun test_vi_poll_event(-1, ctx->stVencCfg[i].selectFd);
985*4882a593Smuzhiyun #endif
986*4882a593Smuzhiyun // freeze test
987*4882a593Smuzhiyun RK_MPI_VI_SetChnFreeze(ctx->pipeId, ctx->channelId, ctx->bFreeze);
988*4882a593Smuzhiyun
989*4882a593Smuzhiyun s32Ret = RK_MPI_VENC_GetStream(ctx->stVencCfg[i].s32ChnId, &ctx->stFrame[i], -1);
990*4882a593Smuzhiyun if (s32Ret == RK_SUCCESS) {
991*4882a593Smuzhiyun if (ctx->stVencCfg[i].bOutDebugCfg) {
992*4882a593Smuzhiyun pData = RK_MPI_MB_Handle2VirAddr(ctx->stFrame[i].pstPack->pMbBlk);
993*4882a593Smuzhiyun fwrite(pData, 1, ctx->stFrame[i].pstPack->u32Len, ctx->stVencCfg[i].fp);
994*4882a593Smuzhiyun fflush(ctx->stVencCfg[i].fp);
995*4882a593Smuzhiyun }
996*4882a593Smuzhiyun RK_U64 nowUs = TEST_COMM_GetNowUs();
997*4882a593Smuzhiyun
998*4882a593Smuzhiyun RK_LOGD("chn:%d, loopCount:%d enc->seq:%d wd:%d pts=%lld delay=%lldus\n", i, loopCount,
999*4882a593Smuzhiyun ctx->stFrame[i].u32Seq, ctx->stFrame[i].pstPack->u32Len,
1000*4882a593Smuzhiyun ctx->stFrame[i].pstPack->u64PTS,
1001*4882a593Smuzhiyun nowUs - ctx->stFrame[i].pstPack->u64PTS);
1002*4882a593Smuzhiyun s32Ret = RK_MPI_VENC_ReleaseStream(ctx->stVencCfg[i].s32ChnId, &ctx->stFrame[i]);
1003*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
1004*4882a593Smuzhiyun RK_LOGE("RK_MPI_VENC_ReleaseStream fail %x", s32Ret);
1005*4882a593Smuzhiyun }
1006*4882a593Smuzhiyun loopCount++;
1007*4882a593Smuzhiyun } else {
1008*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_GetChnFrame fail %x", s32Ret);
1009*4882a593Smuzhiyun }
1010*4882a593Smuzhiyun }
1011*4882a593Smuzhiyun usleep(10*1000);
1012*4882a593Smuzhiyun }
1013*4882a593Smuzhiyun
1014*4882a593Smuzhiyun __FAILED:
1015*4882a593Smuzhiyun for (i = 0; i < u32DstCount; i++) {
1016*4882a593Smuzhiyun s32Ret = RK_MPI_SYS_UnBind(&stSrcChn, &stDestChn[i]);
1017*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
1018*4882a593Smuzhiyun RK_LOGE("RK_MPI_SYS_UnBind fail %x", s32Ret);
1019*4882a593Smuzhiyun }
1020*4882a593Smuzhiyun }
1021*4882a593Smuzhiyun // 5. disable one chn
1022*4882a593Smuzhiyun s32Ret = RK_MPI_VI_DisableChn(ctx->pipeId, ctx->channelId);
1023*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_DisableChn %x", s32Ret);
1024*4882a593Smuzhiyun
1025*4882a593Smuzhiyun for (i = 0; i < u32DstCount; i++) {
1026*4882a593Smuzhiyun s32Ret = RK_MPI_VENC_StopRecvFrame(ctx->stVencCfg[i].s32ChnId);
1027*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
1028*4882a593Smuzhiyun return s32Ret;
1029*4882a593Smuzhiyun }
1030*4882a593Smuzhiyun RK_LOGE("destroy enc chn:%d", ctx->stVencCfg[i].s32ChnId);
1031*4882a593Smuzhiyun s32Ret = RK_MPI_VENC_DestroyChn(ctx->stVencCfg[i].s32ChnId);
1032*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
1033*4882a593Smuzhiyun RK_LOGE("RK_MPI_VDEC_DestroyChn fail %x", s32Ret);
1034*4882a593Smuzhiyun }
1035*4882a593Smuzhiyun }
1036*4882a593Smuzhiyun
1037*4882a593Smuzhiyun // 6.disable dev(will diabled all chn)
1038*4882a593Smuzhiyun s32Ret = RK_MPI_VI_DisableDev(ctx->devId);
1039*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_DisableDev %x", s32Ret);
1040*4882a593Smuzhiyun for (i = 0; i < u32DstCount; i++) {
1041*4882a593Smuzhiyun if (ctx->stFrame[i].pstPack)
1042*4882a593Smuzhiyun free(ctx->stFrame[i].pstPack);
1043*4882a593Smuzhiyun if (ctx->stVencCfg[i].fp)
1044*4882a593Smuzhiyun fclose(ctx->stVencCfg[i].fp);
1045*4882a593Smuzhiyun }
1046*4882a593Smuzhiyun return s32Ret;
1047*4882a593Smuzhiyun }
1048*4882a593Smuzhiyun
test_vi_get_release_frame_loop(TEST_VI_CTX_S * ctx)1049*4882a593Smuzhiyun static RK_S32 test_vi_get_release_frame_loop(TEST_VI_CTX_S *ctx) {
1050*4882a593Smuzhiyun RK_S32 s32Ret;
1051*4882a593Smuzhiyun RK_S32 loopCount = 0;
1052*4882a593Smuzhiyun RK_S32 waitTime = 33;
1053*4882a593Smuzhiyun
1054*4882a593Smuzhiyun /* test use getframe&release_frame */
1055*4882a593Smuzhiyun s32Ret = test_vi_init(ctx);
1056*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
1057*4882a593Smuzhiyun RK_LOGE("vi %d:%d init failed:%x", ctx->devId, ctx->channelId, s32Ret);
1058*4882a593Smuzhiyun goto __FAILED;
1059*4882a593Smuzhiyun }
1060*4882a593Smuzhiyun
1061*4882a593Smuzhiyun while (loopCount < ctx->loopCountSet) {
1062*4882a593Smuzhiyun #if TEST_WITH_FD_SWITCH
1063*4882a593Smuzhiyun if (loopCount % 10 == 0 && ctx->selectFd != -1) { // test close/reopen the fd
1064*4882a593Smuzhiyun RK_MPI_VI_CloseChnFd(ctx->pipeId, ctx->channelId);
1065*4882a593Smuzhiyun RK_LOGE("close ctx->pipeId=%d, ctx->channelId=%d, ctx->selectFd:%d",
1066*4882a593Smuzhiyun ctx->pipeId, ctx->channelId, ctx->selectFd);
1067*4882a593Smuzhiyun ctx->selectFd = -1;
1068*4882a593Smuzhiyun } else {
1069*4882a593Smuzhiyun if (ctx->selectFd < 0) {
1070*4882a593Smuzhiyun ctx->selectFd = RK_MPI_VI_GetChnFd(ctx->pipeId, ctx->channelId);
1071*4882a593Smuzhiyun RK_LOGE("regetfd ctx->pipeId=%d, ctx->channelId=%d, ctx->selectFd:%d",
1072*4882a593Smuzhiyun ctx->pipeId, ctx->channelId, ctx->selectFd);
1073*4882a593Smuzhiyun // do not use non-block polling for the first time after switching fd
1074*4882a593Smuzhiyun test_vi_poll_event(33, ctx->selectFd);
1075*4882a593Smuzhiyun } else {
1076*4882a593Smuzhiyun test_vi_poll_event(-1, ctx->selectFd);
1077*4882a593Smuzhiyun }
1078*4882a593Smuzhiyun }
1079*4882a593Smuzhiyun #elif TEST_WITH_FD
1080*4882a593Smuzhiyun test_vi_poll_event(-1, ctx->selectFd);
1081*4882a593Smuzhiyun #endif
1082*4882a593Smuzhiyun
1083*4882a593Smuzhiyun /* test user picture */
1084*4882a593Smuzhiyun if (loopCount > 5 && ctx->bUserPicEnabled) {
1085*4882a593Smuzhiyun ctx->bUserPicEnabled = RK_FALSE;
1086*4882a593Smuzhiyun RK_MPI_VI_DisableUserPic(ctx->pipeId, ctx->channelId);
1087*4882a593Smuzhiyun if (ctx->stUsrPic.enUsrPicMode == VI_USERPIC_MODE_PIC &&
1088*4882a593Smuzhiyun ctx->stUsrPic.unUsrPic.stUsrPicFrm.stVFrame.pMbBlk) {
1089*4882a593Smuzhiyun RK_MPI_MMZ_Free(ctx->stUsrPic.unUsrPic.stUsrPicFrm.stVFrame.pMbBlk);
1090*4882a593Smuzhiyun ctx->stUsrPic.unUsrPic.stUsrPicFrm.stVFrame.pMbBlk = RK_NULL;
1091*4882a593Smuzhiyun }
1092*4882a593Smuzhiyun }
1093*4882a593Smuzhiyun
1094*4882a593Smuzhiyun // freeze test
1095*4882a593Smuzhiyun RK_MPI_VI_SetChnFreeze(ctx->pipeId, ctx->channelId, ctx->bFreeze);
1096*4882a593Smuzhiyun
1097*4882a593Smuzhiyun // 5.get the frame
1098*4882a593Smuzhiyun s32Ret = RK_MPI_VI_GetChnFrame(ctx->pipeId, ctx->channelId, &ctx->stViFrame, waitTime);
1099*4882a593Smuzhiyun if (s32Ret == RK_SUCCESS) {
1100*4882a593Smuzhiyun RK_U64 nowUs = TEST_COMM_GetNowUs();
1101*4882a593Smuzhiyun void *data = RK_MPI_MB_Handle2VirAddr(ctx->stViFrame.stVFrame.pMbBlk);
1102*4882a593Smuzhiyun
1103*4882a593Smuzhiyun RK_LOGD("RK_MPI_VI_GetChnFrame ok:data %p loop:%d seq:%d pts:%lld ms len=%d", data, loopCount,
1104*4882a593Smuzhiyun ctx->stViFrame.stVFrame.u32TimeRef, ctx->stViFrame.stVFrame.u64PTS/1000,
1105*4882a593Smuzhiyun RK_MPI_MB_GetLength(ctx->stViFrame.stVFrame.pMbBlk));
1106*4882a593Smuzhiyun // 6.get the channel status
1107*4882a593Smuzhiyun s32Ret = RK_MPI_VI_QueryChnStatus(ctx->pipeId, ctx->channelId, &ctx->stChnStatus);
1108*4882a593Smuzhiyun RK_LOGD("RK_MPI_VI_QueryChnStatus ret %x, w:%d,h:%d,enable:%d," \
1109*4882a593Smuzhiyun "current frame id:%d,input lost:%d,output lost:%d," \
1110*4882a593Smuzhiyun "framerate:%d,vbfail:%d delay=%lldus",
1111*4882a593Smuzhiyun s32Ret,
1112*4882a593Smuzhiyun ctx->stChnStatus.stSize.u32Width,
1113*4882a593Smuzhiyun ctx->stChnStatus.stSize.u32Height,
1114*4882a593Smuzhiyun ctx->stChnStatus.bEnable,
1115*4882a593Smuzhiyun ctx->stChnStatus.u32CurFrameID,
1116*4882a593Smuzhiyun ctx->stChnStatus.u32InputLostFrame,
1117*4882a593Smuzhiyun ctx->stChnStatus.u32OutputLostFrame,
1118*4882a593Smuzhiyun ctx->stChnStatus.u32FrameRate,
1119*4882a593Smuzhiyun ctx->stChnStatus.u32VbFail,
1120*4882a593Smuzhiyun nowUs - ctx->stViFrame.stVFrame.u64PTS);
1121*4882a593Smuzhiyun
1122*4882a593Smuzhiyun // 7.release the frame
1123*4882a593Smuzhiyun s32Ret = RK_MPI_VI_ReleaseChnFrame(ctx->pipeId, ctx->channelId, &ctx->stViFrame);
1124*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
1125*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_ReleaseChnFrame fail %x", s32Ret);
1126*4882a593Smuzhiyun }
1127*4882a593Smuzhiyun loopCount++;
1128*4882a593Smuzhiyun } else {
1129*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_GetChnFrame timeout %x", s32Ret);
1130*4882a593Smuzhiyun }
1131*4882a593Smuzhiyun
1132*4882a593Smuzhiyun usleep(10*1000);
1133*4882a593Smuzhiyun }
1134*4882a593Smuzhiyun
1135*4882a593Smuzhiyun __FAILED:
1136*4882a593Smuzhiyun // if enable rgn,deinit it and destory it.
1137*4882a593Smuzhiyun if (ctx->bEnRgn) {
1138*4882a593Smuzhiyun destory_rgn(ctx);
1139*4882a593Smuzhiyun }
1140*4882a593Smuzhiyun
1141*4882a593Smuzhiyun // 9. disable one chn
1142*4882a593Smuzhiyun s32Ret = RK_MPI_VI_DisableChn(ctx->pipeId, ctx->channelId);
1143*4882a593Smuzhiyun // 10.disable dev(will diabled all chn)
1144*4882a593Smuzhiyun s32Ret = RK_MPI_VI_DisableDev(ctx->devId);
1145*4882a593Smuzhiyun
1146*4882a593Smuzhiyun return s32Ret;
1147*4882a593Smuzhiyun }
1148*4882a593Smuzhiyun
create_vi(TEST_VI_CTX_S * ctx)1149*4882a593Smuzhiyun static RK_S32 create_vi(TEST_VI_CTX_S *ctx) {
1150*4882a593Smuzhiyun RK_S32 s32Ret = RK_FAILURE;
1151*4882a593Smuzhiyun
1152*4882a593Smuzhiyun // 0. get dev config status
1153*4882a593Smuzhiyun s32Ret = RK_MPI_VI_GetDevAttr(ctx->devId, &ctx->stDevAttr);
1154*4882a593Smuzhiyun if (s32Ret == RK_ERR_VI_NOT_CONFIG) {
1155*4882a593Smuzhiyun // 0-1.config dev
1156*4882a593Smuzhiyun s32Ret = RK_MPI_VI_SetDevAttr(ctx->devId, &ctx->stDevAttr);
1157*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
1158*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_SetDevAttr %x", s32Ret);
1159*4882a593Smuzhiyun goto __FAILED;
1160*4882a593Smuzhiyun }
1161*4882a593Smuzhiyun } else {
1162*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_SetDevAttr already");
1163*4882a593Smuzhiyun }
1164*4882a593Smuzhiyun // 1.get dev enable status
1165*4882a593Smuzhiyun s32Ret = RK_MPI_VI_GetDevIsEnable(ctx->devId);
1166*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
1167*4882a593Smuzhiyun // 1-2.enable dev
1168*4882a593Smuzhiyun s32Ret = RK_MPI_VI_EnableDev(ctx->devId);
1169*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
1170*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_EnableDev %x", s32Ret);
1171*4882a593Smuzhiyun goto __FAILED;
1172*4882a593Smuzhiyun }
1173*4882a593Smuzhiyun // 1-3.bind dev/pipe
1174*4882a593Smuzhiyun ctx->stBindPipe.u32Num = ctx->pipeId;
1175*4882a593Smuzhiyun ctx->stBindPipe.PipeId[0] = ctx->pipeId;
1176*4882a593Smuzhiyun s32Ret = RK_MPI_VI_SetDevBindPipe(ctx->devId, &ctx->stBindPipe);
1177*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
1178*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_SetDevBindPipe %x", s32Ret);
1179*4882a593Smuzhiyun goto __FAILED;
1180*4882a593Smuzhiyun }
1181*4882a593Smuzhiyun } else {
1182*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_EnableDev already");
1183*4882a593Smuzhiyun }
1184*4882a593Smuzhiyun // 2.config channel
1185*4882a593Smuzhiyun s32Ret = RK_MPI_VI_SetChnAttr(ctx->pipeId, ctx->channelId, &ctx->stChnAttr);
1186*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
1187*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_SetChnAttr %x", s32Ret);
1188*4882a593Smuzhiyun goto __FAILED;
1189*4882a593Smuzhiyun }
1190*4882a593Smuzhiyun // 3.enable channel
1191*4882a593Smuzhiyun RK_LOGD("RK_MPI_VI_EnableChn %x %d %d", ctx->devId, ctx->pipeId, ctx->channelId);
1192*4882a593Smuzhiyun s32Ret = RK_MPI_VI_EnableChn(ctx->pipeId, ctx->channelId);
1193*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
1194*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_EnableChn %x", s32Ret);
1195*4882a593Smuzhiyun goto __FAILED;
1196*4882a593Smuzhiyun }
1197*4882a593Smuzhiyun // 4.save debug file
1198*4882a593Smuzhiyun if (ctx->stDebugFile.bCfg) {
1199*4882a593Smuzhiyun s32Ret = RK_MPI_VI_ChnSaveFile(ctx->pipeId, ctx->channelId, &ctx->stDebugFile);
1200*4882a593Smuzhiyun RK_LOGD("RK_MPI_VI_ChnSaveFile %x", s32Ret);
1201*4882a593Smuzhiyun }
1202*4882a593Smuzhiyun
1203*4882a593Smuzhiyun __FAILED:
1204*4882a593Smuzhiyun return s32Ret;
1205*4882a593Smuzhiyun }
1206*4882a593Smuzhiyun
destroy_vi(TEST_VI_CTX_S * ctx)1207*4882a593Smuzhiyun static RK_S32 destroy_vi(TEST_VI_CTX_S *ctx) {
1208*4882a593Smuzhiyun RK_S32 s32Ret = RK_FAILURE;
1209*4882a593Smuzhiyun s32Ret = RK_MPI_VI_DisableChn(ctx->pipeId, ctx->channelId);
1210*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_DisableChn pipe=%d ret:%x", ctx->pipeId, s32Ret);
1211*4882a593Smuzhiyun
1212*4882a593Smuzhiyun s32Ret = RK_MPI_VI_DisableDev(ctx->devId);
1213*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_DisableDev pipe=%d ret:%x", ctx->pipeId, s32Ret);
1214*4882a593Smuzhiyun
1215*4882a593Smuzhiyun RK_SAFE_FREE(ctx);
1216*4882a593Smuzhiyun return s32Ret;
1217*4882a593Smuzhiyun }
1218*4882a593Smuzhiyun
test_vi_muti_vi_loop(TEST_VI_CTX_S * ctx_out)1219*4882a593Smuzhiyun static RK_S32 test_vi_muti_vi_loop(TEST_VI_CTX_S *ctx_out) {
1220*4882a593Smuzhiyun RK_S32 s32Ret = RK_FAILURE;
1221*4882a593Smuzhiyun TEST_VI_CTX_S *pstViCtx[TEST_VI_SENSOR_NUM];
1222*4882a593Smuzhiyun RK_S32 loopCount = 0;
1223*4882a593Smuzhiyun RK_S32 waitTime = 33;
1224*4882a593Smuzhiyun RK_S32 i = 0;
1225*4882a593Smuzhiyun
1226*4882a593Smuzhiyun for (i = 0; i < TEST_VI_SENSOR_NUM; i++) {
1227*4882a593Smuzhiyun pstViCtx[i] = reinterpret_cast<TEST_VI_CTX_S *>(malloc(sizeof(TEST_VI_CTX_S)));
1228*4882a593Smuzhiyun memset(pstViCtx[i], 0, sizeof(TEST_VI_CTX_S));
1229*4882a593Smuzhiyun
1230*4882a593Smuzhiyun /* vi config init */
1231*4882a593Smuzhiyun pstViCtx[i]->devId = i;
1232*4882a593Smuzhiyun pstViCtx[i]->pipeId = pstViCtx[i]->devId;
1233*4882a593Smuzhiyun pstViCtx[i]->channelId = 2;
1234*4882a593Smuzhiyun
1235*4882a593Smuzhiyun if (TEST_VI_SENSOR_NUM == 2) {
1236*4882a593Smuzhiyun pstViCtx[i]->stChnAttr.stSize.u32Width = 2688;
1237*4882a593Smuzhiyun pstViCtx[i]->stChnAttr.stSize.u32Height = 1520;
1238*4882a593Smuzhiyun } else if (TEST_VI_SENSOR_NUM == 4 || TEST_VI_SENSOR_NUM == 6) {
1239*4882a593Smuzhiyun pstViCtx[i]->stChnAttr.stSize.u32Width = 2560;
1240*4882a593Smuzhiyun pstViCtx[i]->stChnAttr.stSize.u32Height = 1520;
1241*4882a593Smuzhiyun }
1242*4882a593Smuzhiyun pstViCtx[i]->stChnAttr.stIspOpt.enMemoryType = VI_V4L2_MEMORY_TYPE_DMABUF;
1243*4882a593Smuzhiyun
1244*4882a593Smuzhiyun pstViCtx[i]->stChnAttr.stIspOpt.u32BufCount = 10;
1245*4882a593Smuzhiyun pstViCtx[i]->stChnAttr.u32Depth = 2;
1246*4882a593Smuzhiyun pstViCtx[i]->stChnAttr.enPixelFormat = RK_FMT_YUV420SP;
1247*4882a593Smuzhiyun pstViCtx[i]->stChnAttr.enCompressMode = COMPRESS_AFBC_16x16;
1248*4882a593Smuzhiyun pstViCtx[i]->stChnAttr.stFrameRate.s32SrcFrameRate = -1;
1249*4882a593Smuzhiyun pstViCtx[i]->stChnAttr.stFrameRate.s32DstFrameRate = -1;
1250*4882a593Smuzhiyun
1251*4882a593Smuzhiyun /* vi create */
1252*4882a593Smuzhiyun s32Ret = create_vi(pstViCtx[i]);
1253*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
1254*4882a593Smuzhiyun RK_LOGE("vi [%d, %d] init failed: %x",
1255*4882a593Smuzhiyun pstViCtx[i]->devId, pstViCtx[i]->channelId,
1256*4882a593Smuzhiyun s32Ret);
1257*4882a593Smuzhiyun goto __FAILED_VI;
1258*4882a593Smuzhiyun }
1259*4882a593Smuzhiyun }
1260*4882a593Smuzhiyun
1261*4882a593Smuzhiyun while (loopCount < ctx_out->loopCountSet) {
1262*4882a593Smuzhiyun for (i = 0; i < TEST_VI_SENSOR_NUM; i++) {
1263*4882a593Smuzhiyun // get the frame
1264*4882a593Smuzhiyun s32Ret = RK_MPI_VI_GetChnFrame(pstViCtx[i]->pipeId, pstViCtx[i]->channelId,
1265*4882a593Smuzhiyun &pstViCtx[i]->stViFrame, waitTime);
1266*4882a593Smuzhiyun if (s32Ret == RK_SUCCESS) {
1267*4882a593Smuzhiyun RK_U64 nowUs = TEST_COMM_GetNowUs();
1268*4882a593Smuzhiyun void *data = RK_MPI_MB_Handle2VirAddr(pstViCtx[i]->stViFrame.stVFrame.pMbBlk);
1269*4882a593Smuzhiyun RK_LOGD("dev %d GetChnFrame Success!", i);
1270*4882a593Smuzhiyun RK_LOGD("RK_MPI_VI_GetChnFrame ok:data %p loop:%d seq:%d pts:%lld ms len=%d",
1271*4882a593Smuzhiyun data, loopCount, pstViCtx[i]->stViFrame.stVFrame.u32TimeRef,
1272*4882a593Smuzhiyun pstViCtx[i]->stViFrame.stVFrame.u64PTS/1000,
1273*4882a593Smuzhiyun RK_MPI_MB_GetLength(pstViCtx[i]->stViFrame.stVFrame.pMbBlk));
1274*4882a593Smuzhiyun // get the channel status
1275*4882a593Smuzhiyun s32Ret = RK_MPI_VI_QueryChnStatus(pstViCtx[i]->pipeId, pstViCtx[i]->channelId,
1276*4882a593Smuzhiyun &pstViCtx[i]->stChnStatus);
1277*4882a593Smuzhiyun RK_LOGD("RK_MPI_VI_QueryChnStatus ret %x, w:%d,h:%d,enable:%d," \
1278*4882a593Smuzhiyun "input lost:%d, output lost:%d, framerate:%d,vbfail:%d delay=%lldus",
1279*4882a593Smuzhiyun s32Ret,
1280*4882a593Smuzhiyun pstViCtx[i]->stChnStatus.stSize.u32Width,
1281*4882a593Smuzhiyun pstViCtx[i]->stChnStatus.stSize.u32Height,
1282*4882a593Smuzhiyun pstViCtx[i]->stChnStatus.bEnable,
1283*4882a593Smuzhiyun pstViCtx[i]->stChnStatus.u32InputLostFrame,
1284*4882a593Smuzhiyun pstViCtx[i]->stChnStatus.u32OutputLostFrame,
1285*4882a593Smuzhiyun pstViCtx[i]->stChnStatus.u32FrameRate,
1286*4882a593Smuzhiyun pstViCtx[i]->stChnStatus.u32VbFail,
1287*4882a593Smuzhiyun nowUs - pstViCtx[i]->stViFrame.stVFrame.u64PTS);
1288*4882a593Smuzhiyun // release the frame
1289*4882a593Smuzhiyun s32Ret = RK_MPI_VI_ReleaseChnFrame(pstViCtx[i]->pipeId, pstViCtx[i]->channelId,
1290*4882a593Smuzhiyun &pstViCtx[i]->stViFrame);
1291*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
1292*4882a593Smuzhiyun RK_LOGE("RK_MPI_VI_ReleaseChnFrame fail %x", s32Ret);
1293*4882a593Smuzhiyun }
1294*4882a593Smuzhiyun } else {
1295*4882a593Smuzhiyun RK_LOGE("dev %d RK_MPI_VI_GetChnFrame timeout %x", i, s32Ret);
1296*4882a593Smuzhiyun }
1297*4882a593Smuzhiyun usleep(3*1000);
1298*4882a593Smuzhiyun }
1299*4882a593Smuzhiyun loopCount++;
1300*4882a593Smuzhiyun usleep(10*1000);
1301*4882a593Smuzhiyun }
1302*4882a593Smuzhiyun
1303*4882a593Smuzhiyun __FAILED_VI:
1304*4882a593Smuzhiyun /* destroy vi*/
1305*4882a593Smuzhiyun for (RK_S32 i = 0; i < TEST_VI_SENSOR_NUM; i++) {
1306*4882a593Smuzhiyun s32Ret = destroy_vi(pstViCtx[i]);
1307*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
1308*4882a593Smuzhiyun RK_LOGE("destroy vi [%d, %d] error %x",
1309*4882a593Smuzhiyun pstViCtx[i]->devId, pstViCtx[i]->channelId,
1310*4882a593Smuzhiyun s32Ret);
1311*4882a593Smuzhiyun goto __FAILED;
1312*4882a593Smuzhiyun }
1313*4882a593Smuzhiyun }
1314*4882a593Smuzhiyun __FAILED:
1315*4882a593Smuzhiyun return s32Ret;
1316*4882a593Smuzhiyun }
1317*4882a593Smuzhiyun
mpi_vi_test_show_options(const TEST_VI_CTX_S * ctx)1318*4882a593Smuzhiyun static void mpi_vi_test_show_options(const TEST_VI_CTX_S *ctx) {
1319*4882a593Smuzhiyun RK_PRINT("cmd parse result:\n");
1320*4882a593Smuzhiyun
1321*4882a593Smuzhiyun RK_PRINT("output file open : %d\n", ctx->stDebugFile.bCfg);
1322*4882a593Smuzhiyun RK_PRINT("yuv output file name : %s/%s\n", ctx->stDebugFile.aFilePath, ctx->stDebugFile.aFileName);
1323*4882a593Smuzhiyun RK_PRINT("enc0 output file path : /%s/%s\n", ctx->stVencCfg[0].dstFilePath, ctx->stVencCfg[0].dstFileName);
1324*4882a593Smuzhiyun RK_PRINT("enc1 output file path : /%s/%s\n", ctx->stVencCfg[1].dstFilePath, ctx->stVencCfg[1].dstFileName);
1325*4882a593Smuzhiyun RK_PRINT("loop count : %d\n", ctx->loopCountSet);
1326*4882a593Smuzhiyun RK_PRINT("enMode : %d\n", ctx->enMode);
1327*4882a593Smuzhiyun RK_PRINT("dev : %d\n", ctx->devId);
1328*4882a593Smuzhiyun RK_PRINT("pipe : %d\n", ctx->pipeId);
1329*4882a593Smuzhiyun RK_PRINT("channel : %d\n", ctx->channelId);
1330*4882a593Smuzhiyun RK_PRINT("width : %d\n", ctx->width);
1331*4882a593Smuzhiyun RK_PRINT("height : %d\n", ctx->height);
1332*4882a593Smuzhiyun RK_PRINT("enCompressMode : %d\n", ctx->enCompressMode);
1333*4882a593Smuzhiyun RK_PRINT("enMemoryType : %d\n", ctx->stChnAttr.stIspOpt.enMemoryType);
1334*4882a593Smuzhiyun RK_PRINT("aEntityName : %s\n", ctx->stChnAttr.stIspOpt.aEntityName);
1335*4882a593Smuzhiyun RK_PRINT("depth : %d\n", ctx->stChnAttr.u32Depth);
1336*4882a593Smuzhiyun RK_PRINT("enPixelFormat : %d\n", ctx->stChnAttr.enPixelFormat);
1337*4882a593Smuzhiyun RK_PRINT("bFreeze : %d\n", ctx->bFreeze);
1338*4882a593Smuzhiyun RK_PRINT("src_frame rate : %d\n", ctx->stChnAttr.stFrameRate.s32SrcFrameRate);
1339*4882a593Smuzhiyun RK_PRINT("dst frame rate : %d\n", ctx->stChnAttr.stFrameRate.s32DstFrameRate);
1340*4882a593Smuzhiyun RK_PRINT("out buf count : %d\n", ctx->stChnAttr.stIspOpt.u32BufCount);
1341*4882a593Smuzhiyun RK_PRINT("bUserPicEnabled : %d\n", ctx->bUserPicEnabled);
1342*4882a593Smuzhiyun RK_PRINT("bEnRgn : %d\n", ctx->bEnRgn);
1343*4882a593Smuzhiyun RK_PRINT("rgn count : %d\n", ctx->s32RgnCnt);
1344*4882a593Smuzhiyun RK_PRINT("rgn type : %d\n", ctx->rgnType);
1345*4882a593Smuzhiyun RK_PRINT("bGetConnecInfo : %d\n", ctx->bGetConnecInfo);
1346*4882a593Smuzhiyun RK_PRINT("bGetEdid : %d\n", ctx->bGetEdid);
1347*4882a593Smuzhiyun RK_PRINT("bSetEdid : %d\n", ctx->bSetEdid);
1348*4882a593Smuzhiyun }
1349*4882a593Smuzhiyun
1350*4882a593Smuzhiyun static const char *const usages[] = {
1351*4882a593Smuzhiyun "./rk_mpi_vi_test -w 1920 -h 1080 -t 4 -n rkispp_scale0",
1352*4882a593Smuzhiyun RK_NULL,
1353*4882a593Smuzhiyun };
1354*4882a593Smuzhiyun
main(int argc,const char ** argv)1355*4882a593Smuzhiyun int main(int argc, const char **argv) {
1356*4882a593Smuzhiyun RK_S32 i;
1357*4882a593Smuzhiyun RK_S32 s32Ret = RK_FAILURE;
1358*4882a593Smuzhiyun TEST_VI_CTX_S *ctx;
1359*4882a593Smuzhiyun ctx = reinterpret_cast<TEST_VI_CTX_S *>(malloc(sizeof(TEST_VI_CTX_S)));
1360*4882a593Smuzhiyun memset(ctx, 0, sizeof(TEST_VI_CTX_S));
1361*4882a593Smuzhiyun
1362*4882a593Smuzhiyun ctx->width = 0;
1363*4882a593Smuzhiyun ctx->height = 0;
1364*4882a593Smuzhiyun ctx->devId = 0;
1365*4882a593Smuzhiyun ctx->pipeId = ctx->devId;
1366*4882a593Smuzhiyun ctx->channelId = 1;
1367*4882a593Smuzhiyun ctx->loopCountSet = 100;
1368*4882a593Smuzhiyun ctx->enMode = TEST_VI_MODE_BIND_VENC;
1369*4882a593Smuzhiyun ctx->stChnAttr.stIspOpt.u32BufCount = 3;
1370*4882a593Smuzhiyun ctx->stChnAttr.stIspOpt.enMemoryType = VI_V4L2_MEMORY_TYPE_DMABUF;
1371*4882a593Smuzhiyun ctx->stChnAttr.stIspOpt.enCaptureType = VI_V4L2_CAPTURE_TYPE_VIDEO_CAPTURE;
1372*4882a593Smuzhiyun ctx->stChnAttr.u32Depth = 0;
1373*4882a593Smuzhiyun ctx->aEntityName = RK_NULL;
1374*4882a593Smuzhiyun ctx->stChnAttr.enPixelFormat = RK_FMT_YUV420SP;
1375*4882a593Smuzhiyun ctx->stChnAttr.stFrameRate.s32SrcFrameRate = -1;
1376*4882a593Smuzhiyun ctx->stChnAttr.stFrameRate.s32DstFrameRate = -1;
1377*4882a593Smuzhiyun ctx->bEnRgn = RK_FALSE;
1378*4882a593Smuzhiyun ctx->s32RgnCnt = 1;
1379*4882a593Smuzhiyun ctx->rgnType = RGN_BUTT;
1380*4882a593Smuzhiyun RK_LOGE("test running enter!");
1381*4882a593Smuzhiyun
1382*4882a593Smuzhiyun struct argparse_option options[] = {
1383*4882a593Smuzhiyun OPT_HELP(),
1384*4882a593Smuzhiyun OPT_GROUP("basic options:"),
1385*4882a593Smuzhiyun OPT_INTEGER('w', "width", &(ctx->width),
1386*4882a593Smuzhiyun "set capture channel width(required, default 0)", NULL, 0, 0),
1387*4882a593Smuzhiyun OPT_INTEGER('h', "height", &(ctx->height),
1388*4882a593Smuzhiyun "set capture channel height(required, default 0)", NULL, 0, 0),
1389*4882a593Smuzhiyun OPT_INTEGER('d', "dev", &(ctx->devId),
1390*4882a593Smuzhiyun "set dev id(default 0)", NULL, 0, 0),
1391*4882a593Smuzhiyun OPT_INTEGER('p', "pipe", &(ctx->pipeId),
1392*4882a593Smuzhiyun "set pipe id(default 0)", NULL, 0, 0),
1393*4882a593Smuzhiyun OPT_INTEGER('c', "channel", &(ctx->channelId),
1394*4882a593Smuzhiyun "set channel id(default 1)", NULL, 0, 0),
1395*4882a593Smuzhiyun OPT_INTEGER('l', "loopcount", &(ctx->loopCountSet),
1396*4882a593Smuzhiyun "set capture frame count(default 100)", NULL, 0, 0),
1397*4882a593Smuzhiyun OPT_INTEGER('C', "compressmode", &(ctx->enCompressMode),
1398*4882a593Smuzhiyun "set capture compressmode(default 0; 0:MODE_NONE 1:AFBC_16x16)", NULL, 0, 0),
1399*4882a593Smuzhiyun OPT_INTEGER('o', "output", &(ctx->stDebugFile.bCfg),
1400*4882a593Smuzhiyun "save output file, file at /data/test_<devid>_<pipeid>_<channelid>.bin"
1401*4882a593Smuzhiyun " (default 0; 0:no save 1:save)", NULL, 0, 0),
1402*4882a593Smuzhiyun OPT_INTEGER('m', "mode", &(ctx->enMode),
1403*4882a593Smuzhiyun "test mode(default 1; 0:vi get&release frame 1:vi bind one venc(h264) \n\t"
1404*4882a593Smuzhiyun "2:vi bind two venc(h264)) 3:vi bind vpss bind venc \n\t"
1405*4882a593Smuzhiyun "4:vi bind vo(only support 356x now)", NULL, 0, 0),
1406*4882a593Smuzhiyun OPT_INTEGER('t', "memorytype", &(ctx->stChnAttr.stIspOpt.enMemoryType),
1407*4882a593Smuzhiyun "set the buf memorytype(required, default 4; 1:mmap(hdmiin/bt1120/sensor input) "
1408*4882a593Smuzhiyun "2:userptr(invalid) 3:overlay(invalid) 4:dma(sensor))", NULL, 0, 0),
1409*4882a593Smuzhiyun OPT_STRING('n', "name", &(ctx->aEntityName),
1410*4882a593Smuzhiyun "set the entityName (required, default null;\n\t"
1411*4882a593Smuzhiyun "rv1126 sensor:rkispp_m_bypass rkispp_scale0 rkispp_scale1 rkispp_scale2;\n\t"
1412*4882a593Smuzhiyun "rv1126 hdmiin/bt1120/sensor:/dev/videox such as /dev/video19 /dev/video20;\n\t"
1413*4882a593Smuzhiyun "rk356x hdmiin/bt1120/sensor:/dev/videox such as /dev/video0 /dev/video1", NULL, 0, 0),
1414*4882a593Smuzhiyun OPT_INTEGER('D', "depth", &(ctx->stChnAttr.u32Depth),
1415*4882a593Smuzhiyun "channel output depth, default{u32BufCount(not bind) or 0(bind venc/vpss/...)}", NULL, 0, 0),
1416*4882a593Smuzhiyun OPT_INTEGER('f', "format", &(ctx->stChnAttr.enPixelFormat),
1417*4882a593Smuzhiyun "set the format(default 0; 0:RK_FMT_YUV420SP 10:RK_FMT_YUV422_UYVY"
1418*4882a593Smuzhiyun "131080:RK_FMT_RGB_BAYER_SBGGR_12BPP)", NULL, 0, 0),
1419*4882a593Smuzhiyun OPT_INTEGER('\0', "freeze", &(ctx->bFreeze),
1420*4882a593Smuzhiyun "freeze output(default 0; 0:disable freeze 1:enable freeze)", NULL, 0, 0),
1421*4882a593Smuzhiyun OPT_INTEGER('\0', "src_rate", &(ctx->stChnAttr.stFrameRate.s32SrcFrameRate),
1422*4882a593Smuzhiyun "src frame rate(default -1; -1:not control; other:1-max_fps<isp_out_fps>)", NULL, 0, 0),
1423*4882a593Smuzhiyun OPT_INTEGER('\0', "dst_rate", &(ctx->stChnAttr.stFrameRate.s32DstFrameRate),
1424*4882a593Smuzhiyun "dst frame rate(default -1; -1:not control; other:1-src_fps<src_rate>)", NULL, 0, 0),
1425*4882a593Smuzhiyun OPT_INTEGER('\0', "buf_count", &(ctx->stChnAttr.stIspOpt.u32BufCount),
1426*4882a593Smuzhiyun "out buf count, range[1-8] default(3)", NULL, 0, 0),
1427*4882a593Smuzhiyun OPT_INTEGER('U', "user_pic", &(ctx->bUserPicEnabled),
1428*4882a593Smuzhiyun "enable using user specify picture as vi input.", NULL, 0, 0),
1429*4882a593Smuzhiyun OPT_INTEGER('\0', "rgn_type", &(ctx->rgnType),
1430*4882a593Smuzhiyun "rgn type. 0:overlay, 1:overlayEx,2:cover,3:coverEx,4:mosaic,5:moscaiEx", NULL, 0, 0),
1431*4882a593Smuzhiyun OPT_INTEGER('\0', "rgn_cnt", &(ctx->s32RgnCnt),
1432*4882a593Smuzhiyun "rgn count. default(1),max:8", NULL, 0, 0),
1433*4882a593Smuzhiyun OPT_INTEGER('\0', "en_rgn", &(ctx->bEnRgn),
1434*4882a593Smuzhiyun "enable rgn. default(0)", NULL, 0, 0),
1435*4882a593Smuzhiyun OPT_INTEGER('\0', "get_connect_info", &(ctx->bGetConnecInfo),
1436*4882a593Smuzhiyun "get connect info. default(0)", NULL, 0, 0),
1437*4882a593Smuzhiyun OPT_INTEGER('\0', "get_edid", &(ctx->bGetEdid),
1438*4882a593Smuzhiyun "get edid. default(0)", NULL, 0, 0),
1439*4882a593Smuzhiyun OPT_INTEGER('\0', "set_edid", &(ctx->bSetEdid),
1440*4882a593Smuzhiyun "set edid. default(0)", NULL, 0, 0),
1441*4882a593Smuzhiyun
1442*4882a593Smuzhiyun OPT_END(),
1443*4882a593Smuzhiyun };
1444*4882a593Smuzhiyun
1445*4882a593Smuzhiyun struct argparse argparse;
1446*4882a593Smuzhiyun argparse_init(&argparse, options, usages, 0);
1447*4882a593Smuzhiyun argparse_describe(&argparse, "\nselect a test case to run.",
1448*4882a593Smuzhiyun "\nuse --help for details.");
1449*4882a593Smuzhiyun argc = argparse_parse(&argparse, argc, argv);
1450*4882a593Smuzhiyun
1451*4882a593Smuzhiyun if (!ctx->width || !ctx->height) {
1452*4882a593Smuzhiyun argparse_usage(&argparse);
1453*4882a593Smuzhiyun goto __FAILED2;
1454*4882a593Smuzhiyun }
1455*4882a593Smuzhiyun
1456*4882a593Smuzhiyun if (ctx->pipeId != ctx->devId)
1457*4882a593Smuzhiyun ctx->pipeId = ctx->devId;
1458*4882a593Smuzhiyun
1459*4882a593Smuzhiyun if (ctx->stDebugFile.bCfg) {
1460*4882a593Smuzhiyun if (ctx->enMode == TEST_VI_MODE_BIND_VENC || ctx->enMode == TEST_VI_MODE_BIND_VPSS_BIND_VENC) {
1461*4882a593Smuzhiyun ctx->stVencCfg[0].bOutDebugCfg = ctx->stDebugFile.bCfg;
1462*4882a593Smuzhiyun } else if (ctx->enMode == TEST_VI_MODE_BIND_VENC_MULTI) {
1463*4882a593Smuzhiyun ctx->stVencCfg[0].bOutDebugCfg = ctx->stDebugFile.bCfg;
1464*4882a593Smuzhiyun ctx->stVencCfg[1].bOutDebugCfg = ctx->stDebugFile.bCfg;
1465*4882a593Smuzhiyun }
1466*4882a593Smuzhiyun memcpy(&ctx->stDebugFile.aFilePath, "/data", strlen("/data"));
1467*4882a593Smuzhiyun snprintf(ctx->stDebugFile.aFileName, MAX_VI_FILE_PATH_LEN,
1468*4882a593Smuzhiyun "test_%d_%d_%d.bin", ctx->devId, ctx->pipeId, ctx->channelId);
1469*4882a593Smuzhiyun }
1470*4882a593Smuzhiyun for (i = 0; i < ctx->enMode; i++) {
1471*4882a593Smuzhiyun if (ctx->stVencCfg[i].bOutDebugCfg) {
1472*4882a593Smuzhiyun char name[256] = {0};
1473*4882a593Smuzhiyun memcpy(&ctx->stVencCfg[i].dstFilePath, "data", strlen("data"));
1474*4882a593Smuzhiyun snprintf(ctx->stVencCfg[i].dstFileName, sizeof(ctx->stVencCfg[i].dstFileName),
1475*4882a593Smuzhiyun "venc_%d.bin", i);
1476*4882a593Smuzhiyun snprintf(name, sizeof(name), "/%s/%s",
1477*4882a593Smuzhiyun ctx->stVencCfg[i].dstFilePath, ctx->stVencCfg[i].dstFileName);
1478*4882a593Smuzhiyun ctx->stVencCfg[i].fp = fopen(name, "wb");
1479*4882a593Smuzhiyun if (ctx->stVencCfg[i].fp == RK_NULL) {
1480*4882a593Smuzhiyun RK_LOGE("chn %d can't open file %s in get picture thread!\n", i, name);
1481*4882a593Smuzhiyun goto __FAILED;
1482*4882a593Smuzhiyun }
1483*4882a593Smuzhiyun }
1484*4882a593Smuzhiyun }
1485*4882a593Smuzhiyun
1486*4882a593Smuzhiyun RK_LOGE("test running enter ctx->aEntityName=%s!", ctx->aEntityName);
1487*4882a593Smuzhiyun if (ctx->aEntityName != RK_NULL)
1488*4882a593Smuzhiyun memcpy(ctx->stChnAttr.stIspOpt.aEntityName, ctx->aEntityName, strlen(ctx->aEntityName));
1489*4882a593Smuzhiyun
1490*4882a593Smuzhiyun if (ctx->pipeId != ctx->devId)
1491*4882a593Smuzhiyun ctx->pipeId = ctx->devId;
1492*4882a593Smuzhiyun
1493*4882a593Smuzhiyun mpi_vi_test_show_options(ctx);
1494*4882a593Smuzhiyun
1495*4882a593Smuzhiyun if (RK_MPI_SYS_Init() != RK_SUCCESS) {
1496*4882a593Smuzhiyun RK_LOGE("rk mpi sys init fail!");
1497*4882a593Smuzhiyun goto __FAILED;
1498*4882a593Smuzhiyun }
1499*4882a593Smuzhiyun switch (ctx->enMode) {
1500*4882a593Smuzhiyun case TEST_VI_MODE_VI_ONLY:
1501*4882a593Smuzhiyun if (!ctx->stChnAttr.u32Depth) {
1502*4882a593Smuzhiyun RK_LOGE("depth need > 0 when vi not bind any other module!");
1503*4882a593Smuzhiyun ctx->stChnAttr.u32Depth = ctx->stChnAttr.stIspOpt.u32BufCount;
1504*4882a593Smuzhiyun }
1505*4882a593Smuzhiyun s32Ret = test_vi_get_release_frame_loop(ctx);
1506*4882a593Smuzhiyun break;
1507*4882a593Smuzhiyun case TEST_VI_MODE_BIND_VENC:
1508*4882a593Smuzhiyun case TEST_VI_MODE_BIND_VENC_MULTI:
1509*4882a593Smuzhiyun s32Ret = test_vi_bind_venc_loop(ctx);
1510*4882a593Smuzhiyun break;
1511*4882a593Smuzhiyun case TEST_VI_MODE_BIND_VPSS_BIND_VENC:
1512*4882a593Smuzhiyun s32Ret = test_vi_bind_vpss_venc_loop(ctx);
1513*4882a593Smuzhiyun break;
1514*4882a593Smuzhiyun case TEST_VI_MODE_BIND_VO:
1515*4882a593Smuzhiyun s32Ret = test_vi_bind_vo_loop(ctx);
1516*4882a593Smuzhiyun break;
1517*4882a593Smuzhiyun case TEST_VI_MODE_MUTI_VI:
1518*4882a593Smuzhiyun s32Ret = test_vi_muti_vi_loop(ctx);
1519*4882a593Smuzhiyun break;
1520*4882a593Smuzhiyun default:
1521*4882a593Smuzhiyun RK_LOGE("no support such test mode:%d", ctx->enMode);
1522*4882a593Smuzhiyun break;
1523*4882a593Smuzhiyun }
1524*4882a593Smuzhiyun __FAILED:
1525*4882a593Smuzhiyun RK_LOGE("test running exit:%d", s32Ret);
1526*4882a593Smuzhiyun RK_MPI_SYS_Exit();
1527*4882a593Smuzhiyun __FAILED2:
1528*4882a593Smuzhiyun if (ctx) {
1529*4882a593Smuzhiyun free(ctx);
1530*4882a593Smuzhiyun ctx = RK_NULL;
1531*4882a593Smuzhiyun }
1532*4882a593Smuzhiyun
1533*4882a593Smuzhiyun return 0;
1534*4882a593Smuzhiyun }
1535