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

Last change on this file since 462 was 38, checked in by seregin, 12 years ago

AVC_SYNTAX: initial porting of the AVC metadata file reading

File size: 8.3 KB
RevLine 
[2]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-2012, 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#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;
71#if AVC_BASE
72  string cfg_BLReconFile;
73#endif
74#else
75  string cfg_ReconFile;
76#endif
[38]77#if AVC_SYNTAX || SYNTAX_OUTPUT
78  string cfg_BLSyntaxFile;
79#endif
[2]80#if TARGET_DECLAYERID_SET
81  string cfg_TargetDecLayerIdSetFile;
82#endif
83
84  po::Options opts;
85  opts.addOptions()
86  ("help", do_help, false, "this help text")
87  ("BitstreamFile,b", cfg_BitstreamFile, string(""), "bitstream input file name")
88#if SVC_EXTENSION
89  ("ReconFileL%d,-o%d",   cfg_ReconFile,   string(""), MAX_LAYERS, "Layer %d reconstructed YUV output file name\n"
90                                                     "YUV writing is skipped if omitted")
91#if AVC_BASE
92  ("BLReconFile,-ibl",    cfg_BLReconFile,  string(""), "BL reconstructed YUV input file name")
93  ("BLSourceWidth,-wdt",    m_iBLSourceWidth,        0, "BL source picture width")
94  ("BLSourceHeight,-hgt",   m_iBLSourceHeight,       0, "BL source picture height")
[38]95#if AVC_SYNTAX
96  ("BLSyntaxFile,-ibs",    cfg_BLSyntaxFile,  string(""), "BL syntax input file name") 
[2]97#endif
[38]98#endif
[2]99#else
100  ("ReconFile,o",     cfg_ReconFile,     string(""), "reconstructed YUV output file name\n"
101                                                     "YUV writing is skipped if omitted")
102#endif
[38]103#if SYNTAX_OUTPUT
104  ("BLSyntaxFile,-ibs",    cfg_BLSyntaxFile,  string(""), "BL syntax input file name")
105  ("BLSourceWidth,-wdt",    m_iBLSourceWidth,        0, "BL source picture width")
106  ("BLSourceHeight,-hgt",   m_iBLSourceHeight,       0, "BL source picture height")
107  ("BLFrames,-fr",          m_iBLFrames,       0, "BL number of frames")
108#endif
[2]109  ("SkipFrames,s", m_iSkipFrame, 0, "number of frames to skip before random access")
110  ("OutputBitDepth,d", m_outputBitDepth, 0u, "bit depth of YUV output file (use 0 for native depth)")
111#if SVC_EXTENSION
112  ("LayerNum,-ls", nLayerNum, 1, "Number of layers to be decoded.")
113#endif
114  ("MaxTemporalLayer,t", m_iMaxTemporalLayer, -1, "Maximum Temporal Layer to be decoded. -1 to decode all layers")
115  ("SEIpictureDigest", m_decodedPictureHashSEIEnabled, 1, "Control handling of decoded picture hash SEI messages\n"
116                                              "\t3: checksum\n"
117                                              "\t2: CRC\n"
118                                              "\t1: MD5\n"
119                                              "\t0: ignore")
120#if TARGET_DECLAYERID_SET
121  ("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.")
122#endif
123  ;
124  po::setDefaults(opts);
125  const list<const char*>& argv_unhandled = po::scanArgv(opts, argc, (const char**) argv);
126
127  for (list<const char*>::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++)
128  {
129    fprintf(stderr, "Unhandled argument ignored: `%s'\n", *it);
130  }
131
132  if (argc == 1 || do_help)
133  {
134    po::doHelp(cout, opts);
135    return false;
136  }
137
138  /* convert std::string to c string for compatability */
139  m_pchBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str());
140#if SVC_EXTENSION
141  m_tgtLayerId = nLayerNum - 1;
142  assert( m_tgtLayerId >= 0 );
143  for(UInt layer=0; layer<= m_tgtLayerId; layer++)
144  {
145    m_pchReconFile[layer] = cfg_ReconFile[layer].empty() ? NULL : strdup(cfg_ReconFile[layer].c_str());
146  }
147#if AVC_BASE
148  m_pchBLReconFile = cfg_BLReconFile.empty() ? NULL : strdup(cfg_BLReconFile.c_str());
149#endif
150#else
151  m_pchReconFile = cfg_ReconFile.empty() ? NULL : strdup(cfg_ReconFile.c_str());
152#endif
[38]153#if AVC_SYNTAX || SYNTAX_OUTPUT
154  m_pchBLSyntaxFile = cfg_BLSyntaxFile.empty() ? NULL : strdup(cfg_BLSyntaxFile.c_str());
155#endif
[2]156
157  if (!m_pchBitstreamFile)
158  {
159    fprintf(stderr, "No input file specifed, aborting\n");
160    return false;
161  }
162
163#if TARGET_DECLAYERID_SET
164  if ( !cfg_TargetDecLayerIdSetFile.empty() )
165  {
166    FILE* targetDecLayerIdSetFile = fopen ( cfg_TargetDecLayerIdSetFile.c_str(), "r" );
167    if ( targetDecLayerIdSetFile )
168    {
169      Bool isLayerIdZeroIncluded = false;
170      while ( !feof(targetDecLayerIdSetFile) )
171      {
172        Int layerIdParsed = 0;
173        if ( fscanf( targetDecLayerIdSetFile, "%d ", &layerIdParsed ) != 1 )
174        {
175          if ( m_targetDecLayerIdSet.size() == 0 )
176          {
177            fprintf(stderr, "No LayerId could be parsed in file %s. Decoding all LayerIds as default.\n", cfg_TargetDecLayerIdSetFile.c_str() );
178          }
179          break;
180        }
181        if ( layerIdParsed  == -1 ) // The file includes a -1, which means all LayerIds are to be decoded.
182        {
183          m_targetDecLayerIdSet.clear(); // Empty set means decoding all layers.
184          break;
185        }
186        if ( layerIdParsed < 0 || layerIdParsed >= MAX_NUM_LAYER_IDS )
187        {
188          fprintf(stderr, "Warning! Parsed LayerId %d is not withing allowed range [0,%d]. Ignoring this value.\n", layerIdParsed, MAX_NUM_LAYER_IDS-1 );
189        }
190        else
191        {
192          isLayerIdZeroIncluded = layerIdParsed == 0 ? true : isLayerIdZeroIncluded;
193          m_targetDecLayerIdSet.push_back ( layerIdParsed );
194        }
195      }
196      fclose (targetDecLayerIdSetFile);
197      if ( m_targetDecLayerIdSet.size() > 0 && !isLayerIdZeroIncluded )
198      {
199        fprintf(stderr, "TargetDecLayerIdSet must contain LayerId=0, aborting" );
200        return false;
201      }
202    }
203    else
204    {
205      fprintf(stderr, "File %s could not be opened. Using all LayerIds as default.\n", cfg_TargetDecLayerIdSetFile.c_str() );
206    }
207  }
208#endif
209
210  return true;
211}
212
213//! \}
Note: See TracBrowser for help on using the repository browser.