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

Last change on this file since 291 was 291, checked in by nokia, 12 years ago

JCTVC-M0457: Co-located picture signaling

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