Index: branches/SHM-6-dev/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- branches/SHM-6-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 804)
+++ branches/SHM-6-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 805)
@@ -1119,5 +1119,7 @@
 #endif
 #if Q0078_ADD_LAYER_SETS
+  vps->setVpsNumLayerSetsMinus1(vps->getNumLayerSets() - 1);
   vps->setNumAddLayerSets(m_numAddLayerSets);
+  vps->setNumLayerSets(vps->getNumLayerSets() + vps->getNumAddLayerSets());
   if (m_numAddLayerSets > 0)
   {
@@ -1247,105 +1249,4 @@
   }
 #endif
-  // Target output layer
-  vps->setNumOutputLayerSets(vps->getNumLayerSets());
-  vps->setNumProfileTierLevel(vps->getNumLayerSets());
-#if P0295_DEFAULT_OUT_LAYER_IDC
-  vps->setDefaultTargetOutputLayerIdc(1);
-#else
-#if O0109_DEFAULT_ONE_OUT_LAYER_IDC
-  vps->setDefaultOneTargetOutputLayerIdc(1);
-#else
-  vps->setDefaultOneTargetOutputLayerFlag(true);
-#endif
-#endif
-  for(i = 1; i < vps->getNumLayerSets(); i++)
-  {
-    vps->setProfileLevelTierIdx(i, i);
-    vps->setOutputLayerSetIdx(i, i);
-  }  
-#endif
- #if VPS_DPB_SIZE_TABLE
-  // The Layer ID List variables can be derived here.  
-#if DERIVE_LAYER_ID_LIST_VARIABLES
-  vps->deriveLayerIdListVariables();
-#endif
-#if RESOLUTION_BASED_DPB
-  vps->assignSubDpbIndices();
-#else
-  vps->deriveNumberOfSubDpbs();
-#endif
-
-  // derive OutputLayerFlag[i][j] 
-  if( vps->getDefaultTargetOutputLayerIdc() == 1 )
-  {
-    // default_output_layer_idc equal to 1 specifies that only the layer with the highest value of nuh_layer_id such that nuh_layer_id equal to nuhLayerIdA and 
-    // AuxId[ nuhLayerIdA ] equal to 0 in each of the output layer sets with index in the range of 1 to vps_num_layer_sets_minus1, inclusive, is an output layer of its output layer set.
-
-    // Include the highest layer as output layer for each layer set
-    for(Int lsIdx = 1; lsIdx < vps->getNumLayerSets(); lsIdx++)
-    {
-      for( UInt layer = 0; layer < vps->getNumLayersInIdList(lsIdx); layer++ )
-      {
-        if( vps->getLayerIdIncludedFlag(lsIdx, layer) )      
-        {        
-          vps->setOutputLayerFlag( lsIdx, layer, layer == vps->getNumLayersInIdList(lsIdx) - 1 );
-        }
-      }
-    }
-  }
-  else
-  {
-    // cases when default_output_layer_idc is not equal to 1
-    assert(!"default_output_layer_idc not equal to 1 is not yet supported");
-  }
-
-  // Initialize dpb_size_table() for all ouput layer sets in the VPS extension
-  for(i = 1; i < vps->getNumOutputLayerSets(); i++)
-  {
-#if CHANGE_NUMSUBDPB_IDX
-    Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx( i );
-#endif
-    Int layerSetId = vps->getOutputLayerSetIdx(i);
-
-    for(Int j = 0; j < vps->getMaxTLayers(); j++)
-    {
-
-      Int maxNumReorderPics = -1;
-#if CHANGE_NUMSUBDPB_IDX
-#if RESOLUTION_BASED_DPB
-      for(Int k = 0; k < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet); k++)
-#else
-      for(Int k = 0; k < vps->getNumSubDpbs(layerSetIdxForOutputLayerSet); k++)
-#endif
-#else
-      for(Int k = 0; k < vps->getNumSubDpbs(i); k++)
-#endif
-      {
-        Int layerId = vps->getLayerSetLayerIdList(layerSetId, k); // k-th layer in the output layer set
-#if RESOLUTION_BASED_DPB
-        vps->setMaxVpsLayerDecPicBuffMinus1( i, k, j, m_acTEncTop[layerId].getMaxDecPicBuffering(j) - 1 );
-        // Add sub-DPB sizes of layers belonging to a sub-DPB. If a different sub-DPB size is calculated
-        // at the encoder, modify below
-        Int oldValue = vps->getMaxVpsDecPicBufferingMinus1( i, vps->getSubDpbAssigned( layerSetIdxForOutputLayerSet, k ), j );
-        oldValue += vps->getMaxVpsLayerDecPicBuffMinus1( i, k, j ) + 1;
-        vps->setMaxVpsDecPicBufferingMinus1( i, vps->getSubDpbAssigned( layerSetIdxForOutputLayerSet, k ), j, oldValue );
-#else
-        vps->setMaxVpsDecPicBufferingMinus1( i, k, j,  m_acTEncTop[layerId].getMaxDecPicBuffering(j) - 1 );
-#endif
-        maxNumReorderPics       = std::max( maxNumReorderPics, m_acTEncTop[layerId].getNumReorderPics(j));
-      }
-#if RESOLUTION_BASED_DPB
-      for(Int k = 0; k < vps->getNumSubDpbs(i); k++)
-      {
-        // Decrement m_maxVpsDecPicBufferingMinus1
-        Int oldValue = vps->getMaxVpsDecPicBufferingMinus1( i, vps->getSubDpbAssigned( layerSetIdxForOutputLayerSet, k ), j );
-        vps->setMaxVpsDecPicBufferingMinus1( i, vps->getSubDpbAssigned( layerSetIdxForOutputLayerSet, k ), j, oldValue - 1 );
-      }
-#endif
-      vps->setMaxVpsNumReorderPics(i, j, maxNumReorderPics);
-      vps->determineSubDpbInfoFlags();
-    }
-  }
-#endif
 #if VPS_EXTN_DIRECT_REF_LAYERS
   // Direct reference layers
@@ -1354,32 +1255,32 @@
   Bool isDefaultDirectDependencyTypeSet = false;
 #endif
-  for(UInt layerCtr = 1;layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
-  {
-    vps->setNumDirectRefLayers( layerCtr, m_acTEncTop[layerCtr].getNumDirectRefLayers() );
-    maxDirectRefLayers = max<UInt>( maxDirectRefLayers, vps->getNumDirectRefLayers( layerCtr ) );
-
-    for(i = 0; i < vps->getNumDirectRefLayers(layerCtr); i++)
-    {
-      vps->setRefLayerId( layerCtr, i, m_acTEncTop[layerCtr].getRefLayerId(i) );
+  for (UInt layerCtr = 1; layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
+  {
+    vps->setNumDirectRefLayers(layerCtr, m_acTEncTop[layerCtr].getNumDirectRefLayers());
+    maxDirectRefLayers = max<UInt>(maxDirectRefLayers, vps->getNumDirectRefLayers(layerCtr));
+
+    for (i = 0; i < vps->getNumDirectRefLayers(layerCtr); i++)
+    {
+      vps->setRefLayerId(layerCtr, i, m_acTEncTop[layerCtr].getRefLayerId(i));
     }
     // Set direct dependency flag
     // Initialize flag to 0
-    for(Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
-    {
-      vps->setDirectDependencyFlag( layerCtr, refLayerCtr, false );
-    }
-    for(i = 0; i < vps->getNumDirectRefLayers(layerCtr); i++)
-    {
-      vps->setDirectDependencyFlag( layerCtr, vps->getLayerIdInVps(m_acTEncTop[layerCtr].getRefLayerId(i)), true);
+    for (Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
+    {
+      vps->setDirectDependencyFlag(layerCtr, refLayerCtr, false);
+    }
+    for (i = 0; i < vps->getNumDirectRefLayers(layerCtr); i++)
+    {
+      vps->setDirectDependencyFlag(layerCtr, vps->getLayerIdInVps(m_acTEncTop[layerCtr].getRefLayerId(i)), true);
     }
     // prediction indications
     vps->setDirectDepTypeLen(2); // sample and motion types are encoded
-    for(Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
-    {
-      if (vps->getDirectDependencyFlag( layerCtr, refLayerCtr))
+    for (Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
+    {
+      if (vps->getDirectDependencyFlag(layerCtr, refLayerCtr))
       {
         assert(m_acTEncTop[layerCtr].getSamplePredEnabledFlag(refLayerCtr) || m_acTEncTop[layerCtr].getMotionPredEnabledFlag(refLayerCtr));
-        vps->setDirectDependencyType( layerCtr, refLayerCtr, ((m_acTEncTop[layerCtr].getSamplePredEnabledFlag(refLayerCtr) ? 1 : 0) |
-                                                              (m_acTEncTop[layerCtr].getMotionPredEnabledFlag(refLayerCtr) ? 2 : 0)) - 1);
+        vps->setDirectDependencyType(layerCtr, refLayerCtr, ((m_acTEncTop[layerCtr].getSamplePredEnabledFlag(refLayerCtr) ? 1 : 0) |
+          (m_acTEncTop[layerCtr].getMotionPredEnabledFlag(refLayerCtr) ? 2 : 0)) - 1);
 #if O0096_DEFAULT_DEPENDENCY_TYPE
         if (!isDefaultDirectDependencyTypeSet)
@@ -1397,5 +1298,5 @@
       else
       {
-        vps->setDirectDependencyType( layerCtr, refLayerCtr, 0 );
+        vps->setDirectDependencyType(layerCtr, refLayerCtr, 0);
       }
     }
@@ -1405,9 +1306,9 @@
   vps->setNumRefLayers();
 
-  if(vps->getMaxLayers() > MAX_REF_LAYERS)
-  {
-    for(UInt layerCtr = 1; layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
-    {
-      assert( vps->getNumRefLayers(vps->getLayerIdInNuh(layerCtr)) <= MAX_REF_LAYERS);
+  if (vps->getMaxLayers() > MAX_REF_LAYERS)
+  {
+    for (UInt layerCtr = 1; layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
+    {
+      assert(vps->getNumRefLayers(vps->getLayerIdInNuh(layerCtr)) <= MAX_REF_LAYERS);
     }
   }
@@ -1416,5 +1317,109 @@
   vps->setPredictedLayerIds();
   vps->setTreePartitionLayerIdList();
-#endif
+  vps->setLayerIdIncludedFlagsForAddLayerSets();
+#endif
+#endif
+  // Target output layer
+  vps->setNumOutputLayerSets(vps->getNumLayerSets());
+  vps->setNumProfileTierLevel(vps->getNumLayerSets());
+#if P0295_DEFAULT_OUT_LAYER_IDC
+  vps->setDefaultTargetOutputLayerIdc(1);
+#else
+#if O0109_DEFAULT_ONE_OUT_LAYER_IDC
+  vps->setDefaultOneTargetOutputLayerIdc(1);
+#else
+  vps->setDefaultOneTargetOutputLayerFlag(true);
+#endif
+#endif
+  for(i = 1; i < vps->getNumLayerSets(); i++)
+  {
+    vps->setProfileLevelTierIdx(i, i);
+    vps->setOutputLayerSetIdx(i, i);
+  }  
+#endif
+ #if VPS_DPB_SIZE_TABLE
+  // The Layer ID List variables can be derived here.  
+#if DERIVE_LAYER_ID_LIST_VARIABLES
+  vps->deriveLayerIdListVariables();
+#endif
+#if RESOLUTION_BASED_DPB
+  vps->assignSubDpbIndices();
+#else
+  vps->deriveNumberOfSubDpbs();
+#endif
+
+  // derive OutputLayerFlag[i][j] 
+  if( vps->getDefaultTargetOutputLayerIdc() == 1 )
+  {
+    // default_output_layer_idc equal to 1 specifies that only the layer with the highest value of nuh_layer_id such that nuh_layer_id equal to nuhLayerIdA and 
+    // AuxId[ nuhLayerIdA ] equal to 0 in each of the output layer sets with index in the range of 1 to vps_num_layer_sets_minus1, inclusive, is an output layer of its output layer set.
+
+    // Include the highest layer as output layer for each layer set
+    for(Int lsIdx = 1; lsIdx < vps->getNumLayerSets(); lsIdx++)
+    {
+      for( UInt layer = 0; layer < vps->getNumLayersInIdList(lsIdx); layer++ )
+      {
+#if !Q0078_ADD_LAYER_SETS  // the following condition is incorrect and is not needed anyway
+        if( vps->getLayerIdIncludedFlag(lsIdx, layer) )      
+#endif
+        {        
+          vps->setOutputLayerFlag( lsIdx, layer, layer == vps->getNumLayersInIdList(lsIdx) - 1 );
+        }
+      }
+    }
+  }
+  else
+  {
+    // cases when default_output_layer_idc is not equal to 1
+    assert(!"default_output_layer_idc not equal to 1 is not yet supported");
+  }
+
+  // Initialize dpb_size_table() for all ouput layer sets in the VPS extension
+  for(i = 1; i < vps->getNumOutputLayerSets(); i++)
+  {
+#if CHANGE_NUMSUBDPB_IDX
+    Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx( i );
+#endif
+    Int layerSetId = vps->getOutputLayerSetIdx(i);
+
+    for(Int j = 0; j < vps->getMaxTLayers(); j++)
+    {
+
+      Int maxNumReorderPics = -1;
+#if CHANGE_NUMSUBDPB_IDX
+#if RESOLUTION_BASED_DPB
+      for(Int k = 0; k < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet); k++)
+#else
+      for(Int k = 0; k < vps->getNumSubDpbs(layerSetIdxForOutputLayerSet); k++)
+#endif
+#else
+      for(Int k = 0; k < vps->getNumSubDpbs(i); k++)
+#endif
+      {
+        Int layerId = vps->getLayerSetLayerIdList(layerSetId, k); // k-th layer in the output layer set
+#if RESOLUTION_BASED_DPB
+        vps->setMaxVpsLayerDecPicBuffMinus1( i, k, j, m_acTEncTop[layerId].getMaxDecPicBuffering(j) - 1 );
+        // Add sub-DPB sizes of layers belonging to a sub-DPB. If a different sub-DPB size is calculated
+        // at the encoder, modify below
+        Int oldValue = vps->getMaxVpsDecPicBufferingMinus1( i, vps->getSubDpbAssigned( layerSetIdxForOutputLayerSet, k ), j );
+        oldValue += vps->getMaxVpsLayerDecPicBuffMinus1( i, k, j ) + 1;
+        vps->setMaxVpsDecPicBufferingMinus1( i, vps->getSubDpbAssigned( layerSetIdxForOutputLayerSet, k ), j, oldValue );
+#else
+        vps->setMaxVpsDecPicBufferingMinus1( i, k, j,  m_acTEncTop[layerId].getMaxDecPicBuffering(j) - 1 );
+#endif
+        maxNumReorderPics       = std::max( maxNumReorderPics, m_acTEncTop[layerId].getNumReorderPics(j));
+      }
+#if RESOLUTION_BASED_DPB
+      for(Int k = 0; k < vps->getNumSubDpbs(i); k++)
+      {
+        // Decrement m_maxVpsDecPicBufferingMinus1
+        Int oldValue = vps->getMaxVpsDecPicBufferingMinus1( i, vps->getSubDpbAssigned( layerSetIdxForOutputLayerSet, k ), j );
+        vps->setMaxVpsDecPicBufferingMinus1( i, vps->getSubDpbAssigned( layerSetIdxForOutputLayerSet, k ), j, oldValue - 1 );
+      }
+#endif
+      vps->setMaxVpsNumReorderPics(i, j, maxNumReorderPics);
+      vps->determineSubDpbInfoFlags();
+    }
+  }
 #endif
     vps->setMaxOneActiveRefLayerFlag(maxDirectRefLayers > 1 ? false : true);
@@ -1505,5 +1510,9 @@
   {
     vps->setVpsVuiBspHrdPresentFlag(true);
+#if Q0078_ADD_LAYER_SETS
+    vps->setVpsNumBspHrdParametersMinus1(vps->getVpsNumLayerSetsMinus1() - 1); 
+#else
     vps->setVpsNumBspHrdParametersMinus1(vps->getNumLayerSets() - 2); 
+#endif
     vps->createBspHrdParamBuffer(vps->getVpsNumBspHrdParametersMinus1() + 1);
     for ( i = 0; i <= vps->getVpsNumBspHrdParametersMinus1(); i++ )
@@ -1538,5 +1547,9 @@
       vps->setBspHrdParameters( i, pcCfgLayer->getFrameRate(), numDU, pcCfgLayer->getTargetBitrate(), ( pcCfgLayer->getIntraPeriod() > 0 ) );
     }
+#if Q0078_ADD_LAYER_SETS
+    for (UInt h = 1; h <= vps->getVpsNumLayerSetsMinus1(); h++)
+#else
     for(UInt h = 1; h <= (vps->getNumLayerSets()-1); h++)
+#endif
     {
       vps->setNumBitstreamPartitions(h, 1);
Index: branches/SHM-6-dev/source/Lib/TLibCommon/TComRom.h
===================================================================
--- branches/SHM-6-dev/source/Lib/TLibCommon/TComRom.h	(revision 804)
+++ branches/SHM-6-dev/source/Lib/TLibCommon/TComRom.h	(revision 805)
@@ -159,5 +159,5 @@
 
 #ifndef ENC_DEC_TRACE
-# define ENC_DEC_TRACE 1
+# define ENC_DEC_TRACE 0
 #endif
 
Index: branches/SHM-6-dev/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- branches/SHM-6-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 804)
+++ branches/SHM-6-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 805)
@@ -2711,4 +2711,31 @@
   setNumIndependentLayers(numIndependentLayers);
 }
+
+void TComVPS::setLayerIdIncludedFlagsForAddLayerSets()
+{
+  for (UInt i = 0; i < getNumAddLayerSets(); i++)
+  {
+    for (UInt j = 1; j < getNumIndependentLayers(); j++)
+    {
+      Int layerNum = 0;
+      Int lsIdx = getVpsNumLayerSetsMinus1() + 1 + i;
+      for (Int layerId = 0; layerId < MAX_VPS_LAYER_ID_PLUS1; layerId++)
+      {
+        setLayerIdIncludedFlag(false, lsIdx, layerId);
+      }
+      for (Int treeIdx = 1; treeIdx < getNumIndependentLayers(); treeIdx++)
+      {
+        for (Int layerCnt = 0; layerCnt < getHighestLayerIdxPlus1(i, j); layerCnt++)
+        {
+          setLayerSetLayerIdList(lsIdx, layerNum, getTreePartitionLayerId(treeIdx, layerCnt));
+          setLayerIdIncludedFlag(true, lsIdx, getTreePartitionLayerId(treeIdx, layerCnt));
+          layerNum++;
+        }
+      }
+      setNumLayersInIdList(lsIdx, layerNum);
+    }
+  }
+}
+
 #endif
 
Index: branches/SHM-6-dev/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- branches/SHM-6-dev/source/Lib/TLibCommon/TComSlice.h	(revision 804)
+++ branches/SHM-6-dev/source/Lib/TLibCommon/TComSlice.h	(revision 805)
@@ -140,7 +140,4 @@
   
   Void  create  (Int numberOfEntries);
-#if Q0078_ADD_LAYER_SETS
-  Void  copy(TComRPSList& a);
-#endif
   Void  destroy();
 
@@ -487,6 +484,11 @@
 #if SVC_EXTENSION
 #if DERIVE_LAYER_ID_LIST_VARIABLES
+#if Q0078_ADD_LAYER_SETS
+  Int         m_layerSetLayerIdList[MAX_VPS_LAYER_SETS_PLUS1 + MAX_NUM_ADD_LAYER_SETS][MAX_VPS_LAYER_ID_PLUS1];
+  Int         m_numLayerInIdList[MAX_VPS_LAYER_SETS_PLUS1 + MAX_NUM_ADD_LAYER_SETS];
+#else
   Int         m_layerSetLayerIdList[MAX_VPS_LAYER_SETS_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
   Int         m_numLayerInIdList[MAX_VPS_LAYER_SETS_PLUS1];
+#endif
 #endif
 #if !P0125_REVERT_VPS_EXTN_OFFSET_TO_RESERVED
@@ -498,5 +500,6 @@
   UInt        m_numLayerSets;
 #if Q0078_ADD_LAYER_SETS
-  Bool        m_layerIdIncludedFlag[2*MAX_VPS_LAYER_SETS_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
+  UInt        m_vpsNumLayerSetsMinus1;
+  Bool        m_layerIdIncludedFlag[MAX_VPS_LAYER_SETS_PLUS1 + MAX_NUM_ADD_LAYER_SETS][MAX_VPS_LAYER_ID_PLUS1];
 #else
   Bool        m_layerIdIncludedFlag[MAX_VPS_LAYER_SETS_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
@@ -520,5 +523,9 @@
 #endif
 #if BITRATE_PICRATE_SIGNALLING
+#if Q0078_ADD_LAYER_SETS
+  UInt       m_maxSLInLayerSetMinus1[MAX_VPS_LAYER_SETS_PLUS1 + MAX_NUM_ADD_LAYER_SETS];
+#else
   UInt       m_maxSLInLayerSetMinus1[MAX_VPS_LAYER_SETS_PLUS1];
+#endif
 #endif
     
@@ -536,6 +543,11 @@
   // Target output layer signalling related
   UInt       m_numOutputLayerSets;
+#if Q0078_ADD_LAYER_SETS
+  UInt       m_outputLayerSetIdx[MAX_VPS_LAYER_SETS_PLUS1 + 2*MAX_NUM_ADD_LAYER_SETS];
+  Bool       m_outputLayerFlag[MAX_VPS_LAYER_SETS_PLUS1 + 2*MAX_NUM_ADD_LAYER_SETS][MAX_VPS_LAYER_ID_PLUS1];
+#else
   UInt       m_outputLayerSetIdx[MAX_VPS_LAYER_SETS_PLUS1];
   Bool       m_outputLayerFlag[MAX_VPS_LAYER_SETS_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
+#endif
 #endif
 #if VPS_EXTN_DIRECT_REF_LAYERS
@@ -633,5 +645,9 @@
 
 #if P0300_ALT_OUTPUT_LAYER_FLAG
+#if Q0078_ADD_LAYER_SETS
+  Bool       m_altOutputLayerFlag[MAX_VPS_LAYER_SETS_PLUS1 + 2*MAX_NUM_ADD_LAYER_SETS];
+#else
   Bool       m_altOutputLayerFlag[MAX_VPS_LAYER_SETS_PLUS1];
+#endif
 #else
 #if O0153_ALT_OUTPUT_LAYER_FLAG
@@ -664,6 +680,6 @@
 #if Q0078_ADD_LAYER_SETS
   Int        m_numAddLayerSets;
-  UInt       m_highestLayerIdxPlus1[MAX_VPS_LAYER_SETS_PLUS1][MAX_NUM_LAYER_IDS];
-  UInt       m_predictedLayerId[MAX_NUM_LAYER_IDS][64];
+  UInt       m_highestLayerIdxPlus1[MAX_NUM_ADD_LAYER_SETS][MAX_NUM_LAYER_IDS];
+  UInt       m_predictedLayerId[MAX_NUM_LAYER_IDS][MAX_NUM_LAYER_IDS];
   UInt       m_numPredictedLayers[MAX_NUM_LAYER_IDS];
   Int        m_numIndependentLayers;
@@ -684,5 +700,9 @@
   Int        m_maxVpsLatencyIncreasePlus1  [MAX_VPS_OP_LAYER_SETS_PLUS1][MAX_LAYERS];
 #if CHANGE_NUMSUBDPB_IDX
+#if Q0078_ADD_LAYER_SETS
+  Int        m_numSubDpbs                  [MAX_VPS_LAYER_SETS_PLUS1 + 2*MAX_NUM_ADD_LAYER_SETS];
+#else
   Int        m_numSubDpbs                  [MAX_VPS_LAYER_SETS_PLUS1];
+#endif
 #else
   Int        m_numSubDpbs                  [MAX_VPS_OP_LAYER_SETS_PLUS1];
@@ -816,8 +836,11 @@
 #endif
 #if Q0078_ADD_LAYER_SETS
+  void    setLayerIdIncludedFlagsForAddLayerSets();
+  UInt    getVpsNumLayerSetsMinus1()                                             { return m_vpsNumLayerSetsMinus1; }
+  Void    setVpsNumLayerSetsMinus1(UInt x)                                       { m_vpsNumLayerSetsMinus1 = x; }
   UInt    getNumAddLayerSets()                                                   { return m_numAddLayerSets; }
   Void    setNumAddLayerSets(UInt x)                                             { m_numAddLayerSets = x; }
-  UInt    getHighestLayerIdxPlus1(UInt set, UInt idx)                             { return m_highestLayerIdxPlus1[set][idx]; }
-  Void    setHighestLayerIdxPlus1(UInt set, UInt idx, UInt layerIdx)              { m_highestLayerIdxPlus1[set][idx] = layerIdx; }
+  UInt    getHighestLayerIdxPlus1(UInt set, UInt idx)                            { return m_highestLayerIdxPlus1[set][idx]; }
+  Void    setHighestLayerIdxPlus1(UInt set, UInt idx, UInt layerIdx)             { m_highestLayerIdxPlus1[set][idx] = layerIdx; }
   Void    setPredictedLayerIds();
   UInt    getPredictedLayerId(UInt layerIdx, UInt predIdx)                       { return m_predictedLayerId[layerIdx][predIdx]; }
Index: branches/SHM-6-dev/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- branches/SHM-6-dev/source/Lib/TLibCommon/TypeDef.h	(revision 804)
+++ branches/SHM-6-dev/source/Lib/TLibCommon/TypeDef.h	(revision 805)
@@ -204,4 +204,7 @@
 
 #define Q0078_ADD_LAYER_SETS             1      ///< JCTVC-Q0078: additional layer sets and layer set config
+#if Q0078_ADD_LAYER_SETS
+#define MAX_NUM_ADD_LAYER_SETS           1023
+#endif
 
 #define VPS_DPB_SIZE_TABLE               1      ///< JCTVC-O0217: DPB operations: signaling DPB-related parameters
Index: branches/SHM-6-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- branches/SHM-6-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 804)
+++ branches/SHM-6-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 805)
@@ -973,6 +973,12 @@
   assert( pcVPS->getMaxLayerId()       < MAX_VPS_LAYER_ID_PLUS1 );
   READ_CODE( 6, uiCode, "vps_max_layer_id" );           pcVPS->setMaxLayerId( uiCode );
+#if Q0078_ADD_LAYER_SETS
+  READ_UVLC(uiCode, "vps_num_layer_sets_minus1");  pcVPS->setVpsNumLayerSetsMinus1(uiCode);
+  pcVPS->setNumLayerSets(pcVPS->getVpsNumLayerSetsMinus1() + 1);
+  for (UInt opsIdx = 1; opsIdx <= pcVPS->getVpsNumLayerSetsMinus1(); opsIdx++)
+#else
   READ_UVLC(    uiCode, "vps_num_layer_sets_minus1" );  pcVPS->setNumLayerSets( uiCode + 1 );
   for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getNumLayerSets() - 1 ); opsIdx ++ )
+#endif
   {
     // Operation point set
@@ -1310,27 +1316,6 @@
       }
     }
-
-    for (i = 0; i < vps->getNumAddLayerSets(); i++)
-    {
-      for (j = 1; j < vps->getNumIndependentLayers(); j++)
-      {
-        Int layerNum = 0;
-        Int lsIdx = vps->getNumLayerSets() + i;
-        for (Int layerId = 0; layerId < MAX_VPS_LAYER_ID_PLUS1; layerId++)
-        {
-          vps->setLayerIdIncludedFlag(false, lsIdx, layerId);
-        }
-        for (Int treeIdx = 1; treeIdx < vps->getNumIndependentLayers(); treeIdx++)
-        {
-          for (Int layerCnt = 0; layerCnt < vps->getHighestLayerIdxPlus1(i, j); layerCnt++)
-          {
-            vps->setLayerSetLayerIdList(lsIdx, layerNum, vps->getTreePartitionLayerId(treeIdx, layerCnt));
-            vps->setLayerIdIncludedFlag(true, lsIdx, vps->getTreePartitionLayerId(treeIdx, layerCnt));
-            layerNum++;
-          }
-        }
-        vps->setNumLayersInIdList(lsIdx, layerNum);
-      }
-    }
+    vps->setNumLayerSets(vps->getNumLayerSets() + vps->getNumAddLayerSets());
+    vps->setLayerIdIncludedFlagsForAddLayerSets();
   }
 #endif
@@ -1394,5 +1379,9 @@
       vps->setOutputLayerSetIdx( i, i );
     }
+#if Q0078_ADD_LAYER_SETS
+    if ( i > vps->getVpsNumLayerSetsMinus1() || vps->getDefaultTargetOutputLayerIdc() >= 2 )
+#else
     if ( i > (vps->getNumLayerSets() - 1) || vps->getDefaultTargetOutputLayerIdc() >= 2 )
+#endif
     {
       Int lsIdx = vps->getOutputLayerSetIdx(i);
@@ -2135,5 +2124,9 @@
   Bool parseFlag = vps->getBitRatePresentVpsFlag() || vps->getPicRatePresentVpsFlag();
 
+#if Q0078_ADD_LAYER_SETS
+  for( i = 0; i <= vps->getVpsNumLayerSetsMinus1(); i++ )
+#else
   for( i = 0; i < vps->getNumLayerSets(); i++ )
+#endif
   {
 #if BITRATE_PICRATE_SIGNALLING
@@ -2367,5 +2360,9 @@
         parseHrdParameters(vps->getBspHrd(i), i==0 ? 1 : vps->getBspCprmsPresentFlag(i), vps->getMaxTLayers()-1);
       }
+#if Q0078_ADD_LAYER_SETS
+      for (UInt h = 1; h <= vps->getVpsNumLayerSetsMinus1(); h++)
+#else
       for( UInt h = 1; h <= (vps->getNumLayerSets()-1); h++ )
+#endif
       {
         READ_UVLC( uiCode, "num_bitstream_partitions[i]"); vps->setNumBitstreamPartitions(h, uiCode);
@@ -2776,5 +2773,9 @@
           if(rpcSlice->getVPS()->getVpsExtensionFlag()==1)
           {
+#if Q0078_ADD_LAYER_SETS
+              for (Int ii = 1; ii < (rpcSlice->getVPS()->getVpsNumLayerSetsMinus1() + 1); ii++)  // prevent assert error when num_add_layer_sets > 0
+#else
               for (Int ii=1; ii< rpcSlice->getVPS()->getNumOutputLayerSets(); ii++ )
+#endif
               {
                   Int layerSetIdxForOutputLayerSet = rpcSlice->getVPS()->getOutputLayerSetIdx( ii );
@@ -2789,4 +2790,5 @@
                   if(chkAssert)
                   {
+                      // There may be something wrong here (layer id assumed to be layer idx?)
                       assert(rps->getNumberOfNegativePictures() <= rpcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii , rpcSlice->getLayerId() , rpcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)));
                       assert(rps->getNumberOfPositivePictures() <= rpcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii , rpcSlice->getLayerId() , rpcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)) - rps->getNumberOfNegativePictures());
Index: branches/SHM-6-dev/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- branches/SHM-6-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 804)
+++ branches/SHM-6-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 805)
@@ -745,6 +745,11 @@
 #endif
   WRITE_CODE( pcVPS->getMaxLayerId(), 6,                       "vps_max_layer_id" );
+#if Q0078_ADD_LAYER_SETS
+  WRITE_UVLC(pcVPS->getVpsNumLayerSetsMinus1(),                "vps_num_layer_sets_minus1");
+  for (UInt opsIdx = 1; opsIdx <= pcVPS->getVpsNumLayerSetsMinus1(); opsIdx++)
+#else
   WRITE_UVLC( pcVPS->getNumLayerSets() - 1,                 "vps_num_layer_sets_minus1" );
-  for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getNumLayerSets() - 1 ); opsIdx ++ )
+  for (UInt opsIdx = 1; opsIdx <= (pcVPS->getNumLayerSets() - 1); opsIdx++)
+#endif
   {
     // Operation point set
@@ -1065,5 +1070,9 @@
 #if P0295_DEFAULT_OUT_LAYER_IDC
     }
+#if Q0078_ADD_LAYER_SETS
+    if ( i > vps->getVpsNumLayerSetsMinus1() || vps->getDefaultTargetOutputLayerIdc() >= 2 ) //Instead of == 2, >= 2 is used to follow the agreement that value 3 should be interpreted as 2
+#else
     if ( i > (vps->getNumLayerSets() - 1) || vps->getDefaultTargetOutputLayerIdc() >= 2 ) //Instead of == 2, >= 2 is used to follow the agreement that value 3 should be interpreted as 2
+#endif
     {
 #endif
@@ -1469,5 +1478,9 @@
   if( vps->getBitRatePresentVpsFlag() || vps->getPicRatePresentVpsFlag() )
   {
+#if Q0078_ADD_LAYER_SETS
+    for( i = 0; i <= vps->getVpsNumLayerSetsMinus1(); i++ )
+#else
     for( i = 0; i < vps->getNumLayerSets(); i++ )
+#endif
     {
 #if BITRATE_PICRATE_SIGNALLING
@@ -1641,5 +1654,9 @@
         codeHrdParameters(vps->getBspHrd(i), i==0 ? 1 : vps->getBspCprmsPresentFlag(i), vps->getMaxTLayers()-1);
       }
+#if Q0078_ADD_LAYER_SETS
+      for( UInt h = 1; h <= vps->getVpsNumLayerSetsMinus1(); h++ )
+#else
       for( UInt h = 1; h <= (vps->getNumLayerSets()-1); h++ )
+#endif
       {
         WRITE_UVLC( vps->getNumBitstreamPartitions(h), "num_bitstream_partitions[i]");
