Index: trunk/source/App/TAppDecoder/TAppDecCfg.h
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecCfg.h	(revision 950)
+++ trunk/source/App/TAppDecoder/TAppDecCfg.h	(revision 964)
@@ -45,5 +45,4 @@
 #include "TLibCommon/CommonDef.h"
 #include <vector>
-
 //! \ingroup TAppDecoder
 //! \{
Index: trunk/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 950)
+++ trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 964)
@@ -70,4 +70,9 @@
     m_pScaleOffsetFile  = 0;
 #endif
+
+#if H_MV_HLS_7_VPS_P0300_27
+    m_markedForOutput = false; 
+#endif
+
 }
 
@@ -152,9 +157,11 @@
   Bool openedReconFile = false; // reconstruction file not yet opened. (must be performed after SPS is seen)
 #else
-#if H_3D
+
   Int  pocCurrPic        = -MAX_INT;     
   Int  pocLastPic        = -MAX_INT;   
-#endif
-
+
+#if H_MV_HLS_7_VPS_P0300_27
+  Int  layerIdLastPic    = -MAX_INT; 
+#endif
   Int  layerIdCurrPic    = 0; 
 
@@ -188,8 +195,6 @@
     Bool newSliceDiffPoc   = false;
     Bool newSliceDiffLayer = false;
-    Bool sliceSkippedFlag = false; 
-#if H_3D
+    Bool sliceSkippedFlag  = false; 
     Bool allLayersDecoded  = false;     
-#endif
 #endif
     if (nalUnit.empty())
@@ -210,5 +215,8 @@
           || nalu.m_layerId > MAX_NUM_LAYER_IDS-1
           || (nalu.m_nalUnitType == NAL_UNIT_VPS && nalu.m_layerId > 0)           
-          || (nalu.m_nalUnitType == NAL_UNIT_EOB && nalu.m_layerId > 0)           
+          || (nalu.m_nalUnitType == NAL_UNIT_EOB && nalu.m_layerId > 0)    
+#if H_MV_HLS_8_MIS_Q0177_47
+          || (nalu.m_nalUnitType == NAL_UNIT_EOS && nalu.m_layerId > 0)    
+#endif
          ) 
       {
@@ -229,8 +237,17 @@
         // - nalu.isSlice() == true      
 
+#if H_MV_HLS_7_VPS_P0300_27
+        if ( nalu.m_nalUnitType == NAL_UNIT_VPS )
+        {
+          m_vps = m_tDecTop[decIdx]->getPrefetchedVPS(); 
+          if ( m_targetDecLayerIdSetFileEmpty )
+          {
+            TComVPS* vps = m_vps; 
+#else
         // Update TargetDecLayerIdList only when not specified by layer id file, specification by file might actually out of conformance. 
         if (nalu.m_nalUnitType == NAL_UNIT_VPS && m_targetDecLayerIdSetFileEmpty )
         {
           TComVPS* vps = m_tDecTop[decIdx]->getPrefetchedVPS(); 
+#endif
           if ( m_targetOptLayerSetIdx == -1 )
           {
@@ -238,4 +255,10 @@
             m_targetOptLayerSetIdx = vps->getVpsNumLayerSetsMinus1(); 
           }
+#if H_MV_HLS_8_HRD_Q0102_08
+          for (Int dI = 0; dI < m_numDecoders; dI++ )
+          {
+            m_tDecTop[decIdx]->setTargetOptLayerSetIdx( m_targetOptLayerSetIdx ); 
+          }
+#endif
 
           if ( m_targetOptLayerSetIdx < 0 || m_targetOptLayerSetIdx >= vps->getNumOutputLayerSets() )
@@ -246,5 +269,7 @@
           m_targetDecLayerIdSet = vps->getTargetDecLayerIdList( m_targetOptLayerSetIdx ); 
         }
-
+#if H_MV_HLS_7_VPS_P0300_27
+      }
+#endif
 #if H_3D
         if (nalu.m_nalUnitType == NAL_UNIT_VPS )
@@ -257,7 +282,5 @@
         {
           layerIdCurrPic = nalu.m_layerId; 
-#if H_3D
           pocCurrPic     = m_tDecTop[decIdx]->getCurrPoc(); 
-#endif
           decIdxCurrPic  = decIdx; 
           firstSlice     = false; 
@@ -266,14 +289,13 @@
         if ( bNewPicture || !bitstreamFile )
         { 
+#if H_MV_HLS_7_VPS_P0300_27
+          layerIdLastPic    = layerIdCurrPic; 
+#endif
           layerIdCurrPic    = nalu.m_layerId; 
-#if H_3D          
           pocLastPic        = pocCurrPic; 
           pocCurrPic        = m_tDecTop[decIdx]->getCurrPoc(); 
-#endif          
           decIdxLastPic     = decIdxCurrPic; 
           decIdxCurrPic     = decIdx; 
-#if H_3D
           allLayersDecoded = ( pocCurrPic != pocLastPic );
-#endif
         }
 #else
@@ -318,4 +340,7 @@
         assert( decIdxLastPic != -1 ); 
         m_tDecTop[decIdxLastPic]->endPicDecoding(poc, pcListPic, m_targetDecLayerIdSet );
+#if H_MV_HLS_7_VPS_P0300_27
+        xMarkForOutput( allLayersDecoded, poc, layerIdLastPic ); 
+#endif
 #else
         m_cTDecTop.executeLoopFilters(poc, pcListPic);
@@ -324,4 +349,12 @@
       loopFiltered = (nalu.m_nalUnitType == NAL_UNIT_EOS);
     }
+#if !FIX_WRITING_OUTPUT
+#if SETTING_NO_OUT_PIC_PRIOR
+    if (bNewPicture && m_cTDecTop.getIsNoOutputPriorPics())
+    {
+      m_cTDecTop.checkNoOutputPriorPics( pcListPic );
+    }
+#endif
+#endif
 #if H_3D
     if ( allLayersDecoded || !bitstreamFile )
@@ -351,4 +384,24 @@
         m_reconOpen[decIdxLastPic] = true;
       }
+#if FIX_WRITING_OUTPUT
+      // write reconstruction to file
+      if( bNewPicture )
+      {
+        // Bumping after picture has been decoded
+#if ENC_DEC_TRACE
+        g_bJustDoIt = true;  
+        writeToTraceFile( "Bumping after decoding \n", g_decTracePicOutput  );         
+        g_bJustDoIt = false;  
+#endif
+        xWriteOutput( pcListPic, decIdxLastPic, nalu.m_temporalId );
+      }
+#if SETTING_NO_OUT_PIC_PRIOR
+      if ( (bNewPicture || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_CRA) && m_tDecTop[decIdxLastPic]->getNoOutputPriorPicsFlag() )
+      {
+        m_tDecTop[decIdxLastPic]->checkNoOutputPriorPics( pcListPic );
+        m_tDecTop[decIdxLastPic]->setNoOutputPriorPicsFlag (false);
+      }
+#endif
+#endif
       if ( bNewPicture && newSliceDiffPoc && 
 #else
@@ -356,4 +409,18 @@
         openedReconFile  = true;
       }
+#if FIX_WRITING_OUTPUT
+      // write reconstruction to file
+      if( bNewPicture )
+      {
+        xWriteOutput( pcListPic, nalu.m_temporalId );
+      }
+#if SETTING_NO_OUT_PIC_PRIOR
+      if ( (bNewPicture || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_CRA) && m_cTDecTop.getNoOutputPriorPicsFlag() )
+      {
+        m_cTDecTop.checkNoOutputPriorPics( pcListPic );
+        m_cTDecTop.setNoOutputPriorPicsFlag (false);
+      }
+#endif
+#endif
       if ( bNewPicture && 
 #endif
@@ -373,18 +440,44 @@
       {
 #if H_MV
+#if FIX_OUTPUT_EOS
+        xWriteOutput( pcListPic, decIdxLastPic, nalu.m_temporalId );
+#else
         xFlushOutput( pcListPic, decIdxLastPic );
+#endif
+#else
+#if FIX_OUTPUT_EOS
+        xWriteOutput( pcListPic, nalu.m_temporalId );
 #else
         xFlushOutput( pcListPic );
 #endif
-      }
-      // write reconstruction to file
+
+#endif
+      }
+      // write reconstruction to file -- for additional bumping as defined in C.5.2.3 
+#if H_MV
+      // Above comment seems to be wrong
+#endif
+#if FIX_WRITING_OUTPUT
+      if(!bNewPicture && nalu.m_nalUnitType >= NAL_UNIT_CODED_SLICE_TRAIL_N && nalu.m_nalUnitType <= NAL_UNIT_RESERVED_VCL31)
+#else
       if(bNewPicture)
-      {
-#if H_MV
-        xWriteOutput( pcListPic, decIdxLastPic, nalu.m_temporalId );
-      }
-    }
-  }
-
+#endif
+      {
+#if H_MV        
+        // Bumping after reference picture set has been applied (here after first vcl nalu. 
+#if ENC_DEC_TRACE
+        g_bJustDoIt = true;  
+        writeToTraceFile( "Bumping after reference picture set has been applied \n", g_decTracePicOutput  );         
+        g_bJustDoIt = false;  
+#endif
+
+        xWriteOutput( m_tDecTop[decIdxCurrPic]->getListPic(), decIdxCurrPic, nalu.m_temporalId );
+#else
+        xWriteOutput( pcListPic, nalu.m_temporalId );
+#endif
+      }
+    }
+  }
+#if H_MV
 #if H_3D
   if( m_cCamParsCollector.isInitialized() )
@@ -397,10 +490,5 @@
     xFlushOutput( m_tDecTop[decIdx]->getListPic(), decIdx );
   }
-#else
-        xWriteOutput( pcListPic, nalu.m_temporalId );
-      }
-    }
-  }
-  
+#else  
   xFlushOutput( pcListPic );
   // delete buffers
@@ -497,4 +585,25 @@
   TComList<TComPic*>::iterator iterPic   = pcListPic->begin();
   Int numPicsNotYetDisplayed = 0;
+  Int dpbFullness = 0;
+#if H_MV
+  // preliminary fix
+  TComSPS* activeSPS = m_tDecTop[0]->getActiveSPS();
+#else
+  TComSPS* activeSPS = m_cTDecTop.getActiveSPS();
+#endif
+  UInt numReorderPicsHighestTid;
+  UInt maxDecPicBufferingHighestTid;
+  UInt maxNrSublayers = activeSPS->getMaxTLayers();
+
+  if(m_iMaxTemporalLayer == -1 || m_iMaxTemporalLayer >= maxNrSublayers)
+  {
+    numReorderPicsHighestTid = activeSPS->getNumReorderPics(maxNrSublayers-1);
+    maxDecPicBufferingHighestTid =  activeSPS->getMaxDecPicBuffering(maxNrSublayers-1); 
+  }
+  else
+  {
+    numReorderPicsHighestTid = activeSPS->getNumReorderPics(m_iMaxTemporalLayer);
+    maxDecPicBufferingHighestTid = activeSPS->getMaxDecPicBuffering(m_iMaxTemporalLayer); 
+  }
   
   while (iterPic != pcListPic->end())
@@ -508,4 +617,9 @@
     {
       numPicsNotYetDisplayed++;
+      dpbFullness++;
+    }
+    else if(pcPic->getSlice( 0 )->isReferenced())
+    {
+      dpbFullness++;
     }
     iterPic++;
@@ -533,6 +647,8 @@
           && pcPicBottom->getOutputMark() && (numPicsNotYetDisplayed >  pcPicBottom->getNumReorderPics(tId) && (pcPicTop->getPOC() == m_pocLastDisplay[decIdx]+1 || m_pocLastDisplay[decIdx]<0)))
 #else
-      if ( pcPicTop->getOutputMark() && (numPicsNotYetDisplayed >  pcPicTop->getNumReorderPics(tId) && !(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1)
-          && pcPicBottom->getOutputMark() && (numPicsNotYetDisplayed >  pcPicBottom->getNumReorderPics(tId) && (pcPicTop->getPOC() == m_iPOCLastDisplay+1 || m_iPOCLastDisplay<0)))
+      if ( pcPicTop->getOutputMark() && pcPicBottom->getOutputMark() &&
+          (numPicsNotYetDisplayed >  numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid) &&
+          (!(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1) &&
+          (pcPicTop->getPOC() == m_iPOCLastDisplay+1 || m_iPOCLastDisplay < 0))
 #endif
       {
@@ -552,4 +668,10 @@
         assert( conf   .getScaledFlag() );
         assert( defDisp.getScaledFlag() );
+#if ENC_DEC_TRACE
+        g_bJustDoIt = true;  
+        writeToTraceFile( "OutputPic Poc"   , pcPic->getPOC    (), g_decTracePicOutput  ); 
+        writeToTraceFile( "OutputPic LayerId", pcPic->getLayerId(), g_decTracePicOutput );         
+        g_bJustDoIt = false;  
+#endif
         m_tVideoIOYuvReconFile[decIdx]->write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
 #else
@@ -613,11 +735,17 @@
 
 #if H_MV
-      if ( pcPic->getOutputMark() && (numPicsNotYetDisplayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_pocLastDisplay[decIdx]))
+      if(pcPic->getOutputMark() && pcPic->getPOC() > m_pocLastDisplay[decIdx] &&
+        (numPicsNotYetDisplayed >  numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid))
 #else      
-      if ( pcPic->getOutputMark() && (numPicsNotYetDisplayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_iPOCLastDisplay))
+      if(pcPic->getOutputMark() && pcPic->getPOC() > m_iPOCLastDisplay &&
+        (numPicsNotYetDisplayed >  numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid))
 #endif
       {
         // write to file
         numPicsNotYetDisplayed--;
+        if(pcPic->getSlice(0)->isReferenced() == false)
+        {
+          dpbFullness--;
+        }
 #if H_MV
       if ( m_pchReconFiles[decIdx] )
@@ -631,4 +759,10 @@
         assert( conf   .getScaledFlag() );
         assert( defDisp.getScaledFlag() );
+#if ENC_DEC_TRACE
+        g_bJustDoIt = true;  
+        writeToTraceFile( "OutputPic Poc"   , pcPic->getPOC    (), g_decTracePicOutput  ); 
+        writeToTraceFile( "OutputPic LayerId", pcPic->getLayerId(), g_decTracePicOutput );         
+        g_bJustDoIt = false; 
+#endif
         m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(),
 #else
@@ -665,4 +799,7 @@
         }
         pcPic->setOutputMark(false);
+#if H_MV_HLS_7_VPS_P0300_27
+        pcPic->setPicOutputFlag(false);
+#endif
       }
       
@@ -715,4 +852,10 @@
         assert( conf   .getScaledFlag() );
         assert( defDisp.getScaledFlag() );
+#if ENC_DEC_TRACE
+        g_bJustDoIt = true;  
+        writeToTraceFile( "OutputPic Poc"   , pcPic->getPOC    (), g_decTracePicOutput  ); 
+        writeToTraceFile( "OutputPic LayerId", pcPic->getLayerId(), g_decTracePicOutput );         
+        g_bJustDoIt = false;  
+#endif
         m_tVideoIOYuvReconFile[decIdx]->write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
 #else
@@ -802,4 +945,10 @@
         assert( conf   .getScaledFlag() );
         assert( defDisp.getScaledFlag() );
+#if ENC_DEC_TRACE
+        g_bJustDoIt = true;  
+        writeToTraceFile( "OutputPic Poc"   , pcPic->getPOC    (), g_decTracePicOutput  ); 
+        writeToTraceFile( "OutputPic LayerId", pcPic->getLayerId(), g_decTracePicOutput );         
+        g_bJustDoIt = false;  
+#endif
         m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(),
 #else
@@ -836,4 +985,7 @@
         }
         pcPic->setOutputMark(false);
+#if H_MV_HLS_7_VPS_P0300_27
+        pcPic->setPicOutputFlag(false);
+#endif
       }
 #if !H_MV
@@ -909,4 +1061,7 @@
     m_tDecTop[ decIdx ]->setIvPicLists( &m_ivPicLists ); 
     m_tDecTop[ decIdx ]->setLayerInitilizedFlags( m_layerInitilizedFlags );
+#if    H_MV_HLS_8_HRD_Q0102_08
+    m_tDecTop[ decIdx ]->setTargetOptLayerSetIdx( m_targetOptLayerSetIdx );    
+#endif
 
 #if H_3D
@@ -941,5 +1096,61 @@
   };
   return decIdx;
+
 }
+
+
+#if H_MV_HLS_7_VPS_P0300_27
+Void TAppDecTop::xMarkForOutput( Bool allLayersDecoded, Int pocLastPic, Int layerIdLastPic )
+{  
+  vector<Int> targetOptLayerIdList = m_vps->getTargetOptLayerIdList( m_targetOptLayerSetIdx );
+
+  if (m_vps->getAltOutputLayerFlagVar( m_targetOptLayerSetIdx ) )
+  {
+    assert( targetOptLayerIdList.size() == 1 ); 
+    Int targetLayerId = targetOptLayerIdList[0];     
+
+    TComPic* curPic = m_ivPicLists.getPic( layerIdLastPic, pocLastPic );
+    assert( curPic != NULL );
+
+    if ( layerIdLastPic == targetLayerId )
+    {
+      if ( curPic->getPicOutputFlag() )
+      {
+        curPic->setOutputMark( true );
+      }
+      else
+      {        
+        xMarkAltOutPic( targetLayerId, pocLastPic ); 
+      }
+      m_markedForOutput = true; 
+    }
+    else if ( ( layerIdLastPic > targetLayerId || allLayersDecoded ) && !m_markedForOutput )
+    {
+      xMarkAltOutPic( targetLayerId, pocLastPic );
+    }
+
+    if ( allLayersDecoded )
+    {
+      m_markedForOutput = false; 
+    }
+  }
+  else
+  { 
+    for( Int dI = 0; dI < m_numDecoders; dI++ )
+    {      
+      Int layerId = m_tDecTop[dI]->getLayerId(); 
+      TComPic* curPic = m_ivPicLists.getPic( layerId, pocLastPic );
+      if ( curPic != NULL )
+      {
+        if ( curPic->getReconMark() )
+        {
+          Bool isTargetOptLayer = std::find(targetOptLayerIdList.begin(), targetOptLayerIdList.end(), layerId) != targetOptLayerIdList.end();
+          curPic->setOutputMark( isTargetOptLayer ? curPic->getPicOutputFlag() : false ); 
+        }
+      }
+    }
+  }
+}
+#endif
 #endif
 //! \}
Index: trunk/source/App/TAppDecoder/TAppDecTop.h
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecTop.h	(revision 950)
+++ trunk/source/App/TAppDecoder/TAppDecTop.h	(revision 964)
@@ -68,5 +68,7 @@
   TComPicLists                    m_ivPicLists;                                ///< picture buffers of decoder instances
   Bool                            m_layerInitilizedFlags[ MAX_NUM_LAYER_IDS ]; ///< for layerwise startup 
-
+#if H_MV_HLS_7_VPS_P0300_27
+  TComVPS*                        m_vps;                                ///< active VPS
+#endif
 #else
   TDecTop                         m_cTDecTop;                     ///< decoder class
@@ -80,4 +82,9 @@
   Int                             m_iPOCLastDisplay;              ///< last POC in display order
 #endif
+#if H_MV_HLS_7_VPS_P0300_27
+  Bool                            m_markedForOutput; 
+#endif
+
+
 #if H_3D
   FILE*                           m_pScaleOffsetFile;
@@ -99,4 +106,42 @@
 #if H_MV
   Void  xWriteOutput      ( TComList<TComPic*>* pcListPic, Int layerId, Int tId ); ///< write YUV to file
+
+#if H_MV_HLS_7_VPS_P0300_27
+  Void  xMarkForOutput   ( Bool allLayersDecoded, Int pocLastPic, Int layerIdLastPic );         
+  Void  xMarkAltOutPic    ( Int targetOutputLayer, Int pocLastPic )
+  {
+    Int optLayerIdxInVps = m_vps->getLayerIdInNuh( targetOutputLayer ); 
+    Int highestNuhLayerId = -1; 
+    TComPic* picWithHighestNuhLayerId = NULL; 
+    for (Int dIdx = 0; dIdx < m_numDecoders; dIdx++)
+    {
+      Int curLayerId = m_tDecTop[dIdx]->getLayerId();
+      Int curLayerIdxInVps = m_vps->getLayerIdInNuh( curLayerId  ); 
+      if ( m_vps->getInDirectDependencyFlag(optLayerIdxInVps, curLayerIdxInVps ) )
+      {
+        TComPic* curPic = m_ivPicLists.getPic( curLayerId, pocLastPic ); 
+        if (curPic != NULL)
+        {
+          if (curPic->getReconMark() && curPic->getPicOutputFlag() )
+          {
+            curPic->setOutputMark   ( false ); 
+            curPic->setPicOutputFlag( false ); 
+            if ( curLayerId > highestNuhLayerId)
+            {
+              highestNuhLayerId = curLayerId ; 
+              picWithHighestNuhLayerId = curPic; 
+            }            
+          }
+        }
+      }
+    }
+    if ( picWithHighestNuhLayerId != NULL )
+    {
+      picWithHighestNuhLayerId->setPicOutputFlag(true); 
+      picWithHighestNuhLayerId->setOutputMark   (true); 
+    }
+  }
+#endif
+
   Void  xFlushOutput      ( TComList<TComPic*>* pcListPic, Int layerId ); ///< flush all remaining decoded pictures to file
   Int   xGetDecoderIdx    ( Int layerId, Bool createFlag = false );
Index: trunk/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 950)
+++ trunk/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 964)
@@ -388,9 +388,12 @@
   ("VpsNumLayerSets",       m_vpsNumLayerSets    , 1                    , "Number of layer sets")    
   ("LayerIdsInSet_%d",      m_layerIdsInSets     , std::vector<Int>(1,0), MAX_VPS_OP_SETS_PLUS1 ,"LayerIds of Layer set")  
-  ("DefaultTargetOutputLayerIdc"     , m_defaultTargetOutputLayerIdc     , 0, "Specifies output layers of layer sets, 0: output all layers, 1: output highest layer, 2: specified by LayerIdsInDefOutputLayerSet")
+  ("DefaultTargetOutputLayerIdc"     , m_defaultOutputLayerIdc     , 0, "Specifies output layers of layer sets, 0: output all layers, 1: output highest layer, 2: specified by LayerIdsInDefOutputLayerSet")
   ("OutputLayerSetIdx",     m_outputLayerSetIdx  , std::vector<Int>(0,0), "Indices of layer sets used as additional output layer sets")  
 
   ("LayerIdsInAddOutputLayerSet_%d", m_layerIdsInAddOutputLayerSet      , std::vector<Int>(0,0), MAX_VPS_ADD_OUTPUT_LAYER_SETS, "Indices in VPS of output layers in additional output layer set")  
   ("LayerIdsInDefOutputLayerSet_%d", m_layerIdsInDefOutputLayerSet      , std::vector<Int>(0,0), MAX_VPS_OP_SETS_PLUS1, "Indices in VPS of output layers in layer set")  
+#if H_MV_HLS_7_VPS_P0300_27
+  ("AltOutputLayerFlag",    m_altOutputLayerFlag , std::vector<Bool>(1,0), "Alt output layer flag")
+#endif
   ("ProfileLevelTierIdx",   m_profileLevelTierIdx, std::vector<Int>(1,0), "Indices to profile level tier")
   
@@ -453,5 +456,9 @@
 ("IntraPeriod,-ip",         m_iIntraPeriod,              -1, "Intra period in frames, (-1: only first frame)")
 #endif
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  ("DecodingRefreshType,-dr", m_iDecodingRefreshType,       0, "Intra refresh type (0:none 1:CRA 2:IDR 3:RecPointSEI)")
+#else
   ("DecodingRefreshType,-dr", m_iDecodingRefreshType,       0, "Intra refresh type (0:none 1:CRA 2:IDR)")
+#endif
   ("GOPSize,g",               m_iGOPSize,                   1, "GOP size of temporal structure")
   // motion options
@@ -470,5 +477,4 @@
   ("LambdaModifier5,-LM5", m_adLambdaModifier[ 5 ], ( Double )1.0, "Lambda modifier for temporal layer 5")
   ("LambdaModifier6,-LM6", m_adLambdaModifier[ 6 ], ( Double )1.0, "Lambda modifier for temporal layer 6")
-  ("LambdaModifier7,-LM7", m_adLambdaModifier[ 7 ], ( Double )1.0, "Lambda modifier for temporal layer 7")
 
   /* Quantization parameters */
@@ -694,4 +700,6 @@
   ("SEIToneMapCameraIsoSpeedIdc",                     m_cameraIsoSpeedIdc,                        0, "Indicates the camera ISO speed for daylight illumination")
   ("SEIToneMapCameraIsoSpeedValue",                   m_cameraIsoSpeedValue,                    400, "Specifies the camera ISO speed for daylight illumination of Extended_ISO")
+  ("SEIToneMapExposureIndexIdc",                      m_exposureIndexIdc,                         0, "Indicates the exposure index setting of the camera")
+  ("SEIToneMapExposureIndexValue",                    m_exposureIndexValue,                     400, "Specifies the exposure index setting of the cameran of Extended_ISO")
   ("SEIToneMapExposureCompensationValueSignFlag",     m_exposureCompensationValueSignFlag,        0, "Specifies the sign of ExposureCompensationValue")
   ("SEIToneMapExposureCompensationValueNumerator",    m_exposureCompensationValueNumerator,       0, "Specifies the numerator of ExposureCompensationValue")
@@ -724,4 +732,5 @@
   ("SEISOPDescription",              m_SOPDescriptionSEIEnabled,              0, "Control generation of SOP description SEI messages")
   ("SEIScalableNesting",             m_scalableNestingSEIEnabled,              0, "Control generation of scalable nesting SEI messages")
+#if H_MV
   ("SubBitstreamPropSEIEnabled",              m_subBistreamPropSEIEnabled,    false                     ,"Enable signaling of sub-bitstream property SEI message")
   ("SEISubBitstreamNumAdditionalSubStreams",  m_sbPropNumAdditionalSubStreams,0, "Number of substreams for which additional information is signalled")
@@ -731,4 +740,5 @@
   ("SEISubBitstreamAvgBitRate",               m_sbPropAvgBitRate,             std::vector< Int  >(1,0)  ,"Specifies average bit rate of the i-th sub-bitstream")
   ("SEISubBitstreamMaxBitRate",               m_sbPropMaxBitRate,             std::vector< Int  >(1,0)  ,"Specifies maximum bit rate of the i-th sub-bitstream")
+#endif
 #if H_3D
   ("CameraParameterFile,cpf", m_pchCameraParameterFile,    (Char *) 0, "Camera Parameter File Name")
@@ -1047,4 +1057,11 @@
   xResizeVector( m_loopFilterNotAcrossTilesFlag ); 
   xResizeVector( m_wppInUseFlag ); 
+
+#if H_MV_HLS_7_VPS_P0300_27
+  for (Int olsIdx = 0; olsIdx < m_vpsNumLayerSets + (Int) m_outputLayerSetIdx.size(); olsIdx++)
+  {    
+    m_altOutputLayerFlag.push_back( false );      
+  }
+#endif
 #else
   m_aidQP = new Int[ m_framesToBeEncoded + m_iGOPSize + 1 ];
@@ -1417,7 +1434,7 @@
   }
 
-  xConfirmPara( m_defaultTargetOutputLayerIdc < 0 || m_defaultTargetOutputLayerIdc > 2, "Default target output layer idc must greater than or equal to 0 and less than or equal to 2." );  
-
-  if( m_defaultTargetOutputLayerIdc != 2 )
+  xConfirmPara( m_defaultOutputLayerIdc < 0 || m_defaultOutputLayerIdc > 2, "Default target output layer idc must greater than or equal to 0 and less than or equal to 2." );  
+
+  if( m_defaultOutputLayerIdc != 2 )
   {
     Bool anyDefaultOutputFlag = false;   
@@ -1448,4 +1465,7 @@
   }
 
+#if H_MV_HLS_7_VPS_P0300_27
+  xConfirmPara( m_altOutputLayerFlag.size() < m_vpsNumLayerSets + m_outputLayerSetIdx.size(), "The number of Profile Level Tier indices must be equal to the number of layer set plus the number of output layer set indices" );
+#endif
   xConfirmPara( m_profileLevelTierIdx.size() < m_vpsNumLayerSets + m_outputLayerSetIdx.size(), "The number of Profile Level Tier indices must be equal to the number of layer set plus the number of output layer set indices" );
 
@@ -1472,5 +1492,13 @@
   xConfirmPara( (m_iIntraPeriod > 0 && m_iIntraPeriod < m_iGOPSize) || m_iIntraPeriod == 0, "Intra period must be more than GOP size, or -1 , not 0" );
 #endif
+#if ALLOW_RECOVERY_POINT_AS_RAP
+  xConfirmPara( m_iDecodingRefreshType < 0 || m_iDecodingRefreshType > 3,                   "Decoding Refresh Type must be comprised between 0 and 3 included" );
+  if(m_iDecodingRefreshType == 3)
+  {
+    xConfirmPara( !m_recoveryPointSEIEnabled,                                               "When using RecoveryPointSEI messages as RA points, recoveryPointSEI must be enabled" );
+  }
+#else
   xConfirmPara( m_iDecodingRefreshType < 0 || m_iDecodingRefreshType > 2,                   "Decoding Refresh Type must be equal to 0, 1 or 2" );
+#endif
 #if H_MV
   for( Int layer = 0; layer < m_numberOfLayers; layer++ )
@@ -1591,5 +1619,9 @@
   xConfirmPara( m_pchCameraParameterFile    == 0                ,   "CameraParameterFile must be given");
   xConfirmPara( m_pchBaseViewCameraNumbers  == 0                ,   "BaseViewCameraNumbers must be given" );
+#if BUG_FIX_TK65
+  xConfirmPara( ( ((UInt) m_numberOfLayers >> 1 ) != m_cCameraData.getBaseViewNumbers().size() ) && ( m_numberOfLayers != m_cCameraData.getBaseViewNumbers().size() ),   "Number of Views in BaseViewCameraNumbers must be equal to NumberOfViews" );
+#else
   xConfirmPara( ((UInt) m_numberOfLayers >> 1 ) != m_cCameraData.getBaseViewNumbers().size(),   "Number of Views in BaseViewCameraNumbers must be equal to NumberOfViews" );
+#endif
   xConfirmPara    ( m_iCodedCamParPrecision < 0 || m_iCodedCamParPrecision > 5,       "CodedCamParsPrecision must be in range of 0..5" );
 #if H_3D_VSO
@@ -2178,4 +2210,5 @@
     xConfirmPara( m_toneMapModelId < 0 || m_toneMapModelId > 4 , "SEIToneMapModelId must be in rage 0 to 4");
     xConfirmPara( m_cameraIsoSpeedValue == 0, "SEIToneMapCameraIsoSpeedValue shall not be equal to 0");
+    xConfirmPara( m_exposureIndexValue  == 0, "SEIToneMapExposureIndexValue shall not be equal to 0");
     xConfirmPara( m_extendedRangeWhiteLevel < 100, "SEIToneMapExtendedRangeWhiteLevel should be greater than or equal to 100");
     xConfirmPara( m_nominalBlackLevelLumaCodeValue >= m_nominalWhiteLevelLumaCodeValue, "SEIToneMapNominalWhiteLevelLumaCodeValue shall be greater than SEIToneMapNominalBlackLevelLumaCodeValue");
Index: trunk/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncCfg.h	(revision 950)
+++ trunk/source/App/TAppEncoder/TAppEncCfg.h	(revision 964)
@@ -89,10 +89,13 @@
   Int                    m_vpsNumLayerSets;                   ///< Number of layer sets
   std::vector< std::vector<Int> > m_layerIdsInSets;           ///< LayerIds in vps of layer set 
-  Int                    m_defaultTargetOutputLayerIdc;       ///< Specifies output layers of layer sets, 0: output all layers, 1: output highest layers, 2: specified by LayerIdsInDefOuputLayerSet
+  Int                    m_defaultOutputLayerIdc;       ///< Specifies output layers of layer sets, 0: output all layers, 1: output highest layers, 2: specified by LayerIdsInDefOuputLayerSet
   std::vector<Int>       m_outputLayerSetIdx;                 ///< Indices of layer sets used as additional output layer sets  
   std::vector< std::vector<Int> > m_layerIdsInAddOutputLayerSet; ///< LayerIds in vps of additional output layers
   std::vector< std::vector<Int> > m_layerIdsInDefOutputLayerSet; ///< Indices in vps of output layers in layer sets
   std::vector<Int>       m_profileLevelTierIdx;               ///< Indices of of profile level tier
-  
+  #if H_MV_HLS_7_VPS_P0300_27
+  std::vector<Bool>      m_altOutputLayerFlag;                ///< Alt output layer flag
+#endif
+
   // Dependencies
   std::vector< std::vector<Int> > m_directRefLayers;          ///< LayerIds of direct reference layers
@@ -338,4 +341,6 @@
   Int       m_cameraIsoSpeedIdc;
   Int       m_cameraIsoSpeedValue;
+  Int       m_exposureIndexIdc;
+  Int       m_exposureIndexValue;
   Int       m_exposureCompensationValueSignFlag;
   Int       m_exposureCompensationValueNumerator;
Index: trunk/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 950)
+++ trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 964)
@@ -57,4 +57,8 @@
 TAppEncTop::TAppEncTop()
 {
+
+#if H_MV_HLS_8
+  m_vps = new TComVPS; 
+#endif
 #if !H_MV
   m_iFrameRcvd = 0;
@@ -66,4 +70,11 @@
 TAppEncTop::~TAppEncTop()
 {
+#if H_MV_HLS_8
+  if (m_vps)
+  {
+   delete m_vps; 
+  };
+#endif
+
 }
 
@@ -71,5 +82,9 @@
 {
 #if H_MV
+#if H_MV_HLS_8
+  TComVPS& vps = (*m_vps);   
+#else
   TComVPS& vps = m_vps;   
+#endif
 #else
   TComVPS vps;
@@ -409,4 +424,6 @@
   m_cTEncTop.setTMISEICameraIsoSpeedIdc                   ( m_cameraIsoSpeedIdc );
   m_cTEncTop.setTMISEICameraIsoSpeedValue                 ( m_cameraIsoSpeedValue );
+  m_cTEncTop.setTMISEIExposureIndexIdc                    ( m_exposureIndexIdc );
+  m_cTEncTop.setTMISEIExposureIndexValue                  ( m_exposureIndexValue );
   m_cTEncTop.setTMISEIExposureCompensationValueSignFlag   ( m_exposureCompensationValueSignFlag );
   m_cTEncTop.setTMISEIExposureCompensationValueNumerator  ( m_exposureCompensationValueNumerator );
@@ -691,8 +708,15 @@
 {
 #if H_3D
+#if H_MV_HLS_8
+  for ( Int viewIndex = 0; viewIndex < m_vps->getNumViews(); viewIndex++ )
+  {
+    m_vps->initCamParaVPS( viewIndex, true, m_cCameraData.getCamParsCodedPrecision(), 
+      m_cCameraData.getVaryingCameraParameters(), m_cCameraData.getCodedScale(), m_cCameraData.getCodedOffset() );
+#else
   for ( Int viewIndex = 0; viewIndex < m_vps.getNumViews(); viewIndex++ )
   {
-    m_vps.initCamParaVPS( viewIndex, true, m_cCameraData.getCamParsCodedPrecision(), 
+  m_vps.initCamParaVPS( viewIndex, true, m_cCameraData.getCamParsCodedPrecision(), 
       m_cCameraData.getVaryingCameraParameters(), m_cCameraData.getCodedScale(), m_cCameraData.getCodedOffset() );
+#endif
   }
 #endif
@@ -1275,5 +1299,10 @@
 
   Int  defaultDirectDependencyType = -1; 
+#if MV_FIX_DEP_TYPES
+  Bool defaultDirectDependencyFlag = false; 
+#else
   Bool defaultDirectDependencyFlag = true; 
+#endif
+
   for( Int depLayer = 1; depLayer < m_numberOfLayers; depLayer++ )
   {
@@ -1293,4 +1322,7 @@
       {
         defaultDirectDependencyType = curDirectDependencyType; 
+#if MV_FIX_DEP_TYPES
+        defaultDirectDependencyFlag = true; 
+#endif
       }
       
@@ -1482,5 +1514,9 @@
 Void TAppEncTop::xSetRepFormat( TComVPS& vps )
 {
+#if H_MV_HLS_8_PMS_Q0195_20
+  vps.setRepFormatIdxPresentFlag( false ); 
+#else
   vps.setRepFormatIdxPresentFlag( true ); 
+#endif
   vps.setVpsNumRepFormatsMinus1 ( 0    ); 
 
@@ -1499,8 +1535,10 @@
   vps.setRepFormat( 0 , repFormat );
 
+#if !H_MV_HLS_8_PMS_Q0195_20
   for(Int i = 0; i <= vps.getMaxLayersMinus1(); i++ )
   {
     vps.setVpsRepFormatIdx( i , 0 ); 
   }
+#endif
 }
 
@@ -1513,14 +1551,30 @@
   assert ( dpbSize != 0 ); 
 
+#if H_MV_HLS_8_HRD_Q0102_08
+  for( Int i = 0; i < vps.getNumOutputLayerSets(); i++ )
+#else
   for( Int i = 1; i < vps.getNumOutputLayerSets(); i++ )
+#endif
   {  
+#if H_MV_HLS_8_MIS_Q0102_30
+    Int currLsIdx = vps.olsIdxToLsIdx( i ); 
+#endif
     std::vector<Int> targetDecLayerIdList = vps.getTargetDecLayerIdList( i ); 
     Bool subLayerFlagInfoPresentFlag = false; 
 
+#if H_MV_HLS_8_MIS_Q0102_30
+    for( Int j = 0; j  <=  vps.getMaxSubLayersInLayerSetMinus1( currLsIdx ); j++ )
+#else
     for( Int j = 0; j  <=  vps.getMaxSubLayersInLayerSetMinus1( i ); j++ )
+#endif
     {   
       Bool subLayerDpbInfoPresentFlag = false; 
-      assert( vps.getNumSubDpbs( vps.getLayerSetIdxForOutputLayerSet( i ) ) == targetDecLayerIdList.size() ); 
-      for( Int k = 0; k < vps.getNumSubDpbs( vps.getLayerSetIdxForOutputLayerSet( i )); k++ )   
+#if H_MV_HLS_8_MIS_Q0102_30 || H_MV_HLS_8_DBP_NODOC_42
+      assert( vps.getNumLayersInIdList( currLsIdx ) == targetDecLayerIdList.size() ); 
+      for( Int k = 0; k < vps.getNumLayersInIdList( currLsIdx ); k++ )   
+#else
+      assert( vps.getNumSubDpbs( vps.olsIdxToLsIdx( i ) ) == targetDecLayerIdList.size() ); 
+      for( Int k = 0; k < vps.getNumSubDpbs( vps.olsIdxToLsIdx( i )); k++ )   
+#endif
       {
         Int layerIdInVps = vps.getLayerIdInVps( targetDecLayerIdList[k] );           
@@ -1587,6 +1641,11 @@
   Int numAddOuputLayerSets = (Int) m_outputLayerSetIdx.size(); 
   // Additional output layer sets + profileLevelTierIdx
-  vps.setDefaultTargetOutputLayerIdc      ( m_defaultTargetOutputLayerIdc );   
-  vps.setNumAddOutputLayerSets            ( numAddOuputLayerSets          ); 
+  vps.setDefaultOutputLayerIdc      ( m_defaultOutputLayerIdc );   
+#if H_MV_HLS_8_SYN_39_19
+  vps.setNumAddLayerSets            ( 0                             );  
+  vps.setNumAddOlss                 ( numAddOuputLayerSets          ); 
+#else
+  vps.setNumAddLayerSets            ( numAddOuputLayerSets          ); 
+#endif
   vps.initTargetLayerIdLists(); 
 
@@ -1595,9 +1654,9 @@
     Int addOutLsIdx = olsIdx - m_vpsNumLayerSets;     
     
-    vps.setOutputLayerSetIdxMinus1( olsIdx, ( ( addOutLsIdx < 0 ) ?  olsIdx  : m_outputLayerSetIdx[ addOutLsIdx ] ) - 1 ); 
-
-    std::vector<Int>& layerIdList    = m_layerIdsInSets[ vps.getLayerSetIdxForOutputLayerSet( olsIdx ) ];
-
-    if (vps.getDefaultTargetOutputLayerIdc() == 2 || addOutLsIdx >= 0 )
+    vps.setLayerSetIdxForOlsMinus1( olsIdx, ( ( addOutLsIdx < 0 ) ?  olsIdx  : m_outputLayerSetIdx[ addOutLsIdx ] ) - 1 ); 
+
+    std::vector<Int>& layerIdList    = m_layerIdsInSets[ vps.olsIdxToLsIdx( olsIdx ) ];
+
+    if (vps.getDefaultOutputLayerIdc() == 2 || addOutLsIdx >= 0 )
     { 
       for ( Int i = 0; i < layerIdList.size(); i++)
@@ -1637,8 +1696,22 @@
       vps.setProfileLevelTierIdx( olsIdx, m_profileLevelTierIdx[ olsIdx ] ); 
     }
-
+#if H_MV_HLS_7_VPS_P0300_27
+    if ( vps.getNumOutputLayersInOutputLayerSet( olsIdx ) == 1 && 
+        vps.getNumDirectRefLayers( vps.getOlsHighestOutputLayerId( olsIdx ) ) )
+    {   
+      vps.setAltOutputLayerFlag( olsIdx , m_altOutputLayerFlag[ olsIdx ]);
+    }
+    else
+    {
+      vps.setAltOutputLayerFlag( olsIdx , false );
+      if ( m_altOutputLayerFlag[ olsIdx ] )
+      {
+        printf( "\nWarning: Ignoring AltOutputLayerFlag for output layer set %d, since more than one output layer or no dependent layers.\n", olsIdx );            
+      }
+    }
+#else
     vps.setAltOutputLayerFlag( olsIdx , false);     
-  }
-
+#endif
+  }
 }
 
Index: trunk/source/App/TAppEncoder/TAppEncTop.h
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncTop.h	(revision 950)
+++ trunk/source/App/TAppEncoder/TAppEncTop.h	(revision 964)
@@ -75,5 +75,9 @@
 
   TComPicLists               m_ivPicLists;                  ///< picture buffers of encoder instances
+#if H_MV_HLS_8
+  TComVPS*                   m_vps;                         ///< vps
+#else
   TComVPS                    m_vps;                         ///< vps
+#endif
 #else
   TEncTop                    m_cTEncTop;                    ///< encoder class
