source: 3DVCSoftware/branches/HTM-3.0-LG/source/Lib/TLibDecoder/TDecTop.cpp @ 1417

Last change on this file since 1417 was 57, checked in by hschwarz, 13 years ago

corrected output of decoded camera parameter files

  • Property svn:eol-style set to native
File size: 40.8 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-2012, 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 "../../App/TAppDecoder/TAppDecTop.h"
40#include "TDecTop.h"
41
42//! \ingroup TLibDecoder
43//! \{
44
45
46CamParsCollector::CamParsCollector()
47: m_bInitialized( false )
48{
49  m_aaiCodedOffset         = new Int* [ MAX_VIEW_NUM ];
50  m_aaiCodedScale          = new Int* [ MAX_VIEW_NUM ];
51  m_aiViewOrderIndex       = new Int  [ MAX_VIEW_NUM ];
52  m_aiViewReceived         = new Int  [ MAX_VIEW_NUM ];
53  for( UInt uiId = 0; uiId < MAX_VIEW_NUM; uiId++ )
54  {
55    m_aaiCodedOffset      [ uiId ] = new Int [ MAX_VIEW_NUM ];
56    m_aaiCodedScale       [ uiId ] = new Int [ MAX_VIEW_NUM ];
57  }
58}
59
60CamParsCollector::~CamParsCollector()
61{
62  for( UInt uiId = 0; uiId < MAX_VIEW_NUM; uiId++ )
63  {
64    delete [] m_aaiCodedOffset      [ uiId ];
65    delete [] m_aaiCodedScale       [ uiId ];
66  }
67  delete [] m_aaiCodedOffset;
68  delete [] m_aaiCodedScale;
69  delete [] m_aiViewOrderIndex;
70  delete [] m_aiViewReceived;
71}
72
73Void
74CamParsCollector::init( FILE* pCodedScaleOffsetFile )
75{
76  m_bInitialized            = true;
77  m_pCodedScaleOffsetFile   = pCodedScaleOffsetFile;
78  m_uiCamParsCodedPrecision = 0;
79  m_bCamParsVaryOverTime    = false;
80  m_iLastViewId             = -1;
81  m_iLastPOC                = -1;
82  m_uiMaxViewId             = 0;
83}
84
85Void
86CamParsCollector::uninit()
87{
88  m_bInitialized = false;
89}
90
91Void
92CamParsCollector::setSlice( TComSlice* pcSlice )
93{
94  if( pcSlice == 0 )
95  {
96    AOF( xIsComplete() );
97    if( m_bCamParsVaryOverTime || m_iLastPOC == 0 )
98    {
99      xOutput( m_iLastPOC );
100    }
101    return;
102  }
103
104  AOF( pcSlice->getSPS()->getViewId() < MAX_VIEW_NUM );
105  if ( pcSlice->getSPS()->isDepth  () )
106  {
107    return;
108  }
109  Bool  bFirstAU          = ( pcSlice->getPOC()               == 0 );
110  Bool  bFirstSliceInAU   = ( pcSlice->getPOC()               != Int ( m_iLastPOC ) );
111  Bool  bFirstSliceInView = ( pcSlice->getSPS()->getViewId()  != UInt( m_iLastViewId ) || bFirstSliceInAU );
112  AOT(  bFirstSliceInAU  &&   pcSlice->getSPS()->getViewId()  != 0 );
113  AOT( !bFirstSliceInAU  &&   pcSlice->getSPS()->getViewId()   < UInt( m_iLastViewId ) );
114  AOT( !bFirstSliceInAU  &&   pcSlice->getSPS()->getViewId()   > UInt( m_iLastViewId + 1 ) );
115  AOT( !bFirstAU         &&   pcSlice->getSPS()->getViewId()   > m_uiMaxViewId );
116  if ( !bFirstSliceInView )
117  {
118    if( m_bCamParsVaryOverTime ) // check consistency of slice parameters here
119    {
120      UInt uiViewId = pcSlice->getSPS()->getViewId();
121      for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ )
122      {
123        AOF( m_aaiCodedScale [ uiBaseId ][ uiViewId ] == pcSlice->getCodedScale    () [ uiBaseId ] );
124        AOF( m_aaiCodedOffset[ uiBaseId ][ uiViewId ] == pcSlice->getCodedOffset   () [ uiBaseId ] );
125        AOF( m_aaiCodedScale [ uiViewId ][ uiBaseId ] == pcSlice->getInvCodedScale () [ uiBaseId ] );
126        AOF( m_aaiCodedOffset[ uiViewId ][ uiBaseId ] == pcSlice->getInvCodedOffset() [ uiBaseId ] );
127      }
128    }
129    return;
130  }
131
132  if( bFirstSliceInAU )
133  {
134    if( !bFirstAU )
135    {
136      AOF( xIsComplete() );
137      xOutput( m_iLastPOC );
138    }
139    ::memset( m_aiViewReceived, 0x00, MAX_VIEW_NUM * sizeof( Int ) );
140  }
141
142  UInt uiViewId                 = pcSlice->getSPS()->getViewId();
143  m_aiViewReceived[ uiViewId ]  = 1;
144  if( bFirstAU )
145  {
146    m_uiMaxViewId                     = Max( m_uiMaxViewId, uiViewId );
147    m_aiViewOrderIndex[ uiViewId ]    = pcSlice->getSPS()->getViewOrderIdx();
148    if( uiViewId == 1 )
149    {
150      m_uiCamParsCodedPrecision       = pcSlice->getSPS()->getCamParPrecision     ();
151      m_bCamParsVaryOverTime          = pcSlice->getSPS()->hasCamParInSliceHeader ();
152    }
153    else if( uiViewId > 1 )
154    {
155      AOF( m_uiCamParsCodedPrecision == pcSlice->getSPS()->getCamParPrecision     () );
156      AOF( m_bCamParsVaryOverTime    == pcSlice->getSPS()->hasCamParInSliceHeader () );
157    }
158    for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ )
159    {
160      if( m_bCamParsVaryOverTime )
161      {
162        m_aaiCodedScale [ uiBaseId ][ uiViewId ]  = pcSlice->getCodedScale    () [ uiBaseId ];
163        m_aaiCodedOffset[ uiBaseId ][ uiViewId ]  = pcSlice->getCodedOffset   () [ uiBaseId ];
164        m_aaiCodedScale [ uiViewId ][ uiBaseId ]  = pcSlice->getInvCodedScale () [ uiBaseId ];
165        m_aaiCodedOffset[ uiViewId ][ uiBaseId ]  = pcSlice->getInvCodedOffset() [ uiBaseId ];
166      }
167      else
168      {
169        m_aaiCodedScale [ uiBaseId ][ uiViewId ]  = pcSlice->getSPS()->getCodedScale    () [ uiBaseId ];
170        m_aaiCodedOffset[ uiBaseId ][ uiViewId ]  = pcSlice->getSPS()->getCodedOffset   () [ uiBaseId ];
171        m_aaiCodedScale [ uiViewId ][ uiBaseId ]  = pcSlice->getSPS()->getInvCodedScale () [ uiBaseId ];
172        m_aaiCodedOffset[ uiViewId ][ uiBaseId ]  = pcSlice->getSPS()->getInvCodedOffset() [ uiBaseId ];
173      }
174    }
175  }
176  else
177  {
178    AOF( m_aiViewOrderIndex[ uiViewId ] == pcSlice->getSPS()->getViewOrderIdx() );
179    if( m_bCamParsVaryOverTime )
180    {
181      for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ )
182      {
183        m_aaiCodedScale [ uiBaseId ][ uiViewId ]  = pcSlice->getCodedScale    () [ uiBaseId ];
184        m_aaiCodedOffset[ uiBaseId ][ uiViewId ]  = pcSlice->getCodedOffset   () [ uiBaseId ];
185        m_aaiCodedScale [ uiViewId ][ uiBaseId ]  = pcSlice->getInvCodedScale () [ uiBaseId ];
186        m_aaiCodedOffset[ uiViewId ][ uiBaseId ]  = pcSlice->getInvCodedOffset() [ uiBaseId ];
187      }
188    }
189  }
190  m_iLastViewId = (Int)pcSlice->getSPS()->getViewId();
191  m_iLastPOC    = (Int)pcSlice->getPOC();
192}
193
194Bool
195CamParsCollector::xIsComplete()
196{
197  for( UInt uiView = 0; uiView <= m_uiMaxViewId; uiView++ )
198  {
199    if( m_aiViewReceived[ uiView ] == 0 )
200    {
201      return false;
202    }
203  }
204  return true;
205}
206
207Void
208CamParsCollector::xOutput( Int iPOC )
209{
210  if( m_pCodedScaleOffsetFile )
211  {
212    if( iPOC == 0 )
213    {
214      fprintf( m_pCodedScaleOffsetFile, "#     ViewId ViewOrderIdx\n" );
215      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------\n" );
216      for( UInt uiViewId = 0; uiViewId <= m_uiMaxViewId; uiViewId++ )
217      {
218        fprintf( m_pCodedScaleOffsetFile, "%12d %12d\n", uiViewId, m_aiViewOrderIndex[ uiViewId ] );
219      }
220      fprintf( m_pCodedScaleOffsetFile, "\n\n");
221      fprintf( m_pCodedScaleOffsetFile, "# StartFrame     EndFrame   TargetView     BaseView   CodedScale  CodedOffset    Precision\n" );
222      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------ ------------ ------------ ------------ ------------ ------------\n" );
223    }
224    if( iPOC == 0 || m_bCamParsVaryOverTime )
225    {
226      Int iS = iPOC;
227      Int iE = ( m_bCamParsVaryOverTime ? iPOC : ~( 1 << 31 ) );
228      for( UInt uiViewId = 0; uiViewId <= m_uiMaxViewId; uiViewId++ )
229      {
230        for( UInt uiBaseId = 0; uiBaseId <= m_uiMaxViewId; uiBaseId++ )
231        {
232          if( uiViewId != uiBaseId )
233          {
234            fprintf( m_pCodedScaleOffsetFile, "%12d %12d %12d %12d %12d %12d %12d\n",
235              iS, iE, uiViewId, uiBaseId, m_aaiCodedScale[ uiBaseId ][ uiViewId ], m_aaiCodedOffset[ uiBaseId ][ uiViewId ], m_uiCamParsCodedPrecision );
236          }
237        }
238      }
239    }
240  }
241}
242
243TDecTop::TDecTop()
244: m_SEIs(0)
245, m_tAppDecTop( NULL )
246, m_nalUnitTypeBaseView( NAL_UNIT_INVALID )
247{
248  m_pcPic = 0;
249  m_iGopSize      = 0;
250  m_bGopSizeSet   = false;
251  m_iMaxRefPicNum = 0;
252  m_uiValidPS = 0;
253#if SONY_COLPIC_AVAILABILITY
254  m_iViewOrderIdx = 0;
255#endif
256#if ENC_DEC_TRACE
257  g_hTrace = fopen( "TraceDec.txt", "wb" );
258  g_bJustDoIt = g_bEncDecTraceDisable;
259  g_nSymbolCounter = 0;
260#endif
261  m_bRefreshPending = 0;
262  m_pocCRA = 0;
263  m_pocRandomAccess = MAX_INT;         
264  m_prevPOC                = MAX_INT;
265  m_bFirstSliceInPicture    = true;
266  m_bFirstSliceInSequence   = true;
267  m_pcCamParsCollector = 0;
268}
269
270TDecTop::~TDecTop()
271{
272#if ENC_DEC_TRACE
273  fclose( g_hTrace );
274#endif
275}
276
277Void TDecTop::create()
278{
279  m_cGopDecoder.create();
280  m_apcSlicePilot = new TComSlice;
281  m_uiSliceIdx = m_uiLastSliceIdx = 0;
282}
283
284Void TDecTop::destroy()
285{
286  m_cGopDecoder.destroy();
287 
288  delete m_apcSlicePilot;
289  m_apcSlicePilot = NULL;
290 
291  m_cSliceDecoder.destroy();
292  m_tAppDecTop = NULL;
293
294#if DEPTH_MAP_GENERATION
295  m_cDepthMapGenerator.destroy();
296#endif
297#if HHI_INTER_VIEW_RESIDUAL_PRED
298  m_cResidualGenerator.destroy();
299#endif
300}
301
302Void TDecTop::init( TAppDecTop* pcTAppDecTop, Bool bFirstInstance )
303{
304  // initialize ROM
305  if( bFirstInstance )
306  {
307  initROM();
308  }
309  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cAdaptiveLoopFilter, &m_cSAO
310#if DEPTH_MAP_GENERATION
311                    , &m_cDepthMapGenerator
312#endif
313#if HHI_INTER_VIEW_RESIDUAL_PRED
314                    , &m_cResidualGenerator
315#endif
316    );
317  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
318  m_cEntropyDecoder.init(&m_cPrediction);
319  m_tAppDecTop = pcTAppDecTop;
320#if DEPTH_MAP_GENERATION
321  m_cDepthMapGenerator.init( &m_cPrediction, m_tAppDecTop->getSPSAccess(), m_tAppDecTop->getAUPicAccess() );
322#endif
323#if HHI_INTER_VIEW_RESIDUAL_PRED
324  m_cResidualGenerator.init( &m_cTrQuant, &m_cDepthMapGenerator );
325#endif
326}
327
328Void TDecTop::deletePicBuffer ( )
329{
330  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
331  Int iSize = Int( m_cListPic.size() );
332 
333  for (Int i = 0; i < iSize; i++ )
334  {
335    if( *iterPic )
336    {
337      TComPic* pcPic = *(iterPic++);
338      pcPic->destroy();
339   
340      delete pcPic;
341      pcPic = NULL;
342    }
343  }
344 
345  // destroy ALF temporary buffers
346  m_cAdaptiveLoopFilter.destroy();
347
348  m_cSAO.destroy();
349 
350  m_cLoopFilter.        destroy();
351 
352  // destroy ROM
353  if(m_viewId == 0 && m_isDepth == false)
354  {
355    destroyROM();
356  }
357}
358
359#if HHI_INTER_VIEW_RESIDUAL_PRED
360Void
361TDecTop::deleteExtraPicBuffers( Int iPoc )
362{
363  TComPic*                      pcPic = 0;
364  TComList<TComPic*>::iterator  cIter = m_cListPic.begin();
365  TComList<TComPic*>::iterator  cEnd  = m_cListPic.end  ();
366  for( ; cIter != cEnd; cIter++ )
367  {
368    if( (*cIter)->getPOC() == iPoc )
369    {
370      pcPic = *cIter;
371      break;
372    }
373  }
374  //AOF( pcPic );
375  if ( pcPic )
376  {
377    pcPic->removeResidualBuffer   ();
378  }
379}
380#endif
381
382
383Void
384TDecTop::compressMotion( Int iPoc )
385{
386  TComPic*                      pcPic = 0;
387  TComList<TComPic*>::iterator  cIter = m_cListPic.begin();
388  TComList<TComPic*>::iterator  cEnd  = m_cListPic.end  ();
389  for( ; cIter != cEnd; cIter++ )
390  {
391    if( (*cIter)->getPOC() == iPoc )
392    {
393      pcPic = *cIter;
394      break;
395    }
396  }
397//  AOF( pcPic );
398  if ( pcPic )
399  {
400    pcPic->compressMotion();
401  }
402}
403
404Void TDecTop::xUpdateGopSize (TComSlice* pcSlice)
405{
406  if ( !pcSlice->isIntra() && !m_bGopSizeSet)
407  {
408    m_iGopSize    = pcSlice->getPOC();
409    m_bGopSizeSet = true;
410   
411    m_cGopDecoder.setGopSize(m_iGopSize);
412  }
413}
414
415Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
416{
417  xUpdateGopSize(pcSlice);
418 
419#if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER
420  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer())+pcSlice->getSPS()->getNumReorderPics(pcSlice->getTLayer()) + 1; // +1 to have space for the picture currently being decoded
421#else
422  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxNumberOfReferencePictures()+pcSlice->getSPS()->getNumReorderFrames() + 1; // +1 to have space for the picture currently being decoded
423#endif
424
425#if DEPTH_MAP_GENERATION
426  UInt uiPdm                  = ( pcSlice->getSPS()->getViewId() ? pcSlice->getSPS()->getPredDepthMapGeneration() : m_tAppDecTop->getSPSAccess()->getPdm() );
427  Bool bNeedPrdDepthMapBuffer = ( !pcSlice->getSPS()->isDepth() && uiPdm > 0 );
428#endif
429
430  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
431  {
432    rpcPic = new TComPic();
433   
434    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true);
435   
436#if DEPTH_MAP_GENERATION
437    if( bNeedPrdDepthMapBuffer )
438    {
439      rpcPic->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
440    }
441#endif
442   
443    m_cListPic.pushBack( rpcPic );
444   
445    return;
446  }
447 
448  Bool bBufferIsAvailable = false;
449  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
450  while (iterPic != m_cListPic.end())
451  {
452    rpcPic = *(iterPic++);
453    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
454    {
455      rpcPic->setOutputMark(false);
456      bBufferIsAvailable = true;
457      break;
458    }
459
460    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
461    {
462      rpcPic->setOutputMark(false);
463      rpcPic->setReconMark( false );
464      rpcPic->getPicYuvRec()->setBorderExtension( false );
465      bBufferIsAvailable = true;
466      break;
467    }
468  }
469 
470  if ( !bBufferIsAvailable )
471  {
472    //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer.
473    m_iMaxRefPicNum++;
474    rpcPic = new TComPic();
475    m_cListPic.pushBack( rpcPic );
476  }
477  rpcPic->destroy(); 
478  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true);
479#if DEPTH_MAP_GENERATION
480  if( bNeedPrdDepthMapBuffer && !rpcPic->getPredDepthMap() )
481  {
482    rpcPic->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
483  }
484#endif
485}
486
487Void TDecTop::executeDeblockAndAlf(UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, Int& iSkipFrame, Int& iPOCLastDisplay)
488{
489  if (!m_pcPic)
490  {
491    /* nothing to deblock */
492    return;
493  }
494 
495  TComPic*&   pcPic         = m_pcPic;
496
497  // Execute Deblock and ALF only + Cleanup
498
499  m_cGopDecoder.decompressGop(NULL, pcPic, true);
500
501  TComSlice::sortPicList( m_cListPic ); // sorting for application output
502  ruiPOC              = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
503  rpcListPic          = &m_cListPic; 
504  m_cCuDecoder.destroy();       
505  m_bFirstSliceInPicture  = true;
506
507  return;
508}
509
510Void TDecTop::xCreateLostPicture(Int iLostPoc) 
511{
512  printf("\ninserting lost poc : %d\n",iLostPoc);
513  TComSlice cFillSlice;
514  cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
515  cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
516  cFillSlice.initSlice();
517  cFillSlice.initTiles();
518  TComPic *cFillPic;
519  xGetNewPicBuffer(&cFillSlice,cFillPic);
520  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
521  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
522  cFillPic->getSlice(0)->initSlice();
523  cFillPic->getSlice(0)->initTiles();
524
525 
526 
527  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
528  Int closestPoc = 1000000;
529  while ( iterPic != m_cListPic.end())
530  {
531    TComPic * rpcPic = *(iterPic++);
532    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())
533    {
534      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
535    }
536  }
537  iterPic = m_cListPic.begin();
538  while ( iterPic != m_cListPic.end())
539  {
540    TComPic *rpcPic = *(iterPic++);
541    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
542    {
543      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
544      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
545      break;
546    }
547  }
548  cFillPic->setCurrSliceIdx(0);
549  for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) 
550  {
551    cFillPic->getCU(i)->initCU(cFillPic,i);
552  }
553  cFillPic->getSlice(0)->setReferenced(true);
554  cFillPic->getSlice(0)->setPOC(iLostPoc);
555  cFillPic->setReconMark(true);
556  cFillPic->setOutputMark(true);
557  if(m_pocRandomAccess == MAX_INT)
558  {
559    m_pocRandomAccess = iLostPoc;
560  }
561}
562
563
564Void TDecTop::xActivateParameterSets()
565{
566  m_parameterSetManagerDecoder.applyPrefetchedPS();
567
568  TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
569  assert (pps != 0);
570
571  TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId());
572  assert (sps != 0);
573
574  m_apcSlicePilot->setPPS(pps);
575  m_apcSlicePilot->setSPS(sps);
576  pps->setSPS(sps);
577
578  if(sps->getUseSAO() || sps->getUseALF()|| sps->getScalingListFlag() || sps->getUseDF())
579  {
580    m_apcSlicePilot->setAPS( m_parameterSetManagerDecoder.getAPS(m_apcSlicePilot->getAPSId())  );
581  }
582  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
583
584  for (Int i = 0; i < sps->getMaxCUDepth() - 1; i++)
585  {
586    sps->setAMPAcc( i, sps->getUseAMP() );
587  }
588
589  for (Int i = sps->getMaxCUDepth() - 1; i < sps->getMaxCUDepth(); i++)
590  {
591    sps->setAMPAcc( i, 0 );
592  }
593
594#if !LCU_SYNTAX_ALF
595  // create ALF temporary buffer
596  m_cAdaptiveLoopFilter.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
597#endif
598  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
599  m_cLoopFilter.        create( g_uiMaxCUDepth );
600}
601
602#if SKIPFRAME_BUGFIX
603Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
604#else
605Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int iSkipFrame, Int iPOCLastDisplay )
606#endif
607{
608  TComPic*&   pcPic         = m_pcPic;
609  m_apcSlicePilot->initSlice();
610
611  //!!!KS: DIRTY HACK
612  m_apcSlicePilot->setPPSId(0);
613  m_apcSlicePilot->setPPS(m_parameterSetManagerDecoder.getPrefetchedPPS(0));
614  m_apcSlicePilot->setSPS(m_parameterSetManagerDecoder.getPrefetchedSPS(0));
615  m_apcSlicePilot->initTiles();
616
617  if (m_bFirstSliceInPicture)
618  {
619    m_uiSliceIdx     = 0;
620    m_uiLastSliceIdx = 0;
621  }
622  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
623  if (!m_bFirstSliceInPicture)
624  {
625    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
626  }
627
628  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
629  if( m_bFirstSliceInPicture )
630  {
631    if( nalu.m_viewId == 0 ) { m_nalUnitTypeBaseView = nalu.m_nalUnitType; }
632    else                     { m_nalUnitTypeBaseView = m_tAppDecTop->getTDecTop( 0, nalu.m_isDepth )->getNalUnitTypeBaseView(); }
633    m_apcSlicePilot->setNalUnitTypeBaseViewMvc( m_nalUnitTypeBaseView );
634  }
635
636#if SONY_COLPIC_AVAILABILITY
637  m_apcSlicePilot->setViewOrderIdx( m_apcSlicePilot->getSPS()->getViewOrderIdx());
638#endif
639
640#if NAL_REF_FLAG
641  m_apcSlicePilot->setReferenced(nalu.m_nalRefFlag);
642#else
643  m_apcSlicePilot->setReferenced(nalu.m_nalRefIDC != NAL_REF_IDC_PRIORITY_LOWEST);
644#endif
645  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
646
647  // ALF CU parameters should be part of the slice header -> needs to be fixed
648#if LCU_SYNTAX_ALF
649  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder, m_cGopDecoder.getAlfCuCtrlParam(), m_cGopDecoder.getAlfParamSet());
650#else
651  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder, m_cGopDecoder.getAlfCuCtrlParam() );
652#endif
653  // byte align
654  {
655    Int numBitsForByteAlignment = nalu.m_Bitstream->getNumBitsUntilByteAligned();
656    if ( numBitsForByteAlignment > 0 )
657    {
658      UInt bitsForByteAlignment;
659      nalu.m_Bitstream->read( numBitsForByteAlignment, bitsForByteAlignment );
660      assert( bitsForByteAlignment == ( ( 1 << numBitsForByteAlignment ) - 1 ) );
661    }
662  }
663
664  // exit when a new picture is found
665  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence)
666  {
667#if START_DECODING_AT_CRA
668    if (m_prevPOC >= m_pocRandomAccess)
669    {
670      m_prevPOC = m_apcSlicePilot->getPOC();
671      return true;
672    }
673    m_prevPOC = m_apcSlicePilot->getPOC();
674#else
675    m_prevPOC = m_apcSlicePilot->getPOC();
676    return true;
677#endif
678  }
679  // actual decoding starts here
680  xActivateParameterSets();
681  m_apcSlicePilot->initTiles();
682
683  if (m_apcSlicePilot->isNextSlice()) 
684  {
685    m_prevPOC = m_apcSlicePilot->getPOC();
686  }
687  m_bFirstSliceInSequence = false;
688  if (m_apcSlicePilot->isNextSlice())
689  {
690    // Skip pictures due to random access
691    if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
692    {
693      return false;
694    }
695  }
696  //detect lost reference picture and insert copy of earlier frame.
697#if START_DECODING_AT_CRA
698  while(m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess) > 0)
699#else
700  while(m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true) > 0)
701#endif
702  {
703    xCreateLostPicture(m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), false)-1);
704  }
705  if (m_bFirstSliceInPicture)
706  {
707    // Buffer initialize for prediction.
708    m_cPrediction.initTempBuff();
709    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
710    //  Get a new picture buffer
711    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
712
713#if SONY_COLPIC_AVAILABILITY
714    pcPic->setViewOrderIdx( m_apcSlicePilot->getSPS()->getViewOrderIdx() );
715#endif
716
717    /* transfer any SEI messages that have been received to the picture */
718    pcPic->setSEIs(m_SEIs);
719    m_SEIs = NULL;
720
721    // Recursive structure
722    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
723    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
724    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
725
726    m_cSliceDecoder.create( m_apcSlicePilot, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
727#if DEPTH_MAP_GENERATION
728    UInt uiPdm = ( m_apcSlicePilot->getSPS()->getViewId() ? m_apcSlicePilot->getSPS()->getPredDepthMapGeneration() : m_tAppDecTop->getSPSAccess()->getPdm() );
729    m_cDepthMapGenerator.create( true, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement, PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
730    TComDepthMapGenerator* pcDMG0 = m_tAppDecTop->getDecTop0()->getDepthMapGenerator();
731    if( m_apcSlicePilot->getSPS()->getViewId() == 1 && ( pcDMG0->getSubSampExpX() != PDM_SUB_SAMP_EXP_X(uiPdm) || pcDMG0->getSubSampExpY() != PDM_SUB_SAMP_EXP_Y(uiPdm) ) )
732    {
733      pcDMG0->create( true, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement, PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
734    }
735#endif
736#if HHI_INTER_VIEW_RESIDUAL_PRED
737    m_cResidualGenerator.create( true, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement );
738#endif
739  }
740
741  //  Set picture slice pointer
742  TComSlice*  pcSlice = m_apcSlicePilot;
743  Bool bNextSlice     = pcSlice->isNextSlice();
744
745  UInt uiCummulativeTileWidth;
746  UInt uiCummulativeTileHeight;
747  UInt i, j, p;
748
749#if !REMOVE_TILE_DEPENDENCE
750  //set the TileBoundaryIndependenceIdr
751  if(pcSlice->getPPS()->getTileBehaviorControlPresentFlag() == 1)
752  {
753    pcPic->getPicSym()->setTileBoundaryIndependenceIdr( pcSlice->getPPS()->getTileBoundaryIndependenceIdr() );
754  }
755  else
756  {
757    pcPic->getPicSym()->setTileBoundaryIndependenceIdr( pcSlice->getPPS()->getSPS()->getTileBoundaryIndependenceIdr() );
758  }
759#endif
760
761  if( pcSlice->getPPS()->getColumnRowInfoPresent() == 1 )
762  {
763    //set NumColumnsMins1 and NumRowsMinus1
764    pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
765    pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
766
767    //create the TComTileArray
768    pcPic->getPicSym()->xCreateTComTileArray();
769
770    if( pcSlice->getPPS()->getUniformSpacingIdr() == 1)
771    {
772      //set the width for each tile
773      for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
774      {
775        for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
776        {
777          pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
778            setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
779            - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
780        }
781      }
782
783      //set the height for each tile
784      for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
785      {
786        for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
787        {
788          pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
789            setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
790            - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
791        }
792      }
793    }
794    else
795    {
796      //set the width for each tile
797      for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
798      {
799        uiCummulativeTileWidth = 0;
800        for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
801        {
802          pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
803          uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
804        }
805        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
806      }
807
808      //set the height for each tile
809      for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
810      {
811        uiCummulativeTileHeight = 0;
812        for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
813        { 
814          pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
815          uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
816        }
817        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
818      }
819    }
820  }
821  else
822  {
823    //set NumColumnsMins1 and NumRowsMinus1
824    pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getSPS()->getNumColumnsMinus1() );
825    pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getSPS()->getNumRowsMinus1() );
826
827    //create the TComTileArray
828    pcPic->getPicSym()->xCreateTComTileArray();
829
830    //automatically set the column and row boundary if UniformSpacingIdr = 1
831    if( pcSlice->getSPS()->getUniformSpacingIdr() == 1 )
832    {
833      //set the width for each tile
834      for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
835      {
836        for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
837        {
838          pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
839            setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
840            - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
841        }
842      }
843
844      //set the height for each tile
845      for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
846      {
847        for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
848        {
849          pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
850            setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
851            - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
852        }
853      }
854    }
855    else
856    {
857      //set the width for each tile
858      for(j=0; j < pcSlice->getSPS()->getNumRowsMinus1()+1; j++)
859      {
860        uiCummulativeTileWidth = 0;
861        for(i=0; i < pcSlice->getSPS()->getNumColumnsMinus1(); i++)
862        {
863          pcPic->getPicSym()->getTComTile(j * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getSPS()->getColumnWidth(i) );
864          uiCummulativeTileWidth += pcSlice->getSPS()->getColumnWidth(i);
865        }
866        pcPic->getPicSym()->getTComTile(j * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
867      }
868
869      //set the height for each tile
870      for(j=0; j < pcSlice->getSPS()->getNumColumnsMinus1()+1; j++)
871      {
872        uiCummulativeTileHeight = 0;
873        for(i=0; i < pcSlice->getSPS()->getNumRowsMinus1(); i++)
874        { 
875          pcPic->getPicSym()->getTComTile(i * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getSPS()->getRowHeight(i) );
876          uiCummulativeTileHeight += pcSlice->getSPS()->getRowHeight(i);
877        }
878        pcPic->getPicSym()->getTComTile(i * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
879      }
880    }
881  }
882
883  pcPic->getPicSym()->xInitTiles();
884
885  //generate the Coding Order Map and Inverse Coding Order Map
886  UInt uiEncCUAddr;
887  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
888  {
889    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
890    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
891  }
892  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
893  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
894
895  //convert the start and end CU addresses of the slice and entropy slice into encoding order
896  pcSlice->setEntropySliceCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getEntropySliceCurStartCUAddr()) );
897  pcSlice->setEntropySliceCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getEntropySliceCurEndCUAddr()) );
898  if(pcSlice->isNextSlice())
899  {
900    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
901    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
902  }
903
904  if (m_bFirstSliceInPicture) 
905  {
906    if(pcPic->getNumAllocatedSlice() != 1)
907    {
908      pcPic->clearSliceBuffer();
909    }
910  }
911  else
912  {
913    pcPic->allocateNewSlice();
914  }
915  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
916  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
917  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
918
919  pcPic->setTLayer(nalu.m_temporalId);
920
921  if (bNextSlice)
922  {
923    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_cListPic); 
924
925    if ( !pcSlice->getPPS()->getEnableTMVPFlag() && pcPic->getTLayer() == 0 )
926    {
927      pcSlice->decodingMarkingForNoTMVP( m_cListPic, pcSlice->getPOC() );
928    }
929
930    // Set reference list
931    pcSlice->setViewId(m_viewId);
932    pcSlice->setIsDepth(m_isDepth);
933
934#if SONY_COLPIC_AVAILABILITY
935    pcSlice->setViewOrderIdx( pcPic->getViewOrderIdx() );
936#endif
937
938    assert( m_tAppDecTop != NULL );
939    TComPic * const pcTexturePic = m_isDepth ? m_tAppDecTop->getPicFromView(  m_viewId, pcSlice->getPOC(), false ) : NULL;
940    assert( !m_isDepth || pcTexturePic != NULL );
941    pcSlice->setTexturePic( pcTexturePic );
942
943    std::vector<TComPic*> apcInterViewRefPics = m_tAppDecTop->getInterViewRefPics( m_viewId, pcSlice->getPOC(), m_isDepth, pcSlice->getSPS() );
944    pcSlice->setRefPicListMvc( m_cListPic, apcInterViewRefPics );
945
946    // For generalized B
947    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
948    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
949    {
950      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
951      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
952
953      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
954      {
955        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
956      }
957    }
958    if (pcSlice->isInterB())
959    {
960      Bool bLowDelay = true;
961      Int  iCurrPOC  = pcSlice->getPOC();
962      Int iRefIdx = 0;
963
964      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
965      {
966        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
967        {
968          bLowDelay = false;
969        }
970      }
971      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
972      {
973        if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
974        {
975          bLowDelay = false;
976        }
977      }
978
979      pcSlice->setCheckLDC(bLowDelay);           
980    }
981
982    //---------------
983    pcSlice->setRefPOCnViewListsMvc();
984
985    if(!pcSlice->getRefPicListModificationFlagLC())
986    {
987      pcSlice->generateCombinedList();
988    }
989
990    if( pcSlice->getRefPicListCombinationFlag() && pcSlice->getPPS()->getWPBiPredIdc()==1 && pcSlice->getSliceType()==B_SLICE )
991    {
992      pcSlice->setWpParamforLC();
993    }
994    pcSlice->setNoBackPredFlag( false );
995    if ( pcSlice->getSliceType() == B_SLICE && !pcSlice->getRefPicListCombinationFlag())
996    {
997      if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) )
998      {
999        pcSlice->setNoBackPredFlag( true );
1000        for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ )
1001        {
1002          if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) 
1003          {
1004            pcSlice->setNoBackPredFlag( false );
1005            break;
1006          }
1007        }
1008      }
1009    }
1010  }
1011
1012  pcPic->setCurrSliceIdx(m_uiSliceIdx);
1013  if(pcSlice->getSPS()->getScalingListFlag())
1014  {
1015    if(pcSlice->getAPS()->getScalingListEnabled())
1016    {
1017      pcSlice->setScalingList ( pcSlice->getAPS()->getScalingList()  );
1018      if(pcSlice->getScalingList()->getScalingListPresentFlag())
1019      {
1020        pcSlice->setDefaultScalingList();
1021      }
1022      m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
1023    }
1024    m_cTrQuant.setUseScalingList(true);
1025  }
1026  else
1027  {
1028    m_cTrQuant.setFlatScalingList();
1029    m_cTrQuant.setUseScalingList(false);
1030  }
1031
1032#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
1033  if( m_parameterSetManagerDecoder.getPrefetchedSPS(0)->getUseDMM() && g_aacWedgeLists.empty() )
1034  {
1035    initWedgeLists();
1036  }
1037#endif
1038
1039  //  Decode a picture
1040  m_cGopDecoder.decompressGop(nalu.m_Bitstream, pcPic, false);
1041
1042  if( m_pcCamParsCollector )
1043  {
1044    m_pcCamParsCollector->setSlice( pcSlice );
1045  }
1046
1047  m_bFirstSliceInPicture = false;
1048  m_uiSliceIdx++;
1049
1050  return false;
1051}
1052
1053
1054Void TDecTop::xDecodeSPS()
1055{
1056  TComSPS* sps = new TComSPS();
1057#if RPS_IN_SPS
1058  TComRPSList* rps = new TComRPSList();
1059  sps->setRPSList(rps);
1060#endif
1061#if HHI_MPI
1062  m_cEntropyDecoder.decodeSPS( sps, m_isDepth );
1063#else
1064  m_cEntropyDecoder.decodeSPS( sps );
1065#endif
1066  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
1067#if LCU_SYNTAX_ALF
1068  m_cAdaptiveLoopFilter.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
1069#endif
1070}
1071
1072Void TDecTop::xDecodePPS()
1073{
1074#if !RPS_IN_SPS
1075  TComRPSList* rps = new TComRPSList();
1076#endif
1077  TComPPS* pps = new TComPPS();
1078#if !RPS_IN_SPS
1079  pps->setRPSList(rps);
1080#endif
1081#if TILES_OR_ENTROPY_SYNC_IDC
1082  m_cEntropyDecoder.decodePPS( pps, &m_parameterSetManagerDecoder );
1083#else
1084  m_cEntropyDecoder.decodePPS( pps );
1085#endif
1086  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
1087
1088  //!!!KS: Activate parameter sets for parsing APS (unless dependency is resolved)
1089  m_apcSlicePilot->setPPSId(pps->getPPSId());
1090  xActivateParameterSets();
1091  m_apcSlicePilot->initTiles();
1092}
1093
1094Void TDecTop::xDecodeAPS()
1095{
1096  TComAPS  *aps = new TComAPS();
1097  allocAPS (aps);
1098  decodeAPS(aps);
1099  m_parameterSetManagerDecoder.storePrefetchedAPS(aps);
1100}
1101
1102Void TDecTop::xDecodeSEI()
1103{
1104  m_SEIs = new SEImessages;
1105  m_cEntropyDecoder.decodeSEI(*m_SEIs);
1106}
1107
1108Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1109{
1110  // Initialize entropy decoder
1111  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1112  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
1113
1114  switch (nalu.m_nalUnitType)
1115  {
1116    case NAL_UNIT_SPS:
1117      xDecodeSPS();
1118      return false;
1119
1120    case NAL_UNIT_PPS:
1121      xDecodePPS();
1122      return false;
1123    case NAL_UNIT_APS:
1124      xDecodeAPS();
1125      return false;
1126
1127    case NAL_UNIT_SEI:
1128      xDecodeSEI();
1129      return false;
1130
1131    case NAL_UNIT_CODED_SLICE:
1132    case NAL_UNIT_CODED_SLICE_IDR:
1133#if H0566_TLA
1134    case NAL_UNIT_CODED_SLICE_IDV:
1135    case NAL_UNIT_CODED_SLICE_CRA:
1136    case NAL_UNIT_CODED_SLICE_TLA:
1137#else
1138    case NAL_UNIT_CODED_SLICE_CDR:
1139#endif
1140      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1141      break;
1142    default:
1143      assert (1);
1144  }
1145
1146  return false;
1147}
1148
1149/** Function for checking if picture should be skipped because of random access
1150 * \param iSkipFrame skip frame counter
1151 * \param iPOCLastDisplay POC of last picture displayed
1152 * \returns true if the picture shold be skipped in the random access.
1153 * This function checks the skipping of pictures in the case of -s option random access.
1154 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1155 * It also checks the type of Nal unit type at the random access point.
1156 * If the random access point is CRA, pictures with POC equal to or greater than the CRA POC are decoded.
1157 * If the random access point is IDR all pictures after the random access point are decoded.
1158 * If the random access point is not IDR or CRA, a warning is issues, and decoding of pictures with POC
1159 * equal to or greater than the random access point POC is attempted. For non IDR/CRA random
1160 * access point there is no guarantee that the decoder will not crash.
1161 */
1162Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
1163{
1164  if (iSkipFrame) 
1165  {
1166    iSkipFrame--;   // decrement the counter
1167    return true;
1168  }
1169  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1170  {
1171#if H0566_TLA
1172    if( m_apcSlicePilot->getNalUnitTypeBaseViewMvc() == NAL_UNIT_CODED_SLICE_CRA )
1173#else
1174    if( m_apcSlicePilot->getNalUnitTypeBaseViewMvc() == NAL_UNIT_CODED_SLICE_CDR )
1175#endif
1176    {
1177      m_pocRandomAccess = m_apcSlicePilot->getPOC(); // set the POC random access since we need to skip the reordered pictures in CRA.
1178    }
1179    else if( m_apcSlicePilot->getNalUnitTypeBaseViewMvc() == NAL_UNIT_CODED_SLICE_IDR )
1180    {
1181      m_pocRandomAccess = 0; // no need to skip the reordered pictures in IDR, they are decodable.
1182    }
1183    else 
1184    {
1185#if START_DECODING_AT_CRA
1186      static bool warningMessage = false;
1187      if(!warningMessage)
1188      {
1189        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1190        warningMessage = true;
1191      }
1192      return true;
1193#else
1194      printf("\nUnsafe random access point. Decoder may crash.");
1195      m_pocRandomAccess = 0;
1196#endif
1197    }
1198  }
1199  else if (m_apcSlicePilot->getPOC() < m_pocRandomAccess)  // skip the reordered pictures if necessary
1200  {
1201    iPOCLastDisplay++;
1202    return true;
1203  }
1204  // if we reach here, then the picture is not skipped.
1205  return false; 
1206}
1207
1208Void TDecTop::allocAPS (TComAPS* pAPS)
1209{
1210  // we don't know the SPS before it has been activated. These fields could exist
1211  // depending on the corresponding flags in the APS, but SAO/ALF allocation functions will
1212  // have to be moved for that
1213  pAPS->createScalingList();
1214  pAPS->createSaoParam();
1215  m_cSAO.allocSaoParam(pAPS->getSaoParam());
1216  pAPS->createAlfParam();
1217#if !LCU_SYNTAX_ALF
1218  m_cAdaptiveLoopFilter.allocALFParam(pAPS->getAlfParam());
1219#endif
1220}
1221
1222//! \}
Note: See TracBrowser for help on using the repository browser.