source: SHVCSoftware/branches/SHM-upgrade/source/Lib/TLibDecoder/TDecTop.cpp @ 1311

Last change on this file since 1311 was 1022, checked in by seregin, 10 years ago

fix for the SAO width and height setting

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