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

Last change on this file since 363 was 363, checked in by tech, 11 years ago

Fixed wrongly merged parts.

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