source: 3DVCSoftware/branches/HTM-DEV-0.1-dev/source/Lib/TLibDecoder/TDecTop.cpp @ 372

Last change on this file since 372 was 372, checked in by tech, 12 years ago

Further minor cleanups.

  • Property svn:eol-style set to native
File size: 29.5 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 H_MV
42ParameterSetManagerDecoder TDecTop::m_parameterSetManagerDecoder;
43#endif
44//! \ingroup TLibDecoder
45//! \{
46
47TDecTop::TDecTop()
48{
49  m_pcPic = 0;
50  m_iMaxRefPicNum = 0;
51#if ENC_DEC_TRACE
52  g_hTrace = fopen( "TraceDec.txt", "wb" );
53  g_bJustDoIt = g_bEncDecTraceDisable;
54  g_nSymbolCounter = 0;
55#endif
56  m_pocCRA = 0;
57  m_prevRAPisBLA = false;
58  m_pocRandomAccess = MAX_INT; 
59  m_prevPOC                = MAX_INT;
60  m_bFirstSliceInPicture    = true;
61  m_bFirstSliceInSequence   = true;
62#if H_MV
63  m_layerId = 0;
64  m_viewId = 0;
65#if H_3D
66  m_isDepth = false;
67#endif
68#endif
69}
70
71TDecTop::~TDecTop()
72{
73#if ENC_DEC_TRACE
74  fclose( g_hTrace );
75#endif
76}
77
78Void TDecTop::create()
79{
80  m_cGopDecoder.create();
81  m_apcSlicePilot = new TComSlice;
82  m_uiSliceIdx = 0;
83}
84
85Void TDecTop::destroy()
86{
87  m_cGopDecoder.destroy();
88 
89  delete m_apcSlicePilot;
90  m_apcSlicePilot = NULL;
91 
92  m_cSliceDecoder.destroy();
93}
94
95Void TDecTop::init()
96{
97  // initialize ROM
98#if !H_MV
99  initROM();
100#endif
101  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
102  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
103  m_cEntropyDecoder.init(&m_cPrediction);
104}
105
106Void TDecTop::deletePicBuffer ( )
107{
108  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
109  Int iSize = Int( m_cListPic.size() );
110 
111  for (Int i = 0; i < iSize; i++ )
112  {
113    TComPic* pcPic = *(iterPic++);
114#if H_MV
115    if( pcPic )
116    {
117#endif
118    pcPic->destroy();
119   
120    delete pcPic;
121    pcPic = NULL;
122#if H_MV
123    }
124#endif
125  }
126 
127  m_cSAO.destroy();
128 
129  m_cLoopFilter.        destroy();
130 
131#if !H_MV
132  // destroy ROM
133  destroyROM();
134#endif
135}
136
137Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
138{
139  Int  numReorderPics[MAX_TLAYER];
140  Window &conformanceWindow = pcSlice->getSPS()->getConformanceWindow();
141  Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window();
142
143  for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
144  {
145    numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer);
146  }
147
148#if L0323_DPB
149  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer())+pcSlice->getSPS()->getNumReorderPics(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
150#else
151  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer())+pcSlice->getSPS()->getNumReorderPics(pcSlice->getTLayer()) + 1; // +1 to have space for the picture currently being decoded
152#endif
153  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
154  {
155    rpcPic = new TComPic();
156   
157    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
158                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
159    rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
160    m_cListPic.pushBack( rpcPic );
161   
162    return;
163  }
164 
165  Bool bBufferIsAvailable = false;
166  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
167  while (iterPic != m_cListPic.end())
168  {
169    rpcPic = *(iterPic++);
170    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
171    {
172      rpcPic->setOutputMark(false);
173      bBufferIsAvailable = true;
174      break;
175    }
176
177    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
178    {
179      rpcPic->setOutputMark(false);
180      rpcPic->setReconMark( false );
181      rpcPic->getPicYuvRec()->setBorderExtension( false );
182      bBufferIsAvailable = true;
183      break;
184    }
185  }
186 
187  if ( !bBufferIsAvailable )
188  {
189    //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer.
190    m_iMaxRefPicNum++;
191    rpcPic = new TComPic();
192    m_cListPic.pushBack( rpcPic );
193  }
194  rpcPic->destroy();
195  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
196                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
197  rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
198}
199
200#if H_MV
201Void TDecTop::endPicDecoding(Int& poc, TComList<TComPic*>*& rpcListPic, std::vector<Int>& targetDecLayerIdSet )
202#else
203Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic)
204#endif
205{
206  if (!m_pcPic)
207  {
208    /* nothing to deblock */
209    return;
210  }
211 
212  TComPic*&   pcPic         = m_pcPic;
213
214  // Execute Deblock + Cleanup
215
216  m_cGopDecoder.filterPicture(pcPic);
217
218  TComSlice::sortPicList( m_cListPic ); // sorting for application output
219  poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
220  rpcListPic          = &m_cListPic; 
221  m_cCuDecoder.destroy();       
222#if H_MV
223  TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer ); 
224  TComSlice::markIvRefPicsAsUnused   ( m_ivPicLists, targetDecLayerIdSet, m_parameterSetManagerDecoder.getActiveVPS(), m_layerId, poc ); 
225#endif
226  m_bFirstSliceInPicture  = true;
227
228  return;
229}
230
231Void TDecTop::xCreateLostPicture(Int iLostPoc) 
232{
233  printf("\ninserting lost poc : %d\n",iLostPoc);
234  TComSlice cFillSlice;
235  cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
236  cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
237  cFillSlice.initSlice();
238  TComPic *cFillPic;
239  xGetNewPicBuffer(&cFillSlice,cFillPic);
240  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
241  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
242  cFillPic->getSlice(0)->initSlice();
243 
244  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
245  Int closestPoc = 1000000;
246  while ( iterPic != m_cListPic.end())
247  {
248    TComPic * rpcPic = *(iterPic++);
249    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())
250    {
251      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
252    }
253  }
254  iterPic = m_cListPic.begin();
255  while ( iterPic != m_cListPic.end())
256  {
257    TComPic *rpcPic = *(iterPic++);
258    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
259    {
260      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
261      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
262      break;
263    }
264  }
265  cFillPic->setCurrSliceIdx(0);
266  for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) 
267  {
268    cFillPic->getCU(i)->initCU(cFillPic,i);
269  }
270  cFillPic->getSlice(0)->setReferenced(true);
271  cFillPic->getSlice(0)->setPOC(iLostPoc);
272  cFillPic->setReconMark(true);
273  cFillPic->setOutputMark(true);
274  if(m_pocRandomAccess == MAX_INT)
275  {
276    m_pocRandomAccess = iLostPoc;
277  }
278}
279
280
281Void TDecTop::xActivateParameterSets()
282{
283  m_parameterSetManagerDecoder.applyPrefetchedPS();
284 
285  TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
286  assert (pps != 0);
287
288  TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId());
289  assert (sps != 0);
290
291  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
292  {
293    printf ("Parameter set activation failed!");
294    assert (0);
295  }
296
297  if( pps->getDependentSliceSegmentsEnabledFlag() )
298  {
299    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
300
301    if (m_cSliceDecoder.getCtxMemSize() != NumCtx)
302    {
303      m_cSliceDecoder.initCtxMem(NumCtx);
304      for ( UInt st = 0; st < NumCtx; st++ )
305      {
306        TDecSbac* ctx = NULL;
307        ctx = new TDecSbac;
308        ctx->init( &m_cBinCABAC );
309        m_cSliceDecoder.setCtxMem( ctx, st );
310      }
311    }
312  }
313
314  m_apcSlicePilot->setPPS(pps);
315  m_apcSlicePilot->setSPS(sps);
316#if H_MV
317  m_apcSlicePilot->setVPS( m_parameterSetManagerDecoder.getActiveVPS() );
318#endif
319  pps->setSPS(sps);
320  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
321  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
322
323  g_bitDepthY     = sps->getBitDepthY();
324  g_bitDepthC     = sps->getBitDepthC();
325  g_uiMaxCUWidth  = sps->getMaxCUWidth();
326  g_uiMaxCUHeight = sps->getMaxCUHeight();
327  g_uiMaxCUDepth  = sps->getMaxCUDepth();
328  g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() );
329
330  for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++)
331  {
332    sps->setAMPAcc( i, sps->getUseAMP() );
333  }
334
335  for (Int i = sps->getLog2DiffMaxMinCodingBlockSize(); i < sps->getMaxCUDepth(); i++)
336  {
337    sps->setAMPAcc( i, 0 );
338  }
339
340  m_cSAO.destroy();
341  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() );
342  m_cLoopFilter.create( sps->getMaxCUDepth() );
343}
344
345#if H_MV
346Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool newLayerFlag )
347{
348  assert( nalu.m_layerId == m_layerId ); 
349
350#else
351Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
352{
353#endif
354  TComPic*&   pcPic         = m_pcPic;
355  m_apcSlicePilot->initSlice();
356
357  if (m_bFirstSliceInPicture)
358  {
359    m_uiSliceIdx     = 0;
360  }
361  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
362  if (!m_bFirstSliceInPicture)
363  {
364    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
365  }
366
367  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
368  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
369                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
370                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
371                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
372                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
373  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
374 
375  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
376  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
377
378#if H_MV
379  m_apcSlicePilot->setLayerId( nalu.m_layerId );
380#endif
381  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
382
383#if H_MV 
384  TComVPS* vps     = m_apcSlicePilot->getVPS();
385  Int layerIdInVps = vps->getLayerIdInVps( nalu.m_layerId );
386 
387  setViewId(  vps->getViewId( layerIdInVps  ) );
388  m_apcSlicePilot->setViewId( getViewId() );
389#if H_3D
390  setIsDepth( vps->getDepthId( layerIdInVps ) == 1 );
391  m_apcSlicePilot->setIsDepth( getIsDepth() );
392#endif
393#endif
394    // Skip pictures due to random access
395    if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
396    {
397      return false;
398    }
399    // Skip TFD pictures associated with BLA/BLANT pictures
400    if (isSkipPictureForBLA(iPOCLastDisplay))
401    {
402      return false;
403    }
404
405  //we should only get a different poc for a new picture (with CTU address==0)
406  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (!m_apcSlicePilot->getSliceCurStartCUAddr()==0))
407  {
408    printf ("Warning, the first slice of a picture might have been lost!\n");
409  }
410  // exit when a new picture is found
411  if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence )
412  {
413    if (m_prevPOC >= m_pocRandomAccess)
414    {
415      m_prevPOC = m_apcSlicePilot->getPOC();
416      return true;
417    }
418    m_prevPOC = m_apcSlicePilot->getPOC();
419  }
420#if H_MV
421  if ( newLayerFlag )
422  {
423    return false; 
424  }
425#endif
426  // actual decoding starts here
427  xActivateParameterSets();
428
429  if (m_apcSlicePilot->isNextSlice()) 
430  {
431    m_prevPOC = m_apcSlicePilot->getPOC();
432  }
433  m_bFirstSliceInSequence = false;
434  //detect lost reference picture and insert copy of earlier frame.
435  Int lostPoc;
436  while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
437  {
438    xCreateLostPicture(lostPoc-1);
439  }
440  if (m_bFirstSliceInPicture)
441  {
442    // Buffer initialize for prediction.
443    m_cPrediction.initTempBuff();
444    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
445#if H_MV
446    m_apcSlicePilot->createAndApplyIvReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer ); 
447#endif
448    //  Get a new picture buffer
449    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
450
451    // transfer any SEI messages that have been received to the picture
452    pcPic->setSEIs(m_SEIs);
453    m_SEIs.clear();
454
455    // Recursive structure
456    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
457    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
458    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
459
460    m_cSliceDecoder.create();
461  }
462  else
463  {
464    // Check if any new SEI has arrived
465    if(!m_SEIs.empty())
466    {
467      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
468      SEIMessages &picSEI = pcPic->getSEIs();
469      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
470      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
471      deleteSEIs(m_SEIs);
472    }
473  }
474 
475  //  Set picture slice pointer
476  TComSlice*  pcSlice = m_apcSlicePilot;
477  Bool bNextSlice     = pcSlice->isNextSlice();
478
479  UInt uiCummulativeTileWidth;
480  UInt uiCummulativeTileHeight;
481  UInt i, j, p;
482
483  //set NumColumnsMins1 and NumRowsMinus1
484  pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
485  pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
486
487  //create the TComTileArray
488  pcPic->getPicSym()->xCreateTComTileArray();
489
490  if( pcSlice->getPPS()->getUniformSpacingFlag() )
491  {
492    //set the width for each tile
493    for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
494    {
495      for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
496      {
497        pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
498          setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
499          - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
500      }
501    }
502
503    //set the height for each tile
504    for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
505    {
506      for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
507      {
508        pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
509          setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
510          - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
511      }
512    }
513  }
514  else
515  {
516    //set the width for each tile
517    for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
518    {
519      uiCummulativeTileWidth = 0;
520      for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
521      {
522        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
523        uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
524      }
525      pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
526    }
527
528    //set the height for each tile
529    for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
530    {
531      uiCummulativeTileHeight = 0;
532      for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
533      { 
534        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
535        uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
536      }
537      pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
538    }
539  }
540
541  pcPic->getPicSym()->xInitTiles();
542
543  //generate the Coding Order Map and Inverse Coding Order Map
544  UInt uiEncCUAddr;
545  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
546  {
547    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
548    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
549  }
550  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
551  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
552
553  //convert the start and end CU addresses of the slice and dependent slice into encoding order
554  pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) );
555  pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) );
556  if(pcSlice->isNextSlice())
557  {
558    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
559    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
560  }
561
562  if (m_bFirstSliceInPicture) 
563  {
564    if(pcPic->getNumAllocatedSlice() != 1)
565    {
566      pcPic->clearSliceBuffer();
567    }
568  }
569  else
570  {
571    pcPic->allocateNewSlice();
572  }
573  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
574  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
575  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
576
577  pcPic->setTLayer(nalu.m_temporalId);
578
579#if H_MV
580  pcPic->setLayerId( nalu.m_layerId );
581  pcPic->setViewId ( getViewId() );
582#if H_3D
583  pcPic->setIsDepth( getIsDepth() );
584#endif
585#endif
586  if (bNextSlice)
587  {
588    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA, m_cListPic );
589    // Set reference list
590#if H_MV   
591    pcSlice->setRefPicList( m_cListPic, m_refPicSetInterLayer, true );   
592#else
593#if FIX1071
594    pcSlice->setRefPicList( m_cListPic, true );
595#else
596    pcSlice->setRefPicList( m_cListPic );
597#endif
598
599#endif
600    // For generalized B
601    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
602    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
603    {
604      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
605      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
606
607      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
608      {
609        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
610      }
611    }
612    if (!pcSlice->isIntra())
613    {
614      Bool bLowDelay = true;
615      Int  iCurrPOC  = pcSlice->getPOC();
616      Int iRefIdx = 0;
617
618      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
619      {
620        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
621        {
622          bLowDelay = false;
623        }
624      }
625      if (pcSlice->isInterB())
626      {
627        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
628        {
629          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
630          {
631            bLowDelay = false;
632          }
633        }       
634      }
635
636      pcSlice->setCheckLDC(bLowDelay);           
637    }
638
639    //---------------
640    pcSlice->setRefPOCList();
641#if !L0034_COMBINED_LIST_CLEANUP
642    pcSlice->setNoBackPredFlag( false );
643    if ( pcSlice->getSliceType() == B_SLICE )
644    {
645      if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) )
646      {
647        pcSlice->setNoBackPredFlag( true );
648        for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ )
649        {
650          if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) 
651          {
652            pcSlice->setNoBackPredFlag( false );
653            break;
654          }
655        }
656      }
657    }
658#endif
659  }
660
661  pcPic->setCurrSliceIdx(m_uiSliceIdx);
662  if(pcSlice->getSPS()->getScalingListFlag())
663  {
664    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
665    if(pcSlice->getPPS()->getScalingListPresentFlag())
666    {
667      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
668    }
669    pcSlice->getScalingList()->setUseTransformSkip(pcSlice->getPPS()->getUseTransformSkip());
670    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
671    {
672      pcSlice->setDefaultScalingList();
673    }
674    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
675    m_cTrQuant.setUseScalingList(true);
676  }
677  else
678  {
679    m_cTrQuant.setFlatScalingList();
680    m_cTrQuant.setUseScalingList(false);
681  }
682
683  //  Decode a picture
684  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
685
686  m_bFirstSliceInPicture = false;
687  m_uiSliceIdx++;
688
689  return false;
690}
691
692Void TDecTop::xDecodeVPS()
693{
694  TComVPS* vps = new TComVPS();
695 
696  m_cEntropyDecoder.decodeVPS( vps );
697  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
698}
699
700Void TDecTop::xDecodeSPS()
701{
702  TComSPS* sps = new TComSPS();
703  m_cEntropyDecoder.decodeSPS( sps );
704  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
705}
706
707Void TDecTop::xDecodePPS()
708{
709  TComPPS* pps = new TComPPS();
710  m_cEntropyDecoder.decodePPS( pps );
711  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
712}
713
714Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
715{
716  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
717  {
718    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
719  }
720  else
721  {
722    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
723    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
724    if (activeParamSets.size()>0)
725    {
726      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
727      m_parameterSetManagerDecoder.applyPrefetchedPS();
728      assert(seiAps->activeSeqParamSetId.size()>0);
729      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
730      {
731        printf ("Warning SPS activation with Active parameter set SEI failed");
732      }
733    }
734  }
735}
736
737#if H_MV
738Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayerFlag)
739#else
740Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
741#endif
742{
743  // Initialize entropy decoder
744  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
745  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
746
747  switch (nalu.m_nalUnitType)
748  {
749    case NAL_UNIT_VPS:
750      xDecodeVPS();
751      return false;
752     
753    case NAL_UNIT_SPS:
754      xDecodeSPS();
755      return false;
756
757    case NAL_UNIT_PPS:
758      xDecodePPS();
759      return false;
760     
761    case NAL_UNIT_PREFIX_SEI:
762    case NAL_UNIT_SUFFIX_SEI:
763      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
764      return false;
765
766    case NAL_UNIT_CODED_SLICE_TRAIL_R:
767    case NAL_UNIT_CODED_SLICE_TRAIL_N:
768    case NAL_UNIT_CODED_SLICE_TLA_R:
769    case NAL_UNIT_CODED_SLICE_TSA_N:
770    case NAL_UNIT_CODED_SLICE_STSA_R:
771    case NAL_UNIT_CODED_SLICE_STSA_N:
772    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
773    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
774    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
775    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
776    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
777    case NAL_UNIT_CODED_SLICE_CRA:
778    case NAL_UNIT_CODED_SLICE_RADL_N:
779    case NAL_UNIT_CODED_SLICE_RADL_R:
780    case NAL_UNIT_CODED_SLICE_RASL_N:
781    case NAL_UNIT_CODED_SLICE_RASL_R:
782#if H_MV
783      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, newLayerFlag);
784#else
785      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
786#endif
787      break;
788    default:
789      assert (1);
790  }
791
792  return false;
793}
794
795/** Function for checking if picture should be skipped because of association with a previous BLA picture
796 * \param iPOCLastDisplay POC of last picture displayed
797 * \returns true if the picture should be skipped
798 * This function skips all TFD pictures that follow a BLA picture
799 * in decoding order and precede it in output order.
800 */
801Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
802{
803  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))
804  {
805    iPOCLastDisplay++;
806    return true;
807  }
808  return false;
809}
810
811/** Function for checking if picture should be skipped because of random access
812 * \param iSkipFrame skip frame counter
813 * \param iPOCLastDisplay POC of last picture displayed
814 * \returns true if the picture shold be skipped in the random access.
815 * This function checks the skipping of pictures in the case of -s option random access.
816 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
817 * It also checks the type of Nal unit type at the random access point.
818 * 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.
819 * If the random access point is IDR all pictures after the random access point are decoded.
820 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
821 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
822 * access point there is no guarantee that the decoder will not crash.
823 */
824Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
825{
826  if (iSkipFrame) 
827  {
828    iSkipFrame--;   // decrement the counter
829    return true;
830  }
831  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
832  {
833    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
834        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
835        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
836        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
837    {
838      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
839      m_pocRandomAccess = m_apcSlicePilot->getPOC();
840    }
841    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
842    {
843      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
844    }
845    else 
846    {
847      static Bool warningMessage = false;
848      if(!warningMessage)
849      {
850        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
851        warningMessage = true;
852      }
853      return true;
854    }
855  }
856  // skip the reordered pictures, if necessary
857  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))
858  {
859    iPOCLastDisplay++;
860    return true;
861  }
862  // if we reach here, then the picture is not skipped.
863  return false; 
864}
865
866#if H_MV
867TComPic* TDecTop::getPic( Int poc )
868{
869  xGetPic( m_layerId, poc ); 
870  TComList<TComPic*>* listPic = getListPic();
871  TComPic* pcPic = NULL;
872  for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++)
873  {
874    if( (*it)->getPOC() == poc )
875    {
876      pcPic = *it ;
877      break ;
878    }
879  }
880  return pcPic;
881}
882
883TComPic* TDecTop::xGetPic( Int layerId, Int poc )
884{ 
885  return m_ivPicLists->getPic( layerId, poc ) ;
886}
887
888#endif
889//! \}
Note: See TracBrowser for help on using the repository browser.