source: SHVCSoftware/branches/SHM-upgrade/source/Lib/TLibDecoder/TDecTop.cpp @ 1014

Last change on this file since 1014 was 1010, checked in by seregin, 10 years ago

port the fix for the ticket #56 (rev 1009)

  • Property svn:eol-style set to native
File size: 121.1 KB
RevLine 
[313]1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
[916]4 * granted under this license.
[313]5 *
[595]6 * Copyright (c) 2010-2014, ITU/ISO/IEC
[313]7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TDecTop.cpp
35    \brief    decoder class
36*/
37
38#include "NALread.h"
39#include "TDecTop.h"
[916]40#if RExt__DECODER_DEBUG_BIT_STATISTICS
41#include "TLibCommon/TComCodingStatistics.h"
42#endif
[313]43
44#if SVC_EXTENSION
45UInt  TDecTop::m_prevPOC = MAX_UINT;
46UInt  TDecTop::m_uiPrevLayerId = MAX_UINT;
47Bool  TDecTop::m_bFirstSliceInSequence = true;
[851]48#if POC_RESET_RESTRICTIONS
49Bool  TDecTop::m_checkPocRestrictionsForCurrAu       = false;
50Int   TDecTop::m_pocResetIdcOrCurrAu                 = -1;
51Bool  TDecTop::m_baseLayerIdrFlag                    = false;
52Bool  TDecTop::m_baseLayerPicPresentFlag             = false;
53Bool  TDecTop::m_baseLayerIrapFlag                   = false;
54Bool  TDecTop::m_nonBaseIdrPresentFlag               = false;
55Int   TDecTop::m_nonBaseIdrType                      = -1;
56Bool  TDecTop::m_picNonIdrWithRadlPresentFlag        = false;
57Bool  TDecTop::m_picNonIdrNoLpPresentFlag            = false;
[313]58#endif
[854]59#if POC_RESET_VALUE_RESTRICTION
60Int   TDecTop::m_crossLayerPocResetPeriodId          = -1;
61Int   TDecTop::m_crossLayerPocResetIdc               = -1;
[851]62#endif
[854]63#endif
[313]64
65//! \ingroup TLibDecoder
66//! \{
67
68TDecTop::TDecTop()
[916]69  : m_pDecodedSEIOutputStream(NULL)
[313]70{
71  m_pcPic = 0;
72  m_iMaxRefPicNum = 0;
73#if ENC_DEC_TRACE
[916]74  if (g_hTrace == NULL)
75  {
76    g_hTrace = fopen( "TraceDec.txt", "wb" );
77  }
[313]78  g_bJustDoIt = g_bEncDecTraceDisable;
79  g_nSymbolCounter = 0;
80#endif
[442]81  m_associatedIRAPType = NAL_UNIT_INVALID;
[313]82  m_pocCRA = 0;
[916]83  m_pocRandomAccess = MAX_INT;
[313]84#if !SVC_EXTENSION
85  m_prevPOC                = MAX_INT;
86#endif
87  m_bFirstSliceInPicture    = true;
88#if !SVC_EXTENSION
89  m_bFirstSliceInSequence   = true;
90#endif
91#if SVC_EXTENSION
92  m_layerId = 0;
[1006]93#if R0235_SMALLEST_LAYER_ID
94  m_smallestLayerId = 0;
95#endif
[313]96#if AVC_BASE
97  m_pBLReconFile = NULL;
98#endif
99  memset(m_cIlpPic, 0, sizeof(m_cIlpPic));
100#endif
[442]101  m_prevSliceSkipped = false;
102  m_skippedPOC = 0;
[713]103  m_bFirstSliceInBitstream  = true;
104  m_lastPOCNoOutputPriorPics = -1;
105  m_craNoRaslOutputFlag = false;
106  m_isNoOutputPriorPics = false;
[815]107#if Q0177_EOS_CHECKS
108  m_isLastNALWasEos = false;
109#endif
[979]110#if R0071_IRAP_EOS_CROSS_LAYER_IMPACTS
111  m_lastPicHasEos = false;
112#endif
[540]113#if NO_CLRAS_OUTPUT_FLAG
114  m_noClrasOutputFlag          = false;
115  m_layerInitializedFlag       = false;
[713]116  m_firstPicInLayerDecodedFlag = false; 
[540]117#endif
[588]118#if RESOLUTION_BASED_DPB
119  m_subDpbIdx = -1;
120#endif
[815]121#if POC_RESET_IDC_DECODER
122  m_parseIdc = -1;
123  m_lastPocPeriodId = -1;
124  m_prevPicOrderCnt = 0;
125#endif
[713]126#if Q0048_CGS_3D_ASYMLUT
127  m_pColorMappedPic = NULL;
128#endif
129
[851]130#if POC_RESET_RESTRICTIONS
131  resetPocRestrictionCheckParameters();
132#endif
[903]133#if P0297_VPS_POC_LSB_ALIGNED_FLAG
134  m_pocResettingFlag        = false;
135  m_pocDecrementedInDPBFlag = false;
136#endif
[928]137#if CONFORMANCE_BITSTREAM_MODE
138  m_confModeFlag = false;
139#endif
[962]140#if FIX_NON_OUTPUT_LAYER
141  m_isOutputLayerFlag = false;
142#endif
[313]143}
144
145TDecTop::~TDecTop()
146{
147#if ENC_DEC_TRACE
[916]148  if (g_hTrace != stdout)
149  {
150    fclose( g_hTrace );
151  }
[313]152#endif
[713]153#if Q0048_CGS_3D_ASYMLUT
154  if(m_pColorMappedPic)
155  {
156    m_pColorMappedPic->destroy();
157    delete m_pColorMappedPic;
158    m_pColorMappedPic = NULL;
159  }
160#endif
[313]161}
162
163Void TDecTop::create()
164{
165#if SVC_EXTENSION
166  m_cGopDecoder.create( m_layerId );
167#else
168  m_cGopDecoder.create();
169#endif
170  m_apcSlicePilot = new TComSlice;
171  m_uiSliceIdx = 0;
172}
173
174Void TDecTop::destroy()
175{
176  m_cGopDecoder.destroy();
[916]177
[313]178  delete m_apcSlicePilot;
179  m_apcSlicePilot = NULL;
[916]180
[313]181  m_cSliceDecoder.destroy();
[442]182#if SVC_EXTENSION
[313]183  for(Int i=0; i<MAX_NUM_REF; i++)
184  {
185    if(m_cIlpPic[i])
186    {
187      m_cIlpPic[i]->destroy();
188      delete m_cIlpPic[i];
189      m_cIlpPic[i] = NULL;
190    }
[822]191  }
[313]192#endif
193}
194
195Void TDecTop::init()
196{
197#if !SVC_EXTENSION
198  // initialize ROM
199  initROM();
200#endif
201#if SVC_EXTENSION
202  m_cGopDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
[644]203  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder, m_cSAO.getSaoMaxOffsetQVal() );
[313]204#else
205  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
206  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
207#endif
208  m_cEntropyDecoder.init(&m_cPrediction);
209}
210
211Void TDecTop::deletePicBuffer ( )
212{
213  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
214  Int iSize = Int( m_cListPic.size() );
[916]215
[313]216  for (Int i = 0; i < iSize; i++ )
217  {
218    TComPic* pcPic = *(iterPic++);
219#if SVC_EXTENSION
220    if( pcPic )
221    {
222      pcPic->destroy();
223
224      delete pcPic;
225      pcPic = NULL;
226    }
227#else
228    pcPic->destroy();
[916]229
[313]230    delete pcPic;
231    pcPic = NULL;
232#endif
233  }
[916]234
[313]235  m_cSAO.destroy();
[916]236
[313]237  m_cLoopFilter.        destroy();
238 
239#if !SVC_EXTENSION
240  // destroy ROM
241  destroyROM();
242#endif
243}
244
245Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
246{
247  Int  numReorderPics[MAX_TLAYER];
[869]248#if R0156_CONF_WINDOW_IN_REP_FORMAT
249  Window &conformanceWindow = pcSlice->getConformanceWindow();
250#else
[313]251  Window &conformanceWindow = pcSlice->getSPS()->getConformanceWindow();
[869]252#endif
[313]253  Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window();
254
[916]255  for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++)
[313]256  {
[540]257#if USE_DPB_SIZE_TABLE
[588]258    if( getCommonDecoderParams()->getTargetOutputLayerSetIdx() == 0 )
[540]259    {
260      assert( this->getLayerId() == 0 );
261      numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer);
262    }
263    else
264    {
265      TComVPS *vps = pcSlice->getVPS();
266      // SHM decoders will use DPB size table in the VPS to determine the number of reorder pictures.
[588]267      numReorderPics[temporalLayer] = vps->getMaxVpsNumReorderPics( getCommonDecoderParams()->getTargetOutputLayerSetIdx() , temporalLayer);
[540]268    }
269#else
[313]270    numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer);
[540]271#endif
[313]272  }
273
[540]274#if USE_DPB_SIZE_TABLE
[588]275  if( getCommonDecoderParams()->getTargetOutputLayerSetIdx() == 0 )
[540]276  {
277    assert( this->getLayerId() == 0 );
278    m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
279  }
280  else
281  {
[588]282#if RESOLUTION_BASED_DPB
283    Int layerSetIdxForOutputLayerSet = pcSlice->getVPS()->getOutputLayerSetIdx( getCommonDecoderParams()->getTargetOutputLayerSetIdx() );
284    Int layerIdx = pcSlice->getVPS()->findLayerIdxInLayerSet( layerSetIdxForOutputLayerSet, pcSlice->getLayerId() );  assert( layerIdx != -1 );
285    m_iMaxRefPicNum = pcSlice->getVPS()->getMaxVpsLayerDecPicBuffMinus1( getCommonDecoderParams()->getTargetOutputLayerSetIdx(), layerIdx, pcSlice->getTLayer() ) + 1; // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
286#else
287    m_iMaxRefPicNum = pcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1( getCommonDecoderParams()->getTargetOutputLayerSetIdx(), pcSlice->getLayerId(), pcSlice->getTLayer() ) + 1; // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
[874]288    //TODO: HENDRY -- Do the checking here.
[588]289#endif
[540]290  }
291#else
[313]292  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
[540]293#endif
[345]294
295#if SVC_EXTENSION
296  m_iMaxRefPicNum += 1; // it should be updated if more than 1 resampling picture is used
297#endif
298
[313]299  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
300  {
301    rpcPic = new TComPic();
302
303#if SVC_EXTENSION //Temporal solution, should be modified
304    if(m_layerId > 0)
305    {
306      for(UInt i = 0; i < pcSlice->getVPS()->getNumDirectRefLayers( m_layerId ); i++ )
307      {
[849]308#if MOVE_SCALED_OFFSET_TO_PPS
[540]309#if O0098_SCALED_REF_LAYER_ID
[849]310        const Window scalEL = pcSlice->getPPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, i));
311#else
312        const Window scalEL = pcSlice->getPPS()->getScaledRefLayerWindow(i);
313#endif
314#else
315#if O0098_SCALED_REF_LAYER_ID
[540]316        const Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, i));
317#else
[313]318        const Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(i);
[540]319#endif
[849]320#endif
321#if REF_REGION_OFFSET
322        const Window refEL = pcSlice->getPPS()->getRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, i));
[873]323#if RESAMPLING_FIX
324        Bool equalOffsets = scalEL.hasEqualOffset(refEL);
325#if R0209_GENERIC_PHASE
326        Bool zeroPhase = pcSlice->getPPS()->hasZeroResamplingPhase(pcSlice->getVPS()->getRefLayerId(m_layerId, i));
327#endif
328#else
[849]329        Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0
330                             && refEL.getWindowLeftOffset() == 0 && refEL.getWindowRightOffset() == 0 && refEL.getWindowTopOffset() == 0 && refEL.getWindowBottomOffset() == 0 );
[873]331#endif
[849]332#else
[313]333        Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
[849]334#endif
[313]335
336#if VPS_EXTN_DIRECT_REF_LAYERS
337        TDecTop *pcTDecTopBase = (TDecTop *)getRefLayerDec( i );
338#else
339        TDecTop *pcTDecTopBase = (TDecTop *)getLayerDec( m_layerId-1 );
340#endif
341        //TComPic*                      pcPic = *(pcTDecTopBase->getListPic()->begin());
342        TComPicYuv* pcPicYuvRecBase = (*(pcTDecTopBase->getListPic()->begin()))->getPicYuvRec(); 
[442]343#if REPN_FORMAT_IN_VPS
[644]344#if O0194_DIFFERENT_BITDEPTH_EL_BL
345        UInt refLayerId = pcSlice->getVPS()->getRefLayerId(m_layerId, i);
[916]346        Bool sameBitDepths = ( g_bitDepthLayer[CHANNEL_TYPE_LUMA][m_layerId] == g_bitDepthLayer[CHANNEL_TYPE_LUMA][refLayerId] ) && ( g_bitDepthLayer[CHANNEL_TYPE_CHROMA][m_layerId] == g_bitDepthLayer[CHANNEL_TYPE_CHROMA][refLayerId] );
[644]347
[901]348#if REF_IDX_MFM
[916]349        if( pcPicYuvRecBase->getWidth(COMPONENT_Y) == pcSlice->getPicWidthInLumaSamples() && pcPicYuvRecBase->getHeight(COMPONENT_Y) == pcSlice->getPicHeightInLumaSamples() && equalOffsets && zeroPhase )
[901]350        {
351          rpcPic->setEqualPictureSizeAndOffsetFlag( i, true );
352        }
353
354        if( !rpcPic->equalPictureSizeAndOffsetFlag(i) || !sameBitDepths
355#else
[873]356        if( pcPicYuvRecBase->getWidth() != pcSlice->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getPicHeightInLumaSamples() || !sameBitDepths
357#if REF_REGION_OFFSET && RESAMPLING_FIX
358          || !equalOffsets
359#if R0209_GENERIC_PHASE
360          || !zeroPhase
361#endif
362#else
363          || !zeroOffsets
364#endif
[901]365#endif
[713]366#if Q0048_CGS_3D_ASYMLUT
367          || pcSlice->getPPS()->getCGSFlag() > 0
368#endif
369#if LAYER_CTB
370          || pcTDecTopBase->getActiveSPS()->getMaxCUWidth() != m_ppcTDecTop[m_layerId]->getActiveSPS()->getMaxCUWidth() || pcTDecTopBase->getActiveSPS()->getMaxCUHeight() != m_ppcTDecTop[m_layerId]->getActiveSPS()->getMaxCUHeight() || pcTDecTopBase->getActiveSPS()->getMaxCUDepth() != m_ppcTDecTop[m_layerId]->getActiveSPS()->getMaxCUDepth()
371#endif
372          )
[644]373#else
[873]374        if(pcPicYuvRecBase->getWidth() != pcSlice->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getPicHeightInLumaSamples()
375#if REF_REGION_OFFSET && RESAMPLING_FIX
376          || !equalOffsets
377#if R0209_GENERIC_PHASE
378          || !zeroPhase
[644]379#endif
[442]380#else
[873]381          || !zeroOffsets
[442]382#endif
[873]383        )
384#endif
385#else
386        if(pcPicYuvRecBase->getWidth() != pcSlice->getSPS()->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getSPS()->getPicHeightInLumaSamples()
387#if REF_REGION_OFFSET && RESAMPLING_FIX
388          || !equalOffsets
389#if R0209_GENERIC_PHASE
390          || !zeroPhase
391#endif
392#else
393          || !zeroOffsets
394#endif
395        )
396#endif
[313]397        {
398          rpcPic->setSpatialEnhLayerFlag( i, true );
399
400          //only for scalable extension
[815]401          assert( pcSlice->getVPS()->getScalabilityMask( SCALABILITY_ID ) == true );
[313]402        }
403      }
404    }
[815]405
[442]406#if REPN_FORMAT_IN_VPS
[494]407    rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
408                     conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
409#else
410    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
411                     conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
412#endif
[815]413
414#else //SVC_EXTENSION
[916]415    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
[313]416                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
[815]417#endif //SVC_EXTENSION
418   
[313]419    m_cListPic.pushBack( rpcPic );
[916]420
[313]421    return;
422  }
[916]423
[313]424  Bool bBufferIsAvailable = false;
425  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
426  while (iterPic != m_cListPic.end())
427  {
428    rpcPic = *(iterPic++);
429    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
430    {
431      rpcPic->setOutputMark(false);
432      bBufferIsAvailable = true;
433      break;
434    }
435
436    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
437    {
438#if !SVC_EXTENSION
439      rpcPic->setOutputMark(false);
440#endif
441      rpcPic->setReconMark( false );
442      rpcPic->getPicYuvRec()->setBorderExtension( false );
443      bBufferIsAvailable = true;
444      break;
445    }
446  }
[916]447
[313]448  if ( !bBufferIsAvailable )
449  {
450    //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer.
451    m_iMaxRefPicNum++;
452    rpcPic = new TComPic();
453    m_cListPic.pushBack( rpcPic );
454  }
455  rpcPic->destroy();
456
[815]457#if SVC_EXTENSION
[442]458#if REPN_FORMAT_IN_VPS
[494]459  rpcPic->create ( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
460                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
461#else
462  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
463                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
464#endif
[815]465#else  //SVC_EXTENSION
[916]466  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
[313]467                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
[815]468#endif //SVC_EXTENSION
[313]469}
470
471Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic)
472{
473  if (!m_pcPic)
474  {
475    /* nothing to deblock */
476    return;
477  }
478
[916]479  TComPic*   pcPic         = m_pcPic;
480
[313]481  // Execute Deblock + Cleanup
[916]482
[313]483  m_cGopDecoder.filterPicture(pcPic);
484
[962]485#if FIX_NON_OUTPUT_LAYER
486  if( this->getLayerDec(pcPic->getLayerId())->m_isOutputLayerFlag == false )
487  {
488    pcPic->setOutputMark( false );
489  }
490#endif
491
[313]492  TComSlice::sortPicList( m_cListPic ); // sorting for application output
493  poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
[916]494  rpcListPic          = &m_cListPic;
495  m_cCuDecoder.destroy();
[313]496  m_bFirstSliceInPicture  = true;
497
498  return;
499}
500
[916]501Void TDecTop::checkNoOutputPriorPics (TComList<TComPic*>* pcListPic)
[713]502{
[916]503  if (!pcListPic || !m_isNoOutputPriorPics) return;
[713]504
[916]505  TComList<TComPic*>::iterator  iterPic   = pcListPic->begin();
[713]506
[916]507  while (iterPic != pcListPic->end())
[713]508  {
[916]509    TComPic* pcPicTmp = *(iterPic++);
[713]510    if (m_lastPOCNoOutputPriorPics != pcPicTmp->getPOC())
511    {
512      pcPicTmp->setOutputMark(false);
513    }
514  }
515}
516
[916]517Void TDecTop::xCreateLostPicture(Int iLostPoc)
[442]518{
[313]519  printf("\ninserting lost poc : %d\n",iLostPoc);
520  TComSlice cFillSlice;
[540]521  cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
522  cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
[313]523#if SVC_EXTENSION
[540]524  cFillSlice.setVPS( m_parameterSetManagerDecoder.getFirstVPS() );
[313]525  cFillSlice.initSlice( m_layerId );
526#else
527  cFillSlice.initSlice();
528#endif
529  TComPic *cFillPic;
530  xGetNewPicBuffer(&cFillSlice,cFillPic);
[540]531  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
532  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
[313]533#if SVC_EXTENSION
[540]534  cFillPic->getSlice(0)->setVPS( m_parameterSetManagerDecoder.getFirstVPS() );
[313]535  cFillPic->getSlice(0)->initSlice( m_layerId );
536#else
537  cFillPic->getSlice(0)->initSlice();
538#endif
539 
540  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
541  Int closestPoc = 1000000;
542  while ( iterPic != m_cListPic.end())
543  {
544    TComPic * rpcPic = *(iterPic++);
545    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)<closestPoc&&abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)!=0&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
546    {
547      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
548    }
549  }
550  iterPic = m_cListPic.begin();
551  while ( iterPic != m_cListPic.end())
552  {
553    TComPic *rpcPic = *(iterPic++);
554    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
555    {
556      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
557      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
558      break;
559    }
560  }
561  cFillPic->setCurrSliceIdx(0);
[916]562  for(Int ctuRsAddr=0; ctuRsAddr<cFillPic->getNumberOfCtusInFrame(); ctuRsAddr++)
[313]563  {
[916]564    cFillPic->getCtu(ctuRsAddr)->initCtu(cFillPic, ctuRsAddr);
[313]565  }
566  cFillPic->getSlice(0)->setReferenced(true);
567  cFillPic->getSlice(0)->setPOC(iLostPoc);
568  cFillPic->setReconMark(true);
569  cFillPic->setOutputMark(true);
570  if(m_pocRandomAccess == MAX_INT)
571  {
572    m_pocRandomAccess = iLostPoc;
573  }
574}
575
576
577Void TDecTop::xActivateParameterSets()
578{
579  m_parameterSetManagerDecoder.applyPrefetchedPS();
[916]580
[313]581  TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
582  assert (pps != 0);
583
584  TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId());
585  assert (sps != 0);
586
587  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
588  {
589    printf ("Parameter set activation failed!");
590    assert (0);
591  }
592
[540]593#if SCALINGLIST_INFERRING
594  // scaling list settings and checks
595  TComVPS *activeVPS = m_parameterSetManagerDecoder.getActiveVPS();
596  TComSPS *activeSPS = m_parameterSetManagerDecoder.getActiveSPS();
597  TComPPS *activePPS = m_parameterSetManagerDecoder.getActivePPS();
598
599  if( activeSPS->getInferScalingListFlag() )
600  {
601    UInt refLayerId = activeSPS->getScalingListRefLayerId();
602    TComSPS *refSps = m_ppcTDecTop[refLayerId]->getParameterSetManager()->getActiveSPS(); assert( refSps != NULL );
603
604    // When avc_base_layer_flag is equal to 1, it is a requirement of bitstream conformance that the value of sps_scaling_list_ref_layer_id shall be greater than 0
[874]605#if VPS_AVC_BL_FLAG_REMOVAL
606    if( activeVPS->getNonHEVCBaseLayerFlag() )
607#else
[540]608    if( activeVPS->getAvcBaseLayerFlag() )
[874]609#endif
[540]610    {
611      assert( refLayerId > 0 );
612    }
613
614    // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and
615    // sps_infer_scaling_list_flag in the SPS is equal to 1, sps_infer_scaling_list_flag shall be equal to 0 for the SPS that is active for the layer with nuh_layer_id equal to sps_scaling_list_ref_layer_id
616    assert( refSps->getInferScalingListFlag() == false );
617
618    // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB,
619    // the layer with nuh_layer_id equal to sps_scaling_list_ref_layer_id shall be a direct or indirect reference layer of the layer with nuh_layer_id equal to nuhLayerIdB
620    assert( activeVPS->getRecursiveRefLayerFlag( activeSPS->getLayerId(), refLayerId ) == true );
621   
622    if( activeSPS->getScalingList() != refSps->getScalingList() )
623    {
624      // delete created instance of scaling list since it will be inferred
625      delete activeSPS->getScalingList();
626
627      // infer scaling list
628      activeSPS->setScalingList( refSps->getScalingList() );
629    }
630  }
631
632  if( activePPS->getInferScalingListFlag() )
633  {
634    UInt refLayerId = activePPS->getScalingListRefLayerId();
635    TComPPS *refPps = m_ppcTDecTop[refLayerId]->getParameterSetManager()->getActivePPS(); assert( refPps != NULL );
636
637    // When avc_base_layer_flag is equal to 1, it is a requirement of bitstream conformance that the value of sps_scaling_list_ref_layer_id shall be greater than 0
[874]638#if VPS_AVC_BL_FLAG_REMOVAL
639    if( activeVPS->getNonHEVCBaseLayerFlag() )
640#else
[540]641    if( activeVPS->getAvcBaseLayerFlag() )
[874]642#endif
[540]643    {
644      assert( refLayerId > 0 );
645    }
646
647    // It is a requirement of bitstream conformance that, when an PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and
648    // pps_infer_scaling_list_flag in the PPS is equal to 1, pps_infer_scaling_list_flag shall be equal to 0 for the PPS that is active for the layer with nuh_layer_id equal to pps_scaling_list_ref_layer_id
649    assert( refPps->getInferScalingListFlag() == false );
650
651    // It is a requirement of bitstream conformance that, when an PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB,
652    // the layer with nuh_layer_id equal to pps_scaling_list_ref_layer_id shall be a direct or indirect reference layer of the layer with nuh_layer_id equal to nuhLayerIdB
653    assert( activeVPS->getRecursiveRefLayerFlag( activePPS->getLayerId(), refLayerId ) == true );
654   
655    if( activePPS->getScalingList() != refPps->getScalingList() )
656    {
657      // delete created instance of scaling list since it will be inferred
658      delete activePPS->getScalingList();
659
660      // infer scaling list
661      activePPS->setScalingList( refPps->getScalingList() );
662    }
663
664  }
665#endif
666
[713]667#if AVC_BASE
[874]668#if VPS_AVC_BL_FLAG_REMOVAL
669  if( activeVPS->getNonHEVCBaseLayerFlag() )
670#else
[713]671  if( activeVPS->getAvcBaseLayerFlag() )
[874]672#endif
[713]673  {
674    TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
675    if( m_layerId == 1 && pBLPic->getPicYuvRec() == NULL )
676    {
677      UInt refLayerId = 0;
678      RepFormat* repFormat = activeVPS->getVpsRepFormat( activeVPS->getVpsRepFormatIdx(refLayerId) );
679
680      Int  numReorderPics[MAX_TLAYER];
[869]681#if !R0156_CONF_WINDOW_IN_REP_FORMAT
[713]682      Window conformanceWindow;
[869]683#endif
[713]684      Window defaultDisplayWindow;
685
[869]686#if R0156_CONF_WINDOW_IN_REP_FORMAT
[713]687#if AUXILIARY_PICTURES
[869]688      pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), repFormat->getChromaFormatVpsIdc(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), repFormat->getConformanceWindowVps(), defaultDisplayWindow, numReorderPics, NULL, true);
689#else
690      pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), repFormat->getConformanceWindowVps(), defaultDisplayWindow, numReorderPics, NULL, true);
691#endif
692#else
693#if AUXILIARY_PICTURES
[713]694      pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), repFormat->getChromaFormatVpsIdc(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, NULL, true);
695#else
696      pBLPic->create( repFormat->getPicWidthVpsInLumaSamples(), repFormat->getPicHeightVpsInLumaSamples(), activeSPS->getMaxCUWidth(), activeSPS->getMaxCUHeight(), activeSPS->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, NULL, true);
697#endif
[869]698#endif
[713]699      // it is needed where the VPS is accessed through the slice
700      pBLPic->getSlice(0)->setVPS( activeVPS );
701
702#if O0194_DIFFERENT_BITDEPTH_EL_BL
[916]703      g_bitDepthLayer[CHANNEL_TYPE_LUMA][0] = repFormat->getBitDepthVpsLuma();
704      g_bitDepthLayer[CHANNEL_TYPE_CHROMA][0] = repFormat->getBitDepthVpsChroma();
[713]705#endif
706    }
707  }
708#endif
709
[644]710#if P0312_VERT_PHASE_ADJ
[849]711#if MOVE_SCALED_OFFSET_TO_PPS
[644]712  if( activeVPS->getVpsVuiVertPhaseInUseFlag() == 0 )
713  {   
[849]714    for(Int i = 0; i < activePPS->getNumScaledRefLayerOffsets(); i++)
715    {
716      UInt scaledRefLayerId = activePPS->getScaledRefLayerId(i);
717      if( activePPS->getVertPhasePositionEnableFlag( scaledRefLayerId ) )
718      {
719        printf("\nWarning: LayerId = %d: vert_phase_position_enable_flag[%d] = 1, however indication vert_phase_position_in_use_flag = 0\n", m_layerId, scaledRefLayerId );
720        break;
721      }
722    }
723  }
724#else
725  if( activeVPS->getVpsVuiVertPhaseInUseFlag() == 0 )
726  {   
[644]727    for(Int i = 0; i < activeSPS->getNumScaledRefLayerOffsets(); i++)
728    {
729      UInt scaledRefLayerId = activeSPS->getScaledRefLayerId(i);
730      if( activeSPS->getVertPhasePositionEnableFlag( scaledRefLayerId ) )
731      {
732        printf("\nWarning: LayerId = %d: vert_phase_position_enable_flag[%d] = 1, however indication vert_phase_position_in_use_flag = 0\n", m_layerId, scaledRefLayerId );
733        break;
734      }
735    }
736  }
737#endif
[849]738#endif
[644]739
740#if SPS_DPB_PARAMS
741  if( m_layerId > 0 )
742  {
743    // When not present sps_max_sub_layers_minus1 is inferred to be equal to vps_max_sub_layers_minus1.
744    sps->setMaxTLayers( activeVPS->getMaxTLayers() );
745
746    // When not present sps_temporal_id_nesting_flag is inferred to be equal to vps_temporal_id_nesting_flag
[815]747#if Q0177_SPS_TEMP_NESTING_FIX
748    sps->setTemporalIdNestingFlag( (sps->getMaxTLayers() > 1) ? activeVPS->getTemporalNestingFlag() : true );
749#else
[644]750    sps->setTemporalIdNestingFlag( activeVPS->getTemporalNestingFlag() );
[815]751#endif
[644]752
753    // When sps_max_dec_pic_buffering_minus1[ i ] is not present for i in the range of 0 to sps_max_sub_layers_minus1, inclusive, due to nuh_layer_id being greater than 0,
754    // it is inferred to be equal to max_vps_dec_pic_buffering_minus1[ TargetOptLayerSetIdx ][ currLayerId ][ i ] of the active VPS, where currLayerId is the nuh_layer_id of the layer that refers to the SPS.
755    for(UInt i=0; i < sps->getMaxTLayers(); i++)
756    {
757      // to avoid compiler warning "array subscript is above array bounds"
758      assert( i < MAX_TLAYER );
[815]759#if LAYER_DECPICBUFF_PARAM && RESOLUTION_BASED_DPB
760      sps->setMaxDecPicBuffering( activeVPS->getMaxVpsLayerDecPicBuffMinus1( getCommonDecoderParams()->getTargetOutputLayerSetIdx(), sps->getLayerId(), i) + 1, i);
761#else
[644]762      sps->setMaxDecPicBuffering( activeVPS->getMaxVpsDecPicBufferingMinus1( getCommonDecoderParams()->getTargetOutputLayerSetIdx(), sps->getLayerId(), i) + 1, i);
[815]763#endif
[644]764    }
[1010]765
766#if P0182_VPS_VUI_PS_FLAG
767    UInt layerIdx = activeVPS->getLayerIdInVps( m_layerId );
768
769    if( activeVPS->getBaseLayerPSCompatibilityFlag(layerIdx) )
770    {
771      RepFormat* repFormat = activeVPS->getVpsRepFormat(activeVPS->getVpsRepFormatIdx(layerIdx));
772
773      assert( pps->getLayerId() == 0 );
774      assert( sps->getLayerId() == 0 );
775      assert( repFormat->getChromaFormatVpsIdc() == sps->getChromaFormatIdc() );
776      assert( repFormat->getSeparateColourPlaneVpsFlag() == 0 );
777      assert( repFormat->getPicHeightVpsInLumaSamples() == sps->getPicHeightInLumaSamples() );
778      assert( repFormat->getPicWidthVpsInLumaSamples()  == sps->getPicWidthInLumaSamples() );
779      assert( repFormat->getBitDepthVpsLuma()   == sps->getBitDepth(CHANNEL_TYPE_LUMA) );
780      assert( repFormat->getBitDepthVpsChroma() == sps->getBitDepth(CHANNEL_TYPE_CHROMA) );
781      assert( repFormat->getConformanceWindowVps().getWindowLeftOffset()   == sps->getConformanceWindow().getWindowLeftOffset() );
782      assert( repFormat->getConformanceWindowVps().getWindowRightOffset()  == sps->getConformanceWindow().getWindowRightOffset() );
783      assert( repFormat->getConformanceWindowVps().getWindowTopOffset()    == sps->getConformanceWindow().getWindowTopOffset() );
784      assert( repFormat->getConformanceWindowVps().getWindowBottomOffset() == sps->getConformanceWindow().getWindowBottomOffset() );
785    }   
786#endif
[644]787  }
788#endif
789
[916]790#if R0227_REP_FORMAT_CONSTRAINT //Conformance checking for rep format -- rep format of current picture of current layer shall never be greater rep format defined in VPS for the current layer
[1000]791  UInt layerIdx = activeVPS->getLayerIdInVps(m_apcSlicePilot->getLayerId());
792
[916]793  if ( activeVPS->getVpsExtensionFlag() == 1 && (m_apcSlicePilot->getLayerId() == 0 || sps->getV1CompatibleSPSFlag() == 1) )
[313]794  {
[1000]795    assert( sps->getPicWidthInLumaSamples()        <= activeVPS->getVpsRepFormat( activeVPS->getVpsRepFormatIdx(layerIdx) )->getPicWidthVpsInLumaSamples() );
796    assert( sps->getPicHeightInLumaSamples()       <= activeVPS->getVpsRepFormat( activeVPS->getVpsRepFormatIdx(layerIdx) )->getPicHeightVpsInLumaSamples() );
797    assert( sps->getChromaFormatIdc()              <= activeVPS->getVpsRepFormat( activeVPS->getVpsRepFormatIdx(layerIdx) )->getChromaFormatVpsIdc() );
798    assert( sps->getBitDepth(CHANNEL_TYPE_LUMA)    <= activeVPS->getVpsRepFormat( activeVPS->getVpsRepFormatIdx(layerIdx) )->getBitDepthVpsLuma() );
799    assert( sps->getBitDepth(CHANNEL_TYPE_CHROMA)  <= activeVPS->getVpsRepFormat( activeVPS->getVpsRepFormatIdx(layerIdx) )->getBitDepthVpsChroma() );
[313]800  }
[916]801  else if ( activeVPS->getVpsExtensionFlag() == 1 )
802  {
[1000]803    assert( activeVPS->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : activeVPS->getVpsRepFormatIdx(layerIdx))->getPicWidthVpsInLumaSamples()  <= activeVPS->getVpsRepFormat( activeVPS->getVpsRepFormatIdx(layerIdx))->getPicWidthVpsInLumaSamples());
804    assert( activeVPS->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : activeVPS->getVpsRepFormatIdx(layerIdx))->getPicHeightVpsInLumaSamples() <= activeVPS->getVpsRepFormat( activeVPS->getVpsRepFormatIdx(layerIdx))->getPicHeightVpsInLumaSamples());
805    assert( activeVPS->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : activeVPS->getVpsRepFormatIdx(layerIdx))->getChromaFormatVpsIdc()        <= activeVPS->getVpsRepFormat( activeVPS->getVpsRepFormatIdx(layerIdx))->getChromaFormatVpsIdc());
806    assert( activeVPS->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : activeVPS->getVpsRepFormatIdx(layerIdx))->getBitDepthVpsLuma()           <= activeVPS->getVpsRepFormat( activeVPS->getVpsRepFormatIdx(layerIdx))->getBitDepthVpsLuma());
807    assert( activeVPS->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : activeVPS->getVpsRepFormatIdx(layerIdx))->getBitDepthVpsChroma()         <= activeVPS->getVpsRepFormat( activeVPS->getVpsRepFormatIdx(layerIdx))->getBitDepthVpsChroma());
[916]808  }
809#endif
[313]810
811  m_apcSlicePilot->setPPS(pps);
812  m_apcSlicePilot->setSPS(sps);
813  pps->setSPS(sps);
[916]814  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumTileColumnsMinus1() + 1) : ((pps->getNumTileRowsMinus1() + 1)*(pps->getNumTileColumnsMinus1() + 1)));
[313]815  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
[916]816  pps->setMinCuChromaQpAdjSize( sps->getMaxCUWidth() >> ( pps->getMaxCuChromaQpAdjDepth()) );
[313]817
[916]818  for (UInt channel = 0; channel < MAX_NUM_CHANNEL_TYPE; channel++)
819  {
[442]820#if REPN_FORMAT_IN_VPS
[916]821    g_bitDepth[channel] = isLuma(ChannelType(channel)) ? m_apcSlicePilot->getBitDepthY() : m_apcSlicePilot->getBitDepthC();
[442]822#else
[916]823    g_bitDepth[channel] = sps->getBitDepth(ChannelType(channel));
[442]824#endif
[916]825
826    if (sps->getUseExtendedPrecision()) g_maxTrDynamicRange[channel] = std::max<Int>(15, (g_bitDepth[channel] + 6));
827    else                                g_maxTrDynamicRange[channel] = 15;
828  }
[313]829  g_uiMaxCUWidth  = sps->getMaxCUWidth();
830  g_uiMaxCUHeight = sps->getMaxCUHeight();
831  g_uiMaxCUDepth  = sps->getMaxCUDepth();
[916]832  g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() + (Int)getMaxCUDepthOffset(sps->getChromaFormatIdc(), sps->getQuadtreeTULog2MinSize()));
[313]833
834  for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++)
835  {
836    sps->setAMPAcc( i, sps->getUseAMP() );
837  }
838
839  for (Int i = sps->getLog2DiffMaxMinCodingBlockSize(); i < sps->getMaxCUDepth(); i++)
840  {
841    sps->setAMPAcc( i, 0 );
842  }
843
844  m_cSAO.destroy();
[442]845#if REPN_FORMAT_IN_VPS
[916]846  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), pps->getSaoOffsetBitShift(CHANNEL_TYPE_LUMA), pps->getSaoOffsetBitShift(CHANNEL_TYPE_CHROMA) );
[540]847#endif
[313]848  m_cLoopFilter.create( sps->getMaxCUDepth() );
849}
850
851#if SVC_EXTENSION
[442]852#if POC_RESET_FLAG
853Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int &iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC )
854#else
[313]855Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC )
[442]856#endif
[313]857#else
858Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
859#endif
860{
[595]861#if SVC_EXTENSION
[540]862  m_apcSlicePilot->setVPS( m_parameterSetManagerDecoder.getPrefetchedVPS(0) );
863#if OUTPUT_LAYER_SET_INDEX
864  // Following check should go wherever the VPS is activated
[1006]865#if R0235_SMALLEST_LAYER_ID
866  if (!m_apcSlicePilot->getVPS()->getBaseLayerAvailableFlag())
867  {
868    assert(nalu.m_layerId != 0);
869    assert(m_apcSlicePilot->getVPS()->getNumAddLayerSets() > 0);
870    if (getCommonDecoderParams()->getTargetOutputLayerSetIdx() >= 0)
871    {
872      UInt layerIdx = m_apcSlicePilot->getVPS()->getOutputLayerSetIdx(getCommonDecoderParams()->getTargetOutputLayerSetIdx());
873      assert(layerIdx > m_apcSlicePilot->getVPS()->getVpsNumLayerSetsMinus1());
874    }
[1008]875  } 
[1006]876#else
[588]877  checkValueOfTargetOutputLayerSetIdx( m_apcSlicePilot->getVPS());
[540]878#endif
[1006]879#endif
[588]880#if RESOLUTION_BASED_DPB
881  // Following assignment should go wherever a new VPS is activated
882  assignSubDpbs(m_apcSlicePilot->getVPS());
883#endif
[313]884  m_apcSlicePilot->initSlice( nalu.m_layerId );
[595]885#else //SVC_EXTENSION
[313]886  m_apcSlicePilot->initSlice();
887#endif
888
889  if (m_bFirstSliceInPicture)
890  {
[916]891    m_uiSliceIdx = 0;
[313]892  }
[595]893  else
[313]894  {
[916]895    m_apcSlicePilot->copySliceInfo( m_pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
[313]896  }
[595]897  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
[313]898
899  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
[851]900#if POC_RESET_RESTRICTIONS
901  m_apcSlicePilot->setTLayer( nalu.m_temporalId );
902#endif
[313]903  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
904                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
905                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
906                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
907                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
908  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
909  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
910  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
911
[916]912#if ENC_DEC_TRACE
913  const UInt64 originalSymbolCount = g_nSymbolCounter;
914#endif
915
[442]916#if SVC_EXTENSION
[588]917#if VPS_EXTN_DIRECT_REF_LAYERS
[313]918  setRefLayerParams(m_apcSlicePilot->getVPS());
919#endif
920  m_apcSlicePilot->setNumMotionPredRefLayers(m_numMotionPredRefLayers);
921#endif
922  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
923
[442]924  // set POC for dependent slices in skipped pictures
[916]925  if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped)
[442]926  {
927    m_apcSlicePilot->setPOC(m_skippedPOC);
928  }
929
930  m_apcSlicePilot->setAssociatedIRAPPOC(m_pocCRA);
931  m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType);
932
[713]933  //For inference of NoOutputOfPriorPicsFlag
934  if (m_apcSlicePilot->getRapPicFlag())
[644]935  {
[713]936    if ((m_apcSlicePilot->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_apcSlicePilot->getNalUnitType() <= NAL_UNIT_CODED_SLICE_IDR_N_LP) || 
937        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_bFirstSliceInSequence) ||
938        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getHandleCraAsBlaFlag()))
[644]939    {
[713]940      m_apcSlicePilot->setNoRaslOutputFlag(true);
[644]941    }
[713]942    //the inference for NoOutputPriorPicsFlag
943    if (!m_bFirstSliceInBitstream && m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag())
944    {
945      if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
946      {
947        m_apcSlicePilot->setNoOutputPriorPicsFlag(true);
948      }
949    }
[644]950    else
951    {
[713]952      m_apcSlicePilot->setNoOutputPriorPicsFlag(false);
[644]953    }
[713]954
955    if(m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
956    {
957      m_craNoRaslOutputFlag = m_apcSlicePilot->getNoRaslOutputFlag();
958    }
[644]959  }
[713]960  if (m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoOutputPriorPicsFlag())
961  {
962    m_lastPOCNoOutputPriorPics = m_apcSlicePilot->getPOC();
963    m_isNoOutputPriorPics = true;
964  }
965  else
966  {
967    m_isNoOutputPriorPics = false;
968  }
969
970  //For inference of PicOutputFlag
971  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R)
972  {
973    if ( m_craNoRaslOutputFlag )
974    {
975      m_apcSlicePilot->setPicOutputFlag(false);
976    }
977  }
[644]978
[713]979  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_craNoRaslOutputFlag) //Reset POC MSB when CRA has NoRaslOutputFlag equal to 1
980  {
981    Int iMaxPOClsb = 1 << m_apcSlicePilot->getSPS()->getBitsForPOC();
982    m_apcSlicePilot->setPOC( m_apcSlicePilot->getPOC() & (iMaxPOClsb - 1) );
983  }
984
[313]985  // Skip pictures due to random access
986  if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
987  {
[442]988    m_prevSliceSkipped = true;
989    m_skippedPOC = m_apcSlicePilot->getPOC();
[313]990    return false;
991  }
992  // Skip TFD pictures associated with BLA/BLANT pictures
993  if (isSkipPictureForBLA(iPOCLastDisplay))
994  {
[442]995    m_prevSliceSkipped = true;
996    m_skippedPOC = m_apcSlicePilot->getPOC();
[313]997    return false;
998  }
999
[442]1000  // clear previous slice skipped flag
1001  m_prevSliceSkipped = false;
1002
[313]1003  // exit when a new picture is found
1004#if SVC_EXTENSION
1005  bNewPOC = (m_apcSlicePilot->getPOC()!= m_prevPOC);
[644]1006
1007#if NO_OUTPUT_OF_PRIOR_PICS
1008#if NO_CLRAS_OUTPUT_FLAG
[1006]1009#if R0235_SMALLEST_LAYER_ID
1010  if (m_layerId == m_smallestLayerId && m_apcSlicePilot->getRapPicFlag())
1011#else
[644]1012  if (m_layerId == 0 && m_apcSlicePilot->getRapPicFlag() )
[1006]1013#endif
[644]1014  {
1015    if (m_bFirstSliceInSequence)
1016    {
1017      setNoClrasOutputFlag(true);
1018    }
[979]1019#if R0071_IRAP_EOS_CROSS_LAYER_IMPACTS
1020    else if( m_lastPicHasEos )
1021    {
1022      setNoClrasOutputFlag(true);
1023    }
1024#endif
[644]1025    else if ( m_apcSlicePilot->getBlaPicFlag() )
1026    {
1027      setNoClrasOutputFlag(true);
1028    }
1029#if O0149_CROSS_LAYER_BLA_FLAG
1030    else if (m_apcSlicePilot->getIdrPicFlag() && m_apcSlicePilot->getCrossLayerBLAFlag())
1031    {
1032      setNoClrasOutputFlag(true);
1033    }
1034#endif
1035    else
1036    {
1037      setNoClrasOutputFlag(false);
1038    }     
1039  }
1040  else
1041  {
1042    setNoClrasOutputFlag(false);
1043  }
1044
[1006]1045#if R0235_SMALLEST_LAYER_ID
1046  m_apcSlicePilot->decodingRefreshMarking( m_cListPic, m_noClrasOutputFlag, m_smallestLayerId );
1047#else
[713]1048  m_apcSlicePilot->decodingRefreshMarking( m_cListPic, m_noClrasOutputFlag );
[644]1049#endif
[1006]1050#endif
[644]1051
1052  // Derive the value of NoOutputOfPriorPicsFlag
1053  if( bNewPOC || m_layerId!=m_uiPrevLayerId )   // i.e. new coded picture
1054  {
1055    if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getNoRaslOutputFlag() )
1056    {
[713]1057      this->setNoOutputPriorPicsFlag( true );
[644]1058    }
1059    else if( m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag() )
1060    {
[713]1061      this->setNoOutputPriorPicsFlag( m_apcSlicePilot->getNoOutputPriorPicsFlag() );
[644]1062    }
1063    else
1064    {
1065      if( this->m_ppcTDecTop[0]->getNoClrasOutputFlag() )
1066      {
[713]1067        this->setNoOutputPriorPicsFlag( true );
[644]1068      }
1069    }
1070  }
1071#endif
[903]1072
[815]1073#if POC_RESET_IDC_DECODER
1074  if( m_parseIdc != -1 ) // Second pass for a POC resetting picture
1075  {
1076    m_parseIdc++; // Proceed to POC decoding and RPS derivation
1077  }
1078 
1079  if( m_parseIdc == 2 )
1080  {
1081    bNewPOC = false;
1082  }
[644]1083
[815]1084  if( (bNewPOC || m_layerId!=m_uiPrevLayerId) && (m_parseIdc == -1) ) // Will be true at the first pass
1085  {
1086  //if (bNewPOC || m_layerId!=m_uiPrevLayerId)
1087  // Check if new reset period has started - this is needed just so that the SHM decoder which calls slice header decoding twice
1088  // does not invoke the output twice
1089  //if( m_lastPocPeriodId[m_apcSlicePilot->getLayerId()] == m_apcSlicePilot->getPocResetPeriodId() )
1090    // Update CurrAU marking
1091    if(( m_layerId < m_uiPrevLayerId) ||( ( m_layerId == m_uiPrevLayerId) && bNewPOC)) // Decoding a lower layer than or same layer as previous - mark all earlier pictures as not in current AU
1092    {
[851]1093#if POC_RESET_RESTRICTIONS
1094      // New access unit; reset all variables related to POC reset restrictions
1095      resetPocRestrictionCheckParameters();
1096#endif
[815]1097      markAllPicsAsNoCurrAu();
[903]1098#if P0297_VPS_POC_LSB_ALIGNED_FLAG
1099      for (UInt i = 0; i < MAX_LAYERS; i++)
1100      {
1101        m_ppcTDecTop[i]->m_pocDecrementedInDPBFlag = false;
1102      }
1103#endif
[815]1104    }
1105
[903]1106
1107#if P0297_VPS_POC_LSB_ALIGNED_FLAG
1108    m_pocResettingFlag = false;
1109
1110    if (m_apcSlicePilot->getPocResetIdc() != 0)
1111    {
1112      if (m_apcSlicePilot->getVPS()->getVpsPocLsbAlignedFlag())
1113      {
1114        m_pocResettingFlag = true;
1115      }
1116      else if (m_pocDecrementedInDPBFlag)
1117      {
1118        m_pocResettingFlag = false;
1119      }
1120      else
1121      {
1122        m_pocResettingFlag = true;
1123      }
1124    }
1125#endif
1126
[815]1127    if( m_apcSlicePilot->getPocResetIdc() && m_apcSlicePilot->getSliceIdx() == 0 )
1128    {
1129      Int pocResetPeriodId = m_apcSlicePilot->getPocResetPeriodId();
1130      if ( m_apcSlicePilot->getPocResetIdc() == 1 || m_apcSlicePilot->getPocResetIdc() == 2 ||
1131        ( m_apcSlicePilot->getPocResetIdc() == 3 && pocResetPeriodId != getLastPocPeriodId() ) )
1132      {
1133        setLastPocPeriodId(pocResetPeriodId);
1134        m_parseIdc = 0;
1135      }
[854]1136#if POC_RESET_VALUE_RESTRICTION
1137      // Check if the POC Reset period ID matches with the Reset Period ID
1138      if( pocResetPeriodId == m_crossLayerPocResetPeriodId )
1139      {
1140        // If matching, and current poc_reset_idc = 3, then the values should match
1141        if( m_apcSlicePilot->getPocResetIdc() == 3 )
1142        {
[858]1143          assert( ( m_apcSlicePilot->getFullPocResetFlag() == false && m_crossLayerPocResetIdc == 1 ) ||
1144                  ( m_apcSlicePilot->getFullPocResetFlag() == true  && m_crossLayerPocResetIdc == 2 ) );
[854]1145        }
1146      }
1147      else
1148      {
1149        // This is the first picture of a POC resetting access unit
1150        m_crossLayerPocResetPeriodId = pocResetPeriodId;
1151        if( m_apcSlicePilot->getPocResetIdc() == 1 || m_apcSlicePilot->getPocResetIdc() == 2 )
1152        {
1153          m_crossLayerPocResetIdc = m_apcSlicePilot->getPocResetIdc();
1154        }
1155        else
1156        { // poc_reset_idc = 3
1157          // In this case, the entire POC resetting access unit has been lost.
1158          // Need more checking to ensure poc_reset_idc = 3 works.
1159          assert ( 0 );
1160        }
1161      }
1162#endif
[815]1163    }
1164    else
1165    {
1166      m_parseIdc = 3; // Proceed to decoding POC and RPS
[851]1167    }
[815]1168  }
1169#endif
1170
[644]1171#if ALIGNED_BUMPING
[815]1172#if POC_RESET_IDC_DECODER
[903]1173
1174#if P0297_VPS_POC_LSB_ALIGNED_FLAG
1175  UInt affectedLayerList[MAX_NUM_LAYER_IDS];
1176  Int  numAffectedLayers;
1177
1178  affectedLayerList[0] = m_apcSlicePilot->getLayerId();
1179  numAffectedLayers = 1;
1180
1181  if (m_apcSlicePilot->getVPS()->getVpsPocLsbAlignedFlag())
1182  {
1183    for (UInt j = 0; j < m_apcSlicePilot->getVPS()->getNumPredictedLayers(m_apcSlicePilot->getLayerId()); j++)
1184    {
1185      affectedLayerList[j + 1] = m_apcSlicePilot->getVPS()->getPredictedLayerId(m_apcSlicePilot->getLayerId(), j);
1186    }
1187    numAffectedLayers = m_apcSlicePilot->getVPS()->getNumPredictedLayers(m_apcSlicePilot->getLayerId()) + 1;
1188  }
1189#endif
1190
[815]1191  //if(  (bNewPOC || m_layerId != m_uiPrevLayerId) && ( m_parseIdc != 1) )
[903]1192#if P0297_VPS_POC_LSB_ALIGNED_FLAG
1193  if (m_parseIdc == 1 && m_pocResettingFlag)
1194#else
1195  if (m_parseIdc == 1)
1196#endif
[815]1197  {
1198    // Invoke output of pictures if the current picture is a POC reset picture
1199    bNewPOC = true;
1200    /* Include reset of all POCs in the layer */
1201
1202  // This operation would do the following:
1203  // 1. Update the other picture in the DPB. This should be done only for the first slice of the picture.
1204  // 2. Update the value of m_pocCRA.
1205  // 3. Reset the POC values at the decoder for the current picture to be zero - will be done later
1206  // 4. update value of POCLastDisplay
1207     
1208  //Do the reset stuff here
1209    Int maxPocLsb = 1 << m_apcSlicePilot->getSPS()->getBitsForPOC();
1210    Int pocLsbVal;
1211    if( m_apcSlicePilot->getPocResetIdc() == 3 )
1212    {
1213      pocLsbVal = m_apcSlicePilot->getPocLsbVal() ;
1214    }
1215    else
1216    {
1217      pocLsbVal = (m_apcSlicePilot->getPOC() % maxPocLsb);
1218    }
1219
1220    Int pocMsbDelta = 0;
1221    if ( m_apcSlicePilot->getPocMsbValPresentFlag() ) 
1222    {
1223      pocMsbDelta = m_apcSlicePilot->getPocMsbVal() * maxPocLsb;
1224    }
1225    else
1226    {
1227      //This MSB derivation can be made into one function. Item to do next.
1228      Int prevPoc     = this->getPrevPicOrderCnt();
1229      Int prevPocLsb  = prevPoc & (maxPocLsb - 1);
1230      Int prevPocMsb  = prevPoc - prevPocLsb;
1231
1232      pocMsbDelta = m_apcSlicePilot->getCurrMsb( pocLsbVal, prevPocLsb, prevPocMsb, maxPocLsb );
1233    }
1234
1235    Int pocLsbDelta;
1236    if( m_apcSlicePilot->getPocResetIdc() == 2 ||  ( m_apcSlicePilot->getPocResetIdc() == 3 && m_apcSlicePilot->getFullPocResetFlag() ))
1237    {
1238      pocLsbDelta = pocLsbVal;
1239    }
1240    else
1241    {
1242      pocLsbDelta = 0; 
1243    }
1244
1245    Int deltaPocVal  =  pocMsbDelta + pocLsbDelta;
1246
[903]1247#if P0297_VPS_POC_LSB_ALIGNED_FLAG
1248    for (UInt layerIdx = 0; layerIdx < numAffectedLayers; layerIdx++)
1249    {
1250      if (!m_ppcTDecTop[affectedLayerList[layerIdx]]->m_pocDecrementedInDPBFlag)
1251      {
1252        m_ppcTDecTop[affectedLayerList[layerIdx]]->m_pocDecrementedInDPBFlag = true;
1253        TComList<TComPic*>::iterator  iterPic = m_ppcTDecTop[affectedLayerList[layerIdx]]->getListPic()->begin();
1254        while (iterPic != m_ppcTDecTop[affectedLayerList[layerIdx]]->getListPic()->end())
1255#else
[815]1256    //Reset all POC for DPB -> basically do it for each slice in the picutre
1257    TComList<TComPic*>::iterator  iterPic = m_cListPic.begin(); 
1258
1259    // Iterate through all picture in DPB
1260    while( iterPic != m_cListPic.end() )
[903]1261#endif
[815]1262    {
1263      TComPic *dpbPic = *iterPic;
1264      // Check if the picture pointed to by iterPic is either used for reference or
1265      // needed for output, are in the same layer, and not the current picture.
[903]1266#if P0297_VPS_POC_LSB_ALIGNED_FLAG
1267      assert(dpbPic->getLayerId() == affectedLayerList[layerIdx]);
1268      if ( (dpbPic->getReconMark()) && (dpbPic->getPicSym()->getSlice(0)->getPicOutputFlag()) )
1269#else
1270      if ( /*  ( ( dpbPic->getSlice(0)->isReferenced() ) || ( dpbPic->getOutputMark() ) )
[815]1271          &&*/ ( dpbPic->getLayerId() == m_apcSlicePilot->getLayerId() )
1272            && ( dpbPic->getReconMark() ) && ( dpbPic->getPicSym()->getSlice(0)->getPicOutputFlag() ))
[903]1273#endif
[815]1274      {
1275        for(Int i = dpbPic->getNumAllocatedSlice()-1; i >= 0; i--)
1276        {
1277
1278          TComSlice *slice = dpbPic->getSlice(i);
1279          TComReferencePictureSet *rps = slice->getRPS();
1280          slice->setPOC( slice->getPOC() - deltaPocVal );
1281
1282          // Also adjust the POC value stored in the RPS of each such slice
1283          for(Int j = rps->getNumberOfPictures(); j >= 0; j--)
1284          {
1285            rps->setPOC( j, rps->getPOC(j) - deltaPocVal );
1286          }
1287          // Also adjust the value of refPOC
1288          for(Int k = 0; k < 2; k++)  // For List 0 and List 1
1289          {
1290            RefPicList list = (k == 1) ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
1291            for(Int j = 0; j < slice->getNumRefIdx(list); j++)
1292            {
1293              slice->setRefPOC( slice->getRefPOC(list, j) - deltaPocVal, list, j);
1294            }
1295          }
1296        }
1297      }
1298      iterPic++;
1299    }
[903]1300#if P0297_VPS_POC_LSB_ALIGNED_FLAG
1301        // Update the value of pocCRA
1302        m_ppcTDecTop[affectedLayerList[layerIdx]]->m_pocCRA -= deltaPocVal;
1303      }
1304    }
1305#else
[815]1306    // Update the value of pocCRA
1307    m_pocCRA -= deltaPocVal;
[903]1308#endif
[815]1309
1310    // Update value of POCLastDisplay
1311    iPOCLastDisplay -= deltaPocVal;
1312  }
1313  Int maxPocLsb = 1 << m_apcSlicePilot->getSPS()->getBitsForPOC();
1314  Int slicePicOrderCntLsb = m_apcSlicePilot->getPicOrderCntLsb();
1315
[903]1316#if P0297_VPS_POC_LSB_ALIGNED_FLAG
1317  if (m_pocResettingFlag && (m_parseIdc == 1 || m_parseIdc == 2))
1318#else
1319  if (m_parseIdc == 1 || m_parseIdc == 2) // TODO This should be replaced by pocResettingFlag.
1320#endif
[815]1321  {
1322    // Set poc for current slice
1323    if( m_apcSlicePilot->getPocResetIdc() == 1 )
1324    {       
1325      m_apcSlicePilot->setPOC( slicePicOrderCntLsb );
1326    }
1327    else if( m_apcSlicePilot->getPocResetIdc() == 2 )
1328    {
1329      m_apcSlicePilot->setPOC( 0 );
1330    }
1331    else 
1332    {
1333      Int picOrderCntMsb = m_apcSlicePilot->getCurrMsb( slicePicOrderCntLsb, m_apcSlicePilot->getFullPocResetFlag() ? 0 : m_apcSlicePilot->getPocLsbVal(), 0 , maxPocLsb );
1334      m_apcSlicePilot->setPOC( picOrderCntMsb + slicePicOrderCntLsb );
1335    }
1336  }
1337  else if (m_parseIdc == 3)
1338  {
1339    Int picOrderCntMsb = 0;
1340    if( m_apcSlicePilot->getPocMsbValPresentFlag() )
1341    {
1342      picOrderCntMsb = m_apcSlicePilot->getPocMsbVal() * maxPocLsb;
1343    }
1344    else if( m_apcSlicePilot->getIdrPicFlag() )
1345    {
1346      picOrderCntMsb = 0;
1347    }
1348    else
1349    {
1350      Int prevPicOrderCntLsb = this->getPrevPicOrderCnt() & ( maxPocLsb - 1);
1351      Int prevPicOrderCntMsb  = this->getPrevPicOrderCnt() - prevPicOrderCntLsb;
1352      picOrderCntMsb = m_apcSlicePilot->getCurrMsb(slicePicOrderCntLsb, prevPicOrderCntLsb, prevPicOrderCntMsb, maxPocLsb );
1353    }
1354    m_apcSlicePilot->setPOC( picOrderCntMsb + slicePicOrderCntLsb );
1355  }
1356
1357  if( m_parseIdc == 1 || m_parseIdc == 3)
1358  {
1359    // Adjust prevPicOrderCnt
1360    if(    !m_apcSlicePilot->getRaslPicFlag() 
1361        && !m_apcSlicePilot->getRadlPicFlag()
1362        && (m_apcSlicePilot->getNalUnitType() % 2 == 1)
1363        && ( nalu.m_temporalId == 0 )
1364        && !m_apcSlicePilot->getDiscardableFlag() )
1365    {
[903]1366#if P0297_VPS_POC_LSB_ALIGNED_FLAG
1367      for (UInt i = 0; i < numAffectedLayers; i++)
1368      {
1369        m_ppcTDecTop[affectedLayerList[i]]->setPrevPicOrderCnt(m_apcSlicePilot->getPOC());
1370      }
1371#else
[815]1372      this->setPrevPicOrderCnt( m_apcSlicePilot->getPOC() );
[903]1373#endif
[815]1374    }
1375    else if ( m_apcSlicePilot->getPocResetIdc() == 3 )
1376    {
[903]1377#if P0297_VPS_POC_LSB_ALIGNED_FLAG
1378      if (!m_firstPicInLayerDecodedFlag || (m_firstPicInLayerDecodedFlag && m_pocResettingFlag))
1379      {
1380        for (UInt i = 0; i < numAffectedLayers; i++)
1381        {
1382          m_ppcTDecTop[affectedLayerList[i]]->setPrevPicOrderCnt( m_apcSlicePilot->getFullPocResetFlag() 
1383                                                                  ? 0 : m_apcSlicePilot->getPocLsbVal() );
1384        }
1385      }
1386#else
[815]1387      this->setPrevPicOrderCnt( m_apcSlicePilot->getFullPocResetFlag() 
1388                                            ? 0 : m_apcSlicePilot->getPocLsbVal() );
[903]1389#endif
[815]1390    }
1391#else
[644]1392  if (bNewPOC || m_layerId!=m_uiPrevLayerId)
1393  {
[815]1394#endif
[644]1395    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
1396  }
1397#endif
[815]1398#if POC_RESET_IDC_DECODER
[916]1399  if (!m_apcSlicePilot->getDependentSliceSegmentFlag() && (bNewPOC || m_layerId!=m_uiPrevLayerId || m_parseIdc == 1) && !m_bFirstSliceInSequence )
[815]1400#else
[916]1401  if (!m_apcSlicePilot->getDependentSliceSegmentFlag() && (bNewPOC || m_layerId!=m_uiPrevLayerId) && !m_bFirstSliceInSequence )
[815]1402#endif
[313]1403  {
1404    m_prevPOC = m_apcSlicePilot->getPOC();
1405    curLayerId = m_uiPrevLayerId; 
1406    m_uiPrevLayerId = m_layerId;
1407    return true;
1408  }
[815]1409
1410#if POC_RESET_IDC_DECODER
1411  m_parseIdc = -1;
[313]1412#endif
[815]1413
[853]1414
[850]1415#if R0226_SLICE_TMVP
1416  if ( m_apcSlicePilot->getTLayer() == 0 && m_apcSlicePilot->getEnableTMVPFlag() == 0 )
1417  {
1418    //update all pics in the DPB such that they cannot be used for TMPV ref
1419    TComList<TComPic*>::iterator  iterRefPic = m_cListPic.begin(); 
1420    while( iterRefPic != m_cListPic.end() )
1421    {
1422      TComPic *refPic = *iterRefPic;
1423      if( ( refPic->getLayerId() == m_apcSlicePilot->getLayerId() ) && refPic->getReconMark() )
1424      {
1425        for(Int i = refPic->getNumAllocatedSlice()-1; i >= 0; i--)
1426        {
1427
1428          TComSlice *refSlice = refPic->getSlice(i);
1429          refSlice->setAvailableForTMVPRefFlag( false );
1430        }
1431      }
1432      iterRefPic++;
1433    }
1434  }
1435  m_apcSlicePilot->setAvailableForTMVPRefFlag( true );
1436#endif
1437
[313]1438  // actual decoding starts here
[916]1439  xActivateParameterSets();
[815]1440
[442]1441#if REPN_FORMAT_IN_VPS
1442  // Initialize ILRP if needed, only for the current layer 
1443  // ILRP intialization should go along with activation of parameters sets,
1444  // although activation of parameter sets itself need not be done for each and every slice!!!
1445  xInitILRP(m_apcSlicePilot);
1446#endif
[916]1447  if (!m_apcSlicePilot->getDependentSliceSegmentFlag()) 
[313]1448  {
1449    m_prevPOC = m_apcSlicePilot->getPOC();
1450    curLayerId = m_layerId;
1451    m_uiPrevLayerId = m_layerId;
1452  }
[713]1453  m_bFirstSliceInSequence = false;
1454  m_bFirstSliceInBitstream  = false;
[442]1455#if POC_RESET_FLAG
1456  // This operation would do the following:
1457  // 1. Update the other picture in the DPB. This should be done only for the first slice of the picture.
1458  // 2. Update the value of m_pocCRA.
1459  // 3. Reset the POC values at the decoder for the current picture to be zero.
1460  // 4. update value of POCLastDisplay
1461  if( m_apcSlicePilot->getPocResetFlag() )
1462  {
1463    if( m_apcSlicePilot->getSliceIdx() == 0 )
1464    {
1465      Int pocAdjustValue = m_apcSlicePilot->getPOC();
1466
[540]1467#if PREVTID0_POC_RESET
1468      m_apcSlicePilot->adjustPrevTid0POC(pocAdjustValue);
1469#endif
[442]1470      // If poc reset flag is set to 1, reset all POC for DPB -> basically do it for each slice in the picutre
1471      TComList<TComPic*>::iterator  iterPic = m_cListPic.begin(); 
1472
1473      // Iterate through all picture in DPB
1474      while( iterPic != m_cListPic.end() )
1475      {
1476        TComPic *dpbPic = *iterPic;
1477        // Check if the picture pointed to by iterPic is either used for reference or
1478        // needed for output, are in the same layer, and not the current picture.
1479        if( /*  ( ( dpbPic->getSlice(0)->isReferenced() ) || ( dpbPic->getOutputMark() ) )
1480            &&*/ ( dpbPic->getLayerId() == m_apcSlicePilot->getLayerId() )
1481              && ( dpbPic->getReconMark() ) 
1482          )
1483        {
1484          for(Int i = dpbPic->getNumAllocatedSlice()-1; i >= 0; i--)
1485          {
1486
1487            TComSlice *slice = dpbPic->getSlice(i);
1488            TComReferencePictureSet *rps = slice->getRPS();
1489            slice->setPOC( slice->getPOC() - pocAdjustValue );
1490
1491            // Also adjust the POC value stored in the RPS of each such slice
1492            for(Int j = rps->getNumberOfPictures(); j >= 0; j--)
1493            {
1494              rps->setPOC( j, rps->getPOC(j) - pocAdjustValue );
1495            }
1496            // Also adjust the value of refPOC
1497            for(Int k = 0; k < 2; k++)  // For List 0 and List 1
1498            {
1499              RefPicList list = (k == 1) ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
1500              for(Int j = 0; j < slice->getNumRefIdx(list); j++)
1501              {
1502                slice->setRefPOC( slice->getRefPOC(list, j) - pocAdjustValue, list, j);
1503              }
1504            }
1505          }
1506        }
1507        iterPic++;
1508      }
1509      // Update the value of pocCRA
1510      m_pocCRA -= pocAdjustValue;
1511      // Update value of POCLastDisplay
1512      iPOCLastDisplay -= pocAdjustValue;
1513    }
1514    // Reset current poc for current slice and RPS
1515    m_apcSlicePilot->setPOC( 0 );
1516  }
1517#endif
[815]1518  // Alignment of TSA and STSA pictures across AU
1519#if !Q0108_TSA_STSA
[442]1520  if( m_apcSlicePilot->getLayerId() > 0 )
1521  {
1522    // Check for TSA alignment
1523    if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N ||
[540]1524        m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R
[442]1525         )
1526    {
1527      for(Int dependentLayerIdx = 0; dependentLayerIdx < m_apcSlicePilot->getVPS()->getNumDirectRefLayers(m_layerId); dependentLayerIdx++)
1528      {
1529        TComList<TComPic*> *cListPic = getRefLayerDec( dependentLayerIdx )->getListPic();
1530        TComPic* refpicLayer = m_apcSlicePilot->getRefPic(*cListPic, m_apcSlicePilot->getPOC() );
1531        if( refpicLayer )
1532        {
1533          assert( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N ||
[540]1534                    m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R );    // TSA pictures should be aligned among depenedent layers
[442]1535        } 
1536      }
1537    }
1538    // Check for STSA alignment
1539    if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N ||
1540         m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_R
1541         )
1542    {
1543      for(Int dependentLayerIdx = 0; dependentLayerIdx < m_apcSlicePilot->getVPS()->getNumDirectRefLayers(m_layerId); dependentLayerIdx++)
1544      {
1545        TComList<TComPic*> *cListPic = getRefLayerDec( dependentLayerIdx )->getListPic();
1546        TComPic* refpicLayer = m_apcSlicePilot->getRefPic(*cListPic, m_apcSlicePilot->getPOC() ); // STSA pictures should be aligned among dependent layers
1547        if( refpicLayer )
1548
1549        {
1550          assert( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N ||
1551                    m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_R );
1552        }
1553      }
1554    }
1555  }
1556#endif
[815]1557
1558#else //SVC_EXTENSION
1559  //we should only get a different poc for a new picture (with CTU address==0)
[916]1560  if (!m_apcSlicePilot->getDependentSliceSegmentFlag() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (m_apcSlicePilot->getSliceCurStartCtuTsAddr() != 0)) 
[815]1561  {
1562    printf ("Warning, the first slice of a picture might have been lost!\n");
1563  }
[916]1564
[815]1565  // exit when a new picture is found
[916]1566  if (!m_apcSlicePilot->getDependentSliceSegmentFlag() && (m_apcSlicePilot->getSliceCurStartCtuTsAddr() == 0 && !m_bFirstSliceInPicture) )
[815]1567  {
1568    if (m_prevPOC >= m_pocRandomAccess)
1569    {
1570      m_prevPOC = m_apcSlicePilot->getPOC();
[916]1571#if ENC_DEC_TRACE
1572      //rewind the trace counter since we didn't actually decode the slice
1573      g_nSymbolCounter = originalSymbolCount;
1574#endif
[815]1575      return true;
1576    }
1577    m_prevPOC = m_apcSlicePilot->getPOC();
1578  }
1579
1580  // actual decoding starts here
1581  xActivateParameterSets();
1582
[916]1583  if (!m_apcSlicePilot->getDependentSliceSegmentFlag())
[815]1584  {
1585    m_prevPOC = m_apcSlicePilot->getPOC();
1586  }
1587  m_bFirstSliceInSequence = false;
[916]1588  m_bFirstSliceInBitstream  = false;
[815]1589#endif //SVC_EXTENSION
[313]1590  //detect lost reference picture and insert copy of earlier frame.
1591  Int lostPoc;
1592  while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
1593  {
1594    xCreateLostPicture(lostPoc-1);
1595  }
1596  if (m_bFirstSliceInPicture)
1597  {
1598#if AVC_BASE
[874]1599#if VPS_AVC_BL_FLAG_REMOVAL
1600    if( m_layerId == 1 && m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getNonHEVCBaseLayerFlag() )
1601#else
[540]1602    if( m_layerId == 1 && m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
[874]1603#endif
[313]1604    {
1605      TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
[540]1606      pBLPic->getSlice(0)->setReferenced(true);
[313]1607      fstream* pFile  = m_ppcTDecTop[0]->getBLReconFile();
1608
1609      if( pFile->good() )
1610      {
[916]1611        Bool is16bit  = g_bitDepthLayer[CHANNEL_TYPE_LUMA][0] > 8 || g_bitDepthLayer[CHANNEL_TYPE_CHROMA][0] > 8;
1612        UInt uiWidth  = pBLPic->getPicYuvRec()->getWidth(COMPONENT_Y);
1613        UInt uiHeight = pBLPic->getPicYuvRec()->getHeight(COMPONENT_Y);
[815]1614
1615        Int len = uiWidth * (is16bit ? 2 : 1);
1616        UChar *buf = new UChar[len];
1617
[313]1618        UInt64 uiPos = (UInt64) m_apcSlicePilot->getPOC() * uiWidth * uiHeight * 3 / 2;
[815]1619        if( is16bit )
1620        {
1621            uiPos <<= 1;
1622        }
[313]1623
1624        pFile->seekg((UInt)uiPos, ios::beg );
1625
[815]1626        // read Y component
[916]1627        Pel* pPel = pBLPic->getPicYuvRec()->getAddr(COMPONENT_Y);
1628        UInt uiStride = pBLPic->getPicYuvRec()->getStride(COMPONENT_Y);
[313]1629        for( Int i = 0; i < uiHeight; i++ )
1630        {
[815]1631          pFile->read(reinterpret_cast<Char*>(buf), len);
1632
1633          if( !is16bit )
[313]1634          {
[815]1635            for (Int x = 0; x < uiWidth; x++)
1636            {
1637              pPel[x] = buf[x];
1638            }
[313]1639          }
[815]1640          else
1641          {
1642            for (Int x = 0; x < uiWidth; x++)
1643            {
1644              pPel[x] = (buf[2*x+1] << 8) | buf[2*x];
1645            }
1646          }
1647     
[313]1648          pPel += uiStride;
1649        }
1650
[815]1651        len >>= 1;
1652        uiWidth >>= 1;
1653        uiHeight >>= 1;
1654
1655        // read Cb component
[916]1656        pPel = pBLPic->getPicYuvRec()->getAddr(COMPONENT_Cb);
1657        uiStride = pBLPic->getPicYuvRec()->getStride(COMPONENT_Cb);
[815]1658        for( Int i = 0; i < uiHeight; i++ )
[313]1659        {
[815]1660          pFile->read(reinterpret_cast<Char*>(buf), len);
1661
1662          if( !is16bit )
[313]1663          {
[815]1664            for( Int x = 0; x < uiWidth; x++ )
1665            {
1666              pPel[x] = buf[x];
1667            }
[313]1668          }
[815]1669          else
1670          {
1671            for( Int x = 0; x < uiWidth; x++ )
1672            {
1673              pPel[x] = (buf[2*x+1] << 8) | buf[2*x];
1674            }
1675          }
1676     
[313]1677          pPel += uiStride;
1678        }
1679
[815]1680        // read Cr component
[916]1681        pPel = pBLPic->getPicYuvRec()->getAddr(COMPONENT_Cr);
1682        uiStride = pBLPic->getPicYuvRec()->getStride(COMPONENT_Cr);
[815]1683        for( Int i = 0; i < uiHeight; i++ )
[313]1684        {
[815]1685          pFile->read(reinterpret_cast<Char*>(buf), len);
1686
1687          if( !is16bit )
[313]1688          {
[815]1689            for( Int x = 0; x < uiWidth; x++ )
1690            {
1691              pPel[x] = buf[x];
1692            }
[313]1693          }
[815]1694          else
1695          {
1696            for( Int x = 0; x < uiWidth; x++ )
1697            {
1698              pPel[x] = (buf[2*x+1] << 8) | buf[2*x];
1699            }
1700          }
1701     
[313]1702          pPel += uiStride;
1703        }
[815]1704
1705        delete[] buf;
[313]1706      }
1707    }
1708#endif
1709
[713]1710#if NO_OUTPUT_OF_PRIOR_PICS
[644]1711    if ( m_layerId == 0 && m_apcSlicePilot->getRapPicFlag() && getNoClrasOutputFlag() )
1712    {
1713      for (UInt i = 0; i < m_apcSlicePilot->getVPS()->getMaxLayers(); i++)
1714      {
1715        m_ppcTDecTop[i]->setLayerInitializedFlag(false);
1716        m_ppcTDecTop[i]->setFirstPicInLayerDecodedFlag(false);
1717      }
1718    }
1719#endif
[979]1720#if R0071_IRAP_EOS_CROSS_LAYER_IMPACTS
1721    xCheckLayerReset();
1722    xSetLayerInitializedFlag();
1723#endif
[313]1724    // Buffer initialize for prediction.
[916]1725    m_cPrediction.initTempBuff(m_apcSlicePilot->getSPS()->getChromaFormatIdc());
[713]1726#if ALIGNED_BUMPING
1727    m_apcSlicePilot->checkLeadingPictureRestrictions(m_cListPic);
1728#else
[313]1729    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
[644]1730#endif
[313]1731    //  Get a new picture buffer
[916]1732    xGetNewPicBuffer (m_apcSlicePilot, m_pcPic);
[313]1733
[815]1734#if POC_RESET_IDC_DECODER
[916]1735    m_pcPic->setCurrAuFlag( true );
[851]1736#if POC_RESET_RESTRICTIONS
[916]1737    if( m_pcPic->getLayerId() > 0 && m_apcSlicePilot->isIDR() && !m_nonBaseIdrPresentFlag )
[851]1738    {
1739      // IDR picture with nuh_layer_id > 0 present
1740      m_nonBaseIdrPresentFlag = true;
1741      m_nonBaseIdrType = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL);
1742    }
1743    else
1744    {
1745      if( m_apcSlicePilot->getNalUnitType() != NAL_UNIT_CODED_SLICE_IDR_W_RADL )
1746      {
1747        // Picture with nal_unit_type not equal IDR_W_RADL present
1748        m_picNonIdrWithRadlPresentFlag = true;
1749      }
1750      if( m_apcSlicePilot->getNalUnitType() != NAL_UNIT_CODED_SLICE_IDR_N_LP )
1751      {
1752        // Picture with nal_unit_type not equal IDR_N_LP present
1753        m_picNonIdrNoLpPresentFlag = true;
1754      }
1755    }
1756    if( !m_checkPocRestrictionsForCurrAu )  // Will be true for the first slice/picture of the AU
1757    {
1758      m_checkPocRestrictionsForCurrAu = true;
1759      m_pocResetIdcOrCurrAu = m_apcSlicePilot->getPocResetIdc();
[916]1760      if( m_pcPic->getLayerId() == 0 )
[851]1761      {
1762        // Base layer picture is present
1763        m_baseLayerPicPresentFlag = true;
1764        if( m_apcSlicePilot->isIRAP() )
1765        {
1766          // Base layer picture is IRAP
1767          m_baseLayerIrapFlag = true;
1768        }
1769        if( m_apcSlicePilot->isIDR() )
1770        {
1771          // Base layer picture is IDR
1772          m_baseLayerIdrFlag = true;
1773        }
1774        else
1775        {
1776          if( m_apcSlicePilot->getVPS()->getBaseLayerInternalFlag())
1777          {
1778            /* When the picture with nuh_layer_id equal to 0 in an access unit is not an IDR picture
1779            and vps_base_layer_internal_flag is equal to 1, the value of poc_reset_idc shall not be equal to 2
1780            for any picture in the access unit. */
1781            assert( m_apcSlicePilot->getPocResetIdc() != 2 );
1782          }
1783        }
1784      }
1785    }
1786    else
1787    {
1788      // The value of poc_reset_idc of all coded pictures that are present in the bitstream in an access unit shall be the same.
1789      assert( m_pocResetIdcOrCurrAu == m_apcSlicePilot->getPocResetIdc() );
1790
1791      /* When the picture in an access unit with nuh_layer_id equal to 0 is an IRAP picture and vps_base_layer_internal_flag is equal to 1
1792      and there is at least one other picture in the same access unit that is not an IRAP picture,
1793      the value of poc_reset_idc shall be equal to 1 or 2 for all pictures in the access unit. */
1794      if( m_baseLayerPicPresentFlag && m_baseLayerIrapFlag && !m_apcSlicePilot->isIRAP() && m_apcSlicePilot->getVPS()->getBaseLayerInternalFlag() )
1795      {
1796        assert( m_apcSlicePilot->getPocResetIdc() == 1 || m_apcSlicePilot->getPocResetIdc() == 2 );
1797      }
1798
1799      /* When the picture with nuh_layer_id equal to 0 in an access unit is an IDR picture and
1800      vps_base_layer_internal_flag is equal to 1 and there is at least one non-IDR picture in the same access unit,
1801      the value of poc_reset_idc shall be equal to 2 for all pictures in the access unit. */
1802      if( m_baseLayerPicPresentFlag && m_baseLayerIdrFlag && !m_apcSlicePilot->isIDR() && m_apcSlicePilot->getVPS()->getBaseLayerInternalFlag() )
1803      {
1804        assert( m_apcSlicePilot->getPocResetIdc() == 2 );
1805      }
1806
1807      /* When there is at least one picture that has nuh_layer_id greater than 0 and that is an IDR picture
1808      with a particular value of nal_unit_type in an access unit and there is at least one other coded picture
1809      that is present in the bitstream in the same access unit with a different value of nal_unit_type,
1810      the value of poc_reset_idc shall be equal to 1 or 2 for all pictures in the access unit. */
[858]1811      if( m_nonBaseIdrPresentFlag && (
1812            ( m_nonBaseIdrType == 1 && m_picNonIdrWithRadlPresentFlag ) ||
1813            ( m_nonBaseIdrType == 0 && m_picNonIdrNoLpPresentFlag )
1814        ))
[851]1815      {
1816        assert( m_apcSlicePilot->getPocResetIdc() == 1 || m_apcSlicePilot->getPocResetIdc() == 2 );
1817      }
1818    }
[815]1819#endif
[851]1820#endif
[815]1821
[442]1822    Bool isField = false;
1823    Bool isTff = false;
1824   
1825    if(!m_SEIs.empty())
1826    {
1827      // Check if any new Picture Timing SEI has arrived
1828      SEIMessages pictureTimingSEIs = extractSeisByType (m_SEIs, SEI::PICTURE_TIMING);
1829      if (pictureTimingSEIs.size()>0)
1830      {
1831        SEIPictureTiming* pictureTiming = (SEIPictureTiming*) *(pictureTimingSEIs.begin());
1832        isField = (pictureTiming->m_picStruct == 1) || (pictureTiming->m_picStruct == 2);
1833        isTff =  (pictureTiming->m_picStruct == 1);
1834      }
[853]1835
1836#if R0226_CONSTRAINT_TMVP_SEI
1837      // Check if any new temporal motion vector prediction constraints SEI has arrived
1838      SEIMessages seiTMVPConstrainsList = extractSeisByType (m_SEIs, SEI::TMVP_CONSTRAINTS);
1839      if (seiTMVPConstrainsList.size() > 0)
1840      {
[916]1841        assert ( m_pcPic->getTLayer() == 0 );  //this SEI can present only for AU with Tid equal to 0
[853]1842        SEITMVPConstrains* tmvpConstraintSEI = (SEITMVPConstrains*) *(seiTMVPConstrainsList.begin());
1843        if ( tmvpConstraintSEI->prev_pics_not_used_flag == 1 )
1844        {
1845          //update all pics in the DPB such that they cannot be used for TMPV ref
1846          TComList<TComPic*>::iterator  iterRefPic = m_cListPic.begin(); 
1847          while( iterRefPic != m_cListPic.end() )
1848          {
1849            TComPic *refPic = *iterRefPic;
[916]1850            if( ( refPic->getLayerId() == m_pcPic->getLayerId() ) && refPic->getReconMark() )
[853]1851            {
1852              for(Int i = refPic->getNumAllocatedSlice()-1; i >= 0; i--)
1853              {
1854                TComSlice *refSlice = refPic->getSlice(i);
1855                refSlice->setAvailableForTMVPRefFlag( false );
1856              }
1857            }
1858            iterRefPic++;
1859          }
1860        }
1861      }
1862#endif
[442]1863    }
1864   
1865    //Set Field/Frame coding mode
1866    m_pcPic->setField(isField);
1867    m_pcPic->setTopField(isTff);
1868
[313]1869    // transfer any SEI messages that have been received to the picture
[916]1870    m_pcPic->setSEIs(m_SEIs);
[313]1871    m_SEIs.clear();
1872
1873    // Recursive structure
[916]1874    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getChromaFormatIdc() );
[313]1875#if SVC_EXTENSION
1876    m_cCuDecoder.init   ( m_ppcTDecTop,&m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction, curLayerId );
1877#else
1878    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
1879#endif
1880    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
1881
1882    m_cSliceDecoder.create();
1883  }
1884  else
1885  {
1886    // Check if any new SEI has arrived
1887    if(!m_SEIs.empty())
1888    {
1889      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
[916]1890      SEIMessages &picSEI = m_pcPic->getSEIs();
[313]1891      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
1892      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
1893      deleteSEIs(m_SEIs);
1894    }
1895  }
[916]1896
[313]1897  //  Set picture slice pointer
1898  TComSlice*  pcSlice = m_apcSlicePilot;
1899
[916]1900  m_pcPic->getPicSym()->initTiles(pcSlice->getPPS());
1901  m_pcPic->getPicSym()->initCtuTsRsAddrMaps();
[313]1902
[916]1903  // When decoding the slice header, the stored start and end addresses were actually RS addresses, not TS addresses.
1904  // Now, having set up the maps, convert them to the correct form.
1905  pcSlice->setSliceSegmentCurStartCtuTsAddr( m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceSegmentCurStartCtuTsAddr()) );
1906  pcSlice->setSliceSegmentCurEndCtuTsAddr( m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceSegmentCurEndCtuTsAddr()) );
1907  if(!pcSlice->getDependentSliceSegmentFlag())
[313]1908  {
[916]1909    pcSlice->setSliceCurStartCtuTsAddr(m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceCurStartCtuTsAddr()));
1910    pcSlice->setSliceCurEndCtuTsAddr(m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceCurEndCtuTsAddr()));
[313]1911  }
1912
[916]1913  if (m_bFirstSliceInPicture)
[313]1914  {
[916]1915    if(m_pcPic->getNumAllocatedSlice() != 1)
[313]1916    {
[916]1917      m_pcPic->clearSliceBuffer();
[313]1918    }
1919  }
1920  else
1921  {
[916]1922    m_pcPic->allocateNewSlice();
[313]1923  }
[916]1924  assert(m_pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
1925  m_apcSlicePilot = m_pcPic->getPicSym()->getSlice(m_uiSliceIdx);
1926  m_pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
[313]1927
[916]1928  m_pcPic->setTLayer(nalu.m_temporalId);
[313]1929
1930#if SVC_EXTENSION
[916]1931  m_pcPic->setLayerId(nalu.m_layerId);
[313]1932  pcSlice->setLayerId(nalu.m_layerId);
[916]1933  pcSlice->setPic(m_pcPic);
[313]1934#endif
1935
[916]1936  if (!pcSlice->getDependentSliceSegmentFlag())
[313]1937  {
[442]1938    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_associatedIRAPType, m_cListPic );
[313]1939    // Set reference list
[442]1940#if SVC_EXTENSION
[313]1941    if (m_layerId == 0)
1942#endif
1943    pcSlice->setRefPicList( m_cListPic, true );
1944
[494]1945#if SVC_EXTENSION
1946    // Create upsampling reference layer pictures for all possible dependent layers and do it only once for the first slice.
1947    // Other slices might choose which reference pictures to be used for inter-layer prediction
1948    if( m_layerId > 0 && m_uiSliceIdx == 0 )
1949    {     
[540]1950#if M0040_ADAPTIVE_RESOLUTION_CHANGE
1951      if( !pcSlice->getVPS()->getSingleLayerForNonIrapFlag() || ( pcSlice->getVPS()->getSingleLayerForNonIrapFlag() && pcSlice->isIRAP() ) )
1952#endif
[916]1953      for( Int i = 0; i < pcSlice->getNumILRRefIdx(); i++ )
[313]1954      {
[494]1955        UInt refLayerIdc = i;
[815]1956        UInt refLayerId = pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc);
[313]1957#if AVC_BASE
[874]1958#if VPS_AVC_BL_FLAG_REMOVAL
1959        if( refLayerId == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getNonHEVCBaseLayerFlag() )
1960#else
[815]1961        if( refLayerId == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getAvcBaseLayerFlag() )
[874]1962#endif
[540]1963        {         
1964          TComPic* pic = *m_ppcTDecTop[0]->getListPic()->begin();
1965
1966          if( pic )
1967          {
1968            pcSlice->setBaseColPic ( refLayerIdc, pic );
1969          }
1970          else
1971          {
1972            continue;
1973          }
[313]1974        }
1975        else
1976        {
1977#if VPS_EXTN_DIRECT_REF_LAYERS
1978          TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
1979#else
1980          TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
1981#endif
1982          TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
[540]1983          if( !pcSlice->setBaseColPic ( *cListPic, refLayerIdc ) )
1984          {
1985            continue;
1986          }
[313]1987        }
1988#else
1989#if VPS_EXTN_DIRECT_REF_LAYERS
1990        TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
1991#else
1992        TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
1993#endif
1994        TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
1995        pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
1996#endif
1997
[849]1998#if MOVE_SCALED_OFFSET_TO_PPS
[540]1999#if O0098_SCALED_REF_LAYER_ID
[849]2000        const Window &scalEL = pcSlice->getPPS()->getScaledRefLayerWindowForLayer(refLayerId);
2001#else
2002        const Window &scalEL = pcSlice->getPPS()->getScaledRefLayerWindow(refLayerIdc);
2003#endif
2004#else
2005#if O0098_SCALED_REF_LAYER_ID
[815]2006        const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(refLayerId);
[540]2007#else
[313]2008        const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
[540]2009#endif
[849]2010#endif
[313]2011
[849]2012#if REF_REGION_OFFSET
2013        const Window &windowRL = pcSlice->getPPS()->getRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc));
[916]2014        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth(COMPONENT_Y) - windowRL.getWindowLeftOffset() - windowRL.getWindowRightOffset();
2015        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight(COMPONENT_Y) - windowRL.getWindowTopOffset() - windowRL.getWindowBottomOffset();
[849]2016#else
[916]2017        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth(COMPONENT_Y);
2018        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight(COMPONENT_Y);
[713]2019#if Q0200_CONFORMANCE_BL_SIZE
2020        Int chromaFormatIdc = pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getChromaFormatIdc();
2021        const Window &confBL = pcSlice->getBaseColPic(refLayerIdc)->getConformanceWindow(); 
2022        widthBL  -= ( confBL.getWindowLeftOffset() + confBL.getWindowRightOffset() ) * TComSPS::getWinUnitX( chromaFormatIdc );
2023        heightBL -= ( confBL.getWindowTopOffset() + confBL.getWindowBottomOffset() ) * TComSPS::getWinUnitY( chromaFormatIdc );
2024#endif
[849]2025#endif
[916]2026        Int widthEL   = m_pcPic->getPicYuvRec()->getWidth(COMPONENT_Y)  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
2027        Int heightEL  = m_pcPic->getPicYuvRec()->getHeight(COMPONENT_Y) - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
[313]2028
[873]2029#if RESAMPLING_FIX
2030#if REF_REGION_OFFSET
2031        // conformance check: the values of RefLayerRegionWidthInSamplesY, RefLayerRegionHeightInSamplesY, ScaledRefRegionWidthInSamplesY and ScaledRefRegionHeightInSamplesY shall be greater than 0
2032        assert(widthEL > 0 && heightEL > 0 && widthBL > 0 && widthEL > 0);
2033
2034        // conformance check: ScaledRefRegionWidthInSamplesY shall be greater or equal to RefLayerRegionWidthInSamplesY and ScaledRefRegionHeightInSamplesY shall be greater or equal to RefLayerRegionHeightInSamplesY
2035        assert(widthEL >= widthBL && heightEL >= heightBL);
2036
2037#if R0209_GENERIC_PHASE
2038        // conformance check: when ScaledRefRegionWidthInSamplesY is equal to RefLayerRegionWidthInSamplesY, PhaseHorY shall be equal to 0, when ScaledRefRegionWidthInSamplesC is equal to RefLayerRegionWidthInSamplesC, PhaseHorC shall be equal to 0, when ScaledRefRegionHeightInSamplesY is equal to RefLayerRegionHeightInSamplesY, PhaseVerY shall be equal to 0, and when ScaledRefRegionHeightInSamplesC is equal to RefLayerRegionHeightInSamplesC, PhaseVerC shall be equal to 0.
2039        Int phaseHorLuma   = pcSlice->getPPS()->getPhaseHorLuma(refLayerIdc);
2040        Int phaseVerLuma   = pcSlice->getPPS()->getPhaseVerLuma(refLayerIdc);
2041        Int phaseHorChroma = pcSlice->getPPS()->getPhaseHorChroma(refLayerIdc);
2042        Int phaseVerChroma = pcSlice->getPPS()->getPhaseVerChroma(refLayerIdc);
2043        assert( ( (widthEL  != widthBL)  || (phaseHorLuma == 0 && phaseHorChroma == 0) )
2044             && ( (heightEL != heightBL) || (phaseVerLuma == 0 && phaseVerChroma == 0) ) );
2045#endif
2046#endif
2047#endif
2048
[313]2049        g_mvScalingFactor[refLayerIdc][0] = widthEL  == widthBL  ? 4096 : Clip3(-4096, 4095, ((widthEL  << 8) + (widthBL  >> 1)) / widthBL);
2050        g_mvScalingFactor[refLayerIdc][1] = heightEL == heightBL ? 4096 : Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL);
2051
2052        g_posScalingFactor[refLayerIdc][0] = ((widthBL  << 16) + (widthEL  >> 1)) / widthEL;
2053        g_posScalingFactor[refLayerIdc][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL;
2054
[713]2055#if Q0048_CGS_3D_ASYMLUT
2056        TComPicYuv* pBaseColRec = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec();
[825]2057        if( pcSlice->getPPS()->getCGSFlag() 
2058#if R0150_CGS_SIGNAL_CONSTRAINTS
2059          && m_c3DAsymLUTPPS.isRefLayer( pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc) )
2060#endif
2061          )
[713]2062        {
[825]2063#if R0150_CGS_SIGNAL_CONSTRAINTS
2064          assert( pcSlice->getBaseColPic( refLayerIdc )->getSlice( 0 )->getBitDepthY() == m_c3DAsymLUTPPS.getInputBitDepthY() );
2065          assert( pcSlice->getBaseColPic( refLayerIdc )->getSlice( 0 )->getBitDepthC() == m_c3DAsymLUTPPS.getInputBitDepthC() );
2066          assert( pcSlice->getBitDepthY() >= m_c3DAsymLUTPPS.getOutputBitDepthY() );
2067          assert( pcSlice->getBitDepthY() >= m_c3DAsymLUTPPS.getOutputBitDepthC() );
2068#endif
[713]2069          if(!m_pColorMappedPic)
2070          {
2071            initAsymLut(pcSlice->getBaseColPic(refLayerIdc)->getSlice(0));
2072          }
2073          m_c3DAsymLUTPPS.colorMapping( pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(),  m_pColorMappedPic );
2074          pBaseColRec = m_pColorMappedPic;
2075        }
2076#endif
[815]2077#if SVC_EXTENSION
[916]2078        if( m_pcPic->isSpatialEnhLayer(refLayerIdc) )
[815]2079        {
2080          // check for the sample prediction picture type
2081          if( m_ppcTDecTop[m_layerId]->getSamplePredEnabledFlag(refLayerId) )
2082          {
[946]2083#if O0215_PHASE_ALIGNMENT_REMOVAL
[947]2084            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, m_pcPic->getPicYuvRec());
[946]2085#else
[494]2086#if O0215_PHASE_ALIGNMENT
2087#if O0194_JOINT_US_BITSHIFT
[713]2088#if Q0048_CGS_3D_ASYMLUT
[916]2089            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, m_pcPic->getPicYuvRec(), pcSlice->getVPS()->getPhaseAlignFlag() );
[313]2090#else
[916]2091            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), m_pcPic->getPicYuvRec(), pcSlice->getVPS()->getPhaseAlignFlag() );
[713]2092#endif
2093#else
2094#if Q0048_CGS_3D_ASYMLUT
[849]2095#if MOVE_SCALED_OFFSET_TO_PPS
[916]2096          m_cPrediction.upsampleBasePic( refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, m_pcPic->getPicYuvRec(), pcSlice->getPPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
[713]2097#else
[916]2098          m_cPrediction.upsampleBasePic( refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, m_pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
[313]2099#endif
[849]2100#else
[916]2101          m_cPrediction.upsampleBasePic( refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), m_pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
[713]2102#endif
[849]2103#endif
[494]2104#else
2105#if O0194_JOINT_US_BITSHIFT
[713]2106#if Q0048_CGS_3D_ASYMLUT
[849]2107#if REF_REGION_OFFSET
[916]2108          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, m_pcPic->getPicYuvRec(), scalEL, altRL );
[713]2109#else
[916]2110          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, m_pcPic->getPicYuvRec(), scalEL );
[713]2111#endif
[494]2112#else
[916]2113          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), m_pcPic->getPicYuvRec(), scalEL );
[849]2114#endif
2115#else
[713]2116#if Q0048_CGS_3D_ASYMLUT
[916]2117            m_cPrediction.upsampleBasePic( refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, m_pcPic->getPicYuvRec(), scalEL );
[713]2118#else
[916]2119            m_cPrediction.upsampleBasePic( refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), m_pcPic->getPicYuvRec(), scalEL );
[494]2120#endif
2121#endif
[713]2122#endif
[946]2123#endif
[815]2124          }
[313]2125        }
2126        else
2127        {
[916]2128          m_pcPic->setFullPelBaseRec( refLayerIdc, pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec() );
[313]2129        }
[916]2130        pcSlice->setFullPelBaseRec ( refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc) );
[815]2131#endif //SVC_EXTENSION
[313]2132      }
2133    }
2134
2135    if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
2136    {
[916]2137      for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
[494]2138      {
2139        UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
2140#if AVC_BASE
[874]2141#if VPS_AVC_BL_FLAG_REMOVAL
2142        if( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getNonHEVCBaseLayerFlag() )
2143#else
[540]2144        if( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getAvcBaseLayerFlag() )
[874]2145#endif
[494]2146        {
2147          pcSlice->setBaseColPic ( refLayerIdc, *m_ppcTDecTop[0]->getListPic()->begin() );
2148        }
2149        else
2150        {
2151#if VPS_EXTN_DIRECT_REF_LAYERS
2152          TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
2153#else
2154          TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
2155#endif
2156          TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
2157          pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
2158        }
2159#else
2160#if VPS_EXTN_DIRECT_REF_LAYERS
2161        TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
2162#else
2163        TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
2164#endif
2165        TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
2166        pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
2167#endif
2168
[916]2169        pcSlice->setFullPelBaseRec ( refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc) );
[494]2170      }
2171
2172      pcSlice->setILRPic( m_cIlpPic );
2173
[313]2174#if REF_IDX_MFM
2175      pcSlice->setRefPicList( m_cListPic, false, m_cIlpPic);
2176    }
2177#if M0040_ADAPTIVE_RESOLUTION_CHANGE
2178    else if ( m_layerId > 0 )
2179    {
2180      pcSlice->setRefPicList( m_cListPic, false, NULL);
2181    }
2182#endif
[494]2183#if MFM_ENCCONSTRAINT
2184    if( pcSlice->getMFMEnabledFlag() )
2185    {
[815]2186      TComPic* refPic = pcSlice->getRefPic( pcSlice->getSliceType() == B_SLICE ? ( RefPicList )( 1 - pcSlice->getColFromL0Flag() ) : REF_PIC_LIST_0 , pcSlice->getColRefIdx() );
2187
2188      assert( refPic );
2189
2190      Int refLayerId = refPic->getLayerId();
2191
[494]2192      if( refLayerId != pcSlice->getLayerId() )
2193      {
2194        TComPic* pColBasePic = pcSlice->getBaseColPic( *m_ppcTDecTop[refLayerId]->getListPic() );
2195        assert( pColBasePic->checkSameRefInfo() == true );
2196      }
2197    }
[313]2198#endif
[494]2199#endif
2200   
[540]2201    if( m_layerId > 0 && pcSlice->getVPS()->getCrossLayerIrapAlignFlag() )
[442]2202    {
[540]2203#if M0040_ADAPTIVE_RESOLUTION_CHANGE
2204      if( !pcSlice->getVPS()->getSingleLayerForNonIrapFlag() || ( pcSlice->getVPS()->getSingleLayerForNonIrapFlag() && pcSlice->isIRAP() ) )
2205#endif
[442]2206      for(Int dependentLayerIdx = 0; dependentLayerIdx < pcSlice->getVPS()->getNumDirectRefLayers(m_layerId); dependentLayerIdx++)
2207      {
2208        TComList<TComPic*> *cListPic = getRefLayerDec( dependentLayerIdx )->getListPic();
2209        TComPic* refpicLayer = pcSlice->getRefPic(*cListPic, pcSlice->getPOC() );
2210        if(refpicLayer && pcSlice->isIRAP())
2211        {                 
2212          assert(pcSlice->getNalUnitType() == refpicLayer->getSlice(0)->getNalUnitType());
2213        }
2214      }
2215    }
[850]2216   
[815]2217    if( m_layerId > 0 && !pcSlice->isIntra() && pcSlice->getEnableTMVPFlag() )
2218    {
2219      TComPic* refPic = pcSlice->getRefPic(RefPicList(1 - pcSlice->getColFromL0Flag()), pcSlice->getColRefIdx());
2220
2221      assert( refPic );
[850]2222#if R0226_SLICE_TMVP
2223      assert ( refPic->getPicSym()->getSlice(0)->getAvailableForTMVPRefFlag() == true );
2224#endif
[815]2225
2226      // It is a requirement of bitstream conformance when the collocated picture, used for temporal motion vector prediction, is an inter-layer reference picture,
2227      // VpsInterLayerMotionPredictionEnabled[ LayerIdxInVps[ currLayerId ] ][ LayerIdxInVps[ rLId ] ] shall be equal to 1, where rLId is set equal to nuh_layer_id of the inter-layer picture.
2228      if( refPic->isILR(pcSlice->getLayerId()) )
2229      {
2230        assert( m_ppcTDecTop[m_layerId]->getMotionPredEnabledFlag(refPic->getLayerId()) );
2231      }
2232    }
[494]2233#endif //SVC_EXTENSION
[442]2234   
[313]2235    // For generalized B
2236    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
2237    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
2238    {
2239      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
2240      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
2241
2242      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
2243      {
2244        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
2245      }
2246    }
2247    if (!pcSlice->isIntra())
2248    {
2249      Bool bLowDelay = true;
2250      Int  iCurrPOC  = pcSlice->getPOC();
2251      Int iRefIdx = 0;
2252
2253      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
2254      {
2255        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
2256        {
2257          bLowDelay = false;
2258        }
2259      }
2260      if (pcSlice->isInterB())
2261      {
2262        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
2263        {
2264          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
2265          {
2266            bLowDelay = false;
2267          }
[916]2268        }
[313]2269      }
2270
[916]2271      pcSlice->setCheckLDC(bLowDelay);
[313]2272    }
2273
2274    //---------------
2275    pcSlice->setRefPOCList();
2276  }
2277
[916]2278  m_pcPic->setCurrSliceIdx(m_uiSliceIdx);
[313]2279  if(pcSlice->getSPS()->getScalingListFlag())
2280  {
2281    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
2282    if(pcSlice->getPPS()->getScalingListPresentFlag())
2283    {
2284      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
2285    }
[540]2286#if SCALINGLIST_INFERRING
2287    if( m_layerId == 0 || ( m_layerId > 0 && !pcSlice->getPPS()->getInferScalingListFlag() && !pcSlice->getSPS()->getInferScalingListFlag() ) )
2288#endif
[313]2289    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
2290    {
2291      pcSlice->setDefaultScalingList();
2292    }
[916]2293    m_cTrQuant.setScalingListDec(pcSlice->getScalingList(), pcSlice->getSPS()->getChromaFormatIdc());
[313]2294    m_cTrQuant.setUseScalingList(true);
2295  }
2296  else
2297  {
[916]2298    m_cTrQuant.setFlatScalingList(pcSlice->getSPS()->getChromaFormatIdc());
[313]2299    m_cTrQuant.setUseScalingList(false);
2300  }
2301
2302  //  Decode a picture
[916]2303  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, m_pcPic);
[313]2304
[903]2305#if P0297_VPS_POC_LSB_ALIGNED_FLAG
2306  setFirstPicInLayerDecodedFlag(true);
2307#endif
[979]2308#if R0071_IRAP_EOS_CROSS_LAYER_IMPACTS
2309  m_lastPicHasEos = false;
2310#endif
[903]2311
[313]2312  m_bFirstSliceInPicture = false;
2313  m_uiSliceIdx++;
2314
2315  return false;
2316}
2317
2318Void TDecTop::xDecodeVPS()
2319{
2320  TComVPS* vps = new TComVPS();
[916]2321
[313]2322  m_cEntropyDecoder.decodeVPS( vps );
[916]2323  m_parameterSetManagerDecoder.storePrefetchedVPS(vps);
[1008]2324#if R0235_SMALLEST_LAYER_ID
2325  checkValueOfTargetOutputLayerSetIdx(vps);
2326#endif
[313]2327}
2328
[833]2329#if SVC_EXTENSION
[313]2330Void TDecTop::xDecodeSPS()
2331{
2332  TComSPS* sps = new TComSPS();
[916]2333#if O0043_BEST_EFFORT_DECODING
2334  sps->setForceDecodeBitDepth(m_forceDecodeBitDepth);
2335#endif
[313]2336  sps->setLayerId(m_layerId);
[644]2337#if SPS_DPB_PARAMS
2338  m_cEntropyDecoder.decodeSPS( sps ); // it should be removed after macro clean up
2339#else
[540]2340  m_cEntropyDecoder.decodeSPS( sps, &m_parameterSetManagerDecoder );
[644]2341#endif
[540]2342  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
[442]2343#if !REPN_FORMAT_IN_VPS   // ILRP can only be initialized at activation 
[313]2344  if(m_numLayer>0)
2345  {
2346    xInitILRP(sps);
2347  }
2348#endif
2349}
2350
[713]2351Void TDecTop::xDecodePPS(
2352#if Q0048_CGS_3D_ASYMLUT
2353  TCom3DAsymLUT * pc3DAsymLUT
2354#endif
2355  )
[313]2356{
2357  TComPPS* pps = new TComPPS();
[442]2358
[540]2359#if SCALINGLIST_INFERRING
2360  pps->setLayerId( m_layerId );
[442]2361#endif
2362
[713]2363  m_cEntropyDecoder.decodePPS( pps
2364#if Q0048_CGS_3D_ASYMLUT
2365    , pc3DAsymLUT , m_layerId
2366#endif
2367    );
[313]2368  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
2369}
[833]2370#else
2371Void TDecTop::xDecodeSPS()
2372{
2373  TComSPS* sps = new TComSPS();
[916]2374#if O0043_BEST_EFFORT_DECODING
2375  sps->setForceDecodeBitDepth(m_forceDecodeBitDepth);
2376#endif
[833]2377  m_cEntropyDecoder.decodeSPS( sps );
2378  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
2379}
[313]2380
[833]2381Void TDecTop::xDecodePPS()
2382{
2383  TComPPS* pps = new TComPPS();
2384  m_cEntropyDecoder.decodePPS( pps );
2385  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
2386}
2387#endif //SVC_EXTENSION
2388
[313]2389Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
2390{
2391#if SVC_EXTENSION
2392  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
2393  {
[442]2394    if (m_prevSliceSkipped) // No need to decode SEI messages of a skipped access unit
2395    {
2396      return;
2397    }
[588]2398#if LAYERS_NOT_PRESENT_SEI
[916]2399    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS(), m_pDecodedSEIOutputStream  );
[313]2400#else
[916]2401    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS(), m_pDecodedSEIOutputStream  );
[313]2402#endif
2403  }
2404  else
2405  {
[588]2406#if LAYERS_NOT_PRESENT_SEI
[916]2407    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS(), m_pDecodedSEIOutputStream  );
[313]2408#else
[916]2409    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS(), m_pDecodedSEIOutputStream  );
[313]2410#endif
2411    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
2412    if (activeParamSets.size()>0)
2413    {
2414      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
[884]2415#if !R0247_SEI_ACTIVE
[540]2416      m_parameterSetManagerDecoder.applyPrefetchedPS();
[713]2417      assert(seiAps->activeSeqParameterSetId.size()>0);
2418      if( !m_parameterSetManagerDecoder.activateSPSWithSEI( seiAps->activeSeqParameterSetId[0] ) )
[313]2419      {
2420        printf ("Warning SPS activation with Active parameter set SEI failed");
2421      }
[884]2422#else
2423      getLayerDec(0)->m_parameterSetManagerDecoder.applyPrefetchedPS();
2424      assert(seiAps->activeSeqParameterSetId.size()>0);
2425      if( !getLayerDec(0)->m_parameterSetManagerDecoder.activateSPSWithSEI( seiAps->activeSeqParameterSetId[0] ) )
2426      {
2427        printf ("Warning SPS activation with Active parameter set SEI failed");
2428      }
2429      for (Int c=1 ; c <= seiAps->numSpsIdsMinus1; c++)
2430      {
2431        Int layerIdx = seiAps->layerSpsIdx[c];
2432        getLayerDec(layerIdx)->m_parameterSetManagerDecoder.applyPrefetchedPS();
2433        if( !getLayerDec(layerIdx)->m_parameterSetManagerDecoder.activateSPSWithSEI( seiAps->activeSeqParameterSetId[layerIdx] ) )
2434        {
2435          printf ("Warning SPS activation with Active parameter set SEI failed");
2436        }
2437      }
2438#endif
[313]2439    }
2440  }
2441#else
2442  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
2443  {
[588]2444#if LAYERS_NOT_PRESENT_SEI
[916]2445    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS(), m_pDecodedSEIOutputStream  );
[313]2446#else
[916]2447    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS(), m_pDecodedSEIOutputStream );
2448
[313]2449#endif
2450  }
2451  else
2452  {
[588]2453#if LAYERS_NOT_PRESENT_SEI
[916]2454    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS(), m_pDecodedSEIOutputStream  );
[313]2455#else
[916]2456    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS(), m_pDecodedSEIOutputStream );
[313]2457#endif
2458    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
2459    if (activeParamSets.size()>0)
2460    {
2461      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
2462      m_parameterSetManagerDecoder.applyPrefetchedPS();
[713]2463      assert(seiAps->activeSeqParameterSetId.size()>0);
2464      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParameterSetId[0] ))
[313]2465      {
2466        printf ("Warning SPS activation with Active parameter set SEI failed");
2467      }
2468    }
2469  }
2470#endif
2471}
2472
2473#if SVC_EXTENSION
2474Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC)
2475#else
2476Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
2477#endif
2478{
2479  // Initialize entropy decoder
2480  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
2481  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
2482
[547]2483#if O0137_MAX_LAYERID
2484  // ignore any NAL units with nuh_layer_id == 63
2485  if (nalu.m_layerId == 63 )
2486  { 
2487    return false;
2488  }
2489#endif
[313]2490  switch (nalu.m_nalUnitType)
2491  {
2492    case NAL_UNIT_VPS:
[815]2493#if SVC_EXTENSION
[442]2494      assert( nalu.m_layerId == 0 ); // Non-conforming bitstream. The value of nuh_layer_id of VPS NAL unit shall be equal to 0.
2495#endif
[313]2496      xDecodeVPS();
[916]2497#if RExt__DECODER_DEBUG_BIT_STATISTICS
2498      TComCodingStatistics::IncrementStatisticEP(STATS__BYTE_ALIGNMENT_BITS,nalu.m_Bitstream->readByteAlignment(),0);
2499#endif
[815]2500#if Q0177_EOS_CHECKS
2501      m_isLastNALWasEos = false;
2502#endif
[313]2503#if AVC_BASE
[874]2504#if VPS_AVC_BL_FLAG_REMOVAL
2505      if( m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getNonHEVCBaseLayerFlag() )
2506#else
[540]2507      if( m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
[874]2508#endif
[313]2509      {
2510        if( !m_ppcTDecTop[0]->getBLReconFile()->good() )
2511        {
2512          printf( "Base layer YUV input reading error\n" );
2513          exit(EXIT_FAILURE);
2514        }       
2515      }
2516      else
2517      {
2518        TComList<TComPic*> *cListPic = m_ppcTDecTop[0]->getListPic();
2519        cListPic->clear();
2520      }
2521#endif
[1006]2522#if R0235_SMALLEST_LAYER_ID
2523      xDeriveSmallestLayerId(m_parameterSetManagerDecoder.getPrefetchedVPS(0));
2524#endif
[313]2525      return false;
[916]2526
[313]2527    case NAL_UNIT_SPS:
2528      xDecodeSPS();
[916]2529#if RExt__DECODER_DEBUG_BIT_STATISTICS
2530      TComCodingStatistics::IncrementStatisticEP(STATS__BYTE_ALIGNMENT_BITS,nalu.m_Bitstream->readByteAlignment(),0);
2531#endif
[313]2532      return false;
2533
2534    case NAL_UNIT_PPS:
[713]2535      xDecodePPS(
2536#if Q0048_CGS_3D_ASYMLUT
2537        &m_c3DAsymLUTPPS
2538#endif
2539        );
[916]2540#if RExt__DECODER_DEBUG_BIT_STATISTICS
2541      TComCodingStatistics::IncrementStatisticEP(STATS__BYTE_ALIGNMENT_BITS,nalu.m_Bitstream->readByteAlignment(),0);
2542#endif
[313]2543      return false;
[916]2544
[313]2545    case NAL_UNIT_PREFIX_SEI:
2546    case NAL_UNIT_SUFFIX_SEI:
[815]2547#if Q0177_EOS_CHECKS
2548      if ( nalu.m_nalUnitType == NAL_UNIT_SUFFIX_SEI )
2549      {
2550        assert( m_isLastNALWasEos == false );
2551      }
2552#endif
[313]2553      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
2554      return false;
2555
2556    case NAL_UNIT_CODED_SLICE_TRAIL_R:
2557    case NAL_UNIT_CODED_SLICE_TRAIL_N:
[540]2558    case NAL_UNIT_CODED_SLICE_TSA_R:
[313]2559    case NAL_UNIT_CODED_SLICE_TSA_N:
2560    case NAL_UNIT_CODED_SLICE_STSA_R:
2561    case NAL_UNIT_CODED_SLICE_STSA_N:
2562    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
2563    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
2564    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
2565    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
2566    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
2567    case NAL_UNIT_CODED_SLICE_CRA:
2568    case NAL_UNIT_CODED_SLICE_RADL_N:
2569    case NAL_UNIT_CODED_SLICE_RADL_R:
2570    case NAL_UNIT_CODED_SLICE_RASL_N:
2571    case NAL_UNIT_CODED_SLICE_RASL_R:
[815]2572#if Q0177_EOS_CHECKS
2573      if (nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_N ||
2574          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_N ||
2575          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_N ||
2576          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
2577          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N )
2578      {
2579        assert( m_isLastNALWasEos == false );
2580      }
2581      else
2582      {
2583        m_isLastNALWasEos = false;
2584      }
2585#endif
[313]2586#if SVC_EXTENSION
2587      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, curLayerId, bNewPOC);
2588#else
2589      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
2590#endif
2591      break;
[916]2592
[540]2593    case NAL_UNIT_EOS:
[815]2594#if Q0177_EOS_CHECKS
2595      assert( m_isLastNALWasEos == false );
[979]2596#if !R0071_IRAP_EOS_CROSS_LAYER_IMPACTS
[815]2597      //Check layer id of the nalu. if it is not 0, give a warning message and just return without doing anything.
2598      if (nalu.m_layerId > 0)
2599      {
2600        printf( "\nThis bitstream has EOS with non-zero layer id.\n" );
2601        return false;
2602      }
[979]2603#endif
[815]2604      m_isLastNALWasEos = true;
[979]2605#if R0071_IRAP_EOS_CROSS_LAYER_IMPACTS
2606      m_lastPicHasEos = true;
[815]2607#endif
[979]2608#endif
[540]2609      m_associatedIRAPType = NAL_UNIT_INVALID;
2610      m_pocCRA = 0;
2611      m_pocRandomAccess = MAX_INT;
2612      m_prevPOC = MAX_INT;
2613      m_prevSliceSkipped = false;
2614      m_skippedPOC = 0;
2615      return false;
[916]2616
[540]2617    case NAL_UNIT_ACCESS_UNIT_DELIMITER:
2618      // TODO: process AU delimiter
2619      return false;
[916]2620
[540]2621    case NAL_UNIT_EOB:
[588]2622#if P0130_EOB
2623      //Check layer id of the nalu. if it is not 0, give a warning message.
2624      if (nalu.m_layerId > 0)
2625      {
2626        printf( "\n\nThis bitstream is ended with EOB NALU that has layer id greater than 0\n" );
2627      }
2628#endif
[540]2629      return false;
[916]2630
[713]2631    case NAL_UNIT_FILLER_DATA:
[815]2632#if Q0177_EOS_CHECKS
2633      assert( m_isLastNALWasEos == false );
2634#endif
[713]2635      return false;
[916]2636
[595]2637    case NAL_UNIT_RESERVED_VCL_N10:
2638    case NAL_UNIT_RESERVED_VCL_R11:
2639    case NAL_UNIT_RESERVED_VCL_N12:
2640    case NAL_UNIT_RESERVED_VCL_R13:
2641    case NAL_UNIT_RESERVED_VCL_N14:
2642    case NAL_UNIT_RESERVED_VCL_R15:
[916]2643
[595]2644    case NAL_UNIT_RESERVED_IRAP_VCL22:
2645    case NAL_UNIT_RESERVED_IRAP_VCL23:
[916]2646
[595]2647    case NAL_UNIT_RESERVED_VCL24:
2648    case NAL_UNIT_RESERVED_VCL25:
2649    case NAL_UNIT_RESERVED_VCL26:
2650    case NAL_UNIT_RESERVED_VCL27:
2651    case NAL_UNIT_RESERVED_VCL28:
2652    case NAL_UNIT_RESERVED_VCL29:
2653    case NAL_UNIT_RESERVED_VCL30:
2654    case NAL_UNIT_RESERVED_VCL31:
[916]2655
[595]2656    case NAL_UNIT_RESERVED_NVCL41:
2657    case NAL_UNIT_RESERVED_NVCL42:
2658    case NAL_UNIT_RESERVED_NVCL43:
2659    case NAL_UNIT_RESERVED_NVCL44:
2660    case NAL_UNIT_RESERVED_NVCL45:
2661    case NAL_UNIT_RESERVED_NVCL46:
2662    case NAL_UNIT_RESERVED_NVCL47:
2663    case NAL_UNIT_UNSPECIFIED_48:
2664    case NAL_UNIT_UNSPECIFIED_49:
2665    case NAL_UNIT_UNSPECIFIED_50:
2666    case NAL_UNIT_UNSPECIFIED_51:
2667    case NAL_UNIT_UNSPECIFIED_52:
2668    case NAL_UNIT_UNSPECIFIED_53:
2669    case NAL_UNIT_UNSPECIFIED_54:
2670    case NAL_UNIT_UNSPECIFIED_55:
2671    case NAL_UNIT_UNSPECIFIED_56:
2672    case NAL_UNIT_UNSPECIFIED_57:
2673    case NAL_UNIT_UNSPECIFIED_58:
2674    case NAL_UNIT_UNSPECIFIED_59:
2675    case NAL_UNIT_UNSPECIFIED_60:
2676    case NAL_UNIT_UNSPECIFIED_61:
2677    case NAL_UNIT_UNSPECIFIED_62:
2678    case NAL_UNIT_UNSPECIFIED_63:
2679
[313]2680    default:
[540]2681      assert (0);
[916]2682      break;
[313]2683  }
2684
2685  return false;
2686}
2687
2688/** Function for checking if picture should be skipped because of association with a previous BLA picture
2689 * \param iPOCLastDisplay POC of last picture displayed
2690 * \returns true if the picture should be skipped
2691 * This function skips all TFD pictures that follow a BLA picture
2692 * in decoding order and precede it in output order.
2693 */
2694Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
2695{
[916]2696  if ((m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_N_LP || m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_W_LP || m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_W_RADL) &&
[442]2697       m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
[313]2698  {
2699    iPOCLastDisplay++;
2700    return true;
2701  }
2702  return false;
2703}
2704
2705/** Function for checking if picture should be skipped because of random access
2706 * \param iSkipFrame skip frame counter
2707 * \param iPOCLastDisplay POC of last picture displayed
2708 * \returns true if the picture shold be skipped in the random access.
2709 * This function checks the skipping of pictures in the case of -s option random access.
2710 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
2711 * It also checks the type of Nal unit type at the random access point.
2712 * If the random access point is CRA/CRANT/BLA/BLANT, TFD pictures with POC less than the POC of the random access point are skipped.
2713 * If the random access point is IDR all pictures after the random access point are decoded.
[916]2714 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
2715 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
[313]2716 * access point there is no guarantee that the decoder will not crash.
2717 */
2718Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
2719{
[916]2720  if (iSkipFrame)
[313]2721  {
2722    iSkipFrame--;   // decrement the counter
2723    return true;
2724  }
2725  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
2726  {
2727    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
2728        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
2729        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
2730        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
2731    {
2732      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
2733      m_pocRandomAccess = m_apcSlicePilot->getPOC();
2734    }
2735    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
2736    {
2737      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
2738    }
[916]2739    else
[313]2740    {
2741      static Bool warningMessage = false;
2742      if(!warningMessage)
2743      {
2744        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
2745        warningMessage = true;
2746      }
2747      return true;
2748    }
2749  }
2750  // skip the reordered pictures, if necessary
2751  else if (m_apcSlicePilot->getPOC() < m_pocRandomAccess && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
2752  {
2753    iPOCLastDisplay++;
2754    return true;
2755  }
2756  // if we reach here, then the picture is not skipped.
[916]2757  return false;
[313]2758}
2759
[595]2760#if SVC_EXTENSION
[916]2761#if !REPN_FORMAT_IN_VPS
2762Void TDecTop::xInitILRP(TComSPS *pcSPS)
2763#else
2764Void TDecTop::xInitILRP(TComSlice *slice)
2765#endif
2766{
2767#if REPN_FORMAT_IN_VPS
2768  TComSPS* pcSPS = slice->getSPS();
2769  Int bitDepthY   = slice->getBitDepthY();
2770  Int bitDepthC   = slice->getBitDepthC();
2771  Int picWidth    = slice->getPicWidthInLumaSamples();
2772  Int picHeight   = slice->getPicHeightInLumaSamples();
2773#endif
2774  if(m_layerId>0)
2775  {
2776#if REPN_FORMAT_IN_VPS
2777    g_bitDepth[CHANNEL_TYPE_LUMA]     = bitDepthY;
2778    g_bitDepth[CHANNEL_TYPE_CHROMA]   = bitDepthC;
2779#else
2780    g_bitDepth[CHANNEL_TYPE_LUMA]     = pcSPS->getBitDepthY();
2781    g_bitDepth[CHANNEL_TYPE_CHROMA]   = pcSPS->getBitDepthC();
2782#endif
2783    g_uiMaxCUWidth  = pcSPS->getMaxCUWidth();
2784    g_uiMaxCUHeight = pcSPS->getMaxCUHeight();
2785    g_uiMaxCUDepth  = pcSPS->getMaxCUDepth();
2786    g_uiAddCUDepth  = max (0, pcSPS->getLog2MinCodingBlockSize() - (Int)pcSPS->getQuadtreeTULog2MinSize() );
2787
2788    Int  numReorderPics[MAX_TLAYER];
2789#if R0156_CONF_WINDOW_IN_REP_FORMAT
2790    Window &conformanceWindow = slice->getConformanceWindow();
2791#else
2792    Window &conformanceWindow = pcSPS->getConformanceWindow();
2793#endif
2794    Window defaultDisplayWindow = pcSPS->getVuiParametersPresentFlag() ? pcSPS->getVuiParameters()->getDefaultDisplayWindow() : Window();
2795
2796    for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
2797    {
2798#if USE_DPB_SIZE_TABLE
2799      if( getCommonDecoderParams()->getTargetOutputLayerSetIdx() == 0 )
2800      {
2801        assert( this->getLayerId() == 0 );
2802        numReorderPics[temporalLayer] = pcSPS->getNumReorderPics(temporalLayer);
2803      }
2804      else
2805      {
2806        TComVPS *vps = slice->getVPS();
2807        // SHM decoders will use DPB size table in the VPS to determine the number of reorder pictures.
2808        numReorderPics[temporalLayer] = vps->getMaxVpsNumReorderPics( getCommonDecoderParams()->getTargetOutputLayerSetIdx() , temporalLayer);
2809      }
2810#else
2811      numReorderPics[temporalLayer] = pcSPS->getNumReorderPics(temporalLayer);
2812#endif
2813    }
2814
2815    if (m_cIlpPic[0] == NULL)
2816    {
2817      for (Int j=0; j < m_numDirectRefLayers; j++)
2818      {
2819
2820        m_cIlpPic[j] = new  TComPic;
2821
2822#if AUXILIARY_PICTURES
2823#if REPN_FORMAT_IN_VPS
2824        m_cIlpPic[j]->create(picWidth, picHeight, slice->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
2825#else
2826        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), pcSPS->getChromaFormatIdc(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
2827#endif
2828#else
2829#if REPN_FORMAT_IN_VPS
2830        m_cIlpPic[j]->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
2831#else
2832        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
2833#endif
2834#endif
2835        for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCtusInFrame(); i++)
2836        {
2837          m_cIlpPic[j]->getPicSym()->getCtu(i)->initCtu(m_cIlpPic[j], i);
2838        }
2839      }
2840    }
2841  }
2842}
2843
[313]2844#if VPS_EXTN_DIRECT_REF_LAYERS
2845TDecTop* TDecTop::getRefLayerDec( UInt refLayerIdc )
2846{
[540]2847  TComVPS* vps = m_parameterSetManagerDecoder.getActiveVPS();
[313]2848  if( vps->getNumDirectRefLayers( m_layerId ) <= 0 )
2849  {
2850    return (TDecTop *)getLayerDec( 0 );
2851  }
2852 
2853  return (TDecTop *)getLayerDec( vps->getRefLayerId( m_layerId, refLayerIdc ) );
2854}
2855#endif
2856
[588]2857#if VPS_EXTN_DIRECT_REF_LAYERS
[313]2858Void TDecTop::setRefLayerParams( TComVPS* vps )
2859{
2860  for(UInt layer = 0; layer < m_numLayer; layer++)
2861  {
2862    TDecTop *decTop = (TDecTop *)getLayerDec(layer);
2863    decTop->setNumSamplePredRefLayers(0);
2864    decTop->setNumMotionPredRefLayers(0);
2865    decTop->setNumDirectRefLayers(0);
2866    for(Int i = 0; i < MAX_VPS_LAYER_ID_PLUS1; i++)
2867    {
2868      decTop->setSamplePredEnabledFlag(i, false);
2869      decTop->setMotionPredEnabledFlag(i, false);
2870      decTop->setSamplePredRefLayerId(i, 0);
2871      decTop->setMotionPredRefLayerId(i, 0);
2872    }
2873    for(Int j = 0; j < layer; j++)
2874    {
2875      if (vps->getDirectDependencyFlag(layer, j))
2876      {
2877        decTop->setRefLayerId(decTop->getNumDirectRefLayers(), vps->getLayerIdInNuh(layer));
2878        decTop->setNumDirectRefLayers(decTop->getNumDirectRefLayers() + 1);
2879
2880        Int samplePredEnabledFlag = (vps->getDirectDependencyType(layer, j) + 1) & 1;
2881        decTop->setSamplePredEnabledFlag(j, samplePredEnabledFlag == 1 ? true : false);
2882        decTop->setNumSamplePredRefLayers(decTop->getNumSamplePredRefLayers() + samplePredEnabledFlag);
2883
2884        Int motionPredEnabledFlag = ((vps->getDirectDependencyType(layer, j) + 1) & 2) >> 1;
2885        decTop->setMotionPredEnabledFlag(j, motionPredEnabledFlag == 1 ? true : false);
2886        decTop->setNumMotionPredRefLayers(decTop->getNumMotionPredRefLayers() + motionPredEnabledFlag);
2887      }
2888    }
2889  }
[815]2890  for( Int i = 1; i < m_numLayer; i++ )
[313]2891  {
[815]2892    Int mIdx = 0, sIdx = 0;
[313]2893    Int iNuhLId = vps->getLayerIdInNuh(i);
2894    TDecTop *decTop = (TDecTop *)getLayerDec(iNuhLId);
2895    for ( Int j = 0; j < i; j++ )
2896    {
2897      if (decTop->getMotionPredEnabledFlag(j))
2898      {
2899        decTop->setMotionPredRefLayerId(mIdx++, vps->getLayerIdInNuh(j));
2900      }
2901      if (decTop->getSamplePredEnabledFlag(j))
2902      {
2903        decTop->setSamplePredRefLayerId(sIdx++, vps->getLayerIdInNuh(j));
2904      }
2905    }
2906  }
2907}
[916]2908#endif
[313]2909
[916]2910#if EARLY_REF_PIC_MARKING
2911Void TDecTop::earlyPicMarking(Int maxTemporalLayer, std::vector<Int>& targetDecLayerIdSet)
2912{
2913  UInt currTid = m_pcPic->getTLayer();
2914  UInt highestTid = (maxTemporalLayer >= 0) ? maxTemporalLayer : (m_pcPic->getSlice(0)->getSPS()->getMaxTLayers() - 1);
2915  UInt latestDecLayerId = m_layerId;
2916  UInt numTargetDecLayers = 0;
2917  Int targetDecLayerIdList[MAX_LAYERS];
2918  UInt latestDecIdx = 0;
2919  TComSlice* pcSlice = m_pcPic->getSlice(0);
2920
2921  if ( currTid != highestTid )  // Marking  process is only applicaple for highest decoded TLayer
2922  {
2923    return;
2924  }
2925
2926  // currPic must be marked as "used for reference" and must be a sub-layer non-reference picture
2927  if ( !((pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N  ||
2928          pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N    ||
2929          pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N   ||
2930          pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N   ||
2931          pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N   ||
2932          pcSlice->getNalUnitType() == NAL_UNIT_RESERVED_VCL_N10     ||
2933          pcSlice->getNalUnitType() == NAL_UNIT_RESERVED_VCL_N12     ||
2934          pcSlice->getNalUnitType() == NAL_UNIT_RESERVED_VCL_N14) && pcSlice->isReferenced()))
2935  {
2936    return;
2937  }
2938
2939  if ( targetDecLayerIdSet.size() == 0 ) // Cannot mark if we don't know the number of scalable layers
2940  {
2941    return;
2942  }
2943
2944  for (std::vector<Int>::iterator it = targetDecLayerIdSet.begin(); it != targetDecLayerIdSet.end(); it++)
2945  {
2946    if ( latestDecLayerId == (*it) )
2947    {
2948      latestDecIdx = numTargetDecLayers;
2949    }
2950    targetDecLayerIdList[numTargetDecLayers++] = (*it);
2951  }
2952
2953  Int remainingInterLayerReferencesFlag = 0;
2954#if O0225_MAX_TID_FOR_REF_LAYERS
2955  for ( Int j = latestDecIdx + 1; j < numTargetDecLayers; j++ )
2956  {
2957    Int jLidx = pcSlice->getVPS()->getLayerIdInVps(targetDecLayerIdList[j]);
2958    if ( currTid <= pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(latestDecLayerId,jLidx) - 1 )
2959    {
2960#else
2961  if ( currTid <= pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(latestDecLayerId) - 1 )
2962  {
2963    for ( Int j = latestDecIdx + 1; j < numTargetDecLayers; j++ )
2964    {
2965#endif
2966      for ( Int k = 0; k < m_ppcTDecTop[targetDecLayerIdList[j]]->getNumDirectRefLayers(); k++ )
2967      {
2968        if ( latestDecIdx == m_ppcTDecTop[targetDecLayerIdList[j]]->getRefLayerId(k) )
2969        {
2970          remainingInterLayerReferencesFlag = 1;
2971        }
2972      }
2973    }
2974  }
2975
2976  if ( remainingInterLayerReferencesFlag == 0 )
2977  {
2978    pcSlice->setReferenced(false);
2979  }
2980}
[313]2981#endif
2982
[588]2983#if OUTPUT_LAYER_SET_INDEX
2984Void TDecTop::checkValueOfTargetOutputLayerSetIdx(TComVPS *vps)
[313]2985{
[588]2986  CommonDecoderParams* params = this->getCommonDecoderParams();
[313]2987
[962]2988#if !FIX_CONF_MODE
[588]2989  assert( params->getTargetLayerId() < vps->getMaxLayers() );
[962]2990#endif
[313]2991
[540]2992  if( params->getValueCheckedFlag() )
2993  {
2994    return; // Already checked
2995  }
[588]2996  if( params->getTargetOutputLayerSetIdx() == -1 )  // Output layer set index not specified
[540]2997  {
2998    Bool layerSetMatchFound = false;
2999    // Output layer set index not assigned.
3000    // Based on the value of targetLayerId, check if any of the output layer matches
3001    // Currently, the target layer ID in the encoder assumes that all the layers are decoded   
3002    // Check if any of the output layer sets match this description
3003    for(Int i = 0; i < vps->getNumOutputLayerSets(); i++)
3004    {
3005      Bool layerSetMatchFlag = true;
3006      Int layerSetIdx = vps->getOutputLayerSetIdx( i );
3007      if( vps->getNumLayersInIdList( layerSetIdx ) == params->getTargetLayerId() + 1 )
3008      {
3009        for(Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++)
3010        {
3011          if( vps->getLayerSetLayerIdList( layerSetIdx, j ) != j )
3012          {
3013            layerSetMatchFlag = false;
3014            break;
3015          }
3016        }
3017      }
3018      else
3019      {
3020        layerSetMatchFlag = false;
3021      }
3022     
3023      if( layerSetMatchFlag ) // Potential output layer set candidate found
3024      {
3025        // If target dec layer ID list is also included - check if they match
3026        if( params->getTargetDecLayerIdSet() )
3027        {
3028          if( params->getTargetDecLayerIdSet()->size() ) 
3029          {
3030            for(Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++)
3031            {
3032              if( *(params->getTargetDecLayerIdSet()->begin() + j) != vps->getLayerIdInNuh(vps->getLayerSetLayerIdList( layerSetIdx, j )))
3033              {
3034                layerSetMatchFlag = false;
3035              }
3036            }
3037          }
3038        }
3039        if( layerSetMatchFlag ) // The target dec layer ID list also matches, if present
3040        {
3041          // Match found
3042          layerSetMatchFound = true;
[588]3043          params->setTargetOutputLayerSetIdx( i );
[540]3044          params->setValueCheckedFlag( true );
3045          break;
3046        }
3047      }
3048    }
3049    assert( layerSetMatchFound ); // No output layer set matched the value of either targetLayerId or targetdeclayerIdlist
3050  }   
3051  else // Output layer set index is assigned - check if the values match
3052  {
3053    // Check if the target decoded layer is the highest layer in the list
[1008]3054#if R0235_SMALLEST_LAYER_ID
3055    assert( params->getTargetOutputLayerSetIdx() < vps->getNumOutputLayerSets() );
3056#endif
[928]3057#if !CONFORMANCE_BITSTREAM_MODE
[588]3058    assert( params->getTargetOutputLayerSetIdx() < vps->getNumLayerSets() );
[928]3059#endif
[588]3060    Int layerSetIdx = vps->getOutputLayerSetIdx( params->getTargetOutputLayerSetIdx() );  // Index to the layer set
[928]3061#if !CONFORMANCE_BITSTREAM_MODE
[540]3062    assert( params->getTargetLayerId() == vps->getNumLayersInIdList( layerSetIdx ) - 1);
[928]3063#endif
[1008]3064   
3065#if !R0235_SMALLEST_LAYER_ID
[540]3066    Bool layerSetMatchFlag = true;
3067    for(Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++)
3068    {
3069      if( vps->getLayerSetLayerIdList( layerSetIdx, j ) != j )
3070      {
3071        layerSetMatchFlag = false;
3072        break;
3073      }
3074    }
3075
3076    assert(layerSetMatchFlag);    // Signaled output layer set index does not match targetOutputLayerId.
[1008]3077#endif
[540]3078   
3079    // Check if the targetdeclayerIdlist matches the output layer set
3080    if( params->getTargetDecLayerIdSet() )
3081    {
3082      if( params->getTargetDecLayerIdSet()->size() ) 
3083      {
3084        for(Int i = 0; i < vps->getNumLayersInIdList( layerSetIdx ); i++)
3085        {
3086          assert( *(params->getTargetDecLayerIdSet()->begin() + i) == vps->getLayerIdInNuh(vps->getLayerSetLayerIdList( layerSetIdx, i )));
3087        }
3088      }
3089    }
3090    params->setValueCheckedFlag( true );
3091
3092  }
[961]3093#if FIX_CONF_MODE
3094  // Set correct value of targetLayerId
3095  Int targetOlsIdx = params->getTargetOutputLayerSetIdx();
3096  Int targetLsIdx = vps->getOutputLayerSetIdx( targetOlsIdx );
3097  params->setTargetLayerId( vps->getLayerSetLayerIdList( targetLsIdx, vps->getNumLayersInIdList(targetLsIdx)-1 ) );
3098#endif
[962]3099#if FIX_NON_OUTPUT_LAYER
3100  // Check if the current layer is an output layer
3101  for(Int i = 0; i < vps->getNumLayersInIdList( targetLsIdx ); i++)
3102  {
3103    if( vps->getOutputLayerFlag( targetOlsIdx, i ) )
3104    {
3105      this->getLayerDec( vps->getLayerSetLayerIdList( targetLsIdx, i ) )->m_isOutputLayerFlag = true;
3106    }
3107  }
3108#endif
[540]3109}
3110#endif
[588]3111#if RESOLUTION_BASED_DPB
3112Void TDecTop::assignSubDpbs(TComVPS *vps)
3113{
3114  if( m_subDpbIdx == -1 ) // Sub-DPB index is not already assigned
3115  {
3116    Int lsIdx = vps->getOutputLayerSetIdx( getCommonDecoderParams()->getTargetOutputLayerSetIdx() );
3117
3118    Int layerIdx = vps->findLayerIdxInLayerSet( lsIdx, getLayerId() );
3119    assert( layerIdx != -1 ); // Current layer should be found in the layer set.
3120
3121    // Copy from the active VPS based on the layer ID.
3122    m_subDpbIdx = vps->getSubDpbAssigned( lsIdx, layerIdx );
3123  }
3124}
3125#endif
[815]3126#if POC_RESET_IDC_DECODER
3127Void TDecTop::markAllPicsAsNoCurrAu()
3128{
3129  for(Int i = 0; i < MAX_LAYERS; i++)
3130  {
3131    TComList<TComPic*>* listPic = this->getLayerDec(i)->getListPic();
3132    TComList<TComPic*>::iterator  iterPic = listPic->begin();
3133    while ( iterPic != listPic->end() )
3134    {
3135      TComPic *pcPic = *(iterPic);
3136      pcPic->setCurrAuFlag( false );
3137      iterPic++;
3138    }
3139  }
3140}
3141#endif
[713]3142#if Q0048_CGS_3D_ASYMLUT
3143Void TDecTop::initAsymLut(TComSlice *pcSlice)
3144{
3145  if(m_layerId>0)
3146  {
3147    if(!m_pColorMappedPic)
3148    {
3149      Int picWidth    = pcSlice->getPicWidthInLumaSamples();
3150      Int picHeight   = pcSlice->getPicHeightInLumaSamples();
3151      m_pColorMappedPic = new TComPicYuv;
3152      m_pColorMappedPic->create( picWidth, picHeight, pcSlice->getChromaFormatIdc()/*CHROMA_420*/, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, NULL );
3153    }
3154  }
3155}
3156#endif
[851]3157#if POC_RESET_RESTRICTIONS
3158Void TDecTop::resetPocRestrictionCheckParameters()
3159{
3160  TDecTop::m_checkPocRestrictionsForCurrAu       = false;
3161  TDecTop::m_pocResetIdcOrCurrAu                 = -1;
3162  TDecTop::m_baseLayerIdrFlag                    = false;
3163  TDecTop::m_baseLayerPicPresentFlag             = false;
3164  TDecTop::m_baseLayerIrapFlag                   = false;
3165  TDecTop::m_nonBaseIdrPresentFlag               = false;
3166  TDecTop::m_nonBaseIdrType                      = -1;
3167  TDecTop::m_picNonIdrWithRadlPresentFlag        = false;
3168  TDecTop::m_picNonIdrNoLpPresentFlag            = false;
3169}
3170#endif
[979]3171
3172#if R0071_IRAP_EOS_CROSS_LAYER_IMPACTS
3173Void TDecTop::xCheckLayerReset()
3174{
[1006]3175#if R0235_SMALLEST_LAYER_ID
3176  if (m_apcSlicePilot->isIRAP() && m_layerId > m_smallestLayerId)
3177#else
[979]3178  if (m_apcSlicePilot->isIRAP() && m_layerId > 0)
[1006]3179#endif
[979]3180  {
3181    Bool layerResetFlag;
3182    UInt dolLayerId;
3183    if (m_lastPicHasEos)
3184    {
3185      layerResetFlag = true;
3186      dolLayerId = m_layerId;
3187    }
3188    else if ((m_apcSlicePilot->isCRA() && m_apcSlicePilot->getHandleCraAsBlaFlag()) ||
3189      (m_apcSlicePilot->isIDR() && m_apcSlicePilot->getCrossLayerBLAFlag()) || m_apcSlicePilot->isBLA())
3190    {
3191      layerResetFlag = true;
3192      dolLayerId = m_layerId;
3193    }
3194    else
3195    {
3196      layerResetFlag = false;
3197    }
3198
3199    if (layerResetFlag)
3200    {
3201      for (Int i = 0; i < m_apcSlicePilot->getVPS()->getNumPredictedLayers(dolLayerId); i++)
3202      {
3203        UInt iLayerId = m_apcSlicePilot->getVPS()->getPredictedLayerId(dolLayerId, i);
3204        m_ppcTDecTop[iLayerId]->m_layerInitializedFlag = false;
3205        m_ppcTDecTop[iLayerId]->m_firstPicInLayerDecodedFlag = false;
3206      }
3207
3208      for (TComList<TComPic*>::iterator i = m_cListPic.begin(); i != m_cListPic.end(); i++)
3209      {
3210        if ((*i)->getPOC() != m_apcSlicePilot->getPOC())
3211        {
3212          (*i)->getSlice(0)->setReferenced(false);
3213        }
3214      }
3215
3216      for (UInt i = 0; i < m_apcSlicePilot->getVPS()->getNumPredictedLayers(dolLayerId); i++)
3217      {
3218        UInt predLId = m_apcSlicePilot->getVPS()->getPredictedLayerId(dolLayerId, i);
3219        for (TComList<TComPic*>::iterator pic = m_ppcTDecTop[predLId]->getListPic()->begin(); pic != m_ppcTDecTop[predLId]->getListPic()->end(); pic++)
3220        {
3221          if ((*pic)->getSlice(0)->getPOC() != m_apcSlicePilot->getPOC())
3222          {
3223            (*pic)->getSlice(0)->setReferenced(false);
3224          }
3225        }
3226      }
3227    }
3228  }
3229}
3230
3231Void TDecTop::xSetLayerInitializedFlag()
3232{
3233  if (m_apcSlicePilot->isIRAP() && m_apcSlicePilot->getNoRaslOutputFlag())
3234  {
3235    if (m_layerId == 0)
3236    {
3237      m_ppcTDecTop[m_layerId]->setLayerInitializedFlag(true);
3238    }
3239    else if (!m_ppcTDecTop[m_layerId]->getLayerInitializedFlag() && m_apcSlicePilot->getVPS()->getNumDirectRefLayers(m_layerId) == 0)
3240    {
3241      m_ppcTDecTop[m_layerId]->setLayerInitializedFlag(true);
3242    }
3243    else if (!m_ppcTDecTop[m_layerId]->getLayerInitializedFlag())
3244    {
3245      Bool refLayersInitialized = true;
3246      for (UInt j = 0; j < m_apcSlicePilot->getVPS()->getNumDirectRefLayers(m_layerId); j++)
3247      {
3248        UInt refLayerId = m_apcSlicePilot->getVPS()->getRefLayerId(m_layerId, j);
3249        if (!m_ppcTDecTop[refLayerId]->getLayerInitializedFlag())
3250        {
3251          refLayersInitialized = false;
3252        }
3253      }
3254      if (refLayersInitialized)
3255      {
3256        m_ppcTDecTop[m_layerId]->setLayerInitializedFlag(true);
3257      }
3258    }
3259  }
3260}
3261#endif
3262
[1006]3263#if R0235_SMALLEST_LAYER_ID
3264Void TDecTop::xDeriveSmallestLayerId(TComVPS* vps)
3265{
3266  UInt smallestLayerId;
[1008]3267  Int  targetOlsIdx = m_commonDecoderParams->getTargetOutputLayerSetIdx();
3268  assert( targetOlsIdx >= 0 );
3269
[1006]3270  UInt targetDecLayerSetIdx = vps->getOutputLayerSetIdx(targetOlsIdx);
3271  UInt lsIdx = targetDecLayerSetIdx;
3272  UInt targetDecLayerIdList[MAX_LAYERS] = {0};
3273
3274  for (UInt i = 0, j = 0; i < vps->getNumLayersInIdList(lsIdx); i++)
3275  {
3276    if (vps->getNecessaryLayerFlag(targetOlsIdx, i))
3277    {
3278      targetDecLayerIdList[j++] = vps->getLayerSetLayerIdList(lsIdx, i);
3279    }
3280  }
3281
3282  if (targetDecLayerSetIdx <= vps->getVpsNumLayerSetsMinus1())
3283  {
3284    smallestLayerId = 0;
3285  }
3286  else if (vps->getNumLayersInIdList(targetDecLayerSetIdx) == 1)
3287  {
3288    smallestLayerId = 0;
3289  }
3290  else
3291  {
3292    smallestLayerId = targetDecLayerIdList[0];
3293  }
3294
3295  for (UInt layer = 0; layer <= MAX_VPS_LAYER_ID_PLUS1 - 1; layer++)
3296  {
3297    m_ppcTDecTop[layer]->m_smallestLayerId = smallestLayerId;
3298  }
3299}
3300#endif
3301
[595]3302#endif //SVC_EXTENSION
[713]3303
3304
[313]3305//! \}
Note: See TracBrowser for help on using the repository browser.