Index: branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/NALwrite.cpp
===================================================================
--- branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/NALwrite.cpp	(revision 69)
+++ branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/NALwrite.cpp	(revision 70)
@@ -64,4 +64,8 @@
 #endif
 
+#if VIDYO_VPS_INTEGRATION
+  bsNALUHeader.write(nalu.m_temporalId, 3); // temporal_id
+  bsNALUHeader.write(nalu.m_layerId + 1, 5); // layer_id_plus1
+#else
 #if H0388
   bsNALUHeader.write(nalu.m_temporalId, 3); // temporal_id
@@ -90,4 +94,6 @@
   }
 #endif
+#endif
+  
   out.write(bsNALUHeader.getByteStream(), bsNALUHeader.getByteStreamLength());
 
@@ -201,10 +207,17 @@
   naluDest.m_nalRefIDC   = naluSrc.m_nalRefIDC;
 #endif
+#if !VIDYO_VPS_INTEGRATION
   naluDest.m_viewId      = naluSrc.m_viewId;
   naluDest.m_isDepth     = naluSrc.m_isDepth;
+#endif
   naluDest.m_temporalId  = naluSrc.m_temporalId;
+#if VIDYO_VPS_INTEGRATION
+  naluDest.m_layerId = naluSrc.m_layerId;
+#else
+  
 #if !H0388
   naluDest.m_OutputFlag  = naluSrc.m_OutputFlag;
 #endif
+#endif
   naluDest.m_Bitstream   = naluSrc.m_Bitstream;
 }
Index: branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/NALwrite.h
===================================================================
--- branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/NALwrite.h	(revision 69)
+++ branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/NALwrite.h	(revision 70)
@@ -62,11 +62,23 @@
     NalRefIdc nalRefIDC,
 #endif
+#if VIDYO_VPS_INTEGRATION
+    unsigned layerId,
+#else
     Int viewId,
     Bool isDepth,
+#endif
     unsigned temporalID = 0)
 #if NAL_REF_FLAG
+#if VIDYO_VPS_INTEGRATION
+  : NALUnit(nalUnitType, nalRefFlag, layerId, temporalID)
+#else
   : NALUnit(nalUnitType, nalRefFlag, viewId, isDepth, temporalID)
+#endif
+#else
+#if VIDYO_VPS_INTEGRATION
+  : NALUnit(nalUnitType, nalRefIDC, layerId, temporalID)
 #else
   : NALUnit(nalUnitType, nalRefIDC, viewId, isDepth, temporalID)
+#endif
 #endif
   , m_Bitstream()
Index: branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 69)
+++ branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 70)
@@ -375,4 +375,52 @@
 }
 
+#if VIDYO_VPS_INTEGRATION
+Void TEncCavlc::codeVPS( TComVPS* pcVPS )
+{
+	WRITE_CODE( pcVPS->getMaxTLayers() - 1,     3,        "max_temporal_layers_minus1" );
+  WRITE_CODE( pcVPS->getMaxLayers() - 1,      5,        "max_layers_minus1" );
+  WRITE_FLAG( pcVPS->getTemporalNestingFlag() - 1,      "temporal_id_nesting_flag" );
+  WRITE_UVLC( pcVPS->getVPSId(),                        "video_parameter_set_id" );
+  for(UInt i=0; i <= pcVPS->getMaxTLayers()-1; i++)
+  {
+    WRITE_UVLC( pcVPS->getMaxDecPicBuffering(i),           "max_dec_pic_buffering[i]" );
+    WRITE_UVLC( pcVPS->getNumReorderPics(i),               "num_reorder_pics[i]" );
+    WRITE_UVLC( pcVPS->getMaxLatencyIncrease(i),           "max_latency_increase[i]" );
+  }
+  
+  WRITE_CODE( 1,      1,        "bit_equal_to_one" );
+  
+  if( pcVPS->getMaxLayers() - 1 > 0 )
+  {
+    WRITE_UVLC( pcVPS->getExtensionType(),                        "extension_type" );
+    
+    if( pcVPS->getExtensionType() == 0)
+      WRITE_SVLC( pcVPS->getViewOrderIdx(0),                      "view_order_idx[0]" );
+    
+    for(UInt i=0; i <= pcVPS->getMaxLayers()-1; i++)
+    {
+      WRITE_FLAG( pcVPS->getDependentFlag(i),                     "dependent_flag[i]" );
+      if( pcVPS->getDependentFlag(i) )
+      {
+        WRITE_UVLC( i - pcVPS->getDependentLayer(i) - 1,          "delta_reference_layer_id_minus1[i]" );
+        if( pcVPS->getExtensionType() == VPS_EXTENSION_TYPE_MULTI_VIEW )
+        {
+          WRITE_UVLC( pcVPS->getViewId(i),                        "view_id[i]" );
+          WRITE_FLAG( pcVPS->getDepthFlag(i),                     "depth_flag[i]" );
+          WRITE_SVLC( pcVPS->getViewOrderIdx(i),                  "view_order_idx[i]" );
+        }
+        
+      }
+    }
+  }
+  
+  WRITE_FLAG( 0,                     "vps_extension_flag" );
+  
+  //future extensions here..
+  
+  return;
+}
+#endif
+
 #if HHI_MPI
 Void TEncCavlc::codeSPS( TComSPS* pcSPS, Bool bIsDepth )
@@ -388,4 +436,7 @@
   WRITE_CODE( pcSPS->getLevelIdc (),       8,       "level_idc" );
   WRITE_UVLC( pcSPS->getSPSId (),                   "seq_parameter_set_id" );
+#if VIDYO_VPS_INTEGRATION
+  WRITE_UVLC( pcSPS->getVPSId (),                   "video_parameter_set_id" );
+#endif
   WRITE_UVLC( pcSPS->getChromaFormatIdc (),         "chroma_format_idc" );
   WRITE_CODE( pcSPS->getMaxTLayers() - 1,  3,       "max_temporal_layers_minus1" );
Index: branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncCavlc.h
===================================================================
--- branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncCavlc.h	(revision 69)
+++ branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncCavlc.h	(revision 70)
@@ -113,5 +113,9 @@
   UInt  getNumberOfWrittenBits()                { return  m_pcBitIf->getNumberOfWrittenBits();  }
   UInt  getCoeffCost          ()                { return  m_uiCoeffCost;  }
-  
+
+#if VIDYO_VPS_INTEGRATION
+  Void  codeVPS                 ( TComVPS* pcVPS );
+#endif
+
 #if HHI_MPI
   Void  codeSPS                 ( TComSPS* pcSPS, Bool bIsDepth );
Index: branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncCfg.h	(revision 69)
+++ branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncCfg.h	(revision 70)
@@ -290,4 +290,8 @@
 #endif
 
+#if VIDYO_VPS_INTEGRATION
+  UInt     m_layerId;
+#endif
+  
   Int      m_viewId;
   Bool     m_isDepth;
@@ -765,5 +769,9 @@
   Int       getTSIG()                            { return m_signHidingThreshold; }
 #endif
-
+#if VIDYO_VPS_INTEGRATION
+  Void      setLayerId             ( UInt layerId )   { m_layerId = layerId; }
+  UInt      getLayerId             ()               { return m_layerId; }
+#endif
+  
   Void      setViewId             ( Int viewId )   { m_viewId = viewId; }
   Int       getViewId             ()               { return m_viewId; }
Index: branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncEntropy.cpp
===================================================================
--- branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 69)
+++ branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 70)
@@ -121,4 +121,16 @@
 }
 
+#if VIDYO_VPS_INTEGRATION
+Void TEncEntropy::encodeVPS( TComVPS* pcVPS )
+{
+  m_pcEntropyCoderIf->codeVPS( pcVPS );
+  return;
+}
+#endif
+
+#if VIDYO_VPS_INTEGRATION
+Void  codeVPS                 ( TComVPS* pcVPS );
+#endif
+
 #if HHI_MPI
 Void TEncEntropy::encodeSPS( TComSPS* pcSPS, Bool bIsDepth )
Index: branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncEntropy.h
===================================================================
--- branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncEntropy.h	(revision 69)
+++ branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncEntropy.h	(revision 70)
@@ -76,4 +76,8 @@
   virtual UInt  getCoeffCost          ()                = 0;
 
+#if VIDYO_VPS_INTEGRATION
+	virtual Void  codeVPS                 ( TComVPS* pcVPS )                                      = 0;
+#endif
+	
 #if HHI_MPI
   virtual Void  codeSPS                 ( TComSPS* pcSPS, Bool bIsDepth )                       = 0;
@@ -229,4 +233,7 @@
   
 public:
+#if VIDYO_VPS_INTEGRATION
+	Void encodeVPS               ( TComVPS* pcVPS);
+#endif
   // SPS
 #if HHI_MPI
Index: branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 69)
+++ branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 70)
@@ -809,6 +809,19 @@
       if ( m_bSeqFirst )
       {
+#if VIDYO_VPS_INTEGRATION
+        {
+          OutputNALUnit nalu(NAL_UNIT_VPS, true, m_pcEncTop->getLayerId());
+          m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
+          m_pcEntropyCoder->encodeVPS(m_pcEncTop->getEncTop()->getVPS());
+          writeRBSPTrailingBits(nalu.m_Bitstream);
+          accessUnit.push_back(new NALUnitEBSP(nalu));
+        }
+#endif
 #if NAL_REF_FLAG
+#if VIDYO_VPS_INTEGRATION
+        OutputNALUnit nalu(NAL_UNIT_SPS, true, m_pcEncTop->getLayerId());
+#else
         OutputNALUnit nalu(NAL_UNIT_SPS, true, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth());
+#endif
 #else
         OutputNALUnit nalu(NAL_UNIT_SPS, NAL_REF_IDC_PRIORITY_HIGHEST, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth());
@@ -827,5 +840,9 @@
 
 #if NAL_REF_FLAG
+#if VIDYO_VPS_INTEGRATION 
+        nalu = NALUnit(NAL_UNIT_PPS, true, m_pcEncTop->getLayerId());
+#else
         nalu = NALUnit(NAL_UNIT_PPS, true, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth());
+#endif
 #else
         nalu = NALUnit(NAL_UNIT_PPS, NAL_REF_IDC_PRIORITY_HIGHEST, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth());
@@ -954,11 +971,28 @@
 #if H0388
 #if NAL_REF_FLAG
-        OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->isReferenced(), m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth(), pcSlice->getTLayer() );
-#else
-        OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->isReferenced() ? NAL_REF_IDC_PRIORITY_HIGHEST: NAL_REF_IDC_PRIORITY_LOWEST, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth(), pcSlice->getTLayer() );
-#endif
-#else
-        OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->isReferenced() ? NAL_REF_IDC_PRIORITY_HIGHEST: NAL_REF_IDC_PRIORITY_LOWEST, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth(), pcSlice->getTLayer(), true);
-#endif
+        OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->isReferenced(),
+#if !VIDYO_VPS_INTEGRATION
+                           m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth(), pcSlice->getTLayer() );
+#else
+                           m_pcEncTop->getLayerId(), pcSlice->getTLayer() );
+#endif
+#else
+        OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->isReferenced() ? NAL_REF_IDC_PRIORITY_HIGHEST: NAL_REF_IDC_PRIORITY_LOWEST, 
+#if !VIDYO_VPS_INTEGRATION
+                           m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth(), pcSlice->getTLayer() );
+#else
+                           m_pcEncTop->getLayerId(), pcSlice->getTLayer() );
+#endif
+#endif
+#else
+        OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->isReferenced() ? NAL_REF_IDC_PRIORITY_HIGHEST: NAL_REF_IDC_PRIORITY_LOWEST, 
+#if !VIDYO_VPS_INTEGRATION
+                           m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth(), pcSlice->getTLayer(), true );
+#else
+                           m_pcEncTop->getLayerId(), pcSlice->getTLayer(), true );
+#endif
+
+#endif
+            
         Bool bEntropySlice = (!pcSlice->isNextSlice());
         if (!bEntropySlice)
@@ -1414,5 +1448,9 @@
           {
 #if NAL_REF_FLAG
+#if VIDYO_VPS_INTEGRATION
+            OutputNALUnit nalu(NAL_UNIT_APS, true, m_pcEncTop->getLayerId());
+#else
             OutputNALUnit nalu(NAL_UNIT_APS, true, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth());
+#endif
 #else
             OutputNALUnit nalu(NAL_UNIT_APS, NAL_REF_IDC_PRIORITY_HIGHEST, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth());
@@ -1476,5 +1514,9 @@
 
 #if NAL_REF_FLAG
+#if VIDYO_VPS_INTEGRATION
+        OutputNALUnit nalu(NAL_UNIT_SEI, false, m_pcEncTop->getLayerId());
+#else
         OutputNALUnit nalu(NAL_UNIT_SEI, false, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth());
+#endif
 #else
         OutputNALUnit nalu(NAL_UNIT_SEI, NAL_REF_IDC_PRIORITY_LOWEST, m_pcEncTop->getViewId(), m_pcEncTop->getIsDepth());
Index: branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncSbac.cpp
===================================================================
--- branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 69)
+++ branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 70)
@@ -342,4 +342,12 @@
 }
 
+#if VIDYO_VPS_INTEGRATION
+Void TEncSbac::codeVPS( TComVPS* pcVPS )
+{
+	assert (0);
+  return;
+}
+#endif
+
 #if HHI_MPI
 Void TEncSbac::codeSPS( TComSPS* pcSPS, Bool bIsDepth )
Index: branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncSbac.h
===================================================================
--- branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncSbac.h	(revision 69)
+++ branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncSbac.h	(revision 70)
@@ -98,4 +98,8 @@
   //--SBAC RD
 
+#if VIDYO_VPS_INTEGRATION
+  Void  codeVPS                 ( TComVPS* pcVPS );
+#endif
+	
 #if HHI_MPI
   Void  codeSPS                 ( TComSPS* pcSPS, Bool bIsDepth );
