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

Last change on this file since 1005 was 1005, checked in by nokia, 10 years ago

Implementation of JCTVC-R0235 - Processing of bitstreams without an available base layer

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