source: SHVCSoftware/branches/SHM-1.0-dev/source/Lib/TLibDecoder/TDecTop.cpp @ 1499

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

Merge with trunk

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