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

Last change on this file since 91 was 90, checked in by seregin, 12 years ago

splitting parameter sets for layers

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