Index: trunk/source/Lib/TLibDecoder/NALread.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/NALread.cpp	(revision 713)
+++ trunk/source/Lib/TLibDecoder/NALread.cpp	(revision 815)
@@ -114,4 +114,5 @@
   if ( nalu.m_temporalId )
   {
+#if !Q0108_TSA_STSA
     assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA_W_LP
          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA_W_RADL
@@ -124,11 +125,29 @@
          && nalu.m_nalUnitType != NAL_UNIT_EOS
          && nalu.m_nalUnitType != NAL_UNIT_EOB );
+#else
+    assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA_W_LP
+         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA_W_RADL
+         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_BLA_N_LP
+         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDR_W_RADL
+         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_IDR_N_LP
+         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_CRA
+         && nalu.m_nalUnitType != NAL_UNIT_VPS
+         && nalu.m_nalUnitType != NAL_UNIT_SPS
+         && nalu.m_nalUnitType != NAL_UNIT_EOS); 
+#endif
   }
   else
   {
+#if !Q0108_TSA_STSA
     assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_R
          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_N
          && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_R
-         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_N );
+         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_N 
+         );
+#else
+    assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_R
+         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_N
+         );
+#endif
   }
 }
Index: trunk/source/Lib/TLibDecoder/SEIread.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/SEIread.cpp	(revision 713)
+++ trunk/source/Lib/TLibDecoder/SEIread.cpp	(revision 815)
@@ -93,4 +93,9 @@
     fprintf( g_hTrace, "===========Tone Mapping Info SEI message ===========\n");
     break;
+#if P0050_KNEE_FUNCTION_SEI
+  case SEI::KNEE_FUNCTION_INFO:
+    fprintf( g_hTrace, "=========== Knee Function Information SEI message ===========\n");
+    break;
+#endif
 #if Q0074_SEI_COLOR_MAPPING
   case SEI::COLOR_MAPPING_INFO:
@@ -129,4 +134,12 @@
   case SEI::BSP_HRD:
     fprintf( g_hTrace, "=========== Bitstream parition HRD parameters SEI message ===========\n");
+    break;
+#endif
+#if Q0078_ADD_LAYER_SETS
+  case SEI::OUTPUT_LAYER_SET_NESTING:
+    fprintf(g_hTrace, "=========== Output layer set nesting SEI message ===========\n");
+    break;
+  case SEI::VPS_REWRITING:
+    fprintf(g_hTrace, "=========== VPS rewriting SEI message ===========\n");
     break;
 #endif
@@ -285,4 +298,10 @@
       xParseSEIToneMappingInfo((SEIToneMappingInfo&) *sei, payloadSize);
       break;
+#if P0050_KNEE_FUNCTION_SEI
+    case SEI::KNEE_FUNCTION_INFO:
+      sei = new SEIKneeFunctionInfo;
+      xParseSEIKneeFunctionInfo((SEIKneeFunctionInfo&) *sei, payloadSize);
+      break;
+#endif
 #if Q0074_SEI_COLOR_MAPPING
     case SEI::COLOR_MAPPING_INFO:
@@ -345,4 +364,30 @@
      sei = new SEIBspHrd;
      xParseSEIBspHrd((SEIBspHrd&) *sei, sps, *nestingSei);
+     break;
+#endif
+#if Q0078_ADD_LAYER_SETS
+   case SEI::OUTPUT_LAYER_SET_NESTING:
+     sei = new SEIOutputLayerSetNesting;
+#if LAYERS_NOT_PRESENT_SEI
+     xParseSEIOutputLayerSetNesting((SEIOutputLayerSetNesting&)*sei, nalUnitType, vps, sps);
+#else
+     xParseSEIOutputLayerSetNesting((SEIOutputLayerSetNesting&)*sei, nalUnitType, sps);
+#endif
+     break;
+   case SEI::VPS_REWRITING:
+     sei = new SEIVPSRewriting;
+     xParseSEIVPSRewriting((SEIVPSRewriting&)*sei);
+     break;
+#endif
+#if Q0189_TMVP_CONSTRAINTS
+   case SEI::TMVP_CONSTRAINTS:
+     sei =  new SEITMVPConstrains;
+     xParseSEITMVPConstraints((SEITMVPConstrains&) *sei, payloadSize);
+     break;
+#endif
+#if Q0247_FRAME_FIELD_INFO
+   case SEI::FRAME_FIELD_INFO:
+     sei =  new SEIFrameFieldInfo;
+     xParseSEIFrameFieldInfo    ((SEIFrameFieldInfo&) *sei, payloadSize); 
      break;
 #endif
@@ -849,4 +894,31 @@
 }
 
+#if P0050_KNEE_FUNCTION_SEI
+Void SEIReader::xParseSEIKneeFunctionInfo(SEIKneeFunctionInfo& sei, UInt /*payloadSize*/){
+  Int i;
+  UInt val;
+  READ_UVLC( val, "knee_function_id" );                   sei.m_kneeId = val;
+  READ_FLAG( val, "knee_function_cancel_flag" );          sei.m_kneeCancelFlag = val;
+  if ( !sei.m_kneeCancelFlag )
+  {
+    READ_FLAG( val, "knee_function_persistence_flag" );   sei.m_kneePersistenceFlag = val;
+    READ_FLAG( val, "mapping_flag" );                     sei.m_kneeMappingFlag = val;
+    READ_CODE( 32, val, "input_d_range" );                sei.m_kneeInputDrange = val;
+    READ_CODE( 32, val, "input_disp_luminance" );         sei.m_kneeInputDispLuminance = val;
+    READ_CODE( 32, val, "output_d_range" );               sei.m_kneeOutputDrange = val;
+    READ_CODE( 32, val, "output_disp_luminance" );        sei.m_kneeOutputDispLuminance = val;
+    READ_UVLC( val, "num_knee_points_minus1" );           sei.m_kneeNumKneePointsMinus1 = val;
+    assert( sei.m_kneeNumKneePointsMinus1 > 0 );
+    sei.m_kneeInputKneePoint.resize(sei.m_kneeNumKneePointsMinus1+1);
+    sei.m_kneeOutputKneePoint.resize(sei.m_kneeNumKneePointsMinus1+1);
+    for(i = 0; i <= sei.m_kneeNumKneePointsMinus1; i++ )
+    {
+      READ_CODE( 10, val, "input_knee_point" );           sei.m_kneeInputKneePoint[i] = val;
+      READ_CODE( 10, val, "output_knee_point" );          sei.m_kneeOutputKneePoint[i] = val;
+    }
+  }
+}
+#endif
+
 #if Q0074_SEI_COLOR_MAPPING
 Void SEIReader::xParseSEIColorMappingInfo(SEIColorMappingInfo& sei, UInt /*payloadSize*/)
@@ -960,4 +1032,25 @@
 }
 
+#if Q0189_TMVP_CONSTRAINTS 
+Void SEIReader::xParseSEITMVPConstraints   (SEITMVPConstrains& sei, UInt payloadSize)
+{
+  UInt uiCode;
+  READ_UVLC( uiCode,           "prev_pics_not_used_flag"              ); sei.prev_pics_not_used_flag = uiCode;
+  READ_UVLC( uiCode,           "no_intra_layer_col_pic_flag"            ); sei.no_intra_layer_col_pic_flag = uiCode;
+  xParseByteAlign();
+}
+#endif
+
+#if Q0247_FRAME_FIELD_INFO
+Void SEIReader::xParseSEIFrameFieldInfo    (SEIFrameFieldInfo& sei, UInt payloadSize)
+{
+  UInt code;
+  READ_CODE( 4, code, "ffinfo_pic_struct" );             sei.m_ffinfo_picStruct            = code;
+  READ_CODE( 2, code, "ffinfo_source_scan_type" );       sei.m_ffinfo_sourceScanType = code;
+  READ_FLAG(    code, "ffinfo_duplicate_flag" );         sei.m_ffinfo_duplicateFlag    = ( code == 1 ? true : false );
+  xParseByteAlign();
+}
+#endif
+
 #if LAYERS_NOT_PRESENT_SEI
 Void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComVPS *vps, TComSPS *sps)
@@ -1209,21 +1302,69 @@
     UInt lsIdx = nestingSei.m_nestingOpIdx[h];
     READ_UVLC( uiCode, "num_sei_bitstream_partitions_minus1[i]"); sei.m_seiNumBitstreamPartitionsMinus1[lsIdx] = uiCode;
-    for (UInt i = 0; i <= sei.m_seiNumBitstreamPartitionsMinus1[lsIdx]; i++)
-    {
-      for (UInt j = 0; j < sei.m_vpsMaxLayers; j++)
+#if HRD_BPB
+    Int chkPart=0;
+#endif
+    UInt i;
+    for(i = 0; i <= sei.m_seiNumBitstreamPartitionsMinus1[lsIdx]; i++)
+    {
+#if HRD_BPB
+      UInt nl=0; UInt j;
+      for(j = 0; j < sei.m_vpsMaxLayers; j++)
       {
         if (sei.m_layerIdIncludedFlag[lsIdx][j])
         {
+          nl++;
+        }
+      }
+      for (j = 0; j < nl; j++)
+      {
+#else
+      for (UInt j = 0; j < sei.m_vpsMaxLayers; j++)
+      {
+        if (sei.m_layerIdIncludedFlag[lsIdx][j])
+        {
+#endif
           READ_FLAG( uiCode, "sei_layer_in_bsp_flag[lsIdx][i][j]" ); sei.m_seiLayerInBspFlag[lsIdx][i][j] = uiCode;
         }
-      }
-    }
+#if !HRD_BPB
+      }
+#endif
+#if HRD_BPB
+      chkPart+=sei.m_seiLayerInBspFlag[lsIdx][i][j];
+#endif
+    }
+#if HRD_BPB
+    assert(chkPart<=1);
+#endif
+#if HRD_BPB
+    if(sei.m_seiNumBitstreamPartitionsMinus1[lsIdx]==0)
+    {
+      Int chkPartition1=0; Int chkPartition2=0;
+      for (UInt j = 0; j < sei.m_vpsMaxLayers; j++)
+      {
+        if( sei.m_layerIdIncludedFlag[lsIdx][j] )
+        {
+          chkPartition1+=sei.m_seiLayerInBspFlag[lsIdx][0][j];
+          chkPartition2++;
+        }
+      }
+      assert(chkPartition1!=chkPartition2);
+    }
+#endif
+      
     READ_UVLC( uiCode, "sei_num_bsp_sched_combinations_minus1[i]"); sei.m_seiNumBspSchedCombinationsMinus1[lsIdx] = uiCode;
-    for (UInt i = 0; i <= sei.m_seiNumBspSchedCombinationsMinus1[lsIdx]; i++)
+    for (i = 0; i <= sei.m_seiNumBspSchedCombinationsMinus1[lsIdx]; i++)
     {
       for (UInt j = 0; j <= sei.m_seiNumBitstreamPartitionsMinus1[lsIdx]; j++)
       {
         READ_UVLC( uiCode, "sei_bsp_comb_hrd_idx[lsIdx][i][j]"); sei.m_seiBspCombHrdIdx[lsIdx][i][j] = uiCode;
+#if HRD_BPB
+        assert(uiCode <= sei.m_seiNumBspHrdParametersMinus1);
+#endif
         READ_UVLC( uiCode, "sei_bsp_comb_sched_idx[lsIdx][i][j]"); sei.m_seiBspCombScheddx[lsIdx][i][j] = uiCode;
+#if HRD_BPB
+        assert(uiCode <= sei.hrd->getCpbCntMinus1( sps->getMaxTLayers()-1 ));
+#endif
+
       }
     }
@@ -1307,4 +1448,57 @@
 #endif
 
+#if Q0078_ADD_LAYER_SETS
+
+#if LAYERS_NOT_PRESENT_SEI
+Void SEIReader::xParseSEIOutputLayerSetNesting(SEIOutputLayerSetNesting& sei, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps)
+#else
+Void SEIReader::xParseSEIOutputLayerSetNesting(SEIOutputLayerSetNesting& sei, const NalUnitType nalUnitType, TComSPS *sps)
+#endif
+{
+  UInt uiCode;
+  SEIMessages seis;
+
+  READ_FLAG(uiCode, "ols_flag"); sei.m_olsFlag = uiCode;
+  READ_UVLC(uiCode, "num_ols_indices_minus1"); sei.m_numOlsIndicesMinus1 = uiCode;
+
+  for (Int i = 0; i <= sei.m_numOlsIndicesMinus1; i++)
+  {
+    READ_UVLC(uiCode, "ols_idx[i]"); sei.m_olsIdx[i] = uiCode;
+  }
+
+  // byte alignment
+  while (m_pcBitstream->getNumBitsRead() % 8 != 0)
+  {
+    UInt code;
+    READ_FLAG(code, "ols_nesting_zero_bit");
+  }
+
+  sei.m_callerOwnsSEIs = false;
+
+  // read nested SEI messages
+  do {
+#if O0164_MULTI_LAYER_HRD
+#if LAYERS_NOT_PRESENT_SEI
+    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps);
+#else
+    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps);
+#endif
+#else
+#if LAYERS_NOT_PRESENT_SEI
+    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps);
+#else
+    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps);
+#endif
+#endif
+  } while (m_pcBitstream->getNumBitsLeft() > 8);
+
+}
+
+Void SEIReader::xParseSEIVPSRewriting(SEIVPSRewriting &sei)
+{
+}
+
+#endif
+
 #endif //SVC_EXTENSION
 
Index: trunk/source/Lib/TLibDecoder/SEIread.h
===================================================================
--- trunk/source/Lib/TLibDecoder/SEIread.h	(revision 713)
+++ trunk/source/Lib/TLibDecoder/SEIread.h	(revision 815)
@@ -90,4 +90,7 @@
   Void xParseSEIGradualDecodingRefreshInfo (SEIGradualDecodingRefreshInfo &sei, UInt payloadSize);
   Void xParseSEIToneMappingInfo       (SEIToneMappingInfo& sei, UInt payloadSize);
+#if P0050_KNEE_FUNCTION_SEI
+  Void xParseSEIKneeFunctionInfo      (SEIKneeFunctionInfo& sei, UInt payloadSize);
+#endif
 #if Q0074_SEI_COLOR_MAPPING
   Void xParseSEIColorMappingInfo      (SEIColorMappingInfo& sei, UInt payloadSize);
@@ -116,4 +119,19 @@
   Void xParseHrdParameters(TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1);
 #endif
+#if Q0078_ADD_LAYER_SETS
+#if LAYERS_NOT_PRESENT_SEI
+  Void xParseSEIOutputLayerSetNesting(SEIOutputLayerSetNesting& sei, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps);
+#else
+  Void xParseSEIOutputLayerSetNesting(SEIOutputLayerSetNesting& sei, const NalUnitType nalUnitType, TComSPS *sps);
+#endif
+  Void xParseSEIVPSRewriting(SEIVPSRewriting &sei);
+#endif
+
+#if Q0189_TMVP_CONSTRAINTS 
+  Void xParseSEITMVPConstraints    (SEITMVPConstrains& sei, UInt payloadSize);
+#endif
+#if Q0247_FRAME_FIELD_INFO
+  Void xParseSEIFrameFieldInfo    (SEIFrameFieldInfo& sei, UInt payloadSize);
+#endif
   Void xParseByteAlign();
 };
Index: trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 713)
+++ trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 815)
@@ -339,5 +339,11 @@
 
   READ_FLAG( uiCode, "pps_extension_flag");
+#if POC_RESET_INFO_INFERENCE
+  pcPPS->setExtensionFlag( uiCode ? true : false );
+
+  if( pcPPS->getExtensionFlag() )
+#else
   if (uiCode)
+#endif  
   {
 #if P0166_MODIFIED_PPS_EXTENSION
@@ -367,4 +373,10 @@
 #endif
     }
+#if POC_RESET_INFO_INFERENCE
+    else  // Extension type 0 absent
+    {
+      pcPPS->setPocResetInfoPresentFlag( false );
+    }
+#endif
     if (ppsExtensionTypeFlag[7])
     {
@@ -379,4 +391,10 @@
 #endif
   }
+#if POC_RESET_INFO_INFERENCE
+  if( !pcPPS->getExtensionFlag() )
+  {
+    pcPPS->setPocResetInfoPresentFlag( false );
+  }
+#endif
 }
 
@@ -443,5 +461,5 @@
   TimingInfo *timingInfo = pcVUI->getTimingInfo();
   READ_FLAG(       uiCode, "vui_timing_info_present_flag");         timingInfo->setTimingInfoPresentFlag      (uiCode ? true : false);
-#if TIMING_INFO_NONZERO_LAYERID_SPS
+#if SVC_EXTENSION
   if( pcSPS->getLayerId() > 0 )
   {
@@ -585,4 +603,5 @@
 #endif
 
+#if !Q0177_SPS_TEMP_NESTING_FIX   //This part is not needed anymore as it is already covered by implementation in TDecTop::xActivateParameterSets()
   if ( pcSPS->getMaxTLayers() == 1 )
   {
@@ -596,4 +615,6 @@
 #endif
   }
+#endif
+
 #ifdef SPS_PTL_FIX
   if ( pcSPS->getLayerId() == 0)
@@ -827,8 +848,10 @@
 
   READ_FLAG( uiCode, "sps_extension_flag");
-  if (uiCode)
-  {
-#if SPS_EXTENSION
-
+
+#if SVC_EXTENSION
+  pcSPS->setExtensionFlag( uiCode ? true : false );
+
+  if( pcSPS->getExtensionFlag() )
+  {
 #if O0142_CONDITIONAL_SPS_EXTENSION
     UInt spsExtensionTypeFlag[8];
@@ -849,17 +872,22 @@
     {
 #endif
-
-#endif
       while ( xMoreRbspData() )
       {
         READ_FLAG( uiCode, "sps_extension_data_flag");
       }
-#if SPS_EXTENSION
-    }
-#endif
-  }
-}
-
-#if SPS_EXTENSION
+    }
+  }
+#else
+  if (uiCode)
+  {
+    while ( xMoreRbspData() )
+    {
+      READ_FLAG( uiCode, "sps_extension_data_flag");
+    }
+  }
+#endif
+}
+
+#if SVC_EXTENSION
 Void TDecCavlc::parseSPSExtension( TComSPS* pcSPS )
 {
@@ -899,5 +927,5 @@
   READ_CODE( 4,  uiCode,  "vps_video_parameter_set_id" );         pcVPS->setVPSId( uiCode );
   READ_CODE( 2,  uiCode,  "vps_reserved_three_2bits" );           assert(uiCode == 3);
-#if VPS_RENAME
+#if SVC_EXTENSION
 #if O0137_MAX_LAYERID
   READ_CODE( 6,  uiCode,  "vps_max_layers_minus1" );              pcVPS->setMaxLayers( min( 62u, uiCode) + 1 );
@@ -941,10 +969,16 @@
   }
 
-#if VPS_RENAME
+#if SVC_EXTENSION
   assert( pcVPS->getNumHrdParameters() < MAX_VPS_LAYER_SETS_PLUS1 );
   assert( pcVPS->getMaxLayerId()       < MAX_VPS_LAYER_ID_PLUS1 );
   READ_CODE( 6, uiCode, "vps_max_layer_id" );           pcVPS->setMaxLayerId( uiCode );
+#if Q0078_ADD_LAYER_SETS
+  READ_UVLC(uiCode, "vps_num_layer_sets_minus1");  pcVPS->setVpsNumLayerSetsMinus1(uiCode);
+  pcVPS->setNumLayerSets(pcVPS->getVpsNumLayerSetsMinus1() + 1);
+  for (UInt opsIdx = 1; opsIdx <= pcVPS->getVpsNumLayerSetsMinus1(); opsIdx++)
+#else
   READ_UVLC(    uiCode, "vps_num_layer_sets_minus1" );  pcVPS->setNumLayerSets( uiCode + 1 );
   for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getNumLayerSets() - 1 ); opsIdx ++ )
+#endif
   {
     // Operation point set
@@ -995,5 +1029,5 @@
   }
 
-#if VPS_EXTNS
+#if SVC_EXTENSION
   READ_FLAG( uiCode,  "vps_extension_flag" );      pcVPS->setVpsExtensionFlag( uiCode ? true : false );
 
@@ -1040,5 +1074,4 @@
 
 #if SVC_EXTENSION
-#if VPS_EXTNS
 Void TDecCavlc::parseVPSExtension(TComVPS *vps)
 {
@@ -1081,4 +1114,5 @@
   }
 
+  // The value of dimBitOffset[ NumScalabilityTypes ] is set equal to 6.
   if(vps->getSplittingFlag())
   {
@@ -1166,4 +1200,19 @@
   }
 #endif
+#if Q0078_ADD_LAYER_SETS
+#if O0092_0094_DEPENDENCY_CONSTRAINT // Moved here
+  vps->setNumRefLayers();
+
+  if (vps->getMaxLayers() > MAX_REF_LAYERS)
+  {
+    for (i = 1; i < vps->getMaxLayers(); i++)
+    {
+      assert(vps->getNumRefLayers(vps->getLayerIdInNuh(i)) <= MAX_REF_LAYERS);
+    }
+  }
+#endif
+  vps->setPredictedLayerIds();
+  vps->setTreePartitionLayerIdList();
+#endif
 #if VPS_TSLAYERS
   READ_FLAG( uiCode, "vps_sub_layers_max_minus1_present_flag"); vps->setMaxTSLayersPresentFlag(uiCode ? true : false);
@@ -1184,5 +1233,4 @@
   }
 #endif
-#if N0120_MAX_TID_REF_PRESENT_FLAG
   READ_FLAG( uiCode, "max_tid_ref_present_flag"); vps->setMaxTidRefPresentFlag(uiCode ? true : false);
   if (vps->getMaxTidRefPresentFlag())
@@ -1201,9 +1249,5 @@
 #else
       READ_CODE( 3, uiCode, "max_tid_il_ref_pics_plus1[i]" ); vps->setMaxTidIlRefPicsPlus1(i, uiCode);
-#if N0120_MAX_TID_REF_CFG
       assert( uiCode <= vps->getMaxTLayers());
-#else
-      assert( uiCode <= vps->getMaxTLayers()+ 1 );
-#endif
 #endif 
     }
@@ -1223,25 +1267,5 @@
     }
   }
-#else
-  for(i = 0; i < vps->getMaxLayers() - 1; i++)
-  {
-#if O0225_MAX_TID_FOR_REF_LAYERS
-       for( j = i+1; j <= vps->getMaxLayers() - 1; j++)
-       {
-         if(vps->getDirectDependencyFlag(j, i))
-         {
-           READ_CODE( 3, uiCode, "max_tid_il_ref_pics_plus1[i][j]" ); vps->setMaxTidIlRefPicsPlus1(i, j, uiCode);
-           assert( uiCode <= vps->getMaxTLayers() );
-         }
-       }
-#else
-    READ_CODE( 3, uiCode, "max_tid_il_ref_pics_plus1[i]" ); vps->setMaxTidIlRefPicsPlus1(i, uiCode);
-    assert( uiCode <= vps->getMaxTLayers() );
-#endif   
-  }
-#endif
-#if ILP_SSH_SIG
-    READ_FLAG( uiCode, "all_ref_layers_active_flag" ); vps->setIlpSshSignalingEnabledFlag(uiCode ? true : false);
-#endif
+  READ_FLAG( uiCode, "all_ref_layers_active_flag" ); vps->setIlpSshSignalingEnabledFlag(uiCode ? true : false);
 #if VPS_EXTN_PROFILE_INFO
   // Profile-tier-level signalling
@@ -1276,4 +1300,25 @@
 #endif
 
+#if Q0078_ADD_LAYER_SETS
+  if (vps->getNumIndependentLayers() > 1)
+  {
+    READ_UVLC(uiCode, "num_add_layer_sets"); vps->setNumAddLayerSets(uiCode);
+    for (i = 0; i < vps->getNumAddLayerSets(); i++)
+    {
+      for (j = 1; j < vps->getNumIndependentLayers(); j++)
+      {
+        int len = 1;
+        while ((1 << len) < (vps->getNumLayersInTreePartition(j) + 1))
+        {
+          len++;
+        }
+        READ_CODE(len, uiCode, "highest_layer_idx_plus1[i][j]"); vps->setHighestLayerIdxPlus1(i, j, uiCode);
+      }
+    }
+    vps->setNumLayerSets(vps->getNumLayerSets() + vps->getNumAddLayerSets());
+    vps->setLayerIdIncludedFlagsForAddLayerSets();
+  }
+#endif
+
 #if !VPS_EXTN_UEV_CODING
   READ_FLAG( uiCode, "more_output_layer_sets_than_default_flag" ); vps->setMoreOutputLayerSetsThanDefaultFlag( uiCode ? true : false );
@@ -1293,6 +1338,6 @@
   if( vps->getNumLayerSets() > 1 )
   {
-    READ_UVLC( uiCode, "num_add_output_layer_sets" );            vps->setNumAddOutputLayerSets( uiCode );
-    READ_CODE( 2, uiCode, "default_target_output_layer_idc" );   vps->setDefaultTargetOutputLayerIdc( uiCode );
+    READ_UVLC( uiCode, "num_add_olss" );            vps->setNumAddOutputLayerSets( uiCode );
+    READ_CODE( 2, uiCode, "default_output_layer_idc" );   vps->setDefaultTargetOutputLayerIdc( uiCode );
   }
   else
@@ -1304,5 +1349,5 @@
 #endif
 
-  // The value of num_add_output_layer_sets shall be in the range of 0 to 1023, inclusive.
+  // The value of num_add_olss shall be in the range of 0 to 1023, inclusive.
   assert( vps->getNumAddOutputLayerSets() >= 0 && vps->getNumAddOutputLayerSets() < 1024 );
 
@@ -1328,5 +1373,5 @@
         numBits++;
       }
-      READ_CODE( numBits, uiCode, "output_layer_set_idx_minus1");   vps->setOutputLayerSetIdx( i, uiCode + 1);
+      READ_CODE( numBits, uiCode, "layer_set_idx_for_ols_minus1");   vps->setOutputLayerSetIdx( i, uiCode + 1);
     }
     else
@@ -1334,5 +1379,9 @@
       vps->setOutputLayerSetIdx( i, i );
     }
+#if Q0078_ADD_LAYER_SETS
+    if ( i > vps->getVpsNumLayerSetsMinus1() || vps->getDefaultTargetOutputLayerIdc() >= 2 )
+#else
     if ( i > (vps->getNumLayerSets() - 1) || vps->getDefaultTargetOutputLayerIdc() >= 2 )
+#endif
     {
       Int lsIdx = vps->getOutputLayerSetIdx(i);
@@ -1634,5 +1683,5 @@
 #endif
 
-#if N0147_IRAP_ALIGN_FLAG && !IRAP_ALIGN_FLAG_IN_VPS_VUI
+#if !IRAP_ALIGN_FLAG_IN_VPS_VUI
   READ_FLAG(uiCode, "cross_layer_irap_aligned_flag" );
   vps->setCrossLayerIrapAlignFlag(uiCode);
@@ -1678,9 +1727,8 @@
   }
 #endif
-#if O0092_0094_DEPENDENCY_CONSTRAINT
-  for(i = 1; i < vps->getMaxLayers(); i++)
-  {
-    vps->setNumRefLayers(vps->getLayerIdInNuh(i));   // identify the number of direct and indirect reference layers of current layer and set recursiveRefLayersFlags
-  }
+#if !Q0078_ADD_LAYER_SETS
+#if O0092_0094_DEPENDENCY_CONSTRAINT // Moved up
+  vps->setNumRefLayers();
+
   if(vps->getMaxLayers() > MAX_REF_LAYERS)
   {
@@ -1690,4 +1738,5 @@
     }
   }
+#endif
 #endif
 
@@ -1732,5 +1781,4 @@
 #endif
   {
-#if VPS_VUI
     while ( m_pcBitstream->getNumBitsRead() % 8 != 0 )
     {
@@ -1738,5 +1786,4 @@
     }
     parseVPSVUI(vps);
-#endif
   }
   else
@@ -1778,10 +1825,10 @@
   }
   
-  // When not present, the value of num_add_output_layer_sets is inferred to be equal to 0.
-  // NumOutputLayerSets = num_add_output_layer_sets + vps_num_layer_sets_minus1 + 1
+  // When not present, the value of num_add_olss is inferred to be equal to 0.
+  // NumOutputLayerSets = num_add_olss + NumLayerSets
   vps->setNumOutputLayerSets( vps->getNumLayerSets() );
 
   // For i in the range of 0 to NumOutputLayerSets-1, inclusive, the variable LayerSetIdxForOutputLayerSet[ i ] is derived as specified in the following: 
-  // LayerSetIdxForOutputLayerSet[ i ] = ( i <= vps_number_layer_sets_minus1 ) ? i : output_layer_set_idx_minus1[ i ] + 1
+  // LayerSetIdxForOutputLayerSet[ i ] = ( i <= vps_number_layer_sets_minus1 ) ? i : layer_set_idx_for_ols_minus1[ i ] + 1
   for( i = 1; i < vps->getNumOutputLayerSets(); i++ )
   {
@@ -1834,8 +1881,6 @@
 Void TDecCavlc::defaultVPSVUI( TComVPS* vps )
 {
-#if N0147_IRAP_ALIGN_FLAG
   // When not present, the value of all_layers_idr_aligned_flag is inferred to be equal to 0.
   vps->setCrossLayerIrapAlignFlag( false );
-#endif
 
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
@@ -1849,5 +1894,4 @@
 #endif
 }
-#endif
 
 #if REPN_FORMAT_IN_VPS
@@ -1918,6 +1962,11 @@
   UInt uiCode;
 #if DPB_PARAMS_MAXTLAYERS
+#if BITRATE_PICRATE_SIGNALLING
+    Int * MaxSubLayersInLayerSetMinus1 = new Int[vps->getNumLayerSets()];
+    for(Int i = 0; i < vps->getNumLayerSets(); i++)
+#else
     Int * MaxSubLayersInLayerSetMinus1 = new Int[vps->getNumOutputLayerSets()];
     for(Int i = 1; i < vps->getNumOutputLayerSets(); i++)
+#endif
     {
         UInt maxSLMinus1 = 0;
@@ -1927,4 +1976,7 @@
         Int optLsIdx = i;
 #endif
+#if BITRATE_PICRATE_SIGNALLING
+        optLsIdx = i;
+#endif
         for(Int k = 0; k < vps->getNumLayersInIdList(optLsIdx); k++ ) {
             Int  lId = vps->getLayerSetLayerIdList(optLsIdx, k);
@@ -1932,4 +1984,7 @@
         }
         MaxSubLayersInLayerSetMinus1[ i ] = maxSLMinus1;
+#if BITRATE_PICRATE_SIGNALLING
+        vps->setMaxSLayersInLayerSetMinus1(i,MaxSubLayersInLayerSetMinus1[ i ]);
+#endif
     }
 #endif
@@ -1945,5 +2000,9 @@
     READ_FLAG( uiCode, "sub_layer_flag_info_present_flag[i]");  vps->setSubLayerFlagInfoPresentFlag( i, uiCode ? true : false );
 #if DPB_PARAMS_MAXTLAYERS
+#if BITRATE_PICRATE_SIGNALLING
+    for(Int j = 0; j <= MaxSubLayersInLayerSetMinus1[ vps->getOutputLayerSetIdx( i ) ]; j++)
+#else
     for(Int j = 0; j <= MaxSubLayersInLayerSetMinus1[ i ]; j++)
+#endif
 #else
     for(Int j = 0; j <= vps->getMaxTLayers(); j++)
@@ -2009,13 +2068,19 @@
       if( !vps->getSubLayerDpbInfoPresentFlag(i, j) )  // If sub-layer DPB information is NOT present
       {
+#if RESOLUTION_BASED_DPB
         for(Int k = 0; k < vps->getNumSubDpbs(layerSetIdxForOutputLayerSet); k++)
+#else
+        for(Int k = 0; k < vps->getNumLayersInIdList( layerSetIdxForOutputLayerSet ); k++)
+#endif
         {
           vps->setMaxVpsDecPicBufferingMinus1( i, k, j, vps->getMaxVpsDecPicBufferingMinus1( i, k, j - 1 ) );
         }
         vps->setMaxVpsNumReorderPics( i, j, vps->getMaxVpsNumReorderPics( i, j - 1) );
+#if RESOLUTION_BASED_DPB
         for(Int k = 0; k < vps->getNumLayersInIdList( layerSetIdxForOutputLayerSet ); k++)
         {
           vps->setMaxVpsLayerDecPicBuffMinus1( i, k, j, vps->getMaxVpsLayerDecPicBuffMinus1( i, k, j - 1));
         }
+#endif
         vps->setMaxVpsLatencyIncreasePlus1( i, j, vps->getMaxVpsLatencyIncreasePlus1( i, j - 1 ) );
       }
@@ -2024,5 +2089,5 @@
 }
 #endif
-#if VPS_VUI
+
 Void TDecCavlc::parseVPSVUI(TComVPS *vps)
 {
@@ -2039,8 +2104,8 @@
     vps->setCrossLayerIrapAlignFlag(uiCode);
 #if P0068_CROSS_LAYER_ALIGNED_IDR_ONLY_FOR_IRAP_FLAG
-    if (uiCode)
-    {
-      READ_FLAG(uiCode, "all_layers_idr_aligned_flag" );
-      vps->setCrossLayerIrapAlignFlag(uiCode);
+    if( uiCode )
+    {
+      READ_FLAG( uiCode, "all_layers_idr_aligned_flag" );
+      vps->setCrossLayerAlignedIdrOnlyFlag(uiCode);
     }
 #endif
@@ -2053,54 +2118,60 @@
   }
 #endif
-#if VPS_VUI_BITRATE_PICRATE
+
   READ_FLAG( uiCode,        "bit_rate_present_vps_flag" );  vps->setBitRatePresentVpsFlag( uiCode ? true : false );
   READ_FLAG( uiCode,        "pic_rate_present_vps_flag" );  vps->setPicRatePresentVpsFlag( uiCode ? true : false );
 
   Bool parseFlag = vps->getBitRatePresentVpsFlag() || vps->getPicRatePresentVpsFlag();
-  {
-    for( i = 0; i < vps->getNumLayerSets(); i++ )
-    {
-      for( j = 0; j < vps->getMaxTLayers(); j++ )
-      {
-        if( parseFlag && vps->getBitRatePresentVpsFlag() )
-        {
-          READ_FLAG( uiCode,        "bit_rate_present_flag[i][j]" );  vps->setBitRatePresentFlag( i, j, uiCode ? true : false );
-        }
-        else
-        {
-          vps->setBitRatePresentFlag( i, j, false );
-        }
-        if( parseFlag && vps->getPicRatePresentVpsFlag() )
-        {
-          READ_FLAG( uiCode,        "pic_rate_present_flag[i][j]" );  vps->setPicRatePresentFlag( i, j, uiCode ? true : false );
-        }
-        else
-        {
-          vps->setPicRatePresentFlag( i, j, false );
-        }
-        if( parseFlag && vps->getBitRatePresentFlag(i, j) )
-        {
-          READ_CODE( 16, uiCode,    "avg_bit_rate[i][j]" ); vps->setAvgBitRate( i, j, uiCode );
-          READ_CODE( 16, uiCode,    "max_bit_rate[i][j]" ); vps->setMaxBitRate( i, j, uiCode );
-        }
-        else
-        {
-          vps->setAvgBitRate( i, j, 0 );
-          vps->setMaxBitRate( i, j, 0 );
-        }
-        if( parseFlag && vps->getPicRatePresentFlag(i, j) )
-        {
-          READ_CODE( 2 , uiCode,    "constant_pic_rate_idc[i][j]" ); vps->setConstPicRateIdc( i, j, uiCode );
-          READ_CODE( 16, uiCode,    "avg_pic_rate[i][j]"          ); vps->setAvgPicRate( i, j, uiCode );
-        }
-        else
-        {
-          vps->setConstPicRateIdc( i, j, 0 );
-          vps->setAvgPicRate     ( i, j, 0 );
-        }
-      }
-    }
-  }
-#endif
+
+#if Q0078_ADD_LAYER_SETS
+  for( i = 0; i <= vps->getVpsNumLayerSetsMinus1(); i++ )
+#else
+  for( i = 0; i < vps->getNumLayerSets(); i++ )
+#endif
+  {
+#if BITRATE_PICRATE_SIGNALLING
+    for( j = 0; j <= vps->getMaxSLayersInLayerSetMinus1(i); j++ )
+#else
+    for( j = 0; j < vps->getMaxTLayers(); j++ )
+#endif
+    {
+      if( parseFlag && vps->getBitRatePresentVpsFlag() )
+      {
+        READ_FLAG( uiCode,        "bit_rate_present_flag[i][j]" );  vps->setBitRatePresentFlag( i, j, uiCode ? true : false );
+      }
+      else
+      {
+        vps->setBitRatePresentFlag( i, j, false );
+      }
+      if( parseFlag && vps->getPicRatePresentVpsFlag() )
+      {
+        READ_FLAG( uiCode,        "pic_rate_present_flag[i][j]" );  vps->setPicRatePresentFlag( i, j, uiCode ? true : false );
+      }
+      else
+      {
+        vps->setPicRatePresentFlag( i, j, false );
+      }
+      if( parseFlag && vps->getBitRatePresentFlag(i, j) )
+      {
+        READ_CODE( 16, uiCode,    "avg_bit_rate[i][j]" ); vps->setAvgBitRate( i, j, uiCode );
+        READ_CODE( 16, uiCode,    "max_bit_rate[i][j]" ); vps->setMaxBitRate( i, j, uiCode );
+      }
+      else
+      {
+        vps->setAvgBitRate( i, j, 0 );
+        vps->setMaxBitRate( i, j, 0 );
+      }
+      if( parseFlag && vps->getPicRatePresentFlag(i, j) )
+      {
+        READ_CODE( 2 , uiCode,    "constant_pic_rate_idc[i][j]" ); vps->setConstPicRateIdc( i, j, uiCode );
+        READ_CODE( 16, uiCode,    "avg_pic_rate[i][j]"          ); vps->setAvgPicRate( i, j, uiCode );
+      }
+      else
+      {
+        vps->setConstPicRateIdc( i, j, 0 );
+        vps->setAvgPicRate     ( i, j, 0 );
+      }
+    }
+  }
 #if VPS_VUI_VIDEO_SIGNAL_MOVE
   READ_FLAG( uiCode, "video_signal_info_idx_present_flag" ); vps->setVideoSigPresentVpsFlag( uiCode == 1 );
@@ -2162,5 +2233,5 @@
     }
 #endif
-#if TILE_BOUNDARY_ALIGNED_FLAG
+
     for(i = 1; i < vps->getMaxLayers(); i++)
     {
@@ -2177,5 +2248,4 @@
       }
     }
-#endif
 #if VPS_VUI_TILES_NOT_IN_USE__FLAG
   }
@@ -2290,7 +2360,14 @@
         parseHrdParameters(vps->getBspHrd(i), i==0 ? 1 : vps->getBspCprmsPresentFlag(i), vps->getMaxTLayers()-1);
       }
+#if Q0078_ADD_LAYER_SETS
+      for (UInt h = 1; h <= vps->getVpsNumLayerSetsMinus1(); h++)
+#else
       for( UInt h = 1; h <= (vps->getNumLayerSets()-1); h++ )
+#endif
       {
         READ_UVLC( uiCode, "num_bitstream_partitions[i]"); vps->setNumBitstreamPartitions(h, uiCode);
+#if HRD_BPB
+        Int chkPart=0;
+#endif
         for( i = 0; i < vps->getNumBitstreamPartitions(h); i++ )
         {
@@ -2302,8 +2379,33 @@
             }
           }
-        }
+#if HRD_BPB
+          chkPart+=vps->getLayerInBspFlag(h, i, j);
+#endif
+        }
+#if HRD_BPB
+        assert(chkPart<=1);
+#endif
+#if HRD_BPB
+        if(vps->getNumBitstreamPartitions(h)==1)
+        {
+          Int chkPartition1=0; Int chkPartition2=0;
+          for( j = 0; j <= (vps->getMaxLayers()-1); j++ )
+          {
+            if( vps->getLayerIdIncludedFlag(h, j) )
+            {
+              chkPartition1+=vps->getLayerInBspFlag(h, 0, j);
+              chkPartition2++;
+            }
+          }
+          assert(chkPartition1!=chkPartition2);
+        }
+#endif
         if (vps->getNumBitstreamPartitions(h))
         {
+#if Q0182_MULTI_LAYER_HRD_UPDATE
+          READ_UVLC( uiCode, "num_bsp_sched_combinations_minus1[h]"); vps->setNumBspSchedCombinations(h, uiCode + 1);
+#else
           READ_UVLC( uiCode, "num_bsp_sched_combinations[h]"); vps->setNumBspSchedCombinations(h, uiCode);
+#endif
           for( i = 0; i < vps->getNumBspSchedCombinations(h); i++ )
           {
@@ -2311,5 +2413,12 @@
             {
               READ_UVLC( uiCode, "bsp_comb_hrd_idx[h][i][j]"); vps->setBspCombHrdIdx(h, i, j, uiCode);
+#if HRD_BPB
+              assert(uiCode <= vps->getVpsNumBspHrdParametersMinus1());
+#endif
+                
               READ_UVLC( uiCode, "bsp_comb_sched_idx[h][i][j]"); vps->setBspCombSchedIdx(h, i, j, uiCode);
+#if HRD_BPB
+              assert(uiCode <= vps->getBspHrdParamBufferCpbCntMinus1(uiCode,vps->getMaxTLayers()-1));
+#endif
             }
           }
@@ -2334,5 +2443,4 @@
 #endif
 }
-#endif
 #endif //SVC_EXTENSION
 
@@ -2412,4 +2520,10 @@
   }
 
+#if Q0142_POC_LSB_NOT_PRESENT
+#if SHM_FIX7
+    Int iPOClsb = 0;
+#endif
+#endif
+
   if(!rpcSlice->getDependentSliceSegmentFlag())
   {
@@ -2484,7 +2598,9 @@
     }
 #if N0065_LAYER_POC_ALIGNMENT
+#if !Q0142_POC_LSB_NOT_PRESENT
 #if SHM_FIX7
     Int iPOClsb = 0;
 #endif
+#endif
 #if O0062_POC_LSB_NOT_PRESENT_FLAG
     if( ( rpcSlice->getLayerId() > 0 && !rpcSlice->getVPS()->getPocLsbNotPresentFlag( rpcSlice->getVPS()->getLayerIdInVps(rpcSlice->getLayerId())) ) || !rpcSlice->getIdrPicFlag())
@@ -2497,4 +2613,7 @@
     {
       READ_CODE(sps->getBitsForPOC(), uiCode, "pic_order_cnt_lsb");
+#if POC_RESET_IDC_DECODER
+      rpcSlice->setPicOrderCntLsb( uiCode );
+#endif
 #if SHM_FIX7
       iPOClsb = uiCode;
@@ -2531,4 +2650,10 @@
 #if SHM_FIX7
       }
+#endif
+#if POC_RESET_IDC_DECODER
+    else
+    {
+      rpcSlice->setPicOrderCntLsb( 0 );
+    }
 #endif
       if( !rpcSlice->getIdrPicFlag() )
@@ -2645,4 +2770,40 @@
         rps->setNumberOfPictures(offset);
       }
+#if DPB_CONSTRAINTS
+          if(rpcSlice->getVPS()->getVpsExtensionFlag()==1)
+          {
+#if Q0078_ADD_LAYER_SETS
+              for (Int ii = 1; ii < (rpcSlice->getVPS()->getVpsNumLayerSetsMinus1() + 1); ii++)  // prevent assert error when num_add_layer_sets > 0
+#else
+              for (Int ii=1; ii< rpcSlice->getVPS()->getNumOutputLayerSets(); ii++ )
+#endif
+              {
+                  Int layerSetIdxForOutputLayerSet = rpcSlice->getVPS()->getOutputLayerSetIdx( ii );
+                  Int chkAssert=0;
+                  for(Int kk = 0; kk < rpcSlice->getVPS()->getNumLayersInIdList(layerSetIdxForOutputLayerSet); kk++)
+                  {
+                      if(rpcSlice->getLayerId()==rpcSlice->getVPS()->getLayerSetLayerIdList(layerSetIdxForOutputLayerSet, kk))
+                      {
+                          chkAssert=1;
+                      }
+                  }
+                  if(chkAssert)
+                  {
+                      // There may be something wrong here (layer id assumed to be layer idx?)
+                      assert(rps->getNumberOfNegativePictures() <= rpcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii , rpcSlice->getLayerId() , rpcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)));
+                      assert(rps->getNumberOfPositivePictures() <= rpcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii , rpcSlice->getLayerId() , rpcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)) - rps->getNumberOfNegativePictures());
+                      assert((rps->getNumberOfPositivePictures() + rps->getNumberOfNegativePictures() + rps->getNumberOfLongtermPictures()) <= rpcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii , rpcSlice->getLayerId() , rpcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)));
+                  }
+              }
+              
+              
+          }
+          if(rpcSlice->getLayerId() == 0)
+          {
+              assert(rps->getNumberOfNegativePictures() <= rpcSlice->getSPS()->getMaxDecPicBuffering(rpcSlice->getSPS()->getMaxTLayers()-1) );
+              assert(rps->getNumberOfPositivePictures() <= rpcSlice->getSPS()->getMaxDecPicBuffering(rpcSlice->getSPS()->getMaxTLayers()-1) -rps->getNumberOfNegativePictures());
+              assert((rps->getNumberOfPositivePictures() + rps->getNumberOfNegativePictures() + rps->getNumberOfLongtermPictures()) <= rpcSlice->getSPS()->getMaxDecPicBuffering(rpcSlice->getSPS()->getMaxTLayers()-1));
+          }
+#endif
       if ( rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
         || rpcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
@@ -2673,13 +2834,5 @@
 #if SVC_EXTENSION
     rpcSlice->setActiveNumILRRefIdx(0);
-#if ILP_SSH_SIG
-#if ILP_SSH_SIG_FIX
     if((rpcSlice->getLayerId() > 0) && !(rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag()) && (rpcSlice->getNumILRRefIdx() > 0) )
-#else
-    if((rpcSlice->getLayerId() > 0) && rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag() && (rpcSlice->getNumILRRefIdx() > 0) )
-#endif
-#else
-    if((rpcSlice->getLayerId() > 0)  &&  (rpcSlice->getNumILRRefIdx() > 0) )
-#endif
     {
       READ_FLAG(uiCode,"inter_layer_pred_enabled_flag");
@@ -2720,5 +2873,5 @@
 #endif 
           }
-#if ILP_NUM_REF_CHK
+
           if( rpcSlice->getActiveNumILRRefIdx() == rpcSlice->getNumILRRefIdx() )
           {
@@ -2730,13 +2883,10 @@
           else
           {
-#endif
-          for(Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
-          {
-            READ_CODE( numBits,uiCode,"inter_layer_pred_layer_idc[i]" );
-            rpcSlice->setInterLayerPredLayerIdc(uiCode,i);
+            for(Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
+            {
+              READ_CODE( numBits,uiCode,"inter_layer_pred_layer_idc[i]" );
+              rpcSlice->setInterLayerPredLayerIdc(uiCode,i);
+            }
           }
-#if ILP_NUM_REF_CHK
-          }
-#endif
         }
         else
@@ -2760,10 +2910,5 @@
       }
     }
-#if ILP_SSH_SIG
-#if ILP_SSH_SIG_FIX
     else if( rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag() == true &&  (rpcSlice->getLayerId() > 0 ))
-#else
-    else if( rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag() == false )
-#endif
     {
       rpcSlice->setInterLayerPredEnabledFlag(true);
@@ -2799,6 +2944,4 @@
 #endif 
     }
-#endif
-#endif
 #if P0312_VERT_PHASE_ADJ
     for(Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ ) 
@@ -2811,4 +2954,5 @@
     }
 #endif
+#endif //SVC_EXTENSION
 
     if(sps->getUseSAO())
@@ -2992,5 +3136,5 @@
 #if SVC_EXTENSION && REF_IDX_MFM
       // set motion mapping flag
-      rpcSlice->setMFMEnabledFlag( ( rpcSlice->getNumMotionPredRefLayers() > 0 && rpcSlice->getActiveNumILRRefIdx() ) ? true : false );
+      rpcSlice->setMFMEnabledFlag( ( rpcSlice->getNumMotionPredRefLayers() > 0 && rpcSlice->getActiveNumILRRefIdx() && !rpcSlice->isIntra() ) ? true : false );
 #endif
       if ( rpcSlice->getSliceType() == B_SLICE )
@@ -3132,15 +3276,15 @@
 
 #if POC_RESET_IDC_SIGNALLING
-  Int sliceHederExtensionLength = 0;
+  Int sliceHeaderExtensionLength = 0;
   if(pps->getSliceHeaderExtensionPresentFlag())
   {
-    READ_UVLC( uiCode, "slice_header_extension_length"); sliceHederExtensionLength = uiCode;
+    READ_UVLC( uiCode, "slice_header_extension_length"); sliceHeaderExtensionLength = uiCode;
   }
   else
   {
-    sliceHederExtensionLength = 0;
+    sliceHeaderExtensionLength = 0;
   }
   UInt startBits = m_pcBitstream->getNumBitsRead();     // Start counter of # SH Extn bits
-  if( sliceHederExtensionLength > 0 )
+  if( sliceHeaderExtensionLength > 0 )
   {
     if( rpcSlice->getPPS()->getPocResetInfoPresentFlag() )
@@ -3152,4 +3296,10 @@
       rpcSlice->setPocResetIdc( 0 );
     }
+#if Q0142_POC_LSB_NOT_PRESENT
+    if ( rpcSlice->getVPS()->getPocLsbNotPresentFlag(rpcSlice->getLayerId()) && iPOClsb > 0 )
+    {
+      assert( rpcSlice->getPocResetIdc() != 2 );
+    }
+#endif
     if( rpcSlice->getPocResetIdc() > 0 )
     {
@@ -3166,4 +3316,10 @@
       READ_FLAG( uiCode,        "full_poc_reset_flag"); rpcSlice->setFullPocResetFlag((uiCode == 1) ? true : false);
       READ_CODE(rpcSlice->getSPS()->getBitsForPOC(), uiCode,"poc_lsb_val"); rpcSlice->setPocLsbVal(uiCode);
+#if Q0142_POC_LSB_NOT_PRESENT
+      if ( rpcSlice->getVPS()->getPocLsbNotPresentFlag(rpcSlice->getLayerId()) && rpcSlice->getFullPocResetFlag() )
+      {
+        assert( rpcSlice->getPocLsbVal() == 0 );
+      }
+#endif
     }
 
@@ -3179,5 +3335,13 @@
     else
     {
+#if POC_MSB_VAL_PRESENT_FLAG_SEM
+      if( sliceHeaderExtensionLength == 0 )
+      {
+        rpcSlice->setPocMsbValPresentFlag( false );
+      }
+      else if( rpcSlice->getPocMsbValRequiredFlag() )
+#else
       if( rpcSlice->getPocMsbValRequiredFlag() )
+#endif
       {
         rpcSlice->setPocMsbValPresentFlag( true );
@@ -3189,8 +3353,12 @@
     }
 
+#if !POC_RESET_IDC_DECODER
     Int maxPocLsb  = 1 << rpcSlice->getSPS()->getBitsForPOC();
+#endif
     if( rpcSlice->getPocMsbValPresentFlag() )
     {
       READ_UVLC( uiCode,    "poc_msb_val");             rpcSlice->setPocMsbVal( uiCode );
+
+#if !POC_RESET_IDC_DECODER
       // Update POC of the slice based on this MSB val
       Int pocLsb     = rpcSlice->getPOC() % maxPocLsb;
@@ -3200,4 +3368,5 @@
     {
       rpcSlice->setPocMsbVal( rpcSlice->getPOC() / maxPocLsb );
+#endif
     }
 
@@ -3212,5 +3381,9 @@
     while( counter )
     {
+#if Q0146_SSH_EXT_DATA_BIT 
+      READ_FLAG( uiCode, "slice_segment_header_extension_data_bit" );
+#else
       READ_FLAG( uiCode, "slice_segment_header_extension_reserved_bit" ); assert( uiCode == 1 );
+#endif
       counter--;
     }
Index: trunk/source/Lib/TLibDecoder/TDecCAVLC.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 713)
+++ trunk/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 815)
@@ -75,14 +75,9 @@
   Void  parseQtRootCbf      ( UInt uiAbsPartIdx, UInt& uiQtRootCbf );
   Void  parseVPS            ( TComVPS* pcVPS );
-#if SPS_EXTENSION
-#if VPS_EXTNS
+#if SVC_EXTENSION
   Void  parseVPSExtension   ( TComVPS* pcVPS );
   Void  defaultVPSExtension ( TComVPS* pcVPS );
-#endif
-
-#if VPS_VUI
-  Void  parseVPSVUI   ( TComVPS* pcVPS );
-  Void  defaultVPSVUI ( TComVPS* pcVPS );
-#endif 
+  Void  parseVPSVUI         ( TComVPS* pcVPS );
+  Void  defaultVPSVUI       ( TComVPS* pcVPS );
 #if REPN_FORMAT_IN_VPS
   Void  parseRepFormat      ( RepFormat *repFormat, RepFormat *repFormatPrev );
Index: trunk/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 713)
+++ trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 815)
@@ -85,4 +85,7 @@
   m_isNoOutputPriorPics = false;
 #endif
+#if Q0177_EOS_CHECKS
+  m_isLastNALWasEos = false;
+#endif
 #if NO_CLRAS_OUTPUT_FLAG
   m_noClrasOutputFlag          = false;
@@ -93,4 +96,9 @@
   m_subDpbIdx = -1;
 #endif
+#if POC_RESET_IDC_DECODER
+  m_parseIdc = -1;
+  m_lastPocPeriodId = -1;
+  m_prevPicOrderCnt = 0;
+#endif
 #if Q0048_CGS_3D_ASYMLUT
   m_pColorMappedPic = NULL;
@@ -104,4 +112,36 @@
 TDecTop::~TDecTop()
 {
+#if Q0078_ADD_LAYER_SETS
+  for (Int psId = 0; psId < MAX_NUM_SPS; psId++)
+  {
+    TComSPS* sps = m_parameterSetManagerDecoder.getSPS(psId);
+    if (sps != NULL)
+    {
+      // Remove parameter set from other layers to prevent multiple deletes of the same object
+      for (Int lId = 0; lId < m_numLayer; lId++)
+      {
+        if (m_ppcTDecTop[lId] != this)
+        {
+          m_parameterSetManagerDecoder.removeSPS(psId);
+        }
+      }
+    }
+  }
+  for (Int psId = 0; psId < MAX_NUM_PPS; psId++)
+  {
+    TComPPS* pps = m_parameterSetManagerDecoder.getPPS(psId);
+    if (pps != NULL)
+    {
+      // Remove parameter set from other layers to prevent multiple deletes of the same object
+      for (Int lId = 0; lId < m_numLayer; lId++)
+      {
+        if (m_ppcTDecTop[lId] != this)
+        {
+          m_parameterSetManagerDecoder.removePPS(psId);
+        }
+      }
+    }
+  }
+#endif
 #if ENC_DEC_TRACE
   fclose( g_hTrace );
@@ -225,31 +265,16 @@
 
         m_cIlpPic[j] = new  TComPic;
+
 #if AUXILIARY_PICTURES
 #if REPN_FORMAT_IN_VPS
-#if SVC_UPSAMPLING
         m_cIlpPic[j]->create(picWidth, picHeight, slice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
 #else
-        m_cIlpPic[j]->create(picWidth, picHeight, slice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
-#endif
-#else
-#if SVC_UPSAMPLING
         m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), pcSPS->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
-#else
-        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), pcSPS->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
-#endif
 #endif
 #else
 #if REPN_FORMAT_IN_VPS
-#if SVC_UPSAMPLING
         m_cIlpPic[j]->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
 #else
-        m_cIlpPic[j]->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
-#endif
-#else
-#if SVC_UPSAMPLING
         m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
-#else
-        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
-#endif
 #endif
 #endif
@@ -393,51 +418,32 @@
 
           //only for scalable extension
-#if SCALABILITY_MASK_E0104
-          assert( pcSlice->getVPS()->getScalabilityMask(2) == true );
-#else
-          assert( pcSlice->getVPS()->getScalabilityMask(1) == true );
-#endif
-        }
-      }
-    }
-#endif
-    
+          assert( pcSlice->getVPS()->getScalabilityMask( SCALABILITY_ID ) == true );
+        }
+      }
+    }
+
 #if AUXILIARY_PICTURES
 #if REPN_FORMAT_IN_VPS
-#if SVC_UPSAMPLING
     rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
                      conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
 #else
-    rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
-                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
-#endif
-#else
-#if SVC_UPSAMPLING
     rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
                      conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
-#else
-    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
-                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
-#endif
 #endif
 #else
 #if REPN_FORMAT_IN_VPS
-#if SVC_UPSAMPLING
     rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
                      conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
 #else
-    rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
-                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
-#endif
-#else
-#if SVC_UPSAMPLING
     rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
                      conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
-#else
+#endif
+#endif
+
+#else //SVC_EXTENSION
     rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
                      conformanceWindow, defaultDisplayWindow, numReorderPics, true);
-#endif
-#endif
-#endif
+#endif //SVC_EXTENSION
+    
     m_cListPic.pushBack( rpcPic );
     
@@ -478,45 +484,27 @@
   rpcPic->destroy();
 
+#if SVC_EXTENSION
 #if AUXILIARY_PICTURES
 #if REPN_FORMAT_IN_VPS
-#if SVC_UPSAMPLING
   rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
                    conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
-
-#else
-  rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
-                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
-#endif
-#else
-#if SVC_UPSAMPLING
+#else
   rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
                    conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
-
-#else
-  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
-                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
-#endif
 #endif
 #else
 #if REPN_FORMAT_IN_VPS
-#if SVC_UPSAMPLING
   rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
                    conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
 
 #else
-  rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
-                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
-#endif
-#else
-#if SVC_UPSAMPLING
   rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
                    conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
-
-#else
+#endif
+#endif
+#else  //SVC_EXTENSION
   rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
                    conformanceWindow, defaultDisplayWindow, numReorderPics, true);
-#endif
-#endif
-#endif
+#endif //SVC_EXTENSION
 }
 
@@ -793,5 +781,4 @@
 
 #if AUXILIARY_PICTURES
-#if SVC_UPSAMPLING
 #if AVC_SYNTAX
       pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), repFormat->getChromaFormatVpsIdc(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, activeSPS, true);
@@ -800,15 +787,8 @@
 #endif
 #else
-      pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), repFormat->getChromaFormatVpsIdc(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, true);
-#endif
-#else
-#if SVC_UPSAMPLING
 #if AVC_SYNTAX
       pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, activeSPS, true);
 #else
       pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, NULL, true);
-#endif
-#else
-      pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), onformanceWindow, defaultDisplayWindow, numReorderPics, true);
 #endif
 #endif
@@ -846,5 +826,9 @@
 
     // When not present sps_temporal_id_nesting_flag is inferred to be equal to vps_temporal_id_nesting_flag
+#if Q0177_SPS_TEMP_NESTING_FIX
+    sps->setTemporalIdNestingFlag( (sps->getMaxTLayers() > 1) ? activeVPS->getTemporalNestingFlag() : true );
+#else
     sps->setTemporalIdNestingFlag( activeVPS->getTemporalNestingFlag() );
+#endif
 
     // When sps_max_dec_pic_buffering_minus1[ i ] is not present for i in the range of 0 to sps_max_sub_layers_minus1, inclusive, due to nuh_layer_id being greater than 0, 
@@ -854,6 +838,9 @@
       // to avoid compiler warning "array subscript is above array bounds"
       assert( i < MAX_TLAYER );
-
+#if LAYER_DECPICBUFF_PARAM && RESOLUTION_BASED_DPB
+      sps->setMaxDecPicBuffering( activeVPS->getMaxVpsLayerDecPicBuffMinus1( getCommonDecoderParams()->getTargetOutputLayerSetIdx(), sps->getLayerId(), i) + 1, i);
+#else
       sps->setMaxDecPicBuffering( activeVPS->getMaxVpsDecPicBufferingMinus1( getCommonDecoderParams()->getTargetOutputLayerSetIdx(), sps->getLayerId(), i) + 1, i);
+#endif
     }
   }
@@ -1122,12 +1109,210 @@
   }
 #endif
+#if POC_RESET_IDC_DECODER
+  if( m_parseIdc != -1 ) // Second pass for a POC resetting picture
+  {
+    m_parseIdc++; // Proceed to POC decoding and RPS derivation
+  }
+  
+  if( m_parseIdc == 2 )
+  {
+    bNewPOC = false;
+  }
+
+  if( (bNewPOC || m_layerId!=m_uiPrevLayerId) && (m_parseIdc == -1) ) // Will be true at the first pass
+  {
+  //if (bNewPOC || m_layerId!=m_uiPrevLayerId)
+  // Check if new reset period has started - this is needed just so that the SHM decoder which calls slice header decoding twice 
+  // does not invoke the output twice
+  //if( m_lastPocPeriodId[m_apcSlicePilot->getLayerId()] == m_apcSlicePilot->getPocResetPeriodId() )
+    // Update CurrAU marking
+    if(( m_layerId < m_uiPrevLayerId) ||( ( m_layerId == m_uiPrevLayerId) && bNewPOC)) // Decoding a lower layer than or same layer as previous - mark all earlier pictures as not in current AU
+    {
+      markAllPicsAsNoCurrAu();
+    }
+
+    if( m_apcSlicePilot->getPocResetIdc() && m_apcSlicePilot->getSliceIdx() == 0 )
+    {
+      Int pocResetPeriodId = m_apcSlicePilot->getPocResetPeriodId();
+      if ( m_apcSlicePilot->getPocResetIdc() == 1 || m_apcSlicePilot->getPocResetIdc() == 2 ||
+        ( m_apcSlicePilot->getPocResetIdc() == 3 && pocResetPeriodId != getLastPocPeriodId() ) )
+      {
+        setLastPocPeriodId(pocResetPeriodId);
+        m_parseIdc = 0;
+      }
+    }
+    else
+    {
+      m_parseIdc = 3; // Proceed to decoding POC and RPS
+    }  
+  }
+#endif
 
 #if ALIGNED_BUMPING
+#if POC_RESET_IDC_DECODER
+  //if(  (bNewPOC || m_layerId != m_uiPrevLayerId) && ( m_parseIdc != 1) )
+  if( m_parseIdc == 1 )
+  {
+    // Invoke output of pictures if the current picture is a POC reset picture
+    bNewPOC = true;
+    /* Include reset of all POCs in the layer */
+
+  // This operation would do the following:
+  // 1. Update the other picture in the DPB. This should be done only for the first slice of the picture.
+  // 2. Update the value of m_pocCRA.
+  // 3. Reset the POC values at the decoder for the current picture to be zero - will be done later
+  // 4. update value of POCLastDisplay
+      
+  //Do the reset stuff here
+    Int maxPocLsb = 1 << m_apcSlicePilot->getSPS()->getBitsForPOC();
+    Int pocLsbVal;
+    if( m_apcSlicePilot->getPocResetIdc() == 3 )
+    {
+      pocLsbVal = m_apcSlicePilot->getPocLsbVal() ;
+    }
+    else
+    {
+      pocLsbVal = (m_apcSlicePilot->getPOC() % maxPocLsb);
+    }
+
+    Int pocMsbDelta = 0;
+    if ( m_apcSlicePilot->getPocMsbValPresentFlag() ) 
+    {
+      pocMsbDelta = m_apcSlicePilot->getPocMsbVal() * maxPocLsb;
+    }
+    else
+    {
+      //This MSB derivation can be made into one function. Item to do next.
+      Int prevPoc     = this->getPrevPicOrderCnt();
+      Int prevPocLsb  = prevPoc & (maxPocLsb - 1);
+      Int prevPocMsb  = prevPoc - prevPocLsb;
+
+      pocMsbDelta = m_apcSlicePilot->getCurrMsb( pocLsbVal, prevPocLsb, prevPocMsb, maxPocLsb );
+    }
+
+    Int pocLsbDelta;
+    if( m_apcSlicePilot->getPocResetIdc() == 2 ||  ( m_apcSlicePilot->getPocResetIdc() == 3 && m_apcSlicePilot->getFullPocResetFlag() ))
+    {
+      pocLsbDelta = pocLsbVal;
+    }
+    else
+    {
+      pocLsbDelta = 0; 
+    }
+
+    Int deltaPocVal  =  pocMsbDelta + pocLsbDelta;
+
+    //Reset all POC for DPB -> basically do it for each slice in the picutre
+    TComList<TComPic*>::iterator  iterPic = m_cListPic.begin();  
+
+    // Iterate through all picture in DPB
+    while( iterPic != m_cListPic.end() )
+    {
+      TComPic *dpbPic = *iterPic;
+      // Check if the picture pointed to by iterPic is either used for reference or
+      // needed for output, are in the same layer, and not the current picture.
+      if( /*  ( ( dpbPic->getSlice(0)->isReferenced() ) || ( dpbPic->getOutputMark() ) )
+          &&*/ ( dpbPic->getLayerId() == m_apcSlicePilot->getLayerId() )
+            && ( dpbPic->getReconMark() ) && ( dpbPic->getPicSym()->getSlice(0)->getPicOutputFlag() ))
+      {
+        for(Int i = dpbPic->getNumAllocatedSlice()-1; i >= 0; i--)
+        {
+
+          TComSlice *slice = dpbPic->getSlice(i);
+          TComReferencePictureSet *rps = slice->getRPS();
+          slice->setPOC( slice->getPOC() - deltaPocVal );
+
+          // Also adjust the POC value stored in the RPS of each such slice
+          for(Int j = rps->getNumberOfPictures(); j >= 0; j--)
+          {
+            rps->setPOC( j, rps->getPOC(j) - deltaPocVal );
+          }
+          // Also adjust the value of refPOC
+          for(Int k = 0; k < 2; k++)  // For List 0 and List 1
+          {
+            RefPicList list = (k == 1) ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
+            for(Int j = 0; j < slice->getNumRefIdx(list); j++)
+            {
+              slice->setRefPOC( slice->getRefPOC(list, j) - deltaPocVal, list, j);
+            }
+          }
+        }
+      }
+      iterPic++;
+    }
+    // Update the value of pocCRA
+    m_pocCRA -= deltaPocVal;
+
+    // Update value of POCLastDisplay
+    iPOCLastDisplay -= deltaPocVal;
+  }
+  Int maxPocLsb = 1 << m_apcSlicePilot->getSPS()->getBitsForPOC();
+  Int slicePicOrderCntLsb = m_apcSlicePilot->getPicOrderCntLsb();
+
+  if( m_parseIdc == 1 || m_parseIdc == 2 ) // TODO This should be replaced by pocResettingFlag.
+  {
+    // Set poc for current slice
+    if( m_apcSlicePilot->getPocResetIdc() == 1 )
+    {        
+      m_apcSlicePilot->setPOC( slicePicOrderCntLsb );
+    }
+    else if( m_apcSlicePilot->getPocResetIdc() == 2 )
+    {
+      m_apcSlicePilot->setPOC( 0 );
+    }
+    else 
+    {
+      Int picOrderCntMsb = m_apcSlicePilot->getCurrMsb( slicePicOrderCntLsb, m_apcSlicePilot->getFullPocResetFlag() ? 0 : m_apcSlicePilot->getPocLsbVal(), 0 , maxPocLsb );
+      m_apcSlicePilot->setPOC( picOrderCntMsb + slicePicOrderCntLsb );
+    }
+  }
+  else if (m_parseIdc == 3)
+  {
+    Int picOrderCntMsb = 0;
+    if( m_apcSlicePilot->getPocMsbValPresentFlag() )
+    {
+      picOrderCntMsb = m_apcSlicePilot->getPocMsbVal() * maxPocLsb;
+    }
+    else if( m_apcSlicePilot->getIdrPicFlag() )
+    {
+      picOrderCntMsb = 0;
+    }
+    else
+    {
+      Int prevPicOrderCntLsb = this->getPrevPicOrderCnt() & ( maxPocLsb - 1);
+      Int prevPicOrderCntMsb  = this->getPrevPicOrderCnt() - prevPicOrderCntLsb;
+      picOrderCntMsb = m_apcSlicePilot->getCurrMsb(slicePicOrderCntLsb, prevPicOrderCntLsb, prevPicOrderCntMsb, maxPocLsb );
+    }
+    m_apcSlicePilot->setPOC( picOrderCntMsb + slicePicOrderCntLsb );
+  }
+
+  if( m_parseIdc == 1 || m_parseIdc == 3)
+  {
+    // Adjust prevPicOrderCnt
+    if(    !m_apcSlicePilot->getRaslPicFlag() 
+        && !m_apcSlicePilot->getRadlPicFlag()
+        && (m_apcSlicePilot->getNalUnitType() % 2 == 1)
+        && ( nalu.m_temporalId == 0 )
+        && !m_apcSlicePilot->getDiscardableFlag() )
+    {
+      this->setPrevPicOrderCnt( m_apcSlicePilot->getPOC() );
+    }
+    else if ( m_apcSlicePilot->getPocResetIdc() == 3 )
+    {
+      this->setPrevPicOrderCnt( m_apcSlicePilot->getFullPocResetFlag() 
+                                            ? 0 : m_apcSlicePilot->getPocLsbVal() );
+    }
+#else
   if (bNewPOC || m_layerId!=m_uiPrevLayerId)
   {
+#endif
     m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
   }
 #endif
+#if POC_RESET_IDC_DECODER
+  if (m_apcSlicePilot->isNextSlice() && (bNewPOC || m_layerId!=m_uiPrevLayerId || m_parseIdc == 1) && !m_bFirstSliceInSequence )
+#else
   if (m_apcSlicePilot->isNextSlice() && (bNewPOC || m_layerId!=m_uiPrevLayerId) && !m_bFirstSliceInSequence )
+#endif
   {
     m_prevPOC = m_apcSlicePilot->getPOC();
@@ -1136,36 +1321,12 @@
     return true;
   }
-#else
-  //we should only get a different poc for a new picture (with CTU address==0)
-  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (m_apcSlicePilot->getSliceCurStartCUAddr()!=0))
-  {
-    printf ("Warning, the first slice of a picture might have been lost!\n");
-  }
-  // exit when a new picture is found
-  if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence )
-  {
-    if (m_prevPOC >= m_pocRandomAccess)
-    {
-      m_prevPOC = m_apcSlicePilot->getPOC();
-      return true;
-    }
-    m_prevPOC = m_apcSlicePilot->getPOC();
-  }
-#endif
+
+#if POC_RESET_IDC_DECODER
+  m_parseIdc = -1;
+#endif
+
   // actual decoding starts here
-  xActivateParameterSets();
-#if !O0223_O0139_IRAP_ALIGN_NO_CONTRAINTS && N0147_IRAP_ALIGN_FLAG
-  //Note setting O0223_O0139_IRAP_ALIGN_NO_CONTRAINTS to 0 may cause decoder to crash.
-  //When cross_layer_irap_aligned_flag is equal to 0, num_extra_slice_header_bits >=1 
-  if(!m_apcSlicePilot->getVPS()->getCrossLayerIrapAlignFlag() )
-  {
-    assert( m_apcSlicePilot->getPPS()->getNumExtraSliceHeaderBits() > 0);
-  }
-  //When cross_layer_irap_aligned_flag is equal to 1, the value of poc_reset_flag shall be equal to 0  
-  if( m_apcSlicePilot->getVPS()->getCrossLayerIrapAlignFlag() )
-  {
-    assert( m_apcSlicePilot->getPocResetFlag() == 0);
-  }
-#endif 
+    xActivateParameterSets();
+
 #if REPN_FORMAT_IN_VPS
   // Initialize ILRP if needed, only for the current layer  
@@ -1177,8 +1338,6 @@
   {
     m_prevPOC = m_apcSlicePilot->getPOC();
-#if SVC_EXTENSION
     curLayerId = m_layerId;
     m_uiPrevLayerId = m_layerId;
-#endif
   }
   m_bFirstSliceInSequence = false;
@@ -1249,5 +1408,6 @@
   }
 #endif
-#if ALIGN_TSA_STSA_PICS
+  // Alignment of TSA and STSA pictures across AU
+#if !Q0108_TSA_STSA
   if( m_apcSlicePilot->getLayerId() > 0 )
   {
@@ -1287,4 +1447,31 @@
   }
 #endif
+
+#else //SVC_EXTENSION
+  //we should only get a different poc for a new picture (with CTU address==0)
+  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (m_apcSlicePilot->getSliceCurStartCUAddr()!=0))
+  {
+    printf ("Warning, the first slice of a picture might have been lost!\n");
+  }
+  // exit when a new picture is found
+  if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence )
+  {
+    if (m_prevPOC >= m_pocRandomAccess)
+    {
+      m_prevPOC = m_apcSlicePilot->getPOC();
+      return true;
+    }
+    m_prevPOC = m_apcSlicePilot->getPOC();
+  }
+
+  // actual decoding starts here
+  xActivateParameterSets();
+
+  if (m_apcSlicePilot->isNextSlice()) 
+  {
+    m_prevPOC = m_apcSlicePilot->getPOC();
+  }
+  m_bFirstSliceInSequence = false;
+#endif //SVC_EXTENSION
   //detect lost reference picture and insert copy of earlier frame.
   Int lostPoc;
@@ -1301,45 +1488,102 @@
       pBLPic->getSlice(0)->setReferenced(true);
       fstream* pFile  = m_ppcTDecTop[0]->getBLReconFile();
-      UInt uiWidth    = pBLPic->getPicYuvRec()->getWidth();
-      UInt uiHeight   = pBLPic->getPicYuvRec()->getHeight();
 
       if( pFile->good() )
       {
+        Bool is16bit  = g_bitDepthYLayer[0] > 8 || g_bitDepthCLayer[0] > 8;
+        UInt uiWidth  = pBLPic->getPicYuvRec()->getWidth();
+        UInt uiHeight = pBLPic->getPicYuvRec()->getHeight();
+
+        Int len = uiWidth * (is16bit ? 2 : 1);
+        UChar *buf = new UChar[len];
+
         UInt64 uiPos = (UInt64) m_apcSlicePilot->getPOC() * uiWidth * uiHeight * 3 / 2;
+        if( is16bit )
+        {
+            uiPos <<= 1;
+        }
 
         pFile->seekg((UInt)uiPos, ios::beg );
 
+        // read Y component
         Pel* pPel = pBLPic->getPicYuvRec()->getLumaAddr();
         UInt uiStride = pBLPic->getPicYuvRec()->getStride();
         for( Int i = 0; i < uiHeight; i++ )
         {
-          for( Int j = 0; j < uiWidth; j++ )
+          pFile->read(reinterpret_cast<Char*>(buf), len);
+
+          if( !is16bit )
           {
-            pPel[j] = pFile->get();
+            for (Int x = 0; x < uiWidth; x++)
+            {
+              pPel[x] = buf[x];
+            }
           }
+          else
+          {
+            for (Int x = 0; x < uiWidth; x++)
+            {
+              pPel[x] = (buf[2*x+1] << 8) | buf[2*x];
+            }
+          }
+     
           pPel += uiStride;
         }
 
+        len >>= 1;
+        uiWidth >>= 1;
+        uiHeight >>= 1;
+
+        // read Cb component
         pPel = pBLPic->getPicYuvRec()->getCbAddr();
         uiStride = pBLPic->getPicYuvRec()->getCStride();
-        for( Int i = 0; i < uiHeight/2; i++ )
-        {
-          for( Int j = 0; j < uiWidth/2; j++ )
+        for( Int i = 0; i < uiHeight; i++ )
+        {
+          pFile->read(reinterpret_cast<Char*>(buf), len);
+
+          if( !is16bit )
           {
-            pPel[j] = pFile->get();
+            for( Int x = 0; x < uiWidth; x++ )
+            {
+              pPel[x] = buf[x];
+            }
           }
+          else
+          {
+            for( Int x = 0; x < uiWidth; x++ )
+            {
+              pPel[x] = (buf[2*x+1] << 8) | buf[2*x];
+            }
+          }
+     
           pPel += uiStride;
         }
 
+        // read Cr component
         pPel = pBLPic->getPicYuvRec()->getCrAddr();
         uiStride = pBLPic->getPicYuvRec()->getCStride();
-        for( Int i = 0; i < uiHeight/2; i++ )
-        {
-          for( Int j = 0; j < uiWidth/2; j++ )
+        for( Int i = 0; i < uiHeight; i++ )
+        {
+          pFile->read(reinterpret_cast<Char*>(buf), len);
+
+          if( !is16bit )
           {
-            pPel[j] = pFile->get();
+            for( Int x = 0; x < uiWidth; x++ )
+            {
+              pPel[x] = buf[x];
+            }
           }
+          else
+          {
+            for( Int x = 0; x < uiWidth; x++ )
+            {
+              pPel[x] = (buf[2*x+1] << 8) | buf[2*x];
+            }
+          }
+     
           pPel += uiStride;
         }
+
+        delete[] buf;
       }
     }
@@ -1365,4 +1609,8 @@
     //  Get a new picture buffer
     xGetNewPicBuffer (m_apcSlicePilot, pcPic);
+
+#if POC_RESET_IDC_DECODER
+  pcPic->setCurrAuFlag( true );
+#endif
 
     Bool isField = false;
@@ -1543,6 +1791,7 @@
       {
         UInt refLayerIdc = i;
+        UInt refLayerId = pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc);
 #if AVC_BASE
-        if( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getAvcBaseLayerFlag() )
+        if( refLayerId == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getAvcBaseLayerFlag() )
         {          
           TComPic* pic = *m_ppcTDecTop[0]->getListPic()->begin();
@@ -1593,5 +1842,5 @@
 
 #if O0098_SCALED_REF_LAYER_ID
-        const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc));
+        const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(refLayerId);
 #else
         const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
@@ -1627,19 +1876,22 @@
         }
 #endif
-#if SVC_UPSAMPLING
+#if SVC_EXTENSION
         if( pcPic->isSpatialEnhLayer(refLayerIdc) )
-        {    
+        {
+          // check for the sample prediction picture type
+          if( m_ppcTDecTop[m_layerId]->getSamplePredEnabledFlag(refLayerId) )
+          {
 #if O0215_PHASE_ALIGNMENT
 #if O0194_JOINT_US_BITSHIFT
 #if Q0048_CGS_3D_ASYMLUT 
-          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getVPS()->getPhaseAlignFlag() );
-#else
-          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getVPS()->getPhaseAlignFlag() );
+            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getVPS()->getPhaseAlignFlag() );
+#else
+            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getVPS()->getPhaseAlignFlag() );
 #endif
 #else
 #if Q0048_CGS_3D_ASYMLUT 
-          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
-#else
-          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
+            m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
+#else
+            m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
 #endif
 #endif
@@ -1647,16 +1899,17 @@
 #if O0194_JOINT_US_BITSHIFT
 #if Q0048_CGS_3D_ASYMLUT 
-          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
-#else
-          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
+            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
+#else
+            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
 #endif
 #else
 #if Q0048_CGS_3D_ASYMLUT 
-          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
-#else
-          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
-#endif
-#endif
-#endif
+            m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
+#else
+            m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
+#endif
+#endif
+#endif
+          }
         }
         else
@@ -1665,5 +1918,5 @@
         }
         pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) );
-#endif
+#endif //SVC_EXTENSION
       }
     }
@@ -1732,5 +1985,10 @@
     if( pcSlice->getMFMEnabledFlag() )
     {
-      Int refLayerId = pcSlice->getRefPic( pcSlice->getSliceType() == B_SLICE ? ( RefPicList )( 1 - pcSlice->getColFromL0Flag() ) : REF_PIC_LIST_0 , pcSlice->getColRefIdx() )->getLayerId();
+      TComPic* refPic = pcSlice->getRefPic( pcSlice->getSliceType() == B_SLICE ? ( RefPicList )( 1 - pcSlice->getColFromL0Flag() ) : REF_PIC_LIST_0 , pcSlice->getColRefIdx() );
+
+      assert( refPic );
+
+      Int refLayerId = refPic->getLayerId();
+
       if( refLayerId != pcSlice->getLayerId() )
       {
@@ -1742,5 +2000,4 @@
 #endif
     
-#if N0147_IRAP_ALIGN_FLAG
     if( m_layerId > 0 && pcSlice->getVPS()->getCrossLayerIrapAlignFlag() )
     {
@@ -1758,5 +2015,18 @@
       }
     }
-#endif 
+
+    if( m_layerId > 0 && !pcSlice->isIntra() && pcSlice->getEnableTMVPFlag() )
+    {
+      TComPic* refPic = pcSlice->getRefPic(RefPicList(1 - pcSlice->getColFromL0Flag()), pcSlice->getColRefIdx());
+
+      assert( refPic );
+
+      // It is a requirement of bitstream conformance when the collocated picture, used for temporal motion vector prediction, is an inter-layer reference picture, 
+      // VpsInterLayerMotionPredictionEnabled[ LayerIdxInVps[ currLayerId ] ][ LayerIdxInVps[ rLId ] ] shall be equal to 1, where rLId is set equal to nuh_layer_id of the inter-layer picture.
+      if( refPic->isILR(pcSlice->getLayerId()) )
+      {
+        assert( m_ppcTDecTop[m_layerId]->getMotionPredEnabledFlag(refPic->getLayerId()) );
+      }
+    }
 #endif //SVC_EXTENSION
     
@@ -1856,4 +2126,14 @@
 #endif
   m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
+#if Q0078_ADD_LAYER_SETS
+  // Store SPS for all layers
+  for (Int lId = 0; lId < m_numLayer; lId++)
+  {
+    if (m_ppcTDecTop[lId] != this)
+    {
+      m_ppcTDecTop[lId]->getParameterSetManager()->storePrefetchedSPS(sps);
+    }
+  }
+#endif
 #if !REPN_FORMAT_IN_VPS   // ILRP can only be initialized at activation  
   if(m_numLayer>0)
@@ -1886,4 +2166,14 @@
     );
   m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
+#if Q0078_ADD_LAYER_SETS
+  // Store PPS for all layers
+  for (Int lId = 0; lId < m_numLayer; lId++)
+  {
+    if (m_ppcTDecTop[lId] != this)
+    {
+      m_ppcTDecTop[lId]->getParameterSetManager()->storePrefetchedPPS(pps);
+    }
+  }
+#endif
 
   if( pps->getDependentSliceSegmentsEnabledFlag() )
@@ -1906,10 +2196,8 @@
   if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
   {
-#if RANDOM_ACCESS_SEI_FIX
     if (m_prevSliceSkipped) // No need to decode SEI messages of a skipped access unit
     {
       return;
     }
-#endif
 #if LAYERS_NOT_PRESENT_SEI
     m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
@@ -1991,8 +2279,11 @@
   {
     case NAL_UNIT_VPS:
-#if VPS_NUH_LAYER_ID
+#if SVC_EXTENSION
       assert( nalu.m_layerId == 0 ); // Non-conforming bitstream. The value of nuh_layer_id of VPS NAL unit shall be equal to 0.
 #endif
       xDecodeVPS();
+#if Q0177_EOS_CHECKS
+      m_isLastNALWasEos = false;
+#endif
 #if AVC_BASE
       if( m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
@@ -2033,4 +2324,10 @@
     case NAL_UNIT_PREFIX_SEI:
     case NAL_UNIT_SUFFIX_SEI:
+#if Q0177_EOS_CHECKS
+      if ( nalu.m_nalUnitType == NAL_UNIT_SUFFIX_SEI )
+      {
+        assert( m_isLastNALWasEos == false );
+      }
+#endif
       xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
       return false;
@@ -2052,4 +2349,18 @@
     case NAL_UNIT_CODED_SLICE_RASL_N:
     case NAL_UNIT_CODED_SLICE_RASL_R:
+#if Q0177_EOS_CHECKS
+      if (nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_N ||
+          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_N ||
+          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_N ||
+          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
+          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N )
+      {
+        assert( m_isLastNALWasEos == false );
+      }
+      else
+      {
+        m_isLastNALWasEos = false;
+      }
+#endif
 #if SVC_EXTENSION
       return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, curLayerId, bNewPOC);
@@ -2060,4 +2371,14 @@
       
     case NAL_UNIT_EOS:
+#if Q0177_EOS_CHECKS
+      assert( m_isLastNALWasEos == false );
+      //Check layer id of the nalu. if it is not 0, give a warning message and just return without doing anything.
+      if (nalu.m_layerId > 0)
+      {
+        printf( "\nThis bitstream has EOS with non-zero layer id.\n" );
+        return false;
+      }
+      m_isLastNALWasEos = true;
+#endif
       m_associatedIRAPType = NAL_UNIT_INVALID;
       m_pocCRA = 0;
@@ -2085,4 +2406,7 @@
       
     case NAL_UNIT_FILLER_DATA:
+#if Q0177_EOS_CHECKS
+      assert( m_isLastNALWasEos == false );
+#endif
       return false;
       
@@ -2256,6 +2580,7 @@
     }
   }
-  for ( Int i = 1, mIdx = 0, sIdx = 0; i < m_numLayer; i++ )
-  {
+  for( Int i = 1; i < m_numLayer; i++ )
+  {
+    Int mIdx = 0, sIdx = 0;
     Int iNuhLId = vps->getLayerIdInNuh(i);
     TDecTop *decTop = (TDecTop *)getLayerDec(iNuhLId);
@@ -2392,5 +2717,20 @@
 }
 #endif
-
+#if POC_RESET_IDC_DECODER
+Void TDecTop::markAllPicsAsNoCurrAu()
+{
+  for(Int i = 0; i < MAX_LAYERS; i++)
+  {
+    TComList<TComPic*>* listPic = this->getLayerDec(i)->getListPic();
+    TComList<TComPic*>::iterator  iterPic = listPic->begin();
+    while ( iterPic != listPic->end() )
+    {
+      TComPic *pcPic = *(iterPic);
+      pcPic->setCurrAuFlag( false );
+      iterPic++;
+    }
+  }
+}
+#endif
 #if Q0048_CGS_3D_ASYMLUT
 Void TDecTop::initAsymLut(TComSlice *pcSlice)
Index: trunk/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecTop.h	(revision 713)
+++ trunk/source/Lib/TLibDecoder/TDecTop.h	(revision 815)
@@ -162,4 +162,7 @@
   Bool                    m_craNoRaslOutputFlag;    //value of variable NoRaslOutputFlag of the last CRA pic
 #endif
+#if Q0177_EOS_CHECKS
+  Bool                    m_isLastNALWasEos;
+#endif
 
 #if SVC_EXTENSION
@@ -201,4 +204,9 @@
   Bool                    m_firstPicInLayerDecodedFlag;
 #endif
+#if POC_RESET_IDC_DECODER
+  Int                     m_parseIdc;
+  Int                     m_lastPocPeriodId;
+  Int                     m_prevPicOrderCnt;
+#endif
 #if RESOLUTION_BASED_DPB
   Int                     m_subDpbIdx;     // Index to the sub-DPB that the layer belongs to.
@@ -241,4 +249,15 @@
 #if EARLY_REF_PIC_MARKING
   Void earlyPicMarking(Int maxTemporalLayer, std::vector<Int>& targetDecLayerIdList);
+#endif
+#if POC_RESET_IDC_DECODER
+  Int getParseIdc() { return m_parseIdc;}
+  Void        setParseIdc(Int x) { m_parseIdc = x;}
+  Void        markAllPicsAsNoCurrAu();
+
+  Int   getLastPocPeriodId() { return m_lastPocPeriodId; }
+  Void  setLastPocPeriodId(Int x)    { m_lastPocPeriodId = x; }
+
+  Int   getPrevPicOrderCnt() { return m_prevPicOrderCnt; }
+  Void  setPrevPicOrderCnt(Int const x) { m_prevPicOrderCnt = x; }
 #endif
   UInt      getLayerId            () { return m_layerId;              }
