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

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

code rearrangement

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