source: 3DVCSoftware/branches/0.3-poznan-univ/source/App/TAppEncoder/TAppEncCfg.cpp @ 47

Last change on this file since 47 was 41, checked in by poznan-univ, 13 years ago

Adjustment for FlexCO, and high-level syntax improvement.

  • Property svn:eol-style set to native
File size: 49.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-2011, 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 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
35
36/** \file     TAppEncCfg.cpp
37    \brief    Handle encoder configuration parameters
38*/
39
40#include <stdlib.h>
41#include <math.h>
42#include <cassert>
43#include <cstring>
44#include <string>
45#include "TAppEncCfg.h"
46#include "../../App/TAppCommon/program_options_lite.h"
47
48
49using namespace std;
50namespace po = df::program_options_lite;
51
52/* configuration helper funcs */
53void doOldStyleCmdlineOn(po::Options& opts, const std::string& arg);
54void doOldStyleCmdlineOff(po::Options& opts, const std::string& arg);
55
56// ====================================================================================================================
57// Local constants
58// ====================================================================================================================
59
60/// max value of source padding size
61/** \todo replace it by command line option
62 */
63#define MAX_PAD_SIZE                16
64#define MAX_INPUT_VIEW_NUM          10
65#define MAX_ERREF_VIEW_NUM          15
66
67// ====================================================================================================================
68// Constructor / destructor / initialization / destroy
69// ====================================================================================================================
70
71TAppEncCfg::TAppEncCfg()
72{
73  m_aidQP = NULL;
74#if HHI_VSO
75  m_aaiERViewRefLutInd.resize( MAX_INPUT_VIEW_NUM );
76#endif
77}
78
79TAppEncCfg::~TAppEncCfg()
80{
81  if ( m_aidQP )
82  {
83    delete[] m_aidQP; m_aidQP = NULL;
84  }
85  for(Int i = 0; i< m_pchInputFileList.size(); i++ )
86  {
87    if ( m_pchInputFileList[i] != NULL )
88      free (m_pchInputFileList[i]);
89  }
90
91  for(Int i = 0; i< m_pchDepthInputFileList.size(); i++ )
92  {
93    if ( m_pchDepthInputFileList[i] != NULL )
94      free (m_pchDepthInputFileList[i]);
95  }
96
97  for(Int i = 0; i< m_pchReconFileList.size(); i++ )
98  {
99    if ( m_pchReconFileList[i] != NULL )
100      free (m_pchReconFileList[i]);
101  }
102
103  for(Int i = 0; i< m_pchERRefFileList.size(); i++ )
104  {
105    if ( m_pchERRefFileList[i] != NULL )
106      free (m_pchERRefFileList[i]);
107  }
108
109  if (m_pchBitstreamFile != NULL)
110    free (m_pchBitstreamFile) ;
111
112#if FLEX_CODING_ORDER
113  if (m_pchMVCJointCodingOrder != NULL)
114  {
115    free(m_pchMVCJointCodingOrder) ;
116  }
117#endif
118
119  for(Int i = 0; i< m_pchDepthReconFileList.size(); i++ )
120  {
121    if ( m_pchDepthReconFileList[i] != NULL )
122      free (m_pchDepthReconFileList[i]);
123  }
124
125  if (m_pchCameraParameterFile != NULL)
126    free (m_pchCameraParameterFile);
127
128  if (m_pchBaseViewCameraNumbers != NULL)
129    free (m_pchBaseViewCameraNumbers);
130
131#if HHI_VSO
132  if (  m_pchVSOConfig != NULL)
133    free (  m_pchVSOConfig );
134#endif
135
136}
137
138Void TAppEncCfg::create()
139{
140}
141
142Void TAppEncCfg::destroy()
143{
144}
145
146// ====================================================================================================================
147// Public member functions
148// ====================================================================================================================
149
150/** \param  argc        number of arguments
151    \param  argv        array of arguments
152    \retval             true when success
153 */
154Bool TAppEncCfg::parseCfg( Int argc, Char* argv[] )
155{
156  bool do_help = false;
157
158  string cfg_InputFile;
159  string cfg_BitstreamFile;
160  string cfg_ReconFile;
161  string cfg_dQPFile;
162
163#if FLEX_CODING_ORDER
164  string cfg_JointCodingOrdering;
165#endif
166
167  po::Options opts;
168  opts.addOptions()
169  ("help", do_help, false, "this help text")
170  ("c", po::parseConfigFile, "configuration file name")
171
172  /* File, I/O and source parameters */
173  ("InputFile_%d,i_%d",       m_pchInputFileList,       (char *) 0 , MAX_INPUT_VIEW_NUM , "original Yuv input file name %d")
174  ("DepthInputFile_%d,di_%d", m_pchDepthInputFileList,  (char *) 0 , MAX_INPUT_VIEW_NUM , "original Yuv depth input file name %d")
175  ("ReconFile_%d,o_%d",       m_pchReconFileList,       (char *) 0 , MAX_INPUT_VIEW_NUM , "reconstructed Yuv output file name %d")
176  ("DepthReconFile_%d,do_%d", m_pchDepthReconFileList,  (char *) 0 , MAX_INPUT_VIEW_NUM , "reconstructed Yuv depth output file name %d")
177  ("BitstreamFile,b", cfg_BitstreamFile, string(""), "bitstream output file name")
178
179  ("CodeDepthMaps",         m_bUsingDepthMaps, false, "Encode depth maps" )
180  ("CodedCamParsPrecision", m_iCodedCamParPrecision, STD_CAM_PARAMETERS_PRECISION, "precision for coding of camera parameters (in units of 2^(-x) luma samples)" )
181
182#ifdef WEIGHT_PRED
183  ("weighted_pred_flag,-wpP",     m_bUseWeightPred, false, "weighted prediction flag (P-Slices)")
184  ("weighted_bipred_idc,-wpBidc", m_uiBiPredIdc,    0u,    "weighted bipred idc (B-Slices)")
185#endif
186  ("SourceWidth,-wdt",      m_iSourceWidth,  0, "Source picture width")
187  ("SourceHeight,-hgt",     m_iSourceHeight, 0, "Source picture height")
188  ("InputBitDepth",         m_uiInputBitDepth, 8u, "bit-depth of input file")
189  ("BitDepth",              m_uiInputBitDepth, 8u, "deprecated alias of InputBitDepth")
190  ("OutputBitDepth",        m_uiOutputBitDepth, 0u, "bit-depth of output file")
191#if ENABLE_IBDI
192  ("BitIncrement",          m_uiBitIncrement, 0xffffffffu, "bit-depth increasement")
193#endif
194  ("InternalBitDepth",      m_uiInternalBitDepth, 0u, "Internal bit-depth (BitDepth+BitIncrement)")
195  ("HorizontalPadding,-pdx",m_aiPad[0],      0, "horizontal source padding size")
196  ("VerticalPadding,-pdy",  m_aiPad[1],      0, "vertical source padding size")
197  ("PAD",                   m_bUsePAD,   false, "automatic source padding of multiple of 16" )
198  ("FrameRate,-fr",         m_iFrameRate,        0, "Frame rate")
199  ("FrameSkip,-fs",         m_FrameSkip,         0u, "Number of frames to skip at start of input YUV")
200  ("FramesToBeEncoded,f",   m_iFrameToBeEncoded, 0, "number of frames to be encoded (default=all)")
201  ("FrameToBeEncoded",      m_iFrameToBeEncoded, 0, "depricated alias of FramesToBeEncoded")
202
203  ("NumberOfViews",         m_iNumberOfViews,    0, "Number of views")
204
205#if FLEX_CODING_ORDER
206  ("3DVFlexOrder",          m_b3DVFlexOrder,   false, "flexible coding order flag" )
207  ("3DVCodingOrder",            cfg_JointCodingOrdering,  string(""), "The coding order for joint texture-depth coding")
208#endif
209
210  /* Unit definition parameters */
211  ("MaxCUWidth",          m_uiMaxCUWidth,  64u)
212  ("MaxCUHeight",         m_uiMaxCUHeight, 64u)
213  /* todo: remove defaults from MaxCUSize */
214  ("MaxCUSize,s",         m_uiMaxCUWidth,  64u, "max CU size")
215  ("MaxCUSize,s",         m_uiMaxCUHeight, 64u, "max CU size")
216  ("MaxPartitionDepth,h", m_uiMaxCUDepth,   4u, "CU depth")
217
218  ("QuadtreeTULog2MaxSize", m_uiQuadtreeTULog2MaxSize, 6u)
219  ("QuadtreeTULog2MinSize", m_uiQuadtreeTULog2MinSize, 2u)
220
221  ("QuadtreeTUMaxDepthIntra", m_uiQuadtreeTUMaxDepthIntra, 1u)
222  ("QuadtreeTUMaxDepthInter", m_uiQuadtreeTUMaxDepthInter, 2u)
223
224  /* Coding structure paramters */
225  ("CodedPictureStoreSize,cpss",  m_uiCodedPictureStoreSize, 16u, "Size of coded picture Buffer")
226#if DCM_DECODING_REFRESH
227  ("DecodingRefreshType,-dr",m_iDecodingRefreshType, 0, "intra refresh, (0:none 1:CDR 2:IDR)")
228#endif
229  ("GOPSize,g",      m_iGOPSize,      1, "GOP size of temporal structure")
230  ("RateGOPSize,-rg",m_iRateGOPSize, -1, "GOP size of hierarchical QP assignment (-1: implies inherit GOPSize value)")
231#if !HHI_NO_LowDelayCoding
232  ("LowDelayCoding",         m_bUseLDC,             false, "low-delay mode")
233#endif
234#if DCM_COMB_LIST
235  ("ListCombination, -lc", m_bUseLComb, true, "combined reference list for uni-prediction in B-slices")
236  ("LCModification", m_bLCMod, false, "enables signalling of combined reference list derivation")
237#endif
238
239  ("GOPFormatString,gfs", m_cInputFormatString,  string(""), "Group of pictures")
240
241  /* motion options */
242  ("FastSearch", m_iFastSearch, 1, "0:Full search  1:Diamond  2:PMVFAST")
243  ("SearchRange,-sr",m_iSearchRange, 96, "motion search range")
244  ("BipredSearchRange", m_bipredSearchRange, 4, "motion search range for bipred refinement")
245  ("HadamardME", m_bUseHADME, true, "hadamard ME for fractional-pel")
246  ("ASR", m_bUseASR, false, "adaptive motion search range")
247
248  /* Quantization parameters */
249  ("QP,q",          m_adQP,     std::vector<double>(1,32), "Qp value, if value is float, QP is switched once during encoding, if two values are given the second is used for depth")
250  ("DeltaQpRD,-dqr",m_uiDeltaQpRD,       0u, "max dQp offset for slice")
251  ("MaxDeltaQP,d",  m_iMaxDeltaQP,        0, "max dQp offset for block")
252  ("dQPFile,m",     m_pchdQPFile , (char*) 0, "dQP file name")
253  ("RDOQ",          m_abUseRDOQ, std::vector<Bool>(1,true), "Enable RDOQ")
254  ("TemporalLayerQPOffset_L0,-tq0", m_aiTLayerQPOffset[0], 0, "QP offset of temporal layer 0")
255  ("TemporalLayerQPOffset_L1,-tq1", m_aiTLayerQPOffset[1], 0, "QP offset of temporal layer 1")
256  ("TemporalLayerQPOffset_L2,-tq2", m_aiTLayerQPOffset[2], 0, "QP offset of temporal layer 2")
257  ("TemporalLayerQPOffset_L3,-tq3", m_aiTLayerQPOffset[3], 0, "QP offset of temporal layer 3")
258  ("TemporalLayerQPOffset_L4,-tq4", m_aiTLayerQPOffset[4], 0, "QP offset of temporal layer 3")
259  ("TemporalLayerQPOffset_L5,-tq5", m_aiTLayerQPOffset[5], 0, "QP offset of temporal layer 3")
260  ("TemporalLayerQPOffset_L6,-tq6", m_aiTLayerQPOffset[6], 0, "QP offset of temporal layer 3")
261  ("TemporalLayerQPOffset_L7,-tq7", m_aiTLayerQPOffset[7], 0, "QP offset of temporal layer 3")
262  ("TemporalLayerQPOffset_L8,-tq8", m_aiTLayerQPOffset[8], 0, "QP offset of temporal layer 3")
263  ("TemporalLayerQPOffset_L9,-tq9", m_aiTLayerQPOffset[9], 0, "QP offset of temporal layer 3")
264
265  /* Entropy coding parameters */
266  ("SymbolMode,-sym", m_iSymbolMode, 1, "symbol mode (0=VLC, 1=SBAC)")
267  ("SBACRD", m_bUseSBACRD, true, "SBAC based RD estimation")
268
269  /* Deblocking filter parameters */
270  ("LoopFilterDisable", m_abLoopFilterDisable, std::vector<Bool>(1,false), "Disables LoopFilter")
271  ("LoopFilterAlphaC0Offset", m_iLoopFilterAlphaC0Offset, 0)
272  ("LoopFilterBetaOffset", m_iLoopFilterBetaOffset, 0 )
273
274  /* Camera Paremetes */
275  ("CameraParameterFile,cpf", m_pchCameraParameterFile,    (Char *) 0, "Camera Parameter File Name")
276  ("BaseViewCameraNumbers" ,  m_pchBaseViewCameraNumbers,  (Char *) 0, "Numbers of base views")
277
278
279    /* View Synthesis Optimization */
280
281#if HHI_VSO
282  ("VSOConfig",                       m_pchVSOConfig            , (Char *) 0    , "VSO configuration")
283    ("VSO",                             m_bUseVSO                 , false         , "Use VSO" )
284    // GT: For development, will be removed later
285  ("VSOMode",                         m_uiVSOMode               , (UInt)   4    , "VSO Mode")
286#if HHI_VSO_LS_TABLE
287  ("LambdaScaleVSO",                  m_dLambdaScaleVSO         , (Double) 1  , "Lambda Scaling for VSO")
288#else
289  ("LambdaScaleVSO",                  m_dLambdaScaleVSO         , (Double) 0.5  , "Lambda Scaling for VSO")
290#endif
291    ("ForceLambdaScaleVSO",             m_bForceLambdaScaleVSO    , false         , "Force using Lambda Scale VSO also in non-VSO-Mode")
292#if HHI_VSO_DIST_INT
293  ("AllowNegDist",                    m_bAllowNegDist           , true         , "Allow negative Distortion in VSO")
294#endif
295
296    ("NumberOfExternalRefs",            m_iNumberOfExternalRefs   , 0             , "Number of virtual external reference views")
297    ("ERRefFile_%d,er_%d",              m_pchERRefFileList        , (char *) 0    , MAX_ERREF_VIEW_NUM , "virtual external reference view file name %d")
298    ("VSERViewReferences_%d,evr_%d"  ,  m_aaiERViewRefInd         , vector<Int>() , MAX_INPUT_VIEW_NUM, "Numbers of external virtual reference views to be used for this view")
299    ("VSBaseViewReferences_%d,bvr_%d",  m_aaiBaseViewRefInd       , vector<Int>() , MAX_INPUT_VIEW_NUM, "Numbers of external virtual reference views to be used for this view")
300#endif
301
302  /* Coding tools */
303  ("MRG", m_bUseMRG, true, "merging of motion partitions")
304
305#if LM_CHROMA
306  ("LMChroma", m_bUseLMChroma, true, "intra chroma prediction based on recontructed luma")
307#endif
308
309  ("ALF", m_abUseALF, std::vector<Bool>(1,true), "Enables ALF")
310#if MTK_SAO
311  ("SAO", m_abUseSAO, std::vector<Bool>(1, true), "SAO")
312#endif
313
314#if MQT_ALF_NPASS
315  ("ALFEncodePassReduction", m_iALFEncodePassReduction, 0, "0:Original 16-pass, 1: 1-pass, 2: 2-pass encoding")
316#endif
317#if HHI_RMP_SWITCH
318  ("RMP", m_bUseRMP ,true, "Rectangular motion partition" )
319#endif
320#ifdef ROUNDING_CONTROL_BIPRED
321  ("RoundingControlBipred", m_useRoundingControlBipred, false, "Rounding control for bi-prediction")
322#endif
323    ("SliceMode",            m_iSliceMode,           0, "0: Disable all Recon slice limits, 1: Enforce max # of LCUs, 2: Enforce max # of bytes")
324    ("SliceArgument",        m_iSliceArgument,       0, "if SliceMode==1 SliceArgument represents max # of LCUs. if SliceMode==2 SliceArgument represents max # of bytes.")
325    ("EntropySliceMode",     m_iEntropySliceMode,    0, "0: Disable all entropy slice limits, 1: Enforce max # of LCUs, 2: Enforce constraint based entropy slices")
326    ("EntropySliceArgument", m_iEntropySliceArgument,0, "if EntropySliceMode==1 SliceArgument represents max # of LCUs. if EntropySliceMode==2 EntropySliceArgument represents max # of bins.")
327#if MTK_NONCROSS_INLOOP_FILTER
328    ("LFCrossSliceBoundaryFlag", m_bLFCrossSliceBoundaryFlag, true)
329#endif
330#if CONSTRAINED_INTRA_PRED
331  ("ConstrainedIntraPred", m_bUseConstrainedIntraPred, false, "Constrained Intra Prediction")
332#endif
333  /* Misc. */
334  ("SEIpictureDigest", m_pictureDigestEnabled, false, "Control generation of picture_digest SEI messages\n"
335                                              "\t1: use MD5\n"
336                                              "\t0: disable")
337  ("FEN", m_bUseFastEnc, false, "fast encoder setting")
338
339#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
340  ("DMM", m_bUseDMM, false, "add depth modes intra")
341#endif
342#if HHI_MPI
343  ("MVI", m_bUseMVI, false, "use motion vector inheritance for depth map coding")
344#endif
345
346  /* Multiview tools */
347#if DEPTH_MAP_GENERATION
348  ("PredDepthMapGen",  m_uiPredDepthMapGeneration, (UInt)0, "generation of prediction depth maps for motion data prediction" )
349#endif
350#if HHI_INTER_VIEW_MOTION_PRED
351  ("MultiviewMvPred",  m_uiMultiviewMvPredMode,    (UInt)0, "usage of predicted depth maps" )
352  ("MultiviewMvRegMode",        m_uiMultiviewMvRegMode,         (UInt)0, "regularization mode for multiview motion vectors" )
353  ("MultiviewMvRegLambdaScale", m_dMultiviewMvRegLambdaScale, (Double)0, "lambda scale for multiview motion vector regularization" )
354#endif
355#if HHI_INTER_VIEW_RESIDUAL_PRED
356  ("MultiviewResPred", m_uiMultiviewResPredMode,   (UInt)0, "usage of inter-view residual prediction" )
357#endif
358
359#if POZNAN_DBMP
360  ("DBMP",  m_uiDBMP,    (UInt)0, "usage of Depth-Based Motion Prediction" )
361#endif
362
363#if POZNAN_ENCODE_ONLY_DISOCCLUDED_CU
364  ("CUSkip",  m_uiUseCUSkip,    (UInt)1, "encode only disoccluded CUs in dependend view" )
365#endif
366
367  ("QpChangeFrame", m_iQpChangeFrame, PicOrderCnt(0), "start frame for QP change")
368  ("QpChangeOffsetVideo", m_iQpChangeOffsetVideo, 0, "QP change offset for video")
369  ("QpChangeOffsetDepth", m_iQpChangeOffsetDepth, 0, "QP change offset for depth")
370#if HHI_INTERVIEW_SKIP
371  ("InterViewSkip",  m_uiInterViewSkip,    (UInt)0, "usage of interview skip" )
372#if HHI_INTERVIEW_SKIP_LAMBDA_SCALE
373  ("InterViewSkipLambdaScale",  m_dInterViewSkipLambdaScale,    (Double)8, "lambda scale for interview skip" )
374#endif
375#endif
376#if POZNAN_TEXTURE_TU_DELTA_QP_ACCORDING_TO_DEPTH
377  ("TDdQP", m_bUseTexDqpAccordingToDepth, false, "texture TU blocks QP param modification according to depth map's values")
378#endif
379#if POZNAN_TEXTURE_TU_DELTA_QP_PARAM_IN_CFG_FOR_ENC
380  ("TDdQPOffset",              m_dTexDqpAccordingToDepthOffset,       (Double)(-2.6), "texture block QP changing tool based on coresponding depth block values - offset parameter" )
381  ("TDdQPMul",                 m_dTexDqpAccordingToDepthMul,          (Double)(1),    "texture block QP changing tool based on coresponding depth block values - multiplicative parameter" )
382  ("TDdQPTopBottomRow",        m_iTexDqpAccordingToDepthTopBottomRow, (Int)2,         "texture block QP changing tool - top and bottom CU rows delta QP parameter" )
383#endif
384#if POZNAN_NONLINEAR_DEPTH
385  ("NonlinearDepth",           m_bUseNonlinearDepth,    true, "usage of non-linear depth representation")   
386  ("NonlinearDepthModel",      m_aiNonlinearDepthModel, std::vector<Int>(0,0), "Nodes for definition of non-linear depth representation")   
387#if POZNAN_NONLINEAR_DEPTH_THRESHOLD
388  ("NonlinearDepthThreshold",  m_iNonlinearDepthThreshold, 100, "Threshold for usage of Nonlinear depth representation")   
389#endif
390#endif
391
392
393  /* Compatability with old style -1 FOO or -0 FOO options. */
394  ("1", doOldStyleCmdlineOn, "turn option <name> on")
395  ("0", doOldStyleCmdlineOff, "turn option <name> off")
396  ;
397
398  po::setDefaults(opts);
399  const list<const char*>& argv_unhandled = po::scanArgv(opts, argc, (const char**) argv);
400
401  for (list<const char*>::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++)
402  {
403    fprintf(stderr, "Unhandled argument ignored: `%s'\n", *it);
404  }
405
406  if (argc == 1 || do_help)
407  {
408    /* argc == 1: no options have been specified */
409    po::doHelp(cout, opts);
410    xPrintUsage();
411    return false;
412  }
413
414  /*
415   * Set any derived parameters
416   */
417  /* convert std::string to c string for compatability */
418  m_pchBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str());
419  m_pchdQPFile = cfg_dQPFile.empty() ? NULL : strdup(cfg_dQPFile.c_str());
420
421#if FLEX_CODING_ORDER && HHI_VSO
422  m_pchMVCJointCodingOrder      = cfg_JointCodingOrdering.empty()?NULL:strdup(cfg_JointCodingOrdering.c_str());
423  // If flexible order is enabled and if depth comes before the texture for a view, disable VSO
424  Bool depthComesFirst = false;
425  if ( m_b3DVFlexOrder )
426  {
427    for(Int iViewIdx=0; iViewIdx<m_iNumberOfViews; iViewIdx++)
428    {
429      for ( Int ii=1; ii<12; ii+=2 )
430      {
431        Int iViewIdxCfg = (Int)(m_pchMVCJointCodingOrder[ii]-'0');
432        if ( iViewIdxCfg == iViewIdx )
433        {
434          if ( m_pchMVCJointCodingOrder[ii-1]=='D' ) // depth comes first for this view
435          {
436            depthComesFirst = true;
437            break;
438          }
439          else
440          {
441            assert(m_pchMVCJointCodingOrder[ii-1]=='T');
442          }
443        }
444      }
445    }
446  }
447  if (depthComesFirst)
448  {
449    m_bUseVSO = false;         
450  }
451#endif
452
453
454// GT FIX
455  if ( m_bUsingDepthMaps )
456  {
457    for(Int i = 0; i < m_pchDepthReconFileList.size() ; i++)
458    {
459      if ((m_pchDepthInputFileList[i] != NULL) && (m_pchReconFileList[i] != NULL) && (i < m_iNumberOfViews) )
460      {
461        if (m_pchDepthReconFileList[i] == NULL )
462        {
463          xAppendToFileNameEnd( m_pchReconFileList[i], "_depth", m_pchDepthReconFileList[i] );
464        }
465      }
466      else
467      {
468        m_pchDepthReconFileList[i] = NULL;
469      }
470    };
471  }
472// GT FIX END
473
474  if (m_iRateGOPSize == -1)
475  {
476    /* if rateGOPSize has not been specified, the default value is GOPSize */
477    m_iRateGOPSize = m_iGOPSize;
478  }
479
480  // compute source padding size
481  if ( m_bUsePAD )
482  {
483    if ( m_iSourceWidth%MAX_PAD_SIZE )
484    {
485      m_aiPad[0] = (m_iSourceWidth/MAX_PAD_SIZE+1)*MAX_PAD_SIZE - m_iSourceWidth;
486    }
487
488    if ( m_iSourceHeight%MAX_PAD_SIZE )
489    {
490      m_aiPad[1] = (m_iSourceHeight/MAX_PAD_SIZE+1)*MAX_PAD_SIZE - m_iSourceHeight;
491    }
492  }
493  m_iSourceWidth  += m_aiPad[0];
494  m_iSourceHeight += m_aiPad[1];
495
496//GT QP Depth
497  if ( m_adQP.size() < 2 )
498  {
499    m_adQP.push_back( m_adQP[0] );
500  };
501  for (UInt uiK = 0; uiK < m_adQP.size(); uiK++)
502  {
503    m_aiQP.push_back( (Int)( m_adQP[uiK] ) );
504  }
505//GT QP Depth end
506
507#if HHI_VSO
508  m_bUseVSO = m_bUseVSO && m_bUsingDepthMaps && (m_uiVSOMode != 0);
509#endif
510
511#if POZNAN_NONLINEAR_DEPTH
512#if POZNAN_NONLINEAR_DEPTH_THRESHOLD
513  if(m_bUseNonlinearDepth && m_iNonlinearDepthThreshold>0)
514  {
515    FILE *base_depth_file;
516    unsigned char *depth_buf;
517    int histogram[256];
518    int i, size;
519    float weighted_avg;
520    base_depth_file = fopen(m_pchDepthInputFileList[0], "rb");
521    if (base_depth_file)
522    {
523      size = m_iSourceWidth*m_iSourceHeight;
524      depth_buf = (unsigned char *)malloc(size);
525      fread(depth_buf, 1, size, base_depth_file);
526      fclose(base_depth_file);
527      memset(histogram, 0, sizeof(histogram));
528      for (i=0; i<size;++i) histogram[depth_buf[i]]++;
529      weighted_avg = 0;
530      for (i=0; i<256; ++i) weighted_avg += i*histogram[i];
531      weighted_avg /= size;
532
533      if (weighted_avg<m_iNonlinearDepthThreshold)
534      {
535        m_bUseNonlinearDepth = 0;
536        printf ("\nWeighted average of depth histogram:%f < %d, turning NonlinearDepthRepresentation OFF\n", weighted_avg, m_iNonlinearDepthThreshold);
537      }
538    }
539  }
540#endif
541
542  if(m_bUseNonlinearDepth)
543  {
544    m_cNonlinearDepthModel.m_iNum = (Int)m_aiNonlinearDepthModel.size();
545    m_cNonlinearDepthModel.m_aiPoints[0]=0;
546    for (int i=0; i<m_cNonlinearDepthModel.m_iNum; ++i)
547      m_cNonlinearDepthModel.m_aiPoints[i+1] = m_aiNonlinearDepthModel[i];
548
549    m_cNonlinearDepthModel.m_aiPoints[m_cNonlinearDepthModel.m_iNum+1]=0;
550    m_cNonlinearDepthModel.Init();
551  }
552#endif
553
554  xCleanUpVectors();
555
556#if HHI_VSO
557  if ( m_abUseALF .size() < 2)
558    m_abUseALF .push_back( m_bUseVSO ? false : m_abUseALF[0]  );
559
560  if ( m_abUseRDOQ.size() < 2)
561    m_abUseRDOQ.push_back( m_bUseVSO ? true : m_abUseRDOQ[0] );
562
563  if ( m_abLoopFilterDisable.size() < 2)
564    m_abLoopFilterDisable.push_back( m_bUseVSO ? true : m_abLoopFilterDisable[0]  );
565
566  if (m_abUseSAO.size() < 2)
567    m_abUseSAO.push_back            ( m_bUseVSO ? false : m_abUseSAO[0] );
568#else
569  if ( m_abUseALF .size() < 2)
570    m_abUseALF .push_back( m_abUseALF[0]  );
571
572  if ( m_abUseRDOQ.size() < 2)
573    m_abUseRDOQ.push_back( m_abUseRDOQ[0] );
574
575  if ( m_abLoopFilterDisable.size() < 2)
576    m_abLoopFilterDisable.push_back( m_abLoopFilterDisable[0]  );
577
578  if (m_abUseSAO.size() < 2)
579    m_abUseSAO.push_back            ( m_abUseSAO[0] );
580#endif
581
582#if HHI_VSO
583  if ( m_bUseVSO )
584  {
585    if ( m_iNumberOfExternalRefs != 0 )
586    {
587      xCleanUpVector( m_aaiERViewRefInd,    vector<Int>() );
588      xCleanUpVector( m_aaiBaseViewRefInd,  vector<Int>() );
589    }
590    else
591    {
592      m_aaiERViewRefInd   .clear();
593      m_aaiERViewRefInd   .resize( m_iNumberOfViews );
594      m_aaiERViewRefLutInd.clear();
595      m_aaiERViewRefLutInd.resize( m_iNumberOfViews );
596      m_aaiBaseViewRefInd .clear();
597      m_aaiBaseViewRefInd .resize( m_iNumberOfViews );
598    }
599  }
600
601#if HHI_VSO_LS_TABLE
602  // Q&D
603  Double adLambdaScaleTable[] = 
604  {  0.031250, 0.031639, 0.032029, 0.032418, 0.032808, 0.033197, 0.033586, 0.033976, 0.034365, 0.034755, 
605     0.035144, 0.035533, 0.035923, 0.036312, 0.036702, 0.037091, 0.037480, 0.037870, 0.038259, 0.038648, 
606     0.039038, 0.039427, 0.039817, 0.040206, 0.040595, 0.040985, 0.041374, 0.041764, 0.042153, 0.042542, 
607     0.042932, 0.043321, 0.043711, 0.044100, 0.044194, 0.053033, 0.061872, 0.070711, 0.079550, 0.088388, 
608     0.117851, 0.147314, 0.176777, 0.235702, 0.294628, 0.353553, 0.471405, 0.589256, 0.707107, 0.707100, 
609     0.753550, 0.800000 
610  }; 
611  AOT( (m_aiQP[1] < 0) || (m_aiQP[1] > 51));
612  m_dLambdaScaleVSO *= adLambdaScaleTable[m_aiQP[1]]; 
613#endif
614#endif
615
616  // set global variables
617  xSetGlobal();
618
619  // read and check camera parameters
620#if HHI_VSO
621if ( m_bUseVSO && m_uiVSOMode == 4)
622{
623  m_cRenModStrParser.setString( m_iNumberOfViews, m_pchVSOConfig );
624  m_cCameraData     .init     ( (UInt)m_iNumberOfViews,
625                                      m_uiInputBitDepth,
626                                (UInt)m_iCodedCamParPrecision,
627                                      m_FrameSkip,
628                                (UInt)m_iFrameToBeEncoded,
629                                      m_pchCameraParameterFile,
630                                      m_pchBaseViewCameraNumbers,
631                                      NULL,
632                                      m_cRenModStrParser.getSynthViews(),
633                                      LOG2_DISP_PREC_LUT
634#if POZNAN_NONLINEAR_DEPTH                                     
635                                      ,(m_bUseNonlinearDepth ? &m_cNonlinearDepthModel : NULL)
636#endif
637                                      );
638}
639else if ( m_bUseVSO && m_uiVSOMode != 4 )
640{
641  m_cCameraData     .init     ( (UInt)m_iNumberOfViews,
642                                      m_uiInputBitDepth,
643                                (UInt)m_iCodedCamParPrecision,
644                                      m_FrameSkip,
645                                (UInt)m_iFrameToBeEncoded,
646                                      m_pchCameraParameterFile,
647                                      m_pchBaseViewCameraNumbers,
648                                      m_pchVSOConfig,
649                                      NULL,
650                                      LOG2_DISP_PREC_LUT
651#if POZNAN_NONLINEAR_DEPTH                                     
652                                      ,(m_bUseNonlinearDepth ? &m_cNonlinearDepthModel : NULL)
653#endif                                     
654                                      );
655}
656else
657{
658  m_cCameraData     .init     ( (UInt)m_iNumberOfViews,
659    m_uiInputBitDepth,
660    (UInt)m_iCodedCamParPrecision,
661    m_FrameSkip,
662    (UInt)m_iFrameToBeEncoded,
663    m_pchCameraParameterFile,
664    m_pchBaseViewCameraNumbers,
665    NULL,
666    NULL,
667    LOG2_DISP_PREC_LUT
668#if POZNAN_NONLINEAR_DEPTH                                     
669    ,(m_bUseNonlinearDepth ? &m_cNonlinearDepthModel : NULL)
670#endif   
671    );
672}
673#else
674  m_cCameraData     .init     ( (UInt)m_iNumberOfViews,
675    m_uiInputBitDepth,
676    (UInt)m_iCodedCamParPrecision,
677    m_FrameSkip,
678    (UInt)m_iFrameToBeEncoded,
679    m_pchCameraParameterFile,
680    m_pchBaseViewCameraNumbers,
681    NULL,
682    NULL,
683    LOG2_DISP_PREC_LUT
684#if POZNAN_NONLINEAR_DEPTH                                     
685    ,(m_bUseNonlinearDepth ? &m_cNonlinearDepthModel : NULL)
686#endif   
687    );
688#endif
689
690
691  // check validity of input parameters
692  xCheckParameter();
693  m_cCameraData.check( false, true );
694
695  // print-out parameters
696  xPrintParameter();
697
698  return true;
699}
700
701// ====================================================================================================================
702// Private member functions
703// ====================================================================================================================
704
705Bool confirmPara(Bool bflag, const char* message);
706
707Void TAppEncCfg::xCheckParameter()
708{
709  bool check_failed = false; /* abort if there is a fatal configuration problem */
710#define xConfirmPara(a,b) check_failed |= confirmPara(a,b)
711  // check range of parameters
712#if ENABLE_IBDI
713  xConfirmPara( m_uiInternalBitDepth > 0 && (int)m_uiBitIncrement != -1,                    "InternalBitDepth and BitIncrement may not be specified simultaneously");
714#else
715  xConfirmPara( m_uiInputBitDepth < 8,                                                      "InputBitDepth must be at least 8" );
716#endif
717  xConfirmPara( m_iFrameRate <= 0,                                                          "Frame rate must be more than 1" );
718  xConfirmPara( m_iFrameToBeEncoded <= 0,                                                   "Total Number Of Frames encoded must be more than 1" );
719  xConfirmPara( m_iGOPSize < 1 ,                                                            "GOP Size must be more than 1" );
720#if DCM_DECODING_REFRESH
721  xConfirmPara( m_iDecodingRefreshType < 0 || m_iDecodingRefreshType > 2,                   "Decoding Refresh Type must be equal to 0, 1 or 2" );
722#endif
723//GT QP Depth
724  xConfirmPara( m_aiQP[0] < 0 || m_aiQP[0] > 51,                                             "QP exceeds supported range (0 to 51)" );
725  if ( m_aiQP.size() >= 2 )
726  {
727    xConfirmPara( m_aiQP[1] < 0 || m_aiQP[1] > 51,                                           "QP Depth exceeds supported range (0 to 51)" );
728  }
729//GT QP Depth End
730#if MQT_ALF_NPASS
731  xConfirmPara( m_iALFEncodePassReduction < 0 || m_iALFEncodePassReduction > 2,             "ALFEncodePassReduction must be equal to 0, 1 or 2");
732#endif
733  xConfirmPara( m_iLoopFilterAlphaC0Offset < -26 || m_iLoopFilterAlphaC0Offset > 26,        "Loop Filter Alpha Offset exceeds supported range (-26 to 26)" );
734  xConfirmPara( m_iLoopFilterBetaOffset < -26 || m_iLoopFilterBetaOffset > 26,              "Loop Filter Beta Offset exceeds supported range (-26 to 26)");
735  xConfirmPara( m_iFastSearch < 0 || m_iFastSearch > 2,                                     "Fast Search Mode is not supported value (0:Full search  1:Diamond  2:PMVFAST)" );
736  xConfirmPara( m_iSearchRange < 0 ,                                                        "Search Range must be more than 0" );
737  xConfirmPara( m_bipredSearchRange < 0 ,                                                   "Search Range must be more than 0" );
738  xConfirmPara( m_iMaxDeltaQP > 7,                                                          "Absolute Delta QP exceeds supported range (0 to 7)" );
739  xConfirmPara( (m_uiMaxCUWidth  >> m_uiMaxCUDepth) < 4,                                    "Minimum partition width size should be larger than or equal to 8");
740  xConfirmPara( (m_uiMaxCUHeight >> m_uiMaxCUDepth) < 4,                                    "Minimum partition height size should be larger than or equal to 8");
741  xConfirmPara( m_uiMaxCUWidth < 16,                                                        "Maximum partition width size should be larger than or equal to 16");
742  xConfirmPara( m_uiMaxCUHeight < 16,                                                       "Maximum partition height size should be larger than or equal to 16");
743  xConfirmPara( (m_iSourceWidth  % (m_uiMaxCUWidth  >> (m_uiMaxCUDepth-1)))!=0,             "Frame width should be multiple of minimum CU size");
744  xConfirmPara( (m_iSourceHeight % (m_uiMaxCUHeight >> (m_uiMaxCUDepth-1)))!=0,             "Frame height should be multiple of minimum CU size");
745
746  xConfirmPara( m_uiQuadtreeTULog2MinSize < 2,                                        "QuadtreeTULog2MinSize must be 2 or greater.");
747  xConfirmPara( m_uiQuadtreeTULog2MinSize > 5,                                        "QuadtreeTULog2MinSize must be 5 or smaller.");
748  xConfirmPara( m_uiQuadtreeTULog2MaxSize < 2,                                        "QuadtreeTULog2MaxSize must be 2 or greater.");
749  xConfirmPara( m_uiQuadtreeTULog2MaxSize > 5,                                        "QuadtreeTULog2MaxSize must be 5 or smaller.");
750  xConfirmPara( m_uiQuadtreeTULog2MaxSize < m_uiQuadtreeTULog2MinSize,                "QuadtreeTULog2MaxSize must be greater than or equal to m_uiQuadtreeTULog2MinSize.");
751  xConfirmPara( (1<<m_uiQuadtreeTULog2MinSize)>(m_uiMaxCUWidth >>(m_uiMaxCUDepth-1)), "QuadtreeTULog2MinSize must not be greater than minimum CU size" ); // HS
752  xConfirmPara( (1<<m_uiQuadtreeTULog2MinSize)>(m_uiMaxCUHeight>>(m_uiMaxCUDepth-1)), "QuadtreeTULog2MinSize must not be greater than minimum CU size" ); // HS
753  xConfirmPara( ( 1 << m_uiQuadtreeTULog2MinSize ) > ( m_uiMaxCUWidth  >> m_uiMaxCUDepth ), "Minimum CU width must be greater than minimum transform size." );
754  xConfirmPara( ( 1 << m_uiQuadtreeTULog2MinSize ) > ( m_uiMaxCUHeight >> m_uiMaxCUDepth ), "Minimum CU height must be greater than minimum transform size." );
755  xConfirmPara( m_uiQuadtreeTUMaxDepthInter < 1,                                                         "QuadtreeTUMaxDepthInter must be greater than or equal to 1" );
756  xConfirmPara( m_uiQuadtreeTUMaxDepthInter > m_uiQuadtreeTULog2MaxSize - m_uiQuadtreeTULog2MinSize + 1, "QuadtreeTUMaxDepthInter must be less than or equal to the difference between QuadtreeTULog2MaxSize and QuadtreeTULog2MinSize plus 1" );
757  xConfirmPara( m_uiQuadtreeTUMaxDepthIntra < 1,                                                         "QuadtreeTUMaxDepthIntra must be greater than or equal to 1" );
758  xConfirmPara( m_uiQuadtreeTUMaxDepthIntra > m_uiQuadtreeTULog2MaxSize - m_uiQuadtreeTULog2MinSize + 1, "QuadtreeTUMaxDepthIntra must be less than or equal to the difference between QuadtreeTULog2MaxSize and QuadtreeTULog2MinSize plus 1" );
759
760  xConfirmPara( m_iSliceMode < 0 || m_iSliceMode > 2, "SliceMode exceeds supported range (0 to 2)" );
761  if (m_iSliceMode!=0)
762  {
763    xConfirmPara( m_iSliceArgument < 1 ,         "SliceArgument should be larger than or equal to 1" );
764  }
765  xConfirmPara( m_iEntropySliceMode < 0 || m_iEntropySliceMode > 2, "EntropySliceMode exceeds supported range (0 to 2)" );
766  if (m_iEntropySliceMode!=0)
767  {
768    xConfirmPara( m_iEntropySliceArgument < 1 ,         "EntropySliceArgument should be larger than or equal to 1" );
769  }
770
771  xConfirmPara( m_iSymbolMode < 0 || m_iSymbolMode > 1,                                     "SymbolMode must be equal to 0 or 1" );
772
773  // Check MultiView stuff
774  xConfirmPara    ( m_iNumberOfViews > MAX_INPUT_VIEW_NUM ,                           "NumberOfViews must be less than or equal to MAX_INPUT_VIEW_NUM");
775  xConfirmPara    ( Int( m_pchInputFileList.size() ) < m_iNumberOfViews,              "Number of InputFiles must be greater than or equal to NumberOfViews" );
776  xConfirmPara    ( Int( m_pchReconFileList.size() ) < m_iNumberOfViews,              "Number of ReconFiles must be greater than or equal to NumberOfViews" );
777
778  xConfirmPara    ( m_iCodedCamParPrecision < 0 || m_iCodedCamParPrecision > 5,       "CodedCamParsPrecision must be in range of 0..5" );
779#if DEPTH_MAP_GENERATION
780  xConfirmPara    ( m_uiPredDepthMapGeneration > 2,                                   "PredDepthMapGen must be less than or equal to 2" );
781  xConfirmPara    ( m_uiPredDepthMapGeneration >= 2 && !m_bUsingDepthMaps,            "PredDepthMapGen >= 2 requires CodeDepthMaps = 1" );
782#endif
783#if HHI_INTER_VIEW_MOTION_PRED
784  xConfirmPara    ( m_uiMultiviewMvPredMode > 7,                                      "MultiviewMvPred must be less than or equal to 7" );
785  xConfirmPara    ( m_uiMultiviewMvPredMode > 0 && m_uiPredDepthMapGeneration == 0 ,  "MultiviewMvPred > 0 requires PredDepthMapGen > 0" );
786  xConfirmPara    ( m_uiMultiviewMvRegMode       > 1,                                 "MultiviewMvRegMode must be less than or equal to 1" );
787  xConfirmPara    ( m_dMultiviewMvRegLambdaScale < 0.0,                               "MultiviewMvRegLambdaScale must not be negative" );
788  if( m_uiMultiviewMvRegMode )
789  {
790    xConfirmPara  ( Int( m_pchDepthInputFileList.size() ) < m_iNumberOfViews,         "MultiviewMvRegMode > 0 requires the presence of input depth maps" );
791  }
792#endif
793#if HHI_INTER_VIEW_RESIDUAL_PRED
794  xConfirmPara    ( m_uiMultiviewResPredMode > 1,                                     "MultiviewResPred must be less than or equal to 1" );
795  xConfirmPara    ( m_uiMultiviewResPredMode > 0 && m_uiPredDepthMapGeneration == 0 , "MultiviewResPred > 0 requires PredDepthMapGen > 0" );
796#endif
797
798#if POZNAN_DBMP
799  xConfirmPara    ( m_uiDBMP > 1,                                                                                                       "DBMP must be less than or equal to 1" );
800#endif
801
802#if POZNAN_ENCODE_ONLY_DISOCCLUDED_CU
803  xConfirmPara    ( m_uiUseCUSkip > 1,                                                                                          "CU-Skip must be less than or equal to 1" );
804#endif
805
806#if HHI_INTERVIEW_SKIP
807  xConfirmPara    ( m_uiInterViewSkip > 1,                                        "RenderingSkipMode > 1 not supported" );
808  xConfirmPara    ( m_uiInterViewSkip > 0 && !m_bUsingDepthMaps,                  "RenderingSkipMode > 0 requires CodeDepthMaps = 1" );
809#endif
810  if( m_bUsingDepthMaps )
811  {
812    xConfirmPara  ( Int( m_pchDepthInputFileList.size() ) < m_iNumberOfViews,         "Number of DepthInputFiles must be greater than or equal to NumberOfViews" );
813    xConfirmPara  ( Int( m_pchDepthReconFileList.size() ) < m_iNumberOfViews,         "Number of DepthReconFiles must be greater than or equal to NumberOfViews" );
814
815#if HHI_VSO
816    if( m_bUseVSO )
817    {
818      xConfirmPara( m_pchCameraParameterFile    == 0                             ,   "CameraParameterFile must be given");
819      xConfirmPara(   m_pchVSOConfig            == 0                             ,   "VSO Setup string must be given");
820      xConfirmPara( m_pchBaseViewCameraNumbers  == 0                             ,   "BaseViewCameraNumbers must be given" );
821      xConfirmPara( m_iNumberOfViews != m_cCameraData.getBaseViewNumbers().size(),   "Number of Views in BaseViewCameraNumbers must be equal to NumberOfViews" );
822      xConfirmPara( m_uiVSOMode < 0 || m_uiVSOMode > 4 ,                             "VSO Mode must be greater than or equal to 0 and less than 5");
823      xConfirmPara( m_iNumberOfExternalRefs               > MAX_ERREF_VIEW_NUM,      "NumberOfExternalRefs must be less than of equal to TAppMVEncCfg::MAX_ERREF_VIEW_NUM" );
824      xConfirmPara( Int( m_pchERRefFileList .size() ) < m_iNumberOfExternalRefs,     "Number of ERRefFileFiles  must be greater than or equal to NumberOfExternalRefs" );
825    }
826#endif
827  }
828
829#if DCM_COMB_LIST
830#if !HHI_NO_LowDelayCoding
831  xConfirmPara( m_bUseLComb==false && m_bUseLDC==false,         "LComb can only be 0 if LowDelayCoding is 1" );
832#else
833  xConfirmPara( m_bUseLComb==false,                             "LComb can only be 0 if LowDelayCoding is 1" );
834#endif
835#endif
836
837  // max CU width and height should be power of 2
838  UInt ui = m_uiMaxCUWidth;
839  while(ui)
840  {
841    ui >>= 1;
842    if( (ui & 1) == 1)
843      xConfirmPara( ui != 1 , "Width should be 2^n");
844  }
845  ui = m_uiMaxCUHeight;
846  while(ui)
847  {
848    ui >>= 1;
849    if( (ui & 1) == 1)
850      xConfirmPara( ui != 1 , "Height should be 2^n");
851  }
852
853  // SBACRD is supported only for SBAC
854  if ( m_iSymbolMode == 0 )
855  {
856    m_bUseSBACRD = false;
857  }
858
859#undef xConfirmPara
860  if (check_failed)
861  {
862    exit(EXIT_FAILURE);
863  }
864}
865
866template <class T>
867Void
868TAppEncCfg::xCleanUpVector( std::vector<T>& rcVec, const T& rcInvalid )
869{
870  Int iFirstInv = (Int)rcVec.size();
871  for( Int iIdx = 0; iIdx < (Int)rcVec.size(); iIdx++ )
872  {
873    if( rcVec[ iIdx ] == rcInvalid )
874    {
875      iFirstInv = iIdx;
876      break;
877    }
878  }
879  while( (Int)rcVec.size() > iFirstInv )
880  {
881    rcVec.pop_back();
882  }
883}
884
885Void
886TAppEncCfg::xCleanUpVectors()
887{
888  xCleanUpVector( m_pchInputFileList,       (char*)0 );
889  xCleanUpVector( m_pchDepthInputFileList,  (char*)0 );
890  xCleanUpVector( m_pchReconFileList,       (char*)0 );
891  xCleanUpVector( m_pchDepthReconFileList,  (char*)0 );
892
893#if HHI_VSO
894  if ( m_bUseVSO)
895  {
896    xCleanUpVector( m_pchERRefFileList,       (char*)0 );
897  }
898#endif
899}
900
901/** \todo use of global variables should be removed later
902 */
903Void TAppEncCfg::xSetGlobal()
904{
905  // set max CU width & height
906  g_uiMaxCUWidth  = m_uiMaxCUWidth;
907  g_uiMaxCUHeight = m_uiMaxCUHeight;
908
909  // compute actual CU depth with respect to config depth and max transform size
910  g_uiAddCUDepth  = 0;
911  while( (m_uiMaxCUWidth>>m_uiMaxCUDepth) > ( 1 << ( m_uiQuadtreeTULog2MinSize + g_uiAddCUDepth )  ) ) g_uiAddCUDepth++;
912
913  m_uiMaxCUDepth += g_uiAddCUDepth;
914  g_uiAddCUDepth++;
915  g_uiMaxCUDepth = m_uiMaxCUDepth;
916
917  // set internal bit-depth and constants
918#if ENABLE_IBDI
919  if ((int)m_uiBitIncrement != -1)
920  {
921    g_uiBitDepth = m_uiInputBitDepth;
922    g_uiBitIncrement = m_uiBitIncrement;
923    m_uiInternalBitDepth = g_uiBitDepth + g_uiBitIncrement;
924  }
925  else
926  {
927    g_uiBitDepth = min(8u, m_uiInputBitDepth);
928    if (m_uiInternalBitDepth == 0) {
929      /* default increement = 2 */
930      m_uiInternalBitDepth = 2 + g_uiBitDepth;
931    }
932    g_uiBitIncrement = m_uiInternalBitDepth - g_uiBitDepth;
933  }
934#else
935#if FULL_NBIT
936  g_uiBitDepth = m_uiInternalBitDepth;
937  g_uiBitIncrement = 0;
938#else
939  g_uiBitDepth = 8;
940  g_uiBitIncrement = m_uiInternalBitDepth - g_uiBitDepth;
941#endif
942#endif
943#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
944  g_dDeltaDCsQuantOffset = Double(g_uiBitIncrement) -  2.0;
945#endif
946
947  g_uiBASE_MAX     = ((1<<(g_uiBitDepth))-1);
948
949#if IBDI_NOCLIP_RANGE
950  g_uiIBDI_MAX     = g_uiBASE_MAX << g_uiBitIncrement;
951#else
952  g_uiIBDI_MAX     = ((1<<(g_uiBitDepth+g_uiBitIncrement))-1);
953#endif
954
955  if (m_uiOutputBitDepth == 0)
956  {
957    m_uiOutputBitDepth = m_uiInternalBitDepth;
958  }
959}
960
961Void TAppEncCfg::xPrintParameter()
962{
963  printf("\n");
964  for( Int iCounter = 0; iCounter<m_iNumberOfViews; iCounter++)
965  {
966    printf("Input          File %i        : %s\n", iCounter, m_pchInputFileList[iCounter]);
967  }
968  for( Int iCounter = 0; iCounter < (Int)m_pchDepthInputFileList.size(); iCounter++)
969  {
970    printf("DepthInput     File %i        : %s\n", iCounter, m_pchDepthInputFileList[iCounter]);
971  }
972  printf("Bitstream      File          : %s\n", m_pchBitstreamFile      );
973  for( Int iCounter = 0; iCounter<m_iNumberOfViews; iCounter++)
974  {
975    printf("Reconstruction File %i        : %s\n", iCounter, m_pchReconFileList[iCounter]);
976  }
977
978  for( Int iCounter = 0; iCounter<(Int)m_pchDepthReconFileList.size(); iCounter++)
979  {
980    printf("Reconstruction Depth File %i  : %s\n", iCounter, m_pchDepthReconFileList[iCounter]);
981  }
982  printf("Real     Format              : %dx%d %dHz\n", m_iSourceWidth - m_aiPad[0], m_iSourceHeight-m_aiPad[1], m_iFrameRate );
983  printf("Internal Format              : %dx%d %dHz\n", m_iSourceWidth, m_iSourceHeight, m_iFrameRate );
984  printf("Frame index                  : %u - %d (%d frames)\n", m_FrameSkip, m_FrameSkip+m_iFrameToBeEncoded-1, m_iFrameToBeEncoded );
985  printf("CU size / depth              : %d / %d\n", m_uiMaxCUWidth, m_uiMaxCUDepth );
986  printf("RQT trans. size (min / max)  : %d / %d\n", 1 << m_uiQuadtreeTULog2MinSize, 1 << m_uiQuadtreeTULog2MaxSize );
987  printf("Max RQT depth inter          : %d\n", m_uiQuadtreeTUMaxDepthInter);
988  printf("Max RQT depth intra          : %d\n", m_uiQuadtreeTUMaxDepthIntra);
989  printf("Motion search range          : %d\n", m_iSearchRange );
990#if DCM_DECODING_REFRESH
991  printf("Decoding refresh type        : %d\n", m_iDecodingRefreshType );
992#endif
993  printf("QP                           : %5.2f\n", m_adQP[0] );
994  printf("QP Depth                     : %5.2f\n", m_adQP[ m_adQP.size()  < 2 ? 0 : 1] );
995  printf("Coded Picture Store Size     : %d\n", m_uiCodedPictureStoreSize);
996  printf("GOP size                     : %d\n", m_iGOPSize );
997  printf("Rate GOP size                : %d\n", m_iRateGOPSize );
998  printf("Internal bit depth           : %d\n", m_uiInternalBitDepth );
999
1000  if ( m_iSymbolMode == 0 )
1001  {
1002    printf("Entropy coder                : VLC\n");
1003  }
1004  else if( m_iSymbolMode == 1 )
1005  {
1006    printf("Entropy coder                : CABAC\n");
1007  }
1008  else if( m_iSymbolMode == 2 )
1009  {
1010    printf("Entropy coder                : PIPE\n");
1011  }
1012  else
1013  {
1014    assert(0);
1015  }
1016
1017  printf("GOP Format String            : %s\n", m_cInputFormatString.c_str() );
1018  printf("Loop Filter Disabled         : %d %d\n", m_abLoopFilterDisable[0] ? 1 : 0,  m_abLoopFilterDisable[1] ? 1 : 0 );
1019  printf("Coded Camera Param. Precision: %d\n", m_iCodedCamParPrecision);
1020
1021#if HHI_VSO
1022  printf("Force use of Lambda Scale    : %d\n", m_bForceLambdaScaleVSO );
1023
1024  if ( m_bUseVSO )
1025  {
1026    printf("VSO Lambda Scale             : %5.2f\n", m_dLambdaScaleVSO );
1027    printf("VSO Mode                     : %d\n",    m_uiVSOMode       );
1028    printf("VSO Config                   : %s\n",    m_pchVSOConfig    );
1029#if HHI_VSO_DIST_INT
1030    printf("VSO Negative Distortion      : %d\n",    m_bAllowNegDist ? 1 : 0);
1031#endif
1032  }
1033#endif
1034
1035
1036  printf("\n");
1037
1038  printf("TOOL CFG GENERAL: ");
1039  printf("IBD:%d ", !!g_uiBitIncrement);
1040  printf("HAD:%d ", m_bUseHADME           );
1041  printf("SRD:%d ", m_bUseSBACRD          );
1042  printf("SQP:%d ", m_uiDeltaQpRD         );
1043  printf("ASR:%d ", m_bUseASR             );
1044  printf("PAD:%d ", m_bUsePAD             );
1045  printf("LDC:%d ", m_bUseLDC             );
1046#if DCM_COMB_LIST
1047  printf("LComb:%d ", m_bUseLComb         );
1048  printf("LCMod:%d ", m_bLCMod         );
1049#endif
1050  printf("FEN:%d ", m_bUseFastEnc         );
1051  printf("RQT:%d ", 1     );
1052  printf("MRG:%d ", m_bUseMRG             ); // SOPH: Merge Mode
1053#if LM_CHROMA
1054  printf("LMC:%d ", m_bUseLMChroma        );
1055#endif
1056#if HHI_RMP_SWITCH
1057  printf("RMP:%d ", m_bUseRMP);
1058#endif
1059  printf("Slice:%d ",m_iSliceMode);
1060  if (m_iSliceMode!=0)
1061  {
1062    printf("(%d) ", m_iSliceArgument);
1063  }
1064  printf("EntropySlice:%d ",m_iEntropySliceMode);
1065  if (m_iEntropySliceMode!=0)
1066  {
1067    printf("(%d) ", m_iEntropySliceArgument);
1068  }
1069#if CONSTRAINED_INTRA_PRED
1070  printf("CIP:%d ", m_bUseConstrainedIntraPred);
1071#endif
1072#if MTK_SAO
1073#endif
1074
1075#if POZNAN_MP
1076  printf("POZNAN_MP(1){ ");
1077
1078#if POZNAN_MP_USE_DEPTH_MAP_GENERATION
1079  printf("dmg=1 ");
1080#else
1081  printf("dmg=0 ");
1082#endif
1083
1084#if POZNAN_MP_FILL
1085  printf("fill=%d ",POZNAN_MP_FILL_TYPE);
1086#else
1087  printf("fill=- ");
1088#endif
1089
1090#if POZNAN_DBMP
1091  printf("DBMP:%d ", m_uiDBMP);
1092  if(m_uiDBMP)
1093  {   
1094        printf("cand=%d ",POZNAN_DBMP_MERGE_POS);
1095#if POZNAN_DBMP_CALC_PRED_DATA
1096        printf("pr=1 ");
1097#else
1098        printf("pr=0 ");
1099#endif
1100#if POZNAN_DBMP_COMPRESS_ME_DATA
1101        printf("comp=1 ");
1102#else
1103        printf("comp=0 ");
1104#endif
1105#if POZNAN_DBMP_USE_IN_NONANCHOR_PIC_ONLY
1106        printf("na=1 ");
1107#else
1108        printf("na=0 ");
1109#endif
1110  }
1111#endif
1112  printf("} ");
1113#endif
1114
1115#if POZNAN_ENCODE_ONLY_DISOCCLUDED_CU
1116  printf("CU-Skip:%d ", m_uiUseCUSkip);
1117#endif
1118
1119  printf("\n");
1120  printf("TOOL CFG VIDEO  : ");
1121  printf("ALF:%d ", (m_abUseALF [0] ? 1 : 0) );
1122  printf("SAO:%d ", (m_abUseSAO [0] ? 1 : 0));
1123  printf("RDQ:%d ", (m_abUseRDOQ[0] ? 1 : 0) );
1124#if POZNAN_TEXTURE_TU_DELTA_QP_ACCORDING_TO_DEPTH
1125  printf("TDdQP:%d ", m_bUseTexDqpAccordingToDepth);
1126#endif
1127
1128  printf("\n");
1129
1130  printf("TOOL CFG DEPTH  : ");
1131  printf("ALF:%d ", (m_abUseALF [1] ? 1 : 0));
1132  printf("SAO:%d ", (m_abUseSAO [1] ? 1 : 0));
1133  printf("RDQ:%d ", (m_abUseRDOQ[1] ? 1 : 0));
1134#if HHI_VSO
1135  printf("VSO:%d ", m_bUseVSO             );
1136#endif
1137#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
1138  printf("DMM:%d ", m_bUseDMM );
1139#endif
1140#if HHI_MPI
1141  printf("MVI:%d ", m_bUseMVI ? 1 : 0 );
1142#endif
1143#if POZNAN_NONLINEAR_DEPTH
1144  printf("NLDR:%d ", m_bUseNonlinearDepth ? 1 : 0);
1145#endif
1146  printf("\n");
1147
1148  fflush(stdout);
1149}
1150
1151Void TAppEncCfg::xPrintUsage()
1152{
1153  printf( "          <name> = ALF - adaptive loop filter\n");
1154  printf( "                   IBD - bit-depth increasement\n");
1155  printf( "                   GPB - generalized B instead of P in low-delay mode\n");
1156  printf( "                   HAD - hadamard ME for fractional-pel\n");
1157  printf( "                   SRD - SBAC based RD estimation\n");
1158  printf( "                   RDQ - RDOQ\n");
1159  printf( "                   LDC - low-delay mode\n");
1160  printf( "                   NRF - non-reference frame marking in last layer\n");
1161  printf( "                   BQP - hier-P style QP assignment in low-delay mode\n");
1162  printf( "                   PAD - automatic source padding of multiple of 16\n");
1163  printf( "                   ASR - adaptive motion search range\n");
1164  printf( "                   FEN - fast encoder setting\n");
1165  printf( "                   MRG - merging of motion partitions\n"); // SOPH: Merge Mode
1166
1167#if LM_CHROMA
1168  printf( "                   LMC - intra chroma prediction based on luma\n");
1169#endif
1170
1171  printf( "\n" );
1172  printf( "  Example 1) TAppEncoder.exe -c test.cfg -q 32 -g 8 -f 9 -s 64 -h 4\n");
1173  printf("              -> QP 32, hierarchical-B GOP 8, 9 frames, 64x64-8x8 CU (~4x4 PU)\n\n");
1174  printf( "  Example 2) TAppEncoder.exe -c test.cfg -q 32 -g 4 -f 9 -s 64 -h 4 -1 LDC\n");
1175  printf("              -> QP 32, hierarchical-P GOP 4, 9 frames, 64x64-8x8 CU (~4x4 PU)\n\n");
1176}
1177
1178Bool confirmPara(Bool bflag, const char* message)
1179{
1180  if (!bflag)
1181    return false;
1182
1183  printf("Error: %s\n",message);
1184  return true;
1185}
1186
1187/* helper function */
1188/* for handling "-1/-0 FOO" */
1189void translateOldStyleCmdline(const char* value, po::Options& opts, const std::string& arg)
1190{
1191  const char* argv[] = {arg.c_str(), value};
1192  /* replace some short names with their long name varients */
1193  if (arg == "LDC")
1194  {
1195    argv[0] = "LowDelayCoding";
1196  }
1197  else if (arg == "RDQ")
1198  {
1199    argv[0] = "RDOQ";
1200  }
1201  else if (arg == "HAD")
1202  {
1203    argv[0] = "HadamardME";
1204  }
1205  else if (arg == "SRD")
1206  {
1207    argv[0] = "SBACRD";
1208  }
1209  else if (arg == "IBD")
1210  {
1211    argv[0] = "BitIncrement";
1212  }
1213  /* issue a warning for change in FEN behaviour */
1214  if (arg == "FEN")
1215  {
1216    /* xxx todo */
1217  }
1218  po::storePair(opts, argv[0], argv[1]);
1219}
1220
1221void doOldStyleCmdlineOn(po::Options& opts, const std::string& arg)
1222{
1223  if (arg == "IBD")
1224  {
1225    translateOldStyleCmdline("4", opts, arg);
1226    return;
1227  }
1228  translateOldStyleCmdline("1", opts, arg);
1229}
1230
1231void doOldStyleCmdlineOff(po::Options& opts, const std::string& arg)
1232{
1233  translateOldStyleCmdline("0", opts, arg);
1234}
1235
1236Void TAppEncCfg::xAppendToFileNameEnd( Char* pchInputFileName, const Char* pchStringToAppend, Char*& rpchOutputFileName)
1237{
1238  size_t iInLength     = strlen(pchInputFileName);
1239  size_t iAppendLength = strlen(pchStringToAppend);
1240
1241  rpchOutputFileName = (Char*) malloc(iInLength+iAppendLength+1);
1242  Char* pCDot = strrchr(pchInputFileName,'.');
1243  pCDot = pCDot ? pCDot : pchInputFileName + iInLength;
1244  size_t iCharsToDot = pCDot - pchInputFileName ;
1245  size_t iCharsToEnd = iInLength - iCharsToDot;
1246  strncpy(rpchOutputFileName                            ,  pchInputFileName            , iCharsToDot  );
1247  strncpy(rpchOutputFileName+ iCharsToDot               ,  pchStringToAppend           , iAppendLength);
1248  strncpy(rpchOutputFileName+ iCharsToDot+iAppendLength ,  pchInputFileName+iCharsToDot, iCharsToEnd  );
1249  rpchOutputFileName[iInLength+iAppendLength] = '\0';
1250}
Note: See TracBrowser for help on using the repository browser.