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 );
