Changeset 1317 in 3DVCSoftware


Ignore:
Timestamp:
4 Sep 2015, 21:28:58 (9 years ago)
Author:
tech
Message:

Clean-ups. HLS.

Location:
branches/HTM-15.0-dev0/source
Files:
47 edited

Legend:

Unmodified
Added
Removed
  • branches/HTM-15.0-dev0/source/App/TAppDecoder/TAppDecCfg.cpp

    r1313 r1317  
    102102  ("RespectDefDispWindow,w",    m_respectDefDispWindow,                0,          "Only output content inside the default display window\n")
    103103#if NH_MV
    104   ("OutputVpsInfo,v",           m_outputVpsInfo,                       false,       "Output information about the layer dependencies and layer sets")
     104  ("OutputVpsInfo,v",           m_printVpsInfo,                       false,       "Output information about the layer dependencies and layer sets")
     105  ("PrintPicOutput,c" ,         m_printPicOutput,                     false,         "Print information on picture output")
     106  ("PrintNalus,n",              m_printReceivedNalus,                 false,        "Print information on received NAL units")
    105107#endif
    106108#if O0043_BEST_EFFORT_DECODING
  • branches/HTM-15.0-dev0/source/App/TAppDecoder/TAppDecCfg.h

    r1313 r1317  
    4545#include "TLibCommon/CommonDef.h"
    4646#include <vector>
     47#if NH_MV
     48#include <fstream>
     49#endif
    4750
    4851//! \ingroup TAppDecoder
     
    5861protected:
    5962  Char*         m_pchBitstreamFile;                     ///< input bitstream file name
    60 #if NH_MV
    61   Int           m_targetOptLayerSetIdx;                 ///< target output layer set index
    62   Int           m_maxLayerId;                           ///< maximum nuh_layer_id decoded
    63   std::vector<Char*> m_pchReconFiles;                   ///< array of output reconstruction file name create from output reconstruction file name
    64 #endif
    6563  Char*         m_pchReconFile;                         ///< output reconstruction file name
    66 #if NH_3D
    67   Char*         m_pchScaleOffsetFile;                   ///< output coded scale and offset parameters
    68   Bool          m_depth420OutputFlag;                   ///< output depth layers in 4:2:0
    69 #endif
    7064  Int           m_iSkipFrame;                           ///< counter for frames prior to the random access point to skip
    7165  Int           m_outputBitDepth[MAX_NUM_CHANNEL_TYPE]; ///< bit depth used for writing output
     
    7670  Bool          m_decodedNoDisplaySEIEnabled;         ///< Enable(true)/disable(false) writing only pictures that get displayed based on the no display SEI message
    7771  std::vector<Int> m_targetDecLayerIdSet;             ///< set of LayerIds to be included in the sub-bitstream extraction process.
    78 #if NH_MV
    79   Bool          m_targetDecLayerIdSetFileEmpty;       ///< indication if target layers are given by file
    80 #endif
    8172
    8273  Int           m_respectDefDispWindow;               ///< Only output content inside the default display window
     
    8778  Bool          m_bClipOutputVideoToRec709Range;      ///< If true, clip the output video to the Rec 709 range on saving.
    8879#if NH_MV
    89   Bool          m_outputVpsInfo;                     ///< Output VPS information
     80  std::vector<Char*> m_pchReconFiles;                   ///< array of output reconstruction file name create from output reconstruction file name
     81
     82  Int           m_targetOptLayerSetIdx;                 ///< target output layer set index
     83  Int           m_targetDecLayerSetIdx;
     84  Int           m_baseLayerOutputFlag;
     85  Int           m_baseLayerPicOutputFlag;
     86  Int           m_auOutputFlag;
     87  Int           m_maxLayerId;                           ///< maximum nuh_layer_id decoded
     88  std::ifstream m_bitstreamFile;
     89  Bool          m_targetDecLayerIdSetFileEmpty;       ///< indication if target layers are given by file
     90  Int           m_highestTid;
     91
     92  Bool          m_printVpsInfo;                      ///< Output VPS information
     93  Bool          m_printPicOutput;                     ///< Print information on picture output
     94  Bool          m_printReceivedNalus;                 ///< Print information on received NAL units
     95#if NH_3D
     96  Char*         m_pchScaleOffsetFile;                   ///< output coded scale and offset parameters
     97  Bool          m_depth420OutputFlag;                   ///< output depth layers in 4:2:0
     98#endif
     99
    90100  Void xAppendToFileNameEnd( Char* pchInputFileName, const Char* pchStringToAppend, Char*& rpchOutputFileName); ///< create filenames
    91101#endif
     
    100110  , m_decodedPictureHashSEIEnabled(0)
    101111  , m_decodedNoDisplaySEIEnabled(false)
    102 #if NH_MV
    103   , m_targetDecLayerIdSetFileEmpty(true)
    104 #endif
    105112  , m_respectDefDispWindow(0)
    106113#if O0043_BEST_EFFORT_DECODING
    107114  , m_forceDecodeBitDepth(0)
    108115#endif
     116#if NH_MV
     117  , m_highestTid(-1)
     118  , m_targetDecLayerIdSetFileEmpty(true)
     119#endif
     120
    109121  {
    110122    for (UInt channelTypeIndex = 0; channelTypeIndex < MAX_NUM_CHANNEL_TYPE; channelTypeIndex++)
  • branches/HTM-15.0-dev0/source/App/TAppDecoder/TAppDecTop.cpp

    r1313 r1317  
    6464{
    6565#if NH_MV
    66   for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++)
    67   {
    68     m_layerIdToDecIdx[i] = -1;
    69     m_layerInitilizedFlags[i] = false;
    70   }
     66  for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++)
     67  {
     68    m_layerIdToDecIdx                     [i] = -1;
     69    m_layerInitilizedFlag                 [i] = false;
     70    m_eosInLayer                          [i] = false;
     71    m_firstPicInLayerDecodedFlag          [i] = false;
     72    m_pocDecrementedInDpbFlag             [i] = false;
     73    m_decodingOrder                       [i] = 0;
     74    m_lastPresentPocResetIdc              [i] = MIN_INT;
     75    m_firstPicInPocResettingPeriodReceived[i] = true;
     76    m_noRaslOutputFlagAssocIrap           [i] = false;
     77  }
     78
     79  m_curPic                          = NULL;
     80  m_vps                             = NULL;
     81  m_sps                             = NULL;
     82  m_pps                             = NULL;
     83  m_initilizedFromVPS               = false;
     84  m_firstSliceInBitstream           = true;
     85  m_newVpsActivatedbyCurAu          = false;
     86  m_newVpsActivatedbyCurPic         = false;
     87  m_handleCraAsBlaFlag              = false;
     88  m_handleCraAsBlaFlagSetByExtMeans = false;
     89  m_noClrasOutputFlag               = false;
     90  m_noClrasOutputFlagSetByExtMeans  = false;
     91  m_layerResetFlag                  = false;
     92  m_totalNumofPicsReceived          = 0;
     93  m_cvsStartFound                   = false;
    7194#endif
    7295#if NH_3D
    73     m_pScaleOffsetFile  = 0;
     96    m_pScaleOffsetFile              = 0;
    7497#endif
    75 
     98}
     99
     100Void TAppDecTop::create()
     101{
    76102#if NH_MV
    77     m_markedForOutput = false;
     103#if ENC_DEC_TRACE
     104  if ( g_hTrace == NULL )
     105  {
     106    g_hTrace = fopen( "TraceDec.txt", "wb" );
     107    g_bJustDoIt = g_bEncDecTraceDisable;
     108    g_nSymbolCounter = 0;
     109  }
    78110#endif
    79 
    80 }
    81 
    82 Void TAppDecTop::create()
    83 {
     111#endif
    84112}
    85113
     
    115143  {
    116144    free (m_pchScaleOffsetFile);
    117     m_pchScaleOffsetFile = NULL; 
     145    m_pchScaleOffsetFile = NULL;
    118146  }
    119147#endif
     
    132160 .
    133161 */
     162
     163#if NH_MV
    134164Void TAppDecTop::decode()
    135165{
     166  // create & initialize internal classes
     167  xInitFileIO  ();
     168  xCreateDecLib();
     169  xInitDecLib  ();
     170
     171  InputByteStream bytestream(m_bitstreamFile);
     172
     173  while ( m_bitstreamFile )
     174  {
     175    AnnexBStats stats = AnnexBStats();
     176    InputNALUnit nalu;
     177
     178    byteStreamNALUnit(bytestream, nalu.getBitstream().getFifo(), stats);
     179
     180    if (nalu.getBitstream().getFifo().empty())
     181    {
     182      /* this can happen if the following occur:
     183       *  - empty input file
     184       *  - two back-to-back start_code_prefixes
     185       *  - start_code_prefix immediately followed by EOF
     186       */
     187      fprintf(stderr, "Warning: Attempt to decode an empty NAL unit\n");
     188    }
     189    else
     190    {
     191      read(nalu);
     192
     193      if ( m_printReceivedNalus )
     194      {
     195        std::cout << "Received NAL unit: ";
     196        nalu.print();
     197        std::cout << std::endl;
     198      }
     199
     200      if ( xExtractAndRewrite( &nalu )
     201          && nalu.m_nuhLayerId <= MAX_NUM_LAYER_IDS-1
     202          && !(nalu.m_nalUnitType == NAL_UNIT_VPS && nalu.m_nuhLayerId > 0)
     203          && !(nalu.m_nalUnitType == NAL_UNIT_EOB && nalu.m_nuhLayerId > 0)
     204         )
     205      {
     206        xGetDecoderIdx( nalu.m_nuhLayerId , true );
     207        if( nalu.isSlice() )
     208        {
     209          xProcessVclNalu   ( nalu );
     210        }
     211        else
     212        {
     213          xProcessNonVclNalu( nalu );
     214        }
     215      }
     216    }
     217  }
     218 xTerminateDecoding();
     219}
     220#endif
     221
     222#if !NH_MV
     223Void TAppDecTop::decode()
     224{
    136225  Int                 poc;
    137 #if NH_MV
    138   poc = -1;
    139 #endif
    140226  TComList<TComPic*>* pcListPic = NULL;
    141227
     
    146232    exit(EXIT_FAILURE);
    147233  }
    148 #if NH_3D
    149   if( m_pchScaleOffsetFile )
    150   {
    151     m_pScaleOffsetFile = ::fopen( m_pchScaleOffsetFile, "wt" );
    152     AOF( m_pScaleOffsetFile );
    153   }
    154 #endif
    155234
    156235  InputByteStream bytestream(bitstreamFile);
     
    169248  xCreateDecLib();
    170249  xInitDecLib  ();
    171 #if !NH_MV
     250
    172251  m_iPOCLastDisplay += m_iSkipFrame;      // set the last displayed POC correctly for skip forward.
    173252
    174253  // main decoder loop
    175254  Bool openedReconFile = false; // reconstruction file not yet opened. (must be performed after SPS is seen)
    176 #else
    177 
    178   Int  pocCurrPic        = -MAX_INT;     
    179   Int  pocLastPic        = -MAX_INT;   
    180 
    181   Int  layerIdLastPic    = -MAX_INT;
    182   Int  layerIdCurrPic    = 0;
    183 
    184   Int  decIdxLastPic     = 0;
    185   Int  decIdxCurrPic     = 0;
    186 
    187   Bool firstSlice        = true;
    188 #endif
    189255  Bool loopFiltered = false;
    190256
     
    201267    streampos location = bitstreamFile.tellg();
    202268#endif
    203 #if NH_MV
    204 #if ENC_DEC_TRACE
    205     Int64 symCount = g_nSymbolCounter;
    206 #endif
    207 #endif
    208269    AnnexBStats stats = AnnexBStats();
    209270
     
    213274    // call actual decoding function
    214275    Bool bNewPicture = false;
    215 #if NH_MV
    216     Bool newSliceDiffPoc   = false;
    217     Bool newSliceDiffLayer = false;
    218     Bool sliceSkippedFlag  = false;
    219     Bool allLayersDecoded  = false;     
    220 #endif
    221276    if (nalu.getBitstream().getFifo().empty())
    222277    {
     
    231286    {
    232287      read(nalu);
    233 #if NH_MV     
    234       if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer)
    235           || !isNaluWithinTargetDecLayerIdSet(&nalu)
    236           || nalu.m_nuhLayerId > MAX_NUM_LAYER_IDS-1
    237           || (nalu.m_nalUnitType == NAL_UNIT_VPS && nalu.m_nuhLayerId > 0)           
    238           || (nalu.m_nalUnitType == NAL_UNIT_EOB && nalu.m_nuhLayerId > 0)             
    239          )
     288
     289      if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu)  )
    240290      {
    241291        bNewPicture = false;
    242         if ( !bitstreamFile )
    243         {
    244           decIdxLastPic     = decIdxCurrPic;
    245         }
    246292      }
    247293      else
    248       {
    249         Int decIdx     = xGetDecoderIdx( nalu.m_nuhLayerId , true );     
    250         newSliceDiffLayer = nalu.isSlice() && ( nalu.m_nuhLayerId != layerIdCurrPic ) && !firstSlice;
    251         newSliceDiffPoc   = m_tDecTop[decIdx]->decode(nalu, m_iSkipFrame, m_pocLastDisplay[decIdx], newSliceDiffLayer, sliceSkippedFlag );
    252         // decode function only returns true when all of the following conditions are true
    253         // - poc in particular layer changes
    254         // - nalu does not belong to first slice in layer
    255         // - nalu.isSlice() == true     
    256 
    257         bNewPicture       = ( newSliceDiffLayer || newSliceDiffPoc ) && !sliceSkippedFlag;
    258         if ( nalu.isSlice() && firstSlice && !sliceSkippedFlag )       
    259         {
    260           layerIdCurrPic = nalu.m_nuhLayerId;
    261           pocCurrPic     = m_tDecTop[decIdx]->getCurrPoc();
    262           decIdxCurrPic  = decIdx;
    263           firstSlice     = false;
    264 
    265           /// Use VPS activated by the first slice to determine OLS
    266           m_vps = m_tDecTop[decIdx]->getActiveVPS( );
    267           if ( m_targetDecLayerIdSetFileEmpty )
    268           {           
    269             if ( m_targetOptLayerSetIdx == -1 )
    270             {
    271               m_targetOptLayerSetIdx = m_tDecTop[decIdx]->getTargetOlsIdx();
    272             }
    273             else
    274             {
    275               assert( m_tDecTop[decIdx]->getTargetOlsIdx() == m_targetOptLayerSetIdx );
    276             }
    277 
    278             if ( m_targetOptLayerSetIdx < 0 || m_targetOptLayerSetIdx >= m_vps->getNumOutputLayerSets() )
    279             {
    280               fprintf(stderr, "\ntarget output layer set index must be in the range of 0 to %d, inclusive \n", m_vps->getNumOutputLayerSets() - 1 );           
    281               exit(EXIT_FAILURE);
    282             }
    283             m_targetDecLayerIdSet = m_vps->getTargetDecLayerIdList( m_targetOptLayerSetIdx );
    284           }
    285 
    286           if (m_outputVpsInfo )
    287           {
    288             m_vps->printScalabilityId();
    289             m_vps->printLayerDependencies();
    290             m_vps->printLayerSets();
    291             m_vps->printPTL();
    292           }
    293         }       
    294 
    295         if ( bNewPicture || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS )
    296         {
    297           layerIdLastPic    = layerIdCurrPic;
    298           layerIdCurrPic    = nalu.m_nuhLayerId;
    299           pocLastPic        = pocCurrPic;
    300           pocCurrPic        = m_tDecTop[decIdx]->getCurrPoc();
    301           decIdxLastPic     = decIdxCurrPic;
    302           decIdxCurrPic     = decIdx;
    303           allLayersDecoded = ( pocCurrPic != pocLastPic ) && ( nalu.m_nalUnitType != NAL_UNIT_EOS );
    304         }
    305 #else
    306       if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu)  )
    307       {
    308         bNewPicture = false;
    309       }
    310       else
    311294      {
    312295        bNewPicture = m_cTDecTop.decode(nalu, m_iSkipFrame, m_iPOCLastDisplay);
    313 #endif
    314296        if (bNewPicture)
    315297        {
     
    327309          bytestream.reset();
    328310#endif
    329 #if H_MV_ENC_DEC_TRAC
    330 #if ENC_DEC_TRACE
    331           const Bool resetCounter = false;
    332           if ( resetCounter )
    333           {
    334             g_nSymbolCounter  = symCount; // Only reset counter SH becomes traced twice
    335           }
    336           else
    337           {
    338             g_disableHLSTrace = true;     // Tracing of second parsing of SH is not carried out
    339           }     
    340 #endif
    341 #endif
    342311        }
    343312      }
     
    345314
    346315    if ( (bNewPicture || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS) &&
    347 #if NH_MV     
    348       !m_tDecTop[decIdxLastPic]->getFirstSliceInSequence () )
    349 #else
     316
    350317      !m_cTDecTop.getFirstSliceInSequence () )
    351 #endif
    352318
    353319    {
    354320      if (!loopFiltered || bitstreamFile)
    355321      {
    356 #if NH_MV
    357         assert( decIdxLastPic != -1 );
    358         m_tDecTop[decIdxLastPic]->endPicDecoding(poc, pcListPic, m_targetDecLayerIdSet );
    359         xMarkForOutput( allLayersDecoded, poc, layerIdLastPic );
    360 #else
    361322        m_cTDecTop.executeLoopFilters(poc, pcListPic);
    362 #endif
    363323      }
    364324      loopFiltered = (nalu.m_nalUnitType == NAL_UNIT_EOS);
    365325      if (nalu.m_nalUnitType == NAL_UNIT_EOS)
    366326      {
    367 #if NH_MV     
    368         m_tDecTop[decIdxLastPic]->setFirstSliceInSequence(true);
    369 #else
    370327        m_cTDecTop.setFirstSliceInSequence(true);
    371 #endif
    372328      }
    373329    }
    374330    else if ( (bNewPicture || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS ) &&
    375 #if NH_MV     
    376               m_tDecTop[decIdxLastPic]->getFirstSliceInSequence () )
    377 #else
    378               m_cTDecTop.getFirstSliceInSequence () )
    379 #endif
    380     {
    381 #if NH_MV     
    382       m_tDecTop[decIdxLastPic]->setFirstSliceInPicture (true);
    383 #else
     331              m_cTDecTop.getFirstSliceInSequence () )
     332    {
    384333      m_cTDecTop.setFirstSliceInPicture (true);
    385 #endif
    386     }
    387 
    388 #if NH_3D
    389     if ( allLayersDecoded || !bitstreamFile )
    390     {
    391       for( Int dI = 0; dI < m_numDecoders; dI++ )
    392       {
    393         TComPic* picLastCoded = m_ivPicLists.getPic( m_tDecTop[dI]->getLayerId(), pocLastPic );
    394         assert( picLastCoded != NULL );       
    395         picLastCoded->compressMotion(1);
    396       }
    397     }
    398 #endif
     334   }
    399335
    400336    if( pcListPic )
    401337    {
    402 #if NH_MV
    403       if ( m_pchReconFiles[decIdxLastPic] && !m_reconOpen[decIdxLastPic] )
    404 #else
    405338      if ( m_pchReconFile && !openedReconFile )
    406 #endif
    407339      {
    408340        const BitDepths &bitDepths=pcListPic->front()->getPicSym()->getSPS().getBitDepths(); // use bit depths of first reconstructed picture.
     
    414346          }
    415347        }
    416 #if NH_MV
    417         m_tVideoIOYuvReconFile[decIdxLastPic]->open( m_pchReconFiles[decIdxLastPic], true, m_outputBitDepth, m_outputBitDepth, bitDepths.recon ); // write mode
    418         m_reconOpen[decIdxLastPic] = true;
     348        m_cTVideoIOYuvReconFile.open( m_pchReconFile, true, m_outputBitDepth, m_outputBitDepth, bitDepths.recon ); // write mode
     349        openedReconFile = true;
    419350      }
    420351      // write reconstruction to file
    421352      if( bNewPicture )
    422353      {
    423         // Bumping after picture has been decoded
    424 #if ENC_DEC_TRACE
    425         g_bJustDoIt = true; 
    426         writeToTraceFile( "Bumping after decoding \n", g_decTracePicOutput  );         
    427         g_bJustDoIt = false; 
    428 #endif
    429         xWriteOutput( pcListPic, decIdxLastPic, nalu.m_temporalId );
    430       }
    431       if ( (bNewPicture || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_CRA) && m_tDecTop[decIdxLastPic]->getNoOutputPriorPicsFlag() )
    432       {
    433         m_tDecTop[decIdxLastPic]->checkNoOutputPriorPics( pcListPic );
    434         m_tDecTop[decIdxLastPic]->setNoOutputPriorPicsFlag (false);
    435       }
    436 
    437       if ( bNewPicture && newSliceDiffPoc &&
    438 #else
    439         m_cTVideoIOYuvReconFile.open( m_pchReconFile, true, m_outputBitDepth, m_outputBitDepth, bitDepths.recon ); // write mode
    440         openedReconFile = true;
    441       }
    442       // write reconstruction to file
    443       if( bNewPicture )
    444       {
    445354        xWriteOutput( pcListPic, nalu.m_temporalId );
    446355      }
     
    452361
    453362      if ( bNewPicture &&
    454 #endif
    455363           (   nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL
    456364            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP
     
    459367            || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP ) )
    460368      {
    461 #if NH_MV
    462         xFlushOutput( pcListPic, decIdxLastPic );
    463 #else
     369
    464370        xFlushOutput( pcListPic );
    465 #endif
    466371      }
    467372      if (nalu.m_nalUnitType == NAL_UNIT_EOS)
    468373      {
    469 #if NH_MV
    470         xWriteOutput( pcListPic, decIdxCurrPic, nalu.m_temporalId );
    471 #else
     374
    472375        xWriteOutput( pcListPic, nalu.m_temporalId );
    473 #endif
    474 #if NH_MV
    475         m_tDecTop[decIdxCurrPic]->setFirstSliceInPicture (false);
    476 #else
    477376        m_cTDecTop.setFirstSliceInPicture (false);
    478 #endif
    479377      }
    480378      // write reconstruction to file -- for additional bumping as defined in C.5.2.3
    481 #if NH_MV
    482       // Above comment seems to be wrong
    483 #endif
    484379      if(!bNewPicture && nalu.m_nalUnitType >= NAL_UNIT_CODED_SLICE_TRAIL_N && nalu.m_nalUnitType <= NAL_UNIT_RESERVED_VCL31)
    485380      {
    486 #if NH_MV       
    487         // Bumping after reference picture set has been applied (here after first vcl nalu.
    488 #if ENC_DEC_TRACE
    489         g_bJustDoIt = true; 
    490         writeToTraceFile( "Bumping after reference picture set has been applied \n", g_decTracePicOutput  );         
    491         g_bJustDoIt = false; 
    492 #endif
    493 
    494         xWriteOutput( m_tDecTop[decIdxCurrPic]->getListPic(), decIdxCurrPic, nalu.m_temporalId );
    495 #else
    496381        xWriteOutput( pcListPic, nalu.m_temporalId );
    497 #endif
    498       }
    499     }
    500   }
    501 #if NH_MV
    502 #if NH_3D
    503   if( m_cCamParsCollector.isInitialized() )
    504   {
    505     m_cCamParsCollector.setSlice( 0 );
    506   }
    507 #endif
    508   for(UInt decIdx = 0; decIdx < m_numDecoders; decIdx++)
    509   {
    510     xFlushOutput( m_tDecTop[decIdx]->getListPic(), decIdx );
    511   }
    512 #else 
     382      }
     383    }
     384  }
     385
    513386  xFlushOutput( pcListPic );
    514387  // delete buffers
     
    516389  // destroy internal classes
    517390  xDestroyDecLib();
     391}
    518392#endif
    519 }
    520393
    521394// ====================================================================================================================
     
    527400#if NH_MV
    528401  // initialize global variables
    529   initROM(); 
     402  initROM();
    530403#if NH_3D_DMM
    531404  initWedgeLists();
     
    548421    {
    549422      m_tVideoIOYuvReconFile[decIdx]->close();
    550       delete m_tVideoIOYuvReconFile[decIdx]; 
     423      delete m_tVideoIOYuvReconFile[decIdx];
    551424      m_tVideoIOYuvReconFile[decIdx] = NULL ;
    552425    }
     
    554427    if( m_tDecTop[decIdx] )
    555428    {
     429#if !NH_MV
    556430      m_tDecTop[decIdx]->deletePicBuffer();
     431#endif
    557432      m_tDecTop[decIdx]->destroy() ;
    558433    }
    559     delete m_tDecTop[decIdx] ; 
     434    delete m_tDecTop[decIdx] ;
    560435    m_tDecTop[decIdx] = NULL ;
    561436  }
     
    571446#if NH_3D
    572447  m_cCamParsCollector.uninit();
    573   if( m_pScaleOffsetFile ) 
    574   { 
    575     ::fclose( m_pScaleOffsetFile ); 
     448  if( m_pScaleOffsetFile )
     449  {
     450    ::fclose( m_pScaleOffsetFile );
    576451  }
    577452#endif
     
    584459  m_cCamParsCollector.setCodeScaleOffsetFile( m_pScaleOffsetFile );
    585460#endif
    586 #if !NH_MV
     461#if NH_MV
     462  m_dpb.setPrintPicOutput(m_printPicOutput);
     463#else
    587464  // initialize decoder class
    588465  m_cTDecTop.init();
     
    599476}
    600477
     478
     479#if !NH_MV
    601480/** \param pcListPic list of pictures to be written to file
    602481    \param tId       temporal sub-layer ID
    603482 */
    604 #if NH_MV
    605 Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, Int decIdx, Int tId )
    606 #else
    607483Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, UInt tId )
    608 #endif
    609484{
    610485  if (pcListPic->empty())
     
    625500  {
    626501    numReorderPicsHighestTid = activeSPS->getNumReorderPics(maxNrSublayers-1);
    627     maxDecPicBufferingHighestTid =  activeSPS->getMaxDecPicBuffering(maxNrSublayers-1); 
     502    maxDecPicBufferingHighestTid =  activeSPS->getMaxDecPicBuffering(maxNrSublayers-1);
    628503  }
    629504  else
    630505  {
    631506    numReorderPicsHighestTid = activeSPS->getNumReorderPics(m_iMaxTemporalLayer);
    632     maxDecPicBufferingHighestTid = activeSPS->getMaxDecPicBuffering(m_iMaxTemporalLayer); 
     507    maxDecPicBufferingHighestTid = activeSPS->getMaxDecPicBuffering(m_iMaxTemporalLayer);
    633508  }
    634509
     
    636511  {
    637512    TComPic* pcPic = *(iterPic);
    638 #if NH_MV
    639     if(pcPic->getOutputMark() && pcPic->getPOC() > m_pocLastDisplay[decIdx])
    640 #else
    641513    if(pcPic->getOutputMark() && pcPic->getPOC() > m_iPOCLastDisplay)
    642 #endif
    643514    {
    644515       numPicsNotYetDisplayed++;
     
    671542      TComPic* pcPicBottom = *(iterPic);
    672543
    673 #if NH_MV
    674       if ( pcPicTop->getOutputMark() && pcPicBottom->getOutputMark() &&
    675         (numPicsNotYetDisplayed >  numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid) &&
    676         (!(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1) &&
    677         (pcPicTop->getPOC() == m_pocLastDisplay[decIdx]+1 || m_pocLastDisplay[decIdx] < 0))
    678 #else
    679544      if ( pcPicTop->getOutputMark() && pcPicBottom->getOutputMark() &&
    680545          (numPicsNotYetDisplayed >  numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid) &&
    681546          (!(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1) &&
    682547          (pcPicTop->getPOC() == m_iPOCLastDisplay+1 || m_iPOCLastDisplay < 0))
    683 #endif
    684548      {
    685549        // write to file
    686550        numPicsNotYetDisplayed = numPicsNotYetDisplayed-2;
    687 #if NH_MV
    688       if ( m_pchReconFiles[decIdx] )
    689 #else
    690551        if ( m_pchReconFile )
    691 #endif
    692552        {
    693553          const Window &conf = pcPicTop->getConformanceWindow();
     
    708568          if (display)
    709569          {
    710 #if NH_MV
    711         assert( conf   .getScaledFlag() );
    712         assert( defDisp.getScaledFlag() );
    713 #if ENC_DEC_TRACE
    714         g_bJustDoIt = true; 
    715         writeToTraceFile( "OutputPic Poc"   , pcPic->getPOC    (), g_decTracePicOutput  );
    716         writeToTraceFile( "OutputPic LayerId", pcPic->getLayerId(), g_decTracePicOutput );         
    717         g_bJustDoIt = false; 
    718 #endif
    719         m_tVideoIOYuvReconFile[decIdx]->write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
    720 #else
    721570        m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
    722 #endif
    723571                                           m_outputColourSpaceConvert,
    724572                                           conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
    725573                                           conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
    726574                                           conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
    727 #if NH_3D
    728                                            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), m_depth420OutputFlag && pcPicTop->getIsDepth() ? CHROMA_420 : NUM_CHROMA_FORMAT, isTff );
    729 #else
    730575                                           conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), NUM_CHROMA_FORMAT, isTff );
    731 #endif
    732576          }
    733577        }
    734578
    735579        // update POC of display order
    736 #if NH_MV
    737         m_pocLastDisplay[decIdx] = pcPic->getPOC();
    738 #else
    739580        m_iPOCLastDisplay = pcPicBottom->getPOC();
    740 #endif
    741581
    742582        // erase non-referenced picture in the reference picture list after display
     
    768608      pcPic = *(iterPic);
    769609
    770 #if NH_MV
    771       if(pcPic->getOutputMark() && pcPic->getPOC() > m_pocLastDisplay[decIdx] &&
    772         (numPicsNotYetDisplayed >  numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid))
    773 #else     
    774610      if(pcPic->getOutputMark() && pcPic->getPOC() > m_iPOCLastDisplay &&
    775611        (numPicsNotYetDisplayed >  numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid))
    776 #endif
    777612      {
    778613        // write to file
     
    782617          dpbFullness--;
    783618        }
    784 #if NH_MV
    785       if ( m_pchReconFiles[decIdx] )
    786 #else
    787619        if ( m_pchReconFile )
    788 #endif
    789620        {
    790621          const Window &conf    = pcPic->getConformanceWindow();
    791622          const Window defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
    792 #if NH_MV
    793         assert( conf   .getScaledFlag() );
    794         assert( defDisp.getScaledFlag() );
    795 #if ENC_DEC_TRACE
    796         g_bJustDoIt = true; 
    797         writeToTraceFile( "OutputPic Poc"   , pcPic->getPOC    (), g_decTracePicOutput  );
    798         writeToTraceFile( "OutputPic LayerId", pcPic->getLayerId(), g_decTracePicOutput );         
    799         g_bJustDoIt = false;
    800 #endif
    801         m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(),
    802 #else
     623
    803624          m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(),
    804 #endif
    805625                                         m_outputColourSpaceConvert,
    806626                                         conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
    807627                                         conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
    808628                                         conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
    809                                          conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(),
    810 #if NH_3D
    811                                           m_depth420OutputFlag && pcPic->getIsDepth() ? CHROMA_420 : NUM_CHROMA_FORMAT,
    812 #else
    813                                           NUM_CHROMA_FORMAT,
    814 #endif
    815            m_bClipOutputVideoToRec709Range   );
     629                                         conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(),
     630                                         NUM_CHROMA_FORMAT, m_bClipOutputVideoToRec709Range  );
    816631        }
    817632
    818633        // update POC of display order
    819 #if NH_MV
    820         m_pocLastDisplay[decIdx] = pcPic->getPOC();
    821 #else
    822634        m_iPOCLastDisplay = pcPic->getPOC();
    823 #endif
    824635
    825636        // erase non-referenced picture in the reference picture list after display
     
    832643        }
    833644        pcPic->setOutputMark(false);
    834 #if NH_MV
    835         pcPic->setPicOutputFlag(false);
    836 #endif
    837645      }
    838646
     
    844652/** \param pcListPic list of pictures to be written to file
    845653 */
    846 #if NH_MV
    847 Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic, Int decIdx )
    848 #else
    849654Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic )
    850 #endif
    851655{
    852656  if(!pcListPic || pcListPic->empty())
     
    873677      {
    874678        // write to file
    875 #if NH_MV
    876       if ( m_pchReconFiles[decIdx] )
    877 #else
     679
    878680        if ( m_pchReconFile )
    879 #endif
    880681        {
    881682          const Window &conf = pcPicTop->getConformanceWindow();
    882683          const Window  defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window();
    883684          const Bool isTff = pcPicTop->isTopField();
    884 #if NH_MV
    885         assert( conf   .getScaledFlag() );
    886         assert( defDisp.getScaledFlag() );
    887 #if ENC_DEC_TRACE
    888         g_bJustDoIt = true; 
    889         writeToTraceFile( "OutputPic Poc"   , pcPic->getPOC    (), g_decTracePicOutput  );
    890         writeToTraceFile( "OutputPic LayerId", pcPic->getLayerId(), g_decTracePicOutput );         
    891         g_bJustDoIt = false; 
    892 #endif
    893         m_tVideoIOYuvReconFile[decIdx]->write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
    894 #else
    895685          m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
    896 #endif
    897686                                         m_outputColourSpaceConvert,
    898687                                         conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
    899688                                         conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
    900689                                         conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
    901 #if NH_3D
    902                                          conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), m_depth420OutputFlag && pcPicTop->getIsDepth() ? CHROMA_420 : NUM_CHROMA_FORMAT, isTff );
    903 #else
    904690                                         conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), NUM_CHROMA_FORMAT, isTff );
    905 #endif
    906691        }
    907692
    908693        // update POC of display order
    909 #if NH_MV
    910       m_pocLastDisplay[decIdx] = pcPic->getPOC();
    911 #else
    912694        m_iPOCLastDisplay = pcPicBottom->getPOC();
    913 #endif       
     695
    914696        // erase non-referenced picture in the reference picture list after display
    915697        if ( !pcPicTop->getSlice(0)->isReferenced() && pcPicTop->getReconMark() == true )
     
    954736      {
    955737        // write to file
    956 #if NH_MV
    957       if ( m_pchReconFiles[decIdx] )
    958 #else
    959738        if ( m_pchReconFile )
    960 #endif
    961739        {
    962740          const Window &conf    = pcPic->getConformanceWindow();
    963741          const Window  defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
    964 #if NH_MV
    965         assert( conf   .getScaledFlag() );
    966         assert( defDisp.getScaledFlag() );
    967 #if ENC_DEC_TRACE
    968         g_bJustDoIt = true; 
    969         writeToTraceFile( "OutputPic Poc"   , pcPic->getPOC    (), g_decTracePicOutput  );
    970         writeToTraceFile( "OutputPic LayerId", pcPic->getLayerId(), g_decTracePicOutput );         
    971         g_bJustDoIt = false; 
    972 #endif
    973         m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(),
    974 #else
    975742          m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(),
    976 #endif
    977743                                         m_outputColourSpaceConvert,
    978744                                         conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
    979745                                         conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
    980746                                         conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
    981                                          conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(),
    982 #if NH_3D
    983                                          m_depth420OutputFlag && pcPic->getIsDepth() ? CHROMA_420 : NUM_CHROMA_FORMAT
    984 #else
    985                                          NUM_CHROMA_FORMAT
    986 #endif
    987                                          , m_bClipOutputVideoToRec709Range);
     747                                         conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(),
     748                                         NUM_CHROMA_FORMAT, m_bClipOutputVideoToRec709Range );
    988749        }
    989750
    990751        // update POC of display order
    991 #if NH_MV
    992       m_pocLastDisplay[decIdx] = pcPic->getPOC();
    993 #else
    994752        m_iPOCLastDisplay = pcPic->getPOC();
    995 #endif
    996 
    997753        // erase non-referenced picture in the reference picture list after display
    998754        if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true )
     
    1004760        }
    1005761        pcPic->setOutputMark(false);
    1006 #if NH_MV
    1007         pcPic->setPicOutputFlag(false);
    1008 #endif
    1009       }
    1010 #if !NH_MV
     762      }
    1011763      if(pcPic != NULL)
    1012764      {
     
    1015767        pcPic = NULL;
    1016768      }
    1017 #endif
    1018769      iterPic++;
    1019770    }
    1020771  }
    1021 #if NH_MV
    1022   m_pocLastDisplay[decIdx] = -MAX_INT;
    1023 #else
    1024772  pcListPic->clear();
    1025773  m_iPOCLastDisplay = -MAX_INT;
     774}
    1026775#endif
    1027 }
    1028 
    1029776/** \param nalu Input nalu to check whether its LayerId is within targetDecLayerIdSet
    1030777 */
     778#if NH_MV
     779Bool TAppDecTop::xIsNaluInTargetDecLayerIdSet( InputNALUnit* nalu )
     780#else
    1031781Bool TAppDecTop::isNaluWithinTargetDecLayerIdSet( InputNALUnit* nalu )
     782#endif
    1032783{
    1033784  if ( m_targetDecLayerIdSet.size() == 0 ) // By default, the set is empty, meaning all LayerIds are allowed
     
    1037788  for (std::vector<Int>::iterator it = m_targetDecLayerIdSet.begin(); it != m_targetDecLayerIdSet.end(); it++)
    1038789  {
     790    if ( nalu->m_nuhLayerId == (*it) )
     791    {
     792      return true;
     793    }
     794  }
     795  return false;
     796}
     797
    1039798#if NH_MV
    1040     if ( nalu->m_nuhLayerId == (*it) )
    1041 #else
    1042     if ( nalu->m_nuhLayerId == (*it) )
     799
     800Bool TAppDecTop::xExtractAndRewrite( InputNALUnit* nalu )
     801{
     802  Bool naluInSubStream;
     803  if ( !m_initilizedFromVPS )
     804  {
     805    naluInSubStream = true; // No active VPS yet. Wait for slice activating one.
     806  }
     807  else
     808  {
     809    if ( m_decProcCvsg == CLAUSE_8 )
     810    {
     811      // 8.1.2->clause 10
     812
     813      // sub-bitstream extraction process as specified in clause 10
     814      naluInSubStream = true;
     815      if ( nalu->m_temporalId > m_highestTid || !xIsNaluInTargetDecLayerIdSet(nalu) )
     816      {
     817        naluInSubStream = false;
     818      }
     819    }
     820    else
     821    {
     822      // F.8.1.2
     823      Int targetDecLayerSetIdx = m_vps->olsIdxToLsIdx( m_targetOptLayerSetIdx );
     824      if ( targetDecLayerSetIdx <= m_vps->getVpsNumLayerSetsMinus1() && m_vps->getVpsBaseLayerInternalFlag() )
     825      {
     826        // - If TargetDecLayerSetIdx is less than or equal to vps_num_layer_sets_minus1 and
     827        //   vps_base_layer_internal_flag is equal to 1, the following applies:
     828        //   - The sub-bitstream extraction process as specified in clause 10 is applied with the CVSG, HighestTid and
     829        //     TargetDecLayerIdList as inputs, and the output is assigned to a bitstream referred to as BitstreamToDecode.
     830
     831        naluInSubStream = true;
     832        if ( nalu->m_temporalId > m_highestTid || !xIsNaluInTargetDecLayerIdSet(nalu) )
     833        {
     834          naluInSubStream = false;
     835        }
     836
     837      }
     838      else if ( targetDecLayerSetIdx <= m_vps->getVpsNumLayerSetsMinus1() && !m_vps->getVpsBaseLayerInternalFlag() )
     839      {
     840        // - Otherwise, if TargetDecLayerSetIdx is less than or equal to vps_num_layer_sets_minus1 and vps_base_layer_internal_flag
     841        //   is equal to 0, the following applies:
     842        //   - The sub-bitstream extraction process as specified in clause F.10.1 is applied with the CVSG, HighestTid and
     843        //     TargetDecLayerIdList as inputs, and the output is assigned to a bitstream referred to as BitstreamToDecode.
     844
     845        naluInSubStream = true;
     846        if ( nalu->m_temporalId > m_highestTid || !xIsNaluInTargetDecLayerIdSet(nalu) )
     847        {
     848          naluInSubStream = false;
     849        }
     850      }
     851      else if ( targetDecLayerSetIdx > m_vps->getVpsNumLayerSetsMinus1() && m_vps->getNumLayersInIdList( targetDecLayerSetIdx ) == 1 )
     852      {
     853        // - Otherwise, if TargetDecLayerSetIdx is greater than vps_num_layer_sets_minus1 and
     854        //   NumLayersInIdList[ TargetDecLayerSetIdx ] is equal to 1, the following applies:
     855        //   - The independent non-base layer rewriting process of clause F.10.2 is applied with the CVSG, HighestTid and
     856        //     TargetDecLayerIdList[ 0 ] as inputs, and the output is assigned to a bitstream referred to as BitstreamToDecode.
     857
     858        Int assingedBaseLayerId = m_targetDecLayerIdSet[0];
     859        naluInSubStream = true;
     860
     861        if ( nalu->m_nalUnitType != NAL_UNIT_SPS &&
     862          nalu->m_nalUnitType != NAL_UNIT_PPS &&
     863          nalu->m_nalUnitType != NAL_UNIT_EOB &&
     864          nalu->m_nuhLayerId != assingedBaseLayerId )
     865        {
     866          naluInSubStream = false;
     867        }
     868
     869        if ( ( nalu->m_nalUnitType == NAL_UNIT_SPS || nalu->m_nalUnitType != NAL_UNIT_PPS ) &&
     870          !( nalu->m_nuhLayerId == 0 || nalu->m_nuhLayerId == assingedBaseLayerId ) )
     871        {
     872          naluInSubStream = false;
     873        }
     874
     875        if ( nalu->m_nalUnitType == NAL_UNIT_VPS )
     876        {
     877          naluInSubStream = false;
     878        }
     879
     880        if ( nalu->m_temporalId > m_highestTid )
     881        {
     882          naluInSubStream = false;
     883        }
     884               
     885        // For now, don't do the layer id change here, but change smallest layer id.
     886        // To be verified.         
     887        //if ( naluInSubStream )
     888        //{
     889        //  nalu->m_nuhLayerId = 0;
     890        //}
     891      }
     892      else
     893      {
     894        // - Otherwise, the following applies:
     895        //   - The sub-bitstream extraction process as specified in clause F.10.3 is applied with the CVSG, HighestTid and
     896        //     TargetDecLayerIdList as inputs, and the output is assigned to a bitstream referred to as BitstreamToDecode.
     897
     898        naluInSubStream = true;
     899
     900        if ( nalu->m_nalUnitType != NAL_UNIT_VPS &&
     901          nalu->m_nalUnitType != NAL_UNIT_SPS &&
     902          nalu->m_nalUnitType != NAL_UNIT_PPS &&
     903          nalu->m_nalUnitType != NAL_UNIT_EOS &&
     904          nalu->m_nalUnitType != NAL_UNIT_EOB &&
     905          !xIsNaluInTargetDecLayerIdSet(nalu) )
     906        {
     907          naluInSubStream = false;
     908        }
     909
     910        if ( ( nalu->m_nalUnitType == NAL_UNIT_VPS ||
     911          nalu->m_nalUnitType == NAL_UNIT_SPS ||
     912          nalu->m_nalUnitType == NAL_UNIT_PPS ||
     913          nalu->m_nalUnitType == NAL_UNIT_EOS    ) &&
     914          !( nalu->m_nuhLayerId == 0 || xIsNaluInTargetDecLayerIdSet(nalu) )
     915          )
     916        {
     917          naluInSubStream = false;
     918        }
     919
     920        if ( nalu->m_temporalId > m_highestTid )
     921        {
     922          naluInSubStream = false;
     923        }
     924        // TBD: vps_base_layer_available_flag in each VPS is set equal to 0.
     925      }
     926    }
     927  }
     928
     929  return naluInSubStream;
     930}
     931
     932Void TAppDecTop::xProcessVclNalu( InputNALUnit nalu )
     933{
     934  TDecTop* dec  = xGetDecoder( nalu );
     935
     936  // Decode slice header of slice of current or new picture.
     937  dec->decodeSliceHeader( nalu );
     938
     939  // Check if slice belongs to current or new picture
     940  Bool sliceIsFirstOfNewPicture = dec->getFirstSliceSegementInPicFlag();
     941
     942  if ( !xIsSkipVclNalu( nalu, sliceIsFirstOfNewPicture ) )
     943  {
     944    if ( sliceIsFirstOfNewPicture )
     945    {
     946      xDetectNewPocResettingPeriod( nalu );
     947      Bool sliceIsFirstOfNewAU = xDetectNewAu( nalu );
     948      xFinalizePreviousPictures ( sliceIsFirstOfNewAU );
     949      xDecodeFirstSliceOfPicture( nalu, sliceIsFirstOfNewAU );
     950    }
     951    else
     952    {
     953      xDecodeFollowSliceOfPicture( nalu );
     954    }
     955  }
     956}
     957
     958Bool TAppDecTop::xIsSkipVclNalu( InputNALUnit& nalu, Bool isFirstSliceOfPic )
     959{
     960
     961  TDecTop* dec = xGetDecoder( nalu );
     962
     963  m_handleCraAsBlaFlagSetByExtMeans = false;
     964  Bool skipNalu = false;
     965
     966  if ( isFirstSliceOfPic )
     967  {
     968    m_totalNumofPicsReceived++;
     969  }
     970
     971  if (!m_cvsStartFound )
     972  {
     973    // Skip as specified by decoder option. (Not normative!)
     974    if ( m_totalNumofPicsReceived <= m_iSkipFrame )
     975    {
     976      skipNalu = true;
     977      if ( isFirstSliceOfPic )
     978      {
     979        std::cout << "Layer " << std::setfill(' ') << std::setw(2) << nalu.m_nuhLayerId
     980          << "   POC    ? Skipping picture." << std::setw(5) << m_totalNumofPicsReceived - 1 << std::endl;
     981      }
     982    }
     983    else
     984    {     
     985      if ( dec->getIsInOwnTargetDecLayerIdList() )
     986      {
     987        // Search for initial IRAP access unit
     988        Bool canBeSliceOfInitialIrapAu = nalu.isIrap() && ( dec->decProcClause8() || nalu.m_nuhLayerId == dec->getSmallestLayerId() );
     989
     990        if ( !canBeSliceOfInitialIrapAu )
     991        {
     992          skipNalu = true;
     993          if ( isFirstSliceOfPic )
     994          {
     995            std::cout << "Layer " << std::setfill(' ') << std::setw(2) << nalu.m_nuhLayerId
     996              << "   POC    ? Not an initial IRAP AU. Skipping picture." << std::setw(5) << m_totalNumofPicsReceived - 1 << std::endl;
     997          }
     998        }
     999        else
     1000        {
     1001          m_cvsStartFound = true;
     1002          if( nalu.isCra() )
     1003          {
     1004            // Ensure that NoRaslOutputFlag of picture is equal to 1.
     1005            m_handleCraAsBlaFlagSetByExtMeans = true;
     1006            m_handleCraAsBlaFlag = true;
     1007          }
     1008        }
     1009      }
     1010      else
     1011      {
     1012        skipNalu = true;
     1013      }
     1014    }
     1015  }
     1016  else
     1017  {
     1018    assert( dec->getIsInOwnTargetDecLayerIdList() );
     1019  }
     1020  return skipNalu;
     1021}
     1022
     1023Void TAppDecTop::xProcessNonVclNalu( InputNALUnit nalu )
     1024{
     1025  xGetDecoder(nalu)->decodeNonVclNalu( nalu );
     1026
     1027  if (  nalu.m_nalUnitType == NAL_UNIT_EOS )
     1028  {
     1029    m_eosInLayer[ nalu.m_nuhLayerId ] = true;
     1030  }
     1031}
     1032Void TAppDecTop::xTerminateDecoding()
     1033{
     1034    xFinalizePic( true );
     1035    xFinalizeAU ( );
     1036
     1037#if NH_3D
     1038  if( m_cCamParsCollector.isInitialized() )
     1039  {
     1040    m_cCamParsCollector.setSlice( 0 );
     1041  }
    10431042#endif
    1044     {
    1045       return true;
    1046     }
    1047   }
    1048   return false;
    1049 }
    1050 
    1051 #if NH_MV
     1043   xFlushOutput();
     1044   m_dpb.emptyAllSubDpbs();
     1045}
     1046
     1047
     1048//////////////////////////////
     1049/// Process slices
     1050//////////////////////////////
     1051
     1052Void TAppDecTop::xDecodeFirstSliceOfPicture( InputNALUnit nalu, Bool sliceIsFirstOfNewAu )
     1053{
     1054  TDecTop* dec = xGetDecoder(nalu);
     1055  // Initialize from VPS of first slice
     1056
     1057  // Get current SPS and PPS
     1058  TComSlice* slicePilot = dec->getSlicePilot();
     1059  m_vps = slicePilot->getVPS();
     1060  m_sps = slicePilot->getSPS();
     1061  m_pps = slicePilot->getPPS();
     1062
     1063  /// Use VPS activated by the first slice to initialized decoding
     1064  if( !m_initilizedFromVPS )
     1065  {
     1066    xF811GeneralDecProc( nalu );
     1067    m_initilizedFromVPS = true;
     1068    m_newVpsActivatedbyCurAu  = true; //TBD
     1069    m_newVpsActivatedbyCurPic = true;
     1070#if NH_3D
     1071    m_dpb.setVPS( m_vps );
     1072#endif
     1073  }
     1074
     1075  // Create new sub-DBP if not existing
     1076  m_dpb.getSubDpb( nalu.m_nuhLayerId, true );
     1077
     1078  // Create a new picture initialize and make it the current picture
     1079  assert( m_curPic == NULL );
     1080  m_curPic = new TComPic;
     1081
     1082  m_curPic->create(*m_sps, *m_pps, true);
     1083
     1084  m_curPic->setLayerId                      ( nalu.m_nuhLayerId );
     1085  m_curPic->setDecodingOrder                ( m_decodingOrder[ nalu.m_nuhLayerId ]);
     1086  m_curPic->setIsFstPicOfAllLayOfPocResetPer( m_newPicIsFstPicOfAllLayOfPocResetPer );
     1087  m_curPic->setIsPocResettingPic            ( m_newPicIsPocResettingPic );
     1088  m_curPic->setActivatesNewVps              ( m_newVpsActivatedbyCurPic );
     1089
     1090  dec     ->activatePSsAndInitPicOrSlice( m_curPic );
     1091
     1092  m_decodingOrder[ nalu.m_nuhLayerId ]++;
     1093
     1094  // Insert pic to current AU
     1095  // ( There is also a "current AU in the DBP", however the DBP AU will include the current
     1096  //   picture only after it is inserted to the DBP )
     1097  m_curAu.addPic(  m_curPic, true );
     1098
     1099  // Invoke Claus 8 and Annex F decoding process for a picture (only parts before POC derivation ).
     1100  xPicDecoding( START_PIC, sliceIsFirstOfNewAu );
     1101
     1102  if (m_decProcCvsg == ANNEX_F )
     1103  {
     1104    // Do output before POC derivation
     1105    xF13522OutputAndRemOfPicsFromDpb( true );
     1106  }
     1107
     1108  // Decode POC and apply reference picture set
     1109  dec->setDecProcPocAndRps( m_decProcPocAndRps );
     1110  dec->decodePocAndRps( );
     1111
     1112  // Do output after POC and RPS derivation
     1113  if (m_decProcCvsg == CLAUSE_8 )
     1114  {
     1115    xC522OutputAndRemOfPicsFromDpb( );
     1116  }
     1117  else if (m_decProcCvsg == ANNEX_F )
     1118  {
     1119    xF13522OutputAndRemOfPicsFromDpb( false );
     1120  }
     1121  else
     1122  {
     1123    assert(false);
     1124  }
     1125
     1126  // Generate unavailable reference pictures
     1127  dec->genUnavailableRefPics( );
     1128
     1129  // decode first slice segment
     1130  dec->decodeSliceSegment( nalu );
     1131
     1132  m_firstSliceInBitstream = false;
     1133}
     1134
     1135Void TAppDecTop::xDecodeFollowSliceOfPicture( InputNALUnit nalu )
     1136{
     1137  // decode following segment
     1138    TDecTop* dec = xGetDecoder( nalu );
     1139    dec->activatePSsAndInitPicOrSlice( NULL );
     1140    dec->decodeSliceSegment          ( nalu );
     1141}
     1142
     1143Void TAppDecTop::xFinalizePreviousPictures( Bool sliceIsFirstOfNewAU )
     1144{
     1145  Bool curPicIsLastInAu = sliceIsFirstOfNewAU && (m_curPic != NULL);
     1146  // When slice belongs to new picture, finalize current picture.
     1147  if( m_curPic != NULL )
     1148  {
     1149    xFinalizePic( curPicIsLastInAu );
     1150
     1151    if (m_curPic->isIrap() )
     1152    {
     1153      m_noRaslOutputFlagAssocIrap[ m_curPic->getLayerId() ] = m_curPic->getNoRaslOutputFlag();
     1154    }
     1155
     1156    m_tDecTop[ xGetDecoderIdx( m_curPic->getLayerId() )]->finalizePic();
     1157    m_curPic->getPicYuvRec()->extendPicBorder();
     1158    m_newVpsActivatedbyCurPic = false;
     1159  }
     1160
     1161  // When slice belongs to new AU, finalize current AU.
     1162  if ( curPicIsLastInAu && !m_curAu.empty() )
     1163  {
     1164    xFinalizeAU( );
     1165    m_newVpsActivatedbyCurAu = false;
     1166    m_curAu.clear();
     1167  }
     1168  m_curPic = NULL;
     1169}
     1170
     1171
     1172Void TAppDecTop::xFinalizePic(Bool curPicIsLastInAu )
     1173{
     1174  if ( m_curPic != NULL )
     1175  {
     1176    m_tDecTop[ xGetDecoderIdx(m_curPic->getLayerId() ) ]->executeLoopFilters( ); // 8.7
     1177
     1178    // Invoke Claus 8 and F.8 decoding process for a picture (only parts after POC derivation )
     1179    xPicDecoding(FINALIZE_PIC, curPicIsLastInAu );
     1180
     1181    if( m_decProcCvsg == CLAUSE_8 )
     1182    {
     1183      xC523PicDecMarkAddBumpAndStor    ( );
     1184    }
     1185    else if ( m_decProcCvsg == ANNEX_F )
     1186    {
     1187      xF13523PicDecMarkAddBumpAndStor  ( curPicIsLastInAu );
     1188    }
     1189  }
     1190}
     1191
     1192Void TAppDecTop::xFinalizeAU()
     1193{
     1194#if NH_3D
     1195  if ( !m_curAu.empty())
     1196  {
     1197    for (TComList<TComPic*>::iterator it = m_curAu.begin(); it != m_curAu.end(); it++)
     1198    {
     1199      TComPic* pic = (*it);
     1200      if ( !pic->getHasGeneratedRefPics() )
     1201      {
     1202        pic->compressMotion(1);
     1203      }
     1204    }
     1205  }
     1206#endif
     1207}
     1208
     1209
     1210Void TAppDecTop::xF811GeneralDecProc( InputNALUnit nalu )
     1211{
     1212  ////////////////////////////////////////////////////////////////////////////////
     1213  // F.8.1 General decoding process
     1214  ////////////////////////////////////////////////////////////////////////////////
     1215
     1216  // The following applies at the beginning of decoding a CVSG, after activating the VPS RBSP that is active for
     1217  // the entire CVSG and before decoding any VCL NAL units of the CVSG:
     1218
     1219  if ( !m_vps->getVpsExtensionFlag() )
     1220  {
     1221    //-   If vps_extension( ) is not present in the active VPS or a decoding process specified in this annex is not in use,
     1222    //   clause 8.1.2 is invoked with the CVSG as input.
     1223    x812CvsgDecodingProcess( xGetDecoderIdx( nalu.m_nuhLayerId ) );
     1224    m_decProcCvsg = CLAUSE_8;
     1225  }
     1226  else
     1227  {
     1228    // - Otherwise (vps_extension( ) is present in the active VPS and a decoding process specified in this annex is in use),
     1229    xF812CvsgDecodingProcess( xGetDecoderIdx( nalu.m_nuhLayerId ) );
     1230    xF13521InitDpb();
     1231    m_decProcCvsg = ANNEX_F;
     1232  }
     1233
     1234  if ( m_printVpsInfo  && ( m_decProcCvsg == ANNEX_F ) )
     1235  {
     1236    m_vps->printScalabilityId();
     1237    m_vps->printLayerDependencies();
     1238    m_vps->printLayerSets();
     1239    m_vps->printPTL();
     1240  }
     1241}
     1242
     1243Void   TAppDecTop::xPicDecoding( DecProcPart curPart, Bool picPosInAuIndication )
     1244{
     1245  if ( m_decProcCvsg == CLAUSE_8 )
     1246  {
     1247    // F.8.1.1 -> 8.1.2 -> 8.1.3
     1248    x813decProcForCodPicWithLIdZero  ( curPart );
     1249  }
     1250  else if ( m_decProcCvsg == ANNEX_F )
     1251  {
     1252    if ( m_targetOptLayerSetIdx == 0  )
     1253    {
     1254      // F.8.1.1 -> F.8.1.2 -> 8.1.3
     1255      x813decProcForCodPicWithLIdZero  ( curPart );
     1256    }
     1257    else
     1258    {
     1259      // F.8.1.1 -> F.8.1.2 -> F.8.1.3
     1260      xF813ComDecProcForACodedPic( curPart, picPosInAuIndication );
     1261    }
     1262  }
     1263  else
     1264  {
     1265    assert( false );
     1266  }
     1267}
     1268
     1269Void TAppDecTop::x812CvsgDecodingProcess( Int decIdx )
     1270{
     1271  ///////////////////////////////////////////////////////////////////////////////////////
     1272  //  8.1.2 CVSG decoding process
     1273  ///////////////////////////////////////////////////////////////////////////////////////
     1274
     1275  // The layer identifier list TargetDecLayerIdList, which specifies the list of nuh_layer_id values,
     1276  // in increasing order of nuh_layer_id values, of the NAL units to be decoded, is specified as follows:
     1277
     1278  Bool externalMeansToSetTargetDecLayerIdList = !m_targetDecLayerIdSetFileEmpty;
     1279
     1280  if ( externalMeansToSetTargetDecLayerIdList )
     1281  {
     1282    // - If some external means, not specified in this Specification, is available to set TargetDecLayerIdList,
     1283    //   TargetDecLayerIdList is set by the external means.
     1284    assert( !m_targetDecLayerIdSet.empty() ); // Already done when parsing cfg ile
     1285  }
     1286  else
     1287  {
     1288    //-  Otherwise, TargetDecLayerIdList contains only one nuh_layer_id value that is equal to 0.
     1289    m_targetDecLayerIdSet.clear();
     1290    m_targetDecLayerIdSet.push_back( 0 );
     1291  }
     1292
     1293  // The variable HighestTid, which identifies the highest temporal sub-layer to be decoded, is specified as follows:
     1294  Bool externalMeansSetHighestTid = ( m_iMaxTemporalLayer != -1 );
     1295  if ( externalMeansSetHighestTid )
     1296  {
     1297    //- If some external means, not specified in this Specification, is available to set HighestTid,
     1298    //  HighestTid is set by the external means.
     1299    m_highestTid = m_iMaxTemporalLayer;
     1300  }
     1301  else
     1302  {
     1303    //-  Otherwise, HighestTid is set equal to sps_max_sub_layers_minus1.
     1304    m_highestTid = m_sps->getSpsMaxSubLayersMinus1();
     1305  }
     1306
     1307  //The variable SubPicHrdFlag is specified as follows:
     1308  //- 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.
     1309  //- Otherwise, SubPicHrdFlag is set equal to ( SubPicHrdPreferredFlag  &&  sub_pic_hrd_params_present_flag ).
     1310
     1311  // 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.
     1312}
     1313
     1314Void TAppDecTop::x813decProcForCodPicWithLIdZero( DecProcPart curPart )
     1315{
     1316  ////////////////////////////////////////////////////////////////////////////////
     1317  // 8.1.3 Decoding process for a coded picture with nuh_layer_id equal to 0.
     1318  ////////////////////////////////////////////////////////////////////////////////
     1319
     1320  if ( curPart == START_PIC )
     1321  {
     1322    Int nuhLayerId = m_curPic->getLayerId();
     1323
     1324    if ( ( m_curPic->isBla() && m_curPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP ) || m_curPic->isCra() )
     1325    {
     1326      // Not needed.
     1327      // 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:
     1328      // -  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.
     1329      // -  Otherwise, the value of UseAltCpbParamsFlag is set equal to 0.
     1330    }
     1331
     1332    if ( m_curPic->isIrap() )
     1333    {
     1334      // When the current picture is an IRAP picture, the following applies:
     1335      if ( m_curPic->isIdr() || m_curPic->isBla() || m_curPic->getDecodingOrder() == 0 || m_eosInLayer[ nuhLayerId ] )
     1336      {
     1337        // -  If the current picture is an IDR picture, a BLA picture, the first picture in the bitstream in decoding order,
     1338        //    or the first picture that follows an end of sequence NAL unit in decoding order, the variable NoRaslOutputFlag
     1339        //    is set equal to 1.
     1340
     1341        m_curPic->setNoRaslOutputFlag( true );
     1342      }
     1343      else if ( m_handleCraAsBlaFlagSetByExtMeans )
     1344      {
     1345        // -  Otherwise, if some external means not specified in this Specification is available to set the variable HandleCraAsBlaFlag
     1346        //    to a value for the current picture, the variable HandleCraAsBlaFlag is set equal to the value provided by
     1347        //    the external means and the variable NoRaslOutputFlag is set equal to HandleCraAsBlaFlag.
     1348
     1349        m_curPic->setNoRaslOutputFlag( m_handleCraAsBlaFlag );
     1350      }
     1351      else
     1352      {
     1353        // -  Otherwise, the variable HandleCraAsBlaFlag is set equal to 0 and the variable NoRaslOutputFlag is set equal to 0.
     1354        m_handleCraAsBlaFlag = false;
     1355        m_curPic->setNoRaslOutputFlag( false );
     1356      }
     1357    }
     1358
     1359    m_decProcPocAndRps = CLAUSE_8;
     1360  }
     1361  else if ( curPart == FINALIZE_PIC )
     1362  {
     1363    // -  PicOutputFlag is set as follows:
     1364    if (m_curPic->isRasl() && m_noRaslOutputFlagAssocIrap[ m_curPic->getLayerId() ] )
     1365    {
     1366      // -  If the current picture is a RASL picture and NoRaslOutputFlag of the associated IRAP picture is equal to 1,
     1367      //    PicOutputFlag is set equal to 0.
     1368      m_curPic->setPicOutputFlag( false );
     1369    }
     1370    else
     1371    {
     1372      // -  Otherwise, PicOutputFlag is set equal to pic_output_flag.
     1373      m_curPic->setPicOutputFlag( m_curPic->getSlice(0)->getPicOutputFlag() );
     1374    }
     1375
     1376    // 4.  After all slices of the current picture have been decoded, the decoded picture is marked as "used for short-term reference".
     1377    m_curPic->markAsUsedForShortTermReference();
     1378  }
     1379}
     1380
     1381// F.8.1.2
     1382Void TAppDecTop::xF812CvsgDecodingProcess( Int decIdx )
     1383{
     1384  ///////////////////////////////////////////////////////////////////////////////////////
     1385  //  F.8.1.2 CVSG decoding process
     1386 ///////////////////////////////////////////////////////////////////////////////////////
     1387
     1388  // The variable TargetOlsIdx, which specifies the index to the list of the OLSs
     1389  // specified by the VPS, of the target OLS, is specified as follows:
     1390
     1391
     1392  // If some external means, not specified in this Specification, is available to set
     1393  // TargetOlsIdx, TargetOlsIdx is set by the external means.
     1394
     1395  // For this decoder the TargetOlsIdx is always set by external means:
     1396  // When m_targetOptLayerSetIdx is equal to -1,  TargetOlsIdx is set to getVpsNumLayerSetsMinus1 (which has already been done in TDecTop, since needed there for parsing)
     1397  // Otherwise m_targetOptLayerSetIdx is used directly.
     1398
     1399  if ( m_targetOptLayerSetIdx == -1 )
     1400  {
     1401    m_targetOptLayerSetIdx = m_tDecTop[decIdx]->getTargetOlsIdx();
     1402  }
     1403  else
     1404  {
     1405    assert( m_tDecTop[decIdx]->getTargetOlsIdx() == m_targetOptLayerSetIdx );
     1406  }
     1407
     1408  m_targetDecLayerSetIdx = m_vps->olsIdxToLsIdx( m_targetOptLayerSetIdx );
     1409  m_targetDecLayerIdSet  = m_vps->getTargetDecLayerIdList( m_targetOptLayerSetIdx );
     1410
     1411
     1412  if ( m_targetOptLayerSetIdx < 0 || m_targetOptLayerSetIdx >= m_vps->getNumOutputLayerSets() )
     1413  {
     1414    fprintf(stderr, "\ntarget output layer set index must be in the range of 0 to %d, inclusive \n", m_vps->getNumOutputLayerSets() - 1 );
     1415    exit(EXIT_FAILURE);
     1416  }
     1417
     1418  if ( !m_vps->getVpsBaseLayerAvailableFlag() )
     1419  {
     1420    if(  m_targetDecLayerSetIdx < m_vps->getFirstAddLayerSetIdx() || m_targetDecLayerSetIdx > m_vps->getLastAddLayerSetIdx() )
     1421    {
     1422      // When vps_base_layer_available_flag is equal to 0, OlsIdxToLsIdx[ TargetOlsIdx ] shall be in the range of FirstAddLayerSetIdx to LastAddLayerSetIdx, inclusive.
     1423      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() );
     1424      exit(EXIT_FAILURE);
     1425    }
     1426  }
     1427
     1428  if ( !m_vps->getVpsBaseLayerInternalFlag() && m_targetOptLayerSetIdx <= 0 )
     1429  {
     1430    // When vps_base_layer_internal_flag is equal to 0, TargetOlsIdx shall be greater than 0.
     1431    fprintf(stderr, "\nvps_base_layer_internal_flag is equal to 0, TargetOlsIdx shall be greater than 0.\n" );
     1432    exit(EXIT_FAILURE);
     1433  }
     1434
     1435  // The variable HighestTid, which identifies the highest temporal sub-layer to be decoded,
     1436  // is specified as follows:
     1437
     1438  Bool externalMeansSetHighestTid = ( m_iMaxTemporalLayer != -1 );
     1439  if ( externalMeansSetHighestTid )
     1440  {
     1441    m_highestTid = m_iMaxTemporalLayer;
     1442  }
     1443  else
     1444  {
     1445    m_highestTid = m_sps->getSpsMaxSubLayersMinus1();
     1446  }
     1447
     1448  // The variable SubPicHrdPreferredFlag is either specified by external means, or when not specified by external means, set equal to 0.
     1449  // The variable SubPicHrdFlag is specified as follows:
     1450  // -  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.
     1451  // -  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.
     1452  // -  TBD in case that needed some when.
     1453
     1454  // A bitstream to be decoded, BitstreamToDecode, is specified as follows:
     1455  //   - Extraction is done in xExtractAndRewrite();
     1456
     1457  //   - SmallestLayerId is already derived in  TDecTop:: initFromActiveVps, since required for SH parsing.
     1458  m_smallestLayerId = m_tDecTop[decIdx]->getSmallestLayerId();
     1459
     1460  // When vps_base_layer_internal_flag is equal to 0, vps_base_layer_available_flag is equal to 1,
     1461  // and TargetDecLayerSetIdx is in the range of 0 to vps_num_layer_sets_minus1, inclusive,
     1462  // the following applies:
     1463  if ( !m_vps->getVpsBaseLayerInternalFlag() && m_vps->getVpsBaseLayerAvailableFlag() &&
     1464       ( m_targetDecLayerSetIdx >= 0 && m_targetDecLayerSetIdx <= m_vps->getVpsNumLayerSetsMinus1() ) )
     1465  {
     1466
     1467    // TBD: The size of the sub-DPB for the layer with nuh_layer_id equal to 0 is set equal to 1.
     1468
     1469    // TBD: The values of pic_width_in_luma_samples, pic_height_in_luma_samples, chroma_format_idc,
     1470    // separate_colour_plane_flag, bit_depth_luma_minus8, bit_depth_chroma_minus8, conf_win_left_offset,
     1471    // conf_win_right_offset, conf_win_top_offset, and conf_win_bottom_offset for decoded pictures
     1472    // with nuh_layer_id equal to 0 are set equal to the values of pic_width_vps_in_luma_samples,
     1473    // pic_height_vps_in_luma_samples, chroma_format_vps_idc, separate_colour_plane_vps_flag,
     1474    // bit_depth_vps_luma_minus8, bit_depth_vps_chroma_minus8, conf_win_vps_left_offset,
     1475    // conf_win_vps_right_offset, conf_win_vps_top_offset, and conf_win_vps_bottom_offset respectively,
     1476    // of the vps_rep_format_idx[ 0 ]-th rep_format( ) syntax structure in the active VPS.
     1477
     1478    // The variable BaseLayerOutputFlag is set equal to ( TargetOptLayerIdList[ 0 ]  = =  0 ).
     1479
     1480    m_baseLayerOutputFlag = ( m_vps->getTargetOptLayerIdList( m_targetOptLayerSetIdx )[ 0 ] == 0 );
     1481
     1482    // NOTE - The BaseLayerOutputFlag for each access unit is to be sent by an external means to
     1483    // the base layer decoder for controlling the output of base layer decoded pictures.
     1484    // BaseLayerOutputFlag equal to 1 indicates that the base layer is an output layer.
     1485    // BaseLayerOutputFlag equal to 0 indicates that the base layer is not an output layer.
     1486
     1487    // The variable LayerInitializedFlag[ i ] is set equal to 0 for all values of i from 0
     1488    // to vps_max_layer_id, inclusive, and the variable FirstPicInLayerDecodedFlag[ i ] is set
     1489    // equal to 0 for all values of i from 0 to vps_max_layer_id, inclusive.
     1490
     1491    for (Int i = 0; i <= m_vps->getVpsMaxLayerId(); i++ )
     1492    {
     1493      m_layerInitilizedFlag       [ i ] = false;
     1494      m_firstPicInLayerDecodedFlag[ i ] = false;
     1495    }
     1496  }
     1497}
     1498
     1499Void TAppDecTop::xC522OutputAndRemOfPicsFromDpb( )
     1500{
     1501  ////////////////////////////////////////////////////////////////////////////////
     1502  // C.5.2.2 Output and removal of pictures from the DPB
     1503  ////////////////////////////////////////////////////////////////////////////////
     1504
     1505//  The output and removal of pictures from the DPB before the decoding of the current picture
     1506//  (but after parsing the slice header of the first slice of the current picture) happens instantaneously
     1507//  when the first decoding unit of the access unit containing the current picture is removed from the CPB and proceeds as follows:
     1508//  - The decoding process for RPS as specified in clause 8.3.2 is invoked.
     1509
     1510  Int nuhLayerId = m_curPic->getLayerId();
     1511  const TComSPS* sps = m_curPic->getSlice(0)->getSPS();
     1512  assert( nuhLayerId == 0 );
     1513
     1514  if( ( m_curPic->isIrap() && m_curPic->getNoRaslOutputFlag() == 1) && m_curPic->getDecodingOrder() != 0 )
     1515  {
     1516    // - If the current picture is an IRAP picture with NoRaslOutputFlag equal to 1 that is not picture 0,
     1517    //   the following ordered steps are applied:
     1518
     1519    // 1.  The variable NoOutputOfPriorPicsFlag is derived for the decoder under test as follows:
     1520    Int noOutputOfPriorPicsFlag;
     1521    if( m_curPic->isCra() )
     1522    {
     1523      //-  If the current picture is a CRA picture, NoOutputOfPriorPicsFlag is set equal to 1
     1524      // (regardless of the value of no_output_of_prior_pics_flag).
     1525      noOutputOfPriorPicsFlag = true;
     1526    }
     1527    else if ( 0  )
     1528    {
     1529      // TBD
     1530      //- Otherwise, if the value of pic_width_in_luma_samples, pic_height_in_luma_samples, chroma_format_idc,
     1531      //  separate_colour_plane_flag, bit_depth_luma_minus8, bit_depth_chroma_minus8 or sps_max_dec_pic_buffering_minus1[ HighestTid ]
     1532      //  derived from the active SPS is different from the value of pic_width_in_luma_samples, pic_height_in_luma_samples,
     1533      //  chroma_format_idc, separate_colour_plane_flag, bit_depth_luma_minus8, bit_depth_chroma_minus8 or
     1534      //  sps_max_dec_pic_buffering_minus1[ HighestTid ], respectively, derived from the SPS active for the preceding picture,
     1535      //  NoOutputOfPriorPicsFlag may (but should not) be set to 1 by the decoder under test,
     1536      //  regardless of the value of no_output_of_prior_pics_flag.
     1537      //     NOTE - Although setting NoOutputOfPriorPicsFlag equal to no_output_of_prior_pics_flag is preferred under these conditions,
     1538      //            the decoder under test is allowed to set NoOutputOfPriorPicsFlag to 1 in this case.
     1539    }
     1540    else
     1541    {
     1542      noOutputOfPriorPicsFlag = m_curPic->getSlice(0)->getNoOutputPriorPicsFlag();
     1543    }
     1544    //  2.  The value of NoOutputOfPriorPicsFlag derived for the decoder under test is applied for the HRD as follows:
     1545    if (noOutputOfPriorPicsFlag)
     1546    {
     1547      //-  If NoOutputOfPriorPicsFlag is equal to 1, all picture storage buffers in the DPB are emptied
     1548      //   without output of the pictures they contain and the DPB fullness is set equal to 0.
     1549      m_dpb.emptySubDpb( nuhLayerId );
     1550    }
     1551    else if (!noOutputOfPriorPicsFlag)
     1552    {
     1553      //  -  Otherwise (NoOutputOfPriorPicsFlag is equal to 0), all picture storage buffers containing a picture that
     1554      //     is marked as "not needed for output" and "unused for reference" are emptied (without output) and all non-empty
     1555      //     picture storage buffers in the DPB are emptied by repeatedly invoking the "bumping" process specified in clause C.5.2.4
     1556      //     and the DPB fullness is set equal to 0.
     1557
     1558      m_dpb.emptySubDpbNotNeedForOutputAndUnusedForRef( nuhLayerId );
     1559      while( m_dpb.getSubDpb( nuhLayerId, false  )->size() != 0 )
     1560      {
     1561        xC524Bumping();
     1562      }
     1563    }
     1564  }
     1565  else if ( !( m_curPic->isIrap() && m_curPic->getNoRaslOutputFlag() == 0 ) )
     1566  {
     1567    //  -  Otherwise (the current picture is not an IRAP picture with NoRaslOutputFlag equal to 1),
     1568    //     all picture storage buffers containing a picture which are marked as "not needed for output" and "unused for reference"
     1569    //     are emptied (without output). For each picture storage buffer that is emptied, the DPB fullness is decremented by one.
     1570
     1571    m_dpb.emptySubDpbNotNeedForOutputAndUnusedForRef( nuhLayerId );
     1572
     1573    Bool repeat = true;
     1574
     1575    while( repeat )
     1576    {
     1577      TComSubDpb* dpb = m_dpb.getSubDpb( nuhLayerId, false );
     1578      TComList<TComPic*> picsMarkedForOutput = dpb->getPicsMarkedNeedForOutput();
     1579      // When one or more of the following conditions are true, the "bumping" process specified in clause C.5.2.4
     1580      // is invoked repeatedly while further decrementing the DPB fullness by one for each additional picture storage buffer that
     1581      // is emptied, until none of the following conditions are true:
     1582
     1583      // -  The number of pictures in the DPB that are marked as "needed for output" is greater
     1584      //    than sps_max_num_reorder_pics[ HighestTid ].
     1585      Bool cond1 = ( picsMarkedForOutput.size() > sps->getSpsMaxNumReorderPics( m_highestTid ) );
     1586
     1587      //  -  sps_max_latency_increase_plus1[ HighestTid ] is not equal to 0 and there is at least one picture in the DPB
     1588      //     that is marked as "needed for output" for which the associated variable PicLatencyCount is greater than or equal
     1589      //     to SpsMaxLatencyPictures[ HighestTid ].
     1590      Bool anyPicWithGtOrEqLatencyCnt = false;
     1591      for (TComList<TComPic*>::iterator itP = picsMarkedForOutput.begin(); itP != picsMarkedForOutput.end() && !anyPicWithGtOrEqLatencyCnt; itP++ )
     1592      {
     1593        anyPicWithGtOrEqLatencyCnt = anyPicWithGtOrEqLatencyCnt || ( (*itP)->getPicLatencyCount() >= sps->getSpsMaxLatencyPictures( m_highestTid ));
     1594      }
     1595      Bool cond2 = ( sps->getSpsMaxLatencyIncreasePlus1( m_highestTid ) != 0 ) && anyPicWithGtOrEqLatencyCnt;
     1596
     1597      //  -  The number of pictures in the DPB is greater than or equal to sps_max_dec_pic_buffering_minus1[ HighestTid ] + 1.
     1598      Bool cond3 = ( dpb->size() >= ( sps->getSpsMaxDecPicBufferingMinus1( m_highestTid ) + 1 ));
     1599
     1600      if ( cond1 || cond2 || cond3 )
     1601      {
     1602        xC524Bumping();
     1603      }
     1604      else
     1605      {
     1606        repeat = false;
     1607      }
     1608    }
     1609  }
     1610}
     1611
     1612Void TAppDecTop::xC523PicDecMarkAddBumpAndStor()
     1613{
     1614  ///////////////////////////////////////////////////////////////////////////////////////
     1615  // C.5.2.3 Picture decoding, marking, additional bumping and storage 
     1616  ///////////////////////////////////////////////////////////////////////////////////////
     1617 
     1618  Int nuhLayerId = m_curPic->getLayerId();
     1619  const TComSPS* sps = m_curPic->getSlice(0)->getSPS();
     1620  // The processes specified in this clause happen instantaneously when the last decoding unit of access unit n containing the
     1621  // current picture is removed from the CPB.
     1622  if (m_curPic->getPicOutputFlag() )
     1623  {
     1624    // When the current picture has PicOutputFlag equal to 1, for each picture in the DPB that is marked as "needed for output"
     1625    // and follows the current picture in output order, the associated variable PicLatencyCount is set equal to PicLatencyCount + 1.
     1626    TComSubDpb* dpb = m_dpb.getSubDpb( nuhLayerId, false);
     1627
     1628    for (TComSubDpb::iterator itP = dpb->begin(); itP != dpb->end(); itP++)
     1629    {
     1630      TComPic* pic = (*itP);
     1631      if ( pic->getOutputMark() && pic->getPOC() > m_curPic->getPOC() )
     1632      {
     1633        pic->setPicLatencyCount( pic->getPicLatencyCount() + 1 );
     1634      }
     1635    }
     1636  }
     1637
     1638  // The current picture is considered as decoded after the last decoding unit of the picture is decoded.
     1639  // The current decoded picture is stored in an empty picture storage buffer in the DPB and the following applies:
     1640  m_dpb.addNewPic( m_curPic );
     1641
     1642
     1643  if (m_curPic->getPicOutputFlag())
     1644  {
     1645    // - If the current decoded picture has PicOutputFlag equal to 1, it is marked as "needed for output" and its associated
     1646    //   variable PicLatencyCount is set equal to 0.
     1647    m_curPic->setOutputMark( true );
     1648    m_curPic->setPicLatencyCount( 0 );
     1649  }
     1650  else if (!m_curPic->getPicOutputFlag() )
     1651  {
     1652    // - Otherwise (the current decoded picture has PicOutputFlag equal to 0), it is marked as "not needed for output".
     1653    m_curPic->setOutputMark( false );
     1654  }
     1655
     1656  // The current decoded picture is marked as "used for short-term reference".
     1657  m_curPic->markAsUsedForShortTermReference();
     1658
     1659  Bool repeat = true;
     1660
     1661  while( repeat )
     1662  {
     1663    TComSubDpb* dpb = m_dpb.getSubDpb( nuhLayerId, false );
     1664    TComList<TComPic*> picsMarkedForOutput = dpb->getPicsMarkedNeedForOutput();
     1665
     1666    // When one or more of the following conditions are true, the "bumping" process specified in clause C.5.2.4
     1667    // is invoked repeatedly until none of the following conditions are true:
     1668
     1669    // - The number of pictures in the DPB that are marked as "needed for output" is greater than sps_max_num_reorder_pics[ HighestTid ].
     1670    Bool cond1 = ( picsMarkedForOutput.size() > sps->getSpsMaxNumReorderPics( m_highestTid ) );
     1671
     1672    // - sps_max_latency_increase_plus1[ HighestTid ] is not equal to 0 and there is at least one picture in the DPB that is marked
     1673    //   as "needed for output" for which the associated variable PicLatencyCount that is greater than or equal to
     1674    //   SpsMaxLatencyPictures[ HighestTid ].
     1675    Bool anyPicWithGtOrEqLatencyCnt = false;
     1676    for (TComList<TComPic*>::iterator itP = picsMarkedForOutput.begin(); itP != picsMarkedForOutput.end() && !anyPicWithGtOrEqLatencyCnt; itP++ )
     1677    {
     1678      anyPicWithGtOrEqLatencyCnt = anyPicWithGtOrEqLatencyCnt || ( (*itP)->getPicLatencyCount() >= sps->getSpsMaxLatencyPictures( m_highestTid ));
     1679    }
     1680    Bool cond2 = ( sps->getSpsMaxLatencyIncreasePlus1( m_highestTid ) != 0 ) && anyPicWithGtOrEqLatencyCnt;
     1681
     1682    if ( cond1 || cond2 )
     1683    {
     1684      xC524Bumping();
     1685    }
     1686    else
     1687    {
     1688      repeat = false;
     1689    }
     1690  }
     1691}
     1692
     1693Void TAppDecTop::xC524Bumping( )
     1694{
     1695  ////////////////////////////////////////////////////////////////////////////////
     1696  // C.5.2.4 "Bumping" process
     1697  ////////////////////////////////////////////////////////////////////////////////
     1698
     1699  // The "bumping" process consists of the following ordered steps:
     1700
     1701  // 1.  The picture that is first for output is selected as the one having the smallest value of PicOrderCntVal of all pictures
     1702  //     in the DPB marked as "needed for output".
     1703  TComPic* pic = *(m_dpb.getSubDpb( 0, false)->getPicsMarkedNeedForOutput().begin()); // pics are sorted, so take first
     1704
     1705  // 2.  The picture is cropped, using the conformance cropping window specified in the active SPS for the picture,
     1706  //     the cropped picture is output, and the picture is marked as "not needed for output".
     1707  xCropAndOutput( pic );
     1708  pic->setOutputMark( false );
     1709
     1710  //3.  When the picture storage buffer that included the picture that was cropped and output contains a picture marked
     1711  //    as "unused for reference", the picture storage buffer is emptied.
     1712  if (pic->getMarkedUnUsedForReference() )
     1713  {
     1714    m_dpb.removePic( pic );
     1715  }
     1716
     1717  // NOTE - For any two pictures picA and picB that belong to the same CVS and are output by the "bumping process", when picA
     1718  //        is output earlier than picB, the value of PicOrderCntVal of picA is less than the value of PicOrderCntVal of picB.
     1719}
     1720
     1721
     1722Void TAppDecTop::xF813ComDecProcForACodedPic( DecProcPart curPart, Bool picPosInAuIndication )
     1723{
     1724  ////////////////////////////////////////////////////////////////////////////////
     1725  // F.8.1.3  Common decoding process for a coded picture
     1726  ////////////////////////////////////////////////////////////////////////////////
     1727
     1728  // PicPosInAuIndication is interpreted based on curPart.
     1729  // - If curPart is equal to START_PIC               , it indicates whether the current pic is the first in the current AU.
     1730  // - Otherwise (if curPart is equal to FINALIZE_PIC), it indicates whether the current pic is the last  in the current AU.
     1731
     1732  if (curPart == START_PIC )
     1733  {
     1734    Bool curPicIsFirstInAu = picPosInAuIndication;
     1735
     1736    Int nuhLayerId = m_curPic->getLayerId();
     1737
     1738    if ( !m_vps->getVpsBaseLayerInternalFlag() && m_vps->getVpsBaseLayerAvailableFlag() &&
     1739      ( m_targetDecLayerSetIdx >= 0 && m_targetDecLayerSetIdx <= m_vps->getVpsNumLayerSetsMinus1() ) &&
     1740      m_curPic->getSlice(0)->getTemporalId() <= m_vps->getSubLayersVpsMaxMinus1( 0 ) && curPicIsFirstInAu )
     1741    {
     1742      // When vps_base_layer_internal_flag is equal to 0, vps_base_layer_available_flag is equal to 1,
     1743      // TargetDecLayerSetIdx is in the range of 0 to vps_num_layer_sets_minus1, inclusive,
     1744      // TemporalId is less than or equal to sub_layers_vps_max_minus1[ 0 ], and the current picture
     1745      // is the first coded picture of an access unit, clause F.8.1.8 is invoked prior to decoding the current picture.
     1746
     1747      assert( false ); //TBD
     1748    }
     1749
     1750    //  When the current picture is an IRAP picture, the variable HandleCraAsBlaFlag is derived as specified in the following:
     1751    if ( m_curPic->isIrap() )
     1752    {
     1753      if ( m_handleCraAsBlaFlagSetByExtMeans )
     1754      {
     1755        // If some external means not specified in this Specification is available to set the variable HandleCraAsBlaFlag to
     1756        // a value for the current picture, the variable HandleCraAsBlaFlag is set equal to the value provided by the external means.
     1757      }
     1758      else
     1759      {
     1760        // - Otherwise, the variable HandleCraAsBlaFlag is set equal to 0.
     1761        m_handleCraAsBlaFlag = false;
     1762      }
     1763    }
     1764
     1765    if ( m_curPic->isIrap() && nuhLayerId == m_smallestLayerId )
     1766    {
     1767      // When the current picture is an IRAP picture and has nuh_layer_id equal to SmallestLayerId, the following applies:
     1768      // The variable NoClrasOutputFlag is specified as follows:
     1769
     1770      if( m_firstSliceInBitstream )
     1771      {
     1772        //  - If the current picture is the first picture in the bitstream, NoClrasOutputFlag is set equal to 1.
     1773        m_curPic->setNoClrasOutputFlag(true );
     1774      }
     1775      else if( m_eosInLayer[ 0 ] || m_eosInLayer[ nuhLayerId ] )
     1776      {
     1777        //  - Otherwise, if the current picture is included in the first access unit that follows an access unit
     1778        //    including an end of sequence NAL unit with nuh_layer_id equal to SmallestLayerId or 0 in decoding order,
     1779        //    NoClrasOutputFlag is set equal to 1.
     1780
     1781        m_curPic->setNoClrasOutputFlag(true );
     1782      }
     1783      else if ( m_curPic->isBla() || (m_curPic->isCra() && m_handleCraAsBlaFlag ))
     1784      {
     1785        //  - Otherwise, if the current picture is a BLA picture or a CRA picture with HandleCraAsBlaFlag equal to 1,
     1786        //    NoClrasOutputFlag is set equal to 1.
     1787        m_curPic->setNoClrasOutputFlag(true );
     1788      }
     1789      else if ( m_curPic->isIdr() && m_curPic->getSlice(0)->getCrossLayerBlaFlag() )
     1790      {
     1791        //  - Otherwise, if the current picture is an IDR picture with cross_layer_bla_flag is equal to 1,
     1792        //    NoClrasOutputFlag is set equal to 1.
     1793        m_curPic->setNoClrasOutputFlag(true );
     1794      }
     1795      else if ( m_noClrasOutputFlagSetByExtMeans )
     1796      {
     1797        m_curPic->setNoClrasOutputFlag( m_noClrasOutputFlag );
     1798        //  - Otherwise, if some external means, not specified in this Specification, is available to set NoClrasOutputFlag,
     1799        //    NoClrasOutputFlag is set by the external means.
     1800      }
     1801      else
     1802      {
     1803        //  - Otherwise, NoClrasOutputFlag is set equal to 0.
     1804        m_curPic->setNoClrasOutputFlag(false );
     1805      }
     1806
     1807      //-  When NoClrasOutputFlag is equal to 1, the variable LayerInitializedFlag[ i ] is set equal to 0 for all values
     1808      //  of i from 0 to vps_max_layer_id, inclusive, and the variable FirstPicInLayerDecodedFlag[ i ] is set equal to 0
     1809      //  for all values of i from 0 to vps_max_layer_id, inclusive.
     1810      if ( m_curPic->getNoClrasOutputFlag( ) )
     1811      {
     1812        for (Int i = 0; i <= m_vps->getVpsMaxLayerId(); i++)
     1813        {
     1814          m_layerInitilizedFlag       [i] = false;
     1815          m_firstPicInLayerDecodedFlag[i] = false;
     1816        }
     1817      }
     1818    }
     1819
     1820    // The variables LayerResetFlag and dolLayerId are derived as follows:
     1821    Int dolLayerId = -1;
     1822    if ( m_curPic->isIrap() && nuhLayerId > m_smallestLayerId )
     1823    {
     1824      // - If the current picture is an IRAP picture and has nuh_layer_id nuhLayerId greater than SmallestLayerId,
     1825      //   the following applies:
     1826
     1827      if( m_eosInLayer[ nuhLayerId ] )
     1828      {
     1829        // -  If the current picture is the first picture, in decoding order, that follows an end of sequence NAL unit with
     1830        //    nuh_layer_id equal to nuhLayerId, LayerResetFlag is set equal to 1 and dolLayerId is set equal to the nuh_layer_id
     1831        //    value of the current NAL unit.
     1832
     1833        m_layerResetFlag = true;
     1834        dolLayerId = nuhLayerId;
     1835      }
     1836      else  if( ( m_curPic->isCra() && m_handleCraAsBlaFlag ) ||
     1837        (m_curPic->isIdr() && m_curPic->getSlice(0)->getCrossLayerBlaFlag() ) || m_curPic->isBla() )
     1838      {
     1839        // - Otherwise, if the current picture is a CRA picture with HandleCraAsBlaFlag equal to 1, an IDR picture with
     1840        //   cross_layer_bla_flag is equal to 1 or a BLA picture, LayerResetFlag is set equal to 1 and dolLayerId is set
     1841        //   equal to the nuh_layer_id value of the current NAL unit.
     1842        m_layerResetFlag = true;
     1843        dolLayerId = nuhLayerId;
     1844      }
     1845      else
     1846      {
     1847        // -   Otherwise, LayerResetFlag is set equal to 0.
     1848        m_layerResetFlag = false;
     1849      }
     1850
     1851      // NOTE 1 - An end of sequence NAL unit, a CRA picture with HandleCraAsBlaFlag equal to 1, an IDR picture with
     1852      // cross_layer_bla_flag equal to 1, or a BLA picture, each with nuh_layer_id nuhLayerId greater than SmallestLayerId,
     1853      // may be present to indicate a discontinuity of the layer with nuh_layer_id equal to nuhLayerId and its predicted layers.
     1854
     1855      if (m_layerResetFlag )
     1856      {
     1857        //When LayerResetFlag is equal to 1, the following applies:
     1858        //  - The values of LayerInitializedFlag and FirstPicInLayerDecodedFlag are updated as follows:
     1859
     1860        for( Int i = 0; i < m_vps->getNumPredictedLayers( dolLayerId ); i++ )
     1861        {
     1862          Int iLayerId = m_vps->getIdPredictedLayer(  dolLayerId , i );
     1863          m_layerInitilizedFlag       [ iLayerId ] = false;
     1864          m_firstPicInLayerDecodedFlag[ iLayerId ] = false;
     1865        }
     1866
     1867        //  - Each picture that is in the DPB and has nuh_layer_id equal to dolLayerId is marked as "unused for reference".
     1868        m_dpb.markSubDpbAsUnusedForReference( dolLayerId );
     1869
     1870        //  - When NumPredictedLayers[ dolLayerId ] is greater than 0, each picture that is in the DPB and has nuh_layer_id
     1871        //    equal to any value of IdPredictedLayer[ dolLayerId ][ i ] for the values of i in the range of 0 to
     1872        //    NumPredictedLayers[ dolLayerId ] - 1, inclusive, is marked as "unused for reference".
     1873
     1874        for( Int i = 0; i <= m_vps->getNumPredictedLayers( dolLayerId )- 1; i++  )
     1875        {
     1876          m_dpb.markSubDpbAsUnusedForReference( m_vps->getIdPredictedLayer( dolLayerId, i ) );
     1877        }
     1878      }
     1879    }
     1880    else
     1881    {
     1882      // - Otherwise, LayerResetFlag is set equal to 0.
     1883      m_layerResetFlag = false;
     1884    }
     1885
     1886    if ( m_curPic->isIrap() )
     1887    {
     1888      // When the current picture is an IRAP picture, the following applies:
     1889
     1890      if ( m_curPic->isIdr() || m_curPic->isBla() || m_curPic->getDecodingOrder() == 0 || m_eosInLayer[nuhLayerId] )
     1891      {
     1892        // - If the current picture with a particular value of nuh_layer_id is an IDR picture, a BLA picture, the first picture
     1893        //   with that particular value of nuh_layer_id in the bitstream in decoding order or the first picture with that
     1894        //   particular value of nuh_layer_id that follows an end of sequence NAL unit with that particular value of nuh_layer_id
     1895        //   in decoding order, the variable NoRaslOutputFlag is set equal to 1.
     1896
     1897        m_curPic->setNoRaslOutputFlag(  true );
     1898      }
     1899      else if ( m_layerInitilizedFlag[ nuhLayerId ] == 0 && xAllRefLayersInitilized( nuhLayerId ) )
     1900      {
     1901        // Otherwise, if LayerInitializedFlag[ nuh_layer_id ] is equal to 0 and LayerInitializedFlag[ refLayerId ] is equal to 1
     1902        // for all values of refLayerId equal to IdDirectRefLayer[ nuh_layer_id ][ j ], where j is in the range of 0 to
     1903        // NumDirectRefLayers[ nuh_layer_id ] - 1, inclusive, the variable NoRaslOutputFlag is set equal to 1.
     1904
     1905        m_curPic->setNoRaslOutputFlag(  true );
     1906      }
     1907      else
     1908      {
     1909        // - Otherwise, the variable NoRaslOutputFlag is set equal to HandleCraAsBlaFlag.
     1910        m_curPic->setNoRaslOutputFlag(  m_handleCraAsBlaFlag );
     1911      }
     1912    }
     1913
     1914    // The following applies for the decoding of the current picture:
     1915    if ( m_curPic->isIrap() && m_curPic->getNoRaslOutputFlag() && (
     1916      ( nuhLayerId == 0 ) ||
     1917      ( m_layerInitilizedFlag[ nuhLayerId ] == 0   && m_vps->getNumDirectRefLayers( nuhLayerId ) == 0  ) ||
     1918      ( m_layerInitilizedFlag[ nuhLayerId ] == 0 && xAllRefLayersInitilized( nuhLayerId ) )
     1919      ) )
     1920    {
     1921      // When the current picture is an IRAP picture with NoRaslOutputFlag equal to 1 and one of the following conditions is true,
     1922      // LayerInitializedFlag[ nuh_layer_id ] is set equal to 1:
     1923      // - nuh_layer_id is equal to 0.
     1924      // - LayerInitializedFlag[ nuh_layer_id ] is equal to 0 and NumDirectRefLayers[ nuh_layer_id ] is equal to 0.
     1925      // - LayerInitializedFlag[ nuh_layer_id ] is equal to 0 and LayerInitializedFlag[ refLayerId ] is equal to 1 for all values of
     1926      //   refLayerId equal to IdDirectRefLayer[ nuh_layer_id ][ j ], where j is in the range of 0 to NumDirectRefLayers[ nuh_layer_id ] - 1, inclusive.
     1927
     1928      m_layerInitilizedFlag[ nuhLayerId ] = true;
     1929    }
     1930
     1931    // The following applies for the decoding of the current picture:
     1932
     1933    if ( nuhLayerId == 0 )
     1934    {
     1935      //  If the current picture has nuh_layer_id equal to 0, the decoding process for the current picture takes as inputs the syntax elements
     1936      //  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
     1937      //  is invoked.
     1938
     1939      xF814decProcForCodPicWithLIdZero( curPart );
     1940    }
     1941    else
     1942    {
     1943      Bool decodedPicWithLayerIdZeroProvided = false;
     1944      if ( !m_vps->getVpsBaseLayerInternalFlag() && m_vps->getVpsBaseLayerAvailableFlag() &&
     1945        ( m_targetDecLayerSetIdx >= 0 && m_targetDecLayerSetIdx <= m_vps->getVpsNumLayerSetsMinus1() ) &&
     1946        m_curPic->getSlice(0)->getTemporalId() <= m_vps->getSubLayersVpsMaxMinus1( 0 ) && curPicIsFirstInAu
     1947        && decodedPicWithLayerIdZeroProvided )
     1948      {
     1949        assert( false ); //TBD
     1950        //TBD: Hybrid scalability
     1951        //  When vps_base_layer_internal_flag is equal to 0, vps_base_layer_available_flag is equal to 1,
     1952        //  TargetDecLayerSetIdx is in the range of 0 to vps_num_layer_sets_minus1, inclusive,
     1953        //  TemporalId is less than or equal to sub_layers_vps_max_minus1[ 0 ], the current picture
     1954        //  is the first coded picture of an access unit, and a decoded picture with nuh_layer_id equal
     1955        //  to 0 is provided by external means for the current access unit, clause F.8.1.9 is invoked
     1956        //  after the decoding of the slice segment header of the first slice segment, in decoding order,
     1957        //  of the current picture, but prior to decoding any slice segment of the first
     1958        //  coded picture of the access unit.
     1959      }
     1960
     1961      m_decProcPocAndRps = ANNEX_F;
     1962      // For the decoding of the slice segment header of the first slice segment, in decoding order, of the current picture,
     1963      // the decoding process for starting the decoding of a coded picture with nuh_layer_id greater than 0 specified in
     1964      // clause F.8.1.5 is invoked.  --> This is done in the loop when receiving slices.
     1965
     1966      // The decoding process is already selected before.
     1967    }
     1968  }
     1969  else if( curPart == FINALIZE_PIC )
     1970  {
     1971    Bool curPicIsLastInAu = picPosInAuIndication;
     1972
     1973    if (m_curPic->getLayerId() == 0 )
     1974    {
     1975      xF814decProcForCodPicWithLIdZero( curPart );
     1976    }
     1977    else
     1978    {
     1979      // - After all slices of the current picture have been decoded, the decoding process for ending the decoding of a
     1980      //   coded picture with nuh_layer_id greater than 0 specified in clause F.8.1.6 is invoked.
     1981      xF816decProcEndDecOfCodPicLIdGrtZero( );
     1982    }
     1983
     1984    TComSlice* slice = m_curPic->getSlice(0);
     1985    const TComVPS* vps = slice->getVPS();
     1986
     1987    if ( curPicIsLastInAu )
     1988    {
     1989      //When the current picture is the last coded picture in an access unit in BitstreamToDecode, the following steps apply after
     1990      // the decoding of the current picture, prior to the decoding of the next picture:
     1991
     1992      //-  PicOutputFlag is updated as follows:
     1993      TComPic* picAtOutputLayer = NULL;
     1994      Int outputLayerId = -1;
     1995
     1996      // Try to find pic at output layer.
     1997      if( vps->getAltOutputLayerFlag( m_targetOptLayerSetIdx ) )
     1998      {
     1999        // When alt_output_layer_flag is equal to 1, the target output layer set can only contain one output layer.
     2000        assert( vps->getNumOutputLayersInOutputLayerSet( m_targetOptLayerSetIdx ) == 1 );
     2001        outputLayerId = vps->getTargetOptLayerIdList(m_targetOptLayerSetIdx)[0];
     2002        picAtOutputLayer = m_curAu.getPic( outputLayerId );
     2003      }
     2004
     2005      if ( vps->getAltOutputLayerFlag( m_targetOptLayerSetIdx ) &&
     2006        ( picAtOutputLayer == NULL || (picAtOutputLayer != NULL && !picAtOutputLayer->getPicOutputFlag() ) ) )
     2007      {
     2008        // If alt_output_layer_flag[ TargetOlsIdx ] is equal to 1 and the current access unit either does
     2009        // not contain a picture at the output layer or contains a picture at the output layer that has PicOutputFlag equal to 0:
     2010
     2011        // - The list nonOutputLayerPictures is set to be the list of the pictures of the access unit with PicOutputFlag equal to 1 and
     2012        //   with nuh_layer_id values among the nuh_layer_id values of the reference layers of the output layer.
     2013        TComList<TComPic*> nonOutputLayerPictures;
     2014        for( TComList<TComPic*>::iterator itP= m_curAu.begin();  itP != m_curAu.end() ; itP++ )
     2015        {
     2016          TComPic* pic = (*itP);
     2017          Bool isRefernceLayerOfOutputLayer = false;
     2018          for ( Int i = 0; i < vps->getNumRefLayers( outputLayerId ) && !isRefernceLayerOfOutputLayer; i++ )
     2019          {
     2020            if ( pic->getLayerId() == vps->getIdRefLayer(outputLayerId, i) )
     2021            {
     2022              isRefernceLayerOfOutputLayer = true;
     2023            }
     2024          }
     2025
     2026          if ( pic->getPicOutputFlag() && isRefernceLayerOfOutputLayer )
     2027          {
     2028            nonOutputLayerPictures.pushBack( pic );
     2029          }
     2030        }
     2031
     2032
     2033        if (nonOutputLayerPictures.size() != 0 )
     2034        {
     2035          // -  When the list nonOutputLayerPictures is not empty,
     2036          //    The picture with the highest nuh_layer_id value among the list nonOutputLayerPictures is removed from the list nonOutputLayerPictures.
     2037          //    As in AU the picture with the highest layer id is the last
     2038          nonOutputLayerPictures.pop_back();
     2039        }
     2040
     2041        //  -  PicOutputFlag for each picture that is included in the list nonOutputLayerPictures is set equal to 0.
     2042        for( TComList<TComPic*>::iterator itP= nonOutputLayerPictures.begin();  itP != nonOutputLayerPictures.end() ; itP++ )
     2043        {
     2044          (*itP)->setPicOutputFlag( false );
     2045        }
     2046      }
     2047      else
     2048      {
     2049        //Otherwise, PicOutputFlag for pictures that are not included in an output layer is set equal to 0.
     2050        for( TComList<TComPic*>::iterator itP= m_curAu.begin();  itP != m_curAu.end() ; itP++ )
     2051        {
     2052          TComPic* pic = (*itP);
     2053
     2054          Bool includedInOutputLayer = false;
     2055          for (Int i = 0 ; i < vps->getNumOutputLayersInOutputLayerSet( m_targetOptLayerSetIdx ) && !includedInOutputLayer; i++)
     2056          {
     2057            includedInOutputLayer = ( pic->getLayerId() ==  vps->getTargetOptLayerIdList(m_targetOptLayerSetIdx)[i]);
     2058          }
     2059
     2060          if ( !includedInOutputLayer )
     2061          {
     2062            pic->setPicOutputFlag( false );
     2063          }
     2064        }
     2065      }
     2066
     2067      // When vps_base_layer_internal_flag is equal to 0, vps_base_layer_available_flag is equal to 1 and
     2068      // TargetDecLayerSetIdx is in the range of 0 to vps_num_layer_sets_minus1, inclusive
     2069
     2070      if( !vps->getVpsBaseLayerInternalFlag() && vps->getVpsBaseLayerAvailableFlag() && ( m_targetDecLayerSetIdx >= 0 && m_targetDecLayerSetIdx <= vps->getVpsNumLayerSetsMinus1()   ) )
     2071      {
     2072        if( !m_baseLayerOutputFlag )
     2073        {
     2074          // Check if base layer is a reference layer of the output layer
     2075          // and if the access unit does not contain a picture at any other reference layer of the output layer
     2076          Bool baseLayerIsRefOfOutputLayer = false;
     2077          Bool auDoesNotContainPicAtAnyOtherRefLayerOfOptLayer = true;
     2078          if ( vps->getAltOutputLayerFlag( m_targetOptLayerSetIdx ))
     2079          {
     2080            assert( outputLayerId >= 0 );
     2081
     2082            for (Int i = 0; i < vps->getNumRefLayers( outputLayerId ); i++ )
     2083            {
     2084              Int refLayerId = vps->getIdRefLayer(outputLayerId, i);
     2085              if( refLayerId == 0 )
     2086              {
     2087                baseLayerIsRefOfOutputLayer = true;
     2088              }
     2089              else
     2090              {
     2091                if ( m_curAu.getPic( refLayerId ) != NULL )
     2092                {
     2093                  auDoesNotContainPicAtAnyOtherRefLayerOfOptLayer = false;
     2094                }
     2095              }
     2096            }
     2097          }
     2098
     2099          // If alt_output_layer_flag[ TargetOlsIdx ] is equal to 1, the base layer is a reference layer of the output layer,
     2100          // the access unit does not contain a picture at the output layer or contains a picture at the output layer that has
     2101          // PicOutputFlag equal to 0, and the access unit does not contain a picture at any other reference layer of the output layer,
     2102          // BaseLayerPicOutputFlag is set equal to 1
     2103
     2104          if ( vps->getAltOutputLayerFlag( m_targetOptLayerSetIdx ) && baseLayerIsRefOfOutputLayer
     2105            && ( ( picAtOutputLayer == NULL ) || ( picAtOutputLayer != NULL && !picAtOutputLayer->getPicOutputFlag()  ) )
     2106            &&  auDoesNotContainPicAtAnyOtherRefLayerOfOptLayer )
     2107          {
     2108            m_baseLayerPicOutputFlag = true;
     2109          }
     2110          else
     2111          {
     2112            m_baseLayerPicOutputFlag = false;
     2113          }
     2114        }
     2115        else
     2116        {
     2117          m_baseLayerPicOutputFlag = true;
     2118        }
     2119
     2120        // NOTE 3 - The BaseLayerPicOutputFlag for each access unit is to be sent by an external means
     2121        // to the base layer decoder for controlling the output of base layer decoded pictures.
     2122        // BaseLayerPicOutputFlag equal to 1 for an access unit specifies that the base layer picture of the access unit is to be output.
     2123        // BaseLayerPicOutputFlag equal to 0 for an access unit specifies that the base layer picture of the access unit is not to be output.
     2124
     2125        //  The sub-DPB for the layer with nuh_layer_id equal to 0 is set to be empty.
     2126        m_dpb.emptySubDpb( 0 );
     2127      }
     2128
     2129      // The variable AuOutputFlag that is associated with the current access unit is derived as follows:
     2130
     2131      // Derive if at least one picture in the current access unit has PicOutputFlag equal to 1
     2132      Bool atLeastOnePicInAuWithPicOptFlagOne = false;
     2133      for( TComList<TComPic*>::iterator itP= m_curAu.begin();  itP != m_curAu.end() ; itP++ )
     2134      {
     2135        if ( (*itP)->getPicOutputFlag() )
     2136        {
     2137          atLeastOnePicInAuWithPicOptFlagOne = true;
     2138        }
     2139      }
     2140
     2141      //If at least one picture in the current access unit has PicOutputFlag equal to 1
     2142      if ( atLeastOnePicInAuWithPicOptFlagOne )
     2143      {
     2144        m_auOutputFlag = true;
     2145      }
     2146      else
     2147      {
     2148        m_auOutputFlag = false;
     2149      }
     2150
     2151      // The variable PicLatencyCount that is associated with the current access unit is set equal to 0.
     2152      m_curAu.setPicLatencyCount( 0 );
     2153
     2154
     2155      if ( m_auOutputFlag )
     2156      {
     2157        // for each access unit in the DPB
     2158        // that has at least one picture marked as "needed for output" and
     2159        // follows the current access unit in output order, the associated
     2160        // variable PicLatencyCount is set equal to PicLatencyCount + 1.
     2161
     2162        TComList<TComAu*> aus = m_dpb.getAusHavingPicsMarkedForOutput(); // <-- current AU is actually not yet in DPB, but this does not matter here.
     2163
     2164        for(TComList<TComAu*>::iterator itA= aus.begin(); ( itA!=aus.end()); itA++)
     2165        {
     2166          if( m_curAu.getPoc() < (*itA)->getPoc())
     2167          {
     2168            (*itA)->setPicLatencyCount( (*itA)->getPicLatencyCount() + 1 );
     2169          }
     2170        }
     2171      }
     2172    }
     2173  }
     2174}
     2175
     2176Void TAppDecTop::xF814decProcForCodPicWithLIdZero( DecProcPart curPart )
     2177{
     2178  ////////////////////////////////////////////////////////////////////////////////
     2179  // F.8.1.4 Decoding process for a coded picture with nuh_layer_id equal to 0
     2180  ////////////////////////////////////////////////////////////////////////////////
     2181
     2182  x813decProcForCodPicWithLIdZero( curPart );
     2183
     2184  if (curPart == START_PIC )
     2185  {
     2186    m_decProcPocAndRps = ANNEX_F;
     2187  }
     2188  else if (curPart == FINALIZE_PIC )
     2189  {
     2190    if ( !m_firstPicInLayerDecodedFlag[0] )
     2191    {
     2192      m_firstPicInLayerDecodedFlag[0] = true;
     2193    }
     2194  }
     2195}
     2196
     2197Void TAppDecTop::xF13521InitDpb()
     2198{
     2199  ////////////////////////////////////////////////////////////////////////////////
     2200  // F.13.5.2.1 General
     2201  ////////////////////////////////////////////////////////////////////////////////
     2202
     2203  const TComDpbSize* dpbSize = m_vps->getDpbSize();
     2204  m_maxNumReorderPics       = dpbSize->getMaxVpsNumReorderPics      ( m_targetOptLayerSetIdx, m_highestTid );
     2205  m_maxLatencyIncreasePlus1 = dpbSize->getMaxVpsLatencyIncreasePlus1( m_targetOptLayerSetIdx, m_highestTid );
     2206  m_maxLatencyValue         = dpbSize->getVpsMaxLatencyPictures     ( m_targetOptLayerSetIdx, m_highestTid );
     2207
     2208  for(Int i = 0; i < MAX_NUM_LAYER_IDS; i++)
     2209  {
     2210    m_maxDecPicBufferingMinus1[ i ] = MIN_INT;
     2211  }
     2212  for( Int i = 0; i <= m_vps->getMaxLayersMinus1(); i++ )
     2213  {
     2214    Int currLayerId = m_vps->getLayerIdInNuh( i );
     2215    for(Int layerIdx = 0 ; layerIdx < m_vps->getNumLayersInIdList( m_targetDecLayerSetIdx); layerIdx++ )
     2216    {
     2217      if( m_vps->getLayerSetLayerIdList( m_targetDecLayerSetIdx, layerIdx ) == currLayerId )
     2218      {
     2219        m_maxDecPicBufferingMinus1[currLayerId] = dpbSize->getMaxVpsDecPicBufferingMinus1( m_targetDecLayerSetIdx, layerIdx, m_highestTid );
     2220      }
     2221    }
     2222  }
     2223}
     2224
     2225Void TAppDecTop::xF13522OutputAndRemOfPicsFromDpb( Bool beforePocDerivation )
     2226{
     2227  ////////////////////////////////////////////////////////////////////////////////
     2228  // F.13.5.2.2 Output and removal of pictures from the DPB
     2229  ////////////////////////////////////////////////////////////////////////////////
     2230
     2231  if( beforePocDerivation )
     2232  {
     2233    // F.13.5.2.2
     2234    // Part before POC and RPS derivation.
     2235
     2236    if( m_curPic->getDecodingOrder() != 0 )
     2237    {
     2238      // When the current picture is not picture 0 in the current layer,
     2239      // the output and removal of pictures in the current layer, with nuh_layer_id equal to currLayerId,
     2240      // from the DPB before the decoding of the current picture, i.e., picture n, but after parsing the
     2241      // slice header of the first slice of the current picture and before the invocation of the decoding
     2242      // process for picture order count, happens instantaneously when the first decoding unit of the current
     2243      // picture is removed from the CPB and proceeds as follows:
     2244
     2245      if( m_curPic->getIsPocResettingPic() )
     2246      {
     2247        // When the current picture is a POC resetting picture, all pictures in the DPB that do
     2248        // not belong to the current access unit and that are marked as "needed for output" are
     2249        // output, starting with pictures with the smallest value of PicOrderCntVal of all pictures
     2250        // excluding those in the current access unit in the DPB, in ascending order of the PicOrderCntVal
     2251        // values, and pictures with the same value of PicOrderCntVal are output in ascending order
     2252        // of the nuh_layer_id values. When a picture is output, it is cropped using the conformance cropping
     2253        // window specified in the active SPS for the picture, the cropped picture is output, and
     2254        // the picture is marked as "not needed for output"
     2255
     2256        TComList<TComAu*>* aus = m_dpb.getAus(); // Theses are sorted by POC.
     2257        for (TComList<TComAu*>::iterator itA = aus->begin(); itA != aus->end(); itA++ )
     2258        {
     2259          //Pictures in AUs are sorted by nuh_layer_id;
     2260          for (TComAu::iterator itP = (*itA)->begin(); itP != (*itA)->end(); itP++ )
     2261          {
     2262            TComPic* pic = (*itP);
     2263            if ( !m_curAu.containsPic( pic ) )
     2264            {
     2265              xCropAndOutput( pic );
     2266              pic->setOutputMark( false );
     2267            }
     2268          }
     2269        }
     2270      }
     2271    }
     2272  }
     2273  else if ( !beforePocDerivation )
     2274  {
     2275    //  The variable listOfSubDpbsToEmpty is derived as follows:
     2276
     2277    Int nuhLayerId = m_curPic->getLayerId();
     2278    TComList<TComSubDpb*> listOfSubDpbsToEmpty;
     2279
     2280    if ( m_newVpsActivatedbyCurAu && ( m_curPic->isIrap()&& nuhLayerId == m_smallestLayerId
     2281      && m_curPic->getNoRaslOutputFlag() && m_curPic->getNoClrasOutputFlag() ) )
     2282    {
     2283      // If a new VPS is activated by the current access unit or the current picture is IRAP picture
     2284      // with nuh_layer_id equal to SmallestLayerId,   NoRaslOutputFlag equal to 1, and NoClrasOutputFlag equal to 1,
     2285      // listOfSubDpbsToEmpty is set equal to all the sub-DPBs.
     2286      listOfSubDpbsToEmpty = (*m_dpb.getSubDpbs());
     2287    }
     2288    else if (m_curPic->isIrap() && m_vps->getNumDirectRefLayers( nuhLayerId ) == 0 &&
     2289      nuhLayerId > m_smallestLayerId && m_curPic->getNoRaslOutputFlag() && m_layerResetFlag  )
     2290    {
     2291      // Otherwise, if the current picture is an IRAP picture with any nuh_layer_id value indepLayerId
     2292      // such that NumDirectRefLayers[ indepLayerId ] is equal to 0 and indepLayerId is greater than
     2293      // SmallestLayerId, and with NoRaslOutputFlag equal to 1, and LayerResetFlag is equal to 1,
     2294
     2295      // listOfSubDpbsToEmpty is set equal to the sub-DPBs containing the current layer and the sub-DPBs
     2296      // containing the predicted layers of the current layer.
     2297
     2298      listOfSubDpbsToEmpty.pushBack( m_dpb.getSubDpb( nuhLayerId, false  ) );
     2299      for( Int i = 0; i < m_vps->getNumPredictedLayers( nuhLayerId ); i++  )
     2300      {
     2301        listOfSubDpbsToEmpty.pushBack( m_dpb.getSubDpb( m_vps->getIdPredictedLayer( nuhLayerId, i), false  ) );
     2302      }
     2303    }
     2304    else
     2305    {
     2306      // Otherwise, crossLayerBufferEmptyFlag is set equal to 0.
     2307
     2308      // The SPEC seems to have an issue here. Use current subDpb as in form F.13.3.2
     2309      listOfSubDpbsToEmpty.pushBack( m_dpb.getSubDpb( nuhLayerId, false  ) );
     2310    }
     2311
     2312    // If the current picture is an IRAP picture with NoRaslOutputFlag equal to 1 and any of
     2313    // the following conditions is true:
     2314    //   - nuh_layer_id equal to SmallestLayerId,
     2315    //   - nuh_layer_id of the current layer is greater than SmallestLayerId, and NumDirectRefLayers[ nuh_layer_id ]
     2316    //     is equal to 0,
     2317
     2318    if ( m_curPic->isIrap() && m_curPic->getNoRaslOutputFlag() && (
     2319      ( nuhLayerId == m_smallestLayerId ) ||
     2320      ( ( nuhLayerId > m_smallestLayerId ) && m_vps->getNumDirectRefLayers( nuhLayerId ) == 0 ) )
     2321      )
     2322    {
     2323      // 1. The variable NoOutputOfPriorPicsFlag is derived for the decoder under test as follows:
     2324      Bool noOutputOfPriorPicsFlag;
     2325      if( m_curPic->isCra() )
     2326      {
     2327        noOutputOfPriorPicsFlag = true;
     2328        // - If the current picture is a CRA picture, NoOutputOfPriorPicsFlag is set equal to 1
     2329        // (regardless of the value of no_output_of_prior_pics_flag).
     2330      }
     2331      else if ( false )
     2332      {
     2333        // TBD
     2334        // - Otherwise, if the value of pic_width_in_luma_samples, pic_height_in_luma_samples,
     2335        //   chroma_format_idc, bit_depth_luma_minus8, bit_depth_chroma_minus8, separate_colour_plane_flag,
     2336        //   or sps_max_dec_pic_buffering_minus1[ HighestTid ] derived from the active SPS for the current
     2337        //   layer is different from the value of pic_width_in_luma_samples, pic_height_in_luma_samples,
     2338        //   chroma_format_idc, bit_depth_luma_minus8, bit_depth_chroma_minus8, separate_colour_plane_flag,
     2339        //   or sps_max_dec_pic_buffering_minus1[ HighestTid ], respectively, derived from the SPS that
     2340        //   was active for the current layer when decoding the preceding picture in the current layer,
     2341        //   NoOutputOfPriorPicsFlag may (but should not) be set equal to 1 by the decoder under test,
     2342        //   regardless of the value of no_output_of_prior_pics_flag.
     2343        //    NOTE - Although setting NoOutputOfPriorPicsFlag equal to no_output_of_prior_pics_flag is preferred
     2344        //    under these conditions, the decoder under test is allowed to set NoOutputOfPriorPicsFlag to 1 in this case.
     2345        // - Otherwise, NoOutputOfPriorPicsFlag is set equal to no_output_of_prior_pics_flag.
     2346
     2347        // assert( 1 );
     2348      }
     2349      else
     2350      {
     2351        // - Otherwise, NoOutputOfPriorPicsFlag is set equal to no_output_of_prior_pics_flag.
     2352        noOutputOfPriorPicsFlag = m_curPic->getSlice(0)->getNoOutputPriorPicsFlag();
     2353      }
     2354
     2355      // 2. The value of NoOutputOfPriorPicsFlag derived for the decoder under test is applied for the HRD as follows:
     2356      if ( !noOutputOfPriorPicsFlag )
     2357      {
     2358        // - If NoOutputOfPriorPicsFlag is equal to 0, all non-empty picture storage buffers in all the sub-DPBs included
     2359        //   in listOfSubDpbsToEmpty are output by repeatedly invoking the "bumping" process specified in clause
     2360        //   F.13.5.2.4 until all these pictures are marked as "not needed for output".
     2361
     2362        Bool repeat = true;
     2363        while (repeat )
     2364        {
     2365          Bool allPicsMarkedNotNeedForOutput = true;
     2366          for (TComList<TComSubDpb*>::iterator itS = listOfSubDpbsToEmpty.begin(); itS != listOfSubDpbsToEmpty.end() && allPicsMarkedNotNeedForOutput; itS++ )
     2367          {
     2368            allPicsMarkedNotNeedForOutput = allPicsMarkedNotNeedForOutput && ( (*itS)->areAllPicsMarkedNotNeedForOutput() );
     2369          }
     2370
     2371          if ( !allPicsMarkedNotNeedForOutput )
     2372          {
     2373            xF13524Bumping( m_dpb.getAusHavingPicsMarkedForOutput() );
     2374          }
     2375          else
     2376          {
     2377            repeat = false;
     2378          }
     2379        }
     2380      }
     2381      else
     2382      {
     2383        // - Otherwise (NoOutputOfPriorPicsFlag is equal to 1), all picture storage buffers containing a picture
     2384        //   that is marked as "not needed for output" and "unused for reference" are emptied (without output),
     2385        //   all pictures that are contained in a sub-DPB included in listOfSubDpbsToEmpty are emptied, and the sub-DPB
     2386        //   fullness of each sub-DPB is decremented by the number of picture storage buffers emptied in that sub-DPB.
     2387        m_dpb.emptyNotNeedForOutputAndUnusedForRef();
     2388
     2389        for( TComList<TComSubDpb*>::iterator iS = listOfSubDpbsToEmpty.begin(); iS != listOfSubDpbsToEmpty.end(); iS++)
     2390        {
     2391          m_dpb.emptySubDpbs( &listOfSubDpbsToEmpty );
     2392        }
     2393      }
     2394    }
     2395    else
     2396    {
     2397      // -  Otherwise, all picture storage buffers that contain a picture in the current layer and that are marked as
     2398      //   "not needed for output" and "unused for reference" are emptied (without output). For each picture storage buffer that is emptied,
     2399      //   the sub-DPB fullness is decremented by one.
     2400
     2401      m_dpb.emptySubDpbNotNeedForOutputAndUnusedForRef( nuhLayerId );
     2402
     2403      //    When one or more of the following conditions are true, the "bumping" process specified in clause F.13.5.2.4
     2404      //    is invoked repeatedly until none of the following conditions are true:
     2405
     2406      Bool repeat = true;
     2407      while ( repeat )
     2408      {
     2409        TComList<TComAu*> aus = m_dpb.getAusHavingPicsMarkedForOutput();
     2410
     2411        // The number of access units that contain at least one decoded picture in the DPB marked
     2412        // as "needed for output" is greater than MaxNumReorderPics.
     2413        Bool cond1 = ( aus.size() > m_maxNumReorderPics );
     2414
     2415        // MaxLatencyIncreasePlus1 is not equal to 0 and there is at least one access unit
     2416        // that contains at least one decoded picture in the DPB marked as "needed for output"
     2417        // for which the associated variable PicLatencyCount is greater than or equal to MaxLatencyValue.
     2418        Bool auWithGreaterLatencyCount = false;
     2419        for(TComList<TComAu*>::iterator itA= aus.begin(); ( itA!=aus.end()) && !auWithGreaterLatencyCount ; itA++)
     2420        {
     2421          if ( (*itA)->getPicLatencyCount() > m_maxLatencyValue )
     2422          {
     2423            auWithGreaterLatencyCount = true;
     2424          }
     2425        }
     2426
     2427        Bool cond2 = (m_maxLatencyIncreasePlus1 != 0 ) && auWithGreaterLatencyCount;
     2428
     2429        // The number of pictures in the sub-DPB is greater than or equal to MaxDecPicBufferingMinus1 + 1.
     2430        Bool cond3 = ( m_dpb.getSubDpb( nuhLayerId, false )->size() >= m_maxDecPicBufferingMinus1[ nuhLayerId ] + 1 );
     2431
     2432        if ( cond1  || cond2 || cond3 )
     2433        {
     2434          xF13524Bumping( aus );
     2435        }
     2436        else
     2437        {
     2438          repeat = false;
     2439        }
     2440      }
     2441    }
     2442  }
     2443}
     2444
     2445Void TAppDecTop::xF13523PicDecMarkAddBumpAndStor( Bool curPicIsLastInAu )
     2446{
     2447  ////////////////////////////////////////////////////////////////////////////////
     2448  // F.13.5.2.3 Picture decoding, marking, additional bumping and storage
     2449  ////////////////////////////////////////////////////////////////////////////////
     2450
     2451  const TComVPS* vps = m_curPic->getSlice(0)->getVPS();
     2452
     2453  // The current picture is considered as decoded after the last decoding unit of
     2454  // the picture is decoded. The current decoded picture is stored in an empty picture
     2455  // storage buffer in the sub-DPB.
     2456
     2457  m_dpb.addNewPic( m_curPic );
     2458
     2459  if ( curPicIsLastInAu )
     2460  {
     2461    // When the current picture is the last picture in an access unit, the following applies
     2462    // for each decoded picture with nuh_layer_id greater than or
     2463    // equal to ( vps_base_layer_internal_flag ? 0 : 1 ) of the access unit:
     2464
     2465    for( TComList<TComPic*>::iterator itP = m_curAu.begin(); itP != m_curAu.end(); itP++ )
     2466    {
     2467      TComPic* pic = (*itP);
     2468      if( pic->getLayerId() >= ( vps->getVpsBaseLayerInternalFlag() ? 0 : 1 ) )
     2469      {
     2470        if ( pic->getPicOutputFlag() )
     2471        {
     2472          //If the decoded picture has PicOutputFlag equal to 1, it is marked as "needed for output".
     2473          pic->setOutputMark( true );
     2474        }
     2475        else
     2476        {
     2477          // Otherwise it is marked as "not needed for output".
     2478          pic->setOutputMark( false );
     2479        }
     2480        // NOTE - Prior to investigating the conditions above, PicOutputFlag
     2481        // of each picture of the access unit is updated as specified in clause F.8.1.2.
     2482      }
     2483    }
     2484  }
     2485
     2486  // The current decoded picture is marked as "used for short-term reference".
     2487  m_curPic->markAsUsedForShortTermReference();
     2488
     2489
     2490  Bool repeat = true;
     2491  while ( repeat )
     2492  {
     2493    TComList<TComAu*> aus = m_dpb.getAusHavingPicsMarkedForOutput();
     2494
     2495    // When one or more of the following conditions are true,
     2496    // the "bumping" process specified in clause F.13.5.2.4 is invoked
     2497    // repeatedly until none of the following conditions are true:
     2498
     2499    // - The number of access units that contain at least one decoded picture in the DPB marked
     2500    //   as "needed for output" is greater than MaxNumReorderPics.
     2501    Bool cond1 = ( aus.size() > m_maxNumReorderPics );
     2502
     2503    // - MaxLatencyIncreasePlus1 is not equal to 0 and there is at least one access unit
     2504    //   that contains at least one decoded picture in the DPB marked as "needed for output"
     2505    //   for which the associated variable PicLatencyCount is greater than or equal to MaxLatencyValue.
     2506    Bool auWithGreaterLatencyCount = false;
     2507    for(TComList<TComAu*>::iterator itA= aus.begin(); ( itA!=aus.end()) && !auWithGreaterLatencyCount ; itA++)
     2508    {
     2509      if ( (*itA)->getPicLatencyCount() > m_maxLatencyValue )
     2510      {
     2511        auWithGreaterLatencyCount = true;
     2512      }
     2513    }
     2514
     2515    Bool cond2 = (m_maxLatencyIncreasePlus1 != 0 ) && auWithGreaterLatencyCount;
     2516
     2517    if ( cond1  || cond2 )
     2518    {
     2519      xF13524Bumping( aus );
     2520    }
     2521    else
     2522    {
     2523      repeat = false;
     2524    }
     2525  }
     2526}
     2527
     2528Void TAppDecTop::xF13524Bumping( TComList<TComAu*> aus )
     2529{
     2530  ////////////////////////////////////////////////////////////////////////////////
     2531  // F.13.5.2.4 "Bumping" process
     2532  ////////////////////////////////////////////////////////////////////////////////
     2533
     2534  // The picture or pictures that are first for output are selected as the ones having the
     2535  // smallest value of PicOrderCntVal of all pictures in the DPB marked as "needed for output".
     2536
     2537  assert( !aus.empty() );
     2538
     2539  // Create copy, since original AU from DBP is modified when removing pic.
     2540  TComAu auWithSmallestPoc = *((*aus.begin())); // List is sorted, hence the AU with smallest POC is the first.
     2541
     2542  for(TComAu::iterator itP= auWithSmallestPoc.begin(); ( itP!=auWithSmallestPoc.end() ); itP++)
     2543  {
     2544    TComPic* pic = (*itP);
     2545
     2546    if (pic->getOutputMark() )
     2547    {
     2548      // Each of these pictures is, in ascending nuh_layer_id order, cropped,
     2549      // using the conformance cropping window specified in the active SPS for the picture,
     2550      // the cropped picture is output, and the picture is marked as "not needed for output".
     2551
     2552      // pictures are sorted in the AU in ascending nuh_layer_id order.
     2553
     2554
     2555      xCropAndOutput( pic );
     2556      pic->setOutputMark( false );
     2557
     2558      // Each picture storage buffer that contains a picture marked as "unused for reference"
     2559      // and that was one of the pictures cropped and output is emptied and the fullness of
     2560      // the associated sub-DPB is decremented by one.
     2561
     2562      if (pic->getMarkedUnUsedForReference() )
     2563      {
     2564        m_dpb.removePic( pic );
     2565      }
     2566    }
     2567  }
     2568}
     2569
     2570Void TAppDecTop::xF816decProcEndDecOfCodPicLIdGrtZero()
     2571{
     2572  ////////////////////////////////////////////////////////////////////////////////
     2573  // F.8.1.6  Decoding process for ending the decoding of a coded picture with nuh_layer_id greater than 0
     2574  ////////////////////////////////////////////////////////////////////////////////
     2575
     2576  const TComSlice* slice = m_curPic->getSlice( 0 );
     2577  const Int nuhLayerId   = m_curPic->getLayerId();
     2578
     2579  assert(  nuhLayerId != 0 );
     2580
     2581  //The marking of decoded pictures is modified as specified in the following:
     2582  for (Int i = 0; i < m_curPic->getDecodedRps()->m_numActiveRefLayerPics0;i++ )
     2583  {
     2584    m_curPic->getDecodedRps()->m_refPicSetInterLayer0[i]->markAsUsedForShortTermReference();
     2585  }
     2586
     2587  for (Int i = 0; i < m_curPic->getDecodedRps()->m_numActiveRefLayerPics1;i++ )
     2588  {
     2589    m_curPic->getDecodedRps()->m_refPicSetInterLayer1[i]->markAsUsedForShortTermReference();
     2590  }
     2591
     2592  // PicOutputFlag is set as follows:
     2593  if ( !m_layerInitilizedFlag[ nuhLayerId ] )
     2594  {
     2595    // - If LayerInitializedFlag[ nuh_layer_id ] is equal to 0, PicOutputFlag is set equal to 0.
     2596    m_curPic->setPicOutputFlag( false );
     2597  }
     2598  else if (m_curPic->isRasl( ) && m_noRaslOutputFlagAssocIrap[ nuhLayerId] )
     2599  {
     2600    // - Otherwise, if the current picture is a RASL picture and NoRaslOutputFlag of the associated IRAP picture is equal to 1,
     2601    //   PicOutputFlag is set equal to 0.
     2602
     2603    m_curPic->setPicOutputFlag( false );
     2604  }
     2605  else
     2606  {
     2607    // - Otherwise, PicOutputFlag is set equal to pic_output_flag.
     2608    m_curPic->setPicOutputFlag( slice->getPicOutputFlag() );
     2609  }
     2610
     2611  // The decoded picture is marked as "used for short-term reference".
     2612  m_curPic->markAsUsedForShortTermReference();
     2613
     2614  if ( !m_firstPicInLayerDecodedFlag[ nuhLayerId ] )
     2615  {
     2616    // When FirstPicInLayerDecodedFlag[ nuh_layer_id ] is equal to 0, FirstPicInLayerDecodedFlag[ nuh_layer_id ] is set equal to 1.
     2617    m_firstPicInLayerDecodedFlag[ nuhLayerId ] = true;
     2618  }
     2619}
     2620
     2621TDecTop* TAppDecTop::xGetDecoder( InputNALUnit& nalu )
     2622{
     2623  return m_tDecTop[ xGetDecoderIdx( nalu.m_nuhLayerId )];
     2624}
     2625
     2626
    10522627Int TAppDecTop::xGetDecoderIdx( Int layerId, Bool createFlag /*= false */ )
    10532628{
    1054   Int decIdx = -1; 
    1055 
    1056   if ( layerId > MAX_NUM_LAYER_IDS-1 ) 
    1057   {
    1058     return decIdx; 
    1059   }
    1060 
    1061   if ( m_layerIdToDecIdx[ layerId ] != -1 ) 
    1062   {     
    1063     decIdx = m_layerIdToDecIdx[ layerId ]; 
     2629  Int decIdx = -1;
     2630
     2631  if ( layerId > MAX_NUM_LAYER_IDS-1 )
     2632  {
     2633    return decIdx;
     2634  }
     2635
     2636  if ( m_layerIdToDecIdx[ layerId ] != -1 )
     2637  {
     2638    decIdx = m_layerIdToDecIdx[ layerId ];
    10642639  }
    10652640  else
    1066   {     
    1067     assert ( createFlag ); 
    1068     assert( m_numDecoders < MAX_NUM_LAYERS ); 
    1069 
    1070     decIdx = m_numDecoders; 
     2641  {
     2642    assert ( createFlag );
     2643    assert( m_numDecoders < MAX_NUM_LAYERS );
     2644
     2645    decIdx = m_numDecoders;
    10712646
    10722647    // Init decoder
     
    10762651    m_tDecTop[ decIdx ]->setLayerId( layerId );
    10772652    m_tDecTop[ decIdx ]->setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
    1078     m_tDecTop[ decIdx ]->setIvPicLists( &m_ivPicLists );
    1079     m_tDecTop[ decIdx ]->setLayerInitilizedFlags( m_layerInitilizedFlags );
    1080     m_tDecTop[ decIdx ]->setTargetOlsIdx( m_targetOptLayerSetIdx );   
     2653    m_tDecTop[ decIdx ]->setDpb( &m_dpb );
     2654    m_tDecTop[ decIdx ]->setTargetOlsIdx( m_targetOptLayerSetIdx );
     2655    m_tDecTop[ decIdx ]->setFirstPicInLayerDecodedFlag( m_firstPicInLayerDecodedFlag );
     2656    m_tDecTop[ decIdx ]->setPocDecrementedInDPBFlag   ( m_pocDecrementedInDpbFlag    );
     2657    m_tDecTop[ decIdx ]->setLastPresentPocResetIdc    ( m_lastPresentPocResetIdc );
     2658
     2659
    10812660#if O0043_BEST_EFFORT_DECODING
    10822661    m_cTDecTop[ decIdx ]->setForceDecodeBitDepth(m_forceDecodeBitDepth);
     
    10912670#endif
    10922671
    1093     // append pic list of new decoder to PicLists
    1094     assert( m_ivPicLists.size() == m_numDecoders );
    1095     m_ivPicLists.push_back( m_tDecTop[ decIdx ]->getListPic() );
    1096 
    1097     // create recon file related stuff     
     2672    // append pic list of new decoder to PicLists
     2673
     2674    // create recon file related stuff
    10982675    Char* pchTempFilename = NULL;
    10992676    if ( m_pchReconFile )
    1100     {     
    1101       Char buffer[4];     
     2677    {
     2678      Char buffer[4];
    11022679      sprintf(buffer,"_%i", layerId );
    1103       assert ( m_pchReconFile ); 
     2680      assert ( m_pchReconFile );
    11042681      xAppendToFileNameEnd( m_pchReconFile , buffer, pchTempFilename );
    11052682      assert( m_pchReconFiles.size() == m_numDecoders );
    11062683    }
    11072684
    1108     m_pchReconFiles.push_back( pchTempFilename );   
     2685    m_pchReconFiles.push_back( pchTempFilename );
    11092686
    11102687    m_tVideoIOYuvReconFile[ decIdx ] = new TVideoIOYuv;
    11112688    m_reconOpen           [ decIdx ] = false;
    11122689
    1113     // set others
    1114     m_pocLastDisplay      [ decIdx ] = -MAX_INT;
    1115     m_layerIdToDecIdx     [ layerId ] = decIdx;
    1116 
    1117     m_numDecoders++;
     2690    // set others
     2691    m_layerIdToDecIdx     [ layerId ] = decIdx;
     2692
     2693    m_numDecoders++;
    11182694  };
    11192695  return decIdx;
     
    11212697}
    11222698
    1123 Void TAppDecTop::xMarkForOutput( Bool allLayersDecoded, Int pocLastPic, Int layerIdLastPic )
     2699Int TAppDecTop::xPreDecodePoc( InputNALUnit& nalu )
    11242700
    1125   vector<Int> targetOptLayerIdList = m_vps->getTargetOptLayerIdList( m_targetOptLayerSetIdx );
    1126 
    1127   if (m_vps->getAltOutputLayerFlagVar( m_targetOptLayerSetIdx ) )
    1128   {
    1129     assert( targetOptLayerIdList.size() == 1 );
    1130     Int targetLayerId = targetOptLayerIdList[0];     
    1131 
    1132     TComPic* curPic = m_ivPicLists.getPic( layerIdLastPic, pocLastPic );
    1133     assert( curPic != NULL );
    1134 
    1135     if ( layerIdLastPic == targetLayerId )
    1136     {
    1137       if ( curPic->getPicOutputFlag() )
    1138       {
    1139         curPic->setOutputMark( true );
     2701  // - 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
     2702  // - F.8.1.3 needs to know if the current picture is the first of an AU
     2703  //   actually before its POC has been decoded.
     2704
     2705  // Thus, in the software implementation the processes can not be invoked in the same order as in the Spec.
     2706  // For this, this function decodes the POC before invoking F.8.1.3. However, this is done without
     2707  // altering member variables
     2708
     2709  // Do some stuff from F.8.1.3 required for POC derivation, which is not depending on AU detection.
     2710  TDecTop* dec          = xGetDecoder( nalu );
     2711  TComSlice* slicePilot = dec->getSlicePilot();
     2712  Int nuhLayerId        = nalu.m_nuhLayerId;
     2713  Int smallestLayerId   = dec->getSmallestLayerId();
     2714
     2715  Int handleCraAsBlaFlag;
     2716  if ( nalu.isIrap() )
     2717  {
     2718    if ( !m_handleCraAsBlaFlagSetByExtMeans )
     2719    {
     2720      handleCraAsBlaFlag = false;
     2721    }
     2722  }
     2723
     2724  Bool firstPicInLayerDecodedFlag = m_firstPicInLayerDecodedFlag[ nalu.m_nuhLayerId ];
     2725 
     2726  if ( nalu.isIrap() && nuhLayerId == smallestLayerId )
     2727  {
     2728    Int noClrasOutputFlag;
     2729    if( m_firstSliceInBitstream )
     2730    {
     2731      noClrasOutputFlag = true;
     2732    }
     2733    else if( m_eosInLayer[ 0 ] || m_eosInLayer[ nuhLayerId ] )
     2734    {
     2735      noClrasOutputFlag = true;
     2736    }
     2737    else if ( nalu.isBla() || (nalu.isCra() && handleCraAsBlaFlag ))
     2738    {
     2739      noClrasOutputFlag = true;
     2740    }
     2741    else if ( nalu.isIdr() && slicePilot->getCrossLayerBlaFlag() )
     2742    {
     2743      noClrasOutputFlag = true;
     2744    }
     2745    else if ( m_noClrasOutputFlagSetByExtMeans )
     2746    {
     2747      noClrasOutputFlag = m_noClrasOutputFlag;
     2748    }
     2749    else
     2750    {     
     2751      noClrasOutputFlag  = false;
     2752    }
     2753
     2754    if( noClrasOutputFlag )
     2755    {
     2756      firstPicInLayerDecodedFlag = false;
     2757    }   
     2758  }
     2759
     2760  // Derive POC
     2761  return dec->preDecodePoc(firstPicInLayerDecodedFlag, m_newPicIsFstPicOfAllLayOfPocResetPer, m_newPicIsPocResettingPic );
     2762}
     2763
     2764Bool TAppDecTop::xDetectNewAu( InputNALUnit& nalu )
     2765{
     2766  TDecTop*        dec        = xGetDecoder( nalu );
     2767  TComSlice*      slicePilot = dec->getSlicePilot();
     2768  const TComVPS*  vps        = slicePilot->getVPS();
     2769
     2770  Bool firstVclNaluOfAu;
     2771
     2772  if (m_curPic == NULL )
     2773  {
     2774    // No picture decoded yet, so we have a new AU.
     2775    firstVclNaluOfAu = true;
     2776  }
     2777  else
     2778  {
     2779    if ( !vps->getVpsExtensionFlag() )
     2780    {
     2781      // Decoding according to clause 8, hence one pic per AU.
     2782      firstVclNaluOfAu = slicePilot->getFirstSliceSegementInPicFlag();
     2783    }
     2784    else
     2785    {
     2786      if ( dec->getTargetOlsIdx() == 0 )
     2787      {
     2788        // Only the base layer is decoded, hence one pic per AU.
     2789        firstVclNaluOfAu = slicePilot->getFirstSliceSegementInPicFlag();
    11402790      }
    11412791      else
    1142       {       
    1143         xMarkAltOutPic( targetLayerId, pocLastPic );
    1144       }
    1145       m_markedForOutput = true;
    1146     }
    1147     else if ( ( layerIdLastPic > targetLayerId || allLayersDecoded ) && !m_markedForOutput )
    1148     {
    1149       xMarkAltOutPic( targetLayerId, pocLastPic );
    1150     }
    1151 
    1152     if ( allLayersDecoded )
    1153     {
    1154       m_markedForOutput = false;
    1155     }
     2792      {
     2793        // F.7.4.2.4.4  Order of NAL units and coded pictures and association to access units   
     2794        //  An access unit consists of one or more coded pictures, each with a distinct value of
     2795        //  nuh_layer_id, and zero or more non-VCL NAL units.
     2796
     2797        //  A VCL NAL unit is the first VCL NAL unit of an access unit, when all of the following conditions are true:
     2798        //  -  first_slice_segment_in_pic_flag is equal to 1.
     2799        //  -  At least one of the following conditions is true:
     2800        //     - The previous picture in decoding order belongs to a different POC resetting period
     2801        //       than the picture containing the VCL NAL unit.
     2802        Bool prevPicDiffPocResetPeriod = m_newPicIsFstPicOfAllLayOfPocResetPer;
     2803
     2804        //     - PicOrderCntVal derived for the VCL NAL unit differs from the PicOrderCntVal of the
     2805        //       previous picture in decoding order.
     2806        Bool prevPicDiffPoc = ( xPreDecodePoc( nalu ) != m_curPic->getPOC() );
     2807
     2808        if( slicePilot->getFirstSliceSegementInPicFlag() && ( prevPicDiffPocResetPeriod || prevPicDiffPoc ) )
     2809        {
     2810          firstVclNaluOfAu = true;
     2811        }
     2812        else
     2813        {
     2814          firstVclNaluOfAu = false;
     2815        }
     2816      }
     2817    }
     2818  }
     2819  return firstVclNaluOfAu;
     2820}
     2821
     2822Void TAppDecTop::xDetectNewPocResettingPeriod( InputNALUnit& nalu )
     2823{
     2824  TDecTop* dec  = xGetDecoder( nalu );
     2825  dec->inferPocResetPeriodId();
     2826
     2827
     2828  Int pocResetIdc         = dec->getSlicePilot()->getPocResetIdc();
     2829  Int newPocResetPeriodId = dec->getSlicePilot()->getPocResetPeriodId();
     2830
     2831  Int curPocResetPeriodId = ( m_curPic != NULL)  ? m_curPic->getPocResetPeriodId() : MIN_INT;
     2832
     2833  // Check if new picture starts a new poc resetting period.
     2834  if(  ( pocResetIdc == 1 || pocResetIdc == 2 ) &&  ( curPocResetPeriodId != newPocResetPeriodId ) )
     2835  {
     2836    for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++ )
     2837    {
     2838      m_firstPicInPocResettingPeriodReceived[ i ] = false;
     2839    }
     2840    m_newPicIsFstPicOfAllLayOfPocResetPer = true;
    11562841  }
    11572842  else
    1158   {
    1159     for( Int dI = 0; dI < m_numDecoders; dI++ )
    1160     {     
    1161       Int layerId = m_tDecTop[dI]->getLayerId();
    1162       TComPic* curPic = m_ivPicLists.getPic( layerId, pocLastPic );
    1163       if ( curPic != NULL )
    1164       {
    1165         if ( curPic->getReconMark() )
    1166         {
    1167           Bool isTargetOptLayer = std::find(targetOptLayerIdList.begin(), targetOptLayerIdList.end(), layerId) != targetOptLayerIdList.end();
    1168           curPic->setOutputMark( isTargetOptLayer ? curPic->getPicOutputFlag() : false );
    1169         }
    1170       }
    1171     }
    1172   }
    1173 }
    1174 
    1175 Void TAppDecTop::xMarkAltOutPic( Int targetOutputLayer, Int pocLastPic )
    1176 {
    1177   Int optLayerIdxInVps = m_vps->getLayerIdInNuh( targetOutputLayer );
    1178   Int highestNuhLayerId = -1;
    1179   TComPic* picWithHighestNuhLayerId = NULL;
    1180   for (Int dIdx = 0; dIdx < m_numDecoders; dIdx++)
    1181   {
    1182     Int curLayerId = m_tDecTop[dIdx]->getLayerId();
    1183     Int curLayerIdxInVps = m_vps->getLayerIdInNuh( curLayerId  );
    1184     if ( m_vps->getDependencyFlag(optLayerIdxInVps, curLayerIdxInVps ) )
    1185     {
    1186       TComPic* curPic = m_ivPicLists.getPic( curLayerId, pocLastPic );
    1187       if (curPic != NULL)
    1188       {
    1189         if (curPic->getReconMark() && curPic->getPicOutputFlag() )
    1190         {
    1191           curPic->setOutputMark   ( false );
    1192           curPic->setPicOutputFlag( false );
    1193           if ( curLayerId > highestNuhLayerId)
    1194           {
    1195             highestNuhLayerId = curLayerId ;
    1196             picWithHighestNuhLayerId = curPic;
    1197           }           
    1198         }
    1199       }
    1200     }
    1201   }
    1202   if ( picWithHighestNuhLayerId != NULL )
    1203   {
    1204     picWithHighestNuhLayerId->setPicOutputFlag(true);
    1205     picWithHighestNuhLayerId->setOutputMark   (true);
    1206   }
     2843  {
     2844    m_newPicIsFstPicOfAllLayOfPocResetPer = false;
     2845  }
     2846
     2847  // Check if current picture is a poc resetting picture (thus the first picture of this layer within the POC resetting period.
     2848  if ( !m_firstPicInPocResettingPeriodReceived[ nalu.m_nuhLayerId ] )
     2849  {
     2850    m_newPicIsPocResettingPic = true;
     2851    m_firstPicInPocResettingPeriodReceived[ nalu.m_nuhLayerId ] = true;
     2852  }
     2853  else
     2854  {
     2855    m_newPicIsPocResettingPic = false;
     2856  }
     2857
     2858}
     2859
     2860Bool TAppDecTop::xAllRefLayersInitilized( Int curLayerId )
     2861{
     2862  Bool allRefLayersInitilizedFlag = true;
     2863  for (Int i = 0; i < m_vps->getNumDirectRefLayers( curLayerId  ); i++ )
     2864  {
     2865    Int refLayerId = m_vps->getIdDirectRefLayer( curLayerId, i );
     2866    allRefLayersInitilizedFlag = allRefLayersInitilizedFlag && m_layerInitilizedFlag[ refLayerId ];
     2867  }
     2868
     2869  return allRefLayersInitilizedFlag;
     2870}
     2871
     2872Void TAppDecTop::xInitFileIO()
     2873{
     2874  m_bitstreamFile.open(m_pchBitstreamFile, ifstream::in | ifstream::binary);
     2875
     2876  if ( !m_bitstreamFile)
     2877  {
     2878    fprintf(stderr, "\nUnable to open bitstream file `%s' for reading\n", m_pchBitstreamFile);
     2879    exit(EXIT_FAILURE);
     2880  }
     2881
     2882  if (!m_outputDecodedSEIMessagesFilename.empty() && m_outputDecodedSEIMessagesFilename!="-")
     2883  {
     2884    m_seiMessageFileStream.open(m_outputDecodedSEIMessagesFilename.c_str(), std::ios::out);
     2885    if (!m_seiMessageFileStream.is_open() || !m_seiMessageFileStream.good())
     2886    {
     2887      fprintf(stderr, "\nUnable to open file `%s' for writing decoded SEI messages\n", m_outputDecodedSEIMessagesFilename.c_str());
     2888      exit(EXIT_FAILURE);
     2889    }
     2890  }
     2891
     2892#if NH_3D
     2893  if( m_pchScaleOffsetFile )
     2894  {
     2895    m_pScaleOffsetFile = ::fopen( m_pchScaleOffsetFile, "wt" );
     2896    if (!m_pScaleOffsetFile)
     2897    {
     2898      fprintf(stderr, "\nUnable to open file `%s' for writing decoded Camera Parameters messages\n", m_pchScaleOffsetFile);
     2899      exit(EXIT_FAILURE);
     2900    }
     2901  }
     2902#endif
     2903}
     2904
     2905Void TAppDecTop::xOpenReconFile( TComPic* curPic )
     2906{
     2907  Int decIdx = xGetDecoderIdx( curPic->getLayerId() );
     2908
     2909  if ( m_pchReconFile && !m_reconOpen[decIdx] )
     2910  {
     2911    const BitDepths &bitDepths= curPic->getPicSym()->getSPS().getBitDepths(); // use bit depths of first reconstructed picture.
     2912    for (UInt channelType = 0; channelType < MAX_NUM_CHANNEL_TYPE; channelType++)
     2913    {
     2914      if (m_outputBitDepth[channelType] == 0)
     2915      {
     2916        m_outputBitDepth[channelType] = bitDepths.recon[channelType];
     2917      }
     2918    }
     2919
     2920    m_tVideoIOYuvReconFile[decIdx]->open( m_pchReconFiles[decIdx], true, m_outputBitDepth, m_outputBitDepth, bitDepths.recon ); // write mode
     2921    m_reconOpen[decIdx] = true;
     2922  }
     2923}
     2924
     2925Void TAppDecTop::xFlushOutput()
     2926{
     2927  Bool repeat = true;
     2928  while ( repeat )
     2929  {
     2930    if( m_decProcCvsg == ANNEX_F )
     2931    {
     2932      TComList<TComAu*> aus = m_dpb.getAusHavingPicsMarkedForOutput();
     2933      if ( !aus.empty() )
     2934      {
     2935        xF13524Bumping( aus );
     2936      }     
     2937      else
     2938      {
     2939        repeat = false;
     2940      }
     2941    }     
     2942    else if( m_decProcCvsg == CLAUSE_8 )
     2943    {
     2944      TComList<TComPic*> picsMarkedForOutput = m_dpb.getSubDpb( 0, false )->getPicsMarkedNeedForOutput();
     2945      if (!picsMarkedForOutput.empty())
     2946      {
     2947        xC524Bumping();
     2948      }
     2949      else
     2950      {
     2951        repeat = false;
     2952      }
     2953    }
     2954  }
     2955}
     2956
     2957Void TAppDecTop::xCropAndOutput( TComPic* curPic )
     2958{
     2959
     2960  if ( m_printPicOutput )
     2961  {
     2962    std::cout << "  Output picture: ";
     2963    curPic->print( 2 );
     2964    std::cout << std::endl;
     2965  }
     2966
     2967  assert( !curPic->getHasGeneratedRefPics() );
     2968  assert( !curPic->getIsGenerated()         );
     2969
     2970  Int decIdx = xGetDecoderIdx( curPic->getLayerId() );
     2971
     2972  if (!m_reconOpen[ decIdx ])
     2973  {
     2974    xOpenReconFile( curPic );
     2975  }
     2976
     2977  if ( m_pchReconFiles[ decIdx ] )
     2978  {
     2979    const Window &conf    = curPic->getConformanceWindow();
     2980    const Window  defDisp = m_respectDefDispWindow ? curPic->getDefDisplayWindow() : Window();
     2981
     2982    assert( conf   .getScaledFlag() );
     2983    assert( defDisp.getScaledFlag() );
     2984
     2985    m_tVideoIOYuvReconFile[decIdx]->write( curPic->getPicYuvRec(),
     2986      m_outputColourSpaceConvert,
     2987      conf.getWindowLeftOffset()   + defDisp.getWindowLeftOffset(),
     2988      conf.getWindowRightOffset()  + defDisp.getWindowRightOffset(),
     2989      conf.getWindowTopOffset()    + defDisp.getWindowTopOffset(),
     2990      conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(),
     2991#if NH_3D
     2992      m_depth420OutputFlag && curPic->getIsDepth() ? CHROMA_420 : NUM_CHROMA_FORMAT
     2993#else
     2994      NUM_CHROMA_FORMAT
     2995#endif
     2996      , m_bClipOutputVideoToRec709Range);
     2997  }
     2998}
     2999
     3000UInt TAppDecTop::getNumberOfChecksumErrorsDetected() const
     3001{
     3002  UInt numOfChecksumErrors = 0;
     3003  for (Int i = 0; i < m_numDecoders; i++ )
     3004  {
     3005    numOfChecksumErrors += getNumberOfChecksumErrorsDetected( i );
     3006  }
     3007  return numOfChecksumErrors;
    12073008}
    12083009
  • branches/HTM-15.0-dev0/source/App/TAppDecoder/TAppDecTop.h

    r1313 r1317  
    6060{
    6161private:
    62   // class interface
     62  // class interface 
    6363#if NH_MV
    6464  TDecTop*                        m_tDecTop             [ MAX_NUM_LAYERS ];    ///< decoder classes
    6565  TVideoIOYuv*                    m_tVideoIOYuvReconFile[ MAX_NUM_LAYERS ];    ///< reconstruction YUV class
    66   Int                             m_layerIdToDecIdx     [ MAX_NUM_LAYER_IDS ]; ///< maping from layer id to decoder index
     66  Int                             m_layerIdToDecIdx     [ MAX_NUM_LAYER_IDS ]; ///< mapping from layer id to decoder index
    6767  Int                             m_numDecoders;                               ///< number of decoder instances
    68   TComPicLists                    m_ivPicLists;                                ///< picture buffers of decoder instances
    69   Bool                            m_layerInitilizedFlags[ MAX_NUM_LAYER_IDS ]; ///< for layerwise startup
     68  TComPicLists                    m_dpb;                                       ///< picture buffers of decoder instances
     69
     70  TComPic*                        m_curPic;                                    ///< currently decoded picture
     71  TComAu                          m_curAu;                                     ///< currently decoded Au
     72 
     73  // Random access related
     74  Bool                            m_handleCraAsBlaFlag;
     75  Bool                            m_handleCraAsBlaFlagSetByExtMeans;
     76  Bool                            m_noClrasOutputFlag;
     77  Bool                            m_noClrasOutputFlagSetByExtMeans;
     78  Bool                            m_noRaslOutputFlagAssocIrap           [ MAX_NUM_LAYER_IDS ];
     79
     80  // Layer wise startup
     81  Bool                            m_firstPicInLayerDecodedFlag          [ MAX_NUM_LAYER_IDS ];
     82  Bool                            m_layerInitilizedFlag                 [ MAX_NUM_LAYER_IDS ];
     83  Bool                            m_layerResetFlag;
     84
     85  // DPB related variables
     86  Int                             m_maxNumReorderPics;
     87  Int                             m_maxLatencyIncreasePlus1;
     88  Int                             m_maxLatencyValue;
     89  Int                             m_maxDecPicBufferingMinus1            [ MAX_NUM_LAYER_IDS ];
     90
     91  // Poc resetting
     92  Int                             m_lastPresentPocResetIdc              [ MAX_NUM_LAYER_IDS ];
     93  Bool                            m_firstPicInPocResettingPeriodReceived[ MAX_NUM_LAYER_IDS ];
     94  Bool                            m_pocDecrementedInDpbFlag             [ MAX_NUM_LAYER_IDS ];
     95  Bool                            m_newPicIsFstPicOfAllLayOfPocResetPer;
     96  Bool                            m_newPicIsPocResettingPic;
     97
     98  // General decoding state
     99  Bool                            m_newVpsActivatedbyCurAu;
     100  Bool                            m_newVpsActivatedbyCurPic;
     101  Bool                            m_eosInLayer                          [ MAX_NUM_LAYER_IDS ];
     102  Bool                            m_initilizedFromVPS;
     103  Bool                            m_firstSliceInBitstream;
     104  UInt64                          m_decodingOrder                       [ MAX_NUM_LAYER_IDS ];
     105  UInt64                          m_totalNumofPicsReceived;
     106  Bool                            m_cvsStartFound;
     107  Int                             m_smallestLayerId;
     108
     109  // Decoding processes for current  picture
     110  DecodingProcess                 m_decProcPocAndRps;
     111  DecodingProcess                 m_decProcCvsg;
     112 
     113  // Active parameter sets
     114  const TComPPS*                  m_pps;                                ///< active PPS
     115  const TComSPS*                  m_sps;                                ///< active SPS
    70116  const TComVPS*                  m_vps;                                ///< active VPS
     117
     118  Bool                            m_reconOpen           [ MAX_NUM_LAYERS ]; ///< reconstruction file opened
     119#if NH_3D
     120  FILE*                           m_pScaleOffsetFile;
     121  CamParsCollector                m_cCamParsCollector;
     122#endif
    71123#else
    72124  TDecTop                         m_cTDecTop;                     ///< decoder class
    73125  TVideoIOYuv                     m_cTVideoIOYuvReconFile;        ///< reconstruction YUV class
    74 #endif
    75126  // for output control
    76 #if NH_MV
    77   Int                             m_pocLastDisplay      [ MAX_NUM_LAYERS ]; ///< last POC in display order
    78   Bool                            m_reconOpen           [ MAX_NUM_LAYERS ]; ///< reconstruction file opened
    79   Bool                            m_markedForOutput;
    80 #else
    81127  Int                             m_iPOCLastDisplay;              ///< last POC in display order
    82128#endif
    83   std::ofstream                   m_seiMessageFileStream;         ///< Used for outputing SEI messages.
    84 
    85 #if NH_3D
    86   FILE*                           m_pScaleOffsetFile;
    87   CamParsCollector                m_cCamParsCollector;
    88 #endif
     129  std::ofstream                   m_seiMessageFileStream;         ///< Used for outputing SEI messages. 
    89130public:
    90131  TAppDecTop();
     
    95136  Void  decode            (); ///< main decoding function
    96137#if NH_MV
    97   UInt  getNumberOfChecksumErrorsDetected( ) const
    98   {
    99     UInt numOfChecksumErrors = 0;
    100     for (Int i = 0; i < m_numDecoders; i++ )
    101     {
    102       numOfChecksumErrors += getNumberOfChecksumErrorsDetected( i );
    103     }
    104     return numOfChecksumErrors;
    105   }
    106 
     138  UInt  getNumberOfChecksumErrorsDetected( ) const;
    107139  UInt  getNumberOfChecksumErrorsDetected( Int decIdx ) const { return m_tDecTop[decIdx]->getNumberOfChecksumErrorsDetected(); }
    108 
    109140#else
    110141  UInt  getNumberOfChecksumErrorsDetected() const { return m_cTDecTop.getNumberOfChecksumErrorsDetected(); }
     
    112143
    113144protected:
     145
    114146  Void  xCreateDecLib     (); ///< create internal classes
    115147  Void  xDestroyDecLib    (); ///< destroy internal classes
    116148  Void  xInitDecLib       (); ///< initialize decoder class
    117149
    118 #if NH_MV
    119   Void  xWriteOutput      ( TComList<TComPic*>* pcListPic, Int layerId, Int tId ); ///< write YUV to file
    120 
    121   Void  xMarkForOutput   ( Bool allLayersDecoded, Int pocLastPic, Int layerIdLastPic );         
    122   Void  xMarkAltOutPic    ( Int targetOutputLayer, Int pocLastPic );
    123 
    124   Void  xFlushOutput      ( TComList<TComPic*>* pcListPic, Int layerId ); ///< flush all remaining decoded pictures to file
    125   Int   xGetDecoderIdx    ( Int layerId, Bool createFlag = false );
    126 #else
     150#if !NH_MV
    127151  Void  xWriteOutput      ( TComList<TComPic*>* pcListPic , UInt tId); ///< write YUV to file
    128152  Void  xFlushOutput      ( TComList<TComPic*>* pcListPic ); ///< flush all remaining decoded pictures to file
    129 #endif
    130   Bool  isNaluWithinTargetDecLayerIdSet ( InputNALUnit* nalu ); ///< check whether given Nalu is within targetDecLayerIdSet
     153  Bool  isNaluWithinTargetDecLayerIdSet    ( InputNALUnit* nalu ); ///< check whether given Nalu is within targetDecLayerIdSet
     154
     155#else
     156  // Process NAL units
     157  Bool xExtractAndRewrite                  ( InputNALUnit* nalu );
     158  Void xProcessVclNalu                     ( InputNALUnit nalu );
     159  Bool xIsSkipVclNalu                      ( InputNALUnit& nalu, Bool isFirstSliceOfPic );
     160  Void xProcessNonVclNalu                  ( InputNALUnit nalu );
     161  Void xTerminateDecoding                  ( );
     162
     163  // Process slice
     164  Void xDecodeFirstSliceOfPicture          ( InputNALUnit nalu, Bool sliceIsFirstOfNewAu ); 
     165  Void xDecodeFollowSliceOfPicture         ( InputNALUnit nalu );
     166
     167  // Process picture 
     168  Void xFinalizePreviousPictures           ( Bool sliceIsFirstOfNewAU );
     169  Void xFinalizePic                        ( Bool curPicIsLastInAu );
     170  Void xFinalizeAU                         ( );
     171  Void xPicDecoding                        ( DecProcPart curPart, Bool picPosInAuIndication );
     172
     173  // Clause 8
     174  Void x812CvsgDecodingProcess             ( Int decIdx );
     175  Void x813decProcForCodPicWithLIdZero     ( DecProcPart curPart );
     176
     177  // Annex C (DPB)
     178  Void xC522OutputAndRemOfPicsFromDpb      ( );
     179  Void xC523PicDecMarkAddBumpAndStor       ( );
     180  Void xC524Bumping                        ( );
     181
     182  // Annex F.8
     183  Void xF811GeneralDecProc                 ( InputNALUnit nalu );
     184  Void xF812CvsgDecodingProcess            ( Int decIdx );
     185  Void xF813ComDecProcForACodedPic         ( DecProcPart curPart, Bool picPosInAuIndication );
     186  Void xF814decProcForCodPicWithLIdZero    ( DecProcPart curPart );
     187  Void xF816decProcEndDecOfCodPicLIdGrtZero( );
     188
     189  // Annex F.13 (DPB)
     190  Void xF13521InitDpb                      ( );
     191  Void xF13522OutputAndRemOfPicsFromDpb    ( Bool beforePocDerivation );
     192  Void xF13523PicDecMarkAddBumpAndStor     ( Bool curPicIsLastInAu   );
     193  Void xF13524Bumping                      ( TComList<TComAu*> aus );
     194
     195  // Helpers
     196  TDecTop* xGetDecoder                     ( InputNALUnit& nalu ); 
     197  Int   xGetDecoderIdx                     ( Int layerId, Bool createFlag = false );
     198  Int   xPreDecodePoc                      ( InputNALUnit& nalu );
     199  Bool  xDetectNewAu                       ( InputNALUnit& nalu );
     200  Void  xDetectNewPocResettingPeriod       ( InputNALUnit& nalu );
     201  Bool  xIsNaluInTargetDecLayerIdSet       ( InputNALUnit* nalu ); ///< check whether given Nalu is within targetDecLayerIdSet
     202  Bool  xAllRefLayersInitilized            ( Int curLayerId );
     203  Void  xInitFileIO                        ( ); 
     204  Void  xOpenReconFile                     ( TComPic* curPic );
     205  Void  xFlushOutput                       ( );
     206  Void  xCropAndOutput                     ( TComPic* curPic ); 
     207#endif
    131208};
    132209
     
    134211
    135212#endif
    136 
  • branches/HTM-15.0-dev0/source/App/TAppEncoder/TAppEncTop.cpp

    r1313 r1317  
    260260  {
    261261    m_cListPicYuvRec            .push_back(new TComList<TComPicYuv*>) ;
     262
     263#if !NH_MV
    262264    m_ivPicLists.push_back( m_acTEncTopList[ layerIdInVps ]->getListPic()  );
     265#endif
     266
    263267    TEncTop& m_cTEncTop = *m_acTEncTopList[ layerIdInVps ];  // It is not a member, but this name helps avoiding code duplication !!!
    264268
    265     Int layerId = vps.getLayerIdInNuh( layerIdInVps );
     269    Int layerId = vps.getLayerIdInNuh          ( layerIdInVps );
     270#if NH_MV
     271    m_ivPicLists.getSubDpb( layerId, true );
     272#endif
     273
    266274    m_cTEncTop.setLayerIdInVps                 ( layerIdInVps );
    267275    m_cTEncTop.setLayerId                      ( layerId );   
     
    12161224  }
    12171225#if NH_MV
    1218     }
     1226}
    12191227  }
    12201228#endif 
     
    17661774      // check if all inter layer reference pictures specified in the gop entry are valid reference layer pictures when allRefLayerActiveFlag is equal to 1
    17671775      // (Should actually always be true)
    1768       Bool maxTidIlRefAndSubLayerMaxVaildFlag = true;
     1776      Bool maxTidIlRefAndSubLayerMaxValidFlag = true;
    17691777      for( Int l = 0; l < ge.m_numActiveRefLayerPics; l++ )
    17701778      {   
     
    17841792          }         
    17851793        }
    1786        maxTidIlRefAndSubLayerMaxVaildFlag = maxTidIlRefAndSubLayerMaxVaildFlag && referenceLayerFoundFlag; 
    1787       }
    1788       assert ( maxTidIlRefAndSubLayerMaxVaildFlag ); // Something wrong with MaxTidIlRefPicsPlus1 or SubLayersVpsMaxMinus1
     1794       maxTidIlRefAndSubLayerMaxValidFlag = maxTidIlRefAndSubLayerMaxValidFlag && referenceLayerFoundFlag; 
     1795      }
     1796      assert ( maxTidIlRefAndSubLayerMaxValidFlag ); // Something wrong with MaxTidIlRefPicsPlus1 or SubLayersVpsMaxMinus1
    17891797    }           
    17901798  }
  • branches/HTM-15.0-dev0/source/Lib/TLibCommon/CommonDef.h

    r1314 r1317  
    278278static const Int  MAX_NUM_VIDEO_SIGNAL_INFO =                     16 ;
    279279static const Int  MAX_NUM_SCALED_REF_LAYERS =     MAX_NUM_LAYERS - 1 ;
     280static const Int  MAX_NUM_PICS_RPS          =                     16 ;
     281static const Int  MAX_NUM_REF_LAYERS        =                     63 ; 
    280282#endif
    281283
     
    367369#endif
    368370
     371#if NH_MV
     372static const std::string NALU_TYPE_STR[] = { 
     373    "CODED_SLICE_TRAIL_N   ",  // 0
     374    "CODED_SLICE_TRAIL_R   ",  // 1
     375    "CODED_SLICE_TSA_N     ",  // 2
     376    "CODED_SLICE_TSA_R     ",  // 3
     377    "CODED_SLICE_STSA_N    ",  // 4
     378    "CODED_SLICE_STSA_R    ",  // 5
     379    "CODED_SLICE_RADL_N    ",  // 6
     380    "CODED_SLICE_RADL_R    ",  // 7
     381    "CODED_SLICE_RASL_N    ",  // 8
     382    "CODED_SLICE_RASL_R    ",  // 9
     383    "RESERVED_VCL_N10      ",
     384    "RESERVED_VCL_R11      ",
     385    "RESERVED_VCL_N12      ",
     386    "RESERVED_VCL_R13      ",
     387    "RESERVED_VCL_N14      ",
     388    "RESERVED_VCL_R15      ",
     389    "CODED_SLICE_BLA_W_LP  ",  // 16
     390    "CODED_SLICE_BLA_W_RADL",  // 17
     391    "CODED_SLICE_BLA_N_LP  ",  // 18
     392    "CODED_SLICE_IDR_W_RADL",  // 19
     393    "CODED_SLICE_IDR_N_LP  ",  // 20
     394    "CODED_SLICE_CRA       ",  // 21
     395    "RESERVED_IRAP_VCL22   ",
     396    "RESERVED_IRAP_VCL23   ",
     397    "RESERVED_VCL24        ",
     398    "RESERVED_VCL25        ",
     399    "RESERVED_VCL26        ",
     400    "RESERVED_VCL27        ",
     401    "RESERVED_VCL28        ",
     402    "RESERVED_VCL29        ",
     403    "RESERVED_VCL30        ",
     404    "RESERVED_VCL31        ",
     405    "VPS                   ",   // 32
     406    "SPS                   ",   // 33
     407    "PPS                   ",   // 34
     408    "ACCESS_UNIT_DELIMITER ",   // 35
     409    "EOS                   ",   // 36
     410    "EOB                   ",   // 37
     411    "FILLER_DATA           ",   // 38
     412    "PREFIX_SEI            ",   // 39
     413    "SUFFIX_SEI            ",   // 40
     414    "RESERVED_NVCL41       ",
     415    "RESERVED_NVCL42       ",
     416    "RESERVED_NVCL43       ",
     417    "RESERVED_NVCL44       ",
     418    "RESERVED_NVCL45       ",
     419    "RESERVED_NVCL46       ",
     420    "RESERVED_NVCL47       ",
     421    "UNSPECIFIED_48        ",
     422    "UNSPECIFIED_49        ",
     423    "UNSPECIFIED_50        ",
     424    "UNSPECIFIED_51        ",
     425    "UNSPECIFIED_52        ",
     426    "UNSPECIFIED_53        ",
     427    "UNSPECIFIED_54        ",
     428    "UNSPECIFIED_55        ",
     429    "UNSPECIFIED_56        ",
     430    "UNSPECIFIED_57        ",
     431    "UNSPECIFIED_58        ",
     432    "UNSPECIFIED_59        ",
     433    "UNSPECIFIED_60        ",
     434    "UNSPECIFIED_61        ",
     435    "UNSPECIFIED_62        ",
     436    "UNSPECIFIED_63        ",
     437    "INVALID               "               
     438  };
     439#endif
    369440
    370441#if NH_3D
  • branches/HTM-15.0-dev0/source/Lib/TLibCommon/Debug.cpp

    r1313 r1317  
    152152EnvVar DebugOptionList::ForceLumaMode         ("FORCE_LUMA_MODE",   "0", "Force a particular intra direction for Luma (0-34)"                                             );
    153153EnvVar DebugOptionList::ForceChromaMode       ("FORCE_CHROMA_MODE", "0", "Force a particular intra direction for chroma (0-5)"                                            );
    154 
    155 #if DEBUG_STRING
    156 EnvVar DebugOptionList::DebugString_Structure ("DEBUG_STRUCTURE",   "3", "Produce output on chosen structure                        bit0=intra, bit1=inter");
    157 EnvVar DebugOptionList::DebugString_Pred      ("DEBUG_PRED",        "3", "Produce output on prediction data.                        bit0=intra, bit1=inter");
    158 EnvVar DebugOptionList::DebugString_Resi      ("DEBUG_RESI",        "3", "Produce output on residual data.                          bit0=intra, bit1=inter");
    159 EnvVar DebugOptionList::DebugString_Reco      ("DEBUG_RECO",        "3", "Produce output on reconstructed data.                     bit0=intra, bit1=inter");
     154                                                                     
     155#if DEBUG_STRING                                                     
     156EnvVar DebugOptionList::DebugString_Structure ("DEBUG_STRUCTURE",   "0", "Produce output on chosen structure                        bit0=intra, bit1=inter");
     157EnvVar DebugOptionList::DebugString_Pred      ("DEBUG_PRED",        "0", "Produce output on prediction data.                        bit0=intra, bit1=inter");
     158EnvVar DebugOptionList::DebugString_Resi      ("DEBUG_RESI",        "0", "Produce output on residual data.                          bit0=intra, bit1=inter");
     159EnvVar DebugOptionList::DebugString_Reco      ("DEBUG_RECO",        "0", "Produce output on reconstructed data.                     bit0=intra, bit1=inter");
    160160EnvVar DebugOptionList::DebugString_InvTran   ("DEBUG_INV_QT",      "0", "Produce output on inverse-quantiser and transform stages. bit0=intra, bit1=inter");
    161161#endif
  • branches/HTM-15.0-dev0/source/Lib/TLibCommon/NAL.h

    r1313 r1317  
    9898        || m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R;
    9999  }
     100#if NH_MV
     101  Bool isIrap()
     102  {
     103   return  m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP
     104        || m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL
     105        || m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP
     106        || m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL
     107        || m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP
     108        || m_nalUnitType == NAL_UNIT_CODED_SLICE_CRA;
     109  }
     110
     111  Bool isIdr()
     112  {
     113    return  m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL
     114         || m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP;
     115  }
     116
     117  Bool isBla()
     118  {
     119    return  m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP
     120         || m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL
     121         || m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP;
     122  }
     123
     124  Bool isCra()
     125  {
     126   return  m_nalUnitType == NAL_UNIT_CODED_SLICE_CRA;
     127  }
     128
     129
     130#endif
    100131  Bool isSei()
    101132  {
     
    108139    return ( (UInt)m_nalUnitType < 32 );
    109140  }
     141#if NH_MV
     142  Void print( )
     143  {
     144    std::cout << "Type: " << NALU_TYPE_STR[m_nalUnitType] << " LayerId: " << m_nuhLayerId << " TemporalId: " << m_temporalId;
     145  }
     146#endif
    110147};
    111148
  • branches/HTM-15.0-dev0/source/Lib/TLibCommon/TComBitStream.cpp

    r1313 r1317  
    4141#include <string.h>
    4242#include <memory.h>
    43 
     43#if NH_MV
     44#include "TComRom.h" // This is only here, since ENC_DEC_TRACE is currently there. Consider removing when this has changed.
     45#endif
    4446using namespace std;
    4547
     
    258260  m_numBitsRead += uiNumberOfBits;
    259261
     262#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC
     263  if ( g_traceBitsRead )
     264  {
     265      Bool oldJustDoIt = g_bJustDoIt;
     266      g_bJustDoIt = true;
     267      writeToTraceFile( "Bits: ", m_numBitsRead, true );
     268      g_bJustDoIt = oldJustDoIt;
     269  }
     270#endif
     271
    260272  /* NB, bits are extracted from the MSB of each byte. */
    261273  UInt retval = 0;
  • branches/HTM-15.0-dev0/source/Lib/TLibCommon/TComCodingStatistics.h

    r1313 r1317  
    102102  STATS__CABAC_BITS__3D_IC,
    103103#endif
    104 #if NH_3D_DMM || NH_3D_SDC_INTRA || H_3D_INTER_SDC
     104#if NH_3D_DMM || NH_3D_SDC_INTRA || NH_3D_SDC_INTER
    105105  STATS__CABAC_BITS__DELTADC_SIGN_EP,
    106106  STATS__CABAC_BITS__DELTADC_PREFIX,
     
    174174    "CABAC_BITS__3D_IC"
    175175#endif
    176 #if NH_3D_DMM || NH_3D_SDC_INTRA || H_3D_INTER_SDC
     176#if NH_3D_DMM || NH_3D_SDC_INTRA || NH_3D_SDC_INTER
    177177   ,"STATS__CABAC_BITS__DELTADC_SIGN_EP"
    178178   ,"STATS__CABAC_BITS__DELTADC_PREFIX"
  • branches/HTM-15.0-dev0/source/Lib/TLibCommon/TComDataCU.cpp

    r1313 r1317  
    29342934}
    29352935
    2936 #if NH_3D_FIX_PRUNING
     2936#if NH_3D
    29372937Bool TComDataCU::hasEqualMotion( Int dirA, const TComMvField* mvFieldA, Int dirB, const TComMvField* mvFieldB )
    29382938{
     
    30463046      if( !iLoop && ivCandDir[0] > 0)
    30473047      {
    3048 #if NH_3D_FIX_PRUNING
    30493048        if( hasEqualMotion(tmpDir, tmpMV, m_mergCands[MRG_IVMC].m_uDir, m_mergCands[MRG_IVMC].m_cMvField ))
    3050 #else
    3051         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])
    3052 #endif
    30533049        {
    30543050            bRemove                         = true;
     
    31013097  }
    31023098
     3099
     3100#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC
     3101  if ( g_traceMergeCandListConst )
     3102  {
     3103    for (Int i = 0; i<MRG_IVSHIFT+1; i++)
     3104    {
     3105      m_mergCands[i].print( i );
     3106    }
     3107  }
     3108#endif
     3109
     3110
    31033111  Int iCount = 0;
    31043112  TComMv cZeroMv;
     
    31563164    pcMvFieldNeighbours[(ui<<1)+1].setMvField(cZeroMv, NOT_VALID);
    31573165  }
     3166
    31583167  // copy extMergeCandList to output
    31593168  for( UInt ui = 0; ui < getSlice()->getMaxNumMergeCand(); ui++ )
     
    31613170    puhInterDirNeighbours[ui] = uhInterDirNeighboursExt[ui];
    31623171    pcMvFieldNeighbours[ui<<1].setMvField(extMergeCandList[ui<<1].getMv(), extMergeCandList[ui<<1].getRefIdx());
     3172
    31633173    if ( getSlice()->isInterB() )
     3174    {
    31643175      pcMvFieldNeighbours[(ui<<1)+1].setMvField(extMergeCandList[(ui<<1)+1].getMv(), extMergeCandList[(ui<<1)+1].getRefIdx());
    3165   }
     3176    }
     3177  }
     3178
     3179#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC
     3180  if ( g_traceMergeCandListConst )
     3181  {
     3182    std::cout << std::setfill(' ')                          << std::setw( 15 )
     3183      <<  "Num"                                             << std::setw( 15 )
     3184      <<  "Dir "                                            << std::setw( 15 )
     3185      <<  "L0 RefIdx"                                       << std::setw( 15 )
     3186      <<  "L0 Hor"                                          << std::setw( 15 )
     3187      <<  "L0 Ver"                                          << std::setw( 15 )
     3188      <<  "L1 RefIdx"                                       << std::setw( 15 )
     3189      <<  "L1 Hor"                                          << std::setw( 15 )
     3190      <<  "L1 Ver"                                          << std::setw( 15 )
     3191      << std::endl;
     3192
     3193    // copy extMergeCandList to output
     3194    for( UInt ui = 0; ui < getSlice()->getMaxNumMergeCand(); ui++ )
     3195    {
     3196      UChar curDir        = puhInterDirNeighbours[ui];
     3197      TComMvField& curf   = pcMvFieldNeighbours[ui<<1];
     3198      TComMvField& curf2  = pcMvFieldNeighbours[(ui<<1)+1];
     3199
     3200      std::cout << std::setfill(' ')                         << std::setw( 15 )
     3201        << ui                                                << std::setw( 15 )       
     3202        << (UInt) curDir                                     << std::setw( 15 )   
     3203        << ((curDir & 1) ? curf.getRefIdx()       : MIN_INT) << std::setw( 15 )
     3204        << ((curDir & 1) ? curf.getMv().getHor()  : MIN_INT) << std::setw( 15 )
     3205        << ((curDir & 1) ? curf.getMv().getVer()  : MIN_INT) << std::setw( 15 );
     3206
     3207      if ( getSlice()->isInterB() )
     3208      {     
     3209        std::cout << ((curDir & 2) ? curf2.getRefIdx() : MIN_INT) << std::setw( 15 )
     3210          << ((curDir & 1) ? curf2.getMv().getHor()    : MIN_INT) << std::setw( 15 )
     3211          << ((curDir & 1) ? curf2.getMv().getVer()    : MIN_INT) << std::setw( 15 );
     3212      }
     3213      std::cout << std::endl;
     3214    }
     3215  }
     3216#endif
    31663217  numValidMergeCand = iCount;
    31673218  assert(iCount == getSlice()->getMaxNumMergeCand());
     
    35033554          continue;
    35043555        }
    3505 #if NH_3D_FIX_PRUNING
    35063556        if (hasEqualMotion( tmpDir, tmpMV, m_mergCands[MRG_A1+iCnloop].m_uDir, m_mergCands[MRG_A1+iCnloop].m_cMvField ) )
    3507 #else
    3508         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])
    3509 #endif
    35103557        {
    35113558          m_mergCands[MRG_A1+iCnloop].m_bAvailable = false;
     
    35813628          continue;
    35823629        }
    3583 #if NH_3D_FIX_PRUNING
    35843630        if (hasEqualMotion(ivCandDir[0], tmpMV, m_mergCands[MRG_A1+i].m_uDir,  m_mergCands[MRG_A1+i].m_cMvField) )
    3585 #else
    3586         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])
    3587 #endif
    35883631        {
    35893632          m_mergCands[MRG_A1+i].m_bAvailable = false;
     
    35943637    else
    35953638    {
    3596 #if NH_3D_FIX_PRUNING
    35973639      if( hasEqualMotion( ivCandDir[0], tmpMV, m_mergCands[MRG_T].m_uDir, m_mergCands[MRG_T].m_cMvField ) )
    3598 #else
    3599       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])
    3600 #endif
    36013640      {
    36023641        bRemoveSpa                      = true;
     
    36473686      !bARPFlag &&
    36483687#endif
    3649 #if H_3D || NH_3D_FIX_VSP
     3688#if NH_3D
    36503689      (nPSW + nPSH > 12) &&
    36513690#endif
     
    36943733        continue;
    36953734      }
    3696 #if NH_3D_FIX_PRUNING
    36973735      if ( hasEqualMotion(ivCandDir[1], tmpMV, m_mergCands[MRG_A1+i].m_uDir, m_mergCands[MRG_A1+i].m_cMvField) )
    3698 #else
    3699       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])
    3700 #endif
    37013736      {
    37023737        bRemoveSpa                      = true;
     
    48524887  }
    48534888}
     4889#if NH_3D
     4890Void TComDataCU::printMV( )
     4891
     4892
     4893  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
     4894  {
     4895    std::cout << "L" << i;
     4896    m_acCUMvField[i].print(m_pePredMode);
     4897  }
     4898
     4899}
     4900#endif
    48544901
    48554902UInt TComDataCU::getCoefScanIdx(const UInt uiAbsPartIdx, const UInt uiWidth, const UInt uiHeight, const ComponentID compID) const
     
    52845331#if NH_3D_NBDV_REF
    52855332          TComPic* picDepth = NULL;
    5286           assert(getSlice()->getRefPic(eRefPicList, refId)->getPOC() == getSlice()->getPOC());         
     5333          assert(getSlice()->getRefPic(eRefPicList, refId)->getPOC() == getSlice()->getPOC());           
    52875334#if H_3D_FCO_VSP_DONBDV_E0163
    52885335          picDepth  = getSlice()->getIvPic(true, getSlice()->getViewIndex() );
     
    56275674    if(!m_pcSlice->getIsDepth())
    56285675    {
    5629 #if H_3D_DBBP || NH_3D_ALIGN_SPIVMP_DBBP
     5676#if NH_3D_DBBP
    56305677      if (!getDBBPFlag(0))
    56315678#else
     
    58035850      iCurrPosY  += ( iHeight >> 1 );
    58045851    }
    5805 #if H_3D_DBBP || NH_3D_ALIGN_SPIVMP_DBBP
     5852#if NH_3D_DBBP
    58065853    for(Int iLoopCan = ( (m_pcSlice->getIsDepth() || getDBBPFlag(0)) ? 0 : 1 ); iLoopCan < ( 2 - m_pcSlice->getIsDepth() ); iLoopCan ++)
    58075854#else
     
    58785925    }
    58795926#if NH_3D_SPIVMP
    5880 #if H_3D_DBBP || NH_3D_ALIGN_SPIVMP_DBBP
     5927#if NH_3D_DBBP
    58815928    for(Int iLoopCan = ( (m_pcSlice->getIsDepth() || getDBBPFlag(0)) ? 0 : 1 ); iLoopCan < ( 2 - m_pcSlice->getIsDepth() ); iLoopCan ++)
    58825929#else
  • branches/HTM-15.0-dev0/source/Lib/TLibCommon/TComDataCU.h

    r1313 r1317  
    601601#if NH_3D
    602602  Void          compressMV            ( Int scale );
     603  Void          printMV               ( );
    603604#else           
    604605  Void          compressMV            ();
     
    644645
    645646  Bool          hasEqualMotion              ( UInt uiAbsPartIdx, TComDataCU* pcCandCU, UInt uiCandAbsPartIdx );
    646 #if NH_3D_FIX_PRUNING
     647#if NH_3D
    647648  Bool          hasEqualMotion              ( Int dirA, const TComMvField* mvFieldA,  Int dirB, const TComMvField* mvFieldB  );
    648649#endif
  • branches/HTM-15.0-dev0/source/Lib/TLibCommon/TComMotionInfo.cpp

    r1313 r1317  
    4444#include "TComPic.h"
    4545#endif
    46 
     46#if NH_MV
     47#include <iomanip>
     48#endif
    4749//! \ingroup TLibCommon
    4850//! \{
     
    377379  }
    378380}
     381
     382#if NH_MV
     383Void TComCUMvField::print(Char* pePredMode)
     384{
     385  for ( Int uiPartIdx = 0; uiPartIdx < m_uiNumPartition; uiPartIdx += 1 )
     386  {
     387    PredMode predMode = static_cast<PredMode>( pePredMode[ uiPartIdx ] );
     388
     389    if ( predMode == MODE_INTRA)
     390    {
     391      std::cout << std::setfill(' ') << "("
     392        << std::setw(3) <<  "   "    << ","
     393        << std::setw(3) <<  "   "    << ","
     394        << std::setw(3) <<  "   "    << ")";
     395    }
     396    else
     397    {
     398      ;
     399      std::cout << std::setfill(' ') << "("
     400        << std::setw(3) <<  (Int) m_piRefIdx[ uiPartIdx ]        << ","
     401        << std::setw(3) <<  m_pcMv[ uiPartIdx ].getHor()   << ","
     402        << std::setw(3) <<  m_pcMv[ uiPartIdx ].getVer()   << ")";
     403    }   
     404  }
     405}
     406
     407#if NH_3D_MLC
     408Void TComMotionCand::print( Int i )
     409{
     410  if (i == 0  )
     411  {
     412
     413    std::cout << std::setfill(' ')                          << std::setw( 15 )
     414      << "Num"                                              << std::setw( 15 )
     415      << "Avai"                                             << std::setw( 15 )
     416      << "Dir "                                             << std::setw( 15 )
     417      <<  "L0 RefIdx"                                       << std::setw( 15 )
     418      <<  "L0 Hor"                                          << std::setw( 15 )
     419      <<  "L0 Ver"                                          << std::setw( 15 )
     420      <<  "L1 RefIdx"                                       << std::setw( 15 )
     421      <<  "L1 Hor"                                          << std::setw( 15 )
     422      <<  "L1 Ver"                                          << std::setw( 15 )
     423      << "VspFlag"                                          << std::setw( 15 )
     424      << "SPIVMPFlag"                                       
     425      << std::endl;
     426  }
     427
     428  std::cout << std::setfill(' ')                                  << std::setw( 15 )
     429    << i                                                          << std::setw( 15 )
     430    << m_bAvailable                                               << std::setw( 15 )
     431    << (UInt) m_uDir                                              << std::setw( 15 )
     432    << ((m_uDir & 1) ? m_cMvField[0].getRefIdx()       : MIN_INT) << std::setw( 15 )
     433    << ((m_uDir & 1) ? m_cMvField[0].getMv().getHor()  : MIN_INT) << std::setw( 15 )
     434    << ((m_uDir & 1) ? m_cMvField[0].getMv().getVer()  : MIN_INT) << std::setw( 15 )
     435    << ((m_uDir & 2) ? m_cMvField[1].getRefIdx()       : MIN_INT) << std::setw( 15 )
     436    << ((m_uDir & 2) ? m_cMvField[1].getMv().getHor()  : MIN_INT) << std::setw( 15 )
     437    << ((m_uDir & 2) ? m_cMvField[1].getMv().getVer()  : MIN_INT) << std::setw( 15 )
     438    << m_iVspFlag                                                 << std::setw( 15 )
     439    << m_bSPIVMPFlag                                              << std::setw( 15 )
     440    << std::endl;
     441}
     442#endif
     443#endif
    379444//! \}
  • branches/HTM-15.0-dev0/source/Lib/TLibCommon/TComMotionInfo.h

    r1313 r1317  
    4343#include "CommonDef.h"
    4444#include "TComMv.h"
     45
    4546//! \ingroup TLibCommon
    4647//! \{
     
    188189 
    189190  Void compress(Char* pePredMode, Int scale);
     191#if NH_MV
     192  Void print   (Char* pePredMode);
     193#endif
    190194};
    191195
     
    281285#endif
    282286  }
     287
     288
     289  Void print( Int i );
     290
    283291};
     292
     293
    284294#endif
    285295
  • branches/HTM-15.0-dev0/source/Lib/TLibCommon/TComPic.cpp

    r1313 r1317  
    5454, m_bReconstructed                        (false)
    5555, m_bNeededForOutput                      (false)
    56 #if NH_MV
    57 , m_bPicOutputFlag                        (false)
    58 #endif
    5956, m_uiCurrSliceIdx                        (0)
    6057, m_bCheckLTMSB                           (false)
     
    6259, m_layerId                               (0)
    6360, m_viewId                                (0)
     61, m_bPicOutputFlag                        (false)
    6462#if NH_3D
    6563, m_viewIndex                             (0)
     
    8280  m_eRapRefList       = REF_PIC_LIST_0;
    8381  m_uiRapRefIdx       = 0;
     82#endif
     83#if NH_MV
     84  m_isPocResettingPic = false;   
     85  m_hasGeneratedRefPics = false;
     86  m_isFstPicOfAllLayOfPocResetPer = false;
     87  m_decodingOrder     = 0;
     88  m_noRaslOutputFlag  = false; 
     89  m_noClrasOutputFlag = false;
     90  m_picLatencyCount   = 0;
     91  m_isGenerated       = false;
     92  m_isGeneratedCl833  = false;
     93  m_activatesNewVps   = false;
    8494#endif
    8595}
     
    185195  }
    186196}
     197
    187198
    188199Bool  TComPic::getSAOMergeAvailability(Int currAddr, Int mergeAddr)
     
    231242
    232243#if NH_MV
    233 Void TComPic::print( Bool legend )
    234 {
    235   if ( legend )
    236     std::cout  << std::endl << "LId"        << "\t" << "POC"   << "\t" << "Rec"          << "\t" << "Ref"                       << "\t" << "LT"            <<  "\t" << "OutMark" <<  "\t" << "OutFlag" << std::endl;
    237   else
    238     std::cout  << getLayerId() << "\t" << getPOC()<< "\t" << getReconMark() << "\t" << getSlice(0)->isReferenced() << "\t" << getIsLongTerm() << "\t" << getOutputMark() << "\t" << getSlice(0)->getPicOutputFlag() <<std::endl;
    239 }
    240 
    241 TComPic* TComPicLists::getPic( Int layerIdInNuh, Int poc )
    242 {
    243   TComPic* pcPic = NULL;
    244   for(TComList<TComList<TComPic*>*>::iterator itL = m_lists.begin(); ( itL != m_lists.end() && pcPic == NULL ); itL++)
    245   {   
    246     for(TComList<TComPic*>::iterator itP=(*itL)->begin(); ( itP!=(*itL)->end() && pcPic == NULL ); itP++)
    247     {
    248       TComPic* currPic = (*itP);
    249       if ( ( currPic->getPOC() == poc ) && ( currPic->getLayerId() == layerIdInNuh ) )
    250       {
    251         pcPic = currPic ;     
    252       }
    253     }
    254   }
    255   return pcPic;
     244Bool TComPic::getPocResetPeriodId()
     245{
     246  return getSlice(0)->getPocResetIdc();
     247}
     248
     249Void TComPic::markAsUsedForShortTermReference()
     250{
     251  getSlice(0)->setReferenced( true );
     252  setIsLongTerm( false );
     253}
     254
     255Void TComPic::markAsUsedForLongTermReference()
     256{
     257  getSlice(0)->setReferenced( true );
     258  setIsLongTerm( true );
     259}
     260
     261
     262Void TComPic::markAsUnusedForReference()
     263{
     264  getSlice(0)->setReferenced( false );
     265  setIsLongTerm( false );
     266}
     267
     268
     269Bool TComPic::getMarkedUnUsedForReference()
     270{
     271  return !getSlice(0)->isReferenced( );
     272}
     273
     274
     275Bool TComPic::getMarkedAsShortTerm()
     276{
     277  return ( getSlice(0)->isReferenced( ) && !getIsLongTerm() );
     278}
     279
     280Void TComPic::print( Int outputLevel )
     281{
     282  if ( outputLevel== 0  )
     283  {
     284    std::cout  << std::endl
     285      << "LId"
     286      << "\t" << "POC"
     287      << "\t" << "Rec"
     288      << "\t" << "Ref"
     289      << "\t" << "LT"
     290      << "\t" << "OutMark"
     291      << "\t" << "OutFlag"
     292      << "\t" << "Type"
     293      << "\t" << "PReFlag"
     294      << std::endl;
     295  }
     296  else if( outputLevel == 1  )
     297  {
     298    std::cout  << getLayerId()
     299      << "\t" << getPOC()
     300      << "\t" << getReconMark()
     301      << "\t" << getSlice(0)->isReferenced()
     302      << "\t" << getIsLongTerm()
     303      << "\t" << getOutputMark()
     304      << "\t" << getSlice(0)->getPicOutputFlag()
     305      << "\t" << getSlice(0)->getNalUnitTypeString()
     306      << "\t" << getSlice(0)->getPocResetFlag()
     307      << std::endl;
     308  }
     309  else if ( outputLevel == 2  )
     310  {
     311    std::cout  << std:: setfill(' ')
     312      << " LayerId: "         << std::setw(2) << getLayerId()
     313      << "\t"  << " POC: "             << std::setw(5) << getPOC()
     314      << "\t"  << " Dec. Order: "      << std::setw(5) << getDecodingOrder()
     315      << "\t"  << " Referenced: "      << std::setw(1) << getSlice(0)->isReferenced()
     316      << "\t"  << " Pic type: "        <<                 getSlice(0)->getNalUnitTypeString()
     317      << "\t"  << " Generated: "       << std::setw(1) << getIsGenerated()
     318      << "\t"  << " Gen. Ref. Pics: "  << std::setw(1) << getHasGeneratedRefPics();
     319  }
     320  else if ( outputLevel == 4  )
     321  {
     322    std::cout  << std:: setfill(' ')
     323      << " LayerId: "         << std::setw(2) << getLayerId()
     324      << "\t"  << " POC: "             << std::setw(5) << getPOC()     
     325      << "\t"  << " Referenced: "      << std::setw(1) << getSlice(0)->isReferenced() << std::endl;
     326  }
    256327}
    257328
    258329#if NH_3D
    259 TComPic* TComPicLists::getPic( Int viewIndex, Bool depthFlag, Int poc )
    260 {
    261   return getPic   ( m_vps->getLayerIdInNuh( viewIndex, depthFlag ), poc );
    262 }
    263 #endif
    264 Void TComPicLists::print()
    265 {
    266   Bool first = true;     
    267   for(TComList<TComList<TComPic*>*>::iterator itL = m_lists.begin(); ( itL != m_lists.end() ); itL++)
    268   {   
    269     for(TComList<TComPic*>::iterator itP=(*itL)->begin(); ( itP!=(*itL)->end() ); itP++)
    270     {
    271       if ( first )
    272       {
    273         (*itP)->print( true );       
    274         first = false;
    275       }
    276       (*itP)->print( false );       
    277     }
    278   }
    279 }
    280 
    281 TComPicYuv* TComPicLists::getPicYuv( Int layerIdInNuh, Int poc, Bool reconFlag )
    282 {
    283   TComPic*    pcPic = getPic( layerIdInNuh, poc );
    284   TComPicYuv* pcPicYuv = NULL;
    285 
    286   if (pcPic != NULL)
    287   {
    288     if( reconFlag )
    289     {
    290       if ( pcPic->getReconMark() )
    291       {
    292         pcPicYuv = pcPic->getPicYuvRec();
    293       }
    294     }
    295     else
    296     {
    297       pcPicYuv = pcPic->getPicYuvOrg();
    298     }
    299   };
    300 
    301   return pcPicYuv;
    302 }
    303 
    304 #if NH_3D
    305 TComPicYuv* TComPicLists::getPicYuv( Int viewIndex, Bool depthFlag, Int poc, Bool recon )
    306 
    307   Int layerIdInNuh = m_vps->getLayerIdInNuh( viewIndex, depthFlag );
    308   return getPicYuv( layerIdInNuh, poc, recon );
    309 }
    310 #if NH_3D_ARP
    311 TComList<TComPic*>* TComPicLists::getPicList( Int layerIdInNuh )
    312 {
    313   TComList<TComList<TComPic*>*>::iterator itL = m_lists.begin();
    314   Int iLayer = 0;
    315 
    316   assert( layerIdInNuh < m_lists.size() );
    317 
    318   while( iLayer != layerIdInNuh )
    319   {
    320     itL++;
    321     iLayer++;
    322   }
    323 
    324   return *itL;
    325 }
    326 #endif
    327 #endif
    328 #endif // NH_MV
     330Void TComPic::printMotion()
     331{
     332  TComPicSym* pPicSym = getPicSym();
     333  for ( UInt uiCUAddr = 0; uiCUAddr < pPicSym->getNumberOfCtusInFrame(); uiCUAddr++ )
     334  {
     335    TComDataCU* pCtu = pPicSym->getCtu(uiCUAddr);
     336    std::cout << "CUAddr " << uiCUAddr << std::endl;
     337    pCtu->printMV();
     338    std::cout << std::endl;
     339  }
     340}
    329341
    330342#if NH_3D_NBDV
     
    437449          m_abTIVRINCurrRL[curCandPic][iColRefDir][iColRefIdx] = false;
    438450          Int iColViewIdx    = pcCandColSlice->getViewIndex();
     451#if H_3D_FIX_ARP_CHECK_NOT_IN_DPB
     452          // The picture pcCandColSlice->getRefPic((RefPicList)iColRefDir, iColRefIdx) might not be in DPB anymore
     453          // So don't access it directly.
     454          Int iColRefViewIdx = pcCandColSlice->getVPS()->getViewOrderIdx( pcCandColSlice->getRefLayerId( (RefPicList)iColRefDir, iColRefIdx ) );       
     455#else
    439456          Int iColRefViewIdx = pcCandColSlice->getRefPic((RefPicList)iColRefDir, iColRefIdx)->getViewIndex();
     457#endif
    440458          if(iColViewIdx == iColRefViewIdx)
    441459          {
     
    487505        {
    488506          if(pcCurrSlice->getRefPOC((RefPicList)iCurrRefDir, iCurrRefIdx ) == iTextRefPOC &&
    489              pcCurrSlice->getRefPic((RefPicList)iCurrRefDir, iCurrRefIdx)->getViewIndex() == iTextRefViewId)
     507            pcCurrSlice->getRefPic((RefPicList)iCurrRefDir, iCurrRefIdx)->getViewIndex() == iTextRefViewId)
    490508          { 
    491             m_aiTexToDepRef[iTextRefDir][iTextRefIdx] = iCurrRefIdx;
     509            m_aiTexToDepRef[iTextRefDir][iTextRefIdx] = iCurrRefIdx;           
    492510          }
    493511        }
     
    504522}
    505523#endif
     524#endif
     525
     526Void TComAu::setPicLatencyCount( Int picLatenyCount )
     527{
     528  for(TComList<TComPic*>::iterator itP= begin();  itP!= end(); itP++)
     529  {     
     530    (*itP)->setPicLatencyCount( picLatenyCount );
     531  }
     532}
     533
     534TComPic* TComAu::getPic( Int nuhLayerId )
     535{
     536  TComPic* pic = NULL;
     537  for(TComList<TComPic*>::iterator itP= begin(); ( itP!= end() && (pic == NULL) ); itP++)
     538  {     
     539    if ( (*itP)->getLayerId() == nuhLayerId )
     540    {
     541      pic = (*itP);
     542    }
     543  }
     544  return pic;
     545}
     546
     547Void TComAu::addPic( TComPic* pic, Bool pocUnkown )
     548{
     549  if ( !empty() )
     550  {
     551    if (!pocUnkown)
     552    {
     553      assert( pic->getPOC()   == ( getPoc() ));
     554    }     
     555    pic->setPicLatencyCount( getPicLatencyCount() );
     556
     557    assert( getPic( pic->getLayerId() ) == NULL );
     558
     559    // Add sorted
     560    TComAu::iterator itP = begin();
     561    Bool inserted = false;
     562    while( !inserted )
     563    {
     564      if ( ( itP == end()) || pic->getLayerId() < (*itP)->getLayerId() )
     565      {
     566        insert(itP, pic );
     567        inserted = true;
     568      }
     569      else
     570      {
     571        ++itP;
     572      }       
     573    }     
     574  }
     575  else
     576  {
     577    pushBack( pic );     
     578  }
     579}
     580
     581Bool TComAu::containsPic( TComPic* pic )
     582{
     583  Bool isInList = false;
     584  for(TComList<TComPic*>::iterator itP= begin(); ( itP!= end() && (!isInList) ); itP++)
     585  {
     586    isInList = isInList || ( pic == (*itP));
     587  }
     588  return isInList;
     589}
     590
     591TComSubDpb::TComSubDpb( Int nuhLayerid )
     592{
     593  m_nuhLayerId = nuhLayerid;
     594}
     595
     596TComPic* TComSubDpb::getPic( Int poc )
     597{
     598  TComPic* pic = NULL;
     599  for(TComList<TComPic*>::iterator itP= begin(); ( itP!= end() && (pic == NULL) ); itP++)
     600  {     
     601    if ( (*itP)->getPOC() == poc )
     602    {
     603      pic = (*itP);
     604    }
     605  }
     606  return pic;
     607}
     608
     609TComPic* TComSubDpb::getPicFromLsb( Int pocLsb, Int maxPicOrderCntLsb )
     610{
     611  TComPic* pic = NULL;
     612  for(TComList<TComPic*>::iterator itP= begin(); ( itP!= end() && (pic == NULL) ); itP++)
     613  {     
     614    if ( ( (*itP)->getPOC() & ( maxPicOrderCntLsb - 1 ) ) == pocLsb )
     615    {
     616      pic = (*itP);
     617    }
     618  }
     619  return pic;
     620}
     621
     622TComPic* TComSubDpb::getShortTermRefPic( Int poc )
     623{
     624  TComPic* pic = NULL;
     625  for(TComList<TComPic*>::iterator itP= begin(); ( itP!= end() && (pic == NULL) ); itP++)
     626  {     
     627    if ( (*itP)->getPOC() == poc && (*itP)->getMarkedAsShortTerm() )
     628    {
     629      pic = (*itP);
     630    }
     631  }
     632  return pic;
     633}
     634
     635TComList<TComPic*> TComSubDpb::getPicsMarkedNeedForOutput()
     636{
     637  TComList<TComPic*> picsMarkedNeedForOutput;
     638
     639  for(TComList<TComPic*>::iterator itP= begin();  itP!= end() ; itP++ )
     640  {     
     641    if ( (*itP)->getOutputMark() )
     642    {
     643      picsMarkedNeedForOutput.push_back( (*itP) );
     644    }
     645  }
     646  return picsMarkedNeedForOutput;
     647}
     648
     649Void TComSubDpb::markAllAsUnusedForReference()
     650{
     651  for(TComList<TComPic*>::iterator itP= begin();  itP!= end() ; itP++ )
     652  {     
     653    (*itP)->markAsUnusedForReference();
     654  }
     655}
     656
     657Void TComSubDpb::addPic( TComPic* pic )
     658{
     659  assert( pic != NULL );
     660  assert( m_nuhLayerId == pic->getLayerId() || m_nuhLayerId == -1);     
     661  if ( !empty() )
     662  {
     663    assert( getPic( pic->getPOC() ) == NULL ); // Don't add twice; assert( pic->getLayerId() == m_nuhLayerId );           
     664
     665    // Add sorted
     666    TComSubDpb::iterator itP = begin();
     667    Bool inserted = false;
     668    while( !inserted )
     669    {
     670      if ( ( itP == end()) || pic->getPOC() < (*itP)->getPOC() )
     671      {
     672        insert(itP, pic );
     673        inserted = true;
     674      }
     675      else
     676      {
     677        ++itP;
     678      }       
     679    }     
     680  }
     681  else
     682  {
     683    pushBack( pic );
     684  }
     685}
     686
     687Void TComSubDpb::removePics( std::vector<TComPic*> picToRemove )
     688{
     689  for (Int i = 0; i < picToRemove.size(); i++ )
     690  {
     691    if( picToRemove[i] != NULL)
     692    {
     693      remove( picToRemove[i] );
     694    }
     695  }
     696}
     697
     698Bool TComSubDpb::areAllPicsMarkedNotNeedForOutput()
     699{
     700  return ( getPicsMarkedNeedForOutput().size() == 0 );
     701}
     702
     703
     704TComPicLists::~TComPicLists()
     705{
     706  emptyAllSubDpbs();
     707  for(TComList<TComSubDpb*>::iterator itL = m_subDpbs.begin(); ( itL != m_subDpbs.end()); itL++)
     708  {     
     709    if ( (*itL) != NULL )
     710    {
     711      delete (*itL);
     712      (*itL) = NULL;
     713    }
     714  }
     715}
     716
     717Void TComPicLists::addNewPic( TComPic* pic )
     718{
     719  getSubDpb ( pic->getLayerId() , true )->addPic( pic );
     720  getAu     ( pic->getPOC()     , true )->addPic( pic , false );
     721  if ( m_printPicOutput )
     722  {
     723    std::cout << "  Add    picture: ";
     724    pic->print( 2 );
     725    std::cout << std::endl;
     726  }
     727}
     728
     729Void TComPicLists::removePic( TComPic* pic )
     730{
     731  if (pic != NULL)
     732  {
     733
     734    TComSubDpb* curSubDpb = getSubDpb( pic->getLayerId(), false );
     735    curSubDpb->remove( pic );
     736
     737    TComAu* curAu = getAu     ( pic->getPOC(), false );       
     738
     739    if (curAu != NULL)
     740    {   
     741      curAu->remove( pic );
     742      // Remove AU when empty.
     743      if (curAu->empty() )
     744      {
     745        m_aus.remove( curAu );
     746        delete curAu;
     747      }
     748    }
     749
     750    if ( m_printPicOutput )
     751    {
     752      std::cout << "  Remove picture: ";
     753      pic->print( 2 );
     754      std::cout << std::endl;
     755    }
     756
     757    pic->destroy();
     758    delete pic;
     759  }
     760}
     761
     762TComPic* TComPicLists::getPic( Int layerIdInNuh, Int poc )
     763{
     764  TComPic* pcPic = NULL;
     765  TComSubDpb* subDpb = getSubDpb( layerIdInNuh, false );
     766  if ( subDpb != NULL )
     767  {
     768    pcPic = subDpb->getPic( poc );
     769  }
     770  return pcPic;
     771}
     772
     773TComPicYuv* TComPicLists::getPicYuv( Int layerIdInNuh, Int poc, Bool reconFlag )
     774{
     775  TComPic*    pcPic = getPic( layerIdInNuh, poc );
     776  TComPicYuv* pcPicYuv = NULL;
     777
     778  if (pcPic != NULL)
     779  {
     780    if( reconFlag )
     781    {
     782      if ( pcPic->getReconMark() )
     783      {
     784        pcPicYuv = pcPic->getPicYuvRec();
     785      }
     786    }
     787    else
     788    {
     789      pcPicYuv = pcPic->getPicYuvOrg();
     790    }
     791  };
     792
     793  return pcPicYuv;
     794}
     795
     796TComSubDpb* TComPicLists::getSubDpb( Int nuhLayerId, Bool create )
     797{
     798  TComSubDpb* subDpb = NULL;
     799  for(TComList<TComSubDpb*>::iterator itL = m_subDpbs.begin(); ( itL != m_subDpbs.end() && subDpb == NULL ); itL++)
     800  {     
     801    if ( (*itL)->getLayerId() == nuhLayerId )
     802    {       
     803      subDpb = (*itL);
     804    }
     805  } 
     806  if ( subDpb == NULL && create )
     807  {
     808    m_subDpbs.push_back( new TComSubDpb(nuhLayerId) );
     809  }
     810  return subDpb;
     811}
     812
     813TComList<TComSubDpb*>* TComPicLists::getSubDpbs()
     814{
     815  return (&m_subDpbs);
     816}
     817
     818TComAu* TComPicLists::addAu( Int poc )
     819{
     820  TComList<TComAu*>::iterator itA = m_aus.begin();
     821
     822  assert( getAu(poc, false) == NULL );
     823  Bool inserted = false;
     824  while( !inserted)
     825  {     
     826    if ( ( itA == m_aus.end()) || poc < (*itA)->getPoc() )
     827    {       
     828      m_aus.insert(itA, new TComAu );       
     829      inserted = true;
     830      --itA;
     831    }
     832    else
     833    {
     834      ++itA;
     835    }
     836  }
     837  return (*itA);
     838}
     839
     840TComAu* TComPicLists::getAu( Int poc, Bool create )
     841{
     842  TComAu* au = NULL;
     843
     844  for( TComList<TComAu*>::iterator itA = m_aus.begin(); ( itA != m_aus.end() && au == NULL ); itA++)
     845  {
     846    if ( (*itA)->getPoc() == poc )
     847    {       
     848      au = (*itA);
     849    }
     850  } 
     851
     852  if ( au == NULL && create )
     853  {
     854    au = addAu( poc );
     855  }
     856  return au;
     857}
     858
     859TComList<TComAu*>* TComPicLists::getAus()
     860{
     861  return (&m_aus);
     862}
     863
     864TComList<TComAu*> TComPicLists::getAusHavingPicsMarkedForOutput()
     865{
     866  TComList<TComAu*> ausHavingPicsForOutput;
     867  for(TComList<TComAu*>::iterator itA= m_aus.begin(); ( itA!=m_aus.end()); itA++)
     868  {
     869    Bool hasPicMarkedAsNeedForOutput = false;
     870    for( TComAu::iterator itP= (*itA)->begin(); (itP!=(*itA)->end() && !hasPicMarkedAsNeedForOutput); itP++  )
     871    {
     872      if( (*itP)->getOutputMark() )
     873      {
     874        hasPicMarkedAsNeedForOutput = true;
     875      }
     876    }
     877    if (hasPicMarkedAsNeedForOutput)
     878    {
     879      ausHavingPicsForOutput.pushBack( (*itA) );
     880    }
     881  }
     882  return ausHavingPicsForOutput;
     883}
     884
     885Void TComPicLists::markSubDpbAsUnusedForReference( Int layerIdInNuh )
     886{
     887  TComSubDpb* subDpb = getSubDpb( layerIdInNuh, false );
     888  markSubDpbAsUnusedForReference( *subDpb );
     889}
     890
     891Void TComPicLists::markSubDpbAsUnusedForReference( TComSubDpb& subDpb )
     892{
     893  for(TComList<TComPic*>::iterator itP=subDpb.begin(); ( itP!=subDpb.end()); itP++)
     894  {
     895    (*itP)->markAsUnusedForReference();
     896  }
     897}
     898
     899Void TComPicLists::markAllSubDpbAsUnusedForReference()
     900{
     901  for(TComList<TComSubDpb*>::iterator itS= m_subDpbs.begin(); ( itS!=m_subDpbs.end()); itS++)
     902  {
     903    markSubDpbAsUnusedForReference( *(*itS) );
     904  }
     905}
     906
     907Void TComPicLists::decrementPocsInSubDpb( Int nuhLayerId, Int deltaPocVal )
     908{
     909  TComSubDpb* subDpb = getSubDpb( nuhLayerId, false );
     910
     911  for(TComSubDpb::iterator itP = subDpb->begin(); itP!=subDpb->end(); itP++)
     912  {
     913    TComPic* pic = (*itP);
     914    for (Int i = 0; i < pic->getNumAllocatedSlice(); i++)
     915    {
     916      TComSlice* slice = pic->getSlice(i);
     917      slice->setPOC( slice->getPOC() - deltaPocVal );
     918    }   
     919  }
     920}
     921Void TComPicLists::emptyAllSubDpbs()
     922{
     923  emptySubDpbs( &m_subDpbs );
     924}
     925
     926Void TComPicLists::emptySubDpbs( TComList<TComSubDpb*>* subDpbs )
     927{
     928  assert( subDpbs != NULL );
     929  for( TComList<TComSubDpb*>::iterator itS = subDpbs->begin(); itS != subDpbs->end(); itS++ )
     930  {
     931    emptySubDpb( (*itS) );
     932  }
     933}
     934
     935Void TComPicLists::emptySubDpb( TComSubDpb* subDpb )
     936{
     937  if(subDpb != NULL)
     938  {
     939    while( !subDpb->empty() )
     940    {
     941      TComPic* curPic = *(subDpb->begin());
     942      removePic( curPic );
     943    }
     944  }
     945}
     946
     947Void TComPicLists::emptySubDpb( Int nuhLayerId )
     948{
     949  emptySubDpb( getSubDpb( nuhLayerId , false) );
     950}
     951
     952Void TComPicLists::emptyNotNeedForOutputAndUnusedForRef()
     953{
     954  for(TComList<TComSubDpb*>::iterator itS= m_subDpbs.begin(); ( itS!=m_subDpbs.end()); itS++)
     955  {
     956    emptySubDpbNotNeedForOutputAndUnusedForRef( *(*itS) );
     957  }
     958}
     959
     960Void TComPicLists::emptySubDpbNotNeedForOutputAndUnusedForRef( Int layerId )
     961{
     962  TComSubDpb* subDpb = getSubDpb( layerId, false );
     963  emptySubDpbNotNeedForOutputAndUnusedForRef( *subDpb );
     964}
     965
     966Void TComPicLists::emptySubDpbNotNeedForOutputAndUnusedForRef( TComSubDpb subDpb )
     967{
     968  for(TComSubDpb::iterator itP= subDpb.begin(); ( itP!=subDpb.end()); itP++)
     969  {
     970    TComPic* pic = (*itP);
     971    if ( !pic->getOutputMark() && pic->getMarkedUnUsedForReference() )
     972    {
     973      removePic( pic );
     974    }
     975  }
     976}
     977
     978Void TComPicLists::print()
     979{
     980  Bool first = true;     
     981  for(TComList<TComSubDpb*>::iterator itL = m_subDpbs.begin(); ( itL != m_subDpbs.end() ); itL++)
     982  {   
     983    for(TComList<TComPic*>::iterator itP=(*itL)->begin(); ( itP!=(*itL)->end() ); itP++)
     984    {
     985      if ( first )
     986      {
     987        (*itP)->print( true );       
     988        first = false;
     989      }
     990      (*itP)->print( false );       
     991    }
     992  }
     993}
     994
     995#if NH_3D
     996TComPicYuv* TComPicLists::getPicYuv( Int viewIndex, Bool depthFlag, Int poc, Bool recon )
     997
     998  Int layerIdInNuh = m_vps->getLayerIdInNuh( viewIndex, depthFlag );
     999  return getPicYuv( layerIdInNuh, poc, recon );
     1000}
     1001
     1002TComPic* TComPicLists::getPic( Int viewIndex, Bool depthFlag, Int poc )
     1003{
     1004  return getPic   ( m_vps->getLayerIdInNuh( viewIndex, depthFlag ), poc );
     1005}
     1006
     1007#endif
     1008
     1009#endif
     1010
     1011
    5061012
    5071013
    5081014//! \}
     1015
  • branches/HTM-15.0-dev0/source/Lib/TLibCommon/TComPic.h

    r1313 r1317  
    5454/// picture class (symbol + YUV buffers)
    5555
     56
     57
     58#if NH_MV
     59class TComPic;
     60
     61class TComDecodedRps
     62{
     63public:
     64
     65  TComDecodedRps()
     66  {
     67    m_refPicSetsCurr[0] = &m_refPicSetStCurrBefore;
     68    m_refPicSetsCurr[1] = &m_refPicSetStCurrAfter ;
     69    m_refPicSetsCurr[2] = &m_refPicSetLtCurr      ;
     70
     71    m_refPicSetsLt  [0] = &m_refPicSetLtCurr      ;
     72    m_refPicSetsLt  [1] = &m_refPicSetLtFoll      ;
     73
     74    m_refPicSetsAll [0] = &m_refPicSetStCurrBefore;
     75    m_refPicSetsAll [1] = &m_refPicSetStCurrAfter ;
     76    m_refPicSetsAll [2] = &m_refPicSetStFoll      ;
     77    m_refPicSetsAll [3] = &m_refPicSetLtCurr      ;
     78    m_refPicSetsAll [4] = &m_refPicSetLtFoll      ;
     79  };   
     80
     81  std::vector<Int>       m_pocStCurrBefore;
     82  std::vector<Int>       m_pocStCurrAfter;
     83  std::vector<Int>       m_pocStFoll;   
     84  std::vector<Int>       m_pocLtCurr;
     85  std::vector<Int>       m_pocLtFoll;
     86
     87  Int                    m_numPocStCurrBefore;
     88  Int                    m_numPocStCurrAfter;
     89  Int                    m_numPocStFoll;
     90  Int                    m_numPocLtCurr;
     91  Int                    m_numPocLtFoll;
     92
     93  std::vector<TComPic*>  m_refPicSetStCurrBefore;
     94  std::vector<TComPic*>  m_refPicSetStCurrAfter;
     95  std::vector<TComPic*>  m_refPicSetStFoll;
     96  std::vector<TComPic*>  m_refPicSetLtCurr;
     97  std::vector<TComPic*>  m_refPicSetLtFoll;   
     98
     99  std::vector<TComPic*>* m_refPicSetsCurr[3];
     100  std::vector<TComPic*>* m_refPicSetsLt  [2];
     101  std::vector<TComPic*>* m_refPicSetsAll [5];
     102
     103  // Annex F
     104  Int                    m_numActiveRefLayerPics0;
     105  Int                    m_numActiveRefLayerPics1;     
     106
     107  std::vector<TComPic*>  m_refPicSetInterLayer0;
     108  std::vector<TComPic*>  m_refPicSetInterLayer1;
     109};
     110#endif
     111
    56112class TComPic
    57113{
     
    72128  Bool                  m_bReconstructed;
    73129  Bool                  m_bNeededForOutput;
    74 #if NH_MV
    75   Bool                  m_bPicOutputFlag;         // Semantics variable
    76 #endif
     130
    77131  UInt                  m_uiCurrSliceIdx;         // Index of current slice
    78132  Bool                  m_bCheckLTMSB;
     
    87141  Int                   m_layerId;
    88142  Int                   m_viewId;
     143  Bool                  m_bPicOutputFlag;                // Semantics variable
     144  Bool                  m_hasGeneratedRefPics;
     145  Bool                  m_isPocResettingPic;
     146  Bool                  m_isFstPicOfAllLayOfPocResetPer;
     147  Int64                 m_decodingOrder;
     148  Bool                  m_noRaslOutputFlag;
     149  Bool                  m_noClrasOutputFlag;
     150  Int                   m_picLatencyCount;
     151  Bool                  m_isGenerated;
     152  Bool                  m_isGeneratedCl833;
     153  Bool                  m_activatesNewVps;
     154  TComDecodedRps        m_decodedRps;
     155#endif
    89156#if NH_3D
    90157  Int                   m_viewIndex;
     
    92159  Int**                 m_aaiCodedScale;
    93160  Int**                 m_aaiCodedOffset;
    94 #endif
    95 #endif
    96161#if NH_3D_QTLPC
    97162  Bool                  m_bReduceBitsQTL;
    98163#endif
    99164#if NH_3D_NBDV
    100   UInt        m_uiRapRefIdx;
    101   RefPicList  m_eRapRefList;
    102   Int         m_iNumDdvCandPics;
    103   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
    104   Int         m_aiTexToDepRef  [2][MAX_NUM_REF];
    105 #endif
    106 
     165  UInt                   m_uiRapRefIdx;
     166  RefPicList             m_eRapRefList;
     167  Int                    m_iNumDdvCandPics;
     168  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
     169  Int                    m_aiTexToDepRef  [2][MAX_NUM_REF];
     170#endif
     171#endif
    107172public:
    108173  TComPic();
     
    115180  UInt          getTLayer() const               { return m_uiTLayer;   }
    116181  Void          setTLayer( UInt uiTLayer ) { m_uiTLayer = uiTLayer; }
    117 #if NH_MV
    118   Void          setLayerId            ( Int layerId )    { m_layerId      = layerId; }
    119   Int           getLayerId            ()                 { return m_layerId;    }
    120   Void          setViewId             ( Int viewId )     { m_viewId = viewId;   }
    121   Int           getViewId             ()                 { return m_viewId;     }
    122 #if NH_3D
    123   Void          setViewIndex          ( Int viewIndex )  { m_viewIndex = viewIndex;   }
    124   Int           getViewIndex          ()                 { return m_viewIndex;     }
    125 
    126   Void          setIsDepth            ( Bool isDepth )   { m_isDepth = isDepth; }
    127   Bool          getIsDepth            ()                 { return m_isDepth; }
    128 
    129   Void          setScaleOffset( Int** pS, Int** pO )  { m_aaiCodedScale = pS; m_aaiCodedOffset = pO; }
    130   Int**         getCodedScale ()                      { return m_aaiCodedScale;  }
    131   Int**         getCodedOffset()                      { return m_aaiCodedOffset; }
    132 #endif
    133 #endif
    134 #if NH_3D_QTLPC
    135   Bool          getReduceBitsFlag ()             { return m_bReduceBitsQTL;     }
    136   Void          setReduceBitsFlag ( Bool bFlag ) { m_bReduceBitsQTL = bFlag;    }
    137 #endif
    138182
    139183  Bool          getUsedByCurr() const            { return m_bUsedByCurr; }
     
    177221  Void          setOutputMark (Bool b) { m_bNeededForOutput = b;     }
    178222  Bool          getOutputMark () const      { return m_bNeededForOutput;  }
    179  #if NH_MV
    180   Void          setPicOutputFlag(Bool b) { m_bPicOutputFlag = b;      }
    181   Bool          getPicOutputFlag()       { return m_bPicOutputFlag ;  }
    182 #endif
    183 #if NH_3D
    184 #if NH_3D_ARP
    185   Void          getCUAddrAndPartIdx( Int iX, Int iY, Int& riCuAddr, Int& riAbsZorderIdx );
    186 #endif
    187   Void          compressMotion(Int scale);
    188 #else   
     223
     224#if !NH_3D
    189225  Void          compressMotion();
    190226#endif
     
    210246
    211247#if NH_MV
    212   Void          print( Bool legend );
     248   Void          setLayerId            ( Int layerId )    { m_layerId      = layerId; }
     249   Int           getLayerId            ()                 { return m_layerId;    }
     250   
     251   Void          setViewId             ( Int viewId )     { m_viewId = viewId;   }
     252   Int           getViewId             ()                 { return m_viewId;     }
     253
     254   Void          setPicOutputFlag(Bool b)                 { m_bPicOutputFlag = b;      }
     255   Bool          getPicOutputFlag()                       { return m_bPicOutputFlag ;  }
     256
     257   Bool          getPocResetPeriodId();
     258
     259   Void          markAsUsedForShortTermReference();
     260   Void          markAsUsedForLongTermReference();
     261   Void          markAsUnusedForReference();
     262
     263   Bool          getMarkedUnUsedForReference();
     264   Bool          getMarkedAsShortTerm();
     265
     266   Void          setHasGeneratedRefPics(Bool val)       { m_hasGeneratedRefPics  = val;    }
     267   Bool          getHasGeneratedRefPics( )              { return m_hasGeneratedRefPics;   }
     268
     269   Void          setIsPocResettingPic(Bool val)         { m_isPocResettingPic = val;    }
     270   Bool          getIsPocResettingPic( )                { return m_isPocResettingPic;   }
     271
     272   Void          setIsFstPicOfAllLayOfPocResetPer(Bool val) { m_isFstPicOfAllLayOfPocResetPer = val;  }
     273   Bool          getIsFstPicOfAllLayOfPocResetPer( )        { return m_isFstPicOfAllLayOfPocResetPer; }
     274
     275   Int64         getDecodingOrder( )                    { return m_decodingOrder;       }
     276   Void          setDecodingOrder( UInt64 val  )        { m_decodingOrder = val;        }
     277
     278   Bool          getNoRaslOutputFlag()                  { return m_noRaslOutputFlag;     }
     279   Void          setNoRaslOutputFlag( Bool b )          { m_noRaslOutputFlag = b;        }
     280
     281   Bool          getNoClrasOutputFlag()                 { return m_noClrasOutputFlag;    }
     282   Void          setNoClrasOutputFlag( Bool b )         { m_noClrasOutputFlag = b;       }
     283
     284   Int           getPicLatencyCount()                   { return m_picLatencyCount;      }
     285   Void          setPicLatencyCount( Int val )          { m_picLatencyCount = val;       }
     286
     287   Bool          getIsGenerated() const                 { return m_isGenerated;          }
     288   Void          setIsGenerated( Bool b )               { m_isGenerated = b;             }
     289
     290   Bool          getIsGeneratedCl833() const            { return m_isGeneratedCl833;     }
     291   Void          setIsGeneratedCl833( Bool b )          { m_isGeneratedCl833 = b;        }
     292
     293   Int           getTemporalId( )                       { return getSlice(0)->getTemporalId(); }
     294
     295   Bool          getActivatesNewVps()                   { return m_activatesNewVps;      }
     296   Void          setActivatesNewVps( Bool b )           { m_activatesNewVps = b;         }
     297
     298   TComDecodedRps* getDecodedRps()                      { return &m_decodedRps;          }
     299
     300   Bool          isIrap()                               { return getSlice(0)->isIRAP(); }
     301   Bool          isBla ()                               { return getSlice(0)->isBla (); }
     302   Bool          isIdr ()                               { return getSlice(0)->isIdr (); }
     303   Bool          isCra ()                               { return getSlice(0)->isCra (); }
     304   Bool          isSlnr ()                              { return getSlice(0)->isSlnr (); }
     305   Bool          isRasl ()                              { return getSlice(0)->isRasl (); }
     306   Bool          isRadl ()                              { return getSlice(0)->isRadl (); }
     307   Bool          isStsa ()                              { return getSlice(0)->isStsa (); }
     308   Bool          isTsa ()                               { return getSlice(0)->isTsa  (); }
     309
     310   Void          print( Int outputLevel );
     311
     312#if NH_3D
     313   Void          setViewIndex          ( Int viewIndex )  { m_viewIndex = viewIndex;   }
     314   Int           getViewIndex          ()                 { return m_viewIndex;     }
     315
     316   Void          setIsDepth            ( Bool isDepth )   { m_isDepth = isDepth; }
     317   Bool          getIsDepth            ()                 { return m_isDepth; }
     318
     319   Void          setScaleOffset( Int** pS, Int** pO )     { m_aaiCodedScale = pS; m_aaiCodedOffset = pO; }
     320   Int**         getCodedScale ()                         { return m_aaiCodedScale;  }
     321   Int**         getCodedOffset()                         { return m_aaiCodedOffset; }
     322
     323   Void          compressMotion(Int scale);
     324   Void          printMotion( );
     325#if NH_3D_ARP
     326   Void          getCUAddrAndPartIdx( Int iX, Int iY, Int& riCuAddr, Int& riAbsZorderIdx );
     327#endif
     328#if NH_3D_QTLPC
     329   Bool          getReduceBitsFlag ()                     { return m_bReduceBitsQTL;     }
     330   Void          setReduceBitsFlag ( Bool bFlag )         { m_bReduceBitsQTL = bFlag;    }
    213331#endif
    214332#if NH_3D_NBDV
    215   Int           getNumDdvCandPics()                    {return m_iNumDdvCandPics;   }
    216   Int           getDisCandRefPictures(Int iColPOC);
    217   Void          setRapRefIdx(UInt uiRapRefIdx)         {m_uiRapRefIdx = uiRapRefIdx;}
    218   Void          setRapRefList(RefPicList eRefPicList)  {m_eRapRefList = eRefPicList;}
    219   Void          setNumDdvCandPics (Int i)              {m_iNumDdvCandPics = i;       }
    220   UInt          getRapRefIdx()                         {return m_uiRapRefIdx;       }
    221   RefPicList    getRapRefList()                        {return m_eRapRefList;       }
    222   Void          checkTemporalIVRef();
    223   Bool          isTempIVRefValid(Int currCandPic, Int iTempRefDir, Int iTempRefIdx);
    224   Void          checkTextureRef(  );
    225   Int           isTextRefValid(Int iTextRefDir, Int iTextRefIdx);
     333  Int            getNumDdvCandPics()                      { return m_iNumDdvCandPics;    }
     334  Int            getDisCandRefPictures(Int iColPOC);       
     335  Void           setRapRefIdx(UInt uiRapRefIdx)           { m_uiRapRefIdx = uiRapRefIdx; }
     336  Void           setRapRefList(RefPicList eRefPicList)    { m_eRapRefList = eRefPicList; }
     337  Void           setNumDdvCandPics (Int i)                { m_iNumDdvCandPics = i;       }
     338  UInt           getRapRefIdx()                           { return m_uiRapRefIdx;        }
     339  RefPicList     getRapRefList()                          { return m_eRapRefList;        }
     340  Void           checkTemporalIVRef();                     
     341  Bool           isTempIVRefValid(Int currCandPic, Int iTempRefDir, Int iTempRefIdx);
     342  Void           checkTextureRef(  );
     343  Int            isTextRefValid(Int iTextRefDir, Int iTextRefIdx);
     344#endif
     345#endif
    226346#endif
    227347
     
    241361
    242362#if NH_MV
     363
     364class TComAu : public TComList<TComPic*>
     365{
     366 
     367public:
     368
     369  Int                 getPoc            ( )                     {  assert(!empty()); return back()->getPOC            ();  }
     370  Void                setPicLatencyCount( Int picLatenyCount );
     371  Int                 getPicLatencyCount( )                     {  assert(!empty()); return back()->getPicLatencyCount();  } 
     372  TComPic*            getPic            ( Int nuhLayerId  );
     373  Void                addPic            ( TComPic* pic, Bool pocUnkown );
     374  Bool                containsPic       ( TComPic* pic ); 
     375};
     376
     377
     378class TComSubDpb : public TComList<TComPic*>
     379{
     380private:
     381  Int m_nuhLayerId;
     382public: 
     383  TComSubDpb( Int nuhLayerid );
     384
     385  Int                 getLayerId                      ( ) { return m_nuhLayerId; }
     386
     387  TComPic*            getPic                          ( Int poc  );
     388  TComPic*            getPicFromLsb                   ( Int pocLsb, Int maxPicOrderCntLsb );
     389  TComPic*            getShortTermRefPic              ( Int poc  );
     390  TComList<TComPic*>  getPicsMarkedNeedForOutput      ( );
     391
     392  Void                markAllAsUnusedForReference     ( );
     393
     394  Void                addPic                          ( TComPic* pic );
     395  Void                removePics                      ( std::vector<TComPic*> picToRemove );
     396  Bool                areAllPicsMarkedNotNeedForOutput( );
     397};
     398
    243399class TComPicLists
    244400{
    245401private:
    246   TComList<TComList<TComPic*>*> m_lists;
    247 #if NH_3D
    248   const TComVPS*                     m_vps;
     402  TComList<TComAu*    >       m_aus; 
     403  TComList<TComSubDpb*>       m_subDpbs;
     404  Bool                        m_printPicOutput;
     405#if NH_3D                     
     406  const TComVPS*              m_vps;
    249407#endif
    250408public:
    251   Void        push_back( TComList<TComPic*>* list ) { m_lists.push_back( list );   }
    252   Int         size     ()                           { return (Int) m_lists.size(); }
    253 #if NH_3D_ARP
    254   TComList<TComPic*>*  getPicList   ( Int layerIdInNuh );
    255 #endif
    256   TComPic*    getPic   ( Int layerIdInNuh,              Int poc );   
    257   TComPicYuv* getPicYuv( Int layerIdInNuh,              Int poc, Bool recon );
    258 #if NH_3D
    259   Void        setVPS   ( const TComVPS* vps ) { m_vps = vps;  };
    260   TComPic*    getPic   ( Int viewIndex, Bool depthFlag, Int poc );
    261   TComPicYuv* getPicYuv( Int viewIndex, Bool depthFlag, Int poc, Bool recon );
     409  ~TComPicLists();
     410
     411  // Add and remove single pictures
     412  Void                   addNewPic( TComPic* pic );
     413  Void                   removePic( TComPic* pic );
     414
     415  // Get Pics
     416  TComPic*               getPic                         ( Int layerIdInNuh, Int poc );
     417  TComPicYuv*            getPicYuv                      ( Int layerIdInNuh, Int poc, Bool recon );
     418
     419  // Get and AUs and SubDPBs
     420  TComSubDpb*            getSubDpb                      ( Int nuhLayerId, Bool create );
     421  TComList<TComSubDpb*>* getSubDpbs                     ( );
     422                                                       
     423  TComAu*                addAu                          ( Int poc  );
     424  TComAu*                getAu                          ( Int poc, Bool create );
     425  TComList<TComAu*>*     getAus                         ( );
     426  TComList<TComAu*>      getAusHavingPicsMarkedForOutput( );
     427
     428  // Mark pictures and set POCs
     429  Void                   markSubDpbAsUnusedForReference ( Int layerIdInNuh );
     430  Void                   markSubDpbAsUnusedForReference ( TComSubDpb& subDpb );
     431  Void                   markAllSubDpbAsUnusedForReference(  );
     432  Void                   decrementPocsInSubDpb          ( Int nuhLayerId, Int deltaPocVal );
     433 
     434  // Empty Sub DPBs
     435  Void                   emptyAllSubDpbs                ( );
     436  Void                   emptySubDpbs                   ( TComList<TComSubDpb*>* subDpbs);
     437  Void                   emptySubDpb                    ( TComSubDpb* subDpb);
     438  Void                   emptySubDpb                    ( Int nuhLayerId );
     439
     440  Void                   emptyNotNeedForOutputAndUnusedForRef      ( );
     441  Void                   emptySubDpbNotNeedForOutputAndUnusedForRef( Int layerId  );
     442  Void                   emptySubDpbNotNeedForOutputAndUnusedForRef( TComSubDpb subDpb ); 
     443
     444  // For printing to std::out
     445  Void                   setPrintPicOutput ( Bool printPicOutput ) { m_printPicOutput = printPicOutput; };
     446  Void                   print();
     447
     448#if NH_3D                                   
     449  Void                   setVPS                        ( const TComVPS* vps ) { m_vps = vps;  };
     450  TComPic*               getPic                        ( Int viewIndex, Bool depthFlag, Int poc );
     451  TComPicYuv*            getPicYuv                     ( Int viewIndex, Bool depthFlag, Int poc, Bool recon );
    262452#endif 
    263453
    264   Void print( ); 
    265 
    266 }; // END CLASS DEFINITION TComPicLists
    267 
    268 #endif
     454};
     455
     456// END CLASS DEFINITION TComPicLists
     457
     458#endif
     459
    269460
    270461//! \}
  • branches/HTM-15.0-dev0/source/Lib/TLibCommon/TComPicYuv.h

    r1313 r1317  
    166166  // Set border extension flag
    167167  Void          setBorderExtension(Bool b) { m_bIsBorderExtended = b; }
     168#if NH_MV
     169  Bool          getBorderExtension( )     { return m_bIsBorderExtended; }
     170#endif
    168171#if NH_3D
    169172  // Set Function
  • branches/HTM-15.0-dev0/source/Lib/TLibCommon/TComPrediction.cpp

    r1313 r1317  
    584584    pcCU->getSPAbsPartIdx(uiPartAddr, iSPWidth, iSPHeight, i, iNumSPInOneLine, uiSPAddr[i]);
    585585  }
    586 #if H_3D_ARP || NH_3D_ALIGN_SPIVMP_RP // check this!
     586#if NH_3D_ARP
    587587  if( pcCU->getARPW( uiPartAddr ) != 0 )
    588588  {
     
    13021302  TComMv      cMv         = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
    13031303  pcCU->clipMv(cMv);
     1304
     1305#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC
     1306  if ( g_traceMotionInfoBeforUniPred  )
     1307  {
     1308    std::cout << "RefPic POC     : " << pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()     << std::endl;
     1309    std::cout << "RefPic Layer Id: " << pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getLayerId() << std::endl;
     1310    std::cout << "RefIdx         : " << iRefIdx                                                           << std::endl;
     1311    std::cout << "RefPIcList     : " << eRefPicList                                                        << std::endl;
     1312  }
     1313#endif
     1314
    13041315#if NH_MV
    13051316  pcCU->checkMvVertRest(cMv, eRefPicList, iRefIdx );
     
    13091320  {
    13101321    if( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPOC()== pcCU->getSlice()->getPOC() )
    1311   {
     1322    {
    13121323      xPredInterUniARPviewRef( pcCU , uiPartAddr , iWidth , iHeight , eRefPicList , pcYuvPred , bi );
    1313   }
    1314   else
    1315   {
     1324    }
     1325    else
     1326    {
    13161327      xPredInterUniARP( pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, bi );
    13171328    }     
    1318     }
    1319     else
    1320     {
    1321 #endif
    1322   for (UInt comp=COMPONENT_Y; comp<pcYuvPred->getNumberValidComponents(); comp++)
    1323   {
    1324     const ComponentID compID=ComponentID(comp);
     1329  }
     1330  else
     1331  {
     1332#endif
     1333
     1334    for (UInt comp=COMPONENT_Y; comp<pcYuvPred->getNumberValidComponents(); comp++)
     1335    {
     1336      const ComponentID compID=ComponentID(comp);
    13251337#if NH_3D_IC
    1326     Bool bICFlag = pcCU->getICFlag( uiPartAddr ) && ( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getViewIndex() != pcCU->getSlice()->getViewIndex() ) && ( isLuma(compID) || (iWidth > 8) );
     1338      Bool bICFlag = pcCU->getICFlag( uiPartAddr ) && ( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getViewIndex() != pcCU->getSlice()->getViewIndex() ) && ( isLuma(compID) || (iWidth > 8) );
    13271339      xPredInterBlk(compID,  pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, pcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID))
    13281340#if NH_3D_ARP
     
    13311343        , bICFlag );
    13321344#else
    1333     xPredInterBlk  (compID,  pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, pcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)) );
    1334 #endif
    1335   }
     1345      xPredInterBlk  (compID,  pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, pcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)) );
     1346#endif
     1347    }
    13361348#if NH_3D_ARP
    13371349  }
     
    18131825)
    18141826{
     1827#if NH_MV
     1828  assert( refPic->getBorderExtension() );
     1829#endif
    18151830  Int     refStride  = refPic->getStride(compID);
    18161831  Int     dstStride  = dstPic->getStride(compID);
  • branches/HTM-15.0-dev0/source/Lib/TLibCommon/TComPrediction.h

    r1313 r1317  
    176176  Void          combineSegmentsWithMask( TComYuv* pInYuv[2], TComYuv* pOutYuv, Bool* pMask, UInt uiWidth, UInt uiHeight, UInt uiPartAddr, UInt partSize, Int bitDepthY );
    177177#endif
    178 
     178#if NH_3D
    179179  Pel  predIntraGetPredValDC      ( const Pel* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight, Bool bAbove, Bool bLeft );
    180 
     180#endif
    181181  Pel*  getPredictorPtr           ( const ComponentID compID, const Bool bUseFilteredPredictions )
    182182  {
  • branches/HTM-15.0-dev0/source/Lib/TLibCommon/TComRdCost.cpp

    r1313 r1317  
    133133  }
    134134
     135#if NH_MV
    135136  D_PRINT_INDENT( g_traceRDCost,  "Dist: " + n2s(uiDistortion) + " Bits: " + n2s(uiBits) + " RD Cost: " + n2s(dRdCost));
     137#endif
    136138  return dRdCost;
    137139}
     
    603605  cDtParam.bitDepth   = bitDepth;
    604606
    605 #if NH_3D_IC_FIX
    606607  cDtParam.bUseIC       = false;
    607 #endif
    608608#if NH_3D_SDC_INTER
    609609  cDtParam.bUseSDCMRSAD = false;
     
    36853685  }
    36863686
     3687#if NH_MV
    36873688  D_PRINT_INDENT( g_traceRDCost, "VSO Dist: " + n2s(uiDistortion) + " Bits: " + n2s(uiBits) + " RD Cost: " + n2s(dRdCost));
     3689#endif
    36883690
    36893691  return dRdCost;
  • branches/HTM-15.0-dev0/source/Lib/TLibCommon/TComRom.cpp

    r1313 r1317  
    222222#if NH_MV
    223223#if H_MV_HLS_PTL_LIMITS
    224  g_generalTierAndLevelLimits[ Level::LEVEL1   ] = TComGeneralTierAndLevelLimits(    36864,     350,  INT_MIN,   16,   1,   1 );
    225  g_generalTierAndLevelLimits[ Level::LEVEL2   ] = TComGeneralTierAndLevelLimits(   122880,    1500,  INT_MIN,   16,   1,   1 );
    226  g_generalTierAndLevelLimits[ Level::LEVEL2_1 ] = TComGeneralTierAndLevelLimits(   245760,    3000,  INT_MIN,   20,   1,   1 );
    227  g_generalTierAndLevelLimits[ Level::LEVEL3   ] = TComGeneralTierAndLevelLimits(   552960,    6000,  INT_MIN,   30,   2,   2 );
    228  g_generalTierAndLevelLimits[ Level::LEVEL3_1 ] = TComGeneralTierAndLevelLimits(   983040,   10000,  INT_MIN,   40,   3,   3 );
     224 g_generalTierAndLevelLimits[ Level::LEVEL1   ] = TComGeneralTierAndLevelLimits(    36864,     350,  MIN_INT,   16,   1,   1 );
     225 g_generalTierAndLevelLimits[ Level::LEVEL2   ] = TComGeneralTierAndLevelLimits(   122880,    1500,  MIN_INT,   16,   1,   1 );
     226 g_generalTierAndLevelLimits[ Level::LEVEL2_1 ] = TComGeneralTierAndLevelLimits(   245760,    3000,  MIN_INT,   20,   1,   1 );
     227 g_generalTierAndLevelLimits[ Level::LEVEL3   ] = TComGeneralTierAndLevelLimits(   552960,    6000,  MIN_INT,   30,   2,   2 );
     228 g_generalTierAndLevelLimits[ Level::LEVEL3_1 ] = TComGeneralTierAndLevelLimits(   983040,   10000,  MIN_INT,   40,   3,   3 );
    229229 g_generalTierAndLevelLimits[ Level::LEVEL4   ] = TComGeneralTierAndLevelLimits(  2228224,   12000,    30000,   75,   5,   5 );
    230230 g_generalTierAndLevelLimits[ Level::LEVEL4_1 ] = TComGeneralTierAndLevelLimits(  2228224,   20000,    50000,   75,   5,   5 );
     
    546546Bool g_disableNumbering = false;
    547547Bool g_disableHLSTrace = false;
    548 UInt64 g_stopAtCounter         = 4660;
    549 Bool g_traceCopyBack           = false;
    550 Bool g_decTraceDispDer         = false;
    551 Bool g_decTraceMvFromMerge     = false;
    552 Bool g_decTracePicOutput       = false;
     548UInt64 g_stopAtCounter       = 4660;
     549Bool g_traceCopyBack         = false;
     550Bool g_decTraceDispDer       = false;
     551Bool g_decTraceMvFromMerge   = false;
     552Bool g_decTracePicOutput     = false;
    553553Bool g_startStopTrace          = false;
    554 Bool g_outputPos               = false;
    555 Bool g_traceCameraParameters   = false;
    556 Bool g_encNumberOfWrittenBits  = false;
     554Bool g_outputPos             = false;   
     555Bool g_traceCameraParameters = false;
     556Bool g_encNumberOfWrittenBits     = false;
    557557Bool g_traceEncFracBits        = false;
    558558Bool g_traceIntraSearchCost    = false;
     
    561561Bool g_traceModeCheck          = false;
    562562UInt g_indent                  = false;
     563Bool g_decNumBitsRead          = false;
     564Bool g_traceMotionInfoBeforUniPred = false;
     565Bool g_traceMergeCandListConst = false;
     566Bool g_traceSubPBMotion       = false;
    563567#endif
    564568#endif
     
    693697  Bool startTrace = false;
    694698  if ( g_startStopTrace && poc == 0 && layerId == 0 )
    695   {   
     699  {
    696700    startTrace = ( cuPelX  == 0 ) && ( cuPelY  == 0 ) && ( cuWidth == 64 ) && ( cuHeight == 64 );
    697   }
     701    }
    698702  if ( startTrace )
    699703  {
     
    705709    g_traceModeCheck         = true;
    706710    g_traceCopyBack          = false;
    707  
     711    }
    708712  Bool stopTrace = false;
    709713  if ( g_startStopTrace && poc == 0 && layerId == 0 )
     
    752756    fflush ( g_hTrace );   
    753757  }
    754 }
    755 Void printStr( std::string str )
    756 {
    757   std::cout << str << std::endl;
    758 }
    759 Void printStrIndent( Bool b, std::string strStr )
    760 {
    761   if ( b )
    762   { 
    763     std::cout << std::string(g_indent, ' ');
    764     printStr( strStr );
    765   }
    766 }
    767 Void prinStrIncIndent( Bool b,  std::string strStr )
    768 {
    769   if ( b )
    770   {
    771     printStrIndent( true,  strStr );
    772     if (g_indent < 50)
    773     {
    774       g_indent++;
    775     }
    776   } 
    777 }
    778 Void decIndent( Bool b )
    779 {
    780   if (b && g_indent > 0)
    781   {
    782     g_indent--; 
    783   } 
    784758}
    785759#endif
  • branches/HTM-15.0-dev0/source/Lib/TLibCommon/TComRom.h

    r1313 r1317  
    9191extern const UChar  g_aucIntraModeNumFast_NotUseMPM[MAX_CU_DEPTH];
    9292extern const UChar  g_chroma422IntraAngleMappingTable[NUM_INTRA_MODE];
     93#if NH_3D_DMM
    9394// ====================================================================================================================
    9495// Depth coding modes
    9596// ====================================================================================================================
    96 #if NH_3D_DMM
     97
    9798extern const WedgeResolution                                 g_dmmWedgeResolution [6];
    9899extern const UChar                                           g_dmm1TabIdxBits     [6];
     
    193194 extern Bool   g_traceSAOCost;
    194195 extern UInt   g_indent;
     196extern Bool   g_traceMotionInfoBeforUniPred;
     197 extern Bool   g_traceMergeCandListConst;
     198 extern Bool   g_traceSubPBMotion;
    195199#define DTRACE_CU(x,y)             writeToTraceFile( x,y, g_traceCU );
    196200#define DTRACE_PU(x,y)             writeToTraceFile( x,y, g_tracePU );
     
    232236#define DTRACE_CABAC_R( x,y )
    233237#define DTRACE_CABAC_N
     238#if NH_MV
    234239#define DTRACE_CU(x,y) ;             
    235240#define DTRACE_PU(x,y) ;           
     
    242247#define D_PRINT_INC_INDENT( b, str );
    243248#define D_PRINT_INDENT( b, str );
    244 
     249#endif
    245250#endif
    246251const Char* nalUnitTypeToString(NalUnitType type);
  • branches/HTM-15.0-dev0/source/Lib/TLibCommon/TComSlice.cpp

    r1313 r1317  
    66 * Copyright (c) 2010-2015, ITU/ISO/IEC
    77 * All rights reserved.
     8
    89 *
    910 * Redistribution and use in source and binary forms, with or without
     
    112113, m_encCABACTableIdx              (I_SLICE)
    113114#if NH_MV
    114 , m_availableForTMVPRefFlag       ( true )
    115115, m_refPicSetInterLayer0          ( NULL )
    116116, m_refPicSetInterLayer1          ( NULL )
     
    121121, m_isDepth                       (false)
    122122#endif
    123 #if !H_MV_HLS7_GEN
     123#if NH_MV
    124124, m_pocResetFlag                  (false)
    125 #endif
    126 #if NH_MV
    127125, m_crossLayerBlaFlag             (false)
    128126#endif
     
    134132, m_pocResetIdc                   (0)
    135133, m_pocResetPeriodId              (0)
     134, m_hasPocResetPeriodIdPresent    (false)
    136135, m_fullPocResetFlag              (false)
    137136, m_pocLsbVal                     (0)
    138 , m_pocMsbValPresentFlag          (false)
    139 , m_pocMsbVal                     (0)
     137, m_pocMsbCycleValPresentFlag     (false)
     138, m_pocMsbCycleVal                (0)
    140139, m_pocMsbValRequiredFlag         (false)
    141140#endif
     
    155154#endif
    156155{
     156
     157#if NH_MV
     158  m_shortTermRefPicSetIdx = 0;
     159  m_numLongTermSps        = 0;
     160  m_numLongTermPics       = 0;
     161  for (Int i = 0; i < MAX_NUM_PICS_RPS; i++)
     162  {
     163    m_ltIdxSps          [i] = 0;
     164    m_deltaPocMsbCycleLt[i] = 0;
     165  }
     166  setSliceTemporalMvpEnabledFlag( false );
     167#endif
    157168  for(UInt i=0; i<NUM_REF_PIC_LIST_01; i++)
    158169  {
     
    790801#endif
    791802
     803
    792804Int TComSlice::getNumRpsCurrTempList() const
    793805{
     
    806818  }
    807819#if NH_MV
    808   numRpsCurrTempList = numRpsCurrTempList + getNumActiveRefLayerPics();
     820    numRpsCurrTempList = numRpsCurrTempList + getNumActiveRefLayerPics();
    809821#endif
    810822  return numRpsCurrTempList;
     
    10971109  m_pcVPS                = pSrc->m_pcVPS;
    10981110#endif
    1099   m_pRPS                = pSrc->m_pRPS;  m_iLastIDR             = pSrc->m_iLastIDR;
     1111  m_pRPS                = pSrc->m_pRPS;
     1112  m_iLastIDR             = pSrc->m_iLastIDR;
    11001113
    11011114  m_pcPic                = pSrc->m_pcPic;
     
    11551168#if NH_MV
    11561169  // Additional slice header syntax elements
    1157 #if !H_MV_HLS7_GEN
    11581170  m_pocResetFlag               = pSrc->m_pocResetFlag;
    1159 #endif
    11601171  m_discardableFlag            = pSrc->m_discardableFlag;
    11611172  m_interLayerPredEnabledFlag  = pSrc->m_interLayerPredEnabledFlag;
     
    26702681  }
    26712682}
    2672 #endif
    2673 
     2683
     2684#endif
    26742685#endif // NH_MV
    26752686
     
    27192730, m_uiBitsForPOC              (  8)
    27202731, m_numLongTermRefPicSPS      (  0)
     2732#if NH_MV
     2733, m_numShortTermRefPicSets    (   0)
     2734#endif
    27212735, m_uiMaxTrSize               ( 32)
    27222736, m_bUseSAO                   (false)
     
    27502764  for ( Int i = 0; i < MAX_TLAYER; i++ )
    27512765  {
     2766#if NH_MV
     2767    m_uiSpsMaxLatencyIncreasePlus1[i] = 0;
     2768#else
    27522769    m_uiMaxLatencyIncrease[i] = 0;
     2770#endif
    27532771    m_uiMaxDecPicBuffering[i] = 1;
    27542772    m_numReorderPics[i]       = 0;
     
    30813099Void TComSPS::inferSpsMaxDecPicBufferingMinus1( TComVPS* vps, Int targetOptLayerSetIdx, Int currLayerId, Bool encoder )
    30823100{
    3083   const std::vector<Int>& targetDecLayerIdList = vps->getTargetDecLayerIdList( vps->olsIdxToLsIdx( targetOptLayerSetIdx ));
    3084 
    30853101  if ( getMultiLayerExtSpsFlag() )
    30863102  {
     3103    const std::vector<Int>& targetDecLayerIdList = vps->getTargetDecLayerIdList( vps->olsIdxToLsIdx( targetOptLayerSetIdx ));
    30873104    Int layerIdx = 0;         
    30883105    while (layerIdx < (Int) targetDecLayerIdList.size() )
     
    31093126        // This preliminary fix needs to be checked.
    31103127        assert( getNumReorderPics( i )     == maxNumReorderPics       );
    3111         assert( getMaxLatencyIncrease( i ) == maxLatencyIncreasePlus1 );
     3128        assert( getSpsMaxLatencyIncreasePlus1( i ) == maxLatencyIncreasePlus1 );
    31123129
    31133130      }
     
    31173134        setMaxDecPicBuffering( maxDecPicBufferingMinus1 + 1 , i);
    31183135        setNumReorderPics    ( maxNumReorderPics, i );
    3119         setMaxLatencyIncrease( maxLatencyIncreasePlus1 - 1 , i);
     3136        setSpsMaxLatencyIncreasePlus1( maxLatencyIncreasePlus1 , i);
    31203137      }
    31213138    }   
     
    34123429  }
    34133430}
    3414 
    34153431Void TComSlice::markIvRefPicsAsShortTerm( std::vector<TComPic*> refPicSetInterLayer0, std::vector<TComPic*> refPicSetInterLayer1 )
    34163432{
     
    34353451    for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[li]-1); rIdx ++)
    34363452    {     
    3437       if (rIdx == 0 && li == 0) m_apcRefPicList[li][rIdx]->print( true );
     3453      if (rIdx == 0 && li == 0) m_apcRefPicList[li][rIdx]->print( 1 );
     3454      m_apcRefPicList[li][rIdx]->print( 0 );     
    34383455       
    3439       m_apcRefPicList[li][rIdx]->print( false );
    34403456    }
    34413457  }
     
    34563472  m_refPicSetInterLayer1 = refPicSetInterLayer1;
    34573473}
     3474
     3475TComPic* TComSlice::getRefPicSetInterLayer( Int setIdc, Int i ) const
     3476{
     3477  TComPic* pic = NULL;
     3478  if (setIdc == 0 )
     3479  {
     3480    pic = (*m_refPicSetInterLayer0)[ i ];
     3481  }
     3482  else if (setIdc == 1 )
     3483  {
     3484    pic = (*m_refPicSetInterLayer1)[ i ];
     3485  }
     3486
     3487  assert( pic != NULL );   
     3488
     3489  return pic;
     3490}
     3491
    34583492
    34593493TComPic* TComSlice::getPicFromRefPicSetInterLayer(Int setIdc, Int layerId ) const
     
    35723606#endif
    35733607}
     3608#endif
    35743609#if NH_3D_NBDV
    35753610Void TComSlice::setDefaultRefView()
     
    36873722      if( iViewIdx<getViewIndex() && !bIsDepth )
    36883723      {
    3689         setBaseViewRefPicList( ivPicLists->getPicList( iLayerId ), iViewIdx );
     3724        setBaseViewRefPicList( ivPicLists->getSubDpb( iLayerId, false ), iViewIdx );
    36903725      }
    36913726    }
     
    37103745        if ( pcCurrPic->getViewIndex() != pcRefPic->getViewIndex() )
    37113746        {
    3712           existInterViewRef = true;       
     3747          existInterViewRef = true;
    37133748        }
    37143749      }