Index: trunk/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 42)
+++ trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 56)
@@ -2,7 +2,7 @@
  * License, included below. This software may be subject to other third party
  * and contributor rights, including patent rights, and no such rights are
- * granted under this license.
+ * granted under this license.  
  *
- * Copyright (c) 2010-2011, ISO/IEC
+ * Copyright (c) 2010-2012, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -15,5 +15,5 @@
  *    this list of conditions and the following disclaimer in the documentation
  *    and/or other materials provided with the distribution.
- *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
  *    be used to endorse or promote products derived from this software without
  *    specific prior written permission.
@@ -32,6 +32,4 @@
  */
 
-
-
 /** \file     TAppEncCfg.cpp
     \brief    Handle encoder configuration parameters
@@ -39,14 +37,20 @@
 
 #include <stdlib.h>
-#include <math.h>
 #include <cassert>
 #include <cstring>
 #include <string>
+#include "TLibCommon/TComRom.h"
 #include "TAppEncCfg.h"
-#include "../../App/TAppCommon/program_options_lite.h"
-
+#include "TAppCommon/program_options_lite.h"
+
+#ifdef WIN32
+#define strdup _strdup
+#endif
 
 using namespace std;
 namespace po = df::program_options_lite;
+
+//! \ingroup TAppEncoder
+//! \{
 
 /* configuration helper funcs */
@@ -62,6 +66,4 @@
  */
 #define MAX_PAD_SIZE                16
-#define MAX_INPUT_VIEW_NUM          10
-#define MAX_ERREF_VIEW_NUM          15
 
 // ====================================================================================================================
@@ -72,7 +74,4 @@
 {
   m_aidQP = NULL;
-#if HHI_VSO
-  m_aaiERViewRefLutInd.resize( MAX_INPUT_VIEW_NUM );
-#endif
 }
 
@@ -88,5 +87,4 @@
       free (m_pchInputFileList[i]);
   }
-
   for(Int i = 0; i< m_pchDepthInputFileList.size(); i++ )
   {
@@ -94,5 +92,4 @@
       free (m_pchDepthInputFileList[i]);
   }
-
   for(Int i = 0; i< m_pchReconFileList.size(); i++ )
   {
@@ -100,32 +97,11 @@
       free (m_pchReconFileList[i]);
   }
-
-  for(Int i = 0; i< m_pchERRefFileList.size(); i++ )
-  {
-    if ( m_pchERRefFileList[i] != NULL )
-      free (m_pchERRefFileList[i]);
-  }
-
+  for(Int i = 0; i< m_pchDepthReconFileList.size(); i++ )
+  {
+    if ( m_pchDepthReconFileList[i] != NULL )
+      free (m_pchDepthReconFileList[i]);
+  }
   if (m_pchBitstreamFile != NULL)
     free (m_pchBitstreamFile) ;
-
-#if FLEX_CODING_ORDER
-  if (m_pchMVCJointCodingOrder != NULL)
-  {
-	  free(m_pchMVCJointCodingOrder) ;
-  }
-#endif
-  for(Int i = 0; i< m_pchDepthReconFileList.size(); i++ )
-  {
-    if ( m_pchDepthReconFileList[i] != NULL )
-      free (m_pchDepthReconFileList[i]);
-  }
-
-  if (m_pchCameraParameterFile != NULL)
-    free (m_pchCameraParameterFile);
-
-  if (m_pchBaseViewCameraNumbers != NULL)
-    free (m_pchBaseViewCameraNumbers);
-
 #if HHI_VSO
   if (  m_pchVSOConfig != NULL)
@@ -141,4 +117,45 @@
 Void TAppEncCfg::destroy()
 {
+}
+
+std::istringstream &operator>>( std::istringstream &in, GOPEntryMvc &entry )     //input
+{
+  in>>entry.m_sliceType;
+  in>>entry.m_POC;
+  in>>entry.m_QPOffset;
+  in>>entry.m_QPFactor;
+  in>>entry.m_temporalId;
+  in>>entry.m_numRefPicsActive;
+  in>>entry.m_refPic;
+  in>>entry.m_numRefPics;
+  for ( Int i = 0; i < entry.m_numRefPics; i++ )
+  {
+    in>>entry.m_referencePics[i];
+  }
+  in>>entry.m_interRPSPrediction;
+  if (entry.m_interRPSPrediction)
+  {
+    in>>entry.m_deltaRIdxMinus1;
+    in>>entry.m_deltaRPS;
+    in>>entry.m_numRefIdc;
+    for ( Int i = 0; i < entry.m_numRefIdc; i++ )
+    {
+      in>>entry.m_refIdc[i];
+    }
+  }
+  in>>entry.m_numInterViewRefPics;
+  for( Int i = 0; i < entry.m_numInterViewRefPics; i++ )
+  {
+    in>>entry.m_interViewRefs[i];
+  }
+  for( Int i = 0; i < entry.m_numInterViewRefPics; i++ )
+  {
+    in>>entry.m_interViewRefPosL0[i];
+  }
+  for( Int i = 0; i < entry.m_numInterViewRefPics; i++ )
+  {
+    in>>entry.m_interViewRefPosL1[i];
+  }
+  return in;
 }
 
@@ -154,57 +171,53 @@
 {
   bool do_help = false;
-
-  string cfg_InputFile;
+  
   string cfg_BitstreamFile;
-  string cfg_ReconFile;
   string cfg_dQPFile;
-
-#if FLEX_CODING_ORDER
-  string cfg_JointCodingOrdering;
-#endif
-
+  string cfg_ColumnWidth;
+  string cfg_RowHeight;
+  string cfg_ScalingListFile;
   po::Options opts;
   opts.addOptions()
   ("help", do_help, false, "this help text")
   ("c", po::parseConfigFile, "configuration file name")
-
+  
   /* File, I/O and source parameters */
-  ("InputFile_%d,i_%d",       m_pchInputFileList,       (char *) 0 , MAX_INPUT_VIEW_NUM , "original Yuv input file name %d")
-  ("DepthInputFile_%d,di_%d", m_pchDepthInputFileList,  (char *) 0 , MAX_INPUT_VIEW_NUM , "original Yuv depth input file name %d")
-  ("ReconFile_%d,o_%d",       m_pchReconFileList,       (char *) 0 , MAX_INPUT_VIEW_NUM , "reconstructed Yuv output file name %d")
-  ("DepthReconFile_%d,do_%d", m_pchDepthReconFileList,  (char *) 0 , MAX_INPUT_VIEW_NUM , "reconstructed Yuv depth output file name %d")
+  ("InputFile_%d,i_%d",       m_pchInputFileList,       (char *) 0 , MAX_VIEW_NUM , "original Yuv input file name %d")
+  ("DepthInputFile_%d,di_%d", m_pchDepthInputFileList,  (char *) 0 , MAX_VIEW_NUM , "original Yuv depth input file name %d")
+  ("ReconFile_%d,o_%d",       m_pchReconFileList,       (char *) 0 , MAX_VIEW_NUM , "reconstructed Yuv output file name %d")
+  ("DepthReconFile_%d,do_%d", m_pchDepthReconFileList,  (char *) 0 , MAX_VIEW_NUM , "reconstructed Yuv depth output file name %d")
   ("BitstreamFile,b", cfg_BitstreamFile, string(""), "bitstream output file name")
-
   ("CodeDepthMaps",         m_bUsingDepthMaps, false, "Encode depth maps" )
   ("CodedCamParsPrecision", m_iCodedCamParPrecision, STD_CAM_PARAMETERS_PRECISION, "precision for coding of camera parameters (in units of 2^(-x) luma samples)" )
-
-#ifdef WEIGHT_PRED
-  ("weighted_pred_flag,-wpP",     m_bUseWeightPred, false, "weighted prediction flag (P-Slices)")
-  ("weighted_bipred_idc,-wpBidc", m_uiBiPredIdc,    0u,    "weighted bipred idc (B-Slices)")
-#endif
+  ("LambdaModifier0,-LM0", m_adLambdaModifier[ 0 ], ( double )1.0, "Lambda modifier for temporal layer 0")
+  ("LambdaModifier1,-LM1", m_adLambdaModifier[ 1 ], ( double )1.0, "Lambda modifier for temporal layer 1")
+  ("LambdaModifier2,-LM2", m_adLambdaModifier[ 2 ], ( double )1.0, "Lambda modifier for temporal layer 2")
+  ("LambdaModifier3,-LM3", m_adLambdaModifier[ 3 ], ( double )1.0, "Lambda modifier for temporal layer 3")
   ("SourceWidth,-wdt",      m_iSourceWidth,  0, "Source picture width")
   ("SourceHeight,-hgt",     m_iSourceHeight, 0, "Source picture height")
+#if PIC_CROPPING
+  ("CroppingMode",          m_croppingMode,  0, "Cropping mode (0: no cropping, 1:automatic padding, 2: padding, 3:cropping")
+  ("CropLeft",              m_cropLeft,      0, "Left cropping/padding for cropping mode 3")
+  ("CropRight",             m_cropRight,     0, "Right cropping/padding for cropping mode 3")
+  ("CropTop",               m_cropTop,       0, "Top cropping/padding for cropping mode 3")
+  ("CropBottom",            m_cropBottom,    0, "Bottom cropping/padding for cropping mode 3")
+  ("HorizontalPadding,-pdx",m_aiPad[0],      0, "horizontal source padding for cropping mode 2")
+  ("VerticalPadding,-pdy",  m_aiPad[1],      0, "vertical source padding for cropping mode 2")
+#endif
   ("InputBitDepth",         m_uiInputBitDepth, 8u, "bit-depth of input file")
   ("BitDepth",              m_uiInputBitDepth, 8u, "deprecated alias of InputBitDepth")
   ("OutputBitDepth",        m_uiOutputBitDepth, 0u, "bit-depth of output file")
-#if ENABLE_IBDI
-  ("BitIncrement",          m_uiBitIncrement, 0xffffffffu, "bit-depth increasement")
-#endif
   ("InternalBitDepth",      m_uiInternalBitDepth, 0u, "Internal bit-depth (BitDepth+BitIncrement)")
+#if !PIC_CROPPING
   ("HorizontalPadding,-pdx",m_aiPad[0],      0, "horizontal source padding size")
   ("VerticalPadding,-pdy",  m_aiPad[1],      0, "vertical source padding size")
   ("PAD",                   m_bUsePAD,   false, "automatic source padding of multiple of 16" )
+#endif
   ("FrameRate,-fr",         m_iFrameRate,        0, "Frame rate")
   ("FrameSkip,-fs",         m_FrameSkip,         0u, "Number of frames to skip at start of input YUV")
   ("FramesToBeEncoded,f",   m_iFrameToBeEncoded, 0, "number of frames to be encoded (default=all)")
   ("FrameToBeEncoded",      m_iFrameToBeEncoded, 0, "depricated alias of FramesToBeEncoded")
-
+  
   ("NumberOfViews",         m_iNumberOfViews,    0, "Number of views")
-
-#if FLEX_CODING_ORDER
-  ("FCO",               m_b3DVFlexOrder,   false, "flexible coding order flag" )
-  ("CodingOrder",   		cfg_JointCodingOrdering,  string(""), "The coding order for joint texture-depth coding")
-#endif
-
   /* Unit definition parameters */
   ("MaxCUWidth",          m_uiMaxCUWidth,  64u)
@@ -214,28 +227,24 @@
   ("MaxCUSize,s",         m_uiMaxCUHeight, 64u, "max CU size")
   ("MaxPartitionDepth,h", m_uiMaxCUDepth,   4u, "CU depth")
-
+  
   ("QuadtreeTULog2MaxSize", m_uiQuadtreeTULog2MaxSize, 6u)
   ("QuadtreeTULog2MinSize", m_uiQuadtreeTULog2MinSize, 2u)
-
+  
   ("QuadtreeTUMaxDepthIntra", m_uiQuadtreeTUMaxDepthIntra, 1u)
   ("QuadtreeTUMaxDepthInter", m_uiQuadtreeTUMaxDepthInter, 2u)
-
+  
   /* Coding structure paramters */
-  ("CodedPictureStoreSize,cpss",  m_uiCodedPictureStoreSize, 16u, "Size of coded picture Buffer")
-#if DCM_DECODING_REFRESH
-  ("DecodingRefreshType,-dr",m_iDecodingRefreshType, 0, "intra refresh, (0:none 1:CDR 2:IDR)")
-#endif
+  ("IntraPeriod,-ip",m_iIntraPeriod, -1, "intra period in frames, (-1: only first frame)")
+  ("DecodingRefreshType,-dr",m_iDecodingRefreshType, 0, "intra refresh, (0:none 1:CRA 2:IDR)")
   ("GOPSize,g",      m_iGOPSize,      1, "GOP size of temporal structure")
-  ("RateGOPSize,-rg",m_iRateGOPSize, -1, "GOP size of hierarchical QP assignment (-1: implies inherit GOPSize value)")
-#if !HHI_NO_LowDelayCoding
-  ("LowDelayCoding",         m_bUseLDC,             false, "low-delay mode")
-#endif
-#if DCM_COMB_LIST
-  ("ListCombination, -lc", m_bUseLComb, true, "combined reference list for uni-prediction in B-slices")
+#if !H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER
+  ("MaxNumberOfReorderPictures",   m_numReorderFrames,               -1, "Max. number of reorder pictures: -1: encoder determines value, >=0: set explicitly")
+  ("MaxNumberOfReferencePictures", m_maxNumberOfReferencePictures, 6, "Max. number of reference pictures")
+#endif
+  ("ListCombination,-lc", m_bUseLComb, true, "combined reference list flag for uni-prediction in B-slices")
   ("LCModification", m_bLCMod, false, "enables signalling of combined reference list derivation")
-#endif
-
-  ("GOPFormatString,gfs", m_cInputFormatString,  string(""), "Group of pictures")
-
+  ("DisableInter4x4", m_bDisInter4x4, true, "Disable Inter 4x4")
+  ("NSQT", m_enableNSQT, true, "Enable non-square transforms")
+  ("AMP", m_enableAMP, true, "Enable asymmetric motion partitions")
   /* motion options */
   ("FastSearch", m_iFastSearch, 1, "0:Full search  1:Diamond  2:PMVFAST")
@@ -244,30 +253,48 @@
   ("HadamardME", m_bUseHADME, true, "hadamard ME for fractional-pel")
   ("ASR", m_bUseASR, false, "adaptive motion search range")
-
+  
   /* Quantization parameters */
   ("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")
   ("DeltaQpRD,-dqr",m_uiDeltaQpRD,       0u, "max dQp offset for slice")
   ("MaxDeltaQP,d",  m_iMaxDeltaQP,        0, "max dQp offset for block")
-  ("dQPFile,m",     m_pchdQPFile , (char*) 0, "dQP file name")
+  ("MaxCuDQPDepth,-dqd",  m_iMaxCuDQPDepth,        0, "max depth for a minimum CuDQP")
+
+    ("ChromaQpOffset,   -cqo",   m_iChromaQpOffset,           0, "ChromaQpOffset")
+    ("ChromaQpOffset2nd,-cqo2",  m_iChromaQpOffset2nd,        0, "ChromaQpOffset2nd")
+
+#if ADAPTIVE_QP_SELECTION
+    ("AdaptiveQpSelection,-aqps",   m_bUseAdaptQpSelect,           false, "AdaptiveQpSelection")
+#endif
+
+  ("AdaptiveQP,-aq", m_bUseAdaptiveQP, false, "QP adaptation based on a psycho-visual model")
+  ("MaxQPAdaptationRange,-aqr", m_iQPAdaptationRange, 6, "QP adaptation range")
+  ("dQPFile,m",     cfg_dQPFile, string(""), "dQP file name")
   ("RDOQ",          m_abUseRDOQ, std::vector<Bool>(1,true), "Enable RDOQ")
-  ("TemporalLayerQPOffset_L0,-tq0", m_aiTLayerQPOffset[0], 0, "QP offset of temporal layer 0")
-  ("TemporalLayerQPOffset_L1,-tq1", m_aiTLayerQPOffset[1], 0, "QP offset of temporal layer 1")
-  ("TemporalLayerQPOffset_L2,-tq2", m_aiTLayerQPOffset[2], 0, "QP offset of temporal layer 2")
-  ("TemporalLayerQPOffset_L3,-tq3", m_aiTLayerQPOffset[3], 0, "QP offset of temporal layer 3")
-  ("TemporalLayerQPOffset_L4,-tq4", m_aiTLayerQPOffset[4], 0, "QP offset of temporal layer 3")
-  ("TemporalLayerQPOffset_L5,-tq5", m_aiTLayerQPOffset[5], 0, "QP offset of temporal layer 3")
-  ("TemporalLayerQPOffset_L6,-tq6", m_aiTLayerQPOffset[6], 0, "QP offset of temporal layer 3")
-  ("TemporalLayerQPOffset_L7,-tq7", m_aiTLayerQPOffset[7], 0, "QP offset of temporal layer 3")
-  ("TemporalLayerQPOffset_L8,-tq8", m_aiTLayerQPOffset[8], 0, "QP offset of temporal layer 3")
-  ("TemporalLayerQPOffset_L9,-tq9", m_aiTLayerQPOffset[9], 0, "QP offset of temporal layer 3")
+  ("TemporalLayerQPOffset_L0,-tq0", m_aiTLayerQPOffset[0], MAX_QP + 1, "QP offset of temporal layer 0")
+  ("TemporalLayerQPOffset_L1,-tq1", m_aiTLayerQPOffset[1], MAX_QP + 1, "QP offset of temporal layer 1")
+  ("TemporalLayerQPOffset_L2,-tq2", m_aiTLayerQPOffset[2], MAX_QP + 1, "QP offset of temporal layer 2")
+  ("TemporalLayerQPOffset_L3,-tq3", m_aiTLayerQPOffset[3], MAX_QP + 1, "QP offset of temporal layer 3")
+  
+#if !H0566_TLA
+  ("TLayeringBasedOnCodingStruct,-tl", m_bTLayering, false, "Temporal ID is set based on the hierarchical coding structure")
+  
+  ("TLayerSwitchingFlag_L0,-ts0", m_abTLayerSwitchingFlag[0], false, "Switching flag for temporal layer 0")
+  ("TLayerSwitchingFlag_L1,-ts1", m_abTLayerSwitchingFlag[1], false, "Switching flag for temporal layer 1")
+  ("TLayerSwitchingFlag_L2,-ts2", m_abTLayerSwitchingFlag[2], false, "Switching flag for temporal layer 2")
+  ("TLayerSwitchingFlag_L3,-ts3", m_abTLayerSwitchingFlag[3], false, "Switching flag for temporal layer 3")
+#endif
 
   /* Entropy coding parameters */
-  ("SymbolMode,-sym", m_iSymbolMode, 1, "symbol mode (0=VLC, 1=SBAC)")
   ("SBACRD", m_bUseSBACRD, true, "SBAC based RD estimation")
-
+  
   /* Deblocking filter parameters */
   ("LoopFilterDisable", m_abLoopFilterDisable, std::vector<Bool>(1,false), "Disables LoopFilter")
-  ("LoopFilterAlphaC0Offset", m_iLoopFilterAlphaC0Offset, 0)
-  ("LoopFilterBetaOffset", m_iLoopFilterBetaOffset, 0 )
+
+  ("LoopFilterOffsetInAPS", m_loopFilterOffsetInAPS, false)
+  ("LoopFilterBetaOffset_div2", m_loopFilterBetaOffsetDiv2, 0 )
+  ("LoopFilterTcOffset_div2", m_loopFilterTcOffsetDiv2, 0 )
+#if DBL_CONTROL
+  ("DeblockingFilterControlPresent", m_DeblockingFilterControlPresent, false)
+#endif
 
   /* Camera Paremetes */
@@ -275,6 +302,5 @@
   ("BaseViewCameraNumbers" ,  m_pchBaseViewCameraNumbers,  (Char *) 0, "Numbers of base views")
 
-
-    /* View Synthesis Optimization */
+  /* View Synthesis Optimization */
 
 #if HHI_VSO
@@ -293,81 +319,135 @@
 #endif
 
-    ("NumberOfExternalRefs",            m_iNumberOfExternalRefs   , 0             , "Number of virtual external reference views")
-    ("ERRefFile_%d,er_%d",              m_pchERRefFileList        , (char *) 0    , MAX_ERREF_VIEW_NUM , "virtual external reference view file name %d")
-    ("VSERViewReferences_%d,evr_%d"  ,  m_aaiERViewRefInd         , vector<Int>() , MAX_INPUT_VIEW_NUM, "Numbers of external virtual reference views to be used for this view")
-    ("VSBaseViewReferences_%d,bvr_%d",  m_aaiBaseViewRefInd       , vector<Int>() , MAX_INPUT_VIEW_NUM, "Numbers of external virtual reference views to be used for this view")
+#endif
+
+#if DEPTH_MAP_GENERATION
+  ("PredDepthMapGen",  m_uiPredDepthMapGeneration, (UInt)0, "generation of prediction depth maps for motion data prediction" )
+#endif
+#if HHI_INTER_VIEW_MOTION_PRED
+  ("MultiviewMvPred",  m_uiMultiviewMvPredMode,    (UInt)0, "usage of predicted depth maps" )
+  ("MultiviewMvRegMode",        m_uiMultiviewMvRegMode,         (UInt)0, "regularization mode for multiview motion vectors" )
+  ("MultiviewMvRegLambdaScale", m_dMultiviewMvRegLambdaScale, (Double)0, "lambda scale for multiview motion vector regularization" )
+#endif
+#if HHI_INTER_VIEW_RESIDUAL_PRED
+  ("MultiviewResPred", m_uiMultiviewResPredMode,   (UInt)0, "usage of inter-view residual prediction" )
 #endif
 
   /* Coding tools */
-  ("MRG", m_bUseMRG, true, "merging of motion partitions")
-
-#if LM_CHROMA
   ("LMChroma", m_bUseLMChroma, true, "intra chroma prediction based on recontructed luma")
-#endif
 
   ("ALF", m_abUseALF, std::vector<Bool>(1,true), "Enables ALF")
-#if MTK_SAO
   ("SAO", m_abUseSAO, std::vector<Bool>(1, true), "SAO")
-#endif
-
-#if MQT_ALF_NPASS
+#if SAO_UNIT_INTERLEAVING
+  ("MaxNumOffsetsPerPic", m_maxNumOffsetsPerPic, 2048, "2048: default")   
+  ("SAOInterleaving", m_saoInterleavingFlag, false, "0: SAO Picture Mode, 1: SAO Interleaving ")   
+#endif
+
   ("ALFEncodePassReduction", m_iALFEncodePassReduction, 0, "0:Original 16-pass, 1: 1-pass, 2: 2-pass encoding")
-#endif
-#if HHI_RMP_SWITCH
-  ("RMP", m_bUseRMP ,true, "Rectangular motion partition" )
-#endif
-#ifdef ROUNDING_CONTROL_BIPRED
-  ("RoundingControlBipred", m_useRoundingControlBipred, false, "Rounding control for bi-prediction")
-#endif
+
+  ("ALFMaxNumFilter,-ALFMNF", m_iALFMaxNumberFilters, 16, "16: No Constrained, 1-15: Constrained max number of filter")
+#if LCU_SYNTAX_ALF
+  ("ALFParamInSlice", m_bALFParamInSlice, false, "ALF parameters in 0: APS, 1: slice header")
+  ("ALFPicBasedEncode", m_bALFPicBasedEncode, true, "ALF picture-based encoding 0: false, 1: true")
+#endif
+
     ("SliceMode",            m_iSliceMode,           0, "0: Disable all Recon slice limits, 1: Enforce max # of LCUs, 2: Enforce max # of bytes")
     ("SliceArgument",        m_iSliceArgument,       0, "if SliceMode==1 SliceArgument represents max # of LCUs. if SliceMode==2 SliceArgument represents max # of bytes.")
     ("EntropySliceMode",     m_iEntropySliceMode,    0, "0: Disable all entropy slice limits, 1: Enforce max # of LCUs, 2: Enforce constraint based entropy slices")
     ("EntropySliceArgument", m_iEntropySliceArgument,0, "if EntropySliceMode==1 SliceArgument represents max # of LCUs. if EntropySliceMode==2 EntropySliceArgument represents max # of bins.")
-#if MTK_NONCROSS_INLOOP_FILTER
+    ("SliceGranularity",     m_iSliceGranularity,    0, "0: Slices always end at LCU borders. 1-3: slices may end at a depth of 1-3 below LCU level.")
     ("LFCrossSliceBoundaryFlag", m_bLFCrossSliceBoundaryFlag, true)
-#endif
-#if CONSTRAINED_INTRA_PRED
-  ("ConstrainedIntraPred", m_bUseConstrainedIntraPred, false, "Constrained Intra Prediction")
-#endif
+
+    ("ConstrainedIntraPred", m_bUseConstrainedIntraPred, false, "Constrained Intra Prediction")
+    ("PCMEnabledFlag", m_usePCM         , false)
+    ("PCMLog2MaxSize", m_pcmLog2MaxSize, 5u)
+    ("PCMLog2MinSize", m_uiPCMLog2MinSize, 3u)
+
+    ("PCMInputBitDepthFlag", m_bPCMInputBitDepthFlag, true)
+    ("PCMFilterDisableFlag", m_bPCMFilterDisableFlag, false)
+#if LOSSLESS_CODING
+    ("LosslessCuEnabled", m_useLossless, false)
+#endif
+    ("weighted_pred_flag,-wpP",     m_bUseWeightPred, false, "weighted prediction flag (P-Slices)")
+    ("weighted_bipred_idc,-wpBidc", m_uiBiPredIdc,    0u,    "weighted bipred idc (B-Slices)")
+    ("TileInfoPresentFlag",         m_iColumnRowInfoPresent,         1,          "0: tiles parameters are NOT present in the PPS. 1: tiles parameters are present in the PPS")
+    ("UniformSpacingIdc",           m_iUniformSpacingIdr,            0,          "Indicates if the column and row boundaries are distributed uniformly")
+#if !REMOVE_TILE_DEPENDENCE
+    ("TileBoundaryIndependenceIdc", m_iTileBoundaryIndependenceIdr,  1,          "Indicates if the column and row boundaries break the prediction")
+#endif
+    ("NumTileColumnsMinus1",        m_iNumColumnsMinus1,             0,          "Number of columns in a picture minus 1")
+    ("ColumnWidthArray",            cfg_ColumnWidth,                 string(""), "Array containing ColumnWidth values in units of LCU")
+    ("NumTileRowsMinus1",           m_iNumRowsMinus1,                0,          "Number of rows in a picture minus 1")
+    ("RowHeightArray",              cfg_RowHeight,                   string(""), "Array containing RowHeight values in units of LCU")
+    ("TileLocationInSliceHeaderFlag", m_iTileLocationInSliceHeaderFlag, 0,       "0: Disable transmission of tile location in slice header. 1: Transmit tile locations in slice header.")
+    ("TileMarkerFlag",                m_iTileMarkerFlag,                0,       "0: Disable transmission of lightweight tile marker. 1: Transmit light weight tile marker.")
+    ("MaxTileMarkerEntryPoints",    m_iMaxTileMarkerEntryPoints,    4,       "Maximum number of uniformly-spaced tile entry points (using light weigh tile markers). Default=4. If number of tiles < MaxTileMarkerEntryPoints then all tiles have entry points.")
+    ("TileControlPresentFlag",       m_iTileBehaviorControlPresentFlag,         1,          "0: tiles behavior control parameters are NOT present in the PPS. 1: tiles behavior control parameters are present in the PPS")
+    ("LFCrossTileBoundaryFlag",      m_bLFCrossTileBoundaryFlag,             true,          "1: cross-tile-boundary loop filtering. 0:non-cross-tile-boundary loop filtering")
+    ("WaveFrontSynchro",            m_iWaveFrontSynchro,             0,          "0: no synchro; 1 synchro with TR; 2 TRR etc")
+    ("WaveFrontFlush",              m_iWaveFrontFlush,               0,          "Flush and terminate CABAC coding for each LCU line")
+    ("WaveFrontSubstreams",         m_iWaveFrontSubstreams,          1,          "# coded substreams wanted; per tile if TileBoundaryIndependenceIdc is 1, otherwise per frame")
+    ("ScalingList",                 m_useScalingListId,              0,          "0: no scaling list, 1: default scaling lists, 2: scaling lists specified in ScalingListFile")
+    ("ScalingListFile",             cfg_ScalingListFile,             string(""), "Scaling list file name")
+#if MULTIBITS_DATA_HIDING
+    ("SignHideFlag,-SBH",                m_signHideFlag, 1)
+    ("SignHideThreshold,-TSIG",          m_signHidingThreshold,         4)
+#endif
+#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
+  ("DMM",                         m_bUseDMM,                       false,      "depth model modes flag")
+#endif
+
   /* Misc. */
-  ("SEIpictureDigest", m_pictureDigestEnabled, false, "Control generation of picture_digest SEI messages\n"
+  ("SEIpictureDigest", m_pictureDigestEnabled, true, "Control generation of picture_digest SEI messages\n"
                                               "\t1: use MD5\n"
                                               "\t0: disable")
+
+  ("TMVP", m_enableTMVP, true, "Enable TMVP" )
+
   ("FEN", m_bUseFastEnc, false, "fast encoder setting")
-
-#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
-  ("DMM", m_bUseDMM, false, "add depth modes intra")
-#endif
-#if HHI_MPI
-  ("MVI", m_bUseMVI, false, "use motion vector inheritance for depth map coding")
-#endif
-
-  /* Multiview tools */
-#if DEPTH_MAP_GENERATION
-  ("PredDepthMapGen",  m_uiPredDepthMapGeneration, (UInt)0, "generation of prediction depth maps for motion data prediction" )
-#endif
-#if HHI_INTER_VIEW_MOTION_PRED
-  ("MultiviewMvPred",  m_uiMultiviewMvPredMode,    (UInt)0, "usage of predicted depth maps" )
-  ("MultiviewMvRegMode",        m_uiMultiviewMvRegMode,         (UInt)0, "regularization mode for multiview motion vectors" )
-  ("MultiviewMvRegLambdaScale", m_dMultiviewMvRegLambdaScale, (Double)0, "lambda scale for multiview motion vector regularization" )
-#endif
-#if HHI_INTER_VIEW_RESIDUAL_PRED
-  ("MultiviewResPred", m_uiMultiviewResPredMode,   (UInt)0, "usage of inter-view residual prediction" )
-#endif
-
-  ("QpChangeFrame", m_iQpChangeFrame, PicOrderCnt(0), "start frame for QP change")
-  ("QpChangeOffsetVideo", m_iQpChangeOffsetVideo, 0, "QP change offset for video")
-  ("QpChangeOffsetDepth", m_iQpChangeOffsetDepth, 0, "QP change offset for depth")
+  ("ECU", m_bUseEarlyCU, false, "Early CU setting") 
+#if FAST_DECISION_FOR_MRG_RD_COST
+  ("FDM", m_useFastDecisionForMerge, true, "Fast decision for Merge RD Cost") 
+#endif
+  ("CFM", m_bUseCbfFastMode, false, "Cbf fast mode setting")
 #if HHI_INTERVIEW_SKIP
-  ("InterViewSkip",  m_uiInterViewSkip,    (UInt)0, "usage of interview skip" )
+  ("InterViewSkip",  m_bInterViewSkip,    false, "usage of interview skip" )
 #if HHI_INTERVIEW_SKIP_LAMBDA_SCALE
   ("InterViewSkipLambdaScale",  m_dInterViewSkipLambdaScale,    (Double)8, "lambda scale for interview skip" )
 #endif
 #endif
-
   /* Compatability with old style -1 FOO or -0 FOO options. */
   ("1", doOldStyleCmdlineOn, "turn option <name> on")
   ("0", doOldStyleCmdlineOff, "turn option <name> off")
+#if HHI_MPI
+  ("MVI", m_bUseMVI, false, "use motion vector inheritance for depth map coding")
+#endif
   ;
+  
+  // parse coding structure
+  for( Int k = 0; k < MAX_VIEW_NUM; k++ )
+  {
+    if( k == 0 )
+    {
+      for( Int i = 1; i < MAX_GOP + 1; i++ ) 
+      {
+        std::ostringstream cOSS;
+        cOSS<<"Frame"<<i;
+        opts.addOptions()( cOSS.str(), m_GOPListsMvc[k][i-1], GOPEntryMvc() );
+      }
+    }
+    else
+    {
+      std::ostringstream cOSS1;
+      cOSS1<<"FrameI"<<"_v"<<k;
+      opts.addOptions()(cOSS1.str(), m_GOPListsMvc[k][MAX_GOP], GOPEntryMvc());
+
+      for( Int i = 1; i < MAX_GOP + 1; i++ ) 
+      {
+        std::ostringstream cOSS2;
+        cOSS2<<"Frame"<<i<<"_v"<<k;
+        opts.addOptions()(cOSS2.str(), m_GOPListsMvc[k][i-1], GOPEntryMvc());
+      }
+    }
+  }
 
   po::setDefaults(opts);
@@ -378,5 +458,5 @@
     fprintf(stderr, "Unhandled argument ignored: `%s'\n", *it);
   }
-
+  
   if (argc == 1 || do_help)
   {
@@ -386,5 +466,5 @@
     return false;
   }
-
+  
   /*
    * Set any derived parameters
@@ -393,42 +473,9 @@
   m_pchBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str());
   m_pchdQPFile = cfg_dQPFile.empty() ? NULL : strdup(cfg_dQPFile.c_str());
-
-
-#if FLEX_CODING_ORDER
-  m_pchMVCJointCodingOrder	= cfg_JointCodingOrdering.empty()?NULL:strdup(cfg_JointCodingOrdering.c_str());
-  // If flexible order is enabled and if depth comes before the texture for a view, disable VSO
-
-#if HHI_VSO && DISABLE_FCO_FOR_VSO
-  Bool depthComesFirst = false;
-  if ( m_b3DVFlexOrder )
-  {
-    for(Int iViewIdx=0; iViewIdx<m_iNumberOfViews; iViewIdx++)
-    {
-      for ( Int ii=1; ii<12; ii+=2 )
-      {
-        Int iViewIdxCfg = (Int)(m_pchMVCJointCodingOrder[ii]-'0');
-        if ( iViewIdxCfg == iViewIdx )
-        {
-          if ( m_pchMVCJointCodingOrder[ii-1]=='D' ) // depth comes first for this view
-          {
-            depthComesFirst = true;
-            break;
-          }
-          else
-          {
-            assert(m_pchMVCJointCodingOrder[ii-1]=='T');
-          }
-        }
-      }
-    }
-  }
-  if (depthComesFirst)
-  {
-    m_bUseVSO = false;		
-  }
-#endif
-#endif
-
-// GT FIX
+  
+  m_pchColumnWidth = cfg_ColumnWidth.empty() ? NULL: strdup(cfg_ColumnWidth.c_str());
+  m_pchRowHeight = cfg_RowHeight.empty() ? NULL : strdup(cfg_RowHeight.c_str());
+  m_scalingListFile = cfg_ScalingListFile.empty() ? NULL : strdup(cfg_ScalingListFile.c_str());
+  
   if ( m_bUsingDepthMaps )
   {
@@ -448,29 +495,4 @@
     };
   }
-// GT FIX END
-
-  if (m_iRateGOPSize == -1)
-  {
-    /* if rateGOPSize has not been specified, the default value is GOPSize */
-    m_iRateGOPSize = m_iGOPSize;
-  }
-
-  // compute source padding size
-  if ( m_bUsePAD )
-  {
-    if ( m_iSourceWidth%MAX_PAD_SIZE )
-    {
-      m_aiPad[0] = (m_iSourceWidth/MAX_PAD_SIZE+1)*MAX_PAD_SIZE - m_iSourceWidth;
-    }
-
-    if ( m_iSourceHeight%MAX_PAD_SIZE )
-    {
-      m_aiPad[1] = (m_iSourceHeight/MAX_PAD_SIZE+1)*MAX_PAD_SIZE - m_iSourceHeight;
-    }
-  }
-  m_iSourceWidth  += m_aiPad[0];
-  m_iSourceHeight += m_aiPad[1];
-
-//GT QP Depth
   if ( m_adQP.size() < 2 )
   {
@@ -481,5 +503,123 @@
     m_aiQP.push_back( (Int)( m_adQP[uiK] ) );
   }
-//GT QP Depth end
+
+#if PIC_CROPPING
+  switch (m_croppingMode)
+  {
+  case 0:
+    {
+      // no cropping or padding
+      m_cropLeft = m_cropRight = m_cropTop = m_cropBottom = 0;
+      m_aiPad[1] = m_aiPad[0] = 0;
+      break;
+    }
+  case 1:
+    {
+      // automatic padding to minimum CU size
+      Int minCuSize = m_uiMaxCUHeight >> (m_uiMaxCUDepth - 1);
+      if (m_iSourceWidth % minCuSize)
+      {
+        m_aiPad[0] = m_cropRight  = ((m_iSourceWidth / minCuSize) + 1) * minCuSize - m_iSourceWidth;
+        m_iSourceWidth  += m_cropRight;
+      }
+      if (m_iSourceHeight % minCuSize)
+      {
+        m_aiPad[1] = m_cropBottom = ((m_iSourceHeight / minCuSize) + 1) * minCuSize - m_iSourceHeight;
+        m_iSourceHeight += m_cropBottom;
+      }
+      break;
+    }
+  case 2:
+    {
+      //padding
+      m_iSourceWidth  += m_aiPad[0];
+      m_iSourceHeight += m_aiPad[1];
+      m_cropRight  = m_aiPad[0];
+      m_cropBottom = m_aiPad[1];
+      break;
+    }
+  case 3:
+    {
+      // cropping
+      if ((m_cropLeft == 0) && (m_cropRight == 0) && (m_cropTop == 0) && (m_cropBottom == 0))
+      {
+        fprintf(stderr, "Warning: Cropping enabled, but all cropping parameters set to zero\n");
+      }
+      if ((m_aiPad[1] != 0) || (m_aiPad[0]!=0))
+      {
+        fprintf(stderr, "Warning: Cropping enabled, padding parameters will be ignored\n");
+      }
+      m_aiPad[1] = m_aiPad[0] = 0;
+      break;
+    }
+  }
+#else
+
+  // compute source padding size
+  if ( m_bUsePAD )
+  {
+    if ( m_iSourceWidth%MAX_PAD_SIZE )
+    {
+      m_aiPad[0] = (m_iSourceWidth/MAX_PAD_SIZE+1)*MAX_PAD_SIZE - m_iSourceWidth;
+    }
+    
+    if ( m_iSourceHeight%MAX_PAD_SIZE )
+    {
+      m_aiPad[1] = (m_iSourceHeight/MAX_PAD_SIZE+1)*MAX_PAD_SIZE - m_iSourceHeight;
+    }
+  }
+  m_iSourceWidth  += m_aiPad[0];
+  m_iSourceHeight += m_aiPad[1];
+#endif
+  
+  // allocate slice-based dQP values
+  m_aidQP = new Int[ m_iFrameToBeEncoded + m_iGOPSize + 1 ];
+  m_aidQPdepth =  new Int[ m_iFrameToBeEncoded + m_iGOPSize + 1 ];
+  ::memset( m_aidQP, 0, sizeof(Int)*( m_iFrameToBeEncoded + m_iGOPSize + 1 ) );
+  ::memset( m_aidQPdepth, 0, sizeof(Int)*( m_iFrameToBeEncoded + m_iGOPSize + 1 ) );
+  
+  // handling of floating-point QP values
+  // if QP is not integer, sequence is split into two sections having QP and QP+1
+  m_aiQP[0] = (Int)( m_adQP[0] );
+  if ( m_aiQP[0] < m_adQP[0] )
+  {
+    Int iSwitchPOC = (Int)( m_iFrameToBeEncoded - (m_adQP[0] - m_aiQP[0])*m_iFrameToBeEncoded + 0.5 );
+    
+    iSwitchPOC = (Int)( (Double)iSwitchPOC / m_iGOPSize + 0.5 )*m_iGOPSize;
+    for ( Int i=iSwitchPOC; i<m_iFrameToBeEncoded + m_iGOPSize + 1; i++ )
+    {
+      m_aidQP[i] = 1;
+    }
+  }
+
+  m_aiQP[1] = (Int)( m_adQP[1] );
+  if ( m_aiQP[1] < m_adQP[1] )
+  {
+    Int iSwitchPOC = (Int)( m_iFrameToBeEncoded - (m_adQP[1] - m_aiQP[1])*m_iFrameToBeEncoded + 0.5 );
+
+    iSwitchPOC = (Int)( (Double)iSwitchPOC / m_iGOPSize + 0.5 )*m_iGOPSize;
+    for ( Int i=iSwitchPOC; i<m_iFrameToBeEncoded + m_iGOPSize + 1; i++ )
+    {
+      m_aidQPdepth[i] = 1;
+    }
+  }
+
+  // reading external dQP description from file
+  if ( m_pchdQPFile )
+  {
+    FILE* fpt=fopen( m_pchdQPFile, "r" );
+    if ( fpt )
+    {
+      Int iValue;
+      Int iPOC = 0;
+      while ( iPOC < m_iFrameToBeEncoded )
+      {
+        if ( fscanf(fpt, "%d", &iValue ) == EOF ) break;
+        m_aidQP[ iPOC ] = iValue;
+        iPOC++;
+      }
+      fclose(fpt);
+    }
+  }
 
 #if HHI_VSO
@@ -516,21 +656,4 @@
 
 #if HHI_VSO
-  if ( m_bUseVSO )
-  {
-    if ( m_iNumberOfExternalRefs != 0 )
-    {
-      xCleanUpVector( m_aaiERViewRefInd,    vector<Int>() );
-      xCleanUpVector( m_aaiBaseViewRefInd,  vector<Int>() );
-    }
-    else
-    {
-      m_aaiERViewRefInd   .clear();
-      m_aaiERViewRefInd   .resize( m_iNumberOfViews );
-      m_aaiERViewRefLutInd.clear();
-      m_aaiERViewRefLutInd.resize( m_iNumberOfViews );
-      m_aaiBaseViewRefInd .clear();
-      m_aaiBaseViewRefInd .resize( m_iNumberOfViews );
-    }
-  }
 
 #if HHI_VSO_LS_TABLE
@@ -549,5 +672,5 @@
 #endif
 
-  // set global variables
+ // set global variables
   xSetGlobal();
 
@@ -611,8 +734,8 @@
   xCheckParameter();
   m_cCameraData.check( false, true );
-
+  
   // print-out parameters
   xPrintParameter();
-
+  
   return true;
 }
@@ -629,16 +752,18 @@
 #define xConfirmPara(a,b) check_failed |= confirmPara(a,b)
   // check range of parameters
-#if ENABLE_IBDI
-  xConfirmPara( m_uiInternalBitDepth > 0 && (int)m_uiBitIncrement != -1,                    "InternalBitDepth and BitIncrement may not be specified simultaneously");
+  xConfirmPara( m_uiInputBitDepth < 8,                                                      "InputBitDepth must be at least 8" );
+  xConfirmPara( m_iFrameRate <= 0,                                                          "Frame rate must be more than 1" );
+  xConfirmPara( m_iFrameToBeEncoded <= 0,                                                   "Total Number Of Frames encoded must be more than 0" );
+  xConfirmPara( m_iGOPSize < 1 ,                                                            "GOP Size must be greater or equal to 1" );
+  xConfirmPara( m_iGOPSize > 1 &&  m_iGOPSize % 2,                                          "GOP Size must be a multiple of 2, if GOP Size is greater than 1" );
+  xConfirmPara( (m_iIntraPeriod > 0 && m_iIntraPeriod < m_iGOPSize) || m_iIntraPeriod == 0, "Intra period must be more than GOP size, or -1 , not 0" );
+  xConfirmPara( m_iDecodingRefreshType < 0 || m_iDecodingRefreshType > 2,                   "Decoding Refresh Type must be equal to 0, 1 or 2" );
+#if H0736_AVC_STYLE_QP_RANGE
+  xConfirmPara( m_aiQP[0] < -6 * ((Int)m_uiInternalBitDepth - 8) || m_aiQP[0] > 51,         "QP exceeds supported range (-QpBDOffsety to 51)" );
+  if ( m_aiQP.size() >= 2 )
+  {
+    xConfirmPara( m_aiQP[1] < -6 * ((Int)m_uiInternalBitDepth - 8) || m_aiQP[1] > 51,       "QP depth exceeds supported range (-QpBDOffsety to 51)" );
+  }
 #else
-  xConfirmPara( m_uiInputBitDepth < 8,                                                      "InputBitDepth must be at least 8" );
-#endif
-  xConfirmPara( m_iFrameRate <= 0,                                                          "Frame rate must be more than 1" );
-  xConfirmPara( m_iFrameToBeEncoded <= 0,                                                   "Total Number Of Frames encoded must be more than 1" );
-  xConfirmPara( m_iGOPSize < 1 ,                                                            "GOP Size must be more than 1" );
-#if DCM_DECODING_REFRESH
-  xConfirmPara( m_iDecodingRefreshType < 0 || m_iDecodingRefreshType > 2,                   "Decoding Refresh Type must be equal to 0, 1 or 2" );
-#endif
-//GT QP Depth
   xConfirmPara( m_aiQP[0] < 0 || m_aiQP[0] > 51,                                             "QP exceeds supported range (0 to 51)" );
   if ( m_aiQP.size() >= 2 )
@@ -646,21 +771,41 @@
     xConfirmPara( m_aiQP[1] < 0 || m_aiQP[1] > 51,                                           "QP Depth exceeds supported range (0 to 51)" );
   }
-//GT QP Depth End
-#if MQT_ALF_NPASS
+#endif
   xConfirmPara( m_iALFEncodePassReduction < 0 || m_iALFEncodePassReduction > 2,             "ALFEncodePassReduction must be equal to 0, 1 or 2");
-#endif
-  xConfirmPara( m_iLoopFilterAlphaC0Offset < -26 || m_iLoopFilterAlphaC0Offset > 26,        "Loop Filter Alpha Offset exceeds supported range (-26 to 26)" );
-  xConfirmPara( m_iLoopFilterBetaOffset < -26 || m_iLoopFilterBetaOffset > 26,              "Loop Filter Beta Offset exceeds supported range (-26 to 26)");
+#if LCU_SYNTAX_ALF
+  xConfirmPara( m_iALFMaxNumberFilters < 1,                                                 "ALFMaxNumFilter should be larger than 1");  
+#else
+  xConfirmPara( m_iALFMaxNumberFilters < 1 || m_iALFMaxNumberFilters > 16,                  "ALFMaxNumFilter exceeds supported range (1 to 16)");  
+#endif
+  xConfirmPara( m_loopFilterBetaOffsetDiv2 < -13 || m_loopFilterBetaOffsetDiv2 > 13,          "Loop Filter Beta Offset div. 2 exceeds supported range (-13 to 13)");
+  xConfirmPara( m_loopFilterTcOffsetDiv2 < -13 || m_loopFilterTcOffsetDiv2 > 13,              "Loop Filter Tc Offset div. 2 exceeds supported range (-13 to 13)");
   xConfirmPara( m_iFastSearch < 0 || m_iFastSearch > 2,                                     "Fast Search Mode is not supported value (0:Full search  1:Diamond  2:PMVFAST)" );
   xConfirmPara( m_iSearchRange < 0 ,                                                        "Search Range must be more than 0" );
   xConfirmPara( m_bipredSearchRange < 0 ,                                                   "Search Range must be more than 0" );
   xConfirmPara( m_iMaxDeltaQP > 7,                                                          "Absolute Delta QP exceeds supported range (0 to 7)" );
+  xConfirmPara( m_iMaxCuDQPDepth > m_uiMaxCUDepth - 1,                                          "Absolute depth for a minimum CuDQP exceeds maximum coding unit depth" );
+
+  xConfirmPara( m_iChromaQpOffset    < -12,   "Min. Chroma Qp Offset is -12"     );
+  xConfirmPara( m_iChromaQpOffset    >  12,   "Max. Chroma Qp Offset is  12"     );
+  xConfirmPara( m_iChromaQpOffset2nd < -12,   "Min. Chroma Qp Offset 2nd is -12" );
+  xConfirmPara( m_iChromaQpOffset2nd >  12,   "Max. Chroma Qp Offset 2nd is  12" );
+
+  xConfirmPara( m_iQPAdaptationRange <= 0,                                                  "QP Adaptation Range must be more than 0" );
+  if (m_iDecodingRefreshType == 2)
+  {
+    xConfirmPara( m_iIntraPeriod > 0 && m_iIntraPeriod <= m_iGOPSize ,                      "Intra period must be larger than GOP size for periodic IDR pictures");
+  }
   xConfirmPara( (m_uiMaxCUWidth  >> m_uiMaxCUDepth) < 4,                                    "Minimum partition width size should be larger than or equal to 8");
   xConfirmPara( (m_uiMaxCUHeight >> m_uiMaxCUDepth) < 4,                                    "Minimum partition height size should be larger than or equal to 8");
   xConfirmPara( m_uiMaxCUWidth < 16,                                                        "Maximum partition width size should be larger than or equal to 16");
   xConfirmPara( m_uiMaxCUHeight < 16,                                                       "Maximum partition height size should be larger than or equal to 16");
+#if PIC_CROPPING
+  xConfirmPara( (m_iSourceWidth  % (m_uiMaxCUWidth  >> (m_uiMaxCUDepth-1)))!=0,             "Resulting coded frame width must be a multiple of the minimum CU size");
+  xConfirmPara( (m_iSourceHeight % (m_uiMaxCUHeight >> (m_uiMaxCUDepth-1)))!=0,             "Resulting coded frame height must be a multiple of the minimum CU size");
+#else
   xConfirmPara( (m_iSourceWidth  % (m_uiMaxCUWidth  >> (m_uiMaxCUDepth-1)))!=0,             "Frame width should be multiple of minimum CU size");
   xConfirmPara( (m_iSourceHeight % (m_uiMaxCUHeight >> (m_uiMaxCUDepth-1)))!=0,             "Frame height should be multiple of minimum CU size");
-
+#endif
+  
   xConfirmPara( m_uiQuadtreeTULog2MinSize < 2,                                        "QuadtreeTULog2MinSize must be 2 or greater.");
   xConfirmPara( m_uiQuadtreeTULog2MinSize > 5,                                        "QuadtreeTULog2MinSize must be 5 or smaller.");
@@ -677,23 +822,11 @@
   xConfirmPara( m_uiQuadtreeTUMaxDepthIntra > m_uiQuadtreeTULog2MaxSize - m_uiQuadtreeTULog2MinSize + 1, "QuadtreeTUMaxDepthIntra must be less than or equal to the difference between QuadtreeTULog2MaxSize and QuadtreeTULog2MinSize plus 1" );
 
-  xConfirmPara( m_iSliceMode < 0 || m_iSliceMode > 2, "SliceMode exceeds supported range (0 to 2)" );
-  if (m_iSliceMode!=0)
-  {
-    xConfirmPara( m_iSliceArgument < 1 ,         "SliceArgument should be larger than or equal to 1" );
-  }
-  xConfirmPara( m_iEntropySliceMode < 0 || m_iEntropySliceMode > 2, "EntropySliceMode exceeds supported range (0 to 2)" );
-  if (m_iEntropySliceMode!=0)
-  {
-    xConfirmPara( m_iEntropySliceArgument < 1 ,         "EntropySliceArgument should be larger than or equal to 1" );
-  }
-
-  xConfirmPara( m_iSymbolMode < 0 || m_iSymbolMode > 1,                                     "SymbolMode must be equal to 0 or 1" );
-
-  // Check MultiView stuff
-  xConfirmPara    ( m_iNumberOfViews > MAX_INPUT_VIEW_NUM ,                           "NumberOfViews must be less than or equal to MAX_INPUT_VIEW_NUM");
+  xConfirmPara( m_iNumberOfViews > MAX_VIEW_NUM ,                                     "NumberOfViews must be less than or equal to MAX_VIEW_NUM");
   xConfirmPara    ( Int( m_pchInputFileList.size() ) < m_iNumberOfViews,              "Number of InputFiles must be greater than or equal to NumberOfViews" );
   xConfirmPara    ( Int( m_pchReconFileList.size() ) < m_iNumberOfViews,              "Number of ReconFiles must be greater than or equal to NumberOfViews" );
-
   xConfirmPara    ( m_iCodedCamParPrecision < 0 || m_iCodedCamParPrecision > 5,       "CodedCamParsPrecision must be in range of 0..5" );
+#if HHI_INTERVIEW_SKIP
+  xConfirmPara    ( m_bInterViewSkip && !m_bUsingDepthMaps,                       "RenderingSkipMode requires CodeDepthMaps = 1" );
+#endif
 #if DEPTH_MAP_GENERATION
   xConfirmPara    ( m_uiPredDepthMapGeneration > 2,                                   "PredDepthMapGen must be less than or equal to 2" );
@@ -714,9 +847,4 @@
   xConfirmPara    ( m_uiMultiviewResPredMode > 0 && m_uiPredDepthMapGeneration == 0 , "MultiviewResPred > 0 requires PredDepthMapGen > 0" );
 #endif
-
-#if HHI_INTERVIEW_SKIP
-  xConfirmPara    ( m_uiInterViewSkip > 1,                                        "RenderingSkipMode > 1 not supported" );
-  xConfirmPara    ( m_uiInterViewSkip > 0 && !m_bUsingDepthMaps,                  "RenderingSkipMode > 0 requires CodeDepthMaps = 1" );
-#endif
   if( m_bUsingDepthMaps )
   {
@@ -732,16 +860,50 @@
       xConfirmPara( m_iNumberOfViews != m_cCameraData.getBaseViewNumbers().size(),   "Number of Views in BaseViewCameraNumbers must be equal to NumberOfViews" );
       xConfirmPara( m_uiVSOMode < 0 || m_uiVSOMode > 4 ,                             "VSO Mode must be greater than or equal to 0 and less than 5");
-      xConfirmPara( m_iNumberOfExternalRefs               > MAX_ERREF_VIEW_NUM,      "NumberOfExternalRefs must be less than of equal to TAppMVEncCfg::MAX_ERREF_VIEW_NUM" );
-      xConfirmPara( Int( m_pchERRefFileList .size() ) < m_iNumberOfExternalRefs,     "Number of ERRefFileFiles  must be greater than or equal to NumberOfExternalRefs" );
-    }
-#endif
-  }
-
-#if DCM_COMB_LIST
-#if !HHI_NO_LowDelayCoding
-  xConfirmPara( m_bUseLComb==false && m_bUseLDC==false,         "LComb can only be 0 if LowDelayCoding is 1" );
-#else
-  xConfirmPara( m_bUseLComb==false,                             "LComb can only be 0 if LowDelayCoding is 1" );
-#endif
+    }
+#endif
+  }
+#if ADAPTIVE_QP_SELECTION
+#if H0736_AVC_STYLE_QP_RANGE
+  xConfirmPara( m_bUseAdaptQpSelect == true && m_aiQP[0] < 0,                                              "AdaptiveQpSelection must be disabled when QP < 0.");
+  xConfirmPara( m_bUseAdaptQpSelect == true && m_aiQP[1] < 0,                                              "AdaptiveQpSelection must be disabled when QP < 0.");
+  xConfirmPara( m_bUseAdaptQpSelect == true && (m_iChromaQpOffset !=0 || m_iChromaQpOffset2nd != 0 ),  "AdaptiveQpSelection must be disabled when ChromaQpOffset is not equal to 0.");
+#endif
+#endif
+
+  if( m_usePCM)
+  {
+    xConfirmPara(  m_uiPCMLog2MinSize < 3,                                      "PCMLog2MinSize must be 3 or greater.");
+    xConfirmPara(  m_uiPCMLog2MinSize > 5,                                      "PCMLog2MinSize must be 5 or smaller.");
+    xConfirmPara(  m_pcmLog2MaxSize > 5,                                        "PCMLog2MaxSize must be 5 or smaller.");
+    xConfirmPara(  m_pcmLog2MaxSize < m_uiPCMLog2MinSize,                       "PCMLog2MaxSize must be equal to or greater than m_uiPCMLog2MinSize.");
+  }
+
+#if FIXED_NUMBER_OF_TILES_SLICE_MODE
+  xConfirmPara( m_iSliceMode < 0 || m_iSliceMode > 3, "SliceMode exceeds supported range (0 to 3)" );
+#endif
+  if (m_iSliceMode!=0)
+  {
+    xConfirmPara( m_iSliceArgument < 1 ,         "SliceArgument should be larger than or equal to 1" );
+  }
+#if FIXED_NUMBER_OF_TILES_SLICE_MODE
+  if (m_iSliceMode==3)
+  {
+    xConfirmPara( m_iSliceGranularity > 0 ,      "When SliceMode == 3 is chosen, the SliceGranularity must be 0" );
+  }
+#endif
+  xConfirmPara( m_iEntropySliceMode < 0 || m_iEntropySliceMode > 2, "EntropySliceMode exceeds supported range (0 to 2)" );
+  if (m_iEntropySliceMode!=0)
+  {
+    xConfirmPara( m_iEntropySliceArgument < 1 ,         "EntropySliceArgument should be larger than or equal to 1" );
+  }
+  xConfirmPara( m_iSliceGranularity >= m_uiMaxCUDepth, "SliceGranularity must be smaller than maximum cu depth");
+  xConfirmPara( m_iSliceGranularity <0 || m_iSliceGranularity > 3, "SliceGranularity exceeds supported range (0 to 3)" );
+  xConfirmPara( m_iSliceGranularity > m_iMaxCuDQPDepth, "SliceGranularity must be smaller smaller than or equal to maximum dqp depth" );
+
+#if NO_COMBINED_PARALLEL
+  bool tileFlag = (m_iNumColumnsMinus1 > 0 || m_iNumRowsMinus1 > 0 );
+  xConfirmPara( tileFlag && m_iEntropySliceMode,            "Tile and Entropy Slice can not be applied together");
+  xConfirmPara( tileFlag && m_iWaveFrontSynchro,            "Tile and Wavefront can not be applied together");
+  xConfirmPara( m_iWaveFrontSynchro && m_iEntropySliceMode, "Wavefront and Entropy Slice can not be applied together");  
 #endif
 
@@ -761,13 +923,490 @@
       xConfirmPara( ui != 1 , "Height should be 2^n");
   }
-
-  // SBACRD is supported only for SBAC
-  if ( m_iSymbolMode == 0 )
-  {
-    m_bUseSBACRD = false;
-  }
+  
+  xConfirmPara( m_iWaveFrontSynchro < 0, "WaveFrontSynchro cannot be negative" );
+  xConfirmPara( m_iWaveFrontFlush < 0, "WaveFrontFlush cannot be negative" );
+  xConfirmPara( m_iWaveFrontSubstreams <= 0, "WaveFrontSubstreams must be positive" );
+  xConfirmPara( m_iWaveFrontSubstreams > 1 && !m_iWaveFrontSynchro, "Must have WaveFrontSynchro > 0 in order to have WaveFrontSubstreams > 1" );
 
 #undef xConfirmPara
   if (check_failed)
+  {
+    exit(EXIT_FAILURE);
+  }
+
+  xCheckCodingStructureMvc();
+}
+
+Void TAppEncCfg::xCheckCodingStructureMvc()
+{
+  bool check_failed = false; /* abort if there is a fatal configuration problem */
+#define xConfirmPara(a,b) check_failed |= confirmPara(a,b)
+
+  // validate that POC of same frame is identical across multiple views
+  Bool bErrorMvePoc = false;
+  if( m_iNumberOfViews > 1 )
+  {
+    for( Int k = 1; k < m_iNumberOfViews; k++ )
+    {
+      for( Int i = 0; i < MAX_GOP; i++ )
+      {
+        if( m_GOPListsMvc[k][i].m_POC != m_GOPListsMvc[0][i].m_POC )
+        {
+          printf( "\nError: Frame%d_v%d POC %d is not identical to Frame%d POC\n", i, k, m_GOPListsMvc[k][i].m_POC, i );
+          bErrorMvePoc = true;
+        }
+      }
+    }
+  }
+  xConfirmPara( bErrorMvePoc,  "Invalid inter-view POC structure given" );
+
+  // validate that baseview has no inter-view refs 
+  Bool bErrorIvpBase = false;
+  for( Int i = 0; i < MAX_GOP; i++ )
+  {
+    if( m_GOPListsMvc[0][i].m_numInterViewRefPics != 0 )
+    {
+      printf( "\nError: Frame%d inter_view refs not available in view 0\n", i );
+      bErrorIvpBase = true;
+    }
+  }
+  xConfirmPara( bErrorIvpBase, "Inter-view refs not possible in base view" );
+
+  // validate inter-view refs
+  Bool bErrorIvpEnhV = false;
+  if( m_iNumberOfViews > 1 )
+  {
+    for( Int k = 1; k < m_iNumberOfViews; k++ )
+    {
+      for( Int i = 0; i < MAX_GOP+1; i++ )
+      {
+        for( Int j = 0; j < m_GOPListsMvc[k][i].m_numInterViewRefPics; j++ )
+        {
+          Int iAbsViewId = m_GOPListsMvc[k][i].m_interViewRefs[j] + k;
+          if( iAbsViewId < 0 || iAbsViewId >= k )
+          {
+            printf( "\nError: inter-view ref pic %d is not available for Frame%d_v%d\n", m_GOPListsMvc[k][i].m_interViewRefs[j], i, k );
+            bErrorIvpEnhV = true;
+          }
+          if( m_GOPListsMvc[k][i].m_interViewRefPosL0[j] < 0 || m_GOPListsMvc[k][i].m_interViewRefPosL0[j] > m_GOPListsMvc[k][i].m_numRefPicsActive )
+          {
+            printf( "\nError: inter-view ref pos %d on L0 is not available for Frame%d_v%d\n", m_GOPListsMvc[k][i].m_interViewRefPosL0[j], i, k );
+            bErrorIvpEnhV = true;
+          }
+          if( m_GOPListsMvc[k][i].m_interViewRefPosL1[j] < 0 || m_GOPListsMvc[k][i].m_interViewRefPosL1[j] > m_GOPListsMvc[k][i].m_numRefPicsActive )
+          {
+            printf( "\nError: inter-view ref pos %d on L1 is not available for Frame%d_v%d\n", m_GOPListsMvc[k][i].m_interViewRefPosL1[j], i, k );
+            bErrorIvpEnhV = true;
+          }
+        }
+        if( i == MAX_GOP ) // inter-view refs at I pic position in base view
+        {
+          if( m_GOPListsMvc[k][MAX_GOP].m_sliceType != 'B' && m_GOPListsMvc[k][MAX_GOP].m_sliceType != 'P' && m_GOPListsMvc[k][MAX_GOP].m_sliceType != 'I' )
+          {
+            printf( "\nError: slice type of FrameI_v%d must be equal to B or P or I\n", k );
+            bErrorIvpEnhV = true;
+          }
+
+          if( m_GOPListsMvc[k][MAX_GOP].m_POC != 0 )
+          {
+            printf( "\nError: POC %d not possible for FrameI_v%d, must be 0\n", m_GOPListsMvc[k][MAX_GOP].m_POC, k );
+            bErrorIvpEnhV = true;
+          }
+
+          if( m_GOPListsMvc[k][MAX_GOP].m_temporalId != 0 )
+          {
+            printf( "\nWarning: Temporal id of FrameI_v%d must be 0 (cp. I-frame in base view)\n", k );
+            m_GOPListsMvc[k][MAX_GOP].m_temporalId = 0;
+          }
+
+          if( !(m_GOPListsMvc[k][MAX_GOP].m_refPic) )
+          {
+            printf( "\nWarning: FrameI_v%d must be ref pic (cp. I-frame in base view)\n", k );
+            m_GOPListsMvc[k][MAX_GOP].m_refPic = true;
+          }
+
+          if( m_GOPListsMvc[k][MAX_GOP].m_numRefPics != 0 )
+          {
+            printf( "\nWarning: temporal references not possible for FrameI_v%d\n", k );
+            for( Int j = 0; j < m_GOPListsMvc[k][MAX_GOP].m_numRefPics; j++ )
+            {
+              m_GOPListsMvc[k][MAX_GOP].m_referencePics[j] = 0;
+            }
+            m_GOPListsMvc[k][MAX_GOP].m_numRefPics = 0;
+          }
+
+          if( m_GOPListsMvc[k][MAX_GOP].m_interRPSPrediction )
+          {
+            printf( "\nError: inter RPS prediction not possible for FrameI_v%d, must be 0\n", k );
+            bErrorIvpEnhV = true;
+          }
+
+          if( m_GOPListsMvc[k][MAX_GOP].m_sliceType == 'I' && m_GOPListsMvc[k][MAX_GOP].m_numInterViewRefPics != 0 )
+          {
+            printf( "\nError: inter-view prediction not possible for FrameI_v%d with slice type I, #IV_ref_pics must be 0\n", k );
+            bErrorIvpEnhV = true;
+          }
+
+          if( m_GOPListsMvc[k][MAX_GOP].m_numRefPicsActive > m_GOPListsMvc[k][MAX_GOP].m_numInterViewRefPics )
+          {
+            m_GOPListsMvc[k][MAX_GOP].m_numRefPicsActive = m_GOPListsMvc[k][MAX_GOP].m_numInterViewRefPics;
+          }
+
+          if( m_GOPListsMvc[k][MAX_GOP].m_sliceType == 'P' )
+          {
+            if( m_GOPListsMvc[k][MAX_GOP].m_numInterViewRefPics < 1 )
+            {
+              printf( "\nError: #IV_ref_pics must be at least one for FrameI_v%d with slice type P\n", k );
+              bErrorIvpEnhV = true;
+            }
+            else
+            {
+              for( Int j = 0; j < m_GOPListsMvc[k][MAX_GOP].m_numInterViewRefPics; j++ )
+              {
+                if( m_GOPListsMvc[k][MAX_GOP].m_interViewRefPosL1[j] != 0 )
+                {
+                  printf( "\nError: inter-view ref pos %d on L1 not possible for FrameI_v%d with slice type P\n", m_GOPListsMvc[k][MAX_GOP].m_interViewRefPosL1[j], k );
+                  bErrorIvpEnhV = true;
+                }
+              }
+            }
+          }
+
+          if( m_GOPListsMvc[k][MAX_GOP].m_sliceType == 'B' && m_GOPListsMvc[k][MAX_GOP].m_numInterViewRefPics < 1 )
+          {
+            printf( "\nError: #IV_ref_pics must be at least one for FrameI_v%d with slice type B\n", k );
+            bErrorIvpEnhV = true;
+          }
+        }
+      }
+    }
+  }
+  xConfirmPara( bErrorIvpEnhV, "Invalid inter-view coding structure for enhancement views given" );
+
+  // validate temporal coding structure
+  if( !bErrorMvePoc && !bErrorIvpBase && !bErrorIvpEnhV )
+  {
+    for( Int viewId = 0; viewId < m_iNumberOfViews; viewId++ )
+    {
+      Bool verifiedGOP = false;
+      Bool errorGOP    = false;
+      Int  checkGOP    = 1;
+      Int  numRefs     = 1;
+      Int refList[MAX_NUM_REF_PICS+1];
+      refList[0] = 0;
+      Bool isOK[MAX_GOP];
+      for( Int i = 0; i < MAX_GOP; i++ ) { isOK[i] = false; }
+      Int numOK = 0;
+#if !H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER
+      Int numReorderFramesRequired=0;
+      m_maxNumberOfReferencePictures=0;
+      Int lastDisp = -1;
+#endif
+      m_extraRPSs[viewId] = 0;
+      //start looping through frames in coding order until we can verify that the GOP structure is correct.
+      while( !verifiedGOP && !errorGOP )
+      {
+        Int curGOP = (checkGOP-1)%m_iGOPSize;
+        Int curPOC = ((checkGOP-1)/m_iGOPSize)*m_iGOPSize + m_GOPListsMvc[viewId][curGOP].m_POC;    
+        if( m_GOPListsMvc[viewId][curGOP].m_POC < 0 )
+        {
+          printf( "\nError: found fewer Reference Picture Sets than GOPSize for view %d\n", viewId );
+          errorGOP = true;
+        }
+        else 
+        {
+          //check that all reference pictures are available, or have a POC < 0 meaning they might be available in the next GOP.
+          Bool beforeI = false;
+          for( Int i = 0; i < m_GOPListsMvc[viewId][curGOP].m_numRefPics; i++ ) 
+          {
+            Int absPOC = curPOC + m_GOPListsMvc[viewId][curGOP].m_referencePics[i];
+            if( absPOC < 0 )
+            {
+              beforeI = true;
+            }
+            else 
+            {
+              Bool found = false;
+              for( Int j = 0; j < numRefs; j++ )
+              {
+                if( refList[j] == absPOC ) 
+                {
+                  found = true;
+                  for( Int k = 0; k < m_iGOPSize; k++ )
+                  {
+                    if( absPOC%m_iGOPSize == m_GOPListsMvc[viewId][k].m_POC%m_iGOPSize )
+                    {
+                      m_GOPListsMvc[viewId][curGOP].m_usedByCurrPic[i] = (m_GOPListsMvc[viewId][k].m_temporalId <= m_GOPListsMvc[viewId][curGOP].m_temporalId);
+                    }
+                  }
+                }
+              }
+              if( !found )
+              {
+                printf("\nError: ref pic %d is not available for GOP frame %d of view %d\n", m_GOPListsMvc[viewId][curGOP].m_referencePics[i], curGOP+1, viewId );
+                errorGOP = true;
+              }
+            }
+          }
+          if( !beforeI && !errorGOP )
+          {
+            //all ref frames were present
+            if( !isOK[curGOP] ) 
+            {
+              numOK++;
+              isOK[curGOP] = true;
+              if( numOK == m_iGOPSize )
+              {
+                verifiedGOP = true;
+              }
+            }
+          }
+          else 
+          {
+            //create a new GOPEntry for this frame containing all the reference pictures that were available (POC > 0)
+            m_GOPListsMvc[viewId][m_iGOPSize+m_extraRPSs[viewId]] = m_GOPListsMvc[viewId][curGOP];
+            Int newRefs = 0;
+            for( Int i = 0; i < m_GOPListsMvc[viewId][curGOP].m_numRefPics; i++ )
+            {
+              Int absPOC = curPOC + m_GOPListsMvc[viewId][curGOP].m_referencePics[i];
+              if( absPOC >= 0 )
+              {
+                m_GOPListsMvc[viewId][m_iGOPSize+m_extraRPSs[viewId]].m_referencePics[newRefs] = m_GOPListsMvc[viewId][curGOP].m_referencePics[i];
+                m_GOPListsMvc[viewId][m_iGOPSize+m_extraRPSs[viewId]].m_usedByCurrPic[newRefs] = m_GOPListsMvc[viewId][curGOP].m_usedByCurrPic[i];
+                newRefs++;
+              }
+            }
+            Int numPrefRefs = m_GOPListsMvc[viewId][curGOP].m_numRefPicsActive;
+
+            for( Int offset = -1; offset > -checkGOP; offset-- )
+            {
+              //step backwards in coding order and include any extra available pictures we might find useful to replace the ones with POC < 0.
+              Int offGOP =  (checkGOP - 1 + offset)%m_iGOPSize;
+              Int offPOC = ((checkGOP - 1 + offset)/m_iGOPSize) * m_iGOPSize + m_GOPListsMvc[viewId][offGOP].m_POC;
+              if( offPOC >= 0 && m_GOPListsMvc[viewId][offGOP].m_refPic && m_GOPListsMvc[viewId][offGOP].m_temporalId <= m_GOPListsMvc[viewId][curGOP].m_temporalId )
+              {
+                Bool newRef = false;
+                for( Int i = 0; i < numRefs; i++ )
+                {
+                  if( refList[i] == offPOC )
+                  {
+                    newRef = true;
+                  }
+                }
+                for( Int i = 0; i < newRefs; i++ ) 
+                {
+                  if( m_GOPListsMvc[viewId][m_iGOPSize+m_extraRPSs[viewId]].m_referencePics[i] == (offPOC - curPOC) )
+                  {
+                    newRef = false;
+                  }
+                }
+                if( newRef ) 
+                {
+                  Int insertPoint = newRefs;
+                  //this picture can be added, find appropriate place in list and insert it.
+                  for( Int j = 0; j < newRefs; j++ )
+                  {
+                    if( m_GOPListsMvc[viewId][m_iGOPSize+m_extraRPSs[viewId]].m_referencePics[j] < (offPOC - curPOC) || 
+                        m_GOPListsMvc[viewId][m_iGOPSize+m_extraRPSs[viewId]].m_referencePics[j] > 0 )
+                    {
+                      insertPoint = j;
+                      break;
+                    }
+                  }
+                  Int prev = offPOC - curPOC;
+                  Int prevUsed = (m_GOPListsMvc[viewId][offGOP].m_temporalId <= m_GOPListsMvc[viewId][curGOP].m_temporalId);
+                  for( Int j = insertPoint; j < newRefs+1; j++ )
+                  {
+                    Int newPrev = m_GOPListsMvc[viewId][m_iGOPSize+m_extraRPSs[viewId]].m_referencePics[j];
+                    Int newUsed = m_GOPListsMvc[viewId][m_iGOPSize+m_extraRPSs[viewId]].m_usedByCurrPic[j];
+                    m_GOPListsMvc[viewId][m_iGOPSize+m_extraRPSs[viewId]].m_referencePics[j] = prev;
+                    m_GOPListsMvc[viewId][m_iGOPSize+m_extraRPSs[viewId]].m_usedByCurrPic[j] = prevUsed;
+                    prevUsed = newUsed;
+                    prev = newPrev;
+                  }
+                  newRefs++;
+                }
+              }
+              if( newRefs >= numPrefRefs )
+              {
+                break;
+              }
+            }
+            m_GOPListsMvc[viewId][m_iGOPSize+m_extraRPSs[viewId]].m_numRefPics = newRefs;
+            m_GOPListsMvc[viewId][m_iGOPSize+m_extraRPSs[viewId]].m_POC = curPOC;
+            if( m_extraRPSs[viewId] == 0 )
+            {
+              m_GOPListsMvc[viewId][m_iGOPSize+m_extraRPSs[viewId]].m_interRPSPrediction = 0;
+              m_GOPListsMvc[viewId][m_iGOPSize+m_extraRPSs[viewId]].m_numRefIdc = 0;
+            }
+            else
+            {
+              Int rIdx =  m_iGOPSize + m_extraRPSs[viewId] - 1;
+              Int refPOC = m_GOPListsMvc[viewId][rIdx].m_POC;
+              Int refPics = m_GOPListsMvc[viewId][rIdx].m_numRefPics;
+              Int newIdc = 0;
+              for( Int i = 0; i <= refPics; i++ )
+              {
+                Int deltaPOC = ((i != refPics)? m_GOPListsMvc[viewId][rIdx].m_referencePics[i] : 0);  // check if the reference abs POC is >= 0
+                Int absPOCref = refPOC + deltaPOC;
+                Int refIdc = 0;
+                for( Int j = 0; j < m_GOPListsMvc[viewId][m_iGOPSize+m_extraRPSs[viewId]].m_numRefPics; j++ )
+                {
+                  if( (absPOCref - curPOC) == m_GOPListsMvc[viewId][m_iGOPSize+m_extraRPSs[viewId]].m_referencePics[j] )
+                  {
+                    if( m_GOPListsMvc[viewId][m_iGOPSize+m_extraRPSs[viewId]].m_usedByCurrPic[j] )
+                    {
+                      refIdc = 1;
+                    }
+                    else
+                    {
+                      refIdc = 2;
+                    }
+                  }
+                }
+                m_GOPListsMvc[viewId][m_iGOPSize+m_extraRPSs[viewId]].m_refIdc[newIdc] = refIdc;
+                newIdc++;
+              }
+              m_GOPListsMvc[viewId][m_iGOPSize+m_extraRPSs[viewId]].m_interRPSPrediction = 1;  
+              m_GOPListsMvc[viewId][m_iGOPSize+m_extraRPSs[viewId]].m_numRefIdc = newIdc;
+              m_GOPListsMvc[viewId][m_iGOPSize+m_extraRPSs[viewId]].m_deltaRPS = refPOC - m_GOPListsMvc[viewId][m_iGOPSize+m_extraRPSs[viewId]].m_POC; 
+              m_GOPListsMvc[viewId][m_iGOPSize+m_extraRPSs[viewId]].m_deltaRIdxMinus1 = 0; 
+            }
+            curGOP = m_iGOPSize + m_extraRPSs[viewId];
+            m_extraRPSs[viewId]++;
+          }
+          numRefs = 0;
+          for( Int i = 0; i < m_GOPListsMvc[viewId][curGOP].m_numRefPics; i++ )
+          {
+            Int absPOC = curPOC + m_GOPListsMvc[viewId][curGOP].m_referencePics[i];
+            if( absPOC >= 0 )
+            {
+              refList[numRefs] = absPOC;
+              numRefs++;
+            }
+          }
+#if !H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER
+          if(m_maxNumberOfReferencePictures<numRefs)
+          {
+            m_maxNumberOfReferencePictures=numRefs;
+          }
+#endif
+          refList[numRefs] = curPOC;
+          numRefs++;
+#if !H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER
+          Int nonDisplayed=0;
+          for(Int i=0; i<numRefs; i++) 
+          {
+            if(refList[i]==lastDisp+1) 
+            {
+              lastDisp=refList[i];
+              i=0;
+            }
+          }
+          for(Int i=0; i<numRefs; i++) 
+          {
+            if(refList[i]>lastDisp)
+            {
+              nonDisplayed++;
+            }
+          }
+          if(nonDisplayed>numReorderFramesRequired)
+          {
+            numReorderFramesRequired=nonDisplayed;
+          }
+#endif
+        }
+        checkGOP++;
+      }
+#if !H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER
+      if (m_numReorderFrames == -1)
+      {
+        m_numReorderFrames = numReorderFramesRequired;
+      }
+#endif
+      xConfirmPara( errorGOP, "Invalid GOP structure given" );
+#if H0566_TLA
+      m_maxTempLayer[viewId] = 1;
+#endif
+      for( Int i = 0; i < m_iGOPSize; i++ ) 
+      {
+#if H0566_TLA
+        if( m_GOPListsMvc[viewId][i].m_temporalId >= m_maxTempLayer[viewId] )
+        {
+          m_maxTempLayer[viewId] = m_GOPListsMvc[viewId][i].m_temporalId + 1;
+        }
+#endif
+        xConfirmPara( m_GOPListsMvc[viewId][i].m_sliceType != 'B' && m_GOPListsMvc[viewId][i].m_sliceType != 'P', "Slice type must be equal to B or P" );
+      }
+
+#if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER
+      for( Int i = 0; i < MAX_TLAYER; i++ )
+      {
+        m_numReorderPics[viewId][i] = 0;
+        m_maxDecPicBuffering[viewId][i] = 0;
+      }
+      for( Int i = 0; i < m_iGOPSize; i++ ) 
+      {
+        if( m_GOPListsMvc[viewId][i].m_numRefPics > m_maxDecPicBuffering[viewId][m_GOPListsMvc[viewId][i].m_temporalId] )
+        {
+          m_maxDecPicBuffering[viewId][m_GOPListsMvc[viewId][i].m_temporalId] = m_GOPListsMvc[viewId][i].m_numRefPics;
+        }
+        Int highestDecodingNumberWithLowerPOC = 0; 
+        for( Int j = 0; j < m_iGOPSize; j++ )
+        {
+          if( m_GOPListsMvc[viewId][j].m_POC <= m_GOPListsMvc[viewId][i].m_POC )
+          {
+            highestDecodingNumberWithLowerPOC = j;
+          }
+        }
+        Int numReorder = 0;
+        for( Int j = 0; j < highestDecodingNumberWithLowerPOC; j++ )
+        {
+          if( m_GOPListsMvc[viewId][j].m_temporalId <= m_GOPListsMvc[viewId][i].m_temporalId && 
+              m_GOPListsMvc[viewId][j].m_POC        >  m_GOPListsMvc[viewId][i].m_POC )
+          {
+            numReorder++;
+          }
+        }    
+        if( numReorder > m_numReorderPics[viewId][m_GOPListsMvc[viewId][i].m_temporalId] )
+        {
+          m_numReorderPics[viewId][m_GOPListsMvc[viewId][i].m_temporalId] = numReorder;
+        }
+      }
+      for( Int i = 0; i < MAX_TLAYER-1; i++ ) 
+      {
+        // a lower layer can not have higher value of m_numReorderPics than a higher layer
+        if( m_numReorderPics[viewId][i+1] < m_numReorderPics[viewId][i] )
+        {
+          m_numReorderPics[viewId][i+1] = m_numReorderPics[viewId][i];
+        }
+        // the value of num_reorder_pics[ i ] shall be in the range of 0 to max_dec_pic_buffering[ i ], inclusive
+        if( m_numReorderPics[viewId][i] > m_maxDecPicBuffering[viewId][i] )
+        {
+          m_maxDecPicBuffering[viewId][i] = m_numReorderPics[viewId][i];
+        }
+        // a lower layer can not have higher value of m_uiMaxDecPicBuffering than a higher layer
+        if( m_maxDecPicBuffering[viewId][i+1] < m_maxDecPicBuffering[viewId][i] )
+        {
+          m_maxDecPicBuffering[viewId][i+1] = m_maxDecPicBuffering[viewId][i];
+        }
+      }
+      // the value of num_reorder_pics[ i ] shall be in the range of 0 to max_dec_pic_buffering[ i ], inclusive
+      if( m_numReorderPics[viewId][MAX_TLAYER-1] > m_maxDecPicBuffering[viewId][MAX_TLAYER-1] )
+      {
+        m_maxDecPicBuffering[viewId][MAX_TLAYER-1] = m_numReorderPics[viewId][MAX_TLAYER-1];
+      }
+#endif
+
+#if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER
+      xConfirmPara( m_bUseLComb == false && m_numReorderPics[viewId][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.
+#else
+      xConfirmPara( m_bUseLComb==false && m_numReorderFrames!=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.
+      xConfirmPara( m_numReorderFrames < numReorderFramesRequired, "For the used GOP the encoder requires more pictures for reordering than specified in MaxNumberOfReorderPictures" );
+#endif
+    }
+  }
+#undef xConfirmPara
+  if( check_failed )
   {
     exit(EXIT_FAILURE);
@@ -801,11 +1440,4 @@
   xCleanUpVector( m_pchReconFileList,       (char*)0 );
   xCleanUpVector( m_pchDepthReconFileList,  (char*)0 );
-
-#if HHI_VSO
-  if ( m_bUseVSO)
-  {
-    xCleanUpVector( m_pchERRefFileList,       (char*)0 );
-  }
-#endif
 }
 
@@ -817,31 +1449,14 @@
   g_uiMaxCUWidth  = m_uiMaxCUWidth;
   g_uiMaxCUHeight = m_uiMaxCUHeight;
-
+  
   // compute actual CU depth with respect to config depth and max transform size
   g_uiAddCUDepth  = 0;
   while( (m_uiMaxCUWidth>>m_uiMaxCUDepth) > ( 1 << ( m_uiQuadtreeTULog2MinSize + g_uiAddCUDepth )  ) ) g_uiAddCUDepth++;
-
+  
   m_uiMaxCUDepth += g_uiAddCUDepth;
   g_uiAddCUDepth++;
   g_uiMaxCUDepth = m_uiMaxCUDepth;
-
+  
   // set internal bit-depth and constants
-#if ENABLE_IBDI
-  if ((int)m_uiBitIncrement != -1)
-  {
-    g_uiBitDepth = m_uiInputBitDepth;
-    g_uiBitIncrement = m_uiBitIncrement;
-    m_uiInternalBitDepth = g_uiBitDepth + g_uiBitIncrement;
-  }
-  else
-  {
-    g_uiBitDepth = min(8u, m_uiInputBitDepth);
-    if (m_uiInternalBitDepth == 0) {
-      /* default increement = 2 */
-      m_uiInternalBitDepth = 2 + g_uiBitDepth;
-    }
-    g_uiBitIncrement = m_uiInternalBitDepth - g_uiBitDepth;
-  }
-#else
 #if FULL_NBIT
   g_uiBitDepth = m_uiInternalBitDepth;
@@ -851,11 +1466,11 @@
   g_uiBitIncrement = m_uiInternalBitDepth - g_uiBitDepth;
 #endif
-#endif
+
 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
-  g_dDeltaDCsQuantOffset = Double(g_uiBitIncrement) -  2.0;
+  g_iDeltaDCsQuantOffset = g_uiBitIncrement - 2;
 #endif
 
   g_uiBASE_MAX     = ((1<<(g_uiBitDepth))-1);
-
+  
 #if IBDI_NOCLIP_RANGE
   g_uiIBDI_MAX     = g_uiBASE_MAX << g_uiBitIncrement;
@@ -863,9 +1478,12 @@
   g_uiIBDI_MAX     = ((1<<(g_uiBitDepth+g_uiBitIncrement))-1);
 #endif
-
+  
   if (m_uiOutputBitDepth == 0)
   {
     m_uiOutputBitDepth = m_uiInternalBitDepth;
   }
+
+  g_uiPCMBitDepthLuma = m_uiPCMBitDepthLuma = ((m_bPCMInputBitDepthFlag)? m_uiInputBitDepth : m_uiInternalBitDepth);
+  g_uiPCMBitDepthChroma = ((m_bPCMInputBitDepthFlag)? m_uiInputBitDepth : m_uiInternalBitDepth);
 }
 
@@ -873,23 +1491,32 @@
 {
   printf("\n");
-  for( Int iCounter = 0; iCounter<m_iNumberOfViews; iCounter++)
-  {
-    printf("Input          File %i        : %s\n", iCounter, m_pchInputFileList[iCounter]);
-  }
-  for( Int iCounter = 0; iCounter < (Int)m_pchDepthInputFileList.size(); iCounter++)
-  {
-    printf("DepthInput     File %i        : %s\n", iCounter, m_pchDepthInputFileList[iCounter]);
-  }
-  printf("Bitstream      File          : %s\n", m_pchBitstreamFile      );
-  for( Int iCounter = 0; iCounter<m_iNumberOfViews; iCounter++)
-  {
-    printf("Reconstruction File %i        : %s\n", iCounter, m_pchReconFileList[iCounter]);
-  }
-
-  for( Int iCounter = 0; iCounter<(Int)m_pchDepthReconFileList.size(); iCounter++)
-  {
-    printf("Reconstruction Depth File %i  : %s\n", iCounter, m_pchDepthReconFileList[iCounter]);
-  }
+  for( Int iCounter = 0; iCounter< m_iNumberOfViews; iCounter++)
+  {
+    printf("Texture Input File %i            : %s\n", iCounter, m_pchInputFileList[iCounter]);
+  }
+  if( m_bUsingDepthMaps )
+  {
+    for( Int iCounter = 0; iCounter < m_iNumberOfViews; iCounter++)
+    {
+      printf("Depth Input File %i              : %s\n", iCounter, m_pchDepthInputFileList[iCounter]);
+    }
+  }
+  printf("Bitstream File                  : %s\n", m_pchBitstreamFile      );
+  for( Int iCounter = 0; iCounter< m_iNumberOfViews; iCounter++)
+  {
+    printf("Texture Reconstruction File %i   : %s\n", iCounter, m_pchReconFileList[iCounter]);
+  }
+  if( m_bUsingDepthMaps )
+  {
+    for( Int iCounter = 0; iCounter< m_iNumberOfViews; iCounter++)
+    {
+      printf("Depth Reconstruction File %i     : %s\n", iCounter, m_pchDepthReconFileList[iCounter]);
+    }
+  }
+#if PIC_CROPPING
+  printf("Real     Format              : %dx%d %dHz\n", m_iSourceWidth - m_cropLeft - m_cropRight, m_iSourceHeight - m_cropTop - m_cropBottom, m_iFrameRate );
+#else
   printf("Real     Format              : %dx%d %dHz\n", m_iSourceWidth - m_aiPad[0], m_iSourceHeight-m_aiPad[1], m_iFrameRate );
+#endif
   printf("Internal Format              : %dx%d %dHz\n", m_iSourceWidth, m_iSourceHeight, m_iFrameRate );
   printf("Frame index                  : %u - %d (%d frames)\n", m_FrameSkip, m_FrameSkip+m_iFrameToBeEncoded-1, m_iFrameToBeEncoded );
@@ -898,34 +1525,28 @@
   printf("Max RQT depth inter          : %d\n", m_uiQuadtreeTUMaxDepthInter);
   printf("Max RQT depth intra          : %d\n", m_uiQuadtreeTUMaxDepthIntra);
+  printf("Min PCM size                 : %d\n", 1 << m_uiPCMLog2MinSize);
   printf("Motion search range          : %d\n", m_iSearchRange );
-#if DCM_DECODING_REFRESH
+  printf("Intra period                 : %d\n", m_iIntraPeriod );
   printf("Decoding refresh type        : %d\n", m_iDecodingRefreshType );
-#endif
-  printf("QP                           : %5.2f\n", m_adQP[0] );
-  printf("QP Depth                     : %5.2f\n", m_adQP[ m_adQP.size()  < 2 ? 0 : 1] );
-  printf("Coded Picture Store Size     : %d\n", m_uiCodedPictureStoreSize);
+  printf("QP Texture                   : %5.2f\n", m_adQP[0] );
+  if( m_bUsingDepthMaps )
+  {
+    printf("QP Depth                     : %5.2f\n", m_adQP[ m_adQP.size()  < 2 ? 0 : 1] );
+  }
+  printf("Max dQP signaling depth      : %d\n", m_iMaxCuDQPDepth);
+
+  printf("Chroma Qp Offset             : %d\n", m_iChromaQpOffset   );
+  printf("Chroma Qp Offset 2nd         : %d\n", m_iChromaQpOffset2nd);
+
+  printf("QP adaptation                : %d (range=%d)\n", m_bUseAdaptiveQP, (m_bUseAdaptiveQP ? m_iQPAdaptationRange : 0) );
   printf("GOP size                     : %d\n", m_iGOPSize );
-  printf("Rate GOP size                : %d\n", m_iRateGOPSize );
   printf("Internal bit depth           : %d\n", m_uiInternalBitDepth );
-
-  if ( m_iSymbolMode == 0 )
-  {
-    printf("Entropy coder                : VLC\n");
-  }
-  else if( m_iSymbolMode == 1 )
-  {
-    printf("Entropy coder                : CABAC\n");
-  }
-  else if( m_iSymbolMode == 2 )
-  {
-    printf("Entropy coder                : PIPE\n");
-  }
-  else
-  {
-    assert(0);
-  }
-
-  printf("GOP Format String            : %s\n", m_cInputFormatString.c_str() );
-  printf("Loop Filter Disabled         : %d %d\n", m_abLoopFilterDisable[0] ? 1 : 0,  m_abLoopFilterDisable[1] ? 1 : 0 );
+  printf("PCM sample bit depth         : %d\n", m_uiPCMBitDepthLuma );
+  if((m_uiMaxCUWidth >> m_uiMaxCUDepth) == 4)
+  {
+    printf("DisableInter4x4              : %d\n", m_bDisInter4x4);  
+  }
+
+printf("Loop Filter Disabled         : %d %d\n", m_abLoopFilterDisable[0] ? 1 : 0,  m_abLoopFilterDisable[1] ? 1 : 0 );
   printf("Coded Camera Param. Precision: %d\n", m_iCodedCamParPrecision);
 
@@ -943,9 +1564,17 @@
   }
 #endif
-
+#if HHI_INTERVIEW_SKIP
+    printf("InterView Skip:              : %d\n",    m_bInterViewSkip ? 1:0 );
+    printf("InterView Skip Lambda Scale  : %f\n",    m_dInterViewSkipLambdaScale );
+#endif
 
   printf("\n");
-
-  printf("TOOL CFG GENERAL: ");
+  
+  printf("TOOL CFG General: ");  
+#if LCU_SYNTAX_ALF
+  printf("ALFMNF:%d ", m_iALFMaxNumberFilters);
+  printf("ALFInSlice:%d ", m_bALFParamInSlice);
+  printf("ALFPicEnc:%d ", m_bALFPicBasedEncode);
+#endif
   printf("IBD:%d ", !!g_uiBitIncrement);
   printf("HAD:%d ", m_bUseHADME           );
@@ -953,33 +1582,66 @@
   printf("SQP:%d ", m_uiDeltaQpRD         );
   printf("ASR:%d ", m_bUseASR             );
+#if !PIC_CROPPING
   printf("PAD:%d ", m_bUsePAD             );
-  printf("LDC:%d ", m_bUseLDC             );
-#if DCM_COMB_LIST
+#endif
   printf("LComb:%d ", m_bUseLComb         );
   printf("LCMod:%d ", m_bLCMod         );
-#endif
   printf("FEN:%d ", m_bUseFastEnc         );
+  printf("ECU:%d ", m_bUseEarlyCU         );
+#if FAST_DECISION_FOR_MRG_RD_COST
+  printf("FDM:%d ", m_useFastDecisionForMerge );
+#endif
+  printf("CFM:%d ", m_bUseCbfFastMode         );
   printf("RQT:%d ", 1     );
-  printf("MRG:%d ", m_bUseMRG             ); // SOPH: Merge Mode
-#if LM_CHROMA
-  printf("LMC:%d ", m_bUseLMChroma        );
-#endif
-#if HHI_RMP_SWITCH
-  printf("RMP:%d ", m_bUseRMP);
-#endif
-  printf("Slice:%d ",m_iSliceMode);
+  printf("LMC:%d ", m_bUseLMChroma        ); 
+  printf("Slice: G=%d M=%d ", m_iSliceGranularity, m_iSliceMode);
   if (m_iSliceMode!=0)
   {
-    printf("(%d) ", m_iSliceArgument);
-  }
-  printf("EntropySlice:%d ",m_iEntropySliceMode);
+    printf("A=%d ", m_iSliceArgument);
+  }
+  printf("EntropySlice: M=%d ",m_iEntropySliceMode);
   if (m_iEntropySliceMode!=0)
   {
-    printf("(%d) ", m_iEntropySliceArgument);
-  }
-#if CONSTRAINED_INTRA_PRED
+    printf("A=%d ", m_iEntropySliceArgument);
+  }
   printf("CIP:%d ", m_bUseConstrainedIntraPred);
-#endif
-#if MTK_SAO
+#if BURST_IPCM
+  printf("PCM:%d ", (m_usePCM && (1<<m_uiPCMLog2MinSize) <= m_uiMaxCUWidth)? 1 : 0);
+#else
+  printf("PCM:%d ", ((1<<m_uiPCMLog2MinSize) <= m_uiMaxCUWidth)? 1 : 0);
+#endif
+#if SAO_UNIT_INTERLEAVING
+  printf("SAOInterleaving:%d ", (m_saoInterleavingFlag)?(1):(0));
+#endif
+#if LOSSLESS_CODING
+  printf("LosslessCuEnabled:%d ", (m_useLossless)? 1:0 );
+#endif  
+  printf("WPP:%d ", (Int)m_bUseWeightPred);
+  printf("WPB:%d ", m_uiBiPredIdc);
+#if !REMOVE_TILE_DEPENDENCE
+  printf("TileBoundaryIndependence:%d ", m_iTileBoundaryIndependenceIdr ); 
+#endif
+  printf("TileLocationInSliceHdr:%d ", m_iTileLocationInSliceHeaderFlag);
+  printf("TileMarker:%d", m_iTileMarkerFlag);
+  if (m_iTileMarkerFlag)
+  {
+    printf("[%d] ", m_iMaxTileMarkerEntryPoints);
+  }
+  else
+  {
+    printf(" ");
+  }
+  printf(" WaveFrontSynchro:%d WaveFrontFlush:%d WaveFrontSubstreams:%d",
+          m_iWaveFrontSynchro, m_iWaveFrontFlush, m_iWaveFrontSubstreams);
+  printf(" ScalingList:%d ", m_useScalingListId );
+
+  printf("TMVP:%d ", m_enableTMVP     );
+
+#if ADAPTIVE_QP_SELECTION
+  printf("AQpS:%d", m_bUseAdaptQpSelect   );
+#endif
+
+#if MULTIBITS_DATA_HIDING
+  printf(" SignBitHidingFlag:%d SignBitHidingThreshold:%d", m_signHideFlag, m_signHidingThreshold);
 #endif
   printf("\n");
@@ -1003,6 +1665,6 @@
   printf("MVI:%d ", m_bUseMVI ? 1 : 0 );
 #endif
-  printf("\n");
-
+  printf("\n\n");
+  
   fflush(stdout);
 }
@@ -1021,11 +1683,8 @@
   printf( "                   PAD - automatic source padding of multiple of 16\n");
   printf( "                   ASR - adaptive motion search range\n");
-  printf( "                   FEN - fast encoder setting\n");
-  printf( "                   MRG - merging of motion partitions\n"); // SOPH: Merge Mode
-
-#if LM_CHROMA
+  printf( "                   FEN - fast encoder setting\n");  
+  printf( "                   ECU - Early CU setting\n");
+  printf( "                   CFM - Cbf fast mode setting\n");
   printf( "                   LMC - intra chroma prediction based on luma\n");
-#endif
-
   printf( "\n" );
   printf( "  Example 1) TAppEncoder.exe -c test.cfg -q 32 -g 8 -f 9 -s 64 -h 4\n");
@@ -1039,5 +1698,5 @@
   if (!bflag)
     return false;
-
+  
   printf("Error: %s\n",message);
   return true;
@@ -1108,2 +1767,4 @@
   rpchOutputFileName[iInLength+iAppendLength] = '\0';
 }
+
+//! \}
Index: trunk/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncCfg.h	(revision 42)
+++ trunk/source/App/TAppEncoder/TAppEncCfg.h	(revision 56)
@@ -2,7 +2,7 @@
  * License, included below. This software may be subject to other third party
  * and contributor rights, including patent rights, and no such rights are
- * granted under this license.
+ * granted under this license.  
  *
- * Copyright (c) 2010-2011, ISO/IEC
+ * Copyright (c) 2010-2012, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -15,5 +15,5 @@
  *    this list of conditions and the following disclaimer in the documentation
  *    and/or other materials provided with the distribution.
- *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
  *    be used to endorse or promote products derived from this software without
  *    specific prior written permission.
@@ -32,6 +32,4 @@
  */
 
-
-
 /** \file     TAppEncCfg.h
     \brief    Handle encoder configuration parameters (header)
@@ -41,13 +39,17 @@
 #define __TAPPENCCFG__
 
-#include "../../Lib/TLibCommon/CommonDef.h"
-#include "../../Lib/TLibCommon/TComMVDRefData.h"
-#include "../../App/TAppCommon/TAppComCamPara.h"
-#include "../../Lib/TLibRenderer/TRenTop.h"
-#include "../../Lib/TLibRenderer/TRenModel.h"
-#include "../../Lib/TLibRenderer/TRenModSetupStrParser.h"
-
-#include <string>
+#include "TLibCommon/CommonDef.h"
+
+#include "TLibEncoder/TEncCfg.h"
+#include "TAppCommon/TAppComCamPara.h"
+#include "TLibRenderer/TRenTop.h"
+#include "TLibRenderer/TRenModel.h"
+#include "TLibRenderer/TRenModSetupStrParser.h"
+
+#include <sstream>
 #include <vector>
+
+//! \ingroup TAppEncoder
+//! \{
 
 // ====================================================================================================================
@@ -60,13 +62,10 @@
 protected:
   // file I/O
-  char*     m_pchBitstreamFile;                               ///< output bitstream file
-
   std::vector<char*>     m_pchInputFileList;                  ///< source file names
   std::vector<char*>     m_pchDepthInputFileList;             ///< source depth file names
   std::vector<char*>     m_pchReconFileList;                  ///< output reconstruction file names
   std::vector<char*>     m_pchDepthReconFileList;             ///< output depth reconstruction file names
-
-  std::vector<char*>     m_pchERRefFileList;                  ///< virtual external reference view files names
-
+  char*     m_pchBitstreamFile;                               ///< output bitstream file
+  Double    m_adLambdaModifier[ MAX_TLAYER ];                 ///< Lambda modifier array for each temporal layer
   // source specification
   Int       m_iFrameRate;                                     ///< source frame-rates (Hz)
@@ -74,42 +73,64 @@
   Int       m_iSourceWidth;                                   ///< source width in pixel
   Int       m_iSourceHeight;                                  ///< source height in pixel
+#if PIC_CROPPING
+  Int       m_croppingMode;
+  Int       m_cropLeft;
+  Int       m_cropRight;
+  Int       m_cropTop;
+  Int       m_cropBottom;
+#endif
   Int       m_iFrameToBeEncoded;                              ///< number of encoded frames
+#if !PIC_CROPPING
   Bool      m_bUsePAD;                                        ///< flag for using source padding
+#endif
   Int       m_aiPad[2];                                       ///< number of padded pixels for width and height
-
-  Int       m_iNumberOfViews;                                ///< number Views to Encode
-  Bool      m_bUsingDepthMaps ;
-
-#if FLEX_CODING_ORDER
-  char*		m_pchMVCJointCodingOrder;		///<  texture-depth coding order
-  Bool		m_b3DVFlexOrder;		///<  flexible coding order flag
-#endif
-
-
+  
+  Int       m_iNumberOfViews;                                 ///< number Views to Encode
+  Bool      m_bUsingDepthMaps;
   // coding structure
-#if DCM_DECODING_REFRESH
+  Int       m_iIntraPeriod;                                   ///< period of I-slice (random access period)
   Int       m_iDecodingRefreshType;                           ///< random access type
-#endif
-  UInt      m_uiCodedPictureStoreSize ;
   Int       m_iGOPSize;                                       ///< GOP size of hierarchical structure
-  Int       m_iRateGOPSize;                                   ///< GOP size for QP variance
-#if !HHI_NO_LowDelayCoding
-  Bool      m_bUseLDC;                                        ///< flag for using low-delay coding mode
-#endif
-#if DCM_COMB_LIST
+  Int       m_extraRPSs[MAX_VIEW_NUM];
+  GOPEntryMvc m_GOPListsMvc[MAX_VIEW_NUM][MAX_GOP+1];
+#if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER
+  Int       m_numReorderPics[MAX_VIEW_NUM][MAX_TLAYER];       ///< total number of reorder pictures
+  Int       m_maxDecPicBuffering[MAX_VIEW_NUM][MAX_TLAYER];   ///< total number of reference pictures needed for decoding
+#else
+  Int       m_numReorderFrames;                               ///< total number of reorder pictures
+  Int       m_maxNumberOfReferencePictures;                   ///< total number of reference pictures needed for decoding
+#endif
   Bool      m_bUseLComb;                                      ///< flag for using combined reference list for uni-prediction in B-slices (JCTVC-D421)
   Bool      m_bLCMod;                                         ///< flag for specifying whether the combined reference list for uni-prediction in B-slices is uploaded explicitly
-#endif
-  std::string     m_cInputFormatString ;                            // GOP string
+  Bool      m_bDisInter4x4;
+  Bool      m_enableNSQT;                                     ///< flag for enabling NSQT
+  Bool      m_enableAMP;
   // coding quality
-
   std::vector<Double>  m_adQP;                                ///< QP value of key-picture (floating point) [0] video, [1] depth
-  std::vector<Int>     m_aiQP;                                ///< QP value of key-picture (integer)
-
+  std::vector<Int>     m_aiQP;                                ///< QP value of key-picture (integer) [0] video, [1] depth
   Int       m_aiTLayerQPOffset[MAX_TLAYER];                   ///< QP offset corresponding to temporal layer depth
   char*     m_pchdQPFile;                                     ///< QP offset for each slice (initialized from external file)
   Int*      m_aidQP;                                          ///< array of slice QP values
+  Int*      m_aidQPdepth;                                     ///< array of depth slice QP values
   Int       m_iMaxDeltaQP;                                    ///< max. |delta QP|
   UInt      m_uiDeltaQpRD;                                    ///< dQP range for multi-pass slice QP optimization
+  Int       m_iMaxCuDQPDepth;                                 ///< Max. depth for a minimum CuDQPSize (0:default)
+
+  Int       m_iChromaQpOffset;                                 ///< ChromaQpOffset    (0:default) 
+  Int       m_iChromaQpOffset2nd;                              ///< ChromaQpOffset2nd (0:default)
+
+#if ADAPTIVE_QP_SELECTION
+  Bool      m_bUseAdaptQpSelect;
+#endif
+
+  Bool      m_bUseAdaptiveQP;                                 ///< Flag for enabling QP adaptation based on a psycho-visual model
+  Int       m_iQPAdaptationRange;                             ///< dQP range by QP adaptation
+  
+#if H0566_TLA
+  Int       m_maxTempLayer[MAX_VIEW_NUM];                     ///< Max temporal layer
+#else
+  Bool      m_bTLayering;                                     ///< indicates whether temporal IDs are set based on the hierarchical coding structure
+  Bool      m_abTLayerSwitchingFlag[MAX_TLAYER];              ///< temporal layer switching flags corresponding to each temporal layer
+#endif
 
   // coding unit (CU) definition
@@ -117,47 +138,55 @@
   UInt      m_uiMaxCUHeight;                                  ///< max. CU height in pixel
   UInt      m_uiMaxCUDepth;                                   ///< max. CU depth
-
+  
   // transfom unit (TU) definition
   UInt      m_uiQuadtreeTULog2MaxSize;
   UInt      m_uiQuadtreeTULog2MinSize;
-
+  
   UInt      m_uiQuadtreeTUMaxDepthInter;
   UInt      m_uiQuadtreeTUMaxDepthIntra;
-
+  
   // coding tools (bit-depth)
   UInt      m_uiInputBitDepth;                                ///< bit-depth of input file
   UInt      m_uiOutputBitDepth;                               ///< bit-depth of output file
-#ifdef ENABLE_IBDI
-  UInt      m_uiBitIncrement;                                 ///< bit-depth increment
-#endif
   UInt      m_uiInternalBitDepth;                             ///< Internal bit-depth (BitDepth+BitIncrement)
 
-#if MTK_SAO
+  // coding tools (PCM bit-depth)
+  Bool      m_bPCMInputBitDepthFlag;                          ///< 0: PCM bit-depth is internal bit-depth. 1: PCM bit-depth is input bit-depth.
+  UInt      m_uiPCMBitDepthLuma;                              ///< PCM bit-depth for luma
+
+  // coding tool (lossless)
+#if LOSSLESS_CODING
+  Bool      m_useLossless;                                    ///< flag for using lossless coding
+#endif
   vector<Bool> m_abUseSAO;
-#endif
-
+#if SAO_UNIT_INTERLEAVING
+  Int       m_maxNumOffsetsPerPic;                            ///< SAO maximun number of offset per picture
+  Bool      m_saoInterleavingFlag;                            ///< SAO interleaving flag
+#endif
   // coding tools (loop filter)
   vector<Bool> m_abUseALF;                                    ///< flag for using adaptive loop filter [0] - video, [1] - depth
-#ifdef MQT_ALF_NPASS
-  Int       m_iALFEncodePassReduction;                        ///< ALF encoding pass, 0 = original 16-pass, 1 = 1-pass, 2 = 2-pass
+  Int       m_iALFEncodePassReduction;                        //!< ALF encoding pass, 0 = original 16-pass, 1 = 1-pass, 2 = 2-pass
+  
+  Int       m_iALFMaxNumberFilters;                           ///< ALF Max Number Filters in one picture
+#if LCU_SYNTAX_ALF
+  Bool      m_bALFParamInSlice;
+  Bool      m_bALFPicBasedEncode;
 #endif
 
   vector<Bool> m_abLoopFilterDisable;                         ///< flag for using deblocking filter filter [0] - video, [1] - depth
-  Int       m_iLoopFilterAlphaC0Offset;                       ///< alpha offset for deblocking filter
-  Int       m_iLoopFilterBetaOffset;                          ///< beta offset for deblocking filter
-
-  // coding tools (entropy coder)
-  Int       m_iSymbolMode;                                    ///< entropy coder mode, 0 = VLC, 1 = CABAC
-
-  // coding tools (inter - merge motion partitions)
-  Bool      m_bUseMRG;                                        ///< SOPH: flag for using motion partition Merge Mode
-
-#if LM_CHROMA
+  Bool      m_loopFilterOffsetInAPS;                         ///< offset for deblocking filter in 0 = slice header, 1 = APS
+  Int       m_loopFilterBetaOffsetDiv2;                     ///< beta offset for deblocking filter
+  Int       m_loopFilterTcOffsetDiv2;                       ///< tc offset for deblocking filter
+#if DBL_CONTROL
+  Bool      m_DeblockingFilterControlPresent;                 ///< deblocking filter control present flag in PPS
+#endif
+ 
   Bool      m_bUseLMChroma;                                  ///< JL: Chroma intra prediction based on luma signal
-#endif
-
-#if HHI_RMP_SWITCH
-  Bool      m_bUseRMP;
-#endif
+
+  // coding tools (PCM)
+  Bool      m_usePCM;                                         ///< flag for using IPCM
+  UInt      m_pcmLog2MaxSize;                                 ///< log2 of maximum PCM block size
+  UInt      m_uiPCMLog2MinSize;                               ///< log2 of minimum PCM block size
+  Bool      m_bPCMFilterDisableFlag;                          ///< PCM filter disable flag
 
   // coding tools (encoder-only parameters)
@@ -165,9 +194,16 @@
   Bool      m_bUseASR;                                        ///< flag for using adaptive motion search range
   Bool      m_bUseHADME;                                      ///< flag for using HAD in sub-pel ME
-  vector<Bool> m_abUseRDOQ;                                   ///< flag for using RD optimized quantization [0]-video, [1]-depth
+vector<Bool> m_abUseRDOQ;                                   ///< flag for using RD optimized quantization [0]-video, [1]-depth
   Int       m_iFastSearch;                                    ///< ME mode, 0 = full, 1 = diamond, 2 = PMVFAST
   Int       m_iSearchRange;                                   ///< ME search range
   Int       m_bipredSearchRange;                              ///< ME search range for bipred refinement
   Bool      m_bUseFastEnc;                                    ///< flag for using fast encoder setting
+#if HHI_INTERVIEW_SKIP
+  Bool      m_bInterViewSkip;                            ///< usage of interview skip mode ( do not transmit residual)
+#if HHI_INTERVIEW_SKIP_LAMBDA_SCALE
+  Double    m_dInterViewSkipLambdaScale;                 ///< lambda scale for interview skip
+#endif
+#endif
+  Bool      m_bUseEarlyCU;                                    ///< flag for using Early CU setting
 
 #if DEPTH_MAP_GENERATION
@@ -183,10 +219,54 @@
 #endif
 
-#if HHI_INTERVIEW_SKIP
-  UInt      m_uiInterViewSkip;                            ///< usage of interview skip mode ( do not transmit residual)
-#if HHI_INTERVIEW_SKIP_LAMBDA_SCALE
-  Double    m_dInterViewSkipLambdaScale;                 ///< lambda scale for interview skip
-#endif
-#endif
+#if FAST_DECISION_FOR_MRG_RD_COST
+  Bool      m_useFastDecisionForMerge;                        ///< flag for using Fast Decision Merge RD-Cost 
+#endif
+  Bool      m_bUseCbfFastMode;                              ///< flag for using Cbf Fast PU Mode Decision
+  Int       m_iSliceMode;           ///< 0: Disable all Recon slice limits, 1 : Maximum number of largest coding units per slice, 2: Maximum number of bytes in a slice
+  Int       m_iSliceArgument;       ///< If m_iSliceMode==1, m_iSliceArgument=max. # of largest coding units. If m_iSliceMode==2, m_iSliceArgument=max. # of bytes.
+  Int       m_iEntropySliceMode;    ///< 0: Disable all entropy slice limits, 1 : Maximum number of largest coding units per slice, 2: Constraint based entropy slice
+  Int       m_iEntropySliceArgument;///< If m_iEntropySliceMode==1, m_iEntropySliceArgument=max. # of largest coding units. If m_iEntropySliceMode==2, m_iEntropySliceArgument=max. # of bins.
+
+  Int       m_iSliceGranularity;///< 0: Slices always end at LCU borders. 1-3: slices may end at a depth of 1-3 below LCU level.
+  Bool m_bLFCrossSliceBoundaryFlag;  ///< 0: Cross-slice-boundary in-loop filtering 1: non-cross-slice-boundary in-loop filtering
+  Int  m_iTileBehaviorControlPresentFlag; //!< 1: tile behavior control parameters are in PPS 0: tile behavior control parameters are not in PPS
+  Bool m_bLFCrossTileBoundaryFlag;  //!< 1: Cross-tile-boundary in-loop filtering 0: non-cross-tile-boundary in-loop filtering
+  Int       m_iColumnRowInfoPresent;
+  Int       m_iUniformSpacingIdr;
+#if !REMOVE_TILE_DEPENDENCE
+  Int       m_iTileBoundaryIndependenceIdr;
+#endif
+  Int       m_iNumColumnsMinus1;
+  char*     m_pchColumnWidth;
+  Int       m_iNumRowsMinus1;
+  char*     m_pchRowHeight;
+  Int       m_iTileLocationInSliceHeaderFlag; //< enable(1)/disable(0) transmitssion of tile location in slice header
+  Int       m_iTileMarkerFlag;              //< enable(1)/disable(0) transmitssion of light weight tile marker
+  Int       m_iMaxTileMarkerEntryPoints;    //< maximum number of tile markers allowed in a slice (controls degree of parallelism)
+  Double    m_dMaxTileMarkerOffset;         //< Calculated offset. Light weight tile markers will be transmitted for TileIdx= Offset, 2*Offset, 3*Offset ... 
+
+  Int       m_iWaveFrontSynchro; //< 0: no WPP. >= 1: WPP is enabled, the "Top right" from which inheritance occurs is this LCU offset in the line above the current.
+  Int       m_iWaveFrontFlush; //< enable(1)/disable(0) the CABAC flush at the end of each line of LCUs.
+  Int       m_iWaveFrontSubstreams; //< If iWaveFrontSynchro, this is the number of substreams per frame (dependent tiles) or per tile (independent tiles).
+
+  Bool      m_bUseConstrainedIntraPred;                       ///< flag for using constrained intra prediction
+  
+  bool m_pictureDigestEnabled; ///< enable(1)/disable(0) md5 computation and SEI signalling
+
+  // weighted prediction
+  Bool      m_bUseWeightPred;                                 ///< Use of explicit Weighting Prediction for P_SLICE
+  UInt      m_uiBiPredIdc;                                    ///< Use of Bi-Directional Weighting Prediction (B_SLICE): explicit(1) or implicit(2)
+
+  Bool      m_enableTMVP;
+#if MULTIBITS_DATA_HIDING
+  Int       m_signHideFlag;
+  Int       m_signHidingThreshold;
+#endif
+#if HHI_MPI
+  Bool      m_bUseMVI;  ///< flag for using Motion Vector Inheritance for depth map coding
+#endif
+
+  Int       m_useScalingListId;                               ///< using quantization matrix
+  char*     m_scalingListFile;                                ///< quantization matrix file name
 
   // camera parameter
@@ -196,8 +276,4 @@
 
   Int       m_iCodedCamParPrecision;                          ///< precision for coding of camera parameters
-
-#if HHI_INTERVIEW_SKIP
-  TRenTop  m_cUsedPelsRenderer;                               ///< renderer for used pels map
-#endif
 
 #if HHI_VSO
@@ -211,42 +287,10 @@
   Bool      m_bAllowNegDist;                              ///< Allow negative distortion in VSO
 #endif
-  UInt      m_uiVSOMode;                                  ///< Number of VSO Mode, 1 = , 2 = simple, org vs. ren, 3 = simple, ren vs. ren, 4 = full
-  Int       m_iNumberOfExternalRefs;                      ///< number Virtual External Reference Views
-  std::vector< std::vector<Int> > m_aaiBaseViewRefInd;    ///< View numbers of Base View References
-  std::vector< std::vector<Int> > m_aaiERViewRefInd;      ///< View numbers of External ViewReferences
-  std::vector< std::vector<Int> > m_aaiERViewRefLutInd;   ///< Indices of LUTs used for External View References
-#endif
-
-  Int       m_iSliceMode;           ///< 0: Disable all Recon slice limits, 1 : Maximum number of largest coding units per slice, 2: Maximum number of bytes in a slice
-  Int       m_iSliceArgument;       ///< If m_iSliceMode==1, m_iSliceArgument=max. # of largest coding units. If m_iSliceMode==2, m_iSliceArgument=max. # of bytes.
-  Int       m_iEntropySliceMode;    ///< 0: Disable all entropy slice limits, 1 : Maximum number of largest coding units per slice, 2: Constraint based entropy slice
-  Int       m_iEntropySliceArgument;///< If m_iEntropySliceMode==1, m_iEntropySliceArgument=max. # of largest coding units. If m_iEntropySliceMode==2, m_iEntropySliceArgument=max. # of bins.
-
-#if MTK_NONCROSS_INLOOP_FILTER
-  Bool m_bLFCrossSliceBoundaryFlag;  ///< 0: Cross-slice-boundary in-loop filtering 1: non-cross-slice-boundary in-loop filtering
-#endif
-#ifdef ROUNDING_CONTROL_BIPRED
-  Bool m_useRoundingControlBipred;
-#endif
-#if CONSTRAINED_INTRA_PRED
-  Bool      m_bUseConstrainedIntraPred;                       ///< flag for using constrained intra prediction
-#endif
+  UInt      m_uiVSOMode;                                  ///< Number of VSO Mode, 1 = , 2 = simple, org vs. ren, 3 = simple, ren vs. ren, 4 = full  
+#endif
+
+  // coding tools (depth intra modes)
 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
-  Bool      m_bUseDMM;
-#endif
-#if HHI_MPI
-  Bool      m_bUseMVI;  ///< flag for using Motion Vector Inheritance for depth map coding
-#endif
-
-  PicOrderCnt m_iQpChangeFrame;
-  Int         m_iQpChangeOffsetVideo;
-  Int         m_iQpChangeOffsetDepth;
-
-  bool m_pictureDigestEnabled; ///< enable(1)/disable(0) md5 computation and SEI signalling
-
-  //====== Weighted Prediction ========
-#ifdef WEIGHT_PRED
-  Bool                    m_bUseWeightPred;                   ///< Use of explicit Weighting Prediction for P_SLICE
-  UInt                    m_uiBiPredIdc;                      ///< Use of Bi-Directional Weighting Prediction (B_SLICE): explicit(1) or implicit(2)
+  Bool      m_bUseDMM;                                        ///< flag for using DMM
 #endif
 
@@ -256,5 +300,5 @@
   Void  xPrintParameter ();                                   ///< print configuration values
   Void  xPrintUsage     ();                                   ///< print usage
-
+  
   Void  xCleanUpVectors ();                                   ///< clean up vector sizes
   Void  xInitCameraPars ();                                   ///< init camera parameters
@@ -265,11 +309,9 @@
   Void xGetShiftParameter( UInt uiSourceView, UInt uiTargetView, bool bExternal, double& rdScale, double& rdOffset ); ///< Get one Shift Parameters
 
-  // util
   Void  xAppendToFileNameEnd( Char* pchInputFileName, const Char* pchStringToAppend, Char* & rpchOutputFileName);
-  Bool  xConfirmParameter(Bool bflag, const char* message);
-
+
+  Void  xCheckCodingStructureMvc();                           ///< validate and configure inter-view coding structure
 
   template <class T> Void xCleanUpVector( std::vector<T>& rcVec, const T& rcInvalid );
-
 #if HHI_VSO
   // Ren Model String
@@ -277,15 +319,16 @@
 #endif
 public:
-
   TAppEncCfg();
   virtual ~TAppEncCfg();
-
+  
 public:
   Void  create    ();                                         ///< create option handling class
   Void  destroy   ();                                         ///< destroy option handling class
   Bool  parseCfg  ( Int argc, Char* argv[] );                 ///< parse configuration file to fill member variables
-
+  
 };// END CLASS DEFINITION TAppEncCfg
 
+//! \}
+
 #endif // __TAPPENCCFG__
 
Index: trunk/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 42)
+++ trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 56)
@@ -2,7 +2,7 @@
  * License, included below. This software may be subject to other third party
  * and contributor rights, including patent rights, and no such rights are
- * granted under this license.
+ * granted under this license.  
  *
- * Copyright (c) 2010-2011, ISO/IEC
+ * Copyright (c) 2010-2012, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -15,5 +15,5 @@
  *    this list of conditions and the following disclaimer in the documentation
  *    and/or other materials provided with the distribution.
- *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
  *    be used to endorse or promote products derived from this software without
  *    specific prior written permission.
@@ -32,6 +32,4 @@
  */
 
-
-
 /** \file     TAppEncTop.cpp
     \brief    Encoder application class
@@ -39,4 +37,6 @@
 
 #include <list>
+#include <fstream>
+#include <stdlib.h>
 #include <stdio.h>
 #include <fcntl.h>
@@ -44,4 +44,10 @@
 
 #include "TAppEncTop.h"
+#include "TLibEncoder/AnnexBwrite.h"
+
+using namespace std;
+
+//! \ingroup TAppEncoder
+//! \{
 
 // ====================================================================================================================
@@ -51,7 +57,6 @@
 TAppEncTop::TAppEncTop()
 {
-#if HHI_VSO
-  m_iLastFramePutInERViewBuffer = -1;
-#endif
+  m_totalBytes = 0;
+  m_essentialBytes = 0;
 }
 
@@ -60,55 +65,114 @@
 }
 
-
 Void TAppEncTop::xInitLibCfg()
 {
   for(Int iViewIdx=0; iViewIdx<m_iNumberOfViews; iViewIdx++)
   {
-    m_iFrameRcvdVector.push_back(0) ;
-    m_acTEncTopList.push_back(new TEncTop);
-
+    m_frameRcvd.push_back(0);
+    m_acTEncTopList.push_back(new TEncTop); 
     m_acTVideoIOYuvInputFileList.push_back(new TVideoIOYuv);
-
     m_acTVideoIOYuvReconFileList.push_back(new TVideoIOYuv);
-    m_cListPicYuvRecList.push_back(new TComList<TComPicYuv*>) ;
-    m_aiNextPocToDump.push_back( 0 );
-    m_cListPicYuvRecMap.push_back( std::map<PicOrderCnt,TComPicYuv*>() );
+    m_picYuvRec.push_back(new TComList<TComPicYuv*>) ;
+
     m_acTEncTopList[iViewIdx]->setFrameRate                    ( m_iFrameRate );
     m_acTEncTopList[iViewIdx]->setFrameSkip                    ( m_FrameSkip );
     m_acTEncTopList[iViewIdx]->setSourceWidth                  ( m_iSourceWidth );
     m_acTEncTopList[iViewIdx]->setSourceHeight                 ( m_iSourceHeight );
+#if PIC_CROPPING
+    m_acTEncTopList[iViewIdx]->setCroppingMode                 ( m_croppingMode );
+    m_acTEncTopList[iViewIdx]->setCropLeft                     ( m_cropLeft );
+    m_acTEncTopList[iViewIdx]->setCropRight                    ( m_cropRight );
+    m_acTEncTopList[iViewIdx]->setCropTop                      ( m_cropTop );
+    m_acTEncTopList[iViewIdx]->setCropBottom                   ( m_cropBottom );
+#endif
     m_acTEncTopList[iViewIdx]->setFrameToBeEncoded             ( m_iFrameToBeEncoded );
+    m_acTEncTopList[iViewIdx]->setViewId                       ( iViewIdx );
+    m_acTEncTopList[iViewIdx]->setIsDepth                      ( false );
+    m_acTEncTopList[iViewIdx]->setViewOrderIdx                 ( m_cCameraData.getViewOrderIndex()[ iViewIdx ] );
+    m_acTEncTopList[iViewIdx]->setCamParPrecision              ( m_cCameraData.getCamParsCodedPrecision  () );
+    m_acTEncTopList[iViewIdx]->setCamParInSliceHeader          ( m_cCameraData.getVaryingCameraParameters() );
+    m_acTEncTopList[iViewIdx]->setCodedScale                   ( m_cCameraData.getCodedScale             () );
+    m_acTEncTopList[iViewIdx]->setCodedOffset                  ( m_cCameraData.getCodedOffset            () );
 
   //====== Coding Structure ========
-#if DCM_DECODING_REFRESH
+    m_acTEncTopList[iViewIdx]->setIntraPeriod                  ( m_iIntraPeriod );
     m_acTEncTopList[iViewIdx]->setDecodingRefreshType          ( m_iDecodingRefreshType );
-#endif
-    m_acTEncTopList[iViewIdx]->setCPSSize                      ( m_uiCodedPictureStoreSize );
     m_acTEncTopList[iViewIdx]->setGOPSize                      ( m_iGOPSize );
-    m_acTEncTopList[iViewIdx]->setRateGOPSize                  ( m_iRateGOPSize );
-
-    m_acTEncTopList[iViewIdx]->setSeqStructure                              ( m_cInputFormatString );
-
+    m_acTEncTopList[iViewIdx]->setGopList                      ( m_GOPListsMvc[iViewIdx] );
+    m_acTEncTopList[iViewIdx]->setExtraRPSs                    ( m_extraRPSs[iViewIdx] );
+#if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER
+    for(Int i = 0; i < MAX_TLAYER; i++)
+    {
+      m_acTEncTopList[iViewIdx]->setNumReorderPics             ( m_numReorderPics[iViewIdx][i], i );
+      m_acTEncTopList[iViewIdx]->setMaxDecPicBuffering         ( m_maxDecPicBuffering[iViewIdx][i], i );
+    }
+#else
+    m_acTEncTopList[iViewIdx]->setNumReorderFrames             ( m_numReorderFrames );
+    m_acTEncTopList[iViewIdx]->setMaxNumberOfReferencePictures ( m_maxNumberOfReferencePictures );
+#endif
+    for( UInt uiLoop = 0; uiLoop < MAX_TLAYER; ++uiLoop )
+    {
+      m_acTEncTopList[iViewIdx]->setLambdaModifier( uiLoop, m_adLambdaModifier[ uiLoop ] );
+    }
     m_acTEncTopList[iViewIdx]->setQP                           ( m_aiQP[0] );
-
+  
     m_acTEncTopList[iViewIdx]->setTemporalLayerQPOffset        ( m_aiTLayerQPOffset );
     m_acTEncTopList[iViewIdx]->setPad                          ( m_aiPad );
-
-    //===== Slice ========
-
-    //====== Entropy Coding ========
-    m_acTEncTopList[iViewIdx]->setSymbolMode                   ( m_iSymbolMode );
-
-    //====== Loop/Deblock Filter ========
-    m_acTEncTopList[iViewIdx]->setLoopFilterDisable            ( m_abLoopFilterDisable[0]   );
-    m_acTEncTopList[iViewIdx]->setLoopFilterAlphaC0Offset      ( m_iLoopFilterAlphaC0Offset );
-    m_acTEncTopList[iViewIdx]->setLoopFilterBetaOffset         ( m_iLoopFilterBetaOffset    );
-
-    //====== Motion search ========
+    
+#if H0566_TLA
+    m_acTEncTopList[iViewIdx]->setMaxTempLayer                 ( m_maxTempLayer[iViewIdx] );
+#else
+    m_acTEncTopList[iViewIdx]->setTLayering                    ( m_bTLayering );
+    m_acTEncTopList[iViewIdx]->setTLayerSwitchingFlag          ( m_abTLayerSwitchingFlag );
+#endif
+
+    m_acTEncTopList[iViewIdx]->setDisInter4x4                  ( m_bDisInter4x4);
+  
+    m_acTEncTopList[iViewIdx]->setUseNSQT( m_enableNSQT );
+    m_acTEncTopList[iViewIdx]->setUseAMP( m_enableAMP );
+  
+  //===== Slice ========
+  
+  //====== Loop/Deblock Filter ========
+    m_acTEncTopList[iViewIdx]->setLoopFilterDisable            ( m_abLoopFilterDisable[0]       );
+    m_acTEncTopList[iViewIdx]->setLoopFilterOffsetInAPS        ( m_loopFilterOffsetInAPS );
+    m_acTEncTopList[iViewIdx]->setLoopFilterBetaOffset         ( m_loopFilterBetaOffsetDiv2  );
+    m_acTEncTopList[iViewIdx]->setLoopFilterTcOffset           ( m_loopFilterTcOffsetDiv2    );
+#if DBL_CONTROL
+    m_acTEncTopList[iViewIdx]->setDeblockingFilterControlPresent( m_DeblockingFilterControlPresent);
+#endif
+
+  //====== Motion search ========
     m_acTEncTopList[iViewIdx]->setFastSearch                   ( m_iFastSearch  );
     m_acTEncTopList[iViewIdx]->setSearchRange                  ( m_iSearchRange );
     m_acTEncTopList[iViewIdx]->setBipredSearchRange            ( m_bipredSearchRange );
+
+  //====== Quality control ========
     m_acTEncTopList[iViewIdx]->setMaxDeltaQP                   ( m_iMaxDeltaQP  );
-
+    m_acTEncTopList[iViewIdx]->setMaxCuDQPDepth                ( m_iMaxCuDQPDepth  );
+
+    m_acTEncTopList[iViewIdx]->setChromaQpOffset               ( m_iChromaQpOffset     );
+    m_acTEncTopList[iViewIdx]->setChromaQpOffset2nd            ( m_iChromaQpOffset2nd  );
+
+#if ADAPTIVE_QP_SELECTION
+    m_acTEncTopList[iViewIdx]->setUseAdaptQpSelect             ( m_bUseAdaptQpSelect   );
+#endif
+
+#if LOSSLESS_CODING
+    Int lowestQP;
+#if H0736_AVC_STYLE_QP_RANGE
+    lowestQP =  - ( (Int)(6*(g_uiBitDepth + g_uiBitIncrement - 8)) );
+#else
+    lowestQP = 0;
+#endif
+    if ((m_iMaxDeltaQP == 0 ) && (m_aiQP[0] == lowestQP) && (m_useLossless == true))
+    {
+      m_bUseAdaptiveQP = false;
+    }
+#endif
+
+    m_acTEncTopList[iViewIdx]->setUseAdaptiveQP                ( m_bUseAdaptiveQP  );
+    m_acTEncTopList[iViewIdx]->setQPAdaptationRange            ( m_iQPAdaptationRange );
+  
 #if HHI_VSO
     //====== VSO =========
@@ -116,7 +180,23 @@
     m_acTEncTopList[iViewIdx]->setLambdaScaleVSO               ( 1     );
     m_acTEncTopList[iViewIdx]->setVSOMode                      ( 0     );
-#endif
-
-    //====== Tool list ========
+    m_acTEncTopList[iViewIdx]->setUseVSO                       ( false ); //GT: might be enabled later for VSO Mode 4
+#endif
+
+#if DEPTH_MAP_GENERATION
+    m_acTEncTopList[iViewIdx]->setPredDepthMapGeneration       ( m_uiPredDepthMapGeneration );
+    m_acTEncTopList[iViewIdx]->setPdmPrecision                 ( (UInt)m_cCameraData.getPdmPrecision     () );
+    m_acTEncTopList[iViewIdx]->setPdmScaleNomDelta             (       m_cCameraData.getPdmScaleNomDelta () );
+    m_acTEncTopList[iViewIdx]->setPdmOffset                    (       m_cCameraData.getPdmOffset        () );
+#endif
+#if HHI_INTER_VIEW_MOTION_PRED
+    m_acTEncTopList[iViewIdx]->setMultiviewMvPredMode          ( m_uiMultiviewMvPredMode );
+    m_acTEncTopList[iViewIdx]->setMultiviewMvRegMode           ( iViewIdx ? m_uiMultiviewMvRegMode       : 0   );
+    m_acTEncTopList[iViewIdx]->setMultiviewMvRegLambdaScale    ( iViewIdx ? m_dMultiviewMvRegLambdaScale : 0.0 );
+#endif
+#if HHI_INTER_VIEW_RESIDUAL_PRED
+    m_acTEncTopList[iViewIdx]->setMultiviewResPredMode         ( m_uiMultiviewResPredMode );
+#endif
+
+  //====== Tool list ========
     m_acTEncTopList[iViewIdx]->setUseSBACRD                    ( m_bUseSBACRD   );
     m_acTEncTopList[iViewIdx]->setDeltaQpRD                    ( m_uiDeltaQpRD  );
@@ -124,15 +204,17 @@
     m_acTEncTopList[iViewIdx]->setUseHADME                     ( m_bUseHADME    );
     m_acTEncTopList[iViewIdx]->setUseALF                       ( m_abUseALF[0]  );
-#if MQT_ALF_NPASS
     m_acTEncTopList[iViewIdx]->setALFEncodePassReduction       ( m_iALFEncodePassReduction );
-#endif
-#if DCM_COMB_LIST
+#if LOSSLESS_CODING
+    m_acTEncTopList[iViewIdx]->setUseLossless                  ( m_useLossless );
+#endif
+    m_acTEncTopList[iViewIdx]->setALFMaxNumberFilters          ( m_iALFMaxNumberFilters ) ;
+
     m_acTEncTopList[iViewIdx]->setUseLComb                     ( m_bUseLComb    );
     m_acTEncTopList[iViewIdx]->setLCMod                        ( m_bLCMod         );
-#endif
     m_acTEncTopList[iViewIdx]->setdQPs                         ( m_aidQP        );
     m_acTEncTopList[iViewIdx]->setUseRDOQ                      ( m_abUseRDOQ[0] );
-    m_acTEncTopList[iViewIdx]->setUseLDC                       ( m_bUseLDC      );
+#if !PIC_CROPPING
     m_acTEncTopList[iViewIdx]->setUsePAD                       ( m_bUsePAD      );
+#endif
     m_acTEncTopList[iViewIdx]->setQuadtreeTULog2MaxSize        ( m_uiQuadtreeTULog2MaxSize );
     m_acTEncTopList[iViewIdx]->setQuadtreeTULog2MinSize        ( m_uiQuadtreeTULog2MinSize );
@@ -140,150 +222,171 @@
     m_acTEncTopList[iViewIdx]->setQuadtreeTUMaxDepthIntra      ( m_uiQuadtreeTUMaxDepthIntra );
     m_acTEncTopList[iViewIdx]->setUseFastEnc                   ( m_bUseFastEnc  );
-
-#if HHI_VSO
-    m_acTEncTopList[iViewIdx]->setUseVSO                       ( false ); //GT: might be enabled later for VSO Mode 4
-#endif
-
-#if BITSTREAM_EXTRACTION
-    m_acTEncTopList[iViewIdx]->setLayerId                      ( ( (UInt)iViewIdx ) << 1 );
-#endif
-    m_acTEncTopList[iViewIdx]->setViewId                       ( (UInt)iViewIdx );
-    m_acTEncTopList[iViewIdx]->setViewOrderIdx                 ( m_cCameraData.getViewOrderIndex()[ iViewIdx ] );
-    m_acTEncTopList[iViewIdx]->setIsDepth                      ( false );
-    m_acTEncTopList[iViewIdx]->setCamParPrecision              ( m_cCameraData.getCamParsCodedPrecision  () );
-    m_acTEncTopList[iViewIdx]->setCamParInSliceHeader          ( m_cCameraData.getVaryingCameraParameters() );
-    m_acTEncTopList[iViewIdx]->setCodedScale                   ( m_cCameraData.getCodedScale             () );
-    m_acTEncTopList[iViewIdx]->setCodedOffset                  ( m_cCameraData.getCodedOffset            () );
-#if DEPTH_MAP_GENERATION
-    m_acTEncTopList[iViewIdx]->setPredDepthMapGeneration       ( m_uiPredDepthMapGeneration );
-    m_acTEncTopList[iViewIdx]->setPdmPrecision                 ( (UInt)m_cCameraData.getPdmPrecision     () );
-    m_acTEncTopList[iViewIdx]->setPdmScaleNomDelta             (       m_cCameraData.getPdmScaleNomDelta () );
-    m_acTEncTopList[iViewIdx]->setPdmOffset                    (       m_cCameraData.getPdmOffset        () );
-#endif
-#if HHI_INTER_VIEW_MOTION_PRED
-    m_acTEncTopList[iViewIdx]->setMultiviewMvPredMode          ( m_uiMultiviewMvPredMode );
-    m_acTEncTopList[iViewIdx]->setMultiviewMvRegMode           ( iViewIdx ? m_uiMultiviewMvRegMode       : 0   );
-    m_acTEncTopList[iViewIdx]->setMultiviewMvRegLambdaScale    ( iViewIdx ? m_dMultiviewMvRegLambdaScale : 0.0 );
-#endif
-#if HHI_INTER_VIEW_RESIDUAL_PRED
-    m_acTEncTopList[iViewIdx]->setMultiviewResPredMode         ( m_uiMultiviewResPredMode );
-#endif
-
-
+    m_acTEncTopList[iViewIdx]->setUseEarlyCU                   ( m_bUseEarlyCU  ); 
+#if FAST_DECISION_FOR_MRG_RD_COST
+    m_acTEncTopList[iViewIdx]->setUseFastDecisionForMerge      ( m_useFastDecisionForMerge  );
+#endif
+    m_acTEncTopList[iViewIdx]->setUseCbfFastMode               ( m_bUseCbfFastMode  );
 #if HHI_INTERVIEW_SKIP
-    m_acTEncTopList[iViewIdx]->setInterViewSkip            ( iViewIdx ? m_uiInterViewSkip : 0 );
+    m_acTEncTopList[iViewIdx]->setInterViewSkip            ( iViewIdx>0 ? m_bInterViewSkip : false );
 #if HHI_INTERVIEW_SKIP_LAMBDA_SCALE
-    m_acTEncTopList[iViewIdx]->setInterViewSkipLambdaScale ( iViewIdx ? (Int)m_dInterViewSkipLambdaScale : 1 );
-#endif
-#endif
-    m_acTEncTopList[iViewIdx]->setUseMRG                       ( m_bUseMRG      ); // SOPH:
-
-#if LM_CHROMA
+    m_acTEncTopList[iViewIdx]->setInterViewSkipLambdaScale ( iViewIdx>0 ? (UInt)m_dInterViewSkipLambdaScale : 1 );
+#endif
+#endif
     m_acTEncTopList[iViewIdx]->setUseLMChroma                  ( m_bUseLMChroma );
-#endif
-
-#if HHI_RMP_SWITCH
-    m_acTEncTopList[iViewIdx]->setUseRMP                     ( m_bUseRMP );
-#endif
-#ifdef ROUNDING_CONTROL_BIPRED
-    m_acTEncTopList[iViewIdx]->setUseRoundingControlBipred(m_useRoundingControlBipred);
-#endif
+    m_acTEncTopList[iViewIdx]->setUseConstrainedIntraPred      ( m_bUseConstrainedIntraPred );
+    m_acTEncTopList[iViewIdx]->setPCMLog2MinSize               ( m_uiPCMLog2MinSize);
+    m_acTEncTopList[iViewIdx]->setUsePCM                       ( m_usePCM );
+    m_acTEncTopList[iViewIdx]->setPCMLog2MaxSize               ( m_pcmLog2MaxSize);
+
+  //====== Weighted Prediction ========
+    m_acTEncTopList[iViewIdx]->setUseWP                        ( m_bUseWeightPred      );
+    m_acTEncTopList[iViewIdx]->setWPBiPredIdc                  ( m_uiBiPredIdc         );
+  //====== Slice ========
+    m_acTEncTopList[iViewIdx]->setSliceMode                    ( m_iSliceMode                );
+    m_acTEncTopList[iViewIdx]->setSliceArgument                ( m_iSliceArgument            );
+
+  //====== Entropy Slice ========
+    m_acTEncTopList[iViewIdx]->setEntropySliceMode             ( m_iEntropySliceMode         );
+    m_acTEncTopList[iViewIdx]->setEntropySliceArgument         ( m_iEntropySliceArgument     );
+    int iNumPartInCU = 1<<(m_uiMaxCUDepth<<1);
+    if(m_iEntropySliceMode==SHARP_FIXED_NUMBER_OF_LCU_IN_ENTROPY_SLICE)
+    {
+      m_acTEncTopList[iViewIdx]->setEntropySliceArgument ( m_iEntropySliceArgument * ( iNumPartInCU >> ( m_iSliceGranularity << 1 ) ) );
+    }
+    if(m_iSliceMode==AD_HOC_SLICES_FIXED_NUMBER_OF_LCU_IN_SLICE)
+    {
+      m_acTEncTopList[iViewIdx]->setSliceArgument ( m_iSliceArgument * ( iNumPartInCU >> ( m_iSliceGranularity << 1 ) ) );
+    }
+#if FIXED_NUMBER_OF_TILES_SLICE_MODE
+    if(m_iSliceMode==AD_HOC_SLICES_FIXED_NUMBER_OF_TILES_IN_SLICE)
+    {
+      m_acTEncTopList[iViewIdx]->setSliceArgument ( m_iSliceArgument );
+    }
+#endif
+    m_acTEncTopList[iViewIdx]->setSliceGranularity        ( m_iSliceGranularity         );
+    if(m_iSliceMode == 0 )
+    {
+      m_bLFCrossSliceBoundaryFlag = true;
+    }
+    m_acTEncTopList[iViewIdx]->setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag );
+    m_acTEncTopList[iViewIdx]->setUseSAO               ( m_abUseSAO[0]     );
+#if SAO_UNIT_INTERLEAVING
+    m_acTEncTopList[iViewIdx]->setMaxNumOffsetsPerPic (m_maxNumOffsetsPerPic);
+    m_acTEncTopList[iViewIdx]->setSaoInterleavingFlag (m_saoInterleavingFlag);
+#endif
+    m_acTEncTopList[iViewIdx]->setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag); 
+    m_acTEncTopList[iViewIdx]->setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag); 
+
+    m_acTEncTopList[iViewIdx]->setPictureDigestEnabled(m_pictureDigestEnabled);
+
+    m_acTEncTopList[iViewIdx]->setColumnRowInfoPresent       ( m_iColumnRowInfoPresent );
+    m_acTEncTopList[iViewIdx]->setUniformSpacingIdr          ( m_iUniformSpacingIdr );
+#if !REMOVE_TILE_DEPENDENCE
+    m_acTEncTopList[iViewIdx]->setTileBoundaryIndependenceIdr( m_iTileBoundaryIndependenceIdr );
+#endif
+    m_acTEncTopList[iViewIdx]->setNumColumnsMinus1           ( m_iNumColumnsMinus1 );
+    m_acTEncTopList[iViewIdx]->setNumRowsMinus1              ( m_iNumRowsMinus1 );
+    if(m_iUniformSpacingIdr==0)
+    {
+      m_acTEncTopList[iViewIdx]->setColumnWidth              ( m_pchColumnWidth );
+      m_acTEncTopList[iViewIdx]->setRowHeight                ( m_pchRowHeight );
+    }
+    m_acTEncTopList[iViewIdx]->xCheckGSParameters();
+    m_acTEncTopList[iViewIdx]->setTileLocationInSliceHeaderFlag ( m_iTileLocationInSliceHeaderFlag );
+    m_acTEncTopList[iViewIdx]->setTileMarkerFlag              ( m_iTileMarkerFlag );
+    m_acTEncTopList[iViewIdx]->setMaxTileMarkerEntryPoints    ( m_iMaxTileMarkerEntryPoints );
+  
+    Int uiTilesCount          = (m_iNumRowsMinus1+1) * (m_iNumColumnsMinus1+1);
+    m_dMaxTileMarkerOffset    = ((Double)uiTilesCount) / m_iMaxTileMarkerEntryPoints;
+    m_acTEncTopList[iViewIdx]->setMaxTileMarkerOffset         ( m_dMaxTileMarkerOffset );
+    m_acTEncTopList[iViewIdx]->setTileBehaviorControlPresentFlag( m_iTileBehaviorControlPresentFlag );
+#if !REMOVE_TILE_DEPENDENCE
+    if(m_iTileBoundaryIndependenceIdr == 0 || uiTilesCount == 1)
+#else
+    if(uiTilesCount == 1)
+#endif
+    {
+      m_bLFCrossTileBoundaryFlag = true; 
+    }
+    m_acTEncTopList[iViewIdx]->setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag );
+    m_acTEncTopList[iViewIdx]->setWaveFrontSynchro           ( m_iWaveFrontSynchro );
+    m_acTEncTopList[iViewIdx]->setWaveFrontFlush             ( m_iWaveFrontFlush );
+    m_acTEncTopList[iViewIdx]->setWaveFrontSubstreams        ( m_iWaveFrontSubstreams );
+    m_acTEncTopList[iViewIdx]->setEnableTMVP ( m_enableTMVP );
+    m_acTEncTopList[iViewIdx]->setUseScalingListId           ( m_useScalingListId  );
+    m_acTEncTopList[iViewIdx]->setScalingListFile            ( m_scalingListFile   );
+#if MULTIBITS_DATA_HIDING
+    m_acTEncTopList[iViewIdx]->setSignHideFlag(m_signHideFlag);
+    m_acTEncTopList[iViewIdx]->setTSIG(m_signHidingThreshold);
+#endif
+
+#if LCU_SYNTAX_ALF
+    if(uiTilesCount > 1)
+    {
+      m_bALFParamInSlice = false;
+      m_bALFPicBasedEncode = true;
+    }
+    m_acTEncTopList[iViewIdx]->setALFParamInSlice              ( m_bALFParamInSlice);
+    m_acTEncTopList[iViewIdx]->setALFPicBasedEncode            ( m_bALFPicBasedEncode);
+#endif
+
+    //====== Depth tools ========
 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
-    m_acTEncTopList[iViewIdx]->setUseDMM( false );
-#endif
-#if CONSTRAINED_INTRA_PRED
-    m_acTEncTopList[iViewIdx]->setUseConstrainedIntraPred      ( m_bUseConstrainedIntraPred );
-#endif
-#ifdef WEIGHT_PRED
-    //====== Weighted Prediction ========
-    m_acTEncTopList[iViewIdx]->setUseWP                         ( m_bUseWeightPred      );
-    m_acTEncTopList[iViewIdx]->setWPBiPredIdc                   ( m_uiBiPredIdc         );
-#endif
-    //====== Slice ========
-    m_acTEncTopList[iViewIdx]->setSliceMode               ( m_iSliceMode                );
-    m_acTEncTopList[iViewIdx]->setSliceArgument           ( m_iSliceArgument            );
-
-    //====== Entropy Slice ========
-    m_acTEncTopList[iViewIdx]->setEntropySliceMode        ( m_iEntropySliceMode         );
-    m_acTEncTopList[iViewIdx]->setEntropySliceArgument    ( m_iEntropySliceArgument     );
-#if MTK_NONCROSS_INLOOP_FILTER
-    if(m_iSliceMode == 0 )
-    {
-      m_bLFCrossSliceBoundaryFlag = true;
-    }
-    m_acTEncTopList[iViewIdx]->setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag );
-#endif
-#if MTK_SAO
-    m_acTEncTopList[iViewIdx]->setUseSAO               ( m_abUseSAO[0]     );
+    m_acTEncTopList[iViewIdx]->setUseDMM                     ( false );
 #endif
 #if HHI_MPI
     m_acTEncTopList[iViewIdx]->setUseMVI( false );
 #endif
-
-    m_acTEncTopList[iViewIdx]->setPictureDigestEnabled(m_pictureDigestEnabled);
-    m_acTEncTopList[iViewIdx]->setQpChangeFrame( m_iQpChangeFrame );
-    m_acTEncTopList[iViewIdx]->setQpChangeOffsetVideo( m_iQpChangeOffsetVideo );
-    m_acTEncTopList[iViewIdx]->setQpChangeOffsetDepth( m_iQpChangeOffsetDepth );
   }
   if( m_bUsingDepthMaps )
   {
-
-#if HHI_VSO
-    for (Int iViewIdx=0; iViewIdx<m_iNumberOfExternalRefs; iViewIdx++)
-    {
-        m_acTVideoIOYuvERFileList.push_back(new TVideoIOYuv);
-    }
-#endif
-
     for(Int iViewIdx=0; iViewIdx<m_iNumberOfViews; iViewIdx++)
     {
-#if FLEX_CODING_ORDER
-      // Detect whether depth comes before than texture for this view
-      Bool isDepthFirst = false;
-      if ( m_b3DVFlexOrder )
-      {
-        for ( Int ii=1; ii<12; ii+=2 )
-        {
-          Int iViewIdxCfg = (Int)(m_pchMVCJointCodingOrder[ii]-'0');
-          if ( iViewIdxCfg == iViewIdx )
-          {
-            if ( m_pchMVCJointCodingOrder[ii-1]=='D' ) // depth comes first for this view
-            {
-              isDepthFirst = true;
-            }
-            else
-            {
-              assert(m_pchMVCJointCodingOrder[ii-1]=='T');
-            }
-            break;
-          }
-        }
-      }
-#endif
-      m_iDepthFrameRcvdVector.push_back(0) ;
-      m_acTEncDepthTopList.push_back(new TEncTop);
-
+      m_depthFrameRcvd.push_back(0);
+      m_acTEncDepthTopList.push_back(new TEncTop); 
       m_acTVideoIOYuvDepthInputFileList.push_back(new TVideoIOYuv);
-
       m_acTVideoIOYuvDepthReconFileList.push_back(new TVideoIOYuv);
-      m_cListPicYuvDepthRecList.push_back(new TComList<TComPicYuv*>) ;
-      m_aiNextDepthPocToDump.push_back( 0 );
-      m_cListPicYuvDepthRecMap.push_back( std::map<PicOrderCnt,TComPicYuv*>() );
+      m_picYuvDepthRec.push_back(new TComList<TComPicYuv*>) ;
+
       m_acTEncDepthTopList[iViewIdx]->setFrameRate                    ( m_iFrameRate );
       m_acTEncDepthTopList[iViewIdx]->setFrameSkip                    ( m_FrameSkip );
       m_acTEncDepthTopList[iViewIdx]->setSourceWidth                  ( m_iSourceWidth );
       m_acTEncDepthTopList[iViewIdx]->setSourceHeight                 ( m_iSourceHeight );
+#if PIC_CROPPING
+      m_acTEncDepthTopList[iViewIdx]->setCroppingMode                 ( m_croppingMode );
+      m_acTEncDepthTopList[iViewIdx]->setCropLeft                     ( m_cropLeft );
+      m_acTEncDepthTopList[iViewIdx]->setCropRight                    ( m_cropRight );
+      m_acTEncDepthTopList[iViewIdx]->setCropTop                      ( m_cropTop );
+      m_acTEncDepthTopList[iViewIdx]->setCropBottom                   ( m_cropBottom );
+#endif
       m_acTEncDepthTopList[iViewIdx]->setFrameToBeEncoded             ( m_iFrameToBeEncoded );
+      m_acTEncDepthTopList[iViewIdx]->setViewId                       ( iViewIdx );
+      m_acTEncDepthTopList[iViewIdx]->setIsDepth                      ( true );
+      m_acTEncDepthTopList[iViewIdx]->setViewOrderIdx                 ( m_cCameraData.getViewOrderIndex()[ iViewIdx ] );
+      m_acTEncDepthTopList[iViewIdx]->setCamParPrecision              ( 0 );
+      m_acTEncDepthTopList[iViewIdx]->setCamParInSliceHeader          ( false );
+      m_acTEncDepthTopList[iViewIdx]->setCodedScale                   ( 0 );
+      m_acTEncDepthTopList[iViewIdx]->setCodedOffset                  ( 0 );
 
       //====== Coding Structure ========
-#if DCM_DECODING_REFRESH
+      m_acTEncDepthTopList[iViewIdx]->setIntraPeriod                  ( m_iIntraPeriod );
       m_acTEncDepthTopList[iViewIdx]->setDecodingRefreshType          ( m_iDecodingRefreshType );
-#endif
-      m_acTEncDepthTopList[iViewIdx]->setCPSSize                      ( m_uiCodedPictureStoreSize );
       m_acTEncDepthTopList[iViewIdx]->setGOPSize                      ( m_iGOPSize );
-      m_acTEncDepthTopList[iViewIdx]->setRateGOPSize                  ( m_iRateGOPSize );
-
-      m_acTEncDepthTopList[iViewIdx]->setSeqStructure                              ( m_cInputFormatString );
-
+      m_acTEncDepthTopList[iViewIdx]->setGopList                      ( m_GOPListsMvc[iViewIdx] );
+      m_acTEncDepthTopList[iViewIdx]->setExtraRPSs                    ( m_extraRPSs[iViewIdx] );
+#if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER
+      for(Int i = 0; i < MAX_TLAYER; i++)
+      {
+        m_acTEncDepthTopList[iViewIdx]->setNumReorderPics             ( m_numReorderPics[iViewIdx][i], i );
+        m_acTEncDepthTopList[iViewIdx]->setMaxDecPicBuffering         ( m_maxDecPicBuffering[iViewIdx][i], i );
+      }
+#else
+      m_acTEncDepthTopList[iViewIdx]->setNumReorderFrames             ( m_numReorderFrames );
+      m_acTEncDepthTopList[iViewIdx]->setMaxNumberOfReferencePictures ( m_maxNumberOfReferencePictures );
+#endif
+      for( UInt uiLoop = 0; uiLoop < MAX_TLAYER; ++uiLoop )
+      {
+        m_acTEncDepthTopList[iViewIdx]->setLambdaModifier( uiLoop, m_adLambdaModifier[ uiLoop ] );
+      }
       m_acTEncDepthTopList[iViewIdx]->setQP                           ( m_aiQP[1] );
 
@@ -291,13 +394,26 @@
       m_acTEncDepthTopList[iViewIdx]->setPad                          ( m_aiPad );
 
+#if H0566_TLA
+      m_acTEncDepthTopList[iViewIdx]->setMaxTempLayer                 ( m_maxTempLayer[iViewIdx] );
+#else
+      m_acTEncDepthTopList[iViewIdx]->setTLayering                    ( m_bTLayering );
+      m_acTEncDepthTopList[iViewIdx]->setTLayerSwitchingFlag          ( m_abTLayerSwitchingFlag );
+#endif
+
+      m_acTEncDepthTopList[iViewIdx]->setDisInter4x4                  ( m_bDisInter4x4);
+
+      m_acTEncDepthTopList[iViewIdx]->setUseNSQT( m_enableNSQT );
+      m_acTEncDepthTopList[iViewIdx]->setUseAMP( m_enableAMP );
+
       //===== Slice ========
-
-      //====== Entropy Coding ========
-      m_acTEncDepthTopList[iViewIdx]->setSymbolMode                   ( m_iSymbolMode );
 
       //====== Loop/Deblock Filter ========
       m_acTEncDepthTopList[iViewIdx]->setLoopFilterDisable            ( m_abLoopFilterDisable[1]   );
-      m_acTEncDepthTopList[iViewIdx]->setLoopFilterAlphaC0Offset      ( m_iLoopFilterAlphaC0Offset );
-      m_acTEncDepthTopList[iViewIdx]->setLoopFilterBetaOffset         ( m_iLoopFilterBetaOffset    );
+      m_acTEncDepthTopList[iViewIdx]->setLoopFilterOffsetInAPS        ( m_loopFilterOffsetInAPS );
+      m_acTEncDepthTopList[iViewIdx]->setLoopFilterBetaOffset         ( m_loopFilterBetaOffsetDiv2  );
+      m_acTEncDepthTopList[iViewIdx]->setLoopFilterTcOffset           ( m_loopFilterTcOffsetDiv2    );
+#if DBL_CONTROL
+      m_acTEncDepthTopList[iViewIdx]->setDeblockingFilterControlPresent( m_DeblockingFilterControlPresent);
+#endif
 
       //====== Motion search ========
@@ -305,5 +421,18 @@
       m_acTEncDepthTopList[iViewIdx]->setSearchRange                  ( m_iSearchRange );
       m_acTEncDepthTopList[iViewIdx]->setBipredSearchRange            ( m_bipredSearchRange );
+
+      //====== Quality control ========
       m_acTEncDepthTopList[iViewIdx]->setMaxDeltaQP                   ( m_iMaxDeltaQP  );
+      m_acTEncDepthTopList[iViewIdx]->setMaxCuDQPDepth                ( m_iMaxCuDQPDepth  );
+
+      m_acTEncDepthTopList[iViewIdx]->setChromaQpOffset               ( m_iChromaQpOffset     );
+      m_acTEncDepthTopList[iViewIdx]->setChromaQpOffset2nd            ( m_iChromaQpOffset2nd  );
+
+#if ADAPTIVE_QP_SELECTION
+      m_acTEncDepthTopList[iViewIdx]->setUseAdaptQpSelect             ( m_bUseAdaptQpSelect   );
+#endif
+
+      m_acTEncDepthTopList[iViewIdx]->setUseAdaptiveQP                ( m_bUseAdaptiveQP  );
+      m_acTEncDepthTopList[iViewIdx]->setQPAdaptationRange            ( m_iQPAdaptationRange );
 
       //====== Tool list ========
@@ -313,15 +442,17 @@
       m_acTEncDepthTopList[iViewIdx]->setUseHADME                     ( m_bUseHADME    );
       m_acTEncDepthTopList[iViewIdx]->setUseALF                       ( m_abUseALF[1]  );
-#if MQT_ALF_NPASS
       m_acTEncDepthTopList[iViewIdx]->setALFEncodePassReduction       ( m_iALFEncodePassReduction );
-#endif
-#if DCM_COMB_LIST
+#if LOSSLESS_CODING
+      m_acTEncDepthTopList[iViewIdx]->setUseLossless                  ( m_useLossless );
+#endif
+      m_acTEncDepthTopList[iViewIdx]->setALFMaxNumberFilters          ( m_iALFMaxNumberFilters ) ;
+
       m_acTEncDepthTopList[iViewIdx]->setUseLComb                     ( m_bUseLComb    );
-      m_acTEncDepthTopList[iViewIdx]->setLCMod                        ( m_bLCMod         );
-#endif
-      m_acTEncDepthTopList[iViewIdx]->setdQPs                         ( m_aidQP        );
+      m_acTEncDepthTopList[iViewIdx]->setLCMod                        ( m_bLCMod       );
+      m_acTEncDepthTopList[iViewIdx]->setdQPs                         ( m_aidQPdepth   );
       m_acTEncDepthTopList[iViewIdx]->setUseRDOQ                      ( m_abUseRDOQ[1] );
-      m_acTEncDepthTopList[iViewIdx]->setUseLDC                       ( m_bUseLDC      );
+#if !PIC_CROPPING
       m_acTEncDepthTopList[iViewIdx]->setUsePAD                       ( m_bUsePAD      );
+#endif
       m_acTEncDepthTopList[iViewIdx]->setQuadtreeTULog2MaxSize        ( m_uiQuadtreeTULog2MaxSize );
       m_acTEncDepthTopList[iViewIdx]->setQuadtreeTULog2MinSize        ( m_uiQuadtreeTULog2MinSize );
@@ -329,5 +460,21 @@
       m_acTEncDepthTopList[iViewIdx]->setQuadtreeTUMaxDepthIntra      ( m_uiQuadtreeTUMaxDepthIntra );
       m_acTEncDepthTopList[iViewIdx]->setUseFastEnc                   ( m_bUseFastEnc  );
-
+      m_acTEncDepthTopList[iViewIdx]->setUseEarlyCU                   ( m_bUseEarlyCU  ); 
+#if FAST_DECISION_FOR_MRG_RD_COST
+      m_acTEncDepthTopList[iViewIdx]->setUseFastDecisionForMerge      ( m_useFastDecisionForMerge  );
+#endif
+      m_acTEncDepthTopList[iViewIdx]->setUseCbfFastMode               ( m_bUseCbfFastMode  );
+#if HHI_INTERVIEW_SKIP
+      m_acTEncDepthTopList[iViewIdx]->setInterViewSkip            ( 0 );
+#if HHI_INTERVIEW_SKIP_LAMBDA_SCALE
+      m_acTEncDepthTopList[iViewIdx]->setInterViewSkipLambdaScale ( 1 );
+#endif
+#endif
+      m_acTEncDepthTopList[iViewIdx]->setUseLMChroma                  ( m_bUseLMChroma );
+      m_acTEncDepthTopList[iViewIdx]->setUseConstrainedIntraPred      ( m_bUseConstrainedIntraPred );
+      m_acTEncDepthTopList[iViewIdx]->setPCMLog2MinSize               ( m_uiPCMLog2MinSize);
+      m_acTEncDepthTopList[iViewIdx]->setUsePCM                       ( m_usePCM );
+      m_acTEncDepthTopList[iViewIdx]->setPCMLog2MaxSize               ( m_pcmLog2MaxSize);
+      //====== VSO ========
 #if HHI_VSO
       m_acTEncDepthTopList[iViewIdx]->setUseVSO                       ( m_bUseVSO      ); //GT: might be enabled/disabled later for VSO Mode 4
@@ -340,14 +487,4 @@
 #endif
 
-#if BITSTREAM_EXTRACTION
-      m_acTEncDepthTopList[iViewIdx]->setLayerId                      ( ( ( (UInt)iViewIdx ) << 1 ) + 1 );
-#endif
-      m_acTEncDepthTopList[iViewIdx]->setViewId                       ( (UInt)iViewIdx );
-      m_acTEncDepthTopList[iViewIdx]->setViewOrderIdx                 ( m_cCameraData.getViewOrderIndex()[ iViewIdx ] );
-      m_acTEncDepthTopList[iViewIdx]->setIsDepth                      ( true );
-      m_acTEncDepthTopList[iViewIdx]->setCamParPrecision              ( 0 );
-      m_acTEncDepthTopList[iViewIdx]->setCamParInSliceHeader          ( false );
-      m_acTEncDepthTopList[iViewIdx]->setCodedScale                   ( 0 );
-      m_acTEncDepthTopList[iViewIdx]->setCodedOffset                  ( 0 );
 #if DEPTH_MAP_GENERATION
       m_acTEncDepthTopList[iViewIdx]->setPredDepthMapGeneration       ( 0 );
@@ -362,68 +499,106 @@
 #endif
 
-#if HHI_INTERVIEW_SKIP
-      m_acTEncDepthTopList[iViewIdx]->setInterViewSkip            ( 0 );
-#if HHI_INTERVIEW_SKIP_LAMBDA_SCALE
-      m_acTEncDepthTopList[iViewIdx]->setInterViewSkipLambdaScale ( 1 );
-#endif
-#endif
-      m_acTEncDepthTopList[iViewIdx]->setUseMRG                       ( m_bUseMRG      ); // SOPH:
-
-#if LM_CHROMA
-      m_acTEncDepthTopList[iViewIdx]->setUseLMChroma                  ( m_bUseLMChroma );
-#endif
-
-#if HHI_RMP_SWITCH
-      m_acTEncDepthTopList[iViewIdx]->setUseRMP                     ( m_bUseRMP );
-#endif
-#ifdef ROUNDING_CONTROL_BIPRED
-      m_acTEncDepthTopList[iViewIdx]->setUseRoundingControlBipred(m_useRoundingControlBipred);
-#endif
+      //====== Weighted Prediction ========
+      m_acTEncDepthTopList[iViewIdx]->setUseWP                        ( m_bUseWeightPred      );
+      m_acTEncDepthTopList[iViewIdx]->setWPBiPredIdc                  ( m_uiBiPredIdc         );
+      //====== Slice ========
+      m_acTEncDepthTopList[iViewIdx]->setSliceMode                    ( m_iSliceMode                );
+      m_acTEncDepthTopList[iViewIdx]->setSliceArgument                ( m_iSliceArgument            );
+
+      //====== Entropy Slice ========
+      m_acTEncDepthTopList[iViewIdx]->setEntropySliceMode             ( m_iEntropySliceMode         );
+      m_acTEncDepthTopList[iViewIdx]->setEntropySliceArgument         ( m_iEntropySliceArgument     );
+      int iNumPartInCU = 1<<(m_uiMaxCUDepth<<1);
+      if(m_iEntropySliceMode==SHARP_FIXED_NUMBER_OF_LCU_IN_ENTROPY_SLICE)
+      {
+        m_acTEncDepthTopList[iViewIdx]->setEntropySliceArgument ( m_iEntropySliceArgument * ( iNumPartInCU >> ( m_iSliceGranularity << 1 ) ) );
+      }
+      if(m_iSliceMode==AD_HOC_SLICES_FIXED_NUMBER_OF_LCU_IN_SLICE)
+      {
+        m_acTEncDepthTopList[iViewIdx]->setSliceArgument ( m_iSliceArgument * ( iNumPartInCU >> ( m_iSliceGranularity << 1 ) ) );
+      }
+#if FIXED_NUMBER_OF_TILES_SLICE_MODE
+      if(m_iSliceMode==AD_HOC_SLICES_FIXED_NUMBER_OF_TILES_IN_SLICE)
+      {
+        m_acTEncDepthTopList[iViewIdx]->setSliceArgument ( m_iSliceArgument );
+      }
+#endif
+      m_acTEncDepthTopList[iViewIdx]->setSliceGranularity        ( m_iSliceGranularity         );
+      if(m_iSliceMode == 0 )
+      {
+        m_bLFCrossSliceBoundaryFlag = true;
+      }
+      m_acTEncDepthTopList[iViewIdx]->setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag );
+      m_acTEncDepthTopList[iViewIdx]->setUseSAO               ( m_abUseSAO[1]     );
+#if SAO_UNIT_INTERLEAVING
+      m_acTEncDepthTopList[iViewIdx]->setMaxNumOffsetsPerPic (m_maxNumOffsetsPerPic);
+      m_acTEncDepthTopList[iViewIdx]->setSaoInterleavingFlag (m_saoInterleavingFlag);
+#endif
+      m_acTEncDepthTopList[iViewIdx]->setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag); 
+      m_acTEncDepthTopList[iViewIdx]->setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag); 
+
+      m_acTEncDepthTopList[iViewIdx]->setPictureDigestEnabled(m_pictureDigestEnabled);
+
+      m_acTEncDepthTopList[iViewIdx]->setColumnRowInfoPresent       ( m_iColumnRowInfoPresent );
+      m_acTEncDepthTopList[iViewIdx]->setUniformSpacingIdr          ( m_iUniformSpacingIdr );
+#if !REMOVE_TILE_DEPENDENCE
+      m_acTEncDepthTopList[iViewIdx]->setTileBoundaryIndependenceIdr( m_iTileBoundaryIndependenceIdr );
+#endif
+      m_acTEncDepthTopList[iViewIdx]->setNumColumnsMinus1           ( m_iNumColumnsMinus1 );
+      m_acTEncDepthTopList[iViewIdx]->setNumRowsMinus1              ( m_iNumRowsMinus1 );
+      if(m_iUniformSpacingIdr==0)
+      {
+        m_acTEncDepthTopList[iViewIdx]->setColumnWidth              ( m_pchColumnWidth );
+        m_acTEncDepthTopList[iViewIdx]->setRowHeight                ( m_pchRowHeight );
+      }
+      m_acTEncDepthTopList[iViewIdx]->xCheckGSParameters();
+      m_acTEncDepthTopList[iViewIdx]->setTileLocationInSliceHeaderFlag ( m_iTileLocationInSliceHeaderFlag );
+      m_acTEncDepthTopList[iViewIdx]->setTileMarkerFlag              ( m_iTileMarkerFlag );
+      m_acTEncDepthTopList[iViewIdx]->setMaxTileMarkerEntryPoints    ( m_iMaxTileMarkerEntryPoints );
+
+      Int uiTilesCount          = (m_iNumRowsMinus1+1) * (m_iNumColumnsMinus1+1);
+      m_dMaxTileMarkerOffset    = ((Double)uiTilesCount) / m_iMaxTileMarkerEntryPoints;
+      m_acTEncDepthTopList[iViewIdx]->setMaxTileMarkerOffset         ( m_dMaxTileMarkerOffset );
+      m_acTEncDepthTopList[iViewIdx]->setTileBehaviorControlPresentFlag( m_iTileBehaviorControlPresentFlag );
+#if !REMOVE_TILE_DEPENDENCE
+      if(m_iTileBoundaryIndependenceIdr == 0 || uiTilesCount == 1)
+#else
+      if(uiTilesCount == 1)
+#endif
+      {
+        m_bLFCrossTileBoundaryFlag = true; 
+      }
+      m_acTEncDepthTopList[iViewIdx]->setLFCrossTileBoundaryFlag( m_bLFCrossTileBoundaryFlag );
+      m_acTEncDepthTopList[iViewIdx]->setWaveFrontSynchro           ( m_iWaveFrontSynchro );
+      m_acTEncDepthTopList[iViewIdx]->setWaveFrontFlush             ( m_iWaveFrontFlush );
+      m_acTEncDepthTopList[iViewIdx]->setWaveFrontSubstreams        ( m_iWaveFrontSubstreams );
+      m_acTEncDepthTopList[iViewIdx]->setEnableTMVP ( m_enableTMVP );
+      m_acTEncDepthTopList[iViewIdx]->setUseScalingListId           ( m_useScalingListId  );
+      m_acTEncDepthTopList[iViewIdx]->setScalingListFile            ( m_scalingListFile   );
+#if MULTIBITS_DATA_HIDING
+      m_acTEncDepthTopList[iViewIdx]->setSignHideFlag(m_signHideFlag);
+      m_acTEncDepthTopList[iViewIdx]->setTSIG(m_signHidingThreshold);
+#endif
+
+#if LCU_SYNTAX_ALF
+      if(uiTilesCount > 1)
+      {
+        m_bALFParamInSlice = false;
+        m_bALFPicBasedEncode = true;
+      }
+      m_acTEncDepthTopList[iViewIdx]->setALFParamInSlice              ( m_bALFParamInSlice);
+      m_acTEncDepthTopList[iViewIdx]->setALFPicBasedEncode            ( m_bALFPicBasedEncode);
+#endif
+
+  //====== Depth tools ========
 #if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
-      m_acTEncDepthTopList[iViewIdx]->setUseDMM( m_bUseDMM );
-#endif
-#if FLEX_CODING_ORDER && HHI_DMM_PRED_TEX
-      m_acTEncDepthTopList[iViewIdx]->setUseDMM34( (m_b3DVFlexOrder && isDepthFirst) ? false : m_bUseDMM );
-#endif
-#if CONSTRAINED_INTRA_PRED
-      m_acTEncDepthTopList[iViewIdx]->setUseConstrainedIntraPred      ( m_bUseConstrainedIntraPred );
-#endif
-#ifdef WEIGHT_PRED
-    //====== Weighted Prediction ========
-      m_acTEncDepthTopList[iViewIdx]->setUseWP                         ( m_bUseWeightPred      );
-      m_acTEncDepthTopList[iViewIdx]->setWPBiPredIdc                   ( m_uiBiPredIdc         );
-#endif
-      //====== Slice ========
-      m_acTEncDepthTopList[iViewIdx]->setSliceMode               ( m_iSliceMode                );
-      m_acTEncDepthTopList[iViewIdx]->setSliceArgument           ( m_iSliceArgument            );
-
-      //====== Entropy Slice ========
-      m_acTEncDepthTopList[iViewIdx]->setEntropySliceMode        ( m_iEntropySliceMode         );
-      m_acTEncDepthTopList[iViewIdx]->setEntropySliceArgument    ( m_iEntropySliceArgument     );
-#if MTK_NONCROSS_INLOOP_FILTER
-      if(m_iSliceMode == 0 )
-      {
-        m_bLFCrossSliceBoundaryFlag = true;
-      }
-      m_acTEncDepthTopList[iViewIdx]->setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag );
-#endif
-#if MTK_SAO
-      m_acTEncDepthTopList[iViewIdx]->setUseSAO               ( m_abUseSAO[1]     );
+    m_acTEncDepthTopList[iViewIdx]->setUseDMM                     ( m_bUseDMM );
 #endif
 #if HHI_MPI
-#if FLEX_CODING_ORDER
-      m_acTEncDepthTopList[iViewIdx]->setUseMVI( (m_b3DVFlexOrder && isDepthFirst) ? false : m_bUseMVI );
-#else
-      m_acTEncDepthTopList[iViewIdx]->setUseMVI( m_bUseMVI );
-#endif
-#endif
-      
-      m_acTEncDepthTopList[iViewIdx]->setPictureDigestEnabled(m_pictureDigestEnabled);
-
-      m_acTEncDepthTopList[iViewIdx]->setQpChangeFrame( m_iQpChangeFrame );
-      m_acTEncDepthTopList[iViewIdx]->setQpChangeOffsetVideo( m_iQpChangeOffsetVideo );
-      m_acTEncDepthTopList[iViewIdx]->setQpChangeOffsetDepth( m_iQpChangeOffsetDepth );
-    }
-  }
+     m_acTEncDepthTopList[iViewIdx]->setUseMVI( m_bUseMVI );
+#endif
+    }
+  }
+
 #if HHI_INTER_VIEW_MOTION_PRED
   else if( m_uiMultiviewMvRegMode )
@@ -466,5 +641,5 @@
     else
     {
-      m_cRendererTop.init(m_iSourceWidth, m_iSourceHeight,true,0,0,true, 0,0,0,0,0,0,0,1,0,0 );  //GT: simplest configuration
+      AOT(true);
     }
   }
@@ -474,78 +649,59 @@
   m_cUsedPelsRenderer.init(m_iSourceWidth, m_iSourceHeight, true, 0, LOG2_DISP_PREC_LUT, true, 0, 0, 0, 0, 0, 6, 4, 1, 0, 6 );
 #endif
+
 }
 
 Void TAppEncTop::xCreateLib()
 {
-  // Video I/O
-  m_cTVideoIOBitsFile.openBits( m_pchBitstreamFile, true  );  // write mode
-
   for(Int iViewIdx=0; iViewIdx<m_iNumberOfViews; iViewIdx++)
   {
     m_acTVideoIOYuvInputFileList[iViewIdx]->open( m_pchInputFileList[iViewIdx],     false, m_uiInputBitDepth, m_uiInternalBitDepth );  // read  mode
-    m_acTVideoIOYuvInputFileList[iViewIdx]->skipFrames(m_FrameSkip, m_iSourceWidth, m_iSourceHeight);
-    m_acTVideoIOYuvReconFileList[iViewIdx]->open( m_pchReconFileList[iViewIdx],     true, m_uiOutputBitDepth, m_uiInternalBitDepth);  // write mode
-
-    // Neo Decoder
+    m_acTVideoIOYuvInputFileList[iViewIdx]->skipFrames(m_FrameSkip, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1]);
+
+    if (m_pchReconFileList[iViewIdx])
+      m_acTVideoIOYuvReconFileList[iViewIdx]->open(m_pchReconFileList[iViewIdx], true, m_uiOutputBitDepth, m_uiInternalBitDepth);  // write mode
     m_acTEncTopList[iViewIdx]->create();
-
     if( m_bUsingDepthMaps )
+    {
+      m_acTVideoIOYuvDepthInputFileList[iViewIdx]->open( m_pchDepthInputFileList[iViewIdx],     false, m_uiInputBitDepth, m_uiInternalBitDepth );  // read  mode
+      m_acTVideoIOYuvDepthInputFileList[iViewIdx]->skipFrames(m_FrameSkip, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1]);
+
+      if (m_pchDepthReconFileList[iViewIdx])
+        m_acTVideoIOYuvDepthReconFileList[iViewIdx]->open(m_pchDepthReconFileList[iViewIdx], true, m_uiOutputBitDepth, m_uiInternalBitDepth);  // write mode
+      m_acTEncDepthTopList[iViewIdx]->create();
+    }
+#if HHI_INTER_VIEW_MOTION_PRED
+    else if( m_uiMultiviewMvRegMode )
     {
       m_acTVideoIOYuvDepthInputFileList[iViewIdx]->open( m_pchDepthInputFileList[iViewIdx],     false, m_uiInputBitDepth, m_uiInternalBitDepth );  // read  mode
       m_acTVideoIOYuvDepthInputFileList[iViewIdx]->skipFrames(m_FrameSkip, m_iSourceWidth, m_iSourceHeight);
-
-      m_acTVideoIOYuvDepthReconFileList[iViewIdx]->open( m_pchDepthReconFileList[iViewIdx],     true, m_uiOutputBitDepth, m_uiInternalBitDepth);  // write mode
-
-      // Neo Decoder
-      m_acTEncDepthTopList[iViewIdx]->create();
-    }
-#if HHI_INTER_VIEW_MOTION_PRED
-    else if( m_uiMultiviewMvRegMode )
-    {
-      m_acTVideoIOYuvDepthInputFileList[iViewIdx]->open( m_pchDepthInputFileList[iViewIdx],     false, m_uiInputBitDepth, m_uiInternalBitDepth );  // read  mode
-      m_acTVideoIOYuvDepthInputFileList[iViewIdx]->skipFrames(m_FrameSkip, m_iSourceWidth, m_iSourceHeight);
-    }
-#endif
-  }
-
-#if HHI_VSO
-  for(Int iViewIdx=0; iViewIdx < m_iNumberOfExternalRefs; iViewIdx++)
-  {
-    m_acTVideoIOYuvERFileList[iViewIdx]->open( m_pchERRefFileList[iViewIdx], false, m_uiInputBitDepth, m_uiInternalBitDepth ); // read mode
-  }
-#endif
+    }
+#endif
+  }
 }
 
 Void TAppEncTop::xDestroyLib()
 {
-
-  m_cTVideoIOBitsFile.closeBits();
-
-#if HHI_VSO
-  for ( Int iViewIdx = 0; iViewIdx < m_iNumberOfExternalRefs; iViewIdx++ )
-  {
-    m_acTVideoIOYuvERFileList[iViewIdx]->close();
-    delete m_acTVideoIOYuvERFileList[iViewIdx];
-    m_acTVideoIOYuvERFileList[iViewIdx] = 0;
-  };
-#endif
-
+  // Video I/O
   for(Int iViewIdx=0; iViewIdx<m_iNumberOfViews; iViewIdx++)
   {
     m_acTVideoIOYuvInputFileList[iViewIdx]->close();
     m_acTVideoIOYuvReconFileList[iViewIdx]->close();
-
-    delete m_acTVideoIOYuvInputFileList[iViewIdx] ; m_acTVideoIOYuvInputFileList[iViewIdx] = NULL;
-    delete m_acTVideoIOYuvReconFileList[iViewIdx] ; m_acTVideoIOYuvReconFileList[iViewIdx] = NULL;
-
-    delete m_cListPicYuvRecList[iViewIdx] ; m_cListPicYuvRecList[iViewIdx] = NULL;
-
+    delete m_acTVideoIOYuvInputFileList[iViewIdx] ; 
+    m_acTVideoIOYuvInputFileList[iViewIdx] = NULL;
+    delete m_acTVideoIOYuvReconFileList[iViewIdx] ; 
+    m_acTVideoIOYuvReconFileList[iViewIdx] = NULL;
+    m_acTEncTopList[iViewIdx]->deletePicBuffer();
     m_acTEncTopList[iViewIdx]->destroy();
-    delete m_acTEncTopList[iViewIdx] ; m_acTEncTopList[iViewIdx] = NULL;
+    delete m_acTEncTopList[iViewIdx] ; 
+    m_acTEncTopList[iViewIdx] = NULL;
+    delete m_picYuvRec[iViewIdx] ; 
+    m_picYuvRec[iViewIdx] = NULL;
 
     if( iViewIdx < Int( m_acTVideoIOYuvDepthInputFileList.size() ) && m_acTVideoIOYuvDepthInputFileList[iViewIdx] )
     {
       m_acTVideoIOYuvDepthInputFileList[iViewIdx]->close( );
-      delete m_acTVideoIOYuvDepthInputFileList[iViewIdx] ;
+      delete m_acTVideoIOYuvDepthInputFileList[iViewIdx];
+      m_acTVideoIOYuvDepthInputFileList[iViewIdx] = NULL;
     }
     if( iViewIdx < Int( m_acTVideoIOYuvDepthReconFileList.size() ) && m_acTVideoIOYuvDepthReconFileList[iViewIdx] )
@@ -553,13 +709,17 @@
       m_acTVideoIOYuvDepthReconFileList[iViewIdx]->close () ;
       delete m_acTVideoIOYuvDepthReconFileList[iViewIdx];
+      m_acTVideoIOYuvDepthReconFileList[iViewIdx] = NULL;
     }
     if( iViewIdx < Int( m_acTEncDepthTopList.size() ) && m_acTEncDepthTopList[iViewIdx] )
     {
+      m_acTEncDepthTopList[iViewIdx]->deletePicBuffer();
       m_acTEncDepthTopList[iViewIdx]->destroy();
       delete m_acTEncDepthTopList[iViewIdx];
-    }
-    if( iViewIdx < Int( m_cListPicYuvDepthRecList.size() ) && m_cListPicYuvDepthRecList[iViewIdx] )
-    {
-      delete m_cListPicYuvDepthRecList[iViewIdx ];
+      m_acTEncDepthTopList[iViewIdx] = NULL;
+    }
+    if( iViewIdx < Int( m_picYuvDepthRec.size() ) && m_picYuvDepthRec[iViewIdx] )
+    {
+      delete m_picYuvDepthRec[iViewIdx] ; 
+      m_picYuvDepthRec[iViewIdx] = NULL;
     }
   }
@@ -601,46 +761,44 @@
  .
  */
-//GT PRE LOAD ENC BUFFER
 Void TAppEncTop::encode()
 {
-  TComPicYuv*       pcPicYuvOrg      = new TComPicYuv;
+  fstream bitstreamFile(m_pchBitstreamFile, fstream::binary | fstream::out);
+  if (!bitstreamFile)
+  {
+    fprintf(stderr, "\nfailed to open bitstream file `%s' for writing\n", m_pchBitstreamFile);
+    exit(EXIT_FAILURE);
+  }
+
+  TComPicYuv*       pcPicYuvOrg = new TComPicYuv;
   TComPicYuv*       pcDepthPicYuvOrg = new TComPicYuv;
   TComPicYuv*       pcPdmDepthOrg    = new TComPicYuv;
-  TComPicYuv*       pcPicYuvRec      = NULL;
-  //TComPicYuv*       pcDepthPicYuvRec = NULL;
-
+  TComPicYuv*       pcPicYuvRec = NULL;
+  TComPicYuv*       pcDepthPicYuvRec = NULL;
+  
   // initialize internal class & member variables
   xInitLibCfg();
   xCreateLib();
   xInitLib();
-
+  
   // main encoder loop
-
-  //GT: setup and init Bools for Eos and Continue Reading
-  Bool  bAllEos = false;
-  Bool  bAllContinueReadingPics = false;
-  std::vector<Bool>  bEos ;
-  std::vector<Bool>  bContinueReadingPics ;
-
-  Bool  bAllDepthEos = false;
-  Bool  bAllContinueReadingDepthPics = false;
-  std::vector<Bool>  bDepthEos ;
-  std::vector<Bool>  bContinueReadingDepthPics ;
+  Bool  allEos = false;
+  std::vector<Bool>  eos ;
+  std::vector<Bool>  depthEos ;
+  Int maxGopSize = 0;
+  Int gopSize = 1;
+  
+  list<AccessUnit> outputAccessUnits; ///< list of access units to write out.  is populated by the encoding process
+  maxGopSize = (std::max)(maxGopSize, m_acTEncTopList[0]->getGOPSize());   
+
   for(Int iViewIdx=0; iViewIdx < m_iNumberOfViews; iViewIdx++ )
   {
-    bEos.push_back( false ) ;
-    bContinueReadingPics.push_back( true );
-    if( m_bUsingDepthMaps)
-    {
-      bDepthEos.push_back( false ) ;
-      bContinueReadingDepthPics.push_back( true ) ;
-    }
-  }
+    eos.push_back( false );
+    depthEos.push_back( false );
+  }
+
   // allocate original YUV buffer
   pcPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
-  if( m_bUsingDepthMaps)
-  {
-    pcDepthPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
-  }
+  pcDepthPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
+
 #if HHI_INTER_VIEW_MOTION_PRED
   if( m_uiMultiviewMvRegMode )
@@ -650,25 +808,17 @@
 #endif
 
-  TComBitstream*    pcBitstream = new TComBitstream;
-  pcBitstream->create( (m_iSourceWidth * m_iSourceHeight * 3) >> 1 ) ; //GT: is size reasonable ??
-
-  while ( !(bAllEos&& bAllContinueReadingPics) )
-  {
-    bAllContinueReadingPics = false;
-    bAllContinueReadingDepthPics = false;
-
-    //GT: Read all Buffers
-    for(Int iViewIdx=0; iViewIdx < m_iNumberOfViews; iViewIdx++ ) //GT; store frames first
-    {
-      if (!bEos[iViewIdx] && bContinueReadingPics[iViewIdx] ) //GT: read frames to buffer
+  while ( !allEos )
+  {
+    for(Int iViewIdx=0; iViewIdx < m_iNumberOfViews; iViewIdx++ )
+    {
+      Int frmCnt = 0;
+      while ( !eos[iViewIdx] && !(frmCnt == gopSize))
       {
         // get buffers
-        xGetBuffer( pcPicYuvRec, iViewIdx, m_cListPicYuvRecList ); // ringbuffer of size gopsize -> m_cListPicYuvRec, m_cListBitstream
+        xGetBuffer(pcPicYuvRec, iViewIdx, false);
+
         // read input YUV file
-        m_acTVideoIOYuvInputFileList[iViewIdx]->read( pcPicYuvOrg, m_aiPad  ) ;
-        bEos[iViewIdx] = ( m_acTVideoIOYuvInputFileList[iViewIdx]->isEof() == 1 ?   true : false  );             //GT: End of File
-        bEos[iViewIdx] = ( m_iFrameRcvdVector[iViewIdx] == (m_iFrameToBeEncoded - 1) ?    true : bEos[iViewIdx]   );   //GT: FramesToBeEncoded Reached
-        bAllEos = bAllEos|bEos[iViewIdx] ;
-
+        m_acTVideoIOYuvInputFileList[iViewIdx]->read( pcPicYuvOrg, m_aiPad );
+      
 #if HHI_INTER_VIEW_MOTION_PRED
         if( m_uiMultiviewMvRegMode && iViewIdx )
@@ -678,227 +828,104 @@
 #endif
 
+#if HHI_INTER_VIEW_MOTION_PRED
+        m_acTEncTopList[iViewIdx]->initNewPic( pcPicYuvOrg, ( m_uiMultiviewMvRegMode && iViewIdx ? pcPdmDepthOrg : 0 ) );
+#else
+        m_acTEncTopList[iViewIdx]->initNewPic( pcPicYuvOrg );
+#endif
+
         // increase number of received frames
-        m_iFrameRcvdVector[iViewIdx]++ ;
-      }
-
-#if HHI_INTER_VIEW_MOTION_PRED
-      m_acTEncTopList[iViewIdx]->receivePic( bEos[iViewIdx],  pcPicYuvOrg, m_cListPicYuvRecList[iViewIdx]->back(), ( m_uiMultiviewMvRegMode && iViewIdx ? pcPdmDepthOrg : 0 ) );
-#else
-      m_acTEncTopList[iViewIdx]->receivePic( bEos[iViewIdx],  pcPicYuvOrg, m_cListPicYuvRecList[iViewIdx]->back(), 0 );
-#endif
-
+        m_frameRcvd[iViewIdx]++;
+        frmCnt++;
+        // check end of file
+        eos[iViewIdx] = ( m_acTVideoIOYuvInputFileList[iViewIdx]->isEof() == 1 ?   true : false  );
+        eos[iViewIdx] = ( m_frameRcvd[iViewIdx] == m_iFrameToBeEncoded ?    true : eos[iViewIdx]   );
+        allEos = allEos|eos[iViewIdx] ; 
+      }
       if( m_bUsingDepthMaps )
       {
-        if (!bDepthEos[iViewIdx] && bContinueReadingDepthPics[iViewIdx] )
+        Int frmCntDepth = 0;
+        while ( !depthEos[iViewIdx] && !(frmCntDepth == gopSize))
         {
           // get buffers
-          xGetBuffer( pcPicYuvRec, iViewIdx, m_cListPicYuvDepthRecList ); // ringbuffer of size gopsize -> m_cListPicYuvRec, m_cListBitstream
+          xGetBuffer(pcDepthPicYuvRec, iViewIdx, true);
+
           // read input YUV file
-          m_acTVideoIOYuvDepthInputFileList[iViewIdx]->read( pcDepthPicYuvOrg, m_aiPad  ) ;
-          bDepthEos[iViewIdx] = ( m_acTVideoIOYuvDepthInputFileList[iViewIdx]->isEof() == 1 ?   true : false  );
-          bDepthEos[iViewIdx] = ( m_iDepthFrameRcvdVector[iViewIdx] == (m_iFrameToBeEncoded - 1) ?    true : bDepthEos[iViewIdx]   );
-          bAllDepthEos = bAllDepthEos|bDepthEos[iViewIdx] ;
+          m_acTVideoIOYuvDepthInputFileList[iViewIdx]->read( pcDepthPicYuvOrg, m_aiPad );
+
+          m_acTEncDepthTopList[iViewIdx]->initNewPic( pcDepthPicYuvOrg );
+
           // increase number of received frames
-          m_iDepthFrameRcvdVector[iViewIdx]++ ;
+          m_depthFrameRcvd[iViewIdx]++;
+          frmCntDepth++;
+          // check end of file
+          depthEos[iViewIdx] = ( m_acTVideoIOYuvDepthInputFileList[iViewIdx]->isEof() == 1 ?   true : false  );
+          depthEos[iViewIdx] = ( m_depthFrameRcvd[iViewIdx] == m_iFrameToBeEncoded ?    true : depthEos[iViewIdx]   );
+          allEos = allEos|depthEos[iViewIdx] ; 
         }
-        m_acTEncDepthTopList[iViewIdx]->receivePic( bDepthEos[iViewIdx],  pcDepthPicYuvOrg, m_cListPicYuvDepthRecList[iViewIdx]->back() );
-      }
-    }
-
-    //===== store current POC =====
-    Bool  bCurrPocCoded = m_acTEncTopList[ 0 ]->currentPocWillBeCoded();
-    Int   iCurrPoc      = m_acTEncTopList[ 0 ]->getNextFrameId();
-
-    //===== update camera parameters =====
-    if( bCurrPocCoded )
-    {
-      m_cCameraData.update( (UInt)iCurrPoc );
-    }
-
-#if HHI_VSO    
-    if ( m_bUseVSO && ( m_uiVSOMode != 4) )
-    {
-      //GT: Read external reference pics or render references
-      xStoreVSORefPicsInBuffer();       //GT;
-    }
-#endif
-
-#if FLEX_CODING_ORDER
-    if (m_b3DVFlexOrder)
-    {
-      Int i=0;
-      Int iViewIdx = 0;
-      bool bThisViewContinueReadingPics = false;
-      bool bThisViewContinueReadingDepthPics = false;
-      Int iNumberofDepthViews = m_bUsingDepthMaps?m_iNumberOfViews:0;
-      for(Int j=0; j < (m_iNumberOfViews+ iNumberofDepthViews); j++ )     // Start encoding
-      {
-        if (m_pchMVCJointCodingOrder[i]=='T')
+      }
+    }
+    for ( Int gopId=0; gopId < gopSize; gopId++ )
+    {
+      Int  iNumEncoded = 0;
+      UInt iNextPoc = m_acTEncTopList[0] -> getFrameId( gopId );
+      if ( iNextPoc < m_iFrameToBeEncoded )
+      {
+      m_cCameraData.update( iNextPoc );
+      }
+      for(Int iViewIdx=0; iViewIdx < m_iNumberOfViews; iViewIdx++ )
+      {
+        iNumEncoded = 0;
+        // call encoding function for one frame
+        m_acTEncTopList[iViewIdx]->encode( eos[iViewIdx], pcPicYuvOrg, *m_picYuvRec[iViewIdx], outputAccessUnits, iNumEncoded, gopId );
+        xWriteOutput(bitstreamFile, iNumEncoded, outputAccessUnits, iViewIdx, false);
+        outputAccessUnits.clear();
+        if( m_bUsingDepthMaps )
         {
-          i++;
-          assert(isdigit(m_pchMVCJointCodingOrder[i]));
-          iViewIdx = (Int)(m_pchMVCJointCodingOrder[i]-'0');
-          bThisViewContinueReadingPics = bContinueReadingPics[iViewIdx];
-          m_acTEncTopList[iViewIdx]->encode( bEos[iViewIdx], m_cListPicYuvRecMap[iViewIdx], pcBitstream, bThisViewContinueReadingPics );
-          bContinueReadingPics[iViewIdx]=bThisViewContinueReadingPics;
-          bAllContinueReadingPics = bAllContinueReadingPics||bContinueReadingPics[iViewIdx];
-
-          if(pcBitstream->getNumberOfWrittenBits()!=0)
-          {
-            m_cTVideoIOBitsFile.writeBits( pcBitstream );
-          }
-          pcBitstream->resetBits(); //GT: also done later in ....
-          pcBitstream->rewindStreamPacket( );
-          // write bistream to file if necessary
-          xWriteOutput( iViewIdx ); //GT: Write Reconfiles (when gop is complete?)
-          i++;
+          Int  iNumDepthEncoded = 0;
+          // call encoding function for one depth frame
+          m_acTEncDepthTopList[iViewIdx]->encode( depthEos[iViewIdx], pcDepthPicYuvOrg, *m_picYuvDepthRec[iViewIdx], outputAccessUnits, iNumDepthEncoded, gopId );
+          xWriteOutput(bitstreamFile, iNumDepthEncoded, outputAccessUnits, iViewIdx, true);
+          outputAccessUnits.clear();
         }
-        else if ( m_pchMVCJointCodingOrder[i] == 'D')
-        {
-          i++;
-          if( m_bUsingDepthMaps )
-          {
-            assert(isdigit(m_pchMVCJointCodingOrder[i]));
-            iViewIdx = (Int)(m_pchMVCJointCodingOrder[i]-'0');
-            bThisViewContinueReadingDepthPics = bContinueReadingDepthPics[iViewIdx];
-            m_acTEncDepthTopList[iViewIdx]->encode( bDepthEos[iViewIdx], m_cListPicYuvDepthRecMap[iViewIdx], pcBitstream, bThisViewContinueReadingDepthPics );
-            bContinueReadingDepthPics[iViewIdx]=bThisViewContinueReadingDepthPics;
-
-            bAllContinueReadingDepthPics = bAllContinueReadingDepthPics||bContinueReadingDepthPics[iViewIdx];
-            if(pcBitstream->getNumberOfWrittenBits()!=0)
-            {
-              m_cTVideoIOBitsFile.writeBits( pcBitstream );
-            }
-            pcBitstream->resetBits();
-            pcBitstream->rewindStreamPacket( );
-            // write bistream to file if necessary
-            xWriteOutput( iViewIdx, true );
-            i++;
-          }
-        }
-      }
-    }
-    else
-    {
-#endif
-    //GT: Encode
-    for(Int iViewIdx=0; iViewIdx < m_iNumberOfViews; iViewIdx++ )     // Start encoding
-    {
-      bool bThisViewContinueReadingPics = bContinueReadingPics[iViewIdx];
-      m_acTEncTopList[iViewIdx]->encode( bEos[iViewIdx], m_cListPicYuvRecMap[iViewIdx], pcBitstream, bThisViewContinueReadingPics );
-      bContinueReadingPics[iViewIdx]=bThisViewContinueReadingPics;
-      bAllContinueReadingPics = bAllContinueReadingPics||bContinueReadingPics[iViewIdx];
-
-      if(pcBitstream->getNumberOfWrittenBits()!=0)
-      {
-        m_cTVideoIOBitsFile.writeBits( pcBitstream );
-      }
-      pcBitstream->resetBits(); //GT: also done later in ....
-      pcBitstream->rewindStreamPacket( );
-      // write bistream to file if necessary
-      xWriteOutput( iViewIdx ); //GT: Write Reconfiles (when gop is complete?)
-
-      if( m_bUsingDepthMaps )
-      {
-        bool bThisViewContinueReadingDepthPics = bContinueReadingDepthPics[iViewIdx];
-        m_acTEncDepthTopList[iViewIdx]->encode( bDepthEos[iViewIdx], m_cListPicYuvDepthRecMap[iViewIdx], pcBitstream, bThisViewContinueReadingDepthPics );
-        bContinueReadingDepthPics[iViewIdx]=bThisViewContinueReadingDepthPics;
-
-        bAllContinueReadingDepthPics = bAllContinueReadingDepthPics||bContinueReadingDepthPics[iViewIdx];
-        if(pcBitstream->getNumberOfWrittenBits()!=0)
-        {
-          m_cTVideoIOBitsFile.writeBits( pcBitstream );
-        }
-        pcBitstream->resetBits();
-        pcBitstream->rewindStreamPacket( );
-        // write bistream to file if necessary
-        xWriteOutput( iViewIdx, true );
-      }
-    }
-#if FLEX_CODING_ORDER
-	}
-#endif
-    // delete extra picture buffers
-    if( bCurrPocCoded )
-    {
+      }
+#if HHI_INTERVIEW_SKIP || HHI_INTER_VIEW_MOTION_PRED || HHI_INTER_VIEW_RESIDUAL_PRED
       for( Int iViewIdx = 0; iViewIdx < m_iNumberOfViews; iViewIdx++ )
       {
         if( iViewIdx < (Int)m_acTEncTopList.size() && m_acTEncTopList[iViewIdx] )
         {
-          m_acTEncTopList[iViewIdx]->deleteExtraPicBuffers( iCurrPoc );
+          m_acTEncTopList[iViewIdx]->deleteExtraPicBuffers( m_acTEncTopList[iViewIdx]->getGOPEncoder()->getPocLastCoded() );
         }
         if( iViewIdx < (Int)m_acTEncDepthTopList.size() && m_acTEncDepthTopList[iViewIdx] )
         {
-          m_acTEncDepthTopList[iViewIdx]->deleteExtraPicBuffers( iCurrPoc );
+          m_acTEncDepthTopList[iViewIdx]->deleteExtraPicBuffers( m_acTEncTopList[iViewIdx]->getGOPEncoder()->getPocLastCoded() );
         }
       }
-    }
-
-#if AMVP_BUFFERCOMPRESS
-    // compress motion for entire access
-    if( bCurrPocCoded )
-    {
-      for( Int iViewIdx = 0; iViewIdx < m_iNumberOfViews; iViewIdx++ )
-      {
-        if( iViewIdx < (Int)m_acTEncTopList.size() && m_acTEncTopList[iViewIdx] )
+#endif
+      for(Int iViewIdx=0; iViewIdx < m_iNumberOfViews; iViewIdx++ )
+      {
+        m_acTEncTopList[iViewIdx]->compressMotion( m_acTEncTopList[iViewIdx]->getGOPEncoder()->getPocLastCoded() );
+        if( m_bUsingDepthMaps )
         {
-          m_acTEncTopList[iViewIdx]->compressMotion( iCurrPoc );
+          m_acTEncDepthTopList[iViewIdx]->compressMotion( m_acTEncDepthTopList[iViewIdx]->getGOPEncoder()->getPocLastCoded() );
         }
-        if( iViewIdx < (Int)m_acTEncDepthTopList.size() && m_acTEncDepthTopList[iViewIdx] )
-        {
-          m_acTEncDepthTopList[iViewIdx]->compressMotion( iCurrPoc );
-        }
-      }
-    }
-#endif
-  }
-
-  // write output
-  for(Int iViewIdx=0; iViewIdx < m_iNumberOfViews; iViewIdx++ )
-  {
-    m_acTEncTopList[iViewIdx]->printOutSummary(m_acTEncTopList[iViewIdx]->getNumAllPicCoded());
-    if ( m_bUsingDepthMaps )
-    {
-      m_acTEncDepthTopList[iViewIdx]->printOutSummary(m_acTEncDepthTopList[iViewIdx]->getNumAllPicCoded());
-    }
-  }
-
+      }
+    }
+    gopSize = maxGopSize;
+  }
   // delete original YUV buffer
   pcPicYuvOrg->destroy();
   delete pcPicYuvOrg;
   pcPicYuvOrg = NULL;
-
-  // valgrind
-  if( m_bUsingDepthMaps)
-  {
-    pcDepthPicYuvOrg->destroy();
-  }
-  delete pcDepthPicYuvOrg ;
-  pcDepthPicYuvOrg = NULL ;
-
-  pcBitstream->destroy();
-  delete pcBitstream;
-  pcBitstream = NULL ;
-
-
-  // delete used buffers in encoder class
-  for(Int iViewIdx =0; iViewIdx < m_iNumberOfViews; iViewIdx++)
-  {
-    m_acTEncTopList[iViewIdx]->deletePicBuffer() ;
-  }
-
-  if( m_bUsingDepthMaps)
-  {
-    for(Int iViewIdx =0; iViewIdx < m_iNumberOfViews; iViewIdx++)
-    {
-      m_acTEncDepthTopList[iViewIdx]->deletePicBuffer() ;
-    }
-  }
-
-  if ( pcPdmDepthOrg )
-  {
-    pcPdmDepthOrg->destroy();
-    delete pcPdmDepthOrg;
-    pcPdmDepthOrg = NULL;
+  pcDepthPicYuvOrg->destroy();
+  delete pcDepthPicYuvOrg;
+  pcDepthPicYuvOrg = NULL;
+  
+  for(Int iViewIdx=0; iViewIdx < m_iNumberOfViews; iViewIdx++ )
+  {
+    m_acTEncTopList[iViewIdx]->printOutSummary(m_acTEncTopList[iViewIdx]->getNumAllPicCoded());
+    if ( m_bUsingDepthMaps )
+    {
+      m_acTEncDepthTopList[iViewIdx]->printOutSummary(m_acTEncDepthTopList[iViewIdx]->getNumAllPicCoded());
+    }
   }
 
@@ -906,5 +933,20 @@
   xDeleteBuffer();
   xDestroyLib();
-}
+
+  return;
+}
+
+TEncTop*  TAppEncTop::getTEncTop( Int viewId, Bool isDepth )    
+{ 
+  if ( isDepth )  
+  {
+    return m_acTEncDepthTopList[viewId]; 
+  } 
+  else
+  { 
+    return m_acTEncTopList[viewId]; 
+  } 
+}
+
 
 // ====================================================================================================================
@@ -918,150 +960,129 @@
  .
  */
-Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec, Int iViewIdx, std::vector< TComList<TComPicYuv*>*>& racBuffer )
-{
-  if ( m_uiCodedPictureStoreSize   == 0 )
-    {
-      if (racBuffer[iViewIdx]->size() == 0)
-      {
-        rpcPicYuvRec = new TComPicYuv;
-        rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
-
-        racBuffer[iViewIdx]->pushBack( rpcPicYuvRec );
-      }
-      rpcPicYuvRec = racBuffer[iViewIdx]->popFront(); //GT why? only one in list ?? A: only to get rpcPicYuvRec
-      racBuffer[iViewIdx]->pushBack( rpcPicYuvRec );
-      return;
-    }
-
-    // org. buffer
-  if ( racBuffer[iViewIdx]->size() == (UInt)m_uiCodedPictureStoreSize )
-    {
-      rpcPicYuvRec = racBuffer[iViewIdx]->popFront();
+Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec, Int iViewIdx, Bool isDepth)
+{
+  assert( m_iGOPSize > 0 );
+  
+  if( !isDepth )
+  {
+    if ( m_picYuvRec[iViewIdx]->size() == (UInt)m_iGOPSize )
+    {
+      rpcPicYuvRec = m_picYuvRec[iViewIdx]->popFront();
     }
     else
     {
-      rpcPicYuvRec = new TComPicYuv;
+      rpcPicYuvRec = new TComPicYuv; 
       rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
     }
-    racBuffer[iViewIdx]->pushBack( rpcPicYuvRec );
+    m_picYuvRec[iViewIdx]->pushBack( rpcPicYuvRec );
+  }
+  else
+  {
+    if ( m_picYuvDepthRec[iViewIdx]->size() == (UInt)m_iGOPSize )
+    {
+      rpcPicYuvRec = m_picYuvDepthRec[iViewIdx]->popFront();
+    }
+    else
+    {
+      rpcPicYuvRec = new TComPicYuv; 
+      rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
+    }
+    m_picYuvDepthRec[iViewIdx]->pushBack( rpcPicYuvRec );
+  }
 }
 
 Void TAppEncTop::xDeleteBuffer( )
 {
-  TComList<TComBitstream*>::iterator iterBitstream = m_cListBitstream.begin();
-
-  Int iSize = Int( m_cListBitstream.size() );
-
-  for ( Int i = 0; i < iSize; i++ )
-  {
-    TComBitstream* pcBitstream = *(iterBitstream++);
-
-    pcBitstream->destroy();
-
-    delete pcBitstream; pcBitstream = NULL;
-  }
-
-  for(Int iViewIdx=0; iViewIdx<m_iNumberOfViews; iViewIdx++)
-  {
-    TComList<TComPicYuv*>::iterator iterPicYuvRec  = m_cListPicYuvRecList[iViewIdx]->begin();
-
-    iSize = Int( m_cListPicYuvRecList[iViewIdx]->size() );
-
-    for ( Int i = 0; i < iSize; i++ )
-    {
+  for(Int iViewIdx=0; iViewIdx<m_picYuvRec.size(); iViewIdx++)
+  {
+    if(m_picYuvRec[iViewIdx])
+    {
+      TComList<TComPicYuv*>::iterator iterPicYuvRec  = m_picYuvRec[iViewIdx]->begin();
+      Int iSize = Int( m_picYuvRec[iViewIdx]->size() );
+      for ( Int i = 0; i < iSize; i++ )
+      {
         TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
-        pcPicYuvRec->destroy();
-        delete pcPicYuvRec; pcPicYuvRec = NULL;
-    }
-  }
-  if( m_bUsingDepthMaps)
-  {
-    for(Int iViewIdx=0; iViewIdx<m_iNumberOfViews; iViewIdx++)
-    {
-      TComList<TComPicYuv*>::iterator iterPicYuvRec  = m_cListPicYuvDepthRecList[iViewIdx]->begin();
-
-      iSize = Int( m_cListPicYuvDepthRecList[iViewIdx]->size() );
-
+        if(pcPicYuvRec)
+        {
+          pcPicYuvRec->destroy();
+          delete pcPicYuvRec; 
+          pcPicYuvRec = NULL;
+        }
+      }
+    } 
+  }
+  for(Int iViewIdx=0; iViewIdx<m_picYuvDepthRec.size(); iViewIdx++)
+  {
+    if(m_picYuvDepthRec[iViewIdx])
+    {
+      TComList<TComPicYuv*>::iterator iterPicYuvRec  = m_picYuvDepthRec[iViewIdx]->begin();
+      Int iSize = Int( m_picYuvDepthRec[iViewIdx]->size() );
       for ( Int i = 0; i < iSize; i++ )
       {
-          TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
+        TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
+        if(pcPicYuvRec)
+        {
           pcPicYuvRec->destroy();
-          delete pcPicYuvRec; pcPicYuvRec = NULL;
-      }
-    }
-  }
-
-  // Delete ERFiles
-
-#if HHI_VSO
-  std::map< Int,vector<TComPicYuv*> >::iterator iterMapPicExtRefView = m_cMapPicExtRefView.begin();
-  while ( iterMapPicExtRefView != m_cMapPicExtRefView.end() )
-  {
-    for ( UInt uiViewNumber = 0; uiViewNumber < iterMapPicExtRefView->second.size(); uiViewNumber++ )
-    {
-      if ( iterMapPicExtRefView->second[uiViewNumber] )
-      {
-        iterMapPicExtRefView->second[uiViewNumber]->destroy();
-        delete iterMapPicExtRefView->second[uiViewNumber];
-      }
-    }
-    iterMapPicExtRefView++;
-  }
-#endif
+          delete pcPicYuvRec; 
+          pcPicYuvRec = NULL;
+        }
+      } 
+    }
+  }
 }
 
 /** \param iNumEncoded  number of encoded frames
  */
-Void TAppEncTop::xWriteOutput( Int iViewIdx, Bool isDepth )
-{
-  std::map<PicOrderCnt, TComPicYuv*> &rcMap = ( isDepth ? m_cListPicYuvDepthRecMap          : m_cListPicYuvRecMap          )[iViewIdx];
-  PicOrderCnt  &riNextPocToDump             = ( isDepth ? m_aiNextDepthPocToDump            : m_aiNextPocToDump            )[iViewIdx];
-  TVideoIOYuv* &rpcTVideoIOYuvReconFile     = ( isDepth ? m_acTVideoIOYuvDepthReconFileList : m_acTVideoIOYuvReconFileList )[iViewIdx];
-  std::map<PicOrderCnt, TComPicYuv*>::iterator i;
-
-  while( ! rcMap.empty() && ( i = rcMap.begin() )->first == riNextPocToDump )
-  {
-    riNextPocToDump++;
-    rpcTVideoIOYuvReconFile->write( i->second, m_aiPad );
-    rcMap.erase( i );
-  }
-}
-
-// GT FIX
-std::vector<TComPic*> TAppEncTop::getSpatialRefPics( Int iViewIdx, Int iPoc, Bool bIsDepthCoder )
-{
-  std::vector<TComPic*> apcRefPics( iViewIdx, (TComPic*)NULL );
-  for( int iRefViewIdx = 0; iRefViewIdx < iViewIdx; iRefViewIdx++ )
-  {
-// GT FIX
-    TComPic* pcRefPic = xGetPicFromView(iRefViewIdx, iPoc, bIsDepthCoder);
-
-    assert( pcRefPic != NULL );
-    apcRefPics[iRefViewIdx] = pcRefPic;
-  }
-  return apcRefPics;
-}
-
-
-TComPic* TAppEncTop::xGetPicFromView( Int iViewIdx, Int iPoc, bool bDepth )
-{
-  assert( ( iViewIdx >= 0) && ( iViewIdx < m_iNumberOfViews ) );
-
-  TComPic* pcPic = 0;
-  TComList<TComPic*>* apcListPic;
-
-  apcListPic = (bDepth ?  m_acTEncDepthTopList[iViewIdx] : m_acTEncTopList[iViewIdx])->getListPic() ;
-
-  for(TComList<TComPic*>::iterator it=apcListPic->begin(); it!=apcListPic->end(); it++)
-  {
-    if( (*it)->getPOC() == iPoc )
-    {
-      pcPic = *it ;
-      break ;
-    }
-  }
-
-  return pcPic;
-};
+Void TAppEncTop::xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, std::list<AccessUnit>& accessUnits, Int iViewIdx, Bool isDepth )
+{
+  Int i;
+  
+  if( iNumEncoded > 0 )
+  {
+    TComList<TComPicYuv*>::iterator iterPicYuvRec = !isDepth ? m_picYuvRec[iViewIdx]->end() : m_picYuvDepthRec[iViewIdx]->end();
+  
+    for ( i = 0; i < iNumEncoded; i++ )
+    {
+      --iterPicYuvRec;
+    }
+  
+    for ( i = 0; i < iNumEncoded; i++ )
+    {
+      TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
+      if( !isDepth )
+      {
+        if (m_pchReconFileList[iViewIdx])
+        {
+#if PIC_CROPPING
+          m_acTVideoIOYuvReconFileList[iViewIdx]->write( pcPicYuvRec, m_cropLeft, m_cropRight, m_cropTop, m_cropBottom );
+#else
+          m_acTVideoIOYuvReconFileList[iViewIdx]->write( pcPicYuvRec, m_aiPad );
+#endif
+        }
+      }
+      else
+      {
+        if (m_pchDepthReconFileList[iViewIdx])
+        {
+#if PIC_CROPPING
+          m_acTVideoIOYuvDepthReconFileList[iViewIdx]->write( pcPicYuvRec, m_cropLeft, m_cropRight, m_cropTop, m_cropBottom );
+#else
+          m_acTVideoIOYuvDepthReconFileList[iViewIdx]->write( pcPicYuvRec, m_aiPad );
+#endif
+        }
+      }
+    }
+  }
+  if( ! accessUnits.empty() )
+  {
+    list<AccessUnit>::iterator aUIter;
+    for( aUIter = accessUnits.begin(); aUIter != accessUnits.end(); aUIter++ )
+    {
+      const vector<unsigned>& stats = writeAnnexB(bitstreamFile, *aUIter);
+      rateStatsAccum(*aUIter, stats);
+    }
+  }
+}
+
 
 TComPicYuv* TAppEncTop::xGetPicYuvFromView( Int iViewIdx, Int iPoc, Bool bDepth, Bool bRecon )
@@ -1088,187 +1109,38 @@
 };
 
-#if HHI_VSO
-Void TAppEncTop::xSetBasePicYuv( Int iViewIdx, Int iPoc, TComMVDRefData* pcRefInfo, InterViewReference eView, bool bDepth )
-{
-
-  if ( ( iViewIdx < 0) || ( iViewIdx >= m_iNumberOfViews ) )
-    return;
-
-  if ( !m_bUsingDepthMaps && bDepth )
-    return;
-
-  TComPic* pcPic = xGetPicFromView( iViewIdx, iPoc, bDepth);
-
-  if (pcPic == 0)
-    return;
-
-  pcRefInfo->setPicYuvBaseView(eView, bDepth, pcPic->getPicYuvOrg(),  pcPic->getReconMark() ? pcPic->getPicYuvRec() : NULL );
-
-};
-
-Void TAppEncTop::setMVDPic( Int iViewIdx, Int iPoc, TComMVDRefData* pcMVDRefData )
-{
-  AOF( iViewIdx >= 0);
-  AOF( iViewIdx <  m_iNumberOfViews  );
-
-  xSetBasePicYuv(iViewIdx - 1, iPoc, pcMVDRefData, PREVVIEW, false);
-  xSetBasePicYuv(iViewIdx    , iPoc, pcMVDRefData, CURRVIEW, false );
-  xSetBasePicYuv(iViewIdx + 1, iPoc, pcMVDRefData, NEXTVIEW, false );
-
-  if ( m_bUsingDepthMaps )
-  {
-    xSetBasePicYuv(iViewIdx - 1, iPoc, pcMVDRefData, PREVVIEW, true );
-    xSetBasePicYuv(iViewIdx    , iPoc, pcMVDRefData, CURRVIEW, true );
-    xSetBasePicYuv(iViewIdx + 1, iPoc, pcMVDRefData, NEXTVIEW, true );
-  }
-
-
-  xSetBaseLUT       (iViewIdx, iViewIdx-1  , pcMVDRefData, PREVVIEW );
-  xSetBaseLUT       (iViewIdx, iViewIdx+1  , pcMVDRefData, NEXTVIEW );
-
-
-  if ( m_bUseVSO && m_uiVSOMode != 4)
-  {
-    xSetERPicYuvs               (iViewIdx, iPoc, pcMVDRefData);
-    pcMVDRefData->setShiftLUTsERView(m_cCameraData.getSynthViewShiftLUTD()[iViewIdx],  m_cCameraData.getSynthViewShiftLUTI()[iViewIdx] );
-    pcMVDRefData->setRefViewInd     (m_aaiBaseViewRefInd[iViewIdx], m_aaiERViewRefInd[iViewIdx], m_aaiERViewRefLutInd[iViewIdx]);
-  }
-};
-
-
-Void TAppEncTop::xSetBaseLUT( Int iViewIdxSource, Int iViewIdxTarget, TComMVDRefData* pcRefInfo, InterViewReference eView )
-{
-  if ( ( iViewIdxSource < 0) || ( iViewIdxSource >= m_iNumberOfViews )||( iViewIdxTarget < 0) || ( iViewIdxTarget >= m_iNumberOfViews ) )
-    return;
-  assert( abs( iViewIdxTarget - iViewIdxSource ) <= 1 );  //GT; Not supported yet
-  pcRefInfo->setShiftLUTsBaseView(eView, m_cCameraData.getBaseViewShiftLUTD()[iViewIdxSource][iViewIdxTarget],m_cCameraData.getBaseViewShiftLUTI()[iViewIdxSource][iViewIdxTarget] );
-};
-
-Void TAppEncTop::xSetERPicYuvs( Int iViewIdx, Int iPoc, TComMVDRefData* pcReferenceInfo )
-{
-  std::vector<TComPicYuv*> apcExtRefViews;
-
-  std::map< Int, vector<TComPicYuv*> >::iterator cMapIt;
-  cMapIt = m_cMapPicExtRefView.find(iPoc);
-
-  assert(  cMapIt != m_cMapPicExtRefView.end() );
-
-  pcReferenceInfo->setPicYuvERViews( cMapIt->second );
-}
-
-Void TAppEncTop::xStoreVSORefPicsInBuffer()
-{
-  // X-Check if all Encoders have received the same number of pics
-  Int iNumRcvd = m_iFrameRcvdVector[0];
-  for ( UInt uiViewNumber = 0; uiViewNumber < m_iNumberOfViews; uiViewNumber ++ )
-  {
-    assert( ( m_iFrameRcvdVector[uiViewNumber] == iNumRcvd ) && ( m_iDepthFrameRcvdVector[uiViewNumber] == iNumRcvd ) ); //GT; if assert here, the encoder instances are not synchronized any more, re-think this function and the ERView Buffer!!
-  };
-
-  Int iCurPoc = iNumRcvd - 1;
-
-  if ( iCurPoc <= m_iLastFramePutInERViewBuffer )
-  {
-    return;
-  }
-
-  std::vector<TComPicYuv*> apcExtRefViewVec;
-
-  Int iNumberOfReferenceViews = 0;
-  if (m_iNumberOfExternalRefs != 0)
-  {
-    m_aaiERViewRefLutInd = m_aaiERViewRefInd;
-    // Insert Rendered Views form File
-
-    iNumberOfReferenceViews = m_iNumberOfExternalRefs;
-
-    for ( UInt uiViewNumber = 0; uiViewNumber < iNumberOfReferenceViews; uiViewNumber++ )
-    {
-      TComPicYuv* pcPicYuvERView = new TComPicYuv;
-      pcPicYuvERView->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
-
-      m_acTVideoIOYuvERFileList[uiViewNumber]->read( pcPicYuvERView, m_aiPad  ) ;
-
-      apcExtRefViewVec.push_back( pcPicYuvERView );
-    }
-  }
-  else
-  { //Render Views
-
-    for ( UInt uiViewNumber = 0; uiViewNumber < m_iNumberOfViews; uiViewNumber++ )
-    {
-      m_aaiERViewRefInd   [uiViewNumber].clear();
-      m_aaiERViewRefLutInd[uiViewNumber].clear();
-    }
-
-    iNumberOfReferenceViews = 0;
-    for ( UInt iSynthViewIdx = 0; iSynthViewIdx < m_cCameraData.getSynthViewNumbers().size(); iSynthViewIdx++ )
-    {
-      // Get Left and right view
-      Int  iLeftViewIdx  = -1;
-      Int  iRightViewIdx = -1;
-      Bool bIsBaseView;
-
-      Int iRelDistToLeft;
-      m_cCameraData.getLeftRightBaseView( iSynthViewIdx, iLeftViewIdx, iRightViewIdx, iRelDistToLeft, bIsBaseView );
-
-      if  ((iLeftViewIdx == -1) || (iRightViewIdx == -1))
-      {
-        std::cerr << "Left or right View not given." << endl;
-        exit(EXIT_FAILURE);
-      }
-
-      m_cRendererTop.setShiftLUTs(
-        m_cCameraData.getSynthViewShiftLUTD()[iLeftViewIdx] [iSynthViewIdx],
-        m_cCameraData.getSynthViewShiftLUTI()[iLeftViewIdx] [iSynthViewIdx],
-        m_cCameraData.getBaseViewShiftLUTI ()[iLeftViewIdx] [iRightViewIdx],
-        m_cCameraData.getSynthViewShiftLUTD()[iRightViewIdx][iSynthViewIdx],
-        m_cCameraData.getSynthViewShiftLUTI()[iRightViewIdx][iSynthViewIdx],
-        m_cCameraData.getBaseViewShiftLUTI ()[iRightViewIdx][iLeftViewIdx],
-        iRelDistToLeft
-      );
-      if ( bIsBaseView ) continue;
-
-      // Render from left
-      TComPicYuv* pcPicYuvERView = new TComPicYuv;
-      pcPicYuvERView->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
-      m_cRendererTop.extrapolateView( xGetPicFromView( iLeftViewIdx, iCurPoc, false )->getPicYuvOrg(), xGetPicFromView( iLeftViewIdx, iCurPoc, true )->getPicYuvOrg(), pcPicYuvERView, true );
-
-      apcExtRefViewVec.push_back( pcPicYuvERView );
-
-      m_aaiERViewRefInd   [ iLeftViewIdx].push_back( iNumberOfReferenceViews );
-      m_aaiERViewRefLutInd[ iLeftViewIdx].push_back( iSynthViewIdx );
-      iNumberOfReferenceViews++;
-
-      //Render from right
-      pcPicYuvERView = new TComPicYuv;
-      pcPicYuvERView->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
-
-      m_cRendererTop.extrapolateView( xGetPicFromView( iRightViewIdx, iCurPoc, false )->getPicYuvOrg(), xGetPicFromView( iRightViewIdx, iCurPoc, true )->getPicYuvOrg(), pcPicYuvERView, false );
-      apcExtRefViewVec.push_back( pcPicYuvERView );
-
-      m_aaiERViewRefInd   [ iRightViewIdx].push_back( iNumberOfReferenceViews );
-      m_aaiERViewRefLutInd[ iRightViewIdx].push_back( iSynthViewIdx );
-      iNumberOfReferenceViews++;
-    }
-  }
-
-  m_iLastFramePutInERViewBuffer++;
-  m_cMapPicExtRefView.insert( std::make_pair( m_iLastFramePutInERViewBuffer, apcExtRefViewVec ) );
-
-  if ( m_cMapPicExtRefView.size() >  (UInt)m_iGOPSize + 1 )
-  {
-    for ( UInt uiViewNumber = 0; uiViewNumber < (UInt) m_cMapPicExtRefView.begin()->second.size(); uiViewNumber++ )
-    {
-      if ( m_cMapPicExtRefView.begin()->second[uiViewNumber] )
-      {
-        m_cMapPicExtRefView.begin()->second[uiViewNumber]->destroy();
-        delete m_cMapPicExtRefView.begin()->second[uiViewNumber];
-      }
-    }
-    m_cMapPicExtRefView.erase ( m_cMapPicExtRefView.begin() );
-  }
-}
-#endif
+/**
+ *
+ */
+void TAppEncTop::rateStatsAccum(const AccessUnit& au, const std::vector<unsigned>& annexBsizes)
+{
+  AccessUnit::const_iterator it_au = au.begin();
+  vector<unsigned>::const_iterator it_stats = annexBsizes.begin();
+
+  for (; it_au != au.end(); it_au++, it_stats++)
+  {
+    switch ((*it_au)->m_nalUnitType)
+    {
+    case NAL_UNIT_CODED_SLICE:
+#if H0566_TLA
+    case NAL_UNIT_CODED_SLICE_IDV:
+    case NAL_UNIT_CODED_SLICE_TLA:
+    case NAL_UNIT_CODED_SLICE_CRA:
+#else
+    case NAL_UNIT_CODED_SLICE_DATAPART_A:
+    case NAL_UNIT_CODED_SLICE_DATAPART_B:
+    case NAL_UNIT_CODED_SLICE_CDR:
+#endif
+    case NAL_UNIT_CODED_SLICE_IDR:
+    case NAL_UNIT_SPS:
+    case NAL_UNIT_PPS:
+      m_essentialBytes += *it_stats;
+      break;
+    default:
+      break;
+    }
+
+    m_totalBytes += *it_stats;
+  }
+}
 
 #if HHI_INTERVIEW_SKIP
@@ -1277,7 +1149,5 @@
   AOT( iViewIdx <= 0);
   AOT( iViewIdx >= m_iNumberOfViews );
-  AOF( m_uiInterViewSkip != 0 );
   AOF( m_cCameraData.getCurFrameId() == iPoc );
-
   Int iViewSIdx      = m_cCameraData.getBaseId2SortedId()[iViewIdx];
   Int iFirstViewSIdx = m_cCameraData.getBaseId2SortedId()[0];
@@ -1287,5 +1157,5 @@
   Bool bFirstIsLeft = (iFirstViewSIdx < iViewSIdx);
 
-    m_cUsedPelsRenderer.setShiftLUTs(
+  m_cUsedPelsRenderer.setShiftLUTs(
       m_cCameraData.getBaseViewShiftLUTD()[0][iViewIdx],
       m_cCameraData.getBaseViewShiftLUTI()[0][iViewIdx],
@@ -1297,13 +1167,10 @@
       );
 
-
   TComPicYuv* pcPicYuvDepth = xGetPicYuvFromView(0, iPoc, true, true );
   AOF( pcPicYuvDepth);
 
   m_cUsedPelsRenderer.getUsedSamplesMap( pcPicYuvDepth, pcPicYuvUsedSplsMap, bFirstIsLeft );
-
-}
-#endif
-
+}
+#endif
 #if HHI_VSO
 Void TAppEncTop::setupRenModel( Int iPoc, Int iEncViewIdx, Int iEncContent )
@@ -1403,2 +1270,47 @@
 #endif
 
+
+
+/*
+void TAppEncTop::printRateSummary()
+{
+  double time = (double) m_iFrameRcvd / m_iFrameRate;
+  printf("Bytes written to file: %u (%.3f kbps)\n", m_totalBytes, 0.008 * m_totalBytes / time);
+#if VERBOSE_RATE
+  printf("Bytes for SPS/PPS/Slice (Incl. Annex B): %u (%.3f kbps)\n", m_essentialBytes, 0.008 * m_essentialBytes / time);
+#endif
+}
+*/
+
+std::vector<TComPic*> TAppEncTop::getInterViewRefPics( Int viewId, Int poc, Bool isDepth, TComSPS* sps )
+{
+  std::vector<TComPic*> apcRefPics( sps->getNumberOfUsableInterViewRefs(), (TComPic*)NULL );
+  for( Int k = 0; k < sps->getNumberOfUsableInterViewRefs(); k++ )
+  {
+    TComPic* pcRefPic = xGetPicFromView( sps->getUsableInterViewRef( k ) + viewId, poc, isDepth );
+    assert( pcRefPic != NULL );
+    apcRefPics[k] = pcRefPic;
+  }
+  return apcRefPics;
+}
+
+TComPic* TAppEncTop::xGetPicFromView( Int viewIdx, Int poc, Bool isDepth )
+{
+  assert( ( viewIdx >= 0 ) && ( viewIdx < m_iNumberOfViews ) );
+
+  TComList<TComPic*>* apcListPic = (isDepth ?  m_acTEncDepthTopList[viewIdx] : m_acTEncTopList[viewIdx])->getListPic() ;
+
+  TComPic* pcPic = NULL;
+  for(TComList<TComPic*>::iterator it=apcListPic->begin(); it!=apcListPic->end(); it++)
+  {
+    if( (*it)->getPOC() == poc )
+    {
+      pcPic = *it ;
+      break ;
+    }
+  }
+
+  return pcPic;
+};
+
+//! \}
Index: trunk/source/App/TAppEncoder/TAppEncTop.h
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncTop.h	(revision 42)
+++ trunk/source/App/TAppEncoder/TAppEncTop.h	(revision 56)
@@ -2,7 +2,7 @@
  * License, included below. This software may be subject to other third party
  * and contributor rights, including patent rights, and no such rights are
- * granted under this license.
+ * granted under this license.  
  *
- * Copyright (c) 2010-2011, ISO/IEC
+ * Copyright (c) 2010-2012, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -15,5 +15,5 @@
  *    this list of conditions and the following disclaimer in the documentation
  *    and/or other materials provided with the distribution.
- *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
  *    be used to endorse or promote products derived from this software without
  *    specific prior written permission.
@@ -32,6 +32,4 @@
  */
 
-
-
 /** \file     TAppEncTop.h
     \brief    Encoder application class (header)
@@ -41,13 +39,18 @@
 #define __TAPPENCTOP__
 
-#include "../../Lib/TLibEncoder/TEncTop.h"
-#include "../../Lib/TLibVideoIO/TVideoIOYuv.h"
-#include "../../Lib/TLibVideoIO/TVideoIOBits.h"
-#include "../../Lib/TLibCommon/TComBitStream.h"
-#include "../../Lib/TLibCommon/TComDepthMapGenerator.h"
+#include <list>
+#include <ostream>
+
+#include "TLibEncoder/TEncTop.h"
+#include "TLibVideoIO/TVideoIOYuv.h"
+#include "TLibCommon/AccessUnit.h"
 #include "TAppEncCfg.h"
-//GT VSO
+#include "TLibCommon/TComDepthMapGenerator.h"
+#if HHI_VSO || HHI_INTERVIEW_SKIP
 #include "../../Lib/TLibRenderer/TRenTop.h"
-//GT VSO end
+#endif
+
+//! \ingroup TAppEncoder
+//! \{
 
 // ====================================================================================================================
@@ -60,25 +63,19 @@
 private:
   // class interface
+  std::vector<TEncTop*>				  m_acTEncTopList ;
+  std::vector<TEncTop*>				  m_acTEncDepthTopList ;
+  std::vector<TVideoIOYuv*>		m_acTVideoIOYuvInputFileList;  ///< input YUV file
+  std::vector<TVideoIOYuv*>  m_acTVideoIOYuvDepthInputFileList;
+  std::vector<TVideoIOYuv*>		m_acTVideoIOYuvReconFileList;  ///< output reconstruction file
+  std::vector<TVideoIOYuv*>  m_acTVideoIOYuvDepthReconFileList;
 
-  std::vector<TEncTop*>				 m_acTEncTopList ;
-  std::vector<TEncTop*>        m_acTEncDepthTopList ;
-  std::vector<TVideoIOYuv*>		 m_acTVideoIOYuvInputFileList;
-  std::vector<TVideoIOYuv*>    m_acTVideoIOYuvDepthInputFileList;
-  std::vector<TVideoIOYuv*>		 m_acTVideoIOYuvReconFileList;
-  std::vector<TVideoIOYuv*>    m_acTVideoIOYuvDepthReconFileList;
+  std::vector< TComList<TComPicYuv*>* >  m_picYuvRec;       ///< list of reconstruction YUV files
+  std::vector< TComList<TComPicYuv*>* >  m_picYuvDepthRec;         
 
-  TVideoIOBitsStartCode      m_cTVideoIOBitsFile;           ///< output bitstream file
-  
-  std::vector< TComList<TComPicYuv*>* >  m_cListPicYuvRecList;              ///< list of reconstruction YUV files
-  std::vector< TComList<TComPicYuv*>* >  m_cListPicYuvDepthRecList;         ///< list of reconstruction YUV files
-  std::vector<PicOrderCnt> m_aiNextPocToDump;
-  std::vector<PicOrderCnt> m_aiNextDepthPocToDump;
-  std::vector< std::map<PicOrderCnt, TComPicYuv*> > m_cListPicYuvRecMap;
-  std::vector< std::map<PicOrderCnt, TComPicYuv*> > m_cListPicYuvDepthRecMap;
+  std::vector<Int>          	m_frameRcvd;                  ///< number of received frames
+  std::vector<Int>          	m_depthFrameRcvd;   
 
-  TComList<TComBitstream*>   m_cListBitstream;              ///< list of bitstreams
-  
-  std::vector<Int>           	m_iFrameRcvdVector;                  ///< number of received frames
-  std::vector<Int>            m_iDepthFrameRcvdVector;             ///< number of received frames
+  unsigned                   m_essentialBytes;
+  unsigned                   m_totalBytes;
 
 #if DEPTH_MAP_GENERATION
@@ -86,5 +83,5 @@
   TComAUPicAccess             m_cAUPicAccess;
 #endif
-  
+
 #if HHI_VSO
   TRenTop                     m_cRendererTop; 
@@ -92,4 +89,7 @@
 #endif
 
+#if HHI_INTERVIEW_SKIP
+  TRenTop  m_cUsedPelsRenderer;                               ///< renderer for used pels map
+#endif
 protected:
   // initialization
@@ -100,26 +100,16 @@
   
   /// obtain required buffers
-  Void  xGetBuffer        ( TComPicYuv*& rpcPicYuvRec,			//GT: unused?
-                           TComBitstream*& rpcBitStream );
+  Void xGetBuffer(TComPicYuv*& rpcPicYuvRec, Int iViewIdx, Bool isDepth);
   
-  Void  xGetBuffer        ( TComPicYuv*& rpcPicYuvRec, Int iViewIdx, std::vector< TComList<TComPicYuv*>*>& racBuffer  );
-
   /// delete allocated buffers
   Void  xDeleteBuffer     ();
   
   // file I/O
-  Void  xWriteOutput      ( Int iViewIdx, Bool isDepth = false );              ///< write bitstream to file
-
-
-  // util  
-  TComPic*    xGetPicFromView   ( Int iViewIdx, Int iPoc, Bool bDepth );
+  Void xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, std::list<AccessUnit>& accessUnits, Int iViewIdx, Bool isDepth); ///< write bitstream to file
+  void rateStatsAccum(const AccessUnit& au, const std::vector<unsigned>& stats);
+  // void printRateSummary();
+  
+  TComPic* xGetPicFromView( Int viewId, Int iPoc, Bool isDepth );
   TComPicYuv* xGetPicYuvFromView( Int iViewIdx, Int iPoc, Bool bDepth, Bool bRecon );
-
-
-  // Ref Data
-#if HHI_VSO
-  Void  xSetBaseLUT   ( Int iViewIdxSource, Int iViewIdxTarget, TComMVDRefData* pcRefInfo, InterViewReference eView );
-  Void  xSetBasePicYuv( Int iViewIdx, Int iPoc, TComMVDRefData* pcRefInfo, InterViewReference eView, bool bDepth ); ///< store pics from buffers in pcRefInfo
-#endif
   
 public:
@@ -128,16 +118,17 @@
   
   Void        encode      ();                               ///< main encoding function
+  TEncTop*    getTEncTop( Int viewId, Bool isDepth );   
+
+  std::vector<TComPic*> getInterViewRefPics( Int viewId, Int poc, Bool isDepth, TComSPS* sps );
+  TComPic*              getPicFromView     ( Int viewId, Int poc, Bool isDepth ) { return xGetPicFromView( viewId, poc, isDepth ); }
+  TComPicYuv*           getPicYuvFromView  ( Int iViewIdx, Int iPoc, bool bDepth, Bool bRecon ) { return xGetPicYuvFromView( iViewIdx, iPoc, bDepth, bRecon ); }
+
+#if HHI_INTERVIEW_SKIP
+  Void                  getUsedPelsMap   ( Int iViewIdx, Int iPoc, TComPicYuv* pcPicYuvUsedPelsMap );
+#endif
 #if HHI_VSO
   Void                  setupRenModel    ( Int iPoc, Int iEncViewIdx, Int iEncContent );
-  Void                  setMVDPic        ( Int iViewIdx, Int iPoc, TComMVDRefData* pcReferenceInfo ); // set MultiView References
 #endif
-  Void                  getUsedPelsMap   ( Int iViewIdx, Int iPoc, TComPicYuv* pcPicYuvUsedPelsMap );
-  std::vector<TComPic*> getSpatialRefPics( Int iViewIdx, Int iPoc, Bool bIsDepthCoder );              // only for mvc functionality yet 
-  TComPic*              getPicFromView   ( Int iViewIdx, Int iPoc, Bool bDepth ) { return xGetPicFromView( iViewIdx, iPoc, bDepth ); }
-
-#if HHI_VSO
-  TRenModel* getRenModel    () { return  &m_cRendererModel ; }; 
-#endif
-
+  
 #if DEPTH_MAP_GENERATION
   TComSPSAccess*    getSPSAccess  () { return &m_cSPSAccess;   }
@@ -146,14 +137,15 @@
 
 #if HHI_VSO
+  TRenModel* getRenModel    () { return  &m_cRendererModel ; }; 
+#endif
+
+#if HHI_VSO
 private:
-  std::vector<TVideoIOYuv*>		               m_acTVideoIOYuvERFileList;
-  std::map< Int, std::vector< TComPicYuv*> > m_cMapPicExtRefView;             /// Buffer for external Reference files
-
-  Int                                        m_iLastFramePutInERViewBuffer;   ///< Poc of last frame put to ERView Buffer
-  Void  xSetERPicYuvs(  Int iViewIdx, Int iPoc, TComMVDRefData* pcReferenceInfo );    ///< store pic from buffer in pcReferenceInfo    
   Void  xStoreVSORefPicsInBuffer();                                                   ///< read in External Ref pic from file and store in buffer
 #endif
-  
+
 };// END CLASS DEFINITION TAppEncTop
+
+//! \}
 
 #endif // __TAPPENCTOP__
Index: trunk/source/App/TAppEncoder/encmain.cpp
===================================================================
--- trunk/source/App/TAppEncoder/encmain.cpp	(revision 42)
+++ trunk/source/App/TAppEncoder/encmain.cpp	(revision 56)
@@ -2,7 +2,7 @@
  * License, included below. This software may be subject to other third party
  * and contributor rights, including patent rights, and no such rights are
- * granted under this license.
+ * granted under this license.  
  *
- * Copyright (c) 2010-2011, ISO/IEC
+ * Copyright (c) 2010-2012, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -15,5 +15,5 @@
  *    this list of conditions and the following disclaimer in the documentation
  *    and/or other materials provided with the distribution.
- *  * Neither the name of the ISO/IEC nor the names of its contributors may
+ *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
  *    be used to endorse or promote products derived from this software without
  *    specific prior written permission.
@@ -32,6 +32,4 @@
  */
 
-
-
 /** \file     encmain.cpp
     \brief    Encoder application main
@@ -40,4 +38,7 @@
 #include <time.h>
 #include "TAppEncTop.h"
+
+//! \ingroup TAppEncoder
+//! \{
 
 // ====================================================================================================================
@@ -51,5 +52,5 @@
   // print information
   fprintf( stdout, "\n" );
-  fprintf( stdout, "HM %s based Multiview Video plus Depth Coder: Encoder Version [%s]", HM_VERSION, NV_VERSION );
+  fprintf( stdout, "3D-HTM Software: Encoder Version [%s] based on HM Version [%s]", NV_VERSION, HM_VERSION );  
   fprintf( stdout, NVM_ONOS );
   fprintf( stdout, NVM_COMPILEDBY );
@@ -84,3 +85,3 @@
 }
 
-
+//! \}
