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

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

update get chroma format idc, patched-by Guillaume Barroux<guillaume.b@…>

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