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

Last change on this file since 138 was 137, checked in by mediatek, 12 years ago

M0133/M0449: inter-layer MV scaling and pixel mapping position calculation
Author: Peter Chuang <peter.chuang@…>

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