source: SHVCSoftware/branches/SHM-2.1-dev/source/App/TAppEncoder/TAppEncCfg.cpp @ 243

Last change on this file since 243 was 212, checked in by canon, 13 years ago

integration M0115 - Fast Intra Decision - cfg parameter: FIS (off by default)
edouard.francois@…

File size: 98.6 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6 * Copyright (c) 2010-2013, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     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, m_pColumnWidth()
72, m_pRowHeight()
73, m_scalingListFile()
74#if REF_IDX_FRAMEWORK
75, m_elRapSliceBEnabled(0)
76#endif
77{
78  for(UInt layer=0; layer<MAX_LAYERS; layer++)
79  {
80    m_acLayerCfg[layer].setAppEncCfg(this);
81  }
82}
83#else
84TAppEncCfg::TAppEncCfg()
85: m_pchInputFile()
86, m_pchBitstreamFile()
87, m_pchReconFile()
88, m_pchdQPFile()
89, m_pColumnWidth()
90, m_pRowHeight()
91, m_scalingListFile()
92{
93  m_aidQP = NULL;
94#if J0149_TONE_MAPPING_SEI
95  m_startOfCodedInterval = NULL;
96  m_codedPivotValue = NULL;
97  m_targetPivotValue = NULL;
98#endif
99}
100#endif
101
102TAppEncCfg::~TAppEncCfg()
103{
104#if SVC_EXTENSION
105  free(m_pBitstreamFile);
106#else
107  free(m_pchBitstreamFile);
108  if ( m_aidQP )
109  {
110    delete[] m_aidQP;
111  }
112#if J0149_TONE_MAPPING_SEI
113  if ( m_startOfCodedInterval )
114  {
115    delete[] m_startOfCodedInterval;
116    m_startOfCodedInterval = NULL;
117  }
118   if ( m_codedPivotValue )
119  {
120    delete[] m_codedPivotValue;
121    m_codedPivotValue = NULL;
122  }
123  if ( m_targetPivotValue )
124  {
125    delete[] m_targetPivotValue;
126    m_targetPivotValue = NULL;
127  }
128#endif
129  free(m_pchInputFile);
130#endif
131#if !SVC_EXTENSION 
132  free(m_pchReconFile);
133  free(m_pchdQPFile);
134#endif
135  free(m_pColumnWidth);
136  free(m_pRowHeight);
137  free(m_scalingListFile);
138}
139
140Void TAppEncCfg::create()
141{
142}
143
144Void TAppEncCfg::destroy()
145{
146#if VPS_EXTN_DIRECT_REF_LAYERS
147  for(Int layer = 0; layer < MAX_LAYERS; layer++)
148  {
149    if( m_acLayerCfg[layer].m_numDirectRefLayers > 0 )
150    {
151      delete [] m_acLayerCfg[layer].m_refLayerIds;
152    }
153  }
154#endif
155}
156
157std::istringstream &operator>>(std::istringstream &in, GOPEntry &entry)     //input
158{
159  in>>entry.m_sliceType;
160  in>>entry.m_POC;
161  in>>entry.m_QPOffset;
162  in>>entry.m_QPFactor;
163  in>>entry.m_tcOffsetDiv2;
164  in>>entry.m_betaOffsetDiv2;
165  in>>entry.m_temporalId;
166  in>>entry.m_numRefPicsActive;
167  in>>entry.m_numRefPics;
168  for ( Int i = 0; i < entry.m_numRefPics; i++ )
169  {
170    in>>entry.m_referencePics[i];
171  }
172  in>>entry.m_interRPSPrediction;
173#if AUTO_INTER_RPS
174  if (entry.m_interRPSPrediction==1)
175  {
176    in>>entry.m_deltaRPS;
177    in>>entry.m_numRefIdc;
178    for ( Int i = 0; i < entry.m_numRefIdc; i++ )
179    {
180      in>>entry.m_refIdc[i];
181    }
182  }
183  else if (entry.m_interRPSPrediction==2)
184  {
185    in>>entry.m_deltaRPS;
186  }
187#else
188  if (entry.m_interRPSPrediction)
189  {
190    in>>entry.m_deltaRPS;
191    in>>entry.m_numRefIdc;
192    for ( Int i = 0; i < entry.m_numRefIdc; i++ )
193    {
194      in>>entry.m_refIdc[i];
195    }
196  }
197#endif
198  return in;
199}
200
201#if SVC_EXTENSION
202void TAppEncCfg::getDirFilename(string& filename, string& dir, const string path)
203{
204  size_t pos = path.find_last_of("\\");
205  if(pos != std::string::npos)
206  {
207    filename.assign(path.begin() + pos + 1, path.end());
208    dir.assign(path.begin(), path.begin() + pos + 1);
209  }
210  else
211  {
212    pos = path.find_last_of("/");
213    if(pos != std::string::npos)
214    {
215      filename.assign(path.begin() + pos + 1, path.end());
216      dir.assign(path.begin(), path.begin() + pos + 1);
217    }
218    else
219    {
220      filename = path;
221      dir.assign("");
222    }
223  }
224}
225#endif
226
227static const struct MapStrToProfile {
228  const Char* str;
229  Profile::Name value;
230} strToProfile[] = {
231  {"none", Profile::NONE},
232  {"main", Profile::MAIN},
233  {"main10", Profile::MAIN10},
234  {"main-still-picture", Profile::MAINSTILLPICTURE},
235};
236
237static const struct MapStrToTier {
238  const Char* str;
239  Level::Tier value;
240} strToTier[] = {
241  {"main", Level::MAIN},
242  {"high", Level::HIGH},
243};
244
245static const struct MapStrToLevel {
246  const Char* str;
247  Level::Name value;
248} strToLevel[] = {
249  {"none",Level::NONE},
250  {"1",   Level::LEVEL1},
251  {"2",   Level::LEVEL2},
252  {"2.1", Level::LEVEL2_1},
253  {"3",   Level::LEVEL3},
254  {"3.1", Level::LEVEL3_1},
255  {"4",   Level::LEVEL4},
256  {"4.1", Level::LEVEL4_1},
257  {"5",   Level::LEVEL5},
258  {"5.1", Level::LEVEL5_1},
259  {"5.2", Level::LEVEL5_2},
260  {"6",   Level::LEVEL6},
261  {"6.1", Level::LEVEL6_1},
262  {"6.2", Level::LEVEL6_2},
263};
264
265template<typename T, typename P>
266static istream& readStrToEnum(P map[], unsigned long mapLen, istream &in, T &val)
267{
268  string str;
269  in >> str;
270
271  for (Int i = 0; i < mapLen; i++)
272  {
273    if (str == map[i].str)
274    {
275      val = map[i].value;
276      goto found;
277    }
278  }
279  /* not found */
280  in.setstate(ios::failbit);
281found:
282  return in;
283}
284
285static istream& operator>>(istream &in, Profile::Name &profile)
286{
287  return readStrToEnum(strToProfile, sizeof(strToProfile)/sizeof(*strToProfile), in, profile);
288}
289
290static istream& operator>>(istream &in, Level::Tier &tier)
291{
292  return readStrToEnum(strToTier, sizeof(strToTier)/sizeof(*strToTier), in, tier);
293}
294
295static istream& operator>>(istream &in, Level::Name &level)
296{
297  return readStrToEnum(strToLevel, sizeof(strToLevel)/sizeof(*strToLevel), in, level);
298}
299
300#if SIGNAL_BITRATE_PICRATE_IN_VPS
301Void readBoolString(const string inpString, const Int numEntries, Bool* &memberArray, const char *elementName);
302Void readIntString(const string inpString, const Int numEntries, Int* &memberArray, const char *elementName);
303#endif
304// ====================================================================================================================
305// Public member functions
306// ====================================================================================================================
307
308/** \param  argc        number of arguments
309    \param  argv        array of arguments
310    \retval             true when success
311 */
312Bool TAppEncCfg::parseCfg( Int argc, Char* argv[] )
313{
314  Bool do_help = false;
315 
316#if SVC_EXTENSION
317  string  cfg_LayerCfgFile  [MAX_LAYERS];
318  string  cfg_BitstreamFile;
319  string* cfg_InputFile     [MAX_LAYERS];
320  string* cfg_ReconFile     [MAX_LAYERS];
321  Double* cfg_fQP           [MAX_LAYERS];
322
323  Int*    cfg_SourceWidth   [MAX_LAYERS]; 
324  Int*    cfg_SourceHeight  [MAX_LAYERS];
325  Int*    cfg_FrameRate     [MAX_LAYERS];
326  Int*    cfg_IntraPeriod   [MAX_LAYERS];
327  Int*    cfg_conformanceMode  [MAX_LAYERS];
328#if VPS_EXTN_DIRECT_REF_LAYERS
329  Int*    cfg_numDirectRefLayers [MAX_LAYERS];
330  string cfg_refLayerIds   [MAX_LAYERS];
331  string* cfg_refLayerIdsPtr   [MAX_LAYERS];
332#endif
333#if SCALED_REF_LAYER_OFFSETS
334  Int*    cfg_scaledRefLayerLeftOffset [MAX_LAYERS];
335  Int*    cfg_scaledRefLayerTopOffset [MAX_LAYERS];
336  Int*    cfg_scaledRefLayerRightOffset [MAX_LAYERS];
337  Int*    cfg_scaledRefLayerBottomOffset [MAX_LAYERS];
338#endif
339#if RC_SHVC_HARMONIZATION
340  Bool*   cfg_RCEnableRateControl  [MAX_LAYERS];
341  Int*    cfg_RCTargetBitRate      [MAX_LAYERS];
342  Bool*   cfg_RCKeepHierarchicalBit[MAX_LAYERS];
343  Bool*   cfg_RCLCULevelRC         [MAX_LAYERS];
344  Bool*   cfg_RCUseLCUSeparateModel[MAX_LAYERS];
345  Int*    cfg_RCInitialQP          [MAX_LAYERS];
346  Bool*   cfg_RCForceIntraQP       [MAX_LAYERS];
347#endif
348  for(UInt layer = 0; layer < MAX_LAYERS; layer++)
349  {
350    cfg_InputFile[layer]    = &m_acLayerCfg[layer].m_cInputFile;
351    cfg_ReconFile[layer]    = &m_acLayerCfg[layer].m_cReconFile;
352    cfg_fQP[layer]          = &m_acLayerCfg[layer].m_fQP;
353    cfg_SourceWidth[layer]  = &m_acLayerCfg[layer].m_iSourceWidth;
354    cfg_SourceHeight[layer] = &m_acLayerCfg[layer].m_iSourceHeight;
355    cfg_FrameRate[layer]    = &m_acLayerCfg[layer].m_iFrameRate; 
356    cfg_IntraPeriod[layer]  = &m_acLayerCfg[layer].m_iIntraPeriod; 
357    cfg_conformanceMode[layer] = &m_acLayerCfg[layer].m_conformanceMode;
358#if VPS_EXTN_DIRECT_REF_LAYERS
359    cfg_numDirectRefLayers  [layer] = &m_acLayerCfg[layer].m_numDirectRefLayers;
360    cfg_refLayerIdsPtr      [layer]  = &cfg_refLayerIds[layer];
361#endif
362#if SCALED_REF_LAYER_OFFSETS
363    cfg_scaledRefLayerLeftOffset  [layer] = &m_acLayerCfg[layer].m_scaledRefLayerLeftOffset;
364    cfg_scaledRefLayerTopOffset   [layer] = &m_acLayerCfg[layer].m_scaledRefLayerTopOffset;
365    cfg_scaledRefLayerRightOffset [layer] = &m_acLayerCfg[layer].m_scaledRefLayerRightOffset;
366    cfg_scaledRefLayerBottomOffset[layer] = &m_acLayerCfg[layer].m_scaledRefLayerBottomOffset;
367#endif
368#if RC_SHVC_HARMONIZATION
369    cfg_RCEnableRateControl[layer]   = &m_acLayerCfg[layer].m_RCEnableRateControl;
370    cfg_RCTargetBitRate[layer]       = &m_acLayerCfg[layer].m_RCTargetBitrate;
371    cfg_RCKeepHierarchicalBit[layer] = &m_acLayerCfg[layer].m_RCKeepHierarchicalBit;
372    cfg_RCLCULevelRC[layer]          = &m_acLayerCfg[layer].m_RCLCULevelRC;
373    cfg_RCUseLCUSeparateModel[layer] = &m_acLayerCfg[layer].m_RCUseLCUSeparateModel;
374    cfg_RCInitialQP[layer]           = &m_acLayerCfg[layer].m_RCInitialQP;
375    cfg_RCForceIntraQP[layer]        = &m_acLayerCfg[layer].m_RCForceIntraQP;
376#endif
377  }
378#if AVC_BASE
379  string  cfg_BLInputFile;
380#endif
381#if AVC_SYNTAX
382  string  cfg_BLSyntaxFile;
383#endif
384#else
385  string cfg_InputFile;
386  string cfg_BitstreamFile;
387  string cfg_ReconFile;
388  string cfg_dQPFile;
389#endif
390  string cfg_ColumnWidth;
391  string cfg_RowHeight;
392  string cfg_ScalingListFile;
393#if J0149_TONE_MAPPING_SEI
394  string cfg_startOfCodedInterval;
395  string cfg_codedPivotValue;
396  string cfg_targetPivotValue;
397#endif
398#if SIGNAL_BITRATE_PICRATE_IN_VPS
399  string cfg_bitRateInfoPresentFlag;
400  string cfg_picRateInfoPresentFlag;
401  string cfg_avgBitRate;
402  string cfg_maxBitRate;
403  string cfg_avgPicRate;
404  string cfg_constantPicRateIdc;
405#endif
406  po::Options opts;
407  opts.addOptions()
408  ("help", do_help, false, "this help text")
409  ("c", po::parseConfigFile, "configuration file name")
410 
411  // File, I/O and source parameters
412#if SVC_EXTENSION
413  ("InputFile%d,-i%d",        cfg_InputFile,  string(""), MAX_LAYERS, "original YUV input file name for layer %d")
414  ("ReconFile%d,-o%d",        cfg_ReconFile,  string(""), MAX_LAYERS, "reconstruction YUV input file name for layer %d")
415  ("LayerConfig%d,-lc%d",     cfg_LayerCfgFile, string(""), MAX_LAYERS, "layer %d configuration file name")
416  ("SourceWidth%d,-wdt%d",    cfg_SourceWidth, 0, MAX_LAYERS, "Source picture width for layer %d")
417  ("SourceHeight%d,-hgt%d",   cfg_SourceHeight, 0, MAX_LAYERS, "Source picture height for layer %d")
418  ("FrameRate%d,-fr%d",       cfg_FrameRate,  0, MAX_LAYERS, "Frame rate for layer %d")
419  ("LambdaModifier%d,-LM%d",  m_adLambdaModifier, ( double )1.0, MAX_TLAYER, "Lambda modifier for temporal layer %d")
420#if VPS_EXTN_DIRECT_REF_LAYERS
421  ("NumDirectRefLayers%d",    cfg_numDirectRefLayers, -1, MAX_LAYERS, "Number of direct reference layers")
422  ("RefLayerIds%d",           cfg_refLayerIdsPtr, string(""), MAX_LAYERS, "direct reference layer IDs")
423#endif
424  ("NumLayers",               m_numLayers, 1, "Number of layers to code")
425  ("ConformanceMode%d",       cfg_conformanceMode,0, MAX_LAYERS, "Window conformance mode (0: no cropping, 1:automatic padding, 2: padding, 3:cropping")
426
427  ("BitstreamFile,b",       cfg_BitstreamFile, string(""), "Bitstream output file name")
428  ("InputBitDepth",         m_inputBitDepthY,    8, "Bit-depth of input file")
429  ("OutputBitDepth",        m_outputBitDepthY,   0, "Bit-depth of output file (default:InternalBitDepth)")
430  ("InternalBitDepth",      m_internalBitDepthY, 0, "Bit-depth the codec operates at. (default:InputBitDepth)"
431                                                       "If different to InputBitDepth, source data will be converted")
432  ("InputBitDepthC",        m_inputBitDepthC,    0, "As per InputBitDepth but for chroma component. (default:InputBitDepth)")
433  ("OutputBitDepthC",       m_outputBitDepthC,   0, "As per OutputBitDepth but for chroma component. (default:InternalBitDepthC)")
434  ("InternalBitDepthC",     m_internalBitDepthC, 0, "As per InternalBitDepth but for chroma component. (default:IntrenalBitDepth)")
435#if SCALED_REF_LAYER_OFFSETS
436  ("ScaledRefLayerLeftOffset%d",   cfg_scaledRefLayerLeftOffset,  0, MAX_LAYERS, "Horizontal offset of top-left luma sample of scaled base layer picture with respect to"
437                                                                 " top-left luma sample of the EL picture, in units of two luma samples")
438  ("ScaledRefLayerTopOffset%d",    cfg_scaledRefLayerTopOffset,   0, MAX_LAYERS,   "Vertical offset of top-left luma sample of scaled base layer picture with respect to"
439                                                                 " top-left luma sample of the EL picture, in units of two luma samples")
440  ("ScaledRefLayerRightOffset%d",  cfg_scaledRefLayerRightOffset, 0, MAX_LAYERS, "Horizontal offset of bottom-right luma sample of scaled base layer picture with respect to"
441                                                                 " bottom-right luma sample of the EL picture, in units of two luma samples")
442  ("ScaledRefLayerBottomOffset%d", cfg_scaledRefLayerBottomOffset,0, MAX_LAYERS, "Vertical offset of bottom-right luma sample of scaled base layer picture with respect to"
443                                                                 " bottom-right luma sample of the EL picture, in units of two luma samples")
444#endif
445#if AVC_BASE
446  ("AvcBase,-avc",            m_avcBaseLayerFlag,     0, "avc_base_layer_flag")
447  ("InputBLFile,-ibl",        cfg_BLInputFile,     string(""), "Base layer rec YUV input file name")
448#if AVC_SYNTAX
449  ("InputBLSyntaxFile,-ibs",  cfg_BLSyntaxFile,     string(""), "Base layer syntax input file name")
450#endif
451#endif
452#if REF_IDX_FRAMEWORK
453  ("EnableElRapB,-use-rap-b",  m_elRapSliceBEnabled, 0, "Set ILP over base-layer I picture to B picture (default is P picture)")
454#endif 
455#else 
456  ("InputFile,i",           cfg_InputFile,     string(""), "Original YUV input file name")
457  ("BitstreamFile,b",       cfg_BitstreamFile, string(""), "Bitstream output file name")
458  ("ReconFile,o",           cfg_ReconFile,     string(""), "Reconstructed YUV output file name")
459  ("SourceWidth,-wdt",      m_iSourceWidth,        0, "Source picture width")
460  ("SourceHeight,-hgt",     m_iSourceHeight,       0, "Source picture height")
461  ("InputBitDepth",         m_inputBitDepthY,    8, "Bit-depth of input file")
462  ("OutputBitDepth",        m_outputBitDepthY,   0, "Bit-depth of output file (default:InternalBitDepth)")
463  ("InternalBitDepth",      m_internalBitDepthY, 0, "Bit-depth the codec operates at. (default:InputBitDepth)"
464                                                       "If different to InputBitDepth, source data will be converted")
465  ("InputBitDepthC",        m_inputBitDepthC,    0, "As per InputBitDepth but for chroma component. (default:InputBitDepth)")
466  ("OutputBitDepthC",       m_outputBitDepthC,   0, "As per OutputBitDepth but for chroma component. (default:InternalBitDepthC)")
467  ("InternalBitDepthC",     m_internalBitDepthC, 0, "As per InternalBitDepth but for chroma component. (default:IntrenalBitDepth)")
468  ("ConformanceMode",       m_conformanceMode,     0, "Window conformance mode (0: no window, 1:automatic padding, 2:padding, 3:conformance")
469  ("HorizontalPadding,-pdx",m_aiPad[0],            0, "Horizontal source padding for conformance window mode 2")
470  ("VerticalPadding,-pdy",  m_aiPad[1],            0, "Vertical source padding for conformance window mode 2")
471  ("ConfLeft",              m_confLeft,            0, "Left offset for window conformance mode 3")
472  ("ConfRight",             m_confRight,           0, "Right offset for window conformance mode 3")
473  ("ConfTop",               m_confTop,             0, "Top offset for window conformance mode 3")
474  ("ConfBottom",            m_confBottom,          0, "Bottom offset for window conformance mode 3")
475  ("FrameRate,-fr",         m_iFrameRate,          0, "Frame rate")
476#endif
477  ("FrameSkip,-fs",         m_FrameSkip,          0u, "Number of frames to skip at start of input YUV")
478  ("FramesToBeEncoded,f",   m_framesToBeEncoded,   0, "Number of frames to be encoded (default=all)")
479 
480  // Profile and level
481  ("Profile", m_profile,   Profile::NONE, "Profile to be used when encoding (Incomplete)")
482  ("Level",   m_level,     Level::NONE,   "Level limit to be used, eg 5.1 (Incomplete)")
483  ("Tier",    m_levelTier, Level::MAIN,   "Tier to use for interpretation of --Level")
484
485#if L0046_CONSTRAINT_FLAGS
486  ("ProgressiveSource", m_progressiveSourceFlag, false, "Indicate that source is progressive")
487  ("InterlacedSource",  m_interlacedSourceFlag,  false, "Indicate that source is interlaced")
488  ("NonPackedSource",   m_nonPackedConstraintFlag, false, "Indicate that source does not contain frame packing")
489  ("FrameOnly",         m_frameOnlyConstraintFlag, false, "Indicate that the bitstream contains only frames")
490#endif
491
492  // Unit definition parameters
493  ("MaxCUWidth",              m_uiMaxCUWidth,             64u)
494  ("MaxCUHeight",             m_uiMaxCUHeight,            64u)
495  // todo: remove defaults from MaxCUSize
496  ("MaxCUSize,s",             m_uiMaxCUWidth,             64u, "Maximum CU size")
497  ("MaxCUSize,s",             m_uiMaxCUHeight,            64u, "Maximum CU size")
498  ("MaxPartitionDepth,h",     m_uiMaxCUDepth,              4u, "CU depth")
499 
500  ("QuadtreeTULog2MaxSize",   m_uiQuadtreeTULog2MaxSize,   6u, "Maximum TU size in logarithm base 2")
501  ("QuadtreeTULog2MinSize",   m_uiQuadtreeTULog2MinSize,   2u, "Minimum TU size in logarithm base 2")
502 
503  ("QuadtreeTUMaxDepthIntra", m_uiQuadtreeTUMaxDepthIntra, 1u, "Depth of TU tree for intra CUs")
504  ("QuadtreeTUMaxDepthInter", m_uiQuadtreeTUMaxDepthInter, 2u, "Depth of TU tree for inter CUs")
505 
506  // Coding structure paramters
507#if SVC_EXTENSION
508  ("IntraPeriod%d,-ip%d",  cfg_IntraPeriod, -1, MAX_LAYERS, "intra period in frames for layer %d, (-1: only first frame)")
509#else
510  ("IntraPeriod,-ip",         m_iIntraPeriod,              -1, "Intra period in frames, (-1: only first frame)")
511#endif
512  ("DecodingRefreshType,-dr", m_iDecodingRefreshType,       0, "Intra refresh type (0:none 1:CRA 2:IDR)")
513  ("GOPSize,g",               m_iGOPSize,                   1, "GOP size of temporal structure")
514#if !L0034_COMBINED_LIST_CLEANUP
515  ("ListCombination,-lc",     m_bUseLComb,               true, "Combined reference list for uni-prediction estimation in B-slices")
516#endif
517  // motion options
518  ("FastSearch",              m_iFastSearch,                1, "0:Full search  1:Diamond  2:PMVFAST")
519  ("SearchRange,-sr",         m_iSearchRange,              96, "Motion search range")
520  ("BipredSearchRange",       m_bipredSearchRange,          4, "Motion search range for bipred refinement")
521  ("HadamardME",              m_bUseHADME,               true, "Hadamard ME for fractional-pel")
522  ("ASR",                     m_bUseASR,                false, "Adaptive motion search range")
523
524#if SVC_EXTENSION
525  ("LambdaModifier%d,-LM%d",  m_adLambdaModifier, ( double )1.0, MAX_TLAYER, "Lambda modifier for temporal layer %d")
526#else
527  // Mode decision parameters
528  ("LambdaModifier0,-LM0", m_adLambdaModifier[ 0 ], ( Double )1.0, "Lambda modifier for temporal layer 0")
529  ("LambdaModifier1,-LM1", m_adLambdaModifier[ 1 ], ( Double )1.0, "Lambda modifier for temporal layer 1")
530  ("LambdaModifier2,-LM2", m_adLambdaModifier[ 2 ], ( Double )1.0, "Lambda modifier for temporal layer 2")
531  ("LambdaModifier3,-LM3", m_adLambdaModifier[ 3 ], ( Double )1.0, "Lambda modifier for temporal layer 3")
532  ("LambdaModifier4,-LM4", m_adLambdaModifier[ 4 ], ( Double )1.0, "Lambda modifier for temporal layer 4")
533  ("LambdaModifier5,-LM5", m_adLambdaModifier[ 5 ], ( Double )1.0, "Lambda modifier for temporal layer 5")
534  ("LambdaModifier6,-LM6", m_adLambdaModifier[ 6 ], ( Double )1.0, "Lambda modifier for temporal layer 6")
535  ("LambdaModifier7,-LM7", m_adLambdaModifier[ 7 ], ( Double )1.0, "Lambda modifier for temporal layer 7")
536#endif
537
538  /* Quantization parameters */
539#if SVC_EXTENSION
540  ("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")
541#else
542  ("QP,q",          m_fQP,             30.0, "Qp value, if value is float, QP is switched once during encoding")
543#endif
544  ("DeltaQpRD,-dqr",m_uiDeltaQpRD,       0u, "max dQp offset for slice")
545  ("MaxDeltaQP,d",  m_iMaxDeltaQP,        0, "max dQp offset for block")
546  ("MaxCuDQPDepth,-dqd",  m_iMaxCuDQPDepth,        0, "max depth for a minimum CuDQP")
547
548  ("CbQpOffset,-cbqpofs",  m_cbQpOffset,        0, "Chroma Cb QP Offset")
549  ("CrQpOffset,-crqpofs",  m_crQpOffset,        0, "Chroma Cr QP Offset")
550
551#if ADAPTIVE_QP_SELECTION
552  ("AdaptiveQpSelection,-aqps",   m_bUseAdaptQpSelect,           false, "AdaptiveQpSelection")
553#endif
554
555  ("AdaptiveQP,-aq",                m_bUseAdaptiveQP,           false, "QP adaptation based on a psycho-visual model")
556  ("MaxQPAdaptationRange,-aqr",     m_iQPAdaptationRange,           6, "QP adaptation range")
557#if !SVC_EXTENSION
558  ("dQPFile,m",                     cfg_dQPFile,           string(""), "dQP file name")
559#endif
560  ("RDOQ",                          m_useRDOQ,                  true )
561  ("RDOQTS",                        m_useRDOQTS,                true )
562#if L0232_RD_PENALTY
563  ("RDpenalty",                     m_rdPenalty,                0,  "RD-penalty for 32x32 TU for intra in non-intra slices. 0:disbaled  1:RD-penalty  2:maximum RD-penalty")
564#endif
565  // Entropy coding parameters
566  ("SBACRD",                         m_bUseSBACRD,                      true, "SBAC based RD estimation")
567 
568  // Deblocking filter parameters
569  ("LoopFilterDisable",              m_bLoopFilterDisable,             false )
570  ("LoopFilterOffsetInPPS",          m_loopFilterOffsetInPPS,          false )
571  ("LoopFilterBetaOffset_div2",      m_loopFilterBetaOffsetDiv2,           0 )
572  ("LoopFilterTcOffset_div2",        m_loopFilterTcOffsetDiv2,             0 )
573  ("DeblockingFilterControlPresent", m_DeblockingFilterControlPresent, false )
574#if L0386_DB_METRIC
575  ("DeblockingFilterMetric",         m_DeblockingFilterMetric,         false )
576#endif
577
578  // Coding tools
579  ("AMP",                      m_enableAMP,                 true,  "Enable asymmetric motion partitions")
580  ("TransformSkip",            m_useTransformSkip,          false, "Intra transform skipping")
581  ("TransformSkipFast",        m_useTransformSkipFast,      false, "Fast intra transform skipping")
582  ("SAO",                      m_bUseSAO,                   true,  "Enable Sample Adaptive Offset")
583  ("MaxNumOffsetsPerPic",      m_maxNumOffsetsPerPic,       2048,  "Max number of SAO offset per picture (Default: 2048)")   
584  ("SAOLcuBoundary",           m_saoLcuBoundary,            false, "0: right/bottom LCU boundary areas skipped from SAO parameter estimation, 1: non-deblocked pixels are used for those areas")
585  ("SAOLcuBasedOptimization",  m_saoLcuBasedOptimization,   true,  "0: SAO picture-based optimization, 1: SAO LCU-based optimization ")
586  ("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")
587  ("SliceArgument",            m_sliceArgument,            0,     "Depending on SliceMode being:"
588                                                                   "\t1: max number of CTUs per slice"
589                                                                   "\t2: max number of bytes per slice"
590                                                                   "\t3: max number of tiles per slice")
591  ("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")
592  ("SliceSegmentArgument",     m_sliceSegmentArgument,   0,     "Depending on SliceSegmentMode being:"
593                                                                   "\t1: max number of CTUs per slice segment"
594                                                                   "\t2: max number of bytes per slice segment"
595                                                                   "\t3: max number of tiles per slice segment")
596  ("LFCrossSliceBoundaryFlag", m_bLFCrossSliceBoundaryFlag, true)
597
598  ("ConstrainedIntraPred",     m_bUseConstrainedIntraPred,  false, "Constrained Intra Prediction")
599
600  ("PCMEnabledFlag",           m_usePCM,                    false)
601  ("PCMLog2MaxSize",           m_pcmLog2MaxSize,            5u)
602  ("PCMLog2MinSize",           m_uiPCMLog2MinSize,          3u)
603  ("PCMInputBitDepthFlag",     m_bPCMInputBitDepthFlag,     true)
604  ("PCMFilterDisableFlag",     m_bPCMFilterDisableFlag,    false)
605
606  ("LosslessCuEnabled",        m_useLossless, false)
607
608  ("WeightedPredP,-wpP",          m_useWeightedPred,               false,      "Use weighted prediction in P slices")
609  ("WeightedPredB,-wpB",          m_useWeightedBiPred,             false,      "Use weighted (bidirectional) prediction in B slices")
610  ("Log2ParallelMergeLevel",      m_log2ParallelMergeLevel,     2u,          "Parallel merge estimation region")
611  ("UniformSpacingIdc",           m_iUniformSpacingIdr,            0,          "Indicates if the column and row boundaries are distributed uniformly")
612  ("NumTileColumnsMinus1",        m_iNumColumnsMinus1,             0,          "Number of columns in a picture minus 1")
613  ("ColumnWidthArray",            cfg_ColumnWidth,                 string(""), "Array containing ColumnWidth values in units of LCU")
614  ("NumTileRowsMinus1",           m_iNumRowsMinus1,                0,          "Number of rows in a picture minus 1")
615  ("RowHeightArray",              cfg_RowHeight,                   string(""), "Array containing RowHeight values in units of LCU")
616  ("LFCrossTileBoundaryFlag",      m_bLFCrossTileBoundaryFlag,             true,          "1: cross-tile-boundary loop filtering. 0:non-cross-tile-boundary loop filtering")
617  ("WaveFrontSynchro",            m_iWaveFrontSynchro,             0,          "0: no synchro; 1 synchro with TR; 2 TRR etc")
618  ("ScalingList",                 m_useScalingListId,              0,          "0: no scaling list, 1: default scaling lists, 2: scaling lists specified in ScalingListFile")
619  ("ScalingListFile",             cfg_ScalingListFile,             string(""), "Scaling list file name")
620  ("SignHideFlag,-SBH",                m_signHideFlag, 1)
621  ("MaxNumMergeCand",             m_maxNumMergeCand,             5u,         "Maximum number of merge candidates")
622
623  /* Misc. */
624  ("SEIDecodedPictureHash",       m_decodedPictureHashSEIEnabled, 0, "Control generation of decode picture hash SEI messages\n"
625                                                                    "\t3: checksum\n"
626                                                                    "\t2: CRC\n"
627                                                                    "\t1: use MD5\n"
628                                                                    "\t0: disable")
629  ("SEIpictureDigest",            m_decodedPictureHashSEIEnabled, 0, "deprecated alias for SEIDecodedPictureHash")
630  ("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")
631  ("FEN", m_bUseFastEnc, false, "fast encoder setting")
632  ("ECU", m_bUseEarlyCU, false, "Early CU setting") 
633  ("FDM", m_useFastDecisionForMerge, true, "Fast decision for Merge RD Cost") 
634  ("CFM", m_bUseCbfFastMode, false, "Cbf fast mode setting")
635  ("ESD", m_useEarlySkipDetection, false, "Early SKIP detection setting")
636#if FAST_INTRA_SHVC
637  ("FIS", m_useFastIntraScalable, false, "Fast Intra Decision for Scalable HEVC")
638#endif
639#if RATE_CONTROL_LAMBDA_DOMAIN
640#if RC_SHVC_HARMONIZATION
641  ("RateControl%d", cfg_RCEnableRateControl, false, MAX_LAYERS, "Rate control: enable rate control for layer %d")
642  ("TargetBitrate%d", cfg_RCTargetBitRate, 0, MAX_LAYERS, "Rate control: target bitrate for layer %d")
643  ("KeepHierarchicalBit%d", cfg_RCKeepHierarchicalBit, false, MAX_LAYERS, "Rate control: keep hierarchical bit allocation for layer %d")
644  ("LCULevelRateControl%d", cfg_RCLCULevelRC, true, MAX_LAYERS, "Rate control: LCU level RC")
645  ("RCLCUSeparateModel%d", cfg_RCUseLCUSeparateModel, true, MAX_LAYERS, "Rate control: Use LCU level separate R-lambda model")
646  ("InitialQP%d", cfg_RCInitialQP, 0, MAX_LAYERS, "Rate control: initial QP")
647  ("RCForceIntraQP%d", cfg_RCForceIntraQP, false, MAX_LAYERS, "Rate control: force intra QP to be equal to initial QP")
648#else
649  ( "RateControl",         m_RCEnableRateControl,   false, "Rate control: enable rate control" )
650  ( "TargetBitrate",       m_RCTargetBitrate,           0, "Rate control: target bitrate" )
651  ( "KeepHierarchicalBit", m_RCKeepHierarchicalBit, false, "Rate control: keep hierarchical bit allocation in rate control algorithm" )
652  ( "LCULevelRateControl", m_RCLCULevelRC,           true, "Rate control: true: LCU level RC; false: picture level RC" )
653  ( "RCLCUSeparateModel",  m_RCUseLCUSeparateModel,  true, "Rate control: use LCU level separate R-lambda model" )
654  ( "InitialQP",           m_RCInitialQP,               0, "Rate control: initial QP" )
655  ( "RCForceIntraQP",      m_RCForceIntraQP,        false, "Rate control: force intra QP to be equal to initial QP" )
656#endif
657#else
658  ("RateCtrl,-rc", m_enableRateCtrl, false, "Rate control on/off")
659  ("TargetBitrate,-tbr", m_targetBitrate, 0, "Input target bitrate")
660  ("NumLCUInUnit,-nu", m_numLCUInUnit, 0, "Number of LCUs in an Unit")
661#endif
662
663  ("TransquantBypassEnableFlag", m_TransquantBypassEnableFlag, false, "transquant_bypass_enable_flag indicator in PPS")
664  ("CUTransquantBypassFlagValue", m_CUTransquantBypassFlagValue, false, "Fixed cu_transquant_bypass_flag value, when transquant_bypass_enable_flag is enabled")
665  ("RecalculateQPAccordingToLambda", m_recalculateQPAccordingToLambda, false, "Recalculate QP values according to lambda values. Do not suggest to be enabled in all intra case")
666  ("StrongIntraSmoothing,-sis",      m_useStrongIntraSmoothing,           true, "Enable strong intra smoothing for 32x32 blocks")
667  ("SEIActiveParameterSets",         m_activeParameterSetsSEIEnabled,          0, "Enable generation of active parameter sets SEI messages")
668  ("VuiParametersPresent,-vui",      m_vuiParametersPresentFlag,           false, "Enable generation of vui_parameters()")
669  ("AspectRatioInfoPresent",         m_aspectRatioInfoPresentFlag,         false, "Signals whether aspect_ratio_idc is present")
670  ("AspectRatioIdc",                 m_aspectRatioIdc,                         0, "aspect_ratio_idc")
671  ("SarWidth",                       m_sarWidth,                               0, "horizontal size of the sample aspect ratio")
672  ("SarHeight",                      m_sarHeight,                              0, "vertical size of the sample aspect ratio")
673  ("OverscanInfoPresent",            m_overscanInfoPresentFlag,            false, "Indicates whether conformant decoded pictures are suitable for display using overscan\n")
674  ("OverscanAppropriate",            m_overscanAppropriateFlag,            false, "Indicates whether conformant decoded pictures are suitable for display using overscan\n")
675  ("VideoSignalTypePresent",         m_videoSignalTypePresentFlag,         false, "Signals whether video_format, video_full_range_flag, and colour_description_present_flag are present")
676  ("VideoFormat",                    m_videoFormat,                            5, "Indicates representation of pictures")
677  ("VideoFullRange",                 m_videoFullRangeFlag,                 false, "Indicates the black level and range of luma and chroma signals")
678  ("ColourDescriptionPresent",       m_colourDescriptionPresentFlag,       false, "Signals whether colour_primaries, transfer_characteristics and matrix_coefficients are present")
679  ("ColourPrimaries",                m_colourPrimaries,                        2, "Indicates chromaticity coordinates of the source primaries")
680  ("TransferCharateristics",         m_transferCharacteristics,                2, "Indicates the opto-electronic transfer characteristics of the source")
681  ("MatrixCoefficients",             m_matrixCoefficients,                     2, "Describes the matrix coefficients used in deriving luma and chroma from RGB primaries")
682  ("ChromaLocInfoPresent",           m_chromaLocInfoPresentFlag,           false, "Signals whether chroma_sample_loc_type_top_field and chroma_sample_loc_type_bottom_field are present")
683  ("ChromaSampleLocTypeTopField",    m_chromaSampleLocTypeTopField,            0, "Specifies the location of chroma samples for top field")
684  ("ChromaSampleLocTypeBottomField", m_chromaSampleLocTypeBottomField,         0, "Specifies the location of chroma samples for bottom field")
685  ("NeutralChromaIndication",        m_neutralChromaIndicationFlag,        false, "Indicates that the value of all decoded chroma samples is equal to 1<<(BitDepthCr-1)")
686  ("DefaultDisplayWindowFlag",       m_defaultDisplayWindowFlag,           false, "Indicates the presence of the Default Window parameters")
687  ("DefDispWinLeftOffset",           m_defDispWinLeftOffset,                   0, "Specifies the left offset of the default display window from the conformance window")
688  ("DefDispWinRightOffset",          m_defDispWinRightOffset,                  0, "Specifies the right offset of the default display window from the conformance window")
689  ("DefDispWinTopOffset",            m_defDispWinTopOffset,                    0, "Specifies the top offset of the default display window from the conformance window")
690  ("DefDispWinBottomOffset",         m_defDispWinBottomOffset,                 0, "Specifies the bottom offset of the default display window from the conformance window")
691  ("FrameFieldInfoPresentFlag",      m_frameFieldInfoPresentFlag,               false, "Indicates that pic_struct and field coding related values are present in picture timing SEI messages")
692  ("PocProportionalToTimingFlag",   m_pocProportionalToTimingFlag,         false, "Indicates that the POC value is proportional to the output time w.r.t. first picture in CVS")
693  ("NumTicksPocDiffOneMinus1",      m_numTicksPocDiffOneMinus1,                0, "Number of ticks minus 1 that for a POC difference of one")
694  ("BitstreamRestriction",           m_bitstreamRestrictionFlag,           false, "Signals whether bitstream restriction parameters are present")
695  ("TilesFixedStructure",            m_tilesFixedStructureFlag,            false, "Indicates that each active picture parameter set has the same values of the syntax elements related to tiles")
696  ("MotionVectorsOverPicBoundaries", m_motionVectorsOverPicBoundariesFlag, false, "Indicates that no samples outside the picture boundaries are used for inter prediction")
697  ("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")
698  ("MaxBitsPerMinCuDenom",           m_maxBitsPerMinCuDenom,                   1, "Indicates an upper bound for the number of bits of coding_unit() data")
699  ("Log2MaxMvLengthHorizontal",      m_log2MaxMvLengthHorizontal,             15, "Indicate the maximum absolute value of a decoded horizontal MV component in quarter-pel luma units")
700  ("Log2MaxMvLengthVertical",        m_log2MaxMvLengthVertical,               15, "Indicate the maximum absolute value of a decoded vertical MV component in quarter-pel luma units")
701  ("SEIRecoveryPoint",               m_recoveryPointSEIEnabled,                0, "Control generation of recovery point SEI messages")
702  ("SEIBufferingPeriod",             m_bufferingPeriodSEIEnabled,              0, "Control generation of buffering period SEI messages")
703  ("SEIPictureTiming",               m_pictureTimingSEIEnabled,                0, "Control generation of picture timing SEI messages")
704#if J0149_TONE_MAPPING_SEI
705  ("SEIToneMappingInfo",                       m_toneMappingInfoSEIEnabled,    false, "Control generation of Tone Mapping SEI messages")
706  ("SEIToneMapId",                             m_toneMapId,                        0, "Specifies Id of Tone Mapping SEI message for a given session")
707  ("SEIToneMapCancelFlag",                     m_toneMapCancelFlag,            false, "Indicates that Tone Mapping SEI message cancels the persistance or follows")
708  ("SEIToneMapPersistenceFlag",                m_toneMapPersistenceFlag,        true, "Specifies the persistence of the Tone Mapping SEI message")
709  ("SEIToneMapCodedDataBitDepth",              m_toneMapCodedDataBitDepth,         8, "Specifies Coded Data BitDepth of Tone Mapping SEI messages")
710  ("SEIToneMapTargetBitDepth",                 m_toneMapTargetBitDepth,            8, "Specifies Output BitDepth of Tome mapping function")
711  ("SEIToneMapModelId",                        m_toneMapModelId,                   0, "Specifies Model utilized for mapping coded data into target_bit_depth range\n"
712                                                                                      "\t0:  linear mapping with clipping\n"
713                                                                                      "\t1:  sigmoidal mapping\n"
714                                                                                      "\t2:  user-defined table mapping\n"
715                                                                                      "\t3:  piece-wise linear mapping\n"
716                                                                                      "\t4:  luminance dynamic range information ")
717  ("SEIToneMapMinValue",                              m_toneMapMinValue,                          0, "Specifies the minimum value in mode 0")
718  ("SEIToneMapMaxValue",                              m_toneMapMaxValue,                       1023, "Specifies the maxmum value in mode 0")
719  ("SEIToneMapSigmoidMidpoint",                       m_sigmoidMidpoint,                        512, "Specifies the centre point in mode 1")
720  ("SEIToneMapSigmoidWidth",                          m_sigmoidWidth,                           960, "Specifies the distance between 5% and 95% values of the target_bit_depth in mode 1")
721  ("SEIToneMapStartOfCodedInterval",                  cfg_startOfCodedInterval,          string(""), "Array of user-defined mapping table")
722  ("SEIToneMapNumPivots",                             m_numPivots,                                0, "Specifies the number of pivot points in mode 3")
723  ("SEIToneMapCodedPivotValue",                       cfg_codedPivotValue,               string(""), "Array of pivot point")
724  ("SEIToneMapTargetPivotValue",                      cfg_targetPivotValue,              string(""), "Array of pivot point")
725  ("SEIToneMapCameraIsoSpeedIdc",                     m_cameraIsoSpeedIdc,                        0, "Indicates the camera ISO speed for daylight illumination")
726  ("SEIToneMapCameraIsoSpeedValue",                   m_cameraIsoSpeedValue,                    400, "Specifies the camera ISO speed for daylight illumination of Extended_ISO")
727  ("SEIToneMapExposureCompensationValueSignFlag",     m_exposureCompensationValueSignFlag,        0, "Specifies the sign of ExposureCompensationValue")
728  ("SEIToneMapExposureCompensationValueNumerator",    m_exposureCompensationValueNumerator,       0, "Specifies the numerator of ExposureCompensationValue")
729  ("SEIToneMapExposureCompensationValueDenomIdc",     m_exposureCompensationValueDenomIdc,        2, "Specifies the denominator of ExposureCompensationValue")
730  ("SEIToneMapRefScreenLuminanceWhite",               m_refScreenLuminanceWhite,                350, "Specifies reference screen brightness setting in units of candela per square metre")
731  ("SEIToneMapExtendedRangeWhiteLevel",               m_extendedRangeWhiteLevel,                800, "Indicates the luminance dynamic range")
732  ("SEIToneMapNominalBlackLevelLumaCodeValue",        m_nominalBlackLevelLumaCodeValue,          16, "Specifies luma sample value of the nominal black level assigned decoded pictures")
733  ("SEIToneMapNominalWhiteLevelLumaCodeValue",        m_nominalWhiteLevelLumaCodeValue,         235, "Specifies luma sample value of the nominal white level assigned decoded pictures")
734  ("SEIToneMapExtendedWhiteLevelLumaCodeValue",       m_extendedWhiteLevelLumaCodeValue,        300, "Specifies luma sample value of the extended dynamic range assigned decoded pictures")
735#endif
736  ("SEIFramePacking",                m_framePackingSEIEnabled,                 0, "Control generation of frame packing SEI messages")
737  ("SEIFramePackingType",            m_framePackingSEIType,                    0, "Define frame packing arrangement\n"
738                                                                                  "\t0: checkerboard - pixels alternatively represent either frames\n"
739                                                                                  "\t1: column alternation - frames are interlaced by column\n"
740                                                                                  "\t2: row alternation - frames are interlaced by row\n"
741                                                                                  "\t3: side by side - frames are displayed horizontally\n"
742                                                                                  "\t4: top bottom - frames are displayed vertically\n"
743                                                                                  "\t5: frame alternation - one frame is alternated with the other")
744  ("SEIFramePackingId",              m_framePackingSEIId,                      0, "Id of frame packing SEI message for a given session")
745  ("SEIFramePackingQuincunx",        m_framePackingSEIQuincunx,                0, "Indicate the presence of a Quincunx type video frame")
746  ("SEIFramePackingInterpretation",  m_framePackingSEIInterpretation,          0, "Indicate the interpretation of the frame pair\n"
747                                                                                  "\t0: unspecified\n"
748                                                                                  "\t1: stereo pair, frame0 represents left view\n"
749                                                                                  "\t2: stereo pair, frame0 represents right view")
750  ("SEIDisplayOrientation",          m_displayOrientationSEIAngle,             0, "Control generation of display orientation SEI messages\n"
751                                                              "\tN: 0 < N < (2^16 - 1) enable display orientation SEI message with anticlockwise_rotation = N and display_orientation_repetition_period = 1\n"
752                                                              "\t0: disable")
753  ("SEITemporalLevel0Index",         m_temporalLevel0IndexSEIEnabled,          0, "Control generation of temporal level 0 index SEI messages")
754  ("SEIGradualDecodingRefreshInfo",  m_gradualDecodingRefreshInfoEnabled,      0, "Control generation of gradual decoding refresh information SEI message")
755  ("SEIDecodingUnitInfo",             m_decodingUnitInfoSEIEnabled,                       0, "Control generation of decoding unit information SEI message.")
756#if L0208_SOP_DESCRIPTION_SEI
757  ("SEISOPDescription",              m_SOPDescriptionSEIEnabled,              0, "Control generation of SOP description SEI messages")
758#endif
759#if K0180_SCALABLE_NESTING_SEI
760  ("SEIScalableNesting",             m_scalableNestingSEIEnabled,              0, "Control generation of scalable nesting SEI messages")
761#endif
762#if SIGNAL_BITRATE_PICRATE_IN_VPS
763  ("BitRatePicRateMaxTLayers",   m_bitRatePicRateMaxTLayers,           0, "Maximum number of sub-layers signalled; can be inferred otherwise; here for easy parsing of config. file")
764  ("BitRateInfoPresent",         cfg_bitRateInfoPresentFlag,          string(""), "Control signalling of bit rate information of avg. bit rate and max. bit rate in VPS\n"
765                                                                          "\t0: Do not sent bit rate info\n"
766                                                                          "\tN (N > 0): Send bit rate info for N sub-layers. N should equal maxTempLayers.")                                                                     
767  ("PicRateInfoPresent",         cfg_picRateInfoPresentFlag,          string(""), "Control signalling of picture rate information of avg. bit rate and max. bit rate in VPS\n"
768                                                                          "\t0: Do not sent picture rate info\n"
769                                                                          "\tN (N > 0): Send picture rate info for N sub-layers. N should equal maxTempLayers.")                                                                     
770  ("AvgBitRate",                   cfg_avgBitRate,                    string(""), "List of avg. bit rates for the different sub-layers; include non-negative number even if corresponding flag is 0")
771  ("MaxBitRate",                   cfg_maxBitRate,                    string(""), "List of max. bit rates for the different sub-layers; include non-negative number even if corresponding flag is 0")
772  ("AvgPicRate",                   cfg_avgPicRate,                    string(""), "List of avg. picture rates for the different sub-layers; include non-negative number even if corresponding flag is 0")
773  ("ConstantPicRateIdc",           cfg_constantPicRateIdc,            string(""), "List of constant picture rate IDCs; include non-negative number even if corresponding flag is 0")
774#endif
775  ;
776 
777  for(Int i=1; i<MAX_GOP+1; i++) {
778    std::ostringstream cOSS;
779    cOSS<<"Frame"<<i;
780    opts.addOptions()(cOSS.str(), m_GOPList[i-1], GOPEntry());
781  }
782  po::setDefaults(opts);
783  const list<const Char*>& argv_unhandled = po::scanArgv(opts, argc, (const Char**) argv);
784
785  for (list<const Char*>::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++)
786  {
787    fprintf(stderr, "Unhandled argument ignored: `%s'\n", *it);
788  }
789 
790  if (argc == 1 || do_help)
791  {
792    /* argc == 1: no options have been specified */
793    po::doHelp(cout, opts);
794    return false;
795  }
796 
797  /*
798   * Set any derived parameters
799   */
800  /* convert std::string to c string for compatability */
801#if SVC_EXTENSION
802#if AVC_BASE
803  if( m_avcBaseLayerFlag )
804  {
805    *cfg_InputFile[0] = cfg_BLInputFile;
806  }
807#endif
808  m_pBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str());
809#if AVC_SYNTAX
810  m_BLSyntaxFile = cfg_BLSyntaxFile.empty() ? NULL : strdup(cfg_BLSyntaxFile.c_str());
811#endif
812#else
813  m_pchInputFile = cfg_InputFile.empty() ? NULL : strdup(cfg_InputFile.c_str());
814  m_pchBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str());
815  m_pchReconFile = cfg_ReconFile.empty() ? NULL : strdup(cfg_ReconFile.c_str());
816  m_pchdQPFile = cfg_dQPFile.empty() ? NULL : strdup(cfg_dQPFile.c_str());
817#endif 
818
819  Char* pColumnWidth = cfg_ColumnWidth.empty() ? NULL: strdup(cfg_ColumnWidth.c_str());
820  Char* pRowHeight = cfg_RowHeight.empty() ? NULL : strdup(cfg_RowHeight.c_str());
821  if( m_iUniformSpacingIdr == 0 && m_iNumColumnsMinus1 > 0 )
822  {
823    char *columnWidth;
824    int  i=0;
825    m_pColumnWidth = new UInt[m_iNumColumnsMinus1];
826    columnWidth = strtok(pColumnWidth, " ,-");
827    while(columnWidth!=NULL)
828    {
829      if( i>=m_iNumColumnsMinus1 )
830      {
831        printf( "The number of columns whose width are defined is larger than the allowed number of columns.\n" );
832        exit( EXIT_FAILURE );
833      }
834      *( m_pColumnWidth + i ) = atoi( columnWidth );
835      columnWidth = strtok(NULL, " ,-");
836      i++;
837    }
838    if( i<m_iNumColumnsMinus1 )
839    {
840      printf( "The width of some columns is not defined.\n" );
841      exit( EXIT_FAILURE );
842    }
843  }
844  else
845  {
846    m_pColumnWidth = NULL;
847  }
848
849  if( m_iUniformSpacingIdr == 0 && m_iNumRowsMinus1 > 0 )
850  {
851    char *rowHeight;
852    int  i=0;
853    m_pRowHeight = new UInt[m_iNumRowsMinus1];
854    rowHeight = strtok(pRowHeight, " ,-");
855    while(rowHeight!=NULL)
856    {
857      if( i>=m_iNumRowsMinus1 )
858      {
859        printf( "The number of rows whose height are defined is larger than the allowed number of rows.\n" );
860        exit( EXIT_FAILURE );
861      }
862      *( m_pRowHeight + i ) = atoi( rowHeight );
863      rowHeight = strtok(NULL, " ,-");
864      i++;
865    }
866    if( i<m_iNumRowsMinus1 )
867    {
868      printf( "The height of some rows is not defined.\n" );
869      exit( EXIT_FAILURE );
870   }
871  }
872  else
873  {
874    m_pRowHeight = NULL;
875  }
876#if VPS_EXTN_DIRECT_REF_LAYERS
877  for(Int layer = 0; layer < MAX_LAYERS; layer++)
878  {
879    Char* pRefLayerIds = cfg_refLayerIds[layer].empty() ? NULL: strdup(cfg_refLayerIds[layer].c_str());
880    if( m_acLayerCfg[layer].m_numDirectRefLayers > 0 )
881    {
882      char *refLayerId;
883      int  i=0;
884      m_acLayerCfg[layer].m_refLayerIds = new Int[m_acLayerCfg[layer].m_numDirectRefLayers];
885      refLayerId = strtok(pRefLayerIds, " ,-");
886      while(refLayerId != NULL)
887      {
888        if( i >= m_acLayerCfg[layer].m_numDirectRefLayers )
889        {
890          printf( "The number of columns whose width are defined is larger than the allowed number of columns.\n" );
891          exit( EXIT_FAILURE );
892        }
893        *( m_acLayerCfg[layer].m_refLayerIds + i ) = atoi( refLayerId );
894        refLayerId = strtok(NULL, " ,-");
895        i++;
896      }
897      if( i < m_acLayerCfg[layer].m_numDirectRefLayers )
898      {
899        printf( "The width of some columns is not defined.\n" );
900        exit( EXIT_FAILURE );
901      }
902    }
903    else
904    {
905      m_acLayerCfg[layer].m_refLayerIds = NULL;
906    }
907  }
908#endif
909#if SIGNAL_BITRATE_PICRATE_IN_VPS
910  readBoolString(cfg_bitRateInfoPresentFlag, m_bitRatePicRateMaxTLayers, m_bitRateInfoPresentFlag, "bit rate info. present flag" );
911  readIntString (cfg_avgBitRate,             m_bitRatePicRateMaxTLayers, m_avgBitRate,             "avg. bit rate"               );
912  readIntString (cfg_maxBitRate,             m_bitRatePicRateMaxTLayers, m_maxBitRate,             "max. bit rate"               );
913  readBoolString(cfg_picRateInfoPresentFlag, m_bitRatePicRateMaxTLayers, m_picRateInfoPresentFlag, "bit rate info. present flag" );
914  readIntString (cfg_avgPicRate,             m_bitRatePicRateMaxTLayers, m_avgPicRate,             "avg. pic rate"               );
915  readIntString (cfg_constantPicRateIdc,     m_bitRatePicRateMaxTLayers, m_constantPicRateIdc,     "constant pic rate Idc"       );
916#endif
917  m_scalingListFile = cfg_ScalingListFile.empty() ? NULL : strdup(cfg_ScalingListFile.c_str());
918 
919  /* rules for input, output and internal bitdepths as per help text */
920  if (!m_internalBitDepthY) { m_internalBitDepthY = m_inputBitDepthY; }
921  if (!m_internalBitDepthC) { m_internalBitDepthC = m_internalBitDepthY; }
922  if (!m_inputBitDepthC) { m_inputBitDepthC = m_inputBitDepthY; }
923  if (!m_outputBitDepthY) { m_outputBitDepthY = m_internalBitDepthY; }
924  if (!m_outputBitDepthC) { m_outputBitDepthC = m_internalBitDepthC; }
925
926#if !SVC_EXTENSION
927  // TODO:ChromaFmt assumes 4:2:0 below
928  switch (m_conformanceMode)
929  {
930  case 0:
931    {
932      // no conformance or padding
933      m_confLeft = m_confRight = m_confTop = m_confBottom = 0;
934      m_aiPad[1] = m_aiPad[0] = 0;
935      break;
936    }
937  case 1:
938    {
939      // automatic padding to minimum CU size
940      Int minCuSize = m_uiMaxCUHeight >> (m_uiMaxCUDepth - 1);
941      if (m_iSourceWidth % minCuSize)
942      {
943        m_aiPad[0] = m_confRight  = ((m_iSourceWidth / minCuSize) + 1) * minCuSize - m_iSourceWidth;
944        m_iSourceWidth  += m_confRight;
945      }
946      if (m_iSourceHeight % minCuSize)
947      {
948        m_aiPad[1] = m_confBottom = ((m_iSourceHeight / minCuSize) + 1) * minCuSize - m_iSourceHeight;
949        m_iSourceHeight += m_confBottom;
950      }
951      if (m_aiPad[0] % TComSPS::getWinUnitX(CHROMA_420) != 0)
952      {
953        fprintf(stderr, "Error: picture width is not an integer multiple of the specified chroma subsampling\n");
954        exit(EXIT_FAILURE);
955      }
956      if (m_aiPad[1] % TComSPS::getWinUnitY(CHROMA_420) != 0)
957      {
958        fprintf(stderr, "Error: picture height is not an integer multiple of the specified chroma subsampling\n");
959        exit(EXIT_FAILURE);
960      }
961      break;
962    }
963  case 2:
964    {
965      //padding
966      m_iSourceWidth  += m_aiPad[0];
967      m_iSourceHeight += m_aiPad[1];
968      m_confRight  = m_aiPad[0];
969      m_confBottom = m_aiPad[1];
970      break;
971    }
972  case 3:
973    {
974      // conformance
975      if ((m_confLeft == 0) && (m_confRight == 0) && (m_confTop == 0) && (m_confBottom == 0))
976      {
977        fprintf(stderr, "Warning: Conformance window enabled, but all conformance window parameters set to zero\n");
978      }
979      if ((m_aiPad[1] != 0) || (m_aiPad[0]!=0))
980      {
981        fprintf(stderr, "Warning: Conformance window enabled, padding parameters will be ignored\n");
982      }
983      m_aiPad[1] = m_aiPad[0] = 0;
984      break;
985    }
986  }
987 
988  // allocate slice-based dQP values
989  m_aidQP = new Int[ m_framesToBeEncoded + m_iGOPSize + 1 ];
990  ::memset( m_aidQP, 0, sizeof(Int)*( m_framesToBeEncoded + m_iGOPSize + 1 ) );
991 
992  // handling of floating-point QP values
993  // if QP is not integer, sequence is split into two sections having QP and QP+1
994  m_iQP = (Int)( m_fQP );
995  if ( m_iQP < m_fQP )
996  {
997    Int iSwitchPOC = (Int)( m_framesToBeEncoded - (m_fQP - m_iQP)*m_framesToBeEncoded + 0.5 );
998   
999    iSwitchPOC = (Int)( (Double)iSwitchPOC / m_iGOPSize + 0.5 )*m_iGOPSize;
1000    for ( Int i=iSwitchPOC; i<m_framesToBeEncoded + m_iGOPSize + 1; i++ )
1001    {
1002      m_aidQP[i] = 1;
1003    }
1004  }
1005 
1006  // reading external dQP description from file
1007  if ( m_pchdQPFile )
1008  {
1009    FILE* fpt=fopen( m_pchdQPFile, "r" );
1010    if ( fpt )
1011    {
1012      Int iValue;
1013      Int iPOC = 0;
1014      while ( iPOC < m_framesToBeEncoded )
1015      {
1016        if ( fscanf(fpt, "%d", &iValue ) == EOF ) break;
1017        m_aidQP[ iPOC ] = iValue;
1018        iPOC++;
1019      }
1020      fclose(fpt);
1021    }
1022  }
1023  m_iWaveFrontSubstreams = m_iWaveFrontSynchro ? (m_iSourceHeight + m_uiMaxCUHeight - 1) / m_uiMaxCUHeight : 1;
1024#endif
1025#if J0149_TONE_MAPPING_SEI
1026  if( m_toneMappingInfoSEIEnabled && !m_toneMapCancelFlag )
1027  {
1028    Char* pcStartOfCodedInterval = cfg_startOfCodedInterval.empty() ? NULL: strdup(cfg_startOfCodedInterval.c_str());
1029    Char* pcCodedPivotValue = cfg_codedPivotValue.empty() ? NULL: strdup(cfg_codedPivotValue.c_str());
1030    Char* pcTargetPivotValue = cfg_targetPivotValue.empty() ? NULL: strdup(cfg_targetPivotValue.c_str());
1031    if( m_toneMapModelId == 2 && pcStartOfCodedInterval )
1032    {
1033      char *startOfCodedInterval;
1034      UInt num = 1u<< m_toneMapTargetBitDepth;
1035      m_startOfCodedInterval = new Int[num];
1036      ::memset( m_startOfCodedInterval, 0, sizeof(Int)*num );
1037      startOfCodedInterval = strtok(pcStartOfCodedInterval, " .");
1038      int i = 0;
1039      while( startOfCodedInterval && ( i < num ) )
1040      {
1041        m_startOfCodedInterval[i] = atoi( startOfCodedInterval );
1042        startOfCodedInterval = strtok(NULL, " .");
1043        i++;
1044      }
1045    } 
1046    else
1047    {
1048      m_startOfCodedInterval = NULL;
1049    }
1050    if( ( m_toneMapModelId == 3 ) && ( m_numPivots > 0 ) )
1051    {
1052      if( pcCodedPivotValue && pcTargetPivotValue )
1053      {
1054        char *codedPivotValue;
1055        char *targetPivotValue;
1056        m_codedPivotValue = new Int[m_numPivots];
1057        m_targetPivotValue = new Int[m_numPivots];
1058        ::memset( m_codedPivotValue, 0, sizeof(Int)*( m_numPivots ) );
1059        ::memset( m_targetPivotValue, 0, sizeof(Int)*( m_numPivots ) );
1060        codedPivotValue = strtok(pcCodedPivotValue, " .");
1061        int i=0;
1062        while(codedPivotValue&&i<m_numPivots)
1063        {
1064          m_codedPivotValue[i] = atoi( codedPivotValue );
1065          codedPivotValue = strtok(NULL, " .");
1066          i++;
1067        }
1068        i=0;
1069        targetPivotValue = strtok(pcTargetPivotValue, " .");
1070        while(targetPivotValue&&i<m_numPivots)
1071        {
1072          m_targetPivotValue[i]= atoi( targetPivotValue );
1073          targetPivotValue = strtok(NULL, " .");
1074          i++;
1075        }
1076      }
1077    }
1078    else
1079    {
1080      m_codedPivotValue = NULL;
1081      m_targetPivotValue = NULL;
1082    }
1083  }
1084#endif
1085  // check validity of input parameters
1086  xCheckParameter();
1087 
1088  // set global varibles
1089  xSetGlobal();
1090 
1091  // print-out parameters
1092  xPrintParameter();
1093 
1094  return true;
1095}
1096#if SIGNAL_BITRATE_PICRATE_IN_VPS
1097Void readBoolString(const string inpString, const Int numEntries, Bool* &memberArray, const char *elementName)
1098{
1099  Char* inpArray = inpString.empty() ? NULL : strdup(inpString.c_str());
1100  Int i = 0;
1101  if(numEntries)
1102  {
1103    Char* tempArray = strtok(inpArray, " ,-");
1104    memberArray = new Bool[numEntries];
1105    while( tempArray != NULL )
1106    {
1107      if( i >= numEntries )
1108      {
1109        printf( "The number of %s defined is larger than the allowed number\n", elementName );
1110        exit( EXIT_FAILURE );
1111      }
1112      assert( (atoi(tempArray) == 0) || (atoi(tempArray) == 1) );
1113      *( memberArray + i ) = atoi(tempArray);
1114      tempArray = strtok(NULL, " ,-");
1115      i++;
1116    }
1117    if( i < numEntries )
1118    {
1119      printf( "Some %s are not defined\n", elementName );
1120      exit( EXIT_FAILURE );
1121    }
1122  }
1123  else
1124  {
1125    memberArray = NULL;
1126  }
1127}
1128
1129Void readIntString(const string inpString, const Int numEntries, Int* &memberArray, const char *elementName)
1130{
1131  Char* inpArray = inpString.empty() ? NULL : strdup(inpString.c_str());
1132  Int i = 0;
1133  if(numEntries)
1134  {
1135    Char* tempArray = strtok(inpArray, " ,-");
1136    memberArray = new Int[numEntries];
1137    while( tempArray != NULL )
1138    {
1139      if( i >= numEntries )
1140      {
1141        printf( "The number of %s defined is larger than the allowed number\n", elementName );
1142        exit( EXIT_FAILURE );
1143      }
1144      *( memberArray + i ) = atoi(tempArray);
1145      tempArray = strtok(NULL, " ,-");
1146      i++;
1147    }
1148    if( i < numEntries )
1149    {
1150      printf( "Some %s are not defined\n", elementName );
1151      exit( EXIT_FAILURE );
1152    }
1153  }
1154  else
1155  {
1156    memberArray = NULL;
1157  }
1158}
1159#endif
1160// ====================================================================================================================
1161// Private member functions
1162// ====================================================================================================================
1163
1164Bool confirmPara(Bool bflag, const Char* message);
1165
1166Void TAppEncCfg::xCheckParameter()
1167{
1168  if (!m_decodedPictureHashSEIEnabled)
1169  {
1170    fprintf(stderr, "******************************************************************\n");
1171    fprintf(stderr, "** WARNING: --SEIDecodedPictureHash is now disabled by default. **\n");
1172    fprintf(stderr, "**          Automatic verification of decoded pictures by a     **\n");
1173    fprintf(stderr, "**          decoder requires this option to be enabled.         **\n");
1174    fprintf(stderr, "******************************************************************\n");
1175  }
1176
1177  Bool check_failed = false; /* abort if there is a fatal configuration problem */
1178#define xConfirmPara(a,b) check_failed |= confirmPara(a,b)
1179  // check range of parameters
1180  xConfirmPara( m_inputBitDepthY < 8,                                                     "InputBitDepth must be at least 8" );
1181  xConfirmPara( m_inputBitDepthC < 8,                                                     "InputBitDepthC must be at least 8" );
1182#if !SVC_EXTENSION 
1183  xConfirmPara( m_iFrameRate <= 0,                                                          "Frame rate must be more than 1" );
1184#endif
1185  xConfirmPara( m_framesToBeEncoded <= 0,                                                   "Total Number Of Frames encoded must be more than 0" );
1186  xConfirmPara( m_iGOPSize < 1 ,                                                            "GOP Size must be greater or equal to 1" );
1187  xConfirmPara( m_iGOPSize > 1 &&  m_iGOPSize % 2,                                          "GOP Size must be a multiple of 2, if GOP Size is greater than 1" );
1188#if !SVC_EXTENSION
1189  xConfirmPara( (m_iIntraPeriod > 0 && m_iIntraPeriod < m_iGOPSize) || m_iIntraPeriod == 0, "Intra period must be more than GOP size, or -1 , not 0" );
1190#endif
1191  xConfirmPara( m_iDecodingRefreshType < 0 || m_iDecodingRefreshType > 2,                   "Decoding Refresh Type must be equal to 0, 1 or 2" );
1192#if !SVC_EXTENSION
1193  xConfirmPara( m_iQP <  -6 * (m_internalBitDepthY - 8) || m_iQP > 51,                    "QP exceeds supported range (-QpBDOffsety to 51)" );
1194#endif
1195  xConfirmPara( m_loopFilterBetaOffsetDiv2 < -13 || m_loopFilterBetaOffsetDiv2 > 13,          "Loop Filter Beta Offset div. 2 exceeds supported range (-13 to 13)");
1196  xConfirmPara( m_loopFilterTcOffsetDiv2 < -13 || m_loopFilterTcOffsetDiv2 > 13,              "Loop Filter Tc Offset div. 2 exceeds supported range (-13 to 13)");
1197  xConfirmPara( m_iFastSearch < 0 || m_iFastSearch > 2,                                     "Fast Search Mode is not supported value (0:Full search  1:Diamond  2:PMVFAST)" );
1198  xConfirmPara( m_iSearchRange < 0 ,                                                        "Search Range must be more than 0" );
1199  xConfirmPara( m_bipredSearchRange < 0 ,                                                   "Search Range must be more than 0" );
1200  xConfirmPara( m_iMaxDeltaQP > 7,                                                          "Absolute Delta QP exceeds supported range (0 to 7)" );
1201  xConfirmPara( m_iMaxCuDQPDepth > m_uiMaxCUDepth - 1,                                          "Absolute depth for a minimum CuDQP exceeds maximum coding unit depth" );
1202
1203  xConfirmPara( m_cbQpOffset < -12,   "Min. Chroma Cb QP Offset is -12" );
1204  xConfirmPara( m_cbQpOffset >  12,   "Max. Chroma Cb QP Offset is  12" );
1205  xConfirmPara( m_crQpOffset < -12,   "Min. Chroma Cr QP Offset is -12" );
1206  xConfirmPara( m_crQpOffset >  12,   "Max. Chroma Cr QP Offset is  12" );
1207
1208  xConfirmPara( m_iQPAdaptationRange <= 0,                                                  "QP Adaptation Range must be more than 0" );
1209#if !SVC_EXTENSION
1210  if (m_iDecodingRefreshType == 2)
1211  {
1212    xConfirmPara( m_iIntraPeriod > 0 && m_iIntraPeriod <= m_iGOPSize ,                      "Intra period must be larger than GOP size for periodic IDR pictures");
1213  }
1214#endif
1215  xConfirmPara( (m_uiMaxCUWidth  >> m_uiMaxCUDepth) < 4,                                    "Minimum partition width size should be larger than or equal to 8");
1216  xConfirmPara( (m_uiMaxCUHeight >> m_uiMaxCUDepth) < 4,                                    "Minimum partition height size should be larger than or equal to 8");
1217  xConfirmPara( m_uiMaxCUWidth < 16,                                                        "Maximum partition width size should be larger than or equal to 16");
1218  xConfirmPara( m_uiMaxCUHeight < 16,                                                       "Maximum partition height size should be larger than or equal to 16");
1219#if !SVC_EXTENSION
1220  xConfirmPara( (m_iSourceWidth  % (m_uiMaxCUWidth  >> (m_uiMaxCUDepth-1)))!=0,             "Resulting coded frame width must be a multiple of the minimum CU size");
1221  xConfirmPara( (m_iSourceHeight % (m_uiMaxCUHeight >> (m_uiMaxCUDepth-1)))!=0,             "Resulting coded frame height must be a multiple of the minimum CU size");
1222#endif
1223 
1224  xConfirmPara( m_uiQuadtreeTULog2MinSize < 2,                                        "QuadtreeTULog2MinSize must be 2 or greater.");
1225  xConfirmPara( m_uiQuadtreeTULog2MaxSize > 5,                                        "QuadtreeTULog2MaxSize must be 5 or smaller.");
1226  xConfirmPara( (1<<m_uiQuadtreeTULog2MaxSize) > m_uiMaxCUWidth,                                        "QuadtreeTULog2MaxSize must be log2(maxCUSize) or smaller.");
1227 
1228  xConfirmPara( m_uiQuadtreeTULog2MaxSize < m_uiQuadtreeTULog2MinSize,                "QuadtreeTULog2MaxSize must be greater than or equal to m_uiQuadtreeTULog2MinSize.");
1229  xConfirmPara( (1<<m_uiQuadtreeTULog2MinSize)>(m_uiMaxCUWidth >>(m_uiMaxCUDepth-1)), "QuadtreeTULog2MinSize must not be greater than minimum CU size" ); // HS
1230  xConfirmPara( (1<<m_uiQuadtreeTULog2MinSize)>(m_uiMaxCUHeight>>(m_uiMaxCUDepth-1)), "QuadtreeTULog2MinSize must not be greater than minimum CU size" ); // HS
1231  xConfirmPara( ( 1 << m_uiQuadtreeTULog2MinSize ) > ( m_uiMaxCUWidth  >> m_uiMaxCUDepth ), "Minimum CU width must be greater than minimum transform size." );
1232  xConfirmPara( ( 1 << m_uiQuadtreeTULog2MinSize ) > ( m_uiMaxCUHeight >> m_uiMaxCUDepth ), "Minimum CU height must be greater than minimum transform size." );
1233  xConfirmPara( m_uiQuadtreeTUMaxDepthInter < 1,                                                         "QuadtreeTUMaxDepthInter must be greater than or equal to 1" );
1234  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" );
1235  xConfirmPara( m_uiQuadtreeTUMaxDepthIntra < 1,                                                         "QuadtreeTUMaxDepthIntra must be greater than or equal to 1" );
1236  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" );
1237 
1238  xConfirmPara(  m_maxNumMergeCand < 1,  "MaxNumMergeCand must be 1 or greater.");
1239  xConfirmPara(  m_maxNumMergeCand > 5,  "MaxNumMergeCand must be 5 or smaller.");
1240
1241#if !SVC_EXTENSION
1242#if ADAPTIVE_QP_SELECTION
1243  xConfirmPara( m_bUseAdaptQpSelect == true && m_iQP < 0,                                              "AdaptiveQpSelection must be disabled when QP < 0.");
1244  xConfirmPara( m_bUseAdaptQpSelect == true && (m_cbQpOffset !=0 || m_crQpOffset != 0 ),               "AdaptiveQpSelection must be disabled when ChromaQpOffset is not equal to 0.");
1245#endif
1246#endif
1247
1248  if( m_usePCM)
1249  {
1250    xConfirmPara(  m_uiPCMLog2MinSize < 3,                                      "PCMLog2MinSize must be 3 or greater.");
1251    xConfirmPara(  m_uiPCMLog2MinSize > 5,                                      "PCMLog2MinSize must be 5 or smaller.");
1252    xConfirmPara(  m_pcmLog2MaxSize > 5,                                        "PCMLog2MaxSize must be 5 or smaller.");
1253    xConfirmPara(  m_pcmLog2MaxSize < m_uiPCMLog2MinSize,                       "PCMLog2MaxSize must be equal to or greater than m_uiPCMLog2MinSize.");
1254  }
1255
1256  xConfirmPara( m_sliceMode < 0 || m_sliceMode > 3, "SliceMode exceeds supported range (0 to 3)" );
1257  if (m_sliceMode!=0)
1258  {
1259    xConfirmPara( m_sliceArgument < 1 ,         "SliceArgument should be larger than or equal to 1" );
1260  }
1261  xConfirmPara( m_sliceSegmentMode < 0 || m_sliceSegmentMode > 3, "SliceSegmentMode exceeds supported range (0 to 3)" );
1262  if (m_sliceSegmentMode!=0)
1263  {
1264    xConfirmPara( m_sliceSegmentArgument < 1 ,         "SliceSegmentArgument should be larger than or equal to 1" );
1265  }
1266 
1267  Bool tileFlag = (m_iNumColumnsMinus1 > 0 || m_iNumRowsMinus1 > 0 );
1268  xConfirmPara( tileFlag && m_iWaveFrontSynchro,            "Tile and Wavefront can not be applied together");
1269
1270  //TODO:ChromaFmt assumes 4:2:0 below
1271#if !SVC_EXTENSION
1272  xConfirmPara( m_iSourceWidth  % TComSPS::getWinUnitX(CHROMA_420) != 0, "Picture width must be an integer multiple of the specified chroma subsampling");
1273  xConfirmPara( m_iSourceHeight % TComSPS::getWinUnitY(CHROMA_420) != 0, "Picture height must be an integer multiple of the specified chroma subsampling");
1274
1275  xConfirmPara( m_aiPad[0] % TComSPS::getWinUnitX(CHROMA_420) != 0, "Horizontal padding must be an integer multiple of the specified chroma subsampling");
1276  xConfirmPara( m_aiPad[1] % TComSPS::getWinUnitY(CHROMA_420) != 0, "Vertical padding must be an integer multiple of the specified chroma subsampling");
1277
1278  xConfirmPara( m_confLeft   % TComSPS::getWinUnitX(CHROMA_420) != 0, "Left conformance window offset must be an integer multiple of the specified chroma subsampling");
1279  xConfirmPara( m_confRight  % TComSPS::getWinUnitX(CHROMA_420) != 0, "Right conformance window offset must be an integer multiple of the specified chroma subsampling");
1280  xConfirmPara( m_confTop    % TComSPS::getWinUnitY(CHROMA_420) != 0, "Top conformance window offset must be an integer multiple of the specified chroma subsampling");
1281  xConfirmPara( m_confBottom % TComSPS::getWinUnitY(CHROMA_420) != 0, "Bottom conformance window offset must be an integer multiple of the specified chroma subsampling");
1282#endif
1283
1284  // max CU width and height should be power of 2
1285  UInt ui = m_uiMaxCUWidth;
1286  while(ui)
1287  {
1288    ui >>= 1;
1289    if( (ui & 1) == 1)
1290      xConfirmPara( ui != 1 , "Width should be 2^n");
1291  }
1292  ui = m_uiMaxCUHeight;
1293  while(ui)
1294  {
1295    ui >>= 1;
1296    if( (ui & 1) == 1)
1297      xConfirmPara( ui != 1 , "Height should be 2^n");
1298  }
1299
1300
1301  /* if this is an intra-only sequence, ie IntraPeriod=1, don't verify the GOP structure
1302   * This permits the ability to omit a GOP structure specification */
1303#if SVC_EXTENSION
1304  for(UInt layer = 0; layer < MAX_LAYERS; layer++)
1305  {
1306    Int m_iIntraPeriod = m_acLayerCfg[layer].m_iIntraPeriod;
1307#endif
1308  if (m_iIntraPeriod == 1 && m_GOPList[0].m_POC == -1) {
1309    m_GOPList[0] = GOPEntry();
1310    m_GOPList[0].m_QPFactor = 1;
1311    m_GOPList[0].m_betaOffsetDiv2 = 0;
1312    m_GOPList[0].m_tcOffsetDiv2 = 0;
1313    m_GOPList[0].m_POC = 1;
1314    m_GOPList[0].m_numRefPicsActive = 4;
1315  }
1316#if SVC_EXTENSION
1317  }
1318#endif
1319 
1320  Bool verifiedGOP=false;
1321  Bool errorGOP=false;
1322  Int checkGOP=1;
1323  Int numRefs = 1;
1324  Int refList[MAX_NUM_REF_PICS+1];
1325  refList[0]=0;
1326  Bool isOK[MAX_GOP];
1327  for(Int i=0; i<MAX_GOP; i++) 
1328  {
1329    isOK[i]=false;
1330  }
1331  Int numOK=0;
1332#if !SVC_EXTENSION
1333  xConfirmPara( m_iIntraPeriod >=0&&(m_iIntraPeriod%m_iGOPSize!=0), "Intra period must be a multiple of GOPSize, or -1" );
1334#endif
1335
1336  for(Int i=0; i<m_iGOPSize; i++)
1337  {
1338    if(m_GOPList[i].m_POC==m_iGOPSize)
1339    {
1340      xConfirmPara( m_GOPList[i].m_temporalId!=0 , "The last frame in each GOP must have temporal ID = 0 " );
1341    }
1342  }
1343
1344#if SVC_EXTENSION
1345  xConfirmPara( m_numLayers > MAX_LAYERS , "Number of layers in config file is greater than MAX_LAYERS" );
1346  m_numLayers = m_numLayers > MAX_LAYERS ? MAX_LAYERS : m_numLayers;
1347
1348  // verify layer configuration parameters
1349  for(UInt layer=0; layer<m_numLayers; layer++)
1350  {
1351    if(m_acLayerCfg[layer].xCheckParameter())
1352    {
1353      printf("\nError: invalid configuration parameter found in layer %d \n", layer);
1354      check_failed = true;
1355    }
1356  }
1357#endif 
1358
1359#if SVC_EXTENSION
1360  // verify layer configuration parameters
1361  for(UInt layer=0; layer<m_numLayers; layer++)
1362  {
1363    Int m_iIntraPeriod = m_acLayerCfg[layer].m_iIntraPeriod;
1364#endif
1365  if ( (m_iIntraPeriod != 1) && !m_loopFilterOffsetInPPS && m_DeblockingFilterControlPresent && (!m_bLoopFilterDisable) )
1366  {
1367    for(Int i=0; i<m_iGOPSize; i++)
1368    {
1369      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)" );
1370      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)" );
1371    }
1372  }
1373#if SVC_EXTENSION
1374  }
1375#endif
1376
1377  m_extraRPSs=0;
1378  //start looping through frames in coding order until we can verify that the GOP structure is correct.
1379  while(!verifiedGOP&&!errorGOP) 
1380  {
1381    Int curGOP = (checkGOP-1)%m_iGOPSize;
1382    Int curPOC = ((checkGOP-1)/m_iGOPSize)*m_iGOPSize + m_GOPList[curGOP].m_POC;   
1383    if(m_GOPList[curGOP].m_POC<0) 
1384    {
1385      printf("\nError: found fewer Reference Picture Sets than GOPSize\n");
1386      errorGOP=true;
1387    }
1388    else 
1389    {
1390      //check that all reference pictures are available, or have a POC < 0 meaning they might be available in the next GOP.
1391      Bool beforeI = false;
1392      for(Int i = 0; i< m_GOPList[curGOP].m_numRefPics; i++) 
1393      {
1394        Int absPOC = curPOC+m_GOPList[curGOP].m_referencePics[i];
1395        if(absPOC < 0)
1396        {
1397          beforeI=true;
1398        }
1399        else 
1400        {
1401          Bool found=false;
1402          for(Int j=0; j<numRefs; j++) 
1403          {
1404            if(refList[j]==absPOC) 
1405            {
1406              found=true;
1407              for(Int k=0; k<m_iGOPSize; k++)
1408              {
1409                if(absPOC%m_iGOPSize == m_GOPList[k].m_POC%m_iGOPSize)
1410                {
1411                  if(m_GOPList[k].m_temporalId==m_GOPList[curGOP].m_temporalId)
1412                  {
1413                    m_GOPList[k].m_refPic = true;
1414                  }
1415                  m_GOPList[curGOP].m_usedByCurrPic[i]=m_GOPList[k].m_temporalId<=m_GOPList[curGOP].m_temporalId;
1416                }
1417              }
1418            }
1419          }
1420          if(!found)
1421          {
1422            printf("\nError: ref pic %d is not available for GOP frame %d\n",m_GOPList[curGOP].m_referencePics[i],curGOP+1);
1423            errorGOP=true;
1424          }
1425        }
1426      }
1427      if(!beforeI&&!errorGOP)
1428      {
1429        //all ref frames were present
1430        if(!isOK[curGOP]) 
1431        {
1432          numOK++;
1433          isOK[curGOP]=true;
1434          if(numOK==m_iGOPSize)
1435          {
1436            verifiedGOP=true;
1437          }
1438        }
1439      }
1440      else 
1441      {
1442        //create a new GOPEntry for this frame containing all the reference pictures that were available (POC > 0)
1443        m_GOPList[m_iGOPSize+m_extraRPSs]=m_GOPList[curGOP];
1444        Int newRefs=0;
1445        for(Int i = 0; i< m_GOPList[curGOP].m_numRefPics; i++) 
1446        {
1447          Int absPOC = curPOC+m_GOPList[curGOP].m_referencePics[i];
1448          if(absPOC>=0)
1449          {
1450            m_GOPList[m_iGOPSize+m_extraRPSs].m_referencePics[newRefs]=m_GOPList[curGOP].m_referencePics[i];
1451            m_GOPList[m_iGOPSize+m_extraRPSs].m_usedByCurrPic[newRefs]=m_GOPList[curGOP].m_usedByCurrPic[i];
1452            newRefs++;
1453          }
1454        }
1455        Int numPrefRefs = m_GOPList[curGOP].m_numRefPicsActive;
1456       
1457        for(Int offset = -1; offset>-checkGOP; offset--)
1458        {
1459          //step backwards in coding order and include any extra available pictures we might find useful to replace the ones with POC < 0.
1460          Int offGOP = (checkGOP-1+offset)%m_iGOPSize;
1461          Int offPOC = ((checkGOP-1+offset)/m_iGOPSize)*m_iGOPSize + m_GOPList[offGOP].m_POC;
1462          if(offPOC>=0&&m_GOPList[offGOP].m_temporalId<=m_GOPList[curGOP].m_temporalId)
1463          {
1464            Bool newRef=false;
1465            for(Int i=0; i<numRefs; i++)
1466            {
1467              if(refList[i]==offPOC)
1468              {
1469                newRef=true;
1470              }
1471            }
1472            for(Int i=0; i<newRefs; i++) 
1473            {
1474              if(m_GOPList[m_iGOPSize+m_extraRPSs].m_referencePics[i]==offPOC-curPOC)
1475              {
1476                newRef=false;
1477              }
1478            }
1479            if(newRef) 
1480            {
1481              Int insertPoint=newRefs;
1482              //this picture can be added, find appropriate place in list and insert it.
1483              if(m_GOPList[offGOP].m_temporalId==m_GOPList[curGOP].m_temporalId)
1484              {
1485                m_GOPList[offGOP].m_refPic = true;
1486              }
1487              for(Int j=0; j<newRefs; j++)
1488              {
1489                if(m_GOPList[m_iGOPSize+m_extraRPSs].m_referencePics[j]<offPOC-curPOC||m_GOPList[m_iGOPSize+m_extraRPSs].m_referencePics[j]>0)
1490                {
1491                  insertPoint = j;
1492                  break;
1493                }
1494              }
1495              Int prev = offPOC-curPOC;
1496              Int prevUsed = m_GOPList[offGOP].m_temporalId<=m_GOPList[curGOP].m_temporalId;
1497              for(Int j=insertPoint; j<newRefs+1; j++)
1498              {
1499                Int newPrev = m_GOPList[m_iGOPSize+m_extraRPSs].m_referencePics[j];
1500                Int newUsed = m_GOPList[m_iGOPSize+m_extraRPSs].m_usedByCurrPic[j];
1501                m_GOPList[m_iGOPSize+m_extraRPSs].m_referencePics[j]=prev;
1502                m_GOPList[m_iGOPSize+m_extraRPSs].m_usedByCurrPic[j]=prevUsed;
1503                prevUsed=newUsed;
1504                prev=newPrev;
1505              }
1506              newRefs++;
1507            }
1508          }
1509          if(newRefs>=numPrefRefs)
1510          {
1511            break;
1512          }
1513        }
1514        m_GOPList[m_iGOPSize+m_extraRPSs].m_numRefPics=newRefs;
1515        m_GOPList[m_iGOPSize+m_extraRPSs].m_POC = curPOC;
1516        if (m_extraRPSs == 0)
1517        {
1518          m_GOPList[m_iGOPSize+m_extraRPSs].m_interRPSPrediction = 0;
1519          m_GOPList[m_iGOPSize+m_extraRPSs].m_numRefIdc = 0;
1520        }
1521        else
1522        {
1523          Int rIdx =  m_iGOPSize + m_extraRPSs - 1;
1524          Int refPOC = m_GOPList[rIdx].m_POC;
1525          Int refPics = m_GOPList[rIdx].m_numRefPics;
1526          Int newIdc=0;
1527          for(Int i = 0; i<= refPics; i++) 
1528          {
1529            Int deltaPOC = ((i != refPics)? m_GOPList[rIdx].m_referencePics[i] : 0);  // check if the reference abs POC is >= 0
1530            Int absPOCref = refPOC+deltaPOC;
1531            Int refIdc = 0;
1532            for (Int j = 0; j < m_GOPList[m_iGOPSize+m_extraRPSs].m_numRefPics; j++)
1533            {
1534              if ( (absPOCref - curPOC) == m_GOPList[m_iGOPSize+m_extraRPSs].m_referencePics[j])
1535              {
1536                if (m_GOPList[m_iGOPSize+m_extraRPSs].m_usedByCurrPic[j])
1537                {
1538                  refIdc = 1;
1539                }
1540                else
1541                {
1542                  refIdc = 2;
1543                }
1544              }
1545            }
1546            m_GOPList[m_iGOPSize+m_extraRPSs].m_refIdc[newIdc]=refIdc;
1547            newIdc++;
1548          }
1549          m_GOPList[m_iGOPSize+m_extraRPSs].m_interRPSPrediction = 1; 
1550          m_GOPList[m_iGOPSize+m_extraRPSs].m_numRefIdc = newIdc;
1551          m_GOPList[m_iGOPSize+m_extraRPSs].m_deltaRPS = refPOC - m_GOPList[m_iGOPSize+m_extraRPSs].m_POC; 
1552        }
1553        curGOP=m_iGOPSize+m_extraRPSs;
1554        m_extraRPSs++;
1555      }
1556      numRefs=0;
1557      for(Int i = 0; i< m_GOPList[curGOP].m_numRefPics; i++) 
1558      {
1559        Int absPOC = curPOC+m_GOPList[curGOP].m_referencePics[i];
1560        if(absPOC >= 0) 
1561        {
1562          refList[numRefs]=absPOC;
1563          numRefs++;
1564        }
1565      }
1566      refList[numRefs]=curPOC;
1567      numRefs++;
1568    }
1569    checkGOP++;
1570  }
1571  xConfirmPara(errorGOP,"Invalid GOP structure given");
1572  m_maxTempLayer = 1;
1573  for(Int i=0; i<m_iGOPSize; i++) 
1574  {
1575    if(m_GOPList[i].m_temporalId >= m_maxTempLayer)
1576    {
1577      m_maxTempLayer = m_GOPList[i].m_temporalId+1;
1578    }
1579    xConfirmPara(m_GOPList[i].m_sliceType!='B'&&m_GOPList[i].m_sliceType!='P', "Slice type must be equal to B or P");
1580  }
1581  for(Int i=0; i<MAX_TLAYER; i++)
1582  {
1583    m_numReorderPics[i] = 0;
1584#if L0323_DPB
1585    m_maxDecPicBuffering[i] = 1;
1586#else
1587    m_maxDecPicBuffering[i] = 0;
1588#endif
1589  }
1590  for(Int i=0; i<m_iGOPSize; i++) 
1591  {
1592#if L0323_DPB
1593    if(m_GOPList[i].m_numRefPics+1 > m_maxDecPicBuffering[m_GOPList[i].m_temporalId])
1594#else
1595    if(m_GOPList[i].m_numRefPics > m_maxDecPicBuffering[m_GOPList[i].m_temporalId])
1596#endif
1597    {
1598#if L0323_DPB
1599      m_maxDecPicBuffering[m_GOPList[i].m_temporalId] = m_GOPList[i].m_numRefPics + 1;
1600#else
1601      m_maxDecPicBuffering[m_GOPList[i].m_temporalId] = m_GOPList[i].m_numRefPics;
1602#endif
1603    }
1604    Int highestDecodingNumberWithLowerPOC = 0; 
1605    for(Int j=0; j<m_iGOPSize; j++)
1606    {
1607      if(m_GOPList[j].m_POC <= m_GOPList[i].m_POC)
1608      {
1609        highestDecodingNumberWithLowerPOC = j;
1610      }
1611    }
1612    Int numReorder = 0;
1613    for(Int j=0; j<highestDecodingNumberWithLowerPOC; j++)
1614    {
1615      if(m_GOPList[j].m_temporalId <= m_GOPList[i].m_temporalId && 
1616        m_GOPList[j].m_POC > m_GOPList[i].m_POC)
1617      {
1618        numReorder++;
1619      }
1620    }   
1621    if(numReorder > m_numReorderPics[m_GOPList[i].m_temporalId])
1622    {
1623      m_numReorderPics[m_GOPList[i].m_temporalId] = numReorder;
1624    }
1625  }
1626  for(Int i=0; i<MAX_TLAYER-1; i++) 
1627  {
1628    // a lower layer can not have higher value of m_numReorderPics than a higher layer
1629    if(m_numReorderPics[i+1] < m_numReorderPics[i])
1630    {
1631      m_numReorderPics[i+1] = m_numReorderPics[i];
1632    }
1633#if L0323_DPB
1634    // the value of num_reorder_pics[ i ] shall be in the range of 0 to max_dec_pic_buffering[ i ] - 1, inclusive
1635    if(m_numReorderPics[i] > m_maxDecPicBuffering[i] - 1)
1636    {
1637      m_maxDecPicBuffering[i] = m_numReorderPics[i] + 1;
1638    }
1639#else
1640    // the value of num_reorder_pics[ i ] shall be in the range of 0 to max_dec_pic_buffering[ i ], inclusive
1641    if(m_numReorderPics[i] > m_maxDecPicBuffering[i])
1642    {
1643      m_maxDecPicBuffering[i] = m_numReorderPics[i];
1644    }
1645#endif
1646    // a lower layer can not have higher value of m_uiMaxDecPicBuffering than a higher layer
1647    if(m_maxDecPicBuffering[i+1] < m_maxDecPicBuffering[i])
1648    {
1649      m_maxDecPicBuffering[i+1] = m_maxDecPicBuffering[i];
1650    }
1651  }
1652
1653
1654#if L0323_DPB
1655  // the value of num_reorder_pics[ i ] shall be in the range of 0 to max_dec_pic_buffering[ i ] -  1, inclusive
1656  if(m_numReorderPics[MAX_TLAYER-1] > m_maxDecPicBuffering[MAX_TLAYER-1] - 1)
1657  {
1658    m_maxDecPicBuffering[MAX_TLAYER-1] = m_numReorderPics[MAX_TLAYER-1] + 1;
1659  }
1660#else
1661  // the value of num_reorder_pics[ i ] shall be in the range of 0 to max_dec_pic_buffering[ i ], inclusive
1662  if(m_numReorderPics[MAX_TLAYER-1] > m_maxDecPicBuffering[MAX_TLAYER-1])
1663  {
1664    m_maxDecPicBuffering[MAX_TLAYER-1] = m_numReorderPics[MAX_TLAYER-1];
1665  }
1666#endif
1667
1668#if SVC_EXTENSION // ToDo: it should be checked for the case when parameters are different for the layers
1669  for(UInt layer = 0; layer < MAX_LAYERS; layer++)
1670  {
1671    Int m_iSourceWidth = m_acLayerCfg[layer].m_iSourceWidth;
1672    Int m_iSourceHeight = m_acLayerCfg[layer].m_iSourceHeight;
1673#endif
1674  if(m_vuiParametersPresentFlag && m_bitstreamRestrictionFlag)
1675  { 
1676    Int PicSizeInSamplesY =  m_iSourceWidth * m_iSourceHeight;
1677    if(tileFlag)
1678    {
1679      Int maxTileWidth = 0;
1680      Int maxTileHeight = 0;
1681      Int widthInCU = (m_iSourceWidth % m_uiMaxCUWidth) ? m_iSourceWidth/m_uiMaxCUWidth + 1: m_iSourceWidth/m_uiMaxCUWidth;
1682      Int heightInCU = (m_iSourceHeight % m_uiMaxCUHeight) ? m_iSourceHeight/m_uiMaxCUHeight + 1: m_iSourceHeight/m_uiMaxCUHeight;
1683      if(m_iUniformSpacingIdr)
1684      {
1685        maxTileWidth = m_uiMaxCUWidth*((widthInCU+m_iNumColumnsMinus1)/(m_iNumColumnsMinus1+1));
1686        maxTileHeight = m_uiMaxCUHeight*((heightInCU+m_iNumRowsMinus1)/(m_iNumRowsMinus1+1));
1687        // if only the last tile-row is one treeblock higher than the others
1688        // the maxTileHeight becomes smaller if the last row of treeblocks has lower height than the others
1689        if(!((heightInCU-1)%(m_iNumRowsMinus1+1)))
1690        {
1691          maxTileHeight = maxTileHeight - m_uiMaxCUHeight + (m_iSourceHeight % m_uiMaxCUHeight);
1692        }     
1693        // if only the last tile-column is one treeblock wider than the others
1694        // the maxTileWidth becomes smaller if the last column of treeblocks has lower width than the others   
1695        if(!((widthInCU-1)%(m_iNumColumnsMinus1+1)))
1696        {
1697          maxTileWidth = maxTileWidth - m_uiMaxCUWidth + (m_iSourceWidth % m_uiMaxCUWidth);
1698        }
1699      }
1700      else // not uniform spacing
1701      {
1702        if(m_iNumColumnsMinus1<1)
1703        {
1704          maxTileWidth = m_iSourceWidth;
1705        }
1706        else
1707        {
1708          Int accColumnWidth = 0;
1709          for(Int col=0; col<(m_iNumColumnsMinus1); col++)
1710          {
1711            maxTileWidth = m_pColumnWidth[col]>maxTileWidth ? m_pColumnWidth[col]:maxTileWidth;
1712            accColumnWidth += m_pColumnWidth[col];
1713          }
1714          maxTileWidth = (widthInCU-accColumnWidth)>maxTileWidth ? m_uiMaxCUWidth*(widthInCU-accColumnWidth):m_uiMaxCUWidth*maxTileWidth;
1715        }
1716        if(m_iNumRowsMinus1<1)
1717        {
1718          maxTileHeight = m_iSourceHeight;
1719        }
1720        else
1721        {
1722          Int accRowHeight = 0;
1723          for(Int row=0; row<(m_iNumRowsMinus1); row++)
1724          {
1725            maxTileHeight = m_pRowHeight[row]>maxTileHeight ? m_pRowHeight[row]:maxTileHeight;
1726            accRowHeight += m_pRowHeight[row];
1727          }
1728          maxTileHeight = (heightInCU-accRowHeight)>maxTileHeight ? m_uiMaxCUHeight*(heightInCU-accRowHeight):m_uiMaxCUHeight*maxTileHeight;
1729        }
1730      }
1731      Int maxSizeInSamplesY = maxTileWidth*maxTileHeight;
1732      m_minSpatialSegmentationIdc = 4*PicSizeInSamplesY/maxSizeInSamplesY-4;
1733    }
1734    else if(m_iWaveFrontSynchro)
1735    {
1736      m_minSpatialSegmentationIdc = 4*PicSizeInSamplesY/((2*m_iSourceHeight+m_iSourceWidth)*m_uiMaxCUHeight)-4;
1737    }
1738    else if(m_sliceMode == 1)
1739    {
1740      m_minSpatialSegmentationIdc = 4*PicSizeInSamplesY/(m_sliceArgument*m_uiMaxCUWidth*m_uiMaxCUHeight)-4;
1741    }
1742    else
1743    {
1744      m_minSpatialSegmentationIdc = 0;
1745    }
1746  }
1747#if SVC_EXTENSION
1748  }
1749#endif
1750#if !L0034_COMBINED_LIST_CLEANUP
1751  xConfirmPara( m_bUseLComb==false && m_numReorderPics[MAX_TLAYER-1]!=0, "ListCombination can only be 0 in low delay coding (more precisely when L0 and L1 are identical)" );  // Note however this is not the full necessary condition as ref_pic_list_combination_flag can only be 0 if L0 == L1.
1752#endif
1753  xConfirmPara( m_iWaveFrontSynchro < 0, "WaveFrontSynchro cannot be negative" );
1754#if !SVC_EXTENSION
1755  xConfirmPara( m_iWaveFrontSubstreams <= 0, "WaveFrontSubstreams must be positive" );
1756  xConfirmPara( m_iWaveFrontSubstreams > 1 && !m_iWaveFrontSynchro, "Must have WaveFrontSynchro > 0 in order to have WaveFrontSubstreams > 1" );
1757#endif
1758
1759  xConfirmPara( m_decodedPictureHashSEIEnabled<0 || m_decodedPictureHashSEIEnabled>3, "this hash type is not correct!\n");
1760
1761#if J0149_TONE_MAPPING_SEI
1762  if (m_toneMappingInfoSEIEnabled)
1763  {
1764    xConfirmPara( m_toneMapCodedDataBitDepth < 8 || m_toneMapCodedDataBitDepth > 14 , "SEIToneMapCodedDataBitDepth must be in rage 8 to 14");
1765    xConfirmPara( m_toneMapTargetBitDepth < 1 || (m_toneMapTargetBitDepth > 16 && m_toneMapTargetBitDepth < 255) , "SEIToneMapTargetBitDepth must be in rage 1 to 16 or equal to 255");
1766    xConfirmPara( m_toneMapModelId < 0 || m_toneMapModelId > 4 , "SEIToneMapModelId must be in rage 0 to 4");
1767    xConfirmPara( m_cameraIsoSpeedValue == 0, "SEIToneMapCameraIsoSpeedValue shall not be equal to 0");
1768    xConfirmPara( m_extendedRangeWhiteLevel < 100, "SEIToneMapExtendedRangeWhiteLevel should be greater than or equal to 100");
1769    xConfirmPara( m_nominalBlackLevelLumaCodeValue >= m_nominalWhiteLevelLumaCodeValue, "SEIToneMapNominalWhiteLevelLumaCodeValue shall be greater than SEIToneMapNominalBlackLevelLumaCodeValue");
1770    xConfirmPara( m_extendedWhiteLevelLumaCodeValue < m_nominalWhiteLevelLumaCodeValue, "SEIToneMapExtendedWhiteLevelLumaCodeValue shall be greater than or equal to SEIToneMapNominalWhiteLevelLumaCodeValue");
1771  }
1772#endif
1773
1774#if RATE_CONTROL_LAMBDA_DOMAIN
1775#if RC_SHVC_HARMONIZATION
1776  for ( Int layer=0; layer<m_numLayers; layer++ )
1777  {
1778    if ( m_acLayerCfg[layer].m_RCEnableRateControl )
1779    {
1780      if ( m_acLayerCfg[layer].m_RCForceIntraQP )
1781      {
1782        if ( m_acLayerCfg[layer].m_RCInitialQP == 0 )
1783        {
1784          printf( "\nInitial QP for rate control is not specified. Reset not to use force intra QP!" );
1785          m_acLayerCfg[layer].m_RCForceIntraQP = false;
1786        }
1787      }
1788    }
1789    xConfirmPara( m_uiDeltaQpRD > 0, "Rate control cannot be used together with slice level multiple-QP optimization!\n" );
1790  }
1791#else
1792  if ( m_RCEnableRateControl )
1793  {
1794    if ( m_RCForceIntraQP )
1795    {
1796      if ( m_RCInitialQP == 0 )
1797      {
1798        printf( "\nInitial QP for rate control is not specified. Reset not to use force intra QP!" );
1799        m_RCForceIntraQP = false;
1800      }
1801    }
1802    xConfirmPara( m_uiDeltaQpRD > 0, "Rate control cannot be used together with slice level multiple-QP optimization!\n" );
1803  }
1804#endif
1805#else
1806  if(m_enableRateCtrl)
1807  {
1808    Int numLCUInWidth  = (m_iSourceWidth  / m_uiMaxCUWidth) + (( m_iSourceWidth  %  m_uiMaxCUWidth ) ? 1 : 0);
1809    Int numLCUInHeight = (m_iSourceHeight / m_uiMaxCUHeight)+ (( m_iSourceHeight %  m_uiMaxCUHeight) ? 1 : 0);
1810    Int numLCUInPic    =  numLCUInWidth * numLCUInHeight;
1811
1812    xConfirmPara( (numLCUInPic % m_numLCUInUnit) != 0, "total number of LCUs in a frame should be completely divided by NumLCUInUnit" );
1813
1814    m_iMaxDeltaQP       = MAX_DELTA_QP;
1815    m_iMaxCuDQPDepth    = MAX_CUDQP_DEPTH;
1816  }
1817#endif
1818
1819  xConfirmPara(!m_TransquantBypassEnableFlag && m_CUTransquantBypassFlagValue, "CUTransquantBypassFlagValue cannot be 1 when TransquantBypassEnableFlag is 0");
1820
1821  xConfirmPara(m_log2ParallelMergeLevel < 2, "Log2ParallelMergeLevel should be larger than or equal to 2");
1822#if L0444_FPA_TYPE
1823  if (m_framePackingSEIEnabled)
1824  {
1825    xConfirmPara(m_framePackingSEIType < 3 || m_framePackingSEIType > 5 , "SEIFramePackingType must be in rage 3 to 5");
1826  }
1827#endif
1828#if VPS_EXTN_DIRECT_REF_LAYERS
1829  xConfirmPara( (m_acLayerCfg[0].m_numDirectRefLayers != 0) && (m_acLayerCfg[0].m_numDirectRefLayers != -1), "Layer 0 cannot have any reference layers" );
1830  // NOTE: m_numDirectRefLayers  (for any layer) could be -1 (not signalled in cfg), in which case only the "previous layer" would be taken for reference
1831  for(Int layer = 1; layer < MAX_LAYERS; layer++)
1832  {
1833    xConfirmPara(m_acLayerCfg[layer].m_numDirectRefLayers > layer, "Cannot reference more layers than before current layer");
1834    for(Int i = 0; i < m_acLayerCfg[layer].m_numDirectRefLayers; i++)
1835    {
1836      xConfirmPara(m_acLayerCfg[layer].m_refLayerIds[i] > layer, "Cannot reference higher layers");
1837      xConfirmPara(m_acLayerCfg[layer].m_refLayerIds[i] == layer, "Cannot reference the current layer itself");
1838    }
1839  }
1840#endif
1841#undef xConfirmPara
1842  if (check_failed)
1843  {
1844    exit(EXIT_FAILURE);
1845  }
1846}
1847
1848/** \todo use of global variables should be removed later
1849 */
1850Void TAppEncCfg::xSetGlobal()
1851{
1852  // set max CU width & height
1853  g_uiMaxCUWidth  = m_uiMaxCUWidth;
1854  g_uiMaxCUHeight = m_uiMaxCUHeight;
1855 
1856  // compute actual CU depth with respect to config depth and max transform size
1857  g_uiAddCUDepth  = 0;
1858  while( (m_uiMaxCUWidth>>m_uiMaxCUDepth) > ( 1 << ( m_uiQuadtreeTULog2MinSize + g_uiAddCUDepth )  ) ) g_uiAddCUDepth++;
1859 
1860  m_uiMaxCUDepth += g_uiAddCUDepth;
1861  g_uiAddCUDepth++;
1862  g_uiMaxCUDepth = m_uiMaxCUDepth;
1863 
1864  // set internal bit-depth and constants
1865  g_bitDepthY = m_internalBitDepthY;
1866  g_bitDepthC = m_internalBitDepthC;
1867 
1868  g_uiPCMBitDepthLuma = m_bPCMInputBitDepthFlag ? m_inputBitDepthY : m_internalBitDepthY;
1869  g_uiPCMBitDepthChroma = m_bPCMInputBitDepthFlag ? m_inputBitDepthC : m_internalBitDepthC;
1870}
1871
1872Void TAppEncCfg::xPrintParameter()
1873{
1874  printf("\n");
1875#if SVC_EXTENSION 
1876  printf("Total number of layers        : %d\n", m_numLayers            );
1877  for(UInt layer=0; layer<m_numLayers; layer++)
1878  {
1879    printf("=== Layer %d settings === \n", layer);
1880#if AVC_SYNTAX
1881    m_acLayerCfg[layer].xPrintParameter( layer );
1882#else
1883    m_acLayerCfg[layer].xPrintParameter();
1884#endif
1885    printf("\n");
1886  }
1887  printf("=== Common configuration settings === \n");
1888  printf("Bitstream      File          : %s\n", m_pBitstreamFile      );
1889#else
1890  printf("Input          File          : %s\n", m_pchInputFile          );
1891  printf("Bitstream      File          : %s\n", m_pchBitstreamFile      );
1892  printf("Reconstruction File          : %s\n", m_pchReconFile          );
1893  printf("Real     Format              : %dx%d %dHz\n", m_iSourceWidth - m_confLeft - m_confRight, m_iSourceHeight - m_confTop - m_confBottom, m_iFrameRate );
1894  printf("Internal Format              : %dx%d %dHz\n", m_iSourceWidth, m_iSourceHeight, m_iFrameRate );
1895#endif
1896  printf("Frame index                  : %u - %d (%d frames)\n", m_FrameSkip, m_FrameSkip+m_framesToBeEncoded-1, m_framesToBeEncoded );
1897  printf("CU size / depth              : %d / %d\n", m_uiMaxCUWidth, m_uiMaxCUDepth );
1898  printf("RQT trans. size (min / max)  : %d / %d\n", 1 << m_uiQuadtreeTULog2MinSize, 1 << m_uiQuadtreeTULog2MaxSize );
1899  printf("Max RQT depth inter          : %d\n", m_uiQuadtreeTUMaxDepthInter);
1900  printf("Max RQT depth intra          : %d\n", m_uiQuadtreeTUMaxDepthIntra);
1901  printf("Min PCM size                 : %d\n", 1 << m_uiPCMLog2MinSize);
1902  printf("Motion search range          : %d\n", m_iSearchRange );
1903#if !SVC_EXTENSION
1904  printf("Intra period                 : %d\n", m_iIntraPeriod );
1905#endif
1906  printf("Decoding refresh type        : %d\n", m_iDecodingRefreshType );
1907#if !SVC_EXTENSION
1908  printf("QP                           : %5.2f\n", m_fQP );
1909#endif
1910  printf("Max dQP signaling depth      : %d\n", m_iMaxCuDQPDepth);
1911
1912  printf("Cb QP Offset                 : %d\n", m_cbQpOffset   );
1913  printf("Cr QP Offset                 : %d\n", m_crQpOffset);
1914
1915  printf("QP adaptation                : %d (range=%d)\n", m_bUseAdaptiveQP, (m_bUseAdaptiveQP ? m_iQPAdaptationRange : 0) );
1916  printf("GOP size                     : %d\n", m_iGOPSize );
1917  printf("Internal bit depth           : (Y:%d, C:%d)\n", m_internalBitDepthY, m_internalBitDepthC );
1918  printf("PCM sample bit depth         : (Y:%d, C:%d)\n", g_uiPCMBitDepthLuma, g_uiPCMBitDepthChroma );
1919#if RATE_CONTROL_LAMBDA_DOMAIN
1920#if !RC_SHVC_HARMONIZATION
1921  printf("RateControl                  : %d\n", m_RCEnableRateControl );
1922  if(m_RCEnableRateControl)
1923  {
1924    printf("TargetBitrate                : %d\n", m_RCTargetBitrate );
1925    printf("KeepHierarchicalBit          : %d\n", m_RCKeepHierarchicalBit );
1926    printf("LCULevelRC                   : %d\n", m_RCLCULevelRC );
1927    printf("UseLCUSeparateModel          : %d\n", m_RCUseLCUSeparateModel );
1928    printf("InitialQP                    : %d\n", m_RCInitialQP );
1929    printf("ForceIntraQP                 : %d\n", m_RCForceIntraQP );
1930  }
1931#endif
1932#else
1933  printf("RateControl                  : %d\n", m_enableRateCtrl);
1934  if(m_enableRateCtrl)
1935  {
1936    printf("TargetBitrate                : %d\n", m_targetBitrate);
1937    printf("NumLCUInUnit                 : %d\n", m_numLCUInUnit);
1938  }
1939#endif
1940  printf("Max Num Merge Candidates     : %d\n", m_maxNumMergeCand);
1941  printf("\n");
1942 
1943  printf("TOOL CFG: ");
1944  printf("IBD:%d ", g_bitDepthY > m_inputBitDepthY || g_bitDepthC > m_inputBitDepthC);
1945  printf("HAD:%d ", m_bUseHADME           );
1946  printf("SRD:%d ", m_bUseSBACRD          );
1947  printf("RDQ:%d ", m_useRDOQ            );
1948  printf("RDQTS:%d ", m_useRDOQTS        );
1949#if L0232_RD_PENALTY
1950  printf("RDpenalty:%d ", m_rdPenalty  );
1951#endif
1952  printf("SQP:%d ", m_uiDeltaQpRD         );
1953  printf("ASR:%d ", m_bUseASR             );
1954#if !L0034_COMBINED_LIST_CLEANUP
1955  printf("LComb:%d ", m_bUseLComb         );
1956#endif
1957  printf("FEN:%d ", m_bUseFastEnc         );
1958  printf("ECU:%d ", m_bUseEarlyCU         );
1959  printf("FDM:%d ", m_useFastDecisionForMerge );
1960  printf("CFM:%d ", m_bUseCbfFastMode         );
1961  printf("ESD:%d ", m_useEarlySkipDetection  );
1962#if FAST_INTRA_SHVC
1963  printf("FIS:%d ", m_useFastIntraScalable  );
1964#endif
1965  printf("RQT:%d ", 1     );
1966  printf("TransformSkip:%d ",     m_useTransformSkip              );
1967  printf("TransformSkipFast:%d ", m_useTransformSkipFast       );
1968  printf("Slice: M=%d ", m_sliceMode);
1969  if (m_sliceMode!=0)
1970  {
1971    printf("A=%d ", m_sliceArgument);
1972  }
1973  printf("SliceSegment: M=%d ",m_sliceSegmentMode);
1974  if (m_sliceSegmentMode!=0)
1975  {
1976    printf("A=%d ", m_sliceSegmentArgument);
1977  }
1978  printf("CIP:%d ", m_bUseConstrainedIntraPred);
1979  printf("SAO:%d ", (m_bUseSAO)?(1):(0));
1980  printf("PCM:%d ", (m_usePCM && (1<<m_uiPCMLog2MinSize) <= m_uiMaxCUWidth)? 1 : 0);
1981  printf("SAOLcuBasedOptimization:%d ", (m_saoLcuBasedOptimization)?(1):(0));
1982
1983  printf("LosslessCuEnabled:%d ", (m_useLossless)? 1:0 );
1984  printf("WPP:%d ", (Int)m_useWeightedPred);
1985  printf("WPB:%d ", (Int)m_useWeightedBiPred);
1986  printf("PME:%d ", m_log2ParallelMergeLevel);
1987#if !SVC_EXTENSION
1988  printf(" WaveFrontSynchro:%d WaveFrontSubstreams:%d",
1989          m_iWaveFrontSynchro, m_iWaveFrontSubstreams);
1990#endif
1991  printf(" ScalingList:%d ", m_useScalingListId );
1992  printf("TMVPMode:%d ", m_TMVPModeId     );
1993#if ADAPTIVE_QP_SELECTION
1994  printf("AQpS:%d", m_bUseAdaptQpSelect   );
1995#endif
1996
1997  printf(" SignBitHidingFlag:%d ", m_signHideFlag);
1998#if SVC_EXTENSION
1999  printf("RecalQP:%d ", m_recalculateQPAccordingToLambda ? 1 : 0 );
2000#if AVC_BASE
2001  printf("AvcBase:%d ", m_avcBaseLayerFlag ? 1 : 0);
2002#else
2003  printf("AvcBase:%d ", 0);
2004#endif
2005#if REF_IDX_FRAMEWORK
2006  printf("REF_IDX_FRAMEWORK:%d ", REF_IDX_FRAMEWORK);
2007  printf("EL_RAP_SliceType: %d ", m_elRapSliceBEnabled);
2008  printf("REF_IDX_ME_ZEROMV: %d ", REF_IDX_ME_ZEROMV);
2009  printf("ENCODER_FAST_MODE: %d ", ENCODER_FAST_MODE);
2010  printf("REF_IDX_MFM: %d ", REF_IDX_MFM);
2011#elif INTRA_BL
2012  printf("INTRA_BL:%d ", INTRA_BL);
2013#if !AVC_BASE
2014  printf("SVC_MVP:%d ", SVC_MVP );
2015  printf("SVC_BL_CAND_INTRA:%d", SVC_BL_CAND_INTRA );
2016#endif
2017#endif
2018#else
2019  printf("RecalQP:%d", m_recalculateQPAccordingToLambda ? 1 : 0 );
2020#endif
2021  printf("\n\n");
2022 
2023  fflush(stdout);
2024}
2025
2026Bool confirmPara(Bool bflag, const Char* message)
2027{
2028  if (!bflag)
2029    return false;
2030 
2031  printf("Error: %s\n",message);
2032  return true;
2033}
2034
2035//! \}
Note: See TracBrowser for help on using the repository browser.