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

Last change on this file since 891 was 884, checked in by nokia, 11 years ago

implementation of jct-vc R0247
(1) Only the base layer creates the Active Parameter Sets SEI message.
(2) Active Parameter Sets SEI message can active more than 1 sps.

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