source: SHVCSoftware/branches/SHM-1.1-dev/source/Lib/TLibDecoder/TDecTop.cpp @ 39

Last change on this file since 39 was 38, checked in by seregin, 13 years ago

AVC_SYNTAX: initial porting of the AVC metadata file reading

File size: 38.0 KB
RevLine 
[2]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
[38]83#if AVC_SYNTAX || SYNTAX_OUTPUT
84  m_pBLSyntaxFile = NULL;
85#endif
[2]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);
[6]164#if SVC_UPSAMPLING
[2]165        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, pcSPS, true);
[6]166#else
167        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true);
168#endif
[28]169#if REF_IDX_ME_AROUND_ZEROMV || REF_IDX_ME_ZEROMV || REF_IDX_MFM
[21]170        m_cIlpPic[j]->setIsILR(true);
171#endif
[2]172        for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++)
173        {
[30]174          m_cIlpPic[j]->getPicSym()->getCU(i)->initCU(m_cIlpPic[j], i);
[2]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
[28]275
276
[2]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
[28]323
324
[2]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
[38]341#if SYNTAX_OUTPUT
342  pcPic->wrireBLSyntax( getBLSyntaxFile(), SYNTAX_BYTES );
343#endif
344
[2]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() );
[11]360#if SET_SLICE_LAYER_ID
361  cFillSlice.initSlice( m_parameterSetManagerDecoder.getFirstSPS()->getLayerId() );
362#else
[2]363  cFillSlice.initSlice();
[11]364#endif
[2]365  TComPic *cFillPic;
366  xGetNewPicBuffer(&cFillSlice,cFillPic);
367  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
368  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
[11]369#if SET_SLICE_LAYER_ID
370  cFillPic->getSlice(0)->initSlice( cFillPic->getLayerId() );
371#else
[2]372  cFillPic->getSlice(0)->initSlice();
[11]373#endif
[2]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;
[11]464#if SET_SLICE_LAYER_ID
465  m_apcSlicePilot->initSlice( nalu.m_layerId );
466#else
[2]467  m_apcSlicePilot->initSlice();
[11]468#endif
[2]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
564#if AVC_BASE
565  if( m_layerId == 1 )
566  {
567    TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
[38]568    fstream* pFile  = m_ppcTDecTop[0]->getBLReconFile();
569    UInt uiWidth    = pBLPic->getPicYuvRec()->getWidth() - pBLPic->getPicYuvRec()->getPicCropLeftOffset() - pBLPic->getPicYuvRec()->getPicCropRightOffset();;
570    UInt uiHeight   = pBLPic->getPicYuvRec()->getHeight() - pBLPic->getPicYuvRec()->getPicCropTopOffset() - pBLPic->getPicYuvRec()->getPicCropBottomOffset();
[2]571       
[38]572    if( pFile->good() )
[2]573    {
[38]574      UInt64 uiPos = (UInt64) m_apcSlicePilot->getPOC() * uiWidth * uiHeight * 3 / 2;
[2]575
[38]576      pFile->seekg((UInt)uiPos, ios::beg );
577
[2]578      Pel* pPel = pBLPic->getPicYuvRec()->getLumaAddr();
579      UInt uiStride = pBLPic->getPicYuvRec()->getStride();
580      for( Int i = 0; i < uiHeight; i++ )
581      {
582        for( Int j = 0; j < uiWidth; j++ )
583        {
[38]584          pPel[j] = pFile->get();
[2]585        }
586        pPel += uiStride;
587      }
588
589      pPel = pBLPic->getPicYuvRec()->getCbAddr();
590      uiStride = pBLPic->getPicYuvRec()->getCStride();
591      for( Int i = 0; i < uiHeight/2; i++ )
592      {
593        for( Int j = 0; j < uiWidth/2; j++ )
594        {
[38]595          pPel[j] = pFile->get();
[2]596        }
597        pPel += uiStride;
598      }
599
600      pPel = pBLPic->getPicYuvRec()->getCrAddr();
601      uiStride = pBLPic->getPicYuvRec()->getCStride();
602      for( Int i = 0; i < uiHeight/2; i++ )
603      {
604        for( Int j = 0; j < uiWidth/2; j++ )
605        {
[38]606          pPel[j] = pFile->get();
[2]607        }
608        pPel += uiStride;
609      }
610    }
[38]611#if AVC_SYNTAX
612    if( m_apcSlicePilot->getPOC() == 0 )
613    {
614      // initialize partition order.
615      UInt* piTmp = &g_auiZscanToRaster[0];
616      initZscanToRaster( pBLPic->getPicSym()->getMaxDepth() + 1, 1, 0, piTmp );
617      initRasterToZscan( pBLPic->getPicSym()->getMaxCUWidth(), pBLPic->getPicSym()->getMaxCUHeight(), pBLPic->getPicSym()->getMaxDepth() + 1 );
618    }
619    pBLPic->getSlice( 0 )->setPOC( m_apcSlicePilot->getPOC() );
620    pBLPic->getSlice( 0 )->setSliceType( m_apcSlicePilot->getSliceType() );
621    pBLPic->readBLSyntax( m_ppcTDecTop[0]->getBLSyntaxFile(), SYNTAX_BYTES );
622#endif
[2]623  }
624#endif
625
626    // Buffer initialize for prediction.
627    m_cPrediction.initTempBuff();
628    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
629    //  Get a new picture buffer
630    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
631
632    /* transfer any SEI messages that have been received to the picture */
633    pcPic->setSEIs(m_SEIs);
634    m_SEIs = NULL;
635
636    // Recursive structure
637    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
638#if SVC_EXTENSION
639    m_cCuDecoder.init   ( m_ppcTDecTop,&m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction, curLayerId );
640#else
641    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
642#endif
643    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
644
645    m_cSliceDecoder.create( m_apcSlicePilot, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
646  }
647
648  //  Set picture slice pointer
649  TComSlice*  pcSlice = m_apcSlicePilot;
650  Bool bNextSlice     = pcSlice->isNextSlice();
651
652  UInt uiCummulativeTileWidth;
653  UInt uiCummulativeTileHeight;
654  UInt i, j, p;
655
656  //set NumColumnsMins1 and NumRowsMinus1
657  pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
658  pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
659
660  //create the TComTileArray
661  pcPic->getPicSym()->xCreateTComTileArray();
662
663  if( pcSlice->getPPS()->getUniformSpacingFlag() )
664  {
665    //set the width for each tile
666    for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
667    {
668      for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
669      {
670        pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
671          setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
672          - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
673      }
674    }
675
676    //set the height for each tile
677    for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
678    {
679      for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
680      {
681        pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
682          setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
683          - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
684      }
685    }
686  }
687  else
688  {
689    //set the width for each tile
690    for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
691    {
692      uiCummulativeTileWidth = 0;
693      for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
694      {
695        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
696        uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
697      }
698      pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
699    }
700
701    //set the height for each tile
702    for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
703    {
704      uiCummulativeTileHeight = 0;
705      for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
706      { 
707        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
708        uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
709      }
710      pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
711    }
712  }
713
714  pcPic->getPicSym()->xInitTiles();
715
716  //generate the Coding Order Map and Inverse Coding Order Map
717  UInt uiEncCUAddr;
718  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
719  {
720    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
721    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
722  }
723  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
724  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
725
726  //convert the start and end CU addresses of the slice and dependent slice into encoding order
727  pcSlice->setDependentSliceCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getDependentSliceCurStartCUAddr()) );
728  pcSlice->setDependentSliceCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getDependentSliceCurEndCUAddr()) );
729  if(pcSlice->isNextSlice())
730  {
731    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
732    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
733  }
734
735  if (m_bFirstSliceInPicture) 
736  {
737    if(pcPic->getNumAllocatedSlice() != 1)
738    {
739      pcPic->clearSliceBuffer();
740    }
741  }
742  else
743  {
744    pcPic->allocateNewSlice();
745  }
746  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
747  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
748  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
749
750  pcPic->setTLayer(nalu.m_temporalId);
751
752#if SVC_EXTENSION
753  pcPic->setLayerId(nalu.m_layerId);
754  pcSlice->setLayerId(nalu.m_layerId);
755#endif
756
757  if (bNextSlice)
758  {
759    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA, m_cListPic);
760#if !REF_IDX_FRAMEWORK
761    // Set reference list
762    pcSlice->setRefPicList( m_cListPic );
763#endif
764
765#if SVC_EXTENSION   
766    if(m_layerId > 0)
767    {
768#if AVC_BASE
769      pcSlice->setBaseColPic ( *m_ppcTDecTop[0]->getListPic()->begin() );
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    // Set reference list
791    pcSlice->setRefPicList( m_cListPic );
792    if(m_layerId > 0)
793    {
794      setILRPic(pcPic);
[28]795#if REF_IDX_MFM
796      pcSlice->setRefPOCListILP(m_ppcTDecTop[m_layerId]->m_cIlpPic, pcSlice->getBaseColPic());
797#endif
798
[2]799      pcSlice->addRefPicList ( m_cIlpPic, 
800                               1, 
801                               ((pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA) && 
802                                (pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA)) ? 0: -1);
803    }
804#endif
805
806    // For generalized B
807    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
808    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
809    {
810      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
811      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
812
813      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
814      {
815        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
816      }
817    }
818    if (pcSlice->isInterB())
819    {
820      Bool bLowDelay = true;
821      Int  iCurrPOC  = pcSlice->getPOC();
822      Int iRefIdx = 0;
823
824      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
825      {
826        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
827        {
828          bLowDelay = false;
829        }
830      }
831      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
832      {
833        if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
834        {
835          bLowDelay = false;
836        }
837      }
838
839      pcSlice->setCheckLDC(bLowDelay);           
840    }
841
842    //---------------
843    pcSlice->setRefPOCList();
844    pcSlice->setNoBackPredFlag( false );
845    if ( pcSlice->getSliceType() == B_SLICE )
846    {
847      if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) )
848      {
849        pcSlice->setNoBackPredFlag( true );
850        for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ )
851        {
852          if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) 
853          {
854            pcSlice->setNoBackPredFlag( false );
855            break;
856          }
857        }
858      }
859    }
860  }
861
862  pcPic->setCurrSliceIdx(m_uiSliceIdx);
863  if(pcSlice->getSPS()->getScalingListFlag())
864  {
865    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
866    if(pcSlice->getPPS()->getScalingListPresentFlag())
867    {
868      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
869    }
870#if TS_FLAT_QUANTIZATION_MATRIX
871    pcSlice->getScalingList()->setUseTransformSkip(pcSlice->getPPS()->getUseTransformSkip());
872#endif
873    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
874    {
875      pcSlice->setDefaultScalingList();
876    }
877    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
878    m_cTrQuant.setUseScalingList(true);
879  }
880  else
881  {
882    m_cTrQuant.setFlatScalingList();
883    m_cTrQuant.setUseScalingList(false);
884  }
885
886  //  Decode a picture
887  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
888
889  m_bFirstSliceInPicture = false;
890  m_uiSliceIdx++;
891
892  return false;
893}
894
895Void TDecTop::xDecodeVPS()
896{
897  TComVPS* vps = new TComVPS();
898 
899  m_cEntropyDecoder.decodeVPS( vps );
900  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
901}
902
903Void TDecTop::xDecodeSPS()
904{
905  TComSPS* sps = new TComSPS();
906#if SVC_EXTENSION
907  sps->setLayerId(m_layerId);
908#endif
909  m_cEntropyDecoder.decodeSPS( sps );
910  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
[28]911#if REF_IDX_MFM
912  m_pcSPS = sps;
913  setMFMEnabledFlag(sps->getMFMEnabledFlag());
914#endif
[2]915#if !REMOVE_ALF
916  m_cAdaptiveLoopFilter.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
917#endif
918#if REF_IDX_FRAMEWORK
919  if(m_numLayer>0)
920  {
921    xInitILRP(sps);
922  }
923#endif
924}
925
926Void TDecTop::xDecodePPS()
927{
928  TComPPS* pps = new TComPPS();
929  m_cEntropyDecoder.decodePPS( pps, &m_parameterSetManagerDecoder );
930  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
931
932#if DEPENDENT_SLICES
933#if TILES_WPP_ENTROPYSLICES_FLAGS
934  if( pps->getDependentSliceEnabledFlag() && (!pps->getEntropySliceEnabledFlag()) )
935#else
936  if( pps->getDependentSliceEnabledFlag() && (!pps->getCabacIndependentFlag()) )
937#endif
938  {
939#if TILES_WPP_ENTROPYSLICES_FLAGS
940    int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
941#else
942    int NumCtx = (pps->getTilesOrEntropyCodingSyncIdc() == 2)?2:1;
943#endif
944    m_cSliceDecoder.initCtxMem(NumCtx);
945    for ( UInt st = 0; st < NumCtx; st++ )
946    {
947      TDecSbac* ctx = NULL;
948      ctx = new TDecSbac;
949      ctx->init( &m_cBinCABAC );
950      m_cSliceDecoder.setCtxMem( ctx, st );
951    }
952  }
953#endif
954}
955
956#if !REMOVE_APS
957Void TDecTop::xDecodeAPS()
958{
959  TComAPS  *aps = new TComAPS();
960  allocAPS (aps);
961  decodeAPS(aps);
962  m_parameterSetManagerDecoder.storePrefetchedAPS(aps);
963}
964#endif
965
966Void TDecTop::xDecodeSEI( TComInputBitstream* bs )
967{
968#if RECOVERY_POINT_SEI || BUFFERING_PERIOD_AND_TIMING_SEI
969  if ( m_SEIs == NULL )
970#endif
971  m_SEIs = new SEImessages;
972#if BUFFERING_PERIOD_AND_TIMING_SEI
973  m_SEIs->m_pSPS = m_parameterSetManagerDecoder.getSPS(0);
974#endif
975  m_seiReader.parseSEImessage( bs, *m_SEIs );
976}
977
978#if SVC_EXTENSION
979Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC)
980#else
981Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
982#endif
983{
984  // Initialize entropy decoder
985  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
986  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
987
988  switch (nalu.m_nalUnitType)
989  {
990    case NAL_UNIT_VPS:
991      xDecodeVPS();
992      return false;
993     
994    case NAL_UNIT_SPS:
995      xDecodeSPS();
996#if AVC_BASE
997      {
998        TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
999        if( nalu.m_layerId == 1 && pBLPic->getPicYuvRec() == NULL )
1000        {
1001#if SVC_UPSAMPLING
[38]1002#if AVC_SYNTAX
1003          TComSPS* sps = new TComSPS();
1004          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, sps, true);
1005#else
[2]1006          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, NULL, true);
[38]1007#endif
[2]1008#else
1009          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true);
1010#endif
1011        }
1012      }
1013#endif
1014      return false;
1015
1016    case NAL_UNIT_PPS:
1017      xDecodePPS();
1018      return false;
1019#if !REMOVE_APS
1020    case NAL_UNIT_APS:
1021      xDecodeAPS();
1022      return false;
1023#endif
1024     
1025    case NAL_UNIT_SEI:
1026      xDecodeSEI( nalu.m_Bitstream );
1027      return false;
1028
1029#if NAL_UNIT_TYPES_J1003_D7
1030    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1031    case NAL_UNIT_CODED_SLICE_TRAIL_N:
1032    case NAL_UNIT_CODED_SLICE_TLA:
1033    case NAL_UNIT_CODED_SLICE_TSA_N:
1034    case NAL_UNIT_CODED_SLICE_STSA_R:
1035    case NAL_UNIT_CODED_SLICE_STSA_N:
1036    case NAL_UNIT_CODED_SLICE_BLA:
1037    case NAL_UNIT_CODED_SLICE_BLANT:
1038    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1039    case NAL_UNIT_CODED_SLICE_IDR:
1040    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
1041    case NAL_UNIT_CODED_SLICE_CRA:
1042    case NAL_UNIT_CODED_SLICE_DLP:
1043    case NAL_UNIT_CODED_SLICE_TFD:
1044#else
1045    case NAL_UNIT_CODED_SLICE:
1046    case NAL_UNIT_CODED_SLICE_TFD:
1047    case NAL_UNIT_CODED_SLICE_TLA:
1048    case NAL_UNIT_CODED_SLICE_CRA:
1049    case NAL_UNIT_CODED_SLICE_CRANT:
1050    case NAL_UNIT_CODED_SLICE_BLA:
1051    case NAL_UNIT_CODED_SLICE_BLANT:
1052    case NAL_UNIT_CODED_SLICE_IDR:
1053#endif
1054#if SVC_EXTENSION
1055      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, curLayerId, bNewPOC);
1056#else
1057      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1058#endif
1059      break;
1060    default:
1061      assert (1);
1062  }
1063
1064  return false;
1065}
1066
1067/** Function for checking if picture should be skipped because of association with a previous BLA picture
1068 * \param iPOCLastDisplay POC of last picture displayed
1069 * \returns true if the picture should be skipped
1070 * This function skips all TFD pictures that follow a BLA picture
1071 * in decoding order and precede it in output order.
1072 */
1073Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
1074{
1075  if (m_prevRAPisBLA && m_apcSlicePilot->getPOC() < m_pocCRA && m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TFD)
1076  {
1077    iPOCLastDisplay++;
1078    return true;
1079  }
1080  return false;
1081}
1082
1083/** Function for checking if picture should be skipped because of random access
1084 * \param iSkipFrame skip frame counter
1085 * \param iPOCLastDisplay POC of last picture displayed
1086 * \returns true if the picture shold be skipped in the random access.
1087 * This function checks the skipping of pictures in the case of -s option random access.
1088 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1089 * It also checks the type of Nal unit type at the random access point.
1090 * 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.
1091 * If the random access point is IDR all pictures after the random access point are decoded.
1092 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
1093 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
1094 * access point there is no guarantee that the decoder will not crash.
1095 */
1096Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
1097{
1098  if (iSkipFrame) 
1099  {
1100    iSkipFrame--;   // decrement the counter
1101    return true;
1102  }
1103  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1104  {
1105    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
1106#if !NAL_UNIT_TYPES_J1003_D7
1107        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRANT
1108#endif
1109        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA
1110#if SUPPORT_FOR_RAP_N_LP
1111        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1112#endif
1113        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT )
1114    {
1115      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
1116      m_pocRandomAccess = m_apcSlicePilot->getPOC();
1117    }
1118#if SUPPORT_FOR_RAP_N_LP
1119    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
1120#else
1121    else if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR)
1122#endif
1123    {
1124      m_pocRandomAccess = 0; // no need to skip the reordered pictures in IDR, they are decodable.
1125    }
1126    else 
1127    {
1128      static bool warningMessage = false;
1129      if(!warningMessage)
1130      {
1131        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1132        warningMessage = true;
1133      }
1134      return true;
1135    }
1136  }
1137  // skip the reordered pictures, if necessary
1138  else if (m_apcSlicePilot->getPOC() < m_pocRandomAccess && m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TFD)
1139  {
1140    iPOCLastDisplay++;
1141    return true;
1142  }
1143  // if we reach here, then the picture is not skipped.
1144  return false; 
1145}
1146
1147#if !REMOVE_APS
1148Void TDecTop::allocAPS (TComAPS* pAPS)
1149{
1150  // we don't know the SPS before it has been activated. These fields could exist
1151  // depending on the corresponding flags in the APS, but SAO/ALF allocation functions will
1152  // have to be moved for that
1153  pAPS->createSaoParam();
1154  m_cSAO.allocSaoParam(pAPS->getSaoParam());
1155#if !REMOVE_ALF
1156  pAPS->createAlfParam();
1157#endif
1158}
1159#endif
1160
1161//! \}
Note: See TracBrowser for help on using the repository browser.