Index: branches/HTM-3.0-Vidyo/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- branches/HTM-3.0-Vidyo/source/App/TAppDecoder/TAppDecTop.cpp	(revision 70)
+++ branches/HTM-3.0-Vidyo/source/App/TAppDecoder/TAppDecTop.cpp	(revision 71)
@@ -82,5 +82,10 @@
 Void TAppDecTop::decode()
 {
+#if VIDYO_VPS_INTEGRATION
+  increaseNumberOfViews( 0, 0, 0 );
+#else
   increaseNumberOfViews( 1 );
+#endif
+  
 #if SONY_COLPIC_AVAILABILITY
   m_tDecTop[0]->setViewOrderIdx(0);
@@ -141,4 +146,14 @@
       read(nalu, nalUnit);
 #if VIDYO_VPS_INTEGRATION
+      Int viewId = 0;
+      Int depth = 0;
+      
+      if(nalu.m_nalUnitType != NAL_UNIT_VPS || nalu.m_layerId)
+      {
+        // code assumes that the first nal unit is VPS
+        // currently, this is a hack that requires non-first VPSs have non-zero layer_id
+        viewId = getVPSAccess()->getActiveVPS()->getViewId(nalu.m_layerId);
+        depth = getVPSAccess()->getActiveVPS()->getDepthFlag(nalu.m_layerId);
+      }
       viewDepthId = nalu.m_layerId;   // coding order T0D0T1D1T2D2
 #else
@@ -151,5 +166,9 @@
       if( viewDepthId >= m_tDecTop.size() )      
       {
+#if VIDYO_VPS_INTEGRATION
+        increaseNumberOfViews( viewDepthId, viewId, depth );
+#else
         increaseNumberOfViews( viewDepthId +1 );
+#endif   
       }
       if(m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer)
@@ -397,13 +416,21 @@
   m_pocLastDisplay[viewDepthId] = -MAX_INT;
 }
-
+#if VIDYO_VPS_INTEGRATION
+Void  TAppDecTop::increaseNumberOfViews  ( UInt layerId, UInt viewId, UInt isDepth )
+#else
 Void  TAppDecTop::increaseNumberOfViews  ( Int newNumberOfViewDepth )
-{
+#endif
+{
+#if VIDYO_VPS_INTEGRATION
+  Int newNumberOfViewDepth = layerId + 1;
+#endif
   if ( m_outputBitDepth == 0 )
   {
     m_outputBitDepth = g_uiBitDepth + g_uiBitIncrement;
   }
+#if !VIDYO_VPS_INTEGRATION
   Int viewId = (newNumberOfViewDepth-1)>>1;   // coding order T0D0T1D1T2D2
   Bool isDepth = ((newNumberOfViewDepth % 2) == 0);  // coding order T0D0T1D1T2D2
+#endif
   if( isDepth )
     m_useDepth = true;
Index: branches/HTM-3.0-Vidyo/source/App/TAppDecoder/TAppDecTop.h
===================================================================
--- branches/HTM-3.0-Vidyo/source/App/TAppDecoder/TAppDecTop.h	(revision 70)
+++ branches/HTM-3.0-Vidyo/source/App/TAppDecoder/TAppDecTop.h	(revision 71)
@@ -74,4 +74,7 @@
   CamParsCollector                m_cCamParsCollector;
 #if DEPTH_MAP_GENERATION
+#if VIDYO_VPS_INTEGRATION
+  TComVPSAccess                   m_cVPSAccess;
+#endif
   TComSPSAccess                   m_cSPSAccess;
   TComAUPicAccess                 m_cAUPicAccess;
@@ -85,5 +88,9 @@
   Void  destroy           (); ///< destroy internal members
   Void  decode            (); ///< main decoding function
+#if VIDYO_VPS_INTEGRATION
+  Void  increaseNumberOfViews	(UInt layerId, UInt viewId, UInt isDepth);
+#else
   Void  increaseNumberOfViews	(Int newNumberOfViewDepth);
+#endif
   TDecTop* getTDecTop     ( Int viewId, Bool isDepth );
 
@@ -92,4 +99,7 @@
 
 #if DEPTH_MAP_GENERATION
+#if VIDYO_VPS_INTEGRATION
+  TComVPSAccess*    getVPSAccess  () { return &m_cVPSAccess;   }
+#endif
   TComSPSAccess*    getSPSAccess  () { return &m_cSPSAccess;   }
   TComAUPicAccess*  getAUPicAccess() { return &m_cAUPicAccess; }
Index: branches/HTM-3.0-Vidyo/source/App/TAppEncoder/TAppEncTop.h
===================================================================
--- branches/HTM-3.0-Vidyo/source/App/TAppEncoder/TAppEncTop.h	(revision 70)
+++ branches/HTM-3.0-Vidyo/source/App/TAppEncoder/TAppEncTop.h	(revision 71)
@@ -80,4 +80,7 @@
 
 #if DEPTH_MAP_GENERATION
+#if VIDYO_VPS_INTEGRATION
+  TComVPSAccess               m_cVPSAccess;
+#endif
   TComSPSAccess               m_cSPSAccess;
   TComAUPicAccess             m_cAUPicAccess;
@@ -137,4 +140,5 @@
 #if VIDYO_VPS_INTEGRATION
   TComVPS*          getVPS()  { return &m_cVPS; }
+  TComVPSAccess*    getVPSAccess  () { return &m_cVPSAccess;   }
 #endif
   
Index: branches/HTM-3.0-Vidyo/source/Lib/TLibCommon/TComDepthMapGenerator.cpp
===================================================================
--- branches/HTM-3.0-Vidyo/source/Lib/TLibCommon/TComDepthMapGenerator.cpp	(revision 70)
+++ branches/HTM-3.0-Vidyo/source/Lib/TLibCommon/TComDepthMapGenerator.cpp	(revision 71)
@@ -122,6 +122,11 @@
 }
 
+#if VIDYO_VPS_INTEGRATION
+Void
+TComDepthMapGenerator::init( TComPrediction* pcPrediction, TComVPSAccess* pcVPSAccess, TComSPSAccess* pcSPSAccess, TComAUPicAccess* pcAUPicAccess )
+#else
 Void
 TComDepthMapGenerator::init( TComPrediction* pcPrediction, TComSPSAccess* pcSPSAccess, TComAUPicAccess* pcAUPicAccess )
+#endif
 {
   AOF( pcPrediction  );
@@ -130,4 +135,7 @@
   uninit();
   m_pcPrediction  = pcPrediction;
+#if VIDYO_VPS_INTEGRATION
+  m_pcVPSAccess   = pcVPSAccess;
+#endif
   m_pcSPSAccess   = pcSPSAccess;
   m_pcAUPicAccess = pcAUPicAccess;
@@ -157,4 +165,7 @@
 
   // update SPS list and AU pic list and set depth map generator in SPS
+#if VIDYO_VPS_INTEGRATION
+  m_pcVPSAccess  ->addVPS( pcPic->getVPS() );
+#endif
   m_pcSPSAccess  ->addSPS( pcPic->getSPS() );
   m_pcAUPicAccess->addPic( pcPic );
Index: branches/HTM-3.0-Vidyo/source/Lib/TLibCommon/TComDepthMapGenerator.h
===================================================================
--- branches/HTM-3.0-Vidyo/source/Lib/TLibCommon/TComDepthMapGenerator.h	(revision 70)
+++ branches/HTM-3.0-Vidyo/source/Lib/TLibCommon/TComDepthMapGenerator.h	(revision 71)
@@ -50,5 +50,21 @@
 
 #if DEPTH_MAP_GENERATION
-
+#if VIDYO_VPS_INTEGRATION
+class TComVPSAccess // would be better to have a real VPS buffer
+{
+public:
+  TComVPSAccess ()  { clear(); }
+  ~TComVPSAccess()  {}
+  
+  Void      clear   ()                                { ::memset( m_aacVPS, 0x00, sizeof( m_aacVPS ) ); m_uiActiceVPSId = 0;}
+  Void      addVPS  ( TComVPS* pcVPS )                { m_aacVPS[ pcVPS->getVPSId() ] = pcVPS; }
+  TComVPS*  getVPS  ( UInt uiVPSId )                  { return m_aacVPS[ uiVPSId ]; }
+  TComVPS*  getActiveVPS  ( )                         { return m_aacVPS[ m_uiActiceVPSId ]; }
+  Void      setActiveVPSId  ( UInt activeVPSId )      { m_uiActiceVPSId = activeVPSId; }
+private:
+  TComVPS*  m_aacVPS[ MAX_NUM_VPS ];
+  UInt      m_uiActiceVPSId;
+};
+#endif
 
 class TComSPSAccess // would be better to have a real SPS buffer
@@ -113,4 +129,7 @@
   Void  destroy               ();
 
+#if VIDYO_VPS_INTEGRATION
+  Void  init( TComPrediction* pcPrediction, TComVPSAccess* pcVPSAccess, TComSPSAccess* pcSPSAccess, TComAUPicAccess* pcAUPicAccess );
+#endif
   Void  init                  ( TComPrediction* pcPrediction, TComSPSAccess* pcSPSAccess, TComAUPicAccess* pcAUPicAccess );
   Void  uninit                ();
@@ -136,4 +155,7 @@
 
   TComPrediction*   getPrediction ()  { return m_pcPrediction;  }
+#if VIDYO_VPS_INTEGRATION
+  TComVPSAccess*    getVPSAccess  ()  { return m_pcVPSAccess;   }
+#endif
   TComSPSAccess*    getSPSAccess  ()  { return m_pcSPSAccess;   }
   TComAUPicAccess*  getAUPicAccess()  { return m_pcAUPicAccess; }
@@ -198,4 +220,7 @@
   Bool              m_bDecoder;
   TComPrediction*   m_pcPrediction;
+#if VIDYO_VPS_INTEGRATION
+  TComVPSAccess*    m_pcVPSAccess;
+#endif
   TComSPSAccess*    m_pcSPSAccess;
   TComAUPicAccess*  m_pcAUPicAccess;
Index: branches/HTM-3.0-Vidyo/source/Lib/TLibCommon/TComPic.h
===================================================================
--- branches/HTM-3.0-Vidyo/source/Lib/TLibCommon/TComPic.h	(revision 70)
+++ branches/HTM-3.0-Vidyo/source/Lib/TLibCommon/TComPic.h	(revision 71)
@@ -120,4 +120,7 @@
   TComSlice*    getSlice(Int i)       { return  m_apcPicSym->getSlice(i);  }
   TComSlice*    getCurrSlice()        { return  m_apcPicSym->getSlice(m_uiCurrSliceIdx);  }
+#if VIDYO_VPS_INTEGRATION
+  TComVPS*      getVPS()              { return  m_apcPicSym->getSlice(m_uiCurrSliceIdx)->getVPS();  }
+#endif
   TComSPS*      getSPS()              { return  m_apcPicSym->getSlice(m_uiCurrSliceIdx)->getSPS();  }
   Int           getPOC()              { return  m_apcPicSym->getSlice(m_uiCurrSliceIdx)->getPOC();  }
Index: branches/HTM-3.0-Vidyo/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- branches/HTM-3.0-Vidyo/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 70)
+++ branches/HTM-3.0-Vidyo/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 71)
@@ -1349,5 +1349,5 @@
   READ_FLAG( uiCode,  "temporal_id_nesting_flag" );       pcVPS->setTemporalNestingFlag( uiCode ? true:false );
   READ_UVLC( uiCode,  "video_parameter_set_id" );         pcVPS->setVPSId( uiCode );
-  for(UInt i=0; i <= pcVPS->getMaxTLayers()-1; i++)
+  for(UInt i = 0; i <= pcVPS->getMaxTLayers()-1; i++)
   {
     READ_UVLC( uiCode,  "max_dec_pic_buffering[i]" );     pcVPS->setMaxDecPicBuffering( uiCode, i );
@@ -1362,8 +1362,8 @@
     READ_UVLC( uiCode,  "extension_type" );               pcVPS->setExtensionType( uiCode );
     
-    if( pcVPS->getExtensionType() == 0)
-      READ_SVLC( iCode,  "view_order_idx[0]" );           pcVPS->setViewOrderIdx( iCode, 0 );
-    
-    for(UInt i=0; i <= pcVPS->getMaxLayers()-1; i++)
+    pcVPS->setViewOrderIdx( 0, 0 );
+    pcVPS->setViewId( 0, 0 );
+    pcVPS->setDepthFlag( 0, 0 );
+    for(UInt i = 1; i <= pcVPS->getMaxLayers()-1; i++)
     {
       READ_FLAG( uiCode, "dependent_flag[i]" );           pcVPS->setDependentFlag( uiCode ? true:false, i);
Index: branches/HTM-3.0-Vidyo/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- branches/HTM-3.0-Vidyo/source/Lib/TLibDecoder/TDecTop.cpp	(revision 70)
+++ branches/HTM-3.0-Vidyo/source/Lib/TLibDecoder/TDecTop.cpp	(revision 71)
@@ -319,5 +319,9 @@
   m_tAppDecTop = pcTAppDecTop;
 #if DEPTH_MAP_GENERATION
+#if VIDYO_VPS_INTEGRATION
+  m_cDepthMapGenerator.init( &m_cPrediction, m_tAppDecTop->getVPSAccess(), m_tAppDecTop->getSPSAccess(), m_tAppDecTop->getAUPicAccess() );
+#else
   m_cDepthMapGenerator.init( &m_cPrediction, m_tAppDecTop->getSPSAccess(), m_tAppDecTop->getAUPicAccess() );
+#endif
 #endif
 #if HHI_INTER_VIEW_RESIDUAL_PRED
@@ -574,4 +578,7 @@
   TComVPS *vps = m_parameterSetManagerDecoder.getVPS(sps->getVPSId());
   assert (vps != 0);
+  if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA )
+    // VPS can only be activated on IDR or CRA...
+    getTAppDecTop()->getVPSAccess()->setActiveVPSId( sps->getVPSId() );
 #endif
   m_apcSlicePilot->setPPS(pps);
@@ -1082,5 +1089,5 @@
   m_cEntropyDecoder.decodeVPS( vps );
   m_parameterSetManagerDecoder.storePrefetchedVPS(vps);  
-
+  getTAppDecTop()->getVPSAccess()->addVPS( vps );
 }
 #endif
Index: branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 70)
+++ branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 71)
@@ -395,8 +395,5 @@
     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++)
+    for(UInt i=1; i <= pcVPS->getMaxLayers()-1; i++)
     {
       WRITE_FLAG( pcVPS->getDependentFlag(i),                     "dependent_flag[i]" );
Index: branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 70)
+++ branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 71)
@@ -246,5 +246,9 @@
 
       std::vector<TComAPS>& vAPS = m_pcEncTop->getAPS();
+#if VIDYO_VPS_INTEGRATION
+    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, uiPOCCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getEncTop()->getVPS(), m_pcEncTop->getSPS(), m_pcEncTop->getPPS() );
+#else
       m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, uiPOCCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS() );
+#endif
       pcSlice->setLastIDR(m_iLastIDR);
       pcSlice->setSliceIdx(0);
Index: branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 70)
+++ branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 71)
@@ -161,5 +161,9 @@
  \param pPPS          PPS associated with the slice
  */
+#if VIDYO_VPS_INTEGRATION
+Void TEncSlice::initEncSlice( TComPic* pcPic, Int iPOCLast, UInt uiPOCCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComVPS * pVPS, TComSPS* pSPS, TComPPS *pPPS )
+#else
 Void TEncSlice::initEncSlice( TComPic* pcPic, Int iPOCLast, UInt uiPOCCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS )
+#endif
 {
   Double dQP;
@@ -167,4 +171,7 @@
   
   rpcSlice = pcPic->getSlice(0);
+#if VIDYO_VPS_INTEGRATION
+  rpcSlice->setVPS( pVPS );
+#endif
   rpcSlice->setSPS( pSPS );
   rpcSlice->setPPS( pPPS );
Index: branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncSlice.h
===================================================================
--- branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncSlice.h	(revision 70)
+++ branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncSlice.h	(revision 71)
@@ -110,6 +110,9 @@
   
   /// preparation of slice encoding (reference marking, QP and lambda)
+#if VIDYO_VPS_INTEGRATION
+  Void    initEncSlice        ( TComPic*  pcPic, Int iPOCLast, UInt uiPOCCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComVPS* pVPS, TComSPS* pSPS, TComPPS *pPPS );
+#else
   Void    initEncSlice        ( TComPic*  pcPic, Int iPOCLast, UInt uiPOCCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS );
-
+#endif
   // compress and encode slice
   Void    precompressSlice    ( TComPic*& rpcPic                                );      ///< precompress slice for multi-loop opt.
Index: branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncTop.cpp	(revision 70)
+++ branches/HTM-3.0-Vidyo/source/Lib/TLibEncoder/TEncTop.cpp	(revision 71)
@@ -348,5 +348,9 @@
 
 #if DEPTH_MAP_GENERATION
-  m_cDepthMapGenerator.init( (TComPrediction*)this->getPredSearch(), m_pcTAppEncTop->getSPSAccess(), m_pcTAppEncTop->getAUPicAccess() );
+#if VIDYO_VPS_INTEGRATION
+  m_cDepthMapGenerator.init( (TComPrediction*)this->getPredSearch(), m_pcTAppEncTop->getVPSAccess(), m_pcTAppEncTop->getSPSAccess(), m_pcTAppEncTop->getAUPicAccess() );
+#else
+  m_cDepthMapGenerator.init( (TComPrediction*)this->getPredSearch(), m_pcTAppEncTop->getVPSAccess(), m_pcTAppEncTop->getSPSAccess(), m_pcTAppEncTop->getAUPicAccess() );
+#endif
 #endif
 #if HHI_INTER_VIEW_RESIDUAL_PRED
