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

Last change on this file since 1011 was 1009, checked in by seregin, 11 years ago

fix for the ticket #56

  • Property svn:eol-style set to native
File size: 118.7 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6 * Copyright (c) 2010-2014, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TDecTop.cpp
35    \brief    decoder class
36*/
37
38#include "NALread.h"
39#include "TDecTop.h"
40
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#if P0182_VPS_VUI_PS_FLAG
938    UInt layerIdx = activeVPS->getLayerIdInVps( m_layerId );
939
940    if( activeVPS->getBaseLayerPSCompatibilityFlag(layerIdx) )
941    {
942      RepFormat* repFormat = activeVPS->getVpsRepFormat(activeVPS->getVpsRepFormatIdx(layerIdx));
943
944      assert( pps->getLayerId() == 0 );
945      assert( sps->getLayerId() == 0 );
946      assert( repFormat->getChromaFormatVpsIdc() == sps->getChromaFormatIdc() );
947      assert( repFormat->getSeparateColourPlaneVpsFlag() == 0 );
948      assert( repFormat->getPicHeightVpsInLumaSamples() == sps->getPicHeightInLumaSamples() );
949      assert( repFormat->getPicWidthVpsInLumaSamples()  == sps->getPicWidthInLumaSamples() );
950      assert( repFormat->getBitDepthVpsLuma()   == sps->getBitDepthY() );
951      assert( repFormat->getBitDepthVpsChroma() == sps->getBitDepthC() );
952      assert( repFormat->getConformanceWindowVps().getWindowLeftOffset()   == sps->getConformanceWindow().getWindowLeftOffset() );
953      assert( repFormat->getConformanceWindowVps().getWindowRightOffset()  == sps->getConformanceWindow().getWindowRightOffset() );
954      assert( repFormat->getConformanceWindowVps().getWindowTopOffset()    == sps->getConformanceWindow().getWindowTopOffset() );
955      assert( repFormat->getConformanceWindowVps().getWindowBottomOffset() == sps->getConformanceWindow().getWindowBottomOffset() );
956    }   
957#endif
958  }
959#endif
960
961  if( pps->getDependentSliceSegmentsEnabledFlag() )
962  {
963    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
964
965    if (m_cSliceDecoder.getCtxMemSize() != NumCtx)
966    {
967      m_cSliceDecoder.initCtxMem(NumCtx);
968      for ( UInt st = 0; st < NumCtx; st++ )
969      {
970        TDecSbac* ctx = NULL;
971        ctx = new TDecSbac;
972        ctx->init( &m_cBinCABAC );
973        m_cSliceDecoder.setCtxMem( ctx, st );
974      }
975    }
976  }
977
978  m_apcSlicePilot->setPPS(pps);
979  m_apcSlicePilot->setSPS(sps);
980  pps->setSPS(sps);
981#if REPN_FORMAT_IN_VPS
982  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumTileColumnsMinus1() + 1) : 1);
983#else
984  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumTileColumnsMinus1() + 1) : 1);
985#endif
986  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
987
988#if REPN_FORMAT_IN_VPS
989  g_bitDepthY     = m_apcSlicePilot->getBitDepthY();
990  g_bitDepthC     = m_apcSlicePilot->getBitDepthC();
991#else
992  g_bitDepthY     = sps->getBitDepthY();
993  g_bitDepthC     = sps->getBitDepthC();
994#endif
995  g_uiMaxCUWidth  = sps->getMaxCUWidth();
996  g_uiMaxCUHeight = sps->getMaxCUHeight();
997  g_uiMaxCUDepth  = sps->getMaxCUDepth();
998  g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() );
999
1000  for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++)
1001  {
1002    sps->setAMPAcc( i, sps->getUseAMP() );
1003  }
1004
1005  for (Int i = sps->getLog2DiffMaxMinCodingBlockSize(); i < sps->getMaxCUDepth(); i++)
1006  {
1007    sps->setAMPAcc( i, 0 );
1008  }
1009
1010  m_cSAO.destroy();
1011#if REPN_FORMAT_IN_VPS
1012#if AUXILIARY_PICTURES
1013  m_cSAO.create( m_apcSlicePilot->getPicWidthInLumaSamples(), m_apcSlicePilot->getPicHeightInLumaSamples(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() );
1014#else
1015  m_cSAO.create( m_apcSlicePilot->getPicWidthInLumaSamples(), m_apcSlicePilot->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() );
1016#endif
1017#else
1018  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() );
1019#endif
1020  m_cLoopFilter.create( sps->getMaxCUDepth() );
1021}
1022
1023#if SVC_EXTENSION
1024#if POC_RESET_FLAG
1025Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int &iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC )
1026#else
1027Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC )
1028#endif
1029#else
1030Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
1031#endif
1032{
1033  TComPic*&   pcPic         = m_pcPic;
1034#if SVC_EXTENSION
1035  m_apcSlicePilot->setVPS( m_parameterSetManagerDecoder.getPrefetchedVPS(0) );
1036#if OUTPUT_LAYER_SET_INDEX
1037  // Following check should go wherever the VPS is activated
1038#if R0235_SMALLEST_LAYER_ID
1039  if (!m_apcSlicePilot->getVPS()->getBaseLayerAvailableFlag())
1040  {
1041    assert(nalu.m_layerId != 0);
1042    assert(m_apcSlicePilot->getVPS()->getNumAddLayerSets() > 0);
1043    if (getCommonDecoderParams()->getTargetOutputLayerSetIdx() >= 0)
1044    {
1045      UInt layerIdx = m_apcSlicePilot->getVPS()->getOutputLayerSetIdx(getCommonDecoderParams()->getTargetOutputLayerSetIdx());
1046      assert(layerIdx > m_apcSlicePilot->getVPS()->getVpsNumLayerSetsMinus1());
1047    }
1048  }
1049#else
1050  checkValueOfTargetOutputLayerSetIdx(m_apcSlicePilot->getVPS());
1051#endif
1052#endif
1053#if RESOLUTION_BASED_DPB
1054  // Following assignment should go wherever a new VPS is activated
1055  assignSubDpbs(m_apcSlicePilot->getVPS());
1056#endif
1057  m_apcSlicePilot->initSlice( nalu.m_layerId );
1058#else //SVC_EXTENSION
1059  m_apcSlicePilot->initSlice();
1060#endif
1061
1062  if (m_bFirstSliceInPicture)
1063  {
1064    m_uiSliceIdx     = 0;
1065  }
1066  else
1067  {
1068    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
1069  }
1070  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
1071
1072  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
1073#if POC_RESET_RESTRICTIONS
1074  m_apcSlicePilot->setTLayer( nalu.m_temporalId );
1075#endif
1076  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
1077                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
1078                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
1079                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
1080                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
1081  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
1082 
1083  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
1084  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
1085
1086#if SVC_EXTENSION
1087#if VPS_EXTN_DIRECT_REF_LAYERS
1088  setRefLayerParams(m_apcSlicePilot->getVPS());
1089#endif
1090  m_apcSlicePilot->setNumMotionPredRefLayers(m_numMotionPredRefLayers);
1091#endif
1092  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
1093
1094  // set POC for dependent slices in skipped pictures
1095  if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped) 
1096  {
1097    m_apcSlicePilot->setPOC(m_skippedPOC);
1098  }
1099
1100  m_apcSlicePilot->setAssociatedIRAPPOC(m_pocCRA);
1101  m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType);
1102
1103#if SETTING_NO_OUT_PIC_PRIOR
1104  //For inference of NoOutputOfPriorPicsFlag
1105  if (m_apcSlicePilot->getRapPicFlag())
1106  {
1107    if ((m_apcSlicePilot->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_apcSlicePilot->getNalUnitType() <= NAL_UNIT_CODED_SLICE_IDR_N_LP) || 
1108        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_bFirstSliceInSequence) ||
1109        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getHandleCraAsBlaFlag()))
1110    {
1111      m_apcSlicePilot->setNoRaslOutputFlag(true);
1112    }
1113    //the inference for NoOutputPriorPicsFlag
1114    if (!m_bFirstSliceInBitstream && m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag())
1115    {
1116      if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
1117      {
1118        m_apcSlicePilot->setNoOutputPriorPicsFlag(true);
1119      }
1120    }
1121    else
1122    {
1123      m_apcSlicePilot->setNoOutputPriorPicsFlag(false);
1124    }
1125
1126    if(m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
1127    {
1128      m_craNoRaslOutputFlag = m_apcSlicePilot->getNoRaslOutputFlag();
1129    }
1130  }
1131  if (m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoOutputPriorPicsFlag())
1132  {
1133    m_lastPOCNoOutputPriorPics = m_apcSlicePilot->getPOC();
1134    m_isNoOutputPriorPics = true;
1135  }
1136  else
1137  {
1138    m_isNoOutputPriorPics = false;
1139  }
1140
1141  //For inference of PicOutputFlag
1142  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R)
1143  {
1144    if ( m_craNoRaslOutputFlag )
1145    {
1146      m_apcSlicePilot->setPicOutputFlag(false);
1147    }
1148  }
1149#endif
1150
1151#if FIX_POC_CRA_NORASL_OUTPUT
1152  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_craNoRaslOutputFlag) //Reset POC MSB when CRA has NoRaslOutputFlag equal to 1
1153  {
1154    Int iMaxPOClsb = 1 << m_apcSlicePilot->getSPS()->getBitsForPOC();
1155    m_apcSlicePilot->setPOC( m_apcSlicePilot->getPOC() & (iMaxPOClsb - 1) );
1156  }
1157#endif
1158
1159  // Skip pictures due to random access
1160  if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
1161  {
1162    m_prevSliceSkipped = true;
1163    m_skippedPOC = m_apcSlicePilot->getPOC();
1164    return false;
1165  }
1166  // Skip TFD pictures associated with BLA/BLANT pictures
1167  if (isSkipPictureForBLA(iPOCLastDisplay))
1168  {
1169    m_prevSliceSkipped = true;
1170    m_skippedPOC = m_apcSlicePilot->getPOC();
1171    return false;
1172  }
1173
1174  // clear previous slice skipped flag
1175  m_prevSliceSkipped = false;
1176
1177  // exit when a new picture is found
1178#if SVC_EXTENSION
1179  bNewPOC = (m_apcSlicePilot->getPOC()!= m_prevPOC);
1180
1181#if NO_OUTPUT_OF_PRIOR_PICS
1182#if NO_CLRAS_OUTPUT_FLAG
1183#if R0235_SMALLEST_LAYER_ID
1184  if (m_layerId == m_smallestLayerId && m_apcSlicePilot->getRapPicFlag())
1185#else
1186  if (m_layerId == 0 && m_apcSlicePilot->getRapPicFlag() )
1187#endif
1188  {
1189    if (m_bFirstSliceInSequence)
1190    {
1191      setNoClrasOutputFlag(true);
1192    }
1193#if R0071_IRAP_EOS_CROSS_LAYER_IMPACTS
1194    else if (m_lastPicHasEos)
1195    {
1196      setNoClrasOutputFlag(true);
1197    }
1198#endif
1199    else if ( m_apcSlicePilot->getBlaPicFlag() )
1200    {
1201      setNoClrasOutputFlag(true);
1202    }
1203#if O0149_CROSS_LAYER_BLA_FLAG
1204    else if (m_apcSlicePilot->getIdrPicFlag() && m_apcSlicePilot->getCrossLayerBLAFlag())
1205    {
1206      setNoClrasOutputFlag(true);
1207    }
1208#endif
1209    else
1210    {
1211      setNoClrasOutputFlag(false);
1212    }     
1213  }
1214  else
1215  {
1216    setNoClrasOutputFlag(false);
1217  }
1218
1219#if R0235_SMALLEST_LAYER_ID
1220  m_apcSlicePilot->decodingRefreshMarking( m_cListPic, m_noClrasOutputFlag, m_smallestLayerId );
1221#else
1222  m_apcSlicePilot->decodingRefreshMarking( m_cListPic, m_noClrasOutputFlag );
1223#endif
1224#endif
1225
1226  // Derive the value of NoOutputOfPriorPicsFlag
1227  if( bNewPOC || m_layerId!=m_uiPrevLayerId )   // i.e. new coded picture
1228  {
1229    if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getNoRaslOutputFlag() )
1230    {
1231      this->setNoOutputPriorPicsFlag( true );
1232    }
1233    else if( m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag() )
1234    {
1235      this->setNoOutputPriorPicsFlag( m_apcSlicePilot->getNoOutputPriorPicsFlag() );
1236    }
1237    else
1238    {
1239      if( this->m_ppcTDecTop[0]->getNoClrasOutputFlag() )
1240      {
1241        this->setNoOutputPriorPicsFlag( true );
1242      }
1243    }
1244  }
1245#endif
1246
1247#if POC_RESET_IDC_DECODER
1248  if( m_parseIdc != -1 ) // Second pass for a POC resetting picture
1249  {
1250    m_parseIdc++; // Proceed to POC decoding and RPS derivation
1251  }
1252 
1253  if( m_parseIdc == 2 )
1254  {
1255    bNewPOC = false;
1256  }
1257
1258  if( (bNewPOC || m_layerId!=m_uiPrevLayerId) && (m_parseIdc == -1) ) // Will be true at the first pass
1259  {
1260  //if (bNewPOC || m_layerId!=m_uiPrevLayerId)
1261  // Check if new reset period has started - this is needed just so that the SHM decoder which calls slice header decoding twice
1262  // does not invoke the output twice
1263  //if( m_lastPocPeriodId[m_apcSlicePilot->getLayerId()] == m_apcSlicePilot->getPocResetPeriodId() )
1264    // Update CurrAU marking
1265    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
1266    {
1267#if POC_RESET_RESTRICTIONS
1268      // New access unit; reset all variables related to POC reset restrictions
1269      resetPocRestrictionCheckParameters();
1270#endif
1271      markAllPicsAsNoCurrAu();
1272#if P0297_VPS_POC_LSB_ALIGNED_FLAG
1273      for (UInt i = 0; i < MAX_LAYERS; i++)
1274      {
1275        m_ppcTDecTop[i]->m_pocDecrementedInDPBFlag = false;
1276      }
1277#endif
1278    }
1279
1280
1281#if P0297_VPS_POC_LSB_ALIGNED_FLAG
1282    m_pocResettingFlag = false;
1283
1284    if (m_apcSlicePilot->getPocResetIdc() != 0)
1285    {
1286      if (m_apcSlicePilot->getVPS()->getVpsPocLsbAlignedFlag())
1287      {
1288        m_pocResettingFlag = true;
1289      }
1290      else if (m_pocDecrementedInDPBFlag)
1291      {
1292        m_pocResettingFlag = false;
1293      }
1294      else
1295      {
1296        m_pocResettingFlag = true;
1297      }
1298    }
1299#endif
1300
1301    if( m_apcSlicePilot->getPocResetIdc() && m_apcSlicePilot->getSliceIdx() == 0 )
1302    {
1303      Int pocResetPeriodId = m_apcSlicePilot->getPocResetPeriodId();
1304      if ( m_apcSlicePilot->getPocResetIdc() == 1 || m_apcSlicePilot->getPocResetIdc() == 2 ||
1305        ( m_apcSlicePilot->getPocResetIdc() == 3 && pocResetPeriodId != getLastPocPeriodId() ) )
1306      {
1307        setLastPocPeriodId(pocResetPeriodId);
1308        m_parseIdc = 0;
1309      }
1310#if POC_RESET_VALUE_RESTRICTION
1311      // Check if the POC Reset period ID matches with the Reset Period ID
1312      if( pocResetPeriodId == m_crossLayerPocResetPeriodId )
1313      {
1314        // If matching, and current poc_reset_idc = 3, then the values should match
1315        if( m_apcSlicePilot->getPocResetIdc() == 3 )
1316        {
1317          assert( ( m_apcSlicePilot->getFullPocResetFlag() == false && m_crossLayerPocResetIdc == 1 ) ||
1318                  ( m_apcSlicePilot->getFullPocResetFlag() == true  && m_crossLayerPocResetIdc == 2 ) );
1319        }
1320      }
1321      else
1322      {
1323        // This is the first picture of a POC resetting access unit
1324        m_crossLayerPocResetPeriodId = pocResetPeriodId;
1325        if( m_apcSlicePilot->getPocResetIdc() == 1 || m_apcSlicePilot->getPocResetIdc() == 2 )
1326        {
1327          m_crossLayerPocResetIdc = m_apcSlicePilot->getPocResetIdc();
1328        }
1329        else
1330        { // poc_reset_idc = 3
1331          // In this case, the entire POC resetting access unit has been lost.
1332          // Need more checking to ensure poc_reset_idc = 3 works.
1333          assert ( 0 );
1334        }
1335      }
1336#endif
1337    }
1338    else
1339    {
1340      m_parseIdc = 3; // Proceed to decoding POC and RPS
1341    }
1342  }
1343#endif
1344
1345#if ALIGNED_BUMPING
1346#if POC_RESET_IDC_DECODER
1347
1348#if P0297_VPS_POC_LSB_ALIGNED_FLAG
1349  UInt affectedLayerList[MAX_NUM_LAYER_IDS];
1350  Int  numAffectedLayers;
1351
1352  affectedLayerList[0] = m_apcSlicePilot->getLayerId();
1353  numAffectedLayers = 1;
1354
1355  if (m_apcSlicePilot->getVPS()->getVpsPocLsbAlignedFlag())
1356  {
1357    for (UInt j = 0; j < m_apcSlicePilot->getVPS()->getNumPredictedLayers(m_apcSlicePilot->getLayerId()); j++)
1358    {
1359      affectedLayerList[j + 1] = m_apcSlicePilot->getVPS()->getPredictedLayerId(m_apcSlicePilot->getLayerId(), j);
1360    }
1361    numAffectedLayers = m_apcSlicePilot->getVPS()->getNumPredictedLayers(m_apcSlicePilot->getLayerId()) + 1;
1362  }
1363#endif
1364
1365  //if(  (bNewPOC || m_layerId != m_uiPrevLayerId) && ( m_parseIdc != 1) )
1366#if P0297_VPS_POC_LSB_ALIGNED_FLAG
1367  if (m_parseIdc == 1 && m_pocResettingFlag)
1368#else
1369  if (m_parseIdc == 1)
1370#endif
1371  {
1372    // Invoke output of pictures if the current picture is a POC reset picture
1373    bNewPOC = true;
1374    /* Include reset of all POCs in the layer */
1375
1376  // This operation would do the following:
1377  // 1. Update the other picture in the DPB. This should be done only for the first slice of the picture.
1378  // 2. Update the value of m_pocCRA.
1379  // 3. Reset the POC values at the decoder for the current picture to be zero - will be done later
1380  // 4. update value of POCLastDisplay
1381     
1382  //Do the reset stuff here
1383    Int maxPocLsb = 1 << m_apcSlicePilot->getSPS()->getBitsForPOC();
1384    Int pocLsbVal;
1385    if( m_apcSlicePilot->getPocResetIdc() == 3 )
1386    {
1387      pocLsbVal = m_apcSlicePilot->getPocLsbVal() ;
1388    }
1389    else
1390    {
1391      pocLsbVal = (m_apcSlicePilot->getPOC() % maxPocLsb);
1392    }
1393
1394    Int pocMsbDelta = 0;
1395    if ( m_apcSlicePilot->getPocMsbValPresentFlag() ) 
1396    {
1397      pocMsbDelta = m_apcSlicePilot->getPocMsbVal() * maxPocLsb;
1398    }
1399    else
1400    {
1401      //This MSB derivation can be made into one function. Item to do next.
1402      Int prevPoc     = this->getPrevPicOrderCnt();
1403      Int prevPocLsb  = prevPoc & (maxPocLsb - 1);
1404      Int prevPocMsb  = prevPoc - prevPocLsb;
1405
1406      pocMsbDelta = m_apcSlicePilot->getCurrMsb( pocLsbVal, prevPocLsb, prevPocMsb, maxPocLsb );
1407    }
1408
1409    Int pocLsbDelta;
1410    if( m_apcSlicePilot->getPocResetIdc() == 2 ||  ( m_apcSlicePilot->getPocResetIdc() == 3 && m_apcSlicePilot->getFullPocResetFlag() ))
1411    {
1412      pocLsbDelta = pocLsbVal;
1413    }
1414    else
1415    {
1416      pocLsbDelta = 0; 
1417    }
1418
1419    Int deltaPocVal  =  pocMsbDelta + pocLsbDelta;
1420
1421#if P0297_VPS_POC_LSB_ALIGNED_FLAG
1422    for (UInt layerIdx = 0; layerIdx < numAffectedLayers; layerIdx++)
1423    {
1424      if (!m_ppcTDecTop[affectedLayerList[layerIdx]]->m_pocDecrementedInDPBFlag)
1425      {
1426        m_ppcTDecTop[affectedLayerList[layerIdx]]->m_pocDecrementedInDPBFlag = true;
1427        TComList<TComPic*>::iterator  iterPic = m_ppcTDecTop[affectedLayerList[layerIdx]]->getListPic()->begin();
1428        while (iterPic != m_ppcTDecTop[affectedLayerList[layerIdx]]->getListPic()->end())
1429#else
1430    //Reset all POC for DPB -> basically do it for each slice in the picutre
1431    TComList<TComPic*>::iterator  iterPic = m_cListPic.begin(); 
1432
1433    // Iterate through all picture in DPB
1434    while( iterPic != m_cListPic.end() )
1435#endif
1436    {
1437      TComPic *dpbPic = *iterPic;
1438      // Check if the picture pointed to by iterPic is either used for reference or
1439      // needed for output, are in the same layer, and not the current picture.
1440#if P0297_VPS_POC_LSB_ALIGNED_FLAG
1441      assert(dpbPic->getLayerId() == affectedLayerList[layerIdx]);
1442      if ( (dpbPic->getReconMark()) && (dpbPic->getPicSym()->getSlice(0)->getPicOutputFlag()) )
1443#else
1444      if ( /*  ( ( dpbPic->getSlice(0)->isReferenced() ) || ( dpbPic->getOutputMark() ) )
1445          &&*/ ( dpbPic->getLayerId() == m_apcSlicePilot->getLayerId() )
1446            && ( dpbPic->getReconMark() ) && ( dpbPic->getPicSym()->getSlice(0)->getPicOutputFlag() ))
1447#endif
1448      {
1449        for(Int i = dpbPic->getNumAllocatedSlice()-1; i >= 0; i--)
1450        {
1451
1452          TComSlice *slice = dpbPic->getSlice(i);
1453          TComReferencePictureSet *rps = slice->getRPS();
1454          slice->setPOC( slice->getPOC() - deltaPocVal );
1455
1456          // Also adjust the POC value stored in the RPS of each such slice
1457          for(Int j = rps->getNumberOfPictures(); j >= 0; j--)
1458          {
1459            rps->setPOC( j, rps->getPOC(j) - deltaPocVal );
1460          }
1461          // Also adjust the value of refPOC
1462          for(Int k = 0; k < 2; k++)  // For List 0 and List 1
1463          {
1464            RefPicList list = (k == 1) ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
1465            for(Int j = 0; j < slice->getNumRefIdx(list); j++)
1466            {
1467              slice->setRefPOC( slice->getRefPOC(list, j) - deltaPocVal, list, j);
1468            }
1469          }
1470        }
1471      }
1472      iterPic++;
1473    }
1474#if P0297_VPS_POC_LSB_ALIGNED_FLAG
1475        // Update the value of pocCRA
1476        m_ppcTDecTop[affectedLayerList[layerIdx]]->m_pocCRA -= deltaPocVal;
1477      }
1478    }
1479#else
1480    // Update the value of pocCRA
1481    m_pocCRA -= deltaPocVal;
1482#endif
1483
1484    // Update value of POCLastDisplay
1485    iPOCLastDisplay -= deltaPocVal;
1486  }
1487  Int maxPocLsb = 1 << m_apcSlicePilot->getSPS()->getBitsForPOC();
1488  Int slicePicOrderCntLsb = m_apcSlicePilot->getPicOrderCntLsb();
1489
1490#if P0297_VPS_POC_LSB_ALIGNED_FLAG
1491  if (m_pocResettingFlag && (m_parseIdc == 1 || m_parseIdc == 2))
1492#else
1493  if (m_parseIdc == 1 || m_parseIdc == 2) // TODO This should be replaced by pocResettingFlag.
1494#endif
1495  {
1496    // Set poc for current slice
1497    if( m_apcSlicePilot->getPocResetIdc() == 1 )
1498    {       
1499      m_apcSlicePilot->setPOC( slicePicOrderCntLsb );
1500    }
1501    else if( m_apcSlicePilot->getPocResetIdc() == 2 )
1502    {
1503      m_apcSlicePilot->setPOC( 0 );
1504    }
1505    else 
1506    {
1507      Int picOrderCntMsb = m_apcSlicePilot->getCurrMsb( slicePicOrderCntLsb, m_apcSlicePilot->getFullPocResetFlag() ? 0 : m_apcSlicePilot->getPocLsbVal(), 0 , maxPocLsb );
1508      m_apcSlicePilot->setPOC( picOrderCntMsb + slicePicOrderCntLsb );
1509    }
1510  }
1511  else if (m_parseIdc == 3)
1512  {
1513    Int picOrderCntMsb = 0;
1514    if( m_apcSlicePilot->getPocMsbValPresentFlag() )
1515    {
1516      picOrderCntMsb = m_apcSlicePilot->getPocMsbVal() * maxPocLsb;
1517    }
1518    else if( m_apcSlicePilot->getIdrPicFlag() )
1519    {
1520      picOrderCntMsb = 0;
1521    }
1522    else
1523    {
1524      Int prevPicOrderCntLsb = this->getPrevPicOrderCnt() & ( maxPocLsb - 1);
1525      Int prevPicOrderCntMsb  = this->getPrevPicOrderCnt() - prevPicOrderCntLsb;
1526      picOrderCntMsb = m_apcSlicePilot->getCurrMsb(slicePicOrderCntLsb, prevPicOrderCntLsb, prevPicOrderCntMsb, maxPocLsb );
1527    }
1528    m_apcSlicePilot->setPOC( picOrderCntMsb + slicePicOrderCntLsb );
1529  }
1530
1531  if( m_parseIdc == 1 || m_parseIdc == 3)
1532  {
1533    // Adjust prevPicOrderCnt
1534    if(    !m_apcSlicePilot->getRaslPicFlag() 
1535        && !m_apcSlicePilot->getRadlPicFlag()
1536        && (m_apcSlicePilot->getNalUnitType() % 2 == 1)
1537        && ( nalu.m_temporalId == 0 )
1538        && !m_apcSlicePilot->getDiscardableFlag() )
1539    {
1540#if P0297_VPS_POC_LSB_ALIGNED_FLAG
1541      for (UInt i = 0; i < numAffectedLayers; i++)
1542      {
1543        m_ppcTDecTop[affectedLayerList[i]]->setPrevPicOrderCnt(m_apcSlicePilot->getPOC());
1544      }
1545#else
1546      this->setPrevPicOrderCnt( m_apcSlicePilot->getPOC() );
1547#endif
1548    }
1549    else if ( m_apcSlicePilot->getPocResetIdc() == 3 )
1550    {
1551#if P0297_VPS_POC_LSB_ALIGNED_FLAG
1552      if (!m_firstPicInLayerDecodedFlag || (m_firstPicInLayerDecodedFlag && m_pocResettingFlag))
1553      {
1554        for (UInt i = 0; i < numAffectedLayers; i++)
1555        {
1556          m_ppcTDecTop[affectedLayerList[i]]->setPrevPicOrderCnt( m_apcSlicePilot->getFullPocResetFlag() 
1557                                                                  ? 0 : m_apcSlicePilot->getPocLsbVal() );
1558        }
1559      }
1560#else
1561      this->setPrevPicOrderCnt( m_apcSlicePilot->getFullPocResetFlag() 
1562                                            ? 0 : m_apcSlicePilot->getPocLsbVal() );
1563#endif
1564    }
1565#else
1566  if (bNewPOC || m_layerId!=m_uiPrevLayerId)
1567  {
1568#endif
1569    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
1570  }
1571#endif
1572#if POC_RESET_IDC_DECODER
1573  if (m_apcSlicePilot->isNextSlice() && (bNewPOC || m_layerId!=m_uiPrevLayerId || m_parseIdc == 1) && !m_bFirstSliceInSequence )
1574#else
1575  if (m_apcSlicePilot->isNextSlice() && (bNewPOC || m_layerId!=m_uiPrevLayerId) && !m_bFirstSliceInSequence )
1576#endif
1577  {
1578    m_prevPOC = m_apcSlicePilot->getPOC();
1579    curLayerId = m_uiPrevLayerId; 
1580    m_uiPrevLayerId = m_layerId;
1581    return true;
1582  }
1583
1584#if POC_RESET_IDC_DECODER
1585  m_parseIdc = -1;
1586#endif
1587
1588
1589#if R0226_SLICE_TMVP
1590  if ( m_apcSlicePilot->getTLayer() == 0 && m_apcSlicePilot->getEnableTMVPFlag() == 0 )
1591  {
1592    //update all pics in the DPB such that they cannot be used for TMPV ref
1593    TComList<TComPic*>::iterator  iterRefPic = m_cListPic.begin(); 
1594    while( iterRefPic != m_cListPic.end() )
1595    {
1596      TComPic *refPic = *iterRefPic;
1597      if( ( refPic->getLayerId() == m_apcSlicePilot->getLayerId() ) && refPic->getReconMark() )
1598      {
1599        for(Int i = refPic->getNumAllocatedSlice()-1; i >= 0; i--)
1600        {
1601
1602          TComSlice *refSlice = refPic->getSlice(i);
1603          refSlice->setAvailableForTMVPRefFlag( false );
1604        }
1605      }
1606      iterRefPic++;
1607    }
1608  }
1609  m_apcSlicePilot->setAvailableForTMVPRefFlag( true );
1610#endif
1611
1612  // actual decoding starts here
1613    xActivateParameterSets();
1614
1615#if REPN_FORMAT_IN_VPS
1616  // Initialize ILRP if needed, only for the current layer 
1617  // ILRP intialization should go along with activation of parameters sets,
1618  // although activation of parameter sets itself need not be done for each and every slice!!!
1619  xInitILRP(m_apcSlicePilot);
1620#endif
1621  if (m_apcSlicePilot->isNextSlice()) 
1622  {
1623    m_prevPOC = m_apcSlicePilot->getPOC();
1624    curLayerId = m_layerId;
1625    m_uiPrevLayerId = m_layerId;
1626  }
1627  m_bFirstSliceInSequence = false;
1628#if SETTING_NO_OUT_PIC_PRIOR 
1629  m_bFirstSliceInBitstream  = false;
1630#endif
1631#if POC_RESET_FLAG
1632  // This operation would do the following:
1633  // 1. Update the other picture in the DPB. This should be done only for the first slice of the picture.
1634  // 2. Update the value of m_pocCRA.
1635  // 3. Reset the POC values at the decoder for the current picture to be zero.
1636  // 4. update value of POCLastDisplay
1637  if( m_apcSlicePilot->getPocResetFlag() )
1638  {
1639    if( m_apcSlicePilot->getSliceIdx() == 0 )
1640    {
1641      Int pocAdjustValue = m_apcSlicePilot->getPOC();
1642
1643#if PREVTID0_POC_RESET
1644      m_apcSlicePilot->adjustPrevTid0POC(pocAdjustValue);
1645#endif
1646      // If poc reset flag is set to 1, reset all POC for DPB -> basically do it for each slice in the picutre
1647      TComList<TComPic*>::iterator  iterPic = m_cListPic.begin(); 
1648
1649      // Iterate through all picture in DPB
1650      while( iterPic != m_cListPic.end() )
1651      {
1652        TComPic *dpbPic = *iterPic;
1653        // Check if the picture pointed to by iterPic is either used for reference or
1654        // needed for output, are in the same layer, and not the current picture.
1655        if( /*  ( ( dpbPic->getSlice(0)->isReferenced() ) || ( dpbPic->getOutputMark() ) )
1656            &&*/ ( dpbPic->getLayerId() == m_apcSlicePilot->getLayerId() )
1657              && ( dpbPic->getReconMark() ) 
1658          )
1659        {
1660          for(Int i = dpbPic->getNumAllocatedSlice()-1; i >= 0; i--)
1661          {
1662
1663            TComSlice *slice = dpbPic->getSlice(i);
1664            TComReferencePictureSet *rps = slice->getRPS();
1665            slice->setPOC( slice->getPOC() - pocAdjustValue );
1666
1667            // Also adjust the POC value stored in the RPS of each such slice
1668            for(Int j = rps->getNumberOfPictures(); j >= 0; j--)
1669            {
1670              rps->setPOC( j, rps->getPOC(j) - pocAdjustValue );
1671            }
1672            // Also adjust the value of refPOC
1673            for(Int k = 0; k < 2; k++)  // For List 0 and List 1
1674            {
1675              RefPicList list = (k == 1) ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
1676              for(Int j = 0; j < slice->getNumRefIdx(list); j++)
1677              {
1678                slice->setRefPOC( slice->getRefPOC(list, j) - pocAdjustValue, list, j);
1679              }
1680            }
1681          }
1682        }
1683        iterPic++;
1684      }
1685      // Update the value of pocCRA
1686      m_pocCRA -= pocAdjustValue;
1687      // Update value of POCLastDisplay
1688      iPOCLastDisplay -= pocAdjustValue;
1689    }
1690    // Reset current poc for current slice and RPS
1691    m_apcSlicePilot->setPOC( 0 );
1692  }
1693#endif
1694  // Alignment of TSA and STSA pictures across AU
1695#if !Q0108_TSA_STSA
1696  if( m_apcSlicePilot->getLayerId() > 0 )
1697  {
1698    // Check for TSA alignment
1699    if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N ||
1700        m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R
1701         )
1702    {
1703      for(Int dependentLayerIdx = 0; dependentLayerIdx < m_apcSlicePilot->getVPS()->getNumDirectRefLayers(m_layerId); dependentLayerIdx++)
1704      {
1705        TComList<TComPic*> *cListPic = getRefLayerDec( dependentLayerIdx )->getListPic();
1706        TComPic* refpicLayer = m_apcSlicePilot->getRefPic(*cListPic, m_apcSlicePilot->getPOC() );
1707        if( refpicLayer )
1708        {
1709          assert( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N ||
1710                    m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R );    // TSA pictures should be aligned among depenedent layers
1711        } 
1712      }
1713    }
1714    // Check for STSA alignment
1715    if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N ||
1716         m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_R
1717         )
1718    {
1719      for(Int dependentLayerIdx = 0; dependentLayerIdx < m_apcSlicePilot->getVPS()->getNumDirectRefLayers(m_layerId); dependentLayerIdx++)
1720      {
1721        TComList<TComPic*> *cListPic = getRefLayerDec( dependentLayerIdx )->getListPic();
1722        TComPic* refpicLayer = m_apcSlicePilot->getRefPic(*cListPic, m_apcSlicePilot->getPOC() ); // STSA pictures should be aligned among dependent layers
1723        if( refpicLayer )
1724
1725        {
1726          assert( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N ||
1727                    m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_R );
1728        }
1729      }
1730    }
1731  }
1732#endif
1733
1734#else //SVC_EXTENSION
1735  //we should only get a different poc for a new picture (with CTU address==0)
1736  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (m_apcSlicePilot->getSliceCurStartCUAddr()!=0))
1737  {
1738    printf ("Warning, the first slice of a picture might have been lost!\n");
1739  }
1740  // exit when a new picture is found
1741  if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence )
1742  {
1743    if (m_prevPOC >= m_pocRandomAccess)
1744    {
1745      m_prevPOC = m_apcSlicePilot->getPOC();
1746      return true;
1747    }
1748    m_prevPOC = m_apcSlicePilot->getPOC();
1749  }
1750
1751  // actual decoding starts here
1752  xActivateParameterSets();
1753
1754  if (m_apcSlicePilot->isNextSlice()) 
1755  {
1756    m_prevPOC = m_apcSlicePilot->getPOC();
1757  }
1758  m_bFirstSliceInSequence = false;
1759#endif //SVC_EXTENSION
1760  //detect lost reference picture and insert copy of earlier frame.
1761  Int lostPoc;
1762  while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
1763  {
1764    xCreateLostPicture(lostPoc-1);
1765  }
1766  if (m_bFirstSliceInPicture)
1767  {
1768#if AVC_BASE
1769#if VPS_AVC_BL_FLAG_REMOVAL
1770    if( m_layerId == 1 && m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getNonHEVCBaseLayerFlag() )
1771#else
1772    if( m_layerId == 1 && m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
1773#endif
1774    {
1775      TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
1776      pBLPic->getSlice(0)->setReferenced(true);
1777      fstream* pFile  = m_ppcTDecTop[0]->getBLReconFile();
1778
1779      if( pFile->good() )
1780      {
1781        Bool is16bit  = g_bitDepthYLayer[0] > 8 || g_bitDepthCLayer[0] > 8;
1782        UInt uiWidth  = pBLPic->getPicYuvRec()->getWidth();
1783        UInt uiHeight = pBLPic->getPicYuvRec()->getHeight();
1784
1785        Int len = uiWidth * (is16bit ? 2 : 1);
1786        UChar *buf = new UChar[len];
1787
1788        UInt64 uiPos = (UInt64) m_apcSlicePilot->getPOC() * uiWidth * uiHeight * 3 / 2;
1789        if( is16bit )
1790        {
1791            uiPos <<= 1;
1792        }
1793
1794        pFile->seekg((UInt)uiPos, ios::beg );
1795
1796        // read Y component
1797        Pel* pPel = pBLPic->getPicYuvRec()->getLumaAddr();
1798        UInt uiStride = pBLPic->getPicYuvRec()->getStride();
1799        for( Int i = 0; i < uiHeight; i++ )
1800        {
1801          pFile->read(reinterpret_cast<Char*>(buf), len);
1802
1803          if( !is16bit )
1804          {
1805            for (Int x = 0; x < uiWidth; x++)
1806            {
1807              pPel[x] = buf[x];
1808            }
1809          }
1810          else
1811          {
1812            for (Int x = 0; x < uiWidth; x++)
1813            {
1814              pPel[x] = (buf[2*x+1] << 8) | buf[2*x];
1815            }
1816          }
1817     
1818          pPel += uiStride;
1819        }
1820
1821        len >>= 1;
1822        uiWidth >>= 1;
1823        uiHeight >>= 1;
1824
1825        // read Cb component
1826        pPel = pBLPic->getPicYuvRec()->getCbAddr();
1827        uiStride = pBLPic->getPicYuvRec()->getCStride();
1828        for( Int i = 0; i < uiHeight; i++ )
1829        {
1830          pFile->read(reinterpret_cast<Char*>(buf), len);
1831
1832          if( !is16bit )
1833          {
1834            for( Int x = 0; x < uiWidth; x++ )
1835            {
1836              pPel[x] = buf[x];
1837            }
1838          }
1839          else
1840          {
1841            for( Int x = 0; x < uiWidth; x++ )
1842            {
1843              pPel[x] = (buf[2*x+1] << 8) | buf[2*x];
1844            }
1845          }
1846     
1847          pPel += uiStride;
1848        }
1849
1850        // read Cr component
1851        pPel = pBLPic->getPicYuvRec()->getCrAddr();
1852        uiStride = pBLPic->getPicYuvRec()->getCStride();
1853        for( Int i = 0; i < uiHeight; i++ )
1854        {
1855          pFile->read(reinterpret_cast<Char*>(buf), len);
1856
1857          if( !is16bit )
1858          {
1859            for( Int x = 0; x < uiWidth; x++ )
1860            {
1861              pPel[x] = buf[x];
1862            }
1863          }
1864          else
1865          {
1866            for( Int x = 0; x < uiWidth; x++ )
1867            {
1868              pPel[x] = (buf[2*x+1] << 8) | buf[2*x];
1869            }
1870          }
1871     
1872          pPel += uiStride;
1873        }
1874
1875        delete[] buf;
1876      }
1877    }
1878#endif
1879
1880#if NO_OUTPUT_OF_PRIOR_PICS
1881    if ( m_layerId == 0 && m_apcSlicePilot->getRapPicFlag() && getNoClrasOutputFlag() )
1882    {
1883      for (UInt i = 0; i < m_apcSlicePilot->getVPS()->getMaxLayers(); i++)
1884      {
1885        m_ppcTDecTop[i]->setLayerInitializedFlag(false);
1886        m_ppcTDecTop[i]->setFirstPicInLayerDecodedFlag(false);
1887      }
1888    }
1889#endif
1890#if R0071_IRAP_EOS_CROSS_LAYER_IMPACTS
1891    xCheckLayerReset();
1892    xSetLayerInitializedFlag();
1893#endif
1894    // Buffer initialize for prediction.
1895    m_cPrediction.initTempBuff();
1896#if ALIGNED_BUMPING
1897    m_apcSlicePilot->checkLeadingPictureRestrictions(m_cListPic);
1898#else
1899    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
1900#endif
1901    //  Get a new picture buffer
1902    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
1903
1904#if POC_RESET_IDC_DECODER
1905    pcPic->setCurrAuFlag( true );
1906#if POC_RESET_RESTRICTIONS
1907    if( pcPic->getLayerId() > 0 && m_apcSlicePilot->isIDR() && !m_nonBaseIdrPresentFlag )
1908    {
1909      // IDR picture with nuh_layer_id > 0 present
1910      m_nonBaseIdrPresentFlag = true;
1911      m_nonBaseIdrType = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL);
1912    }
1913    else
1914    {
1915      if( m_apcSlicePilot->getNalUnitType() != NAL_UNIT_CODED_SLICE_IDR_W_RADL )
1916      {
1917        // Picture with nal_unit_type not equal IDR_W_RADL present
1918        m_picNonIdrWithRadlPresentFlag = true;
1919      }
1920      if( m_apcSlicePilot->getNalUnitType() != NAL_UNIT_CODED_SLICE_IDR_N_LP )
1921      {
1922        // Picture with nal_unit_type not equal IDR_N_LP present
1923        m_picNonIdrNoLpPresentFlag = true;
1924      }
1925    }
1926    if( !m_checkPocRestrictionsForCurrAu )  // Will be true for the first slice/picture of the AU
1927    {
1928      m_checkPocRestrictionsForCurrAu = true;
1929      m_pocResetIdcOrCurrAu = m_apcSlicePilot->getPocResetIdc();
1930      if( pcPic->getLayerId() == 0 )
1931      {
1932        // Base layer picture is present
1933        m_baseLayerPicPresentFlag = true;
1934        if( m_apcSlicePilot->isIRAP() )
1935        {
1936          // Base layer picture is IRAP
1937          m_baseLayerIrapFlag = true;
1938        }
1939        if( m_apcSlicePilot->isIDR() )
1940        {
1941          // Base layer picture is IDR
1942          m_baseLayerIdrFlag = true;
1943        }
1944        else
1945        {
1946          if( m_apcSlicePilot->getVPS()->getBaseLayerInternalFlag())
1947          {
1948            /* When the picture with nuh_layer_id equal to 0 in an access unit is not an IDR picture
1949            and vps_base_layer_internal_flag is equal to 1, the value of poc_reset_idc shall not be equal to 2
1950            for any picture in the access unit. */
1951            assert( m_apcSlicePilot->getPocResetIdc() != 2 );
1952          }
1953        }
1954      }
1955    }
1956    else
1957    {
1958      // The value of poc_reset_idc of all coded pictures that are present in the bitstream in an access unit shall be the same.
1959      assert( m_pocResetIdcOrCurrAu == m_apcSlicePilot->getPocResetIdc() );
1960
1961      /* 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
1962      and there is at least one other picture in the same access unit that is not an IRAP picture,
1963      the value of poc_reset_idc shall be equal to 1 or 2 for all pictures in the access unit. */
1964      if( m_baseLayerPicPresentFlag && m_baseLayerIrapFlag && !m_apcSlicePilot->isIRAP() && m_apcSlicePilot->getVPS()->getBaseLayerInternalFlag() )
1965      {
1966        assert( m_apcSlicePilot->getPocResetIdc() == 1 || m_apcSlicePilot->getPocResetIdc() == 2 );
1967      }
1968
1969      /* When the picture with nuh_layer_id equal to 0 in an access unit is an IDR picture and
1970      vps_base_layer_internal_flag is equal to 1 and there is at least one non-IDR picture in the same access unit,
1971      the value of poc_reset_idc shall be equal to 2 for all pictures in the access unit. */
1972      if( m_baseLayerPicPresentFlag && m_baseLayerIdrFlag && !m_apcSlicePilot->isIDR() && m_apcSlicePilot->getVPS()->getBaseLayerInternalFlag() )
1973      {
1974        assert( m_apcSlicePilot->getPocResetIdc() == 2 );
1975      }
1976
1977      /* When there is at least one picture that has nuh_layer_id greater than 0 and that is an IDR picture
1978      with a particular value of nal_unit_type in an access unit and there is at least one other coded picture
1979      that is present in the bitstream in the same access unit with a different value of nal_unit_type,
1980      the value of poc_reset_idc shall be equal to 1 or 2 for all pictures in the access unit. */
1981      if( m_nonBaseIdrPresentFlag && (
1982            ( m_nonBaseIdrType == 1 && m_picNonIdrWithRadlPresentFlag ) ||
1983            ( m_nonBaseIdrType == 0 && m_picNonIdrNoLpPresentFlag )
1984        ))
1985      {
1986        assert( m_apcSlicePilot->getPocResetIdc() == 1 || m_apcSlicePilot->getPocResetIdc() == 2 );
1987      }
1988    }
1989#endif
1990#endif
1991
1992    Bool isField = false;
1993    Bool isTff = false;
1994   
1995    if(!m_SEIs.empty())
1996    {
1997      // Check if any new Picture Timing SEI has arrived
1998      SEIMessages pictureTimingSEIs = extractSeisByType (m_SEIs, SEI::PICTURE_TIMING);
1999      if (pictureTimingSEIs.size()>0)
2000      {
2001        SEIPictureTiming* pictureTiming = (SEIPictureTiming*) *(pictureTimingSEIs.begin());
2002        isField = (pictureTiming->m_picStruct == 1) || (pictureTiming->m_picStruct == 2);
2003        isTff =  (pictureTiming->m_picStruct == 1);
2004      }
2005
2006#if R0226_CONSTRAINT_TMVP_SEI
2007      // Check if any new temporal motion vector prediction constraints SEI has arrived
2008      SEIMessages seiTMVPConstrainsList = extractSeisByType (m_SEIs, SEI::TMVP_CONSTRAINTS);
2009      if (seiTMVPConstrainsList.size() > 0)
2010      {
2011        assert ( pcPic->getTLayer() == 0 );  //this SEI can present only for AU with Tid equal to 0
2012        SEITMVPConstrains* tmvpConstraintSEI = (SEITMVPConstrains*) *(seiTMVPConstrainsList.begin());
2013        if ( tmvpConstraintSEI->prev_pics_not_used_flag == 1 )
2014        {
2015          //update all pics in the DPB such that they cannot be used for TMPV ref
2016          TComList<TComPic*>::iterator  iterRefPic = m_cListPic.begin(); 
2017          while( iterRefPic != m_cListPic.end() )
2018          {
2019            TComPic *refPic = *iterRefPic;
2020            if( ( refPic->getLayerId() == pcPic->getLayerId() ) && refPic->getReconMark() )
2021            {
2022              for(Int i = refPic->getNumAllocatedSlice()-1; i >= 0; i--)
2023              {
2024                TComSlice *refSlice = refPic->getSlice(i);
2025                refSlice->setAvailableForTMVPRefFlag( false );
2026              }
2027            }
2028            iterRefPic++;
2029          }
2030        }
2031      }
2032#endif
2033    }
2034   
2035    //Set Field/Frame coding mode
2036    m_pcPic->setField(isField);
2037    m_pcPic->setTopField(isTff);
2038
2039    // transfer any SEI messages that have been received to the picture
2040    pcPic->setSEIs(m_SEIs);
2041    m_SEIs.clear();
2042
2043    // Recursive structure
2044    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
2045#if SVC_EXTENSION
2046    m_cCuDecoder.init   ( m_ppcTDecTop,&m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction, curLayerId );
2047#else
2048    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
2049#endif
2050    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
2051
2052    m_cSliceDecoder.create();
2053  }
2054  else
2055  {
2056    // Check if any new SEI has arrived
2057    if(!m_SEIs.empty())
2058    {
2059      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
2060      SEIMessages &picSEI = pcPic->getSEIs();
2061      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
2062      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
2063      deleteSEIs(m_SEIs);
2064    }
2065  }
2066 
2067  //  Set picture slice pointer
2068  TComSlice*  pcSlice = m_apcSlicePilot;
2069  Bool bNextSlice     = pcSlice->isNextSlice();
2070
2071  UInt i;
2072  pcPic->getPicSym()->initTiles(pcSlice->getPPS());
2073
2074  //generate the Coding Order Map and Inverse Coding Order Map
2075  UInt uiEncCUAddr;
2076  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
2077  {
2078    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
2079    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
2080  }
2081  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
2082  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
2083
2084  //convert the start and end CU addresses of the slice and dependent slice into encoding order
2085  pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) );
2086  pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) );
2087  if(pcSlice->isNextSlice())
2088  {
2089    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
2090    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
2091  }
2092
2093  if (m_bFirstSliceInPicture) 
2094  {
2095    if(pcPic->getNumAllocatedSlice() != 1)
2096    {
2097      pcPic->clearSliceBuffer();
2098    }
2099  }
2100  else
2101  {
2102    pcPic->allocateNewSlice();
2103  }
2104  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
2105  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
2106  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
2107
2108  pcPic->setTLayer(nalu.m_temporalId);
2109
2110#if SVC_EXTENSION
2111  pcPic->setLayerId(nalu.m_layerId);
2112  pcSlice->setLayerId(nalu.m_layerId);
2113  pcSlice->setPic(pcPic);
2114#endif
2115
2116  if (bNextSlice)
2117  {
2118    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_associatedIRAPType, m_cListPic );
2119    // Set reference list
2120#if SVC_EXTENSION
2121    if (m_layerId == 0)
2122#endif
2123    pcSlice->setRefPicList( m_cListPic, true );
2124
2125#if SVC_EXTENSION
2126    // Create upsampling reference layer pictures for all possible dependent layers and do it only once for the first slice.
2127    // Other slices might choose which reference pictures to be used for inter-layer prediction
2128    if( m_layerId > 0 && m_uiSliceIdx == 0 )
2129    {     
2130#if M0040_ADAPTIVE_RESOLUTION_CHANGE
2131      if( !pcSlice->getVPS()->getSingleLayerForNonIrapFlag() || ( pcSlice->getVPS()->getSingleLayerForNonIrapFlag() && pcSlice->isIRAP() ) )
2132#endif
2133      for( i = 0; i < pcSlice->getNumILRRefIdx(); i++ )
2134      {
2135        UInt refLayerIdc = i;
2136        UInt refLayerId = pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc);
2137#if AVC_BASE
2138#if VPS_AVC_BL_FLAG_REMOVAL
2139        if( refLayerId == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getNonHEVCBaseLayerFlag() )
2140#else
2141        if( refLayerId == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getAvcBaseLayerFlag() )
2142#endif
2143        {         
2144          TComPic* pic = *m_ppcTDecTop[0]->getListPic()->begin();
2145
2146          if( pic )
2147          {
2148            pcSlice->setBaseColPic ( refLayerIdc, pic );
2149          }
2150          else
2151          {
2152            continue;
2153          }
2154        }
2155        else
2156        {
2157#if VPS_EXTN_DIRECT_REF_LAYERS
2158          TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
2159#else
2160          TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
2161#endif
2162          TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
2163          if( !pcSlice->setBaseColPic ( *cListPic, refLayerIdc ) )
2164          {
2165            continue;
2166          }
2167        }
2168#else
2169#if VPS_EXTN_DIRECT_REF_LAYERS
2170        TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
2171#else
2172        TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
2173#endif
2174        TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
2175        pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
2176#endif
2177
2178#if MOVE_SCALED_OFFSET_TO_PPS
2179#if O0098_SCALED_REF_LAYER_ID
2180        const Window &scalEL = pcSlice->getPPS()->getScaledRefLayerWindowForLayer(refLayerId);
2181#else
2182        const Window &scalEL = pcSlice->getPPS()->getScaledRefLayerWindow(refLayerIdc);
2183#endif
2184#else
2185#if O0098_SCALED_REF_LAYER_ID
2186        const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(refLayerId);
2187#else
2188        const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
2189#endif
2190#endif
2191
2192#if REF_REGION_OFFSET
2193        const Window &windowRL = pcSlice->getPPS()->getRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc));
2194        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth() - windowRL.getWindowLeftOffset() - windowRL.getWindowRightOffset();
2195        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight() - windowRL.getWindowTopOffset() - windowRL.getWindowBottomOffset();
2196#else
2197        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth();
2198        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight();
2199#if Q0200_CONFORMANCE_BL_SIZE
2200        Int chromaFormatIdc = pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getChromaFormatIdc();
2201        const Window &confBL = pcSlice->getBaseColPic(refLayerIdc)->getConformanceWindow(); 
2202        widthBL  -= ( confBL.getWindowLeftOffset() + confBL.getWindowRightOffset() ) * TComSPS::getWinUnitX( chromaFormatIdc );
2203        heightBL -= ( confBL.getWindowTopOffset() + confBL.getWindowBottomOffset() ) * TComSPS::getWinUnitY( chromaFormatIdc );
2204#endif
2205#endif
2206        Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
2207        Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
2208
2209#if RESAMPLING_FIX
2210#if REF_REGION_OFFSET
2211        // conformance check: the values of RefLayerRegionWidthInSamplesY, RefLayerRegionHeightInSamplesY, ScaledRefRegionWidthInSamplesY and ScaledRefRegionHeightInSamplesY shall be greater than 0
2212        assert(widthEL > 0 && heightEL > 0 && widthBL > 0 && widthEL > 0);
2213
2214        // conformance check: ScaledRefRegionWidthInSamplesY shall be greater or equal to RefLayerRegionWidthInSamplesY and ScaledRefRegionHeightInSamplesY shall be greater or equal to RefLayerRegionHeightInSamplesY
2215        assert(widthEL >= widthBL && heightEL >= heightBL);
2216
2217#if R0209_GENERIC_PHASE
2218        // 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.
2219        Int phaseHorLuma   = pcSlice->getPPS()->getPhaseHorLuma(refLayerIdc);
2220        Int phaseVerLuma   = pcSlice->getPPS()->getPhaseVerLuma(refLayerIdc);
2221        Int phaseHorChroma = pcSlice->getPPS()->getPhaseHorChroma(refLayerIdc);
2222        Int phaseVerChroma = pcSlice->getPPS()->getPhaseVerChroma(refLayerIdc);
2223        assert( ( (widthEL  != widthBL)  || (phaseHorLuma == 0 && phaseHorChroma == 0) )
2224             && ( (heightEL != heightBL) || (phaseVerLuma == 0 && phaseVerChroma == 0) ) );
2225#endif
2226#endif
2227#endif
2228
2229        g_mvScalingFactor[refLayerIdc][0] = widthEL  == widthBL  ? 4096 : Clip3(-4096, 4095, ((widthEL  << 8) + (widthBL  >> 1)) / widthBL);
2230        g_mvScalingFactor[refLayerIdc][1] = heightEL == heightBL ? 4096 : Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL);
2231
2232        g_posScalingFactor[refLayerIdc][0] = ((widthBL  << 16) + (widthEL  >> 1)) / widthEL;
2233        g_posScalingFactor[refLayerIdc][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL;
2234
2235#if Q0048_CGS_3D_ASYMLUT
2236        TComPicYuv* pBaseColRec = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec();
2237        if( pcSlice->getPPS()->getCGSFlag() 
2238#if R0150_CGS_SIGNAL_CONSTRAINTS
2239          && m_c3DAsymLUTPPS.isRefLayer( pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc) )
2240#endif
2241          )
2242        {
2243#if R0150_CGS_SIGNAL_CONSTRAINTS
2244          assert( pcSlice->getBaseColPic( refLayerIdc )->getSlice( 0 )->getBitDepthY() == m_c3DAsymLUTPPS.getInputBitDepthY() );
2245          assert( pcSlice->getBaseColPic( refLayerIdc )->getSlice( 0 )->getBitDepthC() == m_c3DAsymLUTPPS.getInputBitDepthC() );
2246          assert( pcSlice->getBitDepthY() >= m_c3DAsymLUTPPS.getOutputBitDepthY() );
2247          assert( pcSlice->getBitDepthY() >= m_c3DAsymLUTPPS.getOutputBitDepthC() );
2248#endif
2249          if(!m_pColorMappedPic)
2250          {
2251            initAsymLut(pcSlice->getBaseColPic(refLayerIdc)->getSlice(0));
2252          }
2253          m_c3DAsymLUTPPS.colorMapping( pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(),  m_pColorMappedPic );
2254          pBaseColRec = m_pColorMappedPic;
2255        }
2256#endif
2257#if SVC_EXTENSION
2258        if( pcPic->isSpatialEnhLayer(refLayerIdc) )
2259        {
2260          // check for the sample prediction picture type
2261          if( m_ppcTDecTop[m_layerId]->getSamplePredEnabledFlag(refLayerId) )
2262          {
2263#if O0215_PHASE_ALIGNMENT_REMOVAL
2264            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec());
2265#else
2266#if O0215_PHASE_ALIGNMENT
2267#if O0194_JOINT_US_BITSHIFT
2268#if Q0048_CGS_3D_ASYMLUT
2269            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getVPS()->getPhaseAlignFlag() );
2270#else
2271            m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getVPS()->getPhaseAlignFlag() );
2272#endif
2273#else
2274#if Q0048_CGS_3D_ASYMLUT
2275#if MOVE_SCALED_OFFSET_TO_PPS
2276          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getPPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
2277#else
2278          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
2279#endif
2280#else
2281          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
2282#endif
2283#endif
2284#else
2285#if O0194_JOINT_US_BITSHIFT
2286#if Q0048_CGS_3D_ASYMLUT
2287#if REF_REGION_OFFSET
2288          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL, altRL );
2289#else
2290          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
2291#endif
2292#else
2293          m_cPrediction.upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
2294#endif
2295#else
2296#if Q0048_CGS_3D_ASYMLUT
2297            m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pBaseColRec, pcPic->getPicYuvRec(), scalEL );
2298#else
2299            m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
2300#endif
2301#endif
2302#endif
2303#endif
2304          }
2305        }
2306        else
2307        {
2308          pcPic->setFullPelBaseRec( refLayerIdc, pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec() );
2309        }
2310        pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) );
2311#endif //SVC_EXTENSION
2312      }
2313    }
2314
2315    if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
2316    {
2317      for( i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
2318      {
2319        UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
2320#if AVC_BASE
2321#if VPS_AVC_BL_FLAG_REMOVAL
2322        if( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getNonHEVCBaseLayerFlag() )
2323#else
2324        if( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) == 0 && m_parameterSetManagerDecoder.getActiveVPS()->getAvcBaseLayerFlag() )
2325#endif
2326        {
2327          pcSlice->setBaseColPic ( refLayerIdc, *m_ppcTDecTop[0]->getListPic()->begin() );
2328        }
2329        else
2330        {
2331#if VPS_EXTN_DIRECT_REF_LAYERS
2332          TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
2333#else
2334          TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
2335#endif
2336          TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
2337          pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
2338        }
2339#else
2340#if VPS_EXTN_DIRECT_REF_LAYERS
2341        TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
2342#else
2343        TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
2344#endif
2345        TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
2346        pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
2347#endif
2348
2349        pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) );
2350      }
2351
2352      pcSlice->setILRPic( m_cIlpPic );
2353
2354#if REF_IDX_MFM
2355      pcSlice->setRefPicList( m_cListPic, false, m_cIlpPic);
2356    }
2357#if M0040_ADAPTIVE_RESOLUTION_CHANGE
2358    else if ( m_layerId > 0 )
2359    {
2360      pcSlice->setRefPicList( m_cListPic, false, NULL);
2361    }
2362#endif
2363#if MFM_ENCCONSTRAINT
2364    if( pcSlice->getMFMEnabledFlag() )
2365    {
2366      TComPic* refPic = pcSlice->getRefPic( pcSlice->getSliceType() == B_SLICE ? ( RefPicList )( 1 - pcSlice->getColFromL0Flag() ) : REF_PIC_LIST_0 , pcSlice->getColRefIdx() );
2367
2368      assert( refPic );
2369
2370      Int refLayerId = refPic->getLayerId();
2371
2372      if( refLayerId != pcSlice->getLayerId() )
2373      {
2374        TComPic* pColBasePic = pcSlice->getBaseColPic( *m_ppcTDecTop[refLayerId]->getListPic() );
2375        assert( pColBasePic->checkSameRefInfo() == true );
2376      }
2377    }
2378#endif
2379#endif
2380   
2381    if( m_layerId > 0 && pcSlice->getVPS()->getCrossLayerIrapAlignFlag() )
2382    {
2383#if M0040_ADAPTIVE_RESOLUTION_CHANGE
2384      if( !pcSlice->getVPS()->getSingleLayerForNonIrapFlag() || ( pcSlice->getVPS()->getSingleLayerForNonIrapFlag() && pcSlice->isIRAP() ) )
2385#endif
2386      for(Int dependentLayerIdx = 0; dependentLayerIdx < pcSlice->getVPS()->getNumDirectRefLayers(m_layerId); dependentLayerIdx++)
2387      {
2388        TComList<TComPic*> *cListPic = getRefLayerDec( dependentLayerIdx )->getListPic();
2389        TComPic* refpicLayer = pcSlice->getRefPic(*cListPic, pcSlice->getPOC() );
2390        if(refpicLayer && pcSlice->isIRAP())
2391        {                 
2392          assert(pcSlice->getNalUnitType() == refpicLayer->getSlice(0)->getNalUnitType());
2393        }
2394      }
2395    }
2396   
2397    if( m_layerId > 0 && !pcSlice->isIntra() && pcSlice->getEnableTMVPFlag() )
2398    {
2399      TComPic* refPic = pcSlice->getRefPic(RefPicList(1 - pcSlice->getColFromL0Flag()), pcSlice->getColRefIdx());
2400
2401      assert( refPic );
2402#if R0226_SLICE_TMVP
2403      assert ( refPic->getPicSym()->getSlice(0)->getAvailableForTMVPRefFlag() == true );
2404#endif
2405
2406      // It is a requirement of bitstream conformance when the collocated picture, used for temporal motion vector prediction, is an inter-layer reference picture,
2407      // VpsInterLayerMotionPredictionEnabled[ LayerIdxInVps[ currLayerId ] ][ LayerIdxInVps[ rLId ] ] shall be equal to 1, where rLId is set equal to nuh_layer_id of the inter-layer picture.
2408      if( refPic->isILR(pcSlice->getLayerId()) )
2409      {
2410        assert( m_ppcTDecTop[m_layerId]->getMotionPredEnabledFlag(refPic->getLayerId()) );
2411      }
2412    }
2413#endif //SVC_EXTENSION
2414   
2415    // For generalized B
2416    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
2417    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
2418    {
2419      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
2420      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
2421
2422      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
2423      {
2424        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
2425      }
2426    }
2427    if (!pcSlice->isIntra())
2428    {
2429      Bool bLowDelay = true;
2430      Int  iCurrPOC  = pcSlice->getPOC();
2431      Int iRefIdx = 0;
2432
2433      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
2434      {
2435        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
2436        {
2437          bLowDelay = false;
2438        }
2439      }
2440      if (pcSlice->isInterB())
2441      {
2442        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
2443        {
2444          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
2445          {
2446            bLowDelay = false;
2447          }
2448        }       
2449      }
2450
2451      pcSlice->setCheckLDC(bLowDelay);           
2452    }
2453
2454    //---------------
2455    pcSlice->setRefPOCList();
2456  }
2457
2458  pcPic->setCurrSliceIdx(m_uiSliceIdx);
2459  if(pcSlice->getSPS()->getScalingListFlag())
2460  {
2461    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
2462    if(pcSlice->getPPS()->getScalingListPresentFlag())
2463    {
2464      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
2465    }
2466#if SCALINGLIST_INFERRING
2467    if( m_layerId == 0 || ( m_layerId > 0 && !pcSlice->getPPS()->getInferScalingListFlag() && !pcSlice->getSPS()->getInferScalingListFlag() ) )
2468#endif
2469    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
2470    {
2471      pcSlice->setDefaultScalingList();
2472    }
2473    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
2474    m_cTrQuant.setUseScalingList(true);
2475  }
2476  else
2477  {
2478    m_cTrQuant.setFlatScalingList();
2479    m_cTrQuant.setUseScalingList(false);
2480  }
2481
2482  //  Decode a picture
2483  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
2484
2485#if P0297_VPS_POC_LSB_ALIGNED_FLAG
2486  setFirstPicInLayerDecodedFlag(true);
2487#endif
2488#if R0071_IRAP_EOS_CROSS_LAYER_IMPACTS
2489  m_lastPicHasEos = false;
2490#endif
2491
2492  m_bFirstSliceInPicture = false;
2493  m_uiSliceIdx++;
2494
2495  return false;
2496}
2497
2498Void TDecTop::xDecodeVPS()
2499{
2500  TComVPS* vps = new TComVPS();
2501 
2502  m_cEntropyDecoder.decodeVPS( vps );
2503  m_parameterSetManagerDecoder.storePrefetchedVPS(vps);
2504#if R0235_SMALLEST_LAYER_ID
2505  checkValueOfTargetOutputLayerSetIdx(vps);
2506#endif
2507}
2508
2509#if SVC_EXTENSION
2510Void TDecTop::xDecodeSPS()
2511{
2512  TComSPS* sps = new TComSPS();
2513  sps->setLayerId(m_layerId);
2514#if SPS_DPB_PARAMS
2515  m_cEntropyDecoder.decodeSPS( sps ); // it should be removed after macro clean up
2516#else
2517  m_cEntropyDecoder.decodeSPS( sps, &m_parameterSetManagerDecoder );
2518#endif
2519  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
2520#if !REPN_FORMAT_IN_VPS   // ILRP can only be initialized at activation 
2521  if(m_numLayer>0)
2522  {
2523    xInitILRP(sps);
2524  }
2525#endif
2526}
2527
2528Void TDecTop::xDecodePPS(
2529#if Q0048_CGS_3D_ASYMLUT
2530  TCom3DAsymLUT * pc3DAsymLUT
2531#endif
2532  )
2533{
2534  TComPPS* pps = new TComPPS();
2535
2536#if SCALINGLIST_INFERRING
2537  pps->setLayerId( m_layerId );
2538#endif
2539
2540  m_cEntropyDecoder.decodePPS( pps
2541#if Q0048_CGS_3D_ASYMLUT
2542    , pc3DAsymLUT , m_layerId
2543#endif
2544    );
2545  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
2546}
2547#else
2548Void TDecTop::xDecodeSPS()
2549{
2550  TComSPS* sps = new TComSPS();
2551  m_cEntropyDecoder.decodeSPS( sps );
2552  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
2553}
2554
2555Void TDecTop::xDecodePPS()
2556{
2557  TComPPS* pps = new TComPPS();
2558  m_cEntropyDecoder.decodePPS( pps );
2559  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
2560}
2561#endif //SVC_EXTENSION
2562
2563Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
2564{
2565#if SVC_EXTENSION
2566  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
2567  {
2568    if (m_prevSliceSkipped) // No need to decode SEI messages of a skipped access unit
2569    {
2570      return;
2571    }
2572#if LAYERS_NOT_PRESENT_SEI
2573    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
2574#else
2575    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
2576#endif
2577  }
2578  else
2579  {
2580#if LAYERS_NOT_PRESENT_SEI
2581    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
2582#else
2583    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
2584#endif
2585    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
2586    if (activeParamSets.size()>0)
2587    {
2588      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
2589#if !R0247_SEI_ACTIVE
2590      m_parameterSetManagerDecoder.applyPrefetchedPS();
2591      assert(seiAps->activeSeqParameterSetId.size()>0);
2592      if( !m_parameterSetManagerDecoder.activateSPSWithSEI( seiAps->activeSeqParameterSetId[0] ) )
2593      {
2594        printf ("Warning SPS activation with Active parameter set SEI failed");
2595      }
2596#else
2597      getLayerDec(0)->m_parameterSetManagerDecoder.applyPrefetchedPS();
2598      assert(seiAps->activeSeqParameterSetId.size()>0);
2599      if( !getLayerDec(0)->m_parameterSetManagerDecoder.activateSPSWithSEI( seiAps->activeSeqParameterSetId[0] ) )
2600      {
2601        printf ("Warning SPS activation with Active parameter set SEI failed");
2602      }
2603      for (Int c=1 ; c <= seiAps->numSpsIdsMinus1; c++)
2604      {
2605        Int layerIdx = seiAps->layerSpsIdx[c];
2606        getLayerDec(layerIdx)->m_parameterSetManagerDecoder.applyPrefetchedPS();
2607        if( !getLayerDec(layerIdx)->m_parameterSetManagerDecoder.activateSPSWithSEI( seiAps->activeSeqParameterSetId[layerIdx] ) )
2608        {
2609          printf ("Warning SPS activation with Active parameter set SEI failed");
2610        }
2611      }
2612#endif
2613    }
2614  }
2615#else
2616  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
2617  {
2618#if LAYERS_NOT_PRESENT_SEI
2619    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
2620#else
2621    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
2622#endif
2623  }
2624  else
2625  {
2626#if LAYERS_NOT_PRESENT_SEI
2627    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
2628#else
2629    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
2630#endif
2631    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
2632    if (activeParamSets.size()>0)
2633    {
2634      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
2635      m_parameterSetManagerDecoder.applyPrefetchedPS();
2636      assert(seiAps->activeSeqParameterSetId.size()>0);
2637      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParameterSetId[0] ))
2638      {
2639        printf ("Warning SPS activation with Active parameter set SEI failed");
2640      }
2641    }
2642  }
2643#endif
2644}
2645
2646#if SVC_EXTENSION
2647Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC)
2648#else
2649Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
2650#endif
2651{
2652  // Initialize entropy decoder
2653  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
2654  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
2655
2656#if O0137_MAX_LAYERID
2657  // ignore any NAL units with nuh_layer_id == 63
2658  if (nalu.m_layerId == 63 )
2659  { 
2660    return false;
2661  }
2662#endif
2663  switch (nalu.m_nalUnitType)
2664  {
2665    case NAL_UNIT_VPS:
2666#if SVC_EXTENSION
2667      assert( nalu.m_layerId == 0 ); // Non-conforming bitstream. The value of nuh_layer_id of VPS NAL unit shall be equal to 0.
2668#endif
2669      xDecodeVPS();
2670#if Q0177_EOS_CHECKS
2671      m_isLastNALWasEos = false;
2672#endif
2673#if AVC_BASE
2674#if VPS_AVC_BL_FLAG_REMOVAL
2675      if( m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getNonHEVCBaseLayerFlag() )
2676#else
2677      if( m_parameterSetManagerDecoder.getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
2678#endif
2679      {
2680        if( !m_ppcTDecTop[0]->getBLReconFile()->good() )
2681        {
2682          printf( "Base layer YUV input reading error\n" );
2683          exit(EXIT_FAILURE);
2684        }       
2685      }
2686      else
2687      {
2688        TComList<TComPic*> *cListPic = m_ppcTDecTop[0]->getListPic();
2689        cListPic->clear();
2690      }
2691#endif
2692#if R0235_SMALLEST_LAYER_ID
2693      xDeriveSmallestLayerId(m_parameterSetManagerDecoder.getPrefetchedVPS(0));
2694#endif
2695      return false;
2696     
2697    case NAL_UNIT_SPS:
2698      xDecodeSPS();
2699      return false;
2700
2701    case NAL_UNIT_PPS:
2702      xDecodePPS(
2703#if Q0048_CGS_3D_ASYMLUT
2704        &m_c3DAsymLUTPPS
2705#endif
2706        );
2707      return false;
2708     
2709    case NAL_UNIT_PREFIX_SEI:
2710    case NAL_UNIT_SUFFIX_SEI:
2711#if Q0177_EOS_CHECKS
2712      if ( nalu.m_nalUnitType == NAL_UNIT_SUFFIX_SEI )
2713      {
2714        assert( m_isLastNALWasEos == false );
2715      }
2716#endif
2717      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
2718      return false;
2719
2720    case NAL_UNIT_CODED_SLICE_TRAIL_R:
2721    case NAL_UNIT_CODED_SLICE_TRAIL_N:
2722    case NAL_UNIT_CODED_SLICE_TSA_R:
2723    case NAL_UNIT_CODED_SLICE_TSA_N:
2724    case NAL_UNIT_CODED_SLICE_STSA_R:
2725    case NAL_UNIT_CODED_SLICE_STSA_N:
2726    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
2727    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
2728    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
2729    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
2730    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
2731    case NAL_UNIT_CODED_SLICE_CRA:
2732    case NAL_UNIT_CODED_SLICE_RADL_N:
2733    case NAL_UNIT_CODED_SLICE_RADL_R:
2734    case NAL_UNIT_CODED_SLICE_RASL_N:
2735    case NAL_UNIT_CODED_SLICE_RASL_R:
2736#if Q0177_EOS_CHECKS
2737      if (nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_N ||
2738          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_N ||
2739          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_N ||
2740          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
2741          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N )
2742      {
2743        assert( m_isLastNALWasEos == false );
2744      }
2745      else
2746      {
2747        m_isLastNALWasEos = false;
2748      }
2749#endif
2750#if SVC_EXTENSION
2751      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, curLayerId, bNewPOC);
2752#else
2753      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
2754#endif
2755      break;
2756     
2757    case NAL_UNIT_EOS:
2758#if Q0177_EOS_CHECKS
2759      assert( m_isLastNALWasEos == false );
2760#if !R0071_IRAP_EOS_CROSS_LAYER_IMPACTS
2761      //Check layer id of the nalu. if it is not 0, give a warning message and just return without doing anything.
2762      if (nalu.m_layerId > 0)
2763      {
2764        printf( "\nThis bitstream has EOS with non-zero layer id.\n" );
2765        return false;
2766      }
2767#endif
2768      m_isLastNALWasEos = true;
2769#if R0071_IRAP_EOS_CROSS_LAYER_IMPACTS
2770      m_lastPicHasEos = true;
2771#endif
2772#endif
2773      m_associatedIRAPType = NAL_UNIT_INVALID;
2774      m_pocCRA = 0;
2775      m_pocRandomAccess = MAX_INT;
2776      m_prevPOC = MAX_INT;
2777      m_bFirstSliceInPicture = true;
2778      m_bFirstSliceInSequence = true;
2779      m_prevSliceSkipped = false;
2780      m_skippedPOC = 0;
2781      return false;
2782     
2783    case NAL_UNIT_ACCESS_UNIT_DELIMITER:
2784      // TODO: process AU delimiter
2785      return false;
2786     
2787    case NAL_UNIT_EOB:
2788#if P0130_EOB
2789      //Check layer id of the nalu. if it is not 0, give a warning message.
2790      if (nalu.m_layerId > 0)
2791      {
2792        printf( "\n\nThis bitstream is ended with EOB NALU that has layer id greater than 0\n" );
2793      }
2794#endif
2795      return false;
2796     
2797    case NAL_UNIT_FILLER_DATA:
2798#if Q0177_EOS_CHECKS
2799      assert( m_isLastNALWasEos == false );
2800#endif
2801      return false;
2802     
2803    case NAL_UNIT_RESERVED_VCL_N10:
2804    case NAL_UNIT_RESERVED_VCL_R11:
2805    case NAL_UNIT_RESERVED_VCL_N12:
2806    case NAL_UNIT_RESERVED_VCL_R13:
2807    case NAL_UNIT_RESERVED_VCL_N14:
2808    case NAL_UNIT_RESERVED_VCL_R15:
2809     
2810    case NAL_UNIT_RESERVED_IRAP_VCL22:
2811    case NAL_UNIT_RESERVED_IRAP_VCL23:
2812     
2813    case NAL_UNIT_RESERVED_VCL24:
2814    case NAL_UNIT_RESERVED_VCL25:
2815    case NAL_UNIT_RESERVED_VCL26:
2816    case NAL_UNIT_RESERVED_VCL27:
2817    case NAL_UNIT_RESERVED_VCL28:
2818    case NAL_UNIT_RESERVED_VCL29:
2819    case NAL_UNIT_RESERVED_VCL30:
2820    case NAL_UNIT_RESERVED_VCL31:
2821     
2822    case NAL_UNIT_RESERVED_NVCL41:
2823    case NAL_UNIT_RESERVED_NVCL42:
2824    case NAL_UNIT_RESERVED_NVCL43:
2825    case NAL_UNIT_RESERVED_NVCL44:
2826    case NAL_UNIT_RESERVED_NVCL45:
2827    case NAL_UNIT_RESERVED_NVCL46:
2828    case NAL_UNIT_RESERVED_NVCL47:
2829    case NAL_UNIT_UNSPECIFIED_48:
2830    case NAL_UNIT_UNSPECIFIED_49:
2831    case NAL_UNIT_UNSPECIFIED_50:
2832    case NAL_UNIT_UNSPECIFIED_51:
2833    case NAL_UNIT_UNSPECIFIED_52:
2834    case NAL_UNIT_UNSPECIFIED_53:
2835    case NAL_UNIT_UNSPECIFIED_54:
2836    case NAL_UNIT_UNSPECIFIED_55:
2837    case NAL_UNIT_UNSPECIFIED_56:
2838    case NAL_UNIT_UNSPECIFIED_57:
2839    case NAL_UNIT_UNSPECIFIED_58:
2840    case NAL_UNIT_UNSPECIFIED_59:
2841    case NAL_UNIT_UNSPECIFIED_60:
2842    case NAL_UNIT_UNSPECIFIED_61:
2843    case NAL_UNIT_UNSPECIFIED_62:
2844    case NAL_UNIT_UNSPECIFIED_63:
2845
2846    default:
2847      assert (0);
2848  }
2849
2850  return false;
2851}
2852
2853/** Function for checking if picture should be skipped because of association with a previous BLA picture
2854 * \param iPOCLastDisplay POC of last picture displayed
2855 * \returns true if the picture should be skipped
2856 * This function skips all TFD pictures that follow a BLA picture
2857 * in decoding order and precede it in output order.
2858 */
2859Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
2860{
2861  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) && 
2862       m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
2863  {
2864    iPOCLastDisplay++;
2865    return true;
2866  }
2867  return false;
2868}
2869
2870/** Function for checking if picture should be skipped because of random access
2871 * \param iSkipFrame skip frame counter
2872 * \param iPOCLastDisplay POC of last picture displayed
2873 * \returns true if the picture shold be skipped in the random access.
2874 * This function checks the skipping of pictures in the case of -s option random access.
2875 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
2876 * It also checks the type of Nal unit type at the random access point.
2877 * 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.
2878 * If the random access point is IDR all pictures after the random access point are decoded.
2879 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
2880 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
2881 * access point there is no guarantee that the decoder will not crash.
2882 */
2883Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
2884{
2885  if (iSkipFrame) 
2886  {
2887    iSkipFrame--;   // decrement the counter
2888    return true;
2889  }
2890  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
2891  {
2892    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
2893        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
2894        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
2895        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
2896    {
2897      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
2898      m_pocRandomAccess = m_apcSlicePilot->getPOC();
2899    }
2900    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
2901    {
2902      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
2903    }
2904    else 
2905    {
2906      static Bool warningMessage = false;
2907      if(!warningMessage)
2908      {
2909        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
2910        warningMessage = true;
2911      }
2912      return true;
2913    }
2914  }
2915  // skip the reordered pictures, if necessary
2916  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))
2917  {
2918    iPOCLastDisplay++;
2919    return true;
2920  }
2921  // if we reach here, then the picture is not skipped.
2922  return false; 
2923}
2924
2925#if SVC_EXTENSION
2926#if VPS_EXTN_DIRECT_REF_LAYERS
2927TDecTop* TDecTop::getRefLayerDec( UInt refLayerIdc )
2928{
2929  TComVPS* vps = m_parameterSetManagerDecoder.getActiveVPS();
2930  if( vps->getNumDirectRefLayers( m_layerId ) <= 0 )
2931  {
2932    return (TDecTop *)getLayerDec( 0 );
2933  }
2934 
2935  return (TDecTop *)getLayerDec( vps->getRefLayerId( m_layerId, refLayerIdc ) );
2936}
2937#endif
2938
2939#if VPS_EXTN_DIRECT_REF_LAYERS
2940Void TDecTop::setRefLayerParams( TComVPS* vps )
2941{
2942  for(UInt layer = 0; layer < m_numLayer; layer++)
2943  {
2944    TDecTop *decTop = (TDecTop *)getLayerDec(layer);
2945    decTop->setNumSamplePredRefLayers(0);
2946    decTop->setNumMotionPredRefLayers(0);
2947    decTop->setNumDirectRefLayers(0);
2948    for(Int i = 0; i < MAX_VPS_LAYER_ID_PLUS1; i++)
2949    {
2950      decTop->setSamplePredEnabledFlag(i, false);
2951      decTop->setMotionPredEnabledFlag(i, false);
2952      decTop->setSamplePredRefLayerId(i, 0);
2953      decTop->setMotionPredRefLayerId(i, 0);
2954    }
2955    for(Int j = 0; j < layer; j++)
2956    {
2957      if (vps->getDirectDependencyFlag(layer, j))
2958      {
2959        decTop->setRefLayerId(decTop->getNumDirectRefLayers(), vps->getLayerIdInNuh(layer));
2960        decTop->setNumDirectRefLayers(decTop->getNumDirectRefLayers() + 1);
2961
2962        Int samplePredEnabledFlag = (vps->getDirectDependencyType(layer, j) + 1) & 1;
2963        decTop->setSamplePredEnabledFlag(j, samplePredEnabledFlag == 1 ? true : false);
2964        decTop->setNumSamplePredRefLayers(decTop->getNumSamplePredRefLayers() + samplePredEnabledFlag);
2965
2966        Int motionPredEnabledFlag = ((vps->getDirectDependencyType(layer, j) + 1) & 2) >> 1;
2967        decTop->setMotionPredEnabledFlag(j, motionPredEnabledFlag == 1 ? true : false);
2968        decTop->setNumMotionPredRefLayers(decTop->getNumMotionPredRefLayers() + motionPredEnabledFlag);
2969      }
2970    }
2971  }
2972  for( Int i = 1; i < m_numLayer; i++ )
2973  {
2974    Int mIdx = 0, sIdx = 0;
2975    Int iNuhLId = vps->getLayerIdInNuh(i);
2976    TDecTop *decTop = (TDecTop *)getLayerDec(iNuhLId);
2977    for ( Int j = 0; j < i; j++ )
2978    {
2979      if (decTop->getMotionPredEnabledFlag(j))
2980      {
2981        decTop->setMotionPredRefLayerId(mIdx++, vps->getLayerIdInNuh(j));
2982      }
2983      if (decTop->getSamplePredEnabledFlag(j))
2984      {
2985        decTop->setSamplePredRefLayerId(sIdx++, vps->getLayerIdInNuh(j));
2986      }
2987    }
2988  }
2989}
2990
2991#endif
2992
2993#if OUTPUT_LAYER_SET_INDEX
2994Void TDecTop::checkValueOfTargetOutputLayerSetIdx(TComVPS *vps)
2995{
2996  CommonDecoderParams* params = this->getCommonDecoderParams();
2997
2998#if !FIX_CONF_MODE
2999  assert( params->getTargetLayerId() < vps->getMaxLayers() );
3000#endif
3001
3002  if( params->getValueCheckedFlag() )
3003  {
3004    return; // Already checked
3005  }
3006  if( params->getTargetOutputLayerSetIdx() == -1 )  // Output layer set index not specified
3007  {
3008    Bool layerSetMatchFound = false;
3009    // Output layer set index not assigned.
3010    // Based on the value of targetLayerId, check if any of the output layer matches
3011    // Currently, the target layer ID in the encoder assumes that all the layers are decoded   
3012    // Check if any of the output layer sets match this description
3013    for(Int i = 0; i < vps->getNumOutputLayerSets(); i++)
3014    {
3015      Bool layerSetMatchFlag = true;
3016      Int layerSetIdx = vps->getOutputLayerSetIdx( i );
3017      if( vps->getNumLayersInIdList( layerSetIdx ) == params->getTargetLayerId() + 1 )
3018      {
3019        for(Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++)
3020        {
3021          if( vps->getLayerSetLayerIdList( layerSetIdx, j ) != j )
3022          {
3023            layerSetMatchFlag = false;
3024            break;
3025          }
3026        }
3027      }
3028      else
3029      {
3030        layerSetMatchFlag = false;
3031      }
3032     
3033      if( layerSetMatchFlag ) // Potential output layer set candidate found
3034      {
3035        // If target dec layer ID list is also included - check if they match
3036        if( params->getTargetDecLayerIdSet() )
3037        {
3038          if( params->getTargetDecLayerIdSet()->size() ) 
3039          {
3040            for(Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++)
3041            {
3042              if( *(params->getTargetDecLayerIdSet()->begin() + j) != vps->getLayerIdInNuh(vps->getLayerSetLayerIdList( layerSetIdx, j )))
3043              {
3044                layerSetMatchFlag = false;
3045              }
3046            }
3047          }
3048        }
3049        if( layerSetMatchFlag ) // The target dec layer ID list also matches, if present
3050        {
3051          // Match found
3052          layerSetMatchFound = true;
3053          params->setTargetOutputLayerSetIdx( i );
3054          params->setValueCheckedFlag( true );
3055          break;
3056        }
3057      }
3058    }
3059    assert( layerSetMatchFound ); // No output layer set matched the value of either targetLayerId or targetdeclayerIdlist
3060  }   
3061  else // Output layer set index is assigned - check if the values match
3062  {
3063    // Check if the target decoded layer is the highest layer in the list
3064#if R0235_SMALLEST_LAYER_ID
3065    assert( params->getTargetOutputLayerSetIdx() < vps->getNumOutputLayerSets() );
3066#endif
3067#if !CONFORMANCE_BITSTREAM_MODE
3068    assert( params->getTargetOutputLayerSetIdx() < vps->getNumLayerSets() );
3069#endif
3070    Int layerSetIdx = vps->getOutputLayerSetIdx( params->getTargetOutputLayerSetIdx() );  // Index to the layer set
3071#if !CONFORMANCE_BITSTREAM_MODE
3072    assert( params->getTargetLayerId() == vps->getNumLayersInIdList( layerSetIdx ) - 1);
3073#endif
3074#if !R0235_SMALLEST_LAYER_ID
3075    Bool layerSetMatchFlag = true;
3076    for(Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++)
3077    {
3078      if( vps->getLayerSetLayerIdList( layerSetIdx, j ) != j )
3079      {
3080        layerSetMatchFlag = false;
3081        break;
3082      }
3083    }
3084
3085    assert(layerSetMatchFlag);    // Signaled output layer set index does not match targetOutputLayerId.
3086#endif
3087   
3088    // Check if the targetdeclayerIdlist matches the output layer set
3089    if( params->getTargetDecLayerIdSet() )
3090    {
3091      if( params->getTargetDecLayerIdSet()->size() ) 
3092      {
3093        for(Int i = 0; i < vps->getNumLayersInIdList( layerSetIdx ); i++)
3094        {
3095          assert( *(params->getTargetDecLayerIdSet()->begin() + i) == vps->getLayerIdInNuh(vps->getLayerSetLayerIdList( layerSetIdx, i )));
3096        }
3097      }
3098    }
3099    params->setValueCheckedFlag( true );
3100
3101  }
3102#if FIX_CONF_MODE
3103  // Set correct value of targetLayerId
3104  Int targetOlsIdx = params->getTargetOutputLayerSetIdx();
3105  Int targetLsIdx = vps->getOutputLayerSetIdx( targetOlsIdx );
3106  params->setTargetLayerId( vps->getLayerSetLayerIdList( targetLsIdx, vps->getNumLayersInIdList(targetLsIdx)-1 ) );
3107#endif
3108#if FIX_NON_OUTPUT_LAYER
3109  // Check if the current layer is an output layer
3110  for(Int i = 0; i < vps->getNumLayersInIdList( targetLsIdx ); i++)
3111  {
3112    if( vps->getOutputLayerFlag( targetOlsIdx, i ) )
3113    {
3114      this->getLayerDec( vps->getLayerSetLayerIdList( targetLsIdx, i ) )->m_isOutputLayerFlag = true;
3115    }
3116  }
3117#endif
3118}
3119#endif
3120#if RESOLUTION_BASED_DPB
3121Void TDecTop::assignSubDpbs(TComVPS *vps)
3122{
3123  if( m_subDpbIdx == -1 ) // Sub-DPB index is not already assigned
3124  {
3125    Int lsIdx = vps->getOutputLayerSetIdx( getCommonDecoderParams()->getTargetOutputLayerSetIdx() );
3126
3127    Int layerIdx = vps->findLayerIdxInLayerSet( lsIdx, getLayerId() );
3128    assert( layerIdx != -1 ); // Current layer should be found in the layer set.
3129
3130    // Copy from the active VPS based on the layer ID.
3131    m_subDpbIdx = vps->getSubDpbAssigned( lsIdx, layerIdx );
3132  }
3133}
3134#endif
3135#if POC_RESET_IDC_DECODER
3136Void TDecTop::markAllPicsAsNoCurrAu()
3137{
3138  for(Int i = 0; i < MAX_LAYERS; i++)
3139  {
3140    TComList<TComPic*>* listPic = this->getLayerDec(i)->getListPic();
3141    TComList<TComPic*>::iterator  iterPic = listPic->begin();
3142    while ( iterPic != listPic->end() )
3143    {
3144      TComPic *pcPic = *(iterPic);
3145      pcPic->setCurrAuFlag( false );
3146      iterPic++;
3147    }
3148  }
3149}
3150#endif
3151#if Q0048_CGS_3D_ASYMLUT
3152Void TDecTop::initAsymLut(TComSlice *pcSlice)
3153{
3154  if(m_layerId>0)
3155  {
3156    if(!m_pColorMappedPic)
3157    {
3158      Int picWidth    = pcSlice->getPicWidthInLumaSamples();
3159      Int picHeight   = pcSlice->getPicHeightInLumaSamples();
3160      m_pColorMappedPic = new TComPicYuv;
3161      m_pColorMappedPic->create( picWidth, picHeight, pcSlice->getChromaFormatIdc()/*CHROMA_420*/, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, NULL );
3162    }
3163  }
3164}
3165#endif
3166#if POC_RESET_RESTRICTIONS
3167Void TDecTop::resetPocRestrictionCheckParameters()
3168{
3169  TDecTop::m_checkPocRestrictionsForCurrAu       = false;
3170  TDecTop::m_pocResetIdcOrCurrAu                 = -1;
3171  TDecTop::m_baseLayerIdrFlag                    = false;
3172  TDecTop::m_baseLayerPicPresentFlag             = false;
3173  TDecTop::m_baseLayerIrapFlag                   = false;
3174  TDecTop::m_nonBaseIdrPresentFlag               = false;
3175  TDecTop::m_nonBaseIdrType                      = -1;
3176  TDecTop::m_picNonIdrWithRadlPresentFlag        = false;
3177  TDecTop::m_picNonIdrNoLpPresentFlag            = false;
3178}
3179#endif
3180
3181#if R0071_IRAP_EOS_CROSS_LAYER_IMPACTS
3182Void TDecTop::xCheckLayerReset()
3183{
3184#if R0235_SMALLEST_LAYER_ID
3185  if (m_apcSlicePilot->isIRAP() && m_layerId > m_smallestLayerId)
3186#else
3187  if (m_apcSlicePilot->isIRAP() && m_layerId > 0)
3188#endif
3189  {
3190    Bool layerResetFlag;
3191    UInt dolLayerId;
3192    if (m_lastPicHasEos)
3193    {
3194      layerResetFlag = true;
3195      dolLayerId = m_layerId;
3196    }
3197    else if ((m_apcSlicePilot->isCRA() && m_apcSlicePilot->getHandleCraAsBlaFlag()) ||
3198      (m_apcSlicePilot->isIDR() && m_apcSlicePilot->getCrossLayerBLAFlag()) || m_apcSlicePilot->isBLA())
3199    {
3200      layerResetFlag = true;
3201      dolLayerId = m_layerId;
3202    }
3203    else
3204    {
3205      layerResetFlag = false;
3206    }
3207
3208    if (layerResetFlag)
3209    {
3210      for (Int i = 0; i < m_apcSlicePilot->getVPS()->getNumPredictedLayers(dolLayerId); i++)
3211      {
3212        UInt iLayerId = m_apcSlicePilot->getVPS()->getPredictedLayerId(dolLayerId, i);
3213        m_ppcTDecTop[iLayerId]->m_layerInitializedFlag = false;
3214        m_ppcTDecTop[iLayerId]->m_firstPicInLayerDecodedFlag = false;
3215      }
3216
3217      for (TComList<TComPic*>::iterator i = m_cListPic.begin(); i != m_cListPic.end(); i++)
3218      {
3219        if ((*i)->getPOC() != m_apcSlicePilot->getPOC())
3220        {
3221          (*i)->getSlice(0)->setReferenced(false);
3222        }
3223      }
3224
3225      for (UInt i = 0; i < m_apcSlicePilot->getVPS()->getNumPredictedLayers(dolLayerId); i++)
3226      {
3227        UInt predLId = m_apcSlicePilot->getVPS()->getPredictedLayerId(dolLayerId, i);
3228        for (TComList<TComPic*>::iterator pic = m_ppcTDecTop[predLId]->getListPic()->begin(); pic != m_ppcTDecTop[predLId]->getListPic()->end(); pic++)
3229        {
3230          if ((*pic)->getSlice(0)->getPOC() != m_apcSlicePilot->getPOC())
3231          {
3232            (*pic)->getSlice(0)->setReferenced(false);
3233          }
3234        }
3235      }
3236    }
3237  }
3238}
3239
3240Void TDecTop::xSetLayerInitializedFlag()
3241{
3242  if (m_apcSlicePilot->isIRAP() && m_apcSlicePilot->getNoRaslOutputFlag())
3243  {
3244    if (m_layerId == 0)
3245    {
3246      m_ppcTDecTop[m_layerId]->setLayerInitializedFlag(true);
3247    }
3248    else if (!m_ppcTDecTop[m_layerId]->getLayerInitializedFlag() && m_apcSlicePilot->getVPS()->getNumDirectRefLayers(m_layerId) == 0)
3249    {
3250      m_ppcTDecTop[m_layerId]->setLayerInitializedFlag(true);
3251    }
3252    else if (!m_ppcTDecTop[m_layerId]->getLayerInitializedFlag())
3253    {
3254      Bool refLayersInitialized = true;
3255      for (UInt j = 0; j < m_apcSlicePilot->getVPS()->getNumDirectRefLayers(m_layerId); j++)
3256      {
3257        UInt refLayerId = m_apcSlicePilot->getVPS()->getRefLayerId(m_layerId, j);
3258        if (!m_ppcTDecTop[refLayerId]->getLayerInitializedFlag())
3259        {
3260          refLayersInitialized = false;
3261        }
3262      }
3263      if (refLayersInitialized)
3264      {
3265        m_ppcTDecTop[m_layerId]->setLayerInitializedFlag(true);
3266      }
3267    }
3268  }
3269}
3270#endif
3271
3272#if R0235_SMALLEST_LAYER_ID
3273Void TDecTop::xDeriveSmallestLayerId(TComVPS* vps)
3274{
3275  UInt smallestLayerId;
3276  Int  targetOlsIdx = getCommonDecoderParams()->getTargetOutputLayerSetIdx();
3277  assert( targetOlsIdx >= 0 );
3278
3279  UInt targetDecLayerSetIdx = vps->getOutputLayerSetIdx(targetOlsIdx);
3280  UInt lsIdx = targetDecLayerSetIdx;
3281  UInt targetDecLayerIdList[MAX_LAYERS] = {0};
3282
3283  for (UInt i = 0, j = 0; i < vps->getNumLayersInIdList(lsIdx); i++)
3284  {
3285    if (vps->getNecessaryLayerFlag(targetOlsIdx, i))
3286    {
3287      targetDecLayerIdList[j++] = vps->getLayerSetLayerIdList(lsIdx, i);
3288    }
3289  }
3290
3291  if (targetDecLayerSetIdx <= vps->getVpsNumLayerSetsMinus1())
3292  {
3293    smallestLayerId = 0;
3294  }
3295  else if (vps->getNumLayersInIdList(targetDecLayerSetIdx) == 1)
3296  {
3297    smallestLayerId = 0;
3298  }
3299  else
3300  {
3301    smallestLayerId = targetDecLayerIdList[0];
3302  }
3303
3304  for (UInt layer = 0; layer <= MAX_VPS_LAYER_ID_PLUS1 - 1; layer++)
3305  {
3306    m_ppcTDecTop[layer]->m_smallestLayerId = smallestLayerId;
3307  }
3308}
3309#endif
3310
3311#endif //SVC_EXTENSION
3312
3313
3314//! \}
Note: See TracBrowser for help on using the repository browser.