source: SHVCSoftware/branches/SHM-2.1-dev/source/Lib/TLibDecoder/TDecTop.cpp @ 844

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

update to HM11.0

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