Index: branches/HTM-8.0-dev0/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- branches/HTM-8.0-dev0/source/App/TAppDecoder/TAppDecTop.cpp	(revision 617)
+++ branches/HTM-8.0-dev0/source/App/TAppDecoder/TAppDecTop.cpp	(revision 618)
@@ -504,4 +504,8 @@
         const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
 #if H_MV
+#if H_MV5
+        assert( conf   .getScaledFlag() );
+        assert( defDisp.getScaledFlag() );
+#endif
         m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(),
 #else
@@ -577,4 +581,8 @@
         const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
 #if H_MV
+#if H_MV5
+        assert( conf   .getScaledFlag() );
+        assert( defDisp.getScaledFlag() );
+#endif
         m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(),
 #else
Index: branches/HTM-8.0-dev0/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- branches/HTM-8.0-dev0/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 617)
+++ branches/HTM-8.0-dev0/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 618)
@@ -224,8 +224,10 @@
     in>>entry.m_interViewRefPosL[1][i];
   }
+#if !H_MV5
   if (entry.m_numActiveRefLayerPics > 0 )
   {
     in>>entry.m_collocatedRefLayerIdx; 
   }
+#endif
 #endif
   return in;
@@ -367,10 +369,19 @@
   ("NumberOfLayers",        m_numberOfLayers     , 1,                     "Number of layers")
 #if !H_3D
+#if H_MV5
+  ("ScalabilityMask",       m_scalabilityMask    , 2                    , "Scalability Mask")    
+#else
   ("ScalabilityMask",       m_scalabilityMask    , 1                    , "Scalability Mask")    
+#endif
 #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")
+#if H_MV5
+  ("ViewOrderIndex",        m_viewOrderIndex     , std::vector<Int>(1,0), "View Order Index per layer")
+  ("ViewId",                m_viewId             , std::vector<Int>(1,0), "View Id per View Order Index")
+#else
   ("ViewId",                m_viewId             , std::vector<Int>(1,0), "View Id")
+#endif
 #if H_3D
   ("DepthFlag",             m_depthFlag          , std::vector<Int>(1,0), "Depth Flag")
@@ -587,4 +598,24 @@
   ("TargetBitrate,-tbr", m_targetBitrate, 0, "Input target bitrate")
   ("NumLCUInUnit,-nu", m_numLCUInUnit, 0, "Number of LCUs in an Unit")
+#endif
+
+#if H_MV5
+#if H_MV
+  // VPS VUI
+  ("VpsVuiPresentFlag"           , m_vpsVuiPresentFlag           , false                                           , "VpsVuiPresentFlag           ")
+  ("BitRatePresentVpsFlag"       , m_bitRatePresentVpsFlag       , false                                           , "BitRatePresentVpsFlag       ")
+  ("PicRatePresentVpsFlag"       , m_picRatePresentVpsFlag       , false                                           , "PicRatePresentVpsFlag       ")
+  ("BitRatePresentFlag"          , m_bitRatePresentFlag          , std::vector< Bool >(1,0)  ,MAX_VPS_OP_SETS_PLUS1, "BitRatePresentFlag per sub layer for the N-th layer set")
+  ("PicRatePresentFlag"          , m_picRatePresentFlag          , std::vector< Bool >(1,0)  ,MAX_VPS_OP_SETS_PLUS1, "PicRatePresentFlag per sub layer for the N-th layer set")
+  ("AvgBitRate"                  , m_avgBitRate                  , std::vector< Int  >(1,0)  ,MAX_VPS_OP_SETS_PLUS1, "AvgBitRate         per sub layer for the N-th layer set")
+  ("MaxBitRate"                  , m_maxBitRate                  , std::vector< Int  >(1,0)  ,MAX_VPS_OP_SETS_PLUS1, "MaxBitRate         per sub layer for the N-th layer set")
+  ("ConstantPicRateIdc"          , m_constantPicRateIdc          , std::vector< Int  >(1,0)  ,MAX_VPS_OP_SETS_PLUS1, "ConstantPicRateIdc per sub layer for the N-th layer set")
+  ("AvgPicRate"                  , m_avgPicRate                  , std::vector< Int  >(1,0)  ,MAX_VPS_OP_SETS_PLUS1, "AvgPicRate         per sub layer for the N-th layer set")
+  ("TileBoundariesAlignedFlag"   , m_tileBoundariesAlignedFlag   , std::vector< Bool >(1,0)  ,MAX_NUM_LAYERS       , "TileBoundariesAlignedFlag    per direct reference for the N-th layer")
+  ("IlpRestrictedRefLayersFlag"  , m_ilpRestrictedRefLayersFlag  , false                                           , "IlpRestrictedRefLayersFlag")
+  ("MinSpatialSegmentOffsetPlus1", m_minSpatialSegmentOffsetPlus1, std::vector< Int  >(1,0)  ,MAX_NUM_LAYERS       , "MinSpatialSegmentOffsetPlus1 per direct reference for the N-th layer")
+  ("CtuBasedOffsetEnabledFlag"   , m_ctuBasedOffsetEnabledFlag   , std::vector< Bool >(1,0)  ,MAX_NUM_LAYERS       , "CtuBasedOffsetEnabledFlag    per direct reference for the N-th layer")
+  ("MinHorizontalCtuOffsetPlus1" , m_minHorizontalCtuOffsetPlus1 , std::vector< Int  >(1,0)  ,MAX_NUM_LAYERS       , "MinHorizontalCtuOffsetPlus1  per direct reference for the N-th layer")
+#endif
 #endif
 
@@ -731,4 +762,7 @@
     if( k == 0 )
     {
+#if H_MV5
+      m_GOPListMvc[0][0].m_sliceType = 'I'; 
+#endif
       for( Int i = 1; i < MAX_GOP + 1; i++ ) 
       {
@@ -934,4 +968,26 @@
   // allocate slice-based dQP values
 #if H_MV
+#if H_MV5
+  xResizeVector( m_viewOrderIndex    ); 
+
+  std::vector<Int> uniqueViewOrderIndices; 
+  for( Int layer = 0; layer < m_numberOfLayers; layer++ )
+  {    
+    Bool isIn = false; 
+    for ( Int i = 0 ; i < uniqueViewOrderIndices.size(); i++ )
+    {
+      isIn = isIn || ( m_viewOrderIndex[ layer ] == uniqueViewOrderIndices[ i ] ); 
+    }
+    if ( !isIn ) 
+    {
+      uniqueViewOrderIndices.push_back( m_viewOrderIndex[ layer ] ); 
+    } 
+  }
+  m_iNumberOfViews = (Int) uniqueViewOrderIndices.size(); 
+
+#if H_3D
+  xResizeVector( m_depthFlag ); 
+#endif
+#else
   xResizeVector( m_viewId    ); 
 #if H_3D
@@ -954,4 +1010,5 @@
 #endif
 
+#endif
   xResizeVector( m_fQP ); 
 
@@ -1226,4 +1283,20 @@
   xConfirmPara( (m_layerIdInNuh.size()!=1) && (m_layerIdInNuh.size() < m_numberOfLayers) , "LayerIdInNuh must be given for all layers. ");
   
+#if H_MV5
+#if H_3D
+  xConfirmPara( m_scalabilityMask != 2 && m_scalabilityMask != 3, "Scalability Mask must be equal to 2 or 3. ");
+#else
+  xConfirmPara( m_scalabilityMask != 2 , "Scalability Mask must be equal to 2. ");
+#endif
+
+#if H_3D
+  if ( m_scalabilityMask & ( 1 << DEPTH_ID ) )
+  {
+    m_dimIds.push_back( m_depthFlag ); 
+  }
+#endif
+
+  m_dimIds.push_back( m_viewOrderIndex );   
+#else
 #if H_3D
   xConfirmPara( m_scalabilityMask != 1 && m_scalabilityMask != 3, "Scalability Mask must be equal to 1 or 3. ");
@@ -1239,4 +1312,5 @@
 #endif
 
+#endif
   xConfirmPara(  m_dimensionIdLen.size() < m_dimIds.size(), "DimensionIdLen must be given for all dimensions. "   );   Int dimBitOffset[MAX_NUM_SCALABILITY_TYPES+1]; 
 
@@ -1255,5 +1329,9 @@
   {    
     xConfirmPara( m_dimIds[j].size() < m_numberOfLayers,  "DimensionId must be given for all layers and all dimensions. ");   
+#if H_MV5   
+    xConfirmPara( (m_dimIds[j][0] != 0)                 , "DimensionId of layer 0 must be 0. " );
+#else
     xConfirmPara( ( j != viewDimPosition ) &&  (m_dimIds[j][0] != 0), "DimensionId of layer 0 must be 0. " );
+#endif
     xConfirmPara( m_dimensionIdLen[j] < 1 || m_dimensionIdLen[j] > 8, "DimensionIdLen must be greater than 0 and less than 9 in all dimensions. " ); 
      
@@ -1297,16 +1375,31 @@
      {
        Bool inc = m_dimIds[ lastDiff ][ i ] > m_dimIds[ lastDiff ][ j ]; 
+#if H_MV5
+       Bool shallBeButIsNotIncreasing = ( !inc  ) ; 
+#else
        Bool shallBeButIsNotIncreasing = ( !inc && ( lastDiff != viewDimPosition ) ) ; 
+#endif
        if ( shallBeButIsNotIncreasing )
        {       
          printf( "\nError: Positions of Layers %d and %d is not increasing in dimension %d \n", i, j, lastDiff);        
        }
+#if H_MV5
+       xConfirmPara( shallBeButIsNotIncreasing,  "DimensionIds shall be increasing within one dimension. " );
+#else
        xConfirmPara( shallBeButIsNotIncreasing && ( lastDiff != viewDimPosition ),  "DimensionIds shall be increasing within one dimension. " );
+#endif
      }
    }
  }
 
+#if H_MV5
+ /// ViewId 
+ xConfirmPara( m_viewId.size() != m_iNumberOfViews, "The number of ViewIds must be equal to the number of views." ); 
+
   /// Layer sets
+  xConfirmPara( m_vpsNumLayerSets < 0 || m_vpsNumLayerSets > 1024, "VpsNumLayerSets must be greater than 0 and less than 1025. ") ; 
+#else
   xConfirmPara( m_vpsNumLayerSets < 0 || m_vpsNumLayerSets > 1024, "VpsNumLayerSets must be greater than 0 and less than 1025") ; 
+#endif
   for( Int lsIdx = 0; lsIdx < m_vpsNumLayerSets; lsIdx++ )
   {
@@ -2068,4 +2161,28 @@
   }
 #endif
+#if H_MV5
+#if H_MV
+  // VPS VUI
+  for(Int i = 0; i < MAX_VPS_OP_SETS_PLUS1; i++ )
+  { 
+    for (Int j = 0; j < MAX_TLAYER; j++)
+    {    
+      if ( j < m_avgBitRate        [i].size() ) xConfirmPara( m_avgBitRate[i][j]         <  0 || m_avgBitRate[i][j]         > 65535, "avg_bit_rate            must be more than or equal to     0 and less than 65536" );
+      if ( j < m_maxBitRate        [i].size() ) xConfirmPara( m_maxBitRate[i][j]         <  0 || m_maxBitRate[i][j]         > 65535, "max_bit_rate            must be more than or equal to     0 and less than 65536" );
+      if ( j < m_constantPicRateIdc[i].size() ) xConfirmPara( m_constantPicRateIdc[i][j] <  0 || m_constantPicRateIdc[i][j] >     3, "constant_pic_rate_idc   must be more than or equal to     0 and less than     4" );
+      if ( j < m_avgPicRate        [i].size() ) xConfirmPara( m_avgPicRate[i][j]         <  0 || m_avgPicRate[i][j]         > 65535, "avg_pic_rate            must be more than or equal to     0 and less than 65536" );
+    }
+  }
+  // todo: replace value of 100 with requirement in spec
+  for(Int i = 0; i < MAX_NUM_LAYERS; i++ )
+  { 
+    for (Int j = 0; j < MAX_NUM_LAYERS; j++)
+    {    
+      if ( j < m_minSpatialSegmentOffsetPlus1[i].size() ) xConfirmPara( m_minSpatialSegmentOffsetPlus1[i][j] < 0 || m_minSpatialSegmentOffsetPlus1[i][j] >   100, "min_spatial_segment_offset_plus1 must be more than or equal to     0 and less than   101" );
+      if ( j < m_minHorizontalCtuOffsetPlus1[i] .size() ) xConfirmPara( m_minHorizontalCtuOffsetPlus1[i][j]  < 0 || m_minHorizontalCtuOffsetPlus1[i][j]  >   100, "min_horizontal_ctu_offset_plus1  must be more than or equal to     0 and less than   101" );
+    }
+  }
+#endif
+#endif
 
   xConfirmPara(!m_TransquantBypassEnableFlag && m_CUTransquantBypassFlagValue, "CUTransquantBypassFlagValue cannot be 1 when TransquantBypassEnableFlag is 0");
@@ -2133,5 +2250,10 @@
 #endif
 #if H_MV
+#if H_MV5
+  xPrintParaVector( "ViewIdVal"     , m_viewId ); 
+  xPrintParaVector( "ViewOrderIndex", m_viewOrderIndex ); 
+#else
   xPrintParaVector( "ViewId", m_viewId ); 
+#endif
 #endif
 #if H_3D
Index: branches/HTM-8.0-dev0/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- branches/HTM-8.0-dev0/source/App/TAppEncoder/TAppEncCfg.h	(revision 617)
+++ branches/HTM-8.0-dev0/source/App/TAppEncoder/TAppEncCfg.h	(revision 618)
@@ -69,6 +69,10 @@
   std::vector<char*>     m_pchReconFileList;                  ///< output reconstruction file names
   Int                    m_numberOfLayers;                    ///< number of Layers to Encode
+#if H_MV5
+  Int                    m_iNumberOfViews;                    ///< number of Layers that are views
+#else
 #if H_3D
   Int                    m_iNumberOfViews;                    ///< number of Layers that are views
+#endif
 #endif
 #else
@@ -79,4 +83,7 @@
   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_MV5
+  std::vector<Int>       m_viewOrderIndex;                    ///< view order index  
+#endif
 #if H_3D
   std::vector<Int>       m_depthFlag;                         ///< depth flag
@@ -98,4 +105,22 @@
   std::vector< std::vector<Int> > m_directRefLayers;          ///< LayerIds of direct reference layers
   std::vector< std::vector<Int> > m_dependencyTypes;          ///< Dependency types of direct reference layers
+
+#if H_MV5
+  // VPS VUI
+  Bool m_vpsVuiPresentFlag;
+  Bool m_bitRatePresentVpsFlag;
+  Bool m_picRatePresentVpsFlag;
+  std::vector< std::vector<Bool > > m_bitRatePresentFlag;
+  std::vector< std::vector<Bool > > m_picRatePresentFlag;
+  std::vector< std::vector<Int  > > m_avgBitRate;
+  std::vector< std::vector<Int  > > m_maxBitRate;
+  std::vector< std::vector<Int  > > m_constantPicRateIdc;
+  std::vector< std::vector<Int  > > m_avgPicRate;
+  std::vector< std::vector<Bool > > m_tileBoundariesAlignedFlag;  
+  Bool m_ilpRestrictedRefLayersFlag;
+  std::vector< std::vector<Int  > > m_minSpatialSegmentOffsetPlus1;
+  std::vector< std::vector<Bool > > m_ctuBasedOffsetEnabledFlag;
+  std::vector< std::vector<Int  > > m_minHorizontalCtuOffsetPlus1;
+#endif
 
 #if H_3D_IV_MERGE
Index: branches/HTM-8.0-dev0/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- branches/HTM-8.0-dev0/source/App/TAppEncoder/TAppEncTop.cpp	(revision 617)
+++ branches/HTM-8.0-dev0/source/App/TAppEncoder/TAppEncTop.cpp	(revision 618)
@@ -88,5 +88,9 @@
     vps.setTemporalNestingFlag(true);
   }
+#if H_MV5
+  vps.setMaxLayersMinus1( m_numberOfLayers - 1);
+#else
   vps.setMaxLayers( m_numberOfLayers );
+#endif
   for(Int i = 0; i < MAX_TLAYER; i++)
   {
@@ -120,12 +124,25 @@
   xSetDependencies( vps );
   xSetProfileTierLevel     ( vps ); 
+#if H_MV5
+  xSetRepFormat            ( vps ); 
+#endif
   xSetLayerSets            ( vps ); 
+#if H_MV5
+  xSetVPSVUI               ( vps ); 
+#endif
 #if H_3D
+#if !H_MV5
   vps.initViewIndex(); 
+#endif
   xSetVPSExtension2        ( vps ); 
   m_ivPicLists.setVPS      ( &vps ); 
 #endif
 
+
+#if H_MV5
+  for(Int layerIdInVps = 0; layerIdInVps < m_numberOfLayers; layerIdInVps++)
+#else 
   for(Int layer = 0; layer < m_numberOfLayers; layer++)
+#endif
   {
     m_frameRcvd                 .push_back(0);
@@ -134,5 +151,14 @@
     m_acTVideoIOYuvReconFileList.push_back(new TVideoIOYuv);
     m_picYuvRec                 .push_back(new TComList<TComPicYuv*>) ;
-
+#if H_MV5   
+    m_ivPicLists.push_back( m_acTEncTopList[ layerIdInVps ]->getListPic()  ); 
+    TEncTop& m_cTEncTop = *m_acTEncTopList[ layerIdInVps ];  // It is not a member, but this name helps avoiding code duplication !!!
+
+    Int layerId = vps.getLayerIdInNuh( layerIdInVps );
+    m_cTEncTop.setLayerIdInVps                 ( layerIdInVps ); 
+    m_cTEncTop.setLayerId                      ( layerId );    
+    m_cTEncTop.setViewId                       ( vps.getViewId      (  layerId ) );
+    m_cTEncTop.setViewIndex                    ( vps.getViewIndex   (  layerId ) );
+#else
     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 !!!
@@ -141,7 +167,13 @@
     m_cTEncTop.setLayerId                      ( vps.getLayerIdInNuh( layer ) );    
     m_cTEncTop.setViewId                       ( vps.getViewId      ( layer ) );
+
+#endif
 #if H_3D
+#if H_MV5
+    Bool isDepth = ( vps.getDepthId     ( layerId ) != 0 ) ;
+#else
     Bool isDepth = ( vps.getDepthId     ( layer ) != 0 ) ;
     m_cTEncTop.setViewIndex                    ( vps.getViewIndex   ( layer ) );
+#endif
     m_cTEncTop.setIsDepth                      ( isDepth );
     //====== Camera Parameters =========
@@ -169,4 +201,14 @@
     m_cTEncTop.setDWeight                      ( isDepth ? m_iDWeight             : 0     );
 #endif // H_3D_VSO
+#if H_MV5
+#if H_3D_ARP
+    //====== Advanced Inter-view Residual Prediction =========
+    m_cTEncTop.setUseAdvRP                     ( ( isDepth || 0==layerIdInVps ) ? 0 : m_uiUseAdvResPred );
+    m_cTEncTop.setARPStepNum                   ( ( isDepth || 0==layerIdInVps ) ? 1 : H_3D_ARP_WFNR     );
+#endif
+#if H_3D_IC
+    m_cTEncTop.setUseIC                        ( vps.getViewIndex( layerId ) == 0 ? false : m_abUseIC[isDepth ? 1 : 0] );
+#endif
+#else
 #if H_3D_ARP
     //====== Advanced Inter-view Residual Prediction =========
@@ -176,4 +218,5 @@
 #if H_3D_IC
     m_cTEncTop.setUseIC                        ( vps.getViewIndex( layer ) == 0 ? false : m_abUseIC[isDepth ? 1 : 0] );
+#endif
 #endif
   //========== Depth intra modes ==========
@@ -217,4 +260,13 @@
   m_cTEncTop.setGOPSize                      ( m_iGOPSize );
 #if H_MV
+#if H_MV5
+m_cTEncTop.setGopList                      ( m_GOPListMvc[layerIdInVps] );
+  m_cTEncTop.setExtraRPSs                    ( m_extraRPSsMvc[layerIdInVps] );
+  for(Int i = 0; i < MAX_TLAYER; i++)
+  {
+    m_cTEncTop.setNumReorderPics             ( m_numReorderPicsMvc[layerIdInVps][i], i );
+    m_cTEncTop.setMaxDecPicBuffering         ( m_maxDecPicBufferingMvc[layerIdInVps][i], i );
+  }
+#else
   m_cTEncTop.setGopList                      ( m_GOPListMvc[layer] );
   m_cTEncTop.setExtraRPSs                    ( m_extraRPSsMvc[layer] );
@@ -224,4 +276,5 @@
     m_cTEncTop.setMaxDecPicBuffering         ( m_maxDecPicBufferingMvc[layer][i], i );
   }
+#endif
 #else
   m_cTEncTop.setGopList                      ( m_GOPList );
@@ -238,5 +291,9 @@
   }
 #if H_MV
+#if H_MV5
+  m_cTEncTop.setQP                           ( m_iQP[layerIdInVps] );
+#else
   m_cTEncTop.setQP                           ( m_iQP[layer] );
+#endif
 #else
   m_cTEncTop.setQP                           ( m_iQP );
@@ -246,5 +303,9 @@
 
 #if H_MV
+#if H_MV5
+  m_cTEncTop.setMaxTempLayer                 ( m_maxTempLayerMvc[layerIdInVps] );
+#else
   m_cTEncTop.setMaxTempLayer                 ( m_maxTempLayerMvc[layer] );
+#endif
 #else
   m_cTEncTop.setMaxTempLayer                 ( m_maxTempLayer );
@@ -256,5 +317,9 @@
   //====== Loop/Deblock Filter ========
 #if H_MV
+#if H_MV5
+  m_cTEncTop.setLoopFilterDisable            ( m_bLoopFilterDisable[layerIdInVps]);
+#else
   m_cTEncTop.setLoopFilterDisable            ( m_bLoopFilterDisable[layer]);
+#endif
 #else
   m_cTEncTop.setLoopFilterDisable            ( m_bLoopFilterDisable       );
@@ -286,5 +351,9 @@
 
 #if H_MV
+#if H_MV5
+  if ((m_iMaxDeltaQP == 0 ) && (m_iQP[layerIdInVps] == lowestQP) && (m_useLossless == true))
+#else
   if ((m_iMaxDeltaQP == 0 ) && (m_iQP[layer] == lowestQP) && (m_useLossless == true))
+#endif
 #else
   if ((m_iMaxDeltaQP == 0 ) && (m_iQP == lowestQP) && (m_useLossless == true))
@@ -303,5 +372,9 @@
   m_cTEncTop.setUseLossless                  ( m_useLossless );
 #if H_MV
+#if H_MV5
+  m_cTEncTop.setdQPs                         ( m_aidQP[layerIdInVps]   );
+#else
   m_cTEncTop.setdQPs                         ( m_aidQP[layer]   );
+#endif
 #else
   m_cTEncTop.setdQPs                         ( m_aidQP        );
@@ -362,5 +435,9 @@
   m_cTEncTop.setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag );
 #if H_MV
+#if H_MV5
+  m_cTEncTop.setUseSAO ( m_bUseSAO[layerIdInVps] );
+#else
   m_cTEncTop.setUseSAO ( m_bUseSAO[layer] );
+#endif
 #else
   m_cTEncTop.setUseSAO ( m_bUseSAO );
@@ -1044,13 +1121,37 @@
 Void TAppEncTop::xSetDimensionIdAndLength( TComVPS& vps )
 {   
+#if H_MV5
+  vps.setScalabilityMaskFlag( m_scalabilityMask ); 
+#else
   vps.setScalabilityMask( m_scalabilityMask ); 
+#endif
   for( Int dim = 0; dim < m_dimIds.size(); dim++ )
   {
     vps.setDimensionIdLen( dim, m_dimensionIdLen[ dim ] );
+#if H_MV5
+    for( Int layer = 0; layer <= vps.getMaxLayersMinus1(); layer++ )
+#else
     for( Int layer = 0; layer < vps.getMaxLayers(); layer++ )
+#endif
+
     {        
       vps.setDimensionId( layer, dim, m_dimIds[ dim ][ layer ] );        
     }  
   }
+
+#if H_MV5
+  Int maxViewId = xGetMax( m_viewId ); 
+
+  Int viewIdLenMinus1 = std::max( gCeilLog2( maxViewId + 1 ) - 1, 0 ) ; 
+  const Int maxViewIdLenMinus1 = ( 1 << 4 ) - 1; 
+  assert( viewIdLenMinus1 <= maxViewIdLenMinus1  ); 
+  vps.setViewIdLenMinus1( viewIdLenMinus1 ); 
+  for (Int i = 0; i < m_iNumberOfViews; i++)
+  {
+    vps.setViewIdVal( i, m_viewId[ i] ); 
+  }
+
+  assert( m_iNumberOfViews == vps.getNumViews() ); 
+#endif
 }
 
@@ -1078,5 +1179,8 @@
   }
 
-  // Max temporal id for inter layer reference pictures
+  // Max temporal id for inter layer reference pictures + presence flag
+#if H_MV5
+  Bool maxTidRefPresentFlag = false; 
+#endif
   for ( Int refLayerIdInVps = 0; refLayerIdInVps < m_numberOfLayers; refLayerIdInVps++)
     {
@@ -1099,13 +1203,27 @@
     }
     vps.setMaxTidIlRefPicPlus1( refLayerIdInVps, maxTid + 1 );
-  }
-
+#if H_MV5
+    maxTidRefPresentFlag = maxTidRefPresentFlag || ( maxTid != 6 );    
+#endif
+  }
+
+#if H_MV5
+  vps.setMaxTidRefPresentFlag( maxTidRefPresentFlag );
+#endif
   // Max one active ref layer flag
   Bool maxOneActiveRefLayerFlag = true;  
+#if H_MV5
+  for ( Int layerIdInVps = 1; layerIdInVps < m_numberOfLayers && maxOneActiveRefLayerFlag; layerIdInVps++)
+#else
   for ( Int currLayerIdInVps = 1; currLayerIdInVps < m_numberOfLayers && maxOneActiveRefLayerFlag; currLayerIdInVps++)
+#endif
   {
     for( Int i = 0; i < ( getGOPSize() + 1) && maxOneActiveRefLayerFlag; i++ ) 
     {        
+#if H_MV5
+      GOPEntry ge =  m_GOPListMvc[layerIdInVps][ ( i < getGOPSize()  ? i : MAX_GOP ) ]; 
+#else
       GOPEntry ge =  m_GOPListMvc[currLayerIdInVps][ ( i < getGOPSize()  ? i : MAX_GOP ) ]; 
+#endif
       maxOneActiveRefLayerFlag =  maxOneActiveRefLayerFlag && (ge.m_numActiveRefLayerPics <= 1); 
     }            
@@ -1113,7 +1231,43 @@
 
   vps.setMaxOneActiveRefLayerFlag( maxOneActiveRefLayerFlag );
+  
+  
+#if H_MV5
+  // All Ref layers active flag
+  Bool allRefLayersActiveFlag = true; 
+  for ( Int layerIdInVps = 1; layerIdInVps < m_numberOfLayers && allRefLayersActiveFlag; layerIdInVps++)
+  {    
+    for( Int i = 0; i < ( getGOPSize() + 1) && allRefLayersActiveFlag; i++ ) 
+    {        
+      GOPEntry ge =  m_GOPListMvc[layerIdInVps][ ( i < getGOPSize()  ? i : MAX_GOP ) ]; 
+      allRefLayersActiveFlag = allRefLayersActiveFlag && (ge.m_numActiveRefLayerPics == m_directRefLayers[ layerIdInVps ].size() ); 
+    }            
+  }
+
+  vps.setAllRefLayersActiveFlag( allRefLayersActiveFlag );
+
+  // Currently cross layer irap aligned is always true.   
+  vps.setCrossLayerIrapAlignedFlag( true ); 
+#endif
   vps.setRefLayers(); 
 }; 
 
+#if H_MV5
+GOPEntry* TAppEncTop::xGetGopEntry( Int layerIdInVps, Int poc )
+{
+  GOPEntry* geFound = NULL; 
+  for( Int i = 0; i < ( getGOPSize() + 1) && geFound == NULL ; i++ ) 
+  {
+    GOPEntry* ge = &(m_GOPListMvc[layerIdInVps][ ( i < getGOPSize()  ? i : MAX_GOP ) ]);
+    if ( ge->m_POC == poc )
+    {
+      geFound = ge;       
+    }
+  }
+  assert( geFound != NULL ); 
+  return geFound; 
+}
+#endif
+
 Void TAppEncTop::xSetLayerIds( TComVPS& vps )
 {
@@ -1137,5 +1291,7 @@
   Int maxVec = 0; 
   for ( Int i = 0; i < vec.size(); i++)    
+  {
     maxVec = max( vec[i], maxVec ); 
+  }
   return maxVec;
 }
@@ -1152,4 +1308,30 @@
 }
 
+#if H_MV5
+
+Void TAppEncTop::xSetRepFormat( TComVPS& vps )
+{
+  vps.setRepFormatIdxPresentFlag( true ); 
+  vps.setVpsNumRepFormatsMinus1 ( 0    ); 
+
+  TComRepFormat* repFormat = new TComRepFormat; 
+
+  repFormat->setBitDepthVpsChromaMinus8   ( g_bitDepthC - 8 ); 
+  repFormat->setBitDepthVpsLumaMinus8     ( g_bitDepthY - 8 );
+  repFormat->setChromaFormatVpsIdc        ( CHROMA_420      );
+  repFormat->setPicHeightVpsInLumaSamples ( m_iSourceHeight );
+  repFormat->setPicWidthVpsInLumaSamples  ( m_iSourceWidth  );    
+  // ToDo not supported yet. 
+  //repFormat->setSeparateColourPlaneVpsFlag( );
+
+  assert( vps.getRepFormat( 0 ) == NULL ); 
+  vps.setRepFormat( 0 , repFormat );
+
+  for(Int i = 0; i <= vps.getMaxLayersMinus1(); i++ )
+  {
+    vps.setVpsRepFormatIdx( i , 0 ); 
+  }
+}
+#endif
 
 Void TAppEncTop::xSetLayerSets( TComVPS& vps )
@@ -1204,9 +1386,106 @@
   }
 }
+#if H_MV5
+
+Void TAppEncTop::xSetVPSVUI( TComVPS& vps )
+{
+  vps.setVpsVuiPresentFlag( m_vpsVuiPresentFlag ); 
+
+  if ( m_vpsVuiPresentFlag )
+  {
+    TComVPSVUI* pcVPSVUI = vps.getVPSVUI(  ); 
+
+    assert( pcVPSVUI ); 
+
+    pcVPSVUI->setBitRatePresentVpsFlag( m_bitRatePresentVpsFlag );
+    pcVPSVUI->setPicRatePresentVpsFlag( m_picRatePresentVpsFlag );
+
+    if( pcVPSVUI->getBitRatePresentVpsFlag( )  ||  pcVPSVUI->getPicRatePresentVpsFlag( ) )
+    {
+      for( Int i = 0; i  <=  vps.getVpsNumberLayerSetsMinus1(); i++ )
+      {
+        for( Int j = 0; j  <=  vps.getMaxTLayers(); j++ ) 
+        {
+          if( pcVPSVUI->getBitRatePresentVpsFlag( ) && m_bitRatePresentFlag[i].size() > j )
+          {
+            pcVPSVUI->setBitRatePresentFlag( i, j, m_bitRatePresentFlag[i][j] );            
+          }
+          if( pcVPSVUI->getPicRatePresentVpsFlag( ) && m_picRatePresentFlag[i].size() > j   )
+          {
+            pcVPSVUI->setPicRatePresentFlag( i, j, m_picRatePresentFlag[i][j] );
+          }
+          if( pcVPSVUI->getBitRatePresentFlag( i, j )  && m_avgBitRate[i].size() > j )
+          {
+            pcVPSVUI->setAvgBitRate( i, j, m_avgBitRate[i][j] );          
+          }
+          if( pcVPSVUI->getBitRatePresentFlag( i, j )  && m_maxBitRate[i].size() > j )
+          {
+            pcVPSVUI->setMaxBitRate( i, j, m_maxBitRate[i][j] );
+          }
+          if( pcVPSVUI->getPicRatePresentFlag( i, j ) && m_constantPicRateIdc[i].size() > j )
+          {
+            pcVPSVUI->setConstantPicRateIdc( i, j, m_constantPicRateIdc[i][j] );
+          }
+          if( pcVPSVUI->getPicRatePresentFlag( i, j ) && m_avgPicRate[i].size() > j )
+          {
+            pcVPSVUI->setAvgPicRate( i, j, m_avgPicRate[i][j] );
+          }
+        }
+      }
+    }
+
+    for( Int i = 1; i  <=  vps.getMaxLayersMinus1(); i++ )
+    {
+      for( Int  j = 0; j < vps.getNumDirectRefLayers( vps.getLayerIdInNuh( i ) ); j++ ) 
+      {
+        if ( m_tileBoundariesAlignedFlag[i].size() > j )
+        {
+          pcVPSVUI->setTileBoundariesAlignedFlag( i, j, m_tileBoundariesAlignedFlag[i][j]);
+        }
+      }
+    }
+
+    pcVPSVUI->setIlpRestrictedRefLayersFlag( m_ilpRestrictedRefLayersFlag );
+
+    if( pcVPSVUI->getIlpRestrictedRefLayersFlag( ) )
+    {
+      for( Int i = 1; i  <=  vps.getMaxLayersMinus1(); i++ )
+      {
+        for( Int j = 0; j < vps.getNumDirectRefLayers( vps.getLayerIdInNuh( i ) ); j++ )
+        {
+          if ( m_minSpatialSegmentOffsetPlus1[i].size() > j )
+          {        
+            pcVPSVUI->setMinSpatialSegmentOffsetPlus1( i, j, m_minSpatialSegmentOffsetPlus1[i][j] );
+          }
+          if( pcVPSVUI->getMinSpatialSegmentOffsetPlus1( i, j ) > 0 )
+          {
+            if ( m_ctuBasedOffsetEnabledFlag[i].size() > j )
+            {        
+              pcVPSVUI->setCtuBasedOffsetEnabledFlag( i, j, m_ctuBasedOffsetEnabledFlag[i][j] );
+            }
+            if( pcVPSVUI->getCtuBasedOffsetEnabledFlag( i, j ) )
+            {
+              if ( m_minHorizontalCtuOffsetPlus1[i].size() > j )
+              {
+                pcVPSVUI->setMinHorizontalCtuOffsetPlus1( i, j, m_minHorizontalCtuOffsetPlus1[i][j] );
+              }
+            }
+          }
+        }
+      }
+    }      
+  }
+}
+#endif
 #endif
 #if H_3D
 Void TAppEncTop::xSetVPSExtension2( TComVPS& vps )
 {
+#if H_MV5
+
+  for ( Int layer = 0; layer <= vps.getMaxLayersMinus1(); layer++ )
+#else
   for ( Int layer = 0; layer < vps.getMaxLayers(); layer++ )
+#endif
   {
     Bool isDepth      = ( vps.getDepthId( layer ) == 1 ) ;
Index: branches/HTM-8.0-dev0/source/App/TAppEncoder/TAppEncTop.h
===================================================================
--- branches/HTM-8.0-dev0/source/App/TAppEncoder/TAppEncTop.h	(revision 617)
+++ branches/HTM-8.0-dev0/source/App/TAppEncoder/TAppEncTop.h	(revision 618)
@@ -121,4 +121,9 @@
   Void xSetLayerSets              ( TComVPS& vps );
   Void xSetProfileTierLevel       ( TComVPS& vps );
+#if H_MV5
+  Void xSetRepFormat              ( TComVPS& vps );
+  Void xSetVPSVUI                 ( TComVPS& vps );
+  GOPEntry* xGetGopEntry( Int layerIdInVps, Int poc );
+#endif
   Int  xGetMax( std::vector<Int>& vec);
 #endif
Index: branches/HTM-8.0-dev0/source/Lib/TLibCommon/CommonDef.h
===================================================================
--- branches/HTM-8.0-dev0/source/Lib/TLibCommon/CommonDef.h	(revision 617)
+++ branches/HTM-8.0-dev0/source/Lib/TLibCommon/CommonDef.h	(revision 618)
@@ -48,4 +48,7 @@
 #endif // _MSC_VER > 1000
 #include "TypeDef.h"
+#if H_MV
+#include <assert.h>
+#endif
 
 //! \ingroup TLibCommon
@@ -183,4 +186,15 @@
     return (t < 0) ? T(-1) : T(1);
 }
+
+#if H_MV5
+template <typename T>
+__inline T gCeilLog2( T val )
+{
+  assert( val > 0 ); 
+  Int ceilLog2 = 0;
+  while( val > ( 1 << ceilLog2 ) ) ceilLog2++;
+  return ceilLog2;
+}
+#endif
 
 #define RemoveBitIncrement( exp ) ( exp >> ( g_bitDepthY - 8 ) )
Index: branches/HTM-8.0-dev0/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- branches/HTM-8.0-dev0/source/Lib/TLibCommon/TComDataCU.cpp	(revision 617)
+++ branches/HTM-8.0-dev0/source/Lib/TLibCommon/TComDataCU.cpp	(revision 618)
@@ -4830,4 +4830,7 @@
 
   // use coldir.
+#if H_MV5
+  TComPic *pColPic = getSlice()->getRefPic( RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0), getSlice()->getColRefIdx());
+#else
 #if H_MV
   TComPic *pColPic;  
@@ -4842,4 +4845,5 @@
 #else
   TComPic *pColPic = getSlice()->getRefPic( RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0), getSlice()->getColRefIdx());
+#endif
 #endif
   TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
Index: branches/HTM-8.0-dev0/source/Lib/TLibCommon/TComRom.cpp
===================================================================
--- branches/HTM-8.0-dev0/source/Lib/TLibCommon/TComRom.cpp	(revision 617)
+++ branches/HTM-8.0-dev0/source/Lib/TLibCommon/TComRom.cpp	(revision 618)
@@ -372,5 +372,5 @@
 const Bool g_bEncDecTraceEnable  = true;
 const Bool g_bEncDecTraceDisable = false;
-Bool   g_HLSTraceEnable = true;
+Bool   g_HLSTraceEnable = false;
 Bool   g_bJustDoIt = false;
 UInt64 g_nSymbolCounter = 0;
@@ -380,5 +380,8 @@
 Bool g_traceTU = true; 
 Bool g_disableHLSTrace = false; 
-UInt64 g_stopAtCounter   = 10803; 
+UInt64 g_stopAtCounter       = 48; 
+Bool g_traceCopyBack         = false; 
+Bool g_decTraceDispDer       = false; 
+Bool g_decTraceMvFromMerge   = false; 
 #endif
 #endif
Index: branches/HTM-8.0-dev0/source/Lib/TLibCommon/TComRom.h
===================================================================
--- branches/HTM-8.0-dev0/source/Lib/TLibCommon/TComRom.h	(revision 617)
+++ branches/HTM-8.0-dev0/source/Lib/TLibCommon/TComRom.h	(revision 618)
@@ -224,6 +224,9 @@
  extern Bool   g_tracePU; 
  extern Bool   g_traceTU; 
- extern Bool   g_disableHLSTrace; 
- extern UInt64 g_stopAtCounter; 
+ extern Bool   g_disableHLSTrace;       // USE g_HLSTraceEnable to toggle HLS trace. Not this one!
+ extern UInt64 g_stopAtCounter;         // Counter to set breakpoint. 
+ extern Bool   g_traceCopyBack;         // Output samples on copy back  
+ extern Bool   g_decTraceDispDer; // Trace derived disparity vectors (decoder only) 
+ extern Bool   g_decTraceMvFromMerge;   // Trace motion vectors obtained from merge (decoder only) 
 
 #define DTRACE_CU(x,y)             writeToTraceFile( x,y, g_traceCU );
Index: branches/HTM-8.0-dev0/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- branches/HTM-8.0-dev0/source/Lib/TLibCommon/TComSlice.cpp	(revision 617)
+++ branches/HTM-8.0-dev0/source/Lib/TLibCommon/TComSlice.cpp	(revision 618)
@@ -101,17 +101,32 @@
 , m_enableTMVPFlag                ( true )
 #if H_MV
+#if H_MV5
+, m_refPicSetInterLayer0           ( NULL )
+, m_refPicSetInterLayer1           ( NULL )
+#else
 , m_refPicSetInterLayer           ( NULL )
+#endif
 , m_layerId                       (0)
 , m_viewId                        (0)
+#if H_MV5
+, m_viewIndex                     (0)
+#endif
 #if H_3D
+#if !H_MV5
 , m_viewIndex                     (0)
+#endif
 , m_isDepth                       (false)
+#endif
+#if H_MV5
+, m_pocResetFlag                  (false)
 #endif
 , m_discardableFlag               (false)
 , m_interLayerPredEnabledFlag     (false)
 , m_numInterLayerRefPicsMinus1    (0)
+#if !H_MV5
 , m_interLayerSamplePredOnlyFlag  (false)
 , m_altCollocatedIndicationFlag   (0)
 , m_collocatedRefLayerIdx         (0)
+#endif
 #if H_3D_IC
 , m_bApplyIC                      ( false )
@@ -149,5 +164,9 @@
   for (Int i = 0; i < MAX_NUM_LAYERS; i++ )
   {
+#if H_MV5
+   m_interLayerPredLayerIdc[ i ] = i;
+#else
    m_interLayerPredLayerIdc[ i ] = 0;
+#endif
   }
 #endif
@@ -162,12 +181,18 @@
   {
     if ( m_depthToDisparityB && m_depthToDisparityB[ i ] )
+    {
       delete[] m_depthToDisparityB [ i ];
+    }
 
     if ( m_depthToDisparityF && m_depthToDisparityF[ i ] ) 
+    {
       delete[] m_depthToDisparityF [ i ];
   }
+  }
 
   if ( m_depthToDisparityF )
+  {
     delete[] m_depthToDisparityF; 
+  }
 
   m_depthToDisparityF = NULL;
@@ -362,7 +387,6 @@
   }
 }
-#if H_MV
-Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& refPicSetInterLayer , Bool checkNumPocTotalCurr)
-#else
+#if H_MV5
+#if !H_MV
 #if FIX1071
 Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr )
@@ -370,5 +394,4 @@
 Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic )
 #endif
-#endif
 {
 #if FIX1071
@@ -380,12 +403,10 @@
       ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
       ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
-      
+
       return;
     }
-    
-#if !H_MV
+
     m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
     m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
-#endif
   }
 
@@ -411,4 +432,352 @@
     }
   }
+
+  for(; i < m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures(); i++)
+  {
+    if(m_pcRPS->getUsed(i))
+    {
+      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
+      pcRefPic->setIsLongTerm(0);
+      pcRefPic->getPicYuvRec()->extendPicBorder();
+      RefPicSetStCurr1[NumPocStCurr1] = pcRefPic;
+      NumPocStCurr1++;
+      pcRefPic->setCheckLTMSBPresent(false);  
+    }
+  }
+
+  for(i = m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()+m_pcRPS->getNumberOfLongtermPictures()-1; i > m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()-1 ; i--)
+  {
+    if(m_pcRPS->getUsed(i))
+    {
+      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
+      pcRefPic->setIsLongTerm(1);
+      pcRefPic->getPicYuvRec()->extendPicBorder();
+      RefPicSetLtCurr[NumPocLtCurr] = pcRefPic;
+      NumPocLtCurr++;
+    }
+    if(pcRefPic==NULL) 
+    {
+      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
+    }
+    pcRefPic->setCheckLTMSBPresent(m_pcRPS->getCheckLTMSBPresent(i));  
+  }
+
+  // ref_pic_list_init
+  TComPic*  rpsCurrList0[MAX_NUM_REF+1];
+  TComPic*  rpsCurrList1[MAX_NUM_REF+1];
+  Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr;
+
+#if FIX1071
+  if (checkNumPocTotalCurr)
+  {
+    // The variable NumPocTotalCurr is derived as specified in subclause 7.4.7.2. It is a requirement of bitstream conformance that the following applies to the value of NumPocTotalCurr:
+    //  If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
+    //  Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
+    if (getRapPicFlag())
+    {
+      assert(numPocTotalCurr == 0);
+    }
+
+    if (m_eSliceType == I_SLICE)
+    {
+      ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
+      ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
+
+      return;
+    }
+
+    assert(numPocTotalCurr > 0);
+
+    m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
+    m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
+  }
+#endif
+
+  Int cIdx = 0;
+  for ( i=0; i<NumPocStCurr0; i++, cIdx++)
+  {
+    rpsCurrList0[cIdx] = RefPicSetStCurr0[i];
+  }
+  for ( i=0; i<NumPocStCurr1; i++, cIdx++)
+  {
+    rpsCurrList0[cIdx] = RefPicSetStCurr1[i];
+  }
+  for ( i=0; i<NumPocLtCurr;  i++, cIdx++)
+  {
+    rpsCurrList0[cIdx] = RefPicSetLtCurr[i];
+  }
+  assert(cIdx == numPocTotalCurr);
+
+  if (m_eSliceType==B_SLICE)
+  {
+    cIdx = 0;
+    for ( i=0; i<NumPocStCurr1; i++, cIdx++)
+    {
+      rpsCurrList1[cIdx] = RefPicSetStCurr1[i];
+    }
+    for ( i=0; i<NumPocStCurr0; i++, cIdx++)
+    {
+      rpsCurrList1[cIdx] = RefPicSetStCurr0[i];
+    }
+    for ( i=0; i<NumPocLtCurr;  i++, cIdx++)
+    {
+      rpsCurrList1[cIdx] = RefPicSetLtCurr[i];
+    }
+    assert(cIdx == numPocTotalCurr);
+  }
+
+  ::memset(m_bIsUsedAsLongTerm, 0, sizeof(m_bIsUsedAsLongTerm));
+
+  for (Int rIdx = 0; rIdx < m_aiNumRefIdx[0]; rIdx ++)
+  {
+    cIdx = m_RefPicListModification.getRefPicListModificationFlagL0() ? m_RefPicListModification.getRefPicSetIdxL0(rIdx) : rIdx % numPocTotalCurr;
+    assert(cIdx >= 0 && cIdx < numPocTotalCurr);
+    m_apcRefPicList[0][rIdx] = rpsCurrList0[ cIdx ];
+    m_bIsUsedAsLongTerm[0][rIdx] = ( cIdx >= NumPocStCurr0 + NumPocStCurr1 );
+  }
+  if ( m_eSliceType != B_SLICE )
+  {
+    m_aiNumRefIdx[1] = 0;
+    ::memset( m_apcRefPicList[1], 0, sizeof(m_apcRefPicList[1]));
+  }
+  else
+  {
+    for (Int rIdx = 0; rIdx < m_aiNumRefIdx[1]; rIdx ++)
+    {
+      cIdx = m_RefPicListModification.getRefPicListModificationFlagL1() ? m_RefPicListModification.getRefPicSetIdxL1(rIdx) : rIdx % numPocTotalCurr;
+      assert(cIdx >= 0 && cIdx < numPocTotalCurr);
+      m_apcRefPicList[1][rIdx] = rpsCurrList1[ cIdx ];
+      m_bIsUsedAsLongTerm[1][rIdx] = ( cIdx >= NumPocStCurr0 + NumPocStCurr1 );
+    }
+  }
+}
+
+#else
+Void TComSlice::getTempRefPicLists( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& refPicSetInterLayer0, std::vector<TComPic*>& refPicSetInterLayer1,                                     
+                                   std::vector<TComPic*> rpsCurrList[2], std::vector<Bool> usedAsLongTerm[2], Int& numPocTotalCurr, Bool checkNumPocTotalCurr )
+{
+  if (!checkNumPocTotalCurr)
+  {
+    if (m_eSliceType == I_SLICE)
+    {      
+      return;
+    }    
+  }
+
+  TComPic*  pcRefPic= NULL;
+  TComPic*  RefPicSetStCurr0[16];
+  TComPic*  RefPicSetStCurr1[16];
+  TComPic*  RefPicSetLtCurr[16];
+  UInt NumPocStCurr0 = 0;
+  UInt NumPocStCurr1 = 0;
+  UInt NumPocLtCurr = 0;
+  Int i;
+
+  for(i=0; i < m_pcRPS->getNumberOfNegativePictures(); i++)
+  {
+    if(m_pcRPS->getUsed(i))
+    {
+      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
+      pcRefPic->setIsLongTerm(0);
+      pcRefPic->getPicYuvRec()->extendPicBorder();
+      RefPicSetStCurr0[NumPocStCurr0] = pcRefPic;
+      NumPocStCurr0++;
+      pcRefPic->setCheckLTMSBPresent(false);  
+    }
+  }
+  
+  for(; i < m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures(); i++)
+  {
+    if(m_pcRPS->getUsed(i))
+    {
+      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
+      pcRefPic->setIsLongTerm(0);
+      pcRefPic->getPicYuvRec()->extendPicBorder();
+      RefPicSetStCurr1[NumPocStCurr1] = pcRefPic;
+      NumPocStCurr1++;
+      pcRefPic->setCheckLTMSBPresent(false);  
+    }
+  }
+  
+  for(i = m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()+m_pcRPS->getNumberOfLongtermPictures()-1; i > m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()-1 ; i--)
+  {
+    if(m_pcRPS->getUsed(i))
+    {
+      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
+      pcRefPic->setIsLongTerm(1);
+      pcRefPic->getPicYuvRec()->extendPicBorder();
+      RefPicSetLtCurr[NumPocLtCurr] = pcRefPic;
+      NumPocLtCurr++;
+    }
+    if(pcRefPic==NULL) 
+    {
+      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
+    }
+    pcRefPic->setCheckLTMSBPresent(m_pcRPS->getCheckLTMSBPresent(i));  
+  }
+
+  Int numPocInterCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr; 
+  numPocTotalCurr = numPocInterCurr + getNumActiveRefLayerPics( );
+  assert( numPocTotalCurr == getNumRpsCurrTempList() );
+
+  if (checkNumPocTotalCurr)
+  {
+    // The variable NumPocTotalCurr is derived as specified in subclause 7.4.7.2. It is a requirement of bitstream conformance that the following applies to the value of NumPocTotalCurr:
+    // - If nuh_layer_id is equal to 0 and the current picture is a BLA picture or a CRA picture, the value of NumPocTotalCurr shall be equal to 0.
+    // - Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
+    if ( getRapPicFlag() && m_layerId == 0 )
+    {
+      assert(numPocTotalCurr == 0);
+    }
+
+    if (m_eSliceType == I_SLICE)
+    {
+      ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
+      ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
+      
+      return;
+    }
+    
+    assert(numPocTotalCurr > 0);
+    
+    m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
+    m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
+  }
+
+  std::vector<TComPic*>* refPicSetInterLayer[2] = { &refPicSetInterLayer0, &refPicSetInterLayer1}; 
+  Int numPocInterLayer[2] = { getNumActiveRefLayerPics0( ), getNumActiveRefLayerPics1( ) }; 
+  
+  TComPic**             refPicSetStCurr    [2] = { RefPicSetStCurr0, RefPicSetStCurr1 };
+  Int numPocStCurr[2] = { NumPocStCurr0, NumPocStCurr1 }; 
+
+  for (Int li = 0; li < ((m_eSliceType==B_SLICE) ? 2 : 1); li++)
+  { 
+    rpsCurrList   [li].resize(MAX_NUM_REF+1,NULL ); 
+    usedAsLongTerm[li].resize(MAX_NUM_REF+1,false); 
+
+    Int cIdx = 0;
+    for ( i=0; i < numPocStCurr[li]; i++, cIdx++)
+    {
+      rpsCurrList[li][cIdx] = refPicSetStCurr[li][i];
+      usedAsLongTerm [li][cIdx] = false;  
+    }
+
+    for ( i=0; i < numPocInterLayer[li];  i++, cIdx++)
+    {    
+      rpsCurrList[li][cIdx] = (*refPicSetInterLayer[li])[i];
+      usedAsLongTerm [li][cIdx] = true;  
+    }
+
+    for ( i=0; i < numPocStCurr[1-li]; i++, cIdx++)
+    {
+      rpsCurrList[li][cIdx] = refPicSetStCurr[1-li][i];
+      usedAsLongTerm [li][cIdx] = false;  
+    }
+
+    for ( i=0; i<NumPocLtCurr;  i++, cIdx++)
+    {
+      rpsCurrList[li][cIdx] = RefPicSetLtCurr[i];
+      usedAsLongTerm [li][cIdx] = true;  
+    }
+
+    for ( i=0; i < numPocInterLayer[1-li];  i++, cIdx++)
+    {    
+      assert( cIdx < MAX_NUM_REF );    
+      rpsCurrList[li][cIdx] = (*refPicSetInterLayer[1-li])[i];
+      usedAsLongTerm [li][cIdx] = true;  
+    }
+
+    assert(cIdx == numPocTotalCurr);
+  }
+}
+
+Void TComSlice::setRefPicList( std::vector<TComPic*> rpsCurrList[2], std::vector<Bool> usedAsLongTerm[2], Int numPocTotalCurr, Bool checkNumPocTotalCurr )
+
+{
+  if (!checkNumPocTotalCurr)
+  {
+    if (m_eSliceType == I_SLICE)
+    {
+      ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
+      ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
+
+      return;
+    }    
+  }
+
+  ::memset(m_bIsUsedAsLongTerm, 0, sizeof(m_bIsUsedAsLongTerm));
+
+  for (Int li = 0; li < 2; li++)
+  {
+    if ( m_eSliceType == P_SLICE && li == 1 )
+    {
+      m_aiNumRefIdx[1] = 0;
+      ::memset( m_apcRefPicList[1], 0, sizeof(m_apcRefPicList[1]));
+    } 
+    else
+    {
+      for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[ li ] - 1 ); rIdx ++)
+      { 
+        Bool listModified             =                m_RefPicListModification.getRefPicListModificationFlagL( li ); 
+        Int orgIdx                    = listModified ? m_RefPicListModification.getRefPicSetIdxL(li, rIdx) : (rIdx % numPocTotalCurr); 
+
+        assert( rpsCurrList[li][ orgIdx ] != NULL ); 
+        m_apcRefPicList    [li][rIdx] = rpsCurrList    [li][ orgIdx ];
+        m_bIsUsedAsLongTerm[li][rIdx] = usedAsLongTerm [li][ orgIdx ] ; 
+      }
+    }
+  }
+}
+#endif
+#else
+#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 )
+#else
+Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic )
+#endif
+#endif
+{
+#if FIX1071
+  if (!checkNumPocTotalCurr)
+#endif
+  {
+    if (m_eSliceType == I_SLICE)
+    {
+      ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
+      ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
+      
+      return;
+    }
+    
+#if !H_MV
+    m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
+    m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
+#endif
+  }
+
+  TComPic*  pcRefPic= NULL;
+  TComPic*  RefPicSetStCurr0[16];
+  TComPic*  RefPicSetStCurr1[16];
+  TComPic*  RefPicSetLtCurr[16];
+  UInt NumPocStCurr0 = 0;
+  UInt NumPocStCurr1 = 0;
+  UInt NumPocLtCurr = 0;
+  Int i;
+
+  for(i=0; i < m_pcRPS->getNumberOfNegativePictures(); i++)
+  {
+    if(m_pcRPS->getUsed(i))
+    {
+      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
+      pcRefPic->setIsLongTerm(0);
+      pcRefPic->getPicYuvRec()->extendPicBorder();
+      RefPicSetStCurr0[NumPocStCurr0] = pcRefPic;
+      NumPocStCurr0++;
+      pcRefPic->setCheckLTMSBPresent(false);  
+    }
+  }
   
   for(; i < m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures(); i++)
@@ -458,10 +827,10 @@
     // The variable NumPocTotalCurr is derived as specified in subclause 7.4.7.2. It is a requirement of bitstream conformance that the following applies to the value of NumPocTotalCurr:
 #if H_MV
-    // – If nuh_layer_id is equal to 0 and the current picture is a BLA picture or a CRA picture, the value of NumPocTotalCurr shall be equal to 0.
-    // – Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
+    // â If nuh_layer_id is equal to 0 and the current picture is a BLA picture or a CRA picture, the value of NumPocTotalCurr shall be equal to 0.
+    // â Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
     if ( getRapPicFlag() && m_layerId == 0 )
 #else
-    // – If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
-    // – Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
+    // â If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
+    // â Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
     if (getRapPicFlag())
 #endif
@@ -593,4 +962,5 @@
 }
 
+#endif
 Int TComSlice::getNumRpsCurrTempList()
 {
@@ -609,5 +979,7 @@
   }
 #if H_MV
+#if !H_MV5
   assert( ( numRpsCurrTempList == 0 ) || getInterRefEnabledInRPLFlag() ); 
+#endif
   numRpsCurrTempList = numRpsCurrTempList + getNumActiveRefLayerPics();
 #endif
@@ -923,4 +1295,7 @@
 #if H_MV
   // Additional slice header syntax elements 
+#if H_MV5
+  m_pocResetFlag               = pSrc->m_pocResetFlag; 
+#endif
   m_discardableFlag            = pSrc->m_discardableFlag; 
   m_interLayerPredEnabledFlag  = pSrc->m_interLayerPredEnabledFlag; 
@@ -931,5 +1306,5 @@
     m_interLayerPredLayerIdc[ layer ] = pSrc->m_interLayerPredLayerIdc[ layer ]; 
   }
-  
+#if !H_MV5
   m_interLayerSamplePredOnlyFlag = pSrc->m_interLayerSamplePredOnlyFlag;
   m_altCollocatedIndicationFlag  = pSrc->m_altCollocatedIndicationFlag ;   
@@ -941,4 +1316,5 @@
     m_interLayerPredLayerIdc[layer] = pSrc->m_interLayerPredLayerIdc[layer];
   }
+#endif
 #endif
 #if H_3D_IC
@@ -1405,5 +1781,13 @@
 : m_VPSId                     (  0)
 , m_uiMaxTLayers              (  1)
+#if H_MV5
+#if H_MV
+, m_uiMaxLayersMinus1         (  0)
+#else
 , m_uiMaxLayers               (  1)
+#endif
+#else
+, m_uiMaxLayers               (  1)
+#endif
 , m_bTemporalIdNestingFlag    (false)
 , m_numHrdParameters          (  0)
@@ -1416,4 +1800,9 @@
 , m_hrdOpSetIdx               (NULL)
 , m_cprmsPresentFlag          (NULL)
+#if H_MV5
+#if H_MV
+, m_vpsVUI                 (  NULL )
+#endif
+#endif
 {
   for( Int i = 0; i < MAX_TLAYER; i++)
@@ -1459,9 +1848,16 @@
 
   m_avcBaseLayerFlag = false;
+#if H_MV5
+  m_vpsVuiOffset     = 0; 
+#endif
   m_splittingFlag    = false;
   
   for( Int i = 0; i < MAX_NUM_SCALABILITY_TYPES; i++ )
   {
+#if H_MV5
+    m_scalabilityMaskFlag[i] = false;
+#else
     m_scalabilityMask[i] = false;
+#endif
     m_dimensionIdLen [i]  = -1; 
   }
@@ -1489,5 +1885,13 @@
     m_layerIdInNuh      [i] = ( i == 0 ) ? 0 : -1; 
     m_numDirectRefLayers[i] = 0; 
+#if H_MV5
+    m_maxTidIlRefPicPlus1[i] = 7;
+    m_vpsRepFormatIdx    [i] = 0; 
+    m_repFormat          [i] = NULL; 
+    m_viewIdVal          [i] = 0; 
+#else
     m_maxTidIlRefPicPlus1[i] = -1; 
+#endif
+
 #if H_3D
     m_viewIndex         [i] = -1; 
@@ -1531,4 +1935,7 @@
 #endif
   }
+#if H_MV5
+  m_vpsVUI = new TComVPSVUI; 
+#endif
 #if H_3D
   for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
@@ -1556,4 +1963,26 @@
   if( m_hrdOpSetIdx      != NULL )     delete[] m_hrdOpSetIdx;
   if( m_cprmsPresentFlag != NULL )     delete[] m_cprmsPresentFlag;
+#if H_MV5
+#if H_MV
+  if ( m_vpsVUI          != NULL )     delete m_vpsVUI; 
+  for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
+  {
+    if (m_repFormat[ i ] != NULL )      delete m_repFormat[ i ];    
+#if H_3D_DIM_DLT
+    if ( m_iDepthValue2Idx[i] != 0 ) 
+    {
+       xFree( m_iDepthValue2Idx[i] );
+       m_iDepthValue2Idx[i] = 0; 
+    }
+
+    if ( m_iIdx2DepthValue[i] != 0 ) 
+    {
+      xFree( m_iIdx2DepthValue[i] );
+      m_iIdx2DepthValue[i] = 0; 
+    }
+#endif
+  }
+#endif
+#else
 #if H_3D_DIM_DLT
   for( Int i = 0; i < MAX_NUM_LAYERS; i++ )
@@ -1572,4 +2001,5 @@
     }
   }
+#endif
 #endif
 }
@@ -1642,5 +2072,9 @@
 Bool TComVPS::checkVPSExtensionSyntax()
 {
+#if H_MV5
+  for( Int layer = 1; layer <= getMaxLayersMinus1(); layer++ )
+#else
   for( Int layer = 1; layer < getMaxLayers(); layer++ )
+#endif
   {
     // check layer_id_in_nuh constraint
@@ -1658,15 +2092,31 @@
 {
   assert( scalType >= 0 && scalType <= MAX_NUM_SCALABILITY_TYPES ); 
+#if H_MV5
+  assert( scalType == MAX_NUM_SCALABILITY_TYPES || getScalabilityMaskFlag( scalType ) );
+#else
   assert( scalType == MAX_NUM_SCALABILITY_TYPES || getScalabilityMask( scalType ) );
-
+#endif
   Int scalIdx = 0; 
   for( Int curScalType = 0; curScalType < scalType; curScalType++ )
   {
+#if H_MV5
+    scalIdx += ( getScalabilityMaskFlag( curScalType ) ? 1 : 0 );
+#else
     scalIdx += ( getScalabilityMask( curScalType ) ? 1 : 0 );
+#endif
+
   }
 
   return scalIdx; 
 }
-
+#if H_MV5
+Void TComVPS::setScalabilityMaskFlag( UInt val )
+{
+  for ( Int scalType = 0; scalType < MAX_NUM_SCALABILITY_TYPES; scalType++ ) 
+  {
+    setScalabilityMaskFlag( scalType, ( val & (1 << scalType ) ) != 0 );
+  }
+}
+#else
 Void TComVPS::setScalabilityMask( UInt val )
 {
@@ -1675,4 +2125,56 @@
 }
 
+#endif
+
+#if H_MV5
+Void TComVPS::setRefLayers()
+{
+  for( Int i = 0; i  <= getMaxLayersMinus1(); i++ )
+  {
+    Int iNuhLId = getLayerIdInNuh( i ); 
+    m_numDirectRefLayers[ iNuhLId ] = 0; 
+    for( Int j = 0; j < i; j++ )
+    {
+      if( getDirectDependencyFlag(i , j) )
+      {
+        m_refLayerId[ iNuhLId ][m_numDirectRefLayers[ iNuhLId ]++ ] = getLayerIdInNuh( j );
+      }
+    }
+  }
+}
+
+Int TComVPS::getRefLayerId( Int layerIdInNuh, Int idx )
+{
+  assert( idx >= 0 && idx < m_numDirectRefLayers[layerIdInNuh] );     
+  Int refLayerIdInNuh = m_refLayerId[ layerIdInNuh ][ idx ];    
+  assert ( refLayerIdInNuh >= 0 ); 
+  return refLayerIdInNuh;
+}
+
+Int TComVPS::getScalabilityId( Int layerIdInVps, ScalabilityType scalType )
+{
+  return getScalabilityMaskFlag( scalType ) ? getDimensionId( layerIdInVps, scalTypeToScalIdx( scalType ) ) : 0;
+}
+
+#if H_3D
+Int TComVPS::getLayerIdInNuh( Int viewIndex, Bool depthFlag )
+{
+  Int foundLayerIdinNuh = -1; 
+
+  for (Int layerIdInVps = 0 ; layerIdInVps <= getMaxLayersMinus1(); layerIdInVps++ )
+  {
+    Int layerIdInNuh = getLayerIdInNuh( layerIdInVps ); 
+    if( ( getViewIndex( layerIdInNuh ) == viewIndex ) && ( getDepthId( layerIdInNuh ) == ( depthFlag ? 1 : 0 ) )  )
+    {
+      foundLayerIdinNuh = layerIdInNuh; 
+      break; 
+    }
+  }
+  assert( foundLayerIdinNuh != -1 ); 
+
+  return foundLayerIdinNuh;
+}
+#endif // H_3D
+#else
 Void TComVPS::setRefLayers()
 {
@@ -1793,4 +2295,6 @@
 }
 
+#endif // H_MV5
+
 
 Int TComVPS::xGetDimBitOffset( Int j )
@@ -1832,4 +2336,35 @@
   return numLayersInIdList;
 }
+#if H_MV5
+Int TComVPS::getNumViews()
+{
+  Int numViews = 1; 
+  for( Int i = 0; i <=  getMaxLayersMinus1(); i++ )
+  {
+    Int lId = getLayerIdInNuh( i ); 
+    if ( i > 0 && ( getViewIndex( lId ) != getScalabilityId( i - 1, VIEW_ORDER_INDEX ) ) )
+    {
+      numViews++; 
+    }    
+  }
+
+  return numViews;
+}
+
+Bool TComVPS::getInDirectDependencyFlag( Int depLayeridInVps, Int refLayeridInVps, Int depth /*= 0 */ )
+{
+  assert( depth < 65 ); 
+  Bool dependentFlag = getDirectDependencyFlag( depLayeridInVps, refLayeridInVps ); 
+
+  for( Int i = 0; i < depLayeridInVps && !dependentFlag; i++ )
+  {
+    if ( getDirectDependencyFlag( depLayeridInVps, i ) )
+    {
+      dependentFlag = getInDirectDependencyFlag( i, refLayeridInVps, depth++ ); 
+    }
+  }
+  return dependentFlag;
+}
+#endif
 #endif // H_MV
 
@@ -1882,6 +2417,14 @@
 , m_vuiParameters             ()
 #if H_MV
+#if H_MV5
+, m_pcVPS                     ( NULL )
+, m_spsInferScalingListFlag   ( false )
+, m_spsScalingListRefLayerId  ( 0 )
+, m_updateRepFormatFlag       ( true ) 
+, m_interViewMvVertConstraintFlag (false)
+#else
 , m_interViewMvVertConstraintFlag (false)
 , m_numIlpRestrictedRefLayers ( 0 )
+#endif
 #endif
 #if H_3D
@@ -1898,4 +2441,5 @@
   ::memset(m_ltRefPicPocLsbSps, 0, sizeof(m_ltRefPicPocLsbSps));
   ::memset(m_usedByCurrPicLtSPSFlag, 0, sizeof(m_usedByCurrPicLtSPSFlag));
+#if !H_MV5
 #if H_MV
   for (Int i = 0; i < MAX_NUM_LAYERS; i++ )
@@ -1905,4 +2449,5 @@
     m_minHorizontalCtuOffsetPlus1 [ i ] = 0;
   }
+#endif
 #endif
 }
@@ -2058,4 +2603,10 @@
 , m_listsModificationPresentFlag(  0)
 , m_numExtraSliceHeaderBits(0)
+#if H_MV5
+#if H_MV
+, m_ppsInferScalingListFlag(false)
+, m_ppsScalingListRefLayerId(0)
+#endif
+#endif
 {
   m_scalingList = new TComScalingList;
@@ -2077,4 +2628,57 @@
 }
 
+#if H_MV5
+#if H_MV
+Void TComSPS::inferRepFormat( TComVPS* vps, Int layerIdCurr )
+{
+  if ( layerIdCurr > 0 )
+  { 
+    TComRepFormat* repFormat = vps->getRepFormat( vps->getVpsRepFormatIdx( vps->getLayerIdInVps( layerIdCurr ) ) ); 
+    if ( !getUpdateRepFormatFlag() )
+    {        
+      setChromaFormatIdc( repFormat->getChromaFormatVpsIdc() );         
+      //// ToDo: add when supported: 
+      // setSeperateColourPlaneFlag( repFormat->getSeparateColourPlaneVpsFlag() ) ; 
+
+      setPicWidthInLumaSamples ( repFormat->getPicWidthVpsInLumaSamples()  ); 
+      setPicHeightInLumaSamples( repFormat->getPicHeightVpsInLumaSamples() ); 
+
+      setBitDepthY             ( repFormat->getBitDepthVpsLumaMinus8()   + 8 ); 
+      setQpBDOffsetY           ( (Int) (6*( getBitDepthY() - 8 )) );
+
+      setBitDepthC             ( repFormat->getBitDepthVpsChromaMinus8() + 8 ); 
+      setQpBDOffsetC           ( (Int) (6* ( getBitDepthC() -8 ) ) );
+    }
+    else
+    {
+      assert( getChromaFormatIdc()      <=  repFormat->getChromaFormatVpsIdc()         ); 
+      //// ToDo: add when supported: 
+      // assert( getSeperateColourPlaneFlag() <=  repFormat->getSeparateColourPlaneVpsFlag() ) ; 
+
+      assert( getPicWidthInLumaSamples()  <= repFormat->getPicWidthVpsInLumaSamples()    ); 
+      assert( getPicHeightInLumaSamples() <= repFormat->getPicHeightVpsInLumaSamples()   ); 
+
+      assert( getBitDepthY()              <= repFormat->getBitDepthVpsLumaMinus8()   + 8 );         
+      assert( getBitDepthC()              <= repFormat->getBitDepthVpsChromaMinus8() + 8 ); 
+    }
+  }
+
+  // Set conformance window
+  Int scal = TComSPS::getWinUnitX( getChromaFormatIdc() ) ;
+  getConformanceWindow().scaleOffsets( scal );
+  getVuiParameters()->getDefaultDisplayWindow().scaleOffsets( scal );
+}
+
+Void TComSPS::inferScalingList( TComSPS* spsSrc )
+{
+  if ( getSpsInferScalingListFlag() ) 
+  {
+    assert( spsSrc != NULL ); 
+    assert( !spsSrc->getSpsInferScalingListFlag() );             
+    getScalingList()->inferFrom( spsSrc->getScalingList() ); 
+  }
+}
+#endif
+#endif
 #if H_3D
 Void
@@ -2346,7 +2950,9 @@
 
 #if H_MV
-Void TComSlice::createAndApplyIvReferencePictureSet( TComPicLists* ivPicLists, std::vector<TComPic*>& refPicSetInterLayer )
-{
-  refPicSetInterLayer.clear(); 
+#if H_MV5
+Void TComSlice::createInterLayerReferencePictureSet( TComPicLists* ivPicLists, std::vector<TComPic*>& refPicSetInterLayer0, std::vector<TComPic*>& refPicSetInterLayer1 )
+{
+  refPicSetInterLayer0.clear(); 
+  refPicSetInterLayer1.clear(); 
 
   for( Int i = 0; i < getNumActiveRefLayerPics(); i++ ) 
@@ -2360,4 +2966,35 @@
     picRef->getSlice(0)->setReferenced( true );       
 
+    Int viewIdCur  = getVPS()->getViewId( getLayerId() ); 
+    Int viewIdZero = getVPS()->getViewId( 0 );
+    Int viewIdRef  = getVPS()->getViewId( layerIdRef ); 
+
+    if (  ( viewIdCur <= viewIdZero && viewIdCur <= viewIdRef ) || ( viewIdCur >= viewIdZero && viewIdCur >= viewIdRef ) )
+    {
+      refPicSetInterLayer0.push_back( picRef ); 
+    }
+    else
+    {
+      refPicSetInterLayer1.push_back( picRef ); 
+    }
+    // Consider to check here: 
+    // "If the current picture is a RADL picture, there shall be no entry in the RefPicSetInterLayer0 and RefPicSetInterLayer1 that is a RASL picture. "    
+  }
+}
+#else
+Void TComSlice::createAndApplyIvReferencePictureSet( TComPicLists* ivPicLists, std::vector<TComPic*>& refPicSetInterLayer )
+{
+  refPicSetInterLayer.clear(); 
+
+  for( Int i = 0; i < getNumActiveRefLayerPics(); i++ ) 
+  {
+    Int layerIdRef = getRefPicLayerId( i ); 
+    TComPic* picRef = ivPicLists->getPic( layerIdRef, getPOC() ) ; 
+    assert ( picRef != 0 ); 
+
+    picRef->getPicYuvRec()->extendPicBorder(); 
+    picRef->setIsLongTerm( true );        
+    picRef->getSlice(0)->setReferenced( true );       
+
     // Consider to check here: 
     // "If the current picture is a RADL picture, there shall be no entry in the RefPicSetInterLayer that is a RASL picture. "
@@ -2365,5 +3002,22 @@
   }
 }
-
+#endif
+
+#if H_MV5
+Void TComSlice::markIvRefPicsAsShortTerm( std::vector<TComPic*> refPicSetInterLayer0, std::vector<TComPic*> refPicSetInterLayer1 )
+{
+  // Mark as shortterm 
+  for ( Int i = 0; i < refPicSetInterLayer0.size(); i++ ) 
+  {
+    refPicSetInterLayer0[i]->setIsLongTerm( false ); 
+  }
+
+  for ( Int i = 0; i < refPicSetInterLayer1.size(); i++ ) 
+  {
+    refPicSetInterLayer1[i]->setIsLongTerm( false ); 
+  }
+
+}
+#else
 Void TComSlice::markIvRefPicsAsShortTerm( std::vector<TComPic*> refPicSetInterLayer )
 {
@@ -2375,4 +3029,5 @@
 }
 
+#endif
 Void TComSlice::markIvRefPicsAsUnused( TComPicLists* ivPicLists, std::vector<Int> targetDecLayerIdSet, TComVPS* vps, Int curLayerId, Int curPoc )
 {
@@ -2380,5 +3035,9 @@
   if (targetDecLayerIdSet.size() == 0 )    
   {
+#if H_MV5
+    for ( Int layerIdInVps = 0; layerIdInVps <= vps->getMaxLayersMinus1(); layerIdInVps++ )
+#else
     for ( Int layerIdInVps = 0; layerIdInVps < vps->getMaxLayers(); layerIdInVps++ )
+#endif
     {
       targetDecLayerIdSet.push_back( vps->getLayerIdInNuh( layerIdInVps ) ); 
@@ -2391,5 +3050,7 @@
   {
     if ( targetDecLayerIdSet[ latestDecIdx ] == curLayerId )
+    {
       break; 
+  }        
   }        
 
@@ -2407,11 +3068,22 @@
           if ( vps->nuhLayerIdIncluded( targetDecLayerIdSet[ j ] ) )
           {
+#if H_MV5
+            for( Int k = 0; k < vpsSlice->getNumDirectRefLayers( targetDecLayerIdSet[ j ] ); k++ )
+            {
+              if ( targetDecLayerIdSet[ i ] == vpsSlice->getRefLayerId( targetDecLayerIdSet[ j ],  k  ) )
+#else
             Int targetDecLayerIdinVPS = vpsSlice->getLayerIdInVps( targetDecLayerIdSet[ j ] ); 
             for( Int k = 0; k < vpsSlice->getNumDirectRefLayers( targetDecLayerIdinVPS ); k++ )
+            {
               if ( targetDecLayerIdSet[ i ] == vpsSlice->getRefLayerId( targetDecLayerIdinVPS,  k  ) )
+#endif
+              {
                 remainingInterLayerReferencesFlag = true;
           }
         }
+          }
+        }
         if( !remainingInterLayerReferencesFlag )
+        {
           pcPic->getSlice(0)->setReferenced( false );                   
       }
@@ -2419,6 +3091,11 @@
   }
 }
-
+}
+
+#if H_MV5
+Void TComSlice::printRefPicList()
+#else
 Void TComSlice::xPrintRefPicList()
+#endif
 {  
   for ( Int li = 0; li < 2; li++)
@@ -2433,4 +3110,5 @@
   }
 }
+#if !H_MV5
 Int TComSlice::xCeilLog2( Int val )
 {
@@ -2440,4 +3118,5 @@
   return ceilLog2;
 }
+#endif
 
 Void TComSlice::markCurrPic( TComPic* currPic )
@@ -2454,4 +3133,30 @@
 }
 
+#if H_MV5
+Void TComSlice::setRefPicSetInterLayer( std::vector<TComPic*>* refPicSetInterLayer0, std::vector<TComPic*>* refPicSetInterLayer1 )
+{
+  m_refPicSetInterLayer0 = refPicSetInterLayer0; 
+  m_refPicSetInterLayer1 = refPicSetInterLayer1; 
+}
+
+TComPic* TComSlice::getPicFromRefPicSetInterLayer(Int setIdc, Int layerId )
+{
+  assert ( setIdc == 0 || setIdc == 1);   
+  std::vector<TComPic*>* refPicSetInterLayer = ( setIdc == 0 ? m_refPicSetInterLayer0 : m_refPicSetInterLayer1);   
+  assert( refPicSetInterLayer != 0 ); 
+  
+  TComPic* pcPic = NULL; 
+  for ( Int i = 0; i < (*refPicSetInterLayer).size(); i++ )
+  {
+    if ((*refPicSetInterLayer)[ i ]->getLayerId() == layerId )
+    {
+      pcPic = (*refPicSetInterLayer)[ i ]; 
+    }
+  }
+
+  assert(pcPic != NULL); 
+  return pcPic;
+}
+#else
 Void TComSlice::setRefPicSetInterLayer( std::vector<TComPic*>* refPicSetInterLayer )
 {
@@ -2474,9 +3179,24 @@
   return pcPic;
 }
-
+#endif
 Int TComSlice::getNumActiveRefLayerPics()
 {
   Int numActiveRefLayerPics; 
 
+#if H_MV5
+  if( getLayerId() == 0 || getVPS()->getNumDirectRefLayers( getLayerId() ) ==  0 )
+  {
+    numActiveRefLayerPics = 0; 
+  }
+  else if (getVPS()->getAllRefLayersActiveFlag() )
+  {
+    numActiveRefLayerPics = getVPS()->getNumDirectRefLayers( getLayerId() );
+  }
+  else if ( !getInterLayerPredEnabledFlag() )
+  {
+    numActiveRefLayerPics = 0; 
+  }
+  else if( getVPS()->getMaxOneActiveRefLayerFlag() || getVPS()->getNumDirectRefLayers( getLayerId() ) == 1 )
+#else
   if( getLayerId() == 0 || getVPS()->getNumDirectRefLayers( getLayerIdInVps() ) ==  0 || !getInterLayerPredEnabledFlag() )
   {
@@ -2484,4 +3204,5 @@
   }
   else if( getVPS()->getMaxOneActiveRefLayerFlag() || getVPS()->getNumDirectRefLayers( getLayerIdInVps() ) == 1 )
+#endif
   {
     numActiveRefLayerPics = 1; 
@@ -2496,7 +3217,12 @@
 Int TComSlice::getRefPicLayerId( Int i )
 {
+#if H_MV5
+  return getVPS()->getRefLayerId( getLayerId(), getInterLayerPredLayerIdc( i ) );
+#else
   return getVPS()->getRefLayerId( getLayerIdInVps(), getInterLayerPredLayerIdc( i ) );
-}
-
+#endif
+}
+
+#if !H_MV5
 Void TComSlice::setActiveMotionPredRefLayers()
 {
@@ -2527,4 +3253,5 @@
   return interRefEnabledInRPLFlag;
 }
+#endif
 #if H_3D_ARP
 Void TComSlice::setARPStepNum()                                  
@@ -2804,4 +3531,20 @@
 }
 
+#if H_MV5
+#if H_MV
+Void TComScalingList::inferFrom( TComScalingList* srcScLi )
+{
+  for(Int sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
+  {
+    for(Int listId = 0; listId <  g_scalingListNum[sizeId]; listId++)
+    {
+      setRefMatrixId  (sizeId,listId, srcScLi->getRefMatrixId  (sizeId,listId));
+      setScalingListDC(sizeId,listId, srcScLi->getScalingListDC(sizeId,listId));          
+      ::memcpy(getScalingListAddress(sizeId, listId),srcScLi->getScalingListAddress(sizeId, listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
+    }
+  }
+}
+#endif
+#endif
 /** initialization process of quantization matrix array
  */
@@ -2893,7 +3636,22 @@
 , m_ppsMap(MAX_NUM_PPS)
 , m_activeVPSId(-1)
+#if H_MV5
+#if !H_MV
 , m_activeSPSId(-1)
 , m_activePPSId(-1)
 {
+#else
+{
+  for (Int i = 0; i < MAX_NUM_LAYERS; i++ )
+  {
+    m_activeSPSId[ i ] = -1; 
+    m_activePPSId[ i ] = -1; 
+  }
+#endif
+#else
+, m_activeSPSId(-1)
+, m_activePPSId(-1)
+{
+#endif
 }
 
@@ -2905,5 +3663,13 @@
 //! activate a SPS from a active parameter sets SEI message
 //! \returns true, if activation is successful
+#if H_MV5
+#if H_MV
+Bool ParameterSetManager::activateSPSWithSEI(Int spsId, Int layerId )
+#else
 Bool ParameterSetManager::activateSPSWithSEI(Int spsId)
+#endif
+#else
+Bool ParameterSetManager::activateSPSWithSEI(Int spsId)
+#endif
 {
   TComSPS *sps = m_spsMap.getPS(spsId);
@@ -2914,5 +3680,13 @@
     {
       m_activeVPSId = vpsId;
+#if !H_MV5
       m_activeSPSId = spsId;
+#else
+#if H_MV
+      m_activeSPSId[ layerId ] = spsId;
+#else
+      m_activeSPSId = spsId;
+#endif
+#endif
       return true;
     }
@@ -2931,4 +3705,46 @@
 //! activate a PPS and depending on isIDR parameter also SPS and VPS
 //! \returns true, if activation is successful
+#if H_MV5
+#if H_MV
+Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP, Int layerId )
+#else
+Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP)
+#endif
+{
+  TComPPS *pps = m_ppsMap.getPS(ppsId);
+  if (pps)
+  {
+    Int spsId = pps->getSPSId();
+#if H_MV
+    if (!isIRAP && (spsId != m_activeSPSId[ layerId ]))
+#else
+    if (!isIRAP && (spsId != m_activeSPSId))
+#endif
+    {
+      printf("Warning: tried to activate PPS referring to a inactive SPS at non-IRAP.");
+      return false;
+    }
+
+    TComSPS *sps = m_spsMap.getPS(spsId);
+    if (sps)
+    {
+      Int vpsId = sps->getVPSId();
+      if (!isIRAP && (vpsId != m_activeVPSId))
+      {
+        printf("Warning: tried to activate PPS referring to a inactive VPS at non-IRAP.");
+        return false;
+      }
+      if (m_vpsMap.getPS(vpsId))
+      {
+#if H_MV
+        m_activePPSId[ layerId ] = ppsId;
+        m_activeVPSId = vpsId;
+        m_activeSPSId[ layerId ] = spsId;
+#else
+        m_activePPSId = ppsId;
+        m_activeVPSId = vpsId;
+        m_activeSPSId = spsId;
+#endif
+#else
 Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP)
 {
@@ -2960,4 +3776,5 @@
         m_activeVPSId = vpsId;
         m_activeSPSId = spsId;
+#endif
         return true;
       }
@@ -3021,2 +3838,37 @@
 #endif
 //! \}
+
+#if H_MV5
+#if H_MV
+TComVPSVUI::TComVPSVUI()
+{
+  m_bitRatePresentVpsFlag = false;
+  m_picRatePresentVpsFlag = false;
+  for ( Int i = 0; i < MAX_VPS_OP_SETS_PLUS1; i++)
+  {    
+    for ( Int j = 0; j < MAX_TLAYER; j++)
+    {    
+      m_bitRatePresentFlag          [i][j] = false;
+      m_picRatePresentFlag          [i][j] = false;
+      m_avgBitRate                  [i][j] = -1;
+      m_maxBitRate                  [i][j] = -1;
+      m_constantPicRateIdc          [i][j] = -1;
+      m_avgPicRate                  [i][j] = -1;
+    }
+  }
+
+  m_ilpRestrictedRefLayersFlag = false;
+
+  for ( Int i = 0; i < MAX_NUM_LAYERS; i++)
+  {          
+    for ( Int j = 0; j < MAX_NUM_LAYERS; j++)
+    {    
+      m_tileBoundariesAlignedFlag   [i][j] = false;
+      m_minSpatialSegmentOffsetPlus1[i][j] = 0;
+      m_ctuBasedOffsetEnabledFlag   [i][j] = false;
+      m_minHorizontalCtuOffsetPlus1 [i][j] = -1;
+    }
+  }
+}
+#endif
+#endif
Index: branches/HTM-8.0-dev0/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- branches/HTM-8.0-dev0/source/Lib/TLibCommon/TComSlice.h	(revision 617)
+++ branches/HTM-8.0-dev0/source/Lib/TLibCommon/TComSlice.h	(revision 618)
@@ -169,4 +169,9 @@
   Void     processRefMatrix               (UInt sizeId, UInt listId , UInt refListId );
   Bool     xParseScalingList              (Char* pchFile);
+#if H_MV5
+#if H_MV
+  Void     inferFrom                      ( TComScalingList* srcScLi );
+#endif
+#endif
 
 private:
@@ -402,4 +407,101 @@
 };
 
+#if H_MV5
+#if H_MV
+class TComVPSVUI
+{
+private:
+  Bool m_bitRatePresentVpsFlag;
+  Bool m_picRatePresentVpsFlag;
+  Bool m_bitRatePresentFlag          [MAX_VPS_OP_SETS_PLUS1][MAX_TLAYER];
+  Bool m_picRatePresentFlag          [MAX_VPS_OP_SETS_PLUS1][MAX_TLAYER];
+  Int  m_avgBitRate                  [MAX_VPS_OP_SETS_PLUS1][MAX_TLAYER];
+  Int  m_maxBitRate                  [MAX_VPS_OP_SETS_PLUS1][MAX_TLAYER];
+  Int  m_constantPicRateIdc          [MAX_VPS_OP_SETS_PLUS1][MAX_TLAYER];
+  Int  m_avgPicRate                  [MAX_VPS_OP_SETS_PLUS1][MAX_TLAYER];
+  Bool m_tileBoundariesAlignedFlag   [MAX_NUM_LAYERS][MAX_NUM_LAYERS];
+  Bool m_ilpRestrictedRefLayersFlag;
+  Int  m_minSpatialSegmentOffsetPlus1[MAX_NUM_LAYERS][MAX_NUM_LAYERS];
+  Bool m_ctuBasedOffsetEnabledFlag   [MAX_NUM_LAYERS][MAX_NUM_LAYERS];
+  Int  m_minHorizontalCtuOffsetPlus1 [MAX_NUM_LAYERS][MAX_NUM_LAYERS];
+
+public: 
+  TComVPSVUI();;
+
+  Void setBitRatePresentVpsFlag( Bool flag ) { m_bitRatePresentVpsFlag = flag; } 
+  Bool getBitRatePresentVpsFlag(  ) { return m_bitRatePresentVpsFlag; } 
+
+  Void setPicRatePresentVpsFlag( Bool flag ) { m_picRatePresentVpsFlag = flag; } 
+  Bool getPicRatePresentVpsFlag(  ) { return m_picRatePresentVpsFlag; } 
+
+  Void setBitRatePresentFlag( Int i, Int j, Bool flag ) { m_bitRatePresentFlag[i][j] = flag; } 
+  Bool getBitRatePresentFlag( Int i, Int j ) { return m_bitRatePresentFlag[i][j]; } 
+
+  Void setPicRatePresentFlag( Int i, Int j, Bool flag ) { m_picRatePresentFlag[i][j] = flag; } 
+  Bool getPicRatePresentFlag( Int i, Int j ) { return m_picRatePresentFlag[i][j]; } 
+
+  Void setAvgBitRate( Int i, Int j, Int  val ) { m_avgBitRate[i][j] = val; } 
+  Int  getAvgBitRate( Int i, Int j ) { return m_avgBitRate[i][j]; } 
+
+  Void setMaxBitRate( Int i, Int j, Int  val ) { m_maxBitRate[i][j] = val; } 
+  Int  getMaxBitRate( Int i, Int j ) { return m_maxBitRate[i][j]; } 
+
+  Void setConstantPicRateIdc( Int i, Int j, Int  val ) { m_constantPicRateIdc[i][j] = val; } 
+  Int  getConstantPicRateIdc( Int i, Int j ) { return m_constantPicRateIdc[i][j]; } 
+
+  Void setAvgPicRate( Int i, Int j, Int  val ) { m_avgPicRate[i][j] = val; } 
+  Int  getAvgPicRate( Int i, Int j ) { return m_avgPicRate[i][j]; } 
+
+  Void setTileBoundariesAlignedFlag( Int i, Int j, Bool flag ) { m_tileBoundariesAlignedFlag[i][j] = flag; } 
+  Bool getTileBoundariesAlignedFlag( Int i, Int j ) { return m_tileBoundariesAlignedFlag[i][j]; } 
+
+  Void setIlpRestrictedRefLayersFlag( Bool flag ) { m_ilpRestrictedRefLayersFlag = flag; } 
+  Bool getIlpRestrictedRefLayersFlag(  ) { return m_ilpRestrictedRefLayersFlag; } 
+
+  Void setMinSpatialSegmentOffsetPlus1( Int i, Int j, Int  val ) { m_minSpatialSegmentOffsetPlus1[i][j] = val; } 
+  Int  getMinSpatialSegmentOffsetPlus1( Int i, Int j ) { return m_minSpatialSegmentOffsetPlus1[i][j]; } 
+
+  Void setCtuBasedOffsetEnabledFlag( Int i, Int j, Bool flag ) { m_ctuBasedOffsetEnabledFlag[i][j] = flag; } 
+  Bool getCtuBasedOffsetEnabledFlag( Int i, Int j ) { return m_ctuBasedOffsetEnabledFlag[i][j]; } 
+
+  Void setMinHorizontalCtuOffsetPlus1( Int i, Int j, Int  val ) { m_minHorizontalCtuOffsetPlus1[i][j] = val; } 
+  Int  getMinHorizontalCtuOffsetPlus1( Int i, Int j ) { return m_minHorizontalCtuOffsetPlus1[i][j]; } 
+
+};
+
+class TComRepFormat
+{
+private:
+  Int  m_chromaFormatVpsIdc;
+  Bool m_separateColourPlaneVpsFlag;
+  Int  m_picWidthVpsInLumaSamples;
+  Int  m_picHeightVpsInLumaSamples;
+  Int  m_bitDepthVpsLumaMinus8;
+  Int  m_bitDepthVpsChromaMinus8;
+
+public: 
+  TComRepFormat() { };  
+
+  Void setChromaFormatVpsIdc( Int  val ) { m_chromaFormatVpsIdc = val; } 
+  Int  getChromaFormatVpsIdc(  ) { return m_chromaFormatVpsIdc; } 
+
+  Void setSeparateColourPlaneVpsFlag( Bool flag ) { m_separateColourPlaneVpsFlag = flag; } 
+  Bool getSeparateColourPlaneVpsFlag(  ) { return m_separateColourPlaneVpsFlag; } 
+
+  Void setPicWidthVpsInLumaSamples( Int  val ) { m_picWidthVpsInLumaSamples = val; } 
+  Int  getPicWidthVpsInLumaSamples(  ) { return m_picWidthVpsInLumaSamples; } 
+
+  Void setPicHeightVpsInLumaSamples( Int  val ) { m_picHeightVpsInLumaSamples = val; } 
+  Int  getPicHeightVpsInLumaSamples(  ) { return m_picHeightVpsInLumaSamples; } 
+
+  Void setBitDepthVpsLumaMinus8( Int  val ) { m_bitDepthVpsLumaMinus8 = val; } 
+  Int  getBitDepthVpsLumaMinus8(  ) { return m_bitDepthVpsLumaMinus8; } 
+
+  Void setBitDepthVpsChromaMinus8( Int  val ) { m_bitDepthVpsChromaMinus8 = val; } 
+  Int  getBitDepthVpsChromaMinus8(  ) { return m_bitDepthVpsChromaMinus8; } 
+};
+#endif
+#endif
+
 class TComVPS
 {
@@ -407,5 +509,14 @@
   Int         m_VPSId;
   UInt        m_uiMaxTLayers;
+
+#if H_MV5
+#if H_MV
+  UInt        m_uiMaxLayersMinus1;
+#else
   UInt        m_uiMaxLayers;
+#endif
+#else
+  UInt        m_uiMaxLayers;
+#endif
   Bool        m_bTemporalIdNestingFlag;
   
@@ -440,12 +551,29 @@
   /// VPS EXTENSION SYNTAX ELEMENTS
   Bool        m_avcBaseLayerFlag;
+#if H_MV5
+  Int         m_vpsVuiOffset;
+#endif
   Bool        m_splittingFlag;
+#if H_MV5
+  Bool        m_scalabilityMaskFlag          [MAX_NUM_SCALABILITY_TYPES];
+#else
   Bool        m_scalabilityMask          [MAX_NUM_SCALABILITY_TYPES];
+#endif
   Int         m_dimensionIdLen           [MAX_NUM_SCALABILITY_TYPES];
   Bool        m_vpsNuhLayerIdPresentFlag;
   Int         m_layerIdInNuh             [MAX_NUM_LAYER_IDS];
   Int         m_dimensionId              [MAX_NUM_LAYER_IDS][MAX_NUM_SCALABILITY_TYPES];  
+#if H_MV5
+  Int         m_viewIdLenMinus1;
+  Int         m_viewIdVal                [MAX_NUM_LAYERS];
+#endif
   Bool        m_directDependencyFlag     [MAX_NUM_LAYER_IDS][MAX_NUM_LAYER_IDS];
+#if H_MV5
+  Bool        m_maxTidRefPresentFlag;
+#endif
   Int         m_maxTidIlRefPicPlus1      [MAX_NUM_LAYERS];
+#if H_MV5
+  Bool        m_allRefLayersActiveFlag;
+#endif
   Int         m_vpsNumberLayerSetsMinus1; 
   Int         m_vpsNumProfileTierLevelMinus1;   
@@ -458,6 +586,19 @@
   Bool        m_outputLayerFlag          [MAX_VPS_OUTPUTLAYER_SETS][MAX_VPS_NUH_LAYER_ID_PLUS1];
   Int         m_profileLevelTierIdx      [MAX_VPS_OUTPUTLAYER_SETS ];
+#if H_MV5
+  Bool        m_repFormatIdxPresentFlag;
+  Int         m_vpsNumRepFormatsMinus1;
+  Int         m_vpsRepFormatIdx          [MAX_NUM_LAYERS];
+  TComRepFormat* m_repFormat             [MAX_NUM_LAYERS]; 
+#endif
   Bool        m_maxOneActiveRefLayerFlag;       
+#if H_MV5
+  Bool        m_crossLayerIrapAlignedFlag;
+#endif
   Int         m_directDepTypeLenMinus2;         
+#if H_MV5
+  Bool        m_vpsVuiPresentFlag;
+  TComVPSVUI* m_vpsVUI; 
+#endif
   Int         m_directDependencyType     [MAX_NUM_LAYERS] [MAX_NUM_LAYERS];
 
@@ -475,4 +616,7 @@
   Bool        m_motionPredEnabledFlag    [MAX_NUM_LAYERS][MAX_NUM_LAYERS];
   Int         m_motionPredRefLayerId     [MAX_NUM_LAYERS][MAX_NUM_LAYERS];
+#if H_MV5
+  Int         m_viewIndex                [MAX_NUM_LAYERS   ];
+#else
 #if H_3D
   Int         m_viewIndex                [MAX_NUM_LAYERS   ];
@@ -480,6 +624,8 @@
 
   Int         xCeilLog2       ( Int val );
+#endif
   Int         xGetDimBitOffset( Int j );
   
+  // VPS EXTENSION 2 SYNTAX ELEMENTS
 #if H_3D_ARP
   UInt        m_uiUseAdvResPred          [MAX_NUM_LAYERS   ];
@@ -535,6 +681,16 @@
   Void    setMaxTLayers  (UInt t)             { m_uiMaxTLayers = t; }
   
+#if H_MV5
+#if H_MV    
+  UInt    getMaxLayersMinus1()                { return m_uiMaxLayersMinus1;  }; 
+  Void    setMaxLayersMinus1(UInt l)          { m_uiMaxLayersMinus1 = l; }
+#else
   UInt    getMaxLayers   ()                   { return m_uiMaxLayers;   }
   Void    setMaxLayers   (UInt l)             { m_uiMaxLayers = l; }
+#endif
+#else
+  UInt    getMaxLayers   ()                   { return m_uiMaxLayers;   }
+  Void    setMaxLayers   (UInt l)             { m_uiMaxLayers = l; }
+#endif
 
   Bool    getTemporalNestingFlag   ()         { return m_bTemporalIdNestingFlag;   }
@@ -579,12 +735,22 @@
   Bool    getAvcBaseLayerFlag()                                            { return m_avcBaseLayerFlag; } 
 
+#if H_MV5
+  Void    setVpsVuiOffset( Int  val )                                      { m_vpsVuiOffset = val; } 
+  Int     getVpsVuiOffset(  )                                              { return m_vpsVuiOffset; } 
+#endif
+
   Void    setSplittingFlag( Bool val )                                     { m_splittingFlag = val;  }
   Bool    getSplittingFlag()                                               { return m_splittingFlag; }
 
+#if H_MV5
+  Void    setScalabilityMaskFlag( UInt val );
+  Void    setScalabilityMaskFlag( Int scalType, Bool val )                     { m_scalabilityMaskFlag[scalType] = val;  }
+  Bool    getScalabilityMaskFlag( Int scalType )                               { return m_scalabilityMaskFlag[scalType]; }
+#else
   Void    setScalabilityMask( UInt val );
 
   Void    setScalabilityMask( Int scalType, Bool val )              { m_scalabilityMask[scalType] = val;  }
   Bool    getScalabilityMask( Int scalType )                        { return m_scalabilityMask[scalType]; }
-
+#endif
   Int     getNumScalabilityTypes( );
 
@@ -603,10 +769,24 @@
   Int     getDimensionId( Int layerIdInVps, Int scalIdx )                  { return m_dimensionId[layerIdInVps][scalIdx]; }
 
+#if H_MV5
+  Void    setViewIdLenMinus1( Int  val )                                   { m_viewIdLenMinus1 = val; } 
+  Int     getViewIdLenMinus1(  )                                           { return m_viewIdLenMinus1; } 
+
+  Void    setViewIdVal( Int viewOrderIndex, Int  val )                     { m_viewIdVal[viewOrderIndex] = val; } 
+  Int     getViewIdVal( Int viewOrderIndex )                               { return m_viewIdVal[viewOrderIndex]; } 
+#endif
   Void    setDirectDependencyFlag( Int depLayeridInVps, Int refLayeridInVps, Bool val ) { m_directDependencyFlag[depLayeridInVps][refLayeridInVps] = val;  }
   Bool    getDirectDependencyFlag( Int depLayeridInVps, Int refLayeridInVps )           { return m_directDependencyFlag[depLayeridInVps][refLayeridInVps]; }
 
+#if H_MV5
+  Void    setMaxTidRefPresentFlag( Bool flag )                             { m_maxTidRefPresentFlag = flag; } 
+  Bool    getMaxTidRefPresentFlag(  )                                      { return m_maxTidRefPresentFlag; } 
+#endif
   Void    setMaxTidIlRefPicPlus1( Int layerIdInVps, Int val )              { m_maxTidIlRefPicPlus1[ layerIdInVps ] = val;  } 
   Int     getMaxTidIlRefPicPlus1( Int layerIdInVps )                       { return m_maxTidIlRefPicPlus1[ layerIdInVps ]; } 
-  
+#if H_MV5
+  Void    setAllRefLayersActiveFlag( Bool flag )                           { m_allRefLayersActiveFlag = flag; } 
+  Bool    getAllRefLayersActiveFlag(  )                                    { return m_allRefLayersActiveFlag; } 
+#endif
   Void    setVpsNumberLayerSetsMinus1( Int val )                           { m_vpsNumberLayerSetsMinus1 = val;  } 
   Int     getVpsNumberLayerSetsMinus1( )                                   { return m_vpsNumberLayerSetsMinus1; } 
@@ -639,7 +819,23 @@
   Int     getProfileLevelTierIdx( Int outLayerSetIdx )                     { return m_profileLevelTierIdx[ outLayerSetIdx ]; } 
 
+#if H_MV5
+  Void    setRepFormatIdxPresentFlag( Bool flag )                          { m_repFormatIdxPresentFlag = flag; } 
+  Bool    getRepFormatIdxPresentFlag(  )                                   { return m_repFormatIdxPresentFlag; } 
+
+  Void    setVpsNumRepFormatsMinus1( Int  val )                            { m_vpsNumRepFormatsMinus1 = val; } 
+  Int     getVpsNumRepFormatsMinus1(  )                                    { return m_vpsNumRepFormatsMinus1; } 
+
+  Void    setVpsRepFormatIdx( Int i, Int  val )                            { m_vpsRepFormatIdx[i] = val; } 
+  Int     getVpsRepFormatIdx( Int i )                                      { return m_vpsRepFormatIdx[i]; } 
+
+  Void    setRepFormat( Int i, TComRepFormat* val )                        { m_repFormat[i] = val;  }
+  TComRepFormat* getRepFormat( Int i )                                     { return m_repFormat[i]; }
+#endif
   Void    setMaxOneActiveRefLayerFlag( Bool flag)                          { m_maxOneActiveRefLayerFlag = flag; } 
   Bool    getMaxOneActiveRefLayerFlag( )                                   { return m_maxOneActiveRefLayerFlag; } 
-
+#if H_MV5
+  Void    setCrossLayerIrapAlignedFlag( Bool flag )                        { m_crossLayerIrapAlignedFlag = flag; } 
+  Bool    getCrossLayerIrapAlignedFlag(  )                                 { return m_crossLayerIrapAlignedFlag; } 
+#endif
   Void    setDirectDepTypeLenMinus2( Int val)                              { m_directDepTypeLenMinus2 = val; } 
   Int     getDirectDepTypeLenMinus2( )                                     { return m_directDepTypeLenMinus2; } 
@@ -647,6 +843,10 @@
   Void    setDirectDependencyType( Int depLayeridInVps, Int refLayeridInVps, Int val) { m_directDependencyType[ depLayeridInVps ][ refLayeridInVps ] = val; } 
   Int     getDirectDependencyType( Int depLayeridInVps, Int refLayeridInVps)   { return m_directDependencyType[ depLayeridInVps ][ refLayeridInVps ]; } 
-
-
+#if H_MV5  
+  Void    setVpsVuiPresentFlag( Bool flag )                                { m_vpsVuiPresentFlag = flag; } 
+  Bool    getVpsVuiPresentFlag(  )                                         { return m_vpsVuiPresentFlag; } 
+
+  TComVPSVUI* getVPSVUI(  )                                                { return m_vpsVUI;  }
+#endif
   // VPS EXTENSION SEMANTICS VARIABLES
   Void    setLayerIdInVps( Int layerIdInNuh, Int val )                     { m_layerIdInVps[layerIdInNuh] = val;  }
@@ -654,8 +854,19 @@
 
   Int     getScalabilityId ( Int layerIdInVps, ScalabilityType scalType );
+#if H_MV5
+  Int     getViewId        ( Int layerIdInNuh )                            { return m_viewIdVal[ getViewIndex( getLayerIdInVps( layerIdInNuh) )]; }
+#else
   Int     getViewId  ( Int layerIdInVps )                                  { return getScalabilityId( layerIdInVps, VIEW_ID  ); }
 
+#endif
   Void    setRefLayers(); 
 
+#if H_MV5
+  Int     getViewIndex    ( Int layerIdInNuh )                             { return getScalabilityId( getLayerIdInVps(layerIdInNuh), VIEW_ORDER_INDEX  ); }    
+  Int     getNumViews();
+
+  Int     getNumDirectRefLayers( Int layerIdInNuh )                        { return m_numDirectRefLayers[ layerIdInNuh ];  };                               
+  Int     getRefLayerId        ( Int layerIdInNuh, Int idx );; 
+#else
   Int     getNumDirectRefLayers( Int layerIdInVps )          { return m_numDirectRefLayers[ layerIdInVps ];  };                               
   Int     getRefLayerId        ( Int layerIdInVps, Int idx );; 
@@ -668,9 +879,14 @@
   Bool    getMotionPredEnabledFlag ( Int layerIdInVps, Int idx ) { return m_motionPredEnabledFlag [layerIdInVps][idx]; } 
   Int     getMotionPredRefLayerId  ( Int layerIdInVps, Int idx ) { return m_motionPredRefLayerId  [layerIdInVps][idx]; } 
-
+#endif  
   Bool    checkVPSExtensionSyntax(); 
   Int     scalTypeToScalIdx   ( ScalabilityType scalType );
 
+  #if H_MV5
+Int     getProfileLevelTierIdxLen()                                      { return gCeilLog2( getVpsNumProfileTierLevelMinus1() + 1 ); };       
+#else
   Int     getProfileLevelTierIdxLen() { return xCeilLog2( getVpsNumProfileTierLevelMinus1() + 1 ); };       
+#endif
+
   Int     getNumLayersInIdList              ( Int lsIdx );; 
 
@@ -679,8 +895,17 @@
   Int     inferLastDimsionIdLenMinus1();
 
+#if H_MV5
+  // helpers
+  Bool    getInDirectDependencyFlag( Int depLayeridInVps, Int refLayeridInVps, Int depth = 0 );
+#endif
+  /// VPS EXTENSION 2 SYNTAX ELEMENTS
 #if H_3D  
+#if H_MV5
+  Int     getDepthId      ( Int layerIdInNuh)                             { return getScalabilityId( getLayerIdInVps(layerIdInNuh), DEPTH_ID ); }
+#else
   Void    initViewIndex(); 
   Int     getViewIndex    ( Int layerIdInVps )                             { return m_viewIndex[ layerIdInVps ]; }    
   Int     getDepthId      ( Int layerIdInVps )                             { return getScalabilityId( layerIdInVps, DEPTH_ID ); }
+#endif
   Int     getLayerIdInNuh( Int viewIndex, Bool depthFlag );   
 
@@ -735,4 +960,9 @@
   Int           m_winTopOffset;
   Int           m_winBottomOffset;
+#if H_MV5
+#if H_MV
+  Bool          m_scaledFlag; 
+#endif
+#endif
 public:
   Window()
@@ -742,4 +972,9 @@
   , m_winTopOffset      (0)
   , m_winBottomOffset   (0)
+#if H_MV5
+#if H_MV
+  , m_scaledFlag(true)
+#endif
+#endif
   { }
 
@@ -755,4 +990,21 @@
   Void          setWindowBottomOffset(Int val)    { m_winBottomOffset = val; m_enabledFlag = true; }
 
+#if H_MV5
+#if H_MV
+  Void          setScaledFlag(Bool flag)          { m_scaledFlag = flag;  } 
+  Bool          getScaledFlag() const             { return m_scaledFlag;  } 
+  Void          scaleOffsets( Int scal )          
+  {
+    if (! m_scaledFlag )
+    {
+      m_scaledFlag         = true; 
+      m_winLeftOffset     *= scal; 
+      m_winRightOffset    *= scal; 
+      m_winTopOffset      *= scal; 
+      m_winBottomOffset   *= scal; 
+    }
+  }
+#endif
+#endif
   Void          setWindow(Int offsetLeft, Int offsetLRight, Int offsetLTop, Int offsetLBottom)
   {
@@ -802,6 +1054,8 @@
   TComHRD m_hrdParameters;
   TimingInfo m_timingInfo;
+#if !H_MV5
 #if H_MV
   Bool m_tileBoundariesAlignedFlag;
+#endif
 #endif
 
@@ -837,6 +1091,8 @@
     ,m_log2MaxMvLengthHorizontal(15)
     ,m_log2MaxMvLengthVertical(15)
+#if !H_MV5
 #if H_MV
     ,m_tileBoundariesAlignedFlag(true)
+#endif
 #endif
   {}
@@ -935,8 +1191,11 @@
   TComHRD* getHrdParameters                 ()             { return &m_hrdParameters; }
   TimingInfo* getTimingInfo() { return &m_timingInfo; }
+#if !H_MV5
 #if H_MV
 Bool getTileBoundariesAlignedFlag(  ) { return m_tileBoundariesAlignedFlag; } 
   Void setTileBoundariesAlignedFlag( Bool flag ) { m_tileBoundariesAlignedFlag = flag; } 
 #endif
+#endif
+
 };
 
@@ -1022,9 +1281,19 @@
   TComPTL     m_pcPTL;
 #if H_MV
+#if H_MV5
+  TComVPS*    m_pcVPS; 
+  // SPS 
+  Bool        m_spsInferScalingListFlag;
+  Int         m_spsScalingListRefLayerId;
+  Bool        m_updateRepFormatFlag;
+#endif
+  // SPS Extension 
   Bool        m_interViewMvVertConstraintFlag;
+#if !H_MV5
   Int         m_numIlpRestrictedRefLayers        ;
   Int         m_minSpatialSegmentOffsetPlus1[MAX_NUM_LAYERS];
   Bool        m_ctuBasedOffsetEnabledFlag   [MAX_NUM_LAYERS];
   Int         m_minHorizontalCtuOffsetPlus1 [MAX_NUM_LAYERS];
+#endif
 #endif
 #if H_3D
@@ -1163,8 +1432,26 @@
   TComPTL* getPTL()     { return &m_pcPTL; }
 #if H_MV
+#if H_MV5
+  Void      setVPS          ( TComVPS* pcVPS ) { m_pcVPS = pcVPS; }
+  TComVPS*  getVPS          () { return m_pcVPS; }
+
+  Void setSpsInferScalingListFlag( Bool flag ) { m_spsInferScalingListFlag = flag; } 
+  Bool getSpsInferScalingListFlag(  )          { return m_spsInferScalingListFlag; } 
+
+  Void setSpsScalingListRefLayerId( Int  val ) { m_spsScalingListRefLayerId = val; } 
+  Int  getSpsScalingListRefLayerId(  )         { return m_spsScalingListRefLayerId; } 
+
+  Void setUpdateRepFormatFlag( Bool flag )     { m_updateRepFormatFlag = flag; } 
+  Bool getUpdateRepFormatFlag(  )              { return m_updateRepFormatFlag; } 
+#endif
+  // SPS Extension 
   Void setInterViewMvVertConstraintFlag(Bool val) { m_interViewMvVertConstraintFlag = val; }
   Bool getInterViewMvVertConstraintFlag()         { return m_interViewMvVertConstraintFlag;}
-
-  ////  sps_extension_vui_parameters( )
+#if H_MV5
+  // Inference 
+  Void inferRepFormat( TComVPS* vps, Int layerIdCurr );
+
+  Void inferScalingList( TComSPS* spsSrc );
+#else
   Void setNumIlpRestrictedRefLayers   ( Int val )        { m_numIlpRestrictedRefLayers         = val;}
   Int  getNumIlpRestrictedRefLayers   ( )                { return m_numIlpRestrictedRefLayers        ;}
@@ -1178,4 +1465,6 @@
   Void setMinHorizontalCtuOffsetPlus1 ( Int i, Int val )   { m_minHorizontalCtuOffsetPlus1 [ i ] = val;}
   Int  getMinHorizontalCtuOffsetPlus1 ( Int i )            { return m_minHorizontalCtuOffsetPlus1 [ i ];}
+
+#endif
 #endif
 #if H_3D_QTLPC
@@ -1293,4 +1582,11 @@
   Int m_numExtraSliceHeaderBits;
 
+#if H_MV5
+#if H_MV
+  Int  m_layerId; 
+  Bool m_ppsInferScalingListFlag;
+  Int  m_ppsScalingListRefLayerId;
+#endif
+#endif
 public:
   TComPPS();
@@ -1414,4 +1710,16 @@
   Bool getSliceHeaderExtensionPresentFlag   ()                    { return m_sliceHeaderExtensionPresentFlag; }
   Void setSliceHeaderExtensionPresentFlag   (Bool val)            { m_sliceHeaderExtensionPresentFlag = val; }
+#if H_MV5
+#if H_MV
+  Void setLayerId( Int  val ) { m_layerId = val; } 
+  Int  getLayerId(  ) { return m_layerId; } 
+
+  Void setPpsInferScalingListFlag( Bool flag ) { m_ppsInferScalingListFlag = flag; } 
+  Bool getPpsInferScalingListFlag(  ) { return m_ppsInferScalingListFlag; } 
+
+  Void setPpsScalingListRefLayerId( Int  val ) { m_ppsScalingListRefLayerId = val; } 
+  Int  getPpsScalingListRefLayerId(  ) { return m_ppsScalingListRefLayerId; } 
+#endif
+#endif
 };
 
@@ -1446,4 +1754,9 @@
   Bool        m_PicOutputFlag;        ///< pic_output_flag 
   Int         m_iPOC;
+#if H_MV5
+#if H_MV
+  Int         m_iPOCBeforeReset; 
+#endif
+#endif
   Int         m_iLastIDR;
   static Int  m_prevPOC;
@@ -1540,4 +1853,14 @@
   Bool       m_enableTMVPFlag;
 #if H_MV
+#if H_MV5
+  std::vector<TComPic*>* m_refPicSetInterLayer0; 
+  std::vector<TComPic*>* m_refPicSetInterLayer1; 
+  Int        m_layerId; 
+  Int        m_viewId;
+  Int        m_viewIndex; 
+#if H_3D
+  Bool       m_isDepth;
+#endif
+#else
   std::vector<TComPic*>* m_refPicSetInterLayer; 
   Int        m_layerId; 
@@ -1547,10 +1870,15 @@
   Bool       m_isDepth;
 #endif
+#endif
 
 // Additional slice header syntax elements 
+#if H_MV5
+  Bool       m_pocResetFlag; 
+#endif
   Bool       m_discardableFlag;
   Bool       m_interLayerPredEnabledFlag;
   Int        m_numInterLayerRefPicsMinus1;
   Int        m_interLayerPredLayerIdc       [MAX_NUM_LAYERS];
+#if !H_MV5
   Bool       m_interLayerSamplePredOnlyFlag;
   Bool       m_altCollocatedIndicationFlag;
@@ -1560,4 +1888,5 @@
   Int        m_activeMotionPredRefLayerId   [ MAX_NUM_LAYER_IDS ];
 
+#endif
   Int        m_aaiCodedScale [2][MAX_NUM_LAYERS];
   Int        m_aaiCodedOffset[2][MAX_NUM_LAYERS];
@@ -1693,9 +2022,18 @@
   
 #if H_MV
+#if H_MV5
+  Void      setPocBeforeReset   ( Int i )                       { m_iPOCBeforeReset = i; }
+  Int       getPocBeforeReset   ( )                             { return m_iPOCBeforeReset; }
+#endif
   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
+#if H_MV5
+  Void      getTempRefPicLists   ( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& refPicSetInterLayer0, std::vector<TComPic*>& refPicSetInterLayer1,                                     
+                                   std::vector<TComPic*> rpsCurrList[2], std::vector<Bool> usedAsLongTerm[2], Int& numPocTotalCurr, Bool checkNumPocTotalCurr = false );
+
+  Void      setRefPicList        ( std::vector<TComPic*> rpsCurrList[2], std::vector<Bool> usedAsLongTerm[2], Int numPocTotalCurr, Bool checkNumPocTotalCurr = false ); 
+#else
   Void      setRefPicList       ( TComList<TComPic*>& rcListPic, std::vector<TComPic*>& interLayerRefPicSet , Bool checkNumPocTotalCurr = false );
+#endif
 #else
 #if FIX1071
@@ -1746,9 +2084,18 @@
   Void applyReferencePictureSet( TComList<TComPic*>& rcListPic, TComReferencePictureSet *RPSList);
 #if H_MV
+#if !H_MV5
   Void createAndApplyIvReferencePictureSet( TComPicLists* ivPicLists, std::vector<TComPic*>& refPicSetInterLayer );
   static Void markIvRefPicsAsShortTerm    ( std::vector<TComPic*> refPicSetInterLayer );
+#else
+  Void createInterLayerReferencePictureSet( TComPicLists* ivPicLists, std::vector<TComPic*>& refPicSetInterLayer0, std::vector<TComPic*>& refPicSetInterLayer1 );
+  static Void markIvRefPicsAsShortTerm    ( std::vector<TComPic*> refPicSetInterLayer0, std::vector<TComPic*> refPicSetInterLayer1 );
+#endif
   static Void markCurrPic                 ( TComPic* currPic );; 
   static Void markIvRefPicsAsUnused       ( TComPicLists* ivPicLists, std::vector<Int> targetDecLayerIdSet, TComVPS* vps, Int curLayerId, Int curPoc  );
+#if H_MV5
+  Void        printRefPicList();
+#else
   Void        xPrintRefPicList();
+#endif
 #endif
   Bool isTemporalLayerSwitchingPoint( TComList<TComPic*>& rcListPic );
@@ -1837,4 +2184,8 @@
   Void      setViewId             ( Int viewId )     { m_viewId = viewId;   }
   Int       getViewId             ()                 { return m_viewId;     }
+#if H_MV5
+  Void      setViewIndex          ( Int viewIndex )  { m_viewIndex = viewIndex;   }
+  Int       getViewIndex          ()                 { return m_viewIndex;     }
+#endif
 #if H_3D
 #if H_3D_TMVP
@@ -1843,6 +2194,8 @@
   Int       getAlterRefIdx          ( RefPicList e )        { return  m_aiAlterRefIdx[e];     }
 #endif
+#if !H_MV5
   Void      setViewIndex          ( Int viewIndex )  { m_viewIndex = viewIndex;   }
   Int       getViewIndex          ()                 { return m_viewIndex;     }
+#endif
   Void      setIsDepth            ( Bool isDepth )   { m_isDepth = isDepth; }
   Bool      getIsDepth            ()                 { return m_isDepth; }
@@ -1865,4 +2218,10 @@
 #if H_MV
 // Additional slice header syntax elements
+
+#if H_MV5
+  Void setPocResetFlag( Bool flag ) { m_pocResetFlag = flag; } 
+  Bool getPocResetFlag(  ) { return m_pocResetFlag; } 
+#endif
+
 Void setDiscardableFlag( Bool flag ) { m_discardableFlag = flag; } 
 Bool getDiscardableFlag(  ) { return m_discardableFlag; } 
@@ -1877,4 +2236,19 @@
 Int  getInterLayerPredLayerIdc( Int i ) { return m_interLayerPredLayerIdc[i]; } 
 
+#if H_MV5 
+  // Additional variables derived in slice header semantics 
+  Int  getNumInterLayerRefPicsMinus1Len( ) { return gCeilLog2(  getVPS()->getNumDirectRefLayers( getLayerId() )); }
+  Int  getInterLayerPredLayerIdcLen    ( ) { return gCeilLog2(  getVPS()->getNumDirectRefLayers( getLayerId() )); }
+
+  Int  getNumActiveRefLayerPics( );
+
+  Int  getNumActiveRefLayerPics0( )        { return (Int) m_refPicSetInterLayer0->size();  };
+  Int  getNumActiveRefLayerPics1( )        { return (Int) m_refPicSetInterLayer1->size();  };
+
+  Int  getRefPicLayerId               ( Int i );
+
+  Void     setRefPicSetInterLayer       ( std::vector<TComPic*>* refPicSetInterLayer0, std::vector<TComPic*>* refPicSetInterLayer1);
+  TComPic* getPicFromRefPicSetInterLayer( Int setIdc, Int layerId );
+#else
 Void setInterLayerSamplePredOnlyFlag( Bool flag ) { m_interLayerSamplePredOnlyFlag = flag; } 
 Bool getInterLayerSamplePredOnlyFlag(  ) { return m_interLayerSamplePredOnlyFlag; } 
@@ -1903,4 +2277,5 @@
 TComPic* getPicFromRefPicSetInterLayer( Int layerId );
 
+#endif
 #endif
 protected:
@@ -1909,5 +2284,7 @@
 TComPic*  xGetLongTermRefPic(TComList<TComPic*>& rcListPic, Int poc, Bool pocHasMsb);
 #if H_MV
+#if !H_MV5
   Int       xCeilLog2( Int val );
+#endif
   TComPic*  xGetInterLayerRefPic( std::vector<TComPic*>& rcListIlPic, Int layerId );  
 #endif
@@ -1991,4 +2368,5 @@
   //! activate a SPS from a active parameter sets SEI message
   //! \returns true, if activation is successful
+#if !H_MV5
   Bool activateSPSWithSEI(Int SPSId);
 
@@ -2010,4 +2388,43 @@
   Int m_activeSPSId;
   Int m_activePPSId;
+#else
+#if H_MV
+  Bool activateSPSWithSEI(Int SPSId, Int layerId );
+#else
+  Bool activateSPSWithSEI(Int SPSId);
+#endif
+
+  //! activate a PPS and depending on isIDR parameter also SPS and VPS
+  //! \returns true, if activation is successful
+#if H_MV
+  Bool activatePPS(Int ppsId, Bool isIRAP, Int layerId );
+#else
+  Bool activatePPS(Int ppsId, Bool isIRAP);
+#endif
+
+  TComVPS* getActiveVPS(){ return m_vpsMap.getPS(m_activeVPSId); };
+#if H_MV
+  TComSPS* getActiveSPS( Int layerId ){ return m_spsMap.getPS( m_activeSPSId[ layerId ] ); };
+  TComPPS* getActivePPS( Int layerId ){ return m_ppsMap.getPS( m_activePPSId[ layerId ] ); };
+#else
+  TComSPS* getActiveSPS(){ return m_spsMap.getPS(m_activeSPSId); };
+  TComPPS* getActivePPS(){ return m_ppsMap.getPS(m_activePPSId); };
+#endif
+protected:
+  
+  ParameterSetMap<TComVPS> m_vpsMap;
+  ParameterSetMap<TComSPS> m_spsMap; 
+  ParameterSetMap<TComPPS> m_ppsMap;
+
+  Int m_activeVPSId;
+#if H_MV
+  Int m_activeSPSId[ MAX_NUM_LAYERS ];
+  Int m_activePPSId[ MAX_NUM_LAYERS ];
+#else
+  Int m_activeSPSId;
+  Int m_activePPSId;
+#endif
+
+#endif
 };
 
Index: branches/HTM-8.0-dev0/source/Lib/TLibCommon/TComYuv.cpp
===================================================================
--- branches/HTM-8.0-dev0/source/Lib/TLibCommon/TComYuv.cpp	(revision 617)
+++ branches/HTM-8.0-dev0/source/Lib/TLibCommon/TComYuv.cpp	(revision 618)
@@ -110,4 +110,16 @@
   {
     ::memcpy( pDst, pSrc, sizeof(Pel)*iWidth);
+
+#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC
+    if ( g_traceCopyBack && g_nSymbolCounter >= g_stopAtCounter )
+    { 
+      for ( Int x = 0; x < iWidth; x++)
+      {      
+        std::cout << pSrc[ x ] << " " ; 
+      }
+      std::cout << std::endl;
+    }
+#endif
+
     pDst += iDstStride;
     pSrc += iSrcStride;
Index: branches/HTM-8.0-dev0/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- branches/HTM-8.0-dev0/source/Lib/TLibCommon/TypeDef.h	(revision 617)
+++ branches/HTM-8.0-dev0/source/Lib/TLibCommon/TypeDef.h	(revision 618)
@@ -70,4 +70,5 @@
 #if H_MV
 #define H_MV_ENC_DEC_TRAC                 1  //< CU/PU level tracking
+#define H_MV5                             1
 #endif
 
@@ -791,8 +792,15 @@
   enum ScalabilityType
   {
+#if H_MV5
+#if H_3D
+    DEPTH_ID = 0,    
+#endif    
+    VIEW_ORDER_INDEX  = 1,
+#else
     VIEW_ID  = 0,
 #if H_3D
     DEPTH_ID = 1,    
 #endif    
+#endif
   };
 #endif
Index: branches/HTM-8.0-dev0/source/Lib/TLibDecoder/SyntaxElementParser.cpp
===================================================================
--- branches/HTM-8.0-dev0/source/Lib/TLibDecoder/SyntaxElementParser.cpp	(revision 617)
+++ branches/HTM-8.0-dev0/source/Lib/TLibDecoder/SyntaxElementParser.cpp	(revision 618)
@@ -50,5 +50,5 @@
   xReadCode (length, rValue);
 #if H_MV_ENC_DEC_TRAC
-  if ( g_disableHLSTrace )
+  if ( g_disableHLSTrace || !g_HLSTraceEnable )
   {
     return; 
@@ -71,5 +71,5 @@
   xReadUvlc (rValue);
 #if H_MV_ENC_DEC_TRAC
-  if ( g_disableHLSTrace )
+  if ( g_disableHLSTrace  || !g_HLSTraceEnable )
   {
     return; 
@@ -85,5 +85,5 @@
   xReadSvlc(rValue);
 #if H_MV_ENC_DEC_TRAC
-  if ( g_disableHLSTrace )
+  if ( g_disableHLSTrace  || !g_HLSTraceEnable  )
   {
     return; 
@@ -99,5 +99,5 @@
   xReadFlag(rValue);
 #if H_MV_ENC_DEC_TRAC
-  if ( g_disableHLSTrace )
+  if ( g_disableHLSTrace  || !g_HLSTraceEnable )
   {
     return; 
Index: branches/HTM-8.0-dev0/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- branches/HTM-8.0-dev0/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 617)
+++ branches/HTM-8.0-dev0/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 618)
@@ -330,4 +330,19 @@
     }
   }
+#if H_MV5
+#if H_MV
+  if ( pcPPS->getLayerId() > 0 )
+  {
+    READ_FLAG( uiCode, "pps_infer_scaling_list_flag" ); pcPPS->setPpsInferScalingListFlag( uiCode == 1 );    
+  }
+
+  if( pcPPS->getPpsInferScalingListFlag( ) ) 
+  {
+    READ_CODE( 6, uiCode, "pps_scaling_list_ref_layer_id" ); pcPPS->setPpsScalingListRefLayerId( uiCode );
+  }
+  else
+  {  
+#endif
+#endif
   READ_FLAG( uiCode, "pps_scaling_list_data_present_flag" );           pcPPS->setScalingListPresentFlag( uiCode ? true : false );
   if(pcPPS->getScalingListPresentFlag ())
@@ -335,4 +350,9 @@
     parseScalingList( pcPPS->getScalingList() );
   }
+#if H_MV5
+#if H_MV
+  }
+#endif
+#endif
 
   READ_FLAG( uiCode, "lists_modification_present_flag");
@@ -410,8 +430,23 @@
   {
     Window &defDisp = pcVUI->getDefaultDisplayWindow();
+#if !H_MV5
     READ_UVLC(   uiCode, "def_disp_win_left_offset" );                defDisp.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
     READ_UVLC(   uiCode, "def_disp_win_right_offset" );               defDisp.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
     READ_UVLC(   uiCode, "def_disp_win_top_offset" );                 defDisp.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
     READ_UVLC(   uiCode, "def_disp_win_bottom_offset" );              defDisp.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
+#else
+#if H_MV
+    defDisp.setScaledFlag( false ); 
+    READ_UVLC(   uiCode, "def_disp_win_left_offset" );                defDisp.setWindowLeftOffset  ( uiCode );
+    READ_UVLC(   uiCode, "def_disp_win_right_offset" );               defDisp.setWindowRightOffset ( uiCode );
+    READ_UVLC(   uiCode, "def_disp_win_top_offset" );                 defDisp.setWindowTopOffset   ( uiCode );
+    READ_UVLC(   uiCode, "def_disp_win_bottom_offset" );              defDisp.setWindowBottomOffset( uiCode );
+#else
+    READ_UVLC(   uiCode, "def_disp_win_left_offset" );                defDisp.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
+    READ_UVLC(   uiCode, "def_disp_win_right_offset" );               defDisp.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc()) );
+    READ_UVLC(   uiCode, "def_disp_win_top_offset" );                 defDisp.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
+    READ_UVLC(   uiCode, "def_disp_win_bottom_offset" );              defDisp.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc()) );
+#endif
+#endif
   }
   TimingInfo *timingInfo = pcVUI->getTimingInfo();
@@ -436,4 +471,5 @@
   {
     READ_FLAG(   uiCode, "tiles_fixed_structure_flag");               pcVUI->setTilesFixedStructureFlag(uiCode);
+#if !H_MV5
 #if H_MV
     if ( pcSPS->getLayerId() > 0 )
@@ -441,4 +477,5 @@
       READ_FLAG( uiCode, "tile_boundaries_aligned_flag" ); pcVUI->setTileBoundariesAlignedFlag( uiCode == 1 );
     }
+#endif
 #endif
     READ_FLAG(   uiCode, "motion_vectors_over_pic_boundaries_flag");  pcVUI->setMotionVectorsOverPicBoundariesFlag(uiCode);
@@ -560,5 +597,15 @@
   READ_UVLC(     uiCode, "sps_seq_parameter_set_id" );           pcSPS->setSPSId( uiCode );
   assert(uiCode <= 15);
+#if H_MV5
+#if H_MV
+  if ( pcSPS->getLayerId() > 0 )
+  {
+    READ_FLAG( uiCode, "update_rep_format_flag" );               pcSPS->setUpdateRepFormatFlag( uiCode == 1 );
+  }
   
+  if ( pcSPS->getUpdateRepFormatFlag() )
+  { 
+#endif
+#endif
   READ_UVLC(     uiCode, "chroma_format_idc" );                  pcSPS->setChromaFormatIdc( uiCode );
   assert(uiCode <= 3);
@@ -572,14 +619,41 @@
   READ_UVLC (    uiCode, "pic_width_in_luma_samples" );          pcSPS->setPicWidthInLumaSamples ( uiCode    );
   READ_UVLC (    uiCode, "pic_height_in_luma_samples" );         pcSPS->setPicHeightInLumaSamples( uiCode    );
+#if H_MV5
+#if H_MV
+  }
+#endif
+#endif
   READ_FLAG(     uiCode, "conformance_window_flag");
   if (uiCode != 0)
   {
     Window &conf = pcSPS->getConformanceWindow();
+#if H_MV5
+#if H_MV
+    // Needs to be scaled later, when ChromaFormatIdc is known. 
+    conf.setScaledFlag( false ); 
+    READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode  );
+    READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode  );
+    READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode  );
+    READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode  );    
+#else
     READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
     READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
     READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
     READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
-  }
-
+#endif
+#else
+    READ_UVLC(   uiCode, "conf_win_left_offset" );               conf.setWindowLeftOffset  ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
+    READ_UVLC(   uiCode, "conf_win_right_offset" );              conf.setWindowRightOffset ( uiCode * TComSPS::getWinUnitX( pcSPS->getChromaFormatIdc() ) );
+    READ_UVLC(   uiCode, "conf_win_top_offset" );                conf.setWindowTopOffset   ( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
+    READ_UVLC(   uiCode, "conf_win_bottom_offset" );             conf.setWindowBottomOffset( uiCode * TComSPS::getWinUnitY( pcSPS->getChromaFormatIdc() ) );
+#endif
+  }
+
+#if H_MV5
+#if H_MV
+  if ( pcSPS->getUpdateRepFormatFlag() )
+  { 
+#endif
+#endif
   READ_UVLC(     uiCode, "bit_depth_luma_minus8" );
   assert(uiCode <= 6);
@@ -591,4 +665,9 @@
   pcSPS->setBitDepthC( uiCode + 8 );
   pcSPS->setQpBDOffsetC( (Int) (6*uiCode) );
+#if H_MV5
+#if H_MV
+  }
+#endif
+#endif
 
   READ_UVLC( uiCode,    "log2_max_pic_order_cnt_lsb_minus4" );   pcSPS->setBitsForPOC( 4 + uiCode );
@@ -613,5 +692,9 @@
     pcSPS->setNumReorderPics(uiCode, i);
 #if H_MV
+#if H_MV5
+    READ_UVLC ( uiCode, "sps_max_latency_increase_plus1[i]");
+#else
     READ_UVLC ( uiCode, "sps_max_latency_increase[i]");
+#endif
 #else
     READ_UVLC ( uiCode, "sps_max_latency_increase");
@@ -653,4 +736,19 @@
   if(pcSPS->getScalingListFlag())
   {
+#if H_MV5
+#if H_MV
+    if ( pcSPS->getLayerId() > 0 )
+    {    
+      READ_FLAG( uiCode, "sps_infer_scaling_list_flag" ); pcSPS->setSpsInferScalingListFlag( uiCode == 1 );
+    }
+
+    if ( pcSPS->getSpsInferScalingListFlag() )
+    {
+      READ_CODE( 6, uiCode, "sps_scaling_list_ref_layer_id" ); pcSPS->setSpsScalingListRefLayerId( uiCode );
+    }
+    else
+    {    
+#endif
+#endif
     READ_FLAG( uiCode, "sps_scaling_list_data_present_flag" );                 pcSPS->setScalingListPresentFlag ( uiCode );
     if(pcSPS->getScalingListPresentFlag ())
@@ -658,4 +756,9 @@
       parseScalingList( pcSPS->getScalingList() );
     }
+#if H_MV5
+#if H_MV
+    }
+#endif
+#endif
   }
   READ_FLAG( uiCode, "amp_enabled_flag" );                          pcSPS->setUseAMP( uiCode );
@@ -711,4 +814,5 @@
   if (uiCode)
   {
+#if !H_MV5
 #if !H_MV
     while ( xMoreRbspData() )
@@ -789,4 +893,75 @@
   }
 }
+#else 
+#if H_MV
+    parseSPSExtension( pcSPS ); 
+    READ_FLAG( uiCode, "sps_extension2_flag");
+    if ( uiCode )
+    {
+#if H_3D
+      parseSPSExtension2( pcSPS, viewIndex, depthFlag ); 
+      READ_FLAG( uiCode, "sps_extension3_flag");
+      if ( uiCode )
+      {
+#endif
+#endif
+        while ( xMoreRbspData() )
+        {
+          READ_FLAG( uiCode, "sps_extension_data_flag");
+        }
+#if H_MV      
+#if H_3D
+      }
+#endif
+    }
+#endif
+  }
+}
+#endif
+#if H_MV5
+Void TDecCavlc::parseSPSExtension( TComSPS* pcSPS )
+{
+  UInt uiCode; 
+  READ_FLAG( uiCode, "inter_view_mv_vert_constraint_flag" );    pcSPS->setInterViewMvVertConstraintFlag(uiCode == 1 ? true : false);
+  READ_UVLC( uiCode, "sps_shvc_reserved_zero_idc" ); 
+}
+
+#if H_3D
+Void TDecCavlc::parseSPSExtension2( TComSPS* pcSPS, Int viewIndex, Bool depthFlag )
+{ 
+  UInt uiCode; 
+#if H_3D_QTLPC
+  //GT: This has to go to VPS
+  if( depthFlag )
+  {
+    READ_FLAG( uiCode, "use_qtl_flag" );
+    pcSPS->setUseQTL( uiCode );
+    READ_FLAG( uiCode, "use_pc_flag" );
+    pcSPS->setUsePC( uiCode );
+  }
+#endif
+
+  UInt uiCamParPrecision = 0; 
+  Bool bCamParSlice      = false; 
+  if ( !depthFlag )
+  {      
+    READ_UVLC( uiCamParPrecision, "cp_precision" );
+    READ_FLAG( uiCode, "cp_in_slice_header_flag" );    bCamParSlice = ( uiCode == 1 );
+    if( !bCamParSlice )
+    {       
+      for( UInt uiBaseIndex = 0; uiBaseIndex < viewIndex; uiBaseIndex++ )
+      {
+        Int iCode; 
+        READ_SVLC( iCode, "cp_scale" );                m_aaiTempScale  [ uiBaseIndex ][ viewIndex ]   = iCode;
+        READ_SVLC( iCode, "cp_off" );                  m_aaiTempOffset [ uiBaseIndex ][ viewIndex ]   = iCode;
+        READ_SVLC( iCode, "cp_inv_scale_plus_scale" ); m_aaiTempScale  [ viewIndex   ][ uiBaseIndex ] = iCode - m_aaiTempScale [ uiBaseIndex ][ viewIndex ];
+        READ_SVLC( iCode, "cp_inv_off_plus_off" );     m_aaiTempOffset [ viewIndex   ][ uiBaseIndex ] = iCode - m_aaiTempOffset[ uiBaseIndex ][ viewIndex ];
+      }
+    }
+  }
+  pcSPS->initCamParaSPS( viewIndex, uiCamParPrecision, bCamParSlice, m_aaiTempScale, m_aaiTempOffset ); 
+}
+#endif
+#endif
 
 Void TDecCavlc::parseVPS(TComVPS* pcVPS)
@@ -797,5 +972,9 @@
   READ_CODE( 2,  uiCode,  "vps_reserved_three_2bits" );           assert(uiCode == 3);
 #if H_MV
+#if H_MV5
+  READ_CODE( 6,  uiCode,  "vps_max_layers_minus1" );              pcVPS->setMaxLayersMinus1( uiCode  );
+#else
   READ_CODE( 6,  uiCode,  "vps_max_layers_minus1" );              pcVPS->setMaxLayers( uiCode + 1 );
+#endif
 #else
   READ_CODE( 6,  uiCode,  "vps_reserved_zero_6bits" );            assert(uiCode == 0);
@@ -882,4 +1061,5 @@
   if (uiCode)
   {
+#if !H_MV5
 #if H_MV
     m_pcBitstream->readOutTrailingBits();
@@ -1099,4 +1279,375 @@
   return;
 }
+#else
+#if H_MV
+    m_pcBitstream->readOutTrailingBits();
+    parseVPSExtension( pcVPS );   
+    READ_FLAG( uiCode,  "vps_extension2_flag" );
+    if (uiCode)
+    {
+#if H_3D
+      m_pcBitstream->readOutTrailingBits();
+      parseVPSExtension2( pcVPS );   
+      READ_FLAG( uiCode,  "vps_extension3_flag" );
+      if (uiCode)
+      {      
+#endif
+#endif  
+        while ( xMoreRbspData() )
+        {
+          READ_FLAG( uiCode, "vps_extension_data_flag");
+        }
+#if H_MV
+#if H_3D
+      }
+#endif
+    }
+#endif
+  }
+}
+#endif
+
+#if H_MV5
+#if H_MV
+Void TDecCavlc::parseVPSExtension( TComVPS* pcVPS )
+{
+  UInt uiCode; 
+  READ_FLAG( uiCode, "avc_base_layer_flag" );                     pcVPS->setAvcBaseLayerFlag( uiCode == 1 ? true : false );
+  READ_CODE( 16, uiCode, "vps_vui_offset" );                      pcVPS->setVpsVuiOffset( uiCode );
+  READ_FLAG( uiCode, "splitting_flag" );                          pcVPS->setSplittingFlag( uiCode == 1 ? true : false );
+
+  for( Int sIdx = 0; sIdx < MAX_NUM_SCALABILITY_TYPES; sIdx++ )
+  {
+    READ_FLAG( uiCode,  "scalability_mask_flag[i]" );             pcVPS->setScalabilityMaskFlag( sIdx, uiCode == 1 ? true : false );      
+  }
+
+  for( Int sIdx = 0; sIdx < pcVPS->getNumScalabilityTypes( ) - ( pcVPS->getSplittingFlag() ? 1 : 0 ); sIdx++ )
+  {
+    READ_CODE( 3, uiCode, "dimension_id_len_minus1[j]" );       pcVPS->setDimensionIdLen( sIdx, uiCode + 1 );
+  }
+
+  if ( pcVPS->getSplittingFlag() )
+  {
+    pcVPS->setDimensionIdLen( pcVPS->getNumScalabilityTypes( ) - 1, pcVPS->inferLastDimsionIdLenMinus1() );       
+  }
+
+  READ_FLAG( uiCode, "vps_nuh_layer_id_present_flag" );           pcVPS->setVpsNuhLayerIdPresentFlag( uiCode == 1 ? true : false );
+
+  for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
+  {
+    if ( pcVPS->getVpsNuhLayerIdPresentFlag() )
+    {
+      READ_CODE( 6, uiCode, "layer_id_in_nuh[i]" );                pcVPS->setLayerIdInNuh( i, uiCode );
+    }
+    else
+    {
+      pcVPS->setLayerIdInNuh( i, i );; 
+    }
+
+    pcVPS->setLayerIdInVps( pcVPS->getLayerIdInNuh( i ), i ); 
+
+    for( Int j = 0; j < pcVPS->getNumScalabilityTypes() ; j++ ) 
+    {
+      if ( !pcVPS->getSplittingFlag() )
+      {
+        READ_CODE( pcVPS->getDimensionIdLen( j ), uiCode, "dimension_id[i][j]" );  pcVPS->setDimensionId( i, j, uiCode );
+      }
+      else
+      {
+        pcVPS->setDimensionId( i, j, pcVPS->inferDimensionId( i, j)  );
+      }
+    }
+  }
+
+  // GT spec says: trac #39
+  // if ( pcVPS->getNumViews() > 1 )  
+  //   However, this is a bug in the text since, view_id_len_minus1 is needed to parse view_id_val. 
+  {
+    READ_CODE( 4, uiCode, "view_id_len_minus1" ); pcVPS->setViewIdLenMinus1( uiCode );
+  }
+
+  for( Int i = 0; i < pcVPS->getNumViews(); i++ )
+  {
+    READ_CODE( pcVPS->getViewIdLenMinus1( ) + 1, uiCode, "view_id_val[i]" ); pcVPS->setViewIdVal( i, uiCode );
+  }
+
+  for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
+  {
+    for( Int j = 0; j < i; j++ )
+    {
+      READ_FLAG( uiCode, "direct_dependency_flag[i][j]" );             pcVPS->setDirectDependencyFlag( i, j, uiCode );
+    }
+  }
+
+  READ_FLAG( uiCode, "max_tid_ref_present_flag" ); pcVPS->setMaxTidRefPresentFlag( uiCode == 1 );
+
+  if ( pcVPS->getMaxTidRefPresentFlag() )
+  {    
+    for( Int i = 0; i < pcVPS->getMaxLayersMinus1(); i++ )
+    {
+      READ_CODE( 3, uiCode,       "max_tid_il_ref_pics_plus1[i]" );      pcVPS->setMaxTidIlRefPicPlus1( i , uiCode ); 
+    }
+  }
+
+  READ_FLAG( uiCode, "all_ref_layers_active_flag" );             pcVPS->setAllRefLayersActiveFlag( uiCode == 1 );
+  READ_CODE( 10, uiCode, "vps_number_layer_sets_minus1"      );  pcVPS->setVpsNumberLayerSetsMinus1    ( uiCode ); 
+  READ_CODE( 6,  uiCode, "vps_num_profile_tier_level_minus1" );  pcVPS->setVpsNumProfileTierLevelMinus1( uiCode );
+
+  for( Int i = 1; i <= pcVPS->getVpsNumProfileTierLevelMinus1(); i++ )
+  {
+    READ_FLAG(  uiCode, "vps_profile_present_flag[i]" );    pcVPS->setVpsProfilePresentFlag( i, uiCode == 1 );
+    if( !pcVPS->getVpsProfilePresentFlag( i ) )
+    {
+      READ_CODE( 6, uiCode, "profile_ref_minus1[i]" ); pcVPS->setProfileRefMinus1( i, uiCode );
+    }
+    parsePTL ( pcVPS->getPTL( i ), pcVPS->getVpsProfilePresentFlag( i ), pcVPS->getMaxTLayers()-1);
+    if( !pcVPS->getVpsProfilePresentFlag( i ) )
+    {
+      TComPTL temp = *pcVPS->getPTL( i );
+      *pcVPS->getPTL( i ) = *pcVPS->getPTL( pcVPS->getProfileRefMinus1( i ) + 1 );
+      pcVPS->getPTL( i )->copyLevelFrom( &temp );
+    }
+  }
+
+  Int numOutputLayerSets = pcVPS->getVpsNumberLayerSetsMinus1( ) + 1; 
+
+  READ_FLAG( uiCode, "more_output_layer_sets_than_default_flag" ); pcVPS->setMoreOutputLayerSetsThanDefaultFlag( uiCode == 1 );
+
+  if ( pcVPS->getMoreOutputLayerSetsThanDefaultFlag( ) )
+  {
+    READ_CODE( 10, uiCode, "num_add_output_layer_sets_minus1"      ); pcVPS->setNumAddOutputLayerSetsMinus1( uiCode );
+    numOutputLayerSets += ( pcVPS->getNumAddOutputLayerSetsMinus1( ) + 1); 
+  }
+
+  if( numOutputLayerSets > 1)
+  {
+    READ_FLAG( uiCode, "default_one_target_output_layer_flag" ); pcVPS->setDefaultOneTargetOutputLayerFlag(  uiCode == 1); 
+  }  
+
+  for( Int i = 1; i < numOutputLayerSets; i++ )
+  {
+    if( i > pcVPS->getVpsNumberLayerSetsMinus1( ) )
+    {        
+      READ_UVLC( uiCode,      "output_layer_set_idx_minus1[i]" ); pcVPS->setOutputLayerSetIdxMinus1( i, uiCode ); 
+      for( Int j = 0; j < pcVPS->getNumLayersInIdList( j ) - 1; j++ )
+      {
+        READ_FLAG( uiCode, "output_layer_flag" ); pcVPS->setOutputLayerFlag( i, j, uiCode == 1 ); 
+      }        
+    }
+    if ( pcVPS->getProfileLevelTierIdxLen()  > 0 )
+    {      
+      READ_CODE( pcVPS->getProfileLevelTierIdxLen(), uiCode,"profile_level_tier_idx[ i ]" );   pcVPS->setProfileLevelTierIdx( i , uiCode ); 
+    }
+  }
+
+  READ_FLAG( uiCode, "rep_format_idx_present_flag" ); pcVPS->setRepFormatIdxPresentFlag( uiCode == 1 );
+  if ( pcVPS->getRepFormatIdxPresentFlag() )
+  {
+    READ_CODE( 4, uiCode, "vps_num_rep_formats_minus1" ); pcVPS->setVpsNumRepFormatsMinus1( uiCode );
+  }
+
+  for (Int i = 0; i <= pcVPS->getVpsNumRepFormatsMinus1(); i++ )
+  { 
+    assert( pcVPS->getRepFormat(i) == NULL ); 
+    TComRepFormat* repFormat = new TComRepFormat(); 
+    parseRepFormat( repFormat );
+    pcVPS->setRepFormat(i, repFormat ); 
+  }
+
+  if( pcVPS->getRepFormatIdxPresentFlag() ) 
+  {
+    for( Int i = 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
+    {
+      if( pcVPS->getVpsNumRepFormatsMinus1() > 0 )
+      {
+        READ_CODE( 4, uiCode, "vps_rep_format_idx" ); pcVPS->setVpsRepFormatIdx( i, uiCode );
+      }
+    }
+  }
+
+  READ_FLAG( uiCode, "max_one_active_ref_layer_flag" ); pcVPS->setMaxOneActiveRefLayerFlag ( uiCode == 1 ); 
+  READ_FLAG( uiCode, "cross_layer_irap_aligned_flag" ); pcVPS->setCrossLayerIrapAlignedFlag( uiCode == 1 );
+  READ_UVLC( uiCode, "direct_dep_type_len_minus2")    ; pcVPS->setDirectDepTypeLenMinus2   ( uiCode ); 
+
+  for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
+  {
+    for( Int j = 0; j < i; j++ )
+    {
+      if (pcVPS->getDirectDependencyFlag( i, j) )
+      {        
+        READ_CODE( pcVPS->getDirectDepTypeLenMinus2( ) + 2,  uiCode, "direct_dependency_type[i][j]" ); pcVPS->setDirectDependencyType( i, j , uiCode);
+      }
+    }
+  }
+
+  READ_FLAG( uiCode, "vps_shvc_reserved_zero_flag" ); 
+  READ_FLAG( uiCode, "vps_vui_present_flag" )       ; pcVPS->setVpsVuiPresentFlag( uiCode == 1 );
+
+  if( pcVPS->getVpsVuiPresentFlag() )
+  {
+    m_pcBitstream->readOutTrailingBits(); // vps_vui_alignment_bit_equal_to_one
+    parseVPSVUI( pcVPS ); 
+  }     
+
+  pcVPS->checkVPSExtensionSyntax(); 
+  pcVPS->setRefLayers(); 
+}
+
+Void TDecCavlc::parseRepFormat( TComRepFormat* pcRepFormat )
+{
+  assert( pcRepFormat ); 
+
+  UInt uiCode; 
+  READ_CODE( 2,  uiCode, "chroma_format_vps_idc" );          pcRepFormat->setChromaFormatVpsIdc       ( uiCode );
+  if ( pcRepFormat->getChromaFormatVpsIdc() == 3 )
+  {
+    READ_FLAG( uiCode, "separate_colour_plane_vps_flag" ); pcRepFormat->setSeparateColourPlaneVpsFlag( uiCode == 1 ); 
+  }
+  READ_CODE( 16, uiCode, "pic_width_vps_in_luma_samples" );  pcRepFormat->setPicWidthVpsInLumaSamples ( uiCode );
+  READ_CODE( 16, uiCode, "pic_height_vps_in_luma_samples" ); pcRepFormat->setPicHeightVpsInLumaSamples( uiCode );
+  READ_CODE( 4,  uiCode, "bit_depth_vps_luma_minus8" );      pcRepFormat->setBitDepthVpsLumaMinus8    ( uiCode );
+  READ_CODE( 4,  uiCode, "bit_depth_vps_chroma_minus8" );    pcRepFormat->setBitDepthVpsChromaMinus8  ( uiCode );
+}
+
+
+Void TDecCavlc::parseVPSVUI( TComVPS* pcVPS )
+{
+  assert( pcVPS ); 
+
+  TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( ); 
+
+  assert( pcVPSVUI ); 
+
+  UInt uiCode; 
+  READ_FLAG( uiCode, "bit_rate_present_vps_flag" ); pcVPSVUI->setBitRatePresentVpsFlag( uiCode == 1 );
+  READ_FLAG( uiCode, "pic_rate_present_vps_flag" ); pcVPSVUI->setPicRatePresentVpsFlag( uiCode == 1 );
+  if( pcVPSVUI->getBitRatePresentVpsFlag( )  ||  pcVPSVUI->getPicRatePresentVpsFlag( ) )
+  {
+    for( Int i = 0; i  <=  pcVPS->getVpsNumberLayerSetsMinus1(); i++ )
+    {
+      for( Int j = 0; j  <=  pcVPS->getMaxTLayers(); j++ ) 
+      {
+        if( pcVPSVUI->getBitRatePresentVpsFlag( ) )
+        {
+          READ_FLAG( uiCode, "bit_rate_present_flag" ); pcVPSVUI->setBitRatePresentFlag( i, j, uiCode == 1 );            
+        }
+        if( pcVPSVUI->getPicRatePresentVpsFlag( )  )
+        {
+          READ_FLAG( uiCode, "pic_rate_present_flag" ); pcVPSVUI->setPicRatePresentFlag( i, j, uiCode == 1 );
+        }
+        if( pcVPSVUI->getBitRatePresentFlag( i, j ) )
+        {
+          READ_CODE( 16, uiCode, "avg_bit_rate" ); pcVPSVUI->setAvgBitRate( i, j, uiCode );
+          READ_CODE( 16, uiCode, "max_bit_rate" ); pcVPSVUI->setMaxBitRate( i, j, uiCode );
+        }
+        if( pcVPSVUI->getPicRatePresentFlag( i, j ) )
+        {
+          READ_CODE( 2,  uiCode, "constant_pic_rate_idc" ); pcVPSVUI->setConstantPicRateIdc( i, j, uiCode );
+          READ_CODE( 16, uiCode, "avg_pic_rate" );          pcVPSVUI->setAvgPicRate( i, j, uiCode );
+        }
+      }
+    }
+  }
+
+  for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
+  {
+    for( Int  j = 0; j < pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i ) ); j++ ) 
+    {
+      READ_FLAG( uiCode, "tile_boundaries_aligned_flag" ); pcVPSVUI->setTileBoundariesAlignedFlag( i, j, uiCode == 1 );
+    }
+  }
+
+  READ_FLAG( uiCode, "ilp_restricted_ref_layers_flag" ); pcVPSVUI->setIlpRestrictedRefLayersFlag( uiCode == 1 );
+
+  if( pcVPSVUI->getIlpRestrictedRefLayersFlag( ) )
+  {
+    for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
+    {
+      for( Int j = 0; j < pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i ) ); j++ )
+      {
+        READ_UVLC( uiCode, "min_spatial_segment_offset_plus1" ); pcVPSVUI->setMinSpatialSegmentOffsetPlus1( i, j, uiCode );
+        if( pcVPSVUI->getMinSpatialSegmentOffsetPlus1( i, j ) > 0 )
+        {
+          READ_FLAG( uiCode, "ctu_based_offset_enabled_flag" ); pcVPSVUI->setCtuBasedOffsetEnabledFlag( i, j, uiCode == 1 );
+          if( pcVPSVUI->getCtuBasedOffsetEnabledFlag( i, j ) )
+          {
+            READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1" ); pcVPSVUI->setMinHorizontalCtuOffsetPlus1( i, j, uiCode );
+          }
+        }
+      }
+    }
+  }
+}
+#endif
+
+#if H_3D
+Void TDecCavlc::parseVPSExtension2( TComVPS* pcVPS )
+{
+  UInt uiCode; 
+  for( Int i = 0; i <= pcVPS->getMaxLayersMinus1(); i++ )
+  {
+#if H_3D_ARP
+    pcVPS->setUseAdvRP  ( i, 0 );
+    pcVPS->setARPStepNum( i, 1 );
+#endif  
+    if ( i != 0 )
+    {
+      if( !( pcVPS->getDepthId( i ) == 1 ) )
+      {
+#if H_3D_IV_MERGE
+        READ_FLAG( uiCode, "iv_mv_pred_flag[i]");          pcVPS->setIvMvPredFlag         ( i, uiCode == 1 ? true : false );
+#endif
+#if H_3D_ARP
+        READ_FLAG( uiCode, "iv_res_pred_flag[i]"  );       pcVPS->setUseAdvRP  ( i, uiCode ); pcVPS->setARPStepNum( i, uiCode ? H_3D_ARP_WFNR : 1 );
+
+#endif
+#if H_3D_NBDV_REF
+        READ_FLAG( uiCode, "depth_refinement_flag[i]");    pcVPS->setDepthRefinementFlag  ( i, uiCode == 1 ? true : false );
+#endif
+#if H_3D_VSP
+        READ_FLAG( uiCode, "view_synthesis_pred_flag[i]"); pcVPS->setViewSynthesisPredFlag( i, uiCode == 1 ? true : false );
+#endif
+      }
+      else
+      {
+
+        READ_FLAG( uiCode, "vps_depth_modes_flag[i]" );             pcVPS->setVpsDepthModesFlag( i, uiCode == 1 ? true : false );
+        //          READ_FLAG( uiCode, "lim_qt_pred_flag[i]");                  pcVPS->setLimQtPreFlag     ( i, uiCode == 1 ? true : false ); 
+#if H_3D_DIM_DLT
+        if( pcVPS->getVpsDepthModesFlag( i ) )
+        {
+          READ_FLAG( uiCode, "dlt_flag[i]" );                       pcVPS->setUseDLTFlag( i, uiCode == 1 ? true : false );
+        }
+        if( pcVPS->getUseDLTFlag( i ) )
+        {
+          // decode mapping
+          UInt uiNumDepthValues;
+          // parse number of values in DLT
+          READ_UVLC(uiNumDepthValues, "num_depth_values_in_dlt[i]");
+
+          // parse actual DLT values
+          Int* aiIdx2DepthValue = (Int*) calloc(uiNumDepthValues, sizeof(Int));
+          for(Int d=0; d<uiNumDepthValues; d++)
+          {
+            READ_UVLC(uiCode, "dlt_depth_value[i][d]");
+            aiIdx2DepthValue[d] = (Int)uiCode;
+          }
+
+          pcVPS->setDepthLUTs(i, aiIdx2DepthValue, uiNumDepthValues);
+
+          // clean memory
+          free(aiIdx2DepthValue);
+        }
+#endif
+#if LGE_INTER_SDC_E0156
+            READ_FLAG( uiCode, "depth_inter_SDC_flag" );              pcVPS->setInterSDCFlag( i, uiCode ? true : false );
+#endif
+      }
+    }
+  }
+  READ_FLAG( uiCode, "iv_mv_scaling_flag");                       pcVPS->setIvMvScalingFlag( uiCode == 1 ? true : false ); 
+}
+#endif
+#endif
 
 Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)
@@ -1129,4 +1680,17 @@
 #if H_MV
   vps = parameterSetManager->getPrefetchedVPS(sps->getVPSId());
+#if H_MV5
+  assert( vps != NULL );
+  
+  sps->inferRepFormat  ( vps , rpcSlice->getLayerId() ); 
+  sps->inferScalingList( parameterSetManager->getActiveSPS( sps->getSpsScalingListRefLayerId() ) );   
+
+  rpcSlice->setVPS(vps);      
+  rpcSlice->setViewId   ( vps->getViewId   ( rpcSlice->getLayerId() )      );
+  rpcSlice->setViewIndex( vps->getViewIndex( rpcSlice->getLayerId() )      );  
+#if H_3D  
+  rpcSlice->setIsDepth  ( vps->getDepthId  ( rpcSlice->getLayerId() ) == 1 );
+#endif
+#else
   assert(vps!=0);
   rpcSlice->setVPS(vps);      
@@ -1137,4 +1701,5 @@
 #endif
 #endif
+#endif
   rpcSlice->setSPS(sps);
   rpcSlice->setPPS(pps);
@@ -1182,4 +1747,20 @@
   {
 #if H_MV    
+#if H_MV5
+    Int esb = 0; //Don't use i, otherwise will shadow something below
+    if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
+    {
+      esb++; 
+      READ_FLAG( uiCode, "poc_reset_flag" ); rpcSlice->setPocResetFlag( uiCode == 1 );
+    }
+
+    if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
+    {
+      esb++; 
+      READ_FLAG( uiCode, "discardable_flag" ); rpcSlice->setDiscardableFlag( uiCode == 1 );
+    }
+
+    for (; esb < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); esb++)    
+#else
     if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > 0 )
     {
@@ -1188,4 +1769,5 @@
 
     for (Int i = 1; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)    
+#endif
 #else
     for (Int i = 0; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
@@ -1251,5 +1833,14 @@
       }
       rpcSlice->setPOC              (iPOCmsb+iPOClsb);
-
+#if H_MV5
+#if H_MV
+      if ( rpcSlice->getPocResetFlag() )  
+      {
+        rpcSlice->setPocBeforeReset   ( rpcSlice->getPOC() ); 
+        rpcSlice->setPOC              ( 0 );
+
+      }      
+#endif
+#endif
       TComReferencePictureSet* rps;
       rps = rpcSlice->getLocalRPS();
@@ -1379,4 +1970,24 @@
     }
 #if H_MV
+#if H_MV5
+    Int layerId       = rpcSlice->getLayerId(); 
+    if( rpcSlice->getLayerId() > 0 && !vps->getAllRefLayersActiveFlag() && vps->getNumDirectRefLayers( layerId ) > 0 )    {   
+      READ_FLAG( uiCode, "inter_layer_pred_enabled_flag" ); rpcSlice->setInterLayerPredEnabledFlag( uiCode == 1 );
+      if( rpcSlice->getInterLayerPredEnabledFlag() && vps->getNumDirectRefLayers( layerId ) > 1 )
+      {            
+        if( !vps->getMaxOneActiveRefLayerFlag())  
+        {
+          READ_CODE( rpcSlice->getNumInterLayerRefPicsMinus1Len( ), uiCode, "num_inter_layer_ref_pics_minus1" ); rpcSlice->setNumInterLayerRefPicsMinus1( uiCode );
+        }
+        if ( rpcSlice->getNumActiveRefLayerPics() != vps->getNumDirectRefLayers( layerId ) )
+        {
+          for( Int idx = 0; idx < rpcSlice->getNumActiveRefLayerPics(); idx++ )   
+          {
+            READ_CODE( rpcSlice->getInterLayerPredLayerIdcLen( ), uiCode, "inter_layer_pred_layer_idc" ); rpcSlice->setInterLayerPredLayerIdc( idx, uiCode );
+          }
+        }
+      }  
+    }
+#else
     Int layerIdInVps       = rpcSlice->getLayerIdInVps(); 
     if( rpcSlice->getLayerId() > 0 && vps->getNumDirectRefLayers( layerIdInVps ) > 0 )
@@ -1402,5 +2013,5 @@
       READ_FLAG( uiCode, "inter_layer_sample_pred_only_flag" ); rpcSlice->setInterLayerSamplePredOnlyFlag( uiCode == 1 );
     }
-
+#endif
 #endif
     if(sps->getUseSAO())
@@ -1544,4 +2155,5 @@
     if ( rpcSlice->getEnableTMVPFlag() )
     {
+#if !H_MV5
 #if H_MV
       if( rpcSlice->getLayerId() > 0 && rpcSlice->getNumActiveMotionPredRefLayers() > 0 )
@@ -1557,4 +2169,5 @@
       {
 #endif
+#endif
       if ( rpcSlice->getSliceType() == B_SLICE )
       {
@@ -1578,6 +2191,8 @@
         rpcSlice->setColRefIdx(0);
       }
-#if H_MV
-      }
+#if !H_MV5
+#if H_MV
+      }
+#endif
 #endif
     }
Index: branches/HTM-8.0-dev0/source/Lib/TLibDecoder/TDecCAVLC.h
===================================================================
--- branches/HTM-8.0-dev0/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 617)
+++ branches/HTM-8.0-dev0/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 618)
@@ -76,5 +76,20 @@
   Void  parseQtRootCbf      ( UInt uiAbsPartIdx, UInt& uiQtRootCbf );
   Void  parseVPS            ( TComVPS* pcVPS );
+#if H_MV5
+#if H_MV
+  Void  parseVPSExtension   ( TComVPS* pcVPS ); 
+  Void  parseRepFormat      ( TComRepFormat* pcRepFormat );
+  Void  parseVPSVUI         ( TComVPS* pcVPS );
+#endif
+
+#if H_MV
+  Void  parseSPSExtension   ( TComSPS* pcSPS );  
+#endif
+#endif
 #if H_3D
+#if H_MV5
+  Void  parseVPSExtension2  ( TComVPS* pcVPS ); 
+  Void  parseSPSExtension2  ( TComSPS* pcSPS, Int viewIndex, Bool depthFlag );
+#endif
   Void  parseSPS            ( TComSPS* pcSPS, Int viewIndex, Bool depthFlag );
 #else
Index: branches/HTM-8.0-dev0/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- branches/HTM-8.0-dev0/source/Lib/TLibDecoder/TDecCu.cpp	(revision 617)
+++ branches/HTM-8.0-dev0/source/Lib/TLibDecoder/TDecCu.cpp	(revision 618)
@@ -315,8 +315,23 @@
 #if H_3D_NBDV_REF
       if(pcCU->getSlice()->getVPS()->getDepthRefinementFlag( pcCU->getSlice()->getLayerIdInVps() ))  //Notes from QC: please check the condition for DoNBDV. Remove this comment once it is done.
+      {
         DvInfo.bDV = m_ppcCU[uiDepth]->getDisMvpCandNBDV(&DvInfo, true);
+      }
       else
 #endif
+      {
         DvInfo.bDV = m_ppcCU[uiDepth]->getDisMvpCandNBDV(&DvInfo);
+      }
+
+#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC   
+      if ( g_decTraceDispDer )
+      {
+        DTRACE_CU( "RefViewIdx",  DvInfo.m_aVIdxCan );       
+        DTRACE_CU( "MvDisp[x]", DvInfo.m_acNBDV.getHor() );
+        DTRACE_CU( "MvDisp[y]", DvInfo.m_acNBDV.getVer() );
+        DTRACE_CU( "MvRefinedDisp[x]", DvInfo.m_acDoNBDV.getHor() );
+        DTRACE_CU( "MvRefinedDisp[y]", DvInfo.m_acDoNBDV.getVer() );
+      }
+#endif
 
       pcCU->setDvInfoSubParts(DvInfo, uiAbsPartIdx, uiDepth);
@@ -389,4 +404,21 @@
         pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvd( cTmpMv, SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
         pcCU->getCUMvField( RefPicList( uiRefListIdx ) )->setAllMvField( cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ], SIZE_2Nx2N, uiAbsPartIdx, uiDepth );
+#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC   
+        if ( g_decTraceMvFromMerge )
+        {        
+          if ( uiRefListIdx == 0 )
+          {
+            DTRACE_PU( "mvL0[0]", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getHor());
+            DTRACE_PU( "mvL0[1]", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getVer());
+            DTRACE_PU( "refIdxL0   ", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getRefIdx());
+          }
+          else
+          {
+            DTRACE_PU( "mvL1[0]", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getHor());
+            DTRACE_PU( "mvL1[1]", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getVer());
+            DTRACE_PU( "refIdxL1", cMvFieldNeighbours[ 2*uiMergeIndex + uiRefListIdx ].getRefIdx());
+          }
+        }
+#endif
       }
     }
Index: branches/HTM-8.0-dev0/source/Lib/TLibDecoder/TDecSbac.cpp
===================================================================
--- branches/HTM-8.0-dev0/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 617)
+++ branches/HTM-8.0-dev0/source/Lib/TLibDecoder/TDecSbac.cpp	(revision 618)
@@ -584,8 +584,15 @@
   m_pcTDecBinIf->decodeBin(uiResidual, m_cSDCResidualFlagSCModel.get( 0, 0, 0 ) );
   
+#if H_MV_ENC_DEC_TRAC
+  DTRACE_CU("sdc_residual_flag[i]", uiResidual)
+#endif
+  
   if (uiResidual)
   {
     // decode residual sign bit
     m_pcTDecBinIf->decodeBinEP(uiSign);
+#if H_MV_ENC_DEC_TRAC
+    DTRACE_CU("sdc_residual_sign_flag[i]", uiSign)
+#endif
     
     // decode residual magnitude
@@ -617,5 +624,11 @@
     }
     else
+    {
       uiAbsIdx = uiCount;
+    }
+  
+#if H_MV_ENC_DEC_TRAC
+    DTRACE_CU("sdc_residual_abs_minus1[i]", uiAbsIdx)
+#endif
     
     uiAbsIdx += 1;
Index: branches/HTM-8.0-dev0/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- branches/HTM-8.0-dev0/source/Lib/TLibDecoder/TDecTop.cpp	(revision 617)
+++ branches/HTM-8.0-dev0/source/Lib/TLibDecoder/TDecTop.cpp	(revision 618)
@@ -436,4 +436,10 @@
   Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window();
 
+#if H_MV5
+#if H_MV
+    assert( conformanceWindow   .getScaledFlag() ); 
+    assert( defaultDisplayWindow.getScaledFlag() );
+#endif
+#endif
   for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
   {
@@ -512,5 +518,9 @@
   m_cCuDecoder.destroy();        
 #if H_MV 
+#if H_MV5
+  TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer0, m_refPicSetInterLayer1 );  
+#else
   TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer );  
+#endif
   TComSlice::markCurrPic( pcPic ); 
   TComSlice::markIvRefPicsAsUnused   ( m_ivPicLists, targetDecLayerIdSet, m_parameterSetManagerDecoder.getActiveVPS(), m_layerId, poc ); 
@@ -581,5 +591,15 @@
   assert (sps != 0);
 
+#if H_MV5
+#if H_MV
+  TComVPS* vps = m_parameterSetManagerDecoder.getVPS(sps->getVPSId());
+  assert (vps != 0); 
+  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP(), m_layerId ) )
+#else
   if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
+#endif
+#else
+  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
+#endif
   {
     printf ("Parameter set activation failed!");
@@ -607,5 +627,11 @@
   m_apcSlicePilot->setSPS(sps);
 #if H_MV
+#if H_MV5
+  m_apcSlicePilot->setVPS(vps);  
+  sps->inferRepFormat  ( vps , m_layerId ); 
+  sps->inferScalingList( m_parameterSetManagerDecoder.getActiveSPS( sps->getSpsScalingListRefLayerId() ) ); 
+#else
   m_apcSlicePilot->setVPS( m_parameterSetManagerDecoder.getActiveVPS() );
+#endif
 #endif
   pps->setSPS(sps);
@@ -669,5 +695,9 @@
 
 #if H_MV
+#if H_MV5
+  m_apcSlicePilot->setRefPicSetInterLayer( & m_refPicSetInterLayer0, &m_refPicSetInterLayer1 ); 
+#else
   m_apcSlicePilot->setRefPicSetInterLayer( & m_refPicSetInterLayer ); 
+#endif
   m_apcSlicePilot->setLayerId( nalu.m_layerId );
 #endif
@@ -676,4 +706,13 @@
 #if H_MV  
   TComVPS* vps     = m_apcSlicePilot->getVPS();
+#if H_MV5
+  Int layerId  = nalu.m_layerId;   
+  setViewId   ( vps->getViewId   ( layerId )      );  
+#if H_3D
+  setViewIndex( vps->getViewIndex( layerId )      );  
+  setIsDepth  ( vps->getDepthId  ( layerId ) == 1 );  
+  m_ivPicLists->setVPS( vps ); 
+#endif
+#else
   Int layerIdInVps = vps->getLayerIdInVps( nalu.m_layerId );  
   setViewId   ( vps->getViewId   ( layerIdInVps )      );  
@@ -684,4 +723,5 @@
 #endif
 #endif
+#endif
     // Skip pictures due to random access
     if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
@@ -723,4 +763,13 @@
 #endif
   // actual decoding starts here
+#if H_MV5
+#if H_MV
+   // This part needs further testing !
+   if ( m_apcSlicePilot->getPocResetFlag() )
+   {   
+     xResetPocInPicBuffer();
+   }
+#endif
+#endif
   xActivateParameterSets();
 
@@ -742,5 +791,9 @@
     m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
 #if H_MV
+#if H_MV5
+    m_apcSlicePilot->createInterLayerReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
+#else
     m_apcSlicePilot->createAndApplyIvReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer ); 
+#endif
 #endif
     //  Get a new picture buffer
@@ -888,9 +941,19 @@
     // Set reference list
 #if H_MV    
+#if H_MV5
+    std::vector< TComPic* > tempRefPicLists[2];
+    std::vector< Bool     > usedAsLongTerm [2];
+    Int       numPocTotalCurr;
+
+    pcSlice->getTempRefPicLists( m_cListPic, m_refPicSetInterLayer0, m_refPicSetInterLayer1, tempRefPicLists, usedAsLongTerm, numPocTotalCurr);
+    pcSlice->setRefPicList     ( tempRefPicLists, usedAsLongTerm, numPocTotalCurr, true ); 
+#else
     pcSlice->setRefPicList( m_cListPic, m_refPicSetInterLayer, true );    
+#endif
 #if H_3D_ARP
     pcSlice->setARPStepNum();
     if( pcSlice->getARPStepNum() > 1 )
     {
+      // GT: This seems to be broken, not all nuh_layer_ids are necessarily present
       for(Int iLayerId = 0; iLayerId < nalu.m_layerId; iLayerId ++ )
       {
@@ -1021,6 +1084,10 @@
   TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 ); 
   assert( vps != 0 ); 
+#if H_MV5
+  m_cEntropyDecoder.decodeSPS( sps, vps->getViewIndex( m_layerId ), ( vps->getDepthId( m_layerId ) == 1 ) );
+#else
   Int layerIdInVPS = vps->getLayerIdInVps( m_layerId ); 
   m_cEntropyDecoder.decodeSPS( sps, vps->getViewIndex( layerIdInVPS ), ( vps->getDepthId( layerIdInVPS ) == 1 ) );
+#endif
 #else
   m_cEntropyDecoder.decodeSPS( sps );
@@ -1032,4 +1099,9 @@
 {
   TComPPS* pps = new TComPPS();
+#if H_MV5
+#if H_MV
+  pps->setLayerId( getLayerId() ); 
+#endif
+#endif
   m_cEntropyDecoder.decodePPS( pps );
   m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
@@ -1040,9 +1112,25 @@
   if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
   {
+#if H_MV5
+#if H_MV
+    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS( m_layerId ) );
+#else
     m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
+#endif
+#else
+    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );  
+#endif
   }
   else
   {
+#if H_MV5
+#if H_MV
+    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS( m_layerId ) );
+#else
     m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
+#endif
+#else
+    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
+#endif
     SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
     if (activeParamSets.size()>0)
@@ -1051,5 +1139,13 @@
       m_parameterSetManagerDecoder.applyPrefetchedPS();
       assert(seiAps->activeSeqParamSetId.size()>0);
+#if H_MV5
+#if H_MV
+      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0], m_layerId ))
+#else
       if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
+#endif
+#else
+      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
+#endif
       {
         printf ("Warning SPS activation with Active parameter set SEI failed");
@@ -1210,4 +1306,22 @@
 }
 
+#if H_MV5
+Void TDecTop::xResetPocInPicBuffer()
+{
+  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
+  while (iterPic != m_cListPic.end())
+  {
+    TComPic* pic = *(iterPic++);
+    if ( pic->getReconMark() )
+    {
+      for( Int i = 0; i < pic->getNumAllocatedSlice(); i++)
+      {
+        TComSlice* slice = pic->getSlice( i ); 
+        slice->setPOC ( slice->getPOC() - m_apcSlicePilot->getPocBeforeReset() );            
+      }         
+    }     
+  }
+}
+#endif
 #endif
 //! \}
Index: branches/HTM-8.0-dev0/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- branches/HTM-8.0-dev0/source/Lib/TLibDecoder/TDecTop.h	(revision 617)
+++ branches/HTM-8.0-dev0/source/Lib/TLibDecoder/TDecTop.h	(revision 618)
@@ -216,5 +216,10 @@
   Int                     m_viewId;
   TComPicLists*           m_ivPicLists;
+#if H_MV5
+  std::vector<TComPic*>   m_refPicSetInterLayer0; 
+  std::vector<TComPic*>   m_refPicSetInterLayer1; 
+#else
   std::vector<TComPic*>   m_refPicSetInterLayer; 
+#endif
 #if H_3D
   Int                     m_viewIndex; 
@@ -274,4 +279,7 @@
   TComPic*  xGetPic( Int layerId, Int poc ); 
   Bool      xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool newLayerFlag );  
+#if H_MV5
+  Void      xResetPocInPicBuffer();
+#endif
 #else
   Bool      xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay);
Index: branches/HTM-8.0-dev0/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- branches/HTM-8.0-dev0/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 617)
+++ branches/HTM-8.0-dev0/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 618)
@@ -229,4 +229,19 @@
     }
   }
+#if H_MV5
+#if H_MV
+  if ( pcPPS->getLayerId() > 0 )
+  {
+    WRITE_FLAG( pcPPS->getPpsInferScalingListFlag( ) ? 1 : 0 , "pps_infer_scaling_list_flag" );
+  }
+
+  if( pcPPS->getPpsInferScalingListFlag( ) ) 
+  {
+    WRITE_CODE( pcPPS->getPpsScalingListRefLayerId( ), 6, "pps_scaling_list_ref_layer_id" );
+  }
+  else
+  {  
+#endif  
+#endif
   WRITE_FLAG( pcPPS->getScalingListPresentFlag() ? 1 : 0,                          "pps_scaling_list_data_present_flag" ); 
   if( pcPPS->getScalingListPresentFlag() )
@@ -237,4 +252,9 @@
     codeScalingList( m_pcSlice->getScalingList() );
   }
+#if H_MV5
+#if H_MV
+  }
+#endif
+#endif
   WRITE_FLAG( pcPPS->getListsModificationPresentFlag(), "lists_modification_present_flag");
   WRITE_UVLC( pcPPS->getLog2ParallelMergeLevelMinus2(), "log2_parallel_merge_level_minus2");
@@ -319,4 +339,5 @@
   {
     WRITE_FLAG(pcVUI->getTilesFixedStructureFlag(),             "tiles_fixed_structure_flag");
+#if !H_MV5
 #if H_MV
     if ( pcSPS->getLayerId() > 0 )
@@ -324,4 +345,5 @@
       WRITE_FLAG( pcVUI->getTileBoundariesAlignedFlag( ) ? 1 : 0 , "tile_boundaries_aligned_flag" );
     }
+#endif
 #endif
     WRITE_FLAG(pcVUI->getMotionVectorsOverPicBoundariesFlag(),  "motion_vectors_over_pic_boundaries_flag");
@@ -429,4 +451,15 @@
 #endif
   WRITE_UVLC( pcSPS->getSPSId (),                   "sps_seq_parameter_set_id" );
+#if H_MV5
+#if H_MV
+  if ( pcSPS->getLayerId() > 0 )
+  {
+    WRITE_FLAG( pcSPS->getUpdateRepFormatFlag( ) ? 1 : 0 , "update_rep_format_flag" );
+  }
+
+  if ( pcSPS->getUpdateRepFormatFlag() )
+  { 
+#endif
+#endif
   WRITE_UVLC( pcSPS->getChromaFormatIdc (),         "chroma_format_idc" );
   assert(pcSPS->getChromaFormatIdc () == 1);
@@ -439,4 +472,9 @@
   WRITE_UVLC( pcSPS->getPicWidthInLumaSamples (),   "pic_width_in_luma_samples" );
   WRITE_UVLC( pcSPS->getPicHeightInLumaSamples(),   "pic_height_in_luma_samples" );
+#if H_MV5
+#if H_MV
+  }
+#endif
+#endif
   Window conf = pcSPS->getConformanceWindow();
 
@@ -449,8 +487,17 @@
     WRITE_UVLC( conf.getWindowBottomOffset() / TComSPS::getWinUnitY(pcSPS->getChromaFormatIdc() ), "conf_win_bottom_offset" );
   }
-
+#if H_MV5
+#if H_MV
+  if ( pcSPS->getUpdateRepFormatFlag() )
+  { 
+#endif
+#endif
   WRITE_UVLC( pcSPS->getBitDepthY() - 8,             "bit_depth_luma_minus8" );
   WRITE_UVLC( pcSPS->getBitDepthC() - 8,             "bit_depth_chroma_minus8" );
-
+#if H_MV5
+#if H_MV
+  }
+#endif
+#endif
   WRITE_UVLC( pcSPS->getBitsForPOC()-4,                 "log2_max_pic_order_cnt_lsb_minus4" );
 
@@ -478,4 +525,19 @@
   if(pcSPS->getScalingListFlag())
   {
+#if H_MV5
+#if H_MV
+    if ( pcSPS->getLayerId() > 0 )
+    {    
+      WRITE_FLAG( pcSPS->getSpsInferScalingListFlag( ) ? 1 : 0 , "sps_infer_scaling_list_flag" );
+    }
+
+    if ( pcSPS->getSpsInferScalingListFlag() )
+    {
+      WRITE_CODE( pcSPS->getSpsScalingListRefLayerId( ), 6, "sps_scaling_list_ref_layer_id" );
+    }
+    else
+    {    
+#endif
+#endif
     WRITE_FLAG( pcSPS->getScalingListPresentFlag() ? 1 : 0,                          "sps_scaling_list_data_present_flag" ); 
     if(pcSPS->getScalingListPresentFlag())
@@ -486,4 +548,9 @@
       codeScalingList( m_pcSlice->getScalingList() );
     }
+#if H_MV5
+#if H_MV
+    }
+#endif
+#endif
   }
   WRITE_FLAG( pcSPS->getUseAMP() ? 1 : 0,                                            "amp_enabled_flag" );
@@ -531,4 +598,5 @@
   }
 
+#if !H_MV5
 #if H_MV
   WRITE_FLAG( 1, "sps_extension_flag" );
@@ -586,4 +654,57 @@
 #endif
 }
+#else
+#if !H_MV
+  WRITE_FLAG( 0, "sps_extension_flag" );
+#else
+  WRITE_FLAG( 1, "sps_extension_flag" );
+  codeSPSExtension( pcSPS ); 
+#if !H_3D
+  WRITE_FLAG( 0, "sps_extension2_flag" );
+#else
+  WRITE_FLAG( 1, "sps_extension2_flag" );
+  codeSPSExtension2( pcSPS, viewIndex, depthFlag ); 
+  WRITE_FLAG( 0, "sps_extension3_flag" );
+#endif  
+#endif
+}
+
+#if H_MV
+Void TEncCavlc::codeSPSExtension( TComSPS* pcSPS )
+{
+  WRITE_FLAG( pcSPS->getInterViewMvVertConstraintFlag() ? 1 : 0, "inter_view_mv_vert_constraint_flag" );
+  WRITE_UVLC( 0, "sps_shvc_reserved_zero_idc" ); 
+}
+#endif
+
+#if H_3D
+Void TEncCavlc::codeSPSExtension2( TComSPS* pcSPS, Int viewIndex, Bool depthFlag )
+{
+#if H_3D_QTLPC
+//GT: This has to go to VPS
+if( depthFlag )
+{
+  WRITE_FLAG( pcSPS->getUseQTL() ? 1 : 0, "use_qtl_flag");
+  WRITE_FLAG( pcSPS->getUsePC()  ? 1 : 0, "use_pc_flag");
+}
+#endif
+  if (!depthFlag )
+  {
+    WRITE_UVLC( pcSPS->getCamParPrecision(), "cp_precision" );
+    WRITE_FLAG( pcSPS->hasCamParInSliceHeader() ? 1 : 0, "cp_in_slice_header_flag" );
+    if( !pcSPS->hasCamParInSliceHeader() )
+    {
+      for( UInt uiIndex = 0; uiIndex < viewIndex; uiIndex++ )
+      {
+        WRITE_SVLC( pcSPS->getCodedScale    ()[ uiIndex ],                                      "cp_scale" );
+        WRITE_SVLC( pcSPS->getCodedOffset   ()[ uiIndex ],                                      "cp_off" );
+        WRITE_SVLC( pcSPS->getInvCodedScale ()[ uiIndex ] + pcSPS->getCodedScale ()[ uiIndex ], "cp_inv_scale_plus_scale" );
+        WRITE_SVLC( pcSPS->getInvCodedOffset()[ uiIndex ] + pcSPS->getCodedOffset()[ uiIndex ], "cp_inv_off_plus_off" );
+      }
+    }
+  }
+}
+#endif
+#endif
 
 Void TEncCavlc::codeVPS( TComVPS* pcVPS )
@@ -592,5 +713,9 @@
   WRITE_CODE( 3,                                    2,        "vps_reserved_three_2bits" );
 #if H_MV
+#if H_MV5
+  WRITE_CODE( pcVPS->getMaxLayersMinus1(),       6,        "vps_max_layers_minus1" );
+#else
   WRITE_CODE( pcVPS->getMaxLayers() - 1,            6,        "vps_max_layers_minus1" );
+#endif
 #else
   WRITE_CODE( 0,                                    6,        "vps_reserved_zero_6bits" );
@@ -675,4 +800,5 @@
     }
   }
+#if !H_MV5
 #if H_MV
   WRITE_FLAG( 1,                                             "vps_extension_flag" );
@@ -860,4 +986,339 @@
   return;
 }
+#else
+#if H_MV
+  WRITE_FLAG( 1,                     "vps_extension_flag" );
+  m_pcBitIf->writeAlignOne();
+  codeVPSExtension( pcVPS );                           
+#if H_3D
+  WRITE_FLAG( 1,                     "vps_extension2_flag" );
+  m_pcBitIf->writeAlignOne();      
+  codeVPSExtension2( pcVPS ); 
+  WRITE_FLAG( 0,                     "vps_extension3_flag" );
+#else
+  WRITE_FLAG( 0,                     "vps_extension2_flag" );
+#endif
+#else
+  WRITE_FLAG( 0,                     "vps_extension_flag" );
+#endif
+  //future extensions here..
+}
+
+#endif
+
+
+#if H_MV5
+#if H_MV
+Void TEncCavlc::codeVPSExtension( TComVPS *pcVPS ) 
+{
+  WRITE_FLAG( pcVPS->getAvcBaseLayerFlag() ? 1 : 0,          "avc_base_layer_flag" );
+  WRITE_CODE( pcVPS->getVpsVuiOffset( ), 16,                 "vps_vui_offset" );  // TBD
+  WRITE_FLAG( pcVPS->getSplittingFlag() ? 1 : 0,             "splitting_flag" );
+  
+  for( Int type = 0; type < MAX_NUM_SCALABILITY_TYPES; type++ )
+  {
+    WRITE_FLAG( pcVPS->getScalabilityMaskFlag( type ) ? 1 : 0,   "scalability_mask_flag[i]" );
+  }
+
+  for( Int sIdx = 0; sIdx < pcVPS->getNumScalabilityTypes( ) - ( pcVPS->getSplittingFlag() ? 1 : 0 ); sIdx++ )
+  {
+    WRITE_CODE( pcVPS->getDimensionIdLen( sIdx ) - 1 , 3,    "dimension_id_len_minus1[j]");    
+  }
+
+  if ( pcVPS->getSplittingFlag() )
+  { // Ignore old dimension id length
+    pcVPS->setDimensionIdLen( pcVPS->getNumScalabilityTypes( ) - 1 ,pcVPS->inferLastDimsionIdLenMinus1() + 1 );       
+  }    
+
+  WRITE_FLAG( pcVPS->getVpsNuhLayerIdPresentFlag() ? 1 : 0,  "vps_nuh_layer_id_present_flag");
+
+  for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
+  {
+    if ( pcVPS->getVpsNuhLayerIdPresentFlag() )
+    {      
+      WRITE_CODE( pcVPS->getLayerIdInNuh( i ), 6,          "layer_id_in_nuh[i]");
+  }
+    else
+    {
+      assert( pcVPS->getLayerIdInNuh( i ) == i ); 
+  }
+
+    assert(  pcVPS->getLayerIdInVps( pcVPS->getLayerIdInNuh( i ) ) == i ); 
+
+    for( Int j = 0; j < pcVPS->getNumScalabilityTypes() ; j++ )
+    {
+      if ( !pcVPS->getSplittingFlag() )
+      {
+        WRITE_CODE( pcVPS->getDimensionId( i, j ), pcVPS->getDimensionIdLen( j ), "dimension_id[i][j]");      
+      }
+      else
+      {
+        assert( pcVPS->getDimensionId( i, j ) ==  pcVPS->inferDimensionId( i, j )  );
+      }
+    }
+  }
+
+  // GT spec says: trac #39
+  // if ( pcVPS->getNumViews() > 1 )  
+  //   However, this is a bug in the text since, view_id_len_minus1 is needed to parse view_id_val. 
+  {
+    WRITE_CODE( pcVPS->getViewIdLenMinus1( ), 4, "view_id_len_minus1" );
+  }
+
+  for( Int i = 0; i < pcVPS->getNumViews(); i++ )
+  {
+    WRITE_CODE( pcVPS->getViewIdVal( i ), pcVPS->getViewIdLenMinus1( ) + 1, "view_id_val[i]" );
+  }
+
+  for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
+  {
+    for( Int j = 0; j < i; j++ )
+    {
+      WRITE_FLAG( pcVPS->getDirectDependencyFlag( i, j ),    "direct_dependency_flag[i][j]" );
+    }
+  }
+
+  WRITE_FLAG( pcVPS->getMaxTidRefPresentFlag( ) ? 1 : 0 , "max_tid_ref_present_flag" );
+
+  if ( pcVPS->getMaxTidRefPresentFlag() )
+  {    
+    for( Int i = 0; i < pcVPS->getMaxLayersMinus1(); i++ )
+    {
+      WRITE_CODE( pcVPS->getMaxTidIlRefPicPlus1( i ), 3,       "max_tid_il_ref_pics_plus1[i]" );
+    }
+  }
+
+  WRITE_FLAG( pcVPS->getAllRefLayersActiveFlag( ) ? 1 : 0 , "all_ref_layers_active_flag" );
+  WRITE_CODE( pcVPS->getVpsNumberLayerSetsMinus1( )    , 10,    "vps_number_layer_sets_minus1"      );
+  WRITE_CODE( pcVPS->getVpsNumProfileTierLevelMinus1( ), 6,     "vps_num_profile_tier_level_minus1" );
+
+  for( Int i = 1; i <= pcVPS->getVpsNumProfileTierLevelMinus1(); i++ )
+  {
+    WRITE_FLAG( pcVPS->getVpsProfilePresentFlag( i ) ? 1 : 0, "vps_profile_present_flag[i]" );
+    if( !pcVPS->getVpsProfilePresentFlag( i ) )
+    {    
+      WRITE_CODE( pcVPS->getProfileRefMinus1( i ), 6, "profile_ref_minus1[i]" );
+    }
+    codePTL( pcVPS->getPTL( i ), pcVPS->getVpsProfilePresentFlag( i ), pcVPS->getMaxTLayers() - 1 );
+  }
+
+  Int numOutputLayerSets = pcVPS->getVpsNumberLayerSetsMinus1( ) + 1; 
+
+  WRITE_FLAG( pcVPS->getMoreOutputLayerSetsThanDefaultFlag( ) ? 1 : 0, "more_output_layer_sets_than_default_flag" );
+
+  if ( pcVPS->getMoreOutputLayerSetsThanDefaultFlag( ) )
+  {
+    WRITE_CODE( pcVPS->getNumAddOutputLayerSetsMinus1( )    , 10,    "num_add_output_layer_sets_minus1"      );
+    numOutputLayerSets += ( pcVPS->getNumAddOutputLayerSetsMinus1( ) + 1 ); 
+  }
+
+  if( numOutputLayerSets > 1)
+  {
+    WRITE_FLAG( pcVPS->getDefaultOneTargetOutputLayerFlag( ) ? 1 : 0, "default_one_target_output_layer_flag" );
+  }  
+
+  for( Int i = 1; i < numOutputLayerSets; i++ )
+  {
+    if( i > pcVPS->getVpsNumberLayerSetsMinus1( ) )
+    {      
+      WRITE_UVLC( pcVPS->getOutputLayerSetIdxMinus1( i ),      "output_layer_set_idx_minus1[i]" );
+      for( Int j = 0; j < pcVPS->getNumLayersInIdList( j ) - 1 ; j++ )
+      {
+        WRITE_FLAG( pcVPS->getOutputLayerFlag( i, j) ? 1 : 0, "output_layer_flag" );
+      }      
+    }
+    if ( pcVPS->getProfileLevelTierIdxLen()  > 0 )
+    {      
+      WRITE_CODE( pcVPS->getProfileLevelTierIdx( i ), pcVPS->getProfileLevelTierIdxLen() ,"profile_level_tier_idx[ i ]" );   
+    }
+  }
+
+  WRITE_FLAG( pcVPS->getRepFormatIdxPresentFlag( ) ? 1 : 0 , "rep_format_idx_present_flag" );
+  if ( pcVPS->getRepFormatIdxPresentFlag() )
+  {
+    WRITE_CODE( pcVPS->getVpsNumRepFormatsMinus1( ), 4, "vps_num_rep_formats_minus1" );
+  }
+
+  for (Int i = 0; i <= pcVPS->getVpsNumRepFormatsMinus1(); i++ )
+  {    
+    TComRepFormat* pcRepFormat = pcVPS->getRepFormat(i);     
+    codeRepFormat( pcRepFormat ); 
+  }
+
+  if( pcVPS->getRepFormatIdxPresentFlag() ) 
+  {
+    for( Int i = 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
+    {
+      if( pcVPS->getVpsNumRepFormatsMinus1() > 0 )
+      {
+        WRITE_CODE( pcVPS->getVpsRepFormatIdx( i ), 4, "vps_rep_format_idx" );
+      }
+    }
+  }
+
+  WRITE_FLAG( pcVPS->getMaxOneActiveRefLayerFlag( ) ? 1 : 0, "max_one_active_ref_layer_flag" );
+  WRITE_FLAG( pcVPS->getCrossLayerIrapAlignedFlag( ) ? 1 : 0 , "cross_layer_irap_aligned_flag" );
+  WRITE_UVLC( pcVPS->getDirectDepTypeLenMinus2 ( ),         "direct_dep_type_len_minus2"); 
+
+    for( Int i = 1; i <= pcVPS->getMaxLayersMinus1(); i++ )
+    {
+      for( Int j = 0; j < i; j++ )
+      {
+        if (pcVPS->getDirectDependencyFlag( i, j) )
+        {        
+          assert ( pcVPS->getDirectDependencyType( i, j ) != -1 ); 
+          WRITE_CODE( pcVPS->getDirectDependencyType( i, j ),pcVPS->getDirectDepTypeLenMinus2( ) + 2,  "direct_dependency_type[i][j]" );
+        }
+      }
+    }
+    
+    WRITE_FLAG ( 0,                                      "vps_shvc_reserved_zero_flag" ); 
+    WRITE_FLAG( pcVPS->getVpsVuiPresentFlag( ) ? 1 : 0 , "vps_vui_present_flag" );
+
+    if( pcVPS->getVpsVuiPresentFlag() )
+    {
+      m_pcBitIf->writeAlignOne();  // vps_vui_alignment_bit_equal_to_one
+      codeVPSVUI( pcVPS ); 
+    }     
+}
+
+Void TEncCavlc::codeRepFormat( TComRepFormat* pcRepFormat )
+{
+  assert( pcRepFormat ); 
+
+  WRITE_CODE( pcRepFormat->getChromaFormatVpsIdc( ), 2, "chroma_format_vps_idc" );
+
+  if ( pcRepFormat->getChromaFormatVpsIdc() == 3 )
+  {
+    WRITE_FLAG( pcRepFormat->getSeparateColourPlaneVpsFlag( ) ? 1 : 0 , "separate_colour_plane_vps_flag" );
+  }
+  WRITE_CODE( pcRepFormat->getPicWidthVpsInLumaSamples( ),  16, "pic_width_vps_in_luma_samples" );
+  WRITE_CODE( pcRepFormat->getPicHeightVpsInLumaSamples( ), 16, "pic_height_vps_in_luma_samples" );
+  WRITE_CODE( pcRepFormat->getBitDepthVpsLumaMinus8( ),      4, "bit_depth_vps_luma_minus8" );
+  WRITE_CODE( pcRepFormat->getBitDepthVpsChromaMinus8( ),    4, "bit_depth_vps_chroma_minus8" );
+}
+
+Void TEncCavlc::codeVPSVUI( TComVPS* pcVPS )
+{
+  assert( pcVPS ); 
+
+  TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( ); 
+
+  assert( pcVPSVUI ); 
+
+  WRITE_FLAG( pcVPSVUI->getBitRatePresentVpsFlag( ) ? 1 : 0 , "bit_rate_present_vps_flag" );
+  WRITE_FLAG( pcVPSVUI->getPicRatePresentVpsFlag( ) ? 1 : 0 , "pic_rate_present_vps_flag" );
+  if( pcVPSVUI->getBitRatePresentVpsFlag( )  ||  pcVPSVUI->getPicRatePresentVpsFlag( ) )
+  {
+    for( Int i = 0; i  <=  pcVPS->getVpsNumberLayerSetsMinus1(); i++ )
+    {
+      for( Int j = 0; j  <=  pcVPS->getMaxTLayers(); j++ ) 
+      {
+        if( pcVPSVUI->getBitRatePresentVpsFlag( ) )
+        {
+          WRITE_FLAG( pcVPSVUI->getBitRatePresentFlag( i, j ) ? 1 : 0 , "bit_rate_present_flag" );
+        }
+        if( pcVPSVUI->getBitRatePresentVpsFlag( )  )
+        {
+          WRITE_FLAG( pcVPSVUI->getPicRatePresentFlag( i, j ) ? 1 : 0 , "pic_rate_present_flag" );
+        }
+        if( pcVPSVUI->getBitRatePresentFlag( i, j ) )
+        {
+          WRITE_CODE( pcVPSVUI->getAvgBitRate( i, j ), 16, "avg_bit_rate" );
+          WRITE_CODE( pcVPSVUI->getMaxBitRate( i, j ), 16, "max_bit_rate" );
+        }
+        if( pcVPSVUI->getPicRatePresentFlag( i, j ) )
+        {
+          WRITE_CODE( pcVPSVUI->getConstantPicRateIdc( i, j ), 2, "constant_pic_rate_idc" );
+          WRITE_CODE( pcVPSVUI->getAvgPicRate( i, j ), 16, "avg_pic_rate" );
+        }
+      }
+    }
+  }
+
+  for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
+  {
+    for( Int  j = 0; j < pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i ) ); j++ ) 
+    {
+      WRITE_FLAG( pcVPSVUI->getTileBoundariesAlignedFlag( i, j ) ? 1 : 0 , "tile_boundaries_aligned_flag" );
+    }
+  }
+
+  WRITE_FLAG( pcVPSVUI->getIlpRestrictedRefLayersFlag( ) ? 1 : 0 , "ilp_restricted_ref_layers_flag" );
+
+  if( pcVPSVUI->getIlpRestrictedRefLayersFlag( ) )
+  {
+    for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
+    {
+      for( Int j = 0; j < pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i ) ); j++ )
+      {
+        WRITE_UVLC( pcVPSVUI->getMinSpatialSegmentOffsetPlus1( i, j ), "min_spatial_segment_offset_plus1" );
+        if( pcVPSVUI->getMinSpatialSegmentOffsetPlus1( i, j ) > 0 )
+        {
+          WRITE_FLAG( pcVPSVUI->getCtuBasedOffsetEnabledFlag( i, j ) ? 1 : 0 , "ctu_based_offset_enabled_flag" );
+          if( pcVPSVUI->getCtuBasedOffsetEnabledFlag( i, j ) )
+          {
+            WRITE_UVLC( pcVPSVUI->getMinHorizontalCtuOffsetPlus1( i, j ), "min_horizontal_ctu_offset_plus1" );
+          }
+        }
+      }
+    }
+  }
+}
+#endif
+
+#if H_3D
+Void TEncCavlc::codeVPSExtension2( TComVPS* pcVPS )
+{ 
+  for( Int i = 0; i <= pcVPS->getMaxLayersMinus1(); i++ )
+  {
+    if (i!= 0)
+    {
+      if ( !( pcVPS->getDepthId( i ) == 1 ) )
+      {
+#if H_3D_IV_MERGE
+        WRITE_FLAG( pcVPS->getIvMvPredFlag         ( i ) ? 1 : 0 , "iv_mv_pred_flag[i]");
+#endif
+#if H_3D_ARP
+        WRITE_FLAG( pcVPS->getUseAdvRP             ( i ) ? 1 : 0,  "iv_res_pred_flag[i]"  );
+#endif
+#if H_3D_NBDV_REF
+        WRITE_FLAG( pcVPS->getDepthRefinementFlag  ( i ) ? 1 : 0 , "depth_refinement_flag[i]");
+#endif
+#if H_3D_VSP
+        WRITE_FLAG( pcVPS->getViewSynthesisPredFlag( i ) ? 1 : 0 , "view_synthesis_pred_flag[i]");
+#endif
+      }          
+      else
+      {
+        WRITE_FLAG( pcVPS->getVpsDepthModesFlag( i ) ? 1 : 0 ,          "vps_depth_modes_flag[i]" );
+        //WRITE_FLAG( pcVPS->getLimQtPredFlag    ( i ) ? 1 : 0 ,          "lim_qt_pred_flag[i]"     ); 
+#if H_3D_DIM_DLT
+        if( pcVPS->getVpsDepthModesFlag( i ) )
+        {
+          WRITE_FLAG( pcVPS->getUseDLTFlag( i ) ? 1 : 0, "dlt_flag[i]" );
+        }
+        if( pcVPS->getUseDLTFlag( i ) )
+        {
+          // code mapping
+          WRITE_UVLC(pcVPS->getNumDepthValues(i), "num_depth_values_in_dlt[i]");
+          for(Int d=0; d<pcVPS->getNumDepthValues(i); d++)
+          {
+            WRITE_UVLC( pcVPS->idx2DepthValue(i, d), "dlt_depth_value[i][d]" );
+          }
+        }        
+#endif
+#if LGE_INTER_SDC_E0156
+        WRITE_FLAG( pcVPS->getInterSDCFlag( i ) ? 1 : 0, "depth_inter_SDC_flag" );
+#endif
+      }
+    }  
+  }
+#if H_3D_TMVP
+  WRITE_FLAG( pcVPS->getIvMvScalingFlag( ) ? 1 : 0 ,          "iv_mv_scaling_flag" );
+#endif
+}
+#endif
+#endif
 
 Void TEncCavlc::codeSliceHeader         ( TComSlice* pcSlice )
@@ -909,4 +1370,20 @@
   {
 #if H_MV    
+#if H_MV5
+    Int esb = 0;  //Don't use i, otherwise will shadow something below
+    if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
+    {
+      esb++; 
+      WRITE_FLAG( pcSlice->getPocResetFlag( ) ? 1 : 0 , "poc_reset_flag" );
+    }
+
+    if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
+    {
+      esb++; 
+      WRITE_FLAG( pcSlice->getDiscardableFlag( ) ? 1 : 0 , "discardable_flag" );
+    }
+
+    for (; esb < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); esb++)    
+#else
     if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > 0 )
     {
@@ -915,4 +1392,5 @@
 
     for (Int i = 1; i < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)    
+#endif
 #else
     for (Int i = 0; i < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
@@ -1052,4 +1530,25 @@
     }
 #if H_MV
+#if H_MV5
+    Int layerId = pcSlice->getLayerId(); 
+    if( pcSlice->getLayerId() > 0 && !vps->getAllRefLayersActiveFlag() && vps->getNumDirectRefLayers( layerId ) > 0 )
+    {   
+      WRITE_FLAG( pcSlice->getInterLayerPredEnabledFlag( ) ? 1 : 0 , "inter_layer_pred_enabled_flag" );
+      if( pcSlice->getInterLayerPredEnabledFlag() && vps->getNumDirectRefLayers( layerId ) > 1 )
+      {            
+        if( !vps->getMaxOneActiveRefLayerFlag())  
+        {
+          WRITE_CODE( pcSlice->getNumInterLayerRefPicsMinus1( ), pcSlice->getNumInterLayerRefPicsMinus1Len( ), "num_inter_layer_ref_pics_minus1" );
+        }
+        if ( pcSlice->getNumActiveRefLayerPics() != vps->getNumDirectRefLayers( layerId ) )
+        {        
+          for( Int idx = 0; idx < pcSlice->getNumActiveRefLayerPics(); idx++ )   
+          {
+            WRITE_CODE( pcSlice->getInterLayerPredLayerIdc( idx ), pcSlice->getInterLayerPredLayerIdcLen( ), "inter_layer_pred_layer_idc" );
+          }
+        }
+      }  
+    }
+#else
     Int layerIdInVps       = pcSlice->getLayerIdInVps(); 
     if( pcSlice->getLayerId() > 0 && vps->getNumDirectRefLayers( layerIdInVps ) > 0 )
@@ -1074,4 +1573,5 @@
     }
 
+#endif
 #endif
     if(pcSlice->getSPS()->getUseSAO())
@@ -1178,4 +1678,5 @@
     if ( pcSlice->getEnableTMVPFlag() )
     {
+#if !H_MV5
 #if H_MV
       if( pcSlice->getLayerId() > 0 && pcSlice->getNumActiveMotionPredRefLayers() > 0 )
@@ -1190,4 +1691,5 @@
       {
 #endif
+#endif
       if ( pcSlice->getSliceType() == B_SLICE )
       {
@@ -1202,6 +1704,8 @@
       }
     }
+#if !H_MV5
 #if H_MV
     }
+#endif
 #endif
     if ( (pcSlice->getPPS()->getUseWP() && pcSlice->getSliceType()==P_SLICE) || (pcSlice->getPPS()->getWPBiPred() && pcSlice->getSliceType()==B_SLICE) )
Index: branches/HTM-8.0-dev0/source/Lib/TLibEncoder/TEncCavlc.h
===================================================================
--- branches/HTM-8.0-dev0/source/Lib/TLibEncoder/TEncCavlc.h	(revision 617)
+++ branches/HTM-8.0-dev0/source/Lib/TLibEncoder/TEncCavlc.h	(revision 618)
@@ -84,6 +84,22 @@
   UInt  getCoeffCost          ()                { return  m_uiCoeffCost;  }
   Void  codeVPS                 ( TComVPS* pcVPS );
+#if H_MV5
+#if H_MV
+  Void  codeVPSExtension       ( TComVPS *pcVPS );
+  Void  codeRepFormat          ( TComRepFormat* pcRepFormat );
+  Void  codeVPSVUI             ( TComVPS* pcVPS );
+#endif 
+#endif
   Void  codeVUI                 ( TComVUI *pcVUI, TComSPS* pcSPS );
+#if H_MV5
+#if H_MV
+  Void  codeSPSExtension        ( TComSPS* pcSPS ); 
+#endif
+#endif
 #if H_3D
+#if H_MV5
+  Void  codeVPSExtension2       ( TComVPS* pcVPS ); 
+  Void  codeSPSExtension2       ( TComSPS* pcSPS, Int viewIndex, Bool depthFlag  ); 
+#endif
   Void  codeSPS                 ( TComSPS* pcSPS, Int viewIndex, Bool depthFlag );
 #else
Index: branches/HTM-8.0-dev0/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- branches/HTM-8.0-dev0/source/Lib/TLibEncoder/TEncCfg.h	(revision 617)
+++ branches/HTM-8.0-dev0/source/Lib/TLibEncoder/TEncCfg.h	(revision 618)
@@ -77,5 +77,7 @@
   Int m_interLayerPredLayerIdc [MAX_NUM_REF_PICS];
   Int m_interViewRefPosL[2][MAX_NUM_REF_PICS];  
+#if !H_MV5
   Int m_collocatedRefLayerIdx; 
+#endif
 #endif
   GOPEntry()
@@ -95,5 +97,7 @@
 #if H_MV
   , m_numActiveRefLayerPics(0)
+#if !H_MV5
   , m_collocatedRefLayerIdx(-1)
+#endif
 #endif
   {
@@ -357,8 +361,13 @@
   Int       m_layerIdInVps;
   Int       m_viewId;
+#if H_MV5
+  Int       m_viewIndex; 
+#endif
 #endif 
 
 #if H_3D
+#if !H_MV5
   Int       m_viewIndex; 
+#endif
   Bool      m_isDepth;
 
@@ -417,6 +426,11 @@
   , m_layerIdInVps(-1)
   , m_viewId(-1)
+#if H_MV5
+  , m_viewIndex(-1)
+#endif
 #if H_3D
+#if !H_MV5
   , m_viewIndex(-1)
+#endif
   , m_isDepth(false)
   , m_bUseVSO(false)
@@ -451,7 +465,13 @@
   Void      setViewId                        ( Int viewId  )      { m_viewId  = viewId;  }
   Int       getViewId                        ()                   { return m_viewId;    }
-#if H_3D
+#if H_MV5
   Void      setViewIndex                     ( Int viewIndex  )   { m_viewIndex  = viewIndex;  }
   Int       getViewIndex                     ()                   { return m_viewIndex;    }
+#endif
+#if H_3D
+#if !H_MV5
+  Void      setViewIndex                     ( Int viewIndex  )   { m_viewIndex  = viewIndex;  }
+  Int       getViewIndex                     ()                   { return m_viewIndex;    }
+#endif
   Void      setIsDepth                       ( Bool isDepth )   { m_isDepth = isDepth; }
   Bool      getIsDepth                       ()                 { return m_isDepth; }
Index: branches/HTM-8.0-dev0/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- branches/HTM-8.0-dev0/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 617)
+++ branches/HTM-8.0-dev0/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 618)
@@ -471,13 +471,26 @@
     pcPic->setCurrSliceIdx(0);
 
+
+#if H_MV5
+#if H_MV
+    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getVPS(), m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), getLayerId() );     
+#else
+    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS() );
+#endif
+#else
 #if H_3D
     m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getVPS(), m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), getLayerId() );     
 #else
     m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS() );
+#endif
 #endif
     pcSlice->setLastIDR(m_iLastIDR);
     pcSlice->setSliceIdx(0);
 #if H_MV
+#if H_MV5
+    pcSlice->setRefPicSetInterLayer ( &m_refPicSetInterLayer0, &m_refPicSetInterLayer1 ); 
+#else
     pcSlice->setRefPicSetInterLayer ( &m_refPicSetInterLayer ); 
+#endif
     pcPic  ->setLayerId     ( getLayerId()   );
     pcPic  ->setViewId      ( getViewId()    );    
@@ -642,4 +655,48 @@
     refPicListModification->setRefPicListModificationFlagL1(0);
 #if H_MV
+#if H_MV5
+    if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > 1 )
+    {
+      // Some more sophisticated algorithm to determine discardable_flag might be added here. 
+      pcSlice->setDiscardableFlag           ( false );     
+    }    
+
+    TComVPS*           vps = pcSlice->getVPS();     
+    Int numDirectRefLayers = vps    ->getNumDirectRefLayers( getLayerId() ); 
+    GOPEntry gopEntry      = m_pcCfg->getGOPEntry( (pcSlice->getRapPicFlag() && getLayerId() > 0) ? MAX_GOP : iGOPid );     
+    
+    if ( getLayerId() > 0 && !vps->getAllRefLayersActiveFlag() && numDirectRefLayers > 0 )
+    {         
+      pcSlice->setInterLayerPredEnabledFlag ( gopEntry.m_numActiveRefLayerPics > 0 );     
+      if ( pcSlice->getInterLayerPredEnabledFlag() && numDirectRefLayers > 1 )
+      {
+        if ( !vps->getMaxOneActiveRefLayerFlag() )
+        {    
+          pcSlice->setNumInterLayerRefPicsMinus1( gopEntry.m_numActiveRefLayerPics - 1 ); 
+        }
+        if ( gopEntry.m_numActiveRefLayerPics != vps->getNumDirectRefLayers( getLayerId() ) )
+        {        
+          for (Int i = 0; i < gopEntry.m_numActiveRefLayerPics; i++ )
+          {
+            pcSlice->setInterLayerPredLayerIdc( i, gopEntry.m_interLayerPredLayerIdc[ i ] ); 
+          }
+        }
+      }
+    }
+    assert( pcSlice->getNumActiveRefLayerPics() == gopEntry.m_numActiveRefLayerPics ); 
+    
+    pcSlice->createInterLayerReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
+    pcSlice->setNumRefIdx(REF_PIC_LIST_0,min(gopEntry.m_numRefPicsActive,( pcSlice->getRPS()->getNumberOfPictures() + (Int) m_refPicSetInterLayer0.size() + (Int) m_refPicSetInterLayer1.size()) ) );
+    pcSlice->setNumRefIdx(REF_PIC_LIST_1,min(gopEntry.m_numRefPicsActive,( pcSlice->getRPS()->getNumberOfPictures() + (Int) m_refPicSetInterLayer0.size() + (Int) m_refPicSetInterLayer1.size()) ) );
+
+    std::vector< TComPic* >    tempRefPicLists[2];
+    std::vector< Bool     >    usedAsLongTerm [2];
+    Int       numPocTotalCurr;
+
+    pcSlice->getTempRefPicLists( rcListPic, m_refPicSetInterLayer0, m_refPicSetInterLayer1, tempRefPicLists, usedAsLongTerm, numPocTotalCurr, true );
+    
+
+    xSetRefPicListModificationsMv( tempRefPicLists, pcSlice, iGOPid );    
+#else
     if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > 0 )
     {
@@ -692,4 +749,5 @@
     }
 
+#endif
 #else
     pcSlice->setNumRefIdx(REF_PIC_LIST_0,min(m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive,pcSlice->getRPS()->getNumberOfPictures()));
@@ -702,4 +760,28 @@
 
     //  Set reference list
+#if H_MV5
+#if H_MV    
+    pcSlice->setRefPicList( tempRefPicLists, usedAsLongTerm, numPocTotalCurr ); 
+#else
+    pcSlice->setRefPicList ( rcListPic );
+#endif
+  
+#if H_3D_ARP
+    //GT: This seems to be broken when layerId in vps is not equal to layerId in nuh
+    pcSlice->setARPStepNum();
+    if(pcSlice->getARPStepNum() > 1)
+    {
+      for(Int iLayerId = 0; iLayerId < getLayerId(); iLayerId ++ )
+      {
+        Int  iViewIdx =   pcSlice->getVPS()->getViewIndex(iLayerId);
+        Bool bIsDepth = ( pcSlice->getVPS()->getDepthId  ( iLayerId ) == 1 );
+        if( iViewIdx<getViewIndex() && !bIsDepth )
+        {
+          pcSlice->setBaseViewRefPicList( m_ivPicLists->getPicList( iLayerId ), iViewIdx );
+        }
+      }
+    }
+#endif
+#else
 #if H_MV    
     pcSlice->setRefPicList( rcListPic, m_refPicSetInterLayer );
@@ -722,5 +804,5 @@
     pcSlice->setRefPicList ( rcListPic );
 #endif
-
+#endif
 #if H_3D
     pcSlice->setIvPicLists( m_ivPicLists );         
@@ -2084,5 +2166,9 @@
       pcPic->setReconMark   ( true );
 #if H_MV
+#if H_MV5
+      TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer0, m_refPicSetInterLayer1 );  
+#else
       TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer );  
+#endif
       std::vector<Int> temp; 
       TComSlice::markCurrPic( pcPic ); 
@@ -2916,4 +3002,89 @@
 
 #if H_MV
+#if H_MV5
+Void TEncGOP::xSetRefPicListModificationsMv( std::vector<TComPic*> tempPicLists[2], TComSlice* pcSlice, UInt iGOPid )
+{ 
+  
+  if( pcSlice->getSliceType() == I_SLICE || !(pcSlice->getPPS()->getListsModificationPresentFlag()) || pcSlice->getNumActiveRefLayerPics() == 0 )
+  {
+    return;
+  }
+  
+  GOPEntry ge = m_pcCfg->getGOPEntry( (pcSlice->getRapPicFlag() && ( pcSlice->getLayerId( ) > 0) ) ? MAX_GOP : iGOPid );
+  assert( ge.m_numActiveRefLayerPics == pcSlice->getNumActiveRefLayerPics() ); 
+
+  Int numPicsInTempList     = pcSlice->getNumRpsCurrTempList();  
+
+  // GT: check if SliceType should be checked here. 
+  for (Int li = 0; li < 2; li ++) // Loop over lists L0 and L1
+  {
+    Int numPicsInFinalRefList = pcSlice->getNumRefIdx( ( li == 0 ) ? REF_PIC_LIST_0 : REF_PIC_LIST_1 ); 
+            
+    Int finalIdxToTempIdxMap[16];
+    for( Int k = 0; k < 16; k++ )
+    {
+      finalIdxToTempIdxMap[ k ] = -1;
+    }
+
+    Bool isModified = false;
+    if ( numPicsInTempList > 1 )
+    {
+      for( Int k = 0; k < pcSlice->getNumActiveRefLayerPics(); k++ )
+      {
+        // get position in temp. list
+        Int refPicLayerId = pcSlice->getRefPicLayerId(k);
+        Int idxInTempList = 0; 
+        for (; idxInTempList < numPicsInTempList; idxInTempList++)
+        {
+          if ( (tempPicLists[li][idxInTempList])->getLayerId() == refPicLayerId )
+          {
+            break; 
+          }
+        }
+
+        Int idxInFinalList = ge.m_interViewRefPosL[ li ][ k ];
+        
+        // Add negative from behind 
+        idxInFinalList = ( idxInFinalList < 0 )? ( numPicsInTempList + idxInFinalList ) : idxInFinalList; 
+        
+        Bool curIsModified = ( idxInFinalList != idxInTempList ) && ( ( idxInTempList < numPicsInFinalRefList ) || ( idxInFinalList < numPicsInFinalRefList ) ) ;
+        if ( curIsModified )
+        {
+          isModified = true; 
+          assert( finalIdxToTempIdxMap[ idxInFinalList ] == -1 ); // Assert when two inter layer reference pictures are sorted to the same position
+        }
+        finalIdxToTempIdxMap[ idxInFinalList ] = idxInTempList;              
+      }
+    }
+
+    TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification();
+    refPicListModification->setRefPicListModificationFlagL( li, isModified );  
+
+    if( isModified )
+    {
+      Int refIdx = 0;
+      
+      for( Int i = 0; i < numPicsInFinalRefList; i++ )
+      {
+        if( finalIdxToTempIdxMap[i] >= 0 ) 
+        {
+          refPicListModification->setRefPicSetIdxL( li, i, finalIdxToTempIdxMap[i] );
+        }
+        else
+        {
+          ///* Fill gaps with temporal references *///
+          // Forward inter layer reference pictures
+          while( ( refIdx < numPicsInTempList ) && ( tempPicLists[li][refIdx]->getLayerId() != getLayerId())  )
+          {
+            refIdx++; 
+          }
+          refPicListModification->setRefPicSetIdxL( li, i, refIdx );
+          refIdx++;
+        }
+      }
+    }
+  }
+}
+#else
 Void TEncGOP::xSetRefPicListModificationsMv( TComSlice* pcSlice, UInt iGOPid )
 { 
@@ -2979,3 +3150,4 @@
 }
 #endif
+#endif
 //! \}
Index: branches/HTM-8.0-dev0/source/Lib/TLibEncoder/TEncGOP.h
===================================================================
--- branches/HTM-8.0-dev0/source/Lib/TLibEncoder/TEncGOP.h	(revision 617)
+++ branches/HTM-8.0-dev0/source/Lib/TLibEncoder/TEncGOP.h	(revision 618)
@@ -99,5 +99,10 @@
 #if H_MV
   TComPicLists*           m_ivPicLists;
+#if H_MV5
+  std::vector<TComPic*>   m_refPicSetInterLayer0; 
+  std::vector<TComPic*>   m_refPicSetInterLayer1; 
+#else
   std::vector<TComPic*>   m_refPicSetInterLayer; 
+#endif
 
   Int                     m_pocLastCoded;
@@ -211,5 +216,9 @@
   }
 #if H_MV
+#if H_MV5
+   Void  xSetRefPicListModificationsMv( std::vector<TComPic*> tempPicLists[2], TComSlice* pcSlice, UInt iGOPid );
+#else
    Void  xSetRefPicListModificationsMv( TComSlice* pcSlice, UInt iGOPid );
+#endif
 #endif
   Void dblMetric( TComPic* pcPic, UInt uiNumSlices );
Index: branches/HTM-8.0-dev0/source/Lib/TLibEncoder/TEncSbac.cpp
===================================================================
--- branches/HTM-8.0-dev0/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 617)
+++ branches/HTM-8.0-dev0/source/Lib/TLibEncoder/TEncSbac.cpp	(revision 618)
@@ -649,4 +649,7 @@
   // residual flag
   m_pcBinIf->encodeBin( uiResidual, m_cSDCResidualFlagSCModel.get( 0, 0, 0 ) );
+#if H_MV_ENC_DEC_TRAC
+  DTRACE_CU("sdc_residual_flag[i]", uiResidual)
+#endif  
   
   if (uiResidual)
@@ -654,4 +657,7 @@
     // encode sign bit of residual
     m_pcBinIf->encodeBinEP( uiSign );
+#if H_MV_ENC_DEC_TRAC
+    DTRACE_CU("sdc_residual_sign_flag[i]", uiSign)
+#endif
     
 #if H_3D_DIM_DLT
@@ -664,7 +670,14 @@
     // encode residual magnitude
     uiAbsIdx -= 1;
+
+#if H_MV_ENC_DEC_TRAC
+    DTRACE_CU("sdc_residual_abs_minus1[i]", uiAbsIdx)
+#endif
+
     // prefix part
     if ( uiAbsIdx == 0 )
+    {
       m_pcBinIf->encodeBin( 0, m_cSDCResidualSCModel.get(0, 0, 0) );
+    }
     else
     {
@@ -679,8 +692,9 @@
       }
       if ( uiAbsIdx < uiPrefixThreshold )
+      {
         m_pcBinIf->encodeBin( 0, m_cSDCResidualSCModel.get(0, 0, 0) );
-      // suffix part
+      }      
       else
-      {
+      { // suffix part
         uiAbsIdx -= uiPrefixThreshold;
         UInt uiSuffixLength = numBitsForValue(uiNumDepthValues - uiPrefixThreshold);
Index: branches/HTM-8.0-dev0/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- branches/HTM-8.0-dev0/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 617)
+++ branches/HTM-8.0-dev0/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 618)
@@ -176,8 +176,16 @@
  \param pPPS          PPS associated with the slice
  */
+#if H_MV5
+#if H_MV
+Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComVPS* pVPS, TComSPS* pSPS, TComPPS *pPPS, Int layerId )
+#else
+Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS )
+#endif
+#else
 #if H_3D
 Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComVPS* pVPS, TComSPS* pSPS, TComPPS *pPPS, Int layerId )
 #else
 Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS )
+#endif
 #endif
 {
@@ -186,4 +194,15 @@
   
   rpcSlice = pcPic->getSlice(0);
+
+#if H_MV5
+  rpcSlice->setVPS( pVPS ); 
+
+  rpcSlice->setLayerId     ( layerId );
+  rpcSlice->setViewId      ( pVPS->getViewId      ( layerId ) );    
+  rpcSlice->setViewIndex   ( pVPS->getViewIndex   ( layerId ) );
+#if H_3D
+  rpcSlice->setIsDepth     ( pVPS->getDepthId     ( layerId ) != 0 );    
+#endif
+#else
 #if H_3D
   // GT: Should also be activated for MV-HEVC at some stage
@@ -195,4 +214,5 @@
   rpcSlice->setViewIndex   ( pVPS->getViewIndex   ( vpsLayerId ) );
   rpcSlice->setIsDepth     ( pVPS->getDepthId     ( vpsLayerId ) != 0 );    
+#endif
 #endif
   rpcSlice->setSPS( pSPS );
Index: branches/HTM-8.0-dev0/source/Lib/TLibEncoder/TEncSlice.h
===================================================================
--- branches/HTM-8.0-dev0/source/Lib/TLibEncoder/TEncSlice.h	(revision 617)
+++ branches/HTM-8.0-dev0/source/Lib/TLibEncoder/TEncSlice.h	(revision 618)
@@ -116,4 +116,13 @@
   
   /// preparation of slice encoding (reference marking, QP and lambda)
+#if H_MV5
+#if H_MV
+  Void    initEncSlice        ( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, 
+                                Int iGOPid, TComSlice*& rpcSlice, TComVPS* pVPS, TComSPS* pSPS, TComPPS *pPPS, Int layerId ); 
+#else
+  Void    initEncSlice        ( TComPic*  pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd,
+                                Int iGOPid,   TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS );
+#endif
+#else
 #if H_3D
   Void    initEncSlice        ( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, 
@@ -122,4 +131,5 @@
   Void    initEncSlice        ( TComPic*  pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd,
                                 Int iGOPid,   TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS );
+#endif
 #endif
 #if RATE_CONTROL_LAMBDA_DOMAIN
Index: branches/HTM-8.0-dev0/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- branches/HTM-8.0-dev0/source/Lib/TLibEncoder/TEncTop.cpp	(revision 617)
+++ branches/HTM-8.0-dev0/source/Lib/TLibEncoder/TEncTop.cpp	(revision 618)
@@ -548,4 +548,11 @@
    * that chooses the actual compatibility based upon options */
 
+#if H_MV5
+#if H_MV  
+  m_cSPS.setUpdateRepFormatFlag           ( m_layerId == 0 );    
+  m_cSPS.setSpsInferScalingListFlag       ( m_layerId > 0 && m_cVPS->getInDirectDependencyFlag( getLayerIdInVps(), 0 ) ); 
+  m_cSPS.setSpsScalingListRefLayerId      ( 0              ); 
+#endif
+#endif
   m_cSPS.setPicWidthInLumaSamples         ( m_iSourceWidth      );
   m_cSPS.setPicHeightInLumaSamples        ( m_iSourceHeight     );
@@ -670,5 +677,10 @@
 {
 #if H_MV
+#if H_MV5
+  m_cPPS.setLayerId( getLayerId() );
+  if( getVPS()->getNumDirectRefLayers( getLayerId() ) > 0 )
+#else
   if( getVPS()->getNumDirectRefLayers( getLayerIdInVps() ) > 0 )
+#endif
   {
     m_cPPS.setListsModificationPresentFlag( true );
@@ -736,5 +748,9 @@
   m_cPPS.setOutputFlagPresentFlag( false );
 #if H_MV
+#if H_MV5
+  m_cPPS.setNumExtraSliceHeaderBits( 2 ); 
+#else
   m_cPPS.setNumExtraSliceHeaderBits( 1 ); 
+#endif
 #endif
   m_cPPS.setSignHideFlag(getSignHideFlag());
Index: branches/HTM-8.0-dev0/source/Lib/TLibExtractor/TExtrTop.cpp
===================================================================
--- branches/HTM-8.0-dev0/source/Lib/TLibExtractor/TExtrTop.cpp	(revision 617)
+++ branches/HTM-8.0-dev0/source/Lib/TLibExtractor/TExtrTop.cpp	(revision 618)
@@ -100,4 +100,19 @@
 Void TExtrTop::dumpVpsInfo( std::ostream& rcVpsInfoHandle )
 { 
+#if H_MV5
+  rcVpsInfoHandle << "MaxLayers      = " << m_cVPS.getMaxLayersMinus1() + 1 << std::endl; 
+  rcVpsInfoHandle << "MaxNuhLayerId  = " << m_cVPS.getVpsMaxLayerId() << std::endl;                      
+
+  for ( Int layerIdxInVps = 0; layerIdxInVps <= m_cVPS.getMaxLayersMinus1(); layerIdxInVps++ )
+  {  
+    Int layerId = m_cVPS.getLayerIdInNuh( layerIdxInVps ); 
+    rcVpsInfoHandle << "LayerIdxInVps  = " << layerIdxInVps                       << std::endl; 
+    rcVpsInfoHandle << "LayerIdInNuh   = " << layerId                             << std::endl; 
+    rcVpsInfoHandle << "ViewOrderIndex = " << m_cVPS.getViewIndex     ( layerId ) << std::endl;     
+#if H_3D    
+    rcVpsInfoHandle << "DepthFlag      = " << m_cVPS.getDepthId       ( layerId ) << std::endl;     
+#endif
+    rcVpsInfoHandle << "ViewId         = " << m_cVPS.getViewId        ( layerId ) << std::endl;     
+#else
   rcVpsInfoHandle << "MaxLayers = "     << m_cVPS.getMaxLayers()     << std::endl; 
   rcVpsInfoHandle << "MaxNuhLayerId = " << m_cVPS.getVpsMaxLayerId() << std::endl; 
@@ -112,4 +127,5 @@
     rcVpsInfoHandle << "DepthFlag = "      << m_cVPS.getDepthId     ( layerIdxInVps ) << std::endl;     
 #endif
+#endif
   }
 }
