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

Last change on this file was 1549, checked in by seregin, 9 years ago

port rev 4732, update copyright notice to include 2016

  • Property svn:eol-style set to native
File size: 11.8 KB
RevLine 
[313]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
[1246]4 * granted under this license.
[313]5 *
[1549]6 * Copyright (c) 2010-2016, ITU/ISO/IEC
[313]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"
[1029]43#include "TLibCommon/TComChromaFormat.h"
[313]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 */
[1442]65Bool TAppDecCfg::parseCfg( Int argc, TChar* argv[] )
[313]66{
67  Bool do_help = false;
[1442]68#if SVC_EXTENSION 
[1057]69  Int layerNum, targetLayerId;
[540]70  Int olsIdx;
[924]71#if CONFORMANCE_BITSTREAM_MODE
[1472]72  string confPrefix;
[924]73#endif
[1472]74
75  Int* cfg_outputBitDepthY[MAX_LAYERS];
76  Int* cfg_outputBitDepthC[MAX_LAYERS];
77
78  for( Int layer = 0; layer < MAX_LAYERS; layer++ )
79  {
80    cfg_outputBitDepthY[layer] = &m_outputBitDepth[layer][CHANNEL_TYPE_LUMA];
81    cfg_outputBitDepthC[layer] = &m_outputBitDepth[layer][CHANNEL_TYPE_CHROMA];
82  }
[313]83#endif
[820]84
[313]85  string cfg_TargetDecLayerIdSetFile;
[1029]86  string outputColourSpaceConvert;
[1301]87  Int warnUnknowParameter = 0;
[313]88
89  po::Options opts;
90  opts.addOptions()
[1029]91
92
93  ("help",                      do_help,                               false,      "this help text")
[1442]94  ("BitstreamFile,b",           m_bitstreamFileName,                   string(""), "bitstream input file name")
[313]95#if SVC_EXTENSION
[1472]96  ("c",                         po::parseConfigFile,                               "configuration file name")
97  ("ReconFile%d,-o%d",          m_reconFileName,           string(""), MAX_LAYERS, "Layer %d reconstructed YUV output file name\n"
[1377]98                                                                                   "YUV writing is skipped if omitted")
[313]99#if AVC_BASE
[1442]100  ("BLReconFile,-ibl",                              m_reconFileNameBL, string(""), "BL reconstructed YUV input file name")
[713]101#endif
[1377]102  ("TargetLayerId,-lid",                                        targetLayerId, -1, "Target layer id")
103  ("LayerNum,-ls",                                    layerNum, MAX_NUM_LAYER_IDS, "Target layer id") // Legacy option
104  ("OutpuLayerSetIdx,-olsidx",                                         olsIdx, -1, "Index of output layer set to be decoded.")
[924]105#if CONFORMANCE_BITSTREAM_MODE
[1472]106  ("ConformanceBitstremMode,-confMode",                      m_confModeFlag, false, "Enable generation of conformance bitstream metadata; True: Generate metadata, False: No metadata generated")
107  ("ConformanceMetadataPrefix,-confPrefix",                 confPrefix, string(""), "Prefix for the file name of the conformance data. Default name - 'decodedBitstream'")
[924]108#endif
[1029]109#else
[1442]110  ("ReconFile,o",               m_reconFileName,                       string(""), "reconstructed YUV output file name\n"
[1029]111                                                                                   "YUV writing is skipped if omitted")
112#endif
[1301]113  ("WarnUnknowParameter,w",     warnUnknowParameter,                                  0, "warn for unknown configuration parameters instead of failing")
[1029]114  ("SkipFrames,s",              m_iSkipFrame,                          0,          "number of frames to skip before random access")
[1472]115#if SVC_EXTENSION
116  ("OutputBitDepth%d,%d",       cfg_outputBitDepthY,                0, MAX_LAYERS, "bit depth of YUV output luma component (default: use 0 for native depth)")
117  ("OutputBitDepthC%d,%d",      cfg_outputBitDepthC,                0, MAX_LAYERS, "bit depth of YUV output chroma component (default: use 0 for native depth)")
118#else
[1029]119  ("OutputBitDepth,d",          m_outputBitDepth[CHANNEL_TYPE_LUMA],   0,          "bit depth of YUV output luma component (default: use 0 for native depth)")
120  ("OutputBitDepthC,d",         m_outputBitDepth[CHANNEL_TYPE_CHROMA], 0,          "bit depth of YUV output chroma component (default: use 0 for native depth)")
[1472]121#endif
[1029]122  ("OutputColourSpaceConvert",  outputColourSpaceConvert,              string(""), "Colour space conversion to apply to input 444 video. Permitted values are (empty string=UNCHANGED) " + getListOfColourSpaceConverts(false))
123  ("MaxTemporalLayer,t",        m_iMaxTemporalLayer,                   -1,         "Maximum Temporal Layer to be decoded. -1 to decode all layers")
124  ("SEIDecodedPictureHash",     m_decodedPictureHashSEIEnabled,        1,          "Control handling of decoded picture hash SEI messages\n"
125                                                                                   "\t1: check hash in SEI messages if available in the bitstream\n"
126                                                                                   "\t0: ignore SEI message")
127  ("SEINoDisplay",              m_decodedNoDisplaySEIEnabled,          true,       "Control handling of decoded no display SEI messages")
128  ("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.")
129  ("RespectDefDispWindow,w",    m_respectDefDispWindow,                0,          "Only output content inside the default display window\n")
[1460]130  ("SEIColourRemappingInfoFilename",  m_colourRemapSEIFileName,        string(""), "Colour Remapping YUV output file name. If empty, no remapping is applied (ignore SEI message)\n")
[1029]131#if O0043_BEST_EFFORT_DECODING
132  ("ForceDecodeBitDepth",       m_forceDecodeBitDepth,                 0U,         "Force the decoder to operate at a particular bit-depth (best effort decoding)")
133#endif
[1246]134  ("OutputDecodedSEIMessagesFilename",  m_outputDecodedSEIMessagesFilename,    string(""), "When non empty, output decoded SEI messages to the indicated file. If file is '-', then output to stdout\n")
[1323]135  ("ClipOutputVideoToRec709Range",      m_bClipOutputVideoToRec709Range,  false, "If true then clip output video to the Rec. 709 Range on saving")
[313]136  ;
[1029]137
[313]138  po::setDefaults(opts);
[1301]139  po::ErrorReporter err;
[1442]140  const list<const TChar*>& argv_unhandled = po::scanArgv(opts, argc, (const TChar**) argv, err);
[313]141
[1442]142  for (list<const TChar*>::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++)
[313]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
[1301]153  if (err.is_errored)
154  {
155    if (!warnUnknowParameter)
156    {
157      /* errors have already been reported to stderr */
158      return false;
159    }
160  }
161
[1029]162  m_outputColourSpaceConvert = stringToInputColourSpaceConvert(outputColourSpaceConvert, false);
163  if (m_outputColourSpaceConvert>=NUMBER_INPUT_COLOUR_SPACE_CONVERSIONS)
164  {
165    fprintf(stderr, "Bad output colour space conversion string\n");
166    return false;
167  }
168
[313]169#if SVC_EXTENSION
[1057]170  if( targetLayerId < 0 )
171  {
[1524]172    targetLayerId = MAX_VPS_LAYER_IDX_PLUS1 - 1;
[1057]173  }
174
175  assert( targetLayerId >= 0 );
176  assert( targetLayerId < MAX_NUM_LAYER_IDS );
[1179]177
[924]178#if CONFORMANCE_BITSTREAM_MODE
179  if( m_confModeFlag )
180  {
181    assert( olsIdx != -1 ); // In the conformance mode, target output layer set index is to be explicitly specified.
182
[1472]183    if( confPrefix.empty() )
[924]184    {
185      m_confPrefix = string("decodedBitstream");
186    }
187    else
188    {
[1472]189      m_confPrefix = confPrefix;
[924]190    }
191      // Open metadata file and write
192    char fileNameSuffix[255];
193    sprintf(fileNameSuffix, "%s-OLS%d.opl", m_confPrefix.c_str(), olsIdx);  // olsIdx is the target output layer set index.
194    m_metadataFileName = string(fileNameSuffix);
195    m_metadataFileRefresh = true;
196
197    // Decoded layer YUV files
[1044]198    for(Int layer= 0; layer < MAX_VPS_LAYER_IDX_PLUS1; layer++ )
[924]199    {
200      sprintf(fileNameSuffix, "%s-L%d.yuv", m_confPrefix.c_str(), layer);  // olsIdx is the target output layer set index.
201      m_decodedYuvLayerFileName[layer] = std::string( fileNameSuffix );
202      m_decodedYuvLayerRefresh[layer] = true;
203    }
204  }
205#endif
[1029]206  m_commonDecoderParams.setTargetOutputLayerSetIdx( olsIdx );
[1057]207  m_commonDecoderParams.setTargetLayerId( targetLayerId );
[953]208#endif
[313]209
[1442]210  if (m_bitstreamFileName.empty())
[313]211  {
[1029]212    fprintf(stderr, "No input file specified, aborting\n");
[313]213    return false;
214  }
215
216  if ( !cfg_TargetDecLayerIdSetFile.empty() )
217  {
218    FILE* targetDecLayerIdSetFile = fopen ( cfg_TargetDecLayerIdSetFile.c_str(), "r" );
219    if ( targetDecLayerIdSetFile )
220    {
221      Bool isLayerIdZeroIncluded = false;
222      while ( !feof(targetDecLayerIdSetFile) )
223      {
224        Int layerIdParsed = 0;
225        if ( fscanf( targetDecLayerIdSetFile, "%d ", &layerIdParsed ) != 1 )
226        {
227          if ( m_targetDecLayerIdSet.size() == 0 )
228          {
229            fprintf(stderr, "No LayerId could be parsed in file %s. Decoding all LayerIds as default.\n", cfg_TargetDecLayerIdSetFile.c_str() );
230          }
231          break;
232        }
233        if ( layerIdParsed  == -1 ) // The file includes a -1, which means all LayerIds are to be decoded.
234        {
235          m_targetDecLayerIdSet.clear(); // Empty set means decoding all layers.
236          break;
237        }
238        if ( layerIdParsed < 0 || layerIdParsed >= MAX_NUM_LAYER_IDS )
239        {
[1029]240          fprintf(stderr, "Warning! Parsed LayerId %d is not within allowed range [0,%d]. Ignoring this value.\n", layerIdParsed, MAX_NUM_LAYER_IDS-1 );
[313]241        }
242        else
243        {
244          isLayerIdZeroIncluded = layerIdParsed == 0 ? true : isLayerIdZeroIncluded;
245          m_targetDecLayerIdSet.push_back ( layerIdParsed );
246        }
247      }
248      fclose (targetDecLayerIdSetFile);
[1246]249      if ( m_targetDecLayerIdSet.size() > 0 && !isLayerIdZeroIncluded )
250      {
251        fprintf(stderr, "TargetDecLayerIdSet must contain LayerId=0, aborting" );
252        return false;
253      }
[313]254    }
255    else
256    {
257      fprintf(stderr, "File %s could not be opened. Using all LayerIds as default.\n", cfg_TargetDecLayerIdSetFile.c_str() );
258    }
[1177]259
260#if SVC_EXTENSION
261    m_commonDecoderParams.setTargetDecLayerIdSet( &m_targetDecLayerIdSet );
[540]262#endif
[313]263  }
264
265  return true;
266}
267
268//! \}
Note: See TracBrowser for help on using the repository browser.