source: SHVCSoftware/trunk/source/Lib/TLibDecoder/TDecTop.cpp @ 1115

Last change on this file since 1115 was 906, checked in by seregin, 10 years ago

merge SHM-dev

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