source: SHVCSoftware/branches/SHM-6-dev/source/App/TAppEncoder/TAppEncCfg.cpp @ 721

Last change on this file since 721 was 705, checked in by seregin, 11 years ago

change the conformance input to be not multiplied by SubWidthC and SubHeightC, it should be a lossless change

  • Property svn:eol-style set to native
File size: 123.2 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     TAppEncCfg.cpp
35    \brief    Handle encoder configuration parameters
36*/
37
38#include <stdlib.h>
39#include <cassert>
40#include <cstring>
41#include <string>
42#include "TLibCommon/TComRom.h"
43#include "TAppEncCfg.h"
44
45static istream& operator>>(istream &, Level::Name &);
46static istream& operator>>(istream &, Level::Tier &);
47static istream& operator>>(istream &, Profile::Name &);
48
49#include "TAppCommon/program_options_lite.h"
50#include "TLibEncoder/TEncRateCtrl.h"
51#ifdef WIN32
52#define strdup _strdup
53#endif
54
55using namespace std;
56namespace po = df::program_options_lite;
57
58//! \ingroup TAppEncoder
59//! \{
60
61// ====================================================================================================================
62// Constructor / destructor / initialization / destroy
63// ====================================================================================================================
64
65#if SVC_EXTENSION
66TAppEncCfg::TAppEncCfg()
67: m_pBitstreamFile()
68#if AVC_BASE
69, m_avcBaseLayerFlag(0)
70#endif
71#if N0120_MAX_TID_REF_CFG
72, m_maxTidRefPresentFlag(1)
73#endif
74, m_pColumnWidth()
75, m_pRowHeight()
76, m_scalingListFile()
77, m_elRapSliceBEnabled(0)
78{
79  for(UInt layer=0; layer<MAX_LAYERS; layer++)
80  {
81    m_acLayerCfg[layer].setAppEncCfg(this);
82  }
83  memset( m_scalabilityMask, 0, sizeof(m_scalabilityMask) );
84}
85#else
86TAppEncCfg::TAppEncCfg()
87: m_pchInputFile()
88, m_pchBitstreamFile()
89, m_pchReconFile()
90, m_pchdQPFile()
91, m_pColumnWidth()
92, m_pRowHeight()
93, m_scalingListFile()
94{
95  m_aidQP = NULL;
96  m_startOfCodedInterval = NULL;
97  m_codedPivotValue = NULL;
98  m_targetPivotValue = NULL;
99}
100#endif
101
102TAppEncCfg::~TAppEncCfg()
103{
104#if SVC_EXTENSION
105  free(m_pBitstreamFile);
106#else 
107  if ( m_aidQP )
108  {
109    delete[] m_aidQP;
110  }
111  if ( m_startOfCodedInterval )
112  {
113    delete[] m_startOfCodedInterval;
114    m_startOfCodedInterval = NULL;
115  }
116   if ( m_codedPivotValue )
117  {
118    delete[] m_codedPivotValue;
119    m_codedPivotValue = NULL;
120  }
121  if ( m_targetPivotValue )
122  {
123    delete[] m_targetPivotValue;
124    m_targetPivotValue = NULL;
125  }
126  free(m_pchInputFile);
127  free(m_pchBitstreamFile);
128#endif
129#if !SVC_EXTENSION 
130  free(m_pchReconFile);
131  free(m_pchdQPFile);
132#endif
133  free(m_pColumnWidth);
134  free(m_pRowHeight);
135  free(m_scalingListFile);
136}
137
138Void TAppEncCfg::create()
139{
140}
141
142Void TAppEncCfg::destroy()
143{
144#if VPS_EXTN_DIRECT_REF_LAYERS
145  for(Int layer = 0; layer < MAX_LAYERS; layer++)
146  {
147    if( m_acLayerCfg[layer].m_numSamplePredRefLayers > 0 )
148    {
149      delete [] m_acLayerCfg[layer].m_samplePredRefLayerIds;
150      m_acLayerCfg[layer].m_samplePredRefLayerIds = NULL;
151    }
152    if( m_acLayerCfg[layer].m_numMotionPredRefLayers > 0 )
153    {
154      delete [] m_acLayerCfg[layer].m_motionPredRefLayerIds;
155      m_acLayerCfg[layer].m_motionPredRefLayerIds = NULL;
156    }
157    if( m_acLayerCfg[layer].m_numActiveRefLayers > 0 )
158    {
159      delete [] m_acLayerCfg[layer].m_predLayerIds;
160      m_acLayerCfg[layer].m_predLayerIds = NULL;
161    }
162  }
163#endif
164}
165
166std::istringstream &operator>>(std::istringstream &in, GOPEntry &entry)     //input
167{
168  in>>entry.m_sliceType;
169  in>>entry.m_POC;
170  in>>entry.m_QPOffset;
171  in>>entry.m_QPFactor;
172  in>>entry.m_tcOffsetDiv2;
173  in>>entry.m_betaOffsetDiv2;
174  in>>entry.m_temporalId;
175  in>>entry.m_numRefPicsActive;
176  in>>entry.m_numRefPics;
177  for ( Int i = 0; i < entry.m_numRefPics; i++ )
178  {
179    in>>entry.m_referencePics[i];
180  }
181  in>>entry.m_interRPSPrediction;
182#if AUTO_INTER_RPS
183  if (entry.m_interRPSPrediction==1)
184  {
185    in>>entry.m_deltaRPS;
186    in>>entry.m_numRefIdc;
187    for ( Int i = 0; i < entry.m_numRefIdc; i++ )
188    {
189      in>>entry.m_refIdc[i];
190    }
191  }
192  else if (entry.m_interRPSPrediction==2)
193  {
194    in>>entry.m_deltaRPS;
195  }
196#else
197  if (entry.m_interRPSPrediction)
198  {
199    in>>entry.m_deltaRPS;
200    in>>entry.m_numRefIdc;
201    for ( Int i = 0; i < entry.m_numRefIdc; i++ )
202    {
203      in>>entry.m_refIdc[i];
204    }
205  }
206#endif
207  return in;
208}
209
210#if AUXILIARY_PICTURES
211static inline ChromaFormat numberToChromaFormat(const Int val)
212{
213  switch (val)
214  {
215    case 400: return CHROMA_400; break;
216    case 420: return CHROMA_420; break;
217    case 422: return CHROMA_422; break;
218    case 444: return CHROMA_444; break;
219    default:  return NUM_CHROMA_FORMAT;
220  }
221}
222#endif
223
224#if SVC_EXTENSION
225void TAppEncCfg::getDirFilename(string& filename, string& dir, const string path)
226{
227  size_t pos = path.find_last_of("\\");
228  if(pos != std::string::npos)
229  {
230    filename.assign(path.begin() + pos + 1, path.end());
231    dir.assign(path.begin(), path.begin() + pos + 1);
232  }
233  else
234  {
235    pos = path.find_last_of("/");
236    if(pos != std::string::npos)
237    {
238      filename.assign(path.begin() + pos + 1, path.end());
239      dir.assign(path.begin(), path.begin() + pos + 1);
240    }
241    else
242    {
243      filename = path;
244      dir.assign("");
245    }
246  }
247}
248#endif
249
250static const struct MapStrToProfile {
251  const Char* str;
252  Profile::Name value;
253} strToProfile[] = {
254  {"none", Profile::NONE},
255  {"main", Profile::MAIN},
256  {"main10", Profile::MAIN10},
257  {"main-still-picture", Profile::MAINSTILLPICTURE},
258};
259
260static const struct MapStrToTier {
261  const Char* str;
262  Level::Tier value;
263} strToTier[] = {
264  {"main", Level::MAIN},
265  {"high", Level::HIGH},
266};
267
268static const struct MapStrToLevel {
269  const Char* str;
270  Level::Name value;
271} strToLevel[] = {
272  {"none",Level::NONE},
273  {"1",   Level::LEVEL1},
274  {"2",   Level::LEVEL2},
275  {"2.1", Level::LEVEL2_1},
276  {"3",   Level::LEVEL3},
277  {"3.1", Level::LEVEL3_1},
278  {"4",   Level::LEVEL4},
279  {"4.1", Level::LEVEL4_1},
280  {"5",   Level::LEVEL5},
281  {"5.1", Level::LEVEL5_1},
282  {"5.2", Level::LEVEL5_2},
283  {"6",   Level::LEVEL6},
284  {"6.1", Level::LEVEL6_1},
285  {"6.2", Level::LEVEL6_2},
286};
287
288template<typename T, typename P>
289static istream& readStrToEnum(P map[], unsigned long mapLen, istream &in, T &val)
290{
291  string str;
292  in >> str;
293
294  for (Int i = 0; i < mapLen; i++)
295  {
296    if (str == map[i].str)
297    {
298      val = map[i].value;
299      goto found;
300    }
301  }
302  /* not found */
303  in.setstate(ios::failbit);
304found:
305  return in;
306}
307
308static istream& operator>>(istream &in, Profile::Name &profile)
309{
310  return readStrToEnum(strToProfile, sizeof(strToProfile)/sizeof(*strToProfile), in, profile);
311}
312
313static istream& operator>>(istream &in, Level::Tier &tier)
314{
315  return readStrToEnum(strToTier, sizeof(strToTier)/sizeof(*strToTier), in, tier);
316}
317
318static istream& operator>>(istream &in, Level::Name &level)
319{
320  return readStrToEnum(strToLevel, sizeof(strToLevel)/sizeof(*strToLevel), in, level);
321}
322
323// ====================================================================================================================
324// Public member functions
325// ====================================================================================================================
326
327/** \param  argc        number of arguments
328    \param  argv        array of arguments
329    \retval             true when success
330 */
331Bool TAppEncCfg::parseCfg( Int argc, Char* argv[] )
332{
333  Bool do_help = false;
334 
335#if SVC_EXTENSION
336  string  cfg_LayerCfgFile   [MAX_LAYERS];
337  string  cfg_BitstreamFile;
338  string* cfg_InputFile      [MAX_LAYERS];
339  string* cfg_ReconFile      [MAX_LAYERS];
340  Double* cfg_fQP            [MAX_LAYERS];
341#if Q0074_SEI_COLOR_MAPPING
342  string* cfg_seiColorMappingFile[MAX_LAYERS];
343#endif
344
345#if REPN_FORMAT_IN_VPS
346  Int*    cfg_repFormatIdx  [MAX_LAYERS];
347#endif
348  Int*    cfg_SourceWidth   [MAX_LAYERS]; 
349  Int*    cfg_SourceHeight  [MAX_LAYERS];
350  Int*    cfg_FrameRate     [MAX_LAYERS];
351  Int*    cfg_IntraPeriod   [MAX_LAYERS];
352  Int*    cfg_conformanceMode  [MAX_LAYERS];
353#if LAYER_CTB
354  // coding unit (CU) definition
355  UInt*      cfg_uiMaxCUWidth[MAX_LAYERS];                                   ///< max. CU width in pixel
356  UInt*      cfg_uiMaxCUHeight[MAX_LAYERS];                                  ///< max. CU height in pixel
357  UInt*      cfg_uiMaxCUDepth[MAX_LAYERS];                                   ///< max. CU depth
358 
359  // transfom unit (TU) definition
360  UInt*      cfg_uiQuadtreeTULog2MaxSize[MAX_LAYERS];
361  UInt*      cfg_uiQuadtreeTULog2MinSize[MAX_LAYERS];
362 
363  UInt*      cfg_uiQuadtreeTUMaxDepthInter[MAX_LAYERS];
364  UInt*      cfg_uiQuadtreeTUMaxDepthIntra[MAX_LAYERS];
365#endif
366#if AUXILIARY_PICTURES
367  Int      cfg_tmpChromaFormatIDC  [MAX_LAYERS];
368  Int      cfg_tmpInputChromaFormat[MAX_LAYERS];
369  Int*     cfg_auxId               [MAX_LAYERS];
370#endif
371#if VPS_EXTN_DIRECT_REF_LAYERS
372  Int*    cfg_numSamplePredRefLayers  [MAX_LAYERS];
373  string  cfg_samplePredRefLayerIds   [MAX_LAYERS];
374  string* cfg_samplePredRefLayerIdsPtr[MAX_LAYERS];
375  Int*    cfg_numMotionPredRefLayers  [MAX_LAYERS];
376  string  cfg_motionPredRefLayerIds   [MAX_LAYERS];
377  string* cfg_motionPredRefLayerIdsPtr[MAX_LAYERS];
378  Int*    cfg_numActiveRefLayers [MAX_LAYERS];
379  string  cfg_predLayerIds       [MAX_LAYERS];
380  string* cfg_predLayerIdsPtr    [MAX_LAYERS];
381#endif
382#if O0098_SCALED_REF_LAYER_ID
383  string    cfg_scaledRefLayerId [MAX_LAYERS];
384#endif
385  string    cfg_scaledRefLayerLeftOffset [MAX_LAYERS];
386  string    cfg_scaledRefLayerTopOffset [MAX_LAYERS];
387  string    cfg_scaledRefLayerRightOffset [MAX_LAYERS];
388  string    cfg_scaledRefLayerBottomOffset [MAX_LAYERS];
389  Int*      cfg_numScaledRefLayerOffsets[MAX_LAYERS];
390#if P0312_VERT_PHASE_ADJ
391  string    cfg_vertPhasePositionEnableFlag[MAX_LAYERS];
392#endif
393
394#if O0098_SCALED_REF_LAYER_ID
395  string*    cfg_scaledRefLayerIdPtr           [MAX_LAYERS];
396#endif
397  string*    cfg_scaledRefLayerLeftOffsetPtr   [MAX_LAYERS];
398  string*    cfg_scaledRefLayerTopOffsetPtr    [MAX_LAYERS];
399  string*    cfg_scaledRefLayerRightOffsetPtr  [MAX_LAYERS];
400  string*    cfg_scaledRefLayerBottomOffsetPtr [MAX_LAYERS];
401#if P0312_VERT_PHASE_ADJ
402  string*    cfg_vertPhasePositionEnableFlagPtr[MAX_LAYERS];
403#endif
404
405#if RC_SHVC_HARMONIZATION
406  Bool*   cfg_RCEnableRateControl  [MAX_LAYERS];
407  Int*    cfg_RCTargetBitRate      [MAX_LAYERS];
408  Bool*   cfg_RCKeepHierarchicalBit[MAX_LAYERS];
409  Bool*   cfg_RCLCULevelRC         [MAX_LAYERS];
410  Bool*   cfg_RCUseLCUSeparateModel[MAX_LAYERS];
411  Int*    cfg_RCInitialQP          [MAX_LAYERS];
412  Bool*   cfg_RCForceIntraQP       [MAX_LAYERS];
413#endif
414#if O0194_DIFFERENT_BITDEPTH_EL_BL
415  Int*    cfg_InputBitDepthY    [MAX_LAYERS];
416  Int*    cfg_InternalBitDepthY [MAX_LAYERS];
417  Int*    cfg_InputBitDepthC    [MAX_LAYERS];
418  Int*    cfg_InternalBitDepthC [MAX_LAYERS];
419  Int*    cfg_OutputBitDepthY   [MAX_LAYERS];
420  Int*    cfg_OutputBitDepthC   [MAX_LAYERS];
421#endif
422#if N0120_MAX_TID_REF_CFG
423  Int*    cfg_maxTidIlRefPicsPlus1[MAX_LAYERS]; 
424#endif
425  for(UInt layer = 0; layer < MAX_LAYERS; layer++)
426  {
427    cfg_InputFile[layer]    = &m_acLayerCfg[layer].m_cInputFile;
428    cfg_ReconFile[layer]    = &m_acLayerCfg[layer].m_cReconFile;
429    cfg_fQP[layer]          = &m_acLayerCfg[layer].m_fQP;
430#if REPN_FORMAT_IN_VPS
431    cfg_repFormatIdx[layer] = &m_acLayerCfg[layer].m_repFormatIdx;
432#endif
433    cfg_SourceWidth[layer]  = &m_acLayerCfg[layer].m_iSourceWidth;
434    cfg_SourceHeight[layer] = &m_acLayerCfg[layer].m_iSourceHeight;
435    cfg_FrameRate[layer]    = &m_acLayerCfg[layer].m_iFrameRate; 
436    cfg_IntraPeriod[layer]  = &m_acLayerCfg[layer].m_iIntraPeriod; 
437    cfg_conformanceMode[layer] = &m_acLayerCfg[layer].m_conformanceMode;
438#if Q0074_SEI_COLOR_MAPPING
439    cfg_seiColorMappingFile[layer] = &m_acLayerCfg[layer].m_cSeiColorMappingFile;
440#endif
441#if LAYER_CTB
442    // coding unit (CU) definition
443    cfg_uiMaxCUWidth[layer]  = &m_acLayerCfg[layer].m_uiMaxCUWidth;
444    cfg_uiMaxCUHeight[layer] = &m_acLayerCfg[layer].m_uiMaxCUHeight;
445    cfg_uiMaxCUDepth[layer]  = &m_acLayerCfg[layer].m_uiMaxCUDepth;
446
447    // transfom unit (TU) definition.
448    cfg_uiQuadtreeTULog2MaxSize[layer] = &m_acLayerCfg[layer].m_uiQuadtreeTULog2MaxSize;
449    cfg_uiQuadtreeTULog2MinSize[layer] = &m_acLayerCfg[layer].m_uiQuadtreeTULog2MinSize;
450
451    cfg_uiQuadtreeTUMaxDepthInter[layer] = &m_acLayerCfg[layer].m_uiQuadtreeTUMaxDepthInter;
452    cfg_uiQuadtreeTUMaxDepthIntra[layer] = &m_acLayerCfg[layer].m_uiQuadtreeTUMaxDepthIntra;
453#endif
454#if VPS_EXTN_DIRECT_REF_LAYERS
455    cfg_numSamplePredRefLayers  [layer] = &m_acLayerCfg[layer].m_numSamplePredRefLayers;
456    cfg_samplePredRefLayerIdsPtr[layer] = &cfg_samplePredRefLayerIds[layer];
457    cfg_numMotionPredRefLayers  [layer] = &m_acLayerCfg[layer].m_numMotionPredRefLayers;
458    cfg_motionPredRefLayerIdsPtr[layer] = &cfg_motionPredRefLayerIds[layer];
459    cfg_numActiveRefLayers  [layer] = &m_acLayerCfg[layer].m_numActiveRefLayers;
460    cfg_predLayerIdsPtr     [layer]  = &cfg_predLayerIds[layer];
461#endif
462    cfg_numScaledRefLayerOffsets [layer] = &m_acLayerCfg[layer].m_numScaledRefLayerOffsets;
463    for(Int i = 0; i < MAX_LAYERS; i++)
464    {
465#if O0098_SCALED_REF_LAYER_ID
466      cfg_scaledRefLayerIdPtr          [layer] = &cfg_scaledRefLayerId[layer];
467#endif
468      cfg_scaledRefLayerLeftOffsetPtr  [layer] = &cfg_scaledRefLayerLeftOffset[layer];
469      cfg_scaledRefLayerTopOffsetPtr   [layer] = &cfg_scaledRefLayerTopOffset[layer];
470      cfg_scaledRefLayerRightOffsetPtr [layer] = &cfg_scaledRefLayerRightOffset[layer];
471      cfg_scaledRefLayerBottomOffsetPtr[layer] = &cfg_scaledRefLayerBottomOffset[layer];
472#if P0312_VERT_PHASE_ADJ
473      cfg_vertPhasePositionEnableFlagPtr[layer] = &cfg_vertPhasePositionEnableFlag[layer];
474#endif
475    }
476#if RC_SHVC_HARMONIZATION
477    cfg_RCEnableRateControl[layer]   = &m_acLayerCfg[layer].m_RCEnableRateControl;
478    cfg_RCTargetBitRate[layer]       = &m_acLayerCfg[layer].m_RCTargetBitrate;
479    cfg_RCKeepHierarchicalBit[layer] = &m_acLayerCfg[layer].m_RCKeepHierarchicalBit;
480    cfg_RCLCULevelRC[layer]          = &m_acLayerCfg[layer].m_RCLCULevelRC;
481    cfg_RCUseLCUSeparateModel[layer] = &m_acLayerCfg[layer].m_RCUseLCUSeparateModel;
482    cfg_RCInitialQP[layer]           = &m_acLayerCfg[layer].m_RCInitialQP;
483    cfg_RCForceIntraQP[layer]        = &m_acLayerCfg[layer].m_RCForceIntraQP;
484#endif
485#if O0194_DIFFERENT_BITDEPTH_EL_BL
486  cfg_InputBitDepthY   [layer] = &m_acLayerCfg[layer].m_inputBitDepthY;
487  cfg_InternalBitDepthY[layer] = &m_acLayerCfg[layer].m_internalBitDepthY;
488  cfg_InputBitDepthC   [layer] = &m_acLayerCfg[layer].m_inputBitDepthC;
489  cfg_InternalBitDepthC[layer] = &m_acLayerCfg[layer].m_internalBitDepthC;
490  cfg_OutputBitDepthY  [layer] = &m_acLayerCfg[layer].m_outputBitDepthY;
491  cfg_OutputBitDepthC  [layer] = &m_acLayerCfg[layer].m_outputBitDepthC;
492#endif
493#if N0120_MAX_TID_REF_CFG
494    cfg_maxTidIlRefPicsPlus1[layer] = &m_acLayerCfg[layer].m_maxTidIlRefPicsPlus1; 
495#endif
496#if AUXILIARY_PICTURES
497    cfg_auxId[layer]                = &m_acLayerCfg[layer].m_auxId; 
498#endif
499  }
500#if AVC_BASE
501  string  cfg_BLInputFile;
502#endif
503#if AVC_SYNTAX
504  string  cfg_BLSyntaxFile;
505#endif
506#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
507  string  cfg_tileSets;
508#endif
509#else //SVC_EXTENSION
510  string cfg_InputFile;
511  string cfg_BitstreamFile;
512  string cfg_ReconFile;
513  string cfg_dQPFile;
514#endif //SVC_EXTENSION
515  string cfg_ColumnWidth;
516  string cfg_RowHeight;
517  string cfg_ScalingListFile;
518  string cfg_startOfCodedInterval;
519  string cfg_codedPivotValue;
520  string cfg_targetPivotValue;
521  po::Options opts;
522  opts.addOptions()
523  ("help", do_help, false, "this help text")
524  ("c", po::parseConfigFile, "configuration file name")
525 
526  // File, I/O and source parameters
527#if SVC_EXTENSION
528  ("InputFile%d,-i%d",        cfg_InputFile,  string(""), MAX_LAYERS, "original YUV input file name for layer %d")
529  ("ReconFile%d,-o%d",        cfg_ReconFile,  string(""), MAX_LAYERS, "reconstruction YUV input file name for layer %d")
530  ("LayerConfig%d,-lc%d",     cfg_LayerCfgFile, string(""), MAX_LAYERS, "layer %d configuration file name")
531  ("SourceWidth%d,-wdt%d",    cfg_SourceWidth, 0, MAX_LAYERS, "Source picture width for layer %d")
532  ("SourceHeight%d,-hgt%d",   cfg_SourceHeight, 0, MAX_LAYERS, "Source picture height for layer %d")
533  ("FrameRate%d,-fr%d",       cfg_FrameRate,  0, MAX_LAYERS, "Frame rate for layer %d")
534  ("LambdaModifier%d,-LM%d",  m_adLambdaModifier, ( double )1.0, MAX_TLAYER, "Lambda modifier for temporal layer %d")
535#if O0215_PHASE_ALIGNMENT
536  ("PhaseAlignment",          m_phaseAlignFlag, false, "indicate the sample location alignment between layers (0: zero position aligned, 1: central position aligned)")
537#endif
538#if REPN_FORMAT_IN_VPS
539  ("RepFormatIdx%d",          cfg_repFormatIdx, -1, MAX_LAYERS, "Index to the representation format structure used from the VPS")
540#endif
541#if VPS_EXTN_DIRECT_REF_LAYERS
542  ("NumSamplePredRefLayers%d",cfg_numSamplePredRefLayers, -1, MAX_LAYERS, "Number of sample prediction reference layers")
543  ("SamplePredRefLayerIds%d", cfg_samplePredRefLayerIdsPtr, string(""), MAX_LAYERS, "sample pred reference layer IDs")
544  ("NumMotionPredRefLayers%d",cfg_numMotionPredRefLayers, -1, MAX_LAYERS, "Number of motion prediction reference layers")
545  ("MotionPredRefLayerIds%d", cfg_motionPredRefLayerIdsPtr, string(""), MAX_LAYERS, "motion pred reference layer IDs")
546  ("NumActiveRefLayers%d",    cfg_numActiveRefLayers, -1, MAX_LAYERS, "Number of active reference layers")
547  ("PredLayerIds%d",          cfg_predLayerIdsPtr, string(""), MAX_LAYERS, "inter-layer prediction layer IDs")
548#endif
549  ("NumLayers",               m_numLayers, 1, "Number of layers to code")
550#if AUXILIARY_PICTURES
551  ("InputChromaFormat%d",     cfg_tmpInputChromaFormat,  420, MAX_LAYERS, "InputChromaFormatIDC for layer %d")
552  ("ChromaFormatIDC%d,-cf",   cfg_tmpChromaFormatIDC,    420, MAX_LAYERS, "ChromaFormatIDC (400|420|422|444 or set 0 (default) for same as InputChromaFormat) for layer %d")
553  ("AuxId%d",                 cfg_auxId,                 0,   MAX_LAYERS, "Auxilary picture ID for layer %d (0: Not aux pic, 1: Alpha plane, 2: Depth picture, 3: Cb enh, 4: Cr enh")
554#endif
555  ("ConformanceMode%d",       cfg_conformanceMode,0, MAX_LAYERS, "Window conformance mode (0: no cropping, 1:automatic padding, 2: padding, 3:cropping")
556#if SCALABILITY_MASK_E0104
557  ("ScalabilityMask1",        m_scalabilityMask[1], 0, "scalability_mask[1] (multiview)")
558  ("ScalabilityMask2",        m_scalabilityMask[2], 1, "scalability_mask[2] (scalable)" )
559#if AUXILIARY_PICTURES
560  ("ScalabilityMask3",        m_scalabilityMask[3], 0, "scalability_mask[3] (auxiliary pictures)" )
561#endif
562#else
563  ("ScalabilityMask0",        m_scalabilityMask[0], 0, "scalability_mask[0] (multiview)")
564  ("ScalabilityMask1",        m_scalabilityMask[1], 1, "scalability_mask[1] (scalable)" )
565#endif
566  ("BitstreamFile,b",         cfg_BitstreamFile, string(""), "Bitstream output file name")
567#if !O0194_DIFFERENT_BITDEPTH_EL_BL
568  ("InputBitDepth",           m_inputBitDepthY,    8, "Bit-depth of input file")
569  ("OutputBitDepth",          m_outputBitDepthY,   0, "Bit-depth of output file (default:InternalBitDepth)")
570  ("InternalBitDepth",        m_internalBitDepthY, 0, "Bit-depth the codec operates at. (default:InputBitDepth)"
571                                                       "If different to InputBitDepth, source data will be converted")
572  ("InputBitDepthC",          m_inputBitDepthC,    0, "As per InputBitDepth but for chroma component. (default:InputBitDepth)")
573  ("OutputBitDepthC",         m_outputBitDepthC,   0, "As per OutputBitDepth but for chroma component. (default:InternalBitDepthC)")
574  ("InternalBitDepthC",       m_internalBitDepthC, 0, "As per InternalBitDepth but for chroma component. (default:IntrenalBitDepth)")
575#endif
576  ("NumScaledRefLayerOffsets%d",    cfg_numScaledRefLayerOffsets,     0, MAX_LAYERS,  "Number of scaled offset layer sets ")
577#if O0098_SCALED_REF_LAYER_ID
578  ("ScaledRefLayerId%d",           cfg_scaledRefLayerIdPtr,          string(""), MAX_LAYERS, "Layer ID of scaled base layer picture")
579#endif
580  ("ScaledRefLayerLeftOffset%d",   cfg_scaledRefLayerLeftOffsetPtr,  string(""), MAX_LAYERS, "Horizontal offset of top-left luma sample of scaled base layer picture with respect to"
581                                                                 " top-left luma sample of the EL picture, in units of two luma samples")
582  ("ScaledRefLayerTopOffset%d",    cfg_scaledRefLayerTopOffsetPtr,   string(""), MAX_LAYERS,   "Vertical offset of top-left luma sample of scaled base layer picture with respect to"
583                                                                 " top-left luma sample of the EL picture, in units of two luma samples")
584  ("ScaledRefLayerRightOffset%d",  cfg_scaledRefLayerRightOffsetPtr, string(""), MAX_LAYERS, "Horizontal offset of bottom-right luma sample of scaled base layer picture with respect to"
585                                                                 " bottom-right luma sample of the EL picture, in units of two luma samples")
586  ("ScaledRefLayerBottomOffset%d", cfg_scaledRefLayerBottomOffsetPtr,string(""), MAX_LAYERS, "Vertical offset of bottom-right luma sample of scaled base layer picture with respect to"
587  " bottom-right luma sample of the EL picture, in units of two luma samples")
588#if P0312_VERT_PHASE_ADJ
589  ("VertPhasePositionEnableFlag%d", cfg_vertPhasePositionEnableFlagPtr,string(""), MAX_LAYERS, "VertPhasePositionEnableFlag for layer %d")
590#endif
591#if O0194_DIFFERENT_BITDEPTH_EL_BL
592  ("InputBitDepth%d",       cfg_InputBitDepthY,    8, MAX_LAYERS, "Bit-depth of input file for layer %d")
593  ("InternalBitDepth%d",    cfg_InternalBitDepthY, 0, MAX_LAYERS, "Bit-depth the codec operates at. (default:InputBitDepth) for layer %d ")
594//                                                       "If different to InputBitDepth, source data will be converted")
595  ("InputBitDepthC%d",      cfg_InputBitDepthC,    0, MAX_LAYERS, "As per InputBitDepth but for chroma component. (default:InputBitDepth) for layer %d")
596  ("InternalBitDepthC%d",   cfg_InternalBitDepthC, 0, MAX_LAYERS, "As per InternalBitDepth but for chroma component. (default:IntrenalBitDepth) for layer %d")
597  ("OutputBitDepth%d",      cfg_OutputBitDepthY,   0, MAX_LAYERS, "Bit-depth of output file (default:InternalBitDepth)")
598  ("OutputBitDepthC%d",     cfg_OutputBitDepthC,   0, MAX_LAYERS, "As per OutputBitDepth but for chroma component. (default:InternalBitDepthC)")
599#endif
600#if N0120_MAX_TID_REF_CFG
601  ("MaxTidRefPresentFlag", m_maxTidRefPresentFlag, true, "max_tid_ref_present_flag (0: not present, 1: present(default)) " )
602  ("MaxTidIlRefPicsPlus1%d", cfg_maxTidIlRefPicsPlus1, 1, MAX_LAYERS, "allowed maximum temporal_id for inter-layer prediction")
603#endif
604#if O0223_PICTURE_TYPES_ALIGN_FLAG
605  ("CrossLayerPictureTypeAlignFlag", m_crossLayerPictureTypeAlignFlag, true, "align picture type across layers" ) 
606#endif
607#if N0147_IRAP_ALIGN_FLAG
608  ("CrossLayerIrapAlignFlag", m_crossLayerIrapAlignFlag, true, "align IRAP across layers" ) 
609#endif
610#if P0068_CROSS_LAYER_ALIGNED_IDR_ONLY_FOR_IRAP_FLAG
611  ("CrossLayerAlignedIdrOnlyFlag", m_crossLayerAlignedIdrOnlyFlag, true, "only idr for IRAP across layers" ) 
612#endif
613#if O0194_WEIGHTED_PREDICTION_CGS
614  ("InterLayerWeightedPred", m_useInterLayerWeightedPred, false, "enable IL WP parameters estimation at encoder" ) 
615#endif
616#if AVC_BASE
617  ("AvcBase,-avc",            m_avcBaseLayerFlag,     0, "avc_base_layer_flag")
618  ("InputBLFile,-ibl",        cfg_BLInputFile,     string(""), "Base layer rec YUV input file name")
619#if AVC_SYNTAX
620  ("InputBLSyntaxFile,-ibs",  cfg_BLSyntaxFile,     string(""), "Base layer syntax input file name")
621#endif
622#endif
623  ("EnableElRapB,-use-rap-b",  m_elRapSliceBEnabled, 0, "Set ILP over base-layer I picture to B picture (default is P picture)")
624#if Q0074_SEI_COLOR_MAPPING
625  ("SEIColorMappingFile%d", cfg_seiColorMappingFile, string(""), MAX_LAYERS, "File Containing SEI Color Mapping data")
626#endif
627#else //SVC_EXTENSION
628  ("InputFile,i",           cfg_InputFile,     string(""), "Original YUV input file name")
629  ("BitstreamFile,b",       cfg_BitstreamFile, string(""), "Bitstream output file name")
630  ("ReconFile,o",           cfg_ReconFile,     string(""), "Reconstructed YUV output file name")
631  ("SourceWidth,-wdt",      m_iSourceWidth,        0, "Source picture width")
632  ("SourceHeight,-hgt",     m_iSourceHeight,       0, "Source picture height")
633  ("InputBitDepth",         m_inputBitDepthY,    8, "Bit-depth of input file")
634  ("OutputBitDepth",        m_outputBitDepthY,   0, "Bit-depth of output file (default:InternalBitDepth)")
635  ("InternalBitDepth",      m_internalBitDepthY, 0, "Bit-depth the codec operates at. (default:InputBitDepth)"
636                                                       "If different to InputBitDepth, source data will be converted")
637  ("InputBitDepthC",        m_inputBitDepthC,    0, "As per InputBitDepth but for chroma component. (default:InputBitDepth)")
638  ("OutputBitDepthC",       m_outputBitDepthC,   0, "As per OutputBitDepth but for chroma component. (default:InternalBitDepthC)")
639  ("InternalBitDepthC",     m_internalBitDepthC, 0, "As per InternalBitDepth but for chroma component. (default:IntrenalBitDepth)")
640#if AUXILIARY_PICTURES
641  ("InputChromaFormat",     tmpInputChromaFormat,                       420, "InputChromaFormatIDC")
642  ("ChromaFormatIDC,-cf",   tmpChromaFormat,                             0, "ChromaFormatIDC (400|420|422|444 or set 0 (default) for same as InputChromaFormat)")
643#endif
644  ("ConformanceMode",       m_conformanceMode,     0, "Window conformance mode (0: no window, 1:automatic padding, 2:padding, 3:conformance")
645  ("HorizontalPadding,-pdx",m_aiPad[0],            0, "Horizontal source padding for conformance window mode 2")
646  ("VerticalPadding,-pdy",  m_aiPad[1],            0, "Vertical source padding for conformance window mode 2")
647  ("ConfLeft",              m_confLeft,            0, "Left offset for window conformance mode 3")
648  ("ConfRight",             m_confRight,           0, "Right offset for window conformance mode 3")
649  ("ConfTop",               m_confTop,             0, "Top offset for window conformance mode 3")
650  ("ConfBottom",            m_confBottom,          0, "Bottom offset for window conformance mode 3")
651  ("FrameRate,-fr",         m_iFrameRate,          0, "Frame rate")
652#endif //SVC_EXTENSION
653  ("FrameSkip,-fs",         m_FrameSkip,          0u, "Number of frames to skip at start of input YUV")
654  ("FramesToBeEncoded,f",   m_framesToBeEncoded,   0, "Number of frames to be encoded (default=all)")
655
656  //Field coding parameters
657  ("FieldCoding", m_isField, false, "Signals if it's a field based coding")
658  ("TopFieldFirst, Tff", m_isTopFieldFirst, false, "In case of field based coding, signals whether if it's a top field first or not")
659 
660  // Profile and level
661  ("Profile", m_profile,   Profile::NONE, "Profile to be used when encoding (Incomplete)")
662  ("Level",   m_level,     Level::NONE,   "Level limit to be used, eg 5.1 (Incomplete)")
663  ("Tier",    m_levelTier, Level::MAIN,   "Tier to use for interpretation of --Level")
664
665  ("ProgressiveSource", m_progressiveSourceFlag, false, "Indicate that source is progressive")
666  ("InterlacedSource",  m_interlacedSourceFlag,  false, "Indicate that source is interlaced")
667  ("NonPackedSource",   m_nonPackedConstraintFlag, false, "Indicate that source does not contain frame packing")
668  ("FrameOnly",         m_frameOnlyConstraintFlag, false, "Indicate that the bitstream contains only frames")
669
670#if LAYER_CTB
671  // Unit definition parameters
672  ("MaxCUWidth%d",              cfg_uiMaxCUWidth,             64u, MAX_LAYERS, "Maximum CU width")
673  ("MaxCUHeight%d",             cfg_uiMaxCUHeight,            64u, MAX_LAYERS, "Maximum CU height")
674  // todo: remove defaults from MaxCUSize
675  ("MaxCUSize%d,s%d",           cfg_uiMaxCUWidth,             64u, MAX_LAYERS, "Maximum CU size")
676  ("MaxCUSize%d,s%d",           cfg_uiMaxCUHeight,            64u, MAX_LAYERS, "Maximum CU size")
677  ("MaxPartitionDepth%d,h%d",   cfg_uiMaxCUDepth,              4u, MAX_LAYERS, "CU depth")
678 
679  ("QuadtreeTULog2MaxSize%d",   cfg_uiQuadtreeTULog2MaxSize,   6u, MAX_LAYERS, "Maximum TU size in logarithm base 2")
680  ("QuadtreeTULog2MinSize%d",   cfg_uiQuadtreeTULog2MinSize,   2u, MAX_LAYERS, "Minimum TU size in logarithm base 2")
681 
682  ("QuadtreeTUMaxDepthIntra%d", cfg_uiQuadtreeTUMaxDepthIntra, 1u, MAX_LAYERS, "Depth of TU tree for intra CUs")
683  ("QuadtreeTUMaxDepthInter%d", cfg_uiQuadtreeTUMaxDepthInter, 2u, MAX_LAYERS, "Depth of TU tree for inter CUs")
684
685
686  // set the same CU realted settings across all the layers if config file parameters are not layer specific
687  ("MaxCUWidth",              cfg_uiMaxCUWidth,             64u, MAX_LAYERS, "Maximum CU width")
688  ("MaxCUHeight",             cfg_uiMaxCUHeight,            64u, MAX_LAYERS, "Maximum CU height")
689  // todo: remove defaults from MaxCUSize
690  ("MaxCUSize,s",             cfg_uiMaxCUWidth,             64u, MAX_LAYERS, "Maximum CU size")
691  ("MaxCUSize,s",             cfg_uiMaxCUHeight,            64u, MAX_LAYERS, "Maximum CU size")
692  ("MaxPartitionDepth,h",     cfg_uiMaxCUDepth,              4u, MAX_LAYERS, "CU depth")
693 
694  ("QuadtreeTULog2MaxSize",   cfg_uiQuadtreeTULog2MaxSize,   6u, MAX_LAYERS, "Maximum TU size in logarithm base 2")
695  ("QuadtreeTULog2MinSize",   cfg_uiQuadtreeTULog2MinSize,   2u, MAX_LAYERS, "Minimum TU size in logarithm base 2")
696 
697  ("QuadtreeTUMaxDepthIntra", cfg_uiQuadtreeTUMaxDepthIntra, 1u, MAX_LAYERS, "Depth of TU tree for intra CUs")
698  ("QuadtreeTUMaxDepthInter", cfg_uiQuadtreeTUMaxDepthInter, 2u, MAX_LAYERS, "Depth of TU tree for inter CUs")
699#else
700  // Unit definition parameters
701  ("MaxCUWidth",              m_uiMaxCUWidth,             64u)
702  ("MaxCUHeight",             m_uiMaxCUHeight,            64u)
703  // todo: remove defaults from MaxCUSize
704  ("MaxCUSize,s",             m_uiMaxCUWidth,             64u, "Maximum CU size")
705  ("MaxCUSize,s",             m_uiMaxCUHeight,            64u, "Maximum CU size")
706  ("MaxPartitionDepth,h",     m_uiMaxCUDepth,              4u, "CU depth")
707 
708  ("QuadtreeTULog2MaxSize",   m_uiQuadtreeTULog2MaxSize,   6u, "Maximum TU size in logarithm base 2")
709  ("QuadtreeTULog2MinSize",   m_uiQuadtreeTULog2MinSize,   2u, "Minimum TU size in logarithm base 2")
710 
711  ("QuadtreeTUMaxDepthIntra", m_uiQuadtreeTUMaxDepthIntra, 1u, "Depth of TU tree for intra CUs")
712  ("QuadtreeTUMaxDepthInter", m_uiQuadtreeTUMaxDepthInter, 2u, "Depth of TU tree for inter CUs")
713#endif
714 
715  // Coding structure paramters
716#if SVC_EXTENSION
717  ("IntraPeriod%d,-ip%d",  cfg_IntraPeriod, -1, MAX_LAYERS, "intra period in frames for layer %d, (-1: only first frame)")
718#else
719  ("IntraPeriod,-ip",         m_iIntraPeriod,              -1, "Intra period in frames, (-1: only first frame)")
720#endif
721#if ALLOW_RECOVERY_POINT_AS_RAP
722  ("DecodingRefreshType,-dr", m_iDecodingRefreshType,       0, "Intra refresh type (0:none 1:CRA 2:IDR 3:RecPointSEI)")
723#else
724  ("DecodingRefreshType,-dr", m_iDecodingRefreshType,       0, "Intra refresh type (0:none 1:CRA 2:IDR)")
725#endif
726  ("GOPSize,g",               m_iGOPSize,                   1, "GOP size of temporal structure")
727  // motion options
728  ("FastSearch",              m_iFastSearch,                1, "0:Full search  1:Diamond  2:PMVFAST")
729  ("SearchRange,-sr",         m_iSearchRange,              96, "Motion search range")
730  ("BipredSearchRange",       m_bipredSearchRange,          4, "Motion search range for bipred refinement")
731  ("HadamardME",              m_bUseHADME,               true, "Hadamard ME for fractional-pel")
732  ("ASR",                     m_bUseASR,                false, "Adaptive motion search range")
733
734#if SVC_EXTENSION
735  ("LambdaModifier%d,-LM%d",  m_adLambdaModifier, ( double )1.0, MAX_TLAYER, "Lambda modifier for temporal layer %d")
736#else
737  // Mode decision parameters
738  ("LambdaModifier0,-LM0", m_adLambdaModifier[ 0 ], ( Double )1.0, "Lambda modifier for temporal layer 0")
739  ("LambdaModifier1,-LM1", m_adLambdaModifier[ 1 ], ( Double )1.0, "Lambda modifier for temporal layer 1")
740  ("LambdaModifier2,-LM2", m_adLambdaModifier[ 2 ], ( Double )1.0, "Lambda modifier for temporal layer 2")
741  ("LambdaModifier3,-LM3", m_adLambdaModifier[ 3 ], ( Double )1.0, "Lambda modifier for temporal layer 3")
742  ("LambdaModifier4,-LM4", m_adLambdaModifier[ 4 ], ( Double )1.0, "Lambda modifier for temporal layer 4")
743  ("LambdaModifier5,-LM5", m_adLambdaModifier[ 5 ], ( Double )1.0, "Lambda modifier for temporal layer 5")
744  ("LambdaModifier6,-LM6", m_adLambdaModifier[ 6 ], ( Double )1.0, "Lambda modifier for temporal layer 6")
745#endif
746
747  /* Quantization parameters */
748#if SVC_EXTENSION
749  ("QP%d,-q%d",     cfg_fQP,  30.0, MAX_LAYERS, "Qp value for layer %d, if value is float, QP is switched once during encoding")
750#else
751  ("QP,q",          m_fQP,             30.0, "Qp value, if value is float, QP is switched once during encoding")
752#endif
753  ("DeltaQpRD,-dqr",m_uiDeltaQpRD,       0u, "max dQp offset for slice")
754  ("MaxDeltaQP,d",  m_iMaxDeltaQP,        0, "max dQp offset for block")
755  ("MaxCuDQPDepth,-dqd",  m_iMaxCuDQPDepth,        0, "max depth for a minimum CuDQP")
756
757  ("CbQpOffset,-cbqpofs",  m_cbQpOffset,        0, "Chroma Cb QP Offset")
758  ("CrQpOffset,-crqpofs",  m_crQpOffset,        0, "Chroma Cr QP Offset")
759
760#if ADAPTIVE_QP_SELECTION
761  ("AdaptiveQpSelection,-aqps",   m_bUseAdaptQpSelect,           false, "AdaptiveQpSelection")
762#endif
763
764  ("AdaptiveQP,-aq",                m_bUseAdaptiveQP,           false, "QP adaptation based on a psycho-visual model")
765  ("MaxQPAdaptationRange,-aqr",     m_iQPAdaptationRange,           6, "QP adaptation range")
766#if !SVC_EXTENSION
767  ("dQPFile,m",                     cfg_dQPFile,           string(""), "dQP file name")
768#endif
769  ("RDOQ",                          m_useRDOQ,                  true )
770  ("RDOQTS",                        m_useRDOQTS,                true )
771  ("RDpenalty",                     m_rdPenalty,                0,  "RD-penalty for 32x32 TU for intra in non-intra slices. 0:disbaled  1:RD-penalty  2:maximum RD-penalty")
772 
773  // Deblocking filter parameters
774  ("LoopFilterDisable",              m_bLoopFilterDisable,             false )
775  ("LoopFilterOffsetInPPS",          m_loopFilterOffsetInPPS,          false )
776  ("LoopFilterBetaOffset_div2",      m_loopFilterBetaOffsetDiv2,           0 )
777  ("LoopFilterTcOffset_div2",        m_loopFilterTcOffsetDiv2,             0 )
778  ("DeblockingFilterControlPresent", m_DeblockingFilterControlPresent, false )
779  ("DeblockingFilterMetric",         m_DeblockingFilterMetric,         false )
780
781  // Coding tools
782  ("AMP",                      m_enableAMP,                 true,  "Enable asymmetric motion partitions")
783  ("TransformSkip",            m_useTransformSkip,          false, "Intra transform skipping")
784  ("TransformSkipFast",        m_useTransformSkipFast,      false, "Fast intra transform skipping")
785  ("SAO",                      m_bUseSAO,                   true,  "Enable Sample Adaptive Offset")
786  ("MaxNumOffsetsPerPic",      m_maxNumOffsetsPerPic,       2048,  "Max number of SAO offset per picture (Default: 2048)")   
787  ("SAOLcuBoundary",           m_saoLcuBoundary,            false, "0: right/bottom LCU boundary areas skipped from SAO parameter estimation, 1: non-deblocked pixels are used for those areas")
788  ("SliceMode",                m_sliceMode,                0,     "0: Disable all Recon slice limits, 1: Enforce max # of LCUs, 2: Enforce max # of bytes, 3:specify tiles per dependent slice")
789  ("SliceArgument",            m_sliceArgument,            0,     "Depending on SliceMode being:"
790                                                                   "\t1: max number of CTUs per slice"
791                                                                   "\t2: max number of bytes per slice"
792                                                                   "\t3: max number of tiles per slice")
793  ("SliceSegmentMode",         m_sliceSegmentMode,       0,     "0: Disable all slice segment limits, 1: Enforce max # of LCUs, 2: Enforce max # of bytes, 3:specify tiles per dependent slice")
794  ("SliceSegmentArgument",     m_sliceSegmentArgument,   0,     "Depending on SliceSegmentMode being:"
795                                                                   "\t1: max number of CTUs per slice segment"
796                                                                   "\t2: max number of bytes per slice segment"
797                                                                   "\t3: max number of tiles per slice segment")
798  ("LFCrossSliceBoundaryFlag", m_bLFCrossSliceBoundaryFlag, true)
799
800  ("ConstrainedIntraPred",     m_bUseConstrainedIntraPred,  false, "Constrained Intra Prediction")
801
802  ("PCMEnabledFlag",           m_usePCM,                    false)
803  ("PCMLog2MaxSize",           m_pcmLog2MaxSize,            5u)
804  ("PCMLog2MinSize",           m_uiPCMLog2MinSize,          3u)
805  ("PCMInputBitDepthFlag",     m_bPCMInputBitDepthFlag,     true)
806  ("PCMFilterDisableFlag",     m_bPCMFilterDisableFlag,    false)
807
808  ("WeightedPredP,-wpP",          m_useWeightedPred,               false,      "Use weighted prediction in P slices")
809  ("WeightedPredB,-wpB",          m_useWeightedBiPred,             false,      "Use weighted (bidirectional) prediction in B slices")
810  ("Log2ParallelMergeLevel",      m_log2ParallelMergeLevel,     2u,          "Parallel merge estimation region")
811  ("UniformSpacingIdc",           m_iUniformSpacingIdr,            0,          "Indicates if the column and row boundaries are distributed uniformly")
812  ("NumTileColumnsMinus1",        m_iNumColumnsMinus1,             0,          "Number of columns in a picture minus 1")
813  ("ColumnWidthArray",            cfg_ColumnWidth,                 string(""), "Array containing ColumnWidth values in units of LCU")
814  ("NumTileRowsMinus1",           m_iNumRowsMinus1,                0,          "Number of rows in a picture minus 1")
815  ("RowHeightArray",              cfg_RowHeight,                   string(""), "Array containing RowHeight values in units of LCU")
816  ("LFCrossTileBoundaryFlag",      m_bLFCrossTileBoundaryFlag,             true,          "1: cross-tile-boundary loop filtering. 0:non-cross-tile-boundary loop filtering")
817  ("WaveFrontSynchro",            m_iWaveFrontSynchro,             0,          "0: no synchro; 1 synchro with TR; 2 TRR etc")
818  ("ScalingList",                 m_useScalingListId,              0,          "0: no scaling list, 1: default scaling lists, 2: scaling lists specified in ScalingListFile")
819  ("ScalingListFile",             cfg_ScalingListFile,             string(""), "Scaling list file name")
820  ("SignHideFlag,-SBH",                m_signHideFlag, 1)
821  ("MaxNumMergeCand",             m_maxNumMergeCand,             5u,         "Maximum number of merge candidates")
822
823  /* Misc. */
824  ("SEIDecodedPictureHash",       m_decodedPictureHashSEIEnabled, 0, "Control generation of decode picture hash SEI messages\n"
825                                                                    "\t3: checksum\n"
826                                                                    "\t2: CRC\n"
827                                                                    "\t1: use MD5\n"
828                                                                    "\t0: disable")
829  ("SEIpictureDigest",            m_decodedPictureHashSEIEnabled, 0, "deprecated alias for SEIDecodedPictureHash")
830  ("TMVPMode", m_TMVPModeId, 1, "TMVP mode 0: TMVP disable for all slices. 1: TMVP enable for all slices (default) 2: TMVP enable for certain slices only")
831  ("FEN", m_bUseFastEnc, false, "fast encoder setting")
832  ("ECU", m_bUseEarlyCU, false, "Early CU setting") 
833  ("FDM", m_useFastDecisionForMerge, true, "Fast decision for Merge RD Cost") 
834  ("CFM", m_bUseCbfFastMode, false, "Cbf fast mode setting")
835  ("ESD", m_useEarlySkipDetection, false, "Early SKIP detection setting")
836#if FAST_INTRA_SHVC
837  ("FIS", m_useFastIntraScalable, false, "Fast Intra Decision for Scalable HEVC")
838#endif
839#if RC_SHVC_HARMONIZATION
840  ("RateControl%d", cfg_RCEnableRateControl, false, MAX_LAYERS, "Rate control: enable rate control for layer %d")
841  ("TargetBitrate%d", cfg_RCTargetBitRate, 0, MAX_LAYERS, "Rate control: target bitrate for layer %d")
842  ("KeepHierarchicalBit%d", cfg_RCKeepHierarchicalBit, false, MAX_LAYERS, "Rate control: keep hierarchical bit allocation for layer %d")
843  ("LCULevelRateControl%d", cfg_RCLCULevelRC, true, MAX_LAYERS, "Rate control: LCU level RC")
844  ("RCLCUSeparateModel%d", cfg_RCUseLCUSeparateModel, true, MAX_LAYERS, "Rate control: Use LCU level separate R-lambda model")
845  ("InitialQP%d", cfg_RCInitialQP, 0, MAX_LAYERS, "Rate control: initial QP")
846  ("RCForceIntraQP%d", cfg_RCForceIntraQP, false, MAX_LAYERS, "Rate control: force intra QP to be equal to initial QP")
847#else
848  ( "RateControl",         m_RCEnableRateControl,   false, "Rate control: enable rate control" )
849  ( "TargetBitrate",       m_RCTargetBitrate,           0, "Rate control: target bitrate" )
850  ( "KeepHierarchicalBit", m_RCKeepHierarchicalBit,     0, "Rate control: 0: equal bit allocation; 1: fixed ratio bit allocation; 2: adaptive ratio bit allocation" )
851  ( "LCULevelRateControl", m_RCLCULevelRC,           true, "Rate control: true: LCU level RC; false: picture level RC" )
852  ( "RCLCUSeparateModel",  m_RCUseLCUSeparateModel,  true, "Rate control: use LCU level separate R-lambda model" )
853  ( "InitialQP",           m_RCInitialQP,               0, "Rate control: initial QP" )
854  ( "RCForceIntraQP",      m_RCForceIntraQP,        false, "Rate control: force intra QP to be equal to initial QP" )
855#endif
856
857  ("TransquantBypassEnableFlag", m_TransquantBypassEnableFlag, false, "transquant_bypass_enable_flag indicator in PPS")
858  ("CUTransquantBypassFlagForce", m_CUTransquantBypassFlagForce, false, "Force transquant bypass mode, when transquant_bypass_enable_flag is enabled")
859  ("RecalculateQPAccordingToLambda", m_recalculateQPAccordingToLambda, false, "Recalculate QP values according to lambda values. Do not suggest to be enabled in all intra case")
860  ("StrongIntraSmoothing,-sis",      m_useStrongIntraSmoothing,           true, "Enable strong intra smoothing for 32x32 blocks")
861  ("SEIActiveParameterSets",         m_activeParameterSetsSEIEnabled,          0, "Enable generation of active parameter sets SEI messages")
862  ("VuiParametersPresent,-vui",      m_vuiParametersPresentFlag,           false, "Enable generation of vui_parameters()")
863  ("AspectRatioInfoPresent",         m_aspectRatioInfoPresentFlag,         false, "Signals whether aspect_ratio_idc is present")
864  ("AspectRatioIdc",                 m_aspectRatioIdc,                         0, "aspect_ratio_idc")
865  ("SarWidth",                       m_sarWidth,                               0, "horizontal size of the sample aspect ratio")
866  ("SarHeight",                      m_sarHeight,                              0, "vertical size of the sample aspect ratio")
867  ("OverscanInfoPresent",            m_overscanInfoPresentFlag,            false, "Indicates whether conformant decoded pictures are suitable for display using overscan\n")
868  ("OverscanAppropriate",            m_overscanAppropriateFlag,            false, "Indicates whether conformant decoded pictures are suitable for display using overscan\n")
869  ("VideoSignalTypePresent",         m_videoSignalTypePresentFlag,         false, "Signals whether video_format, video_full_range_flag, and colour_description_present_flag are present")
870  ("VideoFormat",                    m_videoFormat,                            5, "Indicates representation of pictures")
871  ("VideoFullRange",                 m_videoFullRangeFlag,                 false, "Indicates the black level and range of luma and chroma signals")
872  ("ColourDescriptionPresent",       m_colourDescriptionPresentFlag,       false, "Signals whether colour_primaries, transfer_characteristics and matrix_coefficients are present")
873  ("ColourPrimaries",                m_colourPrimaries,                        2, "Indicates chromaticity coordinates of the source primaries")
874  ("TransferCharateristics",         m_transferCharacteristics,                2, "Indicates the opto-electronic transfer characteristics of the source")
875  ("MatrixCoefficients",             m_matrixCoefficients,                     2, "Describes the matrix coefficients used in deriving luma and chroma from RGB primaries")
876  ("ChromaLocInfoPresent",           m_chromaLocInfoPresentFlag,           false, "Signals whether chroma_sample_loc_type_top_field and chroma_sample_loc_type_bottom_field are present")
877  ("ChromaSampleLocTypeTopField",    m_chromaSampleLocTypeTopField,            0, "Specifies the location of chroma samples for top field")
878  ("ChromaSampleLocTypeBottomField", m_chromaSampleLocTypeBottomField,         0, "Specifies the location of chroma samples for bottom field")
879  ("NeutralChromaIndication",        m_neutralChromaIndicationFlag,        false, "Indicates that the value of all decoded chroma samples is equal to 1<<(BitDepthCr-1)")
880  ("DefaultDisplayWindowFlag",       m_defaultDisplayWindowFlag,           false, "Indicates the presence of the Default Window parameters")
881  ("DefDispWinLeftOffset",           m_defDispWinLeftOffset,                   0, "Specifies the left offset of the default display window from the conformance window")
882  ("DefDispWinRightOffset",          m_defDispWinRightOffset,                  0, "Specifies the right offset of the default display window from the conformance window")
883  ("DefDispWinTopOffset",            m_defDispWinTopOffset,                    0, "Specifies the top offset of the default display window from the conformance window")
884  ("DefDispWinBottomOffset",         m_defDispWinBottomOffset,                 0, "Specifies the bottom offset of the default display window from the conformance window")
885  ("FrameFieldInfoPresentFlag",      m_frameFieldInfoPresentFlag,               false, "Indicates that pic_struct and field coding related values are present in picture timing SEI messages")
886  ("PocProportionalToTimingFlag",   m_pocProportionalToTimingFlag,         false, "Indicates that the POC value is proportional to the output time w.r.t. first picture in CVS")
887  ("NumTicksPocDiffOneMinus1",      m_numTicksPocDiffOneMinus1,                0, "Number of ticks minus 1 that for a POC difference of one")
888  ("BitstreamRestriction",           m_bitstreamRestrictionFlag,           false, "Signals whether bitstream restriction parameters are present")
889  ("TilesFixedStructure",            m_tilesFixedStructureFlag,            false, "Indicates that each active picture parameter set has the same values of the syntax elements related to tiles")
890  ("MotionVectorsOverPicBoundaries", m_motionVectorsOverPicBoundariesFlag, false, "Indicates that no samples outside the picture boundaries are used for inter prediction")
891  ("MaxBytesPerPicDenom",            m_maxBytesPerPicDenom,                    2, "Indicates a number of bytes not exceeded by the sum of the sizes of the VCL NAL units associated with any coded picture")
892  ("MaxBitsPerMinCuDenom",           m_maxBitsPerMinCuDenom,                   1, "Indicates an upper bound for the number of bits of coding_unit() data")
893  ("Log2MaxMvLengthHorizontal",      m_log2MaxMvLengthHorizontal,             15, "Indicate the maximum absolute value of a decoded horizontal MV component in quarter-pel luma units")
894  ("Log2MaxMvLengthVertical",        m_log2MaxMvLengthVertical,               15, "Indicate the maximum absolute value of a decoded vertical MV component in quarter-pel luma units")
895  ("SEIRecoveryPoint",               m_recoveryPointSEIEnabled,                0, "Control generation of recovery point SEI messages")
896  ("SEIBufferingPeriod",             m_bufferingPeriodSEIEnabled,              0, "Control generation of buffering period SEI messages")
897  ("SEIPictureTiming",               m_pictureTimingSEIEnabled,                0, "Control generation of picture timing SEI messages")
898  ("SEIToneMappingInfo",                       m_toneMappingInfoSEIEnabled,    false, "Control generation of Tone Mapping SEI messages")
899  ("SEIToneMapId",                             m_toneMapId,                        0, "Specifies Id of Tone Mapping SEI message for a given session")
900  ("SEIToneMapCancelFlag",                     m_toneMapCancelFlag,            false, "Indicates that Tone Mapping SEI message cancels the persistance or follows")
901  ("SEIToneMapPersistenceFlag",                m_toneMapPersistenceFlag,        true, "Specifies the persistence of the Tone Mapping SEI message")
902  ("SEIToneMapCodedDataBitDepth",              m_toneMapCodedDataBitDepth,         8, "Specifies Coded Data BitDepth of Tone Mapping SEI messages")
903  ("SEIToneMapTargetBitDepth",                 m_toneMapTargetBitDepth,            8, "Specifies Output BitDepth of Tome mapping function")
904  ("SEIToneMapModelId",                        m_toneMapModelId,                   0, "Specifies Model utilized for mapping coded data into target_bit_depth range\n"
905                                                                                      "\t0:  linear mapping with clipping\n"
906                                                                                      "\t1:  sigmoidal mapping\n"
907                                                                                      "\t2:  user-defined table mapping\n"
908                                                                                      "\t3:  piece-wise linear mapping\n"
909                                                                                      "\t4:  luminance dynamic range information ")
910  ("SEIToneMapMinValue",                              m_toneMapMinValue,                          0, "Specifies the minimum value in mode 0")
911  ("SEIToneMapMaxValue",                              m_toneMapMaxValue,                       1023, "Specifies the maxmum value in mode 0")
912  ("SEIToneMapSigmoidMidpoint",                       m_sigmoidMidpoint,                        512, "Specifies the centre point in mode 1")
913  ("SEIToneMapSigmoidWidth",                          m_sigmoidWidth,                           960, "Specifies the distance between 5% and 95% values of the target_bit_depth in mode 1")
914  ("SEIToneMapStartOfCodedInterval",                  cfg_startOfCodedInterval,          string(""), "Array of user-defined mapping table")
915  ("SEIToneMapNumPivots",                             m_numPivots,                                0, "Specifies the number of pivot points in mode 3")
916  ("SEIToneMapCodedPivotValue",                       cfg_codedPivotValue,               string(""), "Array of pivot point")
917  ("SEIToneMapTargetPivotValue",                      cfg_targetPivotValue,              string(""), "Array of pivot point")
918  ("SEIToneMapCameraIsoSpeedIdc",                     m_cameraIsoSpeedIdc,                        0, "Indicates the camera ISO speed for daylight illumination")
919  ("SEIToneMapCameraIsoSpeedValue",                   m_cameraIsoSpeedValue,                    400, "Specifies the camera ISO speed for daylight illumination of Extended_ISO")
920  ("SEIToneMapExposureIndexIdc",                      m_exposureIndexIdc,                         0, "Indicates the exposure index setting of the camera")
921  ("SEIToneMapExposureIndexValue",                    m_exposureIndexValue,                     400, "Specifies the exposure index setting of the cameran of Extended_ISO")
922  ("SEIToneMapExposureCompensationValueSignFlag",     m_exposureCompensationValueSignFlag,        0, "Specifies the sign of ExposureCompensationValue")
923  ("SEIToneMapExposureCompensationValueNumerator",    m_exposureCompensationValueNumerator,       0, "Specifies the numerator of ExposureCompensationValue")
924  ("SEIToneMapExposureCompensationValueDenomIdc",     m_exposureCompensationValueDenomIdc,        2, "Specifies the denominator of ExposureCompensationValue")
925  ("SEIToneMapRefScreenLuminanceWhite",               m_refScreenLuminanceWhite,                350, "Specifies reference screen brightness setting in units of candela per square metre")
926  ("SEIToneMapExtendedRangeWhiteLevel",               m_extendedRangeWhiteLevel,                800, "Indicates the luminance dynamic range")
927  ("SEIToneMapNominalBlackLevelLumaCodeValue",        m_nominalBlackLevelLumaCodeValue,          16, "Specifies luma sample value of the nominal black level assigned decoded pictures")
928  ("SEIToneMapNominalWhiteLevelLumaCodeValue",        m_nominalWhiteLevelLumaCodeValue,         235, "Specifies luma sample value of the nominal white level assigned decoded pictures")
929  ("SEIToneMapExtendedWhiteLevelLumaCodeValue",       m_extendedWhiteLevelLumaCodeValue,        300, "Specifies luma sample value of the extended dynamic range assigned decoded pictures")
930  ("SEIFramePacking",                m_framePackingSEIEnabled,                 0, "Control generation of frame packing SEI messages")
931  ("SEIFramePackingType",            m_framePackingSEIType,                    0, "Define frame packing arrangement\n"
932                                                                                  "\t0: checkerboard - pixels alternatively represent either frames\n"
933                                                                                  "\t1: column alternation - frames are interlaced by column\n"
934                                                                                  "\t2: row alternation - frames are interlaced by row\n"
935                                                                                  "\t3: side by side - frames are displayed horizontally\n"
936                                                                                  "\t4: top bottom - frames are displayed vertically\n"
937                                                                                  "\t5: frame alternation - one frame is alternated with the other")
938  ("SEIFramePackingId",              m_framePackingSEIId,                      0, "Id of frame packing SEI message for a given session")
939  ("SEIFramePackingQuincunx",        m_framePackingSEIQuincunx,                0, "Indicate the presence of a Quincunx type video frame")
940  ("SEIFramePackingInterpretation",  m_framePackingSEIInterpretation,          0, "Indicate the interpretation of the frame pair\n"
941                                                                                  "\t0: unspecified\n"
942                                                                                  "\t1: stereo pair, frame0 represents left view\n"
943                                                                                  "\t2: stereo pair, frame0 represents right view")
944  ("SEIDisplayOrientation",          m_displayOrientationSEIAngle,             0, "Control generation of display orientation SEI messages\n"
945                                                              "\tN: 0 < N < (2^16 - 1) enable display orientation SEI message with anticlockwise_rotation = N and display_orientation_repetition_period = 1\n"
946                                                              "\t0: disable")
947  ("SEITemporalLevel0Index",         m_temporalLevel0IndexSEIEnabled,          0, "Control generation of temporal level 0 index SEI messages")
948  ("SEIGradualDecodingRefreshInfo",  m_gradualDecodingRefreshInfoEnabled,      0, "Control generation of gradual decoding refresh information SEI message")
949  ("SEIDecodingUnitInfo",             m_decodingUnitInfoSEIEnabled,                       0, "Control generation of decoding unit information SEI message.")
950#if LAYERS_NOT_PRESENT_SEI
951  ("SEILayersNotPresent",            m_layersNotPresentSEIEnabled,             0, "Control generation of layers not present SEI message")
952#endif
953  ("SEISOPDescription",              m_SOPDescriptionSEIEnabled,              0, "Control generation of SOP description SEI messages")
954  ("SEIScalableNesting",             m_scalableNestingSEIEnabled,              0, "Control generation of scalable nesting SEI messages")
955#if M0040_ADAPTIVE_RESOLUTION_CHANGE
956  ("AdaptiveResolutionChange",     m_adaptiveResolutionChange, 0, "Adaptive resolution change frame number. Should coincide with EL RAP picture. (0: disable)")
957#endif
958#if HIGHER_LAYER_IRAP_SKIP_FLAG
959  ("SkipPictureAtArcSwitch",     m_skipPictureAtArcSwitch, false, "Code the higher layer picture in ARC up-switching as a skip picture. (0: disable)")
960#endif
961#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
962  ("SEIInterLayerConstrainedTileSets", m_interLayerConstrainedTileSetsSEIEnabled, false, "Control generation of inter layer constrained tile sets SEI message")
963  ("IlNumSetsInMessage",               m_ilNumSetsInMessage,                         0u, "Number of inter layer constrained tile sets")
964  ("TileSetsArray",                    cfg_tileSets,                         string(""), "Array containing tile sets params (TopLeftTileIndex, BottonRightTileIndex and ilcIdc for each set) ")
965#endif
966#if O0153_ALT_OUTPUT_LAYER_FLAG
967  ("AltOutputLayerFlag",               m_altOutputLayerFlag,                      false, "Specifies the value of alt_output_layer_flag in VPS extension")
968#endif
969#if O0149_CROSS_LAYER_BLA_FLAG
970  ("CrossLayerBLAFlag",                m_crossLayerBLAFlag,                       false, "Specifies the value of cross_layer_bla_flag in VPS")
971#endif
972#if Q0048_CGS_3D_ASYMLUT
973  ("CGS",     m_nCGSFlag , 0, "whether CGS is enabled")
974  ("CGSMaxOctantDepth", m_nCGSMaxOctantDepth , 1, "max octant depth")
975  ("CGSMaxYPartNumLog",  m_nCGSMaxYPartNumLog2 , 2, "max Y part number ")
976  ("CGSLUTBit",     m_nCGSLUTBit , 12, "bit depth of CGS LUT")
977#endif
978  ;
979 
980  for(Int i=1; i<MAX_GOP+1; i++) {
981    std::ostringstream cOSS;
982    cOSS<<"Frame"<<i;
983    opts.addOptions()(cOSS.str(), m_GOPList[i-1], GOPEntry());
984  }
985  po::setDefaults(opts);
986  const list<const Char*>& argv_unhandled = po::scanArgv(opts, argc, (const Char**) argv);
987
988  if(m_isField)
989  {
990#if SVC_EXTENSION
991    for(Int layer = 0; layer < MAX_LAYERS; layer++)
992    {
993      //Frame height
994      m_acLayerCfg[layer].m_iSourceHeightOrg = m_acLayerCfg[layer].m_iSourceHeight;
995      //Field height
996      m_acLayerCfg[layer].m_iSourceHeight = m_acLayerCfg[layer].m_iSourceHeight >> 1;
997    }
998#else
999    //Frame height
1000    m_iSourceHeightOrg = m_iSourceHeight;
1001    //Field height
1002    m_iSourceHeight = m_iSourceHeight >> 1;
1003#endif
1004    //number of fields to encode
1005    m_framesToBeEncoded *= 2;
1006  }
1007 
1008  for (list<const Char*>::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++)
1009  {
1010    fprintf(stderr, "Unhandled argument ignored: `%s'\n", *it);
1011  }
1012 
1013  if (argc == 1 || do_help)
1014  {
1015    /* argc == 1: no options have been specified */
1016    po::doHelp(cout, opts);
1017    return false;
1018  }
1019 
1020  /*
1021   * Set any derived parameters
1022   */
1023  /* convert std::string to c string for compatability */
1024#if SVC_EXTENSION
1025#if AVC_BASE
1026  if( m_avcBaseLayerFlag )
1027  {
1028    *cfg_InputFile[0] = cfg_BLInputFile;
1029  }
1030#endif
1031  m_pBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str());
1032#if AVC_SYNTAX
1033  m_BLSyntaxFile = cfg_BLSyntaxFile.empty() ? NULL : strdup(cfg_BLSyntaxFile.c_str());
1034#endif
1035#else //SVC_EXTENSION
1036  m_pchInputFile = cfg_InputFile.empty() ? NULL : strdup(cfg_InputFile.c_str());
1037  m_pchBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str());
1038  m_pchReconFile = cfg_ReconFile.empty() ? NULL : strdup(cfg_ReconFile.c_str());
1039  m_pchdQPFile = cfg_dQPFile.empty() ? NULL : strdup(cfg_dQPFile.c_str());
1040#endif //SVC_EXTENSION
1041
1042  Char* pColumnWidth = cfg_ColumnWidth.empty() ? NULL: strdup(cfg_ColumnWidth.c_str());
1043  Char* pRowHeight = cfg_RowHeight.empty() ? NULL : strdup(cfg_RowHeight.c_str());
1044  if( m_iUniformSpacingIdr == 0 && m_iNumColumnsMinus1 > 0 )
1045  {
1046    char *columnWidth;
1047    int  i=0;
1048    m_pColumnWidth = new UInt[m_iNumColumnsMinus1];
1049    columnWidth = strtok(pColumnWidth, " ,-");
1050    while(columnWidth!=NULL)
1051    {
1052      if( i>=m_iNumColumnsMinus1 )
1053      {
1054        printf( "The number of columns whose width are defined is larger than the allowed number of columns.\n" );
1055        exit( EXIT_FAILURE );
1056      }
1057      *( m_pColumnWidth + i ) = atoi( columnWidth );
1058      columnWidth = strtok(NULL, " ,-");
1059      i++;
1060    }
1061    if( i<m_iNumColumnsMinus1 )
1062    {
1063      printf( "The width of some columns is not defined.\n" );
1064      exit( EXIT_FAILURE );
1065    }
1066  }
1067  else
1068  {
1069    m_pColumnWidth = NULL;
1070  }
1071
1072  if( m_iUniformSpacingIdr == 0 && m_iNumRowsMinus1 > 0 )
1073  {
1074    char *rowHeight;
1075    int  i=0;
1076    m_pRowHeight = new UInt[m_iNumRowsMinus1];
1077    rowHeight = strtok(pRowHeight, " ,-");
1078    while(rowHeight!=NULL)
1079    {
1080      if( i>=m_iNumRowsMinus1 )
1081      {
1082        printf( "The number of rows whose height are defined is larger than the allowed number of rows.\n" );
1083        exit( EXIT_FAILURE );
1084      }
1085      *( m_pRowHeight + i ) = atoi( rowHeight );
1086      rowHeight = strtok(NULL, " ,-");
1087      i++;
1088    }
1089    if( i<m_iNumRowsMinus1 )
1090    {
1091      printf( "The height of some rows is not defined.\n" );
1092      exit( EXIT_FAILURE );
1093   }
1094  }
1095  else
1096  {
1097    m_pRowHeight = NULL;
1098  }
1099#if SVC_EXTENSION
1100  for(Int layer = 0; layer < MAX_LAYERS; layer++)
1101  {
1102    // If number of scaled ref. layer offsets is non-zero, at least one of the offsets should be specified
1103    if(m_acLayerCfg[layer].m_numScaledRefLayerOffsets)
1104    {
1105#if O0098_SCALED_REF_LAYER_ID
1106      assert( strcmp(cfg_scaledRefLayerId[layer].c_str(),  ""));
1107#endif
1108#if P0312_VERT_PHASE_ADJ
1109      assert( strcmp(cfg_scaledRefLayerLeftOffset[layer].c_str(),  "") ||
1110              strcmp(cfg_scaledRefLayerRightOffset[layer].c_str(), "") ||
1111              strcmp(cfg_scaledRefLayerTopOffset[layer].c_str(),   "") ||
1112              strcmp(cfg_scaledRefLayerBottomOffset[layer].c_str(),"") ||
1113              strcmp(cfg_vertPhasePositionEnableFlag[layer].c_str(),"") ); 
1114#else
1115      assert( strcmp(cfg_scaledRefLayerLeftOffset[layer].c_str(),  "") ||
1116              strcmp(cfg_scaledRefLayerRightOffset[layer].c_str(), "") ||
1117              strcmp(cfg_scaledRefLayerTopOffset[layer].c_str(),   "") ||
1118              strcmp(cfg_scaledRefLayerBottomOffset[layer].c_str(),"") ); 
1119#endif
1120    }
1121
1122    Int *tempArray = NULL;   // Contain the value
1123
1124#if O0098_SCALED_REF_LAYER_ID
1125    // ID //
1126    if(strcmp(cfg_scaledRefLayerId[layer].c_str(),  ""))
1127    {
1128      cfgStringToArray( &tempArray, cfg_scaledRefLayerId[layer], m_acLayerCfg[layer].m_numScaledRefLayerOffsets, "ScaledRefLayerId");
1129      if(tempArray)
1130      {
1131        for(Int i = 0; i < m_acLayerCfg[layer].m_numScaledRefLayerOffsets; i++)
1132        {
1133          m_acLayerCfg[layer].m_scaledRefLayerId[i] = tempArray[i];
1134        }
1135        delete [] tempArray; tempArray = NULL;
1136      }
1137    }
1138#endif
1139
1140    // Left offset //
1141    if(strcmp(cfg_scaledRefLayerLeftOffset[layer].c_str(),  ""))
1142    {
1143      cfgStringToArray( &tempArray, cfg_scaledRefLayerLeftOffset[layer], m_acLayerCfg[layer].m_numScaledRefLayerOffsets, "LeftOffset");
1144      if(tempArray)
1145      {
1146        for(Int i = 0; i < m_acLayerCfg[layer].m_numScaledRefLayerOffsets; i++)
1147        {
1148          m_acLayerCfg[layer].m_scaledRefLayerLeftOffset[i] = tempArray[i];
1149        }
1150        delete [] tempArray; tempArray = NULL;
1151      }
1152    }
1153
1154    // Top offset //
1155    if(strcmp(cfg_scaledRefLayerTopOffset[layer].c_str(),  ""))
1156    {
1157      cfgStringToArray( &tempArray, cfg_scaledRefLayerTopOffset[layer], m_acLayerCfg[layer].m_numScaledRefLayerOffsets, "TopOffset");
1158      if(tempArray)
1159      {
1160        for(Int i = 0; i < m_acLayerCfg[layer].m_numScaledRefLayerOffsets; i++)
1161        {
1162          m_acLayerCfg[layer].m_scaledRefLayerTopOffset[i] = tempArray[i];
1163        }
1164        delete [] tempArray; tempArray = NULL;
1165      }
1166    }
1167
1168    // Right offset //
1169    if(strcmp(cfg_scaledRefLayerRightOffset[layer].c_str(),  ""))
1170    {
1171      cfgStringToArray( &tempArray, cfg_scaledRefLayerRightOffset[layer], m_acLayerCfg[layer].m_numScaledRefLayerOffsets, "RightOffset");
1172      if(tempArray)
1173      {
1174        for(Int i = 0; i < m_acLayerCfg[layer].m_numScaledRefLayerOffsets; i++)
1175        {
1176          m_acLayerCfg[layer].m_scaledRefLayerRightOffset[i] = tempArray[i];
1177        }
1178        delete [] tempArray; tempArray = NULL;
1179      }
1180    }
1181
1182    // Bottom offset //
1183    if(strcmp(cfg_scaledRefLayerBottomOffset[layer].c_str(),  ""))
1184    {
1185      cfgStringToArray( &tempArray, cfg_scaledRefLayerBottomOffset[layer], m_acLayerCfg[layer].m_numScaledRefLayerOffsets, "BottomOffset");
1186      if(tempArray)
1187      {
1188        for(Int i = 0; i < m_acLayerCfg[layer].m_numScaledRefLayerOffsets; i++)
1189        {
1190          m_acLayerCfg[layer].m_scaledRefLayerBottomOffset[i] = tempArray[i];
1191        }
1192        delete [] tempArray; tempArray = NULL;
1193      }
1194    }
1195#if P0312_VERT_PHASE_ADJ
1196   // VertPhasePositionEnableFlag //
1197    if(strcmp(cfg_vertPhasePositionEnableFlag[layer].c_str(),  ""))
1198    {
1199      cfgStringToArray( &tempArray, cfg_vertPhasePositionEnableFlag[layer], m_acLayerCfg[layer].m_numScaledRefLayerOffsets, "VertPhasePositionEnableFlag");
1200      if(tempArray)
1201      {
1202        for(Int i = 0; i < m_acLayerCfg[layer].m_numScaledRefLayerOffsets; i++)
1203        {
1204          m_acLayerCfg[layer].m_vertPhasePositionEnableFlag[i] = tempArray[i];
1205        }
1206        delete [] tempArray; tempArray = NULL;
1207      }
1208    }
1209#endif
1210  }
1211#if VPS_EXTN_DIRECT_REF_LAYERS
1212  for(Int layer = 0; layer < MAX_LAYERS; layer++)
1213  {
1214    Char* pSamplePredRefLayerIds = cfg_samplePredRefLayerIds[layer].empty() ? NULL: strdup(cfg_samplePredRefLayerIds[layer].c_str());
1215    if( m_acLayerCfg[layer].m_numSamplePredRefLayers > 0 )
1216    {
1217      char *samplePredRefLayerId;
1218      int  i=0;
1219      m_acLayerCfg[layer].m_samplePredRefLayerIds = new Int[m_acLayerCfg[layer].m_numSamplePredRefLayers];
1220      samplePredRefLayerId = strtok(pSamplePredRefLayerIds, " ,-");
1221      while(samplePredRefLayerId != NULL)
1222      {
1223        if( i >= m_acLayerCfg[layer].m_numSamplePredRefLayers )
1224        {
1225          printf( "NumSamplePredRefLayers%d: The number of columns whose width are defined is larger than the allowed number of columns.\n", layer );
1226          exit( EXIT_FAILURE );
1227        }
1228        *( m_acLayerCfg[layer].m_samplePredRefLayerIds + i ) = atoi( samplePredRefLayerId );
1229        samplePredRefLayerId = strtok(NULL, " ,-");
1230        i++;
1231      }
1232      if( i < m_acLayerCfg[layer].m_numSamplePredRefLayers )
1233      {
1234        printf( "NumSamplePredRefLayers%d: The width of some columns is not defined.\n", layer );
1235        exit( EXIT_FAILURE );
1236      }
1237    }
1238    else
1239    {
1240      m_acLayerCfg[layer].m_samplePredRefLayerIds = NULL;
1241    }
1242  }
1243  for(Int layer = 0; layer < MAX_LAYERS; layer++)
1244  {
1245    Char* pMotionPredRefLayerIds = cfg_motionPredRefLayerIds[layer].empty() ? NULL: strdup(cfg_motionPredRefLayerIds[layer].c_str());
1246    if( m_acLayerCfg[layer].m_numMotionPredRefLayers > 0 )
1247    {
1248      char *motionPredRefLayerId;
1249      int  i=0;
1250      m_acLayerCfg[layer].m_motionPredRefLayerIds = new Int[m_acLayerCfg[layer].m_numMotionPredRefLayers];
1251      motionPredRefLayerId = strtok(pMotionPredRefLayerIds, " ,-");
1252      while(motionPredRefLayerId != NULL)
1253      {
1254        if( i >= m_acLayerCfg[layer].m_numMotionPredRefLayers )
1255        {
1256          printf( "NumMotionPredRefLayers%d: The number of columns whose width are defined is larger than the allowed number of columns.\n", layer );
1257          exit( EXIT_FAILURE );
1258        }
1259        *( m_acLayerCfg[layer].m_motionPredRefLayerIds + i ) = atoi( motionPredRefLayerId );
1260        motionPredRefLayerId = strtok(NULL, " ,-");
1261        i++;
1262      }
1263      if( i < m_acLayerCfg[layer].m_numMotionPredRefLayers )
1264      {
1265        printf( "NumMotionPredRefLayers%d: The width of some columns is not defined.\n", layer );
1266        exit( EXIT_FAILURE );
1267      }
1268    }
1269    else
1270    {
1271      m_acLayerCfg[layer].m_motionPredRefLayerIds = NULL;
1272    }
1273  }
1274
1275#if AUXILIARY_PICTURES
1276  for(UInt layer = 0; layer < MAX_LAYERS; layer++)
1277  {
1278    m_acLayerCfg[layer].m_InputChromaFormat =  numberToChromaFormat(cfg_tmpChromaFormatIDC[layer]);
1279    m_acLayerCfg[layer].m_chromaFormatIDC = ((cfg_tmpChromaFormatIDC[layer] == 0) ? (m_acLayerCfg[layer].m_InputChromaFormat ) : (numberToChromaFormat(cfg_tmpChromaFormatIDC[layer])));
1280  }
1281#endif
1282  for(Int layer = 0; layer < MAX_LAYERS; layer++)
1283  {
1284    Char* pPredLayerIds = cfg_predLayerIds[layer].empty() ? NULL: strdup(cfg_predLayerIds[layer].c_str());
1285    if( m_acLayerCfg[layer].m_numActiveRefLayers > 0 )
1286    {
1287      char *refLayerId;
1288      int  i=0;
1289      m_acLayerCfg[layer].m_predLayerIds = new Int[m_acLayerCfg[layer].m_numActiveRefLayers];
1290      refLayerId = strtok(pPredLayerIds, " ,-");
1291      while(refLayerId != NULL)
1292      {
1293        if( i >= m_acLayerCfg[layer].m_numActiveRefLayers )
1294        {
1295          printf( "NumActiveRefLayers%d: The number of columns whose width are defined is larger than the allowed number of columns.\n", layer );
1296          exit( EXIT_FAILURE );
1297        }
1298        *( m_acLayerCfg[layer].m_predLayerIds + i ) = atoi( refLayerId );
1299        refLayerId = strtok(NULL, " ,-");
1300        i++;
1301      }
1302      if( i < m_acLayerCfg[layer].m_numActiveRefLayers )
1303      {
1304        printf( "NumActiveRefLayers%d: The width of some columns is not defined.\n", layer );
1305        exit( EXIT_FAILURE );
1306      }
1307    }
1308    else
1309    {
1310      m_acLayerCfg[layer].m_predLayerIds = NULL;
1311    }
1312  }
1313#endif
1314#endif //SVC_EXTENSION
1315  m_scalingListFile = cfg_ScalingListFile.empty() ? NULL : strdup(cfg_ScalingListFile.c_str());
1316
1317  /* rules for input, output and internal bitdepths as per help text */
1318#if O0194_DIFFERENT_BITDEPTH_EL_BL
1319  for(Int layer = 0; layer < MAX_LAYERS; layer++)
1320  {
1321    if (!m_acLayerCfg[layer].m_internalBitDepthY) { m_acLayerCfg[layer].m_internalBitDepthY = m_acLayerCfg[layer].m_inputBitDepthY; }
1322    if (!m_acLayerCfg[layer].m_internalBitDepthC) { m_acLayerCfg[layer].m_internalBitDepthC = m_acLayerCfg[layer].m_internalBitDepthY; }
1323    if (!m_acLayerCfg[layer].m_inputBitDepthC) { m_acLayerCfg[layer].m_inputBitDepthC = m_acLayerCfg[layer].m_inputBitDepthY; }
1324    if (!m_acLayerCfg[layer].m_outputBitDepthY) { m_acLayerCfg[layer].m_outputBitDepthY = m_acLayerCfg[layer].m_internalBitDepthY; }
1325    if (!m_acLayerCfg[layer].m_outputBitDepthC) { m_acLayerCfg[layer].m_outputBitDepthC = m_acLayerCfg[layer].m_internalBitDepthC; }
1326  }
1327#else
1328  if (!m_internalBitDepthY) { m_internalBitDepthY = m_inputBitDepthY; }
1329  if (!m_internalBitDepthC) { m_internalBitDepthC = m_internalBitDepthY; }
1330  if (!m_inputBitDepthC) { m_inputBitDepthC = m_inputBitDepthY; }
1331  if (!m_outputBitDepthY) { m_outputBitDepthY = m_internalBitDepthY; }
1332  if (!m_outputBitDepthC) { m_outputBitDepthC = m_internalBitDepthC; }
1333#endif
1334
1335#if !SVC_EXTENSION
1336  // TODO:ChromaFmt assumes 4:2:0 below
1337  switch (m_conformanceMode)
1338  {
1339  case 0:
1340    {
1341      // no conformance or padding
1342      m_confLeft = m_confRight = m_confTop = m_confBottom = 0;
1343      m_aiPad[1] = m_aiPad[0] = 0;
1344      break;
1345    }
1346  case 1:
1347    {
1348      // automatic padding to minimum CU size
1349      Int minCuSize = m_uiMaxCUHeight >> (m_uiMaxCUDepth - 1);
1350      if (m_iSourceWidth % minCuSize)
1351      {
1352        m_aiPad[0] = m_confRight  = ((m_iSourceWidth / minCuSize) + 1) * minCuSize - m_iSourceWidth;
1353        m_iSourceWidth  += m_confRight;
1354      }
1355      if (m_iSourceHeight % minCuSize)
1356      {
1357        m_aiPad[1] = m_confBottom = ((m_iSourceHeight / minCuSize) + 1) * minCuSize - m_iSourceHeight;
1358        m_iSourceHeight += m_confBottom;
1359        if ( m_isField )
1360        {
1361          m_iSourceHeightOrg += m_confBottom << 1;
1362          m_aiPad[1] = m_confBottom << 1;
1363        }
1364      }
1365      if (m_aiPad[0] % TComSPS::getWinUnitX(CHROMA_420) != 0)
1366      {
1367        fprintf(stderr, "Error: picture width is not an integer multiple of the specified chroma subsampling\n");
1368        exit(EXIT_FAILURE);
1369      }
1370      if (m_aiPad[1] % TComSPS::getWinUnitY(CHROMA_420) != 0)
1371      {
1372        fprintf(stderr, "Error: picture height is not an integer multiple of the specified chroma subsampling\n");
1373        exit(EXIT_FAILURE);
1374      }
1375      break;
1376    }
1377  case 2:
1378    {
1379      //padding
1380      m_iSourceWidth  += m_aiPad[0];
1381      m_iSourceHeight += m_aiPad[1];
1382      m_confRight  = m_aiPad[0];
1383      m_confBottom = m_aiPad[1];
1384      break;
1385    }
1386  case 3:
1387    {
1388      // conformance
1389      if ((m_confLeft == 0) && (m_confRight == 0) && (m_confTop == 0) && (m_confBottom == 0))
1390      {
1391        fprintf(stderr, "Warning: Conformance window enabled, but all conformance window parameters set to zero\n");
1392      }
1393      if ((m_aiPad[1] != 0) || (m_aiPad[0]!=0))
1394      {
1395        fprintf(stderr, "Warning: Conformance window enabled, padding parameters will be ignored\n");
1396      }
1397      m_aiPad[1] = m_aiPad[0] = 0;
1398      break;
1399    }
1400  }
1401 
1402  // allocate slice-based dQP values
1403  m_aidQP = new Int[ m_framesToBeEncoded + m_iGOPSize + 1 ];
1404  ::memset( m_aidQP, 0, sizeof(Int)*( m_framesToBeEncoded + m_iGOPSize + 1 ) );
1405 
1406  // handling of floating-point QP values
1407  // if QP is not integer, sequence is split into two sections having QP and QP+1
1408  m_iQP = (Int)( m_fQP );
1409  if ( m_iQP < m_fQP )
1410  {
1411    Int iSwitchPOC = (Int)( m_framesToBeEncoded - (m_fQP - m_iQP)*m_framesToBeEncoded + 0.5 );
1412   
1413    iSwitchPOC = (Int)( (Double)iSwitchPOC / m_iGOPSize + 0.5 )*m_iGOPSize;
1414    for ( Int i=iSwitchPOC; i<m_framesToBeEncoded + m_iGOPSize + 1; i++ )
1415    {
1416      m_aidQP[i] = 1;
1417    }
1418  }
1419 
1420  // reading external dQP description from file
1421  if ( m_pchdQPFile )
1422  {
1423    FILE* fpt=fopen( m_pchdQPFile, "r" );
1424    if ( fpt )
1425    {
1426      Int iValue;
1427      Int iPOC = 0;
1428      while ( iPOC < m_framesToBeEncoded )
1429      {
1430        if ( fscanf(fpt, "%d", &iValue ) == EOF ) break;
1431        m_aidQP[ iPOC ] = iValue;
1432        iPOC++;
1433      }
1434      fclose(fpt);
1435    }
1436  }
1437  m_iWaveFrontSubstreams = m_iWaveFrontSynchro ? (m_iSourceHeight + m_uiMaxCUHeight - 1) / m_uiMaxCUHeight : 1;
1438#endif
1439  if( m_toneMappingInfoSEIEnabled && !m_toneMapCancelFlag )
1440  {
1441    Char* pcStartOfCodedInterval = cfg_startOfCodedInterval.empty() ? NULL: strdup(cfg_startOfCodedInterval.c_str());
1442    Char* pcCodedPivotValue = cfg_codedPivotValue.empty() ? NULL: strdup(cfg_codedPivotValue.c_str());
1443    Char* pcTargetPivotValue = cfg_targetPivotValue.empty() ? NULL: strdup(cfg_targetPivotValue.c_str());
1444    if( m_toneMapModelId == 2 && pcStartOfCodedInterval )
1445    {
1446      char *startOfCodedInterval;
1447      UInt num = 1u<< m_toneMapTargetBitDepth;
1448      m_startOfCodedInterval = new Int[num];
1449      ::memset( m_startOfCodedInterval, 0, sizeof(Int)*num );
1450      startOfCodedInterval = strtok(pcStartOfCodedInterval, " .");
1451      int i = 0;
1452      while( startOfCodedInterval && ( i < num ) )
1453      {
1454        m_startOfCodedInterval[i] = atoi( startOfCodedInterval );
1455        startOfCodedInterval = strtok(NULL, " .");
1456        i++;
1457      }
1458    } 
1459    else
1460    {
1461      m_startOfCodedInterval = NULL;
1462    }
1463    if( ( m_toneMapModelId == 3 ) && ( m_numPivots > 0 ) )
1464    {
1465      if( pcCodedPivotValue && pcTargetPivotValue )
1466      {
1467        char *codedPivotValue;
1468        char *targetPivotValue;
1469        m_codedPivotValue = new Int[m_numPivots];
1470        m_targetPivotValue = new Int[m_numPivots];
1471        ::memset( m_codedPivotValue, 0, sizeof(Int)*( m_numPivots ) );
1472        ::memset( m_targetPivotValue, 0, sizeof(Int)*( m_numPivots ) );
1473        codedPivotValue = strtok(pcCodedPivotValue, " .");
1474        int i=0;
1475        while(codedPivotValue&&i<m_numPivots)
1476        {
1477          m_codedPivotValue[i] = atoi( codedPivotValue );
1478          codedPivotValue = strtok(NULL, " .");
1479          i++;
1480        }
1481        i=0;
1482        targetPivotValue = strtok(pcTargetPivotValue, " .");
1483        while(targetPivotValue&&i<m_numPivots)
1484        {
1485          m_targetPivotValue[i]= atoi( targetPivotValue );
1486          targetPivotValue = strtok(NULL, " .");
1487          i++;
1488        }
1489      }
1490    }
1491    else
1492    {
1493      m_codedPivotValue = NULL;
1494      m_targetPivotValue = NULL;
1495    }
1496  }
1497
1498#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
1499  if (m_interLayerConstrainedTileSetsSEIEnabled)
1500  {
1501    if (m_iNumColumnsMinus1 == 0 && m_iNumRowsMinus1 == 0)
1502    {
1503      printf( "Tiles are not defined (needed for inter-layer comnstrained tile sets SEI).\n" );
1504      exit( EXIT_FAILURE );
1505    }
1506    Char* pTileSets = cfg_tileSets.empty() ? NULL : strdup(cfg_tileSets.c_str());
1507    int i = 0;
1508    char *topLeftTileIndex = strtok(pTileSets, " ,");
1509    while(topLeftTileIndex != NULL)
1510    {
1511      if( i >= m_ilNumSetsInMessage )
1512      {
1513        printf( "The number of tile sets is larger than defined by IlNumSetsInMessage.\n" );
1514        exit( EXIT_FAILURE );
1515      }
1516      *( m_topLeftTileIndex + i ) = atoi( topLeftTileIndex );
1517      char *bottonRightTileIndex = strtok(NULL, " ,");
1518      if( bottonRightTileIndex == NULL )
1519      {
1520        printf( "BottonRightTileIndex is missing in the tile sets.\n" );
1521        exit( EXIT_FAILURE );
1522      }
1523      *( m_bottomRightTileIndex + i ) = atoi( bottonRightTileIndex );
1524      char *ilcIdc = strtok(NULL, " ,");
1525      if( ilcIdc == NULL )
1526      {
1527        printf( "IlcIdc is missing in the tile sets.\n" );
1528        exit( EXIT_FAILURE );
1529      }
1530      *( m_ilcIdc + i ) = atoi( ilcIdc );
1531      topLeftTileIndex = strtok(NULL, " ,");
1532      i++;
1533    }
1534    if( i < m_ilNumSetsInMessage )
1535    {
1536      printf( "The number of tile sets is smaller than defined by IlNumSetsInMessage.\n" );
1537      exit( EXIT_FAILURE );
1538    }
1539    m_skippedTileSetPresentFlag = false;
1540  }
1541#endif
1542  // check validity of input parameters
1543  xCheckParameter();
1544 
1545  // set global varibles
1546#if LAYER_CTB
1547  for(Int layer = 0; layer < MAX_LAYERS; layer++)
1548  {
1549    xSetGlobal(layer);
1550  }
1551#else
1552  xSetGlobal();
1553#endif
1554 
1555  // print-out parameters
1556  xPrintParameter();
1557 
1558  return true;
1559}
1560// ====================================================================================================================
1561// Private member functions
1562// ====================================================================================================================
1563
1564Bool confirmPara(Bool bflag, const Char* message);
1565
1566Void TAppEncCfg::xCheckParameter()
1567{
1568  if (!m_decodedPictureHashSEIEnabled)
1569  {
1570    fprintf(stderr, "******************************************************************\n");
1571    fprintf(stderr, "** WARNING: --SEIDecodedPictureHash is now disabled by default. **\n");
1572    fprintf(stderr, "**          Automatic verification of decoded pictures by a     **\n");
1573    fprintf(stderr, "**          decoder requires this option to be enabled.         **\n");
1574    fprintf(stderr, "******************************************************************\n");
1575  }
1576  if( m_profile==Profile::NONE )
1577  {
1578    fprintf(stderr, "***************************************************************************\n");
1579    fprintf(stderr, "** WARNING: For conforming bitstreams a valid Profile value must be set! **\n");
1580    fprintf(stderr, "***************************************************************************\n");
1581  }
1582  if( m_level==Level::NONE )
1583  {
1584    fprintf(stderr, "***************************************************************************\n");
1585    fprintf(stderr, "** WARNING: For conforming bitstreams a valid Level value must be set!   **\n");
1586    fprintf(stderr, "***************************************************************************\n");
1587  }
1588
1589  Bool check_failed = false; /* abort if there is a fatal configuration problem */
1590#define xConfirmPara(a,b) check_failed |= confirmPara(a,b)
1591  // check range of parameters
1592#if O0194_DIFFERENT_BITDEPTH_EL_BL
1593  for(UInt layer=0; layer<m_numLayers; layer++)
1594  {
1595    xConfirmPara( m_acLayerCfg[layer].m_inputBitDepthY < 8,                                                     "InputBitDepth must be at least 8" );
1596    xConfirmPara( m_acLayerCfg[layer].m_inputBitDepthC < 8,                                                     "InputBitDepthC must be at least 8" );
1597  }
1598#else
1599  xConfirmPara( m_inputBitDepthY < 8,                                                     "InputBitDepth must be at least 8" );
1600  xConfirmPara( m_inputBitDepthC < 8,                                                     "InputBitDepthC must be at least 8" );
1601#endif
1602#if !SVC_EXTENSION 
1603  xConfirmPara( m_iFrameRate <= 0,                                                          "Frame rate must be more than 1" );
1604#endif
1605  xConfirmPara( m_framesToBeEncoded <= 0,                                                   "Total Number Of Frames encoded must be more than 0" );
1606  xConfirmPara( m_iGOPSize < 1 ,                                                            "GOP Size must be greater or equal to 1" );
1607  xConfirmPara( m_iGOPSize > 1 &&  m_iGOPSize % 2,                                          "GOP Size must be a multiple of 2, if GOP Size is greater than 1" );
1608#if !SVC_EXTENSION
1609  xConfirmPara( (m_iIntraPeriod > 0 && m_iIntraPeriod < m_iGOPSize) || m_iIntraPeriod == 0, "Intra period must be more than GOP size, or -1 , not 0" );
1610#endif
1611#if ALLOW_RECOVERY_POINT_AS_RAP
1612  xConfirmPara( m_iDecodingRefreshType < 0 || m_iDecodingRefreshType > 3,                   "Decoding Refresh Type must be comprised between 0 and 3 included" );
1613  if(m_iDecodingRefreshType == 3)
1614  {
1615    xConfirmPara( !m_recoveryPointSEIEnabled,                                               "When using RecoveryPointSEI messages as RA points, recoveryPointSEI must be enabled" );
1616  }
1617#else
1618  xConfirmPara( m_iDecodingRefreshType < 0 || m_iDecodingRefreshType > 2,                   "Decoding Refresh Type must be equal to 0, 1 or 2" );
1619#endif
1620#if !SVC_EXTENSION
1621  xConfirmPara( m_iQP <  -6 * (m_internalBitDepthY - 8) || m_iQP > 51,                    "QP exceeds supported range (-QpBDOffsety to 51)" );
1622#endif
1623  xConfirmPara( m_loopFilterBetaOffsetDiv2 < -6 || m_loopFilterBetaOffsetDiv2 > 6,          "Loop Filter Beta Offset div. 2 exceeds supported range (-6 to 6)");
1624  xConfirmPara( m_loopFilterTcOffsetDiv2 < -6 || m_loopFilterTcOffsetDiv2 > 6,              "Loop Filter Tc Offset div. 2 exceeds supported range (-6 to 6)");
1625  xConfirmPara( m_iFastSearch < 0 || m_iFastSearch > 2,                                     "Fast Search Mode is not supported value (0:Full search  1:Diamond  2:PMVFAST)" );
1626  xConfirmPara( m_iSearchRange < 0 ,                                                        "Search Range must be more than 0" );
1627  xConfirmPara( m_bipredSearchRange < 0 ,                                                   "Search Range must be more than 0" );
1628  xConfirmPara( m_iMaxDeltaQP > 7,                                                          "Absolute Delta QP exceeds supported range (0 to 7)" );
1629#if LAYER_CTB
1630  for(UInt layer = 0; layer < MAX_LAYERS; layer++)
1631  {
1632    xConfirmPara( m_iMaxCuDQPDepth > m_acLayerCfg[layer].m_uiMaxCUDepth - 1,                "Absolute depth for a minimum CuDQP exceeds maximum coding unit depth" );
1633  }
1634#else
1635  xConfirmPara( m_iMaxCuDQPDepth > m_uiMaxCUDepth - 1,                                          "Absolute depth for a minimum CuDQP exceeds maximum coding unit depth" );
1636#endif
1637
1638  xConfirmPara( m_cbQpOffset < -12,   "Min. Chroma Cb QP Offset is -12" );
1639  xConfirmPara( m_cbQpOffset >  12,   "Max. Chroma Cb QP Offset is  12" );
1640  xConfirmPara( m_crQpOffset < -12,   "Min. Chroma Cr QP Offset is -12" );
1641  xConfirmPara( m_crQpOffset >  12,   "Max. Chroma Cr QP Offset is  12" );
1642
1643  xConfirmPara( m_iQPAdaptationRange <= 0,                                                  "QP Adaptation Range must be more than 0" );
1644#if !SVC_EXTENSION
1645  if (m_iDecodingRefreshType == 2)
1646  {
1647    xConfirmPara( m_iIntraPeriod > 0 && m_iIntraPeriod <= m_iGOPSize ,                      "Intra period must be larger than GOP size for periodic IDR pictures");
1648  }
1649#endif
1650#if !LAYER_CTB
1651  xConfirmPara( (m_uiMaxCUWidth  >> m_uiMaxCUDepth) < 4,                                    "Minimum partition width size should be larger than or equal to 8");
1652  xConfirmPara( (m_uiMaxCUHeight >> m_uiMaxCUDepth) < 4,                                    "Minimum partition height size should be larger than or equal to 8");
1653  xConfirmPara( m_uiMaxCUWidth < 16,                                                        "Maximum partition width size should be larger than or equal to 16");
1654  xConfirmPara( m_uiMaxCUHeight < 16,                                                       "Maximum partition height size should be larger than or equal to 16");
1655#endif
1656#if !SVC_EXTENSION
1657  xConfirmPara( (m_iSourceWidth  % (m_uiMaxCUWidth  >> (m_uiMaxCUDepth-1)))!=0,             "Resulting coded frame width must be a multiple of the minimum CU size");
1658  xConfirmPara( (m_iSourceHeight % (m_uiMaxCUHeight >> (m_uiMaxCUDepth-1)))!=0,             "Resulting coded frame height must be a multiple of the minimum CU size");
1659#endif
1660 
1661#if !LAYER_CTB
1662  xConfirmPara( m_uiQuadtreeTULog2MinSize < 2,                                        "QuadtreeTULog2MinSize must be 2 or greater.");
1663  xConfirmPara( m_uiQuadtreeTULog2MaxSize > 5,                                        "QuadtreeTULog2MaxSize must be 5 or smaller.");
1664  xConfirmPara( (1<<m_uiQuadtreeTULog2MaxSize) > m_uiMaxCUWidth,                                        "QuadtreeTULog2MaxSize must be log2(maxCUSize) or smaller.");
1665 
1666  xConfirmPara( m_uiQuadtreeTULog2MaxSize < m_uiQuadtreeTULog2MinSize,                "QuadtreeTULog2MaxSize must be greater than or equal to m_uiQuadtreeTULog2MinSize.");
1667  xConfirmPara( (1<<m_uiQuadtreeTULog2MinSize)>(m_uiMaxCUWidth >>(m_uiMaxCUDepth-1)), "QuadtreeTULog2MinSize must not be greater than minimum CU size" ); // HS
1668  xConfirmPara( (1<<m_uiQuadtreeTULog2MinSize)>(m_uiMaxCUHeight>>(m_uiMaxCUDepth-1)), "QuadtreeTULog2MinSize must not be greater than minimum CU size" ); // HS
1669  xConfirmPara( ( 1 << m_uiQuadtreeTULog2MinSize ) > ( m_uiMaxCUWidth  >> m_uiMaxCUDepth ), "Minimum CU width must be greater than minimum transform size." );
1670  xConfirmPara( ( 1 << m_uiQuadtreeTULog2MinSize ) > ( m_uiMaxCUHeight >> m_uiMaxCUDepth ), "Minimum CU height must be greater than minimum transform size." );
1671  xConfirmPara( m_uiQuadtreeTUMaxDepthInter < 1,                                                         "QuadtreeTUMaxDepthInter must be greater than or equal to 1" );
1672  xConfirmPara( m_uiMaxCUWidth < ( 1 << (m_uiQuadtreeTULog2MinSize + m_uiQuadtreeTUMaxDepthInter - 1) ), "QuadtreeTUMaxDepthInter must be less than or equal to the difference between log2(maxCUSize) and QuadtreeTULog2MinSize plus 1" );
1673  xConfirmPara( m_uiQuadtreeTUMaxDepthIntra < 1,                                                         "QuadtreeTUMaxDepthIntra must be greater than or equal to 1" );
1674  xConfirmPara( m_uiMaxCUWidth < ( 1 << (m_uiQuadtreeTULog2MinSize + m_uiQuadtreeTUMaxDepthIntra - 1) ), "QuadtreeTUMaxDepthInter must be less than or equal to the difference between log2(maxCUSize) and QuadtreeTULog2MinSize plus 1" );
1675#endif
1676 
1677  xConfirmPara(  m_maxNumMergeCand < 1,  "MaxNumMergeCand must be 1 or greater.");
1678  xConfirmPara(  m_maxNumMergeCand > 5,  "MaxNumMergeCand must be 5 or smaller.");
1679
1680#if !SVC_EXTENSION
1681#if ADAPTIVE_QP_SELECTION
1682  xConfirmPara( m_bUseAdaptQpSelect == true && m_iQP < 0,                                              "AdaptiveQpSelection must be disabled when QP < 0.");
1683  xConfirmPara( m_bUseAdaptQpSelect == true && (m_cbQpOffset !=0 || m_crQpOffset != 0 ),               "AdaptiveQpSelection must be disabled when ChromaQpOffset is not equal to 0.");
1684#endif
1685#endif
1686
1687  if( m_usePCM)
1688  {
1689    xConfirmPara(  m_uiPCMLog2MinSize < 3,                                      "PCMLog2MinSize must be 3 or greater.");
1690    xConfirmPara(  m_uiPCMLog2MinSize > 5,                                      "PCMLog2MinSize must be 5 or smaller.");
1691    xConfirmPara(  m_pcmLog2MaxSize > 5,                                        "PCMLog2MaxSize must be 5 or smaller.");
1692    xConfirmPara(  m_pcmLog2MaxSize < m_uiPCMLog2MinSize,                       "PCMLog2MaxSize must be equal to or greater than m_uiPCMLog2MinSize.");
1693  }
1694
1695  xConfirmPara( m_sliceMode < 0 || m_sliceMode > 3, "SliceMode exceeds supported range (0 to 3)" );
1696  if (m_sliceMode!=0)
1697  {
1698    xConfirmPara( m_sliceArgument < 1 ,         "SliceArgument should be larger than or equal to 1" );
1699  }
1700  xConfirmPara( m_sliceSegmentMode < 0 || m_sliceSegmentMode > 3, "SliceSegmentMode exceeds supported range (0 to 3)" );
1701  if (m_sliceSegmentMode!=0)
1702  {
1703    xConfirmPara( m_sliceSegmentArgument < 1 ,         "SliceSegmentArgument should be larger than or equal to 1" );
1704  }
1705 
1706  Bool tileFlag = (m_iNumColumnsMinus1 > 0 || m_iNumRowsMinus1 > 0 );
1707  xConfirmPara( tileFlag && m_iWaveFrontSynchro,            "Tile and Wavefront can not be applied together");
1708
1709  //TODO:ChromaFmt assumes 4:2:0 below
1710#if !SVC_EXTENSION
1711  xConfirmPara( m_iSourceWidth  % TComSPS::getWinUnitX(CHROMA_420) != 0, "Picture width must be an integer multiple of the specified chroma subsampling");
1712  xConfirmPara( m_iSourceHeight % TComSPS::getWinUnitY(CHROMA_420) != 0, "Picture height must be an integer multiple of the specified chroma subsampling");
1713
1714  xConfirmPara( m_aiPad[0] % TComSPS::getWinUnitX(CHROMA_420) != 0, "Horizontal padding must be an integer multiple of the specified chroma subsampling");
1715  xConfirmPara( m_aiPad[1] % TComSPS::getWinUnitY(CHROMA_420) != 0, "Vertical padding must be an integer multiple of the specified chroma subsampling");
1716
1717  xConfirmPara( m_confLeft   % TComSPS::getWinUnitX(CHROMA_420) != 0, "Left conformance window offset must be an integer multiple of the specified chroma subsampling");
1718  xConfirmPara( m_confRight  % TComSPS::getWinUnitX(CHROMA_420) != 0, "Right conformance window offset must be an integer multiple of the specified chroma subsampling");
1719  xConfirmPara( m_confTop    % TComSPS::getWinUnitY(CHROMA_420) != 0, "Top conformance window offset must be an integer multiple of the specified chroma subsampling");
1720  xConfirmPara( m_confBottom % TComSPS::getWinUnitY(CHROMA_420) != 0, "Bottom conformance window offset must be an integer multiple of the specified chroma subsampling");
1721#endif
1722
1723#if !LAYER_CTB
1724  // max CU width and height should be power of 2
1725  UInt ui = m_uiMaxCUWidth;
1726  while(ui)
1727  {
1728    ui >>= 1;
1729    if( (ui & 1) == 1)
1730      xConfirmPara( ui != 1 , "Width should be 2^n");
1731  }
1732  ui = m_uiMaxCUHeight;
1733  while(ui)
1734  {
1735    ui >>= 1;
1736    if( (ui & 1) == 1)
1737      xConfirmPara( ui != 1 , "Height should be 2^n");
1738  }
1739#endif
1740
1741  /* if this is an intra-only sequence, ie IntraPeriod=1, don't verify the GOP structure
1742   * This permits the ability to omit a GOP structure specification */
1743#if SVC_EXTENSION
1744  for(UInt layer = 0; layer < MAX_LAYERS; layer++)
1745  {
1746    Int m_iIntraPeriod = m_acLayerCfg[layer].m_iIntraPeriod;
1747#endif
1748  if (m_iIntraPeriod == 1 && m_GOPList[0].m_POC == -1) {
1749    m_GOPList[0] = GOPEntry();
1750    m_GOPList[0].m_QPFactor = 1;
1751    m_GOPList[0].m_betaOffsetDiv2 = 0;
1752    m_GOPList[0].m_tcOffsetDiv2 = 0;
1753    m_GOPList[0].m_POC = 1;
1754    m_GOPList[0].m_numRefPicsActive = 4;
1755  }
1756#if SVC_EXTENSION
1757  }
1758#endif
1759 
1760
1761  Bool verifiedGOP=false;
1762  Bool errorGOP=false;
1763  Int checkGOP=1;
1764  Int numRefs = m_isField ? 2 : 1;
1765  Int refList[MAX_NUM_REF_PICS+1];
1766  refList[0]=0;
1767  if(m_isField)
1768  {
1769    refList[1] = 1;
1770  }
1771  Bool isOK[MAX_GOP];
1772  for(Int i=0; i<MAX_GOP; i++) 
1773  {
1774    isOK[i]=false;
1775  }
1776  Int numOK=0;
1777#if !SVC_EXTENSION
1778  xConfirmPara( m_iIntraPeriod >=0&&(m_iIntraPeriod%m_iGOPSize!=0), "Intra period must be a multiple of GOPSize, or -1" );
1779#endif
1780
1781  for(Int i=0; i<m_iGOPSize; i++)
1782  {
1783    if(m_GOPList[i].m_POC==m_iGOPSize)
1784    {
1785      xConfirmPara( m_GOPList[i].m_temporalId!=0 , "The last frame in each GOP must have temporal ID = 0 " );
1786    }
1787  }
1788
1789#if SVC_EXTENSION
1790  xConfirmPara( m_numLayers > MAX_LAYERS , "Number of layers in config file is greater than MAX_LAYERS" );
1791  m_numLayers = m_numLayers > MAX_LAYERS ? MAX_LAYERS : m_numLayers;
1792
1793 
1794  // it can be updated after AVC BL support will be added to the WD
1795  if( m_avcBaseLayerFlag )
1796  {
1797    m_crossLayerIrapAlignFlag = false;
1798    m_crossLayerPictureTypeAlignFlag = false;
1799    m_crossLayerAlignedIdrOnlyFlag = false;
1800  }
1801
1802  // verify layer configuration parameters
1803  for(UInt layer=0; layer<m_numLayers; layer++)
1804  {
1805    if(m_acLayerCfg[layer].xCheckParameter(m_isField))
1806    {
1807      printf("\nError: invalid configuration parameter found in layer %d \n", layer);
1808      check_failed = true;
1809    }
1810  }
1811
1812  // verify layer configuration parameters
1813  for(UInt layer=0; layer<m_numLayers; layer++)
1814  {
1815    Int m_iIntraPeriod = m_acLayerCfg[layer].m_iIntraPeriod;
1816#endif
1817  if ( (m_iIntraPeriod != 1) && !m_loopFilterOffsetInPPS && m_DeblockingFilterControlPresent && (!m_bLoopFilterDisable) )
1818  {
1819    for(Int i=0; i<m_iGOPSize; i++)
1820    {
1821      xConfirmPara( (m_GOPList[i].m_betaOffsetDiv2 + m_loopFilterBetaOffsetDiv2) < -6 || (m_GOPList[i].m_betaOffsetDiv2 + m_loopFilterBetaOffsetDiv2) > 6, "Loop Filter Beta Offset div. 2 for one of the GOP entries exceeds supported range (-6 to 6)" );
1822      xConfirmPara( (m_GOPList[i].m_tcOffsetDiv2 + m_loopFilterTcOffsetDiv2) < -6 || (m_GOPList[i].m_tcOffsetDiv2 + m_loopFilterTcOffsetDiv2) > 6, "Loop Filter Tc Offset div. 2 for one of the GOP entries exceeds supported range (-6 to 6)" );
1823    }
1824  }
1825#if SVC_EXTENSION
1826  }
1827#endif
1828
1829  m_extraRPSs=0;
1830  //start looping through frames in coding order until we can verify that the GOP structure is correct.
1831  while(!verifiedGOP&&!errorGOP) 
1832  {
1833    Int curGOP = (checkGOP-1)%m_iGOPSize;
1834    Int curPOC = ((checkGOP-1)/m_iGOPSize)*m_iGOPSize + m_GOPList[curGOP].m_POC;   
1835    if(m_GOPList[curGOP].m_POC<0) 
1836    {
1837      printf("\nError: found fewer Reference Picture Sets than GOPSize\n");
1838      errorGOP=true;
1839    }
1840    else 
1841    {
1842      //check that all reference pictures are available, or have a POC < 0 meaning they might be available in the next GOP.
1843      Bool beforeI = false;
1844      for(Int i = 0; i< m_GOPList[curGOP].m_numRefPics; i++) 
1845      {
1846        Int absPOC = curPOC+m_GOPList[curGOP].m_referencePics[i];
1847        if(absPOC < 0)
1848        {
1849          beforeI=true;
1850        }
1851        else 
1852        {
1853          Bool found=false;
1854          for(Int j=0; j<numRefs; j++) 
1855          {
1856            if(refList[j]==absPOC) 
1857            {
1858              found=true;
1859              for(Int k=0; k<m_iGOPSize; k++)
1860              {
1861                if(absPOC%m_iGOPSize == m_GOPList[k].m_POC%m_iGOPSize)
1862                {
1863                  if(m_GOPList[k].m_temporalId==m_GOPList[curGOP].m_temporalId)
1864                  {
1865                    m_GOPList[k].m_refPic = true;
1866                  }
1867                  m_GOPList[curGOP].m_usedByCurrPic[i]=m_GOPList[k].m_temporalId<=m_GOPList[curGOP].m_temporalId;
1868                }
1869              }
1870            }
1871          }
1872          if(!found)
1873          {
1874            printf("\nError: ref pic %d is not available for GOP frame %d\n",m_GOPList[curGOP].m_referencePics[i],curGOP+1);
1875            errorGOP=true;
1876          }
1877        }
1878      }
1879      if(!beforeI&&!errorGOP)
1880      {
1881        //all ref frames were present
1882        if(!isOK[curGOP]) 
1883        {
1884          numOK++;
1885          isOK[curGOP]=true;
1886          if(numOK==m_iGOPSize)
1887          {
1888            verifiedGOP=true;
1889          }
1890        }
1891      }
1892      else 
1893      {
1894        //create a new GOPEntry for this frame containing all the reference pictures that were available (POC > 0)
1895        m_GOPList[m_iGOPSize+m_extraRPSs]=m_GOPList[curGOP];
1896        Int newRefs=0;
1897        for(Int i = 0; i< m_GOPList[curGOP].m_numRefPics; i++) 
1898        {
1899          Int absPOC = curPOC+m_GOPList[curGOP].m_referencePics[i];
1900          if(absPOC>=0)
1901          {
1902            m_GOPList[m_iGOPSize+m_extraRPSs].m_referencePics[newRefs]=m_GOPList[curGOP].m_referencePics[i];
1903            m_GOPList[m_iGOPSize+m_extraRPSs].m_usedByCurrPic[newRefs]=m_GOPList[curGOP].m_usedByCurrPic[i];
1904            newRefs++;
1905          }
1906        }
1907        Int numPrefRefs = m_GOPList[curGOP].m_numRefPicsActive;
1908       
1909        for(Int offset = -1; offset>-checkGOP; offset--)
1910        {
1911          //step backwards in coding order and include any extra available pictures we might find useful to replace the ones with POC < 0.
1912          Int offGOP = (checkGOP-1+offset)%m_iGOPSize;
1913          Int offPOC = ((checkGOP-1+offset)/m_iGOPSize)*m_iGOPSize + m_GOPList[offGOP].m_POC;
1914          if(offPOC>=0&&m_GOPList[offGOP].m_temporalId<=m_GOPList[curGOP].m_temporalId)
1915          {
1916            Bool newRef=false;
1917            for(Int i=0; i<numRefs; i++)
1918            {
1919              if(refList[i]==offPOC)
1920              {
1921                newRef=true;
1922              }
1923            }
1924            for(Int i=0; i<newRefs; i++) 
1925            {
1926              if(m_GOPList[m_iGOPSize+m_extraRPSs].m_referencePics[i]==offPOC-curPOC)
1927              {
1928                newRef=false;
1929              }
1930            }
1931            if(newRef) 
1932            {
1933              Int insertPoint=newRefs;
1934              //this picture can be added, find appropriate place in list and insert it.
1935              if(m_GOPList[offGOP].m_temporalId==m_GOPList[curGOP].m_temporalId)
1936              {
1937                m_GOPList[offGOP].m_refPic = true;
1938              }
1939              for(Int j=0; j<newRefs; j++)
1940              {
1941                if(m_GOPList[m_iGOPSize+m_extraRPSs].m_referencePics[j]<offPOC-curPOC||m_GOPList[m_iGOPSize+m_extraRPSs].m_referencePics[j]>0)
1942                {
1943                  insertPoint = j;
1944                  break;
1945                }
1946              }
1947              Int prev = offPOC-curPOC;
1948              Int prevUsed = m_GOPList[offGOP].m_temporalId<=m_GOPList[curGOP].m_temporalId;
1949              for(Int j=insertPoint; j<newRefs+1; j++)
1950              {
1951                Int newPrev = m_GOPList[m_iGOPSize+m_extraRPSs].m_referencePics[j];
1952                Int newUsed = m_GOPList[m_iGOPSize+m_extraRPSs].m_usedByCurrPic[j];
1953                m_GOPList[m_iGOPSize+m_extraRPSs].m_referencePics[j]=prev;
1954                m_GOPList[m_iGOPSize+m_extraRPSs].m_usedByCurrPic[j]=prevUsed;
1955                prevUsed=newUsed;
1956                prev=newPrev;
1957              }
1958              newRefs++;
1959            }
1960          }
1961          if(newRefs>=numPrefRefs)
1962          {
1963            break;
1964          }
1965        }
1966        m_GOPList[m_iGOPSize+m_extraRPSs].m_numRefPics=newRefs;
1967        m_GOPList[m_iGOPSize+m_extraRPSs].m_POC = curPOC;
1968        if (m_extraRPSs == 0)
1969        {
1970          m_GOPList[m_iGOPSize+m_extraRPSs].m_interRPSPrediction = 0;
1971          m_GOPList[m_iGOPSize+m_extraRPSs].m_numRefIdc = 0;
1972        }
1973        else
1974        {
1975          Int rIdx =  m_iGOPSize + m_extraRPSs - 1;
1976          Int refPOC = m_GOPList[rIdx].m_POC;
1977          Int refPics = m_GOPList[rIdx].m_numRefPics;
1978          Int newIdc=0;
1979          for(Int i = 0; i<= refPics; i++) 
1980          {
1981            Int deltaPOC = ((i != refPics)? m_GOPList[rIdx].m_referencePics[i] : 0);  // check if the reference abs POC is >= 0
1982            Int absPOCref = refPOC+deltaPOC;
1983            Int refIdc = 0;
1984            for (Int j = 0; j < m_GOPList[m_iGOPSize+m_extraRPSs].m_numRefPics; j++)
1985            {
1986              if ( (absPOCref - curPOC) == m_GOPList[m_iGOPSize+m_extraRPSs].m_referencePics[j])
1987              {
1988                if (m_GOPList[m_iGOPSize+m_extraRPSs].m_usedByCurrPic[j])
1989                {
1990                  refIdc = 1;
1991                }
1992                else
1993                {
1994                  refIdc = 2;
1995                }
1996              }
1997            }
1998            m_GOPList[m_iGOPSize+m_extraRPSs].m_refIdc[newIdc]=refIdc;
1999            newIdc++;
2000          }
2001          m_GOPList[m_iGOPSize+m_extraRPSs].m_interRPSPrediction = 1; 
2002          m_GOPList[m_iGOPSize+m_extraRPSs].m_numRefIdc = newIdc;
2003          m_GOPList[m_iGOPSize+m_extraRPSs].m_deltaRPS = refPOC - m_GOPList[m_iGOPSize+m_extraRPSs].m_POC; 
2004        }
2005        curGOP=m_iGOPSize+m_extraRPSs;
2006        m_extraRPSs++;
2007      }
2008      numRefs=0;
2009      for(Int i = 0; i< m_GOPList[curGOP].m_numRefPics; i++) 
2010      {
2011        Int absPOC = curPOC+m_GOPList[curGOP].m_referencePics[i];
2012        if(absPOC >= 0) 
2013        {
2014          refList[numRefs]=absPOC;
2015          numRefs++;
2016        }
2017      }
2018      refList[numRefs]=curPOC;
2019      numRefs++;
2020    }
2021    checkGOP++;
2022  }
2023  xConfirmPara(errorGOP,"Invalid GOP structure given");
2024  m_maxTempLayer = 1;
2025  for(Int i=0; i<m_iGOPSize; i++) 
2026  {
2027    if(m_GOPList[i].m_temporalId >= m_maxTempLayer)
2028    {
2029      m_maxTempLayer = m_GOPList[i].m_temporalId+1;
2030    }
2031    xConfirmPara(m_GOPList[i].m_sliceType!='B'&&m_GOPList[i].m_sliceType!='P'&&m_GOPList[i].m_sliceType!='I', "Slice type must be equal to B or P or I");
2032  }
2033  for(Int i=0; i<MAX_TLAYER; i++)
2034  {
2035    m_numReorderPics[i] = 0;
2036    m_maxDecPicBuffering[i] = 1;
2037  }
2038  for(Int i=0; i<m_iGOPSize; i++) 
2039  {
2040    if(m_GOPList[i].m_numRefPics+1 > m_maxDecPicBuffering[m_GOPList[i].m_temporalId])
2041    {
2042      m_maxDecPicBuffering[m_GOPList[i].m_temporalId] = m_GOPList[i].m_numRefPics + 1;
2043    }
2044    Int highestDecodingNumberWithLowerPOC = 0; 
2045    for(Int j=0; j<m_iGOPSize; j++)
2046    {
2047      if(m_GOPList[j].m_POC <= m_GOPList[i].m_POC)
2048      {
2049        highestDecodingNumberWithLowerPOC = j;
2050      }
2051    }
2052    Int numReorder = 0;
2053    for(Int j=0; j<highestDecodingNumberWithLowerPOC; j++)
2054    {
2055      if(m_GOPList[j].m_temporalId <= m_GOPList[i].m_temporalId && 
2056        m_GOPList[j].m_POC > m_GOPList[i].m_POC)
2057      {
2058        numReorder++;
2059      }
2060    }   
2061    if(numReorder > m_numReorderPics[m_GOPList[i].m_temporalId])
2062    {
2063      m_numReorderPics[m_GOPList[i].m_temporalId] = numReorder;
2064    }
2065  }
2066  for(Int i=0; i<MAX_TLAYER-1; i++) 
2067  {
2068    // a lower layer can not have higher value of m_numReorderPics than a higher layer
2069    if(m_numReorderPics[i+1] < m_numReorderPics[i])
2070    {
2071      m_numReorderPics[i+1] = m_numReorderPics[i];
2072    }
2073    // the value of num_reorder_pics[ i ] shall be in the range of 0 to max_dec_pic_buffering[ i ] - 1, inclusive
2074    if(m_numReorderPics[i] > m_maxDecPicBuffering[i] - 1)
2075    {
2076      m_maxDecPicBuffering[i] = m_numReorderPics[i] + 1;
2077    }
2078    // a lower layer can not have higher value of m_uiMaxDecPicBuffering than a higher layer
2079    if(m_maxDecPicBuffering[i+1] < m_maxDecPicBuffering[i])
2080    {
2081      m_maxDecPicBuffering[i+1] = m_maxDecPicBuffering[i];
2082    }
2083  }
2084
2085
2086  // the value of num_reorder_pics[ i ] shall be in the range of 0 to max_dec_pic_buffering[ i ] -  1, inclusive
2087  if(m_numReorderPics[MAX_TLAYER-1] > m_maxDecPicBuffering[MAX_TLAYER-1] - 1)
2088  {
2089    m_maxDecPicBuffering[MAX_TLAYER-1] = m_numReorderPics[MAX_TLAYER-1] + 1;
2090  }
2091
2092#if SVC_EXTENSION // ToDo: it should be checked for the case when parameters are different for the layers
2093  for(UInt layer = 0; layer < MAX_LAYERS; layer++)
2094  {
2095    Int m_iSourceWidth = m_acLayerCfg[layer].m_iSourceWidth;
2096    Int m_iSourceHeight = m_acLayerCfg[layer].m_iSourceHeight;
2097#if LAYER_CTB
2098    Int m_uiMaxCUWidth = m_acLayerCfg[layer].m_uiMaxCUWidth;
2099    Int m_uiMaxCUHeight = m_acLayerCfg[layer].m_uiMaxCUHeight;
2100#endif
2101#endif
2102  if(m_vuiParametersPresentFlag && m_bitstreamRestrictionFlag)
2103  { 
2104    Int PicSizeInSamplesY =  m_iSourceWidth * m_iSourceHeight;
2105    if(tileFlag)
2106    {
2107      Int maxTileWidth = 0;
2108      Int maxTileHeight = 0;
2109      Int widthInCU = (m_iSourceWidth % m_uiMaxCUWidth) ? m_iSourceWidth/m_uiMaxCUWidth + 1: m_iSourceWidth/m_uiMaxCUWidth;
2110      Int heightInCU = (m_iSourceHeight % m_uiMaxCUHeight) ? m_iSourceHeight/m_uiMaxCUHeight + 1: m_iSourceHeight/m_uiMaxCUHeight;
2111      if(m_iUniformSpacingIdr)
2112      {
2113        maxTileWidth = m_uiMaxCUWidth*((widthInCU+m_iNumColumnsMinus1)/(m_iNumColumnsMinus1+1));
2114        maxTileHeight = m_uiMaxCUHeight*((heightInCU+m_iNumRowsMinus1)/(m_iNumRowsMinus1+1));
2115        // if only the last tile-row is one treeblock higher than the others
2116        // the maxTileHeight becomes smaller if the last row of treeblocks has lower height than the others
2117        if(!((heightInCU-1)%(m_iNumRowsMinus1+1)))
2118        {
2119          maxTileHeight = maxTileHeight - m_uiMaxCUHeight + (m_iSourceHeight % m_uiMaxCUHeight);
2120        }     
2121        // if only the last tile-column is one treeblock wider than the others
2122        // the maxTileWidth becomes smaller if the last column of treeblocks has lower width than the others   
2123        if(!((widthInCU-1)%(m_iNumColumnsMinus1+1)))
2124        {
2125          maxTileWidth = maxTileWidth - m_uiMaxCUWidth + (m_iSourceWidth % m_uiMaxCUWidth);
2126        }
2127      }
2128      else // not uniform spacing
2129      {
2130        if(m_iNumColumnsMinus1<1)
2131        {
2132          maxTileWidth = m_iSourceWidth;
2133        }
2134        else
2135        {
2136          Int accColumnWidth = 0;
2137          for(Int col=0; col<(m_iNumColumnsMinus1); col++)
2138          {
2139            maxTileWidth = m_pColumnWidth[col]>maxTileWidth ? m_pColumnWidth[col]:maxTileWidth;
2140            accColumnWidth += m_pColumnWidth[col];
2141          }
2142          maxTileWidth = (widthInCU-accColumnWidth)>maxTileWidth ? m_uiMaxCUWidth*(widthInCU-accColumnWidth):m_uiMaxCUWidth*maxTileWidth;
2143        }
2144        if(m_iNumRowsMinus1<1)
2145        {
2146          maxTileHeight = m_iSourceHeight;
2147        }
2148        else
2149        {
2150          Int accRowHeight = 0;
2151          for(Int row=0; row<(m_iNumRowsMinus1); row++)
2152          {
2153            maxTileHeight = m_pRowHeight[row]>maxTileHeight ? m_pRowHeight[row]:maxTileHeight;
2154            accRowHeight += m_pRowHeight[row];
2155          }
2156          maxTileHeight = (heightInCU-accRowHeight)>maxTileHeight ? m_uiMaxCUHeight*(heightInCU-accRowHeight):m_uiMaxCUHeight*maxTileHeight;
2157        }
2158      }
2159      Int maxSizeInSamplesY = maxTileWidth*maxTileHeight;
2160      m_minSpatialSegmentationIdc = 4*PicSizeInSamplesY/maxSizeInSamplesY-4;
2161    }
2162    else if(m_iWaveFrontSynchro)
2163    {
2164      m_minSpatialSegmentationIdc = 4*PicSizeInSamplesY/((2*m_iSourceHeight+m_iSourceWidth)*m_uiMaxCUHeight)-4;
2165    }
2166    else if(m_sliceMode == 1)
2167    {
2168      m_minSpatialSegmentationIdc = 4*PicSizeInSamplesY/(m_sliceArgument*m_uiMaxCUWidth*m_uiMaxCUHeight)-4;
2169    }
2170    else
2171    {
2172      m_minSpatialSegmentationIdc = 0;
2173    }
2174  }
2175#if SVC_EXTENSION
2176  }
2177#endif
2178  xConfirmPara( m_iWaveFrontSynchro < 0, "WaveFrontSynchro cannot be negative" );
2179#if !SVC_EXTENSION
2180  xConfirmPara( m_iWaveFrontSubstreams <= 0, "WaveFrontSubstreams must be positive" );
2181  xConfirmPara( m_iWaveFrontSubstreams > 1 && !m_iWaveFrontSynchro, "Must have WaveFrontSynchro > 0 in order to have WaveFrontSubstreams > 1" );
2182#endif
2183
2184  xConfirmPara( m_decodedPictureHashSEIEnabled<0 || m_decodedPictureHashSEIEnabled>3, "this hash type is not correct!\n");
2185
2186  if (m_toneMappingInfoSEIEnabled)
2187  {
2188    xConfirmPara( m_toneMapCodedDataBitDepth < 8 || m_toneMapCodedDataBitDepth > 14 , "SEIToneMapCodedDataBitDepth must be in rage 8 to 14");
2189    xConfirmPara( m_toneMapTargetBitDepth < 1 || (m_toneMapTargetBitDepth > 16 && m_toneMapTargetBitDepth < 255) , "SEIToneMapTargetBitDepth must be in rage 1 to 16 or equal to 255");
2190    xConfirmPara( m_toneMapModelId < 0 || m_toneMapModelId > 4 , "SEIToneMapModelId must be in rage 0 to 4");
2191    xConfirmPara( m_cameraIsoSpeedValue == 0, "SEIToneMapCameraIsoSpeedValue shall not be equal to 0");
2192    xConfirmPara( m_exposureIndexValue  == 0, "SEIToneMapExposureIndexValue shall not be equal to 0");
2193    xConfirmPara( m_extendedRangeWhiteLevel < 100, "SEIToneMapExtendedRangeWhiteLevel should be greater than or equal to 100");
2194    xConfirmPara( m_nominalBlackLevelLumaCodeValue >= m_nominalWhiteLevelLumaCodeValue, "SEIToneMapNominalWhiteLevelLumaCodeValue shall be greater than SEIToneMapNominalBlackLevelLumaCodeValue");
2195    xConfirmPara( m_extendedWhiteLevelLumaCodeValue < m_nominalWhiteLevelLumaCodeValue, "SEIToneMapExtendedWhiteLevelLumaCodeValue shall be greater than or equal to SEIToneMapNominalWhiteLevelLumaCodeValue");
2196  }
2197
2198#if RC_SHVC_HARMONIZATION
2199  for ( Int layer=0; layer<m_numLayers; layer++ )
2200  {
2201    if ( m_acLayerCfg[layer].m_RCEnableRateControl )
2202    {
2203      if ( m_acLayerCfg[layer].m_RCForceIntraQP )
2204      {
2205        if ( m_acLayerCfg[layer].m_RCInitialQP == 0 )
2206        {
2207          printf( "\nInitial QP for rate control is not specified. Reset not to use force intra QP!" );
2208          m_acLayerCfg[layer].m_RCForceIntraQP = false;
2209        }
2210      }
2211    }
2212    xConfirmPara( m_uiDeltaQpRD > 0, "Rate control cannot be used together with slice level multiple-QP optimization!\n" );
2213  }
2214#else
2215  if ( m_RCEnableRateControl )
2216  {
2217    if ( m_RCForceIntraQP )
2218    {
2219      if ( m_RCInitialQP == 0 )
2220      {
2221        printf( "\nInitial QP for rate control is not specified. Reset not to use force intra QP!" );
2222        m_RCForceIntraQP = false;
2223      }
2224    }
2225    xConfirmPara( m_uiDeltaQpRD > 0, "Rate control cannot be used together with slice level multiple-QP optimization!\n" );
2226  }
2227#endif
2228
2229  xConfirmPara(!m_TransquantBypassEnableFlag && m_CUTransquantBypassFlagForce, "CUTransquantBypassFlagForce cannot be 1 when TransquantBypassEnableFlag is 0");
2230
2231  xConfirmPara(m_log2ParallelMergeLevel < 2, "Log2ParallelMergeLevel should be larger than or equal to 2");
2232  if (m_framePackingSEIEnabled)
2233  {
2234    xConfirmPara(m_framePackingSEIType < 3 || m_framePackingSEIType > 5 , "SEIFramePackingType must be in rage 3 to 5");
2235  }
2236#if VPS_EXTN_DIRECT_REF_LAYERS
2237  xConfirmPara( (m_acLayerCfg[0].m_numSamplePredRefLayers != 0) && (m_acLayerCfg[0].m_numSamplePredRefLayers != -1), "Layer 0 cannot have any reference layers" );
2238  // NOTE: m_numSamplePredRefLayers  (for any layer) could be -1 (not signalled in cfg), in which case only the "previous layer" would be taken for reference
2239  for(Int layer = 1; layer < MAX_LAYERS; layer++)
2240  {
2241    xConfirmPara(m_acLayerCfg[layer].m_numSamplePredRefLayers > layer, "Cannot reference more layers than before current layer");
2242    for(Int i = 0; i < m_acLayerCfg[layer].m_numSamplePredRefLayers; i++)
2243    {
2244      xConfirmPara(m_acLayerCfg[layer].m_samplePredRefLayerIds[i] > layer, "Cannot reference higher layers");
2245      xConfirmPara(m_acLayerCfg[layer].m_samplePredRefLayerIds[i] == layer, "Cannot reference the current layer itself");
2246    }
2247  }
2248  xConfirmPara( (m_acLayerCfg[0].m_numMotionPredRefLayers != 0) && (m_acLayerCfg[0].m_numMotionPredRefLayers != -1), "Layer 0 cannot have any reference layers" );
2249  // NOTE: m_numMotionPredRefLayers  (for any layer) could be -1 (not signalled in cfg), in which case only the "previous layer" would be taken for reference
2250  for(Int layer = 1; layer < MAX_LAYERS; layer++)
2251  {
2252    xConfirmPara(m_acLayerCfg[layer].m_numMotionPredRefLayers > layer, "Cannot reference more layers than before current layer");
2253    for(Int i = 0; i < m_acLayerCfg[layer].m_numMotionPredRefLayers; i++)
2254    {
2255      xConfirmPara(m_acLayerCfg[layer].m_motionPredRefLayerIds[i] > layer, "Cannot reference higher layers");
2256      xConfirmPara(m_acLayerCfg[layer].m_motionPredRefLayerIds[i] == layer, "Cannot reference the current layer itself");
2257    }
2258  }
2259
2260  xConfirmPara( (m_acLayerCfg[0].m_numActiveRefLayers != 0) && (m_acLayerCfg[0].m_numActiveRefLayers != -1), "Layer 0 cannot have any active reference layers" );
2261  // NOTE: m_numActiveRefLayers  (for any layer) could be -1 (not signalled in cfg), in which case only the "previous layer" would be taken for reference
2262  for(Int layer = 1; layer < MAX_LAYERS; layer++)
2263  {
2264    Bool predEnabledFlag[MAX_LAYERS];
2265    for (Int refLayer = 0; refLayer < layer; refLayer++)
2266    {
2267      predEnabledFlag[refLayer] = false;
2268    }
2269    for(Int i = 0; i < m_acLayerCfg[layer].m_numSamplePredRefLayers; i++)
2270    {
2271      predEnabledFlag[m_acLayerCfg[layer].m_samplePredRefLayerIds[i]] = true;
2272    }
2273    for(Int i = 0; i < m_acLayerCfg[layer].m_numMotionPredRefLayers; i++)
2274    {
2275      predEnabledFlag[m_acLayerCfg[layer].m_motionPredRefLayerIds[i]] = true;
2276    }
2277    Int numDirectRefLayers = 0;
2278    for (Int refLayer = 0; refLayer < layer; refLayer++)
2279    {
2280      if (predEnabledFlag[refLayer] == true) numDirectRefLayers++;
2281    }
2282    xConfirmPara(m_acLayerCfg[layer].m_numActiveRefLayers > numDirectRefLayers, "Cannot reference more layers than NumDirectRefLayers");
2283    for(Int i = 0; i < m_acLayerCfg[layer].m_numActiveRefLayers; i++)
2284    {
2285      xConfirmPara(m_acLayerCfg[layer].m_predLayerIds[i] >= numDirectRefLayers, "Cannot reference higher layers");
2286    }
2287  }
2288#endif //VPS_EXTN_DIRECT_REF_LAYERS
2289#if M0040_ADAPTIVE_RESOLUTION_CHANGE
2290  if (m_adaptiveResolutionChange > 0)
2291  {
2292    xConfirmPara(m_numLayers != 2, "Adaptive resolution change works with 2 layers only");
2293    xConfirmPara(m_acLayerCfg[1].m_iIntraPeriod == 0 || (m_adaptiveResolutionChange % m_acLayerCfg[1].m_iIntraPeriod) != 0, "Adaptive resolution change must happen at enhancement layer RAP picture");
2294  }
2295#endif
2296#if HIGHER_LAYER_IRAP_SKIP_FLAG
2297  if (m_adaptiveResolutionChange > 0)
2298  {
2299    xConfirmPara(m_crossLayerIrapAlignFlag != 0, "Cross layer IRAP alignment must be disabled when using adaptive resolution change.");
2300  }
2301  if (m_skipPictureAtArcSwitch)
2302  {
2303    xConfirmPara(m_adaptiveResolutionChange <= 0, "Skip picture at ARC switching only works when Adaptive Resolution Change is active (AdaptiveResolutionChange > 0)");
2304  }
2305#endif
2306#if N0120_MAX_TID_REF_CFG
2307  for (UInt layer=0; layer < MAX_LAYERS-1; layer++)
2308  {
2309    xConfirmPara(m_acLayerCfg[layer].m_maxTidIlRefPicsPlus1 < 0 || m_acLayerCfg[layer].m_maxTidIlRefPicsPlus1 > 7, "MaxTidIlRefPicsPlus1 must be in range 0 to 7");
2310  }
2311#endif
2312#if AUXILIARY_PICTURES
2313  for (UInt layer=0; layer < MAX_LAYERS-1; layer++)
2314  {
2315    xConfirmPara(m_acLayerCfg[layer].m_auxId < 0 || m_acLayerCfg[layer].m_auxId > 4, "AuxId must be in range 0 to 4");
2316    xConfirmPara(m_acLayerCfg[layer].m_auxId > 0 && m_acLayerCfg[layer].m_chromaFormatIDC != CHROMA_400, "Auxiliary picture must be monochrome picture");
2317  }
2318#endif
2319#if Q0048_CGS_3D_ASYMLUT
2320  xConfirmPara( m_nCGSFlag < 0 || m_nCGSFlag > 1 , "0<=CGS<=1" );
2321#endif
2322#undef xConfirmPara
2323  if (check_failed)
2324  {
2325    exit(EXIT_FAILURE);
2326  }
2327}
2328
2329/** \todo use of global variables should be removed later
2330 */
2331#if LAYER_CTB
2332Void TAppEncCfg::xSetGlobal(UInt layerId)
2333{
2334  // set max CU width & height
2335  g_auiLayerMaxCUWidth[layerId]  = m_acLayerCfg[layerId].m_uiMaxCUWidth;
2336  g_auiLayerMaxCUHeight[layerId] = m_acLayerCfg[layerId].m_uiMaxCUHeight;
2337 
2338  // compute actual CU depth with respect to config depth and max transform size
2339  g_auiLayerAddCUDepth[layerId]  = 0;
2340  while( (m_acLayerCfg[layerId].m_uiMaxCUWidth>>m_acLayerCfg[layerId].m_uiMaxCUDepth) > ( 1 << ( m_acLayerCfg[layerId].m_uiQuadtreeTULog2MinSize + g_auiLayerAddCUDepth[layerId] )  ) ) g_auiLayerAddCUDepth[layerId]++;
2341 
2342  m_acLayerCfg[layerId].m_uiMaxCUDepth += g_auiLayerAddCUDepth[layerId];
2343  g_auiLayerAddCUDepth[layerId]++;
2344  g_auiLayerMaxCUDepth[layerId] = m_acLayerCfg[layerId].m_uiMaxCUDepth;
2345 
2346#if O0194_DIFFERENT_BITDEPTH_EL_BL
2347  // set internal bit-depth to constant value to make sure to be updated later
2348  g_bitDepthY = -1;
2349  g_bitDepthC = -1;
2350 
2351  g_uiPCMBitDepthLuma = -1;
2352  g_uiPCMBitDepthChroma = -1;
2353#else
2354  // set internal bit-depth and constants
2355  g_bitDepthY = m_internalBitDepthY;
2356  g_bitDepthC = m_internalBitDepthC;
2357 
2358  g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_inputBitDepthY : m_internalBitDepthY;
2359  g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_inputBitDepthC : m_internalBitDepthC;
2360#endif
2361}
2362#else
2363Void TAppEncCfg::xSetGlobal()
2364{
2365  // set max CU width & height
2366  g_uiMaxCUWidth  = m_uiMaxCUWidth;
2367  g_uiMaxCUHeight = m_uiMaxCUHeight;
2368 
2369  // compute actual CU depth with respect to config depth and max transform size
2370  g_uiAddCUDepth  = 0;
2371  while( (m_uiMaxCUWidth>>m_uiMaxCUDepth) > ( 1 << ( m_uiQuadtreeTULog2MinSize + g_uiAddCUDepth )  ) ) g_uiAddCUDepth++;
2372 
2373  m_uiMaxCUDepth += g_uiAddCUDepth;
2374  g_uiAddCUDepth++;
2375  g_uiMaxCUDepth = m_uiMaxCUDepth;
2376 
2377#if O0194_DIFFERENT_BITDEPTH_EL_BL
2378  // set internal bit-depth to constant value to make sure to be updated later
2379  g_bitDepthY = -1;
2380  g_bitDepthC = -1;
2381 
2382  g_uiPCMBitDepthLuma = -1;
2383  g_uiPCMBitDepthChroma = -1;
2384#else
2385  g_bitDepthY = m_internalBitDepthY;
2386  g_bitDepthC = m_internalBitDepthC;
2387 
2388  g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_inputBitDepthY : m_internalBitDepthY;
2389  g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_inputBitDepthC : m_internalBitDepthC;
2390#endif
2391}
2392#endif
2393
2394Void TAppEncCfg::xPrintParameter()
2395{
2396  printf("\n");
2397#if SVC_EXTENSION 
2398  printf("Total number of layers        : %d\n", m_numLayers       );
2399#if SCALABILITY_MASK_E0104
2400  printf("Multiview                     : %d\n", m_scalabilityMask[1] );
2401  printf("Scalable                      : %d\n", m_scalabilityMask[2] );
2402#if AVC_BASE
2403  printf("Base layer                    : %s\n", m_avcBaseLayerFlag ? "AVC" : "HEVC");
2404#endif
2405#if AUXILIARY_PICTURES
2406  printf("Auxiliary pictures            : %d\n", m_scalabilityMask[3] );
2407#endif
2408#else
2409  printf("Multiview                     : %d\n", m_scalabilityMask[0] );
2410  printf("Scalable                      : %d\n", m_scalabilityMask[1] );
2411#endif
2412#if M0040_ADAPTIVE_RESOLUTION_CHANGE
2413  printf("Adaptive Resolution Change    : %d\n", m_adaptiveResolutionChange );
2414#endif
2415#if HIGHER_LAYER_IRAP_SKIP_FLAG
2416  printf("Skip picture at ARC switch    : %d\n", m_skipPictureAtArcSwitch );
2417#endif
2418#if O0223_PICTURE_TYPES_ALIGN_FLAG
2419  printf("Align picture type            : %d\n", m_crossLayerPictureTypeAlignFlag );
2420#endif
2421#if N0147_IRAP_ALIGN_FLAG
2422  printf("Cross layer IRAP alignment    : %d\n", m_crossLayerIrapAlignFlag );
2423#endif
2424#if P0068_CROSS_LAYER_ALIGNED_IDR_ONLY_FOR_IRAP_FLAG
2425  printf("IDR only for IRAP             : %d\n", m_crossLayerAlignedIdrOnlyFlag );
2426#endif
2427#if O0194_WEIGHTED_PREDICTION_CGS
2428  printf("InterLayerWeightedPred        : %d\n", m_useInterLayerWeightedPred );
2429#endif
2430  for(UInt layer=0; layer<m_numLayers; layer++)
2431  {
2432    printf("=== Layer %d settings === \n", layer);
2433#if AVC_SYNTAX
2434    m_acLayerCfg[layer].xPrintParameter( layer );
2435#else
2436    m_acLayerCfg[layer].xPrintParameter();
2437#endif
2438    printf("\n");
2439  }
2440  printf("=== Common configuration settings === \n");
2441  printf("Bitstream      File          : %s\n", m_pBitstreamFile      );
2442#else
2443  printf("Input          File          : %s\n", m_pchInputFile          );
2444  printf("Bitstream      File          : %s\n", m_pchBitstreamFile      );
2445  printf("Reconstruction File          : %s\n", m_pchReconFile          );
2446  printf("Real     Format              : %dx%d %dHz\n", m_iSourceWidth - m_confLeft - m_confRight, m_iSourceHeight - m_confTop - m_confBottom, m_iFrameRate );
2447  printf("Internal Format              : %dx%d %dHz\n", m_iSourceWidth, m_iSourceHeight, m_iFrameRate );
2448#endif
2449  if (m_isField)
2450  {
2451    printf("Frame/Field          : Field based coding\n");
2452    printf("Field index          : %u - %d (%d fields)\n", m_FrameSkip, m_FrameSkip+m_framesToBeEncoded-1, m_framesToBeEncoded );
2453    if (m_isTopFieldFirst)
2454    {
2455      printf("Field Order            : Top field first\n");
2456    }
2457    else
2458    {
2459      printf("Field Order            : Bottom field first\n");
2460    }
2461  }
2462  else
2463  {
2464    printf("Frame/Field                  : Frame based coding\n");
2465    printf("Frame index                  : %u - %d (%d frames)\n", m_FrameSkip, m_FrameSkip+m_framesToBeEncoded-1, m_framesToBeEncoded );
2466  }
2467#if !LAYER_CTB
2468  printf("CU size / depth              : %d / %d\n", m_uiMaxCUWidth, m_uiMaxCUDepth );
2469  printf("RQT trans. size (min / max)  : %d / %d\n", 1 << m_uiQuadtreeTULog2MinSize, 1 << m_uiQuadtreeTULog2MaxSize );
2470  printf("Max RQT depth inter          : %d\n", m_uiQuadtreeTUMaxDepthInter);
2471  printf("Max RQT depth intra          : %d\n", m_uiQuadtreeTUMaxDepthIntra);
2472#endif
2473  printf("Min PCM size                 : %d\n", 1 << m_uiPCMLog2MinSize);
2474  printf("Motion search range          : %d\n", m_iSearchRange );
2475#if !SVC_EXTENSION
2476  printf("Intra period                 : %d\n", m_iIntraPeriod );
2477#endif
2478  printf("Decoding refresh type        : %d\n", m_iDecodingRefreshType );
2479#if !SVC_EXTENSION
2480  printf("QP                           : %5.2f\n", m_fQP );
2481#endif
2482  printf("Max dQP signaling depth      : %d\n", m_iMaxCuDQPDepth);
2483
2484  printf("Cb QP Offset                 : %d\n", m_cbQpOffset   );
2485  printf("Cr QP Offset                 : %d\n", m_crQpOffset);
2486
2487  printf("QP adaptation                : %d (range=%d)\n", m_bUseAdaptiveQP, (m_bUseAdaptiveQP ? m_iQPAdaptationRange : 0) );
2488  printf("GOP size                     : %d\n", m_iGOPSize );
2489#if !O0194_DIFFERENT_BITDEPTH_EL_BL
2490  printf("Internal bit depth           : (Y:%d, C:%d)\n", m_internalBitDepthY, m_internalBitDepthC );
2491  printf("PCM sample bit depth         : (Y:%d, C:%d)\n", g_uiPCMBitDepthLuma, g_uiPCMBitDepthChroma );
2492#endif
2493#if O0215_PHASE_ALIGNMENT
2494  printf("Cross-layer sample alignment : %d\n", m_phaseAlignFlag);
2495#endif
2496#if !RC_SHVC_HARMONIZATION
2497  printf("RateControl                  : %d\n", m_RCEnableRateControl );
2498  if(m_RCEnableRateControl)
2499  {
2500    printf("TargetBitrate                : %d\n", m_RCTargetBitrate );
2501    printf("KeepHierarchicalBit          : %d\n", m_RCKeepHierarchicalBit );
2502    printf("LCULevelRC                   : %d\n", m_RCLCULevelRC );
2503    printf("UseLCUSeparateModel          : %d\n", m_RCUseLCUSeparateModel );
2504    printf("InitialQP                    : %d\n", m_RCInitialQP );
2505    printf("ForceIntraQP                 : %d\n", m_RCForceIntraQP );
2506  }
2507#endif
2508
2509  printf("Max Num Merge Candidates     : %d\n", m_maxNumMergeCand);
2510  printf("\n");
2511 
2512  printf("TOOL CFG: ");
2513#if !O0194_DIFFERENT_BITDEPTH_EL_BL
2514  printf("IBD:%d ", g_bitDepthY > m_inputBitDepthY || g_bitDepthC > m_inputBitDepthC);
2515#endif
2516  printf("HAD:%d ", m_bUseHADME           );
2517  printf("RDQ:%d ", m_useRDOQ            );
2518  printf("RDQTS:%d ", m_useRDOQTS        );
2519  printf("RDpenalty:%d ", m_rdPenalty  );
2520  printf("SQP:%d ", m_uiDeltaQpRD         );
2521  printf("ASR:%d ", m_bUseASR             );
2522  printf("FEN:%d ", m_bUseFastEnc         );
2523  printf("ECU:%d ", m_bUseEarlyCU         );
2524  printf("FDM:%d ", m_useFastDecisionForMerge );
2525  printf("CFM:%d ", m_bUseCbfFastMode         );
2526  printf("ESD:%d ", m_useEarlySkipDetection  );
2527#if FAST_INTRA_SHVC
2528  printf("FIS:%d ", m_useFastIntraScalable  );
2529#endif
2530  printf("RQT:%d ", 1     );
2531  printf("TransformSkip:%d ",     m_useTransformSkip              );
2532  printf("TransformSkipFast:%d ", m_useTransformSkipFast       );
2533  printf("Slice: M=%d ", m_sliceMode);
2534  if (m_sliceMode!=0)
2535  {
2536    printf("A=%d ", m_sliceArgument);
2537  }
2538  printf("SliceSegment: M=%d ",m_sliceSegmentMode);
2539  if (m_sliceSegmentMode!=0)
2540  {
2541    printf("A=%d ", m_sliceSegmentArgument);
2542  }
2543  printf("CIP:%d ", m_bUseConstrainedIntraPred);
2544  printf("SAO:%d ", (m_bUseSAO)?(1):(0));
2545#if !LAYER_CTB
2546  printf("PCM:%d ", (m_usePCM && (1<<m_uiPCMLog2MinSize) <= m_uiMaxCUWidth)? 1 : 0);
2547#endif
2548  if (m_TransquantBypassEnableFlag && m_CUTransquantBypassFlagForce)
2549  {
2550    printf("TransQuantBypassEnabled: =1 ");
2551  }
2552  else
2553  {
2554    printf("TransQuantBypassEnabled:%d ", (m_TransquantBypassEnableFlag)? 1:0 );
2555  }
2556  printf("WPP:%d ", (Int)m_useWeightedPred);
2557  printf("WPB:%d ", (Int)m_useWeightedBiPred);
2558  printf("PME:%d ", m_log2ParallelMergeLevel);
2559#if !SVC_EXTENSION
2560  printf(" WaveFrontSynchro:%d WaveFrontSubstreams:%d",
2561          m_iWaveFrontSynchro, m_iWaveFrontSubstreams);
2562#endif
2563  printf(" ScalingList:%d ", m_useScalingListId );
2564  printf("TMVPMode:%d ", m_TMVPModeId     );
2565#if ADAPTIVE_QP_SELECTION
2566  printf("AQpS:%d", m_bUseAdaptQpSelect   );
2567#endif
2568
2569  printf(" SignBitHidingFlag:%d ", m_signHideFlag);
2570#if SVC_EXTENSION
2571  printf("RecalQP:%d ", m_recalculateQPAccordingToLambda ? 1 : 0 );
2572  printf("EL_RAP_SliceType: %d ", m_elRapSliceBEnabled);
2573  printf("REF_IDX_ME_ZEROMV: %d ", REF_IDX_ME_ZEROMV);
2574  printf("ENCODER_FAST_MODE: %d ", ENCODER_FAST_MODE);
2575  printf("REF_IDX_MFM: %d ", REF_IDX_MFM);
2576  printf("O0194_DIFFERENT_BITDEPTH_EL_BL: %d ", O0194_DIFFERENT_BITDEPTH_EL_BL);
2577  printf("O0194_JOINT_US_BITSHIFT: %d ", O0194_JOINT_US_BITSHIFT);
2578#else
2579  printf("RecalQP:%d", m_recalculateQPAccordingToLambda ? 1 : 0 );
2580#endif
2581#if Q0048_CGS_3D_ASYMLUT
2582  printf("CGS: %d CGSMaxOctantDepth: %d CGSMaxYPartNumLog2: %d CGSLUTBit:%d " , m_nCGSFlag , m_nCGSMaxOctantDepth , m_nCGSMaxYPartNumLog2 , m_nCGSLUTBit );
2583#endif
2584  printf("\n\n");
2585 
2586  fflush(stdout);
2587}
2588
2589Bool confirmPara(Bool bflag, const Char* message)
2590{
2591  if (!bflag)
2592    return false;
2593 
2594  printf("Error: %s\n",message);
2595  return true;
2596}
2597
2598#if SVC_EXTENSION
2599Void TAppEncCfg::cfgStringToArray(Int **arr, string cfgString, Int numEntries, const char* logString)
2600{
2601  Char *tempChar = cfgString.empty() ? NULL : strdup(cfgString.c_str());
2602  if( numEntries > 0 )
2603  {
2604    Char *arrayEntry;
2605    Int i = 0;
2606    *arr = new Int[numEntries];
2607
2608    arrayEntry = strtok( tempChar, " ,");
2609    while(arrayEntry != NULL)
2610    {
2611      if( i >= numEntries )
2612      {
2613        printf( "%s: The number of entries specified is larger than the allowed number.\n", logString );
2614        exit( EXIT_FAILURE );
2615      }
2616      *( *arr + i ) = atoi( arrayEntry );
2617      arrayEntry = strtok(NULL, " ,");
2618      i++;
2619    }
2620    if( i < numEntries )
2621    {
2622      printf( "%s: Some entries are not specified.\n", logString );
2623      exit( EXIT_FAILURE );
2624    }
2625  }
2626  else
2627  {
2628    *arr = NULL;
2629  }
2630}
2631
2632#endif //SVC_EXTENSION
2633//! \}
Note: See TracBrowser for help on using the repository browser.