Index: branches/HTM-DEV-0.1-dev/source/App/TAppDecoder/TAppDecCfg.cpp
===================================================================
--- branches/HTM-DEV-0.1-dev/source/App/TAppDecoder/TAppDecCfg.cpp	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/App/TAppDecoder/TAppDecCfg.cpp	(revision 368)
@@ -42,4 +42,7 @@
 #include "TAppCommon/program_options_lite.h"
 
+#if H_MV
+#include <cassert>
+#endif
 #ifdef WIN32
 #define strdup _strdup
@@ -75,4 +78,7 @@
   ("OutputBitDepth,d", m_outputBitDepthY, 0, "bit depth of YUV output luma component (default: use 0 for native depth)")
   ("OutputBitDepthC,d", m_outputBitDepthC, 0, "bit depth of YUV output chroma component (default: use 0 for native depth)")
+#if H_MV
+  ("MaxLayerId,-ls", m_maxLayerId, MAX_NUM_LAYER_IDS-1, "Maximum LayerId to be decoded.")
+#endif
   ("MaxTemporalLayer,t", m_iMaxTemporalLayer, -1, "Maximum Temporal Layer to be decoded. -1 to decode all layers")
   ("SEIDecodedPictureHash", m_decodedPictureHashSEIEnabled, 1, "Control handling of decoded picture hash SEI messages\n"
@@ -151,7 +157,33 @@
     }
   }
+#if H_MV
+  else
+  {
+    for ( Int curLayerId = 0; curLayerId <= m_maxLayerId; curLayerId++ )
+    {
+      m_targetDecLayerIdSet.push_back( curLayerId );
+    }
+  }
+#endif
 
   return true;
 }
 
+#if H_MV
+Void TAppDecCfg::xAppendToFileNameEnd( Char* pchInputFileName, const Char* pchStringToAppend, Char*& rpchOutputFileName)
+{
+  size_t iInLength     = strlen(pchInputFileName);
+  size_t iAppendLength = strlen(pchStringToAppend); 
+
+  rpchOutputFileName = (Char*) malloc(iInLength+iAppendLength+1);                        
+  Char* pCDot = strrchr(pchInputFileName,'.');         
+  pCDot = pCDot ? pCDot : pchInputFileName + iInLength;        
+  size_t iCharsToDot = pCDot - pchInputFileName ; 
+  size_t iCharsToEnd = iInLength - iCharsToDot;         
+  strncpy(rpchOutputFileName                            ,  pchInputFileName            , iCharsToDot  );
+  strncpy(rpchOutputFileName+ iCharsToDot               ,  pchStringToAppend           , iAppendLength); 
+  strncpy(rpchOutputFileName+ iCharsToDot+iAppendLength ,  pchInputFileName+iCharsToDot, iCharsToEnd  );        
+  rpchOutputFileName[iInLength+iAppendLength] = '\0';          
+}
+#endif
 //! \}
Index: branches/HTM-DEV-0.1-dev/source/App/TAppDecoder/TAppDecCfg.h
===================================================================
--- branches/HTM-DEV-0.1-dev/source/App/TAppDecoder/TAppDecCfg.h	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/App/TAppDecoder/TAppDecCfg.h	(revision 368)
@@ -58,4 +58,8 @@
 protected:
   Char*         m_pchBitstreamFile;                   ///< input bitstream file name
+#if H_MV
+  Int           m_maxLayerId;                         ///< maximum nuh_layer_id decoded
+  std::vector<Char*> m_pchReconFiles;                 ///< array of output reconstruction file name create from output reconstruction file name
+#endif
   Char*         m_pchReconFile;                       ///< output reconstruction file name
   Int           m_iSkipFrame;                         ///< counter for frames prior to the random access point to skip
@@ -69,7 +73,14 @@
   Int           m_respectDefDispWindow;               ///< Only output content inside the default display window 
 
+#if H_MV
+  Void xAppendToFileNameEnd( Char* pchInputFileName, const Char* pchStringToAppend, Char*& rpchOutputFileName); ///< create filenames
+#endif
 public:
   TAppDecCfg()
   : m_pchBitstreamFile(NULL)
+#if H_MV
+  , m_maxLayerId(0)
+  , m_pchReconFiles(NULL) 
+#endif
   , m_pchReconFile(NULL)
   , m_iSkipFrame(0)
Index: branches/HTM-DEV-0.1-dev/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- branches/HTM-DEV-0.1-dev/source/App/TAppDecoder/TAppDecTop.cpp	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/App/TAppDecoder/TAppDecTop.cpp	(revision 368)
@@ -54,7 +54,14 @@
 
 TAppDecTop::TAppDecTop()
+#if !H_MV
 : m_iPOCLastDisplay(-MAX_INT)
+#else
+: m_numDecoders( 0 )
+#endif
 {
   ::memset (m_abDecFlag, 0, sizeof (m_abDecFlag));
+#if H_MV
+  for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++) m_layerIdToDecIdx[i] = -1; 
+#endif
 }
 
@@ -70,4 +77,14 @@
     m_pchBitstreamFile = NULL;
   }
+#if H_MV
+  for (Int decIdx = 0; decIdx < m_numDecoders; decIdx++)
+  {
+    if (m_pchReconFiles[decIdx])
+    {
+      free (m_pchReconFiles[decIdx]);
+      m_pchReconFiles[decIdx] = NULL;
+    }
+  }
+#endif
   if (m_pchReconFile)
   {
@@ -92,4 +109,7 @@
 {
   Int                 poc;
+#if H_MV
+  poc = -1; 
+#endif
   TComList<TComPic*>* pcListPic = NULL;
 
@@ -106,8 +126,21 @@
   xCreateDecLib();
   xInitDecLib  ();
+#if !H_MV
   m_iPOCLastDisplay += m_iSkipFrame;      // set the last displayed POC correctly for skip forward.
 
   // main decoder loop
   Bool recon_opened = false; // reconstruction file not yet opened. (must be performed after SPS is seen)
+#else
+  Int  pocCurrPic        = -MAX_INT;     
+  Int  pocLastPic        = -MAX_INT;   
+  
+  Int  layerIdLastPic    = 0; 
+  Int  layerIdCurrPic    = 0; 
+
+  Int  decIdxLastPic     = 0; 
+  Int  decIdxCurrPic     = 0; 
+
+  Bool firstSlice        = true; 
+#endif
  
   while (!!bitstreamFile)
@@ -119,5 +152,7 @@
     streampos location = bitstreamFile.tellg();
     AnnexBStats stats = AnnexBStats();
+#if !H_MV
     Bool bPreviousPictureDecoded = false;
+#endif
 
     vector<uint8_t> nalUnit;
@@ -127,4 +162,9 @@
     // call actual decoding function
     Bool bNewPicture = false;
+#if H_MV
+    Bool newSliceDiffPoc   = false;
+    Bool newSliceDiffLayer = false;
+    Bool allLayersDecoded  = false;     
+#endif
     if (nalUnit.empty())
     {
@@ -139,4 +179,46 @@
     {
       read(nalu, nalUnit);
+#if H_MV      
+      Int decIdx     = xGetDecoderIdx( nalu.m_layerId , true );
+      
+      if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu) )
+      {
+        bNewPicture = false;
+      }
+      else
+      { 
+        newSliceDiffLayer = nalu.isSlice() && ( nalu.m_layerId != layerIdCurrPic ) && !firstSlice;
+        newSliceDiffPoc   = m_tDecTop[decIdx]->decode(nalu, m_iSkipFrame, m_pocLastDisplay[decIdx], newSliceDiffLayer );
+        // decode function only returns true when all of the following conditions are true
+        // - poc in particular layer changes
+        // - nalu does not belong to first slice in layer
+        // - nalu.isSlice() == true      
+
+        bNewPicture       = newSliceDiffLayer || newSliceDiffPoc; 
+
+        if ( nalu.isSlice() && firstSlice )
+        {
+          layerIdCurrPic = nalu.m_layerId; 
+          pocCurrPic     = m_tDecTop[decIdx]->getCurrPoc(); 
+          decIdxCurrPic  = decIdx; 
+          firstSlice     = false; 
+        }
+
+        if ( bNewPicture || !bitstreamFile )
+        { 
+          layerIdLastPic    = layerIdCurrPic;  
+          layerIdCurrPic    = nalu.m_layerId; 
+          
+          pocLastPic        = pocCurrPic; 
+          pocCurrPic        = m_tDecTop[decIdx]->getCurrPoc(); 
+          
+          decIdxLastPic     = decIdxCurrPic; 
+          decIdxCurrPic     = decIdx; 
+
+          allLayersDecoded = ( pocCurrPic != pocLastPic );
+        }
+
+        
+#else
       if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu)  )
       {
@@ -154,4 +236,5 @@
       {
         bNewPicture = m_cTDecTop.decode(nalu, m_iSkipFrame, m_iPOCLastDisplay);
+#endif
         if (bNewPicture)
         {
@@ -164,23 +247,52 @@
           bytestream.reset();
         }
+#if !H_MV
         bPreviousPictureDecoded = true; 
+#endif
       }
     }
     if (bNewPicture || !bitstreamFile)
     {
+#if H_MV
+      assert( decIdxLastPic != -1 ); 
+      m_tDecTop[decIdxLastPic]->endPicDecoding(poc, pcListPic, m_targetDecLayerIdSet );
+#else
       m_cTDecTop.executeLoopFilters(poc, pcListPic);
-    }
+#endif
+    }
+#if H_3D
+    if ( allLayersDecoded || !bitstreamFile )
+    {
+      for( Int dI = 0; dI < m_numDecoders; dI++ )
+      {
+        TComPic* picLastCoded = m_ivPicLists.getPic( m_tDecTop[dI]->getLayerId(), pocLastPic );
+        assert( picLastCoded != NULL );        
+        picLastCoded->compressMotion();         
+      }
+    }
+#endif
 
     if( pcListPic )
     {
+#if H_MV
+      if ( m_pchReconFiles[decIdxLastPic] && !m_reconOpen[decIdxLastPic] )
+#else
       if ( m_pchReconFile && !recon_opened )
+#endif
       {
         if (!m_outputBitDepthY) { m_outputBitDepthY = g_bitDepthY; }
         if (!m_outputBitDepthC) { m_outputBitDepthC = g_bitDepthC; }
 
+#if H_MV
+        m_tVideoIOYuvReconFile[decIdxLastPic]->open( m_pchReconFiles[decIdxLastPic], true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode
+        m_reconOpen[decIdxLastPic] = true;
+      }
+      if ( bNewPicture && newSliceDiffPoc && 
+#else
         m_cTVideoIOYuvReconFile.open( m_pchReconFile, true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode
         recon_opened = true;
       }
       if ( bNewPicture && 
+#endif
            (   nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL
             || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP
@@ -189,9 +301,24 @@
             || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP ) )
       {
+#if H_MV
+        xFlushOutput( pcListPic, decIdxLastPic );
+#else
         xFlushOutput( pcListPic );
+#endif
       }
       // write reconstruction to file
       if(bNewPicture)
       {
+#if H_MV
+        xWriteOutput( pcListPic, decIdxLastPic, nalu.m_temporalId );
+      }
+    }
+  }
+
+  for(UInt decIdx = 0; decIdx < m_numDecoders; decIdx++)
+  {
+    xFlushOutput( m_tDecTop[decIdx]->getListPic(), decIdx );
+  }
+#else
         xWriteOutput( pcListPic, nalu.m_temporalId );
       }
@@ -202,4 +329,5 @@
   // delete buffers
   m_cTDecTop.deletePicBuffer();
+#endif
      
   // destroy internal classes
@@ -213,10 +341,37 @@
 Void TAppDecTop::xCreateDecLib()
 {
+#if H_MV
+  // initialize global variables
+  initROM();  
+#else
   // create decoder class
   m_cTDecTop.create();
+#endif
 }
 
 Void TAppDecTop::xDestroyDecLib()
 {
+#if H_MV
+  // destroy ROM
+  destroyROM();
+
+  for(Int decIdx = 0; decIdx < m_numDecoders ; decIdx++)
+  {
+    if( m_tVideoIOYuvReconFile[decIdx] )
+    {
+      m_tVideoIOYuvReconFile[decIdx]->close();
+      delete m_tVideoIOYuvReconFile[decIdx]; 
+      m_tVideoIOYuvReconFile[decIdx] = NULL ;
+    }
+
+    if( m_tDecTop[decIdx] )
+    {
+      m_tDecTop[decIdx]->deletePicBuffer();
+      m_tDecTop[decIdx]->destroy() ;
+    }
+    delete m_tDecTop[decIdx] ; 
+    m_tDecTop[decIdx] = NULL ;
+  }
+#else
   if ( m_pchReconFile )
   {
@@ -226,11 +381,14 @@
   // destroy decoder class
   m_cTDecTop.destroy();
+#endif
 }
 
 Void TAppDecTop::xInitDecLib()
 {
+#if !H_MV
   // initialize decoder class
   m_cTDecTop.init();
   m_cTDecTop.setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
+#endif
 }
 
@@ -238,5 +396,9 @@
     \todo            DYN_REF_FREE should be revised
  */
+#if H_MV
+Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, Int decIdx, Int tId )
+#else
 Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, UInt tId )
+#endif
 {
   TComList<TComPic*>::iterator iterPic   = pcListPic->begin();
@@ -246,5 +408,9 @@
   {
     TComPic* pcPic = *(iterPic);
+#if H_MV
+    if(pcPic->getOutputMark() && pcPic->getPOC() > m_pocLastDisplay[decIdx])
+#else
     if(pcPic->getOutputMark() && pcPic->getPOC() > m_iPOCLastDisplay)
+#endif
     {
        not_displayed++;
@@ -258,13 +424,25 @@
     TComPic* pcPic = *(iterPic);
     
+#if H_MV
+    if ( pcPic->getOutputMark() && (not_displayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_pocLastDisplay[decIdx]))
+#else
     if ( pcPic->getOutputMark() && (not_displayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_iPOCLastDisplay))
+#endif
     {
       // write to file
        not_displayed--;
+#if H_MV
+      if ( m_pchReconFiles[decIdx] )
+#else
       if ( m_pchReconFile )
+#endif
       {
         const Window &conf = pcPic->getConformanceWindow();
         const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
+#if H_MV
+        m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(),
+#else
         m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(),
+#endif
                                        conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
                                        conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
@@ -274,5 +452,9 @@
       
       // update POC of display order
+#if H_MV
+      m_pocLastDisplay[decIdx] = pcPic->getPOC();
+#else
       m_iPOCLastDisplay = pcPic->getPOC();
+#endif
       
       // erase non-referenced picture in the reference picture list after display
@@ -302,5 +484,9 @@
     \todo            DYN_REF_FREE should be revised
  */
+#if H_MV
+Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic, Int decIdx )
+#else
 Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic )
+#endif
 {
   if(!pcListPic)
@@ -319,9 +505,17 @@
     {
       // write to file
+#if H_MV
+      if ( m_pchReconFiles[decIdx] )
+#else
       if ( m_pchReconFile )
+#endif
       {
         const Window &conf = pcPic->getConformanceWindow();
         const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
+#if H_MV
+        m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(),
+#else
         m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(),
+#endif
                                        conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
                                        conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
@@ -331,5 +525,9 @@
       
       // update POC of display order
+#if H_MV
+      m_pocLastDisplay[decIdx] = pcPic->getPOC();
+#else
       m_iPOCLastDisplay = pcPic->getPOC();
+#endif
       
       // erase non-referenced picture in the reference picture list after display
@@ -351,4 +549,5 @@
       pcPic->setOutputMark(false);
     }
+#if !H_MV
 #if !DYN_REF_FREE
     if(pcPic)
@@ -359,8 +558,13 @@
     }
 #endif 
+#endif
     iterPic++;
   }
+#if H_MV
+  m_pocLastDisplay[decIdx] = -MAX_INT;
+#else
   pcListPic->clear();
   m_iPOCLastDisplay = -MAX_INT;
+#endif
 }
 
@@ -375,5 +579,9 @@
   for (std::vector<Int>::iterator it = m_targetDecLayerIdSet.begin(); it != m_targetDecLayerIdSet.end(); it++)
   {
+#if H_MV
+    if ( nalu->m_layerId == (*it) )
+#else
     if ( nalu->m_reservedZero6Bits == (*it) )
+#endif
     {
       return true;
Index: branches/HTM-DEV-0.1-dev/source/App/TAppDecoder/TAppDecTop.h
===================================================================
--- branches/HTM-DEV-0.1-dev/source/App/TAppDecoder/TAppDecTop.h	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/App/TAppDecoder/TAppDecTop.h	(revision 368)
@@ -61,10 +61,23 @@
 private:
   // class interface
+#if H_MV
+  TDecTop*                        m_tDecTop             [ MAX_NUM_LAYERS ];    ///< decoder classes
+  TVideoIOYuv*                    m_tVideoIOYuvReconFile[ MAX_NUM_LAYERS ];    ///< reconstruction YUV class
+  Int                             m_layerIdToDecIdx     [ MAX_NUM_LAYER_IDS ]; ///< maping from layer id to decoder index
+  Int                             m_numDecoders;                               ///< number of decoder instances
+  TComPicLists                    m_ivPicLists;                                ///< picture buffers of decoder instances
+#else
   TDecTop                         m_cTDecTop;                     ///< decoder class
   TVideoIOYuv                     m_cTVideoIOYuvReconFile;        ///< reconstruction YUV class
+#endif
   
   // for output control
   Bool                            m_abDecFlag[ MAX_GOP ];         ///< decoded flag in one GOP
+#if H_MV
+  Int                             m_pocLastDisplay      [ MAX_NUM_LAYERS ]; ///< last POC in display order
+  Bool                            m_reconOpen           [ MAX_NUM_LAYERS ]; ///< reconstruction file opened
+#else
   Int                             m_iPOCLastDisplay;              ///< last POC in display order
+#endif
   
 public:
@@ -81,6 +94,61 @@
   Void  xInitDecLib       (); ///< initialize decoder class
   
+#if H_MV
+  Void  xWriteOutput      ( TComList<TComPic*>* pcListPic, Int layerId, Int tId ); ///< write YUV to file
+  Void  xFlushOutput      ( TComList<TComPic*>* pcListPic, Int layerId ); ///< flush all remaining decoded pictures to file
+  Int   xGetDecoderIdx    ( Int layerId, Bool createFlag = false )
+  { 
+    Int decIdx = -1; 
+    if ( m_layerIdToDecIdx[ layerId ] != -1 ) 
+    {      
+      decIdx = m_layerIdToDecIdx[ layerId ]; 
+    }
+    else
+    {      
+      assert ( createFlag ); 
+      assert( m_numDecoders < MAX_NUM_LAYERS ); 
+
+      decIdx = m_numDecoders; 
+      
+      // Init decoder
+      m_tDecTop[ decIdx ] =  new TDecTop;
+      m_tDecTop[ decIdx ]->create();
+      m_tDecTop[ decIdx ]->init( );
+      m_tDecTop[ decIdx ]->setLayerId( layerId );
+      m_tDecTop[ decIdx ]->setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
+      m_tDecTop[ decIdx ]->setIvPicLists( &m_ivPicLists ); 
+     
+      // append pic list of new decoder to PicLists 
+      assert( m_ivPicLists.size() == m_numDecoders );
+      m_ivPicLists.push_back( m_tDecTop[ decIdx ]->getListPic() );
+
+      // create recon file related stuff      
+      Char* pchTempFilename = NULL;
+      if ( m_pchReconFile )
+      {      
+        Char buffer[4];      
+        sprintf(buffer,"_%i", layerId );
+        assert ( m_pchReconFile ); 
+        xAppendToFileNameEnd( m_pchReconFile , buffer, pchTempFilename );
+        assert( m_pchReconFiles.size() == m_numDecoders );
+      }
+
+      m_pchReconFiles.push_back( pchTempFilename );   
+
+      m_tVideoIOYuvReconFile[ decIdx ] = new TVideoIOYuv;
+      m_reconOpen           [ decIdx ] = false;
+
+      // set others 
+      m_pocLastDisplay      [ decIdx ] = -MAX_INT;
+      m_layerIdToDecIdx     [ layerId ] = decIdx; 
+
+      m_numDecoders++; 
+    };
+    return decIdx; 
+  }
+#else
   Void  xWriteOutput      ( TComList<TComPic*>* pcListPic , UInt tId); ///< write YUV to file
   Void  xFlushOutput      ( TComList<TComPic*>* pcListPic ); ///< flush all remaining decoded pictures to file
+#endif
   Bool  isNaluWithinTargetDecLayerIdSet ( InputNALUnit* nalu ); ///< check whether given Nalu is within targetDecLayerIdSet
 };
Index: branches/HTM-DEV-0.1-dev/source/App/TAppDecoder/decmain.cpp
===================================================================
--- branches/HTM-DEV-0.1-dev/source/App/TAppDecoder/decmain.cpp	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/App/TAppDecoder/decmain.cpp	(revision 368)
@@ -56,5 +56,9 @@
   // print information
   fprintf( stdout, "\n" );
+#if H_MV
+  fprintf( stdout, "3D-HTM Software: Decoder Version [%s] based on HM Version [%s]", NV_VERSION, HM_VERSION );  
+#else
   fprintf( stdout, "HM software: Decoder Version [%s]", NV_VERSION );
+#endif
   fprintf( stdout, NVM_ONOS );
   fprintf( stdout, NVM_COMPILEDBY );
Index: branches/HTM-DEV-0.1-dev/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- branches/HTM-DEV-0.1-dev/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 368)
@@ -64,7 +64,11 @@
 
 TAppEncCfg::TAppEncCfg()
+#if H_MV
+: m_pchBitstreamFile()
+#else
 : m_pchInputFile()
 , m_pchBitstreamFile()
 , m_pchReconFile()
+#endif
 , m_pchdQPFile()
 , m_pColumnWidth()
@@ -72,5 +76,7 @@
 , m_scalingListFile()
 {
+#if !H_MV
   m_aidQP = NULL;
+#endif
 #if J0149_TONE_MAPPING_SEI
   m_startOfCodedInterval = NULL;
@@ -82,8 +88,24 @@
 TAppEncCfg::~TAppEncCfg()
 {
+#if H_MV
+  for( Int layer = 0; layer < m_aidQP.size(); layer++ )
+  {
+    if ( m_aidQP[layer] != NULL )
+    {
+      delete[] m_aidQP[layer];
+      m_aidQP[layer] = NULL;
+    }
+  }
+  for(Int i = 0; i< m_pchInputFileList.size(); i++ )
+  {
+    if ( m_pchInputFileList[i] != NULL )
+      free (m_pchInputFileList[i]);
+  }
+#else
   if ( m_aidQP )
   {
     delete[] m_aidQP;
   }
+#endif
 #if J0149_TONE_MAPPING_SEI
   if ( m_startOfCodedInterval )
@@ -103,11 +125,31 @@
   }
 #endif
+#if !H_MV
   free(m_pchInputFile);
+#endif
   free(m_pchBitstreamFile);
+#if H_MV
+  for(Int i = 0; i< m_pchReconFileList.size(); i++ )
+  {
+    if ( m_pchReconFileList[i] != NULL )
+      free (m_pchReconFileList[i]);
+  }
+#else
   free(m_pchReconFile);
+#endif
   free(m_pchdQPFile);
   free(m_pColumnWidth);
   free(m_pRowHeight);
   free(m_scalingListFile);
+#if H_MV
+  for( Int i = 0; i < m_GOPListMvc.size(); i++ )
+  {
+    if( m_GOPListMvc[i] )
+    {
+      delete[] m_GOPListMvc[i];
+      m_GOPListMvc[i] = NULL;
+    }
+  }
+#endif
 }
 
@@ -161,4 +203,19 @@
   }
 #endif
+#if H_MV
+  in>>entry.m_numInterViewRefPics;
+  for( Int i = 0; i < entry.m_numInterViewRefPics; i++ )
+  {
+    in>>entry.m_interViewRefs[i];
+  }
+  for( Int i = 0; i < entry.m_numInterViewRefPics; i++ )
+  {
+    in>>entry.m_interViewRefPosL[0][i];
+  }
+  for( Int i = 0; i < entry.m_numInterViewRefPics; i++ )
+  {
+    in>>entry.m_interViewRefPosL[1][i];
+  }
+#endif
   return in;
 }
@@ -172,4 +229,11 @@
   {"main10", Profile::MAIN10},
   {"main-still-picture", Profile::MAINSTILLPICTURE},
+#if H_MV
+  {"main-stereo",    Profile::MAINSTEREO},
+  {"main-multiview", Profile::MAINMULTIVIEW},
+#if H_3D
+  {"main-3d"    , Profile::MAIN3D},
+#endif
+#endif
 };
 
@@ -253,7 +317,20 @@
   Bool do_help = false;
   
+#if !H_MV
   string cfg_InputFile;
+#endif
   string cfg_BitstreamFile;
+#if !H_MV
   string cfg_ReconFile;
+#endif
+#if H_MV
+  vector<Int>   cfg_dimensionLength; 
+#if H_3D 
+  cfg_dimensionLength.push_back( 2  );  // depth
+  cfg_dimensionLength.push_back( 32 );  // texture 
+#else
+  cfg_dimensionLength.push_back( 64 ); 
+#endif 
+#endif
   string cfg_dQPFile;
   string cfg_ColumnWidth;
@@ -279,7 +356,30 @@
   
   // File, I/O and source parameters
+#if H_MV
+  ("InputFile_%d,i_%d",       m_pchInputFileList,       (char *) 0 , MAX_NUM_LAYER_IDS , "original Yuv input file name %d")
+#else
   ("InputFile,i",           cfg_InputFile,     string(""), "Original YUV input file name")
+#endif
   ("BitstreamFile,b",       cfg_BitstreamFile, string(""), "Bitstream output file name")
+#if H_MV
+  ("ReconFile_%d,o_%d",       m_pchReconFileList,       (char *) 0 , MAX_NUM_LAYER_IDS , "reconstructed Yuv output file name %d")
+#else
   ("ReconFile,o",           cfg_ReconFile,     string(""), "Reconstructed YUV output file name")
+#endif
+#if H_MV
+  ("NumberOfLayers",        m_numberOfLayers     , 1,                     "Number of layers")
+#if !H_3D
+  ("ScalabilityMask",       m_scalabilityMask    , 1                    , "Scalability Mask")    
+#else
+  ("ScalabilityMask",       m_scalabilityMask    , 3                    , "Scalability Mask, 1: Texture 3: Texture + Depth ")    
+#endif  
+  ("DimensionIdLen",        m_dimensionIdLen     , cfg_dimensionLength  , "Number of bits used to store dimensions Id")
+  ("ViewId",                m_viewId             , std::vector<Int>(1,0), "View Id")
+#if H_3D
+  ("DepthFlag",             m_depthFlag          , std::vector<Int>(1,0), "Depth Flag")
+#endif
+  ("LayerIdInNuh",          m_layerIdInNuh       , std::vector<Int>(1,0), "LayerId in Nuh")
+  ("SplittingFlag",         m_splittingFlag      , false                , "Splitting Flag")    
+#endif
   ("SourceWidth,-wdt",      m_iSourceWidth,        0, "Source picture width")
   ("SourceHeight,-hgt",     m_iSourceHeight,       0, "Source picture height")
@@ -353,5 +453,9 @@
 
   /* Quantization parameters */
+#if H_MV
+  ("QP,q",          m_fQP, std::vector<double>(1,30.0), "Qp values for each layer, if value is float, QP is switched once during encoding")
+#else
   ("QP,q",          m_fQP,             30.0, "Qp value, if value is float, QP is switched once during encoding")
+#endif
   ("DeltaQpRD,-dqr",m_uiDeltaQpRD,       0u, "max dQp offset for slice")
   ("MaxDeltaQP,d",  m_iMaxDeltaQP,        0, "max dQp offset for block")
@@ -377,5 +481,9 @@
   
   // Deblocking filter parameters
+#if H_MV
+  ("LoopFilterDisable",              m_bLoopFilterDisable,             std::vector<Bool>(1,false), "Disable Loop Filter per Layer" )
+#else
   ("LoopFilterDisable",              m_bLoopFilterDisable,             false )
+#endif
   ("LoopFilterOffsetInPPS",          m_loopFilterOffsetInPPS,          false )
   ("LoopFilterBetaOffset_div2",      m_loopFilterBetaOffsetDiv2,           0 )
@@ -390,5 +498,9 @@
   ("TransformSkip",            m_useTransformSkip,          false, "Intra transform skipping")
   ("TransformSkipFast",        m_useTransformSkipFast,      false, "Fast intra transform skipping")
+#if H_MV
+  ("SAO",                      m_bUseSAO, std::vector<Bool>(1,true), "Enable Sample Adaptive Offset per Layer")
+#else
   ("SAO",                      m_bUseSAO,                   true,  "Enable Sample Adaptive Offset")
+#endif
   ("MaxNumOffsetsPerPic",      m_maxNumOffsetsPerPic,       2048,  "Max number of SAO offset per picture (Default: 2048)")   
   ("SAOLcuBoundary",           m_saoLcuBoundary,            false, "0: right/bottom LCU boundary areas skipped from SAO parameter estimation, 1: non-deblocked pixels are used for those areas")
@@ -572,4 +684,33 @@
   ;
   
+#if H_MV
+  // parse coding structure
+  for( Int k = 0; k < MAX_NUM_LAYERS; k++ )
+  {
+    m_GOPListMvc.push_back( new GOPEntry[MAX_GOP + 1] );
+    if( k == 0 )
+    {
+      for( Int i = 1; i < MAX_GOP + 1; i++ ) 
+      {
+        std::ostringstream cOSS;
+        cOSS<<"Frame"<<i;
+        opts.addOptions()( cOSS.str(), m_GOPListMvc[k][i-1], GOPEntry() );
+      }
+    }
+    else
+    {
+      std::ostringstream cOSS1;
+      cOSS1<<"FrameI"<<"_l"<<k;
+      opts.addOptions()(cOSS1.str(), m_GOPListMvc[k][MAX_GOP], GOPEntry());
+
+      for( Int i = 1; i < MAX_GOP + 1; i++ ) 
+      {
+        std::ostringstream cOSS2;
+        cOSS2<<"Frame"<<i<<"_l"<<k;
+        opts.addOptions()(cOSS2.str(), m_GOPListMvc[k][i-1], GOPEntry());
+      }
+    }
+  }
+#else
   for(Int i=1; i<MAX_GOP+1; i++) {
     std::ostringstream cOSS;
@@ -577,4 +718,5 @@
     opts.addOptions()(cOSS.str(), m_GOPList[i-1], GOPEntry());
   }
+#endif
   po::setDefaults(opts);
   const list<const Char*>& argv_unhandled = po::scanArgv(opts, argc, (const Char**) argv);
@@ -596,7 +738,11 @@
    */
   /* convert std::string to c string for compatability */
+#if !H_MV
   m_pchInputFile = cfg_InputFile.empty() ? NULL : strdup(cfg_InputFile.c_str());
+#endif
   m_pchBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str());
+#if !H_MV
   m_pchReconFile = cfg_ReconFile.empty() ? NULL : strdup(cfg_ReconFile.c_str());
+#endif
   m_pchdQPFile = cfg_dQPFile.empty() ? NULL : strdup(cfg_dQPFile.c_str());
   
@@ -658,4 +804,8 @@
     m_pRowHeight = NULL;
   }
+#if H_MV
+  free ( pColumnWidth );
+  free ( pRowHeight   ); 
+#endif
 #if SIGNAL_BITRATE_PICRATE_IN_VPS
   readBoolString(cfg_bitRateInfoPresentFlag, m_bitRatePicRateMaxTLayers, m_bitRateInfoPresentFlag, "bit rate info. present flag" );
@@ -737,4 +887,36 @@
   
   // allocate slice-based dQP values
+#if H_MV
+  xResizeVector( m_viewId    ); 
+#if H_3D
+  xResizeVector( m_depthFlag ); 
+#endif
+
+  xResizeVector( m_fQP ); 
+
+  for( Int layer = 0; layer < m_numberOfLayers; layer++ )
+  {
+    m_aidQP.push_back( new Int[ m_framesToBeEncoded + m_iGOPSize + 1 ] );
+    ::memset( m_aidQP[layer], 0, sizeof(Int)*( m_framesToBeEncoded + m_iGOPSize + 1 ) );
+
+    // handling of floating-point QP values
+    // if QP is not integer, sequence is split into two sections having QP and QP+1
+    m_iQP.push_back((Int)( m_fQP[layer] ));
+    if ( m_iQP[layer] < m_fQP[layer] )
+    {
+      Int iSwitchPOC = (Int)( m_framesToBeEncoded - (m_fQP[layer] - m_iQP[layer])*m_framesToBeEncoded + 0.5 );
+
+      iSwitchPOC = (Int)( (Double)iSwitchPOC / m_iGOPSize + 0.5 )*m_iGOPSize;
+      for ( Int i=iSwitchPOC; i<m_framesToBeEncoded + m_iGOPSize + 1; i++ )
+      {
+        m_aidQP[layer][i] = 1;
+      }
+    }
+  }
+
+  xResizeVector( m_bLoopFilterDisable ); 
+  xResizeVector( m_bUseSAO );   
+
+#else
   m_aidQP = new Int[ m_framesToBeEncoded + m_iGOPSize + 1 ];
   ::memset( m_aidQP, 0, sizeof(Int)*( m_framesToBeEncoded + m_iGOPSize + 1 ) );
@@ -753,4 +935,5 @@
     }
   }
+#endif
   
   // reading external dQP description from file
@@ -760,4 +943,8 @@
     if ( fpt )
     {
+#if H_MV
+      for( Int layer = 0; layer < m_numberOfLayers; layer++ )
+      {
+#endif
       Int iValue;
       Int iPOC = 0;
@@ -765,6 +952,12 @@
       {
         if ( fscanf(fpt, "%d", &iValue ) == EOF ) break;
+#if H_MV
+        m_aidQP[layer][ iPOC ] = iValue;
+        iPOC++;
+      }
+#else
         m_aidQP[ iPOC ] = iValue;
         iPOC++;
+#endif
       }
       fclose(fpt);
@@ -932,9 +1125,85 @@
   xConfirmPara( m_iFrameRate <= 0,                                                          "Frame rate must be more than 1" );
   xConfirmPara( m_framesToBeEncoded <= 0,                                                   "Total Number Of Frames encoded must be more than 0" );
+#if H_MV
+  xConfirmPara( m_numberOfLayers > MAX_NUM_LAYER_IDS ,                                      "NumberOfLayers must be less than or equal to MAX_NUM_LAYER_IDS");
+
+
+  xConfirmPara( m_layerIdInNuh[0] != 0      , "LayerIdInNuh must be 0 for the first layer. ");
+  xConfirmPara( (m_layerIdInNuh.size()!=1) && (m_layerIdInNuh.size() < m_numberOfLayers) , "LayerIdInNuh must be given for all layers. ");
+  
+#if H_3D
+  xConfirmPara( m_scalabilityMask != 1 && m_scalabilityMask != 3, "Scalability Mask must be equal to 1 or 3. ");
+#else
+  xConfirmPara( m_scalabilityMask != 1 , "Scalability Mask must be equal to 1. ");
+#endif
+ 
+  m_dimIds.push_back( m_viewId ); 
+#if H_3D
+  if ( m_scalabilityMask & ( 1 << DEPTH_ID ) )
+    m_dimIds.push_back( m_depthFlag ); 
+#endif
+
+  xConfirmPara(  m_dimensionIdLen.size() < m_dimIds.size(), "DimensionIdLen must be given for all dimensions. "   ); 
+
+ for( Int dim = 0; dim < m_dimIds.size(); dim++ )
+ {
+   xConfirmPara( m_dimIds[dim].size() < m_numberOfLayers,  "DimensionId must be given for all layers and all dimensions. ");
+   xConfirmPara( m_dimIds[dim][0] != 0,                    "DimensionId of layer 0 must be 0 in all dimensions. " );
+   xConfirmPara( m_dimensionIdLen[dim] < 1 || m_dimensionIdLen[dim] > 8, "DimensionIdLen must be greater than 0 and less than 9 in all dimensions. " ); 
+   for( Int i = 1; i < m_numberOfLayers; i++ )
+   {     
+     xConfirmPara(  ( m_dimIds[dim][i] < 0 ) || ( m_dimIds[dim][i] > ( ( 1 << m_dimensionIdLen[dim] ) - 1 ) )   , "DimensionId shall be in the range of 0 to 2^DimensionIdLen - 1. " );
+   }
+ }
+
+ for( Int i = 0; i < m_numberOfLayers; i++ )
+ {
+   for( Int j = 0; j < i; j++ )
+   {     
+     Int numDiff  = 0; 
+     Int lastDiff = -1; 
+     for( Int dim = 0; dim < m_dimIds.size(); dim++ )
+     {
+       if ( m_dimIds[dim][i] != m_dimIds[dim][j] )
+       {
+         numDiff ++; 
+         lastDiff = dim; 
+       }
+     }
+
+     Bool allEqual = ( numDiff == 0 ); 
+
+     if ( allEqual ) 
+     {
+       printf( "\nError: Positions of Layers %d and %d are identical in scalability space\n", i, j);
+     }
+
+     xConfirmPara( allEqual , "Each layer shall have a different position in scalability space." );
+
+     if ( numDiff  == 1 ) 
+     {
+       Bool inc = m_dimIds[ lastDiff ][ i ] > m_dimIds[ lastDiff ][ j ]; 
+       if ( !inc )
+       {       
+         printf( "\nError: Positions of Layers %d and %d is not increasing in dimension %d \n", i, j, lastDiff);        
+       }
+       xConfirmPara( !inc,  "DimensionIds shall be increasing within one dimension. " );
+     }
+   }
+ }
+
+#endif
   xConfirmPara( m_iGOPSize < 1 ,                                                            "GOP Size must be greater or equal to 1" );
   xConfirmPara( m_iGOPSize > 1 &&  m_iGOPSize % 2,                                          "GOP Size must be a multiple of 2, if GOP Size is greater than 1" );
   xConfirmPara( (m_iIntraPeriod > 0 && m_iIntraPeriod < m_iGOPSize) || m_iIntraPeriod == 0, "Intra period must be more than GOP size, or -1 , not 0" );
   xConfirmPara( m_iDecodingRefreshType < 0 || m_iDecodingRefreshType > 2,                   "Decoding Refresh Type must be equal to 0, 1 or 2" );
+#if H_MV
+  for( Int layer = 0; layer < m_numberOfLayers; layer++ )
+  {
+    xConfirmPara( m_iQP[layer] <  -6 * (m_internalBitDepthY - 8) || m_iQP[layer] > 51,      "QP exceeds supported range (-QpBDOffsety to 51)" );
+  }
+#else
   xConfirmPara( m_iQP <  -6 * (m_internalBitDepthY - 8) || m_iQP > 51,                    "QP exceeds supported range (-QpBDOffsety to 51)" );
+#endif
   xConfirmPara( m_loopFilterBetaOffsetDiv2 < -13 || m_loopFilterBetaOffsetDiv2 > 13,          "Loop Filter Beta Offset div. 2 exceeds supported range (-13 to 13)");
   xConfirmPara( m_loopFilterTcOffsetDiv2 < -13 || m_loopFilterTcOffsetDiv2 > 13,              "Loop Filter Tc Offset div. 2 exceeds supported range (-13 to 13)");
@@ -980,5 +1249,12 @@
 
 #if ADAPTIVE_QP_SELECTION
+#if H_MV
+  for( Int layer = 0; layer < m_numberOfLayers; layer++ )
+  {
+    xConfirmPara( m_bUseAdaptQpSelect == true && m_iQP[layer] < 0,                                     "AdaptiveQpSelection must be disabled when QP < 0.");
+  }
+#else
   xConfirmPara( m_bUseAdaptQpSelect == true && m_iQP < 0,                                              "AdaptiveQpSelection must be disabled when QP < 0.");
+#endif
   xConfirmPara( m_bUseAdaptQpSelect == true && (m_cbQpOffset !=0 || m_crQpOffset != 0 ),               "AdaptiveQpSelection must be disabled when ChromaQpOffset is not equal to 0.");
 #endif
@@ -1034,4 +1310,151 @@
   }
 
+#if H_MV
+  // validate that POC of same frame is identical across multiple layers
+  Bool bErrorMvePoc = false;
+  if( m_numberOfLayers > 1 )
+  {
+    for( Int k = 1; k < m_numberOfLayers; k++ )
+    {
+      for( Int i = 0; i < MAX_GOP; i++ )
+      {
+        if( m_GOPListMvc[k][i].m_POC != m_GOPListMvc[0][i].m_POC )
+        {
+          printf( "\nError: Frame%d_l%d POC %d is not identical to Frame%d POC\n", i, k, m_GOPListMvc[k][i].m_POC, i );
+          bErrorMvePoc = true;
+        }
+      }
+    }
+  }
+  xConfirmPara( bErrorMvePoc,  "Invalid inter-layer POC structure given" );
+
+  // validate that baseview has no inter-view refs 
+  Bool bErrorIvpBase = false;
+  for( Int i = 0; i < MAX_GOP; i++ )
+  {
+    if( m_GOPListMvc[0][i].m_numInterViewRefPics != 0 )
+    {
+      printf( "\nError: Frame%d inter_layer refs not available in layer 0\n", i );
+      bErrorIvpBase = true;
+    }
+  }
+  xConfirmPara( bErrorIvpBase, "Inter-layer refs not possible in base layer" );
+
+  // validate inter-view refs
+  Bool bErrorIvpEnhV = false;
+  if( m_numberOfLayers > 1 )
+  {
+    for( Int k = 1; k < m_numberOfLayers; k++ )
+    {
+      for( Int i = 0; i < MAX_GOP+1; i++ )
+      {
+        for( Int j = 0; j < m_GOPListMvc[k][i].m_numInterViewRefPics; j++ )
+        {
+          Int iAbsViewId = m_GOPListMvc[k][i].m_interViewRefs[j] + k;
+          if( iAbsViewId < 0 || iAbsViewId >= k )
+          {
+            printf( "\nError: inter-layer ref pic %d is not available for Frame%d_l%d\n", m_GOPListMvc[k][i].m_interViewRefs[j], i, k );
+            bErrorIvpEnhV = true;
+          }
+          if( m_GOPListMvc[k][i].m_interViewRefPosL[0][j] < -1 || m_GOPListMvc[k][i].m_interViewRefPosL[0][j] > m_GOPListMvc[k][i].m_numRefPicsActive )
+          {
+            printf( "\nError: inter-layer ref pos %d on L0 is not available for Frame%d_l%d\n", m_GOPListMvc[k][i].m_interViewRefPosL[0][j], i, k );
+            bErrorIvpEnhV = true;
+          }
+          if( m_GOPListMvc[k][i].m_interViewRefPosL[1][j] < -1  || m_GOPListMvc[k][i].m_interViewRefPosL[1][j] > m_GOPListMvc[k][i].m_numRefPicsActive )
+          {
+            printf( "\nError: inter-layer ref pos %d on L1 is not available for Frame%d_l%d\n", m_GOPListMvc[k][i].m_interViewRefPosL[1][j], i, k );
+            bErrorIvpEnhV = true;
+          }
+        }
+        if( i == MAX_GOP ) // inter-view refs at I pic position in base view
+        {
+          if( m_GOPListMvc[k][MAX_GOP].m_sliceType != 'B' && m_GOPListMvc[k][MAX_GOP].m_sliceType != 'P' && m_GOPListMvc[k][MAX_GOP].m_sliceType != 'I' )
+          {
+            printf( "\nError: slice type of FrameI_l%d must be equal to B or P or I\n", k );
+            bErrorIvpEnhV = true;
+          }
+
+          if( m_GOPListMvc[k][MAX_GOP].m_POC != 0 )
+          {
+            printf( "\nError: POC %d not possible for FrameI_l%d, must be 0\n", m_GOPListMvc[k][MAX_GOP].m_POC, k );
+            bErrorIvpEnhV = true;
+          }
+
+          if( m_GOPListMvc[k][MAX_GOP].m_temporalId != 0 )
+          {
+            printf( "\nWarning: Temporal id of FrameI_l%d must be 0 (cp. I-frame in base layer)\n", k );
+            m_GOPListMvc[k][MAX_GOP].m_temporalId = 0;
+          }
+
+          if( m_GOPListMvc[k][MAX_GOP].m_numRefPics != 0 )
+          {
+            printf( "\nWarning: temporal references not possible for FrameI_l%d\n", k );
+            for( Int j = 0; j < m_GOPListMvc[k][MAX_GOP].m_numRefPics; j++ )
+            {
+              m_GOPListMvc[k][MAX_GOP].m_referencePics[j] = 0;
+            }
+            m_GOPListMvc[k][MAX_GOP].m_numRefPics = 0;
+          }
+
+          if( m_GOPListMvc[k][MAX_GOP].m_interRPSPrediction )
+          {
+            printf( "\nError: inter RPS prediction not possible for FrameI_l%d, must be 0\n", k );
+            bErrorIvpEnhV = true;
+          }
+
+          if( m_GOPListMvc[k][MAX_GOP].m_sliceType == 'I' && m_GOPListMvc[k][MAX_GOP].m_numInterViewRefPics != 0 )
+          {
+            printf( "\nError: inter-layer prediction not possible for FrameI_l%d with slice type I, #IL_ref_pics must be 0\n", k );
+            bErrorIvpEnhV = true;
+          }
+
+          if( m_GOPListMvc[k][MAX_GOP].m_numRefPicsActive > m_GOPListMvc[k][MAX_GOP].m_numInterViewRefPics )
+          {
+            m_GOPListMvc[k][MAX_GOP].m_numRefPicsActive = m_GOPListMvc[k][MAX_GOP].m_numInterViewRefPics;
+          }
+
+          if( m_GOPListMvc[k][MAX_GOP].m_sliceType == 'P' )
+          {
+            if( m_GOPListMvc[k][MAX_GOP].m_numInterViewRefPics < 1 )
+            {
+              printf( "\nError: #IL_ref_pics must be at least one for FrameI_l%d with slice type P\n", k );
+              bErrorIvpEnhV = true;
+            }
+            else
+            {
+              for( Int j = 0; j < m_GOPListMvc[k][MAX_GOP].m_numInterViewRefPics; j++ )
+              {
+                if( m_GOPListMvc[k][MAX_GOP].m_interViewRefPosL[1][j] != -1 )
+                {
+                  printf( "\nError: inter-layer ref pos %d on L1 not possible for FrameI_l%d with slice type P\n", m_GOPListMvc[k][MAX_GOP].m_interViewRefPosL[1][j], k );
+                  bErrorIvpEnhV = true;
+                }
+              }
+            }
+          }
+
+          if( m_GOPListMvc[k][MAX_GOP].m_sliceType == 'B' && m_GOPListMvc[k][MAX_GOP].m_numInterViewRefPics < 1 )
+          {
+            printf( "\nError: #IL_ref_pics must be at least one for FrameI_l%d with slice type B\n", k );
+            bErrorIvpEnhV = true;
+          }
+        }
+      }
+    }
+  }
+  xConfirmPara( bErrorIvpEnhV, "Invalid inter-layer coding structure for enhancement layers given" );
+
+  // validate temporal coding structure
+  if( !bErrorMvePoc && !bErrorIvpBase && !bErrorIvpEnhV )
+  {
+    for( Int layer = 0; layer < m_numberOfLayers; layer++ )
+    {
+      GOPEntry* m_GOPList            = m_GOPListMvc           [layer]; // It is not a member, but this name helps avoiding code duplication !!!
+      Int&      m_extraRPSs          = m_extraRPSsMvc         [layer]; // It is not a member, but this name helps avoiding code duplication !!!
+      Int&      m_maxTempLayer       = m_maxTempLayerMvc      [layer]; // It is not a member, but this name helps avoiding code duplication !!!
+      Int*      m_maxDecPicBuffering = m_maxDecPicBufferingMvc[layer]; // It is not a member, but this name helps avoiding code duplication !!!
+      Int*      m_numReorderPics     = m_numReorderPicsMvc    [layer]; // It is not a member, but this name helps avoiding code duplication !!!
+#endif
   /* if this is an intra-only sequence, ie IntraPeriod=1, don't verify the GOP structure
    * This permits the ability to omit a GOP structure specification */
@@ -1067,5 +1490,9 @@
   }
   
+#if H_MV
+  if ( (m_iIntraPeriod != 1) && !m_loopFilterOffsetInPPS && m_DeblockingFilterControlPresent && (!m_bLoopFilterDisable[layer]) )
+#else
   if ( (m_iIntraPeriod != 1) && !m_loopFilterOffsetInPPS && m_DeblockingFilterControlPresent && (!m_bLoopFilterDisable) )
+#endif
   {
     for(Int i=0; i<m_iGOPSize; i++)
@@ -1083,5 +1510,9 @@
     if(m_GOPList[curGOP].m_POC<0) 
     {
+#if H_MV
+      printf("\nError: found fewer Reference Picture Sets than GOPSize for layer %d\n", layer );
+#else
       printf("\nError: found fewer Reference Picture Sets than GOPSize\n");
+#endif
       errorGOP=true;
     }
@@ -1120,5 +1551,9 @@
           if(!found)
           {
+#if H_MV
+            printf("\nError: ref pic %d is not available for GOP frame %d of layer %d\n", m_GOPList[curGOP].m_referencePics[i], curGOP+1, layer);
+#else
             printf("\nError: ref pic %d is not available for GOP frame %d\n",m_GOPList[curGOP].m_referencePics[i],curGOP+1);
+#endif
             errorGOP=true;
           }
@@ -1497,4 +1932,8 @@
   }
 #endif
+#if H_MV
+  }
+  }
+#endif
 
 #undef xConfirmPara
@@ -1532,7 +1971,32 @@
 {
   printf("\n");
+#if H_MV
+  for( Int layer = 0; layer < m_numberOfLayers; layer++)
+  {
+    printf("Input File %i                 : %s\n", layer, m_pchInputFileList[layer]);
+  }
+#else
   printf("Input          File          : %s\n", m_pchInputFile          );
+#endif
   printf("Bitstream      File          : %s\n", m_pchBitstreamFile      );
+#if H_MV
+  for( Int layer = 0; layer < m_numberOfLayers; layer++)
+  {
+    printf("Reconstruction File %i        : %s\n", layer, m_pchReconFileList[layer]);
+  }
+#else
   printf("Reconstruction File          : %s\n", m_pchReconFile          );
+#endif
+#if H_MV
+ xPrintParaVector( "ViewId", m_viewId ); 
+#endif
+#if H_3D
+ xPrintParaVector( "DepthFlag", m_depthFlag ); 
+#endif
+#if H_MV  
+  xPrintParaVector( "QP"               , m_fQP                ); 
+  xPrintParaVector( "LoopFilterDisable", m_bLoopFilterDisable ); 
+  xPrintParaVector( "SAO"              , m_bUseSAO            ); 
+#endif
   printf("Real     Format              : %dx%d %dHz\n", m_iSourceWidth - m_confLeft - m_confRight, m_iSourceHeight - m_confTop - m_confBottom, m_iFrameRate );
   printf("Internal Format              : %dx%d %dHz\n", m_iSourceWidth, m_iSourceHeight, m_iFrameRate );
@@ -1546,5 +2010,7 @@
   printf("Intra period                 : %d\n", m_iIntraPeriod );
   printf("Decoding refresh type        : %d\n", m_iDecodingRefreshType );
+#if !H_MV
   printf("QP                           : %5.2f\n", m_fQP );
+#endif
   printf("Max dQP signaling depth      : %d\n", m_iMaxCuDQPDepth);
 
@@ -1611,5 +2077,7 @@
   }
   printf("CIP:%d ", m_bUseConstrainedIntraPred);
+#if !H_MV
   printf("SAO:%d ", (m_bUseSAO)?(1):(0));
+#endif
   printf("PCM:%d ", (m_usePCM && (1<<m_uiPCMLog2MinSize) <= m_uiMaxCUWidth)? 1 : 0);
   printf("SAOLcuBasedOptimization:%d ", (m_saoLcuBasedOptimization)?(1):(0));
Index: branches/HTM-DEV-0.1-dev/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- branches/HTM-DEV-0.1-dev/source/App/TAppEncoder/TAppEncCfg.h	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/App/TAppEncoder/TAppEncCfg.h	(revision 368)
@@ -55,8 +55,28 @@
 protected:
   // file I/O
+#if H_MV
+  std::vector<char*>     m_pchInputFileList;                  ///< source file names
+#else
   Char*     m_pchInputFile;                                   ///< source file name
+#endif
   Char*     m_pchBitstreamFile;                               ///< output bitstream file
+#if H_MV
+  std::vector<char*>     m_pchReconFileList;                  ///< output reconstruction file names
+  Int                    m_numberOfLayers;                    ///< number of Layers to Encode
+#else
   Char*     m_pchReconFile;                                   ///< output reconstruction file
+#endif
   // VPS specification
+#if H_MV
+  std::vector< std::vector<Int> > m_dimIds;                   ///< dimension ids ( pointers to m_viewId and m_depthFlag 
+  std::vector<Int>       m_viewId;                            ///< view id
+#if H_3D
+  std::vector<Int>       m_depthFlag;                         ///< depth flag
+#endif
+  std::vector<Int>       m_layerIdInNuh;                      ///< layer Id in Nuh for each layer 
+  Bool                   m_splittingFlag;                     ///< Splitting Flag
+  Int                    m_scalabilityMask;                   ///< Mask indicating scalabilities, 1: texture; 3: texture + depth                                                                
+  std::vector<Int>       m_dimensionIdLen;                   ///< Length of scalability dimension s 
+#endif
   Double    m_adLambdaModifier[ MAX_TLAYER ];                 ///< Lambda modifier array for each temporal layer
   // source specification
@@ -88,4 +108,10 @@
   Int       m_iDecodingRefreshType;                           ///< random access type
   Int       m_iGOPSize;                                       ///< GOP size of hierarchical structure
+#if H_MV
+  Int       m_extraRPSsMvc[MAX_NUM_LAYERS];                       ///< extra RPSs added to handle CRA for each layer
+  std::vector< GOPEntry* >  m_GOPListMvc;                            ///< the coding structure entries from the config file for each layer 
+  Int       m_numReorderPicsMvc[MAX_NUM_LAYERS][MAX_TLAYER];      ///< total number of reorder pictures for each layer
+  Int       m_maxDecPicBufferingMvc[MAX_NUM_LAYERS][MAX_TLAYER];  ///< total number of reference pictures needed for decoding for each layer
+#else
   Int       m_extraRPSs;                                      ///< extra RPSs added to handle CRA
   GOPEntry  m_GOPList[MAX_GOP];                               ///< the coding structure entries from the config file
@@ -96,4 +122,5 @@
   Int       m_maxDecPicBuffering[MAX_TLAYER];                 ///< total number of reference pictures needed for decoding
 #endif
+#endif
 #if !L0034_COMBINED_LIST_CLEANUP
   Bool      m_bUseLComb;                                      ///< flag for using combined reference list for uni-prediction in B-slices (JCTVC-D421)
@@ -103,8 +130,17 @@
   Bool      m_enableAMP;
   // coding quality
+#if H_MV
+  std::vector<Double>  m_fQP;                                 ///< QP value of key-picture (floating point) for each layer
+  std::vector<Int>     m_iQP;                                 ///< QP value of key-picture (integer) for each layer
+#else
   Double    m_fQP;                                            ///< QP value of key-picture (floating point)
   Int       m_iQP;                                            ///< QP value of key-picture (integer)
+#endif
   Char*     m_pchdQPFile;                                     ///< QP offset for each slice (initialized from external file)
+#if H_MV
+  std::vector<Int*> m_aidQP;                                    ///< array of slice QP values for each layer
+#else
   Int*      m_aidQP;                                          ///< array of slice QP values
+#endif
   Int       m_iMaxDeltaQP;                                    ///< max. |delta QP|
   UInt      m_uiDeltaQpRD;                                    ///< dQP range for multi-pass slice QP optimization
@@ -121,5 +157,9 @@
   Int       m_iQPAdaptationRange;                             ///< dQP range by QP adaptation
   
+#if H_MV
+  Int       m_maxTempLayerMvc[MAX_NUM_LAYER_IDS];             ///< Max temporal layer for each layer
+#else
   Int       m_maxTempLayer;                                  ///< Max temporal layer
+#endif
 
   // coding unit (CU) definition
@@ -148,10 +188,18 @@
   // coding tool (lossless)
   Bool      m_useLossless;                                    ///< flag for using lossless coding
+#if H_MV
+  std::vector<Bool> m_bUseSAO; 
+#else
   Bool      m_bUseSAO; 
+#endif
   Int       m_maxNumOffsetsPerPic;                            ///< SAO maximun number of offset per picture
   Bool      m_saoLcuBoundary;                                 ///< SAO parameter estimation using non-deblocked pixels for LCU bottom and right boundary areas
   Bool      m_saoLcuBasedOptimization;                        ///< SAO LCU-based optimization
   // coding tools (loop filter)
+#if H_MV
+  std::vector<Bool> m_bLoopFilterDisable;                     ///< flag for using deblocking filter for each layer
+#else
   Bool      m_bLoopFilterDisable;                             ///< flag for using deblocking filter
+#endif
   Bool      m_loopFilterOffsetInPPS;                         ///< offset for deblocking filter in 0 = slice header, 1 = PPS
   Int       m_loopFilterBetaOffsetDiv2;                     ///< beta offset for deblocking filter
@@ -324,4 +372,45 @@
   Void  xPrintParameter ();                                   ///< print configuration values
   Void  xPrintUsage     ();                                   ///< print usage
+#if H_MV
+  template <typename T>
+  Void xResizeVector(  std::vector<T> & rpcVector )
+  {
+    for( Int layer = 0; rpcVector.size() < m_numberOfLayers; layer++ )
+    {
+      assert( rpcVector.size() > 0 );
+      rpcVector.push_back( rpcVector[layer] );      
+    }
+
+
+    for( ; rpcVector.size() > m_numberOfLayers; )
+    {      
+      rpcVector.pop_back( );      
+    }
+
+  }
+
+  template <typename T>
+  Void xPrintParaVector( std::string description, std::vector<T> & rpcVector )
+  {
+    Int iSpace = max(1, ENC_CFG_CONSOUT_SPACE - (Int) description.length() ); 
+    
+    for ( Int i = 0; i < iSpace; i++ ) 
+      description.append( " " ); 
+      
+    description.append( ":" ); 
+    printf( "%s", description.c_str() ); 
+
+    for(Int i=0;i<rpcVector.size();i++)                
+      xPrintVectorElem( rpcVector[i] );
+
+    printf("\n");
+  }
+  
+  Void xPrintVectorElem( UInt   elem ) { printf(" %d"   , elem            );};
+  Void xPrintVectorElem( Int    elem ) { printf(" %d"   , elem            );};
+  
+  Void xPrintVectorElem( Double elem ) { printf(" %5.2f", elem            );};  
+  Void xPrintVectorElem( Bool   elem ) { printf(" %d"   , ( elem ? 1 : 0 ));};
+#endif
 #if SIGNAL_BITRATE_PICRATE_IN_VPS
   Int       m_bitRatePicRateMaxTLayers;                       ///< Indicates max. number of sub-layers for which bit rate is signalled.
@@ -333,4 +422,7 @@
   Int*      m_constantPicRateIdc;                                ///< Indicates constant picture rate idc for various sub-layers
 #endif
+#if H_MV
+  Int   getGOPSize() { return m_iGOPSize; }
+#endif
 public:
   TAppEncCfg();
Index: branches/HTM-DEV-0.1-dev/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- branches/HTM-DEV-0.1-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 368)
@@ -57,5 +57,7 @@
 TAppEncTop::TAppEncTop()
 {
+#if !H_MV
   m_iFrameRcvd = 0;
+#endif
   m_totalBytes = 0;
   m_essentialBytes = 0;
@@ -70,4 +72,31 @@
   TComVPS vps;
   
+#if H_MV
+  Int maxTempLayer = -1; 
+  for (Int j = 0; j < m_numberOfLayers; j++)
+  {
+    maxTempLayer = max( m_maxTempLayerMvc[ j ], maxTempLayer ); 
+  }
+
+  vps.setMaxTLayers                       ( maxTempLayer );
+  if ( maxTempLayer )
+  {
+    vps.setTemporalNestingFlag(true);
+  }
+  vps.setMaxLayers( m_numberOfLayers );
+  for(Int i = 0; i < MAX_TLAYER; i++)
+  {
+    Int maxNumReOrderPics  = 0; 
+    Int maxDecPicBuffering = 0;
+    for (Int j = 0; j < m_numberOfLayers; j++)
+    {
+      maxNumReOrderPics  = max( maxNumReOrderPics,  m_numReorderPicsMvc    [ j ][ i ] );     
+      maxDecPicBuffering = max( maxDecPicBuffering, m_maxDecPicBufferingMvc[ j ][ i ] );     
+    }
+
+    vps.setNumReorderPics                 ( maxNumReOrderPics  ,i );
+    vps.setMaxDecPicBuffering             ( maxDecPicBuffering ,i );
+  }
+#else
   vps.setMaxTLayers                       ( m_maxTempLayer );
   if (m_maxTempLayer == 1)
@@ -81,4 +110,29 @@
     vps.setMaxDecPicBuffering             ( m_maxDecPicBuffering[i], i );
   }
+#endif
+#if H_MV
+  xSetLayerIds             ( vps );   
+  xSetDimensionIdAndLength ( vps );
+  xSetDirectDependencyFlags( vps );
+
+  for(Int layer = 0; layer < m_numberOfLayers; layer++)
+  {
+    m_frameRcvd                 .push_back(0);
+    m_acTEncTopList             .push_back(new TEncTop); 
+    m_acTVideoIOYuvInputFileList.push_back(new TVideoIOYuv);
+    m_acTVideoIOYuvReconFileList.push_back(new TVideoIOYuv);
+    m_picYuvRec                 .push_back(new TComList<TComPicYuv*>) ;
+
+    m_ivPicLists.push_back( m_acTEncTopList[ layer ]->getListPic()  ); 
+    TEncTop& m_cTEncTop = *m_acTEncTopList[ layer ];  // It is not a member, but this name helps avoiding code duplication !!!
+    
+    m_cTEncTop.setLayerIdInVps( layer ); 
+    m_cTEncTop.setLayerId     ( vps.getLayerIdInNuh( layer ) );    
+    m_cTEncTop.setViewId      ( vps.getViewId      ( layer ) );
+#if H_3D
+    m_cTEncTop.setIsDepth     ( vps.getDepthId     ( layer ) != 0 );
+#endif
+    m_cTEncTop.setIvPicLists  ( &m_ivPicLists ); 
+#endif
   m_cTEncTop.setVPS(&vps);
 
@@ -103,4 +157,13 @@
   m_cTEncTop.setDecodingRefreshType          ( m_iDecodingRefreshType );
   m_cTEncTop.setGOPSize                      ( m_iGOPSize );
+#if H_MV
+  m_cTEncTop.setGopList                      ( m_GOPListMvc[layer] );
+  m_cTEncTop.setExtraRPSs                    ( m_extraRPSsMvc[layer] );
+  for(Int i = 0; i < MAX_TLAYER; i++)
+  {
+    m_cTEncTop.setNumReorderPics             ( m_numReorderPicsMvc[layer][i], i );
+    m_cTEncTop.setMaxDecPicBuffering         ( m_maxDecPicBufferingMvc[layer][i], i );
+  }
+#else
   m_cTEncTop.setGopList                      ( m_GOPList );
   m_cTEncTop.setExtraRPSs                    ( m_extraRPSs );
@@ -110,13 +173,22 @@
     m_cTEncTop.setMaxDecPicBuffering         ( m_maxDecPicBuffering[i], i );
   }
+#endif
   for( UInt uiLoop = 0; uiLoop < MAX_TLAYER; ++uiLoop )
   {
     m_cTEncTop.setLambdaModifier( uiLoop, m_adLambdaModifier[ uiLoop ] );
   }
+#if H_MV
+  m_cTEncTop.setQP                           ( m_iQP[layer] );
+#else
   m_cTEncTop.setQP                           ( m_iQP );
+#endif
 
   m_cTEncTop.setPad                          ( m_aiPad );
 
+#if H_MV
+  m_cTEncTop.setMaxTempLayer                 ( m_maxTempLayerMvc[layer] );
+#else
   m_cTEncTop.setMaxTempLayer                 ( m_maxTempLayer );
+#endif
   m_cTEncTop.setUseAMP( m_enableAMP );
   
@@ -124,5 +196,9 @@
   
   //====== Loop/Deblock Filter ========
+#if H_MV
+  m_cTEncTop.setLoopFilterDisable            ( m_bLoopFilterDisable[layer]);
+#else
   m_cTEncTop.setLoopFilterDisable            ( m_bLoopFilterDisable       );
+#endif
   m_cTEncTop.setLoopFilterOffsetInPPS        ( m_loopFilterOffsetInPPS );
   m_cTEncTop.setLoopFilterBetaOffset         ( m_loopFilterBetaOffsetDiv2  );
@@ -151,5 +227,9 @@
   Int lowestQP;
   lowestQP =  - 6*(g_bitDepthY - 8); // XXX: check
+#if H_MV
+  if ((m_iMaxDeltaQP == 0 ) && (m_iQP[layer] == lowestQP) && (m_useLossless == true))
+#else
   if ((m_iMaxDeltaQP == 0 ) && (m_iQP == lowestQP) && (m_useLossless == true))
+#endif
   {
     m_bUseAdaptiveQP = false;
@@ -167,5 +247,9 @@
   m_cTEncTop.setUseLComb                     ( m_bUseLComb    );
 #endif
+#if H_MV
+  m_cTEncTop.setdQPs                         ( m_aidQP[layer]   );
+#else
   m_cTEncTop.setdQPs                         ( m_aidQP        );
+#endif
   m_cTEncTop.setUseRDOQ                      ( m_useRDOQ     );
   m_cTEncTop.setUseRDOQTS                    ( m_useRDOQTS   );
@@ -224,5 +308,9 @@
   }
   m_cTEncTop.setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag );
+#if H_MV
+  m_cTEncTop.setUseSAO ( m_bUseSAO[layer] );
+#else
   m_cTEncTop.setUseSAO ( m_bUseSAO );
+#endif
   m_cTEncTop.setMaxNumOffsetsPerPic (m_maxNumOffsetsPerPic);
 
@@ -372,8 +460,27 @@
   }
 #endif
+#if H_MV
+  }
+#endif
 }
 
 Void TAppEncTop::xCreateLib()
 {
+#if H_MV
+  // initialize global variables
+  initROM();
+
+  for( Int layer=0; layer < m_numberOfLayers; layer++)
+  {
+    m_acTVideoIOYuvInputFileList[layer]->open( m_pchInputFileList[layer],     false, m_inputBitDepthY, m_inputBitDepthC, m_internalBitDepthY, m_internalBitDepthC );  // read  mode
+    m_acTVideoIOYuvInputFileList[layer]->skipFrames( m_FrameSkip, m_iSourceWidth - m_aiPad[0], m_iSourceHeight - m_aiPad[1]);
+
+    if (m_pchReconFileList[layer])
+    {
+      m_acTVideoIOYuvReconFileList[layer]->open( m_pchReconFileList[layer], true, m_outputBitDepthY, m_outputBitDepthC, m_internalBitDepthY, m_internalBitDepthC);  // write mode
+    }
+    m_acTEncTopList[layer]->create();
+  }
+#else
   // Video I/O
   m_cTVideoIOYuvInputFile.open( m_pchInputFile,     false, m_inputBitDepthY, m_inputBitDepthC, m_internalBitDepthY, m_internalBitDepthC );  // read  mode
@@ -385,8 +492,29 @@
   // Neo Decoder
   m_cTEncTop.create();
+#endif
 }
 
 Void TAppEncTop::xDestroyLib()
 {
+#if H_MV
+  // destroy ROM
+  destroyROM();
+
+  for(Int layer=0; layer<m_numberOfLayers; layer++)
+  {
+    m_acTVideoIOYuvInputFileList[layer]->close();
+    m_acTVideoIOYuvReconFileList[layer]->close();
+    delete m_acTVideoIOYuvInputFileList[layer] ; 
+    m_acTVideoIOYuvInputFileList[layer] = NULL;
+    delete m_acTVideoIOYuvReconFileList[layer] ; 
+    m_acTVideoIOYuvReconFileList[layer] = NULL;
+    m_acTEncTopList[layer]->deletePicBuffer();
+    m_acTEncTopList[layer]->destroy();
+    delete m_acTEncTopList[layer] ; 
+    m_acTEncTopList[layer] = NULL;
+    delete m_picYuvRec[layer] ; 
+    m_picYuvRec[layer] = NULL;
+  }
+#else
   // Video I/O
   m_cTVideoIOYuvInputFile.close();
@@ -395,9 +523,17 @@
   // Neo Decoder
   m_cTEncTop.destroy();
+#endif
 }
 
 Void TAppEncTop::xInitLib()
 {
+#if H_MV
+  for(Int layer=0; layer<m_numberOfLayers; layer++)
+  {
+    m_acTEncTopList[layer]->init( );
+  }
+#else
   m_cTEncTop.init();
+#endif
 }
 
@@ -432,6 +568,22 @@
   
   // main encoder loop
+#if H_MV
+  Bool  allEos = false;
+  std::vector<Bool>  eos ;
+  std::vector<Bool>  flush ;  
+  
+  Int gopSize    = 1;
+  Int maxGopSize = 0;
+  maxGopSize = (std::max)(maxGopSize, m_acTEncTopList[0]->getGOPSize());  
+  
+  for(Int layer=0; layer < m_numberOfLayers; layer++ )
+  {
+    eos  .push_back( false );
+    flush.push_back( false );
+  }
+#else
   Int   iNumEncoded = 0;
   Bool  bEos = false;
+#endif
  
   list<AccessUnit> outputAccessUnits; ///< list of access units to write out.  is populated by the encoding process
@@ -440,4 +592,57 @@
   pcPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
   
+#if H_MV
+  while ( !allEos )
+  {
+    for(Int layer=0; layer < m_numberOfLayers; layer++ )
+    {
+      Int frmCnt = 0;
+      while ( !eos[layer] && !(frmCnt == gopSize))
+      {
+        // get buffers
+        xGetBuffer(pcPicYuvRec, layer);
+
+        // read input YUV file
+        m_acTVideoIOYuvInputFileList[layer]->read      ( pcPicYuvOrg, m_aiPad );
+        m_acTEncTopList             [layer]->initNewPic( pcPicYuvOrg );
+
+        // increase number of received frames
+        m_frameRcvd[layer]++;
+        
+        frmCnt++;
+
+        eos[layer] = (m_frameRcvd[layer] == m_framesToBeEncoded);
+        allEos = allEos|eos[layer];
+
+        // if end of file (which is only detected on a read failure) flush the encoder of any queued pictures
+        if (m_acTVideoIOYuvInputFileList[layer]->isEof())
+        {
+          flush          [layer] = true;
+          eos            [layer]   = true;
+          m_frameRcvd    [layer]--;
+          m_acTEncTopList[layer]->setFramesToBeEncoded(m_frameRcvd[layer]);
+        }
+      }
+    }
+    for ( Int gopId=0; gopId < gopSize; gopId++ )
+    {
+      for(Int layer=0; layer < m_numberOfLayers; layer++ )
+      {
+        Int   iNumEncoded = 0;
+
+        // call encoding function for one frame          
+        m_acTEncTopList[layer]->encode( eos[layer], flush[layer] ? 0 : pcPicYuvOrg, *m_picYuvRec[layer], outputAccessUnits, iNumEncoded, gopId );        
+        xWriteOutput(bitstreamFile, iNumEncoded, outputAccessUnits, layer);
+        outputAccessUnits.clear();
+      }
+
+    }
+    gopSize = maxGopSize;
+  }
+  for(Int layer=0; layer < m_numberOfLayers; layer++ )
+  {
+    m_acTEncTopList[layer]->printSummary( m_acTEncTopList[layer]->getNumAllPicCoded() );
+  }
+#else
   while ( !bEos )
   {
@@ -475,4 +680,5 @@
 
   m_cTEncTop.printSummary();
+#endif
 
   // delete original YUV buffer
@@ -481,6 +687,8 @@
   pcPicYuvOrg = NULL;
   
+#if !H_MV
   // delete used buffers in encoder class
   m_cTEncTop.deletePicBuffer();
+#endif
 
   // delete buffers & classes
@@ -493,4 +701,20 @@
 }
 
+#if H_3D
+TEncTop* TAppEncTop::getTEncTopView( Int viewId, Bool isDepth )
+{
+  TEncTop* encoder = NULL;
+  for( Int layer = 0; layer < m_acTEncTopList.size(); layer++ )
+  {
+    if( m_acTEncTopList[layer]->getViewId()  == viewId &&
+        m_acTEncTopList[layer]->getIsDepth() == isDepth )
+    {
+      encoder = m_acTEncTopList[layer];
+      break;
+    }
+  }
+  return encoder;
+}
+#endif
 // ====================================================================================================================
 // Protected member functions
@@ -503,12 +727,22 @@
  .
  */
+#if H_MV
+Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec, UInt layer)
+#else
 Void TAppEncTop::xGetBuffer( TComPicYuv*& rpcPicYuvRec)
+#endif
 {
   assert( m_iGOPSize > 0 );
   
   // org. buffer
+#if H_MV
+  if ( m_picYuvRec[layer]->size() == (UInt)m_iGOPSize )
+  {
+    rpcPicYuvRec = m_picYuvRec[layer]->popFront();
+#else
   if ( m_cListPicYuvRec.size() == (UInt)m_iGOPSize )
   {
     rpcPicYuvRec = m_cListPicYuvRec.popFront();
+#endif
 
   }
@@ -520,12 +754,25 @@
 
   }
+#if H_MV
+  m_picYuvRec[layer]->pushBack( rpcPicYuvRec );
+#else
   m_cListPicYuvRec.pushBack( rpcPicYuvRec );
+#endif
 }
 
 Void TAppEncTop::xDeleteBuffer( )
 {
+#if H_MV
+  for(Int layer=0; layer<m_picYuvRec.size(); layer++)
+  {
+    if(m_picYuvRec[layer])
+    {
+      TComList<TComPicYuv*>::iterator iterPicYuvRec  = m_picYuvRec[layer]->begin();
+      Int iSize = Int( m_picYuvRec[layer]->size() );
+#else
   TComList<TComPicYuv*>::iterator iterPicYuvRec  = m_cListPicYuvRec.begin();
   
   Int iSize = Int( m_cListPicYuvRec.size() );
+#endif
 
   for ( Int i = 0; i < iSize; i++ )
@@ -536,14 +783,28 @@
   }
 
+#if H_MV
+    }
+  }
+#endif  
 }
 
 /** \param iNumEncoded  number of encoded frames
  */
+#if H_MV
+Void TAppEncTop::xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, std::list<AccessUnit>& accessUnits, UInt layerId)
+#else
 Void TAppEncTop::xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits)
+#endif
 {
   Int i;
   
+#if H_MV
+  if( iNumEncoded > 0 )
+  {
+    TComList<TComPicYuv*>::iterator iterPicYuvRec = m_picYuvRec[layerId]->end();
+#else
   TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end();
   list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
+#endif
 
   for ( i = 0; i < iNumEncoded; i++ )
@@ -555,4 +816,21 @@
   {
     TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
+#if H_MV
+      if (m_pchReconFileList[layerId])
+      {
+        m_acTVideoIOYuvReconFileList[layerId]->write( pcPicYuvRec, m_confLeft, m_confRight, m_confTop, m_confBottom );
+      }
+    }
+  }
+  if( ! accessUnits.empty() )
+  {
+    list<AccessUnit>::iterator aUIter;
+    for( aUIter = accessUnits.begin(); aUIter != accessUnits.end(); aUIter++ )
+    {
+      const vector<unsigned>& stats = writeAnnexB(bitstreamFile, *aUIter);
+      rateStatsAccum(*aUIter, stats);
+    }
+  }
+#else
     if (m_pchReconFile)
     {
@@ -564,4 +842,5 @@
     rateStatsAccum(au, stats);
   }
+#endif
 }
 
@@ -609,5 +888,10 @@
 void TAppEncTop::printRateSummary()
 {
+#if H_MV
+  Double time = (Double) m_frameRcvd[0] / m_iFrameRate;
+  printf("\n");
+#else
   Double time = (Double) m_iFrameRcvd / m_iFrameRate;
+#endif
   printf("Bytes written to file: %u (%.3f kbps)\n", m_totalBytes, 0.008 * m_totalBytes / time);
 #if VERBOSE_RATE
@@ -616,4 +900,66 @@
 }
 
+#if H_MV
+Void TAppEncTop::xSetDimensionIdAndLength( TComVPS& vps )
+{   
+  vps.setScalabilityMask( m_scalabilityMask ); 
+  for( Int dim = 0; dim < m_dimIds.size(); dim++ )
+  {
+      vps.setDimensionIdLen( dim, m_dimensionIdLen[ dim ] );
+      for( Int layer = 1; layer < vps.getMaxLayers(); layer++ )
+      {        
+        vps.setDimensionId( layer, dim, m_dimIds[ dim ][ layer ] );        
+      }  
+  }
+}
+
+Void TAppEncTop::xSetDirectDependencyFlags( TComVPS& vps )
+{
+  for( Int layer = 0; layer < m_numberOfLayers; layer++ )
+  {
+    if( m_GOPListMvc[layer][MAX_GOP].m_POC == -1 )
+    {
+      continue;
+    }
+    for( Int i = 0; i < getGOPSize()+1; i++ ) 
+    {
+      GOPEntry ge = ( i < getGOPSize() ) ? m_GOPListMvc[layer][i] : m_GOPListMvc[layer][MAX_GOP];
+      for( Int j = 0; j < ge.m_numInterViewRefPics; j++ )
+      {
+        Int interLayerRef = layer + ge.m_interViewRefs[j];
+        vps.setDirectDependencyFlag( layer, interLayerRef, true );
+      }
+    }
+  }
+
+  vps.checkVPSExtensionSyntax(); 
+  vps.calcIvRefLayers();
+}
+
+Void TAppEncTop::xSetLayerIds( TComVPS& vps )
+{
+  vps.setSplittingFlag     ( m_splittingFlag );
+
+  Bool nuhLayerIdPresentFlag = !( m_layerIdInNuh.size() == 1 ); 
+  Int  maxNuhLayerId = nuhLayerIdPresentFlag ? xGetMax( m_layerIdInNuh ) : ( m_numberOfLayers - 1 ) ; 
+
+  vps.setMaxNuhLayerId( maxNuhLayerId ); 
+  vps.setVpsNuhLayerIdPresentFlag( nuhLayerIdPresentFlag ); 
+
+  for (Int layer = 0; layer < m_numberOfLayers; layer++ )
+  {
+    vps.setLayerIdInNuh( layer, nuhLayerIdPresentFlag ? m_layerIdInNuh[ layer ] : layer ); 
+    vps.setLayerIdInVps( vps.getLayerIdInNuh( layer ), layer ); 
+  }
+}
+
+Int TAppEncTop::xGetMax( std::vector<Int>& vec )
+{
+  Int maxVec = 0; 
+  for ( Int i = 0; i < vec.size(); i++)    
+    maxVec = max( vec[i], maxVec ); 
+  return maxVec;
+}
+#endif
 
 //! \}
Index: branches/HTM-DEV-0.1-dev/source/App/TAppEncoder/TAppEncTop.h
===================================================================
--- branches/HTM-DEV-0.1-dev/source/App/TAppEncoder/TAppEncTop.h	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/App/TAppEncoder/TAppEncTop.h	(revision 368)
@@ -59,4 +59,15 @@
 private:
   // class interface
+#if H_MV
+  std::vector<TEncTop*>      m_acTEncTopList ;              ///< encoder class per layer 
+  std::vector<TVideoIOYuv*>  m_acTVideoIOYuvInputFileList;  ///< input YUV file
+  std::vector<TVideoIOYuv*>  m_acTVideoIOYuvReconFileList;  ///< output reconstruction file
+  
+  std::vector<TComList<TComPicYuv*>*>  m_picYuvRec;         ///< list of reconstruction YUV files
+
+  std::vector<Int>           m_frameRcvd;                   ///< number of received frames 
+
+  TComPicLists               m_ivPicLists;                  ///< picture buffers of encoder instances
+#else
   TEncTop                    m_cTEncTop;                    ///< encoder class
   TVideoIOYuv                m_cTVideoIOYuvInputFile;       ///< input YUV file
@@ -66,4 +77,5 @@
   
   Int                        m_iFrameRcvd;                  ///< number of received frames
+#endif
 
   UInt m_essentialBytes;
@@ -77,5 +89,9 @@
   
   /// obtain required buffers
+#if H_MV
+  Void xGetBuffer(TComPicYuv*& rpcPicYuvRec, UInt layer);
+#else
   Void xGetBuffer(TComPicYuv*& rpcPicYuvRec);
+#endif
 
   /// delete allocated buffers
@@ -83,8 +99,18 @@
   
   // file I/O
+#if H_MV
+  Void xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, std::list<AccessUnit>& accessUnits, UInt layerId); ///< write bitstream to file
+#else
   Void xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits); ///< write bitstream to file
+#endif
   void rateStatsAccum(const AccessUnit& au, const std::vector<UInt>& stats);
   void printRateSummary();
   
+#if H_MV
+  Void xSetLayerIds               ( TComVPS& vps );  
+  Void xSetDimensionIdAndLength   ( TComVPS& vps );
+  Void xSetDirectDependencyFlags  ( TComVPS& vps );
+  Int  xGetMax( std::vector<Int>& vec);
+#endif
 public:
   TAppEncTop();
@@ -92,5 +118,12 @@
   
   Void        encode      ();                               ///< main encoding function
+#if H_MV
+  TEncTop*    getTEncTopLayer(UInt layer) { return  m_acTEncTopList[layer]; }  ///< return pointer to encoder class for specific layer
+#if H_3D
+  TEncTop*    getTEncTopView( Int viewId, Bool isDepth );                      ///< return pointer to encoder class for specific view Id and texture or depth 
+#endif
+#else
   TEncTop&    getTEncTop  ()   { return  m_cTEncTop; }      ///< return encoder class pointer reference
+#endif
 };// END CLASS DEFINITION TAppEncTop
 
Index: branches/HTM-DEV-0.1-dev/source/App/TAppEncoder/encmain.cpp
===================================================================
--- branches/HTM-DEV-0.1-dev/source/App/TAppEncoder/encmain.cpp	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/App/TAppEncoder/encmain.cpp	(revision 368)
@@ -57,5 +57,9 @@
   // print information
   fprintf( stdout, "\n" );
+#if H_MV
+  fprintf( stdout, "3D-HTM Software: Encoder Version [%s] based on HM Version [%s]", NV_VERSION, HM_VERSION );  
+#else
   fprintf( stdout, "HM software: Encoder Version [%s]", NV_VERSION );
+#endif
   fprintf( stdout, NVM_ONOS );
   fprintf( stdout, NVM_COMPILEDBY );
Index: branches/HTM-DEV-0.1-dev/source/Lib/TAppCommon/program_options_lite.h
===================================================================
--- branches/HTM-DEV-0.1-dev/source/Lib/TAppCommon/program_options_lite.h	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/Lib/TAppCommon/program_options_lite.h	(revision 368)
@@ -37,4 +37,13 @@
 #include <map>
 
+#if H_MV
+#include <vector>
+#include <errno.h>
+#include <cstring>
+
+#ifdef WIN32
+#define strdup _strdup
+#endif
+#endif
 //! \ingroup TAppCommon
 //! \{
@@ -136,4 +145,141 @@
     }
 
+#if H_MV    
+    template<>
+    inline void
+      Option<char*>::parse(const std::string& arg)
+    {
+      opt_storage = arg.empty() ? NULL : strdup(arg.c_str()) ;
+    }
+
+    template<>
+    inline void
+      Option< std::vector<char*> >::parse(const std::string& arg)
+    {
+      opt_storage.clear(); 
+
+      char* pcStart = (char*) arg.data();      
+      char* pcEnd = strtok (pcStart," ");
+
+      while (pcEnd != NULL)
+      {
+        size_t uiStringLength = pcEnd - pcStart;
+        char* pcNewStr = (char*) malloc( uiStringLength + 1 );
+        strncpy( pcNewStr, pcStart, uiStringLength); 
+        pcNewStr[uiStringLength] = '\0'; 
+        pcStart = pcEnd+1; 
+        pcEnd = strtok (NULL, " ,.-");
+        opt_storage.push_back( pcNewStr ); 
+      }      
+    }
+
+
+    template<>    
+    inline void
+      Option< std::vector<double> >::parse(const std::string& arg)
+    {
+      char* pcNextStart = (char*) arg.data();
+      char* pcEnd = pcNextStart + arg.length();
+
+      char* pcOldStart = 0; 
+
+      size_t iIdx = 0; 
+
+      while (pcNextStart < pcEnd)
+      {
+        errno = 0; 
+
+        if ( iIdx < opt_storage.size() )
+        {
+          opt_storage[iIdx] = strtod(pcNextStart, &pcNextStart);
+        }
+        else
+        {
+          opt_storage.push_back( strtod(pcNextStart, &pcNextStart)) ;
+        }
+        iIdx++; 
+
+        if ( errno == ERANGE || (pcNextStart == pcOldStart) )
+        {
+          std::cerr << "Error Parsing Doubles: `" << arg << "'" << std::endl;
+          exit(EXIT_FAILURE);    
+        };   
+        while( (pcNextStart < pcEnd) && ( *pcNextStart == ' ' || *pcNextStart == '\t' || *pcNextStart == '\r' ) ) pcNextStart++;  
+        pcOldStart = pcNextStart; 
+
+      }
+    }
+
+    template<>
+    inline void
+      Option< std::vector<int> >::parse(const std::string& arg)
+    {
+      opt_storage.clear();
+
+
+      char* pcNextStart = (char*) arg.data();
+      char* pcEnd = pcNextStart + arg.length();
+
+      char* pcOldStart = 0; 
+
+      size_t iIdx = 0; 
+
+
+      while (pcNextStart < pcEnd)
+      {
+
+        if ( iIdx < opt_storage.size() )
+        {
+          opt_storage[iIdx] = (int) strtol(pcNextStart, &pcNextStart,10);
+        }
+        else
+        {
+          opt_storage.push_back( (int) strtol(pcNextStart, &pcNextStart,10)) ;
+        }
+        iIdx++; 
+        if ( errno == ERANGE || (pcNextStart == pcOldStart) )
+        {
+          std::cerr << "Error Parsing Integers: `" << arg << "'" << std::endl;
+          exit(EXIT_FAILURE);
+        };   
+        while( (pcNextStart < pcEnd) && ( *pcNextStart == ' ' || *pcNextStart == '\t' || *pcNextStart == '\r' ) ) pcNextStart++;  
+        pcOldStart = pcNextStart;
+      }
+    }
+
+
+    template<>
+    inline void
+      Option< std::vector<bool> >::parse(const std::string& arg)
+    {
+      char* pcNextStart = (char*) arg.data();
+      char* pcEnd = pcNextStart + arg.length();
+
+      char* pcOldStart = 0; 
+
+      size_t iIdx = 0; 
+
+      while (pcNextStart < pcEnd)
+      {
+        if ( iIdx < opt_storage.size() )
+        {
+          opt_storage[iIdx] = (strtol(pcNextStart, &pcNextStart,10) != 0);
+        }
+        else
+        {
+          opt_storage.push_back(strtol(pcNextStart, &pcNextStart,10) != 0) ;
+        }
+        iIdx++; 
+
+        if ( errno == ERANGE || (pcNextStart == pcOldStart) )
+        {
+          std::cerr << "Error Parsing Bools: `" << arg << "'" << std::endl;
+          exit(EXIT_FAILURE);
+        };   
+        while( (pcNextStart < pcEnd) && ( *pcNextStart == ' ' || *pcNextStart == '\t' || *pcNextStart == '\r' ) ) pcNextStart++;  
+        pcOldStart = pcNextStart;
+      }
+    }
+#endif
     /** Option class for argument handling using a user provided function */
     struct OptionFunc : public OptionBase
@@ -210,4 +356,28 @@
       }
       
+#if H_MV
+      template<typename T>
+      OptionSpecific&
+        operator()(const std::string& name, std::vector<T>& storage, T default_val, unsigned uiMaxNum, const std::string& desc = "" )
+      {
+        std::string cNameBuffer;
+        std::string cDescriptionBuffer;
+
+        cNameBuffer       .resize( name.size() + 10 );
+        cDescriptionBuffer.resize( desc.size() + 10 );
+
+        storage.resize(uiMaxNum);
+        for ( unsigned int uiK = 0; uiK < uiMaxNum; uiK++ )
+        {
+          // isn't there are sprintf function for string??
+          sprintf((char*) cNameBuffer.c_str()       ,name.c_str(),uiK,uiK);
+          sprintf((char*) cDescriptionBuffer.c_str(),desc.c_str(),uiK,uiK);
+
+          parent.addOption(new Option<T>( cNameBuffer, (storage[uiK]), default_val, cDescriptionBuffer ));
+        }
+
+        return *this;
+      }
+#endif
       /**
        * Add option described by name to the parent Options list,
Index: branches/HTM-DEV-0.1-dev/source/Lib/TLibCommon/CommonDef.h
===================================================================
--- branches/HTM-DEV-0.1-dev/source/Lib/TLibCommon/CommonDef.h	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/Lib/TLibCommon/CommonDef.h	(revision 368)
@@ -56,5 +56,10 @@
 // ====================================================================================================================
 
+#if H_MV
+#define NV_VERSION        "0.1"                 ///< Current software version
+#define HM_VERSION        "10.1"                ///< 
+#else
 #define NV_VERSION        "10.1"                 ///< Current software version
+#endif
 
 // ====================================================================================================================
@@ -152,4 +157,15 @@
 }
 
+#if H_MV
+
+#define AOF( exp )                  \
+{                                   \
+  if( !( exp ) )                    \
+{                                 \
+  assert( 0 );                    \
+}                                 \
+}
+
+#endif
 
 // ====================================================================================================================
Index: branches/HTM-DEV-0.1-dev/source/Lib/TLibCommon/NAL.h
===================================================================
--- branches/HTM-DEV-0.1-dev/source/Lib/TLibCommon/NAL.h	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/Lib/TLibCommon/NAL.h	(revision 368)
@@ -47,5 +47,9 @@
   NalUnitType m_nalUnitType; ///< nal_unit_type
   UInt        m_temporalId;  ///< temporal_id
+#if H_MV
+  Int         m_layerId;     ///< layer id
+#else
   UInt        m_reservedZero6Bits; ///< reserved_zero_6bits
+#endif
 
   /** construct an NALunit structure with given header values. */
@@ -53,8 +57,16 @@
     NalUnitType nalUnitType,
     Int         temporalId = 0,
+#if H_MV
+    Int         layerId = 0)
+#else
     Int         reservedZero6Bits = 0)
+#endif
     :m_nalUnitType (nalUnitType)
     ,m_temporalId  (temporalId)
+#if H_MV
+    ,m_layerId     (layerId)
+#else
     ,m_reservedZero6Bits(reservedZero6Bits)
+#endif
   {}
 
Index: branches/HTM-DEV-0.1-dev/source/Lib/TLibCommon/TComPic.cpp
===================================================================
--- branches/HTM-DEV-0.1-dev/source/Lib/TLibCommon/TComPic.cpp	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/Lib/TLibCommon/TComPic.cpp	(revision 368)
@@ -64,4 +64,11 @@
 , m_pNDBFilterYuvTmp                      (NULL)
 , m_bCheckLTMSB                           (false)
+#if H_MV
+, m_layerId                               (0)
+, m_viewId                                (0)
+#if H_3D
+, m_isDepth                               (false)
+#endif
+#endif
 {
   m_apcPicYuv[0]      = NULL;
@@ -464,4 +471,13 @@
 
 }
+#if H_MV
+Void TComPic::print( Bool legend )
+{
+  if ( legend )
+    std::cout  << "LId"        << "\t" << "POC"   << "\t" << "Rec"          << "\t" << "Ref"                       << "\t" << "LT"            << std::endl;
+  else
+    std::cout  << getLayerId() << "\t" << getPOC()<< "\t" << getReconMark() << "\t" << getSlice(0)->isReferenced() << "\t" << getIsLongTerm() << std::endl;
+}
+#endif
 
 
Index: branches/HTM-DEV-0.1-dev/source/Lib/TLibCommon/TComPic.h
===================================================================
--- branches/HTM-DEV-0.1-dev/source/Lib/TLibCommon/TComPic.h	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/Lib/TLibCommon/TComPic.h	(revision 368)
@@ -86,4 +86,11 @@
   SEIMessages  m_SEIs; ///< Any SEI messages that have been received.  If !NULL we own the object.
 
+#if H_MV
+  Int                   m_layerId;
+  Int                   m_viewId;
+#if H_3D
+  Bool                  m_isDepth;
+#endif
+#endif
 public:
   TComPic();
@@ -98,4 +105,14 @@
   Void          setTLayer( UInt uiTLayer ) { m_uiTLayer = uiTLayer; }
 
+#if H_MV
+  Void          setLayerId            ( Int layerId )    { m_layerId      = layerId; }
+  Int           getLayerId            ()                 { return m_layerId;    }
+  Void          setViewId             ( Int viewId )     { m_viewId = viewId;   }
+  Int           getViewId             ()                 { return m_viewId;     }
+#if H_3D
+  Void          setIsDepth            ( Bool isDepth )   { m_isDepth = isDepth; }
+  Bool          getIsDepth            ()                 { return m_isDepth; }
+#endif
+#endif
   Bool          getUsedByCurr()             { return m_bUsedByCurr; }
   Void          setUsedByCurr( Bool bUsed ) { m_bUsedByCurr = bUsed; }
@@ -164,4 +181,7 @@
   std::vector<TComDataCU*>& getOneSliceCUDataForNDBFilter      (Int sliceID) { return m_vSliceCUDataLink[sliceID];}
 
+#if H_MV
+  Void          print( Bool legend );
+#endif
   /** transfer ownership of seis to this picture */
   void setSEIs(SEIMessages& seis) { m_SEIs = seis; }
@@ -179,4 +199,51 @@
 };// END CLASS DEFINITION TComPic
 
+#if H_MV
+class TComPicLists 
+{
+private: 
+  TComList<TComList<TComPic*>*> m_lists; 
+public: 
+  
+  Void push_back( TComList<TComPic*>* list ) { m_lists.push_back( list ); }
+  Int  size     ()                           { return (Int) m_lists.size    (); } 
+
+  TComPic* getPic( Int layerIdInNuh, Int poc )
+  { 
+    TComPic* pcPic = NULL;
+    for(TComList<TComList<TComPic*>*>::iterator itL = m_lists.begin(); ( itL != m_lists.end() && pcPic == NULL ); itL++)
+    {    
+      for(TComList<TComPic*>::iterator itP=(*itL)->begin(); ( itP!=(*itL)->end() && pcPic == NULL ); itP++)
+      {
+        if ( ( (*itP)->getPOC() == poc ) && ( (*itP)->getLayerId() == layerIdInNuh ) )
+        {
+          pcPic = *itP ;      
+        }
+      }
+    }
+    return pcPic;
+  }
+
+  Void print( )
+  { 
+    Bool first = true;     
+    for(TComList<TComList<TComPic*>*>::iterator itL = m_lists.begin(); ( itL != m_lists.end() ); itL++)
+    {    
+      for(TComList<TComPic*>::iterator itP=(*itL)->begin(); ( itP!=(*itL)->end() ); itP++)
+      {
+        if ( first )
+        {
+          (*itP)->print( true );       
+          first = false; 
+        }
+        (*itP)->print( false );       
+      }
+    }
+  }
+
+
+}; // END CLASS DEFINITION TComPicLists
+
+#endif 
 //! \}
 
Index: branches/HTM-DEV-0.1-dev/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- branches/HTM-DEV-0.1-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 368)
@@ -107,4 +107,11 @@
 , m_temporalLayerNonReferenceFlag ( false )
 , m_enableTMVPFlag                ( true )
+#if H_MV
+, m_layerId                       (0)
+, m_viewId                        (0)
+#if H_3D
+, m_isDepth                       (false)
+#endif
+#endif
 {
 #if L0034_COMBINED_LIST_CLEANUP
@@ -138,4 +145,8 @@
     m_aiRefPOCList  [0][iNumCount] = 0;
     m_aiRefPOCList  [1][iNumCount] = 0;
+#if H_MV
+    m_aiRefLayerIdList[0][iNumCount] = 0;
+    m_aiRefLayerIdList[1][iNumCount] = 0;
+#endif
   }
   resetWpScaling();
@@ -309,4 +320,7 @@
     {
       m_aiRefPOCList[iDir][iNumRefIdx] = m_apcRefPicList[iDir][iNumRefIdx]->getPOC();
+#if H_MV
+      m_aiRefLayerIdList[iDir][iNumRefIdx] = m_apcRefPicList[iDir][iNumRefIdx]->getLayerId();
+#endif
     }
   }
@@ -354,5 +368,10 @@
         for ( Int iRefIdxLC = 0; iRefIdxLC < m_aiNumRefIdx[REF_PIC_LIST_C]; iRefIdxLC++ )
         {
+#if H_MV
+          if ( m_apcRefPicList[REF_PIC_LIST_0][iNumRefIdx]->getPOC() == m_apcRefPicList[m_eListIdFromIdxOfLC[iRefIdxLC]][m_iRefIdxFromIdxOfLC[iRefIdxLC]]->getPOC() &&
+               m_apcRefPicList[REF_PIC_LIST_0][iNumRefIdx]->getLayerId() == m_apcRefPicList[m_eListIdFromIdxOfLC[iRefIdxLC]][m_iRefIdxFromIdxOfLC[iRefIdxLC]]->getLayerId() )
+#else
           if ( m_apcRefPicList[REF_PIC_LIST_0][iNumRefIdx]->getPOC() == m_apcRefPicList[m_eListIdFromIdxOfLC[iRefIdxLC]][m_iRefIdxFromIdxOfLC[iRefIdxLC]]->getPOC() )
+#endif 
           {
             m_iRefIdxOfL1FromRefIdxOfL0[iNumRefIdx] = m_iRefIdxFromIdxOfLC[iRefIdxLC];
@@ -376,5 +395,10 @@
         for ( Int iRefIdxLC = 0; iRefIdxLC < m_aiNumRefIdx[REF_PIC_LIST_C]; iRefIdxLC++ )
         {
+#if H_MV
+          if ( m_apcRefPicList[REF_PIC_LIST_1][iNumRefIdx]->getPOC() == m_apcRefPicList[m_eListIdFromIdxOfLC[iRefIdxLC]][m_iRefIdxFromIdxOfLC[iRefIdxLC]]->getPOC() &&
+               m_apcRefPicList[REF_PIC_LIST_1][iNumRefIdx]->getLayerId() == m_apcRefPicList[m_eListIdFromIdxOfLC[iRefIdxLC]][m_iRefIdxFromIdxOfLC[iRefIdxLC]]->getLayerId() )
+#else
           if ( m_apcRefPicList[REF_PIC_LIST_1][iNumRefIdx]->getPOC() == m_apcRefPicList[m_eListIdFromIdxOfLC[iRefIdxLC]][m_iRefIdxFromIdxOfLC[iRefIdxLC]]->getPOC() )
+#endif 
           {
             m_iRefIdxOfL0FromRefIdxOfL1[iNumRefIdx] = m_iRefIdxFromIdxOfLC[iRefIdxLC];
@@ -396,4 +420,7 @@
 #endif
 
+#if H_MV
+Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& refPicSetInterLayer , Bool checkNumPocTotalCurr)
+#else
 #if FIX1071
 Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr )
@@ -401,4 +428,5 @@
 Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic )
 #endif
+#endif
 {
 #if FIX1071
@@ -414,6 +442,8 @@
     }
     
+#if !H_MV
     m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
     m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
+#endif
   }
 
@@ -425,4 +455,8 @@
   UInt NumPocStCurr1 = 0;
   UInt NumPocLtCurr = 0;
+#if H_MV
+  Int numDirectRefLayers  = getVPS()->getNumDirectRefLayers( getLayerIdInVps() );
+  assert( numDirectRefLayers == refPicSetInterLayer.size() ); 
+#endif
   Int i;
 
@@ -473,5 +507,10 @@
   TComPic*  rpsCurrList0[MAX_NUM_REF+1];
   TComPic*  rpsCurrList1[MAX_NUM_REF+1];
+#if H_MV
+  Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr + numDirectRefLayers;
+  assert( numPocTotalCurr == getNumRpsCurrTempList() );
+#else
   Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr;
+#endif
 #if FIX1071
   if (checkNumPocTotalCurr)
@@ -513,4 +552,13 @@
     rpsCurrList0[cIdx] = RefPicSetLtCurr[i];
   }
+#if H_MV
+  for ( i=0; i<numDirectRefLayers;  i++, cIdx++)
+  {
+    if( cIdx <= MAX_NUM_REF )
+    {
+      rpsCurrList0[cIdx] = refPicSetInterLayer[i];
+    }
+  }
+#endif
 
   if (m_eSliceType==B_SLICE)
@@ -529,4 +577,13 @@
       rpsCurrList1[cIdx] = RefPicSetLtCurr[i];
     }
+#if H_MV
+    for ( i=0; i<numDirectRefLayers;  i++, cIdx++)
+    {
+      if( cIdx <= MAX_NUM_REF )
+      {
+        rpsCurrList1[cIdx] = refPicSetInterLayer[i];
+      }
+    }
+#endif
   }
 
@@ -570,4 +627,7 @@
     }
   }
+#if H_MV
+  numRpsCurrTempList = numRpsCurrTempList + getVPS()->getNumDirectRefLayers( getLayerIdInVps() );
+#endif
   return numRpsCurrTempList;
 }
@@ -732,4 +792,7 @@
   m_iPOC                 = pSrc->m_iPOC;
   m_eNalUnitType         = pSrc->m_eNalUnitType;
+#if H_MV
+  m_layerId              = pSrc->m_layerId;
+#endif
   m_eSliceType           = pSrc->m_eSliceType;
   m_iSliceQp             = pSrc->m_iSliceQp;
@@ -784,4 +847,7 @@
       m_apcRefPicList[i][j]  = pSrc->m_apcRefPicList[i][j];
       m_aiRefPOCList[i][j]   = pSrc->m_aiRefPOCList[i][j];
+#if H_MV
+      m_aiRefLayerIdList[i][j] = pSrc->m_aiRefLayerIdList[i][j];
+#endif
     }
   }
@@ -799,4 +865,7 @@
 
   // access channel
+#if H_MV
+  m_pcVPS                = pSrc->m_pcVPS;
+#endif
   m_pcSPS                = pSrc->m_pcSPS;
   m_pcPPS                = pSrc->m_pcPPS;
@@ -1312,5 +1381,9 @@
 , m_bTemporalIdNestingFlag    (false)
 , m_numHrdParameters          (  0)
+#if H_MV
+, m_maxNuhLayerId             (  0)
+#else
 , m_maxNuhReservedZeroLayerId (  0)
+#endif
 , m_hrdParameters             (NULL)
 , m_hrdOpSetIdx               (NULL)
@@ -1327,4 +1400,51 @@
     m_uiMaxLatencyIncrease[i] = 0;
   }
+#if H_MV
+  m_avcBaseLayerFlag = false;
+  m_splittingFlag    = false;
+  
+  for( Int i = 0; i < MAX_NUM_SCALABILITY_TYPES; i++ )
+  {
+    m_scalabilityMask[i] = false;
+    m_dimensionIdLen [i]  = -1; 
+  }
+
+  m_vpsNuhLayerIdPresentFlag = false;
+  m_numOutputLayerSets       = 0;
+
+  for( Int i = 0; i < MAX_VPS_OP_SETS_PLUS1; i++ )
+  {
+    m_vpsProfilePresentFlag   [i] = false;
+    m_profileLayerSetRefMinus1[i] = 0;
+    m_outputLayerSetIdx       [i] = 0;
+    for( Int j = 0; j < MAX_VPS_NUH_LAYER_ID_PLUS1; j++ )
+    {
+      m_outputLayerFlag[i][j] = false;
+    }
+  }
+
+  for( Int i = 0; i < MAX_NUM_LAYER_IDS; i++ )
+  {
+    m_layerIdInVps[i] =  (i == 0 ) ? 0 : -1;         
+  }
+
+  for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
+  {
+    m_layerIdInNuh      [i] = ( i == 0 ) ? 0 : -1; 
+    m_numDirectRefLayers[i] = 0; 
+
+    for( Int j = 0; j < MAX_NUM_LAYERS; j++ )
+    {
+      m_directDependencyFlag[i][j] = false;
+      m_refLayerId[i][j]           = -1; 
+    }
+
+    for( Int j = 0; j < MAX_NUM_SCALABILITY_TYPES; j++ )
+    {
+      m_dimensionId[i][j] = 0;
+    }
+
+  }
+#endif
 }
 
@@ -1336,4 +1456,91 @@
 }
 
+#if H_MV
+
+Bool TComVPS::checkVPSExtensionSyntax()
+{
+  // check splitting flag constraint
+  if ( getSplittingFlag() )
+  {
+    // Derive dimBitOffset[j]
+    Int dimBitOffset[MAX_NUM_SCALABILITY_TYPES+1];
+    Int numScalabilityTypes = getNumScalabilityTypes();
+    dimBitOffset[0] = 0;
+
+    for (Int type = 1; type <= numScalabilityTypes; type++ )
+    {
+      dimBitOffset[ type ] = 0;
+      for (Int dimIdx = 0; dimIdx <= type - 1; dimIdx++)
+        dimBitOffset[ type ] += ( getDimensionIdLen( dimIdx ) );
+    }
+
+    for (Int type = 0; type < getNumScalabilityTypes(); type++ )
+    {
+      for( Int layer = 1; layer < getMaxLayers(); layer++ )
+      {
+        assert( getDimensionId( layer, type ) == ( ( getLayerIdInNuh( layer ) & ( (1 << dimBitOffset[ type + 1 ] ) - 1) ) >> dimBitOffset[ type ] ) );
+      }; 
+  };
+  }
+
+  for( Int layer = 1; layer < getMaxLayers(); layer++ )
+  {
+    // check layer_id_in_nuh constraint
+    assert( getLayerIdInNuh( layer ) > getLayerIdInNuh( layer -1 ) );
+  }
+  return true; 
+}
+
+Int TComVPS::getNumScalabilityTypes()
+{
+  return scalTypeToScalIdx( ScalabilityType(MAX_NUM_SCALABILITY_TYPES) );
+}
+
+Int TComVPS::scalTypeToScalIdx( ScalabilityType scalType )
+{
+  assert( scalType >= 0 && scalType <= MAX_NUM_SCALABILITY_TYPES ); 
+  assert( scalType == MAX_NUM_SCALABILITY_TYPES || getScalabilityMask( scalType ) );
+
+  Int scalIdx = 0; 
+  for( Int curScalType = 0; curScalType < scalType; curScalType++ )
+  {
+    scalIdx += ( getScalabilityMask( curScalType ) ? 1 : 0 );
+  }
+
+  return scalIdx; 
+}
+
+
+
+Void TComVPS::setScalabilityMask( UInt val )
+{
+  for ( Int scalType = 0; scalType < MAX_NUM_SCALABILITY_TYPES; scalType++ ) 
+    setScalabilityMask( scalType, ( val & (1 << scalType ) ) == 1 );
+}
+
+Void TComVPS::calcIvRefLayers()
+{
+  for( Int i = 1; i <= getMaxLayers(); i++ )
+  { 
+    m_numDirectRefLayers[ i ] = 0; 
+    for( Int j = 0 ; j < i; j++ )
+      if( m_directDependencyFlag[ i ][ j ])
+        m_refLayerId[ i ][ m_numDirectRefLayers[ i ]++ ] = m_layerIdInNuh[ j ];    
+  }
+}
+
+Int TComVPS::getRefLayerId( Int layerIdInVps, Int idx )
+{
+  assert( idx >= 0 && idx < m_numDirectRefLayers[layerIdInVps] );     
+  Int layerIdInNuh = m_refLayerId[ layerIdInVps ][ idx ];    
+  assert ( layerIdInNuh >= 0 ); 
+  return layerIdInNuh;
+}
+
+Int TComVPS::getScalabilityId( Int layerIdInVps, ScalabilityType scalType )
+{
+  return ( ( layerIdInVps != 0 )&& getScalabilityMask( scalType ) ) ? getDimensionId( layerIdInVps, scalTypeToScalIdx( scalType ) ) : 0;
+}
+#endif
 // ------------------------------------------------------------------------------------------------
 // Sequence parameter set (SPS)
@@ -1382,4 +1589,7 @@
 , m_vuiParametersPresentFlag  (false)
 , m_vuiParameters             ()
+#if H_MV
+, m_interViewMvVertConstraintFlag (false)
+#endif
 {
   for ( Int i = 0; i < MAX_TLAYER; i++ )
@@ -1845,4 +2055,91 @@
 }
 
+#if H_MV
+Void TComSlice::createAndApplyIvReferencePictureSet( TComPicLists* ivPicLists, std::vector<TComPic*>& refPicSetInterLayer )
+{
+  refPicSetInterLayer.clear(); 
+
+  for( Int i = 0; i < getVPS()->getNumDirectRefLayers( getLayerIdInVps() ); i++ ) 
+  {
+    Int layerIdRef = getVPS()->getRefLayerId( getLayerIdInVps(), i ); 
+    TComPic* picRef = ivPicLists->getPic( layerIdRef, getPOC() ) ; 
+    assert ( picRef != 0 ); 
+
+    picRef->getPicYuvRec()->extendPicBorder(); 
+    picRef->setIsLongTerm( true );        
+    picRef->getSlice(0)->setReferenced( true );       
+
+    refPicSetInterLayer.push_back( picRef ); 
+  }
+}
+
+Void TComSlice::markIvRefPicsAsShortTerm( std::vector<TComPic*> refPicSetInterLayer )
+{
+  // Mark as shortterm 
+  for ( Int i = 0; i < refPicSetInterLayer.size(); i++ ) 
+  {
+    refPicSetInterLayer[i]->setIsLongTerm( false ); 
+  }
+}
+
+Void TComSlice::markIvRefPicsAsUnused( TComPicLists* ivPicLists, std::vector<Int> targetDecLayerIdSet, TComVPS* vps, Int curLayerId, Int curPoc )
+{
+  // Fill targetDecLayerIdSet with all layers if empty. 
+  if (targetDecLayerIdSet.size() == 0 )    
+  {
+    for ( Int layerIdInVps = 0; layerIdInVps < vps->getMaxLayers(); layerIdInVps++ )
+    {
+      targetDecLayerIdSet.push_back( vps->getLayerIdInNuh( layerIdInVps ) ); 
+    }
+  }     
+
+  Int numTargetDecLayers = (Int) targetDecLayerIdSet.size(); 
+  Int latestDecIdx; 
+  for ( latestDecIdx = 0; latestDecIdx < numTargetDecLayers; latestDecIdx++)
+  {
+    if ( targetDecLayerIdSet[ latestDecIdx ] == curLayerId )
+      break; 
+  }        
+
+  for( Int i = 0; i <= latestDecIdx; i++ ) 
+  {
+    if ( vps->nuhLayerIdIncluded( targetDecLayerIdSet[ i ] ) )
+    {
+      TComPic* pcPic = ivPicLists->getPic( targetDecLayerIdSet[ i ], curPoc ); 
+      if( pcPic->getSlice(0)->isReferenced() && pcPic->getSlice(0)->getTemporalLayerNonReferenceFlag() ) 
+      { 
+        Bool remainingInterLayerReferencesFlag = false; 
+        for( Int j = latestDecIdx + 1; j < numTargetDecLayers; j++ )
+        { 
+          TComVPS* vpsSlice = pcPic->getSlice(0)->getVPS(); 
+          if ( vps->nuhLayerIdIncluded( targetDecLayerIdSet[ j ] ) )
+          {
+            Int targetDecLayerIdinVPS = vpsSlice->getLayerIdInVps( targetDecLayerIdSet[ j ] ); 
+            for( Int k = 0; k < vpsSlice->getNumDirectRefLayers( targetDecLayerIdinVPS ); k++ )
+              if ( targetDecLayerIdSet[ i ] == vpsSlice->getRefLayerId( targetDecLayerIdinVPS,  k  ) )
+                remainingInterLayerReferencesFlag = true;
+          }
+        }
+        if( !remainingInterLayerReferencesFlag )
+          pcPic->getSlice(0)->setReferenced( false );                   
+      }
+    }
+  }
+}
+
+Void TComSlice::xPrintRefPicList()
+{  
+  for ( Int li = 0; li < 2; li++)
+  {    
+    std::cout << std::endl << "RefPicListL" <<  li << ":" << std::endl; 
+    for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[li]-1); rIdx ++)
+    {      
+      if (rIdx == 0 && li == 0) m_apcRefPicList[li][rIdx]->print( true );
+        
+      m_apcRefPicList[li][rIdx]->print( false );
+    }
+  }
+}
+#endif
 /** get scaling matrix from RefMatrixID
  * \param sizeId size index
@@ -2067,4 +2364,7 @@
   {
     Int spsId = pps->getSPSId();
+#if H_MV
+    // active parameter sets per layer should be used here
+#else
     if (!isIRAP && (spsId != m_activeSPSId))
     {
@@ -2072,4 +2372,5 @@
       return false;
     }
+#endif
     TComSPS *sps = m_spsMap.getPS(spsId);
     if (sps)
@@ -2126,4 +2427,15 @@
 }
 
+#if H_MV
+Void TComPTL::copyLevelFrom( TComPTL* source )
+{
+  getGeneralPTL()->setLevelIdc( source->getGeneralPTL()->getLevelIdc() );
+  for( Int subLayer = 0; subLayer < 6; subLayer++ )
+  {
+    setSubLayerLevelPresentFlag( subLayer, source->getSubLayerLevelPresentFlag( subLayer ) );
+    getSubLayerPTL( subLayer )->setLevelIdc( source->getSubLayerPTL( subLayer )->getLevelIdc() );
+  }
+}
+#endif
 #if SIGNAL_BITRATE_PICRATE_IN_VPS
 TComBitRatePicRateInfo::TComBitRatePicRateInfo()
Index: branches/HTM-DEV-0.1-dev/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- branches/HTM-DEV-0.1-dev/source/Lib/TLibCommon/TComSlice.h	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/Lib/TLibCommon/TComSlice.h	(revision 368)
@@ -51,4 +51,7 @@
 class TComPic;
 class TComTrQuant;
+#if H_MV
+class TComPicLists; 
+#endif
 // ====================================================================================================================
 // Constants
@@ -245,4 +248,7 @@
   ProfileTierLevel* getGeneralPTL()  { return &m_generalPTL; }
   ProfileTierLevel* getSubLayerPTL(Int i)  { return &m_subLayerPTL[i]; }
+#if H_MV
+  Void copyLevelFrom( TComPTL* source );
+#endif
 };
 /// VPS class
@@ -480,12 +486,24 @@
 
   UInt        m_numHrdParameters;
+#if H_MV
+  UInt        m_maxNuhLayerId;
+#else
   UInt        m_maxNuhReservedZeroLayerId;
+#endif
   TComHRD*    m_hrdParameters;
   UInt*       m_hrdOpSetIdx;
   Bool*       m_cprmsPresentFlag;
   UInt        m_numOpSets;
+#if H_MV
+  Bool        m_layerIdIncludedFlag[MAX_VPS_OP_SETS_PLUS1][MAX_VPS_NUH_LAYER_ID_PLUS1];
+#else
   Bool        m_layerIdIncludedFlag[MAX_VPS_OP_SETS_PLUS1][MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1];
-
+#endif
+
+#if H_MV
+  TComPTL     m_pcPTL[MAX_VPS_OP_SETS_PLUS1];
+#else
   TComPTL     m_pcPTL;
+#endif
 #if SIGNAL_BITRATE_PICRATE_IN_VPS
   TComBitRatePicRateInfo    m_bitRatePicRateInfo;
@@ -495,4 +513,26 @@
 #endif
 
+#if H_MV
+  Bool        m_avcBaseLayerFlag;
+  Bool        m_splittingFlag;
+  Bool        m_scalabilityMask          [MAX_NUM_SCALABILITY_TYPES];
+  Int         m_dimensionIdLen           [MAX_NUM_SCALABILITY_TYPES];
+  Bool        m_vpsNuhLayerIdPresentFlag;
+  Int         m_layerIdInNuh             [MAX_NUM_LAYER_IDS];
+  Int         m_layerIdInVps             [MAX_NUM_LAYERS   ];
+  Int         m_dimensionId              [MAX_NUM_LAYER_IDS][MAX_NUM_SCALABILITY_TYPES];  
+
+  
+  Bool        m_vpsProfilePresentFlag    [MAX_VPS_OP_SETS_PLUS1];
+  Int         m_profileLayerSetRefMinus1 [MAX_VPS_OP_SETS_PLUS1];
+  Int         m_numOutputLayerSets;
+  Int         m_outputLayerSetIdx        [MAX_VPS_OP_SETS_PLUS1];
+  Bool        m_outputLayerFlag          [MAX_VPS_OP_SETS_PLUS1][MAX_VPS_NUH_LAYER_ID_PLUS1];
+  Bool        m_directDependencyFlag     [MAX_NUM_LAYER_IDS][MAX_NUM_LAYER_IDS];
+
+  Int         m_numDirectRefLayers       [ MAX_NUM_LAYERS ];
+  Int         m_refLayerId               [ MAX_NUM_LAYERS ][MAX_NUM_LAYERS];  
+
+#endif
 public:
   TComVPS();
@@ -536,6 +576,11 @@
   Void    setNumHrdParameters(UInt v)                           { m_numHrdParameters = v;    }
 
+#if H_MV
+  UInt    getMaxNuhLayerId()                                    { return m_maxNuhLayerId; }
+  Void    setMaxNuhLayerId(UInt v)                              { m_maxNuhLayerId = v;    }
+#else
   UInt    getMaxNuhReservedZeroLayerId()                        { return m_maxNuhReservedZeroLayerId; }
   Void    setMaxNuhReservedZeroLayerId(UInt v)                  { m_maxNuhReservedZeroLayerId = v;    }
+#endif
 
   UInt    getMaxOpSets()                                        { return m_numOpSets; }
@@ -544,5 +589,9 @@
   Void    setLayerIdIncludedFlag(Bool v, UInt opsIdx, UInt id)  { m_layerIdIncludedFlag[opsIdx][id] = v;    }
 
+#if H_MV
+  TComPTL* getPTL( Int layerSet = 0 ) { return &m_pcPTL[layerSet]; }
+#else
   TComPTL* getPTL() { return &m_pcPTL; }
+#endif
 #if SIGNAL_BITRATE_PICRATE_IN_VPS
   TComBitRatePicRateInfo *getBitratePicrateInfo() { return &m_bitRatePicRateInfo; }
@@ -550,4 +599,69 @@
 #if L0043_TIMING_INFO
   TimingInfo* getTimingInfo() { return &m_timingInfo; }
+#endif
+#if H_MV
+  Void    setAvcBaseLayerFlag( Bool val )                                  { m_avcBaseLayerFlag = val;  }
+  Bool    getAvcBaseLayerFlag()                                            { return m_avcBaseLayerFlag; } 
+
+  Void    setSplittingFlag( Bool val )                                     { m_splittingFlag = val;  }
+  Bool    getSplittingFlag()                                               { return m_splittingFlag; }
+
+  Void    setScalabilityMask( UInt val );
+
+  Void    setScalabilityMask( Int scalType, Bool val )              { m_scalabilityMask[scalType] = val;  }
+  Bool    getScalabilityMask( Int scalType )                        { return m_scalabilityMask[scalType]; }
+
+  Int     getNumScalabilityTypes( );
+
+  Void    setDimensionIdLen( Int sIdx, Int val )                           { m_dimensionIdLen[sIdx] = val;  }
+  Int     getDimensionIdLen( Int sIdx )                                    { assert( m_dimensionIdLen[sIdx] > 0) ; return m_dimensionIdLen[sIdx]; }  
+
+  Void    setVpsNuhLayerIdPresentFlag( Bool val )                          { m_vpsNuhLayerIdPresentFlag = val; }
+  Bool    getVpsNuhLayerIdPresentFlag()                                    { return m_vpsNuhLayerIdPresentFlag; }
+
+  Void    setLayerIdInNuh( Int layerIdInVps, Int val )                     { m_layerIdInNuh[layerIdInVps] = val;  }
+  Int     getLayerIdInNuh( Int layerIdInVps )                              { assert( m_layerIdInNuh[layerIdInVps] >= 0 ); return m_layerIdInNuh[layerIdInVps]; }
+
+  Void    setLayerIdInVps( Int layerIdInNuh, Int val )                     { m_layerIdInVps[layerIdInNuh] = val;  }
+  Int     getLayerIdInVps( Int layerIdInNuh )                              { assert( m_layerIdInVps[layerIdInNuh] >= 0 ); return m_layerIdInVps[layerIdInNuh]; }
+
+  Bool    nuhLayerIdIncluded( Int layerIdinNuh )                           { return ( m_layerIdInVps[ layerIdinNuh ] > 0 );  }
+
+  Void    setDimensionId( Int layerIdInVps, Int scalIdx, Int val )         { m_dimensionId[layerIdInVps][scalIdx] = val;  }
+  Int     getDimensionId( Int layerIdInVps, Int scalIdx )                  { return m_dimensionId[layerIdInVps][scalIdx]; }
+
+  Int     getScalabilityId ( Int layerIdInVps, ScalabilityType scalType );
+
+  Int     getViewId  ( Int layerIdInVps )                                  { return getScalabilityId( layerIdInVps, VIEW_ID  ); }
+#if H_3D  
+  Int     getDepthId ( Int layerIdInVps )                                  { return getScalabilityId( layerIdInVps, DEPTH_ID ); }
+#endif
+
+
+  Void    setVpsProfilePresentFlag( Int layerSet, Bool val )               { m_vpsProfilePresentFlag[layerSet] = val;  }
+  Bool    getVpsProfilePresentFlag( Int layerSet )                         { return m_vpsProfilePresentFlag[layerSet]; }
+
+  Void    setProfileLayerSetRefMinus1( Int layerSet, Int val )             { m_profileLayerSetRefMinus1[layerSet] = val;  }
+  Bool    getProfileLayerSetRefMinus1( Int layerSet )                      { return m_profileLayerSetRefMinus1[layerSet]; }
+
+  Void    setNumOutputLayerSets( Int val )                                 { m_numOutputLayerSets = val;  }
+  Int     getNumOutputLayerSets()                                          { return m_numOutputLayerSets; }
+
+  Void    setOutputLayerSetIdx( Int layerSet, Int val )                    { m_outputLayerSetIdx[layerSet] = val;  }
+  Int     getOutputLayerSetIdx( Int layerSet )                             { return m_outputLayerSetIdx[layerSet]; }
+
+  Void    setOutputLayerFlag( Int layerSet, Int layer, Bool val )          { m_outputLayerFlag[layerSet][layer] = val;  }
+  Bool    getOutputLayerFlag( Int layerSet, Int layer )                    { return m_outputLayerFlag[layerSet][layer]; }
+
+  Void    setDirectDependencyFlag( Int layerHigh, Int layerLow, Bool val ) { m_directDependencyFlag[layerHigh][layerLow] = val;  }
+  Bool    getDirectDependencyFlag( Int layerHigh, Int layerLow )           { return m_directDependencyFlag[layerHigh][layerLow]; }
+
+  Void    calcIvRefLayers(); 
+
+  Int     getNumDirectRefLayers( Int layerIdInVps )          { return m_numDirectRefLayers[ layerIdInVps ];  };                               
+  Int     getRefLayerId        ( Int layerIdInVps, Int idx );; 
+  
+  Bool    checkVPSExtensionSyntax(); 
+  Int     scalTypeToScalIdx   ( ScalabilityType scalType );
 #endif
 };
@@ -853,4 +967,7 @@
   static const Int   m_winUnitY[MAX_CHROMA_FORMAT_IDC+1];
   TComPTL     m_pcPTL;
+#if H_MV
+  Bool        m_interViewMvVertConstraintFlag;
+#endif
 public:
   TComSPS();
@@ -983,4 +1100,8 @@
 
   TComPTL* getPTL()     { return &m_pcPTL; }
+#if H_MV
+  Void setInterViewMvVertConstraintFlag(Bool val) { m_interViewMvVertConstraintFlag = val; }
+  Bool getInterViewMvVertConstraintFlag()         { return m_interViewMvVertConstraintFlag;}
+#endif
 };
 
@@ -1009,4 +1130,9 @@
   Void       setRefPicSetIdxL1(UInt idx, UInt refPicSetIdx) { m_RefPicSetIdxL1[idx] = refPicSetIdx; }
   UInt       getRefPicSetIdxL1(UInt idx) { return m_RefPicSetIdxL1[idx]; }
+#if H_MV
+  // Why not an listIdx for all members, would avoid code duplication?? 
+  Void       setRefPicSetIdxL(UInt li, UInt idx, UInt refPicSetIdx) {( li==0 ? m_RefPicSetIdxL0[idx] : m_RefPicSetIdxL1[idx] ) = refPicSetIdx; };
+  Void       setRefPicListModificationFlagL(UInt li, Bool flag) { ( li==0  ? m_bRefPicListModificationFlagL0 : m_bRefPicListModificationFlagL1 ) = flag;  };  
+#endif
 };
 
@@ -1263,4 +1389,7 @@
   TComPic*    m_apcRefPicList [2][MAX_NUM_REF+1];
   Int         m_aiRefPOCList  [2][MAX_NUM_REF+1];
+#if H_MV
+  Int         m_aiRefLayerIdList[2][MAX_NUM_REF+1];
+#endif
   Bool        m_bIsUsedAsLongTerm[2][MAX_NUM_REF+1];
   Int         m_iDepth;
@@ -1328,4 +1457,11 @@
 
   Bool       m_enableTMVPFlag;
+#if H_MV
+  Int        m_layerId; 
+  Int        m_viewId;
+#if H_3D
+  Bool       m_isDepth;
+#endif
+#endif
 public:
   TComSlice();
@@ -1434,8 +1570,16 @@
   Void      setDepth            ( Int iDepth )                  { m_iDepth            = iDepth; }
   
+#if H_MV
+  Int       getRefLayerId        ( RefPicList e, Int iRefIdx)    { return  m_aiRefLayerIdList[e][iRefIdx]; }
+  Void      setRefLayerId        ( Int i, RefPicList e, Int iRefIdx ) { m_aiRefLayerIdList[e][iRefIdx] = i; }
+#endif
+#if H_MV
+  Void      setRefPicList       ( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& interLayerRefPicSet , Bool checkNumPocTotalCurr = false );
+#else
 #if FIX1071
   Void      setRefPicList       ( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr = false );
 #else
   Void      setRefPicList       ( TComList<TComPic*>& rcListPic );
+#endif
 #endif
   Void      setRefPOCList       ();
@@ -1485,4 +1629,12 @@
   Void decodingMarking( TComList<TComPic*>& rcListPic, Int iGOPSIze, Int& iMaxRefPicNum ); 
   Void applyReferencePictureSet( TComList<TComPic*>& rcListPic, TComReferencePictureSet *RPSList);
+#if H_MV
+  Void createAndApplyIvReferencePictureSet( TComPicLists* ivPicLists, std::vector<TComPic*>& refPicSetInterLayer );
+  static Void markIvRefPicsAsShortTerm    ( std::vector<TComPic*> refPicSetInterLayer );
+  static Void markIvRefPicsAsUnused       ( TComPicLists* ivPicLists, std::vector<Int> targetDecLayerIdSet, TComVPS* vps, Int curLayerId, Int curPoc  );
+
+
+  Void xPrintRefPicList();
+#endif
   Bool isTemporalLayerSwitchingPoint( TComList<TComPic*>& rcListPic );
   Bool isStepwiseTemporalLayerSwitchingPointCandidate( TComList<TComPic*>& rcListPic );
@@ -1560,8 +1712,22 @@
   Bool      getEnableTMVPFlag     ()              { return m_enableTMVPFlag;}
 
+#if H_MV
+  Void      setLayerId            ( Int layerId )    { m_layerId      = layerId; }
+  Int       getLayerId            ()                 { return m_layerId;    }
+  Int       getLayerIdInVps       ()                 { return getVPS()->getLayerIdInVps( m_layerId ); }; 
+  Void      setViewId             ( Int viewId )     { m_viewId = viewId;   }
+  Int       getViewId             ()                 { return m_viewId;     }
+#if H_3D
+  Void      setIsDepth            ( Bool isDepth )   { m_isDepth = isDepth; }
+  Bool      getIsDepth            ()                 { return m_isDepth; }
+#endif
+#endif
 protected:
   TComPic*  xGetRefPic  (TComList<TComPic*>& rcListPic,
                          Int                 poc);
 TComPic*  xGetLongTermRefPic(TComList<TComPic*>& rcListPic, Int poc, Bool pocHasMsb);
+#if H_MV
+  TComPic*  xGetInterLayerRefPic( std::vector<TComPic*>& rcListIlPic, Int layerId );
+#endif
 };// END CLASS DEFINITION TComSlice
 
Index: branches/HTM-DEV-0.1-dev/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- branches/HTM-DEV-0.1-dev/source/Lib/TLibCommon/TypeDef.h	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/Lib/TLibCommon/TypeDef.h	(revision 368)
@@ -45,4 +45,7 @@
 
 
+#if H_MV
+#define H_3D                        0
+#endif
 
 ///// ***** HM 10.1 *********
@@ -88,5 +91,11 @@
 #define MAX_VPS_NUM_HRD_PARAMETERS                1
 #define MAX_VPS_OP_SETS_PLUS1                     1024
+#if H_MV
+#define MAX_VPS_NUH_LAYER_ID_PLUS1  64
+#define MAX_NUM_SCALABILITY_TYPES   16
+#define ENC_CFG_CONSOUT_SPACE       29           
+#else
 #define MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1  1
+#endif
 
 #define RATE_CONTROL_LAMBDA_DOMAIN                  1  ///< JCTVC-K0103, rate control by R-lambda model
@@ -95,4 +104,7 @@
 #define MAX_CPB_CNT                     32  ///< Upper bound of (cpb_cnt_minus1 + 1)
 #define MAX_NUM_LAYER_IDS               64
+#if H_MV
+#define MAX_NUM_LAYERS                  64
+#endif
 
 #define COEF_REMAIN_BIN_REDUCTION        3 ///< indicates the level at which the VLC 
@@ -509,4 +521,11 @@
     MAIN10 = 2,
     MAINSTILLPICTURE = 3,
+#if H_MV
+    MAINSTEREO = 4,
+    MAINMULTIVIEW = 5,
+#if H_3D
+    MAIN3D = 6, 
+#endif
+#endif
   };
 }
@@ -540,3 +559,13 @@
 //! \}
 
-#endif
+#if H_MV
+/// scalability types
+  enum ScalabilityType
+  {
+    VIEW_ID  = 0,
+#if H_3D
+    DEPTH_ID = 1,
+#endif    
+  };
+#endif
+#endif
Index: branches/HTM-DEV-0.1-dev/source/Lib/TLibDecoder/NALread.cpp
===================================================================
--- branches/HTM-DEV-0.1-dev/source/Lib/TLibDecoder/NALread.cpp	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/Lib/TLibDecoder/NALread.cpp	(revision 368)
@@ -103,6 +103,10 @@
   assert(forbidden_zero_bit == 0);
   nalu.m_nalUnitType = (NalUnitType) bs.read(6);  // nal_unit_type
+#if H_MV
+  nalu.m_layerId = bs.read(6);                 // layerId
+#else
   nalu.m_reservedZero6Bits = bs.read(6);       // nuh_reserved_zero_6bits
   assert(nalu.m_reservedZero6Bits == 0);
+#endif
   nalu.m_temporalId = bs.read(3) - 1;             // nuh_temporal_id_plus1
 
Index: branches/HTM-DEV-0.1-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- branches/HTM-DEV-0.1-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 368)
@@ -680,8 +680,12 @@
   if (uiCode)
   {
+#if H_MV
+    READ_FLAG( uiCode, "inter_view_mv_vert_constraint_flag" );    pcSPS->setInterViewMvVertConstraintFlag(uiCode == 1 ? true : false);
+#else
     while ( xMoreRbspData() )
     {
       READ_FLAG( uiCode, "sps_extension_data_flag");
     }
+#endif
   }
 }
@@ -693,9 +697,17 @@
   READ_CODE( 4,  uiCode,  "vps_video_parameter_set_id" );         pcVPS->setVPSId( uiCode );
   READ_CODE( 2,  uiCode,  "vps_reserved_three_2bits" );           assert(uiCode == 3);
+#if H_MV
+  READ_CODE( 6,  uiCode,  "vps_max_layers_minus1" );              pcVPS->setMaxLayers( uiCode + 1 );
+#else
   READ_CODE( 6,  uiCode,  "vps_reserved_zero_6bits" );            assert(uiCode == 0);
+#endif
   READ_CODE( 3,  uiCode,  "vps_max_sub_layers_minus1" );          pcVPS->setMaxTLayers( uiCode + 1 );
   READ_FLAG(     uiCode,  "vps_temporal_id_nesting_flag" );       pcVPS->setTemporalNestingFlag( uiCode ? true:false );
   assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag());
+#if H_MV
+  READ_CODE( 16, uiCode,  "vps_extension_offset" );               
+#else
   READ_CODE( 16, uiCode,  "vps_reserved_ffff_16bits" );           assert(uiCode == 0xffff);
+#endif
   parsePTL ( pcVPS->getPTL(), true, pcVPS->getMaxTLayers()-1);
 #if SIGNAL_BITRATE_PICRATE_IN_VPS
@@ -727,11 +739,20 @@
 
   assert( pcVPS->getNumHrdParameters() < MAX_VPS_OP_SETS_PLUS1 );
+#if H_MV
+  assert( pcVPS->getMaxNuhLayerId() < MAX_VPS_NUH_LAYER_ID_PLUS1 );
+  READ_CODE( 6, uiCode, "vps_max_nuh_layer_id" );   pcVPS->setMaxNuhLayerId( uiCode );
+#else
   assert( pcVPS->getMaxNuhReservedZeroLayerId() < MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1 );
   READ_CODE( 6, uiCode, "vps_max_nuh_reserved_zero_layer_id" );   pcVPS->setMaxNuhReservedZeroLayerId( uiCode );
+#endif
   READ_UVLC(    uiCode, "vps_max_op_sets_minus1" );               pcVPS->setMaxOpSets( uiCode + 1 );
   for( UInt opsIdx = 1; opsIdx <= ( pcVPS->getMaxOpSets() - 1 ); opsIdx ++ )
   {
     // Operation point set
+#if H_MV
+    for( UInt i = 0; i <= pcVPS->getMaxNuhLayerId(); i ++ )
+#else
     for( UInt i = 0; i <= pcVPS->getMaxNuhReservedZeroLayerId(); i ++ )
+#endif
     {
       READ_FLAG( uiCode, "layer_id_included_flag[opsIdx][i]" );     pcVPS->setLayerIdIncludedFlag( uiCode == 1 ? true : false, opsIdx, i );
@@ -772,8 +793,110 @@
   if (uiCode)
   {
+#if H_MV
+    m_pcBitstream->readOutTrailingBits();
+
+    READ_FLAG( uiCode, "avc_base_layer_flag" );                     pcVPS->setAvcBaseLayerFlag( uiCode == 1 ? true : false );
+    READ_FLAG( uiCode, "splitting_flag" );                          pcVPS->setSplittingFlag( uiCode == 1 ? true : false );
+
+    // Parse scalability_mask[i]    
+    for( Int sIdx = 0; sIdx < MAX_NUM_SCALABILITY_TYPES; sIdx++ )
+    {
+      READ_FLAG( uiCode,  "scalability_mask[i]" );                  pcVPS->setScalabilityMask( sIdx, uiCode == 1 ? true : false );      
+    }
+
+    Int numScalabilityTypes = pcVPS->getNumScalabilityTypes(); 
+
+    // Parse dimension_id_len_minus1[j]    
+    for( Int sIdx = 0; sIdx < numScalabilityTypes; sIdx++ )
+    {
+        READ_CODE( 3, uiCode, "dimension_id_len_minus1[j]" );       pcVPS->setDimensionIdLen( sIdx, uiCode + 1 );
+    }
+
+    // vps_nuh_layer_id_present_flag
+    READ_FLAG( uiCode, "vps_nuh_layer_id_present_flag" );           pcVPS->setVpsNuhLayerIdPresentFlag( uiCode == 1 ? true : false );
+
+    // parse layer_id_in_nuh[i] and derive LayerIdInVps
+    pcVPS->setLayerIdInNuh( 0, 0 ); pcVPS->setLayerIdInVps( 0, 0 );
+    
+    for( Int layer = 1; layer <= pcVPS->getMaxLayers() - 1; layer++ )
+    {
+      UInt layerIdInNuh; 
+      if ( pcVPS->getVpsNuhLayerIdPresentFlag() )
+      {
+        READ_CODE( 6, uiCode, "layer_id_in_nuh[i]" );                layerIdInNuh = uiCode; 
+      }
+      else
+      {
+        layerIdInNuh = layer; 
+      }      
+
+      pcVPS->setLayerIdInNuh( layer, layerIdInNuh );
+      pcVPS->setLayerIdInVps( layerIdInNuh, layer ); 
+
+      // parse dimension_id[i][j]
+      for( Int sIdx = 0; sIdx < numScalabilityTypes; sIdx++ )
+      {
+          READ_CODE( pcVPS->getDimensionIdLen( sIdx ), uiCode, "dimension_id[i][j]" );  pcVPS->setDimensionId( layer, sIdx, uiCode );
+      }
+    }
+
+    for( Int layerSet = 1; layerSet <= pcVPS->getMaxOpSets() - 1; layerSet++ )
+    {
+      READ_FLAG(  uiCode, "vps_profile_present_flag[lsIdx]" );    pcVPS->setVpsProfilePresentFlag( layerSet, uiCode == 1 ? true : false );
+      if( pcVPS->getVpsProfilePresentFlag( layerSet ) == false )
+      {
+        READ_UVLC( uiCode, "profile_layer_set_ref_minus1[lsIdx]" ); pcVPS->setProfileLayerSetRefMinus1( layerSet, uiCode );
+      }
+
+      parsePTL ( pcVPS->getPTL( layerSet ), pcVPS->getVpsProfilePresentFlag( layerSet ), pcVPS->getMaxTLayers()-1);
+      if( pcVPS->getVpsProfilePresentFlag( layerSet ) == false )
+      {
+        TComPTL temp = *pcVPS->getPTL( layerSet );
+        *pcVPS->getPTL( layerSet ) = *pcVPS->getPTL( pcVPS->getProfileLayerSetRefMinus1( layerSet ) + 1 );
+        pcVPS->getPTL( layerSet )->copyLevelFrom( &temp );
+      }
+    }
+
+    READ_UVLC( uiCode, "num_output_layer_sets" );                  pcVPS->setNumOutputLayerSets( uiCode );
+    
+    for( Int layerSet = 0; layerSet < pcVPS->getNumOutputLayerSets(); layerSet++ )
+    {
+      READ_UVLC( uiCode, "output_layer_set_idx[i]" );              pcVPS->setOutputLayerSetIdx( layerSet, uiCode );
+      for( Int layer = 0; layer <= pcVPS->getMaxNuhLayerId(); layer++ )
+      {
+        if( pcVPS->getLayerIdIncludedFlag( pcVPS->getOutputLayerSetIdx( layerSet ), layer ) == true )
+        {
+          READ_FLAG( uiCode, "output_layer_flag" );                 pcVPS->setOutputLayerFlag( layerSet, layer, uiCode == 1 ? true : false );
+        }
+      }
+    }
+
+    for( Int i = 1; i <= pcVPS->getMaxLayers() - 1; i++ )
+    {
+      for( Int j = 0; j < i; j++ )
+      {
+        READ_FLAG( uiCode, "direct_dependency_flag[i][j]" );             pcVPS->setDirectDependencyFlag( i, j, uiCode );
+      }
+    }
+    
+    READ_FLAG( uiCode,  "vps_extension2_flag" );
+    if (uiCode)
+    {
+      while ( xMoreRbspData() )
+      {
+        READ_FLAG( uiCode, "vps_extension2_data_flag");
+      }
+    }
+
+    pcVPS->checkVPSExtensionSyntax(); 
+
+    pcVPS->calcIvRefLayers(); 
+
+#else
     while ( xMoreRbspData() )
     {
       READ_FLAG( uiCode, "vps_extension_data_flag");
     }
+#endif    
   }
   
@@ -791,4 +914,7 @@
   TComPPS* pps = NULL;
   TComSPS* sps = NULL;
+#if H_MV
+  TComVPS* vps = NULL;
+#endif
 
   UInt firstSliceSegmentInPic;
@@ -805,4 +931,9 @@
   //!KS: need to add error handling code here, if SPS is not available
   assert(sps!=0);
+#if H_MV
+  vps = parameterSetManager->getPrefetchedVPS(sps->getVPSId());
+  assert(vps!=0);
+  rpcSlice->setVPS(vps);
+#endif
   rpcSlice->setSPS(sps);
   rpcSlice->setPPS(pps);
@@ -1392,8 +1523,14 @@
   for (Int i = 0; i < maxNumSubLayersMinus1; i++)
   {
+#if !H_MV
     if(profilePresentFlag)
     {
+#endif
       READ_FLAG( uiCode, "sub_layer_profile_present_flag[i]" ); rpcPTL->setSubLayerProfilePresentFlag(i, uiCode);
-    }
+#if H_MV
+    rpcPTL->setSubLayerProfilePresentFlag( i, profilePresentFlag && rpcPTL->getSubLayerProfilePresentFlag(i) );
+#else
+    }
+#endif
     READ_FLAG( uiCode, "sub_layer_level_present_flag[i]"   ); rpcPTL->setSubLayerLevelPresentFlag  (i, uiCode);
   }
Index: branches/HTM-DEV-0.1-dev/source/Lib/TLibDecoder/TDecGop.cpp
===================================================================
--- branches/HTM-DEV-0.1-dev/source/Lib/TLibDecoder/TDecGop.cpp	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/Lib/TLibDecoder/TDecGop.cpp	(revision 368)
@@ -205,13 +205,23 @@
   }
 
+#if !H_3D
   rpcPic->compressMotion(); 
+#endif
   Char c = (pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B');
   if (!pcSlice->isReferenced()) c += 32;
 
   //-- For time output for each slice
+#if H_MV
+  printf("\nLayer %2d   POC %4d TId: %1d ( %c-SLICE, QP%3d ) ", pcSlice->getLayerId(),
+                                                              pcSlice->getPOC(),
+                                                              pcSlice->getTLayer(),
+                                                              c,
+                                                              pcSlice->getSliceQp() );
+#else
   printf("\nPOC %4d TId: %1d ( %c-SLICE, QP%3d ) ", pcSlice->getPOC(),
                                                     pcSlice->getTLayer(),
                                                     c,
                                                     pcSlice->getSliceQp() );
+#endif
 
   m_dDecTime += (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC;
@@ -224,5 +234,16 @@
     for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++)
     {
+#if H_MV
+      if( pcSlice->getLayerId() != pcSlice->getRefLayerId( RefPicList(iRefList), iRefIndex ) )
+      {
+        printf( "V%d ", pcSlice->getRefLayerId( RefPicList(iRefList), iRefIndex ) );
+      }
+      else
+      {
+#endif
       printf ("%d ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex));
+#if H_MV
+      }
+#endif
     }
     printf ("] ");
Index: branches/HTM-DEV-0.1-dev/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- branches/HTM-DEV-0.1-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 368)
@@ -39,4 +39,7 @@
 #include "TDecTop.h"
 
+#if H_MV
+ParameterSetManagerDecoder TDecTop::m_parameterSetManagerDecoder;
+#endif
 //! \ingroup TLibDecoder
 //! \{
@@ -57,4 +60,11 @@
   m_bFirstSliceInPicture    = true;
   m_bFirstSliceInSequence   = true;
+#if H_MV
+  m_layerId = 0;
+  m_viewId = 0;
+#if H_3D
+  m_isDepth = false;
+#endif
+#endif
 }
 
@@ -86,5 +96,7 @@
 {
   // initialize ROM
+#if !H_MV
   initROM();
+#endif
   m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
   m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
@@ -100,8 +112,15 @@
   {
     TComPic* pcPic = *(iterPic++);
+#if H_MV
+    if( pcPic )
+    {
+#endif
     pcPic->destroy();
     
     delete pcPic;
     pcPic = NULL;
+#if H_MV
+    }
+#endif
   }
   
@@ -110,6 +129,8 @@
   m_cLoopFilter.        destroy();
   
+#if !H_MV
   // destroy ROM
   destroyROM();
+#endif
 }
 
@@ -177,5 +198,9 @@
 }
 
+#if H_MV
+Void TDecTop::endPicDecoding(Int& poc, TComList<TComPic*>*& rpcListPic, std::vector<Int>& targetDecLayerIdSet )
+#else
 Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic)
+#endif
 {
   if (!m_pcPic)
@@ -195,4 +220,8 @@
   rpcListPic          = &m_cListPic;  
   m_cCuDecoder.destroy();        
+#if H_MV 
+  TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer );  
+  TComSlice::markIvRefPicsAsUnused   ( m_ivPicLists, targetDecLayerIdSet, m_parameterSetManagerDecoder.getActiveVPS(), m_layerId, poc ); 
+#endif
   m_bFirstSliceInPicture  = true;
 
@@ -311,6 +340,13 @@
 }
 
+#if H_MV
+Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool newLayerFlag )
+{
+  assert( nalu.m_layerId == m_layerId ); 
+
+#else
 Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
 {
+#endif
   TComPic*&   pcPic         = m_pcPic;
   m_apcSlicePilot->initSlice();
@@ -337,6 +373,20 @@
   m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
 
+#if H_MV
+  m_apcSlicePilot->setLayerId( nalu.m_layerId );
+#endif
   m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
 
+#if H_MV  
+  TComVPS* vps     = m_apcSlicePilot->getVPS();
+  Int layerIdInVps = vps->getLayerIdInVps( nalu.m_layerId );
+  
+  setViewId(  vps->getViewId( layerIdInVps  ) );
+  m_apcSlicePilot->setViewId( getViewId() );
+#if H_3D
+  setIsDepth( vps->getDepthId( layerIdInVps ) == 1 );
+  m_apcSlicePilot->setIsDepth( getIsDepth() );
+#endif
+#endif
     // Skip pictures due to random access
     if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
@@ -365,4 +415,10 @@
     m_prevPOC = m_apcSlicePilot->getPOC();
   }
+#if H_MV
+  if ( newLayerFlag )
+  {
+    return false; 
+  }
+#endif
   // actual decoding starts here
   xActivateParameterSets();
@@ -384,4 +440,7 @@
     m_cPrediction.initTempBuff();
     m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
+#if H_MV
+    m_apcSlicePilot->createAndApplyIvReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer ); 
+#endif
     //  Get a new picture buffer
     xGetNewPicBuffer (m_apcSlicePilot, pcPic);
@@ -515,8 +574,18 @@
   pcPic->setTLayer(nalu.m_temporalId);
 
+#if H_MV
+  pcPic->setLayerId( nalu.m_layerId );
+  pcPic->setViewId ( getViewId() );
+#if H_3D
+  pcPic->setIsDepth( getIsDepth() );
+#endif
+#endif
   if (bNextSlice)
   {
     pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA, m_cListPic );
     // Set reference list
+#if H_MV    
+    pcSlice->setRefPicList( m_cListPic, m_refPicSetInterLayer, true );    
+#else
 #if FIX1071
     pcSlice->setRefPicList( m_cListPic, true );
@@ -525,4 +594,5 @@
 #endif
 
+#endif
     // For generalized B
     // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
@@ -662,5 +732,9 @@
 }
 
+#if H_MV
+Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayerFlag)
+#else
 Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
+#endif
 {
   // Initialize entropy decoder
@@ -703,5 +777,9 @@
     case NAL_UNIT_CODED_SLICE_RASL_N:
     case NAL_UNIT_CODED_SLICE_RASL_R:
+#if H_MV
+      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, newLayerFlag);
+#else
       return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
+#endif
       break;
     default:
@@ -783,3 +861,26 @@
 }
 
+#if H_MV
+TComPic* TDecTop::getPic( Int poc )
+{
+  xGetPic( m_layerId, poc ); 
+  TComList<TComPic*>* listPic = getListPic();
+  TComPic* pcPic = NULL;
+  for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++)
+  {
+    if( (*it)->getPOC() == poc )
+    {
+      pcPic = *it ;
+      break ;
+    }
+  }
+  return pcPic;
+}
+
+TComPic* TDecTop::xGetPic( Int layerId, Int poc )
+{ 
+  return m_ivPicLists->getPic( layerId, poc ) ;
+}
+
+#endif
 //! \}
Index: branches/HTM-DEV-0.1-dev/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- branches/HTM-DEV-0.1-dev/source/Lib/TLibDecoder/TDecTop.h	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/Lib/TLibDecoder/TDecTop.h	(revision 368)
@@ -61,4 +61,7 @@
 // ====================================================================================================================
 
+#if H_MV
+class TAppDecTop;
+#endif
 /// decoder class
 class TDecTop
@@ -72,5 +75,9 @@
 
   TComList<TComPic*>      m_cListPic;         //  Dynamic buffer
+#if H_MV
+  static ParameterSetManagerDecoder m_parameterSetManagerDecoder;  // storage for parameter sets 
+#else
   ParameterSetManagerDecoder m_parameterSetManagerDecoder;  // storage for parameter sets 
+#endif
   TComSlice*              m_apcSlicePilot;
   
@@ -98,4 +105,14 @@
   Bool                    m_bFirstSliceInPicture;
   Bool                    m_bFirstSliceInSequence;
+#if H_MV
+  // For H_MV m_bFirstSliceInSequence indicates first slice in sequence of the particular layer  
+  Int                     m_layerId;
+  Int                     m_viewId;
+  TComPicLists*           m_ivPicLists;
+  std::vector<TComPic*>   m_refPicSetInterLayer; 
+#if H_3D
+  Bool                    m_isDepth;
+#endif
+#endif
 
 public:
@@ -109,10 +126,33 @@
 
   Void  init();
+#if H_MV  
+  Bool  decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayer );
+#else  
   Bool  decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay);
+#endif
   
   Void  deletePicBuffer();
 
+#if H_MV
+  Void endPicDecoding(Int& poc, TComList<TComPic*>*& rpcListPic,  std::vector<Int>& targetDecLayerIdSet);  
+#else
   Void executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic);
+#endif
   
+#if H_MV    
+  TComPic*                getPic                ( Int poc );
+  TComList<TComPic*>*     getListPic            ()               { return &m_cListPic;  }  
+  Void                    setIvPicLists         ( TComPicLists* picLists) { m_ivPicLists = picLists; }
+  
+  Int                     getCurrPoc            ()               { return m_apcSlicePilot->getPOC(); }
+  Void                    setLayerId            ( Int layer)     { m_layerId = layer;   }
+  Int                     getLayerId            ()               { return m_layerId;    }
+  Void                    setViewId             ( Int viewId  )  { m_viewId  = viewId;  }
+  Int                     getViewId             ()               { return m_viewId;     }  
+#if H_3D    
+  Void                    setIsDepth            ( Bool isDepth ) { m_isDepth = isDepth; }
+  Bool                    getIsDepth            ()               { return m_isDepth;    }
+#endif
+#endif
 protected:
   Void  xGetNewPicBuffer  (TComSlice* pcSlice, TComPic*& rpcPic);
@@ -120,5 +160,10 @@
 
   Void      xActivateParameterSets();
+#if H_MV  
+  TComPic*  xGetPic( Int layerId, Int poc ); 
+  Bool      xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool newLayerFlag );  
+#else
   Bool      xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay);
+#endif
   Void      xDecodeVPS();
   Void      xDecodeSPS();
Index: branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/NALwrite.cpp
===================================================================
--- branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/NALwrite.cpp	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/NALwrite.cpp	(revision 368)
@@ -53,5 +53,9 @@
   bsNALUHeader.write(0,1);                    // forbidden_zero_bit
   bsNALUHeader.write(nalu.m_nalUnitType, 6);  // nal_unit_type
+#if H_MV
+  bsNALUHeader.write(nalu.m_layerId, 6);      // layerId       
+#else
   bsNALUHeader.write(nalu.m_reservedZero6Bits, 6);                   // nuh_reserved_zero_6bits
+#endif
   bsNALUHeader.write(nalu.m_temporalId+1, 3); // nuh_temporal_id_plus1
 
@@ -142,5 +146,9 @@
 {
   naluDest.m_nalUnitType = naluSrc.m_nalUnitType;
+#if H_MV
+  naluDest.m_layerId  = naluSrc.m_layerId;
+#else
   naluDest.m_reservedZero6Bits  = naluSrc.m_reservedZero6Bits;
+#endif
   naluDest.m_temporalId  = naluSrc.m_temporalId;
   naluDest.m_Bitstream   = naluSrc.m_Bitstream;
Index: branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/NALwrite.h
===================================================================
--- branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/NALwrite.h	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/NALwrite.h	(revision 368)
@@ -57,6 +57,14 @@
     NalUnitType nalUnitType,
     UInt temporalID = 0,
+#if H_MV
+    Int layerId = 0)
+#else
     UInt reserved_zero_6bits = 0)
+#endif
+#if H_MV
+  : NALUnit(nalUnitType, temporalID, layerId)
+#else
   : NALUnit(nalUnitType, temporalID, reserved_zero_6bits)
+#endif
   , m_Bitstream()
   {}
Index: branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/TEncAnalyze.cpp
===================================================================
--- branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/TEncAnalyze.cpp	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/TEncAnalyze.cpp	(revision 368)
@@ -36,5 +36,7 @@
 */
 
+#if !H_MV
 #include "TEncAnalyze.h"
+#endif
 
 //! \ingroup TLibEncoder
@@ -45,8 +47,10 @@
 //////////////////////////////////////////////////////////////////////
 
+#if !H_MV
 TEncAnalyze             m_gcAnalyzeAll;
 TEncAnalyze             m_gcAnalyzeI;
 TEncAnalyze             m_gcAnalyzeP;
 TEncAnalyze             m_gcAnalyzeB;
+#endif
 
 //! \}
Index: branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/TEncAnalyze.h
===================================================================
--- branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/TEncAnalyze.h	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/TEncAnalyze.h	(revision 368)
@@ -150,8 +150,10 @@
 };
 
+#if !H_MV
 extern TEncAnalyze             m_gcAnalyzeAll;
 extern TEncAnalyze             m_gcAnalyzeI;
 extern TEncAnalyze             m_gcAnalyzeP;
 extern TEncAnalyze             m_gcAnalyzeB;
+#endif
 
 //! \}
Index: branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 368)
@@ -549,5 +549,11 @@
   }
 
+#if H_MV
+  WRITE_FLAG( 1, "sps_extension_flag" );
+
+  WRITE_FLAG( pcSPS->getInterViewMvVertConstraintFlag() ? 1 : 0, "inter_view_mv_vert_constraint_flag" );
+#else
   WRITE_FLAG( 0, "sps_extension_flag" );
+#endif
 }
 
@@ -556,9 +562,17 @@
   WRITE_CODE( pcVPS->getVPSId(),                    4,        "vps_video_parameter_set_id" );
   WRITE_CODE( 3,                                    2,        "vps_reserved_three_2bits" );
+#if H_MV
+  WRITE_CODE( pcVPS->getMaxLayers() - 1,            6,        "vps_max_layers_minus1" );
+#else
   WRITE_CODE( 0,                                    6,        "vps_reserved_zero_6bits" );
+#endif
   WRITE_CODE( pcVPS->getMaxTLayers() - 1,           3,        "vps_max_sub_layers_minus1" );
   WRITE_FLAG( pcVPS->getTemporalNestingFlag(),                "vps_temporal_id_nesting_flag" );
   assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag());
+#if H_MV
+  WRITE_CODE( 0xffff,                              16,        "vps_extension_offset" );
+#else
   WRITE_CODE( 0xffff,                              16,        "vps_reserved_ffff_16bits" );
+#endif
   codePTL( pcVPS->getPTL(), true, pcVPS->getMaxTLayers() - 1 );
 #if SIGNAL_BITRATE_PICRATE_IN_VPS
@@ -583,6 +597,11 @@
 
   assert( pcVPS->getNumHrdParameters() <= MAX_VPS_NUM_HRD_PARAMETERS );
+#if H_MV
+  assert( pcVPS->getMaxNuhLayerId() < MAX_VPS_NUH_LAYER_ID_PLUS1 );
+  WRITE_CODE( pcVPS->getMaxNuhLayerId(), 6,                 "vps_max_nuh_layer_id" );
+#else
   assert( pcVPS->getMaxNuhReservedZeroLayerId() < MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1 );
   WRITE_CODE( pcVPS->getMaxNuhReservedZeroLayerId(), 6,     "vps_max_nuh_reserved_zero_layer_id" );
+#endif
   pcVPS->setMaxOpSets(1);
   WRITE_UVLC( pcVPS->getMaxOpSets() - 1,                    "vps_max_op_sets_minus1" );
@@ -590,5 +609,9 @@
   {
     // Operation point set
+#if H_MV
+    for( UInt i = 0; i <= pcVPS->getMaxNuhLayerId(); i ++ )
+#else
     for( UInt i = 0; i <= pcVPS->getMaxNuhReservedZeroLayerId(); i ++ )
+#endif
     {
       // Only applicable for version 1
@@ -631,5 +654,69 @@
   }
 #endif
+#if H_MV
+  WRITE_FLAG( 1,                                             "vps_extension_flag" );
+
+  m_pcBitIf->writeAlignOne();                        
+
+  WRITE_FLAG( pcVPS->getAvcBaseLayerFlag() ? 1 : 0,          "avc_base_layer_flag" );
+  WRITE_FLAG( pcVPS->getSplittingFlag() ? 1 : 0,             "splitting_flag" );
+  
+  for( Int type = 0; type < MAX_NUM_SCALABILITY_TYPES; type++ )
+  {
+    WRITE_FLAG( pcVPS->getScalabilityMask( type ) ? 1 : 0,   "scalability_mask[i]" );
+  }
+
+  for( Int sIdx = 0; sIdx < pcVPS->getNumScalabilityTypes( ); sIdx++ )
+  {
+    WRITE_CODE( pcVPS->getDimensionIdLen( sIdx ) - 1 , 3,    "dimension_id_len_minus1[j]");    
+  }
+
+  WRITE_FLAG( pcVPS->getVpsNuhLayerIdPresentFlag() ? 1 : 0,  "vps_nuh_layer_id_present_flag");
+
+  for( Int layer = 1; layer <= pcVPS->getMaxLayers() - 1; layer++ )
+  {
+    if (pcVPS->getVpsNuhLayerIdPresentFlag() )
+      WRITE_CODE( pcVPS->getLayerIdInNuh( layer ), 6,          "layer_id_in_nuh[i]");
+    for( Int sIdx = 0; sIdx < pcVPS->getNumScalabilityTypes() ; sIdx++ )
+    {      
+      WRITE_CODE( pcVPS->getDimensionId( layer, sIdx ), pcVPS->getDimensionIdLen( sIdx ), "dimension_id[i][j]");      
+    }
+  }
+
+  for( Int layerSet = 1; layerSet <= pcVPS->getMaxOpSets() - 1; layerSet++ )
+  {
+    WRITE_FLAG( pcVPS->getVpsProfilePresentFlag( layerSet ) ? 1 : 0, "vps_profile_present_flag[lsIdx]" );
+    if( pcVPS->getVpsProfilePresentFlag( layerSet ) == false )
+    {
+      WRITE_UVLC( pcVPS->getProfileLayerSetRefMinus1( layerSet ), "profile_layer_set_ref_minus1[lsIdx]" );
+    }
+    codePTL( pcVPS->getPTL( layerSet ), pcVPS->getVpsProfilePresentFlag( layerSet ), pcVPS->getMaxTLayers() - 1 );
+  }
+
+  WRITE_UVLC( pcVPS->getNumOutputLayerSets(),                "num_output_layer_sets" );
+
+  for( Int layerSet = 0; layerSet < pcVPS->getNumOutputLayerSets(); layerSet++ )
+  {
+    WRITE_UVLC( pcVPS->getOutputLayerSetIdx( layerSet ),      "output_layer_set_idx[i]" );
+    for( Int layer = 0; layer <= pcVPS->getMaxNuhLayerId(); layer++ )
+    {
+      if( pcVPS->getLayerIdIncludedFlag( pcVPS->getOutputLayerSetIdx( layerSet ), layer ) == true )
+      {
+        WRITE_FLAG( pcVPS->getOutputLayerFlag( layerSet, layer ) ? 1 : 0, "output_layer_flag" );
+      }
+    }
+  }
+
+  for( Int i = 1; i <= pcVPS->getMaxLayers() - 1; i++ )
+  {
+    for( Int j = 0; j < i; j++ )
+    {
+      WRITE_FLAG( pcVPS->getDirectDependencyFlag( i, j ),    "direct_dependency_flag[i][j]" );
+    }
+  }
+  WRITE_FLAG( 0,                                             "vps_extension2_flag" );
+#else
   WRITE_FLAG( 0,                     "vps_extension_flag" );
+#endif
   
   //future extensions here..
@@ -1004,8 +1091,12 @@
   for (Int i = 0; i < maxNumSubLayersMinus1; i++)
   {
+#if !H_MV
     if(profilePresentFlag)
     {
+#endif
       WRITE_FLAG( pcPTL->getSubLayerProfilePresentFlag(i), "sub_layer_profile_present_flag[i]" );
-    }
+#if !H_MV
+    }
+#endif
     
     WRITE_FLAG( pcPTL->getSubLayerLevelPresentFlag(i),   "sub_layer_level_present_flag[i]" );
Index: branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/TEncCfg.h	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/TEncCfg.h	(revision 368)
@@ -69,4 +69,9 @@
   Int m_numRefIdc;
   Int m_refIdc[MAX_NUM_REF_PICS+1];
+#if H_MV
+  Int m_numInterViewRefPics;
+  Int m_interViewRefs    [MAX_NUM_REF_PICS];
+  Int m_interViewRefPosL[2][MAX_NUM_REF_PICS];  
+#endif
   GOPEntry()
   : m_POC(-1)
@@ -83,8 +88,15 @@
   , m_deltaRPS(0)
   , m_numRefIdc(0)
+#if H_MV
+  , m_numInterViewRefPics(0)
+#endif
   {
     ::memset( m_referencePics, 0, sizeof(m_referencePics) );
     ::memset( m_usedByCurrPic, 0, sizeof(m_usedByCurrPic) );
     ::memset( m_refIdc,        0, sizeof(m_refIdc) );
+#if H_MV
+    ::memset( m_interViewRefs,   0, sizeof(m_interViewRefs) );
+    ::memset( m_interViewRefPosL[0], -1, sizeof(m_interViewRefPosL[0]) );    ::memset( m_interViewRefPosL[1], -1, sizeof(m_interViewRefPosL[1]) );
+#endif
   }
 };
@@ -127,5 +139,9 @@
   UInt      m_uiDecodingRefreshType;            ///< the type of decoding refresh employed for the random access.
   Int       m_iGOPSize;
+#if H_MV
+  GOPEntry  m_GOPList[MAX_GOP+1];
+#else
   GOPEntry  m_GOPList[MAX_GOP];
+#endif
   Int       m_extraRPSs;
   Int       m_maxDecPicBuffering[MAX_TLAYER];
@@ -337,8 +353,24 @@
   Bool      m_useStrongIntraSmoothing;                        ///< enable the use of strong intra smoothing (bi_linear interpolation) for 32x32 blocks when reference samples are flat.
 
+#if H_MV
+  Int       m_layerId;
+  Int       m_layerIdInVps;
+  Int       m_viewId;
+#if H_3D
+  Bool      m_isDepth;
+#endif
+#endif
 public:
   TEncCfg()
   : m_puiColumnWidth()
   , m_puiRowHeight()
+#if H_MV
+  , m_layerId(-1)
+  , m_layerIdInVps(-1)
+  , m_viewId(-1)
+#if H_3D
+  , m_isDepth(false)
+#endif
+#endif
   {}
 
@@ -362,9 +394,25 @@
   Void      setFramesToBeEncoded            ( Int   i )      { m_framesToBeEncoded = i; }
   
+#if H_MV
+  Void      setLayerId                       ( Int layerId )      { m_layerId = layerId; }
+  Int       getLayerId                       ()                   { return m_layerId;    }
+  Int       getLayerIdInVps                  ()                   { return m_layerIdInVps; }
+  Void      setLayerIdInVps                  ( Int layerIdInVps)  { m_layerIdInVps = layerIdInVps; }
+  Void      setViewId                        ( Int viewId  )      { m_viewId  = viewId;  }
+  Int       getViewId                        ()                   { return m_viewId;    }
+#if H_3D
+  Void      setIsDepth                       ( Bool isDepth )   { m_isDepth = isDepth; }
+  Bool      getIsDepth                       ()                 { return m_isDepth; }
+#endif
+#endif
   //====== Coding Structure ========
   Void      setIntraPeriod                  ( Int   i )      { m_uiIntraPeriod = (UInt)i; }
   Void      setDecodingRefreshType          ( Int   i )      { m_uiDecodingRefreshType = (UInt)i; }
   Void      setGOPSize                      ( Int   i )      { m_iGOPSize = i; }
+#if H_MV
+  Void      setGopList                      ( GOPEntry*  GOPList ) {  for ( Int i = 0; i < MAX_GOP+1; i++ ) m_GOPList[i] = GOPList[i]; }
+#else
   Void      setGopList                      ( GOPEntry*  GOPList ) {  for ( Int i = 0; i < MAX_GOP; i++ ) m_GOPList[i] = GOPList[i]; }
+#endif
   Void      setExtraRPSs                    ( Int   i )      { m_extraRPSs = i; }
   GOPEntry  getGOPEntry                     ( Int   i )      { return m_GOPList[i]; }
Index: branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 368)
@@ -100,4 +100,12 @@
 #endif
 #endif
+#if H_MV
+  m_layerId      = 0;
+  m_viewId       = 0;
+  m_pocLastCoded = -1; 
+#if H_3D
+  m_isDepth = false;
+#endif
+#endif
   return;
 }
@@ -139,4 +147,12 @@
   m_totalCoded         = 0;
 
+#if H_MV
+  m_ivPicLists           = pcTEncTop->getIvPicLists(); 
+  m_layerId              = pcTEncTop->getLayerId();
+  m_viewId               = pcTEncTop->getViewId();
+#if H_3D
+  m_isDepth              = pcTEncTop->getIsDepth();
+#endif
+#endif
 }
 
@@ -342,5 +358,16 @@
 // Public member functions
 // ====================================================================================================================
+#if H_MV
+Void TEncGOP::initGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP)
+{
+  xInitGOP( iPOCLast, iNumPicRcvd, rcListPic, rcListPicYuvRecOut );
+  m_iNumPicCoded = 0;
+}
+#endif
+#if H_MV
+Void TEncGOP::compressPicInGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, Int iGOPid)
+#else
 Void TEncGOP::compressGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP)
+#endif
 {
   TComPic*        pcPic;
@@ -354,7 +381,9 @@
   TComOutputBitstream* pcSubstreamsOut = NULL;
 
+#if !H_MV
   xInitGOP( iPOCLast, iNumPicRcvd, rcListPic, rcListPicYuvRecOut );
   
   m_iNumPicCoded = 0;
+#endif
   SEIPictureTiming pictureTimingSEI;
 #if L0208_SOP_DESCRIPTION_SEI
@@ -379,5 +408,7 @@
   UInt *accumNalsDU = NULL;
   SEIDecodingUnitInfo decodingUnitInfoSEI;
+#if !H_MV
   for ( Int iGOPid=0; iGOPid < m_iGopSize; iGOPid++ )
+#endif
   {
     UInt uiColDir = 1;
@@ -438,5 +469,10 @@
     if(pocCurr>=m_pcCfg->getFramesToBeEncoded())
     {
+#if H_MV
+      delete pcBitstreamRedirect;
+      return;
+#else
       continue;
+#endif
     }
 
@@ -459,4 +495,15 @@
     pcSlice->setLastIDR(m_iLastIDR);
     pcSlice->setSliceIdx(0);
+#if H_MV
+    pcPic  ->setLayerId     ( getLayerId() );
+    pcPic  ->setViewId      ( getViewId()  );
+    pcSlice->setLayerId     ( getLayerId() );
+    pcSlice->setViewId      ( getViewId()  );
+    pcSlice->setVPS         ( m_pcEncTop->getVPS() );
+#if H_3D
+    pcPic  ->setIsDepth( getIsDepth() );
+    pcSlice->setIsDepth( getIsDepth() );
+#endif
+#endif
     //set default slice level flag to the same as SPS level flag
     pcSlice->setLFCrossSliceBoundaryFlag(  pcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()  );
@@ -496,10 +543,22 @@
     }
 
-    if(pcSlice->getSliceType()==B_SLICE&&m_pcCfg->getGOPEntry(iGOPid).m_sliceType=='P')
-    {
-      pcSlice->setSliceType(P_SLICE);
-    }
+#if H_MV
     // Set the nal unit type
     pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR));
+    if( pcSlice->getSliceType() == B_SLICE )
+    {
+      if( m_pcCfg->getGOPEntry( ( pcSlice->getRapPicFlag() && getLayerId() > 0 ) ? MAX_GOP : iGOPid ).m_sliceType == 'P' ) 
+      { 
+        pcSlice->setSliceType( P_SLICE );
+      }
+    }
+#else
+    if(pcSlice->getSliceType()==B_SLICE&&m_pcCfg->getGOPEntry(iGOPid).m_sliceType=='P')
+    {
+      pcSlice->setSliceType(P_SLICE);
+    }
+    // Set the nal unit type
+    pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR));
+#endif
     if(pcSlice->getTemporalLayerNonReferenceFlag())
     {
@@ -589,6 +648,13 @@
     refPicListModification->setRefPicListModificationFlagL0(0);
     refPicListModification->setRefPicListModificationFlagL1(0);
+#if H_MV
+    pcSlice->createAndApplyIvReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer ); 
+    pcSlice->setNumRefIdx(REF_PIC_LIST_0,min(m_pcCfg->getGOPEntry( (pcSlice->getRapPicFlag() && getLayerId() > 0) ? MAX_GOP : iGOPid ).m_numRefPicsActive,( pcSlice->getRPS()->getNumberOfPictures() + (Int) m_refPicSetInterLayer.size() ) ) );
+    pcSlice->setNumRefIdx(REF_PIC_LIST_1,min(m_pcCfg->getGOPEntry( (pcSlice->getRapPicFlag() && getLayerId() > 0) ? MAX_GOP : iGOPid ).m_numRefPicsActive,( pcSlice->getRPS()->getNumberOfPictures() + (Int) m_refPicSetInterLayer.size() ) ) );
+    xSetRefPicListModificationsMvc( pcSlice, pocCurr, iGOPid );    
+#else
     pcSlice->setNumRefIdx(REF_PIC_LIST_0,min(m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive,pcSlice->getRPS()->getNumberOfPictures()));
     pcSlice->setNumRefIdx(REF_PIC_LIST_1,min(m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive,pcSlice->getRPS()->getNumberOfPictures()));
+#endif
 
 #if ADAPTIVE_QP_SELECTION
@@ -597,11 +663,25 @@
 
     //  Set reference list
+#if H_MV    
+    pcSlice->setRefPicList( rcListPic, m_refPicSetInterLayer );
+#else
     pcSlice->setRefPicList ( rcListPic );
+#endif
 
     //  Slice info. refinement
+#if H_MV
+    if ( pcSlice->getSliceType() == B_SLICE )
+    {
+      if( m_pcCfg->getGOPEntry( ( pcSlice->getRapPicFlag() == true && getLayerId() > 0 ) ? MAX_GOP : iGOPid ).m_sliceType == 'P' ) 
+      { 
+        pcSlice->setSliceType( P_SLICE ); 
+      }
+    }
+#else
     if ( (pcSlice->getSliceType() == B_SLICE) && (pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0) )
     {
       pcSlice->setSliceType ( P_SLICE );
     }
+#endif
 #if !L0034_COMBINED_LIST_CLEANUP
     if (pcSlice->getSliceType() != B_SLICE || !pcSlice->getSPS()->getUseLComb())
@@ -1020,4 +1100,8 @@
     {
       OutputNALUnit nalu(NAL_UNIT_VPS);
+#if H_MV
+      if( getLayerId() == 0 )
+      {
+#endif
       m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
       m_pcEntropyCoder->encodeVPS(m_pcEncTop->getVPS());
@@ -1028,5 +1112,10 @@
 #endif
 
+#if H_MV
+      }
+      nalu = NALUnit(NAL_UNIT_SPS, 0, getLayerId());
+#else
       nalu = NALUnit(NAL_UNIT_SPS);
+#endif
       m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
       if (m_bSeqFirst)
@@ -1061,5 +1150,9 @@
 #endif
 
+#if H_MV
+      nalu = NALUnit(NAL_UNIT_PPS, 0, getLayerId());
+#else
       nalu = NALUnit(NAL_UNIT_PPS);
+#endif
       m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
       m_pcEntropyCoder->encodePPS(pcSlice->getPPS());
@@ -1383,5 +1476,9 @@
           m_pcEntropyCoder->resetEntropy      ();
           /* start slice NALunit */
+#if H_MV
+          OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->getTLayer(), getLayerId() );
+#else
           OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->getTLayer() );
+#endif
           Bool sliceSegment = (!pcSlice->isNextSlice());
           if (!sliceSegment)
@@ -1610,5 +1707,10 @@
       }
 
+#if !H_3D
       pcPic->compressMotion(); 
+#endif
+#if H_MV
+      m_pocLastCoded = pcPic->getPOC();
+#endif
       //-- For time output for each slice
       Double dEncTime = (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC;
@@ -1921,4 +2023,9 @@
 
       pcPic->setReconMark   ( true );
+#if H_MV
+      TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer );  
+      std::vector<Int> temp; 
+      TComSlice::markIvRefPicsAsUnused   ( m_ivPicLists, temp, pcPic->getSlice(0)->getVPS(), m_layerId, pcPic->getPOC() ); 
+#endif
       m_bFirst = false;
       m_iNumPicCoded++;
@@ -1941,7 +2048,10 @@
   if( accumNalsDU != NULL) delete accumNalsDU;
 
+#if !H_MV
   assert ( m_iNumPicCoded == iNumPicRcvd );
+#endif
 }
 
+#if !H_MV
 Void TEncGOP::printOutSummary(UInt uiNumAllPicCoded)
 {
@@ -1979,4 +2089,5 @@
   printf("\nRVM: %.3lf\n" , xCalculateRVM());
 }
+#endif
 
 Void TEncGOP::preLoopFilterPicAll( TComPic* pcPic, UInt64& ruiDist, UInt64& ruiBits )
@@ -2254,17 +2365,33 @@
 
   //===== add PSNR =====
+#if H_MV
+  m_pcEncTop->getAnalyzeAll()->addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
+#else
   m_gcAnalyzeAll.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
+#endif
   TComSlice*  pcSlice = pcPic->getSlice(0);
   if (pcSlice->isIntra())
   {
+#if H_MV
+    m_pcEncTop->getAnalyzeI()->addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
+#else
     m_gcAnalyzeI.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
+#endif
   }
   if (pcSlice->isInterP())
   {
+#if H_MV
+    m_pcEncTop->getAnalyzeP()->addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
+#else
     m_gcAnalyzeP.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
+#endif
   }
   if (pcSlice->isInterB())
   {
+#if H_MV
+    m_pcEncTop->getAnalyzeB()->addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
+#else
     m_gcAnalyzeB.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits);
+#endif
   }
 
@@ -2273,4 +2400,14 @@
 
 #if ADAPTIVE_QP_SELECTION
+#if H_MV
+  printf("Layer %3d   POC %4d TId: %1d ( %c-SLICE, nQP %d QP %d ) %10d bits",
+    pcSlice->getLayerId(),
+    pcSlice->getPOC(),
+    pcSlice->getTLayer(),
+    c,
+    pcSlice->getSliceQpBase(),
+    pcSlice->getSliceQp(),
+    uibits );
+#else
   printf("POC %4d TId: %1d ( %c-SLICE, nQP %d QP %d ) %10d bits",
          pcSlice->getPOC(),
@@ -2280,4 +2417,14 @@
          pcSlice->getSliceQp(),
          uibits );
+#endif
+#else
+#if H_MV
+  printf("Layer %3d   POC %4d TId: %1d ( %c-SLICE, QP %d ) %10d bits",
+    pcSlice->getLayerId(),
+    pcSlice->getPOC()-pcSlice->getLastIDR(),
+    pcSlice->getTLayer(),
+    c,
+    pcSlice->getSliceQp(),
+    uibits );
 #else
   printf("POC %4d TId: %1d ( %c-SLICE, QP %d ) %10d bits",
@@ -2287,4 +2434,5 @@
          pcSlice->getSliceQp(),
          uibits );
+#endif
 
 #endif
@@ -2297,5 +2445,16 @@
     for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++)
     {
+#if H_MV
+      if( pcSlice->getLayerId() != pcSlice->getRefLayerId( RefPicList(iRefList), iRefIndex ) )
+      {
+        printf( "V%d ", pcSlice->getRefLayerId( RefPicList(iRefList), iRefIndex ) );
+      }
+      else
+      {
+#endif
       printf ("%d ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR());
+#if H_MV
+      }
+#endif
     }
     printf("]");
@@ -2663,3 +2822,82 @@
 }
 #endif
+#if H_MV
+Void TEncGOP::xSetRefPicListModificationsMvc( TComSlice* pcSlice, UInt uiPOCCurr, UInt iGOPid )
+{ 
+  TComVPS* vps = pcSlice->getVPS(); 
+  Int layer    = pcSlice->getLayerIdInVps( ); 
+  
+  if( pcSlice->getSliceType() == I_SLICE || !(pcSlice->getPPS()->getListsModificationPresentFlag()) || vps->getNumDirectRefLayers( layer ) == 0 )
+  {
+    return;
+  }
+
+  // analyze inter-view modifications
+  GOPEntry ge = m_pcCfg->getGOPEntry( (pcSlice->getRapPicFlag() && ( layer > 0) ) ? MAX_GOP : iGOPid );
+
+  TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification();
+  
+  Int maxRefListSize  = pcSlice->getNumRpsCurrTempList();
+  Int numTemporalRefs = maxRefListSize - vps->getNumDirectRefLayers( layer );
+
+
+  for (Int li = 0; li < 2; li ++) // Loop over lists L0 and L1
+  {
+    Int numModifications = 0;
+    
+    for( Int k = 0; k < ge.m_numInterViewRefPics; k++ ) 
+    {
+      numModifications +=  ( ge.m_interViewRefPosL[li][k] >= 0 ) ? 1 : 0; 
+    }
+
+    // set inter-view modifications
+    if( (maxRefListSize > 1) && (numModifications > 0) )
+    {
+      refPicListModification->setRefPicListModificationFlagL( li, true );
+      Int tempList[16];
+      for( Int k = 0; k < 16; k++ ) { tempList[k] = -1; }
+
+      Bool isModified = false;
+      for( Int k = 0; k < ge.m_numInterViewRefPics; k++ )
+      {
+        if( ge.m_interViewRefPosL[li][k] >= 0 )
+        {
+          Int orgIdx    = numTemporalRefs;
+          Int targetIdx = ge.m_interViewRefPosL[ li ][ k ];
+          for( Int idx = 0; idx < vps->getNumDirectRefLayers( layer ); idx++ )
+          {            
+            Int refLayer  = vps->getLayerIdInVps( vps->getRefLayerId( layer, idx ) );          
+            if( ( layer + ge.m_interViewRefs[ k ]) == refLayer )
+            {
+              tempList[ targetIdx ] = orgIdx;              
+              isModified = ( targetIdx != orgIdx  );
+            }
+            orgIdx++;
+          }
+        }
+      }
+      if( isModified )
+      {
+        Int temporalRefIdx = 0;
+        for( Int i = 0; i < pcSlice->getNumRefIdx( ( li == 0 ) ? REF_PIC_LIST_0 : REF_PIC_LIST_1 ); i++ )
+        {
+          if( tempList[i] >= 0 ) 
+          {
+            refPicListModification->setRefPicSetIdxL( li, i, tempList[i] );
+          }
+          else
+          {
+            refPicListModification->setRefPicSetIdxL( li, i, temporalRefIdx );
+            temporalRefIdx++;
+          }
+        }
+      }
+      else
+      {
+        refPicListModification->setRefPicListModificationFlagL( li, false );
+      }
+    }
+  }
+}
+#endif
 //! \}
Index: branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/TEncGOP.h
===================================================================
--- branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/TEncGOP.h	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/TEncGOP.h	(revision 368)
@@ -97,4 +97,15 @@
   SEIWriter               m_seiWriter;
   
+#if H_MV
+  TComPicLists*           m_ivPicLists;
+  std::vector<TComPic*>   m_refPicSetInterLayer; 
+
+  Int                     m_pocLastCoded;
+  Int                     m_layerId;  
+  Int                     m_viewId;
+#if H_3D
+  Bool                    m_isDepth;
+#endif
+#endif
   //--Adaptive Loop filter
   TEncSampleAdaptiveOffset*  m_pcSAO;
@@ -133,7 +144,20 @@
   
   Void  init        ( TEncTop* pcTEncTop );
+#if H_MV
+  Void  initGOP     ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP);
+  Void  compressPicInGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, Int iGOPid );
+#else
   Void  compressGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, std::list<AccessUnit>& accessUnitsInGOP );
+#endif
   Void  xAttachSliceDataToNalUnit (OutputNALUnit& rNalu, TComOutputBitstream*& rpcBitstreamRedirect);
 
+#if H_MV
+  Int       getPocLastCoded  ()                 { return m_pocLastCoded; }  
+  Int       getLayerId       ()                 { return m_layerId;    }  
+  Int       getViewId        ()                 { return m_viewId;    }
+#if H_3D
+  Bool      getIsDepth       ()                 { return m_isDepth; }
+#endif
+#endif
 
   Int   getGOPSize()          { return  m_iGopSize;  }
@@ -141,5 +165,7 @@
   TComList<TComPic*>*   getListPic()      { return m_pcListPic; }
   
+#if !H_MV
   Void  printOutSummary      ( UInt uiNumAllPicCoded );
+#endif
   Void  preLoopFilterPicAll  ( TComPic* pcPic, UInt64& ruiDist, UInt64& ruiBits );
   
@@ -185,4 +211,7 @@
 #endif
 #endif
+#if H_MV
+   Void  xSetRefPicListModificationsMvc( TComSlice* pcSlice, UInt uiPOCCurr, UInt iGOPid );
+#endif
 #if L0386_DB_METRIC
   Void dblMetric( TComPic* pcPic, UInt uiNumSlices );
Index: branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 368)
@@ -219,4 +219,20 @@
   
   // slice type
+#if H_MV
+  SliceType eSliceTypeBaseView;
+  if( pocLast == 0 || pocCurr % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0 )
+  {
+    eSliceTypeBaseView = I_SLICE;
+  }
+  else
+  {
+    eSliceTypeBaseView = B_SLICE;
+  }
+  SliceType eSliceType = eSliceTypeBaseView;
+  if( eSliceTypeBaseView == I_SLICE && m_pcCfg->getGOPEntry(MAX_GOP).m_POC == 0 && m_pcCfg->getGOPEntry(MAX_GOP).m_sliceType != 'I' )
+  {
+    eSliceType = B_SLICE; 
+  }
+#else
   SliceType eSliceType;
   
@@ -225,4 +241,5 @@
   
   rpcSlice->setSliceType    ( eSliceType );
+#endif
 
   // ------------------------------------------------------------------------------------------------------------------
@@ -253,5 +270,9 @@
     if (!(( m_pcCfg->getMaxDeltaQP() == 0 ) && (dQP == -rpcSlice->getSPS()->getQpBDOffsetY() ) && (rpcSlice->getSPS()->getUseLossless()))) 
     {
+#if H_MV
+      dQP += m_pcCfg->getGOPEntry( (eSliceTypeBaseView == I_SLICE) ? MAX_GOP : iGOPid ).m_QPOffset;
+#else
       dQP += m_pcCfg->getGOPEntry(iGOPid).m_QPOffset;
+#endif
     }
   }
@@ -296,6 +317,15 @@
 #endif
     // Case #1: I or P-slices (key-frame)
+#if H_MV
+    Double dQPFactor;
+    if( eSliceType != I_SLICE ) 
+    {
+      dQPFactor = m_pcCfg->getGOPEntry( (eSliceTypeBaseView == I_SLICE) ? MAX_GOP : iGOPid ).m_QPFactor;
+    }
+    else
+#else
     Double dQPFactor = m_pcCfg->getGOPEntry(iGOPid).m_QPFactor;
     if ( eSliceType==I_SLICE )
+#endif
     {
       dQPFactor=0.57*dLambda_scale;
@@ -332,5 +362,9 @@
   if( rpcSlice->getSliceType( ) != I_SLICE )
   {
+#if H_MV
+    dLambda *= m_pcCfg->getLambdaModifier( m_pcCfg->getGOPEntry((eSliceTypeBaseView == I_SLICE) ? MAX_GOP : iGOPid).m_temporalId );
+#else
     dLambda *= m_pcCfg->getLambdaModifier( m_pcCfg->getGOPEntry(iGOPid).m_temporalId );
+#endif
   }
 
@@ -371,5 +405,13 @@
 #if HB_LAMBDA_FOR_LDC
   // restore original slice type
+#if H_MV
+  eSliceType = eSliceTypeBaseView;
+  if( eSliceTypeBaseView == I_SLICE && m_pcCfg->getGOPEntry(MAX_GOP).m_POC == 0 && m_pcCfg->getGOPEntry(MAX_GOP).m_sliceType != 'I' )
+  {
+    eSliceType = B_SLICE;
+  }
+#else
   eSliceType = (pocLast == 0 || pocCurr % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
+#endif
 
   rpcSlice->setSliceType        ( eSliceType );
@@ -389,6 +431,11 @@
   rpcSlice->setSliceQpDeltaCb   ( 0 );
   rpcSlice->setSliceQpDeltaCr   ( 0 );
+#if H_MV
+  rpcSlice->setNumRefIdx(REF_PIC_LIST_0,m_pcCfg->getGOPEntry( (eSliceTypeBaseView == I_SLICE) ? MAX_GOP : iGOPid ).m_numRefPicsActive);
+  rpcSlice->setNumRefIdx(REF_PIC_LIST_1,m_pcCfg->getGOPEntry( (eSliceTypeBaseView == I_SLICE) ? MAX_GOP : iGOPid ).m_numRefPicsActive);
+#else
   rpcSlice->setNumRefIdx(REF_PIC_LIST_0,m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive);
   rpcSlice->setNumRefIdx(REF_PIC_LIST_1,m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive);
+#endif
 
 #if L0386_DB_METRIC
@@ -411,8 +458,15 @@
       if ( !m_pcCfg->getLoopFilterOffsetInPPS() && eSliceType!=I_SLICE)
       {
+#if H_MV
+        rpcSlice->getPPS()->setDeblockingFilterBetaOffsetDiv2( m_pcCfg->getGOPEntry((eSliceTypeBaseView == I_SLICE) ? MAX_GOP : iGOPid).m_betaOffsetDiv2 + m_pcCfg->getLoopFilterBetaOffset() );
+        rpcSlice->getPPS()->setDeblockingFilterTcOffsetDiv2( m_pcCfg->getGOPEntry((eSliceTypeBaseView == I_SLICE) ? MAX_GOP : iGOPid).m_tcOffsetDiv2 + m_pcCfg->getLoopFilterTcOffset() );
+        rpcSlice->setDeblockingFilterBetaOffsetDiv2( m_pcCfg->getGOPEntry((eSliceTypeBaseView == I_SLICE) ? MAX_GOP : iGOPid).m_betaOffsetDiv2 + m_pcCfg->getLoopFilterBetaOffset()  );
+        rpcSlice->setDeblockingFilterTcOffsetDiv2( m_pcCfg->getGOPEntry((eSliceTypeBaseView == I_SLICE) ? MAX_GOP : iGOPid).m_tcOffsetDiv2 + m_pcCfg->getLoopFilterTcOffset() );
+#else
         rpcSlice->getPPS()->setDeblockingFilterBetaOffsetDiv2( m_pcCfg->getGOPEntry(iGOPid).m_betaOffsetDiv2 + m_pcCfg->getLoopFilterBetaOffset() );
         rpcSlice->getPPS()->setDeblockingFilterTcOffsetDiv2( m_pcCfg->getGOPEntry(iGOPid).m_tcOffsetDiv2 + m_pcCfg->getLoopFilterTcOffset() );
         rpcSlice->setDeblockingFilterBetaOffsetDiv2( m_pcCfg->getGOPEntry(iGOPid).m_betaOffsetDiv2 + m_pcCfg->getLoopFilterBetaOffset()  );
         rpcSlice->setDeblockingFilterTcOffsetDiv2( m_pcCfg->getGOPEntry(iGOPid).m_tcOffsetDiv2 + m_pcCfg->getLoopFilterTcOffset() );
+#endif
       }
       else
@@ -435,5 +489,9 @@
   rpcSlice->setDepth            ( depth );
   
+#if H_MV
+  pcPic->setTLayer( m_pcCfg->getGOPEntry( (eSliceTypeBaseView == I_SLICE) ? MAX_GOP : iGOPid ).m_temporalId );
+#else
   pcPic->setTLayer( m_pcCfg->getGOPEntry(iGOPid).m_temporalId );
+#endif
   if(eSliceType==I_SLICE)
   {
Index: branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/TEncTop.cpp	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/TEncTop.cpp	(revision 368)
@@ -42,4 +42,7 @@
 #include "TLibCommon/ContextModel.h"
 #endif
+#if H_MV
+#include "../../App/TAppEncoder/TAppEncTop.h"
+#endif
 
 //! \ingroup TLibEncoder
@@ -78,4 +81,7 @@
   m_pcBitCounters          = NULL;
   m_pcRdCosts              = NULL;
+#if H_MV
+  m_ivPicLists = NULL;
+#endif
 }
 
@@ -89,6 +95,8 @@
 Void TEncTop::create ()
 {
+#if !H_MV
   // initialize global variables
   initROM();
+#endif
   
   // create processing unit classes
@@ -268,6 +276,8 @@
   delete[] m_pcRdCosts;
   
+#if !H_MV
     // destroy ROM
   destroyROM();
+#endif
 
   return;
@@ -319,4 +329,20 @@
 // ====================================================================================================================
 
+#if H_MV
+Void TEncTop::initNewPic( TComPicYuv* pcPicYuvOrg )
+{
+  TComPic* pcPicCurr = NULL;
+
+  // get original YUV
+  xGetNewPicBuffer( pcPicCurr );
+  pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() );
+
+  // compute image characteristics
+  if ( getUseAdaptiveQP() )
+  {
+    m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) );
+  }
+}
+#endif
 Void TEncTop::deletePicBuffer()
 {
@@ -345,6 +371,23 @@
  \retval  iNumEncoded         number of encoded pictures
  */
+#if H_MV
+Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded , Int gopId )
+{
+#else
 Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded )
 {
+#endif
+#if H_3D
+  TComPic* picLastCoded = getPic( getGOPEncoder()->getPocLastCoded() );
+  if( picLastCoded )
+  {
+    picLastCoded->compressMotion(); 
+  }
+#endif
+#if H_MV
+  if( gopId == 0)
+  {
+    m_cGOPEncoder.initGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut);  
+#else
   if (pcPicYuvOrg) {
     // get original YUV
@@ -365,4 +408,5 @@
     return;
   }
+#endif
   
 #if RATE_CONTROL_LAMBDA_DOMAIN
@@ -373,6 +417,14 @@
 #endif
 
+#if H_MV
+  }
+  m_cGOPEncoder.compressPicInGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, gopId );
+
+  if( gopId + 1 == m_cGOPEncoder.getGOPSize() )
+  {
+#else
   // compress GOP
   m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut);
+#endif
 
 #if RATE_CONTROL_LAMBDA_DOMAIN
@@ -386,4 +438,7 @@
   m_iNumPicRcvd       = 0;
   m_uiNumAllPicCoded += iNumEncoded;
+#if H_MV
+}
+#endif
 }
 
@@ -450,4 +505,7 @@
 Void TEncTop::xInitSPS()
 {
+#if H_MV
+  m_cSPS.setSPSId( getLayerIdInVps() );
+#endif
   ProfileTierLevel& profileTierLevel = *m_cSPS.getPTL()->getGeneralPTL();
   profileTierLevel.setLevelIdc(m_level);
@@ -594,4 +652,12 @@
 Void TEncTop::xInitPPS()
 {
+#if H_MV
+  if( m_cVPS.getNumDirectRefLayers( getLayerIdInVps() ) > 0 )
+  {
+    m_cPPS.setListsModificationPresentFlag( true );
+  }
+  m_cPPS.setPPSId( getLayerIdInVps() );
+  m_cPPS.setSPSId( getLayerIdInVps() );
+#endif
   m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred );
   Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false;
@@ -897,4 +963,17 @@
 Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid )
 {
+#if H_MV
+  if( slice->getRapPicFlag() == true && getLayerId() > 0 && POCCurr == 0 )
+  {
+    TComReferencePictureSet* rps = slice->getLocalRPS();
+    rps->setNumberOfNegativePictures(0);
+    rps->setNumberOfPositivePictures(0);
+    rps->setNumberOfLongtermPictures(0);
+    rps->setNumberOfPictures(0);
+    slice->setRPS(rps);
+  }
+  else
+  {
+#endif
   slice->setRPSidx(GOPid);
 
@@ -924,4 +1003,7 @@
   slice->setRPS(getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx()));
   slice->getRPS()->setNumberOfPictures(slice->getRPS()->getNumberOfNegativePictures()+slice->getRPS()->getNumberOfPositivePictures());
+#if H_MV
+  }
+#endif
 
 }
@@ -1038,3 +1120,65 @@
   }
 }
+#if H_MV
+Void TEncTop::printSummary( Int numAllPicCoded )
+{
+  assert (numAllPicCoded == m_cAnalyzeAll.getNumPic());
+
+  //--CFG_KDY
+  m_cAnalyzeAll.setFrmRate( getFrameRate() );
+  m_cAnalyzeI.setFrmRate( getFrameRate() );
+  m_cAnalyzeP.setFrmRate( getFrameRate() );
+  m_cAnalyzeB.setFrmRate( getFrameRate() );
+
+  //-- all
+  printf( "\n\nSUMMARY ------------------------------------------- LayerId %2d\n", m_layerId );
+
+  m_cAnalyzeAll.printOut('a');
+
+  printf( "\n\nI Slices--------------------------------------------------------\n" );
+  m_cAnalyzeI.printOut('i');
+
+  printf( "\n\nP Slices--------------------------------------------------------\n" );
+  m_cAnalyzeP.printOut('p');
+
+  printf( "\n\nB Slices--------------------------------------------------------\n" );
+  m_cAnalyzeB.printOut('b');
+
+#if _SUMMARY_OUT_
+  m_cAnalyzeAll.printSummaryOut();
+#endif
+#if _SUMMARY_PIC_
+  m_cAnalyzeI.printSummary('I');
+  m_cAnalyzeP.printSummary('P');
+  m_cAnalyzeB.printSummary('B');
+#endif
+}
+
+Int TEncTop::getFrameId(Int iGOPid)  
+{
+  if(m_iPOCLast == 0)
+  {
+    return(0 );
+  }
+  else
+  {
+    return m_iPOCLast -m_iNumPicRcvd+ getGOPEntry(iGOPid).m_POC ;
+  }
+}
+
+TComPic* TEncTop::getPic( Int poc )
+{
+  TComList<TComPic*>* listPic = getListPic();
+  TComPic* pcPic = NULL;
+  for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++)
+  {
+    if( (*it)->getPOC() == poc )
+    {
+      pcPic = *it ;
+      break ;
+    }
+  }
+  return pcPic;
+}
+#endif
 //! \}
Index: branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/TEncTop.h
===================================================================
--- branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/TEncTop.h	(revision 367)
+++ branches/HTM-DEV-0.1-dev/source/Lib/TLibEncoder/TEncTop.h	(revision 368)
@@ -74,4 +74,7 @@
   TComList<TComPic*>      m_cListPic;                     ///< dynamic list of pictures
   
+#if H_MV
+  TComPicLists*           m_ivPicLists;                   ///< access to picture lists of other layers 
+#endif
   // encoder search
   TEncSearch              m_cSearch;                      ///< encoder search class
@@ -122,4 +125,10 @@
   TEncRateCtrl            m_cRateCtrl;                    ///< Rate control class
   
+#if H_MV
+  TEncAnalyze             m_cAnalyzeAll;
+  TEncAnalyze             m_cAnalyzeI;
+  TEncAnalyze             m_cAnalyzeP;
+  TEncAnalyze             m_cAnalyzeB;  
+#endif
 protected:
   Void  xGetNewPicBuffer  ( TComPic*& rpcPic );           ///< get picture buffer which will be processed
@@ -137,8 +146,14 @@
   Void      destroy         ();
   Void      init            ();
+#if H_MV  
+  TComPicLists* getIvPicLists() { return m_ivPicLists; }
+#endif
   Void      deletePicBuffer ();
 
   Void      createWPPCoders(Int iNumSubstreams);
   
+#if H_MV
+  Void      initNewPic(TComPicYuv* pcPicYuvOrg);
+#endif
   // -------------------------------------------------------------------------------------------------------------------
   // member access functions
@@ -177,4 +192,17 @@
 #endif
   TComScalingList*        getScalingList        () { return  &m_scalingList;         }
+#if H_MV
+  TEncAnalyze*            getAnalyzeAll         () { return &m_cAnalyzeAll; }
+  TEncAnalyze*            getAnalyzeI           () { return &m_cAnalyzeI;   }
+  TEncAnalyze*            getAnalyzeP           () { return &m_cAnalyzeP;   }
+  TEncAnalyze*            getAnalyzeB           () { return &m_cAnalyzeB;   }
+
+  Int                     getNumAllPicCoded     () { return m_uiNumAllPicCoded; }
+ 
+  Int                     getFrameId            (Int iGOPid);
+  
+  TComPic*                getPic                ( Int poc );
+  Void                    setIvPicLists         ( TComPicLists* picLists) { m_ivPicLists = picLists; }
+#endif
   // -------------------------------------------------------------------------------------------------------------------
   // encoder function
@@ -182,8 +210,16 @@
 
   /// encode several number of pictures until end-of-sequence
+#if H_MV
+  Void encode( Bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded  , Int gopId  );  
+#else
   Void encode( Bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut,
               std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded );  
-
+#endif
+
+#if H_MV
+  Void printSummary      ( Int numAllPicCoded ); 
+#else
   void printSummary() { m_cGOPEncoder.printOutSummary (m_uiNumAllPicCoded); }
+#endif
 };
 
