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

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

port implementation of JCTVC-R0071 - IRAP and EOS cross-layer impacts (rev 978)

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