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

Last change on this file since 1222 was 1220, checked in by seregin, 10 years ago

macro cleanup: Q0177_EOS_CHECKS

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