source: 3DVCSoftware/branches/HTM-12.1-MV-draft-1/source/Lib/TLibDecoder/TDecTop.cpp @ 1342

Last change on this file since 1342 was 1072, checked in by tech, 11 years ago

Removed 3D-HEVC related integrations.

  • Property svn:eol-style set to native
File size: 45.2 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6* Copyright (c) 2010-2014, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TDecTop.cpp
35    \brief    decoder class
36*/
37
38#include "NALread.h"
39#include "TDecTop.h"
40
41#if H_MV
42ParameterSetManagerDecoder TDecTop::m_parameterSetManagerDecoder;
43#endif
44//! \ingroup TLibDecoder
45//! \{
46
47TDecTop::TDecTop()
48{
49  m_pcPic = 0;
50  m_iMaxRefPicNum = 0;
51#if ENC_DEC_TRACE
52#if H_MV
53  if ( g_hTrace == NULL )
54  {
55#endif
56  g_hTrace = fopen( "TraceDec.txt", "wb" );
57  g_bJustDoIt = g_bEncDecTraceDisable;
58  g_nSymbolCounter = 0;
59#if H_MV
60  }
61#endif
62#endif
63  m_associatedIRAPType = NAL_UNIT_INVALID;
64  m_pocCRA = 0;
65  m_pocRandomAccess = MAX_INT; 
66  m_prevPOC                = MAX_INT;
67  m_bFirstSliceInPicture    = true;
68  m_bFirstSliceInSequence   = true;
69  m_prevSliceSkipped = false;
70  m_skippedPOC = 0;
71#if SETTING_NO_OUT_PIC_PRIOR
72  m_bFirstSliceInBitstream  = true;
73  m_lastPOCNoOutputPriorPics = -1;
74  m_craNoRaslOutputFlag = false;
75  m_isNoOutputPriorPics = false;
76#endif
77#if H_MV
78  m_isLastNALWasEos = false;
79  m_layerId = 0;
80  m_viewId = 0;
81#if H_MV
82  m_targetOptLayerSetIdx = -1; 
83#endif
84#endif
85}
86
87TDecTop::~TDecTop()
88{
89#if ENC_DEC_TRACE
90  fclose( g_hTrace );
91#endif
92}
93
94Void TDecTop::create()
95{
96  m_cGopDecoder.create();
97  m_apcSlicePilot = new TComSlice;
98  m_uiSliceIdx = 0;
99}
100
101Void TDecTop::destroy()
102{
103  m_cGopDecoder.destroy();
104 
105  delete m_apcSlicePilot;
106  m_apcSlicePilot = NULL;
107 
108  m_cSliceDecoder.destroy();
109}
110
111Void TDecTop::init()
112{
113  // initialize ROM
114#if !H_MV
115  initROM();
116#endif
117  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO );
118  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
119  m_cEntropyDecoder.init(&m_cPrediction);
120}
121
122Void TDecTop::deletePicBuffer ( )
123{
124  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
125  Int iSize = Int( m_cListPic.size() );
126 
127  for (Int i = 0; i < iSize; i++ )
128  {
129    TComPic* pcPic = *(iterPic++);
130#if H_MV
131    if( pcPic )
132    {
133#endif
134    pcPic->destroy();
135   
136    delete pcPic;
137    pcPic = NULL;
138#if H_MV
139    }
140#endif
141  }
142 
143  m_cSAO.destroy();
144 
145  m_cLoopFilter.        destroy();
146 
147#if !H_MV
148  // destroy ROM
149  destroyROM();
150#endif
151}
152
153Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
154{
155  Int  numReorderPics[MAX_TLAYER];
156  Window &conformanceWindow = pcSlice->getSPS()->getConformanceWindow();
157  Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window();
158
159#if H_MV
160    assert( conformanceWindow   .getScaledFlag() ); 
161    assert( defaultDisplayWindow.getScaledFlag() );
162#endif
163  for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
164  {
165#if H_MV
166    numReorderPics[temporalLayer] = ( getLayerId() == 0 ) ? pcSlice->getSPS()->getNumReorderPics(temporalLayer) : pcSlice->getVPS()->getNumReorderPics(temporalLayer);
167#else
168    numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer);
169#endif
170  }
171#if H_MV
172  if ( getLayerId() == 0 )
173  { 
174    m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer());
175  }
176  else
177  {
178    m_iMaxRefPicNum = pcSlice->getVPS()->getMaxDecPicBuffering(pcSlice->getTLayer());
179#if H_MV_HLS7_GEN
180    TComVPS* vps         = pcSlice->getVPS();
181    TComDpbSize* dpbSize = vps->getDpbSize(); 
182    Int lsIdx            = vps->olsIdxToLsIdx( getTargetOutputLayerSetIdx()); // Is this correct, seems to be missing in spec?
183    Int layerIdx         = vps->getIdxInLayerSet     ( lsIdx, getLayerId() ); 
184    Int subDpbIdx        = dpbSize->getSubDpbAssigned( lsIdx, layerIdx ); 
185    m_iMaxRefPicNum      = dpbSize->getMaxVpsDecPicBufferingMinus1(getTargetOutputLayerSetIdx(), subDpbIdx , vps->getSubLayersVpsMaxMinus1( vps->getLayerIdInVps( getLayerId() ) ) + 1 ) + 1 ; 
186#endif   
187  }
188#else
189  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
190#endif
191  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
192  {
193    rpcPic = new TComPic();
194   
195    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
196                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
197    m_cListPic.pushBack( rpcPic );
198   
199    return;
200  }
201 
202  Bool bBufferIsAvailable = false;
203  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
204  while (iterPic != m_cListPic.end())
205  {
206    rpcPic = *(iterPic++);
207    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
208    {
209      rpcPic->setOutputMark(false);
210#if H_MV
211      rpcPic->setPicOutputFlag(false); 
212#endif
213      bBufferIsAvailable = true;
214      break;
215    }
216
217    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
218    {
219      rpcPic->setOutputMark(false);
220#if H_MV
221      rpcPic->setPicOutputFlag(false); 
222#endif
223      rpcPic->setReconMark( false );
224      rpcPic->getPicYuvRec()->setBorderExtension( false );
225      bBufferIsAvailable = true;
226      break;
227    }
228  }
229 
230  if ( !bBufferIsAvailable )
231  {
232    //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer.
233    m_iMaxRefPicNum++;
234    rpcPic = new TComPic();
235    m_cListPic.pushBack( rpcPic );
236  }
237  rpcPic->destroy();
238  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
239                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
240}
241
242#if H_MV
243Void TDecTop::endPicDecoding(Int& poc, TComList<TComPic*>*& rpcListPic, std::vector<Int>& targetDecLayerIdSet )
244#else
245Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic)
246#endif
247{
248  if (!m_pcPic)
249  {
250    /* nothing to deblock */
251    return;
252  }
253 
254  TComPic*&   pcPic         = m_pcPic;
255
256  // Execute Deblock + Cleanup
257
258  m_cGopDecoder.filterPicture(pcPic);
259
260  TComSlice::sortPicList( m_cListPic ); // sorting for application output
261  poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
262  rpcListPic          = &m_cListPic; 
263  m_cCuDecoder.destroy();       
264#if H_MV
265  TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
266  TComSlice::markCurrPic( pcPic ); 
267#endif
268  m_bFirstSliceInPicture  = true;
269
270  return;
271}
272
273#if SETTING_NO_OUT_PIC_PRIOR
274Void TDecTop::checkNoOutputPriorPics (TComList<TComPic*>*& rpcListPic)
275{
276  if (!rpcListPic || !m_isNoOutputPriorPics) return;
277
278  TComList<TComPic*>::iterator  iterPic   = rpcListPic->begin();
279
280  while (iterPic != rpcListPic->end())
281  {
282    TComPic*& pcPicTmp = *(iterPic++);
283    if (m_lastPOCNoOutputPriorPics != pcPicTmp->getPOC())
284    {
285      pcPicTmp->setOutputMark(false);
286#if H_MV
287      pcPicTmp->setPicOutputFlag(false); 
288#endif
289    }
290  }
291}
292#endif
293
294Void TDecTop::xCreateLostPicture(Int iLostPoc) 
295{
296  printf("\ninserting lost poc : %d\n",iLostPoc);
297  TComSlice cFillSlice;
298  cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
299  cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
300  cFillSlice.initSlice();
301  TComPic *cFillPic;
302  xGetNewPicBuffer(&cFillSlice,cFillPic);
303  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
304  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
305  cFillPic->getSlice(0)->initSlice();
306 
307  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
308  Int closestPoc = 1000000;
309  while ( iterPic != m_cListPic.end())
310  {
311    TComPic * rpcPic = *(iterPic++);
312    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())
313    {
314      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
315    }
316  }
317  iterPic = m_cListPic.begin();
318  while ( iterPic != m_cListPic.end())
319  {
320    TComPic *rpcPic = *(iterPic++);
321    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
322    {
323      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
324      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
325      break;
326    }
327  }
328  cFillPic->setCurrSliceIdx(0);
329  for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) 
330  {
331    cFillPic->getCU(i)->initCU(cFillPic,i);
332  }
333  cFillPic->getSlice(0)->setReferenced(true);
334  cFillPic->getSlice(0)->setPOC(iLostPoc);
335  cFillPic->setReconMark(true);
336  cFillPic->setOutputMark(true);
337  if(m_pocRandomAccess == MAX_INT)
338  {
339    m_pocRandomAccess = iLostPoc;
340  }
341}
342
343
344Void TDecTop::xActivateParameterSets()
345{
346  m_parameterSetManagerDecoder.applyPrefetchedPS();
347 
348  TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
349  assert (pps != 0);
350
351  TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId());
352  assert (sps != 0);
353
354#if H_MV
355  TComVPS* vps = m_parameterSetManagerDecoder.getVPS(sps->getVPSId());
356  assert (vps != 0); 
357  if (!m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP(), m_layerId ) )
358#else
359  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
360#endif
361  {
362    printf ("Parameter set activation failed!");
363    assert (0);
364  }
365
366#if H_MV
367  sps->inferSpsMaxDecPicBufferingMinus1( vps, m_targetOptLayerSetIdx, getLayerId(), false ); 
368#if !H_MV_HLS10_ADD_LAYERSETS
369  vps->inferDbpSizeLayerSetZero( sps, false ); 
370#endif
371  // When the value of vps_num_rep_formats_minus1 in the active VPS is equal to 0
372  if ( vps->getVpsNumRepFormatsMinus1() == 0 )
373  {
374    //, it is a requirement of bitstream conformance that the value of update_rep_format_flag shall be equal to 0.
375    assert( sps->getUpdateRepFormatFlag() == false ); 
376  }
377  sps->checkRpsMaxNumPics( vps, getLayerId() ); 
378#if H_MV_HLS10_MULTILAYERSPS
379
380  if( sps->getLayerId() != 0 )
381  {
382    sps->inferSpsMaxSubLayersMinus1( true, vps ); 
383  }
384
385#if H_MV_HLS10_MULTILAYERSPS
386  // It is a requirement of bitstream conformance that, when the SPS is referred to by
387  // any current picture that belongs to an independent non-base layer, the value of
388  // MultiLayerExtSpsFlag derived from the SPS shall be equal to 0.
389
390  if ( m_layerId > 0 && vps->getNumRefLayers( m_layerId ) == 0 )
391  { 
392    assert( sps->getMultiLayerExtSpsFlag() == 0 ); 
393  }
394#endif
395
396  if( sps->getMultiLayerExtSpsFlag() )
397  {
398    sps->setTemporalIdNestingFlag( (sps->getMaxTLayers() > 1) ? vps->getTemporalNestingFlag() : true );
399  }
400#else
401  if( m_layerId > 0 )
402  {
403    sps->setTemporalIdNestingFlag( (sps->getMaxTLayers() > 1) ? vps->getTemporalNestingFlag() : true );
404  }
405#endif
406#endif
407
408  if( pps->getDependentSliceSegmentsEnabledFlag() )
409  {
410    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
411
412    if (m_cSliceDecoder.getCtxMemSize() != NumCtx)
413    {
414      m_cSliceDecoder.initCtxMem(NumCtx);
415      for ( UInt st = 0; st < NumCtx; st++ )
416      {
417        TDecSbac* ctx = NULL;
418        ctx = new TDecSbac;
419        ctx->init( &m_cBinCABAC );
420        m_cSliceDecoder.setCtxMem( ctx, st );
421      }
422    }
423  }
424
425  m_apcSlicePilot->setPPS(pps);
426  m_apcSlicePilot->setSPS(sps);
427#if H_MV
428  m_apcSlicePilot->setVPS(vps); 
429#if H_MV_HLS10_REF_PRED_LAYERS
430  // The nuh_layer_id value of the NAL unit containing the PPS that is activated for a layer layerA with nuh_layer_id equal to nuhLayerIdA shall be equal to 0, or nuhLayerIdA, or the nuh_layer_id of a direct or indirect reference layer of layerA.
431  assert( pps->getLayerId() == m_layerId || pps->getLayerId( ) == 0 || vps->getDependencyFlag( m_layerId, pps->getLayerId() ) );   
432  // The nuh_layer_id value of the NAL unit containing the SPS that is activated for a layer layerA with nuh_layer_id equal to nuhLayerIdA shall be equal to 0, or nuhLayerIdA, or the nuh_layer_id of a direct or indirect reference layer of layerA.
433  assert( sps->getLayerId() == m_layerId || sps->getLayerId( ) == 0 || vps->getDependencyFlag( m_layerId, sps->getLayerId() ) );
434#else
435  // The nuh_layer_id value of the NAL unit containing the PPS that is activated for a layer layerA with nuh_layer_id equal to nuhLayerIdA shall be equal to 0, or nuhLayerIdA, or the nuh_layer_id of a direct or indirect reference layer of layerA.
436  assert( pps->getLayerId() == m_layerId || pps->getLayerId( ) == 0 || vps->getInDirectDependencyFlag( m_layerId, pps->getLayerId() ) );   
437  // The nuh_layer_id value of the NAL unit containing the SPS that is activated for a layer layerA with nuh_layer_id equal to nuhLayerIdA shall be equal to 0, or nuhLayerIdA, or the nuh_layer_id of a direct or indirect reference layer of layerA.
438  assert( sps->getLayerId() == m_layerId || sps->getLayerId( ) == 0 || vps->getInDirectDependencyFlag( m_layerId, sps->getLayerId() ) );
439#endif
440  sps->inferRepFormat  ( vps , m_layerId ); 
441  sps->inferScalingList( m_parameterSetManagerDecoder.getActiveSPS( sps->getSpsScalingListRefLayerId() ) ); 
442
443#endif
444  pps->setSPS(sps);
445  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
446  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
447
448  g_bitDepthY     = sps->getBitDepthY();
449  g_bitDepthC     = sps->getBitDepthC();
450  g_uiMaxCUWidth  = sps->getMaxCUWidth();
451  g_uiMaxCUHeight = sps->getMaxCUHeight();
452  g_uiMaxCUDepth  = sps->getMaxCUDepth();
453  g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() );
454
455  for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++)
456  {
457    sps->setAMPAcc( i, sps->getUseAMP() );
458  }
459
460  for (Int i = sps->getLog2DiffMaxMinCodingBlockSize(); i < sps->getMaxCUDepth(); i++)
461  {
462    sps->setAMPAcc( i, 0 );
463  }
464
465  m_cSAO.destroy();
466  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() );
467  m_cLoopFilter.create( sps->getMaxCUDepth() );
468}
469
470#if H_MV
471Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool newLayerFlag, Bool& sliceSkippedFlag  )
472{
473  assert( nalu.m_layerId == m_layerId ); 
474#else
475Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
476{
477#endif
478  TComPic*&   pcPic         = m_pcPic;
479  m_apcSlicePilot->initSlice();
480
481  if (m_bFirstSliceInPicture)
482  {
483    m_uiSliceIdx     = 0;
484  }
485  else
486  {
487    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
488  }
489  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
490
491  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
492  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
493                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
494                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
495                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
496                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
497  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
498 
499  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
500  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
501
502#if H_MV
503  m_apcSlicePilot->setRefPicSetInterLayer( & m_refPicSetInterLayer0, &m_refPicSetInterLayer1 ); 
504  m_apcSlicePilot->setLayerId( nalu.m_layerId );
505  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder, m_targetOptLayerSetIdx );
506#endif
507  // set POC for dependent slices in skipped pictures
508  if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped) 
509  {
510    m_apcSlicePilot->setPOC(m_skippedPOC);
511  }
512
513  m_apcSlicePilot->setAssociatedIRAPPOC(m_pocCRA);
514  m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType);
515
516#if H_MV 
517  TComVPS* vps     = m_apcSlicePilot->getVPS();
518  Int layerId  = nalu.m_layerId;   
519  setViewId   ( vps->getViewId   ( layerId )      ); 
520#endif
521
522#if SETTING_NO_OUT_PIC_PRIOR
523  //For inference of NoOutputOfPriorPicsFlag
524  if (m_apcSlicePilot->getRapPicFlag())
525  {
526    if ((m_apcSlicePilot->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_apcSlicePilot->getNalUnitType() <= NAL_UNIT_CODED_SLICE_IDR_N_LP) || 
527        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_bFirstSliceInSequence) ||
528        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getHandleCraAsBlaFlag()))
529    {
530      m_apcSlicePilot->setNoRaslOutputFlag(true);
531    }
532    //the inference for NoOutputPriorPicsFlag
533    if (!m_bFirstSliceInBitstream && m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag())
534    {
535      if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
536      {
537        m_apcSlicePilot->setNoOutputPriorPicsFlag(true);
538      }
539    }
540    else
541    {
542      m_apcSlicePilot->setNoOutputPriorPicsFlag(false);
543    }
544
545    if(m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
546    {
547      m_craNoRaslOutputFlag = m_apcSlicePilot->getNoRaslOutputFlag();
548    }
549  }
550  if (m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoOutputPriorPicsFlag())
551  {
552    m_lastPOCNoOutputPriorPics = m_apcSlicePilot->getPOC();
553    m_isNoOutputPriorPics = true;
554  }
555  else
556  {
557    m_isNoOutputPriorPics = false;
558  }
559
560  //For inference of PicOutputFlag
561  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R)
562  {
563    if ( m_craNoRaslOutputFlag )
564    {
565      m_apcSlicePilot->setPicOutputFlag(false);
566    }
567  }
568#endif
569
570#if FIX_POC_CRA_NORASL_OUTPUT
571  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_craNoRaslOutputFlag) //Reset POC MSB when CRA has NoRaslOutputFlag equal to 1
572  {
573    Int iMaxPOClsb = 1 << m_apcSlicePilot->getSPS()->getBitsForPOC();
574    m_apcSlicePilot->setPOC( m_apcSlicePilot->getPOC() & (iMaxPOClsb - 1) );
575  }
576#endif
577#if H_MV
578    xCeckNoClrasOutput();
579#endif
580    // Skip pictures due to random access
581    if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
582    {
583    m_prevSliceSkipped = true;
584    m_skippedPOC = m_apcSlicePilot->getPOC();
585#if H_MV
586    sliceSkippedFlag = true; 
587#endif
588      return false;
589    }
590    // Skip TFD pictures associated with BLA/BLANT pictures
591    if (isSkipPictureForBLA(iPOCLastDisplay))
592    {
593    m_prevSliceSkipped = true;
594    m_skippedPOC = m_apcSlicePilot->getPOC();
595#if H_MV
596    sliceSkippedFlag = true; 
597#endif
598      return false;
599    }
600
601  // clear previous slice skipped flag
602  m_prevSliceSkipped = false;
603
604  //we should only get a different poc for a new picture (with CTU address==0)
605  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (m_apcSlicePilot->getSliceCurStartCUAddr()!=0))
606  {
607    printf ("Warning, the first slice of a picture might have been lost!\n");
608  }
609  // exit when a new picture is found
610  if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence )
611  {
612    if (m_prevPOC >= m_pocRandomAccess)
613    {
614      m_prevPOC = m_apcSlicePilot->getPOC();
615      return true;
616    }
617    m_prevPOC = m_apcSlicePilot->getPOC();
618  }
619#if H_MV
620  if ( newLayerFlag )
621  {
622    return false; 
623  }
624#if ENC_DEC_TRACE
625#if H_MV_ENC_DEC_TRAC
626  // parse remainder of SH
627   g_disableHLSTrace = false; 
628#endif
629#endif
630#endif
631  // actual decoding starts here
632#if H_MV
633   // This part needs further testing !
634   if ( m_apcSlicePilot->getPocResetFlag() )
635   {   
636     xResetPocInPicBuffer();
637   }
638#endif
639   
640#if I0044_SLICE_TMVP
641  if ( m_apcSlicePilot->getTLayer() == 0 && m_apcSlicePilot->getEnableTMVPFlag() == 0 )
642  {
643    //update all pics in the DPB such that they cannot be used for TMPV ref
644    TComList<TComPic*>::iterator  iterRefPic = m_cListPic.begin(); 
645    while( iterRefPic != m_cListPic.end() )
646    {
647      TComPic *refPic = *iterRefPic;
648      if( ( refPic->getLayerId() == m_apcSlicePilot->getLayerId() ) && refPic->getReconMark() )
649      {
650        for(Int i = refPic->getNumAllocatedSlice()-1; i >= 0; i--)
651        {
652
653          TComSlice *refSlice = refPic->getSlice(i);
654          refSlice->setAvailableForTMVPRefFlag( false );
655        }
656      }
657      iterRefPic++;
658    }
659  }
660  m_apcSlicePilot->setAvailableForTMVPRefFlag( true );
661#endif
662
663  xActivateParameterSets();
664
665  if (m_apcSlicePilot->isNextSlice()) 
666  {
667    m_prevPOC = m_apcSlicePilot->getPOC();
668  }
669  m_bFirstSliceInSequence = false;
670#if SETTING_NO_OUT_PIC_PRIOR 
671  m_bFirstSliceInBitstream  = false;
672#endif
673  //detect lost reference picture and insert copy of earlier frame.
674  Int lostPoc;
675  while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
676  {
677    xCreateLostPicture(lostPoc-1);
678  }
679  if (m_bFirstSliceInPicture)
680  {
681    // Buffer initialize for prediction.
682    m_cPrediction.initTempBuff();
683    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
684#if H_MV
685    m_apcSlicePilot->createInterLayerReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
686#endif
687    //  Get a new picture buffer
688    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
689
690    Bool isField = false;
691    Bool isTff = false;
692   
693    if(!m_SEIs.empty())
694    {
695      // Check if any new Picture Timing SEI has arrived
696      SEIMessages pictureTimingSEIs = extractSeisByType (m_SEIs, SEI::PICTURE_TIMING);
697      if (pictureTimingSEIs.size()>0)
698      {
699        SEIPictureTiming* pictureTiming = (SEIPictureTiming*) *(pictureTimingSEIs.begin());
700        isField = (pictureTiming->m_picStruct == 1) || (pictureTiming->m_picStruct == 2);
701        isTff =  (pictureTiming->m_picStruct == 1);
702      }
703    }
704   
705    //Set Field/Frame coding mode
706    m_pcPic->setField(isField);
707    m_pcPic->setTopField(isTff);
708   
709    // transfer any SEI messages that have been received to the picture
710    pcPic->setSEIs(m_SEIs);
711    m_SEIs.clear();
712
713    // Recursive structure
714    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
715    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
716    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
717
718    m_cSliceDecoder.create();
719  }
720  else
721  {
722    // Check if any new SEI has arrived
723    if(!m_SEIs.empty())
724    {
725      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
726      SEIMessages &picSEI = pcPic->getSEIs();
727      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
728      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
729      deleteSEIs(m_SEIs);
730    }
731  }
732 
733  //  Set picture slice pointer
734  TComSlice*  pcSlice = m_apcSlicePilot;
735  Bool bNextSlice     = pcSlice->isNextSlice();
736
737  UInt uiCummulativeTileWidth;
738  UInt uiCummulativeTileHeight;
739  UInt i, j, p;
740
741  //set NumColumnsMins1 and NumRowsMinus1
742  pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
743  pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
744
745  //create the TComTileArray
746  pcPic->getPicSym()->xCreateTComTileArray();
747
748  if( pcSlice->getPPS()->getUniformSpacingFlag() )
749  {
750    //set the width for each tile
751    for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
752    {
753      for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
754      {
755        pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
756          setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
757          - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
758      }
759    }
760
761    //set the height for each tile
762    for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
763    {
764      for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
765      {
766        pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
767          setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
768          - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
769      }
770    }
771  }
772  else
773  {
774    //set the width for each tile
775    for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
776    {
777      uiCummulativeTileWidth = 0;
778      for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
779      {
780        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
781        uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
782      }
783      pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
784    }
785
786    //set the height for each tile
787    for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
788    {
789      uiCummulativeTileHeight = 0;
790      for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
791      { 
792        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
793        uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
794      }
795      pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
796    }
797  }
798
799  pcPic->getPicSym()->xInitTiles();
800
801  //generate the Coding Order Map and Inverse Coding Order Map
802  UInt uiEncCUAddr;
803  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
804  {
805    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
806    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
807  }
808  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
809  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
810
811  //convert the start and end CU addresses of the slice and dependent slice into encoding order
812  pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) );
813  pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) );
814  if(pcSlice->isNextSlice())
815  {
816    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
817    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
818  }
819
820  if (m_bFirstSliceInPicture) 
821  {
822    if(pcPic->getNumAllocatedSlice() != 1)
823    {
824      pcPic->clearSliceBuffer();
825    }
826  }
827  else
828  {
829    pcPic->allocateNewSlice();
830  }
831  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
832  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
833  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
834
835  pcPic->setTLayer(nalu.m_temporalId);
836
837#if H_MV
838  pcPic->setLayerId( nalu.m_layerId );
839  pcPic->setViewId ( getViewId() );
840#endif
841  if (bNextSlice)
842  {
843    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_associatedIRAPType, m_cListPic );
844    // Set reference list
845#if H_MV   
846    std::vector< TComPic* > tempRefPicLists[2];
847    std::vector< Bool     > usedAsLongTerm [2];
848    Int       numPocTotalCurr;
849
850    pcSlice->getTempRefPicLists( m_cListPic, m_refPicSetInterLayer0, m_refPicSetInterLayer1, tempRefPicLists, usedAsLongTerm, numPocTotalCurr);
851    pcSlice->setRefPicList     ( tempRefPicLists, usedAsLongTerm, numPocTotalCurr, true ); 
852#else
853    pcSlice->setRefPicList( m_cListPic, true );
854#endif
855
856    // For generalized B
857#if I0044_SLICE_TMVP
858    if( m_layerId > 0 && !pcSlice->isIntra() && pcSlice->getEnableTMVPFlag() )
859    {
860      TComPic* refPic = pcSlice->getRefPic(RefPicList(1 - pcSlice->getColFromL0Flag()), pcSlice->getColRefIdx());
861
862      assert ( refPic );
863      assert ( refPic->getPicSym()->getSlice(0)->getAvailableForTMVPRefFlag() == true );
864    }
865#endif
866
867    // For generalized B
868    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
869    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
870    {
871      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
872      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
873
874      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
875      {
876        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
877      }
878    }
879    if (!pcSlice->isIntra())
880    {
881      Bool bLowDelay = true;
882      Int  iCurrPOC  = pcSlice->getPOC();
883      Int iRefIdx = 0;
884
885      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
886      {
887        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
888        {
889          bLowDelay = false;
890        }
891      }
892      if (pcSlice->isInterB())
893      {
894        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
895        {
896          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
897          {
898            bLowDelay = false;
899          }
900        }       
901      }
902
903      pcSlice->setCheckLDC(bLowDelay);           
904    }
905
906    //---------------
907    pcSlice->setRefPOCList();
908  }
909
910  pcPic->setCurrSliceIdx(m_uiSliceIdx);
911  if(pcSlice->getSPS()->getScalingListFlag())
912  {
913    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
914    if(pcSlice->getPPS()->getScalingListPresentFlag())
915    {
916      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
917    }
918    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
919    {
920      pcSlice->setDefaultScalingList();
921    }
922    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
923    m_cTrQuant.setUseScalingList(true);
924  }
925  else
926  {
927    m_cTrQuant.setFlatScalingList();
928    m_cTrQuant.setUseScalingList(false);
929  }
930
931
932  //  Decode a picture
933  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
934  m_bFirstSliceInPicture = false;
935  m_uiSliceIdx++;
936
937  return false;
938}
939
940Void TDecTop::xDecodeVPS()
941{
942  TComVPS* vps = new TComVPS();
943 
944  m_cEntropyDecoder.decodeVPS( vps );
945  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
946}
947
948Void TDecTop::xDecodeSPS()
949{
950  TComSPS* sps = new TComSPS();
951#if H_MV
952  sps->setLayerId( getLayerId() ); 
953#endif
954  m_cEntropyDecoder.decodeSPS( sps );
955  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
956}
957
958Void TDecTop::xDecodePPS()
959{
960  TComPPS* pps = new TComPPS();
961#if H_MV
962  pps->setLayerId( getLayerId() ); 
963#endif
964  m_cEntropyDecoder.decodePPS( pps );
965  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
966}
967
968Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
969{
970  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
971  {
972#if H_MV
973    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS( m_layerId ) );
974#else
975    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
976#endif
977  }
978  else
979  {
980#if H_MV
981    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS( m_layerId ) );
982#else
983    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
984#endif
985    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
986    if (activeParamSets.size()>0)
987    {
988      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
989      m_parameterSetManagerDecoder.applyPrefetchedPS();
990      assert(seiAps->activeSeqParameterSetId.size()>0);
991#if H_MV
992      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParameterSetId[0], m_layerId ))
993#else
994      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParameterSetId[0] ))
995#endif
996      {
997        printf ("Warning SPS activation with Active parameter set SEI failed");
998      }
999    }
1000  }
1001}
1002
1003#if H_MV
1004Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayerFlag, Bool& sliceSkippedFlag )
1005#else
1006Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1007#endif
1008{
1009  // Initialize entropy decoder
1010  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1011  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
1012
1013  switch (nalu.m_nalUnitType)
1014  {
1015    case NAL_UNIT_VPS:
1016      xDecodeVPS();
1017#if H_MV
1018      m_isLastNALWasEos = false;
1019#endif
1020      return false;
1021     
1022    case NAL_UNIT_SPS:
1023      xDecodeSPS();
1024      return false;
1025
1026    case NAL_UNIT_PPS:
1027      xDecodePPS();
1028      return false;
1029     
1030    case NAL_UNIT_PREFIX_SEI:
1031    case NAL_UNIT_SUFFIX_SEI:
1032#if H_MV
1033      if ( nalu.m_nalUnitType == NAL_UNIT_SUFFIX_SEI )
1034      {
1035        assert( m_isLastNALWasEos == false );
1036      }
1037#endif
1038      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
1039      return false;
1040
1041    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1042    case NAL_UNIT_CODED_SLICE_TRAIL_N:
1043    case NAL_UNIT_CODED_SLICE_TSA_R:
1044    case NAL_UNIT_CODED_SLICE_TSA_N:
1045    case NAL_UNIT_CODED_SLICE_STSA_R:
1046    case NAL_UNIT_CODED_SLICE_STSA_N:
1047    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
1048    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
1049    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1050    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
1051    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
1052    case NAL_UNIT_CODED_SLICE_CRA:
1053    case NAL_UNIT_CODED_SLICE_RADL_N:
1054    case NAL_UNIT_CODED_SLICE_RADL_R:
1055    case NAL_UNIT_CODED_SLICE_RASL_N:
1056    case NAL_UNIT_CODED_SLICE_RASL_R:
1057#if H_MV
1058      if (nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_N ||
1059          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_N ||
1060          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_N ||
1061          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
1062          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N )
1063      {
1064        assert( m_isLastNALWasEos == false );
1065      }
1066      else
1067      {
1068        m_isLastNALWasEos = false;
1069      }
1070
1071      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, newLayerFlag, sliceSkippedFlag );
1072#else
1073      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1074#endif
1075      break;
1076    case NAL_UNIT_EOS:
1077#if H_MV
1078      assert( m_isLastNALWasEos == false );
1079      //Check layer id of the nalu. if it is not 0, give a warning message and just return without doing anything.
1080      if (nalu.m_layerId > 0)
1081      {
1082        printf( "\nThis bitstream has EOS with non-zero layer id.\n" );
1083        return false;
1084      }
1085      m_isLastNALWasEos = true;
1086#endif
1087      m_associatedIRAPType = NAL_UNIT_INVALID;
1088      m_pocCRA = 0;
1089      m_pocRandomAccess = MAX_INT;
1090      m_prevPOC = MAX_INT;
1091      m_bFirstSliceInPicture = true;
1092      m_bFirstSliceInSequence = true;
1093      m_prevSliceSkipped = false;
1094      m_skippedPOC = 0;
1095      return false;
1096     
1097    case NAL_UNIT_ACCESS_UNIT_DELIMITER:
1098      // TODO: process AU delimiter
1099      return false;
1100     
1101    case NAL_UNIT_EOB:
1102      return false;
1103     
1104    case NAL_UNIT_FILLER_DATA:
1105#if H_MV
1106      assert( m_isLastNALWasEos == false );
1107#endif
1108      return false;
1109     
1110    case NAL_UNIT_RESERVED_VCL_N10:
1111    case NAL_UNIT_RESERVED_VCL_R11:
1112    case NAL_UNIT_RESERVED_VCL_N12:
1113    case NAL_UNIT_RESERVED_VCL_R13:
1114    case NAL_UNIT_RESERVED_VCL_N14:
1115    case NAL_UNIT_RESERVED_VCL_R15:
1116     
1117    case NAL_UNIT_RESERVED_IRAP_VCL22:
1118    case NAL_UNIT_RESERVED_IRAP_VCL23:
1119     
1120    case NAL_UNIT_RESERVED_VCL24:
1121    case NAL_UNIT_RESERVED_VCL25:
1122    case NAL_UNIT_RESERVED_VCL26:
1123    case NAL_UNIT_RESERVED_VCL27:
1124    case NAL_UNIT_RESERVED_VCL28:
1125    case NAL_UNIT_RESERVED_VCL29:
1126    case NAL_UNIT_RESERVED_VCL30:
1127    case NAL_UNIT_RESERVED_VCL31:
1128     
1129    case NAL_UNIT_RESERVED_NVCL41:
1130    case NAL_UNIT_RESERVED_NVCL42:
1131    case NAL_UNIT_RESERVED_NVCL43:
1132    case NAL_UNIT_RESERVED_NVCL44:
1133    case NAL_UNIT_RESERVED_NVCL45:
1134    case NAL_UNIT_RESERVED_NVCL46:
1135    case NAL_UNIT_RESERVED_NVCL47:
1136    case NAL_UNIT_UNSPECIFIED_48:
1137    case NAL_UNIT_UNSPECIFIED_49:
1138    case NAL_UNIT_UNSPECIFIED_50:
1139    case NAL_UNIT_UNSPECIFIED_51:
1140    case NAL_UNIT_UNSPECIFIED_52:
1141    case NAL_UNIT_UNSPECIFIED_53:
1142    case NAL_UNIT_UNSPECIFIED_54:
1143    case NAL_UNIT_UNSPECIFIED_55:
1144    case NAL_UNIT_UNSPECIFIED_56:
1145    case NAL_UNIT_UNSPECIFIED_57:
1146    case NAL_UNIT_UNSPECIFIED_58:
1147    case NAL_UNIT_UNSPECIFIED_59:
1148    case NAL_UNIT_UNSPECIFIED_60:
1149    case NAL_UNIT_UNSPECIFIED_61:
1150    case NAL_UNIT_UNSPECIFIED_62:
1151    case NAL_UNIT_UNSPECIFIED_63:
1152    default:
1153      assert (0);
1154  }
1155
1156  return false;
1157}
1158
1159/** Function for checking if picture should be skipped because of association with a previous BLA picture
1160 * \param iPOCLastDisplay POC of last picture displayed
1161 * \returns true if the picture should be skipped
1162 * This function skips all TFD pictures that follow a BLA picture
1163 * in decoding order and precede it in output order.
1164 */
1165Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
1166{
1167  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) && 
1168       m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
1169  {
1170    iPOCLastDisplay++;
1171    return true;
1172  }
1173  return false;
1174}
1175
1176/** Function for checking if picture should be skipped because of random access
1177 * \param iSkipFrame skip frame counter
1178 * \param iPOCLastDisplay POC of last picture displayed
1179 * \returns true if the picture shold be skipped in the random access.
1180 * This function checks the skipping of pictures in the case of -s option random access.
1181 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1182 * It also checks the type of Nal unit type at the random access point.
1183 * 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.
1184 * If the random access point is IDR all pictures after the random access point are decoded.
1185 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
1186 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
1187 * access point there is no guarantee that the decoder will not crash.
1188 */
1189Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
1190{
1191  if (iSkipFrame) 
1192  {
1193    iSkipFrame--;   // decrement the counter
1194    return true;
1195  }
1196#if H_MV
1197  else if ( !m_layerInitilizedFlag[ m_layerId ] ) // start of random access point, m_pocRandomAccess has not been set yet.
1198#else
1199  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1200#endif
1201  {
1202    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
1203        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1204        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1205        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
1206    {
1207
1208#if H_MV
1209      if ( xAllRefLayersInitilized() )
1210      {
1211        m_layerInitilizedFlag[ m_layerId ] = true; 
1212        m_pocRandomAccess = m_apcSlicePilot->getPOC();
1213      }
1214      else
1215      {
1216        return true; 
1217      }
1218#else
1219      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
1220      m_pocRandomAccess = m_apcSlicePilot->getPOC();
1221#endif
1222    }
1223    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
1224    {
1225#if H_MV
1226      if ( xAllRefLayersInitilized() )
1227      {
1228        m_layerInitilizedFlag[ m_layerId ] = true; 
1229        m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1230      }
1231      else 
1232      {
1233        return true; 
1234      }
1235#else
1236      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1237#endif
1238    }
1239    else 
1240    {
1241#if H_MV
1242      static Bool warningMessage[MAX_NUM_LAYERS];
1243      static Bool warningInitFlag = false;
1244     
1245      if (!warningInitFlag)
1246      {
1247        for ( Int i = 0; i < MAX_NUM_LAYERS; i++)
1248        {
1249          warningMessage[i] = true; 
1250        }
1251        warningInitFlag = true; 
1252      }
1253
1254      if ( warningMessage[getLayerId()] )
1255      {
1256        printf("\nLayer%3d   No valid random access point. VCL NAL units of this layer are discarded until next layer initialization picture. ", getLayerId() ); 
1257        warningMessage[m_layerId] = false; 
1258      }
1259#else
1260      static Bool warningMessage = false;
1261      if(!warningMessage)
1262      {
1263        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1264        warningMessage = true;
1265      }
1266#endif
1267      return true;
1268    }
1269  }
1270  // skip the reordered pictures, if necessary
1271  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))
1272  {
1273    iPOCLastDisplay++;
1274    return true;
1275  }
1276#if H_MV
1277  return !m_layerInitilizedFlag[ getLayerId() ]; 
1278#else
1279  // if we reach here, then the picture is not skipped.
1280  return false; 
1281#endif
1282}
1283
1284#if H_MV
1285TComPic* TDecTop::getPic( Int poc )
1286{
1287  xGetPic( m_layerId, poc ); 
1288  TComList<TComPic*>* listPic = getListPic();
1289  TComPic* pcPic = NULL;
1290  for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++)
1291  {
1292    if( (*it)->getPOC() == poc )
1293    {
1294      pcPic = *it ;
1295      break ;
1296    }
1297  }
1298  return pcPic;
1299}
1300
1301TComPic* TDecTop::xGetPic( Int layerId, Int poc )
1302{ 
1303  return m_ivPicLists->getPic( layerId, poc ) ;
1304}
1305
1306Void TDecTop::xResetPocInPicBuffer()
1307{
1308  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
1309  while (iterPic != m_cListPic.end())
1310  {
1311    TComPic* pic = *(iterPic++);
1312    if ( pic->getReconMark() )
1313    {
1314      for( Int i = 0; i < pic->getNumAllocatedSlice(); i++)
1315      {
1316        TComSlice* slice = pic->getSlice( i ); 
1317        slice->setPOC ( slice->getPOC() - m_apcSlicePilot->getPocBeforeReset() );           
1318      }         
1319    }     
1320  }
1321}
1322
1323#if H_MV
1324Void TDecTop::xCeckNoClrasOutput()
1325{
1326  // This part needs further testing!
1327  if ( getLayerId() == 0 )
1328  {   
1329    NalUnitType nut = m_apcSlicePilot->getNalUnitType(); 
1330
1331    Bool isBLA =  ( nut == NAL_UNIT_CODED_SLICE_BLA_W_LP  )  || ( nut == NAL_UNIT_CODED_SLICE_BLA_N_LP ) || ( nut == NAL_UNIT_CODED_SLICE_BLA_W_RADL ); 
1332    Bool isIDR  = ( nut == NAL_UNIT_CODED_SLICE_IDR_W_RADL ) || ( nut == NAL_UNIT_CODED_SLICE_IDR_N_LP ); 
1333    Bool noClrasOutputFlag  = isBLA || ( isIDR  &&  m_apcSlicePilot->getCrossLayerBlaFlag() ); 
1334
1335    if ( noClrasOutputFlag ) 
1336    {
1337      for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++)
1338      {
1339        m_layerInitilizedFlag[i] = false; 
1340      } 
1341    }
1342  }
1343}
1344
1345Bool TDecTop::xAllRefLayersInitilized()
1346{
1347  Bool allRefLayersInitilizedFlag = true; 
1348  TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 ); 
1349  for (Int i = 0; i < vps->getNumDirectRefLayers( getLayerId()  ); i++ )
1350  {
1351#if H_MV_HLS10_REF_PRED_LAYERS
1352    Int refLayerId = vps->getIdDirectRefLayer( m_layerId, i ); 
1353#else
1354    Int refLayerId = vps->getRefLayerId( m_layerId, i ); 
1355#endif
1356    allRefLayersInitilizedFlag = allRefLayersInitilizedFlag && m_layerInitilizedFlag[ refLayerId ]; 
1357  }
1358
1359  return allRefLayersInitilizedFlag;
1360}
1361#endif
1362#endif
1363//! \}
Note: See TracBrowser for help on using the repository browser.