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

Last change on this file since 1157 was 1150, checked in by seregin, 9 years ago

macro cleanup: O0149_CROSS_LAYER_BLA_FLAG

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