source: SHVCSoftware/branches/SHM-upgrade/source/App/TAppDecoder/TAppDecCfg.cpp @ 933

Last change on this file since 933 was 933, checked in by seregin, 10 years ago

fix compiler warning and index bound

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