Index: branches/HTM-DEV-0.3-dev0/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev0/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 488)
+++ 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 488)
+++ 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();
