Index: /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 1072)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 1073)
@@ -3583,4 +3583,20 @@
 #endif
 #if VPS_DPB_SIZE_TABLE
+Int TComVPS::getLayerIdcInOls( Int olsIdx, Int layerId )
+{
+  Int layerIdc = -1;
+
+  std::vector<Int>::iterator it = std::find( m_layerSetLayerIdList[olsIdx].begin(), m_layerSetLayerIdList[olsIdx].end(), layerId );
+
+  if( it != m_layerSetLayerIdList[olsIdx].end() )
+  {
+    layerIdc = std::distance( m_layerSetLayerIdList[olsIdx].begin(), it );
+  }
+
+  assert( layerIdc >= 0 );
+
+  return layerIdc;
+}
+
 Void TComVPS::determineSubDpbInfoFlags()
 {
Index: /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.h	(revision 1072)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.h	(revision 1073)
@@ -1412,13 +1412,14 @@
 #endif
 #if VPS_DPB_SIZE_TABLE
-  Bool   getSubLayerFlagInfoPresentFlag(Int i)         {return m_subLayerFlagInfoPresentFlag[i]; }
-  Void   setSubLayerFlagInfoPresentFlag(Int i, Bool x) {m_subLayerFlagInfoPresentFlag[i] = x;    }
-
-  Bool   getSubLayerDpbInfoPresentFlag(Int i, Int j)         {return m_subLayerDpbInfoPresentFlag[i][j]; }
-  Void   setSubLayerDpbInfoPresentFlag(Int i, Int j, Bool x) {m_subLayerDpbInfoPresentFlag[i][j] = x;    }
+  Bool   getSubLayerFlagInfoPresentFlag(Int olsIdx)         { return m_subLayerFlagInfoPresentFlag[olsIdx]; }
+  Void   setSubLayerFlagInfoPresentFlag(Int olsIdx, Bool x) { m_subLayerFlagInfoPresentFlag[olsIdx] = x;    }
+
+  Bool   getSubLayerDpbInfoPresentFlag(Int olsIdx, Int subLayerIdx)         { return m_subLayerDpbInfoPresentFlag[olsIdx][subLayerIdx]; }
+  Void   setSubLayerDpbInfoPresentFlag(Int olsIdx, Int subLayerIdx, Bool x) { m_subLayerDpbInfoPresentFlag[olsIdx][subLayerIdx] = x;    }
 
   // For the 0-th output layer set, use the date from the active SPS for base layer.
-  Int    getMaxVpsDecPicBufferingMinus1(Int i, Int k, Int j)         { assert(i != 0); return m_maxVpsDecPicBufferingMinus1[i][k][j]; }
-  Void   setMaxVpsDecPicBufferingMinus1(Int i, Int k, Int j, Int x) { m_maxVpsDecPicBufferingMinus1[i][k][j] = x;    }
+  Int    getMaxVpsDecPicBufferingMinus1(Int olsIdx, Int subDpbIdx, Int subLayerIdx)        { assert(olsIdx != 0); return m_maxVpsDecPicBufferingMinus1[olsIdx][subDpbIdx][subLayerIdx]; }
+  Void   setMaxVpsDecPicBufferingMinus1(Int olsIdx, Int subDpbIdx, Int subLayerIdx, Int x) { m_maxVpsDecPicBufferingMinus1[olsIdx][subDpbIdx][subLayerIdx] = x;    }
+  Int    getLayerIdcInOls( Int olsIdx, Int layerId );
 
 #if RESOLUTION_BASED_DPB
@@ -1427,12 +1428,12 @@
 #endif
 
-  Int    getMaxVpsNumReorderPics(Int i, Int j)        { assert(i != 0); return m_maxVpsNumReorderPics[i][j]; }
-  Void   setMaxVpsNumReorderPics(Int i, Int j, Int x) { m_maxVpsNumReorderPics[i][j] = x;    }
-
-  Int    getMaxVpsLatencyIncreasePlus1(Int i, Int j)        { assert(i != 0); return m_maxVpsLatencyIncreasePlus1[i][j]; }
-  Void   setMaxVpsLatencyIncreasePlus1(Int i, Int j, Int x) { m_maxVpsLatencyIncreasePlus1[i][j] = x;    }
-
-  Int    getNumSubDpbs(Int i)                          { return m_numSubDpbs[i]; }
-  Void   setNumSubDpbs(Int i, Int x)                   { m_numSubDpbs[i] = x;    }
+  Int    getMaxVpsNumReorderPics(Int olsIdx, Int subLayerIdx)        { assert(olsIdx != 0); return m_maxVpsNumReorderPics[olsIdx][subLayerIdx]; }
+  Void   setMaxVpsNumReorderPics(Int olsIdx, Int subLayerIdx, Int x) { m_maxVpsNumReorderPics[olsIdx][subLayerIdx] = x;    }
+
+  Int    getMaxVpsLatencyIncreasePlus1(Int olsIdx, Int subLayerIdx)        { assert(olsIdx != 0); return m_maxVpsLatencyIncreasePlus1[olsIdx][subLayerIdx]; }
+  Void   setMaxVpsLatencyIncreasePlus1(Int olsIdx, Int subLayerIdx, Int x) { m_maxVpsLatencyIncreasePlus1[olsIdx][subLayerIdx] = x;    }
+
+  Int    getNumSubDpbs(Int olsIdx)                          { return m_numSubDpbs[olsIdx]; }
+  Void   setNumSubDpbs(Int olsIdx, Int x)                   { m_numSubDpbs[olsIdx] = x;    }
   Void   determineSubDpbInfoFlags();
 #endif
Index: /branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 1072)
+++ /branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 1073)
@@ -1536,8 +1536,8 @@
           if(chkAssert)
           {
-            UInt layerIdx = pcSlice->getVPS()->getLayerIdxInVps(pcSlice->getLayerId());
-            assert(rps->getNumberOfNegativePictures() <= pcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii, layerIdx, pcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)));
-            assert(rps->getNumberOfPositivePictures() <= pcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii, layerIdx, pcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)) - rps->getNumberOfNegativePictures());
-            assert((rps->getNumberOfPositivePictures() + rps->getNumberOfNegativePictures() + rps->getNumberOfLongtermPictures()) <= pcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii, layerIdx, pcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)));
+            UInt layerIdc = pcSlice->getVPS()->getLayerIdcInOls( ii, pcSlice->getLayerId() );
+            assert(rps->getNumberOfNegativePictures() <= pcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii, layerIdc, pcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)));
+            assert(rps->getNumberOfPositivePictures() <= pcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii, layerIdc, pcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)) - rps->getNumberOfNegativePictures());
+            assert((rps->getNumberOfPositivePictures() + rps->getNumberOfNegativePictures() + rps->getNumberOfLongtermPictures()) <= pcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii, layerIdc, pcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)));
           }
         }
Index: /branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 1072)
+++ /branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 1073)
@@ -256,5 +256,5 @@
   {
 #if USE_DPB_SIZE_TABLE
-    if( getCommonDecoderParams()->getTargetOutputLayerSetIdx() == 0 )
+    if( m_commonDecoderParams->getTargetOutputLayerSetIdx() == 0 )
     {
       assert( this->getLayerId() == 0 );
@@ -273,5 +273,5 @@
 
 #if USE_DPB_SIZE_TABLE
-  if( getCommonDecoderParams()->getTargetOutputLayerSetIdx() == 0 )
+  if( m_commonDecoderParams->getTargetOutputLayerSetIdx() == 0 )
   {
     assert( this->getLayerId() == 0 );
@@ -285,5 +285,5 @@
     m_iMaxRefPicNum = pcSlice->getVPS()->getMaxVpsLayerDecPicBuffMinus1( getCommonDecoderParams()->getTargetOutputLayerSetIdx(), layerIdx, pcSlice->getTLayer() ) + 1; // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
 #else
-    m_iMaxRefPicNum = pcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1( getCommonDecoderParams()->getTargetOutputLayerSetIdx(), pcSlice->getLayerId(), pcSlice->getTLayer() ) + 1; // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
+    m_iMaxRefPicNum = pcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1( m_commonDecoderParams->getTargetOutputLayerSetIdx(), pcSlice->getVPS()->getLayerIdcInOls( pcSlice->getVPS()->getOutputLayerSetIdx( m_commonDecoderParams->getTargetOutputLayerSetIdx()), pcSlice->getLayerId() ), pcSlice->getTLayer() ) + 1; // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
 #endif
   }
@@ -300,105 +300,8 @@
     rpcPic = new TComPic();
 
-#if SVC_EXTENSION //Temporal solution, should be modified
+#if SVC_EXTENSION
     if(m_layerId > 0)
     {
-      for(UInt i = 0; i < pcSlice->getVPS()->getNumDirectRefLayers( m_layerId ); i++ )
-      {
-#if MOVE_SCALED_OFFSET_TO_PPS
-#if O0098_SCALED_REF_LAYER_ID
-        const Window scalEL = pcSlice->getPPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, i));
-#else
-        const Window scalEL = pcSlice->getPPS()->getScaledRefLayerWindow(i);
-#endif
-#else
-#if O0098_SCALED_REF_LAYER_ID
-        const Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, i));
-#else
-        const Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(i);
-#endif
-#endif
-#if REF_REGION_OFFSET
-        const Window refEL = pcSlice->getPPS()->getRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, i));
-#if RESAMPLING_FIX
-        Bool equalOffsets = scalEL.hasEqualOffset(refEL);
-#if R0209_GENERIC_PHASE
-        Bool zeroPhase = pcSlice->getPPS()->hasZeroResamplingPhase(pcSlice->getVPS()->getRefLayerId(m_layerId, i));
-#endif
-#else
-        Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0
-                             && refEL.getWindowLeftOffset() == 0 && refEL.getWindowRightOffset() == 0 && refEL.getWindowTopOffset() == 0 && refEL.getWindowBottomOffset() == 0 );
-#endif
-#else
-        Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
-#endif
-
-#if VPS_EXTN_DIRECT_REF_LAYERS
-        TDecTop *pcTDecTopBase = (TDecTop *)getRefLayerDec( i );
-#else
-        TDecTop *pcTDecTopBase = (TDecTop *)getLayerDec( m_layerId-1 );
-#endif
-        //TComPic*                      pcPic = *(pcTDecTopBase->getListPic()->begin()); 
-        TComPicYuv* pcPicYuvRecBase = (*(pcTDecTopBase->getListPic()->begin()))->getPicYuvRec(); 
-#if REPN_FORMAT_IN_VPS
-#if O0194_DIFFERENT_BITDEPTH_EL_BL
-        UInt refLayerId = pcSlice->getVPS()->getRefLayerId(m_layerId, i);
-        Bool sameBitDepths = ( g_bitDepthLayer[CHANNEL_TYPE_LUMA][m_layerId] == g_bitDepthLayer[CHANNEL_TYPE_LUMA][refLayerId] ) && ( g_bitDepthLayer[CHANNEL_TYPE_CHROMA][m_layerId] == g_bitDepthLayer[CHANNEL_TYPE_CHROMA][refLayerId] );
-
-#if REF_IDX_MFM
-        if( pcPicYuvRecBase->getWidth(COMPONENT_Y) == pcSlice->getPicWidthInLumaSamples() && pcPicYuvRecBase->getHeight(COMPONENT_Y) == pcSlice->getPicHeightInLumaSamples() && equalOffsets && zeroPhase )
-        {
-          rpcPic->setEqualPictureSizeAndOffsetFlag( i, true );
-        }
-
-        if( !rpcPic->equalPictureSizeAndOffsetFlag(i) || !sameBitDepths 
-#else
-        if( pcPicYuvRecBase->getWidth() != pcSlice->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getPicHeightInLumaSamples() || !sameBitDepths
-#if REF_REGION_OFFSET && RESAMPLING_FIX
-          || !equalOffsets
-#if R0209_GENERIC_PHASE
-          || !zeroPhase
-#endif
-#else
-          || !zeroOffsets
-#endif
-#endif
-#if Q0048_CGS_3D_ASYMLUT
-          || pcSlice->getPPS()->getCGSFlag() > 0
-#endif
-#if LAYER_CTB
-          || pcTDecTopBase->getActiveSPS()->getMaxCUWidth() != m_ppcTDecTop[m_layerId]->getActiveSPS()->getMaxCUWidth() || pcTDecTopBase->getActiveSPS()->getMaxCUHeight() != m_ppcTDecTop[m_layerId]->getActiveSPS()->getMaxCUHeight() || pcTDecTopBase->getActiveSPS()->getMaxCUDepth() != m_ppcTDecTop[m_layerId]->getActiveSPS()->getMaxCUDepth()
-#endif
-          )
-#else
-        if(pcPicYuvRecBase->getWidth() != pcSlice->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getPicHeightInLumaSamples()
-#if REF_REGION_OFFSET && RESAMPLING_FIX
-          || !equalOffsets
-#if R0209_GENERIC_PHASE
-          || !zeroPhase
-#endif
-#else
-          || !zeroOffsets
-#endif
-        )
-#endif
-#else
-        if(pcPicYuvRecBase->getWidth() != pcSlice->getSPS()->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getSPS()->getPicHeightInLumaSamples()
-#if REF_REGION_OFFSET && RESAMPLING_FIX
-          || !equalOffsets
-#if R0209_GENERIC_PHASE
-          || !zeroPhase
-#endif
-#else
-          || !zeroOffsets
-#endif
-        )
-#endif
-        {
-          rpcPic->setSpatialEnhLayerFlag( i, true );
-
-          //only for scalable extension
-          assert( pcSlice->getVPS()->getScalabilityMask( SCALABILITY_ID ) == true );
-        }
-      }
+      xSetSpatialEnhLayerFlag( pcSlice, rpcPic );
     }
 
@@ -455,4 +358,9 @@
 
 #if SVC_EXTENSION
+  if( m_layerId > 0 )
+  {
+    xSetSpatialEnhLayerFlag( pcSlice, rpcPic );
+  }
+
 #if REPN_FORMAT_IN_VPS
   rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
@@ -757,7 +665,7 @@
       assert( i < MAX_TLAYER );
 #if LAYER_DECPICBUFF_PARAM && RESOLUTION_BASED_DPB
-      sps->setMaxDecPicBuffering( activeVPS->getMaxVpsLayerDecPicBuffMinus1( getCommonDecoderParams()->getTargetOutputLayerSetIdx(), sps->getLayerId(), i) + 1, i);
-#else
-      sps->setMaxDecPicBuffering( activeVPS->getMaxVpsDecPicBufferingMinus1( getCommonDecoderParams()->getTargetOutputLayerSetIdx(), sps->getLayerId(), i) + 1, i);
+      sps->setMaxDecPicBuffering( activeVPS->getMaxVpsLayerDecPicBuffMinus1( m_commonDecoderParams->getTargetOutputLayerSetIdx(), sps->getLayerId(), i) + 1, i);
+#else
+      sps->setMaxDecPicBuffering( activeVPS->getMaxVpsDecPicBufferingMinus1( m_commonDecoderParams->getTargetOutputLayerSetIdx(), activeVPS->getLayerIdcInOls( activeVPS->getOutputLayerSetIdx( m_commonDecoderParams->getTargetOutputLayerSetIdx() ), sps->getLayerId() ), i) + 1, i);
 #endif
     }
@@ -3299,4 +3207,42 @@
 #endif
 
+Void TDecTop::xSetSpatialEnhLayerFlag(TComSlice* slice, TComPic* pic)
+{
+  for(UInt i = 0; i < slice->getVPS()->getNumDirectRefLayers( m_layerId ); i++ )
+  {
+    const Window scalEL = slice->getPPS()->getScaledRefLayerWindowForLayer(slice->getVPS()->getRefLayerId(m_layerId, i));
+    const Window refEL = slice->getPPS()->getRefLayerWindowForLayer(slice->getVPS()->getRefLayerId(m_layerId, i));
+    Bool equalOffsets = scalEL.hasEqualOffset(refEL);
+    Bool zeroPhase = slice->getPPS()->hasZeroResamplingPhase(slice->getVPS()->getRefLayerId(m_layerId, i));
+
+    TDecTop *pcTDecTopBase = (TDecTop *)getRefLayerDec( i );
+    //TComPic*                      pcPic = *(pcTDecTopBase->getListPic()->begin()); 
+    TComPicYuv* pcPicYuvRecBase = (*(pcTDecTopBase->getListPic()->begin()))->getPicYuvRec(); 
+
+    UInt refLayerId = slice->getVPS()->getRefLayerId(m_layerId, i);
+    Bool sameBitDepths = ( g_bitDepthLayer[CHANNEL_TYPE_LUMA][m_layerId] == g_bitDepthLayer[CHANNEL_TYPE_LUMA][refLayerId] ) && ( g_bitDepthLayer[CHANNEL_TYPE_CHROMA][m_layerId] == g_bitDepthLayer[CHANNEL_TYPE_CHROMA][refLayerId] );
+
+    if( pcPicYuvRecBase->getWidth(COMPONENT_Y) == slice->getPicWidthInLumaSamples() && pcPicYuvRecBase->getHeight(COMPONENT_Y) == slice->getPicHeightInLumaSamples() && equalOffsets && zeroPhase )
+    {
+      pic->setEqualPictureSizeAndOffsetFlag( i, true );
+    }
+
+    if( !pic->equalPictureSizeAndOffsetFlag(i) || !sameBitDepths 
+#if Q0048_CGS_3D_ASYMLUT
+      || slice->getPPS()->getCGSFlag() > 0
+#endif
+#if LAYER_CTB
+      || pcTDecTopBase->getActiveSPS()->getMaxCUWidth() != m_ppcTDecTop[m_layerId]->getActiveSPS()->getMaxCUWidth() || pcTDecTopBase->getActiveSPS()->getMaxCUHeight() != m_ppcTDecTop[m_layerId]->getActiveSPS()->getMaxCUHeight() || pcTDecTopBase->getActiveSPS()->getMaxCUDepth() != m_ppcTDecTop[m_layerId]->getActiveSPS()->getMaxCUDepth()
+#endif
+      )
+    {
+      pic->setSpatialEnhLayerFlag( i, true );
+
+      //only for scalable extension
+      assert( slice->getVPS()->getScalabilityMask( SCALABILITY_ID ) == true );
+    }
+  }
+}
+
 #endif //SVC_EXTENSION
 
Index: /branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.h	(revision 1072)
+++ /branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.h	(revision 1073)
@@ -336,4 +336,5 @@
   Bool      xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC);
 #endif
+  Void      xSetSpatialEnhLayerFlag(TComSlice* slice, TComPic* pic);
 #else
   Bool      xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay);
Index: /branches/SHM-dev/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 1072)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 1073)
@@ -2801,5 +2801,5 @@
 #endif
 #endif
-          WRITE_UVLC( vps->getMaxVpsDecPicBufferingMinus1( i, k, j), "max_vps_dec_pic_buffering_minus1[i][k][j]" );
+          WRITE_UVLC( vps->getMaxVpsDecPicBufferingMinus1( i, k, j ), "max_vps_dec_pic_buffering_minus1[i][k][j]" );
         }
         WRITE_UVLC( vps->getMaxVpsNumReorderPics( i, j), "max_vps_num_reorder_pics[i][j]" );              
