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 #undef DBG_MOD_ID
18*4882a593Smuzhiyun #define DBG_MOD_ID RK_ID_VPSS
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun #include <string.h>
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun #include "test_comm_argparse.h"
23*4882a593Smuzhiyun #include "test_mod_vpss.h"
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun #include "rk_debug.h"
26*4882a593Smuzhiyun #include "rk_mpi_sys.h"
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun static const char *const usages[] = {
29*4882a593Smuzhiyun "./rk_mpi_vpss_test [-i SRC_PATH] [-w SRC_WIDTH] [-h SRC_HEIGHT] [-W DST_WIDTH] [-H DST_HEIGHT]...",
30*4882a593Smuzhiyun NULL,
31*4882a593Smuzhiyun };
32*4882a593Smuzhiyun
mpi_vpss_test_show_options(const TEST_VPSS_CTX_S * ctx)33*4882a593Smuzhiyun static void mpi_vpss_test_show_options(const TEST_VPSS_CTX_S *ctx) {
34*4882a593Smuzhiyun RK_PRINT("cmd parse result:\n");
35*4882a593Smuzhiyun RK_PRINT("input file name : %s\n", ctx->srcFileName);
36*4882a593Smuzhiyun RK_PRINT("output file name : %s\n", ctx->dstFilePath);
37*4882a593Smuzhiyun RK_PRINT("loop count : %d\n", ctx->s32LoopCount);
38*4882a593Smuzhiyun RK_PRINT("video process device : %d\n", ctx->s32VProcDevType);
39*4882a593Smuzhiyun RK_PRINT("group number : %d\n", ctx->s32GrpNum);
40*4882a593Smuzhiyun RK_PRINT("channel number : %d\n", ctx->s32ChnNum);
41*4882a593Smuzhiyun RK_PRINT("group crop enabled : %d\n", ctx->bGrpCropEn ? 1 : 0);
42*4882a593Smuzhiyun RK_PRINT("chn crop enabled : %d\n", ctx->bChnCropEn ? 1 : 0);
43*4882a593Smuzhiyun RK_PRINT("group crop ratio : %d\n", ctx->s32GrpCropRatio);
44*4882a593Smuzhiyun RK_PRINT("chn crop ratio : %d\n", ctx->s32ChnCropRatio);
45*4882a593Smuzhiyun RK_PRINT("input width : %d\n", ctx->s32SrcWidth);
46*4882a593Smuzhiyun RK_PRINT("input height : %d\n", ctx->s32SrcHeight);
47*4882a593Smuzhiyun RK_PRINT("input virtual width : %d\n", ctx->s32SrcVirWidth);
48*4882a593Smuzhiyun RK_PRINT("input virtual height : %d\n", ctx->s32SrcVirHeight);
49*4882a593Smuzhiyun RK_PRINT("input compress mode : %d\n", ctx->s32SrcCompressMode);
50*4882a593Smuzhiyun RK_PRINT("input pixel format : %d\n", ctx->s32SrcPixFormat);
51*4882a593Smuzhiyun RK_PRINT("output width : %d\n", ctx->s32DstWidth);
52*4882a593Smuzhiyun RK_PRINT("output height : %d\n", ctx->s32DstHeight);
53*4882a593Smuzhiyun RK_PRINT("output compress mode : %d\n", ctx->s32DstCompressMode);
54*4882a593Smuzhiyun RK_PRINT("output pixel format : %d\n", ctx->s32DstPixFormat);
55*4882a593Smuzhiyun RK_PRINT("fixed rotation : %d\n", ctx->s32Rotation);
56*4882a593Smuzhiyun RK_PRINT("any rotation angle : %d\n", ctx->s32RotationEx);
57*4882a593Smuzhiyun RK_PRINT("enable mirror : %d\n", ctx->s32Mirror);
58*4882a593Smuzhiyun RK_PRINT("enable flip : %d\n", ctx->s32Flip);
59*4882a593Smuzhiyun RK_PRINT("enable attach mb pool : %d\n", ctx->bAttachPool);
60*4882a593Smuzhiyun }
61*4882a593Smuzhiyun
main(int argc,const char ** argv)62*4882a593Smuzhiyun RK_S32 main(int argc, const char **argv) {
63*4882a593Smuzhiyun RK_S32 s32Ret;
64*4882a593Smuzhiyun TEST_VPSS_CTX_S ctx;
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun memset(&ctx, 0, sizeof(TEST_VPSS_CTX_S));
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun // set default params.
69*4882a593Smuzhiyun ctx.dstFilePath = RK_NULL;
70*4882a593Smuzhiyun ctx.s32LoopCount = 1;
71*4882a593Smuzhiyun ctx.s32VProcDevType = VIDEO_PROC_DEV_GPU;
72*4882a593Smuzhiyun ctx.s32GrpNum = 1;
73*4882a593Smuzhiyun ctx.s32ChnNum = 1;
74*4882a593Smuzhiyun ctx.bGrpCropEn = RK_FALSE;
75*4882a593Smuzhiyun ctx.bChnCropEn = RK_FALSE;
76*4882a593Smuzhiyun ctx.s32GrpCropRatio = 1000;
77*4882a593Smuzhiyun ctx.s32ChnCropRatio = 1000;
78*4882a593Smuzhiyun ctx.s32SrcCompressMode = 0;
79*4882a593Smuzhiyun ctx.s32SrcPixFormat = RK_FMT_YUV420SP;
80*4882a593Smuzhiyun ctx.s32DstCompressMode = 0;
81*4882a593Smuzhiyun ctx.s32DstPixFormat = RK_FMT_YUV420SP;
82*4882a593Smuzhiyun ctx.s32GrpIndex = 0;
83*4882a593Smuzhiyun ctx.u32ChnDepth = 8;
84*4882a593Smuzhiyun ctx.s32SrcChnRate = -1;
85*4882a593Smuzhiyun ctx.s32DstChnRate = -1;
86*4882a593Smuzhiyun ctx.s32SrcGrpRate = -1;
87*4882a593Smuzhiyun ctx.s32DstGrpRate = -1;
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun struct argparse_option options[] = {
90*4882a593Smuzhiyun OPT_HELP(),
91*4882a593Smuzhiyun OPT_GROUP("basic options:"),
92*4882a593Smuzhiyun OPT_STRING('i', "input", &(ctx.srcFileName),
93*4882a593Smuzhiyun "input file name. e.g.(/userdata/1080p.nv12). default(NULL)", NULL, 0, 0),
94*4882a593Smuzhiyun OPT_STRING('o', "output", &(ctx.dstFilePath),
95*4882a593Smuzhiyun "output file path. e.g.(/userdata/vpss/). default(NULL).", NULL, 0, 0),
96*4882a593Smuzhiyun OPT_INTEGER('n', "loop_count", &(ctx.s32LoopCount),
97*4882a593Smuzhiyun "loop running count. default(1)", NULL, 0, 0),
98*4882a593Smuzhiyun OPT_INTEGER('\0', "video_proc_dev_type", &(ctx.s32VProcDevType),
99*4882a593Smuzhiyun "the device type of video process. default(0. 0 is GPU, 1 is RGA)", NULL, 0, 0),
100*4882a593Smuzhiyun OPT_INTEGER('g', "group_count", &(ctx.s32GrpNum),
101*4882a593Smuzhiyun "the count of vpss group. default(1).", NULL, 0, 0),
102*4882a593Smuzhiyun OPT_INTEGER('c', "channel_count", &(ctx.s32ChnNum),
103*4882a593Smuzhiyun "the count of vpss channel. default(1).", NULL, 0, 0),
104*4882a593Smuzhiyun OPT_BOOLEAN('\0', "group_crop_en", &(ctx.bGrpCropEn),
105*4882a593Smuzhiyun "vpss group crop is enabled. default(0).", NULL, 0, 0),
106*4882a593Smuzhiyun OPT_BOOLEAN('\0', "channel_crop_en", &(ctx.bChnCropEn),
107*4882a593Smuzhiyun "vpss channel crop is enabled. default(0)", NULL, 0, 0),
108*4882a593Smuzhiyun OPT_INTEGER('\0', "group_crop_ratio", &(ctx.s32GrpCropRatio),
109*4882a593Smuzhiyun "vpss group crop ratio. range(1,1000). default(1000)", NULL, 0, 0),
110*4882a593Smuzhiyun OPT_INTEGER('\0', "channel_crop_ratio", &(ctx.s32ChnCropRatio),
111*4882a593Smuzhiyun "vpss channel crop ratio. range(1,1000). default(1000)", NULL, 0, 0),
112*4882a593Smuzhiyun OPT_INTEGER('w', "src_width", &(ctx.s32SrcWidth),
113*4882a593Smuzhiyun "src width. e.g.(1920). <required>", NULL, 0, 0),
114*4882a593Smuzhiyun OPT_INTEGER('h', "src_height", &(ctx.s32SrcHeight),
115*4882a593Smuzhiyun "src height. e.g.(1080). <required>", NULL, 0, 0),
116*4882a593Smuzhiyun OPT_INTEGER('\0', "src_vir_width", &(ctx.s32SrcVirWidth),
117*4882a593Smuzhiyun "src virtual width. e.g.(1920). default(0)", NULL, 0, 0),
118*4882a593Smuzhiyun OPT_INTEGER('\0', "src_vir_height", &(ctx.s32SrcVirHeight),
119*4882a593Smuzhiyun "src virtual height. e.g.(1080). default(0)", NULL, 0, 0),
120*4882a593Smuzhiyun OPT_INTEGER('m', "src_compress", &(ctx.s32SrcCompressMode),
121*4882a593Smuzhiyun "src compress mode. default(0).", NULL, 0, 0),
122*4882a593Smuzhiyun OPT_INTEGER('f', "src_format", &(ctx.s32SrcPixFormat),
123*4882a593Smuzhiyun "src pixel format. default(0. 0 is NV12).", NULL, 0, 0),
124*4882a593Smuzhiyun OPT_INTEGER('W', "dst_width", &(ctx.s32DstWidth),
125*4882a593Smuzhiyun "dst width. e.g.(1920). <required>", NULL, 0, 0),
126*4882a593Smuzhiyun OPT_INTEGER('H', "dst_height", &(ctx.s32DstHeight),
127*4882a593Smuzhiyun "dst height. e.g.(1080). <required>", NULL, 0, 0),
128*4882a593Smuzhiyun OPT_INTEGER('M', "dst_compress", &(ctx.s32DstCompressMode),
129*4882a593Smuzhiyun "dst compress mode. default(0).", NULL, 0, 0),
130*4882a593Smuzhiyun OPT_INTEGER('F', "dst_format", &(ctx.s32DstPixFormat),
131*4882a593Smuzhiyun "dst pixel format. default(0. 0 is NV12).", NULL, 0, 0),
132*4882a593Smuzhiyun OPT_INTEGER('r', "rotation", &(ctx.s32Rotation),
133*4882a593Smuzhiyun "fixed rotation angle. default(0). 0: 0. 1: 90. 2: 180. 3: 270", NULL, 0, 0),
134*4882a593Smuzhiyun OPT_INTEGER('\0', "grp_rotation", &(ctx.s32GrpRotation),
135*4882a593Smuzhiyun "fixed group rotation angle. default(0). 0: 0. 1: 90. 2: 180. 3: 270", NULL, 0, 0),
136*4882a593Smuzhiyun OPT_INTEGER('R', "rotation_ex", &(ctx.s32RotationEx),
137*4882a593Smuzhiyun "any rotation angle. default(0). ", NULL, 0, 0),
138*4882a593Smuzhiyun OPT_INTEGER('a', "attach_mb_pool", &(ctx.bAttachPool),
139*4882a593Smuzhiyun "enable attach mb pool or not, default(0), 0: RK_FALSE, 1: RK_TRUE", NULL, 0, 0),
140*4882a593Smuzhiyun OPT_INTEGER('\0', "chn_mode", &(ctx.s32ChnMode),
141*4882a593Smuzhiyun "channel mode, default(0), 0: USER, 1: AUTO, 2: PASS-THOUGH", NULL, 0, 0),
142*4882a593Smuzhiyun OPT_INTEGER('d', "chn_depth", &(ctx.u32ChnDepth),
143*4882a593Smuzhiyun "channel output depth, default(8)", NULL, 0, 0),
144*4882a593Smuzhiyun OPT_INTEGER('\0', "mirror", &(ctx.s32Mirror),
145*4882a593Smuzhiyun "picture mirror, default(0)", NULL, 0, 0),
146*4882a593Smuzhiyun OPT_INTEGER('\0', "flip", &(ctx.s32Flip),
147*4882a593Smuzhiyun "picture flip, default(0)", NULL, 0, 0),
148*4882a593Smuzhiyun OPT_INTEGER('\0', "src_chn_rate", &(ctx.s32SrcChnRate),
149*4882a593Smuzhiyun "src vpss channel frame rate, default(-1)", NULL, 0, 0),
150*4882a593Smuzhiyun OPT_INTEGER('\0', "dst_chn_rate", &(ctx.s32DstChnRate),
151*4882a593Smuzhiyun "dst vpss channel frame rate, default(-1)", NULL, 0, 0),
152*4882a593Smuzhiyun OPT_INTEGER('\0', "src_grp_rate", &(ctx.s32SrcGrpRate),
153*4882a593Smuzhiyun "src vpss group frame rate, default(-1)", NULL, 0, 0),
154*4882a593Smuzhiyun OPT_INTEGER('\0', "dst_grp_rate", &(ctx.s32DstGrpRate),
155*4882a593Smuzhiyun "dst vpss group frame rate, default(-1)", NULL, 0, 0),
156*4882a593Smuzhiyun OPT_END(),
157*4882a593Smuzhiyun };
158*4882a593Smuzhiyun
159*4882a593Smuzhiyun struct argparse argparse;
160*4882a593Smuzhiyun argparse_init(&argparse, options, usages, 0);
161*4882a593Smuzhiyun argparse_describe(&argparse, "\nselect a test case to run.",
162*4882a593Smuzhiyun "\nuse --help for details.");
163*4882a593Smuzhiyun
164*4882a593Smuzhiyun argc = argparse_parse(&argparse, argc, argv);
165*4882a593Smuzhiyun mpi_vpss_test_show_options(&ctx);
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun if (ctx.s32SrcWidth <= 0
168*4882a593Smuzhiyun || ctx.s32SrcHeight <= 0
169*4882a593Smuzhiyun || ctx.s32DstWidth <= 0
170*4882a593Smuzhiyun || ctx.s32DstHeight <= 0) {
171*4882a593Smuzhiyun argparse_usage(&argparse);
172*4882a593Smuzhiyun return RK_FAILURE;
173*4882a593Smuzhiyun }
174*4882a593Smuzhiyun
175*4882a593Smuzhiyun s32Ret = RK_MPI_SYS_Init();
176*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
177*4882a593Smuzhiyun return s32Ret;
178*4882a593Smuzhiyun }
179*4882a593Smuzhiyun
180*4882a593Smuzhiyun s32Ret = TEST_VPSS_ModTest(&ctx);
181*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
182*4882a593Smuzhiyun goto __FAILED;
183*4882a593Smuzhiyun }
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun s32Ret = RK_MPI_SYS_Exit();
186*4882a593Smuzhiyun if (s32Ret != RK_SUCCESS) {
187*4882a593Smuzhiyun return s32Ret;
188*4882a593Smuzhiyun }
189*4882a593Smuzhiyun RK_LOGI("test running ok.");
190*4882a593Smuzhiyun return RK_SUCCESS;
191*4882a593Smuzhiyun
192*4882a593Smuzhiyun __FAILED:
193*4882a593Smuzhiyun RK_MPI_SYS_Exit();
194*4882a593Smuzhiyun RK_LOGE("test running failed!");
195*4882a593Smuzhiyun return s32Ret;
196*4882a593Smuzhiyun }
197