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

Last change on this file since 354 was 345, checked in by seregin, 11 years ago

merge SHM-3.0-dev branch

  • Property svn:eol-style set to native
File size: 48.9 KB
RevLine 
[313]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]->destroy();
116      delete m_cIlpPic[i];
117      m_cIlpPic[i] = NULL;
118    }
119  }   
120#endif
121}
122
123Void TDecTop::init()
124{
125#if !SVC_EXTENSION
126  // initialize ROM
127  initROM();
128#endif
129#if SVC_EXTENSION
130  m_cGopDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
131  m_cSliceDecoder.init( m_ppcTDecTop, &m_cEntropyDecoder, &m_cCuDecoder );
132#else
133  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
134  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
135#endif
136  m_cEntropyDecoder.init(&m_cPrediction);
137}
138
139#if REF_IDX_FRAMEWORK
140Void TDecTop::xInitILRP(TComSPS *pcSPS)
141{
142  if(m_layerId>0)
143  {
144    g_bitDepthY     = pcSPS->getBitDepthY();
145    g_bitDepthC     = pcSPS->getBitDepthC();
146    g_uiMaxCUWidth  = pcSPS->getMaxCUWidth();
147    g_uiMaxCUHeight = pcSPS->getMaxCUHeight();
148    g_uiMaxCUDepth  = pcSPS->getMaxCUDepth();
149    g_uiAddCUDepth  = max (0, pcSPS->getLog2MinCodingBlockSize() - (Int)pcSPS->getQuadtreeTULog2MinSize() );
150
151    Int  numReorderPics[MAX_TLAYER];
152    Window &conformanceWindow = pcSPS->getConformanceWindow();
153    Window defaultDisplayWindow = pcSPS->getVuiParametersPresentFlag() ? pcSPS->getVuiParameters()->getDefaultDisplayWindow() : Window();
154
155    for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
156    {
157      numReorderPics[temporalLayer] = pcSPS->getNumReorderPics(temporalLayer);
158    }
159
160    if (m_cIlpPic[0] == NULL)
161    {
162      for (Int j=0; j < MAX_LAYERS /*MAX_NUM_REF*/; j++)  // consider to set to NumDirectRefLayers[LayerIdInVps[nuh_layer_id]]
163      {
164
165        m_cIlpPic[j] = new  TComPic;
166#if SVC_UPSAMPLING
167        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, pcSPS, true);
168#else
169        m_cIlpPic[j]->create(pcSPS->getPicWidthInLumaSamples(), pcSPS->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
170#endif
171        for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++)
172        {
173          m_cIlpPic[j]->getPicSym()->getCU(i)->initCU(m_cIlpPic[j], i);
174        }
175      }
176    }
177  }
178}
179
180Void TDecTop::setILRPic(TComPic *pcPic)
181{
182  for( Int i = 0; i < pcPic->getSlice(0)->getActiveNumILRRefIdx(); i++ )
183  {
184    Int refLayerIdc = pcPic->getSlice(0)->getInterLayerPredLayerIdc(i);
185
186    if(m_cIlpPic[refLayerIdc])
187    {
188      m_cIlpPic[refLayerIdc]->copyUpsampledPictureYuv(pcPic->getFullPelBaseRec(refLayerIdc), m_cIlpPic[refLayerIdc]->getPicYuvRec());
189      m_cIlpPic[refLayerIdc]->getSlice(0)->setPOC(pcPic->getPOC());
190      m_cIlpPic[refLayerIdc]->setLayerId(pcPic->getSlice(0)->getBaseColPic(refLayerIdc)->getLayerId()); //set reference layerId
191      m_cIlpPic[refLayerIdc]->getPicYuvRec()->setBorderExtension(false);
192      m_cIlpPic[refLayerIdc]->getPicYuvRec()->extendPicBorder();
193    }
194  }
195}
196#endif
197
198Void TDecTop::deletePicBuffer ( )
199{
200  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
201  Int iSize = Int( m_cListPic.size() );
202 
203  for (Int i = 0; i < iSize; i++ )
204  {
205    TComPic* pcPic = *(iterPic++);
206#if SVC_EXTENSION
207    if( pcPic )
208    {
209      pcPic->destroy();
210
211      delete pcPic;
212      pcPic = NULL;
213    }
214#else
215    pcPic->destroy();
216   
217    delete pcPic;
218    pcPic = NULL;
219#endif
220  }
221 
222  m_cSAO.destroy();
223 
224  m_cLoopFilter.        destroy();
225 
226#if !SVC_EXTENSION
227  // destroy ROM
228  destroyROM();
229#endif
230}
231
232Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
233{
234  Int  numReorderPics[MAX_TLAYER];
235  Window &conformanceWindow = pcSlice->getSPS()->getConformanceWindow();
236  Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window();
237
238  for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
239  {
240    numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer);
241  }
242
243  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
[345]244
245#if SVC_EXTENSION
246  m_iMaxRefPicNum += 1; // it should be updated if more than 1 resampling picture is used
247#endif
248
[313]249  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
250  {
251    rpcPic = new TComPic();
252
253#if SVC_EXTENSION //Temporal solution, should be modified
254    if(m_layerId > 0)
255    {
256      for(UInt i = 0; i < pcSlice->getVPS()->getNumDirectRefLayers( m_layerId ); i++ )
257      {
258        const Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(i);
259        Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
260
261#if VPS_EXTN_DIRECT_REF_LAYERS
262        TDecTop *pcTDecTopBase = (TDecTop *)getRefLayerDec( i );
263#else
264        TDecTop *pcTDecTopBase = (TDecTop *)getLayerDec( m_layerId-1 );
265#endif
266        //TComPic*                      pcPic = *(pcTDecTopBase->getListPic()->begin());
267        TComPicYuv* pcPicYuvRecBase = (*(pcTDecTopBase->getListPic()->begin()))->getPicYuvRec(); 
268        if(pcPicYuvRecBase->getWidth() != pcSlice->getSPS()->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getSPS()->getPicHeightInLumaSamples() || !zeroOffsets )
269        {
270          rpcPic->setSpatialEnhLayerFlag( i, true );
271
272          //only for scalable extension
273          assert( pcSlice->getVPS()->getScalabilityMask(1) == true );
274        }
275#if MAX_ONE_RESAMPLING_DIRECT_LAYERS
276        if(pcSlice->getVPS()->getScalabilityMask(1))
277        {
278          pcSlice->setPic(rpcPic);
279        }
280#endif
281      }
282    }
283#endif
284   
285#if SVC_UPSAMPLING
286    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
287                     conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
288#else
289    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
290                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
291#endif
292    rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
293    m_cListPic.pushBack( rpcPic );
294   
295    return;
296  }
297 
298  Bool bBufferIsAvailable = false;
299  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
300  while (iterPic != m_cListPic.end())
301  {
302    rpcPic = *(iterPic++);
303    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
304    {
305      rpcPic->setOutputMark(false);
306      bBufferIsAvailable = true;
307      break;
308    }
309
310    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
311    {
312#if !SVC_EXTENSION
313      rpcPic->setOutputMark(false);
314#endif
315      rpcPic->setReconMark( false );
316      rpcPic->getPicYuvRec()->setBorderExtension( false );
317      bBufferIsAvailable = true;
318      break;
319    }
320  }
321 
322  if ( !bBufferIsAvailable )
323  {
324    //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer.
325    m_iMaxRefPicNum++;
326    rpcPic = new TComPic();
327    m_cListPic.pushBack( rpcPic );
328  }
329  rpcPic->destroy();
330
331#if SVC_UPSAMPLING
332  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
333                   conformanceWindow, defaultDisplayWindow, numReorderPics, pcSlice->getSPS(), true);
334
335#else
336  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
337                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
338#endif
339  rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
340}
341
342Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic)
343{
344  if (!m_pcPic)
345  {
346    /* nothing to deblock */
347    return;
348  }
349 
350  TComPic*&   pcPic         = m_pcPic;
351
352  // Execute Deblock + Cleanup
353
354  m_cGopDecoder.filterPicture(pcPic);
355
356#if SYNTAX_OUTPUT
357  pcPic->wrireBLSyntax( getBLSyntaxFile(), SYNTAX_BYTES );
358#endif
359  TComSlice::sortPicList( m_cListPic ); // sorting for application output
360  poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
361  rpcListPic          = &m_cListPic; 
362  m_cCuDecoder.destroy();       
363  m_bFirstSliceInPicture  = true;
364
365  return;
366}
367
368Void TDecTop::xCreateLostPicture(Int iLostPoc) 
369{
370  printf("\ninserting lost poc : %d\n",iLostPoc);
371  TComSlice cFillSlice;
372#if SVC_EXTENSION
373  cFillSlice.setSPS( m_parameterSetManagerDecoder[m_layerId].getFirstSPS() );
374  cFillSlice.setPPS( m_parameterSetManagerDecoder[m_layerId].getFirstPPS() );
375  cFillSlice.setVPS( m_parameterSetManagerDecoder[m_layerId].getFirstVPS() );
376  cFillSlice.initSlice( m_layerId );
377#else
378  cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
379  cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
380  cFillSlice.initSlice();
381#endif
382  TComPic *cFillPic;
383  xGetNewPicBuffer(&cFillSlice,cFillPic);
384#if SVC_EXTENSION
385  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder[m_layerId].getFirstSPS() );
386  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder[m_layerId].getFirstPPS() );
387  cFillPic->getSlice(0)->setVPS( m_parameterSetManagerDecoder[m_layerId].getFirstVPS() );
388  cFillPic->getSlice(0)->initSlice( m_layerId );
389#else
390  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
391  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
392  cFillPic->getSlice(0)->initSlice();
393#endif
394 
395  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
396  Int closestPoc = 1000000;
397  while ( iterPic != m_cListPic.end())
398  {
399    TComPic * rpcPic = *(iterPic++);
400    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())
401    {
402      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
403    }
404  }
405  iterPic = m_cListPic.begin();
406  while ( iterPic != m_cListPic.end())
407  {
408    TComPic *rpcPic = *(iterPic++);
409    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
410    {
411      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
412      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
413      break;
414    }
415  }
416  cFillPic->setCurrSliceIdx(0);
417  for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) 
418  {
419    cFillPic->getCU(i)->initCU(cFillPic,i);
420  }
421  cFillPic->getSlice(0)->setReferenced(true);
422  cFillPic->getSlice(0)->setPOC(iLostPoc);
423  cFillPic->setReconMark(true);
424  cFillPic->setOutputMark(true);
425  if(m_pocRandomAccess == MAX_INT)
426  {
427    m_pocRandomAccess = iLostPoc;
428  }
429}
430
431
432Void TDecTop::xActivateParameterSets()
433{
434#if SVC_EXTENSION
435  m_parameterSetManagerDecoder[m_layerId].applyPrefetchedPS();
436 
437  TComPPS *pps = m_parameterSetManagerDecoder[m_layerId].getPPS(m_apcSlicePilot->getPPSId());
438  assert (pps != 0);
439
440  TComSPS *sps = m_parameterSetManagerDecoder[m_layerId].getSPS(pps->getSPSId());
441  assert (sps != 0);
442
443  if( false == m_parameterSetManagerDecoder[m_layerId].activatePPS(m_apcSlicePilot->getPPSId(), m_apcSlicePilot->isIRAP()) )
444#else
445  m_parameterSetManagerDecoder.applyPrefetchedPS();
446 
447  TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
448  assert (pps != 0);
449
450  TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId());
451  assert (sps != 0);
452
453  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
454#endif
455  {
456    printf ("Parameter set activation failed!");
457    assert (0);
458  }
459
460  if( pps->getDependentSliceSegmentsEnabledFlag() )
461  {
462    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
463
464    if (m_cSliceDecoder.getCtxMemSize() != NumCtx)
465    {
466      m_cSliceDecoder.initCtxMem(NumCtx);
467      for ( UInt st = 0; st < NumCtx; st++ )
468      {
469        TDecSbac* ctx = NULL;
470        ctx = new TDecSbac;
471        ctx->init( &m_cBinCABAC );
472        m_cSliceDecoder.setCtxMem( ctx, st );
473      }
474    }
475  }
476
477  m_apcSlicePilot->setPPS(pps);
478  m_apcSlicePilot->setSPS(sps);
479  pps->setSPS(sps);
480  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
481  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
482
483  g_bitDepthY     = sps->getBitDepthY();
484  g_bitDepthC     = sps->getBitDepthC();
485  g_uiMaxCUWidth  = sps->getMaxCUWidth();
486  g_uiMaxCUHeight = sps->getMaxCUHeight();
487  g_uiMaxCUDepth  = sps->getMaxCUDepth();
488  g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() );
489
490  for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++)
491  {
492    sps->setAMPAcc( i, sps->getUseAMP() );
493  }
494
495  for (Int i = sps->getLog2DiffMaxMinCodingBlockSize(); i < sps->getMaxCUDepth(); i++)
496  {
497    sps->setAMPAcc( i, 0 );
498  }
499
500  m_cSAO.destroy();
501  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() );
502  m_cLoopFilter.create( sps->getMaxCUDepth() );
503}
504
505#if SVC_EXTENSION
506Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC )
507#else
508Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
509#endif
510{
511  TComPic*&   pcPic         = m_pcPic;
512#if SVC_EXTENSION
513  m_apcSlicePilot->setVPS( m_parameterSetManagerDecoder[m_layerId].getPrefetchedVPS(0) );
514  m_apcSlicePilot->initSlice( nalu.m_layerId );
515#else
516  m_apcSlicePilot->initSlice();
517#endif
518
519  if (m_bFirstSliceInPicture)
520  {
521    m_uiSliceIdx     = 0;
522  }
523  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
524  if (!m_bFirstSliceInPicture)
525  {
526    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
527  }
528
529  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
530  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
531                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
532                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
533                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
534                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
535  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
536 
537  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
538  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
539
540#if VPS_EXTN_DIRECT_REF_LAYERS && M0457_PREDICTION_INDICATIONS
541  setRefLayerParams(m_apcSlicePilot->getVPS());
542#endif
543#if REF_IDX_FRAMEWORK && M0457_COL_PICTURE_SIGNALING
544  m_apcSlicePilot->setNumMotionPredRefLayers(m_numMotionPredRefLayers);
545#endif
546
547#if SVC_EXTENSION
548#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
549  m_apcSlicePilot->setNumSamplePredRefLayers( getNumSamplePredRefLayers() );
550#endif
551  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder[m_layerId]);
552#else
553  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
554#endif
555
556  // Skip pictures due to random access
557  if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
558  {
559    return false;
560  }
561  // Skip TFD pictures associated with BLA/BLANT pictures
562  if (isSkipPictureForBLA(iPOCLastDisplay))
563  {
564    return false;
565  }
566
567  // exit when a new picture is found
568#if SVC_EXTENSION
569  bNewPOC = (m_apcSlicePilot->getPOC()!= m_prevPOC);
570  if (m_apcSlicePilot->isNextSlice() && (bNewPOC || m_layerId!=m_uiPrevLayerId) && !m_bFirstSliceInSequence )
571  {
572    m_prevPOC = m_apcSlicePilot->getPOC();
573    curLayerId = m_uiPrevLayerId; 
574    m_uiPrevLayerId = m_layerId;
575    return true;
576  }
577#else
578  //we should only get a different poc for a new picture (with CTU address==0)
579  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (!m_apcSlicePilot->getSliceCurStartCUAddr()==0))
580  {
581    printf ("Warning, the first slice of a picture might have been lost!\n");
582  }
583  // exit when a new picture is found
584  if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence )
585  {
586    if (m_prevPOC >= m_pocRandomAccess)
587    {
588      m_prevPOC = m_apcSlicePilot->getPOC();
589      return true;
590    }
591    m_prevPOC = m_apcSlicePilot->getPOC();
592  }
593#endif
594  // actual decoding starts here
595  xActivateParameterSets();
596
597  if (m_apcSlicePilot->isNextSlice()) 
598  {
599    m_prevPOC = m_apcSlicePilot->getPOC();
600#if SVC_EXTENSION
601    curLayerId = m_layerId;
602    m_uiPrevLayerId = m_layerId;
603#endif
604  }
605  m_bFirstSliceInSequence = false;
606  //detect lost reference picture and insert copy of earlier frame.
607  Int lostPoc;
608  while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
609  {
610    xCreateLostPicture(lostPoc-1);
611  }
612  if (m_bFirstSliceInPicture)
613  {
614#if AVC_BASE
615    if( m_layerId == 1 && m_parameterSetManagerDecoder[0].getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
616    {
617      TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
618      fstream* pFile  = m_ppcTDecTop[0]->getBLReconFile();
619#if ILP_DECODED_PICTURE
620      UInt uiWidth    = pBLPic->getPicYuvRec()->getWidth();
621      UInt uiHeight   = pBLPic->getPicYuvRec()->getHeight();
622#else
623      const Window &conf = pBLPic->getConformanceWindow();
624      UInt uiWidth    = pBLPic->getPicYuvRec()->getWidth() - conf.getWindowLeftOffset() - conf.getWindowRightOffset();
625      UInt uiHeight   = pBLPic->getPicYuvRec()->getHeight() - conf.getWindowTopOffset() - conf.getWindowBottomOffset();
626#endif
627
628      if( pFile->good() )
629      {
630        UInt64 uiPos = (UInt64) m_apcSlicePilot->getPOC() * uiWidth * uiHeight * 3 / 2;
631
632        pFile->seekg((UInt)uiPos, ios::beg );
633
634        Pel* pPel = pBLPic->getPicYuvRec()->getLumaAddr();
635        UInt uiStride = pBLPic->getPicYuvRec()->getStride();
636        for( Int i = 0; i < uiHeight; i++ )
637        {
638          for( Int j = 0; j < uiWidth; j++ )
639          {
640            pPel[j] = pFile->get();
641          }
642          pPel += uiStride;
643        }
644
645        pPel = pBLPic->getPicYuvRec()->getCbAddr();
646        uiStride = pBLPic->getPicYuvRec()->getCStride();
647        for( Int i = 0; i < uiHeight/2; i++ )
648        {
649          for( Int j = 0; j < uiWidth/2; j++ )
650          {
651            pPel[j] = pFile->get();
652          }
653          pPel += uiStride;
654        }
655
656        pPel = pBLPic->getPicYuvRec()->getCrAddr();
657        uiStride = pBLPic->getPicYuvRec()->getCStride();
658        for( Int i = 0; i < uiHeight/2; i++ )
659        {
660          for( Int j = 0; j < uiWidth/2; j++ )
661          {
662            pPel[j] = pFile->get();
663          }
664          pPel += uiStride;
665        }
666      }
667    }
668#endif
669
670    // Buffer initialize for prediction.
671    m_cPrediction.initTempBuff();
672    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
673    //  Get a new picture buffer
674    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
675
676    // transfer any SEI messages that have been received to the picture
677    pcPic->setSEIs(m_SEIs);
678    m_SEIs.clear();
679
680    // Recursive structure
681    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
682#if SVC_EXTENSION
683    m_cCuDecoder.init   ( m_ppcTDecTop,&m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction, curLayerId );
684#else
685    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
686#endif
687    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
688
689    m_cSliceDecoder.create();
690  }
691  else
692  {
693    // Check if any new SEI has arrived
694    if(!m_SEIs.empty())
695    {
696      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
697      SEIMessages &picSEI = pcPic->getSEIs();
698      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
699      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
700      deleteSEIs(m_SEIs);
701    }
702  }
703 
704  //  Set picture slice pointer
705  TComSlice*  pcSlice = m_apcSlicePilot;
706  Bool bNextSlice     = pcSlice->isNextSlice();
707
708  UInt uiCummulativeTileWidth;
709  UInt uiCummulativeTileHeight;
710  UInt i, j, p;
711
712  //set NumColumnsMins1 and NumRowsMinus1
713  pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
714  pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
715
716  //create the TComTileArray
717  pcPic->getPicSym()->xCreateTComTileArray();
718
719  if( pcSlice->getPPS()->getUniformSpacingFlag() )
720  {
721    //set the width for each tile
722    for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
723    {
724      for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
725      {
726        pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
727          setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
728          - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
729      }
730    }
731
732    //set the height for each tile
733    for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
734    {
735      for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
736      {
737        pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
738          setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
739          - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
740      }
741    }
742  }
743  else
744  {
745    //set the width for each tile
746    for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
747    {
748      uiCummulativeTileWidth = 0;
749      for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
750      {
751        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
752        uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
753      }
754      pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
755    }
756
757    //set the height for each tile
758    for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
759    {
760      uiCummulativeTileHeight = 0;
761      for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
762      { 
763        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
764        uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
765      }
766      pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
767    }
768  }
769
770  pcPic->getPicSym()->xInitTiles();
771
772  //generate the Coding Order Map and Inverse Coding Order Map
773  UInt uiEncCUAddr;
774  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
775  {
776    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
777    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
778  }
779  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
780  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
781
782  //convert the start and end CU addresses of the slice and dependent slice into encoding order
783  pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) );
784  pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) );
785  if(pcSlice->isNextSlice())
786  {
787    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
788    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
789  }
790
791  if (m_bFirstSliceInPicture) 
792  {
793    if(pcPic->getNumAllocatedSlice() != 1)
794    {
795      pcPic->clearSliceBuffer();
796    }
797  }
798  else
799  {
800    pcPic->allocateNewSlice();
801  }
802  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
803  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
804  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
805
806  pcPic->setTLayer(nalu.m_temporalId);
807
808#if SVC_EXTENSION
809  pcPic->setLayerId(nalu.m_layerId);
810  pcSlice->setLayerId(nalu.m_layerId);
811#endif
812
813  if (bNextSlice)
814  {
815    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA, m_cListPic );
816    // Set reference list
817#if REF_IDX_FRAMEWORK
818    if (m_layerId == 0)
819#endif
820#if FIX1071
821    pcSlice->setRefPicList( m_cListPic, true );
822#else
823    pcSlice->setRefPicList( m_cListPic );
824#endif
825
826#if SVC_EXTENSION   
827    if(m_layerId > 0)
828    {
829      for( i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
830      {
831        UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
832#if AVC_BASE
833        if( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) == 0 && m_parameterSetManagerDecoder[0].getActiveVPS()->getAvcBaseLayerFlag() )
834        {
835          pcSlice->setBaseColPic ( refLayerIdc, *m_ppcTDecTop[0]->getListPic()->begin() );
836#if AVC_SYNTAX
837          TComPic* pBLPic = pcSlice->getBaseColPic(refLayerIdc);
838          if( pcSlice->getPOC() == 0 )
839          {
840            // initialize partition order.
841            UInt* piTmp = &g_auiZscanToRaster[0];
842            initZscanToRaster( pBLPic->getPicSym()->getMaxDepth() + 1, 1, 0, piTmp );
843            initRasterToZscan( pBLPic->getPicSym()->getMaxCUWidth(), pBLPic->getPicSym()->getMaxCUHeight(), pBLPic->getPicSym()->getMaxDepth() + 1 );
844          }     
845          pBLPic->getSlice( 0 )->initBaseLayerRPL( pcSlice );
846          pBLPic->readBLSyntax( m_ppcTDecTop[0]->getBLSyntaxFile(), SYNTAX_BYTES );
847#endif
848        }
849        else
850        {
851#if VPS_EXTN_DIRECT_REF_LAYERS
852          TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
853#else
854          TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
855#endif
856          TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
857          pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
858        }
859#else
860#if VPS_EXTN_DIRECT_REF_LAYERS
861        TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
862#else
863        TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
864#endif
865        TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
866        pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
867#endif
868
869#if SIMPLIFIED_MV_POS_SCALING
870#if SCALED_REF_LAYER_OFFSETS
871        const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
872
873        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth();
874        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight();
875
876        Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
877        Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
878#else
879        const Window &confBL = pcSlice->getBaseColPic()->getPicYuvRec()->getConformanceWindow();
880        const Window &confEL = pcPic->getPicYuvRec()->getConformanceWindow();
881
882        Int widthBL   = pcSlice->getBaseColPic()->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
883        Int heightBL  = pcSlice->getBaseColPic()->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
884
885        Int widthEL   = pcPic->getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
886        Int heightEL  = pcPic->getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
887#endif
888        g_mvScalingFactor[refLayerIdc][0] = widthEL  == widthBL  ? 4096 : Clip3(-4096, 4095, ((widthEL  << 8) + (widthBL  >> 1)) / widthBL);
889        g_mvScalingFactor[refLayerIdc][1] = heightEL == heightBL ? 4096 : Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL);
890
891        g_posScalingFactor[refLayerIdc][0] = ((widthBL  << 16) + (widthEL  >> 1)) / widthEL;
892        g_posScalingFactor[refLayerIdc][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL;
893#endif
894
895#if SVC_UPSAMPLING
896        if( pcPic->isSpatialEnhLayer(refLayerIdc) )
897        {   
898#if SCALED_REF_LAYER_OFFSETS
899          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc) );
900#else
901          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec() );
902#endif
903        }
904        else
905        {
906          pcPic->setFullPelBaseRec( refLayerIdc, pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec() );
907        }
908        pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) );
909#endif
910      }
911    }
912
913#if REF_IDX_FRAMEWORK
914    if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
915    {
916      setILRPic(pcPic);
917#if REF_IDX_MFM
918#if M0457_COL_PICTURE_SIGNALING
919      if( pcSlice->getMFMEnabledFlag() )
920#else
921      if( pcSlice->getSPS()->getMFMEnabledFlag() )
922#endif
923      {
924        pcSlice->setRefPOCListILP(m_ppcTDecTop[m_layerId]->m_cIlpPic, pcSlice->getBaseColPic());
[345]925#if M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING
[313]926        pcSlice->setMotionPredIlp(getMotionPredIlp(pcSlice));
927#endif
928      }
929#endif
930      pcSlice->setRefPicList( m_cListPic, false, m_cIlpPic);
931    }
932#if M0040_ADAPTIVE_RESOLUTION_CHANGE
933    else if ( m_layerId > 0 )
934    {
935      pcSlice->setRefPicList( m_cListPic, false, NULL);
936    }
937#endif
938#endif
939
940#endif //SVC_EXTENSION
941
942    // For generalized B
943    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
944    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
945    {
946      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
947      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
948
949      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
950      {
951        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
952      }
953    }
954    if (!pcSlice->isIntra())
955    {
956      Bool bLowDelay = true;
957      Int  iCurrPOC  = pcSlice->getPOC();
958      Int iRefIdx = 0;
959
960      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
961      {
962        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
963        {
964          bLowDelay = false;
965        }
966      }
967      if (pcSlice->isInterB())
968      {
969        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
970        {
971          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
972          {
973            bLowDelay = false;
974          }
975        }       
976      }
977
978      pcSlice->setCheckLDC(bLowDelay);           
979    }
980
981    //---------------
982    pcSlice->setRefPOCList();
983  }
984
985  pcPic->setCurrSliceIdx(m_uiSliceIdx);
986  if(pcSlice->getSPS()->getScalingListFlag())
987  {
988    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
989    if(pcSlice->getPPS()->getScalingListPresentFlag())
990    {
991      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
992    }
993    pcSlice->getScalingList()->setUseTransformSkip(pcSlice->getPPS()->getUseTransformSkip());
994    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
995    {
996      pcSlice->setDefaultScalingList();
997    }
998    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
999    m_cTrQuant.setUseScalingList(true);
1000  }
1001  else
1002  {
1003    m_cTrQuant.setFlatScalingList();
1004    m_cTrQuant.setUseScalingList(false);
1005  }
1006
1007  //  Decode a picture
1008  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
1009
1010  m_bFirstSliceInPicture = false;
1011  m_uiSliceIdx++;
1012
1013  return false;
1014}
1015
1016Void TDecTop::xDecodeVPS()
1017{
1018  TComVPS* vps = new TComVPS();
1019 
1020  m_cEntropyDecoder.decodeVPS( vps );
1021#if SVC_EXTENSION
1022  m_parameterSetManagerDecoder[0].storePrefetchedVPS(vps);
1023#else
1024  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
1025#endif
1026}
1027
1028Void TDecTop::xDecodeSPS()
1029{
1030  TComSPS* sps = new TComSPS();
1031#if SVC_EXTENSION
1032  sps->setLayerId(m_layerId);
1033#endif
1034#if SPS_SUB_LAYER_INFO
1035  m_cEntropyDecoder.decodeSPS( sps, &m_parameterSetManagerDecoder[0] );
1036#else
1037  m_cEntropyDecoder.decodeSPS( sps );
1038#endif
1039#if SVC_EXTENSION
1040  m_parameterSetManagerDecoder[m_layerId].storePrefetchedSPS(sps);
1041#else
1042  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
1043#endif
1044#if REF_IDX_FRAMEWORK
1045  if(m_numLayer>0)
1046  {
1047    xInitILRP(sps);
1048  }
1049#endif
1050}
1051
1052Void TDecTop::xDecodePPS()
1053{
1054  TComPPS* pps = new TComPPS();
1055  m_cEntropyDecoder.decodePPS( pps );
1056#if SVC_EXTENSION
1057  m_parameterSetManagerDecoder[m_layerId].storePrefetchedPPS( pps );
1058#else
1059  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
1060#endif
1061
1062  if( pps->getDependentSliceSegmentsEnabledFlag() )
1063  {
1064    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
1065    m_cSliceDecoder.initCtxMem(NumCtx);
1066    for ( UInt st = 0; st < NumCtx; st++ )
1067    {
1068      TDecSbac* ctx = NULL;
1069      ctx = new TDecSbac;
1070      ctx->init( &m_cBinCABAC );
1071      m_cSliceDecoder.setCtxMem( ctx, st );
1072    }
1073  }
1074}
1075
1076Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
1077{
1078#if SVC_EXTENSION
1079  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
1080  {
1081#if M0043_LAYERS_PRESENT_SEI
1082    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveVPS(), m_parameterSetManagerDecoder[m_layerId].getActiveSPS() );
1083#else
1084    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveSPS() );
1085#endif
1086  }
1087  else
1088  {
1089#if M0043_LAYERS_PRESENT_SEI
1090    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveVPS(), m_parameterSetManagerDecoder[m_layerId].getActiveSPS() );
1091#else
1092    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder[m_layerId].getActiveSPS() );
1093#endif
1094    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
1095    if (activeParamSets.size()>0)
1096    {
1097      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
1098      m_parameterSetManagerDecoder[m_layerId].applyPrefetchedPS();
1099      assert(seiAps->activeSeqParamSetId.size()>0);
1100      if (! m_parameterSetManagerDecoder[m_layerId].activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
1101      {
1102        printf ("Warning SPS activation with Active parameter set SEI failed");
1103      }
1104    }
1105  }
1106#else
1107  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
1108  {
1109#if M0043_LAYERS_PRESENT_SEI
1110    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
1111#else
1112    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1113#endif
1114  }
1115  else
1116  {
1117#if M0043_LAYERS_PRESENT_SEI
1118    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveVPS(), m_parameterSetManagerDecoder.getActiveSPS() );
1119#else
1120    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1121#endif
1122    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
1123    if (activeParamSets.size()>0)
1124    {
1125      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
1126      m_parameterSetManagerDecoder.applyPrefetchedPS();
1127      assert(seiAps->activeSeqParamSetId.size()>0);
1128      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
1129      {
1130        printf ("Warning SPS activation with Active parameter set SEI failed");
1131      }
1132    }
1133  }
1134#endif
1135}
1136
1137#if SVC_EXTENSION
1138Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, UInt& curLayerId, Bool& bNewPOC)
1139#else
1140Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1141#endif
1142{
1143  // Initialize entropy decoder
1144  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1145  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
1146
1147  switch (nalu.m_nalUnitType)
1148  {
1149    case NAL_UNIT_VPS:
1150      xDecodeVPS();
1151#if AVC_BASE
1152      if( m_parameterSetManagerDecoder[0].getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
1153      {
1154        if( !m_ppcTDecTop[0]->getBLReconFile()->good() )
1155        {
1156          printf( "Base layer YUV input reading error\n" );
1157          exit(EXIT_FAILURE);
1158        }       
1159#if AVC_SYNTAX
1160        if( !m_ppcTDecTop[0]->getBLSyntaxFile()->good() )
1161        {
1162          printf( "Base layer syntax input reading error\n" );
1163          exit(EXIT_FAILURE);
1164        }
1165#endif
1166      }
1167      else
1168      {
1169        TComList<TComPic*> *cListPic = m_ppcTDecTop[0]->getListPic();
1170        cListPic->clear();
1171      }
1172#endif
1173      return false;
1174     
1175    case NAL_UNIT_SPS:
1176      xDecodeSPS();
1177#if AVC_BASE
1178      if( m_parameterSetManagerDecoder[0].getPrefetchedVPS(0)->getAvcBaseLayerFlag() )
1179      {
1180        TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
1181        if( nalu.m_layerId == 1 && pBLPic->getPicYuvRec() == NULL )
1182        {
1183          // using EL SPS with spsId = 1
1184          TComSPS* sps = m_parameterSetManagerDecoder[nalu.m_layerId].getPrefetchedSPS(1);
1185          Int  numReorderPics[MAX_TLAYER];
1186          Window &conformanceWindow = sps->getConformanceWindow();
1187          Window defaultDisplayWindow = sps->getVuiParametersPresentFlag() ? sps->getVuiParameters()->getDefaultDisplayWindow() : Window();
1188#if SVC_UPSAMPLING
1189#if AVC_SYNTAX
1190
1191          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, sps, true);
1192#else
1193          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), conformanceWindow, defaultDisplayWindow, numReorderPics, NULL, true);
1194#endif
1195#else
1196          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth(), onformanceWindow, defaultDisplayWindow, numReorderPics, true);
1197#endif
1198        }
1199      }
1200#endif
1201      return false;
1202
1203    case NAL_UNIT_PPS:
1204      xDecodePPS();
1205      return false;
1206     
1207    case NAL_UNIT_PREFIX_SEI:
1208    case NAL_UNIT_SUFFIX_SEI:
1209      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
1210      return false;
1211
1212    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1213    case NAL_UNIT_CODED_SLICE_TRAIL_N:
1214    case NAL_UNIT_CODED_SLICE_TLA_R:
1215    case NAL_UNIT_CODED_SLICE_TSA_N:
1216    case NAL_UNIT_CODED_SLICE_STSA_R:
1217    case NAL_UNIT_CODED_SLICE_STSA_N:
1218    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
1219    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
1220    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1221    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
1222    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
1223    case NAL_UNIT_CODED_SLICE_CRA:
1224    case NAL_UNIT_CODED_SLICE_RADL_N:
1225    case NAL_UNIT_CODED_SLICE_RADL_R:
1226    case NAL_UNIT_CODED_SLICE_RASL_N:
1227    case NAL_UNIT_CODED_SLICE_RASL_R:
1228#if SVC_EXTENSION
1229      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, curLayerId, bNewPOC);
1230#else
1231      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1232#endif
1233      break;
1234    default:
1235      assert (1);
1236  }
1237
1238  return false;
1239}
1240
1241/** Function for checking if picture should be skipped because of association with a previous BLA picture
1242 * \param iPOCLastDisplay POC of last picture displayed
1243 * \returns true if the picture should be skipped
1244 * This function skips all TFD pictures that follow a BLA picture
1245 * in decoding order and precede it in output order.
1246 */
1247Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
1248{
1249  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))
1250  {
1251    iPOCLastDisplay++;
1252    return true;
1253  }
1254  return false;
1255}
1256
1257/** Function for checking if picture should be skipped because of random access
1258 * \param iSkipFrame skip frame counter
1259 * \param iPOCLastDisplay POC of last picture displayed
1260 * \returns true if the picture shold be skipped in the random access.
1261 * This function checks the skipping of pictures in the case of -s option random access.
1262 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1263 * It also checks the type of Nal unit type at the random access point.
1264 * 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.
1265 * If the random access point is IDR all pictures after the random access point are decoded.
1266 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
1267 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
1268 * access point there is no guarantee that the decoder will not crash.
1269 */
1270Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
1271{
1272  if (iSkipFrame) 
1273  {
1274    iSkipFrame--;   // decrement the counter
1275    return true;
1276  }
1277  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1278  {
1279    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
1280        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1281        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1282        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
1283    {
1284      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
1285      m_pocRandomAccess = m_apcSlicePilot->getPOC();
1286    }
1287    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
1288    {
1289      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1290    }
1291    else 
1292    {
1293      static Bool warningMessage = false;
1294      if(!warningMessage)
1295      {
1296        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1297        warningMessage = true;
1298      }
1299      return true;
1300    }
1301  }
1302  // skip the reordered pictures, if necessary
1303  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))
1304  {
1305    iPOCLastDisplay++;
1306    return true;
1307  }
1308  // if we reach here, then the picture is not skipped.
1309  return false; 
1310}
1311
1312#if VPS_EXTN_DIRECT_REF_LAYERS
1313TDecTop* TDecTop::getRefLayerDec( UInt refLayerIdc )
1314{
1315  TComVPS* vps = m_parameterSetManagerDecoder[0].getActiveVPS();
1316  if( vps->getNumDirectRefLayers( m_layerId ) <= 0 )
1317  {
1318    return (TDecTop *)getLayerDec( 0 );
1319  }
1320 
1321  return (TDecTop *)getLayerDec( vps->getRefLayerId( m_layerId, refLayerIdc ) );
1322}
1323#endif
1324
1325#if VPS_EXTN_DIRECT_REF_LAYERS && M0457_PREDICTION_INDICATIONS
1326
1327Void TDecTop::setRefLayerParams( TComVPS* vps )
1328{
1329  for(UInt layer = 0; layer < m_numLayer; layer++)
1330  {
1331    TDecTop *decTop = (TDecTop *)getLayerDec(layer);
1332    decTop->setNumSamplePredRefLayers(0);
1333    decTop->setNumMotionPredRefLayers(0);
1334    decTop->setNumDirectRefLayers(0);
1335    for(Int i = 0; i < MAX_VPS_LAYER_ID_PLUS1; i++)
1336    {
1337      decTop->setSamplePredEnabledFlag(i, false);
1338      decTop->setMotionPredEnabledFlag(i, false);
1339      decTop->setSamplePredRefLayerId(i, 0);
1340      decTop->setMotionPredRefLayerId(i, 0);
1341    }
1342    for(Int j = 0; j < layer; j++)
1343    {
1344      if (vps->getDirectDependencyFlag(layer, j))
1345      {
1346        decTop->setRefLayerId(decTop->getNumDirectRefLayers(), vps->getLayerIdInNuh(layer));
1347        decTop->setNumDirectRefLayers(decTop->getNumDirectRefLayers() + 1);
1348
1349        Int samplePredEnabledFlag = (vps->getDirectDependencyType(layer, j) + 1) & 1;
1350        decTop->setSamplePredEnabledFlag(j, samplePredEnabledFlag == 1 ? true : false);
1351        decTop->setNumSamplePredRefLayers(decTop->getNumSamplePredRefLayers() + samplePredEnabledFlag);
1352
1353        Int motionPredEnabledFlag = ((vps->getDirectDependencyType(layer, j) + 1) & 2) >> 1;
1354        decTop->setMotionPredEnabledFlag(j, motionPredEnabledFlag == 1 ? true : false);
1355        decTop->setNumMotionPredRefLayers(decTop->getNumMotionPredRefLayers() + motionPredEnabledFlag);
1356      }
1357    }
1358  }
1359  for ( Int i = 1, mIdx = 0, sIdx = 0; i < m_numLayer; i++ )
1360  {
1361    Int iNuhLId = vps->getLayerIdInNuh(i);
1362    TDecTop *decTop = (TDecTop *)getLayerDec(iNuhLId);
1363    for ( Int j = 0; j < i; j++ )
1364    {
1365      if (decTop->getMotionPredEnabledFlag(j))
1366      {
1367        decTop->setMotionPredRefLayerId(mIdx++, vps->getLayerIdInNuh(j));
1368      }
1369      if (decTop->getSamplePredEnabledFlag(j))
1370      {
1371        decTop->setSamplePredRefLayerId(sIdx++, vps->getLayerIdInNuh(j));
1372      }
1373    }
1374  }
1375}
1376
1377#endif
1378
[345]1379#if M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING
[313]1380TComPic* TDecTop::getMotionPredIlp(TComSlice* pcSlice)
1381{
1382  TComPic* ilpPic = NULL;
1383  Int activeMotionPredReflayerIdx = 0;
1384
1385  for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
1386  {
1387    UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
1388    if( getMotionPredEnabledFlag( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) ) )
1389    {
1390      if (activeMotionPredReflayerIdx == pcSlice->getColRefLayerIdx())
1391      {
1392        ilpPic = m_cIlpPic[refLayerIdc];
1393        break;
1394      }
1395      else
1396      {
1397        activeMotionPredReflayerIdx++;
1398      }
1399    }
1400  }
1401
1402  assert(ilpPic != NULL);
1403
1404  return ilpPic;
1405}
1406#endif
1407
1408//! \}
Note: See TracBrowser for help on using the repository browser.