Index: trunk/source/Lib/TLibDecoder/SEIread.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/SEIread.cpp	(revision 229)
+++ trunk/source/Lib/TLibDecoder/SEIread.cpp	(revision 310)
@@ -90,19 +90,18 @@
     fprintf( g_hTrace, "=========== Decoding Unit Information SEI message ===========\n");
     break;
-#if J0149_TONE_MAPPING_SEI
   case SEI::TONE_MAPPING_INFO:
     fprintf( g_hTrace, "===========Tone Mapping Info SEI message ===========\n");
     break;
-#endif
-#if L0208_SOP_DESCRIPTION_SEI
+#if M0043_LAYERS_PRESENT_SEI
+  case SEI::LAYERS_PRESENT:
+    fprintf( g_hTrace, "=========== Layers Present SEI message ===========\n");
+    break;
+#endif
   case SEI::SOP_DESCRIPTION:
     fprintf( g_hTrace, "=========== SOP Description SEI message ===========\n");
     break;
-#endif
-#if K0180_SCALABLE_NESTING_SEI
   case SEI::SCALABLE_NESTING:
     fprintf( g_hTrace, "=========== Scalable Nesting SEI message ===========\n");
     break;
-#endif
   default:
     fprintf( g_hTrace, "=========== Unknown SEI message ===========\n");
@@ -115,5 +114,9 @@
  * unmarshal a single SEI message from bitstream bs
  */
+#if M0043_LAYERS_PRESENT_SEI
+void SEIReader::parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps)
+#else
 void SEIReader::parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps)
+#endif
 {
   setBitstream(bs);
@@ -122,5 +125,9 @@
   do
   {
+#if M0043_LAYERS_PRESENT_SEI
+    xReadSEImessage(seis, nalUnitType, vps, sps);
+#else
     xReadSEImessage(seis, nalUnitType, sps);
+#endif
     /* SEI messages are an integer number of bytes, something has failed
     * in the parsing if bitstream not byte-aligned */
@@ -133,5 +140,9 @@
 }
 
+#if M0043_LAYERS_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
 {
 #if ENC_DEC_TRACE
@@ -234,22 +245,33 @@
       xParseSEIGradualDecodingRefreshInfo((SEIGradualDecodingRefreshInfo&) *sei, payloadSize);
       break;
-#if J0149_TONE_MAPPING_SEI
     case SEI::TONE_MAPPING_INFO:
       sei = new SEIToneMappingInfo;
       xParseSEIToneMappingInfo((SEIToneMappingInfo&) *sei, payloadSize);
       break;
-#endif
-#if L0208_SOP_DESCRIPTION_SEI
+#if M0043_LAYERS_PRESENT_SEI
+    case SEI::LAYERS_PRESENT:
+      if (!vps)
+      {
+        printf ("Warning: Found Layers present SEI message, but no active VPS is available. Ignoring.");
+      }
+      else
+      {
+        sei = new SEILayersPresent;
+        xParseSEILayersPresent((SEILayersPresent&) *sei, payloadSize, vps);
+      }
+      break;
+#endif
     case SEI::SOP_DESCRIPTION:
       sei = new SEISOPDescription;
       xParseSEISOPDescription((SEISOPDescription&) *sei, payloadSize);
       break;
-#endif
-#if K0180_SCALABLE_NESTING_SEI
     case SEI::SCALABLE_NESTING:
       sei = new SEIScalableNesting;
+#if M0043_LAYERS_PRESENT_SEI
+      xParseSEIScalableNesting((SEIScalableNesting&) *sei, nalUnitType, payloadSize, vps, sps);
+#else
       xParseSEIScalableNesting((SEIScalableNesting&) *sei, nalUnitType, payloadSize, sps);
-      break;
-#endif
+#endif
+      break;
     default:
       for (UInt i = 0; i < payloadSize; i++)
@@ -265,10 +287,8 @@
     switch (payloadType)
     {
-#if L0363_SEI_ALLOW_SUFFIX
       case SEI::USER_DATA_UNREGISTERED:
         sei = new SEIuserDataUnregistered;
         xParseSEIuserDataUnregistered((SEIuserDataUnregistered&) *sei, payloadSize);
         break;
-#endif
       case SEI::DECODED_PICTURE_HASH:
         sei = new SEIDecodedPictureHash;
@@ -402,8 +422,6 @@
   UInt val; 
   READ_CODE(4, val, "active_vps_id");      sei.activeVPSId = val; 
-#if L0047_APS_FLAGS
   READ_FLAG( val, "full_random_access_flag");  sei.m_fullRandomAccessFlag = val ? true : false;
   READ_FLAG( val, "no_param_set_update_flag"); sei.m_noParamSetUpdateFlag = val ? true : false;
-#endif
   READ_UVLC(   val, "num_sps_ids_minus1"); sei.numSpsIdsMinus1 = val;
 
@@ -438,5 +456,4 @@
     sei.m_duSptCpbRemovalDelay = 0;
   }
-#if L0044_DU_DPB_OUTPUT_DELAY_HRD
   READ_FLAG( val, "dpb_output_du_delay_present_flag"); sei.m_dpbOutputDuDelayPresentFlag = val ? true : false;
   if(sei.m_dpbOutputDuDelayPresentFlag)
@@ -445,5 +462,4 @@
     sei.m_picSptDpbOutputDuDelay = val;
   }
-#endif
   xParseByteAlign();
 }
@@ -462,5 +478,4 @@
     READ_FLAG( code, "rap_cpb_params_present_flag" );                   sei.m_rapCpbParamsPresentFlag = code;
   }
-#if L0328_SPLICING
   //read splicing flag and cpb_removal_delay_delta
   READ_FLAG( code, "concatenation_flag"); 
@@ -468,6 +483,4 @@
   READ_CODE( ( pHRD->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_delta_minus1" );
   sei.m_auCpbRemovalDelayDelta = code + 1;
-#endif
-#if L0044_CPB_DPB_DELAY_OFFSET
   if( sei.m_rapCpbParamsPresentFlag )
   {
@@ -475,5 +488,4 @@
     READ_CODE( pHRD->getDpbOutputDelayLengthMinus1()  + 1, code, "dpb_delay_offset" );      sei.m_dpbDelayOffset = code;
   }
-#endif
   for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
   {
@@ -507,27 +519,13 @@
   TComHRD *hrd = vui->getHrdParameters();
 
-#if !L0045_CONDITION_SIGNALLING
-  // This condition was probably OK before the pic_struct, progressive_source_idc, duplicate_flag were added
-  if( !hrd->getNalHrdParametersPresentFlag() && !hrd->getVclHrdParametersPresentFlag() )
-  {
-    return;
-  }
-#endif
-
   if( vui->getFrameFieldInfoPresentFlag() )
   {
     READ_CODE( 4, code, "pic_struct" );             sei.m_picStruct            = code;
-#if L0046_RENAME_PROG_SRC_IDC
     READ_CODE( 2, code, "source_scan_type" );       sei.m_sourceScanType = code;
-#else
-    READ_CODE( 2, code, "progressive_source_idc" ); sei.m_progressiveSourceIdc = code;
-#endif
     READ_FLAG(    code, "duplicate_flag" );         sei.m_duplicateFlag        = ( code == 1 ? true : false );
   }
 
-#if L0045_CONDITION_SIGNALLING
   if( hrd->getCpbDpbDelaysPresentFlag())
   {
-#endif
     READ_CODE( ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_minus1" );
     sei.m_auCpbRemovalDelay = code + 1;
@@ -535,5 +533,4 @@
     sei.m_picDpbOutputDelay = code;
 
-#if L0044_DU_DPB_OUTPUT_DELAY_HRD
     if(hrd->getSubPicCpbParamsPresentFlag())
     {
@@ -541,5 +538,4 @@
       sei.m_picDpbOutputDuDelay = code;
     }
-#endif
     if( hrd->getSubPicCpbParamsPresentFlag() && hrd->getSubPicCpbParamsInPicTimingSEIFlag() )
     {
@@ -575,7 +571,5 @@
       }
     }
-#if L0045_CONDITION_SIGNALLING
-  }
-#endif
+  }
   xParseByteAlign();
 }
@@ -598,7 +592,5 @@
   {
     READ_CODE( 7, val, "frame_packing_arrangement_type" );          sei.m_arrangementType = val;
-#if L0444_FPA_TYPE
     assert((sei.m_arrangementType > 2) && (sei.m_arrangementType < 6) );
-#endif
     READ_FLAG( val, "quincunx_sampling_flag" );                     sei.m_quincunxSamplingFlag = val;
 
@@ -620,9 +612,5 @@
 
     READ_CODE( 8, val, "frame_packing_arrangement_reserved_byte" );   sei.m_arrangementReservedByte = val;
-#if L0045_PERSISTENCE_FLAGS
     READ_FLAG( val,  "frame_packing_arrangement_persistence_flag" );  sei.m_arrangementPersistenceFlag = val ? true : false;
-#else
-    READ_UVLC( val, "frame_packing_arrangement_repetition_period" );  sei.m_arrangementRepetetionPeriod = val;
-#endif
   }
   READ_FLAG( val, "upsampled_aspect_ratio" );                       sei.m_upsampledAspectRatio = val;
@@ -640,13 +628,5 @@
     READ_FLAG( val,     "ver_flip" );                              sei.verFlip               = val;
     READ_CODE( 16, val, "anticlockwise_rotation" );                sei.anticlockwiseRotation = val;
-#if L0045_PERSISTENCE_FLAGS
     READ_FLAG( val,     "display_orientation_persistence_flag" );  sei.persistenceFlag       = val;
-#else
-    READ_UVLC( val,     "display_orientation_repetition_period" ); sei.repetitionPeriod      = val;
-#endif
-#if !REMOVE_SINGLE_SEI_EXTENSION_FLAGS
-    READ_FLAG( val,     "display_orientation_extension_flag" );    sei.extensionFlag         = val;
-    assert( !sei.extensionFlag );
-#endif
   }
   xParseByteAlign();
@@ -668,5 +648,4 @@
 }
 
-#if J0149_TONE_MAPPING_SEI
 Void SEIReader::xParseSEIToneMappingInfo(SEIToneMappingInfo& sei, UInt /*payloadSize*/)
 {
@@ -749,7 +728,26 @@
   xParseByteAlign();
 }
-#endif
-
-#if L0208_SOP_DESCRIPTION_SEI
+
+#if M0043_LAYERS_PRESENT_SEI
+Void SEIReader::xParseSEILayersPresent(SEILayersPresent &sei, UInt payloadSize, TComVPS *vps)
+{
+  UInt uiCode;
+  UInt i = 0;
+
+  READ_UVLC( uiCode,           "lp_sei_active_vps_id" ); sei.m_activeVpsId = uiCode;
+  assert(vps->getVPSId() == sei.m_activeVpsId);
+  sei.m_vpsMaxLayers = vps->getMaxLayers();
+  for (; i < sei.m_vpsMaxLayers; i++)
+  {
+    READ_FLAG( uiCode,         "layer_present_flag"   ); sei.m_layerPresentFlag[i] = uiCode ? true : false;
+  }
+  for (; i < MAX_LAYERS; i++)
+  {
+    sei.m_layerPresentFlag[i] = false;
+  }
+  xParseByteAlign();
+}
+#endif
+
 Void SEIReader::xParseSEISOPDescription(SEISOPDescription &sei, UInt payloadSize)
 {
@@ -775,8 +773,10 @@
   xParseByteAlign();
 }
-#endif
-
-#if K0180_SCALABLE_NESTING_SEI
+
+#if M0043_LAYERS_PRESENT_SEI
+Void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComVPS *vps, TComSPS *sps)
+#else
 Void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComSPS *sps)
+#endif
 {
   UInt uiCode;
@@ -820,9 +820,12 @@
   // read nested SEI messages
   do {
+#if M0043_LAYERS_PRESENT_SEI
+    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps);
+#else
     xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps);
+#endif
   } while (m_pcBitstream->getNumBitsLeft() > 8);
 
 }
-#endif
 
 Void SEIReader::xParseByteAlign()
Index: trunk/source/Lib/TLibDecoder/SEIread.h
===================================================================
--- trunk/source/Lib/TLibDecoder/SEIread.h	(revision 229)
+++ trunk/source/Lib/TLibDecoder/SEIread.h	(revision 310)
@@ -56,7 +56,15 @@
   SEIReader() {};
   virtual ~SEIReader() {};
+#if M0043_LAYERS_PRESENT_SEI
+  Void parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps);
+#else
   Void parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps);
+#endif
 protected:
+#if M0043_LAYERS_PRESENT_SEI
+  Void xReadSEImessage                (SEIMessages& seis, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps);
+#else
   Void xReadSEImessage                (SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps);
+#endif
   Void xParseSEIuserDataUnregistered  (SEIuserDataUnregistered &sei, UInt payloadSize);
   Void xParseSEIActiveParameterSets   (SEIActiveParameterSets  &sei, UInt payloadSize);
@@ -70,11 +78,10 @@
   Void xParseSEITemporalLevel0Index   (SEITemporalLevel0Index &sei, UInt payloadSize);
   Void xParseSEIGradualDecodingRefreshInfo (SEIGradualDecodingRefreshInfo &sei, UInt payloadSize);
-#if J0149_TONE_MAPPING_SEI
   Void xParseSEIToneMappingInfo       (SEIToneMappingInfo& sei, UInt payloadSize);
-#endif
-#if L0208_SOP_DESCRIPTION_SEI
   Void xParseSEISOPDescription        (SEISOPDescription &sei, UInt payloadSize);
-#endif
-#if K0180_SCALABLE_NESTING_SEI
+#if M0043_LAYERS_PRESENT_SEI
+  Void xParseSEILayersPresent         (SEILayersPresent &sei, UInt payloadSize, TComVPS *vps);
+  Void xParseSEIScalableNesting       (SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComVPS *vps, TComSPS *sps);
+#else
   Void xParseSEIScalableNesting       (SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComSPS *sps);
 #endif
Index: trunk/source/Lib/TLibDecoder/TDecBinCoder.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecBinCoder.h	(revision 229)
+++ trunk/source/Lib/TLibDecoder/TDecBinCoder.h	(revision 310)
@@ -54,5 +54,4 @@
   virtual Void  start             ()                                          = 0;
   virtual Void  finish            ()                                          = 0;
-  virtual Void  flush            ()                                           = 0;
 
   virtual Void  decodeBin         ( UInt& ruiBin, ContextModel& rcCtxModel )  = 0;
@@ -61,6 +60,4 @@
   virtual Void  decodeBinTrm      ( UInt& ruiBin                           )  = 0;
   
-  virtual Void  resetBac          ()                                          = 0;
-  virtual Void  decodePCMAlignBits()                                          = 0;
   virtual Void  xReadPCMCode      ( UInt uiLength, UInt& ruiCode)              = 0;
 
Index: trunk/source/Lib/TLibDecoder/TDecBinCoderCABAC.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecBinCoderCABAC.cpp	(revision 229)
+++ trunk/source/Lib/TLibDecoder/TDecBinCoderCABAC.cpp	(revision 310)
@@ -75,15 +75,9 @@
 TDecBinCABAC::finish()
 {
-}
-
-Void 
-TDecBinCABAC::flush()
-{
-  while (m_pcTComBitstream->getNumBitsLeft() > 0 && m_pcTComBitstream->getNumBitsUntilByteAligned() != 0)
-  {
-    UInt uiBits;
-    m_pcTComBitstream->read ( 1, uiBits );
-  }
-  start();
+  UInt lastByte;
+
+  m_pcTComBitstream->peekPreviousByte( lastByte );
+  // Check for proper stop/alignment pattern
+  assert( ((lastByte << (8 + m_bitsNeeded)) & 0xff) == 0x80 );
 }
 
@@ -241,25 +235,4 @@
 }
 
-/** Reset BAC register values.
- * \returns Void
- */
-Void TDecBinCABAC::resetBac()
-{
-  m_uiRange    = 510;
-  m_bitsNeeded = -8;
-  m_uiValue    = m_pcTComBitstream->read( 16 );
-}
-
-/** Decode PCM alignment zero bits.
- * \returns Void
- */
-Void TDecBinCABAC::decodePCMAlignBits()
-{
-  Int iNum = m_pcTComBitstream->getNumBitsUntilByteAligned();
-  
-  UInt uiBit = 0;
-  m_pcTComBitstream->read( iNum, uiBit );
-}
-
 /** Read a PCM code.
  * \param uiLength code bit-depth
Index: trunk/source/Lib/TLibDecoder/TDecBinCoderCABAC.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecBinCoderCABAC.h	(revision 229)
+++ trunk/source/Lib/TLibDecoder/TDecBinCoderCABAC.h	(revision 310)
@@ -56,5 +56,4 @@
   Void  start             ();
   Void  finish            ();
-  Void  flush             ();
   
   Void  decodeBin         ( UInt& ruiBin, ContextModel& rcCtxModel );
@@ -63,6 +62,4 @@
   Void  decodeBinTrm      ( UInt& ruiBin                           );
   
-  Void  resetBac          ();
-  Void  decodePCMAlignBits();
   Void  xReadPCMCode      ( UInt uiLength, UInt& ruiCode );
   
Index: trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 229)
+++ trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 310)
@@ -2,5 +2,5 @@
 * License, included below. This software may be subject to other third party
 * and contributor rights, including patent rights, and no such rights are
-* granted under this license.  
+* granted under this license.
 *
 * Copyright (c) 2010-2013, ITU/ISO/IEC
@@ -93,5 +93,5 @@
   }
 
-  if (interRPSPred) 
+  if (interRPSPred)
   {
     UInt bit;
@@ -114,7 +114,7 @@
     for(Int j=0 ; j <= rpsRef->getNumberOfPictures(); j++)
     {
-      READ_CODE(1, bit, "used_by_curr_pic_flag" ); //first bit is "1" if Idc is 1 
+      READ_CODE(1, bit, "used_by_curr_pic_flag" ); //first bit is "1" if Idc is 1
       Int refIdc = bit;
-      if (refIdc == 0) 
+      if (refIdc == 0)
       {
         READ_CODE(1, bit, "use_delta_flag" ); //second bit is "1" if Idc is 2, "0" otherwise.
@@ -131,13 +131,13 @@
           k0++;
         }
-        else 
+        else
         {
           k1++;
         }
         k++;
-      }  
-      rps->setRefIdc(j,refIdc);  
-    }
-    rps->setNumRefIdc(rpsRef->getNumberOfPictures()+1);  
+      }
+      rps->setRefIdc(j,refIdc);
+    }
+    rps->setNumRefIdc(rpsRef->getNumberOfPictures()+1);
     rps->setNumberOfPictures(k);
     rps->setNumberOfNegativePictures(k0);
@@ -175,35 +175,7 @@
 }
 
-/** copy SAO parameter
-* \param dst  
-* \param src 
-*/
-inline Void copySaoOneLcuParam(SaoLcuParam* dst,  SaoLcuParam* src)
-{
-  Int i;
-  dst->partIdx = src->partIdx;
-  dst->typeIdx = src->typeIdx;
-  if (dst->typeIdx != -1)
-  {
-    dst->subTypeIdx = src->subTypeIdx ;
-    dst->length  = src->length;
-    for (i=0;i<dst->length;i++)
-    {
-      dst->offset[i] = src->offset[i];
-    }
-  }
-  else
-  {
-    dst->length  = 0;
-    for (i=0;i<SAO_BO_LEN;i++)
-    {
-      dst->offset[i] = 0;
-    }
-  }
-}
-
 Void TDecCavlc::parsePPS(TComPPS* pcPPS)
 {
-#if ENC_DEC_TRACE  
+#if ENC_DEC_TRACE
   xTracePPSHeader (pcPPS);
 #endif
@@ -212,33 +184,32 @@
   Int   iCode;
 
-  READ_UVLC( uiCode, "pps_pic_parameter_set_id");                     pcPPS->setPPSId (uiCode);
-  READ_UVLC( uiCode, "pps_seq_parameter_set_id");                     pcPPS->setSPSId (uiCode);
+  READ_UVLC( uiCode, "pps_pic_parameter_set_id");
+  assert(uiCode <= 63);
+  pcPPS->setPPSId (uiCode);
+  
+  READ_UVLC( uiCode, "pps_seq_parameter_set_id");
+  assert(uiCode <= 15);
+  pcPPS->setSPSId (uiCode);
+  
   READ_FLAG( uiCode, "dependent_slice_segments_enabled_flag"    );    pcPPS->setDependentSliceSegmentsEnabledFlag   ( uiCode == 1 );
-#if L0255_MOVE_PPS_FLAGS
   READ_FLAG( uiCode, "output_flag_present_flag" );                    pcPPS->setOutputFlagPresentFlag( uiCode==1 );
 
   READ_CODE(3, uiCode, "num_extra_slice_header_bits");                pcPPS->setNumExtraSliceHeaderBits(uiCode);
-#endif
   READ_FLAG ( uiCode, "sign_data_hiding_flag" ); pcPPS->setSignHideFlag( uiCode );
 
   READ_FLAG( uiCode,   "cabac_init_present_flag" );            pcPPS->setCabacInitPresentFlag( uiCode ? true : false );
 
-#if L0323_LIMIT_DEFAULT_LIST_SIZE
   READ_UVLC(uiCode, "num_ref_idx_l0_default_active_minus1");
   assert(uiCode <= 14);
   pcPPS->setNumRefIdxL0DefaultActive(uiCode+1);
-  
+
   READ_UVLC(uiCode, "num_ref_idx_l1_default_active_minus1");
   assert(uiCode <= 14);
   pcPPS->setNumRefIdxL1DefaultActive(uiCode+1);
-#else
-  READ_UVLC(uiCode, "num_ref_idx_l0_default_active_minus1");       pcPPS->setNumRefIdxL0DefaultActive(uiCode+1);
-  READ_UVLC(uiCode, "num_ref_idx_l1_default_active_minus1");       pcPPS->setNumRefIdxL1DefaultActive(uiCode+1);
-#endif
-  
+
   READ_SVLC(iCode, "init_qp_minus26" );                            pcPPS->setPicInitQPMinus26(iCode);
   READ_FLAG( uiCode, "constrained_intra_pred_flag" );              pcPPS->setConstrainedIntraPred( uiCode ? true : false );
-  READ_FLAG( uiCode, "transform_skip_enabled_flag" );               
-  pcPPS->setUseTransformSkip ( uiCode ? true : false ); 
+  READ_FLAG( uiCode, "transform_skip_enabled_flag" );
+  pcPPS->setUseTransformSkip ( uiCode ? true : false );
 
   READ_FLAG( uiCode, "cu_qp_delta_enabled_flag" );            pcPPS->setUseDQP( uiCode ? true : false );
@@ -270,17 +241,13 @@
   pcPPS->setWPBiPred( uiCode==1 );
 
-#if !L0255_MOVE_PPS_FLAGS
-  READ_FLAG( uiCode, "output_flag_present_flag" );
-  pcPPS->setOutputFlagPresentFlag( uiCode==1 );
-#endif
   READ_FLAG( uiCode, "transquant_bypass_enable_flag");
   pcPPS->setTransquantBypassEnableFlag(uiCode ? true : false);
   READ_FLAG( uiCode, "tiles_enabled_flag"               );    pcPPS->setTilesEnabledFlag            ( uiCode == 1 );
   READ_FLAG( uiCode, "entropy_coding_sync_enabled_flag" );    pcPPS->setEntropyCodingSyncEnabledFlag( uiCode == 1 );
-  
+
   if( pcPPS->getTilesEnabledFlag() )
   {
-    READ_UVLC ( uiCode, "num_tile_columns_minus1" );                pcPPS->setNumColumnsMinus1( uiCode );  
-    READ_UVLC ( uiCode, "num_tile_rows_minus1" );                   pcPPS->setNumRowsMinus1( uiCode );  
+    READ_UVLC ( uiCode, "num_tile_columns_minus1" );                pcPPS->setNumColumnsMinus1( uiCode );
+    READ_UVLC ( uiCode, "num_tile_rows_minus1" );                   pcPPS->setNumRowsMinus1( uiCode );
     READ_FLAG ( uiCode, "uniform_spacing_flag" );                   pcPPS->setUniformSpacingFlag( uiCode );
 
@@ -289,6 +256,6 @@
       UInt* columnWidth = (UInt*)malloc(pcPPS->getNumColumnsMinus1()*sizeof(UInt));
       for(UInt i=0; i<pcPPS->getNumColumnsMinus1(); i++)
-      { 
-        READ_UVLC( uiCode, "column_width_minus1" );  
+      {
+        READ_UVLC( uiCode, "column_width_minus1" );
         columnWidth[i] = uiCode+1;
       }
@@ -303,5 +270,5 @@
       }
       pcPPS->setRowHeight(rowHeight);
-      free(rowHeight);  
+      free(rowHeight);
     }
 
@@ -335,8 +302,4 @@
   pcPPS->setLog2ParallelMergeLevelMinus2 (uiCode);
 
-#if !L0255_MOVE_PPS_FLAGS
-  READ_CODE(3, uiCode, "num_extra_slice_header_bits");
-  pcPPS->setNumExtraSliceHeaderBits(uiCode);
-#endif
   READ_FLAG( uiCode, "slice_segment_header_extension_present_flag");
   pcPPS->setSliceHeaderExtensionPresentFlag(uiCode);
@@ -400,5 +363,4 @@
 
   READ_FLAG(     uiCode, "field_seq_flag");                           pcVUI->setFieldSeqFlag(uiCode);
-  assert(pcVUI->getFieldSeqFlag() == false);        // not supported yet
 
   READ_FLAG(uiCode, "frame_field_info_present_flag");                 pcVUI->setFrameFieldInfoPresentFlag(uiCode);
@@ -413,5 +375,4 @@
     READ_UVLC(   uiCode, "def_disp_win_bottom_offset" );              defDisp.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
   }
-#if L0043_TIMING_INFO
   TimingInfo *timingInfo = pcVUI->getTimingInfo();
   READ_FLAG(       uiCode, "vui_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
@@ -425,5 +386,4 @@
       READ_UVLC(   uiCode, "vui_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
     }
-#endif  
   READ_FLAG(     uiCode, "hrd_parameters_present_flag");              pcVUI->setHrdParametersPresentFlag(uiCode);
   if( pcVUI->getHrdParametersPresentFlag() )
@@ -431,26 +391,19 @@
     parseHrdParameters( pcVUI->getHrdParameters(), 1, pcSPS->getMaxTLayers() - 1 );
   }
-#if L0043_TIMING_INFO
-  }
-#endif
-#if !L0043_TIMING_INFO
-  READ_FLAG( uiCode, "poc_proportional_to_timing_flag" ); pcVUI->setPocProportionalToTimingFlag(uiCode ? true : false);
-  if( pcVUI->getPocProportionalToTimingFlag() && pcVUI->getHrdParameters()->getTimingInfoPresentFlag() )
-  {
-    READ_UVLC( uiCode, "num_ticks_poc_diff_one_minus1" ); pcVUI->setNumTicksPocDiffOneMinus1(uiCode);
-  }
-#endif
+  }
   READ_FLAG(     uiCode, "bitstream_restriction_flag");               pcVUI->setBitstreamRestrictionFlag(uiCode);
   if (pcVUI->getBitstreamRestrictionFlag())
   {
     READ_FLAG(   uiCode, "tiles_fixed_structure_flag");               pcVUI->setTilesFixedStructureFlag(uiCode);
+#if M0464_TILE_BOUNDARY_ALIGNED_FLAG
+    if ( pcSPS->getLayerId() > 0 )
+    {
+      READ_FLAG( uiCode, "tile_boundaries_aligned_flag" ); pcVUI->setTileBoundariesAlignedFlag( uiCode == 1 );
+    }
+#endif
     READ_FLAG(   uiCode, "motion_vectors_over_pic_boundaries_flag");  pcVUI->setMotionVectorsOverPicBoundariesFlag(uiCode);
     READ_FLAG(   uiCode, "restricted_ref_pic_lists_flag");            pcVUI->setRestrictedRefPicListsFlag(uiCode);
-#if L0043_MSS_IDC
     READ_UVLC( uiCode, "min_spatial_segmentation_idc");            pcVUI->setMinSpatialSegmentationIdc(uiCode);
     assert(uiCode < 4096);
-#else
-    READ_CODE( 8, uiCode, "min_spatial_segmentation_idc");            pcVUI->setMinSpatialSegmentationIdc(uiCode);
-#endif
     READ_UVLC(   uiCode, "max_bytes_per_pic_denom" );                 pcVUI->setMaxBytesPerPicDenom(uiCode);
     READ_UVLC(   uiCode, "max_bits_per_mincu_denom" );                pcVUI->setMaxBitsPerMinCuDenom(uiCode);
@@ -465,12 +418,4 @@
   if( commonInfPresentFlag )
   {
-#if !L0043_TIMING_INFO
-    READ_FLAG( uiCode, "timing_info_present_flag" );                  hrd->setTimingInfoPresentFlag( uiCode == 1 ? true : false );
-    if( hrd->getTimingInfoPresentFlag() )
-    {
-      READ_CODE( 32, uiCode, "num_units_in_tick" );                   hrd->setNumUnitsInTick( uiCode );
-      READ_CODE( 32, uiCode, "time_scale" );                          hrd->setTimeScale( uiCode );
-    }
-#endif
     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 );
@@ -483,7 +428,5 @@
         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 );
-#if L0044_DU_DPB_OUTPUT_DELAY_HRD
         READ_CODE( 5, uiCode, "dpb_output_delay_du_length_minus1"  ); hrd->setDpbOutputDelayDuLengthMinus1( uiCode );
-#endif
       }
       READ_CODE( 4, uiCode, "bit_rate_scale" );                       hrd->setBitRateScale( uiCode );
@@ -510,25 +453,18 @@
       hrd->setFixedPicRateWithinCvsFlag( i, true );
     }
-#if L0372
     hrd->setLowDelayHrdFlag( i, 0 ); // Infered to be 0 when not present
     hrd->setCpbCntMinus1   ( i, 0 ); // Infered to be 0 when not present
-#endif
     if( hrd->getFixedPicRateWithinCvsFlag( i ) )
     {
       READ_UVLC( uiCode, "elemental_duration_in_tc_minus1" );             hrd->setPicDurationInTcMinus1( i, uiCode );
     }
-#if L0372
     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 );      
-    }
-#else
-    READ_FLAG( uiCode, "low_delay_hrd_flag" );                      hrd->setLowDelayHrdFlag( i, uiCode == 1 ? true : false  );
-    READ_UVLC( uiCode, "cpb_cnt_minus1" );                          hrd->setCpbCntMinus1( i, uiCode );
-#endif
+      READ_UVLC( uiCode, "cpb_cnt_minus1" );                          hrd->setCpbCntMinus1( i, uiCode );
+    }
     for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
     {
@@ -542,8 +478,6 @@
           if( hrd->getSubPicCpbParamsPresentFlag() )
           {
-#if L0363_DU_BIT_RATE
+            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 );
-#endif
-            READ_UVLC( uiCode, "cpb_size_du_value_minus1" );       hrd->setDuCpbSizeValueMinus1( i, j, nalOrVcl, uiCode );
           }
           READ_FLAG( uiCode, "cbr_flag" );                          hrd->setCbrFlag( i, j, nalOrVcl, uiCode == 1 ? true : false  );
@@ -554,7 +488,11 @@
 }
 
+#if SPS_SUB_LAYER_INFO
+Void TDecCavlc::parseSPS(TComSPS* pcSPS, ParameterSetManagerDecoder *parameterSetManager)
+#else
 Void TDecCavlc::parseSPS(TComSPS* pcSPS)
-{
-#if ENC_DEC_TRACE  
+#endif
+{
+#if ENC_DEC_TRACE
   xTraceSPSHeader (pcSPS);
 #endif
@@ -562,15 +500,36 @@
   UInt  uiCode;
   READ_CODE( 4,  uiCode, "sps_video_parameter_set_id");          pcSPS->setVPSId        ( uiCode );
-  READ_CODE( 3,  uiCode, "sps_max_sub_layers_minus1" );          pcSPS->setMaxTLayers   ( uiCode+1 );
-  READ_FLAG( uiCode, "sps_temporal_id_nesting_flag" );               pcSPS->setTemporalIdNestingFlag ( uiCode > 0 ? true : false );
+#if SPS_SUB_LAYER_INFO
+  if(pcSPS->getLayerId() == 0)
+  {
+#endif
+    READ_CODE( 3,  uiCode, "sps_max_sub_layers_minus1" );          pcSPS->setMaxTLayers   ( uiCode+1 );
+    assert(uiCode <= 6);
+  
+    READ_FLAG( uiCode, "sps_temporal_id_nesting_flag" );               pcSPS->setTemporalIdNestingFlag ( uiCode > 0 ? true : false );
+#if SPS_SUB_LAYER_INFO
+  }
+  else
+  {
+    pcSPS->setMaxTLayers           ( parameterSetManager->getPrefetchedVPS(pcSPS->getVPSId())->getMaxTLayers()          );
+    pcSPS->setTemporalIdNestingFlag( parameterSetManager->getPrefetchedVPS(pcSPS->getVPSId())->getTemporalNestingFlag() );
+  }
+#endif 
   if ( pcSPS->getMaxTLayers() == 1 )
   {
     // sps_temporal_id_nesting_flag must be 1 when sps_max_sub_layers_minus1 is 0
+#if SPS_SUB_LAYER_INFO
+    assert( pcSPS->getTemporalIdNestingFlag() == true );
+#else
     assert( uiCode == 1 );
-  }
-  
+#endif
+  }
+
   parsePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
   READ_UVLC(     uiCode, "sps_seq_parameter_set_id" );           pcSPS->setSPSId( uiCode );
+  assert(uiCode <= 15);
+  
   READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( uiCode );
+  assert(uiCode <= 3);
   // in the first version we only support chroma_format_idc equal to 1 (4:2:0), so separate_colour_plane_flag cannot appear in the bitstream
   assert (uiCode == 1);
@@ -593,27 +552,26 @@
 
   READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
+  assert(uiCode <= 6);
   pcSPS->setBitDepthY( uiCode + 8 );
   pcSPS->setQpBDOffsetY( (Int) (6*uiCode) );
 
   READ_UVLC( uiCode,    "bit_depth_chroma_minus8" );
+  assert(uiCode <= 6);
   pcSPS->setBitDepthC( uiCode + 8 );
   pcSPS->setQpBDOffsetC( (Int) (6*uiCode) );
 
   READ_UVLC( uiCode,    "log2_max_pic_order_cnt_lsb_minus4" );   pcSPS->setBitsForPOC( 4 + uiCode );
+  assert(uiCode <= 12);
 
   UInt subLayerOrderingInfoPresentFlag;
   READ_FLAG(subLayerOrderingInfoPresentFlag, "sps_sub_layer_ordering_info_present_flag");
+  
   for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
   {
-#if L0323_DPB
     READ_UVLC ( uiCode, "sps_max_dec_pic_buffering_minus1");
     pcSPS->setMaxDecPicBuffering( uiCode + 1, i);
-#else
-    READ_UVLC ( uiCode, "sps_max_dec_pic_buffering");
-    pcSPS->setMaxDecPicBuffering( uiCode, i);
-#endif
     READ_UVLC ( uiCode, "sps_num_reorder_pics" );
     pcSPS->setNumReorderPics(uiCode, i);
-    READ_UVLC ( uiCode, "sps_max_latency_increase");
+    READ_UVLC ( uiCode, "sps_max_latency_increase_plus1");
     pcSPS->setMaxLatencyIncrease( uiCode, i );
 
@@ -636,5 +594,5 @@
   pcSPS->setLog2DiffMaxMinCodingBlockSize(uiCode);
   Int maxCUDepthDelta = uiCode;
-  pcSPS->setMaxCUWidth  ( 1<<(log2MinCUSize + maxCUDepthDelta) ); 
+  pcSPS->setMaxCUWidth  ( 1<<(log2MinCUSize + maxCUDepthDelta) );
   pcSPS->setMaxCUHeight ( 1<<(log2MinCUSize + maxCUDepthDelta) );
   READ_UVLC( uiCode, "log2_min_transform_block_size_minus2" );   pcSPS->setQuadtreeTULog2MinSize( uiCode + 2 );
@@ -647,5 +605,5 @@
 
   Int addCuDepth = max (0, log2MinCUSize - (Int)pcSPS->getQuadtreeTULog2MinSize() );
-  pcSPS->setMaxCUDepth( maxCUDepthDelta + addCuDepth ); 
+  pcSPS->setMaxCUDepth( maxCUDepthDelta + addCuDepth );
 
   READ_FLAG( uiCode, "scaling_list_enabled_flag" );                 pcSPS->setScalingListFlag ( uiCode );
@@ -672,4 +630,5 @@
 
   READ_UVLC( uiCode, "num_short_term_ref_pic_sets" );
+  assert(uiCode <= 64);
   pcSPS->createRPSList(uiCode);
 
@@ -683,5 +642,5 @@
   }
   READ_FLAG( uiCode, "long_term_ref_pics_present_flag" );          pcSPS->setLongTermRefsPresent(uiCode);
-  if (pcSPS->getLongTermRefsPresent()) 
+  if (pcSPS->getLongTermRefsPresent())
   {
     READ_UVLC( uiCode, "num_long_term_ref_pic_sps" );
@@ -697,4 +656,5 @@
   READ_FLAG( uiCode, "sps_temporal_mvp_enable_flag" );            pcSPS->setTMVPFlagsPresent(uiCode);
 #if REF_IDX_MFM
+#if !M0457_COL_PICTURE_SIGNALING
   if(pcSPS->getLayerId() > 0)
   {
@@ -703,4 +663,5 @@
   }
 #endif
+#endif
   READ_FLAG( uiCode, "sps_strong_intra_smoothing_enable_flag" );  pcSPS->setUseStrongIntraSmoothing(uiCode);
 
@@ -711,31 +672,76 @@
     parseVUI(pcSPS->getVuiParameters(), pcSPS);
   }
-
-#if SCALED_REF_LAYER_OFFSETS
-  if( pcSPS->getLayerId() > 0 )
-  {
-    Int iCode;
-    Window& scaledWindow = pcSPS->getScaledRefLayerWindow();
-    READ_SVLC( iCode, "scaled_ref_layer_left_offset" );    scaledWindow.setWindowLeftOffset  (iCode << 1);
-    READ_SVLC( iCode, "scaled_ref_layer_top_offset" );     scaledWindow.setWindowTopOffset   (iCode << 1);
-    READ_SVLC( iCode, "scaled_ref_layer_right_offset" );   scaledWindow.setWindowRightOffset (iCode << 1);
-    READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" );  scaledWindow.setWindowBottomOffset(iCode << 1);
-  }
-#endif
 
   READ_FLAG( uiCode, "sps_extension_flag");
   if (uiCode)
   {
-    while ( xMoreRbspData() )
-    {
-      READ_FLAG( uiCode, "sps_extension_data_flag");
-    }
-  }
-}
+#if SPS_EXTENSION
+    parseSPSExtension( pcSPS );
+    READ_FLAG( uiCode, "sps_extension2_flag");
+    if(uiCode)
+    {
+#endif
+      while ( xMoreRbspData() )
+      {
+        READ_FLAG( uiCode, "sps_extension_data_flag");
+      }
+#if SPS_EXTENSION
+    }
+#endif
+  }
+}
+
+#if SPS_EXTENSION
+Void TDecCavlc::parseSPSExtension( TComSPS* pcSPS )
+{
+  UInt uiCode;
+  // more syntax elements to be parsed here
+#if SCALED_REF_LAYER_OFFSETS
+#if SCALED_REF_LAYER_OFFSET_FLAG
+  READ_FLAG( uiCode, "scaled_ref_layer_offset_present_flag" );
+  if( uiCode )
+#else
+  if( pcSPS->getLayerId() > 0 )
+#endif
+  {
+    Int iCode; 
+    READ_UVLC( uiCode,      "num_scaled_ref_layer_offsets" ); pcSPS->setNumScaledRefLayerOffsets(uiCode);
+    for(Int i = 0; i < pcSPS->getNumScaledRefLayerOffsets(); i++)
+    {
+      Window& scaledWindow = pcSPS->getScaledRefLayerWindow(i);
+      READ_SVLC( iCode, "scaled_ref_layer_left_offset" );    scaledWindow.setWindowLeftOffset  (iCode << 1);
+      READ_SVLC( iCode, "scaled_ref_layer_top_offset" );     scaledWindow.setWindowTopOffset   (iCode << 1);
+      READ_SVLC( iCode, "scaled_ref_layer_right_offset" );   scaledWindow.setWindowRightOffset (iCode << 1);
+      READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" );  scaledWindow.setWindowBottomOffset(iCode << 1);
+    }
+  }
+#endif
+#if M0463_VUI_EXT_ILP_REF
+  ////   sps_extension_vui_parameters( )
+  if( pcSPS->getVuiParameters()->getBitstreamRestrictionFlag() )
+  {  
+    READ_UVLC( uiCode, "num_ilp_restricted_ref_layers" ); pcSPS->setNumIlpRestrictedRefLayers( uiCode ); 
+    for( Int i = 0; i < pcSPS->getNumIlpRestrictedRefLayers( ); i++ ) 
+    {  
+      READ_UVLC( uiCode, "min_spatial_segment_offset_plus1" ); pcSPS->setMinSpatialSegmentOffsetPlus1( i, uiCode ); 
+      if( pcSPS->getMinSpatialSegmentOffsetPlus1( i ) > 0 ) 
+      {  
+        READ_FLAG( uiCode, "ctu_based_offset_enabled_flag[ i ]"); pcSPS->setCtuBasedOffsetEnabledFlag(i, uiCode == 1 ); 
+        if( pcSPS->getCtuBasedOffsetEnabledFlag( i ) )  
+        {
+          READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1[ i ]"); pcSPS->setMinHorizontalCtuOffsetPlus1( i, uiCode ); 
+        }
+      }  
+    }  
+  }  
+  ////   sps_extension_vui_parameters( ) END
+#endif
+}
+#endif
 
 Void TDecCavlc::parseVPS(TComVPS* pcVPS)
 {
   UInt  uiCode;
-  
+
   READ_CODE( 4,  uiCode,  "vps_video_parameter_set_id" );         pcVPS->setVPSId( uiCode );
   READ_CODE( 2,  uiCode,  "vps_reserved_three_2bits" );           assert(uiCode == 3);
@@ -750,18 +756,11 @@
   READ_CODE( 16, uiCode,  "vps_reserved_ffff_16bits" );           assert(uiCode == 0xffff);
   parsePTL ( pcVPS->getPTL(), true, pcVPS->getMaxTLayers()-1);
-#if SIGNAL_BITRATE_PICRATE_IN_VPS
-  parseBitratePicRateInfo( pcVPS->getBitratePicrateInfo(), 0, pcVPS->getMaxTLayers() - 1);
-#endif
   UInt subLayerOrderingInfoPresentFlag;
   READ_FLAG(subLayerOrderingInfoPresentFlag, "vps_sub_layer_ordering_info_present_flag");
   for(UInt i = 0; i <= pcVPS->getMaxTLayers()-1; i++)
   {
-#if L0323_DPB
     READ_UVLC( uiCode,  "vps_max_dec_pic_buffering_minus1[i]" );     pcVPS->setMaxDecPicBuffering( uiCode + 1, i );
-#else
-    READ_UVLC( uiCode,  "vps_max_dec_pic_buffering[i]" );     pcVPS->setMaxDecPicBuffering( uiCode, i );
-#endif
     READ_UVLC( uiCode,  "vps_num_reorder_pics[i]" );          pcVPS->setNumReorderPics( uiCode, i );
-    READ_UVLC( uiCode,  "vps_max_latency_increase[i]" );      pcVPS->setMaxLatencyIncrease( uiCode, i );
+    READ_UVLC( uiCode,  "vps_max_latency_increase_plus1[i]" );      pcVPS->setMaxLatencyIncrease( uiCode, i );
 
     if (!subLayerOrderingInfoPresentFlag)
@@ -803,5 +802,4 @@
   pcVPS->deriveLayerIdListVariables();
 #endif
-#if L0043_TIMING_INFO
   TimingInfo *timingInfo = pcVPS->getTimingInfo();
   READ_FLAG(       uiCode, "vps_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
@@ -815,5 +813,4 @@
       READ_UVLC(   uiCode, "vps_num_ticks_poc_diff_one_minus1");    timingInfo->setNumTicksPocDiffOneMinus1   (uiCode);
     }
-#endif
     READ_UVLC( uiCode, "vps_num_hrd_parameters" );                  pcVPS->setNumHrdParameters( uiCode );
 
@@ -831,7 +828,5 @@
       parseHrdParameters(pcVPS->getHrdParameters(i), pcVPS->getCprmsPresentFlag( i ), pcVPS->getMaxTLayers() - 1);
     }
-#if L0043_TIMING_INFO
-  }
-#endif
+  }
   READ_FLAG( uiCode,  "vps_extension_flag" );
   if (uiCode)
@@ -854,5 +849,5 @@
 #endif
   }
-  
+
   return;
 }
@@ -860,5 +855,5 @@
 #if VPS_EXTNS
 Void TDecCavlc::parseVPSExtension(TComVPS *vps)
-{  
+{
   UInt uiCode;
   // ... More syntax elements to be parsed here
@@ -873,16 +868,28 @@
     READ_FLAG( uiCode, "scalability_mask[i]" ); vps->setScalabilityMask(i, uiCode ? true : false);
     numScalabilityTypes += uiCode;
-    if( i != 1 )
-    {
-      // Multiview and reserved masks are not used in this version of software
-      assert( uiCode == 0 );
-    }
   }
   vps->setNumScalabilityTypes(numScalabilityTypes);
 
+#if VPS_SPLIT_FLAG
+  for(j = 0; j < numScalabilityTypes - vps->getSplittingFlag(); j++)
+#else
   for(j = 0; j < numScalabilityTypes; j++)
+#endif
   {
     READ_CODE( 3, uiCode, "dimension_id_len_minus1[j]" ); vps->setDimensionIdLen(j, uiCode + 1);
   }
+#if VPS_SPLIT_FLAG
+  if(vps->getSplittingFlag())
+  {
+    UInt numBits = 0;
+    for(j = 0; j < numScalabilityTypes - 1; j++)
+    {
+      numBits += vps->getDimensionIdLen(j);
+    }
+    assert( numBits < 6 );
+    vps->setDimensionIdLen(numScalabilityTypes-1, 6 - numBits);
+    numBits = 6;
+  }
+#else
   if(vps->getSplittingFlag())
   {
@@ -894,4 +901,5 @@
     assert( numBits <= 6 );
   }
+#endif
 
   READ_FLAG( uiCode, "vps_nuh_layer_id_present_flag" ); vps->setNuhLayerIdPresentFlag(uiCode ? true : false);
@@ -911,4 +919,7 @@
     vps->setLayerIdInVps(vps->getLayerIdInNuh(i), i);
 
+#if VPS_SPLIT_FLAG
+    if(!vps->getSplittingFlag())
+#endif
     for(j = 0; j < numScalabilityTypes; j++)
     {
@@ -939,5 +950,11 @@
 #endif
 #endif
-
+#if JCTVC_M0203_INTERLAYER_PRED_IDC
+  for(i = 0; i < vps->getMaxLayers() - 1; i++)
+  {
+    READ_CODE( 3, uiCode, "max_sublayer_for_ilp_plus1[i]" ); vps->setMaxSublayerForIlpPlus1(i, uiCode);
+    assert( uiCode <= vps->getMaxTLayers() );
+  }
+#endif
 #if VPS_EXTN_PROFILE_INFO
   // Profile-tier-level signalling
@@ -961,7 +978,7 @@
 #endif
       assert( vps->getProfileLayerSetRef(idx) < idx );
-      // Copy profile information as indicated 
+      // Copy profile information as indicated
       vps->getPTLForExtn(idx)->copyProfileInfo( vps->getPTLForExtn( vps->getProfileLayerSetRef(idx) ) );
-    }    
+    }
     parsePTL( vps->getPTLForExtn(idx), vps->getProfilePresentFlag(idx), vps->getMaxTLayers() - 1 );
   }
@@ -1048,11 +1065,11 @@
       }
     }
-  } 
+  }
 #endif
 #endif
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
    READ_FLAG(uiCode, "max_one_active_ref_layer_flag" );
-   vps->setMaxOneActiveRefLayerFlag(uiCode);   
-#endif 
+   vps->setMaxOneActiveRefLayerFlag(uiCode);
+#endif
 
 #if !VPS_MOVE_DIR_DEPENDENCY_FLAG
@@ -1077,4 +1094,20 @@
 #endif
 #endif
+#if VPS_EXTN_DIRECT_REF_LAYERS && M0457_PREDICTION_INDICATIONS
+  READ_UVLC( uiCode,           "direct_dep_type_len_minus2"); vps->setDirectDepTypeLen(uiCode+2);
+  for(i = 1; i < vps->getMaxLayers(); i++)
+  {
+    for(j = 0; j < i; j++)
+    {
+      if (vps->getDirectDependencyFlag(i, j))
+      {
+        READ_CODE( vps->getDirectDepTypeLen(), uiCode, "direct_dependency_type[i][j]" ); vps->setDirectDependencyType(i, j, uiCode);
+      }
+    }
+  }
+#endif
+#if M0040_ADAPTIVE_RESOLUTION_CHANGE
+  READ_FLAG(uiCode, "single_layer_for_non_irap_flag" ); vps->setSingleLayerForNonIrapFlag(uiCode == 1 ? true : false);
+#endif
 }
 #endif
@@ -1094,5 +1127,5 @@
   READ_FLAG( firstSliceSegmentInPic, "first_slice_segment_in_pic_flag" );
   if( rpcSlice->getRapPicFlag())
-  { 
+  {
     READ_FLAG( uiCode, "no_output_of_prior_pics_flag" );  //ignored
   }
@@ -1145,11 +1178,23 @@
     rpcSlice->setSliceCurEndCUAddr(numCTUs*maxParts);
   }
-  
+
   if(!rpcSlice->getDependentSliceSegmentFlag())
   {
+
+#if SH_DISCARDABLE_FLAG
+    if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits()>0)
+    {
+      READ_FLAG(uiCode, "discardable_flag"); // ignored
+    }
+    for (Int i = 1; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
+    {
+      READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
+    }
+#else
     for (Int i = 0; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
     {
       READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
     }
+#endif
 
     READ_UVLC (    uiCode, "slice_type" );            rpcSlice->setSliceType((SliceType)uiCode);
@@ -1179,5 +1224,5 @@
     else
     {
-      READ_CODE(sps->getBitsForPOC(), uiCode, "pic_order_cnt_lsb");  
+      READ_CODE(sps->getBitsForPOC(), uiCode, "pic_order_cnt_lsb");
       Int iPOClsb = uiCode;
       Int iPrevPOC = rpcSlice->getPrevPOC();
@@ -1190,5 +1235,5 @@
         iPOCmsb = iPrevPOCmsb + iMaxPOClsb;
       }
-      else if( (iPOClsb  >  iPrevPOClsb )  && ( (iPOClsb - iPrevPOClsb )  >  ( iMaxPOClsb / 2 ) ) ) 
+      else if( (iPOClsb  >  iPrevPOClsb )  && ( (iPOClsb - iPrevPOClsb )  >  ( iMaxPOClsb / 2 ) ) )
       {
         iPOCmsb = iPrevPOCmsb - iMaxPOClsb;
@@ -1230,5 +1275,5 @@
           uiCode = 0;
         }
-        memcpy(rps,sps->getRPSList()->getReferencePictureSet(uiCode),sizeof(TComReferencePictureSet));
+        *rps = *(sps->getRPSList()->getReferencePictureSet(uiCode));
       }
       if(sps->getLongTermRefsPresent())
@@ -1276,5 +1321,5 @@
           READ_FLAG(uiCode,"delta_poc_msb_present_flag");
           Bool mSBPresentFlag = uiCode ? true : false;
-          if(mSBPresentFlag)                  
+          if(mSBPresentFlag)
           {
             READ_UVLC( uiCode, "delta_poc_msb_cycle_lt[i]" );
@@ -1291,12 +1336,12 @@
             else
             {
-              deltaPocMSBCycleLT = uiCode + prevDeltaMSB;              
+              deltaPocMSBCycleLT = uiCode + prevDeltaMSB;
             }
 
-            Int pocLTCurr = rpcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB 
+            Int pocLTCurr = rpcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB
                                         - iPOClsb + pocLsbLt;
-            rps->setPOC     (j, pocLTCurr); 
+            rps->setPOC     (j, pocLTCurr);
             rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLTCurr);
-            rps->setCheckLTMSBPresent(j,true);  
+            rps->setCheckLTMSBPresent(j,true);
           }
           else
@@ -1304,11 +1349,11 @@
             rps->setPOC     (j, pocLsbLt);
             rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLsbLt);
-            rps->setCheckLTMSBPresent(j,false);  
+            rps->setCheckLTMSBPresent(j,false);
           }
           prevDeltaMSB = deltaPocMSBCycleLT;
         }
         offset += rps->getNumberOfLongtermPictures();
-        rps->setNumberOfPictures(offset);        
-      }  
+        rps->setNumberOfPictures(offset);
+      }
       if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
         || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
@@ -1323,10 +1368,8 @@
         rpcSlice->setRPS(rps);
       }
-
-
       if (rpcSlice->getSPS()->getTMVPFlagsPresent())
       {
         READ_FLAG( uiCode, "slice_temporal_mvp_enable_flag" );
-        rpcSlice->setEnableTMVPFlag( uiCode == 1 ? true : false ); 
+        rpcSlice->setEnableTMVPFlag( uiCode == 1 ? true : false );
       }
       else
@@ -1337,13 +1380,13 @@
 
 #if REF_IDX_FRAMEWORK
-#if JCTVC_M0458_INTERLAYER_RPS_SIG    
+#if JCTVC_M0458_INTERLAYER_RPS_SIG
     rpcSlice->setActiveNumILRRefIdx(0);
-    if((sps->getLayerId() > 0)  &&  (rpcSlice->getNumILRRefIdx() > 0) ) 
-    {      
+    if((sps->getLayerId() > 0)  &&  (rpcSlice->getNumILRRefIdx() > 0) )
+    {
       READ_FLAG(uiCode,"inter_layer_pred_enabled_flag");
       rpcSlice->setInterLayerPredEnabledFlag(uiCode);
       if( rpcSlice->getInterLayerPredEnabledFlag())
       {
-        if(rpcSlice->getNumILRRefIdx() > 1) 
+        if(rpcSlice->getNumILRRefIdx() > 1)
         {
           Int numBits = 1;
@@ -1352,26 +1395,34 @@
             numBits++;
           }
-          if( !rpcSlice->getVPS()->getMaxOneActiveRefLayerFlag()) 
+          if( !rpcSlice->getVPS()->getMaxOneActiveRefLayerFlag())
           {
             READ_CODE( numBits, uiCode,"num_inter_layer_ref_pics_minus1" );
-            rpcSlice->setActiveNumILRRefIdx(uiCode + 1);          
+            rpcSlice->setActiveNumILRRefIdx(uiCode + 1);
           }
           else
           {
-            rpcSlice->setActiveNumILRRefIdx(1);          
+            rpcSlice->setActiveNumILRRefIdx(1);
           }
-          for(Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ ) 
+          for(Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
           {
-            READ_CODE( numBits,uiCode,"inter_layer_pred_layer_idc[i]" );  
-            rpcSlice->setInterLayerPredLayerIdc(uiCode,i);          
+            READ_CODE( numBits,uiCode,"inter_layer_pred_layer_idc[i]" );
+            rpcSlice->setInterLayerPredLayerIdc(uiCode,i);
           }
         }
         else
         {
-          rpcSlice->setActiveNumILRRefIdx(1);          
-          rpcSlice->setInterLayerPredLayerIdc(0,0);      
-        }
-      }
-    }
+          rpcSlice->setActiveNumILRRefIdx(1);
+          rpcSlice->setInterLayerPredLayerIdc(0,0);
+        }
+      }
+    }
+#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
+    rpcSlice->setInterLayerSamplePredOnlyFlag( false );
+    if( rpcSlice->getNumSamplePredRefLayers() > 0 && rpcSlice->getActiveNumILRRefIdx() > 0 )
+    {
+      READ_FLAG( uiCode, "inter_layer_sample_pred_only_flag" );
+      rpcSlice->setInterLayerSamplePredOnlyFlag( uiCode > 0 );
+    }
+#endif
 #else
     if( rpcSlice->getLayerId() > 0 )
@@ -1443,5 +1494,5 @@
           Int length = 1;
           numRpsCurrTempList0 --;
-          while ( numRpsCurrTempList0 >>= 1) 
+          while ( numRpsCurrTempList0 >>= 1)
           {
             length ++;
@@ -1485,5 +1536,5 @@
           Int length = 1;
           numRpsCurrTempList1 --;
-          while ( numRpsCurrTempList1 >>= 1) 
+          while ( numRpsCurrTempList1 >>= 1)
           {
             length ++;
@@ -1503,5 +1554,5 @@
         }
       }
-    }  
+    }
     else
     {
@@ -1522,4 +1573,22 @@
     if ( rpcSlice->getEnableTMVPFlag() )
     {
+#if REF_IDX_FRAMEWORK && M0457_COL_PICTURE_SIGNALING
+      rpcSlice->setMFMEnabledFlag( false );
+      rpcSlice->setColRefLayerIdx( 0 );
+      rpcSlice->setAltColIndicationFlag( false );
+      if ( sps->getLayerId() > 0 && rpcSlice->getActiveNumILRRefIdx() > 0 && rpcSlice->getNumMotionPredRefLayers() > 0 )
+      {
+        READ_FLAG( uiCode, "alt_collocated_indication_flag" );
+        rpcSlice->setAltColIndicationFlag( uiCode == 1 ? true : false );
+        rpcSlice->setMFMEnabledFlag( uiCode == 1 ? true : false );
+        if ( rpcSlice->getNumMotionPredRefLayers() > 1 )
+        {
+          READ_UVLC( uiCode, "collocated_ref_layer_idx" );
+          rpcSlice->setColRefLayerIdx( uiCode );
+        }
+      }
+      else
+      {
+#endif
       if ( rpcSlice->getSliceType() == B_SLICE )
       {
@@ -1543,4 +1612,7 @@
         rpcSlice->setColRefIdx(0);
       }
+#if REF_IDX_FRAMEWORK && M0457_COL_PICTURE_SIGNALING
+      }
+#endif
     }
     if ( (pps->getUseWP() && rpcSlice->getSliceType()==P_SLICE) || (pps->getWPBiPred() && rpcSlice->getSliceType()==B_SLICE) )
@@ -1585,5 +1657,5 @@
       }
       else
-      {  
+      {
         rpcSlice->setDeblockingFilterOverrideFlag(0);
       }
@@ -1609,5 +1681,5 @@
     }
     else
-    {  
+    {
       rpcSlice->setDeblockingFilterDisable       ( false );
       rpcSlice->setDeblockingFilterBetaOffsetDiv2( 0 );
@@ -1629,5 +1701,5 @@
 
   }
-  
+
     UInt *entryPointOffset          = NULL;
     UInt numEntryPointOffsets, offsetLenMinus1;
@@ -1642,11 +1714,6 @@
     for (UInt idx=0; idx<numEntryPointOffsets; idx++)
     {
-#if L0116_ENTRY_POINT
       READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset_minus1");
       entryPointOffset[ idx ] = uiCode + 1;
-#else
-      READ_CODE(offsetLenMinus1+1, uiCode, "entry_point_offset");
-      entryPointOffset[ idx ] = uiCode;
-#endif
     }
   }
@@ -1670,4 +1737,14 @@
   {
     Int endOfSliceHeaderLocation = m_pcBitstream->getByteLocation();
+    
+    // Adjust endOfSliceHeaderLocation to account for emulation prevention bytes in the slice segment header
+    for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
+    {
+      if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) < endOfSliceHeaderLocation )
+      {
+        endOfSliceHeaderLocation++;
+      }
+    }
+
     Int  curEntryPointOffset     = 0;
     Int  prevEntryPointOffset    = 0;
@@ -1679,5 +1756,5 @@
       for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
       {
-        if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) >= ( prevEntryPointOffset + endOfSliceHeaderLocation ) && 
+        if ( m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) >= ( prevEntryPointOffset + endOfSliceHeaderLocation ) &&
              m_pcBitstream->getEmulationPreventionByteLocation( curByteIdx ) <  ( curEntryPointOffset  + endOfSliceHeaderLocation ) )
         {
@@ -1727,5 +1804,5 @@
   return;
 }
-  
+
 Void TDecCavlc::parsePTL( TComPTL *rpcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1 )
 {
@@ -1737,5 +1814,4 @@
   READ_CODE( 8, uiCode, "general_level_idc" );    rpcPTL->getGeneralPTL()->setLevelIdc(uiCode);
 
-#if L0363_BYTE_ALIGN
   for (Int i = 0; i < maxNumSubLayersMinus1; i++)
   {
@@ -1746,5 +1822,5 @@
     READ_FLAG( uiCode, "sub_layer_level_present_flag[i]"   ); rpcPTL->setSubLayerLevelPresentFlag  (i, uiCode);
   }
-  
+
   if (maxNumSubLayersMinus1 > 0)
   {
@@ -1755,15 +1831,7 @@
     }
   }
-#endif
-  
+
   for(Int i = 0; i < maxNumSubLayersMinus1; i++)
   {
-#if !L0363_BYTE_ALIGN
-    if(profilePresentFlag)
-    {
-      READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode);
-    }
-    READ_FLAG( uiCode, "sub_layer_level_present_flag[i]"   ); rpcPTL->setSubLayerLevelPresentFlag  (i, uiCode);
-#endif
     if( profilePresentFlag && rpcPTL->getSubLayerProfilePresentFlag(i) )
     {
@@ -1787,5 +1855,4 @@
     READ_FLAG(  uiCode, "XXX_profile_compatibility_flag[][j]");   ptl->setProfileCompatibilityFlag(j, uiCode ? 1 : 0);
   }
-#if L0046_CONSTRAINT_FLAGS
   READ_FLAG(uiCode, "general_progressive_source_flag");
   ptl->setProgressiveSourceFlag(uiCode ? true : false);
@@ -1793,43 +1860,16 @@
   READ_FLAG(uiCode, "general_interlaced_source_flag");
   ptl->setInterlacedSourceFlag(uiCode ? true : false);
-  
+
   READ_FLAG(uiCode, "general_non_packed_constraint_flag");
   ptl->setNonPackedConstraintFlag(uiCode ? true : false);
-  
+
   READ_FLAG(uiCode, "general_frame_only_constraint_flag");
   ptl->setFrameOnlyConstraintFlag(uiCode ? true : false);
-  
+
   READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[0..15]");
   READ_CODE(16, uiCode, "XXX_reserved_zero_44bits[16..31]");
   READ_CODE(12, uiCode, "XXX_reserved_zero_44bits[32..43]");
-#elif L0363_MORE_BITS
-  READ_CODE(16, uiCode, "XXX_reserved_zero_48bits[0..15]");
-  READ_CODE(16, uiCode, "XXX_reserved_zero_48bits[16..31]");
-  READ_CODE(16, uiCode, "XXX_reserved_zero_48bits[32..47]");
-#else
-  READ_CODE(16, uiCode, "XXX_reserved_zero_16bits[]");  assert( uiCode == 0 );
-#endif
-}
-#if SIGNAL_BITRATE_PICRATE_IN_VPS
-Void TDecCavlc::parseBitratePicRateInfo(TComBitRatePicRateInfo *info, Int tempLevelLow, Int tempLevelHigh)
-{
-  UInt uiCode;
-  for(Int i = tempLevelLow; i <= tempLevelHigh; i++)
-  {
-    READ_FLAG( uiCode, "bit_rate_info_present_flag[i]" ); info->setBitRateInfoPresentFlag(i, uiCode ? true : false);
-    READ_FLAG( uiCode, "pic_rate_info_present_flag[i]" ); info->setPicRateInfoPresentFlag(i, uiCode ? true : false);
-    if(info->getBitRateInfoPresentFlag(i))
-    {
-      READ_CODE( 16, uiCode, "avg_bit_rate[i]" ); info->setAvgBitRate(i, uiCode);
-      READ_CODE( 16, uiCode, "max_bit_rate[i]" ); info->setMaxBitRate(i, uiCode);
-    }
-    if(info->getPicRateInfoPresentFlag(i))
-    {
-      READ_CODE(  2, uiCode,  "constant_pic_rate_idc[i]" ); info->setConstantPicRateIdc(i, uiCode);
-      READ_CODE( 16, uiCode,  "avg_pic_rate[i]"          ); info->setAvgPicRate(i, uiCode);
-    }
-  }
-}
-#endif  
+}
+
 Void TDecCavlc::parseTerminatingBit( UInt& ruiBit )
 {
@@ -1876,5 +1916,5 @@
 }
 
-/** Parse I_PCM information. 
+/** Parse I_PCM information.
 * \param pcCU pointer to CU
 * \param uiAbsPartIdx CU index
@@ -1882,5 +1922,5 @@
 * \returns Void
 *
-* If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes.  
+* If I_PCM flag indicates that the CU is I_PCM, parse its PCM alignment bits and codes.
 */
 Void TDecCavlc::parseIPCMInfo( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
@@ -1890,5 +1930,5 @@
 
 Void TDecCavlc::parseIntraDirLumaAng  ( TComDataCU* /*pcCU*/, UInt /*uiAbsPartIdx*/, UInt /*uiDepth*/ )
-{ 
+{
   assert(0);
 }
@@ -1981,10 +2021,10 @@
   UInt            uiLog2WeightDenomLuma, uiLog2WeightDenomChroma;
   UInt            uiTotalSignalledWeightFlags = 0;
-  
+
   Int iDeltaDenom;
   // decode delta_luma_log2_weight_denom :
   READ_UVLC( uiLog2WeightDenomLuma, "luma_log2_weight_denom" );     // ue(v): luma_log2_weight_denom
   assert( uiLog2WeightDenomLuma <= 7 );
-  if( bChroma ) 
+  if( bChroma )
   {
     READ_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );     // se(v): delta_chroma_log2_weight_denom
@@ -1994,8 +2034,8 @@
   }
 
-  for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ ) 
+  for ( Int iNumRef=0 ; iNumRef<iNbRef ; iNumRef++ )
   {
     RefPicList  eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
-    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
+    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
     {
       pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
@@ -2010,8 +2050,8 @@
       uiTotalSignalledWeightFlags += wp[0].bPresentFlag;
     }
-    if ( bChroma ) 
+    if ( bChroma )
     {
       UInt  uiCode;
-      for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
+      for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
       {
         pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
@@ -2022,8 +2062,8 @@
       }
     }
-    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ ) 
+    for ( Int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
     {
       pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
-      if ( wp[0].bPresentFlag ) 
+      if ( wp[0].bPresentFlag )
       {
         Int iDeltaWeight;
@@ -2036,14 +2076,14 @@
         assert( wp[0].iOffset <=  127 );
       }
-      else 
+      else
       {
         wp[0].iWeight = (1 << wp[0].uiLog2WeightDenom);
         wp[0].iOffset = 0;
       }
-      if ( bChroma ) 
-      {
-        if ( wp[1].bPresentFlag ) 
-        {
-          for ( Int j=1 ; j<3 ; j++ ) 
+      if ( bChroma )
+      {
+        if ( wp[1].bPresentFlag )
+        {
+          for ( Int j=1 ; j<3 ; j++ )
           {
             Int iDeltaWeight;
@@ -2061,7 +2101,7 @@
           }
         }
-        else 
-        {
-          for ( Int j=1 ; j<3 ; j++ ) 
+        else
+        {
+          for ( Int j=1 ; j<3 ; j++ )
           {
             wp[j].iWeight = (1 << wp[j].uiLog2WeightDenom);
@@ -2072,5 +2112,5 @@
     }
 
-    for ( Int iRefIdx=pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) 
+    for ( Int iRefIdx=pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx<MAX_NUM_REF ; iRefIdx++ )
     {
       pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
@@ -2148,5 +2188,5 @@
 
 Bool TDecCavlc::xMoreRbspData()
-{ 
+{
   Int bitsLeft = m_pcBitstream->getNumBitsLeft();
 
Index: trunk/source/Lib/TLibDecoder/TDecCAVLC.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 229)
+++ trunk/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 310)
@@ -75,5 +75,12 @@
   Void  parseVPSExtension   ( TComVPS* pcVPS );
 #endif
+#if SPS_SUB_LAYER_INFO
+  Void  parseSPS            ( TComSPS* pcSPS, ParameterSetManagerDecoder *parameterSetManager );
+#else
   Void  parseSPS            ( TComSPS* pcSPS );
+#endif
+#if SPS_EXTENSION
+  Void parseSPSExtension    ( TComSPS* pcSPS );
+#endif
   Void  parsePPS            ( TComPPS* pcPPS);
   Void  parseVUI            ( TComVUI* pcVUI, TComSPS* pcSPS );
@@ -81,7 +88,4 @@
   Void  parsePTL            ( TComPTL *rpcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1 );
   Void  parseProfileTier    (ProfileTierLevel *ptl);
-#if SIGNAL_BITRATE_PICRATE_IN_VPS
-  Void  parseBitratePicRateInfo(TComBitRatePicRateInfo *info, Int tempLevelLow, Int tempLevelHigh);
-#endif
   Void  parseHrdParameters  (TComHRD *hrd, Bool cprms_present_flag, UInt tempLevelHigh);
   Void  parseSliceHeader    ( TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager);
Index: trunk/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCu.cpp	(revision 229)
+++ trunk/source/Lib/TLibDecoder/TDecCu.cpp	(revision 310)
@@ -935,7 +935,7 @@
 TDecCu::xReconIntraBL( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth )
 {
-  m_ppcYuvReco[uiDepth]->copyFromPicLuma  ( pcCU->getSlice()->getFullPelBaseRec(),  pcCU->getAddr(), pcCU->getZorderIdxInCU(), 0, pcCU->getWidth(0), pcCU->getHeight(0));
-  m_ppcYuvReco[uiDepth]->copyFromPicChroma( pcCU->getSlice()->getFullPelBaseRec(),  pcCU->getAddr(), pcCU->getZorderIdxInCU(), 0, (pcCU->getWidth(0)>>1), (pcCU->getHeight(0)>>1), 0);
-  m_ppcYuvReco[uiDepth]->copyFromPicChroma( pcCU->getSlice()->getFullPelBaseRec(),  pcCU->getAddr(), pcCU->getZorderIdxInCU(), 0, (pcCU->getWidth(0)>>1), (pcCU->getHeight(0)>>1), 1);
+  m_ppcYuvReco[uiDepth]->copyFromPicLuma  ( pcCU->getSlice()->getFullPelBaseRec(m_layerId - 1),  pcCU->getAddr(), pcCU->getZorderIdxInCU(), 0, pcCU->getWidth(0), pcCU->getHeight(0));
+  m_ppcYuvReco[uiDepth]->copyFromPicChroma( pcCU->getSlice()->getFullPelBaseRec(m_layerId - 1),  pcCU->getAddr(), pcCU->getZorderIdxInCU(), 0, (pcCU->getWidth(0)>>1), (pcCU->getHeight(0)>>1), 0);
+  m_ppcYuvReco[uiDepth]->copyFromPicChroma( pcCU->getSlice()->getFullPelBaseRec(m_layerId - 1),  pcCU->getAddr(), pcCU->getZorderIdxInCU(), 0, (pcCU->getWidth(0)>>1), (pcCU->getHeight(0)>>1), 1);
 
   // inter recon
Index: trunk/source/Lib/TLibDecoder/TDecEntropy.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 229)
+++ trunk/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 310)
@@ -188,14 +188,4 @@
       decodeMergeIndex( pcCU, uiPartIdx, uiSubPartIdx, uiDepth );
       UInt uiMergeIndex = pcCU->getMergeIndex(uiSubPartIdx);
-#if 0 //REF_IDX_FRAMEWORK  // HM bug fix
-      if(uiPartIdx)
-      {
-        for(UInt ui=0; ui<uiMergeIndex+1; ui++)
-        {
-          cMvFieldNeighbours[(ui<<1)].setMvField(TComMv(), NOT_VALID);
-          cMvFieldNeighbours[(ui<<1)+1].setMvField(TComMv(), NOT_VALID);
-        }
-      }
-#endif
       if ( pcCU->getSlice()->getPPS()->getLog2ParallelMergeLevelMinus2() && ePartSize != SIZE_2Nx2N && pcSubCU->getWidth( 0 ) <= 8 ) 
       {
Index: trunk/source/Lib/TLibDecoder/TDecEntropy.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecEntropy.h	(revision 229)
+++ trunk/source/Lib/TLibDecoder/TDecEntropy.h	(revision 310)
@@ -66,5 +66,9 @@
 
   virtual Void  parseVPS                  ( TComVPS* pcVPS )                       = 0;
+#if SPS_SUB_LAYER_INFO
+  virtual Void  parseSPS                  ( TComSPS* pcSPS, ParameterSetManagerDecoder *parameterSetManager )           = 0;
+#else
   virtual Void  parseSPS                  ( TComSPS* pcSPS )                                      = 0;
+#endif
   virtual Void  parsePPS                  ( TComPPS* pcPPS )                                      = 0;
 
@@ -134,5 +138,9 @@
   Void    resetEntropy                ( TComSlice* p)           { m_pcEntropyDecoderIf->resetEntropy(p);                    }
   Void    decodeVPS                   ( TComVPS* pcVPS ) { m_pcEntropyDecoderIf->parseVPS(pcVPS); }
+#if SPS_SUB_LAYER_INFO
+  Void    decodeSPS                   ( TComSPS* pcSPS, ParameterSetManagerDecoder *parameterSetManager )    { m_pcEntropyDecoderIf->parseSPS(pcSPS, parameterSetManager);                    }
+#else
   Void    decodeSPS                   ( TComSPS* pcSPS     )    { m_pcEntropyDecoderIf->parseSPS(pcSPS);                    }
+#endif
   Void    decodePPS                   ( TComPPS* pcPPS )    { m_pcEntropyDecoderIf->parsePPS(pcPPS);                    }
   Void    decodeSliceHeader           ( TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)  { m_pcEntropyDecoderIf->parseSliceHeader(rpcSlice, parameterSetManager);         }
Index: trunk/source/Lib/TLibDecoder/TDecGop.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecGop.cpp	(revision 229)
+++ trunk/source/Lib/TLibDecoder/TDecGop.cpp	(revision 310)
@@ -247,5 +247,5 @@
     for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++)
     {
-#if REF_IDX_FRAMEWORK && VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE
+#if REF_IDX_FRAMEWORK && VPS_EXTN_DIRECT_REF_LAYERS
       if( pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->isILR( m_layerId ) )
       {
Index: trunk/source/Lib/TLibDecoder/TDecSbac.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 229)
+++ trunk/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 310)
@@ -158,4 +158,5 @@
   UInt uiBit;
   m_pcTDecBinIf->decodeBinTrm(uiBit);
+  assert(uiBit); // end_of_sub_stream_one_bit must be equal to 1
   m_pcTDecBinIf->finish();  
   m_pcBitstream->readOutTrailingBits();
@@ -196,4 +197,8 @@
 {
   m_pcTDecBinIf->decodeBinTrm( ruiBit );
+  if ( ruiBit )
+  {
+    m_pcTDecBinIf->finish();
+  }
 }
 
@@ -318,5 +323,4 @@
 {
   UInt uiSymbol;
-  Bool readPCMSampleFlag = false;
 
     m_pcTDecBinIf->decodeBinTrm(uiSymbol);
@@ -324,10 +328,4 @@
     if (uiSymbol)
     {
-      readPCMSampleFlag = true;
-      m_pcTDecBinIf->decodePCMAlignBits();
-    }
-
-  if (readPCMSampleFlag == true)
-  {
     Bool bIpcmFlag = true;
 
@@ -395,5 +393,5 @@
     }
 
-      m_pcTDecBinIf->resetBac();
+    m_pcTDecBinIf->start();
   }
 }
@@ -681,5 +679,4 @@
     else
     {
-      intraPredMode = 0;
       m_pcTDecBinIf->decodeBinsEP( symbol, 5 );
       intraPredMode = symbol;
@@ -917,5 +914,4 @@
   else 
   {
-    iDQp=0;
     qp = pcCU->getRefQP(uiAbsPartIdx);
   }
@@ -1102,5 +1098,5 @@
 
   //===== decode significance flags =====
-  UInt uiScanPosLast = uiBlkPosLast;
+  UInt uiScanPosLast;
   const UInt *scan   = g_auiSigLastScan[ uiScanIdx ][ uiLog2BlockSize-1 ];
   for( uiScanPosLast = 0; uiScanPosLast < uiMaxNumCoeffM1; uiScanPosLast++ )
Index: trunk/source/Lib/TLibDecoder/TDecSbac.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecSbac.h	(revision 229)
+++ trunk/source/Lib/TLibDecoder/TDecSbac.h	(revision 310)
@@ -76,5 +76,9 @@
   Void  setBitstream              ( TComInputBitstream* p  ) { m_pcBitstream = p; m_pcTDecBinIf->init( p ); }
   Void  parseVPS                  ( TComVPS* /*pcVPS*/ ) {}
+#if SPS_SUB_LAYER_INFO
+  Void  parseSPS                  ( TComSPS* /*pcSPS*/, ParameterSetManagerDecoder * /*parameterSetManager*/ ) {}
+#else
   Void  parseSPS                  ( TComSPS* /*pcSPS*/ ) {}
+#endif
   Void  parsePPS                  ( TComPPS* /*pcPPS*/ ) {}
 
Index: trunk/source/Lib/TLibDecoder/TDecSlice.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecSlice.cpp	(revision 229)
+++ trunk/source/Lib/TLibDecoder/TDecSlice.cpp	(revision 310)
@@ -198,5 +198,5 @@
   Int iNumSubstreamsPerTile = 1; // if independent.
 #if INTRA_BL
-  m_pcCuDecoder->setBaseRecPic( rpcPic->getLayerId() > 0 ? rpcPic->getFullPelBaseRec() : NULL);
+  m_pcCuDecoder->setBaseRecPic( rpcPic->getLayerId() > 0 ? rpcPic->getFullPelBaseRec(rpcPic->getLayerId()-1) : NULL);
 #endif
   Bool depSliceSegmentsEnabled = rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getPPS()->getDependentSliceSegmentsEnabledFlag();
@@ -384,4 +384,14 @@
     pcSbacDecoders[uiSubStrm].load(pcSbacDecoder);
 
+    if ( uiCol == rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(iCUAddr))->getRightEdgePosInCU()
+        && pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag()
+        && !uiIsLast )
+    {
+      // Parse end_of_substream_one_bit for WPP case
+      UInt binVal;
+      pcSbacDecoder->parseTerminatingBit( binVal );
+      assert( binVal );
+    }
+
     //Store probabilities of second LCU in line into buffer
     if ( (uiCol == uiTileLCUX+1)&& (depSliceSegmentsEnabled || (pcSlice->getPPS()->getNumSubstreams() > 1)) && (pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag()) )
Index: trunk/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 229)
+++ trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 310)
@@ -160,5 +160,5 @@
     if (m_cIlpPic[0] == NULL)
     {
-      for (Int j=0; j< 1/*MAX_NUM_REF*/; j++)  // to be set to NumDirectRefLayers[LayerIdInVps[nuh_layer_id]]
+      for (Int j=0; j < MAX_LAYERS /*MAX_NUM_REF*/; j++)  // consider to set to NumDirectRefLayers[LayerIdInVps[nuh_layer_id]]
       {
 
@@ -180,11 +180,16 @@
 Void TDecTop::setILRPic(TComPic *pcPic)
 {
-  if(m_cIlpPic[0])
-  {
-    m_cIlpPic[0]->copyUpsampledPictureYuv(pcPic->getFullPelBaseRec(), m_cIlpPic[0]->getPicYuvRec());
-    m_cIlpPic[0]->getSlice(0)->setPOC(pcPic->getPOC());
-    m_cIlpPic[0]->setLayerId(pcPic->getSlice(0)->getBaseColPic()->getLayerId()); //set reference layerId
-    m_cIlpPic[0]->getPicYuvRec()->setBorderExtension(false);
-    m_cIlpPic[0]->getPicYuvRec()->extendPicBorder();
+  for( Int i = 0; i < pcPic->getSlice(0)->getActiveNumILRRefIdx(); i++ )
+  {
+    Int refLayerIdc = pcPic->getSlice(0)->getInterLayerPredLayerIdc(i);
+
+    if(m_cIlpPic[refLayerIdc])
+    {
+      m_cIlpPic[refLayerIdc]->copyUpsampledPictureYuv(pcPic->getFullPelBaseRec(refLayerIdc), m_cIlpPic[refLayerIdc]->getPicYuvRec());
+      m_cIlpPic[refLayerIdc]->getSlice(0)->setPOC(pcPic->getPOC());
+      m_cIlpPic[refLayerIdc]->setLayerId(pcPic->getSlice(0)->getBaseColPic(refLayerIdc)->getLayerId()); //set reference layerId
+      m_cIlpPic[refLayerIdc]->getPicYuvRec()->setBorderExtension(false);
+      m_cIlpPic[refLayerIdc]->getPicYuvRec()->extendPicBorder();
+    }
   }
 }
@@ -236,9 +241,5 @@
   }
 
-#if L0323_DPB
-  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer())+pcSlice->getSPS()->getNumReorderPics(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
-#else
-  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer())+pcSlice->getSPS()->getNumReorderPics(pcSlice->getTLayer()) + 1; // +1 to have space for the picture currently being decoded
-#endif
+  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
   if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
   {
@@ -248,14 +249,29 @@
     if(m_layerId > 0)
     {
-#if VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE
-      TDecTop *pcTDecTopBase = (TDecTop *)getRefLayerDec( m_layerId );
-#else
-      TDecTop *pcTDecTopBase = (TDecTop *)getLayerDec( m_layerId-1 );
-#endif
-      //TComPic*                      pcPic = *(pcTDecTopBase->getListPic()->begin()); 
-      TComPicYuv* pcPicYuvRecBase = (*(pcTDecTopBase->getListPic()->begin()))->getPicYuvRec(); 
-      if(pcPicYuvRecBase->getWidth() != pcSlice->getSPS()->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getSPS()->getPicHeightInLumaSamples() )
-      {
-        rpcPic->setSpatialEnhLayerFlag( true );
+      for(UInt i = 0; i < pcSlice->getVPS()->getNumDirectRefLayers( m_layerId ); i++ )
+      {
+        const Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(i);
+        Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
+
+#if VPS_EXTN_DIRECT_REF_LAYERS
+        TDecTop *pcTDecTopBase = (TDecTop *)getRefLayerDec( i );
+#else
+        TDecTop *pcTDecTopBase = (TDecTop *)getLayerDec( m_layerId-1 );
+#endif
+        //TComPic*                      pcPic = *(pcTDecTopBase->getListPic()->begin()); 
+        TComPicYuv* pcPicYuvRecBase = (*(pcTDecTopBase->getListPic()->begin()))->getPicYuvRec(); 
+        if(pcPicYuvRecBase->getWidth() != pcSlice->getSPS()->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getSPS()->getPicHeightInLumaSamples() || !zeroOffsets )
+        {
+          rpcPic->setSpatialEnhLayerFlag( i, true );
+
+          //only for scalable extension
+          assert( pcSlice->getVPS()->getScalabilityMask(1) == true );
+        }
+#if MAX_ONE_RESAMPLING_DIRECT_LAYERS
+        if(pcSlice->getVPS()->getScalabilityMask(1))
+        {
+          pcSlice->setPic(rpcPic);
+        }
+#endif
       }
     }
@@ -456,5 +472,4 @@
   m_apcSlicePilot->setPPS(pps);
   m_apcSlicePilot->setSPS(sps);
-
   pps->setSPS(sps);
   pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
@@ -518,5 +533,15 @@
   m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
 
-#if SVC_EXTENSION
+#if VPS_EXTN_DIRECT_REF_LAYERS && M0457_PREDICTION_INDICATIONS
+  setRefLayerParams(m_apcSlicePilot->getVPS());
+#endif
+#if REF_IDX_FRAMEWORK && M0457_COL_PICTURE_SIGNALING
+  m_apcSlicePilot->setNumMotionPredRefLayers(m_numMotionPredRefLayers);
+#endif
+
+#if SVC_EXTENSION
+#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
+  m_apcSlicePilot->setNumSamplePredRefLayers( getNumSamplePredRefLayers() );
+#endif
   m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder[m_layerId]);
 #else
@@ -803,69 +828,117 @@
     if(m_layerId > 0)
     {
+      for( i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
+      {
+        UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
 #if AVC_BASE
-      if( m_parameterSetManagerDecoder[0].getActiveVPS()->getAvcBaseLayerFlag() )
-      {
-        pcSlice->setBaseColPic ( *m_ppcTDecTop[0]->getListPic()->begin() );
+        if( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) == 0 && m_parameterSetManagerDecoder[0].getActiveVPS()->getAvcBaseLayerFlag() )
+        {
+          pcSlice->setBaseColPic ( refLayerIdc, *m_ppcTDecTop[0]->getListPic()->begin() );
 #if AVC_SYNTAX
-        TComPic* pBLPic = pcSlice->getBaseColPic();
-        if( pcSlice->getPOC() == 0 )
+          TComPic* pBLPic = pcSlice->getBaseColPic(refLayerIdc);
+          if( pcSlice->getPOC() == 0 )
+          {
+            // initialize partition order.
+            UInt* piTmp = &g_auiZscanToRaster[0];
+            initZscanToRaster( pBLPic->getPicSym()->getMaxDepth() + 1, 1, 0, piTmp );
+            initRasterToZscan( pBLPic->getPicSym()->getMaxCUWidth(), pBLPic->getPicSym()->getMaxCUHeight(), pBLPic->getPicSym()->getMaxDepth() + 1 );
+          }      
+          pBLPic->getSlice( 0 )->initBaseLayerRPL( pcSlice );
+          pBLPic->readBLSyntax( m_ppcTDecTop[0]->getBLSyntaxFile(), SYNTAX_BYTES );
+#endif
+        }
+        else
         {
-          // initialize partition order.
-          UInt* piTmp = &g_auiZscanToRaster[0];
-          initZscanToRaster( pBLPic->getPicSym()->getMaxDepth() + 1, 1, 0, piTmp );
-          initRasterToZscan( pBLPic->getPicSym()->getMaxCUWidth(), pBLPic->getPicSym()->getMaxCUHeight(), pBLPic->getPicSym()->getMaxDepth() + 1 );
-        }      
-        pBLPic->getSlice( 0 )->initBaseLayerRPL( pcSlice );
-        pBLPic->readBLSyntax( m_ppcTDecTop[0]->getBLSyntaxFile(), SYNTAX_BYTES );
-#endif
-      }
-      else
-      {
-#if VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE
-        TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( m_layerId );
+#if VPS_EXTN_DIRECT_REF_LAYERS
+          TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
+#else
+          TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
+#endif
+          TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
+          pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
+        }
+#else
+#if VPS_EXTN_DIRECT_REF_LAYERS
+        TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
 #else
         TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
 #endif
         TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
-        pcSlice->setBaseColPic ( *cListPic, m_layerId );
-      }
-#else
-#if VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE
-      TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( m_layerId );
-#else
-      TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
-#endif
-      TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
-      pcSlice->setBaseColPic ( *cListPic, m_layerId );
-#endif
+        pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
+#endif
+
+#if SIMPLIFIED_MV_POS_SCALING
+#if SCALED_REF_LAYER_OFFSETS
+        const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
+
+        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth();
+        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight();
+
+        Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
+        Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
+#else
+        const Window &confBL = pcSlice->getBaseColPic()->getPicYuvRec()->getConformanceWindow();
+        const Window &confEL = pcPic->getPicYuvRec()->getConformanceWindow();
+
+        Int widthBL   = pcSlice->getBaseColPic()->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
+        Int heightBL  = pcSlice->getBaseColPic()->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
+
+        Int widthEL   = pcPic->getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
+        Int heightEL  = pcPic->getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
+#endif
+        g_mvScalingFactor[refLayerIdc][0] = widthEL  == widthBL  ? 4096 : Clip3(-4096, 4095, ((widthEL  << 8) + (widthBL  >> 1)) / widthBL);
+        g_mvScalingFactor[refLayerIdc][1] = heightEL == heightBL ? 4096 : Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL);
+
+        g_posScalingFactor[refLayerIdc][0] = ((widthBL  << 16) + (widthEL  >> 1)) / widthEL;
+        g_posScalingFactor[refLayerIdc][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL;
+#endif
+
 #if SVC_UPSAMPLING
-      if ( pcPic->isSpatialEnhLayer())
-      {    
+        if( pcPic->isSpatialEnhLayer(refLayerIdc) )
+        {    
 #if SCALED_REF_LAYER_OFFSETS
-        m_cPrediction.upsampleBasePic( pcPic->getFullPelBaseRec(), pcSlice->getBaseColPic()->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow() );
-#else
-        m_cPrediction.upsampleBasePic( pcPic->getFullPelBaseRec(), pcSlice->getBaseColPic()->getPicYuvRec(), pcPic->getPicYuvRec() );
-#endif
-      }
-      else
-      {
-        pcPic->setFullPelBaseRec( pcSlice->getBaseColPic()->getPicYuvRec() );
-      }
-      pcSlice->setFullPelBaseRec ( pcPic->getFullPelBaseRec() );
-#endif
+          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc) );
+#else
+          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec() );
+#endif
+        }
+        else
+        {
+          pcPic->setFullPelBaseRec( refLayerIdc, pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec() );
+        }
+        pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) );
+#endif
+      }
     }
 
 #if REF_IDX_FRAMEWORK
+#if ZERO_NUM_DIRECT_LAYERS
+    if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
+#else
     if(m_layerId > 0)
+#endif
     {
       setILRPic(pcPic);
 #if REF_IDX_MFM
+#if M0457_COL_PICTURE_SIGNALING
+      if( pcSlice->getMFMEnabledFlag() )
+#else
       if( pcSlice->getSPS()->getMFMEnabledFlag() )
+#endif
       {
         pcSlice->setRefPOCListILP(m_ppcTDecTop[m_layerId]->m_cIlpPic, pcSlice->getBaseColPic());
+#if M0457_COL_PICTURE_SIGNALING
+        pcSlice->setMotionPredIlp(getMotionPredIlp(pcSlice));
+#endif
       }
 #endif
       pcSlice->setRefPicList( m_cListPic, false, m_cIlpPic);
     }
+#if M0040_ADAPTIVE_RESOLUTION_CHANGE
+    else if ( m_layerId > 0 )
+    {
+      pcSlice->setRefPicList( m_cListPic, false, NULL);
+    }
+#endif
 #endif
 
@@ -913,22 +986,4 @@
     //---------------
     pcSlice->setRefPOCList();
-#if !L0034_COMBINED_LIST_CLEANUP
-    pcSlice->setNoBackPredFlag( false );
-    if ( pcSlice->getSliceType() == B_SLICE )
-    {
-      if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) )
-      {
-        pcSlice->setNoBackPredFlag( true );
-        for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ )
-        {
-          if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) 
-          {
-            pcSlice->setNoBackPredFlag( false );
-            break;
-          }
-        }
-      }
-    }
-#endif
   }
 
@@ -955,33 +1010,4 @@
   }
 
-#if SIMPLIFIED_MV_POS_SCALING
-  if (m_layerId > 0)
-  {
-#if SCALED_REF_LAYER_OFFSETS
-    const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow();
-
-    Int widthBL   = pcSlice->getBaseColPic()->getPicYuvRec()->getWidth();
-    Int heightBL  = pcSlice->getBaseColPic()->getPicYuvRec()->getHeight();
-
-    Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
-    Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
-#else
-    const Window &confBL = pcSlice->getBaseColPic()->getPicYuvRec()->getConformanceWindow();
-    const Window &confEL = pcPic->getPicYuvRec()->getConformanceWindow();
-
-    Int widthBL   = pcSlice->getBaseColPic()->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
-    Int heightBL  = pcSlice->getBaseColPic()->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
-
-    Int widthEL   = pcPic->getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
-    Int heightEL  = pcPic->getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
-#endif
-    g_mvScalingFactor[m_layerId][0] = Clip3(-4096, 4095, ((widthEL  << 8) + (widthBL  >> 1)) / widthBL);
-    g_mvScalingFactor[m_layerId][1] = Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL);
-
-    g_posScalingFactor[m_layerId][0] = ((widthBL  << 16) + (widthEL  >> 1)) / widthEL;
-    g_posScalingFactor[m_layerId][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL;
-  }
-#endif
-
   //  Decode a picture
   m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
@@ -1011,5 +1037,9 @@
   sps->setLayerId(m_layerId);
 #endif
+#if SPS_SUB_LAYER_INFO
+  m_cEntropyDecoder.decodeSPS( sps, &m_parameterSetManagerDecoder[0] );
+#else
   m_cEntropyDecoder.decodeSPS( sps );
+#endif
 #if SVC_EXTENSION
   m_parameterSetManagerDecoder[m_layerId].storePrefetchedSPS(sps);
@@ -1054,9 +1084,17 @@
   if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
   {
+#if M0043_LAYERS_PRESENT_SEI
+    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveVPS(), m_parameterSetManagerDecoder[m_layerId].getActiveSPS() );
+#else
     m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveSPS() );
+#endif
   }
   else
   {
+#if M0043_LAYERS_PRESENT_SEI
+    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveVPS(), m_parameterSetManagerDecoder[m_layerId].getActiveSPS() );
+#else
     m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveSPS() );
+#endif
     SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
     if (activeParamSets.size()>0)
@@ -1074,9 +1112,17 @@
   if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
   {
+#if M0043_LAYERS_PRESENT_SEI
+    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
+#else
     m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
+#endif
   }
   else
   {
+#if M0043_LAYERS_PRESENT_SEI
+    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
+#else
     m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
+#endif
     SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
     if (activeParamSets.size()>0)
@@ -1269,6 +1315,6 @@
 }
 
-#if VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE
-TDecTop* TDecTop::getRefLayerDec( UInt layerId )
+#if VPS_EXTN_DIRECT_REF_LAYERS
+TDecTop* TDecTop::getRefLayerDec( UInt refLayerIdc )
 {
   TComVPS* vps = m_parameterSetManagerDecoder[0].getActiveVPS();
@@ -1281,12 +1327,89 @@
 #endif
   }
-
-  // currently only one reference layer is supported
-  assert( vps->getNumDirectRefLayers( m_layerId ) == 1 );
-#if JCTVC_M0458_INTERLAYER_RPS_SIG
-  assert( vps->getMaxOneActiveRefLayerFlag() == 1 );
-#endif 
-  
-  return (TDecTop *)getLayerDec( vps->getRefLayerId( m_layerId, 0 ) );
+  
+  return (TDecTop *)getLayerDec( vps->getRefLayerId( m_layerId, refLayerIdc ) );
+}
+#endif
+
+#if VPS_EXTN_DIRECT_REF_LAYERS && M0457_PREDICTION_INDICATIONS
+
+Void TDecTop::setRefLayerParams( TComVPS* vps )
+{
+  for(UInt layer = 0; layer < m_numLayer; layer++)
+  {
+    TDecTop *decTop = (TDecTop *)getLayerDec(layer);
+    decTop->setNumSamplePredRefLayers(0);
+    decTop->setNumMotionPredRefLayers(0);
+    decTop->setNumDirectRefLayers(0);
+    for(Int i = 0; i < MAX_VPS_LAYER_ID_PLUS1; i++)
+    {
+      decTop->setSamplePredEnabledFlag(i, false);
+      decTop->setMotionPredEnabledFlag(i, false);
+      decTop->setSamplePredRefLayerId(i, 0);
+      decTop->setMotionPredRefLayerId(i, 0);
+    }
+    for(Int j = 0; j < layer; j++)
+    {
+      if (vps->getDirectDependencyFlag(layer, j))
+      {
+        decTop->setRefLayerId(decTop->getNumDirectRefLayers(), vps->getLayerIdInNuh(layer));
+        decTop->setNumDirectRefLayers(decTop->getNumDirectRefLayers() + 1);
+
+        Int samplePredEnabledFlag = (vps->getDirectDependencyType(layer, j) + 1) & 1;
+        decTop->setSamplePredEnabledFlag(j, samplePredEnabledFlag == 1 ? true : false);
+        decTop->setNumSamplePredRefLayers(decTop->getNumSamplePredRefLayers() + samplePredEnabledFlag);
+
+        Int motionPredEnabledFlag = ((vps->getDirectDependencyType(layer, j) + 1) & 2) >> 1;
+        decTop->setMotionPredEnabledFlag(j, motionPredEnabledFlag == 1 ? true : false);
+        decTop->setNumMotionPredRefLayers(decTop->getNumMotionPredRefLayers() + motionPredEnabledFlag);
+      }
+    }
+  }
+  for ( Int i = 1, mIdx = 0, sIdx = 0; i < m_numLayer; i++ )
+  {
+    Int iNuhLId = vps->getLayerIdInNuh(i);
+    TDecTop *decTop = (TDecTop *)getLayerDec(iNuhLId);
+    for ( Int j = 0; j < i; j++ )
+    {
+      if (decTop->getMotionPredEnabledFlag(j))
+      {
+        decTop->setMotionPredRefLayerId(mIdx++, vps->getLayerIdInNuh(j));
+      }
+      if (decTop->getSamplePredEnabledFlag(j))
+      {
+        decTop->setSamplePredRefLayerId(sIdx++, vps->getLayerIdInNuh(j));
+      }
+    }
+  }
+}
+
+#endif
+
+#if M0457_COL_PICTURE_SIGNALING
+TComPic* TDecTop::getMotionPredIlp(TComSlice* pcSlice)
+{
+  TComPic* ilpPic = NULL;
+  Int activeMotionPredReflayerIdx = 0;
+
+  for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
+  {
+    UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
+    if( getMotionPredEnabledFlag( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) ) )
+    {
+      if (activeMotionPredReflayerIdx == pcSlice->getColRefLayerIdx())
+      {
+        ilpPic = m_cIlpPic[refLayerIdc];
+        break;
+      }
+      else
+      {
+        activeMotionPredReflayerIdx++;
+      }
+    }
+  }
+
+  assert(ilpPic != NULL);
+
+  return ilpPic;
 }
 #endif
Index: trunk/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecTop.h	(revision 229)
+++ trunk/source/Lib/TLibDecoder/TDecTop.h	(revision 310)
@@ -120,4 +120,14 @@
   Int                     m_iBLSourceHeight;
 #endif
+#if VPS_EXTN_DIRECT_REF_LAYERS && M0457_PREDICTION_INDICATIONS
+  Int                     m_numDirectRefLayers;
+  Int                     m_refLayerId[MAX_VPS_LAYER_ID_PLUS1];
+  Int                     m_numSamplePredRefLayers;
+  Int                     m_samplePredRefLayerId[MAX_VPS_LAYER_ID_PLUS1];
+  Int                     m_numMotionPredRefLayers;
+  Int                     m_motionPredRefLayerId[MAX_VPS_LAYER_ID_PLUS1];
+  Bool                    m_samplePredEnabledFlag[MAX_VPS_LAYER_ID_PLUS1];
+  Bool                    m_motionPredEnabledFlag[MAX_VPS_LAYER_ID_PLUS1];
+#endif
 #endif 
 #if AVC_SYNTAX || SYNTAX_OUTPUT
@@ -156,6 +166,36 @@
   Void      setLayerDec(TDecTop **p)    { m_ppcTDecTop = p; }
   TDecTop*  getLayerDec(UInt layer)     { return m_ppcTDecTop[layer]; }
-#if VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE
-  TDecTop*  getRefLayerDec(UInt layerId);
+#if VPS_EXTN_DIRECT_REF_LAYERS
+  TDecTop*  getRefLayerDec(UInt refLayerIdc);
+#if M0457_PREDICTION_INDICATIONS
+  Int       getNumDirectRefLayers           ()                              { return m_numDirectRefLayers;      }
+  Void      setNumDirectRefLayers           (Int num)                       { m_numDirectRefLayers = num;       }
+
+  Int       getRefLayerId                   (Int i)                         { return m_refLayerId[i];           }
+  Void      setRefLayerId                   (Int i, Int refLayerId)         { m_refLayerId[i] = refLayerId;     }
+
+  Int       getNumSamplePredRefLayers       ()                              { return m_numSamplePredRefLayers;  }
+  Void      setNumSamplePredRefLayers       (Int num)                       { m_numSamplePredRefLayers = num;   }
+
+  Int       getSamplePredRefLayerId         (Int i)                         { return m_samplePredRefLayerId[i];       }
+  Void      setSamplePredRefLayerId         (Int i, Int refLayerId)         { m_samplePredRefLayerId[i] = refLayerId; }
+
+  Int       getNumMotionPredRefLayers       ()                              { return m_numMotionPredRefLayers;  }
+  Void      setNumMotionPredRefLayers       (Int num)                       { m_numMotionPredRefLayers = num;   }
+
+  Int       getMotionPredRefLayerId         (Int i)                         { return m_motionPredRefLayerId[i];       }
+  Void      setMotionPredRefLayerId         (Int i, Int refLayerId)         { m_motionPredRefLayerId[i] = refLayerId; }
+
+  Bool      getSamplePredEnabledFlag        (Int i)                         { return m_samplePredEnabledFlag[i];  }
+  Void      setSamplePredEnabledFlag        (Int i,Bool flag)               { m_samplePredEnabledFlag[i] = flag;  }
+
+  Bool      getMotionPredEnabledFlag        (Int i)                         { return m_motionPredEnabledFlag[i];  }
+  Void      setMotionPredEnabledFlag        (Int i,Bool flag)               { m_motionPredEnabledFlag[i] = flag;  }
+
+  TDecTop*  getSamplePredRefLayerDec        ( UInt layerId );
+  TDecTop*  getMotionPredRefLayerDec        ( UInt layerId );
+
+  Void      setRefLayerParams( TComVPS* vps );
+#endif
 #endif
 #if AVC_BASE
@@ -190,4 +230,7 @@
   Void      xDecodePPS();
   Void      xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType );
+#if M0457_COL_PICTURE_SIGNALING
+  TComPic*  getMotionPredIlp(TComSlice* pcSlice);
+#endif
 
 };// END CLASS DEFINITION TDecTop
