source: 3DVCSoftware/branches/HTM-DEV-0.1-dev/source/App/TAppDecoder/TAppDecCfg.cpp @ 330

Last change on this file since 330 was 324, checked in by tech, 12 years ago

Initial development version for update to latest HM version.
Includes MV-HEVC and basic extensions for 3D-HEVC.

  • Property svn:eol-style set to native
File size: 7.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-2013, 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
44#if H_MV
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 */
65Bool TAppDecCfg::parseCfg( Int argc, Char* argv[] )
66{
67  Bool do_help = false;
68  string cfg_BitstreamFile;
69  string cfg_ReconFile;
70  string cfg_TargetDecLayerIdSetFile;
71
72  po::Options opts;
73  opts.addOptions()
74  ("help", do_help, false, "this help text")
75  ("BitstreamFile,b", cfg_BitstreamFile, string(""), "bitstream input file name")
76  ("ReconFile,o",     cfg_ReconFile,     string(""), "reconstructed YUV output file name\n"
77                                                     "YUV writing is skipped if omitted")
78  ("SkipFrames,s", m_iSkipFrame, 0, "number of frames to skip before random access")
79  ("OutputBitDepth,d", m_outputBitDepthY, 0, "bit depth of YUV output luma component (default: use 0 for native depth)")
80  ("OutputBitDepthC,d", m_outputBitDepthC, 0, "bit depth of YUV output chroma component (default: use 0 for native depth)")
81
82#if H_MV
83  ("MaxLayerId,-ls", m_maxLayerId, MAX_NUM_LAYER_IDS-1, "Maximum LayerId to be decoded.")
84#endif
85
86  ("MaxTemporalLayer,t", m_iMaxTemporalLayer, -1, "Maximum Temporal Layer to be decoded. -1 to decode all layers")
87  ("SEIDecodedPictureHash", m_decodedPictureHashSEIEnabled, 1, "Control handling of decoded picture hash SEI messages\n"
88                                              "\t1: check hash in SEI messages if available in the bitstream\n"
89                                              "\t0: ignore SEI message")
90  ("SEIpictureDigest", m_decodedPictureHashSEIEnabled, 1, "deprecated alias for SEIDecodedPictureHash")
91  ("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.")
92  ("RespectDefDispWindow,w", m_respectDefDispWindow, 0, "Only output content inside the default display window\n")
93  ;
94  po::setDefaults(opts);
95  const list<const Char*>& argv_unhandled = po::scanArgv(opts, argc, (const Char**) argv);
96
97  for (list<const Char*>::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++)
98  {
99    fprintf(stderr, "Unhandled argument ignored: `%s'\n", *it);
100  }
101
102  if (argc == 1 || do_help)
103  {
104    po::doHelp(cout, opts);
105    return false;
106  }
107
108  /* convert std::string to c string for compatability */
109  m_pchBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str());
110
111  m_pchReconFile = cfg_ReconFile.empty() ? NULL : strdup(cfg_ReconFile.c_str());
112
113  if (!m_pchBitstreamFile)
114  {
115    fprintf(stderr, "No input file specifed, aborting\n");
116    return false;
117  }
118
119  if ( !cfg_TargetDecLayerIdSetFile.empty() )
120  {
121    FILE* targetDecLayerIdSetFile = fopen ( cfg_TargetDecLayerIdSetFile.c_str(), "r" );
122    if ( targetDecLayerIdSetFile )
123    {
124      Bool isLayerIdZeroIncluded = false;
125      while ( !feof(targetDecLayerIdSetFile) )
126      {
127        Int layerIdParsed = 0;
128        if ( fscanf( targetDecLayerIdSetFile, "%d ", &layerIdParsed ) != 1 )
129        {
130          if ( m_targetDecLayerIdSet.size() == 0 )
131          {
132            fprintf(stderr, "No LayerId could be parsed in file %s. Decoding all LayerIds as default.\n", cfg_TargetDecLayerIdSetFile.c_str() );
133          }
134          break;
135        }
136        if ( layerIdParsed  == -1 ) // The file includes a -1, which means all LayerIds are to be decoded.
137        {
138          m_targetDecLayerIdSet.clear(); // Empty set means decoding all layers.
139          break;
140        }
141        if ( layerIdParsed < 0 || layerIdParsed >= MAX_NUM_LAYER_IDS )
142        {
143          fprintf(stderr, "Warning! Parsed LayerId %d is not withing allowed range [0,%d]. Ignoring this value.\n", layerIdParsed, MAX_NUM_LAYER_IDS-1 );
144        }
145        else
146        {
147          isLayerIdZeroIncluded = layerIdParsed == 0 ? true : isLayerIdZeroIncluded;
148          m_targetDecLayerIdSet.push_back ( layerIdParsed );
149        }
150      }
151      fclose (targetDecLayerIdSetFile);
152      if ( m_targetDecLayerIdSet.size() > 0 && !isLayerIdZeroIncluded )
153      {
154        fprintf(stderr, "TargetDecLayerIdSet must contain LayerId=0, aborting" );
155        return false;
156      }
157    }
158    else
159    {
160      fprintf(stderr, "File %s could not be opened. Using all LayerIds as default.\n", cfg_TargetDecLayerIdSetFile.c_str() );
161    }
162  }
163#if H_MV
164  else
165  {
166    for ( Int curLayerId = 0; curLayerId <= m_maxLayerId; curLayerId++ )
167    {
168      m_targetDecLayerIdSet.push_back( curLayerId );
169    }
170  }
171#endif
172
173  return true;
174}
175
176#if H_MV
177Void TAppDecCfg::xAppendToFileNameEnd( Char* pchInputFileName, const Char* pchStringToAppend, Char*& rpchOutputFileName)
178{
179  size_t iInLength     = strlen(pchInputFileName);
180  size_t iAppendLength = strlen(pchStringToAppend); 
181
182  rpchOutputFileName = (Char*) malloc(iInLength+iAppendLength+1);                       
183  Char* pCDot = strrchr(pchInputFileName,'.');         
184  pCDot = pCDot ? pCDot : pchInputFileName + iInLength;       
185  size_t iCharsToDot = pCDot - pchInputFileName ; 
186  size_t iCharsToEnd = iInLength - iCharsToDot;         
187  strncpy(rpchOutputFileName                            ,  pchInputFileName            , iCharsToDot  );
188  strncpy(rpchOutputFileName+ iCharsToDot               ,  pchStringToAppend           , iAppendLength); 
189  strncpy(rpchOutputFileName+ iCharsToDot+iAppendLength ,  pchInputFileName+iCharsToDot, iCharsToEnd  );       
190  rpchOutputFileName[iInLength+iAppendLength] = '\0';         
191}
192#endif
193
194//! \}
Note: See TracBrowser for help on using the repository browser.