source: 3DVCSoftware/branches/HTM-5.1-dev1-LG-Fix/source/Lib/TLibDecoder/TDecTop.cpp @ 368

Last change on this file since 368 was 210, checked in by tech, 12 years ago

Reintegrated /branches/HTM-5.0-dev0 rev. 207.

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