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

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

port simulcast

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