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

Last change on this file since 1166 was 1163, checked in by seregin, 9 years ago

macro cleanup: P0182_VPS_VUI_PS_FLAG

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