source: 3DVCSoftware/branches/HTM-4.0-Nokia/source/Lib/TLibDecoder/TDecTop.cpp @ 1399

Last change on this file since 1399 was 139, checked in by nokia, 13 years ago

3DV-HTM v4.0: FCO

  • Property svn:eol-style set to native
File size: 42.8 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6 * Copyright (c) 2010-2012, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TDecTop.cpp
35    \brief    decoder class
36*/
37
38#include "NALread.h"
39#include "../../App/TAppDecoder/TAppDecTop.h"
40#include "TDecTop.h"
41
42//! \ingroup TLibDecoder
43//! \{
44
45
46CamParsCollector::CamParsCollector()
47: m_bInitialized( false )
48{
49  m_aaiCodedOffset         = new Int* [ MAX_VIEW_NUM ];
50  m_aaiCodedScale          = new Int* [ MAX_VIEW_NUM ];
51  m_aiViewOrderIndex       = new Int  [ MAX_VIEW_NUM ];
52  m_aiViewReceived         = new Int  [ MAX_VIEW_NUM ];
53  for( UInt uiId = 0; uiId < MAX_VIEW_NUM; uiId++ )
54  {
55    m_aaiCodedOffset      [ uiId ] = new Int [ MAX_VIEW_NUM ];
56    m_aaiCodedScale       [ uiId ] = new Int [ MAX_VIEW_NUM ];
57  }
58}
59
60CamParsCollector::~CamParsCollector()
61{
62  for( UInt uiId = 0; uiId < MAX_VIEW_NUM; uiId++ )
63  {
64    delete [] m_aaiCodedOffset      [ uiId ];
65    delete [] m_aaiCodedScale       [ uiId ];
66  }
67  delete [] m_aaiCodedOffset;
68  delete [] m_aaiCodedScale;
69  delete [] m_aiViewOrderIndex;
70  delete [] m_aiViewReceived;
71}
72
73Void
74CamParsCollector::init( FILE* pCodedScaleOffsetFile )
75{
76  m_bInitialized            = true;
77  m_pCodedScaleOffsetFile   = pCodedScaleOffsetFile;
78  m_uiCamParsCodedPrecision = 0;
79  m_bCamParsVaryOverTime    = false;
80  m_iLastViewId             = -1;
81  m_iLastPOC                = -1;
82  m_uiMaxViewId             = 0;
83}
84
85Void
86CamParsCollector::uninit()
87{
88  m_bInitialized = false;
89}
90
91Void
92CamParsCollector::setSlice( TComSlice* pcSlice )
93{
94  if( pcSlice == 0 )
95  {
96    AOF( xIsComplete() );
97    if( m_bCamParsVaryOverTime || m_iLastPOC == 0 )
98    {
99      xOutput( m_iLastPOC );
100    }
101    return;
102  }
103
104  AOF( pcSlice->getSPS()->getViewId() < MAX_VIEW_NUM );
105  if ( pcSlice->getSPS()->isDepth  () )
106  {
107    return;
108  }
109  Bool  bFirstAU          = ( pcSlice->getPOC()               == 0 );
110  Bool  bFirstSliceInAU   = ( pcSlice->getPOC()               != Int ( m_iLastPOC ) );
111  Bool  bFirstSliceInView = ( pcSlice->getSPS()->getViewId()  != UInt( m_iLastViewId ) || bFirstSliceInAU );
112  AOT(  bFirstSliceInAU  &&   pcSlice->getSPS()->getViewId()  != 0 );
113  AOT( !bFirstSliceInAU  &&   pcSlice->getSPS()->getViewId()   < UInt( m_iLastViewId ) );
114  AOT( !bFirstSliceInAU  &&   pcSlice->getSPS()->getViewId()   > UInt( m_iLastViewId + 1 ) );
115  AOT( !bFirstAU         &&   pcSlice->getSPS()->getViewId()   > m_uiMaxViewId );
116  if ( !bFirstSliceInView )
117  {
118    if( m_bCamParsVaryOverTime ) // check consistency of slice parameters here
119    {
120      UInt uiViewId = pcSlice->getSPS()->getViewId();
121      for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ )
122      {
123        AOF( m_aaiCodedScale [ uiBaseId ][ uiViewId ] == pcSlice->getCodedScale    () [ uiBaseId ] );
124        AOF( m_aaiCodedOffset[ uiBaseId ][ uiViewId ] == pcSlice->getCodedOffset   () [ uiBaseId ] );
125        AOF( m_aaiCodedScale [ uiViewId ][ uiBaseId ] == pcSlice->getInvCodedScale () [ uiBaseId ] );
126        AOF( m_aaiCodedOffset[ uiViewId ][ uiBaseId ] == pcSlice->getInvCodedOffset() [ uiBaseId ] );
127      }
128    }
129    return;
130  }
131
132  if( bFirstSliceInAU )
133  {
134    if( !bFirstAU )
135    {
136      AOF( xIsComplete() );
137      xOutput( m_iLastPOC );
138    }
139    ::memset( m_aiViewReceived, 0x00, MAX_VIEW_NUM * sizeof( Int ) );
140  }
141
142  UInt uiViewId                 = pcSlice->getSPS()->getViewId();
143  m_aiViewReceived[ uiViewId ]  = 1;
144  if( bFirstAU )
145  {
146    m_uiMaxViewId                     = Max( m_uiMaxViewId, uiViewId );
147    m_aiViewOrderIndex[ uiViewId ]    = pcSlice->getSPS()->getViewOrderIdx();
148    if( uiViewId == 1 )
149    {
150      m_uiCamParsCodedPrecision       = pcSlice->getSPS()->getCamParPrecision     ();
151      m_bCamParsVaryOverTime          = pcSlice->getSPS()->hasCamParInSliceHeader ();
152    }
153    else if( uiViewId > 1 )
154    {
155      AOF( m_uiCamParsCodedPrecision == pcSlice->getSPS()->getCamParPrecision     () );
156      AOF( m_bCamParsVaryOverTime    == pcSlice->getSPS()->hasCamParInSliceHeader () );
157    }
158    for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ )
159    {
160      if( m_bCamParsVaryOverTime )
161      {
162        m_aaiCodedScale [ uiBaseId ][ uiViewId ]  = pcSlice->getCodedScale    () [ uiBaseId ];
163        m_aaiCodedOffset[ uiBaseId ][ uiViewId ]  = pcSlice->getCodedOffset   () [ uiBaseId ];
164        m_aaiCodedScale [ uiViewId ][ uiBaseId ]  = pcSlice->getInvCodedScale () [ uiBaseId ];
165        m_aaiCodedOffset[ uiViewId ][ uiBaseId ]  = pcSlice->getInvCodedOffset() [ uiBaseId ];
166      }
167      else
168      {
169        m_aaiCodedScale [ uiBaseId ][ uiViewId ]  = pcSlice->getSPS()->getCodedScale    () [ uiBaseId ];
170        m_aaiCodedOffset[ uiBaseId ][ uiViewId ]  = pcSlice->getSPS()->getCodedOffset   () [ uiBaseId ];
171        m_aaiCodedScale [ uiViewId ][ uiBaseId ]  = pcSlice->getSPS()->getInvCodedScale () [ uiBaseId ];
172        m_aaiCodedOffset[ uiViewId ][ uiBaseId ]  = pcSlice->getSPS()->getInvCodedOffset() [ uiBaseId ];
173      }
174    }
175  }
176  else
177  {
178    AOF( m_aiViewOrderIndex[ uiViewId ] == pcSlice->getSPS()->getViewOrderIdx() );
179    if( m_bCamParsVaryOverTime )
180    {
181      for( UInt uiBaseId = 0; uiBaseId < uiViewId; uiBaseId++ )
182      {
183        m_aaiCodedScale [ uiBaseId ][ uiViewId ]  = pcSlice->getCodedScale    () [ uiBaseId ];
184        m_aaiCodedOffset[ uiBaseId ][ uiViewId ]  = pcSlice->getCodedOffset   () [ uiBaseId ];
185        m_aaiCodedScale [ uiViewId ][ uiBaseId ]  = pcSlice->getInvCodedScale () [ uiBaseId ];
186        m_aaiCodedOffset[ uiViewId ][ uiBaseId ]  = pcSlice->getInvCodedOffset() [ uiBaseId ];
187      }
188    }
189  }
190  m_iLastViewId = (Int)pcSlice->getSPS()->getViewId();
191  m_iLastPOC    = (Int)pcSlice->getPOC();
192}
193
194Bool
195CamParsCollector::xIsComplete()
196{
197  for( UInt uiView = 0; uiView <= m_uiMaxViewId; uiView++ )
198  {
199    if( m_aiViewReceived[ uiView ] == 0 )
200    {
201      return false;
202    }
203  }
204  return true;
205}
206
207Void
208CamParsCollector::xOutput( Int iPOC )
209{
210  if( m_pCodedScaleOffsetFile )
211  {
212    if( iPOC == 0 )
213    {
214      fprintf( m_pCodedScaleOffsetFile, "#     ViewId ViewOrderIdx\n" );
215      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------\n" );
216      for( UInt uiViewId = 0; uiViewId <= m_uiMaxViewId; uiViewId++ )
217      {
218        fprintf( m_pCodedScaleOffsetFile, "%12d %12d\n", uiViewId, m_aiViewOrderIndex[ uiViewId ] );
219      }
220      fprintf( m_pCodedScaleOffsetFile, "\n\n");
221      fprintf( m_pCodedScaleOffsetFile, "# StartFrame     EndFrame   TargetView     BaseView   CodedScale  CodedOffset    Precision\n" );
222      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------ ------------ ------------ ------------ ------------ ------------\n" );
223    }
224    if( iPOC == 0 || m_bCamParsVaryOverTime )
225    {
226      Int iS = iPOC;
227      Int iE = ( m_bCamParsVaryOverTime ? iPOC : ~( 1 << 31 ) );
228      for( UInt uiViewId = 0; uiViewId <= m_uiMaxViewId; uiViewId++ )
229      {
230        for( UInt uiBaseId = 0; uiBaseId <= m_uiMaxViewId; uiBaseId++ )
231        {
232          if( uiViewId != uiBaseId )
233          {
234            fprintf( m_pCodedScaleOffsetFile, "%12d %12d %12d %12d %12d %12d %12d\n",
235              iS, iE, uiViewId, uiBaseId, m_aaiCodedScale[ uiBaseId ][ uiViewId ], m_aaiCodedOffset[ uiBaseId ][ uiViewId ], m_uiCamParsCodedPrecision );
236          }
237        }
238      }
239    }
240  }
241}
242
243TDecTop::TDecTop()
244: m_SEIs(0)
245, m_tAppDecTop( NULL )
246, m_nalUnitTypeBaseView( NAL_UNIT_INVALID )
247{
248  m_pcPic = 0;
249  m_iGopSize      = 0;
250  m_bGopSizeSet   = false;
251  m_iMaxRefPicNum = 0;
252  m_uiValidPS = 0;
253#if SONY_COLPIC_AVAILABILITY
254  m_iViewOrderIdx = 0;
255#endif
256#if ENC_DEC_TRACE
257  g_hTrace = fopen( "TraceDec.txt", "wb" );
258  g_bJustDoIt = g_bEncDecTraceDisable;
259  g_nSymbolCounter = 0;
260#endif
261  m_bRefreshPending = 0;
262  m_pocCRA = 0;
263  m_pocRandomAccess = MAX_INT;         
264  m_prevPOC                = MAX_INT;
265  m_bFirstSliceInPicture    = true;
266  m_bFirstSliceInSequence   = true;
267  m_pcCamParsCollector = 0;
268}
269
270TDecTop::~TDecTop()
271{
272#if ENC_DEC_TRACE
273  fclose( g_hTrace );
274#endif
275}
276
277Void TDecTop::create()
278{
279  m_cGopDecoder.create();
280  m_apcSlicePilot = new TComSlice;
281  m_uiSliceIdx = m_uiLastSliceIdx = 0;
282}
283
284Void TDecTop::destroy()
285{
286  m_cGopDecoder.destroy();
287 
288  delete m_apcSlicePilot;
289  m_apcSlicePilot = NULL;
290 
291  m_cSliceDecoder.destroy();
292  m_tAppDecTop = NULL;
293
294#if DEPTH_MAP_GENERATION
295  m_cDepthMapGenerator.destroy();
296#endif
297#if HHI_INTER_VIEW_RESIDUAL_PRED
298  m_cResidualGenerator.destroy();
299#endif
300}
301
302Void TDecTop::init( TAppDecTop* pcTAppDecTop, Bool bFirstInstance )
303{
304  // initialize ROM
305  if( bFirstInstance )
306  {
307  initROM();
308  }
309  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cAdaptiveLoopFilter, &m_cSAO
310#if DEPTH_MAP_GENERATION
311                    , &m_cDepthMapGenerator
312#endif
313#if HHI_INTER_VIEW_RESIDUAL_PRED
314                    , &m_cResidualGenerator
315#endif
316    );
317  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
318  m_cEntropyDecoder.init(&m_cPrediction);
319  m_tAppDecTop = pcTAppDecTop;
320#if DEPTH_MAP_GENERATION
321#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)
618#else
619Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int iSkipFrame, Int iPOCLastDisplay
620                           )
621#endif
622{
623  TComPic*&   pcPic         = m_pcPic;
624  m_apcSlicePilot->initSlice();
625
626  //!!!KS: DIRTY HACK
627  m_apcSlicePilot->setPPSId(0);
628  m_apcSlicePilot->setPPS(m_parameterSetManagerDecoder.getPrefetchedPPS(0));
629  m_apcSlicePilot->setSPS(m_parameterSetManagerDecoder.getPrefetchedSPS(0));
630#if VIDYO_VPS_INTEGRATION
631  m_apcSlicePilot->setVPS(m_parameterSetManagerDecoder.getPrefetchedVPS(0));
632#endif
633  m_apcSlicePilot->initTiles();
634
635  if (m_bFirstSliceInPicture)
636  {
637    m_uiSliceIdx     = 0;
638    m_uiLastSliceIdx = 0;
639  }
640  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
641  if (!m_bFirstSliceInPicture)
642  {
643    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
644  }
645
646  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
647  if( m_bFirstSliceInPicture )
648  {
649#if VIDYO_VPS_INTEGRATION
650    if( m_apcSlicePilot->getVPS()->getViewId(nalu.m_layerId) == 0 ) { m_nalUnitTypeBaseView = nalu.m_nalUnitType; }
651    else { m_nalUnitTypeBaseView = m_tAppDecTop->getTDecTop( 0, m_apcSlicePilot->getVPS()->getDepthFlag(nalu.m_layerId) )->getNalUnitTypeBaseView(); }
652#else
653    if( nalu.m_viewId == 0 ) { m_nalUnitTypeBaseView = nalu.m_nalUnitType; }
654    else                     { m_nalUnitTypeBaseView = m_tAppDecTop->getTDecTop( 0, nalu.m_isDepth )->getNalUnitTypeBaseView(); }
655#endif
656   
657    m_apcSlicePilot->setNalUnitTypeBaseViewMvc( m_nalUnitTypeBaseView );
658  }
659
660#if SONY_COLPIC_AVAILABILITY
661  m_apcSlicePilot->setViewOrderIdx( m_apcSlicePilot->getSPS()->getViewOrderIdx());
662#endif
663
664#if NAL_REF_FLAG
665  m_apcSlicePilot->setReferenced(nalu.m_nalRefFlag);
666#else
667  m_apcSlicePilot->setReferenced(nalu.m_nalRefIDC != NAL_REF_IDC_PRIORITY_LOWEST);
668#endif
669  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
670
671  // ALF CU parameters should be part of the slice header -> needs to be fixed
672#if LCU_SYNTAX_ALF
673  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder, m_cGopDecoder.getAlfCuCtrlParam(), m_cGopDecoder.getAlfParamSet());
674#else
675  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder, m_cGopDecoder.getAlfCuCtrlParam() );
676#endif
677  // byte align
678  {
679    Int numBitsForByteAlignment = nalu.m_Bitstream->getNumBitsUntilByteAligned();
680    if ( numBitsForByteAlignment > 0 )
681    {
682      UInt bitsForByteAlignment;
683      nalu.m_Bitstream->read( numBitsForByteAlignment, bitsForByteAlignment );
684      assert( bitsForByteAlignment == ( ( 1 << numBitsForByteAlignment ) - 1 ) );
685    }
686  }
687
688  // exit when a new picture is found
689  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence)
690  {
691#if START_DECODING_AT_CRA
692    if (m_prevPOC >= m_pocRandomAccess)
693    {
694      m_prevPOC = m_apcSlicePilot->getPOC();
695      return true;
696    }
697    m_prevPOC = m_apcSlicePilot->getPOC();
698#else
699    m_prevPOC = m_apcSlicePilot->getPOC();
700    return true;
701#endif
702  }
703  // actual decoding starts here
704  xActivateParameterSets();
705  m_apcSlicePilot->initTiles();
706
707  if (m_apcSlicePilot->isNextSlice()) 
708  {
709    m_prevPOC = m_apcSlicePilot->getPOC();
710  }
711  m_bFirstSliceInSequence = false;
712  if (m_apcSlicePilot->isNextSlice())
713  {
714    // Skip pictures due to random access
715    if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
716    {
717      return false;
718    }
719  }
720  //detect lost reference picture and insert copy of earlier frame.
721#if START_DECODING_AT_CRA
722  while(m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess) > 0)
723#else
724  while(m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true) > 0)
725#endif
726  {
727    xCreateLostPicture(m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), false)-1);
728  }
729  if (m_bFirstSliceInPicture)
730  {
731    // Buffer initialize for prediction.
732    m_cPrediction.initTempBuff();
733    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
734    //  Get a new picture buffer
735    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
736
737#if SONY_COLPIC_AVAILABILITY
738    pcPic->setViewOrderIdx( m_apcSlicePilot->getSPS()->getViewOrderIdx() );
739#endif
740
741    /* transfer any SEI messages that have been received to the picture */
742    pcPic->setSEIs(m_SEIs);
743    m_SEIs = NULL;
744
745    // Recursive structure
746    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
747    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
748    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
749
750    m_cSliceDecoder.create( m_apcSlicePilot, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
751#if DEPTH_MAP_GENERATION
752    UInt uiPdm = ( m_apcSlicePilot->getSPS()->getViewId() ? m_apcSlicePilot->getSPS()->getPredDepthMapGeneration() : m_tAppDecTop->getSPSAccess()->getPdm() );
753    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) );
754    TComDepthMapGenerator* pcDMG0 = m_tAppDecTop->getDecTop0()->getDepthMapGenerator();
755    if( m_apcSlicePilot->getSPS()->getViewId() == 1 && ( pcDMG0->getSubSampExpX() != PDM_SUB_SAMP_EXP_X(uiPdm) || pcDMG0->getSubSampExpY() != PDM_SUB_SAMP_EXP_Y(uiPdm) ) )
756    {
757      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) );
758    }
759#endif
760#if HHI_INTER_VIEW_RESIDUAL_PRED
761    m_cResidualGenerator.create( true, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement );
762#endif
763  }
764
765  //  Set picture slice pointer
766  TComSlice*  pcSlice = m_apcSlicePilot;
767  Bool bNextSlice     = pcSlice->isNextSlice();
768
769  UInt uiCummulativeTileWidth;
770  UInt uiCummulativeTileHeight;
771  UInt i, j, p;
772
773#if !REMOVE_TILE_DEPENDENCE
774  //set the TileBoundaryIndependenceIdr
775  if(pcSlice->getPPS()->getTileBehaviorControlPresentFlag() == 1)
776  {
777    pcPic->getPicSym()->setTileBoundaryIndependenceIdr( pcSlice->getPPS()->getTileBoundaryIndependenceIdr() );
778  }
779  else
780  {
781    pcPic->getPicSym()->setTileBoundaryIndependenceIdr( pcSlice->getPPS()->getSPS()->getTileBoundaryIndependenceIdr() );
782  }
783#endif
784
785  if( pcSlice->getPPS()->getColumnRowInfoPresent() == 1 )
786  {
787    //set NumColumnsMins1 and NumRowsMinus1
788    pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
789    pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
790
791    //create the TComTileArray
792    pcPic->getPicSym()->xCreateTComTileArray();
793
794    if( pcSlice->getPPS()->getUniformSpacingIdr() == 1)
795    {
796      //set the width for each tile
797      for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
798      {
799        for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
800        {
801          pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
802            setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
803            - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
804        }
805      }
806
807      //set the height for each tile
808      for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
809      {
810        for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
811        {
812          pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
813            setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
814            - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
815        }
816      }
817    }
818    else
819    {
820      //set the width for each tile
821      for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
822      {
823        uiCummulativeTileWidth = 0;
824        for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
825        {
826          pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
827          uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
828        }
829        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
830      }
831
832      //set the height for each tile
833      for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
834      {
835        uiCummulativeTileHeight = 0;
836        for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
837        { 
838          pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
839          uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
840        }
841        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
842      }
843    }
844  }
845  else
846  {
847    //set NumColumnsMins1 and NumRowsMinus1
848    pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getSPS()->getNumColumnsMinus1() );
849    pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getSPS()->getNumRowsMinus1() );
850
851    //create the TComTileArray
852    pcPic->getPicSym()->xCreateTComTileArray();
853
854    //automatically set the column and row boundary if UniformSpacingIdr = 1
855    if( pcSlice->getSPS()->getUniformSpacingIdr() == 1 )
856    {
857      //set the width for each tile
858      for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
859      {
860        for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
861        {
862          pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
863            setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
864            - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
865        }
866      }
867
868      //set the height for each tile
869      for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
870      {
871        for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
872        {
873          pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
874            setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
875            - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
876        }
877      }
878    }
879    else
880    {
881      //set the width for each tile
882      for(j=0; j < pcSlice->getSPS()->getNumRowsMinus1()+1; j++)
883      {
884        uiCummulativeTileWidth = 0;
885        for(i=0; i < pcSlice->getSPS()->getNumColumnsMinus1(); i++)
886        {
887          pcPic->getPicSym()->getTComTile(j * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getSPS()->getColumnWidth(i) );
888          uiCummulativeTileWidth += pcSlice->getSPS()->getColumnWidth(i);
889        }
890        pcPic->getPicSym()->getTComTile(j * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
891      }
892
893      //set the height for each tile
894      for(j=0; j < pcSlice->getSPS()->getNumColumnsMinus1()+1; j++)
895      {
896        uiCummulativeTileHeight = 0;
897        for(i=0; i < pcSlice->getSPS()->getNumRowsMinus1(); i++)
898        { 
899          pcPic->getPicSym()->getTComTile(i * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getSPS()->getRowHeight(i) );
900          uiCummulativeTileHeight += pcSlice->getSPS()->getRowHeight(i);
901        }
902        pcPic->getPicSym()->getTComTile(i * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
903      }
904    }
905  }
906
907  pcPic->getPicSym()->xInitTiles();
908
909  //generate the Coding Order Map and Inverse Coding Order Map
910  UInt uiEncCUAddr;
911  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
912  {
913    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
914    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
915  }
916  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
917  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
918
919  //convert the start and end CU addresses of the slice and entropy slice into encoding order
920  pcSlice->setEntropySliceCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getEntropySliceCurStartCUAddr()) );
921  pcSlice->setEntropySliceCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getEntropySliceCurEndCUAddr()) );
922  if(pcSlice->isNextSlice())
923  {
924    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
925    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
926  }
927
928  if (m_bFirstSliceInPicture) 
929  {
930    if(pcPic->getNumAllocatedSlice() != 1)
931    {
932      pcPic->clearSliceBuffer();
933    }
934  }
935  else
936  {
937    pcPic->allocateNewSlice();
938  }
939  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
940  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
941  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
942
943  pcPic->setTLayer(nalu.m_temporalId);
944
945  if (bNextSlice)
946  {
947    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_cListPic); 
948
949    if ( !pcSlice->getPPS()->getEnableTMVPFlag() && pcPic->getTLayer() == 0 )
950    {
951      pcSlice->decodingMarkingForNoTMVP( m_cListPic, pcSlice->getPOC() );
952    }
953
954    // Set reference list
955#if VIDYO_VPS_INTEGRATION
956    pcSlice->setViewId( pcSlice->getVPS()->getViewId(nalu.m_layerId) );
957    pcSlice->setIsDepth( pcSlice->getVPS()->getDepthFlag(nalu.m_layerId) );
958#else
959    pcSlice->setViewId(m_viewId);
960    pcSlice->setIsDepth(m_isDepth);
961#endif
962
963#if SONY_COLPIC_AVAILABILITY
964#if VIDYO_VPS_INTEGRATION
965    pcSlice->setViewOrderIdx( pcSlice->getVPS()->getViewOrderIdx(nalu.m_layerId) );
966#else
967    pcSlice->setViewOrderIdx( pcPic->getViewOrderIdx() );
968#endif
969#endif
970
971    assert( m_tAppDecTop != NULL );
972    TComPic * const pcTexturePic = m_isDepth ? m_tAppDecTop->getPicFromView(  m_viewId, pcSlice->getPOC(), false ) : NULL;
973
974#if FLEX_CODING_ORDER
975    if (pcTexturePic != NULL)
976    {
977      assert( !m_isDepth || pcTexturePic != NULL );
978      pcSlice->setTexturePic( pcTexturePic );
979    }
980#else
981    assert( !m_isDepth || pcTexturePic != NULL );
982    pcSlice->setTexturePic( pcTexturePic );
983#endif
984   
985
986//     //original code
987//     assert( !m_isDepth || pcTexturePic != NULL );
988//     pcSlice->setTexturePic( pcTexturePic );
989
990
991
992    std::vector<TComPic*> apcInterViewRefPics = m_tAppDecTop->getInterViewRefPics( m_viewId, pcSlice->getPOC(), m_isDepth, pcSlice->getSPS() );
993    pcSlice->setRefPicListMvc( m_cListPic, apcInterViewRefPics );
994
995    // For generalized B
996    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
997    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
998    {
999      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
1000      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
1001
1002      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
1003      {
1004        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
1005      }
1006    }
1007    if (pcSlice->isInterB())
1008    {
1009      Bool bLowDelay = true;
1010      Int  iCurrPOC  = pcSlice->getPOC();
1011      Int iRefIdx = 0;
1012
1013      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
1014      {
1015        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
1016        {
1017          bLowDelay = false;
1018        }
1019      }
1020      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
1021      {
1022        if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
1023        {
1024          bLowDelay = false;
1025        }
1026      }
1027
1028      pcSlice->setCheckLDC(bLowDelay);           
1029    }
1030
1031    //---------------
1032    pcSlice->setRefPOCnViewListsMvc();
1033
1034    if(!pcSlice->getRefPicListModificationFlagLC())
1035    {
1036      pcSlice->generateCombinedList();
1037    }
1038
1039    if( pcSlice->getRefPicListCombinationFlag() && pcSlice->getPPS()->getWPBiPredIdc()==1 && pcSlice->getSliceType()==B_SLICE )
1040    {
1041      pcSlice->setWpParamforLC();
1042    }
1043    pcSlice->setNoBackPredFlag( false );
1044    if ( pcSlice->getSliceType() == B_SLICE && !pcSlice->getRefPicListCombinationFlag())
1045    {
1046      if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) )
1047      {
1048        pcSlice->setNoBackPredFlag( true );
1049        for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ )
1050        {
1051          if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) 
1052          {
1053            pcSlice->setNoBackPredFlag( false );
1054            break;
1055          }
1056        }
1057      }
1058    }
1059  }
1060
1061  pcPic->setCurrSliceIdx(m_uiSliceIdx);
1062  if(pcSlice->getSPS()->getScalingListFlag())
1063  {
1064    if(pcSlice->getAPS()->getScalingListEnabled())
1065    {
1066      pcSlice->setScalingList ( pcSlice->getAPS()->getScalingList()  );
1067      if(pcSlice->getScalingList()->getScalingListPresentFlag())
1068      {
1069        pcSlice->setDefaultScalingList();
1070      }
1071      m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
1072    }
1073    m_cTrQuant.setUseScalingList(true);
1074  }
1075  else
1076  {
1077    m_cTrQuant.setFlatScalingList();
1078    m_cTrQuant.setUseScalingList(false);
1079  }
1080
1081#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
1082  if( m_parameterSetManagerDecoder.getPrefetchedSPS(0)->getUseDMM() && g_aacWedgeLists.empty() )
1083  {
1084    initWedgeLists();
1085  }
1086#endif
1087
1088  //  Decode a picture
1089  m_cGopDecoder.decompressGop(nalu.m_Bitstream, pcPic, false);
1090
1091  if( m_pcCamParsCollector )
1092  {
1093    m_pcCamParsCollector->setSlice( pcSlice );
1094  }
1095
1096  m_bFirstSliceInPicture = false;
1097  m_uiSliceIdx++;
1098
1099  return false;
1100}
1101
1102
1103
1104
1105
1106#if VIDYO_VPS_INTEGRATION
1107Void TDecTop::xDecodeVPS()
1108{
1109  TComVPS* vps = new TComVPS();
1110 
1111  m_cEntropyDecoder.decodeVPS( vps );
1112  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
1113  getTAppDecTop()->getVPSAccess()->addVPS( vps );
1114}
1115#endif
1116
1117Void TDecTop::xDecodeSPS()
1118{
1119  TComSPS* sps = new TComSPS();
1120#if RPS_IN_SPS
1121  TComRPSList* rps = new TComRPSList();
1122  sps->setRPSList(rps);
1123#endif
1124#if HHI_MPI
1125  m_cEntropyDecoder.decodeSPS( sps, m_isDepth );
1126#else
1127  m_cEntropyDecoder.decodeSPS( sps );
1128#endif
1129  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
1130#if LCU_SYNTAX_ALF
1131  m_cAdaptiveLoopFilter.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
1132#endif
1133}
1134
1135Void TDecTop::xDecodePPS()
1136{
1137#if !RPS_IN_SPS
1138  TComRPSList* rps = new TComRPSList();
1139#endif
1140  TComPPS* pps = new TComPPS();
1141#if !RPS_IN_SPS
1142  pps->setRPSList(rps);
1143#endif
1144#if TILES_OR_ENTROPY_SYNC_IDC
1145  m_cEntropyDecoder.decodePPS( pps, &m_parameterSetManagerDecoder );
1146#else
1147  m_cEntropyDecoder.decodePPS( pps );
1148#endif
1149  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
1150
1151  //!!!KS: Activate parameter sets for parsing APS (unless dependency is resolved)
1152  m_apcSlicePilot->setPPSId(pps->getPPSId());
1153  xActivateParameterSets();
1154  m_apcSlicePilot->initTiles();
1155}
1156
1157Void TDecTop::xDecodeAPS()
1158{
1159  TComAPS  *aps = new TComAPS();
1160  allocAPS (aps);
1161  decodeAPS(aps);
1162  m_parameterSetManagerDecoder.storePrefetchedAPS(aps);
1163}
1164
1165Void TDecTop::xDecodeSEI()
1166{
1167  m_SEIs = new SEImessages;
1168  m_cEntropyDecoder.decodeSEI(*m_SEIs);
1169}
1170
1171Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay
1172
1173 )
1174{
1175  // Initialize entropy decoder
1176  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1177  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
1178
1179  switch (nalu.m_nalUnitType)
1180  {
1181#if VIDYO_VPS_INTEGRATION
1182    case NAL_UNIT_VPS:
1183      xDecodeVPS();
1184      return false;
1185#endif
1186    case NAL_UNIT_SPS:
1187      xDecodeSPS();
1188      return false;
1189
1190    case NAL_UNIT_PPS:
1191      xDecodePPS();
1192      return false;
1193    case NAL_UNIT_APS:
1194      xDecodeAPS();
1195      return false;
1196
1197    case NAL_UNIT_SEI:
1198      xDecodeSEI();
1199      return false;
1200
1201    case NAL_UNIT_CODED_SLICE:
1202    case NAL_UNIT_CODED_SLICE_IDR:
1203#if H0566_TLA
1204    case NAL_UNIT_CODED_SLICE_IDV:
1205    case NAL_UNIT_CODED_SLICE_CRA:
1206    case NAL_UNIT_CODED_SLICE_TLA:
1207#else
1208    case NAL_UNIT_CODED_SLICE_CDR:
1209#endif
1210      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay
1211        );
1212      break;
1213    default:
1214      assert (1);
1215  }
1216
1217  return false;
1218}
1219
1220/** Function for checking if picture should be skipped because of random access
1221 * \param iSkipFrame skip frame counter
1222 * \param iPOCLastDisplay POC of last picture displayed
1223 * \returns true if the picture shold be skipped in the random access.
1224 * This function checks the skipping of pictures in the case of -s option random access.
1225 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1226 * It also checks the type of Nal unit type at the random access point.
1227 * If the random access point is CRA, pictures with POC equal to or greater than the CRA POC are decoded.
1228 * If the random access point is IDR all pictures after the random access point are decoded.
1229 * If the random access point is not IDR or CRA, a warning is issues, and decoding of pictures with POC
1230 * equal to or greater than the random access point POC is attempted. For non IDR/CRA random
1231 * access point there is no guarantee that the decoder will not crash.
1232 */
1233Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
1234{
1235  if (iSkipFrame) 
1236  {
1237    iSkipFrame--;   // decrement the counter
1238    return true;
1239  }
1240  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1241  {
1242#if H0566_TLA
1243    if( m_apcSlicePilot->getNalUnitTypeBaseViewMvc() == NAL_UNIT_CODED_SLICE_CRA )
1244#else
1245    if( m_apcSlicePilot->getNalUnitTypeBaseViewMvc() == NAL_UNIT_CODED_SLICE_CDR )
1246#endif
1247    {
1248      m_pocRandomAccess = m_apcSlicePilot->getPOC(); // set the POC random access since we need to skip the reordered pictures in CRA.
1249    }
1250    else if( m_apcSlicePilot->getNalUnitTypeBaseViewMvc() == NAL_UNIT_CODED_SLICE_IDR )
1251    {
1252      m_pocRandomAccess = 0; // no need to skip the reordered pictures in IDR, they are decodable.
1253    }
1254    else 
1255    {
1256#if START_DECODING_AT_CRA
1257      static bool warningMessage = false;
1258      if(!warningMessage)
1259      {
1260        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1261        warningMessage = true;
1262      }
1263      return true;
1264#else
1265      printf("\nUnsafe random access point. Decoder may crash.");
1266      m_pocRandomAccess = 0;
1267#endif
1268    }
1269  }
1270  else if (m_apcSlicePilot->getPOC() < m_pocRandomAccess)  // skip the reordered pictures if necessary
1271  {
1272    iPOCLastDisplay++;
1273    return true;
1274  }
1275  // if we reach here, then the picture is not skipped.
1276  return false; 
1277}
1278
1279Void TDecTop::allocAPS (TComAPS* pAPS)
1280{
1281  // we don't know the SPS before it has been activated. These fields could exist
1282  // depending on the corresponding flags in the APS, but SAO/ALF allocation functions will
1283  // have to be moved for that
1284  pAPS->createScalingList();
1285  pAPS->createSaoParam();
1286  m_cSAO.allocSaoParam(pAPS->getSaoParam());
1287  pAPS->createAlfParam();
1288#if !LCU_SYNTAX_ALF
1289  m_cAdaptiveLoopFilter.allocALFParam(pAPS->getAlfParam());
1290#endif
1291}
1292
1293//! \}
Note: See TracBrowser for help on using the repository browser.