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

Last change on this file since 1218 was 1213, checked in by seregin, 11 years ago

macro cleanup: R0150_CGS_SIGNAL_CONSTRAINTS

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