source: SHVCSoftware/trunk/source/App/TAppDecoder/TAppDecCfg.cpp @ 762

Last change on this file since 762 was 713, checked in by seregin, 11 years ago

merge with SHM-6-dev

  • Property svn:eol-style set to native
File size: 8.9 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
4 * granted under this license. 
5 *
[595]6 * Copyright (c) 2010-2014, 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"
43#if SVC_EXTENSION
44#include <cassert>
45#endif
46
47#ifdef WIN32
48#define strdup _strdup
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, Char* argv[] )
65{
66  Bool do_help = false;
67  string cfg_BitstreamFile;
68#if SVC_EXTENSION
69  string cfg_ReconFile [MAX_LAYERS];
70  Int nLayerNum;
[540]71#if OUTPUT_LAYER_SET_INDEX
72  Int olsIdx;
73#endif
[313]74#if AVC_BASE
75  string cfg_BLReconFile;
76#endif
77#else
78  string cfg_ReconFile;
79#endif
80#if AVC_SYNTAX || SYNTAX_OUTPUT
81  string cfg_BLSyntaxFile;
82#endif
83  string cfg_TargetDecLayerIdSetFile;
84
85  po::Options opts;
86  opts.addOptions()
87  ("help", do_help, false, "this help text")
88  ("BitstreamFile,b", cfg_BitstreamFile, string(""), "bitstream input file name")
89#if SVC_EXTENSION
90  ("ReconFileL%d,-o%d",   cfg_ReconFile,   string(""), MAX_LAYERS, "Layer %d reconstructed YUV output file name\n"
91                                                     "YUV writing is skipped if omitted")
92#if AVC_BASE
93  ("BLReconFile,-ibl",    cfg_BLReconFile,  string(""), "BL reconstructed YUV input file name")
[713]94#if !REPN_FORMAT_IN_VPS
[313]95  ("BLSourceWidth,-wdt",    m_iBLSourceWidth,        0, "BL source picture width")
96  ("BLSourceHeight,-hgt",   m_iBLSourceHeight,       0, "BL source picture height")
[713]97#endif
[313]98#if AVC_SYNTAX
99  ("BLSyntaxFile,-ibs",    cfg_BLSyntaxFile,  string(""), "BL syntax input file name") 
100#endif
101#endif
102#else
103  ("ReconFile,o",     cfg_ReconFile,     string(""), "reconstructed YUV output file name\n"
104                                                     "YUV writing is skipped if omitted")
105#endif
106#if SYNTAX_OUTPUT
107  ("BLSyntaxFile,-ibs",    cfg_BLSyntaxFile,  string(""), "BL syntax input file name")
108  ("BLSourceWidth,-wdt",    m_iBLSourceWidth,        0, "BL source picture width")
109  ("BLSourceHeight,-hgt",   m_iBLSourceHeight,       0, "BL source picture height")
110  ("BLFrames,-fr",          m_iBLFrames,       0, "BL number of frames")
111#endif
112  ("SkipFrames,s", m_iSkipFrame, 0, "number of frames to skip before random access")
113  ("OutputBitDepth,d", m_outputBitDepthY, 0, "bit depth of YUV output luma component (default: use 0 for native depth)")
114  ("OutputBitDepthC,d", m_outputBitDepthC, 0, "bit depth of YUV output chroma component (default: use 0 for native depth)")
115#if SVC_EXTENSION
116  ("LayerNum,-ls", nLayerNum, 1, "Number of layers to be decoded.")
[540]117#if OUTPUT_LAYER_SET_INDEX
118  ("OutpuLayerSetIdx,-olsidx", olsIdx, -1, "Index of output layer set to be decoded.")
119#endif
[313]120#endif
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  ("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.")
127  ("RespectDefDispWindow,w", m_respectDefDispWindow, 0, "Only output content inside the default display window\n")
128  ;
129  po::setDefaults(opts);
130  const list<const Char*>& argv_unhandled = po::scanArgv(opts, argc, (const Char**) argv);
131
132  for (list<const Char*>::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++)
133  {
134    fprintf(stderr, "Unhandled argument ignored: `%s'\n", *it);
135  }
136
137  if (argc == 1 || do_help)
138  {
139    po::doHelp(cout, opts);
140    return false;
141  }
142
143  /* convert std::string to c string for compatability */
144  m_pchBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str());
145#if SVC_EXTENSION
146  m_tgtLayerId = nLayerNum - 1;
147  assert( m_tgtLayerId >= 0 );
[547]148#if O0137_MAX_LAYERID
149  assert( m_tgtLayerId < MAX_NUM_LAYER_IDS );
150#endif
[540]151#if OUTPUT_LAYER_SET_INDEX 
[588]152  this->getCommonDecoderParams()->setTargetOutputLayerSetIdx( olsIdx       );
[540]153  this->getCommonDecoderParams()->setTargetLayerId    ( m_tgtLayerId );
154#endif
[313]155  for(UInt layer=0; layer<= m_tgtLayerId; layer++)
156  {
157    m_pchReconFile[layer] = cfg_ReconFile[layer].empty() ? NULL : strdup(cfg_ReconFile[layer].c_str());
158  }
159#if AVC_BASE
160  m_pchBLReconFile = cfg_BLReconFile.empty() ? NULL : strdup(cfg_BLReconFile.c_str());
161#endif
162#else
163  m_pchReconFile = cfg_ReconFile.empty() ? NULL : strdup(cfg_ReconFile.c_str());
164#endif
165#if AVC_SYNTAX || SYNTAX_OUTPUT
166  m_pchBLSyntaxFile = cfg_BLSyntaxFile.empty() ? NULL : strdup(cfg_BLSyntaxFile.c_str());
167#endif
168
169  if (!m_pchBitstreamFile)
170  {
171    fprintf(stderr, "No input file specifed, aborting\n");
172    return false;
173  }
174
175  if ( !cfg_TargetDecLayerIdSetFile.empty() )
176  {
177    FILE* targetDecLayerIdSetFile = fopen ( cfg_TargetDecLayerIdSetFile.c_str(), "r" );
178    if ( targetDecLayerIdSetFile )
179    {
180      Bool isLayerIdZeroIncluded = false;
181      while ( !feof(targetDecLayerIdSetFile) )
182      {
183        Int layerIdParsed = 0;
184        if ( fscanf( targetDecLayerIdSetFile, "%d ", &layerIdParsed ) != 1 )
185        {
186          if ( m_targetDecLayerIdSet.size() == 0 )
187          {
188            fprintf(stderr, "No LayerId could be parsed in file %s. Decoding all LayerIds as default.\n", cfg_TargetDecLayerIdSetFile.c_str() );
189          }
190          break;
191        }
192        if ( layerIdParsed  == -1 ) // The file includes a -1, which means all LayerIds are to be decoded.
193        {
194          m_targetDecLayerIdSet.clear(); // Empty set means decoding all layers.
195          break;
196        }
197        if ( layerIdParsed < 0 || layerIdParsed >= MAX_NUM_LAYER_IDS )
198        {
199          fprintf(stderr, "Warning! Parsed LayerId %d is not withing allowed range [0,%d]. Ignoring this value.\n", layerIdParsed, MAX_NUM_LAYER_IDS-1 );
200        }
201        else
202        {
203          isLayerIdZeroIncluded = layerIdParsed == 0 ? true : isLayerIdZeroIncluded;
204          m_targetDecLayerIdSet.push_back ( layerIdParsed );
205        }
206      }
207      fclose (targetDecLayerIdSetFile);
208      if ( m_targetDecLayerIdSet.size() > 0 && !isLayerIdZeroIncluded )
209      {
210        fprintf(stderr, "TargetDecLayerIdSet must contain LayerId=0, aborting" );
211        return false;
212      }
213    }
214    else
215    {
216      fprintf(stderr, "File %s could not be opened. Using all LayerIds as default.\n", cfg_TargetDecLayerIdSetFile.c_str() );
217    }
[540]218#if OUTPUT_LAYER_SET_INDEX 
219    this->getCommonDecoderParams()->setTargetDecLayerIdSet( &m_targetDecLayerIdSet );
220#endif
[313]221  }
222
223  return true;
224}
225
226//! \}
Note: See TracBrowser for help on using the repository browser.