HEVC Test Model (HM)  HM-16.18
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TAppDecCfg.cpp
Go to the documentation of this file.
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-2017, 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 
38 #include <cstdio>
39 #include <cstring>
40 #include <string>
41 #include "TAppDecCfg.h"
44 #ifdef WIN32
45 #define strdup _strdup
46 #endif
47 
48 using namespace std;
49 namespace po = df::program_options_lite;
50 
53 
54 // ====================================================================================================================
55 // Public member functions
56 // ====================================================================================================================
57 
62 {
63  Bool do_help = false;
64  string cfg_TargetDecLayerIdSetFile;
65  string outputColourSpaceConvert;
66  Int warnUnknowParameter = 0;
67 
68  po::Options opts;
69  opts.addOptions()
70 
71 
72  ("help", do_help, false, "this help text")
73  ("BitstreamFile,b", m_bitstreamFileName, string(""), "bitstream input file name")
74  ("ReconFile,o", m_reconFileName, string(""), "reconstructed YUV output file name\n"
75  "YUV writing is skipped if omitted")
76  ("WarnUnknowParameter,w", warnUnknowParameter, 0, "warn for unknown configuration parameters instead of failing")
77  ("SkipFrames,s", m_iSkipFrame, 0, "number of frames to skip before random access")
78  ("OutputBitDepth,d", m_outputBitDepth[CHANNEL_TYPE_LUMA], 0, "bit depth of YUV output luma component (default: use 0 for native depth)")
79  ("OutputBitDepthC,d", m_outputBitDepth[CHANNEL_TYPE_CHROMA], 0, "bit depth of YUV output chroma component (default: use 0 for native depth)")
80  ("OutputColourSpaceConvert", outputColourSpaceConvert, string(""), "Colour space conversion to apply to input 444 video. Permitted values are (empty string=UNCHANGED) " + getListOfColourSpaceConverts(false))
81  ("MaxTemporalLayer,t", m_iMaxTemporalLayer, -1, "Maximum Temporal Layer to be decoded. -1 to decode all layers")
82  ("SEIDecodedPictureHash", m_decodedPictureHashSEIEnabled, 1, "Control handling of decoded picture hash SEI messages\n"
83  "\t1: check hash in SEI messages if available in the bitstream\n"
84  "\t0: ignore SEI message")
85  ("SEINoDisplay", m_decodedNoDisplaySEIEnabled, true, "Control handling of decoded no display SEI messages")
86  ("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.")
87  ("RespectDefDispWindow,w", m_respectDefDispWindow, 0, "Only output content inside the default display window\n")
88  ("SEIColourRemappingInfoFilename", m_colourRemapSEIFileName, string(""), "Colour Remapping YUV output file name. If empty, no remapping is applied (ignore SEI message)\n")
90  ("ForceDecodeBitDepth", m_forceDecodeBitDepth, 0U, "Force the decoder to operate at a particular bit-depth (best effort decoding)")
91 #endif
92  ("OutputDecodedSEIMessagesFilename", m_outputDecodedSEIMessagesFilename, string(""), "When non empty, output decoded SEI messages to the indicated file. If file is '-', then output to stdout\n")
93  ("ClipOutputVideoToRec709Range", m_bClipOutputVideoToRec709Range, false, "If true then clip output video to the Rec. 709 Range on saving")
94 #if MCTS_ENC_CHECK
95  ("TMCTSCheck", m_tmctsCheck, false, "If enabled, the decoder checks for violations of mc_exact_sample_value_match_flag in Temporal MCTS ")
96 #endif
97  ;
98 
99  po::setDefaults(opts);
100  po::ErrorReporter err;
101  const list<const TChar*>& argv_unhandled = po::scanArgv(opts, argc, (const TChar**) argv, err);
102 
103  for (list<const TChar*>::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++)
104  {
105  fprintf(stderr, "Unhandled argument ignored: `%s'\n", *it);
106  }
107 
108  if (argc == 1 || do_help)
109  {
110  po::doHelp(cout, opts);
111  return false;
112  }
113 
114  if (err.is_errored)
115  {
116  if (!warnUnknowParameter)
117  {
118  /* errors have already been reported to stderr */
119  return false;
120  }
121  }
122 
123  m_outputColourSpaceConvert = stringToInputColourSpaceConvert(outputColourSpaceConvert, false);
124  if (m_outputColourSpaceConvert>=NUMBER_INPUT_COLOUR_SPACE_CONVERSIONS)
125  {
126  fprintf(stderr, "Bad output colour space conversion string\n");
127  return false;
128  }
129 
130  if (m_bitstreamFileName.empty())
131  {
132  fprintf(stderr, "No input file specified, aborting\n");
133  return false;
134  }
135 
136  if ( !cfg_TargetDecLayerIdSetFile.empty() )
137  {
138  FILE* targetDecLayerIdSetFile = fopen ( cfg_TargetDecLayerIdSetFile.c_str(), "r" );
139  if ( targetDecLayerIdSetFile )
140  {
141  Bool isLayerIdZeroIncluded = false;
142  while ( !feof(targetDecLayerIdSetFile) )
143  {
144  Int layerIdParsed = 0;
145  if ( fscanf( targetDecLayerIdSetFile, "%d ", &layerIdParsed ) != 1 )
146  {
147  if ( m_targetDecLayerIdSet.size() == 0 )
148  {
149  fprintf(stderr, "No LayerId could be parsed in file %s. Decoding all LayerIds as default.\n", cfg_TargetDecLayerIdSetFile.c_str() );
150  }
151  break;
152  }
153  if ( layerIdParsed == -1 ) // The file includes a -1, which means all LayerIds are to be decoded.
154  {
155  m_targetDecLayerIdSet.clear(); // Empty set means decoding all layers.
156  break;
157  }
158  if ( layerIdParsed < 0 || layerIdParsed >= MAX_NUM_LAYER_IDS )
159  {
160  fprintf(stderr, "Warning! Parsed LayerId %d is not within allowed range [0,%d]. Ignoring this value.\n", layerIdParsed, MAX_NUM_LAYER_IDS-1 );
161  }
162  else
163  {
164  isLayerIdZeroIncluded = layerIdParsed == 0 ? true : isLayerIdZeroIncluded;
165  m_targetDecLayerIdSet.push_back ( layerIdParsed );
166  }
167  }
168  fclose (targetDecLayerIdSetFile);
169  if ( m_targetDecLayerIdSet.size() > 0 && !isLayerIdZeroIncluded )
170  {
171  fprintf(stderr, "TargetDecLayerIdSet must contain LayerId=0, aborting" );
172  return false;
173  }
174  }
175  else
176  {
177  fprintf(stderr, "File %s could not be opened. Using all LayerIds as default.\n", cfg_TargetDecLayerIdSetFile.c_str() );
178  }
179  }
180 
181  return true;
182 }
183 
void doHelp(ostream &out, Options &opts, unsigned columns)
static const Int MAX_NUM_LAYER_IDS
Definition: CommonDef.h:151
char TChar
Definition: TypeDef.h:206
Bool parseCfg(Int argc, TChar *argv[])
initialize option class from configuration
Definition: TAppDecCfg.cpp:61
list< const char * > scanArgv(Options &opts, unsigned argc, const char *argv[], ErrorReporter &error_reporter)
#define O0043_BEST_EFFORT_DECODING
0 (default) = disable code related to best effort decoding, 1 = enable code relating to best effort d...
Definition: TypeDef.h:130
InputColourSpaceConversion stringToInputColourSpaceConvert(const std::string &value, const Bool bIsForward)
bool Bool
Definition: TypeDef.h:204
Decoder configuration class (header)
std::string getListOfColourSpaceConverts(const Bool bIsForward)
int Int
Definition: TypeDef.h:211