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

Last change on this file since 1323 was 1321, checked in by seregin, 9 years ago

port rev 4396, 4397, 4398

  • Property svn:eol-style set to native
File size: 93.5 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-2015, 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#if RExt__DECODER_DEBUG_BIT_STATISTICS
41#include "TLibCommon/TComCodingStatistics.h"
42#endif
43
44#if SVC_EXTENSION
45UInt  TDecTop::m_prevPOC = MAX_UINT;
46UInt  TDecTop::m_uiPrevLayerId = MAX_UINT;
47Bool  TDecTop::m_bFirstSliceInSequence = true;
48Bool  TDecTop::m_checkPocRestrictionsForCurrAu       = false;
49Int   TDecTop::m_pocResetIdcOrCurrAu                 = -1;
50Bool  TDecTop::m_baseLayerIdrFlag                    = false;
51Bool  TDecTop::m_baseLayerPicPresentFlag             = false;
52Bool  TDecTop::m_baseLayerIrapFlag                   = false;
53Bool  TDecTop::m_nonBaseIdrPresentFlag               = false;
54Int   TDecTop::m_nonBaseIdrType                      = -1;
55Bool  TDecTop::m_picNonIdrWithRadlPresentFlag        = false;
56Bool  TDecTop::m_picNonIdrNoLpPresentFlag            = false;
57Int   TDecTop::m_crossLayerPocResetPeriodId          = -1;
58Int   TDecTop::m_crossLayerPocResetIdc               = -1;
59#endif
60
61//! \ingroup TLibDecoder
62//! \{
63
64TDecTop::TDecTop()
65  : m_iMaxRefPicNum(0)
66  , m_associatedIRAPType(NAL_UNIT_INVALID)
67  , m_pocCRA(0)
68  , m_pocRandomAccess(MAX_INT)
69  , m_cListPic()
70  , m_parameterSetManager()
71  , m_apcSlicePilot(NULL)
72  , m_SEIs()
73  , m_cPrediction()
74  , m_cTrQuant()
75  , m_cGopDecoder()
76  , m_cSliceDecoder()
77  , m_cCuDecoder()
78  , m_cEntropyDecoder()
79  , m_cCavlcDecoder()
80  , m_cSbacDecoder()
81  , m_cBinCABAC()
82  , m_seiReader()
83  , m_cLoopFilter()
84  , m_cSAO()
85  , m_pcPic(NULL)
86#if !SVC_EXTENSION
87  , m_prevPOC(MAX_INT)
88#endif
89  , m_prevTid0POC(0)
90  , m_bFirstSliceInPicture(true)
91#if !SVC_EXTENSION
92  , m_bFirstSliceInSequence(true)
93#endif
94  , m_prevSliceSkipped(false)
95  , m_skippedPOC(0)
96  , m_bFirstSliceInBitstream(true)
97  , m_lastPOCNoOutputPriorPics(-1)
98  , m_isNoOutputPriorPics(false)
99  , m_craNoRaslOutputFlag(false)
100#if O0043_BEST_EFFORT_DECODING
101  , m_forceDecodeBitDepth(8)
102#endif
103  , m_pDecodedSEIOutputStream(NULL)
104  , m_warningMessageSkipPicture(false)
105  , m_prefixSEINALUs()
106{
107#if ENC_DEC_TRACE
108  if (g_hTrace == NULL)
109  {
110    g_hTrace = fopen( "TraceDec.txt", "wb" );
111  }
112  g_bJustDoIt = g_bEncDecTraceDisable;
113  g_nSymbolCounter = 0;
114#endif
115
116#if SVC_EXTENSION
117  m_layerId = 0;
118  m_smallestLayerId = 0;
119#if AVC_BASE
120  m_pBLReconFile = NULL;
121#endif
122  memset(m_cIlpPic, 0, sizeof(m_cIlpPic));
123  m_isLastNALWasEos = false;
124  m_lastPicHasEos = false;
125#if NO_CLRAS_OUTPUT_FLAG
126  m_noClrasOutputFlag          = false;
127  m_layerInitializedFlag       = false;
128  m_firstPicInLayerDecodedFlag = false; 
129#endif
130  m_parseIdc = -1;
131  m_lastPocPeriodId = -1;
132  m_prevPicOrderCnt = 0;
133#if CGS_3D_ASYMLUT
134  m_pColorMappedPic = NULL;
135#endif
136
137  resetPocRestrictionCheckParameters();
138  m_pocResettingFlag        = false;
139  m_pocDecrementedInDPBFlag = false;
140#if CONFORMANCE_BITSTREAM_MODE
141  m_confModeFlag = false;
142#endif
143  m_isOutputLayerFlag = false;
144#endif //SVC_EXTENSION
145}
146
147TDecTop::~TDecTop()
148{
149#if ENC_DEC_TRACE
150  if (g_hTrace != stdout)
151  {
152    fclose( g_hTrace );
153  }
154#endif
155  while (!m_prefixSEINALUs.empty())
156  {
157    delete m_prefixSEINALUs.front();
158    m_prefixSEINALUs.pop_front();
159  }
160#if CGS_3D_ASYMLUT
161  if(m_pColorMappedPic)
162  {
163    m_pColorMappedPic->destroy();
164    delete m_pColorMappedPic;
165    m_pColorMappedPic = NULL;
166  }
167#endif
168}
169
170Void TDecTop::create()
171{
172#if SVC_EXTENSION
173  m_cGopDecoder.create( m_layerId );
174#else
175  m_cGopDecoder.create();
176#endif
177  m_apcSlicePilot = new TComSlice;
178  m_uiSliceIdx = 0;
179}
180
181Void TDecTop::destroy()
182{
183  m_cGopDecoder.destroy();
184
185  delete m_apcSlicePilot;
186  m_apcSlicePilot = NULL;
187
188  m_cSliceDecoder.destroy();
189#if SVC_EXTENSION
190  for(Int i=0; i<MAX_NUM_REF; i++)
191  {
192    if(m_cIlpPic[i])
193    {
194      m_cIlpPic[i]->destroy();
195      delete m_cIlpPic[i];
196      m_cIlpPic[i] = NULL;
197    }
198  }
199#endif
200}
201
202Void TDecTop::init()
203{
204#if !SVC_EXTENSION
205  // initialize ROM
206  initROM();
207#endif
208#if SVC_EXTENSION
209  m_cGopDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
210#else
211  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
212#endif
213  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
214  m_cEntropyDecoder.init(&m_cPrediction);
215}
216
217Void TDecTop::deletePicBuffer ( )
218{
219  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
220  Int iSize = Int( m_cListPic.size() );
221
222  for (Int i = 0; i < iSize; i++ )
223  {
224    TComPic* pcPic = *(iterPic++);
225#if SVC_EXTENSION
226    if( pcPic )
227    {
228      pcPic->destroy();
229
230      delete pcPic;
231      pcPic = NULL;
232    }
233#else
234    pcPic->destroy();
235
236    delete pcPic;
237    pcPic = NULL;
238#endif
239  }
240
241  m_cSAO.destroy();
242
243  m_cLoopFilter.        destroy();
244 
245#if !SVC_EXTENSION
246  // destroy ROM
247  destroyROM();
248#endif
249}
250
251#if SVC_EXTENSION
252Void TDecTop::xGetNewPicBuffer( const TComVPS &vps, const TComSPS &sps, const TComPPS &pps, TComPic*& rpcPic, const UInt temporalLayer )
253#else
254Void TDecTop::xGetNewPicBuffer ( const TComSPS &sps, const TComPPS &pps, TComPic*& rpcPic, const UInt temporalLayer )
255#endif
256{
257#if SVC_EXTENSION
258  if( m_commonDecoderParams->getTargetOutputLayerSetIdx() == 0 )
259  {
260    assert( m_layerId == 0 );
261    m_iMaxRefPicNum = sps.getMaxDecPicBuffering(temporalLayer);     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
262  }
263  else
264  {
265    m_iMaxRefPicNum = vps.getMaxVpsDecPicBufferingMinus1( m_commonDecoderParams->getTargetOutputLayerSetIdx(), vps.getLayerIdcForOls( vps.getOutputLayerSetIdx( m_commonDecoderParams->getTargetOutputLayerSetIdx()), m_layerId ), temporalLayer ) + 1; // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
266  }
267
268  m_iMaxRefPicNum += 1; // it should be updated if more than 1 resampling picture is used
269#else
270  m_iMaxRefPicNum = sps.getMaxDecPicBuffering(temporalLayer);     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
271#endif
272 
273  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
274  {
275    rpcPic = new TComPic();
276
277#if SVC_EXTENSION
278    if(m_layerId > 0)
279    {
280      xSetSpatialEnhLayerFlag( vps, sps, pps, rpcPic );
281    }
282
283    rpcPic->create( vps, sps, pps, true, m_layerId);
284#else //SVC_EXTENSION
285    rpcPic->create ( sps, pps, true);
286#endif //SVC_EXTENSION
287   
288    m_cListPic.pushBack( rpcPic );
289
290    return;
291  }
292
293  Bool bBufferIsAvailable = false;
294  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
295  while (iterPic != m_cListPic.end())
296  {
297    rpcPic = *(iterPic++);
298    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
299    {
300      rpcPic->setOutputMark(false);
301      bBufferIsAvailable = true;
302      break;
303    }
304
305    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
306    {
307#if !SVC_EXTENSION
308      rpcPic->setOutputMark(false);
309#endif
310      rpcPic->setReconMark( false );
311      rpcPic->getPicYuvRec()->setBorderExtension( false );
312      bBufferIsAvailable = true;
313      break;
314    }
315  }
316
317  if ( !bBufferIsAvailable )
318  {
319    //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer.
320    m_iMaxRefPicNum++;
321    rpcPic = new TComPic();
322    m_cListPic.pushBack( rpcPic );
323  }
324  rpcPic->destroy();
325
326#if SVC_EXTENSION
327  if( m_layerId > 0 )
328  {
329    xSetSpatialEnhLayerFlag( vps, sps, pps, rpcPic );
330  }
331
332  rpcPic->create( vps, sps, pps, true, m_layerId);
333#else  //SVC_EXTENSION
334  rpcPic->create ( sps, pps, true);
335#endif //SVC_EXTENSION
336}
337
338Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic)
339{
340  if (!m_pcPic)
341  {
342    /* nothing to deblock */
343    return;
344  }
345
346  TComPic*   pcPic         = m_pcPic;
347
348  // Execute Deblock + Cleanup
349
350  m_cGopDecoder.filterPicture(pcPic);
351
352#if SVC_EXTENSION
353  if( this->getLayerDec(pcPic->getLayerId())->m_isOutputLayerFlag == false )
354  {
355    pcPic->setOutputMark( false );
356  }
357#endif
358
359  TComSlice::sortPicList( m_cListPic ); // sorting for application output
360  poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
361  rpcListPic          = &m_cListPic;
362  m_cCuDecoder.destroy();
363  m_bFirstSliceInPicture  = true;
364
365  return;
366}
367
368Void TDecTop::checkNoOutputPriorPics (TComList<TComPic*>* pcListPic)
369{
370  if (!pcListPic || !m_isNoOutputPriorPics)
371  {
372    return;
373  }
374
375  TComList<TComPic*>::iterator  iterPic   = pcListPic->begin();
376
377  while (iterPic != pcListPic->end())
378  {
379    TComPic* pcPicTmp = *(iterPic++);
380    if (m_lastPOCNoOutputPriorPics != pcPicTmp->getPOC())
381    {
382      pcPicTmp->setOutputMark(false);
383    }
384  }
385}
386
387Void TDecTop::xCreateLostPicture(Int iLostPoc)
388{
389  printf("\ninserting lost poc : %d\n",iLostPoc);
390  TComPic *cFillPic;
391#if SVC_EXTENSION
392  xGetNewPicBuffer(*(m_parameterSetManager.getFirstVPS()), *(m_parameterSetManager.getFirstSPS()), *(m_parameterSetManager.getFirstPPS()), cFillPic, 0);
393  cFillPic->getSlice(0)->initSlice( m_layerId );
394#else
395  xGetNewPicBuffer(*(m_parameterSetManager.getFirstSPS()), *(m_parameterSetManager.getFirstPPS()), cFillPic, 0);
396  cFillPic->getSlice(0)->initSlice();
397#endif
398 
399  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
400  Int closestPoc = 1000000;
401  while ( iterPic != m_cListPic.end())
402  {
403    TComPic * rpcPic = *(iterPic++);
404    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())
405    {
406      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
407    }
408  }
409  iterPic = m_cListPic.begin();
410  while ( iterPic != m_cListPic.end())
411  {
412    TComPic *rpcPic = *(iterPic++);
413    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
414    {
415      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
416      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
417      break;
418    }
419  }
420  cFillPic->setCurrSliceIdx(0);
421  for(Int ctuRsAddr=0; ctuRsAddr<cFillPic->getNumberOfCtusInFrame(); ctuRsAddr++)
422  {
423    cFillPic->getCtu(ctuRsAddr)->initCtu(cFillPic, ctuRsAddr);
424  }
425  cFillPic->getSlice(0)->setReferenced(true);
426  cFillPic->getSlice(0)->setPOC(iLostPoc);
427  xUpdatePreviousTid0POC(cFillPic->getSlice(0));
428  cFillPic->setReconMark(true);
429  cFillPic->setOutputMark(true);
430  if(m_pocRandomAccess == MAX_INT)
431  {
432    m_pocRandomAccess = iLostPoc;
433  }
434}
435
436
437Void TDecTop::xActivateParameterSets()
438{
439  if (m_bFirstSliceInPicture)
440  {
441    const TComPPS *pps = m_parameterSetManager.getPPS(m_apcSlicePilot->getPPSId()); // this is a temporary PPS object. Do not store this value
442    assert (pps != 0);
443
444#if SVC_EXTENSION
445    TComSPS *updateSPS = m_parameterSetManager.getSPS(pps->getSPSId());             // this is a temporary SPS object. Do not store this value
446#endif
447    const TComSPS *sps = m_parameterSetManager.getSPS(pps->getSPSId());             // this is a temporary SPS object. Do not store this value
448    assert (sps != 0);
449
450    m_parameterSetManager.clearSPSChangedFlag(sps->getSPSId());
451    m_parameterSetManager.clearPPSChangedFlag(pps->getPPSId());
452
453    if (false == m_parameterSetManager.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
454    {
455      printf ("Parameter set activation failed!");
456      assert (0);
457    }
458
459    xParsePrefixSEImessages();
460
461#if RExt__HIGH_BIT_DEPTH_SUPPORT==0
462    if (sps->getSpsRangeExtension().getExtendedPrecisionProcessingFlag() || sps->getBitDepth(CHANNEL_TYPE_LUMA)>12 || sps->getBitDepth(CHANNEL_TYPE_CHROMA)>12 )
463    {
464      printf("High bit depth support must be enabled at compile-time in order to decode this bitstream\n");
465      assert (0);
466      exit(1);
467    }
468#endif
469
470#if SVC_EXTENSION
471    // scaling list settings and checks
472    TComVPS *vps = m_parameterSetManager.getVPS(sps->getVPSId());
473    assert (vps != 0);
474
475    m_parameterSetManager.clearVPSChangedFlag(sps->getVPSId());   
476
477    if( sps->getInferScalingListFlag() )
478    {
479      UInt refLayerId = sps->getScalingListRefLayerId();
480      const TComSPS *refSps = m_ppcTDecTop[refLayerId]->getParameterSetManager()->getActiveSPS(); assert( refSps != NULL );
481
482      // 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
483      if( vps->getNonHEVCBaseLayerFlag() )
484      {
485        assert( refLayerId > 0 );
486      }
487
488      // 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
489      // 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
490      assert( refSps->getInferScalingListFlag() == false );
491
492      // 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,
493      // 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
494      assert( vps->getRecursiveRefLayerFlag( sps->getLayerId(), refLayerId ) == true );
495    }
496
497    if( pps->getInferScalingListFlag() )
498    {
499      UInt refLayerId = pps->getScalingListRefLayerId();
500      const TComPPS *refPps = m_ppcTDecTop[refLayerId]->getParameterSetManager()->getActivePPS(); assert( refPps != NULL );
501
502      // 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
503      if( vps->getNonHEVCBaseLayerFlag() )
504      {
505        assert( refLayerId > 0 );
506      }
507
508      // 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
509      // 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
510      assert( refPps->getInferScalingListFlag() == false );
511
512      // 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,
513      // 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
514      assert( vps->getRecursiveRefLayerFlag( pps->getLayerId(), refLayerId ) == true );
515    }
516
517#if AVC_BASE
518    if( vps->getNonHEVCBaseLayerFlag() )
519    {
520      TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
521      if( m_layerId > 0 && pBLPic->getPicYuvRec() == NULL )
522      {
523        UInt refLayerId = 0;
524
525        pBLPic->create( *vps, *sps, *pps, true, refLayerId);
526
527        // it is needed where the VPS is accessed through the slice
528        pBLPic->getSlice(0)->setVPS( vps );
529      }
530    }
531#endif
532
533    if( m_layerId > 0 )
534    {
535      // When not present sps_max_sub_layers_minus1 is inferred to be equal to vps_max_sub_layers_minus1.
536      updateSPS->setMaxTLayers( vps->getMaxTLayers() );
537
538      // When not present sps_temporal_id_nesting_flag is inferred to be equal to vps_temporal_id_nesting_flag
539      updateSPS->setTemporalIdNestingFlag( (sps->getMaxTLayers() > 1) ? vps->getTemporalNestingFlag() : true );
540
541      // 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,
542      // 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.
543      for(UInt i=0; i < sps->getMaxTLayers(); i++)
544      {
545        // to avoid compiler warning "array subscript is above array bounds"
546        assert( i < MAX_TLAYER );
547
548        // 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,
549        // due to MultiLayerExtSpsFlag being equal to 1, for a layer that refers to the SPS and has nuh_layer_id equal to currLayerId,
550        // the value of sps_max_dec_pic_buffering_minus1[ i ] is inferred to be equal to max_vps_dec_pic_buffering_minus1[ TargetOlsIdx ][ layerIdx ][ i ] of the active VPS,
551        // where layerIdx is equal to the value such that LayerSetLayerIdList[ TargetDecLayerSetIdx ][ layerIdx ] is equal to currLayerId.
552        if( sps->getMultiLayerExtSpsFlag() )
553        {
554          updateSPS->setMaxDecPicBuffering( vps->getMaxVpsDecPicBufferingMinus1( m_commonDecoderParams->getTargetOutputLayerSetIdx(), vps->getLayerIdcForOls( vps->getOutputLayerSetIdx( m_commonDecoderParams->getTargetOutputLayerSetIdx() ), m_layerId ), i) + 1, i);
555        }
556
557        // The value of sps_max_dec_pic_buffering_minus1[ i ] shall be less than or equal to vps_max_dec_pic_buffering_minus1[ i ] for each value of i.
558        assert( sps->getMaxDecPicBuffering(i) <= vps->getMaxDecPicBuffering(i) );     
559      }
560
561      UInt layerIdx = vps->getLayerIdxInVps( m_layerId );
562
563      if( vps->getBaseLayerPSCompatibilityFlag(layerIdx) )
564      {
565        const RepFormat* repFormat = vps->getVpsRepFormat(vps->getVpsRepFormatIdx(layerIdx));
566
567        assert( pps->getLayerId() == 0 );
568        assert( sps->getLayerId() == 0 );
569        assert( repFormat->getChromaFormatVpsIdc() == sps->getChromaFormatIdc() );
570        assert( repFormat->getSeparateColourPlaneVpsFlag() == 0 );
571        assert( repFormat->getPicHeightVpsInLumaSamples() == sps->getPicHeightInLumaSamples() );
572        assert( repFormat->getPicWidthVpsInLumaSamples()  == sps->getPicWidthInLumaSamples() );
573        assert( repFormat->getBitDepthVpsLuma()   == sps->getBitDepth(CHANNEL_TYPE_LUMA) );
574        assert( repFormat->getBitDepthVpsChroma() == sps->getBitDepth(CHANNEL_TYPE_CHROMA) );
575        assert( repFormat->getConformanceWindowVps().getWindowLeftOffset()   == sps->getConformanceWindow().getWindowLeftOffset() );
576        assert( repFormat->getConformanceWindowVps().getWindowRightOffset()  == sps->getConformanceWindow().getWindowRightOffset() );
577        assert( repFormat->getConformanceWindowVps().getWindowTopOffset()    == sps->getConformanceWindow().getWindowTopOffset() );
578        assert( repFormat->getConformanceWindowVps().getWindowBottomOffset() == sps->getConformanceWindow().getWindowBottomOffset() );
579      }   
580    }
581
582    //Conformance checking for rep format -- rep format of current picture of current layer shall never be greater rep format defined in VPS for the current layer
583    UInt layerIdx = vps->getLayerIdxInVps(m_apcSlicePilot->getLayerId());
584
585    if ( vps->getVpsExtensionFlag() == 1 && (m_apcSlicePilot->getLayerId() == 0 || sps->getV1CompatibleSPSFlag() == 1) )
586    {
587      assert( sps->getPicWidthInLumaSamples()        <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx) )->getPicWidthVpsInLumaSamples() );
588      assert( sps->getPicHeightInLumaSamples()       <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx) )->getPicHeightVpsInLumaSamples() );
589      assert( sps->getChromaFormatIdc()              <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx) )->getChromaFormatVpsIdc() );
590      assert( sps->getBitDepth(CHANNEL_TYPE_LUMA)    <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx) )->getBitDepthVpsLuma() );
591      assert( sps->getBitDepth(CHANNEL_TYPE_CHROMA)  <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx) )->getBitDepthVpsChroma() );
592    }
593    else if ( vps->getVpsExtensionFlag() == 1 )
594    {
595      assert( vps->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(layerIdx))->getPicWidthVpsInLumaSamples()  <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx))->getPicWidthVpsInLumaSamples());
596      assert( vps->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(layerIdx))->getPicHeightVpsInLumaSamples() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx))->getPicHeightVpsInLumaSamples());
597      assert( vps->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(layerIdx))->getChromaFormatVpsIdc()        <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx))->getChromaFormatVpsIdc());
598      assert( vps->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(layerIdx))->getBitDepthVpsLuma()           <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx))->getBitDepthVpsLuma());
599      assert( vps->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(layerIdx))->getBitDepthVpsChroma()         <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx))->getBitDepthVpsChroma());
600    }
601#endif //SVC_EXTENSION
602
603    // NOTE: globals were set up here originally. You can now use:
604    // g_uiMaxCUDepth = sps->getMaxTotalCUDepth();
605    // g_uiAddCUDepth = sps->getMaxTotalCUDepth() - sps->getLog2DiffMaxMinCodingBlockSize()
606
607    //  Get a new picture buffer. This will also set up m_pcPic, and therefore give us a SPS and PPS pointer that we can use.
608#if SVC_EXTENSION
609    xGetNewPicBuffer( *(vps), *(sps), *(pps), m_pcPic, m_apcSlicePilot->getTLayer() );
610#else
611    xGetNewPicBuffer (*(sps), *(pps), m_pcPic, m_apcSlicePilot->getTLayer());
612#endif
613
614#if ALIGNED_BUMPING
615    m_apcSlicePilot->checkLeadingPictureRestrictions(m_cListPic);
616#else
617    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
618#endif
619
620    // make the slice-pilot a real slice, and set up the slice-pilot for the next slice
621    assert(m_pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
622    m_apcSlicePilot = m_pcPic->getPicSym()->swapSliceObject(m_apcSlicePilot, m_uiSliceIdx);
623
624    // we now have a real slice:
625    TComSlice *pSlice = m_pcPic->getSlice(m_uiSliceIdx);
626
627    // Update the PPS and SPS pointers with the ones of the picture.
628    pps=pSlice->getPPS();
629    sps=pSlice->getSPS();
630
631    // Initialise the various objects for the new set of settings
632#if SVC_EXTENSION
633    m_cSAO.create( pSlice->getPicWidthInLumaSamples(), pSlice->getPicHeightInLumaSamples(), pSlice->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxTotalCUDepth(), pps->getPpsRangeExtension().getLog2SaoOffsetScale(CHANNEL_TYPE_LUMA), pps->getPpsRangeExtension().getLog2SaoOffsetScale(CHANNEL_TYPE_CHROMA) );
634#else
635    m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxTotalCUDepth(), pps->getPpsRangeExtension().getLog2SaoOffsetScale(CHANNEL_TYPE_LUMA), pps->getPpsRangeExtension().getLog2SaoOffsetScale(CHANNEL_TYPE_CHROMA) );
636#endif
637    m_cLoopFilter.create( sps->getMaxTotalCUDepth() );
638    m_cPrediction.initTempBuff(sps->getChromaFormatIdc());
639
640
641    Bool isField = false;
642    Bool isTopField = false;
643
644    if(!m_SEIs.empty())
645    {
646      // Check if any new Picture Timing SEI has arrived
647      SEIMessages pictureTimingSEIs = getSeisByType(m_SEIs, SEI::PICTURE_TIMING);
648      if (pictureTimingSEIs.size()>0)
649      {
650        SEIPictureTiming* pictureTiming = (SEIPictureTiming*) *(pictureTimingSEIs.begin());
651        isField    = (pictureTiming->m_picStruct == 1) || (pictureTiming->m_picStruct == 2) || (pictureTiming->m_picStruct == 9) || (pictureTiming->m_picStruct == 10) || (pictureTiming->m_picStruct == 11) || (pictureTiming->m_picStruct == 12);
652        isTopField = (pictureTiming->m_picStruct == 1) || (pictureTiming->m_picStruct == 9) || (pictureTiming->m_picStruct == 11);
653      }
654     
655#if Q0189_TMVP_CONSTRAINTS
656      // Check if any new temporal motion vector prediction constraints SEI has arrived
657      SEIMessages seiTMVPConstrainsList = extractSeisByType (m_SEIs, SEI::TMVP_CONSTRAINTS);
658      if (seiTMVPConstrainsList.size() > 0)
659      {
660        assert ( m_pcPic->getTLayer() == 0 );  //this SEI can present only for AU with Tid equal to 0
661        SEITMVPConstrains* tmvpConstraintSEI = (SEITMVPConstrains*) *(seiTMVPConstrainsList.begin());
662        if ( tmvpConstraintSEI->prev_pics_not_used_flag == 1 )
663        {
664          //update all pics in the DPB such that they cannot be used for TMPV ref
665          TComList<TComPic*>::iterator  iterRefPic = m_cListPic.begin(); 
666          while( iterRefPic != m_cListPic.end() )
667          {
668            TComPic *refPic = *iterRefPic;
669            if( ( refPic->getLayerId() == m_pcPic->getLayerId() ) && refPic->getReconMark() )
670            {
671              for(Int i = refPic->getNumAllocatedSlice()-1; i >= 0; i--)
672              {
673                TComSlice *refSlice = refPic->getSlice(i);
674                refSlice->setAvailableForTMVPRefFlag( false );
675              }
676            }
677            iterRefPic++;
678          }
679        }
680      }
681#endif
682    }
683
684    //Set Field/Frame coding mode
685    m_pcPic->setField(isField);
686    m_pcPic->setTopField(isTopField);
687
688    // transfer any SEI messages that have been received to the picture
689    m_pcPic->setSEIs(m_SEIs);
690    m_SEIs.clear();
691
692    // Recursive structure
693#if SVC_EXTENSION
694    m_cCuDecoder.create ( sps->getMaxTotalCUDepth(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), pSlice->getChromaFormatIdc() );
695    m_cCuDecoder.init   ( m_ppcTDecTop, &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction, m_layerId );
696#else
697    m_cCuDecoder.create ( sps->getMaxTotalCUDepth(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getChromaFormatIdc() );
698    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
699#endif
700    m_cTrQuant.init     ( sps->getMaxTrSize() );
701
702    m_cSliceDecoder.create();
703  }
704  else
705  {
706    // make the slice-pilot a real slice, and set up the slice-pilot for the next slice
707    m_pcPic->allocateNewSlice();
708    assert(m_pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
709    m_apcSlicePilot = m_pcPic->getPicSym()->swapSliceObject(m_apcSlicePilot, m_uiSliceIdx);
710
711    TComSlice *pSlice = m_pcPic->getSlice(m_uiSliceIdx); // we now have a real slice.
712
713    const TComSPS *sps = pSlice->getSPS();
714    const TComPPS *pps = pSlice->getPPS();
715
716    // check that the current active PPS has not changed...
717    if (m_parameterSetManager.getSPSChangedFlag(sps->getSPSId()) )
718    {
719      printf("Error - a new SPS has been decoded while processing a picture\n");
720      exit(1);
721    }
722    if (m_parameterSetManager.getPPSChangedFlag(pps->getPPSId()) )
723    {
724      printf("Error - a new PPS has been decoded while processing a picture\n");
725      exit(1);
726    }
727
728    xParsePrefixSEImessages();
729
730    // Check if any new SEI has arrived
731     if(!m_SEIs.empty())
732     {
733       // Currently only decoding Unit SEI message occurring between VCL NALUs copied
734       SEIMessages &picSEI = m_pcPic->getSEIs();
735       SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
736       picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
737       deleteSEIs(m_SEIs);
738     }
739  }
740}
741
742
743Void TDecTop::xParsePrefixSEIsForUnknownVCLNal()
744{
745  while (!m_prefixSEINALUs.empty())
746  {
747    // do nothing?
748    printf("Discarding Prefix SEI associated with unknown VCL NAL unit.\n");
749    delete m_prefixSEINALUs.front();
750  }
751  // TODO: discard following suffix SEIs as well?
752}
753
754
755Void TDecTop::xParsePrefixSEImessages()
756{
757#if SVC_EXTENSION
758    if (m_prevSliceSkipped) // No need to decode SEI messages of a skipped access unit
759    {
760      return;
761    }
762#endif
763
764  while (!m_prefixSEINALUs.empty())
765  {
766    InputNALUnit &nalu=*m_prefixSEINALUs.front();
767#if LAYERS_NOT_PRESENT_SEI
768    m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_SEIs, nalu.m_nalUnitType, m_parameterSetManager.getActiveVPS(), m_parameterSetManager.getActiveSPS(), m_pDecodedSEIOutputStream );
769#else
770    m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_SEIs, nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS(), m_pDecodedSEIOutputStream );
771#endif
772    delete m_prefixSEINALUs.front();
773    m_prefixSEINALUs.pop_front();
774  }
775}
776
777#if SVC_EXTENSION
778Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC )
779#else
780Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
781#endif
782{
783#if SVC_EXTENSION
784  m_apcSlicePilot->initSlice( nalu.m_nuhLayerId );
785  m_apcSlicePilot->setTLayer( nalu.m_temporalId );
786#else //SVC_EXTENSION
787  m_apcSlicePilot->initSlice(); // the slice pilot is an object to prepare for a new slice
788                                // it is not associated with picture, sps or pps structures.
789#endif
790
791  if (m_bFirstSliceInPicture)
792  {
793    m_uiSliceIdx = 0;
794  }
795  else
796  {
797    m_apcSlicePilot->copySliceInfo( m_pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
798  }
799  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
800
801  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
802
803  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
804                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
805                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
806                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
807                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
808  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
809  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
810  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
811
812#if ENC_DEC_TRACE
813  const UInt64 originalSymbolCount = g_nSymbolCounter;
814#endif
815
816  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManager, m_prevTid0POC);
817
818#if SVC_EXTENSION
819  const TComPPS *pps = m_parameterSetManager.getPPS(m_apcSlicePilot->getPPSId());
820  assert (pps != 0);
821  const TComSPS *sps = m_parameterSetManager.getSPS(pps->getSPSId());
822  assert (sps != 0);
823  const TComVPS *vps = m_parameterSetManager.getVPS(sps->getVPSId());
824  assert (vps != 0);
825
826  // Following check should go wherever the VPS is activated
827  if( !vps->getBaseLayerAvailableFlag() )
828  {
829    assert( nalu.m_nuhLayerId != 0 );
830    assert( vps->getNumAddLayerSets() > 0 );
831
832    if( m_commonDecoderParams->getTargetOutputLayerSetIdx() >= 0 )
833    {
834      UInt layerIdx = vps->getOutputLayerSetIdx( getCommonDecoderParams()->getTargetOutputLayerSetIdx() );
835      assert( layerIdx > vps->getVpsNumLayerSetsMinus1() );
836    }
837  } 
838
839  setRefLayerParams(vps);
840  m_apcSlicePilot->setNumMotionPredRefLayers(m_numMotionPredRefLayers);
841#endif
842
843  // set POC for dependent slices in skipped pictures
844  if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped)
845  {
846    m_apcSlicePilot->setPOC(m_skippedPOC);
847  }
848
849  xUpdatePreviousTid0POC(m_apcSlicePilot);
850
851  m_apcSlicePilot->setAssociatedIRAPPOC(m_pocCRA);
852  m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType);
853
854  //For inference of NoOutputOfPriorPicsFlag
855  if (m_apcSlicePilot->getRapPicFlag())
856  {
857    if ((m_apcSlicePilot->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_apcSlicePilot->getNalUnitType() <= NAL_UNIT_CODED_SLICE_IDR_N_LP) || 
858        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_bFirstSliceInSequence) ||
859        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getHandleCraAsBlaFlag()))
860    {
861      m_apcSlicePilot->setNoRaslOutputFlag(true);
862    }
863    //the inference for NoOutputPriorPicsFlag
864    if (!m_bFirstSliceInBitstream && m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag())
865    {
866      if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
867      {
868        m_apcSlicePilot->setNoOutputPriorPicsFlag(true);
869      }
870    }
871    else
872    {
873      m_apcSlicePilot->setNoOutputPriorPicsFlag(false);
874    }
875
876    if(m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
877    {
878      m_craNoRaslOutputFlag = m_apcSlicePilot->getNoRaslOutputFlag();
879    }
880  }
881  if (m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoOutputPriorPicsFlag())
882  {
883    m_lastPOCNoOutputPriorPics = m_apcSlicePilot->getPOC();
884    m_isNoOutputPriorPics = true;
885  }
886  else
887  {
888    m_isNoOutputPriorPics = false;
889  }
890
891  //For inference of PicOutputFlag
892  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R)
893  {
894    if ( m_craNoRaslOutputFlag )
895    {
896      m_apcSlicePilot->setPicOutputFlag(false);
897    }
898  }
899
900  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_craNoRaslOutputFlag) //Reset POC MSB when CRA has NoRaslOutputFlag equal to 1
901  {
902#if !SVC_EXTENSION
903    TComPPS *pps = m_parameterSetManager.getPPS(m_apcSlicePilot->getPPSId());
904    assert (pps != 0);
905    TComSPS *sps = m_parameterSetManager.getSPS(pps->getSPSId());
906    assert (sps != 0);
907#endif
908    Int iMaxPOClsb = 1 << sps->getBitsForPOC();
909    m_apcSlicePilot->setPOC( m_apcSlicePilot->getPOC() & (iMaxPOClsb - 1) );
910    xUpdatePreviousTid0POC(m_apcSlicePilot);
911  }
912
913  // Skip pictures due to random access
914
915  if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
916  {
917    m_prevSliceSkipped = true;
918    m_skippedPOC = m_apcSlicePilot->getPOC();
919    return false;
920  }
921  // Skip TFD pictures associated with BLA/BLANT pictures
922  if (isSkipPictureForBLA(iPOCLastDisplay))
923  {
924    m_prevSliceSkipped = true;
925    m_skippedPOC = m_apcSlicePilot->getPOC();
926    return false;
927  }
928
929  // clear previous slice skipped flag
930  m_prevSliceSkipped = false;
931
932  // exit when a new picture is found
933#if SVC_EXTENSION
934  bNewPOC = m_apcSlicePilot->getPOC() != m_prevPOC || ( m_apcSlicePilot->getFirstSliceInPic() && m_parseIdc == -1 );
935
936#if NO_CLRAS_OUTPUT_FLAG
937  if( m_layerId == m_smallestLayerId && m_apcSlicePilot->getRapPicFlag() )
938  {
939    if( m_bFirstSliceInSequence )
940    {
941      setNoClrasOutputFlag(true);
942    }
943    else if( m_lastPicHasEos )
944    {
945      setNoClrasOutputFlag(true);
946    }
947    else if( m_apcSlicePilot->getBlaPicFlag() )
948    {
949      setNoClrasOutputFlag(true);
950    }
951    else if( m_apcSlicePilot->getIdrPicFlag() && m_apcSlicePilot->getCrossLayerBLAFlag() )
952    {
953      setNoClrasOutputFlag(true);
954    }
955    else
956    {
957      setNoClrasOutputFlag(false);
958    }     
959  }
960  else
961  {
962    setNoClrasOutputFlag(false);
963  }
964
965  m_apcSlicePilot->decodingRefreshMarking( m_cListPic, m_noClrasOutputFlag, m_smallestLayerId );
966#endif
967
968  // Derive the value of NoOutputOfPriorPicsFlag
969  if( bNewPOC || m_layerId!=m_uiPrevLayerId )   // i.e. new coded picture
970  {
971    if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getNoRaslOutputFlag() )
972    {
973      this->setNoOutputPriorPicsFlag( true );
974    }
975    else if( m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag() )
976    {
977      this->setNoOutputPriorPicsFlag( m_apcSlicePilot->getNoOutputPriorPicsFlag() );
978    }
979    else
980    {
981      if( this->m_ppcTDecTop[0]->getNoClrasOutputFlag() )
982      {
983        this->setNoOutputPriorPicsFlag( true );
984      }
985    }
986  }
987
988#if SVC_POC
989  if( m_parseIdc != -1 ) // Second pass for a POC resetting picture
990  {
991    m_parseIdc++; // Proceed to POC decoding and RPS derivation
992  }
993 
994  if( m_parseIdc == 2 )
995  {
996    bNewPOC = false;
997  }
998
999  if( (bNewPOC || m_layerId!=m_uiPrevLayerId) && (m_parseIdc == -1) ) // Will be true at the first pass
1000  {
1001  //if (bNewPOC || m_layerId!=m_uiPrevLayerId)
1002  // Check if new reset period has started - this is needed just so that the SHM decoder which calls slice header decoding twice
1003  // does not invoke the output twice
1004  //if( m_lastPocPeriodId[m_apcSlicePilot->getLayerId()] == m_apcSlicePilot->getPocResetPeriodId() )
1005    // Update CurrAU marking
1006    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
1007    {
1008      // New access unit; reset all variables related to POC reset restrictions
1009      resetPocRestrictionCheckParameters();
1010
1011      markAllPicsAsNoCurrAu(vps);
1012
1013      for( UInt i = 0; i < MAX_LAYERS; i++ )
1014      {
1015        m_ppcTDecTop[vps->getLayerIdInNuh(i)]->m_pocDecrementedInDPBFlag = false;
1016      }
1017    }
1018
1019    m_pocResettingFlag = false;
1020
1021    if( m_apcSlicePilot->getPocResetIdc() != 0 )
1022    {
1023      if( vps->getVpsPocLsbAlignedFlag() )
1024      {
1025        m_pocResettingFlag = true;
1026      }
1027      else if (m_pocDecrementedInDPBFlag)
1028      {
1029        m_pocResettingFlag = false;
1030      }
1031      else
1032      {
1033        m_pocResettingFlag = true;
1034      }
1035    }
1036
1037    if( m_apcSlicePilot->getPocResetIdc() && m_apcSlicePilot->getSliceIdx() == 0 )
1038    {
1039      Int pocResetPeriodId = m_apcSlicePilot->getPocResetPeriodId();
1040      if ( m_apcSlicePilot->getPocResetIdc() == 1 || m_apcSlicePilot->getPocResetIdc() == 2 ||
1041        ( m_apcSlicePilot->getPocResetIdc() == 3 && pocResetPeriodId != getLastPocPeriodId() ) )
1042      {
1043        setLastPocPeriodId(pocResetPeriodId);
1044        m_parseIdc = 0;
1045      }
1046
1047      // Check if the POC Reset period ID matches with the Reset Period ID
1048      if( pocResetPeriodId == m_crossLayerPocResetPeriodId )
1049      {
1050        // If matching, and current poc_reset_idc = 3, then the values should match
1051        if( m_apcSlicePilot->getPocResetIdc() == 3 )
1052        {
1053          assert( ( m_apcSlicePilot->getFullPocResetFlag() == false && m_crossLayerPocResetIdc == 1 ) ||
1054                  ( m_apcSlicePilot->getFullPocResetFlag() == true  && m_crossLayerPocResetIdc == 2 ) );
1055        }
1056      }
1057      else
1058      {
1059        // This is the first picture of a POC resetting access unit
1060        m_crossLayerPocResetPeriodId = pocResetPeriodId;
1061        if( m_apcSlicePilot->getPocResetIdc() == 1 || m_apcSlicePilot->getPocResetIdc() == 2 )
1062        {
1063          m_crossLayerPocResetIdc = m_apcSlicePilot->getPocResetIdc();
1064        }
1065        else
1066        { // poc_reset_idc = 3
1067          // In this case, the entire POC resetting access unit has been lost.
1068          // Need more checking to ensure poc_reset_idc = 3 works.
1069          assert ( 0 );
1070        }
1071      }
1072    }
1073    else
1074    {
1075      m_parseIdc = 3; // Proceed to decoding POC and RPS
1076    }
1077  }
1078#endif
1079
1080#if ALIGNED_BUMPING
1081  UInt affectedLayerList[MAX_LAYERS];
1082  Int  numAffectedLayers;
1083
1084  affectedLayerList[0] = m_apcSlicePilot->getLayerId();
1085  numAffectedLayers = 1;
1086
1087  if( vps->getVpsPocLsbAlignedFlag() )
1088  {
1089    for( UInt j = 0; j < vps->getNumPredictedLayers(m_apcSlicePilot->getLayerId()); j++ )
1090    {
1091      affectedLayerList[j + 1] = vps->getPredictedLayerId(m_apcSlicePilot->getLayerId(), j);
1092    }
1093    numAffectedLayers = vps->getNumPredictedLayers(m_apcSlicePilot->getLayerId()) + 1;
1094  }
1095
1096  if( m_parseIdc == 1 && m_pocResettingFlag )
1097  {
1098    // Invoke output of pictures if the current picture is a POC reset picture
1099    bNewPOC = true;
1100    /* Include reset of all POCs in the layer */
1101
1102    // This operation would do the following:
1103    // 1. Update the other picture in the DPB. This should be done only for the first slice of the picture.
1104    // 2. Update the value of m_pocCRA.
1105    // 3. Reset the POC values at the decoder for the current picture to be zero - will be done later
1106    // 4. update value of POCLastDisplay
1107
1108    //Do the reset stuff here
1109    Int maxPocLsb = 1 << sps->getBitsForPOC();
1110    Int pocLsbVal;
1111    if( m_apcSlicePilot->getPocResetIdc() == 3 )
1112    {
1113      pocLsbVal = m_apcSlicePilot->getPocLsbVal() ;
1114    }
1115    else
1116    {
1117      pocLsbVal = (m_apcSlicePilot->getPOC() % maxPocLsb);
1118    }
1119
1120    Int pocMsbDelta = 0;
1121    if( m_apcSlicePilot->getPocMsbValPresentFlag() ) 
1122    {
1123      pocMsbDelta = m_apcSlicePilot->getPocMsbVal() * maxPocLsb;
1124    }
1125    else
1126    {
1127      //This MSB derivation can be made into one function. Item to do next.
1128      Int prevPoc     = this->getPrevPicOrderCnt();
1129      Int prevPocLsb  = prevPoc & (maxPocLsb - 1);
1130      Int prevPocMsb  = prevPoc - prevPocLsb;
1131
1132      pocMsbDelta = m_apcSlicePilot->getCurrMsb( pocLsbVal, prevPocLsb, prevPocMsb, maxPocLsb );
1133    }
1134
1135    Int pocLsbDelta;
1136    if( m_apcSlicePilot->getPocResetIdc() == 2 ||  ( m_apcSlicePilot->getPocResetIdc() == 3 && m_apcSlicePilot->getFullPocResetFlag() ))
1137    {
1138      pocLsbDelta = pocLsbVal;
1139    }
1140    else
1141    {
1142      pocLsbDelta = 0; 
1143    }
1144
1145    Int deltaPocVal  =  pocMsbDelta + pocLsbDelta;
1146
1147    for( UInt layerIdx = 0; layerIdx < numAffectedLayers; layerIdx++ )
1148    {
1149      if (!m_ppcTDecTop[affectedLayerList[layerIdx]]->m_pocDecrementedInDPBFlag)
1150      {
1151        m_ppcTDecTop[affectedLayerList[layerIdx]]->m_pocDecrementedInDPBFlag = true;
1152        TComList<TComPic*>::iterator  iterPic = m_ppcTDecTop[affectedLayerList[layerIdx]]->getListPic()->begin();
1153
1154        while (iterPic != m_ppcTDecTop[affectedLayerList[layerIdx]]->getListPic()->end())
1155        {
1156          TComPic *dpbPic = *iterPic;
1157          // Check if the picture pointed to by iterPic is either used for reference or
1158          // needed for output, are in the same layer, and not the current picture.
1159          assert(dpbPic->getLayerId() == affectedLayerList[layerIdx]);
1160
1161          if( (dpbPic->getReconMark()) && (dpbPic->getPicSym()->getSlice(0)->getPicOutputFlag()) )
1162          {
1163            for(Int i = dpbPic->getNumAllocatedSlice()-1; i >= 0; i--)
1164            {
1165
1166              TComSlice *slice = dpbPic->getSlice(i);
1167              TComReferencePictureSet *rps = slice->getRPS();
1168              slice->setPOC( slice->getPOC() - deltaPocVal );
1169
1170              // Also adjust the POC value stored in the RPS of each such slice
1171              for(Int j = rps->getNumberOfPictures(); j >= 0; j--)
1172              {
1173                rps->setPOC( j, rps->getPOC(j) - deltaPocVal );
1174              }
1175              // Also adjust the value of refPOC
1176              for(Int k = 0; k < 2; k++)  // For List 0 and List 1
1177              {
1178                RefPicList list = (k == 1) ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
1179                for(Int j = 0; j < slice->getNumRefIdx(list); j++)
1180                {
1181                  slice->setRefPOC( slice->getRefPOC(list, j) - deltaPocVal, list, j);
1182                }
1183              }
1184            }
1185          }
1186          iterPic++;
1187        }
1188        // Update the value of pocCRA
1189        m_ppcTDecTop[affectedLayerList[layerIdx]]->m_pocCRA -= deltaPocVal;
1190      }
1191    }
1192
1193    // Update value of POCLastDisplay
1194    iPOCLastDisplay -= deltaPocVal;
1195  }
1196  Int maxPocLsb = 1 << sps->getBitsForPOC();
1197  Int slicePicOrderCntLsb = m_apcSlicePilot->getPicOrderCntLsb();
1198
1199  if( m_pocResettingFlag && (m_parseIdc == 1 || m_parseIdc == 2) )
1200  {
1201    // Set poc for current slice
1202    if( m_apcSlicePilot->getPocResetIdc() == 1 )
1203    {       
1204      m_apcSlicePilot->setPOC( slicePicOrderCntLsb );
1205    }
1206    else if( m_apcSlicePilot->getPocResetIdc() == 2 )
1207    {
1208      m_apcSlicePilot->setPOC( 0 );
1209    }
1210    else 
1211    {
1212      Int picOrderCntMsb = m_apcSlicePilot->getCurrMsb( slicePicOrderCntLsb, m_apcSlicePilot->getFullPocResetFlag() ? 0 : m_apcSlicePilot->getPocLsbVal(), 0 , maxPocLsb );
1213      m_apcSlicePilot->setPOC( picOrderCntMsb + slicePicOrderCntLsb );
1214    }
1215  }
1216  else if (m_parseIdc == 3)
1217  {
1218    Int picOrderCntMsb = 0;
1219    if( m_apcSlicePilot->getPocMsbValPresentFlag() )
1220    {
1221      picOrderCntMsb = m_apcSlicePilot->getPocMsbVal() * maxPocLsb;
1222    }
1223    else if( m_apcSlicePilot->getIdrPicFlag() )
1224    {
1225      picOrderCntMsb = 0;
1226    }
1227    else
1228    {
1229      Int prevPicOrderCntLsb = this->getPrevPicOrderCnt() & ( maxPocLsb - 1);
1230      Int prevPicOrderCntMsb  = this->getPrevPicOrderCnt() - prevPicOrderCntLsb;
1231      picOrderCntMsb = m_apcSlicePilot->getCurrMsb(slicePicOrderCntLsb, prevPicOrderCntLsb, prevPicOrderCntMsb, maxPocLsb );
1232    }
1233    m_apcSlicePilot->setPOC( picOrderCntMsb + slicePicOrderCntLsb );
1234  }
1235
1236  if( m_parseIdc == 1 || m_parseIdc == 3)
1237  {
1238    // Adjust prevPicOrderCnt
1239    if(    !m_apcSlicePilot->getRaslPicFlag() 
1240      && !m_apcSlicePilot->getRadlPicFlag()
1241      && (m_apcSlicePilot->getNalUnitType() % 2 == 1)
1242      && ( nalu.m_temporalId == 0 )
1243      && !m_apcSlicePilot->getDiscardableFlag() )
1244    {
1245      for( UInt i = 0; i < numAffectedLayers; i++ )
1246      {
1247        m_ppcTDecTop[affectedLayerList[i]]->setPrevPicOrderCnt(m_apcSlicePilot->getPOC());
1248      }
1249    }
1250    else if( m_apcSlicePilot->getPocResetIdc() == 3 )
1251    {
1252      if( !m_firstPicInLayerDecodedFlag || (m_firstPicInLayerDecodedFlag && m_pocResettingFlag) )
1253      {
1254        for( UInt i = 0; i < numAffectedLayers; i++ )
1255        {
1256          m_ppcTDecTop[affectedLayerList[i]]->setPrevPicOrderCnt( m_apcSlicePilot->getFullPocResetFlag() ? 0 : m_apcSlicePilot->getPocLsbVal() );
1257        }
1258      }
1259    }
1260    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
1261  }
1262
1263  if( !m_apcSlicePilot->getDependentSliceSegmentFlag() && (bNewPOC || m_layerId!=m_uiPrevLayerId || m_parseIdc == 1) && !m_bFirstSliceInSequence )
1264#else
1265  if (!m_apcSlicePilot->getDependentSliceSegmentFlag() && (bNewPOC || m_layerId!=m_uiPrevLayerId) && !m_bFirstSliceInSequence )
1266#endif
1267  {
1268    m_prevPOC = m_apcSlicePilot->getPOC();
1269    curLayerId = m_uiPrevLayerId; 
1270    m_uiPrevLayerId = m_layerId;
1271    return true;
1272  }
1273
1274  m_parseIdc = -1;
1275
1276  if( m_apcSlicePilot->getTLayer() == 0 && m_apcSlicePilot->getEnableTMVPFlag() == 0 )
1277  {
1278    //update all pics in the DPB such that they cannot be used for TMPV ref
1279    TComList<TComPic*>::iterator  iterRefPic = m_cListPic.begin();
1280
1281    while( iterRefPic != m_cListPic.end() )
1282    {
1283      TComPic *refPic = *iterRefPic;
1284      if( ( refPic->getLayerId() == m_apcSlicePilot->getLayerId() ) && refPic->getReconMark() )
1285      {
1286        for( Int i = refPic->getNumAllocatedSlice()-1; i >= 0; i-- )
1287        {
1288
1289          TComSlice *refSlice = refPic->getSlice(i);
1290          refSlice->setAvailableForTMVPRefFlag( false );
1291        }
1292      }
1293      iterRefPic++;
1294    }
1295  }
1296  m_apcSlicePilot->setAvailableForTMVPRefFlag( true );
1297
1298  // Initialize ILRP if needed, only for the current layer 
1299  // ILRP intialization should go along with activation of parameters sets,
1300  // although activation of parameter sets itself need not be done for each and every slice!!!
1301  xInitILRP(m_apcSlicePilot);
1302
1303#else //SVC_EXTENSION
1304  //we should only get a different poc for a new picture (with CTU address==0)
1305  if (!m_apcSlicePilot->getDependentSliceSegmentFlag() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (m_apcSlicePilot->getSliceCurStartCtuTsAddr() != 0)) 
1306  {
1307    printf ("Warning, the first slice of a picture might have been lost!\n");
1308  }
1309
1310  // exit when a new picture is found
1311  if (!m_apcSlicePilot->getDependentSliceSegmentFlag() && (m_apcSlicePilot->getSliceCurStartCtuTsAddr() == 0 && !m_bFirstSliceInPicture) )
1312  {
1313    if (m_prevPOC >= m_pocRandomAccess)
1314    {
1315      m_prevPOC = m_apcSlicePilot->getPOC();
1316#if ENC_DEC_TRACE
1317      //rewind the trace counter since we didn't actually decode the slice
1318      g_nSymbolCounter = originalSymbolCount;
1319#endif
1320      return true;
1321    }
1322    m_prevPOC = m_apcSlicePilot->getPOC();
1323  }
1324#endif //SVC_EXTENSION
1325
1326  //detect lost reference picture and insert copy of earlier frame.
1327  {
1328    Int lostPoc;
1329    while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
1330    {
1331      xCreateLostPicture(lostPoc-1);
1332    }
1333  }
1334
1335  if (!m_apcSlicePilot->getDependentSliceSegmentFlag()) 
1336  {
1337    m_prevPOC = m_apcSlicePilot->getPOC();
1338#if SVC_EXTENSION
1339    curLayerId = m_layerId;
1340    m_uiPrevLayerId = m_layerId;
1341#endif
1342  }
1343
1344  // actual decoding starts here
1345  xActivateParameterSets();
1346
1347  m_bFirstSliceInSequence = false;
1348  m_bFirstSliceInBitstream  = false;
1349
1350  TComSlice* pcSlice = m_pcPic->getPicSym()->getSlice(m_uiSliceIdx);
1351
1352#if SVC_EXTENSION
1353  if (m_bFirstSliceInPicture)
1354  {
1355#if AVC_BASE
1356    if( m_layerId > 0 && vps->getNonHEVCBaseLayerFlag() )
1357    {
1358      TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
1359      pBLPic->getSlice(0)->setReferenced(true);
1360      fstream* pFile  = m_ppcTDecTop[0]->getBLReconFile();
1361
1362      if( pFile->good() )
1363      {
1364        Bool is16bit  = pBLPic->getSlice(0)->getBitDepth(CHANNEL_TYPE_LUMA) > 8 || pBLPic->getSlice(0)->getBitDepth(CHANNEL_TYPE_CHROMA) > 8;
1365        UInt uiWidth  = pBLPic->getPicYuvRec()->getWidth(COMPONENT_Y);
1366        UInt uiHeight = pBLPic->getPicYuvRec()->getHeight(COMPONENT_Y);
1367
1368        Int len = uiWidth * (is16bit ? 2 : 1);
1369        UChar *buf = new UChar[len];
1370
1371        UInt64 uiPos = (UInt64) pcSlice->getPOC() * uiWidth * uiHeight * 3 / 2;
1372        if( is16bit )
1373        {
1374          uiPos <<= 1;
1375        }
1376
1377        pFile->seekg((UInt)uiPos, ios::beg );
1378
1379        // read Y component
1380        Pel* pPel = pBLPic->getPicYuvRec()->getAddr(COMPONENT_Y);
1381        UInt uiStride = pBLPic->getPicYuvRec()->getStride(COMPONENT_Y);
1382        for( Int i = 0; i < uiHeight; i++ )
1383        {
1384          pFile->read(reinterpret_cast<Char*>(buf), len);
1385
1386          if( !is16bit )
1387          {
1388            for (Int x = 0; x < uiWidth; x++)
1389            {
1390              pPel[x] = buf[x];
1391            }
1392          }
1393          else
1394          {
1395            for (Int x = 0; x < uiWidth; x++)
1396            {
1397              pPel[x] = (buf[2*x+1] << 8) | buf[2*x];
1398            }
1399          }
1400     
1401          pPel += uiStride;
1402        }
1403
1404        len >>= 1;
1405        uiWidth >>= 1;
1406        uiHeight >>= 1;
1407
1408        // read Cb component
1409        pPel = pBLPic->getPicYuvRec()->getAddr(COMPONENT_Cb);
1410        uiStride = pBLPic->getPicYuvRec()->getStride(COMPONENT_Cb);
1411        for( Int i = 0; i < uiHeight; i++ )
1412        {
1413          pFile->read(reinterpret_cast<Char*>(buf), len);
1414
1415          if( !is16bit )
1416          {
1417            for( Int x = 0; x < uiWidth; x++ )
1418            {
1419              pPel[x] = buf[x];
1420            }
1421          }
1422          else
1423          {
1424            for( Int x = 0; x < uiWidth; x++ )
1425            {
1426              pPel[x] = (buf[2*x+1] << 8) | buf[2*x];
1427            }
1428          }
1429     
1430          pPel += uiStride;
1431        }
1432
1433        // read Cr component
1434        pPel = pBLPic->getPicYuvRec()->getAddr(COMPONENT_Cr);
1435        uiStride = pBLPic->getPicYuvRec()->getStride(COMPONENT_Cr);
1436        for( Int i = 0; i < uiHeight; i++ )
1437        {
1438          pFile->read(reinterpret_cast<Char*>(buf), len);
1439
1440          if( !is16bit )
1441          {
1442            for( Int x = 0; x < uiWidth; x++ )
1443            {
1444              pPel[x] = buf[x];
1445            }
1446          }
1447          else
1448          {
1449            for( Int x = 0; x < uiWidth; x++ )
1450            {
1451              pPel[x] = (buf[2*x+1] << 8) | buf[2*x];
1452            }
1453          }
1454     
1455          pPel += uiStride;
1456        }
1457
1458        delete[] buf;
1459      }
1460    }
1461#endif
1462
1463    if ( m_layerId == 0 && pcSlice->getRapPicFlag() && getNoClrasOutputFlag() )
1464    {
1465      for (UInt i = 0; i < vps->getMaxLayers(); i++)
1466      {
1467        m_ppcTDecTop[i]->setLayerInitializedFlag(false);
1468        m_ppcTDecTop[i]->setFirstPicInLayerDecodedFlag(false);
1469      }
1470    }
1471
1472    xCheckLayerReset();
1473    xSetLayerInitializedFlag();
1474   
1475#if SVC_POC
1476    m_pcPic->setCurrAuFlag( true );
1477
1478    if( m_pcPic->getLayerId() > 0 && pcSlice->isIDR() && !m_nonBaseIdrPresentFlag )
1479    {
1480      // IDR picture with nuh_layer_id > 0 present
1481      m_nonBaseIdrPresentFlag = true;
1482      m_nonBaseIdrType = (pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL);
1483    }
1484    else
1485    {
1486      if( pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_IDR_W_RADL )
1487      {
1488        // Picture with nal_unit_type not equal IDR_W_RADL present
1489        m_picNonIdrWithRadlPresentFlag = true;
1490      }
1491      if( pcSlice->getNalUnitType() != NAL_UNIT_CODED_SLICE_IDR_N_LP )
1492      {
1493        // Picture with nal_unit_type not equal IDR_N_LP present
1494        m_picNonIdrNoLpPresentFlag = true;
1495      }
1496    }
1497    if( !m_checkPocRestrictionsForCurrAu )  // Will be true for the first slice/picture of the AU
1498    {
1499      m_checkPocRestrictionsForCurrAu = true;
1500      m_pocResetIdcOrCurrAu = pcSlice->getPocResetIdc();
1501      if( m_pcPic->getLayerId() == 0 )
1502      {
1503        // Base layer picture is present
1504        m_baseLayerPicPresentFlag = true;
1505        if( pcSlice->isIRAP() )
1506        {
1507          // Base layer picture is IRAP
1508          m_baseLayerIrapFlag = true;
1509        }
1510        if( pcSlice->isIDR() )
1511        {
1512          // Base layer picture is IDR
1513          m_baseLayerIdrFlag = true;
1514        }
1515        else
1516        {
1517          if( vps->getBaseLayerInternalFlag())
1518          {
1519            /* When the picture with nuh_layer_id equal to 0 in an access unit is not an IDR picture
1520            and vps_base_layer_internal_flag is equal to 1, the value of poc_reset_idc shall not be equal to 2
1521            for any picture in the access unit. */
1522            assert( pcSlice->getPocResetIdc() != 2 );
1523          }
1524        }
1525      }
1526    }
1527    else
1528    {
1529      // The value of poc_reset_idc of all coded pictures that are present in the bitstream in an access unit shall be the same.
1530      assert( m_pocResetIdcOrCurrAu == pcSlice->getPocResetIdc() );
1531
1532      /* 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
1533      and there is at least one other picture in the same access unit that is not an IRAP picture,
1534      the value of poc_reset_idc shall be equal to 1 or 2 for all pictures in the access unit. */
1535      if( m_baseLayerPicPresentFlag && m_baseLayerIrapFlag && !pcSlice->isIRAP() && vps->getBaseLayerInternalFlag() )
1536      {
1537        assert( pcSlice->getPocResetIdc() == 1 || pcSlice->getPocResetIdc() == 2 );
1538      }
1539
1540      /* When the picture with nuh_layer_id equal to 0 in an access unit is an IDR picture and
1541      vps_base_layer_internal_flag is equal to 1 and there is at least one non-IDR picture in the same access unit,
1542      the value of poc_reset_idc shall be equal to 2 for all pictures in the access unit. */
1543      if( m_baseLayerPicPresentFlag && m_baseLayerIdrFlag && !pcSlice->isIDR() && vps->getBaseLayerInternalFlag() )
1544      {
1545        assert( pcSlice->getPocResetIdc() == 2 );
1546      }
1547
1548      /* When there is at least one picture that has nuh_layer_id greater than 0 and that is an IDR picture
1549      with a particular value of nal_unit_type in an access unit and there is at least one other coded picture
1550      that is present in the bitstream in the same access unit with a different value of nal_unit_type,
1551      the value of poc_reset_idc shall be equal to 1 or 2 for all pictures in the access unit. */
1552      if( m_nonBaseIdrPresentFlag && (
1553            ( m_nonBaseIdrType == 1 && m_picNonIdrWithRadlPresentFlag ) ||
1554            ( m_nonBaseIdrType == 0 && m_picNonIdrNoLpPresentFlag )
1555        ))
1556      {
1557        assert( pcSlice->getPocResetIdc() == 1 || pcSlice->getPocResetIdc() == 2 );
1558      }
1559    }
1560#endif
1561  }
1562#endif //SVC_EXTENSION
1563   
1564  // When decoding the slice header, the stored start and end addresses were actually RS addresses, not TS addresses.
1565  // Now, having set up the maps, convert them to the correct form.
1566  pcSlice->setSliceSegmentCurStartCtuTsAddr( m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceSegmentCurStartCtuTsAddr()) );
1567  pcSlice->setSliceSegmentCurEndCtuTsAddr( m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceSegmentCurEndCtuTsAddr()) );
1568  if(!pcSlice->getDependentSliceSegmentFlag())
1569  {
1570    pcSlice->setSliceCurStartCtuTsAddr(m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceCurStartCtuTsAddr()));
1571    pcSlice->setSliceCurEndCtuTsAddr(m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceCurEndCtuTsAddr()));
1572  }
1573   
1574  m_pcPic->setTLayer(nalu.m_temporalId);
1575
1576#if SVC_EXTENSION
1577  m_pcPic->setLayerId(nalu.m_nuhLayerId);
1578  pcSlice->setLayerId(nalu.m_nuhLayerId);
1579  pcSlice->setPic(m_pcPic);
1580#endif
1581
1582  if (!pcSlice->getDependentSliceSegmentFlag())
1583  {
1584    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_associatedIRAPType, m_cListPic );
1585    // Set reference list
1586#if SVC_EXTENSION
1587    if (m_layerId == 0)
1588#endif
1589    pcSlice->setRefPicList( m_cListPic, true );
1590
1591#if SVC_EXTENSION
1592    // Create upsampling reference layer pictures for all possible dependent layers and do it only once for the first slice.
1593    // Other slices might choose which reference pictures to be used for inter-layer prediction
1594    if( m_layerId > 0 && m_uiSliceIdx == 0 && ( !pcSlice->getVPS()->getSingleLayerForNonIrapFlag() || pcSlice->isIRAP() ) )
1595    {
1596      for( Int i = 0; i < pcSlice->getNumILRRefIdx(); i++ )
1597      {
1598        UInt refLayerIdc = i;
1599        UInt refLayerId = pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc);
1600#if AVC_BASE
1601        if( refLayerId == 0 && m_parameterSetManager.getActiveVPS()->getNonHEVCBaseLayerFlag() )
1602        {         
1603          TComPic* pic = *m_ppcTDecTop[0]->getListPic()->begin();
1604
1605          if( pic )
1606          {
1607            pcSlice->setBaseColPic ( refLayerIdc, pic );
1608          }
1609          else
1610          {
1611            continue;
1612          }
1613        }
1614        else
1615        {
1616          TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
1617          TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
1618          if( !pcSlice->setBaseColPic ( *cListPic, refLayerIdc ) )
1619          {
1620            continue;
1621          }
1622        }
1623#else
1624        TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
1625        TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
1626        pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
1627#endif
1628
1629        const Window &scalEL = pcSlice->getPPS()->getScaledRefLayerWindowForLayer(refLayerId);
1630        const Window &windowRL = pcSlice->getPPS()->getRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc));
1631        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth(COMPONENT_Y) - windowRL.getWindowLeftOffset() - windowRL.getWindowRightOffset();
1632        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight(COMPONENT_Y) - windowRL.getWindowTopOffset() - windowRL.getWindowBottomOffset();
1633        Int widthEL   = m_pcPic->getPicYuvRec()->getWidth(COMPONENT_Y)  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
1634        Int heightEL  = m_pcPic->getPicYuvRec()->getHeight(COMPONENT_Y) - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
1635
1636        // conformance check: the values of RefLayerRegionWidthInSamplesY, RefLayerRegionHeightInSamplesY, ScaledRefRegionWidthInSamplesY and ScaledRefRegionHeightInSamplesY shall be greater than 0
1637        assert(widthEL > 0 && heightEL > 0 && widthBL > 0 && widthEL > 0);
1638
1639        // conformance check: ScaledRefRegionWidthInSamplesY shall be greater or equal to RefLayerRegionWidthInSamplesY and ScaledRefRegionHeightInSamplesY shall be greater or equal to RefLayerRegionHeightInSamplesY
1640        assert(widthEL >= widthBL && heightEL >= heightBL);
1641
1642        // 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.
1643        const ResamplingPhase &resamplingPhase = pcSlice->getPPS()->getResamplingPhase( refLayerId );
1644
1645        assert( ( (widthEL  != widthBL)  || (resamplingPhase.phaseHorLuma == 0 && resamplingPhase.phaseHorChroma == 0) )
1646             && ( (heightEL != heightBL) || (resamplingPhase.phaseVerLuma == 0 && resamplingPhase.phaseVerChroma == 0) ) );
1647
1648        g_mvScalingFactor[refLayerIdc][0] = widthEL  == widthBL  ? 4096 : Clip3(-4096, 4095, ((widthEL  << 8) + (widthBL  >> 1)) / widthBL);
1649        g_mvScalingFactor[refLayerIdc][1] = heightEL == heightBL ? 4096 : Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL);
1650
1651        g_posScalingFactor[refLayerIdc][0] = ((widthBL  << 16) + (widthEL  >> 1)) / widthEL;
1652        g_posScalingFactor[refLayerIdc][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL;
1653
1654#if CGS_3D_ASYMLUT
1655        TComPicYuv* pBaseColRec = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec();
1656        if( pcSlice->getPPS()->getCGSFlag() && m_c3DAsymLUTPPS.isRefLayer( pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc) ) )
1657        {
1658          assert( pcSlice->getBaseColPic( refLayerIdc )->getSlice( 0 )->getBitDepth(CHANNEL_TYPE_LUMA) == m_c3DAsymLUTPPS.getInputBitDepthY() );
1659          assert( pcSlice->getBaseColPic( refLayerIdc )->getSlice( 0 )->getBitDepth(CHANNEL_TYPE_CHROMA) == m_c3DAsymLUTPPS.getInputBitDepthC() );
1660          assert( pcSlice->getBitDepth(CHANNEL_TYPE_LUMA) >= m_c3DAsymLUTPPS.getOutputBitDepthY() );
1661          assert( pcSlice->getBitDepth(CHANNEL_TYPE_LUMA) >= m_c3DAsymLUTPPS.getOutputBitDepthC() );
1662
1663          if( !m_pColorMappedPic )
1664          {
1665            initAsymLut(pcSlice->getBaseColPic(refLayerIdc)->getSlice(0));
1666          }
1667
1668          m_c3DAsymLUTPPS.colorMapping( pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), m_pColorMappedPic );
1669          pBaseColRec = m_pColorMappedPic;
1670        }
1671#endif
1672
1673        if( m_pcPic->isSpatialEnhLayer(refLayerIdc) )
1674        {
1675          // check for the sample prediction picture type
1676          if( pcSlice->getVPS()->isSamplePredictionType( pcSlice->getVPS()->getLayerIdxInVps(m_layerId), pcSlice->getVPS()->getLayerIdxInVps(refLayerId) ) )
1677          {
1678            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, m_pcPic->getPicYuvRec(), pcSlice->getBaseColPic( refLayerIdc )->getSlice( 0 )->getBitDepth(CHANNEL_TYPE_LUMA), pcSlice->getBaseColPic( refLayerIdc )->getSlice( 0 )->getBitDepth(CHANNEL_TYPE_CHROMA));
1679          }
1680        }
1681        else
1682        {
1683          m_pcPic->setFullPelBaseRec( refLayerIdc, pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec() );
1684        }
1685        pcSlice->setFullPelBaseRec ( refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc) );
1686      }
1687    }
1688
1689    if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
1690    {
1691      for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
1692      {
1693        UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
1694#if AVC_BASE
1695        if( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) == 0 && pcSlice->getVPS()->getNonHEVCBaseLayerFlag() )
1696        {
1697          pcSlice->setBaseColPic ( refLayerIdc, *m_ppcTDecTop[0]->getListPic()->begin() );
1698        }
1699        else
1700        {
1701          TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
1702          TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
1703          pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
1704        }
1705#else
1706        TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
1707        TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
1708        pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
1709#endif
1710
1711        pcSlice->setFullPelBaseRec ( refLayerIdc, m_pcPic->getFullPelBaseRec(refLayerIdc) );
1712      }
1713
1714      pcSlice->setILRPic( m_cIlpPic );
1715
1716      pcSlice->setRefPicList( m_cListPic, false, m_cIlpPic);
1717    }
1718    else if ( m_layerId > 0 )
1719    {
1720      pcSlice->setRefPicList( m_cListPic, false, NULL);
1721    }
1722
1723    // motion field mapping constraint
1724    if( pcSlice->getMFMEnabledFlag() )
1725    {
1726      TComPic* refPic = pcSlice->getRefPic( pcSlice->getSliceType() == B_SLICE ? ( RefPicList )( 1 - pcSlice->getColFromL0Flag() ) : REF_PIC_LIST_0 , pcSlice->getColRefIdx() );
1727
1728      assert( refPic );
1729
1730      Int refLayerId = refPic->getLayerId();
1731
1732      if( refLayerId != pcSlice->getLayerId() )
1733      {
1734        TComPic* pColBasePic = pcSlice->getBaseColPic( *m_ppcTDecTop[refLayerId]->getListPic() );
1735        assert( pColBasePic->checkSameRefInfo() == true );
1736      }
1737    }
1738   
1739    if( m_layerId > 0 && pcSlice->getVPS()->getCrossLayerIrapAlignFlag() && ( !pcSlice->getVPS()->getSingleLayerForNonIrapFlag() || pcSlice->isIRAP() ) )
1740    {
1741      for(Int dependentLayerIdx = 0; dependentLayerIdx < pcSlice->getVPS()->getNumDirectRefLayers(m_layerId); dependentLayerIdx++)
1742      {
1743        TComList<TComPic*> *cListPic = getRefLayerDec( dependentLayerIdx )->getListPic();
1744        TComPic* refpicLayer = pcSlice->getRefPic(*cListPic, pcSlice->getPOC() );
1745        if(refpicLayer && pcSlice->isIRAP())
1746        {                 
1747          assert(pcSlice->getNalUnitType() == refpicLayer->getSlice(0)->getNalUnitType());
1748        }
1749      }
1750    }
1751   
1752    if( m_layerId > 0 && !pcSlice->isIntra() && pcSlice->getEnableTMVPFlag() )
1753    {
1754      TComPic* refPic = pcSlice->getRefPic(RefPicList(1 - pcSlice->getColFromL0Flag()), pcSlice->getColRefIdx());
1755
1756      assert( refPic );
1757      assert ( refPic->getPicSym()->getSlice(0)->getAvailableForTMVPRefFlag() == true );
1758
1759      // It is a requirement of bitstream conformance when the collocated picture, used for temporal motion vector prediction, is an inter-layer reference picture,
1760      // VpsInterLayerMotionPredictionEnabled[ LayerIdxInVps[ currLayerId ] ][ LayerIdxInVps[ rLId ] ] shall be equal to 1, where rLId is set equal to nuh_layer_id of the inter-layer picture.
1761      if( refPic->isILR(pcSlice->getLayerId()) )
1762      {
1763        assert( pcSlice->getVPS()->isMotionPredictionType( pcSlice->getVPS()->getLayerIdxInVps(m_layerId), refPic->getLayerIdx() ) );
1764      }
1765    }
1766#endif //SVC_EXTENSION
1767   
1768    // For generalized B
1769    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
1770    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
1771    {
1772      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
1773      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
1774
1775      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
1776      {
1777        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
1778      }
1779    }
1780    if (!pcSlice->isIntra())
1781    {
1782      Bool bLowDelay = true;
1783      Int  iCurrPOC  = pcSlice->getPOC();
1784      Int iRefIdx = 0;
1785
1786      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
1787      {
1788        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
1789        {
1790          bLowDelay = false;
1791        }
1792      }
1793      if (pcSlice->isInterB())
1794      {
1795        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
1796        {
1797          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
1798          {
1799            bLowDelay = false;
1800          }
1801        }
1802      }
1803
1804      pcSlice->setCheckLDC(bLowDelay);
1805    }
1806
1807    //---------------
1808    pcSlice->setRefPOCList();
1809  }
1810
1811  m_pcPic->setCurrSliceIdx(m_uiSliceIdx);
1812  if(pcSlice->getSPS()->getScalingListFlag())
1813  {
1814    TComScalingList scalingList;
1815
1816#if SVC_EXTENSION
1817    if( pcSlice->getPPS()->getInferScalingListFlag() )
1818    {
1819      const TComPPS *refPps = m_ppcTDecTop[pcSlice->getPPS()->getScalingListRefLayerId()]->getParameterSetManager()->getActivePPS(); assert( refPps != NULL );
1820      scalingList = refPps->getScalingList();
1821    }
1822    else
1823#endif
1824    if(pcSlice->getPPS()->getScalingListPresentFlag())
1825    {
1826      scalingList = pcSlice->getPPS()->getScalingList();
1827    }
1828#if SVC_EXTENSION
1829    else if( pcSlice->getSPS()->getInferScalingListFlag() )
1830    {
1831      const TComSPS *refSps = m_ppcTDecTop[pcSlice->getSPS()->getScalingListRefLayerId()]->getParameterSetManager()->getActiveSPS(); assert( refSps != NULL );
1832      scalingList = refSps->getScalingList();
1833    }
1834#endif
1835    else if (pcSlice->getSPS()->getScalingListPresentFlag())
1836    {
1837      scalingList = pcSlice->getSPS()->getScalingList();
1838    }
1839    else
1840    {
1841      scalingList.setDefaultScalingList();
1842    }
1843    m_cTrQuant.setScalingListDec(scalingList);
1844    m_cTrQuant.setUseScalingList(true);
1845  }
1846  else
1847  {
1848    const Int maxLog2TrDynamicRange[MAX_NUM_CHANNEL_TYPE] =
1849    {
1850        pcSlice->getSPS()->getMaxLog2TrDynamicRange(CHANNEL_TYPE_LUMA),
1851        pcSlice->getSPS()->getMaxLog2TrDynamicRange(CHANNEL_TYPE_CHROMA)
1852    };
1853#if SVC_EXTENSION
1854    m_cTrQuant.setFlatScalingList(maxLog2TrDynamicRange, pcSlice->getBitDepths());
1855#else
1856    m_cTrQuant.setFlatScalingList(maxLog2TrDynamicRange, pcSlice->getSPS()->getBitDepths());
1857#endif
1858    m_cTrQuant.setUseScalingList(false);
1859  }
1860
1861  //  Decode a picture
1862  m_cGopDecoder.decompressSlice(&(nalu.getBitstream()), m_pcPic);
1863
1864#if SVC_EXTENSION
1865  setFirstPicInLayerDecodedFlag(true);
1866  m_lastPicHasEos = false;
1867#endif
1868
1869  m_bFirstSliceInPicture = false;
1870  m_uiSliceIdx++;
1871
1872  return false;
1873}
1874
1875Void TDecTop::xDecodeVPS(const std::vector<UChar> &naluData)
1876{
1877  TComVPS* vps = new TComVPS();
1878
1879  m_cEntropyDecoder.decodeVPS( vps );
1880  m_parameterSetManager.storeVPS(vps, naluData);
1881#if SVC_EXTENSION
1882  checkValueOfTargetOutputLayerSetIdx(vps);
1883
1884#if AVC_BASE
1885  if( vps->getNonHEVCBaseLayerFlag() )
1886  {
1887    if( !m_ppcTDecTop[0]->getBLReconFile()->good() )
1888    {
1889      printf( "Base layer YUV input reading error\n" );
1890      exit(EXIT_FAILURE);
1891    }       
1892  }
1893  else
1894  {
1895    TComList<TComPic*> *cListPic = m_ppcTDecTop[0]->getListPic();
1896    cListPic->clear();
1897  }
1898#endif
1899
1900  xDeriveSmallestLayerId(vps);
1901#endif
1902}
1903
1904Void TDecTop::xDecodeSPS(const std::vector<UChar> &naluData)
1905{
1906  TComSPS* sps = new TComSPS();
1907#if O0043_BEST_EFFORT_DECODING
1908  sps->setForceDecodeBitDepth(m_forceDecodeBitDepth);
1909#endif
1910#if SVC_EXTENSION
1911  sps->setLayerId(m_layerId);
1912#endif
1913  m_cEntropyDecoder.decodeSPS( sps );
1914  m_parameterSetManager.storeSPS(sps, naluData);
1915}
1916
1917#if CGS_3D_ASYMLUT
1918Void TDecTop::xDecodePPS( const std::vector<UChar> &naluData, TCom3DAsymLUT * pc3DAsymLUT )
1919#else
1920Void TDecTop::xDecodePPS(const std::vector<UChar> &naluData)
1921#endif
1922{
1923  TComPPS* pps = new TComPPS();
1924
1925#if SVC_EXTENSION
1926  pps->setLayerId( m_layerId );
1927#endif
1928#if CGS_3D_ASYMLUT
1929  m_cEntropyDecoder.decodePPS( pps, pc3DAsymLUT, m_layerId );
1930#else
1931  m_cEntropyDecoder.decodePPS( pps );
1932#endif
1933  m_parameterSetManager.storePPS( pps, naluData);
1934}
1935
1936#if SVC_EXTENSION
1937Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC)
1938#else
1939Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1940#endif
1941{
1942#if !SVC_EXTENSION
1943  // ignore all NAL units of layers > 0
1944  if (nalu.m_nuhLayerId > 0)
1945  {
1946    fprintf (stderr, "Warning: found NAL unit with nuh_layer_id equal to %d. Ignoring.\n", nalu.m_nuhLayerId);
1947    return false;
1948  }
1949#endif
1950  // Initialize entropy decoder
1951  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1952  m_cEntropyDecoder.setBitstream      (&(nalu.getBitstream()));
1953
1954#if SVC_EXTENSION
1955  // ignore any NAL units with nuh_layer_id == 63
1956  if( nalu.m_nuhLayerId == 63 )
1957  { 
1958    return false;
1959  }
1960#endif
1961  switch (nalu.m_nalUnitType)
1962  {
1963    case NAL_UNIT_VPS:
1964#if SVC_EXTENSION
1965      assert( nalu.m_nuhLayerId == 0 ); // Non-conforming bitstream. The value of nuh_layer_id of VPS NAL unit shall be equal to 0.
1966#endif
1967      xDecodeVPS(nalu.getBitstream().getFifo());
1968#if RExt__DECODER_DEBUG_BIT_STATISTICS
1969      TComCodingStatistics::IncrementStatisticEP(STATS__BYTE_ALIGNMENT_BITS, nalu.getBitstream().readByteAlignment(), 0);
1970#endif
1971#if SVC_EXTENSION
1972      m_isLastNALWasEos = false;   
1973#endif
1974      return false;
1975
1976    case NAL_UNIT_SPS:
1977      xDecodeSPS(nalu.getBitstream().getFifo());
1978#if RExt__DECODER_DEBUG_BIT_STATISTICS
1979      TComCodingStatistics::IncrementStatisticEP(STATS__BYTE_ALIGNMENT_BITS, nalu.getBitstream().readByteAlignment(), 0);
1980#endif
1981      return false;
1982
1983    case NAL_UNIT_PPS:
1984#if CGS_3D_ASYMLUT
1985      xDecodePPS( nalu.getBitstream().getFifo(), &m_c3DAsymLUTPPS );
1986#else
1987      xDecodePPS(nalu.getBitstream().getFifo());
1988#endif
1989#if RExt__DECODER_DEBUG_BIT_STATISTICS
1990      TComCodingStatistics::IncrementStatisticEP(STATS__BYTE_ALIGNMENT_BITS, nalu.getBitstream().readByteAlignment(),0);
1991#endif
1992      return false;
1993
1994    case NAL_UNIT_PREFIX_SEI:
1995      // Buffer up prefix SEI messages until SPS of associated VCL is known.
1996      m_prefixSEINALUs.push_back(new InputNALUnit(nalu));
1997      return false;
1998
1999    case NAL_UNIT_SUFFIX_SEI:
2000#if SVC_EXTENSION
2001      if( nalu.m_nalUnitType == NAL_UNIT_SUFFIX_SEI )
2002      {
2003        assert( m_isLastNALWasEos == false );
2004      }
2005#endif
2006      if (m_pcPic)
2007      {
2008#if SVC_EXTENSION
2009        m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_pcPic->getSEIs(), nalu.m_nalUnitType, m_parameterSetManager.getActiveVPS(), m_parameterSetManager.getActiveSPS(), m_pDecodedSEIOutputStream );
2010#else
2011        m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_pcPic->getSEIs(), nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS(), m_pDecodedSEIOutputStream );
2012#endif
2013      }
2014      else
2015      {
2016        printf ("Note: received suffix SEI but no picture currently active.\n");
2017      }
2018      return false;
2019
2020    case NAL_UNIT_CODED_SLICE_TRAIL_R:
2021    case NAL_UNIT_CODED_SLICE_TRAIL_N:
2022    case NAL_UNIT_CODED_SLICE_TSA_R:
2023    case NAL_UNIT_CODED_SLICE_TSA_N:
2024    case NAL_UNIT_CODED_SLICE_STSA_R:
2025    case NAL_UNIT_CODED_SLICE_STSA_N:
2026    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
2027    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
2028    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
2029    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
2030    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
2031    case NAL_UNIT_CODED_SLICE_CRA:
2032    case NAL_UNIT_CODED_SLICE_RADL_N:
2033    case NAL_UNIT_CODED_SLICE_RADL_R:
2034    case NAL_UNIT_CODED_SLICE_RASL_N:
2035    case NAL_UNIT_CODED_SLICE_RASL_R:
2036#if SVC_EXTENSION
2037      if( nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_N ||
2038          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_N ||
2039          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_N ||
2040          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
2041          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N )
2042      {
2043        assert( m_isLastNALWasEos == false );
2044      }
2045      else
2046      {
2047        m_isLastNALWasEos = false;
2048      }
2049
2050      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, curLayerId, bNewPOC);
2051#else
2052      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
2053#endif
2054      break;
2055
2056    case NAL_UNIT_EOS:
2057#if SVC_EXTENSION
2058      assert( m_isLastNALWasEos == false );
2059
2060      m_isLastNALWasEos = true;
2061      m_lastPicHasEos = true;
2062#endif
2063      m_associatedIRAPType = NAL_UNIT_INVALID;
2064      m_pocCRA = 0;
2065      m_pocRandomAccess = MAX_INT;
2066      m_prevPOC = MAX_INT;
2067      m_prevSliceSkipped = false;
2068      m_skippedPOC = 0;
2069      return false;
2070
2071    case NAL_UNIT_ACCESS_UNIT_DELIMITER:
2072      // TODO: process AU delimiter
2073      return false;
2074
2075    case NAL_UNIT_EOB:
2076#if SVC_EXTENSION
2077      //Check layer id of the nalu. if it is not 0, give a warning message.
2078      if (nalu.m_nuhLayerId > 0)
2079      {
2080        printf( "\n\nThis bitstream is ended with EOB NALU that has layer id greater than 0\n" );
2081      }
2082#endif
2083      return false;
2084
2085    case NAL_UNIT_FILLER_DATA:
2086#if SVC_EXTENSION
2087      assert( m_isLastNALWasEos == false );
2088#endif
2089      return false;
2090
2091    case NAL_UNIT_RESERVED_VCL_N10:
2092    case NAL_UNIT_RESERVED_VCL_R11:
2093    case NAL_UNIT_RESERVED_VCL_N12:
2094    case NAL_UNIT_RESERVED_VCL_R13:
2095    case NAL_UNIT_RESERVED_VCL_N14:
2096    case NAL_UNIT_RESERVED_VCL_R15:
2097
2098    case NAL_UNIT_RESERVED_IRAP_VCL22:
2099    case NAL_UNIT_RESERVED_IRAP_VCL23:
2100
2101    case NAL_UNIT_RESERVED_VCL24:
2102    case NAL_UNIT_RESERVED_VCL25:
2103    case NAL_UNIT_RESERVED_VCL26:
2104    case NAL_UNIT_RESERVED_VCL27:
2105    case NAL_UNIT_RESERVED_VCL28:
2106    case NAL_UNIT_RESERVED_VCL29:
2107    case NAL_UNIT_RESERVED_VCL30:
2108    case NAL_UNIT_RESERVED_VCL31:
2109      printf ("Note: found reserved VCL NAL unit.\n");
2110      xParsePrefixSEIsForUnknownVCLNal();
2111      return false;
2112
2113    case NAL_UNIT_RESERVED_NVCL41:
2114    case NAL_UNIT_RESERVED_NVCL42:
2115    case NAL_UNIT_RESERVED_NVCL43:
2116    case NAL_UNIT_RESERVED_NVCL44:
2117    case NAL_UNIT_RESERVED_NVCL45:
2118    case NAL_UNIT_RESERVED_NVCL46:
2119    case NAL_UNIT_RESERVED_NVCL47:
2120      printf ("Note: found reserved NAL unit.\n");
2121      return false;
2122    case NAL_UNIT_UNSPECIFIED_48:
2123    case NAL_UNIT_UNSPECIFIED_49:
2124    case NAL_UNIT_UNSPECIFIED_50:
2125    case NAL_UNIT_UNSPECIFIED_51:
2126    case NAL_UNIT_UNSPECIFIED_52:
2127    case NAL_UNIT_UNSPECIFIED_53:
2128    case NAL_UNIT_UNSPECIFIED_54:
2129    case NAL_UNIT_UNSPECIFIED_55:
2130    case NAL_UNIT_UNSPECIFIED_56:
2131    case NAL_UNIT_UNSPECIFIED_57:
2132    case NAL_UNIT_UNSPECIFIED_58:
2133    case NAL_UNIT_UNSPECIFIED_59:
2134    case NAL_UNIT_UNSPECIFIED_60:
2135    case NAL_UNIT_UNSPECIFIED_61:
2136    case NAL_UNIT_UNSPECIFIED_62:
2137    case NAL_UNIT_UNSPECIFIED_63:
2138      printf ("Note: found unspecified NAL unit.\n");
2139      return false;
2140    default:
2141      assert (0);
2142      break;
2143  }
2144
2145  return false;
2146}
2147
2148/** Function for checking if picture should be skipped because of association with a previous BLA picture
2149 * \param iPOCLastDisplay POC of last picture displayed
2150 * \returns true if the picture should be skipped
2151 * This function skips all TFD pictures that follow a BLA picture
2152 * in decoding order and precede it in output order.
2153 */
2154Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
2155{
2156  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) &&
2157       m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
2158  {
2159    iPOCLastDisplay++;
2160    return true;
2161  }
2162  return false;
2163}
2164
2165/** Function for checking if picture should be skipped because of random access
2166 * \param iSkipFrame skip frame counter
2167 * \param iPOCLastDisplay POC of last picture displayed
2168 * \returns true if the picture shold be skipped in the random access.
2169 * This function checks the skipping of pictures in the case of -s option random access.
2170 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
2171 * It also checks the type of Nal unit type at the random access point.
2172 * 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.
2173 * If the random access point is IDR all pictures after the random access point are decoded.
2174 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
2175 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
2176 * access point there is no guarantee that the decoder will not crash.
2177 */
2178Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
2179{
2180  if (iSkipFrame)
2181  {
2182    iSkipFrame--;   // decrement the counter
2183    return true;
2184  }
2185  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
2186  {
2187    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
2188        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
2189        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
2190        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
2191    {
2192      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
2193      m_pocRandomAccess = m_apcSlicePilot->getPOC();
2194    }
2195    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
2196    {
2197      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
2198    }
2199    else
2200    {
2201      if(!m_warningMessageSkipPicture)
2202      {
2203        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
2204        m_warningMessageSkipPicture = true;
2205      }
2206      return true;
2207    }
2208  }
2209  // skip the reordered pictures, if necessary
2210  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))
2211  {
2212    iPOCLastDisplay++;
2213    return true;
2214  }
2215  // if we reach here, then the picture is not skipped.
2216  return false;
2217}
2218
2219#if SVC_EXTENSION
2220Void TDecTop::xInitILRP(TComSlice *slice)
2221{
2222  const TComVPS* vps  = slice->getVPS();
2223  const TComSPS* sps  = slice->getSPS();
2224
2225  if( m_layerId > 0 )
2226  {
2227    if (m_cIlpPic[0] == NULL)
2228    {
2229      for (Int j=0; j < m_numDirectRefLayers; j++)
2230      {
2231        m_cIlpPic[j] = new  TComPic;
2232
2233        m_cIlpPic[j]->create(*vps, *sps, *slice->getPPS(), true, m_layerId);
2234
2235        for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCtusInFrame(); i++)
2236        {
2237          m_cIlpPic[j]->getPicSym()->getCtu(i)->initCtu(m_cIlpPic[j], i);
2238        }
2239      }
2240    }
2241  }
2242}
2243
2244TDecTop* TDecTop::getRefLayerDec( UInt refLayerIdx )
2245{
2246  const TComVPS* vps = m_parameterSetManager.getActiveVPS();
2247  if( vps->getNumDirectRefLayers( m_layerId ) <= 0 )
2248  {
2249    return (TDecTop *)getLayerDec( 0 );
2250  }
2251 
2252  return (TDecTop *)getLayerDec( vps->getRefLayerId( m_layerId, refLayerIdx ) );
2253}
2254
2255Void TDecTop::setRefLayerParams( const TComVPS* vps )
2256{
2257  for(UInt layerIdx = 0; layerIdx < m_numLayer; layerIdx++)
2258  {
2259    TDecTop *decTop = (TDecTop *)getLayerDec(vps->getLayerIdInNuh(layerIdx));
2260    decTop->setNumSamplePredRefLayers(0);
2261    decTop->setNumMotionPredRefLayers(0);
2262    decTop->setNumDirectRefLayers(0);
2263
2264    for(Int j = 0; j < layerIdx; j++)
2265    {
2266      if (vps->getDirectDependencyFlag(layerIdx, j))
2267      {
2268        decTop->setRefLayerId(decTop->getNumDirectRefLayers(), vps->getLayerIdInNuh(layerIdx));
2269        decTop->setNumDirectRefLayers(decTop->getNumDirectRefLayers() + 1);
2270
2271        Int samplePredEnabledFlag = (vps->getDirectDependencyType(layerIdx, j) + 1) & 1;
2272        decTop->setNumSamplePredRefLayers(decTop->getNumSamplePredRefLayers() + samplePredEnabledFlag);
2273
2274        Int motionPredEnabledFlag = ((vps->getDirectDependencyType(layerIdx, j) + 1) & 2) >> 1;
2275        decTop->setNumMotionPredRefLayers(decTop->getNumMotionPredRefLayers() + motionPredEnabledFlag);
2276      }
2277    }
2278  }
2279}
2280
2281Void TDecTop::checkValueOfTargetOutputLayerSetIdx(TComVPS *vps)
2282{
2283  CommonDecoderParams* params = this->getCommonDecoderParams();
2284
2285  if( params->getValueCheckedFlag() )
2286  {
2287    return; // Already checked
2288  }
2289
2290  if( params->getTargetOutputLayerSetIdx() == -1 )  // Output layer set index not specified
2291  {
2292    if( params->getTargetLayerId() > vps->getMaxLayerId() )
2293    {
2294      printf( "Warning: specified target layerId %d is greater than max layerId %d. Target layerId is set equal to max layerId %d.\n", params->getTargetLayerId(), vps->getMaxLayerId(), vps->getMaxLayerId() );
2295      params->setTargetLayerId( vps->getMaxLayerId() );
2296    }
2297
2298    Bool layerSetMatchFound = false;
2299    // Output layer set index not assigned.
2300    // Based on the value of targetLayerId, check if any of the output layer matches
2301    // Currently, the target layer ID in the encoder assumes that all the layers are decoded   
2302    // Check if any of the output layer sets match this description
2303    for( Int i = 0; i < vps->getNumOutputLayerSets(); i++ )
2304    {
2305      Bool layerSetMatchFlag = false;
2306      Int layerSetIdx = vps->getOutputLayerSetIdx( i );
2307
2308      for( Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++ )
2309      {
2310        if( vps->getLayerSetLayerIdList( layerSetIdx, j ) == params->getTargetLayerId() )
2311        {
2312          layerSetMatchFlag = true;
2313          break;
2314        }
2315      }
2316     
2317      if( layerSetMatchFlag ) // Potential output layer set candidate found
2318      {
2319        // If target dec layer ID list is also included - check if they match
2320        if( params->getTargetDecLayerIdSet() )
2321        {
2322          if( params->getTargetDecLayerIdSet()->size() ) 
2323          {
2324            for( Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++ )
2325            {
2326              if( *(params->getTargetDecLayerIdSet()->begin() + j) != vps->getLayerIdInNuh(vps->getLayerSetLayerIdList( layerSetIdx, j )))
2327              {
2328                layerSetMatchFlag = false;
2329              }
2330            }
2331          }
2332        }
2333        if( layerSetMatchFlag ) // The target dec layer ID list also matches, if present
2334        {
2335          // Match found
2336          layerSetMatchFound = true;
2337          params->setTargetOutputLayerSetIdx( i );
2338          params->setValueCheckedFlag( true );
2339          break;
2340        }
2341      }
2342    }
2343    assert( layerSetMatchFound ); // No output layer set matched the value of either targetLayerId or targetdeclayerIdlist
2344  }   
2345  else // Output layer set index is assigned - check if the values match
2346  {
2347    // Check if the target decoded layer is the highest layer in the list
2348    assert( params->getTargetOutputLayerSetIdx() < vps->getNumOutputLayerSets() );
2349#if !CONFORMANCE_BITSTREAM_MODE
2350    assert( params->getTargetOutputLayerSetIdx() < vps->getNumLayerSets() );
2351#endif
2352    Int layerSetIdx = vps->getOutputLayerSetIdx( params->getTargetOutputLayerSetIdx() );  // Index to the layer set
2353#if !CONFORMANCE_BITSTREAM_MODE
2354    assert( params->getTargetLayerId() == vps->getNumLayersInIdList( layerSetIdx ) - 1);
2355#endif
2356   
2357    // Check if the targetdeclayerIdlist matches the output layer set
2358    if( params->getTargetDecLayerIdSet() )
2359    {
2360      if( params->getTargetDecLayerIdSet()->size() ) 
2361      {
2362        for(Int i = 0; i < vps->getNumLayersInIdList( layerSetIdx ); i++)
2363        {
2364          assert( *(params->getTargetDecLayerIdSet()->begin() + i) == vps->getLayerIdInNuh(vps->getLayerSetLayerIdList( layerSetIdx, i )));
2365        }
2366      }
2367    }
2368    params->setValueCheckedFlag( true );
2369
2370  }
2371
2372  // Set correct value of targetLayerId
2373  Int targetOlsIdx = params->getTargetOutputLayerSetIdx();
2374  Int targetLsIdx = vps->getOutputLayerSetIdx( targetOlsIdx );
2375  params->setTargetLayerId( vps->getLayerSetLayerIdList( targetLsIdx, vps->getNumLayersInIdList(targetLsIdx)-1 ) );
2376
2377  // Check if the current layer is an output layer
2378  for( Int i = 0; i < vps->getNumLayersInIdList( targetLsIdx ); i++ )
2379  {
2380    if( vps->getOutputLayerFlag( targetOlsIdx, i ) )
2381    {
2382      this->getLayerDec( vps->getLayerSetLayerIdList( targetLsIdx, i ) )->m_isOutputLayerFlag = true;
2383    }
2384  }
2385}
2386
2387Void TDecTop::markAllPicsAsNoCurrAu( const TComVPS *vps )
2388{
2389  for(Int i = 0; i < MAX_LAYERS; i++)
2390  {
2391    TComList<TComPic*>* listPic = m_ppcTDecTop[vps->getLayerIdInNuh(i)]->getListPic();
2392    TComList<TComPic*>::iterator  iterPic = listPic->begin();
2393    while ( iterPic != listPic->end() )
2394    {
2395      TComPic *pcPic = *(iterPic);
2396      pcPic->setCurrAuFlag( false );
2397      iterPic++;
2398    }
2399  }
2400}
2401
2402#if CGS_3D_ASYMLUT
2403Void TDecTop::initAsymLut(TComSlice *pcSlice)
2404{
2405  if( m_layerId > 0 )
2406  {
2407    if( !m_pColorMappedPic )
2408    {
2409      m_pColorMappedPic = new TComPicYuv;
2410      m_pColorMappedPic->create( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc()/*CHROMA_420*/, pcSlice->getSPS()->getMaxCUWidth(), pcSlice->getSPS()->getMaxCUHeight(), pcSlice->getSPS()->getMaxTotalCUDepth(), true, NULL );
2411    }
2412  }
2413}
2414#endif
2415
2416Void TDecTop::resetPocRestrictionCheckParameters()
2417{
2418  TDecTop::m_checkPocRestrictionsForCurrAu       = false;
2419  TDecTop::m_pocResetIdcOrCurrAu                 = -1;
2420  TDecTop::m_baseLayerIdrFlag                    = false;
2421  TDecTop::m_baseLayerPicPresentFlag             = false;
2422  TDecTop::m_baseLayerIrapFlag                   = false;
2423  TDecTop::m_nonBaseIdrPresentFlag               = false;
2424  TDecTop::m_nonBaseIdrType                      = -1;
2425  TDecTop::m_picNonIdrWithRadlPresentFlag        = false;
2426  TDecTop::m_picNonIdrNoLpPresentFlag            = false;
2427}
2428
2429Void TDecTop::xCheckLayerReset()
2430{
2431  if (m_apcSlicePilot->isIRAP() && m_layerId > m_smallestLayerId)
2432  {
2433    Bool layerResetFlag;
2434    UInt dolLayerId;
2435    if (m_lastPicHasEos)
2436    {
2437      layerResetFlag = true;
2438      dolLayerId = m_layerId;
2439    }
2440    else if ((m_apcSlicePilot->isCRA() && m_apcSlicePilot->getHandleCraAsBlaFlag()) ||
2441      (m_apcSlicePilot->isIDR() && m_apcSlicePilot->getCrossLayerBLAFlag()) || m_apcSlicePilot->isBLA())
2442    {
2443      layerResetFlag = true;
2444      dolLayerId = m_layerId;
2445    }
2446    else
2447    {
2448      layerResetFlag = false;
2449    }
2450
2451    if (layerResetFlag)
2452    {
2453      for (Int i = 0; i < m_apcSlicePilot->getVPS()->getNumPredictedLayers(dolLayerId); i++)
2454      {
2455        UInt iLayerId = m_apcSlicePilot->getVPS()->getPredictedLayerId(dolLayerId, i);
2456        m_ppcTDecTop[iLayerId]->m_layerInitializedFlag = false;
2457        m_ppcTDecTop[iLayerId]->m_firstPicInLayerDecodedFlag = false;
2458      }
2459
2460      for (TComList<TComPic*>::iterator i = m_cListPic.begin(); i != m_cListPic.end(); i++)
2461      {
2462        if ((*i)->getPOC() != m_apcSlicePilot->getPOC())
2463        {
2464          (*i)->getSlice(0)->setReferenced(false);
2465        }
2466      }
2467
2468      for (UInt i = 0; i < m_apcSlicePilot->getVPS()->getNumPredictedLayers(dolLayerId); i++)
2469      {
2470        UInt predLId = m_apcSlicePilot->getVPS()->getPredictedLayerId(dolLayerId, i);
2471        for (TComList<TComPic*>::iterator pic = m_ppcTDecTop[predLId]->getListPic()->begin(); pic != m_ppcTDecTop[predLId]->getListPic()->end(); pic++)
2472        {
2473          if ((*pic)->getSlice(0)->getPOC() != m_apcSlicePilot->getPOC())
2474          {
2475            (*pic)->getSlice(0)->setReferenced(false);
2476          }
2477        }
2478      }
2479    }
2480  }
2481}
2482
2483Void TDecTop::xSetLayerInitializedFlag()
2484{
2485  if (m_apcSlicePilot->isIRAP() && m_apcSlicePilot->getNoRaslOutputFlag())
2486  {
2487    if (m_layerId == 0)
2488    {
2489      m_ppcTDecTop[m_layerId]->setLayerInitializedFlag(true);
2490    }
2491    else if (!m_ppcTDecTop[m_layerId]->getLayerInitializedFlag() && m_apcSlicePilot->getVPS()->getNumDirectRefLayers(m_layerId) == 0)
2492    {
2493      m_ppcTDecTop[m_layerId]->setLayerInitializedFlag(true);
2494    }
2495    else if (!m_ppcTDecTop[m_layerId]->getLayerInitializedFlag())
2496    {
2497      Bool refLayersInitialized = true;
2498      for (UInt j = 0; j < m_apcSlicePilot->getVPS()->getNumDirectRefLayers(m_layerId); j++)
2499      {
2500        UInt refLayerId = m_apcSlicePilot->getVPS()->getRefLayerId(m_layerId, j);
2501        if (!m_ppcTDecTop[refLayerId]->getLayerInitializedFlag())
2502        {
2503          refLayersInitialized = false;
2504        }
2505      }
2506      if (refLayersInitialized)
2507      {
2508        m_ppcTDecTop[m_layerId]->setLayerInitializedFlag(true);
2509      }
2510    }
2511  }
2512}
2513
2514Void TDecTop::xDeriveSmallestLayerId(TComVPS* vps)
2515{
2516  UInt smallestLayerId;
2517  Int  targetOlsIdx = m_commonDecoderParams->getTargetOutputLayerSetIdx();
2518  assert( targetOlsIdx >= 0 );
2519
2520  UInt targetDecLayerSetIdx = vps->getOutputLayerSetIdx(targetOlsIdx);
2521  UInt lsIdx = targetDecLayerSetIdx;
2522  UInt targetDecLayerIdList[MAX_LAYERS] = {0};
2523
2524  for (UInt i = 0, j = 0; i < vps->getNumLayersInIdList(lsIdx); i++)
2525  {
2526    if (vps->getNecessaryLayerFlag(targetOlsIdx, i))
2527    {
2528      targetDecLayerIdList[j++] = vps->getLayerSetLayerIdList(lsIdx, i);
2529    }
2530  }
2531
2532  if (targetDecLayerSetIdx <= vps->getVpsNumLayerSetsMinus1())
2533  {
2534    smallestLayerId = 0;
2535  }
2536  else if (vps->getNumLayersInIdList(targetDecLayerSetIdx) == 1)
2537  {
2538    smallestLayerId = 0;
2539  }
2540  else
2541  {
2542    smallestLayerId = targetDecLayerIdList[0];
2543  }
2544
2545  for( UInt layerId = 0; layerId < MAX_VPS_LAYER_IDX_PLUS1; layerId++ )
2546  {
2547    m_ppcTDecTop[layerId]->m_smallestLayerId = smallestLayerId;
2548  }
2549}
2550
2551Void TDecTop::xSetSpatialEnhLayerFlag( const TComVPS &vps, const TComSPS &sps, const TComPPS &pps, TComPic* pic )
2552{
2553  for(UInt i = 0; i < vps.getNumDirectRefLayers( m_layerId ); i++ )
2554  {
2555    const Window scalEL = pps.getScaledRefLayerWindowForLayer(vps.getRefLayerId(m_layerId, i));
2556    const Window refEL = pps.getRefLayerWindowForLayer(vps.getRefLayerId(m_layerId, i));
2557    Bool equalOffsets = scalEL.hasEqualOffset(refEL);
2558    Bool zeroPhase = pps.hasZeroResamplingPhase(vps.getRefLayerId(m_layerId, i));
2559
2560    TDecTop *pcTDecTopBase = (TDecTop *)getRefLayerDec( i );
2561    TComPicYuv* pcPicYuvRecBase = (*(pcTDecTopBase->getListPic()->begin()))->getPicYuvRec();
2562
2563    const Int bitDepthLuma = vps.getBitDepth(CHANNEL_TYPE_LUMA, &sps, m_layerId);
2564    const Int bitDepthChroma = vps.getBitDepth(CHANNEL_TYPE_CHROMA, &sps, m_layerId);
2565    const Int refBitDepthLuma = (*(pcTDecTopBase->getListPic()->begin()))->getSlice(0)->getBitDepth(CHANNEL_TYPE_LUMA);
2566    const Int refBitDepthChroma = (*(pcTDecTopBase->getListPic()->begin()))->getSlice(0)->getBitDepth(CHANNEL_TYPE_CHROMA);
2567   
2568    Bool sameBitDepths = ( bitDepthLuma == refBitDepthLuma ) && ( bitDepthChroma == refBitDepthChroma );
2569
2570    if( pcPicYuvRecBase->getWidth(COMPONENT_Y) == vps.getPicWidthInLumaSamples(&sps, m_layerId) && pcPicYuvRecBase->getHeight(COMPONENT_Y) == vps.getPicHeightInLumaSamples(&sps, m_layerId) && equalOffsets && zeroPhase )
2571    {
2572      pic->setEqualPictureSizeAndOffsetFlag( i, true );
2573    }
2574
2575    if( !pic->equalPictureSizeAndOffsetFlag(i) || !sameBitDepths
2576#if CGS_3D_ASYMLUT
2577      || pps.getCGSFlag() > 0
2578#endif
2579#if LAYER_CTB
2580      || 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()
2581#endif
2582      )
2583    {
2584      pic->setSpatialEnhLayerFlag( i, true );
2585
2586      //only for scalable extension
2587      assert( vps.getScalabilityMask( SCALABILITY_ID ) == true );
2588    }
2589  }
2590}
2591
2592#endif //SVC_EXTENSION
2593
2594
2595//! \}
Note: See TracBrowser for help on using the repository browser.