• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2023 Shenzhen Kaihong DID Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * 		http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "command_parse.h"
16 #include <getopt.h>
17 #include <iostream>
18 enum class MyOptIndex {
19     OPT_INDEX_UNKONWN = 0,
20     OPT_INDEX_BUFFER_HANDLE,
21     OPT_INDEX_HEVC,
22     OPT_INDEX_HELP,
23     OPT_INDEX_HEIGHT = 'h',
24     OPT_INDEX_INPUT = 'i',
25     OPT_INDEX_OUTPUT = 'o',
26     OPT_INDEX_WIDTH = 'w'
27 };
Parse(int argc,char * argv[],CommandOpt & opt)28 bool CommandParse::Parse(int argc, char *argv[], CommandOpt &opt)
29 {
30     while (1) {
31         int optionIndex = 0;
32         static struct option long_options[] = {
33             {"width", required_argument, 0, static_cast<int>(MyOptIndex::OPT_INDEX_WIDTH)},
34             {"height", required_argument, 0, static_cast<int>(MyOptIndex::OPT_INDEX_HEIGHT)},
35             {"in", required_argument, 0, static_cast<int>(MyOptIndex::OPT_INDEX_INPUT)},
36             {"out", required_argument, 0, static_cast<int>(MyOptIndex::OPT_INDEX_OUTPUT)},
37             {"nocopy", no_argument, nullptr, static_cast<int>(MyOptIndex::OPT_INDEX_BUFFER_HANDLE)},
38             {"HEVC", no_argument, nullptr, static_cast<int>(MyOptIndex::OPT_INDEX_HEVC)},
39             {"help", no_argument, nullptr, static_cast<int>(MyOptIndex::OPT_INDEX_HELP)},
40             {0, 0, 0, static_cast<int>(MyOptIndex::OPT_INDEX_UNKONWN)}
41         };
42         int c = getopt_long(argc, argv, "i:o:w:h:", long_options, &optionIndex);
43         if (c == -1) {
44             break;
45         }
46         MyOptIndex index = (MyOptIndex)c;
47         switch (index) {
48             case MyOptIndex::OPT_INDEX_BUFFER_HANDLE:
49                 opt.useBuffer = true;
50                 break;
51             case MyOptIndex::OPT_INDEX_HEVC:
52                 opt.codec = codecMime::HEVC;
53                 break;
54             case MyOptIndex::OPT_INDEX_HELP:
55                 ShowUsage();
56                 break;
57             case MyOptIndex::OPT_INDEX_INPUT:
58                 opt.fileInput = optarg;
59                 break;
60             case MyOptIndex::OPT_INDEX_OUTPUT:
61                 opt.fileOutput = optarg;
62                 break;
63             case MyOptIndex::OPT_INDEX_WIDTH:
64                 opt.width = atoi(optarg);
65                 break;
66             case MyOptIndex::OPT_INDEX_HEIGHT:
67                 opt.height = atoi(optarg);
68                 break;
69             default:
70                 ShowUsage();
71                 break;
72         }
73     }
74     if (opt.fileInput.empty() || opt.fileOutput.empty() || opt.width == 0 || opt.height == 0) {
75         return false;
76     }
77     return true;
78 }
79 
ShowUsage()80 void CommandParse::ShowUsage()
81 {
82     std::cout << "Options:" << std::endl;
83     std::cout << " -w, --width=width          The video width." << std::endl;
84     std::cout << " -h, --height=height        The video height." << std::endl;
85     std::cout << " -o, --out=FILE             The file name for output file." << std::endl;
86     std::cout << " -i, --in=FILE              The file name for input file." << std::endl;
87     std::cout << " --HEVC                     HEVC decode or HEVC encode, AVC for default." << std::endl;
88     std::cout << " --nocopy                   Support BufferHandle." << std::endl;
89     std::cout << " --help                     The help info." << std::endl;
90 }
91