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

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

decoded picture output for SYNTAX_OUTPU

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#endif //SVC_EXTENSION
854
855    // For generalized B
856    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
857    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
858    {
859      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
860      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
861
862      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
863      {
864        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
865      }
866    }
867    if (!pcSlice->isIntra())
868    {
869      Bool bLowDelay = true;
870      Int  iCurrPOC  = pcSlice->getPOC();
871      Int iRefIdx = 0;
872
873      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
874      {
875        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
876        {
877          bLowDelay = false;
878        }
879      }
880      if (pcSlice->isInterB())
881      {
882        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
883        {
884          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
885          {
886            bLowDelay = false;
887          }
888        }       
889      }
890
891      pcSlice->setCheckLDC(bLowDelay);           
892    }
893
894    //---------------
895    pcSlice->setRefPOCList();
896#if !L0034_COMBINED_LIST_CLEANUP
897    pcSlice->setNoBackPredFlag( false );
898    if ( pcSlice->getSliceType() == B_SLICE )
899    {
900      if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) )
901      {
902        pcSlice->setNoBackPredFlag( true );
903        for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ )
904        {
905          if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) 
906          {
907            pcSlice->setNoBackPredFlag( false );
908            break;
909          }
910        }
911      }
912    }
913#endif
914  }
915
916  pcPic->setCurrSliceIdx(m_uiSliceIdx);
917  if(pcSlice->getSPS()->getScalingListFlag())
918  {
919    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
920    if(pcSlice->getPPS()->getScalingListPresentFlag())
921    {
922      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
923    }
924    pcSlice->getScalingList()->setUseTransformSkip(pcSlice->getPPS()->getUseTransformSkip());
925    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
926    {
927      pcSlice->setDefaultScalingList();
928    }
929    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
930    m_cTrQuant.setUseScalingList(true);
931  }
932  else
933  {
934    m_cTrQuant.setFlatScalingList();
935    m_cTrQuant.setUseScalingList(false);
936  }
937
938#if SIMPLIFIED_MV_POS_SCALING
939  if (m_layerId > 0)
940  {
941    const Window &confBL = pcSlice->getBaseColPic()->getPicYuvRec()->getConformanceWindow();
942    const Window &confEL = pcPic->getPicYuvRec()->getConformanceWindow();
943
944    Int widthBL   = pcSlice->getBaseColPic()->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
945    Int heightBL  = pcSlice->getBaseColPic()->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
946
947    Int widthEL   = pcPic->getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
948    Int heightEL  = pcPic->getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
949
950    g_mvScalingFactor[m_layerId][0] = Clip3(-4096, 4095, ((widthEL  << 8) + (widthBL  >> 1)) / widthBL);
951    g_mvScalingFactor[m_layerId][1] = Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL);
952
953    g_posScalingFactor[m_layerId][0] = ((widthBL  << 16) + (widthEL  >> 1)) / widthEL;
954    g_posScalingFactor[m_layerId][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL;
955  }
956#endif
957
958  //  Decode a picture
959  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
960
961  m_bFirstSliceInPicture = false;
962  m_uiSliceIdx++;
963
964  return false;
965}
966
967Void TDecTop::xDecodeVPS()
968{
969  TComVPS* vps = new TComVPS();
970 
971  m_cEntropyDecoder.decodeVPS( vps );
972#if SVC_EXTENSION
973  m_parameterSetManagerDecoder[0].storePrefetchedVPS(vps);
974#else
975  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
976#endif
977}
978
979Void TDecTop::xDecodeSPS()
980{
981  TComSPS* sps = new TComSPS();
982#if SVC_EXTENSION
983  sps->setLayerId(m_layerId);
984#endif
985  m_cEntropyDecoder.decodeSPS( sps );
986#if SVC_EXTENSION
987  m_parameterSetManagerDecoder[m_layerId].storePrefetchedSPS(sps);
988#else
989  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
990#endif
991#if REF_IDX_FRAMEWORK
992  if(m_numLayer>0)
993  {
994    xInitILRP(sps);
995  }
996#endif
997}
998
999Void TDecTop::xDecodePPS()
1000{
1001  TComPPS* pps = new TComPPS();
1002  m_cEntropyDecoder.decodePPS( pps );
1003#if SVC_EXTENSION
1004  m_parameterSetManagerDecoder[m_layerId].storePrefetchedPPS( pps );
1005#else
1006  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
1007#endif
1008
1009  if( pps->getDependentSliceSegmentsEnabledFlag() )
1010  {
1011    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
1012    m_cSliceDecoder.initCtxMem(NumCtx);
1013    for ( UInt st = 0; st < NumCtx; st++ )
1014    {
1015      TDecSbac* ctx = NULL;
1016      ctx = new TDecSbac;
1017      ctx->init( &m_cBinCABAC );
1018      m_cSliceDecoder.setCtxMem( ctx, st );
1019    }
1020  }
1021}
1022
1023Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
1024{
1025#if SVC_EXTENSION
1026  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
1027  {
1028    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveSPS() );
1029  }
1030  else
1031  {
1032    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveSPS() );
1033    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
1034    if (activeParamSets.size()>0)
1035    {
1036      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
1037      m_parameterSetManagerDecoder[m_layerId].applyPrefetchedPS();
1038      assert(seiAps->activeSeqParamSetId.size()>0);
1039      if (! m_parameterSetManagerDecoder[m_layerId].activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
1040      {
1041        printf ("Warning SPS activation with Active parameter set SEI failed");
1042      }
1043    }
1044  }
1045#else
1046  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
1047  {
1048    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1049  }
1050  else
1051  {
1052    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1053    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
1054    if (activeParamSets.size()>0)
1055    {
1056      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
1057      m_parameterSetManagerDecoder.applyPrefetchedPS();
1058      assert(seiAps->activeSeqParamSetId.size()>0);
1059      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
1060      {
1061        printf ("Warning SPS activation with Active parameter set SEI failed");
1062      }
1063    }
1064  }
1065#endif
1066}
1067
1068#if SVC_EXTENSION
1069Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC)
1070#else
1071Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1072#endif
1073{
1074  // Initialize entropy decoder
1075  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1076  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
1077
1078  switch (nalu.m_nalUnitType)
1079  {
1080    case NAL_UNIT_VPS:
1081      xDecodeVPS();
1082      return false;
1083     
1084    case NAL_UNIT_SPS:
1085      xDecodeSPS();
1086#if AVC_BASE
1087      {
1088        TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
1089        if( nalu.m_layerId == 1 && pBLPic->getPicYuvRec() == NULL )
1090        {
1091          TComSPS* sps = new TComSPS();
1092          Int  numReorderPics[MAX_TLAYER];
1093          Window &conformanceWindow = sps->getConformanceWindow();
1094          Window defaultDisplayWindow = sps->getVuiParametersPresentFlag() ? sps->getVuiParameters()->getDefaultDisplayWindow() : Window();
1095#if SVC_UPSAMPLING
1096#if AVC_SYNTAX
1097
1098          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, sps, true);
1099#else
1100          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, NULL, true);
1101#endif
1102#else
1103          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), onformanceWindow, defaultDisplayWindow, numReorderPics, true);
1104#endif
1105        }
1106      }
1107#endif
1108      return false;
1109
1110    case NAL_UNIT_PPS:
1111      xDecodePPS();
1112      return false;
1113     
1114    case NAL_UNIT_PREFIX_SEI:
1115    case NAL_UNIT_SUFFIX_SEI:
1116      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
1117      return false;
1118
1119    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1120    case NAL_UNIT_CODED_SLICE_TRAIL_N:
1121    case NAL_UNIT_CODED_SLICE_TLA_R:
1122    case NAL_UNIT_CODED_SLICE_TSA_N:
1123    case NAL_UNIT_CODED_SLICE_STSA_R:
1124    case NAL_UNIT_CODED_SLICE_STSA_N:
1125    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
1126    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
1127    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1128    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
1129    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
1130    case NAL_UNIT_CODED_SLICE_CRA:
1131    case NAL_UNIT_CODED_SLICE_RADL_N:
1132    case NAL_UNIT_CODED_SLICE_RADL_R:
1133    case NAL_UNIT_CODED_SLICE_RASL_N:
1134    case NAL_UNIT_CODED_SLICE_RASL_R:
1135#if SVC_EXTENSION
1136      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, curLayerId, bNewPOC);
1137#else
1138      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1139#endif
1140      break;
1141    default:
1142      assert (1);
1143  }
1144
1145  return false;
1146}
1147
1148/** Function for checking if picture should be skipped because of association with a previous BLA picture
1149 * \param iPOCLastDisplay POC of last picture displayed
1150 * \returns true if the picture should be skipped
1151 * This function skips all TFD pictures that follow a BLA picture
1152 * in decoding order and precede it in output order.
1153 */
1154Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
1155{
1156  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))
1157  {
1158    iPOCLastDisplay++;
1159    return true;
1160  }
1161  return false;
1162}
1163
1164/** Function for checking if picture should be skipped because of random access
1165 * \param iSkipFrame skip frame counter
1166 * \param iPOCLastDisplay POC of last picture displayed
1167 * \returns true if the picture shold be skipped in the random access.
1168 * This function checks the skipping of pictures in the case of -s option random access.
1169 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1170 * It also checks the type of Nal unit type at the random access point.
1171 * 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.
1172 * If the random access point is IDR all pictures after the random access point are decoded.
1173 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
1174 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
1175 * access point there is no guarantee that the decoder will not crash.
1176 */
1177Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
1178{
1179  if (iSkipFrame) 
1180  {
1181    iSkipFrame--;   // decrement the counter
1182    return true;
1183  }
1184  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1185  {
1186    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
1187        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1188        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1189        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
1190    {
1191      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
1192      m_pocRandomAccess = m_apcSlicePilot->getPOC();
1193    }
1194    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
1195    {
1196      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1197    }
1198    else 
1199    {
1200      static Bool warningMessage = false;
1201      if(!warningMessage)
1202      {
1203        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1204        warningMessage = true;
1205      }
1206      return true;
1207    }
1208  }
1209  // skip the reordered pictures, if necessary
1210  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))
1211  {
1212    iPOCLastDisplay++;
1213    return true;
1214  }
1215  // if we reach here, then the picture is not skipped.
1216  return false; 
1217}
1218
1219#if VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE
1220TDecTop* TDecTop::getRefLayerDec( UInt layerId )
1221{
1222  TComVPS* vps = m_parameterSetManagerDecoder[0].getActiveVPS();
1223  if( vps->getNumDirectRefLayers( m_layerId ) <= 0 )
1224  {
1225    return NULL;
1226  }
1227
1228  // currently only one reference layer is supported
1229  assert( vps->getNumDirectRefLayers( m_layerId ) == 1 );
1230
1231  return (TDecTop *)getLayerDec( vps->getRefLayerId( m_layerId, 0 ) );
1232}
1233#endif
1234
1235//! \}
Note: See TracBrowser for help on using the repository browser.