Index: branches/HTM-9.0-dev0/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- branches/HTM-9.0-dev0/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 729)
+++ branches/HTM-9.0-dev0/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 730)
@@ -280,4 +280,7 @@
   }
   WRITE_FLAG(pcVUI->getVideoSignalTypePresentFlag(),            "video_signal_type_present_flag");
+#if H_MV_6_PS_O0118_33
+  assert( pcSPS->getLayerId() == 0 || !pcVUI->getVideoSignalTypePresentFlag() ); 
+#endif
   if (pcVUI->getVideoSignalTypePresentFlag())
   {
@@ -443,8 +446,18 @@
   {
     WRITE_FLAG( pcSPS->getUpdateRepFormatFlag( ) ? 1 : 0 , "update_rep_format_flag" );
+#if H_MV_6_PS_REP_FORM_18_19_20    
+    if ( pcSPS->getUpdateRepFormatFlag() )
+    { 
+      WRITE_CODE( pcSPS->getSpsRepFormatIdx( ), 8, "sps_rep_format_idx" );
+    }
+  }
+  else
+  {
+#else
   }
 
   if ( pcSPS->getUpdateRepFormatFlag() )
   { 
+#endif
 #endif
   WRITE_UVLC( pcSPS->getChromaFormatIdc (),         "chroma_format_idc" );
@@ -472,5 +485,9 @@
   }
 #if H_MV
+#if H_MV_6_PS_REP_FORM_18_19_20
+  if ( pcSPS->getLayerId() == 0 )
+#else
   if ( pcSPS->getUpdateRepFormatFlag() )
+#endif
   { 
 #endif
@@ -577,4 +594,32 @@
   WRITE_FLAG( 0, "sps_extension_flag" );
 #else
+#if H_MV_6_PSEM_O0142_3
+  WRITE_FLAG( pcSPS->getSpsExtensionFlag(), "sps_extension_flag" );
+
+  if ( pcSPS->getSpsExtensionFlag() )
+  {
+    for (Int i = 0; i < PS_EX_T_MAX_NUM; i++)
+    {
+      WRITE_FLAG( pcSPS->getSpsExtensionTypeFlag( i ) ? 1 : 0 , "sps_extension_type_flag" );
+#if H_3D
+      assert( !pcSPS->getSpsExtensionTypeFlag( i ) || i == PS_EX_T_MV || i == PS_EX_T_3D ); 
+#else
+      assert( !pcSPS->getSpsExtensionTypeFlag( i ) || i == PS_EX_T_MV ); 
+#endif
+    }  
+
+    if( pcSPS->getSpsExtensionTypeFlag( PS_EX_T_MV ))
+    {
+      codeSPSExtension( pcSPS ); 
+    }
+
+#if H_3D
+    if( pcSPS->getSpsExtensionTypeFlag( PS_EX_T_3D ))
+    {
+      codeSPSExtension2( pcSPS, viewIndex, depthFlag ); 
+    }
+#endif
+  }
+#else
   WRITE_FLAG( 1, "sps_extension_flag" );
   codeSPSExtension( pcSPS ); 
@@ -587,4 +632,5 @@
 #endif  
 #endif
+#endif
 }
 
@@ -593,5 +639,22 @@
 {
   WRITE_FLAG( pcSPS->getInterViewMvVertConstraintFlag() ? 1 : 0, "inter_view_mv_vert_constraint_flag" );
+
+#if !H_MV_6_SHVC_O0098_36
   WRITE_UVLC( 0, "sps_shvc_reserved_zero_idc" ); 
+#else
+  WRITE_UVLC( pcSPS->getNumScaledRefLayerOffsets( ), "num_scaled_ref_layer_offsets" );
+
+  for( Int i = 0; i < pcSPS->getNumScaledRefLayerOffsets( ); i++)
+  {    
+    WRITE_CODE( pcSPS->getScaledRefLayerId( i ), 6, "scaled_ref_layer_id" );
+
+    Int j = pcSPS->getScaledRefLayerId( i ); 
+    
+    WRITE_SVLC( pcSPS->getScaledRefLayerLeftOffset( j ), "scaled_ref_layer_left_offset" );
+    WRITE_SVLC( pcSPS->getScaledRefLayerTopOffset( j ), "scaled_ref_layer_top_offset" );
+    WRITE_SVLC( pcSPS->getScaledRefLayerRightOffset( j ), "scaled_ref_layer_right_offset" );
+    WRITE_SVLC( pcSPS->getScaledRefLayerBottomOffset( j ), "scaled_ref_layer_bottom_offset" );
+  }
+#endif  
 }
 #endif
@@ -740,5 +803,13 @@
 {
   WRITE_FLAG( pcVPS->getAvcBaseLayerFlag() ? 1 : 0,          "avc_base_layer_flag" );
+#if H_MV_6_PS_O0109_24
+  WRITE_FLAG( pcVPS->getVpsVuiPresentFlag() ? 1 : 0 , "vps_vui_present_flag" );
+  if ( pcVPS->getVpsVuiPresentFlag() )
+  {  
+#endif
   WRITE_CODE( pcVPS->getVpsVuiOffset( ), 16,                 "vps_vui_offset" );  // TBD
+#if H_MV_6_PS_O0109_24
+  }
+#endif
   WRITE_FLAG( pcVPS->getSplittingFlag() ? 1 : 0,             "splitting_flag" );
   
@@ -786,4 +857,23 @@
   }
 
+
+#if H_MV_6_PS_O0109_22
+    WRITE_CODE( pcVPS->getViewIdLen( ), 4, "view_id_len" );
+    
+    if ( pcVPS->getViewIdLen( ) > 0 )
+    {    
+      for( Int i = 0; i < pcVPS->getNumViews(); i++ )
+      {
+        WRITE_CODE( pcVPS->getViewIdVal( i ), pcVPS->getViewIdLen( ), "view_id_val[i]" );
+      }
+    }
+    else
+    {
+      for( Int i = 0; i < pcVPS->getNumViews(); i++ )
+      {
+        assert( pcVPS->getViewIdVal( i ) == 0 ); 
+      }
+    }
+#else
   // GT spec says: trac #39
   // if ( pcVPS->getNumViews() > 1 )  
@@ -792,9 +882,10 @@
     WRITE_CODE( pcVPS->getViewIdLenMinus1( ), 4, "view_id_len_minus1" );
   }
-
   for( Int i = 0; i < pcVPS->getNumViews(); i++ )
   {
     WRITE_CODE( pcVPS->getViewIdVal( i ), pcVPS->getViewIdLenMinus1( ) + 1, "view_id_val[i]" );
   }
+#endif
+
 
   for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
@@ -805,5 +896,22 @@
     }
   }
-
+#if H_MV_6_ILDSD_O0120_26
+  WRITE_FLAG( pcVPS->getVpsSubLayersMaxMinus1PresentFlag( ) ? 1 : 0 , "vps_sub_layers_max_minus1_present_flag" );
+  if ( pcVPS->getVpsSubLayersMaxMinus1PresentFlag() )
+  {
+    for (Int i = 0; i < pcVPS->getMaxLayersMinus1(); i++ )
+    {
+      WRITE_CODE( pcVPS->getSubLayersVpsMaxMinus1( i ), 3, "sub_layers_vps_max_minus1" );
+      pcVPS->checkSubLayersVpsMaxMinus1( i ); 
+    }
+  }  
+  else
+  {
+    for (Int i = 0; i < pcVPS->getMaxLayersMinus1(); i++ )
+    {
+      assert( pcVPS->getSubLayersVpsMaxMinus1( i ) + 1 == pcVPS->getMaxTLayers( ) );    
+    }
+  }
+#endif
   WRITE_FLAG( pcVPS->getMaxTidRefPresentFlag( ) ? 1 : 0 , "max_tid_ref_present_flag" );
 
@@ -812,5 +920,15 @@
     for( Int i = 0; i < pcVPS->getMaxLayersMinus1(); i++ )
     {
+#if H_MV_6_ILDDS_O0225_30
+      for( Int j = i + 1; j <= pcVPS->getMaxLayersMinus1(); j++ )
+      {
+        if ( pcVPS->getDirectDependencyFlag(j,i) )
+        {
+          WRITE_CODE( pcVPS->getMaxTidIlRefPicsPlus1( i, j ), 3, "max_tid_il_ref_pics_plus1" );
+        }
+      }
+#else
       WRITE_CODE( pcVPS->getMaxTidIlRefPicPlus1( i ), 3,       "max_tid_il_ref_pics_plus1[i]" );
+#endif
     }
   }
@@ -826,4 +944,7 @@
     {    
       WRITE_CODE( pcVPS->getProfileRefMinus1( i ), 6, "profile_ref_minus1[i]" );
+#if H_MV_6_PS_O0109_23
+      pcVPS->checkProfileRefMinus1( i );      
+#endif
     }
     codePTL( pcVPS->getPTL( i ), pcVPS->getVpsProfilePresentFlag( i ), pcVPS->getMaxTLayers() - 1 );
@@ -842,7 +963,16 @@
   if( numOutputLayerSets > 1)
   {
+#if H_MV_6_PS_0109_25
+    WRITE_CODE( pcVPS->getDefaultOneTargetOutputLayerIdc( ), 2, "default_one_target_output_layer_idc" );
+    pcVPS->checkDefaultOneTargetOutputLayerIdc(); 
+#else
     WRITE_FLAG( pcVPS->getDefaultOneTargetOutputLayerFlag( ) ? 1 : 0, "default_one_target_output_layer_flag" );
+#endif        
   }  
 
+#if H_MV_6_HRD_O0217_13
+  assert( pcVPS->getOutputLayerFlag(0, 0) == pcVPS->inferOutputLayerFlag( 0, 0 )); 
+  assert( pcVPS->getOutputLayerSetIdxMinus1( 0 ) == -1 ); 
+#endif
   for( Int i = 1; i < numOutputLayerSets; i++ )
   {
@@ -855,4 +985,15 @@
       }      
     }
+#if H_MV_6_HRD_O0217_13
+    else
+    { // These inference rules would also be helpful in spec text
+      assert( pcVPS->getOutputLayerSetIdxMinus1(i ) ==  i - 1 ); 
+      for( Int j = 0; j < pcVPS->getNumLayersInIdList( j ) - 1; j++ )
+      {              
+        assert( pcVPS->getOutputLayerFlag( i , j ) == pcVPS->inferOutputLayerFlag( i, j )); 
+      }
+    }
+#endif
+
     if ( pcVPS->getProfileLevelTierIdxLen()  > 0 )
     {      
@@ -861,4 +1002,11 @@
   }
 
+#if H_MV_6_GEN_0153_28
+  if( pcVPS->getMaxLayersMinus1() > 0 )
+  {
+    WRITE_FLAG( pcVPS->getAltOutputLayerFlag( ) ? 1 : 0 , "alt_output_layer_flag" );
+  }
+#endif
+
   WRITE_FLAG( pcVPS->getRepFormatIdxPresentFlag( ) ? 1 : 0 , "rep_format_idx_present_flag" );
   if ( pcVPS->getRepFormatIdxPresentFlag() )
@@ -869,6 +1017,12 @@
   for (Int i = 0; i <= pcVPS->getVpsNumRepFormatsMinus1(); i++ )
   {    
+#if H_MV_6_PS_REP_FORM_18_19_20
+    TComRepFormat* curRepFormat = pcVPS->getRepFormat(i);     
+    TComRepFormat* prevRepFormat = i > 0 ? pcVPS->getRepFormat( i - 1) : NULL; 
+    codeRepFormat( i, curRepFormat ,  prevRepFormat); 
+#else
     TComRepFormat* pcRepFormat = pcVPS->getRepFormat(i);     
     codeRepFormat( pcRepFormat ); 
+#endif
   }
 
@@ -879,5 +1033,9 @@
       if( pcVPS->getVpsNumRepFormatsMinus1() > 0 )
       {
+#if H_MV_6_PS_REP_FORM_18_19_20
+        WRITE_CODE( pcVPS->getVpsRepFormatIdx( i ), 8, "vps_rep_format_idx" );
+#else
         WRITE_CODE( pcVPS->getVpsRepFormatIdx( i ), 4, "vps_rep_format_idx" );
+#endif
       }
     }
@@ -885,7 +1043,49 @@
 
   WRITE_FLAG( pcVPS->getMaxOneActiveRefLayerFlag( ) ? 1 : 0, "max_one_active_ref_layer_flag" );
+#if H_MV_6_MISC_O0062_31
+  for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
+  {
+    if( pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i ) )  ==  0 )
+    {      
+      WRITE_FLAG( pcVPS->getPocLsbNotPresentFlag( i ) ? 1 : 0 , "poc_lsb_not_present_flag" );
+    }
+  }
+#endif
+#if H_MV_6_HRD_O0217_13
+  codeDpbSize( pcVPS ); 
+#endif
+
+#if !H_MV_6_PS_O0223_29
   WRITE_FLAG( pcVPS->getCrossLayerIrapAlignedFlag( ) ? 1 : 0 , "cross_layer_irap_aligned_flag" );
+#endif
   WRITE_UVLC( pcVPS->getDirectDepTypeLenMinus2 ( ),         "direct_dep_type_len_minus2"); 
 
+#if H_MV_6_PS_O0096_21
+  WRITE_FLAG( pcVPS->getDefaultDirectDependencyFlag( ) ? 1 : 0 , "default_direct_dependency_flag" );
+
+  if ( pcVPS->getDefaultDirectDependencyFlag( ) )
+  {  
+    WRITE_CODE( pcVPS->getDefaultDirectDependencyType( ), pcVPS->getDirectDepTypeLenMinus2( ) + 2 , "default_direct_dependency_type" );    
+  }
+
+  for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
+  {
+    for( Int j = 0; j < i; j++ )
+    {
+      if (pcVPS->getDirectDependencyFlag( i, j) )
+      {        
+        if ( pcVPS->getDefaultDirectDependencyFlag( ) )
+        {  
+          assert( pcVPS->getDirectDependencyType( i, j ) == pcVPS->getDefaultDirectDependencyType( ) );
+        }
+        else
+        {
+          assert ( pcVPS->getDirectDependencyType( i, j ) != -1 ); 
+          WRITE_CODE( pcVPS->getDirectDependencyType( i, j ),pcVPS->getDirectDepTypeLenMinus2( ) + 2,  "direct_dependency_type[i][j]" );
+        }
+      }
+    }
+  }  
+#else
     for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
     {
@@ -899,7 +1099,9 @@
       }
     }
-    
+#endif
     WRITE_FLAG ( 0,                                      "vps_shvc_reserved_zero_flag" ); 
+#if !H_MV_6_PS_O0109_24
     WRITE_FLAG( pcVPS->getVpsVuiPresentFlag( ) ? 1 : 0 , "vps_vui_present_flag" );
+#endif
 
     if( pcVPS->getVpsVuiPresentFlag() )
@@ -909,19 +1111,95 @@
     }     
 }
-
+#if H_MV_6_PS_O0118_33
+Void TEncCavlc::codeVideoSignalInfo( TComVideoSignalInfo* pcVideoSignalInfo )
+{
+  assert( pcVideoSignalInfo ); 
+  WRITE_CODE( pcVideoSignalInfo->getVideoVpsFormat( ), 3, "video_vps_format" );
+  WRITE_FLAG( pcVideoSignalInfo->getVideoFullRangeVpsFlag( ) ? 1 : 0 , "video_full_range_vps_flag" );
+  WRITE_CODE( pcVideoSignalInfo->getColourPrimariesVps( ), 8, "colour_primaries_vps" );
+  WRITE_CODE( pcVideoSignalInfo->getTransferCharacteristicsVps( ), 8, "transfer_characteristics_vps" );
+  WRITE_CODE( pcVideoSignalInfo->getMatrixCoeffsVps( ), 8, "matrix_coeffs_vps" );
+}
+#endif
+
+#if H_MV_6_HRD_O0217_13
+Void TEncCavlc::codeDpbSize( TComVPS* vps )
+{ 
+  TComDpbSize* dpbSize = vps->getDpbSize(); 
+  assert ( dpbSize != 0 ); 
+
+  for( Int i = 1; i < vps->getNumOutputLayerSets(); i++ )
+  {  
+    WRITE_FLAG( dpbSize->getSubLayerFlagInfoPresentFlag( i ) ? 1 : 0 , "sub_layer_flag_info_present_flag" );
+
+    for( Int j = 0; j  <=  vps->getMaxTLayers() - 1 ; j++ )
+    {  
+      if( j > 0  &&  dpbSize->getSubLayerDpbInfoPresentFlag( i, j )  )  
+      {
+        WRITE_FLAG( dpbSize->getSubLayerDpbInfoPresentFlag( i, j ) ? 1 : 0 , "sub_layer_dpb_info_present_flag" );
+      }
+      if( dpbSize->getSubLayerDpbInfoPresentFlag( i, j ) )
+      {  
+        for( Int k = 0; k < vps->getNumSubDpbs( vps->getOutputLayerSetIdxMinus1( i ) + 1 ); k++ )   // Preliminary fix does not match with spec
+        {
+          WRITE_UVLC( dpbSize->getMaxVpsDecPicBufferingMinus1( i, k, j ), "max_vps_dec_pic_buffering_minus1" );
+        }
+        WRITE_UVLC( dpbSize->getMaxVpsNumReorderPics( i, j ), "max_vps_num_reorder_pics" );
+        WRITE_UVLC( dpbSize->getMaxVpsLatencyIncreasePlus1( i, j ), "max_vps_latency_increase_plus1" );
+      }
+      else
+      {
+        if ( j > 0 )
+        {
+          for( Int k = 0; k < vps->getNumSubDpbs( vps->getOutputLayerSetIdxMinus1( i ) + 1 ); k++ )   
+          {
+            assert( dpbSize->getMaxVpsDecPicBufferingMinus1( i, k, j ) == dpbSize->getMaxVpsDecPicBufferingMinus1( i,k, j - 1 ) );
+          }
+          assert( dpbSize->getMaxVpsNumReorderPics      ( i, j ) ==  dpbSize->getMaxVpsNumReorderPics      ( i, j - 1 ) );
+          assert( dpbSize->getMaxVpsLatencyIncreasePlus1( i, j ) ==  dpbSize->getMaxVpsLatencyIncreasePlus1( i, j - 1 ) );
+        }
+      }
+    }        
+  }  
+}
+#endif
+
+#if H_MV_6_PS_REP_FORM_18_19_20
+Void TEncCavlc::codeRepFormat( Int i, TComRepFormat* pcRepFormat, TComRepFormat* pcPrevRepFormat )
+#else
 Void TEncCavlc::codeRepFormat( TComRepFormat* pcRepFormat )
+#endif
 {
   assert( pcRepFormat ); 
 
-  WRITE_CODE( pcRepFormat->getChromaFormatVpsIdc( ), 2, "chroma_format_vps_idc" );
-
-  if ( pcRepFormat->getChromaFormatVpsIdc() == 3 )
-  {
-    WRITE_FLAG( pcRepFormat->getSeparateColourPlaneVpsFlag( ) ? 1 : 0 , "separate_colour_plane_vps_flag" );
-  }
+#if H_MV_6_PS_REP_FORM_18_19_20
   WRITE_CODE( pcRepFormat->getPicWidthVpsInLumaSamples( ),  16, "pic_width_vps_in_luma_samples" );
   WRITE_CODE( pcRepFormat->getPicHeightVpsInLumaSamples( ), 16, "pic_height_vps_in_luma_samples" );
+  WRITE_FLAG( pcRepFormat->getChromaAndBitDepthVpsPresentFlag( ) ? 1 : 0 , "chroma_and_bit_depth_vps_present_flag" );
+  
+  pcRepFormat->checkChromaAndBitDepthVpsPresentFlag( i ); 
+
+  if ( pcRepFormat->getChromaAndBitDepthVpsPresentFlag() )
+  {  
+#endif
+  WRITE_CODE( pcRepFormat->getChromaFormatVpsIdc( ), 2, "chroma_format_vps_idc" );
+
+  if ( pcRepFormat->getChromaFormatVpsIdc() == 3 )
+  {
+    WRITE_FLAG( pcRepFormat->getSeparateColourPlaneVpsFlag( ) ? 1 : 0 , "separate_colour_plane_vps_flag" );
+  }
+#if !H_MV_6_PS_REP_FORM_18_19_20
+  WRITE_CODE( pcRepFormat->getPicWidthVpsInLumaSamples( ),  16, "pic_width_vps_in_luma_samples" );
+  WRITE_CODE( pcRepFormat->getPicHeightVpsInLumaSamples( ), 16, "pic_height_vps_in_luma_samples" );
+#endif
   WRITE_CODE( pcRepFormat->getBitDepthVpsLumaMinus8( ),      4, "bit_depth_vps_luma_minus8" );
   WRITE_CODE( pcRepFormat->getBitDepthVpsChromaMinus8( ),    4, "bit_depth_vps_chroma_minus8" );
+#if H_MV_6_PS_REP_FORM_18_19_20
+  }
+  else
+  {
+    pcRepFormat->inferChromaAndBitDepth(pcPrevRepFormat, true ); 
+  }
+#endif
 }
 
@@ -933,4 +1211,12 @@
 
   assert( pcVPSVUI ); 
+
+#if H_MV_6_PS_O0223_29
+  WRITE_FLAG( pcVPSVUI->getCrossLayerPicTypeAlignedFlag( ) ? 1 : 0 , "cross_layer_pic_type_aligned_flag" );
+  if ( !pcVPSVUI->getCrossLayerPicTypeAlignedFlag() )
+  {  
+    WRITE_FLAG( pcVPSVUI->getCrossLayerIrapAlignedFlag( ) ? 1 : 0 , "cross_layer_irap_aligned_flag" );
+  }
+#endif
 
   WRITE_FLAG( pcVPSVUI->getBitRatePresentVpsFlag( ) ? 1 : 0 , "bit_rate_present_vps_flag" );
@@ -964,4 +1250,40 @@
   }
 
+#if H_MV_6_O0226_37
+  WRITE_FLAG( pcVPSVUI->getTilesNotInUseFlag( ) ? 1 : 0 , "tiles_not_in_use_flag" );
+  if( !pcVPSVUI->getTilesNotInUseFlag() ) 
+  {      
+    for( Int i = 0; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
+    {
+      WRITE_FLAG( pcVPSVUI->getTilesInUseFlag( i ) ? 1 : 0 , "tiles_in_use_flag[i]" );
+      if( pcVPSVUI->getTilesInUseFlag( i ) )  
+      {
+        WRITE_FLAG( pcVPSVUI->getLoopFilterNotAcrossTilesFlag( i ) ? 1 : 0, "loop_filter_not_across_tiles_flag[i]" );
+      }
+    }  
+
+    for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )  
+    {
+      for( Int j = 0; j < pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i ) ) ; j++ )
+      {  
+        Int layerIdx = pcVPS->getLayerIdInVps(pcVPS->getRefLayerId(pcVPS->getLayerIdInNuh( i ) , j  ));  
+        if( pcVPSVUI->getTilesInUseFlag( i )  &&  pcVPSVUI->getTilesInUseFlag( layerIdx ) )  
+        {
+          WRITE_FLAG( pcVPSVUI->getTileBoundariesAlignedFlag( i, j ) ? 1 : 0 , "tile_boundaries_aligned_flag[i][j]" );
+        }
+      }  
+    }
+  }  
+
+  WRITE_FLAG( pcVPSVUI->getWppNotInUseFlag( ) ? 1 : 0 , "wpp_not_in_use_flag" );
+
+  if( !pcVPSVUI->getWppNotInUseFlag( ) )
+  {
+    for( Int i = 0; i  <=  pcVPS->getMaxLayersMinus1(); i++ )  
+    {
+      WRITE_FLAG( pcVPSVUI->getWppInUseFlag( i ) ? 1 : 0 , "wpp_in_use_flag[i]" );
+    }
+  }
+#else
   for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
   {
@@ -971,5 +1293,5 @@
     }
   }
-
+#endif
   WRITE_FLAG( pcVPSVUI->getIlpRestrictedRefLayersFlag( ) ? 1 : 0 , "ilp_restricted_ref_layers_flag" );
 
@@ -992,5 +1314,105 @@
     }
   }
-}
+#if H_MV_6_PS_O0118_33
+  WRITE_FLAG( pcVPSVUI->getVideoSignalInfoIdxPresentFlag( ) ? 1 : 0 , "video_signal_info_idx_present_flag" );
+  if( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() )
+  {
+    WRITE_CODE( pcVPSVUI->getVpsNumVideoSignalInfoMinus1( ), 4, "vps_num_video_signal_info_minus1" );
+  }
+  else
+  {
+    pcVPSVUI->setVpsNumVideoSignalInfoMinus1( pcVPS->getMaxLayersMinus1() ); 
+  }
+
+  for( Int i = 0; i <= pcVPSVUI->getVpsNumVideoSignalInfoMinus1(); i++ )
+  {
+    assert( pcVPSVUI->getVideoSignalInfo( i ) != NULL ); 
+    TComVideoSignalInfo* curVideoSignalInfo = pcVPSVUI->getVideoSignalInfo( i ); 
+    codeVideoSignalInfo( curVideoSignalInfo );     
+  }
+
+  if( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() && pcVPSVUI->getVpsNumVideoSignalInfoMinus1() > 0 )
+  {
+    for( Int i = 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
+    {
+      WRITE_CODE( pcVPSVUI->getVpsVideoSignalInfoIdx( i ), 4, "vps_video_signal_info_idx" );
+      assert( pcVPSVUI->getVpsVideoSignalInfoIdx( i ) >= 0 && pcVPSVUI->getVpsVideoSignalInfoIdx( i ) <= pcVPSVUI->getVpsNumVideoSignalInfoMinus1() );
+    }
+  }
+  else
+  {
+    for( Int i = 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
+    {
+      assert( pcVPSVUI->getVpsVideoSignalInfoIdx( i  ) == ( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() ? 0 : i ) ); 
+    }
+  }
+#endif
+#if H_MV_6_HRD_O0164_15
+  WRITE_FLAG( pcVPSVUI->getVpsVuiBspHrdPresentFlag( ) ? 1 : 0 , "vps_vui_bsp_hrd_present_flag" );
+  if ( pcVPSVUI->getVpsVuiBspHrdPresentFlag( ) )
+  {
+    codeVpsVuiBspHrdParameters( pcVPS ); 
+  }
+#endif
+}
+#if H_MV_6_HRD_O0164_15
+Void TEncCavlc::codeVpsVuiBspHrdParameters( TComVPS* pcVPS )
+{
+  assert( pcVPS ); 
+
+  TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( ); 
+
+  assert( pcVPSVUI ); 
+
+  TComVpsVuiBspHrdParameters*  vpsVuiBspHrdP = pcVPSVUI->getVpsVuiBspHrdParameters(); 
+
+  assert ( vpsVuiBspHrdP );
+
+  
+  WRITE_UVLC( vpsVuiBspHrdP->getVpsNumBspHrdParametersMinus1( ), "vps_num_bsp_hrd_parameters_minus1" );
+  for( Int i = 0; i <= vpsVuiBspHrdP->getVpsNumBspHrdParametersMinus1( ); i++ )
+  {  
+    if( i > 0 )
+    {
+      WRITE_FLAG( vpsVuiBspHrdP->getBspCprmsPresentFlag( i ) ? 1 : 0 , "bsp_cprms_present_flag" );
+    }
+    TComHRD* hrdParameters = vpsVuiBspHrdP->getHrdParametermeters( i ); 
+    codeHrdParameters( hrdParameters, vpsVuiBspHrdP->getBspCprmsPresentFlag( i ), pcVPS->getMaxSubLayersMinus1() );     
+  }  
+  for( Int h = 1; h <= pcVPS->getVpsNumLayerSetsMinus1(); h++ )
+  {  
+    WRITE_UVLC( vpsVuiBspHrdP->getNumBitstreamPartitions( h ), "num_bitstream_partitions" );
+    for( Int i = 0; i < vpsVuiBspHrdP->getNumBitstreamPartitions( h ); i++ )  
+    {
+      for( Int j = 0; j <= pcVPS->getMaxLayersMinus1(); j++ )  
+      {
+        if( pcVPS->getLayerIdIncludedFlag( h ,j ) )
+        {
+          WRITE_FLAG( vpsVuiBspHrdP->getLayerInBspFlag( h, i, j ) ? 1 : 0 , "layer_in_bsp_flag" );
+        }
+        else
+        {
+          vpsVuiBspHrdP->setLayerInBspFlag( h, i, j, false ); // This inference seems to be missing in spec 
+        }
+      }
+    }
+    vpsVuiBspHrdP->checkLayerInBspFlag( pcVPS, h ); 
+
+    if( vpsVuiBspHrdP->getNumBitstreamPartitions( h ) )
+    {  
+      WRITE_UVLC( vpsVuiBspHrdP->getNumBspSchedCombinations( h ), "num_bsp_sched_combinations" );
+      for( Int i = 0; i < vpsVuiBspHrdP->getNumBspSchedCombinations( h ); i++ )
+      {
+        for( Int j = 0; j < vpsVuiBspHrdP->getNumBitstreamPartitions( h ); j++ )
+        {  
+          WRITE_UVLC( vpsVuiBspHrdP->getBspCombHrdIdx( h, i, j ), "bsp_comb_hrd_idx" );
+          WRITE_UVLC( vpsVuiBspHrdP->getBspCombSchedIdx( h, i, j ), "bsp_comb_sched_idx" );
+        }  
+      }
+    }  
+  }  
+}  
+#endif
+
 #endif
 
@@ -1115,4 +1537,5 @@
 #if H_MV    
     Int esb = 0;  //Don't use i, otherwise will shadow something below
+#if !H_MV_6_RALS_O0149_11
     if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
     {
@@ -1120,4 +1543,5 @@
       WRITE_FLAG( pcSlice->getPocResetFlag( ) ? 1 : 0 , "poc_reset_flag" );
     }
+#endif
 
     if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
@@ -1126,4 +1550,21 @@
       WRITE_FLAG( pcSlice->getDiscardableFlag( ) ? 1 : 0 , "discardable_flag" );
     }
+
+#if H_MV_6_RALS_O0149_11
+    if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
+    {
+      esb++; 
+      WRITE_FLAG( pcSlice->getCrossLayerBlaFlag( ) ? 1 : 0 , "cross_layer_bla_flag" );
+    }
+    pcSlice->checkCrossLayerBlaFlag( ); 
+
+    if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
+    {
+      esb++; 
+      WRITE_FLAG( pcSlice->getPocResetFlag( ) ? 1 : 0 , "poc_reset_flag" );
+    }
+#endif
+
+
 
     for (; esb < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); esb++)    
@@ -1148,8 +1589,17 @@
     //   colour_plane_id                                      u(2)
 
+#if H_MV_6_POC_31_35_38
+    if ( (pcSlice->getLayerId() > 0 && !vps->getPocLsbNotPresentFlag( pcSlice->getLayerIdInVps())) || !pcSlice->getIdrPicFlag() )
+    {
+      Int picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC())) & ((1<<pcSlice->getSPS()->getBitsForPOC())-1);
+      WRITE_CODE( picOrderCntLSB, pcSlice->getSPS()->getBitsForPOC(), "slice_pic_order_cnt_lsb");
+    }
+#endif
     if( !pcSlice->getIdrPicFlag() )
     {
+#if !H_MV_6_POC_31_35_38
       Int picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC())) & ((1<<pcSlice->getSPS()->getBitsForPOC())-1);
       WRITE_CODE( picOrderCntLSB, pcSlice->getSPS()->getBitsForPOC(), "pic_order_cnt_lsb");
+#endif
       TComReferencePictureSet* rps = pcSlice->getRPS();
       
@@ -1265,4 +1715,7 @@
     }
 #if H_MV
+#if H_MV_6_ILDDS_ILREFPICS_27_34
+    Bool interLayerPredLayerIdcPresentFlag = false; 
+#endif
     Int layerId = pcSlice->getLayerId(); 
     if( pcSlice->getLayerId() > 0 && !vps->getAllRefLayersActiveFlag() && vps->getNumDirectRefLayers( layerId ) > 0 )
@@ -1276,5 +1729,8 @@
         }
         if ( pcSlice->getNumActiveRefLayerPics() != vps->getNumDirectRefLayers( layerId ) )
-        {        
+        {
+#if H_MV_6_ILDDS_ILREFPICS_27_34
+          interLayerPredLayerIdcPresentFlag = true; 
+#endif
           for( Int idx = 0; idx < pcSlice->getNumActiveRefLayerPics(); idx++ )   
           {
@@ -1284,4 +1740,13 @@
       }  
     }
+#if H_MV_6_ILDDS_ILREFPICS_27_34
+    if ( !interLayerPredLayerIdcPresentFlag )
+    {
+      for( Int i = 0; i < pcSlice->getNumActiveRefLayerPics(); i++ )   
+      {
+        assert( pcSlice->getInterLayerPredLayerIdc( i ) == pcSlice->getRefLayerPicIdc( i ) );
+      }
+    }
+#endif
 #endif
     if(pcSlice->getSPS()->getUseSAO())
Index: branches/HTM-9.0-dev0/source/Lib/TLibEncoder/TEncCavlc.h
===================================================================
--- branches/HTM-9.0-dev0/source/Lib/TLibEncoder/TEncCavlc.h	(revision 729)
+++ branches/HTM-9.0-dev0/source/Lib/TLibEncoder/TEncCavlc.h	(revision 730)
@@ -85,7 +85,22 @@
   Void  codeVPS                 ( TComVPS* pcVPS );
 #if H_MV
-  Void  codeVPSExtension       ( TComVPS *pcVPS );
-  Void  codeRepFormat          ( TComRepFormat* pcRepFormat );
-  Void  codeVPSVUI             ( TComVPS* pcVPS );
+  Void  codeVPSExtension        ( TComVPS *pcVPS );
+#if H_MV_6_PS_O0118_33
+  Void  codeVideoSignalInfo     ( TComVideoSignalInfo* pcVideoSignalInfo ); 
+#endif
+
+#if H_MV_6_HRD_O0217_13
+  Void  codeDpbSize   ( TComVPS* vps );
+#endif
+
+#if H_MV_6_PS_REP_FORM_18_19_20
+  Void  codeRepFormat           ( Int i, TComRepFormat* curRepFormat, TComRepFormat* prevRepFormat );
+#else
+  Void  codeRepFormat           ( TComRepFormat* pcRepFormat );
+#endif
+  Void  codeVPSVUI              ( TComVPS* pcVPS );
+#if H_MV_6_HRD_O0164_15
+  Void  codeVpsVuiBspHrdParameters( TComVPS* pcVPS ); 
+#endif
 #endif 
   Void  codeVUI                 ( TComVUI *pcVUI, TComSPS* pcSPS );
Index: branches/HTM-9.0-dev0/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- branches/HTM-9.0-dev0/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 729)
+++ branches/HTM-9.0-dev0/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 730)
@@ -664,5 +664,9 @@
     refPicListModification->setRefPicListModificationFlagL1(0);
 #if H_MV
+#if H_MV_6_RALS_O0149_11
+    if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > 0 )
+#else
     if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > 1 )
+#endif
     {
       // Some more sophisticated algorithm to determine discardable_flag might be added here. 
@@ -673,5 +677,8 @@
     Int numDirectRefLayers = vps    ->getNumDirectRefLayers( getLayerId() ); 
     GOPEntry gopEntry      = m_pcCfg->getGOPEntry( (pcSlice->getRapPicFlag() && getLayerId() > 0) ? MAX_GOP : iGOPid );     
-    
+
+#if H_MV_6_ILDDS_ILREFPICS_27_34
+    Bool interLayerPredLayerIdcPresentFlag = false; 
+#endif
     if ( getLayerId() > 0 && !vps->getAllRefLayersActiveFlag() && numDirectRefLayers > 0 )
     {         
@@ -685,4 +692,7 @@
         if ( gopEntry.m_numActiveRefLayerPics != vps->getNumDirectRefLayers( getLayerId() ) )
         {        
+#if H_MV_6_ILDDS_ILREFPICS_27_34
+          interLayerPredLayerIdcPresentFlag = true; 
+#endif
           for (Int i = 0; i < gopEntry.m_numActiveRefLayerPics; i++ )
           {
@@ -692,4 +702,15 @@
       }
     }
+#if H_MV_6_ILDDS_ILREFPICS_27_34
+    if ( !interLayerPredLayerIdcPresentFlag )
+    {
+      for( Int i = 0; i < pcSlice->getNumActiveRefLayerPics(); i++ )   
+      {
+        pcSlice->setInterLayerPredLayerIdc(i, pcSlice->getRefLayerPicIdc( i ) );
+      }
+    }
+#endif
+
+
     assert( pcSlice->getNumActiveRefLayerPics() == gopEntry.m_numActiveRefLayerPics ); 
     
Index: branches/HTM-9.0-dev0/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- branches/HTM-9.0-dev0/source/Lib/TLibEncoder/TEncTop.cpp	(revision 729)
+++ branches/HTM-9.0-dev0/source/Lib/TLibEncoder/TEncTop.cpp	(revision 730)
@@ -719,7 +719,18 @@
 
 #if H_MV  
+#if H_MV_6_PS_REP_FORM_18_19_20
+  m_cSPS.setUpdateRepFormatFlag           ( false );    
+#else
   m_cSPS.setUpdateRepFormatFlag           ( m_layerId == 0 );    
+#endif
   m_cSPS.setSpsInferScalingListFlag       ( m_layerId > 0 && m_cVPS->getInDirectDependencyFlag( getLayerIdInVps(), 0 ) ); 
   m_cSPS.setSpsScalingListRefLayerId      ( 0              ); 
+#if H_MV_6_PSEM_O0142_3
+  m_cSPS.setSpsExtensionFlag              ( true ); 
+  m_cSPS.setSpsExtensionTypeFlag          ( PS_EX_T_MV ,true ); 
+#if H_3D
+  m_cSPS.setSpsExtensionTypeFlag          ( PS_EX_T_3D ,true ); 
+#endif
+#endif
 #endif
   m_cSPS.setPicWidthInLumaSamples         ( m_iSourceWidth      );
@@ -808,5 +819,9 @@
     pcVUI->setOverscanInfoPresentFlag(getOverscanInfoPresentFlag());
     pcVUI->setOverscanAppropriateFlag(getOverscanAppropriateFlag());
+#if H_MV_6_PS_O0118_33
+    pcVUI->setVideoSignalTypePresentFlag(getVideoSignalTypePresentFlag() && getLayerId() == 0 );
+#else
     pcVUI->setVideoSignalTypePresentFlag(getVideoSignalTypePresentFlag());
+#endif
     pcVUI->setVideoFormat(getVideoFormat());
     pcVUI->setVideoFullRangeFlag(getVideoFullRangeFlag());
@@ -922,5 +937,9 @@
   m_cPPS.setOutputFlagPresentFlag( false );
 #if H_MV
+#if H_MV_6_RALS_O0149_11
+  m_cPPS.setNumExtraSliceHeaderBits( 3 ); 
+#else
   m_cPPS.setNumExtraSliceHeaderBits( 2 ); 
+#endif
 #endif
   m_cPPS.setSignHideFlag(getSignHideFlag());
