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

Last change on this file since 963 was 953, checked in by qualcomm, 10 years ago

Fixes for conformance testing and non-output layers.

  • Value of PicOutputFlag of non-output layers was not being computed correctly. Fixed under MACRO FIX_NON_OUTPUT_LAYER
  • Some fixes for conformance testing under macro FIX_CONF_MODE.

From: Adarsh K. Ramasubramonian <aramasub@…>

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