source: SHVCSoftware/branches/SHM-dev/source/App/TAppDecoder/TAppDecCfg.cpp @ 1405

Last change on this file since 1405 was 1377, checked in by seregin, 9 years ago

dynamic memory allocation at encoder

  • Property svn:eol-style set to native
File size: 12.0 KB
Line 
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-2015, 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#include "TLibCommon/TComChromaFormat.h"
44#if SVC_EXTENSION
45#include <cassert>
46#endif
47
48#ifdef WIN32
49#define strdup _strdup
50#endif
51
52using namespace std;
53namespace po = df::program_options_lite;
54
55//! \ingroup TAppDecoder
56//! \{
57
58// ====================================================================================================================
59// Public member functions
60// ====================================================================================================================
61
62/** \param argc number of arguments
63    \param argv array of arguments
64 */
65Bool TAppDecCfg::parseCfg( Int argc, Char* argv[] )
66{
67  Bool do_help = false;
68  string cfg_BitstreamFile;
69#if SVC_EXTENSION
70  string cfg_ReconFile [MAX_LAYERS];
71  Int layerNum, targetLayerId;
72  Int olsIdx;
73#if CONFORMANCE_BITSTREAM_MODE
74  string cfg_confPrefix;
75#endif
76#if AVC_BASE
77  string cfg_BLReconFile;
78#endif
79#else
80  string cfg_ReconFile;
81#endif
82
83  string cfg_TargetDecLayerIdSetFile;
84  string outputColourSpaceConvert;
85  Int warnUnknowParameter = 0;
86
87  po::Options opts;
88  opts.addOptions()
89
90
91  ("help",                      do_help,                               false,      "this help text")
92  ("BitstreamFile,b",           cfg_BitstreamFile,                     string(""), "bitstream input file name")
93#if SVC_EXTENSION
94  ("ReconFileL%d,-o%d",                   cfg_ReconFile,   string(""), MAX_LAYERS, "Layer %d reconstructed YUV output file name\n"
95                                                                                   "YUV writing is skipped if omitted")
96#if AVC_BASE
97  ("BLReconFile,-ibl",                               cfg_BLReconFile,  string(""), "BL reconstructed YUV input file name")
98#endif
99  ("TargetLayerId,-lid",                                        targetLayerId, -1, "Target layer id")
100  ("LayerNum,-ls",                                    layerNum, MAX_NUM_LAYER_IDS, "Target layer id") // Legacy option
101  ("OutpuLayerSetIdx,-olsidx",                                         olsIdx, -1, "Index of output layer set to be decoded.")
102#if CONFORMANCE_BITSTREAM_MODE
103  ("ConformanceBitstremMode,-confMode",                     m_confModeFlag, false, "Enable generation of conformance bitstream metadata; True: Generate metadata, False: No metadata generated")
104  ("ConformanceMetadataPrefix,           -confPrefix", cfg_confPrefix, string(""), "Prefix for the file name of the conformance data. Default name - 'decodedBitstream'")
105#endif
106#else
107  ("ReconFile,o",               cfg_ReconFile,                         string(""), "reconstructed YUV output file name\n"
108                                                                                   "YUV writing is skipped if omitted")
109#endif
110  ("WarnUnknowParameter,w",     warnUnknowParameter,                                  0, "warn for unknown configuration parameters instead of failing")
111  ("SkipFrames,s",              m_iSkipFrame,                          0,          "number of frames to skip before random access")
112  ("OutputBitDepth,d",          m_outputBitDepth[CHANNEL_TYPE_LUMA],   0,          "bit depth of YUV output luma component (default: use 0 for native depth)")
113  ("OutputBitDepthC,d",         m_outputBitDepth[CHANNEL_TYPE_CHROMA], 0,          "bit depth of YUV output chroma component (default: use 0 for native depth)")
114  ("OutputColourSpaceConvert",  outputColourSpaceConvert,              string(""), "Colour space conversion to apply to input 444 video. Permitted values are (empty string=UNCHANGED) " + getListOfColourSpaceConverts(false))
115  ("MaxTemporalLayer,t",        m_iMaxTemporalLayer,                   -1,         "Maximum Temporal Layer to be decoded. -1 to decode all layers")
116  ("SEIDecodedPictureHash",     m_decodedPictureHashSEIEnabled,        1,          "Control handling of decoded picture hash SEI messages\n"
117                                                                                   "\t1: check hash in SEI messages if available in the bitstream\n"
118                                                                                   "\t0: ignore SEI message")
119  ("SEINoDisplay",              m_decodedNoDisplaySEIEnabled,          true,       "Control handling of decoded no display SEI messages")
120  ("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.")
121  ("RespectDefDispWindow,w",    m_respectDefDispWindow,                0,          "Only output content inside the default display window\n")
122#if O0043_BEST_EFFORT_DECODING
123  ("ForceDecodeBitDepth",       m_forceDecodeBitDepth,                 0U,         "Force the decoder to operate at a particular bit-depth (best effort decoding)")
124#endif
125  ("OutputDecodedSEIMessagesFilename",  m_outputDecodedSEIMessagesFilename,    string(""), "When non empty, output decoded SEI messages to the indicated file. If file is '-', then output to stdout\n")
126  ("ClipOutputVideoToRec709Range",      m_bClipOutputVideoToRec709Range,  false, "If true then clip output video to the Rec. 709 Range on saving")
127#if Q0074_COLOUR_REMAPPING_SEI
128  ("SEIColourRemappingInfo,-cri", m_colourRemapSEIEnabled, false, "Control handling of Colour Remapping Information SEI messages\n"
129                                              "\t1: apply colour remapping on decoded pictures if available in the bitstream\n"
130                                              "\t0: ignore SEI message")
131#endif
132  ;
133
134  po::setDefaults(opts);
135  po::ErrorReporter err;
136  const list<const Char*>& argv_unhandled = po::scanArgv(opts, argc, (const Char**) argv, err);
137
138  for (list<const Char*>::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++)
139  {
140    fprintf(stderr, "Unhandled argument ignored: `%s'\n", *it);
141  }
142
143  if (argc == 1 || do_help)
144  {
145    po::doHelp(cout, opts);
146    return false;
147  }
148
149  if (err.is_errored)
150  {
151    if (!warnUnknowParameter)
152    {
153      /* errors have already been reported to stderr */
154      return false;
155    }
156  }
157
158  m_outputColourSpaceConvert = stringToInputColourSpaceConvert(outputColourSpaceConvert, false);
159  if (m_outputColourSpaceConvert>=NUMBER_INPUT_COLOUR_SPACE_CONVERSIONS)
160  {
161    fprintf(stderr, "Bad output colour space conversion string\n");
162    return false;
163  }
164
165  /* convert std::string to c string for compatability */
166  m_pchBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str());
167#if SVC_EXTENSION
168  if( targetLayerId < 0 )
169  {
170    targetLayerId = layerNum - 1;
171  }
172
173  assert( targetLayerId >= 0 );
174  assert( targetLayerId < MAX_NUM_LAYER_IDS );
175
176#if CONFORMANCE_BITSTREAM_MODE
177  if( m_confModeFlag )
178  {
179    assert( olsIdx != -1 ); // In the conformance mode, target output layer set index is to be explicitly specified.
180
181    if( cfg_confPrefix.empty() )
182    {
183      m_confPrefix = string("decodedBitstream");
184    }
185    else
186    {
187      m_confPrefix = cfg_confPrefix;
188    }
189      // Open metadata file and write
190    char fileNameSuffix[255];
191    sprintf(fileNameSuffix, "%s-OLS%d.opl", m_confPrefix.c_str(), olsIdx);  // olsIdx is the target output layer set index.
192    m_metadataFileName = string(fileNameSuffix);
193    m_metadataFileRefresh = true;
194
195    // Decoded layer YUV files
196    for(Int layer= 0; layer < MAX_VPS_LAYER_IDX_PLUS1; layer++ )
197    {
198      sprintf(fileNameSuffix, "%s-L%d.yuv", m_confPrefix.c_str(), layer);  // olsIdx is the target output layer set index.
199      m_decodedYuvLayerFileName[layer] = std::string( fileNameSuffix );
200      m_decodedYuvLayerRefresh[layer] = true;
201    }
202  }
203#endif
204  m_commonDecoderParams.setTargetOutputLayerSetIdx( olsIdx );
205  m_commonDecoderParams.setTargetLayerId( targetLayerId );
206
207#if CONFORMANCE_BITSTREAM_MODE
208  for(Int layer = 0; layer < MAX_VPS_LAYER_IDX_PLUS1; layer++ )
209  {
210#else
211  for(UInt layer=0; layer<= m_tgtLayerId; layer++)
212  {
213    assert( layer < MAX_LAYERS );
214#endif
215    m_pchReconFile[layer] = cfg_ReconFile[layer].empty() ? NULL : strdup(cfg_ReconFile[layer].c_str());
216  }
217#if AVC_BASE
218  m_pchBLReconFile = cfg_BLReconFile.empty() ? NULL : strdup(cfg_BLReconFile.c_str());
219#endif
220#else
221  m_pchReconFile = cfg_ReconFile.empty() ? NULL : strdup(cfg_ReconFile.c_str());
222#endif
223
224  if (!m_pchBitstreamFile)
225  {
226    fprintf(stderr, "No input file specified, aborting\n");
227    return false;
228  }
229
230  if ( !cfg_TargetDecLayerIdSetFile.empty() )
231  {
232    FILE* targetDecLayerIdSetFile = fopen ( cfg_TargetDecLayerIdSetFile.c_str(), "r" );
233    if ( targetDecLayerIdSetFile )
234    {
235      Bool isLayerIdZeroIncluded = false;
236      while ( !feof(targetDecLayerIdSetFile) )
237      {
238        Int layerIdParsed = 0;
239        if ( fscanf( targetDecLayerIdSetFile, "%d ", &layerIdParsed ) != 1 )
240        {
241          if ( m_targetDecLayerIdSet.size() == 0 )
242          {
243            fprintf(stderr, "No LayerId could be parsed in file %s. Decoding all LayerIds as default.\n", cfg_TargetDecLayerIdSetFile.c_str() );
244          }
245          break;
246        }
247        if ( layerIdParsed  == -1 ) // The file includes a -1, which means all LayerIds are to be decoded.
248        {
249          m_targetDecLayerIdSet.clear(); // Empty set means decoding all layers.
250          break;
251        }
252        if ( layerIdParsed < 0 || layerIdParsed >= MAX_NUM_LAYER_IDS )
253        {
254          fprintf(stderr, "Warning! Parsed LayerId %d is not within allowed range [0,%d]. Ignoring this value.\n", layerIdParsed, MAX_NUM_LAYER_IDS-1 );
255        }
256        else
257        {
258          isLayerIdZeroIncluded = layerIdParsed == 0 ? true : isLayerIdZeroIncluded;
259          m_targetDecLayerIdSet.push_back ( layerIdParsed );
260        }
261      }
262      fclose (targetDecLayerIdSetFile);
263      if ( m_targetDecLayerIdSet.size() > 0 && !isLayerIdZeroIncluded )
264      {
265        fprintf(stderr, "TargetDecLayerIdSet must contain LayerId=0, aborting" );
266        return false;
267      }
268    }
269    else
270    {
271      fprintf(stderr, "File %s could not be opened. Using all LayerIds as default.\n", cfg_TargetDecLayerIdSetFile.c_str() );
272    }
273
274#if SVC_EXTENSION
275    m_commonDecoderParams.setTargetDecLayerIdSet( &m_targetDecLayerIdSet );
276#endif
277  }
278
279  return true;
280}
281
282//! \}
Note: See TracBrowser for help on using the repository browser.