source: SHVCSoftware/trunk/source/Lib/TLibDecoder/TDecTop.cpp @ 78

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

Reintegrate SHM-1.1-dev branch into the trunk

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