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

Last change on this file since 1379 was 1377, checked in by seregin, 11 years ago

dynamic memory allocation at encoder

  • Property svn:eol-style set to native
File size: 93.0 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license.
5 *
6 * Copyright (c) 2010-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
41#if SVC_EXTENSION
42UInt  TDecTop::m_prevPOC                       = MAX_UINT;
43UInt  TDecTop::m_uiPrevLayerId                 = MAX_UINT;
44Bool  TDecTop::m_bFirstSliceInSequence         = true;
45Bool  TDecTop::m_checkPocRestrictionsForCurrAu = false;
46Int   TDecTop::m_pocResetIdcOrCurrAu           = -1;
47Bool  TDecTop::m_baseLayerIdrFlag              = false;
48Bool  TDecTop::m_baseLayerPicPresentFlag       = false;
49Bool  TDecTop::m_baseLayerIrapFlag             = false;
50Bool  TDecTop::m_nonBaseIdrPresentFlag         = false;
51Int   TDecTop::m_nonBaseIdrType                = -1;
52Bool  TDecTop::m_picNonIdrWithRadlPresentFlag  = false;
53Bool  TDecTop::m_picNonIdrNoLpPresentFlag      = false;
54Int   TDecTop::m_crossLayerPocResetPeriodId    = -1;
55Int   TDecTop::m_crossLayerPocResetIdc         = -1;
56#endif
57
58//! \ingroup TLibDecoder
59//! \{
60
61TDecTop::TDecTop()
62  : m_iMaxRefPicNum(0)
63  , m_associatedIRAPType(NAL_UNIT_INVALID)
64  , m_pocCRA(0)
65  , m_pocRandomAccess(MAX_INT)
66  , m_cListPic()
67  , m_parameterSetManager()
68  , m_apcSlicePilot(NULL)
69  , m_SEIs()
70  , m_cPrediction()
71  , m_cTrQuant()
72  , m_cGopDecoder()
73  , m_cSliceDecoder()
74  , m_cCuDecoder()
75  , m_cEntropyDecoder()
76  , m_cCavlcDecoder()
77  , m_cSbacDecoder()
78  , m_cBinCABAC()
79  , m_seiReader()
80  , m_cLoopFilter()
81  , m_cSAO()
82  , m_pcPic(NULL)
83#if !SVC_EXTENSION
84  , m_prevPOC(MAX_INT)
85#endif
86  , m_prevTid0POC(0)
87  , m_bFirstSliceInPicture(true)
88#if !SVC_EXTENSION
89  , m_bFirstSliceInSequence(true)
90#endif
91  , m_prevSliceSkipped(false)
92  , m_skippedPOC(0)
93  , m_bFirstSliceInBitstream(true)
94  , m_lastPOCNoOutputPriorPics(-1)
95  , m_isNoOutputPriorPics(false)
96  , m_craNoRaslOutputFlag(false)
97#if O0043_BEST_EFFORT_DECODING
98  , m_forceDecodeBitDepth(8)
99#endif
100  , m_pDecodedSEIOutputStream(NULL)
101  , m_warningMessageSkipPicture(false)
102  , m_prefixSEINALUs()
103{
104#if ENC_DEC_TRACE
105  if (g_hTrace == NULL)
106  {
107    g_hTrace = fopen( "TraceDec.txt", "wb" );
108  }
109  g_bJustDoIt = g_bEncDecTraceDisable;
110  g_nSymbolCounter = 0;
111#endif
112
113#if SVC_EXTENSION
114  m_layerId = 0;
115  m_smallestLayerId = 0;
116#if AVC_BASE
117  m_pBLReconFile = NULL;
118#endif
119  memset(m_cIlpPic, 0, sizeof(m_cIlpPic));
120  m_isLastNALWasEos = false;
121  m_lastPicHasEos = false;
122#if NO_CLRAS_OUTPUT_FLAG
123  m_noClrasOutputFlag          = false;
124  m_layerInitializedFlag       = false;
125  m_firstPicInLayerDecodedFlag = false; 
126#endif
127  m_parseIdc = -1;
128  m_lastPocPeriodId = -1;
129  m_prevPicOrderCnt = 0;
130#if CGS_3D_ASYMLUT
131  m_pColorMappedPic = NULL;
132#endif
133
134  resetPocRestrictionCheckParameters();
135  m_pocResettingFlag        = false;
136  m_pocDecrementedInDPBFlag = false;
137#if CONFORMANCE_BITSTREAM_MODE
138  m_confModeFlag = false;
139#endif
140  m_isOutputLayerFlag = false;
141#endif //SVC_EXTENSION
142}
143
144TDecTop::~TDecTop()
145{
146#if ENC_DEC_TRACE
147  if (g_hTrace != stdout)
148  {
149    fclose( g_hTrace );
150  }
151#endif
152  while (!m_prefixSEINALUs.empty())
153  {
154    delete m_prefixSEINALUs.front();
155    m_prefixSEINALUs.pop_front();
156  }
157#if CGS_3D_ASYMLUT
158  if(m_pColorMappedPic)
159  {
160    m_pColorMappedPic->destroy();
161    delete m_pColorMappedPic;
162    m_pColorMappedPic = NULL;
163  }
164#endif
165}
166
167Void TDecTop::create()
168{
169#if SVC_EXTENSION
170  m_cGopDecoder.create( m_layerId );
171#else
172  m_cGopDecoder.create();
173#endif
174  m_apcSlicePilot = new TComSlice;
175  m_uiSliceIdx = 0;
176}
177
178Void TDecTop::destroy()
179{
180  m_cGopDecoder.destroy();
181
182  delete m_apcSlicePilot;
183  m_apcSlicePilot = NULL;
184
185  m_cSliceDecoder.destroy();
186#if SVC_EXTENSION
187  for(Int i=0; i<MAX_NUM_REF; i++)
188  {
189    if(m_cIlpPic[i])
190    {
191      m_cIlpPic[i]->destroy();
192      delete m_cIlpPic[i];
193      m_cIlpPic[i] = NULL;
194    }
195  }
196#endif
197}
198
199Void TDecTop::init()
200{
201#if !SVC_EXTENSION
202  // initialize ROM
203  initROM();
204#endif
205#if SVC_EXTENSION
206  m_cGopDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
207#else
208  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
209#endif
210  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
211  m_cEntropyDecoder.init(&m_cPrediction);
212}
213
214Void TDecTop::deletePicBuffer ( )
215{
216  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
217  Int iSize = Int( m_cListPic.size() );
218
219  for (Int i = 0; i < iSize; i++ )
220  {
221    TComPic* pcPic = *(iterPic++);
222#if SVC_EXTENSION
223    if( pcPic )
224    {
225      pcPic->destroy();
226
227      delete pcPic;
228      pcPic = NULL;
229    }
230#else
231    pcPic->destroy();
232
233    delete pcPic;
234    pcPic = NULL;
235#endif
236  }
237
238  m_cSAO.destroy();
239
240  m_cLoopFilter.        destroy();
241 
242#if !SVC_EXTENSION
243  // destroy ROM
244  destroyROM();
245#endif
246}
247
248#if SVC_EXTENSION
249Void TDecTop::xGetNewPicBuffer( const TComVPS &vps, const TComSPS &sps, const TComPPS &pps, TComPic*& rpcPic, const UInt temporalLayer )
250#else
251Void TDecTop::xGetNewPicBuffer ( const TComSPS &sps, const TComPPS &pps, TComPic*& rpcPic, const UInt temporalLayer )
252#endif
253{
254#if SVC_EXTENSION
255  if( m_commonDecoderParams->getTargetOutputLayerSetIdx() == 0 )
256  {
257    assert( m_layerId == 0 );
258    m_iMaxRefPicNum = sps.getMaxDecPicBuffering(temporalLayer);     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
259  }
260  else
261  {
262    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
263  }
264
265  m_iMaxRefPicNum += 1; // it should be updated if more than 1 resampling picture is used
266#else
267  m_iMaxRefPicNum = sps.getMaxDecPicBuffering(temporalLayer);     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
268#endif
269 
270  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
271  {
272    rpcPic = new TComPic();
273
274#if SVC_EXTENSION
275    if(m_layerId > 0)
276    {
277      xSetSpatialEnhLayerFlag( vps, sps, pps, rpcPic );
278    }
279
280    rpcPic->create( vps, sps, pps, true, m_layerId);
281#else //SVC_EXTENSION
282    rpcPic->create ( sps, pps, true);
283#endif //SVC_EXTENSION
284   
285    m_cListPic.pushBack( rpcPic );
286
287    return;
288  }
289
290  Bool bBufferIsAvailable = false;
291  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
292  while (iterPic != m_cListPic.end())
293  {
294    rpcPic = *(iterPic++);
295    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
296    {
297      rpcPic->setOutputMark(false);
298      bBufferIsAvailable = true;
299      break;
300    }
301
302    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
303    {
304#if !SVC_EXTENSION
305      rpcPic->setOutputMark(false);
306#endif
307      rpcPic->setReconMark( false );
308      rpcPic->getPicYuvRec()->setBorderExtension( false );
309      bBufferIsAvailable = true;
310      break;
311    }
312  }
313
314  if ( !bBufferIsAvailable )
315  {
316    //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer.
317    m_iMaxRefPicNum++;
318    rpcPic = new TComPic();
319    m_cListPic.pushBack( rpcPic );
320  }
321  rpcPic->destroy();
322
323#if SVC_EXTENSION
324  if( m_layerId > 0 )
325  {
326    xSetSpatialEnhLayerFlag( vps, sps, pps, rpcPic );
327  }
328
329  rpcPic->create( vps, sps, pps, true, m_layerId);
330#else  //SVC_EXTENSION
331  rpcPic->create ( sps, pps, true);
332#endif //SVC_EXTENSION
333}
334
335Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic)
336{
337  if (!m_pcPic)
338  {
339    /* nothing to deblock */
340    return;
341  }
342
343  TComPic*   pcPic         = m_pcPic;
344
345  // Execute Deblock + Cleanup
346
347  m_cGopDecoder.filterPicture(pcPic);
348
349#if SVC_EXTENSION
350  if( this->getLayerDec(pcPic->getLayerId())->m_isOutputLayerFlag == false )
351  {
352    pcPic->setOutputMark( false );
353  }
354#endif
355
356  TComSlice::sortPicList( m_cListPic ); // sorting for application output
357  poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
358  rpcListPic          = &m_cListPic;
359  m_cCuDecoder.destroy();
360  m_bFirstSliceInPicture  = true;
361
362  return;
363}
364
365Void TDecTop::checkNoOutputPriorPics (TComList<TComPic*>* pcListPic)
366{
367  if (!pcListPic || !m_isNoOutputPriorPics)
368  {
369    return;
370  }
371
372  TComList<TComPic*>::iterator  iterPic   = pcListPic->begin();
373
374  while (iterPic != pcListPic->end())
375  {
376    TComPic* pcPicTmp = *(iterPic++);
377    if (m_lastPOCNoOutputPriorPics != pcPicTmp->getPOC())
378    {
379      pcPicTmp->setOutputMark(false);
380    }
381  }
382}
383
384Void TDecTop::xCreateLostPicture(Int iLostPoc)
385{
386  printf("\ninserting lost poc : %d\n",iLostPoc);
387  TComPic *cFillPic;
388#if SVC_EXTENSION
389  xGetNewPicBuffer(*(m_parameterSetManager.getFirstVPS()), *(m_parameterSetManager.getFirstSPS()), *(m_parameterSetManager.getFirstPPS()), cFillPic, 0);
390  cFillPic->getSlice(0)->initSlice( m_layerId );
391#else
392  xGetNewPicBuffer(*(m_parameterSetManager.getFirstSPS()), *(m_parameterSetManager.getFirstPPS()), cFillPic, 0);
393  cFillPic->getSlice(0)->initSlice();
394#endif
395 
396  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
397  Int closestPoc = 1000000;
398  while ( iterPic != m_cListPic.end())
399  {
400    TComPic * rpcPic = *(iterPic++);
401    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())
402    {
403      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
404    }
405  }
406  iterPic = m_cListPic.begin();
407  while ( iterPic != m_cListPic.end())
408  {
409    TComPic *rpcPic = *(iterPic++);
410    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
411    {
412      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
413      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
414      break;
415    }
416  }
417  cFillPic->setCurrSliceIdx(0);
418  for(Int ctuRsAddr=0; ctuRsAddr<cFillPic->getNumberOfCtusInFrame(); ctuRsAddr++)
419  {
420    cFillPic->getCtu(ctuRsAddr)->initCtu(cFillPic, ctuRsAddr);
421  }
422  cFillPic->getSlice(0)->setReferenced(true);
423  cFillPic->getSlice(0)->setPOC(iLostPoc);
424  xUpdatePreviousTid0POC(cFillPic->getSlice(0));
425  cFillPic->setReconMark(true);
426  cFillPic->setOutputMark(true);
427  if(m_pocRandomAccess == MAX_INT)
428  {
429    m_pocRandomAccess = iLostPoc;
430  }
431}
432
433
434Void TDecTop::xActivateParameterSets()
435{
436  if (m_bFirstSliceInPicture)
437  {
438    const TComPPS *pps = m_parameterSetManager.getPPS(m_apcSlicePilot->getPPSId()); // this is a temporary PPS object. Do not store this value
439    assert (pps != 0);
440
441#if SVC_EXTENSION
442    TComSPS *updateSPS = m_parameterSetManager.getSPS(pps->getSPSId());             // this is a temporary SPS object. Do not store this value
443#endif
444    const TComSPS *sps = m_parameterSetManager.getSPS(pps->getSPSId());             // this is a temporary SPS object. Do not store this value
445    assert (sps != 0);
446
447    m_parameterSetManager.clearSPSChangedFlag(sps->getSPSId());
448    m_parameterSetManager.clearPPSChangedFlag(pps->getPPSId());
449
450    if (false == m_parameterSetManager.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
451    {
452      printf ("Parameter set activation failed!");
453      assert (0);
454    }
455
456    xParsePrefixSEImessages();
457
458#if RExt__HIGH_BIT_DEPTH_SUPPORT==0
459    if (sps->getSpsRangeExtension().getExtendedPrecisionProcessingFlag() || sps->getBitDepth(CHANNEL_TYPE_LUMA)>12 || sps->getBitDepth(CHANNEL_TYPE_CHROMA)>12 )
460    {
461      printf("High bit depth support must be enabled at compile-time in order to decode this bitstream\n");
462      assert (0);
463      exit(1);
464    }
465#endif
466
467#if SVC_EXTENSION
468    // scaling list settings and checks
469    TComVPS *vps = m_parameterSetManager.getVPS(sps->getVPSId());
470    assert (vps != 0);
471
472    m_parameterSetManager.clearVPSChangedFlag(sps->getVPSId());   
473
474    if( sps->getInferScalingListFlag() )
475    {
476      UInt refLayerId = sps->getScalingListRefLayerId();
477      const TComSPS *refSps = m_ppcTDecTop[refLayerId]->getParameterSetManager()->getActiveSPS(); assert( refSps != NULL );
478
479      // 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
480      if( vps->getNonHEVCBaseLayerFlag() )
481      {
482        assert( refLayerId > 0 );
483      }
484
485      // 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
486      // 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
487      assert( refSps->getInferScalingListFlag() == false );
488
489      // 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,
490      // 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
491      assert( vps->getRecursiveRefLayerFlag( sps->getLayerId(), refLayerId ) == true );
492    }
493
494    if( pps->getInferScalingListFlag() )
495    {
496      UInt refLayerId = pps->getScalingListRefLayerId();
497      const TComPPS *refPps = m_ppcTDecTop[refLayerId]->getParameterSetManager()->getActivePPS(); assert( refPps != NULL );
498
499      // 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
500      if( vps->getNonHEVCBaseLayerFlag() )
501      {
502        assert( refLayerId > 0 );
503      }
504
505      // 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
506      // 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
507      assert( refPps->getInferScalingListFlag() == false );
508
509      // 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,
510      // 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
511      assert( vps->getRecursiveRefLayerFlag( pps->getLayerId(), refLayerId ) == true );
512    }
513
514#if AVC_BASE
515    if( vps->getNonHEVCBaseLayerFlag() )
516    {
517      TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
518      if( m_layerId > 0 && pBLPic->getPicYuvRec() == NULL )
519      {
520        UInt refLayerId = 0;
521
522        pBLPic->create( *vps, *sps, *pps, true, refLayerId);
523
524        // it is needed where the VPS is accessed through the slice
525        pBLPic->getSlice(0)->setVPS( vps );
526      }
527    }
528#endif
529
530    if( m_layerId > 0 )
531    {
532      // When not present sps_max_sub_layers_minus1 is inferred to be equal to vps_max_sub_layers_minus1.
533      updateSPS->setMaxTLayers( vps->getMaxTLayers() );
534
535      // When not present sps_temporal_id_nesting_flag is inferred to be equal to vps_temporal_id_nesting_flag
536      updateSPS->setTemporalIdNestingFlag( (sps->getMaxTLayers() > 1) ? vps->getTemporalNestingFlag() : true );
537
538      // 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,
539      // 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.
540      for(UInt i=0; i < sps->getMaxTLayers(); i++)
541      {
542        // to avoid compiler warning "array subscript is above array bounds"
543        assert( i < MAX_TLAYER );
544
545        // 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,
546        // due to MultiLayerExtSpsFlag being equal to 1, for a layer that refers to the SPS and has nuh_layer_id equal to currLayerId,
547        // 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,
548        // where layerIdx is equal to the value such that LayerSetLayerIdList[ TargetDecLayerSetIdx ][ layerIdx ] is equal to currLayerId.
549        if( sps->getMultiLayerExtSpsFlag() )
550        {
551          updateSPS->setMaxDecPicBuffering( vps->getMaxVpsDecPicBufferingMinus1( m_commonDecoderParams->getTargetOutputLayerSetIdx(), vps->getLayerIdcForOls( vps->getOutputLayerSetIdx( m_commonDecoderParams->getTargetOutputLayerSetIdx() ), m_layerId ), i) + 1, i);
552        }
553
554        // 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.
555        assert( sps->getMaxDecPicBuffering(i) <= vps->getMaxDecPicBuffering(i) );     
556      }
557
558      UInt layerIdx = vps->getLayerIdxInVps( m_layerId );
559
560      if( vps->getBaseLayerPSCompatibilityFlag(layerIdx) )
561      {
562        const RepFormat* repFormat = vps->getVpsRepFormat(vps->getVpsRepFormatIdx(layerIdx));
563
564        assert( pps->getLayerId() == 0 );
565        assert( sps->getLayerId() == 0 );
566        assert( repFormat->getChromaFormatVpsIdc() == sps->getChromaFormatIdc() );
567        assert( repFormat->getSeparateColourPlaneVpsFlag() == 0 );
568        assert( repFormat->getPicHeightVpsInLumaSamples() == sps->getPicHeightInLumaSamples() );
569        assert( repFormat->getPicWidthVpsInLumaSamples()  == sps->getPicWidthInLumaSamples() );
570        assert( repFormat->getBitDepthVpsLuma()   == sps->getBitDepth(CHANNEL_TYPE_LUMA) );
571        assert( repFormat->getBitDepthVpsChroma() == sps->getBitDepth(CHANNEL_TYPE_CHROMA) );
572        assert( repFormat->getConformanceWindowVps().getWindowLeftOffset()   == sps->getConformanceWindow().getWindowLeftOffset() );
573        assert( repFormat->getConformanceWindowVps().getWindowRightOffset()  == sps->getConformanceWindow().getWindowRightOffset() );
574        assert( repFormat->getConformanceWindowVps().getWindowTopOffset()    == sps->getConformanceWindow().getWindowTopOffset() );
575        assert( repFormat->getConformanceWindowVps().getWindowBottomOffset() == sps->getConformanceWindow().getWindowBottomOffset() );
576      }   
577    }
578
579    //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
580    UInt layerIdx = vps->getLayerIdxInVps(m_apcSlicePilot->getLayerId());
581
582    if ( vps->getVpsExtensionFlag() == 1 && (m_apcSlicePilot->getLayerId() == 0 || sps->getV1CompatibleSPSFlag() == 1) )
583    {
584      assert( sps->getPicWidthInLumaSamples()        <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx) )->getPicWidthVpsInLumaSamples() );
585      assert( sps->getPicHeightInLumaSamples()       <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx) )->getPicHeightVpsInLumaSamples() );
586      assert( sps->getChromaFormatIdc()              <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx) )->getChromaFormatVpsIdc() );
587      assert( sps->getBitDepth(CHANNEL_TYPE_LUMA)    <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx) )->getBitDepthVpsLuma() );
588      assert( sps->getBitDepth(CHANNEL_TYPE_CHROMA)  <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx) )->getBitDepthVpsChroma() );
589    }
590    else if ( vps->getVpsExtensionFlag() == 1 )
591    {
592      assert( vps->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(layerIdx))->getPicWidthVpsInLumaSamples()  <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx))->getPicWidthVpsInLumaSamples());
593      assert( vps->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(layerIdx))->getPicHeightVpsInLumaSamples() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx))->getPicHeightVpsInLumaSamples());
594      assert( vps->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(layerIdx))->getChromaFormatVpsIdc()        <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx))->getChromaFormatVpsIdc());
595      assert( vps->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(layerIdx))->getBitDepthVpsLuma()           <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx))->getBitDepthVpsLuma());
596      assert( vps->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(layerIdx))->getBitDepthVpsChroma()         <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx))->getBitDepthVpsChroma());
597    }
598#endif //SVC_EXTENSION
599
600    // NOTE: globals were set up here originally. You can now use:
601    // g_uiMaxCUDepth = sps->getMaxTotalCUDepth();
602    // g_uiAddCUDepth = sps->getMaxTotalCUDepth() - sps->getLog2DiffMaxMinCodingBlockSize()
603
604    //  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.
605#if SVC_EXTENSION
606    xGetNewPicBuffer( *(vps), *(sps), *(pps), m_pcPic, m_apcSlicePilot->getTLayer() );
607#else
608    xGetNewPicBuffer (*(sps), *(pps), m_pcPic, m_apcSlicePilot->getTLayer());
609#endif
610
611#if ALIGNED_BUMPING
612    m_apcSlicePilot->checkLeadingPictureRestrictions(m_cListPic);
613#else
614    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
615#endif
616
617    // make the slice-pilot a real slice, and set up the slice-pilot for the next slice
618    assert(m_pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
619    m_apcSlicePilot = m_pcPic->getPicSym()->swapSliceObject(m_apcSlicePilot, m_uiSliceIdx);
620
621    // we now have a real slice:
622    TComSlice *pSlice = m_pcPic->getSlice(m_uiSliceIdx);
623
624    // Update the PPS and SPS pointers with the ones of the picture.
625    pps=pSlice->getPPS();
626    sps=pSlice->getSPS();
627
628    // Initialise the various objects for the new set of settings
629#if SVC_EXTENSION
630    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) );
631#else
632    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) );
633#endif
634    m_cLoopFilter.create( sps->getMaxTotalCUDepth() );
635    m_cPrediction.initTempBuff(sps->getChromaFormatIdc());
636
637
638    Bool isField = false;
639    Bool isTopField = false;
640
641    if(!m_SEIs.empty())
642    {
643      // Check if any new Picture Timing SEI has arrived
644      SEIMessages pictureTimingSEIs = getSeisByType(m_SEIs, SEI::PICTURE_TIMING);
645      if (pictureTimingSEIs.size()>0)
646      {
647        SEIPictureTiming* pictureTiming = (SEIPictureTiming*) *(pictureTimingSEIs.begin());
648        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);
649        isTopField = (pictureTiming->m_picStruct == 1) || (pictureTiming->m_picStruct == 9) || (pictureTiming->m_picStruct == 11);
650      }
651     
652#if Q0189_TMVP_CONSTRAINTS
653      // Check if any new temporal motion vector prediction constraints SEI has arrived
654      SEIMessages seiTMVPConstrainsList = extractSeisByType (m_SEIs, SEI::TMVP_CONSTRAINTS);
655      if (seiTMVPConstrainsList.size() > 0)
656      {
657        assert ( m_pcPic->getTLayer() == 0 );  //this SEI can present only for AU with Tid equal to 0
658        SEITMVPConstrains* tmvpConstraintSEI = (SEITMVPConstrains*) *(seiTMVPConstrainsList.begin());
659        if ( tmvpConstraintSEI->prev_pics_not_used_flag == 1 )
660        {
661          //update all pics in the DPB such that they cannot be used for TMPV ref
662          TComList<TComPic*>::iterator  iterRefPic = m_cListPic.begin(); 
663          while( iterRefPic != m_cListPic.end() )
664          {
665            TComPic *refPic = *iterRefPic;
666            if( ( refPic->getLayerId() == m_pcPic->getLayerId() ) && refPic->getReconMark() )
667            {
668              for(Int i = refPic->getNumAllocatedSlice()-1; i >= 0; i--)
669              {
670                TComSlice *refSlice = refPic->getSlice(i);
671                refSlice->setAvailableForTMVPRefFlag( false );
672              }
673            }
674            iterRefPic++;
675          }
676        }
677      }
678#endif
679    }
680
681    //Set Field/Frame coding mode
682    m_pcPic->setField(isField);
683    m_pcPic->setTopField(isTopField);
684
685    // transfer any SEI messages that have been received to the picture
686    m_pcPic->setSEIs(m_SEIs);
687    m_SEIs.clear();
688
689    // Recursive structure
690#if SVC_EXTENSION
691    m_cCuDecoder.create ( sps->getMaxTotalCUDepth(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), pSlice->getChromaFormatIdc() );
692    m_cCuDecoder.init   ( m_ppcTDecTop, &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction, m_layerId );
693#else
694    m_cCuDecoder.create ( sps->getMaxTotalCUDepth(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getChromaFormatIdc() );
695    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
696#endif
697    m_cTrQuant.init     ( sps->getMaxTrSize() );
698
699    m_cSliceDecoder.create();
700  }
701  else
702  {
703    // make the slice-pilot a real slice, and set up the slice-pilot for the next slice
704    m_pcPic->allocateNewSlice();
705    assert(m_pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
706    m_apcSlicePilot = m_pcPic->getPicSym()->swapSliceObject(m_apcSlicePilot, m_uiSliceIdx);
707
708    TComSlice *pSlice = m_pcPic->getSlice(m_uiSliceIdx); // we now have a real slice.
709
710    const TComSPS *sps = pSlice->getSPS();
711    const TComPPS *pps = pSlice->getPPS();
712
713    // check that the current active PPS has not changed...
714    if (m_parameterSetManager.getSPSChangedFlag(sps->getSPSId()) )
715    {
716      printf("Error - a new SPS has been decoded while processing a picture\n");
717      exit(1);
718    }
719    if (m_parameterSetManager.getPPSChangedFlag(pps->getPPSId()) )
720    {
721      printf("Error - a new PPS has been decoded while processing a picture\n");
722      exit(1);
723    }
724
725    xParsePrefixSEImessages();
726
727    // Check if any new SEI has arrived
728     if(!m_SEIs.empty())
729     {
730       // Currently only decoding Unit SEI message occurring between VCL NALUs copied
731       SEIMessages &picSEI = m_pcPic->getSEIs();
732       SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
733       picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
734       deleteSEIs(m_SEIs);
735     }
736  }
737}
738
739
740Void TDecTop::xParsePrefixSEIsForUnknownVCLNal()
741{
742  while (!m_prefixSEINALUs.empty())
743  {
744    // do nothing?
745    printf("Discarding Prefix SEI associated with unknown VCL NAL unit.\n");
746    delete m_prefixSEINALUs.front();
747  }
748  // TODO: discard following suffix SEIs as well?
749}
750
751
752Void TDecTop::xParsePrefixSEImessages()
753{
754#if SVC_EXTENSION
755    if (m_prevSliceSkipped) // No need to decode SEI messages of a skipped access unit
756    {
757      return;
758    }
759#endif
760
761  while (!m_prefixSEINALUs.empty())
762  {
763    InputNALUnit &nalu=*m_prefixSEINALUs.front();
764#if LAYERS_NOT_PRESENT_SEI
765    m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_SEIs, nalu.m_nalUnitType, m_parameterSetManager.getActiveVPS(), m_parameterSetManager.getActiveSPS(), m_pDecodedSEIOutputStream );
766#else
767    m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_SEIs, nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS(), m_pDecodedSEIOutputStream );
768#endif
769    delete m_prefixSEINALUs.front();
770    m_prefixSEINALUs.pop_front();
771  }
772}
773
774#if SVC_EXTENSION
775Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC )
776#else
777Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
778#endif
779{
780#if SVC_EXTENSION
781  m_apcSlicePilot->initSlice( nalu.m_nuhLayerId );
782  m_apcSlicePilot->setTLayer( nalu.m_temporalId );
783#else //SVC_EXTENSION
784  m_apcSlicePilot->initSlice(); // the slice pilot is an object to prepare for a new slice
785                                // it is not associated with picture, sps or pps structures.
786#endif
787
788  if (m_bFirstSliceInPicture)
789  {
790    m_uiSliceIdx = 0;
791  }
792  else
793  {
794    m_apcSlicePilot->copySliceInfo( m_pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
795  }
796  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
797
798  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
799
800  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
801                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
802                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
803                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
804                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
805  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
806  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
807  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
808
809#if ENC_DEC_TRACE
810  const UInt64 originalSymbolCount = g_nSymbolCounter;
811#endif
812
813  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManager, m_prevTid0POC);
814
815#if SVC_EXTENSION
816  const TComPPS *pps = m_parameterSetManager.getPPS(m_apcSlicePilot->getPPSId());
817  assert (pps != 0);
818  const TComSPS *sps = m_parameterSetManager.getSPS(pps->getSPSId());
819  assert (sps != 0);
820  const TComVPS *vps = m_parameterSetManager.getVPS(sps->getVPSId());
821  assert (vps != 0);
822
823  // Following check should go wherever the VPS is activated
824  if( !vps->getBaseLayerAvailableFlag() )
825  {
826    assert( nalu.m_nuhLayerId != 0 );
827    assert( vps->getNumAddLayerSets() > 0 );
828
829    if( m_commonDecoderParams->getTargetOutputLayerSetIdx() >= 0 )
830    {
831      UInt layerIdx = vps->getOutputLayerSetIdx( getCommonDecoderParams()->getTargetOutputLayerSetIdx() );
832      assert( layerIdx > vps->getVpsNumLayerSetsMinus1() );
833    }
834  } 
835
836  setRefLayerParams(vps);
837  m_apcSlicePilot->setNumMotionPredRefLayers(m_numMotionPredRefLayers);
838#endif
839
840  // set POC for dependent slices in skipped pictures
841  if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped)
842  {
843    m_apcSlicePilot->setPOC(m_skippedPOC);
844  }
845
846  xUpdatePreviousTid0POC(m_apcSlicePilot);
847
848  m_apcSlicePilot->setAssociatedIRAPPOC(m_pocCRA);
849  m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType);
850
851  //For inference of NoOutputOfPriorPicsFlag
852  if (m_apcSlicePilot->getRapPicFlag())
853  {
854    if ((m_apcSlicePilot->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_apcSlicePilot->getNalUnitType() <= NAL_UNIT_CODED_SLICE_IDR_N_LP) || 
855        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_bFirstSliceInSequence) ||
856        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getHandleCraAsBlaFlag()))
857    {
858      m_apcSlicePilot->setNoRaslOutputFlag(true);
859    }
860    //the inference for NoOutputPriorPicsFlag
861    if (!m_bFirstSliceInBitstream && m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag())
862    {
863      if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
864      {
865        m_apcSlicePilot->setNoOutputPriorPicsFlag(true);
866      }
867    }
868    else
869    {
870      m_apcSlicePilot->setNoOutputPriorPicsFlag(false);
871    }
872
873    if(m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
874    {
875      m_craNoRaslOutputFlag = m_apcSlicePilot->getNoRaslOutputFlag();
876    }
877  }
878  if (m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoOutputPriorPicsFlag())
879  {
880    m_lastPOCNoOutputPriorPics = m_apcSlicePilot->getPOC();
881    m_isNoOutputPriorPics = true;
882  }
883  else
884  {
885    m_isNoOutputPriorPics = false;
886  }
887
888  //For inference of PicOutputFlag
889  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R)
890  {
891    if ( m_craNoRaslOutputFlag )
892    {
893      m_apcSlicePilot->setPicOutputFlag(false);
894    }
895  }
896
897  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_craNoRaslOutputFlag) //Reset POC MSB when CRA has NoRaslOutputFlag equal to 1
898  {
899#if !SVC_EXTENSION
900    TComPPS *pps = m_parameterSetManager.getPPS(m_apcSlicePilot->getPPSId());
901    assert (pps != 0);
902    TComSPS *sps = m_parameterSetManager.getSPS(pps->getSPSId());
903    assert (sps != 0);
904#endif
905    Int iMaxPOClsb = 1 << sps->getBitsForPOC();
906    m_apcSlicePilot->setPOC( m_apcSlicePilot->getPOC() & (iMaxPOClsb - 1) );
907    xUpdatePreviousTid0POC(m_apcSlicePilot);
908  }
909
910  // Skip pictures due to random access
911
912  if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
913  {
914    m_prevSliceSkipped = true;
915    m_skippedPOC = m_apcSlicePilot->getPOC();
916    return false;
917  }
918  // Skip TFD pictures associated with BLA/BLANT pictures
919  if (isSkipPictureForBLA(iPOCLastDisplay))
920  {
921    m_prevSliceSkipped = true;
922    m_skippedPOC = m_apcSlicePilot->getPOC();
923    return false;
924  }
925
926  // clear previous slice skipped flag
927  m_prevSliceSkipped = false;
928
929  // exit when a new picture is found
930#if SVC_EXTENSION
931  bNewPOC = m_apcSlicePilot->getPOC() != m_prevPOC || ( m_apcSlicePilot->getFirstSliceInPic() && m_parseIdc == -1 );
932
933#if NO_CLRAS_OUTPUT_FLAG
934  if( m_layerId == m_smallestLayerId && m_apcSlicePilot->getRapPicFlag() )
935  {
936    if( m_bFirstSliceInSequence )
937    {
938      setNoClrasOutputFlag(true);
939    }
940    else if( m_lastPicHasEos )
941    {
942      setNoClrasOutputFlag(true);
943    }
944    else if( m_apcSlicePilot->getBlaPicFlag() )
945    {
946      setNoClrasOutputFlag(true);
947    }
948    else if( m_apcSlicePilot->getIdrPicFlag() && m_apcSlicePilot->getCrossLayerBLAFlag() )
949    {
950      setNoClrasOutputFlag(true);
951    }
952    else
953    {
954      setNoClrasOutputFlag(false);
955    }     
956  }
957  else
958  {
959    setNoClrasOutputFlag(false);
960  }
961
962  m_apcSlicePilot->decodingRefreshMarking( m_cListPic, m_noClrasOutputFlag, m_smallestLayerId );
963#endif
964
965  // Derive the value of NoOutputOfPriorPicsFlag
966  if( bNewPOC || m_layerId!=m_uiPrevLayerId )   // i.e. new coded picture
967  {
968    if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getNoRaslOutputFlag() )
969    {
970      this->setNoOutputPriorPicsFlag( true );
971    }
972    else if( m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag() )
973    {
974      this->setNoOutputPriorPicsFlag( m_apcSlicePilot->getNoOutputPriorPicsFlag() );
975    }
976    else
977    {
978      if( this->m_ppcTDecTop[0]->getNoClrasOutputFlag() )
979      {
980        this->setNoOutputPriorPicsFlag( true );
981      }
982    }
983  }
984
985#if SVC_POC
986  if( m_parseIdc != -1 ) // Second pass for a POC resetting picture
987  {
988    m_parseIdc++; // Proceed to POC decoding and RPS derivation
989  }
990 
991  if( m_parseIdc == 2 )
992  {
993    bNewPOC = false;
994  }
995
996  if( (bNewPOC || m_layerId!=m_uiPrevLayerId) && (m_parseIdc == -1) ) // Will be true at the first pass
997  {
998  //if (bNewPOC || m_layerId!=m_uiPrevLayerId)
999  // Check if new reset period has started - this is needed just so that the SHM decoder which calls slice header decoding twice
1000  // does not invoke the output twice
1001  //if( m_lastPocPeriodId[m_apcSlicePilot->getLayerId()] == m_apcSlicePilot->getPocResetPeriodId() )
1002    // Update CurrAU marking
1003    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
1004    {
1005      // New access unit; reset all variables related to POC reset restrictions
1006      resetPocRestrictionCheckParameters();
1007
1008      markAllPicsAsNoCurrAu(vps);
1009
1010      for( UInt i = 0; i < MAX_LAYERS; i++ )
1011      {
1012        m_ppcTDecTop[vps->getLayerIdInNuh(i)]->m_pocDecrementedInDPBFlag = false;
1013      }
1014    }
1015
1016    m_pocResettingFlag = false;
1017
1018    if( m_apcSlicePilot->getPocResetIdc() != 0 )
1019    {
1020      if( vps->getVpsPocLsbAlignedFlag() )
1021      {
1022        m_pocResettingFlag = true;
1023      }
1024      else if (m_pocDecrementedInDPBFlag)
1025      {
1026        m_pocResettingFlag = false;
1027      }
1028      else
1029      {
1030        m_pocResettingFlag = true;
1031      }
1032    }
1033
1034    if( m_apcSlicePilot->getPocResetIdc() && m_apcSlicePilot->getSliceIdx() == 0 )
1035    {
1036      Int pocResetPeriodId = m_apcSlicePilot->getPocResetPeriodId();
1037      if ( m_apcSlicePilot->getPocResetIdc() == 1 || m_apcSlicePilot->getPocResetIdc() == 2 ||
1038        ( m_apcSlicePilot->getPocResetIdc() == 3 && pocResetPeriodId != getLastPocPeriodId() ) )
1039      {
1040        setLastPocPeriodId(pocResetPeriodId);
1041        m_parseIdc = 0;
1042      }
1043
1044      // Check if the POC Reset period ID matches with the Reset Period ID
1045      if( pocResetPeriodId == m_crossLayerPocResetPeriodId )
1046      {
1047        // If matching, and current poc_reset_idc = 3, then the values should match
1048        if( m_apcSlicePilot->getPocResetIdc() == 3 )
1049        {
1050          assert( ( m_apcSlicePilot->getFullPocResetFlag() == false && m_crossLayerPocResetIdc == 1 ) ||
1051                  ( m_apcSlicePilot->getFullPocResetFlag() == true  && m_crossLayerPocResetIdc == 2 ) );
1052        }
1053      }
1054      else
1055      {
1056        // This is the first picture of a POC resetting access unit
1057        m_crossLayerPocResetPeriodId = pocResetPeriodId;
1058        if( m_apcSlicePilot->getPocResetIdc() == 1 || m_apcSlicePilot->getPocResetIdc() == 2 )
1059        {
1060          m_crossLayerPocResetIdc = m_apcSlicePilot->getPocResetIdc();
1061        }
1062        else
1063        { // poc_reset_idc = 3
1064          // In this case, the entire POC resetting access unit has been lost.
1065          // Need more checking to ensure poc_reset_idc = 3 works.
1066          assert ( 0 );
1067        }
1068      }
1069    }
1070    else
1071    {
1072      m_parseIdc = 3; // Proceed to decoding POC and RPS
1073    }
1074  }
1075#endif
1076
1077#if ALIGNED_BUMPING
1078  UInt affectedLayerList[MAX_LAYERS];
1079  Int  numAffectedLayers;
1080
1081  affectedLayerList[0] = m_apcSlicePilot->getLayerId();
1082  numAffectedLayers = 1;
1083
1084  if( vps->getVpsPocLsbAlignedFlag() )
1085  {
1086    for( UInt j = 0; j < vps->getNumPredictedLayers(m_apcSlicePilot->getLayerId()); j++ )
1087    {
1088      affectedLayerList[j + 1] = vps->getPredictedLayerId(m_apcSlicePilot->getLayerId(), j);
1089    }
1090    numAffectedLayers = vps->getNumPredictedLayers(m_apcSlicePilot->getLayerId()) + 1;
1091  }
1092
1093  if( m_parseIdc == 1 && m_pocResettingFlag )
1094  {
1095    // Invoke output of pictures if the current picture is a POC reset picture
1096    bNewPOC = true;
1097    /* Include reset of all POCs in the layer */
1098
1099    // This operation would do the following:
1100    // 1. Update the other picture in the DPB. This should be done only for the first slice of the picture.
1101    // 2. Update the value of m_pocCRA.
1102    // 3. Reset the POC values at the decoder for the current picture to be zero - will be done later
1103    // 4. update value of POCLastDisplay
1104
1105    //Do the reset stuff here
1106    Int maxPocLsb = 1 << sps->getBitsForPOC();
1107    Int pocLsbVal;
1108    if( m_apcSlicePilot->getPocResetIdc() == 3 )
1109    {
1110      pocLsbVal = m_apcSlicePilot->getPocLsbVal() ;
1111    }
1112    else
1113    {
1114      pocLsbVal = (m_apcSlicePilot->getPOC() % maxPocLsb);
1115    }
1116
1117    Int pocMsbDelta = 0;
1118    if( m_apcSlicePilot->getPocMsbValPresentFlag() ) 
1119    {
1120      pocMsbDelta = m_apcSlicePilot->getPocMsbVal() * maxPocLsb;
1121    }
1122    else
1123    {
1124      //This MSB derivation can be made into one function. Item to do next.
1125      Int prevPoc     = this->getPrevPicOrderCnt();
1126      Int prevPocLsb  = prevPoc & (maxPocLsb - 1);
1127      Int prevPocMsb  = prevPoc - prevPocLsb;
1128
1129      pocMsbDelta = m_apcSlicePilot->getCurrMsb( pocLsbVal, prevPocLsb, prevPocMsb, maxPocLsb );
1130    }
1131
1132    Int pocLsbDelta;
1133    if( m_apcSlicePilot->getPocResetIdc() == 2 ||  ( m_apcSlicePilot->getPocResetIdc() == 3 && m_apcSlicePilot->getFullPocResetFlag() ))
1134    {
1135      pocLsbDelta = pocLsbVal;
1136    }
1137    else
1138    {
1139      pocLsbDelta = 0; 
1140    }
1141
1142    Int deltaPocVal  =  pocMsbDelta + pocLsbDelta;
1143
1144    for( UInt layerIdx = 0; layerIdx < numAffectedLayers; layerIdx++ )
1145    {
1146      if (!m_ppcTDecTop[affectedLayerList[layerIdx]]->m_pocDecrementedInDPBFlag)
1147      {
1148        m_ppcTDecTop[affectedLayerList[layerIdx]]->m_pocDecrementedInDPBFlag = true;
1149        TComList<TComPic*>::iterator  iterPic = m_ppcTDecTop[affectedLayerList[layerIdx]]->getListPic()->begin();
1150
1151        while (iterPic != m_ppcTDecTop[affectedLayerList[layerIdx]]->getListPic()->end())
1152        {
1153          TComPic *dpbPic = *iterPic;
1154          // Check if the picture pointed to by iterPic is either used for reference or
1155          // needed for output, are in the same layer, and not the current picture.
1156          assert(dpbPic->getLayerId() == affectedLayerList[layerIdx]);
1157
1158          if( (dpbPic->getReconMark()) && (dpbPic->getPicSym()->getSlice(0)->getPicOutputFlag()) )
1159          {
1160            for(Int i = dpbPic->getNumAllocatedSlice()-1; i >= 0; i--)
1161            {
1162
1163              TComSlice *slice = dpbPic->getSlice(i);
1164              TComReferencePictureSet *rps = slice->getLocalRPS();
1165              slice->setPOC( slice->getPOC() - deltaPocVal );
1166
1167              // Also adjust the POC value stored in the RPS of each such slice
1168              for(Int j = rps->getNumberOfPictures(); j >= 0; j--)
1169              {
1170                rps->setPOC( j, rps->getPOC(j) - deltaPocVal );
1171              }
1172
1173              slice->setRPS(rps);
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 SVC_EXTENSION
1969      m_isLastNALWasEos = false;   
1970#endif
1971      return false;
1972
1973    case NAL_UNIT_SPS:
1974      xDecodeSPS(nalu.getBitstream().getFifo());
1975      return false;
1976
1977    case NAL_UNIT_PPS:
1978#if CGS_3D_ASYMLUT
1979      xDecodePPS( nalu.getBitstream().getFifo(), &m_c3DAsymLUTPPS );
1980#else
1981      xDecodePPS(nalu.getBitstream().getFifo());
1982#endif
1983      return false;
1984
1985    case NAL_UNIT_PREFIX_SEI:
1986      // Buffer up prefix SEI messages until SPS of associated VCL is known.
1987      m_prefixSEINALUs.push_back(new InputNALUnit(nalu));
1988      return false;
1989
1990    case NAL_UNIT_SUFFIX_SEI:
1991#if SVC_EXTENSION
1992      if( nalu.m_nalUnitType == NAL_UNIT_SUFFIX_SEI )
1993      {
1994        assert( m_isLastNALWasEos == false );
1995      }
1996#endif
1997      if (m_pcPic)
1998      {
1999#if SVC_EXTENSION
2000        m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_pcPic->getSEIs(), nalu.m_nalUnitType, m_parameterSetManager.getActiveVPS(), m_parameterSetManager.getActiveSPS(), m_pDecodedSEIOutputStream );
2001#else
2002        m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_pcPic->getSEIs(), nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS(), m_pDecodedSEIOutputStream );
2003#endif
2004      }
2005      else
2006      {
2007        printf ("Note: received suffix SEI but no picture currently active.\n");
2008      }
2009      return false;
2010
2011    case NAL_UNIT_CODED_SLICE_TRAIL_R:
2012    case NAL_UNIT_CODED_SLICE_TRAIL_N:
2013    case NAL_UNIT_CODED_SLICE_TSA_R:
2014    case NAL_UNIT_CODED_SLICE_TSA_N:
2015    case NAL_UNIT_CODED_SLICE_STSA_R:
2016    case NAL_UNIT_CODED_SLICE_STSA_N:
2017    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
2018    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
2019    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
2020    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
2021    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
2022    case NAL_UNIT_CODED_SLICE_CRA:
2023    case NAL_UNIT_CODED_SLICE_RADL_N:
2024    case NAL_UNIT_CODED_SLICE_RADL_R:
2025    case NAL_UNIT_CODED_SLICE_RASL_N:
2026    case NAL_UNIT_CODED_SLICE_RASL_R:
2027#if SVC_EXTENSION
2028      if( nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_N ||
2029          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_N ||
2030          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_N ||
2031          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
2032          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N )
2033      {
2034        assert( m_isLastNALWasEos == false );
2035      }
2036      else
2037      {
2038        m_isLastNALWasEos = false;
2039      }
2040
2041      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, curLayerId, bNewPOC);
2042#else
2043      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
2044#endif
2045      break;
2046
2047    case NAL_UNIT_EOS:
2048#if SVC_EXTENSION
2049      assert( m_isLastNALWasEos == false );
2050
2051      m_isLastNALWasEos = true;
2052      m_lastPicHasEos = true;
2053#endif
2054      m_associatedIRAPType = NAL_UNIT_INVALID;
2055      m_pocCRA = 0;
2056      m_pocRandomAccess = MAX_INT;
2057      m_prevPOC = MAX_INT;
2058      m_prevSliceSkipped = false;
2059      m_skippedPOC = 0;
2060      return false;
2061
2062    case NAL_UNIT_ACCESS_UNIT_DELIMITER:
2063      {
2064        AUDReader audReader;
2065        UInt picType;
2066        audReader.parseAccessUnitDelimiter(&(nalu.getBitstream()),picType);
2067        printf ("Note: found NAL_UNIT_ACCESS_UNIT_DELIMITER\n");
2068        return false;
2069      }
2070
2071    case NAL_UNIT_EOB:
2072#if SVC_EXTENSION
2073      //Check layer id of the nalu. if it is not 0, give a warning message.
2074      if (nalu.m_nuhLayerId > 0)
2075      {
2076        printf( "\n\nThis bitstream is ended with EOB NALU that has layer id greater than 0\n" );
2077      }
2078#endif
2079      return false;
2080
2081    case NAL_UNIT_FILLER_DATA:
2082      {
2083        FDReader fdReader;
2084        UInt size;
2085        fdReader.parseFillerData(&(nalu.getBitstream()),size);
2086        printf ("Note: found NAL_UNIT_FILLER_DATA with %u bytes payload.\n", size);
2087#if SVC_EXTENSION
2088        assert( m_isLastNALWasEos == false );
2089#endif
2090        return false;
2091      }
2092
2093    case NAL_UNIT_RESERVED_VCL_N10:
2094    case NAL_UNIT_RESERVED_VCL_R11:
2095    case NAL_UNIT_RESERVED_VCL_N12:
2096    case NAL_UNIT_RESERVED_VCL_R13:
2097    case NAL_UNIT_RESERVED_VCL_N14:
2098    case NAL_UNIT_RESERVED_VCL_R15:
2099
2100    case NAL_UNIT_RESERVED_IRAP_VCL22:
2101    case NAL_UNIT_RESERVED_IRAP_VCL23:
2102
2103    case NAL_UNIT_RESERVED_VCL24:
2104    case NAL_UNIT_RESERVED_VCL25:
2105    case NAL_UNIT_RESERVED_VCL26:
2106    case NAL_UNIT_RESERVED_VCL27:
2107    case NAL_UNIT_RESERVED_VCL28:
2108    case NAL_UNIT_RESERVED_VCL29:
2109    case NAL_UNIT_RESERVED_VCL30:
2110    case NAL_UNIT_RESERVED_VCL31:
2111      printf ("Note: found reserved VCL NAL unit.\n");
2112      xParsePrefixSEIsForUnknownVCLNal();
2113      return false;
2114
2115    case NAL_UNIT_RESERVED_NVCL41:
2116    case NAL_UNIT_RESERVED_NVCL42:
2117    case NAL_UNIT_RESERVED_NVCL43:
2118    case NAL_UNIT_RESERVED_NVCL44:
2119    case NAL_UNIT_RESERVED_NVCL45:
2120    case NAL_UNIT_RESERVED_NVCL46:
2121    case NAL_UNIT_RESERVED_NVCL47:
2122      printf ("Note: found reserved NAL unit.\n");
2123      return false;
2124    case NAL_UNIT_UNSPECIFIED_48:
2125    case NAL_UNIT_UNSPECIFIED_49:
2126    case NAL_UNIT_UNSPECIFIED_50:
2127    case NAL_UNIT_UNSPECIFIED_51:
2128    case NAL_UNIT_UNSPECIFIED_52:
2129    case NAL_UNIT_UNSPECIFIED_53:
2130    case NAL_UNIT_UNSPECIFIED_54:
2131    case NAL_UNIT_UNSPECIFIED_55:
2132    case NAL_UNIT_UNSPECIFIED_56:
2133    case NAL_UNIT_UNSPECIFIED_57:
2134    case NAL_UNIT_UNSPECIFIED_58:
2135    case NAL_UNIT_UNSPECIFIED_59:
2136    case NAL_UNIT_UNSPECIFIED_60:
2137    case NAL_UNIT_UNSPECIFIED_61:
2138    case NAL_UNIT_UNSPECIFIED_62:
2139    case NAL_UNIT_UNSPECIFIED_63:
2140      printf ("Note: found unspecified NAL unit.\n");
2141      return false;
2142    default:
2143      assert (0);
2144      break;
2145  }
2146
2147  return false;
2148}
2149
2150/** Function for checking if picture should be skipped because of association with a previous BLA picture
2151 * \param iPOCLastDisplay POC of last picture displayed
2152 * \returns true if the picture should be skipped
2153 * This function skips all TFD pictures that follow a BLA picture
2154 * in decoding order and precede it in output order.
2155 */
2156Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
2157{
2158  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) &&
2159       m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
2160  {
2161    iPOCLastDisplay++;
2162    return true;
2163  }
2164  return false;
2165}
2166
2167/** Function for checking if picture should be skipped because of random access
2168 * \param iSkipFrame skip frame counter
2169 * \param iPOCLastDisplay POC of last picture displayed
2170 * \returns true if the picture shold be skipped in the random access.
2171 * This function checks the skipping of pictures in the case of -s option random access.
2172 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
2173 * It also checks the type of Nal unit type at the random access point.
2174 * 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.
2175 * If the random access point is IDR all pictures after the random access point are decoded.
2176 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
2177 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
2178 * access point there is no guarantee that the decoder will not crash.
2179 */
2180Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
2181{
2182  if (iSkipFrame)
2183  {
2184    iSkipFrame--;   // decrement the counter
2185    return true;
2186  }
2187  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
2188  {
2189    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
2190        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
2191        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
2192        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
2193    {
2194      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
2195      m_pocRandomAccess = m_apcSlicePilot->getPOC();
2196    }
2197    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
2198    {
2199      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
2200    }
2201    else
2202    {
2203      if(!m_warningMessageSkipPicture)
2204      {
2205        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
2206        m_warningMessageSkipPicture = true;
2207      }
2208      return true;
2209    }
2210  }
2211  // skip the reordered pictures, if necessary
2212  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))
2213  {
2214    iPOCLastDisplay++;
2215    return true;
2216  }
2217  // if we reach here, then the picture is not skipped.
2218  return false;
2219}
2220
2221#if SVC_EXTENSION
2222Void TDecTop::xInitILRP(TComSlice *slice)
2223{
2224  const TComVPS* vps  = slice->getVPS();
2225  const TComSPS* sps  = slice->getSPS();
2226
2227  if( m_layerId > 0 )
2228  {
2229    if (m_cIlpPic[0] == NULL)
2230    {
2231      for (Int j=0; j < m_numDirectRefLayers; j++)
2232      {
2233        m_cIlpPic[j] = new  TComPic;
2234
2235        m_cIlpPic[j]->create(*vps, *sps, *slice->getPPS(), true, m_layerId);
2236
2237        for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCtusInFrame(); i++)
2238        {
2239          m_cIlpPic[j]->getPicSym()->getCtu(i)->initCtu(m_cIlpPic[j], i);
2240        }
2241      }
2242    }
2243  }
2244}
2245
2246TDecTop* TDecTop::getRefLayerDec( UInt refLayerIdx )
2247{
2248  const TComVPS* vps = m_parameterSetManager.getActiveVPS();
2249  if( vps->getNumDirectRefLayers( m_layerId ) <= 0 )
2250  {
2251    return (TDecTop *)getLayerDec( 0 );
2252  }
2253 
2254  return (TDecTop *)getLayerDec( vps->getRefLayerId( m_layerId, refLayerIdx ) );
2255}
2256
2257Void TDecTop::setRefLayerParams( const TComVPS* vps )
2258{
2259  for(UInt layerIdx = 0; layerIdx < m_numLayer; layerIdx++)
2260  {
2261    TDecTop *decTop = (TDecTop *)getLayerDec(vps->getLayerIdInNuh(layerIdx));
2262    decTop->setNumSamplePredRefLayers(0);
2263    decTop->setNumMotionPredRefLayers(0);
2264    decTop->setNumDirectRefLayers(0);
2265
2266    for(Int j = 0; j < layerIdx; j++)
2267    {
2268      if (vps->getDirectDependencyFlag(layerIdx, j))
2269      {
2270        decTop->setRefLayerId(decTop->getNumDirectRefLayers(), vps->getLayerIdInNuh(layerIdx));
2271        decTop->setNumDirectRefLayers(decTop->getNumDirectRefLayers() + 1);
2272
2273        Int samplePredEnabledFlag = (vps->getDirectDependencyType(layerIdx, j) + 1) & 1;
2274        decTop->setNumSamplePredRefLayers(decTop->getNumSamplePredRefLayers() + samplePredEnabledFlag);
2275
2276        Int motionPredEnabledFlag = ((vps->getDirectDependencyType(layerIdx, j) + 1) & 2) >> 1;
2277        decTop->setNumMotionPredRefLayers(decTop->getNumMotionPredRefLayers() + motionPredEnabledFlag);
2278      }
2279    }
2280  }
2281}
2282
2283Void TDecTop::checkValueOfTargetOutputLayerSetIdx(TComVPS *vps)
2284{
2285  CommonDecoderParams* params = this->getCommonDecoderParams();
2286
2287  if( params->getValueCheckedFlag() )
2288  {
2289    return; // Already checked
2290  }
2291
2292  if( params->getTargetOutputLayerSetIdx() == -1 )  // Output layer set index not specified
2293  {
2294    if( params->getTargetLayerId() > vps->getMaxLayerId() )
2295    {
2296      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() );
2297      params->setTargetLayerId( vps->getMaxLayerId() );
2298    }
2299
2300    Bool layerSetMatchFound = false;
2301    // Output layer set index not assigned.
2302    // Based on the value of targetLayerId, check if any of the output layer matches
2303    // Currently, the target layer ID in the encoder assumes that all the layers are decoded   
2304    // Check if any of the output layer sets match this description
2305    for( Int i = 0; i < vps->getNumOutputLayerSets(); i++ )
2306    {
2307      Bool layerSetMatchFlag = false;
2308      Int layerSetIdx = vps->getOutputLayerSetIdx( i );
2309
2310      for( Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++ )
2311      {
2312        if( vps->getLayerSetLayerIdList( layerSetIdx, j ) == params->getTargetLayerId() )
2313        {
2314          layerSetMatchFlag = true;
2315          break;
2316        }
2317      }
2318     
2319      if( layerSetMatchFlag ) // Potential output layer set candidate found
2320      {
2321        // If target dec layer ID list is also included - check if they match
2322        if( params->getTargetDecLayerIdSet() )
2323        {
2324          if( params->getTargetDecLayerIdSet()->size() ) 
2325          {
2326            for( Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++ )
2327            {
2328              if( *(params->getTargetDecLayerIdSet()->begin() + j) != vps->getLayerIdInNuh(vps->getLayerSetLayerIdList( layerSetIdx, j )))
2329              {
2330                layerSetMatchFlag = false;
2331              }
2332            }
2333          }
2334        }
2335        if( layerSetMatchFlag ) // The target dec layer ID list also matches, if present
2336        {
2337          // Match found
2338          layerSetMatchFound = true;
2339          params->setTargetOutputLayerSetIdx( i );
2340          params->setValueCheckedFlag( true );
2341          break;
2342        }
2343      }
2344    }
2345    assert( layerSetMatchFound ); // No output layer set matched the value of either targetLayerId or targetdeclayerIdlist
2346  }   
2347  else // Output layer set index is assigned - check if the values match
2348  {
2349    // Check if the target decoded layer is the highest layer in the list
2350    assert( params->getTargetOutputLayerSetIdx() < vps->getNumOutputLayerSets() );
2351#if !CONFORMANCE_BITSTREAM_MODE
2352    assert( params->getTargetOutputLayerSetIdx() < vps->getNumLayerSets() );
2353#endif
2354    Int layerSetIdx = vps->getOutputLayerSetIdx( params->getTargetOutputLayerSetIdx() );  // Index to the layer set
2355#if !CONFORMANCE_BITSTREAM_MODE
2356    assert( params->getTargetLayerId() == vps->getNumLayersInIdList( layerSetIdx ) - 1);
2357#endif
2358   
2359    // Check if the targetdeclayerIdlist matches the output layer set
2360    if( params->getTargetDecLayerIdSet() )
2361    {
2362      if( params->getTargetDecLayerIdSet()->size() ) 
2363      {
2364        for(Int i = 0; i < vps->getNumLayersInIdList( layerSetIdx ); i++)
2365        {
2366          assert( *(params->getTargetDecLayerIdSet()->begin() + i) == vps->getLayerIdInNuh(vps->getLayerSetLayerIdList( layerSetIdx, i )));
2367        }
2368      }
2369    }
2370    params->setValueCheckedFlag( true );
2371
2372  }
2373
2374  // Set correct value of targetLayerId
2375  Int targetOlsIdx = params->getTargetOutputLayerSetIdx();
2376  Int targetLsIdx = vps->getOutputLayerSetIdx( targetOlsIdx );
2377  params->setTargetLayerId( vps->getLayerSetLayerIdList( targetLsIdx, vps->getNumLayersInIdList(targetLsIdx)-1 ) );
2378
2379  // Check if the current layer is an output layer
2380  for( Int i = 0; i < vps->getNumLayersInIdList( targetLsIdx ); i++ )
2381  {
2382    if( vps->getOutputLayerFlag( targetOlsIdx, i ) )
2383    {
2384      this->getLayerDec( vps->getLayerSetLayerIdList( targetLsIdx, i ) )->m_isOutputLayerFlag = true;
2385    }
2386  }
2387}
2388
2389Void TDecTop::markAllPicsAsNoCurrAu( const TComVPS *vps )
2390{
2391  for(Int i = 0; i < MAX_LAYERS; i++)
2392  {
2393    TComList<TComPic*>* listPic = m_ppcTDecTop[vps->getLayerIdInNuh(i)]->getListPic();
2394    TComList<TComPic*>::iterator  iterPic = listPic->begin();
2395    while ( iterPic != listPic->end() )
2396    {
2397      TComPic *pcPic = *(iterPic);
2398      pcPic->setCurrAuFlag( false );
2399      iterPic++;
2400    }
2401  }
2402}
2403
2404#if CGS_3D_ASYMLUT
2405Void TDecTop::initAsymLut(TComSlice *pcSlice)
2406{
2407  if( m_layerId > 0 )
2408  {
2409    if( !m_pColorMappedPic )
2410    {
2411      m_pColorMappedPic = new TComPicYuv;
2412      m_pColorMappedPic->create( pcSlice->getPicWidthInLumaSamples(), pcSlice->getPicHeightInLumaSamples(), pcSlice->getChromaFormatIdc()/*CHROMA_420*/, pcSlice->getSPS()->getMaxCUWidth(), pcSlice->getSPS()->getMaxCUHeight(), pcSlice->getSPS()->getMaxTotalCUDepth(), true, NULL );
2413    }
2414  }
2415}
2416#endif
2417
2418Void TDecTop::resetPocRestrictionCheckParameters()
2419{
2420  TDecTop::m_checkPocRestrictionsForCurrAu       = false;
2421  TDecTop::m_pocResetIdcOrCurrAu                 = -1;
2422  TDecTop::m_baseLayerIdrFlag                    = false;
2423  TDecTop::m_baseLayerPicPresentFlag             = false;
2424  TDecTop::m_baseLayerIrapFlag                   = false;
2425  TDecTop::m_nonBaseIdrPresentFlag               = false;
2426  TDecTop::m_nonBaseIdrType                      = -1;
2427  TDecTop::m_picNonIdrWithRadlPresentFlag        = false;
2428  TDecTop::m_picNonIdrNoLpPresentFlag            = false;
2429}
2430
2431Void TDecTop::xCheckLayerReset()
2432{
2433  if (m_apcSlicePilot->isIRAP() && m_layerId > m_smallestLayerId)
2434  {
2435    Bool layerResetFlag;
2436    UInt dolLayerId;
2437    if (m_lastPicHasEos)
2438    {
2439      layerResetFlag = true;
2440      dolLayerId = m_layerId;
2441    }
2442    else if ((m_apcSlicePilot->isCRA() && m_apcSlicePilot->getHandleCraAsBlaFlag()) ||
2443      (m_apcSlicePilot->isIDR() && m_apcSlicePilot->getCrossLayerBLAFlag()) || m_apcSlicePilot->isBLA())
2444    {
2445      layerResetFlag = true;
2446      dolLayerId = m_layerId;
2447    }
2448    else
2449    {
2450      layerResetFlag = false;
2451    }
2452
2453    if (layerResetFlag)
2454    {
2455      for (Int i = 0; i < m_apcSlicePilot->getVPS()->getNumPredictedLayers(dolLayerId); i++)
2456      {
2457        UInt iLayerId = m_apcSlicePilot->getVPS()->getPredictedLayerId(dolLayerId, i);
2458        m_ppcTDecTop[iLayerId]->m_layerInitializedFlag = false;
2459        m_ppcTDecTop[iLayerId]->m_firstPicInLayerDecodedFlag = false;
2460      }
2461
2462      for (TComList<TComPic*>::iterator i = m_cListPic.begin(); i != m_cListPic.end(); i++)
2463      {
2464        if ((*i)->getPOC() != m_apcSlicePilot->getPOC())
2465        {
2466          (*i)->getSlice(0)->setReferenced(false);
2467        }
2468      }
2469
2470      for (UInt i = 0; i < m_apcSlicePilot->getVPS()->getNumPredictedLayers(dolLayerId); i++)
2471      {
2472        UInt predLId = m_apcSlicePilot->getVPS()->getPredictedLayerId(dolLayerId, i);
2473        for (TComList<TComPic*>::iterator pic = m_ppcTDecTop[predLId]->getListPic()->begin(); pic != m_ppcTDecTop[predLId]->getListPic()->end(); pic++)
2474        {
2475          if ((*pic)->getSlice(0)->getPOC() != m_apcSlicePilot->getPOC())
2476          {
2477            (*pic)->getSlice(0)->setReferenced(false);
2478          }
2479        }
2480      }
2481    }
2482  }
2483}
2484
2485Void TDecTop::xSetLayerInitializedFlag()
2486{
2487  if (m_apcSlicePilot->isIRAP() && m_apcSlicePilot->getNoRaslOutputFlag())
2488  {
2489    if (m_layerId == 0)
2490    {
2491      m_ppcTDecTop[m_layerId]->setLayerInitializedFlag(true);
2492    }
2493    else if (!m_ppcTDecTop[m_layerId]->getLayerInitializedFlag() && m_apcSlicePilot->getVPS()->getNumDirectRefLayers(m_layerId) == 0)
2494    {
2495      m_ppcTDecTop[m_layerId]->setLayerInitializedFlag(true);
2496    }
2497    else if (!m_ppcTDecTop[m_layerId]->getLayerInitializedFlag())
2498    {
2499      Bool refLayersInitialized = true;
2500      for (UInt j = 0; j < m_apcSlicePilot->getVPS()->getNumDirectRefLayers(m_layerId); j++)
2501      {
2502        UInt refLayerId = m_apcSlicePilot->getVPS()->getRefLayerId(m_layerId, j);
2503        if (!m_ppcTDecTop[refLayerId]->getLayerInitializedFlag())
2504        {
2505          refLayersInitialized = false;
2506        }
2507      }
2508      if (refLayersInitialized)
2509      {
2510        m_ppcTDecTop[m_layerId]->setLayerInitializedFlag(true);
2511      }
2512    }
2513  }
2514}
2515
2516Void TDecTop::xDeriveSmallestLayerId(TComVPS* vps)
2517{
2518  UInt smallestLayerId;
2519  Int  targetOlsIdx = m_commonDecoderParams->getTargetOutputLayerSetIdx();
2520  assert( targetOlsIdx >= 0 );
2521
2522  UInt targetDecLayerSetIdx = vps->getOutputLayerSetIdx(targetOlsIdx);
2523  UInt lsIdx = targetDecLayerSetIdx;
2524  UInt targetDecLayerIdList[MAX_LAYERS] = {0};
2525
2526  for (UInt i = 0, j = 0; i < vps->getNumLayersInIdList(lsIdx); i++)
2527  {
2528    if (vps->getNecessaryLayerFlag(targetOlsIdx, i))
2529    {
2530      targetDecLayerIdList[j++] = vps->getLayerSetLayerIdList(lsIdx, i);
2531    }
2532  }
2533
2534  if (targetDecLayerSetIdx <= vps->getVpsNumLayerSetsMinus1())
2535  {
2536    smallestLayerId = 0;
2537  }
2538  else if (vps->getNumLayersInIdList(targetDecLayerSetIdx) == 1)
2539  {
2540    smallestLayerId = 0;
2541  }
2542  else
2543  {
2544    smallestLayerId = targetDecLayerIdList[0];
2545  }
2546
2547  for( UInt layerId = 0; layerId < MAX_VPS_LAYER_IDX_PLUS1; layerId++ )
2548  {
2549    m_ppcTDecTop[layerId]->m_smallestLayerId = smallestLayerId;
2550  }
2551}
2552
2553Void TDecTop::xSetSpatialEnhLayerFlag( const TComVPS &vps, const TComSPS &sps, const TComPPS &pps, TComPic* pic )
2554{
2555  for(UInt i = 0; i < vps.getNumDirectRefLayers( m_layerId ); i++ )
2556  {
2557    const Window scalEL = pps.getScaledRefLayerWindowForLayer(vps.getRefLayerId(m_layerId, i));
2558    const Window refEL = pps.getRefLayerWindowForLayer(vps.getRefLayerId(m_layerId, i));
2559    Bool equalOffsets = scalEL.hasEqualOffset(refEL);
2560    Bool zeroPhase = pps.hasZeroResamplingPhase(vps.getRefLayerId(m_layerId, i));
2561
2562    TDecTop *pcTDecTopBase = (TDecTop *)getRefLayerDec( i );
2563    TComPicYuv* pcPicYuvRecBase = (*(pcTDecTopBase->getListPic()->begin()))->getPicYuvRec();
2564
2565    const Int bitDepthLuma = vps.getBitDepth(CHANNEL_TYPE_LUMA, &sps, m_layerId);
2566    const Int bitDepthChroma = vps.getBitDepth(CHANNEL_TYPE_CHROMA, &sps, m_layerId);
2567    const Int refBitDepthLuma = (*(pcTDecTopBase->getListPic()->begin()))->getSlice(0)->getBitDepth(CHANNEL_TYPE_LUMA);
2568    const Int refBitDepthChroma = (*(pcTDecTopBase->getListPic()->begin()))->getSlice(0)->getBitDepth(CHANNEL_TYPE_CHROMA);
2569   
2570    Bool sameBitDepths = ( bitDepthLuma == refBitDepthLuma ) && ( bitDepthChroma == refBitDepthChroma );
2571
2572    if( pcPicYuvRecBase->getWidth(COMPONENT_Y) == vps.getPicWidthInLumaSamples(&sps, m_layerId) && pcPicYuvRecBase->getHeight(COMPONENT_Y) == vps.getPicHeightInLumaSamples(&sps, m_layerId) && equalOffsets && zeroPhase )
2573    {
2574      pic->setEqualPictureSizeAndOffsetFlag( i, true );
2575    }
2576
2577    if( !pic->equalPictureSizeAndOffsetFlag(i) || !sameBitDepths
2578#if CGS_3D_ASYMLUT
2579      || pps.getCGSFlag() > 0
2580#endif
2581      )
2582    {
2583      pic->setSpatialEnhLayerFlag( i, true );
2584
2585      //only for scalable extension
2586      assert( vps.getScalabilityMask( SCALABILITY_ID ) == true );
2587    }
2588  }
2589}
2590
2591#endif //SVC_EXTENSION
2592
2593
2594//! \}
Note: See TracBrowser for help on using the repository browser.