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

Last change on this file since 558 was 104, checked in by interdigital, 12 years ago

reference picture list construction bug fix for adding ILR picture to match SHM test model text.

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