1 | |
---|
2 | |
---|
3 | /** \file TAppDecCfg.cpp |
---|
4 | \brief Decoder configuration class |
---|
5 | */ |
---|
6 | |
---|
7 | #include <cstdio> |
---|
8 | #include <cstring> |
---|
9 | #include <string> |
---|
10 | #include "TAppDecCfg.h" |
---|
11 | #include "../../App/TAppCommon/program_options_lite.h" |
---|
12 | |
---|
13 | #ifdef WIN32 |
---|
14 | #define strdup _strdup |
---|
15 | #endif |
---|
16 | |
---|
17 | using namespace std; |
---|
18 | namespace po = df::program_options_lite; |
---|
19 | |
---|
20 | // ==================================================================================================================== |
---|
21 | // Public member functions |
---|
22 | // ==================================================================================================================== |
---|
23 | |
---|
24 | /** \param argc number of arguments |
---|
25 | \param argv array of arguments |
---|
26 | */ |
---|
27 | Bool TAppDecCfg::parseCfg( Int argc, Char* argv[] ) |
---|
28 | { |
---|
29 | bool do_help = false; |
---|
30 | string cfg_BitstreamFile; |
---|
31 | string cfg_ReconFile; |
---|
32 | string cfg_ScaleOffsetFile; |
---|
33 | |
---|
34 | po::Options opts; |
---|
35 | opts.addOptions() |
---|
36 | ("help", do_help, false, "this help text") |
---|
37 | ("BitstreamFile,b", cfg_BitstreamFile, string(""), "bitstream input file name") |
---|
38 | ("ReconFile,o", cfg_ReconFile, string(""), "reconstructed YUV output file name\n" |
---|
39 | "YUV writing is skipped if omitted") |
---|
40 | ("ScaleOffsetFile,p", cfg_ScaleOffsetFile, string(""), "file with coded scales and offsets") |
---|
41 | #if DCM_SKIP_DECODING_FRAMES |
---|
42 | ("SkipFrames,s", m_iSkipFrame, 0, "number of frames to skip before random access") |
---|
43 | #endif |
---|
44 | ("OutputBitDepth,d", m_outputBitDepth, 0u, "bit depth of YUV output file (use 0 for native depth)") |
---|
45 | ("SEIpictureDigest", m_pictureDigestEnabled, false, "Control handling of picture_digest SEI messages\n" |
---|
46 | "\t1: check\n" |
---|
47 | "\t0: ignore") |
---|
48 | ; |
---|
49 | |
---|
50 | po::setDefaults(opts); |
---|
51 | const list<const char*>& argv_unhandled = po::scanArgv(opts, argc, (const char**) argv); |
---|
52 | |
---|
53 | for (list<const char*>::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++) |
---|
54 | { |
---|
55 | fprintf(stderr, "Unhandled argument ignored: `%s'\n", *it); |
---|
56 | } |
---|
57 | |
---|
58 | if (argc == 1 || do_help) |
---|
59 | { |
---|
60 | po::doHelp(cout, opts); |
---|
61 | return false; |
---|
62 | } |
---|
63 | |
---|
64 | /* convert std::string to c string for compatability */ |
---|
65 | m_pchBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str()); |
---|
66 | m_pchReconFile = cfg_ReconFile.empty() ? NULL : strdup(cfg_ReconFile.c_str()); |
---|
67 | m_pchScaleOffsetFile = cfg_ScaleOffsetFile.empty() ? NULL : strdup(cfg_ScaleOffsetFile.c_str()); |
---|
68 | |
---|
69 | if (!m_pchBitstreamFile) |
---|
70 | { |
---|
71 | fprintf(stderr, "No input file specifed, aborting\n"); |
---|
72 | return false; |
---|
73 | } |
---|
74 | |
---|
75 | return true; |
---|
76 | } |
---|
77 | |
---|
78 | Void TAppDecCfg::xAppendToFileNameEnd( Char* pchInputFileName, const Char* pchStringToAppend, Char*& rpchOutputFileName) |
---|
79 | { |
---|
80 | size_t iInLength = strlen(pchInputFileName); |
---|
81 | size_t iAppendLength = strlen(pchStringToAppend); |
---|
82 | |
---|
83 | rpchOutputFileName = (Char*) malloc(iInLength+iAppendLength+1); |
---|
84 | Char* pCDot = strrchr(pchInputFileName,'.'); |
---|
85 | pCDot = pCDot ? pCDot : pchInputFileName + iInLength; |
---|
86 | size_t iCharsToDot = pCDot - pchInputFileName ; |
---|
87 | size_t iCharsToEnd = iInLength - iCharsToDot; |
---|
88 | strncpy(rpchOutputFileName , pchInputFileName , iCharsToDot ); |
---|
89 | strncpy(rpchOutputFileName+ iCharsToDot , pchStringToAppend , iAppendLength); |
---|
90 | strncpy(rpchOutputFileName+ iCharsToDot+iAppendLength , pchInputFileName+iCharsToDot, iCharsToEnd ); |
---|
91 | rpchOutputFileName[iInLength+iAppendLength] = '\0'; |
---|
92 | } |
---|