1 | /* The copyright in this software is being made available under the BSD |
---|
2 | * License, included below. This software may be subject to other third party |
---|
3 | * and contributor rights, including patent rights, and no such rights are |
---|
4 | * granted under this license. |
---|
5 | * |
---|
6 | * Copyright (c) 2010-2014, ITU/ISO/IEC |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | * this list of conditions and the following disclaimer in the documentation |
---|
16 | * and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
18 | * be used to endorse or promote products derived from this software without |
---|
19 | * specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | /** \file TAppDecCfg.cpp |
---|
35 | \brief Decoder configuration class |
---|
36 | */ |
---|
37 | |
---|
38 | #include <cstdio> |
---|
39 | #include <cstring> |
---|
40 | #include <string> |
---|
41 | #include "TAppDecCfg.h" |
---|
42 | #include "TAppCommon/program_options_lite.h" |
---|
43 | #if SVC_EXTENSION |
---|
44 | #include <cassert> |
---|
45 | #endif |
---|
46 | |
---|
47 | #ifdef WIN32 |
---|
48 | #define strdup _strdup |
---|
49 | #endif |
---|
50 | |
---|
51 | using namespace std; |
---|
52 | namespace po = df::program_options_lite; |
---|
53 | |
---|
54 | //! \ingroup TAppDecoder |
---|
55 | //! \{ |
---|
56 | |
---|
57 | // ==================================================================================================================== |
---|
58 | // Public member functions |
---|
59 | // ==================================================================================================================== |
---|
60 | |
---|
61 | /** \param argc number of arguments |
---|
62 | \param argv array of arguments |
---|
63 | */ |
---|
64 | Bool TAppDecCfg::parseCfg( Int argc, Char* argv[] ) |
---|
65 | { |
---|
66 | Bool do_help = false; |
---|
67 | string cfg_BitstreamFile; |
---|
68 | #if SVC_EXTENSION |
---|
69 | string cfg_ReconFile [MAX_LAYERS]; |
---|
70 | Int nLayerNum; |
---|
71 | #if OUTPUT_LAYER_SET_INDEX |
---|
72 | Int olsIdx; |
---|
73 | #endif |
---|
74 | #if AVC_BASE |
---|
75 | string cfg_BLReconFile; |
---|
76 | #endif |
---|
77 | #else |
---|
78 | string cfg_ReconFile; |
---|
79 | #endif |
---|
80 | |
---|
81 | string cfg_TargetDecLayerIdSetFile; |
---|
82 | |
---|
83 | po::Options opts; |
---|
84 | opts.addOptions() |
---|
85 | ("help", do_help, false, "this help text") |
---|
86 | ("BitstreamFile,b", cfg_BitstreamFile, string(""), "bitstream input file name") |
---|
87 | #if SVC_EXTENSION |
---|
88 | ("ReconFileL%d,-o%d", cfg_ReconFile, string(""), MAX_LAYERS, "Layer %d reconstructed YUV output file name\n" |
---|
89 | "YUV writing is skipped if omitted") |
---|
90 | #if AVC_BASE |
---|
91 | ("BLReconFile,-ibl", cfg_BLReconFile, string(""), "BL reconstructed YUV input file name") |
---|
92 | #if !REPN_FORMAT_IN_VPS |
---|
93 | ("BLSourceWidth,-wdt", m_iBLSourceWidth, 0, "BL source picture width") |
---|
94 | ("BLSourceHeight,-hgt", m_iBLSourceHeight, 0, "BL source picture height") |
---|
95 | #endif |
---|
96 | #endif |
---|
97 | #else |
---|
98 | ("ReconFile,o", cfg_ReconFile, string(""), "reconstructed YUV output file name\n" |
---|
99 | "YUV writing is skipped if omitted") |
---|
100 | #endif |
---|
101 | ("SkipFrames,s", m_iSkipFrame, 0, "number of frames to skip before random access") |
---|
102 | ("OutputBitDepth,d", m_outputBitDepthY, 0, "bit depth of YUV output luma component (default: use 0 for native depth)") |
---|
103 | ("OutputBitDepthC,d", m_outputBitDepthC, 0, "bit depth of YUV output chroma component (default: use 0 for native depth)") |
---|
104 | #if SVC_EXTENSION |
---|
105 | ("LayerNum,-ls", nLayerNum, 1, "Number of layers to be decoded.") |
---|
106 | #if OUTPUT_LAYER_SET_INDEX |
---|
107 | ("OutpuLayerSetIdx,-olsidx", olsIdx, -1, "Index of output layer set to be decoded.") |
---|
108 | #endif |
---|
109 | #endif |
---|
110 | ("MaxTemporalLayer,t", m_iMaxTemporalLayer, -1, "Maximum Temporal Layer to be decoded. -1 to decode all layers") |
---|
111 | ("SEIDecodedPictureHash", m_decodedPictureHashSEIEnabled, 1, "Control handling of decoded picture hash SEI messages\n" |
---|
112 | "\t1: check hash in SEI messages if available in the bitstream\n" |
---|
113 | "\t0: ignore SEI message") |
---|
114 | ("SEIpictureDigest", m_decodedPictureHashSEIEnabled, 1, "deprecated alias for SEIDecodedPictureHash") |
---|
115 | ("TarDecLayerIdSetFile,l", cfg_TargetDecLayerIdSetFile, string(""), "targetDecLayerIdSet file name. The file should include white space separated LayerId values to be decoded. Omitting the option or a value of -1 in the file decodes all layers.") |
---|
116 | ("RespectDefDispWindow,w", m_respectDefDispWindow, 0, "Only output content inside the default display window\n") |
---|
117 | ; |
---|
118 | po::setDefaults(opts); |
---|
119 | const list<const Char*>& argv_unhandled = po::scanArgv(opts, argc, (const Char**) argv); |
---|
120 | |
---|
121 | for (list<const Char*>::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++) |
---|
122 | { |
---|
123 | fprintf(stderr, "Unhandled argument ignored: `%s'\n", *it); |
---|
124 | } |
---|
125 | |
---|
126 | if (argc == 1 || do_help) |
---|
127 | { |
---|
128 | po::doHelp(cout, opts); |
---|
129 | return false; |
---|
130 | } |
---|
131 | |
---|
132 | /* convert std::string to c string for compatability */ |
---|
133 | m_pchBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str()); |
---|
134 | #if SVC_EXTENSION |
---|
135 | m_tgtLayerId = nLayerNum - 1; |
---|
136 | assert( m_tgtLayerId >= 0 ); |
---|
137 | assert( m_tgtLayerId < MAX_LAYERS ); |
---|
138 | #if O0137_MAX_LAYERID |
---|
139 | assert( m_tgtLayerId < MAX_NUM_LAYER_IDS ); |
---|
140 | #endif |
---|
141 | #if OUTPUT_LAYER_SET_INDEX |
---|
142 | this->getCommonDecoderParams()->setTargetOutputLayerSetIdx( olsIdx ); |
---|
143 | this->getCommonDecoderParams()->setTargetLayerId ( m_tgtLayerId ); |
---|
144 | #endif |
---|
145 | for(UInt layer=0; layer<= m_tgtLayerId; layer++) |
---|
146 | { |
---|
147 | m_pchReconFile[layer] = cfg_ReconFile[layer].empty() ? NULL : strdup(cfg_ReconFile[layer].c_str()); |
---|
148 | } |
---|
149 | #if AVC_BASE |
---|
150 | m_pchBLReconFile = cfg_BLReconFile.empty() ? NULL : strdup(cfg_BLReconFile.c_str()); |
---|
151 | #endif |
---|
152 | #else |
---|
153 | m_pchReconFile = cfg_ReconFile.empty() ? NULL : strdup(cfg_ReconFile.c_str()); |
---|
154 | #endif |
---|
155 | |
---|
156 | if (!m_pchBitstreamFile) |
---|
157 | { |
---|
158 | fprintf(stderr, "No input file specifed, aborting\n"); |
---|
159 | return false; |
---|
160 | } |
---|
161 | |
---|
162 | if ( !cfg_TargetDecLayerIdSetFile.empty() ) |
---|
163 | { |
---|
164 | FILE* targetDecLayerIdSetFile = fopen ( cfg_TargetDecLayerIdSetFile.c_str(), "r" ); |
---|
165 | if ( targetDecLayerIdSetFile ) |
---|
166 | { |
---|
167 | Bool isLayerIdZeroIncluded = false; |
---|
168 | while ( !feof(targetDecLayerIdSetFile) ) |
---|
169 | { |
---|
170 | Int layerIdParsed = 0; |
---|
171 | if ( fscanf( targetDecLayerIdSetFile, "%d ", &layerIdParsed ) != 1 ) |
---|
172 | { |
---|
173 | if ( m_targetDecLayerIdSet.size() == 0 ) |
---|
174 | { |
---|
175 | fprintf(stderr, "No LayerId could be parsed in file %s. Decoding all LayerIds as default.\n", cfg_TargetDecLayerIdSetFile.c_str() ); |
---|
176 | } |
---|
177 | break; |
---|
178 | } |
---|
179 | if ( layerIdParsed == -1 ) // The file includes a -1, which means all LayerIds are to be decoded. |
---|
180 | { |
---|
181 | m_targetDecLayerIdSet.clear(); // Empty set means decoding all layers. |
---|
182 | break; |
---|
183 | } |
---|
184 | if ( layerIdParsed < 0 || layerIdParsed >= MAX_NUM_LAYER_IDS ) |
---|
185 | { |
---|
186 | fprintf(stderr, "Warning! Parsed LayerId %d is not withing allowed range [0,%d]. Ignoring this value.\n", layerIdParsed, MAX_NUM_LAYER_IDS-1 ); |
---|
187 | } |
---|
188 | else |
---|
189 | { |
---|
190 | isLayerIdZeroIncluded = layerIdParsed == 0 ? true : isLayerIdZeroIncluded; |
---|
191 | m_targetDecLayerIdSet.push_back ( layerIdParsed ); |
---|
192 | } |
---|
193 | } |
---|
194 | fclose (targetDecLayerIdSetFile); |
---|
195 | if ( m_targetDecLayerIdSet.size() > 0 && !isLayerIdZeroIncluded ) |
---|
196 | { |
---|
197 | fprintf(stderr, "TargetDecLayerIdSet must contain LayerId=0, aborting" ); |
---|
198 | return false; |
---|
199 | } |
---|
200 | } |
---|
201 | else |
---|
202 | { |
---|
203 | fprintf(stderr, "File %s could not be opened. Using all LayerIds as default.\n", cfg_TargetDecLayerIdSetFile.c_str() ); |
---|
204 | } |
---|
205 | #if OUTPUT_LAYER_SET_INDEX |
---|
206 | this->getCommonDecoderParams()->setTargetDecLayerIdSet( &m_targetDecLayerIdSet ); |
---|
207 | #endif |
---|
208 | } |
---|
209 | |
---|
210 | return true; |
---|
211 | } |
---|
212 | |
---|
213 | //! \} |
---|