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

Last change on this file since 1502 was 1502, checked in by seregin, 8 years ago

infer parameters in SPS after activation, fixing chroma scaling for non 4:2:0

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