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

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

initial porting

  • Property svn:eol-style set to native
File size: 9.9 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 AVC_BASE
76  string cfg_BLReconFile;
77#endif
78#else
79  string cfg_ReconFile;
80#endif
81
82  string cfg_TargetDecLayerIdSetFile;
83  string outputColourSpaceConvert;
84
85  po::Options opts;
86  opts.addOptions()
87
88
89  ("help",                      do_help,                               false,      "this help text")
90  ("BitstreamFile,b",           cfg_BitstreamFile,                     string(""), "bitstream input file name")
91#if SVC_EXTENSION
92  ("ReconFileL%d,-o%d",   cfg_ReconFile,   string(""), MAX_LAYERS, "Layer %d reconstructed YUV output file name\n"
93                                                     "YUV writing is skipped if omitted")
94#if AVC_BASE
95  ("BLReconFile,-ibl",    cfg_BLReconFile,  string(""), "BL reconstructed YUV input file name")
96#if !REPN_FORMAT_IN_VPS
97  ("BLSourceWidth,-wdt",    m_iBLSourceWidth,        0, "BL source picture width")
98  ("BLSourceHeight,-hgt",   m_iBLSourceHeight,       0, "BL source picture height")
99#endif
100#endif
101  ("LayerNum,-ls", nLayerNum, 1, "Number of layers to be decoded.")
102#if OUTPUT_LAYER_SET_INDEX
103  ("OutpuLayerSetIdx,-olsidx", olsIdx, -1, "Index of output layer set to be decoded.")
104#endif
105#else
106  ("ReconFile,o",               cfg_ReconFile,                         string(""), "reconstructed YUV output file name\n"
107                                                                                   "YUV writing is skipped if omitted")
108#endif
109
110  ("SkipFrames,s",              m_iSkipFrame,                          0,          "number of frames to skip before random access")
111  ("OutputBitDepth,d",          m_outputBitDepth[CHANNEL_TYPE_LUMA],   0,          "bit depth of YUV output luma component (default: use 0 for native depth)")
112  ("OutputBitDepthC,d",         m_outputBitDepth[CHANNEL_TYPE_CHROMA], 0,          "bit depth of YUV output chroma component (default: use 0 for native depth)")
113  ("OutputColourSpaceConvert",  outputColourSpaceConvert,              string(""), "Colour space conversion to apply to input 444 video. Permitted values are (empty string=UNCHANGED) " + getListOfColourSpaceConverts(false))
114  ("MaxTemporalLayer,t",        m_iMaxTemporalLayer,                   -1,         "Maximum Temporal Layer to be decoded. -1 to decode all layers")
115  ("SEIDecodedPictureHash",     m_decodedPictureHashSEIEnabled,        1,          "Control handling of decoded picture hash SEI messages\n"
116                                                                                   "\t1: check hash in SEI messages if available in the bitstream\n"
117                                                                                   "\t0: ignore SEI message")
118  ("SEIpictureDigest",          m_decodedPictureHashSEIEnabled,        1,          "deprecated alias for SEIDecodedPictureHash")
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#if Q0074_COLOUR_REMAPPING_SEI
126  ("SEIColourRemappingInfo", m_colourRemapSEIEnabled, false, "Control handling of Colour Remapping Information SEI messages\n"
127                                              "\t1: apply colour remapping on decoded pictures if available in the bitstream\n"
128                                              "\t0: ignore SEI message")
129#endif
130  ;
131
132  po::setDefaults(opts);
133  const list<const Char*>& argv_unhandled = po::scanArgv(opts, argc, (const Char**) argv);
134
135  for (list<const Char*>::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++)
136  {
137    fprintf(stderr, "Unhandled argument ignored: `%s'\n", *it);
138  }
139
140  if (argc == 1 || do_help)
141  {
142    po::doHelp(cout, opts);
143    return false;
144  }
145
146  m_outputColourSpaceConvert = stringToInputColourSpaceConvert(outputColourSpaceConvert, false);
147  if (m_outputColourSpaceConvert>=NUMBER_INPUT_COLOUR_SPACE_CONVERSIONS)
148  {
149    fprintf(stderr, "Bad output colour space conversion string\n");
150    return false;
151  }
152
153  /* convert std::string to c string for compatability */
154  m_pchBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str());
155#if SVC_EXTENSION
156  m_tgtLayerId = nLayerNum - 1;
157  assert( m_tgtLayerId >= 0 );
158  assert( m_tgtLayerId < MAX_LAYERS );
159#if O0137_MAX_LAYERID
160  assert( m_tgtLayerId < MAX_NUM_LAYER_IDS );
161#endif
162#if OUTPUT_LAYER_SET_INDEX 
163  this->getCommonDecoderParams()->setTargetOutputLayerSetIdx( olsIdx       );
164  this->getCommonDecoderParams()->setTargetLayerId    ( m_tgtLayerId );
165#endif
166  for(UInt layer=0; layer<= m_tgtLayerId; layer++)
167  {
168    m_pchReconFile[layer] = cfg_ReconFile[layer].empty() ? NULL : strdup(cfg_ReconFile[layer].c_str());
169  }
170#if AVC_BASE
171  m_pchBLReconFile = cfg_BLReconFile.empty() ? NULL : strdup(cfg_BLReconFile.c_str());
172#endif
173#else
174  m_pchReconFile = cfg_ReconFile.empty() ? NULL : strdup(cfg_ReconFile.c_str());
175#endif
176
177  if (!m_pchBitstreamFile)
178  {
179    fprintf(stderr, "No input file specified, aborting\n");
180    return false;
181  }
182
183  if ( !cfg_TargetDecLayerIdSetFile.empty() )
184  {
185    FILE* targetDecLayerIdSetFile = fopen ( cfg_TargetDecLayerIdSetFile.c_str(), "r" );
186    if ( targetDecLayerIdSetFile )
187    {
188      Bool isLayerIdZeroIncluded = false;
189      while ( !feof(targetDecLayerIdSetFile) )
190      {
191        Int layerIdParsed = 0;
192        if ( fscanf( targetDecLayerIdSetFile, "%d ", &layerIdParsed ) != 1 )
193        {
194          if ( m_targetDecLayerIdSet.size() == 0 )
195          {
196            fprintf(stderr, "No LayerId could be parsed in file %s. Decoding all LayerIds as default.\n", cfg_TargetDecLayerIdSetFile.c_str() );
197          }
198          break;
199        }
200        if ( layerIdParsed  == -1 ) // The file includes a -1, which means all LayerIds are to be decoded.
201        {
202          m_targetDecLayerIdSet.clear(); // Empty set means decoding all layers.
203          break;
204        }
205        if ( layerIdParsed < 0 || layerIdParsed >= MAX_NUM_LAYER_IDS )
206        {
207          fprintf(stderr, "Warning! Parsed LayerId %d is not within allowed range [0,%d]. Ignoring this value.\n", layerIdParsed, MAX_NUM_LAYER_IDS-1 );
208        }
209        else
210        {
211          isLayerIdZeroIncluded = layerIdParsed == 0 ? true : isLayerIdZeroIncluded;
212          m_targetDecLayerIdSet.push_back ( layerIdParsed );
213        }
214      }
215      fclose (targetDecLayerIdSetFile);
216      if ( m_targetDecLayerIdSet.size() > 0 && !isLayerIdZeroIncluded )
217      {
218        fprintf(stderr, "TargetDecLayerIdSet must contain LayerId=0, aborting" );
219        return false;
220      }
221    }
222    else
223    {
224      fprintf(stderr, "File %s could not be opened. Using all LayerIds as default.\n", cfg_TargetDecLayerIdSetFile.c_str() );
225    }
226#if OUTPUT_LAYER_SET_INDEX 
227    this->getCommonDecoderParams()->setTargetDecLayerIdSet( &m_targetDecLayerIdSet );
228#endif
229  }
230
231  return true;
232}
233
234//! \}
Note: See TracBrowser for help on using the repository browser.