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

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

fix variable name

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