source: SHVCSoftware/branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.cpp @ 941

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

support profile, tier and level for each layer, patch was provided by Hendry <fhendry@…>

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