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

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

replace NALU type constants 15 and 24

  • Property svn:eol-style set to native
File size: 95.0 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license.
5 *
6 * Copyright (c) 2010-2015, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TDecTop.cpp
35    \brief    decoder class
36*/
37
38#include "NALread.h"
39#include "TDecTop.h"
40
41#if SVC_EXTENSION
42UInt  TDecTop::m_prevPOC                       = MAX_UINT;
43UInt  TDecTop::m_uiPrevLayerId                 = MAX_UINT;
44Bool  TDecTop::m_bFirstSliceInSequence         = true;
45Bool  TDecTop::m_checkPocRestrictionsForCurrAu = false;
46Int   TDecTop::m_pocResetIdcOrCurrAu           = -1;
47Bool  TDecTop::m_baseLayerIdrFlag              = false;
48Bool  TDecTop::m_baseLayerPicPresentFlag       = false;
49Bool  TDecTop::m_baseLayerIrapFlag             = false;
50Bool  TDecTop::m_nonBaseIdrPresentFlag         = false;
51Int   TDecTop::m_nonBaseIdrType                = -1;
52Bool  TDecTop::m_picNonIdrWithRadlPresentFlag  = false;
53Bool  TDecTop::m_picNonIdrNoLpPresentFlag      = false;
54Int   TDecTop::m_crossLayerPocResetPeriodId    = -1;
55Int   TDecTop::m_crossLayerPocResetIdc         = -1;
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      xSetRequireResamplingFlag( vps, sps, pps, rpcPic );
275    }
276
277    rpcPic->create( 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    xSetRequireResamplingFlag( vps, sps, pps, rpcPic );
324  }
325
326  rpcPic->create( 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->getPicSym()->inferSpsForNonHEVCBL(vps, sps->getMaxCUWidth(), sps->getMaxCUHeight());
523
524        pBLPic->create( pBLPic->getPicSym()->getSPS(), *pps, true, refLayerId);
525
526        // it is needed where the VPS is accessed through the slice
527        pBLPic->getSlice(0)->setVPS( vps );
528        pBLPic->getSlice(0)->setSPS( &pBLPic->getPicSym()->getSPS() );
529      }
530    }
531#endif
532
533    if( m_layerId > 0 )
534    {
535      // When not present sps_max_sub_layers_minus1 is inferred to be equal to vps_max_sub_layers_minus1.
536      updateSPS->setMaxTLayers( vps->getMaxTLayers() );
537
538      // When not present sps_temporal_id_nesting_flag is inferred to be equal to vps_temporal_id_nesting_flag
539      updateSPS->setTemporalIdNestingFlag( (sps->getMaxTLayers() > 1) ? vps->getTemporalNestingFlag() : true );
540
541      // When sps_max_dec_pic_buffering_minus1[ i ] is not present for i in the range of 0 to sps_max_sub_layers_minus1, inclusive, due to nuh_layer_id being greater than 0,
542      // it is inferred to be equal to max_vps_dec_pic_buffering_minus1[ TargetOptLayerSetIdx ][ currLayerId ][ i ] of the active VPS, where currLayerId is the nuh_layer_id of the layer that refers to the SPS.
543      for(UInt i=0; i < sps->getMaxTLayers(); i++)
544      {
545        // to avoid compiler warning "array subscript is above array bounds"
546        assert( i < MAX_TLAYER );
547
548        // When sps_max_dec_pic_buffering_minus1[ i ] is not present for i in the range of 0 to sps_max_sub_layers_minus1, inclusive,
549        // due to MultiLayerExtSpsFlag being equal to 1, for a layer that refers to the SPS and has nuh_layer_id equal to currLayerId,
550        // the value of sps_max_dec_pic_buffering_minus1[ i ] is inferred to be equal to max_vps_dec_pic_buffering_minus1[ TargetOlsIdx ][ layerIdx ][ i ] of the active VPS,
551        // where layerIdx is equal to the value such that LayerSetLayerIdList[ TargetDecLayerSetIdx ][ layerIdx ] is equal to currLayerId.
552        if( sps->getMultiLayerExtSpsFlag() )
553        {
554          updateSPS->setMaxDecPicBuffering( vps->getMaxVpsDecPicBufferingMinus1( m_commonDecoderParams->getTargetOutputLayerSetIdx(), vps->getLayerIdcForOls( vps->getOutputLayerSetIdx( m_commonDecoderParams->getTargetOutputLayerSetIdx() ), m_layerId ), i) + 1, i);
555        }
556
557        // The value of sps_max_dec_pic_buffering_minus1[ i ] shall be less than or equal to vps_max_dec_pic_buffering_minus1[ i ] for each value of i.
558        assert( sps->getMaxDecPicBuffering(i) <= vps->getMaxDecPicBuffering(i) );     
559      }
560
561      UInt layerIdx = vps->getLayerIdxInVps( m_layerId );
562
563      if( vps->getBaseLayerPSCompatibilityFlag(layerIdx) )
564      {
565        const RepFormat* repFormat = vps->getVpsRepFormat(vps->getVpsRepFormatIdx(layerIdx));
566
567        assert( pps->getLayerId() == 0 );
568        assert( sps->getLayerId() == 0 );
569        assert( repFormat->getChromaFormatVpsIdc() == sps->getChromaFormatIdc() );
570        assert( repFormat->getSeparateColourPlaneVpsFlag() == 0 );
571        assert( repFormat->getPicHeightVpsInLumaSamples() == sps->getPicHeightInLumaSamples() );
572        assert( repFormat->getPicWidthVpsInLumaSamples()  == sps->getPicWidthInLumaSamples() );
573        assert( repFormat->getBitDepthVpsLuma()   == sps->getBitDepth(CHANNEL_TYPE_LUMA) );
574        assert( repFormat->getBitDepthVpsChroma() == sps->getBitDepth(CHANNEL_TYPE_CHROMA) );
575        assert( repFormat->getConformanceWindowVps().getWindowLeftOffset()   == sps->getConformanceWindow().getWindowLeftOffset() );
576        assert( repFormat->getConformanceWindowVps().getWindowRightOffset()  == sps->getConformanceWindow().getWindowRightOffset() );
577        assert( repFormat->getConformanceWindowVps().getWindowTopOffset()    == sps->getConformanceWindow().getWindowTopOffset() );
578        assert( repFormat->getConformanceWindowVps().getWindowBottomOffset() == sps->getConformanceWindow().getWindowBottomOffset() );
579      }   
580    }
581
582    //Conformance checking for rep format -- rep format of current picture of current layer shall never be greater rep format defined in VPS for the current layer
583    UInt layerIdx = vps->getLayerIdxInVps(m_apcSlicePilot->getLayerId());
584
585    if ( vps->getVpsExtensionFlag() == 1 && (m_apcSlicePilot->getLayerId() == 0 || sps->getV1CompatibleSPSFlag() == 1) )
586    {
587      assert( sps->getPicWidthInLumaSamples()        <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx) )->getPicWidthVpsInLumaSamples() );
588      assert( sps->getPicHeightInLumaSamples()       <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx) )->getPicHeightVpsInLumaSamples() );
589      assert( sps->getChromaFormatIdc()              <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx) )->getChromaFormatVpsIdc() );
590      assert( sps->getBitDepth(CHANNEL_TYPE_LUMA)    <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx) )->getBitDepthVpsLuma() );
591      assert( sps->getBitDepth(CHANNEL_TYPE_CHROMA)  <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx) )->getBitDepthVpsChroma() );
592    }
593    else if ( vps->getVpsExtensionFlag() == 1 )
594    {
595      assert( vps->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(layerIdx))->getPicWidthVpsInLumaSamples()  <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx))->getPicWidthVpsInLumaSamples());
596      assert( vps->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(layerIdx))->getPicHeightVpsInLumaSamples() <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx))->getPicHeightVpsInLumaSamples());
597      assert( vps->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(layerIdx))->getChromaFormatVpsIdc()        <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx))->getChromaFormatVpsIdc());
598      assert( vps->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(layerIdx))->getBitDepthVpsLuma()           <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx))->getBitDepthVpsLuma());
599      assert( vps->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(layerIdx))->getBitDepthVpsChroma()         <= vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerIdx))->getBitDepthVpsChroma());
600    }
601
602    updateSPS->inferSPS( m_layerId, vps );
603#endif //SVC_EXTENSION
604
605    // NOTE: globals were set up here originally. You can now use:
606    // g_uiMaxCUDepth = sps->getMaxTotalCUDepth();
607    // g_uiAddCUDepth = sps->getMaxTotalCUDepth() - sps->getLog2DiffMaxMinCodingBlockSize()
608
609    //  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.
610#if SVC_EXTENSION
611    xGetNewPicBuffer( *(vps), *(sps), *(pps), m_pcPic, m_apcSlicePilot->getTLayer() );
612#else
613    xGetNewPicBuffer (*(sps), *(pps), m_pcPic, m_apcSlicePilot->getTLayer());
614#endif
615
616#if ALIGNED_BUMPING
617    m_apcSlicePilot->checkLeadingPictureRestrictions(m_cListPic);
618#else
619    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
620#endif
621
622    // make the slice-pilot a real slice, and set up the slice-pilot for the next slice
623    assert(m_pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
624    m_apcSlicePilot = m_pcPic->getPicSym()->swapSliceObject(m_apcSlicePilot, m_uiSliceIdx);
625
626    // we now have a real slice:
627    TComSlice *pSlice = m_pcPic->getSlice(m_uiSliceIdx);
628
629    // Update the PPS and SPS pointers with the ones of the picture.
630    pps=pSlice->getPPS();
631    sps=pSlice->getSPS();
632
633    // Initialise the various objects for the new set of settings
634    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) );
635    m_cLoopFilter.create( sps->getMaxTotalCUDepth() );
636    m_cPrediction.initTempBuff(sps->getChromaFormatIdc());
637
638
639    Bool isField = false;
640    Bool isTopField = false;
641
642    if(!m_SEIs.empty())
643    {
644      // Check if any new Picture Timing SEI has arrived
645      SEIMessages pictureTimingSEIs = getSeisByType(m_SEIs, SEI::PICTURE_TIMING);
646      if (pictureTimingSEIs.size()>0)
647      {
648        SEIPictureTiming* pictureTiming = (SEIPictureTiming*) *(pictureTimingSEIs.begin());
649        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);
650        isTopField = (pictureTiming->m_picStruct == 1) || (pictureTiming->m_picStruct == 9) || (pictureTiming->m_picStruct == 11);
651      }
652     
653#if Q0189_TMVP_CONSTRAINTS
654      // Check if any new temporal motion vector prediction constraints SEI has arrived
655      SEIMessages seiTMVPConstrainsList = extractSeisByType (m_SEIs, SEI::TMVP_CONSTRAINTS);
656      if (seiTMVPConstrainsList.size() > 0)
657      {
658        assert ( m_pcPic->getTLayer() == 0 );  //this SEI can present only for AU with Tid equal to 0
659        SEITMVPConstrains* tmvpConstraintSEI = (SEITMVPConstrains*) *(seiTMVPConstrainsList.begin());
660        if ( tmvpConstraintSEI->prev_pics_not_used_flag == 1 )
661        {
662          //update all pics in the DPB such that they cannot be used for TMPV ref
663          TComList<TComPic*>::iterator  iterRefPic = m_cListPic.begin(); 
664          while( iterRefPic != m_cListPic.end() )
665          {
666            TComPic *refPic = *iterRefPic;
667            if( ( refPic->getLayerId() == m_pcPic->getLayerId() ) && refPic->getReconMark() )
668            {
669              for(Int i = refPic->getNumAllocatedSlice()-1; i >= 0; i--)
670              {
671                TComSlice *refSlice = refPic->getSlice(i);
672                refSlice->setAvailableForTMVPRefFlag( false );
673              }
674            }
675            iterRefPic++;
676          }
677        }
678      }
679#endif
680    }
681
682    //Set Field/Frame coding mode
683    m_pcPic->setField(isField);
684    m_pcPic->setTopField(isTopField);
685
686    // transfer any SEI messages that have been received to the picture
687    m_pcPic->setSEIs(m_SEIs);
688    m_SEIs.clear();
689
690    // Recursive structure
691    m_cCuDecoder.create ( sps->getMaxTotalCUDepth(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getChromaFormatIdc() );
692#if SVC_EXTENSION
693    m_cCuDecoder.init   ( m_ppcTDecTop, &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction, m_layerId );
694#else
695    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
696#endif
697    m_cTrQuant.init     ( sps->getMaxTrSize() );
698
699    m_cSliceDecoder.create();
700  }
701  else
702  {
703    // make the slice-pilot a real slice, and set up the slice-pilot for the next slice
704    m_pcPic->allocateNewSlice();
705    assert(m_pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
706    m_apcSlicePilot = m_pcPic->getPicSym()->swapSliceObject(m_apcSlicePilot, m_uiSliceIdx);
707
708    TComSlice *pSlice = m_pcPic->getSlice(m_uiSliceIdx); // we now have a real slice.
709
710    const TComSPS *sps = pSlice->getSPS();
711    const TComPPS *pps = pSlice->getPPS();
712
713    // check that the current active PPS has not changed...
714    if (m_parameterSetManager.getSPSChangedFlag(sps->getSPSId()) )
715    {
716      printf("Error - a new SPS has been decoded while processing a picture\n");
717      exit(1);
718    }
719    if (m_parameterSetManager.getPPSChangedFlag(pps->getPPSId()) )
720    {
721      printf("Error - a new PPS has been decoded while processing a picture\n");
722      exit(1);
723    }
724
725    xParsePrefixSEImessages();
726
727    // Check if any new SEI has arrived
728     if(!m_SEIs.empty())
729     {
730       // Currently only decoding Unit SEI message occurring between VCL NALUs copied
731       SEIMessages &picSEI = m_pcPic->getSEIs();
732       SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
733       picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
734       deleteSEIs(m_SEIs);
735     }
736  }
737}
738
739
740Void TDecTop::xParsePrefixSEIsForUnknownVCLNal()
741{
742  while (!m_prefixSEINALUs.empty())
743  {
744    // do nothing?
745    printf("Discarding Prefix SEI associated with unknown VCL NAL unit.\n");
746    delete m_prefixSEINALUs.front();
747  }
748  // TODO: discard following suffix SEIs as well?
749}
750
751
752Void TDecTop::xParsePrefixSEImessages()
753{
754#if SVC_EXTENSION
755    if (m_prevSliceSkipped) // No need to decode SEI messages of a skipped access unit
756    {
757      return;
758    }
759#endif
760
761  while (!m_prefixSEINALUs.empty())
762  {
763    InputNALUnit &nalu=*m_prefixSEINALUs.front();
764#if LAYERS_NOT_PRESENT_SEI
765    m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_SEIs, nalu.m_nalUnitType, m_parameterSetManager.getActiveVPS(), m_parameterSetManager.getActiveSPS(), m_pDecodedSEIOutputStream );
766#else
767    m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_SEIs, nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS(), m_pDecodedSEIOutputStream );
768#endif
769    delete m_prefixSEINALUs.front();
770    m_prefixSEINALUs.pop_front();
771  }
772}
773
774#if SVC_EXTENSION
775Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC )
776#else
777Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
778#endif
779{
780#if SVC_EXTENSION
781  m_apcSlicePilot->initSlice( nalu.m_nuhLayerId );
782  m_apcSlicePilot->setTLayer( nalu.m_temporalId );
783#else //SVC_EXTENSION
784  m_apcSlicePilot->initSlice(); // the slice pilot is an object to prepare for a new slice
785                                // it is not associated with picture, sps or pps structures.
786#endif
787
788  if (m_bFirstSliceInPicture)
789  {
790    m_uiSliceIdx = 0;
791  }
792  else
793  {
794    m_apcSlicePilot->copySliceInfo( m_pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
795  }
796  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
797
798  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
799
800  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
801                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
802                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
803                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
804                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
805  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
806  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
807  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
808
809#if ENC_DEC_TRACE
810  const UInt64 originalSymbolCount = g_nSymbolCounter;
811#endif
812
813  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManager, m_prevTid0POC);
814
815#if SVC_EXTENSION
816  const TComPPS *pps = m_parameterSetManager.getPPS(m_apcSlicePilot->getPPSId());
817  assert (pps != 0);
818  const TComSPS *sps = m_parameterSetManager.getSPS(pps->getSPSId());
819  assert (sps != 0);
820  const TComVPS *vps = m_parameterSetManager.getVPS(sps->getVPSId());
821  assert (vps != 0);
822
823  // Following check should go wherever the VPS is activated
824  if( !vps->getBaseLayerAvailableFlag() )
825  {
826    assert( nalu.m_nuhLayerId != 0 );
827    assert( vps->getNumAddLayerSets() > 0 );
828
829    if( m_commonDecoderParams->getTargetOutputLayerSetIdx() >= 0 )
830    {
831      UInt layerIdx = vps->getOutputLayerSetIdx( getCommonDecoderParams()->getTargetOutputLayerSetIdx() );
832      assert( layerIdx > vps->getVpsNumLayerSetsMinus1() );
833    }
834  } 
835
836  setRefLayerParams(vps);
837  m_apcSlicePilot->setNumMotionPredRefLayers(m_numMotionPredRefLayers);
838
839  // set motion mapping flag
840  m_apcSlicePilot->setMFMEnabledFlag( ( m_apcSlicePilot->getNumMotionPredRefLayers() > 0 && m_apcSlicePilot->getActiveNumILRRefIdx() && !m_apcSlicePilot->isIntra() ) ? true : false );
841#endif
842
843  // set POC for dependent slices in skipped pictures
844  if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped)
845  {
846    m_apcSlicePilot->setPOC(m_skippedPOC);
847  }
848
849#if !CONFORMANCE_BITSTREAM_FIX  //This update previous Tid0 POC is moved down and invoke only after the POC derivation has been finalized
850  xUpdatePreviousTid0POC(m_apcSlicePilot);
851#endif
852
853  m_apcSlicePilot->setAssociatedIRAPPOC(m_pocCRA);
854  m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType);
855
856  //For inference of NoOutputOfPriorPicsFlag
857  if (m_apcSlicePilot->getRapPicFlag())
858  {
859    if ((m_apcSlicePilot->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_apcSlicePilot->getNalUnitType() <= NAL_UNIT_CODED_SLICE_IDR_N_LP) || 
860        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_bFirstSliceInSequence) ||
861        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getHandleCraAsBlaFlag()))
862    {
863      m_apcSlicePilot->setNoRaslOutputFlag(true);
864    }
865    //the inference for NoOutputPriorPicsFlag
866    if (!m_bFirstSliceInBitstream && m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag())
867    {
868      if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
869      {
870        m_apcSlicePilot->setNoOutputPriorPicsFlag(true);
871      }
872    }
873    else
874    {
875      m_apcSlicePilot->setNoOutputPriorPicsFlag(false);
876    }
877
878    if(m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
879    {
880      m_craNoRaslOutputFlag = m_apcSlicePilot->getNoRaslOutputFlag();
881    }
882  }
883  if (m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoOutputPriorPicsFlag())
884  {
885    m_lastPOCNoOutputPriorPics = m_apcSlicePilot->getPOC();
886    m_isNoOutputPriorPics = true;
887  }
888  else
889  {
890    m_isNoOutputPriorPics = false;
891  }
892
893  //For inference of PicOutputFlag
894  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R)
895  {
896    if ( m_craNoRaslOutputFlag )
897    {
898      m_apcSlicePilot->setPicOutputFlag(false);
899    }
900  }
901
902  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_craNoRaslOutputFlag) //Reset POC MSB when CRA has NoRaslOutputFlag equal to 1
903  {
904#if !SVC_EXTENSION
905    TComPPS *pps = m_parameterSetManager.getPPS(m_apcSlicePilot->getPPSId());
906    assert (pps != 0);
907    TComSPS *sps = m_parameterSetManager.getSPS(pps->getSPSId());
908    assert (sps != 0);
909#endif
910    Int iMaxPOClsb = 1 << sps->getBitsForPOC();
911    m_apcSlicePilot->setPOC( m_apcSlicePilot->getPOC() & (iMaxPOClsb - 1) );
912#if !CONFORMANCE_BITSTREAM_FIX  //This update previous Tid0 POC is moved down and invoke only after the POC derivation has been finalized
913    xUpdatePreviousTid0POC(m_apcSlicePilot);
914#endif
915  }
916
917  // Skip pictures due to random access
918
919  if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
920  {
921    m_prevSliceSkipped = true;
922    m_skippedPOC = m_apcSlicePilot->getPOC();
923    return false;
924  }
925  // Skip TFD pictures associated with BLA/BLANT pictures
926  if (isSkipPictureForBLA(iPOCLastDisplay))
927  {
928    m_prevSliceSkipped = true;
929    m_skippedPOC = m_apcSlicePilot->getPOC();
930    return false;
931  }
932
933  // clear previous slice skipped flag
934  m_prevSliceSkipped = false;
935
936  // exit when a new picture is found
937#if SVC_EXTENSION
938  bNewPOC = m_apcSlicePilot->getPOC() != m_prevPOC || ( m_apcSlicePilot->getFirstSliceInPic() && m_parseIdc == -1 );
939
940#if NO_CLRAS_OUTPUT_FLAG
941  if( m_layerId == m_smallestLayerId && m_apcSlicePilot->getRapPicFlag() )
942  {
943    if( m_bFirstSliceInSequence )
944    {
945      setNoClrasOutputFlag(true);
946    }
947    else if( m_lastPicHasEos )
948    {
949      setNoClrasOutputFlag(true);
950    }
951    else if( m_apcSlicePilot->getBlaPicFlag() )
952    {
953      setNoClrasOutputFlag(true);
954    }
955    else if( m_apcSlicePilot->getIdrPicFlag() && m_apcSlicePilot->getCrossLayerBLAFlag() )
956    {
957      setNoClrasOutputFlag(true);
958    }
959    else
960    {
961      setNoClrasOutputFlag(false);
962    }     
963  }
964  else
965  {
966    setNoClrasOutputFlag(false);
967  }
968
969  m_apcSlicePilot->decodingRefreshMarking( m_cListPic, m_noClrasOutputFlag, m_smallestLayerId );
970#endif
971
972  // Derive the value of NoOutputOfPriorPicsFlag
973  if( bNewPOC || m_layerId!=m_uiPrevLayerId )   // i.e. new coded picture
974  {
975    if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getNoRaslOutputFlag() )
976    {
977      this->setNoOutputPriorPicsFlag( true );
978    }
979    else if( m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag() )
980    {
981      this->setNoOutputPriorPicsFlag( m_apcSlicePilot->getNoOutputPriorPicsFlag() );
982    }
983    else
984    {
985      if( this->m_ppcTDecTop[0]->getNoClrasOutputFlag() )
986      {
987        this->setNoOutputPriorPicsFlag( true );
988      }
989    }
990  }
991
992#if SVC_POC
993  if( m_parseIdc != -1 ) // Second pass for a POC resetting picture
994  {
995    m_parseIdc++; // Proceed to POC decoding and RPS derivation
996  }
997 
998  if( m_parseIdc == 2 )
999  {
1000    bNewPOC = false;
1001  }
1002
1003  if( (bNewPOC || m_layerId!=m_uiPrevLayerId) && (m_parseIdc == -1) ) // Will be true at the first pass
1004  {
1005  //if (bNewPOC || m_layerId!=m_uiPrevLayerId)
1006  // Check if new reset period has started - this is needed just so that the SHM decoder which calls slice header decoding twice
1007  // does not invoke the output twice
1008  //if( m_lastPocPeriodId[m_apcSlicePilot->getLayerId()] == m_apcSlicePilot->getPocResetPeriodId() )
1009    // Update CurrAU marking
1010    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
1011    {
1012      // New access unit; reset all variables related to POC reset restrictions
1013      resetPocRestrictionCheckParameters();
1014
1015      markAllPicsAsNoCurrAu(vps);
1016
1017      for( UInt i = 0; i < MAX_LAYERS; i++ )
1018      {
1019        m_ppcTDecTop[vps->getLayerIdInNuh(i)]->m_pocDecrementedInDPBFlag = false;
1020      }
1021    }
1022
1023    m_pocResettingFlag = false;
1024
1025    if( m_apcSlicePilot->getPocResetIdc() != 0 )
1026    {
1027      if( vps->getVpsPocLsbAlignedFlag() )
1028      {
1029        m_pocResettingFlag = true;
1030      }
1031      else if (m_pocDecrementedInDPBFlag)
1032      {
1033        m_pocResettingFlag = false;
1034      }
1035      else
1036      {
1037        m_pocResettingFlag = true;
1038      }
1039    }
1040
1041#if CONFORMANCE_BITSTREAM_FIX
1042    if( m_apcSlicePilot->getPocResetIdc() && m_apcSlicePilot->getFirstSliceInPic() )
1043#else
1044    if( m_apcSlicePilot->getPocResetIdc() && m_apcSlicePilot->getSliceIdx() == 0 )
1045#endif
1046    {
1047      Int pocResetPeriodId = m_apcSlicePilot->getPocResetPeriodId();
1048      if ( m_apcSlicePilot->getPocResetIdc() == 1 || m_apcSlicePilot->getPocResetIdc() == 2 ||
1049        ( m_apcSlicePilot->getPocResetIdc() == 3 && pocResetPeriodId != getLastPocPeriodId() ) )
1050      {
1051        setLastPocPeriodId(pocResetPeriodId);
1052        m_parseIdc = 0;
1053      }
1054
1055      // Check if the POC Reset period ID matches with the Reset Period ID
1056      if( pocResetPeriodId == m_crossLayerPocResetPeriodId )
1057      {
1058        // If matching, and current poc_reset_idc = 3, then the values should match
1059        if( m_apcSlicePilot->getPocResetIdc() == 3 )
1060        {
1061          assert( ( m_apcSlicePilot->getFullPocResetFlag() == false && m_crossLayerPocResetIdc == 1 ) ||
1062                  ( m_apcSlicePilot->getFullPocResetFlag() == true  && m_crossLayerPocResetIdc == 2 ) );
1063        }
1064      }
1065      else
1066      {
1067        // This is the first picture of a POC resetting access unit
1068        m_crossLayerPocResetPeriodId = pocResetPeriodId;
1069        if( m_apcSlicePilot->getPocResetIdc() == 1 || m_apcSlicePilot->getPocResetIdc() == 2 )
1070        {
1071          m_crossLayerPocResetIdc = m_apcSlicePilot->getPocResetIdc();
1072        }
1073        else
1074        { // poc_reset_idc = 3
1075          // In this case, the entire POC resetting access unit has been lost.
1076          // Need more checking to ensure poc_reset_idc = 3 works.
1077          assert ( 0 );
1078        }
1079      }
1080    }
1081    else
1082    {
1083      m_parseIdc = 3; // Proceed to decoding POC and RPS
1084    }
1085  }
1086#endif
1087
1088#if ALIGNED_BUMPING
1089  UInt affectedLayerList[MAX_LAYERS];
1090  Int  numAffectedLayers;
1091
1092  affectedLayerList[0] = m_apcSlicePilot->getLayerId();
1093  numAffectedLayers = 1;
1094
1095  if( vps->getVpsPocLsbAlignedFlag() )
1096  {
1097    for( UInt j = 0; j < vps->getNumPredictedLayers(m_apcSlicePilot->getLayerId()); j++ )
1098    {
1099      affectedLayerList[j + 1] = vps->getPredictedLayerId(m_apcSlicePilot->getLayerId(), j);
1100    }
1101    numAffectedLayers = vps->getNumPredictedLayers(m_apcSlicePilot->getLayerId()) + 1;
1102  }
1103
1104  if( m_parseIdc == 1 && m_pocResettingFlag )
1105  {
1106    // Invoke output of pictures if the current picture is a POC reset picture
1107    bNewPOC = true;
1108    /* Include reset of all POCs in the layer */
1109
1110    // This operation would do the following:
1111    // 1. Update the other picture in the DPB. This should be done only for the first slice of the picture.
1112    // 2. Update the value of m_pocCRA.
1113    // 3. Reset the POC values at the decoder for the current picture to be zero - will be done later
1114    // 4. update value of POCLastDisplay
1115
1116    //Do the reset stuff here
1117    Int maxPocLsb = 1 << sps->getBitsForPOC();
1118    Int pocLsbVal;
1119    if( m_apcSlicePilot->getPocResetIdc() == 3 )
1120    {
1121      pocLsbVal = m_apcSlicePilot->getPocLsbVal() ;
1122    }
1123    else
1124    {
1125      pocLsbVal = (m_apcSlicePilot->getPOC() % maxPocLsb);
1126    }
1127
1128    Int pocMsbDelta = 0;
1129    if( m_apcSlicePilot->getPocMsbValPresentFlag() ) 
1130    {
1131      pocMsbDelta = m_apcSlicePilot->getPocMsbVal() * maxPocLsb;
1132    }
1133    else
1134    {
1135      //This MSB derivation can be made into one function. Item to do next.
1136      Int prevPoc     = this->getPrevPicOrderCnt();
1137      Int prevPocLsb  = prevPoc & (maxPocLsb - 1);
1138      Int prevPocMsb  = prevPoc - prevPocLsb;
1139
1140      pocMsbDelta = m_apcSlicePilot->getCurrMsb( pocLsbVal, prevPocLsb, prevPocMsb, maxPocLsb );
1141    }
1142
1143    Int pocLsbDelta;
1144    if( m_apcSlicePilot->getPocResetIdc() == 2 ||  ( m_apcSlicePilot->getPocResetIdc() == 3 && m_apcSlicePilot->getFullPocResetFlag() ))
1145    {
1146      pocLsbDelta = pocLsbVal;
1147    }
1148    else
1149    {
1150      pocLsbDelta = 0; 
1151    }
1152
1153    Int deltaPocVal  =  pocMsbDelta + pocLsbDelta;
1154
1155    for( UInt layerIdx = 0; layerIdx < numAffectedLayers; layerIdx++ )
1156    {
1157      if (!m_ppcTDecTop[affectedLayerList[layerIdx]]->m_pocDecrementedInDPBFlag)
1158      {
1159        m_ppcTDecTop[affectedLayerList[layerIdx]]->m_pocDecrementedInDPBFlag = true;
1160        TComList<TComPic*>::iterator  iterPic = m_ppcTDecTop[affectedLayerList[layerIdx]]->getListPic()->begin();
1161
1162        while (iterPic != m_ppcTDecTop[affectedLayerList[layerIdx]]->getListPic()->end())
1163        {
1164          TComPic *dpbPic = *iterPic;
1165          // Check if the picture pointed to by iterPic is either used for reference or
1166          // needed for output, are in the same layer, and not the current picture.
1167          assert(dpbPic->getLayerId() == affectedLayerList[layerIdx]);
1168
1169          if( (dpbPic->getReconMark()) && (dpbPic->getPicSym()->getSlice(0)->getPicOutputFlag()) )
1170          {
1171            for(Int i = dpbPic->getNumAllocatedSlice()-1; i >= 0; i--)
1172            {
1173
1174              TComSlice *slice = dpbPic->getSlice(i);
1175              TComReferencePictureSet *rps = slice->getLocalRPS();
1176              slice->setPOC( slice->getPOC() - deltaPocVal );
1177
1178              // Also adjust the POC value stored in the RPS of each such slice
1179              for(Int j = rps->getNumberOfPictures(); j >= 0; j--)
1180              {
1181                rps->setPOC( j, rps->getPOC(j) - deltaPocVal );
1182              }
1183
1184              slice->setRPS(rps);
1185
1186              // Also adjust the value of refPOC
1187              for(Int k = 0; k < 2; k++)  // For List 0 and List 1
1188              {
1189                RefPicList list = (k == 1) ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
1190                for(Int j = 0; j < slice->getNumRefIdx(list); j++)
1191                {
1192                  slice->setRefPOC( slice->getRefPOC(list, j) - deltaPocVal, list, j);
1193                }
1194              }
1195            }
1196          }
1197          iterPic++;
1198        }
1199        // Update the value of pocCRA
1200        m_ppcTDecTop[affectedLayerList[layerIdx]]->m_pocCRA -= deltaPocVal;
1201      }
1202    }
1203
1204    // Update value of POCLastDisplay
1205    iPOCLastDisplay -= deltaPocVal;
1206  }
1207  Int maxPocLsb = 1 << sps->getBitsForPOC();
1208  Int slicePicOrderCntLsb = m_apcSlicePilot->getPicOrderCntLsb();
1209
1210  if( m_pocResettingFlag && (m_parseIdc == 1 || m_parseIdc == 2) )
1211  {
1212    // Set poc for current slice
1213    if( m_apcSlicePilot->getPocResetIdc() == 1 )
1214    {       
1215      m_apcSlicePilot->setPOC( slicePicOrderCntLsb );
1216    }
1217    else if( m_apcSlicePilot->getPocResetIdc() == 2 )
1218    {
1219      m_apcSlicePilot->setPOC( 0 );
1220    }
1221    else 
1222    {
1223      Int picOrderCntMsb = m_apcSlicePilot->getCurrMsb( slicePicOrderCntLsb, m_apcSlicePilot->getFullPocResetFlag() ? 0 : m_apcSlicePilot->getPocLsbVal(), 0 , maxPocLsb );
1224      m_apcSlicePilot->setPOC( picOrderCntMsb + slicePicOrderCntLsb );
1225    }
1226  }
1227  else if (m_parseIdc == 3)
1228  {
1229    Int picOrderCntMsb = 0;
1230    if( m_apcSlicePilot->getPocMsbValPresentFlag() )
1231    {
1232      picOrderCntMsb = m_apcSlicePilot->getPocMsbVal() * maxPocLsb;
1233    }
1234    else if( m_apcSlicePilot->getIdrPicFlag() )
1235    {
1236      picOrderCntMsb = 0;
1237    }
1238    else
1239    {
1240      Int prevPicOrderCntLsb = this->getPrevPicOrderCnt() & ( maxPocLsb - 1);
1241      Int prevPicOrderCntMsb  = this->getPrevPicOrderCnt() - prevPicOrderCntLsb;
1242      picOrderCntMsb = m_apcSlicePilot->getCurrMsb(slicePicOrderCntLsb, prevPicOrderCntLsb, prevPicOrderCntMsb, maxPocLsb );
1243    }
1244    m_apcSlicePilot->setPOC( picOrderCntMsb + slicePicOrderCntLsb );
1245  }
1246
1247#if CONFORMANCE_BITSTREAM_FIX
1248  xUpdatePreviousTid0POC(m_apcSlicePilot);
1249#endif
1250
1251  //detect lost reference picture and insert copy of earlier frame.
1252  {
1253    Int lostPoc;
1254    while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
1255    {
1256      xCreateLostPicture(lostPoc-1);
1257    }
1258  }
1259
1260  if( m_parseIdc == 1 || m_parseIdc == 3)
1261  {
1262    // Adjust prevPicOrderCnt
1263    if(    !m_apcSlicePilot->getRaslPicFlag() 
1264      && !m_apcSlicePilot->getRadlPicFlag()
1265      && (m_apcSlicePilot->getNalUnitType() % 2 == 1
1266#if CONFORMANCE_BITSTREAM_FIX
1267        || (m_apcSlicePilot->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_apcSlicePilot->getNalUnitType() <= NAL_UNIT_RESERVED_IRAP_VCL23)) // should it be NAL_UNIT_CODED_SLICE_CRA instead?
1268#else
1269        )
1270#endif
1271      && ( nalu.m_temporalId == 0 )
1272      && !m_apcSlicePilot->getDiscardableFlag() )
1273    {
1274      for( UInt i = 0; i < numAffectedLayers; i++ )
1275      {
1276        m_ppcTDecTop[affectedLayerList[i]]->setPrevPicOrderCnt(m_apcSlicePilot->getPOC());
1277      }
1278    }
1279    else if( m_apcSlicePilot->getPocResetIdc() == 3 )
1280    {
1281      if( !m_firstPicInLayerDecodedFlag || (m_firstPicInLayerDecodedFlag && m_pocResettingFlag) )
1282      {
1283        for( UInt i = 0; i < numAffectedLayers; i++ )
1284        {
1285          m_ppcTDecTop[affectedLayerList[i]]->setPrevPicOrderCnt( m_apcSlicePilot->getFullPocResetFlag() ? 0 : m_apcSlicePilot->getPocLsbVal() );
1286        }
1287      }
1288    }
1289    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
1290  }
1291
1292  if( !m_apcSlicePilot->getDependentSliceSegmentFlag() && (bNewPOC || m_layerId!=m_uiPrevLayerId || m_parseIdc == 1) && !m_bFirstSliceInSequence )
1293#else
1294  if (!m_apcSlicePilot->getDependentSliceSegmentFlag() && (bNewPOC || m_layerId!=m_uiPrevLayerId) && !m_bFirstSliceInSequence )
1295#endif
1296  {
1297    m_prevPOC = m_apcSlicePilot->getPOC();
1298#if ENC_DEC_TRACE
1299    //rewind the trace counter since we didn't actually decode the slice
1300    g_nSymbolCounter = originalSymbolCount;
1301#endif
1302    curLayerId = m_uiPrevLayerId; 
1303    m_uiPrevLayerId = m_layerId;
1304    return true;
1305  }
1306
1307  m_parseIdc = -1;
1308
1309  if( m_apcSlicePilot->getTLayer() == 0 && m_apcSlicePilot->getEnableTMVPFlag() == 0 )
1310  {
1311    //update all pics in the DPB such that they cannot be used for TMPV ref
1312    TComList<TComPic*>::iterator  iterRefPic = m_cListPic.begin();
1313
1314    while( iterRefPic != m_cListPic.end() )
1315    {
1316      TComPic *refPic = *iterRefPic;
1317      if( ( refPic->getLayerId() == m_apcSlicePilot->getLayerId() ) && refPic->getReconMark() )
1318      {
1319        for( Int i = refPic->getNumAllocatedSlice()-1; i >= 0; i-- )
1320        {
1321
1322          TComSlice *refSlice = refPic->getSlice(i);
1323          refSlice->setAvailableForTMVPRefFlag( false );
1324        }
1325      }
1326      iterRefPic++;
1327    }
1328  }
1329  m_apcSlicePilot->setAvailableForTMVPRefFlag( true );
1330#else //SVC_EXTENSION
1331  //we should only get a different poc for a new picture (with CTU address==0)
1332  if (!m_apcSlicePilot->getDependentSliceSegmentFlag() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (m_apcSlicePilot->getSliceCurStartCtuTsAddr() != 0)) 
1333  {
1334    printf ("Warning, the first slice of a picture might have been lost!\n");
1335  }
1336
1337  // exit when a new picture is found
1338  if (!m_apcSlicePilot->getDependentSliceSegmentFlag() && (m_apcSlicePilot->getSliceCurStartCtuTsAddr() == 0 && !m_bFirstSliceInPicture) )
1339  {
1340    if (m_prevPOC >= m_pocRandomAccess)
1341    {
1342      m_prevPOC = m_apcSlicePilot->getPOC();
1343#if ENC_DEC_TRACE
1344      //rewind the trace counter since we didn't actually decode the slice
1345      g_nSymbolCounter = originalSymbolCount;
1346#endif
1347      return true;
1348    }
1349    m_prevPOC = m_apcSlicePilot->getPOC();
1350  }
1351
1352  //detect lost reference picture and insert copy of earlier frame.
1353  {
1354    Int lostPoc;
1355    while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
1356    {
1357      xCreateLostPicture(lostPoc-1);
1358    }
1359  }
1360#endif //SVC_EXTENSION
1361
1362  if (!m_apcSlicePilot->getDependentSliceSegmentFlag()) 
1363  {
1364    m_prevPOC = m_apcSlicePilot->getPOC();
1365#if SVC_EXTENSION
1366    curLayerId = m_layerId;
1367    m_uiPrevLayerId = m_layerId;
1368#endif
1369  }
1370
1371  // actual decoding starts here
1372  xActivateParameterSets();
1373
1374  m_bFirstSliceInSequence = false;
1375  m_bFirstSliceInBitstream  = false;
1376
1377  TComSlice* pcSlice = m_pcPic->getPicSym()->getSlice(m_uiSliceIdx);
1378
1379#if SVC_EXTENSION
1380  if (m_bFirstSliceInPicture)
1381  {
1382    // Initialize ILRP if needed, only for the current layer 
1383    // ILRP intialization should go along with activation of parameters sets,
1384    // although activation of parameter sets itself need not be done for each and every slice!!!
1385    xInitILRP(pcSlice->getSPS(), pcSlice->getPPS());
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->requireResampling(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(const TComSPS *sps, const TComPPS *pps)
2263{
2264  if( m_layerId > 0 )
2265  {
2266    if (m_cIlpPic[0] == NULL)
2267    {
2268      for (Int j=0; j < m_numDirectRefLayers; j++)
2269      {
2270        m_cIlpPic[j] = new  TComPic;
2271
2272        m_cIlpPic[j]->create(*sps, *pps, true, m_layerId);
2273
2274        for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCtusInFrame(); i++)
2275        {
2276          m_cIlpPic[j]->getPicSym()->getCtu(i)->initCtu(m_cIlpPic[j], i);
2277        }
2278      }
2279    }
2280  }
2281}
2282
2283TDecTop* TDecTop::getRefLayerDec( UInt refLayerIdx )
2284{
2285  const TComVPS* vps = m_parameterSetManager.getActiveVPS();
2286  if( vps->getNumDirectRefLayers( m_layerId ) <= 0 )
2287  {
2288    return (TDecTop *)getLayerDec( 0 );
2289  }
2290 
2291  return (TDecTop *)getLayerDec( vps->getRefLayerId( m_layerId, refLayerIdx ) );
2292}
2293
2294Void TDecTop::setRefLayerParams( const TComVPS* vps )
2295{
2296  for(UInt layerIdx = 0; layerIdx < m_numLayer; layerIdx++)
2297  {
2298    TDecTop *decTop = (TDecTop *)getLayerDec(vps->getLayerIdInNuh(layerIdx));
2299    decTop->setNumSamplePredRefLayers(0);
2300    decTop->setNumMotionPredRefLayers(0);
2301    decTop->setNumDirectRefLayers(0);
2302
2303    for(Int j = 0; j < layerIdx; j++)
2304    {
2305      if (vps->getDirectDependencyFlag(layerIdx, j))
2306      {
2307        decTop->setRefLayerId(decTop->getNumDirectRefLayers(), vps->getLayerIdInNuh(layerIdx));
2308        decTop->setNumDirectRefLayers(decTop->getNumDirectRefLayers() + 1);
2309
2310        Int samplePredEnabledFlag = (vps->getDirectDependencyType(layerIdx, j) + 1) & 1;
2311        decTop->setNumSamplePredRefLayers(decTop->getNumSamplePredRefLayers() + samplePredEnabledFlag);
2312
2313        Int motionPredEnabledFlag = ((vps->getDirectDependencyType(layerIdx, j) + 1) & 2) >> 1;
2314        decTop->setNumMotionPredRefLayers(decTop->getNumMotionPredRefLayers() + motionPredEnabledFlag);
2315      }
2316    }
2317  }
2318}
2319
2320Void TDecTop::checkValueOfTargetOutputLayerSetIdx(TComVPS *vps)
2321{
2322  CommonDecoderParams* params = this->getCommonDecoderParams();
2323
2324  if( params->getValueCheckedFlag() )
2325  {
2326    return; // Already checked
2327  }
2328
2329  if( params->getTargetOutputLayerSetIdx() == -1 )  // Output layer set index not specified
2330  {
2331    if( params->getTargetLayerId() > vps->getMaxLayerId() )
2332    {
2333      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() );
2334      params->setTargetLayerId( vps->getMaxLayerId() );
2335    }
2336
2337    Bool layerSetMatchFound = false;
2338    // Output layer set index not assigned.
2339    // Based on the value of targetLayerId, check if any of the output layer matches
2340    // Currently, the target layer ID in the encoder assumes that all the layers are decoded   
2341    // Check if any of the output layer sets match this description
2342    for( Int i = 0; i < vps->getNumOutputLayerSets(); i++ )
2343    {
2344      Bool layerSetMatchFlag = false;
2345      Int layerSetIdx = vps->getOutputLayerSetIdx( i );
2346
2347      for( Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++ )
2348      {
2349        if( vps->getLayerSetLayerIdList( layerSetIdx, j ) == params->getTargetLayerId() )
2350        {
2351          layerSetMatchFlag = true;
2352          break;
2353        }
2354      }
2355     
2356      if( layerSetMatchFlag ) // Potential output layer set candidate found
2357      {
2358        // If target dec layer ID list is also included - check if they match
2359        if( params->getTargetDecLayerIdSet() )
2360        {
2361          if( params->getTargetDecLayerIdSet()->size() ) 
2362          {
2363            for( Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++ )
2364            {
2365              if( *(params->getTargetDecLayerIdSet()->begin() + j) != vps->getLayerIdInNuh(vps->getLayerSetLayerIdList( layerSetIdx, j )))
2366              {
2367                layerSetMatchFlag = false;
2368              }
2369            }
2370          }
2371        }
2372        if( layerSetMatchFlag ) // The target dec layer ID list also matches, if present
2373        {
2374          // Match found
2375          layerSetMatchFound = true;
2376          params->setTargetOutputLayerSetIdx( i );
2377          params->setValueCheckedFlag( true );
2378          break;
2379        }
2380      }
2381    }
2382    assert( layerSetMatchFound ); // No output layer set matched the value of either targetLayerId or targetdeclayerIdlist
2383  }   
2384  else // Output layer set index is assigned - check if the values match
2385  {
2386    // Check if the target decoded layer is the highest layer in the list
2387    assert( params->getTargetOutputLayerSetIdx() < vps->getNumOutputLayerSets() );
2388#if !CONFORMANCE_BITSTREAM_MODE
2389    assert( params->getTargetOutputLayerSetIdx() < vps->getNumLayerSets() );
2390#endif
2391    Int layerSetIdx = vps->getOutputLayerSetIdx( params->getTargetOutputLayerSetIdx() );  // Index to the layer set
2392#if !CONFORMANCE_BITSTREAM_MODE
2393    assert( params->getTargetLayerId() == vps->getNumLayersInIdList( layerSetIdx ) - 1);
2394#endif
2395   
2396    // Check if the targetdeclayerIdlist matches the output layer set
2397    if( params->getTargetDecLayerIdSet() )
2398    {
2399      if( params->getTargetDecLayerIdSet()->size() ) 
2400      {
2401        for(Int i = 0; i < vps->getNumLayersInIdList( layerSetIdx ); i++)
2402        {
2403          assert( *(params->getTargetDecLayerIdSet()->begin() + i) == vps->getLayerIdInNuh(vps->getLayerSetLayerIdList( layerSetIdx, i )));
2404        }
2405      }
2406    }
2407    params->setValueCheckedFlag( true );
2408
2409  }
2410
2411  // Set correct value of targetLayerId
2412  Int targetOlsIdx = params->getTargetOutputLayerSetIdx();
2413  Int targetLsIdx = vps->getOutputLayerSetIdx( targetOlsIdx );
2414  params->setTargetLayerId( vps->getLayerSetLayerIdList( targetLsIdx, vps->getNumLayersInIdList(targetLsIdx)-1 ) );
2415
2416  // Check if the current layer is an output layer
2417  for( Int i = 0; i < vps->getNumLayersInIdList( targetLsIdx ); i++ )
2418  {
2419    if( vps->getOutputLayerFlag( targetOlsIdx, i ) )
2420    {
2421      m_ppcTDecTop[vps->getLayerSetLayerIdList( targetLsIdx, i )]->m_isOutputLayerFlag = true;
2422    }
2423  }
2424}
2425
2426Void TDecTop::markAllPicsAsNoCurrAu( const TComVPS *vps )
2427{
2428  for(Int i = 0; i < MAX_LAYERS; i++)
2429  {
2430    TComList<TComPic*>* listPic = m_ppcTDecTop[vps->getLayerIdInNuh(i)]->getListPic();
2431    TComList<TComPic*>::iterator  iterPic = listPic->begin();
2432    while ( iterPic != listPic->end() )
2433    {
2434      TComPic *pcPic = *(iterPic);
2435      pcPic->setCurrAuFlag( false );
2436      iterPic++;
2437    }
2438  }
2439}
2440
2441#if CGS_3D_ASYMLUT
2442Void TDecTop::initAsymLut(TComSlice *pcSlice)
2443{
2444  if( m_layerId > 0 )
2445  {
2446    if( !m_pColorMappedPic )
2447    {
2448      m_pColorMappedPic = new TComPicYuv;
2449      m_pColorMappedPic->create( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), pcSlice->getSPS()->getChromaFormatIdc(), pcSlice->getSPS()->getMaxCUWidth(), pcSlice->getSPS()->getMaxCUHeight(), pcSlice->getSPS()->getMaxTotalCUDepth(), true, NULL );
2450    }
2451  }
2452}
2453#endif
2454
2455Void TDecTop::resetPocRestrictionCheckParameters()
2456{
2457  TDecTop::m_checkPocRestrictionsForCurrAu       = false;
2458  TDecTop::m_pocResetIdcOrCurrAu                 = -1;
2459  TDecTop::m_baseLayerIdrFlag                    = false;
2460  TDecTop::m_baseLayerPicPresentFlag             = false;
2461  TDecTop::m_baseLayerIrapFlag                   = false;
2462  TDecTop::m_nonBaseIdrPresentFlag               = false;
2463  TDecTop::m_nonBaseIdrType                      = -1;
2464  TDecTop::m_picNonIdrWithRadlPresentFlag        = false;
2465  TDecTop::m_picNonIdrNoLpPresentFlag            = false;
2466}
2467
2468Void TDecTop::xCheckLayerReset()
2469{
2470  if (m_apcSlicePilot->isIRAP() && m_layerId > m_smallestLayerId)
2471  {
2472    Bool layerResetFlag;
2473    UInt dolLayerId;
2474    if (m_lastPicHasEos)
2475    {
2476      layerResetFlag = true;
2477      dolLayerId = m_layerId;
2478    }
2479    else if ((m_apcSlicePilot->isCRA() && m_apcSlicePilot->getHandleCraAsBlaFlag()) ||
2480      (m_apcSlicePilot->isIDR() && m_apcSlicePilot->getCrossLayerBLAFlag()) || m_apcSlicePilot->isBLA())
2481    {
2482      layerResetFlag = true;
2483      dolLayerId = m_layerId;
2484    }
2485    else
2486    {
2487      layerResetFlag = false;
2488    }
2489
2490    if (layerResetFlag)
2491    {
2492      for (Int i = 0; i < m_apcSlicePilot->getVPS()->getNumPredictedLayers(dolLayerId); i++)
2493      {
2494        UInt iLayerId = m_apcSlicePilot->getVPS()->getPredictedLayerId(dolLayerId, i);
2495        m_ppcTDecTop[iLayerId]->m_layerInitializedFlag = false;
2496        m_ppcTDecTop[iLayerId]->m_firstPicInLayerDecodedFlag = false;
2497      }
2498
2499      for (TComList<TComPic*>::iterator i = m_cListPic.begin(); i != m_cListPic.end(); i++)
2500      {
2501        if ((*i)->getPOC() != m_apcSlicePilot->getPOC())
2502        {
2503          (*i)->getSlice(0)->setReferenced(false);
2504        }
2505      }
2506
2507      for (UInt i = 0; i < m_apcSlicePilot->getVPS()->getNumPredictedLayers(dolLayerId); i++)
2508      {
2509        UInt predLId = m_apcSlicePilot->getVPS()->getPredictedLayerId(dolLayerId, i);
2510        for (TComList<TComPic*>::iterator pic = m_ppcTDecTop[predLId]->getListPic()->begin(); pic != m_ppcTDecTop[predLId]->getListPic()->end(); pic++)
2511        {
2512          if ((*pic)->getSlice(0)->getPOC() != m_apcSlicePilot->getPOC())
2513          {
2514            (*pic)->getSlice(0)->setReferenced(false);
2515          }
2516        }
2517      }
2518    }
2519  }
2520}
2521
2522Void TDecTop::xSetLayerInitializedFlag()
2523{
2524  if (m_apcSlicePilot->isIRAP() && m_apcSlicePilot->getNoRaslOutputFlag())
2525  {
2526    if (m_layerId == 0)
2527    {
2528      m_ppcTDecTop[m_layerId]->setLayerInitializedFlag(true);
2529    }
2530    else if (!m_ppcTDecTop[m_layerId]->getLayerInitializedFlag() && m_apcSlicePilot->getVPS()->getNumDirectRefLayers(m_layerId) == 0)
2531    {
2532      m_ppcTDecTop[m_layerId]->setLayerInitializedFlag(true);
2533    }
2534    else if (!m_ppcTDecTop[m_layerId]->getLayerInitializedFlag())
2535    {
2536      Bool refLayersInitialized = true;
2537      for (UInt j = 0; j < m_apcSlicePilot->getVPS()->getNumDirectRefLayers(m_layerId); j++)
2538      {
2539        UInt refLayerId = m_apcSlicePilot->getVPS()->getRefLayerId(m_layerId, j);
2540        if (!m_ppcTDecTop[refLayerId]->getLayerInitializedFlag())
2541        {
2542          refLayersInitialized = false;
2543        }
2544      }
2545      if (refLayersInitialized)
2546      {
2547        m_ppcTDecTop[m_layerId]->setLayerInitializedFlag(true);
2548      }
2549    }
2550  }
2551}
2552
2553Void TDecTop::xDeriveSmallestLayerId(TComVPS* vps)
2554{
2555  UInt smallestLayerId;
2556  Int  targetOlsIdx = m_commonDecoderParams->getTargetOutputLayerSetIdx();
2557  assert( targetOlsIdx >= 0 );
2558
2559  // list of layers to be decoded is not built yet
2560  m_targetDecLayerIdList.resize(0);
2561
2562  UInt targetDecLayerSetIdx = vps->getOutputLayerSetIdx(targetOlsIdx);
2563  UInt lsIdx = targetDecLayerSetIdx;
2564 
2565  for (UInt i = 0; i < vps->getNumLayersInIdList(lsIdx); i++)
2566  {
2567    if (vps->getNecessaryLayerFlag(targetOlsIdx, i))
2568    {
2569      m_targetDecLayerIdList.push_back( vps->getLayerSetLayerIdList(lsIdx, i) );
2570    }
2571  }
2572
2573  if (targetDecLayerSetIdx <= vps->getVpsNumLayerSetsMinus1())
2574  {
2575    smallestLayerId = 0;
2576  }
2577  else if (vps->getNumLayersInIdList(targetDecLayerSetIdx) == 1)
2578  {
2579    smallestLayerId = 0;
2580  }
2581  else
2582  {
2583    smallestLayerId = m_targetDecLayerIdList[0];
2584  }
2585
2586  for( UInt layerId = 0; layerId < MAX_VPS_LAYER_IDX_PLUS1; layerId++ )
2587  {
2588    m_ppcTDecTop[layerId]->m_smallestLayerId = smallestLayerId;
2589  }
2590}
2591
2592Void TDecTop::xSetRequireResamplingFlag( const TComVPS &vps, const TComSPS &sps, const TComPPS &pps, TComPic* pic )
2593{
2594  for(UInt i = 0; i < vps.getNumDirectRefLayers( m_layerId ); i++ )
2595  {
2596    const Window scalEL = pps.getScaledRefLayerWindowForLayer(vps.getRefLayerId(m_layerId, i));
2597    const Window refEL = pps.getRefLayerWindowForLayer(vps.getRefLayerId(m_layerId, i));
2598    Bool equalOffsets = scalEL.hasEqualOffset(refEL);
2599    Bool zeroPhase = pps.hasZeroResamplingPhase(vps.getRefLayerId(m_layerId, i));
2600
2601    TDecTop *pcTDecTopBase = (TDecTop *)getRefLayerDec( i );
2602    TComPicYuv* pcPicYuvRecBase = (*(pcTDecTopBase->getListPic()->begin()))->getPicYuvRec();
2603
2604    const Int bitDepthLuma = sps.getBitDepth(CHANNEL_TYPE_LUMA);
2605    const Int bitDepthChroma = sps.getBitDepth(CHANNEL_TYPE_CHROMA);
2606    const Int refBitDepthLuma = (*(pcTDecTopBase->getListPic()->begin()))->getSlice(0)->getSPS()->getBitDepth(CHANNEL_TYPE_LUMA);
2607    const Int refBitDepthChroma = (*(pcTDecTopBase->getListPic()->begin()))->getSlice(0)->getSPS()->getBitDepth(CHANNEL_TYPE_CHROMA);
2608   
2609    Bool sameBitDepths = ( bitDepthLuma == refBitDepthLuma ) && ( bitDepthChroma == refBitDepthChroma );
2610
2611    if( pcPicYuvRecBase->getWidth(COMPONENT_Y) == sps.getPicWidthInLumaSamples() && pcPicYuvRecBase->getHeight(COMPONENT_Y) == sps.getPicHeightInLumaSamples() && equalOffsets && zeroPhase )
2612    {
2613      pic->setEqualPictureSizeAndOffsetFlag( i, true );
2614    }
2615
2616    if( !pic->equalPictureSizeAndOffsetFlag(i) || !sameBitDepths
2617#if CGS_3D_ASYMLUT
2618      || pps.getCGSFlag() > 0
2619#endif
2620      )
2621    {
2622      pic->setRequireResamplingFlag( i, true );
2623
2624      //only for scalable extension
2625      assert( vps.getScalabilityMask( SCALABILITY_ID ) == true );
2626    }
2627  }
2628}
2629
2630#endif //SVC_EXTENSION
2631
2632
2633//! \}
Note: See TracBrowser for help on using the repository browser.