00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <iostream>
00030 #include <cstdlib>
00031 #include <cstring>
00032 #ifdef ENABLE_GIE
00033 #include "gie_inference.h"
00034 #endif
00035 #include "v4l2_backend_test.h"
00036
00037 #define CHECK_OPTION_VALUE(argp) if(!*argp || (*argp)[0] == '-') \
00038 { \
00039 cerr << "Error: value not specified for option " << arg << endl; \
00040 goto error; \
00041 }
00042
00043 #define CSV_PARSE_CHECK_ERROR(condition, str) \
00044 if (condition) {\
00045 cerr << "Error: " << str << endl; \
00046 goto error; \
00047 }
00048
00049 using namespace std;
00050
00051 void
00052 print_help(void)
00053 {
00054 cerr << "\nbackend <channel-num> <in-file1> <in-file2>... <in-format> [options]\n\n"
00055 "Channel-num:\n"
00056 "\t1-4, Number of file arguments should exactly match the number of channels specified\n\n"
00057 "Supported formats:\n"
00058 "\tH264\n"
00059 "\tH265\n\n"
00060 "OPTIONS:\n"
00061 "\t-h,--help Prints this text\n"
00062 "\t-fps <fps> Display rate in frames per second [Default = 30]\n\n"
00063 "\t--s Give a statistic of each channel\n"
00064 "\t-run-opt <0-3> 0[default], 1 parser only, 2 parser+decoder, 3 parser+decoder+VIC\n"
00065 "\t--input-nalu Input to the decoder will be nal units[Default]\n"
00066 "\t--input-chunks Input to the decoder will be a chunk of bytes\n\n"
00067 #ifdef ENABLE_GIE
00068 "\t--gie-deployfile set deploy file name\n"
00069 "\t--gie-modelfile set model file name\n"
00070 "\t--gie-proc-interval set process interval, 1 frame will be process every gie-proc-interval\n"
00071 "\t--gie-forcefp32 0 to use fp16 (if supported), 1 to use fp32\n"
00072 "\t--gie-dumpresult 1 to dump result, 0[default] otherwise\n"
00073 "\t--gie-enable-perf 1[default] to enable perf measurement, 0 otherwise\n"
00074 #endif
00075 << endl;
00076 }
00077
00078 static uint32_t
00079 get_decoder_type(char *arg)
00080 {
00081 if (!strcmp(arg, "H264"))
00082 return V4L2_PIX_FMT_H264;
00083 if (!strcmp(arg, "H265"))
00084 return V4L2_PIX_FMT_H265;
00085 return 0;
00086 }
00087
00088 int
00089 parse_csv_args(context_t * ctx,
00090 #ifdef ENABLE_GIE
00091 GIE_Context *gie_ctx,
00092 #endif
00093 int argc, char *argv[])
00094 {
00095 char **argp = argv;
00096 char *arg = *(++argp);
00097
00098 ctx->decoder_pixfmt = get_decoder_type(*argp);
00099 CSV_PARSE_CHECK_ERROR(ctx->decoder_pixfmt == 0,
00100 "Incorrect input format");
00101
00102 while ((arg = *(++argp)))
00103 {
00104 if (!strcmp(arg, "-o"))
00105 {
00106 argp++;
00107 CHECK_OPTION_VALUE(argp);
00108 ctx->out_file_path = strdup(*argp);
00109 CSV_PARSE_CHECK_ERROR(!ctx->out_file_path,
00110 "Output file not specified");
00111 }
00112 else if (!strcmp(arg, "--disable-dpb"))
00113 {
00114 ctx->disable_dpb = true;
00115 }
00116 else if (!strcmp(arg, "--fullscreen"))
00117 {
00118 ctx->fullscreen = true;
00119 }
00120 else if (!strcmp(arg, "-wh"))
00121 {
00122 argp++;
00123 CHECK_OPTION_VALUE(argp);
00124 ctx->window_height = atoi(*argp);
00125 CSV_PARSE_CHECK_ERROR(ctx->window_height == 0,
00126 "Window height should be > 0");
00127 }
00128 else if (!strcmp(arg, "-ww"))
00129 {
00130 argp++;
00131 CHECK_OPTION_VALUE(argp);
00132 ctx->window_width = atoi(*argp);
00133 CSV_PARSE_CHECK_ERROR(ctx->window_width == 0,
00134 "Window width should be > 0");
00135 }
00136 else if (!strcmp(arg, "-wx"))
00137 {
00138 argp++;
00139 CHECK_OPTION_VALUE(argp);
00140 ctx->window_x = atoi(*argp);
00141 }
00142 else if (!strcmp(arg, "-wy"))
00143 {
00144 argp++;
00145 CHECK_OPTION_VALUE(argp);
00146 ctx->window_y = atoi(*argp);
00147 }
00148 else if (!strcmp(arg, "-fps"))
00149 {
00150 argp++;
00151 CHECK_OPTION_VALUE(argp);
00152 ctx->fps = atof(*argp);
00153 CSV_PARSE_CHECK_ERROR(ctx->fps == 0, "FPS should be > 0");
00154 }
00155 else if (!strcmp(arg, "-run-opt"))
00156 {
00157 argp++;
00158 ctx->cpu_occupation_option = atoi(*argp);
00159 CSV_PARSE_CHECK_ERROR(ctx->cpu_occupation_option < 0 ||
00160 ctx->cpu_occupation_option >3,
00161 "parameter error:run-opt should be 0-3");
00162 }
00163 else if (!strcmp(arg, "--s"))
00164 {
00165 ctx->do_stat = true;
00166 }
00167 else if (!strcmp(arg, "--input-nalu"))
00168 {
00169 ctx->input_nalu = true;
00170 }
00171 else if (!strcmp(arg, "--input-chunks"))
00172 {
00173 ctx->input_nalu = false;
00174 }
00175 else if (!strcmp(arg, "--dbg-level"))
00176 {
00177 argp++;
00178 CHECK_OPTION_VALUE(argp);
00179 log_level = atoi(*argp);
00180 }
00181 else if (!strcmp(arg, "-h") || !strcmp(arg, "--help"))
00182 {
00183 print_help();
00184 exit(EXIT_SUCCESS);
00185 }
00186 #ifdef ENABLE_GIE
00187 else if (!strcmp(arg, "--gie-deployfile"))
00188 {
00189 argp++;
00190
00191
00192 continue;
00193 }
00194 else if (!strcmp(arg, "--gie-modelfile"))
00195 {
00196 argp++;
00197
00198
00199 continue;
00200 }
00201 else if (!strcmp(arg, "--gie-forcefp32"))
00202 {
00203 argp++;
00204 gie_ctx->setForcedFp32((bool)atoi(*argp));
00205 }
00206 else if (!strcmp(arg, "--gie-proc-interval"))
00207 {
00208 argp++;
00209 gie_ctx->setFilterNum(atoi(*argp));
00210 }
00211 else if (!strcmp(arg, "--gie-dumpresult"))
00212 {
00213 if (*(argp + 1) != NULL &&
00214 (strcmp(*(argp + 1), "0") == 0 ||
00215 strcmp(*(argp + 1), "1") == 0))
00216 {
00217 argp++;
00218 gie_ctx->setDumpResult((bool)atoi(*argp));
00219 }
00220 }
00221 else if (!strcmp(arg, "--gie-enable-perf"))
00222 {
00223 if (*(argp + 1) != NULL &&
00224 (strcmp(*(argp + 1), "0") == 0 ||
00225 strcmp(*(argp + 1), "1") == 0))
00226 {
00227 argp++;
00228 gie_ctx->setGieProfilerEnabled((bool)atoi(*argp));
00229 }
00230 }
00231 #endif
00232 else
00233 {
00234 CSV_PARSE_CHECK_ERROR(ctx->out_file_path,
00235 "Unknown option " << arg);
00236 }
00237 }
00238
00239 return 0;
00240
00241 error:
00242 print_help();
00243 return -1;
00244 }
00245
00246 void
00247 parse_global(global_cfg* cfg, int argc, char ***argv)
00248 {
00249 char **argp = *argv;
00250 char *arg = *(++argp);
00251 if (argc == 1 || (arg && (!strcmp(arg, "-h") || !strcmp(arg, "--help"))))
00252 {
00253 print_help();
00254 exit(1);
00255 }
00256 cfg->channel_num = atoi(*argp);
00257 CSV_PARSE_CHECK_ERROR(cfg->channel_num < 1 || cfg->channel_num > 4,
00258 "channel should be between 1 and 4, program will exit");
00259
00260 for (int i = 0; i < cfg->channel_num; i++)
00261 {
00262 if (*(argp + 1) != NULL && strcmp(*(argp + 1), "H264") != 0 &&
00263 strcmp(*(argp + 1), "H265") != 0)
00264 {
00265 cfg->in_file_path[i] = strdup(*(++argp));
00266 }
00267 else
00268 {
00269 cout << "Not enough number of files provided" << endl;
00270 print_help();
00271 exit(1);
00272 }
00273 }
00274
00275 *argv = argp;
00276
00277 #ifdef ENABLE_GIE
00278
00279 while ((arg = *(++argp)))
00280 {
00281 if (!strcmp(arg, "--gie-deployfile"))
00282 {
00283 argp++;
00284 cfg->deployfile = *argp;
00285 }
00286 else if (!strcmp(arg, "--gie-modelfile"))
00287 {
00288 argp++;
00289 cfg->modelfile = *argp;
00290 }
00291 }
00292 #endif
00293 return;
00294
00295 error:
00296 exit(EXIT_SUCCESS);
00297 }