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

Last change on this file since 1547 was 1534, checked in by seregin, 9 years ago

integration of multi-view support from JCTVC-W0134

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