source: 3DVCSoftware/branches/HTM-15.2-dev/source/App/TAppDecoder/TAppDecCfg.cpp @ 1373

Last change on this file since 1373 was 1373, checked in by tech, 8 years ago

Macro fixes.

  • Property svn:eol-style set to native
File size: 10.8 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#ifdef WIN32
45#define strdup _strdup
46#endif
47#if NH_MV
48#include <cassert>
49#endif
50
51using namespace std;
52namespace po = df::program_options_lite;
53
54//! \ingroup TAppDecoder
55//! \{
56
57// ====================================================================================================================
58// Public member functions
59// ====================================================================================================================
60
61/** \param argc number of arguments
62    \param argv array of arguments
63 */
64Bool TAppDecCfg::parseCfg( Int argc, TChar* argv[] )
65{
66  Bool do_help = false;
67  string cfg_TargetDecLayerIdSetFile;
68#if NH_3D
69  string cfg_ScaleOffsetFile;
70#endif
71  string outputColourSpaceConvert;
72  Int warnUnknowParameter = 0;
73
74  po::Options opts;
75  opts.addOptions()
76
77
78  ("help",                      do_help,                               false,      "this help text")
79  ("BitstreamFile,b",           m_bitstreamFileName,                   string(""), "bitstream input file name")
80  ("ReconFile,o",               m_reconFileName,                       string(""), "reconstructed YUV output file name\n"
81                                                                                   "YUV writing is skipped if omitted")
82#if NH_3D
83  ("ScaleOffsetFile,p",         cfg_ScaleOffsetFile,                   string(""), "file with coded scales and offsets")
84  ("Depth420OutputFlag",        m_depth420OutputFlag,                  true      , "Output depth layers in 4:2:0 ") 
85#endif
86  ("WarnUnknowParameter,w",     warnUnknowParameter,                                  0, "warn for unknown configuration parameters instead of failing")
87  ("SkipFrames,s",              m_iSkipFrame,                          0,          "number of frames to skip before random access")
88  ("OutputBitDepth,d",          m_outputBitDepth[CHANNEL_TYPE_LUMA],   0,          "bit depth of YUV output luma component (default: use 0 for native depth)")
89  ("OutputBitDepthC,d",         m_outputBitDepth[CHANNEL_TYPE_CHROMA], 0,          "bit depth of YUV output chroma component (default: use 0 for native depth)")
90  ("OutputColourSpaceConvert",  outputColourSpaceConvert,              string(""), "Colour space conversion to apply to input 444 video. Permitted values are (empty string=UNCHANGED) " + getListOfColourSpaceConverts(false))
91#if NH_MV
92  ("TargetOptLayerSetIdx,x", m_targetOptLayerSetInd, std::vector<Int>(1,-1), "Target output layer set index. (default: -1, determine automatically to be equal to highest layer set index") // Should actually equal to 0 as default. However, this would cause only the base layer to be decoded. 
93#endif
94  ("MaxTemporalLayer,t",        m_iMaxTemporalLayer,                   -1,         "Maximum Temporal Layer to be decoded. -1 to decode all layers")
95  ("SEIDecodedPictureHash",     m_decodedPictureHashSEIEnabled,        1,          "Control handling of decoded picture hash SEI messages\n"
96                                                                                   "\t1: check hash in SEI messages if available in the bitstream\n"
97                                                                                   "\t0: ignore SEI message")
98  ("SEINoDisplay",              m_decodedNoDisplaySEIEnabled,          true,       "Control handling of decoded no display SEI messages")
99  ("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.")
100  ("RespectDefDispWindow,w",    m_respectDefDispWindow,                0,          "Only output content inside the default display window\n")
101#if NH_MV
102  ("OutputVpsInfo,v",           m_printVpsInfo,                       false,       "Output information about the layer dependencies and layer sets")
103  ("PrintPicOutput,c" ,         m_printPicOutput,                     false,         "Print information on picture output")
104  ("PrintNalus,n",              m_printReceivedNalus,                 false,        "Print information on received NAL units")
105#endif
106  ("SEIColourRemappingInfoFilename",  m_colourRemapSEIFileName,        string(""), "Colour Remapping YUV output file name. If empty, no remapping is applied (ignore SEI message)\n")
107
108#if O0043_BEST_EFFORT_DECODING
109  ("ForceDecodeBitDepth",       m_forceDecodeBitDepth,                 0U,         "Force the decoder to operate at a particular bit-depth (best effort decoding)")
110#endif
111#if NH_MV_SEI
112  ("OutputDecodedSEIMessagesFilename,m",  m_outputDecodedSEIMessagesFilename,    string(""), "When non empty, output decoded SEI messages to the indicated file. If file is '-', then output to stdout\n")
113#else
114  ("OutputDecodedSEIMessagesFilename",  m_outputDecodedSEIMessagesFilename,    string(""), "When non empty, output decoded SEI messages to the indicated file. If file is '-', then output to stdout\n")
115#endif
116  ("ClipOutputVideoToRec709Range",      m_bClipOutputVideoToRec709Range,  false, "If true then clip output video to the Rec. 709 Range on saving")
117  ;
118
119  po::setDefaults(opts);
120  po::ErrorReporter err;
121  const list<const TChar*>& argv_unhandled = po::scanArgv(opts, argc, (const TChar**) argv, err);
122
123  for (list<const TChar*>::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++)
124  {
125    fprintf(stderr, "Unhandled argument ignored: `%s'\n", *it);
126  }
127
128  if (argc == 1 || do_help)
129  {
130    po::doHelp(cout, opts);
131    return false;
132  }
133
134  if (err.is_errored)
135  {
136    if (!warnUnknowParameter)
137    {
138      /* errors have already been reported to stderr */
139      return false;
140    }
141  }
142
143  m_outputColourSpaceConvert = stringToInputColourSpaceConvert(outputColourSpaceConvert, false);
144  if (m_outputColourSpaceConvert>=NUMBER_INPUT_COLOUR_SPACE_CONVERSIONS)
145  {
146    fprintf(stderr, "Bad output colour space conversion string\n");
147    return false;
148  }
149
150#if NH_3D
151  m_pchScaleOffsetFile = cfg_ScaleOffsetFile.empty() ? NULL : strdup(cfg_ScaleOffsetFile.c_str());
152#endif
153
154  if (m_bitstreamFileName.empty())
155  {
156    fprintf(stderr, "No input file specified, aborting\n");
157    return false;
158  }
159
160  if ( !cfg_TargetDecLayerIdSetFile.empty() )
161  {
162#if NH_MV
163    m_targetDecLayerIdSetFileEmpty = false;     
164#endif
165    FILE* targetDecLayerIdSetFile = fopen ( cfg_TargetDecLayerIdSetFile.c_str(), "r" );
166    if ( targetDecLayerIdSetFile )
167    {
168      Bool isLayerIdZeroIncluded = false;
169      while ( !feof(targetDecLayerIdSetFile) )
170      {
171        Int layerIdParsed = 0;
172        if ( fscanf( targetDecLayerIdSetFile, "%d ", &layerIdParsed ) != 1 )
173        {
174          if ( m_targetDecLayerIdSet.size() == 0 )
175          {
176            fprintf(stderr, "No LayerId could be parsed in file %s. Decoding all LayerIds as default.\n", cfg_TargetDecLayerIdSetFile.c_str() );
177          }
178          break;
179        }
180        if ( layerIdParsed  == -1 ) // The file includes a -1, which means all LayerIds are to be decoded.
181        {
182          m_targetDecLayerIdSet.clear(); // Empty set means decoding all layers.
183          break;
184        }
185        if ( layerIdParsed < 0 || layerIdParsed >= MAX_NUM_LAYER_IDS )
186        {
187          fprintf(stderr, "Warning! Parsed LayerId %d is not within allowed range [0,%d]. Ignoring this value.\n", layerIdParsed, MAX_NUM_LAYER_IDS-1 );
188        }
189        else
190        {
191          isLayerIdZeroIncluded = layerIdParsed == 0 ? true : isLayerIdZeroIncluded;
192          m_targetDecLayerIdSet.push_back ( layerIdParsed );
193        }
194      }
195      fclose (targetDecLayerIdSetFile);
196      if ( m_targetDecLayerIdSet.size() > 0 && !isLayerIdZeroIncluded )
197      {
198        fprintf(stderr, "TargetDecLayerIdSet must contain LayerId=0, aborting" );
199        return false;
200      }
201    }
202    else
203    {
204      fprintf(stderr, "File %s could not be opened. Using all LayerIds as default.\n", cfg_TargetDecLayerIdSetFile.c_str() );
205    }
206  }
207
208#if NH_MV
209  //m_targetDecLayerIdSet.push_back( 0 );         // Only base layer at startup
210#endif
211  return true;
212}
213
214#if NH_MV
215Void TAppDecCfg::xAppendToFileNameEnd( const TChar* pchInputFileName, const TChar* pchStringToAppend, TChar*& rpchOutputFileName)
216{
217  size_t iInLength     = strlen(pchInputFileName);
218  size_t iAppendLength = strlen(pchStringToAppend); 
219
220  rpchOutputFileName = (TChar*) malloc(iInLength+iAppendLength+1);                       
221  const TChar* pCDot = strrchr(pchInputFileName,'.');         
222  pCDot = pCDot ? pCDot : pchInputFileName + iInLength;       
223  size_t iCharsToDot = pCDot - pchInputFileName ; 
224  size_t iCharsToEnd = iInLength - iCharsToDot;         
225  strncpy(rpchOutputFileName                            ,  pchInputFileName            , iCharsToDot  );
226  strncpy(rpchOutputFileName+ iCharsToDot               ,  pchStringToAppend           , iAppendLength); 
227  strncpy(rpchOutputFileName+ iCharsToDot+iAppendLength ,  pchInputFileName+iCharsToDot, iCharsToEnd  );       
228  rpchOutputFileName[iInLength+iAppendLength] = '\0';         
229}
230#endif
231//! \}
Note: See TracBrowser for help on using the repository browser.