source: SHVCSoftware/branches/SHM-temp/source/Lib/TLibDecoder/TDecTop.cpp @ 1041

Last change on this file since 1041 was 1040, checked in by interdigital, 10 years ago

fixed couple if statements using fixed layerId value "m_layerId == 1" as test condition

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