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

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

remove global variables g_mvScalingFactor and g_posScalingFactor, and make them TComPic members

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