Index: trunk/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 597)
+++ trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 644)
@@ -41,9 +41,8 @@
 #include <fcntl.h>
 #include <assert.h>
-
+#include <iostream>
 #include "TAppDecTop.h"
 #include "TLibDecoder/AnnexBread.h"
 #include "TLibDecoder/NALread.h"
-
 //! \ingroup TAppDecoder
 //! \{
@@ -255,4 +254,44 @@
         openedReconFile[curLayerId] = true;
       }
+#if ALIGNED_BUMPING
+      Bool outputPicturesFlag = true;  
+#if NO_OUTPUT_OF_PRIOR_PICS
+      if( m_acTDecTop[nalu.m_layerId].getNoOutputOfPriorPicsFlags() )
+      {
+        outputPicturesFlag = false;
+      }
+#endif
+
+      if (nalu.m_nalUnitType == NAL_UNIT_EOS) // End of sequence
+      {
+        flushAllPictures( nalu.m_layerId, outputPicturesFlag );       
+      }
+      if( bNewPicture ) // New picture, slice header parsed but picture not decoded
+      {
+#if NO_OUTPUT_OF_PRIOR_PICS
+        if( 
+#else
+        if ( bNewPOC &&
+#endif
+           (   nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL
+            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP
+            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP
+            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL
+            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP ) )
+        {
+          flushAllPictures( nalu.m_layerId, outputPicturesFlag );
+        }
+        else
+        {
+          this->checkOutputBeforeDecoding( nalu.m_layerId );
+        }
+      }
+
+      /* The following code has to be executed when the last DU of the picture is decoded
+         TODO: Need code to identify end of decoding a picture
+      {
+        this->checkOutputAfterDecoding( );
+      } */
+#else
       if ( bNewPicture && bNewPOC &&
            (   nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL
@@ -273,10 +312,15 @@
         xWriteOutput( pcListPic, curLayerId, nalu.m_temporalId );
       }
-    }
-  }
+#endif
+    }
+  }
+#if ALIGNED_BUMPING
+   flushAllPictures( true );   
+#else
   for(UInt layer = 0; layer <= m_tgtLayerId; layer++)
   {
     xFlushOutput( m_acTDecTop[layer].getListPic(), layer );
   }
+#endif
   // delete buffers
 #if AVC_BASE
@@ -987,4 +1031,403 @@
   return false;
 }
-
+#if ALIGNED_BUMPING
+// Function outputs a picture, and marks it as not needed for output.
+Void TAppDecTop::xOutputAndMarkPic( TComPic *pic, const Char *reconFile, const Int layerIdx, Int &pocLastDisplay, DpbStatus &dpbStatus )
+{
+  if ( reconFile )
+  {
+    const Window &conf = pic->getConformanceWindow();
+    const Window &defDisp = m_respectDefDispWindow ? pic->getDefDisplayWindow() : Window();
+    Int xScal =  1, yScal = 1;
+#if REPN_FORMAT_IN_VPS
+    UInt chromaFormatIdc = pic->getSlice(0)->getChromaFormatIdc();
+    xScal = TComSPS::getWinUnitX( chromaFormatIdc );
+    yScal = TComSPS::getWinUnitY( chromaFormatIdc );
+#endif
+    m_acTVideoIOYuvReconFile[layerIdx].write( pic->getPicYuvRec(),
+      conf.getWindowLeftOffset()  * xScal + defDisp.getWindowLeftOffset(),
+      conf.getWindowRightOffset() * xScal + defDisp.getWindowRightOffset(),
+      conf.getWindowTopOffset()   * yScal + defDisp.getWindowTopOffset(),
+      conf.getWindowBottomOffset()* yScal + defDisp.getWindowBottomOffset() );
+  }
+  // update POC of display order
+  pocLastDisplay = pic->getPOC();
+
+  // Mark as not needed for output
+  pic->setOutputMark(false);
+
+  // "erase" non-referenced picture in the reference picture list after display
+  if ( !pic->getSlice(0)->isReferenced() && pic->getReconMark() == true )
+  {
+    pic->setReconMark(false);
+
+    // mark it should be extended later
+    pic->getPicYuvRec()->setBorderExtension( false );
+
+    dpbStatus.m_numPicsInLayer[layerIdx]--;
+  }
+}
+
+Void TAppDecTop::flushAllPictures(Int layerId, Bool outputPictures)
+{
+  // First "empty" all pictures that are not used for reference and not needed for output
+  emptyUnusedPicturesNotNeededForOutput();
+
+  if( outputPictures )  // All pictures in the DPB in that layer are to be output; this means other pictures would also be output
+  {
+    std::vector<Int>  listOfPocs;
+    std::vector<Int>  listOfPocsInEachLayer[MAX_LAYERS];
+    std::vector<Int>  listOfPocsPositionInEachLayer[MAX_LAYERS];
+    DpbStatus dpbStatus;
+
+    // Find the status of the DPB
+    xFindDPBStatus(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus);
+
+    if( listOfPocs.size() )
+    {
+      while( listOfPocsInEachLayer[layerId].size() )    // As long as there picture in the layer to be output
+      {
+        bumpingProcess( listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus );
+      }
+    }
+  }
+
+  // Now remove all pictures from the layer DPB?
+  markAllPicturesAsErased(layerId);
+}
+Void TAppDecTop::flushAllPictures(Bool outputPictures)
+{
+  // First "empty" all pictures that are not used for reference and not needed for output
+  emptyUnusedPicturesNotNeededForOutput();
+
+  if( outputPictures )  // All pictures in the DPB are to be output
+  {
+    std::vector<Int>  listOfPocs;
+    std::vector<Int>  listOfPocsInEachLayer[MAX_LAYERS];
+    std::vector<Int>  listOfPocsPositionInEachLayer[MAX_LAYERS];
+    DpbStatus dpbStatus;
+
+    // Find the status of the DPB
+    xFindDPBStatus(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus);
+
+    while( dpbStatus.m_numAUsNotDisplayed )
+    {
+      bumpingProcess( listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus );
+    }
+  }
+
+  // Now remove all pictures from the DPB?
+  markAllPicturesAsErased();
+}
+
+Void TAppDecTop::markAllPicturesAsErased()
+{
+  for(Int i = 0; i < MAX_LAYERS; i++)
+  {
+    m_acTDecTop[i].getListPic()->clear();
+  }
+}
+
+Void TAppDecTop::markAllPicturesAsErased(Int layerIdx)
+{
+  m_acTDecTop[layerIdx].getListPic()->clear();
+}
+
+Void TAppDecTop::checkOutputBeforeDecoding(Int layerIdx)
+{
+    
+  std::vector<Int>  listOfPocs;
+  std::vector<Int>  listOfPocsInEachLayer[MAX_LAYERS];
+  std::vector<Int>  listOfPocsPositionInEachLayer[MAX_LAYERS];
+  DpbStatus dpbStatus;
+
+  // First "empty" all pictures that are not used for reference and not needed for output
+  emptyUnusedPicturesNotNeededForOutput();
+
+  // Find the status of the DPB
+  xFindDPBStatus(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus);
+
+  // If not picture to be output, return
+  if( listOfPocs.size() == 0 )
+  {
+    return;
+  }
+
+  // Find DPB-information from the VPS
+  DpbStatus maxDpbLimit;
+  Int targetLsIdx, subDpbIdx;
+  TComVPS *vps = findDpbParametersFromVps(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, maxDpbLimit);
+  if( getCommonDecoderParams()->getTargetOutputLayerSetIdx() == 0 )
+  {
+    targetLsIdx = 0;
+    subDpbIdx   = 0; 
+  }
+  else
+  {
+    targetLsIdx = vps->getOutputLayerSetIdx( getCommonDecoderParams()->getTargetOutputLayerSetIdx() );
+    subDpbIdx   = vps->getSubDpbAssigned( targetLsIdx, layerIdx );
+  }
+  // Assume that listOfPocs is sorted in increasing order - if not have to sort it.
+  while( ifInvokeBumpingBeforeDecoding(dpbStatus, maxDpbLimit, layerIdx, subDpbIdx) )
+  {
+    bumpingProcess( listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus );
+  }  
+}
+
+Void TAppDecTop::checkOutputAfterDecoding()
+{    
+  std::vector<Int>  listOfPocs;
+  std::vector<Int>  listOfPocsInEachLayer[MAX_LAYERS];
+  std::vector<Int>  listOfPocsPositionInEachLayer[MAX_LAYERS];
+  DpbStatus dpbStatus;
+
+  // First "empty" all pictures that are not used for reference and not needed for output
+  emptyUnusedPicturesNotNeededForOutput();
+
+  // Find the status of the DPB
+  xFindDPBStatus(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus);
+
+  // If not picture to be output, return
+  if( listOfPocs.size() == 0 )
+  {
+    return;
+  }
+
+  // Find DPB-information from the VPS
+  DpbStatus maxDpbLimit;
+  findDpbParametersFromVps(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, maxDpbLimit);
+
+  // Assume that listOfPocs is sorted in increasing order - if not have to sort it.
+  while( ifInvokeBumpingAfterDecoding(dpbStatus, maxDpbLimit) )
+  {
+    bumpingProcess( listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus );
+  }  
+}
+
+Void TAppDecTop::bumpingProcess(std::vector<Int> &listOfPocs, std::vector<Int> *listOfPocsInEachLayer, std::vector<Int> *listOfPocsPositionInEachLayer, DpbStatus &dpbStatus)
+{
+  // Choose the smallest POC value
+  Int pocValue = *(listOfPocs.begin());
+  std::vector<int>::iterator it;
+  TComList<TComPic*>::iterator iterPic;
+  for( Int layerIdx = 0; layerIdx < dpbStatus.m_numLayers; layerIdx++)
+  {
+    // Check if picture with pocValue is present.
+    it = find( listOfPocsInEachLayer[layerIdx].begin(), listOfPocsInEachLayer[layerIdx].end(), pocValue );
+    if( it != listOfPocsInEachLayer[layerIdx].end() )  // picture found.
+    {
+      Int picPosition = std::distance( listOfPocsInEachLayer[layerIdx].begin(), it );
+      Int j;
+      for(j = 0, iterPic = m_acTDecTop[layerIdx].getListPic()->begin(); j < listOfPocsPositionInEachLayer[layerIdx][picPosition]; j++) // Picture to be output
+      {
+        iterPic++;
+      }
+      TComPic *pic = *iterPic;
+
+      xOutputAndMarkPic( pic, m_pchReconFile[layerIdx], layerIdx, m_aiPOCLastDisplay[layerIdx], dpbStatus );
+
+      listOfPocsInEachLayer[layerIdx].erase( it );
+      listOfPocsPositionInEachLayer[layerIdx].erase( listOfPocsPositionInEachLayer[layerIdx].begin() + picPosition );
+    }
+  }
+  // Update sub-DPB status
+  for( Int subDpbIdx = 0; subDpbIdx < dpbStatus.m_numSubDpbs; subDpbIdx++)
+  {
+    dpbStatus.m_numPicsInSubDpb[subDpbIdx]--;
+  }
+  dpbStatus.m_numAUsNotDisplayed--;    
+
+  // Remove the picture from the listOfPocs
+  listOfPocs.erase( listOfPocs.begin() );
+}
+
+TComVPS *TAppDecTop::findDpbParametersFromVps(std::vector<Int> const &listOfPocs, std::vector<Int> const *listOfPocsInEachLayer, std::vector<Int> const *listOfPocsPositionInEachLayer, DpbStatus &maxDpbLimit)
+{
+  Int targetOutputLsIdx = getCommonDecoderParams()->getTargetOutputLayerSetIdx();
+  TComVPS *vps = NULL;
+
+  if( targetOutputLsIdx == 0 )   // Only base layer is output
+  {
+    TComSPS *sps = NULL;
+    assert( listOfPocsInEachLayer[0].size() != 0 );
+    TComList<TComPic*>::iterator iterPic;
+    Int j;
+    for(j = 0, iterPic = m_acTDecTop[0].getListPic()->begin(); j < listOfPocsPositionInEachLayer[0][0]; j++) // Picture to be output
+    {
+      iterPic++;
+    }
+    TComPic *pic = *iterPic;
+    sps = pic->getSlice(0)->getSPS();   assert( sps->getLayerId() == 0 );
+    vps = pic->getSlice(0)->getVPS();
+    Int highestTId = sps->getMaxTLayers() - 1;
+
+    maxDpbLimit.m_numAUsNotDisplayed = sps->getNumReorderPics( highestTId ); // m_numAUsNotDisplayed is only variable name - stores reorderpics
+    maxDpbLimit.m_maxLatencyIncrease = sps->getMaxLatencyIncrease( highestTId ) > 0;
+    if( maxDpbLimit.m_maxLatencyIncrease )
+    {
+      maxDpbLimit.m_maxLatencyPictures = sps->getMaxLatencyIncrease( highestTId ) + sps->getNumReorderPics( highestTId ) - 1;
+    }
+    maxDpbLimit.m_numPicsInLayer[0] = sps->getMaxDecPicBuffering( highestTId );
+    maxDpbLimit.m_numPicsInSubDpb[0] = sps->getMaxDecPicBuffering( highestTId );
+  }
+  else
+  {
+    // -------------------------------------
+    // Find the VPS used for the pictures
+    // -------------------------------------
+    for(Int i = 0; i < MAX_LAYERS; i++)
+    {
+      if( m_acTDecTop[i].getListPic()->empty() )
+      {
+        assert( listOfPocsInEachLayer[i].size() == 0 );
+        continue;
+      }
+      std::vector<Int>::const_iterator it;
+      it = find( listOfPocsInEachLayer[i].begin(), listOfPocsInEachLayer[i].end(), listOfPocs[0] );
+      TComList<TComPic*>::iterator iterPic;
+      if( it != listOfPocsInEachLayer[i].end() )
+      {
+        Int picPosition = std::distance( listOfPocsInEachLayer[i].begin(), it );
+        Int j;
+        for(j = 0, iterPic = m_acTDecTop[i].getListPic()->begin(); j < listOfPocsPositionInEachLayer[i][picPosition]; j++) // Picture to be output
+        {
+          iterPic++;
+        }
+        TComPic *pic = *iterPic;
+        vps = pic->getSlice(0)->getVPS();
+        break;
+      }
+    }
+
+    Int targetLsIdx       = vps->getOutputLayerSetIdx( getCommonDecoderParams()->getTargetOutputLayerSetIdx() );
+    Int highestTId = vps->getMaxTLayers() - 1;
+
+    maxDpbLimit.m_numAUsNotDisplayed = vps->getMaxVpsNumReorderPics( targetOutputLsIdx, highestTId ); // m_numAUsNotDisplayed is only variable name - stores reorderpics
+    maxDpbLimit.m_maxLatencyIncrease  = vps->getMaxVpsLatencyIncreasePlus1(targetOutputLsIdx, highestTId ) > 0;
+    if( maxDpbLimit.m_maxLatencyIncrease )
+    {
+      maxDpbLimit.m_maxLatencyPictures = vps->getMaxVpsNumReorderPics( targetOutputLsIdx, highestTId ) + vps->getMaxVpsLatencyIncreasePlus1(targetOutputLsIdx, highestTId ) - 1;
+    }
+    for(Int i = 0; i < vps->getNumLayersInIdList( targetLsIdx ); i++)
+    {
+      maxDpbLimit.m_numPicsInLayer[i] = vps->getMaxVpsLayerDecPicBuffMinus1( targetOutputLsIdx, i, highestTId ) + 1;
+      maxDpbLimit.m_numPicsInSubDpb[vps->getSubDpbAssigned( targetLsIdx, i )] = vps->getMaxVpsDecPicBufferingMinus1( targetOutputLsIdx, vps->getSubDpbAssigned( targetLsIdx, i ), highestTId) + 1;
+    }
+    // -------------------------------------
+  }
+  return vps;
+}
+Void TAppDecTop::emptyUnusedPicturesNotNeededForOutput()
+{
+  for(Int layerIdx = 0; layerIdx < MAX_LAYERS; layerIdx++)
+  {
+    TComList <TComPic*> *pcListPic = m_acTDecTop[layerIdx].getListPic();
+    TComList<TComPic*>::iterator iterPic = pcListPic->begin();
+    while ( iterPic != pcListPic->end() )
+    {
+      TComPic *pic = *iterPic;
+      if( !pic->getSlice(0)->isReferenced() && !pic->getOutputMark() )
+      {
+        // Emtpy the picture buffer
+        pic->setReconMark( false );
+      }
+      iterPic++;
+    }
+  }
+}
+
+Bool TAppDecTop::ifInvokeBumpingBeforeDecoding( const DpbStatus &dpbStatus, const DpbStatus &dpbLimit, const Int layerIdx, const Int subDpbIdx )
+{
+  Bool retVal = false;
+  // Number of reorder picutres
+  retVal |= ( dpbStatus.m_numAUsNotDisplayed > dpbLimit.m_numAUsNotDisplayed );
+
+  // Number of pictures in each sub-DPB
+  retVal |= ( dpbStatus.m_numPicsInSubDpb[subDpbIdx] >= dpbLimit.m_numPicsInSubDpb[subDpbIdx] );
+  
+  // Number of pictures in each layer
+  retVal |= ( dpbStatus.m_numPicsInLayer[layerIdx] >= dpbLimit.m_numPicsInLayer[layerIdx]);
+
+  return retVal;
+}
+
+Bool TAppDecTop::ifInvokeBumpingAfterDecoding( const DpbStatus &dpbStatus, const DpbStatus &dpbLimit )
+{
+  Bool retVal = false;
+
+  // Number of reorder picutres
+  retVal |= ( dpbStatus.m_numAUsNotDisplayed > dpbLimit.m_numAUsNotDisplayed );
+
+  return retVal;
+}
+
+Void TAppDecTop::xFindDPBStatus( std::vector<Int> &listOfPocs
+                            , std::vector<Int> *listOfPocsInEachLayer
+                            , std::vector<Int> *listOfPocsPositionInEachLayer
+                            , DpbStatus &dpbStatus
+                            )
+{
+  TComVPS *vps = NULL;
+  dpbStatus.init();
+  for( Int i = 0; i < MAX_LAYERS; i++ )
+  {
+    if( m_acTDecTop[i].getListPic()->empty() )
+    {
+      continue;
+    }
+    
+    // To check # AUs that have at least one picture not output,
+    // For each layer, populate listOfPOcs if not already present
+    TComList<TComPic*>::iterator iterPic = m_acTDecTop[i].getListPic()->begin();
+    Int picPositionInList = 0;
+    while (iterPic != m_acTDecTop[i].getListPic()->end())
+    {
+      TComPic* pic = *(iterPic);
+      if( pic->getReconMark() )
+      {
+        if( vps == NULL )
+        {
+          vps = pic->getSlice(0)->getVPS();
+        }
+
+        std::vector<Int>::iterator it;
+        if( pic->getOutputMark() ) // && pic->getPOC() > m_aiPOCLastDisplay[i])
+        {
+          it = find( listOfPocs.begin(), listOfPocs.end(), pic->getPOC() ); // Check if already included
+          if( it == listOfPocs.end() )  // New POC value - i.e. new AU - add to the list
+          {
+            listOfPocs.push_back( pic->getPOC() );
+          }
+          listOfPocsInEachLayer         [i].push_back( pic->getPOC()    );    // POC to be output in each layer
+          listOfPocsPositionInEachLayer [i].push_back( picPositionInList  );  // For ease of access
+        }
+        if( pic->getSlice(0)->isReferenced() || pic->getOutputMark() )
+        {
+          dpbStatus.m_numPicsInLayer[i]++;  // Count pictures that are "used for reference" or "needed for output"
+        }
+      }
+      iterPic++;
+      picPositionInList++;
+    }
+  }
+
+  assert( vps != NULL );    // No picture in any DPB?
+  std::sort( listOfPocs.begin(), listOfPocs.end() );    // Sort in increasing order of POC
+  Int targetLsIdx = vps->getOutputLayerSetIdx( getCommonDecoderParams()->getTargetOutputLayerSetIdx() );
+  // Update status
+  dpbStatus.m_numAUsNotDisplayed = listOfPocs.size();   // Number of AUs not displayed
+  dpbStatus.m_numLayers = vps->getNumLayersInIdList( targetLsIdx );
+  dpbStatus.m_numSubDpbs = vps->getNumSubDpbs( vps->getOutputLayerSetIdx(
+                                                      this->getCommonDecoderParams()->getTargetOutputLayerSetIdx() ) );
+
+  for(Int i = 0; i < dpbStatus.m_numLayers; i++)
+  {
+    dpbStatus.m_numPicsNotDisplayedInLayer[i] = listOfPocsInEachLayer[i].size();
+    dpbStatus.m_numPicsInSubDpb[vps->getSubDpbAssigned(targetLsIdx,i)] += dpbStatus.m_numPicsInLayer[i];
+  }
+  assert( dpbStatus.m_numAUsNotDisplayed != -1 );
+
+
+}  
+#endif
 //! \}
Index: trunk/source/App/TAppDecoder/TAppDecTop.h
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecTop.h	(revision 597)
+++ trunk/source/App/TAppDecoder/TAppDecTop.h	(revision 644)
@@ -55,5 +55,7 @@
 // Class definition
 // ====================================================================================================================
-
+#if ALIGNED_BUMPING
+struct DpbStatus;
+#endif
 /// decoder application class
 class TAppDecTop : public TAppDecCfg
@@ -98,6 +100,58 @@
 #endif
   Bool  isNaluWithinTargetDecLayerIdSet ( InputNALUnit* nalu ); ///< check whether given Nalu is within targetDecLayerIdSet
+#if ALIGNED_BUMPING
+  Void checkOutputBeforeDecoding(Int layerIdx);
+  Void checkOutputAfterDecoding();
+  Void flushAllPictures(Bool outputPictures); 
+  Void flushAllPictures(Int layerId, Bool outputPictures);
+
+  Void xOutputAndMarkPic( TComPic *pic, const Char *reconFile, const Int layerID, Int &pocLastDisplay, DpbStatus &dpbStatus);
+  Void xFindDPBStatus( std::vector<Int> &listOfPocs
+                            , std::vector<Int> *listOfPocsInEachLayer
+                            , std::vector<Int> *listOfPocsPositionInEachLayer
+                            , DpbStatus &dpbStatus
+                            );
+
+  Bool ifInvokeBumpingBeforeDecoding( const DpbStatus &dpbStatus, const DpbStatus &dpbLimit, const Int layerIdx, const Int subDpbIdx );
+  Bool ifInvokeBumpingAfterDecoding ( const DpbStatus &dpbStatus, const DpbStatus &dpbLimit );
+  Void bumpingProcess(std::vector<Int> &listOfPocs, std::vector<Int> *listOfPocsInEachLayer, std::vector<Int> *listOfPocsPositionInEachLayer, DpbStatus &dpbStatus);
+  Void emptyUnusedPicturesNotNeededForOutput();
+  Void markAllPicturesAsErased();
+  Void markAllPicturesAsErased(Int layerIdx);
+  TComVPS* findDpbParametersFromVps(std::vector<Int> const &listOfPocs, std::vector<Int> const *listOfPocsInEachLayer, std::vector<Int> const *listOfPocsPositionInEachLayer, DpbStatus &maxDpbLimit);
+#endif
 };
 
+#if ALIGNED_BUMPING
+struct DpbStatus
+{
+  // Number of AUs and pictures
+  Int m_numAUsNotDisplayed;
+  Int m_numPicsNotDisplayedInLayer[MAX_LAYERS];
+  Int m_numPicsInLayer[MAX_LAYERS];   // Pictures marked as used_for_reference or needed for output in the layer
+  Int m_numPicsInSubDpb[MAX_LAYERS];  // Pictures marked as used_for_reference or needed for output in the sub-DPB
+  Bool m_maxLatencyIncrease;
+  Int m_maxLatencyPictures;
+  
+  Int m_numSubDpbs;
+  Int m_numLayers;
+
+  DpbStatus()
+  {
+    init();
+  }
+  Void init()
+  {
+    m_numAUsNotDisplayed = 0;
+    m_maxLatencyIncrease  = false;
+    m_maxLatencyPictures  = 0;
+    ::memset( m_numPicsInLayer,  0, sizeof(m_numPicsInLayer)  );
+    ::memset( m_numPicsInSubDpb, 0, sizeof(m_numPicsInSubDpb) );
+    ::memset(m_numPicsNotDisplayedInLayer, 0, sizeof(m_numPicsNotDisplayedInLayer) );
+    m_numSubDpbs = -1;
+    m_numLayers = -1;
+  }
+};
+#endif
 //! \}
 
Index: trunk/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 597)
+++ trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 644)
@@ -385,4 +385,7 @@
   string    cfg_scaledRefLayerBottomOffset [MAX_LAYERS];
   Int*      cfg_numScaledRefLayerOffsets[MAX_LAYERS];
+#if P0312_VERT_PHASE_ADJ
+  string    cfg_vertPhasePositionEnableFlag[MAX_LAYERS];
+#endif
 
 #if O0098_SCALED_REF_LAYER_ID
@@ -393,4 +396,8 @@
   string*    cfg_scaledRefLayerRightOffsetPtr  [MAX_LAYERS];
   string*    cfg_scaledRefLayerBottomOffsetPtr [MAX_LAYERS];
+#if P0312_VERT_PHASE_ADJ
+  string*    cfg_vertPhasePositionEnableFlagPtr[MAX_LAYERS];
+#endif
+
 #if RC_SHVC_HARMONIZATION
   Bool*   cfg_RCEnableRateControl  [MAX_LAYERS];
@@ -451,10 +458,13 @@
     {
 #if O0098_SCALED_REF_LAYER_ID
-      cfg_scaledRefLayerIdPtr          [layer] = &cfg_scaledRefLayerId[layer]          ;
-#endif
-      cfg_scaledRefLayerLeftOffsetPtr  [layer] = &cfg_scaledRefLayerLeftOffset[layer]  ;
-      cfg_scaledRefLayerTopOffsetPtr   [layer] = &cfg_scaledRefLayerTopOffset[layer]   ;
-      cfg_scaledRefLayerRightOffsetPtr [layer] = &cfg_scaledRefLayerRightOffset[layer] ;
+      cfg_scaledRefLayerIdPtr          [layer] = &cfg_scaledRefLayerId[layer];
+#endif
+      cfg_scaledRefLayerLeftOffsetPtr  [layer] = &cfg_scaledRefLayerLeftOffset[layer];
+      cfg_scaledRefLayerTopOffsetPtr   [layer] = &cfg_scaledRefLayerTopOffset[layer];
+      cfg_scaledRefLayerRightOffsetPtr [layer] = &cfg_scaledRefLayerRightOffset[layer];
       cfg_scaledRefLayerBottomOffsetPtr[layer] = &cfg_scaledRefLayerBottomOffset[layer];
+#if P0312_VERT_PHASE_ADJ
+      cfg_vertPhasePositionEnableFlagPtr[layer] = &cfg_vertPhasePositionEnableFlag[layer];
+#endif
     }
 #if RC_SHVC_HARMONIZATION
@@ -569,5 +579,8 @@
                                                                  " bottom-right luma sample of the EL picture, in units of two luma samples")
   ("ScaledRefLayerBottomOffset%d", cfg_scaledRefLayerBottomOffsetPtr,string(""), MAX_LAYERS, "Vertical offset of bottom-right luma sample of scaled base layer picture with respect to"
-                                                                 " bottom-right luma sample of the EL picture, in units of two luma samples")
+  " bottom-right luma sample of the EL picture, in units of two luma samples")
+#if P0312_VERT_PHASE_ADJ
+  ("VertPhasePositionEnableFlag%d", cfg_vertPhasePositionEnableFlagPtr,string(""), MAX_LAYERS, "VertPhasePositionEnableFlag for layer %d")
+#endif
 #if O0194_DIFFERENT_BITDEPTH_EL_BL
   ("InputBitDepth%d",       cfg_InputBitDepthY,    8, MAX_LAYERS, "Bit-depth of input file for layer %d")
@@ -588,4 +601,7 @@
 #if N0147_IRAP_ALIGN_FLAG
   ("CrossLayerIrapAlignFlag", m_crossLayerIrapAlignFlag, true, "align IRAP across layers" )  
+#endif
+#if P0068_CROSS_LAYER_ALIGNED_IDR_ONLY_FOR_IRAP_FLAG
+  ("CrossLayerAlignedIdrOnlyFlag", m_crossLayerAlignedIdrOnlyFlag, true, "only idr for IRAP across layers" )  
 #endif
 #if O0194_WEIGHTED_PREDICTION_CGS
@@ -714,5 +730,4 @@
   ("LambdaModifier5,-LM5", m_adLambdaModifier[ 5 ], ( Double )1.0, "Lambda modifier for temporal layer 5")
   ("LambdaModifier6,-LM6", m_adLambdaModifier[ 6 ], ( Double )1.0, "Lambda modifier for temporal layer 6")
-  ("LambdaModifier7,-LM7", m_adLambdaModifier[ 7 ], ( Double )1.0, "Lambda modifier for temporal layer 7")
 #endif
 
@@ -1070,9 +1085,16 @@
       assert( strcmp(cfg_scaledRefLayerId[layer].c_str(),  ""));
 #endif
+#if P0312_VERT_PHASE_ADJ
       assert( strcmp(cfg_scaledRefLayerLeftOffset[layer].c_str(),  "") ||
               strcmp(cfg_scaledRefLayerRightOffset[layer].c_str(), "") ||
               strcmp(cfg_scaledRefLayerTopOffset[layer].c_str(),   "") ||
-              strcmp(cfg_scaledRefLayerBottomOffset[layer].c_str(),"")
-            ); 
+              strcmp(cfg_scaledRefLayerBottomOffset[layer].c_str(),"") ||
+              strcmp(cfg_vertPhasePositionEnableFlag[layer].c_str(),"") ); 
+#else
+      assert( strcmp(cfg_scaledRefLayerLeftOffset[layer].c_str(),  "") ||
+              strcmp(cfg_scaledRefLayerRightOffset[layer].c_str(), "") ||
+              strcmp(cfg_scaledRefLayerTopOffset[layer].c_str(),   "") ||
+              strcmp(cfg_scaledRefLayerBottomOffset[layer].c_str(),"") ); 
+#endif
     }
 
@@ -1150,4 +1172,19 @@
       }
     }
+#if P0312_VERT_PHASE_ADJ
+   // VertPhasePositionEnableFlag //
+    if(strcmp(cfg_vertPhasePositionEnableFlag[layer].c_str(),  ""))
+    {
+      cfgStringToArray( &tempArray, cfg_vertPhasePositionEnableFlag[layer], m_acLayerCfg[layer].m_numScaledRefLayerOffsets, "VertPhasePositionEnableFlag");
+      if(tempArray)
+      {
+        for(Int i = 0; i < m_acLayerCfg[layer].m_numScaledRefLayerOffsets; i++)
+        {
+          m_acLayerCfg[layer].m_vertPhasePositionEnableFlag[i] = tempArray[i];
+        }
+        delete [] tempArray; tempArray = NULL;
+      }
+    }
+#endif
   }
 #if VPS_EXTN_DIRECT_REF_LAYERS
@@ -2342,4 +2379,7 @@
   printf("Cross layer IRAP alignment    : %d\n", m_crossLayerIrapAlignFlag );
 #endif
+#if P0068_CROSS_LAYER_ALIGNED_IDR_ONLY_FOR_IRAP_FLAG
+  printf("IDR only for IRAP             : %d\n", m_crossLayerAlignedIdrOnlyFlag );
+#endif
 #if O0194_WEIGHTED_PREDICTION_CGS
   printf("InterLayerWeightedPred        : %d\n", m_useInterLayerWeightedPred );
Index: trunk/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncCfg.h	(revision 597)
+++ trunk/source/App/TAppEncoder/TAppEncCfg.h	(revision 644)
@@ -384,4 +384,7 @@
   Bool      m_crossLayerIrapAlignFlag;
 #endif
+#if P0068_CROSS_LAYER_ALIGNED_IDR_ONLY_FOR_IRAP_FLAG
+  Bool      m_crossLayerAlignedIdrOnlyFlag;
+#endif
 #if O0149_CROSS_LAYER_BLA_FLAG
   Bool      m_crossLayerBLAFlag;
Index: trunk/source/App/TAppEncoder/TAppEncLayerCfg.cpp
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncLayerCfg.cpp	(revision 597)
+++ trunk/source/App/TAppEncoder/TAppEncLayerCfg.cpp	(revision 644)
@@ -60,4 +60,7 @@
   ::memset(m_scaledRefLayerRightOffset,  0, sizeof(m_scaledRefLayerRightOffset));
   ::memset(m_scaledRefLayerBottomOffset, 0, sizeof(m_scaledRefLayerBottomOffset));
+#if P0312_VERT_PHASE_ADJ 
+  ::memset(m_vertPhasePositionEnableFlag, 0, sizeof(m_vertPhasePositionEnableFlag));
+#endif
 }
 
Index: trunk/source/App/TAppEncoder/TAppEncLayerCfg.h
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 597)
+++ trunk/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 644)
@@ -97,4 +97,8 @@
   Int       m_scaledRefLayerRightOffset [MAX_LAYERS];
   Int       m_scaledRefLayerBottomOffset[MAX_LAYERS];
+#if P0312_VERT_PHASE_ADJ 
+  Bool      m_vertPhasePositionEnableFlag[MAX_LAYERS];
+#endif
+
 #if O0194_DIFFERENT_BITDEPTH_EL_BL
   Int       m_inputBitDepthY;                               ///< bit-depth of input file (luma component)
Index: trunk/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 597)
+++ trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 644)
@@ -570,6 +570,12 @@
         m_acTEncTop[layer].setScaledRefLayerId(i, m_acLayerCfg[layer].m_scaledRefLayerId[i]);
 #endif
+#if P0312_VERT_PHASE_ADJ
+        m_acTEncTop[layer].setVertPhasePositionEnableFlag( i, m_acLayerCfg[layer].m_vertPhasePositionEnableFlag[i] );
+        m_acTEncTop[layer].getScaledRefLayerWindow(i).setWindow( 2*m_acLayerCfg[layer].m_scaledRefLayerLeftOffset[i], 2*m_acLayerCfg[layer].m_scaledRefLayerRightOffset[i],
+                                                  2*m_acLayerCfg[layer].m_scaledRefLayerTopOffset[i], 2*m_acLayerCfg[layer].m_scaledRefLayerBottomOffset[i], m_acLayerCfg[layer].m_vertPhasePositionEnableFlag[i] );
+#else
         m_acTEncTop[layer].getScaledRefLayerWindow(i).setWindow( 2*m_acLayerCfg[layer].m_scaledRefLayerLeftOffset[i], 2*m_acLayerCfg[layer].m_scaledRefLayerRightOffset[i],
                                                   2*m_acLayerCfg[layer].m_scaledRefLayerTopOffset[i], 2*m_acLayerCfg[layer].m_scaledRefLayerBottomOffset[i]);
+#endif
       }
     }
@@ -956,4 +962,8 @@
 #endif
     m_acTEncTop[layer].init(isFieldCoding);
+#if P0182_VPS_VUI_PS_FLAG
+    m_acTEncTop[layer].getVPS()->setSPSId(layer, m_acTEncTop[layer].getSPS()->getSPSId());
+    m_acTEncTop[layer].getVPS()->setPPSId(layer, m_acTEncTop[layer].getPPS()->getPPSId());
+#endif
   }
 #if VPS_RENAME
@@ -1193,5 +1203,5 @@
         // at the encoder, modify below
         Int oldValue = vps->getMaxVpsDecPicBufferingMinus1( i, vps->getSubDpbAssigned( layerSetIdxForOutputLayerSet, k ), j );
-        oldValue += vps->getMaxVpsLayerDecPicBuffMinus1( i, k, j );
+        oldValue += vps->getMaxVpsLayerDecPicBuffMinus1( i, k, j ) + 1;
         vps->setMaxVpsDecPicBufferingMinus1( i, vps->getSubDpbAssigned( layerSetIdxForOutputLayerSet, k ), j, oldValue );
 #else
@@ -1200,4 +1210,12 @@
         maxNumReorderPics       = std::max( maxNumReorderPics, m_acTEncTop[layerId].getNumReorderPics(j));
       }
+#if RESOLUTION_BASED_DPB
+      for(Int k = 0; k < vps->getNumSubDpbs(i); k++)
+      {
+        // Decrement m_maxVpsDecPicBufferingMinus1
+        Int oldValue = vps->getMaxVpsDecPicBufferingMinus1( i, vps->getSubDpbAssigned( layerSetIdxForOutputLayerSet, k ), j );
+        vps->setMaxVpsDecPicBufferingMinus1( i, vps->getSubDpbAssigned( layerSetIdxForOutputLayerSet, k ), j, oldValue - 1 );
+      }
+#endif
       vps->setMaxVpsNumReorderPics(i, j, maxNumReorderPics);
       vps->determineSubDpbInfoFlags();
@@ -1286,4 +1304,7 @@
     vps->setCrossLayerPictureTypeAlignFlag( m_crossLayerPictureTypeAlignFlag );
 #endif
+#if P0068_CROSS_LAYER_ALIGNED_IDR_ONLY_FOR_IRAP_FLAG
+    vps->setCrossLayerAlignedIdrOnlyFlag( m_crossLayerAlignedIdrOnlyFlag );
+#endif
 #if N0147_IRAP_ALIGN_FLAG
     vps->setCrossLayerIrapAlignFlag( m_crossLayerIrapAlignFlag );
@@ -1327,6 +1348,85 @@
 #endif
 
+#if P0300_ALT_OUTPUT_LAYER_FLAG
+  for (Int k = 0; k < MAX_VPS_LAYER_SETS_PLUS1; k++)
+  {
+    vps->setAltOuputLayerFlag( k, m_altOutputLayerFlag );
+  }
+#else
 #if O0153_ALT_OUTPUT_LAYER_FLAG
   vps->setAltOuputLayerFlag( m_altOutputLayerFlag );
+#endif
+#endif
+
+#if P0312_VERT_PHASE_ADJ
+  Bool vpsVuiVertPhaseInUseFlag = false;
+  for( UInt layerId = 1; layerId < m_numLayers; layerId++ )
+  {
+    for( i = 0; i < m_acLayerCfg[layerId].m_numScaledRefLayerOffsets; i++ )
+    {
+      if( m_acTEncTop[layerId].getVertPhasePositionEnableFlag(i) )
+      {
+        vpsVuiVertPhaseInUseFlag = true;
+        break;
+      }
+    }
+  }
+  vps->setVpsVuiVertPhaseInUseFlag( vpsVuiVertPhaseInUseFlag );
+#endif
+
+#if O0164_MULTI_LAYER_HRD
+  vps->setVpsVuiBspHrdPresentFlag(false);
+  TEncTop *pcCfg = &m_acTEncTop[0];
+  if( pcCfg->getBufferingPeriodSEIEnabled() )
+  {
+    vps->setVpsVuiBspHrdPresentFlag(true);
+    vps->setVpsNumBspHrdParametersMinus1(vps->getNumLayerSets() - 2); 
+    vps->createBspHrdParamBuffer(vps->getVpsNumBspHrdParametersMinus1() + 1);
+    for ( i = 0; i <= vps->getVpsNumBspHrdParametersMinus1(); i++ )
+    {
+      vps->setBspCprmsPresentFlag(i, true);
+
+      UInt layerId = i + 1;
+      TEncTop *pcCfgLayer = &m_acTEncTop[layerId];
+
+      Int iPicWidth         = pcCfgLayer->getSourceWidth();
+      Int iPicHeight        = pcCfgLayer->getSourceHeight();
+      UInt uiWidthInCU       = ( iPicWidth %m_uiMaxCUWidth  ) ? iPicWidth /m_uiMaxCUWidth  + 1 : iPicWidth /m_uiMaxCUWidth;
+      UInt uiHeightInCU      = ( iPicHeight%m_uiMaxCUHeight ) ? iPicHeight/m_uiMaxCUHeight + 1 : iPicHeight/m_uiMaxCUHeight;
+      UInt uiNumCUsInFrame   = uiWidthInCU * uiHeightInCU;
+
+      UInt maxCU = pcCfgLayer->getSliceArgument() >> ( m_uiMaxCUDepth << 1);
+      UInt numDU = ( pcCfgLayer->getSliceMode() == 1 ) ? ( uiNumCUsInFrame / maxCU ) : ( 0 );
+      if( uiNumCUsInFrame % maxCU != 0 || numDU == 0 )
+      {
+        numDU ++;
+      }
+      vps->getBspHrd(i)->setNumDU( numDU );
+      vps->setBspHrdParameters( i, pcCfgLayer->getFrameRate(), numDU, pcCfgLayer->getTargetBitrate(), ( pcCfgLayer->getIntraPeriod() > 0 ) );
+    }
+    for(UInt h = 1; h <= (vps->getNumLayerSets()-1); h++)
+    {
+      vps->setNumBitstreamPartitions(h, 1);
+      for( i = 0; i < vps->getNumBitstreamPartitions(h); i++ )
+      {
+        for( UInt j = 0; j <= (vps->getMaxLayers()-1); j++ )
+        {
+          if (vps->getLayerIdIncludedFlag(h, j) && h == j)
+          {
+            vps->setLayerInBspFlag(h, i, j, true);
+          }
+        }
+      }
+      vps->setNumBspSchedCombinations(h, 1);
+      for( i = 0; i < vps->getNumBspSchedCombinations(h); i++ )
+      {
+        for( UInt j = 0; j < vps->getNumBitstreamPartitions(h); j++ )
+        {
+          vps->setBspCombHrdIdx(h, i, j, 0);
+          vps->setBspCombSchedIdx(h, i, j, 0);
+        }
+      }
+    }
+  }
 #endif
 
Index: trunk/source/Lib/TLibCommon/CommonDef.h
===================================================================
--- trunk/source/Lib/TLibCommon/CommonDef.h	(revision 597)
+++ trunk/source/Lib/TLibCommon/CommonDef.h	(revision 644)
@@ -58,5 +58,5 @@
 #if SVC_EXTENSION
 #include <vector>
-#define NV_VERSION        "5.0 (HM-13.0)"                 ///< Current software version
+#define NV_VERSION        "5.1 (HM-13.0)"                 ///< Current software version
 #else
 #define NV_VERSION        "13.0"                ///< Current software version
@@ -178,5 +178,5 @@
 
 // Explicit temporal layer QP offset
-#define MAX_TLAYER                  8           ///< max number of temporal layer
+#define MAX_TLAYER                  7           ///< max number of temporal layer
 #define HB_LAMBDA_FOR_LDC           1           ///< use of B-style lambda for non-key pictures in low-delay mode
 
@@ -288,4 +288,5 @@
   std::vector<Int> *m_targetDecLayerIdSet; 
   Bool m_valueCheckedFlag;
+  Int m_highestTId;
 public:
   CommonDecoderParams(): 
@@ -294,4 +295,5 @@
     , m_targetDecLayerIdSet(NULL)
     , m_valueCheckedFlag(false)
+    , m_highestTId(6)
  {}
 
@@ -308,4 +310,6 @@
   Bool getValueCheckedFlag()            { return m_valueCheckedFlag;}
   
+  Void setHighestTId(const Int x) { m_highestTId = x; }
+  Int  getHighestTId()            { return m_highestTId; }
 };
 #endif
Index: trunk/source/Lib/TLibCommon/SEI.h
===================================================================
--- trunk/source/Lib/TLibCommon/SEI.h	(revision 597)
+++ trunk/source/Lib/TLibCommon/SEI.h	(revision 644)
@@ -40,4 +40,7 @@
 //! \{
 class TComSPS;
+#if O0164_MULTI_LAYER_HRD
+class TComHRD;
+#endif
 
 /**
@@ -81,4 +84,9 @@
    ,SUB_BITSTREAM_PROPERTY               = 139    // Final PayloadType to be defined after finalization
 #endif
+#if O0164_MULTI_LAYER_HRD
+   ,BSP_NESTING                          = 140
+   ,BSP_INITIAL_ARRIVAL_TIME             = 141
+   ,BSP_HRD                              = 142
+#endif
   };
   
@@ -157,4 +165,8 @@
   , m_cpbDelayOffset      (0)
   , m_dpbDelayOffset      (0)
+#if P0138_USE_ALT_CPB_PARAMS_FLAG
+  , m_useAltCpbParamsFlagPresent(false)
+  , m_useAltCpbParamsFlag (false)
+#endif
   {
     ::memset(m_initialCpbRemovalDelay, 0, sizeof(m_initialCpbRemovalDelay));
@@ -175,4 +187,8 @@
   Bool m_concatenationFlag;
   UInt m_auCpbRemovalDelayDelta;
+#if P0138_USE_ALT_CPB_PARAMS_FLAG
+  Bool m_useAltCpbParamsFlagPresent;
+  Bool m_useAltCpbParamsFlag;
+#endif
 };
 class SEIPictureTiming : public SEI
@@ -440,4 +456,60 @@
 Void deleteSEIs (SEIMessages &seiList);
 
+#if O0164_MULTI_LAYER_HRD
+
+class SEIBspNesting : public SEI
+{
+public:
+  PayloadType payloadType() const { return BSP_NESTING; }
+
+  SEIBspNesting() {}
+  virtual ~SEIBspNesting()
+  {
+    if (!m_callerOwnsSEIs)
+    {
+      deleteSEIs(m_nestedSEIs);
+    }
+  }
+
+  Int  m_bspIdx;
+  Bool  m_callerOwnsSEIs;
+  SEIMessages m_nestedSEIs;
+};
+
+class SEIBspInitialArrivalTime : public SEI
+{
+public:
+  PayloadType payloadType() const { return BSP_INITIAL_ARRIVAL_TIME; }
+
+  SEIBspInitialArrivalTime () {}
+  virtual ~SEIBspInitialArrivalTime () {}
+
+  UInt m_nalInitialArrivalDelay[256];
+  UInt m_vclInitialArrivalDelay[256];
+};
+
+class SEIBspHrd : public SEI
+{
+public:
+  PayloadType payloadType() const { return BSP_HRD; }
+
+  SEIBspHrd () {}
+  virtual ~SEIBspHrd () {}
+
+  UInt m_seiNumBspHrdParametersMinus1;
+  Bool m_seiBspCprmsPresentFlag[MAX_VPS_LAYER_SETS_PLUS1];
+  UInt m_seiNumBitstreamPartitionsMinus1[MAX_VPS_LAYER_SETS_PLUS1];
+  Bool m_seiLayerInBspFlag[MAX_VPS_LAYER_SETS_PLUS1][8][MAX_LAYERS];
+  UInt m_seiNumBspSchedCombinationsMinus1[MAX_VPS_LAYER_SETS_PLUS1];
+  UInt m_seiBspCombHrdIdx[MAX_VPS_LAYER_SETS_PLUS1][16][16];
+  UInt m_seiBspCombScheddx[MAX_VPS_LAYER_SETS_PLUS1][16][16];
+  UInt m_vpsMaxLayers;
+  Bool m_layerIdIncludedFlag[MAX_VPS_LAYER_SETS_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
+
+  TComHRD *hrd;
+};
+
+#endif
+
 class SEIScalableNesting : public SEI
 {
Index: trunk/source/Lib/TLibCommon/TComBitStream.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComBitStream.cpp	(revision 597)
+++ trunk/source/Lib/TLibCommon/TComBitStream.cpp	(revision 644)
@@ -229,4 +229,7 @@
   UChar saved_held_bits = m_held_bits;
   UInt saved_fifo_idx = m_fifo_idx;
+#if P0138_USE_ALT_CPB_PARAMS_FLAG
+  UInt saved_numBitsRead = m_numBitsRead;
+#endif
 
   UInt num_bits_to_read = min(uiNumberOfBits, getNumBitsLeft());
@@ -237,4 +240,7 @@
   m_held_bits = saved_held_bits;
   m_num_held_bits = saved_num_held_bits;
+#if P0138_USE_ALT_CPB_PARAMS_FLAG
+  m_numBitsRead = saved_numBitsRead;
+#endif
 }
 
Index: trunk/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 597)
+++ trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 644)
@@ -768,10 +768,10 @@
 #if O0215_PHASE_ALIGNMENT
 #if O0194_JOINT_US_BITSHIFT
-Void TComPrediction::upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, bool phaseAlignFlag )
+Void TComPrediction::upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, Bool phaseAlignFlag )
 {
   m_cUsf.upsampleBasePic( currSlice, refLayerIdc, pcUsPic, pcBasePic, pcTempPic, window, phaseAlignFlag );
 }
 #else
-Void TComPrediction::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, bool phaseAlignFlag )
+Void TComPrediction::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, Bool phaseAlignFlag )
 {
   m_cUsf.upsampleBasePic( refLayerIdc, pcUsPic, pcBasePic, pcTempPic, window, phaseAlignFlag );
Index: trunk/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPrediction.h	(revision 597)
+++ trunk/source/Lib/TLibCommon/TComPrediction.h	(revision 644)
@@ -49,5 +49,4 @@
 
 #if SVC_UPSAMPLING
-#include "TComDataCU.h"
 #include "TComUpsampleFilter.h"
 #endif
@@ -122,7 +121,7 @@
 #if O0215_PHASE_ALIGNMENT
 #if O0194_JOINT_US_BITSHIFT
-  Void upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, bool phaseAlignFlag );
+  Void upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, Bool phaseAlignFlag );
 #else
-  Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, bool phaseAlignFlag );
+  Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, Bool phaseAlignFlag );
 #endif
 #else
Index: trunk/source/Lib/TLibCommon/TComRom.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComRom.h	(revision 597)
+++ trunk/source/Lib/TLibCommon/TComRom.h	(revision 644)
@@ -273,6 +273,6 @@
 #if SVC_EXTENSION
 #if FAST_INTRA_SHVC
-extern       UInt  g_reducedSetIntraModes[NUM_INTRA_MODE-1];
-extern       UInt  g_predefSetIntraModes[NUM_INTRA_MODE-1];
+extern UInt g_reducedSetIntraModes[NUM_INTRA_MODE-1];
+extern UInt g_predefSetIntraModes[NUM_INTRA_MODE-1];
 #endif
 extern Int g_mvScalingFactor  [MAX_LAYERS][2];
Index: trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp	(revision 597)
+++ trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp	(revision 644)
@@ -44,5 +44,7 @@
 //! \ingroup TLibCommon
 //! \{
+#if !SVC_EXTENSION
 UInt g_saoMaxOffsetQVal[NUM_SAO_COMPONENTS]; 
+#endif
 
 SAOOffset::SAOOffset()
@@ -160,5 +162,9 @@
     Int bitDepthSample = (compIdx == SAO_Y)?g_bitDepthY:g_bitDepthC;
     m_offsetStepLog2  [compIdx] = max(bitDepthSample - MAX_SAO_TRUNCATED_BITDEPTH, 0);
+#if SVC_EXTENSION
+    m_saoMaxOffsetQVal[compIdx] = (1<<(min(bitDepthSample,MAX_SAO_TRUNCATED_BITDEPTH)-5))-1; //Table 9-32, inclusive
+#else
     g_saoMaxOffsetQVal[compIdx] = (1<<(min(bitDepthSample,MAX_SAO_TRUNCATED_BITDEPTH)-5))-1; //Table 9-32, inclusive
+#endif
   }
 
@@ -168,5 +174,9 @@
     Int bitDepthSample = (compIdx == SAO_Y)?g_bitDepthY:g_bitDepthC; //exclusive
     Int maxSampleValue = (1<< bitDepthSample); //exclusive
+#if SVC_EXTENSION
+    Int maxOffsetValue = (m_saoMaxOffsetQVal[compIdx] << m_offsetStepLog2[compIdx]); 
+#else
     Int maxOffsetValue = (g_saoMaxOffsetQVal[compIdx] << m_offsetStepLog2[compIdx]); 
+#endif
 
     m_offsetClipTable[compIdx] = new Int[(maxSampleValue + maxOffsetValue -1)+ (maxOffsetValue)+1 ]; //positive & negative range plus 0
Index: trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.h	(revision 597)
+++ trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.h	(revision 644)
@@ -53,5 +53,7 @@
 // Class definition
 // ====================================================================================================================
+#if !SVC_EXTENSION
 extern UInt g_saoMaxOffsetQVal[NUM_SAO_COMPONENTS]; 
+#endif
 
 class TComSampleAdaptiveOffset
@@ -69,4 +71,7 @@
   Void reconstructBlkSAOParams(TComPic* pic, SAOBlkParam* saoBlkParams);
   Void PCMLFDisableProcess (TComPic* pcPic);
+#if SVC_EXTENSION
+  UInt* getSaoMaxOffsetQVal() { return m_saoMaxOffsetQVal; } 
+#endif
 protected:
   Void offsetBlock(Int compIdx, Int typeIdx, Int* offset, Pel* srcBlk, Pel* resBlk, Int srcStride, Int resStride,  Int width, Int height
@@ -101,5 +106,7 @@
   Int*   m_offsetClipTable[NUM_SAO_COMPONENTS];
   Short* m_signTable;
-
+#if SVC_EXTENSION
+  UInt m_saoMaxOffsetQVal[NUM_SAO_COMPONENTS]; 
+#endif
 };
 
Index: trunk/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 597)
+++ trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 644)
@@ -111,4 +111,18 @@
 , m_bCrossLayerBLAFlag            ( false )
 #endif
+#if NO_OUTPUT_OF_PRIOR_PICS
+, m_noOutputOfPriorPicsFlag       ( false )
+, m_noRaslOutputFlag              ( false )
+, m_handleCraAsBlaFlag            ( false )
+#endif
+#if POC_RESET_IDC_SIGNALLING
+, m_pocResetIdc                   ( 0 )
+, m_pocResetPeriodId              ( 0 )
+, m_fullPocResetFlag              ( false )
+, m_pocLsbVal                     ( 0 )
+, m_pocMsbVal                     ( 0 )
+, m_pocMsbValRequiredFlag         ( false )
+, m_pocMsbValPresentFlag          ( false )
+#endif
 #endif //SVC_EXTENSION
 {
@@ -120,4 +134,7 @@
   m_interLayerPredEnabledFlag = 0;
   ::memset( m_interLayerPredLayerIdc, 0, sizeof(m_interLayerPredLayerIdc) );
+#if P0312_VERT_PHASE_ADJ
+  ::memset( m_vertPhasePositionFlag, 0, sizeof(m_vertPhasePositionFlag) );
+#endif
 #endif //SVC_EXTENSION
 
@@ -194,4 +211,16 @@
       || getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA;
 }
+#if NO_OUTPUT_OF_PRIOR_PICS
+Bool TComSlice::getBlaPicFlag       ()
+{
+    return  getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
+    || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
+    || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP;
+}
+Bool TComSlice::getCraPicFlag       ()
+{
+    return getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA;
+}
+#endif
 
 /**
@@ -848,5 +877,5 @@
 
 #if SVC_EXTENSION
-  if( m_eSliceType == I_SLICE || ( m_pcSPS->getLayerId() && 
+  if( m_eSliceType == I_SLICE || ( m_layerId && 
     (m_eNalUnitType >= NAL_UNIT_CODED_SLICE_BLA_W_LP) &&
     (m_eNalUnitType <= NAL_UNIT_CODED_SLICE_CRA) ) )
@@ -872,5 +901,5 @@
   {
     numRpsCurrTempList += m_activeNumILRRefIdx;
-}
+  }
 #endif
 
@@ -1105,4 +1134,7 @@
   m_interLayerPredEnabledFlag  = pSrc->m_interLayerPredEnabledFlag;
   memcpy( m_interLayerPredLayerIdc, pSrc->m_interLayerPredLayerIdc, sizeof( m_interLayerPredLayerIdc ) );
+#if P0312_VERT_PHASE_ADJ
+  memcpy( m_vertPhasePositionFlag, pSrc->m_vertPhasePositionFlag, sizeof( m_vertPhasePositionFlag ) );
+#endif
 #endif
   m_pcSPS                = pSrc->m_pcSPS;
@@ -1389,5 +1421,7 @@
   Int i, isReference;
 
+#if !ALIGNED_BUMPING
   checkLeadingPictureRestrictions(rcListPic);
+#endif
 
   // loop through all pictures in the reference picture buffer
@@ -2071,4 +2105,7 @@
   m_crossLayerIrapAlignFlag = true;
 #endif 
+#if P0068_CROSS_LAYER_ALIGNED_IDR_ONLY_FOR_IRAP_FLAG
+  m_crossLayerAlignedIdrOnlyFlag = false;
+#endif
 #if N0120_MAX_TID_REF_PRESENT_FLAG
   m_maxTidRefPresentFlag = true;
@@ -2455,4 +2492,83 @@
   return -1;  // Layer not found
 }
+#if O0164_MULTI_LAYER_HRD
+Void TComVPS::setBspHrdParameters( UInt hrdIdx, UInt frameRate, UInt numDU, UInt bitRate, Bool randomAccess )
+{
+  if( !getVpsVuiBspHrdPresentFlag() )
+  {
+    return;
+  }
+
+  TComHRD *hrd = getBspHrd(hrdIdx);
+
+  Bool rateCnt = ( bitRate > 0 );
+  hrd->setNalHrdParametersPresentFlag( rateCnt );
+  hrd->setVclHrdParametersPresentFlag( rateCnt );
+
+  hrd->setSubPicCpbParamsPresentFlag( ( numDU > 1 ) );
+
+  if( hrd->getSubPicCpbParamsPresentFlag() )
+  {
+    hrd->setTickDivisorMinus2( 100 - 2 );                          // 
+    hrd->setDuCpbRemovalDelayLengthMinus1( 7 );                    // 8-bit precision ( plus 1 for last DU in AU )
+    hrd->setSubPicCpbParamsInPicTimingSEIFlag( true );
+    hrd->setDpbOutputDelayDuLengthMinus1( 5 + 7 );                 // With sub-clock tick factor of 100, at least 7 bits to have the same value as AU dpb delay
+  }
+  else
+  {
+    hrd->setSubPicCpbParamsInPicTimingSEIFlag( false );  
+  }
+
+  hrd->setBitRateScale( 4 );                                       // in units of 2~( 6 + 4 ) = 1,024 bps
+  hrd->setCpbSizeScale( 6 );                                       // in units of 2~( 4 + 4 ) = 1,024 bit
+  hrd->setDuCpbSizeScale( 6 );                                       // in units of 2~( 4 + 4 ) = 1,024 bit
+
+  hrd->setInitialCpbRemovalDelayLengthMinus1(15);                  // assuming 0.5 sec, log2( 90,000 * 0.5 ) = 16-bit
+  if( randomAccess )
+  {
+    hrd->setCpbRemovalDelayLengthMinus1(5);                        // 32 = 2^5 (plus 1)
+    hrd->setDpbOutputDelayLengthMinus1 (5);                        // 32 + 3 = 2^6
+  }
+  else
+  {
+    hrd->setCpbRemovalDelayLengthMinus1(9);                        // max. 2^10
+    hrd->setDpbOutputDelayLengthMinus1 (9);                        // max. 2^10
+  }
+
+  /*
+  Note: only the case of "vps_max_temporal_layers_minus1 = 0" is supported.
+  */
+  Int i, j;
+  UInt birateValue, cpbSizeValue;
+  UInt ducpbSizeValue;
+  UInt duBitRateValue = 0;
+
+  for( i = 0; i < MAX_TLAYER; i ++ )
+  {
+    hrd->setFixedPicRateFlag( i, 1 );
+    hrd->setPicDurationInTcMinus1( i, 0 );
+    hrd->setLowDelayHrdFlag( i, 0 );
+    hrd->setCpbCntMinus1( i, 0 );
+
+    birateValue  = bitRate;
+    cpbSizeValue = bitRate;                                     // 1 second
+    ducpbSizeValue = bitRate/numDU;
+    duBitRateValue = bitRate;
+    for( j = 0; j < ( hrd->getCpbCntMinus1( i ) + 1 ); j ++ )
+    {
+      hrd->setBitRateValueMinus1( i, j, 0, ( birateValue  - 1 ) );
+      hrd->setCpbSizeValueMinus1( i, j, 0, ( cpbSizeValue - 1 ) );
+      hrd->setDuCpbSizeValueMinus1( i, j, 0, ( ducpbSizeValue - 1 ) );
+      hrd->setCbrFlag( i, j, 0, ( j == 0 ) );
+
+      hrd->setBitRateValueMinus1( i, j, 1, ( birateValue  - 1) );
+      hrd->setCpbSizeValueMinus1( i, j, 1, ( cpbSizeValue - 1 ) );
+      hrd->setDuCpbSizeValueMinus1( i, j, 1, ( ducpbSizeValue - 1 ) );
+      hrd->setDuBitRateValueMinus1( i, j, 1, ( duBitRateValue - 1 ) );
+      hrd->setCbrFlag( i, j, 1, ( j == 0 ) );
+    }
+  }
+}
+#endif
 // RepFormat Assignment operator
 RepFormat& RepFormat::operator= (const RepFormat &other)
@@ -2548,4 +2664,8 @@
   ::memset(m_ltRefPicPocLsbSps, 0, sizeof(m_ltRefPicPocLsbSps));
   ::memset(m_usedByCurrPicLtSPSFlag, 0, sizeof(m_usedByCurrPicLtSPSFlag));
+
+#if P0312_VERT_PHASE_ADJ 
+  ::memset(m_vertPhasePositionEnableFlag, 0, sizeof(m_vertPhasePositionEnableFlag));
+#endif
 }
 
@@ -2736,4 +2856,7 @@
 , m_scalingListRefLayerId ( 0 )
 #endif
+#if POC_RESET_IDC
+, m_pocResetInfoPresentFlag   (false)
+#endif
 {
   m_scalingList = new TComScalingList;
@@ -3405,5 +3528,4 @@
     //set reference picture POC of each ILP reference 
     Int thePoc = ilpPic[refLayerIdc]->getPOC(); 
-    assert(thePoc >= 0);
     assert(thePoc == pcRefPicBL->getPOC());
 
Index: trunk/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComSlice.h	(revision 597)
+++ trunk/source/Lib/TLibCommon/TComSlice.h	(revision 644)
@@ -231,7 +231,7 @@
 {
   ProfileTierLevel m_generalPTL;
-  ProfileTierLevel m_subLayerPTL[6];      // max. value of max_sub_layers_minus1 is 6
-  Bool m_subLayerProfilePresentFlag[6];
-  Bool m_subLayerLevelPresentFlag[6];
+  ProfileTierLevel m_subLayerPTL    [MAX_TLAYER-1];      // max. value of max_sub_layers_minus1 is MAX_TLAYER-1 ( = 6 )
+  Bool m_subLayerProfilePresentFlag [MAX_TLAYER-1];
+  Bool m_subLayerLevelPresentFlag   [MAX_TLAYER-1];
 
 public:
@@ -568,4 +568,7 @@
   Bool       m_crossLayerIrapAlignFlag;
 #endif
+#if P0068_CROSS_LAYER_ALIGNED_IDR_ONLY_FOR_IRAP_FLAG
+  Bool       m_crossLayerAlignedIdrOnlyFlag;
+#endif
 #if O0225_MAX_TID_FOR_REF_LAYERS
   UInt       m_maxTidIlRefPicsPlus1[MAX_VPS_LAYER_ID_PLUS1 - 1][MAX_VPS_LAYER_ID_PLUS1];
@@ -599,31 +602,40 @@
 #endif 
 #if N0160_VUI_EXT_ILP_REF    
-  Bool        m_ilpRestrictedRefLayersFlag;
-  Int         m_minSpatialSegmentOffsetPlus1[MAX_VPS_LAYER_ID_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
-  Bool        m_ctuBasedOffsetEnabledFlag   [MAX_VPS_LAYER_ID_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
-  Int         m_minHorizontalCtuOffsetPlus1 [MAX_VPS_LAYER_ID_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
+  Bool       m_ilpRestrictedRefLayersFlag;
+  Int        m_minSpatialSegmentOffsetPlus1[MAX_VPS_LAYER_ID_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
+  Bool       m_ctuBasedOffsetEnabledFlag   [MAX_VPS_LAYER_ID_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
+  Int        m_minHorizontalCtuOffsetPlus1 [MAX_VPS_LAYER_ID_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
 #endif 
 #if VPS_VUI_VIDEO_SIGNAL
-  Bool        m_vidSigPresentVpsFlag;
-  Int         m_vpsVidSigInfo;
-  Int         m_vpsVidSigIdx[MAX_VPS_LAYER_ID_PLUS1];
-  Int         m_vpsVidFormat[16];
-  Bool        m_vpsFullRangeFlag[16];
-  Int         m_vpsColorPrimaries[16];
-  Int         m_vpsTransChar[16];
-  Int         m_vpsMatCoeff[16];
+  Bool       m_vidSigPresentVpsFlag;
+  Int        m_vpsVidSigInfo;
+  Int        m_vpsVidSigIdx[MAX_VPS_LAYER_ID_PLUS1];
+  Int        m_vpsVidFormat[16];
+  Bool       m_vpsFullRangeFlag[16];
+  Int        m_vpsColorPrimaries[16];
+  Int        m_vpsTransChar[16];
+  Int        m_vpsMatCoeff[16];
 #endif 
 #if VPS_VUI_BITRATE_PICRATE
-  Bool        m_bitRatePresentVpsFlag;
-  Bool        m_picRatePresentVpsFlag;
-  Bool        m_bitRatePresentFlag  [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
-  Bool        m_picRatePresentFlag  [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
-  Int         m_avgBitRate          [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
-  Int         m_maxBitRate          [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
-  Int         m_constPicRateIdc     [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
-  Int         m_avgPicRate          [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
-#endif
+  Bool       m_bitRatePresentVpsFlag;
+  Bool       m_picRatePresentVpsFlag;
+  Bool       m_bitRatePresentFlag  [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
+  Bool       m_picRatePresentFlag  [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
+  Int        m_avgBitRate          [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
+  Int        m_maxBitRate          [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
+  Int        m_constPicRateIdc     [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
+  Int        m_avgPicRate          [MAX_VPS_LAYER_SETS_PLUS1][MAX_TLAYER];
+#endif
+  
+#if P0312_VERT_PHASE_ADJ
+  Bool       m_vpsVuiVertPhaseInUseFlag;
+#endif
+
+#if P0300_ALT_OUTPUT_LAYER_FLAG
+  Bool       m_altOutputLayerFlag[MAX_VPS_LAYER_SETS_PLUS1];
+#else
 #if O0153_ALT_OUTPUT_LAYER_FLAG
   Bool       m_altOutputLayerFlag;
+#endif
 #endif
 #if REPN_FORMAT_IN_VPS
@@ -635,9 +647,9 @@
 #if VIEW_ID_RELATED_SIGNALING 
 #if O0109_VIEW_ID_LEN
-  Int         m_viewIdLen;
+  Int        m_viewIdLen;
 #else
-  Int         m_viewIdLenMinus1;
-#endif
-  Int         m_viewIdVal                [MAX_LAYERS];
+  Int        m_viewIdLenMinus1;
+#endif
+  Int        m_viewIdVal                [MAX_LAYERS];
 #endif
 
@@ -650,17 +662,20 @@
   Bool       m_recursiveRefLayerFlag[MAX_NUM_LAYER_IDS][MAX_NUM_LAYER_IDS];  // flag to indicate if j-th layer is a direct or indirect reference layer of i-th layer
 #endif
+#if SPS_DPB_PARAMS
+  Int        m_TolsIdx;
+#endif
 #if VPS_DPB_SIZE_TABLE
-  Bool    m_subLayerFlagInfoPresentFlag [MAX_VPS_OP_LAYER_SETS_PLUS1];
-  Bool    m_subLayerDpbInfoPresentFlag  [MAX_VPS_OP_LAYER_SETS_PLUS1][MAX_LAYERS];
-  Int     m_maxVpsDecPicBufferingMinus1 [MAX_VPS_OP_LAYER_SETS_PLUS1][MAX_LAYERS][MAX_TLAYER];
+  Bool       m_subLayerFlagInfoPresentFlag [MAX_VPS_OP_LAYER_SETS_PLUS1];
+  Bool       m_subLayerDpbInfoPresentFlag  [MAX_VPS_OP_LAYER_SETS_PLUS1][MAX_LAYERS];
+  Int        m_maxVpsDecPicBufferingMinus1 [MAX_VPS_OP_LAYER_SETS_PLUS1][MAX_LAYERS][MAX_TLAYER];
 #if RESOLUTION_BASED_DPB
-  Int     m_maxVpsLayerDecPicBuffMinus1 [MAX_VPS_OP_LAYER_SETS_PLUS1][MAX_LAYERS][MAX_TLAYER];  
-#endif
-  Int     m_maxVpsNumReorderPics        [MAX_VPS_OP_LAYER_SETS_PLUS1][MAX_LAYERS];
-  Int     m_maxVpsLatencyIncreasePlus1  [MAX_VPS_OP_LAYER_SETS_PLUS1][MAX_LAYERS];
+  Int        m_maxVpsLayerDecPicBuffMinus1 [MAX_VPS_OP_LAYER_SETS_PLUS1][MAX_LAYERS][MAX_TLAYER];  
+#endif
+  Int        m_maxVpsNumReorderPics        [MAX_VPS_OP_LAYER_SETS_PLUS1][MAX_LAYERS];
+  Int        m_maxVpsLatencyIncreasePlus1  [MAX_VPS_OP_LAYER_SETS_PLUS1][MAX_LAYERS];
 #if CHANGE_NUMSUBDPB_IDX
-  Int     m_numSubDpbs                  [MAX_VPS_LAYER_SETS_PLUS1];
+  Int        m_numSubDpbs                  [MAX_VPS_LAYER_SETS_PLUS1];
 #else
-  Int     m_numSubDpbs                  [MAX_VPS_OP_LAYER_SETS_PLUS1];
+  Int        m_numSubDpbs                  [MAX_VPS_OP_LAYER_SETS_PLUS1];
 #endif
 #endif
@@ -670,14 +685,32 @@
 #endif
 
+#if O0164_MULTI_LAYER_HRD
+  Bool       m_vpsVuiBspHrdPresentFlag;
+  UInt       m_vpsNumBspHrdParametersMinus1;
+  Bool       m_bspCprmsPresentFlag[MAX_VPS_LAYER_SETS_PLUS1];
+  TComHRD    *m_bspHrd;
+  UInt       m_numBitstreamPartitions[MAX_VPS_LAYER_SETS_PLUS1];
+  Bool       m_layerInBspFlag[MAX_VPS_LAYER_SETS_PLUS1][8][MAX_LAYERS];
+  UInt       m_numBspSchedCombinations[MAX_VPS_LAYER_SETS_PLUS1];
+  UInt       m_bspCombHrdIdx[MAX_VPS_LAYER_SETS_PLUS1][16][16];
+  UInt       m_bspCombSchedIdx[MAX_VPS_LAYER_SETS_PLUS1][16][16];
+#endif
+
+#if P0182_VPS_VUI_PS_FLAG
+  UInt       m_SPSId[MAX_LAYERS];
+  UInt       m_PPSId[MAX_LAYERS];
+  UInt       m_baseLayerPSCompatibilityFlag[MAX_LAYERS];
+#endif
+
 #if !P0307_REMOVE_VPS_VUI_OFFSET
 #if VPS_VUI_OFFSET
-  Int     m_vpsVuiOffset;
+  Int        m_vpsVuiOffset;
 #endif
 #endif
 #if P0307_VPS_NON_VUI_EXTENSION
-  Int     m_vpsNonVuiExtLength;
+  Int        m_vpsNonVuiExtLength;
 #endif
 #if RESOLUTION_BASED_DPB
-  Int     m_subDpbAssigned            [MAX_VPS_LAYER_SETS_PLUS1][MAX_LAYERS];
+  Int        m_subDpbAssigned            [MAX_VPS_LAYER_SETS_PLUS1][MAX_LAYERS];
 #endif
 #endif //SVC_EXTENSION
@@ -692,4 +725,13 @@
     m_cprmsPresentFlag = new Bool   [ getNumHrdParameters() ];
   }
+
+#if O0164_MULTI_LAYER_HRD
+  Void    createBspHrdParamBuffer(UInt numHrds)
+  {
+    m_bspHrd    = new TComHRD[ numHrds ];
+//    m_hrdOpSetIdx      = new UInt   [ getNumHrdParameters() ];
+//    m_cprmsPresentFlag = new Bool   [ getNumHrdParameters() ];
+  }
+#endif
 
   TComHRD* getHrdParameters   ( UInt i )             { return &m_hrdParameters[ i ]; }
@@ -875,4 +917,8 @@
   Bool   getCrossLayerPictureTypeAlignFlag()                                    { return m_crossLayerPictureTypeAlignFlag;                      }
   Void   setCrossLayerPictureTypeAlignFlag(Bool x)                              { m_crossLayerPictureTypeAlignFlag = x;                         }
+#endif 
+#if P0068_CROSS_LAYER_ALIGNED_IDR_ONLY_FOR_IRAP_FLAG
+  Bool   getCrossLayerAlignedIdrOnlyFlag()                                    { return m_crossLayerAlignedIdrOnlyFlag;                      }
+  Void   setCrossLayerAlignedIdrOnlyFlag(Bool x)                              { m_crossLayerAlignedIdrOnlyFlag = x;                         }
 #endif 
 #if N0147_IRAP_ALIGN_FLAG
@@ -892,8 +938,8 @@
 #endif 
 #if VPS_TSLAYERS
-    Bool   getMaxTSLayersPresentFlag()                                  { return m_maxTSLayersPresentFlag ;}
-    Void   setMaxTSLayersPresentFlag(Bool x)                            { m_maxTSLayersPresentFlag = x;}
-    UInt   getMaxTSLayersMinus1(Int layerId)                            { return m_maxTSLayerMinus1[layerId];}
-    Void   setMaxTSLayersMinus1(Int layerId, UInt maxTSublayer)         { m_maxTSLayerMinus1[layerId] = maxTSublayer;}
+  Bool   getMaxTSLayersPresentFlag()                                  { return m_maxTSLayersPresentFlag ;}
+  Void   setMaxTSLayersPresentFlag(Bool x)                            { m_maxTSLayersPresentFlag = x;}
+  UInt   getMaxTSLayersMinus1(Int layerId)                            { return m_maxTSLayerMinus1[layerId];}
+  Void   setMaxTSLayersMinus1(Int layerId, UInt maxTSublayer)         { m_maxTSLayerMinus1[layerId] = maxTSublayer;}
 #endif
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
@@ -924,59 +970,97 @@
 #endif 
 #if N0160_VUI_EXT_ILP_REF  
-  Bool  getIlpRestrictedRefLayersFlag   ( )                                        { return m_ilpRestrictedRefLayersFlag        ;}
-  Void  setIlpRestrictedRefLayersFlag   ( Int val )                                { m_ilpRestrictedRefLayersFlag         = val;}
-  
-  Int  getMinSpatialSegmentOffsetPlus1( Int currLayerId, Int refLayerId )          { return m_minSpatialSegmentOffsetPlus1[currLayerId][refLayerId];}
-  Void setMinSpatialSegmentOffsetPlus1( Int currLayerId, Int refLayerId, Int val ) { m_minSpatialSegmentOffsetPlus1[currLayerId][refLayerId] = val;}
-  
-  Bool getCtuBasedOffsetEnabledFlag   ( Int currLayerId, Int refLayerId )            { return m_ctuBasedOffsetEnabledFlag[currLayerId][refLayerId];}
-  Void setCtuBasedOffsetEnabledFlag   ( Int currLayerId, Int refLayerId, Bool flag ) { m_ctuBasedOffsetEnabledFlag[currLayerId][refLayerId] = flag;}
-  
-  Int  getMinHorizontalCtuOffsetPlus1 ( Int currLayerId, Int refLayerId )            { return m_minHorizontalCtuOffsetPlus1[currLayerId][refLayerId];}
-  Void setMinHorizontalCtuOffsetPlus1 ( Int currLayerId, Int refLayerId, Int val )   { m_minHorizontalCtuOffsetPlus1[currLayerId][refLayerId] = val;}  
+  Bool   getIlpRestrictedRefLayersFlag   ( )                                        { return m_ilpRestrictedRefLayersFlag        ;}
+  Void   setIlpRestrictedRefLayersFlag   ( Int val )                                { m_ilpRestrictedRefLayersFlag         = val;}
+  
+  Int    getMinSpatialSegmentOffsetPlus1( Int currLayerId, Int refLayerId )          { return m_minSpatialSegmentOffsetPlus1[currLayerId][refLayerId];}
+  Void   setMinSpatialSegmentOffsetPlus1( Int currLayerId, Int refLayerId, Int val ) { m_minSpatialSegmentOffsetPlus1[currLayerId][refLayerId] = val;}
+  
+  Bool   getCtuBasedOffsetEnabledFlag   ( Int currLayerId, Int refLayerId )            { return m_ctuBasedOffsetEnabledFlag[currLayerId][refLayerId];}
+  Void   setCtuBasedOffsetEnabledFlag   ( Int currLayerId, Int refLayerId, Bool flag ) { m_ctuBasedOffsetEnabledFlag[currLayerId][refLayerId] = flag;}
+  
+  Int    getMinHorizontalCtuOffsetPlus1 ( Int currLayerId, Int refLayerId )            { return m_minHorizontalCtuOffsetPlus1[currLayerId][refLayerId];}
+  Void   setMinHorizontalCtuOffsetPlus1 ( Int currLayerId, Int refLayerId, Int val )   { m_minHorizontalCtuOffsetPlus1[currLayerId][refLayerId] = val;}  
 #endif
 #if VPS_VUI_VIDEO_SIGNAL
-    Bool   getVideoSigPresentVpsFlag()           { return m_vidSigPresentVpsFlag; }
-    Void   setVideoSigPresentVpsFlag(Bool x)     { m_vidSigPresentVpsFlag = x;    }
-    Int    getNumVideoSignalInfo()               { return m_vpsVidSigInfo;        }
-    Void   setNumVideoSignalInfo(Int x)          { m_vpsVidSigInfo = x;           }
-    Int    getVideoSignalInfoIdx(Int idx)        { return m_vpsVidSigIdx[idx];    }
-    Void   setVideoSignalInfoIdx(Int idx, Int x) { m_vpsVidSigIdx[idx] = x;       }
-    Int    getVideoVPSFormat(Int idx)            { return m_vpsVidFormat[idx];    }
-    Void   setVideoVPSFormat(Int idx, Int x)     { m_vpsVidFormat[idx] = x;       }
-    Bool   getVideoFullRangeVpsFlag(Int idx)     { return m_vpsFullRangeFlag[idx];}
-    Void   setVideoFullRangeVpsFlag(Int idx, Bool x) { m_vpsFullRangeFlag[idx] = x;   }
-    Int    getColorPrimaries(Int idx)            { return m_vpsColorPrimaries[idx];   }
-    Void   setColorPrimaries(Int idx, Int x)     { m_vpsColorPrimaries[idx] = x;      }
-    Int    getTransCharacter(Int idx)            { return m_vpsTransChar[idx];    }
-    Void   setTransCharacter(Int idx, Int x)     { m_vpsTransChar[idx] = x;       }
-    Int    getMaxtrixCoeff(Int idx)              { return m_vpsMatCoeff[idx];     }
-    Void   setMaxtrixCoeff(Int idx, Int x)       { m_vpsMatCoeff[idx] = x;        }
+  Bool   getVideoSigPresentVpsFlag()           { return m_vidSigPresentVpsFlag; }
+  Void   setVideoSigPresentVpsFlag(Bool x)     { m_vidSigPresentVpsFlag = x;    }
+  Int    getNumVideoSignalInfo()               { return m_vpsVidSigInfo;        }
+  Void   setNumVideoSignalInfo(Int x)          { m_vpsVidSigInfo = x;           }
+  Int    getVideoSignalInfoIdx(Int idx)        { return m_vpsVidSigIdx[idx];    }
+  Void   setVideoSignalInfoIdx(Int idx, Int x) { m_vpsVidSigIdx[idx] = x;       }
+  Int    getVideoVPSFormat(Int idx)            { return m_vpsVidFormat[idx];    }
+  Void   setVideoVPSFormat(Int idx, Int x)     { m_vpsVidFormat[idx] = x;       }
+  Bool   getVideoFullRangeVpsFlag(Int idx)     { return m_vpsFullRangeFlag[idx];}
+  Void   setVideoFullRangeVpsFlag(Int idx, Bool x) { m_vpsFullRangeFlag[idx] = x;   }
+  Int    getColorPrimaries(Int idx)            { return m_vpsColorPrimaries[idx];   }
+  Void   setColorPrimaries(Int idx, Int x)     { m_vpsColorPrimaries[idx] = x;      }
+  Int    getTransCharacter(Int idx)            { return m_vpsTransChar[idx];    }
+  Void   setTransCharacter(Int idx, Int x)     { m_vpsTransChar[idx] = x;       }
+  Int    getMaxtrixCoeff(Int idx)              { return m_vpsMatCoeff[idx];     }
+  Void   setMaxtrixCoeff(Int idx, Int x)       { m_vpsMatCoeff[idx] = x;        }
 #endif
 #if VPS_VUI_BITRATE_PICRATE
-  Bool getBitRatePresentVpsFlag()       { return m_bitRatePresentVpsFlag; }
-  Void setBitRatePresentVpsFlag(Bool x) { m_bitRatePresentVpsFlag = x;    }
-  Bool getPicRatePresentVpsFlag()       { return m_picRatePresentVpsFlag; }
-  Void setPicRatePresentVpsFlag(Bool x) { m_picRatePresentVpsFlag = x;    }
-
-  Bool getBitRatePresentFlag(Int i, Int j)          { return m_bitRatePresentFlag[i][j]; }
-  Void setBitRatePresentFlag(Int i, Int j, Bool x)  { m_bitRatePresentFlag[i][j] = x;    }
-  Bool getPicRatePresentFlag(Int i, Int j)          { return m_picRatePresentFlag[i][j]; }
-  Void setPicRatePresentFlag(Int i, Int j, Bool x)  { m_picRatePresentFlag[i][j] = x;    }
-  
-  Int  getAvgBitRate(Int i, Int j)          { return m_avgBitRate[i][j]; }
-  Void setAvgBitRate(Int i, Int j, Int x)   { m_avgBitRate[i][j] = x;    }
-  Int  getMaxBitRate(Int i, Int j)          { return m_maxBitRate[i][j]; }
-  Void setMaxBitRate(Int i, Int j, Int x)   { m_maxBitRate[i][j] = x;    }
-  
-  Int  getConstPicRateIdc(Int i, Int j)          { return m_constPicRateIdc[i][j]; }
-  Void setConstPicRateIdc(Int i, Int j, Int x)   { m_constPicRateIdc[i][j] = x;    }
-  Int  getAvgPicRate(Int i, Int j)          { return m_avgPicRate[i][j]; }
-  Void setAvgPicRate(Int i, Int j, Int x)   { m_avgPicRate[i][j] = x;    }
-#endif
+  Bool   getBitRatePresentVpsFlag()       { return m_bitRatePresentVpsFlag; }
+  Void   setBitRatePresentVpsFlag(Bool x) { m_bitRatePresentVpsFlag = x;    }
+  Bool   getPicRatePresentVpsFlag()       { return m_picRatePresentVpsFlag; }
+  Void   setPicRatePresentVpsFlag(Bool x) { m_picRatePresentVpsFlag = x;    }
+         
+  Bool   getBitRatePresentFlag(Int i, Int j)          { return m_bitRatePresentFlag[i][j]; }
+  Void   setBitRatePresentFlag(Int i, Int j, Bool x)  { m_bitRatePresentFlag[i][j] = x;    }
+  Bool   getPicRatePresentFlag(Int i, Int j)          { return m_picRatePresentFlag[i][j]; }
+  Void   setPicRatePresentFlag(Int i, Int j, Bool x)  { m_picRatePresentFlag[i][j] = x;    }
+         
+  Int    getAvgBitRate(Int i, Int j)          { return m_avgBitRate[i][j]; }
+  Void   setAvgBitRate(Int i, Int j, Int x)   { m_avgBitRate[i][j] = x;    }
+  Int    getMaxBitRate(Int i, Int j)          { return m_maxBitRate[i][j]; }
+  Void   setMaxBitRate(Int i, Int j, Int x)   { m_maxBitRate[i][j] = x;    }
+         
+  Int    getConstPicRateIdc(Int i, Int j)          { return m_constPicRateIdc[i][j]; }
+  Void   setConstPicRateIdc(Int i, Int j, Int x)   { m_constPicRateIdc[i][j] = x;    }
+  Int    getAvgPicRate(Int i, Int j)          { return m_avgPicRate[i][j]; }
+  Void   setAvgPicRate(Int i, Int j, Int x)   { m_avgPicRate[i][j] = x;    }
+#endif
+#if O0164_MULTI_LAYER_HRD
+  Bool     getVpsVuiBspHrdPresentFlag()                         { return m_vpsVuiBspHrdPresentFlag;      }
+  Void     setVpsVuiBspHrdPresentFlag(Bool x)                   { m_vpsVuiBspHrdPresentFlag = x;         }
+  UInt     getVpsNumBspHrdParametersMinus1()                    { return m_vpsNumBspHrdParametersMinus1; }
+  Void     setVpsNumBspHrdParametersMinus1(UInt i)              { m_vpsNumBspHrdParametersMinus1 = i;    }
+  Bool     getBspCprmsPresentFlag(UInt i)                       { return m_bspCprmsPresentFlag[i];       }
+  Void     setBspCprmsPresentFlag(UInt i, Bool val)             { m_bspCprmsPresentFlag[i] = val;        }
+  TComHRD* getBspHrd(UInt i)                                    { return &m_bspHrd[i];                    }
+  UInt     getNumBitstreamPartitions(UInt i)                    { return m_numBitstreamPartitions[i];    }
+  Void     setNumBitstreamPartitions(UInt i, UInt val)          { m_numBitstreamPartitions[i] = val;     }
+  UInt     getLayerInBspFlag(UInt h, UInt i, UInt j)            { return m_layerInBspFlag[h][i][j];      }
+  Void     setLayerInBspFlag(UInt h, UInt i, UInt j, UInt val)  { m_layerInBspFlag[h][i][j] = val;       }
+  UInt     getNumBspSchedCombinations(UInt i)                   { return m_numBspSchedCombinations[i];   }
+  Void     setNumBspSchedCombinations(UInt i, UInt val)         { m_numBspSchedCombinations[i] = val;    }
+  UInt     getBspCombHrdIdx(UInt h, UInt i, UInt j)             { return m_bspCombHrdIdx[h][i][j];       }
+  Void     setBspCombHrdIdx(UInt h, UInt i, UInt j, UInt val)   { m_bspCombHrdIdx[h][i][j] = val;        }
+  UInt     getBspCombSchedIdx(UInt h, UInt i, UInt j)           { return m_bspCombSchedIdx[h][i][j];     }
+  Void     setBspCombSchedIdx(UInt h, UInt i, UInt j, UInt val) { m_bspCombSchedIdx[h][i][j] = val;      }
+#endif
+#if P0182_VPS_VUI_PS_FLAG
+  Int    getSPSId       (Int layer)                   { return m_SPSId[layer];       }
+  Void   setSPSId       (Int layer, Int val)          { m_SPSId[layer] = val;        }
+  Int    getPPSId       (Int layer)                   { return m_PPSId[layer];       }
+  Void   setPPSId       (Int layer, Int val)          { m_PPSId[layer] = val;        }
+  Void   setBaseLayerPSCompatibilityFlag (Int layer, int val)        { m_baseLayerPSCompatibilityFlag[layer] = val; }
+  Int    getBaseLayerPSCompatibilityFlag (Int layer)   { return m_baseLayerPSCompatibilityFlag[layer];}
+#endif
+
+#if P0312_VERT_PHASE_ADJ
+  Bool   getVpsVuiVertPhaseInUseFlag()       { return m_vpsVuiVertPhaseInUseFlag; }
+  Void   setVpsVuiVertPhaseInUseFlag(Bool x) { m_vpsVuiVertPhaseInUseFlag = x;    }
+#endif
+
+#if P0300_ALT_OUTPUT_LAYER_FLAG
+  Bool   getAltOuputLayerFlag(Int idx)         { return m_altOutputLayerFlag[idx]; }
+  Void   setAltOuputLayerFlag(Int idx, Bool x) { m_altOutputLayerFlag[idx] = x;    }
+#else
 #if O0153_ALT_OUTPUT_LAYER_FLAG
   Bool   getAltOuputLayerFlag()             { return m_altOutputLayerFlag; }
   Void   setAltOuputLayerFlag(Bool x)       { m_altOutputLayerFlag = x;    }
 #endif
+#endif
 #if REPN_FORMAT_IN_VPS
   Bool   getRepFormatIdxPresentFlag()       { return m_repFormatIdxPresentFlag; }
@@ -988,29 +1072,29 @@
   RepFormat* getVpsRepFormat(Int idx)       { return &m_vpsRepFormat[idx];      }
 
-  Int    getVpsRepFormatIdx(Int idx)        { return m_vpsRepFormatIdx[idx];   }
-  Void   setVpsRepFormatIdx(Int idx, Int x) { m_vpsRepFormatIdx[idx] = x;      }         
+  Int    getVpsRepFormatIdx(Int idx)        { return m_vpsRepFormatIdx[idx];    }
+  Void   setVpsRepFormatIdx(Int idx, Int x) { m_vpsRepFormatIdx[idx] = x;       }         
 #endif
 #if VIEW_ID_RELATED_SIGNALING
 #if O0109_VIEW_ID_LEN
-  Void    setViewIdLen( Int  val )                                   { m_viewIdLen = val; } 
-  Int     getViewIdLen(  )                                           { return m_viewIdLen; } 
+  Void   setViewIdLen( Int  val )                                   { m_viewIdLen = val;  } 
+  Int    getViewIdLen(  )                                           { return m_viewIdLen; } 
 #else
-  Void    setViewIdLenMinus1( Int  val )                                   { m_viewIdLenMinus1 = val; } 
-  Int     getViewIdLenMinus1(  )                                           { return m_viewIdLenMinus1; } 
-#endif
-
-  Void    setViewIdVal( Int viewOrderIndex, Int  val )                     { m_viewIdVal[viewOrderIndex] = val; } 
-  Int     getViewIdVal( Int viewOrderIndex )                               { return m_viewIdVal[viewOrderIndex]; } 
-  Int     getScalabilityId(Int, ScalabilityType scalType );
-
-  Int     getViewIndex    ( Int layerIdInNuh )                             { return getScalabilityId( getLayerIdInVps(layerIdInNuh), VIEW_ORDER_INDEX  ); }    
-
-  Int     getNumViews();
-  Int     scalTypeToScalIdx( ScalabilityType scalType );
+  Void   setViewIdLenMinus1( Int  val )                             { m_viewIdLenMinus1 = val;  } 
+  Int    getViewIdLenMinus1(  )                                     { return m_viewIdLenMinus1; } 
+#endif
+
+  Void   setViewIdVal( Int viewOrderIndex, Int  val )               { m_viewIdVal[viewOrderIndex] = val;  } 
+  Int    getViewIdVal( Int viewOrderIndex )                         { return m_viewIdVal[viewOrderIndex]; } 
+  Int    getScalabilityId(Int, ScalabilityType scalType );
+
+  Int    getViewIndex    ( Int layerIdInNuh )                       { return getScalabilityId( getLayerIdInVps(layerIdInNuh), VIEW_ORDER_INDEX  ); }    
+
+  Int    getNumViews();
+  Int    scalTypeToScalIdx( ScalabilityType scalType );
 #endif
 #if !P0125_REVERT_VPS_EXTN_OFFSET_TO_RESERVED
 #if VPS_EXTN_OFFSET
-  Int     getExtensionOffset()                 { return m_extensionOffset;   }
-  Void    setExtensionOffset( UInt offset )    { m_extensionOffset = offset; }
+  Int    getExtensionOffset()                 { return m_extensionOffset;   }
+  Void   setExtensionOffset( UInt offset )    { m_extensionOffset = offset; }
 #endif
 #endif
@@ -1020,28 +1104,28 @@
 #endif
 #if VPS_DPB_SIZE_TABLE
-  Bool    getSubLayerFlagInfoPresentFlag(Int i)         {return m_subLayerFlagInfoPresentFlag[i]; }
-  Void    setSubLayerFlagInfoPresentFlag(Int i, Bool x) {m_subLayerFlagInfoPresentFlag[i] = x;    }
-
-  Bool    getSubLayerDpbInfoPresentFlag(Int i, Int j)         {return m_subLayerDpbInfoPresentFlag[i][j]; }
-  Void    setSubLayerDpbInfoPresentFlag(Int i, Int j, Bool x) {m_subLayerDpbInfoPresentFlag[i][j] = x;    }
+  Bool   getSubLayerFlagInfoPresentFlag(Int i)         {return m_subLayerFlagInfoPresentFlag[i]; }
+  Void   setSubLayerFlagInfoPresentFlag(Int i, Bool x) {m_subLayerFlagInfoPresentFlag[i] = x;    }
+
+  Bool   getSubLayerDpbInfoPresentFlag(Int i, Int j)         {return m_subLayerDpbInfoPresentFlag[i][j]; }
+  Void   setSubLayerDpbInfoPresentFlag(Int i, Int j, Bool x) {m_subLayerDpbInfoPresentFlag[i][j] = x;    }
 
   // For the 0-th output layer set, use the date from the active SPS for base layer.
-  Int     getMaxVpsDecPicBufferingMinus1(Int i, Int k, Int j)         { assert(i != 0); return m_maxVpsDecPicBufferingMinus1[i][k][j]; }
-  Void    setMaxVpsDecPicBufferingMinus1(Int i, Int k, Int j, Int x) { m_maxVpsDecPicBufferingMinus1[i][k][j] = x;    }
+  Int    getMaxVpsDecPicBufferingMinus1(Int i, Int k, Int j)         { assert(i != 0); return m_maxVpsDecPicBufferingMinus1[i][k][j]; }
+  Void   setMaxVpsDecPicBufferingMinus1(Int i, Int k, Int j, Int x) { m_maxVpsDecPicBufferingMinus1[i][k][j] = x;    }
 
 #if RESOLUTION_BASED_DPB
-  Int     getMaxVpsLayerDecPicBuffMinus1(Int i, Int k, Int j)        { assert(i != 0); return m_maxVpsLayerDecPicBuffMinus1[i][k][j]; }
-  Void    setMaxVpsLayerDecPicBuffMinus1(Int i, Int k, Int j, Int x) { m_maxVpsLayerDecPicBuffMinus1[i][k][j] = x;    }
-#endif
-
-  Int     getMaxVpsNumReorderPics(Int i, Int j)         { assert(i != 0); return m_maxVpsNumReorderPics[i][j]; }
-  Void    setMaxVpsNumReorderPics(Int i, Int j, Int x) { m_maxVpsNumReorderPics[i][j] = x;    }
-
-  Int     getMaxVpsLatencyIncreasePlus1(Int i, Int j)         { assert(i != 0); return m_maxVpsLatencyIncreasePlus1[i][j]; }
-  Void    setMaxVpsLatencyIncreasePlus1(Int i, Int j, Int x) { m_maxVpsLatencyIncreasePlus1[i][j] = x;    }
-
-  Int     getNumSubDpbs(Int i)                          { return m_numSubDpbs[i]; }
-  Void    setNumSubDpbs(Int i, Int x)                   { m_numSubDpbs[i] = x;    }
-  Void    determineSubDpbInfoFlags();
+  Int    getMaxVpsLayerDecPicBuffMinus1(Int i, Int k, Int j)        { assert(i != 0); return m_maxVpsLayerDecPicBuffMinus1[i][k][j]; }
+  Void   setMaxVpsLayerDecPicBuffMinus1(Int i, Int k, Int j, Int x) { m_maxVpsLayerDecPicBuffMinus1[i][k][j] = x;    }
+#endif
+
+  Int    getMaxVpsNumReorderPics(Int i, Int j)        { assert(i != 0); return m_maxVpsNumReorderPics[i][j]; }
+  Void   setMaxVpsNumReorderPics(Int i, Int j, Int x) { m_maxVpsNumReorderPics[i][j] = x;    }
+
+  Int    getMaxVpsLatencyIncreasePlus1(Int i, Int j)        { assert(i != 0); return m_maxVpsLatencyIncreasePlus1[i][j]; }
+  Void   setMaxVpsLatencyIncreasePlus1(Int i, Int j, Int x) { m_maxVpsLatencyIncreasePlus1[i][j] = x;    }
+
+  Int    getNumSubDpbs(Int i)                          { return m_numSubDpbs[i]; }
+  Void   setNumSubDpbs(Int i, Int x)                   { m_numSubDpbs[i] = x;    }
+  Void   determineSubDpbInfoFlags();
 #endif
 
@@ -1053,16 +1137,19 @@
 #if !P0307_REMOVE_VPS_VUI_OFFSET
 #if VPS_VUI_OFFSET
-  Int     getVpsVuiOffset()         { return m_vpsVuiOffset; }
-  Void    setVpsVuiOffset(Int x)    { m_vpsVuiOffset = x; }
+  Int    getVpsVuiOffset()         { return m_vpsVuiOffset; }
+  Void   setVpsVuiOffset(Int x)    { m_vpsVuiOffset = x; }
 #endif
 #endif
 #if P0307_VPS_NON_VUI_EXTENSION
-  Int     getVpsNonVuiExtLength()         { return m_vpsNonVuiExtLength; }
-  Void    setVpsNonVuiExtLength(Int x)    { m_vpsNonVuiExtLength = x; }
+  Int    getVpsNonVuiExtLength()         { return m_vpsNonVuiExtLength; }
+  Void   setVpsNonVuiExtLength(Int x)    { m_vpsNonVuiExtLength = x; }
 #endif
 #if RESOLUTION_BASED_DPB
-  Void assignSubDpbIndices();
-  Int  getSubDpbAssigned  (Int lsIdx, Int layerIdx) { return m_subDpbAssigned[lsIdx][layerIdx]; }
-  Int  findLayerIdxInLayerSet ( Int lsIdx, Int nuhLayerId );
+  Void   assignSubDpbIndices();
+  Int    getSubDpbAssigned  (Int lsIdx, Int layerIdx) { return m_subDpbAssigned[lsIdx][layerIdx]; }
+  Int    findLayerIdxInLayerSet ( Int lsIdx, Int nuhLayerId );
+#endif
+#if O0164_MULTI_LAYER_HRD
+  Void setBspHrdParameters( UInt hrdIdx, UInt frameRate, UInt numDU, UInt bitRate, Bool randomAccess );
 #endif
 #endif //SVC_EXTENSION
@@ -1077,4 +1164,7 @@
   Int           m_winTopOffset;
   Int           m_winBottomOffset;
+#if P0312_VERT_PHASE_ADJ
+  Bool          m_vertPhasePositionEnableFlag;
+#endif
 public:
   Window()
@@ -1084,8 +1174,15 @@
   , m_winTopOffset      (0)
   , m_winBottomOffset   (0)
+#if P0312_VERT_PHASE_ADJ
+  , m_vertPhasePositionEnableFlag(false)  
+#endif
   { }
 
   Bool          getWindowEnabledFlag() const      { return m_enabledFlag; }
-  Void          resetWindow()                     { m_enabledFlag = false; m_winLeftOffset = m_winRightOffset = m_winTopOffset = m_winBottomOffset = 0; }
+#if P0312_VERT_PHASE_ADJ 
+  Void          resetWindow()                     { m_enabledFlag = false; m_winLeftOffset = m_winRightOffset = m_winTopOffset = m_winBottomOffset = 0; m_vertPhasePositionEnableFlag = false; } 
+#else
+  Void          resetWindow()                     { m_enabledFlag = false; m_winLeftOffset = m_winRightOffset = m_winTopOffset = m_winBottomOffset = 0;} 
+#endif
   Int           getWindowLeftOffset() const       { return m_enabledFlag ? m_winLeftOffset : 0; }
   Void          setWindowLeftOffset(Int val)      { m_winLeftOffset = val; m_enabledFlag = true; }
@@ -1097,5 +1194,11 @@
   Void          setWindowBottomOffset(Int val)    { m_winBottomOffset = val; m_enabledFlag = true; }
 
+#if P0312_VERT_PHASE_ADJ
+  Bool          getVertPhasePositionEnableFlag() const     { return m_vertPhasePositionEnableFlag;  }
+  Void          setVertPhasePositionEnableFlag(Bool val)    { m_vertPhasePositionEnableFlag = val;  }
+  Void          setWindow(Int offsetLeft, Int offsetLRight, Int offsetLTop, Int offsetLBottom, Bool vertPhasePositionEnableFlag = 0)
+#else
   Void          setWindow(Int offsetLeft, Int offsetLRight, Int offsetLTop, Int offsetLBottom)
+#endif
   {
     m_enabledFlag       = true;
@@ -1104,4 +1207,7 @@
     m_winTopOffset      = offsetLTop;
     m_winBottomOffset   = offsetLBottom;
+#if P0312_VERT_PHASE_ADJ
+    m_vertPhasePositionEnableFlag = vertPhasePositionEnableFlag;    
+#endif
   }
 };
@@ -1353,6 +1459,9 @@
 
 #if SVC_EXTENSION
-  UInt m_layerId;
+  UInt        m_layerId;
   UInt        m_numScaledRefLayerOffsets;
+#if P0312_VERT_PHASE_ADJ
+ Bool         m_vertPhasePositionEnableFlag[MAX_LAYERS];
+#endif
 #if O0098_SCALED_REF_LAYER_ID
   UInt        m_scaledRefLayerId[MAX_LAYERS];
@@ -1360,12 +1469,12 @@
   Window      m_scaledRefLayerWindow[MAX_LAYERS];
 #if REPN_FORMAT_IN_VPS
-  Bool m_updateRepFormatFlag;
+  Bool        m_updateRepFormatFlag;
 #if O0096_REP_FORMAT_INDEX
-  UInt m_updateRepFormatIndex;
+  UInt        m_updateRepFormatIndex;
 #endif
 #endif
 #if SCALINGLIST_INFERRING
-  Bool       m_inferScalingListFlag;
-  UInt       m_scalingListRefLayerId;
+  Bool        m_inferScalingListFlag;
+  UInt        m_scalingListRefLayerId;
 #endif
 #endif //SVC_EXTENSION
@@ -1507,11 +1616,15 @@
 
 #if SVC_EXTENSION
-  Void     setLayerId(UInt layerId) { m_layerId = layerId; }
-  UInt     getLayerId() { return m_layerId; }
-  UInt     getNumScaledRefLayerOffsets()  { return m_numScaledRefLayerOffsets; }
-  Void     setNumScaledRefLayerOffsets(Int x)  { m_numScaledRefLayerOffsets = x; }
+  Void     setLayerId(UInt layerId)            { m_layerId = layerId; }
+  UInt     getLayerId()                        { return m_layerId;    }
+  UInt     getNumScaledRefLayerOffsets()       { return m_numScaledRefLayerOffsets; }
+  Void     setNumScaledRefLayerOffsets(Int x)  { m_numScaledRefLayerOffsets = x;    }
+#if P0312_VERT_PHASE_ADJ
+  Bool     getVertPhasePositionEnableFlag(Int x)          { return m_vertPhasePositionEnableFlag[x]; }
+  Void     setVertPhasePositionEnableFlag(Int x, Bool b)  { m_vertPhasePositionEnableFlag[x] = b;    } 
+#endif
 #if O0098_SCALED_REF_LAYER_ID
   UInt     getScaledRefLayerId(Int x)          { return m_scaledRefLayerId[x]; }
-  Void     setScaledRefLayerId(Int x, UInt id) { m_scaledRefLayerId[x] = id; }
+  Void     setScaledRefLayerId(Int x, UInt id) { m_scaledRefLayerId[x] = id;   }
   Window&  getScaledRefLayerWindowForLayer( Int layerId );
 #endif
@@ -1624,4 +1737,7 @@
   Bool     m_inferScalingListFlag;
   UInt     m_scalingListRefLayerId;
+#endif
+#if POC_RESET_IDC
+  Bool     m_pocResetInfoPresentFlag;
 #endif
 #endif
@@ -1762,4 +1878,8 @@
   Bool getSliceHeaderExtensionPresentFlag   ()                    { return m_sliceHeaderExtensionPresentFlag; }
   Void setSliceHeaderExtensionPresentFlag   (Bool val)            { m_sliceHeaderExtensionPresentFlag = val; }
+#if POC_RESET_IDC
+  Bool getPocResetInfoPresentFlag   ()                    { return m_pocResetInfoPresentFlag; }
+  Void setPocResetInfoPresentFlag   (const Bool val)      { m_pocResetInfoPresentFlag = val; }
+#endif
 };
 
@@ -1899,4 +2019,7 @@
   Int         m_activeNumILRRefIdx;        //< Active inter-layer reference pictures
   Int         m_interLayerPredLayerIdc  [MAX_VPS_LAYER_ID_PLUS1];
+#if P0312_VERT_PHASE_ADJ
+  Bool        m_vertPhasePositionFlag[MAX_VPS_LAYER_ID_PLUS1];
+#endif
 #if POC_RESET_FLAG
   Bool        m_bPocResetFlag;
@@ -1906,4 +2029,18 @@
 #if O0149_CROSS_LAYER_BLA_FLAG
   Bool        m_bCrossLayerBLAFlag;
+#endif
+#if NO_OUTPUT_OF_PRIOR_PICS
+  Bool        m_noOutputOfPriorPicsFlag;
+  Bool        m_noRaslOutputFlag;
+  Bool        m_handleCraAsBlaFlag;
+#endif
+#if POC_RESET_IDC_SIGNALLING
+  Int         m_pocResetIdc;
+  Int         m_pocResetPeriodId;
+  Bool        m_fullPocResetFlag;
+  Int         m_pocLsbVal;
+  Int         m_pocMsbVal;
+  Bool        m_pocMsbValRequiredFlag;
+  Bool        m_pocMsbValPresentFlag;
 #endif
 #endif //SVC_EXTENSION
@@ -1993,4 +2130,8 @@
   NalUnitType getNalUnitType    () const                        { return m_eNalUnitType;        }
   Bool      getRapPicFlag       ();  
+#if NO_OUTPUT_OF_PRIOR_PICS
+  Bool      getBlaPicFlag       ();
+  Bool      getCraPicFlag       ();
+#endif
   Bool      getIdrPicFlag       ()                              { return getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP; }
   Bool      isIRAP              () const                        { return (getNalUnitType() >= 16) && (getNalUnitType() <= 23); }  
@@ -2170,4 +2311,9 @@
   Bool      getInterLayerPredEnabledFlag     ()                { return m_interLayerPredEnabledFlag;}
 
+#if P0312_VERT_PHASE_ADJ
+  Int       getVertPhasePositionFlag (UInt layerIdx)              { return   m_vertPhasePositionFlag[layerIdx];}
+  Void      setVertPhasePositionFlag (Bool b, UInt layerIdx)      {  m_vertPhasePositionFlag[layerIdx] = b;  }
+#endif
+
   Void      setNumMotionPredRefLayers(int i)            { m_numMotionPredRefLayers = i; }
   Int       getNumMotionPredRefLayers()                 { return m_numMotionPredRefLayers; }
@@ -2214,4 +2360,31 @@
 
   Void setILRPic(TComPic **pcIlpPic);
+#if NO_OUTPUT_OF_PRIOR_PICS
+  Void setNoOutputOfPriorPicsFlag(const Bool x)   { m_noOutputOfPriorPicsFlag = x;    }
+  Bool getNoOutputOfPriorPicsFlag()               { return m_noOutputOfPriorPicsFlag; }
+
+  Void setNoRaslOutputFlag    ( const Bool val )   { m_noRaslOutputFlag = val;  }
+  Bool getNoRaslOutputFlag    ()                   { return m_noRaslOutputFlag; }
+
+  Void setHandleCraAsBlaFlag  ( const Bool val )   { m_handleCraAsBlaFlag = val;  }
+  Bool getHandleCraAsBlaFlag  ()                   { return m_handleCraAsBlaFlag; }
+
+#endif
+#if POC_RESET_IDC_SIGNALLING
+  Int       getPocResetIdc       ()                              { return m_pocResetIdc;       }
+  Void      setPocResetIdc       (Int b)                         { m_pocResetIdc = b;          }
+  Int       getPocResetPeriodId  ()                              { return m_pocResetPeriodId;       }
+  Void      setPocResetPeriodId  (Int b)                         { m_pocResetPeriodId = b;          }
+  Bool      getFullPocResetFlag  ()                              { return m_fullPocResetFlag;       }
+  Void      setFullPocResetFlag  (Bool b)                        { m_fullPocResetFlag = b;          }
+  Int       getPocLsbVal         ()                              { return m_pocLsbVal;       }
+  Void      setPocLsbVal       (Int b)                           { m_pocLsbVal = b;          }
+  Int       getPocMsbVal         ()                              { return m_pocMsbVal;       }
+  Void      setPocMsbVal       (Int b)                           { m_pocMsbVal = b;          }
+  Bool      getPocMsbValPresentFlag ()                           { return m_pocMsbValPresentFlag; }
+  Void      setPocMsbValPresentFlag (Bool x)                     { m_pocMsbValPresentFlag = x; }
+  Bool      getPocMsbValRequiredFlag ()                           { return m_pocMsbValRequiredFlag; }
+  Void      setPocMsbValRequiredFlag (Bool x)                     { m_pocMsbValRequiredFlag = x; }
+#endif
 
 #endif //SVC_EXTENSION
Index: trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 597)
+++ trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 644)
@@ -127,4 +127,13 @@
   Int strideEL  = pcUsPic->getStride();
 
+#if P0312_VERT_PHASE_ADJ
+  Bool vertPhasePositionEnableFlag = scalEL.getVertPhasePositionEnableFlag();
+  Bool vertPhasePositionFlag = currSlice->getVertPhasePositionFlag( refLayerIdc );
+  if( vertPhasePositionFlag )
+  {
+    assert( vertPhasePositionEnableFlag );
+  }
+#endif
+
   Pel* piTempBufY = pcTempPic->getLumaAddr();
   Pel* piSrcBufY  = pcBasePic->getLumaAddr();
@@ -155,11 +164,24 @@
 #endif
 
+  // non-normative software optimization for certain simple resampling cases
   if( scaleX == 65536 && scaleY == 65536 ) // ratio 1x
   {
     piSrcY = piSrcBufY;
     piDstY = piDstBufY + scalEL.getWindowLeftOffset() + scalEL.getWindowTopOffset() * strideEL;
+
+#if O0194_JOINT_US_BITSHIFT
+    Int shift = g_bitDepthYLayer[currLayerId] - g_bitDepthYLayer[refLayerId];
+#endif
+
     for( i = 0; i < heightBL; i++ )
     {
+#if O0194_JOINT_US_BITSHIFT
+      for( j = 0; j < widthBL; j++ )
+      {
+        piDstY[j] = piSrcY[j] << shift;
+      }
+#else
       memcpy( piDstY, piSrcY, sizeof(Pel) * widthBL );
+#endif
       piSrcY += strideBL;
       piDstY += strideEL;
@@ -172,6 +194,6 @@
     heightBL >>= 1;
 
-    strideBL  = pcBasePic->getCStride();
-    strideEL  = pcUsPic->getCStride();
+    strideBL = pcBasePic->getCStride();
+    strideEL = pcUsPic->getCStride();
 
     piSrcU = piSrcBufU;
@@ -181,8 +203,20 @@
     piDstV = piDstBufV + ( scalEL.getWindowLeftOffset() >> 1 ) + ( scalEL.getWindowTopOffset() >> 1 ) * strideEL;
 
+#if O0194_JOINT_US_BITSHIFT
+    shift = g_bitDepthCLayer[currLayerId] - g_bitDepthCLayer[refLayerId];
+#endif
+
     for( i = 0; i < heightBL; i++ )
     {
+#if O0194_JOINT_US_BITSHIFT
+      for( j = 0; j < widthBL; j++ )
+      {
+        piDstU[j] = piSrcU[j] << shift;
+        piDstV[j] = piSrcV[j] << shift;
+      }
+#else
       memcpy( piDstU, piSrcU, sizeof(Pel) * widthBL );
       memcpy( piDstV, piSrcV, sizeof(Pel) * widthBL );
+#endif
       piSrcU += strideBL;
       piSrcV += strideBL;
@@ -191,5 +225,5 @@
     }
   }
-  else
+  else // general resampling process
   {
     Int refPos16 = 0;
@@ -212,5 +246,5 @@
 
     pcBasePic->setBorderExtension(false);
-    pcBasePic->extendPicBorder   (); // extend the border.
+    pcBasePic->extendPicBorder(); // extend the border.
 
     Int   shiftX = 16;
@@ -219,8 +253,16 @@
 #if O0215_PHASE_ALIGNMENT //for Luma, if Phase 0, then both PhaseX  and PhaseY should be 0. If symmetric: both PhaseX and PhaseY should be 2
     Int   phaseX = 2*phaseAlignFlag;
+#if P0312_VERT_PHASE_ADJ
+    Int   phaseY = vertPhasePositionEnableFlag ? ( vertPhasePositionFlag * 4 ) : ( 2 * phaseAlignFlag );
+#else
     Int   phaseY = 2*phaseAlignFlag;
+#endif
 #else
     Int   phaseX = 0;
+#if P0312_VERT_PHASE_ADJ
+    Int   phaseY = (vertPhasePositionEnableFlag?(vertPhasePositionFlag *4):(0));
+#else
     Int   phaseY = 0;
+#endif
 #endif
 
@@ -251,5 +293,5 @@
     Int leftOffset = leftStartL > 0 ? leftStartL : 0;
 
-#if  N0214_INTERMEDIATE_BUFFER_16BITS
+#if N0214_INTERMEDIATE_BUFFER_16BITS
 #if O0194_JOINT_US_BITSHIFT
     // g_bitDepthY was set to EL bit-depth, but shift1 should be calculated using BL bit-depth
@@ -274,5 +316,5 @@
       for( j = 0; j < heightBL ; j++ )
       {
-#if  N0214_INTERMEDIATE_BUFFER_16BITS
+#if N0214_INTERMEDIATE_BUFFER_16BITS
         *piDstY = sumLumaHor(piSrcY, coeff) >> shift1;
 #else
@@ -290,5 +332,5 @@
     pcTempPic->setHeight(heightEL);
 
-#if  N0214_INTERMEDIATE_BUFFER_16BITS
+#if N0214_INTERMEDIATE_BUFFER_16BITS
 #if O0194_JOINT_US_BITSHIFT
     Int nShift = 20 - g_bitDepthYLayer[currLayerId];
@@ -363,32 +405,29 @@
 
 #if O0215_PHASE_ALIGNMENT
+    Int phaseXC = phaseAlignFlag;
+#if P0312_VERT_PHASE_ADJ
+    Int phaseYC = vertPhasePositionEnableFlag ? ( vertPhasePositionFlag * 4 ) : ( phaseAlignFlag + 1 );
+#else
+    Int phaseYC = phaseAlignFlag + 1;
+#endif
+#else
     Int phaseXC = 0;
+#if P0312_VERT_PHASE_ADJ
+    Int phaseYC = vertPhasePositionEnableFlag ? (vertPhasePositionFlag * 4): 1;
+#else
     Int phaseYC = 1;
-
+#endif
+#endif
+    
 #if ROUNDING_OFFSET
-    addX       = ( ( (phaseXC+phaseAlignFlag) * scaleX + 2 ) >> 2 ) + ( 1 << ( shiftX - 5 ) );
-    addY       = ( ( (phaseYC+phaseAlignFlag) * scaleY + 2 ) >> 2 ) + ( 1 << ( shiftY - 5 ) );
-#else
-    addX       = ( ( ( widthBL * (phaseXC+phaseAlignFlag) ) << ( shiftX - 2 ) ) + ( widthEL >> 1 ) ) / widthEL + ( 1 << ( shiftX - 5 ) );
-    addY       = ( ( ( heightBL * (phaseYC+phaseAlignFlag) ) << ( shiftY - 2 ) ) + ( heightEL >> 1 ) ) / heightEL+ ( 1 << ( shiftY - 5 ) );
-#endif
-
-    deltaX     = 4 * (phaseXC+phaseAlignFlag);
-    deltaY     = 4 * (phaseYC+phaseAlignFlag);
-#else
-    phaseX = 0;
-    phaseY = 1;
-
-#if ROUNDING_OFFSET
-    addX       = ( ( phaseX * scaleX + 2 ) >> 2 ) + ( 1 << ( shiftX - 5 ) );
-    addY       = ( ( phaseY * scaleY + 2 ) >> 2 ) + ( 1 << ( shiftY - 5 ) );
-#else
-    addX       = ( ( ( widthBL * phaseX ) << ( shiftX - 2 ) ) + ( widthEL >> 1 ) ) / widthEL + ( 1 << ( shiftX - 5 ) );
-    addY       = ( ( ( heightBL * phaseY ) << ( shiftY - 2 ) ) + ( heightEL >> 1 ) ) / heightEL+ ( 1 << ( shiftY - 5 ) );
-#endif
-
-    deltaX     = 4 * phaseX;
-    deltaY     = 4 * phaseY;
-#endif
+    addX       = ( ( phaseXC * scaleX + 2 ) >> 2 ) + ( 1 << ( shiftX - 5 ) );
+    addY       = ( ( phaseYC * scaleY + 2 ) >> 2 ) + ( 1 << ( shiftY - 5 ) );
+#else
+    addX       = ( ( ( widthBL * (phaseXC) ) << ( shiftX - 2 ) ) + ( widthEL >> 1 ) ) / widthEL + ( 1 << ( shiftX - 5 ) );
+    addY       = ( ( ( heightBL * (phaseYC) ) << ( shiftY - 2 ) ) + ( heightEL >> 1 ) ) / heightEL+ ( 1 << ( shiftY - 5 ) );
+#endif
+
+    deltaX     = 4 * phaseXC;
+    deltaY     = 4 * phaseYC;
 
     shiftXM4 = shiftX - 4;
@@ -401,5 +440,5 @@
     heightBL  = min<Int>( pcBasePic->getHeight() >> 1, heightEL );
 
-#if  N0214_INTERMEDIATE_BUFFER_16BITS
+#if N0214_INTERMEDIATE_BUFFER_16BITS
 #if O0194_JOINT_US_BITSHIFT
     // g_bitDepthC was set to EL bit-depth, but shift1 should be calculated using BL bit-depth
@@ -426,5 +465,5 @@
       for( j = 0; j < heightBL ; j++ )
       {
-#if  N0214_INTERMEDIATE_BUFFER_16BITS
+#if N0214_INTERMEDIATE_BUFFER_16BITS
         *piDstU = sumChromaHor(piSrcU, coeff) >> shift1;
         *piDstV = sumChromaHor(piSrcV, coeff) >> shift1;
@@ -447,5 +486,5 @@
     pcTempPic->setHeight(heightEL << 1);
 
-#if  N0214_INTERMEDIATE_BUFFER_16BITS
+#if N0214_INTERMEDIATE_BUFFER_16BITS
 #if O0194_JOINT_US_BITSHIFT
     nShift = 20 - g_bitDepthCLayer[currLayerId];
Index: trunk/source/Lib/TLibCommon/TComUpsampleFilter.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComUpsampleFilter.h	(revision 597)
+++ trunk/source/Lib/TLibCommon/TComUpsampleFilter.h	(revision 644)
@@ -45,7 +45,7 @@
 #if O0215_PHASE_ALIGNMENT
 #if O0194_JOINT_US_BITSHIFT
-  Void upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, bool phaseAlignFlag );
+  Void upsampleBasePic( TComSlice* currSlice, UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, Bool phaseAlignFlag );
 #else
-  Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, bool phaseAlignFlag );
+  Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window, Bool phaseAlignFlag );
 #endif
 #else
Index: trunk/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- trunk/source/Lib/TLibCommon/TypeDef.h	(revision 597)
+++ trunk/source/Lib/TLibCommon/TypeDef.h	(revision 644)
@@ -50,7 +50,9 @@
 #define O0137_MAX_LAYERID                1      ///< JCTVC-O0137, JCTVC-O0200, JCTVC-O0223: restrict nuh_layer_id and vps_max_layers_minus1
 
+#define P0312_VERT_PHASE_ADJ             1      ///< JCTVC-P0312: vertical phase adjustment in re-sampling process (BoG report)
 #define P0130_EOB                        1      ///< JCTVC-P0130, set layer Id of EOB NALU to be fixed to 0
 #define P0307_REMOVE_VPS_VUI_OFFSET      1      ///< JCTVC-P0307, remove implementation related to VPS VUI offset signalling
 #define P0307_VPS_NON_VUI_EXTENSION      1      ///< JCTVC-P0307, implementation related to NON VUI VPS Extension signalling
+#define P0307_VPS_NON_VUI_EXT_UPDATE     1      ///< JCTVC-P0307, implementation related to NON VUI VPS Extension signalling
 
 #define DISCARDABLE_PIC_RPS              1      ///< JCTVC-P0130: Inter-layer RPS and temporal RPS should not contain picture with discardable_flag equal to 1
@@ -58,4 +60,6 @@
 #define CHANGE_NUMSUBDPB_IDX             1      ///< Change index of NumSubDpb from output layer set to layer set, to be more aligned with the Spec
 #define RESOLUTION_BASED_DPB             1      ///< JCTVC-P0192: Assign layers to sub-DPBs based on the rep_format() signaled in the VPS
+#define ALIGNED_BUMPING                  1      ///< JCTVC-P0192: Align bumping of pictures in an AU
+#define MAX_SUBDPBS                      MAX_LAYERS
 #define SUB_BITSTREAM_PROPERTY_SEI       1      ///< JCTVC-P0204: Sub-bitstream property SEI message
 #if SUB_BITSTREAM_PROPERTY_SEI
@@ -75,4 +79,6 @@
 
 #define O0135_DEFAULT_ONE_OUT_SEMANTIC   1      ///< JCTVC-O0135: semantics change of default_one_target_output_layer_idc for auxiliary pictures
+
+#define O0164_MULTI_LAYER_HRD            1      ///< JCTVC-O0164: Multi-layer HRD operation
 
 #define O0194_DIFFERENT_BITDEPTH_EL_BL   1      ///< JCTVC-O0194: Support for different bitdepth values for BL and EL, add required configuration parameters (and Some bugfixes when REPN_FORMAT_IN_VPS (JCTVC-N0092) is enabled)
@@ -84,4 +90,9 @@
 #define VPS_NUH_LAYER_ID                 1      ///< JCTVC-N0085: Assert that the nuh_layer_id of VPS NAL unit should be 0
 #define POC_RESET_FLAG                   1      ///< JCTVC-N0244: POC reset flag for  layer pictures.
+#define POC_RESET_IDC                    1      ///< JCTVC-P0041: Include poc_reset_idc and related derivation - eventually will replace POC_RESET_FLAG
+#if POC_RESET_IDC
+#define POC_RESET_IDC_SIGNALLING         1      ///< JCTVC-P0041: Include signalling for poc_reset related syntax elements
+#endif
+#define NO_OUTPUT_OF_PRIOR_PICS          1      ///< Use no_output_of_prior_pics_flag
 #define ALIGN_TSA_STSA_PICS              1      ///< JCTVC-N0084: Alignment of TSA and STSA pictures across AU.
 #define REPN_FORMAT_IN_VPS               1      ///< JCTVC-N0092: Signal represenation format (spatial resolution, bit depth, colour format) in the VPS
@@ -137,4 +148,5 @@
 #define VPS_VUI_VIDEO_SIGNAL_MOVE        1      ///< JCTVC-P0076 Move video signal information syntax structure earlier in the VPS VUI
 #endif 
+#define P0182_VPS_VUI_PS_FLAG            1      ///< JCTVC-P0182, add base_layer_parameter_set_compatibility_flag
 #endif //VPS_VUI
 
@@ -179,4 +191,6 @@
 #define O0223_PICTURE_TYPES_ALIGN_FLAG   1  ///< a flag to indicatate whether picture types are aligned across layers.
 
+#define P0068_CROSS_LAYER_ALIGNED_IDR_ONLY_FOR_IRAP_FLAG   1  ///< a flag to indicatate whether picture types for IRAP are IDR across layers.
+
 #define N0147_IRAP_ALIGN_FLAG            1      ///< a flag to indicatate whether IRAPs are aligned across layers
 #if N0147_IRAP_ALIGN_FLAG
@@ -216,4 +230,5 @@
 
 #define O0153_ALT_OUTPUT_LAYER_FLAG      1      ///< JCTVC-O0153: alt output layer flag
+#define P0300_ALT_OUTPUT_LAYER_FLAG      1      ///< JCTVC-P0300: alt output layer flag
 
 #define VPS_DPB_SIZE_TABLE               1      ///< JCTVC-O0217: DPB operations: signaling DPB-related parameters
@@ -224,7 +239,12 @@
 #endif
 #endif
-
+#define SPS_DPB_PARAMS                   1      ///< JCTVC-P0155 signaling & inferrence for sps dpb parameters for nuh_layer_id > 0
+#define DPB_PARAMS_MAXTLAYERS            1      ///< JCTVC-P0156 DPB parameters up to maximum temporal sub-layers in the layer set
+#define NUM_OL_FLAGS                     1      ///< JCTVC-P0156 output_layer_flag[ i ][ j ] is signalled for j equal to 0 to NumLayersInIdList[ lsIdx ] inclusive
 #define NO_CLRAS_OUTPUT_FLAG             1
 #define O0149_CROSS_LAYER_BLA_FLAG       1      ///< JCTVC-O0149: signal cross_layer_bla_flag in slice header
+
+#define P0138_USE_ALT_CPB_PARAMS_FLAG    1      ///< JCTVC-P0138: use_alt_cpb_params_flag syntax in buffering period SEI message extension
+#define P0166_MODIFIED_PPS_EXTENSION     1      ///< JCTVC-P0166: add pps_extension_type_flag
 
 #if VIEW_ID_RELATED_SIGNALING
Index: trunk/source/Lib/TLibDecoder/SEIread.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/SEIread.cpp	(revision 597)
+++ trunk/source/Lib/TLibDecoder/SEIread.cpp	(revision 644)
@@ -111,7 +111,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 parition 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
@@ -152,8 +163,16 @@
 }
 
+#if O0164_MULTI_LAYER_HRD
+#if LAYERS_NOT_PRESENT_SEI
+Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps, const SEIScalableNesting *nestingSei, const SEIBspNesting *bspNestingSei)
+#else
+Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps, const SEIScalableNesting *nestingSei)
+#endif
+#else
 #if LAYERS_NOT_PRESENT_SEI
 Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps)
 #else
 Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps)
+#endif
 #endif
 {
@@ -272,4 +291,5 @@
       xParseSEIScalableNesting((SEIScalableNesting&) *sei, nalUnitType, payloadSize, sps);
 #endif
+      break;
 #if SVC_EXTENSION
 #if LAYERS_NOT_PRESENT_SEI
@@ -296,4 +316,22 @@
      sei = new SEISubBitstreamProperty;
      xParseSEISubBitstreamProperty((SEISubBitstreamProperty&) *sei);
+     break;
+#endif
+#if O0164_MULTI_LAYER_HRD
+   case SEI::BSP_NESTING:
+     sei = new SEIBspNesting;
+#if LAYERS_NOT_PRESENT_SEI
+     xParseSEIBspNesting((SEIBspNesting&) *sei, nalUnitType, vps, sps, *nestingSei);
+#else
+     xParseSEIBspNesting((SEIBspNesting&) *sei, nalUnitType, sps, *nestingSei);
+#endif
+     break;
+   case SEI::BSP_INITIAL_ARRIVAL_TIME:
+     sei = new SEIBspInitialArrivalTime;
+     xParseSEIBspInitialArrivalTime((SEIBspInitialArrivalTime&) *sei, vps, sps, *nestingSei, *bspNestingSei);
+     break;
+   case SEI::BSP_HRD:
+     sei = new SEIBspHrd;
+     xParseSEIBspHrd((SEIBspHrd&) *sei, sps, *nestingSei);
      break;
 #endif
@@ -380,4 +418,36 @@
 }
 
+#if P0138_USE_ALT_CPB_PARAMS_FLAG
+/**
+ * Check if SEI message contains payload extension
+ */
+Bool SEIReader::xPayloadExtensionPresent()
+{
+  Int payloadBitsRemaining = getBitstream()->getNumBitsLeft();
+  Bool payloadExtensionPresent = false;
+
+  if (payloadBitsRemaining > 8)
+  {
+    payloadExtensionPresent = true;
+  }
+  else
+  {
+    Int finalBits = getBitstream()->peekBits(payloadBitsRemaining);
+    while (payloadBitsRemaining && (finalBits & 1) == 0)
+    {
+      payloadBitsRemaining--;
+      finalBits >>= 1;
+    }
+    payloadBitsRemaining--;
+    if (payloadBitsRemaining > 0)
+    {
+      payloadExtensionPresent = true;
+    }
+  }
+
+  return payloadExtensionPresent;
+}
+#endif
+
 /**
  * parse bitstream bs and unpack a user_data_unregistered SEI message
@@ -536,4 +606,16 @@
     }
   }
+
+#if P0138_USE_ALT_CPB_PARAMS_FLAG
+  sei.m_useAltCpbParamsFlag = false;
+  sei.m_useAltCpbParamsFlagPresent = false;
+  if (xPayloadExtensionPresent())
+  {
+    READ_FLAG (code, "use_alt_cpb_params_flag");
+    sei.m_useAltCpbParamsFlag = code;
+    sei.m_useAltCpbParamsFlagPresent = true;
+  }
+#endif
+
   xParseByteAlign();
 }
@@ -826,8 +908,16 @@
   // read nested SEI messages
   do {
+#if O0164_MULTI_LAYER_HRD
+#if LAYERS_NOT_PRESENT_SEI
+    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps, &sei);
+#else
+    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps, &sei);
+#endif
+#else
 #if LAYERS_NOT_PRESENT_SEI
     xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps);
 #else
     xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps);
+#endif
 #endif
   } while (m_pcBitstream->getNumBitsLeft() > 8);
@@ -930,4 +1020,193 @@
 }
 #endif
+
+#if O0164_MULTI_LAYER_HRD
+#if LAYERS_NOT_PRESENT_SEI
+Void SEIReader::xParseSEIBspNesting(SEIBspNesting &sei, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps, const SEIScalableNesting &nestingSei)
+#else
+Void SEIReader::xParseSEIBspNesting(SEIBspNesting &sei, const NalUnitType nalUnitType, TComSPS *sps, const SEIScalableNesting &nestingSei)
+#endif
+{
+  UInt uiCode;
+  READ_UVLC( uiCode, "bsp_idx" ); sei.m_bspIdx = uiCode;
+
+  // byte alignment
+  while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
+  {
+    UInt code;
+    READ_FLAG( code, "bsp_nesting_zero_bit" );
+  }
+
+  sei.m_callerOwnsSEIs = false;
+
+  // read nested SEI messages
+  do {
+#if LAYERS_NOT_PRESENT_SEI
+    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps, &nestingSei, &sei);
+#else
+    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps, &nestingSei);
+#endif
+  } while (m_pcBitstream->getNumBitsLeft() > 8);
+}
+
+Void SEIReader::xParseSEIBspInitialArrivalTime(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;
+  UInt uiCode;
+
+  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++)
+    {
+      READ_CODE( len, uiCode, "nal_initial_arrival_delay" ); sei.m_nalInitialArrivalDelay[i] = uiCode;
+    }
+  }
+  else
+  {
+    for(UInt i = 0; i < schedCombCnt; i++)
+    {
+      READ_CODE( len, uiCode, "vcl_initial_arrival_delay" ); sei.m_vclInitialArrivalDelay[i] = uiCode;
+    }
+  }
+}
+
+Void SEIReader::xParseSEIBspHrd(SEIBspHrd &sei, TComSPS *sps, const SEIScalableNesting &nestingSei)
+{
+  UInt uiCode;
+  READ_UVLC( uiCode, "sei_num_bsp_hrd_parameters_minus1" ); sei.m_seiNumBspHrdParametersMinus1 = uiCode;
+  for (UInt i = 0; i <= sei.m_seiNumBspHrdParametersMinus1; i++)
+  {
+    if (i > 0)
+    {
+      READ_FLAG( uiCode, "sei_bsp_cprms_present_flag" ); sei.m_seiBspCprmsPresentFlag[i] = uiCode;
+    }
+    xParseHrdParameters(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];
+    READ_UVLC( uiCode, "num_sei_bitstream_partitions_minus1[i]"); sei.m_seiNumBitstreamPartitionsMinus1[lsIdx] = uiCode;
+    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])
+        {
+          READ_FLAG( uiCode, "sei_layer_in_bsp_flag[lsIdx][i][j]" ); sei.m_seiLayerInBspFlag[lsIdx][i][j] = uiCode;
+        }
+      }
+    }
+    READ_UVLC( uiCode, "sei_num_bsp_sched_combinations_minus1[i]"); sei.m_seiNumBspSchedCombinationsMinus1[lsIdx] = uiCode;
+    for (UInt i = 0; i <= sei.m_seiNumBspSchedCombinationsMinus1[lsIdx]; i++)
+    {
+      for (UInt j = 0; j <= sei.m_seiNumBitstreamPartitionsMinus1[lsIdx]; j++)
+      {
+        READ_UVLC( uiCode, "sei_bsp_comb_hrd_idx[lsIdx][i][j]"); sei.m_seiBspCombHrdIdx[lsIdx][i][j] = uiCode;
+        READ_UVLC( uiCode, "sei_bsp_comb_sched_idx[lsIdx][i][j]"); sei.m_seiBspCombScheddx[lsIdx][i][j] = uiCode;
+      }
+    }
+  }
+}
+
+Void SEIReader::xParseHrdParameters(TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1)
+{
+  UInt  uiCode;
+  if( commonInfPresentFlag )
+  {
+    READ_FLAG( uiCode, "nal_hrd_parameters_present_flag" );           hrd->setNalHrdParametersPresentFlag( uiCode == 1 ? true : false );
+    READ_FLAG( uiCode, "vcl_hrd_parameters_present_flag" );           hrd->setVclHrdParametersPresentFlag( uiCode == 1 ? true : false );
+    if( hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag() )
+    {
+      READ_FLAG( uiCode, "sub_pic_cpb_params_present_flag" );         hrd->setSubPicCpbParamsPresentFlag( uiCode == 1 ? true : false );
+      if( hrd->getSubPicCpbParamsPresentFlag() )
+      {
+        READ_CODE( 8, uiCode, "tick_divisor_minus2" );                hrd->setTickDivisorMinus2( uiCode );
+        READ_CODE( 5, uiCode, "du_cpb_removal_delay_length_minus1" ); hrd->setDuCpbRemovalDelayLengthMinus1( uiCode );
+        READ_FLAG( uiCode, "sub_pic_cpb_params_in_pic_timing_sei_flag" ); hrd->setSubPicCpbParamsInPicTimingSEIFlag( uiCode == 1 ? true : false );
+        READ_CODE( 5, uiCode, "dpb_output_delay_du_length_minus1"  ); hrd->setDpbOutputDelayDuLengthMinus1( uiCode );
+      }
+      READ_CODE( 4, uiCode, "bit_rate_scale" );                       hrd->setBitRateScale( uiCode );
+      READ_CODE( 4, uiCode, "cpb_size_scale" );                       hrd->setCpbSizeScale( uiCode );
+      if( hrd->getSubPicCpbParamsPresentFlag() )
+      {
+        READ_CODE( 4, uiCode, "cpb_size_du_scale" );                  hrd->setDuCpbSizeScale( uiCode );
+      }
+      READ_CODE( 5, uiCode, "initial_cpb_removal_delay_length_minus1" ); hrd->setInitialCpbRemovalDelayLengthMinus1( uiCode );
+      READ_CODE( 5, uiCode, "au_cpb_removal_delay_length_minus1" );      hrd->setCpbRemovalDelayLengthMinus1( uiCode );
+      READ_CODE( 5, uiCode, "dpb_output_delay_length_minus1" );       hrd->setDpbOutputDelayLengthMinus1( uiCode );
+    }
+  }
+  Int i, j, nalOrVcl;
+  for( i = 0; i <= maxNumSubLayersMinus1; i ++ )
+  {
+    READ_FLAG( uiCode, "fixed_pic_rate_general_flag" );                     hrd->setFixedPicRateFlag( i, uiCode == 1 ? true : false  );
+    if( !hrd->getFixedPicRateFlag( i ) )
+    {
+      READ_FLAG( uiCode, "fixed_pic_rate_within_cvs_flag" );                hrd->setFixedPicRateWithinCvsFlag( i, uiCode == 1 ? true : false  );
+    }
+    else
+    {
+      hrd->setFixedPicRateWithinCvsFlag( i, true );
+    }
+    hrd->setLowDelayHrdFlag( i, 0 ); // Infered to be 0 when not present
+    hrd->setCpbCntMinus1   ( i, 0 ); // Infered to be 0 when not present
+    if( hrd->getFixedPicRateWithinCvsFlag( i ) )
+    {
+      READ_UVLC( uiCode, "elemental_duration_in_tc_minus1" );             hrd->setPicDurationInTcMinus1( i, uiCode );
+    }
+    else
+    {
+      READ_FLAG( uiCode, "low_delay_hrd_flag" );                      hrd->setLowDelayHrdFlag( i, uiCode == 1 ? true : false  );
+    }
+    if (!hrd->getLowDelayHrdFlag( i ))
+    {
+      READ_UVLC( uiCode, "cpb_cnt_minus1" );                          hrd->setCpbCntMinus1( i, uiCode );
+    }
+    for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
+    {
+      if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
+          ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
+      {
+        for( j = 0; j <= ( hrd->getCpbCntMinus1( i ) ); j ++ )
+        {
+          READ_UVLC( uiCode, "bit_rate_value_minus1" );             hrd->setBitRateValueMinus1( i, j, nalOrVcl, uiCode );
+          READ_UVLC( uiCode, "cpb_size_value_minus1" );             hrd->setCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
+          if( hrd->getSubPicCpbParamsPresentFlag() )
+          {
+            READ_UVLC( uiCode, "cpb_size_du_value_minus1" );       hrd->setDuCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
+            READ_UVLC( uiCode, "bit_rate_du_value_minus1" );       hrd->setDuBitRateValueMinus1( i, j, nalOrVcl, uiCode );
+          }
+          READ_FLAG( uiCode, "cbr_flag" );                          hrd->setCbrFlag( i, j, nalOrVcl, uiCode == 1 ? true : false  );
+        }
+      }
+    }
+  }
+}
+#endif
+
 #endif //SVC_EXTENSION
 
Index: trunk/source/Lib/TLibDecoder/SEIread.h
===================================================================
--- trunk/source/Lib/TLibDecoder/SEIread.h	(revision 597)
+++ trunk/source/Lib/TLibDecoder/SEIread.h	(revision 644)
@@ -62,8 +62,19 @@
 #endif
 protected:
+#if O0164_MULTI_LAYER_HRD
+#if LAYERS_NOT_PRESENT_SEI
+  Void xReadSEImessage                (SEIMessages& seis, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps, const SEIScalableNesting *nestingSei=NULL, const SEIBspNesting *bspNestingSei=NULL);
+#else
+  Void xReadSEImessage                (SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps, const SEIScalableNesting *nestingSei=NULL);
+#endif
+#else
 #if LAYERS_NOT_PRESENT_SEI
   Void xReadSEImessage                (SEIMessages& seis, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps);
 #else
   Void xReadSEImessage                (SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps);
+#endif
+#endif
+#if P0138_USE_ALT_CPB_PARAMS_FLAG
+  Bool xPayloadExtensionPresent       ();
 #endif
   Void xParseSEIuserDataUnregistered  (SEIuserDataUnregistered &sei, UInt payloadSize);
@@ -92,4 +103,14 @@
   Void xParseSEIScalableNesting       (SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComSPS *sps);
 #endif
+#if O0164_MULTI_LAYER_HRD
+#if LAYERS_NOT_PRESENT_SEI
+  Void xParseSEIBspNesting(SEIBspNesting &sei, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps, const SEIScalableNesting &nestingSei);
+#else
+  Void xParseSEIBspNesting(SEIBspNesting &sei, const NalUnitType nalUnitType, TComSPS *sps, const SEIScalableNesting &nestingSei);
+#endif
+  Void xParseSEIBspInitialArrivalTime(SEIBspInitialArrivalTime &sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting &nestingSei, const SEIBspNesting &bspNestingSei);
+  Void xParseSEIBspHrd(SEIBspHrd &sei, TComSPS *sps, const SEIScalableNesting &nestingSei);
+  Void xParseHrdParameters(TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1);
+#endif
   Void xParseByteAlign();
 };
Index: trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 597)
+++ trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 644)
@@ -334,8 +334,31 @@
   if (uiCode)
   {
+#if P0166_MODIFIED_PPS_EXTENSION
+    UInt ppsExtensionTypeFlag[8];
+    for (UInt i = 0; i < 8; i++)
+    {
+      READ_FLAG( ppsExtensionTypeFlag[i], "pps_extension_type_flag" );
+    }
+#if !POC_RESET_IDC
+    if (ppsExtensionTypeFlag[1])
+    {
+#else
+    if( ppsExtensionTypeFlag[0] )
+    {
+      READ_FLAG( uiCode, "poc_reset_info_present_flag" );
+      pcPPS->setPocResetInfoPresentFlag(uiCode ? true : false);
+#endif
+    }
+    if (ppsExtensionTypeFlag[7])
+    {
+#endif
+
     while ( xMoreRbspData() )
     {
       READ_FLAG( uiCode, "pps_extension_data_flag");
     }
+#if P0166_MODIFIED_PPS_EXTENSION
+    }
+#endif
   }
 }
@@ -514,5 +537,5 @@
 }
 
-#if SVC_EXTENSION
+#if SVC_EXTENSION && !SPS_DPB_PARAMS
 Void TDecCavlc::parseSPS(TComSPS* pcSPS, ParameterSetManagerDecoder *parameterSetManager)
 #else
@@ -536,4 +559,5 @@
 #if SVC_EXTENSION
   }
+#if !SPS_DPB_PARAMS
   else
   {
@@ -542,9 +566,13 @@
   }
 #endif
+#endif
+
   if ( pcSPS->getMaxTLayers() == 1 )
   {
     // sps_temporal_id_nesting_flag must be 1 when sps_max_sub_layers_minus1 is 0
 #if SVC_EXTENSION
+#if !SPS_DPB_PARAMS
     assert( pcSPS->getTemporalIdNestingFlag() == true );
+#endif
 #else
     assert( uiCode == 1 );
@@ -644,28 +672,34 @@
   assert(uiCode <= 12);
 
-  UInt subLayerOrderingInfoPresentFlag;
-  READ_FLAG(subLayerOrderingInfoPresentFlag, "sps_sub_layer_ordering_info_present_flag");
-
-  for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
-  {
-    READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1");
-    pcSPS->setMaxDecPicBuffering( uiCode + 1, i);
-    READ_UVLC ( uiCode, "sps_num_reorder_pics" );
-    pcSPS->setNumReorderPics(uiCode, i);
-    READ_UVLC ( uiCode, "sps_max_latency_increase_plus1");
-    pcSPS->setMaxLatencyIncrease( uiCode, i );
-
-    if (!subLayerOrderingInfoPresentFlag)
-    {
-      for (i++; i <= pcSPS->getMaxTLayers()-1; i++)
-      {
-        pcSPS->setMaxDecPicBuffering(pcSPS->getMaxDecPicBuffering(0), i);
-        pcSPS->setNumReorderPics(pcSPS->getNumReorderPics(0), i);
-        pcSPS->setMaxLatencyIncrease(pcSPS->getMaxLatencyIncrease(0), i);
-      }
-      break;
-    }
-  }
-
+#if SPS_DPB_PARAMS
+  if( pcSPS->getLayerId() == 0 )  
+  {
+#endif
+    UInt subLayerOrderingInfoPresentFlag;
+    READ_FLAG(subLayerOrderingInfoPresentFlag, "sps_sub_layer_ordering_info_present_flag");
+
+    for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
+    {
+      READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1");
+      pcSPS->setMaxDecPicBuffering( uiCode + 1, i);
+      READ_UVLC ( uiCode, "sps_num_reorder_pics" );
+      pcSPS->setNumReorderPics(uiCode, i);
+      READ_UVLC ( uiCode, "sps_max_latency_increase_plus1");
+      pcSPS->setMaxLatencyIncrease( uiCode, i );
+
+      if (!subLayerOrderingInfoPresentFlag)
+      {
+        for (i++; i <= pcSPS->getMaxTLayers()-1; i++)
+        {
+          pcSPS->setMaxDecPicBuffering(pcSPS->getMaxDecPicBuffering(0), i);
+          pcSPS->setNumReorderPics(pcSPS->getNumReorderPics(0), i);
+          pcSPS->setMaxLatencyIncrease(pcSPS->getMaxLatencyIncrease(0), i);
+        }
+        break;
+      }
+    }
+#if SPS_DPB_PARAMS
+  }
+#endif
   READ_UVLC( uiCode, "log2_min_coding_block_size_minus3" );
   Int log2MinCUSize = uiCode + 3;
@@ -824,5 +858,5 @@
       Window& scaledWindow = pcSPS->getScaledRefLayerWindow(i);
 #if O0098_SCALED_REF_LAYER_ID
-      READ_CODE( 6,  uiCode,  "scaled_ref_layer_left_id" );  pcSPS->setScaledRefLayerId( i, uiCode );
+      READ_CODE( 6,  uiCode,  "scaled_ref_layer_id" );       pcSPS->setScaledRefLayerId( i, uiCode );
 #endif
       READ_SVLC( iCode, "scaled_ref_layer_left_offset" );    scaledWindow.setWindowLeftOffset  (iCode << 1);
@@ -830,4 +864,7 @@
       READ_SVLC( iCode, "scaled_ref_layer_right_offset" );   scaledWindow.setWindowRightOffset (iCode << 1);
       READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" );  scaledWindow.setWindowBottomOffset(iCode << 1);
+#if P0312_VERT_PHASE_ADJ
+      READ_FLAG( uiCode, "vert_phase_position_enable_flag" ); scaledWindow.setVertPhasePositionEnableFlag(uiCode);  pcSPS->setVertPhasePositionEnableFlag( pcSPS->getScaledRefLayerId(i), uiCode);    
+#endif
     }
   }
@@ -850,5 +887,5 @@
   READ_CODE( 6,  uiCode,  "vps_reserved_zero_6bits" );            assert(uiCode == 0);
 #endif
-  READ_CODE( 3,  uiCode,  "vps_max_sub_layers_minus1" );          pcVPS->setMaxTLayers( uiCode + 1 );
+  READ_CODE( 3,  uiCode,  "vps_max_sub_layers_minus1" );          pcVPS->setMaxTLayers( uiCode + 1 ); assert(uiCode <= 6);
   READ_FLAG(     uiCode,  "vps_temporal_id_nesting_flag" );       pcVPS->setTemporalNestingFlag( uiCode ? true:false );
   assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag());
@@ -970,4 +1007,8 @@
   UInt uiCode;
   // ... More syntax elements to be parsed 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 numScalabilityTypes = 0, i = 0, j = 0;
@@ -1091,5 +1132,5 @@
     if (vps->getMaxTSLayersPresentFlag())
     {
-        for(i = 0; i < vps->getMaxLayers() - 1; i++)
+        for(i = 0; i < vps->getMaxLayers(); i++)
         {
             READ_CODE( 3, uiCode, "sub_layers_vps_max_minus1[i]" ); vps->setMaxTSLayersMinus1(i, uiCode);
@@ -1098,5 +1139,5 @@
     else
     {
-        for( i = 0; i < vps->getMaxLayers() - 1; i++)
+        for( i = 0; i < vps->getMaxLayers(); i++)
         {
             vps->setMaxTSLayersMinus1(i, vps->getMaxTLayers()-1);
@@ -1238,5 +1279,9 @@
     {
       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
       {
         READ_FLAG( uiCode, "output_layer_flag[i][j]"); vps->setOutputLayerFlag(i, j, uiCode);
@@ -1269,4 +1314,21 @@
     }
     READ_CODE( numBits, uiCode, "profile_level_tier_idx[i]" );     vps->setProfileLevelTierIdx(i, uiCode);
+#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)
+    {
+      READ_FLAG(uiCode, "alt_output_layer_flag[i]");
+      vps->setAltOuputLayerFlag(i, uiCode ? true : false);
+    }
+#endif
   }
 #else
@@ -1292,5 +1354,9 @@
       READ_CODE( numBits, uiCode, "output_layer_set_idx_minus1");   vps->setOutputLayerSetIdx( i, uiCode + 1);
       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
       {
         READ_FLAG( uiCode, "output_layer_flag[i][j]"); vps->setOutputLayerFlag(i, j, uiCode);
@@ -1354,4 +1420,5 @@
 #endif
 
+#if !P0300_ALT_OUTPUT_LAYER_FLAG
 #if O0153_ALT_OUTPUT_LAYER_FLAG
   if( vps->getMaxLayers() > 1 )
@@ -1360,4 +1427,5 @@
     vps->setAltOuputLayerFlag( uiCode ? true : false );
   }
+#endif
 #endif
 
@@ -1510,8 +1578,16 @@
 #if P0307_VPS_NON_VUI_EXTENSION
   READ_UVLC( uiCode,           "vps_non_vui_extension_length"); vps->setVpsNonVuiExtLength((Int)uiCode);
+#if P0307_VPS_NON_VUI_EXT_UPDATE
+  Int nonVuiExtByte = uiCode;
+  for (i = 1; i <= nonVuiExtByte; i++)
+  {
+    READ_CODE( 8, uiCode, "vps_non_vui_extension_data_byte" ); //just parse and discard for now.
+  }
+#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
 
@@ -1596,4 +1672,22 @@
 {
   UInt uiCode;
+#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
+    
 #if !RESOLUTION_BASED_DPB
   vps->deriveNumberOfSubDpbs();
@@ -1605,5 +1699,9 @@
 #endif
     READ_FLAG( uiCode, "sub_layer_flag_info_present_flag[i]");  vps->setSubLayerFlagInfoPresentFlag( i, uiCode ? true : false );
-    for(Int j = 0; j < vps->getMaxTLayers(); j++)
+#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) )
@@ -1652,4 +1750,30 @@
       }
     }
+    for(Int j = vps->getMaxTLayers(); j < MAX_TLAYER; j++)
+    {
+      vps->setSubLayerDpbInfoPresentFlag( i, j, false );
+    }
+  }
+
+  // Infer values when not signalled
+  for(Int i = 1; i < vps->getNumOutputLayerSets(); i++)
+  {
+    Int layerSetIdxForOutputLayerSet = vps->getOutputLayerSetIdx( i );
+    for(Int j = 0; j < MAX_TLAYER; j++)
+    {
+      if( !vps->getSubLayerDpbInfoPresentFlag(i, j) )  // If sub-layer DPB information is NOT present
+      {
+        for(Int k = 0; k < vps->getNumSubDpbs(layerSetIdxForOutputLayerSet); k++)
+        {
+          vps->setMaxVpsDecPicBufferingMinus1( i, k, j, vps->getMaxVpsDecPicBufferingMinus1( i, k, j - 1 ) );
+        }
+        vps->setMaxVpsNumReorderPics( i, j, vps->getMaxVpsNumReorderPics( i, j - 1) );
+        for(Int k = 0; k < vps->getNumLayersInIdList( layerSetIdxForOutputLayerSet ); k++)
+        {
+          vps->setMaxVpsLayerDecPicBuffMinus1( i, k, j, vps->getMaxVpsLayerDecPicBuffMinus1( i, k, j - 1));
+        }
+        vps->setMaxVpsLatencyIncreasePlus1( i, j, vps->getMaxVpsLatencyIncreasePlus1( i, j - 1 ) );
+      }
+    }
   }
 }
@@ -1669,4 +1793,11 @@
     READ_FLAG(uiCode, "cross_layer_irap_aligned_flag" );
     vps->setCrossLayerIrapAlignFlag(uiCode);
+#if P0068_CROSS_LAYER_ALIGNED_IDR_ONLY_FOR_IRAP_FLAG
+    if (uiCode)
+    {
+      READ_FLAG(uiCode, "only_idr_for_IRAP_across_layers" );
+      vps->setCrossLayerIrapAlignFlag(uiCode);
+    }
+#endif
 #endif
 #if O0223_PICTURE_TYPES_ALIGN_FLAG
@@ -1825,5 +1956,7 @@
 #endif
 #endif
-
+#if P0312_VERT_PHASE_ADJ
+  READ_FLAG( uiCode, "vps_vui_vert_phase_in_use_flag" ); vps->setVpsVuiVertPhaseInUseFlag(uiCode);
+#endif
 #if N0160_VUI_EXT_ILP_REF
   READ_FLAG( uiCode, "ilp_restricted_ref_layers_flag" ); vps->setIlpRestrictedRefLayersFlag( uiCode == 1 );
@@ -1892,4 +2025,62 @@
 #endif 
 #endif
+
+#if O0164_MULTI_LAYER_HRD
+    READ_FLAG(uiCode, "vps_vui_bsp_hrd_present_flag" ); vps->setVpsVuiBspHrdPresentFlag(uiCode);
+    if (vps->getVpsVuiBspHrdPresentFlag())
+    {
+      READ_UVLC( uiCode, "vps_num_bsp_hrd_parameters_minus1" ); vps->setVpsNumBspHrdParametersMinus1(uiCode);
+      vps->createBspHrdParamBuffer(vps->getVpsNumBspHrdParametersMinus1() + 1);
+      for( i = 0; i <= vps->getVpsNumBspHrdParametersMinus1(); i++ )
+      {
+        if( i > 0 )
+        {
+          READ_FLAG( uiCode, "bsp_cprms_present_flag[i]" ); vps->setBspCprmsPresentFlag(i, uiCode);
+        }
+        parseHrdParameters(vps->getBspHrd(i), i==0 ? 1 : vps->getBspCprmsPresentFlag(i), vps->getMaxTLayers()-1);
+      }
+      for( UInt h = 1; h <= (vps->getNumLayerSets()-1); h++ )
+      {
+        READ_UVLC( uiCode, "num_bitstream_partitions[i]"); vps->setNumBitstreamPartitions(h, uiCode);
+        for( i = 0; i < vps->getNumBitstreamPartitions(h); i++ )
+        {
+          for( j = 0; j <= (vps->getMaxLayers()-1); j++ )
+          {
+            if( vps->getLayerIdIncludedFlag(h, j) )
+            {
+              READ_FLAG( uiCode, "layer_in_bsp_flag[h][i][j]" ); vps->setLayerInBspFlag(h, i, j, uiCode);
+            }
+          }
+        }
+        if (vps->getNumBitstreamPartitions(h))
+        {
+          READ_UVLC( uiCode, "num_bsp_sched_combinations[h]"); vps->setNumBspSchedCombinations(h, uiCode);
+          for( i = 0; i < vps->getNumBspSchedCombinations(h); i++ )
+          {
+            for( j = 0; j < vps->getNumBitstreamPartitions(h); j++ )
+            {
+              READ_UVLC( uiCode, "bsp_comb_hrd_idx[h][i][j]"); vps->setBspCombHrdIdx(h, i, j, uiCode);
+              READ_UVLC( uiCode, "bsp_comb_sched_idx[h][i][j]"); vps->setBspCombSchedIdx(h, i, j, uiCode);
+            }
+          }
+        }
+      }
+    }
+#endif
+
+#if P0182_VPS_VUI_PS_FLAG
+    for(i = 1; i < vps->getMaxLayers(); i++)
+    {
+      if (vps->getNumRefLayers(vps->getLayerIdInNuh(i)) == 0)
+      {
+        READ_FLAG( uiCode, "base_layer_parameter_set_compatibility_flag" ); 
+        vps->setBaseLayerPSCompatibilityFlag( i, uiCode );
+      }
+      else
+      {
+        vps->setBaseLayerPSCompatibilityFlag( i, 0 );
+      }
+    }
+#endif
 }
 #endif
@@ -1911,5 +2102,9 @@
   if( rpcSlice->getRapPicFlag())
   {
+#if !NO_OUTPUT_OF_PRIOR_PICS
     READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  //ignored
+#else
+    READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  rpcSlice->setNoOutputOfPriorPicsFlag( uiCode ? true : false );
+#endif
   }
   READ_UVLC (    uiCode, "slice_pic_parameter_set_id" );  rpcSlice->setPPSId(uiCode);
@@ -2229,10 +2424,10 @@
 #if ILP_SSH_SIG
 #if ILP_SSH_SIG_FIX
-    if((sps->getLayerId() > 0) && !(rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag()) && (rpcSlice->getNumILRRefIdx() > 0) )
-#else
-    if((sps->getLayerId() > 0) && rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag() && (rpcSlice->getNumILRRefIdx() > 0) )
-#endif
-#else
-    if((sps->getLayerId() > 0)  &&  (rpcSlice->getNumILRRefIdx() > 0) )
+    if((rpcSlice->getLayerId() > 0) && !(rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag()) && (rpcSlice->getNumILRRefIdx() > 0) )
+#else
+    if((rpcSlice->getLayerId() > 0) && rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag() && (rpcSlice->getNumILRRefIdx() > 0) )
+#endif
+#else
+    if((rpcSlice->getLayerId() > 0)  &&  (rpcSlice->getNumILRRefIdx() > 0) )
 #endif
     {
@@ -2256,17 +2451,13 @@
           {
 #if P0079_DERIVE_NUMACTIVE_REF_PICS
-            Int   numRefLayerPics = 0;
-            Int   i = 0;
-            Int   refLayerPicIdc  [MAX_VPS_LAYER_ID_PLUS1];
-            for(i = 0, numRefLayerPics = 0;  i < rpcSlice->getNumILRRefIdx(); i++ ) 
+            for( Int i = 0; i < rpcSlice->getNumILRRefIdx(); i++ ) 
             {
               if(rpcSlice->getVPS()->getMaxTidIlRefPicsPlus1(rpcSlice->getVPS()->getLayerIdInVps(i),rpcSlice->getLayerId()) >  rpcSlice->getTLayer() &&
                 (rpcSlice->getVPS()->getMaxTSLayersMinus1(rpcSlice->getVPS()->getLayerIdInVps(i)) >=  rpcSlice->getTLayer()) )
               {          
-                refLayerPicIdc[ numRefLayerPics++ ] = i;
+                rpcSlice->setActiveNumILRRefIdx(1);
+                break;
               }
             }
-            if (numRefLayerPics)
-              rpcSlice->setActiveNumILRRefIdx(1);
 #else
             rpcSlice->setActiveNumILRRefIdx(1);
@@ -2344,4 +2535,14 @@
 #endif
 #endif
+#if P0312_VERT_PHASE_ADJ
+    for(Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ ) 
+    {
+      UInt refLayerIdc = rpcSlice->getInterLayerPredLayerIdc(i);
+      if( rpcSlice->getSPS()->getVertPhasePositionEnableFlag(refLayerIdc) )
+      {
+        READ_FLAG( uiCode, "vert_phase_position_flag" ); rpcSlice->setVertPhasePositionFlag( uiCode? true : false, refLayerIdc );
+      }
+    }
+#endif
 
     if(sps->getUseSAO())
@@ -2661,4 +2862,90 @@
   }
 
+#if POC_RESET_IDC_SIGNALLING
+  Int sliceHederExtensionLength = 0;
+  if(pps->getSliceHeaderExtensionPresentFlag())
+  {
+    READ_UVLC( uiCode, "slice_header_extension_length"); sliceHederExtensionLength = uiCode;
+  }
+  else
+  {
+    sliceHederExtensionLength = 0;
+  }
+  UInt startBits = m_pcBitstream->getNumBitsRead();     // Start counter of # SH Extn bits
+  if( sliceHederExtensionLength > 0 )
+  {
+    if( rpcSlice->getPPS()->getPocResetInfoPresentFlag() )
+    {
+      READ_CODE( 2, uiCode,       "poc_reset_idc"); rpcSlice->setPocResetIdc(uiCode);
+    }
+    else
+    {
+      rpcSlice->setPocResetIdc( 0 );
+    }
+    if( rpcSlice->getPocResetIdc() > 0 )
+    {
+      READ_CODE(6, uiCode,      "poc_reset_period_id"); rpcSlice->setPocResetPeriodId(uiCode);
+    }
+    else
+    {
+     
+      rpcSlice->setPocResetPeriodId( 0 );
+    }
+
+    if (rpcSlice->getPocResetIdc() == 3)
+    {
+      READ_FLAG( uiCode,        "full_poc_reset_flag"); rpcSlice->setFullPocResetFlag((uiCode == 1) ? true : false);
+      READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode,"poc_lsb_val"); rpcSlice->setPocLsbVal(uiCode);
+    }
+
+    // Derive the value of PocMsbValRequiredFlag
+    rpcSlice->setPocMsbValRequiredFlag( rpcSlice->getCraPicFlag() || rpcSlice->getBlaPicFlag()
+                                          /* || related to vps_poc_lsb_aligned_flag */
+                                          );
+
+    if( !rpcSlice->getPocMsbValRequiredFlag() /* vps_poc_lsb_aligned_flag */ )
+    {
+      READ_FLAG( uiCode,    "poc_msb_val_present_flag"); rpcSlice->setPocMsbValPresentFlag( uiCode ? true : false );
+    }
+    else
+    {
+      if( rpcSlice->getPocMsbValRequiredFlag() )
+      {
+        rpcSlice->setPocMsbValPresentFlag( true );
+      }
+      else
+      {
+        rpcSlice->setPocMsbValPresentFlag( false );
+      }
+    }
+
+    Int maxPocLsb  = 1 << rpcSlice->getSPS()->getBitsForPOC();
+    if( rpcSlice->getPocMsbValPresentFlag() )
+    {
+      READ_UVLC( uiCode,    "poc_msb_val");             rpcSlice->setPocMsbVal( uiCode );
+      // Update POC of the slice based on this MSB val
+      Int pocLsb     = rpcSlice->getPOC() % maxPocLsb;
+      rpcSlice->setPOC((rpcSlice->getPocMsbVal() * maxPocLsb) + pocLsb);
+    }
+    else
+    {
+      rpcSlice->setPocMsbVal( rpcSlice->getPOC() / maxPocLsb );
+    }
+
+    // Read remaining bits in the slice header extension.
+    UInt endBits = m_pcBitstream->getNumBitsRead();
+    Int counter = (endBits - startBits) % 8;
+    if( counter )
+    {
+      counter = 8 - counter;
+    }
+
+    while( counter )
+    {
+      READ_FLAG( uiCode, "slice_segment_header_extension_reserved_bit" ); assert( uiCode == 1 );
+      counter--;
+    }
+  }
+#else
   if(pps->getSliceHeaderExtensionPresentFlag())
   {
@@ -2670,4 +2957,5 @@
     }
   }
+#endif
   m_pcBitstream->readByteAlignment();
 
Index: trunk/source/Lib/TLibDecoder/TDecCAVLC.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 597)
+++ trunk/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 644)
@@ -86,5 +86,9 @@
   Void  parseVpsDpbSizeTable( TComVPS *vps );
 #endif
+#if SPS_DPB_PARAMS
+  Void  parseSPS            ( TComSPS* pcSPS ); // it should be removed after macro clean up
+#else
   Void  parseSPS            ( TComSPS* pcSPS, ParameterSetManagerDecoder *parameterSetManager );
+#endif
   Void  parseSPSExtension    ( TComSPS* pcSPS );
 #else //SVC_EXTENSION
Index: trunk/source/Lib/TLibDecoder/TDecEntropy.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecEntropy.h	(revision 597)
+++ trunk/source/Lib/TLibDecoder/TDecEntropy.h	(revision 644)
@@ -66,5 +66,5 @@
 
   virtual Void  parseVPS                  ( TComVPS* pcVPS )                       = 0;
-#if SVC_EXTENSION
+#if SVC_EXTENSION && !SPS_DPB_PARAMS
   virtual Void  parseSPS                  ( TComSPS* pcSPS, ParameterSetManagerDecoder *parameterSetManager )           = 0;
 #else
@@ -133,5 +133,5 @@
   Void    resetEntropy                ( TComSlice* p)           { m_pcEntropyDecoderIf->resetEntropy(p);                    }
   Void    decodeVPS                   ( TComVPS* pcVPS ) { m_pcEntropyDecoderIf->parseVPS(pcVPS); }
-#if SVC_EXTENSION
+#if SVC_EXTENSION && !SPS_DPB_PARAMS
   Void    decodeSPS                   ( TComSPS* pcSPS, ParameterSetManagerDecoder *parameterSetManager )    { m_pcEntropyDecoderIf->parseSPS(pcSPS, parameterSetManager);                    }
 #else
Index: trunk/source/Lib/TLibDecoder/TDecSbac.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 597)
+++ trunk/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 644)
@@ -1394,4 +1394,7 @@
 
 Void TDecSbac::parseSAOBlkParam (SAOBlkParam& saoBlkParam
+#if SVC_EXTENSION
+                                , UInt* saoMaxOffsetQVal
+#endif
                                 , Bool* sliceEnabled
                                 , Bool leftMergeAvail
@@ -1468,5 +1471,9 @@
         for(Int i=0; i< 4; i++)
         {
+#if SVC_EXTENSION
+          parseSaoMaxUvlc(uiSymbol,  saoMaxOffsetQVal[compIdx] ); //sao_offset_abs
+#else
           parseSaoMaxUvlc(uiSymbol,  g_saoMaxOffsetQVal[compIdx] ); //sao_offset_abs
+#endif
           offset[i] = (Int)uiSymbol;
         }
Index: trunk/source/Lib/TLibDecoder/TDecSbac.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecSbac.h	(revision 597)
+++ trunk/source/Lib/TLibDecoder/TDecSbac.h	(revision 644)
@@ -76,5 +76,5 @@
   Void  setBitstream              ( TComInputBitstream* p  ) { m_pcBitstream = p; m_pcTDecBinIf->init( p ); }
   Void  parseVPS                  ( TComVPS* /*pcVPS*/ ) {}
-#if SVC_EXTENSION
+#if SVC_EXTENSION && !SPS_DPB_PARAMS
   Void  parseSPS                  ( TComSPS* /*pcSPS*/, ParameterSetManagerDecoder * /*parameterSetManager*/ ) {}
 #else
@@ -90,5 +90,10 @@
   Void  parseSaoTypeIdx           ( UInt&  ruiVal  );
   Void  parseSaoUflc              ( UInt uiLength, UInt& ruiVal     );
+
+#if SVC_EXTENSION
+  Void parseSAOBlkParam (SAOBlkParam& saoBlkParam, UInt* saoMaxOffsetQVal, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail );
+#else
   Void parseSAOBlkParam (SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail);
+#endif
   Void parseSaoSign(UInt& val);
 private:
Index: trunk/source/Lib/TLibDecoder/TDecSlice.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecSlice.cpp	(revision 597)
+++ trunk/source/Lib/TLibDecoder/TDecSlice.cpp	(revision 644)
@@ -105,9 +105,9 @@
 
 #if SVC_EXTENSION
-Void TDecSlice::init(TDecTop** ppcDecTop,TDecEntropy* pcEntropyDecoder, TDecCu* pcCuDecoder)
+Void TDecSlice::init(TDecEntropy* pcEntropyDecoder, TDecCu* pcCuDecoder, UInt* saoMaxOffsetQVal)
 {
   m_pcEntropyDecoder  = pcEntropyDecoder;
   m_pcCuDecoder       = pcCuDecoder;
-  m_ppcTDecTop        = ppcDecTop;
+  m_saoMaxOffsetQVal  = saoMaxOffsetQVal;
 }
 #else
@@ -347,6 +347,9 @@
           aboveMergeAvail = rpcPic->getSAOMergeAvailability(iCUAddr, iCUAddr-uiWidthInLCUs);
         }
-
+#if SVC_EXTENSION
+        pcSbacDecoder->parseSAOBlkParam( saoblkParam, m_saoMaxOffsetQVal, sliceEnabled, leftMergeAvail, aboveMergeAvail);
+#else
         pcSbacDecoder->parseSAOBlkParam( saoblkParam, sliceEnabled, leftMergeAvail, aboveMergeAvail);
+#endif
       }
       else 
Index: trunk/source/Lib/TLibDecoder/TDecSlice.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecSlice.h	(revision 597)
+++ trunk/source/Lib/TLibDecoder/TDecSlice.h	(revision 644)
@@ -72,5 +72,5 @@
   std::vector<TDecSbac*> CTXMem;
 #if SVC_EXTENSION
-  TDecTop**       m_ppcTDecTop;
+  UInt*           m_saoMaxOffsetQVal; 
 #endif 
   
@@ -80,5 +80,5 @@
   
 #if SVC_EXTENSION  
-  Void  init              ( TDecTop** ppcDecTop, TDecEntropy* pcEntropyDecoder, TDecCu* pcMbDecoder );
+  Void  init              ( TDecEntropy* pcEntropyDecoder, TDecCu* pcMbDecoder, UInt* saoMaxOffsetQVal );
 #else
   Void  init              ( TDecEntropy* pcEntropyDecoder, TDecCu* pcMbDecoder );
@@ -91,7 +91,4 @@
   Void      setCtxMem( TDecSbac* sb, Int b )   { CTXMem[b] = sb; }
   Int       getCtxMemSize( )                   { return (Int)CTXMem.size(); }
-#if SVC_EXTENSION
-  TDecTop*  getLayerDec   ( UInt LayerId )  { return m_ppcTDecTop[LayerId]; }  
-#endif
 };
 
Index: trunk/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 597)
+++ trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 644)
@@ -138,5 +138,5 @@
 #if SVC_EXTENSION
   m_cGopDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
-  m_cSliceDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cCuDecoder );
+  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder, m_cSAO.getSaoMaxOffsetQVal() );
 #else
   m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
@@ -349,5 +349,12 @@
         TComPicYuv* pcPicYuvRecBase = (*(pcTDecTopBase->getListPic()->begin()))->getPicYuvRec(); 
 #if REPN_FORMAT_IN_VPS
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+        UInt refLayerId = pcSlice->getVPS()->getRefLayerId(m_layerId, i);
+        Bool sameBitDepths = ( g_bitDepthYLayer[m_layerId] == g_bitDepthYLayer[refLayerId] ) && ( g_bitDepthCLayer[m_layerId] == g_bitDepthCLayer[refLayerId] );
+
+        if( pcPicYuvRecBase->getWidth() != pcSlice->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getPicHeightInLumaSamples() || !zeroOffsets || !sameBitDepths )
+#else
         if(pcPicYuvRecBase->getWidth() != pcSlice->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getPicHeightInLumaSamples() || !zeroOffsets )
+#endif
 #else
         if(pcPicYuvRecBase->getWidth() != pcSlice->getSPS()->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getSPS()->getPicHeightInLumaSamples() || !zeroOffsets )
@@ -726,4 +733,40 @@
 #endif
 
+#if P0312_VERT_PHASE_ADJ
+  if( activeVPS->getVpsVuiVertPhaseInUseFlag() == 0 )
+  {    
+    for(Int i = 0; i < activeSPS->getNumScaledRefLayerOffsets(); i++)
+    {
+      UInt scaledRefLayerId = activeSPS->getScaledRefLayerId(i);
+      if( activeSPS->getVertPhasePositionEnableFlag( scaledRefLayerId ) )
+      {
+        printf("\nWarning: LayerId = %d: vert_phase_position_enable_flag[%d] = 1, however indication vert_phase_position_in_use_flag = 0\n", m_layerId, scaledRefLayerId );
+        break;
+      }
+    }
+  }
+#endif
+
+#if SPS_DPB_PARAMS
+  if( m_layerId > 0 )
+  {
+    // When not present sps_max_sub_layers_minus1 is inferred to be equal to vps_max_sub_layers_minus1.
+    sps->setMaxTLayers( activeVPS->getMaxTLayers() );
+
+    // When not present sps_temporal_id_nesting_flag is inferred to be equal to vps_temporal_id_nesting_flag
+    sps->setTemporalIdNestingFlag( activeVPS->getTemporalNestingFlag() );
+
+    // When sps_max_dec_pic_buffering_minus1[ i ] is not present for i in the range of 0 to sps_max_sub_layers_minus1, inclusive, due to nuh_layer_id being greater than 0, 
+    // it is inferred to be equal to max_vps_dec_pic_buffering_minus1[ TargetOptLayerSetIdx ][ currLayerId ][ i ] of the active VPS, where currLayerId is the nuh_layer_id of the layer that refers to the SPS.
+    for(UInt i=0; i < sps->getMaxTLayers(); i++)
+    {
+      // to avoid compiler warning "array subscript is above array bounds"
+      assert( i < MAX_TLAYER );
+
+      sps->setMaxDecPicBuffering( activeVPS->getMaxVpsDecPicBufferingMinus1( getCommonDecoderParams()->getTargetOutputLayerSetIdx(), sps->getLayerId(), i) + 1, i);
+    }
+  }
+#endif
+
   if( pps->getDependentSliceSegmentsEnabledFlag() )
   {
@@ -800,6 +843,8 @@
   TComPic*&   pcPic         = m_pcPic;
 #if SVC_EXTENSION
+#if !NO_OUTPUT_OF_PRIOR_PICS
 #if NO_CLRAS_OUTPUT_FLAG
   Bool bFirstSliceInSeq;
+#endif
 #endif
   m_apcSlicePilot->setVPS( m_parameterSetManagerDecoder.getPrefetchedVPS(0) );
@@ -855,4 +900,21 @@
   m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType);
 
+#if NO_OUTPUT_OF_PRIOR_PICS
+  // Infer the value of NoOutputOfPriorPicsFlag
+  if( m_apcSlicePilot->getRapPicFlag() )
+  {
+    if ( m_apcSlicePilot->getBlaPicFlag() || m_apcSlicePilot->getIdrPicFlag()  || 
+        (m_apcSlicePilot->getCraPicFlag() && m_bFirstSliceInSequence) ||
+        (m_apcSlicePilot->getCraPicFlag() && m_apcSlicePilot->getHandleCraAsBlaFlag()))
+    {
+      m_apcSlicePilot->setNoRaslOutputFlag( true );
+    }
+    else
+    {
+      m_apcSlicePilot->setNoRaslOutputFlag( false );
+    }
+  }
+#endif
+
   // Skip pictures due to random access
   if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
@@ -876,4 +938,63 @@
 #if SVC_EXTENSION
   bNewPOC = (m_apcSlicePilot->getPOC()!= m_prevPOC);
+
+#if NO_OUTPUT_OF_PRIOR_PICS
+#if NO_CLRAS_OUTPUT_FLAG
+  if (m_layerId == 0 && m_apcSlicePilot->getRapPicFlag() )
+  {
+    if (m_bFirstSliceInSequence)
+    {
+      setNoClrasOutputFlag(true);
+    }
+    else if ( m_apcSlicePilot->getBlaPicFlag() )
+    {
+      setNoClrasOutputFlag(true);
+    }
+#if O0149_CROSS_LAYER_BLA_FLAG
+    else if (m_apcSlicePilot->getIdrPicFlag() && m_apcSlicePilot->getCrossLayerBLAFlag())
+    {
+      setNoClrasOutputFlag(true);
+    }
+#endif
+    else
+    {
+      setNoClrasOutputFlag(false);
+    }      
+  }
+  else
+  {
+    setNoClrasOutputFlag(false);
+  }
+
+  m_apcSlicePilot->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, m_cListPic, getNoClrasOutputFlag());
+#endif
+
+  // Derive the value of NoOutputOfPriorPicsFlag
+  if( bNewPOC || m_layerId!=m_uiPrevLayerId )   // i.e. new coded picture
+  {
+    if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getNoRaslOutputFlag() )
+    {
+      this->setNoOutputOfPriorPicsFlags( true );
+    }
+    else if( m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag() )
+    {
+      this->setNoOutputOfPriorPicsFlags( m_apcSlicePilot->getNoOutputOfPriorPicsFlag() );
+    }
+    else
+    {
+      if( this->m_ppcTDecTop[0]->getNoClrasOutputFlag() )
+      {
+        this->setNoOutputOfPriorPicsFlags( true );
+      }
+    }
+  }
+#endif
+
+#if ALIGNED_BUMPING
+  if (bNewPOC || m_layerId!=m_uiPrevLayerId)
+  {
+    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
+  }
+#endif
   if (m_apcSlicePilot->isNextSlice() && (bNewPOC || m_layerId!=m_uiPrevLayerId) && !m_bFirstSliceInSequence )
   {
@@ -929,6 +1050,8 @@
 #endif
   }
+#if !NO_OUTPUT_OF_PRIOR_PICS
 #if NO_CLRAS_OUTPUT_FLAG
   bFirstSliceInSeq = m_bFirstSliceInSequence;
+#endif
 #endif
   m_bFirstSliceInSequence = false;
@@ -1093,4 +1216,5 @@
 #endif
 
+#if !NO_OUTPUT_OF_PRIOR_PICS
 #if NO_CLRAS_OUTPUT_FLAG
     if (m_layerId == 0 &&
@@ -1137,8 +1261,21 @@
     m_apcSlicePilot->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, m_cListPic, getNoClrasOutputFlag());
 #endif
-
+#else
+    if ( m_layerId == 0 && m_apcSlicePilot->getRapPicFlag() && getNoClrasOutputFlag() )
+    {
+      for (UInt i = 0; i < m_apcSlicePilot->getVPS()->getMaxLayers(); i++)
+      {
+        m_ppcTDecTop[i]->setLayerInitializedFlag(false);
+        m_ppcTDecTop[i]->setFirstPicInLayerDecodedFlag(false);
+      }
+    }
+#endif
     // Buffer initialize for prediction.
     m_cPrediction.initTempBuff();
+#if !ALIGNED_BUMPING
     m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
+#else
+    m_apcSlicePilot->checkLeadingPictureRestrictions(m_cListPic);
+#endif
     //  Get a new picture buffer
     xGetNewPicBuffer (m_apcSlicePilot, pcPic);
@@ -1600,5 +1737,9 @@
 #if SVC_EXTENSION
   sps->setLayerId(m_layerId);
+#if SPS_DPB_PARAMS
+  m_cEntropyDecoder.decodeSPS( sps ); // it should be removed after macro clean up
+#else
   m_cEntropyDecoder.decodeSPS( sps, &m_parameterSetManagerDecoder );
+#endif
   m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
 #if !REPN_FORMAT_IN_VPS   // ILRP can only be initialized at activation  
Index: trunk/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecTop.h	(revision 597)
+++ trunk/source/Lib/TLibDecoder/TDecTop.h	(revision 644)
@@ -239,5 +239,10 @@
   fstream* getBLSyntaxFile() { return m_pBLSyntaxFile; }
 #endif
-
+#if NO_OUTPUT_OF_PRIOR_PICS
+#if NO_CLRAS_OUTPUT_FLAG
+  Bool getNoOutputOfPriorPicsFlags()         { return m_noOutputOfPriorPicsFlags;}
+  Void setNoOutputOfPriorPicsFlags(Bool x)   { m_noOutputOfPriorPicsFlags = x;   }
+#endif
+#endif
 protected:
   Void  xGetNewPicBuffer  (TComSlice* pcSlice, TComPic*& rpcPic);
@@ -266,7 +271,9 @@
   Int  getFirstPicInLayerDecodedFlag()       { return m_firstPicInLayerDecodedFlag;}
   Void setFirstPicInLayerDecodedFlag(Bool x) { m_firstPicInLayerDecodedFlag = x;   }
+#if !NO_OUTPUT_OF_PRIOR_PICS
   Int  getNoOutputOfPriorPicsFlags()         { return m_noOutputOfPriorPicsFlags;}
   Void setNoOutputOfPriorPicsFlags(Bool x)   { m_noOutputOfPriorPicsFlags = x;   }
 #endif
+#endif
 };// END CLASS DEFINITION TDecTop
 
Index: trunk/source/Lib/TLibEncoder/SEIwrite.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/SEIwrite.cpp	(revision 597)
+++ 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 597)
+++ 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 597)
+++ 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 597)
+++ 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 597)
+++ 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 597)
+++ 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 597)
+++ 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 597)
+++ 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 597)
+++ 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 597)
+++ 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 597)
+++ 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 597)
+++ 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 597)
+++ 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 597)
+++ 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 597)
+++ 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
