Index: /branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- /branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncTop.cpp	(revision 89)
+++ /branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncTop.cpp	(revision 90)
@@ -75,19 +75,20 @@
 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 );
+  }
+
   for(UInt layer=0; layer<m_numLayers; layer++)
   {
-    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_acTEncTop[layer].setVPS(&vps);
     m_acTEncTop[layer].setFrameRate                    ( m_acLayerCfg[layer].getFrameRate() );
Index: /branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- /branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComSlice.cpp	(revision 89)
+++ /branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComSlice.cpp	(revision 90)
@@ -44,4 +44,9 @@
 //! \ingroup TLibCommon
 //! \{
+
+#if SVC_EXTENSION
+  ParameterSetMap<TComVPS> ParameterSetManager::m_vpsMap(MAX_NUM_VPS);
+  Int ParameterSetManager::m_activeVPSId = -1;
+#endif
 
 TComSlice::TComSlice()
@@ -1904,4 +1909,10 @@
 
 ParameterSetManager::ParameterSetManager()
+#if SVC_EXTENSION
+: m_spsMap(MAX_NUM_SPS)
+, m_ppsMap(MAX_NUM_PPS)
+, m_activeSPSId(-1)
+, m_activePPSId(-1)
+#else
 : m_vpsMap(MAX_NUM_VPS)
 , m_spsMap(MAX_NUM_SPS)
@@ -1910,4 +1921,5 @@
 , m_activeSPSId(-1)
 , m_activePPSId(-1)
+#endif
 {
 }
@@ -1946,9 +1958,5 @@
 //! activate a PPS and depending on isIDR parameter also SPS and VPS
 //! \returns true, if activation is successful
-#if SVC_EXTENSION
-Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIDR, UInt layerId)
-#else
 Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIDR)
-#endif
 {
   TComPPS *pps = m_ppsMap.getPS(ppsId);
@@ -1956,9 +1964,5 @@
   {
     Int spsId = pps->getSPSId();
-#if SVC_EXTENSION
-    if (!isIDR && (spsId != layerId ))
-#else
     if (!isIDR && (spsId != m_activeSPSId))
-#endif
     {
       printf("Warning: tried to activate PPS referring to a inactive SPS at non-IDR.");
Index: /branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- /branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComSlice.h	(revision 89)
+++ /branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComSlice.h	(revision 90)
@@ -1676,9 +1676,5 @@
   //! activate a PPS and depending on isIDR parameter also SPS and VPS
   //! \returns true, if activation is successful
-#if SVC_EXTENSION
-  Bool activatePPS(Int ppsId, Bool isIDR, UInt layerId);
-#else
   Bool activatePPS(Int ppsId, Bool isIDR);
-#endif
 
   TComVPS* getActiveVPS(){ return m_vpsMap.getPS(m_activeVPSId); };
@@ -1687,10 +1683,18 @@
 
 protected:
-  
+
+#if SVC_EXTENSION
+  static ParameterSetMap<TComVPS> m_vpsMap;
+#else
   ParameterSetMap<TComVPS> m_vpsMap;
+#endif
   ParameterSetMap<TComSPS> m_spsMap; 
   ParameterSetMap<TComPPS> m_ppsMap;
 
+#if SVC_EXTENSION
+  static Int m_activeVPSId;
+#else
   Int m_activeVPSId;
+#endif
   Int m_activeSPSId;
   Int m_activePPSId;
Index: /branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecSlice.cpp
===================================================================
--- /branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecSlice.cpp	(revision 89)
+++ /branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecSlice.cpp	(revision 90)
@@ -41,4 +41,8 @@
 //! \{
 
+#if SVC_EXTENSION
+  ParameterSetMap<TComVPS> ParameterSetManagerDecoder::m_vpsBuffer(MAX_NUM_VPS);
+#endif
+
 //////////////////////////////////////////////////////////////////////
 // Construction/Destruction
@@ -398,7 +402,12 @@
 
 ParameterSetManagerDecoder::ParameterSetManagerDecoder()
+#if SVC_EXTENSION
+: m_spsBuffer(MAX_NUM_SPS)
+, m_ppsBuffer(MAX_NUM_PPS)
+#else
 : m_vpsBuffer(MAX_NUM_VPS)
 , m_spsBuffer(MAX_NUM_SPS)
 , m_ppsBuffer(MAX_NUM_PPS)
+#endif
 {
 }
Index: /branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecSlice.h
===================================================================
--- /branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecSlice.h	(revision 89)
+++ /branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecSlice.h	(revision 90)
@@ -111,5 +111,9 @@
 
 private:
+#if SVC_EXTENSION
+  static ParameterSetMap<TComVPS> m_vpsBuffer;
+#else
   ParameterSetMap<TComVPS> m_vpsBuffer;
+#endif
   ParameterSetMap<TComSPS> m_spsBuffer; 
   ParameterSetMap<TComPPS> m_ppsBuffer;
Index: /branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- /branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecTop.cpp	(revision 89)
+++ /branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecTop.cpp	(revision 90)
@@ -40,5 +40,4 @@
 
 #if SVC_EXTENSION
-ParameterSetManagerDecoder TDecTop::m_parameterSetManagerDecoder;  // storage for parameter sets 
 UInt  TDecTop::m_prevPOC = MAX_UINT;
 UInt  TDecTop::m_uiPrevLayerId = MAX_UINT;
@@ -332,18 +331,22 @@
   printf("\ninserting lost poc : %d\n",iLostPoc);
   TComSlice cFillSlice;
+#if SVC_EXTENSION
+  cFillSlice.setSPS( m_parameterSetManagerDecoder[m_layerId].getFirstSPS() );
+  cFillSlice.setPPS( m_parameterSetManagerDecoder[m_layerId].getFirstPPS() );
+  cFillSlice.initSlice( m_layerId );
+#else
   cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
   cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
-#if SVC_EXTENSION
-  cFillSlice.initSlice( m_parameterSetManagerDecoder.getFirstSPS()->getLayerId() );
-#else
   cFillSlice.initSlice();
 #endif
   TComPic *cFillPic;
   xGetNewPicBuffer(&cFillSlice,cFillPic);
+#if SVC_EXTENSION
+  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder[m_layerId].getFirstSPS() );
+  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder[m_layerId].getFirstPPS() );
+  cFillPic->getSlice(0)->initSlice( m_layerId );
+#else
   cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
   cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
-#if SVC_EXTENSION
-  cFillPic->getSlice(0)->initSlice( cFillPic->getLayerId() );
-#else
   cFillPic->getSlice(0)->initSlice();
 #endif
@@ -388,4 +391,15 @@
 Void TDecTop::xActivateParameterSets()
 {
+#if SVC_EXTENSION
+  m_parameterSetManagerDecoder[m_layerId].applyPrefetchedPS();
+  
+  TComPPS *pps = m_parameterSetManagerDecoder[m_layerId].getPPS(m_apcSlicePilot->getPPSId());
+  assert (pps != 0);
+
+  TComSPS *sps = m_parameterSetManagerDecoder[m_layerId].getSPS(pps->getSPSId());
+  assert (sps != 0);
+
+  if( false == m_parameterSetManagerDecoder[m_layerId].activatePPS(m_apcSlicePilot->getPPSId(), m_apcSlicePilot->getIdrPicFlag()) )
+#else
   m_parameterSetManagerDecoder.applyPrefetchedPS();
   
@@ -396,7 +410,4 @@
   assert (sps != 0);
 
-#if SVC_EXTENSION
-  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(), m_apcSlicePilot->getIdrPicFlag(), m_apcSlicePilot->getLayerId() ))
-#else
   if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->getIdrPicFlag()))
 #endif
@@ -460,5 +471,9 @@
   m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
 
+#if SVC_EXTENSION
+  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder[m_layerId]);
+#else
   m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
+#endif
   if (m_apcSlicePilot->isNextSlice())
   {
@@ -713,8 +728,6 @@
   {
     pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA );
-#if !REF_IDX_FRAMEWORK || AVC_SYNTAX
     // Set reference list
     pcSlice->setRefPicList( m_cListPic );
-#endif
 
 #if SVC_EXTENSION   
@@ -756,8 +769,4 @@
 
 #if REF_IDX_FRAMEWORK
-#if !AVC_SYNTAX
-    // Set reference list
-    pcSlice->setRefPicList( m_cListPic );
-#endif
     if(m_layerId > 0)
     {
@@ -869,5 +878,9 @@
   
   m_cEntropyDecoder.decodeVPS( vps );
+#if SVC_EXTENSION
+  m_parameterSetManagerDecoder[0].storePrefetchedVPS(vps);
+#else
   m_parameterSetManagerDecoder.storePrefetchedVPS(vps);  
+#endif
 }
 
@@ -879,5 +892,9 @@
 #endif
   m_cEntropyDecoder.decodeSPS( sps );
+#if SVC_EXTENSION
+  m_parameterSetManagerDecoder[m_layerId].storePrefetchedSPS(sps);
+#else
   m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
+#endif
 #if REF_IDX_MFM
   m_pcSPS = sps;
@@ -896,5 +913,9 @@
   TComPPS* pps = new TComPPS();
   m_cEntropyDecoder.decodePPS( pps );
+#if SVC_EXTENSION
+  m_parameterSetManagerDecoder[m_layerId].storePrefetchedPPS( pps );
+#else
   m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
+#endif
 
   if( pps->getDependentSliceSegmentsEnabledFlag() )
@@ -914,4 +935,25 @@
 Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
 {
+#if SVC_EXTENSION
+  if(nalUnitType == NAL_UNIT_SEI_SUFFIX)
+  {
+    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveSPS() );
+  }
+  else
+  {
+    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveSPS() );
+    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
+    if (activeParamSets.size()>0)
+    {
+      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
+      m_parameterSetManagerDecoder[m_layerId].applyPrefetchedPS();
+      assert(seiAps->activeSeqParamSetId.size()>0);
+      if (! m_parameterSetManagerDecoder[m_layerId].activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
+      {
+        printf ("Warning SPS activation with Active parameter set SEI failed");
+      }
+    }
+  }
+#else
   if(nalUnitType == NAL_UNIT_SEI_SUFFIX)
   {
@@ -933,4 +975,5 @@
     }
   }
+#endif
 }
 
Index: /branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- /branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecTop.h	(revision 89)
+++ /branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecTop.h	(revision 90)
@@ -73,5 +73,5 @@
   TComList<TComPic*>      m_cListPic;         //  Dynamic buffer
 #if SVC_EXTENSION
-  static ParameterSetManagerDecoder m_parameterSetManagerDecoder;  // storage for parameter sets 
+  ParameterSetManagerDecoder m_parameterSetManagerDecoder[MAX_LAYERS];  // storage for parameter sets 
 #else
   ParameterSetManagerDecoder m_parameterSetManagerDecoder;  // storage for parameter sets 
Index: /branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- /branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 89)
+++ /branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 90)
@@ -1021,4 +1021,10 @@
 #if SVC_EXTENSION
       OutputNALUnit nalu(NAL_UNIT_VPS, 0, m_layerId);
+#if AVC_BASE
+      if( m_layerId == 1 )
+#else
+      if( m_layerId == 0 )
+#endif
+      {
 #else
       OutputNALUnit nalu(NAL_UNIT_VPS);
@@ -1030,4 +1036,7 @@
 #if RATE_CONTROL_LAMBDA_DOMAIN
       actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8;
+#endif
+#if SVC_EXTENSION
+      }
 #endif
 
