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

Last change on this file since 953 was 953, checked in by qualcomm, 10 years ago

Fixes for conformance testing and non-output layers.

  • Value of PicOutputFlag of non-output layers was not being computed correctly. Fixed under MACRO FIX_NON_OUTPUT_LAYER
  • Some fixes for conformance testing under macro FIX_CONF_MODE.

From: Adarsh K. Ramasubramonian <aramasub@…>

  • Property svn:eol-style set to native
File size: 10.4 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-2014, 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 OUTPUT_LAYER_SET_INDEX
72  Int olsIdx;
73#endif
74#if CONFORMANCE_BITSTREAM_MODE
75  string cfg_confPrefix;
76#endif
77#if AVC_BASE
78  string cfg_BLReconFile;
79#endif
80#else
81  string cfg_ReconFile;
82#endif
83
84  string cfg_TargetDecLayerIdSetFile;
85
86  po::Options opts;
87  opts.addOptions()
88  ("help", do_help, false, "this help text")
89  ("BitstreamFile,b", cfg_BitstreamFile, string(""), "bitstream input file name")
90#if SVC_EXTENSION
91  ("ReconFileL%d,-o%d",   cfg_ReconFile,   string(""), MAX_LAYERS, "Layer %d reconstructed YUV output file name\n"
92                                                     "YUV writing is skipped if omitted")
93#if AVC_BASE
94  ("BLReconFile,-ibl",    cfg_BLReconFile,  string(""), "BL reconstructed YUV input file name")
95#if !REPN_FORMAT_IN_VPS
96  ("BLSourceWidth,-wdt",    m_iBLSourceWidth,        0, "BL source picture width")
97  ("BLSourceHeight,-hgt",   m_iBLSourceHeight,       0, "BL source picture height")
98#endif
99#endif
100#else
101  ("ReconFile,o",     cfg_ReconFile,     string(""), "reconstructed YUV output file name\n"
102                                                     "YUV writing is skipped if omitted")
103#endif
104  ("SkipFrames,s", m_iSkipFrame, 0, "number of frames to skip before random access")
105  ("OutputBitDepth,d", m_outputBitDepthY, 0, "bit depth of YUV output luma component (default: use 0 for native depth)")
106  ("OutputBitDepthC,d", m_outputBitDepthC, 0, "bit depth of YUV output chroma component (default: use 0 for native depth)")
107#if SVC_EXTENSION
108#if FIX_CONF_MODE
109  ("LayerNum,-ls", nLayerNum, MAX_NUM_LAYER_IDS, "Number of layers to be decoded.")
110#else
111  ("LayerNum,-ls", nLayerNum, 1, "Number of layers to be decoded.")
112#endif
113#if OUTPUT_LAYER_SET_INDEX
114  ("OutpuLayerSetIdx,-olsidx", olsIdx, -1, "Index of output layer set to be decoded.")
115#endif
116#if CONFORMANCE_BITSTREAM_MODE
117  ("ConformanceBitstremMode,-confMode", m_confModeFlag, false, "Enable generation of conformance bitstream metadata; True: Generate metadata, False: No metadata generated")
118  ("ConformanceMetadataPrefix,-confPrefix", cfg_confPrefix, string(""), "Prefix for the file name of the conformance data. Default name - 'decodedBitstream'")
119#endif
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#if Q0074_COLOUR_REMAPPING_SEI
129  ("SEIColourRemappingInfo", m_colourRemapSEIEnabled, false, "Control handling of Colour Remapping Information SEI messages\n"
130                                              "\t1: apply colour remapping on decoded pictures if available in the bitstream\n"
131                                              "\t0: ignore SEI message")
132#endif
133  ;
134  po::setDefaults(opts);
135  const list<const Char*>& argv_unhandled = po::scanArgv(opts, argc, (const Char**) argv);
136
137  for (list<const Char*>::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++)
138  {
139    fprintf(stderr, "Unhandled argument ignored: `%s'\n", *it);
140  }
141
142  if (argc == 1 || do_help)
143  {
144    po::doHelp(cout, opts);
145    return false;
146  }
147
148  /* convert std::string to c string for compatability */
149  m_pchBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str());
150#if SVC_EXTENSION
151  m_tgtLayerId = nLayerNum - 1;
152  assert( m_tgtLayerId >= 0 );
153#if !FIX_CONF_MODE
154  assert( m_tgtLayerId < MAX_LAYERS );  // If this is wrong, it should be caught by asserts in other locations.
155#endif
156#if O0137_MAX_LAYERID
157  assert( m_tgtLayerId < MAX_NUM_LAYER_IDS );
158#endif
159#if OUTPUT_LAYER_SET_INDEX 
160#if CONFORMANCE_BITSTREAM_MODE
161  if( m_confModeFlag )
162  {
163    assert( olsIdx != -1 ); // In the conformance mode, target output layer set index is to be explicitly specified.
164
165    if( cfg_confPrefix.empty() )
166    {
167      m_confPrefix = string("decodedBitstream");
168    }
169    else
170    {
171      m_confPrefix = cfg_confPrefix;
172    }
173      // Open metadata file and write
174    char fileNameSuffix[255];
175    sprintf(fileNameSuffix, "%s-OLS%d.opl", m_confPrefix.c_str(), olsIdx);  // olsIdx is the target output layer set index.
176    m_metadataFileName = string(fileNameSuffix);
177    m_metadataFileRefresh = true;
178
179    // Decoded layer YUV files
180#if FIX_CONF_MODE
181    for(Int layer= 0; layer <= MAX_VPS_LAYER_ID_PLUS1-1; layer++ )
182#else
183    for(UInt layer=0; layer<= m_tgtLayerId; layer++)
184#endif
185    {
186      sprintf(fileNameSuffix, "%s-L%d.yuv", m_confPrefix.c_str(), layer);  // olsIdx is the target output layer set index.
187      m_decodedYuvLayerFileName[layer] = std::string( fileNameSuffix );
188      m_decodedYuvLayerRefresh[layer] = true;
189    }
190  }
191#endif
192  this->getCommonDecoderParams()->setTargetOutputLayerSetIdx( olsIdx       );
193  this->getCommonDecoderParams()->setTargetLayerId    ( m_tgtLayerId );
194#endif
195#if FIX_CONF_MODE
196  for(Int layer = 0; layer <= MAX_VPS_LAYER_ID_PLUS1-1; layer++ )
197  {
198#else
199  for(UInt layer=0; layer<= m_tgtLayerId; layer++)
200  {
201    assert( layer < MAX_LAYERS );
202#endif
203    m_pchReconFile[layer] = cfg_ReconFile[layer].empty() ? NULL : strdup(cfg_ReconFile[layer].c_str());
204  }
205#if AVC_BASE
206  m_pchBLReconFile = cfg_BLReconFile.empty() ? NULL : strdup(cfg_BLReconFile.c_str());
207#endif
208#else
209  m_pchReconFile = cfg_ReconFile.empty() ? NULL : strdup(cfg_ReconFile.c_str());
210#endif
211
212  if (!m_pchBitstreamFile)
213  {
214    fprintf(stderr, "No input file specifed, aborting\n");
215    return false;
216  }
217
218  if ( !cfg_TargetDecLayerIdSetFile.empty() )
219  {
220    FILE* targetDecLayerIdSetFile = fopen ( cfg_TargetDecLayerIdSetFile.c_str(), "r" );
221    if ( targetDecLayerIdSetFile )
222    {
223      Bool isLayerIdZeroIncluded = false;
224      while ( !feof(targetDecLayerIdSetFile) )
225      {
226        Int layerIdParsed = 0;
227        if ( fscanf( targetDecLayerIdSetFile, "%d ", &layerIdParsed ) != 1 )
228        {
229          if ( m_targetDecLayerIdSet.size() == 0 )
230          {
231            fprintf(stderr, "No LayerId could be parsed in file %s. Decoding all LayerIds as default.\n", cfg_TargetDecLayerIdSetFile.c_str() );
232          }
233          break;
234        }
235        if ( layerIdParsed  == -1 ) // The file includes a -1, which means all LayerIds are to be decoded.
236        {
237          m_targetDecLayerIdSet.clear(); // Empty set means decoding all layers.
238          break;
239        }
240        if ( layerIdParsed < 0 || layerIdParsed >= MAX_NUM_LAYER_IDS )
241        {
242          fprintf(stderr, "Warning! Parsed LayerId %d is not withing allowed range [0,%d]. Ignoring this value.\n", layerIdParsed, MAX_NUM_LAYER_IDS-1 );
243        }
244        else
245        {
246          isLayerIdZeroIncluded = layerIdParsed == 0 ? true : isLayerIdZeroIncluded;
247          m_targetDecLayerIdSet.push_back ( layerIdParsed );
248        }
249      }
250      fclose (targetDecLayerIdSetFile);
251      if ( m_targetDecLayerIdSet.size() > 0 && !isLayerIdZeroIncluded )
252      {
253        fprintf(stderr, "TargetDecLayerIdSet must contain LayerId=0, aborting" );
254        return false;
255      }
256    }
257    else
258    {
259      fprintf(stderr, "File %s could not be opened. Using all LayerIds as default.\n", cfg_TargetDecLayerIdSetFile.c_str() );
260    }
261#if OUTPUT_LAYER_SET_INDEX 
262    this->getCommonDecoderParams()->setTargetDecLayerIdSet( &m_targetDecLayerIdSet );
263#endif
264  }
265
266  return true;
267}
268
269//! \}
Note: See TracBrowser for help on using the repository browser.