Index: branches/HTM-12.0-dev0/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- branches/HTM-12.0-dev0/source/Lib/TLibCommon/TComSlice.cpp	(revision 1052)
+++ branches/HTM-12.0-dev0/source/Lib/TLibCommon/TComSlice.cpp	(revision 1053)
@@ -103,4 +103,7 @@
 , m_temporalLayerNonReferenceFlag ( false )
 , m_enableTMVPFlag                ( true )
+#if I0044_SLICE_TMVP
+, m_availableForTMVPRefFlag       ( true )
+#endif
 #if H_MV
 , m_refPicSetInterLayer0           ( NULL )
Index: branches/HTM-12.0-dev0/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- branches/HTM-12.0-dev0/source/Lib/TLibCommon/TComSlice.h	(revision 1052)
+++ branches/HTM-12.0-dev0/source/Lib/TLibCommon/TComSlice.h	(revision 1053)
@@ -996,4 +996,7 @@
   Void    setLayerSetIdxForOlsMinus1( Int outLayerSetIdx, Int val )        { m_layerSetIdxForOlsMinus1[ outLayerSetIdx ]  = val; } 
   Int     getLayerSetIdxForOlsMinus1( Int outLayerSetIdx )                 { return m_layerSetIdxForOlsMinus1[ outLayerSetIdx ]; } 
+#if VPS_MISC_UPDATES
+  Int     getLayerSetIdxForOlsMinus1Len( Int outLayerSetIdx )              { return gCeilLog2( m_layerSetIdxForOlsMinus1[ outLayerSetIdx ] + 1 ); } 
+#endif
 
   Void    setOutputLayerFlag( Int outLayerSetIdx, Int i, Bool flag )       { m_outputLayerFlag[ outLayerSetIdx ][ i ] = flag; } 
@@ -2195,4 +2198,8 @@
 
   Bool       m_enableTMVPFlag;
+#if I0044_SLICE_TMVP
+  Bool       m_availableForTMVPRefFlag;
+#endif
+
 #if H_MV
   std::vector<TComPic*>* m_refPicSetInterLayer0; 
@@ -2527,4 +2534,8 @@
   Void      setEnableTMVPFlag     ( Bool   b )    { m_enableTMVPFlag = b; }
   Bool      getEnableTMVPFlag     ()              { return m_enableTMVPFlag;}
+#if I0044_SLICE_TMVP
+  Void      setAvailableForTMVPRefFlag     ( Bool   b )    { m_availableForTMVPRefFlag = b; }
+  Bool      getAvailableForTMVPRefFlag     ()              { return m_availableForTMVPRefFlag;}
+#endif
 
 #if H_MV
Index: branches/HTM-12.0-dev0/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- branches/HTM-12.0-dev0/source/Lib/TLibCommon/TypeDef.h	(revision 1052)
+++ branches/HTM-12.0-dev0/source/Lib/TLibCommon/TypeDef.h	(revision 1053)
@@ -382,5 +382,12 @@
 
 //Added by Qualcomm for HLS
-#define DISCARDABLE_PIC_RPS        1      ///< JCTVC-G0131: Inter-layer RPS and temporal RPS should not contain picture with discardable_flag equal to 1
+#define DISCARDABLE_PIC_RPS              1      ///< JCT3V-G0131: Inter-layer RPS and temporal RPS should not contain picture with discardable_flag equal to 1
+#define VPS_MISC_UPDATES                 1      ///< Misc updates:JCT3V-0240, 
+#define NON_REF_NAL_TYPE_DISCARDABLE     1      ///< JCT3V-G0031: If discardable picture is a non-IRAP, it must be a non-referenced sub-layer picture
+#define INFERENCE_POC_MSB_VAL_PRESENT    1      ///< JCT3V-H0042: poc_msb_val_present_flag shall be equal to 0 when slice_header_extension_length is (inferred to be ) equal to 0
+#define INFERENCE_POC_RESET_INFO_PRESENT 1      ///< JCT3V-H0042: Infer the value of poc_reset_info_present_flag to be equal to 0 when no pps extension / pps extension for multilayer.
+#define I0044_SLICE_TMVP                 1      ///< JCT3V-I0044: Regarding slice_temporal_mvp_enabled_flag
+#define I0045_BR_PR_ADD_LAYER_SET        1      ///< JCT3V-I0045: Signalling of bit-rate and picture rate for additional layer set
+#define I0045_VPS_VUI_VST_PARAMS         1      ///< JCT3V-I0045: Related to signalling of VST parameters of the base layer.
 
 // TBD: Check if integration is necessary. 
Index: branches/HTM-12.0-dev0/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- branches/HTM-12.0-dev0/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 1052)
+++ branches/HTM-12.0-dev0/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 1053)
@@ -392,4 +392,7 @@
       READ_FLAG( uiCode, "pps_extension_reserved_zero_flag" );
     }
+#if INFERENCE_POC_RESET_INFO_PRESENT
+    pcPPS->setPocResetInfoPresentFlag( false );
+#endif
 #if !H_3D
     if ( pcPPS->getPpsExtension6bits() )
@@ -414,4 +417,13 @@
 #endif
   }
+#if INFERENCE_POC_RESET_INFO_PRESENT
+  else
+  {
+    pcPPS->setPpsRangeExtensionsFlag( false );
+    pcPPS->setPpsMultilayerExtensionFlag( false );
+    pcPPS->setPps3dExtensionFlag( false );
+    pcPPS->setPocResetInfoPresentFlag( false );
+  }
+#endif
 }
 
@@ -1274,4 +1286,19 @@
     }
   }
+
+#if VPS_MISC_UPDATES   //These codes are moved from below
+  if ( pcVPS->getNumIndependentLayers() > 1 ) 
+  {
+   READ_UVLC( uiCode, "num_add_layer_sets"      ); pcVPS->setNumAddLayerSets( uiCode );
+  }
+  for (Int i = 0; i < pcVPS->getNumAddLayerSets(); i++)
+  {
+    for (Int j = 0; j < pcVPS->getNumIndependentLayers(); j++)
+    {
+      READ_CODE( pcVPS->getHighestLayerIdxPlus1Len( j ) , uiCode, "highest_layer_idx_plus1" ); pcVPS->setHighestLayerIdxPlus1( i, j, uiCode );
+    }
+  }
+#endif
+
   pcVPS->setRefLayers(); 
   READ_FLAG( uiCode, "vps_sub_layers_max_minus1_present_flag" ); pcVPS->setVpsSubLayersMaxMinus1PresentFlag( uiCode == 1 );
@@ -1322,4 +1349,5 @@
   }
 
+#if !VPS_MISC_UPDATES   //These codes are moved to earlier position.
   if ( pcVPS->getNumIndependentLayers() > 1 ) 
   {
@@ -1333,4 +1361,6 @@
     }
   }
+#endif
+
   if (pcVPS->getNumLayerSets() > 1)
   {
@@ -1351,8 +1381,16 @@
     if( i >= pcVPS->getNumLayerSets( ) )    
     {        
+#if !VPS_MISC_UPDATES
       READ_UVLC( uiCode,      "layer_set_idx_for_ols_minus1[i]" ); pcVPS->setLayerSetIdxForOlsMinus1( i, uiCode ); 
-    }
-
+#else
+      READ_CODE( pcVPS->getLayerSetIdxForOlsMinus1Len( i ), uiCode, "layer_set_idx_for_ols_minus1[i]" ); pcVPS->setLayerSetIdxForOlsMinus1( i, uiCode ); 
+#endif
+    }
+
+#if !VPS_MISC_UPDATES
     if ( i > pcVPS->getVpsNumLayerSetsMinus1() || pcVPS->getDefaultOutputLayerIdc() == 2 )
+#else
+    if ( i > pcVPS->getVpsNumLayerSetsMinus1() || pcVPS->getDefaultOutputLayerIdc() >= 2 )  //According to the spec, value 3 shall be treated as 2
+#endif
     {       
       for( Int j = 0; j < pcVPS->getNumLayersInIdList( pcVPS->olsIdxToLsIdx( i ) ); j++ )
@@ -1521,5 +1559,9 @@
   if( pcVPSVUI->getBitRatePresentVpsFlag( )  ||  pcVPSVUI->getPicRatePresentVpsFlag( ) )
   {
+#if I0045_BR_PR_ADD_LAYER_SET
+    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1; i  <  pcVPS->getNumLayerSets(); i++ )
+#else
     for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1; i  <=  pcVPS->getVpsNumLayerSetsMinus1(); i++ )
+#endif
     {
       for( Int j = 0; j  <=  pcVPS->getMaxSubLayersInLayerSetMinus1( i ); j++ ) 
@@ -1554,5 +1596,9 @@
   else
   {
+#if I0045_VPS_VUI_VST_PARAMS
+    pcVPSVUI->setVpsNumVideoSignalInfoMinus1( pcVPS->getMaxLayersMinus1() - pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1); 
+#else
     pcVPSVUI->setVpsNumVideoSignalInfoMinus1( pcVPS->getMaxLayersMinus1() ); 
+#endif
   }
 
@@ -1565,4 +1611,27 @@
   }
 
+#if I0045_VPS_VUI_VST_PARAMS
+  if( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() && pcVPSVUI->getVpsNumVideoSignalInfoMinus1() > 0 )
+  {
+    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
+    {
+      READ_CODE( 4, uiCode, "vps_video_signal_info_idx" ); pcVPSVUI->setVpsVideoSignalInfoIdx( i, uiCode );
+    }
+  }
+  else if ( !pcVPSVUI->getVideoSignalInfoIdxPresentFlag() )
+  {
+    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
+    {
+      pcVPSVUI->setVpsVideoSignalInfoIdx( i, i );
+    }
+  }
+  else
+  {
+    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
+    {
+      pcVPSVUI->setVpsVideoSignalInfoIdx( i, 0 );
+    }
+  }
+#else
   if( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() && pcVPSVUI->getVpsNumVideoSignalInfoMinus1() > 0 )
   {
@@ -1580,4 +1649,5 @@
     }
   }
+#endif
   READ_FLAG( uiCode, "tiles_not_in_use_flag" ); pcVPSVUI->setTilesNotInUseFlag( uiCode == 1 );
   if( !pcVPSVUI->getTilesNotInUseFlag() ) 
@@ -1641,4 +1711,7 @@
   if ( pcVPSVUI->getVpsVuiBspHrdPresentFlag( ) )
   {
+#if VPS_MISC_UPDATES
+    assert(pcVPS->getTimingInfo()->getTimingInfoPresentFlag() == 1);
+#endif
     parseVpsVuiBspHrdParameters( pcVPS ); 
   }
@@ -2008,4 +2081,14 @@
       esb++; 
       READ_FLAG( uiCode, "discardable_flag" ); rpcSlice->setDiscardableFlag( uiCode == 1 );
+#if NON_REF_NAL_TYPE_DISCARDABLE
+      if ( uiCode == 1 )
+      {
+        assert(rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_TRAIL_R &&
+          rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_TSA_R &&
+          rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_STSA_R &&
+          rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RADL_R &&
+          rpcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RASL_R);
+      }
+#endif
     }
 
@@ -2287,5 +2370,9 @@
       if (rpcSlice->getSPS()->getTMVPFlagsPresent())
       {
+#if I0044_SLICE_TMVP
+        READ_FLAG( uiCode, "slice_temporal_mvp_enabled_flag" );
+#else
         READ_FLAG( uiCode, "slice_temporal_mvp_enable_flag" );
+#endif
         rpcSlice->setEnableTMVPFlag( uiCode == 1 ? true : false ); 
       }
@@ -2723,4 +2810,11 @@
 #endif
   }
+#if INFERENCE_POC_MSB_VAL_PRESENT
+  else
+  {
+    rpcSlice->setSliceSegmentHeaderExtensionLength( 0 );
+    rpcSlice->setPocMsbValPresentFlag( false );
+  }
+#endif
 
 
Index: branches/HTM-12.0-dev0/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- branches/HTM-12.0-dev0/source/Lib/TLibDecoder/TDecTop.cpp	(revision 1052)
+++ branches/HTM-12.0-dev0/source/Lib/TLibDecoder/TDecTop.cpp	(revision 1053)
@@ -909,4 +909,28 @@
    }
 #endif
+   
+#if I0044_SLICE_TMVP
+  if ( m_apcSlicePilot->getTLayer() == 0 && m_apcSlicePilot->getEnableTMVPFlag() == 0 )
+  {
+    //update all pics in the DPB such that they cannot be used for TMPV ref
+    TComList<TComPic*>::iterator  iterRefPic = m_cListPic.begin();  
+    while( iterRefPic != m_cListPic.end() )
+    {
+      TComPic *refPic = *iterRefPic;
+      if( ( refPic->getLayerId() == m_apcSlicePilot->getLayerId() ) && refPic->getReconMark() )
+      {
+        for(Int i = refPic->getNumAllocatedSlice()-1; i >= 0; i--)
+        {
+
+          TComSlice *refSlice = refPic->getSlice(i);
+          refSlice->setAvailableForTMVPRefFlag( false );
+        }
+      }
+      iterRefPic++;
+    }
+  }
+  m_apcSlicePilot->setAvailableForTMVPRefFlag( true );
+#endif
+
   xActivateParameterSets();
 
@@ -1132,4 +1156,15 @@
 #endif    
 #endif
+
+#if I0044_SLICE_TMVP
+    if( m_layerId > 0 && !pcSlice->isIntra() && pcSlice->getEnableTMVPFlag() )
+    {
+      TComPic* refPic = pcSlice->getRefPic(RefPicList(1 - pcSlice->getColFromL0Flag()), pcSlice->getColRefIdx());
+
+      assert ( refPic );
+      assert ( refPic->getPicSym()->getSlice(0)->getAvailableForTMVPRefFlag() == true );
+    }
+#endif
+
     // For generalized B
     // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
Index: branches/HTM-12.0-dev0/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- branches/HTM-12.0-dev0/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 1052)
+++ branches/HTM-12.0-dev0/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 1053)
@@ -1012,5 +1012,6 @@
 #if H_MV
 Void TEncCavlc::codeVPSExtension( TComVPS *pcVPS ) 
-{  
+{ 
+  //TODO: ADD implementation for PTL. Need to add level info in each layer.
   WRITE_FLAG( pcVPS->getSplittingFlag() ? 1 : 0,             "splitting_flag" );
 
@@ -1084,4 +1085,18 @@
   }
 
+#if VPS_MISC_UPDATES   //These codes are moved from below.
+  if ( pcVPS->getNumIndependentLayers() > 1 ) 
+  {
+   WRITE_UVLC( pcVPS->getNumAddLayerSets( ), "num_add_layer_sets" );
+  }
+  for (Int i = 0; i < pcVPS->getNumAddLayerSets(); i++)
+  {
+    for (Int j = 0; j < pcVPS->getNumIndependentLayers(); j++)
+    {
+      WRITE_CODE( pcVPS->getHighestLayerIdxPlus1( i, j ), pcVPS->getHighestLayerIdxPlus1Len( j )  , "highest_layer_idx_plus1" );
+    }
+  }
+#endif
+
   WRITE_FLAG( pcVPS->getVpsSubLayersMaxMinus1PresentFlag( ) ? 1 : 0 , "vps_sub_layers_max_minus1_present_flag" );
   if ( pcVPS->getVpsSubLayersMaxMinus1PresentFlag() )
@@ -1125,4 +1140,5 @@
   }
 
+#if !VPS_MISC_UPDATES
   if ( pcVPS->getNumIndependentLayers() > 1 ) 
   {
@@ -1136,4 +1152,6 @@
     }
   }
+#endif
+
   if (pcVPS->getNumLayerSets() > 1)
   {
@@ -1152,8 +1170,16 @@
     if( i >= pcVPS->getNumLayerSets( ) )    
     {      
+#if !VPS_MISC_UPDATES
       WRITE_UVLC( pcVPS->getLayerSetIdxForOlsMinus1( i ),      "layer_set_idx_for_ols_minus1[i]" );
-    }
-
+#else
+      WRITE_CODE( pcVPS->getLayerSetIdxForOlsMinus1( i ), pcVPS->getLayerSetIdxForOlsMinus1Len( i ) ,      "layer_set_idx_for_ols_minus1[i]" );
+#endif
+    }
+
+#if !VPS_MISC_UPDATES
     if ( i > pcVPS->getVpsNumLayerSetsMinus1() || pcVPS->getDefaultOutputLayerIdc() == 2 )
+#else
+    if ( i > pcVPS->getVpsNumLayerSetsMinus1() || pcVPS->getDefaultOutputLayerIdc() >= 2 ) //according to the flag value 3 shall be treated as 2.
+#endif
     {       
       for( Int j = 0; j < pcVPS->getNumLayersInIdList( pcVPS->olsIdxToLsIdx( i ) ); j++ )
@@ -1371,5 +1397,9 @@
   if( pcVPSVUI->getBitRatePresentVpsFlag( )  ||  pcVPSVUI->getPicRatePresentVpsFlag( ) )
   {
+#if I0045_BR_PR_ADD_LAYER_SET
+    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1; i  <  pcVPS->getNumLayerSets(); i++ )
+#else
     for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1; i  <=  pcVPS->getVpsNumLayerSetsMinus1(); i++ )
+#endif
     {
       for( Int j = 0; j  <=  pcVPS->getMaxSubLayersInLayerSetMinus1( i ); j++ ) 
@@ -1404,5 +1434,9 @@
   else
   {
+#if I0045_VPS_VUI_VST_PARAMS
+    pcVPSVUI->setVpsNumVideoSignalInfoMinus1( pcVPS->getMaxLayersMinus1() - pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1 ); 
+#else
     pcVPSVUI->setVpsNumVideoSignalInfoMinus1( pcVPS->getMaxLayersMinus1() ); 
+#endif
   }
 
@@ -1417,4 +1451,10 @@
   if( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() && pcVPSVUI->getVpsNumVideoSignalInfoMinus1() > 0 )
   {
+#if I0045_VPS_VUI_VST_PARAMS
+    for( Int i = pcVPS->getVpsBaseLayerInternalFlag() ? 0 : 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
+    {
+      WRITE_CODE( pcVPSVUI->getVpsVideoSignalInfoIdx( i ), 4, "vps_video_signal_info_idx" );
+    }
+#else
     for( Int i = 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
     {
@@ -1429,4 +1469,5 @@
       assert( pcVPSVUI->getVpsVideoSignalInfoIdx( i  ) == ( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() ? 0 : i ) ); 
     }
+#endif
   }
   WRITE_FLAG( pcVPSVUI->getTilesNotInUseFlag( ) ? 1 : 0 , "tiles_not_in_use_flag" );
@@ -1733,4 +1774,14 @@
       esb++; 
       WRITE_FLAG( pcSlice->getDiscardableFlag( ) ? 1 : 0 , "discardable_flag" );
+#if NON_REF_NAL_TYPE_DISCARDABLE
+      if (pcSlice->getDiscardableFlag( ))
+      {
+        assert(pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_TRAIL_R &&
+          pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_TSA_R &&
+          pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_STSA_R &&
+          pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RADL_R &&
+          pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_RASL_R);
+      }
+#endif
     }
 
@@ -1893,5 +1944,9 @@
       if (pcSlice->getSPS()->getTMVPFlagsPresent())
       {
+#if I0044_SLICE_TMVP
+        WRITE_FLAG( pcSlice->getEnableTMVPFlag() ? 1 : 0, "slice_temporal_mvp_enabled_flag" );
+#else
         WRITE_FLAG( pcSlice->getEnableTMVPFlag() ? 1 : 0, "slice_temporal_mvp_enable_flag" );
+#endif
       }
     }
