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

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

port rev 4260

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