source: SHVCSoftware/branches/HM-10.0-dev-SHM/source/Lib/TLibDecoder/TDecTop.cpp @ 59

Last change on this file since 59 was 58, checked in by seregin, 12 years ago

porting AVC support

File size: 36.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-2013, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TDecTop.cpp
35    \brief    decoder class
36*/
37
38#include "NALread.h"
39#include "TDecTop.h"
40
41#if SVC_EXTENSION
42ParameterSetManagerDecoder TDecTop::m_parameterSetManagerDecoder;  // storage for parameter sets
43UInt  TDecTop::m_prevPOC = MAX_UINT;
44UInt  TDecTop::m_uiPrevLayerId = MAX_UINT;
45Bool  TDecTop::m_bFirstSliceInSequence = true;
46#endif
47
48//! \ingroup TLibDecoder
49//! \{
50
51TDecTop::TDecTop()
52{
53  m_pcPic = 0;
54  m_iMaxRefPicNum = 0;
55#if ENC_DEC_TRACE
56  g_hTrace = fopen( "TraceDec.txt", "wb" );
57  g_bJustDoIt = g_bEncDecTraceDisable;
58  g_nSymbolCounter = 0;
59#endif
60  m_pocCRA = 0;
61  m_prevRAPisBLA = false;
62  m_pocRandomAccess = MAX_INT;         
63#if !SVC_EXTENSION
64  m_prevPOC                = MAX_INT;
65#endif
66  m_bFirstSliceInPicture    = true;
67#if !SVC_EXTENSION
68  m_bFirstSliceInSequence   = true;
69#endif
70#if SVC_EXTENSION
71  m_layerId = 0;
72#if AVC_BASE
73  m_pBLReconFile = NULL;
74#endif
75#endif
76#if REF_IDX_FRAMEWORK
77  memset(m_cIlpPic, 0, sizeof(m_cIlpPic));
78#endif
79#if AVC_SYNTAX || SYNTAX_OUTPUT
80  m_pBLSyntaxFile = NULL;
81#endif
82
83}
84
85TDecTop::~TDecTop()
86{
87#if ENC_DEC_TRACE
88  fclose( g_hTrace );
89#endif
90}
91
92Void TDecTop::create()
93{
94#if SVC_EXTENSION
95  m_cGopDecoder.create( m_layerId );
96#else
97  m_cGopDecoder.create();
98#endif
99  m_apcSlicePilot = new TComSlice;
100  m_uiSliceIdx = 0;
101}
102
103Void TDecTop::destroy()
104{
105  m_cGopDecoder.destroy();
106 
107  delete m_apcSlicePilot;
108  m_apcSlicePilot = NULL;
109 
110  m_cSliceDecoder.destroy();
111#if REF_IDX_FRAMEWORK
112  for(Int i=0; i<MAX_NUM_REF; i++)
113  {
114    if(m_cIlpPic[i])
115    {
116      //m_cIlpPic[i]->setPicYuvRec(NULL);
117      m_cIlpPic[i]->destroy();
118      delete m_cIlpPic[i];
119      m_cIlpPic[i] = NULL;
120    }
121  }   
122#endif
123}
124
125Void TDecTop::init()
126{
127#if !SVC_EXTENSION
128  // initialize ROM
129  initROM();
130#endif
131#if SVC_EXTENSION
132  m_cGopDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
133  m_cSliceDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cCuDecoder );
134#else
135  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
136  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
137#endif
138  m_cEntropyDecoder.init(&m_cPrediction);
139}
140
141#if REF_IDX_FRAMEWORK
142Void TDecTop::xInitILRP(TComSPS *pcSPS)
143{
144  if(m_layerId>0)
145  {
146    Int  numReorderPics[MAX_TLAYER];
147    Window &conformanceWindow = pcSPS->getConformanceWindow();
148    Window defaultDisplayWindow = pcSPS->getVuiParametersPresentFlag() ? pcSPS->getVuiParameters()->getDefaultDisplayWindow() : Window();
149
150    if (m_cIlpPic[0] == NULL)
151    {
152      for (Int j=0; j<1/*MAX_NUM_REF*/; j++)
153      {
154        m_cIlpPic[j] = new  TComPic;
155        //m_cIlpPic[j]->createWithOutYuv(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, &m_cSPS, true);
156#if SVC_UPSAMPLING
157        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
158#else
159        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
160#endif
161#if REF_IDX_ME_AROUND_ZEROMV || REF_IDX_ME_ZEROMV || REF_IDX_MFM
162        m_cIlpPic[j]->setIsILR(true);
163#endif
164        for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++)
165        {
166          m_cIlpPic[j]->getPicSym()->getCU(i)->initCU(m_cIlpPic[j], i);
167        }
168      }
169    }
170  }
171}
172
173Void TDecTop::setILRPic(TComPic *pcPic)
174{
175  if(m_cIlpPic[0])
176  {
177    //m_cIlpPic[0]->setPicYuvRec(pcPic->getFullPelBaseRec());
178    m_cIlpPic[0]->copyUpsampledPictureYuv(pcPic->getFullPelBaseRec(), m_cIlpPic[0]->getPicYuvRec());
179    m_cIlpPic[0]->getSlice(0)->setPOC(pcPic->getPOC());
180    m_cIlpPic[0]->getPicYuvRec()->setBorderExtension(false);
181    m_cIlpPic[0]->getPicYuvRec()->extendPicBorder();
182  }
183}
184#endif
185
186Void TDecTop::deletePicBuffer ( )
187{
188  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
189  Int iSize = Int( m_cListPic.size() );
190 
191  for (Int i = 0; i < iSize; i++ )
192  {
193    TComPic* pcPic = *(iterPic++);
194#if SVC_EXTENSION
195    if( pcPic )
196    {
197      pcPic->destroy();
198
199      delete pcPic;
200      pcPic = NULL;
201    }
202#else
203    pcPic->destroy();
204   
205    delete pcPic;
206    pcPic = NULL;
207#endif
208  }
209 
210  m_cSAO.destroy();
211 
212  m_cLoopFilter.        destroy();
213 
214#if !SVC_EXTENSION
215  // destroy ROM
216  destroyROM();
217#endif
218}
219
220Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
221{
222  Int  numReorderPics[MAX_TLAYER];
223  Window &conformanceWindow = pcSlice->getSPS()->getConformanceWindow();
224  Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window();
225
226  for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
227  {
228    numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer);
229  }
230
231  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer())+pcSlice->getSPS()->getNumReorderPics(pcSlice->getTLayer()) + 1; // +1 to have space for the picture currently being decoded
232  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
233  {
234    rpcPic = new TComPic();
235
236#if SVC_EXTENSION //Temporal solution, should be modified
237    if(m_layerId > 0)
238    {
239      TDecTop *pcTDecTopBase = (TDecTop *)getLayerDec( m_layerId-1 );
240      //TComPic*                      pcPic = *(pcTDecTopBase->getListPic()->begin());
241      TComPicYuv* pcPicYuvRecBase = (*(pcTDecTopBase->getListPic()->begin()))->getPicYuvRec(); 
242      if(pcPicYuvRecBase->getWidth() != pcSlice->getSPS()->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getSPS()->getPicHeightInLumaSamples() )
243      {
244        rpcPic->setSpatialEnhLayerFlag( true );
245      }
246    }
247#endif
248   
249#if SVC_UPSAMPLING
250    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
251                     conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
252#else
253    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
254                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
255#endif
256    rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
257    m_cListPic.pushBack( rpcPic );
258   
259    return;
260  }
261 
262  Bool bBufferIsAvailable = false;
263  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
264  while (iterPic != m_cListPic.end())
265  {
266    rpcPic = *(iterPic++);
267    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
268    {
269      rpcPic->setOutputMark(false);
270      bBufferIsAvailable = true;
271      break;
272    }
273
274    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
275    {
276#if !SVC_EXTENSION
277      rpcPic->setOutputMark(false);
278#endif
279      rpcPic->setReconMark( false );
280      rpcPic->getPicYuvRec()->setBorderExtension( false );
281      bBufferIsAvailable = true;
282      break;
283    }
284  }
285 
286  if ( !bBufferIsAvailable )
287  {
288    //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer.
289    m_iMaxRefPicNum++;
290    rpcPic = new TComPic();
291    m_cListPic.pushBack( rpcPic );
292  }
293  rpcPic->destroy();
294
295#if SVC_UPSAMPLING
296  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
297                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
298
299#else
300  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
301                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
302#endif
303  rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
304}
305
306Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic)
307{
308  if (!m_pcPic)
309  {
310    /* nothing to deblock */
311    return;
312  }
313 
314  TComPic*&   pcPic         = m_pcPic;
315
316  // Execute Deblock + Cleanup
317
318  m_cGopDecoder.filterPicture(pcPic);
319
320#if SYNTAX_OUTPUT
321  pcPic->wrireBLSyntax( getBLSyntaxFile(), SYNTAX_BYTES );
322#endif
323  TComSlice::sortPicList( m_cListPic ); // sorting for application output
324  poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
325  rpcListPic          = &m_cListPic; 
326  m_cCuDecoder.destroy();       
327  m_bFirstSliceInPicture  = true;
328
329  return;
330}
331
332Void TDecTop::xCreateLostPicture(Int iLostPoc) 
333{
334  printf("\ninserting lost poc : %d\n",iLostPoc);
335  TComSlice cFillSlice;
336  cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
337  cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
338#if SET_SLICE_LAYER_ID
339  cFillSlice.initSlice( m_parameterSetManagerDecoder.getFirstSPS()->getLayerId() );
340#else
341  cFillSlice.initSlice();
342#endif
343  TComPic *cFillPic;
344  xGetNewPicBuffer(&cFillSlice,cFillPic);
345  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
346  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
347#if SET_SLICE_LAYER_ID
348  cFillPic->getSlice(0)->initSlice( cFillPic->getLayerId() );
349#else
350  cFillPic->getSlice(0)->initSlice();
351#endif
352 
353  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
354  Int closestPoc = 1000000;
355  while ( iterPic != m_cListPic.end())
356  {
357    TComPic * rpcPic = *(iterPic++);
358    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())
359    {
360      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
361    }
362  }
363  iterPic = m_cListPic.begin();
364  while ( iterPic != m_cListPic.end())
365  {
366    TComPic *rpcPic = *(iterPic++);
367    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
368    {
369      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
370      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
371      break;
372    }
373  }
374  cFillPic->setCurrSliceIdx(0);
375  for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) 
376  {
377    cFillPic->getCU(i)->initCU(cFillPic,i);
378  }
379  cFillPic->getSlice(0)->setReferenced(true);
380  cFillPic->getSlice(0)->setPOC(iLostPoc);
381  cFillPic->setReconMark(true);
382  cFillPic->setOutputMark(true);
383  if(m_pocRandomAccess == MAX_INT)
384  {
385    m_pocRandomAccess = iLostPoc;
386  }
387}
388
389
390Void TDecTop::xActivateParameterSets()
391{
392  m_parameterSetManagerDecoder.applyPrefetchedPS();
393 
394  TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
395  assert (pps != 0);
396
397  TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId());
398  assert (sps != 0);
399
400#if SVC_EXTENSION
401  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(), m_apcSlicePilot->getIdrPicFlag(), m_apcSlicePilot->getLayerId() ))
402#else
403  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->getIdrPicFlag()))
404#endif
405  {
406    printf ("Parameter set activation failed!");
407    assert (0);
408  }
409
410  m_apcSlicePilot->setPPS(pps);
411  m_apcSlicePilot->setSPS(sps);
412  pps->setSPS(sps);
413  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
414  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
415
416  for (Int i = 0; i < sps->getMaxCUDepth() - g_uiAddCUDepth; i++)
417  {
418    sps->setAMPAcc( i, sps->getUseAMP() );
419  }
420
421  for (Int i = sps->getMaxCUDepth() - g_uiAddCUDepth; i < sps->getMaxCUDepth(); i++)
422  {
423    sps->setAMPAcc( i, 0 );
424  }
425
426  m_cSAO.destroy();
427  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight );
428  m_cLoopFilter.        create( g_uiMaxCUDepth );
429}
430
431#if SVC_EXTENSION
432Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC )
433#else
434Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
435#endif
436{
437  TComPic*&   pcPic         = m_pcPic;
438#if SET_SLICE_LAYER_ID
439  m_apcSlicePilot->initSlice( nalu.m_layerId );
440#else
441  m_apcSlicePilot->initSlice();
442#endif
443
444  if (m_bFirstSliceInPicture)
445  {
446    m_uiSliceIdx     = 0;
447  }
448  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
449  if (!m_bFirstSliceInPicture)
450  {
451    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
452  }
453
454  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
455  if((m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N) ||
456     (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N) ||
457     (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N))
458  {
459    m_apcSlicePilot->setTemporalLayerNonReferenceFlag(true);
460  }
461  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
462  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
463
464  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
465  if (m_apcSlicePilot->isNextSlice())
466  {
467    // Skip pictures due to random access
468    if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
469    {
470      return false;
471    }
472    // Skip TFD pictures associated with BLA/BLANT pictures
473    if (isSkipPictureForBLA(iPOCLastDisplay))
474    {
475      return false;
476    }
477  } 
478
479  // exit when a new picture is found
480#if SVC_EXTENSION
481  bNewPOC = (m_apcSlicePilot->getPOC()!= m_prevPOC);
482  if (m_apcSlicePilot->isNextSlice() && (bNewPOC || m_layerId!=m_uiPrevLayerId) && !m_bFirstSliceInSequence )
483  {
484    m_prevPOC = m_apcSlicePilot->getPOC();
485    curLayerId = m_uiPrevLayerId; 
486    m_uiPrevLayerId = m_layerId;
487    return true;
488  }
489#else
490  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence)
491  {
492    if (m_prevPOC >= m_pocRandomAccess)
493    {
494      m_prevPOC = m_apcSlicePilot->getPOC();
495      return true;
496    }
497    m_prevPOC = m_apcSlicePilot->getPOC();
498  }
499#endif
500  // actual decoding starts here
501  xActivateParameterSets();
502
503  if (m_apcSlicePilot->isNextSlice()) 
504  {
505    m_prevPOC = m_apcSlicePilot->getPOC();
506#if SVC_EXTENSION
507    curLayerId = m_layerId;
508    m_uiPrevLayerId = m_layerId;
509#endif
510  }
511  m_bFirstSliceInSequence = false;
512  //detect lost reference picture and insert copy of earlier frame.
513  Int lostPoc;
514  while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
515  {
516    xCreateLostPicture(lostPoc-1);
517  }
518  if (m_bFirstSliceInPicture)
519  {
520#if AVC_BASE
521  if( m_layerId == 1 )
522  {
523    TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
524    fstream* pFile  = m_ppcTDecTop[0]->getBLReconFile();
525    const Window &conf = pBLPic->getConformanceWindow();
526    UInt uiWidth    = pBLPic->getPicYuvRec()->getWidth() - conf.getWindowLeftOffset() - conf.getWindowRightOffset();
527    UInt uiHeight   = pBLPic->getPicYuvRec()->getHeight() - conf.getWindowTopOffset() - conf.getWindowBottomOffset();
528       
529    if( pFile->good() )
530    {
531      UInt64 uiPos = (UInt64) m_apcSlicePilot->getPOC() * uiWidth * uiHeight * 3 / 2;
532
533      pFile->seekg((UInt)uiPos, ios::beg );
534
535      Pel* pPel = pBLPic->getPicYuvRec()->getLumaAddr();
536      UInt uiStride = pBLPic->getPicYuvRec()->getStride();
537      for( Int i = 0; i < uiHeight; i++ )
538      {
539        for( Int j = 0; j < uiWidth; j++ )
540        {
541          pPel[j] = pFile->get();
542        }
543        pPel += uiStride;
544      }
545
546      pPel = pBLPic->getPicYuvRec()->getCbAddr();
547      uiStride = pBLPic->getPicYuvRec()->getCStride();
548      for( Int i = 0; i < uiHeight/2; i++ )
549      {
550        for( Int j = 0; j < uiWidth/2; j++ )
551        {
552          pPel[j] = pFile->get();
553        }
554        pPel += uiStride;
555      }
556
557      pPel = pBLPic->getPicYuvRec()->getCrAddr();
558      uiStride = pBLPic->getPicYuvRec()->getCStride();
559      for( Int i = 0; i < uiHeight/2; i++ )
560      {
561        for( Int j = 0; j < uiWidth/2; j++ )
562        {
563          pPel[j] = pFile->get();
564        }
565        pPel += uiStride;
566      }
567    }
568  }
569#endif
570
571    // Buffer initialize for prediction.
572    m_cPrediction.initTempBuff();
573    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
574    //  Get a new picture buffer
575    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
576
577    // transfer any SEI messages that have been received to the picture
578    pcPic->setSEIs(m_SEIs);
579    m_SEIs.clear();
580
581    // Recursive structure
582    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
583#if SVC_EXTENSION
584    m_cCuDecoder.init   ( m_ppcTDecTop,&m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction, curLayerId );
585#else
586    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
587#endif
588    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
589
590    m_cSliceDecoder.create();
591  }
592  else
593  {
594    // Check if any new SEI has arrived
595    if(!m_SEIs.empty())
596    {
597      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
598      SEIMessages &picSEI = pcPic->getSEIs();
599      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
600      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
601      deleteSEIs(m_SEIs);
602    }
603  }
604 
605  //  Set picture slice pointer
606  TComSlice*  pcSlice = m_apcSlicePilot;
607  Bool bNextSlice     = pcSlice->isNextSlice();
608
609  UInt uiCummulativeTileWidth;
610  UInt uiCummulativeTileHeight;
611  UInt i, j, p;
612
613  //set NumColumnsMins1 and NumRowsMinus1
614  pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
615  pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
616
617  //create the TComTileArray
618  pcPic->getPicSym()->xCreateTComTileArray();
619
620  if( pcSlice->getPPS()->getUniformSpacingFlag() )
621  {
622    //set the width for each tile
623    for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
624    {
625      for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
626      {
627        pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
628          setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
629          - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
630      }
631    }
632
633    //set the height for each tile
634    for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
635    {
636      for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
637      {
638        pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
639          setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
640          - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
641      }
642    }
643  }
644  else
645  {
646    //set the width for each tile
647    for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
648    {
649      uiCummulativeTileWidth = 0;
650      for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
651      {
652        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
653        uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
654      }
655      pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
656    }
657
658    //set the height for each tile
659    for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
660    {
661      uiCummulativeTileHeight = 0;
662      for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
663      { 
664        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
665        uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
666      }
667      pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
668    }
669  }
670
671  pcPic->getPicSym()->xInitTiles();
672
673  //generate the Coding Order Map and Inverse Coding Order Map
674  UInt uiEncCUAddr;
675  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
676  {
677    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
678    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
679  }
680  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
681  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
682
683  //convert the start and end CU addresses of the slice and dependent slice into encoding order
684  pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) );
685  pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) );
686  if(pcSlice->isNextSlice())
687  {
688    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
689    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
690  }
691
692  if (m_bFirstSliceInPicture) 
693  {
694    if(pcPic->getNumAllocatedSlice() != 1)
695    {
696      pcPic->clearSliceBuffer();
697    }
698  }
699  else
700  {
701    pcPic->allocateNewSlice();
702  }
703  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
704  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
705  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
706
707  pcPic->setTLayer(nalu.m_temporalId);
708
709#if SVC_EXTENSION
710  pcPic->setLayerId(nalu.m_layerId);
711  pcSlice->setLayerId(nalu.m_layerId);
712#endif
713
714  if (bNextSlice)
715  {
716    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA );
717#if !REF_IDX_FRAMEWORK || AVC_SYNTAX
718    // Set reference list
719    pcSlice->setRefPicList( m_cListPic );
720#endif
721
722#if SVC_EXTENSION   
723    if(m_layerId > 0)
724    {
725#if AVC_BASE
726      pcSlice->setBaseColPic ( *m_ppcTDecTop[0]->getListPic()->begin() );
727#if AVC_SYNTAX
728      TComPic* pBLPic = pcSlice->getBaseColPic();
729      if( pcSlice->getPOC() == 0 )
730      {
731        // initialize partition order.
732        UInt* piTmp = &g_auiZscanToRaster[0];
733        initZscanToRaster( pBLPic->getPicSym()->getMaxDepth() + 1, 1, 0, piTmp );
734        initRasterToZscan( pBLPic->getPicSym()->getMaxCUWidth(), pBLPic->getPicSym()->getMaxCUHeight(), pBLPic->getPicSym()->getMaxDepth() + 1 );
735      }     
736      pBLPic->getSlice( 0 )->initBaseLayerRPL( pcSlice );
737      pBLPic->readBLSyntax( m_ppcTDecTop[0]->getBLSyntaxFile(), SYNTAX_BYTES );
738#endif
739
740#else
741      TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
742      TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
743      pcSlice->setBaseColPic ( *cListPic, m_layerId );
744#endif
745#if SVC_UPSAMPLING
746      if ( pcPic->isSpatialEnhLayer())
747      {   
748        m_cPrediction.upsampleBasePic( pcPic->getFullPelBaseRec(), pcSlice->getBaseColPic()->getPicYuvRec(), pcPic->getPicYuvRec() );
749      }
750      else
751      {
752        pcPic->setFullPelBaseRec( pcSlice->getBaseColPic()->getPicYuvRec() );
753      }
754      pcSlice->setFullPelBaseRec ( pcPic->getFullPelBaseRec() );
755#endif
756    }
757#endif
758
759#if REF_IDX_FRAMEWORK
760#if !AVC_SYNTAX
761    // Set reference list
762    pcSlice->setRefPicList( m_cListPic );
763#endif
764    if(m_layerId > 0)
765    {
766      setILRPic(pcPic);
767#if REF_IDX_MFM
768      pcSlice->setRefPOCListILP(m_ppcTDecTop[m_layerId]->m_cIlpPic, pcSlice->getBaseColPic());
769#endif
770
771      pcSlice->addRefPicList ( m_cIlpPic, 
772                               1, 
773                               ((pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA) && 
774                                (pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA)) ? 0: -1);
775    }
776#endif
777
778    // For generalized B
779    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
780    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
781    {
782      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
783      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
784
785      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
786      {
787        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
788      }
789    }
790    if (!pcSlice->isIntra())
791    {
792      Bool bLowDelay = true;
793      Int  iCurrPOC  = pcSlice->getPOC();
794      Int iRefIdx = 0;
795
796      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
797      {
798        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
799        {
800          bLowDelay = false;
801        }
802      }
803      if (pcSlice->isInterB())
804      {
805        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
806        {
807          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
808          {
809            bLowDelay = false;
810          }
811        }       
812      }
813
814      pcSlice->setCheckLDC(bLowDelay);           
815    }
816
817    //---------------
818    pcSlice->setRefPOCList();
819    pcSlice->setNoBackPredFlag( false );
820    if ( pcSlice->getSliceType() == B_SLICE )
821    {
822      if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) )
823      {
824        pcSlice->setNoBackPredFlag( true );
825        for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ )
826        {
827          if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) 
828          {
829            pcSlice->setNoBackPredFlag( false );
830            break;
831          }
832        }
833      }
834    }
835  }
836
837  pcPic->setCurrSliceIdx(m_uiSliceIdx);
838  if(pcSlice->getSPS()->getScalingListFlag())
839  {
840    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
841    if(pcSlice->getPPS()->getScalingListPresentFlag())
842    {
843      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
844    }
845    pcSlice->getScalingList()->setUseTransformSkip(pcSlice->getPPS()->getUseTransformSkip());
846    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
847    {
848      pcSlice->setDefaultScalingList();
849    }
850    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
851    m_cTrQuant.setUseScalingList(true);
852  }
853  else
854  {
855    m_cTrQuant.setFlatScalingList();
856    m_cTrQuant.setUseScalingList(false);
857  }
858
859  //  Decode a picture
860  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
861
862  m_bFirstSliceInPicture = false;
863  m_uiSliceIdx++;
864
865  return false;
866}
867
868Void TDecTop::xDecodeVPS()
869{
870  TComVPS* vps = new TComVPS();
871 
872  m_cEntropyDecoder.decodeVPS( vps );
873  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
874}
875
876Void TDecTop::xDecodeSPS()
877{
878  TComSPS* sps = new TComSPS();
879#if SVC_EXTENSION
880  sps->setLayerId(m_layerId);
881#endif
882  m_cEntropyDecoder.decodeSPS( sps );
883  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
884#if REF_IDX_MFM
885  m_pcSPS = sps;
886  setMFMEnabledFlag(sps->getMFMEnabledFlag());
887#endif
888#if REF_IDX_FRAMEWORK
889  if(m_numLayer>0)
890  {
891    xInitILRP(sps);
892  }
893#endif
894}
895
896Void TDecTop::xDecodePPS()
897{
898  TComPPS* pps = new TComPPS();
899  m_cEntropyDecoder.decodePPS( pps );
900  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
901
902  if( pps->getDependentSliceSegmentsEnabledFlag() )
903  {
904    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
905    m_cSliceDecoder.initCtxMem(NumCtx);
906    for ( UInt st = 0; st < NumCtx; st++ )
907    {
908      TDecSbac* ctx = NULL;
909      ctx = new TDecSbac;
910      ctx->init( &m_cBinCABAC );
911      m_cSliceDecoder.setCtxMem( ctx, st );
912    }
913  }
914}
915
916Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
917{
918  if(nalUnitType == NAL_UNIT_SEI_SUFFIX)
919  {
920    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
921  }
922  else
923  {
924    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
925    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
926    if (activeParamSets.size()>0)
927    {
928      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
929      m_parameterSetManagerDecoder.applyPrefetchedPS();
930      assert(seiAps->activeSeqParamSetId.size()>0);
931      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
932      {
933        printf ("Warning SPS activation with Active parameter set SEI failed");
934      }
935    }
936  }
937}
938
939#if SVC_EXTENSION
940Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC)
941#else
942Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
943#endif
944{
945  // Initialize entropy decoder
946  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
947  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
948
949  switch (nalu.m_nalUnitType)
950  {
951    case NAL_UNIT_VPS:
952      xDecodeVPS();
953      return false;
954     
955    case NAL_UNIT_SPS:
956      xDecodeSPS();
957#if AVC_BASE
958      {
959        TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
960        if( nalu.m_layerId == 1 && pBLPic->getPicYuvRec() == NULL )
961        {
962#if SVC_UPSAMPLING
963#if AVC_SYNTAX
964          TComSPS* sps = new TComSPS();
965          Int  numReorderPics[MAX_TLAYER];
966          Window &conformanceWindow = sps->getConformanceWindow();
967          Window defaultDisplayWindow = sps->getVuiParametersPresentFlag() ? sps->getVuiParameters()->getDefaultDisplayWindow() : Window();
968
969          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, sps, true);
970#else
971          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, NULL, onformanceWindow, defaultDisplayWindow, numReorderPics, true);
972#endif
973#else
974          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, onformanceWindow, defaultDisplayWindow, numReorderPics, true);
975#endif
976        }
977      }
978#endif
979      return false;
980
981    case NAL_UNIT_PPS:
982      xDecodePPS();
983      return false;
984     
985    case NAL_UNIT_SEI:
986    case NAL_UNIT_SEI_SUFFIX:
987      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
988      return false;
989
990    case NAL_UNIT_CODED_SLICE_TRAIL_R:
991    case NAL_UNIT_CODED_SLICE_TRAIL_N:
992    case NAL_UNIT_CODED_SLICE_TLA:
993    case NAL_UNIT_CODED_SLICE_TSA_N:
994    case NAL_UNIT_CODED_SLICE_STSA_R:
995    case NAL_UNIT_CODED_SLICE_STSA_N:
996    case NAL_UNIT_CODED_SLICE_BLA:
997    case NAL_UNIT_CODED_SLICE_BLANT:
998    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
999    case NAL_UNIT_CODED_SLICE_IDR:
1000    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
1001    case NAL_UNIT_CODED_SLICE_CRA:
1002    case NAL_UNIT_CODED_SLICE_RADL_N:
1003    case NAL_UNIT_CODED_SLICE_DLP:
1004    case NAL_UNIT_CODED_SLICE_RASL_N:
1005    case NAL_UNIT_CODED_SLICE_TFD:
1006#if SVC_EXTENSION
1007      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, curLayerId, bNewPOC);
1008#else
1009      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1010#endif
1011      break;
1012    default:
1013      assert (1);
1014  }
1015
1016  return false;
1017}
1018
1019/** Function for checking if picture should be skipped because of association with a previous BLA picture
1020 * \param iPOCLastDisplay POC of last picture displayed
1021 * \returns true if the picture should be skipped
1022 * This function skips all TFD pictures that follow a BLA picture
1023 * in decoding order and precede it in output order.
1024 */
1025Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
1026{
1027  if (m_prevRAPisBLA && m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TFD || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
1028  {
1029    iPOCLastDisplay++;
1030    return true;
1031  }
1032  return false;
1033}
1034
1035/** Function for checking if picture should be skipped because of random access
1036 * \param iSkipFrame skip frame counter
1037 * \param iPOCLastDisplay POC of last picture displayed
1038 * \returns true if the picture shold be skipped in the random access.
1039 * This function checks the skipping of pictures in the case of -s option random access.
1040 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1041 * It also checks the type of Nal unit type at the random access point.
1042 * 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.
1043 * If the random access point is IDR all pictures after the random access point are decoded.
1044 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
1045 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
1046 * access point there is no guarantee that the decoder will not crash.
1047 */
1048Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
1049{
1050  if (iSkipFrame) 
1051  {
1052    iSkipFrame--;   // decrement the counter
1053    return true;
1054  }
1055  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1056  {
1057    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
1058        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA
1059        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1060        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT )
1061    {
1062      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
1063      m_pocRandomAccess = m_apcSlicePilot->getPOC();
1064    }
1065    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
1066    {
1067      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1068    }
1069    else 
1070    {
1071      static Bool warningMessage = false;
1072      if(!warningMessage)
1073      {
1074        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1075        warningMessage = true;
1076      }
1077      return true;
1078    }
1079  }
1080  // skip the reordered pictures, if necessary
1081  else if (m_apcSlicePilot->getPOC() < m_pocRandomAccess && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TFD || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
1082  {
1083    iPOCLastDisplay++;
1084    return true;
1085  }
1086  // if we reach here, then the picture is not skipped.
1087  return false; 
1088}
1089
1090//! \}
Note: See TracBrowser for help on using the repository browser.