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

Last change on this file since 95 was 77, checked in by tech, 13 years ago

Merged with branch/HTM-3.0Samsung REV74 including:

  • restricted residual prediction m24766
  • Inter-view residual prediction m24938
  • VPS concept m24714,m24878, m24945,m24896, m2491
  • reference list modification, restriction on IDR m24876, m24874
  • depth based motion parameter prediction m24829

Fixed bugs:

  • interview prediction
  • VSO

Added:

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