source: 3DVCSoftware/branches/HTM-3.0-Vidyo/source/Lib/TLibDecoder/TDecTop.cpp @ 70

Last change on this file since 70 was 70, checked in by vidyo, 13 years ago
  • Property svn:eol-style set to native
File size: 42.0 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#if VIDYO_VPS_INTEGRATION
574  TComVPS *vps = m_parameterSetManagerDecoder.getVPS(sps->getVPSId());
575  assert (vps != 0);
576#endif
577  m_apcSlicePilot->setPPS(pps);
578  m_apcSlicePilot->setSPS(sps);
579#if VIDYO_VPS_INTEGRATION
580  m_apcSlicePilot->setVPS(vps);
581#endif
582  pps->setSPS(sps);
583
584  if(sps->getUseSAO() || sps->getUseALF()|| sps->getScalingListFlag() || sps->getUseDF())
585  {
586    m_apcSlicePilot->setAPS( m_parameterSetManagerDecoder.getAPS(m_apcSlicePilot->getAPSId())  );
587  }
588  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
589
590  for (Int i = 0; i < sps->getMaxCUDepth() - 1; i++)
591  {
592    sps->setAMPAcc( i, sps->getUseAMP() );
593  }
594
595  for (Int i = sps->getMaxCUDepth() - 1; i < sps->getMaxCUDepth(); i++)
596  {
597    sps->setAMPAcc( i, 0 );
598  }
599
600#if !LCU_SYNTAX_ALF
601  // create ALF temporary buffer
602  m_cAdaptiveLoopFilter.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
603#endif
604  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
605  m_cLoopFilter.        create( g_uiMaxCUDepth );
606}
607
608#if SKIPFRAME_BUGFIX
609Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
610#else
611Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int iSkipFrame, Int iPOCLastDisplay )
612#endif
613{
614  TComPic*&   pcPic         = m_pcPic;
615  m_apcSlicePilot->initSlice();
616
617  //!!!KS: DIRTY HACK
618  m_apcSlicePilot->setPPSId(0);
619  m_apcSlicePilot->setPPS(m_parameterSetManagerDecoder.getPrefetchedPPS(0));
620  m_apcSlicePilot->setSPS(m_parameterSetManagerDecoder.getPrefetchedSPS(0));
621#if VIDYO_VPS_INTEGRATION
622  m_apcSlicePilot->setVPS(m_parameterSetManagerDecoder.getPrefetchedVPS(0));
623#endif
624  m_apcSlicePilot->initTiles();
625
626  if (m_bFirstSliceInPicture)
627  {
628    m_uiSliceIdx     = 0;
629    m_uiLastSliceIdx = 0;
630  }
631  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
632  if (!m_bFirstSliceInPicture)
633  {
634    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
635  }
636
637  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
638  if( m_bFirstSliceInPicture )
639  {
640#if VIDYO_VPS_INTEGRATION
641    if( m_apcSlicePilot->getVPS()->getViewId(nalu.m_layerId) == 0 ) { m_nalUnitTypeBaseView = nalu.m_nalUnitType; }
642    else { m_nalUnitTypeBaseView = m_tAppDecTop->getTDecTop( 0, m_apcSlicePilot->getVPS()->getDepthFlag(nalu.m_layerId) )->getNalUnitTypeBaseView(); }
643#else
644    if( nalu.m_viewId == 0 ) { m_nalUnitTypeBaseView = nalu.m_nalUnitType; }
645    else                     { m_nalUnitTypeBaseView = m_tAppDecTop->getTDecTop( 0, nalu.m_isDepth )->getNalUnitTypeBaseView(); }
646#endif
647   
648    m_apcSlicePilot->setNalUnitTypeBaseViewMvc( m_nalUnitTypeBaseView );
649  }
650
651#if SONY_COLPIC_AVAILABILITY
652  m_apcSlicePilot->setViewOrderIdx( m_apcSlicePilot->getSPS()->getViewOrderIdx());
653#endif
654
655#if NAL_REF_FLAG
656  m_apcSlicePilot->setReferenced(nalu.m_nalRefFlag);
657#else
658  m_apcSlicePilot->setReferenced(nalu.m_nalRefIDC != NAL_REF_IDC_PRIORITY_LOWEST);
659#endif
660  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
661
662  // ALF CU parameters should be part of the slice header -> needs to be fixed
663#if LCU_SYNTAX_ALF
664  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder, m_cGopDecoder.getAlfCuCtrlParam(), m_cGopDecoder.getAlfParamSet());
665#else
666  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder, m_cGopDecoder.getAlfCuCtrlParam() );
667#endif
668  // byte align
669  {
670    Int numBitsForByteAlignment = nalu.m_Bitstream->getNumBitsUntilByteAligned();
671    if ( numBitsForByteAlignment > 0 )
672    {
673      UInt bitsForByteAlignment;
674      nalu.m_Bitstream->read( numBitsForByteAlignment, bitsForByteAlignment );
675      assert( bitsForByteAlignment == ( ( 1 << numBitsForByteAlignment ) - 1 ) );
676    }
677  }
678
679  // exit when a new picture is found
680  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence)
681  {
682#if START_DECODING_AT_CRA
683    if (m_prevPOC >= m_pocRandomAccess)
684    {
685      m_prevPOC = m_apcSlicePilot->getPOC();
686      return true;
687    }
688    m_prevPOC = m_apcSlicePilot->getPOC();
689#else
690    m_prevPOC = m_apcSlicePilot->getPOC();
691    return true;
692#endif
693  }
694  // actual decoding starts here
695  xActivateParameterSets();
696  m_apcSlicePilot->initTiles();
697
698  if (m_apcSlicePilot->isNextSlice()) 
699  {
700    m_prevPOC = m_apcSlicePilot->getPOC();
701  }
702  m_bFirstSliceInSequence = false;
703  if (m_apcSlicePilot->isNextSlice())
704  {
705    // Skip pictures due to random access
706    if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
707    {
708      return false;
709    }
710  }
711  //detect lost reference picture and insert copy of earlier frame.
712#if START_DECODING_AT_CRA
713  while(m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess) > 0)
714#else
715  while(m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true) > 0)
716#endif
717  {
718    xCreateLostPicture(m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), false)-1);
719  }
720  if (m_bFirstSliceInPicture)
721  {
722    // Buffer initialize for prediction.
723    m_cPrediction.initTempBuff();
724    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
725    //  Get a new picture buffer
726    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
727
728#if SONY_COLPIC_AVAILABILITY
729    pcPic->setViewOrderIdx( m_apcSlicePilot->getSPS()->getViewOrderIdx() );
730#endif
731
732    /* transfer any SEI messages that have been received to the picture */
733    pcPic->setSEIs(m_SEIs);
734    m_SEIs = NULL;
735
736    // Recursive structure
737    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
738    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
739    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
740
741    m_cSliceDecoder.create( m_apcSlicePilot, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
742#if DEPTH_MAP_GENERATION
743    UInt uiPdm = ( m_apcSlicePilot->getSPS()->getViewId() ? m_apcSlicePilot->getSPS()->getPredDepthMapGeneration() : m_tAppDecTop->getSPSAccess()->getPdm() );
744    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) );
745    TComDepthMapGenerator* pcDMG0 = m_tAppDecTop->getDecTop0()->getDepthMapGenerator();
746    if( m_apcSlicePilot->getSPS()->getViewId() == 1 && ( pcDMG0->getSubSampExpX() != PDM_SUB_SAMP_EXP_X(uiPdm) || pcDMG0->getSubSampExpY() != PDM_SUB_SAMP_EXP_Y(uiPdm) ) )
747    {
748      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) );
749    }
750#endif
751#if HHI_INTER_VIEW_RESIDUAL_PRED
752    m_cResidualGenerator.create( true, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement );
753#endif
754  }
755
756  //  Set picture slice pointer
757  TComSlice*  pcSlice = m_apcSlicePilot;
758  Bool bNextSlice     = pcSlice->isNextSlice();
759
760  UInt uiCummulativeTileWidth;
761  UInt uiCummulativeTileHeight;
762  UInt i, j, p;
763
764#if !REMOVE_TILE_DEPENDENCE
765  //set the TileBoundaryIndependenceIdr
766  if(pcSlice->getPPS()->getTileBehaviorControlPresentFlag() == 1)
767  {
768    pcPic->getPicSym()->setTileBoundaryIndependenceIdr( pcSlice->getPPS()->getTileBoundaryIndependenceIdr() );
769  }
770  else
771  {
772    pcPic->getPicSym()->setTileBoundaryIndependenceIdr( pcSlice->getPPS()->getSPS()->getTileBoundaryIndependenceIdr() );
773  }
774#endif
775
776  if( pcSlice->getPPS()->getColumnRowInfoPresent() == 1 )
777  {
778    //set NumColumnsMins1 and NumRowsMinus1
779    pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
780    pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
781
782    //create the TComTileArray
783    pcPic->getPicSym()->xCreateTComTileArray();
784
785    if( pcSlice->getPPS()->getUniformSpacingIdr() == 1)
786    {
787      //set the width for each tile
788      for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
789      {
790        for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
791        {
792          pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
793            setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
794            - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
795        }
796      }
797
798      //set the height for each tile
799      for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
800      {
801        for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
802        {
803          pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
804            setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
805            - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
806        }
807      }
808    }
809    else
810    {
811      //set the width for each tile
812      for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
813      {
814        uiCummulativeTileWidth = 0;
815        for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
816        {
817          pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
818          uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
819        }
820        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
821      }
822
823      //set the height for each tile
824      for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
825      {
826        uiCummulativeTileHeight = 0;
827        for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
828        { 
829          pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
830          uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
831        }
832        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
833      }
834    }
835  }
836  else
837  {
838    //set NumColumnsMins1 and NumRowsMinus1
839    pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getSPS()->getNumColumnsMinus1() );
840    pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getSPS()->getNumRowsMinus1() );
841
842    //create the TComTileArray
843    pcPic->getPicSym()->xCreateTComTileArray();
844
845    //automatically set the column and row boundary if UniformSpacingIdr = 1
846    if( pcSlice->getSPS()->getUniformSpacingIdr() == 1 )
847    {
848      //set the width for each tile
849      for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
850      {
851        for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
852        {
853          pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
854            setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
855            - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
856        }
857      }
858
859      //set the height for each tile
860      for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
861      {
862        for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
863        {
864          pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
865            setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
866            - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
867        }
868      }
869    }
870    else
871    {
872      //set the width for each tile
873      for(j=0; j < pcSlice->getSPS()->getNumRowsMinus1()+1; j++)
874      {
875        uiCummulativeTileWidth = 0;
876        for(i=0; i < pcSlice->getSPS()->getNumColumnsMinus1(); i++)
877        {
878          pcPic->getPicSym()->getTComTile(j * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getSPS()->getColumnWidth(i) );
879          uiCummulativeTileWidth += pcSlice->getSPS()->getColumnWidth(i);
880        }
881        pcPic->getPicSym()->getTComTile(j * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
882      }
883
884      //set the height for each tile
885      for(j=0; j < pcSlice->getSPS()->getNumColumnsMinus1()+1; j++)
886      {
887        uiCummulativeTileHeight = 0;
888        for(i=0; i < pcSlice->getSPS()->getNumRowsMinus1(); i++)
889        { 
890          pcPic->getPicSym()->getTComTile(i * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getSPS()->getRowHeight(i) );
891          uiCummulativeTileHeight += pcSlice->getSPS()->getRowHeight(i);
892        }
893        pcPic->getPicSym()->getTComTile(i * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
894      }
895    }
896  }
897
898  pcPic->getPicSym()->xInitTiles();
899
900  //generate the Coding Order Map and Inverse Coding Order Map
901  UInt uiEncCUAddr;
902  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
903  {
904    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
905    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
906  }
907  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
908  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
909
910  //convert the start and end CU addresses of the slice and entropy slice into encoding order
911  pcSlice->setEntropySliceCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getEntropySliceCurStartCUAddr()) );
912  pcSlice->setEntropySliceCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getEntropySliceCurEndCUAddr()) );
913  if(pcSlice->isNextSlice())
914  {
915    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
916    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
917  }
918
919  if (m_bFirstSliceInPicture) 
920  {
921    if(pcPic->getNumAllocatedSlice() != 1)
922    {
923      pcPic->clearSliceBuffer();
924    }
925  }
926  else
927  {
928    pcPic->allocateNewSlice();
929  }
930  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
931  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
932  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
933
934  pcPic->setTLayer(nalu.m_temporalId);
935
936  if (bNextSlice)
937  {
938    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_cListPic); 
939
940    if ( !pcSlice->getPPS()->getEnableTMVPFlag() && pcPic->getTLayer() == 0 )
941    {
942      pcSlice->decodingMarkingForNoTMVP( m_cListPic, pcSlice->getPOC() );
943    }
944
945    // Set reference list
946#if VIDYO_VPS_INTEGRATION
947    pcSlice->setViewId( pcSlice->getVPS()->getViewId(nalu.m_layerId) );
948    pcSlice->setIsDepth( pcSlice->getVPS()->getDepthFlag(nalu.m_layerId) );
949#else
950    pcSlice->setViewId(m_viewId);
951    pcSlice->setIsDepth(m_isDepth);
952#endif
953   
954#if SONY_COLPIC_AVAILABILITY
955#if VIDYO_VPS_INTEGRATION
956    pcSlice->setViewOrderIdx( pcSlice->getVPS()->getViewOrderIdx(nalu.m_layerId) );
957#else
958    pcSlice->setViewOrderIdx( pcPic->getViewOrderIdx() );
959#endif
960#endif
961
962    assert( m_tAppDecTop != NULL );
963    TComPic * const pcTexturePic = m_isDepth ? m_tAppDecTop->getPicFromView(  m_viewId, pcSlice->getPOC(), false ) : NULL;
964    assert( !m_isDepth || pcTexturePic != NULL );
965    pcSlice->setTexturePic( pcTexturePic );
966
967    std::vector<TComPic*> apcInterViewRefPics = m_tAppDecTop->getInterViewRefPics( m_viewId, pcSlice->getPOC(), m_isDepth, pcSlice->getSPS() );
968    pcSlice->setRefPicListMvc( m_cListPic, apcInterViewRefPics );
969
970    // For generalized B
971    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
972    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
973    {
974      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
975      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
976
977      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
978      {
979        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
980      }
981    }
982    if (pcSlice->isInterB())
983    {
984      Bool bLowDelay = true;
985      Int  iCurrPOC  = pcSlice->getPOC();
986      Int iRefIdx = 0;
987
988      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
989      {
990        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
991        {
992          bLowDelay = false;
993        }
994      }
995      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
996      {
997        if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
998        {
999          bLowDelay = false;
1000        }
1001      }
1002
1003      pcSlice->setCheckLDC(bLowDelay);           
1004    }
1005
1006    //---------------
1007    pcSlice->setRefPOCnViewListsMvc();
1008
1009    if(!pcSlice->getRefPicListModificationFlagLC())
1010    {
1011      pcSlice->generateCombinedList();
1012    }
1013
1014    if( pcSlice->getRefPicListCombinationFlag() && pcSlice->getPPS()->getWPBiPredIdc()==1 && pcSlice->getSliceType()==B_SLICE )
1015    {
1016      pcSlice->setWpParamforLC();
1017    }
1018    pcSlice->setNoBackPredFlag( false );
1019    if ( pcSlice->getSliceType() == B_SLICE && !pcSlice->getRefPicListCombinationFlag())
1020    {
1021      if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) )
1022      {
1023        pcSlice->setNoBackPredFlag( true );
1024        for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ )
1025        {
1026          if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) 
1027          {
1028            pcSlice->setNoBackPredFlag( false );
1029            break;
1030          }
1031        }
1032      }
1033    }
1034  }
1035
1036  pcPic->setCurrSliceIdx(m_uiSliceIdx);
1037  if(pcSlice->getSPS()->getScalingListFlag())
1038  {
1039    if(pcSlice->getAPS()->getScalingListEnabled())
1040    {
1041      pcSlice->setScalingList ( pcSlice->getAPS()->getScalingList()  );
1042      if(pcSlice->getScalingList()->getScalingListPresentFlag())
1043      {
1044        pcSlice->setDefaultScalingList();
1045      }
1046      m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
1047    }
1048    m_cTrQuant.setUseScalingList(true);
1049  }
1050  else
1051  {
1052    m_cTrQuant.setFlatScalingList();
1053    m_cTrQuant.setUseScalingList(false);
1054  }
1055
1056#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
1057  if( m_parameterSetManagerDecoder.getPrefetchedSPS(0)->getUseDMM() && g_aacWedgeLists.empty() )
1058  {
1059    initWedgeLists();
1060  }
1061#endif
1062
1063  //  Decode a picture
1064  m_cGopDecoder.decompressGop(nalu.m_Bitstream, pcPic, false);
1065
1066  if( m_pcCamParsCollector )
1067  {
1068    m_pcCamParsCollector->setSlice( pcSlice );
1069  }
1070
1071  m_bFirstSliceInPicture = false;
1072  m_uiSliceIdx++;
1073
1074  return false;
1075}
1076
1077#if VIDYO_VPS_INTEGRATION
1078Void TDecTop::xDecodeVPS()
1079{
1080  TComVPS* vps = new TComVPS();
1081 
1082  m_cEntropyDecoder.decodeVPS( vps );
1083  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
1084
1085}
1086#endif
1087
1088Void TDecTop::xDecodeSPS()
1089{
1090  TComSPS* sps = new TComSPS();
1091#if RPS_IN_SPS
1092  TComRPSList* rps = new TComRPSList();
1093  sps->setRPSList(rps);
1094#endif
1095#if HHI_MPI
1096  m_cEntropyDecoder.decodeSPS( sps, m_isDepth );
1097#else
1098  m_cEntropyDecoder.decodeSPS( sps );
1099#endif
1100  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
1101#if LCU_SYNTAX_ALF
1102  m_cAdaptiveLoopFilter.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
1103#endif
1104}
1105
1106Void TDecTop::xDecodePPS()
1107{
1108#if !RPS_IN_SPS
1109  TComRPSList* rps = new TComRPSList();
1110#endif
1111  TComPPS* pps = new TComPPS();
1112#if !RPS_IN_SPS
1113  pps->setRPSList(rps);
1114#endif
1115#if TILES_OR_ENTROPY_SYNC_IDC
1116  m_cEntropyDecoder.decodePPS( pps, &m_parameterSetManagerDecoder );
1117#else
1118  m_cEntropyDecoder.decodePPS( pps );
1119#endif
1120  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
1121
1122  //!!!KS: Activate parameter sets for parsing APS (unless dependency is resolved)
1123  m_apcSlicePilot->setPPSId(pps->getPPSId());
1124  xActivateParameterSets();
1125  m_apcSlicePilot->initTiles();
1126}
1127
1128Void TDecTop::xDecodeAPS()
1129{
1130  TComAPS  *aps = new TComAPS();
1131  allocAPS (aps);
1132  decodeAPS(aps);
1133  m_parameterSetManagerDecoder.storePrefetchedAPS(aps);
1134}
1135
1136Void TDecTop::xDecodeSEI()
1137{
1138  m_SEIs = new SEImessages;
1139  m_cEntropyDecoder.decodeSEI(*m_SEIs);
1140}
1141
1142Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1143{
1144  // Initialize entropy decoder
1145  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1146  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
1147
1148  switch (nalu.m_nalUnitType)
1149  {
1150#if VIDYO_VPS_INTEGRATION
1151    case NAL_UNIT_VPS:
1152      xDecodeVPS();
1153      return false;
1154#endif
1155    case NAL_UNIT_SPS:
1156      xDecodeSPS();
1157      return false;
1158
1159    case NAL_UNIT_PPS:
1160      xDecodePPS();
1161      return false;
1162    case NAL_UNIT_APS:
1163      xDecodeAPS();
1164      return false;
1165
1166    case NAL_UNIT_SEI:
1167      xDecodeSEI();
1168      return false;
1169
1170    case NAL_UNIT_CODED_SLICE:
1171    case NAL_UNIT_CODED_SLICE_IDR:
1172#if H0566_TLA
1173    case NAL_UNIT_CODED_SLICE_IDV:
1174    case NAL_UNIT_CODED_SLICE_CRA:
1175    case NAL_UNIT_CODED_SLICE_TLA:
1176#else
1177    case NAL_UNIT_CODED_SLICE_CDR:
1178#endif
1179      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1180      break;
1181    default:
1182      assert (1);
1183  }
1184
1185  return false;
1186}
1187
1188/** Function for checking if picture should be skipped because of random access
1189 * \param iSkipFrame skip frame counter
1190 * \param iPOCLastDisplay POC of last picture displayed
1191 * \returns true if the picture shold be skipped in the random access.
1192 * This function checks the skipping of pictures in the case of -s option random access.
1193 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1194 * It also checks the type of Nal unit type at the random access point.
1195 * If the random access point is CRA, pictures with POC equal to or greater than the CRA POC are decoded.
1196 * If the random access point is IDR all pictures after the random access point are decoded.
1197 * If the random access point is not IDR or CRA, a warning is issues, and decoding of pictures with POC
1198 * equal to or greater than the random access point POC is attempted. For non IDR/CRA random
1199 * access point there is no guarantee that the decoder will not crash.
1200 */
1201Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
1202{
1203  if (iSkipFrame) 
1204  {
1205    iSkipFrame--;   // decrement the counter
1206    return true;
1207  }
1208  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1209  {
1210#if H0566_TLA
1211    if( m_apcSlicePilot->getNalUnitTypeBaseViewMvc() == NAL_UNIT_CODED_SLICE_CRA )
1212#else
1213    if( m_apcSlicePilot->getNalUnitTypeBaseViewMvc() == NAL_UNIT_CODED_SLICE_CDR )
1214#endif
1215    {
1216      m_pocRandomAccess = m_apcSlicePilot->getPOC(); // set the POC random access since we need to skip the reordered pictures in CRA.
1217    }
1218    else if( m_apcSlicePilot->getNalUnitTypeBaseViewMvc() == NAL_UNIT_CODED_SLICE_IDR )
1219    {
1220      m_pocRandomAccess = 0; // no need to skip the reordered pictures in IDR, they are decodable.
1221    }
1222    else 
1223    {
1224#if START_DECODING_AT_CRA
1225      static bool warningMessage = false;
1226      if(!warningMessage)
1227      {
1228        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1229        warningMessage = true;
1230      }
1231      return true;
1232#else
1233      printf("\nUnsafe random access point. Decoder may crash.");
1234      m_pocRandomAccess = 0;
1235#endif
1236    }
1237  }
1238  else if (m_apcSlicePilot->getPOC() < m_pocRandomAccess)  // skip the reordered pictures if necessary
1239  {
1240    iPOCLastDisplay++;
1241    return true;
1242  }
1243  // if we reach here, then the picture is not skipped.
1244  return false; 
1245}
1246
1247Void TDecTop::allocAPS (TComAPS* pAPS)
1248{
1249  // we don't know the SPS before it has been activated. These fields could exist
1250  // depending on the corresponding flags in the APS, but SAO/ALF allocation functions will
1251  // have to be moved for that
1252  pAPS->createScalingList();
1253  pAPS->createSaoParam();
1254  m_cSAO.allocSaoParam(pAPS->getSaoParam());
1255  pAPS->createAlfParam();
1256#if !LCU_SYNTAX_ALF
1257  m_cAdaptiveLoopFilter.allocALFParam(pAPS->getAlfParam());
1258#endif
1259}
1260
1261//! \}
Note: See TracBrowser for help on using the repository browser.