Index: /branches/HTM-15.1-dev0-Vidyo/source/Lib/TLibCommon/SEI.cpp
===================================================================
--- /branches/HTM-15.1-dev0-Vidyo/source/Lib/TLibCommon/SEI.cpp	(revision 1330)
+++ /branches/HTM-15.1-dev0-Vidyo/source/Lib/TLibCommon/SEI.cpp	(revision 1331)
@@ -224,5 +224,5 @@
 #endif
 #if NH_MV_SEI
-#if NH_MV_SEI_TBD
+#if NH_MV_LAYERS_NOT_PRESENT_SEI
   case SEI::LAYERS_NOT_PRESENT                    :               return new SEILayersNotPresent;
 #endif
@@ -342,5 +342,5 @@
 
 
-#if NH_MV_SEI_TBD
+#if NH_MV_LAYERS_NOT_PRESENT_SEI
 Void SEILayersNotPresent::setupFromCfgFile(const Char* cfgFile)
 { 
@@ -349,12 +349,13 @@
 
   // TBD: Add default values for which layers, POCS, Tids or Nalu types the SEI should be send. 
-  defAppLayerIds    .push_back( TBD );
-  defAppPocs        .push_back( TBD );
-  defAppTids        .push_back( TBD );
-  defAppVclNaluTypes.push_back( TBD );
+  // This SEI message doesn't need to be added by default to any Layer / POC / NAL Unit / T Layer. Not sure if empty is right.
+  defAppLayerIds     empty( );      //push_back( TBD );
+  defAppPocs         empty( );      //push_back( TBD );
+  defAppTids         empty( );      //push_back( TBD );
+  defAppVclNaluTypes.empty( );      //push_back( TBD );
 
   Int      defSeiNaluId                  = 0; 
   Int      defPositionInSeiNalu          = 0; 
-  Bool     defModifyByEncoder            = TBD; 
+  Bool     defModifyByEncoder            = false;   //0: Use payload as specified in cfg file   1: Modify SEI by encoder
 
   // Setup config file options
@@ -363,5 +364,5 @@
 
   opts.addOptions()
-    ("LnpSeiActiveVpsId"              , m_lnpSeiActiveVpsId                , 0                              , "LnpSeiActiveVpsId"                )
+    ("LnpSeiActiveVpsId"              , m_lnpSeiActiveVpsId                , 0                              , "LnpSeiActiveVpsId"                )   //Why?
     ("LayerNotPresentFlag"            , m_layerNotPresentFlag              , BoolAry1d(1,0)                 , "LayerNotPresentFlag"              )
     ;
@@ -372,30 +373,32 @@
   po::ErrorReporter err;
   po::parseConfigFile( opts, cfgFile, err );
-};
-
-Bool SEILayersNotPresent::checkCfg( const TComSlice* slice )
-{ 
-  // Check config values
-  Bool wrongConfig = false; 
-
-  // TBD: Add constraints on presence of SEI here. 
-  xCheckCfg     ( wrongConfig, TBD , "TBD" );
-  xCheckCfg     ( wrongConfig, TBD , "TBD" );
-
-  // TBD: Modify constraints according to the SEI semantics. 
-  xCheckCfgRange( wrongConfig, m_lnpSeiActiveVpsId              , MINVAL , MAXVAL, "lnp_sei_active_vps_id"            );
-  xCheckCfgRange( wrongConfig, m_layerNotPresentFlag[i]         , MINVAL , MAXVAL, "layer_not_present_flag"           );
-
-  return wrongConfig; 
-};
-
-Void SEILayersNotPresent::setupFromSlice  ( const TComSlice* slice )
-{
-  sei.m_lnpSeiActiveVpsId =  TBD ;
-  for( Int i = 0; i  <=  MaxLayersMinus1; i++ )
-  {
-    sei.m_layerNotPresentFlag[i] =  TBD ;
-  }
-};
+  m_lnpSeiMaxLayers = m_layerNotPresentFlag.size();
+};
+
+  Bool SEILayersNotPresent::checkCfg( const TComSlice* slice )
+  { 
+//  // Check config values
+//  Bool wrongConfig = false; 
+//
+//  // TBD: Add constraints on presence of SEI here. 
+//  xCheckCfg     ( wrongConfig, TBD , "TBD" );
+//  xCheckCfg     ( wrongConfig, TBD , "TBD" );
+//
+//  // TBD: Modify constraints according to the SEI semantics. 
+//  xCheckCfgRange( wrongConfig, m_lnpSeiActiveVpsId              , MINVAL , MAXVAL, "lnp_sei_active_vps_id"            );
+//  xCheckCfgRange( wrongConfig, m_layerNotPresentFlag[i]         , MINVAL , MAXVAL, "layer_not_present_flag"           );
+//
+//  return wrongConfig; 
+      return false;
+  };
+//
+//Void SEILayersNotPresent::setupFromSlice  ( const TComSlice* slice )
+//{
+//  sei.m_lnpSeiActiveVpsId =  TBD ;
+//  for( Int i = 0; i  <=  MaxLayersMinus1; i++ )
+//  {
+//    sei.m_layerNotPresentFlag[i] =  TBD ;
+//  }
+//};
 #endif
 
Index: /branches/HTM-15.1-dev0-Vidyo/source/Lib/TLibCommon/SEI.h
===================================================================
--- /branches/HTM-15.1-dev0-Vidyo/source/Lib/TLibCommon/SEI.h	(revision 1330)
+++ /branches/HTM-15.1-dev0-Vidyo/source/Lib/TLibCommon/SEI.h	(revision 1331)
@@ -660,5 +660,5 @@
 
 #if NH_MV_SEI
-#if NH_MV_SEI_TBD
+#if NH_MV_LAYERS_NOT_PRESENT_SEI
 class SEILayersNotPresent : public SEI
 {
@@ -670,9 +670,15 @@
 
   Void setupFromCfgFile( const Char*      cfgFile );
-  Void setupFromSlice  ( const TComSlice* slice   );
+  //Void setupFromSlice  ( const TComSlice* slice   );
   Bool checkCfg        ( const TComSlice* slice   );
 
   Int       m_lnpSeiActiveVpsId;
+  UInt      m_lnpSeiMaxLayers;
   BoolAry1d m_layerNotPresentFlag;
+
+  void resizeDimI( Int sizeDimI )
+  {
+    m_layerNotPresentFlag.resize( sizeDimI );
+  }
 };
 #endif
Index: /branches/HTM-15.1-dev0-Vidyo/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- /branches/HTM-15.1-dev0-Vidyo/source/Lib/TLibCommon/TypeDef.h	(revision 1330)
+++ /branches/HTM-15.1-dev0-Vidyo/source/Lib/TLibCommon/TypeDef.h	(revision 1331)
@@ -70,4 +70,5 @@
 #define NH_MV_FIX_INIT_NUM_ACTIVE_REF_LAYER_PICS  1 // Derivation of NumActiveRefLayerPIcs. !!SPEC!! 
 #define NH_MV_FIX_NUM_POC_TOTAL_CUR               1 // Derivation of NumPocTotalCur for IDR pictures. !!SPEC!!
+#define NH_MV_LAYERS_NOT_PRESENT_SEI              1 // Layers not present SEI message JCTMV-M0043
 #endif
 #if NH_3D
Index: /branches/HTM-15.1-dev0-Vidyo/source/Lib/TLibDecoder/SEIread.cpp
===================================================================
--- /branches/HTM-15.1-dev0-Vidyo/source/Lib/TLibDecoder/SEIread.cpp	(revision 1330)
+++ /branches/HTM-15.1-dev0-Vidyo/source/Lib/TLibDecoder/SEIread.cpp	(revision 1331)
@@ -124,5 +124,9 @@
  * unmarshal a single SEI message from bitstream bs
  */
+#if NH_MV_LAYERS_NOT_PRESENT_SEI
+Void SEIReader::parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, const TComVPS *vps, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
+#else
 Void SEIReader::parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
+#endif
 {
   setBitstream(bs);
@@ -131,6 +135,9 @@
   do
   {
+#if NH_MV_LAYERS_NOT_PRESENT_SEI
+    xReadSEImessage(seis, nalUnitType, vps, sps, pDecodedMessageOutputStream);
+#else
     xReadSEImessage(seis, nalUnitType, sps, pDecodedMessageOutputStream);
-
+#endif
     /* SEI messages are an integer number of bytes, something has failed
     * in the parsing if bitstream not byte-aligned */
@@ -142,5 +149,9 @@
 }
 
+#if NH_MV_LAYERS_NOT_PRESENT_SEI
+Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, const TComVPS *vps, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
+#else
 Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
+#endif
 {
 #if ENC_DEC_TRACE
@@ -261,5 +272,9 @@
     case SEI::SCALABLE_NESTING:
       sei = new SEIScalableNesting;
+#if NH_MV_LAYERS_NOT_PRESENT_SEI
+      xParseSEIScalableNesting((SEIScalableNesting&) *sei, nalUnitType, payloadSize, vps, sps, pDecodedMessageOutputStream);
+#else
       xParseSEIScalableNesting((SEIScalableNesting&) *sei, nalUnitType, payloadSize, sps, pDecodedMessageOutputStream);
+#endif
       break;
     case SEI::TEMP_MOTION_CONSTRAINED_TILE_SETS:
@@ -290,8 +305,15 @@
       break;
 #else
-#if NH_MV_TBD
+#if NH_MV_LAYERS_NOT_PRESENT_SEI
     case SEI::LAYERS_NOT_PRESENT:
-      sei = new SEILayersNotPresent;
-      xParseSEILayersNotPresent((SEILayersNotPresent&) *sei, payloadSize, pDecodedMessageOutputStream );
+      if (!vps)
+      {
+        printf ("Warning: Found Layers not present SEI message, but no active VPS is available. Ignoring.");
+      }
+      else
+      {
+        sei = new SEILayersNotPresent;
+        xParseSEILayersNotPresent((SEILayersNotPresent&) *sei, payloadSize, vps, pDecodedMessageOutputStream);
+      }
       break;
 #endif
@@ -885,5 +907,9 @@
 }
 
+#if NH_MV_LAYERS_NOT_PRESENT_SEI
+Void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, const TComVPS *vps, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
+#else
 Void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream)
+#endif
 {
   UInt uiCode;
@@ -927,5 +953,9 @@
   do
   {
+#if NH_MV_LAYERS_NOT_PRESENT_SEI
+    xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps, pDecodedMessageOutputStream);
+#else
     xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps, pDecodedMessageOutputStream);
+#endif
   } while (m_pcBitstream->getNumBitsLeft() > 8);
 
@@ -1183,14 +1213,20 @@
 }
 
-#if NH_MV_SEI_TBD
-Void SEIReader::xParseSEILayersNotPresent(SEILayersNotPresent& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream)
-{
-  UInt code;
-  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
-
+#if NH_MV_LAYERS_NOT_PRESENT_SEI
+Void SEIReader::xParseSEILayersNotPresent(SEILayersNotPresent &sei, UInt payloadSize, const TComVPS *vps, std::ostream *pDecodedMessageOutputStream)
+{
+  UInt code;
+  UInt i = 0;
+
+  output_sei_message_header(sei, pDecodedMessageOutputStream, payloadSize);
   sei_read_code( pDecodedMessageOutputStream, 4, code, "lnp_sei_active_vps_id" ); sei.m_lnpSeiActiveVpsId = code;
-  for( Int i = 0; i  <=  MaxLayersMinus1; i++ )
-  {
-    sei_read_flag( pDecodedMessageOutputStream, code, "layer_not_present_flag" ); sei.m_layerNotPresentFlag[i] = (code == 1);
+  assert(vps->getVPSId() == sei.m_lnpSeiActiveVpsId);
+
+  sei.m_lnpSeiMaxLayers = vps->getMaxLayersMinus1() + 1;
+  sei.resizeDimI(sei.m_lnpSeiMaxLayers);
+  for (; i < sei.m_lnpSeiMaxLayers; i++)
+  {
+    sei_read_flag( pDecodedMessageOutputStream, code, "layer_not_present_flag" ); 
+    sei.m_layerNotPresentFlag[i] = (code == 1);
   }
 };
Index: /branches/HTM-15.1-dev0-Vidyo/source/Lib/TLibDecoder/SEIread.h
===================================================================
--- /branches/HTM-15.1-dev0-Vidyo/source/Lib/TLibDecoder/SEIread.h	(revision 1330)
+++ /branches/HTM-15.1-dev0-Vidyo/source/Lib/TLibDecoder/SEIread.h	(revision 1331)
@@ -56,5 +56,9 @@
   SEIReader() {};
   virtual ~SEIReader() {};
+#if NH_MV_LAYERS_NOT_PRESENT_SEI
+  Void parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, const TComVPS *vps, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream);
+#else
   Void parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream);
+#endif
 #if NH_MV_SEI
   Void setLayerId                            ( Int   layerId )   { m_layerId  = layerId; }; 
@@ -62,5 +66,9 @@
 #endif
 protected:
+#if NH_MV_LAYERS_NOT_PRESENT_SEI
+  Void xReadSEImessage                        (SEIMessages& seis, const NalUnitType nalUnitType, const TComVPS *vps, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream);
+#else
   Void xReadSEImessage                        (SEIMessages& seis, const NalUnitType nalUnitType, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream);
+#endif
   Void xParseSEIuserDataUnregistered          (SEIuserDataUnregistered &sei,          UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
   Void xParseSEIActiveParameterSets           (SEIActiveParameterSets  &sei,          UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
@@ -78,5 +86,9 @@
   Void xParseSEIToneMappingInfo               (SEIToneMappingInfo& sei,               UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
   Void xParseSEISOPDescription                (SEISOPDescription &sei,                UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
+#if NH_MV_LAYERS_NOT_PRESENT_SEI
+  Void xParseSEIScalableNesting               (SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, const TComVPS *vps, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream);
+#else
   Void xParseSEIScalableNesting               (SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, const TComSPS *sps, std::ostream *pDecodedMessageOutputStream);
+#endif
   Void xParseSEITempMotionConstraintsTileSets (SEITempMotionConstrainedTileSets& sei, UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
   Void xParseSEITimeCode                      (SEITimeCode& sei,                      UInt payloadSize,                     std::ostream *pDecodedMessageOutputStream);
@@ -90,6 +102,6 @@
 #endif
 #endif
-#if NH_MV_SEI_TBD
-  Void xParseSEILayersNotPresent              (SEILayersNotPresent& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream);
+#if NH_MV_LAYERS_NOT_PRESENT_SEI
+  Void xParseSEILayersNotPresent              (SEILayersNotPresent &sei, UInt payloadSize, const TComVPS *vps ,std::ostream *pDecodedMessageOutputStream);
 #endif
   Void xParseSEIInterLayerConstrainedTileSets (SEIInterLayerConstrainedTileSets& sei, UInt payloadSize, std::ostream *pDecodedMessageOutputStream);
Index: /branches/HTM-15.1-dev0-Vidyo/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- /branches/HTM-15.1-dev0-Vidyo/source/Lib/TLibDecoder/TDecTop.cpp	(revision 1330)
+++ /branches/HTM-15.1-dev0-Vidyo/source/Lib/TLibDecoder/TDecTop.cpp	(revision 1331)
@@ -836,5 +836,9 @@
     InputNALUnit &nalu=*m_prefixSEINALUs.front();
 #if NH_MV
+#if NH_MV_LAYERS_NOT_PRESENT_SEI
+    m_seiReader.parseSEImessage(&(nalu.getBitstream()), m_SEIs, nalu.m_nalUnitType, m_parameterSetManager.getActiveVPS(), m_parameterSetManager.getActiveSPS(getLayerId()), m_pDecodedSEIOutputStream);
+#else
     m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_SEIs, nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS( getLayerId() ), m_pDecodedSEIOutputStream );
+#endif
 #else
     m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_SEIs, nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS(), m_pDecodedSEIOutputStream );
@@ -1308,5 +1312,9 @@
       {
 #if NH_MV
-        m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_pcPic->getSEIs(), nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS( getLayerId() ), m_pDecodedSEIOutputStream );
+#if NH_MV_LAYERS_NOT_PRESENT_SEI
+      m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_pcPic->getSEIs(), nalu.m_nalUnitType, m_parameterSetManager.getActiveVPS(), m_parameterSetManager.getActiveSPS(getLayerId()), m_pDecodedSEIOutputStream);
+#else
+      m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_pcPic->getSEIs(), nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS( getLayerId() ), m_pDecodedSEIOutputStream );
+#endif
 #else
         m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_pcPic->getSEIs(), nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS(), m_pDecodedSEIOutputStream );
Index: /branches/HTM-15.1-dev0-Vidyo/source/Lib/TLibEncoder/SEIwrite.cpp
===================================================================
--- /branches/HTM-15.1-dev0-Vidyo/source/Lib/TLibEncoder/SEIwrite.cpp	(revision 1330)
+++ /branches/HTM-15.1-dev0-Vidyo/source/Lib/TLibEncoder/SEIwrite.cpp	(revision 1331)
@@ -129,7 +129,7 @@
 #endif
 #if NH_MV_SEI
-#if NH_MV_SEI_TBD
+#if NH_MV_LAYERS_NOT_PRESENT_SEI
    case SEI::LAYERS_NOT_PRESENT:
-     xWriteSEILayersNotPresent(*static_cast<const SEILayersNotPresent*>(&sei));
+       xWriteSEILayersNotPresent(*static_cast<const SEILayersNotPresent*>(&sei));
      break; 
 #endif
@@ -881,9 +881,9 @@
 }
 
-#if NH_MV_SEI_TBD
-Void SEIWriter::xWriteSEILayersNotPresent( const SEILayersNotPresent& sei)
+#if NH_MV_LAYERS_NOT_PRESENT_SEI
+Void SEIWriter::xWriteSEILayersNotPresent(const SEILayersNotPresent& sei)
 {
   WRITE_CODE( sei.m_lnpSeiActiveVpsId, 4, "lnp_sei_active_vps_id" );
-  for( Int i = 0; i  <=  MaxLayersMinus1; i++ )
+  for( Int i = 0; i  <  sei.m_lnpSeiMaxLayers; i++ )
   {
     WRITE_FLAG( ( sei.m_layerNotPresentFlag[i] ? 1 : 0 ), "layer_not_present_flag" );
Index: /branches/HTM-15.1-dev0-Vidyo/source/Lib/TLibEncoder/SEIwrite.h
===================================================================
--- /branches/HTM-15.1-dev0-Vidyo/source/Lib/TLibEncoder/SEIwrite.h	(revision 1330)
+++ /branches/HTM-15.1-dev0-Vidyo/source/Lib/TLibEncoder/SEIwrite.h	(revision 1331)
@@ -84,5 +84,5 @@
 
 #if NH_MV_SEI
-#if NH_MV_SEI_TBD
+#if NH_MV_LAYERS_NOT_PRESENT_SEI
   Void xWriteSEILayersNotPresent              ( const SEILayersNotPresent& sei);
 #endif
Index: /branches/HTM-15.1-dev0-Vidyo/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- /branches/HTM-15.1-dev0-Vidyo/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 1330)
+++ /branches/HTM-15.1-dev0-Vidyo/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 1331)
@@ -329,4 +329,11 @@
   xClearSEIs(currentMessages, !testWrite);
 
+#if NH_MV_LAYERS_NOT_PRESENT_SEI
+  // Layers not present SEI message
+  currentMessages = extractSeisByType(localMessages, SEI::LAYERS_NOT_PRESENT);
+  xWriteSEISeparately(NAL_UNIT_PREFIX_SEI, currentMessages, accessUnit, itNalu, temporalId, sps);
+  xClearSEIs(currentMessages, !testWrite);
+#endif
+
   // And finally everything else one by one
   xWriteSEISeparately(NAL_UNIT_PREFIX_SEI, localMessages, accessUnit, itNalu, temporalId, sps);
