Index: trunk/source/App/TAppDecoder/TAppDecCfg.cpp
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecCfg.cpp	(revision 1314)
+++ trunk/source/App/TAppDecoder/TAppDecCfg.cpp	(revision 1321)
@@ -102,5 +102,7 @@
   ("RespectDefDispWindow,w",    m_respectDefDispWindow,                0,          "Only output content inside the default display window\n")
 #if NH_MV
-  ("OutputVpsInfo,v",           m_outputVpsInfo,                       false,       "Output information about the layer dependencies and layer sets")
+  ("OutputVpsInfo,v",           m_printVpsInfo,                       false,       "Output information about the layer dependencies and layer sets")
+  ("PrintPicOutput,c" ,         m_printPicOutput,                     false,         "Print information on picture output")
+  ("PrintNalus,n",              m_printReceivedNalus,                 false,        "Print information on received NAL units")
 #endif
 #if O0043_BEST_EFFORT_DECODING
Index: trunk/source/App/TAppDecoder/TAppDecCfg.h
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecCfg.h	(revision 1314)
+++ trunk/source/App/TAppDecoder/TAppDecCfg.h	(revision 1321)
@@ -45,4 +45,7 @@
 #include "TLibCommon/CommonDef.h"
 #include <vector>
+#if NH_MV
+#include <fstream>
+#endif
 
 //! \ingroup TAppDecoder
@@ -58,14 +61,5 @@
 protected:
   Char*         m_pchBitstreamFile;                     ///< input bitstream file name
-#if NH_MV
-  Int           m_targetOptLayerSetIdx;                 ///< target output layer set index
-  Int           m_maxLayerId;                           ///< maximum nuh_layer_id decoded
-  std::vector<Char*> m_pchReconFiles;                   ///< array of output reconstruction file name create from output reconstruction file name
-#endif
   Char*         m_pchReconFile;                         ///< output reconstruction file name
-#if NH_3D
-  Char*         m_pchScaleOffsetFile;                   ///< output coded scale and offset parameters
-  Bool          m_depth420OutputFlag;                   ///< output depth layers in 4:2:0
-#endif
   Int           m_iSkipFrame;                           ///< counter for frames prior to the random access point to skip
   Int           m_outputBitDepth[MAX_NUM_CHANNEL_TYPE]; ///< bit depth used for writing output
@@ -76,7 +70,4 @@
   Bool          m_decodedNoDisplaySEIEnabled;         ///< Enable(true)/disable(false) writing only pictures that get displayed based on the no display SEI message
   std::vector<Int> m_targetDecLayerIdSet;             ///< set of LayerIds to be included in the sub-bitstream extraction process.
-#if NH_MV
-  Bool          m_targetDecLayerIdSetFileEmpty;       ///< indication if target layers are given by file
-#endif
 
   Int           m_respectDefDispWindow;               ///< Only output content inside the default display window
@@ -87,5 +78,24 @@
   Bool          m_bClipOutputVideoToRec709Range;      ///< If true, clip the output video to the Rec 709 range on saving.
 #if NH_MV
-  Bool          m_outputVpsInfo;                     ///< Output VPS information 
+  std::vector<Char*> m_pchReconFiles;                   ///< array of output reconstruction file name create from output reconstruction file name
+
+  Int           m_targetOptLayerSetIdx;                 ///< target output layer set index
+  Int           m_targetDecLayerSetIdx;
+  Int           m_baseLayerOutputFlag; 
+  Int           m_baseLayerPicOutputFlag; 
+  Int           m_auOutputFlag; 
+  Int           m_maxLayerId;                           ///< maximum nuh_layer_id decoded
+  std::ifstream m_bitstreamFile; 
+  Int           m_highestTid;
+  Bool          m_targetDecLayerIdSetFileEmpty;       ///< indication if target layers are given by file
+
+  Bool          m_printVpsInfo;                      ///< Output VPS information 
+  Bool          m_printPicOutput;                     ///< Print information on picture output
+  Bool          m_printReceivedNalus;                 ///< Print information on received NAL units
+#if NH_3D
+  Char*         m_pchScaleOffsetFile;                   ///< output coded scale and offset parameters
+  Bool          m_depth420OutputFlag;                   ///< output depth layers in 4:2:0
+#endif
+
   Void xAppendToFileNameEnd( Char* pchInputFileName, const Char* pchStringToAppend, Char*& rpchOutputFileName); ///< create filenames
 #endif
@@ -100,11 +110,13 @@
   , m_decodedPictureHashSEIEnabled(0)
   , m_decodedNoDisplaySEIEnabled(false)
-#if NH_MV
-  , m_targetDecLayerIdSetFileEmpty(true)
-#endif
   , m_respectDefDispWindow(0)
 #if O0043_BEST_EFFORT_DECODING
   , m_forceDecodeBitDepth(0)
 #endif
+#if NH_MV
+  , m_highestTid(-1)
+  , m_targetDecLayerIdSetFileEmpty(true)
+#endif
+
   {
     for (UInt channelTypeIndex = 0; channelTypeIndex < MAX_NUM_CHANNEL_TYPE; channelTypeIndex++)
Index: trunk/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 1314)
+++ trunk/source/App/TAppDecoder/TAppDecTop.cpp	(revision 1321)
@@ -64,22 +64,50 @@
 {
 #if NH_MV
-  for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++) 
-  {
-    m_layerIdToDecIdx[i] = -1; 
-    m_layerInitilizedFlags[i] = false; 
-  }
+  for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++)
+  {
+    m_layerIdToDecIdx                     [i] = -1;
+    m_layerInitilizedFlag                 [i] = false;
+    m_eosInLayer                          [i] = false;
+    m_firstPicInLayerDecodedFlag          [i] = false;
+    m_pocDecrementedInDpbFlag             [i] = false;
+    m_decodingOrder                       [i] = 0;
+    m_lastPresentPocResetIdc              [i] = MIN_INT;
+    m_firstPicInPocResettingPeriodReceived[i] = true;
+    m_noRaslOutputFlagAssocIrap           [i] = false;
+  }
+
+  m_curPic                          = NULL;
+  m_vps                             = NULL;
+  m_sps                             = NULL;
+  m_pps                             = NULL;
+  m_initilizedFromVPS               = false;
+  m_firstSliceInBitstream           = true;
+  m_newVpsActivatedbyCurAu          = false;
+  m_newVpsActivatedbyCurPic         = false;
+  m_handleCraAsBlaFlag              = false;
+  m_handleCraAsBlaFlagSetByExtMeans = false;
+  m_noClrasOutputFlag               = false;
+  m_noClrasOutputFlagSetByExtMeans  = false;
+  m_layerResetFlag                  = false;
+  m_totalNumofPicsReceived          = 0;
+  m_cvsStartFound                   = false;
 #endif
 #if NH_3D
-    m_pScaleOffsetFile  = 0;
+    m_pScaleOffsetFile              = 0;
 #endif
-
+}
+
+Void TAppDecTop::create()
+{
 #if NH_MV
-    m_markedForOutput = false; 
+#if ENC_DEC_TRACE
+  if ( g_hTrace == NULL )
+  {
+    g_hTrace = fopen( "TraceDec.txt", "wb" );
+    g_bJustDoIt = g_bEncDecTraceDisable;
+    g_nSymbolCounter = 0;
+  }
 #endif
-
-}
-
-Void TAppDecTop::create()
-{
+#endif
 }
 
@@ -115,5 +143,5 @@
   {
     free (m_pchScaleOffsetFile);
-    m_pchScaleOffsetFile = NULL; 
+    m_pchScaleOffsetFile = NULL;
   }
 #endif
@@ -132,10 +160,68 @@
  .
  */
+
+#if NH_MV
 Void TAppDecTop::decode()
 {
+  // create & initialize internal classes
+  xInitFileIO  ();
+  xCreateDecLib();
+  xInitDecLib  ();
+
+  InputByteStream bytestream(m_bitstreamFile);
+
+  while ( m_bitstreamFile )
+  {
+    AnnexBStats stats = AnnexBStats();
+    InputNALUnit nalu;
+
+    byteStreamNALUnit(bytestream, nalu.getBitstream().getFifo(), stats);
+
+    if (nalu.getBitstream().getFifo().empty())
+    {
+      /* this can happen if the following occur:
+       *  - empty input file
+       *  - two back-to-back start_code_prefixes
+       *  - start_code_prefix immediately followed by EOF
+       */
+      fprintf(stderr, "Warning: Attempt to decode an empty NAL unit\n");
+    }
+    else
+    {
+      read(nalu);
+
+      if ( m_printReceivedNalus )
+      {
+        std::cout << "Received NAL unit: ";
+        nalu.print();
+        std::cout << std::endl;
+      }
+
+      if ( xExtractAndRewrite( &nalu )
+          && nalu.m_nuhLayerId <= MAX_NUM_LAYER_IDS-1
+          && !(nalu.m_nalUnitType == NAL_UNIT_VPS && nalu.m_nuhLayerId > 0)
+          && !(nalu.m_nalUnitType == NAL_UNIT_EOB && nalu.m_nuhLayerId > 0)
+         )
+      {
+        xGetDecoderIdx( nalu.m_nuhLayerId , true );
+        if( nalu.isSlice() )
+        {
+          xProcessVclNalu   ( nalu );
+        }
+        else
+        {
+          xProcessNonVclNalu( nalu );
+        }
+      }
+    }
+  }
+ xTerminateDecoding();
+}
+#endif
+
+#if !NH_MV
+Void TAppDecTop::decode()
+{
   Int                 poc;
-#if NH_MV
-  poc = -1; 
-#endif
   TComList<TComPic*>* pcListPic = NULL;
 
@@ -146,11 +232,4 @@
     exit(EXIT_FAILURE);
   }
-#if NH_3D
-  if( m_pchScaleOffsetFile ) 
-  { 
-    m_pScaleOffsetFile = ::fopen( m_pchScaleOffsetFile, "wt" ); 
-    AOF( m_pScaleOffsetFile ); 
-  }
-#endif
 
   InputByteStream bytestream(bitstreamFile);
@@ -169,22 +248,9 @@
   xCreateDecLib();
   xInitDecLib  ();
-#if !NH_MV
+
   m_iPOCLastDisplay += m_iSkipFrame;      // set the last displayed POC correctly for skip forward.
 
   // main decoder loop
   Bool openedReconFile = false; // reconstruction file not yet opened. (must be performed after SPS is seen)
-#else
-
-  Int  pocCurrPic        = -MAX_INT;     
-  Int  pocLastPic        = -MAX_INT;   
-
-  Int  layerIdLastPic    = -MAX_INT; 
-  Int  layerIdCurrPic    = 0; 
-
-  Int  decIdxLastPic     = 0; 
-  Int  decIdxCurrPic     = 0; 
-
-  Bool firstSlice        = true; 
-#endif
   Bool loopFiltered = false;
 
@@ -201,9 +267,4 @@
     streampos location = bitstreamFile.tellg();
 #endif
-#if NH_MV
-#if ENC_DEC_TRACE
-    Int64 symCount = g_nSymbolCounter;
-#endif
-#endif
     AnnexBStats stats = AnnexBStats();
 
@@ -213,10 +274,4 @@
     // call actual decoding function
     Bool bNewPicture = false;
-#if NH_MV
-    Bool newSliceDiffPoc   = false;
-    Bool newSliceDiffLayer = false;
-    Bool sliceSkippedFlag  = false; 
-    Bool allLayersDecoded  = false;     
-#endif
     if (nalu.getBitstream().getFifo().empty())
     {
@@ -231,85 +286,12 @@
     {
       read(nalu);
-#if NH_MV      
-      if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) 
-          || !isNaluWithinTargetDecLayerIdSet(&nalu)
-          || nalu.m_nuhLayerId > MAX_NUM_LAYER_IDS-1
-          || (nalu.m_nalUnitType == NAL_UNIT_VPS && nalu.m_nuhLayerId > 0)           
-          || (nalu.m_nalUnitType == NAL_UNIT_EOB && nalu.m_nuhLayerId > 0)              
-         ) 
+
+      if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu)  )
       {
         bNewPicture = false;
-        if ( !bitstreamFile )
-        {
-          decIdxLastPic     = decIdxCurrPic; 
-        }
       }
       else
-      { 
-        Int decIdx     = xGetDecoderIdx( nalu.m_nuhLayerId , true );      
-        newSliceDiffLayer = nalu.isSlice() && ( nalu.m_nuhLayerId != layerIdCurrPic ) && !firstSlice;
-        newSliceDiffPoc   = m_tDecTop[decIdx]->decode(nalu, m_iSkipFrame, m_pocLastDisplay[decIdx], newSliceDiffLayer, sliceSkippedFlag );
-        // decode function only returns true when all of the following conditions are true
-        // - poc in particular layer changes
-        // - nalu does not belong to first slice in layer
-        // - nalu.isSlice() == true      
-
-        bNewPicture       = ( newSliceDiffLayer || newSliceDiffPoc ) && !sliceSkippedFlag; 
-        if ( nalu.isSlice() && firstSlice && !sliceSkippedFlag )        
-        {
-          layerIdCurrPic = nalu.m_nuhLayerId; 
-          pocCurrPic     = m_tDecTop[decIdx]->getCurrPoc(); 
-          decIdxCurrPic  = decIdx; 
-          firstSlice     = false; 
-
-          /// Use VPS activated by the first slice to determine OLS
-          m_vps = m_tDecTop[decIdx]->getActiveVPS( );
-          if ( m_targetDecLayerIdSetFileEmpty )
-          {            
-            if ( m_targetOptLayerSetIdx == -1 )
-            {
-              m_targetOptLayerSetIdx = m_tDecTop[decIdx]->getTargetOlsIdx(); 
-            }
-            else
-            {
-              assert( m_tDecTop[decIdx]->getTargetOlsIdx() == m_targetOptLayerSetIdx );
-            }
-
-            if ( m_targetOptLayerSetIdx < 0 || m_targetOptLayerSetIdx >= m_vps->getNumOutputLayerSets() )
-            {
-              fprintf(stderr, "\ntarget output layer set index must be in the range of 0 to %d, inclusive \n", m_vps->getNumOutputLayerSets() - 1 );            
-              exit(EXIT_FAILURE);
-            }
-            m_targetDecLayerIdSet = m_vps->getTargetDecLayerIdList( m_targetOptLayerSetIdx ); 
-          }
-
-          if (m_outputVpsInfo )
-          {
-            m_vps->printScalabilityId();
-            m_vps->printLayerDependencies();
-            m_vps->printLayerSets();
-            m_vps->printPTL(); 
-          }
-        }        
-
-        if ( bNewPicture || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS )
-        { 
-          layerIdLastPic    = layerIdCurrPic; 
-          layerIdCurrPic    = nalu.m_nuhLayerId; 
-          pocLastPic        = pocCurrPic; 
-          pocCurrPic        = m_tDecTop[decIdx]->getCurrPoc(); 
-          decIdxLastPic     = decIdxCurrPic; 
-          decIdxCurrPic     = decIdx; 
-          allLayersDecoded = ( pocCurrPic != pocLastPic ) && ( nalu.m_nalUnitType != NAL_UNIT_EOS );
-        }
-#else
-      if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu)  )
-      {
-        bNewPicture = false;
-      }
-      else
       {
         bNewPicture = m_cTDecTop.decode(nalu, m_iSkipFrame, m_iPOCLastDisplay);
-#endif
         if (bNewPicture)
         {
@@ -327,17 +309,4 @@
           bytestream.reset();
 #endif
-#if H_MV_ENC_DEC_TRAC
-#if ENC_DEC_TRACE
-          const Bool resetCounter = false; 
-          if ( resetCounter )
-          {
-            g_nSymbolCounter  = symCount; // Only reset counter SH becomes traced twice
-          }
-          else
-          {
-            g_disableHLSTrace = true;     // Tracing of second parsing of SH is not carried out
-          }      
-#endif
-#endif
         }
       }
@@ -345,64 +314,27 @@
 
     if ( (bNewPicture || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS) &&
-#if NH_MV      
-      !m_tDecTop[decIdxLastPic]->getFirstSliceInSequence () )
-#else
+
       !m_cTDecTop.getFirstSliceInSequence () )
-#endif
 
     {
       if (!loopFiltered || bitstreamFile)
       {
-#if NH_MV
-        assert( decIdxLastPic != -1 ); 
-        m_tDecTop[decIdxLastPic]->endPicDecoding(poc, pcListPic, m_targetDecLayerIdSet );
-        xMarkForOutput( allLayersDecoded, poc, layerIdLastPic ); 
-#else
         m_cTDecTop.executeLoopFilters(poc, pcListPic);
-#endif
       }
       loopFiltered = (nalu.m_nalUnitType == NAL_UNIT_EOS);
       if (nalu.m_nalUnitType == NAL_UNIT_EOS)
       {
-#if NH_MV      
-        m_tDecTop[decIdxLastPic]->setFirstSliceInSequence(true);
-#else
         m_cTDecTop.setFirstSliceInSequence(true);
-#endif
       }
     }
     else if ( (bNewPicture || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS ) &&
-#if NH_MV      
-              m_tDecTop[decIdxLastPic]->getFirstSliceInSequence () ) 
-#else
-              m_cTDecTop.getFirstSliceInSequence () ) 
-#endif
-    {
-#if NH_MV      
-      m_tDecTop[decIdxLastPic]->setFirstSliceInPicture (true);
-#else
+              m_cTDecTop.getFirstSliceInSequence () )
+    {
       m_cTDecTop.setFirstSliceInPicture (true);
-#endif
-    }
-
-#if NH_3D
-    if ( allLayersDecoded || !bitstreamFile )
-    {
-      for( Int dI = 0; dI < m_numDecoders; dI++ )
-      {
-        TComPic* picLastCoded = m_ivPicLists.getPic( m_tDecTop[dI]->getLayerId(), pocLastPic );
-        assert( picLastCoded != NULL );        
-        picLastCoded->compressMotion(1);
-      }
-    }
-#endif
+   }
 
     if( pcListPic )
     {
-#if NH_MV
-      if ( m_pchReconFiles[decIdxLastPic] && !m_reconOpen[decIdxLastPic] )
-#else
       if ( m_pchReconFile && !openedReconFile )
-#endif
       {
         const BitDepths &bitDepths=pcListPic->front()->getPicSym()->getSPS().getBitDepths(); // use bit depths of first reconstructed picture.
@@ -414,33 +346,10 @@
           }
         }
-#if NH_MV
-        m_tVideoIOYuvReconFile[decIdxLastPic]->open( m_pchReconFiles[decIdxLastPic], true, m_outputBitDepth, m_outputBitDepth, bitDepths.recon ); // write mode
-        m_reconOpen[decIdxLastPic] = true;
+        m_cTVideoIOYuvReconFile.open( m_pchReconFile, true, m_outputBitDepth, m_outputBitDepth, bitDepths.recon ); // write mode
+        openedReconFile = true;
       }
       // 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 ( (bNewPicture || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_CRA) && m_tDecTop[decIdxLastPic]->getNoOutputPriorPicsFlag() )
-      {
-        m_tDecTop[decIdxLastPic]->checkNoOutputPriorPics( pcListPic );
-        m_tDecTop[decIdxLastPic]->setNoOutputPriorPicsFlag (false);
-      }
-
-      if ( bNewPicture && newSliceDiffPoc && 
-#else
-        m_cTVideoIOYuvReconFile.open( m_pchReconFile, true, m_outputBitDepth, m_outputBitDepth, bitDepths.recon ); // write mode
-        openedReconFile = true;
-      }
-      // write reconstruction to file
-      if( bNewPicture )
-      {
         xWriteOutput( pcListPic, nalu.m_temporalId );
       }
@@ -452,5 +361,4 @@
 
       if ( bNewPicture &&
-#endif
            (   nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL
             || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP
@@ -459,56 +367,21 @@
             || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP ) )
       {
-#if NH_MV
-        xFlushOutput( pcListPic, decIdxLastPic );
-#else
+
         xFlushOutput( pcListPic );
-#endif
       }
       if (nalu.m_nalUnitType == NAL_UNIT_EOS)
       {
-#if NH_MV
-        xWriteOutput( pcListPic, decIdxCurrPic, nalu.m_temporalId );
-#else
+
         xWriteOutput( pcListPic, nalu.m_temporalId );
-#endif
-#if NH_MV
-        m_tDecTop[decIdxCurrPic]->setFirstSliceInPicture (false);
-#else
         m_cTDecTop.setFirstSliceInPicture (false);
-#endif
       }
       // write reconstruction to file -- for additional bumping as defined in C.5.2.3
-#if NH_MV
-      // Above comment seems to be wrong
-#endif
       if(!bNewPicture && nalu.m_nalUnitType >= NAL_UNIT_CODED_SLICE_TRAIL_N && nalu.m_nalUnitType <= NAL_UNIT_RESERVED_VCL31)
       {
-#if NH_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 NH_MV
-#if NH_3D
-  if( m_cCamParsCollector.isInitialized() )
-  {
-    m_cCamParsCollector.setSlice( 0 );
-  }
-#endif
-  for(UInt decIdx = 0; decIdx < m_numDecoders; decIdx++)
-  {
-    xFlushOutput( m_tDecTop[decIdx]->getListPic(), decIdx );
-  }
-#else  
+      }
+    }
+  }
+
   xFlushOutput( pcListPic );
   // delete buffers
@@ -516,6 +389,6 @@
   // destroy internal classes
   xDestroyDecLib();
+}
 #endif
-}
 
 // ====================================================================================================================
@@ -527,5 +400,5 @@
 #if NH_MV
   // initialize global variables
-  initROM();  
+  initROM();
 #if NH_3D_DMM
   initWedgeLists();
@@ -548,5 +421,5 @@
     {
       m_tVideoIOYuvReconFile[decIdx]->close();
-      delete m_tVideoIOYuvReconFile[decIdx]; 
+      delete m_tVideoIOYuvReconFile[decIdx];
       m_tVideoIOYuvReconFile[decIdx] = NULL ;
     }
@@ -554,8 +427,10 @@
     if( m_tDecTop[decIdx] )
     {
+#if !NH_MV
       m_tDecTop[decIdx]->deletePicBuffer();
+#endif
       m_tDecTop[decIdx]->destroy() ;
     }
-    delete m_tDecTop[decIdx] ; 
+    delete m_tDecTop[decIdx] ;
     m_tDecTop[decIdx] = NULL ;
   }
@@ -571,7 +446,7 @@
 #if NH_3D
   m_cCamParsCollector.uninit();
-  if( m_pScaleOffsetFile ) 
-  { 
-    ::fclose( m_pScaleOffsetFile ); 
+  if( m_pScaleOffsetFile )
+  {
+    ::fclose( m_pScaleOffsetFile );
   }
 #endif
@@ -584,5 +459,7 @@
   m_cCamParsCollector.setCodeScaleOffsetFile( m_pScaleOffsetFile );
 #endif
-#if !NH_MV
+#if NH_MV
+  m_dpb.setPrintPicOutput(m_printPicOutput);
+#else
   // initialize decoder class
   m_cTDecTop.init();
@@ -599,12 +476,10 @@
 }
 
+
+#if !NH_MV
 /** \param pcListPic list of pictures to be written to file
     \param tId       temporal sub-layer ID
  */
-#if NH_MV
-Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, Int decIdx, Int tId )
-#else
 Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, UInt tId )
-#endif
 {
   if (pcListPic->empty())
@@ -625,10 +500,10 @@
   {
     numReorderPicsHighestTid = activeSPS->getNumReorderPics(maxNrSublayers-1);
-    maxDecPicBufferingHighestTid =  activeSPS->getMaxDecPicBuffering(maxNrSublayers-1); 
+    maxDecPicBufferingHighestTid =  activeSPS->getMaxDecPicBuffering(maxNrSublayers-1);
   }
   else
   {
     numReorderPicsHighestTid = activeSPS->getNumReorderPics(m_iMaxTemporalLayer);
-    maxDecPicBufferingHighestTid = activeSPS->getMaxDecPicBuffering(m_iMaxTemporalLayer); 
+    maxDecPicBufferingHighestTid = activeSPS->getMaxDecPicBuffering(m_iMaxTemporalLayer);
   }
 
@@ -636,9 +511,5 @@
   {
     TComPic* pcPic = *(iterPic);
-#if NH_MV
-    if(pcPic->getOutputMark() && pcPic->getPOC() > m_pocLastDisplay[decIdx])
-#else
     if(pcPic->getOutputMark() && pcPic->getPOC() > m_iPOCLastDisplay)
-#endif
     {
        numPicsNotYetDisplayed++;
@@ -671,23 +542,12 @@
       TComPic* pcPicBottom = *(iterPic);
 
-#if NH_MV
-      if ( pcPicTop->getOutputMark() && pcPicBottom->getOutputMark() &&
-        (numPicsNotYetDisplayed >  numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid) &&
-        (!(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1) &&
-        (pcPicTop->getPOC() == m_pocLastDisplay[decIdx]+1 || m_pocLastDisplay[decIdx] < 0))
-#else
       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
       {
         // write to file
         numPicsNotYetDisplayed = numPicsNotYetDisplayed-2;
-#if NH_MV
-      if ( m_pchReconFiles[decIdx] )
-#else
         if ( m_pchReconFile )
-#endif
         {
           const Window &conf = pcPicTop->getConformanceWindow();
@@ -708,35 +568,15 @@
           if (display)
           {
-#if NH_MV
-        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
         m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
-#endif
                                            m_outputColourSpaceConvert,
                                            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
                                            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
                                            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
-#if NH_3D
-                                           conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), m_depth420OutputFlag && pcPicTop->getIsDepth() ? CHROMA_420 : NUM_CHROMA_FORMAT, isTff );
-#else
                                            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), NUM_CHROMA_FORMAT, isTff );
-#endif
           }
         }
 
         // update POC of display order
-#if NH_MV
-        m_pocLastDisplay[decIdx] = pcPic->getPOC();
-#else
         m_iPOCLastDisplay = pcPicBottom->getPOC();
-#endif
 
         // erase non-referenced picture in the reference picture list after display
@@ -768,11 +608,6 @@
       pcPic = *(iterPic);
 
-#if NH_MV
-      if(pcPic->getOutputMark() && pcPic->getPOC() > m_pocLastDisplay[decIdx] &&
-        (numPicsNotYetDisplayed >  numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid))
-#else      
       if(pcPic->getOutputMark() && pcPic->getPOC() > m_iPOCLastDisplay &&
         (numPicsNotYetDisplayed >  numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid))
-#endif
       {
         // write to file
@@ -782,44 +617,20 @@
           dpbFullness--;
         }
-#if NH_MV
-      if ( m_pchReconFiles[decIdx] )
-#else
         if ( m_pchReconFile )
-#endif
         {
           const Window &conf    = pcPic->getConformanceWindow();
           const Window defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
-#if NH_MV
-        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
+
           m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(),
-#endif
                                          m_outputColourSpaceConvert,
                                          conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
                                          conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
                                          conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
-                                         conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), 
-#if NH_3D
-                                          m_depth420OutputFlag && pcPic->getIsDepth() ? CHROMA_420 : NUM_CHROMA_FORMAT,
-#else
-                                          NUM_CHROMA_FORMAT,
-#endif
-           m_bClipOutputVideoToRec709Range   );
+                                         conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(),
+                                         NUM_CHROMA_FORMAT, m_bClipOutputVideoToRec709Range  );
         }
 
         // update POC of display order
-#if NH_MV
-        m_pocLastDisplay[decIdx] = pcPic->getPOC();
-#else
         m_iPOCLastDisplay = pcPic->getPOC();
-#endif
 
         // erase non-referenced picture in the reference picture list after display
@@ -832,7 +643,4 @@
         }
         pcPic->setOutputMark(false);
-#if NH_MV
-        pcPic->setPicOutputFlag(false);
-#endif
       }
 
@@ -844,9 +652,5 @@
 /** \param pcListPic list of pictures to be written to file
  */
-#if NH_MV
-Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic, Int decIdx )
-#else
 Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic )
-#endif
 {
   if(!pcListPic || pcListPic->empty())
@@ -873,43 +677,21 @@
       {
         // write to file
-#if NH_MV
-      if ( m_pchReconFiles[decIdx] )
-#else
+
         if ( m_pchReconFile )
-#endif
         {
           const Window &conf = pcPicTop->getConformanceWindow();
           const Window  defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window();
           const Bool isTff = pcPicTop->isTopField();
-#if NH_MV
-        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
           m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
-#endif
                                          m_outputColourSpaceConvert,
                                          conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
                                          conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
                                          conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
-#if NH_3D
-                                         conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), m_depth420OutputFlag && pcPicTop->getIsDepth() ? CHROMA_420 : NUM_CHROMA_FORMAT, isTff );
-#else
                                          conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), NUM_CHROMA_FORMAT, isTff );
-#endif
         }
 
         // update POC of display order
-#if NH_MV
-      m_pocLastDisplay[decIdx] = pcPic->getPOC();
-#else
         m_iPOCLastDisplay = pcPicBottom->getPOC();
-#endif        
+
         // erase non-referenced picture in the reference picture list after display
         if ( !pcPicTop->getSlice(0)->isReferenced() && pcPicTop->getReconMark() == true )
@@ -954,45 +736,19 @@
       {
         // write to file
-#if NH_MV
-      if ( m_pchReconFiles[decIdx] )
-#else
         if ( m_pchReconFile )
-#endif
         {
           const Window &conf    = pcPic->getConformanceWindow();
           const Window  defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
-#if NH_MV
-        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
           m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(),
-#endif
                                          m_outputColourSpaceConvert,
                                          conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
                                          conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
                                          conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
-                                         conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), 
-#if NH_3D
-                                         m_depth420OutputFlag && pcPic->getIsDepth() ? CHROMA_420 : NUM_CHROMA_FORMAT
-#else
-                                         NUM_CHROMA_FORMAT
-#endif
-                                         , m_bClipOutputVideoToRec709Range);
+                                         conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(),
+                                         NUM_CHROMA_FORMAT, m_bClipOutputVideoToRec709Range );
         }
 
         // update POC of display order
-#if NH_MV
-      m_pocLastDisplay[decIdx] = pcPic->getPOC();
-#else
         m_iPOCLastDisplay = pcPic->getPOC();
-#endif
-
         // erase non-referenced picture in the reference picture list after display
         if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true )
@@ -1004,9 +760,5 @@
         }
         pcPic->setOutputMark(false);
-#if NH_MV
-        pcPic->setPicOutputFlag(false);
-#endif
-      }
-#if !NH_MV
+      }
       if(pcPic != NULL)
       {
@@ -1015,19 +767,18 @@
         pcPic = NULL;
       }
-#endif
       iterPic++;
     }
   }
-#if NH_MV
-  m_pocLastDisplay[decIdx] = -MAX_INT;
-#else
   pcListPic->clear();
   m_iPOCLastDisplay = -MAX_INT;
+}
 #endif
-}
-
 /** \param nalu Input nalu to check whether its LayerId is within targetDecLayerIdSet
  */
+#if NH_MV
+Bool TAppDecTop::xIsNaluInTargetDecLayerIdSet( InputNALUnit* nalu )
+#else
 Bool TAppDecTop::isNaluWithinTargetDecLayerIdSet( InputNALUnit* nalu )
+#endif
 {
   if ( m_targetDecLayerIdSet.size() == 0 ) // By default, the set is empty, meaning all LayerIds are allowed
@@ -1037,36 +788,1858 @@
   for (std::vector<Int>::iterator it = m_targetDecLayerIdSet.begin(); it != m_targetDecLayerIdSet.end(); it++)
   {
+    if ( nalu->m_nuhLayerId == (*it) )
+    {
+      return true;
+    }
+  }
+  return false;
+}
+
 #if NH_MV
-    if ( nalu->m_nuhLayerId == (*it) )
-#else
-    if ( nalu->m_nuhLayerId == (*it) )
+
+Bool TAppDecTop::xExtractAndRewrite( InputNALUnit* nalu )
+{
+  Bool naluInSubStream;
+  if ( !m_initilizedFromVPS )
+  {
+    naluInSubStream = true; // No active VPS yet. Wait for slice activating one.
+  }
+  else
+  {
+    if ( m_decProcCvsg == CLAUSE_8 )
+    {
+      // 8.1.2->clause 10
+
+      // sub-bitstream extraction process as specified in clause 10
+      naluInSubStream = true;
+      if ( nalu->m_temporalId > m_highestTid || !xIsNaluInTargetDecLayerIdSet(nalu) )
+      {
+        naluInSubStream = false;
+      }
+    }
+    else
+    {
+      // F.8.1.2
+      Int targetDecLayerSetIdx = m_vps->olsIdxToLsIdx( m_targetOptLayerSetIdx );
+      if ( targetDecLayerSetIdx <= m_vps->getVpsNumLayerSetsMinus1() && m_vps->getVpsBaseLayerInternalFlag() )
+      {
+        // - If TargetDecLayerSetIdx is less than or equal to vps_num_layer_sets_minus1 and
+        //   vps_base_layer_internal_flag is equal to 1, the following applies:
+        //   - The sub-bitstream extraction process as specified in clause 10 is applied with the CVSG, HighestTid and
+        //     TargetDecLayerIdList as inputs, and the output is assigned to a bitstream referred to as BitstreamToDecode.
+
+        naluInSubStream = true;
+        if ( nalu->m_temporalId > m_highestTid || !xIsNaluInTargetDecLayerIdSet(nalu) )
+        {
+          naluInSubStream = false;
+        }
+
+      }
+      else if ( targetDecLayerSetIdx <= m_vps->getVpsNumLayerSetsMinus1() && !m_vps->getVpsBaseLayerInternalFlag() )
+      {
+        // - Otherwise, if TargetDecLayerSetIdx is less than or equal to vps_num_layer_sets_minus1 and vps_base_layer_internal_flag
+        //   is equal to 0, the following applies:
+        //   - The sub-bitstream extraction process as specified in clause F.10.1 is applied with the CVSG, HighestTid and
+        //     TargetDecLayerIdList as inputs, and the output is assigned to a bitstream referred to as BitstreamToDecode.
+
+        naluInSubStream = true;
+        if ( nalu->m_temporalId > m_highestTid || !xIsNaluInTargetDecLayerIdSet(nalu) )
+        {
+          naluInSubStream = false;
+        }
+      }
+      else if ( targetDecLayerSetIdx > m_vps->getVpsNumLayerSetsMinus1() && m_vps->getNumLayersInIdList( targetDecLayerSetIdx ) == 1 )
+      {
+        // - Otherwise, if TargetDecLayerSetIdx is greater than vps_num_layer_sets_minus1 and
+        //   NumLayersInIdList[ TargetDecLayerSetIdx ] is equal to 1, the following applies:
+        //   - The independent non-base layer rewriting process of clause F.10.2 is applied with the CVSG, HighestTid and
+        //     TargetDecLayerIdList[ 0 ] as inputs, and the output is assigned to a bitstream referred to as BitstreamToDecode.
+
+        Int assingedBaseLayerId = m_targetDecLayerIdSet[0];
+        naluInSubStream = true;
+
+        if ( nalu->m_nalUnitType != NAL_UNIT_SPS &&
+          nalu->m_nalUnitType != NAL_UNIT_PPS &&
+          nalu->m_nalUnitType != NAL_UNIT_EOB &&
+          nalu->m_nuhLayerId != assingedBaseLayerId )
+        {
+          naluInSubStream = false;
+        }
+
+        if ( ( nalu->m_nalUnitType == NAL_UNIT_SPS || nalu->m_nalUnitType != NAL_UNIT_PPS ) &&
+          !( nalu->m_nuhLayerId == 0 || nalu->m_nuhLayerId == assingedBaseLayerId ) )
+        {
+          naluInSubStream = false;
+        }
+
+        if ( nalu->m_nalUnitType == NAL_UNIT_VPS )
+        {
+          naluInSubStream = false;
+        }
+
+        if ( nalu->m_temporalId > m_highestTid )
+        {
+          naluInSubStream = false;
+        }
+                
+        // For now, don't do the layer id change here, but change smallest layer id. 
+        // To be verified.         
+        //if ( naluInSubStream )
+        //{
+        //  nalu->m_nuhLayerId = 0;
+        //}
+      }
+      else
+      {
+        // - Otherwise, the following applies:
+        //   - The sub-bitstream extraction process as specified in clause F.10.3 is applied with the CVSG, HighestTid and
+        //     TargetDecLayerIdList as inputs, and the output is assigned to a bitstream referred to as BitstreamToDecode.
+
+        naluInSubStream = true;
+
+        if ( nalu->m_nalUnitType != NAL_UNIT_VPS &&
+          nalu->m_nalUnitType != NAL_UNIT_SPS &&
+          nalu->m_nalUnitType != NAL_UNIT_PPS &&
+          nalu->m_nalUnitType != NAL_UNIT_EOS &&
+          nalu->m_nalUnitType != NAL_UNIT_EOB &&
+          !xIsNaluInTargetDecLayerIdSet(nalu) )
+        {
+          naluInSubStream = false;
+        }
+
+        if ( ( nalu->m_nalUnitType == NAL_UNIT_VPS ||
+          nalu->m_nalUnitType == NAL_UNIT_SPS ||
+          nalu->m_nalUnitType == NAL_UNIT_PPS ||
+          nalu->m_nalUnitType == NAL_UNIT_EOS    ) &&
+          !( nalu->m_nuhLayerId == 0 || xIsNaluInTargetDecLayerIdSet(nalu) )
+          )
+        {
+          naluInSubStream = false;
+        }
+
+        if ( nalu->m_temporalId > m_highestTid )
+        {
+          naluInSubStream = false;
+        }
+        // TBD: vps_base_layer_available_flag in each VPS is set equal to 0.
+      }
+    }
+  }
+
+  return naluInSubStream;
+}
+
+Void TAppDecTop::xProcessVclNalu( InputNALUnit nalu )
+{
+  TDecTop* dec  = xGetDecoder( nalu );
+
+  // Decode slice header of slice of current or new picture.
+  dec->decodeSliceHeader( nalu );
+
+  // Check if slice belongs to current or new picture
+  Bool sliceIsFirstOfNewPicture = dec->getFirstSliceSegementInPicFlag();
+
+  if ( !xIsSkipVclNalu( nalu, sliceIsFirstOfNewPicture ) )
+  {
+    if ( sliceIsFirstOfNewPicture )
+    {
+      xDetectNewPocResettingPeriod( nalu );
+      Bool sliceIsFirstOfNewAU = xDetectNewAu( nalu );
+      xFinalizePreviousPictures ( sliceIsFirstOfNewAU );
+      xDecodeFirstSliceOfPicture( nalu, sliceIsFirstOfNewAU );
+    }
+    else
+    {
+      xDecodeFollowSliceOfPicture( nalu );
+    }
+  }
+}
+
+Bool TAppDecTop::xIsSkipVclNalu( InputNALUnit& nalu, Bool isFirstSliceOfPic )
+{
+
+  TDecTop* dec = xGetDecoder( nalu ); 
+
+  m_handleCraAsBlaFlagSetByExtMeans = false;
+  Bool skipNalu = false;
+
+  if ( isFirstSliceOfPic )
+  {
+    m_totalNumofPicsReceived++;
+  }
+
+  if (!m_cvsStartFound )
+  {
+    // Skip as specified by decoder option. (Not normative!)
+    if ( m_totalNumofPicsReceived <= m_iSkipFrame )
+    {
+      skipNalu = true;
+      if ( isFirstSliceOfPic )
+      {
+        std::cout << "Layer " << std::setfill(' ') << std::setw(2) << nalu.m_nuhLayerId
+          << "   POC    ? Skipping picture." << std::setw(5) << m_totalNumofPicsReceived - 1 << std::endl;
+      }
+    }
+    else
+    {      
+      if ( dec->getIsInOwnTargetDecLayerIdList() )
+      {
+        // Search for initial IRAP access unit
+        Bool canBeSliceOfInitialIrapAu = nalu.isIrap() && ( dec->decProcClause8() || nalu.m_nuhLayerId == dec->getSmallestLayerId() );
+
+        if ( !canBeSliceOfInitialIrapAu )
+        {
+          skipNalu = true;
+          if ( isFirstSliceOfPic )
+          {
+            std::cout << "Layer " << std::setfill(' ') << std::setw(2) << nalu.m_nuhLayerId
+              << "   POC    ? Not an initial IRAP AU. Skipping picture." << std::setw(5) << m_totalNumofPicsReceived - 1 << std::endl;
+          }
+        }
+        else
+        {
+          m_cvsStartFound = true;
+          if( nalu.isCra() )
+          {
+            // Ensure that NoRaslOutputFlag of picture is equal to 1.
+            m_handleCraAsBlaFlagSetByExtMeans = true;
+            m_handleCraAsBlaFlag = true;
+          }
+        }
+      }
+      else
+      {
+        skipNalu = true; 
+      }
+    }
+  }
+  else
+  {
+    assert( dec->getIsInOwnTargetDecLayerIdList() ); 
+  }
+  return skipNalu;
+}
+
+Void TAppDecTop::xProcessNonVclNalu( InputNALUnit nalu )
+{
+  xGetDecoder(nalu)->decodeNonVclNalu( nalu );
+
+  if (  nalu.m_nalUnitType == NAL_UNIT_EOS )
+  {
+    m_eosInLayer[ nalu.m_nuhLayerId ] = true;
+  }
+}
+Void TAppDecTop::xTerminateDecoding()
+{
+    xFinalizePic( true );
+    xFinalizeAU ( );
+
+#if NH_3D
+  if( m_cCamParsCollector.isInitialized() )
+  {
+    m_cCamParsCollector.setSlice( 0 );
+  }
 #endif
-    {
-      return true;
-    }
-  }
-  return false;
-}
-
-#if NH_MV
+   xFlushOutput(); 
+   m_dpb.emptyAllSubDpbs();
+}
+
+
+//////////////////////////////
+/// Process slices
+//////////////////////////////
+
+Void TAppDecTop::xDecodeFirstSliceOfPicture( InputNALUnit nalu, Bool sliceIsFirstOfNewAu )
+{
+  TDecTop* dec = xGetDecoder(nalu);
+  // Initialize from VPS of first slice
+
+  // Get current SPS and PPS
+  TComSlice* slicePilot = dec->getSlicePilot(); 
+  m_vps = slicePilot->getVPS(); 
+  m_sps = slicePilot->getSPS(); 
+  m_pps = slicePilot->getPPS(); 
+
+  /// Use VPS activated by the first slice to initialized decoding
+  if( !m_initilizedFromVPS )
+  {
+    xF811GeneralDecProc( nalu );
+    m_initilizedFromVPS = true;
+    m_newVpsActivatedbyCurAu  = true; //TBD
+    m_newVpsActivatedbyCurPic = true;
+#if NH_3D
+    m_dpb.setVPS( m_vps ); 
+#endif
+  }
+
+  // Create new sub-DBP if not existing
+  m_dpb.getSubDpb( nalu.m_nuhLayerId, true );
+
+  // Create a new picture initialize and make it the current picture
+  assert( m_curPic == NULL );
+  m_curPic = new TComPic;
+
+  m_curPic->create(*m_sps, *m_pps, true);
+
+  m_curPic->setLayerId                      ( nalu.m_nuhLayerId );
+  m_curPic->setDecodingOrder                ( m_decodingOrder[ nalu.m_nuhLayerId ]);
+  m_curPic->setIsFstPicOfAllLayOfPocResetPer( m_newPicIsFstPicOfAllLayOfPocResetPer );
+  m_curPic->setIsPocResettingPic            ( m_newPicIsPocResettingPic );
+  m_curPic->setActivatesNewVps              ( m_newVpsActivatedbyCurPic );
+
+  dec     ->activatePSsAndInitPicOrSlice( m_curPic );
+
+  m_decodingOrder[ nalu.m_nuhLayerId ]++;
+
+  // Insert pic to current AU
+  // ( There is also a "current AU in the DBP", however the DBP AU will include the current
+  //   picture only after it is inserted to the DBP )
+  m_curAu.addPic(  m_curPic, true );
+
+  // Invoke Claus 8 and Annex F decoding process for a picture (only parts before POC derivation ).
+  xPicDecoding( START_PIC, sliceIsFirstOfNewAu );
+
+  if (m_decProcCvsg == ANNEX_F )
+  {
+    // Do output before POC derivation
+    xF13522OutputAndRemOfPicsFromDpb( true );
+  }
+
+  // Decode POC and apply reference picture set
+  dec->setDecProcPocAndRps( m_decProcPocAndRps );
+  dec->decodePocAndRps( );
+
+  // Do output after POC and RPS derivation
+  if (m_decProcCvsg == CLAUSE_8 )
+  {
+    xC522OutputAndRemOfPicsFromDpb( );
+  }
+  else if (m_decProcCvsg == ANNEX_F )
+  {
+    xF13522OutputAndRemOfPicsFromDpb( false );
+  }
+  else
+  {
+    assert(false);
+  }
+
+  // Generate unavailable reference pictures
+  dec->genUnavailableRefPics( );
+
+  // decode first slice segment
+  dec->decodeSliceSegment( nalu );
+
+  m_firstSliceInBitstream = false;
+}
+
+Void TAppDecTop::xDecodeFollowSliceOfPicture( InputNALUnit nalu )
+{
+  // decode following segment
+    TDecTop* dec = xGetDecoder( nalu ); 
+    dec->activatePSsAndInitPicOrSlice( NULL );
+    dec->decodeSliceSegment          ( nalu );
+}
+
+Void TAppDecTop::xFinalizePreviousPictures( Bool sliceIsFirstOfNewAU )
+{
+  Bool curPicIsLastInAu = sliceIsFirstOfNewAU && (m_curPic != NULL);
+  // When slice belongs to new picture, finalize current picture.
+  if( m_curPic != NULL )
+  {
+    xFinalizePic( curPicIsLastInAu );
+
+    if (m_curPic->isIrap() )
+    {
+      m_noRaslOutputFlagAssocIrap[ m_curPic->getLayerId() ] = m_curPic->getNoRaslOutputFlag();
+    }
+
+    m_tDecTop[ xGetDecoderIdx( m_curPic->getLayerId() )]->finalizePic();
+    m_curPic->getPicYuvRec()->extendPicBorder(); 
+    m_newVpsActivatedbyCurPic = false;
+  }
+
+  // When slice belongs to new AU, finalize current AU.
+  if ( curPicIsLastInAu && !m_curAu.empty() )
+  {
+    xFinalizeAU( );
+    m_newVpsActivatedbyCurAu = false;
+    m_curAu.clear();
+  }
+  m_curPic = NULL;
+}
+
+
+Void TAppDecTop::xFinalizePic(Bool curPicIsLastInAu )
+{
+  if ( m_curPic != NULL )
+  {
+    m_tDecTop[ xGetDecoderIdx(m_curPic->getLayerId() ) ]->executeLoopFilters( ); // 8.7
+
+    // Invoke Claus 8 and F.8 decoding process for a picture (only parts after POC derivation )
+    xPicDecoding(FINALIZE_PIC, curPicIsLastInAu );
+
+    if( m_decProcCvsg == CLAUSE_8 )
+    {
+      xC523PicDecMarkAddBumpAndStor    ( );
+    }
+    else if ( m_decProcCvsg == ANNEX_F )
+    {
+      xF13523PicDecMarkAddBumpAndStor  ( curPicIsLastInAu );
+    }
+  }
+}
+
+Void TAppDecTop::xFinalizeAU()
+{
+#if NH_3D
+  if ( !m_curAu.empty())
+  {
+    for (TComList<TComPic*>::iterator it = m_curAu.begin(); it != m_curAu.end(); it++)
+    {
+      TComPic* pic = (*it);
+      if ( !pic->getHasGeneratedRefPics() )
+      {
+        pic->compressMotion(1);
+      }
+    }
+  }
+#endif
+}
+
+
+Void TAppDecTop::xF811GeneralDecProc( InputNALUnit nalu )
+{
+  ////////////////////////////////////////////////////////////////////////////////
+  // F.8.1 General decoding process
+  ////////////////////////////////////////////////////////////////////////////////
+
+  // The following applies at the beginning of decoding a CVSG, after activating the VPS RBSP that is active for
+  // the entire CVSG and before decoding any VCL NAL units of the CVSG:
+
+  if ( !m_vps->getVpsExtensionFlag() )
+  {
+    //-   If vps_extension( ) is not present in the active VPS or a decoding process specified in this annex is not in use,
+    //   clause 8.1.2 is invoked with the CVSG as input.
+    x812CvsgDecodingProcess( xGetDecoderIdx( nalu.m_nuhLayerId ) );
+    m_decProcCvsg = CLAUSE_8;
+  }
+  else
+  {
+    // - Otherwise (vps_extension( ) is present in the active VPS and a decoding process specified in this annex is in use),
+    xF812CvsgDecodingProcess( xGetDecoderIdx( nalu.m_nuhLayerId ) );
+    xF13521InitDpb();
+    m_decProcCvsg = ANNEX_F;
+  }
+
+  if ( m_printVpsInfo  && ( m_decProcCvsg == ANNEX_F ) )
+  {
+    m_vps->printScalabilityId();
+    m_vps->printLayerDependencies();
+    m_vps->printLayerSets();
+    m_vps->printPTL();
+  }
+}
+
+Void   TAppDecTop::xPicDecoding( DecProcPart curPart, Bool picPosInAuIndication )
+{
+  if ( m_decProcCvsg == CLAUSE_8 )
+  {
+    // F.8.1.1 -> 8.1.2 -> 8.1.3
+    x813decProcForCodPicWithLIdZero  ( curPart );
+  }
+  else if ( m_decProcCvsg == ANNEX_F )
+  {
+    if ( m_targetOptLayerSetIdx == 0  )
+    {
+      // F.8.1.1 -> F.8.1.2 -> 8.1.3
+      x813decProcForCodPicWithLIdZero  ( curPart );
+    }
+    else
+    {
+      // F.8.1.1 -> F.8.1.2 -> F.8.1.3
+      xF813ComDecProcForACodedPic( curPart, picPosInAuIndication );
+    }
+  }
+  else
+  {
+    assert( false );
+  }
+}
+
+Void TAppDecTop::x812CvsgDecodingProcess( Int decIdx )
+{
+  ///////////////////////////////////////////////////////////////////////////////////////
+  //  8.1.2 CVSG decoding process
+  ///////////////////////////////////////////////////////////////////////////////////////
+
+  // The layer identifier list TargetDecLayerIdList, which specifies the list of nuh_layer_id values,
+  // in increasing order of nuh_layer_id values, of the NAL units to be decoded, is specified as follows:
+
+  Bool externalMeansToSetTargetDecLayerIdList = !m_targetDecLayerIdSetFileEmpty;
+
+  if ( externalMeansToSetTargetDecLayerIdList )
+  {
+    // - If some external means, not specified in this Specification, is available to set TargetDecLayerIdList,
+    //   TargetDecLayerIdList is set by the external means.
+    assert( !m_targetDecLayerIdSet.empty() ); // Already done when parsing cfg ile
+  }
+  else
+  {
+    //-  Otherwise, TargetDecLayerIdList contains only one nuh_layer_id value that is equal to 0.
+    m_targetDecLayerIdSet.clear();
+    m_targetDecLayerIdSet.push_back( 0 );
+  }
+
+  // The variable HighestTid, which identifies the highest temporal sub-layer to be decoded, is specified as follows:
+  Bool externalMeansSetHighestTid = ( m_iMaxTemporalLayer != -1 );
+  if ( externalMeansSetHighestTid )
+  {
+    //- If some external means, not specified in this Specification, is available to set HighestTid,
+    //  HighestTid is set by the external means.
+    m_highestTid = m_iMaxTemporalLayer;
+  }
+  else
+  {
+    //-  Otherwise, HighestTid is set equal to sps_max_sub_layers_minus1.
+    m_highestTid = m_sps->getSpsMaxSubLayersMinus1();
+  }
+
+  //The variable SubPicHrdFlag is specified as follows:
+  //- If the decoding process is invoked in a bitstream conformance test as specified in clause C.1, SubPicHrdFlag is set as specified in clause C.1.
+  //- Otherwise, SubPicHrdFlag is set equal to ( SubPicHrdPreferredFlag  &&  sub_pic_hrd_params_present_flag ).
+
+  // The sub-bitstream extraction process as specified in clause 10 is applied with the CVSG, HighestTid and TargetDecLayerIdList as inputs, and the output is assigned to a bitstream referred to as BitstreamToDecode.
+}
+
+Void TAppDecTop::x813decProcForCodPicWithLIdZero( DecProcPart curPart )
+{
+  ////////////////////////////////////////////////////////////////////////////////
+  // 8.1.3 Decoding process for a coded picture with nuh_layer_id equal to 0.
+  ////////////////////////////////////////////////////////////////////////////////
+
+  if ( curPart == START_PIC )
+  {
+    Int nuhLayerId = m_curPic->getLayerId();
+
+    if ( ( m_curPic->isBla() && m_curPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP ) || m_curPic->isCra() )
+    {
+      // Not needed.
+      // When the current picture is a BLA picture that has nal_unit_type equal to BLA_W_LP or is a CRA picture, the following applies:
+      // -  If some external means not specified in this Specification is available to set the variable UseAltCpbParamsFlag to a value, UseAltCpbParamsFlag is set equal to the value provided by the external means.
+      // -  Otherwise, the value of UseAltCpbParamsFlag is set equal to 0.
+    }
+
+    if ( m_curPic->isIrap() )
+    {
+      // When the current picture is an IRAP picture, the following applies:
+      if ( m_curPic->isIdr() || m_curPic->isBla() || m_curPic->getDecodingOrder() == 0 || m_eosInLayer[ nuhLayerId ] )
+      {
+        // -  If the current picture is an IDR picture, a BLA picture, the first picture in the bitstream in decoding order,
+        //    or the first picture that follows an end of sequence NAL unit in decoding order, the variable NoRaslOutputFlag
+        //    is set equal to 1.
+
+        m_curPic->setNoRaslOutputFlag( true );
+      }
+      else if ( m_handleCraAsBlaFlagSetByExtMeans )
+      {
+        // -  Otherwise, if some external means not specified in this Specification is available to set the variable HandleCraAsBlaFlag
+        //    to a value for the current picture, the variable HandleCraAsBlaFlag is set equal to the value provided by
+        //    the external means and the variable NoRaslOutputFlag is set equal to HandleCraAsBlaFlag.
+
+        m_curPic->setNoRaslOutputFlag( m_handleCraAsBlaFlag );
+      }
+      else
+      {
+        // -  Otherwise, the variable HandleCraAsBlaFlag is set equal to 0 and the variable NoRaslOutputFlag is set equal to 0.
+        m_handleCraAsBlaFlag = false;
+        m_curPic->setNoRaslOutputFlag( false );
+      }
+    }
+
+    m_decProcPocAndRps = CLAUSE_8;
+  }
+  else if ( curPart == FINALIZE_PIC )
+  {
+    // -  PicOutputFlag is set as follows:
+    if (m_curPic->isRasl() && m_noRaslOutputFlagAssocIrap[ m_curPic->getLayerId() ] )
+    {
+      // -  If the current picture is a RASL picture and NoRaslOutputFlag of the associated IRAP picture is equal to 1,
+      //    PicOutputFlag is set equal to 0.
+      m_curPic->setPicOutputFlag( false );
+    }
+    else
+    {
+      // -  Otherwise, PicOutputFlag is set equal to pic_output_flag.
+      m_curPic->setPicOutputFlag( m_curPic->getSlice(0)->getPicOutputFlag() );
+    }
+
+    // 4.  After all slices of the current picture have been decoded, the decoded picture is marked as "used for short-term reference".
+    m_curPic->markAsUsedForShortTermReference();
+  }
+}
+
+// F.8.1.2
+Void TAppDecTop::xF812CvsgDecodingProcess( Int decIdx )
+{
+  ///////////////////////////////////////////////////////////////////////////////////////
+  //  F.8.1.2 CVSG decoding process
+ ///////////////////////////////////////////////////////////////////////////////////////
+
+  // The variable TargetOlsIdx, which specifies the index to the list of the OLSs
+  // specified by the VPS, of the target OLS, is specified as follows:
+
+
+  // If some external means, not specified in this Specification, is available to set
+  // TargetOlsIdx, TargetOlsIdx is set by the external means.
+
+  // For this decoder the TargetOlsIdx is always set by external means:
+  // When m_targetOptLayerSetIdx is equal to -1,  TargetOlsIdx is set to getVpsNumLayerSetsMinus1 (which has already been done in TDecTop, since needed there for parsing)
+  // Otherwise m_targetOptLayerSetIdx is used directly.
+
+  if ( m_targetOptLayerSetIdx == -1 )
+  {
+    m_targetOptLayerSetIdx = m_tDecTop[decIdx]->getTargetOlsIdx();
+  }
+  else
+  {
+    assert( m_tDecTop[decIdx]->getTargetOlsIdx() == m_targetOptLayerSetIdx );
+  }
+
+  m_targetDecLayerSetIdx = m_vps->olsIdxToLsIdx( m_targetOptLayerSetIdx );
+  m_targetDecLayerIdSet  = m_vps->getTargetDecLayerIdList( m_targetOptLayerSetIdx );
+
+
+  if ( m_targetOptLayerSetIdx < 0 || m_targetOptLayerSetIdx >= m_vps->getNumOutputLayerSets() )
+  {
+    fprintf(stderr, "\ntarget output layer set index must be in the range of 0 to %d, inclusive \n", m_vps->getNumOutputLayerSets() - 1 );
+    exit(EXIT_FAILURE);
+  }
+
+  if ( !m_vps->getVpsBaseLayerAvailableFlag() )
+  {
+    if(  m_targetDecLayerSetIdx < m_vps->getFirstAddLayerSetIdx() || m_targetDecLayerSetIdx > m_vps->getLastAddLayerSetIdx() )
+    {
+      // When vps_base_layer_available_flag is equal to 0, OlsIdxToLsIdx[ TargetOlsIdx ] shall be in the range of FirstAddLayerSetIdx to LastAddLayerSetIdx, inclusive.
+      fprintf(stderr, "\nvps_base_layer_available_flag is equal to 0, OlsIdxToLsIdx[ TargetOlsIdx ] shall be in the range of %d to %d, inclusive \n", m_vps->getFirstAddLayerSetIdx(), m_vps->getLastAddLayerSetIdx() );
+      exit(EXIT_FAILURE);
+    }
+  }
+
+  if ( !m_vps->getVpsBaseLayerInternalFlag() && m_targetOptLayerSetIdx <= 0 )
+  {
+    // When vps_base_layer_internal_flag is equal to 0, TargetOlsIdx shall be greater than 0.
+    fprintf(stderr, "\nvps_base_layer_internal_flag is equal to 0, TargetOlsIdx shall be greater than 0.\n" );
+    exit(EXIT_FAILURE);
+  }
+
+  // The variable HighestTid, which identifies the highest temporal sub-layer to be decoded,
+  // is specified as follows:
+
+  Bool externalMeansSetHighestTid = ( m_iMaxTemporalLayer != -1 );
+  if ( externalMeansSetHighestTid )
+  {
+    m_highestTid = m_iMaxTemporalLayer;
+  }
+  else
+  {
+    m_highestTid = m_sps->getSpsMaxSubLayersMinus1();
+  }
+
+  // The variable SubPicHrdPreferredFlag is either specified by external means, or when not specified by external means, set equal to 0.
+  // The variable SubPicHrdFlag is specified as follows:
+  // -  If the decoding process is invoked in a bitstream conformance test as specified in clause F.13.1, SubPicHrdFlag is set as specified in clause F.13.1.
+  // -  Otherwise, SubPicHrdFlag is set equal to ( SubPicHrdPreferredFlag  &&  sub_pic_hrd_params_present_flag ), where sub_pic_hrd_params_present_flag is found in any hrd_parameters( ) syntax structure that applies to at least one bitstream partition of the output layer set idenified by TargetOlsIdx.
+  // -  TBD in case that needed some when.
+
+  // A bitstream to be decoded, BitstreamToDecode, is specified as follows:
+  //   - Extraction is done in xExtractAndRewrite();
+
+  //   - SmallestLayerId is already derived in  TDecTop:: initFromActiveVps, since required for SH parsing.
+  m_smallestLayerId = m_tDecTop[decIdx]->getSmallestLayerId();
+
+  // When vps_base_layer_internal_flag is equal to 0, vps_base_layer_available_flag is equal to 1,
+  // and TargetDecLayerSetIdx is in the range of 0 to vps_num_layer_sets_minus1, inclusive,
+  // the following applies:
+  if ( !m_vps->getVpsBaseLayerInternalFlag() && m_vps->getVpsBaseLayerAvailableFlag() &&
+       ( m_targetDecLayerSetIdx >= 0 && m_targetDecLayerSetIdx <= m_vps->getVpsNumLayerSetsMinus1() ) )
+  {
+
+    // TBD: The size of the sub-DPB for the layer with nuh_layer_id equal to 0 is set equal to 1.
+
+    // TBD: The values of pic_width_in_luma_samples, pic_height_in_luma_samples, chroma_format_idc,
+    // separate_colour_plane_flag, bit_depth_luma_minus8, bit_depth_chroma_minus8, conf_win_left_offset,
+    // conf_win_right_offset, conf_win_top_offset, and conf_win_bottom_offset for decoded pictures
+    // with nuh_layer_id equal to 0 are set equal to the values of pic_width_vps_in_luma_samples,
+    // pic_height_vps_in_luma_samples, chroma_format_vps_idc, separate_colour_plane_vps_flag,
+    // bit_depth_vps_luma_minus8, bit_depth_vps_chroma_minus8, conf_win_vps_left_offset,
+    // conf_win_vps_right_offset, conf_win_vps_top_offset, and conf_win_vps_bottom_offset respectively,
+    // of the vps_rep_format_idx[ 0 ]-th rep_format( ) syntax structure in the active VPS.
+
+    // The variable BaseLayerOutputFlag is set equal to ( TargetOptLayerIdList[ 0 ]  = =  0 ).
+
+    m_baseLayerOutputFlag = ( m_vps->getTargetOptLayerIdList( m_targetOptLayerSetIdx )[ 0 ] == 0 );
+
+    // NOTE - The BaseLayerOutputFlag for each access unit is to be sent by an external means to
+    // the base layer decoder for controlling the output of base layer decoded pictures.
+    // BaseLayerOutputFlag equal to 1 indicates that the base layer is an output layer.
+    // BaseLayerOutputFlag equal to 0 indicates that the base layer is not an output layer.
+
+    // The variable LayerInitializedFlag[ i ] is set equal to 0 for all values of i from 0
+    // to vps_max_layer_id, inclusive, and the variable FirstPicInLayerDecodedFlag[ i ] is set
+    // equal to 0 for all values of i from 0 to vps_max_layer_id, inclusive.
+
+    for (Int i = 0; i <= m_vps->getVpsMaxLayerId(); i++ )
+    {
+      m_layerInitilizedFlag       [ i ] = false;
+      m_firstPicInLayerDecodedFlag[ i ] = false;
+    }
+  }
+}
+
+Void TAppDecTop::xC522OutputAndRemOfPicsFromDpb( )
+{
+  ////////////////////////////////////////////////////////////////////////////////
+  // C.5.2.2 Output and removal of pictures from the DPB
+  ////////////////////////////////////////////////////////////////////////////////
+
+//  The output and removal of pictures from the DPB before the decoding of the current picture
+//  (but after parsing the slice header of the first slice of the current picture) happens instantaneously
+//  when the first decoding unit of the access unit containing the current picture is removed from the CPB and proceeds as follows:
+//  - The decoding process for RPS as specified in clause 8.3.2 is invoked.
+
+  Int nuhLayerId = m_curPic->getLayerId();
+  const TComSPS* sps = m_curPic->getSlice(0)->getSPS();
+  assert( nuhLayerId == 0 );
+
+  if( ( m_curPic->isIrap() && m_curPic->getNoRaslOutputFlag() == 1) && m_curPic->getDecodingOrder() != 0 )
+  {
+    // - If the current picture is an IRAP picture with NoRaslOutputFlag equal to 1 that is not picture 0,
+    //   the following ordered steps are applied:
+
+    // 1.  The variable NoOutputOfPriorPicsFlag is derived for the decoder under test as follows:
+    Int noOutputOfPriorPicsFlag;
+    if( m_curPic->isCra() )
+    {
+      //-  If the current picture is a CRA picture, NoOutputOfPriorPicsFlag is set equal to 1
+      // (regardless of the value of no_output_of_prior_pics_flag).
+      noOutputOfPriorPicsFlag = true;
+    }
+    else if ( 0  )
+    {
+      // TBD
+      //- Otherwise, if the value of pic_width_in_luma_samples, pic_height_in_luma_samples, chroma_format_idc,
+      //  separate_colour_plane_flag, bit_depth_luma_minus8, bit_depth_chroma_minus8 or sps_max_dec_pic_buffering_minus1[ HighestTid ]
+      //  derived from the active SPS is different from the value of pic_width_in_luma_samples, pic_height_in_luma_samples,
+      //  chroma_format_idc, separate_colour_plane_flag, bit_depth_luma_minus8, bit_depth_chroma_minus8 or
+      //  sps_max_dec_pic_buffering_minus1[ HighestTid ], respectively, derived from the SPS active for the preceding picture,
+      //  NoOutputOfPriorPicsFlag may (but should not) be set to 1 by the decoder under test,
+      //  regardless of the value of no_output_of_prior_pics_flag.
+      //     NOTE - Although setting NoOutputOfPriorPicsFlag equal to no_output_of_prior_pics_flag is preferred under these conditions,
+      //            the decoder under test is allowed to set NoOutputOfPriorPicsFlag to 1 in this case.
+    }
+    else
+    {
+      noOutputOfPriorPicsFlag = m_curPic->getSlice(0)->getNoOutputPriorPicsFlag();
+    }
+    //  2.  The value of NoOutputOfPriorPicsFlag derived for the decoder under test is applied for the HRD as follows:
+    if (noOutputOfPriorPicsFlag)
+    {
+      //-  If NoOutputOfPriorPicsFlag is equal to 1, all picture storage buffers in the DPB are emptied
+      //   without output of the pictures they contain and the DPB fullness is set equal to 0.
+      m_dpb.emptySubDpb( nuhLayerId );
+    }
+    else if (!noOutputOfPriorPicsFlag)
+    {
+      //  -  Otherwise (NoOutputOfPriorPicsFlag is equal to 0), all picture storage buffers containing a picture that
+      //     is marked as "not needed for output" and "unused for reference" are emptied (without output) and all non-empty
+      //     picture storage buffers in the DPB are emptied by repeatedly invoking the "bumping" process specified in clause C.5.2.4
+      //     and the DPB fullness is set equal to 0.
+
+      m_dpb.emptySubDpbNotNeedForOutputAndUnusedForRef( nuhLayerId );
+      while( m_dpb.getSubDpb( nuhLayerId, false  )->size() != 0 )
+      {
+        xC524Bumping();
+      }
+    }
+  }
+  else if ( !( m_curPic->isIrap() && m_curPic->getNoRaslOutputFlag() == 0 ) )
+  {
+    //  -  Otherwise (the current picture is not an IRAP picture with NoRaslOutputFlag equal to 1),
+    //     all picture storage buffers containing a picture which are marked as "not needed for output" and "unused for reference"
+    //     are emptied (without output). For each picture storage buffer that is emptied, the DPB fullness is decremented by one.
+
+    m_dpb.emptySubDpbNotNeedForOutputAndUnusedForRef( nuhLayerId );
+
+    Bool repeat = true;
+
+    while( repeat )
+    {
+      TComSubDpb* dpb = m_dpb.getSubDpb( nuhLayerId, false );
+      TComList<TComPic*> picsMarkedForOutput = dpb->getPicsMarkedNeedForOutput();
+      // When one or more of the following conditions are true, the "bumping" process specified in clause C.5.2.4
+      // is invoked repeatedly while further decrementing the DPB fullness by one for each additional picture storage buffer that
+      // is emptied, until none of the following conditions are true:
+
+      // -  The number of pictures in the DPB that are marked as "needed for output" is greater
+      //    than sps_max_num_reorder_pics[ HighestTid ].
+      Bool cond1 = ( picsMarkedForOutput.size() > sps->getSpsMaxNumReorderPics( m_highestTid ) );
+
+      //  -  sps_max_latency_increase_plus1[ HighestTid ] is not equal to 0 and there is at least one picture in the DPB
+      //     that is marked as "needed for output" for which the associated variable PicLatencyCount is greater than or equal
+      //     to SpsMaxLatencyPictures[ HighestTid ].
+      Bool anyPicWithGtOrEqLatencyCnt = false;
+      for (TComList<TComPic*>::iterator itP = picsMarkedForOutput.begin(); itP != picsMarkedForOutput.end() && !anyPicWithGtOrEqLatencyCnt; itP++ )
+      {
+        anyPicWithGtOrEqLatencyCnt = anyPicWithGtOrEqLatencyCnt || ( (*itP)->getPicLatencyCount() >= sps->getSpsMaxLatencyPictures( m_highestTid ));
+      }
+      Bool cond2 = ( sps->getSpsMaxLatencyIncreasePlus1( m_highestTid ) != 0 ) && anyPicWithGtOrEqLatencyCnt;
+
+      //  -  The number of pictures in the DPB is greater than or equal to sps_max_dec_pic_buffering_minus1[ HighestTid ] + 1.
+      Bool cond3 = ( dpb->size() >= ( sps->getSpsMaxDecPicBufferingMinus1( m_highestTid ) + 1 ));
+
+      if ( cond1 || cond2 || cond3 )
+      {
+        xC524Bumping();
+      }
+      else
+      {
+        repeat = false;
+      }
+    }
+  }
+}
+
+Void TAppDecTop::xC523PicDecMarkAddBumpAndStor()
+{
+  ///////////////////////////////////////////////////////////////////////////////////////
+  // C.5.2.3 Picture decoding, marking, additional bumping and storage  
+  ///////////////////////////////////////////////////////////////////////////////////////
+  
+  Int nuhLayerId = m_curPic->getLayerId();
+  const TComSPS* sps = m_curPic->getSlice(0)->getSPS();
+  // The processes specified in this clause happen instantaneously when the last decoding unit of access unit n containing the
+  // current picture is removed from the CPB.
+  if (m_curPic->getPicOutputFlag() )
+  {
+    // When the current picture has PicOutputFlag equal to 1, for each picture in the DPB that is marked as "needed for output"
+    // and follows the current picture in output order, the associated variable PicLatencyCount is set equal to PicLatencyCount + 1.
+    TComSubDpb* dpb = m_dpb.getSubDpb( nuhLayerId, false);
+
+    for (TComSubDpb::iterator itP = dpb->begin(); itP != dpb->end(); itP++)
+    {
+      TComPic* pic = (*itP);
+      if ( pic->getOutputMark() && pic->getPOC() > m_curPic->getPOC() )
+      {
+        pic->setPicLatencyCount( pic->getPicLatencyCount() + 1 );
+      }
+    }
+  }
+
+  // The current picture is considered as decoded after the last decoding unit of the picture is decoded.
+  // The current decoded picture is stored in an empty picture storage buffer in the DPB and the following applies:
+  m_dpb.addNewPic( m_curPic );
+
+
+  if (m_curPic->getPicOutputFlag())
+  {
+    // - If the current decoded picture has PicOutputFlag equal to 1, it is marked as "needed for output" and its associated
+    //   variable PicLatencyCount is set equal to 0.
+    m_curPic->setOutputMark( true );
+    m_curPic->setPicLatencyCount( 0 );
+  }
+  else if (!m_curPic->getPicOutputFlag() )
+  {
+    // - Otherwise (the current decoded picture has PicOutputFlag equal to 0), it is marked as "not needed for output".
+    m_curPic->setOutputMark( false );
+  }
+
+  // The current decoded picture is marked as "used for short-term reference".
+  m_curPic->markAsUsedForShortTermReference();
+
+  Bool repeat = true;
+
+  while( repeat )
+  {
+    TComSubDpb* dpb = m_dpb.getSubDpb( nuhLayerId, false );
+    TComList<TComPic*> picsMarkedForOutput = dpb->getPicsMarkedNeedForOutput();
+
+    // When one or more of the following conditions are true, the "bumping" process specified in clause C.5.2.4
+    // is invoked repeatedly until none of the following conditions are true:
+
+    // - The number of pictures in the DPB that are marked as "needed for output" is greater than sps_max_num_reorder_pics[ HighestTid ].
+    Bool cond1 = ( picsMarkedForOutput.size() > sps->getSpsMaxNumReorderPics( m_highestTid ) );
+
+    // - sps_max_latency_increase_plus1[ HighestTid ] is not equal to 0 and there is at least one picture in the DPB that is marked
+    //   as "needed for output" for which the associated variable PicLatencyCount that is greater than or equal to
+    //   SpsMaxLatencyPictures[ HighestTid ].
+    Bool anyPicWithGtOrEqLatencyCnt = false;
+    for (TComList<TComPic*>::iterator itP = picsMarkedForOutput.begin(); itP != picsMarkedForOutput.end() && !anyPicWithGtOrEqLatencyCnt; itP++ )
+    {
+      anyPicWithGtOrEqLatencyCnt = anyPicWithGtOrEqLatencyCnt || ( (*itP)->getPicLatencyCount() >= sps->getSpsMaxLatencyPictures( m_highestTid ));
+    }
+    Bool cond2 = ( sps->getSpsMaxLatencyIncreasePlus1( m_highestTid ) != 0 ) && anyPicWithGtOrEqLatencyCnt;
+
+    if ( cond1 || cond2 )
+    {
+      xC524Bumping();
+    }
+    else
+    {
+      repeat = false;
+    }
+  }
+}
+
+Void TAppDecTop::xC524Bumping( )
+{
+  ////////////////////////////////////////////////////////////////////////////////
+  // C.5.2.4 "Bumping" process
+  ////////////////////////////////////////////////////////////////////////////////
+
+  // The "bumping" process consists of the following ordered steps:
+
+  // 1.  The picture that is first for output is selected as the one having the smallest value of PicOrderCntVal of all pictures
+  //     in the DPB marked as "needed for output".
+  TComPic* pic = *(m_dpb.getSubDpb( 0, false)->getPicsMarkedNeedForOutput().begin()); // pics are sorted, so take first
+
+  // 2.  The picture is cropped, using the conformance cropping window specified in the active SPS for the picture,
+  //     the cropped picture is output, and the picture is marked as "not needed for output".
+  xCropAndOutput( pic );
+  pic->setOutputMark( false );
+
+  //3.  When the picture storage buffer that included the picture that was cropped and output contains a picture marked
+  //    as "unused for reference", the picture storage buffer is emptied.
+  if (pic->getMarkedUnUsedForReference() )
+  {
+    m_dpb.removePic( pic );
+  }
+
+  // NOTE - For any two pictures picA and picB that belong to the same CVS and are output by the "bumping process", when picA
+  //        is output earlier than picB, the value of PicOrderCntVal of picA is less than the value of PicOrderCntVal of picB.
+}
+
+
+Void TAppDecTop::xF813ComDecProcForACodedPic( DecProcPart curPart, Bool picPosInAuIndication )
+{
+  ////////////////////////////////////////////////////////////////////////////////
+  // F.8.1.3  Common decoding process for a coded picture
+  ////////////////////////////////////////////////////////////////////////////////
+
+  // PicPosInAuIndication is interpreted based on curPart.
+  // - If curPart is equal to START_PIC               , it indicates whether the current pic is the first in the current AU.
+  // - Otherwise (if curPart is equal to FINALIZE_PIC), it indicates whether the current pic is the last  in the current AU.
+
+  if (curPart == START_PIC )
+  {
+    Bool curPicIsFirstInAu = picPosInAuIndication;
+
+    Int nuhLayerId = m_curPic->getLayerId();
+
+    if ( !m_vps->getVpsBaseLayerInternalFlag() && m_vps->getVpsBaseLayerAvailableFlag() &&
+      ( m_targetDecLayerSetIdx >= 0 && m_targetDecLayerSetIdx <= m_vps->getVpsNumLayerSetsMinus1() ) &&
+      m_curPic->getSlice(0)->getTemporalId() <= m_vps->getSubLayersVpsMaxMinus1( 0 ) && curPicIsFirstInAu )
+    {
+      // When vps_base_layer_internal_flag is equal to 0, vps_base_layer_available_flag is equal to 1,
+      // TargetDecLayerSetIdx is in the range of 0 to vps_num_layer_sets_minus1, inclusive,
+      // TemporalId is less than or equal to sub_layers_vps_max_minus1[ 0 ], and the current picture
+      // is the first coded picture of an access unit, clause F.8.1.8 is invoked prior to decoding the current picture.
+
+      assert( false ); //TBD
+    }
+
+    //  When the current picture is an IRAP picture, the variable HandleCraAsBlaFlag is derived as specified in the following:
+    if ( m_curPic->isIrap() )
+    {
+      if ( m_handleCraAsBlaFlagSetByExtMeans )
+      {
+        // If some external means not specified in this Specification is available to set the variable HandleCraAsBlaFlag to
+        // a value for the current picture, the variable HandleCraAsBlaFlag is set equal to the value provided by the external means.
+      }
+      else
+      {
+        // - Otherwise, the variable HandleCraAsBlaFlag is set equal to 0.
+        m_handleCraAsBlaFlag = false;
+      }
+    }
+
+    if ( m_curPic->isIrap() && nuhLayerId == m_smallestLayerId )
+    {
+      // When the current picture is an IRAP picture and has nuh_layer_id equal to SmallestLayerId, the following applies:
+      // The variable NoClrasOutputFlag is specified as follows:
+
+      if( m_firstSliceInBitstream )
+      {
+        //  - If the current picture is the first picture in the bitstream, NoClrasOutputFlag is set equal to 1.
+        m_curPic->setNoClrasOutputFlag(true );
+      }
+      else if( m_eosInLayer[ 0 ] || m_eosInLayer[ nuhLayerId ] )
+      {
+        //  - Otherwise, if the current picture is included in the first access unit that follows an access unit
+        //    including an end of sequence NAL unit with nuh_layer_id equal to SmallestLayerId or 0 in decoding order,
+        //    NoClrasOutputFlag is set equal to 1.
+
+        m_curPic->setNoClrasOutputFlag(true );
+      }
+      else if ( m_curPic->isBla() || (m_curPic->isCra() && m_handleCraAsBlaFlag ))
+      {
+        //  - Otherwise, if the current picture is a BLA picture or a CRA picture with HandleCraAsBlaFlag equal to 1,
+        //    NoClrasOutputFlag is set equal to 1.
+        m_curPic->setNoClrasOutputFlag(true );
+      }
+      else if ( m_curPic->isIdr() && m_curPic->getSlice(0)->getCrossLayerBlaFlag() )
+      {
+        //  - Otherwise, if the current picture is an IDR picture with cross_layer_bla_flag is equal to 1,
+        //    NoClrasOutputFlag is set equal to 1.
+        m_curPic->setNoClrasOutputFlag(true );
+      }
+      else if ( m_noClrasOutputFlagSetByExtMeans )
+      {
+        m_curPic->setNoClrasOutputFlag( m_noClrasOutputFlag );
+        //  - Otherwise, if some external means, not specified in this Specification, is available to set NoClrasOutputFlag,
+        //    NoClrasOutputFlag is set by the external means.
+      }
+      else
+      {
+        //  - Otherwise, NoClrasOutputFlag is set equal to 0.
+        m_curPic->setNoClrasOutputFlag(false );
+      }
+
+      //-  When NoClrasOutputFlag is equal to 1, the variable LayerInitializedFlag[ i ] is set equal to 0 for all values
+      //  of i from 0 to vps_max_layer_id, inclusive, and the variable FirstPicInLayerDecodedFlag[ i ] is set equal to 0
+      //  for all values of i from 0 to vps_max_layer_id, inclusive.
+      if ( m_curPic->getNoClrasOutputFlag( ) )
+      {
+        for (Int i = 0; i <= m_vps->getVpsMaxLayerId(); i++)
+        {
+          m_layerInitilizedFlag       [i] = false;
+          m_firstPicInLayerDecodedFlag[i] = false;
+        }
+      }
+    }
+
+    // The variables LayerResetFlag and dolLayerId are derived as follows:
+    Int dolLayerId = -1;
+    if ( m_curPic->isIrap() && nuhLayerId > m_smallestLayerId )
+    {
+      // - If the current picture is an IRAP picture and has nuh_layer_id nuhLayerId greater than SmallestLayerId,
+      //   the following applies:
+
+      if( m_eosInLayer[ nuhLayerId ] )
+      {
+        // -  If the current picture is the first picture, in decoding order, that follows an end of sequence NAL unit with
+        //    nuh_layer_id equal to nuhLayerId, LayerResetFlag is set equal to 1 and dolLayerId is set equal to the nuh_layer_id
+        //    value of the current NAL unit.
+
+        m_layerResetFlag = true;
+        dolLayerId = nuhLayerId;
+      }
+      else  if( ( m_curPic->isCra() && m_handleCraAsBlaFlag ) ||
+        (m_curPic->isIdr() && m_curPic->getSlice(0)->getCrossLayerBlaFlag() ) || m_curPic->isBla() )
+      {
+        // - Otherwise, if the current picture is a CRA picture with HandleCraAsBlaFlag equal to 1, an IDR picture with
+        //   cross_layer_bla_flag is equal to 1 or a BLA picture, LayerResetFlag is set equal to 1 and dolLayerId is set
+        //   equal to the nuh_layer_id value of the current NAL unit.
+        m_layerResetFlag = true;
+        dolLayerId = nuhLayerId;
+      }
+      else
+      {
+        // -   Otherwise, LayerResetFlag is set equal to 0.
+        m_layerResetFlag = false;
+      }
+
+      // NOTE 1 - An end of sequence NAL unit, a CRA picture with HandleCraAsBlaFlag equal to 1, an IDR picture with
+      // cross_layer_bla_flag equal to 1, or a BLA picture, each with nuh_layer_id nuhLayerId greater than SmallestLayerId,
+      // may be present to indicate a discontinuity of the layer with nuh_layer_id equal to nuhLayerId and its predicted layers.
+
+      if (m_layerResetFlag )
+      {
+        //When LayerResetFlag is equal to 1, the following applies:
+        //  - The values of LayerInitializedFlag and FirstPicInLayerDecodedFlag are updated as follows:
+
+        for( Int i = 0; i < m_vps->getNumPredictedLayers( dolLayerId ); i++ )
+        {
+          Int iLayerId = m_vps->getIdPredictedLayer(  dolLayerId , i );
+          m_layerInitilizedFlag       [ iLayerId ] = false;
+          m_firstPicInLayerDecodedFlag[ iLayerId ] = false;
+        }
+
+        //  - Each picture that is in the DPB and has nuh_layer_id equal to dolLayerId is marked as "unused for reference".
+        m_dpb.markSubDpbAsUnusedForReference( dolLayerId );
+
+        //  - When NumPredictedLayers[ dolLayerId ] is greater than 0, each picture that is in the DPB and has nuh_layer_id
+        //    equal to any value of IdPredictedLayer[ dolLayerId ][ i ] for the values of i in the range of 0 to
+        //    NumPredictedLayers[ dolLayerId ] - 1, inclusive, is marked as "unused for reference".
+
+        for( Int i = 0; i <= m_vps->getNumPredictedLayers( dolLayerId )- 1; i++  )
+        {
+          m_dpb.markSubDpbAsUnusedForReference( m_vps->getIdPredictedLayer( dolLayerId, i ) );
+        }
+      }
+    }
+    else
+    {
+      // - Otherwise, LayerResetFlag is set equal to 0.
+      m_layerResetFlag = false;
+    }
+
+    if ( m_curPic->isIrap() )
+    {
+      // When the current picture is an IRAP picture, the following applies:
+
+      if ( m_curPic->isIdr() || m_curPic->isBla() || m_curPic->getDecodingOrder() == 0 || m_eosInLayer[nuhLayerId] )
+      {
+        // - If the current picture with a particular value of nuh_layer_id is an IDR picture, a BLA picture, the first picture
+        //   with that particular value of nuh_layer_id in the bitstream in decoding order or the first picture with that
+        //   particular value of nuh_layer_id that follows an end of sequence NAL unit with that particular value of nuh_layer_id
+        //   in decoding order, the variable NoRaslOutputFlag is set equal to 1.
+
+        m_curPic->setNoRaslOutputFlag(  true );
+      }
+      else if ( m_layerInitilizedFlag[ nuhLayerId ] == 0 && xAllRefLayersInitilized( nuhLayerId ) )
+      {
+        // Otherwise, if LayerInitializedFlag[ nuh_layer_id ] is equal to 0 and LayerInitializedFlag[ refLayerId ] is equal to 1
+        // for all values of refLayerId equal to IdDirectRefLayer[ nuh_layer_id ][ j ], where j is in the range of 0 to
+        // NumDirectRefLayers[ nuh_layer_id ] - 1, inclusive, the variable NoRaslOutputFlag is set equal to 1.
+
+        m_curPic->setNoRaslOutputFlag(  true );
+      }
+      else
+      {
+        // - Otherwise, the variable NoRaslOutputFlag is set equal to HandleCraAsBlaFlag.
+        m_curPic->setNoRaslOutputFlag(  m_handleCraAsBlaFlag );
+      }
+    }
+
+    // The following applies for the decoding of the current picture:
+    if ( m_curPic->isIrap() && m_curPic->getNoRaslOutputFlag() && (
+      ( nuhLayerId == 0 ) ||
+      ( m_layerInitilizedFlag[ nuhLayerId ] == 0   && m_vps->getNumDirectRefLayers( nuhLayerId ) == 0  ) ||
+      ( m_layerInitilizedFlag[ nuhLayerId ] == 0 && xAllRefLayersInitilized( nuhLayerId ) )
+      ) )
+    {
+      // When the current picture is an IRAP picture with NoRaslOutputFlag equal to 1 and one of the following conditions is true,
+      // LayerInitializedFlag[ nuh_layer_id ] is set equal to 1:
+      // - nuh_layer_id is equal to 0.
+      // - LayerInitializedFlag[ nuh_layer_id ] is equal to 0 and NumDirectRefLayers[ nuh_layer_id ] is equal to 0.
+      // - LayerInitializedFlag[ nuh_layer_id ] is equal to 0 and LayerInitializedFlag[ refLayerId ] is equal to 1 for all values of
+      //   refLayerId equal to IdDirectRefLayer[ nuh_layer_id ][ j ], where j is in the range of 0 to NumDirectRefLayers[ nuh_layer_id ] - 1, inclusive.
+
+      m_layerInitilizedFlag[ nuhLayerId ] = true;
+    }
+
+    // The following applies for the decoding of the current picture:
+
+    if ( nuhLayerId == 0 )
+    {
+      //  If the current picture has nuh_layer_id equal to 0, the decoding process for the current picture takes as inputs the syntax elements
+      //  and upper-case variables from clause F.7 and the decoding process for a coded picture with nuh_layer_id equal to 0 as specified in clause F.8.1.4
+      //  is invoked.
+
+      xF814decProcForCodPicWithLIdZero( curPart );
+    }
+    else
+    {
+      Bool decodedPicWithLayerIdZeroProvided = false;
+      if ( !m_vps->getVpsBaseLayerInternalFlag() && m_vps->getVpsBaseLayerAvailableFlag() &&
+        ( m_targetDecLayerSetIdx >= 0 && m_targetDecLayerSetIdx <= m_vps->getVpsNumLayerSetsMinus1() ) &&
+        m_curPic->getSlice(0)->getTemporalId() <= m_vps->getSubLayersVpsMaxMinus1( 0 ) && curPicIsFirstInAu
+        && decodedPicWithLayerIdZeroProvided )
+      {
+        assert( false ); //TBD
+        //TBD: Hybrid scalability
+        //  When vps_base_layer_internal_flag is equal to 0, vps_base_layer_available_flag is equal to 1,
+        //  TargetDecLayerSetIdx is in the range of 0 to vps_num_layer_sets_minus1, inclusive,
+        //  TemporalId is less than or equal to sub_layers_vps_max_minus1[ 0 ], the current picture
+        //  is the first coded picture of an access unit, and a decoded picture with nuh_layer_id equal
+        //  to 0 is provided by external means for the current access unit, clause F.8.1.9 is invoked
+        //  after the decoding of the slice segment header of the first slice segment, in decoding order,
+        //  of the current picture, but prior to decoding any slice segment of the first
+        //  coded picture of the access unit.
+      }
+
+      m_decProcPocAndRps = ANNEX_F;
+      // For the decoding of the slice segment header of the first slice segment, in decoding order, of the current picture,
+      // the decoding process for starting the decoding of a coded picture with nuh_layer_id greater than 0 specified in
+      // clause F.8.1.5 is invoked.  --> This is done in the loop when receiving slices.
+
+      // The decoding process is already selected before.
+    }
+  }
+  else if( curPart == FINALIZE_PIC )
+  {
+    Bool curPicIsLastInAu = picPosInAuIndication;
+
+    if (m_curPic->getLayerId() == 0 )
+    {
+      xF814decProcForCodPicWithLIdZero( curPart );
+    }
+    else
+    {
+      // - After all slices of the current picture have been decoded, the decoding process for ending the decoding of a
+      //   coded picture with nuh_layer_id greater than 0 specified in clause F.8.1.6 is invoked.
+      xF816decProcEndDecOfCodPicLIdGrtZero( );
+    }
+
+    TComSlice* slice = m_curPic->getSlice(0);
+    const TComVPS* vps = slice->getVPS();
+
+    if ( curPicIsLastInAu )
+    {
+      //When the current picture is the last coded picture in an access unit in BitstreamToDecode, the following steps apply after
+      // the decoding of the current picture, prior to the decoding of the next picture:
+
+      //-  PicOutputFlag is updated as follows:
+      TComPic* picAtOutputLayer = NULL;
+      Int outputLayerId = -1;
+
+      // Try to find pic at output layer.
+      if( vps->getAltOutputLayerFlag( m_targetOptLayerSetIdx ) )
+      {
+        // When alt_output_layer_flag is equal to 1, the target output layer set can only contain one output layer.
+        assert( vps->getNumOutputLayersInOutputLayerSet( m_targetOptLayerSetIdx ) == 1 );
+        outputLayerId = vps->getTargetOptLayerIdList(m_targetOptLayerSetIdx)[0];
+        picAtOutputLayer = m_curAu.getPic( outputLayerId );
+      }
+
+      if ( vps->getAltOutputLayerFlag( m_targetOptLayerSetIdx ) &&
+        ( picAtOutputLayer == NULL || (picAtOutputLayer != NULL && !picAtOutputLayer->getPicOutputFlag() ) ) )
+      {
+        // If alt_output_layer_flag[ TargetOlsIdx ] is equal to 1 and the current access unit either does
+        // not contain a picture at the output layer or contains a picture at the output layer that has PicOutputFlag equal to 0:
+
+        // - The list nonOutputLayerPictures is set to be the list of the pictures of the access unit with PicOutputFlag equal to 1 and
+        //   with nuh_layer_id values among the nuh_layer_id values of the reference layers of the output layer.
+        TComList<TComPic*> nonOutputLayerPictures;
+        for( TComList<TComPic*>::iterator itP= m_curAu.begin();  itP != m_curAu.end() ; itP++ )
+        {
+          TComPic* pic = (*itP);
+          Bool isRefernceLayerOfOutputLayer = false;
+          for ( Int i = 0; i < vps->getNumRefLayers( outputLayerId ) && !isRefernceLayerOfOutputLayer; i++ )
+          {
+            if ( pic->getLayerId() == vps->getIdRefLayer(outputLayerId, i) )
+            {
+              isRefernceLayerOfOutputLayer = true;
+            }
+          }
+
+          if ( pic->getPicOutputFlag() && isRefernceLayerOfOutputLayer )
+          {
+            nonOutputLayerPictures.pushBack( pic );
+          }
+        }
+
+        if (nonOutputLayerPictures.size() != 0 )
+        {
+          // -  When the list nonOutputLayerPictures is not empty,
+          //    The picture with the highest nuh_layer_id value among the list nonOutputLayerPictures is removed from the list nonOutputLayerPictures.
+          //    As in AU the picture with the highest layer id is the last
+          nonOutputLayerPictures.pop_back();
+        }
+
+        //  -  PicOutputFlag for each picture that is included in the list nonOutputLayerPictures is set equal to 0.
+        for( TComList<TComPic*>::iterator itP= nonOutputLayerPictures.begin();  itP != nonOutputLayerPictures.end() ; itP++ )
+        {
+          (*itP)->setPicOutputFlag( false );
+        }
+      }
+      else
+      {
+        //Otherwise, PicOutputFlag for pictures that are not included in an output layer is set equal to 0.
+        for( TComList<TComPic*>::iterator itP= m_curAu.begin();  itP != m_curAu.end() ; itP++ )
+        {
+          TComPic* pic = (*itP);
+
+          Bool includedInOutputLayer = false;
+          for (Int i = 0 ; i < vps->getNumOutputLayersInOutputLayerSet( m_targetOptLayerSetIdx ) && !includedInOutputLayer; i++)
+          {
+            includedInOutputLayer = ( pic->getLayerId() ==  vps->getTargetOptLayerIdList(m_targetOptLayerSetIdx)[i]);
+          }
+
+          if ( !includedInOutputLayer )
+          {
+            pic->setPicOutputFlag( false );
+          }
+        }
+      }
+
+      // When vps_base_layer_internal_flag is equal to 0, vps_base_layer_available_flag is equal to 1 and
+      // TargetDecLayerSetIdx is in the range of 0 to vps_num_layer_sets_minus1, inclusive
+
+      if( !vps->getVpsBaseLayerInternalFlag() && vps->getVpsBaseLayerAvailableFlag() && ( m_targetDecLayerSetIdx >= 0 && m_targetDecLayerSetIdx <= vps->getVpsNumLayerSetsMinus1()   ) )
+      {
+        if( !m_baseLayerOutputFlag )
+        {
+          // Check if base layer is a reference layer of the output layer
+          // and if the access unit does not contain a picture at any other reference layer of the output layer
+          Bool baseLayerIsRefOfOutputLayer = false;
+          Bool auDoesNotContainPicAtAnyOtherRefLayerOfOptLayer = true;
+          if ( vps->getAltOutputLayerFlag( m_targetOptLayerSetIdx ))
+          {
+            assert( outputLayerId >= 0 );
+
+            for (Int i = 0; i < vps->getNumRefLayers( outputLayerId ); i++ )
+            {
+              Int refLayerId = vps->getIdRefLayer(outputLayerId, i);
+              if( refLayerId == 0 )
+              {
+                baseLayerIsRefOfOutputLayer = true;
+              }
+              else
+              {
+                if ( m_curAu.getPic( refLayerId ) != NULL )
+                {
+                  auDoesNotContainPicAtAnyOtherRefLayerOfOptLayer = false;
+                }
+              }
+            }
+          }
+
+          // If alt_output_layer_flag[ TargetOlsIdx ] is equal to 1, the base layer is a reference layer of the output layer,
+          // the access unit does not contain a picture at the output layer or contains a picture at the output layer that has
+          // PicOutputFlag equal to 0, and the access unit does not contain a picture at any other reference layer of the output layer,
+          // BaseLayerPicOutputFlag is set equal to 1
+
+          if ( vps->getAltOutputLayerFlag( m_targetOptLayerSetIdx ) && baseLayerIsRefOfOutputLayer
+            && ( ( picAtOutputLayer == NULL ) || ( picAtOutputLayer != NULL && !picAtOutputLayer->getPicOutputFlag()  ) )
+            &&  auDoesNotContainPicAtAnyOtherRefLayerOfOptLayer )
+          {
+            m_baseLayerPicOutputFlag = true;
+          }
+          else
+          {
+            m_baseLayerPicOutputFlag = false;
+          }
+        }
+        else
+        {
+          m_baseLayerPicOutputFlag = true;
+        }
+
+        // NOTE 3 - The BaseLayerPicOutputFlag for each access unit is to be sent by an external means
+        // to the base layer decoder for controlling the output of base layer decoded pictures.
+        // BaseLayerPicOutputFlag equal to 1 for an access unit specifies that the base layer picture of the access unit is to be output.
+        // BaseLayerPicOutputFlag equal to 0 for an access unit specifies that the base layer picture of the access unit is not to be output.
+
+        //  The sub-DPB for the layer with nuh_layer_id equal to 0 is set to be empty.
+        m_dpb.emptySubDpb( 0 );
+      }
+
+      // The variable AuOutputFlag that is associated with the current access unit is derived as follows:
+
+      // Derive if at least one picture in the current access unit has PicOutputFlag equal to 1
+      Bool atLeastOnePicInAuWithPicOptFlagOne = false;
+      for( TComList<TComPic*>::iterator itP= m_curAu.begin();  itP != m_curAu.end() ; itP++ )
+      {
+        if ( (*itP)->getPicOutputFlag() )
+        {
+          atLeastOnePicInAuWithPicOptFlagOne = true;
+        }
+      }
+
+      //If at least one picture in the current access unit has PicOutputFlag equal to 1
+      if ( atLeastOnePicInAuWithPicOptFlagOne )
+      {
+        m_auOutputFlag = true;
+      }
+      else
+      {
+        m_auOutputFlag = false;
+      }
+
+      // The variable PicLatencyCount that is associated with the current access unit is set equal to 0.
+      m_curAu.setPicLatencyCount( 0 );
+
+      if ( m_auOutputFlag )
+      {
+        // for each access unit in the DPB
+        // that has at least one picture marked as "needed for output" and
+        // follows the current access unit in output order, the associated
+        // variable PicLatencyCount is set equal to PicLatencyCount + 1.
+
+        TComList<TComAu*> aus = m_dpb.getAusHavingPicsMarkedForOutput(); // <-- current AU is actually not yet in DPB, but this does not matter here.
+
+        for(TComList<TComAu*>::iterator itA= aus.begin(); ( itA!=aus.end()); itA++)
+        {
+          if( m_curAu.getPoc() < (*itA)->getPoc())
+          {
+            (*itA)->setPicLatencyCount( (*itA)->getPicLatencyCount() + 1 );
+          }
+        }
+      }
+    }
+  }
+}
+
+Void TAppDecTop::xF814decProcForCodPicWithLIdZero( DecProcPart curPart )
+{
+  ////////////////////////////////////////////////////////////////////////////////
+  // F.8.1.4 Decoding process for a coded picture with nuh_layer_id equal to 0
+  ////////////////////////////////////////////////////////////////////////////////
+
+  x813decProcForCodPicWithLIdZero( curPart );
+
+  if (curPart == START_PIC )
+  {
+    m_decProcPocAndRps = ANNEX_F;
+  }
+  else if (curPart == FINALIZE_PIC )
+  {
+    if ( !m_firstPicInLayerDecodedFlag[0] )
+    {
+      m_firstPicInLayerDecodedFlag[0] = true;
+    }
+  }
+}
+
+Void TAppDecTop::xF13521InitDpb()
+{
+  ////////////////////////////////////////////////////////////////////////////////
+  // F.13.5.2.1 General
+  ////////////////////////////////////////////////////////////////////////////////
+
+  const TComDpbSize* dpbSize = m_vps->getDpbSize();
+  m_maxNumReorderPics       = dpbSize->getMaxVpsNumReorderPics      ( m_targetOptLayerSetIdx, m_highestTid );
+  m_maxLatencyIncreasePlus1 = dpbSize->getMaxVpsLatencyIncreasePlus1( m_targetOptLayerSetIdx, m_highestTid );
+  m_maxLatencyValue         = dpbSize->getVpsMaxLatencyPictures     ( m_targetOptLayerSetIdx, m_highestTid );
+
+  for(Int i = 0; i < MAX_NUM_LAYER_IDS; i++)
+  {
+    m_maxDecPicBufferingMinus1[ i ] = MIN_INT;
+  }
+  for( Int i = 0; i <= m_vps->getMaxLayersMinus1(); i++ )
+  {
+    Int currLayerId = m_vps->getLayerIdInNuh( i );
+    for(Int layerIdx = 0 ; layerIdx < m_vps->getNumLayersInIdList( m_targetDecLayerSetIdx); layerIdx++ )
+    {
+      if( m_vps->getLayerSetLayerIdList( m_targetDecLayerSetIdx, layerIdx ) == currLayerId )
+      {
+        m_maxDecPicBufferingMinus1[currLayerId] = dpbSize->getMaxVpsDecPicBufferingMinus1( m_targetDecLayerSetIdx, layerIdx, m_highestTid );
+      }
+    }
+  }
+}
+
+Void TAppDecTop::xF13522OutputAndRemOfPicsFromDpb( Bool beforePocDerivation )
+{
+  ////////////////////////////////////////////////////////////////////////////////
+  // F.13.5.2.2 Output and removal of pictures from the DPB
+  ////////////////////////////////////////////////////////////////////////////////
+
+  if( beforePocDerivation )
+  {
+    // F.13.5.2.2
+    // Part before POC and RPS derivation.
+
+    if( m_curPic->getDecodingOrder() != 0 )
+    {
+      // When the current picture is not picture 0 in the current layer,
+      // the output and removal of pictures in the current layer, with nuh_layer_id equal to currLayerId,
+      // from the DPB before the decoding of the current picture, i.e., picture n, but after parsing the
+      // slice header of the first slice of the current picture and before the invocation of the decoding
+      // process for picture order count, happens instantaneously when the first decoding unit of the current
+      // picture is removed from the CPB and proceeds as follows:
+
+      if( m_curPic->getIsPocResettingPic() )
+      {
+        // When the current picture is a POC resetting picture, all pictures in the DPB that do
+        // not belong to the current access unit and that are marked as "needed for output" are
+        // output, starting with pictures with the smallest value of PicOrderCntVal of all pictures
+        // excluding those in the current access unit in the DPB, in ascending order of the PicOrderCntVal
+        // values, and pictures with the same value of PicOrderCntVal are output in ascending order
+        // of the nuh_layer_id values. When a picture is output, it is cropped using the conformance cropping
+        // window specified in the active SPS for the picture, the cropped picture is output, and
+        // the picture is marked as "not needed for output"
+
+        TComList<TComAu*>* aus = m_dpb.getAus(); // Theses are sorted by POC.
+        for (TComList<TComAu*>::iterator itA = aus->begin(); itA != aus->end(); itA++ )
+        {
+          //Pictures in AUs are sorted by nuh_layer_id;
+          for (TComAu::iterator itP = (*itA)->begin(); itP != (*itA)->end(); itP++ )
+          {
+            TComPic* pic = (*itP);
+            if ( !m_curAu.containsPic( pic ) )
+            {
+              xCropAndOutput( pic );
+              pic->setOutputMark( false );
+            }
+          }
+        }
+      }
+    }
+  }
+  else if ( !beforePocDerivation )
+  {
+    //  The variable listOfSubDpbsToEmpty is derived as follows:
+
+    Int nuhLayerId = m_curPic->getLayerId();
+    TComList<TComSubDpb*> listOfSubDpbsToEmpty;
+
+    if ( m_newVpsActivatedbyCurAu && ( m_curPic->isIrap()&& nuhLayerId == m_smallestLayerId
+      && m_curPic->getNoRaslOutputFlag() && m_curPic->getNoClrasOutputFlag() ) )
+    {
+      // If a new VPS is activated by the current access unit or the current picture is IRAP picture
+      // with nuh_layer_id equal to SmallestLayerId,   NoRaslOutputFlag equal to 1, and NoClrasOutputFlag equal to 1,
+      // listOfSubDpbsToEmpty is set equal to all the sub-DPBs.
+      listOfSubDpbsToEmpty = (*m_dpb.getSubDpbs());
+    }
+    else if (m_curPic->isIrap() && m_vps->getNumDirectRefLayers( nuhLayerId ) == 0 &&
+      nuhLayerId > m_smallestLayerId && m_curPic->getNoRaslOutputFlag() && m_layerResetFlag  )
+    {
+      // Otherwise, if the current picture is an IRAP picture with any nuh_layer_id value indepLayerId
+      // such that NumDirectRefLayers[ indepLayerId ] is equal to 0 and indepLayerId is greater than
+      // SmallestLayerId, and with NoRaslOutputFlag equal to 1, and LayerResetFlag is equal to 1,
+
+      // listOfSubDpbsToEmpty is set equal to the sub-DPBs containing the current layer and the sub-DPBs
+      // containing the predicted layers of the current layer.
+
+      listOfSubDpbsToEmpty.pushBack( m_dpb.getSubDpb( nuhLayerId, false  ) );
+      for( Int i = 0; i < m_vps->getNumPredictedLayers( nuhLayerId ); i++  )
+      {
+        listOfSubDpbsToEmpty.pushBack( m_dpb.getSubDpb( m_vps->getIdPredictedLayer( nuhLayerId, i), false  ) );
+      }
+    }
+    else
+    {
+      // Otherwise, crossLayerBufferEmptyFlag is set equal to 0.
+
+      // The SPEC seems to have an issue here. Use current subDpb as in form F.13.3.2
+      listOfSubDpbsToEmpty.pushBack( m_dpb.getSubDpb( nuhLayerId, false  ) );
+    }
+
+    // If the current picture is an IRAP picture with NoRaslOutputFlag equal to 1 and any of
+    // the following conditions is true:
+    //   - nuh_layer_id equal to SmallestLayerId,
+    //   - nuh_layer_id of the current layer is greater than SmallestLayerId, and NumDirectRefLayers[ nuh_layer_id ]
+    //     is equal to 0,
+
+    if ( m_curPic->isIrap() && m_curPic->getNoRaslOutputFlag() && (
+      ( nuhLayerId == m_smallestLayerId ) ||
+      ( ( nuhLayerId > m_smallestLayerId ) && m_vps->getNumDirectRefLayers( nuhLayerId ) == 0 ) )
+      )
+    {
+      // 1. The variable NoOutputOfPriorPicsFlag is derived for the decoder under test as follows:
+      Bool noOutputOfPriorPicsFlag;
+      if( m_curPic->isCra() )
+      {
+        noOutputOfPriorPicsFlag = true;
+        // - If the current picture is a CRA picture, NoOutputOfPriorPicsFlag is set equal to 1
+        // (regardless of the value of no_output_of_prior_pics_flag).
+      }
+      else if ( false )
+      {
+        // TBD
+        // - Otherwise, if the value of pic_width_in_luma_samples, pic_height_in_luma_samples,
+        //   chroma_format_idc, bit_depth_luma_minus8, bit_depth_chroma_minus8, separate_colour_plane_flag,
+        //   or sps_max_dec_pic_buffering_minus1[ HighestTid ] derived from the active SPS for the current
+        //   layer is different from the value of pic_width_in_luma_samples, pic_height_in_luma_samples,
+        //   chroma_format_idc, bit_depth_luma_minus8, bit_depth_chroma_minus8, separate_colour_plane_flag,
+        //   or sps_max_dec_pic_buffering_minus1[ HighestTid ], respectively, derived from the SPS that
+        //   was active for the current layer when decoding the preceding picture in the current layer,
+        //   NoOutputOfPriorPicsFlag may (but should not) be set equal to 1 by the decoder under test,
+        //   regardless of the value of no_output_of_prior_pics_flag.
+        //    NOTE - Although setting NoOutputOfPriorPicsFlag equal to no_output_of_prior_pics_flag is preferred
+        //    under these conditions, the decoder under test is allowed to set NoOutputOfPriorPicsFlag to 1 in this case.
+        // - Otherwise, NoOutputOfPriorPicsFlag is set equal to no_output_of_prior_pics_flag.
+
+        // assert( 1 );
+      }
+      else
+      {
+        // - Otherwise, NoOutputOfPriorPicsFlag is set equal to no_output_of_prior_pics_flag.
+        noOutputOfPriorPicsFlag = m_curPic->getSlice(0)->getNoOutputPriorPicsFlag();
+      }
+
+      // 2. The value of NoOutputOfPriorPicsFlag derived for the decoder under test is applied for the HRD as follows:
+      if ( !noOutputOfPriorPicsFlag )
+      {
+        // - If NoOutputOfPriorPicsFlag is equal to 0, all non-empty picture storage buffers in all the sub-DPBs included
+        //   in listOfSubDpbsToEmpty are output by repeatedly invoking the "bumping" process specified in clause
+        //   F.13.5.2.4 until all these pictures are marked as "not needed for output".
+
+        Bool repeat = true;
+        while (repeat )
+        {
+          Bool allPicsMarkedNotNeedForOutput = true;
+          for (TComList<TComSubDpb*>::iterator itS = listOfSubDpbsToEmpty.begin(); itS != listOfSubDpbsToEmpty.end() && allPicsMarkedNotNeedForOutput; itS++ )
+          {
+            allPicsMarkedNotNeedForOutput = allPicsMarkedNotNeedForOutput && ( (*itS)->areAllPicsMarkedNotNeedForOutput() );
+          }
+
+          if ( !allPicsMarkedNotNeedForOutput )
+          {
+            xF13524Bumping( m_dpb.getAusHavingPicsMarkedForOutput() );
+          }
+          else
+          {
+            repeat = false;
+          }
+        }
+      }
+      else
+      {
+        // - Otherwise (NoOutputOfPriorPicsFlag is equal to 1), all picture storage buffers containing a picture
+        //   that is marked as "not needed for output" and "unused for reference" are emptied (without output),
+        //   all pictures that are contained in a sub-DPB included in listOfSubDpbsToEmpty are emptied, and the sub-DPB
+        //   fullness of each sub-DPB is decremented by the number of picture storage buffers emptied in that sub-DPB.
+        m_dpb.emptyNotNeedForOutputAndUnusedForRef();
+
+        for( TComList<TComSubDpb*>::iterator iS = listOfSubDpbsToEmpty.begin(); iS != listOfSubDpbsToEmpty.end(); iS++)
+        {
+          m_dpb.emptySubDpbs( &listOfSubDpbsToEmpty );
+        }
+      }
+    }
+    else
+    {
+      // -  Otherwise, all picture storage buffers that contain a picture in the current layer and that are marked as
+      //   "not needed for output" and "unused for reference" are emptied (without output). For each picture storage buffer that is emptied,
+      //   the sub-DPB fullness is decremented by one.
+
+      m_dpb.emptySubDpbNotNeedForOutputAndUnusedForRef( nuhLayerId );
+
+      //    When one or more of the following conditions are true, the "bumping" process specified in clause F.13.5.2.4
+      //    is invoked repeatedly until none of the following conditions are true:
+
+      Bool repeat = true;
+      while ( repeat )
+      {
+        TComList<TComAu*> aus = m_dpb.getAusHavingPicsMarkedForOutput();
+
+        // The number of access units that contain at least one decoded picture in the DPB marked
+        // as "needed for output" is greater than MaxNumReorderPics.
+        Bool cond1 = ( aus.size() > m_maxNumReorderPics );
+
+        // MaxLatencyIncreasePlus1 is not equal to 0 and there is at least one access unit
+        // that contains at least one decoded picture in the DPB marked as "needed for output"
+        // for which the associated variable PicLatencyCount is greater than or equal to MaxLatencyValue.
+        Bool auWithGreaterLatencyCount = false;
+        for(TComList<TComAu*>::iterator itA= aus.begin(); ( itA!=aus.end()) && !auWithGreaterLatencyCount ; itA++)
+        {
+          if ( (*itA)->getPicLatencyCount() > m_maxLatencyValue )
+          {
+            auWithGreaterLatencyCount = true;
+          }
+        }
+
+        Bool cond2 = (m_maxLatencyIncreasePlus1 != 0 ) && auWithGreaterLatencyCount;
+
+        // The number of pictures in the sub-DPB is greater than or equal to MaxDecPicBufferingMinus1 + 1.
+        Bool cond3 = ( m_dpb.getSubDpb( nuhLayerId, false )->size() >= m_maxDecPicBufferingMinus1[ nuhLayerId ] + 1 );
+
+        if ( cond1  || cond2 || cond3 )
+        {
+          xF13524Bumping( aus );
+        }
+        else
+        {
+          repeat = false;
+        }
+      }
+    }
+  }
+}
+
+Void TAppDecTop::xF13523PicDecMarkAddBumpAndStor( Bool curPicIsLastInAu )
+{
+  ////////////////////////////////////////////////////////////////////////////////
+  // F.13.5.2.3 Picture decoding, marking, additional bumping and storage
+  ////////////////////////////////////////////////////////////////////////////////
+
+  const TComVPS* vps = m_curPic->getSlice(0)->getVPS();
+
+  // The current picture is considered as decoded after the last decoding unit of
+  // the picture is decoded. The current decoded picture is stored in an empty picture
+  // storage buffer in the sub-DPB.
+
+  m_dpb.addNewPic( m_curPic );
+
+  if ( curPicIsLastInAu )
+  {
+    // When the current picture is the last picture in an access unit, the following applies
+    // for each decoded picture with nuh_layer_id greater than or
+    // equal to ( vps_base_layer_internal_flag ? 0 : 1 ) of the access unit:
+
+    for( TComList<TComPic*>::iterator itP = m_curAu.begin(); itP != m_curAu.end(); itP++ )
+    {
+      TComPic* pic = (*itP);
+      if( pic->getLayerId() >= ( vps->getVpsBaseLayerInternalFlag() ? 0 : 1 ) )
+      {
+        if ( pic->getPicOutputFlag() )
+        {
+          //If the decoded picture has PicOutputFlag equal to 1, it is marked as "needed for output".
+          pic->setOutputMark( true );
+        }
+        else
+        {
+          // Otherwise it is marked as "not needed for output".
+          pic->setOutputMark( false );
+        }
+        // NOTE - Prior to investigating the conditions above, PicOutputFlag
+        // of each picture of the access unit is updated as specified in clause F.8.1.2.
+      }
+    }
+  }
+
+  // The current decoded picture is marked as "used for short-term reference".
+  m_curPic->markAsUsedForShortTermReference();
+
+
+  Bool repeat = true;
+  while ( repeat )
+  {
+    TComList<TComAu*> aus = m_dpb.getAusHavingPicsMarkedForOutput();
+
+    // When one or more of the following conditions are true,
+    // the "bumping" process specified in clause F.13.5.2.4 is invoked
+    // repeatedly until none of the following conditions are true:
+
+    // - The number of access units that contain at least one decoded picture in the DPB marked
+    //   as "needed for output" is greater than MaxNumReorderPics.
+    Bool cond1 = ( aus.size() > m_maxNumReorderPics );
+
+    // - MaxLatencyIncreasePlus1 is not equal to 0 and there is at least one access unit
+    //   that contains at least one decoded picture in the DPB marked as "needed for output"
+    //   for which the associated variable PicLatencyCount is greater than or equal to MaxLatencyValue.
+    Bool auWithGreaterLatencyCount = false;
+    for(TComList<TComAu*>::iterator itA= aus.begin(); ( itA!=aus.end()) && !auWithGreaterLatencyCount ; itA++)
+    {
+      if ( (*itA)->getPicLatencyCount() > m_maxLatencyValue )
+      {
+        auWithGreaterLatencyCount = true;
+      }
+    }
+
+    Bool cond2 = (m_maxLatencyIncreasePlus1 != 0 ) && auWithGreaterLatencyCount;
+
+    if ( cond1  || cond2 )
+    {
+      xF13524Bumping( aus );
+    }
+    else
+    {
+      repeat = false;
+    }
+  }
+}
+
+Void TAppDecTop::xF13524Bumping( TComList<TComAu*> aus )
+{
+  ////////////////////////////////////////////////////////////////////////////////
+  // F.13.5.2.4 "Bumping" process
+  ////////////////////////////////////////////////////////////////////////////////
+
+  // The picture or pictures that are first for output are selected as the ones having the
+  // smallest value of PicOrderCntVal of all pictures in the DPB marked as "needed for output".
+
+  assert( !aus.empty() );
+
+  // Create copy, since original AU from DBP is modified when removing pic.
+  TComAu auWithSmallestPoc = *((*aus.begin())); // List is sorted, hence the AU with smallest POC is the first.
+
+  for(TComAu::iterator itP= auWithSmallestPoc.begin(); ( itP!=auWithSmallestPoc.end() ); itP++)
+  {
+    TComPic* pic = (*itP);
+
+    if (pic->getOutputMark() )
+    {
+      // Each of these pictures is, in ascending nuh_layer_id order, cropped,
+      // using the conformance cropping window specified in the active SPS for the picture,
+      // the cropped picture is output, and the picture is marked as "not needed for output".
+
+      // pictures are sorted in the AU in ascending nuh_layer_id order.
+
+
+      xCropAndOutput( pic );
+      pic->setOutputMark( false );
+
+      // Each picture storage buffer that contains a picture marked as "unused for reference"
+      // and that was one of the pictures cropped and output is emptied and the fullness of
+      // the associated sub-DPB is decremented by one.
+
+      if (pic->getMarkedUnUsedForReference() )
+      {
+        m_dpb.removePic( pic );
+      }
+    }
+  }
+}
+
+Void TAppDecTop::xF816decProcEndDecOfCodPicLIdGrtZero()
+{
+  ////////////////////////////////////////////////////////////////////////////////
+  // F.8.1.6  Decoding process for ending the decoding of a coded picture with nuh_layer_id greater than 0
+  ////////////////////////////////////////////////////////////////////////////////
+
+  const TComSlice* slice = m_curPic->getSlice( 0 );
+  const Int nuhLayerId   = m_curPic->getLayerId();
+
+  assert(  nuhLayerId != 0 );
+
+  //The marking of decoded pictures is modified as specified in the following:
+  for (Int i = 0; i < m_curPic->getDecodedRps()->m_numActiveRefLayerPics0;i++ )
+  {
+    m_curPic->getDecodedRps()->m_refPicSetInterLayer0[i]->markAsUsedForShortTermReference();
+  }
+
+  for (Int i = 0; i < m_curPic->getDecodedRps()->m_numActiveRefLayerPics1;i++ )
+  {
+    m_curPic->getDecodedRps()->m_refPicSetInterLayer1[i]->markAsUsedForShortTermReference();
+  }
+
+  // PicOutputFlag is set as follows:
+  if ( !m_layerInitilizedFlag[ nuhLayerId ] )
+  {
+    // - If LayerInitializedFlag[ nuh_layer_id ] is equal to 0, PicOutputFlag is set equal to 0.
+    m_curPic->setPicOutputFlag( false );
+  }
+  else if (m_curPic->isRasl( ) && m_noRaslOutputFlagAssocIrap[ nuhLayerId] )
+  {
+    // - Otherwise, if the current picture is a RASL picture and NoRaslOutputFlag of the associated IRAP picture is equal to 1,
+    //   PicOutputFlag is set equal to 0.
+
+    m_curPic->setPicOutputFlag( false );
+  }
+  else
+  {
+    // - Otherwise, PicOutputFlag is set equal to pic_output_flag.
+    m_curPic->setPicOutputFlag( slice->getPicOutputFlag() );
+  }
+
+  // The decoded picture is marked as "used for short-term reference".
+  m_curPic->markAsUsedForShortTermReference();
+
+  if ( !m_firstPicInLayerDecodedFlag[ nuhLayerId ] )
+  {
+    // When FirstPicInLayerDecodedFlag[ nuh_layer_id ] is equal to 0, FirstPicInLayerDecodedFlag[ nuh_layer_id ] is set equal to 1.
+    m_firstPicInLayerDecodedFlag[ nuhLayerId ] = true;
+  }
+}
+
+TDecTop* TAppDecTop::xGetDecoder( InputNALUnit& nalu )
+{
+  return m_tDecTop[ xGetDecoderIdx( nalu.m_nuhLayerId )];
+}
+
+
 Int TAppDecTop::xGetDecoderIdx( Int layerId, Bool createFlag /*= false */ )
 {
-  Int decIdx = -1; 
-
-  if ( layerId > MAX_NUM_LAYER_IDS-1 )  
-  {
-    return decIdx; 
-  }
-
-  if ( m_layerIdToDecIdx[ layerId ] != -1 ) 
-  {      
-    decIdx = m_layerIdToDecIdx[ layerId ]; 
+  Int decIdx = -1;
+
+  if ( layerId > MAX_NUM_LAYER_IDS-1 )
+  {
+    return decIdx;
+  }
+
+  if ( m_layerIdToDecIdx[ layerId ] != -1 )
+  {
+    decIdx = m_layerIdToDecIdx[ layerId ];
   }
   else
-  {      
-    assert ( createFlag ); 
-    assert( m_numDecoders < MAX_NUM_LAYERS ); 
-
-    decIdx = m_numDecoders; 
+  {
+    assert ( createFlag );
+    assert( m_numDecoders < MAX_NUM_LAYERS );
+
+    decIdx = m_numDecoders;
 
     // Init decoder
@@ -1076,7 +2649,11 @@
     m_tDecTop[ decIdx ]->setLayerId( layerId );
     m_tDecTop[ decIdx ]->setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
-    m_tDecTop[ decIdx ]->setIvPicLists( &m_ivPicLists ); 
-    m_tDecTop[ decIdx ]->setLayerInitilizedFlags( m_layerInitilizedFlags );
-    m_tDecTop[ decIdx ]->setTargetOlsIdx( m_targetOptLayerSetIdx );    
+    m_tDecTop[ decIdx ]->setDpb( &m_dpb );
+    m_tDecTop[ decIdx ]->setTargetOlsIdx( m_targetOptLayerSetIdx );
+    m_tDecTop[ decIdx ]->setFirstPicInLayerDecodedFlag( m_firstPicInLayerDecodedFlag );
+    m_tDecTop[ decIdx ]->setPocDecrementedInDPBFlag   ( m_pocDecrementedInDpbFlag    );
+    m_tDecTop[ decIdx ]->setLastPresentPocResetIdc    ( m_lastPresentPocResetIdc );
+
+
 #if O0043_BEST_EFFORT_DECODING
     m_cTDecTop[ decIdx ]->setForceDecodeBitDepth(m_forceDecodeBitDepth);
@@ -1091,29 +2668,26 @@
 #endif
 
-    // append pic list of new decoder to PicLists 
-    assert( m_ivPicLists.size() == m_numDecoders );
-    m_ivPicLists.push_back( m_tDecTop[ decIdx ]->getListPic() );
-
-    // create recon file related stuff      
+    // append pic list of new decoder to PicLists
+
+    // create recon file related stuff
     Char* pchTempFilename = NULL;
     if ( m_pchReconFile )
-    {      
-      Char buffer[4];      
+    {
+      Char buffer[4];
       sprintf(buffer,"_%i", layerId );
-      assert ( m_pchReconFile ); 
+      assert ( m_pchReconFile );
       xAppendToFileNameEnd( m_pchReconFile , buffer, pchTempFilename );
       assert( m_pchReconFiles.size() == m_numDecoders );
     }
 
-    m_pchReconFiles.push_back( pchTempFilename );   
+    m_pchReconFiles.push_back( pchTempFilename );
 
     m_tVideoIOYuvReconFile[ decIdx ] = new TVideoIOYuv;
     m_reconOpen           [ decIdx ] = false;
 
-    // set others 
-    m_pocLastDisplay      [ decIdx ] = -MAX_INT;
-    m_layerIdToDecIdx     [ layerId ] = decIdx; 
-
-    m_numDecoders++; 
+    // set others
+    m_layerIdToDecIdx     [ layerId ] = decIdx;
+
+    m_numDecoders++;
   };
   return decIdx;
@@ -1121,88 +2695,313 @@
 }
 
-Void TAppDecTop::xMarkForOutput( Bool allLayersDecoded, Int pocLastPic, Int layerIdLastPic )
+Int TAppDecTop::xPreDecodePoc( InputNALUnit& nalu )
 {  
-  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 );
+  // - According to F.7.4.2.4.4, the POC of the current picture is required to detect whether it is the first in a new AU
+  // - F.8.1.3 needs to know if the current picture is the first of an AU
+  //   actually before its POC has been decoded.
+
+  // Thus, in the software implementation the processes can not be invoked in the same order as in the Spec.
+  // For this, this function decodes the POC before invoking F.8.1.3. However, this is done without
+  // altering member variables
+
+  // Do some stuff from F.8.1.3 required for POC derivation, which is not depending on AU detection.
+  TDecTop* dec          = xGetDecoder( nalu ); 
+  TComSlice* slicePilot = dec->getSlicePilot(); 
+  Int nuhLayerId        = nalu.m_nuhLayerId; 
+  Int smallestLayerId   = dec->getSmallestLayerId();
+
+  Int handleCraAsBlaFlag; 
+  if ( nalu.isIrap() )
+  {
+    if ( !m_handleCraAsBlaFlagSetByExtMeans )
+    {
+      handleCraAsBlaFlag = false;
+    }
+  }
+
+  Bool firstPicInLayerDecodedFlag = m_firstPicInLayerDecodedFlag[ nalu.m_nuhLayerId ];
+  
+  if ( nalu.isIrap() && nuhLayerId == smallestLayerId )
+  {
+    Int noClrasOutputFlag;
+    if( m_firstSliceInBitstream )
+    {
+      noClrasOutputFlag = true; 
+    }
+    else if( m_eosInLayer[ 0 ] || m_eosInLayer[ nuhLayerId ] )
+    {
+      noClrasOutputFlag = true;
+    }
+    else if ( nalu.isBla() || (nalu.isCra() && handleCraAsBlaFlag ))
+    {
+      noClrasOutputFlag = true; 
+    }
+    else if ( nalu.isIdr() && slicePilot->getCrossLayerBlaFlag() )
+    {
+      noClrasOutputFlag = true; 
+    }
+    else if ( m_noClrasOutputFlagSetByExtMeans )
+    {
+      noClrasOutputFlag = m_noClrasOutputFlag; 
+    }
+    else
+    {     
+      noClrasOutputFlag  = false;
+    }
+
+    if( noClrasOutputFlag )
+    {
+      firstPicInLayerDecodedFlag = false; 
+    }    
+  }
+
+  // Derive POC
+  return dec->preDecodePoc(firstPicInLayerDecodedFlag, m_newPicIsFstPicOfAllLayOfPocResetPer, m_newPicIsPocResettingPic );
+}
+
+Bool TAppDecTop::xDetectNewAu( InputNALUnit& nalu )
+{
+  TDecTop*        dec        = xGetDecoder( nalu );
+  TComSlice*      slicePilot = dec->getSlicePilot();
+  const TComVPS*  vps        = slicePilot->getVPS();
+
+  Bool firstVclNaluOfAu;
+
+  if (m_curPic == NULL )
+  {
+    // No picture decoded yet, so we have a new AU.
+    firstVclNaluOfAu = true; 
+  }
+  else
+  {
+    if ( !vps->getVpsExtensionFlag() )
+    {
+      // Decoding according to clause 8, hence one pic per AU.
+      firstVclNaluOfAu = slicePilot->getFirstSliceSegementInPicFlag();
+    }
+    else
+    {
+      if ( dec->getTargetOlsIdx() == 0 )
+      {
+        // Only the base layer is decoded, hence one pic per AU.
+        firstVclNaluOfAu = slicePilot->getFirstSliceSegementInPicFlag();
       }
       else
-      {        
-        xMarkAltOutPic( targetLayerId, pocLastPic ); 
-      }
-      m_markedForOutput = true; 
-    }
-    else if ( ( layerIdLastPic > targetLayerId || allLayersDecoded ) && !m_markedForOutput )
-    {
-      xMarkAltOutPic( targetLayerId, pocLastPic );
-    }
-
-    if ( allLayersDecoded )
-    {
-      m_markedForOutput = false; 
-    }
+      {
+        // F.7.4.2.4.4  Order of NAL units and coded pictures and association to access units    
+        //  An access unit consists of one or more coded pictures, each with a distinct value of 
+        //  nuh_layer_id, and zero or more non-VCL NAL units. 
+
+        //  A VCL NAL unit is the first VCL NAL unit of an access unit, when all of the following conditions are true:
+        //  -  first_slice_segment_in_pic_flag is equal to 1.
+        //  -  At least one of the following conditions is true:
+        //     - The previous picture in decoding order belongs to a different POC resetting period 
+        //       than the picture containing the VCL NAL unit.
+        Bool prevPicDiffPocResetPeriod = m_newPicIsFstPicOfAllLayOfPocResetPer; 
+
+        //     - PicOrderCntVal derived for the VCL NAL unit differs from the PicOrderCntVal of the 
+        //       previous picture in decoding order.
+        Bool prevPicDiffPoc = ( xPreDecodePoc( nalu ) != m_curPic->getPOC() );
+
+        if( slicePilot->getFirstSliceSegementInPicFlag() && ( prevPicDiffPocResetPeriod || prevPicDiffPoc ) )
+        {
+          firstVclNaluOfAu = true;
+        }
+        else
+        {
+          firstVclNaluOfAu = false;
+        }
+      }
+    }
+  }
+  return firstVclNaluOfAu;
+}
+
+Void TAppDecTop::xDetectNewPocResettingPeriod( InputNALUnit& nalu )
+{
+  TDecTop* dec  = xGetDecoder( nalu );
+  dec->inferPocResetPeriodId();
+
+
+  Int pocResetIdc         = dec->getSlicePilot()->getPocResetIdc();
+  Int newPocResetPeriodId = dec->getSlicePilot()->getPocResetPeriodId();
+
+  Int curPocResetPeriodId = ( m_curPic != NULL)  ? m_curPic->getPocResetPeriodId() : MIN_INT; 
+
+  // Check if new picture starts a new poc resetting period.
+  if(  ( pocResetIdc == 1 || pocResetIdc == 2 ) &&  ( curPocResetPeriodId != newPocResetPeriodId ) )
+  {
+    for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++ )
+    {
+      m_firstPicInPocResettingPeriodReceived[ i ] = false;
+    }
+    m_newPicIsFstPicOfAllLayOfPocResetPer = true;
   }
   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 ); 
-        }
-      }
-    }
-  }
-}
-
-Void TAppDecTop::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->getDependencyFlag(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); 
-  }
+  {
+    m_newPicIsFstPicOfAllLayOfPocResetPer = false;
+  }
+
+  // Check if current picture is a poc resetting picture (thus the first picture of this layer within the POC resetting period.
+  if ( !m_firstPicInPocResettingPeriodReceived[ nalu.m_nuhLayerId ] )
+  {
+    m_newPicIsPocResettingPic = true;
+    m_firstPicInPocResettingPeriodReceived[ nalu.m_nuhLayerId ] = true;
+  }
+  else
+  {
+    m_newPicIsPocResettingPic = false;
+  }
+
+}
+
+Bool TAppDecTop::xAllRefLayersInitilized( Int curLayerId )
+{
+  Bool allRefLayersInitilizedFlag = true;
+  for (Int i = 0; i < m_vps->getNumDirectRefLayers( curLayerId  ); i++ )
+  {
+    Int refLayerId = m_vps->getIdDirectRefLayer( curLayerId, i );
+    allRefLayersInitilizedFlag = allRefLayersInitilizedFlag && m_layerInitilizedFlag[ refLayerId ];
+  }
+
+  return allRefLayersInitilizedFlag;
+}
+
+Void TAppDecTop::xInitFileIO()
+{
+  m_bitstreamFile.open(m_pchBitstreamFile, ifstream::in | ifstream::binary);
+
+  if ( !m_bitstreamFile)
+  {
+    fprintf(stderr, "\nUnable to open bitstream file `%s' for reading\n", m_pchBitstreamFile);
+    exit(EXIT_FAILURE);
+  }
+
+  if (!m_outputDecodedSEIMessagesFilename.empty() && m_outputDecodedSEIMessagesFilename!="-")
+  {
+    m_seiMessageFileStream.open(m_outputDecodedSEIMessagesFilename.c_str(), std::ios::out);
+    if (!m_seiMessageFileStream.is_open() || !m_seiMessageFileStream.good())
+    {
+      fprintf(stderr, "\nUnable to open file `%s' for writing decoded SEI messages\n", m_outputDecodedSEIMessagesFilename.c_str());
+      exit(EXIT_FAILURE);
+    }
+  }
+
+#if NH_3D
+  if( m_pchScaleOffsetFile )
+  {
+    m_pScaleOffsetFile = ::fopen( m_pchScaleOffsetFile, "wt" );
+    if (!m_pScaleOffsetFile)
+    {
+      fprintf(stderr, "\nUnable to open file `%s' for writing decoded Camera Parameters messages\n", m_pchScaleOffsetFile);
+      exit(EXIT_FAILURE);
+    }
+  }
+#endif
+}
+
+Void TAppDecTop::xOpenReconFile( TComPic* curPic )
+{
+  Int decIdx = xGetDecoderIdx( curPic->getLayerId() );
+
+  if ( m_pchReconFile && !m_reconOpen[decIdx] )
+  {
+    const BitDepths &bitDepths= curPic->getPicSym()->getSPS().getBitDepths(); // use bit depths of first reconstructed picture.
+    for (UInt channelType = 0; channelType < MAX_NUM_CHANNEL_TYPE; channelType++)
+    {
+      if (m_outputBitDepth[channelType] == 0)
+      {
+        m_outputBitDepth[channelType] = bitDepths.recon[channelType];
+      }
+    }
+
+    m_tVideoIOYuvReconFile[decIdx]->open( m_pchReconFiles[decIdx], true, m_outputBitDepth, m_outputBitDepth, bitDepths.recon ); // write mode
+    m_reconOpen[decIdx] = true;
+  }
+}
+
+Void TAppDecTop::xFlushOutput()
+{
+  Bool repeat = true;
+  while ( repeat )
+  {
+    if( m_decProcCvsg == ANNEX_F )
+    {
+      TComList<TComAu*> aus = m_dpb.getAusHavingPicsMarkedForOutput();
+      if ( !aus.empty() )
+      {
+        xF13524Bumping( aus );
+      }      
+      else
+      {
+        repeat = false;
+      }
+    }      
+    else if( m_decProcCvsg == CLAUSE_8 )
+    {
+      TComList<TComPic*> picsMarkedForOutput = m_dpb.getSubDpb( 0, false )->getPicsMarkedNeedForOutput();
+      if (!picsMarkedForOutput.empty())
+      {
+        xC524Bumping();
+      }
+      else
+      {
+        repeat = false; 
+      }
+    }
+  }
+}
+
+Void TAppDecTop::xCropAndOutput( TComPic* curPic )
+{
+
+  if ( m_printPicOutput )
+  {
+    std::cout << "  Output picture: ";
+    curPic->print( 2 );
+    std::cout << std::endl;
+  }
+
+  assert( !curPic->getHasGeneratedRefPics() );
+  assert( !curPic->getIsGenerated()         );
+
+  Int decIdx = xGetDecoderIdx( curPic->getLayerId() );
+
+  if (!m_reconOpen[ decIdx ])
+  {
+    xOpenReconFile( curPic );
+  }
+
+  if ( m_pchReconFiles[ decIdx ] )
+  {
+    const Window &conf    = curPic->getConformanceWindow();
+    const Window  defDisp = m_respectDefDispWindow ? curPic->getDefDisplayWindow() : Window();
+
+    assert( conf   .getScaledFlag() );
+    assert( defDisp.getScaledFlag() );
+
+    m_tVideoIOYuvReconFile[decIdx]->write( curPic->getPicYuvRec(),
+      m_outputColourSpaceConvert,
+      conf.getWindowLeftOffset()   + defDisp.getWindowLeftOffset(),
+      conf.getWindowRightOffset()  + defDisp.getWindowRightOffset(),
+      conf.getWindowTopOffset()    + defDisp.getWindowTopOffset(),
+      conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(),
+#if NH_3D
+      m_depth420OutputFlag && curPic->getIsDepth() ? CHROMA_420 : NUM_CHROMA_FORMAT
+#else
+      NUM_CHROMA_FORMAT
+#endif
+      , m_bClipOutputVideoToRec709Range);
+  }
+}
+
+UInt TAppDecTop::getNumberOfChecksumErrorsDetected() const
+{
+  UInt numOfChecksumErrors = 0;
+  for (Int i = 0; i < m_numDecoders; i++ )
+  {
+    numOfChecksumErrors += getNumberOfChecksumErrorsDetected( i );
+  }
+  return numOfChecksumErrors;
 }
 
Index: trunk/source/App/TAppDecoder/TAppDecTop.h
===================================================================
--- trunk/source/App/TAppDecoder/TAppDecTop.h	(revision 1314)
+++ trunk/source/App/TAppDecoder/TAppDecTop.h	(revision 1321)
@@ -60,31 +60,72 @@
 {
 private:
-  // class interface
+  // class interface  
 #if NH_MV
   TDecTop*                        m_tDecTop             [ MAX_NUM_LAYERS ];    ///< decoder classes
   TVideoIOYuv*                    m_tVideoIOYuvReconFile[ MAX_NUM_LAYERS ];    ///< reconstruction YUV class
-  Int                             m_layerIdToDecIdx     [ MAX_NUM_LAYER_IDS ]; ///< maping from layer id to decoder index
+  Int                             m_layerIdToDecIdx     [ MAX_NUM_LAYER_IDS ]; ///< mapping from layer id to decoder index
   Int                             m_numDecoders;                               ///< number of decoder instances
-  TComPicLists                    m_ivPicLists;                                ///< picture buffers of decoder instances
-  Bool                            m_layerInitilizedFlags[ MAX_NUM_LAYER_IDS ]; ///< for layerwise startup 
+  TComPicLists                    m_dpb;                                       ///< picture buffers of decoder instances
+
+  TComPic*                        m_curPic;                                    ///< currently decoded picture
+  TComAu                          m_curAu;                                     ///< currently decoded Au
+ 
+  // Random access related 
+  Bool                            m_handleCraAsBlaFlag; 
+  Bool                            m_handleCraAsBlaFlagSetByExtMeans; 
+  Bool                            m_noClrasOutputFlag; 
+  Bool                            m_noClrasOutputFlagSetByExtMeans; 
+  Bool                            m_noRaslOutputFlagAssocIrap           [ MAX_NUM_LAYER_IDS ]; 
+
+  // Layer wise startup
+  Bool                            m_firstPicInLayerDecodedFlag          [ MAX_NUM_LAYER_IDS ];
+  Bool                            m_layerInitilizedFlag                 [ MAX_NUM_LAYER_IDS ]; 
+  Bool                            m_layerResetFlag; 
+
+  // DPB related variables
+  Int                             m_maxNumReorderPics; 
+  Int                             m_maxLatencyIncreasePlus1; 
+  Int                             m_maxLatencyValue; 
+  Int                             m_maxDecPicBufferingMinus1            [ MAX_NUM_LAYER_IDS ];
+
+  // Poc resetting
+  Int                             m_lastPresentPocResetIdc              [ MAX_NUM_LAYER_IDS ];
+  Bool                            m_firstPicInPocResettingPeriodReceived[ MAX_NUM_LAYER_IDS ];
+  Bool                            m_pocDecrementedInDpbFlag             [ MAX_NUM_LAYER_IDS ]; 
+  Bool                            m_newPicIsFstPicOfAllLayOfPocResetPer;
+  Bool                            m_newPicIsPocResettingPic;
+
+  // General decoding state
+  Bool                            m_newVpsActivatedbyCurAu; 
+  Bool                            m_newVpsActivatedbyCurPic; 
+  Bool                            m_eosInLayer                          [ MAX_NUM_LAYER_IDS ];
+  Bool                            m_initilizedFromVPS;
+  Bool                            m_firstSliceInBitstream;
+  UInt64                          m_decodingOrder                       [ MAX_NUM_LAYER_IDS ];
+  UInt64                          m_totalNumofPicsReceived;
+  Bool                            m_cvsStartFound; 
+  Int                             m_smallestLayerId;
+
+  // Decoding processes for current  picture
+  DecodingProcess                 m_decProcPocAndRps;
+  DecodingProcess                 m_decProcCvsg; 
+  
+  // Active parameter sets
+  const TComPPS*                  m_pps;                                ///< active PPS
+  const TComSPS*                  m_sps;                                ///< active SPS
   const TComVPS*                  m_vps;                                ///< active VPS
+
+  Bool                            m_reconOpen           [ MAX_NUM_LAYERS ]; ///< reconstruction file opened
+#if NH_3D
+  FILE*                           m_pScaleOffsetFile;
+  CamParsCollector                m_cCamParsCollector;
+#endif
 #else
   TDecTop                         m_cTDecTop;                     ///< decoder class
   TVideoIOYuv                     m_cTVideoIOYuvReconFile;        ///< reconstruction YUV class
-#endif
   // for output control
-#if NH_MV
-  Int                             m_pocLastDisplay      [ MAX_NUM_LAYERS ]; ///< last POC in display order
-  Bool                            m_reconOpen           [ MAX_NUM_LAYERS ]; ///< reconstruction file opened
-  Bool                            m_markedForOutput; 
-#else
   Int                             m_iPOCLastDisplay;              ///< last POC in display order
 #endif
-  std::ofstream                   m_seiMessageFileStream;         ///< Used for outputing SEI messages.
-
-#if NH_3D
-  FILE*                           m_pScaleOffsetFile;
-  CamParsCollector                m_cCamParsCollector;
-#endif
+  std::ofstream                   m_seiMessageFileStream;         ///< Used for outputing SEI messages.  
 public:
   TAppDecTop();
@@ -95,16 +136,6 @@
   Void  decode            (); ///< main decoding function
 #if NH_MV
-  UInt  getNumberOfChecksumErrorsDetected( ) const 
-  {
-    UInt numOfChecksumErrors = 0; 
-    for (Int i = 0; i < m_numDecoders; i++ )
-    {
-      numOfChecksumErrors += getNumberOfChecksumErrorsDetected( i ); 
-    }
-    return numOfChecksumErrors; 
-  }
-
+  UInt  getNumberOfChecksumErrorsDetected( ) const;
   UInt  getNumberOfChecksumErrorsDetected( Int decIdx ) const { return m_tDecTop[decIdx]->getNumberOfChecksumErrorsDetected(); }
-
 #else
   UInt  getNumberOfChecksumErrorsDetected() const { return m_cTDecTop.getNumberOfChecksumErrorsDetected(); }
@@ -112,21 +143,67 @@
 
 protected:
+
   Void  xCreateDecLib     (); ///< create internal classes
   Void  xDestroyDecLib    (); ///< destroy internal classes
   Void  xInitDecLib       (); ///< initialize decoder class
 
-#if NH_MV
-  Void  xWriteOutput      ( TComList<TComPic*>* pcListPic, Int layerId, Int tId ); ///< write YUV to file
-
-  Void  xMarkForOutput   ( Bool allLayersDecoded, Int pocLastPic, Int layerIdLastPic );         
-  Void  xMarkAltOutPic    ( Int targetOutputLayer, Int pocLastPic );
-
-  Void  xFlushOutput      ( TComList<TComPic*>* pcListPic, Int layerId ); ///< flush all remaining decoded pictures to file
-  Int   xGetDecoderIdx    ( Int layerId, Bool createFlag = false );
-#else
+#if !NH_MV
   Void  xWriteOutput      ( TComList<TComPic*>* pcListPic , UInt tId); ///< write YUV to file
   Void  xFlushOutput      ( TComList<TComPic*>* pcListPic ); ///< flush all remaining decoded pictures to file
-#endif
-  Bool  isNaluWithinTargetDecLayerIdSet ( InputNALUnit* nalu ); ///< check whether given Nalu is within targetDecLayerIdSet
+  Bool  isNaluWithinTargetDecLayerIdSet    ( InputNALUnit* nalu ); ///< check whether given Nalu is within targetDecLayerIdSet
+
+#else
+  // Process NAL units 
+  Bool xExtractAndRewrite                  ( InputNALUnit* nalu );
+  Void xProcessVclNalu                     ( InputNALUnit nalu );
+  Bool xIsSkipVclNalu                      ( InputNALUnit& nalu, Bool isFirstSliceOfPic );
+  Void xProcessNonVclNalu                  ( InputNALUnit nalu );
+  Void xTerminateDecoding                  ( );
+
+  // Process slice 
+  Void xDecodeFirstSliceOfPicture          ( InputNALUnit nalu, Bool sliceIsFirstOfNewAu );  
+  Void xDecodeFollowSliceOfPicture         ( InputNALUnit nalu );
+
+  // Process picture  
+  Void xFinalizePreviousPictures           ( Bool sliceIsFirstOfNewAU );
+  Void xFinalizePic                        ( Bool curPicIsLastInAu );
+  Void xFinalizeAU                         ( );
+  Void xPicDecoding                        ( DecProcPart curPart, Bool picPosInAuIndication ); 
+
+  // Clause 8
+  Void x812CvsgDecodingProcess             ( Int decIdx );
+  Void x813decProcForCodPicWithLIdZero     ( DecProcPart curPart );
+
+  // Annex C (DPB)
+  Void xC522OutputAndRemOfPicsFromDpb      ( );
+  Void xC523PicDecMarkAddBumpAndStor       ( );
+  Void xC524Bumping                        ( );
+
+  // Annex F.8
+  Void xF811GeneralDecProc                 ( InputNALUnit nalu );
+  Void xF812CvsgDecodingProcess            ( Int decIdx );
+  Void xF813ComDecProcForACodedPic         ( DecProcPart curPart, Bool picPosInAuIndication );
+  Void xF814decProcForCodPicWithLIdZero    ( DecProcPart curPart );
+  Void xF816decProcEndDecOfCodPicLIdGrtZero( );
+
+  // Annex F.13 (DPB)
+  Void xF13521InitDpb                      ( );
+  Void xF13522OutputAndRemOfPicsFromDpb    ( Bool beforePocDerivation );
+  Void xF13523PicDecMarkAddBumpAndStor     ( Bool curPicIsLastInAu   );
+  Void xF13524Bumping                      ( TComList<TComAu*> aus );
+
+  // Helpers
+  TDecTop* xGetDecoder                     ( InputNALUnit& nalu );  
+  Int   xGetDecoderIdx                     ( Int layerId, Bool createFlag = false );
+  Int   xPreDecodePoc                      ( InputNALUnit& nalu );
+  Bool  xDetectNewAu                       ( InputNALUnit& nalu );
+  Void  xDetectNewPocResettingPeriod       ( InputNALUnit& nalu );
+  Bool  xIsNaluInTargetDecLayerIdSet       ( InputNALUnit* nalu ); ///< check whether given Nalu is within targetDecLayerIdSet
+  Bool  xAllRefLayersInitilized            ( Int curLayerId );
+  Void  xInitFileIO                        ( );  
+  Void  xOpenReconFile                     ( TComPic* curPic );
+  Void  xFlushOutput                       ( );
+  Void  xCropAndOutput                     ( TComPic* curPic );  
+#endif
 };
 
@@ -134,3 +211,2 @@
 
 #endif
-
Index: trunk/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 1314)
+++ trunk/source/App/TAppEncoder/TAppEncTop.cpp	(revision 1321)
@@ -260,8 +260,16 @@
   {
     m_cListPicYuvRec            .push_back(new TComList<TComPicYuv*>) ;
+
+#if !NH_MV
     m_ivPicLists.push_back( m_acTEncTopList[ layerIdInVps ]->getListPic()  ); 
+#endif
+
     TEncTop& m_cTEncTop = *m_acTEncTopList[ layerIdInVps ];  // It is not a member, but this name helps avoiding code duplication !!!
 
-    Int layerId = vps.getLayerIdInNuh( layerIdInVps );
+    Int layerId = vps.getLayerIdInNuh          ( layerIdInVps );
+#if NH_MV
+    m_ivPicLists.getSubDpb( layerId, true ); 
+#endif
+
     m_cTEncTop.setLayerIdInVps                 ( layerIdInVps ); 
     m_cTEncTop.setLayerId                      ( layerId );    
@@ -1216,5 +1224,5 @@
   }
 #if NH_MV
-    }
+}
   }
 #endif  
@@ -1766,5 +1774,5 @@
       // check if all inter layer reference pictures specified in the gop entry are valid reference layer pictures when allRefLayerActiveFlag is equal to 1 
       // (Should actually always be true) 
-      Bool maxTidIlRefAndSubLayerMaxVaildFlag = true; 
+      Bool maxTidIlRefAndSubLayerMaxValidFlag = true; 
       for( Int l = 0; l < ge.m_numActiveRefLayerPics; l++ )
       {   
@@ -1784,7 +1792,7 @@
           }          
         }
-       maxTidIlRefAndSubLayerMaxVaildFlag = maxTidIlRefAndSubLayerMaxVaildFlag && referenceLayerFoundFlag;  
-      }
-      assert ( maxTidIlRefAndSubLayerMaxVaildFlag ); // Something wrong with MaxTidIlRefPicsPlus1 or SubLayersVpsMaxMinus1
+       maxTidIlRefAndSubLayerMaxValidFlag = maxTidIlRefAndSubLayerMaxValidFlag && referenceLayerFoundFlag;  
+      }
+      assert ( maxTidIlRefAndSubLayerMaxValidFlag ); // Something wrong with MaxTidIlRefPicsPlus1 or SubLayersVpsMaxMinus1
     }            
   }
Index: trunk/source/Lib/TLibCommon/CommonDef.h
===================================================================
--- trunk/source/Lib/TLibCommon/CommonDef.h	(revision 1314)
+++ trunk/source/Lib/TLibCommon/CommonDef.h	(revision 1321)
@@ -278,4 +278,6 @@
 static const Int  MAX_NUM_VIDEO_SIGNAL_INFO =                     16 ;
 static const Int  MAX_NUM_SCALED_REF_LAYERS =     MAX_NUM_LAYERS - 1 ; 
+static const Int  MAX_NUM_PICS_RPS          =                     16 ; 
+static const Int  MAX_NUM_REF_LAYERS        =                     63 ;  
 #endif
 
@@ -367,4 +369,73 @@
 #endif
 
+#if NH_MV
+static const std::string NALU_TYPE_STR[] = {  
+    "CODED_SLICE_TRAIL_N   ",  // 0
+    "CODED_SLICE_TRAIL_R   ",  // 1
+    "CODED_SLICE_TSA_N     ",  // 2
+    "CODED_SLICE_TSA_R     ",  // 3
+    "CODED_SLICE_STSA_N    ",  // 4
+    "CODED_SLICE_STSA_R    ",  // 5
+    "CODED_SLICE_RADL_N    ",  // 6
+    "CODED_SLICE_RADL_R    ",  // 7
+    "CODED_SLICE_RASL_N    ",  // 8
+    "CODED_SLICE_RASL_R    ",  // 9
+    "RESERVED_VCL_N10      ",
+    "RESERVED_VCL_R11      ",
+    "RESERVED_VCL_N12      ",
+    "RESERVED_VCL_R13      ",
+    "RESERVED_VCL_N14      ",
+    "RESERVED_VCL_R15      ",
+    "CODED_SLICE_BLA_W_LP  ",  // 16
+    "CODED_SLICE_BLA_W_RADL",  // 17
+    "CODED_SLICE_BLA_N_LP  ",  // 18
+    "CODED_SLICE_IDR_W_RADL",  // 19
+    "CODED_SLICE_IDR_N_LP  ",  // 20
+    "CODED_SLICE_CRA       ",  // 21
+    "RESERVED_IRAP_VCL22   ",
+    "RESERVED_IRAP_VCL23   ",
+    "RESERVED_VCL24        ",
+    "RESERVED_VCL25        ",
+    "RESERVED_VCL26        ",
+    "RESERVED_VCL27        ",
+    "RESERVED_VCL28        ",
+    "RESERVED_VCL29        ",
+    "RESERVED_VCL30        ",
+    "RESERVED_VCL31        ",
+    "VPS                   ",   // 32
+    "SPS                   ",   // 33
+    "PPS                   ",   // 34
+    "ACCESS_UNIT_DELIMITER ",   // 35
+    "EOS                   ",   // 36
+    "EOB                   ",   // 37
+    "FILLER_DATA           ",   // 38
+    "PREFIX_SEI            ",   // 39
+    "SUFFIX_SEI            ",   // 40
+    "RESERVED_NVCL41       ",
+    "RESERVED_NVCL42       ",
+    "RESERVED_NVCL43       ",
+    "RESERVED_NVCL44       ",
+    "RESERVED_NVCL45       ",
+    "RESERVED_NVCL46       ",
+    "RESERVED_NVCL47       ",
+    "UNSPECIFIED_48        ",
+    "UNSPECIFIED_49        ",
+    "UNSPECIFIED_50        ",
+    "UNSPECIFIED_51        ",
+    "UNSPECIFIED_52        ",
+    "UNSPECIFIED_53        ",
+    "UNSPECIFIED_54        ",
+    "UNSPECIFIED_55        ",
+    "UNSPECIFIED_56        ",
+    "UNSPECIFIED_57        ",
+    "UNSPECIFIED_58        ",
+    "UNSPECIFIED_59        ",
+    "UNSPECIFIED_60        ",
+    "UNSPECIFIED_61        ",
+    "UNSPECIFIED_62        ",
+    "UNSPECIFIED_63        ",
+    "INVALID               "               
+  };
+#endif
 
 #if NH_3D
Index: trunk/source/Lib/TLibCommon/Debug.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/Debug.cpp	(revision 1314)
+++ trunk/source/Lib/TLibCommon/Debug.cpp	(revision 1321)
@@ -152,10 +152,10 @@
 EnvVar DebugOptionList::ForceLumaMode         ("FORCE_LUMA_MODE",   "0", "Force a particular intra direction for Luma (0-34)"                                             );
 EnvVar DebugOptionList::ForceChromaMode       ("FORCE_CHROMA_MODE", "0", "Force a particular intra direction for chroma (0-5)"                                            );
-
-#if DEBUG_STRING
-EnvVar DebugOptionList::DebugString_Structure ("DEBUG_STRUCTURE",   "3", "Produce output on chosen structure                        bit0=intra, bit1=inter");
-EnvVar DebugOptionList::DebugString_Pred      ("DEBUG_PRED",        "3", "Produce output on prediction data.                        bit0=intra, bit1=inter");
-EnvVar DebugOptionList::DebugString_Resi      ("DEBUG_RESI",        "3", "Produce output on residual data.                          bit0=intra, bit1=inter");
-EnvVar DebugOptionList::DebugString_Reco      ("DEBUG_RECO",        "3", "Produce output on reconstructed data.                     bit0=intra, bit1=inter");
+                                                                      
+#if DEBUG_STRING                                                      
+EnvVar DebugOptionList::DebugString_Structure ("DEBUG_STRUCTURE",   "0", "Produce output on chosen structure                        bit0=intra, bit1=inter");
+EnvVar DebugOptionList::DebugString_Pred      ("DEBUG_PRED",        "0", "Produce output on prediction data.                        bit0=intra, bit1=inter");
+EnvVar DebugOptionList::DebugString_Resi      ("DEBUG_RESI",        "0", "Produce output on residual data.                          bit0=intra, bit1=inter");
+EnvVar DebugOptionList::DebugString_Reco      ("DEBUG_RECO",        "0", "Produce output on reconstructed data.                     bit0=intra, bit1=inter");
 EnvVar DebugOptionList::DebugString_InvTran   ("DEBUG_INV_QT",      "0", "Produce output on inverse-quantiser and transform stages. bit0=intra, bit1=inter");
 #endif
Index: trunk/source/Lib/TLibCommon/NAL.h
===================================================================
--- trunk/source/Lib/TLibCommon/NAL.h	(revision 1314)
+++ trunk/source/Lib/TLibCommon/NAL.h	(revision 1321)
@@ -98,4 +98,35 @@
         || m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R;
   }
+#if NH_MV
+  Bool isIrap()
+  {
+   return  m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP
+        || m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL
+        || m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP
+        || m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL
+        || m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP
+        || m_nalUnitType == NAL_UNIT_CODED_SLICE_CRA;
+  }
+
+  Bool isIdr()
+  {
+    return  m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL
+         || m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP;
+  }
+
+  Bool isBla()
+  {
+    return  m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP
+         || m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL
+         || m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP;
+  }
+
+  Bool isCra()
+  {
+   return  m_nalUnitType == NAL_UNIT_CODED_SLICE_CRA; 
+  }
+
+
+#endif
   Bool isSei()
   {
@@ -108,4 +139,10 @@
     return ( (UInt)m_nalUnitType < 32 );
   }
+#if NH_MV
+  Void print( )
+  {
+    std::cout << "Type: " << NALU_TYPE_STR[m_nalUnitType] << " LayerId: " << m_nuhLayerId << " TemporalId: " << m_temporalId; 
+  }
+#endif
 };
 
Index: trunk/source/Lib/TLibCommon/TComBitStream.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComBitStream.cpp	(revision 1314)
+++ trunk/source/Lib/TLibCommon/TComBitStream.cpp	(revision 1321)
@@ -41,5 +41,7 @@
 #include <string.h>
 #include <memory.h>
-
+#if NH_MV
+#include "TComRom.h" // This is only here, since ENC_DEC_TRACE is currently there. Consider removing when this has changed.
+#endif
 using namespace std;
 
@@ -258,4 +260,14 @@
   m_numBitsRead += uiNumberOfBits;
 
+#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC
+  if ( g_traceBitsRead )
+  {
+      Bool oldJustDoIt = g_bJustDoIt;
+      g_bJustDoIt = true; 
+      writeToTraceFile( "Bits: ", m_numBitsRead, true );
+      g_bJustDoIt = oldJustDoIt; 
+  }
+#endif
+
   /* NB, bits are extracted from the MSB of each byte. */
   UInt retval = 0;
Index: trunk/source/Lib/TLibCommon/TComCodingStatistics.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComCodingStatistics.h	(revision 1314)
+++ trunk/source/Lib/TLibCommon/TComCodingStatistics.h	(revision 1321)
@@ -102,5 +102,5 @@
   STATS__CABAC_BITS__3D_IC,
 #endif
-#if NH_3D_DMM || NH_3D_SDC_INTRA || H_3D_INTER_SDC
+#if NH_3D_DMM || NH_3D_SDC_INTRA || NH_3D_SDC_INTER
   STATS__CABAC_BITS__DELTADC_SIGN_EP,
   STATS__CABAC_BITS__DELTADC_PREFIX,
@@ -174,5 +174,5 @@
     "CABAC_BITS__3D_IC"
 #endif
-#if NH_3D_DMM || NH_3D_SDC_INTRA || H_3D_INTER_SDC
+#if NH_3D_DMM || NH_3D_SDC_INTRA || NH_3D_SDC_INTER
    ,"STATS__CABAC_BITS__DELTADC_SIGN_EP"
    ,"STATS__CABAC_BITS__DELTADC_PREFIX"
Index: trunk/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 1314)
+++ trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 1321)
@@ -2934,5 +2934,5 @@
 }
 
-#if NH_3D_FIX_PRUNING
+#if NH_3D
 Bool TComDataCU::hasEqualMotion( Int dirA, const TComMvField* mvFieldA, Int dirB, const TComMvField* mvFieldB )
 {
@@ -3046,9 +3046,5 @@
       if( !iLoop && ivCandDir[0] > 0)
       {
-#if NH_3D_FIX_PRUNING
         if( hasEqualMotion(tmpDir, tmpMV, m_mergCands[MRG_IVMC].m_uDir, m_mergCands[MRG_IVMC].m_cMvField )) 
-#else
-        if(tmpDir == m_mergCands[MRG_IVMC].m_uDir && m_mergCands[MRG_IVMC].m_cMvField[0]==tmpMV[0] && m_mergCands[MRG_IVMC].m_cMvField[1]==tmpMV[1])
-#endif
         {
             bRemove                         = true;
@@ -3101,4 +3097,16 @@
   }
 
+
+#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC
+  if ( g_traceMergeCandListConst ) 
+  {
+    for (Int i = 0; i<MRG_IVSHIFT+1; i++)
+    {
+      m_mergCands[i].print( i ); 
+    }
+  }
+#endif
+
+
   Int iCount = 0;
   TComMv cZeroMv;
@@ -3156,4 +3164,5 @@
     pcMvFieldNeighbours[(ui<<1)+1].setMvField(cZeroMv, NOT_VALID);
   }
+
   // copy extMergeCandList to output
   for( UInt ui = 0; ui < getSlice()->getMaxNumMergeCand(); ui++ )
@@ -3161,7 +3170,49 @@
     puhInterDirNeighbours[ui] = uhInterDirNeighboursExt[ui];
     pcMvFieldNeighbours[ui<<1].setMvField(extMergeCandList[ui<<1].getMv(), extMergeCandList[ui<<1].getRefIdx());
+
     if ( getSlice()->isInterB() )
+    {
       pcMvFieldNeighbours[(ui<<1)+1].setMvField(extMergeCandList[(ui<<1)+1].getMv(), extMergeCandList[(ui<<1)+1].getRefIdx());
-  }
+    }
+  }
+
+#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC
+  if ( g_traceMergeCandListConst )
+  {
+    std::cout << std::setfill(' ')                          << std::setw( 15 )
+      <<  "Num"                                             << std::setw( 15 )
+      <<  "Dir "                                            << std::setw( 15 )
+      <<  "L0 RefIdx"                                       << std::setw( 15 )
+      <<  "L0 Hor"                                          << std::setw( 15 )
+      <<  "L0 Ver"                                          << std::setw( 15 )
+      <<  "L1 RefIdx"                                       << std::setw( 15 )
+      <<  "L1 Hor"                                          << std::setw( 15 )
+      <<  "L1 Ver"                                          << std::setw( 15 )
+      << std::endl; 
+
+    // copy extMergeCandList to output
+    for( UInt ui = 0; ui < getSlice()->getMaxNumMergeCand(); ui++ )
+    {
+      UChar curDir        = puhInterDirNeighbours[ui];
+      TComMvField& curf   = pcMvFieldNeighbours[ui<<1];
+      TComMvField& curf2  = pcMvFieldNeighbours[(ui<<1)+1];
+
+      std::cout << std::setfill(' ')                         << std::setw( 15 )
+        << ui                                                << std::setw( 15 )        
+        << (UInt) curDir                                     << std::setw( 15 )    
+        << ((curDir & 1) ? curf.getRefIdx()       : MIN_INT) << std::setw( 15 )
+        << ((curDir & 1) ? curf.getMv().getHor()  : MIN_INT) << std::setw( 15 )
+        << ((curDir & 1) ? curf.getMv().getVer()  : MIN_INT) << std::setw( 15 );
+
+      if ( getSlice()->isInterB() )
+      {      
+        std::cout << ((curDir & 2) ? curf2.getRefIdx() : MIN_INT) << std::setw( 15 )
+          << ((curDir & 1) ? curf2.getMv().getHor()    : MIN_INT) << std::setw( 15 )
+          << ((curDir & 1) ? curf2.getMv().getVer()    : MIN_INT) << std::setw( 15 );
+      }
+      std::cout << std::endl; 
+    }
+  }
+#endif
   numValidMergeCand = iCount;
   assert(iCount == getSlice()->getMaxNumMergeCand());
@@ -3503,9 +3554,5 @@
           continue;
         }
-#if NH_3D_FIX_PRUNING
         if (hasEqualMotion( tmpDir, tmpMV, m_mergCands[MRG_A1+iCnloop].m_uDir, m_mergCands[MRG_A1+iCnloop].m_cMvField ) )
-#else
-        if (tmpDir == m_mergCands[MRG_A1+iCnloop].m_uDir && tmpMV[0]==m_mergCands[MRG_A1+iCnloop].m_cMvField[0] && tmpMV[1]==m_mergCands[MRG_A1+iCnloop].m_cMvField[1])
-#endif
         {
           m_mergCands[MRG_A1+iCnloop].m_bAvailable = false;
@@ -3581,9 +3628,5 @@
           continue;
         }
-#if NH_3D_FIX_PRUNING
         if (hasEqualMotion(ivCandDir[0], tmpMV, m_mergCands[MRG_A1+i].m_uDir,  m_mergCands[MRG_A1+i].m_cMvField) )
-#else
-        if (ivCandDir[0] == m_mergCands[MRG_A1+i].m_uDir && tmpMV[0]==m_mergCands[MRG_A1+i].m_cMvField[0] && tmpMV[1]==m_mergCands[MRG_A1+i].m_cMvField[1])
-#endif
         {
           m_mergCands[MRG_A1+i].m_bAvailable = false;
@@ -3594,9 +3637,5 @@
     else
     {
-#if NH_3D_FIX_PRUNING
       if( hasEqualMotion( ivCandDir[0], tmpMV, m_mergCands[MRG_T].m_uDir, m_mergCands[MRG_T].m_cMvField ) )
-#else
-      if (m_mergCands[MRG_T].m_bAvailable && ivCandDir[0] == m_mergCands[MRG_T].m_uDir && tmpMV[0]==m_mergCands[MRG_T].m_cMvField[0] && tmpMV[1]==m_mergCands[MRG_T].m_cMvField[1])
-#endif
       {
         bRemoveSpa                      = true;
@@ -3647,5 +3686,5 @@
       !bARPFlag &&
 #endif
-#if H_3D || NH_3D_FIX_VSP
+#if NH_3D
       (nPSW + nPSH > 12) &&
 #endif
@@ -3694,9 +3733,5 @@
         continue;
       }
-#if NH_3D_FIX_PRUNING
       if ( hasEqualMotion(ivCandDir[1], tmpMV, m_mergCands[MRG_A1+i].m_uDir, m_mergCands[MRG_A1+i].m_cMvField) )
-#else
-      if (ivCandDir[1] == m_mergCands[MRG_A1+i].m_uDir && tmpMV[0]==m_mergCands[MRG_A1+i].m_cMvField[0] && tmpMV[1]==m_mergCands[MRG_A1+i].m_cMvField[1])
-#endif
       {
         bRemoveSpa                      = true;
@@ -4852,4 +4887,16 @@
   }
 }
+#if NH_3D
+Void TComDataCU::printMV( )
+{  
+
+  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
+  {
+    std::cout << "L" << i; 
+    m_acCUMvField[i].print(m_pePredMode);
+  }
+
+}
+#endif
 
 UInt TComDataCU::getCoefScanIdx(const UInt uiAbsPartIdx, const UInt uiWidth, const UInt uiHeight, const ComponentID compID) const
@@ -5284,5 +5331,5 @@
 #if NH_3D_NBDV_REF
           TComPic* picDepth = NULL;
-          assert(getSlice()->getRefPic(eRefPicList, refId)->getPOC() == getSlice()->getPOC());          
+          assert(getSlice()->getRefPic(eRefPicList, refId)->getPOC() == getSlice()->getPOC());            
 #if H_3D_FCO_VSP_DONBDV_E0163
           picDepth  = getSlice()->getIvPic(true, getSlice()->getViewIndex() );
@@ -5627,5 +5674,5 @@
     if(!m_pcSlice->getIsDepth())
     {
-#if H_3D_DBBP || NH_3D_ALIGN_SPIVMP_DBBP
+#if NH_3D_DBBP
       if (!getDBBPFlag(0))
 #else
@@ -5803,5 +5850,5 @@
       iCurrPosY  += ( iHeight >> 1 );
     }
-#if H_3D_DBBP || NH_3D_ALIGN_SPIVMP_DBBP
+#if NH_3D_DBBP
     for(Int iLoopCan = ( (m_pcSlice->getIsDepth() || getDBBPFlag(0)) ? 0 : 1 ); iLoopCan < ( 2 - m_pcSlice->getIsDepth() ); iLoopCan ++) 
 #else
@@ -5878,5 +5925,5 @@
     }
 #if NH_3D_SPIVMP
-#if H_3D_DBBP || NH_3D_ALIGN_SPIVMP_DBBP
+#if NH_3D_DBBP
     for(Int iLoopCan = ( (m_pcSlice->getIsDepth() || getDBBPFlag(0)) ? 0 : 1 ); iLoopCan < ( 2 - m_pcSlice->getIsDepth() ); iLoopCan ++)
 #else
Index: trunk/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComDataCU.h	(revision 1314)
+++ trunk/source/Lib/TLibCommon/TComDataCU.h	(revision 1321)
@@ -601,4 +601,5 @@
 #if NH_3D
   Void          compressMV            ( Int scale );
+  Void          printMV               ( );
 #else            
   Void          compressMV            ();
@@ -644,5 +645,5 @@
 
   Bool          hasEqualMotion              ( UInt uiAbsPartIdx, TComDataCU* pcCandCU, UInt uiCandAbsPartIdx );
-#if NH_3D_FIX_PRUNING
+#if NH_3D
   Bool          hasEqualMotion              ( Int dirA, const TComMvField* mvFieldA,  Int dirB, const TComMvField* mvFieldB  );
 #endif
Index: trunk/source/Lib/TLibCommon/TComMotionInfo.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComMotionInfo.cpp	(revision 1314)
+++ trunk/source/Lib/TLibCommon/TComMotionInfo.cpp	(revision 1321)
@@ -44,5 +44,7 @@
 #include "TComPic.h"
 #endif
-
+#if NH_MV
+#include <iomanip>
+#endif
 //! \ingroup TLibCommon
 //! \{
@@ -377,3 +379,66 @@
   }
 }
+
+#if NH_MV
+Void TComCUMvField::print(Char* pePredMode)
+{
+  for ( Int uiPartIdx = 0; uiPartIdx < m_uiNumPartition; uiPartIdx += 1 )
+  {
+    PredMode predMode = static_cast<PredMode>( pePredMode[ uiPartIdx ] );
+
+    if ( predMode == MODE_INTRA)
+    {
+      std::cout << std::setfill(' ') << "(" 
+        << std::setw(3) <<  "   "    << ","
+        << std::setw(3) <<  "   "    << ","
+        << std::setw(3) <<  "   "    << ")";
+    }
+    else
+    {
+      ;
+      std::cout << std::setfill(' ') << "(" 
+        << std::setw(3) <<  (Int) m_piRefIdx[ uiPartIdx ]        << ","
+        << std::setw(3) <<  m_pcMv[ uiPartIdx ].getHor()   << ","
+        << std::setw(3) <<  m_pcMv[ uiPartIdx ].getVer()   << ")";
+    }    
+  }
+}
+
+#if NH_3D_MLC
+Void TComMotionCand::print( Int i )
+{
+  if (i == 0  )
+  {
+
+    std::cout << std::setfill(' ')                          << std::setw( 15 )
+      << "Num"                                              << std::setw( 15 )
+      << "Avai"                                             << std::setw( 15 )
+      << "Dir "                                             << std::setw( 15 )
+      <<  "L0 RefIdx"                                       << std::setw( 15 )
+      <<  "L0 Hor"                                          << std::setw( 15 )
+      <<  "L0 Ver"                                          << std::setw( 15 )
+      <<  "L1 RefIdx"                                       << std::setw( 15 )
+      <<  "L1 Hor"                                          << std::setw( 15 )
+      <<  "L1 Ver"                                          << std::setw( 15 )
+      << "VspFlag"                                          << std::setw( 15 )
+      << "SPIVMPFlag"                                       
+      << std::endl; 
+  }
+
+  std::cout << std::setfill(' ')                                  << std::setw( 15 )
+    << i                                                          << std::setw( 15 )
+    << m_bAvailable                                               << std::setw( 15 )
+    << (UInt) m_uDir                                              << std::setw( 15 )
+    << ((m_uDir & 1) ? m_cMvField[0].getRefIdx()       : MIN_INT) << std::setw( 15 )
+    << ((m_uDir & 1) ? m_cMvField[0].getMv().getHor()  : MIN_INT) << std::setw( 15 )
+    << ((m_uDir & 1) ? m_cMvField[0].getMv().getVer()  : MIN_INT) << std::setw( 15 )
+    << ((m_uDir & 2) ? m_cMvField[1].getRefIdx()       : MIN_INT) << std::setw( 15 )
+    << ((m_uDir & 2) ? m_cMvField[1].getMv().getHor()  : MIN_INT) << std::setw( 15 )
+    << ((m_uDir & 2) ? m_cMvField[1].getMv().getVer()  : MIN_INT) << std::setw( 15 )
+    << m_iVspFlag                                                 << std::setw( 15 )
+    << m_bSPIVMPFlag                                              << std::setw( 15 )
+    << std::endl;
+}
+#endif
+#endif
 //! \}
Index: trunk/source/Lib/TLibCommon/TComMotionInfo.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComMotionInfo.h	(revision 1314)
+++ trunk/source/Lib/TLibCommon/TComMotionInfo.h	(revision 1321)
@@ -43,4 +43,5 @@
 #include "CommonDef.h"
 #include "TComMv.h"
+
 //! \ingroup TLibCommon
 //! \{
@@ -188,4 +189,7 @@
   
   Void compress(Char* pePredMode, Int scale); 
+#if NH_MV
+  Void print   (Char* pePredMode);
+#endif
 };
 
@@ -281,5 +285,11 @@
 #endif
   }
+
+
+  Void print( Int i );
+
 };
+
+
 #endif
 
Index: trunk/source/Lib/TLibCommon/TComPic.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPic.cpp	(revision 1314)
+++ trunk/source/Lib/TLibCommon/TComPic.cpp	(revision 1321)
@@ -54,7 +54,4 @@
 , m_bReconstructed                        (false)
 , m_bNeededForOutput                      (false)
-#if NH_MV
-, m_bPicOutputFlag                        (false)
-#endif
 , m_uiCurrSliceIdx                        (0)
 , m_bCheckLTMSB                           (false)
@@ -62,4 +59,5 @@
 , m_layerId                               (0)
 , m_viewId                                (0)
+, m_bPicOutputFlag                        (false)
 #if NH_3D
 , m_viewIndex                             (0)
@@ -82,4 +80,16 @@
   m_eRapRefList       = REF_PIC_LIST_0;
   m_uiRapRefIdx       = 0;
+#endif
+#if NH_MV
+  m_isPocResettingPic = false;   
+  m_hasGeneratedRefPics = false; 
+  m_isFstPicOfAllLayOfPocResetPer = false; 
+  m_decodingOrder     = 0; 
+  m_noRaslOutputFlag  = false;  
+  m_noClrasOutputFlag = false; 
+  m_picLatencyCount   = 0; 
+  m_isGenerated       = false;
+  m_isGeneratedCl833  = false; 
+  m_activatesNewVps   = false; 
 #endif
 }
@@ -185,4 +195,5 @@
   }
 }
+
 
 Bool  TComPic::getSAOMergeAvailability(Int currAddr, Int mergeAddr)
@@ -231,100 +242,101 @@
 
 #if NH_MV
-Void TComPic::print( Bool legend )
-{
-  if ( legend )
-    std::cout  << std::endl << "LId"        << "\t" << "POC"   << "\t" << "Rec"          << "\t" << "Ref"                       << "\t" << "LT"            <<  "\t" << "OutMark" <<  "\t" << "OutFlag" << std::endl;
-  else
-    std::cout  << getLayerId() << "\t" << getPOC()<< "\t" << getReconMark() << "\t" << getSlice(0)->isReferenced() << "\t" << getIsLongTerm() << "\t" << getOutputMark() << "\t" << getSlice(0)->getPicOutputFlag() <<std::endl;
-}
-
-TComPic* TComPicLists::getPic( Int layerIdInNuh, Int poc )
-{
-  TComPic* pcPic = NULL;
-  for(TComList<TComList<TComPic*>*>::iterator itL = m_lists.begin(); ( itL != m_lists.end() && pcPic == NULL ); itL++)
-  {    
-    for(TComList<TComPic*>::iterator itP=(*itL)->begin(); ( itP!=(*itL)->end() && pcPic == NULL ); itP++)
-    {
-      TComPic* currPic = (*itP); 
-      if ( ( currPic->getPOC() == poc ) && ( currPic->getLayerId() == layerIdInNuh ) )
-      {
-        pcPic = currPic ;      
-      }
-    }
-  }
-  return pcPic;
+Bool TComPic::getPocResetPeriodId()
+{
+  return getSlice(0)->getPocResetIdc(); 
+}
+
+Void TComPic::markAsUsedForShortTermReference()
+{
+  getSlice(0)->setReferenced( true );
+  setIsLongTerm( false ); 
+}
+
+Void TComPic::markAsUsedForLongTermReference()
+{
+  getSlice(0)->setReferenced( true );
+  setIsLongTerm( true ); 
+}
+
+
+Void TComPic::markAsUnusedForReference()
+{
+  getSlice(0)->setReferenced( false );
+  setIsLongTerm( false ); 
+}
+
+
+Bool TComPic::getMarkedUnUsedForReference()
+{
+  return !getSlice(0)->isReferenced( );
+}
+
+
+Bool TComPic::getMarkedAsShortTerm()
+{
+  return ( getSlice(0)->isReferenced( ) && !getIsLongTerm() );
+}
+
+Void TComPic::print( Int outputLevel )
+{
+  if ( outputLevel== 0  )
+  {
+    std::cout  << std::endl 
+      << "LId"
+      << "\t" << "POC"
+      << "\t" << "Rec"
+      << "\t" << "Ref"
+      << "\t" << "LT"
+      << "\t" << "OutMark"
+      << "\t" << "OutFlag" 
+      << "\t" << "Type"
+      << "\t" << "PReFlag"
+      << std::endl;
+  }
+  else if( outputLevel == 1  )
+  {
+    std::cout  << getLayerId()
+      << "\t" << getPOC()
+      << "\t" << getReconMark()
+      << "\t" << getSlice(0)->isReferenced()
+      << "\t" << getIsLongTerm()
+      << "\t" << getOutputMark()
+      << "\t" << getSlice(0)->getPicOutputFlag()
+      << "\t" << getSlice(0)->getNalUnitTypeString()
+      << "\t" << getSlice(0)->getPocResetFlag() 
+      << std::endl;
+  }
+  else if ( outputLevel == 2  )
+  {
+    std::cout  << std:: setfill(' ')
+      << " LayerId: "         << std::setw(2) << getLayerId()
+      << "\t"  << " POC: "             << std::setw(5) << getPOC()
+      << "\t"  << " Dec. Order: "      << std::setw(5) << getDecodingOrder()
+      << "\t"  << " Referenced: "      << std::setw(1) << getSlice(0)->isReferenced()
+      << "\t"  << " Pic type: "        <<                 getSlice(0)->getNalUnitTypeString()
+      << "\t"  << " Generated: "       << std::setw(1) << getIsGenerated()
+      << "\t"  << " Gen. Ref. Pics: "  << std::setw(1) << getHasGeneratedRefPics();
+  }
+  else if ( outputLevel == 4  )
+  {
+    std::cout  << std:: setfill(' ')
+      << " LayerId: "         << std::setw(2) << getLayerId()
+      << "\t"  << " POC: "             << std::setw(5) << getPOC()      
+      << "\t"  << " Referenced: "      << std::setw(1) << getSlice(0)->isReferenced() << std::endl; 
+  }
 }
 
 #if NH_3D
-TComPic* TComPicLists::getPic( Int viewIndex, Bool depthFlag, Int poc )
-{
-  return getPic   ( m_vps->getLayerIdInNuh( viewIndex, depthFlag ), poc );
-}
-#endif
-Void TComPicLists::print()
-{
-  Bool first = true;     
-  for(TComList<TComList<TComPic*>*>::iterator itL = m_lists.begin(); ( itL != m_lists.end() ); itL++)
-  {    
-    for(TComList<TComPic*>::iterator itP=(*itL)->begin(); ( itP!=(*itL)->end() ); itP++)
-    {
-      if ( first )
-      {
-        (*itP)->print( true );       
-        first = false; 
-      }
-      (*itP)->print( false );       
-    }
-  }
-}
-
-TComPicYuv* TComPicLists::getPicYuv( Int layerIdInNuh, Int poc, Bool reconFlag )
-{
-  TComPic*    pcPic = getPic( layerIdInNuh, poc );
-  TComPicYuv* pcPicYuv = NULL;
-
-  if (pcPic != NULL)
-  {
-    if( reconFlag )
-    {
-      if ( pcPic->getReconMark() )
-      {
-        pcPicYuv = pcPic->getPicYuvRec();
-      }
-    }
-    else
-    {
-      pcPicYuv = pcPic->getPicYuvOrg();
-    }
-  };
-
-  return pcPicYuv;
-}
-
-#if NH_3D
-TComPicYuv* TComPicLists::getPicYuv( Int viewIndex, Bool depthFlag, Int poc, Bool recon )
-{  
-  Int layerIdInNuh = m_vps->getLayerIdInNuh( viewIndex, depthFlag ); 
-  return getPicYuv( layerIdInNuh, poc, recon );
-}
-#if NH_3D_ARP
-TComList<TComPic*>* TComPicLists::getPicList( Int layerIdInNuh )
-{
-  TComList<TComList<TComPic*>*>::iterator itL = m_lists.begin();
-  Int iLayer = 0;
-
-  assert( layerIdInNuh < m_lists.size() );
-
-  while( iLayer != layerIdInNuh )
-  {
-    itL++;
-    iLayer++;
-  }
-
-  return *itL;
-}
-#endif
-#endif
-#endif // NH_MV
+Void TComPic::printMotion()
+{
+  TComPicSym* pPicSym = getPicSym();
+  for ( UInt uiCUAddr = 0; uiCUAddr < pPicSym->getNumberOfCtusInFrame(); uiCUAddr++ )
+  {
+    TComDataCU* pCtu = pPicSym->getCtu(uiCUAddr);
+    std::cout << "CUAddr " << uiCUAddr << std::endl; 
+    pCtu->printMV();
+    std::cout << std::endl; 
+  }
+}
 
 #if NH_3D_NBDV 
@@ -437,5 +449,11 @@
           m_abTIVRINCurrRL[curCandPic][iColRefDir][iColRefIdx] = false;
           Int iColViewIdx    = pcCandColSlice->getViewIndex();
+#if H_3D_FIX_ARP_CHECK_NOT_IN_DPB
+          // The picture pcCandColSlice->getRefPic((RefPicList)iColRefDir, iColRefIdx) might not be in DPB anymore
+          // So don't access it directly.
+          Int iColRefViewIdx = pcCandColSlice->getVPS()->getViewOrderIdx( pcCandColSlice->getRefLayerId( (RefPicList)iColRefDir, iColRefIdx ) );       
+#else
           Int iColRefViewIdx = pcCandColSlice->getRefPic((RefPicList)iColRefDir, iColRefIdx)->getViewIndex();
+#endif
           if(iColViewIdx == iColRefViewIdx)
           {
@@ -487,7 +505,7 @@
         {
           if(pcCurrSlice->getRefPOC((RefPicList)iCurrRefDir, iCurrRefIdx ) == iTextRefPOC && 
-             pcCurrSlice->getRefPic((RefPicList)iCurrRefDir, iCurrRefIdx)->getViewIndex() == iTextRefViewId)
+            pcCurrSlice->getRefPic((RefPicList)iCurrRefDir, iCurrRefIdx)->getViewIndex() == iTextRefViewId)
           {  
-            m_aiTexToDepRef[iTextRefDir][iTextRefIdx] = iCurrRefIdx;
+            m_aiTexToDepRef[iTextRefDir][iTextRefIdx] = iCurrRefIdx;            
           }
         }
@@ -504,5 +522,494 @@
 }
 #endif
+#endif
+
+Void TComAu::setPicLatencyCount( Int picLatenyCount )
+{
+  for(TComList<TComPic*>::iterator itP= begin();  itP!= end(); itP++)
+  {      
+    (*itP)->setPicLatencyCount( picLatenyCount ); 
+  }
+}
+
+TComPic* TComAu::getPic( Int nuhLayerId )
+{
+  TComPic* pic = NULL; 
+  for(TComList<TComPic*>::iterator itP= begin(); ( itP!= end() && (pic == NULL) ); itP++)
+  {      
+    if ( (*itP)->getLayerId() == nuhLayerId )
+    {
+      pic = (*itP); 
+    }
+  }
+  return pic;
+}
+
+Void TComAu::addPic( TComPic* pic, Bool pocUnkown )
+{
+  if ( !empty() )
+  {
+    if (!pocUnkown)
+    {
+      assert( pic->getPOC()   == ( getPoc() ));
+    }      
+    pic->setPicLatencyCount( getPicLatencyCount() ); 
+
+    assert( getPic( pic->getLayerId() ) == NULL );
+
+    // Add sorted 
+    TComAu::iterator itP = begin(); 
+    Bool inserted = false; 
+    while( !inserted )
+    {
+      if ( ( itP == end()) || pic->getLayerId() < (*itP)->getLayerId() )
+      {
+        insert(itP, pic ); 
+        inserted = true; 
+      }
+      else
+      {
+        ++itP; 
+      }        
+    }      
+  } 
+  else
+  { 
+    pushBack( pic );      
+  }
+}
+
+Bool TComAu::containsPic( TComPic* pic )
+{
+  Bool isInList = false; 
+  for(TComList<TComPic*>::iterator itP= begin(); ( itP!= end() && (!isInList) ); itP++)
+  { 
+    isInList = isInList || ( pic == (*itP)); 
+  }
+  return isInList;
+}
+
+TComSubDpb::TComSubDpb( Int nuhLayerid )
+{
+  m_nuhLayerId = nuhLayerid;
+}
+
+TComPic* TComSubDpb::getPic( Int poc )
+{
+  TComPic* pic = NULL; 
+  for(TComList<TComPic*>::iterator itP= begin(); ( itP!= end() && (pic == NULL) ); itP++)
+  {      
+    if ( (*itP)->getPOC() == poc )
+    {
+      pic = (*itP); 
+    }
+  }
+  return pic;
+}
+
+TComPic* TComSubDpb::getPicFromLsb( Int pocLsb, Int maxPicOrderCntLsb )
+{
+  TComPic* pic = NULL; 
+  for(TComList<TComPic*>::iterator itP= begin(); ( itP!= end() && (pic == NULL) ); itP++)
+  {      
+    if ( ( (*itP)->getPOC() & ( maxPicOrderCntLsb - 1 ) ) == pocLsb )
+    {
+      pic = (*itP); 
+    }
+  }
+  return pic;
+}
+
+TComPic* TComSubDpb::getShortTermRefPic( Int poc )
+{
+  TComPic* pic = NULL; 
+  for(TComList<TComPic*>::iterator itP= begin(); ( itP!= end() && (pic == NULL) ); itP++)
+  {      
+    if ( (*itP)->getPOC() == poc && (*itP)->getMarkedAsShortTerm() )
+    {
+      pic = (*itP); 
+    }
+  }
+  return pic;
+}
+
+TComList<TComPic*> TComSubDpb::getPicsMarkedNeedForOutput()
+{
+  TComList<TComPic*> picsMarkedNeedForOutput; 
+
+  for(TComList<TComPic*>::iterator itP= begin();  itP!= end() ; itP++ )
+  {      
+    if ( (*itP)->getOutputMark() )
+    {
+      picsMarkedNeedForOutput.push_back( (*itP) );
+    }
+  }
+  return picsMarkedNeedForOutput;
+}
+
+Void TComSubDpb::markAllAsUnusedForReference()
+{
+  for(TComList<TComPic*>::iterator itP= begin();  itP!= end() ; itP++ )
+  {      
+    (*itP)->markAsUnusedForReference(); 
+  }
+}
+
+Void TComSubDpb::addPic( TComPic* pic )
+{
+  assert( pic != NULL ); 
+  assert( m_nuhLayerId == pic->getLayerId() || m_nuhLayerId == -1);      
+  if ( !empty() )
+  {
+    assert( getPic( pic->getPOC() ) == NULL ); // Don't add twice; assert( pic->getLayerId() == m_nuhLayerId );            
+
+    // Add sorted 
+    TComSubDpb::iterator itP = begin(); 
+    Bool inserted = false; 
+    while( !inserted )
+    {
+      if ( ( itP == end()) || pic->getPOC() < (*itP)->getPOC() )
+      {
+        insert(itP, pic ); 
+        inserted = true; 
+      }
+      else
+      {
+        ++itP; 
+      }        
+    }      
+  } 
+  else
+  { 
+    pushBack( pic );
+  }
+}
+
+Void TComSubDpb::removePics( std::vector<TComPic*> picToRemove )
+{
+  for (Int i = 0; i < picToRemove.size(); i++ )
+  {
+    if( picToRemove[i] != NULL)
+    {
+      remove( picToRemove[i] ); 
+    }
+  }
+}
+
+Bool TComSubDpb::areAllPicsMarkedNotNeedForOutput()
+{
+  return ( getPicsMarkedNeedForOutput().size() == 0 );
+}
+
+
+TComPicLists::~TComPicLists()
+{
+  emptyAllSubDpbs();
+  for(TComList<TComSubDpb*>::iterator itL = m_subDpbs.begin(); ( itL != m_subDpbs.end()); itL++)
+  {      
+    if ( (*itL) != NULL )
+    {
+      delete (*itL); 
+      (*itL) = NULL; 
+    }
+  }
+}
+
+Void TComPicLists::addNewPic( TComPic* pic )
+{
+  getSubDpb ( pic->getLayerId() , true )->addPic( pic ); 
+  getAu     ( pic->getPOC()     , true )->addPic( pic , false ); 
+  if ( m_printPicOutput )
+  {
+    std::cout << "  Add    picture: ";
+    pic->print( 2 );
+    std::cout << std::endl;
+  }
+}
+
+Void TComPicLists::removePic( TComPic* pic )
+{
+  if (pic != NULL)
+  {
+
+    TComSubDpb* curSubDpb = getSubDpb( pic->getLayerId(), false ); 
+    curSubDpb->remove( pic );
+
+    TComAu* curAu = getAu     ( pic->getPOC(), false );       
+
+    if (curAu != NULL)
+    {    
+      curAu->remove( pic );
+      // Remove AU when empty. 
+      if (curAu->empty() )
+      {
+        m_aus.remove( curAu ); 
+        delete curAu; 
+      }
+    }
+
+    if ( m_printPicOutput )
+    {
+      std::cout << "  Remove picture: ";
+      pic->print( 2 );
+      std::cout << std::endl;
+    }
+
+    pic->destroy();
+    delete pic; 
+  }
+}
+
+TComPic* TComPicLists::getPic( Int layerIdInNuh, Int poc )
+{
+  TComPic* pcPic = NULL;
+  TComSubDpb* subDpb = getSubDpb( layerIdInNuh, false ); 
+  if ( subDpb != NULL )
+  {
+    pcPic = subDpb->getPic( poc ); 
+  }
+  return pcPic;
+}
+
+TComPicYuv* TComPicLists::getPicYuv( Int layerIdInNuh, Int poc, Bool reconFlag )
+{
+  TComPic*    pcPic = getPic( layerIdInNuh, poc );
+  TComPicYuv* pcPicYuv = NULL;
+
+  if (pcPic != NULL)
+  {
+    if( reconFlag )
+    {
+      if ( pcPic->getReconMark() )
+      {
+        pcPicYuv = pcPic->getPicYuvRec();
+      }
+    }
+    else
+    {
+      pcPicYuv = pcPic->getPicYuvOrg();
+    }
+  };
+
+  return pcPicYuv;
+}
+
+TComSubDpb* TComPicLists::getSubDpb( Int nuhLayerId, Bool create )
+{
+  TComSubDpb* subDpb = NULL;
+  for(TComList<TComSubDpb*>::iterator itL = m_subDpbs.begin(); ( itL != m_subDpbs.end() && subDpb == NULL ); itL++)
+  {      
+    if ( (*itL)->getLayerId() == nuhLayerId )
+    {        
+      subDpb = (*itL); 
+    }
+  }  
+  if ( subDpb == NULL && create )
+  {
+    m_subDpbs.push_back( new TComSubDpb(nuhLayerId) ); 
+  }
+  return subDpb;
+}
+
+TComList<TComSubDpb*>* TComPicLists::getSubDpbs()
+{
+  return (&m_subDpbs);
+}
+
+TComAu* TComPicLists::addAu( Int poc )
+{
+  TComList<TComAu*>::iterator itA = m_aus.begin(); 
+
+  assert( getAu(poc, false) == NULL );
+  Bool inserted = false; 
+  while( !inserted)
+  {      
+    if ( ( itA == m_aus.end()) || poc < (*itA)->getPoc() )
+    {        
+      m_aus.insert(itA, new TComAu );        
+      inserted = true; 
+      --itA; 
+    }
+    else
+    {
+      ++itA; 
+    }
+  }
+  return (*itA);
+}
+
+TComAu* TComPicLists::getAu( Int poc, Bool create )
+{
+  TComAu* au = NULL;
+
+  for( TComList<TComAu*>::iterator itA = m_aus.begin(); ( itA != m_aus.end() && au == NULL ); itA++)
+  { 
+    if ( (*itA)->getPoc() == poc )
+    {        
+      au = (*itA); 
+    }
+  }  
+
+  if ( au == NULL && create )
+  {
+    au = addAu( poc ); 
+  }
+  return au;
+}
+
+TComList<TComAu*>* TComPicLists::getAus()
+{
+  return (&m_aus);
+}
+
+TComList<TComAu*> TComPicLists::getAusHavingPicsMarkedForOutput()
+{
+  TComList<TComAu*> ausHavingPicsForOutput; 
+  for(TComList<TComAu*>::iterator itA= m_aus.begin(); ( itA!=m_aus.end()); itA++)
+  {
+    Bool hasPicMarkedAsNeedForOutput = false;
+    for( TComAu::iterator itP= (*itA)->begin(); (itP!=(*itA)->end() && !hasPicMarkedAsNeedForOutput); itP++  )
+    {
+      if( (*itP)->getOutputMark() )
+      {
+        hasPicMarkedAsNeedForOutput = true; 
+      }
+    }
+    if (hasPicMarkedAsNeedForOutput)
+    {
+      ausHavingPicsForOutput.pushBack( (*itA) );
+    }
+  }
+  return ausHavingPicsForOutput;
+}
+
+Void TComPicLists::markSubDpbAsUnusedForReference( Int layerIdInNuh )
+{
+  TComSubDpb* subDpb = getSubDpb( layerIdInNuh, false ); 
+  markSubDpbAsUnusedForReference( *subDpb );
+}
+
+Void TComPicLists::markSubDpbAsUnusedForReference( TComSubDpb& subDpb )
+{
+  for(TComList<TComPic*>::iterator itP=subDpb.begin(); ( itP!=subDpb.end()); itP++)
+  {
+    (*itP)->markAsUnusedForReference(); 
+  }
+}
+
+Void TComPicLists::markAllSubDpbAsUnusedForReference()
+{
+  for(TComList<TComSubDpb*>::iterator itS= m_subDpbs.begin(); ( itS!=m_subDpbs.end()); itS++)
+  {
+    markSubDpbAsUnusedForReference( *(*itS) ); 
+  }
+}
+
+Void TComPicLists::decrementPocsInSubDpb( Int nuhLayerId, Int deltaPocVal )
+{
+  TComSubDpb* subDpb = getSubDpb( nuhLayerId, false ); 
+
+  for(TComSubDpb::iterator itP = subDpb->begin(); itP!=subDpb->end(); itP++)
+  {
+    TComPic* pic = (*itP); 
+    for (Int i = 0; i < pic->getNumAllocatedSlice(); i++)
+    {
+      TComSlice* slice = pic->getSlice(i);
+      slice->setPOC( slice->getPOC() - deltaPocVal ); 
+    }    
+  }
+}
+Void TComPicLists::emptyAllSubDpbs()
+{
+  emptySubDpbs( &m_subDpbs );
+}
+
+Void TComPicLists::emptySubDpbs( TComList<TComSubDpb*>* subDpbs )
+{
+  assert( subDpbs != NULL ); 
+  for( TComList<TComSubDpb*>::iterator itS = subDpbs->begin(); itS != subDpbs->end(); itS++ )
+  {
+    emptySubDpb( (*itS) ); 
+  }
+}
+
+Void TComPicLists::emptySubDpb( TComSubDpb* subDpb )
+{
+  if(subDpb != NULL)
+  {
+    while( !subDpb->empty() )
+    {
+      TComPic* curPic = *(subDpb->begin()); 
+      removePic( curPic ); 
+    }
+  }
+}
+
+Void TComPicLists::emptySubDpb( Int nuhLayerId )
+{
+  emptySubDpb( getSubDpb( nuhLayerId , false) );
+}
+
+Void TComPicLists::emptyNotNeedForOutputAndUnusedForRef()
+{
+  for(TComList<TComSubDpb*>::iterator itS= m_subDpbs.begin(); ( itS!=m_subDpbs.end()); itS++)
+  {
+    emptySubDpbNotNeedForOutputAndUnusedForRef( *(*itS) ); 
+  }
+}
+
+Void TComPicLists::emptySubDpbNotNeedForOutputAndUnusedForRef( Int layerId )
+{
+  TComSubDpb* subDpb = getSubDpb( layerId, false ); 
+  emptySubDpbNotNeedForOutputAndUnusedForRef( *subDpb );
+}
+
+Void TComPicLists::emptySubDpbNotNeedForOutputAndUnusedForRef( TComSubDpb subDpb )
+{
+  for(TComSubDpb::iterator itP= subDpb.begin(); ( itP!=subDpb.end()); itP++)
+  {
+    TComPic* pic = (*itP); 
+    if ( !pic->getOutputMark() && pic->getMarkedUnUsedForReference() )
+    {
+      removePic( pic ); 
+    }
+  }
+}
+
+Void TComPicLists::print()
+{
+  Bool first = true;     
+  for(TComList<TComSubDpb*>::iterator itL = m_subDpbs.begin(); ( itL != m_subDpbs.end() ); itL++)
+  {    
+    for(TComList<TComPic*>::iterator itP=(*itL)->begin(); ( itP!=(*itL)->end() ); itP++)
+    {
+      if ( first )
+      {
+        (*itP)->print( true );       
+        first = false; 
+      }
+      (*itP)->print( false );       
+    }
+  }
+}
+
+#if NH_3D
+TComPicYuv* TComPicLists::getPicYuv( Int viewIndex, Bool depthFlag, Int poc, Bool recon )
+{  
+  Int layerIdInNuh = m_vps->getLayerIdInNuh( viewIndex, depthFlag ); 
+  return getPicYuv( layerIdInNuh, poc, recon );
+}
+
+TComPic* TComPicLists::getPic( Int viewIndex, Bool depthFlag, Int poc )
+{
+  return getPic   ( m_vps->getLayerIdInNuh( viewIndex, depthFlag ), poc );
+}
+
+#endif
+
+#endif
+
+
 
 
 //! \}
+
Index: trunk/source/Lib/TLibCommon/TComPic.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPic.h	(revision 1314)
+++ trunk/source/Lib/TLibCommon/TComPic.h	(revision 1321)
@@ -54,4 +54,60 @@
 /// picture class (symbol + YUV buffers)
 
+
+
+#if NH_MV
+class TComPic; 
+
+class TComDecodedRps
+{
+public: 
+
+  TComDecodedRps()
+  {
+    m_refPicSetsCurr[0] = &m_refPicSetStCurrBefore;
+    m_refPicSetsCurr[1] = &m_refPicSetStCurrAfter ;
+    m_refPicSetsCurr[2] = &m_refPicSetLtCurr      ; 
+
+    m_refPicSetsLt  [0] = &m_refPicSetLtCurr      ; 
+    m_refPicSetsLt  [1] = &m_refPicSetLtFoll      ;
+
+    m_refPicSetsAll [0] = &m_refPicSetStCurrBefore;
+    m_refPicSetsAll [1] = &m_refPicSetStCurrAfter ;
+    m_refPicSetsAll [2] = &m_refPicSetStFoll      ;
+    m_refPicSetsAll [3] = &m_refPicSetLtCurr      ;
+    m_refPicSetsAll [4] = &m_refPicSetLtFoll      ;
+  };    
+
+  std::vector<Int>       m_pocStCurrBefore;
+  std::vector<Int>       m_pocStCurrAfter;
+  std::vector<Int>       m_pocStFoll;    
+  std::vector<Int>       m_pocLtCurr;
+  std::vector<Int>       m_pocLtFoll; 
+
+  Int                    m_numPocStCurrBefore;
+  Int                    m_numPocStCurrAfter;
+  Int                    m_numPocStFoll;
+  Int                    m_numPocLtCurr;
+  Int                    m_numPocLtFoll;
+
+  std::vector<TComPic*>  m_refPicSetStCurrBefore; 
+  std::vector<TComPic*>  m_refPicSetStCurrAfter; 
+  std::vector<TComPic*>  m_refPicSetStFoll; 
+  std::vector<TComPic*>  m_refPicSetLtCurr; 
+  std::vector<TComPic*>  m_refPicSetLtFoll;   
+
+  std::vector<TComPic*>* m_refPicSetsCurr[3];
+  std::vector<TComPic*>* m_refPicSetsLt  [2];
+  std::vector<TComPic*>* m_refPicSetsAll [5];
+
+  // Annex F
+  Int                    m_numActiveRefLayerPics0;
+  Int                    m_numActiveRefLayerPics1;     
+
+  std::vector<TComPic*>  m_refPicSetInterLayer0;
+  std::vector<TComPic*>  m_refPicSetInterLayer1;
+};
+#endif
+
 class TComPic
 {
@@ -72,7 +128,5 @@
   Bool                  m_bReconstructed;
   Bool                  m_bNeededForOutput;
-#if NH_MV
-  Bool                  m_bPicOutputFlag;         // Semantics variable 
-#endif
+
   UInt                  m_uiCurrSliceIdx;         // Index of current slice
   Bool                  m_bCheckLTMSB;
@@ -87,4 +141,17 @@
   Int                   m_layerId;
   Int                   m_viewId;
+  Bool                  m_bPicOutputFlag;                // Semantics variable 
+  Bool                  m_hasGeneratedRefPics; 
+  Bool                  m_isPocResettingPic; 
+  Bool                  m_isFstPicOfAllLayOfPocResetPer; 
+  Int64                 m_decodingOrder; 
+  Bool                  m_noRaslOutputFlag; 
+  Bool                  m_noClrasOutputFlag; 
+  Int                   m_picLatencyCount; 
+  Bool                  m_isGenerated;
+  Bool                  m_isGeneratedCl833; 
+  Bool                  m_activatesNewVps;
+  TComDecodedRps        m_decodedRps;
+#endif
 #if NH_3D
   Int                   m_viewIndex;
@@ -92,17 +159,15 @@
   Int**                 m_aaiCodedScale;
   Int**                 m_aaiCodedOffset;
-#endif
-#endif
 #if NH_3D_QTLPC
   Bool                  m_bReduceBitsQTL;
 #endif
 #if NH_3D_NBDV
-  UInt        m_uiRapRefIdx;
-  RefPicList  m_eRapRefList;
-  Int         m_iNumDdvCandPics;
-  Bool        m_abTIVRINCurrRL [2][2][MAX_NUM_REF]; //whether an inter-view reference picture with the same view index of the inter-view reference picture of temporal reference picture of current picture exists in current reference picture lists
-  Int         m_aiTexToDepRef  [2][MAX_NUM_REF];
-#endif
-
+  UInt                   m_uiRapRefIdx;
+  RefPicList             m_eRapRefList;
+  Int                    m_iNumDdvCandPics;
+  Bool                   m_abTIVRINCurrRL [2][2][MAX_NUM_REF]; //whether an inter-view reference picture with the same view index of the inter-view reference picture of temporal reference picture of current picture exists in current reference picture lists
+  Int                    m_aiTexToDepRef  [2][MAX_NUM_REF];
+#endif
+#endif
 public:
   TComPic();
@@ -115,25 +180,4 @@
   UInt          getTLayer() const               { return m_uiTLayer;   }
   Void          setTLayer( UInt uiTLayer ) { m_uiTLayer = uiTLayer; }
-#if NH_MV
-  Void          setLayerId            ( Int layerId )    { m_layerId      = layerId; }
-  Int           getLayerId            ()                 { return m_layerId;    }
-  Void          setViewId             ( Int viewId )     { m_viewId = viewId;   }
-  Int           getViewId             ()                 { return m_viewId;     }
-#if NH_3D
-  Void          setViewIndex          ( Int viewIndex )  { m_viewIndex = viewIndex;   }
-  Int           getViewIndex          ()                 { return m_viewIndex;     }
-
-  Void          setIsDepth            ( Bool isDepth )   { m_isDepth = isDepth; }
-  Bool          getIsDepth            ()                 { return m_isDepth; }
-
-  Void          setScaleOffset( Int** pS, Int** pO )  { m_aaiCodedScale = pS; m_aaiCodedOffset = pO; }
-  Int**         getCodedScale ()                      { return m_aaiCodedScale;  }
-  Int**         getCodedOffset()                      { return m_aaiCodedOffset; }
-#endif
-#endif
-#if NH_3D_QTLPC
-  Bool          getReduceBitsFlag ()             { return m_bReduceBitsQTL;     }
-  Void          setReduceBitsFlag ( Bool bFlag ) { m_bReduceBitsQTL = bFlag;    }
-#endif
 
   Bool          getUsedByCurr() const            { return m_bUsedByCurr; }
@@ -177,14 +221,6 @@
   Void          setOutputMark (Bool b) { m_bNeededForOutput = b;     }
   Bool          getOutputMark () const      { return m_bNeededForOutput;  }
- #if NH_MV
-  Void          setPicOutputFlag(Bool b) { m_bPicOutputFlag = b;      }
-  Bool          getPicOutputFlag()       { return m_bPicOutputFlag ;  }
-#endif
-#if NH_3D
-#if NH_3D_ARP
-  Void          getCUAddrAndPartIdx( Int iX, Int iY, Int& riCuAddr, Int& riAbsZorderIdx );
-#endif
-  Void          compressMotion(Int scale); 
-#else   
+
+#if !NH_3D
   Void          compressMotion();
 #endif
@@ -210,18 +246,102 @@
 
 #if NH_MV
-  Void          print( Bool legend );
+   Void          setLayerId            ( Int layerId )    { m_layerId      = layerId; }
+   Int           getLayerId            ()                 { return m_layerId;    }
+   
+   Void          setViewId             ( Int viewId )     { m_viewId = viewId;   }
+   Int           getViewId             ()                 { return m_viewId;     }
+
+   Void          setPicOutputFlag(Bool b)                 { m_bPicOutputFlag = b;      }
+   Bool          getPicOutputFlag()                       { return m_bPicOutputFlag ;  }
+
+   Bool          getPocResetPeriodId();
+
+   Void          markAsUsedForShortTermReference();
+   Void          markAsUsedForLongTermReference(); 
+   Void          markAsUnusedForReference(); 
+
+   Bool          getMarkedUnUsedForReference();
+   Bool          getMarkedAsShortTerm();
+
+   Void          setHasGeneratedRefPics(Bool val)       { m_hasGeneratedRefPics  = val;    }
+   Bool          getHasGeneratedRefPics( )              { return m_hasGeneratedRefPics;   }
+
+   Void          setIsPocResettingPic(Bool val)         { m_isPocResettingPic = val;    }
+   Bool          getIsPocResettingPic( )                { return m_isPocResettingPic;   }
+
+   Void          setIsFstPicOfAllLayOfPocResetPer(Bool val) { m_isFstPicOfAllLayOfPocResetPer = val;  }
+   Bool          getIsFstPicOfAllLayOfPocResetPer( )        { return m_isFstPicOfAllLayOfPocResetPer; }
+
+   Int64         getDecodingOrder( )                    { return m_decodingOrder;       }
+   Void          setDecodingOrder( UInt64 val  )        { m_decodingOrder = val;        }
+
+   Bool          getNoRaslOutputFlag()                  { return m_noRaslOutputFlag;     }
+   Void          setNoRaslOutputFlag( Bool b )          { m_noRaslOutputFlag = b;        }
+
+   Bool          getNoClrasOutputFlag()                 { return m_noClrasOutputFlag;    }
+   Void          setNoClrasOutputFlag( Bool b )         { m_noClrasOutputFlag = b;       }
+
+   Int           getPicLatencyCount()                   { return m_picLatencyCount;      }
+   Void          setPicLatencyCount( Int val )          { m_picLatencyCount = val;       }
+
+   Bool          getIsGenerated() const                 { return m_isGenerated;          }
+   Void          setIsGenerated( Bool b )               { m_isGenerated = b;             }
+
+   Bool          getIsGeneratedCl833() const            { return m_isGeneratedCl833;     }
+   Void          setIsGeneratedCl833( Bool b )          { m_isGeneratedCl833 = b;        }
+
+   Int           getTemporalId( )                       { return getSlice(0)->getTemporalId(); }
+
+   Bool          getActivatesNewVps()                   { return m_activatesNewVps;      }
+   Void          setActivatesNewVps( Bool b )           { m_activatesNewVps = b;         }
+
+   TComDecodedRps* getDecodedRps()                      { return &m_decodedRps;          }
+
+   Bool          isIrap()                               { return getSlice(0)->isIRAP(); } 
+   Bool          isBla ()                               { return getSlice(0)->isBla (); } 
+   Bool          isIdr ()                               { return getSlice(0)->isIdr (); } 
+   Bool          isCra ()                               { return getSlice(0)->isCra (); } 
+   Bool          isSlnr ()                              { return getSlice(0)->isSlnr (); }
+   Bool          isRasl ()                              { return getSlice(0)->isRasl (); }
+   Bool          isRadl ()                              { return getSlice(0)->isRadl (); }
+   Bool          isStsa ()                              { return getSlice(0)->isStsa (); }
+   Bool          isTsa ()                               { return getSlice(0)->isTsa  (); }
+
+   Void          print( Int outputLevel );
+
+#if NH_3D
+   Void          setViewIndex          ( Int viewIndex )  { m_viewIndex = viewIndex;   }
+   Int           getViewIndex          ()                 { return m_viewIndex;     }
+
+   Void          setIsDepth            ( Bool isDepth )   { m_isDepth = isDepth; }
+   Bool          getIsDepth            ()                 { return m_isDepth; }
+
+   Void          setScaleOffset( Int** pS, Int** pO )     { m_aaiCodedScale = pS; m_aaiCodedOffset = pO; }
+   Int**         getCodedScale ()                         { return m_aaiCodedScale;  }
+   Int**         getCodedOffset()                         { return m_aaiCodedOffset; }
+
+   Void          compressMotion(Int scale); 
+   Void          printMotion( );
+#if NH_3D_ARP
+   Void          getCUAddrAndPartIdx( Int iX, Int iY, Int& riCuAddr, Int& riAbsZorderIdx );
+#endif
+#if NH_3D_QTLPC
+   Bool          getReduceBitsFlag ()                     { return m_bReduceBitsQTL;     }
+   Void          setReduceBitsFlag ( Bool bFlag )         { m_bReduceBitsQTL = bFlag;    }
 #endif
 #if NH_3D_NBDV
-  Int           getNumDdvCandPics()                    {return m_iNumDdvCandPics;   }
-  Int           getDisCandRefPictures(Int iColPOC);
-  Void          setRapRefIdx(UInt uiRapRefIdx)         {m_uiRapRefIdx = uiRapRefIdx;}
-  Void          setRapRefList(RefPicList eRefPicList)  {m_eRapRefList = eRefPicList;}
-  Void          setNumDdvCandPics (Int i)              {m_iNumDdvCandPics = i;       }
-  UInt          getRapRefIdx()                         {return m_uiRapRefIdx;       }
-  RefPicList    getRapRefList()                        {return m_eRapRefList;       }
-  Void          checkTemporalIVRef();
-  Bool          isTempIVRefValid(Int currCandPic, Int iTempRefDir, Int iTempRefIdx);
-  Void          checkTextureRef(  );
-  Int           isTextRefValid(Int iTextRefDir, Int iTextRefIdx);
+  Int            getNumDdvCandPics()                      { return m_iNumDdvCandPics;    }
+  Int            getDisCandRefPictures(Int iColPOC);        
+  Void           setRapRefIdx(UInt uiRapRefIdx)           { m_uiRapRefIdx = uiRapRefIdx; }
+  Void           setRapRefList(RefPicList eRefPicList)    { m_eRapRefList = eRefPicList; }
+  Void           setNumDdvCandPics (Int i)                { m_iNumDdvCandPics = i;       }
+  UInt           getRapRefIdx()                           { return m_uiRapRefIdx;        }
+  RefPicList     getRapRefList()                          { return m_eRapRefList;        }
+  Void           checkTemporalIVRef();                     
+  Bool           isTempIVRefValid(Int currCandPic, Int iTempRefDir, Int iTempRefIdx);
+  Void           checkTextureRef(  );
+  Int            isTextRefValid(Int iTextRefDir, Int iTextRefIdx);
+#endif
+#endif
 #endif
 
@@ -241,30 +361,102 @@
 
 #if NH_MV
+
+class TComAu : public TComList<TComPic*>
+{
+  
+public:
+
+  Int                 getPoc            ( )                     {  assert(!empty()); return back()->getPOC            ();  }
+  Void                setPicLatencyCount( Int picLatenyCount );
+  Int                 getPicLatencyCount( )                     {  assert(!empty()); return back()->getPicLatencyCount();  }  
+  TComPic*            getPic            ( Int nuhLayerId  );
+  Void                addPic            ( TComPic* pic, Bool pocUnkown );
+  Bool                containsPic       ( TComPic* pic );  
+};
+
+
+class TComSubDpb : public TComList<TComPic*>
+{
+private: 
+  Int m_nuhLayerId; 
+public:  
+  TComSubDpb( Int nuhLayerid );
+
+  Int                 getLayerId                      ( ) { return m_nuhLayerId; }
+
+  TComPic*            getPic                          ( Int poc  );
+  TComPic*            getPicFromLsb                   ( Int pocLsb, Int maxPicOrderCntLsb );
+  TComPic*            getShortTermRefPic              ( Int poc  );
+  TComList<TComPic*>  getPicsMarkedNeedForOutput      ( );
+
+  Void                markAllAsUnusedForReference     ( );
+
+  Void                addPic                          ( TComPic* pic );
+  Void                removePics                      ( std::vector<TComPic*> picToRemove );
+  Bool                areAllPicsMarkedNotNeedForOutput( );
+};
+
 class TComPicLists 
 {
 private: 
-  TComList<TComList<TComPic*>*> m_lists; 
-#if NH_3D
-  const TComVPS*                     m_vps; 
+  TComList<TComAu*    >       m_aus;  
+  TComList<TComSubDpb*>       m_subDpbs; 
+  Bool                        m_printPicOutput; 
+#if NH_3D                     
+  const TComVPS*              m_vps; 
 #endif
 public: 
-  Void        push_back( TComList<TComPic*>* list ) { m_lists.push_back( list );   }
-  Int         size     ()                           { return (Int) m_lists.size(); } 
-#if NH_3D_ARP
-  TComList<TComPic*>*  getPicList   ( Int layerIdInNuh );
-#endif
-  TComPic*    getPic   ( Int layerIdInNuh,              Int poc );    
-  TComPicYuv* getPicYuv( Int layerIdInNuh,              Int poc, Bool recon ); 
-#if NH_3D
-  Void        setVPS   ( const TComVPS* vps ) { m_vps = vps;  }; 
-  TComPic*    getPic   ( Int viewIndex, Bool depthFlag, Int poc );
-  TComPicYuv* getPicYuv( Int viewIndex, Bool depthFlag, Int poc, Bool recon );
+  TComPicLists() { m_printPicOutput = false; };
+  ~TComPicLists();
+
+  // Add and remove single pictures
+  Void                   addNewPic( TComPic* pic );
+  Void                   removePic( TComPic* pic );
+
+  // Get Pics
+  TComPic*               getPic                         ( Int layerIdInNuh, Int poc );
+  TComPicYuv*            getPicYuv                      ( Int layerIdInNuh, Int poc, Bool recon );
+
+  // Get and AUs and SubDPBs
+  TComSubDpb*            getSubDpb                      ( Int nuhLayerId, Bool create );
+  TComList<TComSubDpb*>* getSubDpbs                     ( );
+                                                        
+  TComAu*                addAu                          ( Int poc  );
+  TComAu*                getAu                          ( Int poc, Bool create );
+  TComList<TComAu*>*     getAus                         ( );
+  TComList<TComAu*>      getAusHavingPicsMarkedForOutput( );
+
+  // Mark pictures and set POCs
+  Void                   markSubDpbAsUnusedForReference ( Int layerIdInNuh );
+  Void                   markSubDpbAsUnusedForReference ( TComSubDpb& subDpb );
+  Void                   markAllSubDpbAsUnusedForReference(  );
+  Void                   decrementPocsInSubDpb          ( Int nuhLayerId, Int deltaPocVal );
+  
+  // Empty Sub DPBs
+  Void                   emptyAllSubDpbs                ( );
+  Void                   emptySubDpbs                   ( TComList<TComSubDpb*>* subDpbs);
+  Void                   emptySubDpb                    ( TComSubDpb* subDpb);
+  Void                   emptySubDpb                    ( Int nuhLayerId );
+
+  Void                   emptyNotNeedForOutputAndUnusedForRef      ( );
+  Void                   emptySubDpbNotNeedForOutputAndUnusedForRef( Int layerId  );
+  Void                   emptySubDpbNotNeedForOutputAndUnusedForRef( TComSubDpb subDpb );  
+
+  // For printing to std::out 
+  Void                   setPrintPicOutput ( Bool printPicOutput ) { m_printPicOutput = printPicOutput; };
+  Void                   print(); 
+
+#if NH_3D                                   
+  Void                   setVPS                        ( const TComVPS* vps ) { m_vps = vps;  }; 
+  TComPic*               getPic                        ( Int viewIndex, Bool depthFlag, Int poc );
+  TComPicYuv*            getPicYuv                     ( Int viewIndex, Bool depthFlag, Int poc, Bool recon );
 #endif  
 
-  Void print( );  
-
-}; // END CLASS DEFINITION TComPicLists
-
-#endif 
+}; 
+
+// END CLASS DEFINITION TComPicLists
+
+#endif
+
 
 //! \}
Index: trunk/source/Lib/TLibCommon/TComPicYuv.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPicYuv.h	(revision 1314)
+++ trunk/source/Lib/TLibCommon/TComPicYuv.h	(revision 1321)
@@ -166,4 +166,7 @@
   // Set border extension flag
   Void          setBorderExtension(Bool b) { m_bIsBorderExtended = b; }
+#if NH_MV
+  Bool          getBorderExtension( )     { return m_bIsBorderExtended; }
+#endif
 #if NH_3D
   // Set Function 
Index: trunk/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 1314)
+++ trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 1321)
@@ -562,4 +562,17 @@
       Int RefPOCL0 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr))->getPOC();
       Int RefPOCL1 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_1, pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr))->getPOC();
+#if NH_MV_FIX_TICKET_106
+#if NH_MV
+      Int layerIdL0 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_0, pcCU->getCUMvField(REF_PIC_LIST_0)->getRefIdx(PartAddr))->getLayerId();
+      Int layerIdL1 = pcCU->getSlice()->getRefPic(REF_PIC_LIST_1, pcCU->getCUMvField(REF_PIC_LIST_1)->getRefIdx(PartAddr))->getLayerId();
+#if NH_3D_ARP
+      if(!pcCU->getARPW(PartAddr) && RefPOCL0 == RefPOCL1 && layerIdL0 == layerIdL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr))
+#else
+      if(RefPOCL0 == RefPOCL1 && layerIdL0 == layerIdL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr))
+#endif
+#else
+      if(RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr))
+#endif
+#else
 #if NH_3D_ARP
       if(!pcCU->getARPW(PartAddr) && RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr))
@@ -567,4 +580,5 @@
       if(RefPOCL0 == RefPOCL1 && pcCU->getCUMvField(REF_PIC_LIST_0)->getMv(PartAddr) == pcCU->getCUMvField(REF_PIC_LIST_1)->getMv(PartAddr))
 #endif
+#endif
       {
         return true;
@@ -584,5 +598,5 @@
     pcCU->getSPAbsPartIdx(uiPartAddr, iSPWidth, iSPHeight, i, iNumSPInOneLine, uiSPAddr[i]);
   }
-#if H_3D_ARP || NH_3D_ALIGN_SPIVMP_RP // check this!
+#if NH_3D_ARP
   if( pcCU->getARPW( uiPartAddr ) != 0 )
   {
@@ -1302,4 +1316,15 @@
   TComMv      cMv         = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
   pcCU->clipMv(cMv);
+
+#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC
+  if ( g_traceMotionInfoBeforUniPred  )
+  {
+    std::cout << "RefPic POC     : " << pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()     << std::endl; 
+    std::cout << "RefPic Layer Id: " << pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getLayerId() << std::endl; 
+    std::cout << "RefIdx         : " << iRefIdx                                                           << std::endl; 
+    std::cout << "RefPIcList     : " << eRefPicList                                                        << std::endl; 
+  }
+#endif
+
 #if NH_MV
   pcCU->checkMvVertRest(cMv, eRefPicList, iRefIdx );
@@ -1309,20 +1334,21 @@
   {
     if( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()== pcCU->getSlice()->getPOC() )
-  {
+    {
       xPredInterUniARPviewRef( pcCU , uiPartAddr , iWidth , iHeight , eRefPicList , pcYuvPred , bi ); 
-  }
-  else
-  {
+    }
+    else
+    {
       xPredInterUniARP( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, bi );
     }      
-    }
-    else
-    {
-#endif
-  for (UInt comp=COMPONENT_Y; comp<pcYuvPred->getNumberValidComponents(); comp++)
-  {
-    const ComponentID compID=ComponentID(comp);
+  }
+  else
+  {
+#endif
+
+    for (UInt comp=COMPONENT_Y; comp<pcYuvPred->getNumberValidComponents(); comp++)
+    {
+      const ComponentID compID=ComponentID(comp);
 #if NH_3D_IC
-    Bool bICFlag = pcCU->getICFlag( uiPartAddr ) && ( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getViewIndex() != pcCU->getSlice()->getViewIndex() ) && ( isLuma(compID) || (iWidth > 8) );
+      Bool bICFlag = pcCU->getICFlag( uiPartAddr ) && ( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getViewIndex() != pcCU->getSlice()->getViewIndex() ) && ( isLuma(compID) || (iWidth > 8) );
       xPredInterBlk(compID,  pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, pcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID))
 #if NH_3D_ARP
@@ -1331,7 +1357,7 @@
         , bICFlag );
 #else
-    xPredInterBlk  (compID,  pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, pcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)) );
-#endif
-  }
+      xPredInterBlk  (compID,  pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, pcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)) );
+#endif
+    }
 #if NH_3D_ARP
   }
@@ -1813,4 +1839,7 @@
 )
 {
+#if NH_MV
+  assert( refPic->getBorderExtension() ); 
+#endif
   Int     refStride  = refPic->getStride(compID);
   Int     dstStride  = dstPic->getStride(compID);
Index: trunk/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPrediction.h	(revision 1314)
+++ trunk/source/Lib/TLibCommon/TComPrediction.h	(revision 1321)
@@ -176,7 +176,7 @@
   Void          combineSegmentsWithMask( TComYuv* pInYuv[2], TComYuv* pOutYuv, Bool* pMask, UInt uiWidth, UInt uiHeight, UInt uiPartAddr, UInt partSize, Int bitDepthY );
 #endif
-
+#if NH_3D
   Pel  predIntraGetPredValDC      ( const Pel* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight, Bool bAbove, Bool bLeft );
-
+#endif
   Pel*  getPredictorPtr           ( const ComponentID compID, const Bool bUseFilteredPredictions )
   {
Index: trunk/source/Lib/TLibCommon/TComRdCost.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComRdCost.cpp	(revision 1314)
+++ trunk/source/Lib/TLibCommon/TComRdCost.cpp	(revision 1321)
@@ -133,5 +133,7 @@
   }
 
+#if NH_MV
   D_PRINT_INDENT( g_traceRDCost,  "Dist: " + n2s(uiDistortion) + " Bits: " + n2s(uiBits) + " RD Cost: " + n2s(dRdCost)); 
+#endif
   return dRdCost;
 }
@@ -603,7 +605,5 @@
   cDtParam.bitDepth   = bitDepth;
 
-#if NH_3D_IC_FIX
   cDtParam.bUseIC       = false;
-#endif
 #if NH_3D_SDC_INTER
   cDtParam.bUseSDCMRSAD = false;
@@ -3685,5 +3685,7 @@
   }
 
+#if NH_MV
   D_PRINT_INDENT( g_traceRDCost, "VSO Dist: " + n2s(uiDistortion) + " Bits: " + n2s(uiBits) + " RD Cost: " + n2s(dRdCost)); 
+#endif
 
   return dRdCost;
Index: trunk/source/Lib/TLibCommon/TComRom.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComRom.cpp	(revision 1314)
+++ trunk/source/Lib/TLibCommon/TComRom.cpp	(revision 1321)
@@ -222,9 +222,9 @@
 #if NH_MV
 #if H_MV_HLS_PTL_LIMITS 
- g_generalTierAndLevelLimits[ Level::LEVEL1   ] = TComGeneralTierAndLevelLimits(    36864,     350,  INT_MIN,   16,   1,   1 );
- g_generalTierAndLevelLimits[ Level::LEVEL2   ] = TComGeneralTierAndLevelLimits(   122880,    1500,  INT_MIN,   16,   1,   1 );
- g_generalTierAndLevelLimits[ Level::LEVEL2_1 ] = TComGeneralTierAndLevelLimits(   245760,    3000,  INT_MIN,   20,   1,   1 );
- g_generalTierAndLevelLimits[ Level::LEVEL3   ] = TComGeneralTierAndLevelLimits(   552960,    6000,  INT_MIN,   30,   2,   2 );
- g_generalTierAndLevelLimits[ Level::LEVEL3_1 ] = TComGeneralTierAndLevelLimits(   983040,   10000,  INT_MIN,   40,   3,   3 );
+ g_generalTierAndLevelLimits[ Level::LEVEL1   ] = TComGeneralTierAndLevelLimits(    36864,     350,  MIN_INT,   16,   1,   1 );
+ g_generalTierAndLevelLimits[ Level::LEVEL2   ] = TComGeneralTierAndLevelLimits(   122880,    1500,  MIN_INT,   16,   1,   1 );
+ g_generalTierAndLevelLimits[ Level::LEVEL2_1 ] = TComGeneralTierAndLevelLimits(   245760,    3000,  MIN_INT,   20,   1,   1 );
+ g_generalTierAndLevelLimits[ Level::LEVEL3   ] = TComGeneralTierAndLevelLimits(   552960,    6000,  MIN_INT,   30,   2,   2 );
+ g_generalTierAndLevelLimits[ Level::LEVEL3_1 ] = TComGeneralTierAndLevelLimits(   983040,   10000,  MIN_INT,   40,   3,   3 );
  g_generalTierAndLevelLimits[ Level::LEVEL4   ] = TComGeneralTierAndLevelLimits(  2228224,   12000,    30000,   75,   5,   5 );
  g_generalTierAndLevelLimits[ Level::LEVEL4_1 ] = TComGeneralTierAndLevelLimits(  2228224,   20000,    50000,   75,   5,   5 );
@@ -546,13 +546,13 @@
 Bool g_disableNumbering = false; 
 Bool g_disableHLSTrace = false; 
-UInt64 g_stopAtCounter         = 4660; 
-Bool g_traceCopyBack           = false; 
-Bool g_decTraceDispDer         = false; 
-Bool g_decTraceMvFromMerge     = false; 
-Bool g_decTracePicOutput       = false; 
+UInt64 g_stopAtCounter       = 4660; 
+Bool g_traceCopyBack         = false; 
+Bool g_decTraceDispDer       = false; 
+Bool g_decTraceMvFromMerge   = false; 
+Bool g_decTracePicOutput     = false; 
 Bool g_startStopTrace          = false; 
-Bool g_outputPos               = false;
-Bool g_traceCameraParameters   = false; 
-Bool g_encNumberOfWrittenBits  = false; 
+Bool g_outputPos             = false;   
+Bool g_traceCameraParameters = false; 
+Bool g_encNumberOfWrittenBits     = false; 
 Bool g_traceEncFracBits        = false; 
 Bool g_traceIntraSearchCost    = false; 
@@ -561,4 +561,9 @@
 Bool g_traceModeCheck          = false; 
 UInt g_indent                  = false; 
+Bool g_decNumBitsRead          = false; 
+Bool g_traceMotionInfoBeforUniPred = false; 
+Bool g_traceMergeCandListConst = false; 
+Bool g_traceBitsRead          = false; 
+Bool g_traceSubPBMotion       = false; 
 #endif
 #endif
@@ -693,7 +698,7 @@
   Bool startTrace = false; 
   if ( g_startStopTrace && poc == 0 && layerId == 0 )
-  {    
+  {
     startTrace = ( cuPelX  == 0 ) && ( cuPelY  == 0 ) && ( cuWidth == 64 ) && ( cuHeight == 64 ); 
-  }
+    }
   if ( startTrace )
   { 
@@ -705,5 +710,5 @@
     g_traceModeCheck         = true; 
     g_traceCopyBack          = false; 
-  }  
+    }
   Bool stopTrace = false; 
   if ( g_startStopTrace && poc == 0 && layerId == 0 )
Index: trunk/source/Lib/TLibCommon/TComRom.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComRom.h	(revision 1314)
+++ trunk/source/Lib/TLibCommon/TComRom.h	(revision 1321)
@@ -91,8 +91,8 @@
 extern const UChar  g_aucIntraModeNumFast_NotUseMPM[MAX_CU_DEPTH];
 extern const UChar  g_chroma422IntraAngleMappingTable[NUM_INTRA_MODE];
+#if NH_3D_DMM
 // ====================================================================================================================
 // Depth coding modes
 // ====================================================================================================================
-#if NH_3D_DMM
 extern const WedgeResolution                                 g_dmmWedgeResolution [6];
 extern const UChar                                           g_dmm1TabIdxBits     [6];
@@ -193,4 +193,8 @@
  extern Bool   g_traceSAOCost; 
  extern UInt   g_indent; 
+extern Bool   g_traceMotionInfoBeforUniPred; 
+ extern Bool   g_traceMergeCandListConst; 
+ extern Bool   g_traceSubPBMotion; 
+ extern Bool   g_traceBitsRead;
 #define DTRACE_CU(x,y)             writeToTraceFile( x,y, g_traceCU );
 #define DTRACE_PU(x,y)             writeToTraceFile( x,y, g_tracePU );
@@ -199,9 +203,7 @@
 #define DTRACE_PU_S(x)             writeToTraceFile( x,   g_tracePU );
 #define DTRACE_TU_S(x)             writeToTraceFile( x,   g_traceTU );
-
 #define D_DEC_INDENT( b )            decIndent        ( b );
 #define D_PRINT_INC_INDENT( b, str ) prinStrIncIndent( b, str );
 #define D_PRINT_INDENT( b, str )     printStrIndent   ( b, str);
-
  Void           tracePSHeader   ( const Char* psName, Int layerId ); 
  Void           writeToTraceFile( const Char* symbolName, Int val, Bool doIt );
@@ -209,10 +211,8 @@
  UInt64         incSymbolCounter();          
  Void           stopAtPos       ( Int poc, Int layerId, Int cuPelX, Int cuPelY, Int cuWidth, Int cuHeight );           
-
  Void           printStr         ( std::string str );
  Void           printStrIndent   ( Bool b, std::string str );
  Void           prinStrIncIndent ( Bool b, std::string str );
  Void           decIndent        ( Bool b );
-
  template <typename T>
  std::string n2s ( T Number )
@@ -222,5 +222,4 @@
    return ss.str();
  };
-
 #endif
 #else
@@ -232,4 +231,5 @@
 #define DTRACE_CABAC_R( x,y )
 #define DTRACE_CABAC_N
+#if NH_MV
 #define DTRACE_CU(x,y) ;             
 #define DTRACE_PU(x,y) ;            
@@ -238,9 +238,8 @@
 #define DTRACE_PU_S(x) ;            
 #define DTRACE_TU_S(x) ;            
-
 #define D_DEC_INDENT( b ) ;
 #define D_PRINT_INC_INDENT( b, str );
 #define D_PRINT_INDENT( b, str );
-
+#endif
 #endif
 const Char* nalUnitTypeToString(NalUnitType type);
Index: trunk/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 1314)
+++ trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 1321)
@@ -6,4 +6,5 @@
  * Copyright (c) 2010-2015, ITU/ISO/IEC
  * All rights reserved.
+
  *
  * Redistribution and use in source and binary forms, with or without
@@ -112,5 +113,4 @@
 , m_encCABACTableIdx              (I_SLICE)
 #if NH_MV
-, m_availableForTMVPRefFlag       ( true )
 , m_refPicSetInterLayer0          ( NULL )
 , m_refPicSetInterLayer1          ( NULL )
@@ -121,8 +121,6 @@
 , m_isDepth                       (false)
 #endif
-#if !H_MV_HLS7_GEN
+#if NH_MV
 , m_pocResetFlag                  (false)
-#endif
-#if NH_MV
 , m_crossLayerBlaFlag             (false)
 #endif
@@ -134,8 +132,9 @@
 , m_pocResetIdc                   (0)
 , m_pocResetPeriodId              (0)
+, m_hasPocResetPeriodIdPresent    (false)
 , m_fullPocResetFlag              (false)
 , m_pocLsbVal                     (0)
-, m_pocMsbValPresentFlag          (false)
-, m_pocMsbVal                     (0)
+, m_pocMsbCycleValPresentFlag     (false)
+, m_pocMsbCycleVal                (0)
 , m_pocMsbValRequiredFlag         (false)
 #endif
@@ -155,4 +154,16 @@
 #endif
 {
+
+#if NH_MV
+  m_shortTermRefPicSetIdx = 0; 
+  m_numLongTermSps        = 0; 
+  m_numLongTermPics       = 0; 
+  for (Int i = 0; i < MAX_NUM_PICS_RPS; i++)
+  {
+    m_ltIdxSps          [i] = 0; 
+    m_deltaPocMsbCycleLt[i] = 0;
+  }
+  setSliceTemporalMvpEnabledFlag( false ); 
+#endif
   for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
   {
@@ -790,4 +801,5 @@
 #endif
 
+
 Int TComSlice::getNumRpsCurrTempList() const
 {
@@ -806,5 +818,5 @@
   }
 #if NH_MV
-  numRpsCurrTempList = numRpsCurrTempList + getNumActiveRefLayerPics();
+    numRpsCurrTempList = numRpsCurrTempList + getNumActiveRefLayerPics();
 #endif
   return numRpsCurrTempList;
@@ -1097,5 +1109,6 @@
   m_pcVPS                = pSrc->m_pcVPS;
 #endif
-  m_pRPS                = pSrc->m_pRPS;  m_iLastIDR             = pSrc->m_iLastIDR;
+  m_pRPS                = pSrc->m_pRPS;
+  m_iLastIDR             = pSrc->m_iLastIDR;
 
   m_pcPic                = pSrc->m_pcPic;
@@ -1155,7 +1168,5 @@
 #if NH_MV
   // Additional slice header syntax elements 
-#if !H_MV_HLS7_GEN
   m_pocResetFlag               = pSrc->m_pocResetFlag; 
-#endif
   m_discardableFlag            = pSrc->m_discardableFlag; 
   m_interLayerPredEnabledFlag  = pSrc->m_interLayerPredEnabledFlag; 
@@ -2670,6 +2681,6 @@
   }
 }
-#endif
-
+
+#endif
 #endif // NH_MV
 
@@ -2719,4 +2730,7 @@
 , m_uiBitsForPOC              (  8)
 , m_numLongTermRefPicSPS      (  0)
+#if NH_MV
+, m_numShortTermRefPicSets    (   0)
+#endif
 , m_uiMaxTrSize               ( 32)
 , m_bUseSAO                   (false)
@@ -2750,5 +2764,9 @@
   for ( Int i = 0; i < MAX_TLAYER; i++ )
   {
+#if NH_MV
+    m_uiSpsMaxLatencyIncreasePlus1[i] = 0;
+#else
     m_uiMaxLatencyIncrease[i] = 0;
+#endif
     m_uiMaxDecPicBuffering[i] = 1;
     m_numReorderPics[i]       = 0;
@@ -3081,8 +3099,7 @@
 Void TComSPS::inferSpsMaxDecPicBufferingMinus1( TComVPS* vps, Int targetOptLayerSetIdx, Int currLayerId, Bool encoder )
 {
-  const std::vector<Int>& targetDecLayerIdList = vps->getTargetDecLayerIdList( vps->olsIdxToLsIdx( targetOptLayerSetIdx )); 
-
   if ( getMultiLayerExtSpsFlag() )
   {
+    const std::vector<Int>& targetDecLayerIdList = vps->getTargetDecLayerIdList( vps->olsIdxToLsIdx( targetOptLayerSetIdx )); 
     Int layerIdx = 0;         
     while (layerIdx < (Int) targetDecLayerIdList.size() )
@@ -3109,5 +3126,5 @@
         // This preliminary fix needs to be checked.
         assert( getNumReorderPics( i )     == maxNumReorderPics       ); 
-        assert( getMaxLatencyIncrease( i ) == maxLatencyIncreasePlus1 ); 
+        assert( getSpsMaxLatencyIncreasePlus1( i ) == maxLatencyIncreasePlus1 ); 
 
       }
@@ -3117,5 +3134,5 @@
         setMaxDecPicBuffering( maxDecPicBufferingMinus1 + 1 , i); 
         setNumReorderPics    ( maxNumReorderPics, i );
-        setMaxLatencyIncrease( maxLatencyIncreasePlus1 - 1 , i); 
+        setSpsMaxLatencyIncreasePlus1( maxLatencyIncreasePlus1 , i); 
       }
     }    
@@ -3412,5 +3429,4 @@
   }
 }
-
 Void TComSlice::markIvRefPicsAsShortTerm( std::vector<TComPic*> refPicSetInterLayer0, std::vector<TComPic*> refPicSetInterLayer1 )
 {
@@ -3435,7 +3451,7 @@
     for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[li]-1); rIdx ++)
     {      
-      if (rIdx == 0 && li == 0) m_apcRefPicList[li][rIdx]->print( true );
+      if (rIdx == 0 && li == 0) m_apcRefPicList[li][rIdx]->print( 1 );
+      m_apcRefPicList[li][rIdx]->print( 0 );      
         
-      m_apcRefPicList[li][rIdx]->print( false );
     }
   }
@@ -3456,4 +3472,22 @@
   m_refPicSetInterLayer1 = refPicSetInterLayer1; 
 }
+
+TComPic* TComSlice::getRefPicSetInterLayer( Int setIdc, Int i ) const
+{
+  TComPic* pic = NULL; 
+  if (setIdc == 0 )
+  {
+    pic = (*m_refPicSetInterLayer0)[ i ]; 
+  }
+  else if (setIdc == 1 )
+  {
+    pic = (*m_refPicSetInterLayer1)[ i ]; 
+  }
+
+  assert( pic != NULL );   
+
+  return pic; 
+}
+
 
 TComPic* TComSlice::getPicFromRefPicSetInterLayer(Int setIdc, Int layerId ) const
@@ -3572,4 +3606,5 @@
 #endif
 }
+#endif
 #if NH_3D_NBDV
 Void TComSlice::setDefaultRefView()
@@ -3687,5 +3722,5 @@
       if( iViewIdx<getViewIndex() && !bIsDepth )
       {
-        setBaseViewRefPicList( ivPicLists->getPicList( iLayerId ), iViewIdx );
+        setBaseViewRefPicList( ivPicLists->getSubDpb( iLayerId, false ), iViewIdx );
       }
     }
@@ -3710,5 +3745,5 @@
         if ( pcCurrPic->getViewIndex() != pcRefPic->getViewIndex() )
         {
-          existInterViewRef = true;        
+          existInterViewRef = true;
         }
       }
@@ -3833,7 +3868,7 @@
 #if NH_3D
 Void TComSlice::setIvPicLists( TComPicLists* m_ivPicLists )
-{
+{  
   for (Int i = 0; i < MAX_NUM_LAYERS; i++ )
-  {     
+  { 
     for ( Int depthId = 0; depthId < 2; depthId++ )
     {
@@ -3920,5 +3955,5 @@
 }
 #endif
-#endif
+
 
 
@@ -3933,5 +3968,5 @@
 }
 
-Bool TComSlice::inferPocMsbValPresentFlag()
+Bool TComSlice::inferPocMsbCycleValPresentFlag()
 {
   Bool pocMsbValPresentFlag; 
@@ -3952,4 +3987,324 @@
 }
 
+
+Void TComSlice::f834decProcForRefPicListConst()
+{
+  // This process is invoked at the beginning of the decoding process for each P or B slice.
+  assert( getSliceType() == B_SLICE || getSliceType() == P_SLICE );
+
+  // Reference pictures are addressed through reference indices as specified in clause 8.5.3.3.2. A reference index is an index into 
+  // a reference picture list. When decoding a P slice, there is a single reference picture list RefPicList0. When decoding a B 
+  // slice, there is a second independent reference picture list RefPicList1 in addition to RefPicList0.
+
+  // At the beginning of the decoding process for each slice, the reference picture lists RefPicList0 and, for B slices, RefPicList1 
+  // are derived as follows:
+
+  // The variable NumRpsCurrTempList0 is set equal to Max( num_ref_idx_l0_active_minus1 + 1, NumPicTotalCurr )
+  Int numRpsCurrTempList0 = std::max( getNumRefIdxL0ActiveMinus1() + 1, getNumPicTotalCurr() );
+
+  // and the list RefPicListTemp0 is constructed as follows:
+  std::vector<TComPic*> refPicListTemp0;
+  refPicListTemp0.resize((MAX_NUM_REF+1),NULL);
+
+  const TComDecodedRps* decRps = getPic()->getDecodedRps(); 
+
+  const std::vector<TComPic*>& refPicSetStCurrBefore  = decRps->m_refPicSetStCurrBefore; 
+  const std::vector<TComPic*>& refPicSetStCurrAfter   = decRps->m_refPicSetStCurrAfter;
+  const std::vector<TComPic*>& refPicSetLtCurr        = decRps->m_refPicSetLtCurr; 
+
+  const Int                    numPocStCurrBefore     = decRps->m_numPocStCurrBefore; 
+  const Int                    numPocStCurrAfter      = decRps->m_numPocStCurrAfter;
+  const Int                    numPocLtCurr           = decRps->m_numPocLtCurr;
+
+  const Int                    numActiveRefLayerPics0 = decRps->m_numActiveRefLayerPics0;
+  const Int                    numActiveRefLayerPics1 = decRps->m_numActiveRefLayerPics1;
+
+  const std::vector<TComPic*>& refPicSetInterLayer0   = decRps->m_refPicSetInterLayer0;
+  const std::vector<TComPic*>& refPicSetInterLayer1   = decRps->m_refPicSetInterLayer1;
+
+  Int rIdx = 0;
+  while( rIdx < numRpsCurrTempList0 )
+  {
+    for(Int  i = 0; i < numPocStCurrBefore  &&  rIdx < numRpsCurrTempList0; rIdx++, i++ )
+    {
+      refPicListTemp0[ rIdx ] = refPicSetStCurrBefore[ i ];
+    }    
+
+    for(Int  i = 0; i < numActiveRefLayerPics0; rIdx++, i++ )
+    {
+      refPicListTemp0[ rIdx ] = refPicSetInterLayer0[ i ];
+    }
+
+    for(Int  i = 0;  i < numPocStCurrAfter  &&  rIdx < numRpsCurrTempList0; rIdx++, i++ )  // (F 65)
+    {
+      refPicListTemp0[ rIdx ] = refPicSetStCurrAfter[ i ];
+    }
+
+    for(Int  i = 0; i < numPocLtCurr  &&  rIdx < numRpsCurrTempList0; rIdx++, i++ )
+    {
+      refPicListTemp0[ rIdx ] = refPicSetLtCurr[ i ]; 
+    }
+
+    for(Int  i = 0; i < numActiveRefLayerPics1; rIdx++, i++ )
+    {
+      refPicListTemp0[ rIdx ] = refPicSetInterLayer1[ i ];
+    }
+  }
+
+  // The list RefPicList0 is constructed as follows:
+  TComRefPicListModification* rplm  = getRefPicListModification(); 
+  for( rIdx = 0; rIdx  <=  getNumRefIdxL0ActiveMinus1(); rIdx++ )      //  (F 66)
+  {
+    m_apcRefPicList[ 0 ][ rIdx ] = rplm->getRefPicListModificationFlagL0( ) ? refPicListTemp0[ rplm->getListEntryL0( rIdx )] : refPicListTemp0[ rIdx ];
+    // The decoding process below slice level requires the status
+    // of the reference pictures, when decoding the RPS. So store it here.
+    m_bIsUsedAsLongTerm[ 0 ][ rIdx ] = m_apcRefPicList[ 0 ][ rIdx ]->getIsLongTerm();
+    m_aiRefPOCList     [ 0 ][ rIdx ] = m_apcRefPicList[ 0 ][ rIdx ]->getPOC();
+    m_aiRefLayerIdList [ 0 ][ rIdx ] = m_apcRefPicList[ 0 ][ rIdx ]->getLayerId();
+  }  
+
+  std::vector<TComPic*> refPicListTemp1;
+  refPicListTemp1.resize((MAX_NUM_REF+1),NULL);
+
+  if (getSliceType() == B_SLICE )
+  {
+    // When the slice is a B slice, the variable NumRpsCurrTempList1 is set equal to 
+    // Max( num_ref_idx_l1_active_minus1 + 1, NumPicTotalCurr ) and the list RefPicListTemp1 is constructed as follows:       
+    Int numRpsCurrTempList1 = std::max( getNumRefIdxL1ActiveMinus1() + 1, getNumPicTotalCurr() );
+
+    rIdx = 0; 
+    while( rIdx < numRpsCurrTempList1 )
+    {
+      for( Int i = 0; i < numPocStCurrAfter  &&  rIdx < numRpsCurrTempList1; rIdx++, i++ )
+      {
+        refPicListTemp1[ rIdx ] = refPicSetStCurrAfter[ i ]; 
+      }
+      for( Int i = 0; i< numActiveRefLayerPics1; rIdx++, i++ )
+      {
+        refPicListTemp1[ rIdx ] = refPicSetInterLayer1[ i ]; 
+      }
+      for( Int i = 0;  i < numPocStCurrBefore  &&  rIdx < numRpsCurrTempList1; rIdx++, i++ )  // (F 67)
+      {
+        refPicListTemp1[ rIdx ] = refPicSetStCurrBefore[ i ];
+      }         
+      for( Int i = 0; i < numPocLtCurr  &&  rIdx < numRpsCurrTempList1; rIdx++, i++ )
+      {
+        refPicListTemp1[ rIdx ] = refPicSetLtCurr[ i ];
+      }
+      for( Int i = 0; i< numActiveRefLayerPics0; rIdx++, i++ )
+      {
+        refPicListTemp1[ rIdx ] = refPicSetInterLayer0[ i ]; 
+      }
+    }
+  }
+
+  if (getSliceType() == B_SLICE )
+  {
+    //   When the slice is a B slice, the list RefPicList1 is constructed as follows:
+    for( rIdx = 0; rIdx  <=  getNumRefIdxL1ActiveMinus1(); rIdx++ )      // (F 68)
+    {
+      m_apcRefPicList[ 1 ][ rIdx ] = rplm->getRefPicListModificationFlagL1() ? refPicListTemp1[ rplm->getListEntryL1( rIdx ) ] : refPicListTemp1[ rIdx ]; 
+
+      // The decoding process below slice level requires the marking status
+      // of the reference pictures, when decoding the RPS. So store it here.
+      m_bIsUsedAsLongTerm[ 1 ][ rIdx ] = m_apcRefPicList[ 1 ][ rIdx ]->getIsLongTerm();
+      m_aiRefPOCList     [ 1 ][ rIdx ] = m_apcRefPicList[ 1 ][ rIdx ]->getPOC();
+      m_aiRefLayerIdList [ 1 ][ rIdx ] = m_apcRefPicList[ 1 ][ rIdx ]->getLayerId();
+    }    
+  }
+}
+
+
+Void TComSlice::cl834DecProcForRefPicListConst()
+{
+  // This process is invoked at the beginning of the decoding process for each P or B slice.
+  assert( getSliceType() == B_SLICE || getSliceType() == P_SLICE );
+
+  // Reference pictures are addressed through reference indices as specified in clause 8.5.3.3.2. A reference index is an index into 
+  // a reference picture list. When decoding a P slice, there is a single reference picture list RefPicList0. When decoding a B 
+  // slice, there is a second independent reference picture list RefPicList1 in addition to RefPicList0.
+
+  // At the beginning of the decoding process for each slice, the reference picture lists RefPicList0 and, for B slices, RefPicList1 
+  // are derived as follows:
+
+  // The variable NumRpsCurrTempList0 is set equal to Max( num_ref_idx_l0_active_minus1 + 1, NumPicTotalCurr ) 
+  Int numRpsCurrTempList0 = std::max( getNumRefIdxL0ActiveMinus1() + 1, getNumPicTotalCurr() );
+
+  // and the list RefPicListTemp0 is constructed as follows:
+  std::vector<TComPic*> refPicListTemp0; 
+  refPicListTemp0.resize((MAX_NUM_REF+1),NULL);
+
+  const TComDecodedRps* decRps = getPic()->getDecodedRps(); 
+
+  const std::vector<TComPic*>& refPicSetStCurrBefore = decRps->m_refPicSetStCurrBefore; 
+  const std::vector<TComPic*>& refPicSetStCurrAfter  = decRps->m_refPicSetStCurrAfter;
+  const std::vector<TComPic*>& refPicSetLtCurr       = decRps->m_refPicSetLtCurr; 
+    
+  const Int                    numPocStCurrBefore    = decRps->m_numPocStCurrBefore; 
+  const Int                    numPocStCurrAfter     = decRps->m_numPocStCurrAfter;
+  const Int                    numPocLtCurr          = decRps->m_numPocLtCurr;
+
+  Int rIdx = 0;
+  while( rIdx < numRpsCurrTempList0 )
+  {
+    for(Int  i = 0; i < numPocStCurrBefore  &&  rIdx < numRpsCurrTempList0; rIdx++, i++ )
+    {
+      refPicListTemp0[ rIdx ] = refPicSetStCurrBefore[ i ];
+    }    
+
+    for(Int  i = 0;  i < numPocStCurrAfter  &&  rIdx < numRpsCurrTempList0; rIdx++, i++ )  // (8 8)
+    {
+      refPicListTemp0[ rIdx ] = refPicSetStCurrAfter[ i ];
+    }
+
+    for(Int  i = 0; i < numPocLtCurr  &&  rIdx < numRpsCurrTempList0; rIdx++, i++ )
+    {
+      refPicListTemp0[ rIdx ] = refPicSetLtCurr[ i ]; 
+    }
+  }
+
+  // The list RefPicList0 is constructed as follows:
+
+  TComRefPicListModification* rplm = getRefPicListModification(); 
+  for( rIdx = 0; rIdx  <=  getNumRefIdxL0ActiveMinus1(); rIdx++ )      //   (8-9)
+  {
+    m_apcRefPicList[0][ rIdx ] = rplm->getRefPicListModificationFlagL0( ) ? refPicListTemp0[ rplm->getListEntryL0( rIdx )] : refPicListTemp0[ rIdx ];
+
+    // The decoding process below slice level requires the marking status 
+    // of the reference pictures, when decoding the RPS. So store it here.
+    m_bIsUsedAsLongTerm[ 0 ][ rIdx ] = m_apcRefPicList[ 0 ][ rIdx ]->getIsLongTerm();
+    m_aiRefPOCList     [ 0 ][ rIdx ] = m_apcRefPicList[ 0 ][ rIdx ]->getPOC();
+    m_aiRefLayerIdList [ 0 ][ rIdx ] = m_apcRefPicList[ 0 ][ rIdx ]->getLayerId();
+  }
+
+  std::vector<TComPic*> refPicListTemp1;
+  refPicListTemp1.resize((MAX_NUM_REF+1),NULL);
+
+  if (getSliceType() == B_SLICE )
+  {
+    // When the slice is a B slice, the variable NumRpsCurrTempList1 is set equal to 
+    // Max( num_ref_idx_l1_active_minus1 + 1, NumPicTotalCurr ) and the list RefPicListTemp1 is constructed as follows:
+    Int numRpsCurrTempList1 = std::max( getNumRefIdxL1ActiveMinus1() + 1, getNumPicTotalCurr() );
+
+    rIdx = 0; 
+    while( rIdx < numRpsCurrTempList1 )
+    {
+      for( Int i = 0; i < numPocStCurrAfter  &&  rIdx < numRpsCurrTempList1; rIdx++, i++ )
+      {
+        refPicListTemp1[ rIdx ] = refPicSetStCurrAfter[ i ]; 
+      }
+      for( Int i = 0;  i < numPocStCurrBefore  &&  rIdx < numRpsCurrTempList1; rIdx++, i++ )  // (8-10)
+      {
+        refPicListTemp1[ rIdx ] = refPicSetStCurrBefore[ i ];
+      }         
+      for( Int i = 0; i < numPocLtCurr  &&  rIdx < numRpsCurrTempList1; rIdx++, i++ )
+      {
+        refPicListTemp1[ rIdx ] = refPicSetLtCurr[ i ];
+      }
+    }
+  }
+
+  if (getSliceType() == B_SLICE )
+  {
+    //   When the slice is a B slice, the list RefPicList1 is constructed as follows:
+    for( rIdx = 0; rIdx  <=  getNumRefIdxL1ActiveMinus1(); rIdx++ )      // (F 68)
+    {
+      m_apcRefPicList[ 1 ][ rIdx ] = rplm->getRefPicListModificationFlagL1() ? refPicListTemp1[ rplm->getListEntryL1( rIdx ) ] : refPicListTemp1[ rIdx ]; 
+
+      // The decoding process below slice level requires the marking status 
+      // of the reference pictures, when decoding the RPS. So store it here.
+      m_bIsUsedAsLongTerm[ 1 ][ rIdx ] = m_apcRefPicList[ 1 ][ rIdx ]->getIsLongTerm();
+      m_aiRefPOCList     [ 1 ][ rIdx ] = m_apcRefPicList[ 1 ][ rIdx ]->getPOC();
+      m_aiRefLayerIdList [ 1 ][ rIdx ] = m_apcRefPicList[ 1 ][ rIdx ]->getLayerId();
+    }
+  }
+}
+
+Int TComSlice::getNumPicTotalCurr() const
+{
+  Int numPicTotalCurr = 0;
+#if NH_MV_FIX_NUM_POC_TOTAL_CUR
+  if ( !isIdr()  )
+  {
+    const TComStRefPicSet* stRps = getStRps( getCurrRpsIdx() ); 
+#endif
+    for( Int i = 0; i < stRps->getNumNegativePicsVar(); i++ )
+    {
+      if( stRps->getUsedByCurrPicS0Var( i ) )
+      {
+        numPicTotalCurr++;
+      }
+    }
+    for( Int i = 0; i < stRps->getNumPositivePicsVar(); i++)  //(7 55)
+    {
+      if( stRps->getUsedByCurrPicS1Var(i) )
+      {
+        numPicTotalCurr++;
+      }
+    }
+    for( Int i = 0; i < getNumLongTermSps() + getNumLongTermPics(); i++ )
+    {
+      if( getUsedByCurrPicLtVar( i ) )
+      {
+        numPicTotalCurr++;
+      }
+    }
+#if NH_MV_FIX_NUM_POC_TOTAL_CUR
+  }
+#endif
+
+  if ( decProcAnnexF() )
+  {
+    numPicTotalCurr += getNumActiveRefLayerPics(); 
+  }
+  return numPicTotalCurr;
+}
+
+
+
+Int TComSlice::getPocLsbLtVar( Int i )
+{
+  Int pocLsbLtVar; 
+  if (i < getNumLongTermSps() )
+  {
+
+    pocLsbLtVar = getSPS()->getLtRefPicPocLsbSps( getLtIdxSps( i ) ); 
+  }
+  else
+  {
+    pocLsbLtVar = getPocLsbLt( i ); 
+  }
+  return pocLsbLtVar;
+}
+
+
+Bool TComSlice::getUsedByCurrPicLtVar( Int i ) const
+{
+  Bool usedByCurrPicLtVar; 
+  if (i < getNumLongTermSps() )
+  {
+    usedByCurrPicLtVar = getSPS()->getUsedByCurrPicLtSPSFlag( getLtIdxSps( i ) ); 
+  }
+  else
+  {
+    usedByCurrPicLtVar = getUsedByCurrPicLtFlag( i ); 
+  }
+  return usedByCurrPicLtVar;
+}
+
+
+Int TComSlice::getDeltaPocMsbCycleLtVar( Int i ) const
+{
+  Int deltaPocMsbCycleVar; 
+  if (i == 0 || i == getNumLongTermSps() )
+  {
+    deltaPocMsbCycleVar = getDeltaPocMsbCycleLt( i ); 
+  }
+  else
+  {
+    deltaPocMsbCycleVar = getDeltaPocMsbCycleLt( i ) + getDeltaPocMsbCycleLtVar( i - 1 ); 
+  }
+  return deltaPocMsbCycleVar;
+}
 
 #endif
@@ -4074,13 +4429,27 @@
 
 Void TComSlice::checkInCompPredRefLayers()
-{
+{  
   if ( getInCompPredFlag() )
   {
     for (Int i = 0; i < getNumCurCmpLIds(); i++ )
-    {
+    {      
       assert( getIvPic(!getIsDepth(), getInCmpRefViewIdcs( i ) ) != NULL );       
       //  It is a requirement of bitstream conformance that there 
       //  is a picture in the DPB with PicOrderCntVal equal to the PicOrderCntVal of the current picture, 
       //  and a nuh_layer_id value equal to ViewCompLayerId[ inCmpRefViewIdcs[ i ] ][ !DepthFlag ].
+    }
+  } 
+}
+
+Void TComSlice::setPocsInCurrRPSs()
+{
+  // Currently only needed at decoder side; 
+  m_pocsInCurrRPSs.clear();    
+  std::vector<TComPic*>** rpsCurr = getPic()->getDecodedRps()->m_refPicSetsCurr;
+  for (Int i = 0 ; i < 3; i++ )
+  {
+    for( Int j = 0; j < rpsCurr[i]->size(); j++ )
+    {
+      m_pocsInCurrRPSs.push_back( (*rpsCurr[i])[j]->getPOC() ); 
     }
   }
@@ -4613,4 +4982,5 @@
 
   ProfileTierLevel* curProfileTierLevel = getGeneralPTL( ); 
+  assert( curProfileTierLevel != NULL ); 
 
   if( !profilePresentFlag )
@@ -4644,6 +5014,5 @@
 Void TComPTL::inferSubLayerValues(Int maxNumSubLayersMinus1, Int k, TComPTL* refPTL)
 {
-  assert( k == 0 || refPTL != NULL ); 
-
+  assert( k == 0 || refPTL != NULL );   
   for (Int i = maxNumSubLayersMinus1; i >= 0; i--)
   {
@@ -4665,5 +5034,7 @@
     }    
 
+    assert( refProfileTierLevel != NULL ); 
     ProfileTierLevel* curProfileTierLevel = getSubLayerPTL( i ); 
+    assert( curProfileTierLevel != NULL ); 
     if( !getSubLayerLevelPresentFlag( i ) )
     {
@@ -4883,4 +5254,10 @@
 }
 
+
+Int TComDpbSize::getVpsMaxLatencyPictures( Int i, Int j ) const
+{
+  return getMaxVpsNumReorderPics( i, j ) + getMaxVpsLatencyIncreasePlus1(i, j) - 1; 
+}
+
 Void Window::scaleOffsets( Int scal )
 {
@@ -4894,3 +5271,108 @@
   }
 }
-#endif
+
+Void TComStRefPicSet::inferRps( Int stRpsIdx, TComSPS* sps, Bool encoder )
+{
+  if ( getInterRefPicSetPredictionFlag() )
+  {
+    // When inter_ref_pic_set_prediction_flag is equal to 1, the variables DeltaPocS0[ stRpsIdx ][ i ], UsedByCurrPicS0[ stRpsIdx ][ i ], 
+    // NumNegativePics[ stRpsIdx ], DeltaPocS1[ stRpsIdx ][ i ], UsedByCurrPicS1[ stRpsIdx ][ i ] and NumPositivePics[ stRpsIdx ] are 
+    // derived as follows:
+
+    Int i = 0;
+    Int refRpsIdx = getRefRpsIdx( stRpsIdx );
+    TComStRefPicSet* refRps = sps->getStRefPicSet( refRpsIdx ); 
+
+    for( Int j = refRps->getNumPositivePicsVar( ) - 1; j >= 0; j-- ) 
+    {
+      Int dPoc = refRps->getDeltaPocS1Var( j ) + getDeltaRps();
+      if( dPoc < 0  &&  getUseDeltaFlag( refRps->getNumNegativePicsVar( ) + j ) ) 
+      {
+        setDeltaPocS0Var     ( i, dPoc );
+        setUsedByCurrPicS0Var( i++ , getUsedByCurrPicFlag( refRps->getNumNegativePicsVar( ) + j ) );
+      }
+    }
+    if( getDeltaRps() < 0  && getUseDeltaFlag( refRps->getNumDeltaPocs() ) )   //   (7 59)
+    {
+      setDeltaPocS0Var( i,  getDeltaRps() ); 
+      setUsedByCurrPicS0Var( i++ , getUsedByCurrPicFlag( refRps->getNumDeltaPocs() ) );
+    }
+    for( Int j = 0; j < refRps->getNumNegativePicsVar(); j++ )
+    {
+      Int dPoc = refRps->getDeltaPocS0Var( j ) + getDeltaRps(); 
+      if( dPoc < 0  &&  getUseDeltaFlag( j ) ) 
+      {
+        setDeltaPocS0Var( i , dPoc);
+        setUsedByCurrPicS0Var( i++ , getUsedByCurrPicFlag( j )) ;
+      }
+    }
+
+    setNumNegativePicsVar( i );
+
+    i = 0;
+    for( Int j = refRps->getNumNegativePicsVar() - 1; j  >=  0; j-- )
+    {
+      Int dPoc = refRps->getDeltaPocS0Var( j ) + getDeltaRps(); 
+      if( dPoc > 0  &&  getUseDeltaFlag( j ) )
+      {
+        setDeltaPocS1Var( i, dPoc );
+        setUsedByCurrPicS1Var(  i++, getUsedByCurrPicFlag( j ) ) ;
+      }
+    }
+
+    if( getDeltaRps() > 0  &&  getUseDeltaFlag( refRps->getNumDeltaPocs() ) ) //  (7 60)
+    { 
+      setDeltaPocS1Var( i , getDeltaRps() );
+      setUsedByCurrPicS1Var( i++ , getUsedByCurrPicFlag( refRps->getNumDeltaPocs() ));
+    }
+
+    for( Int j = 0; j < refRps->getNumPositivePicsVar( ); j++) 
+    {
+      Int dPoc = refRps->getDeltaPocS1Var( j ) + getDeltaRps(); 
+      if( dPoc > 0  &&  getUseDeltaFlag( refRps->getNumNegativePicsVar() + j ) ) 
+      {
+        setDeltaPocS1Var( i, dPoc);
+        setUsedByCurrPicS1Var( i++, getUsedByCurrPicFlag( refRps->getNumNegativePicsVar() + j ));
+      }
+    }
+    setNumPositivePicsVar(  i );
+  }
+  else
+  {
+    // When inter_ref_pic_set_prediction_flag is equal to 0, the variables NumNegativePics[ stRpsIdx ], NumPositivePics[ stRpsIdx ], 
+    // UsedByCurrPicS0[ stRpsIdx ][ i ], UsedByCurrPicS1[ stRpsIdx ][ i ], DeltaPocS0[ stRpsIdx ][ i ] and DeltaPocS1[ stRpsIdx ][ i ] 
+    // are derived as follows:
+
+    setNumNegativePicsVar( getNumNegativePics( ) );        //  (7 61)
+    setNumPositivePicsVar( getNumPositivePics( ) );         //  (7 62)
+
+    for (Int i = 0 ; i < getNumNegativePics(); i++ )
+    {      
+      setUsedByCurrPicS0Var( i,  getUsedByCurrPicS0Flag( i ) ); //  (7 63)
+      if (i == 0 )
+      {
+        setDeltaPocS0Var( i , -( getDeltaPocS0Minus1( i ) + 1 )); // (7 65)
+      }
+      else
+      {
+        setDeltaPocS0Var( i , getDeltaPocS0Var( i - 1 ) - ( getDeltaPocS0Minus1( i ) + 1 )); //  (7 67)
+      }
+    }
+
+    for (Int i = 0 ; i < getNumPositivePics(); i++ )
+    {      
+      setUsedByCurrPicS1Var( i,  getUsedByCurrPicS1Flag( i ) ); //  (7 64)
+
+      if (i == 0 )
+      {
+        setDeltaPocS1Var( i , getDeltaPocS1Minus1( i ) + 1    );      // (7 66)
+      }
+      else
+      {
+        setDeltaPocS1Var( i , getDeltaPocS1Var( i - 1 ) + ( getDeltaPocS1Minus1( i ) + 1 )); //  (7 68)
+      }
+    }
+  }
+}
+
+#endif
Index: trunk/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComSlice.h	(revision 1314)
+++ trunk/source/Lib/TLibCommon/TComSlice.h	(revision 1321)
@@ -53,4 +53,5 @@
 class TComTrQuant;
 #if NH_MV
+class TComDecodedRps;
 class TComPicLists; 
 class TComVPS; 
@@ -68,4 +69,114 @@
 
 /// Reference Picture Set class
+
+#if NH_MV
+class TComStRefPicSet 
+{
+  // This class is currently only used by the decoder. 
+  // TBD: Modify encoder to use also it.
+
+private: 
+
+  // Syntax elements: 
+
+  Bool m_interRefPicSetPredictionFlag;
+  Int  m_deltaIdxMinus1;
+  Bool m_deltaRpsSign;
+  Int  m_absDeltaRpsMinus1;
+  Bool m_usedByCurrPicFlag  [ MAX_NUM_PICS_RPS ];
+  Bool m_useDeltaFlag       [ MAX_NUM_PICS_RPS ];
+  Int  m_numNegativePics;   
+  Int  m_numPositivePics;   
+  Int  m_deltaPocS0Minus1   [ MAX_NUM_PICS_RPS ];
+  Bool m_usedByCurrPicS0Flag[ MAX_NUM_PICS_RPS ];
+  Int  m_deltaPocS1Minus1   [ MAX_NUM_PICS_RPS ];
+  Bool m_usedByCurrPicS1Flag[ MAX_NUM_PICS_RPS ];
+
+  // Semantic variables: 
+  Int m_deltaPocS0Var       [ MAX_NUM_PICS_RPS ];
+  Int m_deltaPocS1Var       [ MAX_NUM_PICS_RPS ];
+  Int m_usedByCurrPicS0Var  [ MAX_NUM_PICS_RPS ];
+  Int m_usedByCurrPicS1Var  [ MAX_NUM_PICS_RPS ];
+  Int m_numNegativePicsVar  ;
+  Int m_numPositivePicsVar  ;
+
+public:
+
+  TComStRefPicSet( )
+  {
+    // Set default inheritance values: 
+    setInterRefPicSetPredictionFlag( false ); 
+    setDeltaIdxMinus1( 0 );
+    for (Int j = 0; j < MAX_NUM_PICS_RPS; j++)
+    {
+      setUseDeltaFlag( j, true  ); 
+    }    
+  }
+
+  // Syntax elements: 
+  Void  setInterRefPicSetPredictionFlag( Bool flag )           { m_interRefPicSetPredictionFlag = flag; }
+  Bool  getInterRefPicSetPredictionFlag(  ) const              { return m_interRefPicSetPredictionFlag; }
+
+  Void  setDeltaIdxMinus1( Int  val )                          { m_deltaIdxMinus1 = val;                }
+  Int   getDeltaIdxMinus1(  ) const                            { return m_deltaIdxMinus1;               }
+
+  Void  setDeltaRpsSign( Bool flag )                           { m_deltaRpsSign = flag;                 }
+  Bool  getDeltaRpsSign(  ) const                              { return m_deltaRpsSign;                 }
+
+  Void  setAbsDeltaRpsMinus1( Int  val )                       { m_absDeltaRpsMinus1 = val;             }
+  Int   getAbsDeltaRpsMinus1(  ) const                         { return m_absDeltaRpsMinus1;            }
+
+  Void  setUsedByCurrPicFlag( Int j, Bool flag )               { m_usedByCurrPicFlag[j] = flag;         }
+  Bool  getUsedByCurrPicFlag( Int j ) const                    { return m_usedByCurrPicFlag[j];         }
+
+  Void  setUseDeltaFlag( Int j, Bool flag )                    { m_useDeltaFlag[j] = flag;              }
+  Bool  getUseDeltaFlag( Int j ) const                         { return m_useDeltaFlag[j];              }
+
+  Void  setNumNegativePics( Int  val )                         { m_numNegativePics = val;               }
+  Int   getNumNegativePics(  ) const                           { return m_numNegativePics;              }
+
+  Void  setNumPositivePics( Int  val )                         { m_numPositivePics = val;               }
+  Int   getNumPositivePics(  ) const                           { return m_numPositivePics;              }
+
+  Void  setDeltaPocS0Minus1( Int i, Int  val )                 { m_deltaPocS0Minus1[i] = val;           }
+  Int   getDeltaPocS0Minus1( Int i ) const                     { return m_deltaPocS0Minus1[i];          }
+
+  Void  setUsedByCurrPicS0Flag( Int i, Bool flag )             { m_usedByCurrPicS0Flag[i] = flag;       }
+  Bool  getUsedByCurrPicS0Flag( Int i ) const                  { return m_usedByCurrPicS0Flag[i];       }
+
+  Void  setDeltaPocS1Minus1( Int i, Int  val )                 { m_deltaPocS1Minus1[i] = val;           }
+  Int   getDeltaPocS1Minus1( Int i ) const                     { return m_deltaPocS1Minus1[i];          }
+
+  Void  setUsedByCurrPicS1Flag( Int i, Bool flag )             { m_usedByCurrPicS1Flag[i] = flag;       }
+  Bool  getUsedByCurrPicS1Flag( Int i ) const                  { return m_usedByCurrPicS1Flag[i];       }
+
+  // Semantics variables: 
+  Int   getRefRpsIdx(Int stRpsIdx ) const                      { return ( stRpsIdx - (getDeltaIdxMinus1() +  1) ); }
+  Int   getDeltaRps()  const                                   { return (  ( 1 - 2 * getDeltaRpsSign() ) * ( getAbsDeltaRpsMinus1() + 1 ) ); }
+  Int   getNumDeltaPocs() const                                { return ( getNumNegativePicsVar() + getNumPositivePicsVar());    }
+
+  Void  setNumNegativePicsVar( Int  val )                      { m_numNegativePicsVar = val;            }
+  Int   getNumNegativePicsVar(  ) const                        { return m_numNegativePicsVar;           }
+
+  Void  setNumPositivePicsVar( Int  val )                      { m_numPositivePicsVar = val;            }
+  Int   getNumPositivePicsVar(  ) const                        { return m_numPositivePicsVar;           }
+
+  Void  setDeltaPocS0Var( Int i, Int  val )                    { m_deltaPocS0Var[i] = val;              }
+  Int   getDeltaPocS0Var( Int i ) const                        { return m_deltaPocS0Var[i];             }
+
+  Void  setUsedByCurrPicS0Var( Int i, Bool flag )              { m_usedByCurrPicS0Var[i] = flag;       }
+  Bool  getUsedByCurrPicS0Var( Int i ) const                   { return m_usedByCurrPicS0Var[i];       }
+
+  Void  setDeltaPocS1Var( Int i, Int  val )                    { m_deltaPocS1Var[i] = val;             }
+  Int   getDeltaPocS1Var( Int i ) const                        { return m_deltaPocS1Var[i];            }
+
+  Void  setUsedByCurrPicS1Var( Int i, Bool flag )              { m_usedByCurrPicS1Var[i] = flag;       }
+  Bool  getUsedByCurrPicS1Var( Int i ) const                   { return m_usedByCurrPicS1Var[i];       }
+
+  Void  inferRps( Int stRpsIdx, TComSPS* sps, Bool encoder );
+};
+
+#endif
+
 class TComReferencePictureSet
 {
@@ -302,7 +413,13 @@
 {
   ProfileTierLevel m_generalPTL;
+#if !NH_MV
   ProfileTierLevel m_subLayerPTL    [MAX_TLAYER-1];      // max. value of max_sub_layers_minus1 is MAX_TLAYER-1 (= 6)
   Bool m_subLayerProfilePresentFlag [MAX_TLAYER-1];
   Bool m_subLayerLevelPresentFlag   [MAX_TLAYER-1];
+#else
+  ProfileTierLevel m_subLayerPTL    [MAX_TLAYER];        // However, highest index is 6, so we need one more. 
+  Bool m_subLayerProfilePresentFlag [MAX_TLAYER];
+  Bool m_subLayerLevelPresentFlag   [MAX_TLAYER];
+#endif
 
 public:
@@ -804,5 +921,6 @@
 
   Void          setMaxVpsLatencyIncreasePlus1( Int i, Int j, Int  val )              { m_maxVpsLatencyIncreasePlus1[i][j] = val;                  }
-  Int           getMaxVpsLatencyIncreasePlus1( Int i, Int j ) const                  { return m_maxVpsLatencyIncreasePlus1[i][j];                 }
+  Int           getMaxVpsLatencyIncreasePlus1( Int i, Int j ) const                  { return m_maxVpsLatencyIncreasePlus1[i][j];                 } 
+  Int           getVpsMaxLatencyPictures     ( Int i, Int j ) const;
 };
 #endif
@@ -901,12 +1019,7 @@
   Int         m_defaultDirectDependencyType;
   
-#if H_MV_HLS7_GEN
-  Int         m_directDependencyType     [MAX_NUM_LAYERS] [MAX_NUM_LAYERS];
-#endif
   Bool        m_vpsVuiPresentFlag;
   TComVPSVUI  m_vpsVUI; 
-#if !H_MV_HLS7_GEN
   Int         m_directDependencyType     [MAX_NUM_LAYERS] [MAX_NUM_LAYERS];
-#endif
 
   // VPS EXTENSION SEMANTICS VARIABLES
@@ -1119,9 +1232,5 @@
   Void    setLayerSetIdxForOlsMinus1( Int outLayerSetIdx, Int val )             { m_layerSetIdxForOlsMinus1[ outLayerSetIdx ]  = val; } 
   Int     getLayerSetIdxForOlsMinus1( Int outLayerSetIdx )           const      { return m_layerSetIdxForOlsMinus1[ outLayerSetIdx ]; } 
-#if NH_MV_FIX_TICKET_105
   Int     getLayerSetIdxForOlsMinus1Len( Int outLayerSetIdx )        const      { return gCeilLog2( getNumLayerSets() - 1 ); } 
-#else
-  Int     getLayerSetIdxForOlsMinus1Len( Int outLayerSetIdx )        const      { return gCeilLog2( getNumLayerSets() ); } 
-#endif
 
   Void    setOutputLayerFlag( Int outLayerSetIdx, Int i, Bool flag )            { m_outputLayerFlag[ outLayerSetIdx ][ i ] = flag; } 
@@ -1803,4 +1912,7 @@
 
   TComRPSList      m_RPSList;
+#if NH_MV
+  std::vector<TComStRefPicSet> m_stRefPicSets; 
+#endif
   Bool             m_bLongTermRefsPresent;
   Bool             m_TMVPFlagsPresent;
@@ -1825,4 +1937,7 @@
   UInt             m_uiBitsForPOC;
   UInt             m_numLongTermRefPicSPS;
+#if NH_MV
+  Int              m_numShortTermRefPicSets;
+#endif
   UInt             m_ltRefPicPocLsbSps[MAX_NUM_LONG_TERM_REF_PICS];
   Bool             m_usedByCurrPicLtSPSFlag[MAX_NUM_LONG_TERM_REF_PICS];
@@ -1838,5 +1953,10 @@
   TComScalingList  m_scalingList;
   UInt             m_uiMaxDecPicBuffering[MAX_TLAYER];
+#if NH_MV
+  UInt             m_uiSpsMaxLatencyIncreasePlus1[MAX_TLAYER];  
+  // Calling a member m_uiMaxLatencyIncrease although it is m_uiMaxLatencyIncreasePlus1 is really bad style.  
+#else
   UInt             m_uiMaxLatencyIncrease[MAX_TLAYER];  // Really max latency increase plus 1 (value 0 expresses no limit)
+#endif
 
   Bool             m_useStrongIntraSmoothing;
@@ -1911,4 +2031,8 @@
   Void                   setConformanceWindow(Window& conformanceWindow )                                { m_conformanceWindow = conformanceWindow;                             }
 
+#if NH_MV
+  UInt                   getNumLongTermRefPicsSps() const                                                 { return m_numLongTermRefPicSPS;                                       }
+#endif
+  
   UInt                   getNumLongTermRefPicSPS() const                                                 { return m_numLongTermRefPicSPS;                                       }
   Void                   setNumLongTermRefPicSPS(UInt val)                                               { m_numLongTermRefPicSPS = val;                                        }
@@ -1939,4 +2063,8 @@
   Void                   setBitsForPOC( UInt u )                                                         { m_uiBitsForPOC = u;                                                  }
   UInt                   getBitsForPOC() const                                                           { return m_uiBitsForPOC;                                               }
+#if NH_MV
+  UInt                   getMaxPicOrderCntLsb() const                                                    { return (1 << ( getLog2MaxPicOrderCntLsbMinus4() + 4) );  }
+  Int                    getLog2MaxPicOrderCntLsbMinus4() const                                          { return (getBitsForPOC() - 4);  }
+#endif
   Bool                   getUseAMP() const                                                               { return m_useAMP;                                                     }
   Void                   setUseAMP( Bool b )                                                             { m_useAMP = b;                                                        }
@@ -1954,8 +2082,19 @@
   const TComRPSList*     getRPSList() const                                                              { return &m_RPSList;                                                   }
   TComRPSList*           getRPSList()                                                                    { return &m_RPSList;                                                   }
+#if NH_MV
+  Void                   initStRefPicSets( )                                                             { m_stRefPicSets.resize( getNumShortTermRefPicSets() );                }
+  TComStRefPicSet*       getStRefPicSet( Int i )                                                         { return &(m_stRefPicSets[i]);                                         }
+  const TComStRefPicSet* getStRefPicSet( Int i ) const                                                   { return &(m_stRefPicSets[i]);                                         }
+  Bool                   getLongTermRefPicsPresentFlag() const                                           { return m_bLongTermRefsPresent;                                       }
+  Void                   setLongTermRefPicsPresentFlag(Bool b)                                           { m_bLongTermRefsPresent=b;                                            }
+#else
   Bool                   getLongTermRefsPresent() const                                                  { return m_bLongTermRefsPresent;                                       }
   Void                   setLongTermRefsPresent(Bool b)                                                  { m_bLongTermRefsPresent=b;                                            }
+#endif
   Bool                   getTMVPFlagsPresent() const                                                     { return m_TMVPFlagsPresent;                                           }
   Void                   setTMVPFlagsPresent(Bool b)                                                     { m_TMVPFlagsPresent=b;                                                }
+#if NH_MV
+  Bool                   getSpsTemporalMvpEnabledFlag() const                                            { return m_TMVPFlagsPresent;                                           }
+#endif
   // physical transform
   Void                   setMaxTrSize( UInt u )                                                          { m_uiMaxTrSize = u;                                                   }
@@ -1988,5 +2127,8 @@
   Void                   setPCMFilterDisableFlag( Bool bValue )                                          { m_bPCMFilterDisableFlag = bValue;                                    }
   Bool                   getPCMFilterDisableFlag() const                                                 { return m_bPCMFilterDisableFlag;                                      }
-
+#if NH_MV
+  Void                  setNumShortTermRefPicSets( Int  val )                                            { m_numShortTermRefPicSets = val; } 
+  Int                   getNumShortTermRefPicSets(  )const                                               { return m_numShortTermRefPicSets; } 
+#endif
   Bool                   getScalingListFlag() const                                                      { return m_scalingListEnabledFlag;                                     }
   Void                   setScalingListFlag( Bool b )                                                    { m_scalingListEnabledFlag  = b;                                       }
@@ -1998,6 +2140,17 @@
   UInt                   getMaxDecPicBuffering(UInt tlayer) const                                        { return m_uiMaxDecPicBuffering[tlayer];                               }
   Void                   setMaxDecPicBuffering( UInt ui, UInt tlayer )                                   { assert(tlayer < MAX_TLAYER); m_uiMaxDecPicBuffering[tlayer] = ui;    }
+#if NH_MV
+  UInt                   getSpsMaxDecPicBufferingMinus1(UInt tlayer) const                               { return m_uiMaxDecPicBuffering[tlayer] -1 ;                           }
+  UInt                   getSpsMaxLatencyIncreasePlus1(UInt tlayer) const                                { return m_uiSpsMaxLatencyIncreasePlus1[tlayer];                       }
+  Void                   setSpsMaxLatencyIncreasePlus1( UInt ui , UInt tlayer)                           { m_uiSpsMaxLatencyIncreasePlus1[tlayer] = ui;                         }
+  Int                    getSpsMaxLatencyPictures( Int i )  const                                       { return ( getSpsMaxNumReorderPics(i) + getSpsMaxLatencyIncreasePlus1(i)-1); }
+#else
   UInt                   getMaxLatencyIncrease(UInt tlayer) const                                        { return m_uiMaxLatencyIncrease[tlayer];                               }
   Void                   setMaxLatencyIncrease( UInt ui , UInt tlayer)                                   { m_uiMaxLatencyIncrease[tlayer] = ui;                                 }
+#endif
+
+#if NH_MV
+  Int                    getSpsMaxNumReorderPics(Int i ) const                                           { return getNumReorderPics( i );                                       }
+#endif
 
   Void                   setUseStrongIntraSmoothing(Bool bVal)                                           { m_useStrongIntraSmoothing = bVal;                                    }
@@ -2133,9 +2286,19 @@
   Void    setRefPicSetIdxL1(UInt idx, UInt refPicSetIdx) { assert(idx<REF_PIC_LIST_NUM_IDX); m_RefPicSetIdxL1[idx] = refPicSetIdx; }
 #if NH_MV
-  // Why not a listIdx for all members, would avoid code duplication?? 
+  
   Void    setRefPicSetIdxL(UInt li, UInt idx, UInt refPicSetIdx) {( li==0 ? m_RefPicSetIdxL0[idx] : m_RefPicSetIdxL1[idx] ) = refPicSetIdx;              }
   UInt    getRefPicSetIdxL(UInt li, UInt idx )                   { return ( li == 0 ) ? m_RefPicSetIdxL0[idx] : m_RefPicSetIdxL1[idx] ;                  }
   Void    setRefPicListModificationFlagL(UInt li, Bool flag)     { ( li==0  ? m_refPicListModificationFlagL0 : m_refPicListModificationFlagL1 ) = flag;  }
   Bool    getRefPicListModificationFlagL(UInt li )               { return ( li== 0) ? m_refPicListModificationFlagL0 : m_refPicListModificationFlagL1;   }
+
+  Int     getListEntryL0( Int i) const                           { assert(i<REF_PIC_LIST_NUM_IDX); return m_RefPicSetIdxL0[i];         }
+  Int     getListEntryL1( Int i) const                           { assert(i<REF_PIC_LIST_NUM_IDX); return m_RefPicSetIdxL1[i];         }
+
+  Int     getListEntryLXLen( Int numPicTotalCur ) const          { return gCeilLog2( numPicTotalCur );                                 }  
+
+  Void    setListEntryL0( Int i, Int  val )                      { m_RefPicSetIdxL0[i] = val;                                          } 
+  Void    setListEntryL1( Int i, Int  val )                      { m_RefPicSetIdxL1[i] = val;                                          } 
+
+
 #endif
 };
@@ -2470,4 +2633,7 @@
 private:
   //  Bitstream writing
+#if NH_MV
+  Bool                       m_firstSliceSegmentInPicFlag; 
+#endif
   Bool                       m_saoEnabledFlag[MAX_NUM_CHANNEL_TYPE];
   Int                        m_iPPSId;               ///< picture parameter set ID
@@ -2475,4 +2641,15 @@
 #if NH_MV
   Int                        m_slicePicOrderCntLsb;   
+  Bool                       m_shortTermRefPicSetSpsFlag;
+  Int                        m_shortTermRefPicSetIdx;
+  Int                        m_numLongTermSps;
+  Int                        m_numLongTermPics;
+  Int                        m_ltIdxSps                     [MAX_NUM_PICS_RPS];
+  Int                        m_pocLsbLt                     [MAX_NUM_PICS_RPS];
+  Bool                       m_usedByCurrPicLtFlag          [MAX_NUM_PICS_RPS];
+  Bool                       m_deltaPocMsbPresentFlag       [MAX_NUM_PICS_RPS];
+  Int                        m_deltaPocMsbCycleLt           [MAX_NUM_PICS_RPS];
+  Bool                       m_sliceTemporalMvpEnabledFlag;
+  TComStRefPicSet            m_stRefPicSet; 
 #endif  
   Int                        m_iPOC;
@@ -2510,5 +2687,5 @@
   Int                        m_aiRefPOCList  [NUM_REF_PIC_LIST_01][MAX_NUM_REF+1];
 #if NH_MV
-  Int         m_aiRefLayerIdList[2][MAX_NUM_REF+1];
+  Int                        m_aiRefLayerIdList[2][MAX_NUM_REF+1];
 #endif
   Bool                       m_bIsUsedAsLongTerm[NUM_REF_PIC_LIST_01][MAX_NUM_REF+1];
@@ -2570,8 +2747,5 @@
   SliceType                  m_encCABACTableIdx;           // Used to transmit table selection across slices.
 #if NH_MV
-  Bool       m_availableForTMVPRefFlag;
-#endif
-
-#if NH_MV
+
   std::vector<TComPic*>* m_refPicSetInterLayer0; 
   std::vector<TComPic*>* m_refPicSetInterLayer1; 
@@ -2584,7 +2758,6 @@
 
 // Additional slice header syntax elements 
-#if !H_MV_HLS7_GEN
   Bool       m_pocResetFlag; 
-#endif
+
   Bool       m_crossLayerBlaFlag;
   Bool       m_discardableFlag;
@@ -2596,8 +2769,12 @@
   Int        m_pocResetIdc;
   Int        m_pocResetPeriodId;
+
+  Bool       m_hasPocResetPeriodIdPresent; 
+  DecodingProcess m_decodingProcess; 
+  DecodingProcess m_decProcPocAndRps; 
   Bool       m_fullPocResetFlag;
   Int        m_pocLsbVal;
-  Bool       m_pocMsbValPresentFlag;
-  Int        m_pocMsbVal;
+  Bool       m_pocMsbCycleValPresentFlag;
+  Int        m_pocMsbCycleVal;
   Bool       m_pocMsbValRequiredFlag;
 
@@ -2676,4 +2853,7 @@
   Void                        setSlicePicOrderCntLsb( Int i )                        { m_slicePicOrderCntLsb = i;                                    }
   Int                         getSlicePicOrderCntLsb(  )  const                      { return m_slicePicOrderCntLsb;                                 }
+
+  Bool                        getFirstSliceSegementInPicFlag() const                 {  return m_firstSliceSegmentInPicFlag;                         }
+  Void                        setFirstSliceSegementInPicFlag(Bool val)               { m_firstSliceSegmentInPicFlag = val;                           }
 #endif
   Bool                        getPicOutputFlag() const                               { return m_PicOutputFlag;                                       }
@@ -2734,4 +2914,6 @@
   Void                        setBaseViewRefPicList( TComList<TComPic*> *pListPic, Int iViewIdx )      { m_pBaseViewRefPicList[iViewIdx] = pListPic; }                  
   Void                        setARPStepNum( TComPicLists*ivPicLists );                                                                              
+  Void                        setPocsInCurrRPSs( );
+
   TComPic*                    getBaseViewRefPic    ( UInt uiPOC , Int iViewIdx )     { return xGetRefPic( *m_pBaseViewRefPicList[iViewIdx], uiPOC ); }
   UInt                        getARPStepNum( )                                       { return m_nARPStepNum;                                         }  
@@ -2746,4 +2928,7 @@
   Bool                        getMvdL1ZeroFlag() const                               { return m_bLMvdL1Zero;                                         }
   Int                         getNumRpsCurrTempList() const;
+#if NH_MV
+  Int                         getNumPicTotalCurr() const;
+#endif
   Int                         getList1IdxToList0Idx( Int list1Idx ) const            { return m_list1IdxToList0Idx[list1Idx];                        }
   Void                        setReferenced(Bool b)                                  { m_bRefenced = b;                                              }
@@ -2753,7 +2938,39 @@
   Void                        setNalUnitType( NalUnitType e )                        { m_eNalUnitType      = e;                                      }
   NalUnitType                 getNalUnitType() const                                 { return m_eNalUnitType;                                        }
+#if NH_MV
+  std::string                 getNalUnitTypeString(    )                             { return NALU_TYPE_STR[ getNalUnitType() ]; };
+#endif
   Bool                        getRapPicFlag() const;
   Bool                        getIdrPicFlag() const                                  { return getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP; }
   Bool                        isIRAP() const                                         { return (getNalUnitType() >= 16) && (getNalUnitType() <= 23);  }
+#if NH_MV  
+  Bool                        isBla() const                                          { return ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP   )  || ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP ) || ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL ); }
+  Bool                        isIdr() const                                          { return ( getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL )  || ( getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP ); }
+  Bool                        isCra() const                                          { return ( getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ); }
+
+  Bool                        isSlnr() const                                         { return ( getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N  ||    
+                                                                                                getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N    ||    
+                                                                                                getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N   ||    
+                                                                                                getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N   ||    
+                                                                                                getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N   ||    
+                                                                                                getNalUnitType() == NAL_UNIT_RESERVED_VCL_N10     ||
+                                                                                                getNalUnitType() == NAL_UNIT_RESERVED_VCL_N12     ||            
+                                                                                                getNalUnitType() == NAL_UNIT_RESERVED_VCL_N14     );  }
+  
+  Bool                        isRasl() const                                          { return ( getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R )  || ( getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N ); }
+  Bool                        isRadl() const                                          { return ( getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_R )  || ( getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N ); }
+  Bool                        isStsa() const                                          { return ( getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_R )  || ( getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N ); }
+  Bool                        isTsa()  const                                          { return ( getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R )   || ( getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N ); }
+
+  Bool                        decProcClause8() const                                  { return ( m_decodingProcess == CLAUSE_8  ); }    
+  Bool                        decProcAnnexF()  const                                  { return ( decProcAnnexG()  || decProcAnnexH() || decProcAnnexI() ) ; }
+  Bool                        decProcAnnexG()  const                                  { return ( m_decodingProcess == ANNEX_G || decProcAnnexI()  ); }    
+  Bool                        decProcAnnexH()  const                                  { return ( m_decodingProcess == ANNEX_H  ); }    
+  Bool                        decProcAnnexI()  const                                  { return ( m_decodingProcess == ANNEX_I  ); }    
+  Int                         getCurrRpsIdx() const                                   { return ( getShortTermRefPicSetSpsFlag() ? getShortTermRefPicSetIdx() : getSPS()->getNumShortTermRefPicSets() ) ;}
+
+#endif
+
+
   Void                        checkCRA(const TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, NalUnitType& associatedIRAPType, TComList<TComPic *>& rcListPic);
   Void                        decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic, const bool bEfficientFieldIRAPEnabled);
@@ -2774,4 +2991,8 @@
   Void                        setRefPOC( Int i, RefPicList e, Int iRefIdx )          { m_aiRefPOCList[e][iRefIdx] = i;                               }
   Void                        setNumRefIdx( RefPicList e, Int i )                    { m_aiNumRefIdx[e]    = i;                                      }
+#if NH_MV
+  Int                         getNumRefIdxL0ActiveMinus1() const                     { return ( getNumRefIdx(REF_PIC_LIST_0) -1);                    }
+  Int                         getNumRefIdxL1ActiveMinus1() const                     { return ( getNumRefIdx(REF_PIC_LIST_1) -1);                    }
+#endif
   Void                        setPic( TComPic* p )                                   { m_pcPic             = p;                                      }
   Void                        setDepth( Int iDepth )                                 { m_iDepth            = iDepth;                                 }
@@ -2827,5 +3048,5 @@
   Void                        setTLayer( UInt uiTLayer )                             { m_uiTLayer = uiTLayer;                                        }
 #if NH_MV
-  Int                         getTemporalId          ( )                             { return (Int) m_uiTLayer;                                      }
+  Int                         getTemporalId( ) const                                 { return (Int) m_uiTLayer;                                      }
 #endif
 
@@ -2836,4 +3057,7 @@
 #if NH_MV
   Void                        createInterLayerReferencePictureSet( TComPicLists* ivPicLists, std::vector<TComPic*>& refPicSetInterLayer0, std::vector<TComPic*>& refPicSetInterLayer1 );
+  Void                        f834decProcForRefPicListConst();
+  Void                        cl834DecProcForRefPicListConst();
+
   static Void                 markIvRefPicsAsShortTerm    ( std::vector<TComPic*> refPicSetInterLayer0, std::vector<TComPic*> refPicSetInterLayer1 );
   static Void                 markCurrPic                 ( TComPic* currPic );
@@ -2852,4 +3076,5 @@
   Void                        setNoRaslOutputFlag( Bool val )                        { m_noRaslOutputFlag = val;                                     }
   Bool                        getNoRaslOutputFlag() const                            { return m_noRaslOutputFlag;                                    }
+
 
   Void                        setHandleCraAsBlaFlag( Bool val )                      { m_handleCraAsBlaFlag = val;                                   }
@@ -2915,4 +3140,43 @@
   Bool                        getLFCrossSliceBoundaryFlag()                          { return m_LFCrossSliceBoundaryFlag;                            }
 
+#if NH_MV
+  Void                        setShortTermRefPicSetSpsFlag( Bool flag )              { m_shortTermRefPicSetSpsFlag = flag;                           }
+  Bool                        getShortTermRefPicSetSpsFlag(  ) const                 { return m_shortTermRefPicSetSpsFlag;                           }
+
+  Int                         getShortTermRefPicSetIdxLen() const                    { return gCeilLog2( getSPS()->getNumShortTermRefPicSets() );    }
+  Void                        setShortTermRefPicSetIdx( Int  val )                   { m_shortTermRefPicSetIdx = val;                                }
+  Int                         getShortTermRefPicSetIdx(  ) const                     { return m_shortTermRefPicSetIdx;                               }
+  
+  Void                        setNumLongTermSps( Int  val )                          { m_numLongTermSps = val;                                       }
+  Int                         getNumLongTermSps(  ) const                            { return m_numLongTermSps;                                      }
+
+  Void                        setNumLongTermPics( Int  val )                         { m_numLongTermPics = val;                                      }
+  Int                         getNumLongTermPics(  ) const                           { return m_numLongTermPics;                                     }
+  
+  Int                         getLtIdxSpsLen() const                                 { return gCeilLog2( getSPS()->getNumLongTermRefPicsSps() );     }
+  Void                        setLtIdxSps( Int i, Int  val )                         { m_ltIdxSps[i] = val;                                          }
+  Int                         getLtIdxSps( Int i ) const                             { return m_ltIdxSps[i];                                         }
+
+  Int                         getPocLsbLtLen() const                                 { return (getSPS()->getLog2MaxPicOrderCntLsbMinus4()+ 4);       }
+  Void                        setPocLsbLt( Int i, Int  val )                         { m_pocLsbLt[i] = val;                                          }
+  Int                         getPocLsbLt( Int i ) const                             { return m_pocLsbLt[i];                                         }
+
+  Void                        setUsedByCurrPicLtFlag( Int i, Bool flag )             { m_usedByCurrPicLtFlag[i] = flag;                              }
+  Bool                        getUsedByCurrPicLtFlag( Int i ) const                  { return m_usedByCurrPicLtFlag[i];                              }
+
+  Void                        setDeltaPocMsbPresentFlag( Int i, Bool flag )          { m_deltaPocMsbPresentFlag[i] = flag;                           }
+  Bool                        getDeltaPocMsbPresentFlag( Int i ) const               { return m_deltaPocMsbPresentFlag[i];                           }
+
+  Void                        setDeltaPocMsbCycleLt( Int i, Int  val )               { m_deltaPocMsbCycleLt[i] = val;                                }
+  Int                         getDeltaPocMsbCycleLt( Int i ) const                   { return m_deltaPocMsbCycleLt[i];                               }
+
+  Void                        setSliceTemporalMvpEnabledFlag( Bool flag )            { m_enableTMVPFlag = flag;                         }
+  Bool                        getSliceTemporalMvpEnabledFlag(  ) const               { return m_enableTMVPFlag;                         }
+
+  TComStRefPicSet*            getLocalStRps( )                                       { return &m_stRefPicSet; };
+  const TComStRefPicSet*      getStRps( Int stRpsIdx ) const                         { return ( (stRpsIdx == getSPS()->getNumShortTermRefPicSets()) ? &m_stRefPicSet : getSPS()->getStRefPicSet( stRpsIdx ) ); };
+
+#endif
+
   Void                        setEnableTMVPFlag( Bool   b )                          { m_enableTMVPFlag = b;                                         }
   Bool                        getEnableTMVPFlag()                                    { return m_enableTMVPFlag;                                      }
@@ -2922,7 +3186,4 @@
 
 #if NH_MV
-  Void                        setAvailableForTMVPRefFlag( Bool   b )                 { m_availableForTMVPRefFlag = b;                                }
-  Bool                        getAvailableForTMVPRefFlag()                           { return m_availableForTMVPRefFlag;                             }
-
   Void                        setLayerId     ( Int layerId )                         { m_layerId      = layerId;                                     }
   Int                         getLayerId     ()                 const                { return m_layerId;                                             }
@@ -2932,4 +3193,8 @@
   Void                        setViewIndex   ( Int viewIndex )                       { m_viewIndex = viewIndex;                                      }
   Int                         getViewIndex   ()                 const                { return m_viewIndex;                                           }
+
+  Void                        setDecodingProcess ( DecodingProcess decProc )         { m_decodingProcess = decProc;                                  }
+
+
 #if NH_3D
 #if NH_3D_TMVP
@@ -2986,5 +3251,5 @@
   Void                        checkCrossLayerBlaFlag ( ) const ;
 
-#if !H_MV_HLS7_GEN
+#if NH_MV
   Void                        setPocResetFlag( Bool flag )                           { m_pocResetFlag = flag;                                        }
   Bool                        getPocResetFlag(  ) const                              { return m_pocResetFlag;                                        }
@@ -3010,4 +3275,5 @@
   Void                        checkPocResetIdc( ) const                              { assert( !(getVPS()->getPocLsbNotPresentFlag( getLayerIdInVps() ) )  || !(getSlicePicOrderCntLsb() > 0 ) || !( getPocResetIdc() == 2) ); }
 
+  
   Void                        setPocResetPeriodId( Int  val )                        { m_pocResetPeriodId = val;                                     }
   Int                         getPocResetPeriodId(  ) const                          { return m_pocResetPeriodId;                                    }
@@ -3020,4 +3286,19 @@
   Void                        checkPocLsbVal( ) const                                { assert( !(getVPS()->getPocLsbNotPresentFlag( getLayerIdInVps() ) )  || !getFullPocResetFlag() || ( getPocLsbVal() == 0 ) ); }
 
+#if NH_MV
+  Void                        setHasPocResetPeriodIdPresent( Bool  val )              { m_hasPocResetPeriodIdPresent = val;                                }
+  Bool                        getHasPocResetPeriodIdPresent(  ) const                { return m_hasPocResetPeriodIdPresent;                               }
+
+  Void                        setPocMsbCycleValPresentFlag( Bool flag )              { m_pocMsbCycleValPresentFlag = flag;                                }
+  Bool                        getPocMsbCycleValPresentFlag(  )          const        { return m_pocMsbCycleValPresentFlag;                                }
+
+  Void                        setPocMsbCycleVal( Int  val )                          { m_pocMsbCycleVal = val;                                            }
+  Int                         getPocMsbCycleVal(  )         const                    { return m_pocMsbCycleVal;                                           }
+  
+  Int                         getPocLsbLtVar(Int i);
+  Bool                        getUsedByCurrPicLtVar(Int i) const;
+  Int                         getDeltaPocMsbCycleLtVar( Int i ) const;
+
+#else
   Void                        setPocMsbValPresentFlag( Bool flag )                   { m_pocMsbValPresentFlag = flag;                                }
   Bool                        getPocMsbValPresentFlag(  )          const             { return m_pocMsbValPresentFlag;                                }
@@ -3025,9 +3306,11 @@
   Void                        setPocMsbVal( Int  val )                               { m_pocMsbVal = val;                                            }
   Int                         getPocMsbVal(  )         const                         { return m_pocMsbVal;                                           }
+#endif
+
 
   Bool                        getCraOrBlaPicFlag()       const                       { return ( getCraPicFlag() || getBlaPicFlag() );                }
   Bool                        getPocMsbValRequiredFlag() const                       { return ( getCraOrBlaPicFlag() && ( getVPS()->getVpsPocLsbAlignedFlag() || getVPS()->getNumDirectRefLayers( getLayerIdInVps() ) == 0 ) );  }
 
-  UInt                        getPocLsbValLen() const                                { return getSPS()->getBitsForPOC();                             }; //log2_max_pic_order_cnt_lsb_minus4 + 4
+  UInt                        getPocLsbValLen() const                                { return getSPS()->getBitsForPOC();                             }; //log2_max_pic_order_cnt_lsb_minus4 + 4  
 
   Bool getBlaPicFlag() const
@@ -3069,5 +3352,5 @@
   Void                        deriveInCmpPredAndCpAvailFlag( );
   Void                        init3dToolParameters();
-  Void                        checkInCompPredRefLayers();;
+  Void                        checkInCompPredRefLayers();
 
   Bool                        getIvMvPredFlag           ( )                          { return m_ivMvPredFlag           ;                             };
@@ -3095,6 +3378,14 @@
 #endif
 #endif
+#if NH_MV
+ TComPic*                     getRefPicSetInterLayer( Int setIdc, Int i ) const; 
+#endif
+
   // Inference 
+#if NH_MV
+  Bool                        inferPocMsbCycleValPresentFlag();
+#else
   Bool                        inferPocMsbValPresentFlag();
+#endif
 #endif
 protected:
Index: trunk/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- trunk/source/Lib/TLibCommon/TypeDef.h	(revision 1314)
+++ trunk/source/Lib/TLibCommon/TypeDef.h	(revision 1321)
@@ -61,71 +61,22 @@
 #define NH_3D          ( HEVC_EXT == 2)
 /////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////   FIXES           ///////////////////////////////////  
+/////////////////////////////////////////////////////////////////////////////////////////
+#if NH_MV
+#define NH_MV_FIX_TICKET_106                      1 // Identical motion check. 
+#define NH_MV_FIX_NO_REF_PICS_CHECK               1 // !!SPEC!! 
+#define NH_MV_FIX_INIT_NUM_ACTIVE_REF_LAYER_PICS  1 // Derivation of NumActiveRefLayerPIcs. !!SPEC!! 
+#define NH_MV_FIX_NUM_POC_TOTAL_CUR               1 // Derivation of NumPocTotalCur for IDR pictures. !!SPEC!!
+#endif
+#if NH_3D
+#define H_3D_FIX_ARP_CHECK_NOT_IN_DPB     1
+#endif
+/////////////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////   MAJOR DEFINES   ///////////////////////////////////  
 /////////////////////////////////////////////////////////////////////////////////////////
 #if NH_MV
-#define NH_MV_FIX_TICKET_105              1 // layer_set_idx_for_ols_minus1 length
-#define NH_MV_FIX_TICKET_100              1 // Extra slice header bits
 #define H_MV_ENC_DEC_TRAC                 1  //< CU/PU level tracking
-#define H_MV_ENC_DEC_TRAC_FIX             1  // by SHARP
 #if NH_3D
-// FIXES 
-#define NH_3D_FIX_TICKET_98               1 // Writing of depth intra skip flag
-#define NH_3D_FIX_TICKET_101              ( 1 && NH_3D_VER141_DEC_COMP_FLAG )  // Camera parameters for depth
-#define NH_3D_DIS_FIX                     1
-#define NH_3D_ENC_DEPTH_FIX               1 // Fix Intra TU coding. 
-#define NH_3D_INTRA_SDC_RD_FIX            1 // Fix in RD- decision of intra SDC.
-#define NH_3D_DLT_FIX                     1 // Fixes numbers of parsed DLTs 
-#define NH_3D_VER141_DEC_COMP_FLAG        0 // Makes decoding of this version compatible to HTM-14.1 by re-introducing HTM-14.1 bugs.
-#define NH_3D_ALIGN_SPIVMP_DBBP           1 // Further alignment of DBBP and SBP motion
-#define NH_3D_ALIGN_SPIVMP_RP             1 // Alignment of DBBP and RP
-#define NH_3D_FIX_VSP                     1 
-#define NH_3D_VSO                         1
-#define NH_3D_NBDV                        1
-#define NH_3D_TMVP                        1   // QC_TMVP_C0047 
-                                              // Sony_M23639
-                                              // H_3D_TMVP_SCALING_FIX_K0053       1   // QC/CY for K0053
-#define NH_3D_IC                          1   // Illumination Compensation, JCT3V-B0045, JCT3V-C0046, JCT3V-D0060
-                                              // Unifying rounding offset, for IC part, JCT3V-D0135
-                                              // SHARP_ILLUCOMP_REFINE_E0046
-                                              // MTK_CLIPPING_ALIGN_IC_E0168       // To support simplify bi-prediction PU with identical motion checking, JCT3V-E0168
-                                              // LGE_IC_CTX_F0160 //JCT3V-F0160
-                                              // SEC_ONLY_TEXTURE_IC_F0151
-                                              // MTK_IC_FLAG_CABAC_SIMP_G0061
-                                              // SEC_IC_ARP_SIG_G0072, Disabling IC when ARP is enabled, option 1 in JCT3V-G0072, part 2 in JCT3V-G0121
-                                              // MTK_LOW_LATENCY_IC_ENCODING_H0086  Low-latency IC encoding in JCT3V-H0086
-                                              // MTK_LOW_LATENCY_IC_ENCODING_H0086_FIX  1  // Remove the global variables used in JCT3V-H0086
-                                              // SEC_IC_NEIGHBOR_CLIP_I0080    // Clipping of neighboring sample position, JCT3V-I0080
-                                              // LGE_CHROMA_IC_J0050_J0034
-#define NH_3D_IC_FIX                      1   // Fix uninitialized value in cDtParam.bUseIC (it happened on intra block)
-#define NH_3D_FULL_PEL_DEPTH_MAP_MV_ACC   1   // Full Pel Interpolation for Depth, HHI_FULL_PEL_DEPTH_MAP_MV_ACC
-#define NH_3D_QTLPC                       1   // OL_QTLIMIT_PREDCODING_B0068 //JCT3V-B0068
-                                              // HHI_QTLPC_RAU_OFF_C0160 JCT3V-C0160 change 2: quadtree limitation and predictive coding switched off in random access units 
-                                              // MTK_TEX_DEP_PAR_G0055 Texture-partition-dependent depth partition. JCT3V-G0055
-#define NH_3D_NBDV_REF                    1
-#define NH_3D_MLC                         1
-#define NH_3D_FIX_PRUNING                 1
-#define NH_3D_VSP                         1
-#define NH_3D_IV_MERGE                    1
-#define NH_3D_SPIVMP                      1
 #define NH_3D_INTEGER_MV_DEPTH            1
-#define NH_3D_TEXT_MERGE                  1
-#define NH_3D_DBBP                         1
-#define BUF_FIX 1
-#define NH_3D_ARP                         1  // Advanced residual prediction (ARP), JCT3V-D0177
-                                              // QC_MTK_INTERVIEW_ARP_F0123_F0108 JCT3V-F0123; JCT3V-F0108
-                                              // SHARP_ARP_REF_CHECK_F0105        ARP reference picture selection and DPB check
-                                              // LGE_ARP_CTX_F0161                JCT3V-F0161
-                                              // MTK_ARP_FLAG_CABAC_SIMP_G0061 Use 2 context for ARP flag referring to only left neighbor block in JCT3V-G0061
-                                              // MTK_ARP_REF_SELECTION_G0053 ARP Reference picture selection in JCT3V-G0053 
-                                              // MTK_ALIGN_SW_WD_BI_PRED_ARP_H0085  Align the SW and WD for the bi-prediction ARP PUs by disallowing non-normative fast bi-prediction for ARP PUs, JCT3V-H0085
-                                              // QC_I0051_ARP_SIMP          
-                                              // SHARP_ARP_CHROMA_I0104     
-                                              // MTK_I0072_IVARP_SCALING_FIX
-                                              // SEC_ARP_VIEW_REF_CHECK_J0037    Signaling iv_res_pred_weight_idx when the current slice has both view and temporal reference picture(s), JCT3V-J0037 item1
-                                              // SEC_ARP_REM_ENC_RESTRICT_K0035    Removal of encoder restriction of ARP, JCT3V-K0035
-#define NH_3D_DMM                         1   // Depth modeling modes
-#define NH_3D_DLT                         1   // Depth Lookup Table
-#define NH_3D_SDC_INTRA                   1   // Segment-wise DC Coding method for INTRA
-#define NH_3D_SDC_INTER                   1   // Segment-wise DC Coding method for INTER  
 #define NH_3D_ENC_DEPTH                   1   // Encoder optimizations for depth, incl.
                                               // HHI_DEPTH_INTRA_SEARCH_RAU_C0160
@@ -133,12 +84,21 @@
                                               // HHI_DMM4_ENC_I0066
                                               // H_3D_FAST_DEPTH_INTRA
-#define NH_3D_DIS                         1
 #define NH_3D_FAST_TEXTURE_ENCODING       1   // Fast merge mode decision and early CU determination for texture component of dependent view, JCT3V-E0173
-#endif
-#if H_3D
-#define H_3D_QTLPC                        1   // OL_QTLIMIT_PREDCODING_B0068 //JCT3V-B0068
+#define NH_3D_ARP                         1  // Advanced residual prediction (ARP), JCT3V-D0177
+                                             // QC_MTK_INTERVIEW_ARP_F0123_F0108 JCT3V-F0123; JCT3V-F0108
+                                             // SHARP_ARP_REF_CHECK_F0105        ARP reference picture selection and DPB check
+                                             // LGE_ARP_CTX_F0161                JCT3V-F0161
+                                             // MTK_ARP_FLAG_CABAC_SIMP_G0061 Use 2 context for ARP flag referring to only left neighbor block in JCT3V-G0061
+                                             // MTK_ARP_REF_SELECTION_G0053 ARP Reference picture selection in JCT3V-G0053 
+                                             // MTK_ALIGN_SW_WD_BI_PRED_ARP_H0085  Align the SW and WD for the bi-prediction ARP PUs by disallowing non-normative fast bi-prediction for ARP PUs, JCT3V-H0085
+                                             // QC_I0051_ARP_SIMP          
+                                             // SHARP_ARP_CHROMA_I0104     
+                                             // MTK_I0072_IVARP_SCALING_FIX
+                                             // SEC_ARP_VIEW_REF_CHECK_J0037    Signaling iv_res_pred_weight_idx when the current slice has both view and temporal reference picture(s), JCT3V-J0037 item1
+                                             // SEC_ARP_REM_ENC_RESTRICT_K0035    Removal of encoder restriction of ARP, JCT3V-K0035
+#define NH_3D_QTLPC                        1   // OL_QTLIMIT_PREDCODING_B0068 //JCT3V-B0068
                                               // HHI_QTLPC_RAU_OFF_C0160 JCT3V-C0160 change 2: quadtree limitation and predictive coding switched off in random access units 
                                               // MTK_TEX_DEP_PAR_G0055 Texture-partition-dependent depth partition. JCT3V-G0055
-#define H_3D_VSO                          1   // VSO, View synthesis optimization, includes: 
+#define NH_3D_VSO                          1   // VSO, View synthesis optimization, includes: 
                                               // HHI_VSO
                                               // HHI_VSO_LS_TABLE_M23714 enable table base Lagrange multiplier optimization
@@ -146,5 +106,5 @@
                                               // LGE_WVSO_A0119
                                               // SCU_HS_VSD_BUGFIX_IMPROV_G0163
-#define H_3D_NBDV                         1   // Neighboring block disparity derivation 
+#define NH_3D_NBDV                         1   // Neighboring block disparity derivation 
                                               // QC_JCT3V-A0097 
                                               // LGE_DVMCP_A0126
@@ -162,5 +122,5 @@
                                               // MTK_TEXTURE_MRGCAND_BUGFIX_E0182  Bug fix for TEXTURE MERGING CANDIDATE     , JCT3V-E0182
                                               // LGE_SIMP_DISP_AVAIL_J0041    // Use 2 status for disparity availability - DISP_AVAILABLE and DISP_NONE
-#define H_3D_IC                           1   // Illumination Compensation, JCT3V-B0045, JCT3V-C0046, JCT3V-D0060
+#define NH_3D_IC                          1   // Illumination Compensation, JCT3V-B0045, JCT3V-C0046, JCT3V-D0060
                                               // Unifying rounding offset, for IC part, JCT3V-D0135
                                               // Full Pel Interpolation for Depth, HHI_FULL_PEL_DEPTH_MAP_MV_ACC
@@ -176,5 +136,5 @@
                                               // LGE_CHROMA_IC_J0050_J0034
 #if NH_3D_NBDV
-#define H_3D_NBDV_REF                     1   // Depth oriented neighboring block disparity derivation
+#define NH_3D_NBDV_REF                     1   // Depth oriented neighboring block disparity derivation
                                               // MTK_D0156
                                               // MERL_D0166: Reference view selection in NBDV & Bi-VSP
@@ -184,5 +144,5 @@
                                               // SEC_VER_DONBDV_H0103          Vertical DV Restriction for DoNBDV
 #endif
-#define H_3D_VSP                          1   // View synthesis prediction
+#define NH_3D_VSP                          1   // View synthesis prediction
                                               // MERL_C0152: Basic VSP
                                               // MERL_D0166: Reference view selection in NBDV & Bi-VSP
@@ -202,5 +162,6 @@
                                               // MTK_MRG_LIST_SIZE_CLEANUP_J0059   1   // Include VSP for deriving merge candidate list size, JCT3V-J0059
                                               // SEC_A1_BASED_VSP_J0039            1   // Removal of redundant VSP in Merge list
-#define H_3D_IV_MERGE                     1   // Inter-view motion merge candidate
+#define NH_3D_MLC                          1
+#define NH_3D_IV_MERGE                     1  // Inter-view motion merge candidate
                                               // HHI_INTER_VIEW_MOTION_PRED 
                                               // SAIT_IMPROV_MOTION_PRED_M24829, improved inter-view motion vector prediction
@@ -209,8 +170,6 @@
                                               // MTK_INTERVIEW_MERGE_A0049     , second part
                                               // QC_AMVP_MRG_UNIFY_IVCAN_C0051     
-                                              // TEXTURE MERGING CANDIDATE     , JCT3V-C0137
                                               // QC_INRIA_MTK_MRG_E0126 
                                               // ETRIKHU_MERGE_REUSE_F0093 QC_DEPTH_IV_MRG_F0125, JCT3V-F0125: Depth oriented Inter-view MV candidate
-                                              // EC_MPI_ENABLING_MERGE_F0150, MPI flag in VPS and enabling in Merge mode
                                               // MTK_NBDV_IVREF_FIX_G0067      , Disable IvMC, VSP when IVREF is not available, JCT3V-G0067
                                               // SEC_DEPTH_DV_DERIVAITON_G0074, Simplification of DV derivation for depth, JCT3V-G0074
@@ -225,32 +184,51 @@
                                               // SEC_SIMP_SHIFTED_DV_I0086     Simplification of Shifted DV candidate, JCT3V-I0086
                                               // SEC_SHIFTED_IVMC_POS_K0036    Position Derivation for Shifted-IVMC, JCT3V-K0036
-#define H_3D_TMVP                         1   // QC_TMVP_C0047 
+#define NH_3D_TEXT_MERGE                  1
+                                              // TEXTURE MERGING CANDIDATE     , JCT3V-C0137
+                                              // EC_MPI_ENABLING_MERGE_F0150, MPI flag in VPS and enabling in Merge mode
+#define NH_3D_TMVP                        1   // QC_TMVP_C0047 
                                               // Sony_M23639
                                               // H_3D_TMVP_SCALING_FIX_K0053       1   // QC/CY for K0053
-#define H_3D_DIM                          1   // DIM, Depth intra modes, includes:
+#define NH_3D_DMM                         1   // Depth modeling modes
+                                              // HHI_DMM_PRED_TEX
                                               // HHI_DMM_WEDGE_INTRA
-                                              // HHI_DMM_PRED_TEX
                                               // FIX_WEDGE_NOFLOAT_D0036
                                               // LGE_EDGE_INTRA_A0070
                                               // LGE_DMM3_SIMP_C0044
                                               // QC_DC_PREDICTOR_D0183
+                                              // LGE_CONCATENATE_D0141
+                                              // PKU_QC_DEPTH_INTRA_UNI_D0195
+                                              // SEC_DMM2_E0146_HHIFIX Removal of DMM2 from DMMs
+                                              // ZJU_DEPTH_INTRA_MODE_E0204 Simplified Binarization for depth_intra_mode
+                                              // SCU_HS_DMM4_REMOVE_DIV_E0242 DMM4 Division Removal
+                                              // LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX 1   Removal of overlap between DMM3 and DMM1
+                                              // SEC_DMM3_RBC_F0147 Removal of DMM3 and RBC from DMMs
+                                              // HHI_DIM_PREDSAMP_FIX_F0171
+                                              // QC_DIM_DELTADC_UNIFY_F0132 Unify delta DC coding in depth intra modes
+                                              // LGE_SIMP_DIM_NOT_PRESENT_FLAG_CODING_H0119_H0135  Use only one context for CABAC of dim_not_present_flag
+                                              // QC_SIMP_DELTADC_CODING_H0131   Simplify detaDC entropy coding 
+                                              // MTK_DMM_SIMP_CODE_H0092        Remove CABAC context for DMM1 mode coding
+                                              // MTK_DELTA_DC_FLAG_ONE_CONTEXT_H0084_H0100_H0113 Use only one context for CABAC of delta_dc_flag as in JCTVC-H0084, JCTVC-H0100 and JCTVC-H0113
+                                              // HS_DMM_SIGNALLING_I0120
+                                              // SHARP_DMM1_I0110 LUT size reduction for DMM1 proposed in JCT3V-I0110 
+                                              // MTK_DMM_SIM_J0035
+                                              // SHARP_DMM_CLEAN_K0042             1   // Generate DMM pattern with rotation 
+#define NH_3D_DLT                         1   // Depth Lookup Table
                                               // HHI_DELTADC_DLT_D0035
-                                              // PKU_QC_DEPTH_INTRA_UNI_D0195
+                                              // LGE_PRED_RES_CODING_DLT_DOMAIN_F0159 JCT3V-F0159
+                                              // SEC_NO_RESI_DLT_H0105    
+                                              // MTK_DLT_CODING_FIX_H0091 
+                                              // H_3D_DELTA_DLT
+                                              // RWTH_DLT_CLIP_I0057
+                                              // SHARP_DLT_SIMP_J0029 DLT(DepthValue2Idx[]) table derivation cleanup  
+#define NH_3D_SDC_INTRA                   1   // Segment-wise DC Coding method for INTRA
+#define NH_3D_SDC_INTER                   1   // Segment-wise DC Coding method for INTER  
                                               // RWTH_SDC_DLT_B0036
                                               // INTEL_SDC64_D0193
                                               // RWTH_SDC_CTX_SIMPL_D0032
-                                              // LGE_CONCATENATE_D0141
                                               // FIX_SDC_ENC_RD_WVSO_D0163
                                               // MTK_SAMPLE_BASED_SDC_D0110
-                                              // SEC_DMM2_E0146_HHIFIX Removal of DMM2 from DMMs
-                                              // ZJU_DEPTH_INTRA_MODE_E0204 Simplified Binarization for depth_intra_mode
                                               // KWU_SDC_SIMPLE_DC_E0117 Simplified DC calculation for SDC
-                                              // SCU_HS_DMM4_REMOVE_DIV_E0242 DMM4 Division Removal
                                               // LGE_SDC_REMOVE_DC_E0158 Removal of DC mode from SDC
-                                              // LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX 1   Removal of overlap between DMM3 and DMM1
-                                              // LGE_PRED_RES_CODING_DLT_DOMAIN_F0159 JCT3V-F0159
-                                              // HHI_DIM_PREDSAMP_FIX_F0171
-                                              // SEC_DMM3_RBC_F0147 Removal of DMM3 and RBC from DMMs
-                                              // QC_DIM_DELTADC_UNIFY_F0132 Unify delta DC coding in depth intra modes
                                               // Unify intra SDC and inter SDC
                                               // QC_GENERIC_SDC_G0122 Generalize SDC to all depth intra modes
@@ -259,31 +237,16 @@
                                               // QC_PKU_SDC_SPLIT_G0123 Intra SDC Split
                                               // HS_DMM_SDC_PREDICTOR_UNIFY_H0108  Unification of DMM and SDC predictor derivation
-                                              // LGE_SIMP_DIM_NOT_PRESENT_FLAG_CODING_H0119_H0135  Use only one context for CABAC of dim_not_present_flag
-                                              // QC_SIMP_DELTADC_CODING_H0131   Simplify detaDC entropy coding 
-                                              // MTK_DMM_SIMP_CODE_H0092        Remove CABAC context for DMM1 mode coding
-                                              // MTK_DELTA_DC_FLAG_ONE_CONTEXT_H0084_H0100_H0113 Use only one context for CABAC of delta_dc_flag as in JCTVC-H0084, JCTVC-H0100 and JCTVC-H0113
                                               // MTK_SDC_FLAG_FIX_H0095                          Remove conditional check of PCM flag based on SDC flag, JCTVC-H0095
-                                              // SEC_NO_RESI_DLT_H0105    
-                                              // MTK_DLT_CODING_FIX_H0091 
-                                              // HS_DMM_SIGNALLING_I0120
-                                              // SHARP_DMM1_I0110 LUT size reduction for DMM1 proposed in JCT3V-I0110 
                                               // FAST_SDC_OFFSET_DECISION_I0084
                                               // SEPARATE_FLAG_I0085
-                                              // H_3D_DELTA_DLT
-                                              // RWTH_DLT_CLIP_I0057
-                                              // MTK_DMM_SIM_J0035
                                               // MTK_J0033
-                                              // SHARP_DLT_SIMP_J0029 DLT(DepthValue2Idx[]) table derivation cleanup
-                                              // SHARP_DMM_CLEAN_K0042             1   // Generate DMM pattern with rotation 
-#define H_3D_INTER_SDC                    1   // INTER SDC, Inter simplified depth coding
                                               // LGE_INTER_SDC_E0156 Enable inter SDC for depth coding
                                               // SEC_INTER_SDC_G0101 Improved inter SDC with multiple DC candidates
-#define H_3D_INTER_SDC_FIX                1
-#define H_3D_SPIVMP                       1   // H_3D_SPIVMP JCT3V-F0110: Sub-PU level inter-view motion prediction
+#define NH_3D_SPIVMP                       1   // H_3D_SPIVMP JCT3V-F0110: Sub-PU level inter-view motion prediction
                                               // SEC_SPIVMP_MCP_SIZE_G0077, Apply SPIVMP only to 2Nx2N partition, JCT3V-G0077
                                               // QC_SPIVMP_MPI_G0119 Sub-PU level MPI merge candidate
                                               // Simplification on Sub-PU level temporal interview motion prediction
                                               // MPI_SUBPU_DEFAULT_MV_H0077_H0099_H0111_H0133
-#define H_3D_DBBP                         1   // DBBP: Depth-based Block Partitioning and Merging
+#define NH_3D_DBBP                         1   // DBBP: Depth-based Block Partitioning and Merging
                                               // MTK_DBBP_AMP_REM_H0072   
                                               // RWTH_DBBP_NO_SPU_H0057   
@@ -298,18 +261,10 @@
                                               // RWTH_DBBP_NO_SATD_K0028
                                               // HS_DBBP_CLEAN_K0048
-#define H_3D_DDD                          1   // Disparity derived depth coding
-                                              // LGE_DDD_REMOVAL_J0042_J0030 DDD removal
-#define H_3D_DIS                          1   // Depth intra skip 
+#define NH_3D_DIS                         1   // Depth intra skip 
                                               // SEC_DEPTH_INTRA_SKIP_MODE_K0033  Depth intra skip mode
 #define H_3D_FCO                          0   // Flexible coding order for 3D
-#define H_3D_FAST_INTRA_SDC               1   // I0123
 // OTHERS
                                               // MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170 // Progressive MV Compression, JCT3V-E0170
-#define H_3D_FAST_TEXTURE_ENCODING        1   // Fast merge mode decision and early CU determination for texture component of dependent view, JCT3V-E0173
                                               // MTK_FAST_TEXTURE_ENCODING_E0173
-#if H_3D_DIM
-#define H_3D_FAST_DEPTH_INTRA             1   // Fast DMM Selection
-                                              // SCU_HS_FAST_DEPTH_INTRA_E0238_HHIFIX
-#endif
 //HLS
                                              // HHI_DEPENDENCY_SIGNALLING_I1_J0107
@@ -321,8 +276,8 @@
                                              // H_3D_DIRECT_DEP_TYPE     
 // Rate Control
-#define KWU_FIX_URQ                       1
+#define KWU_FIX_URQ                       0
 #define KWU_RC_VIEWRC_E0227               0  ///< JCT3V-E0227, view-wise target bitrate allocation
 #define KWU_RC_MADPRED_E0227              0  ///< JCT3V-E0227, inter-view MAD prediction
-#endif // H_3D
+#endif // NH_3D
 /////////////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////   DERIVED DEFINES ///////////////////////////////////  
@@ -349,14 +304,4 @@
 #if NH_3D_ARP
 #define H_3D_ARP_WFNR                     3
-#endif
-///// ***** DEPTH INTRA MODES *********
-#if H_3D_DIM
-                                              // HHI_DMM4_ENC_I0066
-#define H_3D_DIM_DMM                      1   // Depth Modeling Modes
-#define H_3D_DIM_SDC                      1   // Simplified Depth Coding method
-#define H_3D_DIM_DLT                      1   // Depth Lookup Table
-#define H_3D_DIM_ENC                      1   // Depth Intra encoder optimizations, includes:
-                                              // HHI_DEPTH_INTRA_SEARCH_RAU_C0160
-                                              // LG_ZEROINTRADEPTHRESI_A0087
 #endif
 /////////////////////////////////////////////////////////////////////////////////////
@@ -389,32 +334,4 @@
 // TBD: Check if integration is necessary. 
 #define H_MV_HLS_PTL_LIMITS                  0
-#define H_MV_HLS7_GEN                        0  // General changes (not tested)
-// POC
-// #define H_MV_HLS_7_POC_P0041_3            0 // (POC/P0041/POC reset) #3 It was remarked that we should require each non-IRAP picture that has discardable_flag equal to 1 to have NUT value indicating that it is a sub-layer non-reference picture. This was agreed. Decision: Adopt (with constraint for discardable_flag as described above) 
-// #define H_MV_HLS_7_POC_P0041_FIXES        0 // (POC/P0041/Fixes) For each non-IRAP picture that has discardable_flag equal to 1 to have NUT value indicating that it is a sub-layer non-reference picture. 
-// #define H_MV_HLS_7_POC_P0056_4            0 // (POC/P0056/layer tree poc) #4 Proposal 1: If the POC reset approach is adopted as the basis for multi-layer POC derivation, it is proposed to derive the POC anchor picture from the previous TID0 picture (that is not a RASL picture, a RADL picture or a sub-layer non-reference picture and not with discardable_flag equal to 1) of  the current layer or any of its reference layer. This is asserted to improve loss resilience and reduce bit rate overhead. Decision: Adopt Proposal 1 (with the suggested modifications Ewith text provided as P0297).
-// SEI related
-//#define H_MV_HLS_8_SEI_NODOC_53  0 // #53 (SEI    /NODOC/Added Multiview view position SEI message) Plain copy from AVC.
-//#define H_MV_HLS_8_SEI_NODOC_52  0 // #52 (SEI    /NODOC/Added Multiview acquisition information SEI) Plain copy from AVC. 
-//#define H_MV_HLS_8_SEI_NODOC_51  0 // #51 (SEI    /NODOC/Added Multiview scene information SEI message)
-//#define H_MV_HLS_8_SEI_Q0189_35  0 // #35 (SEI    /Q0189/SEI message for indicating constraints on TMVP) Proposal 2.3,  SEI message for indicating constraints on TMVP
-//#define H_MV_HLS_8_EDF_Q0116_29  0 // #29 (ED.FIX /Q0116/Recovery point SEI) , consider adding a note regarding how random accessibility is affected by the recovery point SEI message
-//#define H_MV_HLS_8_GEN_Q0183_23  0 // #23 (GEN    /Q0183/SEI clean-ups) numerous small clean-ups on SEI messages.
-//#define H_MV_HLS_8_MIS_Q0247_49  0 // #49 (MISC   /Q0247/frame-field information SEI message)
-//#define H_MV_HLS_8_MIS_Q0189_34  0 // #34 (MISC   /Q0189/slice temporal mvp enabled flag) Proposal 2.2, clarification of semantics of slice temporal mvp enabled flag
-//#define H_MV_HLS_8_EDF_Q0081_01  0 // #1  (ED.FIX /Q0081/alpha channel persist) On reuse of alpha planes in auxiliary pictures. It was asked why there would not be a presumption that the alpha channel content would simply persist, without needing the flag to indicate it. Decision (Ed.): Delegated to editors to clarify, as necessary, that the alpha channel content persists until cancelled or updated in output order.
-//#define H_MV_HLS_8_SEI_Q0253_37  0 // #37 (SEI    /Q0253/layer not present), modified semantics of layers not present SEI message to correct bug introduced during editing 
-//#define H_MV_HLS_8_SEI_Q0045_11  0 // #11 (SEI    /Q0045/Overlay) Proposal for an SEI message on selectable overlays. Decision: Adopt (modified for variable-length strings).
-//#define H_MV_HLS_7_SEI_P0133_28  0 // (SEI/P0133/Recovery point SEI) #28 Decision: Adopt change to recover point semantics only (-v3)
-//#define H_MV_HLS_7_SEI_P0123_25  0 // (SEI/P0123/Alpha channel info) #25 Add alpha channel information SEI message Decision: Adopt. Constrain the bit depth indicated to be equal to the coded bit depth of the aux picture. 
-// DPB
-//#define H_MV_HLS_8_HRD_Q0102_09  0 // #9  (HRD    /Q0102/NoOutputOfPriorPicsFlag) It was suggested that also the separate_colour_plane_flag should affect inference of NoOutputOfPriorPicsFlag. Decision (Ed.): Agreed (affects RExt text).
-//#define H_MV_HLS_8_DBP_Q0154_38  0 // #38 (DBP    /Q0154/VPS DPB) Proposal in C.5.2.1: Add in the decoding process that when a new VPS is activated, all pictures in the DPB are marked as unused for reference
-//#define H_MV_HLS_8_HRD_Q0154_10  0 // #10 (HRD    /Q0154/DPB Flushing and parameters) On picture flushing and DPB parameters Decision: Adopted (some details to be discussed further in BoG).
-//#define H_MV_HLS_7_OTHER_P0187_1 0 // (OTHER/P0187/NoOutputOfPriorPicsFlag) #1 Inference of NoOutputOfPriorPicsFlag and proposes to take into account colour format and bit depth for the inference in addition to spatial resolution 
-// OTHERS
-//#define H_MV_HLS_8_HSB_Q0041_03  0 // #3  (HS     /Q0041/hybrid scalability) The proposed text was endorsed, with non-editorial open issues considered as follows ?// #define H_MV_HLS_7_OTHER_P0187_1          0 // (OTHER/P0187/NoOutputOfPriorPicsFlag) #1 Inference of NoOutputOfPriorPicsFlag and proposes to take into account colour format and bit depth for the inference in addition to spatial resolution 
-//#define H_MV_HLS_8_MIS_Q0078_24  0 // #24 (MISC   /Q0078/scan and pic type) , Items 3 b,c and 4, clarifying which pictures in an output layer sets are applied the values of general_progressive_source_flag, general_interlaced_source_flag, general_non_packed_constraint_flag and general_frame_only_constraint_flag.
-//#define H_MV_HLS_7_HRD_P0138_6   0 //     (HRD/P0138/HRD parameters for bitstreams excluding) #6 Decision: Adopt (as revised in updated contribution, with the specification of a flag in the BP SEI (HRD/P0192/sub-DPB) #12 Establish sub-DPBs based on the representation format indicated at the VPS level. It was suggested that the expressed shared capacity limit would need to be less than or equal to the sum of the individual capacity limits. Decision: Adopt as modified. Further study is encouraged on profile/level constraint selections. 
 /////////////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////   HM RELATED DEFINES ////////////////////////////////
@@ -871,4 +788,16 @@
 #define NUM_SAO_BO_CLASSES_LOG2  5
 #define NUM_SAO_BO_CLASSES       (1<<NUM_SAO_BO_CLASSES_LOG2)
+#if NH_MV
+enum DecodingProcess
+{
+  INVALID,
+  CLAUSE_8,
+  ANNEX_C,
+  ANNEX_F,
+  ANNEX_G,
+  ANNEX_H,
+  ANNEX_I  
+};
+#endif
 namespace Profile
 {
@@ -1017,4 +946,9 @@
   AUX_ID = 3,
 };
+enum DecProcPart
+{
+  START_PIC,
+  FINALIZE_PIC
+};
 #endif
 #if NH_3D
Index: trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 1314)
+++ trunk/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 1321)
@@ -66,4 +66,10 @@
   fprintf( g_hTrace, "=========== Picture Parameter Set  ===========\n");
 }
+
+Void  xTraceSliceHeader ()
+{
+  fprintf( g_hTrace, "=========== Slice ===========\n");
+}
+
 #endif
 #endif
@@ -85,4 +91,47 @@
 // ====================================================================================================================
 
+#if NH_MV
+Void TDecCavlc::parseShortTermRefPicSet( TComSPS* sps, TComStRefPicSet* stRps, Int stRpsIdx )
+{
+  UInt uiCode;  
+  if( stRpsIdx  !=  0 )
+  {
+    READ_FLAG( uiCode, "inter_ref_pic_set_prediction_flag" ); stRps->setInterRefPicSetPredictionFlag( uiCode == 1 );
+  }
+  if( stRps->getInterRefPicSetPredictionFlag() )
+  {
+    if( stRpsIdx  ==  sps->getNumShortTermRefPicSets() )
+    {
+      READ_UVLC( uiCode, "delta_idx_minus1" ); stRps->setDeltaIdxMinus1( uiCode );
+    }
+    READ_FLAG( uiCode, "delta_rps_sign" ); stRps->setDeltaRpsSign( uiCode == 1 );
+    READ_UVLC( uiCode, "abs_delta_rps_minus1" ); stRps->setAbsDeltaRpsMinus1( uiCode );
+    for( Int j = 0; j  <=  sps->getStRefPicSet( stRps->getRefRpsIdx( stRpsIdx ) )->getNumDeltaPocs() ; j++ )
+    {
+      READ_FLAG( uiCode, "used_by_curr_pic_flag" ); stRps->setUsedByCurrPicFlag( j, uiCode == 1 );
+      if( !stRps->getUsedByCurrPicFlag( j ) )
+      {
+        READ_FLAG( uiCode, "use_delta_flag" ); stRps->setUseDeltaFlag( j, uiCode == 1 );
+      }
+    }
+  }
+  else
+  {
+    READ_UVLC( uiCode, "num_negative_pics" ); stRps->setNumNegativePics( uiCode );
+    READ_UVLC( uiCode, "num_positive_pics" ); stRps->setNumPositivePics( uiCode );
+    for( Int i = 0; i < stRps->getNumNegativePics( ); i++ )
+    {
+      READ_UVLC( uiCode, "delta_poc_s0_minus1" ); stRps->setDeltaPocS0Minus1( i, uiCode );
+      READ_FLAG( uiCode, "used_by_curr_pic_s0_flag" ); stRps->setUsedByCurrPicS0Flag( i, uiCode == 1 );
+    }
+    for( Int i = 0; i < stRps->getNumPositivePics( ); i++ )
+    {
+      READ_UVLC( uiCode, "delta_poc_s1_minus1" ); stRps->setDeltaPocS1Minus1( i, uiCode );
+      READ_FLAG( uiCode, "used_by_curr_pic_s1_flag" ); stRps->setUsedByCurrPicS1Flag( i, uiCode == 1 );
+    }
+  }
+  stRps->inferRps( stRpsIdx, sps, false );
+}
+#else
 Void TDecCavlc::parseShortTermRefPicSet( TComSPS* sps, TComReferencePictureSet* rps, Int idx )
 {
@@ -180,4 +229,5 @@
 #endif
 }
+#endif
 
 Void TDecCavlc::parsePPS(TComPPS* pcPPS)
@@ -507,18 +557,10 @@
   {
     READ_CODE(6, uiCode, "pps_depth_layers_minus1");
-#if NH_3D_VER141_DEC_COMP_FLAG
-    pcDLT->setNumDepthViews( uiCode );
-#else
     pcDLT->setNumDepthViews( uiCode+1 );
-#endif
     
     READ_CODE(4, uiCode, "pps_bit_depth_for_depth_layers_minus8");
     pcDLT->setDepthViewBitDepth( (uiCode+8) );
     
-#if NH_3D_DLT_FIX
     for( Int i = 0; i <= pcDLT->getNumDepthViews()-1; i++ )
-#else
-    for( Int i = 0; i <= pcDLT->getNumDepthViews(); i++ )
-#endif
     {
       Int layerId = pcDLT->getDepthIdxToLayerId(i);
@@ -866,5 +908,5 @@
 #if NH_MV
     pcSPS->getPTL()->inferGeneralValues ( true, 0, NULL ); 
-    pcSPS->getPTL()->inferSubLayerValues( pcSPS->getMaxTLayers() - 1, 0, NULL );
+    pcSPS->getPTL()->inferSubLayerValues( pcSPS->getSpsMaxSubLayersMinus1(), 0, NULL );
   }
 #endif
@@ -972,5 +1014,9 @@
     pcSPS->setNumReorderPics(uiCode, i);
     READ_UVLC ( uiCode, "sps_max_latency_increase_plus1[i]");
+#if NH_MV
+    pcSPS->setSpsMaxLatencyIncreasePlus1( uiCode, i );
+#else
     pcSPS->setMaxLatencyIncrease( uiCode, i );
+#endif
 
     if (!subLayerOrderingInfoPresentFlag)
@@ -980,5 +1026,9 @@
         pcSPS->setMaxDecPicBuffering(pcSPS->getMaxDecPicBuffering(0), i);
         pcSPS->setNumReorderPics(pcSPS->getNumReorderPics(0), i);
+#if NH_MV
+        pcSPS->setSpsMaxLatencyIncreasePlus1(pcSPS->getSpsMaxLatencyIncreasePlus1(0), i);
+#else
         pcSPS->setMaxLatencyIncrease(pcSPS->getMaxLatencyIncrease(0), i);
+#endif
       }
       break;
@@ -1053,5 +1103,18 @@
 
   READ_UVLC( uiCode, "num_short_term_ref_pic_sets" );
+
   assert(uiCode <= 64);
+#if NH_MV
+  pcSPS->setNumShortTermRefPicSets( uiCode );  
+  pcSPS->initStRefPicSets();
+
+  for(Int i=0; i< pcSPS->getNumShortTermRefPicSets(); i++ )
+  {
+    parseShortTermRefPicSet(pcSPS,pcSPS->getStRefPicSet(i),i);
+  }
+
+  READ_FLAG( uiCode, "long_term_ref_pics_present_flag" );          pcSPS->setLongTermRefPicsPresentFlag(uiCode);
+  if (pcSPS->getLongTermRefPicsPresentFlag() )
+#else
   pcSPS->createRPSList(uiCode);
 
@@ -1064,6 +1127,8 @@
     parseShortTermRefPicSet(pcSPS,rps,i);
   }
+
   READ_FLAG( uiCode, "long_term_ref_pics_present_flag" );          pcSPS->setLongTermRefsPresent(uiCode);
   if (pcSPS->getLongTermRefsPresent())
+#endif
   {
     READ_UVLC( uiCode, "num_long_term_ref_pics_sps" );
@@ -2149,13 +2214,30 @@
 #endif
 
+#if NH_MV
+Void TDecCavlc::parseFirstSliceSegmentInPicFlag(TComSlice* pcSlice )
+{
+#if ENC_DEC_TRACE
+#if NH_MV
+  tracePSHeader( "Slice", pcSlice->getLayerId() ); 
+#else
+  xTraceSliceHeader();
+#endif
+#endif
+
+  UInt uiCode;
+  READ_FLAG( uiCode, "first_slice_segment_in_pic_flag" );
+  pcSlice->setFirstSliceSegementInPicFlag( uiCode ); 
+}
+
+Void TDecCavlc::parseSliceHeader (TComSlice* pcSlice, ParameterSetManager *parameterSetManager )
+#else
 Void TDecCavlc::parseSliceHeader (TComSlice* pcSlice, ParameterSetManager *parameterSetManager, const Int prevTid0POC)
+#endif
 {
   UInt  uiCode;
   Int   iCode;
 
+#if !NH_MV
 #if ENC_DEC_TRACE
-#if NH_MV
-  tracePSHeader( "Slice", pcSlice->getLayerId() ); 
-#else
   xTraceSliceHeader();
 #endif
@@ -2167,6 +2249,11 @@
 #endif
 
+#if NH_MV
+  // This has been parsed before in parseFirstSliceSegmentFlag(TComSlice* pcSlice )
+  UInt firstSliceSegmentInPic = pcSlice->getFirstSliceSegementInPicFlag();   
+#else
   UInt firstSliceSegmentInPic;
   READ_FLAG( firstSliceSegmentInPic, "first_slice_segment_in_pic_flag" );
+#endif
   if( pcSlice->getRapPicFlag())
   {
@@ -2184,5 +2271,13 @@
   vps = parameterSetManager->getVPS(sps->getVPSId());
   assert( vps != NULL );  
+  
   m_decTop->initFromActiveVps( vps );
+  
+  if ( !m_decTop->getIsInOwnTargetDecLayerIdList() )
+  {
+    return; 
+  }
+
+  pcSlice->setDecodingProcess( m_decTop->getDecodingProcess() ); 
   Int targetOlsIdx = m_decTop->getTargetOlsIdx(); 
 
@@ -2241,8 +2336,4 @@
   pcSlice->setSliceSegmentCurStartCtuTsAddr( sliceSegmentAddress );// this is actually a Raster-Scan (RS) address, but we do not have the RS->TS conversion table defined yet.
   pcSlice->setSliceSegmentCurEndCtuTsAddr(numCTUs);                // Set end as the last CTU of the picture.
-
-#if NH_MV
-    UInt slicePicOrderCntLsb = 0;
-#endif
 
 
@@ -2303,253 +2394,229 @@
 
 #if NH_MV
-    Int iPOClsb = slicePicOrderCntLsb;  // Needed later
     if ( (pcSlice->getLayerId() > 0 && !vps->getPocLsbNotPresentFlag( pcSlice->getLayerIdInVps())) || !pcSlice->getIdrPicFlag() )
     {
-      READ_CODE(sps->getBitsForPOC(), slicePicOrderCntLsb, "slice_pic_order_cnt_lsb");        
-    }    
-    pcSlice->setSlicePicOrderCntLsb( slicePicOrderCntLsb ); 
-
-    Bool picOrderCntMSBZeroFlag = false;     
-
-    // as in HM code. However are all cases for IRAP picture with NoRaslOutputFlag equal to 1 covered??
-    picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP   ); 
-    picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL ); 
-    picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP   ); 
-    picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag ||   pcSlice->getIdrPicFlag(); 
-
-    // TBD picOrderCntMSBZeroFlag = picOrderCntMSBZeroFlag || ( rpcSlice->getLayerId() > 0 &&   !rpcSlice->getFirstPicInLayerDecodedFlag() ); 
-
-    Int picOrderCntMSB = 0; 
-
-    if ( !picOrderCntMSBZeroFlag )
-    {
-      Int prevPicOrderCnt    = prevTid0POC;
-      Int maxPicOrderCntLsb  = 1 << sps->getBitsForPOC();
-      Int prevPicOrderCntLsb = prevPicOrderCnt & (maxPicOrderCntLsb - 1);
-      Int prevPicOrderCntMsb = prevPicOrderCnt - prevPicOrderCntLsb;
-            
-      if( ( slicePicOrderCntLsb  <  prevPicOrderCntLsb ) && ( ( prevPicOrderCntLsb - slicePicOrderCntLsb )  >=  ( maxPicOrderCntLsb / 2 ) ) )
-      {
-        picOrderCntMSB = prevPicOrderCntMsb + maxPicOrderCntLsb;
-      }
-      else if( (slicePicOrderCntLsb  >  prevPicOrderCntLsb )  && ( (slicePicOrderCntLsb - prevPicOrderCntLsb )  >  ( maxPicOrderCntLsb / 2 ) ) ) 
-      {
-        picOrderCntMSB = prevPicOrderCntMsb - maxPicOrderCntLsb;
-      }
-      else
-      {
-        picOrderCntMSB = prevPicOrderCntMsb;
-      }   
-    }
-      
-    pcSlice->setPOC( picOrderCntMSB + slicePicOrderCntLsb );
-    if ( pcSlice->getPocResetFlag() )  
-    {
-      pcSlice->setPocBeforeReset   ( pcSlice->getPOC() ); 
-      pcSlice->setPOC              ( 0 );
-    }      
-#endif
-
-    if( pcSlice->getIdrPicFlag() )
-    {
-#if !NH_MV
-      pcSlice->setPOC(0);
-#endif
-      TComReferencePictureSet* rps = pcSlice->getLocalRPS();
-      (*rps)=TComReferencePictureSet();
-      pcSlice->setRPS(rps);
-#if NH_MV
-      pcSlice->setEnableTMVPFlag(false);
-#endif
-    }
+      READ_CODE(sps->getBitsForPOC(), uiCode, "slice_pic_order_cnt_lsb"); pcSlice->setSlicePicOrderCntLsb( uiCode );
+    } 
     else
     {
-#if !NH_MV
-      READ_CODE(sps->getBitsForPOC(), uiCode, "slice_pic_order_cnt_lsb");
-      Int iPOClsb = uiCode;
-      Int iPrevPOC = prevTid0POC;
-      Int iMaxPOClsb = 1<< sps->getBitsForPOC();
-      Int iPrevPOClsb = iPrevPOC & (iMaxPOClsb - 1);
-      Int iPrevPOCmsb = iPrevPOC-iPrevPOClsb;
-      Int iPOCmsb;
-      if( ( iPOClsb  <  iPrevPOClsb ) && ( ( iPrevPOClsb - iPOClsb )  >=  ( iMaxPOClsb / 2 ) ) )
-      {
-        iPOCmsb = iPrevPOCmsb + iMaxPOClsb;
-      }
-      else if( (iPOClsb  >  iPrevPOClsb )  && ( (iPOClsb - iPrevPOClsb )  >  ( iMaxPOClsb / 2 ) ) )
-      {
-        iPOCmsb = iPrevPOCmsb - iMaxPOClsb;
-      }
-      else
-      {
-        iPOCmsb = iPrevPOCmsb;
-      }
-      if ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
-        || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
-        || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
-      {
-        // For BLA picture types, POCmsb is set to 0.
-        iPOCmsb = 0;
-      }
-      pcSlice->setPOC              (iPOCmsb+iPOClsb);
-#endif
-      TComReferencePictureSet* rps;
-      rps = pcSlice->getLocalRPS();
-      (*rps)=TComReferencePictureSet();
-
-      pcSlice->setRPS(rps);
-      READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" );
-      if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header
-      {
-        parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets());
-#if NH_MV
-        if ( !rps->getInterRPSPrediction( ) )
-        { // check sum of num_positive_pics and num_negative_pics
-          rps->checkMaxNumPics( 
-            vps->getVpsExtensionFlag(), 
-            MAX_INT,  // To be replaced by MaxDbpSize
-            pcSlice->getLayerId(), 
-            sps->getMaxDecPicBuffering( sps->getSpsMaxSubLayersMinus1() ) - 1 );
-        }
-#endif
-
-      }
-      else // use reference to short-term reference picture set in PPS
-      {
-        Int numBits = 0;
-        while ((1 << numBits) < sps->getRPSList()->getNumberOfReferencePictureSets())
-        {
-          numBits++;
-        }
-        if (numBits > 0)
-        {
-          READ_CODE( numBits, uiCode, "short_term_ref_pic_set_idx");
-        }
-        else
-        {
-          uiCode = 0;
-       
-        }
-        *rps = *(sps->getRPSList()->getReferencePictureSet(uiCode));
-      }
-      if(sps->getLongTermRefsPresent())
-      {
-        Int offset = rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures();
-        UInt numOfLtrp = 0;
-        UInt numLtrpInSPS = 0;
-        if (sps->getNumLongTermRefPicSPS() > 0)
-        {
-          READ_UVLC( uiCode, "num_long_term_sps");
-          numLtrpInSPS = uiCode;
-          numOfLtrp += numLtrpInSPS;
-          rps->setNumberOfLongtermPictures(numOfLtrp);
-        }
-        Int bitsForLtrpInSPS = 0;
-        while (sps->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS))
-        {
-          bitsForLtrpInSPS++;
-        }
-        READ_UVLC( uiCode, "num_long_term_pics");             rps->setNumberOfLongtermPictures(uiCode);
-        numOfLtrp += uiCode;
-        rps->setNumberOfLongtermPictures(numOfLtrp);
-        Int maxPicOrderCntLSB = 1 << sps->getBitsForPOC();
-        Int prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;
-        for(Int j=offset+rps->getNumberOfLongtermPictures()-1, k = 0; k < numOfLtrp; j--, k++)
-        {
-          Int pocLsbLt;
-          if (k < numLtrpInSPS)
+      pcSlice->setSlicePicOrderCntLsb( 0 );
+    }
+
+    if( pcSlice->getNalUnitType()  != NAL_UNIT_CODED_SLICE_IDR_W_RADL  &&  pcSlice->getNalUnitType() !=  NAL_UNIT_CODED_SLICE_IDR_N_LP )
+    {      
+      READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" ); pcSlice->setShortTermRefPicSetSpsFlag( uiCode == 1 );
+      if( !pcSlice->getShortTermRefPicSetSpsFlag() )
+      {
+        parseShortTermRefPicSet( sps, pcSlice->getLocalStRps( ), sps->getNumShortTermRefPicSets() );
+      }
+      else if( sps->getNumShortTermRefPicSets() > 1 )
+      {
+        READ_CODE( pcSlice->getShortTermRefPicSetIdxLen() , uiCode, "short_term_ref_pic_set_idx" ); pcSlice->setShortTermRefPicSetIdx( uiCode );
+      }
+      if( sps->getLongTermRefPicsPresentFlag() )
+      {
+        if( sps->getNumLongTermRefPicsSps() > 0 )
+        {
+          READ_UVLC( uiCode, "num_long_term_sps" ); pcSlice->setNumLongTermSps( uiCode );
+        }
+        READ_UVLC( uiCode, "num_long_term_pics" ); pcSlice->setNumLongTermPics( uiCode );
+        for( Int i = 0; i < pcSlice->getNumLongTermSps() + pcSlice->getNumLongTermPics( ); i++ )
+        {
+          if( i < pcSlice->getNumLongTermSps() )
           {
-            uiCode = 0;
-            if (bitsForLtrpInSPS > 0)
+            if( sps->getNumLongTermRefPicsSps() > 1 )
             {
-              READ_CODE(bitsForLtrpInSPS, uiCode, "lt_idx_sps[i]");
+              READ_CODE( pcSlice->getLtIdxSpsLen() , uiCode, "lt_idx_sps" ); pcSlice->setLtIdxSps( i, uiCode );
             }
-            Bool usedByCurrFromSPS=sps->getUsedByCurrPicLtSPSFlag(uiCode);
-
-            pocLsbLt = sps->getLtRefPicPocLsbSps(uiCode);
-            rps->setUsed(j,usedByCurrFromSPS);
           }
           else
           {
-            READ_CODE(sps->getBitsForPOC(), uiCode, "poc_lsb_lt"); pocLsbLt= uiCode;
-            READ_FLAG( uiCode, "used_by_curr_pic_lt_flag");     rps->setUsed(j,uiCode);
+            READ_CODE( pcSlice->getPocLsbLtLen() , uiCode, "poc_lsb_lt" ); pcSlice->setPocLsbLt( i, uiCode );
+            READ_FLAG( uiCode, "used_by_curr_pic_lt_flag" ); pcSlice->setUsedByCurrPicLtFlag( i, uiCode == 1 );
           }
-          READ_FLAG(uiCode,"delta_poc_msb_present_flag");
-          Bool mSBPresentFlag = uiCode ? true : false;
-          if(mSBPresentFlag)
+          READ_FLAG( uiCode, "delta_poc_msb_present_flag" ); pcSlice->setDeltaPocMsbPresentFlag( i, uiCode == 1 );
+          if( pcSlice->getDeltaPocMsbPresentFlag( i ) )
           {
-            READ_UVLC( uiCode, "delta_poc_msb_cycle_lt[i]" );
-            Bool deltaFlag = false;
-            //            First LTRP                               || First LTRP from SH
-            if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (j == offset+(numOfLtrp-numLtrpInSPS)-1) )
-            {
-              deltaFlag = true;
-            }
-            if(deltaFlag)
-            {
-              deltaPocMSBCycleLT = uiCode;
-            }
-            else
-            {
-              deltaPocMSBCycleLT = uiCode + prevDeltaMSB;
-            }
-
-            Int pocLTCurr = pcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB
-                                        - iPOClsb + pocLsbLt;
-            rps->setPOC     (j, pocLTCurr);
-            rps->setDeltaPOC(j, - pcSlice->getPOC() + pocLTCurr);
-            rps->setCheckLTMSBPresent(j,true);
+            READ_UVLC( uiCode, "delta_poc_msb_cycle_lt" ); pcSlice->setDeltaPocMsbCycleLt( i, uiCode );
           }
-          else
-          {
+        }
+      }
+      if( sps->getSpsTemporalMvpEnabledFlag() )
+      {
+        READ_FLAG( uiCode, "slice_temporal_mvp_enabled_flag" ); pcSlice->setSliceTemporalMvpEnabledFlag( uiCode == 1 );
+      }
+    }
+#else
+if( pcSlice->getIdrPicFlag() )
+{
+  pcSlice->setPOC(0);
+  TComReferencePictureSet* rps = pcSlice->getLocalRPS();
+  (*rps)=TComReferencePictureSet();
+  pcSlice->setRPS(rps);
+}
+else
+{
+  READ_CODE(sps->getBitsForPOC(), uiCode, "slice_pic_order_cnt_lsb");
+  Int iPOClsb = uiCode;
+  Int iPrevPOC = prevTid0POC;
+  Int iMaxPOClsb = 1<< sps->getBitsForPOC();
+  Int iPrevPOClsb = iPrevPOC & (iMaxPOClsb - 1);
+  Int iPrevPOCmsb = iPrevPOC-iPrevPOClsb;
+  Int iPOCmsb;
+  if( ( iPOClsb  <  iPrevPOClsb ) && ( ( iPrevPOClsb - iPOClsb )  >=  ( iMaxPOClsb / 2 ) ) )
+  {
+    iPOCmsb = iPrevPOCmsb + iMaxPOClsb;
+  }
+  else if( (iPOClsb  >  iPrevPOClsb )  && ( (iPOClsb - iPrevPOClsb )  >  ( iMaxPOClsb / 2 ) ) )
+  {
+    iPOCmsb = iPrevPOCmsb - iMaxPOClsb;
+  }
+  else
+  {
+    iPOCmsb = iPrevPOCmsb;
+  }
+  if ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
+    || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
+    || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
+  {
+    // For BLA picture types, POCmsb is set to 0.
+    iPOCmsb = 0;
+  }
+  pcSlice->setPOC              (iPOCmsb+iPOClsb);
+
+  TComReferencePictureSet* rps;
+  rps = pcSlice->getLocalRPS();
+  (*rps)=TComReferencePictureSet();
+
+  pcSlice->setRPS(rps);
+  READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" );
+  if(uiCode == 0) // use short-term reference picture set explicitly signalled in slice header
+  {
+    parseShortTermRefPicSet(sps,rps, sps->getRPSList()->getNumberOfReferencePictureSets());
+  }
+  else // use reference to short-term reference picture set in PPS
+  {
+    Int numBits = 0;
+    while ((1 << numBits) < sps->getRPSList()->getNumberOfReferencePictureSets())
+    {
+      numBits++;
+    }
+    if (numBits > 0)
+    {
+      READ_CODE( numBits, uiCode, "short_term_ref_pic_set_idx");
+    }
+    else
+    {
+      uiCode = 0;       
+    }
+    *rps = *(sps->getRPSList()->getReferencePictureSet(uiCode));
+  }
+  if(sps->getLongTermRefsPresent())
+  {
+    Int offset = rps->getNumberOfNegativePictures()+rps->getNumberOfPositivePictures();
+    UInt numOfLtrp = 0;
+    UInt numLtrpInSPS = 0;
+    if (sps->getNumLongTermRefPicSPS() > 0)
+    {
+      READ_UVLC( uiCode, "num_long_term_sps");
+      numLtrpInSPS = uiCode;
+      numOfLtrp += numLtrpInSPS;
+      rps->setNumberOfLongtermPictures(numOfLtrp);
+    }
+    Int bitsForLtrpInSPS = 0;
+    while (sps->getNumLongTermRefPicSPS() > (1 << bitsForLtrpInSPS))
+    {
+      bitsForLtrpInSPS++;
+    }
+    READ_UVLC( uiCode, "num_long_term_pics");             rps->setNumberOfLongtermPictures(uiCode);
+    numOfLtrp += uiCode;
+    rps->setNumberOfLongtermPictures(numOfLtrp);
+    Int maxPicOrderCntLSB = 1 << sps->getBitsForPOC();
+    Int prevDeltaMSB = 0, deltaPocMSBCycleLT = 0;
+    for(Int j=offset+rps->getNumberOfLongtermPictures()-1, k = 0; k < numOfLtrp; j--, k++)
+    {
+      Int pocLsbLt;
+      if (k < numLtrpInSPS)
+      {
+        uiCode = 0;
+        if (bitsForLtrpInSPS > 0)
+        {
+          READ_CODE(bitsForLtrpInSPS, uiCode, "lt_idx_sps[i]");
+        }
+        Bool usedByCurrFromSPS=sps->getUsedByCurrPicLtSPSFlag(uiCode);
+
+        pocLsbLt = sps->getLtRefPicPocLsbSps(uiCode);
+        rps->setUsed(j,usedByCurrFromSPS);
+      }
+      else
+      {
+        READ_CODE(sps->getBitsForPOC(), uiCode, "poc_lsb_lt"); pocLsbLt= uiCode;
+        READ_FLAG( uiCode, "used_by_curr_pic_lt_flag");     rps->setUsed(j,uiCode);
+      }
+      READ_FLAG(uiCode,"delta_poc_msb_present_flag");
+      Bool mSBPresentFlag = uiCode ? true : false;
+      if(mSBPresentFlag)
+      {
+        READ_UVLC( uiCode, "delta_poc_msb_cycle_lt[i]" );
+        Bool deltaFlag = false;
+        //            First LTRP                               || First LTRP from SH
+        if( (j == offset+rps->getNumberOfLongtermPictures()-1) || (j == offset+(numOfLtrp-numLtrpInSPS)-1) )
+        {
+          deltaFlag = true;
+        }
+        if(deltaFlag)
+        {
+          deltaPocMSBCycleLT = uiCode;
+        }
+        else
+        {
+          deltaPocMSBCycleLT = uiCode + prevDeltaMSB;
+        }
+
+        Int pocLTCurr = pcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB
+          - iPOClsb + pocLsbLt;
+        rps->setPOC     (j, pocLTCurr);
+        rps->setDeltaPOC(j, - pcSlice->getPOC() + pocLTCurr);
+        rps->setCheckLTMSBPresent(j,true);
+      }
+      else
+      {
             rps->setPOC     (j, pocLsbLt);
             rps->setDeltaPOC(j, - pcSlice->getPOC() + pocLsbLt);
-            rps->setCheckLTMSBPresent(j,false);
-
-            // reset deltaPocMSBCycleLT for first LTRP from slice header if MSB not present
-            if( j == offset+(numOfLtrp-numLtrpInSPS)-1 )
-            {
-              deltaPocMSBCycleLT = 0;
-            }
-          }
-          prevDeltaMSB = deltaPocMSBCycleLT;
-        }
-        offset += rps->getNumberOfLongtermPictures();
-        rps->setNumberOfPictures(offset);
-      }
-#if NH_MV
-      if ( !rps->getInterRPSPrediction( ) )
-      { // check sum of NumPositivePics, NumNegativePics, num_long_term_sps and num_long_term_pics 
-        rps->checkMaxNumPics( 
-          vps->getVpsExtensionFlag(), 
-            MAX_INT,  // To be replaced by MaxDbpsize
-          pcSlice->getLayerId(), 
-          sps->getMaxDecPicBuffering( sps->getSpsMaxSubLayersMinus1() ) - 1 );
-      }
-#endif
-
-      if ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
-        || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
-        || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
-      {
-        // In the case of BLA picture types, rps data is read from slice header but ignored
-        rps = pcSlice->getLocalRPS();
-        (*rps)=TComReferencePictureSet();
-        pcSlice->setRPS(rps);
-      }
-      if (sps->getTMVPFlagsPresent())
-      {
-#if NH_MV
-        READ_FLAG( uiCode, "slice_temporal_mvp_enabled_flag" );
-#else
-        READ_FLAG( uiCode, "slice_temporal_mvp_enabled_flag" );
-#endif
-        pcSlice->setEnableTMVPFlag( uiCode == 1 ? true : false );
-      }
-      else
-      {
-        pcSlice->setEnableTMVPFlag(false);
-      }
-    }
+        rps->setCheckLTMSBPresent(j,false);
+
+        // reset deltaPocMSBCycleLT for first LTRP from slice header if MSB not present
+        if( j == offset+(numOfLtrp-numLtrpInSPS)-1 )
+        {
+          deltaPocMSBCycleLT = 0;
+        }
+      }
+      prevDeltaMSB = deltaPocMSBCycleLT;
+    }
+    offset += rps->getNumberOfLongtermPictures();
+    rps->setNumberOfPictures(offset);
+  }
+
+  if ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
+    || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
+    || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
+  {
+    // In the case of BLA picture types, rps data is read from slice header but ignored
+    rps = pcSlice->getLocalRPS();
+    (*rps)=TComReferencePictureSet();
+    pcSlice->setRPS(rps);
+  }
+  if (sps->getTMVPFlagsPresent())
+  {
+    READ_FLAG( uiCode, "slice_temporal_mvp_enabled_flag" );
+    pcSlice->setEnableTMVPFlag( uiCode == 1 ? true : false );
+  }
+  else
+  {
+    pcSlice->setEnableTMVPFlag(false);
+  }
+}
+#endif
+
 #if NH_MV
     Bool interLayerPredLayerIdcPresentFlag = false; 
@@ -2649,4 +2716,35 @@
     }
     // }
+#if NH_MV
+    
+    const Int numPicTotalCurr = pcSlice->getNumPicTotalCurr(); 
+    if( pcSlice->getSliceType() == P_SLICE || pcSlice->getSliceType() == B_SLICE )
+    {
+      if( pps->getListsModificationPresentFlag() && numPicTotalCurr > 1 )
+      {
+        TComRefPicListModification* rplMod = pcSlice->getRefPicListModification();
+        READ_FLAG( uiCode, "ref_pic_list_modification_flag_l0" ); rplMod->setRefPicListModificationFlagL0( uiCode == 1 );
+        if( rplMod->getRefPicListModificationFlagL0() )
+        {
+          for( Int i = 0; i  <=  pcSlice->getNumRefIdxL0ActiveMinus1( ); i++ )
+          {
+            READ_CODE( rplMod->getListEntryLXLen( numPicTotalCurr ) , uiCode, "list_entry_l0" ); rplMod->setListEntryL0( i, uiCode );
+          }
+        }
+
+        if( pcSlice->getSliceType() == B_SLICE )
+        {
+          READ_FLAG( uiCode, "ref_pic_list_modification_flag_l1" ); rplMod->setRefPicListModificationFlagL1( uiCode == 1 );
+          if( rplMod->getRefPicListModificationFlagL1() )
+          {
+            for( Int i = 0; i  <=  pcSlice->getNumRefIdxL1ActiveMinus1( ); i++ )
+            {
+              READ_CODE( rplMod->getListEntryLXLen( numPicTotalCurr ), uiCode, "list_entry_l1" ); rplMod->setListEntryL1( i, uiCode );
+            }
+          }
+        }
+      }
+    }
+#else
     TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification();
     if(!pcSlice->isIntra())
@@ -2735,4 +2833,6 @@
       refPicListModification->setRefPicListModificationFlagL1(0);
     }
+#endif
+
     if (pcSlice->isInterB())
     {
@@ -2898,9 +2998,5 @@
     {
       Int voiInVps = vps->getVoiInVps( pcSlice->getViewIndex() ); 
-#if NH_3D_FIX_TICKET_101
       if( vps->getCpInSliceSegmentHeaderFlag( voiInVps ) )
-#else
-      if( vps->getCpInSliceSegmentHeaderFlag( voiInVps ) && !pcSlice->getIsDepth() )
-#endif
       {
         for( Int m = 0; m < vps->getNumCp( voiInVps ); m++ )
@@ -2952,5 +3048,9 @@
     pcSlice->checkPocResetIdc(); 
 
+#if NH_MV
+    if ( pcSlice->getVPS()->getPocLsbNotPresentFlag(pcSlice->getLayerId()) && pcSlice->getSlicePicOrderCntLsb() > 0 )
+#else
     if ( pcSlice->getVPS()->getPocLsbNotPresentFlag(pcSlice->getLayerId()) && slicePicOrderCntLsb > 0 )
+#endif
     {
       assert( pcSlice->getPocResetIdc() != 2 );
@@ -2959,10 +3059,15 @@
     if( pcSlice->getPocResetIdc() !=  0 )
     {
-      READ_CODE( 6, uiCode, "poc_reset_period_id" ); pcSlice->setPocResetPeriodId( uiCode );
+      READ_CODE( 6, uiCode, "poc_reset_period_id" ); pcSlice->setPocResetPeriodId( uiCode );      
+      pcSlice->setHasPocResetPeriodIdPresent( true );
     }
     else
     {
       // TODO Copy poc_reset_period from earlier picture
+#if NH_MV
+      pcSlice->setHasPocResetPeriodIdPresent( false);
+#else
       pcSlice->setPocResetPeriodId( 0 );
+#endif
     }
     
@@ -2972,21 +3077,35 @@
       READ_CODE( pcSlice->getPocLsbValLen() , uiCode, "poc_lsb_val" ); pcSlice->setPocLsbVal( uiCode );
     }          
-    pcSlice->checkPocLsbVal(); 
-
-    // Derive the value of PocMs8bValRequiredFlag
+    pcSlice->checkPocLsbVal();        
 
     if( !pcSlice->getPocMsbValRequiredFlag() && pcSlice->getVPS()->getVpsPocLsbAlignedFlag() )
     {
+#if NH_MV
+      READ_FLAG( uiCode, "poc_msb_cycle_val_present_flag" ); pcSlice->setPocMsbCycleValPresentFlag( uiCode == 1 );
+#else
       READ_FLAG( uiCode, "poc_msb_val_present_flag" ); pcSlice->setPocMsbValPresentFlag( uiCode == 1 );
+#endif
     }
     else
     {
+#if NH_MV
+      pcSlice->setPocMsbCycleValPresentFlag( pcSlice->inferPocMsbCycleValPresentFlag( ) ); 
+#else
       pcSlice->setPocMsbValPresentFlag( pcSlice->inferPocMsbValPresentFlag( ) ); 
+#endif
     }
 
     
+#if NH_MV
+    if( pcSlice->getPocMsbCycleValPresentFlag() )
+#else
     if( pcSlice->getPocMsbValPresentFlag() )
-    {
+#endif
+    {
+#if NH_MV
+      READ_UVLC( uiCode, "poc_msb_val" ); pcSlice->setPocMsbCycleVal( uiCode );
+#else
       READ_UVLC( uiCode, "poc_msb_val" ); pcSlice->setPocMsbVal( uiCode );
+#endif
     }
 
Index: trunk/source/Lib/TLibDecoder/TDecCAVLC.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 1314)
+++ trunk/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 1321)
@@ -64,5 +64,9 @@
 protected:
 
+#if NH_MV
+  Void  parseShortTermRefPicSet            (TComSPS* pcSPS, TComStRefPicSet* pcRPS, Int stRpsIdx );
+#else
   Void  parseShortTermRefPicSet            (TComSPS* pcSPS, TComReferencePictureSet* pcRPS, Int idx);
+#endif
 
 #if NH_MV
@@ -104,5 +108,11 @@
   Void  parseProfileTier    (ProfileTierLevel *ptl, const Bool bIsSubLayer);
   Void  parseHrdParameters  (TComHRD *hrd, Bool cprms_present_flag, UInt tempLevelHigh);
+#if NH_MV
+  Void  parseFirstSliceSegmentInPicFlag( TComSlice* pcSlice );
+  Void  parseSliceHeader    ( TComSlice* pcSlice, ParameterSetManager *parameterSetManager );
+#else
   Void  parseSliceHeader    ( TComSlice* pcSlice, ParameterSetManager *parameterSetManager, const Int prevTid0POC);
+#endif
+
   Void  parseTerminatingBit ( UInt& ruiBit );
   Void  parseRemainingBytes ( Bool noTrailingBytesExpected );
Index: trunk/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCu.cpp	(revision 1314)
+++ trunk/source/Lib/TLibDecoder/TDecCu.cpp	(revision 1321)
@@ -531,4 +531,37 @@
         pcCU->getCUMvField( REF_PIC_LIST_1 )->setMvFieldSP(pcCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx + 1], iSPWidth, iSPHeight);
       }
+#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC
+      if ( g_traceSubPBMotion )
+      {
+        std::cout << std::setfill(' ')                          << std::setw( 15 )
+          << "Num"                                              << std::setw( 15 )
+          << "Dir "                                             << std::setw( 15 )
+          <<  "L0 RefIdx"                                       << std::setw( 15 )
+          <<  "L0 Hor"                                          << std::setw( 15 )
+          <<  "L0 Ver"                                          << std::setw( 15 )
+          <<  "L1 RefIdx"                                       << std::setw( 15 )
+          <<  "L1 Hor"                                          << std::setw( 15 )
+          <<  "L1 Ver"                                          << std::setw( 15 )
+          << std::endl; 
+
+        for (Int iPartitionIdx = 0; iPartitionIdx < iNumSP; iPartitionIdx++)
+        {
+          UChar        dir = puhInterDirSP[iPartitionIdx]; 
+          TComMvField& mv0 = pcMvFieldSP  [2*iPartitionIdx];
+          TComMvField& mv1 = pcMvFieldSP  [2*iPartitionIdx+1];
+
+          std::cout << std::setfill(' ')                                  << std::setw( 15 )
+            << iPartitionIdx                                              << std::setw( 15 )
+            << (UInt) dir                                                 << std::setw( 15 )
+            << ((dir & 1) ? mv0.getRefIdx()       : MIN_INT)              << std::setw( 15 )
+            << ((dir & 1) ? mv0.getMv().getHor()  : MIN_INT)              << std::setw( 15 )
+            << ((dir & 1) ? mv0.getMv().getVer()  : MIN_INT)              << std::setw( 15 )
+            << ((dir & 2) ? mv1.getRefIdx()       : MIN_INT)              << std::setw( 15 )
+            << ((dir & 2) ? mv1.getMv().getHor()  : MIN_INT)              << std::setw( 15 )
+            << ((dir & 2) ? mv1.getMv().getVer()  : MIN_INT)              << std::setw( 15 )
+            << std::endl;
+        }
+      }
+#endif
     }
     delete[] pcMvFieldSP;
@@ -779,4 +812,5 @@
   const ChromaFormat chFmt     = rTu.GetChromaFormat();
 
+  DEBUG_STRING_NEW(sTemp)
   if ( pcCU->getDISType(uiAbsPartIdx) == 0 )
   {
@@ -1271,4 +1305,5 @@
     TComTURecurse tuRecurseWithPU(tuRecurseCU, false, TComTU::DONT_SPLIT);
 
+    DEBUG_STRING_NEW(sTemp)
     m_pcPrediction->initIntraPatternChType( tuRecurseWithPU, COMPONENT_Y, false DEBUG_STRING_PASS_INTO(sTemp) );
 
@@ -1321,5 +1356,5 @@
       
       //===== init pattern for luma prediction =====
-      
+      DEBUG_STRING_NEW(sTemp)
       m_pcPrediction->initIntraPatternChType( tuRecurseWithPU, COMPONENT_Y, bUseFilter  DEBUG_STRING_PASS_INTO(sTemp) );
       
Index: trunk/source/Lib/TLibDecoder/TDecEntropy.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 1314)
+++ trunk/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 1321)
@@ -238,6 +238,7 @@
   UInt uiNumPU = ( ePartSize == SIZE_2Nx2N ? 1 : ( ePartSize == SIZE_NxN ? 4 : 2 ) );
   UInt uiPUOffset = ( g_auiPUOffset[UInt( ePartSize )] << ( ( pcCU->getSlice()->getSPS()->getMaxTotalCUDepth() - uiDepth ) << 1 ) ) >> 4;
+
+#if NH_3D_MLC
 //#if H_3D_IV_MERGE
-#if NH_3D_MLC
   TComMvField cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists
   UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM];
@@ -651,5 +652,5 @@
 #endif
         }
-      }
+      } 
 #if NH_3D_IC
       decodeICFlag( pcCU, uiAbsPartIdx, uiDepth );
Index: trunk/source/Lib/TLibDecoder/TDecEntropy.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecEntropy.h	(revision 1314)
+++ trunk/source/Lib/TLibDecoder/TDecEntropy.h	(revision 1321)
@@ -67,5 +67,10 @@
   virtual Void  parseSPS                  ( TComSPS* pcSPS )     = 0;
   virtual Void  parsePPS                  ( TComPPS* pcPPS )     = 0;
-  virtual Void parseSliceHeader          ( TComSlice* pcSlice, ParameterSetManager *parameterSetManager, const Int prevTid0POC)       = 0;
+#if NH_MV
+  virtual Void  parseFirstSliceSegmentInPicFlag( TComSlice* pcSlice ) = 0;
+  virtual Void  parseSliceHeader          ( TComSlice* pcSlice, ParameterSetManager *parameterSetManager )       = 0;
+#else
+  virtual Void  parseSliceHeader          ( TComSlice* pcSlice, ParameterSetManager *parameterSetManager, const Int prevTid0POC)       = 0;
+#endif
 
   virtual Void parseTerminatingBit       ( UInt& ruilsLast )                                     = 0;
@@ -156,5 +161,12 @@
   Void    decodeSPS                   ( TComSPS* pcSPS ) { m_pcEntropyDecoderIf->parseSPS(pcSPS); }
   Void    decodePPS                   ( TComPPS* pcPPS ) { m_pcEntropyDecoderIf->parsePPS(pcPPS); }
+#if NH_MV
+  Void    decodeFirstSliceSegmentInPicFlag ( TComSlice* pcSlice )  { m_pcEntropyDecoderIf->parseFirstSliceSegmentInPicFlag( pcSlice );         }
+#endif
+#if NH_MV
+  Void    decodeSliceHeader           ( TComSlice* pcSlice, ParameterSetManager *parameterSetManager )  { m_pcEntropyDecoderIf->parseSliceHeader(pcSlice, parameterSetManager);         }
+#else
   Void    decodeSliceHeader           ( TComSlice* pcSlice, ParameterSetManager *parameterSetManager, const Int prevTid0POC)  { m_pcEntropyDecoderIf->parseSliceHeader(pcSlice, parameterSetManager, prevTid0POC);         }
+#endif
   Void    decodeTerminatingBit        ( UInt& ruiIsLast )       { m_pcEntropyDecoderIf->parseTerminatingBit(ruiIsLast);     }
   Void    decodeRemainingBytes( Bool noTrailingBytesExpected ) { m_pcEntropyDecoderIf->parseRemainingBytes(noTrailingBytesExpected); }
Index: trunk/source/Lib/TLibDecoder/TDecSbac.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecSbac.h	(revision 1314)
+++ trunk/source/Lib/TLibDecoder/TDecSbac.h	(revision 1321)
@@ -80,5 +80,10 @@
   Void  parseSPS                  ( TComSPS* /*pcSPS*/ ) {}
   Void  parsePPS                  ( TComPPS* /*pcPPS*/ ) {}
+#if NH_MV
+  Void  parseFirstSliceSegmentInPicFlag( TComSlice* /*pcSlice*/ ) {}
+  Void  parseSliceHeader          ( TComSlice* /*pcSlice*/, ParameterSetManager* /*parameterSetManager*/ ) {}
+#else
   Void  parseSliceHeader          ( TComSlice* /*pcSlice*/, ParameterSetManager* /*parameterSetManager*/, const Int /*prevTid0POC*/) {}
+#endif
   Void  parseTerminatingBit       ( UInt& ruiBit );
   Void  parseRemainingBytes       ( Bool noTrailingBytesExpected);
Index: trunk/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 1314)
+++ trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 1321)
@@ -35,5 +35,4 @@
     \brief    decoder class
 */
-
 #include "NALread.h"
 #include "TDecTop.h"
@@ -127,7 +126,4 @@
   }
 }
-
-
-
 
 Void
@@ -290,19 +286,4 @@
 }
 
-
-#if !NH_3D_FIX_TICKET_101
-#if NH_3D_IV_MERGE
-Void
-CamParsCollector::copyCamParamForSlice( TComSlice* pcSlice )
-{
-  if( m_bCamParsVaryOverTime )
-  {
-    pcSlice->setCamparaSlice( m_aaiCodedScale, m_aaiCodedOffset );
-  }
-}
-#endif
-#endif
-
-
 Void
 CamParsCollector::xOutput( Int iPOC )
@@ -351,9 +332,9 @@
 TDecTop::TDecTop()
   : m_iMaxRefPicNum(0)
+#if !NH_MV
   , m_associatedIRAPType(NAL_UNIT_INVALID)
-  , m_pocCRA(0)
+  , m_pocCRA(0)  
   , m_pocRandomAccess(MAX_INT)
   , m_cListPic()
-#if !NH_MV
   , m_parameterSetManager()
 #endif
@@ -373,4 +354,5 @@
   , m_cSAO()
   , m_pcPic(NULL)
+#if !NH_MV
   , m_prevPOC(MAX_INT)
   , m_prevTid0POC(0)
@@ -383,56 +365,66 @@
   , m_isNoOutputPriorPics(false)
   , m_craNoRaslOutputFlag(false)
+#endif
 #if O0043_BEST_EFFORT_DECODING
   , m_forceDecodeBitDepth(8)
 #endif
   , m_pDecodedSEIOutputStream(NULL)
+#if !NH_MV
   , m_warningMessageSkipPicture(false)
+#endif
   , m_prefixSEINALUs()
+{
+#if !NH_MV
+#if ENC_DEC_TRACE
+  if (g_hTrace == NULL)
+  {
+    g_hTrace = fopen( "TraceDec.txt", "wb" );
+  }
+  g_bJustDoIt = g_bEncDecTraceDisable;
+  g_nSymbolCounter = 0;
+#endif
+#endif
+
+#if NH_MV
+  m_layerId                       = 0;
+  m_viewId                        = 0;
+
+#if NH_3D
+  m_viewIndex                     = 0;
+  m_isDepth                       = false;
+  m_pcCamParsCollector            = 0;
+#endif
+
+  m_decodingProcess               = CLAUSE_8;
+  m_targetOlsIdx                  = -1;
+  m_smallestLayerId               = -1;
+  m_isInOwnTargetDecLayerIdList   = 0;
+  m_prevPicOrderCnt               = 0;
+  m_pocDecrementedInDpbFlag       = NULL;
+  m_firstPicInLayerDecodedFlag    = NULL;
+  m_lastPresentPocResetIdc        = NULL;
+
+  m_prevIrapPoc                   = MIN_INT;
+  m_prevIrapDecodingOrder         = MIN_INT;
+  m_prevStsaDecOrder              = MIN_INT;
+  m_prevStsaTemporalId            = MIN_INT;
+#endif
+}
+
+TDecTop::~TDecTop()
 {
 #if ENC_DEC_TRACE
 #if NH_MV
-  if ( g_hTrace == NULL )
-  {
-#endif
-  if (g_hTrace == NULL)
-  {
-    g_hTrace = fopen( "TraceDec.txt", "wb" );
-  }
-  g_bJustDoIt = g_bEncDecTraceDisable;
-  g_nSymbolCounter = 0;
-#if NH_MV
-  }
-#endif
-#endif
-#if NH_MV
-  m_isLastNALWasEos = false;
-  m_layerId = 0;
-  m_viewId = 0;
-#if NH_3D
-  m_viewIndex = 0; 
-  m_isDepth = false;
-  m_pcCamParsCollector = 0;
-#endif
-#if NH_MV
-  m_targetOlsIdx = -1; 
-#endif
-#endif
-
-}
-
-TDecTop::~TDecTop()
-{
-#if ENC_DEC_TRACE
-#if H_MV_ENC_DEC_TRAC_FIX
   if (g_hTrace != stdout && g_hTrace != NULL)
+  {
+    fclose( g_hTrace );
+    g_hTrace = NULL;
+  }
 #else
   if (g_hTrace != stdout)
-#endif
   {
     fclose( g_hTrace );
-#if H_MV_ENC_DEC_TRAC_FIX
-    g_hTrace = NULL;
-#endif
-  }
+  }
+#endif  
 #endif
   while (!m_prefixSEINALUs.empty())
@@ -452,4 +444,10 @@
 Void TDecTop::destroy()
 {
+
+#if NH_MV
+  m_cSAO.destroy();
+  m_cLoopFilter.        destroy();
+#endif
+
   m_cGopDecoder.destroy();
 
@@ -474,6 +472,8 @@
 }
 
+#if !NH_MV
 Void TDecTop::deletePicBuffer ( )
 {
+
   TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
   Int iSize = Int( m_cListPic.size() );
@@ -482,15 +482,8 @@
   {
     TComPic* pcPic = *(iterPic++);
-#if NH_MV
-    if( pcPic )
-    {
-#endif
     pcPic->destroy();
 
     delete pcPic;
     pcPic = NULL;
-#if NH_MV
-    }
-#endif
   }
 
@@ -499,33 +492,11 @@
   m_cLoopFilter.        destroy();
 
-#if !NH_MV
   // destroy ROM
   destroyROM();
-#endif
 }
 
 Void TDecTop::xGetNewPicBuffer ( const TComSPS &sps, const TComPPS &pps, TComPic*& rpcPic, const UInt temporalLayer )
 {
-#if NH_MV
-  if ( getLayerId() == 0 )
-  {  
-    m_iMaxRefPicNum = sps.getMaxDecPicBuffering(temporalLayer);     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
-  }
-  else
-  {
-    //GTCIC
-    //m_iMaxRefPicNum = pcSlice->getVPS()->getMaxDecPicBuffering(pcSlice->getTLayer());    
-#if H_MV_HLS7_GEN 
-    TComVPS* vps         = pcSlice->getVPS();
-    TComDpbSize* dpbSize = vps->getDpbSize(); 
-    Int lsIdx            = vps->olsIdxToLsIdx( getTargetOutputLayerSetIdx()); // Is this correct, seems to be missing in spec?
-    Int layerIdx         = vps->getIdxInLayerSet     ( lsIdx, getLayerId() ); 
-    Int subDpbIdx        = dpbSize->getSubDpbAssigned( lsIdx, layerIdx ); 
-    m_iMaxRefPicNum      = dpbSize->getMaxVpsDecPicBufferingMinus1(getTargetOutputLayerSetIdx(), subDpbIdx , vps->getSubLayersVpsMaxMinus1( vps->getLayerIdInVps( getLayerId() ) ) + 1 ) + 1 ;  
-#endif    
-  }
-#else
   m_iMaxRefPicNum = sps.getMaxDecPicBuffering(temporalLayer);     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
-#endif
   if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
   {
@@ -547,7 +518,4 @@
     {
       rpcPic->setOutputMark(false);
-#if NH_MV
-      rpcPic->setPicOutputFlag(false); 
-#endif
       bBufferIsAvailable = true;
       break;
@@ -557,7 +525,4 @@
     {
       rpcPic->setOutputMark(false);
-#if NH_MV
-      rpcPic->setPicOutputFlag(false); 
-#endif
       rpcPic->setReconMark( false );
       rpcPic->getPicYuvRec()->setBorderExtension( false );
@@ -577,9 +542,6 @@
   rpcPic->create ( sps, pps, true);
 }
-#if NH_MV
-Void TDecTop::endPicDecoding(Int& poc, TComList<TComPic*>*& rpcListPic, std::vector<Int>& targetDecLayerIdSet )
-#else
+
 Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic)
-#endif
 {
   if (!m_pcPic)
@@ -599,10 +561,5 @@
   rpcListPic          = &m_cListPic;
   m_cCuDecoder.destroy();
-#if NH_MV 
-  TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer0, m_refPicSetInterLayer1 );  
-  TComSlice::markCurrPic( pcPic ); 
-#endif
   m_bFirstSliceInPicture  = true;
-
   return;
 }
@@ -623,7 +580,4 @@
     {
       pcPicTmp->setOutputMark(false);
-#if NH_MV
-      pcPicTmp->setPicOutputFlag(false); 
-#endif
     }
   }
@@ -673,10 +627,20 @@
   }
 }
-
-
+#endif
+
+
+#if NH_MV
+Void TDecTop::activatePSsAndInitPicOrSlice( TComPic* newPic )
+{
+  if ( m_apcSlicePilot->getFirstSliceSegementInPicFlag() )
+  {
+    assert( newPic != NULL );
+
+#else
 Void TDecTop::xActivateParameterSets()
 {
   if (m_bFirstSliceInPicture)
   {
+#endif
     const TComPPS *pps = m_parameterSetManager.getPPS(m_apcSlicePilot->getPPSId()); // this is a temporary PPS object. Do not store this value
     assert (pps != 0);
@@ -690,5 +654,6 @@
     const TComVPS* vps = m_parameterSetManager.getVPS(sps->getVPSId());
     assert (vps != 0); 
-    if (!m_parameterSetManager.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP(), m_layerId ) )
+    // TBD: check the condition on m_firstPicInLayerDecodedFlag 
+    if (!m_parameterSetManager.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP() || !m_firstPicInLayerDecodedFlag[m_layerId] , m_layerId ) )
 #else
     if (false == m_parameterSetManager.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
@@ -700,20 +665,23 @@
 
 #if NH_MV
-  // When the value of vps_num_rep_formats_minus1 in the active VPS is equal to 0
-  if ( vps->getVpsNumRepFormatsMinus1() == 0 )
-  {
-    //, it is a requirement of bitstream conformance that the value of update_rep_format_flag shall be equal to 0.
-    assert( sps->getUpdateRepFormatFlag() == false ); 
-  }
-  sps->checkRpsMaxNumPics( vps, getLayerId() ); 
-
-  // It is a requirement of bitstream conformance that, when the SPS is referred to by 
-  // any current picture that belongs to an independent non-base layer, the value of 
-  // MultiLayerExtSpsFlag derived from the SPS shall be equal to 0.
-
-  if ( m_layerId > 0 && vps->getNumRefLayers( m_layerId ) == 0 )
-  {  
-    assert( sps->getMultiLayerExtSpsFlag() == 0 ); 
-  }
+    if ( decProcAnnexG() )
+    {
+      // When the value of vps_num_rep_formats_minus1 in the active VPS is equal to 0
+      if ( vps->getVpsNumRepFormatsMinus1() == 0 )
+      {
+        //, it is a requirement of bitstream conformance that the value of update_rep_format_flag shall be equal to 0.
+        assert( sps->getUpdateRepFormatFlag() == false ); 
+      }
+      sps->checkRpsMaxNumPics( vps, getLayerId() ); 
+
+      // It is a requirement of bitstream conformance that, when the SPS is referred to by 
+      // any current picture that belongs to an independent non-base layer, the value of 
+      // MultiLayerExtSpsFlag derived from the SPS shall be equal to 0.
+
+      if ( m_layerId > 0 && vps->getNumRefLayers( m_layerId ) == 0 )
+      {  
+        assert( sps->getMultiLayerExtSpsFlag() == 0 ); 
+      }
+    }
 #endif
 
@@ -734,8 +702,10 @@
 
     //  Get a new picture buffer. This will also set up m_pcPic, and therefore give us a SPS and PPS pointer that we can use.
+#if !NH_MV
     xGetNewPicBuffer (*(sps), *(pps), m_pcPic, m_apcSlicePilot->getTLayer());
+
     m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
-#if NH_MV
-    m_apcSlicePilot->createInterLayerReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
+#else
+    m_pcPic = newPic; 
 #endif
 
@@ -752,4 +722,5 @@
 
 #if NH_MV
+    pSlice->setPic( m_pcPic );
     vps=pSlice->getVPS();  
     // The nuh_layer_id value of the NAL unit containing the PPS that is activated for a layer layerA with nuh_layer_id equal to nuhLayerIdA shall be equal to 0, or nuhLayerIdA, or the nuh_layer_id of a direct or indirect reference layer of layerA.
@@ -803,4 +774,8 @@
   else
   {
+#if NH_MV
+    assert( m_pcPic != NULL ); 
+    assert( newPic  == NULL ); 
+#endif
     // make the slice-pilot a real slice, and set up the slice-pilot for the next slice
     m_pcPic->allocateNewSlice();
@@ -828,14 +803,15 @@
 
     // Check if any new SEI has arrived
-     if(!m_SEIs.empty())
-     {
-       // Currently only decoding Unit SEI message occurring between VCL NALUs copied
-       SEIMessages &picSEI = m_pcPic->getSEIs();
-       SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
-       picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
-       deleteSEIs(m_SEIs);
-     }
-  }
-}
+    if(!m_SEIs.empty())
+    {
+      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
+      SEIMessages &picSEI = m_pcPic->getSEIs();
+      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
+      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
+      deleteSEIs(m_SEIs);
+    }
+  }
+}
+
 Void TDecTop::xParsePrefixSEIsForUnknownVCLNal()
 {
@@ -865,18 +841,26 @@
 }
 
-
-#if NH_MV
-Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool newLayerFlag, Bool& sliceSkippedFlag  )
-{
-  assert( nalu.m_nuhLayerId == m_layerId ); 
+#if !NH_MV
+Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
+{
+  m_apcSlicePilot->initSlice(); // the slice pilot is an object to prepare for a new slice
+  // it is not associated with picture, sps or pps structures.
+  if (m_bFirstSliceInPicture)
+  {
 #else
-Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
-{
-#endif
+Void TDecTop::decodeSliceHeader(InputNALUnit &nalu )
+{
+  // Initialize entropy decoder
+  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
+  m_cEntropyDecoder.setBitstream      (&(nalu.getBitstream()));
+
+  assert( nalu.m_nuhLayerId == m_layerId );   
   m_apcSlicePilot->initSlice(); // the slice pilot is an object to prepare for a new slice
-                                // it is not associated with picture, sps or pps structures.
-
-  if (m_bFirstSliceInPicture)
-  {
+  // it is not associated with picture, sps or pps structures.
+  m_apcSlicePilot->setLayerId( nalu.m_nuhLayerId ); 
+  m_cEntropyDecoder.decodeFirstSliceSegmentInPicFlag( m_apcSlicePilot );   
+  if ( m_apcSlicePilot->getFirstSliceSegementInPicFlag() )
+  {
+#endif  
     m_uiSliceIdx = 0;
   }
@@ -889,23 +873,25 @@
   m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
   Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
-                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
-                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
-                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
-                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
+    m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
+    m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
+    m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
+    m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
   m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
+#if !NH_MV
   m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
+#endif
   m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
-
+#if NH_MV
+  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManager );
+#else
 #if ENC_DEC_TRACE
   const UInt64 originalSymbolCount = g_nSymbolCounter;
 #endif
+    m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManager, m_prevTid0POC);
+#endif
 
 #if NH_MV
-  m_apcSlicePilot->setRefPicSetInterLayer( & m_refPicSetInterLayer0, &m_refPicSetInterLayer1 ); 
-  m_apcSlicePilot->setLayerId( nalu.m_nuhLayerId );
-#endif
-
-  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManager, m_prevTid0POC);
-
+}
+#else
   // set POC for dependent slices in skipped pictures
   if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped)
@@ -915,27 +901,17 @@
 
   xUpdatePreviousTid0POC(m_apcSlicePilot);
-
   m_apcSlicePilot->setAssociatedIRAPPOC(m_pocCRA);
   m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType);
-#if NH_MV  
-  const TComVPS* vps     = m_apcSlicePilot->getVPS();
-  Int layerId            = nalu.m_nuhLayerId;   
-  setViewId   ( vps->getViewId   ( layerId )      );  
-#if NH_3D
-  setViewIndex( vps->getViewIndex( layerId )      );  
-  setIsDepth  ( vps->getDepthId  ( layerId ) == 1 );  
-  m_ivPicLists->setVPS( vps ); 
-#endif
-#endif
+
 
   //For inference of NoOutputOfPriorPicsFlag
   if (m_apcSlicePilot->getRapPicFlag())
   {
-    if ((m_apcSlicePilot->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_apcSlicePilot->getNalUnitType() <= NAL_UNIT_CODED_SLICE_IDR_N_LP) || 
+      if ((m_apcSlicePilot->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_apcSlicePilot->getNalUnitType() <= NAL_UNIT_CODED_SLICE_IDR_N_LP) || 
         (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_bFirstSliceInSequence) ||
         (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getHandleCraAsBlaFlag()))
-    {
-      m_apcSlicePilot->setNoRaslOutputFlag(true);
-    }
+      {
+        m_apcSlicePilot->setNoRaslOutputFlag(true);
+      }
     //the inference for NoOutputPriorPicsFlag
     if (!m_bFirstSliceInBitstream && m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag())
@@ -948,5 +924,5 @@
     else
     {
-      m_apcSlicePilot->setNoOutputPriorPicsFlag(false);
+      m_apcSlicePilot->setNoOutputPriorPicsFlag(false); 
     }
 
@@ -974,5 +950,5 @@
     }
   }
-
+  
   if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_craNoRaslOutputFlag) //Reset POC MSB when CRA has NoRaslOutputFlag equal to 1
   {
@@ -985,21 +961,10 @@
     xUpdatePreviousTid0POC(m_apcSlicePilot);
   }
-#if NH_MV
-    xCeckNoClrasOutput();
-#endif
 
   // Skip pictures due to random access
-
-#if NH_MV
-  if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay, vps))
-#else
   if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
-#endif
   {
     m_prevSliceSkipped = true;
     m_skippedPOC = m_apcSlicePilot->getPOC();
-#if NH_MV
-    sliceSkippedFlag = true; 
-#endif
     return false;
   }
@@ -1009,7 +974,4 @@
     m_prevSliceSkipped = true;
     m_skippedPOC = m_apcSlicePilot->getPOC();
-#if NH_MV
-    sliceSkippedFlag = true; 
-#endif
     return false;
   }
@@ -1030,4 +992,5 @@
     {
       m_prevPOC = m_apcSlicePilot->getPOC();
+
 #if ENC_DEC_TRACE
       //rewind the trace counter since we didn't actually decode the slice
@@ -1038,45 +1001,4 @@
     m_prevPOC = m_apcSlicePilot->getPOC();
   }
-#if NH_MV
-  if ( newLayerFlag )
-  {
-    return false; 
-  }
-#if ENC_DEC_TRACE
-#if H_MV_ENC_DEC_TRAC
-  // parse remainder of SH
-   g_disableHLSTrace = false; 
-#endif
-#endif
-#endif
-
-#if NH_MV
-   // This part needs further testing !
-   if ( m_apcSlicePilot->getPocResetFlag() )
-   {   
-     xResetPocInPicBuffer();
-   }
-
-   if ( m_apcSlicePilot->getTLayer() == 0 && m_apcSlicePilot->getEnableTMVPFlag() == 0 )
-  {
-    //update all pics in the DPB such that they cannot be used for TMPV ref
-    TComList<TComPic*>::iterator  iterRefPic = m_cListPic.begin();  
-    while( iterRefPic != m_cListPic.end() )
-    {
-      TComPic *refPic = *iterRefPic;
-      if( ( refPic->getLayerId() == m_apcSlicePilot->getLayerId() ) && refPic->getReconMark() )
-      {
-        for(Int i = refPic->getNumAllocatedSlice()-1; i >= 0; i--)
-        {
-
-          TComSlice *refSlice = refPic->getSlice(i);
-          refSlice->setAvailableForTMVPRefFlag( false );
-        }
-      }
-      iterRefPic++;
-    }
-  }
-  m_apcSlicePilot->setAvailableForTMVPRefFlag( true );
-#endif
 
   //detect lost reference picture and insert copy of earlier frame.
@@ -1093,5 +1015,4 @@
     m_prevPOC = m_apcSlicePilot->getPOC();
   }
-
   // actual decoding starts here
   xActivateParameterSets();
@@ -1103,187 +1024,197 @@
   TComSlice* pcSlice = m_pcPic->getPicSym()->getSlice(m_uiSliceIdx);
 
-  // When decoding the slice header, the stored start and end addresses were actually RS addresses, not TS addresses.
-  // Now, having set up the maps, convert them to the correct form.
-  pcSlice->setSliceSegmentCurStartCtuTsAddr( m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceSegmentCurStartCtuTsAddr()) );
-  pcSlice->setSliceSegmentCurEndCtuTsAddr( m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceSegmentCurEndCtuTsAddr()) );
-  if(!pcSlice->getDependentSliceSegmentFlag())
-  {
-    pcSlice->setSliceCurStartCtuTsAddr(m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceCurStartCtuTsAddr()));
-    pcSlice->setSliceCurEndCtuTsAddr(m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceCurEndCtuTsAddr()));
-  }
-
-  m_pcPic->setTLayer(nalu.m_temporalId);
+#endif
 
 #if NH_MV
-  //Check Multiview Main profile constraint in G.11.1.1
-  //  When ViewOrderIdx[ i ] derived according to any active VPS is equal to 1 
-  //  for the layer with nuh_layer_id equal to i in subBitstream, 
-  //  inter_view_mv_vert_constraint_flag shall be equal to 1 
-  //  in the sps_multilayer_extension( ) syntax structure in each active SPS for that layer.
-  if( pcSlice->getSPS()->getPTL()->getGeneralPTL()->getProfileIdc()==Profile::MULTIVIEWMAIN
+Void TDecTop::decodeSliceSegment(InputNALUnit &nalu )
+{
+  TComSlice* pcSlice = m_pcPic->getPicSym()->getSlice(m_uiSliceIdx);
+
+  if ( m_pcPic->getHasGeneratedRefPics() )
+  {
+    if ( pcSlice->getFirstSliceSegementInPicFlag() )
+    {
+      std::cout << std:: setfill(' ')
+        << "Layer "  << std::setw(2) << m_pcPic->getLayerId()
+        << "   POC " << std::setw(4) << m_pcPic->getPOC()
+        << " Reference pictures missing. Skipping picture." << std::endl;
+    }
+  }
+  else
+  {
+    //Check Multiview Main profile constraint in G.11.1.1
+    //  When ViewOrderIdx[ i ] derived according to any active VPS is equal to 1 
+    //  for the layer with nuh_layer_id equal to i in subBitstream, 
+    //  inter_view_mv_vert_constraint_flag shall be equal to 1 
+    //  in the sps_multilayer_extension( ) syntax structure in each active SPS for that layer.
+    if( pcSlice->getSPS()->getPTL()->getGeneralPTL()->getProfileIdc()==Profile::MULTIVIEWMAIN
       &&
       pcSlice->getVPS()->getViewOrderIdx(pcSlice->getVPS()->getLayerIdInNuh(getLayerId()))==1 
-     )
-  {
-    assert( pcSlice->getSPS()->getInterViewMvVertConstraintFlag()==1 );
-  }
-#endif
-#if NH_MV
-  m_pcPic->setLayerId( nalu.m_nuhLayerId );
-  m_pcPic->setViewId ( getViewId() );
+      )
+    {
+      assert( pcSlice->getSPS()->getInterViewMvVertConstraintFlag()==1 );
+    }
+
+    m_pcPic->setLayerId( nalu.m_nuhLayerId );
+    m_pcPic->setViewId ( getViewId() );
 #if NH_3D
-  m_pcPic->setViewIndex( getViewIndex() );
-  m_pcPic->setIsDepth  ( getIsDepth  () );
-  pcSlice->setIvPicLists( m_ivPicLists );         
-#endif
-#endif
-
-  if (!pcSlice->getDependentSliceSegmentFlag())
-  {
-    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_associatedIRAPType, m_cListPic );
-    // Set reference list
-#if NH_MV    
-    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 ); 
+    m_pcPic->setViewIndex( getViewIndex() );
+    m_pcPic->setIsDepth  ( getIsDepth  () );
+    pcSlice->setIvPicLists( m_dpb );         
+#endif
+#endif
+    
+    // When decoding the slice header, the stored start and end addresses were actually RS addresses, not TS addresses.
+    // Now, having set up the maps, convert them to the correct form.
+    pcSlice->setSliceSegmentCurStartCtuTsAddr( m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceSegmentCurStartCtuTsAddr()) );
+    pcSlice->setSliceSegmentCurEndCtuTsAddr( m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceSegmentCurEndCtuTsAddr()) );
+    if(!pcSlice->getDependentSliceSegmentFlag())
+    {
+      pcSlice->setSliceCurStartCtuTsAddr(m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceCurStartCtuTsAddr()));
+      pcSlice->setSliceCurEndCtuTsAddr(m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceCurEndCtuTsAddr()));
+    }
+
+    m_pcPic->setTLayer(nalu.m_temporalId);
+
+
+    if (!pcSlice->getDependentSliceSegmentFlag())
+    {
+#if !NH_MV
+      pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_associatedIRAPType, m_cListPic );
+      // Set reference list
+      pcSlice->setRefPicList( m_cListPic, true );
+#else
+      if (pcSlice->getSliceType() != I_SLICE )
+      {
+        if( m_decProcPocAndRps == ANNEX_F )
+        {
+          pcSlice->f834decProcForRefPicListConst();
+        }
+        else if ( m_decProcPocAndRps == CLAUSE_8 )
+        {
+          pcSlice->cl834DecProcForRefPicListConst();
+        }
+        else
+        {
+          assert( false ); 
+        }
+      }
 #if NH_3D_NBDV
-    pcSlice->setDefaultRefView();
+      pcSlice->setDefaultRefView();
 #endif
 #if NH_3D_ARP
-    pcSlice->setARPStepNum(m_ivPicLists);
-#endif
-#else
-    pcSlice->setRefPicList( m_cListPic, true );
-#endif
-
-#if NH_3D
-    pcSlice->checkInCompPredRefLayers(); 
-#if NH_3D_IV_MERGE
-#if H_3D_FCO
-    //assert( !getIsDepth() );
-#else
-    assert( !getIsDepth() || ( pcSlice->getTexturePic() != 0 ) );
-#endif
-#endif    
-#endif
-#if NH_MV
-    if( m_layerId > 0 && !pcSlice->isIntra() && pcSlice->getEnableTMVPFlag() )
-    {
-      TComPic* refPic = pcSlice->getRefPic(RefPicList(1 - pcSlice->getColFromL0Flag()), pcSlice->getColRefIdx());
-
-      assert ( refPic );
-      assert ( refPic->getPicSym()->getSlice(0)->getAvailableForTMVPRefFlag() == true );
-    }
-#endif
-
-    // For generalized B
-    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
-    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
-    {
-      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
-      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
-
-      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
-      {
-        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
-      }
-    }
-    if (!pcSlice->isIntra())
-    {
-      Bool bLowDelay = true;
-      Int  iCurrPOC  = pcSlice->getPOC();
-      Int iRefIdx = 0;
-
-      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
-      {
-        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
+      pcSlice->setPocsInCurrRPSs(); 
+      pcSlice->setARPStepNum(m_dpb);
+#endif     
+#endif
+
+      // For generalized B
+      // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
+      if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
+      {
+        Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
+        pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
+
+        for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
         {
-          bLowDelay = false;
+          pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
         }
       }
-      if (pcSlice->isInterB())
-      {
-        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
+      if (!pcSlice->isIntra())
+      {
+        Bool bLowDelay = true;
+        Int  iCurrPOC  = pcSlice->getPOC();
+        Int iRefIdx = 0;
+
+        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
         {
-          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
+          if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
           {
             bLowDelay = false;
           }
         }
-      }
-
-      pcSlice->setCheckLDC(bLowDelay);
-    }
-
-    //---------------
-    pcSlice->setRefPOCList();
+        if (pcSlice->isInterB())
+        {
+          for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
+          {
+            if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
+            {
+              bLowDelay = false;
+            }
+          }
+        }
+
+        pcSlice->setCheckLDC(bLowDelay);
+      }
+
+      //---------------
+      pcSlice->setRefPOCList();
 #if  NH_3D_TMVP
-    if(pcSlice->getLayerId())
-    {
-      pcSlice->generateAlterRefforTMVP();
-    }
-#endif
-  }
-
-  m_pcPic->setCurrSliceIdx(m_uiSliceIdx);
-  if(pcSlice->getSPS()->getScalingListFlag())
-  {
-    TComScalingList scalingList;
-    if(pcSlice->getPPS()->getScalingListPresentFlag())
-    {
-      scalingList = pcSlice->getPPS()->getScalingList();
-    }
-    else if (pcSlice->getSPS()->getScalingListPresentFlag())
-    {
-      scalingList = pcSlice->getSPS()->getScalingList();
+      if(pcSlice->getLayerId())
+      {
+        pcSlice->generateAlterRefforTMVP();
+      }
+#endif
+    }
+
+    m_pcPic->setCurrSliceIdx(m_uiSliceIdx);
+    if(pcSlice->getSPS()->getScalingListFlag())
+    {
+      TComScalingList scalingList;
+      if(pcSlice->getPPS()->getScalingListPresentFlag())
+      {
+        scalingList = pcSlice->getPPS()->getScalingList();
+      }
+      else if (pcSlice->getSPS()->getScalingListPresentFlag())
+      {
+        scalingList = pcSlice->getSPS()->getScalingList();
+      }
+      else
+      {
+        scalingList.setDefaultScalingList();
+      }
+      m_cTrQuant.setScalingListDec(scalingList);
+      m_cTrQuant.setUseScalingList(true);
     }
     else
     {
-      scalingList.setDefaultScalingList();
-    }
-    m_cTrQuant.setScalingListDec(scalingList);
-    m_cTrQuant.setUseScalingList(true);
-  }
-  else
-  {
-    const Int maxLog2TrDynamicRange[MAX_NUM_CHANNEL_TYPE] =
-    {
+      const Int maxLog2TrDynamicRange[MAX_NUM_CHANNEL_TYPE] =
+      {
         pcSlice->getSPS()->getMaxLog2TrDynamicRange(CHANNEL_TYPE_LUMA),
         pcSlice->getSPS()->getMaxLog2TrDynamicRange(CHANNEL_TYPE_CHROMA)
-    };
-    m_cTrQuant.setFlatScalingList(maxLog2TrDynamicRange, pcSlice->getSPS()->getBitDepths());
-    m_cTrQuant.setUseScalingList(false);
-  }
-
-#if !NH_3D_FIX_TICKET_101
-#if NH_3D_IV_MERGE
-#if H_3D_FCO
-  if( !pcSlice->getIsDepth() && m_pcCamParsCollector )
+      };
+      m_cTrQuant.setFlatScalingList(maxLog2TrDynamicRange, pcSlice->getSPS()->getBitDepths());
+      m_cTrQuant.setUseScalingList(false);
+    }
+
+#if NH_3D
+    if ( decProcAnnexI() )
+    {
+      pcSlice->checkInCompPredRefLayers(); 
+    }
+#endif
+
+    //  Decode a picture
+    m_cGopDecoder.decompressSlice(&(nalu.getBitstream()), m_pcPic);
+
+#if NH_3D
+    if( m_pcCamParsCollector )
+    {
+      m_pcCamParsCollector->setSlice( pcSlice );
+    }
+#endif
+
+#if !NH_MV
+    m_bFirstSliceInPicture = false;
 #else
-  if( pcSlice->getIsDepth() && m_pcCamParsCollector )
-#endif
-  {
-    m_pcCamParsCollector->copyCamParamForSlice( pcSlice );
-  }
-#endif
-#endif
-  //  Decode a picture
-  m_cGopDecoder.decompressSlice(&(nalu.getBitstream()), m_pcPic);
-
-#if NH_3D
-  if( m_pcCamParsCollector )
-  {
-    m_pcCamParsCollector->setSlice( pcSlice );
-  }
-#endif
-
-  m_bFirstSliceInPicture = false;
+  }
+#endif
   m_uiSliceIdx++;
 
+#if !NH_MV
   return false;
-}
+#endif
+}
+
 
 Void TDecTop::xDecodeVPS(const std::vector<UChar> &naluData)
@@ -1333,5 +1264,5 @@
 
 #if NH_MV
-Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayerFlag, Bool& sliceSkippedFlag )
+Bool TDecTop::decodeNonVclNalu(InputNALUnit& nalu )
 #else
 Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
@@ -1354,7 +1285,4 @@
     case NAL_UNIT_VPS:
       xDecodeVPS(nalu.getBitstream().getFifo());
-#if NH_MV
-      m_isLastNALWasEos = false;
-#endif
       return false;
 
@@ -1373,10 +1301,4 @@
 
     case NAL_UNIT_SUFFIX_SEI:
-#if NH_MV
-      if ( nalu.m_nalUnitType == NAL_UNIT_SUFFIX_SEI )
-      {
-        assert( m_isLastNALWasEos == false );
-      }
-#endif
       if (m_pcPic)
       {
@@ -1410,17 +1332,6 @@
     case NAL_UNIT_CODED_SLICE_RASL_R:
 #if NH_MV
-      if (nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_N ||
-          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_N ||
-          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_N ||
-          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
-          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N )
-      {
-        assert( m_isLastNALWasEos == false );
-      }
-      else
-      {
-        m_isLastNALWasEos = false;
-      }
-      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, newLayerFlag, sliceSkippedFlag );
+      assert( false ); 
+      return 1; 
 #else
       return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
@@ -1429,14 +1340,5 @@
 
     case NAL_UNIT_EOS:
-#if NH_MV
-      assert( m_isLastNALWasEos == false );
-      //Check layer id of the nalu. if it is not 0, give a warning message and just return without doing anything.
-      if (nalu.m_nuhLayerId > 0)
-      {
-        printf( "\nThis bitstream has EOS with non-zero layer id.\n" );
-        return false;
-      }
-      m_isLastNALWasEos = true;
-#endif
+#if !NH_MV
       m_associatedIRAPType = NAL_UNIT_INVALID;
       m_pocCRA = 0;
@@ -1445,4 +1347,5 @@
       m_prevSliceSkipped = false;
       m_skippedPOC = 0;
+#endif
       return false;
 
@@ -1465,7 +1368,4 @@
         fdReader.parseFillerData(&(nalu.getBitstream()),size);
         printf ("Note: found NAL_UNIT_FILLER_DATA with %u bytes payload.\n", size);
-#if NH_MV
-      assert( m_isLastNALWasEos == false );
-#endif
       return false;
       }
@@ -1528,4 +1428,5 @@
 }
 
+#if !NH_MV
 /** Function for checking if picture should be skipped because of association with a previous BLA picture
  * \param iPOCLastDisplay POC of last picture displayed
@@ -1558,9 +1459,5 @@
  * access point there is no guarantee that the decoder will not crash.
  */
-#if NH_MV
-Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay, const TComVPS* vps)
-#else
 Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay )
-#endif
 {
   if (iSkipFrame)
@@ -1569,9 +1466,5 @@
     return true;
   }
-#if NH_MV
-  else if ( !m_layerInitilizedFlag[ m_layerId ] ) // start of random access point, m_pocRandomAccess has not been set yet.
-#else
   else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
-#endif
   {
     if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
@@ -1581,56 +1474,13 @@
     {
 
-#if NH_MV
-      if ( xAllRefLayersInitilized( vps ) )
-      {
-        m_layerInitilizedFlag[ m_layerId ] = true; 
-        m_pocRandomAccess = m_apcSlicePilot->getPOC();
-      }
-      else
-      {
-        return true; 
-      }
-#else
       // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
       m_pocRandomAccess = m_apcSlicePilot->getPOC();
-#endif
     }
     else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
     {
-#if NH_MV
-      if ( xAllRefLayersInitilized( vps) )
-      {
-        m_layerInitilizedFlag[ m_layerId ] = true; 
-        m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
-      }
-      else 
-      {
-        return true; 
-      }
-#else
       m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
-#endif
     }
     else
     {
-#if NH_MV
-      static Bool warningMessage[MAX_NUM_LAYERS];
-      static Bool warningInitFlag = false;
-      
-      if (!warningInitFlag)
-      {
-        for ( Int i = 0; i < MAX_NUM_LAYERS; i++)
-        {
-          warningMessage[i] = true; 
-        }
-        warningInitFlag = true; 
-      }
-
-      if ( warningMessage[getLayerId()] )
-      {
-        printf("\nLayer%3d   No valid random access point. VCL NAL units of this layer are discarded until next layer initialization picture. ", getLayerId() ); 
-        warningMessage[m_layerId] = false; 
-      }
-#else
       if(!m_warningMessageSkipPicture)
       {
@@ -1638,5 +1488,4 @@
         m_warningMessageSkipPicture = true;
       }
-#endif
       return true;
     }
@@ -1649,109 +1498,1802 @@
   }
   // if we reach here, then the picture is not skipped.
-#if NH_MV
-  return !m_layerInitilizedFlag[ getLayerId() ]; 
+  return false;
+}
+
 #else
-  return false;
-#endif
-}
-#if NH_MV
-TComPic* TDecTop::getPic( Int poc )
-{
-  xGetPic( m_layerId, poc ); 
-  TComList<TComPic*>* listPic = getListPic();
-  TComPic* pcPic = NULL;
-  for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++)
-  {
-    if( (*it)->getPOC() == poc )
-    {
-      pcPic = *it ;
-      break ;
-    }
-  }
-  return pcPic;
-}
-
-TComPic* TDecTop::xGetPic( Int layerId, Int poc )
+
+Int TDecTop::preDecodePoc( Bool firstPicInLayerDecodedFlag, Bool isFstPicOfAllLayOfPocResetPer, Bool isPocResettingPicture )
+{
+  //Output of this process is PicOrderCntVal, the picture order count of the current picture.
+  //  Picture order counts are used to identify pictures, for deriving motion parameters in merge mode and 
+  //  motion vector prediction and for decoder conformance checking (see clause F.13.5).
+
+  //  Each coded picture is associated with a picture order count variable, denoted as PicOrderCntVal.
+
+  TComSlice* slice = m_apcSlicePilot;
+  const Int nuhLayerId   = slice->getLayerId();
+  const TComVPS*   vps   = slice->getVPS(); 
+  const TComSPS*   sps   = slice->getSPS(); 
+
+  Int pocDecrementedInDpbFlag = m_pocDecrementedInDpbFlag[ nuhLayerId ]; 
+
+  if ( isFstPicOfAllLayOfPocResetPer )
+  {
+    //  When the current picture is the first picture among all layers of a POC resetting period, 
+    //  the variable PocDecrementedInDPBFlag[ i ] is set equal to 0 for each value of i in the range of 0 to 62, inclusive.
+    pocDecrementedInDpbFlag = false; 
+  }
+
+  //  The variable pocResettingFlag is derived as follows:
+  Bool pocResettingFlag; 
+  if ( isPocResettingPicture )
+  {
+    //-  If the current picture is a POC resetting picture, the following applies:    
+    if( vps->getVpsPocLsbAlignedFlag()  )
+    {
+      //  -  If vps_poc_lsb_aligned_flag is equal to 0, pocResettingFlag is set equal to 1.
+      pocResettingFlag = true; 
+    }
+    else if ( pocDecrementedInDpbFlag )
+    {
+      //  -  Otherwise, if PocDecrementedInDPBFlag[ nuh_layer_id ] is equal to 1, pocResettingFlag is set equal to 0.
+      pocResettingFlag = false; 
+    }
+    else
+    {
+      //  -  Otherwise, pocResettingFlag is set equal to 1.
+      pocResettingFlag = true; 
+    }
+  }
+  else
+  {
+    //  -  Otherwise, pocResettingFlag is set equal to 0.
+    pocResettingFlag = false; 
+  }
+
+  Int picOrderCntMsb; 
+  Int picOrderCntVal; 
+
+  //  Depending on pocResettingFlag, the following applies:
+  if ( pocResettingFlag )
+  {
+    //-  The PicOrderCntVal of the current picture is derived as follows:
+    if( slice->getPocResetIdc()  ==  1 )
+    {
+      picOrderCntVal = slice->getSlicePicOrderCntLsb(); 
+    }
+    else if (slice->getPocResetIdc()  ==  2 ) 
+    {
+      picOrderCntVal = 0; 
+    }
+    else
+    {
+      picOrderCntMsb = xGetCurrMsb( slice->getSlicePicOrderCntLsb(), slice->getFullPocResetFlag() ? 0 : slice->getPocLsbVal(), 0, sps->getMaxPicOrderCntLsb() ); 
+      picOrderCntVal = picOrderCntMsb + slice->getSlicePicOrderCntLsb(); 
+    }
+  }
+  else
+  {
+    //-  Otherwise (pocResettingFlag is equal to 0), the following applies:
+    //-  The PicOrderCntVal of the current picture is derived as follows:
+
+    if( slice->getPocMsbCycleValPresentFlag() )
+    {
+      picOrderCntMsb = slice->getPocMsbCycleVal() * sps->getMaxPicOrderCntLsb(); 
+    }
+    else if( !firstPicInLayerDecodedFlag  ||
+      slice->getNalUnitType()  ==  NAL_UNIT_CODED_SLICE_IDR_N_LP || slice->getNalUnitType() ==  NAL_UNIT_CODED_SLICE_IDR_W_RADL )
+    {
+      picOrderCntMsb = 0; //     (F 62)
+    }    
+    else
+    {
+      Int prevPicOrderCntLsb = m_prevPicOrderCnt & ( sps->getMaxPicOrderCntLsb() - 1 );
+      Int prevPicOrderCntMsb = m_prevPicOrderCnt - prevPicOrderCntLsb; 
+      picOrderCntMsb = xGetCurrMsb( slice->getSlicePicOrderCntLsb(), prevPicOrderCntLsb, prevPicOrderCntMsb, sps->getMaxPicOrderCntLsb() ); 
+    }
+    picOrderCntVal = picOrderCntMsb + slice->getSlicePicOrderCntLsb(); 
+  }  
+  return picOrderCntVal;
+}
+
+Void TDecTop::inferPocResetPeriodId()
+{
+  // Infer PocResetPeriodId
+  // When not present, the value of poc_reset_period_id is inferred as follows:
+
+  if ( !m_apcSlicePilot->getHasPocResetPeriodIdPresent() )
+  {
+    if ( m_lastPresentPocResetIdc[ m_apcSlicePilot->getLayerId() ] != MIN_INT )
+    {
+      // - If the previous picture picA that has poc_reset_period_id present in the slice segment header is present in the same layer 
+      //   of the bitstream as the current picture, the value of poc_reset_period_id is inferred to be equal to the value of the 
+      //   poc_reset_period_id of picA.
+
+      m_apcSlicePilot->setPocResetPeriodId( m_lastPresentPocResetIdc[ m_apcSlicePilot->getLayerId() ] ); 
+    }
+    else
+    {
+      //- Otherwise, the value of poc_reset_period_id is inferred to be equal to 0.
+      m_apcSlicePilot->setPocResetPeriodId( 0 ); 
+    }
+  }
+  else
+  {
+    m_lastPresentPocResetIdc[ m_apcSlicePilot->getLayerId() ] = m_apcSlicePilot->getPocResetPeriodId();  
+  }
+}
+
+
+Void TDecTop::decodePocAndRps( )
 { 
-  return m_ivPicLists->getPic( layerId, poc ) ;
-}
-
-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() );            
-      }         
-    }     
-  }
-}
-
-Void TDecTop::xCeckNoClrasOutput()
-{
-  // This part needs further testing! 
-  if ( getLayerId() == 0 )
+  assert( m_uiSliceIdx == 0 );
+  Int nuhLayerId = m_pcPic->getLayerId();
+  if ( m_decProcPocAndRps == CLAUSE_8 )
+  {
+    // 8.1.3 Decoding process for a coded picture with nuh_layer_id equal to 0
+
+    // Variables and functions relating to picture order count are derived as 
+    // specified in clause 8.3.1. This needs to be invoked only for the first slice 
+    // segment of a picture.
+    x831DecProcForPicOrderCount( );
+
+    // The decoding process for RPS in clause 8.3.2 is invoked, wherein reference 
+    // pictures may be marked as "unused for reference" or "used for long-term 
+    // reference". This needs to be invoked only for the first slice segment of a 
+    // picture.
+    x832DecProcForRefPicSet    (  false );
+  }
+  else if( m_decProcPocAndRps == ANNEX_F )
+  {
+    // F.8.1.3 Common decoding process for a coded picture
+
+    if (nuhLayerId == 0 )
+    {
+      // F.8.1.4 Decoding process for a coded picture with nuh_layer_id equal to
+      // --> Clause 8.1.3 is invoked with replacments of 8.3.1, 8.3.2, and 8.3.3 by F.8.3.1, 8.3.2, and 8.3.3
+
+      // Variables and functions relating to picture order count are derived as 
+      // specified in clause 8.3.1. This needs to be invoked only for the first slice 
+      // segment of a picture.
+      xF831DecProcForPicOrderCount( );
+
+      // The decoding process for RPS in clause 8.3.2 is invoked, wherein reference 
+      // pictures may be marked as "unused for reference" or "used for long-term 
+      // reference". This needs to be invoked only for the first slice segment of a 
+      // picture.
+      xF832DecProcForRefPicSet( );
+    }
+    else
+    {
+      // F.8.1.5 Decoding process for starting the decoding of a coded picture with
+      // nuh_layer_id greater than 0
+
+      // Variables and functions relating to picture order count are derived in clause F.8.3.1. 
+      // This needs to be invoked only for the first slice segment of a picture. It is a requirement 
+      // of bitstream conformance that PicOrderCntVal of each picture in an access unit shall have the 
+      // same value during and at the end of decoding of the access unit
+      xF831DecProcForPicOrderCount( );
+
+      // The decoding process for RPS in clause F.8.3.2 is invoked, wherein only reference pictures with 
+      // nuh_layer_id equal to that of CurrPic may be marked as "unused for reference" or "used for 
+      // long-term reference" and any picture with a different value of nuh_layer_id is not marked. 
+      // This needs to be invoked only for the first slice segment of a picture.
+      xF832DecProcForRefPicSet( );
+    }
+  }
+  else
+  {
+    assert( false ); 
+  }
+}
+
+Void TDecTop::genUnavailableRefPics( )
+{ 
+  assert( m_uiSliceIdx == 0 );
+  Int nuhLayerId = m_pcPic->getLayerId();
+  if ( m_decProcPocAndRps == CLAUSE_8 )
+  {
+    // 8.1.3 Decoding process for a coded picture with nuh_layer_id equal to 0
+
+    if ( m_pcPic->isBla() || ( m_pcPic->isCra() && m_pcPic->getNoRaslOutputFlag() ) )
+    {
+      // When the current picture is a BLA picture or is a CRA picture 
+      // with NoRaslOutputFlag equal to 1, the decoding process for generating 
+      // unavailable reference pictures specified in clause 8.3.3 is invoked, 
+      // which needs to be invoked only for the first slice segment of a picture.
+      x8331GenDecProcForGenUnavilRefPics();       
+    }
+  }
+  else if( m_decProcPocAndRps == ANNEX_F )
+  {
+    // F.8.1.3 Common decoding process for a coded picture
+
+    if (nuhLayerId == 0 )
+    {
+      // F.8.1.4 Decoding process for a coded picture with nuh_layer_id equal to
+      // --> Clause 8.1.3 is invoked with replacments of 8.3.1, 8.3.2, and 8.3.3 by F.8.3.1, 8.3.2, and 8.3.3
+
+      if ( m_pcPic->isBla() || ( m_pcPic->isCra() && m_pcPic->getNoRaslOutputFlag() ) )
+      {
+        // When the current picture is a BLA picture or is a CRA picture 
+        // with NoRaslOutputFlag equal to 1, the decoding process for generating 
+        // unavailable reference pictures specified in clause 8.3.3 is invoked, 
+        // which needs to be invoked only for the first slice segment of a picture.
+        xF833DecProcForGenUnavRefPics(); 
+      }
+#if NH_MV_FIX_INIT_NUM_ACTIVE_REF_LAYER_PICS
+      TComDecodedRps* decRps = m_pcPic->getDecodedRps(); 
+      decRps->m_numActiveRefLayerPics0 = 0;
+      decRps->m_numActiveRefLayerPics1 = 0;      
+#endif
+    }
+    else
+    {
+      // F.8.1.5 Decoding process for starting the decoding of a coded picture with
+      // nuh_layer_id greater than 0
+
+      if ( !m_firstPicInLayerDecodedFlag[ nuhLayerId ] )
+      {
+        // When FirstPicInLayerDecodedFlag[ nuh_layer_id ] is equal to 0, the decoding process for generating 
+        // unavailable reference pictures for pictures first in decoding order within a layer specified in 
+        // clause F.8.1.7 is invoked, which needs to be invoked only for the first slice segment of a picture.
+        xF817DecProcForGenUnavRefPicForPicsFrstInDecOrderInLay();
+      }
+
+      if ( m_firstPicInLayerDecodedFlag[ nuhLayerId ] && ( m_pcPic->isIrap() && m_pcPic->getNoRaslOutputFlag() ) )
+      {
+        // When FirstPicInLayerDecodedFlag[ nuh_layer_id ] is equal to 1 and the current picture is an IRAP 
+        // picture with NoRaslOutputFlag equal to 1, the decoding process for generating unavailable reference 
+        // pictures specified in clause F.8.3.3 is invoked, which needs to be invoked only for the first slice 
+        // segment of a picture.
+        xF833DecProcForGenUnavRefPics(); 
+      }
+
+      if ( decProcAnnexG() )
+      {
+        // G.1.2 --> G.1.3
+        xG813DecProcForInterLayerRefPicSet();
+      }
+    }
+  }
+  else
+  {
+    assert( false ); 
+  }
+
+  xCheckUnavailableRefPics();      
+}
+Void TDecTop::executeLoopFilters( )
+{
+  assert( m_pcPic != NULL ); 
+  if ( !m_pcPic->getHasGeneratedRefPics() && !m_pcPic->getIsGenerated() )
+  {
+    m_cGopDecoder.filterPicture( m_pcPic );
+  }
+  m_cCuDecoder.destroy();
+}
+
+Void TDecTop::finalizePic()
+{
+  if( m_pcPic->isIrap() )
+  {
+    m_prevIrapPoc           = m_pcPic->getPOC(); 
+    m_prevIrapDecodingOrder = m_pcPic->getDecodingOrder(); 
+  }
+  if( m_pcPic->isStsa() )
+  {
+    m_prevStsaDecOrder      = m_pcPic->getDecodingOrder();
+    m_prevStsaTemporalId    = m_pcPic->getTemporalId()   ;
+  }
+}
+
+
+Void TDecTop::initFromActiveVps( const TComVPS* vps )
+{   
+  setViewId   ( vps->getViewId   ( getLayerId() )      );  
+#if NH_3D
+  setViewIndex( vps->getViewIndex( getLayerId() )      );  
+  setIsDepth  ( vps->getDepthId  ( getLayerId() ) == 1 );  
+#endif
+
+  if ( !vps->getVpsExtensionFlag() )
+  {
+    m_decodingProcess = CLAUSE_8; 
+    m_isInOwnTargetDecLayerIdList = ( getLayerId() ==  0 );
+  }
+  else
+  {  
+    if ( m_targetOlsIdx == -1 )
+    {
+      // Corresponds to specification by "External Means". (Should be set equal to 0, when no external means available. ) 
+      m_targetOlsIdx = vps->getVpsNumLayerSetsMinus1(); 
+    }
+
+    Int targetDecLayerSetIdx = vps->olsIdxToLsIdx( m_targetOlsIdx ); 
+
+    if ( targetDecLayerSetIdx <= vps->getVpsNumLayerSetsMinus1() && vps->getVpsBaseLayerInternalFlag() )
+    {
+      m_smallestLayerId = 0; 
+    }
+    else if ( targetDecLayerSetIdx <= vps->getVpsNumLayerSetsMinus1() && !vps->getVpsBaseLayerInternalFlag() )
+    {
+      m_smallestLayerId = 0; 
+    }
+    else if ( targetDecLayerSetIdx > vps->getVpsNumLayerSetsMinus1() && vps->getNumLayersInIdList( targetDecLayerSetIdx) == 1 )
+    {
+      
+      // m_smallestLayerId = 0;       
+      // For now don't do change of layer id here. 
+      m_smallestLayerId = vps->getTargetDecLayerIdList( targetDecLayerSetIdx )[ 0 ];    
+    }
+    else
+    {
+      m_smallestLayerId = vps->getTargetDecLayerIdList( targetDecLayerSetIdx )[ 0 ];    
+    }
+
+
+    // Set profile
+    Int lsIdx = vps->olsIdxToLsIdx( m_targetOlsIdx );
+    Int lIdx = -1; 
+    for (Int j = 0; j < vps->getNumLayersInIdList( lsIdx ) ; j++ )
+    {
+      if ( vps->getLayerSetLayerIdList( lsIdx, j ) == getLayerId() )
+      {        
+        lIdx = j;         
+        break; 
+      }        
+    }
+    m_isInOwnTargetDecLayerIdList = (lIdx != -1); 
+
+    if ( m_isInOwnTargetDecLayerIdList )
+    {
+      Int profileIdc = vps->getPTL( vps->getProfileTierLevelIdx( m_targetOlsIdx, lIdx ) )->getGeneralPTL()->getProfileIdc();
+      assert( profileIdc == 1 || profileIdc == 6 || profileIdc == 8 ); 
+
+      if (  profileIdc == 6 )
+      {
+        m_decodingProcess = ANNEX_G;
+      }
+      else if (profileIdc == 7 )
+      {
+        m_decodingProcess = ANNEX_H;
+      }
+      else if (profileIdc == 8 )
+      {
+        m_decodingProcess = ANNEX_I;
+      }
+    }
+  }
+}
+
+
+Bool TDecTop::getFirstSliceSegementInPicFlag()
+{
+  return m_apcSlicePilot->getFirstSliceSegementInPicFlag();
+}
+
+Void TDecTop::x831DecProcForPicOrderCount()
+{
+  /////////////////////////////////////////////////////
+  // 8.3.1 Decoding process for picture order count //
+  /////////////////////////////////////////////////////
+
+  //  Output of this process is PicOrderCntVal, the picture order count of the current picture.
+  //  Picture order counts are used to identify pictures, for deriving motion parameters in merge mode and 
+  //  motion vector prediction, and for decoder conformance checking (see clause C.5).
+  //  Each coded picture is associated with a picture order count variable, denoted as PicOrderCntVal.
+
+  const TComSlice* curSlice = m_pcPic->getSlice(0); 
+
+  Int prevPicOrderCntLsb = MIN_INT; 
+  Int prevPicOrderCntMsb = MIN_INT;  
+  if (!(m_pcPic->isIrap() && m_pcPic->getNoRaslOutputFlag() )  )  
+  {
+    //  When the current picture is not an IRAP picture with NoRaslOutputFlag equal to 1, 
+    //  the variables prevPicOrderCntLsb and prevPicOrderCntMsb are derived as follows:
+
+    //  -  Let prevTid0Pic be the previous picture in decoding order that has TemporalId equal to 0 and that is not a RASL picture, 
+    //     a RADL picture or an SLNR picture.
+
+    //  -  The variable prevPicOrderCntLsb is set equal to slice_pic_order_cnt_lsb of prevTid0Pic.
+    prevPicOrderCntLsb = m_prevTid0PicSlicePicOrderCntLsb; 
+
+    //  -  The variable prevPicOrderCntMsb is set equal to PicOrderCntMsb of prevTid0Pic.
+    prevPicOrderCntMsb = m_prevTid0PicPicOrderCntMsb; 
+  }
+
+  //  The variable PicOrderCntMsb of the current picture is derived as follows:  
+  
+  Int slicePicOrderCntLsb = curSlice->getSlicePicOrderCntLsb();
+
+  Int picOrderCntMsb; 
+
+  if (m_pcPic->isIrap() && m_pcPic->getNoRaslOutputFlag()  )
+  {
+    //-  If the current picture is an IRAP picture with NoRaslOutputFlag equal to 1, PicOrderCntMsb is set equal to 0.
+    picOrderCntMsb = 0; 
+  }
+  else
+  {
+    Int maxPicOrderCntLsb   = curSlice->getSPS()->getMaxPicOrderCntLsb(); 
+
+  //  -  Otherwise, PicOrderCntMsb is derived as follows:
+
+    if( ( slicePicOrderCntLsb < prevPicOrderCntLsb )  &&
+      ( ( prevPicOrderCntLsb - slicePicOrderCntLsb )  >=  ( maxPicOrderCntLsb / 2 ) ) )
+    {
+      picOrderCntMsb = prevPicOrderCntMsb + maxPicOrderCntLsb;   // (8 1)
+    }
+    else if( (slicePicOrderCntLsb > prevPicOrderCntLsb )  &&
+    ( ( slicePicOrderCntLsb - prevPicOrderCntLsb ) > ( maxPicOrderCntLsb / 2 ) ) )
+    {
+      picOrderCntMsb = prevPicOrderCntMsb - maxPicOrderCntLsb;
+    }
+    else
+    {
+      picOrderCntMsb = prevPicOrderCntMsb; 
+    }
+  }
+  
+  //PicOrderCntVal is derived as follows:
+  Int picOrderCntVal = picOrderCntMsb + slicePicOrderCntLsb; //   (8 2)
+
+  //  NOTE 1 - All IDR pictures will have PicOrderCntVal equal to 0 since slice_pic_order_cnt_lsb is inferred to be 0 for IDR 
+  //  pictures and prevPicOrderCntLsb and prevPicOrderCntMsb are both set equal to 0.
+
+  m_pcPic->getSlice(0)->setPOC( picOrderCntVal ); 
+
+  // Update prevTid0Pic
+  //   Let prevTid0Pic be the previous picture in decoding order that has TemporalId equal to 0 and that is not a RASL picture, a RADL picture or an SLNR picture.
+  if( curSlice->getTemporalId() == 0  && !m_pcPic->isRasl() && !m_pcPic->isRadl() && !m_pcPic->isSlnr() )
+  {
+    m_prevTid0PicSlicePicOrderCntLsb = slicePicOrderCntLsb;     
+    m_prevTid0PicPicOrderCntMsb      = picOrderCntMsb;  
+  }
+}
+
+Void TDecTop::xF831DecProcForPicOrderCount()
+{
+  //Output of this process is PicOrderCntVal, the picture order count of the current picture.
+  //  Picture order counts are used to identify pictures, for deriving motion parameters in merge mode and 
+  //  motion vector prediction and for decoder conformance checking (see clause F.13.5).
+
+  //  Each coded picture is associated with a picture order count variable, denoted as PicOrderCntVal.
+
+  const TComSlice* slice = m_pcPic->getSlice(0); 
+  const Int nuhLayerId   = m_pcPic->getLayerId(); 
+  const TComVPS*   vps   = slice->getVPS(); 
+  const TComSPS*   sps   = slice->getSPS(); 
+  if ( m_pcPic->getIsFstPicOfAllLayOfPocResetPer() )
+  {
+    //  When the current picture is the first picture among all layers of a POC resetting period, 
+    //  the variable PocDecrementedInDPBFlag[ i ] is set equal to 0 for each value of i in the range of 0 to 62, inclusive.
+    for (Int i = 0; i <= 62; i++)
+    {
+      m_pocDecrementedInDpbFlag[ i ] = 0; 
+    }
+  }
+
+  //  The variable pocResettingFlag is derived as follows:
+  Bool pocResettingFlag; 
+  if (m_pcPic->getIsPocResettingPic() )
+  {
+    //-  If the current picture is a POC resetting picture, the following applies:    
+    if( vps->getVpsPocLsbAlignedFlag()  )
+    {
+      //  -  If vps_poc_lsb_aligned_flag is equal to 0, pocResettingFlag is set equal to 1.
+      pocResettingFlag = true; 
+    }
+    else if ( m_pocDecrementedInDpbFlag[ nuhLayerId ] )
+    {
+      //  -  Otherwise, if PocDecrementedInDPBFlag[ nuh_layer_id ] is equal to 1, pocResettingFlag is set equal to 0.
+      pocResettingFlag = false; 
+    }
+    else
+    {
+      //  -  Otherwise, pocResettingFlag is set equal to 1.
+      pocResettingFlag = true; 
+    }
+  }
+  else
+  {
+    //  -  Otherwise, pocResettingFlag is set equal to 0.
+    pocResettingFlag = false; 
+  }
+
+  //  The list affectedLayerList is derived as follows:
+  std::vector<Int> affectedLayerList; 
+  if (! vps->getVpsPocLsbAlignedFlag() )
+  {
+    //-  If vps_poc_lsb_aligned_flag is equal to 0, affectedLayerList consists of the nuh_layer_id of the current picture.
+    affectedLayerList.push_back( nuhLayerId ); 
+  }
+  else
+  {
+    //  -  Otherwise, affectedLayerList consists of the nuh_layer_id of the current picture and the nuh_layer_id values 
+    //     equal to IdPredictedLayer[ currNuhLayerId ][ j ] for all values of j in the range of 0 to NumPredictedLayers[ currNuhLayerId ] - 1, 
+    //     inclusive, where currNuhLayerId is the nuh_layer_id value of the current picture.
+    affectedLayerList.push_back( nuhLayerId ); 
+    Int currNuhLayerId = nuhLayerId; 
+    for (Int j = 0; j <= vps->getNumPredictedLayers( currNuhLayerId )-1; j++ )
+    {
+      affectedLayerList.push_back( vps->getIdPredictedLayer(currNuhLayerId, j ) );
+    }
+  }
+  
+  Int picOrderCntMsb; 
+  Int picOrderCntVal; 
+
+  //  Depending on pocResettingFlag, the following applies:
+  if ( pocResettingFlag )
+  {
+    //-  If pocResettingFlag is equal to 1, the following applies:
+    if ( m_firstPicInLayerDecodedFlag[ nuhLayerId ] )
+    {
+      //-  The variables pocMsbDelta, pocLsbDelta and DeltaPocVal are derived as follows:
+      Int pocMsbDelta; 
+      Int pocLsbDelta; 
+      Int deltaPocVal;       
+
+      {
+        Int pocLsbVal; 
+        Int prevPicOrderCntLsb; 
+        Int prevPicOrderCntMsb; 
+
+        if( slice->getPocResetIdc() ==  3 )
+        {
+          pocLsbVal = slice->getPocLsbVal(); 
+        }      
+        else
+        {
+          pocLsbVal = slice->getSlicePicOrderCntLsb(); 
+        }
+
+        if( slice->getPocMsbCycleValPresentFlag() )
+        {
+          pocMsbDelta = slice->getPocMsbCycleVal() * sps->getMaxPicOrderCntLsb();   // (F 60)
+        }      
+        else
+        {
+          prevPicOrderCntLsb = m_prevPicOrderCnt & ( sps->getMaxPicOrderCntLsb() - 1 ); 
+          prevPicOrderCntMsb = m_prevPicOrderCnt - prevPicOrderCntLsb; 
+
+          pocMsbDelta = xGetCurrMsb( pocLsbVal, prevPicOrderCntLsb, prevPicOrderCntMsb, sps->getMaxPicOrderCntLsb() ); 
+        }
+
+        if( slice->getPocResetIdc() == 2 ||  ( slice->getPocResetIdc() == 3  &&  slice->getFullPocResetFlag() ) )
+        {
+          pocLsbDelta = pocLsbVal; 
+        }
+        else
+        {
+          pocLsbDelta = 0; 
+        }
+        deltaPocVal = pocMsbDelta + pocLsbDelta; 
+      }
+
+      //-  The PicOrderCntVal of each picture that has nuh_layer_id value nuhLayerId for which PocDecrementedInDPBFlag[ nuhLayerId ] is equal to 0 
+      //   and that is equal to any value in affectedLayerList is decremented by DeltaPocVal.
+      for (Int i = 0; i < (Int) affectedLayerList.size(); i++ )
+      {
+        if ( !m_pocDecrementedInDpbFlag[ affectedLayerList[i] ] )
+        {
+          m_dpb->decrementPocsInSubDpb( affectedLayerList[i], deltaPocVal ); 
+        }
+      }
+
+      //-  PocDecrementedInDPBFlag[ nuhLayerId ] is set equal to 1 for each value of nuhLayerId included in affectedLayerList.
+      for (Int i = 0; i < (Int) affectedLayerList.size(); i++ )
+      {
+        m_pocDecrementedInDpbFlag[ affectedLayerList[i] ] = true; 
+      }
+    } 
+
+    //-  The PicOrderCntVal of the current picture is derived as follows:
+    if( slice->getPocResetIdc()  ==  1 )
+    {
+      picOrderCntVal = slice->getSlicePicOrderCntLsb(); 
+    }
+    else if (slice->getPocResetIdc()  ==  2 ) 
+    {
+      picOrderCntVal = 0; 
+    }
+    else
+    {
+       picOrderCntMsb = xGetCurrMsb( slice->getSlicePicOrderCntLsb(), slice->getFullPocResetFlag() ? 0 : slice->getPocLsbVal(), 0, sps->getMaxPicOrderCntLsb() ); 
+       picOrderCntVal = picOrderCntMsb + slice->getSlicePicOrderCntLsb(); 
+    }
+  }
+  else
+  {
+    //-  Otherwise (pocResettingFlag is equal to 0), the following applies:
+    //-  The PicOrderCntVal of the current picture is derived as follows:
+    
+    if( slice->getPocMsbCycleValPresentFlag() )
+    {
+      picOrderCntMsb = slice->getPocMsbCycleVal() * sps->getMaxPicOrderCntLsb(); 
+    }
+    else if( !m_firstPicInLayerDecodedFlag[ nuhLayerId ]  ||
+    slice->getNalUnitType()  ==  NAL_UNIT_CODED_SLICE_IDR_N_LP || slice->getNalUnitType() ==  NAL_UNIT_CODED_SLICE_IDR_W_RADL )
+    {
+      picOrderCntMsb = 0; //     (F 62)
+    }    
+    else
+    {
+        Int prevPicOrderCntLsb = m_prevPicOrderCnt & ( sps->getMaxPicOrderCntLsb() - 1 );
+        Int prevPicOrderCntMsb = m_prevPicOrderCnt - prevPicOrderCntLsb; 
+        picOrderCntMsb = xGetCurrMsb( slice->getSlicePicOrderCntLsb(), prevPicOrderCntLsb, prevPicOrderCntMsb, sps->getMaxPicOrderCntLsb() ); 
+    }
+    picOrderCntVal = picOrderCntMsb + slice->getSlicePicOrderCntLsb(); 
+  }
+  
+  m_pcPic->getSlice(0)->setPOC( picOrderCntVal ); 
+  
+  for (Int lId = 0; lId < (Int) affectedLayerList.size(); lId++ )
+  {  
+    //  The value of PrevPicOrderCnt[ lId ] for each of the lId values included in affectedLayerList is derived as follows:
+
+    if (!m_pcPic->isRasl() && !m_pcPic->isRadl() && !m_pcPic->isSlnr() && slice->getTemporalId() == 0 && !slice->getDiscardableFlag() )
+    {
+      //-  If the current picture is not a RASL picture, a RADL picture or a sub-layer non-reference picture, and the current picture 
+      //   has TemporalId equal to 0 and discardable_flag equal to 0, PrevPicOrderCnt[ lId ] is set equal to PicOrderCntVal.
+      m_prevPicOrderCnt = picOrderCntVal; 
+    }
+    else if ( slice->getPocResetIdc() == 3 &&  (
+      ( !m_firstPicInLayerDecodedFlag[ nuhLayerId ]) || 
+      ( m_firstPicInLayerDecodedFlag[ nuhLayerId ] && m_pcPic->getIsPocResettingPic() ) 
+      ) )
+    {
+      //  -  Otherwise, when poc_reset_idc is equal to 3 and one of the following conditions is true, PrevPicOrderCnt[ lId ] is set equal to ( full_poc_reset_flag ? 0 : poc_lsb_val ):
+      //     -  FirstPicInLayerDecodedFlag[ nuh_layer_id ] is equal to 0.
+      //     -  FirstPicInLayerDecodedFlag[ nuh_layer_id ] is equal to 1 and the current picture is a POC resetting picture.
+      m_prevPicOrderCnt = ( slice->getFullPocResetFlag() ? 0 : slice->getPocLsbVal() ); 
+    }
+  }
+}
+
+Int TDecTop::xGetCurrMsb( Int cl, Int pl, Int pm, Int ml )
+{
+  Int currMsb; 
+  if ((pl - cl) >= (ml/ 2))
+  {
+    currMsb = pm + ml;
+  }
+  else if ( (cl - pl) > (ml / 2))
+  {
+    currMsb = pm - ml; 
+  }
+  else
+  {
+    currMsb = pm; 
+  }
+
+  return currMsb;  
+}   
+
+
+
+Void TDecTop::x832DecProcForRefPicSet(  Bool annexFModifications )
+{
+  ///////////////////////////////////////////////////////////////////////////////////////
+  // 8.3.2 8.3.2 Decoding process for reference picture set
+  ///////////////////////////////////////////////////////////////////////////////////////
+
+  TComSlice* slice = m_pcPic->getSlice( 0 ); 
+  const TComSPS* sps = slice->getSPS(); 
+  //  This process is invoked once per picture, after decoding of a slice header but prior to the decoding of any coding unit and prior 
+  //  to the decoding process for reference picture list construction for the slice as specified in clause 8.3.3. 
+  //  This process may result in one or more reference pictures in the DPB being marked as "unused for reference" or 
+  //  "used for long-term reference".
+
+  // The variable currPicLayerId is set equal to nuh_layer_id of the current picture.
+  Int currPicLayerId = m_pcPic->getLayerId(); 
+  Int picOrderCntVal = m_pcPic->getPOC(); 
+
+  if (m_pcPic->isIrap() && m_pcPic->getNoRaslOutputFlag()  )
+  {     
+    // When the current picture is an IRAP picture with NoRaslOutputFlag equal to 1, 
+    // all reference pictures with nuh_layer_id equal to currPicLayerId currently in the 
+    // DPB (if any) are marked as "unused for reference".
+    m_dpb->markSubDpbAsUnusedForReference( currPicLayerId ); 
+  }
+  // Short-term reference pictures are identified by their PicOrderCntVal values. Long-term reference pictures are identified either by 
+  // their PicOrderCntVal values or their slice_pic_order_cnt_lsb values.
+
+  // Five lists of picture order count values are constructed to derive the RPS. These five lists are PocStCurrBefore, 
+  // PocStCurrAfter, PocStFoll, PocLtCurr and PocLtFoll, with NumPocStCurrBefore, NumPocStCurrAfter, NumPocStFoll, 
+  // NumPocLtCurr and NumPocLtFoll number of elements, respectively. The five lists and the five variables are derived as follows:
+  
+  TComDecodedRps* decRps = m_pcPic->getDecodedRps(); 
+
+  std::vector<Int>& pocStCurrBefore = decRps->m_pocStCurrBefore;
+  std::vector<Int>& pocStCurrAfter  = decRps->m_pocStCurrAfter;
+  std::vector<Int>& pocStFoll       = decRps->m_pocStFoll;
+  std::vector<Int>& pocLtCurr       = decRps->m_pocLtCurr;
+  std::vector<Int>& pocLtFoll       = decRps->m_pocLtFoll;
+
+  Int& numPocStCurrBefore = decRps->m_numPocStCurrBefore; 
+  Int& numPocStCurrAfter  = decRps->m_numPocStCurrAfter;
+  Int& numPocStFoll       = decRps->m_numPocStFoll;
+  Int& numPocLtCurr       = decRps->m_numPocLtCurr;
+  Int& numPocLtFoll       = decRps->m_numPocLtFoll;   
+
+  std::vector<Int> currDeltaPocMsbPresentFlag, follDeltaPocMsbPresentFlag; 
+
+  if (m_pcPic->isIdr() )
+  {
+    // - If the current picture is an IDR picture, PocStCurrBefore, PocStCurrAfter, PocStFoll, 
+    //   PocLtCurr and PocLtFoll are all set to be empty, and NumPocStCurrBefore, 
+    //   NumPocStCurrAfter, NumPocStFoll, NumPocLtCurr and NumPocLtFoll are all set equal to 0.
+
+    pocStCurrBefore.clear();
+    pocStCurrAfter .clear();
+    pocStFoll      .clear();
+    pocLtCurr      .clear();
+    pocLtFoll      .clear();
+    numPocStCurrBefore = 0; 
+    numPocStCurrAfter  = 0; 
+    numPocStFoll       = 0; 
+    numPocLtCurr       = 0; 
+    numPocLtFoll       = 0; 
+  }
+  else
+  {
+    const TComStRefPicSet* stRps  = slice->getStRps( slice->getCurrRpsIdx() );
+    // -  Otherwise, the following applies:
+
+    Int j = 0; 
+    Int k = 0; 
+    for( Int i = 0; i < stRps->getNumNegativePicsVar() ; i++ )
+    {
+      if( stRps->getUsedByCurrPicS0Var( i  ) )
+      {
+        pocStCurrBefore.push_back( picOrderCntVal + stRps->getDeltaPocS0Var( i ) ); j++;
+      }
+      else
+      {
+        pocStFoll      .push_back( picOrderCntVal + stRps->getDeltaPocS0Var( i ) ); k++;
+      }
+    }
+    numPocStCurrBefore = j;    
+
+    j = 0; 
+    for (Int i = 0; i < stRps->getNumPositivePicsVar(); i++ )
+    {
+      if (stRps->getUsedByCurrPicS1Var( i ) )
+      {
+        pocStCurrAfter.push_back( picOrderCntVal + stRps->getDeltaPocS1Var( i ) ); j++; 
+      }
+      else
+      {
+        pocStFoll     .push_back( picOrderCntVal + stRps->getDeltaPocS1Var( i ) ); k++;
+      }
+    }
+    numPocStCurrAfter = j;
+    numPocStFoll = k; //    (8 5)
+
+
+    j = 0; 
+    k = 0; 
+    for( Int i = 0; i < slice->getNumLongTermSps( ) + slice->getNumLongTermPics(); i++ )
+    {
+      Int pocLt = slice->getPocLsbLtVar( i ); 
+      if( slice->getDeltaPocMsbPresentFlag( i ) )
+      {
+        pocLt  +=  picOrderCntVal - slice->getDeltaPocMsbCycleLtVar( i ) * sps->getMaxPicOrderCntLsb() -
+          ( picOrderCntVal & ( sps->getMaxPicOrderCntLsb() - 1 ) );
+      }
+
+      if( slice->getUsedByCurrPicLtVar(i)) 
+      {
+        pocLtCurr.push_back( pocLt );
+        currDeltaPocMsbPresentFlag.push_back( slice->getDeltaPocMsbPresentFlag( i ) ); j++; 
+      } 
+      else
+      {
+        pocLtFoll.push_back( pocLt );
+        follDeltaPocMsbPresentFlag.push_back( slice->getDeltaPocMsbPresentFlag( i ) ); k++; 
+      }
+    }
+    numPocLtCurr = j;
+    numPocLtFoll = k;
+  }
+
+  assert(numPocStCurrAfter  == pocStCurrAfter   .size() );
+  assert(numPocStCurrBefore == pocStCurrBefore  .size() );
+  assert(numPocStFoll       == pocStFoll        .size() );  
+  assert(numPocLtCurr       == pocLtCurr        .size() );  
+  assert(numPocLtFoll       == pocLtFoll        .size() );
+
+  // where PicOrderCntVal is the picture order count of the current picture as specified in clause 8.3.1.
+
+  //   NOTE 2 - A value of CurrRpsIdx in the range of 0 to num_short_term_ref_pic_sets - 1, inclusive, 
+  //   indicates that a candidate short-term RPS from the active SPS for the current layer is being used, 
+  //   where CurrRpsIdx is the index of the candidate short-term RPS into the list of candidate short-term RPSs signalled 
+  //   in the active SPS for the current layer. CurrRpsIdx equal to num_short_term_ref_pic_sets indicates that 
+  //   the short-term RPS of the current picture is directly signalled in the slice header.
+
+  for (Int i = 0; i <= numPocLtCurr - 1; i++  )
+  {
+      // For each i in the range of 0 to NumPocLtCurr - 1, inclusive, when CurrDeltaPocMsbPresentFlag[ i ] is equal to 1, 
+      // it is a requirement of bitstream conformance that the following conditions apply:
+    if ( currDeltaPocMsbPresentFlag[i] )
+    {
+      // -  There shall be no j in the range of 0 to NumPocStCurrBefore - 1, inclusive, 
+      //    for which PocLtCurr[ i ] is equal to PocStCurrBefore[ j ].
+      for (Int j = 0; j <= numPocStCurrBefore - 1; j++ )
+      {
+        assert(!( pocLtCurr[ i ] == pocStCurrBefore[ j ] ) );
+      }
+
+      // -  There shall be no j in the range of 0 to NumPocStCurrAfter - 1, inclusive, 
+      //    for which PocLtCurr[ i ] is equal to PocStCurrAfter[ j ]. 
+      for (Int j = 0; j <= numPocStCurrAfter - 1; j++ )
+      {
+        assert(!( pocLtCurr[ i ] == pocStCurrAfter[ j ] ) );
+      }
+
+      // -  There shall be no j in the range of 0 to NumPocStFoll - 1, inclusive, 
+      //    for which PocLtCurr[ i ] is equal to PocStFoll[ j ].
+      for (Int j = 0; j <= numPocStFoll - 1; j++ )
+      {
+        assert(!( pocLtCurr[ i ] == pocStFoll[ j ] ) );
+      }
+
+      // -  There shall be no j in the range of 0 to NumPocLtCurr - 1, inclusive, 
+      //    where j is not equal to i, for which PocLtCurr[ i ] is equal to PocLtCurr[ j ].
+      for (Int j = 0; j <= numPocLtCurr - 1; j++ )
+      {
+        if ( i != j )
+        {        
+          assert(!( pocLtCurr[ i ] == pocLtCurr[ j ] ) );
+        }
+      }
+    }
+  }
+
+  for (Int i = 0; i <= numPocLtFoll - 1; i++  )
+  {
+    // For each i in the range of 0 to NumPocLtFoll - 1, inclusive, when FollDeltaPocMsbPresentFlag[ i ] is equal to 1, 
+    // it is a requirement of bitstream conformance that the following conditions apply:
+    if ( follDeltaPocMsbPresentFlag[i] )
+    {
+      // -  There shall be no j in the range of 0 to NumPocStCurrBefore - 1, inclusive, 
+      //    for which PocLtFoll[ i ] is equal to PocStCurrBefore[ j ].
+      for (Int j = 0; j <= numPocStCurrBefore - 1; j++ )
+      {
+        assert(!( pocLtFoll[ i ] == pocStCurrBefore[ j ] ) );
+      }
+
+      // -  There shall be no j in the range of 0 to NumPocStCurrAfter - 1, inclusive, 
+      //    for which PocLtFoll[ i ] is equal to PocStCurrAfter[ j ].
+      for (Int j = 0; j <= numPocStCurrAfter - 1; j++ )
+      {
+        assert(!( pocLtFoll[ i ] == pocStCurrAfter[ j ] ) );
+      }
+
+      // -  There shall be no j in the range of 0 to NumPocStFoll - 1, inclusive, 
+      //    for which PocLtFoll[ i ] is equal to PocStFoll[ j ].
+      for (Int j = 0; j <= numPocStFoll - 1; j++ )
+      {
+        assert(!( pocLtFoll[ i ] == pocStFoll[ j ] ) );
+      }
+
+      // -  There shall be no j in the range of 0 to NumPocLtFoll - 1, inclusive, 
+      //    where j is not equal to i, for which PocLtFoll[ i ] is equal to PocLtFoll[ j ].
+      for (Int j = 0; j <= numPocLtFoll - 1; j++ )
+      {
+        if (j != i)
+        {
+          assert(!( pocLtFoll[ i ] == pocLtFoll[ j ] ) );
+        }
+      }
+
+      // -  There shall be no j in the range of 0 to NumPocLtCurr - 1, inclusive, 
+      //    for which PocLtFoll[ i ] is equal to PocLtCurr[ j ].
+      for (Int j = 0; j <= numPocLtCurr - 1; j++ )
+      {
+        assert(!( pocLtFoll[ i ] == pocLtCurr[ j ] ) );
+      }
+    }
+  }
+
+  Int maxPicOrderCntLsb = sps->getMaxPicOrderCntLsb(); 
+  for (Int i = 0; i <= numPocLtCurr - 1; i++  )
+  {
+    // For each i in the range of 0 to NumPocLtCurr - 1, inclusive, when CurrDeltaPocMsbPresentFlag[ i ] is equal to 0, 
+    // it is a requirement of bitstream conformance that the following conditions apply:
+    if ( currDeltaPocMsbPresentFlag[ i ] == 0  )
+    {
+      // -  There shall be no j in the range of 0 to NumPocStCurrBefore - 1, inclusive, 
+      //    for which PocLtCurr[ i ] is equal to ( PocStCurrBefore[ j ] & ( MaxPicOrderCntLsb - 1 ) ).
+      for (Int j = 0; j <= numPocStCurrBefore - 1; j++ )
+      {
+        assert(!( pocLtCurr[ i ] == ( pocStCurrBefore[ j ] & ( maxPicOrderCntLsb - 1 ) ) ) );
+      }
+
+      // -  There shall be no j in the range of 0 to NumPocStCurrAfter - 1, inclusive,
+      //    for which PocLtCurr[ i ] is equal to ( PocStCurrAfter[ j ] & ( MaxPicOrderCntLsb - 1 ) ).
+      for (Int j = 0; j <= numPocStCurrAfter - 1; j++ )
+      {
+        assert(!( pocLtCurr[ i ] == ( pocStCurrAfter[ j ] & ( maxPicOrderCntLsb - 1 ) ) ) );
+      }
+
+      // -  There shall be no j in the range of 0 to NumPocStFoll - 1, inclusive,
+      //    for which PocLtCurr[ i ] is equal to ( PocStFoll[ j ] & ( MaxPicOrderCntLsb - 1 ) ).
+      for (Int j = 0; j <= numPocStFoll - 1; j++ )
+      {
+        assert(!( pocLtCurr[ i ] == ( pocStFoll[ j ] & ( maxPicOrderCntLsb - 1 ) ) ) );
+      }
+
+      // -  There shall be no j in the range of 0 to NumPocLtCurr - 1, inclusive,
+      //    where j is not equal to i, for which PocLtCurr[ i ] is equal to ( PocLtCurr[ j ] & ( MaxPicOrderCntLsb - 1 ) ).
+      for (Int j = 0; j <= numPocLtCurr - 1; j++ )
+      {
+        if (j != i)
+        {
+          assert(!( pocLtCurr[ i ] == ( pocLtCurr[ j ] & ( maxPicOrderCntLsb - 1 ) ) ) );
+        }
+      }
+    }
+  }
+
+  for (Int i = 0; i <= numPocLtFoll - 1; i++  )
+  {
+    // For each i in the range of 0 to NumPocLtFoll - 1, inclusive, when FollDeltaPocMsbPresentFlag[ i ] is equal to 0, 
+    // it is a requirement of bitstream conformance that the following conditions apply:
+    if ( follDeltaPocMsbPresentFlag[ i ] == 0  )
+    {
+      // -  There shall be no j in the range of 0 to NumPocStCurrBefore - 1, inclusive,
+      //    for which PocLtFoll[ i ] is equal to ( PocStCurrBefore[ j ] & ( MaxPicOrderCntLsb - 1 ) ).
+      for (Int j = 0; j <= numPocStCurrBefore - 1; j++ )
+      {
+        assert(!( pocLtFoll[ i ] == ( pocStCurrBefore[ j ] & ( maxPicOrderCntLsb - 1 ) ) ) );
+      }
+
+      // -  There shall be no j in the range of 0 to NumPocStCurrAfter - 1, inclusive,
+      //    for which PocLtFoll[ i ] is equal to ( PocStCurrAfter[ j ] & ( MaxPicOrderCntLsb - 1 ) ).
+      for (Int j = 0; j <= numPocStCurrAfter - 1; j++ )
+      {
+        assert(!( pocLtFoll[ i ] == ( pocStCurrAfter[ j ] & ( maxPicOrderCntLsb - 1 ) ) ) );
+      }
+
+      // -  There shall be no j in the range of 0 to NumPocStFoll - 1, inclusive,
+      //    for which PocLtFoll[ i ] is equal to ( PocStFoll[ j ] & ( MaxPicOrderCntLsb - 1 ) ).
+      for (Int j = 0; j <= numPocStFoll - 1; j++ )
+      {
+        assert(!( pocLtFoll[ i ] == ( pocStFoll[ j ] & ( maxPicOrderCntLsb - 1 ) ) ) );
+      }
+
+      // -  There shall be no j in the range of 0 to NumPocLtFoll - 1, inclusive,
+      //    where j is not equal to i, for which PocLtFoll[ i ] is equal to ( PocLtFoll[ j ] & ( MaxPicOrderCntLsb - 1 ) ).
+      for (Int j = 0; j <= numPocLtFoll - 1; j++ )
+      {
+        if (j != i)
+        {
+          assert(!( pocLtFoll[ i ] == ( pocLtFoll[ j ] & ( maxPicOrderCntLsb - 1 ) ) ) );
+        }          
+      }
+
+      // -  There shall be no j in the range of 0 to NumPocLtCurr - 1, inclusive,
+      //    for which PocLtFoll[ i ] is equal to ( PocLtCurr[ j ] & ( MaxPicOrderCntLsb - 1 ) ).
+      for (Int j = 0; j <= numPocLtCurr - 1; j++ )
+      {
+        assert(!( pocLtFoll[ i ] == ( pocLtCurr[ j ] & ( maxPicOrderCntLsb - 1 ) ) ) );
+      }
+    }
+  }
+
+  if ( !annexFModifications )
+  {  
+    // The variable NumPicTotalCurr is derived as specified in clause 7.4.7.2. 
+
+    // It is a requirement of bitstream conformance that the following applies to the value of NumPicTotalCurr:
+    if ( m_pcPic->isBla() || m_pcPic->isCra() )
+    {
+      // -  If the current picture is a BLA or CRA picture, the value of NumPicTotalCurr shall be equal to 0.
+      assert( slice->getNumPicTotalCurr() == 0 ); 
+    }
+    else
+    {
+      // -  Otherwise, 
+      if ( slice->isInterP() || slice->isInterB() )
+      {
+        // when the current picture contains a P or B slice, the value of NumPicTotalCurr shall not be equal to 0.
+        assert( slice->getNumPicTotalCurr() != 0 ); 
+      }
+    }
+  }
+    
+  // The RPS of the current picture consists of five RPS lists; RefPicSetStCurrBefore, RefPicSetStCurrAfter, RefPicSetStFoll, 
+  // RefPicSetLtCurr and RefPicSetLtFoll. RefPicSetStCurrBefore, RefPicSetStCurrAfter and RefPicSetStFoll are collectively 
+  // referred to as the short-term RPS. RefPicSetLtCurr and RefPicSetLtFoll are collectively referred to as the long-term RPS.
+
+  std::vector<TComPic*>& refPicSetStCurrBefore = decRps->m_refPicSetStCurrBefore;
+  std::vector<TComPic*>& refPicSetStCurrAfter  = decRps->m_refPicSetStCurrAfter ;
+  std::vector<TComPic*>& refPicSetStFoll       = decRps->m_refPicSetStFoll      ;
+  std::vector<TComPic*>& refPicSetLtCurr       = decRps->m_refPicSetLtCurr      ;
+  std::vector<TComPic*>& refPicSetLtFoll       = decRps->m_refPicSetLtFoll      ;
+  
+  std::vector<TComPic*>** refPicSetsCurr       = decRps->m_refPicSetsCurr       ;
+  std::vector<TComPic*>** refPicSetsLt         = decRps->m_refPicSetsLt         ;
+  std::vector<TComPic*>** refPicSetsAll        = decRps->m_refPicSetsAll        ;
+  //   NOTE 3 - RefPicSetStCurrBefore, RefPicSetStCurrAfter and RefPicSetLtCurr contain all reference pictures that may be 
+  //   used for inter prediction of the current picture and one or more pictures that follow the current picture in decoding order.
+  //   RefPicSetStFoll and RefPicSetLtFoll consist of all reference pictures that are not used for inter prediction of the current 
+  //   picture but may be used in inter prediction for one or more pictures that follow the current picture in decoding order.
+
+  // The derivation process for the RPS and picture marking are performed according to the following ordered steps:
+  // 1.  The following applies:
+
+  TComSubDpb* dpb = m_dpb->getSubDpb( getLayerId(), false );   
+  assert( refPicSetLtCurr.empty() );
+  for( Int i = 0; i < numPocLtCurr; i++ ) 
+  {
+    if( !currDeltaPocMsbPresentFlag[ i ] ) 
+    {    
+      refPicSetLtCurr.push_back( dpb->getPicFromLsb( pocLtCurr[ i ], maxPicOrderCntLsb ) );       
+    }
+    else
+    {
+      refPicSetLtCurr.push_back(dpb->getPic( pocLtCurr[ i ] ));       
+    }    
+  }
+
+  assert( refPicSetLtFoll.empty() );
+  for( Int i = 0; i < numPocLtFoll; i++ )
+  {
+   if( !follDeltaPocMsbPresentFlag[ i ] )
+   {
+     refPicSetLtFoll.push_back(dpb->getPicFromLsb(pocLtFoll[ i ], maxPicOrderCntLsb ));
+   }
+   else
+   {
+     refPicSetLtFoll.push_back(dpb->getPic( pocLtFoll[ i ] ));       
+   }
+  }
+  
+  // 2.  All reference pictures that are included in RefPicSetLtCurr or RefPicSetLtFoll and have nuh_layer_id equal 
+  //     to currPicLayerId are marked as "used for long-term reference".
+  for (Int i = 0; i < numPocLtCurr; i++)
+  {
+    if ( refPicSetLtCurr[i] != NULL )
+    {
+      refPicSetLtCurr[i]->markAsUsedForLongTermReference(); 
+    }    
+  }
+
+  for (Int i = 0; i < numPocLtFoll; i++)
+  {
+    if ( refPicSetLtFoll[i] != NULL )
+    {
+      refPicSetLtFoll[i]->markAsUsedForLongTermReference(); 
+    }    
+  }
+
+  // 3.  The following applies:
+  assert( refPicSetStCurrBefore.empty() );
+  for( Int i = 0; i < numPocStCurrBefore; i++ )
+  {
+    refPicSetStCurrBefore.push_back(dpb->getShortTermRefPic( pocStCurrBefore[ i ] )); 
+  }
+
+  assert( refPicSetStCurrAfter.empty() );
+  for( Int i = 0; i < numPocStCurrAfter; i++ )
+  {
+    refPicSetStCurrAfter.push_back(dpb->getShortTermRefPic( pocStCurrAfter[ i ] )); 
+  }
+
+  assert( refPicSetStFoll.empty() );
+  for( Int i = 0; i < numPocStFoll; i++ )
+  {
+    refPicSetStFoll.push_back(dpb->getShortTermRefPic( pocStFoll[ i ] )); 
+  }
+  
+  // 4.  All reference pictures in the DPB that are not included in RefPicSetLtCurr, RefPicSetLtFoll, RefPicSetStCurrBefore, 
+  //     RefPicSetStCurrAfter, or RefPicSetStFoll and have nuh_layer_id equal to currPicLayerId are marked as "unused for reference".
+  TComSubDpb picsToMark = (*dpb); 
+  for (Int j = 0; j < 5; j++ )
+  {
+    picsToMark.removePics( *refPicSetsAll[j] ); 
+  }  
+  picsToMark.markAllAsUnusedForReference(); 
+  
+  //     NOTE 4 - There may be one or more entries in the RPS lists that are equal to "no reference picture" because 
+  //     the corresponding pictures are not present in the DPB. Entries in RefPicSetStFoll or RefPicSetLtFoll that are equal 
+  //     to "no reference picture" should be ignored. An unintentional picture loss should be inferred for each entry in 
+  //     RefPicSetStCurrBefore, RefPicSetStCurrAfter, or RefPicSetLtCurr that is equal to "no reference picture".
+
+  //     NOTE 5 - A picture cannot be included in more than one of the five RPS lists.
+
+  
+  // It is a requirement of bitstream conformance that the RPS is restricted as follows:
+
+
+#if NH_MV_FIX_NO_REF_PICS_CHECK
+  if ( !annexFModifications || m_firstPicInLayerDecodedFlag[ m_pcPic->getLayerId() ] )
+  { 
+#endif
+    for (Int j = 0; j < 3; j++ )
+    {
+      // -  There shall be no entry in RefPicSetStCurrBefore, RefPicSetStCurrAfter or RefPicSetLtCurr 
+      //    for which one or more of the following are true:
+
+      std::vector<TComPic*>* currSet = refPicSetsCurr[j]; 
+      for (Int i = 0; i < currSet->size(); i++)
+      {
+        TComPic* pic = (*currSet)[i]; 
+
+        // -  The entry is equal to "no reference picture".
+        assert( ! (pic == NULL ) ); 
+
+        // -  The entry is an SLNR picture and has TemporalId equal to that of the current picture.
+        assert( !( pic->isSlnr() && pic->getTemporalId() == m_pcPic->getTemporalId() ) ); 
+
+        // -  The entry is a picture that has TemporalId greater than that of the current picture.
+        assert( !(  pic->getTemporalId() > m_pcPic->getTemporalId() ) ); 
+      }      
+    }
+#if NH_MV_FIX_NO_REF_PICS_CHECK
+  }
+#endif
+  
+  //  -  There shall be no entry in RefPicSetLtCurr or RefPicSetLtFoll for which the 
+  //     difference between the picture order count value of the current picture and the picture order count 
+  //     value of the entry is greater than or equal to 2^24.
+  for (Int j = 0; j < 2; j++ )
   {    
-    NalUnitType nut = m_apcSlicePilot->getNalUnitType(); 
-
-    Bool isBLA =  ( nut == NAL_UNIT_CODED_SLICE_BLA_W_LP  )  || ( nut == NAL_UNIT_CODED_SLICE_BLA_N_LP ) || ( nut == NAL_UNIT_CODED_SLICE_BLA_W_RADL ); 
-    Bool isIDR  = ( nut == NAL_UNIT_CODED_SLICE_IDR_W_RADL ) || ( nut == NAL_UNIT_CODED_SLICE_IDR_N_LP ); 
-    Bool noClrasOutputFlag  = isBLA || ( isIDR  &&  m_apcSlicePilot->getCrossLayerBlaFlag() ); 
-
-    if ( noClrasOutputFlag ) 
-    {
-      for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++)
-      {
-        m_layerInitilizedFlag[i] = false; 
-      } 
-    }
-  }
-}
-
-Bool TDecTop::xAllRefLayersInitilized( const TComVPS* vps )
-{
-  Bool allRefLayersInitilizedFlag = true;   
-  for (Int i = 0; i < vps->getNumDirectRefLayers( getLayerId()  ); i++ )
-  {
-    Int refLayerId = vps->getIdDirectRefLayer( m_layerId, i ); 
-    allRefLayersInitilizedFlag = allRefLayersInitilizedFlag && m_layerInitilizedFlag[ refLayerId ]; 
-  }
-
-  return allRefLayersInitilizedFlag;
-}
-
-
-Void TDecTop::initFromActiveVps( const TComVPS* vps )
-{
-  if ( m_targetOlsIdx == -1 )
-  {
-    // Not normative! Corresponds to specification by "External Means". (Should be set equal to 0, when no external means available. ) 
-    m_targetOlsIdx = vps->getVpsNumLayerSetsMinus1(); 
-  }
-#if NH_3D
-  // Set profile
-  Int lsIdx = vps->olsIdxToLsIdx( m_targetOlsIdx );
-  Int lIdx = -1; 
-  for (Int j = 0; j < vps->getNumLayersInIdList( lsIdx ); j++ )
-  {
-    if ( vps->getLayerSetLayerIdList( lsIdx, j ) == getLayerId() )
-    {
-      lIdx = j; 
-      break; 
-    }        
-  }
-  assert( lIdx != -1 ); 
-
-  Int profileIdc = vps->getPTL( vps->getProfileTierLevelIdx( m_targetOlsIdx, lIdx ) )->getGeneralPTL()->getProfileIdc();
-  assert( profileIdc == 1 || profileIdc == 6 || profileIdc == 8 ); 
-  m_profileIdc = profileIdc;   
-#endif
-}
+    std::vector<TComPic*>* ltSet = refPicSetsLt[j]; 
+    for (Int i = 0; i < ltSet->size(); i++)
+    {
+      TComPic* pic = (*ltSet)[i]; 
+      if( pic != NULL )
+      {
+        assert(!( abs( m_pcPic->getPOC() - pic->getPOC() ) >= (1 << 24) )); 
+      }
+    }
+  }
+
+  //   -  When the current picture is a temporal sub-layer access (TSA) picture, there shall be no picture 
+  //      included in the RPS with TemporalId greater than or equal to the TemporalId of the current picture.
+  if (m_pcPic->isTsa() )
+  {
+    for (Int j = 0; j < 5; j++ )
+    {    
+      std::vector<TComPic*>* aSet = refPicSetsAll[j]; 
+      for (Int i = 0; i < aSet->size(); i++)
+      {
+        TComPic* pic = (*aSet)[i]; 
+        if( pic != NULL )
+        {
+          assert( ! (pic->getTemporalId() >= m_pcPic->getTemporalId() ) ); 
+        }
+      }
+    }
+  }
+
+  //   -  When the current picture is a step-wise temporal sub-layer access (STSA) picture, 
+  //      there shall be no picture included in RefPicSetStCurrBefore, RefPicSetStCurrAfter or RefPicSetLtCurr that has
+  //      TemporalId equal to that of the current picture.
+  if (m_pcPic->isStsa() )
+  {
+    for (Int j = 0; j < 3; j++ )
+    {    
+      std::vector<TComPic*>* cSet = refPicSetsCurr[j]; 
+      for (Int i = 0; i < cSet->size(); i++)
+      {
+        TComPic* pic = (*cSet)[i]; 
+        if( pic != NULL )
+        {
+          assert( ! (pic->getTemporalId() == m_pcPic->getTemporalId() ) ); 
+        }
+      }
+    }
+  }
+
+  //   -  When the current picture is a picture that follows, in decoding order, an STSA picture
+  //      that has TemporalId equal to that of the current picture, there shall be no picture that has
+  //      TemporalId equal to that of the current picture included in RefPicSetStCurrBefore, RefPicSetStCurrAfter
+  //      or RefPicSetLtCurr that precedes the STSA picture in decoding order.
+  if ( m_pcPic->getDecodingOrder() > m_prevStsaDecOrder && m_pcPic->getTemporalId() == m_prevStsaTemporalId  )
+  {
+    for (Int j = 0; j < 3; j++ )
+    {    
+      std::vector<TComPic*>* cSet = refPicSetsCurr[j]; 
+      for (Int i = 0; i < cSet->size(); i++)
+      {
+        TComPic* pic = (*cSet)[i]; 
+        if( pic != NULL )
+        {
+          assert( ! (pic->getTemporalId() == m_pcPic->getTemporalId() && pic->getDecodingOrder() < m_prevStsaDecOrder  ) ); 
+        }
+      }
+    }
+  }
+  
+  //   -  When the current picture is a CRA picture, there shall be no picture included in the RPS that
+  //      precedes, in output order or decoding order, any preceding IRAP picture in decoding order (when present).
+  if ( m_pcPic->isCra() )
+  {
+    for (Int j = 0; j < 5; j++ )
+    {    
+      std::vector<TComPic*>* aSet = refPicSetsAll[j]; 
+      for (Int i = 0; i < aSet->size(); i++)
+      {
+        // TBD check whether it sufficient to test only the last IRAP
+        TComPic* pic = (*aSet)[i]; 
+        if( pic != NULL )
+        {        
+          assert( ! (pic->getPOC()           < m_prevIrapPoc           ) );           
+          assert( ! (pic->getDecodingOrder() < m_prevIrapDecodingOrder ) ); 
+        }
+      }
+    }
+  }
+  
+  Bool isTrailingPicture = ( !m_pcPic->isIrap() ) && ( m_pcPic->getPOC() > m_prevIrapPoc );
+  //   -  When the current picture is a trailing picture, there shall be no picture in RefPicSetStCurrBefore,
+  //      RefPicSetStCurrAfter or RefPicSetLtCurr that was generated by the decoding process for generating unavailable
+  //      reference pictures as specified in clause 8.3.3.
+  if ( isTrailingPicture )
+  {
+    for (Int j = 0; j < 3; j++ )
+    {    
+      std::vector<TComPic*>* cSet = refPicSetsCurr[j]; 
+      for (Int i = 0; i < cSet->size(); i++)
+      {
+        TComPic* pic = (*cSet)[i]; 
+        if( pic != NULL )
+        {
+          assert( ! (pic->getIsGeneratedCl833() ) ); 
+        }
+      }
+    }
+  }
+
+  //   -  When the current picture is a trailing picture, there shall be no picture in the RPS that precedes the
+  //      associated IRAP picture in output order or decoding order.
+  if ( isTrailingPicture )
+  {
+    for (Int j = 0; j < 5; j++ )
+    {    
+      std::vector<TComPic*>* aSet = refPicSetsAll[j]; 
+      for (Int i = 0; i < aSet->size(); i++)
+      {
+        // TBD check whether it sufficient to test only the last IRAP
+         TComPic* pic = (*aSet)[i]; 
+        if( pic != NULL )
+        {         
+          assert( ! (pic->getPOC()           < m_prevIrapPoc           ) ); 
+          assert( ! (pic->getDecodingOrder() < m_prevIrapDecodingOrder ) ); 
+        }
+      }
+    }
+  }
+
+  //   -  When the current picture is a RADL picture, there shall be no picture included in RefPicSetStCurrBefore,
+  //      RefPicSetStCurrAfter or RefPicSetLtCurr that is any of the following:
+  if ( m_pcPic->isRadl() )
+  {
+    for (Int j = 0; j < 3; j++ )
+    {    
+      std::vector<TComPic*>* cSet = refPicSetsCurr[j]; 
+      for (Int i = 0; i < cSet->size(); i++)
+      {        
+        TComPic* pic = (*cSet)[i]; 
+        if( pic != NULL )
+        {        
+          // -  A RASL picture
+          assert( ! (pic->isRasl() ) ); 
+          // -  A picture that was generated by the decoding process for generating unavailable reference pictures 
+          //    as specified in clause 8.3.3
+          assert( ! (pic->getIsGeneratedCl833() ) ); 
+          // -  A picture that precedes the associated IRAP picture in decoding order
+          assert( ! (pic->getDecodingOrder() < m_prevIrapDecodingOrder ) ); 
+        }
+      }
+    }
+  }
+  
+  
+  if ( sps->getTemporalIdNestingFlag() )
+  {
+    // -  When sps_temporal_id_nesting_flag is equal to 1, the following applies:
+    //    -  Let tIdA be the value of TemporalId of the current picture picA.
+    TComPic* picA = m_pcPic; 
+    Int      tIdA = picA->getTemporalId();
+    //   -  Any picture picB with TemporalId equal to tIdB that is less than or equal to tIdA shall not be included in 
+    //      RefPicSetStCurrBefore, RefPicSetStCurrAfter or RefPicSetLtCurr of picA when there exists a picture picC that 
+    //      has TemporalId less than tIdB, follows picB in decoding order, and precedes picA in decoding order.
+    for (Int j = 0; j < 3; j++ )
+    {    
+      std::vector<TComPic*>* cSet = refPicSetsCurr[j]; 
+      for (Int i = 0; i < cSet->size(); i++)
+      {
+        TComPic* picB = (*cSet)[i]; 
+        if( picB != NULL )
+        {
+          Int tIdB = picB->getTemporalId(); 
+
+          if (tIdB <= tIdA)
+          {
+            for ( TComSubDpb::iterator itP = dpb->begin(); itP != dpb->end(); itP++ )
+            {
+              TComPic* picC = (*itP); 
+              assert(! ( picC->getTemporalId() < tIdB && picC->getDecodingOrder() > picB->getDecodingOrder() && picC->getDecodingOrder() < picA->getDecodingOrder()  )  ); 
+            }
+          }
+        }
+      }
+    }
+  }    
+}
+
+
+Void TDecTop::xF832DecProcForRefPicSet()
+{
+  ///////////////////////////////////////////////////////////////////////////////////////
+  // F.8.3.2 Decoding process for reference picture set
+  ///////////////////////////////////////////////////////////////////////////////////////
+
+  // The specifications in clause 8.3.2 apply with the following changes:
+  // -  The references to clauses 7.4.7.2, 8.3.1, 8.3.3 and 8.3.4 are replaced with references to 
+  //    clauses F.7.4.7.2, F.8.3.1, F.8.3.3 and F.8.3.4, respectively.
+
+  x832DecProcForRefPicSet( true ); 
+
+  // -  The following specifications are added:
+  if (m_pcPic->isIrap() && m_pcPic->getLayerId() == m_smallestLayerId )
+  {
+    // -  When the current picture is an IRAP picture with nuh_layer_id equal to SmallestLayerId, 
+    //    all reference pictures with any value of nuh_layer_id currently in the DPB (if any) are marked 
+    //    as "unused for reference" when at least one of the following conditions is true:
+
+    if ( m_pcPic->getNoClrasOutputFlag() || m_pcPic->getActivatesNewVps() )
+    {
+      // -  The current picture has NoClrasOutputFlag is equal to 1.
+      // -  The current picture activates a new VPS.
+      m_dpb->markAllSubDpbAsUnusedForReference( );
+    }
+  }
+
+  // -  It is a requirement of bitstream conformance that the RPS is restricted as follows:
+  // -  When the current picture is a CRA picture, there shall be no picture in RefPicSetStCurrBefore, RefPicSetStCurrAfter 
+  //    or RefPicSetLtCurr.
+
+  std::vector<TComPic*>** refPicSetsCurr       = m_pcPic->getDecodedRps()->m_refPicSetsCurr;
+
+  if ( m_pcPic->isCra() )
+  {
+    for (Int j = 0; j < 3; j++ )   
+    {    
+      std::vector<TComPic*>* cSet = refPicSetsCurr[j]; 
+      assert ( cSet->size() == 0 ); 
+    }
+  }
+
+  // -  The constraints specified in clause 8.3.2 on the value of NumPicTotalCurr are replaced with the following:
+  //    -  It is a requirement of bitstream conformance that the following applies to the value of NumPicTotalCurr:
+  Int numPicTotalCurr = m_pcPic->getSlice(0)->getNumPicTotalCurr(); 
+  Int currPicLayerId  = m_pcPic->getLayerId(); 
+  const TComVPS* vps  = m_pcPic->getSlice(0)->getVPS(); 
+
+  if ( ( m_pcPic->isBla() || m_pcPic->isCra() ) && (  (currPicLayerId == 0 ) || ( vps->getNumDirectRefLayers( currPicLayerId ) == 0 ) ) )
+  {   
+    assert( numPicTotalCurr == 0 ); 
+    // -  If the current picture is a BLA or CRA picture and either currPicLayerId is equal to 0 or 
+    //     NumDirectRefLayers[ currPicLayerId ] is equal to 0, the value of NumPicTotalCurr shall be equal to 0.
+  }
+  else
+  {
+    // TBD: check all slices
+    if ( m_pcPic->getSlice(0)->getSliceType() == P_SLICE  ||  m_pcPic->getSlice(0)->getSliceType() == B_SLICE )
+    {
+      // -  Otherwise, when the current picture contains a P or B slice, the value of NumPicTotalCurr shall not be equal to 0.
+      assert( numPicTotalCurr != 0 ); 
+    }
+  }
+}
+
+
+Void TDecTop::xG813DecProcForInterLayerRefPicSet()
+{
+  ////////////////////////////////////////////////////////////////////
+  // G.8.1.3 Decoding process for inter-layer reference picture set //
+  ////////////////////////////////////////////////////////////////////
+
+  // Outputs of this process are updated lists of inter-layer reference pictures RefPicSetInterLayer0 and RefPicSetInterLayer1 
+  // and the variables NumActiveRefLayerPics0 and NumActiveRefLayerPics1.
+
+  TComDecodedRps* decRps = m_pcPic->getDecodedRps(); 
+  TComSlice* slice       = m_pcPic->getSlice( 0 ); 
+  const TComVPS* vps     =  slice->getVPS(); 
+
+  Int&                   numActiveRefLayerPics0 = decRps->m_numActiveRefLayerPics0;
+  Int&                   numActiveRefLayerPics1 = decRps->m_numActiveRefLayerPics1;
+
+  std::vector<TComPic*>& refPicSetInterLayer0   = decRps->m_refPicSetInterLayer0;
+  std::vector<TComPic*>& refPicSetInterLayer1   = decRps->m_refPicSetInterLayer1; 
+
+  // The variable currLayerId is set equal to nuh_layer_id of the current picture.
+  Int currLayerId = getLayerId(); 
+
+  // The lists RefPicSetInterLayer0 and RefPicSetInterLayer1 are first emptied, NumActiveRefLayerPics0 and NumActiveRefLayerPics1 
+  // are set equal to 0 and the following applies:
+
+  refPicSetInterLayer0.clear(); 
+  refPicSetInterLayer1.clear(); 
+
+  numActiveRefLayerPics0 = 0; 
+  numActiveRefLayerPics1 = 0; 
+
+  Int viewIdCurrLayerId  = vps->getViewId( currLayerId ); 
+  Int viewId0            = vps->getViewId( 0   );
+
+  for( Int i = 0; i < slice->getNumActiveRefLayerPics(); i++ )   
+  {
+    Int viewIdRefPicLayerIdi = vps->getViewId( slice->getRefPicLayerId( i ) ); 
+
+    Bool refPicSet0Flag =
+      ( ( viewIdCurrLayerId <=  viewId0  &&  viewIdCurrLayerId <=  viewIdRefPicLayerIdi )  ||
+      ( viewIdCurrLayerId >=  viewId0  &&  viewIdCurrLayerId >=  viewIdRefPicLayerIdi ) );
+
+    TComPic* picX = m_dpb->getAu(slice->getPOC(), false )->getPic( slice->getRefPicLayerId( i ) );
+    if ( picX != NULL )
+    {
+      // there is a picture picX in the DPB that is in the same access unit as the current picture and has
+      // nuh_layer_id equal to RefPicLayerId[ i ] 
+
+      if ( refPicSet0Flag )
+      {
+        refPicSetInterLayer0.push_back( picX );
+        refPicSetInterLayer0[ numActiveRefLayerPics0++ ]->markAsUsedForLongTermReference();
+      }
+      else
+      {
+        refPicSetInterLayer1.push_back( picX );
+        refPicSetInterLayer1[ numActiveRefLayerPics1++ ]->markAsUsedForLongTermReference();
+      }
+
+      // There shall be no picture that has discardable_flag equal to 1 in RefPicSetInterLayer0 or RefPicSetInterLayer1.
+      assert( ! picX->getSlice(0)->getDiscardableFlag() );
+
+      // If the current picture is a RADL picture, there shall be no entry in RefPicSetInterLayer0 or RefPicSetInterLayer1 
+      // that is a RASL picture.
+      if ( m_pcPic->isRadl() )
+      {
+        assert( ! picX->isRasl() );
+      }
+    }
+    else
+    {
+      if( refPicSet0Flag )
+      {
+        refPicSetInterLayer0.push_back( NULL ); // "no reference picture" (G 1)
+        numActiveRefLayerPics0++;
+      }
+      else
+      {
+        refPicSetInterLayer1.push_back( NULL ); // "no reference picture";
+        numActiveRefLayerPics1++;
+      }
+      // There shall be no entry equal to "no reference picture" in RefPicSetInterLayer0 or RefPicSetInterLayer1.
+      assert( false );
+    }
+  }
+}
+
+
+Void TDecTop::x8331GenDecProcForGenUnavilRefPics()
+{
+  ///////////////////////////////////////////////////////////////////////////////////////
+  // 8.3.3.1  General decoding process for generating unavailable reference pictures ////
+  ///////////////////////////////////////////////////////////////////////////////////////
+
+  // This process is invoked once per coded picture when the current picture is a 
+  // BLA picture or is a CRA picture with NoRaslOutputFlag equal to 1.
+
+  assert( m_pcPic->isBla() || (m_pcPic->isCra() && m_pcPic->getNoRaslOutputFlag() ) );
+  TComDecodedRps* decRps = m_pcPic->getDecodedRps(); 
+
+  std::vector<TComPic*>& refPicSetStFoll      = decRps->m_refPicSetStFoll;
+  std::vector<TComPic*>& refPicSetLtFoll      = decRps->m_refPicSetLtFoll; 
+
+  const std::vector<Int>& pocStFoll             = decRps->m_pocStFoll;
+  const std::vector<Int>& pocLtFoll             = decRps->m_pocLtFoll;
+
+  const Int               numPocStFoll          = decRps->m_numPocStFoll;
+  const Int               numPocLtFoll          = decRps->m_numPocLtFoll;   
+
+  // When this process is invoked, the following applies:
+  for ( Int i = 0 ; i <= numPocStFoll - 1; i++ )
+  {
+    if ( refPicSetStFoll[ i ] == NULL )
+    {
+      //-  For each RefPicSetStFoll[ i ], with i in the range of 0 to NumPocStFoll - 1, inclusive, that is equal 
+      //   to "no reference picture", a picture is generated as specified in clause 8.3.3.2, and the following applies:
+      TComPic* genPic = x8332GenOfOneUnavailPic( true );  
+
+      // -  The value of PicOrderCntVal for the generated picture is set equal to PocStFoll[ i ].
+      genPic->getSlice(0)->setPOC( pocStFoll[ i ] );
+
+      //-  The value of PicOutputFlag for the generated picture is set equal to 0.  
+      genPic->setPicOutputFlag( false ); 
+
+      // -  The generated picture is marked as "used for short-term reference".
+      genPic->markAsUsedForShortTermReference();
+
+      // -  RefPicSetStFoll[ i ] is set to be the generated reference picture.
+      refPicSetStFoll[ i ] = genPic;
+
+      // -  The value of nuh_layer_id for the generated picture is set equal to nuh_layer_id of the current picture.
+      genPic->setLayerId( m_pcPic-> getLayerId() ); 
+
+      // Insert to DPB
+      m_dpb->addNewPic( genPic ); 
+    }
+  }
+
+  for ( Int i = 0 ; i <= numPocLtFoll - 1; i++ )
+  {
+    if ( refPicSetLtFoll[ i ] == NULL )
+    {
+      //-  For each RefPicSetLtFoll[ i ], with i in the range of 0 to NumPocLtFoll - 1, inclusive, that is equal to 
+      //   "no reference picture", a picture is generated as specified in clause 8.3.3.2, and the following applies:
+      TComPic* genPic = x8332GenOfOneUnavailPic( true );  
+
+      //-  The value of PicOrderCntVal for the generated picture is set equal to PocLtFoll[ i ].
+      genPic->getSlice(0)->setPOC( pocStFoll[ i ] );
+
+      //  -  The value of slice_pic_order_cnt_lsb for the generated picture is inferred to be equal to ( PocLtFoll[ i ] & ( MaxPicOrderCntLsb - 1 ) ).
+      genPic->getSlice(0)->setSlicePicOrderCntLsb( ( pocLtFoll[ i ] & ( m_pcPic->getSlice(0)->getSPS()->getMaxPicOrderCntLsb() - 1 ) ) ); 
+
+      //  -  The value of PicOutputFlag for the generated picture is set equal to 0.    
+      genPic->setPicOutputFlag( false ); 
+
+      //  -  The generated picture is marked as "used for long-term reference".
+      genPic->markAsUsedForLongTermReference();
+
+      //  -  RefPicSetLtFoll[ i ] is set to be the generated reference picture.
+      refPicSetLtFoll[ i ] = genPic;
+
+      //  -  The value of nuh_layer_id for the generated picture is set equal to nuh_layer_id of the current picture.
+      genPic->setLayerId( m_pcPic-> getLayerId() ); 
+
+      // Insert to DPB
+      m_dpb->addNewPic( genPic ); 
+    }
+  }
+}
+
+
+TComPic* TDecTop::x8332GenOfOneUnavailPic( Bool calledFromCl8331 )
+{
+  ///////////////////////////////////////////////////////////////////////////////////////
+  // 8.3.3.2 Generation of one unavailable picture
+  ///////////////////////////////////////////////////////////////////////////////////////
+
+  TComPic* genPic = new TComPic; 
+  genPic->create( *m_pcPic->getSlice(0)->getSPS(), *m_pcPic->getSlice(0)->getPPS(), true ); 
+  genPic->setIsGenerated( true );     
+  genPic->setIsGeneratedCl833( calledFromCl8331 ); 
+  return genPic;
+}
+
+
+Void TDecTop::xF817DecProcForGenUnavRefPicForPicsFrstInDecOrderInLay()
+{
+  ///////////////////////////////////////////////////////////////////////////////////////
+  // F.8.1.7 Decoding process for generating unavailable reference pictures for pictures 
+  //         first in decoding order within a layer
+  ///////////////////////////////////////////////////////////////////////////////////////
+
+  //  This process is invoked for a picture with nuh_layer_id equal to layerId, when FirstPicInLayerDecodedFlag[layerId ] is equal to 0.   
+  assert( !m_firstPicInLayerDecodedFlag[ getLayerId() ] );
+
+
+  TComDecodedRps* decRps = m_pcPic->getDecodedRps(); 
+
+  std::vector<TComPic*>& refPicSetStCurrBefore = decRps->m_refPicSetStCurrBefore; 
+  std::vector<TComPic*>& refPicSetStCurrAfter  = decRps->m_refPicSetStCurrAfter;
+  std::vector<TComPic*>& refPicSetStFoll       = decRps->m_refPicSetStFoll;
+  std::vector<TComPic*>& refPicSetLtCurr       = decRps->m_refPicSetLtCurr; 
+  std::vector<TComPic*>& refPicSetLtFoll       = decRps->m_refPicSetLtFoll; 
+
+
+  const std::vector<Int>& pocStCurrBefore      = decRps->m_pocStCurrBefore;
+  const std::vector<Int>& pocStCurrAfter       = decRps->m_pocStCurrAfter;
+  const std::vector<Int>& pocStFoll            = decRps->m_pocStFoll;
+  const std::vector<Int>& pocLtCurr            = decRps->m_pocLtCurr;
+  const std::vector<Int>& pocLtFoll            = decRps->m_pocLtFoll;
+
+  const Int numPocStCurrBefore                 = decRps->m_numPocStCurrBefore; 
+  const Int numPocStCurrAfter                  = decRps->m_numPocStCurrAfter;
+  const Int numPocStFoll                       = decRps->m_numPocStFoll;
+  const Int numPocLtCurr                       = decRps->m_numPocLtCurr;
+  const Int numPocLtFoll                       = decRps->m_numPocLtFoll;   
+
+  Int nuhLayerId = m_pcPic-> getLayerId(); 
+  for ( Int i = 0 ; i <= numPocStCurrBefore - 1; i++ )
+  {
+    if ( refPicSetStCurrBefore[ i ] == NULL )
+    {
+      //-  For each RefPicSetStCurrBefore[ i ], with i in the range of 0 to NumPocStCurrBefore - 1, inclusive, that is 
+      //  equal to "no reference picture", a picture is generated as specified in clause 8.3.3.2 and the following applies:
+      TComPic* genPic = x8332GenOfOneUnavailPic( false );  
+
+      //-  The value of PicOrderCntVal for the generated picture is set equal to PocStCurrBefore[ i ].
+      genPic->getSlice(0)->setPOC( pocStCurrBefore[ i ] );
+
+      //  -  The value of PicOutputFlag for the generated picture is set equal to 0.
+      genPic->setPicOutputFlag( false ); 
+
+      //  -  The generated picture is marked as "used for short-term reference".
+      genPic->markAsUsedForShortTermReference();
+
+      //  -  RefPicSetStCurrBefore[ i ] is set to be the generated reference picture.
+      refPicSetStCurrBefore[ i ] = genPic;
+
+      //  -  The value of nuh_layer_id for the generated picture is set equal to nuh_layer_id.
+      genPic->setLayerId( nuhLayerId ); 
+
+      // Insert to DPB
+      m_dpb->addNewPic( genPic ); 
+    }
+  }
+
+  for ( Int i = 0 ; i <= numPocStCurrAfter - 1; i++ )
+  {
+    if ( refPicSetStCurrAfter[ i ] == NULL )
+    {
+      //  -  For each RefPicSetStCurrAfter[ i ], with i in the range of 0 to NumPocStCurrAfter - 1, inclusive, that is equal 
+      //     to "no reference picture", a picture is generated as specified in clause 8.3.3.2 and the following applies:
+      TComPic* genPic = x8332GenOfOneUnavailPic( false );  
+
+      //  -  The value of PicOrderCntVal for the generated picture is set equal to PocStCurrAfter[ i ].
+      genPic->getSlice(0)->setPOC( pocStCurrAfter[ i ] );
+
+      //  -  The value of PicOutputFlag for the generated picture is set equal to 0.
+      genPic->setPicOutputFlag( false ); 
+
+      //  -  The generated picture is marked as "used for short-term reference".
+      genPic->markAsUsedForShortTermReference();
+
+      //  -  RefPicSetStCurrAfter[ i ] is set to be the generated reference picture.
+      refPicSetStCurrAfter[ i ] = genPic;
+
+      //  -  The value of nuh_layer_id for the generated picture is set equal to nuh_layer_id.
+      genPic->setLayerId( nuhLayerId ); 
+
+      // Insert to DPB
+      m_dpb->addNewPic( genPic ); 
+
+    }
+  }
+
+  for ( Int i = 0 ; i <= numPocStFoll - 1; i++ )
+  {
+    if ( refPicSetStFoll[ i ] == NULL )
+    {
+      //  -  For each RefPicSetStFoll[ i ], with i in the range of 0 to NumPocStFoll - 1, inclusive, that is equal to "no 
+      //     reference picture", a picture is generated as specified in clause 8.3.3.2 and the following applies:
+      TComPic* genPic = x8332GenOfOneUnavailPic( false );  
+
+      //  -  The value of PicOrderCntVal for the generated picture is set equal to PocStFoll[ i ].
+      genPic->getSlice(0)->setPOC( pocStFoll[ i ] );
+
+      //  -  The value of PicOutputFlag for the generated picture is set equal to 0.
+      genPic->setPicOutputFlag( false ); 
+
+      //  -  The generated picture is marked as "used for short-term reference".
+      genPic->markAsUsedForShortTermReference();
+
+      //  -  RefPicSetStFoll[ i ] is set to be the generated reference picture.
+      refPicSetStFoll[ i ] = genPic;
+
+      //  -  The value of nuh_layer_id for the generated picture is set equal to nuh_layer_id.
+      genPic->setLayerId( nuhLayerId ); 
+
+      // Insert to DPB
+      m_dpb->addNewPic( genPic ); 
+    }
+  }
+
+  Int maxPicOrderCntLsb = m_pcPic->getSlice(0)->getSPS()->getMaxPicOrderCntLsb();  
+  for ( Int i = 0 ; i <= numPocLtCurr - 1; i++ )
+  {
+    if ( refPicSetLtCurr[ i ] == NULL )
+    {
+      //  -  For each RefPicSetLtCurr[ i ], with i in the range of 0 to NumPocLtCurr - 1, inclusive, that is equal to "no 
+      //     reference picture", a picture is generated as specified in clause 8.3.3.2 and the following applies:
+      TComPic* genPic = x8332GenOfOneUnavailPic( false );  
+
+      //  -  The value of PicOrderCntVal for the generated picture is set equal to PocLtCurr[ i ].
+      genPic->getSlice(0)->setPOC( pocLtCurr[ i ] );
+
+      //  -  The value of slice_pic_order_cnt_lsb for the generated picture is inferred to be equal to ( PocLtCurr[ i ] & ( 
+      //     MaxPicOrderCntLsb - 1 ) ).
+      genPic->getSlice(0)->setSlicePicOrderCntLsb( ( pocLtCurr[ i ] & ( maxPicOrderCntLsb - 1 ) ) ); 
+
+      //  -  The value of PicOutputFlag for the generated picture is set equal to 0.
+      genPic->setPicOutputFlag( false ); 
+
+      //  -  The generated picture is marked as "used for long-term reference".
+      genPic->markAsUsedForLongTermReference();
+
+      //  -  RefPicSetLtCurr[ i ] is set to be the generated reference picture.
+      refPicSetLtCurr[ i ] = genPic;
+
+      //  -  The value of nuh_layer_id for the generated picture is set equal to nuh_layer_id.
+      genPic->setLayerId( nuhLayerId ); 
+
+      // Insert to DPB
+      m_dpb->addNewPic( genPic ); 
+    }
+  }
+
+  for ( Int i = 0 ; i <= numPocLtFoll - 1; i++ )
+  {
+    if ( refPicSetLtFoll[ i ] == NULL )
+    {
+      //  -  For each RefPicSetLtFoll[ i ], with i in the range of 0 to NumPocLtFoll - 1, inclusive, that is equal to "no 
+      //     reference picture", a picture is generated as specified in clause 8.3.3.2 and the following applies:
+      TComPic* genPic = x8332GenOfOneUnavailPic( false );  
+
+      //  -  The value of PicOrderCntVal for the generated picture is set equal to PocLtFoll[ i ].
+      genPic->getSlice(0)->setPOC( pocLtFoll[ i ] );
+
+      //  -  The value of slice_pic_order_cnt_lsb for the generated picture is inferred to be equal to ( PocLtCurr[ i ] & ( 
+      //     MaxPicOrderCntLsb - 1 ) ).
+      genPic->getSlice(0)->setSlicePicOrderCntLsb( ( pocLtCurr[ i ] & ( maxPicOrderCntLsb - 1 ) ) ); 
+
+      //  -  The value of PicOutputFlag for the generated picture is set equal to 0.
+      genPic->setPicOutputFlag( false ); 
+
+      //  -  The generated picture is marked as "used for long-term reference".
+      genPic->markAsUsedForLongTermReference();
+
+      //  -  RefPicSetLtFoll[ i ] is set to be the generated reference picture.
+      refPicSetLtFoll[ i ] = genPic;
+
+      //  -  The value of nuh_layer_id for the generated picture is set equal to nuh_layer_id.
+      genPic->setLayerId( nuhLayerId ); 
+
+      // Insert to DPB
+      m_dpb->addNewPic( genPic ); 
+    }
+  }
+}
+
+Void TDecTop::xF833DecProcForGenUnavRefPics()
+{
+  ///////////////////////////////////////////////////////////////////////////////////////
+  // F.8.3.3 Decoding process for generating unavailable reference picture
+  ///////////////////////////////////////////////////////////////////////////////////////
+
+  x8331GenDecProcForGenUnavilRefPics();
+}
+
+Void TDecTop::xCheckUnavailableRefPics()
+{
+  std::vector<TComPic*>** refPicSetsCurr       = m_pcPic->getDecodedRps()->m_refPicSetsCurr;
+
+  Bool hasGeneratedRefPic = false; 
+  for (Int j = 0; j < 3; j++ )   
+  {    
+    std::vector<TComPic*>* cSet = refPicSetsCurr[j]; 
+    for (Int i = 0 ; i < cSet->size();  i++ )
+    {
+      assert( (*cSet)[i] != NULL );
+      if ((*cSet)[i]->getIsGenerated() )
+      {
+        hasGeneratedRefPic = true; 
+      }
+    }
+  }
+  m_pcPic->setHasGeneratedRefPics( hasGeneratedRefPic ); 
+}
+
 #endif
 
Index: trunk/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecTop.h	(revision 1314)
+++ trunk/source/Lib/TLibDecoder/TDecTop.h	(revision 1321)
@@ -81,10 +81,4 @@
   Int**** getBaseViewShiftLUTI()  { return m_aiBaseViewShiftLUT;   }
 
-#if !NH_3D_FIX_TICKET_101
-#if NH_3D_IV_MERGE
-  Void  copyCamParamForSlice( TComSlice* pcSlice );
-#endif
-#endif
-
 private:
   Void xResetReceivedIdc( Bool overWriteFlag ); 
@@ -182,18 +176,15 @@
 {
 private:
-  Int                     m_iMaxRefPicNum;
-
-  NalUnitType             m_associatedIRAPType; ///< NAL unit type of the associated IRAP picture
-  Int                     m_pocCRA;            ///< POC number of the latest CRA picture
-  Int                     m_pocRandomAccess;   ///< POC number of the random access point (the first IDR or CRA picture)
-
-  TComList<TComPic*>      m_cListPic;         //  Dynamic buffer
-#if NH_MV
-  Bool*                    m_layerInitilizedFlag; // initialization Layers
-  static ParameterSetManager m_parameterSetManager;  // storage for parameter sets 
-  Int                      m_targetOlsIdx; 
-#else
-  ParameterSetManager     m_parameterSetManager;  // storage for parameter sets
-#endif
+  Int                         m_iMaxRefPicNum;
+                              
+  NalUnitType                 m_associatedIRAPType; ///< NAL unit type of the associated IRAP picture
+#if !NH_MV
+  Int                         m_pocCRA;            ///< POC number of the latest CRA picture
+  Int                         m_pocRandomAccess;   ///< POC number of the random access point (the first IDR or CRA picture)
+  
+  TComList<TComPic*>           m_cListPic;         //  Dynamic buffer
+  ParameterSetManager          m_parameterSetManager;  // storage for parameter sets
+#endif
+
   TComSlice*              m_apcSlicePilot;
 
@@ -215,14 +206,14 @@
 
   Bool isSkipPictureForBLA(Int& iPOCLastDisplay);
-#if NH_MV
-  Bool isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay, const TComVPS* vps);
-#else
+#if !NH_MV
   Bool isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay);
 #endif
+
   TComPic*                m_pcPic;
   UInt                    m_uiSliceIdx;
+#if !NH_MV
   Int                     m_prevPOC;
   Int                     m_prevTid0POC;
-  Bool                    m_bFirstSliceInPicture;
+  Bool                    m_bFirstSliceInPicture;  
   Bool                    m_bFirstSliceInSequence;
   Bool                    m_prevSliceSkipped;
@@ -232,27 +223,56 @@
   Bool                    m_isNoOutputPriorPics;
   Bool                    m_craNoRaslOutputFlag;    //value of variable NoRaslOutputFlag of the last CRA pic
+#endif
+  
 #if O0043_BEST_EFFORT_DECODING
   UInt                    m_forceDecodeBitDepth;
 #endif
+
+
   std::ostream           *m_pDecodedSEIOutputStream;
 
+#if !NH_MV
   Bool                    m_warningMessageSkipPicture;
+#endif
+
 #if NH_MV
-  Bool                    m_isLastNALWasEos;
-#endif
-
-#if NH_MV
-  // For NH_MV m_bFirstSliceInSequence indicates first slice in sequence of the particular layer  
+  // Class interface 
+  static ParameterSetManager  m_parameterSetManager;  // storage for parameter sets 
+  TComPicLists*           m_dpb; 
+#if NH_3D
+  CamParsCollector*       m_pcCamParsCollector;
+#endif
+
+  // Layer identification
   Int                     m_layerId;
   Int                     m_viewId;
-  TComPicLists*           m_ivPicLists;
-  std::vector<TComPic*>   m_refPicSetInterLayer0; 
-  std::vector<TComPic*>   m_refPicSetInterLayer1; 
-#if NH_3D
+#if NH_3D                 
   Int                     m_viewIndex; 
   Bool                    m_isDepth;
-  CamParsCollector*       m_pcCamParsCollector;
-  Int                     m_profileIdc;
-#endif
+#endif
+
+  // Layer set
+  Int                     m_targetOlsIdx; 
+  Int                     m_smallestLayerId; 
+  Bool                    m_isInOwnTargetDecLayerIdList;   
+
+  // Decoding processes 
+  DecodingProcess         m_decodingProcess;
+  DecodingProcess         m_decProcPocAndRps;
+
+  // Decoding state
+  Bool*                   m_firstPicInLayerDecodedFlag;   
+    
+  Int                     m_prevPicOrderCnt; 
+  Int                     m_prevTid0PicPicOrderCntMsb;
+  Int                     m_prevTid0PicSlicePicOrderCntLsb;
+  
+  Int*                    m_lastPresentPocResetIdc;
+  Bool*                   m_pocDecrementedInDpbFlag; 
+
+  Int                     m_prevIrapPoc;
+  Int64                   m_prevIrapDecodingOrder;
+  Int64                   m_prevStsaDecOrder;
+  Int                     m_prevStsaTemporalId;
 #endif
 
@@ -268,87 +288,146 @@
 
   Void  init();
-#if NH_MV  
-  Bool  decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayer, Bool& sliceSkippedFlag );
-  Bool  decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayer );
-#else  
+#if !NH_MV
   Bool  decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay);
-#endif
   Void  deletePicBuffer();
 
-#if NH_MV
-  const TComVPS* getActiveVPS() { return m_parameterSetManager.getActiveVPS( ); }
-  const TComSPS* getActiveSPS() { return m_parameterSetManager.getActiveSPS( m_layerId ); }
-#endif
-
-#if NH_MV
-  Void endPicDecoding(Int& poc, TComList<TComPic*>*& rpcListPic,  std::vector<Int>& targetDecLayerIdSet);  
-#else  
   Void  executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic);
-#endif
   Void  checkNoOutputPriorPics (TComList<TComPic*>* rpcListPic);
 
   Bool  getNoOutputPriorPicsFlag () { return m_isNoOutputPriorPics; }
   Void  setNoOutputPriorPicsFlag (Bool val) { m_isNoOutputPriorPics = val; }
+  
   Void  setFirstSliceInPicture (bool val)  { m_bFirstSliceInPicture = val; }
+
   Bool  getFirstSliceInSequence ()         { return m_bFirstSliceInSequence; }
   Void  setFirstSliceInSequence (bool val) { m_bFirstSliceInSequence = val; }
+#endif
+
 #if O0043_BEST_EFFORT_DECODING
   Void  setForceDecodeBitDepth(UInt bitDepth) { m_forceDecodeBitDepth = bitDepth; }
 #endif
+
   Void  setDecodedSEIMessageOutputStream(std::ostream *pOpStream) { m_pDecodedSEIOutputStream = pOpStream; }
   UInt  getNumberOfChecksumErrorsDetected() const { return m_cGopDecoder.getNumberOfChecksumErrorsDetected(); }
+
 #if NH_MV    
-  TComPic*                getPic                ( Int poc );
-  TComList<TComPic*>*     getListPic            ()               { return &m_cListPic;  }  
-  Void                    setIvPicLists         ( TComPicLists* picLists) { m_ivPicLists = picLists; }
-  Void                    setLayerInitilizedFlags( Bool* val )    { m_layerInitilizedFlag = val; }
-  Void                    setTargetOlsIdx       ( Int targetOlsIdx ) { m_targetOlsIdx = targetOlsIdx; }    
-  Int                     getTargetOlsIdx       ( )                  { return m_targetOlsIdx; }    
-  Int                     getCurrPoc            ()               { return m_apcSlicePilot->getPOC(); }
-  Void                    setLayerId            ( Int layer)     { m_layerId = layer;   }
-  Int                     getLayerId            ()               { return m_layerId;    }
-  Void                    setViewId             ( Int viewId  )  { m_viewId  = viewId;  }
-  Int                     getViewId             ()               { return m_viewId;     }  
-  Void                    initFromActiveVps     ( const TComVPS* vps );
+
+  /////////////////////////
+  // For access from TAppDecTop
+  /////////////////////////
+
+  // Non VCL decoding
+  Bool       decodeNonVclNalu            ( InputNALUnit& nalu );                                    
+                                    
+  // Start picture decoding         
+  Int        preDecodePoc                ( Bool firstPicInLayerDecodedFlag, Bool isFstPicOfAllLayOfPocResetPer, Bool isPocResettingPicture ); 
+  Void       inferPocResetPeriodId       ( );
+  Void       decodeSliceHeader           ( InputNALUnit &nalu );    
+
+  // Picture decoding 
+  Void       activatePSsAndInitPicOrSlice( TComPic* newPic ); 
+  Void       decodePocAndRps             ( );
+  Void       genUnavailableRefPics       ( );                               
+  Void       decodeSliceSegment          ( InputNALUnit &nalu );
+                                    
+  // End Picture decoding           
+  Void       executeLoopFilters          ( );
+  Void       finalizePic( );
+  
+  //////////////////////////
+  // For access from slice 
+  /////////////////////////
+  Void       initFromActiveVps           ( const TComVPS* vps );
+
+  //////////////////////////
+  // General access
+  /////////////////////////
+  
+  // Picture identification 
+  Void       setLayerId            ( Int layer )       { m_layerId = layer;   }
+  Int        getLayerId            ( )                 { return m_layerId;    }
+  Void       setViewId             ( Int viewId )      { m_viewId  = viewId;  }
+  Int        getViewId             ( )                 { return m_viewId;     }  
 #if NH_3D    
-  Void                    setViewIndex          ( Int viewIndex  )  { m_viewIndex  = viewIndex;  }
-  Int                     getViewIndex          ()               { return m_viewIndex;     }  
-  Void                    setIsDepth            ( Bool isDepth ) { m_isDepth = isDepth; }
-  Bool                    getIsDepth            ()               { return m_isDepth;    }
-  Void                    setCamParsCollector( CamParsCollector* pcCamParsCollector ) { m_pcCamParsCollector = pcCamParsCollector; }
-
-
-  Bool                    decProcAnnexI()           { assert( m_profileIdc != -1 ); return ( m_profileIdc == 8); }    
-#endif
+  Void       setViewIndex          ( Int viewIndex )   { m_viewIndex  = viewIndex;  }
+  Int        getViewIndex          ( )                 { return m_viewIndex;     }  
+  Void       setIsDepth            ( Bool isDepth )    { m_isDepth = isDepth; }
+  Bool       getIsDepth            ( )                 { return m_isDepth;    }
+#endif
+
+  // Classes
+  Void       setDpb                ( TComPicLists* picLists) { m_dpb = picLists; }
+#if NH_3D                                       
+  Void       setCamParsCollector   ( CamParsCollector* pcCamParsCollector ) { m_pcCamParsCollector = pcCamParsCollector; }
+#endif
+
+  // Slice pilot access
+  TComSlice* getSlicePilot                ( )               { return m_apcSlicePilot; }
+                                                                         
+  // Decoding state                                                      
+  Bool      getFirstSliceSegementInPicFlag( );              
+  Void      setFirstPicInLayerDecodedFlag(Bool* val )      { m_firstPicInLayerDecodedFlag = val;  }
+  Void      setPocDecrementedInDPBFlag   (Bool* val )      { m_pocDecrementedInDpbFlag = val;  }  
+  Void      setLastPresentPocResetIdc    (Int*  val )      { m_lastPresentPocResetIdc  = val;  }
+                                                           
+  // Layer sets                                                          
+  Void      setTargetOlsIdx        ( Int targetOlsIdx )    { m_targetOlsIdx = targetOlsIdx; }    
+  Int       getTargetOlsIdx        ( )                     { return m_targetOlsIdx; }    
+  Int       getSmallestLayerId     ( )                     { return m_smallestLayerId; }    
+  Bool      getIsInOwnTargetDecLayerIdList()               { return m_isInOwnTargetDecLayerIdList; }
+                                                                         
+  // Decoding processes identification                                   
+  Bool      decProcClause8( )                              { return ( m_decodingProcess == CLAUSE_8 ); }
+  Bool      decProcAnnexF ( )                              { return ( decProcAnnexG() || decProcAnnexH() || decProcAnnexI() ); }
+  Bool      decProcAnnexG ( )                              { return ( m_decodingProcess == ANNEX_G || decProcAnnexI() ); }
+  Bool      decProcAnnexH ( )                              { return ( m_decodingProcess == ANNEX_H  ); }
+  Bool      decProcAnnexI ( )                              { return ( m_decodingProcess == ANNEX_I  ); }
+                                                                         
+  DecodingProcess getDecodingProcess ( ) const                   { return m_decodingProcess;                }
+  Void      setDecProcPocAndRps( DecodingProcess decProc ) { m_decProcPocAndRps = decProc; }    
 #endif
 
 protected:
-  Void  xGetNewPicBuffer  (const TComSPS &sps, const TComPPS &pps, TComPic*& rpcPic, const UInt temporalLayer);
-  Void  xCreateLostPicture (Int iLostPOC);
-
+
+#if !NH_MV
+  Void      xGetNewPicBuffer  (const TComSPS &sps, const TComPPS &pps, TComPic*& rpcPic, const UInt temporalLayer);
+  Void      xCreateLostPicture (Int iLostPOC);
   Void      xActivateParameterSets();
-#if NH_MV  
-  TComPic*  xGetPic( Int layerId, Int poc ); 
-  Bool      xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool newLayerFlag, Bool& sliceSkippedFlag );  
-  Void      xResetPocInPicBuffer();
-  Void      xCeckNoClrasOutput();
-
-  Bool      xAllRefLayersInitilized( const TComVPS* vps );
-#else
-  Bool      xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay);
-#endif
+  Bool      xDecodeSlice                   (InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay);
+#endif
+
   Void      xDecodeVPS(const std::vector<UChar> &naluData);
   Void      xDecodeSPS(const std::vector<UChar> &naluData);
-  Void      xDecodePPS(const std::vector<UChar> &naluData);
+  Void      xDecodePPS(const std::vector<UChar> &naluData);  
+#if !NH_MV
   Void      xUpdatePreviousTid0POC( TComSlice *pSlice ) { if ((pSlice->getTLayer()==0) && (pSlice->isReferenceNalu() && (pSlice->getNalUnitType()!=NAL_UNIT_CODED_SLICE_RASL_R)&& (pSlice->getNalUnitType()!=NAL_UNIT_CODED_SLICE_RADL_R))) { m_prevTid0POC=pSlice->getPOC(); } }
+#endif
 
   Void      xParsePrefixSEImessages();
   Void      xParsePrefixSEIsForUnknownVCLNal();
 
+#if NH_MV
+  // POC 
+  Void      x831DecProcForPicOrderCount         ( );
+  Void      xF831DecProcForPicOrderCount        ( );
+  Int       xGetCurrMsb                         ( Int cl, Int pl, Int pm, Int ml ); 
+
+  //RPS                                         
+  Void      x832DecProcForRefPicSet             ( Bool annexFModifications ); 
+  Void      xF832DecProcForRefPicSet            ( );
+  Void      xG813DecProcForInterLayerRefPicSet  ( );
+
+  // Unavailable Pics 
+  Void      x8331GenDecProcForGenUnavilRefPics  ( );
+  TComPic*  x8332GenOfOneUnavailPic             ( Bool calledFromCl8331 );
+  Void      xF817DecProcForGenUnavRefPicForPicsFrstInDecOrderInLay();
+  Void      xF833DecProcForGenUnavRefPics       ( );  
+  Void      xCheckUnavailableRefPics            ( ); 
+#endif
+
 };// END CLASS DEFINITION TDecTop
 
 
 //! \}
-
 #endif // __TDECTOP__
 
Index: trunk/source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp	(revision 1314)
+++ trunk/source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp	(revision 1321)
@@ -156,5 +156,7 @@
 #if FAST_BIT_EST
   m_fracBits = pcTEncBinCABAC->m_fracBits;
+#if NH_MV
   D_PRINT_INDENT(g_traceEncFracBits,  "CopyState " + n2s(m_fracBits) );    
+#endif
 #endif
 }
@@ -171,7 +173,11 @@
   }
 #if FAST_BIT_EST
+#if NH_MV
   D_PRINT_INDENT( g_traceEncFracBits, "Reset Bits Before" + n2s(m_fracBits) );
+#endif
   m_fracBits &= 32767;
+#if NH_MV
   D_PRINT_INDENT( g_traceEncFracBits, "Reset Bits " + n2s(m_fracBits) );  
+#endif
 #endif
 }
Index: trunk/source/Lib/TLibEncoder/TEncBinCoderCABACCounter.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncBinCoderCABACCounter.cpp	(revision 1314)
+++ trunk/source/Lib/TLibEncoder/TEncBinCoderCABACCounter.cpp	(revision 1321)
@@ -59,5 +59,7 @@
   m_pcTComBitIf->write(0, UInt(m_fracBits >> 15) );
   m_fracBits &= 32767;
+#if NH_MV
   D_PRINT_INDENT( g_traceEncFracBits, "Finish " + n2s(m_fracBits) );    
+#endif
 }
 
@@ -81,5 +83,7 @@
   m_uiBinsCoded += m_binCountIncrement;
   m_fracBits += rcCtxModel.getEntropyBits( binValue );
+#if NH_MV
   D_PRINT_INDENT( g_traceEncFracBits, "EncodeBin " + n2s(m_fracBits) );    
+#endif
 
   rcCtxModel.update( binValue );
@@ -113,5 +117,7 @@
   m_uiBinsCoded += m_binCountIncrement;
   m_fracBits += 32768;
-    D_PRINT_INDENT( g_traceEncFracBits , "EncodeBinEP " + n2s(m_fracBits) );    
+#if NH_MV
+  D_PRINT_INDENT( g_traceEncFracBits , "EncodeBinEP " + n2s(m_fracBits) );
+#endif
 }
 
@@ -126,5 +132,7 @@
   m_uiBinsCoded += numBins & -m_binCountIncrement;
   m_fracBits += 32768 * numBins;
+#if NH_MV
   D_PRINT_INDENT( g_traceEncFracBits , "EncodeBinsEP " + n2s(m_fracBits) );    
+#endif
 }
 
@@ -138,5 +146,7 @@
   m_uiBinsCoded += m_binCountIncrement;
   m_fracBits += ContextModel::getEntropyBitsTrm( binValue );
+#if NH_MV
   D_PRINT_INDENT( g_traceEncFracBits , "EncodeBinTrm " + n2s(m_fracBits) );    
+#endif
 }
 
@@ -144,5 +154,7 @@
 {
   m_fracBits = (m_fracBits + 32767) & (~32767);
+#if NH_MV
   D_PRINT_INDENT( g_traceEncFracBits, "Align " + n2s(m_fracBits) );    
+#endif
 }
 
Index: trunk/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 1314)
+++ trunk/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 1321)
@@ -40,5 +40,5 @@
 #include "SEIwrite.h"
 
-#if NH_3D
+#if NH_MV
 #include "TEncTop.h"
 #endif
@@ -53,4 +53,5 @@
 {
   fprintf( g_hTrace, "=========== Video Parameter Set     ===========\n" );
+}
 
 Void  xTraceSPSHeader ()
@@ -380,9 +381,5 @@
     WRITE_CODE((pcPPS->getDLT()->getDepthViewBitDepth() - 8), 4, "pps_bit_depth_for_depth_layers_minus8");
     
-#if NH_3D_DLT_FIX
     for( Int i = 0; i <= pcPPS->getDLT()->getNumDepthViews()-1; i++ )
-#else
-    for( Int i = 0; i <= pcPPS->getDLT()->getNumDepthViews(); i++ )
-#endif
     {
       Int layerId = pcPPS->getDLT()->getDepthIdxToLayerId(i);
@@ -748,5 +745,9 @@
     WRITE_UVLC( pcSPS->getMaxDecPicBuffering(i) - 1,       "sps_max_dec_pic_buffering_minus1[i]" );
     WRITE_UVLC( pcSPS->getNumReorderPics(i),               "sps_max_num_reorder_pics[i]" );
+#if NH_MV
+    WRITE_UVLC( pcSPS->getSpsMaxLatencyIncreasePlus1(i),   "sps_max_latency_increase_plus1[i]" );
+#else
     WRITE_UVLC( pcSPS->getMaxLatencyIncrease(i),           "sps_max_latency_increase_plus1[i]" );
+#endif
     if (!subLayerOrderingInfoPresentFlag)
     {
@@ -814,6 +815,11 @@
     codeShortTermRefPicSet( rps,false, i);
   }
+#if NH_MV
+  WRITE_FLAG( pcSPS->getLongTermRefPicsPresentFlag() ? 1 : 0,         "long_term_ref_pics_present_flag" );
+  if (pcSPS->getLongTermRefPicsPresentFlag())
+#else
   WRITE_FLAG( pcSPS->getLongTermRefsPresent() ? 1 : 0,         "long_term_ref_pics_present_flag" );
   if (pcSPS->getLongTermRefsPresent())
+#endif
   {
     WRITE_UVLC(pcSPS->getNumLongTermRefPicSPS(), "num_long_term_ref_pics_sps" );
@@ -1747,6 +1753,11 @@
   //write slice address
   const Int sliceSegmentRsAddress = pcSlice->getPic()->getPicSym()->getCtuTsToRsAddrMap(ctuTsAddress);
-
+#if NH_MV
+  // This should actually be done somewhere else and not in writing process.
+  pcSlice->setFirstSliceSegementInPicFlag( sliceSegmentRsAddress==0 ); 
+  WRITE_FLAG( pcSlice->getFirstSliceSegementInPicFlag() , "first_slice_segment_in_pic_flag" );
+#else
   WRITE_FLAG( sliceSegmentRsAddress==0, "first_slice_segment_in_pic_flag" );
+#endif
   if ( pcSlice->getRapPicFlag() )
   {
@@ -1760,5 +1771,4 @@
   else
 #endif
-
   WRITE_UVLC( pcSlice->getPPS()->getPPSId(), "slice_pic_parameter_set_id" );
   if ( pcSlice->getPPS()->getDependentSliceSegmentsEnabledFlag() && (sliceSegmentRsAddress!=0) )
@@ -1772,5 +1782,4 @@
   if ( !pcSlice->getDependentSliceSegmentFlag() )
   {
-
 #if NH_MV    
     Int esb = 0;  //Don't use i, otherwise will shadow something below
@@ -1861,5 +1870,9 @@
         }
       }
+#if NH_MV
+      if(pcSlice->getSPS()->getLongTermRefPicsPresentFlag())
+#else
       if(pcSlice->getSPS()->getLongTermRefsPresent())
+#endif
       {
         Int numLtrpInSH = rps->getNumberOfLongtermPictures();
@@ -2196,5 +2209,5 @@
     Bool isDBFEnabled = (!pcSlice->getDeblockingFilterDisable());
 
-    if(pcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled ))
+      if(pcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() && ( isSAOEnabled || isDBFEnabled ))
     {
       WRITE_FLAG(pcSlice->getLFCrossSliceBoundaryFlag()?1:0, "slice_loop_filter_across_slices_enabled_flag");
@@ -2204,9 +2217,5 @@
     {
       Int voiInVps = vps->getVoiInVps( pcSlice->getViewIndex() ); 
-#if NH_3D_FIX_TICKET_101
       if( vps->getCpInSliceSegmentHeaderFlag( voiInVps ) )
-#else
-      if( vps->getCpInSliceSegmentHeaderFlag( voiInVps ) && !pcSlice->getIsDepth() )
-#endif
       {
         for( Int m = 0; m < vps->getNumCp( voiInVps ); m++ )
@@ -2257,18 +2266,18 @@
       if( pcSlice->getPocMsbValRequiredFlag() )
       {
-        pcSlice->setPocMsbValPresentFlag( true );
+        pcSlice->setPocMsbCycleValPresentFlag( true );
       }
       else
       {
-        pcSlice->setPocMsbValPresentFlag( false );
-      }
-    }
-
-    if( pcSlice->getPocMsbValPresentFlag() )
+        pcSlice->setPocMsbCycleValPresentFlag( false );
+      }
+    }
+
+    if( pcSlice->getPocMsbCycleValPresentFlag() )
     {
 //      Int iMaxPOClsb = 1<< pcSlice->getSPS()->getBitsForPOC(); currently unused
 
       UInt lengthVal = 1;
-      UInt tempVal = pcSlice->getPocMsbVal() + 1;
+      UInt tempVal = pcSlice->getPocMsbCycleVal() + 1;
       assert ( tempVal );
       while( 1 != tempVal )
@@ -2314,14 +2323,14 @@
     if( !pcSlice->getPocMsbValRequiredFlag() &&  pcSlice->getVPS()->getVpsPocLsbAlignedFlag()  )
     {
-      WRITE_FLAG( pcSlice->getPocMsbValPresentFlag( ) ? 1 : 0 , "poc_msb_val_present_flag" );
+      WRITE_FLAG( pcSlice->getPocMsbCycleValPresentFlag( ) ? 1 : 0 , "poc_msb_cycle_val_present_flag" );
     }
     else
     {
-      assert( pcSlice->getPocMsbValPresentFlag() ==  pcSlice->inferPocMsbValPresentFlag( ) ); 
+      assert( pcSlice->getPocMsbCycleValPresentFlag() ==  pcSlice->inferPocMsbCycleValPresentFlag( ) ); 
     }
     
-    if( pcSlice->getPocMsbValPresentFlag() )
-    {
-      WRITE_UVLC( pcSlice->getPocMsbVal( ), "poc_msb_val" );
+    if( pcSlice->getPocMsbCycleValPresentFlag() )
+    {
+      WRITE_UVLC( pcSlice->getPocMsbCycleVal( ), "poc_msb_cycle_val" );
     }
     
@@ -2347,9 +2356,5 @@
   for (Int i = 0; i < maxNumSubLayersMinus1; i++)
   {
-#if !NH_MV
-#endif
     WRITE_FLAG( pcPTL->getSubLayerProfilePresentFlag(i), "sub_layer_profile_present_flag[i]" );
-#if !NH_MV
-#endif
     WRITE_FLAG( pcPTL->getSubLayerLevelPresentFlag(i),   "sub_layer_level_present_flag[i]" );
   }
Index: trunk/source/Lib/TLibEncoder/TEncCavlc.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCavlc.h	(revision 1314)
+++ trunk/source/Lib/TLibEncoder/TEncCavlc.h	(revision 1321)
@@ -66,5 +66,5 @@
 
 protected:
-#if NH_3D
+#if NH_MV
   TEncTop*      m_encTop; 
 #endif
@@ -179,5 +179,5 @@
   Void codeExplicitRdpcmMode( TComTU &rTu, const ComponentID compID );
 
-#if NH_3D
+#if NH_MV
   TEncTop* getEncTop()               { return m_encTop; };
   Void     setEncTop( TEncTop* et )  {  m_encTop = et; };
Index: trunk/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCu.cpp	(revision 1314)
+++ trunk/source/Lib/TLibEncoder/TEncCu.cpp	(revision 1321)
@@ -764,5 +764,5 @@
     if( rpcBestCU->getSlice()->getDepthIntraSkipFlag() )
     {
-      xCheckRDCostDIS( rpcBestCU, rpcTempCU, SIZE_2Nx2N );
+      xCheckRDCostDIS( rpcBestCU, rpcTempCU, SIZE_2Nx2N DEBUG_STRING_PASS_INTO(sDebug) );
       rpcTempCU->initEstData( uiDepth, iMinQP, isAddLowestQP  );
     }
@@ -795,5 +795,5 @@
             {
 #if  NH_3D_FAST_TEXTURE_ENCODING
-              xCheckRDCostInter( rpcBestCU, rpcTempCU DEBUG_STRING_PASS_INTO(sDebug), SIZE_NxN, bFMD  );
+              xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN DEBUG_STRING_PASS_INTO(sDebug), bFMD  );
 #else
 
@@ -1096,8 +1096,8 @@
 
         if((rpcBestCU->getSlice()->getSliceType() == I_SLICE)                                     ||
-           ((!m_pcEncCfg->getDisableIntraPUsInInterSlices()) && ( // avoid very complex intra if it is unlikely
+           ((!m_pcEncCfg->getDisableIntraPUsInInterSlices()) && (
            (rpcBestCU->getCbf( 0, COMPONENT_Y  ) != 0)                                            ||
           ((rpcBestCU->getCbf( 0, COMPONENT_Cb ) != 0) && (numberValidComponents > COMPONENT_Cb)) ||
-          ((rpcBestCU->getCbf( 0, COMPONENT_Cr ) != 0) && (numberValidComponents > COMPONENT_Cr)) 
+          ((rpcBestCU->getCbf( 0, COMPONENT_Cr ) != 0) && (numberValidComponents > COMPONENT_Cr))   // avoid very complex intra if it is unlikely
  #if NH_3D_ENC_DEPTH
             || rpcBestCU->getSlice()->getIsDepth()
@@ -1785,5 +1785,7 @@
   }
 
+#if NH_MV
   D_PRINT_INC_INDENT( g_traceModeCheck, "xCheckRDCostMerge2Nx2N" );
+#endif
 
 #if NH_3D_MLC
@@ -1970,5 +1972,7 @@
   for( UInt uiNoResidual = 0; uiNoResidual < iteration; ++uiNoResidual )
   {
+#if NH_MV
     D_PRINT_INC_INDENT ( g_traceModeCheck, "uiNoResidual: " + n2s( uiNoResidual) );
+#endif
 
     for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand )
@@ -1983,5 +1987,7 @@
       }
 #endif
+#if NH_MV
       D_PRINT_INC_INDENT ( g_traceModeCheck, "uiMergeCand: "+  n2s(uiMergeCand) );
+#endif
 
       if(!(uiNoResidual==1 && mergeCandBuffer[uiMergeCand]==1))
@@ -2173,5 +2179,5 @@
 
               xCheckDQP( rpcTempCU );
-              xCheckBestMode( rpcBestCU, rpcTempCU, uhDepth );
+              xCheckBestMode( rpcBestCU, rpcTempCU, uhDepth DEBUG_STRING_PASS_INTO(bestStr) DEBUG_STRING_PASS_INTO(tmpStr) );
             }
           }
@@ -2197,5 +2203,7 @@
         }
       }
+#if NH_MV
       D_DEC_INDENT( g_traceModeCheck ); 
+#endif
     }
 
@@ -2229,5 +2237,7 @@
       }
     }
+#if NH_MV
     D_DEC_INDENT( g_traceModeCheck ); 
+#endif
   }
   DEBUG_STRING_APPEND(sDebug, bestStr)
@@ -2239,5 +2249,7 @@
  delete[] puhInterDirSP;
 #endif
+#if NH_MV
  D_DEC_INDENT( g_traceModeCheck );
+#endif
 }
 
@@ -2265,5 +2277,7 @@
   }
 
+#if NH_MV
   D_PRINT_INC_INDENT(g_traceModeCheck,   "xCheckRDCostInter; ePartSize:" + n2s( ePartSize) );
+#endif
 
 
@@ -2354,14 +2368,16 @@
   {
 #if NH_3D_ARP
-    if( nARPWMax )
-    {
-      continue;
-    }
-    else
-#endif
-    {
-      D_DEC_INDENT( g_traceModeCheck ); 
-      return;
-    }
+        if( nARPWMax )
+        {
+          continue;
+        }
+        else
+#endif
+    {
+#if NH_MV
+        D_DEC_INDENT( g_traceModeCheck ); 
+#endif
+    return;
+  }
   }
 #endif
@@ -2468,5 +2484,5 @@
 
           xCheckDQP( rpcTempCU );
-          xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth);
+          xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTest));
         }
 
@@ -2479,5 +2495,7 @@
   }
 #endif
+#if NH_MV
   D_DEC_INDENT( g_traceModeCheck ); 
+#endif
 }
 
@@ -2683,6 +2701,7 @@
 #endif
 #if NH_3D_DIS
-Void TEncCu::xCheckRDCostDIS( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize eSize )
+Void TEncCu::xCheckRDCostDIS( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize eSize DEBUG_STRING_FN_DECLARE(sDebug) )
 {
+  DEBUG_STRING_NEW(sTest)
   UInt uiDepth = rpcTempCU->getDepth( 0 );
   if( !rpcBestCU->getSlice()->getIsDepth() || (eSize != SIZE_2Nx2N))
@@ -2691,5 +2710,7 @@
   }
 
+#if NH_MV
   D_PRINT_INC_INDENT(g_traceModeCheck, "xCheckRDCostDIS" );
+#endif
 
 #if NH_3D_VSO // M5
@@ -2753,5 +2774,7 @@
   xCheckDQP( rpcTempCU );
   xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth  DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTest) );
+#if NH_MV
   D_DEC_INDENT( g_traceModeCheck );  
+#endif
 }
 #endif
@@ -2777,6 +2800,8 @@
     }
   }
+#if NH_MV
   D_PRINT_INC_INDENT (g_traceModeCheck, "xCheckRDCostIntra; eSize: " + n2s(eSize) );
-  
+#endif
+
   UInt uiDepth = rpcTempCU->getDepth( 0 );
 #if NH_3D_VSO // M5
@@ -2830,29 +2855,24 @@
     m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0,          true );
   }
-#if NH_3D_DIS && !NH_3D_DIS_FIX
+  m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0,          true );
+#if NH_3D_DIS
   m_pcEntropyCoder->encodeDIS( rpcTempCU, 0,          true );
   if(!rpcTempCU->getDISFlag(0))
   {
 #endif
-  m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0,          true );
-#if NH_3D_DIS_FIX
-  m_pcEntropyCoder->encodeDIS( rpcTempCU, 0,          true );
-  if(!rpcTempCU->getDISFlag(0))
-  {
-#endif
-  m_pcEntropyCoder->encodePredMode( rpcTempCU, 0,          true );
-  m_pcEntropyCoder->encodePartSize( rpcTempCU, 0, uiDepth, true );
-  m_pcEntropyCoder->encodePredInfo( rpcTempCU, 0 );
-  m_pcEntropyCoder->encodeIPCMInfo(rpcTempCU, 0, true );
+    m_pcEntropyCoder->encodePredMode( rpcTempCU, 0,          true );
+    m_pcEntropyCoder->encodePartSize( rpcTempCU, 0, uiDepth, true );
+    m_pcEntropyCoder->encodePredInfo( rpcTempCU, 0 );
+    m_pcEntropyCoder->encodeIPCMInfo(rpcTempCU, 0, true );
 #if NH_3D_SDC_INTRA
     m_pcEntropyCoder->encodeSDCFlag( rpcTempCU, 0, true );
 #endif
 
-  // Encode Coefficients
-  Bool bCodeDQP = getdQPFlag();
-  Bool codeChromaQpAdjFlag = getCodeChromaQpAdjFlag();
-  m_pcEntropyCoder->encodeCoeff( rpcTempCU, 0, uiDepth, bCodeDQP, codeChromaQpAdjFlag );
-  setCodeChromaQpAdjFlag( codeChromaQpAdjFlag );
-  setdQPFlag( bCodeDQP );
+    // Encode Coefficients
+    Bool bCodeDQP = getdQPFlag();
+    Bool codeChromaQpAdjFlag = getCodeChromaQpAdjFlag();
+    m_pcEntropyCoder->encodeCoeff( rpcTempCU, 0, uiDepth, bCodeDQP, codeChromaQpAdjFlag );
+    setCodeChromaQpAdjFlag( codeChromaQpAdjFlag );
+    setdQPFlag( bCodeDQP );
 #if NH_3D_DIS
   }
@@ -2877,6 +2897,8 @@
   xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTest));
 
+#if NH_MV
   D_DEC_INDENT( g_traceModeCheck ); 
-  }
+#endif
+}
 
 
@@ -2912,5 +2934,4 @@
   }
 #endif
-
   rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth );
 #if NH_3D_DIS
Index: trunk/source/Lib/TLibEncoder/TEncCu.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncCu.h	(revision 1314)
+++ trunk/source/Lib/TLibEncoder/TEncCu.h	(revision 1321)
@@ -163,5 +163,5 @@
 #endif
 #if NH_3D_DIS
-  Void  xCheckRDCostDIS   ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize  );
+  Void  xCheckRDCostDIS   ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize DEBUG_STRING_FN_DECLARE(sDebug) );
 #endif
   Void  xCheckRDCostIntra   ( TComDataCU *&rpcBestCU,
Index: trunk/source/Lib/TLibEncoder/TEncEntropy.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 1314)
+++ trunk/source/Lib/TLibEncoder/TEncEntropy.cpp	(revision 1321)
@@ -119,9 +119,5 @@
 Void TEncEntropy::encodeDIS( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
 {
-#if NH_3D_FIX_TICKET_98  
   if( !pcCU->getSlice()->getDepthIntraSkipFlag() )
-#else
-  if ( !pcCU->getSlice()->getIsDepth() )
-#endif
   {
     return;
Index: trunk/source/Lib/TLibEncoder/TEncEntropy.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncEntropy.h	(revision 1314)
+++ trunk/source/Lib/TLibEncoder/TEncEntropy.h	(revision 1321)
@@ -140,5 +140,7 @@
   Void    resetBits                 ()                        { m_pcEntropyCoderIf->resetBits();      }
   UInt    getNumberOfWrittenBits    ()                        {
+#if NH_MV
       D_PRINT_INDENT(g_encNumberOfWrittenBits,  "NumBits: " +  n2s( m_pcEntropyCoderIf->getNumberOfWrittenBits() ))
+#endif
  return m_pcEntropyCoderIf->getNumberOfWrittenBits(); }
   Void    resetEntropy              (const TComSlice *pSlice) { m_pcEntropyCoderIf->resetEntropy(pSlice);  }
Index: trunk/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 1314)
+++ trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 1321)
@@ -1428,9 +1428,9 @@
           if ( gopNum == MAX_GOP)
           {
-            printf( "\nError: FrameI_l%d cannot enable inter-component prediction.\n", pcSlice->getVPS()->getLayerIdInVps( getLayerId() ) );
+            printf( "\nError: FrameI_l%d cannot enable inter-component prediction on slice level. All reference layers need to be available and at least one tool using inter-component prediction must be enabled in the SPS. \n", pcSlice->getVPS()->getLayerIdInVps( getLayerId() ) );
           }
           else
           {
-            printf( "\nError: Frame%d_l%d cannot enable inter-component prediction.\n", gopNum, pcSlice->getVPS()->getLayerIdInVps( getLayerId() ) );
+            printf( "\nError: Frame%d_l%d cannot enable inter-component prediction on slice level. All reference layers need to be available and at least one tool using inter-component prediction must be enabled in the SPS. \n", gopNum, pcSlice->getVPS()->getLayerIdInVps( getLayerId() ) );
           }
           
@@ -1441,5 +1441,4 @@
       pcSlice->checkInCompPredRefLayers(); 
     }   
-
 #if NH_3D_IV_MERGE
     // This needs to be done after initialization of 3D tool parameters.
Index: trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp	(revision 1314)
+++ trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp	(revision 1321)
@@ -826,6 +826,7 @@
       }
 
+#if NH_MV
       D_PRINT_INDENT( g_traceSAOCost, "SAO mode " + n2s( mode ) + " Cost:  " + n2s( modeCost) );
-
+#endif
       if(modeCost < minCost)
       {
Index: trunk/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 1314)
+++ trunk/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 1321)
@@ -1530,5 +1530,7 @@
                                   )
 {
+#if NH_MV
   D_PRINT_INC_INDENT( g_traceModeCheck, "xRecurIntraCodingLumaQT; zeroResiFlag " + n2s(zeroResiFlag) )
+#endif
 
   TComDataCU   *pcCU          = rTu.getCU();
@@ -1713,9 +1715,5 @@
       dSingleCost   = 0.0;
 #if NH_3D_ENC_DEPTH
-#if NH_3D_ENC_DEPTH_FIX
       xIntraCodingTUBlock( pcOrgYuv, pcPredYuv, pcResiYuv, resiLumaSingle, false, uiSingleDistLuma, COMPONENT_Y, rTu DEBUG_STRING_PASS_INTO(sDebug), 0, zeroResiFlag );
-#else
-      xIntraCodingTUBlock( pcOrgYuv, pcPredYuv, pcResiYuv, resiLumaSingle, false, uiSingleDistLuma, COMPONENT_Y, rTu DEBUG_STRING_PASS_INTO(sDebug), zeroResiFlag );
-#endif
 #else
       pcCU ->setTransformSkipSubParts ( 0, COMPONENT_Y, uiAbsPartIdx, totalAdjustedDepthChan );
@@ -1841,5 +1839,7 @@
         }
       }
+#if NH_MV
       D_DEC_INDENT( g_traceModeCheck ); 
+#endif
       return;
     }
@@ -1888,5 +1888,7 @@
   ruiDistY += uiSingleDistLuma;
   dRDCost  += dSingleCost;
+#if NH_MV
   D_DEC_INDENT( g_traceModeCheck ); 
+#endif
 }
 
@@ -1907,5 +1909,5 @@
   TComTURecurse rTu(pcCU, 0);
   const ChromaFormat chFmt     = rTu.GetChromaFormat();
-
+  DEBUG_STRING_NEW(sTemp)
   if ( uiPredMode == 0 )
   {
@@ -2031,5 +2033,5 @@
     TComTURecurse tuRecurseCU(pcCU, 0);
     TComTURecurse tuRecurseWithPU(tuRecurseCU, false, TComTU::DONT_SPLIT);
-
+    DEBUG_STRING_NEW(sTemp)
     initIntraPatternChType( tuRecurseWithPU, COMPONENT_Y, false DEBUG_STRING_PASS_INTO(sTemp) );
 
@@ -2086,5 +2088,5 @@
       
       //===== init pattern for luma prediction =====
-      
+      DEBUG_STRING_NEW(sTemp2)
       initIntraPatternChType( tuRecurseWithPU, COMPONENT_Y, bUseFilter DEBUG_STRING_PASS_INTO(sTemp2) );
       
@@ -2212,5 +2214,4 @@
 
   //===== determine distortion =====  
-#if NH_3D_INTRA_SDC_RD_FIX
 #if NH_3D_VSO  
   if( m_pcRdCost->getUseVSO() )
@@ -2219,20 +2220,4 @@
   }
   else
-#endif
-#else
-#if NH_3D_VSO  
-  if( m_pcRdCost->getUseVSO() )
-  {
-    if( m_pcRdCost->getUseEstimatedVSD() )
-    {
-      ruiDist = m_pcRdCost->getDistPartVSD( pcCU, uiAbsPartIdx, bitDepthY, piPred, uiStride, piOrg, uiStride, uiWidth, uiHeight, false );
-    }
-    else
-    {
-      ruiDist = m_pcRdCost->getDistPartVSO( pcCU, uiAbsPartIdx, bitDepthY, piPred, uiStride, piOrg, uiStride, uiWidth, uiHeight, false );
-    }
-  }
-  else
-#endif
 #endif
   {
@@ -2754,5 +2739,7 @@
                                   Bool        bLumaOnly )
 {
+#if NH_MV
   D_PRINT_INC_INDENT(g_traceModeCheck, "estIntraPredDis");
+#endif
 
   UInt    uiDepth        = pcCU->getDepth(0);
@@ -2772,5 +2759,7 @@
   for( UInt uiPredMode = 0; uiPredMode < 4 ; uiPredMode++ )
   {
+#if NH_MV
     D_PRINT_INC_INDENT(g_traceModeCheck, "uiPredMode" +  n2s(uiPredMode ) );
+#endif
 
     // set context models
@@ -2796,5 +2785,7 @@
       pcPredYuv->copyPartToPartYuv(pcRecoYuv, 0, uiWidth, uiHeight);
     }
+#if NH_MV
       D_DEC_INDENT( g_traceModeCheck );  
+#endif
   } 
 
@@ -2807,5 +2798,7 @@
   //===== set distortion (rate and r-d costs are determined later) =====
   pcCU->getTotalDistortion() = uiBestDist;
+#if NH_MV
   D_DEC_INDENT( g_traceModeCheck ); 
+#endif
 }
 #endif
@@ -2826,5 +2819,7 @@
                               )
 {
+#if NH_MV
   D_PRINT_INC_INDENT( g_traceModeCheck,  "estIntraPredLumaQT");
+#endif
 
   const UInt         uiDepth               = pcCU->getDepth(0);
@@ -2882,5 +2877,7 @@
   {
     const UInt uiPartOffset=tuRecurseWithPU.GetAbsPartIdxTU();
+#if NH_MV
     D_PRINT_INC_INDENT(g_traceModeCheck, "uiPartOffset: " + n2s(uiPartOffset ) );
+#endif
 
 //  for( UInt uiPU = 0, uiPartOffset=0; uiPU < uiNumPU; uiPU++, uiPartOffset += uiQNumParts )
@@ -2927,5 +2924,5 @@
       m_pcRdCost->setDistParam(distParam, sps.getBitDepth(CHANNEL_TYPE_LUMA), piOrg, uiStride, piPred, uiStride, puRect.width, puRect.height, bUseHadamard);
 
-#if NH_3D_IC_FIX
+#if NH_3D
       distParam.bUseIC = false;
 #endif
@@ -2940,5 +2937,7 @@
         Distortion uiSad  = 0;
 #endif
+#if NH_MV
         D_PRINT_INC_INDENT(g_traceModeCheck, "preTest; uiMode " + n2s(uiMode) );
+#endif
 
         const Bool bUseFilter=TComPrediction::filteringIntraReferenceSamples(COMPONENT_Y, uiMode, puRect.width, puRect.height, chFmt, sps.getSpsRangeExtension().getIntraSmoothingDisabledFlag());
@@ -2993,5 +2992,7 @@
 
         CandNum += xUpdateCandList( uiMode, cost, numModesForFullRD, uiRdModeList, CandCostList );
+#if NH_MV
         D_DEC_INDENT( g_traceModeCheck ); 
+#endif
       }
 
@@ -3193,5 +3194,7 @@
 #endif
 
+#if NH_MV
       D_PRINT_INC_INDENT(g_traceModeCheck, "Test; uiOrgMode: " + n2s(uiOrgMode) );
+#endif
 
       pcCU->setIntraDirSubParts ( CHANNEL_TYPE_LUMA, uiOrgMode, uiPartOffset, uiDepth + uiInitTrDepth );
@@ -3395,5 +3398,7 @@
       } // SDC loop
 #endif
+#if NH_MV
       D_DEC_INDENT( g_traceModeCheck ); 
+#endif
     } // Mode loop
 
@@ -3554,5 +3559,7 @@
     pcCU->setSDCFlagSubParts          ( bBestUseSDC, uiPartOffset, uiDepth + uiInitTrDepth );
 #endif
+#if NH_MV
     D_DEC_INDENT( g_traceModeCheck ); 
+#endif
   } while (tuRecurseWithPU.nextSection(tuRecurseCU));
 
@@ -3583,5 +3590,7 @@
   //===== set distortion (rate and r-d costs are determined later) =====
   pcCU->getTotalDistortion() = uiOverallDistY;
+#if NH_MV
   D_DEC_INDENT( g_traceModeCheck ); 
+#endif
 }
 
@@ -3892,5 +3901,7 @@
 )
 {
+#if NH_MV
   D_PRINT_INC_INDENT(g_traceModeCheck,  "xMergeEstimation" ); 
+#endif
 
   UInt uiAbsPartIdx = 0;
@@ -4014,5 +4025,7 @@
   for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand )
   {
+#if NH_MV
     D_PRINT_INC_INDENT(g_traceModeCheck,  "uiMergeCand: " + n2s(uiMergeCand) ); 
+#endif
     Distortion uiCostCand = std::numeric_limits<Distortion>::max();
     UInt       uiBitsCand = 0;
@@ -4092,5 +4105,7 @@
     uiCostCand = uiCostCand + m_pcRdCost->getCost( uiBitsCand );
 
+#if NH_MV
     D_PRINT_INDENT( g_traceRDCost, "IP RD Cost: "  + n2s(uiCostCand)); 
+#endif
 
     if ( uiCostCand < ruiCost )
@@ -4102,7 +4117,11 @@
       uiMergeIndex = uiMergeCand;
     }
+#if NH_MV
     D_DEC_INDENT( g_traceModeCheck ); 
-  }
+#endif
+  }
+#if NH_MV
   D_DEC_INDENT( g_traceModeCheck ); 
+#endif
 }
 
@@ -4142,5 +4161,7 @@
 {
 
+#if NH_MV
   D_PRINT_INC_INDENT(g_traceModeCheck,  "predInterSearch");
+#endif
 
   for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
@@ -4210,5 +4231,7 @@
   for ( Int iPartIdx = 0; iPartIdx < iNumPart; iPartIdx++ )
   {
+#if NH_MV
     D_PRINT_INC_INDENT(g_traceModeCheck, "iPartIdx: " + n2s(iPartIdx) );
+#endif
 
     Distortion   uiCost[2] = { std::numeric_limits<Distortion>::max(), std::numeric_limits<Distortion>::max() };
@@ -4258,5 +4281,7 @@
     for ( Int iRefList = 0; iRefList < iNumPredDir; iRefList++ )
     {
+#if NH_MV
       D_PRINT_INC_INDENT(g_traceModeCheck,  "iRefList: " + n2s(iRefList) );
+#endif
 
       RefPicList  eRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
@@ -4264,5 +4289,7 @@
       for ( Int iRefIdxTemp = 0; iRefIdxTemp < pcCU->getSlice()->getNumRefIdx(eRefPicList); iRefIdxTemp++ )
       {
+#if NH_MV
         D_PRINT_INC_INDENT(g_traceModeCheck,  "iRefIdxTemp: " + n2s(iRefIdxTemp) );
+#endif
 
         uiBitsTemp = uiMbBits[iRefList];
@@ -4338,7 +4365,11 @@
           refIdxValidList1 = iRefIdxTemp;
         }
+#if NH_MV
         D_DEC_INDENT( g_traceModeCheck ); 
-      }
+#endif
+      }
+#if NH_MV
       D_DEC_INDENT( g_traceModeCheck ); 
+#endif
     }
 
@@ -4609,5 +4640,7 @@
         xGetInterPredictionError( pcCU, pcOrgYuv, iPartIdx, uiMEError, m_pcEncCfg->getUseHADME() );
         uiMECost = uiMEError + m_pcRdCost->getCost( uiMEBits );
+#if NH_MV
         D_PRINT_INDENT( g_traceRDCost, "IP RD Cost: "  + n2s(uiMECost)); 
+#endif
       }
 #else
@@ -4756,10 +4789,14 @@
     //  MC
     motionCompensation ( pcCU, pcPredYuv, REF_PIC_LIST_X, iPartIdx );
+#if NH_MV
     D_DEC_INDENT( g_traceModeCheck ); 
+#endif
   } //  end of for ( Int iPartIdx = 0; iPartIdx < iNumPart; iPartIdx++ )
 
   setWpScalingDistParam( pcCU, -1, REF_PIC_LIST_X );
 
+#if NH_MV
   D_DEC_INDENT( g_traceModeCheck ); 
+#endif
   return;
 }
@@ -4769,5 +4806,7 @@
 Void TEncSearch::xEstimateMvPredAMVP( TComDataCU* pcCU, TComYuv* pcOrgYuv, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMvPred, Bool bFilled, Distortion* puiDistBiP )
 {
+#if NH_MV
   D_PRINT_INC_INDENT(g_traceModeCheck, "xEstimateMvPredAMVP");
+#endif
 
   AMVPInfo*  pcAMVPInfo = pcCU->getCUMvField(eRefPicList)->getAMVPInfo();
@@ -4847,9 +4886,13 @@
     if(pcCU->getSlice()->getMvdL1ZeroFlag() && eRefPicList==REF_PIC_LIST_1)
     {
+#if NH_MV
       D_PRINT_INC_INDENT(g_traceModeCheck, "Init");
+#endif
 
       (*puiDistBiP) = xGetTemplateCost( pcCU, uiPartAddr, pcOrgYuv, &m_cYuvPredTemp, rcMvPred, 0, AMVP_MAX_NUM_CANDS, eRefPicList, iRefIdx, iRoiWidth, iRoiHeight);
 
+#if NH_MV
       D_DEC_INDENT( g_traceModeCheck ); 
+#endif
     }
     return;
@@ -4867,5 +4910,7 @@
   for ( i = 0 ; i < pcAMVPInfo->iN; i++)
   {
+#if NH_MV
     D_PRINT_INC_INDENT(g_traceModeCheck, "Cand i=" +  n2s(i) + " X: " + n2s( pcAMVPInfo->m_acMvCand[i].getHor() ) + " Y: " + n2s( pcAMVPInfo->m_acMvCand[i].getVer() ));
+#endif
 
     Distortion uiTmpCost;
@@ -4879,5 +4924,7 @@
     }
 
+#if NH_MV
     D_DEC_INDENT( g_traceModeCheck ); 
+#endif
   }
 
@@ -4889,5 +4936,7 @@
   pcCU->setMVPNumSubParts( pcAMVPInfo->iN, eRefPicList, uiPartAddr, uiPartIdx, pcCU->getDepth(uiPartAddr));
 
+#if NH_MV
   D_DEC_INDENT( g_traceModeCheck ); 
+#endif
 
   return;
@@ -5094,5 +5143,7 @@
 Void TEncSearch::xMotionEstimation( TComDataCU* pcCU, TComYuv* pcYuvOrg, Int iPartIdx, RefPicList eRefPicList, TComMv* pcMvPred, Int iRefIdxPred, TComMv& rcMv, UInt& ruiBits, Distortion& ruiCost, Bool bBi  )
 {
+#if NH_MV
   D_PRINT_INC_INDENT(g_traceModeCheck,  "xMotionEstimation");
+#endif
 
   UInt          uiPartAddr;
@@ -5227,6 +5278,8 @@
   ruiCost       = (Distortion)( floor( fWeight * ( (Double)ruiCost - (Double)m_pcRdCost->getCost( uiMvBits ) ) ) + (Double)m_pcRdCost->getCost( ruiBits ) );
   
+#if NH_MV
   D_PRINT_INDENT(g_traceRDCost, "ME Cost:" + n2s(ruiCost)  );
   D_DEC_INDENT  ( g_traceModeCheck ); 
+#endif
 }
 
@@ -5788,5 +5841,7 @@
                                             Bool bSkipResidual DEBUG_STRING_FN_DECLARE(sDebug) )
 {
+#if NH_MV
   D_PRINT_INC_INDENT(g_traceModeCheck, "encodeResAndCalcRdInterCU; Skip residual: " + n2s(bSkipResidual));
+#endif
 
   assert ( !pcCU->isIntra(0) );
@@ -5883,5 +5938,7 @@
     }
 #endif
+#if NH_MV
     D_DEC_INDENT( g_traceModeCheck ); 
+#endif
 
     return;
@@ -6049,5 +6106,7 @@
   }
 #endif
+#if NH_MV
   D_DEC_INDENT( g_traceModeCheck ); 
+#endif
 }
 
@@ -6207,5 +6266,7 @@
                                            DEBUG_STRING_FN_DECLARE(sDebug) )
 {
+#if NH_MV
   D_PRINT_INC_INDENT(g_traceModeCheck, "xEstimateInterResidualQT");
+#endif
 
   TComDataCU *pcCU        = rTu.getCU();
@@ -6260,5 +6321,7 @@
   if( bCheckFull )
   {
+#if NH_MV
     D_PRINT_INC_INDENT(g_traceModeCheck,  "bCheckFull" );
+#endif
 
     Double minCost[MAX_NUM_COMPONENT][2/*0 = top (or whole TU for non-4:2:2) sub-TU, 1 = bottom sub-TU*/];
@@ -6349,5 +6412,7 @@
           for (Int transformSkipModeId = 0; transformSkipModeId < transformSkipModesToTest; transformSkipModeId++)
           {
+#if NH_MV
             D_PRINT_INC_INDENT( g_traceModeCheck && ( transformSkipModeId > 0) , "TransformSkipModeId: " + n2s(transformSkipModeId) );
+#endif
 
             pcCU->setTransformSkipPartRange(transformSkipModeId, compID, subTUAbsPartIdx, partIdxesPerSubTU);
@@ -6358,5 +6423,7 @@
               const Bool bUseCrossCPrediction = crossCPredictionModeId != 0;
 
+#if NH_MV
               D_PRINT_INC_INDENT( g_traceModeCheck, "Zero" );              
+#endif
 
               m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] );
@@ -6511,11 +6578,14 @@
               }
 
+
               DEBUG_STRING_NEW(sSingleStringTest)
-
-              D_DEC_INDENT( g_traceModeCheck ); 
-
+#if NH_MV
+                D_DEC_INDENT( g_traceModeCheck ); 
+#endif
               if( currAbsSum > 0 ) //if non-zero coefficients are present, a residual needs to be derived for further prediction
               {
+#if NH_MV
                 D_PRINT_INC_INDENT(g_traceModeCheck, "NonZero");
+#endif
 
                 if (isFirstMode)
@@ -6611,5 +6681,7 @@
                 currCompCost = nonCoeffCost;
               }
+#if NH_MV
               D_DEC_INDENT( g_traceModeCheck ); 
+#endif
 
               // evaluate
@@ -6689,5 +6761,7 @@
               }
             }
+#if NH_MV
             D_DEC_INDENT( g_traceModeCheck ); 
+#endif
           }
 
@@ -6700,5 +6774,7 @@
     } // component loop
 
+#if NH_MV
     D_PRINT_INC_INDENT(g_traceModeCheck,  "Final");
+#endif
 
     for(UInt ch = 0; ch < numValidComp; ch++)
@@ -6758,6 +6834,8 @@
       dSingleCost = m_pcRdCost->calcRdCost( uiSingleBits, uiSingleDist );
 
+#if NH_MV
       D_DEC_INDENT( g_traceModeCheck ); 
       D_DEC_INDENT( g_traceModeCheck ); 
+#endif
   } // check full
 
@@ -6765,5 +6843,7 @@
   if( bCheckSplit )
   {
+#if NH_MV
     D_PRINT_INC_INDENT(g_traceModeCheck,  "bCheckSplit" );
+#endif
     if( bCheckFull )
     {
@@ -6935,5 +7015,7 @@
       m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_TEST ] );
     }
+#if NH_MV
     D_DEC_INDENT( g_traceModeCheck ); 
+#endif
   }
   else
@@ -6955,6 +7037,9 @@
 #endif
   }
+#if NH_MV
   D_DEC_INDENT( g_traceModeCheck ); 
+#endif
   DEBUG_STRING_APPEND(sDebug, debug_reorder_data_inter_token[MAX_NUM_COMPONENT])
+
 }
 
Index: trunk/source/Lib/TLibEncoder/TEncSearch.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSearch.h	(revision 1314)
+++ trunk/source/Lib/TLibEncoder/TEncSearch.h	(revision 1321)
@@ -351,8 +351,9 @@
 #endif
 
+#if NH_3D_DMM
   // -------------------------------------------------------------------------------------------------------------------
   // Depth intra search
   // -------------------------------------------------------------------------------------------------------------------
-#if NH_3D_DMM
+
   Void xCalcBiSegDCs              ( Pel* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& valDC1, Pel& valDC2, Pel defaultVal, Bool subSamp = false );
   Void xSearchDmmDeltaDCs         ( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piOrig, Pel* piPredic, UInt uiStride, Bool* biSegPattern, Int patternStride, UInt uiWidth, UInt uiHeight, Pel& rDeltaDC1, Pel& rDeltaDC2 );
Index: trunk/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncTop.cpp	(revision 1314)
+++ trunk/source/Lib/TLibEncoder/TEncTop.cpp	(revision 1321)
@@ -83,5 +83,5 @@
   m_aICEnableNum = NULL;
 #endif
-#if NH_3D
+#if NH_MV
   m_cCavlcCoder.setEncTop(this); 
 #endif
@@ -350,7 +350,5 @@
     m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) );
   }
-#if NH_MV
   pcPicCurr->setLayerId( getLayerId()); 
-#endif
 #if NH_3D
   pcPicCurr->setScaleOffset( m_cameraParameters->getCodedScale(), m_cameraParameters->getCodedOffset() );
@@ -361,7 +359,8 @@
 Void TEncTop::deletePicBuffer()
 {
+
+#if !NH_MV
   TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
   Int iSize = Int( m_cListPic.size() );
-
   for ( Int i = 0; i < iSize; i++ )
   {
@@ -372,4 +371,5 @@
     pcPic = NULL;
   }
+#endif
 }
 
@@ -404,5 +404,5 @@
   if( gopId == 0)
   {
-    m_cGOPEncoder.initGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut);  
+    m_cGOPEncoder.initGOP(m_iPOCLast, m_iNumPicRcvd, *(m_ivPicLists->getSubDpb( getLayerId(), false )), rcListPicYuvRecOut, accessUnitsOut);  
 #else
   if (pcPicYuvOrg != NULL)
@@ -434,5 +434,5 @@
 #if NH_MV
   }
-  m_cGOPEncoder.compressPicInGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false, snrCSC, m_printFrameMSE, gopId);
+  m_cGOPEncoder.compressPicInGOP(m_iPOCLast, m_iNumPicRcvd, *(m_ivPicLists->getSubDpb(getLayerId(), false) ), rcListPicYuvRecOut, accessUnitsOut, false, false, snrCSC, m_printFrameMSE, gopId);
 
   if( gopId + 1 == m_cGOPEncoder.getGOPSize() )
@@ -574,11 +574,23 @@
   // At this point, the SPS and PPS can be considered activated - they are copied to the new TComPic.
 
+#if NH_MV
+  TComList<TComPic*>& cListPic = *(m_ivPicLists->getSubDpb(getLayerId(), false) );
+  TComSlice::sortPicList(cListPic);
+#else
   TComSlice::sortPicList(m_cListPic);
-
-
+#endif
+
+
+#if NH_MV
+  if (cListPic.size() >= (UInt)(m_iGOPSize + getMaxDecPicBuffering(MAX_TLAYER-1) + 2) )
+  {
+    TComList<TComPic*>::iterator iterPic  = cListPic.begin();
+    Int iSize = Int( cListPic.size() );
+#else
   if (m_cListPic.size() >= (UInt)(m_iGOPSize + getMaxDecPicBuffering(MAX_TLAYER-1) + 2) )
   {
     TComList<TComPic*>::iterator iterPic  = m_cListPic.begin();
     Int iSize = Int( m_cListPic.size() );
+#endif
     for ( Int i = 0; i < iSize; i++ )
     {
@@ -604,5 +616,9 @@
     }
 
+#if NH_MV
+    cListPic.pushBack( rpcPic );
+#else
     m_cListPic.pushBack( rpcPic );
+#endif
   }
   rpcPic->setReconMark (false);
@@ -1056,9 +1072,5 @@
   m_cPPS.setOutputFlagPresentFlag( false );
 #if NH_MV
-#if NH_MV_FIX_TICKET_100
   m_cPPS.setNumExtraSliceHeaderBits( 2 ); 
-#else
-  m_cPPS.setNumExtraSliceHeaderBits( 3 ); 
-#endif
 #endif
   m_cPPS.setSignHideFlag(getSignHideFlag());
Index: trunk/source/Lib/TLibEncoder/TEncTop.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncTop.h	(revision 1314)
+++ trunk/source/Lib/TLibEncoder/TEncTop.h	(revision 1321)
@@ -76,5 +76,7 @@
   Int                     m_iNumPicRcvd;                  ///< number of received pictures
   UInt                    m_uiNumAllPicCoded;             ///< number of coded pictures
+#if !NH_MV
   TComList<TComPic*>      m_cListPic;                     ///< dynamic list of pictures
+#endif
 
 #if NH_MV
@@ -170,5 +172,9 @@
   // -------------------------------------------------------------------------------------------------------------------
 
+#if NH_MV
+  TComList<TComPic*>*     getListPic            () { return  m_ivPicLists->getSubDpb( getLayerId(), false);             }
+#else
   TComList<TComPic*>*     getListPic            () { return  &m_cListPic;             }
+#endif
   TEncSearch*             getPredSearch         () { return  &m_cSearch;              }
 
