Index: trunk/source/Lib/TLibEncoder/SEIwrite.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/SEIwrite.cpp	(revision 595)
+++ trunk/source/Lib/TLibEncoder/SEIwrite.cpp	(revision 644)
@@ -105,7 +105,18 @@
 #endif
 #if SUB_BITSTREAM_PROPERTY_SEI
-    case SEI::SUB_BITSTREAM_PROPERTY:
-      fprintf( g_hTrace, "=========== Sub-bitstream property SEI message ===========\n");
-      break;
+  case SEI::SUB_BITSTREAM_PROPERTY:
+    fprintf( g_hTrace, "=========== Sub-bitstream property SEI message ===========\n");
+    break;
+#endif
+#if O0164_MULTI_LAYER_HRD
+  case SEI::BSP_NESTING:
+    fprintf( g_hTrace, "=========== Bitstream partition nesting SEI message ===========\n");
+    break;
+  case SEI::BSP_INITIAL_ARRIVAL_TIME:
+    fprintf( g_hTrace, "=========== Bitstream parition initial arrival time SEI message ===========\n");
+    break;
+  case SEI::BSP_HRD:
+    fprintf( g_hTrace, "=========== Bitstream parition HRD parameters SEI message ===========\n");
+    break;
 #endif
 #endif //SVC_EXTENSION
@@ -117,5 +128,9 @@
 #endif
 
+#if O0164_MULTI_LAYER_HRD
+void SEIWriter::xWriteSEIpayloadData(TComBitIf& bs, const SEI& sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting& nestingSei, const SEIBspNesting& bspNestingSei)
+#else
 void SEIWriter::xWriteSEIpayloadData(TComBitIf& bs, const SEI& sei, TComSPS *sps)
+#endif
 {
   switch (sei.payloadType())
@@ -161,5 +176,9 @@
     break;
   case SEI::SCALABLE_NESTING:
+#if O0164_MULTI_LAYER_HRD
+    xWriteSEIScalableNesting(bs, *static_cast<const SEIScalableNesting*>(&sei), vps, sps);
+#else
     xWriteSEIScalableNesting(bs, *static_cast<const SEIScalableNesting*>(&sei), sps);
+#endif
     break;
 #if SVC_EXTENSION
@@ -179,4 +198,15 @@
      break;
 #endif
+#if O0164_MULTI_LAYER_HRD
+   case SEI::BSP_NESTING:
+     xWriteSEIBspNesting(bs, *static_cast<const SEIBspNesting*>(&sei), vps, sps, nestingSei);
+     break;
+   case SEI::BSP_INITIAL_ARRIVAL_TIME:
+     xWriteSEIBspInitialArrivalTime(*static_cast<const SEIBspInitialArrivalTime*>(&sei), vps, sps, nestingSei, bspNestingSei);
+     break;
+   case SEI::BSP_HRD:
+     xWriteSEIBspHrd(*static_cast<const SEIBspHrd*>(&sei), sps, nestingSei);
+     break;
+#endif
 #endif //SVC_EXTENSION
   default:
@@ -189,5 +219,9 @@
  * in bitstream bs.
  */
+#if O0164_MULTI_LAYER_HRD
+Void SEIWriter::writeSEImessage(TComBitIf& bs, const SEI& sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting* nestingSei, const SEIBspNesting* bspNestingSei)
+#else
 Void SEIWriter::writeSEImessage(TComBitIf& bs, const SEI& sei, TComSPS *sps)
+#endif
 {
   /* calculate how large the payload data is */
@@ -202,5 +236,9 @@
   g_HLSTraceEnable = false;
 #endif
+#if O0164_MULTI_LAYER_HRD
+  xWriteSEIpayloadData(bs_count, sei, vps, sps, *nestingSei, *bspNestingSei);
+#else
   xWriteSEIpayloadData(bs_count, sei, sps);
+#endif
 #if ENC_DEC_TRACE
   g_HLSTraceEnable = traceEnable;
@@ -237,5 +275,9 @@
 #endif
 
+#if O0164_MULTI_LAYER_HRD
+  xWriteSEIpayloadData(bs, sei, vps, sps, *nestingSei, *bspNestingSei);
+#else
   xWriteSEIpayloadData(bs, sei, sps);
+#endif
 }
 
@@ -367,4 +409,10 @@
     }
   }
+#if P0138_USE_ALT_CPB_PARAMS_FLAG
+  if (sei.m_useAltCpbParamsFlagPresent)
+  {
+    WRITE_FLAG( sei.m_useAltCpbParamsFlag, "use_alt_cpb_params_flag");
+  }
+#endif
   xWriteByteAlign();
 }
@@ -571,5 +619,9 @@
 }
 
+#if O0164_MULTI_LAYER_HRD
+Void SEIWriter::xWriteSEIScalableNesting(TComBitIf& bs, const SEIScalableNesting& sei, TComVPS *vps, TComSPS *sps)
+#else
 Void SEIWriter::xWriteSEIScalableNesting(TComBitIf& bs, const SEIScalableNesting& sei, TComSPS *sps)
+#endif
 {
   WRITE_FLAG( sei.m_bitStreamSubsetFlag,             "bitstream_subset_flag"         );
@@ -581,5 +633,4 @@
     for (UInt i = (sei.m_defaultOpFlag ? 1 : 0); i <= sei.m_nestingNumOpsMinus1; i++)
     {
-      WRITE_CODE( sei.m_nestingNoOpMaxTemporalIdPlus1, 3, "nesting_no_op_max_temporal_id" );
       WRITE_CODE( sei.m_nestingMaxTemporalIdPlus1[i], 3,  "nesting_max_temporal_id"       );
       WRITE_UVLC( sei.m_nestingOpIdx[i],                  "nesting_op_idx"                );
@@ -609,5 +660,9 @@
   for (SEIMessages::const_iterator it = sei.m_nestedSEIs.begin(); it != sei.m_nestedSEIs.end(); it++)
   {
+#if O0164_MULTI_LAYER_HRD
+    writeSEImessage(bs, *(*it), vps, sps, &sei);
+#else
     writeSEImessage(bs, *(*it), sps);
+#endif
   }
 }
@@ -693,4 +748,178 @@
 }
 #endif
+
+#if O0164_MULTI_LAYER_HRD
+Void SEIWriter::xWriteSEIBspNesting(TComBitIf& bs, const SEIBspNesting &sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting &nestingSei)
+{
+  WRITE_UVLC( sei.m_bspIdx, "bsp_idx" );
+
+  while ( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 )
+  {
+    WRITE_FLAG( 0, "bsp_nesting_zero_bit" );
+  }
+
+  // write nested SEI messages
+  for (SEIMessages::const_iterator it = sei.m_nestedSEIs.begin(); it != sei.m_nestedSEIs.end(); it++)
+  {
+    writeSEImessage(bs, *(*it), vps, sps, &nestingSei, &sei);
+  }
+}
+
+Void SEIWriter::xWriteSEIBspInitialArrivalTime(const SEIBspInitialArrivalTime &sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting &nestingSei, const SEIBspNesting &bspNestingSei)
+{
+  assert(vps->getVpsVuiPresentFlag());
+
+  UInt schedCombCnt = vps->getNumBspSchedCombinations(nestingSei.m_nestingOpIdx[0]);
+  UInt len;
+  UInt hrdIdx;
+
+  if (schedCombCnt > 0)
+  {
+    hrdIdx = vps->getBspCombHrdIdx(nestingSei.m_nestingOpIdx[0], 0, bspNestingSei.m_bspIdx);
+  }
+  else
+  {
+    hrdIdx = 0;
+  }
+
+  TComHRD *hrd = vps->getBspHrd(hrdIdx);
+
+  if (hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag())
+  {
+    len = hrd->getInitialCpbRemovalDelayLengthMinus1() + 1;
+  }
+  else
+  {
+    len = 23 + 1;
+  }
+
+  if (hrd->getNalHrdParametersPresentFlag())
+  {
+    for(UInt i = 0; i < schedCombCnt; i++)
+    {
+      WRITE_CODE( sei.m_nalInitialArrivalDelay[i], len, "nal_initial_arrival_delay" );
+    }
+  }
+  else
+  {
+    for(UInt i = 0; i < schedCombCnt; i++)
+    {
+      WRITE_CODE( sei.m_vclInitialArrivalDelay[i], len, "vcl_initial_arrival_delay" );
+    }
+  }
+}
+
+Void SEIWriter::xWriteSEIBspHrd(const SEIBspHrd &sei, TComSPS *sps, const SEIScalableNesting &nestingSei)
+{
+  WRITE_UVLC( sei.m_seiNumBspHrdParametersMinus1, "sei_num_bsp_hrd_parameters_minus1" );
+  for (UInt i = 0; i <= sei.m_seiNumBspHrdParametersMinus1; i++)
+  {
+    if (i > 0)
+    {
+      WRITE_FLAG( sei.m_seiBspCprmsPresentFlag[i], "sei_bsp_cprms_present_flag" );
+    }
+    xCodeHrdParameters(sei.hrd, i==0 ? 1 : sei.m_seiBspCprmsPresentFlag[i], nestingSei.m_nestingMaxTemporalIdPlus1[0]-1);
+  }
+  for (UInt h = 0; h <= nestingSei.m_nestingNumOpsMinus1; h++)
+  {
+    UInt lsIdx = nestingSei.m_nestingOpIdx[h];
+    WRITE_UVLC( sei.m_seiNumBitstreamPartitionsMinus1[lsIdx], "num_sei_bitstream_partitions_minus1[i]");
+    for (UInt i = 0; i <= sei.m_seiNumBitstreamPartitionsMinus1[lsIdx]; i++)
+    {
+      for (UInt j = 0; j < sei.m_vpsMaxLayers; j++)
+      {
+        if (sei.m_layerIdIncludedFlag[lsIdx][j])
+        {
+          WRITE_FLAG( sei.m_seiLayerInBspFlag[lsIdx][i][j], "sei_layer_in_bsp_flag[lsIdx][i][j]" );
+        }
+      }
+    }
+    WRITE_UVLC( sei.m_seiNumBspSchedCombinationsMinus1[lsIdx], "sei_num_bsp_sched_combinations_minus1[i]");
+    for (UInt i = 0; i <= sei.m_seiNumBspSchedCombinationsMinus1[lsIdx]; i++)
+    {
+      for (UInt j = 0; j <= sei.m_seiNumBitstreamPartitionsMinus1[lsIdx]; j++)
+      {
+        WRITE_UVLC( sei.m_seiBspCombHrdIdx[lsIdx][i][j], "sei_bsp_comb_hrd_idx[lsIdx][i][j]");
+        WRITE_UVLC( sei.m_seiBspCombScheddx[lsIdx][i][j], "sei_bsp_comb_sched_idx[lsIdx][i][j]");
+      }
+    }
+  }
+}
+
+Void SEIWriter::xCodeHrdParameters( TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1 )
+{
+  if( commonInfPresentFlag )
+  {
+    WRITE_FLAG( hrd->getNalHrdParametersPresentFlag() ? 1 : 0 ,  "nal_hrd_parameters_present_flag" );
+    WRITE_FLAG( hrd->getVclHrdParametersPresentFlag() ? 1 : 0 ,  "vcl_hrd_parameters_present_flag" );
+    if( hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag() )
+    {
+      WRITE_FLAG( hrd->getSubPicCpbParamsPresentFlag() ? 1 : 0,  "sub_pic_cpb_params_present_flag" );
+      if( hrd->getSubPicCpbParamsPresentFlag() )
+      {
+        WRITE_CODE( hrd->getTickDivisorMinus2(), 8,              "tick_divisor_minus2" );
+        WRITE_CODE( hrd->getDuCpbRemovalDelayLengthMinus1(), 5,  "du_cpb_removal_delay_length_minus1" );
+        WRITE_FLAG( hrd->getSubPicCpbParamsInPicTimingSEIFlag() ? 1 : 0, "sub_pic_cpb_params_in_pic_timing_sei_flag" );
+        WRITE_CODE( hrd->getDpbOutputDelayDuLengthMinus1(), 5,   "dpb_output_delay_du_length_minus1"  );
+      }
+      WRITE_CODE( hrd->getBitRateScale(), 4,                     "bit_rate_scale" );
+      WRITE_CODE( hrd->getCpbSizeScale(), 4,                     "cpb_size_scale" );
+      if( hrd->getSubPicCpbParamsPresentFlag() )
+      {
+        WRITE_CODE( hrd->getDuCpbSizeScale(), 4,                "du_cpb_size_scale" ); 
+      }
+      WRITE_CODE( hrd->getInitialCpbRemovalDelayLengthMinus1(), 5, "initial_cpb_removal_delay_length_minus1" );
+      WRITE_CODE( hrd->getCpbRemovalDelayLengthMinus1(),        5, "au_cpb_removal_delay_length_minus1" );
+      WRITE_CODE( hrd->getDpbOutputDelayLengthMinus1(),         5, "dpb_output_delay_length_minus1" );
+    }
+  }
+  Int i, j, nalOrVcl;
+  for( i = 0; i <= maxNumSubLayersMinus1; i ++ )
+  {
+    WRITE_FLAG( hrd->getFixedPicRateFlag( i ) ? 1 : 0,          "fixed_pic_rate_general_flag");
+    if( !hrd->getFixedPicRateFlag( i ) )
+    {
+      WRITE_FLAG( hrd->getFixedPicRateWithinCvsFlag( i ) ? 1 : 0, "fixed_pic_rate_within_cvs_flag");
+    }
+    else
+    {
+      hrd->setFixedPicRateWithinCvsFlag( i, true );
+    }
+    if( hrd->getFixedPicRateWithinCvsFlag( i ) )
+    {
+      WRITE_UVLC( hrd->getPicDurationInTcMinus1( i ),           "elemental_duration_in_tc_minus1");
+    }
+    else
+    {
+      WRITE_FLAG( hrd->getLowDelayHrdFlag( i ) ? 1 : 0,           "low_delay_hrd_flag");
+    }
+    if (!hrd->getLowDelayHrdFlag( i ))
+    {
+      WRITE_UVLC( hrd->getCpbCntMinus1( i ),                      "cpb_cnt_minus1");
+    }
+    
+    for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
+    {
+      if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
+          ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
+      {
+        for( j = 0; j <= ( hrd->getCpbCntMinus1( i ) ); j ++ )
+        {
+          WRITE_UVLC( hrd->getBitRateValueMinus1( i, j, nalOrVcl ), "bit_rate_value_minus1");
+          WRITE_UVLC( hrd->getCpbSizeValueMinus1( i, j, nalOrVcl ), "cpb_size_value_minus1");
+          if( hrd->getSubPicCpbParamsPresentFlag() )
+          {
+            WRITE_UVLC( hrd->getDuCpbSizeValueMinus1( i, j, nalOrVcl ), "cpb_size_du_value_minus1");  
+            WRITE_UVLC( hrd->getDuBitRateValueMinus1( i, j, nalOrVcl ), "bit_rate_du_value_minus1");
+          }
+          WRITE_FLAG( hrd->getCbrFlag( i, j, nalOrVcl ) ? 1 : 0, "cbr_flag");
+        }
+      }
+    }
+  }
+}
+
+#endif
+
 #endif //SVC_EXTENSION
 
Index: trunk/source/Lib/TLibEncoder/SEIwrite.h
===================================================================
--- trunk/source/Lib/TLibEncoder/SEIwrite.h	(revision 595)
+++ trunk/source/Lib/TLibEncoder/SEIwrite.h	(revision 644)
@@ -47,8 +47,16 @@
   virtual ~SEIWriter() {};
 
+#if O0164_MULTI_LAYER_HRD
+  void writeSEImessage(TComBitIf& bs, const SEI& sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting* nestingSei=NULL, const SEIBspNesting* bspNestingSei=NULL);
+#else
   void writeSEImessage(TComBitIf& bs, const SEI& sei, TComSPS *sps);
+#endif
 
 protected:
+#if O0164_MULTI_LAYER_HRD
+  Void xWriteSEIpayloadData(TComBitIf& bs, const SEI& sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting& nestingSei, const SEIBspNesting& bspNestingSei);
+#else
   Void xWriteSEIpayloadData(TComBitIf& bs, const SEI& sei, TComSPS *sps);
+#endif
   Void xWriteSEIuserDataUnregistered(const SEIuserDataUnregistered &sei);
   Void xWriteSEIActiveParameterSets(const SEIActiveParameterSets& sei);
@@ -65,5 +73,9 @@
   Void xWriteSEIToneMappingInfo(const SEIToneMappingInfo& sei);
   Void xWriteSEISOPDescription(const SEISOPDescription& sei);
+#if O0164_MULTI_LAYER_HRD
+  Void xWriteSEIScalableNesting(TComBitIf& bs, const SEIScalableNesting& sei, TComVPS *vps, TComSPS *sps);
+#else
   Void xWriteSEIScalableNesting(TComBitIf& bs, const SEIScalableNesting& sei, TComSPS *sps);
+#endif
   Void xWriteByteAlign();
 #if SVC_EXTENSION
@@ -77,4 +89,10 @@
   Void xWriteSEISubBitstreamProperty(const SEISubBitstreamProperty &sei);
 #endif
+#if O0164_MULTI_LAYER_HRD
+  Void xWriteSEIBspNesting(TComBitIf& bs, const SEIBspNesting &sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting &nestingSei);
+  Void xWriteSEIBspInitialArrivalTime(const SEIBspInitialArrivalTime &sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting &nestingSei, const SEIBspNesting &bspNestingSei);
+  Void xWriteSEIBspHrd(const SEIBspHrd &sei, TComSPS *sps, const SEIScalableNesting &nestingSei);
+  Void xCodeHrdParameters( TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1 );
+#endif
 #endif //SVC_EXTENSION
 };
Index: trunk/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 595)
+++ trunk/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 644)
@@ -251,5 +251,27 @@
   WRITE_UVLC( pcPPS->getLog2ParallelMergeLevelMinus2(), "log2_parallel_merge_level_minus2");
   WRITE_FLAG( pcPPS->getSliceHeaderExtensionPresentFlag() ? 1 : 0, "slice_segment_header_extension_present_flag");
+#if P0166_MODIFIED_PPS_EXTENSION
+  WRITE_FLAG( 1, "pps_extension_flag" );
+  if( 1 ) //pps_extension_flag
+  {
+#if !POC_RESET_IDC
+    UInt ppsExtensionTypeFlag[8] = { 0, 1, 0, 0, 0, 0, 0, 0 };
+#else
+    UInt ppsExtensionTypeFlag[8] = { 1, 0, 0, 0, 0, 0, 0, 0 };
+#endif
+    for (UInt i = 0; i < 8; i++)
+    {
+      WRITE_FLAG( ppsExtensionTypeFlag[i], "pps_extension_type_flag" );
+    }
+#if POC_RESET_IDC
+    if( ppsExtensionTypeFlag[0] )
+    {
+      WRITE_FLAG( pcPPS->getPocResetInfoPresentFlag() ? 1 : 0, "poc_reset_info_present_flag" );
+#endif
+    }
+  }
+#else
   WRITE_FLAG( 0, "pps_extension_flag" );
+#endif
 }
 
@@ -496,4 +518,8 @@
   WRITE_UVLC( pcSPS->getBitsForPOC()-4,                 "log2_max_pic_order_cnt_lsb_minus4" );
 
+#if SPS_DPB_PARAMS
+  if( pcSPS->getLayerId() == 0 )
+  {
+#endif
   const Bool subLayerOrderingInfoPresentFlag = 1;
   WRITE_FLAG(subLayerOrderingInfoPresentFlag,       "sps_sub_layer_ordering_info_present_flag");
@@ -508,4 +534,7 @@
     }
   }
+#if SPS_DPB_PARAMS
+  }
+#endif
   assert( pcSPS->getMaxCUWidth() == pcSPS->getMaxCUHeight() );
   
@@ -632,4 +661,7 @@
       WRITE_SVLC( scaledWindow.getWindowRightOffset()  >> 1, "scaled_ref_layer_right_offset" );
       WRITE_SVLC( scaledWindow.getWindowBottomOffset() >> 1, "scaled_ref_layer_bottom_offset" );
+#if P0312_VERT_PHASE_ADJ
+      WRITE_FLAG( scaledWindow.getVertPhasePositionEnableFlag(), "vert_phase_position_enable_flag" ); 
+#endif
     }
   }
@@ -776,4 +808,8 @@
 {
   // ... More syntax elements to be written here
+#if P0300_ALT_OUTPUT_LAYER_FLAG
+  Int NumOutputLayersInOutputLayerSet[MAX_VPS_LAYER_SETS_PLUS1];
+  Int OlsHighestOutputLayerId[MAX_VPS_LAYER_SETS_PLUS1];
+#endif
 #if VPS_EXTN_MASK_AND_DIM_INFO
   UInt i = 0, j = 0;
@@ -887,5 +923,5 @@
     if (vps->getMaxTSLayersPresentFlag())
     {
-        for( i = 0; i < vps->getMaxLayers() - 1; i++)
+        for( i = 0; i < vps->getMaxLayers(); i++)
         {
             WRITE_CODE(vps->getMaxTSLayersMinus1(i), 3, "sub_layers_vps_max_minus1[i]" );
@@ -993,5 +1029,9 @@
 #endif
       Int lsIdx = vps->getOutputLayerSetIdx(i);
+#if NUM_OL_FLAGS
+      for(j = 0; j < vps->getNumLayersInIdList(lsIdx) ; j++)
+#else
       for(j = 0; j < vps->getNumLayersInIdList(lsIdx) - 1; j++)
+#endif
       {
         WRITE_FLAG( vps->getOutputLayerFlag(i,j), "output_layer_flag[i][j]");
@@ -1004,6 +1044,23 @@
     }
     WRITE_CODE( vps->getProfileLevelTierIdx(i), numBits, "profile_level_tier_idx[i]" );     
-  }
-
+#if P0300_ALT_OUTPUT_LAYER_FLAG
+    NumOutputLayersInOutputLayerSet[i] = 0;
+    Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx(i);
+    for (j = 0; j < vps->getNumLayersInIdList(layerSetIdxForOutputLayerSet); j++)
+    {
+      NumOutputLayersInOutputLayerSet[i] += vps->getOutputLayerFlag(i, j);
+      if (vps->getOutputLayerFlag(i, j))
+      {
+        OlsHighestOutputLayerId[i] = vps->getLayerSetLayerIdList(layerSetIdxForOutputLayerSet, j);
+      }
+    }
+    if (NumOutputLayersInOutputLayerSet[i] == 1 && vps->getNumDirectRefLayers(OlsHighestOutputLayerId[i]) > 0)
+    {
+      WRITE_FLAG(vps->getAltOuputLayerFlag(i), "alt_output_layer_flag[i]");
+    }
+#endif
+  }
+
+#if !P0300_ALT_OUTPUT_LAYER_FLAG
 #if O0153_ALT_OUTPUT_LAYER_FLAG
   if( vps->getMaxLayers() > 1 )
@@ -1011,4 +1068,5 @@
     WRITE_FLAG( vps->getAltOuputLayerFlag(), "alt_output_layer_flag" );   
   }
+#endif
 #endif
 
@@ -1124,8 +1182,15 @@
 #if P0307_VPS_NON_VUI_EXTENSION
   WRITE_UVLC( vps->getVpsNonVuiExtLength(), "vps_non_vui_extension_length" );
+#if P0307_VPS_NON_VUI_EXT_UPDATE
+  for (i = 1; i <= vps->getVpsNonVuiExtLength(); i++)
+  {
+    WRITE_CODE(1, 8, "vps_non_vui_extension_data_byte");
+  }
+#else
   if ( vps->getVpsNonVuiExtLength() > 0 )
   {
     printf("\n\nUp to the current spec, the value of vps_non_vui_extension_length is supposed to be 0\n");
   }
+#endif
 #endif
 
@@ -1217,4 +1282,22 @@
 Void TEncCavlc::codeVpsDpbSizeTable(TComVPS *vps)
 {
+#if DPB_PARAMS_MAXTLAYERS
+    Int * MaxSubLayersInLayerSetMinus1 = new Int[vps->getNumOutputLayerSets()];
+    for(Int i = 1; i < vps->getNumOutputLayerSets(); i++)
+    {
+        UInt maxSLMinus1 = 0;
+#if CHANGE_NUMSUBDPB_IDX
+        Int optLsIdx = vps->getOutputLayerSetIdx( i );
+#else
+        Int optLsIdx = i;
+#endif
+        for(Int k = 0; k < vps->getNumLayersInIdList(optLsIdx); k++ ) {
+            Int  lId = vps->getLayerSetLayerIdList(optLsIdx, k);
+            maxSLMinus1 = max(maxSLMinus1, vps->getMaxTSLayersMinus1(vps->getLayerIdInVps(lId)));
+        }
+        MaxSubLayersInLayerSetMinus1[ i ] = maxSLMinus1;
+    }
+#endif
+    
   for(Int i = 1; i < vps->getNumOutputLayerSets(); i++)
   {
@@ -1222,6 +1305,10 @@
     Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx( i );
 #endif
-    WRITE_FLAG( vps->getSubLayerFlagInfoPresentFlag( i ), "sub_layer_flag_info_present_flag[i]");  
+    WRITE_FLAG( vps->getSubLayerFlagInfoPresentFlag( i ), "sub_layer_flag_info_present_flag[i]");
+#if DPB_PARAMS_MAXTLAYERS
+    for(Int j = 0; j <= MaxSubLayersInLayerSetMinus1[ i ]; j++)
+#else
     for(Int j = 0; j < vps->getMaxTLayers(); j++)
+#endif
     {
       if( j > 0 && vps->getSubLayerFlagInfoPresentFlag(i) )
@@ -1266,4 +1353,10 @@
 #if IRAP_ALIGN_FLAG_IN_VPS_VUI
     WRITE_FLAG(vps->getCrossLayerIrapAlignFlag(), "cross_layer_irap_aligned_flag");
+#if P0068_CROSS_LAYER_ALIGNED_IDR_ONLY_FOR_IRAP_FLAG
+    if(vps->getCrossLayerIrapAlignFlag())
+    {
+       WRITE_FLAG(vps->getCrossLayerAlignedIdrOnlyFlag(), "only_idr_for_IRAP_across_layers");
+    }
+#endif
 #endif 
 #if O0223_PICTURE_TYPES_ALIGN_FLAG
@@ -1375,4 +1468,7 @@
   WRITE_FLAG(vps->getHigherLayerIrapSkipFlag(), "higher_layer_irap_skip_flag" );
 #endif
+#endif
+#if P0312_VERT_PHASE_ADJ
+  WRITE_FLAG( vps->getVpsVuiVertPhaseInUseFlag(), "vps_vui_vert_phase_in_use_flag" );
 #endif
 #if N0160_VUI_EXT_ILP_REF
@@ -1424,4 +1520,62 @@
 #endif 
 #endif
+#if O0164_MULTI_LAYER_HRD
+    WRITE_FLAG(vps->getVpsVuiBspHrdPresentFlag(), "vps_vui_bsp_hrd_present_flag" );
+    if (vps->getVpsVuiBspHrdPresentFlag())
+    {
+      WRITE_UVLC( vps->getVpsNumBspHrdParametersMinus1(), "vps_num_bsp_hrd_parameters_minus1" );
+      for( i = 0; i <= vps->getVpsNumBspHrdParametersMinus1(); i++ )
+      {
+        if( i > 0 )
+        {
+          WRITE_FLAG( vps->getBspCprmsPresentFlag(i), "bsp_cprms_present_flag[i]" );
+        }
+        codeHrdParameters(vps->getBspHrd(i), i==0 ? 1 : vps->getBspCprmsPresentFlag(i), vps->getMaxTLayers()-1);
+      }
+      for( UInt h = 1; h <= (vps->getNumLayerSets()-1); h++ )
+      {
+        WRITE_UVLC( vps->getNumBitstreamPartitions(h), "num_bitstream_partitions[i]");
+        for( i = 0; i < vps->getNumBitstreamPartitions(h); i++ )
+        {
+          for( j = 0; j <= (vps->getMaxLayers()-1); j++ )
+          {
+            if (vps->getLayerIdIncludedFlag(h, j))
+            {
+              WRITE_FLAG( vps->getLayerInBspFlag(h, i, j), "layer_in_bsp_flag[h][i][j]" );
+            }
+          }
+        }
+        if (vps->getNumBitstreamPartitions(h))
+        {
+          WRITE_UVLC( vps->getNumBspSchedCombinations(h), "num_bsp_sched_combinations[h]");
+          for( i = 0; i < vps->getNumBspSchedCombinations(h); i++ )
+          {
+            for( j = 0; j < vps->getNumBitstreamPartitions(h); j++ )
+            {
+              WRITE_UVLC( vps->getBspCombHrdIdx(h, i, j), "bsp_comb_hrd_idx[h][i][j]");
+              WRITE_UVLC( vps->getBspCombSchedIdx(h, i, j), "bsp_comb_sched_idx[h][i][j]");
+            }
+          }
+        }
+      }
+    }
+#endif
+#if P0182_VPS_VUI_PS_FLAG
+    for(i = 1; i < vps->getMaxLayers(); i++)
+    {
+      if(vps->getNumRefLayers(vps->getLayerIdInNuh(i)) == 0) 
+      {
+        if ((vps->getSPSId(i) == 0) && (vps->getPPSId(i) == 0))
+        {
+          vps->setBaseLayerPSCompatibilityFlag(i, 1);
+          WRITE_FLAG(vps->getBaseLayerPSCompatibilityFlag(i), "base_layer_parameter_set_compatibility_flag" );
+        }
+        else
+        {
+          vps->setBaseLayerPSCompatibilityFlag(i, 0);
+        }
+      }
+    }
+#endif
 }
 #endif
@@ -1458,5 +1612,9 @@
   if ( pcSlice->getRapPicFlag() )
   {
+#if NO_OUTPUT_OF_PRIOR_PICS
+    WRITE_FLAG( pcSlice->getNoOutputOfPriorPicsFlag(), "no_output_of_prior_pics_flag" );
+#else
     WRITE_FLAG( 0, "no_output_of_prior_pics_flag" );
+#endif
   }
   WRITE_UVLC( pcSlice->getPPS()->getPPSId(), "slice_pic_parameter_set_id" );
@@ -1690,10 +1848,10 @@
 #if ILP_SSH_SIG
 #if ILP_SSH_SIG_FIX
-    if((pcSlice->getSPS()->getLayerId() > 0) && !(pcSlice->getVPS()->getIlpSshSignalingEnabledFlag()) && (pcSlice->getNumILRRefIdx() > 0) )
-#else
-    if((pcSlice->getSPS()->getLayerId() > 0) && pcSlice->getVPS()->getIlpSshSignalingEnabledFlag() && (pcSlice->getNumILRRefIdx() > 0) )
-#endif
-#else
-    if((pcSlice->getSPS()->getLayerId() > 0)  &&  (pcSlice->getNumILRRefIdx() > 0) )
+    if((pcSlice->getLayerId() > 0) && !(pcSlice->getVPS()->getIlpSshSignalingEnabledFlag()) && (pcSlice->getNumILRRefIdx() > 0) )
+#else
+    if((pcSlice->getLayerId() > 0) && pcSlice->getVPS()->getIlpSshSignalingEnabledFlag() && (pcSlice->getNumILRRefIdx() > 0) )
+#endif
+#else
+    if((pcSlice->getLayerId() > 0)  &&  (pcSlice->getNumILRRefIdx() > 0) )
 #endif
     {
@@ -1726,4 +1884,14 @@
       }
     }     
+#if P0312_VERT_PHASE_ADJ
+    for(Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
+    {
+      UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
+      if( pcSlice->getSPS()->getVertPhasePositionEnableFlag(refLayerIdc) )
+      {
+        WRITE_FLAG( pcSlice->getVertPhasePositionFlag(refLayerIdc), "vert_phase_position_flag" );
+      }
+    }
+#endif
 #endif //SVC_EXTENSION
 
@@ -1886,8 +2054,11 @@
     }
   }
+
+#if !POC_RESET_IDC_SIGNALLING   // Wrong place to put slice header extension
   if(pcSlice->getPPS()->getSliceHeaderExtensionPresentFlag())
   {
     WRITE_UVLC(0,"slice_header_extension_length");
   }
+#endif
 }
 
@@ -2025,4 +2196,100 @@
 }
 
+#if POC_RESET_IDC_SIGNALLING
+Void  TEncCavlc::codeSliceHeaderExtn( TComSlice* slice, Int shBitsWrittenTillNow )
+{
+  Int tmpBitsBeforeWriting = getNumberOfWrittenBits();
+  if(slice->getPPS()->getSliceHeaderExtensionPresentFlag())
+  {
+    // Derive the value of PocMsbValRequiredFlag
+    slice->setPocMsbValRequiredFlag( slice->getCraPicFlag() || slice->getBlaPicFlag()
+                                          /* || related to vps_poc_lsb_aligned_flag */
+                                          );
+
+    // Determine value of SH extension length.
+    Int shExtnLengthInBit = 0;
+    if (slice->getPPS()->getPocResetInfoPresentFlag())
+    {
+      shExtnLengthInBit += 2;
+    }
+    if (slice->getPocResetIdc() > 0)
+    {
+      shExtnLengthInBit += 6;
+    }
+    if (slice->getPocResetIdc() == 3)
+    {
+      shExtnLengthInBit += (slice->getSPS()->getBitsForPOC() + 1);
+    }
+
+
+    if( !slice->getPocMsbValRequiredFlag() /* &&  vps_poc_lsb_aligned_flag */ )
+    {
+      shExtnLengthInBit++;
+    }
+    else
+    {
+      if( slice->getPocMsbValRequiredFlag() )
+      {
+        slice->setPocMsbValPresentFlag( true );
+      }
+      else
+      {
+        slice->setPocMsbValPresentFlag( false );
+      }
+    }
+
+    if( slice->getPocMsbValPresentFlag() )
+    {
+      UInt lengthVal = 1;
+      UInt tempVal = slice->getPocMsbVal() + 1;
+      assert ( tempVal );
+      while( 1 != tempVal )
+      {
+        tempVal >>= 1;
+        lengthVal += 2;
+      }
+      shExtnLengthInBit += lengthVal;
+    }
+    Int shExtnAdditionalBits = 0;
+    if(shExtnLengthInBit % 8 != 0)
+    {
+      shExtnAdditionalBits = 8 - (shExtnLengthInBit % 8);
+    }
+    Int shExtnLength = (shExtnLengthInBit + shExtnAdditionalBits) / 8;
+    WRITE_UVLC( shExtnLength, "slice_header_extension_length" );
+
+    if(slice->getPPS()->getPocResetInfoPresentFlag())
+    {
+      WRITE_CODE( slice->getPocResetIdc(), 2,                                 "poc_reset_idc");
+    }
+    if(slice->getPocResetIdc() > 0)
+    {
+      WRITE_CODE( slice->getPocResetPeriodId(), 6,                            "poc_reset_period_id");
+    }
+    if(slice->getPocResetIdc() == 3) 
+    {
+      WRITE_FLAG( slice->getFullPocResetFlag() ? 1 : 0,                       "full_poc_reset_flag");
+      WRITE_CODE( slice->getPocLsbVal(), slice->getSPS()->getBitsForPOC(),  "poc_lsb_val");
+    }
+
+    if( !slice->getPocMsbValRequiredFlag() /* &&  vps_poc_lsb_aligned_flag */ )
+    {
+      WRITE_FLAG( slice->getPocMsbValPresentFlag(),                           "poc_msb_val_present_flag" );
+    }
+    if( slice->getPocMsbValPresentFlag() )
+    {
+      WRITE_UVLC( slice->getPocMsbVal(),                                      "poc_msb_val" );
+    }
+    for (Int i = 0; i < shExtnAdditionalBits; i++)
+    {
+      WRITE_FLAG( 1, "slice_segment_header_extension_reserved_bit");
+    }
+  }
+  shBitsWrittenTillNow += ( getNumberOfWrittenBits() - tmpBitsBeforeWriting );
+  
+  // Slice header byte_alignment() included in xAttachSliceDataToNalUnit
+}
+#endif
+
 Void TEncCavlc::codeTerminatingBit      ( UInt uilsLast )
 {
Index: trunk/source/Lib/TLibEncoder/TEncCavlc.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCavlc.h	(revision 595)
+++ trunk/source/Lib/TLibEncoder/TEncCavlc.h	(revision 644)
@@ -96,9 +96,16 @@
   Void  codeHrdParameters       ( TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1 );
   Void  codeTilesWPPEntryPoint( TComSlice* pSlice );
+#if POC_RESET_IDC_SIGNALLING
+  Void  codeSliceHeaderExtn( TComSlice* slice, Int shBitsWrittenTillNow );
+#endif
   Void  codeTerminatingBit      ( UInt uilsLast );
   Void  codeSliceFinish         ();
   
   Void codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList );
+#if SVC_EXTENSION
+  Void codeSAOBlkParam(SAOBlkParam& saoBlkParam, UInt* saoMaxOffsetQVal, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail, Bool onlyEstMergeInfo = false){printf("only supported in CABAC"); assert(0); exit(-1);}
+#else
   Void codeSAOBlkParam(SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail, Bool onlyEstMergeInfo = false){printf("only supported in CABAC"); assert(0); exit(-1);}
+#endif
   Void codeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx );
   Void codeSkipFlag      ( TComDataCU* pcCU, UInt uiAbsPartIdx );
Index: trunk/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCfg.h	(revision 595)
+++ trunk/source/Lib/TLibEncoder/TEncCfg.h	(revision 644)
@@ -386,5 +386,9 @@
 
   Window   &getConformanceWindow()                           { return m_conformanceWindow; }
+#if P0312_VERT_PHASE_ADJ 
+  Void      setConformanceWindow (Int confLeft, Int confRight, Int confTop, Int confBottom ) { m_conformanceWindow.setWindow (confLeft, confRight, confTop, confBottom, false); }
+#else
   Void      setConformanceWindow (Int confLeft, Int confRight, Int confTop, Int confBottom ) { m_conformanceWindow.setWindow (confLeft, confRight, confTop, confBottom); }
+#endif
 
   Void      setFramesToBeEncoded            ( Int   i )      { m_framesToBeEncoded = i; }
Index: trunk/source/Lib/TLibEncoder/TEncEntropy.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 595)
+++ trunk/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 644)
@@ -60,4 +60,11 @@
 }
 
+#if POC_RESET_IDC_SIGNALLING
+Void  TEncEntropy::encodeSliceHeaderExtn( TComSlice* pSlice, Int shBitsWrittenTillNow )
+{
+  m_pcEntropyCoderIf->codeSliceHeaderExtn( pSlice, shBitsWrittenTillNow );
+}
+#endif
+
 Void TEncEntropy::encodeTerminatingBit      ( UInt uiIsLast )
 {
Index: trunk/source/Lib/TLibEncoder/TEncEntropy.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncEntropy.h	(revision 595)
+++ trunk/source/Lib/TLibEncoder/TEncEntropy.h	(revision 644)
@@ -74,4 +74,7 @@
 
   virtual Void  codeTilesWPPEntryPoint  ( TComSlice* pSlice )     = 0;
+#if POC_RESET_IDC_SIGNALLING
+  virtual Void  codeSliceHeaderExtn     ( TComSlice* pSlice, Int shBitsWrittenTillNow )     = 0;
+#endif
   virtual Void  codeTerminatingBit      ( UInt uilsLast )                                       = 0;
   virtual Void  codeSliceFinish         ()                                                      = 0;
@@ -105,5 +108,9 @@
   virtual Void codeCoeffNxN      ( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) = 0;
   virtual Void codeTransformSkipFlags ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, TextType eTType ) = 0;
+#if SVC_EXTENSION
+  virtual Void codeSAOBlkParam(SAOBlkParam& saoBlkParam, UInt* saoMaxOffsetQVal, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail, Bool onlyEstMergeInfo = false)    =0;
+#else
   virtual Void codeSAOBlkParam(SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail, Bool onlyEstMergeInfo = false)    =0;
+#endif
   virtual Void estBit               (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType) = 0;
   
@@ -138,4 +145,7 @@
   Void    encodeSliceHeader         ( TComSlice* pcSlice );
   Void    encodeTilesWPPEntryPoint( TComSlice* pSlice );
+#if POC_RESET_IDC_SIGNALLING
+Void      encodeSliceHeaderExtn( TComSlice* pSlice, Int shBitsWrittenTillNow );
+#endif
   Void    encodeTerminatingBit      ( UInt uiIsLast );
   Void    encodeSliceFinish         ();
@@ -184,5 +194,9 @@
   
   Void estimateBit             ( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType);
+#if SVC_EXTENSION
+  Void encodeSAOBlkParam(SAOBlkParam& saoBlkParam, UInt* saoMaxOffsetQVal, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail){m_pcEntropyCoderIf->codeSAOBlkParam(saoBlkParam, saoMaxOffsetQVal, sliceEnabled, leftMergeAvail, aboveMergeAvail, false);}
+#else
   Void encodeSAOBlkParam(SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail){m_pcEntropyCoderIf->codeSAOBlkParam(saoBlkParam, sliceEnabled, leftMergeAvail, aboveMergeAvail, false);}
+#endif
   static Int countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize );
 
Index: trunk/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 595)
+++ trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 644)
@@ -303,5 +303,9 @@
     //nalu = NALUnit(NAL_UNIT_SEI); 
     m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
+#if O0164_MULTI_LAYER_HRD
+    m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, m_pcEncTop->getVPS(), sps); 
+#else
     m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); 
+#endif
     writeRBSPTrailingBits(nalu.m_Bitstream);
     accessUnit.push_back(new NALUnitEBSP(nalu));
@@ -316,5 +320,9 @@
     nalu = NALUnit(NAL_UNIT_PREFIX_SEI);
     m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
+#if O0164_MULTI_LAYER_HRD
+    m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, m_pcEncTop->getVPS(), sps);
+#else
     m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps);
+#endif
     writeRBSPTrailingBits(nalu.m_Bitstream);
     accessUnit.push_back(new NALUnitEBSP(nalu));
@@ -327,5 +335,9 @@
     nalu = NALUnit(NAL_UNIT_PREFIX_SEI); 
     m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
+#if O0164_MULTI_LAYER_HRD
+    m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, m_pcEncTop->getVPS(), sps); 
+#else
     m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); 
+#endif
     writeRBSPTrailingBits(nalu.m_Bitstream);
     accessUnit.push_back(new NALUnitEBSP(nalu));
@@ -338,5 +350,9 @@
     nalu = NALUnit(NAL_UNIT_PREFIX_SEI); 
     m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
+#if O0164_MULTI_LAYER_HRD
+    m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, m_pcEncTop->getVPS(), sps); 
+#else
     m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); 
+#endif
     writeRBSPTrailingBits(nalu.m_Bitstream);
     accessUnit.push_back(new NALUnitEBSP(nalu));
@@ -350,5 +366,9 @@
     SEILayersNotPresent *sei = xCreateSEILayersNotPresent ();
     m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
+#if O0164_MULTI_LAYER_HRD
+    m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, m_pcEncTop->getVPS(), sps); 
+#else
     m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); 
+#endif
     writeRBSPTrailingBits(nalu.m_Bitstream);
     accessUnit.push_back(new NALUnitEBSP(nalu));
@@ -364,5 +384,9 @@
     nalu = NALUnit(NAL_UNIT_PREFIX_SEI, 0, m_pcCfg->getNumLayer()-1); // For highest layer
     m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
+#if O0164_MULTI_LAYER_HRD
+    m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, m_pcEncTop->getVPS(), sps); 
+#else
     m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); 
+#endif
     writeRBSPTrailingBits(nalu.m_Bitstream);
     accessUnit.push_back(new NALUnitEBSP(nalu));
@@ -797,4 +821,11 @@
           Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
 #endif*/
+#if P0312_VERT_PHASE_ADJ
+          //when PhasePositionEnableFlag is equal to 1, set vertPhasePositionFlag to 0 if BL is top field and 1 if bottom
+          if( scalEL.getVertPhasePositionEnableFlag() )
+          {
+            pcSlice->setVertPhasePositionFlag( pcSlice->getPOC()%2, refLayerIdc );
+          }
+#endif
 #if O0215_PHASE_ALIGNMENT
 #if O0194_JOINT_US_BITSHIFT
@@ -928,4 +959,7 @@
       pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS(), pcSlice->isIRAP());
     }
+#if ALIGNED_BUMPING
+    pcSlice->checkLeadingPictureRestrictions(rcListPic);
+#endif
     pcSlice->applyReferencePictureSet(rcListPic, pcSlice->getRPS());
 
@@ -1716,4 +1750,28 @@
       xCreateLeadingSEIMessages(accessUnit, pcSlice->getSPS());
 
+#if O0164_MULTI_LAYER_HRD
+      if (pcSlice->getLayerId() == 0 && m_pcEncTop->getVPS()->getVpsVuiBspHrdPresentFlag())
+      {
+        nalu = NALUnit(NAL_UNIT_PREFIX_SEI, 0, 1);
+        m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
+        m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
+        SEIScalableNesting *scalableBspNestingSei = xCreateBspNestingSEI(pcSlice);
+        m_seiWriter.writeSEImessage(nalu.m_Bitstream, *scalableBspNestingSei, m_pcEncTop->getVPS(), pcSlice->getSPS());
+        writeRBSPTrailingBits(nalu.m_Bitstream);
+
+        UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit);
+        UInt offsetPosition = m_activeParameterSetSEIPresentInAU 
+          + m_bufferingPeriodSEIPresentInAU 
+          + m_pictureTimingSEIPresentInAU
+          + m_nestedPictureTimingSEIPresentInAU;  // Insert SEI after APS, BP and PT SEI
+        AccessUnit::iterator it;
+        for(j = 0, it = accessUnit.begin(); j < seiPositionInAu + offsetPosition; j++)
+        {
+          it++;
+        }
+        accessUnit.insert(it, new NALUnitEBSP(nalu));
+      }
+#endif
+
       m_bSeqFirst = false;
     }
@@ -1750,5 +1808,9 @@
       SOPDescriptionSEI.m_numPicsInSopMinus1 = i - 1;
 
+#if O0164_MULTI_LAYER_HRD
+      m_seiWriter.writeSEImessage( nalu.m_Bitstream, SOPDescriptionSEI, m_pcEncTop->getVPS(), pcSlice->getSPS());
+#else
       m_seiWriter.writeSEImessage( nalu.m_Bitstream, SOPDescriptionSEI, pcSlice->getSPS());
+#endif
       writeRBSPTrailingBits(nalu.m_Bitstream);
       accessUnit.push_back(new NALUnitEBSP(nalu));
@@ -1834,5 +1896,9 @@
       sei_buffering_period.m_dpbDelayOffset = 0;
 
+#if O0164_MULTI_LAYER_HRD
+      m_seiWriter.writeSEImessage( nalu.m_Bitstream, sei_buffering_period, m_pcEncTop->getVPS(), pcSlice->getSPS());
+#else
       m_seiWriter.writeSEImessage( nalu.m_Bitstream, sei_buffering_period, pcSlice->getSPS());
+#endif
       writeRBSPTrailingBits(nalu.m_Bitstream);
       {
@@ -1855,5 +1921,9 @@
         scalableNestingSEI.m_nestedSEIs.clear();
         scalableNestingSEI.m_nestedSEIs.push_back(&sei_buffering_period);
+#if O0164_MULTI_LAYER_HRD
+        m_seiWriter.writeSEImessage( naluTmp.m_Bitstream, scalableNestingSEI, m_pcEncTop->getVPS(), pcSlice->getSPS());
+#else
         m_seiWriter.writeSEImessage( naluTmp.m_Bitstream, scalableNestingSEI, pcSlice->getSPS());
+#endif
         writeRBSPTrailingBits(naluTmp.m_Bitstream);
         UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit);
@@ -1884,5 +1954,9 @@
         seiGradualDecodingRefreshInfo.m_gdrForegroundFlag = true; // Indicating all "foreground"
 
+#if O0164_MULTI_LAYER_HRD
+        m_seiWriter.writeSEImessage( nalu.m_Bitstream, seiGradualDecodingRefreshInfo, m_pcEncTop->getVPS(), pcSlice->getSPS() );
+#else
         m_seiWriter.writeSEImessage( nalu.m_Bitstream, seiGradualDecodingRefreshInfo, pcSlice->getSPS() );
+#endif
         writeRBSPTrailingBits(nalu.m_Bitstream);
         accessUnit.push_back(new NALUnitEBSP(nalu));
@@ -1902,5 +1976,9 @@
       sei_recovery_point.m_brokenLinkFlag    = false;
 
+#if O0164_MULTI_LAYER_HRD
+      m_seiWriter.writeSEImessage( nalu.m_Bitstream, sei_recovery_point, m_pcEncTop->getVPS(), pcSlice->getSPS() );
+#else
       m_seiWriter.writeSEImessage( nalu.m_Bitstream, sei_recovery_point, pcSlice->getSPS() );
+#endif
       writeRBSPTrailingBits(nalu.m_Bitstream);
       accessUnit.push_back(new NALUnitEBSP(nalu));
@@ -2128,5 +2206,12 @@
             m_pcEntropyCoder->setEntropyCoder   ( m_pcCavlcCoder, pcSlice );
             m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
+#if !POC_RESET_IDC_SIGNALLING
             m_pcEntropyCoder->encodeTilesWPPEntryPoint( pcSlice );
+#else
+            tmpBitsBeforeWriting = m_pcEntropyCoder->getNumberOfWrittenBits();
+            m_pcEntropyCoder->encodeTilesWPPEntryPoint( pcSlice );
+            actualHeadBits += ( m_pcEntropyCoder->getNumberOfWrittenBits() - tmpBitsBeforeWriting );
+            m_pcEntropyCoder->encodeSliceHeaderExtn( pcSlice, actualHeadBits );
+#endif
 
             // Substreams...
@@ -2269,5 +2354,9 @@
         /* write the SEI messages */
         m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
+#if O0164_MULTI_LAYER_HRD
+        m_seiWriter.writeSEImessage(nalu.m_Bitstream, sei_recon_picture_digest, m_pcEncTop->getVPS(), pcSlice->getSPS());
+#else
         m_seiWriter.writeSEImessage(nalu.m_Bitstream, sei_recon_picture_digest, pcSlice->getSPS());
+#endif
         writeRBSPTrailingBits(nalu.m_Bitstream);
 
@@ -2293,5 +2382,9 @@
         /* write the SEI messages */
         m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
+#if O0164_MULTI_LAYER_HRD
+        m_seiWriter.writeSEImessage(nalu.m_Bitstream, sei_temporal_level0_index, m_pcEncTop->getVPS(), pcSlice->getSPS());
+#else
         m_seiWriter.writeSEImessage(nalu.m_Bitstream, sei_temporal_level0_index, pcSlice->getSPS());
+#endif
         writeRBSPTrailingBits(nalu.m_Bitstream);
 
@@ -2443,5 +2536,9 @@
           m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
           pictureTimingSEI.m_picStruct = (isField && pcSlice->getPic()->isTopField())? 1 : isField? 2 : 0;
+#if O0164_MULTI_LAYER_HRD
+          m_seiWriter.writeSEImessage(nalu.m_Bitstream, pictureTimingSEI, m_pcEncTop->getVPS(), pcSlice->getSPS());
+#else
           m_seiWriter.writeSEImessage(nalu.m_Bitstream, pictureTimingSEI, pcSlice->getSPS());
+#endif
           writeRBSPTrailingBits(nalu.m_Bitstream);
           UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit);
@@ -2462,5 +2559,9 @@
             scalableNestingSEI.m_nestedSEIs.clear();
             scalableNestingSEI.m_nestedSEIs.push_back(&pictureTimingSEI);
+#if O0164_MULTI_LAYER_HRD
+            m_seiWriter.writeSEImessage(nalu.m_Bitstream, scalableNestingSEI, m_pcEncTop->getVPS(), pcSlice->getSPS());
+#else
             m_seiWriter.writeSEImessage(nalu.m_Bitstream, scalableNestingSEI, pcSlice->getSPS());
+#endif
             writeRBSPTrailingBits(nalu.m_Bitstream);
             UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit);
@@ -2494,5 +2595,9 @@
             {
               // Insert before the first slice. 
+#if O0164_MULTI_LAYER_HRD
+              m_seiWriter.writeSEImessage(nalu.m_Bitstream, tempSEI, m_pcEncTop->getVPS(), pcSlice->getSPS());
+#else
               m_seiWriter.writeSEImessage(nalu.m_Bitstream, tempSEI, pcSlice->getSPS());
+#endif
               writeRBSPTrailingBits(nalu.m_Bitstream);
 
@@ -2516,5 +2621,9 @@
                 {
                   // Insert before the first slice. 
+#if O0164_MULTI_LAYER_HRD
+                  m_seiWriter.writeSEImessage(nalu.m_Bitstream, tempSEI, m_pcEncTop->getVPS(), pcSlice->getSPS());
+#else
                   m_seiWriter.writeSEImessage(nalu.m_Bitstream, tempSEI, pcSlice->getSPS());
+#endif
                   writeRBSPTrailingBits(nalu.m_Bitstream);
 
@@ -3652,4 +3761,71 @@
 }
 #endif
+
+#if O0164_MULTI_LAYER_HRD
+SEIScalableNesting* TEncGOP::xCreateBspNestingSEI(TComSlice *pcSlice)
+{
+  SEIScalableNesting *seiScalableNesting = new SEIScalableNesting();
+  SEIBspInitialArrivalTime *seiBspInitialArrivalTime = new SEIBspInitialArrivalTime();
+  SEIBspNesting *seiBspNesting = new SEIBspNesting();
+  SEIBufferingPeriod *seiBufferingPeriod = new SEIBufferingPeriod();
+
+  // Scalable nesting SEI
+
+  seiScalableNesting->m_bitStreamSubsetFlag           = 1;      // If the nested SEI messages are picture buffereing SEI mesages, picure timing SEI messages or sub-picture timing SEI messages, bitstream_subset_flag shall be equal to 1
+  seiScalableNesting->m_nestingOpFlag                 = 1;
+  seiScalableNesting->m_defaultOpFlag                 = 0;
+  seiScalableNesting->m_nestingNumOpsMinus1           = 0;      //nesting_num_ops_minus1
+  seiScalableNesting->m_nestingOpIdx[0]               = 1;
+  seiScalableNesting->m_allLayersFlag                 = 0;
+  seiScalableNesting->m_nestingNoOpMaxTemporalIdPlus1 = 6 + 1;  //nesting_no_op_max_temporal_id_plus1
+  seiScalableNesting->m_nestingNumLayersMinus1        = 1 - 1;  //nesting_num_layers_minus1
+  seiScalableNesting->m_nestingLayerId[0]             = 0;
+  seiScalableNesting->m_callerOwnsSEIs                = true;
+
+  // Bitstream partition nesting SEI
+
+  seiBspNesting->m_bspIdx = 0;
+  seiBspNesting->m_callerOwnsSEIs = true;
+
+  // Buffering period SEI
+
+  UInt uiInitialCpbRemovalDelay = (90000/2);                      // 0.5 sec
+  seiBufferingPeriod->m_initialCpbRemovalDelay      [0][0]     = uiInitialCpbRemovalDelay;
+  seiBufferingPeriod->m_initialCpbRemovalDelayOffset[0][0]     = uiInitialCpbRemovalDelay;
+  seiBufferingPeriod->m_initialCpbRemovalDelay      [0][1]     = uiInitialCpbRemovalDelay;
+  seiBufferingPeriod->m_initialCpbRemovalDelayOffset[0][1]     = uiInitialCpbRemovalDelay;
+
+  Double dTmp = (Double)pcSlice->getSPS()->getVuiParameters()->getTimingInfo()->getNumUnitsInTick() / (Double)pcSlice->getSPS()->getVuiParameters()->getTimingInfo()->getTimeScale();
+
+  UInt uiTmp = (UInt)( dTmp * 90000.0 ); 
+  uiInitialCpbRemovalDelay -= uiTmp;
+  uiInitialCpbRemovalDelay -= uiTmp / ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getTickDivisorMinus2() + 2 );
+  seiBufferingPeriod->m_initialAltCpbRemovalDelay      [0][0]  = uiInitialCpbRemovalDelay;
+  seiBufferingPeriod->m_initialAltCpbRemovalDelayOffset[0][0]  = uiInitialCpbRemovalDelay;
+  seiBufferingPeriod->m_initialAltCpbRemovalDelay      [0][1]  = uiInitialCpbRemovalDelay;
+  seiBufferingPeriod->m_initialAltCpbRemovalDelayOffset[0][1]  = uiInitialCpbRemovalDelay;
+
+  seiBufferingPeriod->m_rapCpbParamsPresentFlag              = 0;
+  //for the concatenation, it can be set to one during splicing.
+  seiBufferingPeriod->m_concatenationFlag = 0;
+  //since the temporal layer HRD is not ready, we assumed it is fixed
+  seiBufferingPeriod->m_auCpbRemovalDelayDelta = 1;
+  seiBufferingPeriod->m_cpbDelayOffset = 0;
+  seiBufferingPeriod->m_dpbDelayOffset = 0;
+
+  // Intial arrival time SEI message
+
+  seiBspInitialArrivalTime->m_nalInitialArrivalDelay[0] = 0;
+  seiBspInitialArrivalTime->m_vclInitialArrivalDelay[0] = 0;
+
+
+  seiBspNesting->m_nestedSEIs.push_back(seiBufferingPeriod);
+  seiBspNesting->m_nestedSEIs.push_back(seiBspInitialArrivalTime);
+  seiScalableNesting->m_nestedSEIs.push_back(seiBspNesting); // BSP nesting SEI is contained in scalable nesting SEI
+
+  return seiScalableNesting;
+}
+#endif
+
 #endif //SVC_EXTENSION
 
Index: trunk/source/Lib/TLibEncoder/TEncGOP.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncGOP.h	(revision 595)
+++ trunk/source/Lib/TLibEncoder/TEncGOP.h	(revision 644)
@@ -211,4 +211,7 @@
   SEIInterLayerConstrainedTileSets* xCreateSEIInterLayerConstrainedTileSets();
 #endif
+#if O0164_MULTI_LAYER_HRD
+  SEIScalableNesting* xCreateBspNestingSEI(TComSlice *pcSlice);
+#endif
 #endif //SVC_EXTENSION
 };// END CLASS DEFINITION TEncGOP
Index: trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp	(revision 595)
+++ trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp	(revision 644)
@@ -463,5 +463,9 @@
   Int bitDepth = (compIdx== SAO_Y) ? g_bitDepthY : g_bitDepthC;
   Int shift = 2 * DISTORTION_PRECISION_ADJUSTMENT(bitDepth-8);
+#if SVC_EXTENSION
+  Int offsetTh = getSaoMaxOffsetQVal()[compIdx];  //inclusive
+#else
   Int offsetTh = g_saoMaxOffsetQVal[compIdx];  //inclusive
+#endif
 
   ::memset(quantOffsets, 0, sizeof(Int)*MAX_NUM_SAO_CLASSES);
@@ -582,5 +586,9 @@
   modeParam[SAO_Y ].modeIdc = SAO_MODE_OFF;
   m_pcRDGoOnSbacCoder->load(cabacCoderRDO[inCabacLabel]);
+#if SVC_EXTENSION
+  m_pcRDGoOnSbacCoder->codeSAOBlkParam(modeParam, getSaoMaxOffsetQVal(), sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), true);
+#else
   m_pcRDGoOnSbacCoder->codeSAOBlkParam(modeParam, sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), true);
+#endif
   m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]);
 
@@ -590,5 +598,9 @@
   modeParam[compIdx].modeIdc = SAO_MODE_OFF;
   m_pcRDGoOnSbacCoder->resetBits();
+#if SVC_EXTENSION
+  m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, modeParam[compIdx], sliceEnabled[compIdx], getSaoMaxOffsetQVal());
+#else
   m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, modeParam[compIdx], sliceEnabled[compIdx]);
+#endif
   modeDist[compIdx] = 0;
   minCost= m_lambda[compIdx]*((Double)m_pcRDGoOnSbacCoder->getNumberOfWrittenBits());
@@ -613,5 +625,9 @@
       m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]);
       m_pcRDGoOnSbacCoder->resetBits();
+#if SVC_EXTENSION
+      m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, testOffset[compIdx], sliceEnabled[compIdx], getSaoMaxOffsetQVal());
+#else
       m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, testOffset[compIdx], sliceEnabled[compIdx]);
+#endif
       rate = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
       cost = (Double)dist[compIdx] + m_lambda[compIdx]*((Double)rate);
@@ -638,5 +654,9 @@
     modeDist [component] = 0;
 
+#if SVC_EXTENSION
+    m_pcRDGoOnSbacCoder->codeSAOOffsetParam(component, modeParam[component], sliceEnabled[component], getSaoMaxOffsetQVal());
+#else
     m_pcRDGoOnSbacCoder->codeSAOOffsetParam(component, modeParam[component], sliceEnabled[component]);
+#endif
 
     const UInt currentWrittenBits = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
@@ -672,5 +692,9 @@
       dist[compIdx]= getDistortion(ctu, compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, blkStats[ctu][compIdx][typeIdc]);
 
+#if SVC_EXTENSION
+      m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, testOffset[compIdx], sliceEnabled[compIdx], getSaoMaxOffsetQVal());
+#else
       m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, testOffset[compIdx], sliceEnabled[compIdx]);
+#endif
 
       const UInt currentWrittenBits = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
@@ -699,5 +723,9 @@
   m_pcRDGoOnSbacCoder->load(cabacCoderRDO[inCabacLabel]);
   m_pcRDGoOnSbacCoder->resetBits();
+#if SVC_EXTENSION
+  m_pcRDGoOnSbacCoder->codeSAOBlkParam(modeParam, getSaoMaxOffsetQVal(), sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), false);
+#else
   m_pcRDGoOnSbacCoder->codeSAOBlkParam(modeParam, sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), false);
+#endif
   modeNormCost += (Double)m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
 
@@ -742,5 +770,9 @@
     m_pcRDGoOnSbacCoder->load(cabacCoderRDO[inCabacLabel]);
     m_pcRDGoOnSbacCoder->resetBits();
+#if SVC_EXTENSION
+    m_pcRDGoOnSbacCoder->codeSAOBlkParam(testBlkParam, getSaoMaxOffsetQVal(), sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), false);
+#else
     m_pcRDGoOnSbacCoder->codeSAOBlkParam(testBlkParam, sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), false);
+#endif
     Int rate = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
 
Index: trunk/source/Lib/TLibEncoder/TEncSbac.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 595)
+++ trunk/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 644)
@@ -266,4 +266,11 @@
 }
 
+#if POC_RESET_IDC_SIGNALLING
+Void  TEncSbac::codeSliceHeaderExtn( TComSlice* pSlice, Int shBitsWrittenTillNow )
+{
+  assert (0);
+  return;
+}
+#endif
 Void TEncSbac::codeTerminatingBit( UInt uilsLast )
 {
@@ -1592,5 +1599,9 @@
 }
 
+#if SVC_EXTENSION
+Void TEncSbac::codeSAOOffsetParam(Int compIdx, SAOOffset& ctbParam, Bool sliceEnabled, UInt* saoMaxOffsetQVal)
+#else
 Void TEncSbac::codeSAOOffsetParam(Int compIdx, SAOOffset& ctbParam, Bool sliceEnabled)
+#endif
 {
   UInt uiSymbol;
@@ -1639,5 +1650,9 @@
     for(Int i=0; i< 4; i++)
     {
+#if SVC_EXTENSION
+      codeSaoMaxUvlc((offset[i]<0)?(-offset[i]):(offset[i]),  saoMaxOffsetQVal[compIdx] ); //sao_offset_abs
+#else
       codeSaoMaxUvlc((offset[i]<0)?(-offset[i]):(offset[i]),  g_saoMaxOffsetQVal[compIdx] ); //sao_offset_abs
+#endif
     }
 
@@ -1669,4 +1684,7 @@
 
 Void TEncSbac::codeSAOBlkParam(SAOBlkParam& saoBlkParam
+#if SVC_EXTENSION
+                              , UInt* saoMaxOffsetQVal
+#endif
                               , Bool* sliceEnabled
                               , Bool leftMergeAvail
@@ -1700,5 +1718,9 @@
     for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
     {
+#if SVC_EXTENSION
+      codeSAOOffsetParam(compIdx, saoBlkParam[compIdx], sliceEnabled[compIdx], saoMaxOffsetQVal);
+#else
       codeSAOOffsetParam(compIdx, saoBlkParam[compIdx], sliceEnabled[compIdx]);
+#endif
     }
   }
Index: trunk/source/Lib/TLibEncoder/TEncSbac.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSbac.h	(revision 595)
+++ trunk/source/Lib/TLibEncoder/TEncSbac.h	(revision 644)
@@ -95,4 +95,7 @@
   Void  codeSliceHeader         ( TComSlice* pcSlice );
   Void  codeTilesWPPEntryPoint( TComSlice* pSlice );
+#if POC_RESET_IDC_SIGNALLING
+  Void  codeSliceHeaderExtn     ( TComSlice* pSlice, Int shBitsWrittenTillNow );
+#endif
   Void  codeTerminatingBit      ( UInt uilsLast      );
   Void  codeSliceFinish         ();
@@ -104,4 +107,14 @@
   Void  codeScalingList      ( TComScalingList* /*scalingList*/     ){ assert (0);  return;};
 
+#if SVC_EXTENSION
+  Void codeSAOOffsetParam(Int compIdx, SAOOffset& ctbParam, Bool sliceEnabled, UInt* saoMaxOffsetQVal);
+  Void codeSAOBlkParam(SAOBlkParam& saoBlkParam
+                    , UInt* saoMaxOffsetQVal
+                    , Bool* sliceEnabled
+                    , Bool leftMergeAvail
+                    , Bool aboveMergeAvail
+                    , Bool onlyEstMergeInfo = false
+                    );
+#else
   Void codeSAOOffsetParam(Int compIdx, SAOOffset& ctbParam, Bool sliceEnabled);
   Void codeSAOBlkParam(SAOBlkParam& saoBlkParam
@@ -111,4 +124,5 @@
                     , Bool onlyEstMergeInfo = false
                     );
+#endif  
 
 private:
Index: trunk/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 595)
+++ trunk/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 644)
@@ -1356,5 +1356,9 @@
         }
 
+#if SVC_EXTENSION
+        m_pcEntropyCoder->encodeSAOBlkParam(saoblkParam, m_ppcTEncTop[pcSlice->getLayerId()]->getSAO()->getSaoMaxOffsetQVal(), sliceEnabled, leftMergeAvail, aboveMergeAvail);
+#else
         m_pcEntropyCoder->encodeSAOBlkParam(saoblkParam,sliceEnabled, leftMergeAvail, aboveMergeAvail);
+#endif
       }
     }
Index: trunk/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncTop.cpp	(revision 595)
+++ trunk/source/Lib/TLibEncoder/TEncTop.cpp	(revision 644)
@@ -791,5 +791,12 @@
           TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 );
 #endif
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+          UInt refLayerId = m_cVPS.getRefLayerId(m_layerId, i);
+          Bool sameBitDepths = ( g_bitDepthYLayer[m_layerId] == g_bitDepthYLayer[refLayerId] ) && ( g_bitDepthCLayer[m_layerId] == g_bitDepthCLayer[refLayerId] );
+
+          if( m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets || !sameBitDepths )
+#else
           if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets )
+#endif
           {
             pcEPic->setSpatialEnhLayerFlag( i, true );
@@ -846,5 +853,12 @@
           TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 );
 #endif
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+          UInt refLayerId = m_cVPS.getRefLayerId(m_layerId, i);
+          Bool sameBitDepths = ( g_bitDepthYLayer[m_layerId] == g_bitDepthYLayer[refLayerId] ) && ( g_bitDepthCLayer[m_layerId] == g_bitDepthCLayer[refLayerId] );
+
+          if( m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets || !sameBitDepths )
+#else
           if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets )
+#endif
           {
             rpcPic->setSpatialEnhLayerFlag( i, true );
@@ -902,4 +916,7 @@
 #endif
     m_cSPS.getScaledRefLayerWindow(i) = m_scaledRefLayerWindow[i];
+#if P0312_VERT_PHASE_ADJ
+    m_cSPS.setVertPhasePositionEnableFlag( m_scaledRefLayerId[i], m_scaledRefLayerWindow[i].getVertPhasePositionEnableFlag() );
+#endif
   }
 #endif //SVC_EXTENSION
Index: trunk/source/Lib/TLibEncoder/TEncTop.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncTop.h	(revision 595)
+++ trunk/source/Lib/TLibEncoder/TEncTop.h	(revision 644)
@@ -139,4 +139,7 @@
 #endif
   Window                  m_scaledRefLayerWindow[MAX_LAYERS];
+#if P0312_VERT_PHASE_ADJ
+  Bool                    m_vertPhasePositionEnableFlag[MAX_LAYERS];
+#endif
 #if POC_RESET_FLAG
   Int                     m_pocAdjustmentValue;
@@ -213,21 +216,26 @@
   /// encode several number of pictures until end-of-sequence
 #if SVC_EXTENSION
-  Void                    setLayerEnc(TEncTop** p) {m_ppcTEncTop = p;}
-  TEncTop**               getLayerEnc()            {return m_ppcTEncTop;}
-  Int                     getPOCLast            () { return m_iPOCLast;               }
-  Int                     getNumPicRcvd         () { return m_iNumPicRcvd;            }
-  Void                    setNumPicRcvd         ( Int num ) { m_iNumPicRcvd = num;      }
-  Void                    setNumScaledRefLayerOffsets(Int x) { m_numScaledRefLayerOffsets = x; }
-  UInt                    getNumScaledRefLayerOffsets() { return m_numScaledRefLayerOffsets; }
+  Void      setLayerEnc(TEncTop** p)            { m_ppcTEncTop = p;                  }
+  TEncTop** getLayerEnc()                       { return m_ppcTEncTop;               }
+  Int       getPOCLast            ()            { return m_iPOCLast;                 }
+  Int       getNumPicRcvd         ()            { return m_iNumPicRcvd;              }
+  Void      setNumPicRcvd         ( Int num )   { m_iNumPicRcvd = num;               }
+  Void      setNumScaledRefLayerOffsets(Int x)  { m_numScaledRefLayerOffsets = x;    }
+  UInt      getNumScaledRefLayerOffsets()       { return m_numScaledRefLayerOffsets; }
 #if O0098_SCALED_REF_LAYER_ID
-  Void                    setScaledRefLayerId(Int x, UInt id) { m_scaledRefLayerId[x] = id;   }
-  UInt                    getScaledRefLayerId(Int x)          { return m_scaledRefLayerId[x]; }
-  Window&  getScaledRefLayerWindowForLayer(Int layerId);
-#endif
-  Window&  getScaledRefLayerWindow(Int x)            { return m_scaledRefLayerWindow[x]; }
+  Void      setScaledRefLayerId(Int x, UInt id) { m_scaledRefLayerId[x] = id;   }
+  UInt      getScaledRefLayerId(Int x)          { return m_scaledRefLayerId[x]; }
+  Window&   getScaledRefLayerWindowForLayer(Int layerId);
+#endif
+  Window&   getScaledRefLayerWindow(Int x)                 { return m_scaledRefLayerWindow[x];        }
+#if P0312_VERT_PHASE_ADJ
+  Void      setVertPhasePositionEnableFlag(Int x, Bool b)  { m_vertPhasePositionEnableFlag[x] = b;    }
+  UInt      getVertPhasePositionEnableFlag(Int x)          { return m_vertPhasePositionEnableFlag[x]; }
+#endif
+
   TComPic** getIlpList() { return m_cIlpPic; }
 #if REF_IDX_MFM
-  Void      setMFMEnabledFlag       (Bool flag)   {m_bMFMEnabledFlag = flag;}
-  Bool      getMFMEnabledFlag()                   {return m_bMFMEnabledFlag;}    
+  Void      setMFMEnabledFlag       (Bool flag)   { m_bMFMEnabledFlag = flag; }
+  Bool      getMFMEnabledFlag()                   { return m_bMFMEnabledFlag; }    
 #endif
 #if O0194_WEIGHTED_PREDICTION_CGS
@@ -247,6 +255,6 @@
 #endif
 #if POC_RESET_FLAG
-  Int  getPocAdjustmentValue()      { return m_pocAdjustmentValue;}
-  Void setPocAdjustmentValue(Int x) { m_pocAdjustmentValue = x;   }
+  Int       getPocAdjustmentValue()      { return m_pocAdjustmentValue;}
+  Void      setPocAdjustmentValue(Int x) { m_pocAdjustmentValue = x;   }
 #endif
 #if NO_CLRAS_OUTPUT_FLAG
