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