Index: branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 1376)
+++ branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 1377)
@@ -122,8 +122,5 @@
 , m_elRapSliceBEnabled(0)
 {
-  for(UInt layer=0; layer<MAX_LAYERS; layer++)
-  {
-    m_acLayerCfg[layer].setAppEncCfg(this);
-  }
+  memset( m_apcLayerCfg, NULL, sizeof(m_apcLayerCfg) );
   memset( m_scalabilityMask, 0, sizeof(m_scalabilityMask) );
 }
@@ -186,20 +183,25 @@
 {
 #if SVC_EXTENSION
-  for(Int layer = 0; layer < MAX_LAYERS; layer++)
-  {
-    if( m_acLayerCfg[layer].m_numSamplePredRefLayers > 0 )
-    {
-      delete [] m_acLayerCfg[layer].m_samplePredRefLayerIds;
-      m_acLayerCfg[layer].m_samplePredRefLayerIds = NULL;
-    }
-    if( m_acLayerCfg[layer].m_numMotionPredRefLayers > 0 )
-    {
-      delete [] m_acLayerCfg[layer].m_motionPredRefLayerIds;
-      m_acLayerCfg[layer].m_motionPredRefLayerIds = NULL;
-    }
-    if( m_acLayerCfg[layer].m_numActiveRefLayers > 0 )
-    {
-      delete [] m_acLayerCfg[layer].m_predLayerIds;
-      m_acLayerCfg[layer].m_predLayerIds = NULL;
+  for( Int layer = 0; layer < m_numLayers; layer++ )
+  {
+    if( m_apcLayerCfg[layer]->m_numSamplePredRefLayers > 0 )
+    {
+      delete [] m_apcLayerCfg[layer]->m_samplePredRefLayerIds;
+      m_apcLayerCfg[layer]->m_samplePredRefLayerIds = NULL;
+    }
+    if( m_apcLayerCfg[layer]->m_numMotionPredRefLayers > 0 )
+    {
+      delete [] m_apcLayerCfg[layer]->m_motionPredRefLayerIds;
+      m_apcLayerCfg[layer]->m_motionPredRefLayerIds = NULL;
+    }
+    if( m_apcLayerCfg[layer]->m_numActiveRefLayers > 0 )
+    {
+      delete [] m_apcLayerCfg[layer]->m_predLayerIds;
+      m_apcLayerCfg[layer]->m_predLayerIds = NULL;
+    }
+    if( m_apcLayerCfg[layer] )
+    {
+      delete m_apcLayerCfg[layer];
+      m_apcLayerCfg[layer] = NULL;
     }
   }
@@ -752,4 +754,38 @@
 // ====================================================================================================================
 
+#if SVC_EXTENSION
+/** \param  argc        number of arguments
+    \param  argv        array of arguments
+    \retval             true when success
+ */
+Bool TAppEncCfg::parseCfgNumLayersAndInit( Int argc, Char* argv[] )
+{
+  po::Options opts;
+  opts.addOptions()
+  ("c",    po::parseConfigFile, "configuration file name")
+  ("NumLayers",                                     m_numLayers,                                             1, "Number of layers to code")
+  ;
+
+  po::setDefaults(opts);
+  po::ErrorReporter err;
+  err.verbose = false;
+  po::scanArgv(opts, argc, (const Char**) argv, err);
+
+  if( m_numLayers <= 0 )
+  {
+    printf("Wrong number of layers %d\n", m_numLayers);
+    return false;
+  }
+
+  for( Int layer = 0; layer < m_numLayers; layer++ )
+  {
+    m_apcLayerCfg[layer] = new TAppEncLayerCfg;
+    m_apcLayerCfg[layer]->setAppEncCfg(this);
+  }
+
+  return true;
+}
+#endif
+
 /** \param  argc        number of arguments
     \param  argv        array of arguments
@@ -866,51 +902,51 @@
   Int*    cfg_layerPTLIdx[MAX_VPS_LAYER_IDX_PLUS1];
 
-  for( UInt layer = 0; layer < MAX_LAYERS; layer++ )
-  {
-    cfg_InputFile[layer]    = &m_acLayerCfg[layer].m_cInputFile;
-    cfg_ReconFile[layer]    = &m_acLayerCfg[layer].m_cReconFile;
-    cfg_fQP[layer]          = &m_acLayerCfg[layer].m_fQP;
+  for( UInt layer = 0; layer < m_numLayers; layer++ )
+  {
+    cfg_InputFile[layer]    = &m_apcLayerCfg[layer]->m_cInputFile;
+    cfg_ReconFile[layer]    = &m_apcLayerCfg[layer]->m_cReconFile;
+    cfg_fQP[layer]          = &m_apcLayerCfg[layer]->m_fQP;
 #if Q0074_COLOUR_REMAPPING_SEI
-    cfg_colourRemapSEIFileRoot[layer] = &m_acLayerCfg[layer].m_colourRemapSEIFileRoot;
-#endif
-    cfg_repFormatIdx[layer]         = &m_acLayerCfg[layer].m_repFormatIdx;
-    cfg_layerId[layer]              = &m_acLayerCfg[layer].m_layerId;
-    cfg_SourceWidth[layer]          = &m_acLayerCfg[layer].m_iSourceWidth;
-    cfg_SourceHeight[layer]         = &m_acLayerCfg[layer].m_iSourceHeight;
-    cfg_FrameRate[layer]            = &m_acLayerCfg[layer].m_iFrameRate; 
-    cfg_IntraPeriod[layer]          = &m_acLayerCfg[layer].m_iIntraPeriod; 
-    cfg_conformanceMode[layer]      = &m_acLayerCfg[layer].m_conformanceMode;
-    cfg_confWinLeft[layer]          = &m_acLayerCfg[layer].m_confWinLeft;
-    cfg_confWinRight[layer]         = &m_acLayerCfg[layer].m_confWinRight;
-    cfg_confWinTop[layer]           = &m_acLayerCfg[layer].m_confWinTop;
-    cfg_confWinBottom[layer]        = &m_acLayerCfg[layer].m_confWinBottom;
-    cfg_aiPadX[layer]               = &m_acLayerCfg[layer].m_aiPad[0];
-    cfg_aiPadY[layer]               = &m_acLayerCfg[layer].m_aiPad[1];
-    cfg_useExtendedPrecision[layer] = &m_acLayerCfg[layer].m_extendedPrecisionProcessingFlag;
-
-    cfg_maxCuDQPDepth[layer]        = &m_acLayerCfg[layer].m_iMaxCuDQPDepth;
+    cfg_colourRemapSEIFileRoot[layer] = &m_apcLayerCfg[layer]->m_colourRemapSEIFileRoot;
+#endif
+    cfg_repFormatIdx[layer]         = &m_apcLayerCfg[layer]->m_repFormatIdx;
+    cfg_layerId[layer]              = &m_apcLayerCfg[layer]->m_layerId;
+    cfg_SourceWidth[layer]          = &m_apcLayerCfg[layer]->m_iSourceWidth;
+    cfg_SourceHeight[layer]         = &m_apcLayerCfg[layer]->m_iSourceHeight;
+    cfg_FrameRate[layer]            = &m_apcLayerCfg[layer]->m_iFrameRate; 
+    cfg_IntraPeriod[layer]          = &m_apcLayerCfg[layer]->m_iIntraPeriod; 
+    cfg_conformanceMode[layer]      = &m_apcLayerCfg[layer]->m_conformanceMode;
+    cfg_confWinLeft[layer]          = &m_apcLayerCfg[layer]->m_confWinLeft;
+    cfg_confWinRight[layer]         = &m_apcLayerCfg[layer]->m_confWinRight;
+    cfg_confWinTop[layer]           = &m_apcLayerCfg[layer]->m_confWinTop;
+    cfg_confWinBottom[layer]        = &m_apcLayerCfg[layer]->m_confWinBottom;
+    cfg_aiPadX[layer]               = &m_apcLayerCfg[layer]->m_aiPad[0];
+    cfg_aiPadY[layer]               = &m_apcLayerCfg[layer]->m_aiPad[1];
+    cfg_useExtendedPrecision[layer] = &m_apcLayerCfg[layer]->m_extendedPrecisionProcessingFlag;
+
+    cfg_maxCuDQPDepth[layer]        = &m_apcLayerCfg[layer]->m_iMaxCuDQPDepth;
 
     // coding unit (CU) definition
-    cfg_uiMaxCUWidth[layer]  = &m_acLayerCfg[layer].m_uiMaxCUWidth;
-    cfg_uiMaxCUHeight[layer] = &m_acLayerCfg[layer].m_uiMaxCUHeight;
-    cfg_uiMaxCUDepth[layer]  = &m_acLayerCfg[layer].m_uiMaxCUDepth;
+    cfg_uiMaxCUWidth[layer]  = &m_apcLayerCfg[layer]->m_uiMaxCUWidth;
+    cfg_uiMaxCUHeight[layer] = &m_apcLayerCfg[layer]->m_uiMaxCUHeight;
+    cfg_uiMaxCUDepth[layer]  = &m_apcLayerCfg[layer]->m_uiMaxCUDepth;
 
     // transfom unit (TU) definition.
-    cfg_uiQuadtreeTULog2MaxSize[layer] = &m_acLayerCfg[layer].m_uiQuadtreeTULog2MaxSize;
-    cfg_uiQuadtreeTULog2MinSize[layer] = &m_acLayerCfg[layer].m_uiQuadtreeTULog2MinSize;
-
-    cfg_uiQuadtreeTUMaxDepthInter[layer] = &m_acLayerCfg[layer].m_uiQuadtreeTUMaxDepthInter;
-    cfg_uiQuadtreeTUMaxDepthIntra[layer] = &m_acLayerCfg[layer].m_uiQuadtreeTUMaxDepthIntra;
-
-    cfg_numSamplePredRefLayers  [layer] = &m_acLayerCfg[layer].m_numSamplePredRefLayers;
+    cfg_uiQuadtreeTULog2MaxSize[layer] = &m_apcLayerCfg[layer]->m_uiQuadtreeTULog2MaxSize;
+    cfg_uiQuadtreeTULog2MinSize[layer] = &m_apcLayerCfg[layer]->m_uiQuadtreeTULog2MinSize;
+
+    cfg_uiQuadtreeTUMaxDepthInter[layer] = &m_apcLayerCfg[layer]->m_uiQuadtreeTUMaxDepthInter;
+    cfg_uiQuadtreeTUMaxDepthIntra[layer] = &m_apcLayerCfg[layer]->m_uiQuadtreeTUMaxDepthIntra;
+
+    cfg_numSamplePredRefLayers  [layer] = &m_apcLayerCfg[layer]->m_numSamplePredRefLayers;
     cfg_samplePredRefLayerIdsPtr[layer] = &cfg_samplePredRefLayerIds[layer];
-    cfg_numMotionPredRefLayers  [layer] = &m_acLayerCfg[layer].m_numMotionPredRefLayers;
+    cfg_numMotionPredRefLayers  [layer] = &m_apcLayerCfg[layer]->m_numMotionPredRefLayers;
     cfg_motionPredRefLayerIdsPtr[layer] = &cfg_motionPredRefLayerIds[layer];
-    cfg_numActiveRefLayers  [layer] = &m_acLayerCfg[layer].m_numActiveRefLayers;
+    cfg_numActiveRefLayers  [layer] = &m_apcLayerCfg[layer]->m_numActiveRefLayers;
     cfg_predLayerIdsPtr     [layer] = &cfg_predLayerIds[layer];
 
-    cfg_numRefLayerLocationOffsets [layer] = &m_acLayerCfg[layer].m_numRefLayerLocationOffsets;
-    cfg_waveFrontSynchro[layer]  = &m_acLayerCfg[layer].m_waveFrontSynchro;
-    for(Int i = 0; i < MAX_LAYERS; i++)
+    cfg_numRefLayerLocationOffsets [layer] = &m_apcLayerCfg[layer]->m_numRefLayerLocationOffsets;
+    cfg_waveFrontSynchro[layer]  = &m_apcLayerCfg[layer]->m_waveFrontSynchro;
+    for(Int i = 0; i < m_numLayers; i++)
     {
       cfg_refLocationOffsetLayerIdPtr  [layer] = &cfg_refLocationOffsetLayerId[layer];
@@ -932,27 +968,27 @@
     }
 #if RC_SHVC_HARMONIZATION
-    cfg_RCEnableRateControl[layer]   = &m_acLayerCfg[layer].m_RCEnableRateControl;
-    cfg_RCTargetBitRate[layer]       = &m_acLayerCfg[layer].m_RCTargetBitrate;
-    cfg_RCKeepHierarchicalBit[layer] = &m_acLayerCfg[layer].m_RCKeepHierarchicalBit;
-    cfg_RCLCULevelRC[layer]          = &m_acLayerCfg[layer].m_RCLCULevelRC;
-    cfg_RCUseLCUSeparateModel[layer] = &m_acLayerCfg[layer].m_RCUseLCUSeparateModel;
-    cfg_RCInitialQP[layer]           = &m_acLayerCfg[layer].m_RCInitialQP;
-    cfg_RCForceIntraQP[layer]        = &m_acLayerCfg[layer].m_RCForceIntraQP;
-#endif
-
-    cfg_InputBitDepth   [CHANNEL_TYPE_LUMA][layer] = &m_acLayerCfg[layer].m_inputBitDepth[CHANNEL_TYPE_LUMA];
-    cfg_InternalBitDepth[CHANNEL_TYPE_LUMA][layer] = &m_acLayerCfg[layer].m_internalBitDepth[CHANNEL_TYPE_LUMA];
-    cfg_OutputBitDepth  [CHANNEL_TYPE_LUMA][layer] = &m_acLayerCfg[layer].m_outputBitDepth[CHANNEL_TYPE_LUMA];
-    cfg_InternalBitDepth[CHANNEL_TYPE_CHROMA][layer] = &m_acLayerCfg[layer].m_internalBitDepth[CHANNEL_TYPE_CHROMA];
-    cfg_InputBitDepth   [CHANNEL_TYPE_CHROMA][layer] = &m_acLayerCfg[layer].m_inputBitDepth[CHANNEL_TYPE_CHROMA];
-    cfg_OutputBitDepth  [CHANNEL_TYPE_CHROMA][layer] = &m_acLayerCfg[layer].m_outputBitDepth[CHANNEL_TYPE_CHROMA];
-
-    cfg_maxTidIlRefPicsPlus1[layer] = &m_acLayerCfg[layer].m_maxTidIlRefPicsPlus1;
+    cfg_RCEnableRateControl[layer]   = &m_apcLayerCfg[layer]->m_RCEnableRateControl;
+    cfg_RCTargetBitRate[layer]       = &m_apcLayerCfg[layer]->m_RCTargetBitrate;
+    cfg_RCKeepHierarchicalBit[layer] = &m_apcLayerCfg[layer]->m_RCKeepHierarchicalBit;
+    cfg_RCLCULevelRC[layer]          = &m_apcLayerCfg[layer]->m_RCLCULevelRC;
+    cfg_RCUseLCUSeparateModel[layer] = &m_apcLayerCfg[layer]->m_RCUseLCUSeparateModel;
+    cfg_RCInitialQP[layer]           = &m_apcLayerCfg[layer]->m_RCInitialQP;
+    cfg_RCForceIntraQP[layer]        = &m_apcLayerCfg[layer]->m_RCForceIntraQP;
+#endif
+
+    cfg_InputBitDepth   [CHANNEL_TYPE_LUMA][layer] = &m_apcLayerCfg[layer]->m_inputBitDepth[CHANNEL_TYPE_LUMA];
+    cfg_InternalBitDepth[CHANNEL_TYPE_LUMA][layer] = &m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_LUMA];
+    cfg_OutputBitDepth  [CHANNEL_TYPE_LUMA][layer] = &m_apcLayerCfg[layer]->m_outputBitDepth[CHANNEL_TYPE_LUMA];
+    cfg_InternalBitDepth[CHANNEL_TYPE_CHROMA][layer] = &m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_CHROMA];
+    cfg_InputBitDepth   [CHANNEL_TYPE_CHROMA][layer] = &m_apcLayerCfg[layer]->m_inputBitDepth[CHANNEL_TYPE_CHROMA];
+    cfg_OutputBitDepth  [CHANNEL_TYPE_CHROMA][layer] = &m_apcLayerCfg[layer]->m_outputBitDepth[CHANNEL_TYPE_CHROMA];
+
+    cfg_maxTidIlRefPicsPlus1[layer] = &m_apcLayerCfg[layer]->m_maxTidIlRefPicsPlus1;
 #if AUXILIARY_PICTURES
-    cfg_auxId[layer]                = &m_acLayerCfg[layer].m_auxId; 
-#endif
-    cfg_layerSwitchOffBegin[layer]  = &m_acLayerCfg[layer].m_layerSwitchOffBegin;
-    cfg_layerSwitchOffEnd[layer]    = &m_acLayerCfg[layer].m_layerSwitchOffEnd;
-    cfg_layerPTLIdx[layer]          = &m_acLayerCfg[layer].m_layerPTLIdx; 
+    cfg_auxId[layer]                = &m_apcLayerCfg[layer]->m_auxId; 
+#endif
+    cfg_layerSwitchOffBegin[layer]  = &m_apcLayerCfg[layer]->m_layerSwitchOffBegin;
+    cfg_layerSwitchOffEnd[layer]    = &m_apcLayerCfg[layer]->m_layerSwitchOffEnd;
+    cfg_layerPTLIdx[layer]          = &m_apcLayerCfg[layer]->m_layerPTLIdx; 
   }
 
@@ -1064,101 +1100,101 @@
   // File, I/O and source parameters
 #if SVC_EXTENSION
-  ("InputFile%d,-i%d",                              cfg_InputFile,                      string(""), MAX_LAYERS, "original YUV input file name for layer %d")
-  ("ReconFile%d,-o%d",                              cfg_ReconFile,                      string(""), MAX_LAYERS, "reconstruction YUV input file name for layer %d")
-  ("LayerConfig%d,-lc%d",                           cfg_LayerCfgFile,                   string(""), MAX_LAYERS, "layer %d configuration file name")
-  ("SourceWidth%d,-wdt%d",                          cfg_SourceWidth,                             0, MAX_LAYERS, "Source picture width for layer %d")
-  ("SourceHeight%d,-hgt%d",                         cfg_SourceHeight,                            0, MAX_LAYERS, "Source picture height for layer %d")
-  ("FrameRate%d,-fr%d",                             cfg_FrameRate,                               0, MAX_LAYERS, "Frame rate for layer %d")
-  ("LambdaModifier%d,-LM%d",                        m_adLambdaModifier,                Double(1.0), MAX_TLAYER, "Lambda modifier for temporal layer %d")
-  ("RepFormatIdx%d",                                cfg_repFormatIdx,                           -1, MAX_LAYERS, "Index to the representation format structure used from the VPS")
-  ("LayerId%d",                                     cfg_layerId,                                -1, MAX_LAYERS,  "Layer id")
-
-  ("NumSamplePredRefLayers%d",                      cfg_numSamplePredRefLayers,                 -1, MAX_LAYERS, "Number of sample prediction reference layers")
-  ("SamplePredRefLayerIds%d",                       cfg_samplePredRefLayerIdsPtr,       string(""), MAX_LAYERS, "sample pred reference layer IDs")
-  ("NumMotionPredRefLayers%d",                      cfg_numMotionPredRefLayers,                 -1, MAX_LAYERS, "Number of motion prediction reference layers")
-  ("MotionPredRefLayerIds%d",                       cfg_motionPredRefLayerIdsPtr,       string(""), MAX_LAYERS, "motion pred reference layer IDs")
-  ("NumActiveRefLayers%d",                          cfg_numActiveRefLayers,                     -1, MAX_LAYERS, "Number of active reference layers")
-  ("PredLayerIds%d",                                cfg_predLayerIdsPtr,                string(""), MAX_LAYERS, "inter-layer prediction layer IDs")
-
-  ("NumLayers",                                     m_numLayers,                                             1, "Number of layers to code")  
-
-  ("NumLayerSets",                                  m_numLayerSets,                                          1, "Number of layer sets")
-  ("NumLayerInIdList%d",                            cfg_numLayerInIdList,            0, MAX_VPS_LAYER_IDX_PLUS1, "Number of layers in the set")
-  ("LayerSetLayerIdList%d",                         cfg_layerSetLayerIdListPtr, string(""), MAX_VPS_LAYER_IDX_PLUS1, "Layer IDs for the set")
-  ("NumAddLayerSets",                               m_numAddLayerSets,                                       0, "Number of additional layer sets")
-  ("NumHighestLayerIdx%d",                          cfg_numHighestLayerIdx,          0, MAX_VPS_LAYER_IDX_PLUS1, "Number of highest layer idx")
-  ("HighestLayerIdx%d",                             cfg_highestLayerIdxPtr, string(""), MAX_VPS_LAYER_IDX_PLUS1, "Highest layer idx for an additional layer set")
-
-  ("DefaultTargetOutputLayerIdc",                   m_defaultTargetOutputLayerIdc,                           1, "Default target output layers. 0: All layers are output layer, 1: Only highest layer is output layer, 2 or 3: No default output layers")
-  ("NumOutputLayerSets",                            m_numOutputLayerSets,                                    1, "Number of output layer sets excluding the 0-th output layer set")
-  ("NumOutputLayersInOutputLayerSet",               cfg_numOutputLayersInOutputLayerSet,         string(""), 1, "List containing number of output layers in the output layer sets")
-  ("ListOfOutputLayers%d",                          cfg_listOfOutputLayers, string(""), MAX_VPS_LAYER_IDX_PLUS1, "Layer IDs for the set, in terms of layer ID in the output layer set Range: [0..NumLayersInOutputLayerSet-1]")
-  ("OutputLayerSetIdx",                             cfg_outputLayerSetIdx,                       string(""), 1, "Corresponding layer set index, only for non-default output layer sets")
+  ("InputFile%d,-i%d",                              cfg_InputFile,                    string(""), m_numLayers, "original YUV input file name for layer %d")
+  ("ReconFile%d,-o%d",                              cfg_ReconFile,                    string(""), m_numLayers, "reconstruction YUV input file name for layer %d")
+  ("LayerConfig%d,-lc%d",                           cfg_LayerCfgFile,                 string(""), m_numLayers, "layer %d configuration file name")
+  ("SourceWidth%d,-wdt%d",                          cfg_SourceWidth,                           0, m_numLayers, "Source picture width for layer %d")
+  ("SourceHeight%d,-hgt%d",                         cfg_SourceHeight,                          0, m_numLayers, "Source picture height for layer %d")
+  ("FrameRate%d,-fr%d",                             cfg_FrameRate,                             0, m_numLayers, "Frame rate for layer %d")
+  ("LambdaModifier%d,-LM%d",                        m_adLambdaModifier,               Double(1.0), MAX_TLAYER, "Lambda modifier for temporal layer %d")
+  ("RepFormatIdx%d",                                cfg_repFormatIdx,                         -1, m_numLayers, "Index to the representation format structure used from the VPS")
+  ("LayerId%d",                                     cfg_layerId,                              -1, m_numLayers,  "Layer id")
+
+  ("NumSamplePredRefLayers%d",                      cfg_numSamplePredRefLayers,               -1, m_numLayers, "Number of sample prediction reference layers")
+  ("SamplePredRefLayerIds%d",                       cfg_samplePredRefLayerIdsPtr,     string(""), m_numLayers, "sample pred reference layer IDs")
+  ("NumMotionPredRefLayers%d",                      cfg_numMotionPredRefLayers,               -1, m_numLayers, "Number of motion prediction reference layers")
+  ("MotionPredRefLayerIds%d",                       cfg_motionPredRefLayerIdsPtr,     string(""), m_numLayers, "motion pred reference layer IDs")
+  ("NumActiveRefLayers%d",                          cfg_numActiveRefLayers,                   -1, m_numLayers, "Number of active reference layers")
+  ("PredLayerIds%d",                                cfg_predLayerIdsPtr,              string(""), m_numLayers, "inter-layer prediction layer IDs")
+
+  ("NumLayers",                                     m_numLayers,                                            1, "Number of layers to code")  
+
+  ("NumLayerSets",                                  m_numLayerSets,                                         1, "Number of layer sets")
+  ("NumLayerInIdList%d",                            cfg_numLayerInIdList,          0, MAX_VPS_LAYER_IDX_PLUS1, "Number of layers in the set")
+  ("LayerSetLayerIdList%d",                   cfg_layerSetLayerIdListPtr, string(""), MAX_VPS_LAYER_IDX_PLUS1, "Layer IDs for the set")
+  ("NumAddLayerSets",                               m_numAddLayerSets,                                      0, "Number of additional layer sets")
+  ("NumHighestLayerIdx%d",                        cfg_numHighestLayerIdx,          0, MAX_VPS_LAYER_IDX_PLUS1, "Number of highest layer idx")
+  ("HighestLayerIdx%d",                           cfg_highestLayerIdxPtr, string(""), MAX_VPS_LAYER_IDX_PLUS1, "Highest layer idx for an additional layer set")
+
+  ("DefaultTargetOutputLayerIdc",                   m_defaultTargetOutputLayerIdc,                          1, "Default target output layers. 0: All layers are output layer, 1: Only highest layer is output layer, 2 or 3: No default output layers")
+  ("NumOutputLayerSets",                            m_numOutputLayerSets,                                   1, "Number of output layer sets excluding the 0-th output layer set")
+  ("NumOutputLayersInOutputLayerSet",               cfg_numOutputLayersInOutputLayerSet,        string(""), 1, "List containing number of output layers in the output layer sets")
+  ("ListOfOutputLayers%d",                        cfg_listOfOutputLayers, string(""), MAX_VPS_LAYER_IDX_PLUS1, "Layer IDs for the set, in terms of layer ID in the output layer set Range: [0..NumLayersInOutputLayerSet-1]")
+  ("OutputLayerSetIdx",                             cfg_outputLayerSetIdx,                      string(""), 1, "Corresponding layer set index, only for non-default output layer sets")
 #if AUXILIARY_PICTURES
-  ("AuxId%d",                                       cfg_auxId,                                   0, MAX_LAYERS, "Auxilary picture ID for layer %d (0: Not aux pic, 1: Alpha plane, 2: Depth picture, 3: Cb enh, 4: Cr enh")
-#endif
-  ("ExtendedPrecision%d",                           cfg_useExtendedPrecision,                false, MAX_LAYERS, "Increased internal accuracies to support high bit depths (not valid in V1 profiles)")
-  ("ConformanceMode%d",                             cfg_conformanceMode,                         0, MAX_LAYERS, "Window conformance mode (0: no cropping, 1:automatic padding, 2: padding, 3:cropping")
-  ("ConfLeft%d",                                    cfg_confWinLeft,                             0, MAX_LAYERS, "Deprecated alias of ConfWinLeft")
-  ("ConfRight%d",                                   cfg_confWinRight,                            0, MAX_LAYERS, "Deprecated alias of ConfWinRight")
-  ("ConfTop%d",                                     cfg_confWinTop,                              0, MAX_LAYERS, "Deprecated alias of ConfWinTop")
-  ("ConfBottom%d",                                  cfg_confWinBottom,                           0, MAX_LAYERS, "Deprecated alias of ConfWinBottom")
-  ("ConfWinLeft%d",                                 cfg_confWinLeft,                             0, MAX_LAYERS, "Left offset for window conformance mode 3")
-  ("ConfWinRight%d",                                cfg_confWinRight,                            0, MAX_LAYERS, "Right offset for window conformance mode 3")
-  ("ConfWinTop%d",                                  cfg_confWinTop,                              0, MAX_LAYERS, "Top offset for window conformance mode 3")
-  ("ConfWinBottom%d",                               cfg_confWinBottom,                           0, MAX_LAYERS, "Bottom offset for window conformance mode 3")
-  ("HorizontalPadding%d,-pdx%d",                    cfg_aiPadX,                                  0, MAX_LAYERS, "Horizontal source padding for conformance window mode 2")
-  ("VerticalPadding%d,-pdy%d",                      cfg_aiPadY,                                  0, MAX_LAYERS, "Vertical source padding for conformance window mode 2")
-  ("ScalabilityMask1",                              m_scalabilityMask[VIEW_ORDER_INDEX],                     0, "scalability_mask[1] (multiview)")
-  ("ScalabilityMask2",                              m_scalabilityMask[SCALABILITY_ID],                       1, "scalability_mask[2] (scalable)" )
+  ("AuxId%d",                                       cfg_auxId,                                 0, m_numLayers, "Auxilary picture ID for layer %d (0: Not aux pic, 1: Alpha plane, 2: Depth picture, 3: Cb enh, 4: Cr enh")
+#endif
+  ("ExtendedPrecision%d",                           cfg_useExtendedPrecision,              false, m_numLayers, "Increased internal accuracies to support high bit depths (not valid in V1 profiles)")
+  ("ConformanceMode%d",                             cfg_conformanceMode,                       0, m_numLayers, "Window conformance mode (0: no cropping, 1:automatic padding, 2: padding, 3:cropping")
+  ("ConfLeft%d",                                    cfg_confWinLeft,                           0, m_numLayers, "Deprecated alias of ConfWinLeft")
+  ("ConfRight%d",                                   cfg_confWinRight,                          0, m_numLayers, "Deprecated alias of ConfWinRight")
+  ("ConfTop%d",                                     cfg_confWinTop,                            0, m_numLayers, "Deprecated alias of ConfWinTop")
+  ("ConfBottom%d",                                  cfg_confWinBottom,                         0, m_numLayers, "Deprecated alias of ConfWinBottom")
+  ("ConfWinLeft%d",                                 cfg_confWinLeft,                           0, m_numLayers, "Left offset for window conformance mode 3")
+  ("ConfWinRight%d",                                cfg_confWinRight,                          0, m_numLayers, "Right offset for window conformance mode 3")
+  ("ConfWinTop%d",                                  cfg_confWinTop,                            0, m_numLayers, "Top offset for window conformance mode 3")
+  ("ConfWinBottom%d",                               cfg_confWinBottom,                         0, m_numLayers, "Bottom offset for window conformance mode 3")
+  ("HorizontalPadding%d,-pdx%d",                    cfg_aiPadX,                                0, m_numLayers, "Horizontal source padding for conformance window mode 2")
+  ("VerticalPadding%d,-pdy%d",                      cfg_aiPadY,                                0, m_numLayers, "Vertical source padding for conformance window mode 2")
+  ("ScalabilityMask1",                              m_scalabilityMask[VIEW_ORDER_INDEX],                    0, "scalability_mask[1] (multiview)")
+  ("ScalabilityMask2",                              m_scalabilityMask[SCALABILITY_ID],                      1, "scalability_mask[2] (scalable)" )
 #if AUXILIARY_PICTURES
-  ("ScalabilityMask3",                              m_scalabilityMask[AUX_ID],                               0, "scalability_mask[3] (auxiliary pictures)" )
-#endif
-  ("BitstreamFile,b",                               cfg_BitstreamFile, string(""), "Bitstream output file name")
-  ("NumRefLocationOffsets%d",                       cfg_numRefLayerLocationOffsets,              0, MAX_LAYERS,  "Number of reference layer offset sets ")
-  ("RefLocationOffsetLayerId%d",                    cfg_refLocationOffsetLayerIdPtr,    string(""), MAX_LAYERS, "Layer ID of reference location offset")
-  ("ScaledRefLayerLeftOffset%d",                    cfg_scaledRefLayerLeftOffsetPtr,    string(""), MAX_LAYERS, "Horizontal offset of top-left luma sample of scaled base layer picture with respect to"
+  ("ScalabilityMask3",                              m_scalabilityMask[AUX_ID],                              0, "scalability_mask[3] (auxiliary pictures)" )
+#endif
+  ("BitstreamFile,b",                               cfg_BitstreamFile,                             string(""), "Bitstream output file name")
+  ("NumRefLocationOffsets%d",                       cfg_numRefLayerLocationOffsets,            0, m_numLayers,  "Number of reference layer offset sets ")
+  ("RefLocationOffsetLayerId%d",                    cfg_refLocationOffsetLayerIdPtr,  string(""), m_numLayers, "Layer ID of reference location offset")
+  ("ScaledRefLayerLeftOffset%d",                    cfg_scaledRefLayerLeftOffsetPtr,  string(""), m_numLayers, "Horizontal offset of top-left luma sample of scaled base layer picture with respect to"
                                                                                                                 " top-left luma sample of the EL picture, in units of two luma samples")
-  ("ScaledRefLayerTopOffset%d",                     cfg_scaledRefLayerTopOffsetPtr,     string(""), MAX_LAYERS, "Vertical offset of top-left luma sample of scaled base layer picture with respect to"
+  ("ScaledRefLayerTopOffset%d",                     cfg_scaledRefLayerTopOffsetPtr,   string(""), m_numLayers, "Vertical offset of top-left luma sample of scaled base layer picture with respect to"
                                                                                                                 " top-left luma sample of the EL picture, in units of two luma samples")
-  ("ScaledRefLayerRightOffset%d",                   cfg_scaledRefLayerRightOffsetPtr,   string(""), MAX_LAYERS, "Horizontal offset of bottom-right luma sample of scaled base layer picture with respect to"
+  ("ScaledRefLayerRightOffset%d",                   cfg_scaledRefLayerRightOffsetPtr, string(""), m_numLayers, "Horizontal offset of bottom-right luma sample of scaled base layer picture with respect to"
                                                                                                                 " bottom-right luma sample of the EL picture, in units of two luma samples")
-  ("ScaledRefLayerBottomOffset%d",                  cfg_scaledRefLayerBottomOffsetPtr,  string(""), MAX_LAYERS, "Vertical offset of bottom-right luma sample of scaled base layer picture with respect to"
+  ("ScaledRefLayerBottomOffset%d",                  cfg_scaledRefLayerBottomOffsetPtr,string(""), m_numLayers, "Vertical offset of bottom-right luma sample of scaled base layer picture with respect to"
                                                                                                                 "  bottom-right luma sample of the EL picture, in units of two luma samples")
-  ("ScaledRefLayerOffsetPresentFlag%d",         cfg_scaledRefLayerOffsetPresentFlagPtr, string(""), MAX_LAYERS, "presense flag of scaled reference layer offsets")
-  ("RefRegionOffsetPresentFlag%d",                  cfg_refRegionOffsetPresentFlagPtr,  string(""), MAX_LAYERS, "presense flag of reference region offsets")
-  ("RefRegionLeftOffset%d",                         cfg_refRegionLeftOffsetPtr,         string(""), MAX_LAYERS, "Horizontal offset of top-left luma sample of ref region with respect to"
+  ("ScaledRefLayerOffsetPresentFlag%d",        cfg_scaledRefLayerOffsetPresentFlagPtr,string(""), m_numLayers, "presense flag of scaled reference layer offsets")
+  ("RefRegionOffsetPresentFlag%d",                  cfg_refRegionOffsetPresentFlagPtr,string(""), m_numLayers, "presense flag of reference region offsets")
+  ("RefRegionLeftOffset%d",                         cfg_refRegionLeftOffsetPtr,       string(""), m_numLayers, "Horizontal offset of top-left luma sample of ref region with respect to"
                                                                                                                 "  top-left luma sample of the BL picture, in units of two luma samples")
-  ("RefRegionTopOffset%d",                          cfg_refRegionTopOffsetPtr,          string(""), MAX_LAYERS, "Vertical offset of top-left luma sample of ref region with respect to"
+  ("RefRegionTopOffset%d",                          cfg_refRegionTopOffsetPtr,        string(""), m_numLayers, "Vertical offset of top-left luma sample of ref region with respect to"
                                                                                                                 "  top-left luma sample of the BL picture, in units of two luma samples")
-  ("RefRegionRightOffset%d",                        cfg_refRegionRightOffsetPtr,        string(""), MAX_LAYERS, "Horizontal offset of bottom-right luma sample of ref region with respect to"
+  ("RefRegionRightOffset%d",                        cfg_refRegionRightOffsetPtr,      string(""), m_numLayers, "Horizontal offset of bottom-right luma sample of ref region with respect to"
                                                                                                                 "  bottom-right luma sample of the BL picture, in units of two luma samples")
-  ("RefRegionBottomOffset%d",                       cfg_refRegionBottomOffsetPtr,       string(""), MAX_LAYERS, "Vertical offset of bottom-right luma sample of ref region with respect to"
+  ("RefRegionBottomOffset%d",                       cfg_refRegionBottomOffsetPtr,     string(""), m_numLayers, "Vertical offset of bottom-right luma sample of ref region with respect to"
                                                                                                                 "  bottom-right luma sample of the BL picture, in units of two luma samples")
-  ("ResamplePhaseSetPresentFlag%d",                 cfg_resamplePhaseSetPresentFlagPtr, string(""), MAX_LAYERS, "presense flag of resample phase set")
-  ("PhaseHorLuma%d",                                cfg_phaseHorLumaPtr,                string(""), MAX_LAYERS, "luma shift in the horizontal direction used in resampling proces")
-  ("PhaseVerLuma%d",                                cfg_phaseVerLumaPtr,                string(""), MAX_LAYERS, "luma shift in the vertical   direction used in resampling proces")
-  ("PhaseHorChroma%d",                              cfg_phaseHorChromaPtr,              string(""), MAX_LAYERS, "chroma shift in the horizontal direction used in resampling proces")
-  ("PhaseVerChroma%d",                              cfg_phaseVerChromaPtr,              string(""), MAX_LAYERS, "chroma shift in the vertical   direction used in resampling proces")
+  ("ResamplePhaseSetPresentFlag%d",                cfg_resamplePhaseSetPresentFlagPtr,string(""), m_numLayers, "presense flag of resample phase set")
+  ("PhaseHorLuma%d",                                cfg_phaseHorLumaPtr,              string(""), m_numLayers, "luma shift in the horizontal direction used in resampling proces")
+  ("PhaseVerLuma%d",                                cfg_phaseVerLumaPtr,              string(""), m_numLayers, "luma shift in the vertical   direction used in resampling proces")
+  ("PhaseHorChroma%d",                              cfg_phaseHorChromaPtr,            string(""), m_numLayers, "chroma shift in the horizontal direction used in resampling proces")
+  ("PhaseVerChroma%d",                              cfg_phaseVerChromaPtr,            string(""), m_numLayers, "chroma shift in the vertical   direction used in resampling proces")
 #if Q0074_COLOUR_REMAPPING_SEI
-  ("SEIColourRemappingInfoFileRoot%d",              cfg_colourRemapSEIFileRoot,           string(""), MAX_LAYERS, "Colour Remapping Information SEI parameters file name for layer %d")
-#endif
-  ("InputBitDepth%d",                                cfg_InputBitDepth[CHANNEL_TYPE_LUMA],      8, MAX_LAYERS, "Bit-depth of input file for layer %d")
-  ("InternalBitDepth%d",                             cfg_InternalBitDepth[CHANNEL_TYPE_LUMA],   0, MAX_LAYERS, "Bit-depth the codec operates at. (default:InputBitDepth) for layer %d "
+  ("SEIColourRemappingInfoFileRoot%d",              cfg_colourRemapSEIFileRoot,       string(""), m_numLayers, "Colour Remapping Information SEI parameters file name for layer %d")
+#endif
+  ("InputBitDepth%d",                                cfg_InputBitDepth[CHANNEL_TYPE_LUMA],     8, m_numLayers, "Bit-depth of input file for layer %d")
+  ("InternalBitDepth%d",                             cfg_InternalBitDepth[CHANNEL_TYPE_LUMA],  0, m_numLayers, "Bit-depth the codec operates at. (default:InputBitDepth) for layer %d "
                                                                                                                " If different to InputBitDepth, source data will be converted")
-  ("OutputBitDepth%d",                               cfg_OutputBitDepth[CHANNEL_TYPE_LUMA],     0, MAX_LAYERS, "Bit-depth of output file (default:InternalBitDepth)")
-  ("InputBitDepthC%d",                               cfg_InputBitDepth[CHANNEL_TYPE_CHROMA],    0, MAX_LAYERS, "As per InputBitDepth but for chroma component. (default:InputBitDepth) for layer %d")
-  ("InternalBitDepthC%d",                            cfg_InternalBitDepth[CHANNEL_TYPE_CHROMA], 0, MAX_LAYERS, "As per InternalBitDepth but for chroma component. (default:IntrenalBitDepth) for layer %d")
-  ("OutputBitDepthC%d",                              cfg_OutputBitDepth[CHANNEL_TYPE_CHROMA],   0, MAX_LAYERS, "As per OutputBitDepth but for chroma component. (default:InternalBitDepthC)")
+  ("OutputBitDepth%d",                               cfg_OutputBitDepth[CHANNEL_TYPE_LUMA],    0, m_numLayers, "Bit-depth of output file (default:InternalBitDepth)")
+  ("InputBitDepthC%d",                               cfg_InputBitDepth[CHANNEL_TYPE_CHROMA],   0, m_numLayers, "As per InputBitDepth but for chroma component. (default:InputBitDepth) for layer %d")
+  ("InternalBitDepthC%d",                            cfg_InternalBitDepth[CHANNEL_TYPE_CHROMA],0, m_numLayers, "As per InternalBitDepth but for chroma component. (default:IntrenalBitDepth) for layer %d")
+  ("OutputBitDepthC%d",                              cfg_OutputBitDepth[CHANNEL_TYPE_CHROMA],  0, m_numLayers, "As per OutputBitDepth but for chroma component. (default:InternalBitDepthC)")
 
   ("MaxTidRefPresentFlag",                           m_maxTidRefPresentFlag,                            false, "max_tid_ref_present_flag (0: not present, 1: present) " )
-  ("MaxTidIlRefPicsPlus1%d",                         cfg_maxTidIlRefPicsPlus1,                  7, MAX_LAYERS, "allowed maximum temporal_id for inter-layer prediction")
+  ("MaxTidIlRefPicsPlus1%d",                         cfg_maxTidIlRefPicsPlus1,                 7, m_numLayers, "allowed maximum temporal_id for inter-layer prediction")
   ("CrossLayerPictureTypeAlignFlag",                 m_crossLayerPictureTypeAlignFlag,                   true, "align picture type across layers" )  
   ("CrossLayerIrapAlignFlag",                        m_crossLayerIrapAlignFlag,                          true, "align IRAP across layers" )  
   ("CrossLayerAlignedIdrOnlyFlag",                   m_crossLayerAlignedIdrOnlyFlag,                     true, "only idr for IRAP across layers" )  
-  ("InterLayerWeightedPred",                          m_useInterLayerWeightedPred,                       false, "enable IL WP parameters estimation at encoder" )  
+  ("InterLayerWeightedPred",                          m_useInterLayerWeightedPred,                      false, "enable IL WP parameters estimation at encoder" )  
 #if AVC_BASE
-  ("NonHEVCBase,-nonhevc",                            m_nonHEVCBaseLayerFlag,                                0, "BL is available but not internal")
-  ("InputBLFile,-ibl",                                cfg_BLInputFile,                              string(""), "Base layer rec YUV input file name")
+  ("NonHEVCBase,-nonhevc",                            m_nonHEVCBaseLayerFlag,                               0, "BL is available but not internal")
+  ("InputBLFile,-ibl",                                cfg_BLInputFile,                             string(""), "Base layer rec YUV input file name")
 #endif
   ("EnableElRapB,-use-rap-b",                         m_elRapSliceBEnabled,                                 0, "Set ILP over base-layer I picture to B picture (default is P picture)")
@@ -1234,28 +1270,28 @@
   ("IntraConstraintFlag",                             tmpIntraConstraintFlag,                           false, "Value of general_intra_constraint_flag to use for RExt profiles (not used if an explicit RExt sub-profile is specified)")
   ("OnePictureOnlyConstraintFlag",                    tmpOnePictureOnlyConstraintFlag,                  false, "Value of general_one_picture_only_constraint_flag to use for RExt profiles (not used if an explicit RExt sub-profile is specified)")
-  ("LowerBitRateConstraintFlag",                      tmpLowerBitRateConstraintFlag,                      true, "Value of general_lower_bit_rate_constraint_flag to use for RExt profiles")
-
-  ("ProfileCompatibility%d",                          m_profileCompatibility, Profile::NONE, (MAX_NUM_LAYER_IDS + 1), "Compatible profile to be used when encoding")
-  ("ProgressiveSource%d",                             m_progressiveSourceFlagList,   false, (MAX_NUM_LAYER_IDS + 1), "Indicate that source is progressive")
-  ("InterlacedSource%d",                              m_interlacedSourceFlagList,    false, (MAX_NUM_LAYER_IDS + 1), "Indicate that source is interlaced")
-  ("NonPackedSource%d",                               m_nonPackedConstraintFlagList, false, (MAX_NUM_LAYER_IDS + 1), "Indicate that source does not contain frame packing")
-  ("FrameOnly%d",                                     m_frameOnlyConstraintFlagList, false, (MAX_NUM_LAYER_IDS + 1), "Indicate that the bitstream contains only frames")
+  ("LowerBitRateConstraintFlag",                      tmpLowerBitRateConstraintFlag,                     true, "Value of general_lower_bit_rate_constraint_flag to use for RExt profiles")
+
+  ("ProfileCompatibility%d",                   m_profileCompatibility, Profile::NONE, (MAX_NUM_LAYER_IDS + 1), "Compatible profile to be used when encoding")
+  ("ProgressiveSource%d",                       m_progressiveSourceFlagList,   false, (MAX_NUM_LAYER_IDS + 1), "Indicate that source is progressive")
+  ("InterlacedSource%d",                        m_interlacedSourceFlagList,    false, (MAX_NUM_LAYER_IDS + 1), "Indicate that source is interlaced")
+  ("NonPackedSource%d",                         m_nonPackedConstraintFlagList, false, (MAX_NUM_LAYER_IDS + 1), "Indicate that source does not contain frame packing")
+  ("FrameOnly%d",                               m_frameOnlyConstraintFlagList, false, (MAX_NUM_LAYER_IDS + 1), "Indicate that the bitstream contains only frames")
   
-  ("LayerPTLIndex%d",                                 cfg_layerPTLIdx,               0, MAX_VPS_LAYER_IDX_PLUS1, "Index of PTL for each layer")
-  ("ListOfProfileTierLevelOls%d",                     cfg_listOfLayerPTLOfOlss, string(""), MAX_VPS_OUTPUT_LAYER_SETS_PLUS1, "PTL Index for each layer in each OLS except the first OLS. The PTL index for layer in the first OLS is set to 1")
+  ("LayerPTLIndex%d",                                 cfg_layerPTLIdx,                         0, m_numLayers, "Index of PTL for each layer")
+  ("ListOfProfileTierLevelOls%d",       cfg_listOfLayerPTLOfOlss, string(""), MAX_VPS_OUTPUT_LAYER_SETS_PLUS1, "PTL Index for each layer in each OLS except the first OLS. The PTL index for layer in the first OLS is set to 1")
 
   // Unit definition parameters
-  ("MaxCUWidth%d",                                    cfg_uiMaxCUWidth,                       64u, MAX_LAYERS, "Maximum CU width")
-  ("MaxCUHeight%d",                                   cfg_uiMaxCUHeight,                      64u, MAX_LAYERS, "Maximum CU height")
+  ("MaxCUWidth%d",                                    cfg_uiMaxCUWidth,                      64u, m_numLayers, "Maximum CU width")
+  ("MaxCUHeight%d",                                   cfg_uiMaxCUHeight,                     64u, m_numLayers, "Maximum CU height")
   // todo: remove defaults from MaxCUSize
-  ("MaxCUSize%d,s",                                   cfg_uiMaxCUWidth,                       64u, MAX_LAYERS, "Maximum CU size")
-  ("MaxCUSize%d,s",                                   cfg_uiMaxCUHeight,                      64u, MAX_LAYERS, "Maximum CU size")
-  ("MaxPartitionDepth%d,h%d",                         cfg_uiMaxCUDepth,                        4u, MAX_LAYERS, "CU depth")
-
-  ("QuadtreeTULog2MaxSize%d",                         cfg_uiQuadtreeTULog2MaxSize,             5u, MAX_LAYERS, "Maximum TU size in logarithm base 2")
-  ("QuadtreeTULog2MinSize%d",                         cfg_uiQuadtreeTULog2MinSize,             2u, MAX_LAYERS, "Minimum TU size in logarithm base 2")
+  ("MaxCUSize%d,s",                                   cfg_uiMaxCUWidth,                      64u, m_numLayers, "Maximum CU size")
+  ("MaxCUSize%d,s",                                   cfg_uiMaxCUHeight,                     64u, m_numLayers, "Maximum CU size")
+  ("MaxPartitionDepth%d,h%d",                         cfg_uiMaxCUDepth,                       4u, m_numLayers, "CU depth")
+
+  ("QuadtreeTULog2MaxSize%d",                         cfg_uiQuadtreeTULog2MaxSize,            5u, m_numLayers, "Maximum TU size in logarithm base 2")
+  ("QuadtreeTULog2MinSize%d",                         cfg_uiQuadtreeTULog2MinSize,            2u, m_numLayers, "Minimum TU size in logarithm base 2")
                                                                                                
-  ("QuadtreeTUMaxDepthIntra%d",                       cfg_uiQuadtreeTUMaxDepthIntra,           3u, MAX_LAYERS, "Depth of TU tree for intra CUs")
-  ("QuadtreeTUMaxDepthInter%d",                       cfg_uiQuadtreeTUMaxDepthInter,           3u, MAX_LAYERS, "Depth of TU tree for inter CUs") 
+  ("QuadtreeTUMaxDepthIntra%d",                       cfg_uiQuadtreeTUMaxDepthIntra,          3u, m_numLayers, "Depth of TU tree for intra CUs")
+  ("QuadtreeTUMaxDepthInter%d",                       cfg_uiQuadtreeTUMaxDepthInter,          3u, m_numLayers, "Depth of TU tree for inter CUs") 
 #else
   ("Profile",                                         extendedProfile,                                   NONE, "Profile name to use for encoding. Use main (for main), main10 (for main10), main-still-picture, main-RExt (for Range Extensions profile), any of the RExt specific profile names, or none")
@@ -1291,5 +1327,5 @@
   // Coding structure paramters
 #if SVC_EXTENSION
-  ("IntraPeriod%d,-ip%d",                             cfg_IntraPeriod, -1, MAX_LAYERS, "intra period in frames for layer %d, (-1: only first frame)")
+  ("IntraPeriod%d,-ip%d",                             cfg_IntraPeriod,                        -1, m_numLayers, "intra period in frames for layer %d, (-1: only first frame)")
 #else
   ("IntraPeriod,-ip",                                 m_iIntraPeriod,                                      -1, "Intra period in frames, (-1: only first frame)")
@@ -1310,5 +1346,5 @@
 
 #if SVC_EXTENSION
-  ("LambdaModifier%d,-LM%d",                          m_adLambdaModifier, ( double )1.0, MAX_TLAYER, "Lambda modifier for temporal layer %d")
+  ("LambdaModifier%d,-LM%d",                          m_adLambdaModifier,           ( double )1.0, MAX_TLAYER, "Lambda modifier for temporal layer %d")
 #else
   // Mode decision parameters
@@ -1325,5 +1361,5 @@
   /* Quantization parameters */
 #if SVC_EXTENSION
-  ("QP%d,-q%d",                                       cfg_fQP,  30.0, MAX_LAYERS, "Qp value for layer %d, if value is float, QP is switched once during encoding")
+  ("QP%d,-q%d",                                                                   cfg_fQP,  30.0, m_numLayers, "Qp value for layer %d, if value is float, QP is switched once during encoding")
 #else
   ("QP,q",                                            m_fQP,                                             30.0, "Qp value, if value is float, QP is switched once during encoding")
@@ -1332,5 +1368,5 @@
   ("MaxDeltaQP,d",                                    m_iMaxDeltaQP,                                        0, "max dQp offset for block")
 #if SVC_EXTENSION
-  ("MaxCuDQPDepth%d,-dqd",                            cfg_maxCuDQPDepth,                        0, MAX_LAYERS, "max depth for a minimum CuDQP")
+  ("MaxCuDQPDepth%d,-dqd",                            cfg_maxCuDQPDepth,                       0, m_numLayers, "max depth for a minimum CuDQP")
 #else
   ("MaxCuDQPDepth,-dqd",                              m_iMaxCuDQPDepth,                                     0, "max depth for a minimum CuDQP")
@@ -1413,16 +1449,16 @@
   ("Log2ParallelMergeLevel",                          m_log2ParallelMergeLevel,                            2u, "Parallel merge estimation region")
     //deprecated copies of renamed tile parameters
-  ("UniformSpacingIdc",                               m_tileUniformSpacingFlag,                         false,      "deprecated alias of TileUniformSpacing")
+  ("UniformSpacingIdc",                               m_tileUniformSpacingFlag,                         false, "deprecated alias of TileUniformSpacing")
   ("ColumnWidthArray",                                cfg_ColumnWidth,                        cfg_ColumnWidth, "deprecated alias of TileColumnWidthArray")
   ("RowHeightArray",                                  cfg_RowHeight,                            cfg_RowHeight, "deprecated alias of TileRowHeightArray")
 
-  ("TileUniformSpacing",                              m_tileUniformSpacingFlag,                         false,      "Indicates that tile columns and rows are distributed uniformly")
-  ("NumTileColumnsMinus1",                            m_numTileColumnsMinus1,                               0,          "Number of tile columns in a picture minus 1")
-  ("NumTileRowsMinus1",                               m_numTileRowsMinus1,                                  0,          "Number of rows in a picture minus 1")
+  ("TileUniformSpacing",                              m_tileUniformSpacingFlag,                         false, "Indicates that tile columns and rows are distributed uniformly")
+  ("NumTileColumnsMinus1",                            m_numTileColumnsMinus1,                               0, "Number of tile columns in a picture minus 1")
+  ("NumTileRowsMinus1",                               m_numTileRowsMinus1,                                  0, "Number of rows in a picture minus 1")
   ("TileColumnWidthArray",                            cfg_ColumnWidth,                        cfg_ColumnWidth, "Array containing tile column width values in units of CTU")
   ("TileRowHeightArray",                              cfg_RowHeight,                            cfg_RowHeight, "Array containing tile row height values in units of CTU")
   ("LFCrossTileBoundaryFlag",                         m_bLFCrossTileBoundaryFlag,                        true, "1: cross-tile-boundary loop filtering. 0:non-cross-tile-boundary loop filtering")
 #if SVC_EXTENSION
-  ("WaveFrontSynchro%d",                              cfg_waveFrontSynchro,             0,  MAX_LAYERS,          "0: no synchro; 1 synchro with TR; 2 TRR etc")
+  ("WaveFrontSynchro%d",                              cfg_waveFrontSynchro,                   0,  m_numLayers, "0: no synchro; 1 synchro with TR; 2 TRR etc")
 #else
   ("WaveFrontSynchro",                                m_iWaveFrontSynchro,                                  0, "0: no synchro; 1 synchro with top-right-right")
@@ -1448,11 +1484,11 @@
 #endif
 #if RC_SHVC_HARMONIZATION
-  ("RateControl%d",                                   cfg_RCEnableRateControl, false, MAX_LAYERS, "Rate control: enable rate control for layer %d")
-  ("TargetBitrate%d",                                 cfg_RCTargetBitRate, 0, MAX_LAYERS, "Rate control: target bitrate for layer %d")
-  ("KeepHierarchicalBit%d",                           cfg_RCKeepHierarchicalBit, false, MAX_LAYERS, "Rate control: keep hierarchical bit allocation for layer %d")
-  ("LCULevelRateControl%d",                           cfg_RCLCULevelRC, true, MAX_LAYERS, "Rate control: LCU level RC")
-  ("RCLCUSeparateModel%d",                            cfg_RCUseLCUSeparateModel, true, MAX_LAYERS, "Rate control: Use LCU level separate R-lambda model")
-  ("InitialQP%d",                                     cfg_RCInitialQP, 0, MAX_LAYERS, "Rate control: initial QP")
-  ("RCForceIntraQP%d",                                cfg_RCForceIntraQP, false, MAX_LAYERS, "Rate control: force intra QP to be equal to initial QP")
+  ("RateControl%d",                                   cfg_RCEnableRateControl,             false, m_numLayers, "Rate control: enable rate control for layer %d")
+  ("TargetBitrate%d",                                 cfg_RCTargetBitRate,                     0, m_numLayers, "Rate control: target bitrate for layer %d")
+  ("KeepHierarchicalBit%d",                           cfg_RCKeepHierarchicalBit,           false, m_numLayers, "Rate control: keep hierarchical bit allocation for layer %d")
+  ("LCULevelRateControl%d",                           cfg_RCLCULevelRC,                     true, m_numLayers, "Rate control: LCU level RC")
+  ("RCLCUSeparateModel%d",                            cfg_RCUseLCUSeparateModel,            true, m_numLayers, "Rate control: Use LCU level separate R-lambda model")
+  ("InitialQP%d",                                     cfg_RCInitialQP,                         0, m_numLayers, "Rate control: initial QP")
+  ("RCForceIntraQP%d",                                cfg_RCForceIntraQP,                  false, m_numLayers, "Rate control: force intra QP to be equal to initial QP")
 #else
   ( "RateControl",                                    m_RCEnableRateControl,                            false, "Rate control: enable rate control" )
@@ -1676,26 +1712,26 @@
   ("SEITemporalMotionVectorPredictionConstraints",             m_TMVPConstraintsSEIEnabled,              0, "Control generation of TMVP constrants SEI message")
 #endif
-  ("AdaptiveResolutionChange",     m_adaptiveResolutionChange, 0, "Adaptive resolution change frame number. Should coincide with EL RAP picture. (0: disable)")
-  ("LayerSwitchOffBegin%d", cfg_layerSwitchOffBegin, 0, MAX_LAYERS, "Switch layer %d off after given poc")
-  ("LayerSwitchOffEnd%d", cfg_layerSwitchOffEnd, 0, MAX_LAYERS, "Switch layer %d on at given poc")
-  ("SkipPictureAtArcSwitch",     m_skipPictureAtArcSwitch, false, "Code the higher layer picture in ARC up-switching as a skip picture. (0: disable)")
+  ("AdaptiveResolutionChange",                                  m_adaptiveResolutionChange, 0, "Adaptive resolution change frame number. Should coincide with EL RAP picture. (0: disable)")
+  ("LayerSwitchOffBegin%d",                           cfg_layerSwitchOffBegin, 0, m_numLayers, "Switch layer %d off after given poc")
+  ("LayerSwitchOffEnd%d",                               cfg_layerSwitchOffEnd, 0, m_numLayers, "Switch layer %d on at given poc")
+  ("SkipPictureAtArcSwitch",                                  m_skipPictureAtArcSwitch, false, "Code the higher layer picture in ARC up-switching as a skip picture. (0: disable)")
 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
-  ("SEIInterLayerConstrainedTileSets", m_interLayerConstrainedTileSetsSEIEnabled, false, "Control generation of inter layer constrained tile sets SEI message")
-  ("IlNumSetsInMessage",               m_ilNumSetsInMessage,                         0u, "Number of inter layer constrained tile sets")
-  ("TileSetsArray",                    cfg_tileSets,                         string(""), "Array containing tile sets params (TopLeftTileIndex, BottonRightTileIndex and ilcIdc for each set) ")
-#endif
-  ("AltOutputLayerFlag",               m_altOutputLayerFlag,                      false, "Specifies the value of alt_output_layer_flag in VPS extension")
-  ("CrossLayerBLAFlag",                m_crossLayerBLAFlag,                       false, "Specifies the value of cross_layer_bla_flag in VPS")
+  ("SEIInterLayerConstrainedTileSets",       m_interLayerConstrainedTileSetsSEIEnabled, false, "Control generation of inter layer constrained tile sets SEI message")
+  ("IlNumSetsInMessage",                     m_ilNumSetsInMessage,                         0u, "Number of inter layer constrained tile sets")
+  ("TileSetsArray",                          cfg_tileSets,                         string(""), "Array containing tile sets params (TopLeftTileIndex, BottonRightTileIndex and ilcIdc for each set) ")
+#endif
+  ("AltOutputLayerFlag",                     m_altOutputLayerFlag,                      false, "Specifies the value of alt_output_layer_flag in VPS extension")
+  ("CrossLayerBLAFlag",                      m_crossLayerBLAFlag,                       false, "Specifies the value of cross_layer_bla_flag in VPS")
 #if CGS_3D_ASYMLUT
-  ("CGS",     m_nCGSFlag , 0, "whether CGS is enabled")
-  ("CGSMaxOctantDepth", m_nCGSMaxOctantDepth , 1, "max octant depth")
-  ("CGSMaxYPartNumLog",  m_nCGSMaxYPartNumLog2 , 2, "max Y part number ")
-  ("CGSLUTBit",     m_nCGSLUTBit , 12, "bit depth of CGS LUT")
-  ("CGSAdaptC",     m_nCGSAdaptiveChroma , 1, "adaptive chroma partition (only for the case of two chroma partitions)")
+  ("CGS",                                                                       m_nCGSFlag, 0, "whether CGS is enabled")
+  ("CGSMaxOctantDepth",                                               m_nCGSMaxOctantDepth, 1, "max octant depth")
+  ("CGSMaxYPartNumLog",                                              m_nCGSMaxYPartNumLog2, 2, "max Y part number ")
+  ("CGSLUTBit",                                                              m_nCGSLUTBit, 12, "bit depth of CGS LUT")
+  ("CGSAdaptC",                                                       m_nCGSAdaptiveChroma, 1, "adaptive chroma partition (only for the case of two chroma partitions)")
 #if R0179_ENC_OPT_3DLUT_SIZE
-  ("CGSSizeRDO",     m_nCGSLutSizeRDO , 0, "RDOpt selection of best table size (effective when large maximum table size such as 8x8x8 is used)")
-#endif
-#endif
-  ("InheritCodingStruct%d",m_inheritCodingStruct, 0, MAX_LAYERS, "Predicts the GOP structure of one layer for another layer")
+  ("CGSSizeRDO",                                                          m_nCGSLutSizeRDO, 0, "RDOpt selection of best table size (effective when large maximum table size such as 8x8x8 is used)")
+#endif
+#endif
+  ("InheritCodingStruct%d",                             m_inheritCodingStruct, 0, m_numLayers, "Predicts the GOP structure of one layer for another layer")
 #endif //SVC_EXTENSION
   ;
@@ -1709,5 +1745,5 @@
 
 #if SVC_EXTENSION
-  for (Int i=1; i<MAX_LAYERS; i++)
+  for (Int i=1; i<m_numLayers; i++)
   {
     for(Int j=1; j<MAX_GOP+1; j++)
@@ -1725,5 +1761,5 @@
 
 #if SVC_EXTENSION
-  for (Int i=1; i<MAX_LAYERS; i++)
+  for (Int i=1; i<m_numLayers; i++)
   {
     if(m_inheritCodingStruct[i] == 0)
@@ -1795,10 +1831,10 @@
   {
 #if SVC_EXTENSION
-    for(Int layer = 0; layer < MAX_LAYERS; layer++)
+    for(Int layer = 0; layer < m_numLayers; layer++)
     {
       //Frame height
-      m_acLayerCfg[layer].m_iSourceHeightOrg = m_acLayerCfg[layer].m_iSourceHeight;
+      m_apcLayerCfg[layer]->m_iSourceHeightOrg = m_apcLayerCfg[layer]->m_iSourceHeight;
       //Field height
-      m_acLayerCfg[layer].m_iSourceHeight = m_acLayerCfg[layer].m_iSourceHeight >> 1;
+      m_apcLayerCfg[layer]->m_iSourceHeight = m_apcLayerCfg[layer]->m_iSourceHeight >> 1;
     }
 #else
@@ -1870,34 +1906,34 @@
   /* rules for input, output and internal bitdepths as per help text */
 #if SVC_EXTENSION
-  for( Int layer = 0; layer < MAX_LAYERS; layer++ )
-  {
-    if( m_acLayerCfg[layer].m_layerId < 0 )
-    {
-      m_acLayerCfg[layer].m_layerId = layer;
-    }
-
-    m_acLayerCfg[layer].m_MSBExtendedBitDepth[CHANNEL_TYPE_LUMA  ] = m_acLayerCfg[layer].m_inputBitDepth      [CHANNEL_TYPE_LUMA  ];
-    m_acLayerCfg[layer].m_MSBExtendedBitDepth[CHANNEL_TYPE_CHROMA] = m_acLayerCfg[layer].m_MSBExtendedBitDepth[CHANNEL_TYPE_LUMA  ];
-
-    if (m_acLayerCfg[layer].m_internalBitDepth   [CHANNEL_TYPE_LUMA  ] == 0) { m_acLayerCfg[layer].m_internalBitDepth   [CHANNEL_TYPE_LUMA  ] = m_acLayerCfg[layer].m_MSBExtendedBitDepth[CHANNEL_TYPE_LUMA  ]; }
-    if (m_acLayerCfg[layer].m_internalBitDepth   [CHANNEL_TYPE_CHROMA] == 0) { m_acLayerCfg[layer].m_internalBitDepth   [CHANNEL_TYPE_CHROMA] = m_acLayerCfg[layer].m_internalBitDepth   [CHANNEL_TYPE_LUMA  ]; }
-    if (m_acLayerCfg[layer].m_inputBitDepth      [CHANNEL_TYPE_CHROMA] == 0) { m_acLayerCfg[layer].m_inputBitDepth      [CHANNEL_TYPE_CHROMA] = m_acLayerCfg[layer].m_inputBitDepth      [CHANNEL_TYPE_LUMA  ]; }
-    if (m_acLayerCfg[layer].m_outputBitDepth     [CHANNEL_TYPE_LUMA  ] == 0) { m_acLayerCfg[layer].m_outputBitDepth     [CHANNEL_TYPE_LUMA  ] = m_acLayerCfg[layer].m_internalBitDepth   [CHANNEL_TYPE_LUMA  ]; }
-    if (m_acLayerCfg[layer].m_outputBitDepth     [CHANNEL_TYPE_CHROMA] == 0) { m_acLayerCfg[layer].m_outputBitDepth     [CHANNEL_TYPE_CHROMA] = m_acLayerCfg[layer].m_internalBitDepth   [CHANNEL_TYPE_CHROMA]; }
-
-    m_acLayerCfg[layer].m_InputChromaFormatIDC = numberToChromaFormat(tmpInputChromaFormat);
-    m_acLayerCfg[layer].m_chromaFormatIDC      = ((tmpChromaFormat == 0) ? (m_acLayerCfg[layer].m_InputChromaFormatIDC) : (numberToChromaFormat(tmpChromaFormat)));
-
-    m_acLayerCfg[layer].m_highPrecisionOffsetsEnabledFlag = false;
-    m_acLayerCfg[layer].m_extendedPrecisionProcessingFlag = false;
-
-    if( m_acLayerCfg[layer].m_layerSwitchOffBegin < m_acLayerCfg[layer].m_layerSwitchOffEnd )
-    {
-      if( m_iGOPSize > 0 && (m_acLayerCfg[layer].m_layerSwitchOffBegin % m_iGOPSize) != 0 )
+  for( Int layer = 0; layer < m_numLayers; layer++ )
+  {
+    if( m_apcLayerCfg[layer]->m_layerId < 0 )
+    {
+      m_apcLayerCfg[layer]->m_layerId = layer;
+    }
+
+    m_apcLayerCfg[layer]->m_MSBExtendedBitDepth[CHANNEL_TYPE_LUMA  ] = m_apcLayerCfg[layer]->m_inputBitDepth      [CHANNEL_TYPE_LUMA  ];
+    m_apcLayerCfg[layer]->m_MSBExtendedBitDepth[CHANNEL_TYPE_CHROMA] = m_apcLayerCfg[layer]->m_MSBExtendedBitDepth[CHANNEL_TYPE_LUMA  ];
+
+    if (m_apcLayerCfg[layer]->m_internalBitDepth   [CHANNEL_TYPE_LUMA  ] == 0) { m_apcLayerCfg[layer]->m_internalBitDepth   [CHANNEL_TYPE_LUMA  ] = m_apcLayerCfg[layer]->m_MSBExtendedBitDepth[CHANNEL_TYPE_LUMA  ]; }
+    if (m_apcLayerCfg[layer]->m_internalBitDepth   [CHANNEL_TYPE_CHROMA] == 0) { m_apcLayerCfg[layer]->m_internalBitDepth   [CHANNEL_TYPE_CHROMA] = m_apcLayerCfg[layer]->m_internalBitDepth   [CHANNEL_TYPE_LUMA  ]; }
+    if (m_apcLayerCfg[layer]->m_inputBitDepth      [CHANNEL_TYPE_CHROMA] == 0) { m_apcLayerCfg[layer]->m_inputBitDepth      [CHANNEL_TYPE_CHROMA] = m_apcLayerCfg[layer]->m_inputBitDepth      [CHANNEL_TYPE_LUMA  ]; }
+    if (m_apcLayerCfg[layer]->m_outputBitDepth     [CHANNEL_TYPE_LUMA  ] == 0) { m_apcLayerCfg[layer]->m_outputBitDepth     [CHANNEL_TYPE_LUMA  ] = m_apcLayerCfg[layer]->m_internalBitDepth   [CHANNEL_TYPE_LUMA  ]; }
+    if (m_apcLayerCfg[layer]->m_outputBitDepth     [CHANNEL_TYPE_CHROMA] == 0) { m_apcLayerCfg[layer]->m_outputBitDepth     [CHANNEL_TYPE_CHROMA] = m_apcLayerCfg[layer]->m_internalBitDepth   [CHANNEL_TYPE_CHROMA]; }
+
+    m_apcLayerCfg[layer]->m_InputChromaFormatIDC = numberToChromaFormat(tmpInputChromaFormat);
+    m_apcLayerCfg[layer]->m_chromaFormatIDC      = ((tmpChromaFormat == 0) ? (m_apcLayerCfg[layer]->m_InputChromaFormatIDC) : (numberToChromaFormat(tmpChromaFormat)));
+
+    m_apcLayerCfg[layer]->m_highPrecisionOffsetsEnabledFlag = false;
+    m_apcLayerCfg[layer]->m_extendedPrecisionProcessingFlag = false;
+
+    if( m_apcLayerCfg[layer]->m_layerSwitchOffBegin < m_apcLayerCfg[layer]->m_layerSwitchOffEnd )
+    {
+      if( m_iGOPSize > 0 && (m_apcLayerCfg[layer]->m_layerSwitchOffBegin % m_iGOPSize) != 0 )
       {
         printf("LayerSwitchOffBegin%d: Must be multiple of GOP size.\n", layer);
         exit(EXIT_FAILURE);
       }
-      if( m_acLayerCfg[layer].m_iIntraPeriod > 0 && (m_acLayerCfg[layer].m_layerSwitchOffEnd % m_acLayerCfg[layer].m_iIntraPeriod) != 0 )
+      if( m_apcLayerCfg[layer]->m_iIntraPeriod > 0 && (m_apcLayerCfg[layer]->m_layerSwitchOffEnd % m_apcLayerCfg[layer]->m_iIntraPeriod) != 0 )
       {
         printf("LayerSwitchOffEnd%d: Must be IRAP picture.\n", layer);
@@ -1906,14 +1942,14 @@
     }
 
-    m_acLayerCfg[layer].m_bitDepthConstraint = tmpBitDepthConstraint;
-    m_acLayerCfg[layer].m_intraConstraintFlag = tmpIntraConstraintFlag;
-    m_acLayerCfg[layer].m_lowerBitRateConstraintFlag = tmpLowerBitRateConstraintFlag;    
+    m_apcLayerCfg[layer]->m_bitDepthConstraint = tmpBitDepthConstraint;
+    m_apcLayerCfg[layer]->m_intraConstraintFlag = tmpIntraConstraintFlag;
+    m_apcLayerCfg[layer]->m_lowerBitRateConstraintFlag = tmpLowerBitRateConstraintFlag;    
 
     for (UInt channelType = 0; channelType < MAX_NUM_CHANNEL_TYPE; channelType++)
     {
-      m_acLayerCfg[layer].m_log2SaoOffsetScale[channelType] = 0;
+      m_apcLayerCfg[layer]->m_log2SaoOffsetScale[channelType] = 0;
     }
         
-    Int layerPTLIdx = m_acLayerCfg[layer].m_layerPTLIdx;
+    Int layerPTLIdx = m_apcLayerCfg[layer]->m_layerPTLIdx;
 
     if( extendedProfile[layerPTLIdx] >= 1000 && extendedProfile[layerPTLIdx] <= 2316 )
@@ -1921,11 +1957,11 @@
       m_profileList[layerPTLIdx] = Profile::MAINREXT;            
 
-      if( m_acLayerCfg[layer].m_bitDepthConstraint != 0 || tmpConstraintChromaFormat != 0)
+      if( m_apcLayerCfg[layer]->m_bitDepthConstraint != 0 || tmpConstraintChromaFormat != 0)
       {
         fprintf(stderr, "Error: The bit depth and chroma format constraints are not used when an explicit RExt profile is specified\n");
         exit(EXIT_FAILURE);
       }
-      m_acLayerCfg[layer].m_bitDepthConstraint  = (extendedProfile[layerPTLIdx]%100);
-      m_acLayerCfg[layer].m_intraConstraintFlag = (extendedProfile[layerPTLIdx]>=2000);
+      m_apcLayerCfg[layer]->m_bitDepthConstraint  = (extendedProfile[layerPTLIdx]%100);
+      m_apcLayerCfg[layer]->m_intraConstraintFlag = (extendedProfile[layerPTLIdx]>=2000);
       switch ((extendedProfile[layerPTLIdx]/100)%10)
       {
@@ -1948,10 +1984,10 @@
     if( m_profileList[layerPTLIdx] == Profile::HIGHTHROUGHPUTREXT )
     {
-      if( m_acLayerCfg[layer].m_bitDepthConstraint == 0 ) m_acLayerCfg[layer].m_bitDepthConstraint = 16;
-      m_acLayerCfg[layer].m_chromaFormatConstraint = (tmpConstraintChromaFormat == 0) ? CHROMA_444 : numberToChromaFormat(tmpConstraintChromaFormat);
+      if( m_apcLayerCfg[layer]->m_bitDepthConstraint == 0 ) m_apcLayerCfg[layer]->m_bitDepthConstraint = 16;
+      m_apcLayerCfg[layer]->m_chromaFormatConstraint = (tmpConstraintChromaFormat == 0) ? CHROMA_444 : numberToChromaFormat(tmpConstraintChromaFormat);
     }
     else if( m_profileList[layerPTLIdx] == Profile::MAINREXT )
     {
-      if( m_acLayerCfg[layer].m_bitDepthConstraint == 0 && tmpConstraintChromaFormat == 0 )
+      if( m_apcLayerCfg[layer]->m_bitDepthConstraint == 0 && tmpConstraintChromaFormat == 0 )
       {
         // produce a valid combination, if possible.
@@ -1964,16 +2000,16 @@
           m_log2MaxTransformSkipBlockSize!=2;
         const Bool bUsingChromaQPAdjustment= m_diffCuChromaQpOffsetDepth >= 0;
-        const Bool bUsingExtendedPrecision = m_acLayerCfg[layer].m_extendedPrecisionProcessingFlag;
-        m_acLayerCfg[layer].m_chromaFormatConstraint = NUM_CHROMA_FORMAT;
+        const Bool bUsingExtendedPrecision = m_apcLayerCfg[layer]->m_extendedPrecisionProcessingFlag;
+        m_apcLayerCfg[layer]->m_chromaFormatConstraint = NUM_CHROMA_FORMAT;
         automaticallySelectRExtProfile(bUsingGeneralRExtTools,
           bUsingChromaQPAdjustment,
           bUsingExtendedPrecision,
-          m_acLayerCfg[layer].m_intraConstraintFlag,
-          m_acLayerCfg[layer].m_bitDepthConstraint,
-          m_acLayerCfg[layer].m_chromaFormatConstraint,
-          m_acLayerCfg[layer].m_chromaFormatIDC==CHROMA_400 ? m_acLayerCfg[layer].m_internalBitDepth[CHANNEL_TYPE_LUMA] : std::max(m_acLayerCfg[layer].m_internalBitDepth[CHANNEL_TYPE_LUMA], m_acLayerCfg[layer].m_internalBitDepth[CHANNEL_TYPE_CHROMA]),
-          m_acLayerCfg[layer].m_chromaFormatIDC);
-      }
-      else if( m_acLayerCfg[layer].m_bitDepthConstraint == 0 || tmpConstraintChromaFormat == 0)
+          m_apcLayerCfg[layer]->m_intraConstraintFlag,
+          m_apcLayerCfg[layer]->m_bitDepthConstraint,
+          m_apcLayerCfg[layer]->m_chromaFormatConstraint,
+          m_apcLayerCfg[layer]->m_chromaFormatIDC==CHROMA_400 ? m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_LUMA] : std::max(m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_LUMA], m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_CHROMA]),
+          m_apcLayerCfg[layer]->m_chromaFormatIDC);
+      }
+      else if( m_apcLayerCfg[layer]->m_bitDepthConstraint == 0 || tmpConstraintChromaFormat == 0)
       {
         fprintf(stderr, "Error: The bit depth and chroma format constraints must either both be specified or both be configured automatically\n");
@@ -1982,11 +2018,11 @@
       else
       {
-        m_acLayerCfg[layer].m_chromaFormatConstraint = numberToChromaFormat(tmpConstraintChromaFormat);
+        m_apcLayerCfg[layer]->m_chromaFormatConstraint = numberToChromaFormat(tmpConstraintChromaFormat);
       }
     }
     else
     {
-      m_acLayerCfg[layer].m_chromaFormatConstraint = (tmpConstraintChromaFormat == 0) ? m_acLayerCfg[layer].m_chromaFormatIDC : numberToChromaFormat(tmpConstraintChromaFormat);
-      m_acLayerCfg[layer].m_bitDepthConstraint = (m_profileList[layerPTLIdx] == Profile::MAIN10 || m_profileList[layerPTLIdx] == Profile::SCALABLEMAIN10) ? 10 : 8;
+      m_apcLayerCfg[layer]->m_chromaFormatConstraint = (tmpConstraintChromaFormat == 0) ? m_apcLayerCfg[layer]->m_chromaFormatIDC : numberToChromaFormat(tmpConstraintChromaFormat);
+      m_apcLayerCfg[layer]->m_bitDepthConstraint = (m_profileList[layerPTLIdx] == Profile::MAIN10 || m_profileList[layerPTLIdx] == Profile::SCALABLEMAIN10) ? 10 : 8;
     }
   }
@@ -2115,8 +2151,8 @@
 
 #if SVC_EXTENSION
-  for(Int layer = 0; layer < MAX_LAYERS; layer++)
+  for(Int layer = 0; layer < m_numLayers; layer++)
   {
     // If number of scaled ref. layer offsets is non-zero, at least one of the offsets should be specified
-    if(m_acLayerCfg[layer].m_numRefLayerLocationOffsets)
+    if(m_apcLayerCfg[layer]->m_numRefLayerLocationOffsets)
     {
       assert( strcmp(cfg_refLocationOffsetLayerId[layer].c_str(),  ""));
@@ -2147,10 +2183,10 @@
     if(strcmp(cfg_refLocationOffsetLayerId[layer].c_str(),  ""))
     {
-      cfgStringToArray( &tempArray, cfg_refLocationOffsetLayerId[layer], m_acLayerCfg[layer].m_numRefLayerLocationOffsets, "RefLocationOffsetLayerId");
+      cfgStringToArray( &tempArray, cfg_refLocationOffsetLayerId[layer], m_apcLayerCfg[layer]->m_numRefLayerLocationOffsets, "RefLocationOffsetLayerId");
       if(tempArray)
       {
-        for(Int i = 0; i < m_acLayerCfg[layer].m_numRefLayerLocationOffsets; i++)
+        for(Int i = 0; i < m_apcLayerCfg[layer]->m_numRefLayerLocationOffsets; i++)
         {
-          m_acLayerCfg[layer].m_refLocationOffsetLayerId[i] = tempArray[i];
+          m_apcLayerCfg[layer]->m_refLocationOffsetLayerId[i] = tempArray[i];
         }
         delete [] tempArray; tempArray = NULL;
@@ -2161,10 +2197,10 @@
     if(strcmp(cfg_scaledRefLayerOffsetPresentFlag[layer].c_str(),  ""))
     {
-      cfgStringToArray( &tempArray, cfg_scaledRefLayerOffsetPresentFlag[layer], m_acLayerCfg[layer].m_numRefLayerLocationOffsets, "ScaledRefLayerOffsetPresentFlag");
+      cfgStringToArray( &tempArray, cfg_scaledRefLayerOffsetPresentFlag[layer], m_apcLayerCfg[layer]->m_numRefLayerLocationOffsets, "ScaledRefLayerOffsetPresentFlag");
       if(tempArray)
       {
-        for(Int i = 0; i < m_acLayerCfg[layer].m_numRefLayerLocationOffsets; i++)
+        for(Int i = 0; i < m_apcLayerCfg[layer]->m_numRefLayerLocationOffsets; i++)
         {
-          m_acLayerCfg[layer].m_scaledRefLayerOffsetPresentFlag[i] = tempArray[i];
+          m_apcLayerCfg[layer]->m_scaledRefLayerOffsetPresentFlag[i] = tempArray[i];
         }
         delete [] tempArray; tempArray = NULL;
@@ -2175,10 +2211,10 @@
     if(strcmp(cfg_scaledRefLayerLeftOffset[layer].c_str(),  ""))
     {
-      cfgStringToArray( &tempArray, cfg_scaledRefLayerLeftOffset[layer], m_acLayerCfg[layer].m_numRefLayerLocationOffsets, "LeftOffset");
+      cfgStringToArray( &tempArray, cfg_scaledRefLayerLeftOffset[layer], m_apcLayerCfg[layer]->m_numRefLayerLocationOffsets, "LeftOffset");
       if(tempArray)
       {
-        for(Int i = 0; i < m_acLayerCfg[layer].m_numRefLayerLocationOffsets; i++)
+        for(Int i = 0; i < m_apcLayerCfg[layer]->m_numRefLayerLocationOffsets; i++)
         {
-          m_acLayerCfg[layer].m_scaledRefLayerLeftOffset[i] = tempArray[i];
+          m_apcLayerCfg[layer]->m_scaledRefLayerLeftOffset[i] = tempArray[i];
         }
         delete [] tempArray; tempArray = NULL;
@@ -2189,10 +2225,10 @@
     if(strcmp(cfg_scaledRefLayerTopOffset[layer].c_str(),  ""))
     {
-      cfgStringToArray( &tempArray, cfg_scaledRefLayerTopOffset[layer], m_acLayerCfg[layer].m_numRefLayerLocationOffsets, "TopOffset");
+      cfgStringToArray( &tempArray, cfg_scaledRefLayerTopOffset[layer], m_apcLayerCfg[layer]->m_numRefLayerLocationOffsets, "TopOffset");
       if(tempArray)
       {
-        for(Int i = 0; i < m_acLayerCfg[layer].m_numRefLayerLocationOffsets; i++)
+        for(Int i = 0; i < m_apcLayerCfg[layer]->m_numRefLayerLocationOffsets; i++)
         {
-          m_acLayerCfg[layer].m_scaledRefLayerTopOffset[i] = tempArray[i];
+          m_apcLayerCfg[layer]->m_scaledRefLayerTopOffset[i] = tempArray[i];
         }
         delete [] tempArray; tempArray = NULL;
@@ -2203,10 +2239,10 @@
     if(strcmp(cfg_scaledRefLayerRightOffset[layer].c_str(),  ""))
     {
-      cfgStringToArray( &tempArray, cfg_scaledRefLayerRightOffset[layer], m_acLayerCfg[layer].m_numRefLayerLocationOffsets, "RightOffset");
+      cfgStringToArray( &tempArray, cfg_scaledRefLayerRightOffset[layer], m_apcLayerCfg[layer]->m_numRefLayerLocationOffsets, "RightOffset");
       if(tempArray)
       {
-        for(Int i = 0; i < m_acLayerCfg[layer].m_numRefLayerLocationOffsets; i++)
+        for(Int i = 0; i < m_apcLayerCfg[layer]->m_numRefLayerLocationOffsets; i++)
         {
-          m_acLayerCfg[layer].m_scaledRefLayerRightOffset[i] = tempArray[i];
+          m_apcLayerCfg[layer]->m_scaledRefLayerRightOffset[i] = tempArray[i];
         }
         delete [] tempArray; tempArray = NULL;
@@ -2217,10 +2253,10 @@
     if(strcmp(cfg_scaledRefLayerBottomOffset[layer].c_str(),  ""))
     {
-      cfgStringToArray( &tempArray, cfg_scaledRefLayerBottomOffset[layer], m_acLayerCfg[layer].m_numRefLayerLocationOffsets, "BottomOffset");
+      cfgStringToArray( &tempArray, cfg_scaledRefLayerBottomOffset[layer], m_apcLayerCfg[layer]->m_numRefLayerLocationOffsets, "BottomOffset");
       if(tempArray)
       {
-        for(Int i = 0; i < m_acLayerCfg[layer].m_numRefLayerLocationOffsets; i++)
+        for(Int i = 0; i < m_apcLayerCfg[layer]->m_numRefLayerLocationOffsets; i++)
         {
-          m_acLayerCfg[layer].m_scaledRefLayerBottomOffset[i] = tempArray[i];
+          m_apcLayerCfg[layer]->m_scaledRefLayerBottomOffset[i] = tempArray[i];
         }
         delete [] tempArray; tempArray = NULL;
@@ -2231,10 +2267,10 @@
     if(strcmp(cfg_refRegionOffsetPresentFlag[layer].c_str(),  ""))
     {
-      cfgStringToArray( &tempArray, cfg_refRegionOffsetPresentFlag[layer], m_acLayerCfg[layer].m_numRefLayerLocationOffsets, "RefRegionOffsetPresentFlag");
+      cfgStringToArray( &tempArray, cfg_refRegionOffsetPresentFlag[layer], m_apcLayerCfg[layer]->m_numRefLayerLocationOffsets, "RefRegionOffsetPresentFlag");
       if(tempArray)
       {
-        for(Int i = 0; i < m_acLayerCfg[layer].m_numRefLayerLocationOffsets; i++)
+        for(Int i = 0; i < m_apcLayerCfg[layer]->m_numRefLayerLocationOffsets; i++)
         {
-          m_acLayerCfg[layer].m_refRegionOffsetPresentFlag[i] = tempArray[i];
+          m_apcLayerCfg[layer]->m_refRegionOffsetPresentFlag[i] = tempArray[i];
         }
         delete [] tempArray; tempArray = NULL;
@@ -2245,10 +2281,10 @@
     if(strcmp(cfg_refRegionLeftOffset[layer].c_str(),  ""))
     {
-      cfgStringToArray( &tempArray, cfg_refRegionLeftOffset[layer], m_acLayerCfg[layer].m_numRefLayerLocationOffsets, "RefRegionLeftOffset");
+      cfgStringToArray( &tempArray, cfg_refRegionLeftOffset[layer], m_apcLayerCfg[layer]->m_numRefLayerLocationOffsets, "RefRegionLeftOffset");
       if(tempArray)
       {
-        for(Int i = 0; i < m_acLayerCfg[layer].m_numRefLayerLocationOffsets; i++)
+        for(Int i = 0; i < m_apcLayerCfg[layer]->m_numRefLayerLocationOffsets; i++)
         {
-          m_acLayerCfg[layer].m_refRegionLeftOffset[i] = tempArray[i];
+          m_apcLayerCfg[layer]->m_refRegionLeftOffset[i] = tempArray[i];
         }
         delete [] tempArray; tempArray = NULL;
@@ -2259,10 +2295,10 @@
     if(strcmp(cfg_refRegionTopOffset[layer].c_str(),  ""))
     {
-      cfgStringToArray( &tempArray, cfg_refRegionTopOffset[layer], m_acLayerCfg[layer].m_numRefLayerLocationOffsets, "RefRegionTopOffset");
+      cfgStringToArray( &tempArray, cfg_refRegionTopOffset[layer], m_apcLayerCfg[layer]->m_numRefLayerLocationOffsets, "RefRegionTopOffset");
       if(tempArray)
       {
-        for(Int i = 0; i < m_acLayerCfg[layer].m_numRefLayerLocationOffsets; i++)
+        for(Int i = 0; i < m_apcLayerCfg[layer]->m_numRefLayerLocationOffsets; i++)
         {
-          m_acLayerCfg[layer].m_refRegionTopOffset[i] = tempArray[i];
+          m_apcLayerCfg[layer]->m_refRegionTopOffset[i] = tempArray[i];
         }
         delete [] tempArray; tempArray = NULL;
@@ -2273,10 +2309,10 @@
     if(strcmp(cfg_refRegionRightOffset[layer].c_str(),  ""))
     {
-      cfgStringToArray( &tempArray, cfg_refRegionRightOffset[layer], m_acLayerCfg[layer].m_numRefLayerLocationOffsets, "RefRegionRightOffset");
+      cfgStringToArray( &tempArray, cfg_refRegionRightOffset[layer], m_apcLayerCfg[layer]->m_numRefLayerLocationOffsets, "RefRegionRightOffset");
       if(tempArray)
       {
-        for(Int i = 0; i < m_acLayerCfg[layer].m_numRefLayerLocationOffsets; i++)
+        for(Int i = 0; i < m_apcLayerCfg[layer]->m_numRefLayerLocationOffsets; i++)
         {
-          m_acLayerCfg[layer].m_refRegionRightOffset[i] = tempArray[i];
+          m_apcLayerCfg[layer]->m_refRegionRightOffset[i] = tempArray[i];
         }
         delete [] tempArray; tempArray = NULL;
@@ -2287,10 +2323,10 @@
     if(strcmp(cfg_refRegionBottomOffset[layer].c_str(),  ""))
     {
-      cfgStringToArray( &tempArray, cfg_refRegionBottomOffset[layer], m_acLayerCfg[layer].m_numRefLayerLocationOffsets, "RefRegionBottomOffset");
+      cfgStringToArray( &tempArray, cfg_refRegionBottomOffset[layer], m_apcLayerCfg[layer]->m_numRefLayerLocationOffsets, "RefRegionBottomOffset");
       if(tempArray)
       {
-        for(Int i = 0; i < m_acLayerCfg[layer].m_numRefLayerLocationOffsets; i++)
+        for(Int i = 0; i < m_apcLayerCfg[layer]->m_numRefLayerLocationOffsets; i++)
         {
-          m_acLayerCfg[layer].m_refRegionBottomOffset[i] = tempArray[i];
+          m_apcLayerCfg[layer]->m_refRegionBottomOffset[i] = tempArray[i];
         }
         delete [] tempArray; tempArray = NULL;
@@ -2298,5 +2334,5 @@
     }
 
-    Int numPhaseSet = m_acLayerCfg[layer].m_numRefLayerLocationOffsets;
+    Int numPhaseSet = m_apcLayerCfg[layer]->m_numRefLayerLocationOffsets;
 
     // Presense Flag //
@@ -2308,5 +2344,5 @@
         for(Int i = 0; i < numPhaseSet; i++)
         {
-          m_acLayerCfg[layer].m_resamplePhaseSetPresentFlag[i] = tempArray[i];
+          m_apcLayerCfg[layer]->m_resamplePhaseSetPresentFlag[i] = tempArray[i];
         }
         delete [] tempArray; tempArray = NULL;
@@ -2322,5 +2358,5 @@
         for(Int i = 0; i < numPhaseSet; i++)
         {
-          m_acLayerCfg[layer].m_phaseHorLuma[i] = tempArray[i];
+          m_apcLayerCfg[layer]->m_phaseHorLuma[i] = tempArray[i];
         }
         delete [] tempArray; tempArray = NULL;
@@ -2336,5 +2372,5 @@
         for(Int i = 0; i < numPhaseSet; i++)
         {
-          m_acLayerCfg[layer].m_phaseVerLuma[i] = tempArray[i];
+          m_apcLayerCfg[layer]->m_phaseVerLuma[i] = tempArray[i];
         }
         delete [] tempArray; tempArray = NULL;
@@ -2350,5 +2386,5 @@
         for(Int i = 0; i < numPhaseSet; i++)
         {
-          m_acLayerCfg[layer].m_phaseHorChroma[i] = tempArray[i];
+          m_apcLayerCfg[layer]->m_phaseHorChroma[i] = tempArray[i];
         }
         delete [] tempArray; tempArray = NULL;
@@ -2364,5 +2400,5 @@
         for(Int i = 0; i < numPhaseSet; i++)
         {
-          m_acLayerCfg[layer].m_phaseVerChroma[i] = tempArray[i];
+          m_apcLayerCfg[layer]->m_phaseVerChroma[i] = tempArray[i];
         }
         delete [] tempArray; tempArray = NULL;
@@ -2371,22 +2407,22 @@
 
     Char* pSamplePredRefLayerIds = cfg_samplePredRefLayerIds[layer].empty() ? NULL: strdup(cfg_samplePredRefLayerIds[layer].c_str());
-    if( m_acLayerCfg[layer].m_numSamplePredRefLayers > 0 )
+    if( m_apcLayerCfg[layer]->m_numSamplePredRefLayers > 0 )
     {
       char *samplePredRefLayerId;
       int  i=0;
-      m_acLayerCfg[layer].m_samplePredRefLayerIds = new Int[m_acLayerCfg[layer].m_numSamplePredRefLayers];
+      m_apcLayerCfg[layer]->m_samplePredRefLayerIds = new Int[m_apcLayerCfg[layer]->m_numSamplePredRefLayers];
       samplePredRefLayerId = strtok(pSamplePredRefLayerIds, " ,-");
       while(samplePredRefLayerId != NULL)
       {
-        if( i >= m_acLayerCfg[layer].m_numSamplePredRefLayers )
+        if( i >= m_apcLayerCfg[layer]->m_numSamplePredRefLayers )
         {
           printf( "NumSamplePredRefLayers%d: The number of columns whose width are defined is larger than the allowed number of columns.\n", layer );
           exit( EXIT_FAILURE );
         }
-        *( m_acLayerCfg[layer].m_samplePredRefLayerIds + i ) = atoi( samplePredRefLayerId );
+        *( m_apcLayerCfg[layer]->m_samplePredRefLayerIds + i ) = atoi( samplePredRefLayerId );
         samplePredRefLayerId = strtok(NULL, " ,-");
         i++;
       }
-      if( i < m_acLayerCfg[layer].m_numSamplePredRefLayers )
+      if( i < m_apcLayerCfg[layer]->m_numSamplePredRefLayers )
       {
         printf( "NumSamplePredRefLayers%d: The width of some columns is not defined.\n", layer );
@@ -2396,5 +2432,5 @@
     else
     {
-      m_acLayerCfg[layer].m_samplePredRefLayerIds = NULL;
+      m_apcLayerCfg[layer]->m_samplePredRefLayerIds = NULL;
     }
 
@@ -2406,22 +2442,22 @@
 
     Char* pMotionPredRefLayerIds = cfg_motionPredRefLayerIds[layer].empty() ? NULL: strdup(cfg_motionPredRefLayerIds[layer].c_str());
-    if( m_acLayerCfg[layer].m_numMotionPredRefLayers > 0 )
+    if( m_apcLayerCfg[layer]->m_numMotionPredRefLayers > 0 )
     {
       char *motionPredRefLayerId;
       int  i=0;
-      m_acLayerCfg[layer].m_motionPredRefLayerIds = new Int[m_acLayerCfg[layer].m_numMotionPredRefLayers];
+      m_apcLayerCfg[layer]->m_motionPredRefLayerIds = new Int[m_apcLayerCfg[layer]->m_numMotionPredRefLayers];
       motionPredRefLayerId = strtok(pMotionPredRefLayerIds, " ,-");
       while(motionPredRefLayerId != NULL)
       {
-        if( i >= m_acLayerCfg[layer].m_numMotionPredRefLayers )
+        if( i >= m_apcLayerCfg[layer]->m_numMotionPredRefLayers )
         {
           printf( "NumMotionPredRefLayers%d: The number of columns whose width are defined is larger than the allowed number of columns.\n", layer );
           exit( EXIT_FAILURE );
         }
-        *( m_acLayerCfg[layer].m_motionPredRefLayerIds + i ) = atoi( motionPredRefLayerId );
+        *( m_apcLayerCfg[layer]->m_motionPredRefLayerIds + i ) = atoi( motionPredRefLayerId );
         motionPredRefLayerId = strtok(NULL, " ,-");
         i++;
       }
-      if( i < m_acLayerCfg[layer].m_numMotionPredRefLayers )
+      if( i < m_apcLayerCfg[layer]->m_numMotionPredRefLayers )
       {
         printf( "NumMotionPredRefLayers%d: The width of some columns is not defined.\n", layer );
@@ -2431,5 +2467,5 @@
     else
     {
-      m_acLayerCfg[layer].m_motionPredRefLayerIds = NULL;
+      m_apcLayerCfg[layer]->m_motionPredRefLayerIds = NULL;
     }
 
@@ -2441,22 +2477,22 @@
 
     Char* pPredLayerIds = cfg_predLayerIds[layer].empty() ? NULL: strdup(cfg_predLayerIds[layer].c_str());
-    if( m_acLayerCfg[layer].m_numActiveRefLayers > 0 )
+    if( m_apcLayerCfg[layer]->m_numActiveRefLayers > 0 )
     {
       char *refLayerId;
       int  i=0;
-      m_acLayerCfg[layer].m_predLayerIds = new Int[m_acLayerCfg[layer].m_numActiveRefLayers];
+      m_apcLayerCfg[layer]->m_predLayerIds = new Int[m_apcLayerCfg[layer]->m_numActiveRefLayers];
       refLayerId = strtok(pPredLayerIds, " ,-");
       while(refLayerId != NULL)
       {
-        if( i >= m_acLayerCfg[layer].m_numActiveRefLayers )
+        if( i >= m_apcLayerCfg[layer]->m_numActiveRefLayers )
         {
           printf( "NumActiveRefLayers%d: The number of columns whose width are defined is larger than the allowed number of columns.\n", layer );
           exit( EXIT_FAILURE );
         }
-        *( m_acLayerCfg[layer].m_predLayerIds + i ) = atoi( refLayerId );
+        *( m_apcLayerCfg[layer]->m_predLayerIds + i ) = atoi( refLayerId );
         refLayerId = strtok(NULL, " ,-");
         i++;
       }
-      if( i < m_acLayerCfg[layer].m_numActiveRefLayers )
+      if( i < m_apcLayerCfg[layer]->m_numActiveRefLayers )
       {
         printf( "NumActiveRefLayers%d: The width of some columns is not defined.\n", layer );
@@ -2466,5 +2502,5 @@
     else
     {
-      m_acLayerCfg[layer].m_predLayerIds = NULL;
+      m_apcLayerCfg[layer]->m_predLayerIds = NULL;
     }
 
@@ -2474,5 +2510,5 @@
       pPredLayerIds = NULL;
     }
-  } //for(Int layer = 0; layer < MAX_LAYERS; layer++)
+  } //for(Int layer = 0; layer < m_numLayers; layer++)
 
   for (Int layerSet = 1; layerSet < m_numLayerSets; layerSet++)
@@ -2919,11 +2955,11 @@
   {
     UInt uiAddCUDepth  = 0;
-    while( (m_acLayerCfg[layerIdx].m_uiMaxCUWidth>>m_acLayerCfg[layerIdx].m_uiMaxCUDepth) > ( 1 << ( m_acLayerCfg[layerIdx].m_uiQuadtreeTULog2MinSize + uiAddCUDepth )  ) )
+    while( (m_apcLayerCfg[layerIdx]->m_uiMaxCUWidth>>m_apcLayerCfg[layerIdx]->m_uiMaxCUDepth) > ( 1 << ( m_apcLayerCfg[layerIdx]->m_uiQuadtreeTULog2MinSize + uiAddCUDepth )  ) )
     {
       uiAddCUDepth++;
     }
 
-    m_acLayerCfg[layerIdx].m_uiMaxTotalCUDepth = m_acLayerCfg[layerIdx].m_uiMaxCUDepth + uiAddCUDepth + getMaxCUDepthOffset(m_acLayerCfg[layerIdx].m_chromaFormatIDC, m_acLayerCfg[layerIdx].m_uiQuadtreeTULog2MinSize); // if minimum TU larger than 4x4, allow for additional part indices for 4:2:2 SubTUs.    
-    m_acLayerCfg[layerIdx].m_uiLog2DiffMaxMinCodingBlockSize = m_acLayerCfg[layerIdx].m_uiMaxCUDepth - 1;
+    m_apcLayerCfg[layerIdx]->m_uiMaxTotalCUDepth = m_apcLayerCfg[layerIdx]->m_uiMaxCUDepth + uiAddCUDepth + getMaxCUDepthOffset(m_apcLayerCfg[layerIdx]->m_chromaFormatIDC, m_apcLayerCfg[layerIdx]->m_uiQuadtreeTULog2MinSize); // if minimum TU larger than 4x4, allow for additional part indices for 4:2:2 SubTUs.    
+    m_apcLayerCfg[layerIdx]->m_uiLog2DiffMaxMinCodingBlockSize = m_apcLayerCfg[layerIdx]->m_uiMaxCUDepth - 1;
   }
 #else  
@@ -2952,23 +2988,23 @@
 Void TAppEncCfg::xCheckParameter(UInt layerIdx)
 {
-  Bool m_extendedPrecisionProcessingFlag     = m_acLayerCfg[layerIdx].m_extendedPrecisionProcessingFlag;
-  Bool m_highPrecisionOffsetsEnabledFlag     = m_acLayerCfg[layerIdx].m_highPrecisionOffsetsEnabledFlag;
-  ChromaFormat m_chromaFormatIDC             = m_acLayerCfg[layerIdx].m_chromaFormatIDC;
-  ChromaFormat m_chromaFormatConstraint      = m_acLayerCfg[layerIdx].m_chromaFormatConstraint;
-  ChromaFormat m_InputChromaFormatIDC        = m_acLayerCfg[layerIdx].m_InputChromaFormatIDC;
-
-  Int m_inputBitDepth[]       = {m_acLayerCfg[layerIdx].m_inputBitDepth[CHANNEL_TYPE_LUMA],       m_acLayerCfg[layerIdx].m_inputBitDepth[CHANNEL_TYPE_CHROMA]};
-  Int m_internalBitDepth[]    = {m_acLayerCfg[layerIdx].m_internalBitDepth[CHANNEL_TYPE_LUMA],    m_acLayerCfg[layerIdx].m_internalBitDepth[CHANNEL_TYPE_CHROMA]};
-  Int m_MSBExtendedBitDepth[] = {m_acLayerCfg[layerIdx].m_MSBExtendedBitDepth[CHANNEL_TYPE_LUMA], m_acLayerCfg[layerIdx].m_MSBExtendedBitDepth[CHANNEL_TYPE_CHROMA]};  
-
-  m_log2SaoOffsetScale[CHANNEL_TYPE_LUMA]   = m_acLayerCfg[layerIdx].m_log2SaoOffsetScale[CHANNEL_TYPE_LUMA];
-  m_log2SaoOffsetScale[CHANNEL_TYPE_CHROMA] = m_acLayerCfg[layerIdx].m_log2SaoOffsetScale[CHANNEL_TYPE_CHROMA];
-
-  Int layerPTLIdx = m_acLayerCfg[layerIdx].m_layerPTLIdx;
+  Bool m_extendedPrecisionProcessingFlag     = m_apcLayerCfg[layerIdx]->m_extendedPrecisionProcessingFlag;
+  Bool m_highPrecisionOffsetsEnabledFlag     = m_apcLayerCfg[layerIdx]->m_highPrecisionOffsetsEnabledFlag;
+  ChromaFormat m_chromaFormatIDC             = m_apcLayerCfg[layerIdx]->m_chromaFormatIDC;
+  ChromaFormat m_chromaFormatConstraint      = m_apcLayerCfg[layerIdx]->m_chromaFormatConstraint;
+  ChromaFormat m_InputChromaFormatIDC        = m_apcLayerCfg[layerIdx]->m_InputChromaFormatIDC;
+
+  Int m_inputBitDepth[]       = {m_apcLayerCfg[layerIdx]->m_inputBitDepth[CHANNEL_TYPE_LUMA],       m_apcLayerCfg[layerIdx]->m_inputBitDepth[CHANNEL_TYPE_CHROMA]};
+  Int m_internalBitDepth[]    = {m_apcLayerCfg[layerIdx]->m_internalBitDepth[CHANNEL_TYPE_LUMA],    m_apcLayerCfg[layerIdx]->m_internalBitDepth[CHANNEL_TYPE_CHROMA]};
+  Int m_MSBExtendedBitDepth[] = {m_apcLayerCfg[layerIdx]->m_MSBExtendedBitDepth[CHANNEL_TYPE_LUMA], m_apcLayerCfg[layerIdx]->m_MSBExtendedBitDepth[CHANNEL_TYPE_CHROMA]};  
+
+  m_log2SaoOffsetScale[CHANNEL_TYPE_LUMA]   = m_apcLayerCfg[layerIdx]->m_log2SaoOffsetScale[CHANNEL_TYPE_LUMA];
+  m_log2SaoOffsetScale[CHANNEL_TYPE_CHROMA] = m_apcLayerCfg[layerIdx]->m_log2SaoOffsetScale[CHANNEL_TYPE_CHROMA];
+
+  Int layerPTLIdx = m_apcLayerCfg[layerIdx]->m_layerPTLIdx;
   Profile::Name m_profile             = m_profileList[layerPTLIdx];
-  UInt m_bitDepthConstraint           = m_acLayerCfg[layerIdx].m_bitDepthConstraint;
-  Bool m_intraConstraintFlag          = m_acLayerCfg[layerIdx].m_intraConstraintFlag;
-  Bool m_lowerBitRateConstraintFlag   = m_acLayerCfg[layerIdx].m_lowerBitRateConstraintFlag;
-  Bool m_onePictureOnlyConstraintFlag = m_acLayerCfg[layerIdx].m_onePictureOnlyConstraintFlag;
+  UInt m_bitDepthConstraint           = m_apcLayerCfg[layerIdx]->m_bitDepthConstraint;
+  Bool m_intraConstraintFlag          = m_apcLayerCfg[layerIdx]->m_intraConstraintFlag;
+  Bool m_lowerBitRateConstraintFlag   = m_apcLayerCfg[layerIdx]->m_lowerBitRateConstraintFlag;
+  Bool m_onePictureOnlyConstraintFlag = m_apcLayerCfg[layerIdx]->m_onePictureOnlyConstraintFlag;
 #else
 Void TAppEncCfg::xCheckParameter()
@@ -3323,5 +3359,5 @@
    * This permits the ability to omit a GOP structure specification */
 #if SVC_EXTENSION
-  if( m_acLayerCfg[0].m_iIntraPeriod == 1 && m_GOPList[0].m_POC == -1 )
+  if( m_apcLayerCfg[0]->m_iIntraPeriod == 1 && m_GOPList[0].m_POC == -1 )
   {
     m_GOPList[0] = GOPEntry();
@@ -3337,5 +3373,5 @@
   }
 
-  if (m_acLayerCfg[layerIdx].m_iIntraPeriod == 1 && m_EhGOPList[layerIdx][0].m_POC == -1) {
+  if (m_apcLayerCfg[layerIdx]->m_iIntraPeriod == 1 && m_EhGOPList[layerIdx][0].m_POC == -1) {
     m_EhGOPList[layerIdx][0] = GOPEntry();
     m_EhGOPList[layerIdx][0].m_QPFactor = 1;
@@ -3406,5 +3442,5 @@
 
   // verify layer configuration parameters
-  if(m_acLayerCfg[layerIdx].xCheckParameter(m_isField))
+  if(m_apcLayerCfg[layerIdx]->xCheckParameter(m_isField))
   {
     printf("\nError: invalid configuration parameter found in layer %d \n", layerIdx);
@@ -3413,5 +3449,5 @@
 
   // verify layer configuration parameters
-  Int m_iIntraPeriod = m_acLayerCfg[layerIdx].m_iIntraPeriod;
+  Int m_iIntraPeriod = m_apcLayerCfg[layerIdx]->m_iIntraPeriod;
 #endif
   if ( (m_iIntraPeriod != 1) && !m_loopFilterOffsetInPPS && (!m_bLoopFilterDisable) )
@@ -3726,5 +3762,5 @@
     for(UInt layer=0; layer<m_numLayers; layer++)
     {
-      if ( (m_acLayerCfg[layer].m_iIntraPeriod != 1) && !m_loopFilterOffsetInPPS && (!m_bLoopFilterDisable) )
+      if ( (m_apcLayerCfg[layer]->m_iIntraPeriod != 1) && !m_loopFilterOffsetInPPS && (!m_bLoopFilterDisable) )
       {
         for(Int i=0; i<m_iGOPSize; i++)
@@ -4018,11 +4054,11 @@
 
 #if SVC_EXTENSION // ToDo: it should be checked for the case when parameters are different for the layers
-  Int m_iSourceWidth = m_acLayerCfg[layerIdx].m_iSourceWidth;
-  Int m_iSourceHeight = m_acLayerCfg[layerIdx].m_iSourceHeight;
-  Int m_uiMaxCUWidth = m_acLayerCfg[layerIdx].m_uiMaxCUWidth;
-  Int m_uiMaxCUHeight = m_acLayerCfg[layerIdx].m_uiMaxCUHeight;
+  Int m_iSourceWidth = m_apcLayerCfg[layerIdx]->m_iSourceWidth;
+  Int m_iSourceHeight = m_apcLayerCfg[layerIdx]->m_iSourceHeight;
+  Int m_uiMaxCUWidth = m_apcLayerCfg[layerIdx]->m_uiMaxCUWidth;
+  Int m_uiMaxCUHeight = m_apcLayerCfg[layerIdx]->m_uiMaxCUHeight;
 
   Bool tileFlag = (m_numTileColumnsMinus1 > 0 || m_numTileRowsMinus1 > 0 );
-  Int m_iWaveFrontSynchro = m_acLayerCfg[layerIdx].m_waveFrontSynchro;
+  Int m_iWaveFrontSynchro = m_apcLayerCfg[layerIdx]->m_waveFrontSynchro;
   xConfirmPara( tileFlag && m_iWaveFrontSynchro,            "Tile and Wavefront can not be applied together");
 #endif
@@ -4157,12 +4193,12 @@
 
 #if RC_SHVC_HARMONIZATION
-  if ( m_acLayerCfg[layerIdx].m_RCEnableRateControl )
-  {
-    if ( m_acLayerCfg[layerIdx].m_RCForceIntraQP )
-    {
-      if ( m_acLayerCfg[layerIdx].m_RCInitialQP == 0 )
+  if ( m_apcLayerCfg[layerIdx]->m_RCEnableRateControl )
+  {
+    if ( m_apcLayerCfg[layerIdx]->m_RCForceIntraQP )
+    {
+      if ( m_apcLayerCfg[layerIdx]->m_RCInitialQP == 0 )
       {
         printf( "\nInitial QP for rate control is not specified. Reset not to use force intra QP!" );
-        m_acLayerCfg[layerIdx].m_RCForceIntraQP = false;
+        m_apcLayerCfg[layerIdx]->m_RCForceIntraQP = false;
       }
     }
@@ -4210,28 +4246,28 @@
 
 #if SVC_EXTENSION
-  xConfirmPara( (m_acLayerCfg[0].m_numSamplePredRefLayers != 0) && (m_acLayerCfg[0].m_numSamplePredRefLayers != -1), "Layer 0 cannot have any reference layers" );
+  xConfirmPara( (m_apcLayerCfg[0]->m_numSamplePredRefLayers != 0) && (m_apcLayerCfg[0]->m_numSamplePredRefLayers != -1), "Layer 0 cannot have any reference layers" );
   // NOTE: m_numSamplePredRefLayers  (for any layer) could be -1 (not signalled in cfg), in which case only the "previous layer" would be taken for reference
   if( layerIdx > 0 )
   {
-    xConfirmPara(m_acLayerCfg[layerIdx].m_numSamplePredRefLayers > layerIdx, "Cannot reference more layers than before current layer");
-    for(Int i = 0; i < m_acLayerCfg[layerIdx].m_numSamplePredRefLayers; i++)
-    {
-      xConfirmPara(m_acLayerCfg[layerIdx].m_samplePredRefLayerIds[i] > m_acLayerCfg[layerIdx].m_layerId, "Cannot reference higher layers");
-      xConfirmPara(m_acLayerCfg[layerIdx].m_samplePredRefLayerIds[i] == m_acLayerCfg[layerIdx].m_layerId, "Cannot reference the current layer itself");
-    }
-  }
-  xConfirmPara( (m_acLayerCfg[0].m_numMotionPredRefLayers != 0) && (m_acLayerCfg[0].m_numMotionPredRefLayers != -1), "Layer 0 cannot have any reference layers" );
+    xConfirmPara(m_apcLayerCfg[layerIdx]->m_numSamplePredRefLayers > layerIdx, "Cannot reference more layers than before current layer");
+    for(Int i = 0; i < m_apcLayerCfg[layerIdx]->m_numSamplePredRefLayers; i++)
+    {
+      xConfirmPara(m_apcLayerCfg[layerIdx]->m_samplePredRefLayerIds[i] > m_apcLayerCfg[layerIdx]->m_layerId, "Cannot reference higher layers");
+      xConfirmPara(m_apcLayerCfg[layerIdx]->m_samplePredRefLayerIds[i] == m_apcLayerCfg[layerIdx]->m_layerId, "Cannot reference the current layer itself");
+    }
+  }
+  xConfirmPara( (m_apcLayerCfg[0]->m_numMotionPredRefLayers != 0) && (m_apcLayerCfg[0]->m_numMotionPredRefLayers != -1), "Layer 0 cannot have any reference layers" );
   // NOTE: m_numMotionPredRefLayers  (for any layer) could be -1 (not signalled in cfg), in which case only the "previous layer" would be taken for reference
   if( layerIdx > 0 )
   {
-    xConfirmPara(m_acLayerCfg[layerIdx].m_numMotionPredRefLayers > layerIdx, "Cannot reference more layers than before current layer");
-    for(Int i = 0; i < m_acLayerCfg[layerIdx].m_numMotionPredRefLayers; i++)
-    {
-      xConfirmPara(m_acLayerCfg[layerIdx].m_motionPredRefLayerIds[i] > m_acLayerCfg[layerIdx].m_layerId, "Cannot reference higher layers");
-      xConfirmPara(m_acLayerCfg[layerIdx].m_motionPredRefLayerIds[i] == m_acLayerCfg[layerIdx].m_layerId, "Cannot reference the current layer itself");
-    }
-  }
-
-  xConfirmPara( (m_acLayerCfg[0].m_numActiveRefLayers != 0) && (m_acLayerCfg[0].m_numActiveRefLayers != -1), "Layer 0 cannot have any active reference layers" );
+    xConfirmPara(m_apcLayerCfg[layerIdx]->m_numMotionPredRefLayers > layerIdx, "Cannot reference more layers than before current layer");
+    for(Int i = 0; i < m_apcLayerCfg[layerIdx]->m_numMotionPredRefLayers; i++)
+    {
+      xConfirmPara(m_apcLayerCfg[layerIdx]->m_motionPredRefLayerIds[i] > m_apcLayerCfg[layerIdx]->m_layerId, "Cannot reference higher layers");
+      xConfirmPara(m_apcLayerCfg[layerIdx]->m_motionPredRefLayerIds[i] == m_apcLayerCfg[layerIdx]->m_layerId, "Cannot reference the current layer itself");
+    }
+  }
+
+  xConfirmPara( (m_apcLayerCfg[0]->m_numActiveRefLayers != 0) && (m_apcLayerCfg[0]->m_numActiveRefLayers != -1), "Layer 0 cannot have any active reference layers" );
   // NOTE: m_numActiveRefLayers  (for any layer) could be -1 (not signalled in cfg), in which case only the "previous layer" would be taken for reference
   if( layerIdx > 0 )
@@ -4242,11 +4278,11 @@
       predEnabledFlag[refLayer] = false;
     }
-    for(Int i = 0; i < m_acLayerCfg[layerIdx].m_numSamplePredRefLayers; i++)
-    {
-      predEnabledFlag[m_acLayerCfg[layerIdx].m_samplePredRefLayerIds[i]] = true;
-    }
-    for(Int i = 0; i < m_acLayerCfg[layerIdx].m_numMotionPredRefLayers; i++)
-    {
-      predEnabledFlag[m_acLayerCfg[layerIdx].m_motionPredRefLayerIds[i]] = true;
+    for(Int i = 0; i < m_apcLayerCfg[layerIdx]->m_numSamplePredRefLayers; i++)
+    {
+      predEnabledFlag[m_apcLayerCfg[layerIdx]->m_samplePredRefLayerIds[i]] = true;
+    }
+    for(Int i = 0; i < m_apcLayerCfg[layerIdx]->m_numMotionPredRefLayers; i++)
+    {
+      predEnabledFlag[m_apcLayerCfg[layerIdx]->m_motionPredRefLayerIds[i]] = true;
     }
     Int numDirectRefLayers = 0;
@@ -4255,8 +4291,8 @@
       if (predEnabledFlag[refLayer] == true) numDirectRefLayers++;
     }
-    xConfirmPara(m_acLayerCfg[layerIdx].m_numActiveRefLayers > numDirectRefLayers, "Cannot reference more layers than NumDirectRefLayers");
-    for(Int i = 0; i < m_acLayerCfg[layerIdx].m_numActiveRefLayers; i++)
-    {
-      xConfirmPara(m_acLayerCfg[layerIdx].m_predLayerIds[i] >= numDirectRefLayers, "Cannot reference higher layers");
+    xConfirmPara(m_apcLayerCfg[layerIdx]->m_numActiveRefLayers > numDirectRefLayers, "Cannot reference more layers than NumDirectRefLayers");
+    for(Int i = 0; i < m_apcLayerCfg[layerIdx]->m_numActiveRefLayers; i++)
+    {
+      xConfirmPara(m_apcLayerCfg[layerIdx]->m_predLayerIds[i] >= numDirectRefLayers, "Cannot reference higher layers");
     }
   }
@@ -4265,5 +4301,5 @@
   {
     xConfirmPara(m_numLayers != 2, "Adaptive resolution change works with 2 layers only");
-    xConfirmPara(m_acLayerCfg[1].m_iIntraPeriod == 0 || (m_adaptiveResolutionChange % m_acLayerCfg[1].m_iIntraPeriod) != 0, "Adaptive resolution change must happen at enhancement layer RAP picture");
+    xConfirmPara(m_apcLayerCfg[1]->m_iIntraPeriod == 0 || (m_adaptiveResolutionChange % m_apcLayerCfg[1]->m_iIntraPeriod) != 0, "Adaptive resolution change must happen at enhancement layer RAP picture");
   }
 
@@ -4280,10 +4316,10 @@
   if( layerIdx < MAX_LAYERS-1 )
   {
-    xConfirmPara(m_acLayerCfg[layerIdx].m_maxTidIlRefPicsPlus1 < 0 || m_acLayerCfg[layerIdx].m_maxTidIlRefPicsPlus1 > 7, "MaxTidIlRefPicsPlus1 must be in range 0 to 7");
+    xConfirmPara(m_apcLayerCfg[layerIdx]->m_maxTidIlRefPicsPlus1 < 0 || m_apcLayerCfg[layerIdx]->m_maxTidIlRefPicsPlus1 > 7, "MaxTidIlRefPicsPlus1 must be in range 0 to 7");
   }
 #if AUXILIARY_PICTURES
   if( layerIdx < MAX_LAYERS-1 )
   {
-    xConfirmPara(m_acLayerCfg[layerIdx].m_auxId < 0 || m_acLayerCfg[layerIdx].m_auxId > 2, "AuxId must be in range 0 to 2");
+    xConfirmPara(m_apcLayerCfg[layerIdx]->m_auxId < 0 || m_apcLayerCfg[layerIdx]->m_auxId > 2, "AuxId must be in range 0 to 2");
   }
 #endif 
@@ -4341,5 +4377,5 @@
   {
     printf("=== Layer %d settings === \n", layer);
-    m_acLayerCfg[layer].xPrintParameter();
+    m_apcLayerCfg[layer]->xPrintParameter();
     printf("\n");
   }
@@ -4704,5 +4740,5 @@
 {
   Int *tempArray = NULL;
-  numEntries = MAX_LAYERS;
+  numEntries = m_numLayers;
   // For all layer sets
   cfgStringToArrayNumEntries(&tempArray, cfgString, numEntries, logString);
Index: branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.h	(revision 1376)
+++ branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.h	(revision 1377)
@@ -60,5 +60,5 @@
   // file I/O
 #if SVC_EXTENSION
-  TAppEncLayerCfg m_acLayerCfg [MAX_LAYERS];
+  TAppEncLayerCfg* m_apcLayerCfg[MAX_LAYERS];
   Int       m_layerId;
   Int       m_numLayers;                                      ///< number of layers
@@ -551,4 +551,5 @@
   
 #if SVC_EXTENSION
+  Bool parseCfgNumLayersAndInit( Int argc, Char* argv[] );    ///< parse configuration file to to get number of layers and allocate memory
   Int  getNumFrameToBeEncoded()                               { return m_framesToBeEncoded;                          }
   Int  getNumLayer()                                          { return m_numLayers;                                  }
@@ -559,9 +560,9 @@
   UInt getPCMLog2MinSize  ()                                  { return  m_uiPCMLog2MinSize;                          }
 
-  UInt getInternalBitDepth(Int iLayer, ChannelType type)      { return m_acLayerCfg[iLayer].m_internalBitDepth[type];}
-  Bool getPCMInputBitDepthFlag()                              { return m_bPCMInputBitDepthFlag;                      }
+  UInt getInternalBitDepth(Int layer, ChannelType type)       { return m_apcLayerCfg[layer]->m_internalBitDepth[type];}
+  Bool getPCMInputBitDepthFlag()                              { return m_bPCMInputBitDepthFlag;                       }
 
   Int  getDecodingRefreshType()                               { return m_iDecodingRefreshType;                       }
-  Int  getWaveFrontSynchro(Int layerIdx)                      { return m_acLayerCfg[layerIdx].m_waveFrontSynchro;    }
+  Int  getWaveFrontSynchro(Int layerIdx)                      { return m_apcLayerCfg[layerIdx]->m_waveFrontSynchro;  }
   Void getDirFilename(string& filename, string& dir, const string path);
 
Index: branches/SHM-dev/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- branches/SHM-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 1376)
+++ branches/SHM-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 1377)
@@ -64,8 +64,7 @@
   m_essentialBytes = 0;
 #if SVC_EXTENSION
-  for(UInt layer=0; layer < MAX_LAYERS; layer++)
-  {
-    m_apcTEncTop[layer] = &m_acTEncTop[layer];
-  }
+  memset( m_apcTVideoIOYuvInputFile, NULL, sizeof(m_apcTVideoIOYuvInputFile) );
+  memset( m_apcTVideoIOYuvReconFile, NULL, sizeof(m_apcTVideoIOYuvReconFile) );
+  memset( m_apcTEncTop, NULL, sizeof(m_apcTEncTop) );
 #endif
 }
@@ -75,21 +74,30 @@
 }
 
-#if SVC_EXTENSION
 Void TAppEncTop::xInitLibCfg()
 {
-  TComVPS* vps = m_acTEncTop[0].getVPS();
-
-  vps->setVpsPocLsbAlignedFlag(false);
-
-  vps->setMaxTLayers                                                      ( m_maxTempLayer );
+#if SVC_EXTENSION
+  TComVPS& vps = *m_apcTEncTop[0]->getVPS();
+#else
+  TComVPS vps;
+#endif
+
+  vps.setMaxTLayers                                               ( m_maxTempLayer );
   if (m_maxTempLayer == 1)
   {
-    vps->setTemporalNestingFlag(true);
-  }
+    vps.setTemporalNestingFlag(true);
+  }
+  vps.setMaxLayers                                                ( 1 );
   for(Int i = 0; i < MAX_TLAYER; i++)
   {
-    vps->setNumReorderPics                                                ( m_numReorderPics[i], i );
-    vps->setMaxDecPicBuffering                                            ( m_maxDecPicBuffering[i], i );
-  }
+    vps.setNumReorderPics                                         ( m_numReorderPics[i], i );
+    vps.setMaxDecPicBuffering                                     ( m_maxDecPicBuffering[i], i );
+  }
+
+#if !SVC_EXTENSION
+  m_cTEncTop.setVPS(&vps);
+#endif
+  
+#if SVC_EXTENSION
+  vps.setVpsPocLsbAlignedFlag(false);  
 
   Int maxRepFormatIdx = -1;
@@ -98,14 +106,14 @@
   {
     // Auto generation of the format index
-    if( m_acLayerCfg[layer].getRepFormatIdx() == -1 )
+    if( m_apcLayerCfg[layer]->getRepFormatIdx() == -1 )
     {      
       Bool found = false;
       for( UInt idx = 0; idx < layer; idx++ )
       {
-        if( m_acLayerCfg[layer].getSourceWidth() == m_acLayerCfg[idx].getSourceWidth() && m_acLayerCfg[layer].getSourceHeight() == m_acLayerCfg[idx].getSourceHeight()
+        if( m_apcLayerCfg[layer]->getSourceWidth() == m_apcLayerCfg[idx]->getSourceWidth() && m_apcLayerCfg[layer]->getSourceHeight() == m_apcLayerCfg[idx]->getSourceHeight()
 #if AUXILIARY_PICTURES
-          && m_acLayerCfg[layer].getChromaFormatIDC() == m_acLayerCfg[idx].getChromaFormatIDC()
-#endif
-          && m_acLayerCfg[layer].m_internalBitDepth[CHANNEL_TYPE_LUMA] == m_acLayerCfg[idx].m_internalBitDepth[CHANNEL_TYPE_LUMA] && m_acLayerCfg[layer].m_internalBitDepth[CHANNEL_TYPE_CHROMA] == m_acLayerCfg[idx].m_internalBitDepth[CHANNEL_TYPE_CHROMA]
+          && m_apcLayerCfg[layer]->getChromaFormatIDC() == m_apcLayerCfg[idx]->getChromaFormatIDC()
+#endif
+          && m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_LUMA] == m_apcLayerCfg[idx]->m_internalBitDepth[CHANNEL_TYPE_LUMA] && m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_CHROMA] == m_apcLayerCfg[idx]->m_internalBitDepth[CHANNEL_TYPE_CHROMA]
           )
         {
@@ -119,15 +127,15 @@
       }
 
-      m_acLayerCfg[layer].setRepFormatIdx( formatIdx );
-    }
-
-    assert( m_acLayerCfg[layer].getRepFormatIdx() != -1 && "RepFormatIdx not assigned for a layer" );
-
-    vps->setVpsRepFormatIdx( layer, m_acLayerCfg[layer].getRepFormatIdx() );
-
-    maxRepFormatIdx = std::max( m_acLayerCfg[layer].getRepFormatIdx(), maxRepFormatIdx );
-  }
-
-  assert( vps->getVpsRepFormatIdx( 0 ) == 0 );  // Base layer should point to the first one.
+      m_apcLayerCfg[layer]->setRepFormatIdx( formatIdx );
+    }
+
+    assert( m_apcLayerCfg[layer]->getRepFormatIdx() != -1 && "RepFormatIdx not assigned for a layer" );
+
+    vps.setVpsRepFormatIdx( layer, m_apcLayerCfg[layer]->getRepFormatIdx() );
+
+    maxRepFormatIdx = std::max( m_apcLayerCfg[layer]->getRepFormatIdx(), maxRepFormatIdx );
+  }
+
+  assert( vps.getVpsRepFormatIdx( 0 ) == 0 );  // Base layer should point to the first one.
 
   Int* mapIdxToLayer = new Int[maxRepFormatIdx + 1];
@@ -140,5 +148,5 @@
     for(layer=0; layer < m_numLayers; layer++)
     {
-      if( vps->getVpsRepFormatIdx(layer) == i )
+      if( vps.getVpsRepFormatIdx(layer) == i )
       {
         mapIdxToLayer[i] = layer;
@@ -149,12 +157,12 @@
   }
 
-  vps->setVpsNumRepFormats                                                ( maxRepFormatIdx + 1 );
+  vps.setVpsNumRepFormats                                                ( maxRepFormatIdx + 1 );
 
   // When not present, the value of rep_format_idx_present_flag is inferred to be equal to 0
-  vps->setRepFormatIdxPresentFlag                                         ( vps->getVpsNumRepFormats() > 1 ? true : false );
-
-  for(UInt idx=0; idx < vps->getVpsNumRepFormats(); idx++)
-  {
-    RepFormat *repFormat = vps->getVpsRepFormat( idx );
+  vps.setRepFormatIdxPresentFlag                                         ( vps.getVpsNumRepFormats() > 1 ? true : false );
+
+  for(UInt idx=0; idx < vps.getVpsNumRepFormats(); idx++)
+  {
+    RepFormat *repFormat = vps.getVpsRepFormat( idx );
     repFormat->setChromaAndBitDepthVpsPresentFlag                         ( true ); 
     if (idx==0)
@@ -163,8 +171,8 @@
     }
 
-    repFormat->setPicWidthVpsInLumaSamples                                ( m_acLayerCfg[mapIdxToLayer[idx]].getSourceWidth()   );
-    repFormat->setPicHeightVpsInLumaSamples                               ( m_acLayerCfg[mapIdxToLayer[idx]].getSourceHeight()  );
+    repFormat->setPicWidthVpsInLumaSamples                                ( m_apcLayerCfg[mapIdxToLayer[idx]]->getSourceWidth()   );
+    repFormat->setPicHeightVpsInLumaSamples                               ( m_apcLayerCfg[mapIdxToLayer[idx]]->getSourceHeight()  );
 #if AUXILIARY_PICTURES
-    repFormat->setChromaFormatVpsIdc                                      ( m_acLayerCfg[mapIdxToLayer[idx]].getChromaFormatIDC() );
+    repFormat->setChromaFormatVpsIdc                                      ( m_apcLayerCfg[mapIdxToLayer[idx]]->getChromaFormatIDC() );
 #else
     repFormat->setChromaFormatVpsIdc                                      ( 1 );  // Need modification to change for each layer - corresponds to 420
@@ -175,10 +183,10 @@
     repFormat->setBitDepthVpsChroma                                       ( getInternalBitDepth(mapIdxToLayer[idx], CHANNEL_TYPE_CHROMA)    );  // Need modification to change for each layer
 
-    repFormat->getConformanceWindowVps().setWindow                        ( m_acLayerCfg[mapIdxToLayer[idx]].m_confWinLeft,                                                                             
-                                                                            m_acLayerCfg[mapIdxToLayer[idx]].m_confWinRight, 
-                                                                            m_acLayerCfg[mapIdxToLayer[idx]].m_confWinTop,
-                                                                            m_acLayerCfg[mapIdxToLayer[idx]].m_confWinBottom );
-
-    m_acTEncTop[mapIdxToLayer[idx]].setSkipPictureAtArcSwitch             ( m_skipPictureAtArcSwitch );
+    repFormat->getConformanceWindowVps().setWindow                        ( m_apcLayerCfg[mapIdxToLayer[idx]]->m_confWinLeft,                                                                             
+                                                                            m_apcLayerCfg[mapIdxToLayer[idx]]->m_confWinRight, 
+                                                                            m_apcLayerCfg[mapIdxToLayer[idx]]->m_confWinTop,
+                                                                            m_apcLayerCfg[mapIdxToLayer[idx]]->m_confWinBottom );
+
+    m_apcTEncTop[mapIdxToLayer[idx]]->setSkipPictureAtArcSwitch           ( m_skipPictureAtArcSwitch );
   }
 
@@ -186,20 +194,19 @@
 
   //Populate PTL in VPS
-  TComVPS *pVPS = m_acTEncTop[0].getVPS();
   for( Int ii = 0; ii < m_numPTLInfo; ii++ )
   {
-    pVPS->getPTL(ii)->getGeneralPTL()->setLevelIdc(m_levelList[ii]);
-    pVPS->getPTL(ii)->getGeneralPTL()->setTierFlag(m_levelTierList[ii]);
-    pVPS->getPTL(ii)->getGeneralPTL()->setProfileIdc(m_profileList[ii]);
-    pVPS->getPTL(ii)->getGeneralPTL()->setProfileCompatibilityFlag(m_profileCompatibility[ii], 1);
-    pVPS->getPTL(ii)->getGeneralPTL()->setProgressiveSourceFlag(m_progressiveSourceFlagList[ii]);
-    pVPS->getPTL(ii)->getGeneralPTL()->setInterlacedSourceFlag(m_interlacedSourceFlagList[ii]);
-    pVPS->getPTL(ii)->getGeneralPTL()->setNonPackedConstraintFlag(m_nonPackedConstraintFlagList[ii]);
-    pVPS->getPTL(ii)->getGeneralPTL()->setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlagList[ii]);
-  }
-  pVPS->setNumProfileTierLevel(m_numPTLInfo);
+    vps.getPTL(ii)->getGeneralPTL()->setLevelIdc(m_levelList[ii]);
+    vps.getPTL(ii)->getGeneralPTL()->setTierFlag(m_levelTierList[ii]);
+    vps.getPTL(ii)->getGeneralPTL()->setProfileIdc(m_profileList[ii]);
+    vps.getPTL(ii)->getGeneralPTL()->setProfileCompatibilityFlag(m_profileCompatibility[ii], 1);
+    vps.getPTL(ii)->getGeneralPTL()->setProgressiveSourceFlag(m_progressiveSourceFlagList[ii]);
+    vps.getPTL(ii)->getGeneralPTL()->setInterlacedSourceFlag(m_interlacedSourceFlagList[ii]);
+    vps.getPTL(ii)->getGeneralPTL()->setNonPackedConstraintFlag(m_nonPackedConstraintFlagList[ii]);
+    vps.getPTL(ii)->getGeneralPTL()->setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlagList[ii]);
+  }
+  vps.setNumProfileTierLevel(m_numPTLInfo);
 
   std::vector<Int> myvector;
-  vps->getProfileLevelTierIdx()->resize(m_numOutputLayerSets);
+  vps.getProfileLevelTierIdx()->resize(m_numOutputLayerSets);
   for( Int ii = 0; ii < m_numOutputLayerSets; ii++ )
   {
@@ -208,5 +215,5 @@
     for( std::vector<Int>::iterator it = myvector.begin() ; it != myvector.end(); ++it )
     {
-      pVPS->addProfileLevelTierIdx(ii, it[0]);
+      vps.addProfileLevelTierIdx(ii, it[0]);
     }
   }
@@ -214,80 +221,19 @@
   assert( m_numLayers <= MAX_LAYERS );
 
-  for(UInt layer=0; layer<m_numLayers; layer++)
-  {
+  for( UInt layer=0; layer < m_numLayers; layer++ )
+  {
+    TEncTop& m_cTEncTop = *m_apcTEncTop[layer];
     //1
-    m_acTEncTop[layer].setInterLayerWeightedPredFlag                      ( m_useInterLayerWeightedPred );
-    
-    Int layerPTLIdx = m_acLayerCfg[layer].m_layerPTLIdx;
-    m_acTEncTop[layer].setProfile                                         ( m_profileList[layerPTLIdx] );
-    m_acTEncTop[layer].setLevel                                           ( m_levelTierList[layerPTLIdx], m_levelList[layerPTLIdx] );
-    m_acTEncTop[layer].setProgressiveSourceFlag                           ( m_progressiveSourceFlagList[layerPTLIdx] );
-    m_acTEncTop[layer].setInterlacedSourceFlag                            ( m_interlacedSourceFlagList[layerPTLIdx] );
-    m_acTEncTop[layer].setNonPackedConstraintFlag                         ( m_nonPackedConstraintFlagList[layerPTLIdx] );
-    m_acTEncTop[layer].setFrameOnlyConstraintFlag                         ( m_frameOnlyConstraintFlagList[layerPTLIdx] );
-    m_acTEncTop[layer].setBitDepthConstraintValue                         ( m_acLayerCfg[layer].m_bitDepthConstraint );
-    m_acTEncTop[layer].setChromaFormatConstraintValue                     ( m_acLayerCfg[layer].m_chromaFormatConstraint );
-    m_acTEncTop[layer].setIntraConstraintFlag                             ( m_acLayerCfg[layer].m_intraConstraintFlag );
-    m_acTEncTop[layer].setOnePictureOnlyConstraintFlag                    ( m_acLayerCfg[layer].m_onePictureOnlyConstraintFlag );
-    m_acTEncTop[layer].setLowerBitRateConstraintFlag                      ( m_acLayerCfg[layer].m_lowerBitRateConstraintFlag );
-
-    m_acTEncTop[layer].setPrintMSEBasedSequencePSNR                       ( m_printMSEBasedSequencePSNR);
-    m_acTEncTop[layer].setPrintFrameMSE                                   ( m_printFrameMSE);
-    m_acTEncTop[layer].setPrintSequenceMSE                                ( m_printSequenceMSE);
-    m_acTEncTop[layer].setCabacZeroWordPaddingEnabled                     ( m_cabacZeroWordPaddingEnabled );
-
-    m_acTEncTop[layer].setFrameRate                                       ( m_acLayerCfg[layer].getFrameRate() );
-    m_acTEncTop[layer].setFrameSkip                                       ( m_FrameSkip );
-    m_acTEncTop[layer].setSourceWidth                                     ( m_acLayerCfg[layer].getSourceWidth() );
-    m_acTEncTop[layer].setSourceHeight                                    ( m_acLayerCfg[layer].getSourceHeight() );
-    m_acTEncTop[layer].setConformanceWindow                               ( m_acLayerCfg[layer].m_confWinLeft, m_acLayerCfg[layer].m_confWinRight, m_acLayerCfg[layer].m_confWinTop, m_acLayerCfg[layer].m_confWinBottom );
-    m_acTEncTop[layer].setFramesToBeEncoded                               ( m_framesToBeEncoded );
-
-#if AVC_BASE
-    m_acTEncTop[layer].setMFMEnabledFlag                                  (layer == 0 ? false : ( m_nonHEVCBaseLayerFlag ? false : true ) && m_acLayerCfg[layer].getNumMotionPredRefLayers());
-#else
-    m_acTEncTop[layer].setMFMEnabledFlag                                  (layer == 0 ? false : ( m_acLayerCfg[layer].getNumMotionPredRefLayers() > 0 ) );
-#endif
+    m_cTEncTop.setInterLayerWeightedPredFlag                      ( m_useInterLayerWeightedPred );
+    m_cTEncTop.setMFMEnabledFlag                                  ( layer == 0 ? false : ( m_nonHEVCBaseLayerFlag ? false : true ) && m_apcLayerCfg[layer]->getNumMotionPredRefLayers());
 
     // set layer ID
-    m_acTEncTop[layer].setLayerId                                         ( m_acLayerCfg[layer].m_layerId );
-    m_acTEncTop[layer].setNumLayer                                        ( m_numLayers );
-    m_acTEncTop[layer].setLayerEnc                                        ( m_apcTEncTop );
-
-    //====== Coding Structure ========
-    m_acTEncTop[layer].setIntraPeriod                                     ( m_acLayerCfg[layer].m_iIntraPeriod );
-    m_acTEncTop[layer].setDecodingRefreshType                             ( m_iDecodingRefreshType );
-    m_acTEncTop[layer].setGOPSize                                         ( m_iGOPSize );
-
-    m_acTEncTop[layer].setGopList                                         ( layer ? m_EhGOPList[layer] : m_GOPList );
-    m_acTEncTop[layer].setExtraRPSs                                       ( m_extraRPSs[layer] );
-
-    for(Int i = 0; i < MAX_TLAYER; i++)
-    {
-      m_acTEncTop[layer].setNumReorderPics                                ( m_numReorderPics[i], i );
-      m_acTEncTop[layer].setMaxDecPicBuffering                            ( m_maxDecPicBuffering[i], i );
-    }
-    for( UInt uiLoop = 0; uiLoop < MAX_TLAYER; ++uiLoop )
-    {
-      m_acTEncTop[layer].setLambdaModifier                                ( uiLoop, m_adLambdaModifier[ uiLoop ] );
-    }
-    m_acTEncTop[layer].setQP                                              ( m_acLayerCfg[layer].getIntQP() );
-
-    m_acTEncTop[layer].setPad                                             ( m_acLayerCfg[layer].getPad() );
-
-    if (layer== 0)
-    {
-      m_acTEncTop[layer].setMaxTempLayer                                  ( m_maxTempLayer );
-    }
-    else
-    {
-      m_acTEncTop[layer].setMaxTempLayer                                  ( m_EhMaxTempLayer[layer] );
-    }
-
-    m_acTEncTop[layer].setUseAMP( m_enableAMP );
+    m_cTEncTop.setLayerId                                         ( m_apcLayerCfg[layer]->m_layerId );
+    m_cTEncTop.setNumLayer                                        ( m_numLayers );
+    m_cTEncTop.setLayerEnc                                        ( m_apcTEncTop );
 
     if( layer < m_numLayers - 1 )
     {
-       m_acTEncTop[layer].setMaxTidIlRefPicsPlus1                         ( m_acLayerCfg[layer].getMaxTidIlRefPicsPlus1());
+       m_cTEncTop.setMaxTidIlRefPicsPlus1                         ( m_apcLayerCfg[layer]->getMaxTidIlRefPicsPlus1());
     }
 
@@ -296,42 +242,42 @@
       UInt prevLayerIdx = 0;
       UInt prevLayerId  = 0;
-      if (m_acLayerCfg[layer].getNumActiveRefLayers() > 0)
-      {
-        prevLayerIdx = m_acLayerCfg[layer].getPredLayerIdx(m_acLayerCfg[layer].getNumActiveRefLayers() - 1);
-        prevLayerId  = m_acTEncTop[layer].getRefLayerId(prevLayerIdx);
+      if (m_apcLayerCfg[layer]->getNumActiveRefLayers() > 0)
+      {
+        prevLayerIdx = m_apcLayerCfg[layer]->getPredLayerIdx(m_apcLayerCfg[layer]->getNumActiveRefLayers() - 1);
+        prevLayerId  = m_cTEncTop.getRefLayerId(prevLayerIdx);
       }
       for(Int i = 0; i < MAX_VPS_LAYER_IDX_PLUS1; i++)
       {
-        m_acTEncTop[layer].setSamplePredEnabledFlag                       (i, false);
-        m_acTEncTop[layer].setMotionPredEnabledFlag                       (i, false);
-      }
-      if(m_acLayerCfg[layer].getNumSamplePredRefLayers() == -1)
+        m_cTEncTop.setSamplePredEnabledFlag                       (i, false);
+        m_cTEncTop.setMotionPredEnabledFlag                       (i, false);
+      }
+      if(m_apcLayerCfg[layer]->getNumSamplePredRefLayers() == -1)
       {
         // Not included in the configuration file; assume that each layer depends on previous layer
-        m_acTEncTop[layer].setNumSamplePredRefLayers                      (1);      // One sample pred ref. layer
-        m_acTEncTop[layer].setSamplePredRefLayerId                        (prevLayerIdx, prevLayerId);   // Previous layer
-        m_acTEncTop[layer].setSamplePredEnabledFlag                       (prevLayerIdx, true);
+        m_cTEncTop.setNumSamplePredRefLayers                      (1);      // One sample pred ref. layer
+        m_cTEncTop.setSamplePredRefLayerId                        (prevLayerIdx, prevLayerId);   // Previous layer
+        m_cTEncTop.setSamplePredEnabledFlag                       (prevLayerIdx, true);
       }
       else
       {
-        m_acTEncTop[layer].setNumSamplePredRefLayers                      ( m_acLayerCfg[layer].getNumSamplePredRefLayers() );
-        for(Int i = 0; i < m_acTEncTop[layer].getNumSamplePredRefLayers(); i++)
-        {
-          m_acTEncTop[layer].setSamplePredRefLayerId                      ( i, m_acLayerCfg[layer].getSamplePredRefLayerId(i));
-        }
-      }
-      if(m_acLayerCfg[layer].getNumMotionPredRefLayers() == -1)
+        m_cTEncTop.setNumSamplePredRefLayers                      ( m_apcLayerCfg[layer]->getNumSamplePredRefLayers() );
+        for( Int i = 0; i < m_cTEncTop.getNumSamplePredRefLayers(); i++ )
+        {
+          m_cTEncTop.setSamplePredRefLayerId                      ( i, m_apcLayerCfg[layer]->getSamplePredRefLayerId(i));
+        }
+      }
+      if( m_apcLayerCfg[layer]->getNumMotionPredRefLayers() == -1)
       {
         // Not included in the configuration file; assume that each layer depends on previous layer
-        m_acTEncTop[layer].setNumMotionPredRefLayers                      (1);      // One motion pred ref. layer
-        m_acTEncTop[layer].setMotionPredRefLayerId                        (prevLayerIdx, prevLayerId);   // Previous layer
-        m_acTEncTop[layer].setMotionPredEnabledFlag                       (prevLayerIdx, true);
+        m_cTEncTop.setNumMotionPredRefLayers                      (1);      // One motion pred ref. layer
+        m_cTEncTop.setMotionPredRefLayerId                        (prevLayerIdx, prevLayerId);   // Previous layer
+        m_cTEncTop.setMotionPredEnabledFlag                       (prevLayerIdx, true);
       }
       else
       {
-        m_acTEncTop[layer].setNumMotionPredRefLayers                      ( m_acLayerCfg[layer].getNumMotionPredRefLayers() );
-        for(Int i = 0; i < m_acTEncTop[layer].getNumMotionPredRefLayers(); i++)
-        {
-          m_acTEncTop[layer].setMotionPredRefLayerId                      ( i, m_acLayerCfg[layer].getMotionPredRefLayerId(i));
+        m_cTEncTop.setNumMotionPredRefLayers                      ( m_apcLayerCfg[layer]->getNumMotionPredRefLayers() );
+        for( Int i = 0; i < m_cTEncTop.getNumMotionPredRefLayers(); i++ )
+        {
+          m_cTEncTop.setMotionPredRefLayerId                      ( i, m_apcLayerCfg[layer]->getMotionPredRefLayerId(i));
         }
       }
@@ -340,24 +286,24 @@
       assert( layer < MAX_LAYERS );
 
-      for (Int i = 0; i < m_acLayerCfg[layer].m_layerId; i++)
+      for (Int i = 0; i < m_apcLayerCfg[layer]->m_layerId; i++)
       {
         Int refLayerId = -1;
 
-        for( Int layerIdc = 0; layerIdc < m_acTEncTop[layer].getNumSamplePredRefLayers(); layerIdc++ )
-        {
-          if( m_acLayerCfg[layer].getSamplePredRefLayerId(layerIdc) == i )
+        for( Int layerIdc = 0; layerIdc < m_cTEncTop.getNumSamplePredRefLayers(); layerIdc++ )
+        {
+          if( m_apcLayerCfg[layer]->getSamplePredRefLayerId(layerIdc) == i )
           {
             refLayerId = i;
-            m_acTEncTop[layer].setSamplePredEnabledFlag( numDirectRefLayers, true );
+            m_cTEncTop.setSamplePredEnabledFlag( numDirectRefLayers, true );
             break;
           }
         }
 
-        for( Int layerIdc = 0; layerIdc < m_acTEncTop[layer].getNumMotionPredRefLayers(); layerIdc++ )
-        {
-          if( m_acLayerCfg[layer].getMotionPredRefLayerId(layerIdc) == i )
+        for( Int layerIdc = 0; layerIdc < m_cTEncTop.getNumMotionPredRefLayers(); layerIdc++ )
+        {
+          if( m_apcLayerCfg[layer]->getMotionPredRefLayerId(layerIdc) == i )
           {
             refLayerId = i;
-            m_acTEncTop[layer].setMotionPredEnabledFlag( numDirectRefLayers, true );
+            m_cTEncTop.setMotionPredEnabledFlag( numDirectRefLayers, true );
             break;
           }
@@ -366,25 +312,25 @@
         if( refLayerId >= 0 )
         {
-          m_acTEncTop[layer].setRefLayerId                                ( numDirectRefLayers, refLayerId );
+          m_cTEncTop.setRefLayerId                                ( numDirectRefLayers, refLayerId );
           numDirectRefLayers++;
         }
       }
 
-      m_acTEncTop[layer].setNumDirectRefLayers                            ( numDirectRefLayers );
-
-      if(m_acLayerCfg[layer].getNumActiveRefLayers() == -1)
-      {
-        m_acTEncTop[layer].setNumActiveRefLayers                          ( m_acTEncTop[layer].getNumDirectRefLayers() );
-        for( Int i = 0; i < m_acTEncTop[layer].getNumActiveRefLayers(); i++ )
-        {
-          m_acTEncTop[layer].setPredLayerIdx(i, i);
+      m_cTEncTop.setNumDirectRefLayers                            ( numDirectRefLayers );
+
+      if(m_apcLayerCfg[layer]->getNumActiveRefLayers() == -1)
+      {
+        m_cTEncTop.setNumActiveRefLayers                          ( m_cTEncTop.getNumDirectRefLayers() );
+        for( Int i = 0; i < m_cTEncTop.getNumActiveRefLayers(); i++ )
+        {
+          m_cTEncTop.setPredLayerIdx(i, i);
         }
       }
       else
       {
-        m_acTEncTop[layer].setNumActiveRefLayers                          ( m_acLayerCfg[layer].getNumActiveRefLayers() );
-        for(Int i = 0; i < m_acTEncTop[layer].getNumActiveRefLayers(); i++)
-        {
-          m_acTEncTop[layer].setPredLayerIdx                              ( i, m_acLayerCfg[layer].getPredLayerIdx(i));
+        m_cTEncTop.setNumActiveRefLayers                          ( m_apcLayerCfg[layer]->getNumActiveRefLayers() );
+        for(Int i = 0; i < m_cTEncTop.getNumActiveRefLayers(); i++)
+        {
+          m_cTEncTop.setPredLayerIdx                              ( i, m_apcLayerCfg[layer]->getPredLayerIdx(i));
         }
       }
@@ -393,412 +339,153 @@
     {
       assert( layer == 0 );
-      m_acTEncTop[layer].setNumDirectRefLayers(0);
-    }
-
-    //===== Slice ========
-
-    //====== Loop/Deblock Filter ========
-    m_acTEncTop[layer].setLoopFilterDisable                                ( m_bLoopFilterDisable       );
-    m_acTEncTop[layer].setLoopFilterOffsetInPPS                            ( m_loopFilterOffsetInPPS );
-    m_acTEncTop[layer].setLoopFilterBetaOffset                             ( m_loopFilterBetaOffsetDiv2  );
-    m_acTEncTop[layer].setLoopFilterTcOffset                               ( m_loopFilterTcOffsetDiv2    );    
-    m_acTEncTop[layer].setDeblockingFilterMetric                           ( m_DeblockingFilterMetric );
-
-    //====== Motion search ========
-    m_acTEncTop[layer].setDisableIntraPUsInInterSlices                     ( m_bDisableIntraPUsInInterSlices );
-    m_acTEncTop[layer].setFastSearch                                       ( m_iFastSearch  );
-    m_acTEncTop[layer].setSearchRange                                      ( m_iSearchRange );
-    m_acTEncTop[layer].setBipredSearchRange                                ( m_bipredSearchRange );
-    m_acTEncTop[layer].setClipForBiPredMeEnabled                           ( m_bClipForBiPredMeEnabled );
-    m_acTEncTop[layer].setFastMEAssumingSmootherMVEnabled                  ( m_bFastMEAssumingSmootherMVEnabled );
-
-    //====== Quality control ========
-    m_acTEncTop[layer].setMaxDeltaQP                                       ( m_iMaxDeltaQP  );
-    m_acTEncTop[layer].setMaxCuDQPDepth                                    ( m_acLayerCfg[layer].m_iMaxCuDQPDepth  );
-    m_acTEncTop[layer].setDiffCuChromaQpOffsetDepth                        ( m_diffCuChromaQpOffsetDepth );
-    m_acTEncTop[layer].setChromaCbQpOffset                                 ( m_cbQpOffset     );
-    m_acTEncTop[layer].setChromaCrQpOffset                                 ( m_crQpOffset  );
-
-    m_acTEncTop[layer].setChromaFormatIdc                                  ( m_acLayerCfg[layer].m_chromaFormatIDC  );
-
-#if ADAPTIVE_QP_SELECTION
-    m_acTEncTop[layer].setUseAdaptQpSelect                                 ( m_bUseAdaptQpSelect   );
-#endif
-    
-    m_acTEncTop[layer].setUseAdaptiveQP                                    ( m_bUseAdaptiveQP  );
-    m_acTEncTop[layer].setQPAdaptationRange                                ( m_iQPAdaptationRange );
-    m_acTEncTop[layer].setExtendedPrecisionProcessingFlag                  ( m_acLayerCfg[layer].m_extendedPrecisionProcessingFlag );
-    m_acTEncTop[layer].setHighPrecisionOffsetsEnabledFlag                  ( m_acLayerCfg[layer].m_highPrecisionOffsetsEnabledFlag );
-
-    //====== Tool list ========    
-    m_acTEncTop[layer].setDeltaQpRD                                        ( m_uiDeltaQpRD  );
-    m_acTEncTop[layer].setFastDeltaQp                                      ( m_bFastDeltaQP  );
-    m_acTEncTop[layer].setUseASR                                           ( m_bUseASR      );
-    m_acTEncTop[layer].setUseHADME                                         ( m_bUseHADME    );    
-    m_acTEncTop[layer].setdQPs                                             ( m_acLayerCfg[layer].getdQPs() );
-    m_acTEncTop[layer].setUseRDOQ                                          ( m_useRDOQ     );
-    m_acTEncTop[layer].setUseRDOQTS                                        ( m_useRDOQTS   );
-#if T0196_SELECTIVE_RDOQ
-    m_acTEncTop[layer].setUseSelectiveRDOQ                                 ( m_useSelectiveRDOQ );
-#endif
-    m_acTEncTop[layer].setRDpenalty                                        ( m_rdPenalty );
-    m_acTEncTop[layer].setMaxCUWidth                                       ( m_acLayerCfg[layer].m_uiMaxCUWidth );
-    m_acTEncTop[layer].setMaxCUHeight                                      ( m_acLayerCfg[layer].m_uiMaxCUHeight );
-    m_acTEncTop[layer].setMaxTotalCUDepth                                  ( m_acLayerCfg[layer].m_uiMaxTotalCUDepth );
-    m_acTEncTop[layer].setLog2DiffMaxMinCodingBlockSize                    ( m_acLayerCfg[layer].m_uiLog2DiffMaxMinCodingBlockSize );
-
-    m_acTEncTop[layer].setQuadtreeTULog2MaxSize                            ( m_acLayerCfg[layer].m_uiQuadtreeTULog2MaxSize );
-    m_acTEncTop[layer].setQuadtreeTULog2MinSize                            ( m_acLayerCfg[layer].m_uiQuadtreeTULog2MinSize );
-    m_acTEncTop[layer].setQuadtreeTUMaxDepthInter                          ( m_acLayerCfg[layer].m_uiQuadtreeTUMaxDepthInter );
-    m_acTEncTop[layer].setQuadtreeTUMaxDepthIntra                          ( m_acLayerCfg[layer].m_uiQuadtreeTUMaxDepthIntra );
-
-    m_acTEncTop[layer].setUseFastEnc                                       ( m_bUseFastEnc  );
-    m_acTEncTop[layer].setUseEarlyCU                                       ( m_bUseEarlyCU  );
-    m_acTEncTop[layer].setUseFastDecisionForMerge                          ( m_useFastDecisionForMerge  );
-    m_acTEncTop[layer].setUseCbfFastMode                                   ( m_bUseCbfFastMode  );
-    m_acTEncTop[layer].setUseEarlySkipDetection                            ( m_useEarlySkipDetection );
-    m_acTEncTop[layer].setCrossComponentPredictionEnabledFlag              ( m_crossComponentPredictionEnabledFlag );
-    m_acTEncTop[layer].setUseReconBasedCrossCPredictionEstimate            ( m_reconBasedCrossCPredictionEstimate );
-    m_acTEncTop[layer].setLog2SaoOffsetScale                               ( CHANNEL_TYPE_LUMA  , m_log2SaoOffsetScale[CHANNEL_TYPE_LUMA]   );
-    m_acTEncTop[layer].setLog2SaoOffsetScale                               ( CHANNEL_TYPE_CHROMA, m_log2SaoOffsetScale[CHANNEL_TYPE_CHROMA] );
-    m_acTEncTop[layer].setUseTransformSkip                                 ( m_useTransformSkip      );
-    m_acTEncTop[layer].setUseTransformSkipFast                             ( m_useTransformSkipFast  );
-    m_acTEncTop[layer].setTransformSkipRotationEnabledFlag                 ( m_transformSkipRotationEnabledFlag   );
-    m_acTEncTop[layer].setTransformSkipContextEnabledFlag                  ( m_transformSkipContextEnabledFlag   );
-    m_acTEncTop[layer].setPersistentRiceAdaptationEnabledFlag              ( m_persistentRiceAdaptationEnabledFlag );
-    m_acTEncTop[layer].setCabacBypassAlignmentEnabledFlag                  ( m_cabacBypassAlignmentEnabledFlag );
-    m_acTEncTop[layer].setLog2MaxTransformSkipBlockSize                    ( m_log2MaxTransformSkipBlockSize  );
-    for (UInt signallingModeIndex = 0; signallingModeIndex < NUMBER_OF_RDPCM_SIGNALLING_MODES; signallingModeIndex++)
-    {
-      m_acTEncTop[layer].setRdpcmEnabledFlag                               ( RDPCMSignallingMode(signallingModeIndex), m_rdpcmEnabledFlag[signallingModeIndex]);
-    }
-    m_acTEncTop[layer].setUseConstrainedIntraPred                          ( m_bUseConstrainedIntraPred );
-    m_acTEncTop[layer].setFastUDIUseMPMEnabled                             ( m_bFastUDIUseMPMEnabled );
-    m_acTEncTop[layer].setFastMEForGenBLowDelayEnabled                     ( m_bFastMEForGenBLowDelayEnabled );
-    m_acTEncTop[layer].setUseBLambdaForNonKeyLowDelayPictures              ( m_bUseBLambdaForNonKeyLowDelayPictures );
-    m_acTEncTop[layer].setPCMLog2MinSize                                   ( m_uiPCMLog2MinSize);
-    m_acTEncTop[layer].setUsePCM                                           ( m_usePCM );
-
-    for( UInt channelType = 0; channelType < MAX_NUM_CHANNEL_TYPE; channelType++ )
-    {
-      m_acTEncTop[layer].setBitDepth                                       ((ChannelType)channelType, m_acLayerCfg[layer].m_internalBitDepth[channelType]);
-      m_acTEncTop[layer].setPCMBitDepth                                    ((ChannelType)channelType, m_bPCMInputBitDepthFlag ? m_acLayerCfg[layer].m_MSBExtendedBitDepth[channelType] : m_acLayerCfg[layer].m_internalBitDepth[channelType]);
-    }
-    m_acTEncTop[layer].setPCMLog2MaxSize                                   ( m_pcmLog2MaxSize);
-    m_acTEncTop[layer].setMaxNumMergeCand                                  ( m_maxNumMergeCand );
-
-
-    //====== Weighted Prediction ========
-    m_acTEncTop[layer].setUseWP                                            ( m_useWeightedPred      );
-    m_acTEncTop[layer].setWPBiPred                                         ( m_useWeightedBiPred   );
-#if FAST_INTRA_SHVC
-    m_acTEncTop[layer].setUseFastIntraScalable                             ( m_useFastIntraScalable );
-#endif
-
-    if( layer != 0 && m_useInterLayerWeightedPred )
-    {
-      // Enable weighted prediction for enhancement layer
-      m_acTEncTop[layer].setUseWP                                           ( true   );
-      m_acTEncTop[layer].setWPBiPred                                        ( true   );
-    }
-
-    //====== Parallel Merge Estimation ========
-    m_acTEncTop[layer].setLog2ParallelMergeLevelMinus2                      ( m_log2ParallelMergeLevel - 2 );
-
-    //====== Slice ========
-    m_acTEncTop[layer].setSliceMode                                         ( (SliceConstraint) m_sliceMode );
-    m_acTEncTop[layer].setSliceArgument                                     ( m_sliceArgument            );
-
-    //====== Dependent Slice ========
-    m_acTEncTop[layer].setSliceSegmentMode                                  ( (SliceConstraint) m_sliceSegmentMode );
-    m_acTEncTop[layer].setSliceSegmentArgument                              ( m_sliceSegmentArgument     );
-
-    if(m_sliceMode == NO_SLICES )
-    {
-      m_bLFCrossSliceBoundaryFlag = true;
-    }
-
-    m_acTEncTop[layer].setLFCrossSliceBoundaryFlag                          ( m_bLFCrossSliceBoundaryFlag );
-    m_acTEncTop[layer].setUseSAO                                            ( m_bUseSAO );
-    m_acTEncTop[layer].setTestSAODisableAtPictureLevel                      ( m_bTestSAODisableAtPictureLevel );
-    m_acTEncTop[layer].setSaoEncodingRate                                   ( m_saoEncodingRate );
-    m_acTEncTop[layer].setSaoEncodingRateChroma                             ( m_saoEncodingRateChroma );
-    m_acTEncTop[layer].setMaxNumOffsetsPerPic                               ( m_maxNumOffsetsPerPic );
-
-    m_acTEncTop[layer].setSaoCtuBoundary                                    ( m_saoCtuBoundary );
-    m_acTEncTop[layer].setPCMInputBitDepthFlag                              ( m_bPCMInputBitDepthFlag);
-    m_acTEncTop[layer].setPCMFilterDisableFlag                              ( m_bPCMFilterDisableFlag);
-
-    m_acTEncTop[layer].setIntraSmoothingDisabledFlag                        (!m_enableIntraReferenceSmoothing );
-    m_acTEncTop[layer].setDecodedPictureHashSEIEnabled                      ( m_decodedPictureHashSEIEnabled );
-    m_acTEncTop[layer].setRecoveryPointSEIEnabled                           ( m_recoveryPointSEIEnabled );
-    m_acTEncTop[layer].setBufferingPeriodSEIEnabled                         ( m_bufferingPeriodSEIEnabled );
-    m_acTEncTop[layer].setPictureTimingSEIEnabled                           ( m_pictureTimingSEIEnabled );
-    m_acTEncTop[layer].setToneMappingInfoSEIEnabled                         ( m_toneMappingInfoSEIEnabled );
-    m_acTEncTop[layer].setTMISEIToneMapId                                   ( m_toneMapId );
-    m_acTEncTop[layer].setTMISEIToneMapCancelFlag                           ( m_toneMapCancelFlag );
-    m_acTEncTop[layer].setTMISEIToneMapPersistenceFlag                      ( m_toneMapPersistenceFlag );
-    m_acTEncTop[layer].setTMISEICodedDataBitDepth                           ( m_toneMapCodedDataBitDepth );
-    m_acTEncTop[layer].setTMISEITargetBitDepth                              ( m_toneMapTargetBitDepth );
-    m_acTEncTop[layer].setTMISEIModelID                                     ( m_toneMapModelId );
-    m_acTEncTop[layer].setTMISEIMinValue                                    ( m_toneMapMinValue );
-    m_acTEncTop[layer].setTMISEIMaxValue                                    ( m_toneMapMaxValue );
-    m_acTEncTop[layer].setTMISEISigmoidMidpoint                             ( m_sigmoidMidpoint );
-    m_acTEncTop[layer].setTMISEISigmoidWidth                                ( m_sigmoidWidth );
-    m_acTEncTop[layer].setTMISEIStartOfCodedInterva                         ( m_startOfCodedInterval );
-    m_acTEncTop[layer].setTMISEINumPivots                                   ( m_numPivots );
-    m_acTEncTop[layer].setTMISEICodedPivotValue                             ( m_codedPivotValue );
-    m_acTEncTop[layer].setTMISEITargetPivotValue                            ( m_targetPivotValue );
-    m_acTEncTop[layer].setTMISEICameraIsoSpeedIdc                           ( m_cameraIsoSpeedIdc );
-    m_acTEncTop[layer].setTMISEICameraIsoSpeedValue                         ( m_cameraIsoSpeedValue );
-    m_acTEncTop[layer].setTMISEIExposureIndexIdc                            ( m_exposureIndexIdc );
-    m_acTEncTop[layer].setTMISEIExposureIndexValue                          ( m_exposureIndexValue );
-    m_acTEncTop[layer].setTMISEIExposureCompensationValueSignFlag           ( m_exposureCompensationValueSignFlag );
-    m_acTEncTop[layer].setTMISEIExposureCompensationValueNumerator          ( m_exposureCompensationValueNumerator );
-    m_acTEncTop[layer].setTMISEIExposureCompensationValueDenomIdc           ( m_exposureCompensationValueDenomIdc );
-    m_acTEncTop[layer].setTMISEIRefScreenLuminanceWhite                     ( m_refScreenLuminanceWhite );
-    m_acTEncTop[layer].setTMISEIExtendedRangeWhiteLevel                     ( m_extendedRangeWhiteLevel );
-    m_acTEncTop[layer].setTMISEINominalBlackLevelLumaCodeValue              ( m_nominalBlackLevelLumaCodeValue );
-    m_acTEncTop[layer].setTMISEINominalWhiteLevelLumaCodeValue              ( m_nominalWhiteLevelLumaCodeValue );
-    m_acTEncTop[layer].setTMISEIExtendedWhiteLevelLumaCodeValue             ( m_extendedWhiteLevelLumaCodeValue );
-    m_acTEncTop[layer].setChromaSamplingFilterHintEnabled                   ( m_chromaSamplingFilterSEIenabled );
-    m_acTEncTop[layer].setChromaSamplingHorFilterIdc                        ( m_chromaSamplingHorFilterIdc );
-    m_acTEncTop[layer].setChromaSamplingVerFilterIdc                        ( m_chromaSamplingVerFilterIdc );
-    m_acTEncTop[layer].setFramePackingArrangementSEIEnabled                 ( m_framePackingSEIEnabled );
-    m_acTEncTop[layer].setFramePackingArrangementSEIType                    ( m_framePackingSEIType );
-    m_acTEncTop[layer].setFramePackingArrangementSEIId                      ( m_framePackingSEIId );
-    m_acTEncTop[layer].setFramePackingArrangementSEIQuincunx                ( m_framePackingSEIQuincunx );
-    m_acTEncTop[layer].setFramePackingArrangementSEIInterpretation          ( m_framePackingSEIInterpretation );
-    m_acTEncTop[layer].setSegmentedRectFramePackingArrangementSEIEnabled    ( m_segmentedRectFramePackingSEIEnabled );
-    m_acTEncTop[layer].setSegmentedRectFramePackingArrangementSEICancel     ( m_segmentedRectFramePackingSEICancel );
-    m_acTEncTop[layer].setSegmentedRectFramePackingArrangementSEIType       ( m_segmentedRectFramePackingSEIType );
-    m_acTEncTop[layer].setSegmentedRectFramePackingArrangementSEIPersistence( m_segmentedRectFramePackingSEIPersistence );
-    m_acTEncTop[layer].setDisplayOrientationSEIAngle                        ( m_displayOrientationSEIAngle );
-    m_acTEncTop[layer].setTemporalLevel0IndexSEIEnabled                     ( m_temporalLevel0IndexSEIEnabled );
-    m_acTEncTop[layer].setGradualDecodingRefreshInfoEnabled                 ( m_gradualDecodingRefreshInfoEnabled );
-    m_acTEncTop[layer].setNoDisplaySEITLayer                                ( m_noDisplaySEITLayer );
-    m_acTEncTop[layer].setDecodingUnitInfoSEIEnabled                        ( m_decodingUnitInfoSEIEnabled );
-    m_acTEncTop[layer].setSOPDescriptionSEIEnabled                          ( m_SOPDescriptionSEIEnabled );
-    m_acTEncTop[layer].setScalableNestingSEIEnabled                         ( m_scalableNestingSEIEnabled );
-    m_acTEncTop[layer].setTMCTSSEIEnabled                                   ( m_tmctsSEIEnabled );
-    m_acTEncTop[layer].setTimeCodeSEIEnabled                                ( m_timeCodeSEIEnabled );
-    m_acTEncTop[layer].setNumberOfTimeSets                                  ( m_timeCodeSEINumTs );
-    for(Int i = 0; i < m_timeCodeSEINumTs; i++)
-    { 
-      m_acTEncTop[layer].setTimeSet(m_timeSetArray[i], i);
-    }
-    m_acTEncTop[layer].setKneeSEIEnabled                                    ( m_kneeSEIEnabled );
-    m_acTEncTop[layer].setKneeSEIId                                         ( m_kneeSEIId );
-    m_acTEncTop[layer].setKneeSEICancelFlag                                 ( m_kneeSEICancelFlag );
-    m_acTEncTop[layer].setKneeSEIPersistenceFlag                            ( m_kneeSEIPersistenceFlag );    
-    m_acTEncTop[layer].setKneeSEIInputDrange                                ( m_kneeSEIInputDrange );
-    m_acTEncTop[layer].setKneeSEIInputDispLuminance                         ( m_kneeSEIInputDispLuminance );
-    m_acTEncTop[layer].setKneeSEIOutputDrange                               ( m_kneeSEIOutputDrange );
-    m_acTEncTop[layer].setKneeSEIOutputDispLuminance                        ( m_kneeSEIOutputDispLuminance );
-    m_acTEncTop[layer].setKneeSEINumKneePointsMinus1                        ( m_kneeSEINumKneePointsMinus1 );
-    m_acTEncTop[layer].setKneeSEIInputKneePoint                             ( m_kneeSEIInputKneePoint );
-    m_acTEncTop[layer].setKneeSEIOutputKneePoint                            ( m_kneeSEIOutputKneePoint );
-    m_acTEncTop[layer].setMasteringDisplaySEI                               ( m_masteringDisplay );
-#if P0123_ALPHA_CHANNEL_SEI
-    m_acTEncTop[layer].setAlphaSEIEnabled                                   ( m_alphaSEIEnabled );
-    m_acTEncTop[layer].setAlphaCancelFlag                                   ( m_alphaCancelFlag );
-    m_acTEncTop[layer].setAlphaUseIdc                                       ( m_alphaUseIdc );
-    m_acTEncTop[layer].setAlphaBitDepthMinus8                               ( m_alphaBitDepthMinus8 );
-    m_acTEncTop[layer].setAlphaTransparentValue                             ( m_alphaTransparentValue );
-    m_acTEncTop[layer].setAlphaOpaqueValue                                  ( m_alphaOpaqueValue );
-    m_acTEncTop[layer].setAlphaIncrementFlag                                ( m_alphaIncrementFlag );
-    m_acTEncTop[layer].setAlphaClipFlag                                     ( m_alphaClipFlag );
-    m_acTEncTop[layer].setAlphaClipTypeFlag                                 ( m_alphaClipTypeFlag );
-#endif
-#if Q0096_OVERLAY_SEI
-    m_acTEncTop[layer].setOverlaySEIEnabled                                 ( m_overlaySEIEnabled );
-    m_acTEncTop[layer].setOverlaySEICancelFlag                              ( m_overlayInfoCancelFlag );
-    m_acTEncTop[layer].setOverlaySEIContentAuxIdMinus128                    ( m_overlayContentAuxIdMinus128 );
-    m_acTEncTop[layer].setOverlaySEILabelAuxIdMinus128                      ( m_overlayLabelAuxIdMinus128 );
-    m_acTEncTop[layer].setOverlaySEIAlphaAuxIdMinus128                      ( m_overlayAlphaAuxIdMinus128 );
-    m_acTEncTop[layer].setOverlaySEIElementLabelValueLengthMinus8           ( m_overlayElementLabelValueLengthMinus8 );
-    m_acTEncTop[layer].setOverlaySEINumOverlaysMinus1                       ( m_numOverlaysMinus1 );
-    m_acTEncTop[layer].setOverlaySEIIdx                                     ( m_overlayIdx );
-    m_acTEncTop[layer].setOverlaySEILanguagePresentFlag                     ( m_overlayLanguagePresentFlag );
-    m_acTEncTop[layer].setOverlaySEIContentLayerId                          ( m_overlayContentLayerId );
-    m_acTEncTop[layer].setOverlaySEILabelPresentFlag                        ( m_overlayLabelPresentFlag );
-    m_acTEncTop[layer].setOverlaySEILabelLayerId                            ( m_overlayLabelLayerId );
-    m_acTEncTop[layer].setOverlaySEIAlphaPresentFlag                        ( m_overlayAlphaPresentFlag );
-    m_acTEncTop[layer].setOverlaySEIAlphaLayerId                            ( m_overlayAlphaLayerId );
-    m_acTEncTop[layer].setOverlaySEINumElementsMinus1                       ( m_numOverlayElementsMinus1 );
-    m_acTEncTop[layer].setOverlaySEIElementLabelMin                         ( m_overlayElementLabelMin );
-    m_acTEncTop[layer].setOverlaySEIElementLabelMax                         ( m_overlayElementLabelMax );
-    m_acTEncTop[layer].setOverlaySEILanguage                                ( m_overlayLanguage );
-    m_acTEncTop[layer].setOverlaySEIName                                    ( m_overlayName );
-    m_acTEncTop[layer].setOverlaySEIElementName                             ( m_overlayElementName );
-    m_acTEncTop[layer].setOverlaySEIPersistenceFlag                         ( m_overlayInfoPersistenceFlag );
-#endif
-#if Q0074_COLOUR_REMAPPING_SEI
-    m_acTEncTop[layer].setCRISEIFileRoot                                    ( const_cast<Char*>(m_acLayerCfg[layer].m_colourRemapSEIFileRoot.c_str()) );
-#endif    
-#if LAYERS_NOT_PRESENT_SEI
-    m_acTEncTop[layer].setLayersNotPresentSEIEnabled            ( m_layersNotPresentSEIEnabled );
-#endif    
-#if Q0189_TMVP_CONSTRAINTS
-    m_acTEncTop[layer].setTMVPConstraintsSEIEnabled             ( m_TMVPConstraintsSEIEnabled);           
-#endif
-#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
-    m_acTEncTop[layer].setInterLayerConstrainedTileSetsSEIEnabled( m_interLayerConstrainedTileSetsSEIEnabled );
-    m_acTEncTop[layer].setIlNumSetsInMessage                    ( m_ilNumSetsInMessage );
-    m_acTEncTop[layer].setSkippedTileSetPresentFlag             ( m_skippedTileSetPresentFlag );
-    m_acTEncTop[layer].setTopLeftTileIndex                      ( m_topLeftTileIndex );
-    m_acTEncTop[layer].setBottomRightTileIndex                  ( m_bottomRightTileIndex );
-    m_acTEncTop[layer].setIlcIdc                                ( m_ilcIdc );
-#endif
-    m_acTEncTop[layer].setTileUniformSpacingFlag                ( m_tileUniformSpacingFlag );
-    m_acTEncTop[layer].setNumColumnsMinus1                      ( m_numTileColumnsMinus1 );
-    m_acTEncTop[layer].setNumRowsMinus1                         ( m_numTileRowsMinus1 );
-    if(!m_tileUniformSpacingFlag)
-    {
-      m_acTEncTop[layer].setColumnWidth                         ( m_tileColumnWidth );
-      m_acTEncTop[layer].setRowHeight                           ( m_tileRowHeight );
-    }
-    m_acTEncTop[layer].xCheckGSParameters();
-    Int uiTilesCount = (m_numTileRowsMinus1+1) * (m_numTileColumnsMinus1+1);
-    if(uiTilesCount == 1)
-    {
-      m_bLFCrossTileBoundaryFlag = true;
-    }
-    m_acTEncTop[layer].setLFCrossTileBoundaryFlag               ( m_bLFCrossTileBoundaryFlag );
-    m_acTEncTop[layer].setWaveFrontSynchro                      ( m_acLayerCfg[layer].m_waveFrontSynchro );
-    m_acTEncTop[layer].setTMVPModeId                            ( m_TMVPModeId );
-    m_acTEncTop[layer].setUseScalingListId                      ( m_useScalingListId  );
-    m_acTEncTop[layer].setScalingListFile                       ( m_scalingListFile   );
-    m_acTEncTop[layer].setSignHideFlag                          ( m_signHideFlag );
-#if RC_SHVC_HARMONIZATION
-    m_acTEncTop[layer].setUseRateCtrl                           ( m_acLayerCfg[layer].getRCEnableRateControl() );
-    m_acTEncTop[layer].setTargetBitrate                         ( m_acLayerCfg[layer].getRCTargetBitrate() );
-    m_acTEncTop[layer].setKeepHierBit                           ( m_acLayerCfg[layer].getRCKeepHierarchicalBit() );
-    m_acTEncTop[layer].setLCULevelRC                            ( m_acLayerCfg[layer].getRCLCULevelRC() );
-    m_acTEncTop[layer].setUseLCUSeparateModel                   ( m_acLayerCfg[layer].getRCUseLCUSeparateModel() );
-    m_acTEncTop[layer].setInitialQP                             ( m_acLayerCfg[layer].getRCInitialQP() );
-    m_acTEncTop[layer].setForceIntraQP                          ( m_acLayerCfg[layer].getRCForceIntraQP() );
-#else
-    m_acTEncTop[layer].setUseRateCtrl                           ( m_RCEnableRateControl );
-    m_acTEncTop[layer].setTargetBitrate                         ( m_RCTargetBitrate );
-    m_acTEncTop[layer].setKeepHierBit                           ( m_RCKeepHierarchicalBit );
-    m_acTEncTop[layer].setLCULevelRC                            ( m_RCLCULevelRC );
-    m_acTEncTop[layer].setUseLCUSeparateModel                   ( m_RCUseLCUSeparateModel );
-    m_acTEncTop[layer].setInitialQP                             ( m_RCInitialQP );
-    m_acTEncTop[layer].setForceIntraQP                          ( m_RCForceIntraQP );
-#endif
-    m_acTEncTop[layer].setTransquantBypassEnableFlag            ( m_TransquantBypassEnableFlag );
-    m_acTEncTop[layer].setCUTransquantBypassFlagForceValue      ( m_CUTransquantBypassFlagForce );
-    m_acTEncTop[layer].setCostMode                              ( m_costMode );
-    m_acTEncTop[layer].setUseRecalculateQPAccordingToLambda     ( m_recalculateQPAccordingToLambda );
-    m_acTEncTop[layer].setUseStrongIntraSmoothing               ( m_useStrongIntraSmoothing );
-    m_acTEncTop[layer].setActiveParameterSetsSEIEnabled         ( m_activeParameterSetsSEIEnabled );
-    m_acTEncTop[layer].setVuiParametersPresentFlag              ( m_vuiParametersPresentFlag );
-    m_acTEncTop[layer].setAspectRatioInfoPresentFlag            ( m_aspectRatioInfoPresentFlag);
-    m_acTEncTop[layer].setAspectRatioIdc                        ( m_aspectRatioIdc );
-    m_acTEncTop[layer].setSarWidth                              ( m_sarWidth );
-    m_acTEncTop[layer].setSarHeight                             ( m_sarHeight );
-    m_acTEncTop[layer].setOverscanInfoPresentFlag               ( m_overscanInfoPresentFlag );
-    m_acTEncTop[layer].setOverscanAppropriateFlag               ( m_overscanAppropriateFlag );
-    m_acTEncTop[layer].setVideoSignalTypePresentFlag            ( m_videoSignalTypePresentFlag );
-    m_acTEncTop[layer].setVideoFormat                           ( m_videoFormat );
-    m_acTEncTop[layer].setVideoFullRangeFlag                    ( m_videoFullRangeFlag );
-    m_acTEncTop[layer].setColourDescriptionPresentFlag          ( m_colourDescriptionPresentFlag );
-    m_acTEncTop[layer].setColourPrimaries                       ( m_colourPrimaries );
-    m_acTEncTop[layer].setTransferCharacteristics               ( m_transferCharacteristics );
-    m_acTEncTop[layer].setMatrixCoefficients                    ( m_matrixCoefficients );
-    m_acTEncTop[layer].setChromaLocInfoPresentFlag              ( m_chromaLocInfoPresentFlag );
-    m_acTEncTop[layer].setChromaSampleLocTypeTopField           ( m_chromaSampleLocTypeTopField );
-    m_acTEncTop[layer].setChromaSampleLocTypeBottomField        ( m_chromaSampleLocTypeBottomField );
-    m_acTEncTop[layer].setNeutralChromaIndicationFlag           ( m_neutralChromaIndicationFlag );
-    m_acTEncTop[layer].setDefaultDisplayWindow                  ( m_defDispWinLeftOffset, m_defDispWinRightOffset, m_defDispWinTopOffset, m_defDispWinBottomOffset );
-    m_acTEncTop[layer].setFrameFieldInfoPresentFlag             ( m_frameFieldInfoPresentFlag );
-    m_acTEncTop[layer].setPocProportionalToTimingFlag           ( m_pocProportionalToTimingFlag );
-    m_acTEncTop[layer].setNumTicksPocDiffOneMinus1              ( m_numTicksPocDiffOneMinus1    );
-    m_acTEncTop[layer].setBitstreamRestrictionFlag              ( m_bitstreamRestrictionFlag );
-    m_acTEncTop[layer].setTilesFixedStructureFlag               ( m_tilesFixedStructureFlag );
-    m_acTEncTop[layer].setMotionVectorsOverPicBoundariesFlag    ( m_motionVectorsOverPicBoundariesFlag );
-    m_acTEncTop[layer].setMinSpatialSegmentationIdc             ( m_minSpatialSegmentationIdc );
-    m_acTEncTop[layer].setMaxBytesPerPicDenom                   ( m_maxBytesPerPicDenom );
-    m_acTEncTop[layer].setMaxBitsPerMinCuDenom                  ( m_maxBitsPerMinCuDenom );
-    m_acTEncTop[layer].setLog2MaxMvLengthHorizontal             ( m_log2MaxMvLengthHorizontal );
-    m_acTEncTop[layer].setLog2MaxMvLengthVertical               ( m_log2MaxMvLengthVertical );
-    m_acTEncTop[layer].setElRapSliceTypeB                       (layer == 0? 0 : m_elRapSliceBEnabled);
-    m_acTEncTop[layer].setEfficientFieldIRAPEnabled             ( m_bEfficientFieldIRAPEnabled );
-    m_acTEncTop[layer].setHarmonizeGopFirstFieldCoupleEnabled   ( m_bHarmonizeGopFirstFieldCoupleEnabled );
-
-    m_acTEncTop[layer].setSummaryOutFilename                    ( m_summaryOutFilename );
-    m_acTEncTop[layer].setSummaryPicFilenameBase                ( m_summaryPicFilenameBase );
-    m_acTEncTop[layer].setSummaryVerboseness                    ( m_summaryVerboseness );
+      m_cTEncTop.setNumDirectRefLayers(0);
+    }
 
     if( layer > 0 )
     {
 #if AUXILIARY_PICTURES
-      Int subWidthC  = ( m_acLayerCfg[layer].m_chromaFormatIDC == CHROMA_420 || m_acLayerCfg[layer].m_chromaFormatIDC == CHROMA_422 ) ? 2 : 1;
-      Int subHeightC = ( m_acLayerCfg[layer].m_chromaFormatIDC == CHROMA_420 ) ? 2 : 1;
+      Int subWidthC  = ( m_apcLayerCfg[layer]->m_chromaFormatIDC == CHROMA_420 || m_apcLayerCfg[layer]->m_chromaFormatIDC == CHROMA_422 ) ? 2 : 1;
+      Int subHeightC = ( m_apcLayerCfg[layer]->m_chromaFormatIDC == CHROMA_420 ) ? 2 : 1;
 #else
       Int subWidthC  = 2;
       Int subHeightC = 2;
 #endif
-      m_acTEncTop[layer].setNumRefLayerLocationOffsets          ( m_acLayerCfg[layer].m_numRefLayerLocationOffsets );
-      for(Int i = 0; i < m_acLayerCfg[layer].m_numRefLayerLocationOffsets; i++)
-      {
-        m_acTEncTop[layer].setRefLocationOffsetLayerId          (i, m_acLayerCfg[layer].m_refLocationOffsetLayerId[i]);
-        m_acTEncTop[layer].setScaledRefLayerOffsetPresentFlag   ( i, m_acLayerCfg[layer].m_scaledRefLayerOffsetPresentFlag[i] );
-        m_acTEncTop[layer].getScaledRefLayerWindow(i).setWindow ( subWidthC  * m_acLayerCfg[layer].m_scaledRefLayerLeftOffset[i], subWidthC  * m_acLayerCfg[layer].m_scaledRefLayerRightOffset[i],
-                                                                  subHeightC * m_acLayerCfg[layer].m_scaledRefLayerTopOffset[i],  subHeightC * m_acLayerCfg[layer].m_scaledRefLayerBottomOffset[i]);
-
-        Int rlSubWidthC  = ( m_acLayerCfg[i].m_chromaFormatIDC == CHROMA_420 || m_acLayerCfg[i].m_chromaFormatIDC == CHROMA_422 ) ? 2 : 1;
-        Int rlSubHeightC = ( m_acLayerCfg[i].m_chromaFormatIDC == CHROMA_420 ) ? 2 : 1;
-
-        m_acTEncTop[layer].setRefRegionOffsetPresentFlag        ( i, m_acLayerCfg[layer].m_refRegionOffsetPresentFlag[i] );
-        m_acTEncTop[layer].getRefLayerWindow(i).setWindow       ( rlSubWidthC  * m_acLayerCfg[layer].m_refRegionLeftOffset[i], rlSubWidthC  * m_acLayerCfg[layer].m_refRegionRightOffset[i],
-                                                                  rlSubHeightC * m_acLayerCfg[layer].m_refRegionTopOffset[i],  rlSubHeightC * m_acLayerCfg[layer].m_refRegionBottomOffset[i]);
-        m_acTEncTop[layer].setResamplePhaseSetPresentFlag       ( i, m_acLayerCfg[layer].m_resamplePhaseSetPresentFlag[i] );
-        m_acTEncTop[layer].setPhaseHorLuma                      ( i, m_acLayerCfg[layer].m_phaseHorLuma[i] );
-        m_acTEncTop[layer].setPhaseVerLuma                      ( i, m_acLayerCfg[layer].m_phaseVerLuma[i] );
-        m_acTEncTop[layer].setPhaseHorChroma                    ( i, m_acLayerCfg[layer].m_phaseHorChroma[i] );
-        m_acTEncTop[layer].setPhaseVerChroma                    ( i, m_acLayerCfg[layer].m_phaseVerChroma[i] );
-      }
-    }
-
-    m_acTEncTop[layer].setAdaptiveResolutionChange               ( m_adaptiveResolutionChange );
-    m_acTEncTop[layer].setLayerSwitchOffBegin                    ( m_acLayerCfg[layer].m_layerSwitchOffBegin );
-    m_acTEncTop[layer].setLayerSwitchOffEnd                      ( m_acLayerCfg[layer].m_layerSwitchOffEnd );
-#if AUXILIARY_PICTURES
-    m_acTEncTop[layer].setChromaFormatIDC                        ( m_acLayerCfg[layer].m_chromaFormatIDC );
-#endif
-    m_acTEncTop[layer].setAltOuputLayerFlag                      ( m_altOutputLayerFlag );
-    m_acTEncTop[layer].setCrossLayerBLAFlag                      ( m_crossLayerBLAFlag );
+      m_cTEncTop.setNumRefLayerLocationOffsets          ( m_apcLayerCfg[layer]->m_numRefLayerLocationOffsets );
+      for(Int i = 0; i < m_apcLayerCfg[layer]->m_numRefLayerLocationOffsets; i++)
+      {
+        m_cTEncTop.setRefLocationOffsetLayerId          ( i, m_apcLayerCfg[layer]->m_refLocationOffsetLayerId[i]);
+        m_cTEncTop.setScaledRefLayerOffsetPresentFlag   ( i, m_apcLayerCfg[layer]->m_scaledRefLayerOffsetPresentFlag[i] );
+        m_cTEncTop.getScaledRefLayerWindow(i).setWindow ( subWidthC  * m_apcLayerCfg[layer]->m_scaledRefLayerLeftOffset[i], subWidthC  * m_apcLayerCfg[layer]->m_scaledRefLayerRightOffset[i],
+          subHeightC * m_apcLayerCfg[layer]->m_scaledRefLayerTopOffset[i],  subHeightC * m_apcLayerCfg[layer]->m_scaledRefLayerBottomOffset[i]);
+
+        Int rlSubWidthC  = ( m_apcLayerCfg[i]->m_chromaFormatIDC == CHROMA_420 || m_apcLayerCfg[i]->m_chromaFormatIDC == CHROMA_422 ) ? 2 : 1;
+        Int rlSubHeightC = ( m_apcLayerCfg[i]->m_chromaFormatIDC == CHROMA_420 ) ? 2 : 1;
+
+        m_cTEncTop.setRefRegionOffsetPresentFlag        ( i, m_apcLayerCfg[layer]->m_refRegionOffsetPresentFlag[i] );
+        m_cTEncTop.getRefLayerWindow(i).setWindow       ( rlSubWidthC  * m_apcLayerCfg[layer]->m_refRegionLeftOffset[i], rlSubWidthC  * m_apcLayerCfg[layer]->m_refRegionRightOffset[i],
+          rlSubHeightC * m_apcLayerCfg[layer]->m_refRegionTopOffset[i],  rlSubHeightC * m_apcLayerCfg[layer]->m_refRegionBottomOffset[i]);
+        m_cTEncTop.setResamplePhaseSetPresentFlag       ( i, m_apcLayerCfg[layer]->m_resamplePhaseSetPresentFlag[i] );
+        m_cTEncTop.setPhaseHorLuma                      ( i, m_apcLayerCfg[layer]->m_phaseHorLuma[i] );
+        m_cTEncTop.setPhaseVerLuma                      ( i, m_apcLayerCfg[layer]->m_phaseVerLuma[i] );
+        m_cTEncTop.setPhaseHorChroma                    ( i, m_apcLayerCfg[layer]->m_phaseHorChroma[i] );
+        m_cTEncTop.setPhaseVerChroma                    ( i, m_apcLayerCfg[layer]->m_phaseVerChroma[i] );
+      }
+    }
+
+    m_cTEncTop.setAdaptiveResolutionChange               ( m_adaptiveResolutionChange );
+    m_cTEncTop.setLayerSwitchOffBegin                    ( m_apcLayerCfg[layer]->m_layerSwitchOffBegin );
+    m_cTEncTop.setLayerSwitchOffEnd                      ( m_apcLayerCfg[layer]->m_layerSwitchOffEnd );
+    m_cTEncTop.setChromaFormatIDC                        ( m_apcLayerCfg[layer]->m_chromaFormatIDC );
+    m_cTEncTop.setAltOuputLayerFlag                      ( m_altOutputLayerFlag );
+    m_cTEncTop.setCrossLayerBLAFlag                      ( m_crossLayerBLAFlag );
 #if CGS_3D_ASYMLUT
-    m_acTEncTop[layer].setCGSFlag                                ( layer == 0 ? 0 : m_nCGSFlag );
-    m_acTEncTop[layer].setCGSMaxOctantDepth                      ( m_nCGSMaxOctantDepth );
-    m_acTEncTop[layer].setCGSMaxYPartNumLog2                     ( m_nCGSMaxYPartNumLog2 );
-    m_acTEncTop[layer].setCGSLUTBit                              ( m_nCGSLUTBit );
-    m_acTEncTop[layer].setCGSAdaptChroma                         ( m_nCGSAdaptiveChroma );
+    m_cTEncTop.setCGSFlag                                ( layer == 0 ? 0 : m_nCGSFlag );
+    m_cTEncTop.setCGSMaxOctantDepth                      ( m_nCGSMaxOctantDepth );
+    m_cTEncTop.setCGSMaxYPartNumLog2                     ( m_nCGSMaxYPartNumLog2 );
+    m_cTEncTop.setCGSLUTBit                              ( m_nCGSLUTBit );
+    m_cTEncTop.setCGSAdaptChroma                         ( m_nCGSAdaptiveChroma );
 #if R0179_ENC_OPT_3DLUT_SIZE
-    m_acTEncTop[layer].setCGSLutSizeRDO                          ( m_nCGSLutSizeRDO );
-#endif
-#endif
-    m_acTEncTop[layer].setNumAddLayerSets                        ( m_numAddLayerSets );
-  }
-}
-#else //SVC_EXTENSION
-Void TAppEncTop::xInitLibCfg()
-{
-  TComVPS vps;
-
-  vps.setMaxTLayers                                               ( m_maxTempLayer );
-  if (m_maxTempLayer == 1)
-  {
-    vps.setTemporalNestingFlag(true);
-  }
-  vps.setMaxLayers                                                ( 1 );
-  for(Int i = 0; i < MAX_TLAYER; i++)
-  {
-    vps.setNumReorderPics                                         ( m_numReorderPics[i], i );
-    vps.setMaxDecPicBuffering                                     ( m_maxDecPicBuffering[i], i );
-  }
-  m_cTEncTop.setVPS(&vps);
+    m_cTEncTop.setCGSLutSizeRDO                          ( m_nCGSLutSizeRDO );
+#endif
+#endif
+    m_cTEncTop.setNumAddLayerSets                        ( m_numAddLayerSets );
+
+#if P0123_ALPHA_CHANNEL_SEI
+    m_cTEncTop.setAlphaSEIEnabled                                   ( m_alphaSEIEnabled );
+    m_cTEncTop.setAlphaCancelFlag                                   ( m_alphaCancelFlag );
+    m_cTEncTop.setAlphaUseIdc                                       ( m_alphaUseIdc );
+    m_cTEncTop.setAlphaBitDepthMinus8                               ( m_alphaBitDepthMinus8 );
+    m_cTEncTop.setAlphaTransparentValue                             ( m_alphaTransparentValue );
+    m_cTEncTop.setAlphaOpaqueValue                                  ( m_alphaOpaqueValue );
+    m_cTEncTop.setAlphaIncrementFlag                                ( m_alphaIncrementFlag );
+    m_cTEncTop.setAlphaClipFlag                                     ( m_alphaClipFlag );
+    m_cTEncTop.setAlphaClipTypeFlag                                 ( m_alphaClipTypeFlag );
+#endif
+#if Q0096_OVERLAY_SEI
+    m_cTEncTop.setOverlaySEIEnabled                                 ( m_overlaySEIEnabled );
+    m_cTEncTop.setOverlaySEICancelFlag                              ( m_overlayInfoCancelFlag );
+    m_cTEncTop.setOverlaySEIContentAuxIdMinus128                    ( m_overlayContentAuxIdMinus128 );
+    m_cTEncTop.setOverlaySEILabelAuxIdMinus128                      ( m_overlayLabelAuxIdMinus128 );
+    m_cTEncTop.setOverlaySEIAlphaAuxIdMinus128                      ( m_overlayAlphaAuxIdMinus128 );
+    m_cTEncTop.setOverlaySEIElementLabelValueLengthMinus8           ( m_overlayElementLabelValueLengthMinus8 );
+    m_cTEncTop.setOverlaySEINumOverlaysMinus1                       ( m_numOverlaysMinus1 );
+    m_cTEncTop.setOverlaySEIIdx                                     ( m_overlayIdx );
+    m_cTEncTop.setOverlaySEILanguagePresentFlag                     ( m_overlayLanguagePresentFlag );
+    m_cTEncTop.setOverlaySEIContentLayerId                          ( m_overlayContentLayerId );
+    m_cTEncTop.setOverlaySEILabelPresentFlag                        ( m_overlayLabelPresentFlag );
+    m_cTEncTop.setOverlaySEILabelLayerId                            ( m_overlayLabelLayerId );
+    m_cTEncTop.setOverlaySEIAlphaPresentFlag                        ( m_overlayAlphaPresentFlag );
+    m_cTEncTop.setOverlaySEIAlphaLayerId                            ( m_overlayAlphaLayerId );
+    m_cTEncTop.setOverlaySEINumElementsMinus1                       ( m_numOverlayElementsMinus1 );
+    m_cTEncTop.setOverlaySEIElementLabelMin                         ( m_overlayElementLabelMin );
+    m_cTEncTop.setOverlaySEIElementLabelMax                         ( m_overlayElementLabelMax );
+    m_cTEncTop.setOverlaySEILanguage                                ( m_overlayLanguage );
+    m_cTEncTop.setOverlaySEIName                                    ( m_overlayName );
+    m_cTEncTop.setOverlaySEIElementName                             ( m_overlayElementName );
+    m_cTEncTop.setOverlaySEIPersistenceFlag                         ( m_overlayInfoPersistenceFlag );
+#endif  
+#if Q0189_TMVP_CONSTRAINTS
+    m_cTEncTop.setTMVPConstraintsSEIEnabled                         ( m_TMVPConstraintsSEIEnabled);           
+#endif
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+    m_cTEncTop.setInterLayerConstrainedTileSetsSEIEnabled           ( m_interLayerConstrainedTileSetsSEIEnabled );
+    m_cTEncTop.setIlNumSetsInMessage                                ( m_ilNumSetsInMessage );
+    m_cTEncTop.setSkippedTileSetPresentFlag                         ( m_skippedTileSetPresentFlag );
+    m_cTEncTop.setTopLeftTileIndex                                  ( m_topLeftTileIndex );
+    m_cTEncTop.setBottomRightTileIndex                              ( m_bottomRightTileIndex );
+    m_cTEncTop.setIlcIdc                                            ( m_ilcIdc );
+#endif
+
+    Int layerPTLIdx = m_apcLayerCfg[layer]->m_layerPTLIdx;
+
+    Profile::Name m_profile                                    = m_profileList[layerPTLIdx];
+    Level::Tier   m_levelTier                                  = m_levelTierList[layerPTLIdx];
+    Level::Name   m_level                                      = m_levelList[layerPTLIdx];
+    UInt          m_bitDepthConstraint                         = m_apcLayerCfg[layer]->m_bitDepthConstraint;
+    ChromaFormat  m_chromaFormatConstraint                     = m_apcLayerCfg[layer]->m_chromaFormatConstraint;
+    Bool          m_intraConstraintFlag                        = m_apcLayerCfg[layer]->m_intraConstraintFlag;
+    Bool          m_onePictureOnlyConstraintFlag               = m_apcLayerCfg[layer]->m_onePictureOnlyConstraintFlag;
+    Bool          m_lowerBitRateConstraintFlag                 = m_apcLayerCfg[layer]->m_lowerBitRateConstraintFlag;
+    Bool          m_progressiveSourceFlag                      = m_progressiveSourceFlagList[layerPTLIdx];
+    Bool          m_interlacedSourceFlag                       = m_interlacedSourceFlagList[layerPTLIdx];
+    Bool          m_nonPackedConstraintFlag                    = m_nonPackedConstraintFlagList[layerPTLIdx];
+    Bool          m_frameOnlyConstraintFlag                    = m_frameOnlyConstraintFlagList[layerPTLIdx];
+
+    Int           m_iFrameRate                                 = m_apcLayerCfg[layer]->getFrameRate();
+    Int           m_iSourceWidth                               = m_apcLayerCfg[layer]->getSourceWidth();
+    Int           m_iSourceHeight                              = m_apcLayerCfg[layer]->getSourceHeight();
+    Int           m_confWinLeft                                = m_apcLayerCfg[layer]->m_confWinLeft;
+    Int           m_confWinRight                               = m_apcLayerCfg[layer]->m_confWinRight;
+    Int           m_confWinTop                                 = m_apcLayerCfg[layer]->m_confWinTop;
+    Int           m_confWinBottom                              = m_apcLayerCfg[layer]->m_confWinBottom;
+
+    Int           m_iIntraPeriod                               = m_apcLayerCfg[layer]->m_iIntraPeriod;
+    Int           m_iQP                                        = m_apcLayerCfg[layer]->getIntQP();
+    Int          *m_aiPad                                      = m_apcLayerCfg[layer]->getPad();
+
+    Int           m_iMaxCuDQPDepth                             = m_apcLayerCfg[layer]->m_iMaxCuDQPDepth;
+    ChromaFormat  m_chromaFormatIDC                            = m_apcLayerCfg[layer]->m_chromaFormatIDC;
+    Bool          m_extendedPrecisionProcessingFlag            = m_apcLayerCfg[layer]->m_extendedPrecisionProcessingFlag;
+    Bool          m_highPrecisionOffsetsEnabledFlag            = m_apcLayerCfg[layer]->m_highPrecisionOffsetsEnabledFlag;
+    Int           *m_aidQP                                     = m_apcLayerCfg[layer]->getdQPs();
+
+    UInt          m_uiMaxCUWidth                               = m_apcLayerCfg[layer]->m_uiMaxCUWidth;
+    UInt          m_uiMaxCUHeight                              = m_apcLayerCfg[layer]->m_uiMaxCUHeight;
+    UInt          m_uiMaxTotalCUDepth                          = m_apcLayerCfg[layer]->m_uiMaxTotalCUDepth;
+    UInt          m_uiLog2DiffMaxMinCodingBlockSize            = m_apcLayerCfg[layer]->m_uiLog2DiffMaxMinCodingBlockSize;
+    UInt          m_uiQuadtreeTULog2MaxSize                    = m_apcLayerCfg[layer]->m_uiQuadtreeTULog2MaxSize;
+    UInt          m_uiQuadtreeTULog2MinSize                    = m_apcLayerCfg[layer]->m_uiQuadtreeTULog2MinSize;
+    UInt          m_uiQuadtreeTUMaxDepthInter                  = m_apcLayerCfg[layer]->m_uiQuadtreeTUMaxDepthInter;
+    UInt          m_uiQuadtreeTUMaxDepthIntra                  = m_apcLayerCfg[layer]->m_uiQuadtreeTUMaxDepthIntra;
+
+    Int           m_iWaveFrontSynchro                          = m_apcLayerCfg[layer]->m_waveFrontSynchro;
+    Bool          m_RCEnableRateControl                        = m_apcLayerCfg[layer]->getRCEnableRateControl();
+    Int           m_RCTargetBitrate                            = m_apcLayerCfg[layer]->getRCTargetBitrate();
+    Bool          m_RCKeepHierarchicalBit                      = m_apcLayerCfg[layer]->getRCKeepHierarchicalBit();
+    Bool          m_RCLCULevelRC                               = m_apcLayerCfg[layer]->getRCLCULevelRC();
+    Bool          m_RCUseLCUSeparateModel                      = m_apcLayerCfg[layer]->getRCUseLCUSeparateModel();
+    Int           m_RCInitialQP                                = m_apcLayerCfg[layer]->getRCInitialQP();
+    Bool          m_RCForceIntraQP                             = m_apcLayerCfg[layer]->getRCForceIntraQP();
+#endif
 
   m_cTEncTop.setProfile                                           ( m_profile);
@@ -830,6 +517,12 @@
   m_cTEncTop.setDecodingRefreshType                               ( m_iDecodingRefreshType );
   m_cTEncTop.setGOPSize                                           ( m_iGOPSize );
+#if SVC_EXTENSION
+  m_cTEncTop.setGopList                                           ( layer ? m_EhGOPList[layer] : m_GOPList );
+  m_cTEncTop.setExtraRPSs                                         ( m_extraRPSs[layer] );
+#else
   m_cTEncTop.setGopList                                           ( m_GOPList );
   m_cTEncTop.setExtraRPSs                                         ( m_extraRPSs );
+#endif
+
   for(Int i = 0; i < MAX_TLAYER; i++)
   {
@@ -845,5 +538,9 @@
   m_cTEncTop.setPad                                               ( m_aiPad );
 
+#if SVC_EXTENSION
+  m_cTEncTop.setMaxTempLayer                                      ( layer ? m_EhMaxTempLayer[layer] : m_maxTempLayer );
+#else
   m_cTEncTop.setMaxTempLayer                                      ( m_maxTempLayer );
+#endif
   m_cTEncTop.setUseAMP( m_enableAMP );
 
@@ -907,7 +604,4 @@
   m_cTEncTop.setUseCbfFastMode                                    ( m_bUseCbfFastMode  );
   m_cTEncTop.setUseEarlySkipDetection                             ( m_useEarlySkipDetection );
-#if FAST_INTRA_SHVC
-  m_cTEncTop.setUseFastIntraScalable                              ( m_useFastIntraScalable );
-#endif
   m_cTEncTop.setCrossComponentPredictionEnabledFlag               ( m_crossComponentPredictionEnabledFlag );
   m_cTEncTop.setUseReconBasedCrossCPredictionEstimate             ( m_reconBasedCrossCPredictionEstimate );
@@ -935,6 +629,11 @@
   for (UInt channelType = 0; channelType < MAX_NUM_CHANNEL_TYPE; channelType++)
   {
+#if SVC_EXTENSION
+    m_cTEncTop.setBitDepth((ChannelType)channelType, m_apcLayerCfg[layer]->m_internalBitDepth[channelType]);
+    m_cTEncTop.setPCMBitDepth((ChannelType)channelType, m_bPCMInputBitDepthFlag ? m_apcLayerCfg[layer]->m_MSBExtendedBitDepth[channelType] : m_apcLayerCfg[layer]->m_internalBitDepth[channelType]);
+#else
     m_cTEncTop.setBitDepth((ChannelType)channelType, m_internalBitDepth[channelType]);
     m_cTEncTop.setPCMBitDepth((ChannelType)channelType, m_bPCMInputBitDepthFlag ? m_MSBExtendedBitDepth[channelType] : m_internalBitDepth[channelType]);
+#endif
   }
 
@@ -1042,10 +741,5 @@
   m_cTEncTop.setKneeSEIOutputKneePoint                            ( m_kneeSEIOutputKneePoint );
   m_cTEncTop.setMasteringDisplaySEI                               ( m_masteringDisplay );
-#if Q0074_COLOUR_REMAPPING_SEI
-  m_cTEncTop.setCRISEIFileRoot                                    ( const_cast<Char*>(m_colourRemapSEIFileRoot.c_str()) );
-#endif
-#if LAYERS_NOT_PRESENT_SEI
-  m_cTEncTop.setLayersNotPresentSEIEnabled( m_layersNotPresentSEIEnabled );
-#endif
+
   m_cTEncTop.setTileUniformSpacingFlag                            ( m_tileUniformSpacingFlag );
   m_cTEncTop.setNumColumnsMinus1                                  ( m_numTileColumnsMinus1 );
@@ -1117,6 +811,31 @@
   m_cTEncTop.setSummaryPicFilenameBase                            ( m_summaryPicFilenameBase );
   m_cTEncTop.setSummaryVerboseness                                ( m_summaryVerboseness );
+
+#if FAST_INTRA_SHVC
+  m_cTEncTop.setUseFastIntraScalable                              ( m_useFastIntraScalable );
+#endif
+#if Q0074_COLOUR_REMAPPING_SEI
+#if SVC_EXTENSION
+  m_cTEncTop.setCRISEIFileRoot                                    ( const_cast<Char*>(m_apcLayerCfg[layer]->m_colourRemapSEIFileRoot.c_str()) );
+#else
+  m_cTEncTop.setCRISEIFileRoot                                    ( const_cast<Char*>(m_colourRemapSEIFileRoot.c_str()) );
+#endif
+#endif
+#if LAYERS_NOT_PRESENT_SEI
+  m_cTEncTop.setLayersNotPresentSEIEnabled                        ( m_layersNotPresentSEIEnabled );
+#endif  
+
+
+#if SVC_EXTENSION
+  if( layer != 0 && m_useInterLayerWeightedPred )
+  {
+    // Enable weighted prediction for enhancement layer
+    m_cTEncTop.setUseWP                                           ( true   );
+    m_cTEncTop.setWPBiPred                                        ( true   );
+  }
+
+  }
+#endif
 }
-#endif //SVC_EXTENSION
 
 Void TAppEncTop::xCreateLib()
@@ -1131,14 +850,14 @@
     //2
     // Video I/O
-    m_acTVideoIOYuvInputFile[layer].open( (Char *)m_acLayerCfg[layer].getInputFile().c_str(),  false, m_acLayerCfg[layer].m_inputBitDepth, m_acLayerCfg[layer].m_MSBExtendedBitDepth, m_acLayerCfg[layer].m_internalBitDepth );  // read  mode
-    m_acTVideoIOYuvInputFile[layer].skipFrames(m_FrameSkip, m_acLayerCfg[layer].getSourceWidth() - m_acLayerCfg[layer].getPad()[0], m_acLayerCfg[layer].getSourceHeight() - m_acLayerCfg[layer].getPad()[1], m_acLayerCfg[layer].m_InputChromaFormatIDC);
-
-    if( !m_acLayerCfg[layer].getReconFile().empty() )
-    {
-      m_acTVideoIOYuvReconFile[layer].open((Char *)m_acLayerCfg[layer].getReconFile().c_str(), true, m_acLayerCfg[layer].m_outputBitDepth, m_acLayerCfg[layer].m_MSBExtendedBitDepth, m_acLayerCfg[layer].m_internalBitDepth );  // write mode
+    m_apcTVideoIOYuvInputFile[layer]->open( (Char *)m_apcLayerCfg[layer]->getInputFile().c_str(),  false, m_apcLayerCfg[layer]->m_inputBitDepth, m_apcLayerCfg[layer]->m_MSBExtendedBitDepth, m_apcLayerCfg[layer]->m_internalBitDepth );  // read  mode
+    m_apcTVideoIOYuvInputFile[layer]->skipFrames(m_FrameSkip, m_apcLayerCfg[layer]->getSourceWidth() - m_apcLayerCfg[layer]->getPad()[0], m_apcLayerCfg[layer]->getSourceHeight() - m_apcLayerCfg[layer]->getPad()[1], m_apcLayerCfg[layer]->m_InputChromaFormatIDC);
+
+    if( !m_apcLayerCfg[layer]->getReconFile().empty() )
+    {
+      m_apcTVideoIOYuvReconFile[layer]->open((Char *)m_apcLayerCfg[layer]->getReconFile().c_str(), true, m_apcLayerCfg[layer]->m_outputBitDepth, m_apcLayerCfg[layer]->m_MSBExtendedBitDepth, m_apcLayerCfg[layer]->m_internalBitDepth );  // write mode
     }
 
     // Neo Decoder
-    m_acTEncTop[layer].create();
+    m_apcTEncTop[layer]->create();
   }
 #else //SVC_EXTENSION
@@ -1164,17 +883,26 @@
   destroyROM();
 
-  for(UInt layer=0; layer<m_numLayers; layer++)
-  {
-#if LAYER_CTB
-    g_uiMaxCUWidth  = g_auiLayerMaxCUWidth[layer];
-    g_uiMaxCUHeight = g_auiLayerMaxCUHeight[layer];
-    g_uiMaxCUDepth  = g_auiLayerMaxCUDepth[layer];
-    g_uiAddCUDepth  = g_auiLayerAddCUDepth[layer];
-#endif
-
-    m_acTVideoIOYuvInputFile[layer].close();
-    m_acTVideoIOYuvReconFile[layer].close();
-
-    m_acTEncTop[layer].destroy();
+  for( UInt layer=0; layer < m_numLayers; layer++ )
+  {
+    if( m_apcTVideoIOYuvInputFile[layer] )
+    {
+      m_apcTVideoIOYuvInputFile[layer]->close();
+      delete m_apcTVideoIOYuvInputFile[layer];
+      m_apcTVideoIOYuvInputFile[layer] = NULL;
+    }
+
+    if( m_apcTVideoIOYuvReconFile[layer] )
+    {
+      m_apcTVideoIOYuvReconFile[layer]->close();
+      delete m_apcTVideoIOYuvReconFile[layer];
+      m_apcTVideoIOYuvReconFile[layer] = NULL;
+    }
+
+    if( m_apcTEncTop[layer] )
+    {
+      m_apcTEncTop[layer]->destroy();
+      delete m_apcTEncTop[layer];
+      m_apcTEncTop[layer] = NULL;
+    }
   }
 #else //SVC_EXTENSION
@@ -1190,6 +918,6 @@
 {
 #if SVC_EXTENSION
-  TComVPS* vps = m_acTEncTop[0].getVPS();
-  m_acTEncTop[0].getVPS()->setMaxLayers( m_numLayers );
+  TComVPS* vps = m_apcTEncTop[0]->getVPS();
+  m_apcTEncTop[0]->getVPS()->setMaxLayers( m_numLayers );
 
   UInt i = 0, dimIdLen = 0;
@@ -1205,9 +933,9 @@
   for(i = 1; i < vps->getMaxLayers(); i++)
   {
-    vps->setLayerIdInNuh(i, m_acLayerCfg[i].m_layerId);    
+    vps->setLayerIdInNuh(i, m_apcLayerCfg[i]->m_layerId);    
     vps->setLayerIdxInVps(vps->getLayerIdInNuh(i), i);
     vps->setDimensionId(i, 0, i);
 
-    if( m_acLayerCfg[i].m_layerId != i )
+    if( m_apcLayerCfg[i]->m_layerId != i )
     {
       vps->setNuhLayerIdPresentFlag(true);
@@ -1224,9 +952,9 @@
     memcpy( g_auiRasterToPelY,  g_auiLayerRasterToPelY[layer],  sizeof( g_auiRasterToPelY ) );
 #endif
-    m_acTEncTop[layer].init(isFieldCoding);
+    m_apcTEncTop[layer]->init(isFieldCoding);
   }
 
   // Set max-layer ID
-  vps->setMaxLayerId( m_acLayerCfg[m_numLayers - 1].m_layerId );
+  vps->setMaxLayerId( m_apcLayerCfg[m_numLayers - 1]->m_layerId );
   vps->setVpsExtensionFlag( m_numLayers > 1 ? true : false );
 
@@ -1338,7 +1066,7 @@
     for(i = 1; i < vps->getMaxLayers(); i++)
     {
-      if (m_acLayerCfg[i].getAuxId() > maxAuxId)
-      {
-        maxAuxId = m_acLayerCfg[i].getAuxId();
+      if (m_apcLayerCfg[i]->getAuxId() > maxAuxId)
+      {
+        maxAuxId = m_apcLayerCfg[i]->getAuxId();
       }
     }
@@ -1350,5 +1078,5 @@
     for(i = 1; i < vps->getMaxLayers(); i++)
     {
-      vps->setDimensionId(i, auxId, m_acLayerCfg[i].getAuxId());
+      vps->setDimensionId(i, auxId, m_apcLayerCfg[i]->getAuxId());
     }
   }
@@ -1369,5 +1097,5 @@
       for( Int j = i+1; j < vps->getMaxLayers(); j++)
       {
-        vps->setMaxTidIlRefPicsPlus1(i, j, m_acTEncTop[i].getMaxTidIlRefPicsPlus1());
+        vps->setMaxTidIlRefPicsPlus1(i, j, m_apcTEncTop[i]->getMaxTidIlRefPicsPlus1());
       }
     }
@@ -1394,10 +1122,10 @@
     Int numDirectRefLayers = 0;
 
-    vps->setNumDirectRefLayers(layerId, m_acTEncTop[layerCtr].getNumDirectRefLayers());
+    vps->setNumDirectRefLayers(layerId, m_apcTEncTop[layerCtr]->getNumDirectRefLayers());
     maxDirectRefLayers = max<UInt>(maxDirectRefLayers, vps->getNumDirectRefLayers(layerId));
 
     for (i = 0; i < vps->getNumDirectRefLayers(layerId); i++)
     {
-      vps->setRefLayerId(layerId, i, m_acTEncTop[layerCtr].getRefLayerId(i));
+      vps->setRefLayerId(layerId, i, m_apcTEncTop[layerCtr]->getRefLayerId(i));
     }
     // Set direct dependency flag
@@ -1409,5 +1137,5 @@
     for (i = 0; i < vps->getNumDirectRefLayers(layerId); i++)
     {
-      vps->setDirectDependencyFlag(layerCtr, vps->getLayerIdxInVps(m_acTEncTop[layerCtr].getRefLayerId(i)), true);
+      vps->setDirectDependencyFlag(layerCtr, vps->getLayerIdxInVps(m_apcTEncTop[layerCtr]->getRefLayerId(i)), true);
     }
     // prediction indications
@@ -1417,7 +1145,7 @@
       if (vps->getDirectDependencyFlag(layerCtr, refLayerCtr))
       {
-        assert(m_acTEncTop[layerCtr].getSamplePredEnabledFlag(numDirectRefLayers) || m_acTEncTop[layerCtr].getMotionPredEnabledFlag(numDirectRefLayers));
-        vps->setDirectDependencyType(layerCtr, refLayerCtr, ((m_acTEncTop[layerCtr].getSamplePredEnabledFlag(numDirectRefLayers) ? 1 : 0) |
-          (m_acTEncTop[layerCtr].getMotionPredEnabledFlag(numDirectRefLayers) ? 2 : 0)) - 1);
+        assert(m_apcTEncTop[layerCtr]->getSamplePredEnabledFlag(numDirectRefLayers) || m_apcTEncTop[layerCtr]->getMotionPredEnabledFlag(numDirectRefLayers));
+        vps->setDirectDependencyType(layerCtr, refLayerCtr, ((m_apcTEncTop[layerCtr]->getSamplePredEnabledFlag(numDirectRefLayers) ? 1 : 0) |
+          (m_apcTEncTop[layerCtr]->getMotionPredEnabledFlag(numDirectRefLayers) ? 2 : 0)) - 1);
 
         if (!isDefaultDirectDependencyTypeSet)
@@ -1535,6 +1263,6 @@
       {
         Int layerId = vps->getLayerSetLayerIdList(layerSetId, k); // k-th layer in the output layer set
-        vps->setMaxVpsDecPicBufferingMinus1( i, k, j,  m_acTEncTop[vps->getLayerIdxInVps(layerId)].getMaxDecPicBuffering(j) - 1 );
-        maxNumReorderPics       = std::max( maxNumReorderPics, m_acTEncTop[vps->getLayerIdxInVps(layerId)].getNumReorderPics(j));
+        vps->setMaxVpsDecPicBufferingMinus1( i, k, j,  m_apcTEncTop[vps->getLayerIdxInVps(layerId)]->getMaxDecPicBuffering(j) - 1 );
+        maxNumReorderPics       = std::max( maxNumReorderPics, m_apcTEncTop[vps->getLayerIdxInVps(layerId)]->getNumReorderPics(j));
       }
       vps->setMaxVpsNumReorderPics(i, j, maxNumReorderPics);
@@ -1572,5 +1300,5 @@
       if (vps->getDirectDependencyFlag( layerCtr, refLayerCtr))
       {
-        if(m_acTEncTop[layerCtr].getIntraPeriod() !=  m_acTEncTop[refLayerCtr].getIntraPeriod())
+        if(m_apcTEncTop[layerCtr]->getIntraPeriod() !=  m_apcTEncTop[refLayerCtr]->getIntraPeriod())
         {
           vps->setCrossLayerIrapAlignFlag(false);
@@ -1590,5 +1318,5 @@
   // VPS VUI BSP HRD parameters
   vps->setVpsVuiBspHrdPresentFlag(false);
-  TEncTop *pcCfg = &m_acTEncTop[0];
+  TEncTop *pcCfg = m_apcTEncTop[0];
   if( pcCfg->getBufferingPeriodSEIEnabled() )
   {
@@ -1603,12 +1331,12 @@
 
       UInt layerIdx = j;
-      TEncTop *pcCfgLayer = &m_acTEncTop[layerIdx];
+      TEncTop *pcCfgLayer = m_apcTEncTop[layerIdx];
 
       Int iPicWidth         = pcCfgLayer->getSourceWidth();
       Int iPicHeight        = pcCfgLayer->getSourceHeight();
 
-      UInt uiWidthInCU      = ( iPicWidth  % m_acLayerCfg[layerIdx].m_uiMaxCUWidth  ) ? iPicWidth  / m_acLayerCfg[layerIdx].m_uiMaxCUWidth  + 1 : iPicWidth  / m_acLayerCfg[layerIdx].m_uiMaxCUWidth;
-      UInt uiHeightInCU     = ( iPicHeight % m_acLayerCfg[layerIdx].m_uiMaxCUHeight ) ? iPicHeight / m_acLayerCfg[layerIdx].m_uiMaxCUHeight + 1 : iPicHeight / m_acLayerCfg[layerIdx].m_uiMaxCUHeight;
-      UInt maxCU = pcCfgLayer->getSliceArgument() >> ( m_acLayerCfg[layerIdx].m_uiMaxCUDepth << 1);
+      UInt uiWidthInCU      = ( iPicWidth  % m_apcLayerCfg[layerIdx]->m_uiMaxCUWidth  ) ? iPicWidth  / m_apcLayerCfg[layerIdx]->m_uiMaxCUWidth  + 1 : iPicWidth  / m_apcLayerCfg[layerIdx]->m_uiMaxCUWidth;
+      UInt uiHeightInCU     = ( iPicHeight % m_apcLayerCfg[layerIdx]->m_uiMaxCUHeight ) ? iPicHeight / m_apcLayerCfg[layerIdx]->m_uiMaxCUHeight + 1 : iPicHeight / m_apcLayerCfg[layerIdx]->m_uiMaxCUHeight;
+      UInt maxCU = pcCfgLayer->getSliceArgument() >> ( m_apcLayerCfg[layerIdx]->m_uiMaxCUDepth << 1);
 
       UInt uiNumCUsInFrame   = uiWidthInCU * uiHeightInCU;
@@ -1689,4 +1417,12 @@
   }
 
+  // allocated memory
+  for( Int layer = 0; layer < m_numLayers; layer++ )
+  {
+    m_apcTVideoIOYuvInputFile[layer] = new TVideoIOYuv;    
+    m_apcTVideoIOYuvReconFile[layer] = new TVideoIOYuv;
+    m_apcTEncTop[layer] = new TEncTop;
+  }
+
   TComPicYuv*       pcPicYuvOrg [MAX_LAYERS];
   TComPicYuv*       pcPicYuvRec = NULL;
@@ -1715,11 +1451,11 @@
     if( m_isField )
     {
-      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeightOrg(), m_acLayerCfg[layer].getChromaFormatIDC(), m_acLayerCfg[layer].m_uiMaxCUWidth, m_acLayerCfg[layer].m_uiMaxCUHeight, m_acLayerCfg[layer].m_uiMaxTotalCUDepth, true, NULL );
-      acPicYuvTrueOrg[layer].create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeightOrg(), m_acLayerCfg[layer].getChromaFormatIDC(), m_acLayerCfg[layer].m_uiMaxCUWidth, m_acLayerCfg[layer].m_uiMaxCUHeight, m_acLayerCfg[layer].m_uiMaxTotalCUDepth, true, NULL );
+      pcPicYuvOrg[layer]->create( m_apcLayerCfg[layer]->getSourceWidth(), m_apcLayerCfg[layer]->getSourceHeightOrg(), m_apcLayerCfg[layer]->getChromaFormatIDC(), m_apcLayerCfg[layer]->m_uiMaxCUWidth, m_apcLayerCfg[layer]->m_uiMaxCUHeight, m_apcLayerCfg[layer]->m_uiMaxTotalCUDepth, true, NULL );
+      acPicYuvTrueOrg[layer].create( m_apcLayerCfg[layer]->getSourceWidth(), m_apcLayerCfg[layer]->getSourceHeightOrg(), m_apcLayerCfg[layer]->getChromaFormatIDC(), m_apcLayerCfg[layer]->m_uiMaxCUWidth, m_apcLayerCfg[layer]->m_uiMaxCUHeight, m_apcLayerCfg[layer]->m_uiMaxTotalCUDepth, true, NULL );
     }
     else
     {
-      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_acLayerCfg[layer].getChromaFormatIDC(), m_acLayerCfg[layer].m_uiMaxCUWidth, m_acLayerCfg[layer].m_uiMaxCUHeight, m_acLayerCfg[layer].m_uiMaxTotalCUDepth, true, NULL );
-      acPicYuvTrueOrg[layer].create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_acLayerCfg[layer].getChromaFormatIDC(), m_acLayerCfg[layer].m_uiMaxCUWidth, m_acLayerCfg[layer].m_uiMaxCUHeight, m_acLayerCfg[layer].m_uiMaxTotalCUDepth, true, NULL );
+      pcPicYuvOrg[layer]->create( m_apcLayerCfg[layer]->getSourceWidth(), m_apcLayerCfg[layer]->getSourceHeight(), m_apcLayerCfg[layer]->getChromaFormatIDC(), m_apcLayerCfg[layer]->m_uiMaxCUWidth, m_apcLayerCfg[layer]->m_uiMaxCUHeight, m_apcLayerCfg[layer]->m_uiMaxTotalCUDepth, true, NULL );
+      acPicYuvTrueOrg[layer].create( m_apcLayerCfg[layer]->getSourceWidth(), m_apcLayerCfg[layer]->getSourceHeight(), m_apcLayerCfg[layer]->getChromaFormatIDC(), m_apcLayerCfg[layer]->m_uiMaxCUWidth, m_apcLayerCfg[layer]->m_uiMaxCUHeight, m_apcLayerCfg[layer]->m_uiMaxTotalCUDepth, true, NULL );
     }
   }
@@ -1735,21 +1471,14 @@
       {
         //6
-#if LAYER_CTB
-        g_uiMaxCUWidth  = g_auiLayerMaxCUWidth[layer];
-        g_uiMaxCUHeight = g_auiLayerMaxCUHeight[layer];
-        g_uiMaxCUDepth  = g_auiLayerMaxCUDepth[layer];
-        g_uiAddCUDepth  = g_auiLayerAddCUDepth[layer];
-#endif
-
         // get buffers
         xGetBuffer(pcPicYuvRec, layer);
 
         // read input YUV file
-        m_acTVideoIOYuvInputFile[layer].read( pcPicYuvOrg[layer], &acPicYuvTrueOrg[layer], ipCSC, m_acLayerCfg[layer].getPad(), m_acLayerCfg[layer].getInputChromaFormat(), m_bClipInputVideoToRec709Range );
+        m_apcTVideoIOYuvInputFile[layer]->read( pcPicYuvOrg[layer], &acPicYuvTrueOrg[layer], ipCSC, m_apcLayerCfg[layer]->getPad(), m_apcLayerCfg[layer]->getInputChromaFormat(), m_bClipInputVideoToRec709Range );
 
 #if AUXILIARY_PICTURES
-        if( m_acLayerCfg[layer].getChromaFormatIDC() == CHROMA_400 || (m_apcTEncTop[0]->getVPS()->getScalabilityMask(AUX_ID) && (m_acLayerCfg[layer].getAuxId() == AUX_ALPHA || m_acLayerCfg[layer].getAuxId() == AUX_DEPTH)) )
-        {
-          pcPicYuvOrg[layer]->convertToMonochrome(m_acLayerCfg[layer].m_internalBitDepth[CHANNEL_TYPE_CHROMA]);
+        if( m_apcLayerCfg[layer]->getChromaFormatIDC() == CHROMA_400 || (m_apcTEncTop[0]->getVPS()->getScalabilityMask(AUX_ID) && (m_apcLayerCfg[layer]->getAuxId() == AUX_ALPHA || m_apcLayerCfg[layer]->getAuxId() == AUX_DEPTH)) )
+        {
+          pcPicYuvOrg[layer]->convertToMonochrome(m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_CHROMA]);
         }
 #endif
@@ -1765,30 +1494,30 @@
         if ( m_isField )
         {
-          m_acTEncTop[layer].encodePrep( pcPicYuvOrg[layer], &acPicYuvTrueOrg[layer], m_isTopFieldFirst );
+          m_apcTEncTop[layer]->encodePrep( pcPicYuvOrg[layer], &acPicYuvTrueOrg[layer], m_isTopFieldFirst );
         }
         else
         {
-          m_acTEncTop[layer].encodePrep( pcPicYuvOrg[layer], &acPicYuvTrueOrg[layer] );
-        }
-      }
-
-      bFramesReadyToCode = !(!bFirstFrame && ( m_acTEncTop[m_numLayers-1].getNumPicRcvd() != m_iGOPSize && m_iGOPSize ) && !bEos );
+          m_apcTEncTop[layer]->encodePrep( pcPicYuvOrg[layer], &acPicYuvTrueOrg[layer] );
+        }
+      }
+
+      bFramesReadyToCode = !(!bFirstFrame && ( m_apcTEncTop[m_numLayers-1]->getNumPicRcvd() != m_iGOPSize && m_iGOPSize ) && !bEos );
     }
     Bool flush = 0;
     // if end of file (which is only detected on a read failure) flush the encoder of any queued pictures
-    if (m_acTVideoIOYuvInputFile[m_numLayers-1].isEof())
+    if (m_apcTVideoIOYuvInputFile[m_numLayers-1]->isEof())
     {
       flush = true;
       bEos = true;
       m_iFrameRcvd--;
-      m_acTEncTop[m_numLayers-1].setFramesToBeEncoded(m_iFrameRcvd);
+      m_apcTEncTop[m_numLayers-1]->setFramesToBeEncoded(m_iFrameRcvd);
     }
 
 #if RC_SHVC_HARMONIZATION
-    for(UInt layer=0; layer<m_numLayers; layer++)
-    {
-      if ( m_acTEncTop[layer].getUseRateCtrl() )
-      {
-        (m_acTEncTop[layer].getRateCtrl())->initRCGOP(m_acTEncTop[layer].getNumPicRcvd());
+    for( UInt layer=0; layer<m_numLayers; layer++ )
+    {
+      if( m_apcTEncTop[layer]->getUseRateCtrl() )
+      {
+        m_apcTEncTop[layer]->getRateCtrl()->initRCGOP(m_apcTEncTop[layer]->getNumPicRcvd());
       }
     }
@@ -1824,9 +1553,9 @@
         if ( m_isField )
         {
-          m_acTEncTop[layer].encode( flush ? 0 : pcPicYuvOrg[layer], snrCSC, m_acListPicYuvRec[layer], outputAccessUnits, iPicIdInGOP, m_isTopFieldFirst );
+          m_apcTEncTop[layer]->encode( flush ? 0 : pcPicYuvOrg[layer], snrCSC, m_acListPicYuvRec[layer], outputAccessUnits, iPicIdInGOP, m_isTopFieldFirst );
         }
         else
         {
-          m_acTEncTop[layer].encode( flush ? 0 : pcPicYuvOrg[layer], snrCSC, m_acListPicYuvRec[layer], outputAccessUnits, iPicIdInGOP );
+          m_apcTEncTop[layer]->encode( flush ? 0 : pcPicYuvOrg[layer], snrCSC, m_acListPicYuvRec[layer], outputAccessUnits, iPicIdInGOP );
         }
       }
@@ -1867,7 +1596,7 @@
     for(UInt layer=0; layer<m_numLayers; layer++)
     {
-      if ( m_acTEncTop[layer].getUseRateCtrl() )
-      {
-        (m_acTEncTop[layer].getRateCtrl())->destroyRCGOP();
+      if ( m_apcTEncTop[layer]->getUseRateCtrl() )
+      {
+        (m_apcTEncTop[layer]->getRateCtrl())->destroyRCGOP();
       }
     }
@@ -1879,5 +1608,5 @@
       //8
       // write bistream to file if necessary
-      iNumEncoded = m_acTEncTop[layer].getNumPicRcvd();
+      iNumEncoded = m_apcTEncTop[layer]->getNumPicRcvd();
       if ( iNumEncoded > 0 )
       {
@@ -1885,5 +1614,5 @@
         iTotalNumEncoded += iNumEncoded;
       }
-      m_acTEncTop[layer].setNumPicRcvd( 0 );
+      m_apcTEncTop[layer]->setNumPicRcvd( 0 );
     }
 
@@ -1921,5 +1650,5 @@
 
     // delete used buffers in encoder class
-    m_acTEncTop[layer].deletePicBuffer();
+    m_apcTEncTop[layer]->deletePicBuffer();
     acPicYuvTrueOrg[layer].destroy();
   }
@@ -1943,8 +1672,8 @@
   for(layer = 0; layer < m_numLayers; layer++)
   {
-    m_apcTEncTop[layer]->getAnalyzeAll()->setFrmRate( m_acLayerCfg[layer].getFrameRate() * rateMultiplier );
-    m_apcTEncTop[layer]->getAnalyzeI()->setFrmRate( m_acLayerCfg[layer].getFrameRate() * rateMultiplier );
-    m_apcTEncTop[layer]->getAnalyzeP()->setFrmRate( m_acLayerCfg[layer].getFrameRate() * rateMultiplier );
-    m_apcTEncTop[layer]->getAnalyzeB()->setFrmRate( m_acLayerCfg[layer].getFrameRate() * rateMultiplier );
+    m_apcTEncTop[layer]->getAnalyzeAll()->setFrmRate( m_apcLayerCfg[layer]->getFrameRate() * rateMultiplier );
+    m_apcTEncTop[layer]->getAnalyzeI()->setFrmRate( m_apcLayerCfg[layer]->getFrameRate() * rateMultiplier );
+    m_apcTEncTop[layer]->getAnalyzeP()->setFrmRate( m_apcLayerCfg[layer]->getFrameRate() * rateMultiplier );
+    m_apcTEncTop[layer]->getAnalyzeB()->setFrmRate( m_apcLayerCfg[layer]->getFrameRate() * rateMultiplier );
   }
 
@@ -1953,6 +1682,6 @@
   for(layer = 0; layer < m_numLayers; layer++)
   {
-    const BitDepths bitDepths(m_acLayerCfg[layer].m_internalBitDepth[CHANNEL_TYPE_LUMA], m_acLayerCfg[layer].m_internalBitDepth[CHANNEL_TYPE_CHROMA]);    
-    m_apcTEncTop[layer]->getAnalyzeAll()->printOut('a', m_acLayerCfg[layer].getChromaFormatIDC(), printMSEBasedSNR, printSequenceMSE, bitDepths, layer);
+    const BitDepths bitDepths(m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_LUMA], m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_CHROMA]);    
+    m_apcTEncTop[layer]->getAnalyzeAll()->printOut('a', m_apcLayerCfg[layer]->getChromaFormatIDC(), printMSEBasedSNR, printSequenceMSE, bitDepths, layer);
   }
 
@@ -1960,6 +1689,6 @@
   for(layer = 0; layer < m_numLayers; layer++)
   {
-    const BitDepths bitDepths(m_acLayerCfg[layer].m_internalBitDepth[CHANNEL_TYPE_LUMA], m_acLayerCfg[layer].m_internalBitDepth[CHANNEL_TYPE_CHROMA]);
-    m_apcTEncTop[layer]->getAnalyzeI()->printOut('i', m_acLayerCfg[layer].getChromaFormatIDC(), printMSEBasedSNR, printSequenceMSE, bitDepths, layer);
+    const BitDepths bitDepths(m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_LUMA], m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_CHROMA]);
+    m_apcTEncTop[layer]->getAnalyzeI()->printOut('i', m_apcLayerCfg[layer]->getChromaFormatIDC(), printMSEBasedSNR, printSequenceMSE, bitDepths, layer);
   }
 
@@ -1967,6 +1696,6 @@
   for(layer = 0; layer < m_numLayers; layer++)
   {
-    const BitDepths bitDepths(m_acLayerCfg[layer].m_internalBitDepth[CHANNEL_TYPE_LUMA], m_acLayerCfg[layer].m_internalBitDepth[CHANNEL_TYPE_CHROMA]);
-    m_apcTEncTop[layer]->getAnalyzeP()->printOut('p', m_acLayerCfg[layer].getChromaFormatIDC(), printMSEBasedSNR, printSequenceMSE, bitDepths, layer);
+    const BitDepths bitDepths(m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_LUMA], m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_CHROMA]);
+    m_apcTEncTop[layer]->getAnalyzeP()->printOut('p', m_apcLayerCfg[layer]->getChromaFormatIDC(), printMSEBasedSNR, printSequenceMSE, bitDepths, layer);
   }
 
@@ -1974,6 +1703,6 @@
   for(layer = 0; layer < m_numLayers; layer++)
   {
-    const BitDepths bitDepths(m_acLayerCfg[layer].m_internalBitDepth[CHANNEL_TYPE_LUMA], m_acLayerCfg[layer].m_internalBitDepth[CHANNEL_TYPE_CHROMA]);
-    m_apcTEncTop[layer]->getAnalyzeB()->printOut('b', m_acLayerCfg[layer].getChromaFormatIDC(), printMSEBasedSNR, printSequenceMSE, bitDepths, layer);
+    const BitDepths bitDepths(m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_LUMA], m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_CHROMA]);
+    m_apcTEncTop[layer]->getAnalyzeB()->printOut('b', m_apcLayerCfg[layer]->getChromaFormatIDC(), printMSEBasedSNR, printSequenceMSE, bitDepths, layer);
   }
 
@@ -1982,7 +1711,7 @@
     if (!m_apcTEncTop[layer]->getSummaryOutFilename().empty())
     {
-      const BitDepths bitDepths(m_acLayerCfg[layer].m_internalBitDepth[CHANNEL_TYPE_LUMA], m_acLayerCfg[layer].m_internalBitDepth[CHANNEL_TYPE_CHROMA]);
-
-      m_apcTEncTop[layer]->getAnalyzeAll()->printSummary(m_acLayerCfg[layer].getChromaFormatIDC(), printSequenceMSE, bitDepths, m_apcTEncTop[layer]->getSummaryOutFilename());
+      const BitDepths bitDepths(m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_LUMA], m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_CHROMA]);
+
+      m_apcTEncTop[layer]->getAnalyzeAll()->printSummary(m_apcLayerCfg[layer]->getChromaFormatIDC(), printSequenceMSE, bitDepths, m_apcTEncTop[layer]->getSummaryOutFilename());
     }
   }
@@ -1992,9 +1721,9 @@
     if (!m_apcTEncTop[layer]->getSummaryPicFilenameBase().empty())
     {
-      const BitDepths bitDepths(m_acLayerCfg[layer].m_internalBitDepth[CHANNEL_TYPE_LUMA], m_acLayerCfg[layer].m_internalBitDepth[CHANNEL_TYPE_CHROMA]);
-
-      m_apcTEncTop[layer]->getAnalyzeI()->printSummary(m_acLayerCfg[layer].getChromaFormatIDC(), printSequenceMSE, bitDepths, m_apcTEncTop[layer]->getSummaryPicFilenameBase()+"I.txt");
-      m_apcTEncTop[layer]->getAnalyzeP()->printSummary(m_acLayerCfg[layer].getChromaFormatIDC(), printSequenceMSE, bitDepths, m_apcTEncTop[layer]->getSummaryPicFilenameBase()+"P.txt");
-      m_apcTEncTop[layer]->getAnalyzeB()->printSummary(m_acLayerCfg[layer].getChromaFormatIDC(), printSequenceMSE, bitDepths, m_apcTEncTop[layer]->getSummaryPicFilenameBase()+"B.txt");
+      const BitDepths bitDepths(m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_LUMA], m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_CHROMA]);
+
+      m_apcTEncTop[layer]->getAnalyzeI()->printSummary(m_apcLayerCfg[layer]->getChromaFormatIDC(), printSequenceMSE, bitDepths, m_apcTEncTop[layer]->getSummaryPicFilenameBase()+"I.txt");
+      m_apcTEncTop[layer]->getAnalyzeP()->printSummary(m_apcLayerCfg[layer]->getChromaFormatIDC(), printSequenceMSE, bitDepths, m_apcTEncTop[layer]->getSummaryPicFilenameBase()+"P.txt");
+      m_apcTEncTop[layer]->getAnalyzeB()->printSummary(m_apcLayerCfg[layer]->getChromaFormatIDC(), printSequenceMSE, bitDepths, m_apcTEncTop[layer]->getSummaryPicFilenameBase()+"B.txt");
     }
   }
@@ -2004,18 +1733,18 @@
     for(layer = 0; layer < m_numLayers; layer++)
     {
-      const BitDepths bitDepths(m_acLayerCfg[layer].m_internalBitDepth[CHANNEL_TYPE_LUMA], m_acLayerCfg[layer].m_internalBitDepth[CHANNEL_TYPE_CHROMA]);
+      const BitDepths bitDepths(m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_LUMA], m_apcLayerCfg[layer]->m_internalBitDepth[CHANNEL_TYPE_CHROMA]);
       TEncAnalyze *analyze = m_apcTEncTop[layer]->getAnalyzeAllin();
 
       //-- interlaced summary
-      analyze->setFrmRate( m_acLayerCfg[layer].getFrameRate());
+      analyze->setFrmRate( m_apcLayerCfg[layer]->getFrameRate());
       analyze->setBits(m_apcTEncTop[layer]->getAnalyzeB()->getBits());
       // prior to the above statement, the interlace analyser does not contain the correct total number of bits.
 
       printf( "\n\nSUMMARY INTERLACED ---------------------------------------------\n" );
-      analyze->printOut('a', m_acLayerCfg[layer].getChromaFormatIDC(), printMSEBasedSNR, printSequenceMSE, bitDepths, layer);
+      analyze->printOut('a', m_apcLayerCfg[layer]->getChromaFormatIDC(), printMSEBasedSNR, printSequenceMSE, bitDepths, layer);
 
       if (!m_apcTEncTop[layer]->getSummaryOutFilename().empty())
       {
-        analyze->printSummary(m_acLayerCfg[layer].getChromaFormatIDC(), printSequenceMSE, bitDepths, m_apcTEncTop[layer]->getSummaryOutFilename());
+        analyze->printSummary(m_apcLayerCfg[layer]->getChromaFormatIDC(), printSequenceMSE, bitDepths, m_apcTEncTop[layer]->getSummaryOutFilename());
       }
     }
@@ -2170,5 +1899,5 @@
     rpcPicYuvRec = new TComPicYuv;
 
-    rpcPicYuvRec->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_acLayerCfg[layer].getChromaFormatIDC(), m_acLayerCfg[layer].m_uiMaxCUWidth, m_acLayerCfg[layer].m_uiMaxCUHeight, m_acLayerCfg[layer].m_uiMaxTotalCUDepth, true, NULL );
+    rpcPicYuvRec->create( m_apcLayerCfg[layer]->getSourceWidth(), m_apcLayerCfg[layer]->getSourceHeight(), m_apcLayerCfg[layer]->getChromaFormatIDC(), m_apcLayerCfg[layer]->m_uiMaxCUWidth, m_apcLayerCfg[layer]->m_uiMaxCUHeight, m_apcLayerCfg[layer]->m_uiMaxTotalCUDepth, true, NULL );
   }
   m_acListPicYuvRec[layer].pushBack( rpcPicYuvRec );
@@ -2194,5 +1923,5 @@
 Void TAppEncTop::xWriteRecon(UInt layer, Int iNumEncoded)
 {
-  ChromaFormat chromaFormatIdc = m_acLayerCfg[layer].getChromaFormatIDC();
+  ChromaFormat chromaFormatIdc = m_apcLayerCfg[layer]->getChromaFormatIDC();
   Int xScal = TComSPS::getWinUnitX( chromaFormatIdc );
   Int yScal = TComSPS::getWinUnitY( chromaFormatIdc );
@@ -2216,8 +1945,8 @@
       TComPicYuv*  pcPicYuvRecBottom  = *(iterPicYuvRec++);
 
-      if( !m_acLayerCfg[layer].getReconFile().empty() && pcPicYuvRecTop->isReconstructed() && pcPicYuvRecBottom->isReconstructed() )
-      {
-        m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRecTop, pcPicYuvRecBottom, ipCSC, m_acLayerCfg[layer].getConfWinLeft() * xScal, m_acLayerCfg[layer].getConfWinRight() * xScal, 
-        m_acLayerCfg[layer].getConfWinTop() * yScal, m_acLayerCfg[layer].getConfWinBottom() * yScal, NUM_CHROMA_FORMAT, m_isTopFieldFirst );
+      if( !m_apcLayerCfg[layer]->getReconFile().empty() && pcPicYuvRecTop->isReconstructed() && pcPicYuvRecBottom->isReconstructed() )
+      {
+        m_apcTVideoIOYuvReconFile[layer]->write( pcPicYuvRecTop, pcPicYuvRecBottom, ipCSC, m_apcLayerCfg[layer]->getConfWinLeft() * xScal, m_apcLayerCfg[layer]->getConfWinRight() * xScal, 
+        m_apcLayerCfg[layer]->getConfWinTop() * yScal, m_apcLayerCfg[layer]->getConfWinBottom() * yScal, NUM_CHROMA_FORMAT, m_isTopFieldFirst );
       }
     }
@@ -2237,8 +1966,8 @@
     {
       TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
-      if( !m_acLayerCfg[layer].getReconFile().empty() && pcPicYuvRec->isReconstructed() )
-      {
-        m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRec, ipCSC, m_acLayerCfg[layer].getConfWinLeft() * xScal, m_acLayerCfg[layer].getConfWinRight() * xScal,
-          m_acLayerCfg[layer].getConfWinTop() * yScal, m_acLayerCfg[layer].getConfWinBottom() * yScal,
+      if( !m_apcLayerCfg[layer]->getReconFile().empty() && pcPicYuvRec->isReconstructed() )
+      {
+        m_apcTVideoIOYuvReconFile[layer]->write( pcPicYuvRec, ipCSC, m_apcLayerCfg[layer]->getConfWinLeft() * xScal, m_apcLayerCfg[layer]->getConfWinRight() * xScal,
+          m_apcLayerCfg[layer]->getConfWinTop() * yScal, m_apcLayerCfg[layer]->getConfWinBottom() * yScal,
           NUM_CHROMA_FORMAT, m_bClipOutputVideoToRec709Range  );
       }
@@ -2431,5 +2160,5 @@
 {
 #if SVC_EXTENSION
-  Double time = (Double) m_iFrameRcvd / m_acLayerCfg[m_numLayers-1].getFrameRate();
+  Double time = (Double) m_iFrameRcvd / m_apcLayerCfg[m_numLayers-1]->getFrameRate();
 #else
   Double time = (Double) m_iFrameRcvd / m_iFrameRate;
Index: branches/SHM-dev/source/App/TAppEncoder/TAppEncTop.h
===================================================================
--- branches/SHM-dev/source/App/TAppEncoder/TAppEncTop.h	(revision 1376)
+++ branches/SHM-dev/source/App/TAppEncoder/TAppEncTop.h	(revision 1377)
@@ -60,8 +60,7 @@
   // class interface
 #if SVC_EXTENSION
-  TEncTop                    m_acTEncTop [MAX_LAYERS];                    ///< encoder class
-  TEncTop*                   m_apcTEncTop [MAX_LAYERS];                   ///< encoder pointer class
-  TVideoIOYuv                m_acTVideoIOYuvInputFile [MAX_LAYERS];       ///< input YUV file
-  TVideoIOYuv                m_acTVideoIOYuvReconFile [MAX_LAYERS];       ///< output reconstruction file
+  TEncTop*                   m_apcTEncTop[MAX_LAYERS];                    ///< encoder pointer class
+  TVideoIOYuv*               m_apcTVideoIOYuvInputFile[MAX_LAYERS];       ///< input YUV file
+  TVideoIOYuv*               m_apcTVideoIOYuvReconFile[MAX_LAYERS];       ///< output reconstruction file
 
   TComList<TComPicYuv*>      m_acListPicYuvRec [MAX_LAYERS];              ///< list of reconstruction YUV files
@@ -114,5 +113,5 @@
   Void        encode      ();                               ///< main encoding function
 #if SVC_EXTENSION
-  TEncTop&    getTEncTop  (UInt layer)   { return  m_acTEncTop[layer]; }      ///< return encoder class pointer reference
+  TEncTop&    getTEncTop  (UInt layer)   { return  *m_apcTEncTop[layer]; }      ///< return encoder class pointer reference
 #else
   TEncTop&    getTEncTop  ()   { return  m_cTEncTop; }      ///< return encoder class pointer reference
Index: branches/SHM-dev/source/App/TAppEncoder/encmain.cpp
===================================================================
--- branches/SHM-dev/source/App/TAppEncoder/encmain.cpp	(revision 1376)
+++ branches/SHM-dev/source/App/TAppEncoder/encmain.cpp	(revision 1377)
@@ -72,4 +72,16 @@
   try
   {
+#if SVC_EXTENSION
+    // parse number of layers first to allocate memory in the buffers
+    if(!cTAppEncTop.parseCfgNumLayersAndInit( argc, argv ))
+    {
+      cTAppEncTop.destroy();
+#if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
+      EnvVar::printEnvVar();
+#endif
+      return 1;
+    }
+#endif
+
     if(!cTAppEncTop.parseCfg( argc, argv ))
     {
