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

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

fix inference for sps_max_dec_pic_buffering_minus1

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