- Main Page
- Modules
- Namespaces
- Classes
- Files

- Search for |

- File List
- File Members

# samples/04_video_dec_gie/video_dec_gie_csvparser.cpp

Go to the documentation of this file.

    00001 /*
    00002  * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
    00003  *
    00004  * Redistribution and use in source and binary forms, with or without
    00005  * modification, are permitted provided that the following conditions
    00006  * are met:
    00007  *  * Redistributions of source code must retain the above copyright
    00008  *    notice, this list of conditions and the following disclaimer.
    00009  *  * Redistributions in binary form must reproduce the above copyright
    00010  *    notice, this list of conditions and the following disclaimer in the
    00011  *    documentation and/or other materials provided with the distribution.
    00012  *  * Neither the name of NVIDIA CORPORATION nor the names of its
    00013  *    contributors may be used to endorse or promote products derived
    00014  *    from this software without specific prior written permission.
    00015  *
    00016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
    00017  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    00018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    00019  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    00020  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    00021  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    00022  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    00023  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
    00024  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    00026  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    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 }