Index: branches/SHM-2.0-dev/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- branches/SHM-2.0-dev/source/Lib/TLibCommon/TComDataCU.cpp	(revision 133)
+++ branches/SHM-2.0-dev/source/Lib/TLibCommon/TComDataCU.cpp	(revision 134)
@@ -1835,5 +1835,5 @@
   {
     Int refIdxL0 = cMvFieldL0.getRefIdx();
-    if(getSlice()->getRefPic(REF_PIC_LIST_0, refIdxL0)->isILR())
+    if(getSlice()->getRefPic(REF_PIC_LIST_0, refIdxL0)->isILR(m_layerId))
     {
       checkZeroMVILR &= (cMvFieldL0.getHor() == 0 && cMvFieldL0.getVer() == 0);
@@ -1843,5 +1843,5 @@
   {
     Int refIdxL1  = cMvFieldL1.getRefIdx();
-    if(getSlice()->getRefPic(REF_PIC_LIST_1, refIdxL1)->isILR())
+    if(getSlice()->getRefPic(REF_PIC_LIST_1, refIdxL1)->isILR(m_layerId))
     {
       checkZeroMVILR &= (cMvFieldL1.getHor() == 0 && cMvFieldL1.getVer() == 0);
@@ -1859,5 +1859,5 @@
   Bool checkZeroMVILR = true;
 
-  if(getSlice()->getRefPic(eRefPicList, iRefIdx)->isILR())
+  if(getSlice()->getRefPic(eRefPicList, iRefIdx)->isILR(m_layerId))
   {
     AMVPInfo* pcAMVPInfo = getCUMvField(eRefPicList)->getAMVPInfo();
Index: branches/SHM-2.0-dev/source/Lib/TLibCommon/TComPic.h
===================================================================
--- branches/SHM-2.0-dev/source/Lib/TLibCommon/TComPic.h	(revision 133)
+++ branches/SHM-2.0-dev/source/Lib/TLibCommon/TComPic.h	(revision 134)
@@ -124,5 +124,5 @@
 #endif
 #if REF_IDX_ME_ZEROMV || ENCODER_FAST_MODE || REF_IDX_MFM
-  Bool          isILR( UInt refLayer = 0 )   {return (getIsLongTerm() && m_layerId == refLayer);}
+  Bool          isILR( UInt currLayerId )   { return ( getIsLongTerm() && m_layerId < currLayerId ); }
 #endif
 
Index: branches/SHM-2.0-dev/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- branches/SHM-2.0-dev/source/Lib/TLibCommon/TComPrediction.cpp	(revision 133)
+++ branches/SHM-2.0-dev/source/Lib/TLibCommon/TComPrediction.cpp	(revision 134)
@@ -495,5 +495,5 @@
 
 #if REF_IDX_ME_ZEROMV
-  assert( ( pcCU->getSlice()->getRefPic(eRefPicList, iRefIdx)->isILR() && cMv.getHor() == 0 && cMv.getVer() == 0 ) || pcCU->getSlice()->getRefPic(eRefPicList, iRefIdx)->isILR() == false );
+  assert( ( pcCU->getSlice()->getRefPic(eRefPicList, iRefIdx)->isILR(pcCU->getLayerId()) && cMv.getHor() == 0 && cMv.getVer() == 0 ) || pcCU->getSlice()->getRefPic(eRefPicList, iRefIdx)->isILR(pcCU->getLayerId()) == false );
 #endif
 
Index: branches/SHM-2.0-dev/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- branches/SHM-2.0-dev/source/Lib/TLibCommon/TComSlice.h	(revision 133)
+++ branches/SHM-2.0-dev/source/Lib/TLibCommon/TComSlice.h	(revision 134)
@@ -663,12 +663,12 @@
 #if VPS_EXTN_DIRECT_REF_LAYERS
   // Direct dependency of layers
-  Bool   getDirectDependencyFlag(Int i, Int j)                  { return m_directDependencyFlag[i][j]; }
-  Void   setDirectDependencyFlag(Int i, Int j, Bool x)          { m_directDependencyFlag[i][j] = x;    }
-  
-  UInt   getNumDirectRefLayers(Int i)                                { return m_numDirectRefLayers[i];         }
-  Void   setNumDirectRefLayers(Int i, UInt x)                        { m_numDirectRefLayers[i] = x;            }
-
-  UInt   getRefLayerId(Int i, Int j)                            { return m_refLayerId[i][j];           }
-  Void   setRefLayerId(Int i, Int j, UInt x)                    { m_refLayerId[i][j] = x;              }
+  Bool   getDirectDependencyFlag(Int currLayerId, Int refLayerId)               { return m_directDependencyFlag[currLayerId][refLayerId]; }
+  Void   setDirectDependencyFlag(Int currLayerId, Int refLayerId, Bool x)       { m_directDependencyFlag[currLayerId][refLayerId] = x;    }
+  
+  UInt   getNumDirectRefLayers(Int layerId)                                     { return m_numDirectRefLayers[layerId];                   }
+  Void   setNumDirectRefLayers(Int layerId, UInt refLayerNum)                   { m_numDirectRefLayers[layerId] = refLayerNum;            }
+
+  UInt   getRefLayerId(Int layerId, Int refLayerIdx)                            { return m_refLayerId[layerId][refLayerIdx];              }
+  Void   setRefLayerId(Int layerId, Int refLayerIdx, UInt refLayerId)           { m_refLayerId[layerId][refLayerIdx] = refLayerId;        }
 #endif
 };
Index: branches/SHM-2.0-dev/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- branches/SHM-2.0-dev/source/Lib/TLibCommon/TypeDef.h	(revision 133)
+++ branches/SHM-2.0-dev/source/Lib/TLibCommon/TypeDef.h	(revision 134)
@@ -44,4 +44,6 @@
 
 #if SVC_EXTENSION
+#define MAX_LAYERS                       2      ///< max number of layers the codec is supposed to handle
+
 #define VPS_RENAME                       1      ///< Rename variables max_layer_id and num_layer_sets_minus1 in VPS
 #define VPS_EXTNS                        1      ///< Include function structure for VPS extensions
@@ -51,6 +53,6 @@
 #define VPS_EXTN_PROFILE_INFO            1      ///< Include profile information for layer sets in VPS extension
 #define VPS_EXTN_DIRECT_REF_LAYERS       1      ///< Include indication of direct dependency of layers in VPS extension
-#endif
-#define MAX_LAYERS                       2      ///< max number of layers the codec is supposed to handle
+#define VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE   1
+#endif
 
 #define SVC_COL_BLK                      1      ///< get co-located block
@@ -159,5 +161,5 @@
 #if VPS_RENAME
 #define MAX_VPS_LAYER_SETS_PLUS1                  1024
-#define MAX_VPS_LAYER_ID_PLUS1                    2
+#define MAX_VPS_LAYER_ID_PLUS1                    MAX_LAYERS
 #else
 #define MAX_VPS_NUM_HRD_PARAMETERS                1
Index: branches/SHM-2.0-dev/source/Lib/TLibDecoder/TDecGop.cpp
===================================================================
--- branches/SHM-2.0-dev/source/Lib/TLibDecoder/TDecGop.cpp	(revision 133)
+++ branches/SHM-2.0-dev/source/Lib/TLibDecoder/TDecGop.cpp	(revision 134)
@@ -247,4 +247,11 @@
     for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++)
     {
+#if VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE
+      if( pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->isILR( m_layerId ) )
+      {
+        printf( "%d(%d) ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex), pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->getLayerId() );
+      }
+      else
+#endif
       printf ("%d ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex));
     }
Index: branches/SHM-2.0-dev/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- branches/SHM-2.0-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 133)
+++ branches/SHM-2.0-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 134)
@@ -179,5 +179,5 @@
     m_cIlpPic[0]->copyUpsampledPictureYuv(pcPic->getFullPelBaseRec(), m_cIlpPic[0]->getPicYuvRec());
     m_cIlpPic[0]->getSlice(0)->setPOC(pcPic->getPOC());
-    m_cIlpPic[0]->setLayerId(0); //set reference layerId
+    m_cIlpPic[0]->setLayerId(pcPic->getSlice(0)->getBaseColPic()->getLayerId()); //set reference layerId
     m_cIlpPic[0]->getPicYuvRec()->setBorderExtension(false);
     m_cIlpPic[0]->getPicYuvRec()->extendPicBorder();
@@ -243,5 +243,9 @@
     if(m_layerId > 0)
     {
+#if VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE
+      TDecTop *pcTDecTopBase = (TDecTop *)getRefLayerDec( m_layerId );
+#else
       TDecTop *pcTDecTopBase = (TDecTop *)getLayerDec( m_layerId-1 );
+#endif
       //TComPic*                      pcPic = *(pcTDecTopBase->getListPic()->begin()); 
       TComPicYuv* pcPicYuvRecBase = (*(pcTDecTopBase->getListPic()->begin()))->getPicYuvRec(); 
@@ -795,5 +799,9 @@
 
 #else
+#if VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE
+      TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( m_layerId );
+#else
       TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
+#endif
       TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
       pcSlice->setBaseColPic ( *cListPic, m_layerId );
@@ -1175,3 +1183,19 @@
 }
 
+#if VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE
+TDecTop* TDecTop::getRefLayerDec( UInt layerId )
+{
+  TComVPS* vps = m_parameterSetManagerDecoder[0].getActiveVPS();
+  if( vps->getNumDirectRefLayers( m_layerId ) <= 0 )
+  {
+    return NULL;
+  }
+
+  // currently only one reference layer is supported
+  assert( vps->getNumDirectRefLayers( m_layerId ) == 1 );
+
+  return (TDecTop *)getLayerDec( vps->getRefLayerId( m_layerId, 0 ) );
+}
+#endif
+
 //! \}
Index: branches/SHM-2.0-dev/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- branches/SHM-2.0-dev/source/Lib/TLibDecoder/TDecTop.h	(revision 133)
+++ branches/SHM-2.0-dev/source/Lib/TLibDecoder/TDecTop.h	(revision 134)
@@ -154,6 +154,9 @@
   Void      setNumLayer           (UInt uiNum)   { m_numLayer = uiNum;  }
   TComList<TComPic*>*      getListPic() { return &m_cListPic; }
-  Void                setLayerDec(TDecTop **p)    { m_ppcTDecTop = p; }
-  TDecTop*            getLayerDec(UInt layer)   { return m_ppcTDecTop[layer]; }
+  Void      setLayerDec(TDecTop **p)    { m_ppcTDecTop = p; }
+  TDecTop*  getLayerDec(UInt layer)     { return m_ppcTDecTop[layer]; }
+#if VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE
+  TDecTop*  getRefLayerDec(UInt layerId);
+#endif
 #if AVC_BASE
   Void      setBLReconFile( fstream* pFile ) { m_pBLReconFile = pFile; }
Index: branches/SHM-2.0-dev/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- branches/SHM-2.0-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 133)
+++ branches/SHM-2.0-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 134)
@@ -534,5 +534,9 @@
     if (m_layerId > 0)
     {
+#if VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE
+      TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId]->getRefLayerEnc(m_layerId)->getListPic();
+#else
       TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId-1]->getListPic();
+#endif
       pcSlice->setBaseColPic (*cListPic, m_layerId );
     }
@@ -734,5 +738,5 @@
         for(Int colIdx = 0; colIdx < pcSlice->getNumRefIdx( RefPicList(1 - ColFromL0Flag) ); colIdx++) 
         { 
-          if( pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->isILR() ) 
+          if( pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->isILR(m_layerId) ) 
           { 
             ColRefIdx = colIdx; 
@@ -747,5 +751,5 @@
           for(Int colIdx = 0; colIdx < pcSlice->getNumRefIdx( RefPicList(1 - ColFromL0Flag) ); colIdx++) 
           { 
-            if( pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->isILR() ) 
+            if( pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->isILR(m_layerId) ) 
             { 
               ColRefIdx = colIdx; 
@@ -2550,4 +2554,11 @@
     for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++)
     {
+#if VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE
+      if( pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->isILR(m_layerId) )
+      {
+        printf( "%d(%d) ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR(), pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->getLayerId() );
+      }
+      else
+#endif
       printf ("%d ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR());
     }
Index: branches/SHM-2.0-dev/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- branches/SHM-2.0-dev/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 133)
+++ branches/SHM-2.0-dev/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 134)
@@ -3296,5 +3296,5 @@
 #if (ENCODER_FAST_MODE)
         TComPic* pcPic    = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxTemp );
-        if( !testILR && pcPic->isILR() && (ePartSize == SIZE_2Nx2N) ) 
+        if( !testILR && pcPic->isILR(pcCU->getLayerId()) && (ePartSize == SIZE_2Nx2N) ) 
         {
           continue;
@@ -3622,5 +3622,5 @@
         Bool     testIter = true;
         TComPic* pcPic    = pcCU->getSlice()->getRefPic( RefPicList(1 - iRefList), iRefIdxBi[1 - iRefList] );
-        if(pcPic->isILR() && (ePartSize == SIZE_2Nx2N))
+        if(pcPic->isILR(pcCU->getLayerId()) && (ePartSize == SIZE_2Nx2N))
         {
           testIter = false;  //the fixed part is ILR, skip this iteration       
@@ -3637,5 +3637,5 @@
           Bool testRefIdx = true;
           pcPic           = pcCU->getSlice()->getRefPic( RefPicList(iRefList) , iRefIdxTemp );
-          if(pcPic->isILR() && (ePartSize == SIZE_2Nx2N))
+          if(pcPic->isILR(pcCU->getLayerId()) && (ePartSize == SIZE_2Nx2N))
           {
             testRefIdx = false;  //the refined part is ILR, skip this reference pic           
@@ -4308,5 +4308,5 @@
   //  Do integer search
 #if REF_IDX_ME_ZEROMV
-  if( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxPred )->isILR())  //ILR reference pic 
+  if( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxPred )->isILR(pcCU->getLayerId()))  //ILR reference pic 
   {
     rcMv.setZero();  //use Mv(0, 0) for integer ME 
@@ -4341,5 +4341,5 @@
   {
 #if REF_IDX_ME_ZEROMV
-    if( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxPred )->isILR())  //ILR reference pic
+    if( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxPred )->isILR(pcCU->getLayerId()))  //ILR reference pic
     {
       xPatternSearchFracDIFMv0( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost, bBi );
@@ -6315,5 +6315,5 @@
     for( Int refIdx = 0; refIdx < pcCU->getSlice()->getNumRefIdx(eRefPicList); refIdx++ )
     {
-      if( pcCU->getSlice()->getRefPic(eRefPicList, refIdx)->isILR() )
+      if( pcCU->getSlice()->getRefPic(eRefPicList, refIdx)->isILR(pcCU->getLayerId()) )
       {
         iRefIdxTemp = refIdx;
Index: branches/SHM-2.0-dev/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- branches/SHM-2.0-dev/source/Lib/TLibEncoder/TEncTop.cpp	(revision 133)
+++ branches/SHM-2.0-dev/source/Lib/TLibEncoder/TEncTop.cpp	(revision 134)
@@ -500,14 +500,4 @@
     {
       TEncPic* pcEPic = new TEncPic;
-#if SVC_EXTENSION //Temporal solution, should be modified
-      if(m_layerId > 0)
-      {
-        TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 );
-        if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() )
-        {
-          pcEPic->setSpatialEnhLayerFlag( true );
-        }
-      }
-#endif
 
 #if SVC_UPSAMPLING
@@ -524,14 +514,4 @@
       rpcPic = new TComPic;
 
-#if SVC_EXTENSION //Temporal solution, should be modified
-      if(m_layerId > 0)
-      {
-        TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 );
-        if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() )
-        {
-          rpcPic->setSpatialEnhLayerFlag( true );
-        }
-      }
-#endif
 
 #if SVC_UPSAMPLING
@@ -543,4 +523,20 @@
 #endif
     }
+
+#if SVC_EXTENSION //Temporal solution, should be modified
+      if(m_layerId > 0)
+      {
+#if VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE
+        TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( m_layerId );
+#else
+        TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 );
+#endif
+        if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() )
+        {
+          rpcPic->setSpatialEnhLayerFlag( true );
+        }
+      }
+#endif
+
     if (getUseSAO())
     {
@@ -1175,4 +1171,20 @@
 }
 
+#if SVC_EXTENSION
+#if VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE
+TEncTop* TEncTop::getRefLayerEnc( UInt layerId )
+{
+  if( m_ppcTEncTop[m_layerId]->getNumDirectRefLayers() <= 0 )
+  {
+    return NULL;
+  }
+
+  // currently only one reference layer is supported
+  assert( m_ppcTEncTop[m_layerId]->getNumDirectRefLayers() == 1 );
+
+  return (TEncTop *)getLayerEnc( getVPS()->getRefLayerId( m_layerId, 0 ) );
+}
+#endif
+
 #if REF_IDX_FRAMEWORK
 Void TEncTop::xInitILRP()
@@ -1211,5 +1223,5 @@
     m_cIlpPic[0]->copyUpsampledPictureYuv(pcPic->getFullPelBaseRec(), m_cIlpPic[0]->getPicYuvRec());
     m_cIlpPic[0]->getSlice(0)->setPOC(pcPic->getPOC());
-    m_cIlpPic[0]->setLayerId(0); //set reference layerId
+    m_cIlpPic[0]->setLayerId(pcPic->getSlice(0)->getBaseColPic()->getLayerId()); //set reference layerId
     m_cIlpPic[0]->getPicYuvRec()->setBorderExtension(false);
     m_cIlpPic[0]->getPicYuvRec()->extendPicBorder();
@@ -1217,3 +1229,4 @@
 }
 #endif
+#endif
 //! \}
Index: branches/SHM-2.0-dev/source/Lib/TLibEncoder/TEncTop.h
===================================================================
--- branches/SHM-2.0-dev/source/Lib/TLibEncoder/TEncTop.h	(revision 133)
+++ branches/SHM-2.0-dev/source/Lib/TLibEncoder/TEncTop.h	(revision 134)
@@ -212,9 +212,9 @@
 #if REF_IDX_FRAMEWORK
   TComPic** getIlpList() { return m_cIlpPic; }
-  Void setILRPic(TComPic *pcPic);
+  Void      setILRPic(TComPic *pcPic);
 #endif
 #if REF_IDX_MFM
-  Void setMFMEnabledFlag       (Bool flag)   {m_bMFMEnabledFlag = flag;}
-  Bool getMFMEnabledFlag()                   {return m_bMFMEnabledFlag;}    
+  Void      setMFMEnabledFlag       (Bool flag)   {m_bMFMEnabledFlag = flag;}
+  Bool      getMFMEnabledFlag()                   {return m_bMFMEnabledFlag;}    
 #endif
 #if AVC_SYNTAX
@@ -222,7 +222,9 @@
   fstream*  getBLSyntaxFile() { return m_pBLSyntaxFile; }
 #endif
-  Void encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut,
-              std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP  );
-  Void encodePrep( TComPicYuv* pcPicYuvOrg );
+  Void      encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP  );
+  Void      encodePrep( TComPicYuv* pcPicYuvOrg );
+#if VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE
+  TEncTop*  getRefLayerEnc(UInt layerId);
+#endif
 #else
   Void encode( Bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut,
