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

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

Further cleanups

  • 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
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  pps->setSPS(sps);
317  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
318  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
319
320  g_bitDepthY     = sps->getBitDepthY();
321  g_bitDepthC     = sps->getBitDepthC();
322  g_uiMaxCUWidth  = sps->getMaxCUWidth();
323  g_uiMaxCUHeight = sps->getMaxCUHeight();
324  g_uiMaxCUDepth  = sps->getMaxCUDepth();
325  g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() );
326
327  for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++)
328  {
329    sps->setAMPAcc( i, sps->getUseAMP() );
330  }
331
332  for (Int i = sps->getLog2DiffMaxMinCodingBlockSize(); i < sps->getMaxCUDepth(); i++)
333  {
334    sps->setAMPAcc( i, 0 );
335  }
336
337  m_cSAO.destroy();
338  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() );
339  m_cLoopFilter.create( sps->getMaxCUDepth() );
340}
341
342#if H_MV
343Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool newLayerFlag )
344{
345  assert( nalu.m_layerId == m_layerId ); 
346
347#else
348Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
349{
350#endif
351  TComPic*&   pcPic         = m_pcPic;
352  m_apcSlicePilot->initSlice();
353
354  if (m_bFirstSliceInPicture)
355  {
356    m_uiSliceIdx     = 0;
357  }
358  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
359  if (!m_bFirstSliceInPicture)
360  {
361    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
362  }
363
364  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
365  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
366                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
367                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
368                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
369                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
370  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
371 
372  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
373  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
374
375#if H_MV
376  m_apcSlicePilot->setLayerId( nalu.m_layerId );
377#endif
378  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
379
380#if H_MV 
381  TComVPS* vps     = m_apcSlicePilot->getVPS();
382  Int layerIdInVps = vps->getLayerIdInVps( nalu.m_layerId );
383 
384  setViewId(  vps->getViewId( layerIdInVps  ) );
385  m_apcSlicePilot->setViewId( getViewId() );
386#if H_3D
387  setIsDepth( vps->getDepthId( layerIdInVps ) == 1 );
388  m_apcSlicePilot->setIsDepth( getIsDepth() );
389#endif
390#endif
391    // Skip pictures due to random access
392    if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
393    {
394      return false;
395    }
396    // Skip TFD pictures associated with BLA/BLANT pictures
397    if (isSkipPictureForBLA(iPOCLastDisplay))
398    {
399      return false;
400    }
401
402  //we should only get a different poc for a new picture (with CTU address==0)
403  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (!m_apcSlicePilot->getSliceCurStartCUAddr()==0))
404  {
405    printf ("Warning, the first slice of a picture might have been lost!\n");
406  }
407  // exit when a new picture is found
408  if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence )
409  {
410    if (m_prevPOC >= m_pocRandomAccess)
411    {
412      m_prevPOC = m_apcSlicePilot->getPOC();
413      return true;
414    }
415    m_prevPOC = m_apcSlicePilot->getPOC();
416  }
417#if H_MV
418  if ( newLayerFlag )
419  {
420    return false; 
421  }
422#endif
423  // actual decoding starts here
424  xActivateParameterSets();
425
426  if (m_apcSlicePilot->isNextSlice()) 
427  {
428    m_prevPOC = m_apcSlicePilot->getPOC();
429  }
430  m_bFirstSliceInSequence = false;
431  //detect lost reference picture and insert copy of earlier frame.
432  Int lostPoc;
433  while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
434  {
435    xCreateLostPicture(lostPoc-1);
436  }
437  if (m_bFirstSliceInPicture)
438  {
439    // Buffer initialize for prediction.
440    m_cPrediction.initTempBuff();
441    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
442#if H_MV
443    m_apcSlicePilot->createAndApplyIvReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer ); 
444#endif
445    //  Get a new picture buffer
446    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
447
448    // transfer any SEI messages that have been received to the picture
449    pcPic->setSEIs(m_SEIs);
450    m_SEIs.clear();
451
452    // Recursive structure
453    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
454    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
455    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
456
457    m_cSliceDecoder.create();
458  }
459  else
460  {
461    // Check if any new SEI has arrived
462    if(!m_SEIs.empty())
463    {
464      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
465      SEIMessages &picSEI = pcPic->getSEIs();
466      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
467      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
468      deleteSEIs(m_SEIs);
469    }
470  }
471 
472  //  Set picture slice pointer
473  TComSlice*  pcSlice = m_apcSlicePilot;
474  Bool bNextSlice     = pcSlice->isNextSlice();
475
476  UInt uiCummulativeTileWidth;
477  UInt uiCummulativeTileHeight;
478  UInt i, j, p;
479
480  //set NumColumnsMins1 and NumRowsMinus1
481  pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
482  pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
483
484  //create the TComTileArray
485  pcPic->getPicSym()->xCreateTComTileArray();
486
487  if( pcSlice->getPPS()->getUniformSpacingFlag() )
488  {
489    //set the width for each tile
490    for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
491    {
492      for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
493      {
494        pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
495          setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
496          - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
497      }
498    }
499
500    //set the height for each tile
501    for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
502    {
503      for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
504      {
505        pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
506          setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
507          - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
508      }
509    }
510  }
511  else
512  {
513    //set the width for each tile
514    for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
515    {
516      uiCummulativeTileWidth = 0;
517      for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
518      {
519        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
520        uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
521      }
522      pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
523    }
524
525    //set the height for each tile
526    for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
527    {
528      uiCummulativeTileHeight = 0;
529      for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
530      { 
531        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
532        uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
533      }
534      pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
535    }
536  }
537
538  pcPic->getPicSym()->xInitTiles();
539
540  //generate the Coding Order Map and Inverse Coding Order Map
541  UInt uiEncCUAddr;
542  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
543  {
544    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
545    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
546  }
547  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
548  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
549
550  //convert the start and end CU addresses of the slice and dependent slice into encoding order
551  pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) );
552  pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) );
553  if(pcSlice->isNextSlice())
554  {
555    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
556    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
557  }
558
559  if (m_bFirstSliceInPicture) 
560  {
561    if(pcPic->getNumAllocatedSlice() != 1)
562    {
563      pcPic->clearSliceBuffer();
564    }
565  }
566  else
567  {
568    pcPic->allocateNewSlice();
569  }
570  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
571  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
572  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
573
574  pcPic->setTLayer(nalu.m_temporalId);
575
576#if H_MV
577  pcPic->setLayerId( nalu.m_layerId );
578  pcPic->setViewId ( getViewId() );
579#if H_3D
580  pcPic->setIsDepth( getIsDepth() );
581#endif
582#endif
583  if (bNextSlice)
584  {
585    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA, m_cListPic );
586    // Set reference list
587#if H_MV   
588    pcSlice->setRefPicList( m_cListPic, m_refPicSetInterLayer, true );   
589#else
590#if FIX1071
591    pcSlice->setRefPicList( m_cListPic, true );
592#else
593    pcSlice->setRefPicList( m_cListPic );
594#endif
595
596#endif
597    // For generalized B
598    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
599    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
600    {
601      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
602      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
603
604      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
605      {
606        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
607      }
608    }
609    if (!pcSlice->isIntra())
610    {
611      Bool bLowDelay = true;
612      Int  iCurrPOC  = pcSlice->getPOC();
613      Int iRefIdx = 0;
614
615      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
616      {
617        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
618        {
619          bLowDelay = false;
620        }
621      }
622      if (pcSlice->isInterB())
623      {
624        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
625        {
626          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
627          {
628            bLowDelay = false;
629          }
630        }       
631      }
632
633      pcSlice->setCheckLDC(bLowDelay);           
634    }
635
636    //---------------
637    pcSlice->setRefPOCList();
638#if !L0034_COMBINED_LIST_CLEANUP
639    pcSlice->setNoBackPredFlag( false );
640    if ( pcSlice->getSliceType() == B_SLICE )
641    {
642      if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) )
643      {
644        pcSlice->setNoBackPredFlag( true );
645        for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ )
646        {
647          if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) 
648          {
649            pcSlice->setNoBackPredFlag( false );
650            break;
651          }
652        }
653      }
654    }
655#endif
656  }
657
658  pcPic->setCurrSliceIdx(m_uiSliceIdx);
659  if(pcSlice->getSPS()->getScalingListFlag())
660  {
661    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
662    if(pcSlice->getPPS()->getScalingListPresentFlag())
663    {
664      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
665    }
666    pcSlice->getScalingList()->setUseTransformSkip(pcSlice->getPPS()->getUseTransformSkip());
667    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
668    {
669      pcSlice->setDefaultScalingList();
670    }
671    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
672    m_cTrQuant.setUseScalingList(true);
673  }
674  else
675  {
676    m_cTrQuant.setFlatScalingList();
677    m_cTrQuant.setUseScalingList(false);
678  }
679
680  //  Decode a picture
681  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
682
683  m_bFirstSliceInPicture = false;
684  m_uiSliceIdx++;
685
686  return false;
687}
688
689Void TDecTop::xDecodeVPS()
690{
691  TComVPS* vps = new TComVPS();
692 
693  m_cEntropyDecoder.decodeVPS( vps );
694  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
695}
696
697Void TDecTop::xDecodeSPS()
698{
699  TComSPS* sps = new TComSPS();
700  m_cEntropyDecoder.decodeSPS( sps );
701  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
702}
703
704Void TDecTop::xDecodePPS()
705{
706  TComPPS* pps = new TComPPS();
707  m_cEntropyDecoder.decodePPS( pps );
708  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
709}
710
711Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
712{
713  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
714  {
715    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
716  }
717  else
718  {
719    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
720    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
721    if (activeParamSets.size()>0)
722    {
723      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
724      m_parameterSetManagerDecoder.applyPrefetchedPS();
725      assert(seiAps->activeSeqParamSetId.size()>0);
726      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
727      {
728        printf ("Warning SPS activation with Active parameter set SEI failed");
729      }
730    }
731  }
732}
733
734#if H_MV
735Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayerFlag)
736#else
737Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
738#endif
739{
740  // Initialize entropy decoder
741  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
742  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
743
744  switch (nalu.m_nalUnitType)
745  {
746    case NAL_UNIT_VPS:
747      xDecodeVPS();
748      return false;
749     
750    case NAL_UNIT_SPS:
751      xDecodeSPS();
752      return false;
753
754    case NAL_UNIT_PPS:
755      xDecodePPS();
756      return false;
757     
758    case NAL_UNIT_PREFIX_SEI:
759    case NAL_UNIT_SUFFIX_SEI:
760      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
761      return false;
762
763    case NAL_UNIT_CODED_SLICE_TRAIL_R:
764    case NAL_UNIT_CODED_SLICE_TRAIL_N:
765    case NAL_UNIT_CODED_SLICE_TLA_R:
766    case NAL_UNIT_CODED_SLICE_TSA_N:
767    case NAL_UNIT_CODED_SLICE_STSA_R:
768    case NAL_UNIT_CODED_SLICE_STSA_N:
769    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
770    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
771    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
772    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
773    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
774    case NAL_UNIT_CODED_SLICE_CRA:
775    case NAL_UNIT_CODED_SLICE_RADL_N:
776    case NAL_UNIT_CODED_SLICE_RADL_R:
777    case NAL_UNIT_CODED_SLICE_RASL_N:
778    case NAL_UNIT_CODED_SLICE_RASL_R:
779#if H_MV
780      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, newLayerFlag);
781#else
782      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
783#endif
784      break;
785    default:
786      assert (1);
787  }
788
789  return false;
790}
791
792/** Function for checking if picture should be skipped because of association with a previous BLA picture
793 * \param iPOCLastDisplay POC of last picture displayed
794 * \returns true if the picture should be skipped
795 * This function skips all TFD pictures that follow a BLA picture
796 * in decoding order and precede it in output order.
797 */
798Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
799{
800  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))
801  {
802    iPOCLastDisplay++;
803    return true;
804  }
805  return false;
806}
807
808/** Function for checking if picture should be skipped because of random access
809 * \param iSkipFrame skip frame counter
810 * \param iPOCLastDisplay POC of last picture displayed
811 * \returns true if the picture shold be skipped in the random access.
812 * This function checks the skipping of pictures in the case of -s option random access.
813 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
814 * It also checks the type of Nal unit type at the random access point.
815 * 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.
816 * If the random access point is IDR all pictures after the random access point are decoded.
817 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
818 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
819 * access point there is no guarantee that the decoder will not crash.
820 */
821Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
822{
823  if (iSkipFrame) 
824  {
825    iSkipFrame--;   // decrement the counter
826    return true;
827  }
828  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
829  {
830    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
831        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
832        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
833        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
834    {
835      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
836      m_pocRandomAccess = m_apcSlicePilot->getPOC();
837    }
838    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
839    {
840      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
841    }
842    else 
843    {
844      static Bool warningMessage = false;
845      if(!warningMessage)
846      {
847        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
848        warningMessage = true;
849      }
850      return true;
851    }
852  }
853  // skip the reordered pictures, if necessary
854  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))
855  {
856    iPOCLastDisplay++;
857    return true;
858  }
859  // if we reach here, then the picture is not skipped.
860  return false; 
861}
862
863#if H_MV
864TComPic* TDecTop::getPic( Int poc )
865{
866  xGetPic( m_layerId, poc ); 
867  TComList<TComPic*>* listPic = getListPic();
868  TComPic* pcPic = NULL;
869  for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++)
870  {
871    if( (*it)->getPOC() == poc )
872    {
873      pcPic = *it ;
874      break ;
875    }
876  }
877  return pcPic;
878}
879
880TComPic* TDecTop::xGetPic( Int layerId, Int poc )
881{ 
882  return m_ivPicLists->getPic( layerId, poc ) ;
883}
884
885#endif
886//! \}
Note: See TracBrowser for help on using the repository browser.