source: SHVCSoftware/branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecTop.cpp @ 370

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

remove SIMPLIFIED_MV_POS_SCALING macro

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