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
00033 #include "gie_inference.h"
00034 #include "video_dec_gie.h"
00035
00036 #define CHECK_OPTION_VALUE(argp) \
00037 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 static void
00052 printHelp(void)
00053 {
00054 cerr << "\nvideo_dec_gie <in-file> <in-format> [options]\n\n"
00055 "Supported formats:\n"
00056 "\tH264\n"
00057 "\tH265\n\n"
00058 "OPTIONS:\n"
00059 "\t-h,--help Prints this text\n"
00060 "\t--dbg-level <level> Sets the debug level [Values 0-3]\n\n"
00061 "\t--gie-deployfile set deploy file name\n"
00062 "\t--gie-modelfile set model file name\n"
00063 "\t--gie-forcefp32 0 to use fp16 (if supported), 1 to use fp32\n"
00064 "\t--gie-enable-perf 1[default] to enable perf measurement, 0 otherwise\n";
00065 }
00066
00067 static uint32_t
00068 getDecoderType(char *arg)
00069 {
00070 if (!strcmp(arg, "H264"))
00071 return V4L2_PIX_FMT_H264;
00072 if (!strcmp(arg, "H265"))
00073 return V4L2_PIX_FMT_H265;
00074 return 0;
00075 }
00076
00077 static int32_t
00078 get_dbg_level(char *arg)
00079 {
00080 int32_t log_level = atoi(arg);
00081 if (log_level < 0)
00082 {
00083 cout<<"log level too small, set to 0"<<endl;
00084 return 0;
00085 }
00086
00087 if (log_level > 3)
00088 {
00089 cout<<"log level too high, set to 3"<<endl;
00090 return 3;
00091 }
00092
00093 return log_level;
00094 }
00095
00096 int
00097 parseCsvArgs(context_t * ctx, GIE_Context *gie_ctx, int argc, char *argv[])
00098 {
00099 char **argp = argv;
00100 char *arg = *(++argp);
00101
00102 if (argc == 1 || (arg && (!strcmp(arg, "-h") || !strcmp(arg, "--help"))))
00103 {
00104 printHelp();
00105 exit(EXIT_SUCCESS);
00106 }
00107
00108 CSV_PARSE_CHECK_ERROR(argc < 3, "Insufficient arguments");
00109
00110 ctx->in_file_path = strdup(*argp);
00111 CSV_PARSE_CHECK_ERROR(!ctx->in_file_path, "Input file not specified");
00112
00113 ctx->decoder_pixfmt = getDecoderType(*(++argp));
00114 CSV_PARSE_CHECK_ERROR(ctx->decoder_pixfmt == 0,
00115 "Incorrect input format");
00116
00117 while ((arg = *(++argp)))
00118 {
00119 if (!strcmp(arg, "--dbg-level"))
00120 {
00121 argp++;
00122 CHECK_OPTION_VALUE(argp);
00123 log_level = get_dbg_level(*argp);
00124 }
00125 else if (!strcmp(arg, "-h") || !strcmp(arg, "--help"))
00126 {
00127 printHelp();
00128 exit(EXIT_SUCCESS);
00129 }
00130 else if (!strcmp(arg, "--gie-deployfile"))
00131 {
00132 argp++;
00133 ctx->deployfile = *argp;
00134 cout<< "set deployfile: " << *argp << endl;
00135 }
00136 else if (!strcmp(arg, "--gie-modelfile"))
00137 {
00138 argp++;
00139 ctx->modelfile = *argp;
00140 cout<< "set modefile: " << *argp << endl;
00141 }
00142 else if (!strcmp(arg, "--gie-forcefp32"))
00143 {
00144 argp++;
00145 gie_ctx->setForcedFp32(atoi(*argp));
00146 }
00147 else if (!strcmp(arg, "--gie-enable-perf"))
00148 {
00149 if (*(argp + 1) != NULL &&
00150 (strcmp(*(argp + 1), "0") == 0 ||
00151 strcmp(*(argp + 1), "1") == 0))
00152 {
00153 argp++;
00154 gie_ctx->setGieProfilerEnabled((bool)atoi(*argp));
00155 }
00156 }
00157 else
00158 {
00159 CSV_PARSE_CHECK_ERROR(1, "Unknown option " << arg);
00160 }
00161 }
00162
00163 return 0;
00164
00165 error:
00166 printHelp();
00167 return -1;
00168 }