source: 3DVCSoftware/trunk/source/Lib/TLibDecoder/TDecTop.cpp @ 56

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

updated trunk (move to HM6.1)

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