source: 3DVCSoftware/branches/HTM-13.0-MV-draft-2/source/Lib/TLibDecoder/TDecTop.cpp

Last change on this file was 1128, checked in by tech, 10 years ago

Removed 3D-HEVC related code.

  • Property svn:eol-style set to native
File size: 41.4 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  // When the value of vps_num_rep_formats_minus1 in the active VPS is equal to 0
369  if ( vps->getVpsNumRepFormatsMinus1() == 0 )
370  {
371    //, it is a requirement of bitstream conformance that the value of update_rep_format_flag shall be equal to 0.
372    assert( sps->getUpdateRepFormatFlag() == false ); 
373  }
374  sps->checkRpsMaxNumPics( vps, getLayerId() ); 
375
376  if( sps->getLayerId() != 0 )
377  {
378    sps->inferSpsMaxSubLayersMinus1( true, vps ); 
379  }
380
381  // It is a requirement of bitstream conformance that, when the SPS is referred to by
382  // any current picture that belongs to an independent non-base layer, the value of
383  // MultiLayerExtSpsFlag derived from the SPS shall be equal to 0.
384
385  if ( m_layerId > 0 && vps->getNumRefLayers( m_layerId ) == 0 )
386  { 
387    assert( sps->getMultiLayerExtSpsFlag() == 0 ); 
388  }
389
390  if( sps->getMultiLayerExtSpsFlag() )
391  {
392    sps->setTemporalIdNestingFlag( (sps->getMaxTLayers() > 1) ? vps->getTemporalNestingFlag() : true );
393  }
394#endif
395
396  if( pps->getDependentSliceSegmentsEnabledFlag() )
397  {
398    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
399
400    if (m_cSliceDecoder.getCtxMemSize() != NumCtx)
401    {
402      m_cSliceDecoder.initCtxMem(NumCtx);
403      for ( UInt st = 0; st < NumCtx; st++ )
404      {
405        TDecSbac* ctx = NULL;
406        ctx = new TDecSbac;
407        ctx->init( &m_cBinCABAC );
408        m_cSliceDecoder.setCtxMem( ctx, st );
409      }
410    }
411  }
412
413  m_apcSlicePilot->setPPS(pps);
414  m_apcSlicePilot->setSPS(sps);
415#if H_MV
416  m_apcSlicePilot->setVPS(vps); 
417  // 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.
418  assert( pps->getLayerId() == m_layerId || pps->getLayerId( ) == 0 || vps->getDependencyFlag( m_layerId, pps->getLayerId() ) );   
419  // 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.
420  assert( sps->getLayerId() == m_layerId || sps->getLayerId( ) == 0 || vps->getDependencyFlag( m_layerId, sps->getLayerId() ) );
421  sps->inferRepFormat  ( vps , m_layerId ); 
422  sps->inferScalingList( m_parameterSetManagerDecoder.getActiveSPS( sps->getSpsScalingListRefLayerId() ) ); 
423
424#endif
425  pps->setSPS(sps);
426  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumTileColumnsMinus1() + 1) : 1);
427  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
428
429  g_bitDepthY     = sps->getBitDepthY();
430  g_bitDepthC     = sps->getBitDepthC();
431  g_uiMaxCUWidth  = sps->getMaxCUWidth();
432  g_uiMaxCUHeight = sps->getMaxCUHeight();
433  g_uiMaxCUDepth  = sps->getMaxCUDepth();
434  g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() );
435
436  for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++)
437  {
438    sps->setAMPAcc( i, sps->getUseAMP() );
439  }
440
441  for (Int i = sps->getLog2DiffMaxMinCodingBlockSize(); i < sps->getMaxCUDepth(); i++)
442  {
443    sps->setAMPAcc( i, 0 );
444  }
445
446  m_cSAO.destroy();
447  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() );
448  m_cLoopFilter.create( sps->getMaxCUDepth() );
449}
450
451#if H_MV
452Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool newLayerFlag, Bool& sliceSkippedFlag  )
453{
454  assert( nalu.m_layerId == m_layerId ); 
455#else
456Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
457{
458#endif
459  TComPic*&   pcPic         = m_pcPic;
460  m_apcSlicePilot->initSlice();
461
462  if (m_bFirstSliceInPicture)
463  {
464    m_uiSliceIdx     = 0;
465  }
466  else
467  {
468    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
469  }
470  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
471
472  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
473  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
474                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
475                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
476                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
477                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
478  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
479 
480  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
481  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
482
483#if H_MV
484  m_apcSlicePilot->setRefPicSetInterLayer( & m_refPicSetInterLayer0, &m_refPicSetInterLayer1 ); 
485  m_apcSlicePilot->setLayerId( nalu.m_layerId );
486  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder, m_targetOptLayerSetIdx );
487#else
488  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
489#endif
490  // set POC for dependent slices in skipped pictures
491  if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped) 
492  {
493    m_apcSlicePilot->setPOC(m_skippedPOC);
494  }
495
496  m_apcSlicePilot->setAssociatedIRAPPOC(m_pocCRA);
497  m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType);
498
499#if H_MV 
500  TComVPS* vps     = m_apcSlicePilot->getVPS();
501  Int layerId  = nalu.m_layerId;   
502  setViewId   ( vps->getViewId   ( layerId )      ); 
503#endif
504
505#if SETTING_NO_OUT_PIC_PRIOR
506  //For inference of NoOutputOfPriorPicsFlag
507  if (m_apcSlicePilot->getRapPicFlag())
508  {
509    if ((m_apcSlicePilot->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_apcSlicePilot->getNalUnitType() <= NAL_UNIT_CODED_SLICE_IDR_N_LP) || 
510        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_bFirstSliceInSequence) ||
511        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getHandleCraAsBlaFlag()))
512    {
513      m_apcSlicePilot->setNoRaslOutputFlag(true);
514    }
515    //the inference for NoOutputPriorPicsFlag
516    if (!m_bFirstSliceInBitstream && m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag())
517    {
518      if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
519      {
520        m_apcSlicePilot->setNoOutputPriorPicsFlag(true);
521      }
522    }
523    else
524    {
525      m_apcSlicePilot->setNoOutputPriorPicsFlag(false);
526    }
527
528    if(m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
529    {
530      m_craNoRaslOutputFlag = m_apcSlicePilot->getNoRaslOutputFlag();
531    }
532  }
533  if (m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoOutputPriorPicsFlag())
534  {
535    m_lastPOCNoOutputPriorPics = m_apcSlicePilot->getPOC();
536    m_isNoOutputPriorPics = true;
537  }
538  else
539  {
540    m_isNoOutputPriorPics = false;
541  }
542
543  //For inference of PicOutputFlag
544  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R)
545  {
546    if ( m_craNoRaslOutputFlag )
547    {
548      m_apcSlicePilot->setPicOutputFlag(false);
549    }
550  }
551#endif
552
553#if FIX_POC_CRA_NORASL_OUTPUT
554  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_craNoRaslOutputFlag) //Reset POC MSB when CRA has NoRaslOutputFlag equal to 1
555  {
556    Int iMaxPOClsb = 1 << m_apcSlicePilot->getSPS()->getBitsForPOC();
557    m_apcSlicePilot->setPOC( m_apcSlicePilot->getPOC() & (iMaxPOClsb - 1) );
558  }
559#endif
560#if H_MV
561    xCeckNoClrasOutput();
562#endif
563    // Skip pictures due to random access
564    if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
565    {
566    m_prevSliceSkipped = true;
567    m_skippedPOC = m_apcSlicePilot->getPOC();
568#if H_MV
569    sliceSkippedFlag = true; 
570#endif
571      return false;
572    }
573    // Skip TFD pictures associated with BLA/BLANT pictures
574    if (isSkipPictureForBLA(iPOCLastDisplay))
575    {
576    m_prevSliceSkipped = true;
577    m_skippedPOC = m_apcSlicePilot->getPOC();
578#if H_MV
579    sliceSkippedFlag = true; 
580#endif
581      return false;
582    }
583
584  // clear previous slice skipped flag
585  m_prevSliceSkipped = false;
586
587  //we should only get a different poc for a new picture (with CTU address==0)
588  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (m_apcSlicePilot->getSliceCurStartCUAddr()!=0))
589  {
590    printf ("Warning, the first slice of a picture might have been lost!\n");
591  }
592  // exit when a new picture is found
593  if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence )
594  {
595    if (m_prevPOC >= m_pocRandomAccess)
596    {
597      m_prevPOC = m_apcSlicePilot->getPOC();
598      return true;
599    }
600    m_prevPOC = m_apcSlicePilot->getPOC();
601  }
602#if H_MV
603  if ( newLayerFlag )
604  {
605    return false; 
606  }
607#if ENC_DEC_TRACE
608#if H_MV_ENC_DEC_TRAC
609  // parse remainder of SH
610   g_disableHLSTrace = false; 
611#endif
612#endif
613#endif
614  // actual decoding starts here
615#if H_MV
616   // This part needs further testing !
617   if ( m_apcSlicePilot->getPocResetFlag() )
618   {   
619     xResetPocInPicBuffer();
620   }
621
622   if ( m_apcSlicePilot->getTLayer() == 0 && m_apcSlicePilot->getEnableTMVPFlag() == 0 )
623  {
624    //update all pics in the DPB such that they cannot be used for TMPV ref
625    TComList<TComPic*>::iterator  iterRefPic = m_cListPic.begin(); 
626    while( iterRefPic != m_cListPic.end() )
627    {
628      TComPic *refPic = *iterRefPic;
629      if( ( refPic->getLayerId() == m_apcSlicePilot->getLayerId() ) && refPic->getReconMark() )
630      {
631        for(Int i = refPic->getNumAllocatedSlice()-1; i >= 0; i--)
632        {
633
634          TComSlice *refSlice = refPic->getSlice(i);
635          refSlice->setAvailableForTMVPRefFlag( false );
636        }
637      }
638      iterRefPic++;
639    }
640  }
641  m_apcSlicePilot->setAvailableForTMVPRefFlag( true );
642#endif
643
644  xActivateParameterSets();
645
646  if (m_apcSlicePilot->isNextSlice()) 
647  {
648    m_prevPOC = m_apcSlicePilot->getPOC();
649  }
650  m_bFirstSliceInSequence = false;
651#if SETTING_NO_OUT_PIC_PRIOR 
652  m_bFirstSliceInBitstream  = false;
653#endif
654  //detect lost reference picture and insert copy of earlier frame.
655  Int lostPoc;
656  while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
657  {
658    xCreateLostPicture(lostPoc-1);
659  }
660  if (m_bFirstSliceInPicture)
661  {
662    // Buffer initialize for prediction.
663    m_cPrediction.initTempBuff();
664    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
665#if H_MV
666    m_apcSlicePilot->createInterLayerReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
667#endif
668    //  Get a new picture buffer
669    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
670
671    Bool isField = false;
672    Bool isTff = false;
673   
674    if(!m_SEIs.empty())
675    {
676      // Check if any new Picture Timing SEI has arrived
677      SEIMessages pictureTimingSEIs = extractSeisByType (m_SEIs, SEI::PICTURE_TIMING);
678      if (pictureTimingSEIs.size()>0)
679      {
680        SEIPictureTiming* pictureTiming = (SEIPictureTiming*) *(pictureTimingSEIs.begin());
681        isField = (pictureTiming->m_picStruct == 1) || (pictureTiming->m_picStruct == 2);
682        isTff =  (pictureTiming->m_picStruct == 1);
683      }
684    }
685   
686    //Set Field/Frame coding mode
687    m_pcPic->setField(isField);
688    m_pcPic->setTopField(isTff);
689   
690    // transfer any SEI messages that have been received to the picture
691    pcPic->setSEIs(m_SEIs);
692    m_SEIs.clear();
693
694    // Recursive structure
695    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
696    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
697    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
698
699    m_cSliceDecoder.create();
700  }
701  else
702  {
703    // Check if any new SEI has arrived
704    if(!m_SEIs.empty())
705    {
706      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
707      SEIMessages &picSEI = pcPic->getSEIs();
708      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
709      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
710      deleteSEIs(m_SEIs);
711    }
712  }
713 
714  //  Set picture slice pointer
715  TComSlice*  pcSlice = m_apcSlicePilot;
716  Bool bNextSlice     = pcSlice->isNextSlice();
717
718  UInt i;
719  pcPic->getPicSym()->initTiles(pcSlice->getPPS());
720
721  //generate the Coding Order Map and Inverse Coding Order Map
722  UInt uiEncCUAddr;
723  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
724  {
725    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
726    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
727  }
728  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
729  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
730
731  //convert the start and end CU addresses of the slice and dependent slice into encoding order
732  pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) );
733  pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) );
734  if(pcSlice->isNextSlice())
735  {
736    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
737    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
738  }
739
740  if (m_bFirstSliceInPicture) 
741  {
742    if(pcPic->getNumAllocatedSlice() != 1)
743    {
744      pcPic->clearSliceBuffer();
745    }
746  }
747  else
748  {
749    pcPic->allocateNewSlice();
750  }
751  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
752  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
753  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
754
755  pcPic->setTLayer(nalu.m_temporalId);
756
757#if H_MV
758  pcPic->setLayerId( nalu.m_layerId );
759  pcPic->setViewId ( getViewId() );
760#endif
761  if (bNextSlice)
762  {
763    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_associatedIRAPType, m_cListPic );
764    // Set reference list
765#if H_MV   
766    std::vector< TComPic* > tempRefPicLists[2];
767    std::vector< Bool     > usedAsLongTerm [2];
768    Int       numPocTotalCurr;
769
770    pcSlice->getTempRefPicLists( m_cListPic, m_refPicSetInterLayer0, m_refPicSetInterLayer1, tempRefPicLists, usedAsLongTerm, numPocTotalCurr);
771    pcSlice->setRefPicList     ( tempRefPicLists, usedAsLongTerm, numPocTotalCurr, true ); 
772
773
774#else
775    pcSlice->setRefPicList( m_cListPic, true );
776#endif
777
778#if H_MV
779    if( m_layerId > 0 && !pcSlice->isIntra() && pcSlice->getEnableTMVPFlag() )
780    {
781      TComPic* refPic = pcSlice->getRefPic(RefPicList(1 - pcSlice->getColFromL0Flag()), pcSlice->getColRefIdx());
782
783      assert ( refPic );
784      assert ( refPic->getPicSym()->getSlice(0)->getAvailableForTMVPRefFlag() == true );
785    }
786#endif
787
788    // For generalized B
789    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
790    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
791    {
792      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
793      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
794
795      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
796      {
797        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
798      }
799    }
800    if (!pcSlice->isIntra())
801    {
802      Bool bLowDelay = true;
803      Int  iCurrPOC  = pcSlice->getPOC();
804      Int iRefIdx = 0;
805
806      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
807      {
808        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
809        {
810          bLowDelay = false;
811        }
812      }
813      if (pcSlice->isInterB())
814      {
815        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
816        {
817          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
818          {
819            bLowDelay = false;
820          }
821        }       
822      }
823
824      pcSlice->setCheckLDC(bLowDelay);           
825    }
826
827    //---------------
828    pcSlice->setRefPOCList();
829  }
830
831  pcPic->setCurrSliceIdx(m_uiSliceIdx);
832  if(pcSlice->getSPS()->getScalingListFlag())
833  {
834    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
835    if(pcSlice->getPPS()->getScalingListPresentFlag())
836    {
837      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
838    }
839    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
840    {
841      pcSlice->setDefaultScalingList();
842    }
843    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
844    m_cTrQuant.setUseScalingList(true);
845  }
846  else
847  {
848    m_cTrQuant.setFlatScalingList();
849    m_cTrQuant.setUseScalingList(false);
850  }
851
852
853  //  Decode a picture
854  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
855  m_bFirstSliceInPicture = false;
856  m_uiSliceIdx++;
857
858  return false;
859}
860
861Void TDecTop::xDecodeVPS()
862{
863  TComVPS* vps = new TComVPS();
864 
865  m_cEntropyDecoder.decodeVPS( vps );
866  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
867}
868
869Void TDecTop::xDecodeSPS()
870{
871  TComSPS* sps = new TComSPS();
872#if H_MV
873  sps->setLayerId( getLayerId() ); 
874#endif
875  m_cEntropyDecoder.decodeSPS( sps );
876  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
877}
878
879Void TDecTop::xDecodePPS()
880{
881  TComPPS* pps = new TComPPS();
882#if H_MV
883  pps->setLayerId( getLayerId() ); 
884#endif
885  m_cEntropyDecoder.decodePPS( pps );
886  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
887}
888
889Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
890{
891  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
892  {
893#if H_MV
894    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS( m_layerId ) );
895#else
896    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
897#endif
898  }
899  else
900  {
901#if H_MV
902    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS( m_layerId ) );
903#else
904    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
905#endif
906    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
907    if (activeParamSets.size()>0)
908    {
909      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
910      m_parameterSetManagerDecoder.applyPrefetchedPS();
911      assert(seiAps->activeSeqParameterSetId.size()>0);
912#if H_MV
913      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParameterSetId[0], m_layerId ))
914#else
915      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParameterSetId[0] ))
916#endif
917      {
918        printf ("Warning SPS activation with Active parameter set SEI failed");
919      }
920    }
921  }
922}
923
924#if H_MV
925Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayerFlag, Bool& sliceSkippedFlag )
926#else
927Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
928#endif
929{
930  // Initialize entropy decoder
931  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
932  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
933
934  switch (nalu.m_nalUnitType)
935  {
936    case NAL_UNIT_VPS:
937      xDecodeVPS();
938#if H_MV
939      m_isLastNALWasEos = false;
940#endif
941      return false;
942     
943    case NAL_UNIT_SPS:
944      xDecodeSPS();
945      return false;
946
947    case NAL_UNIT_PPS:
948      xDecodePPS();
949      return false;
950     
951    case NAL_UNIT_PREFIX_SEI:
952    case NAL_UNIT_SUFFIX_SEI:
953#if H_MV
954      if ( nalu.m_nalUnitType == NAL_UNIT_SUFFIX_SEI )
955      {
956        assert( m_isLastNALWasEos == false );
957      }
958#endif
959      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
960      return false;
961
962    case NAL_UNIT_CODED_SLICE_TRAIL_R:
963    case NAL_UNIT_CODED_SLICE_TRAIL_N:
964    case NAL_UNIT_CODED_SLICE_TSA_R:
965    case NAL_UNIT_CODED_SLICE_TSA_N:
966    case NAL_UNIT_CODED_SLICE_STSA_R:
967    case NAL_UNIT_CODED_SLICE_STSA_N:
968    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
969    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
970    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
971    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
972    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
973    case NAL_UNIT_CODED_SLICE_CRA:
974    case NAL_UNIT_CODED_SLICE_RADL_N:
975    case NAL_UNIT_CODED_SLICE_RADL_R:
976    case NAL_UNIT_CODED_SLICE_RASL_N:
977    case NAL_UNIT_CODED_SLICE_RASL_R:
978#if H_MV
979      if (nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_N ||
980          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_N ||
981          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_N ||
982          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
983          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N )
984      {
985        assert( m_isLastNALWasEos == false );
986      }
987      else
988      {
989        m_isLastNALWasEos = false;
990      }
991
992      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, newLayerFlag, sliceSkippedFlag );
993#else
994      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
995#endif
996      break;
997    case NAL_UNIT_EOS:
998#if H_MV
999      assert( m_isLastNALWasEos == false );
1000      //Check layer id of the nalu. if it is not 0, give a warning message and just return without doing anything.
1001      if (nalu.m_layerId > 0)
1002      {
1003        printf( "\nThis bitstream has EOS with non-zero layer id.\n" );
1004        return false;
1005      }
1006      m_isLastNALWasEos = true;
1007#endif
1008      m_associatedIRAPType = NAL_UNIT_INVALID;
1009      m_pocCRA = 0;
1010      m_pocRandomAccess = MAX_INT;
1011      m_prevPOC = MAX_INT;
1012      m_bFirstSliceInPicture = true;
1013      m_bFirstSliceInSequence = true;
1014      m_prevSliceSkipped = false;
1015      m_skippedPOC = 0;
1016      return false;
1017     
1018    case NAL_UNIT_ACCESS_UNIT_DELIMITER:
1019      // TODO: process AU delimiter
1020      return false;
1021     
1022    case NAL_UNIT_EOB:
1023      return false;
1024     
1025    case NAL_UNIT_FILLER_DATA:
1026#if H_MV
1027      assert( m_isLastNALWasEos == false );
1028#endif
1029      return false;
1030     
1031    case NAL_UNIT_RESERVED_VCL_N10:
1032    case NAL_UNIT_RESERVED_VCL_R11:
1033    case NAL_UNIT_RESERVED_VCL_N12:
1034    case NAL_UNIT_RESERVED_VCL_R13:
1035    case NAL_UNIT_RESERVED_VCL_N14:
1036    case NAL_UNIT_RESERVED_VCL_R15:
1037     
1038    case NAL_UNIT_RESERVED_IRAP_VCL22:
1039    case NAL_UNIT_RESERVED_IRAP_VCL23:
1040     
1041    case NAL_UNIT_RESERVED_VCL24:
1042    case NAL_UNIT_RESERVED_VCL25:
1043    case NAL_UNIT_RESERVED_VCL26:
1044    case NAL_UNIT_RESERVED_VCL27:
1045    case NAL_UNIT_RESERVED_VCL28:
1046    case NAL_UNIT_RESERVED_VCL29:
1047    case NAL_UNIT_RESERVED_VCL30:
1048    case NAL_UNIT_RESERVED_VCL31:
1049     
1050    case NAL_UNIT_RESERVED_NVCL41:
1051    case NAL_UNIT_RESERVED_NVCL42:
1052    case NAL_UNIT_RESERVED_NVCL43:
1053    case NAL_UNIT_RESERVED_NVCL44:
1054    case NAL_UNIT_RESERVED_NVCL45:
1055    case NAL_UNIT_RESERVED_NVCL46:
1056    case NAL_UNIT_RESERVED_NVCL47:
1057    case NAL_UNIT_UNSPECIFIED_48:
1058    case NAL_UNIT_UNSPECIFIED_49:
1059    case NAL_UNIT_UNSPECIFIED_50:
1060    case NAL_UNIT_UNSPECIFIED_51:
1061    case NAL_UNIT_UNSPECIFIED_52:
1062    case NAL_UNIT_UNSPECIFIED_53:
1063    case NAL_UNIT_UNSPECIFIED_54:
1064    case NAL_UNIT_UNSPECIFIED_55:
1065    case NAL_UNIT_UNSPECIFIED_56:
1066    case NAL_UNIT_UNSPECIFIED_57:
1067    case NAL_UNIT_UNSPECIFIED_58:
1068    case NAL_UNIT_UNSPECIFIED_59:
1069    case NAL_UNIT_UNSPECIFIED_60:
1070    case NAL_UNIT_UNSPECIFIED_61:
1071    case NAL_UNIT_UNSPECIFIED_62:
1072    case NAL_UNIT_UNSPECIFIED_63:
1073    default:
1074      assert (0);
1075  }
1076
1077  return false;
1078}
1079
1080/** Function for checking if picture should be skipped because of association with a previous BLA picture
1081 * \param iPOCLastDisplay POC of last picture displayed
1082 * \returns true if the picture should be skipped
1083 * This function skips all TFD pictures that follow a BLA picture
1084 * in decoding order and precede it in output order.
1085 */
1086Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
1087{
1088  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) && 
1089       m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
1090  {
1091    iPOCLastDisplay++;
1092    return true;
1093  }
1094  return false;
1095}
1096
1097/** Function for checking if picture should be skipped because of random access
1098 * \param iSkipFrame skip frame counter
1099 * \param iPOCLastDisplay POC of last picture displayed
1100 * \returns true if the picture shold be skipped in the random access.
1101 * This function checks the skipping of pictures in the case of -s option random access.
1102 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1103 * It also checks the type of Nal unit type at the random access point.
1104 * 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.
1105 * If the random access point is IDR all pictures after the random access point are decoded.
1106 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
1107 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
1108 * access point there is no guarantee that the decoder will not crash.
1109 */
1110Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
1111{
1112  if (iSkipFrame) 
1113  {
1114    iSkipFrame--;   // decrement the counter
1115    return true;
1116  }
1117#if H_MV
1118  else if ( !m_layerInitilizedFlag[ m_layerId ] ) // start of random access point, m_pocRandomAccess has not been set yet.
1119#else
1120  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1121#endif
1122  {
1123    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
1124        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1125        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1126        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
1127    {
1128
1129#if H_MV
1130      if ( xAllRefLayersInitilized() )
1131      {
1132        m_layerInitilizedFlag[ m_layerId ] = true; 
1133        m_pocRandomAccess = m_apcSlicePilot->getPOC();
1134      }
1135      else
1136      {
1137        return true; 
1138      }
1139#else
1140      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
1141      m_pocRandomAccess = m_apcSlicePilot->getPOC();
1142#endif
1143    }
1144    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
1145    {
1146#if H_MV
1147      if ( xAllRefLayersInitilized() )
1148      {
1149        m_layerInitilizedFlag[ m_layerId ] = true; 
1150        m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1151      }
1152      else 
1153      {
1154        return true; 
1155      }
1156#else
1157      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1158#endif
1159    }
1160    else 
1161    {
1162#if H_MV
1163      static Bool warningMessage[MAX_NUM_LAYERS];
1164      static Bool warningInitFlag = false;
1165     
1166      if (!warningInitFlag)
1167      {
1168        for ( Int i = 0; i < MAX_NUM_LAYERS; i++)
1169        {
1170          warningMessage[i] = true; 
1171        }
1172        warningInitFlag = true; 
1173      }
1174
1175      if ( warningMessage[getLayerId()] )
1176      {
1177        printf("\nLayer%3d   No valid random access point. VCL NAL units of this layer are discarded until next layer initialization picture. ", getLayerId() ); 
1178        warningMessage[m_layerId] = false; 
1179      }
1180#else
1181      static Bool warningMessage = false;
1182      if(!warningMessage)
1183      {
1184        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1185        warningMessage = true;
1186      }
1187#endif
1188      return true;
1189    }
1190  }
1191  // skip the reordered pictures, if necessary
1192  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))
1193  {
1194    iPOCLastDisplay++;
1195    return true;
1196  }
1197#if H_MV
1198  return !m_layerInitilizedFlag[ getLayerId() ]; 
1199#else
1200  // if we reach here, then the picture is not skipped.
1201  return false; 
1202#endif
1203}
1204
1205#if H_MV
1206TComPic* TDecTop::getPic( Int poc )
1207{
1208  xGetPic( m_layerId, poc ); 
1209  TComList<TComPic*>* listPic = getListPic();
1210  TComPic* pcPic = NULL;
1211  for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++)
1212  {
1213    if( (*it)->getPOC() == poc )
1214    {
1215      pcPic = *it ;
1216      break ;
1217    }
1218  }
1219  return pcPic;
1220}
1221
1222TComPic* TDecTop::xGetPic( Int layerId, Int poc )
1223{ 
1224  return m_ivPicLists->getPic( layerId, poc ) ;
1225}
1226
1227Void TDecTop::xResetPocInPicBuffer()
1228{
1229  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
1230  while (iterPic != m_cListPic.end())
1231  {
1232    TComPic* pic = *(iterPic++);
1233    if ( pic->getReconMark() )
1234    {
1235      for( Int i = 0; i < pic->getNumAllocatedSlice(); i++)
1236      {
1237        TComSlice* slice = pic->getSlice( i ); 
1238        slice->setPOC ( slice->getPOC() - m_apcSlicePilot->getPocBeforeReset() );           
1239      }         
1240    }     
1241  }
1242}
1243
1244#if H_MV
1245Void TDecTop::xCeckNoClrasOutput()
1246{
1247  // This part needs further testing!
1248  if ( getLayerId() == 0 )
1249  {   
1250    NalUnitType nut = m_apcSlicePilot->getNalUnitType(); 
1251
1252    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 ); 
1253    Bool isIDR  = ( nut == NAL_UNIT_CODED_SLICE_IDR_W_RADL ) || ( nut == NAL_UNIT_CODED_SLICE_IDR_N_LP ); 
1254    Bool noClrasOutputFlag  = isBLA || ( isIDR  &&  m_apcSlicePilot->getCrossLayerBlaFlag() ); 
1255
1256    if ( noClrasOutputFlag ) 
1257    {
1258      for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++)
1259      {
1260        m_layerInitilizedFlag[i] = false; 
1261      } 
1262    }
1263  }
1264}
1265
1266Bool TDecTop::xAllRefLayersInitilized()
1267{
1268  Bool allRefLayersInitilizedFlag = true; 
1269  TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 ); 
1270  for (Int i = 0; i < vps->getNumDirectRefLayers( getLayerId()  ); i++ )
1271  {
1272    Int refLayerId = vps->getIdDirectRefLayer( m_layerId, i ); 
1273    allRefLayersInitilizedFlag = allRefLayersInitilizedFlag && m_layerInitilizedFlag[ refLayerId ]; 
1274  }
1275
1276  return allRefLayersInitilizedFlag;
1277}
1278#endif
1279#endif
1280//! \}
Note: See TracBrowser for help on using the repository browser.