source: SHVCSoftware/branches/SHM-2.0-dev/source/Lib/TLibDecoder/TDecTop.cpp @ 151

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

compilation error fix

File size: 42.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-2013, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TDecTop.cpp
35    \brief    decoder class
36*/
37
38#include "NALread.h"
39#include "TDecTop.h"
40
41#if SVC_EXTENSION
42UInt  TDecTop::m_prevPOC = MAX_UINT;
43UInt  TDecTop::m_uiPrevLayerId = MAX_UINT;
44Bool  TDecTop::m_bFirstSliceInSequence = true;
45#endif
46
47//! \ingroup TLibDecoder
48//! \{
49
50TDecTop::TDecTop()
51{
52  m_pcPic = 0;
53  m_iMaxRefPicNum = 0;
54#if ENC_DEC_TRACE
55  g_hTrace = fopen( "TraceDec.txt", "wb" );
56  g_bJustDoIt = g_bEncDecTraceDisable;
57  g_nSymbolCounter = 0;
58#endif
59  m_pocCRA = 0;
60  m_prevRAPisBLA = false;
61  m_pocRandomAccess = MAX_INT;         
62#if !SVC_EXTENSION
63  m_prevPOC                = MAX_INT;
64#endif
65  m_bFirstSliceInPicture    = true;
66#if !SVC_EXTENSION
67  m_bFirstSliceInSequence   = true;
68#endif
69#if SVC_EXTENSION
70  m_layerId = 0;
71#if AVC_BASE
72  m_pBLReconFile = NULL;
73#endif
74#endif
75#if REF_IDX_FRAMEWORK
76  memset(m_cIlpPic, 0, sizeof(m_cIlpPic));
77#endif
78#if AVC_SYNTAX || SYNTAX_OUTPUT
79  m_pBLSyntaxFile = NULL;
80#endif
81
82}
83
84TDecTop::~TDecTop()
85{
86#if ENC_DEC_TRACE
87  fclose( g_hTrace );
88#endif
89}
90
91Void TDecTop::create()
92{
93#if SVC_EXTENSION
94  m_cGopDecoder.create( m_layerId );
95#else
96  m_cGopDecoder.create();
97#endif
98  m_apcSlicePilot = new TComSlice;
99  m_uiSliceIdx = 0;
100}
101
102Void TDecTop::destroy()
103{
104  m_cGopDecoder.destroy();
105 
106  delete m_apcSlicePilot;
107  m_apcSlicePilot = NULL;
108 
109  m_cSliceDecoder.destroy();
110#if REF_IDX_FRAMEWORK
111  for(Int i=0; i<MAX_NUM_REF; i++)
112  {
113    if(m_cIlpPic[i])
114    {
115      //m_cIlpPic[i]->setPicYuvRec(NULL);
116      m_cIlpPic[i]->destroy();
117      delete m_cIlpPic[i];
118      m_cIlpPic[i] = NULL;
119    }
120  }   
121#endif
122}
123
124Void TDecTop::init()
125{
126#if !SVC_EXTENSION
127  // initialize ROM
128  initROM();
129#endif
130#if SVC_EXTENSION
131  m_cGopDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
132  m_cSliceDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cCuDecoder );
133#else
134  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
135  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
136#endif
137  m_cEntropyDecoder.init(&m_cPrediction);
138}
139
140#if REF_IDX_FRAMEWORK
141Void TDecTop::xInitILRP(TComSPS *pcSPS)
142{
143  if(m_layerId>0)
144  {
145    g_bitDepthY     = pcSPS->getBitDepthY();
146    g_bitDepthC     = pcSPS->getBitDepthC();
147    g_uiMaxCUWidth  = pcSPS->getMaxCUWidth();
148    g_uiMaxCUHeight = pcSPS->getMaxCUHeight();
149    g_uiMaxCUDepth  = pcSPS->getMaxCUDepth();
150    g_uiAddCUDepth  = max (0, pcSPS->getLog2MinCodingBlockSize() - (Int)pcSPS->getQuadtreeTULog2MinSize() );
151
152    Int  numReorderPics[MAX_TLAYER];
153    Window &conformanceWindow = pcSPS->getConformanceWindow();
154    Window defaultDisplayWindow = pcSPS->getVuiParametersPresentFlag() ? pcSPS->getVuiParameters()->getDefaultDisplayWindow() : Window();
155
156    for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
157    {
158      numReorderPics[temporalLayer] = pcSPS->getNumReorderPics(temporalLayer);
159    }
160
161    if (m_cIlpPic[0] == NULL)
162    {
163      for (Int j=0; j<1/*MAX_NUM_REF*/; j++)
164      {
165        m_cIlpPic[j] = new  TComPic;
166        //m_cIlpPic[j]->createWithOutYuv(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, &m_cSPS, true);
167#if SVC_UPSAMPLING
168        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
169#else
170        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, 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]->setLayerId(pcPic->getSlice(0)->getBaseColPic()->getLayerId()); //set reference layerId
189    m_cIlpPic[0]->getPicYuvRec()->setBorderExtension(false);
190    m_cIlpPic[0]->getPicYuvRec()->extendPicBorder();
191  }
192}
193#endif
194
195Void TDecTop::deletePicBuffer ( )
196{
197  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
198  Int iSize = Int( m_cListPic.size() );
199 
200  for (Int i = 0; i < iSize; i++ )
201  {
202    TComPic* pcPic = *(iterPic++);
203#if SVC_EXTENSION
204    if( pcPic )
205    {
206      pcPic->destroy();
207
208      delete pcPic;
209      pcPic = NULL;
210    }
211#else
212    pcPic->destroy();
213   
214    delete pcPic;
215    pcPic = NULL;
216#endif
217  }
218 
219  m_cSAO.destroy();
220 
221  m_cLoopFilter.        destroy();
222 
223#if !SVC_EXTENSION
224  // destroy ROM
225  destroyROM();
226#endif
227}
228
229Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
230{
231  Int  numReorderPics[MAX_TLAYER];
232  Window &conformanceWindow = pcSlice->getSPS()->getConformanceWindow();
233  Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window();
234
235  for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
236  {
237    numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer);
238  }
239
240#if L0323_DPB
241  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer())+pcSlice->getSPS()->getNumReorderPics(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
242#else
243  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer())+pcSlice->getSPS()->getNumReorderPics(pcSlice->getTLayer()) + 1; // +1 to have space for the picture currently being decoded
244#endif
245  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
246  {
247    rpcPic = new TComPic();
248
249#if SVC_EXTENSION //Temporal solution, should be modified
250    if(m_layerId > 0)
251    {
252#if VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE
253      TDecTop *pcTDecTopBase = (TDecTop *)getRefLayerDec( m_layerId );
254#else
255      TDecTop *pcTDecTopBase = (TDecTop *)getLayerDec( m_layerId-1 );
256#endif
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, 
268                     conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
269#else
270    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
271                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
272#endif
273    rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
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,
314                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
315
316#else
317  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
318                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
319#endif
320  rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
321}
322
323Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic)
324{
325  if (!m_pcPic)
326  {
327    /* nothing to deblock */
328    return;
329  }
330 
331  TComPic*&   pcPic         = m_pcPic;
332
333  // Execute Deblock + Cleanup
334
335  m_cGopDecoder.filterPicture(pcPic);
336
337#if SYNTAX_OUTPUT
338  pcPic->wrireBLSyntax( getBLSyntaxFile(), SYNTAX_BYTES );
339#endif
340  TComSlice::sortPicList( m_cListPic ); // sorting for application output
341  poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
342  rpcListPic          = &m_cListPic; 
343  m_cCuDecoder.destroy();       
344  m_bFirstSliceInPicture  = true;
345
346  return;
347}
348
349Void TDecTop::xCreateLostPicture(Int iLostPoc) 
350{
351  printf("\ninserting lost poc : %d\n",iLostPoc);
352  TComSlice cFillSlice;
353#if SVC_EXTENSION
354  cFillSlice.setSPS( m_parameterSetManagerDecoder[m_layerId].getFirstSPS() );
355  cFillSlice.setPPS( m_parameterSetManagerDecoder[m_layerId].getFirstPPS() );
356  cFillSlice.initSlice( m_layerId );
357#else
358  cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
359  cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
360  cFillSlice.initSlice();
361#endif
362  TComPic *cFillPic;
363  xGetNewPicBuffer(&cFillSlice,cFillPic);
364#if SVC_EXTENSION
365  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder[m_layerId].getFirstSPS() );
366  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder[m_layerId].getFirstPPS() );
367  cFillPic->getSlice(0)->initSlice( m_layerId );
368#else
369  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
370  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
371  cFillPic->getSlice(0)->initSlice();
372#endif
373 
374  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
375  Int closestPoc = 1000000;
376  while ( iterPic != m_cListPic.end())
377  {
378    TComPic * rpcPic = *(iterPic++);
379    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())
380    {
381      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
382    }
383  }
384  iterPic = m_cListPic.begin();
385  while ( iterPic != m_cListPic.end())
386  {
387    TComPic *rpcPic = *(iterPic++);
388    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
389    {
390      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
391      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
392      break;
393    }
394  }
395  cFillPic->setCurrSliceIdx(0);
396  for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) 
397  {
398    cFillPic->getCU(i)->initCU(cFillPic,i);
399  }
400  cFillPic->getSlice(0)->setReferenced(true);
401  cFillPic->getSlice(0)->setPOC(iLostPoc);
402  cFillPic->setReconMark(true);
403  cFillPic->setOutputMark(true);
404  if(m_pocRandomAccess == MAX_INT)
405  {
406    m_pocRandomAccess = iLostPoc;
407  }
408}
409
410
411Void TDecTop::xActivateParameterSets()
412{
413#if SVC_EXTENSION
414  m_parameterSetManagerDecoder[m_layerId].applyPrefetchedPS();
415 
416  TComPPS *pps = m_parameterSetManagerDecoder[m_layerId].getPPS(m_apcSlicePilot->getPPSId());
417  assert (pps != 0);
418
419  TComSPS *sps = m_parameterSetManagerDecoder[m_layerId].getSPS(pps->getSPSId());
420  assert (sps != 0);
421
422  if( false == m_parameterSetManagerDecoder[m_layerId].activatePPS(m_apcSlicePilot->getPPSId(), m_apcSlicePilot->isIRAP()) )
423#else
424  m_parameterSetManagerDecoder.applyPrefetchedPS();
425 
426  TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
427  assert (pps != 0);
428
429  TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId());
430  assert (sps != 0);
431
432  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
433#endif
434  {
435    printf ("Parameter set activation failed!");
436    assert (0);
437  }
438
439  if( pps->getDependentSliceSegmentsEnabledFlag() )
440  {
441    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
442
443    if (m_cSliceDecoder.getCtxMemSize() != NumCtx)
444    {
445      m_cSliceDecoder.initCtxMem(NumCtx);
446      for ( UInt st = 0; st < NumCtx; st++ )
447      {
448        TDecSbac* ctx = NULL;
449        ctx = new TDecSbac;
450        ctx->init( &m_cBinCABAC );
451        m_cSliceDecoder.setCtxMem( ctx, st );
452      }
453    }
454  }
455
456  m_apcSlicePilot->setPPS(pps);
457  m_apcSlicePilot->setSPS(sps);
458  pps->setSPS(sps);
459  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
460  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
461
462  g_bitDepthY     = sps->getBitDepthY();
463  g_bitDepthC     = sps->getBitDepthC();
464  g_uiMaxCUWidth  = sps->getMaxCUWidth();
465  g_uiMaxCUHeight = sps->getMaxCUHeight();
466  g_uiMaxCUDepth  = sps->getMaxCUDepth();
467  g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() );
468
469  for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++)
470  {
471    sps->setAMPAcc( i, sps->getUseAMP() );
472  }
473
474  for (Int i = sps->getLog2DiffMaxMinCodingBlockSize(); i < sps->getMaxCUDepth(); i++)
475  {
476    sps->setAMPAcc( i, 0 );
477  }
478
479  m_cSAO.destroy();
480  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() );
481  m_cLoopFilter.create( sps->getMaxCUDepth() );
482}
483
484#if SVC_EXTENSION
485Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC )
486#else
487Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
488#endif
489{
490  TComPic*&   pcPic         = m_pcPic;
491#if SVC_EXTENSION
492  m_apcSlicePilot->initSlice( nalu.m_layerId );
493#else
494  m_apcSlicePilot->initSlice();
495#endif
496
497  if (m_bFirstSliceInPicture)
498  {
499    m_uiSliceIdx     = 0;
500  }
501  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
502  if (!m_bFirstSliceInPicture)
503  {
504    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
505  }
506
507  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
508  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
509                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
510                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
511                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
512                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
513  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
514 
515  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
516  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
517
518#if SVC_EXTENSION
519  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder[m_layerId]);
520#else
521  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
522#endif
523  if (m_apcSlicePilot->isNextSlice())
524    // Skip pictures due to random access
525    if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
526    {
527      return false;
528    }
529    // Skip TFD pictures associated with BLA/BLANT pictures
530    if (isSkipPictureForBLA(iPOCLastDisplay))
531    {
532      return false;
533    }
534
535  // exit when a new picture is found
536#if SVC_EXTENSION
537  bNewPOC = (m_apcSlicePilot->getPOC()!= m_prevPOC);
538  if (m_apcSlicePilot->isNextSlice() && (bNewPOC || m_layerId!=m_uiPrevLayerId) && !m_bFirstSliceInSequence )
539  {
540    m_prevPOC = m_apcSlicePilot->getPOC();
541    curLayerId = m_uiPrevLayerId; 
542    m_uiPrevLayerId = m_layerId;
543    return true;
544  }
545#else
546  //we should only get a different poc for a new picture (with CTU address==0)
547  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (!m_apcSlicePilot->getSliceCurStartCUAddr()==0))
548  {
549    printf ("Warning, the first slice of a picture might have been lost!\n");
550  }
551  // exit when a new picture is found
552  if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence )
553  {
554    if (m_prevPOC >= m_pocRandomAccess)
555    {
556      m_prevPOC = m_apcSlicePilot->getPOC();
557      return true;
558    }
559    m_prevPOC = m_apcSlicePilot->getPOC();
560  }
561#endif
562  // actual decoding starts here
563  xActivateParameterSets();
564
565  if (m_apcSlicePilot->isNextSlice()) 
566  {
567    m_prevPOC = m_apcSlicePilot->getPOC();
568#if SVC_EXTENSION
569    curLayerId = m_layerId;
570    m_uiPrevLayerId = m_layerId;
571#endif
572  }
573  m_bFirstSliceInSequence = false;
574  //detect lost reference picture and insert copy of earlier frame.
575  Int lostPoc;
576  while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
577  {
578    xCreateLostPicture(lostPoc-1);
579  }
580  if (m_bFirstSliceInPicture)
581  {
582#if AVC_BASE
583  if( m_layerId == 1 )
584  {
585    TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
586    fstream* pFile  = m_ppcTDecTop[0]->getBLReconFile();
587    const Window &conf = pBLPic->getConformanceWindow();
588#if ILP_DECODED_PICTURE
589    UInt uiWidth    = pBLPic->getPicYuvRec()->getWidth();
590    UInt uiHeight   = pBLPic->getPicYuvRec()->getHeight();
591#else
592    UInt uiWidth    = pBLPic->getPicYuvRec()->getWidth() - conf.getWindowLeftOffset() - conf.getWindowRightOffset();
593    UInt uiHeight   = pBLPic->getPicYuvRec()->getHeight() - conf.getWindowTopOffset() - conf.getWindowBottomOffset();
594#endif
595       
596    if( pFile->good() )
597    {
598      UInt64 uiPos = (UInt64) m_apcSlicePilot->getPOC() * uiWidth * uiHeight * 3 / 2;
599
600      pFile->seekg((UInt)uiPos, ios::beg );
601
602      Pel* pPel = pBLPic->getPicYuvRec()->getLumaAddr();
603      UInt uiStride = pBLPic->getPicYuvRec()->getStride();
604      for( Int i = 0; i < uiHeight; i++ )
605      {
606        for( Int j = 0; j < uiWidth; j++ )
607        {
608          pPel[j] = pFile->get();
609        }
610        pPel += uiStride;
611      }
612
613      pPel = pBLPic->getPicYuvRec()->getCbAddr();
614      uiStride = pBLPic->getPicYuvRec()->getCStride();
615      for( Int i = 0; i < uiHeight/2; i++ )
616      {
617        for( Int j = 0; j < uiWidth/2; j++ )
618        {
619          pPel[j] = pFile->get();
620        }
621        pPel += uiStride;
622      }
623
624      pPel = pBLPic->getPicYuvRec()->getCrAddr();
625      uiStride = pBLPic->getPicYuvRec()->getCStride();
626      for( Int i = 0; i < uiHeight/2; i++ )
627      {
628        for( Int j = 0; j < uiWidth/2; j++ )
629        {
630          pPel[j] = pFile->get();
631        }
632        pPel += uiStride;
633      }
634    }
635  }
636#endif
637
638    // Buffer initialize for prediction.
639    m_cPrediction.initTempBuff();
640    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
641    //  Get a new picture buffer
642    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
643
644    // transfer any SEI messages that have been received to the picture
645    pcPic->setSEIs(m_SEIs);
646    m_SEIs.clear();
647
648    // Recursive structure
649    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
650#if SVC_EXTENSION
651    m_cCuDecoder.init   ( m_ppcTDecTop,&m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction, curLayerId );
652#else
653    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
654#endif
655    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
656
657    m_cSliceDecoder.create();
658  }
659  else
660  {
661    // Check if any new SEI has arrived
662    if(!m_SEIs.empty())
663    {
664      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
665      SEIMessages &picSEI = pcPic->getSEIs();
666      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
667      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
668      deleteSEIs(m_SEIs);
669    }
670  }
671 
672  //  Set picture slice pointer
673  TComSlice*  pcSlice = m_apcSlicePilot;
674  Bool bNextSlice     = pcSlice->isNextSlice();
675
676  UInt uiCummulativeTileWidth;
677  UInt uiCummulativeTileHeight;
678  UInt i, j, p;
679
680  //set NumColumnsMins1 and NumRowsMinus1
681  pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
682  pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
683
684  //create the TComTileArray
685  pcPic->getPicSym()->xCreateTComTileArray();
686
687  if( pcSlice->getPPS()->getUniformSpacingFlag() )
688  {
689    //set the width for each tile
690    for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
691    {
692      for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
693      {
694        pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
695          setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
696          - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
697      }
698    }
699
700    //set the height for each tile
701    for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
702    {
703      for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
704      {
705        pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
706          setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
707          - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
708      }
709    }
710  }
711  else
712  {
713    //set the width for each tile
714    for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
715    {
716      uiCummulativeTileWidth = 0;
717      for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
718      {
719        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
720        uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
721      }
722      pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
723    }
724
725    //set the height for each tile
726    for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
727    {
728      uiCummulativeTileHeight = 0;
729      for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
730      { 
731        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
732        uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
733      }
734      pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
735    }
736  }
737
738  pcPic->getPicSym()->xInitTiles();
739
740  //generate the Coding Order Map and Inverse Coding Order Map
741  UInt uiEncCUAddr;
742  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
743  {
744    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
745    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
746  }
747  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
748  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
749
750  //convert the start and end CU addresses of the slice and dependent slice into encoding order
751  pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) );
752  pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) );
753  if(pcSlice->isNextSlice())
754  {
755    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
756    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
757  }
758
759  if (m_bFirstSliceInPicture) 
760  {
761    if(pcPic->getNumAllocatedSlice() != 1)
762    {
763      pcPic->clearSliceBuffer();
764    }
765  }
766  else
767  {
768    pcPic->allocateNewSlice();
769  }
770  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
771  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
772  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
773
774  pcPic->setTLayer(nalu.m_temporalId);
775
776#if SVC_EXTENSION
777  pcPic->setLayerId(nalu.m_layerId);
778  pcSlice->setLayerId(nalu.m_layerId);
779#endif
780
781  if (bNextSlice)
782  {
783    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA, m_cListPic );
784    // Set reference list
785#if REF_LIST_BUGFIX
786    if (m_layerId == 0)
787#endif
788#if FIX1071
789    pcSlice->setRefPicList( m_cListPic, true );
790#else
791    pcSlice->setRefPicList( m_cListPic );
792#endif
793
794#if SVC_EXTENSION   
795    if(m_layerId > 0)
796    {
797#if AVC_BASE
798      pcSlice->setBaseColPic ( *m_ppcTDecTop[0]->getListPic()->begin() );
799#if AVC_SYNTAX
800      TComPic* pBLPic = pcSlice->getBaseColPic();
801      if( pcSlice->getPOC() == 0 )
802      {
803        // initialize partition order.
804        UInt* piTmp = &g_auiZscanToRaster[0];
805        initZscanToRaster( pBLPic->getPicSym()->getMaxDepth() + 1, 1, 0, piTmp );
806        initRasterToZscan( pBLPic->getPicSym()->getMaxCUWidth(), pBLPic->getPicSym()->getMaxCUHeight(), pBLPic->getPicSym()->getMaxDepth() + 1 );
807      }     
808      pBLPic->getSlice( 0 )->initBaseLayerRPL( pcSlice );
809      pBLPic->readBLSyntax( m_ppcTDecTop[0]->getBLSyntaxFile(), SYNTAX_BYTES );
810#endif
811
812#else
813#if VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE
814      TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( m_layerId );
815#else
816      TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
817#endif
818      TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
819      pcSlice->setBaseColPic ( *cListPic, m_layerId );
820#endif
821#if SVC_UPSAMPLING
822      if ( pcPic->isSpatialEnhLayer())
823      {   
824        m_cPrediction.upsampleBasePic( pcPic->getFullPelBaseRec(), pcSlice->getBaseColPic()->getPicYuvRec(), pcPic->getPicYuvRec() );
825      }
826      else
827      {
828        pcPic->setFullPelBaseRec( pcSlice->getBaseColPic()->getPicYuvRec() );
829      }
830      pcSlice->setFullPelBaseRec ( pcPic->getFullPelBaseRec() );
831#endif
832    }
833#endif
834
835#if REF_IDX_FRAMEWORK
836    if(m_layerId > 0)
837    {
838      setILRPic(pcPic);
839#if REF_IDX_MFM
840      pcSlice->setRefPOCListILP(m_ppcTDecTop[m_layerId]->m_cIlpPic, pcSlice->getBaseColPic());
841#endif
842#if REF_LIST_BUGFIX
843      pcSlice->setRefPicListSvc( m_cListPic, m_cIlpPic);
844#else
845      pcSlice->addRefPicList ( m_cIlpPic, 
846                               1, 
847                               ((pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP) && 
848                                (pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA)) ? 0: -1);
849#endif
850    }
851#endif
852
853    // For generalized B
854    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
855    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
856    {
857      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
858      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
859
860      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
861      {
862        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
863      }
864    }
865    if (!pcSlice->isIntra())
866    {
867      Bool bLowDelay = true;
868      Int  iCurrPOC  = pcSlice->getPOC();
869      Int iRefIdx = 0;
870
871      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
872      {
873        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
874        {
875          bLowDelay = false;
876        }
877      }
878      if (pcSlice->isInterB())
879      {
880        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
881        {
882          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
883          {
884            bLowDelay = false;
885          }
886        }       
887      }
888
889      pcSlice->setCheckLDC(bLowDelay);           
890    }
891
892    //---------------
893    pcSlice->setRefPOCList();
894#if !L0034_COMBINED_LIST_CLEANUP
895    pcSlice->setNoBackPredFlag( false );
896    if ( pcSlice->getSliceType() == B_SLICE )
897    {
898      if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) )
899      {
900        pcSlice->setNoBackPredFlag( true );
901        for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ )
902        {
903          if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) 
904          {
905            pcSlice->setNoBackPredFlag( false );
906            break;
907          }
908        }
909      }
910    }
911#endif
912  }
913
914  pcPic->setCurrSliceIdx(m_uiSliceIdx);
915  if(pcSlice->getSPS()->getScalingListFlag())
916  {
917    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
918    if(pcSlice->getPPS()->getScalingListPresentFlag())
919    {
920      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
921    }
922    pcSlice->getScalingList()->setUseTransformSkip(pcSlice->getPPS()->getUseTransformSkip());
923    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
924    {
925      pcSlice->setDefaultScalingList();
926    }
927    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
928    m_cTrQuant.setUseScalingList(true);
929  }
930  else
931  {
932    m_cTrQuant.setFlatScalingList();
933    m_cTrQuant.setUseScalingList(false);
934  }
935
936#if SIMPLIFIED_MV_POS_SCALING
937  if (m_layerId > 0)
938  {
939    const Window &confBL = pcSlice->getBaseColPic()->getPicYuvRec()->getConformanceWindow();
940    const Window &confEL = pcPic->getPicYuvRec()->getConformanceWindow();
941
942    Int widthBL   = pcSlice->getBaseColPic()->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
943    Int heightBL  = pcSlice->getBaseColPic()->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
944
945    Int widthEL   = pcPic->getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
946    Int heightEL  = pcPic->getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
947
948    g_mvScalingFactor[m_layerId][0] = Clip3(-4096, 4095, ((widthEL  << 8) + (widthBL  >> 1)) / widthBL);
949    g_mvScalingFactor[m_layerId][1] = Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL);
950
951    g_posScalingFactor[m_layerId][0] = ((widthBL  << 16) + (widthEL  >> 1)) / widthEL;
952    g_posScalingFactor[m_layerId][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL;
953  }
954#endif
955
956  //  Decode a picture
957  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
958
959  m_bFirstSliceInPicture = false;
960  m_uiSliceIdx++;
961
962  return false;
963}
964
965Void TDecTop::xDecodeVPS()
966{
967  TComVPS* vps = new TComVPS();
968 
969  m_cEntropyDecoder.decodeVPS( vps );
970#if SVC_EXTENSION
971  m_parameterSetManagerDecoder[0].storePrefetchedVPS(vps);
972#else
973  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
974#endif
975}
976
977Void TDecTop::xDecodeSPS()
978{
979  TComSPS* sps = new TComSPS();
980#if SVC_EXTENSION
981  sps->setLayerId(m_layerId);
982#endif
983  m_cEntropyDecoder.decodeSPS( sps );
984#if SVC_EXTENSION
985  m_parameterSetManagerDecoder[m_layerId].storePrefetchedSPS(sps);
986#else
987  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
988#endif
989#if REF_IDX_FRAMEWORK
990  if(m_numLayer>0)
991  {
992    xInitILRP(sps);
993  }
994#endif
995}
996
997Void TDecTop::xDecodePPS()
998{
999  TComPPS* pps = new TComPPS();
1000  m_cEntropyDecoder.decodePPS( pps );
1001#if SVC_EXTENSION
1002  m_parameterSetManagerDecoder[m_layerId].storePrefetchedPPS( pps );
1003#else
1004  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
1005#endif
1006
1007  if( pps->getDependentSliceSegmentsEnabledFlag() )
1008  {
1009    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
1010    m_cSliceDecoder.initCtxMem(NumCtx);
1011    for ( UInt st = 0; st < NumCtx; st++ )
1012    {
1013      TDecSbac* ctx = NULL;
1014      ctx = new TDecSbac;
1015      ctx->init( &m_cBinCABAC );
1016      m_cSliceDecoder.setCtxMem( ctx, st );
1017    }
1018  }
1019}
1020
1021Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
1022{
1023#if SVC_EXTENSION
1024  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
1025  {
1026    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveSPS() );
1027  }
1028  else
1029  {
1030    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveSPS() );
1031    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
1032    if (activeParamSets.size()>0)
1033    {
1034      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
1035      m_parameterSetManagerDecoder[m_layerId].applyPrefetchedPS();
1036      assert(seiAps->activeSeqParamSetId.size()>0);
1037      if (! m_parameterSetManagerDecoder[m_layerId].activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
1038      {
1039        printf ("Warning SPS activation with Active parameter set SEI failed");
1040      }
1041    }
1042  }
1043#else
1044  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
1045  {
1046    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1047  }
1048  else
1049  {
1050    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1051    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
1052    if (activeParamSets.size()>0)
1053    {
1054      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
1055      m_parameterSetManagerDecoder.applyPrefetchedPS();
1056      assert(seiAps->activeSeqParamSetId.size()>0);
1057      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
1058      {
1059        printf ("Warning SPS activation with Active parameter set SEI failed");
1060      }
1061    }
1062  }
1063#endif
1064}
1065
1066#if SVC_EXTENSION
1067Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC)
1068#else
1069Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1070#endif
1071{
1072  // Initialize entropy decoder
1073  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1074  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
1075
1076  switch (nalu.m_nalUnitType)
1077  {
1078    case NAL_UNIT_VPS:
1079      xDecodeVPS();
1080      return false;
1081     
1082    case NAL_UNIT_SPS:
1083      xDecodeSPS();
1084#if AVC_BASE
1085      {
1086        TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
1087        if( nalu.m_layerId == 1 && pBLPic->getPicYuvRec() == NULL )
1088        {
1089          TComSPS* sps = new TComSPS();
1090          Int  numReorderPics[MAX_TLAYER];
1091          Window &conformanceWindow = sps->getConformanceWindow();
1092          Window defaultDisplayWindow = sps->getVuiParametersPresentFlag() ? sps->getVuiParameters()->getDefaultDisplayWindow() : Window();
1093#if SVC_UPSAMPLING
1094#if AVC_SYNTAX
1095
1096          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, sps, true);
1097#else
1098          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, NULL, true);
1099#endif
1100#else
1101          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), onformanceWindow, defaultDisplayWindow, numReorderPics, true);
1102#endif
1103        }
1104      }
1105#endif
1106      return false;
1107
1108    case NAL_UNIT_PPS:
1109      xDecodePPS();
1110      return false;
1111     
1112    case NAL_UNIT_PREFIX_SEI:
1113    case NAL_UNIT_SUFFIX_SEI:
1114      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
1115      return false;
1116
1117    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1118    case NAL_UNIT_CODED_SLICE_TRAIL_N:
1119    case NAL_UNIT_CODED_SLICE_TLA_R:
1120    case NAL_UNIT_CODED_SLICE_TSA_N:
1121    case NAL_UNIT_CODED_SLICE_STSA_R:
1122    case NAL_UNIT_CODED_SLICE_STSA_N:
1123    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
1124    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
1125    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1126    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
1127    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
1128    case NAL_UNIT_CODED_SLICE_CRA:
1129    case NAL_UNIT_CODED_SLICE_RADL_N:
1130    case NAL_UNIT_CODED_SLICE_RADL_R:
1131    case NAL_UNIT_CODED_SLICE_RASL_N:
1132    case NAL_UNIT_CODED_SLICE_RASL_R:
1133#if SVC_EXTENSION
1134      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, curLayerId, bNewPOC);
1135#else
1136      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1137#endif
1138      break;
1139    default:
1140      assert (1);
1141  }
1142
1143  return false;
1144}
1145
1146/** Function for checking if picture should be skipped because of association with a previous BLA picture
1147 * \param iPOCLastDisplay POC of last picture displayed
1148 * \returns true if the picture should be skipped
1149 * This function skips all TFD pictures that follow a BLA picture
1150 * in decoding order and precede it in output order.
1151 */
1152Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
1153{
1154  if (m_prevRAPisBLA && m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
1155  {
1156    iPOCLastDisplay++;
1157    return true;
1158  }
1159  return false;
1160}
1161
1162/** Function for checking if picture should be skipped because of random access
1163 * \param iSkipFrame skip frame counter
1164 * \param iPOCLastDisplay POC of last picture displayed
1165 * \returns true if the picture shold be skipped in the random access.
1166 * This function checks the skipping of pictures in the case of -s option random access.
1167 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1168 * It also checks the type of Nal unit type at the random access point.
1169 * 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.
1170 * If the random access point is IDR all pictures after the random access point are decoded.
1171 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
1172 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
1173 * access point there is no guarantee that the decoder will not crash.
1174 */
1175Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
1176{
1177  if (iSkipFrame) 
1178  {
1179    iSkipFrame--;   // decrement the counter
1180    return true;
1181  }
1182  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1183  {
1184    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
1185        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1186        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1187        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
1188    {
1189      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
1190      m_pocRandomAccess = m_apcSlicePilot->getPOC();
1191    }
1192    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
1193    {
1194      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1195    }
1196    else 
1197    {
1198      static Bool warningMessage = false;
1199      if(!warningMessage)
1200      {
1201        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1202        warningMessage = true;
1203      }
1204      return true;
1205    }
1206  }
1207  // skip the reordered pictures, if necessary
1208  else if (m_apcSlicePilot->getPOC() < m_pocRandomAccess && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
1209  {
1210    iPOCLastDisplay++;
1211    return true;
1212  }
1213  // if we reach here, then the picture is not skipped.
1214  return false; 
1215}
1216
1217#if VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE
1218TDecTop* TDecTop::getRefLayerDec( UInt layerId )
1219{
1220  TComVPS* vps = m_parameterSetManagerDecoder[0].getActiveVPS();
1221  if( vps->getNumDirectRefLayers( m_layerId ) <= 0 )
1222  {
1223    return NULL;
1224  }
1225
1226  // currently only one reference layer is supported
1227  assert( vps->getNumDirectRefLayers( m_layerId ) == 1 );
1228
1229  return (TDecTop *)getLayerDec( vps->getRefLayerId( m_layerId, 0 ) );
1230}
1231#endif
1232
1233//! \}
Note: See TracBrowser for help on using the repository browser.