Index: /branches/HTM-DEV-0.3-dev0/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev0/source/App/TAppEncoder/TAppEncTop.cpp	(revision 489)
+++ /branches/HTM-DEV-0.3-dev0/source/App/TAppEncoder/TAppEncTop.cpp	(revision 490)
@@ -1004,5 +1004,5 @@
 
   vps.checkVPSExtensionSyntax(); 
-  vps.calcIvRefLayers();
+  vps.setRefLayers();
 }
 
Index: /branches/HTM-DEV-0.3-dev0/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev0/source/Lib/TLibCommon/TComSlice.cpp	(revision 489)
+++ /branches/HTM-DEV-0.3-dev0/source/Lib/TLibCommon/TComSlice.cpp	(revision 490)
@@ -114,4 +114,10 @@
 , m_isDepth                       (false)
 #endif
+, m_discardableFlag               (false)
+, m_interLayerPredEnabledFlag     (false)
+, m_numInterLayerRefPicsMinus1    (0)
+, m_interLayerSamplePredOnlyFlag  (false)
+, m_altCollocatedIndicationFlag   (0)
+, m_collocatedRefLayerIdx         (0)
 #endif
 {
@@ -154,4 +160,10 @@
   initWpAcDcParam();
   m_saoEnabledFlag = false;
+#if H_MV
+  for (Int i = 0; i < MAX_NUM_LAYERS; i++ )
+  {
+   m_interLayerPredLayerIdc[ i ] = 0;
+  }
+#endif
 }
 
@@ -1440,4 +1452,30 @@
   }
 #if H_MV
+  m_vpsNumberLayerSetsMinus1     = -1; 
+  m_vpsNumProfileTierLevelMinus1 = -1; 
+    
+  for ( Int i = 0; i < MAX_VPS_PROFILE_TIER_LEVEL; i++)
+  {
+    m_profileRefMinus1[ i ] = -1; 
+  }
+    
+  m_moreOutputLayerSetsThanDefaultFlag = false;   
+  m_numAddOutputLayerSetsMinus1        = -1;   
+  m_defaultOneTargetOutputLayerFlag    = false; 
+  
+  for ( Int i = 0; i < MAX_VPS_OUTPUTLAYER_SETS; i++)
+  {
+    m_outputLayerSetIdxMinus1[i]  = -1; 
+    m_profileLevelTierIdx[i]      = -1; 
+    for ( Int j = 0; j < MAX_VPS_NUH_LAYER_ID_PLUS1; j++)
+    {
+      m_outputLayerFlag[i][j] = false; 
+    }
+  }
+  
+  m_maxOneActiveRefLayerFlag = false; 
+  m_directDepTypeLenMinus2   = -1;         
+  
+
   m_avcBaseLayerFlag = false;
   m_splittingFlag    = false;
@@ -1450,10 +1488,9 @@
 
   m_vpsNuhLayerIdPresentFlag = false;
-  m_numOutputLayerSets       = 0;
-
+  
   for( Int i = 0; i < MAX_VPS_OP_SETS_PLUS1; i++ )
   {
     m_vpsProfilePresentFlag   [i] = false;
-    m_profileLayerSetRefMinus1[i] = 0;
+    m_profileRefMinus1[i] = 0;
     m_outputLayerSetIdxMinus1       [i] = 0;
     for( Int j = 0; j < MAX_VPS_NUH_LAYER_ID_PLUS1; j++ )
@@ -1470,6 +1507,7 @@
   for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
   {
-    m_layerIdInNuh      [i] = ( i == 0 ) ? 0 : -1; 
-    m_numDirectRefLayers[i] = 0; 
+    m_layerIdInNuh       [i] = ( i == 0 ) ? 0 : -1; 
+    m_numDirectRefLayers [i] = 0; 
+    m_maxTidIlRefPicPlus1[i] = -1; 
 #if H_3D
     m_viewIndex         [i] = -1; 
@@ -1479,4 +1517,5 @@
     {
       m_directDependencyFlag[i][j] = false;
+      m_directDependencyType[i][j] = -1; 
       m_refLayerId[i][j]           = -1; 
     }
@@ -1560,12 +1599,50 @@
 }
 
-Void TComVPS::calcIvRefLayers()
-{
-  for( Int i = 1; i <= getMaxLayers(); i++ )
-  { 
-    m_numDirectRefLayers[ i ] = 0; 
-    for( Int j = 0 ; j < i; j++ )
-      if( m_directDependencyFlag[ i ][ j ])
-        m_refLayerId[ i ][ m_numDirectRefLayers[ i ]++ ] = m_layerIdInNuh[ j ];    
+Void TComVPS::setRefLayers()
+{
+  for( Int i = 0; i < MAX_NUM_LAYERS; i++ ) 
+  {
+    m_numSamplePredRefLayers[ i ] = 0;
+    m_numMotionPredRefLayers[ i ] = 0;
+    m_numDirectRefLayers    [ i ] = 0;
+    for( Int j = 0; j < MAX_NUM_LAYERS; j++ ) {
+      m_samplePredEnabledFlag[ i ][ j ] = 0;
+      m_motionPredEnabledFlag[ i ][ j ] = 0;
+      m_refLayerId[ i ][ j ] = 0;
+      m_samplePredRefLayerId[ i ][ j ] = 0;
+      m_motionPredRefLayerId[ i ][ j ] = 0;
+    }
+  }
+
+  for( Int i = 1; i  <= getMaxLayers()- 1; i++ )
+  {
+    for( Int j = 0; j < i; j++ )
+    {
+      if( getDirectDependencyFlag(i,j) )
+      {
+        m_refLayerId[ i ][m_numDirectRefLayers[ i ]++ ] = getLayerIdInNuh( j );
+
+        m_samplePredEnabledFlag [ i ][ j ]  = ( (   getDirectDependencyType( i , j ) + 1 ) & 1 ) == 1;
+        m_numSamplePredRefLayers[ i ]      += m_samplePredEnabledFlag [ i ][ j ] ? 1 : 0; 
+        m_motionPredEnabledFlag [ i ][ j ]  = ( ( ( getDirectDependencyType( i , j ) + 1 ) & 2 ) >> 1 ) == 1;
+        m_numMotionPredRefLayers[ i ]      += m_motionPredEnabledFlag  [ i][ j ] ? 1 : 0; 
+      }
+    }
+  }
+
+  for( Int i = 1, mIdx = 0, sIdx = 0; i <= getMaxLayers()- 1; i++ )
+  {    
+    for( Int j = 0; j < i; j++ )
+    {
+      if( m_motionPredEnabledFlag[ i ][ j ] )
+      {
+        m_motionPredRefLayerId[ i ][ mIdx++ ] = getLayerIdInNuh( j );
+      }
+      
+      if( m_samplePredEnabledFlag[ i ][ j ] )
+      {
+        m_samplePredRefLayerId[ i ][ sIdx++ ] = getLayerIdInNuh( j );
+      }
+    }
   }
 }
@@ -1631,4 +1708,13 @@
 
 #endif // H_3D
+
+Int TComVPS::xCeilLog2( Int val )
+{
+  assert( val > 0 ); 
+  Int ceilLog2 = 0;
+  while( val > ( 1 << ceilLog2 ) ) ceilLog2++;
+  return ceilLog2;
+}
+
 #endif // H_MV
 
@@ -1681,4 +1767,6 @@
 #if H_MV
 , m_interViewMvVertConstraintFlag (false)
+, m_numIlpRestrictedRefLayers ( 0 )
+
 #endif
 #if H_3D
@@ -1699,4 +1787,12 @@
   ::memset(m_ltRefPicPocLsbSps, 0, sizeof(m_ltRefPicPocLsbSps));
   ::memset(m_usedByCurrPicLtSPSFlag, 0, sizeof(m_usedByCurrPicLtSPSFlag));
+#if H_MV
+  for (Int i = 0; i < MAX_NUM_LAYERS; i++ )
+  {
+    m_minSpatialSegmentOffsetPlus1[ i ] = 0;
+    m_ctuBasedOffsetEnabledFlag   [ i ] = false;
+    m_minHorizontalCtuOffsetPlus1 [ i ] = 0;
+  }
+#endif
 }
 
@@ -2258,4 +2354,13 @@
   }
 }
+
+Int TComSlice::xCeilLog2( Int val )
+{
+  assert( val > 0 ); 
+  Int ceilLog2 = 0;
+  while( val > ( 1 << ceilLog2 ) ) ceilLog2++;
+  return ceilLog2;
+}
+
 #endif
 /** get scaling matrix from RefMatrixID
Index: /branches/HTM-DEV-0.3-dev0/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- /branches/HTM-DEV-0.3-dev0/source/Lib/TLibCommon/TComSlice.h	(revision 489)
+++ /branches/HTM-DEV-0.3-dev0/source/Lib/TLibCommon/TComSlice.h	(revision 490)
@@ -515,18 +515,8 @@
 
 
-Int  m_maxTidIlRefPicPlus1            [ MAX_NUM_LAYERS ];
-Int  m_vpsNumberLayerSetsMinus1;       
-Int  m_vpsNumProfileTierLevelMinus1;   
-Int  m_profileRefMinus1               [ MAX_VPS_PROFILE_TIER_LEVEL ];
-Bool m_vpsMoreOutputLayerSetsThanDefaultFlag;
-Int  m_numAddOutputLayerSetsMinus1;    
-Bool m_defaultOneTargetOutputLayerFlag;
-Int  m_outputLayerSetIdxMinus1        [ MAX_VPS_OUTPUTLAYER_SETS ];  
-Int  m_profileLevelTierIdx            [ MAX_VPS_OUTPUTLAYER_SETS ];
-Bool m_maxOneActiveRefLayerFlag;       
-Int  m_directDepTypeLenMinus2;         
-Int  m_directDependencyType           [ MAX_NUM_LAYERS ] [ MAX_NUM_LAYERS ];
-
-#if H_MV
+
+
+#if H_MV
+  /// VPS EXTENSION SYNTAX ELEMENTS
   Bool        m_avcBaseLayerFlag;
   Bool        m_splittingFlag;
@@ -534,28 +524,41 @@
   Int         m_dimensionIdLen           [MAX_NUM_SCALABILITY_TYPES];
   Bool        m_vpsNuhLayerIdPresentFlag;
-  Int         m_layerIdInNuh             [MAX_NUM_LAYER_IDS];
+  Int         m_layerIdInNuh             [MAX_NUM_LAYER_IDS];  
+  Int         m_dimensionId              [MAX_NUM_LAYER_IDS][MAX_NUM_SCALABILITY_TYPES];  
+  Bool        m_directDependencyFlag     [MAX_NUM_LAYER_IDS][MAX_NUM_LAYER_IDS];
+  Int         m_maxTidIlRefPicPlus1      [MAX_NUM_LAYERS];
+  Int         m_vpsNumberLayerSetsMinus1; 
+  Int         m_vpsNumProfileTierLevelMinus1;   
+  Bool        m_vpsProfilePresentFlag    [MAX_VPS_OP_SETS_PLUS1];
+  Int         m_profileRefMinus1         [MAX_VPS_PROFILE_TIER_LEVEL];
+  Bool        m_moreOutputLayerSetsThanDefaultFlag;
+  Int         m_numAddOutputLayerSetsMinus1;    
+  Bool        m_defaultOneTargetOutputLayerFlag;
+  Int         m_outputLayerSetIdxMinus1  [MAX_VPS_OUTPUTLAYER_SETS];  
+  Bool        m_outputLayerFlag          [MAX_VPS_OUTPUTLAYER_SETS][MAX_VPS_NUH_LAYER_ID_PLUS1];
+  Int         m_profileLevelTierIdx      [MAX_VPS_OUTPUTLAYER_SETS ];
+  Bool        m_maxOneActiveRefLayerFlag;       
+  Int         m_directDepTypeLenMinus2;         
+  Int         m_directDependencyType     [MAX_NUM_LAYERS] [MAX_NUM_LAYERS];
+
+  // VPS EXTENSION SEMANTICS VARIABLES
   Int         m_layerIdInVps             [MAX_NUM_LAYERS   ];
-  Int         m_dimensionId              [MAX_NUM_LAYER_IDS][MAX_NUM_SCALABILITY_TYPES];  
+
+  Int         m_numDirectRefLayers       [MAX_NUM_LAYERS];
+  Int         m_refLayerId               [MAX_NUM_LAYERS][MAX_NUM_LAYERS];  
+
+  Int         m_numSamplePredRefLayers   [MAX_NUM_LAYERS];
+  Bool        m_samplePredEnabledFlag    [MAX_NUM_LAYERS][MAX_NUM_LAYERS];
+  Int         m_samplePredRefLayerId     [MAX_NUM_LAYERS][MAX_NUM_LAYERS];
+
+  Int         m_numMotionPredRefLayers   [MAX_NUM_LAYERS];
+  Bool        m_motionPredEnabledFlag    [MAX_NUM_LAYERS][MAX_NUM_LAYERS];
+  Int         m_motionPredRefLayerId     [MAX_NUM_LAYERS][MAX_NUM_LAYERS];
 #if H_3D
   Int         m_viewIndex                [MAX_NUM_LAYERS   ];
 #endif
 
-  
-  Bool        m_vpsProfilePresentFlag    [MAX_VPS_OP_SETS_PLUS1];
-  Int         m_profileLayerSetRefMinus1 [MAX_VPS_OP_SETS_PLUS1];
-  Int         m_numOutputLayerSets;  
-  Bool        m_outputLayerFlag          [MAX_VPS_OUTPUTLAYER_SETS][MAX_VPS_NUH_LAYER_ID_PLUS1];
-  Bool        m_directDependencyFlag     [MAX_NUM_LAYER_IDS][MAX_NUM_LAYER_IDS];
-
-  Int         m_numDirectRefLayers       [ MAX_NUM_LAYERS ];
-  Int         m_refLayerId               [ MAX_NUM_LAYERS ][MAX_NUM_LAYERS];  
-  
-  Int xCeilLog2( Int val )
-  { 
-    assert( val > 0 ); 
-    Int ceilLog2 = 0;
-    while( val > ( 1 << ceilLog2 ) ) ceilLog2++;
-    return ceilLog2; 
-  }
+  Int         xCeilLog2( Int val );
+
 
 #endif
@@ -634,6 +637,6 @@
   Void    setScalabilityMask( UInt val );
 
-  Void    setScalabilityMask( Int scalType, Bool val )              { m_scalabilityMask[scalType] = val;  }
-  Bool    getScalabilityMask( Int scalType )                        { return m_scalabilityMask[scalType]; }
+  Void    setScalabilityMask( Int scalType, Bool val )                     { m_scalabilityMask[scalType] = val;  }
+  Bool    getScalabilityMask( Int scalType )                               { return m_scalabilityMask[scalType]; }
 
   Int     getNumScalabilityTypes( );
@@ -648,89 +651,83 @@
   Int     getLayerIdInNuh( Int layerIdInVps )                              { assert( m_layerIdInNuh[layerIdInVps] >= 0 ); return m_layerIdInNuh[layerIdInVps]; }
 
+  Bool    nuhLayerIdIncluded( Int layerIdinNuh )                           { return ( m_layerIdInVps[ layerIdinNuh ] > 0 );  }
+
+  Void    setDimensionId( Int layerIdInVps, Int scalIdx, Int val )         { m_dimensionId[layerIdInVps][scalIdx] = val;  }
+  Int     getDimensionId( Int layerIdInVps, Int scalIdx )                  { return m_dimensionId[layerIdInVps][scalIdx]; }
+
+  Void    setDirectDependencyFlag( Int depLayeridInVps, Int refLayeridInVps, Bool val ) { m_directDependencyFlag[depLayeridInVps][refLayeridInVps] = val;  }
+  Bool    getDirectDependencyFlag( Int depLayeridInVps, Int refLayeridInVps )           { return m_directDependencyFlag[depLayeridInVps][refLayeridInVps]; }
+
+  Void    setMaxTidIlRefPicPlus1( Int layerIdInVps, Int val )              { m_maxTidIlRefPicPlus1[ layerIdInVps ] = val;  } 
+  Int     getMaxTidIlRefPicPlus1( Int layerIdInVps )                       { return m_maxTidIlRefPicPlus1[ layerIdInVps ]; } 
+  
+  Void    setVpsNumberLayerSetsMinus1( Int val )                           { m_vpsNumberLayerSetsMinus1 = val;  } 
+  Int     getVpsNumberLayerSetsMinus1( )                                   { return m_vpsNumberLayerSetsMinus1; } 
+  
+  Void    setVpsNumProfileTierLevelMinus1( Int val )                       { m_vpsNumProfileTierLevelMinus1 = val;  } 
+  Int     getVpsNumProfileTierLevelMinus1( )                               { return m_vpsNumProfileTierLevelMinus1; } 
+  
+  Void    setVpsProfilePresentFlag( Int layerSet, Bool val )               { m_vpsProfilePresentFlag[layerSet] = val;  }
+  Bool    getVpsProfilePresentFlag( Int layerSet )                         { return m_vpsProfilePresentFlag[layerSet]; }
+
+  Void    setProfileRefMinus1( Int profileTierLevelIdx, Int val )          { m_profileRefMinus1[ profileTierLevelIdx ] = val;  } 
+  Int     getProfileRefMinus1( Int profileTierLevelIdx )                   { return m_profileRefMinus1[ profileTierLevelIdx ]; } 
+
+  Void    setMoreOutputLayerSetsThanDefaultFlag( Bool flag )               { m_moreOutputLayerSetsThanDefaultFlag = flag; } 
+  Bool    getMoreOutputLayerSetsThanDefaultFlag()                          { return m_moreOutputLayerSetsThanDefaultFlag; } 
+  
+  Void    setNumAddOutputLayerSetsMinus1( Int val )                        { m_numAddOutputLayerSetsMinus1 = val; } 
+  Int     getNumAddOutputLayerSetsMinus1( )                                { return m_numAddOutputLayerSetsMinus1; } 
+  
+  Void    setDefaultOneTargetOutputLayerFlag( Bool flag )                  { m_defaultOneTargetOutputLayerFlag = flag; } 
+  Bool    getDefaultOneTargetOutputLayerFlag( )                            { return m_defaultOneTargetOutputLayerFlag; } 
+  
+  Void    setOutputLayerSetIdxMinus1( Int outLayerSetIdx, Int val )        { m_outputLayerSetIdxMinus1[ outLayerSetIdx ]  = val; } 
+  Int     getOutputLayerSetIdxMinus1( Int outLayerSetIdx )                 { return m_outputLayerSetIdxMinus1[ outLayerSetIdx ]; } 
+  
+  Void    setOutputLayerFlag( Int outLayerSetIdx, Int i, Bool flag )       { m_outputLayerFlag[ outLayerSetIdx ][ i ] = flag; } 
+  Bool    getOutputLayerFlag( Int outLayerSetIdx, Int i )                  { return m_outputLayerFlag[ outLayerSetIdx ][ i ]; } 
+
+  Void    setProfileLevelTierIdx( Int outLayerSetIdx, Int val )            { m_profileLevelTierIdx[ outLayerSetIdx  = val ]; } 
+  Int     getProfileLevelTierIdx( Int outLayerSetIdx )                     { return m_profileLevelTierIdx[ outLayerSetIdx ]; } 
+
+  Void    setMaxOneActiveRefLayerFlag( Bool flag)                          { m_maxOneActiveRefLayerFlag = flag; } 
+  Bool    getMaxOneActiveRefLayerFlag( )                                   { return m_maxOneActiveRefLayerFlag; } 
+  
+  Void    setDirectDepTypeLenMinus2( Int val)                              { m_directDepTypeLenMinus2 = val; } 
+  Int     getDirectDepTypeLenMinus2( )                                     { return m_directDepTypeLenMinus2; } 
+  
+  Void    setDirectDependencyType( Int depLayeridInVps, Int refLayeridInVps, Int val) { m_directDependencyType[ depLayeridInVps ][ refLayeridInVps ] = val; } 
+  Int     getDirectDependencyType( Int depLayeridInVps, Int refLayeridInVps)   { return m_directDependencyType[ depLayeridInVps ][ refLayeridInVps ]; } 
+    
+  // VPS EXTENSION SEMANTICS VARIABLES
   Void    setLayerIdInVps( Int layerIdInNuh, Int val )                     { m_layerIdInVps[layerIdInNuh] = val;  }
   Int     getLayerIdInVps( Int layerIdInNuh )                              { assert( m_layerIdInVps[layerIdInNuh] >= 0 ); return m_layerIdInVps[layerIdInNuh]; }
 
-  Bool    nuhLayerIdIncluded( Int layerIdinNuh )                           { return ( m_layerIdInVps[ layerIdinNuh ] > 0 );  }
-
-  Void    setDimensionId( Int layerIdInVps, Int scalIdx, Int val )         { m_dimensionId[layerIdInVps][scalIdx] = val;  }
-  Int     getDimensionId( Int layerIdInVps, Int scalIdx )                  { return m_dimensionId[layerIdInVps][scalIdx]; }
-
   Int     getScalabilityId ( Int layerIdInVps, ScalabilityType scalType );
-
   Int     getViewId  ( Int layerIdInVps )                                  { return getScalabilityId( layerIdInVps, VIEW_ID  ); }
-#if H_3D  
-  Void    initViewIndex(); 
-  Int     getViewIndex    ( Int layerIdInVps )                             { return m_viewIndex[ layerIdInVps ]; }    
-  Int     getDepthId      ( Int layerIdInVps )                             { return getScalabilityId( layerIdInVps, DEPTH_ID ); }
-  Int     getLayerIdInNuh( Int viewIndex, Bool depthFlag );  
-#endif
-
-
-  Void    setVpsProfilePresentFlag( Int layerSet, Bool val )               { m_vpsProfilePresentFlag[layerSet] = val;  }
-  Bool    getVpsProfilePresentFlag( Int layerSet )                         { return m_vpsProfilePresentFlag[layerSet]; }
-
-  Void    setProfileLayerSetRefMinus1( Int layerSet, Int val )             { m_profileLayerSetRefMinus1[layerSet] = val;  }
-  Bool    getProfileLayerSetRefMinus1( Int layerSet )                      { return m_profileLayerSetRefMinus1[layerSet]; }
-
-  Void    setNumOutputLayerSets( Int val )                                 { m_numOutputLayerSets = val;  }
-  Int     getNumOutputLayerSets()                                          { return m_numOutputLayerSets; }
-
-  Void    setDirectDependencyFlag( Int depLayeridInVps, Int refLayeridInVps, Bool val ) { m_directDependencyFlag[depLayeridInVps][refLayeridInVps] = val;  }
-  Bool    getDirectDependencyFlag( Int depLayeridInVps, Int refLayeridInVps )           { return m_directDependencyFlag[depLayeridInVps][refLayeridInVps]; }
-
-  Void    calcIvRefLayers(); 
-
-  Int     getNumDirectRefLayers( Int layerIdInVps )          { return m_numDirectRefLayers[ layerIdInVps ];  };                               
-  Int     getRefLayerId        ( Int layerIdInVps, Int idx );; 
-  
+
+  Void    setRefLayers(); 
+
+  Int     getNumDirectRefLayers    ( Int layerIdInVps )          { return m_numDirectRefLayers[ layerIdInVps ];  };                               
+  Int     getRefLayerId            ( Int layerIdInVps, Int idx );; 
+
+  Int     getNumSamplePredRefLayers( Int layerIdInVps )          { return m_numSamplePredRefLayers[layerIdInVps]; } 
+  Bool    getSamplePredEnabledFlag ( Int layerIdInVps, Int idx ) { return m_samplePredEnabledFlag [layerIdInVps][idx]; } 
+  Int     getSamplePredRefLayerId  ( Int layerIdInVps, Int idx ) { return m_samplePredRefLayerId  [layerIdInVps][idx]; } 
+
+  Int     getNumMotionPredRefLayers( Int layerIdInVps )          { return m_numMotionPredRefLayers[layerIdInVps]; } 
+  Bool    getMotionPredEnabledFlag ( Int layerIdInVps, Int idx ) { return m_motionPredEnabledFlag [layerIdInVps][idx]; } 
+  Int     getMotionPredRefLayerId  ( Int layerIdInVps, Int idx ) { return m_motionPredRefLayerId  [layerIdInVps][idx]; } 
+
   Bool    checkVPSExtensionSyntax(); 
   Int     scalTypeToScalIdx   ( ScalabilityType scalType );
-  
-  
-  Int  getMaxTidIlRefPicPlus1                  ( Int layerIdInVps )                          { return m_maxTidIlRefPicPlus1          [ layerIdInVps        ]; } 
-  Void setMaxTidIlRefPicPlus1                  ( Int layerIdInVps, Int val )                 { m_maxTidIlRefPicPlus1          [ layerIdInVps        ] = val;  } 
-  
-  Int  getVpsNumberLayerSetsMinus1             ()                                            { return m_vpsNumberLayerSetsMinus1                            ; } 
-  Void setVpsNumberLayerSetsMinus1             ( Int val )                                   { m_vpsNumberLayerSetsMinus1                             = val;  } 
-  
-  Int  getVpsNumProfileTierLevelMinus1         ()                                            { return m_vpsNumProfileTierLevelMinus1                        ; } 
-  Void setVpsNumProfileTierLevelMinus1         ( Int val )                                   { m_vpsNumProfileTierLevelMinus1                         = val;  } 
-
-  Void setProfileRefMinus1                     ( Int profileTierLevelIdx, Int val )          { m_profileRefMinus1             [ profileTierLevelIdx ] = val;  } 
-  Int  getProfileRefMinus1                     ( Int profileTierLevelIdx )                   { return m_profileRefMinus1             [ profileTierLevelIdx ]; } 
-  
-  Bool getVpsMoreOutputLayerSetsThanDefaultFlag()                                            { return m_vpsMoreOutputLayerSetsThanDefaultFlag               ; } 
-  Void setVpsMoreOutputLayerSetsThanDefaultFlag( Bool flag )                                 { m_vpsMoreOutputLayerSetsThanDefaultFlag                = flag; } 
-
-  Int  getNumAddOutputLayerSetsMinus1          ()                                            { return m_numAddOutputLayerSetsMinus1                         ; } 
-  Void setNumAddOutputLayerSetsMinus1          ( Int val )                                   { m_numAddOutputLayerSetsMinus1                          = val;  } 
-  
-  Bool getDefaultOneTargetOutputLayerFlag      ()                                            { return m_defaultOneTargetOutputLayerFlag                     ; } 
-  Void setDefaultOneTargetOutputLayerFlag      ( Bool flag )                                 { m_defaultOneTargetOutputLayerFlag                      = flag; } 
-  
-  Int  getOutputLayerSetIdxMinus1              ( Int outLayerSetIdx )                        { return m_outputLayerSetIdxMinus1      [ outLayerSetIdx ]     ; } 
-  Void setOutputLayerSetIdxMinus1              ( Int outLayerSetIdx, Int val )               { m_outputLayerSetIdxMinus1      [ outLayerSetIdx ]      = val;  } 
-  
-  Int  getProfileLevelTierIdx                  ( Int outLayerSetIdx )                        { return m_profileLevelTierIdx          [ outLayerSetIdx ]     ; } 
-  Void setProfileLevelTierIdx                  ( Int outLayerSetIdx, Int val )               { m_profileLevelTierIdx          [ outLayerSetIdx ]      = val;  } 
-  
-  Bool getMaxOneActiveRefLayerFlag()                                                         { return m_maxOneActiveRefLayerFlag                            ; } 
-  Void setMaxOneActiveRefLayerFlag             ( Bool flag)                                  { m_maxOneActiveRefLayerFlag                             = flag; } 
-  
-  Int  getDirectDepTypeLenMinus2()                                                           { return m_directDepTypeLenMinus2                              ; } 
-  Void setDirectDepTypeLenMinus2               ( Int val)                                    { m_directDepTypeLenMinus2                               = val;  } 
-  
-  Int  getDirectDependencyType                 ( Int depLayeridInVps, Int refLayeridInVps)   { return m_directDependencyType         [ depLayeridInVps ][ refLayeridInVps ]; } 
-  Void setDirectDependencyType                 ( Int depLayeridInVps, Int refLayeridInVps, Int val) { m_directDependencyType         [ depLayeridInVps ][ refLayeridInVps ] = val ; } 
-
-  Int  getProfileLevelTierIdxLen() 
-  { 
-    return xCeilLog2( getVpsNumProfileTierLevelMinus1() + 1 );     
-  };
-
-  Int  getNumLayersInIdList              ( Int lsIdx )
+
+
+  Int     getProfileLevelTierIdxLen() { return xCeilLog2( getVpsNumProfileTierLevelMinus1() + 1 ); };       
+  Int     getNumLayersInIdList              ( Int lsIdx )
   {
-    assert( lsIdx > 0 ); 
-    assert( lsIdx <= getMaxOpSets() ); 
+    assert( lsIdx >= 0 ); 
+    assert( lsIdx < getMaxOpSets() ); 
     Int numLayersInIdList = 0; 
     for (Int layerId = 0; layerId < getVpsMaxLayerId(); layerId++ )
@@ -740,5 +737,10 @@
     return numLayersInIdList; 
   }; 
-  
+#if H_3D  
+  Void    initViewIndex(); 
+  Int     getViewIndex    ( Int layerIdInVps )                             { return m_viewIndex[ layerIdInVps ]; }    
+  Int     getDepthId      ( Int layerIdInVps )                             { return getScalabilityId( layerIdInVps, DEPTH_ID ); }
+  Int     getLayerIdInNuh( Int viewIndex, Bool depthFlag );  
+#endif  
 #endif
 };
@@ -824,5 +826,7 @@
   Int  m_numTicksPocDiffOneMinus1;
 #endif
-
+#if H_MV
+  Bool m_tileBoundariesAlignedFlag;
+#endif
 public:
   TComVUI()
@@ -860,4 +864,7 @@
     ,m_numTicksPocDiffOneMinus1(0)
 #endif
+#if H_MV
+    ,m_tileBoundariesAlignedFlag(false)
+#endif
   {}
 
@@ -961,4 +968,8 @@
   Int  getNumTicksPocDiffOneMinus1() {return m_numTicksPocDiffOneMinus1;}
   Void setNumTicksPocDiffOneMinus1(Int x) { m_numTicksPocDiffOneMinus1 = x;}
+#endif
+#if H_MV
+  Bool getTileBoundariesAlignedFlag(  ) { return m_tileBoundariesAlignedFlag; } 
+  Void setTileBoundariesAlignedFlag( Bool flag ) { m_tileBoundariesAlignedFlag = flag; } 
 #endif
 };
@@ -1046,4 +1057,8 @@
 #if H_MV
   Bool        m_interViewMvVertConstraintFlag;
+  Int         m_numIlpRestrictedRefLayers        ;
+  Int         m_minSpatialSegmentOffsetPlus1[MAX_NUM_LAYERS];
+  Bool        m_ctuBasedOffsetEnabledFlag   [MAX_NUM_LAYERS];
+  Int         m_minHorizontalCtuOffsetPlus1 [MAX_NUM_LAYERS];
 #endif
 #if H_3D
@@ -1052,4 +1067,7 @@
   Int         m_aaiCodedScale [2][MAX_NUM_LAYERS];
   Int         m_aaiCodedOffset[2][MAX_NUM_LAYERS];
+#endif
+#if H_MV
+  Int         m_layerId; 
 #endif
 public:
@@ -1186,4 +1204,17 @@
   Void setInterViewMvVertConstraintFlag(Bool val) { m_interViewMvVertConstraintFlag = val; }
   Bool getInterViewMvVertConstraintFlag()         { return m_interViewMvVertConstraintFlag;}
+
+  ////  sps_extension_vui_parameters( )
+  Void setNumIlpRestrictedRefLayers   ( Int val )        { m_numIlpRestrictedRefLayers         = val;}
+  Int  getNumIlpRestrictedRefLayers   ( )                { return m_numIlpRestrictedRefLayers        ;}
+  
+  Void setMinSpatialSegmentOffsetPlus1( Int i, Int val ) { m_minSpatialSegmentOffsetPlus1[ i ] = val;}
+  Int  getMinSpatialSegmentOffsetPlus1( Int i )          { return m_minSpatialSegmentOffsetPlus1[ i ];}
+  
+  Void setCtuBasedOffsetEnabledFlag   ( Int i, Bool flag ) { m_ctuBasedOffsetEnabledFlag   [ i ] = flag;}
+  Bool getCtuBasedOffsetEnabledFlag   ( Int i )            { return m_ctuBasedOffsetEnabledFlag   [ i ];}
+
+  Void setMinHorizontalCtuOffsetPlus1 ( Int i, Int val )   { m_minHorizontalCtuOffsetPlus1 [ i ] = val;}
+  Int  getMinHorizontalCtuOffsetPlus1 ( Int i )            { return m_minHorizontalCtuOffsetPlus1 [ i ];}
 #endif
 #if H_3D
@@ -1196,4 +1227,9 @@
   Int* getInvCodedOffset     ()  { return m_aaiCodedOffset[1]; }
 #endif
+#if H_MV
+  Int  getLayerId            ()           { return m_layerId; }
+  Void setLayerId            ( Int val )  { m_layerId = val; }
+#endif
+
 };
 
@@ -1558,4 +1594,18 @@
   Int        m_aaiCodedOffset[2][MAX_NUM_LAYERS];
 #endif
+#endif
+#if H_MV
+// Additional slice header syntax elements 
+  Bool       m_discardableFlag;
+  Bool       m_interLayerPredEnabledFlag;
+  Int        m_numInterLayerRefPicsMinus1;
+  Int        m_interLayerPredLayerIdc       [MAX_NUM_LAYERS];
+  Bool       m_interLayerSamplePredOnlyFlag;
+  Bool       m_altCollocatedIndicationFlag;
+  Int        m_collocatedRefLayerIdx;
+// Additional slice header semantics variables
+  Int        m_numActiveMotionPredRefLayers;
+  Int        m_activeMotionPredRefLayerId   [ MAX_NUM_LAYER_IDS ];
+
 #endif
 public:
@@ -1829,4 +1879,88 @@
 #endif
 #endif
+#if H_MV
+// Additional slice header syntax elements
+Void setDiscardableFlag( Bool flag ) { m_discardableFlag = flag; } 
+Bool getDiscardableFlag(  ) { return m_discardableFlag; } 
+
+Void setInterLayerPredEnabledFlag( Bool flag ) { m_interLayerPredEnabledFlag = flag; } 
+Bool getInterLayerPredEnabledFlag(  ) { return m_interLayerPredEnabledFlag; } 
+
+Void setNumInterLayerRefPicsMinus1( Int  val ) { m_numInterLayerRefPicsMinus1 = val; } 
+Int  getNumInterLayerRefPicsMinus1(  ) { return m_numInterLayerRefPicsMinus1; } 
+
+Void setInterLayerPredLayerIdc( Int i, Int  val ) { m_interLayerPredLayerIdc[i] = val; } 
+Int  getInterLayerPredLayerIdc( Int i ) { return m_interLayerPredLayerIdc[i]; } 
+
+Void setInterLayerSamplePredOnlyFlag( Bool flag ) { m_interLayerSamplePredOnlyFlag = flag; } 
+Bool getInterLayerSamplePredOnlyFlag(  ) { return m_interLayerSamplePredOnlyFlag; } 
+
+Void setAltCollocatedIndicationFlag( Bool flag ) { m_altCollocatedIndicationFlag = flag; } 
+Bool getAltCollocatedIndicationFlag(  ) { return m_altCollocatedIndicationFlag; } 
+
+Void setCollocatedRefLayerIdx( Int  val ) { m_collocatedRefLayerIdx = val; } 
+Int  getCollocatedRefLayerIdx(  ) { return m_collocatedRefLayerIdx; } 
+
+// Additional variables derived in slice header semantics 
+
+Int  getNumInterLayerRefPicsMinus1Len( ) { return xCeilLog2(  getVPS()->getNumDirectRefLayers( getLayerIdInVps() )); }
+Int  getInterLayerPredLayerIdcLen    ( ) { return xCeilLog2(  getVPS()->getNumDirectRefLayers( getLayerIdInVps() )); }
+
+Int  getNumActiveRefLayerPics( )
+{
+  Int numActiveRefLayerPics; 
+
+  if( getLayerId() == 0 || getVPS()->getNumDirectRefLayers( getLayerIdInVps() ) ==  0 || !getInterLayerPredEnabledFlag() )
+  {
+    numActiveRefLayerPics = 0; 
+  }
+  else if( getVPS()->getMaxOneActiveRefLayerFlag() || getVPS()->getNumDirectRefLayers( getLayerIdInVps() ) == 1 )
+  {
+    numActiveRefLayerPics = 1; 
+  }
+  else
+  {
+    numActiveRefLayerPics = getNumInterLayerRefPicsMinus1() + 1; 
+  }
+  return numActiveRefLayerPics; 
+}
+
+Int getRefPicLayerId( Int i )
+{  
+  return getVPS()->getRefLayerId( getLayerIdInVps(), getInterLayerPredLayerIdc( i ) );
+}
+
+Void setActiveMotionPredRefLayers( )
+{
+  Int j = 0; 
+  for( Int i = 0; i < getNumActiveRefLayerPics(); i++)
+  {
+    if( getVPS()->getMotionPredEnabledFlag( getLayerIdInVps(), getInterLayerPredLayerIdc( i ))  )
+    {
+      m_activeMotionPredRefLayerId[ j++ ] = getVPS()->getRefLayerId( getLayerIdInVps(), i ); 
+    }
+  }
+  m_numActiveMotionPredRefLayers = j;
+
+  // Consider incorporating bitstream conformance tests on derived variables here. 
+}
+
+Int  getActiveMotionPredRefLayerId( Int i ) { return m_activeMotionPredRefLayerId[i]; } 
+Int  getNumActiveMotionPredRefLayers(  ) { return m_numActiveMotionPredRefLayers; } 
+
+Bool getInterRefEnabledInRPLFlag( ) 
+{
+  Bool interRefEnabledInRPLFlag; 
+  if ( getVPS()->getNumSamplePredRefLayers( getLayerIdInVps() ) > 0 && getNumActiveRefLayerPics() > 0 )
+  {
+    interRefEnabledInRPLFlag = !getInterLayerSamplePredOnlyFlag(); 
+  }
+  else
+  {
+    interRefEnabledInRPLFlag = 1; 
+  }
+  return interRefEnabledInRPLFlag; 
+}
+#endif
 protected:
   TComPic*  xGetRefPic  (TComList<TComPic*>& rcListPic,
@@ -1835,4 +1969,5 @@
 #if H_MV
   TComPic*  xGetInterLayerRefPic( std::vector<TComPic*>& rcListIlPic, Int layerId );
+  Int       xCeilLog2( Int val );
 #endif
 };// END CLASS DEFINITION TComSlice
Index: /branches/HTM-DEV-0.3-dev0/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev0/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 489)
+++ /branches/HTM-DEV-0.3-dev0/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 490)
@@ -433,4 +433,10 @@
   {
     READ_FLAG(   uiCode, "tiles_fixed_structure_flag");               pcVUI->setTilesFixedStructureFlag(uiCode);
+#if H_MV
+    if ( pcSPS->getLayerId() > 0 )
+    {
+      READ_FLAG( uiCode, "tile_boundaries_aligned_flag" ); pcVUI->setTileBoundariesAlignedFlag( uiCode == 1 );
+    }
+#endif
     READ_FLAG(   uiCode, "motion_vectors_over_pic_boundaries_flag");  pcVUI->setMotionVectorsOverPicBoundariesFlag(uiCode);
     READ_FLAG(   uiCode, "restricted_ref_pic_lists_flag");            pcVUI->setRestrictedRefPicListsFlag(uiCode);
@@ -721,4 +727,25 @@
     READ_FLAG( uiCode, "inter_view_mv_vert_constraint_flag" );    pcSPS->setInterViewMvVertConstraintFlag(uiCode == 1 ? true : false);
     READ_FLAG( uiCode, "sps_extension2_flag");
+    ////   sps_extension_vui_parameters( )
+    if( pcSPS->getVuiParameters()->getBitstreamRestrictionFlag() )
+    {  
+      READ_UVLC( uiCode, "num_ilp_restricted_ref_layers" ); pcSPS->setNumIlpRestrictedRefLayers( uiCode ); 
+      for( Int i = 0; i < pcSPS->getNumIlpRestrictedRefLayers( ); i++ ) 
+      {  
+        READ_UVLC( uiCode, "min_spatial_segment_offset_plus1" ); pcSPS->setMinSpatialSegmentOffsetPlus1( i, uiCode ); 
+        if( pcSPS->getMinSpatialSegmentOffsetPlus1( i ) > 0 ) 
+        {  
+          READ_FLAG( uiCode, "ctu_based_offset_enabled_flag[ i ]"); pcSPS->setCtuBasedOffsetEnabledFlag(i, uiCode == 1 ); 
+          if( pcSPS->getCtuBasedOffsetEnabledFlag( i ) )  
+          {
+            READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1[ i ]"); pcSPS->setMinHorizontalCtuOffsetPlus1( i, uiCode ); 
+          }
+        }  
+      }  
+    }  
+
+    ////   sps_extension_vui_parameters( ) END
+    READ_UVLC( uiCode, "sps_shvc_reserved_zero_idc" ); 
+
     if ( uiCode )
     {
@@ -869,6 +896,5 @@
     READ_FLAG( uiCode, "avc_base_layer_flag" );                     pcVPS->setAvcBaseLayerFlag( uiCode == 1 ? true : false );
     READ_FLAG( uiCode, "splitting_flag" );                          pcVPS->setSplittingFlag( uiCode == 1 ? true : false );
-
-    // Parse scalability_mask[i]    
+        
     for( Int sIdx = 0; sIdx < MAX_NUM_SCALABILITY_TYPES; sIdx++ )
     {
@@ -876,66 +902,30 @@
     }
 
-    Int numScalabilityTypes = pcVPS->getNumScalabilityTypes(); 
-
-    // Parse dimension_id_len_minus1[j]    
-    for( Int sIdx = 0; sIdx < numScalabilityTypes; sIdx++ )
+    for( Int sIdx = 0; sIdx < pcVPS->getNumScalabilityTypes( ) - ( pcVPS->getSplittingFlag() ? 1 : 0 ); sIdx++ )
     {
         READ_CODE( 3, uiCode, "dimension_id_len_minus1[j]" );       pcVPS->setDimensionIdLen( sIdx, uiCode + 1 );
     }
-
-    // vps_nuh_layer_id_present_flag
+        
     READ_FLAG( uiCode, "vps_nuh_layer_id_present_flag" );           pcVPS->setVpsNuhLayerIdPresentFlag( uiCode == 1 ? true : false );
 
-    // parse layer_id_in_nuh[i] and derive LayerIdInVps
-    // already updated to JCT3V-D0220
-    for( Int layer = 0; layer <= pcVPS->getMaxLayers() - 1; layer++ )
-    {
-      UInt layerIdInNuh; 
-      if ( pcVPS->getVpsNuhLayerIdPresentFlag() && ( layer != 0 ) )
-      {
-        READ_CODE( 6, uiCode, "layer_id_in_nuh[i]" );                layerIdInNuh = uiCode; 
+    for( Int i = 0; i <= pcVPS->getMaxLayers() - 1; i++ )
+    {
+       
+      if ( pcVPS->getVpsNuhLayerIdPresentFlag() && ( i > 0 ) )
+      {
+        READ_CODE( 6, uiCode, "layer_id_in_nuh[i]" );                pcVPS->setLayerIdInNuh( i, uiCode );
       }
       else
       {
-        layerIdInNuh = layer; 
-      }      
-
-      pcVPS->setLayerIdInNuh( layer, layerIdInNuh );
-      pcVPS->setLayerIdInVps( layerIdInNuh, layer ); 
-
-      // parse dimension_id[i][j]
-      for( Int sIdx = 0; sIdx < numScalabilityTypes; sIdx++ )
-      {
-          READ_CODE( pcVPS->getDimensionIdLen( sIdx ), uiCode, "dimension_id[i][j]" );  pcVPS->setDimensionId( layer, sIdx, uiCode );
-      }
-    }
-
-    for( Int layerSet = 1; layerSet <= pcVPS->getMaxOpSets() - 1; layerSet++ )
-    {
-      READ_FLAG(  uiCode, "vps_profile_present_flag[lsIdx]" );    pcVPS->setVpsProfilePresentFlag( layerSet, uiCode == 1 ? true : false );
-      if( pcVPS->getVpsProfilePresentFlag( layerSet ) == false )
-      {
-        READ_UVLC( uiCode, "profile_layer_set_ref_minus1[lsIdx]" ); pcVPS->setProfileLayerSetRefMinus1( layerSet, uiCode );
-      }
-
-      parsePTL ( pcVPS->getPTL( layerSet ), pcVPS->getVpsProfilePresentFlag( layerSet ), pcVPS->getMaxTLayers()-1);
-      if( pcVPS->getVpsProfilePresentFlag( layerSet ) == false )
-      {
-        TComPTL temp = *pcVPS->getPTL( layerSet );
-        *pcVPS->getPTL( layerSet ) = *pcVPS->getPTL( pcVPS->getProfileLayerSetRefMinus1( layerSet ) + 1 );
-        pcVPS->getPTL( layerSet )->copyLevelFrom( &temp );
-      }
-    }
-
-    READ_UVLC( uiCode, "num_output_layer_sets" );                  pcVPS->setNumOutputLayerSets( uiCode );
-    
-    for( Int layerSet = 0; layerSet < pcVPS->getNumOutputLayerSets(); layerSet++ )
-    {
-      READ_UVLC( uiCode, "output_layer_set_idx[i]" );              pcVPS->setOutputLayerSetIdxMinus1( layerSet, uiCode );
-      for( Int layer = 0; layer <= pcVPS->getVpsMaxLayerId(); layer++ )
-      {
-        if( pcVPS->getLayerIdIncludedFlag( pcVPS->getOutputLayerSetIdxMinus1( layerSet ), layer ) == true )
-        {
-//          READ_FLAG( uiCode, "output_layer_flag" );                 pcVPS->setOutputLayerFlag( layerSet, layer, uiCode == 1 ? true : false );
+        pcVPS->setLayerIdInNuh( i, i );; 
+      } 
+      
+      pcVPS->setLayerIdInVps( pcVPS->getLayerIdInNuh( i ), i ); 
+
+      if ( !pcVPS->getSplittingFlag() )
+      {    
+        for( Int j = 0; j < pcVPS->getNumScalabilityTypes() ; j++ ) 
+        {
+          READ_CODE( pcVPS->getDimensionIdLen( j ), uiCode, "dimension_id[i][j]" );  pcVPS->setDimensionId( i, j, uiCode );
         }
       }
@@ -949,5 +939,71 @@
       }
     }
-    
+
+    for( Int i = 0; i < pcVPS->getMaxLayers() - 1; i++ )
+    {
+      READ_CODE( 3, uiCode,       "max_tid_il_ref_pics_plus1[i]" );      pcVPS->setMaxTidIlRefPicPlus1( i , uiCode ); 
+    }
+
+    READ_CODE( 10, uiCode, "vps_number_layer_sets_minus1"      );  pcVPS->setVpsNumberLayerSetsMinus1    ( uiCode ); 
+    READ_CODE( 6,  uiCode, "vps_num_profile_tier_level_minus1" );  pcVPS->setVpsNumProfileTierLevelMinus1( uiCode );
+
+    for( Int i = 1; i <= pcVPS->getMaxOpSets() - 1; i++ )
+    {
+      READ_FLAG(  uiCode, "vps_profile_present_flag[i]" );    pcVPS->setVpsProfilePresentFlag( i, uiCode == 1 );
+      if( !pcVPS->getVpsProfilePresentFlag( i ) )
+      {
+        READ_CODE( 6, uiCode, "profile_ref_minus1[i]" ); pcVPS->setProfileRefMinus1( i, uiCode );
+      }
+      parsePTL ( pcVPS->getPTL( i ), pcVPS->getVpsProfilePresentFlag( i ), pcVPS->getMaxTLayers()-1);
+      if( !pcVPS->getVpsProfilePresentFlag( i ) )
+      {
+        TComPTL temp = *pcVPS->getPTL( i );
+        *pcVPS->getPTL( i ) = *pcVPS->getPTL( pcVPS->getProfileRefMinus1( i ) + 1 );
+        pcVPS->getPTL( i )->copyLevelFrom( &temp );
+      }
+    }
+
+    Int numOutputLayerSets = pcVPS->getVpsNumberLayerSetsMinus1( ) + 1; 
+
+    READ_FLAG( uiCode, "more_output_layer_sets_than_default_flag" ); pcVPS->setMoreOutputLayerSetsThanDefaultFlag( uiCode == 1 );
+
+    if ( pcVPS->getMoreOutputLayerSetsThanDefaultFlag( ) )
+    {
+      READ_CODE( 10, uiCode, "num_add_output_layer_sets_minus1"      ); pcVPS->setNumAddOutputLayerSetsMinus1( uiCode );
+      numOutputLayerSets += pcVPS->getNumAddOutputLayerSetsMinus1( ); 
+    }
+
+    if( numOutputLayerSets > 1)
+    {
+      READ_FLAG( uiCode, "default_one_target_output_layer_flag" ); pcVPS->setDefaultOneTargetOutputLayerFlag(  uiCode == 1); 
+    }  
+
+    for( Int i = 1; i < numOutputLayerSets; i++ )
+    {
+      if( i > pcVPS->getVpsNumberLayerSetsMinus1( ) )
+      {        
+        READ_UVLC( uiCode,      "output_layer_set_idx_minus1[i]" ); pcVPS->setOutputLayerSetIdxMinus1( i, uiCode ); 
+        for( Int j = 0; j <= pcVPS->getNumLayersInIdList( j ); j++ )
+        {
+          READ_FLAG( uiCode, "output_layer_flag" ); pcVPS->setOutputLayerFlag( i, j, uiCode == 1 ); 
+        }
+        READ_CODE( pcVPS->getProfileLevelTierIdxLen(), uiCode,"profile_level_tier_idx[ i ]" );   pcVPS->setProfileLevelTierIdx( i , uiCode ); 
+      }
+    }
+
+    READ_FLAG( uiCode , "max_one_active_ref_layer_flag" ); pcVPS->setMaxOneActiveRefLayerFlag( uiCode == 1 ); 
+    READ_UVLC( uiCode,  "direct_dep_type_len_minus2"); pcVPS->setDirectDepTypeLenMinus2 ( uiCode ); 
+
+    for( Int i = 1; i <= pcVPS->getMaxLayers() - 1; i++ )
+    {
+      for( Int j = 0; j < i; j++ )
+      {
+        READ_CODE( pcVPS->getDirectDepTypeLenMinus2( ) + 2,  uiCode, "direct_dependency_type[i][j]" ); pcVPS->setDirectDependencyType( i, j , uiCode);
+      }
+    }
+
+    READ_FLAG ( uiCode,                    "vps_shvc_reserved_zero_flag" ); 
+
+#if H_3D    
     READ_FLAG( uiCode,  "vps_extension2_flag" );
     if (uiCode)
@@ -959,7 +1015,9 @@
     }
 
+#endif
+
     pcVPS->checkVPSExtensionSyntax(); 
 
-    pcVPS->calcIvRefLayers(); 
+    pcVPS->setRefLayers(); 
 
 #else
@@ -1059,5 +1117,14 @@
   if(!rpcSlice->getDependentSliceSegmentFlag())
   {
-    for (Int i = 0; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
+#if H_MV    
+    if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > 0 )
+    {
+      READ_FLAG( uiCode, "discardable_flag" ); rpcSlice->setDiscardableFlag( uiCode == 1 );
+    }
+
+    for (Int i = 1; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)    
+#else
+    for (Int i = 0; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)    
+#endif     
     {
       READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
@@ -1244,4 +1311,30 @@
       }
     }
+#if H_MV
+    Int layerIdInVps       = rpcSlice->getLayerIdInVps(); 
+    if( rpcSlice->getLayerId() > 0 && vps->getNumDirectRefLayers( layerIdInVps ) > 0 )
+    {   
+      READ_FLAG( uiCode, "inter_layer_pred_enabled_flag" ); rpcSlice->setInterLayerPredEnabledFlag( uiCode == 1 );
+      if( rpcSlice->getInterLayerPredEnabledFlag() && vps->getNumDirectRefLayers( layerIdInVps ) > 1 )
+      {            
+        if( !vps->getMaxOneActiveRefLayerFlag())  
+        {
+          READ_CODE( rpcSlice->getNumInterLayerRefPicsMinus1Len( ), uiCode, "num_inter_layer_ref_pics_minus1" ); rpcSlice->setNumInterLayerRefPicsMinus1( uiCode );
+        }
+        for( Int i = 0; i < rpcSlice->getNumActiveRefLayerPics(); i++ )   
+        {
+          READ_CODE( rpcSlice->getInterLayerPredLayerIdcLen( ), uiCode, "inter_layer_pred_layer_idc" ); rpcSlice->setInterLayerPredLayerIdc( i, uiCode );
+        }
+      }  
+    }
+
+    rpcSlice->setActiveMotionPredRefLayers( );
+
+    if( vps->getNumSamplePredRefLayers( layerIdInVps ) > 0  &&  rpcSlice->getNumActiveRefLayerPics() > 0 )
+    {
+      READ_FLAG( uiCode, "inter_layer_sample_pred_only_flag" ); rpcSlice->setInterLayerSamplePredOnlyFlag( uiCode == 1 );
+    }
+
+#endif
     if(sps->getUseSAO())
     {
@@ -1384,4 +1477,16 @@
     if ( rpcSlice->getEnableTMVPFlag() )
     {
+#if H_MV
+      if( rpcSlice->getLayerId() > 0 && rpcSlice->getNumActiveMotionPredRefLayers() > 0 )
+      {
+        READ_FLAG( uiCode, "alt_collocated_indication_flag" ); rpcSlice->setAltCollocatedIndicationFlag( uiCode == 1 );
+        if( rpcSlice->getAltCollocatedIndicationFlag() && rpcSlice->getNumActiveMotionPredRefLayers() > 1 ) 
+        {          
+          READ_UVLC( uiCode, "collocated_ref_layer_idx" ); rpcSlice->setCollocatedRefLayerIdx( uiCode );
+        }
+      }
+      else 
+      {
+#endif
       if ( rpcSlice->getSliceType() == B_SLICE )
       {
@@ -1405,4 +1510,7 @@
         rpcSlice->setColRefIdx(0);
       }
+#if H_MV
+      }
+#endif
     }
     if ( (pps->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPred() && rpcSlice->getSliceType()==B_SLICE) )
Index: /branches/HTM-DEV-0.3-dev0/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev0/source/Lib/TLibDecoder/TDecTop.cpp	(revision 489)
+++ /branches/HTM-DEV-0.3-dev0/source/Lib/TLibDecoder/TDecTop.cpp	(revision 490)
@@ -1002,6 +1002,9 @@
 {
   TComSPS* sps = new TComSPS();
+#if H_MV
+  sps->setLayerId( getLayerId() ); 
+#endif
 #if H_3D
-  // Preliminary fix. assuming that all sps refer to the same SPS. 
+  // Preliminary fix. assuming that all sps refer to the same VPS. 
   // Parsing dependency should be resolved!
   TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 ); 
Index: /branches/HTM-DEV-0.3-dev0/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev0/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 489)
+++ /branches/HTM-DEV-0.3-dev0/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 490)
@@ -329,4 +329,10 @@
   {
     WRITE_FLAG(pcVUI->getTilesFixedStructureFlag(),             "tiles_fixed_structure_flag");
+#if H_MV
+    if ( pcSPS->getLayerId() > 0 )
+    {
+      WRITE_FLAG( pcVUI->getTileBoundariesAlignedFlag( ) ? 1 : 0 , "tile_boundaries_aligned_flag" );
+    }
+#endif
     WRITE_FLAG(pcVUI->getMotionVectorsOverPicBoundariesFlag(),  "motion_vectors_over_pic_boundaries_flag");
     WRITE_FLAG(pcVUI->getRestrictedRefPicListsFlag(),           "restricted_ref_pic_lists_flag");
@@ -556,4 +562,23 @@
   WRITE_FLAG( 1, "sps_extension_flag" );
   WRITE_FLAG( pcSPS->getInterViewMvVertConstraintFlag() ? 1 : 0, "inter_view_mv_vert_constraint_flag" );
+  ////   sps_extension_vui_parameters( )
+  if( pcSPS->getVuiParameters()->getBitstreamRestrictionFlag() )
+  {  
+    WRITE_UVLC( pcSPS->getNumIlpRestrictedRefLayers( ),           "num_ilp_restricted_ref_layers" ); 
+    for( Int i = 0; i < pcSPS->getNumIlpRestrictedRefLayers( ); i++ ) 
+    {  
+      WRITE_UVLC( pcSPS->getMinSpatialSegmentOffsetPlus1( i ),    "min_spatial_segment_offset_plus1" ); 
+      if( pcSPS->getMinSpatialSegmentOffsetPlus1( i ) > 0 ) 
+      {  
+        WRITE_FLAG( pcSPS->getCtuBasedOffsetEnabledFlag( i ),      "ctu_based_offset_enabled_flag[ i ]"); 
+        if( pcSPS->getCtuBasedOffsetEnabledFlag( i ) )  
+        {
+          WRITE_UVLC( pcSPS->getMinHorizontalCtuOffsetPlus1( i ), "min_horizontal_ctu_offset_plus1[ i ]"); 
+        }
+      }  
+    }  
+  }  
+  ////   sps_extension_vui_parameters( ) END
+  WRITE_UVLC( 0, "sps_shvc_reserved_zero_idc" ); 
 #if !H_3D
   WRITE_FLAG( 0, "sps_extension2_flag" );
@@ -700,10 +725,16 @@
   
   for( Int i = 0; i <= pcVPS->getMaxLayers() - 1; i++ )
-  {
+  {     
     if ( pcVPS->getVpsNuhLayerIdPresentFlag() && ( i > 0 ) )
     {
       WRITE_CODE( pcVPS->getLayerIdInNuh( i ), 6,          "layer_id_in_nuh[i]");
     }
-
+    else
+    {
+      assert( pcVPS->getLayerIdInNuh( i ) == i ); 
+    }
+
+    assert(  pcVPS->getLayerIdInVps( pcVPS->getLayerIdInNuh( i ) ) == i ); 
+      
     if ( !pcVPS->getSplittingFlag() )
     {    
@@ -738,13 +769,12 @@
       WRITE_CODE( pcVPS->getProfileRefMinus1( i ), 6, "profile_ref_minus1[i]" );
     }
-
     codePTL( pcVPS->getPTL( i ), pcVPS->getVpsProfilePresentFlag( i ), pcVPS->getMaxTLayers() - 1 );
   }
 
-  Int numOutputLayerSets = pcVPS->getNumOutputLayerSets(); 
-
-  WRITE_FLAG( pcVPS->getVpsMoreOutputLayerSetsThanDefaultFlag( ) ? 1 : 0, "more_output_layer_sets_than_default_flag" );
-
-  if ( pcVPS->getVpsMoreOutputLayerSetsThanDefaultFlag( ) )
+  Int numOutputLayerSets = pcVPS->getVpsNumberLayerSetsMinus1( ) + 1; 
+
+  WRITE_FLAG( pcVPS->getMoreOutputLayerSetsThanDefaultFlag( ) ? 1 : 0, "more_output_layer_sets_than_default_flag" );
+
+  if ( pcVPS->getMoreOutputLayerSetsThanDefaultFlag( ) )
   {
     WRITE_CODE( pcVPS->getNumAddOutputLayerSetsMinus1( )    , 10,    "num_add_output_layer_sets_minus1"      );
@@ -760,13 +790,10 @@
   {
     if( i > pcVPS->getVpsNumberLayerSetsMinus1( ) )
-    {
-      Int lsIdx = pcVPS->getOutputLayerSetIdxMinus1( i ) + 1; 
-      WRITE_UVLC( lsIdx,      "output_layer_set_idx[i]" );
-
+    {      
+      WRITE_UVLC( pcVPS->getOutputLayerSetIdxMinus1( i ),      "output_layer_set_idx_minus1[i]" );
       for( Int j = 0; j <= pcVPS->getNumLayersInIdList( j ); j++ )
       {
-        //WRITE_FLAG( pcVPS->getOutputLayerFlag( i, j) ? 1 : 0, "output_layer_flag" );
-      }
-
+        WRITE_FLAG( pcVPS->getOutputLayerFlag( i, j) ? 1 : 0, "output_layer_flag" );
+      }
       WRITE_CODE( pcVPS->getProfileLevelTierIdx( i ), pcVPS->getProfileLevelTierIdxLen() ,"profile_level_tier_idx[ i ]" );   
     }
@@ -799,4 +826,7 @@
 Void TEncCavlc::codeSliceHeader         ( TComSlice* pcSlice )
 {
+#if H_MV
+  TComVPS* vps = pcSlice->getVPS(); 
+#endif
 #if ENC_DEC_TRACE  
   xTraceSliceHeader (pcSlice);
@@ -841,5 +871,14 @@
   if ( !pcSlice->getDependentSliceSegmentFlag() )
   {
+#if H_MV    
+    if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > 0 )
+    {
+      WRITE_FLAG( pcSlice->getDiscardableFlag( ) ? 1 : 0 , "discardable_flag" );
+    }
+
+    for (Int i = 1; i < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)    
+#else
     for (Int i = 0; i < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
+#endif
     {
       assert(!!"slice_reserved_undetermined_flag[]");
@@ -994,4 +1033,30 @@
       }
     }
+#if H_MV
+    Int layerIdInVps       = pcSlice->getLayerIdInVps(); 
+    if( pcSlice->getLayerId() > 0 && vps->getNumDirectRefLayers( layerIdInVps ) > 0 )
+    {   
+      WRITE_FLAG( pcSlice->getInterLayerPredEnabledFlag( ) ? 1 : 0 , "inter_layer_pred_enabled_flag" );
+      if( pcSlice->getInterLayerPredEnabledFlag() && vps->getNumDirectRefLayers( layerIdInVps ) > 1 )
+      {            
+        if( !vps->getMaxOneActiveRefLayerFlag())  
+        {
+          WRITE_CODE( pcSlice->getNumInterLayerRefPicsMinus1( ), pcSlice->getNumInterLayerRefPicsMinus1Len( ), "num_inter_layer_ref_pics_minus1" );
+        }
+        for( Int i = 0; i < pcSlice->getNumActiveRefLayerPics(); i++ )   
+        {
+          WRITE_CODE( pcSlice->getInterLayerPredLayerIdc( i ), pcSlice->getInterLayerPredLayerIdcLen( ), "inter_layer_pred_layer_idc" );
+        }
+      }  
+    }
+
+    pcSlice->setActiveMotionPredRefLayers( );
+
+    if( vps->getNumSamplePredRefLayers( layerIdInVps ) > 0  &&  pcSlice->getNumActiveRefLayerPics() > 0 )
+    {
+      WRITE_FLAG( pcSlice->getInterLayerSamplePredOnlyFlag( ) ? 1 : 0 , "inter_layer_sample_pred_only_flag" );
+    }
+
+#endif
     if(pcSlice->getSPS()->getUseSAO())
     {
@@ -1101,4 +1166,18 @@
     if ( pcSlice->getEnableTMVPFlag() )
     {
+#if H_MV
+      if( pcSlice->getLayerId() > 0 && pcSlice->getNumActiveMotionPredRefLayers() > 0 )
+      {
+        WRITE_FLAG( pcSlice->getAltCollocatedIndicationFlag( ) ? 1 : 0 , "alt_collocated_indication_flag" );
+
+        if( pcSlice->getAltCollocatedIndicationFlag() && pcSlice->getNumActiveMotionPredRefLayers() > 1 ) 
+        {          
+          WRITE_UVLC( pcSlice->getCollocatedRefLayerIdx( ), "collocated_ref_layer_idx" );
+        }
+      }
+      else 
+      {
+#endif
+
       if ( pcSlice->getSliceType() == B_SLICE )
       {
@@ -1113,4 +1192,7 @@
       }
     }
+#if H_MV
+    }
+#endif
     if ( (pcSlice->getPPS()->getUseWP() && pcSlice->getSliceType()==P_SLICE) || (pcSlice->getPPS()->getWPBiPred() && pcSlice->getSliceType()==B_SLICE) )
     {
Index: /branches/HTM-DEV-0.3-dev0/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev0/source/Lib/TLibEncoder/TEncTop.cpp	(revision 489)
+++ /branches/HTM-DEV-0.3-dev0/source/Lib/TLibEncoder/TEncTop.cpp	(revision 490)
@@ -512,5 +512,6 @@
 {
 #if H_MV
-  m_cSPS.setSPSId( getLayerIdInVps() );
+  m_cSPS.setSPSId  ( getLayerIdInVps() ); 
+  m_cSPS.setLayerId( getLayerId() );
 #endif
   ProfileTierLevel& profileTierLevel = *m_cSPS.getPTL()->getGeneralPTL();
