source: 3DVCSoftware/branches/HTM-5.1-dev2-Sony/source/Lib/TLibDecoder/TDecTop.cpp @ 1417

Last change on this file since 1417 was 262, checked in by sony, 12 years ago

JCT2-C0115 Inter-view vector scaling for TMVP & flag
The macro is INTER_VIEW_VECTOR_SCALING_C0115.

  • Property svn:eol-style set to native
File size: 45.5 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 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#if QC_MVHEVC_B0046
269  m_bFirstNal                  = false;
270#endif
271}
272
273TDecTop::~TDecTop()
274{
275#if ENC_DEC_TRACE
276  fclose( g_hTrace );
277#endif
278}
279
280Void TDecTop::create()
281{
282  m_cGopDecoder.create();
283  m_apcSlicePilot = new TComSlice;
284  m_uiSliceIdx = m_uiLastSliceIdx = 0;
285}
286
287Void TDecTop::destroy()
288{
289  m_cGopDecoder.destroy();
290 
291  delete m_apcSlicePilot;
292  m_apcSlicePilot = NULL;
293 
294  m_cSliceDecoder.destroy();
295  m_tAppDecTop = NULL;
296
297#if DEPTH_MAP_GENERATION
298  m_cDepthMapGenerator.destroy();
299#endif
300#if HHI_INTER_VIEW_RESIDUAL_PRED
301  m_cResidualGenerator.destroy();
302#endif
303}
304
305Void TDecTop::init( TAppDecTop* pcTAppDecTop, Bool bFirstInstance )
306{
307  // initialize ROM
308  if( bFirstInstance )
309  {
310  initROM();
311  }
312  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cAdaptiveLoopFilter, &m_cSAO
313#if DEPTH_MAP_GENERATION
314                    , &m_cDepthMapGenerator
315#endif
316#if HHI_INTER_VIEW_RESIDUAL_PRED
317                    , &m_cResidualGenerator
318#endif
319    );
320  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
321  m_cEntropyDecoder.init(&m_cPrediction);
322  m_tAppDecTop = pcTAppDecTop;
323#if DEPTH_MAP_GENERATION
324#if VIDYO_VPS_INTEGRATION
325  m_cDepthMapGenerator.init( &m_cPrediction, m_tAppDecTop->getVPSAccess(), m_tAppDecTop->getSPSAccess(), m_tAppDecTop->getAUPicAccess() );
326#else
327  m_cDepthMapGenerator.init( &m_cPrediction, m_tAppDecTop->getSPSAccess(), m_tAppDecTop->getAUPicAccess() );
328#endif
329#endif
330#if HHI_INTER_VIEW_RESIDUAL_PRED
331  m_cResidualGenerator.init( &m_cTrQuant, &m_cDepthMapGenerator );
332#endif
333}
334
335Void TDecTop::deletePicBuffer ( )
336{
337  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
338  Int iSize = Int( m_cListPic.size() );
339 
340  for (Int i = 0; i < iSize; i++ )
341  {
342    if( *iterPic )
343    {
344      TComPic* pcPic = *(iterPic++);
345      pcPic->destroy();
346   
347      delete pcPic;
348      pcPic = NULL;
349    }
350  }
351 
352  // destroy ALF temporary buffers
353  m_cAdaptiveLoopFilter.destroy();
354
355  m_cSAO.destroy();
356 
357  m_cLoopFilter.        destroy();
358 
359  // destroy ROM
360  if(m_viewId == 0 && m_isDepth == false)
361  {
362    destroyROM();
363  }
364}
365
366#if HHI_INTER_VIEW_RESIDUAL_PRED
367Void
368TDecTop::deleteExtraPicBuffers( Int iPoc )
369{
370  TComPic*                      pcPic = 0;
371  TComList<TComPic*>::iterator  cIter = m_cListPic.begin();
372  TComList<TComPic*>::iterator  cEnd  = m_cListPic.end  ();
373  for( ; cIter != cEnd; cIter++ )
374  {
375    if( (*cIter)->getPOC() == iPoc )
376    {
377      pcPic = *cIter;
378      break;
379    }
380  }
381  //AOF( pcPic );
382  if ( pcPic )
383  {
384    pcPic->removeResidualBuffer   ();
385  }
386}
387#endif
388
389
390Void
391TDecTop::compressMotion( Int iPoc )
392{
393  TComPic*                      pcPic = 0;
394  TComList<TComPic*>::iterator  cIter = m_cListPic.begin();
395  TComList<TComPic*>::iterator  cEnd  = m_cListPic.end  ();
396  for( ; cIter != cEnd; cIter++ )
397  {
398    if( (*cIter)->getPOC() == iPoc )
399    {
400      pcPic = *cIter;
401      break;
402    }
403  }
404//  AOF( pcPic );
405  if ( pcPic )
406  {
407    pcPic->compressMotion();
408  }
409}
410
411Void TDecTop::xUpdateGopSize (TComSlice* pcSlice)
412{
413  if ( !pcSlice->isIntra() && !m_bGopSizeSet)
414  {
415    m_iGopSize    = pcSlice->getPOC();
416    m_bGopSizeSet = true;
417   
418    m_cGopDecoder.setGopSize(m_iGopSize);
419  }
420}
421
422Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
423{
424  xUpdateGopSize(pcSlice);
425 
426#if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER
427  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer())+pcSlice->getSPS()->getNumReorderPics(pcSlice->getTLayer()) + 1; // +1 to have space for the picture currently being decoded
428#else
429  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxNumberOfReferencePictures()+pcSlice->getSPS()->getNumReorderFrames() + 1; // +1 to have space for the picture currently being decoded
430#endif
431
432#if DEPTH_MAP_GENERATION
433  UInt uiPdm                  = ( pcSlice->getSPS()->getViewId() ? pcSlice->getSPS()->getPredDepthMapGeneration() : m_tAppDecTop->getSPSAccess()->getPdm() );
434  Bool bNeedPrdDepthMapBuffer = ( !pcSlice->getSPS()->isDepth() && uiPdm > 0 );
435#endif
436
437  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
438  {
439    rpcPic = new TComPic();
440   
441    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true);
442   
443#if DEPTH_MAP_GENERATION
444    if( bNeedPrdDepthMapBuffer )
445    {
446      rpcPic->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
447    }
448#endif
449   
450    m_cListPic.pushBack( rpcPic );
451   
452    return;
453  }
454 
455  Bool bBufferIsAvailable = false;
456  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
457  while (iterPic != m_cListPic.end())
458  {
459    rpcPic = *(iterPic++);
460    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
461    {
462      rpcPic->setOutputMark(false);
463      bBufferIsAvailable = true;
464      break;
465    }
466
467    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
468    {
469      rpcPic->setOutputMark(false);
470      rpcPic->setReconMark( false );
471      rpcPic->getPicYuvRec()->setBorderExtension( false );
472      bBufferIsAvailable = true;
473      break;
474    }
475  }
476 
477  if ( !bBufferIsAvailable )
478  {
479    //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer.
480    m_iMaxRefPicNum++;
481    rpcPic = new TComPic();
482    m_cListPic.pushBack( rpcPic );
483  }
484  rpcPic->destroy(); 
485  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true);
486#if DEPTH_MAP_GENERATION
487  if( bNeedPrdDepthMapBuffer && !rpcPic->getPredDepthMap() )
488  {
489    rpcPic->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
490  }
491#endif
492}
493
494Void TDecTop::executeDeblockAndAlf(UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, Int& iSkipFrame, Int& iPOCLastDisplay)
495{
496  if (!m_pcPic)
497  {
498    /* nothing to deblock */
499    return;
500  }
501 
502  TComPic*&   pcPic         = m_pcPic;
503
504  // Execute Deblock and ALF only + Cleanup
505
506  m_cGopDecoder.decompressGop(NULL, pcPic, true);
507
508  TComSlice::sortPicList( m_cListPic ); // sorting for application output
509  ruiPOC              = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
510  rpcListPic          = &m_cListPic; 
511  m_cCuDecoder.destroy();       
512  m_bFirstSliceInPicture  = true;
513
514  return;
515}
516
517Void TDecTop::xCreateLostPicture(Int iLostPoc) 
518{
519  printf("\ninserting lost poc : %d\n",iLostPoc);
520  TComSlice cFillSlice;
521  cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
522  cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
523  cFillSlice.initSlice();
524  cFillSlice.initTiles();
525  TComPic *cFillPic;
526  xGetNewPicBuffer(&cFillSlice,cFillPic);
527  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
528  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
529  cFillPic->getSlice(0)->initSlice();
530  cFillPic->getSlice(0)->initTiles();
531
532 
533 
534  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
535  Int closestPoc = 1000000;
536  while ( iterPic != m_cListPic.end())
537  {
538    TComPic * rpcPic = *(iterPic++);
539    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())
540    {
541      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
542    }
543  }
544  iterPic = m_cListPic.begin();
545  while ( iterPic != m_cListPic.end())
546  {
547    TComPic *rpcPic = *(iterPic++);
548    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
549    {
550      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
551      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
552      break;
553    }
554  }
555  cFillPic->setCurrSliceIdx(0);
556  for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) 
557  {
558    cFillPic->getCU(i)->initCU(cFillPic,i);
559  }
560  cFillPic->getSlice(0)->setReferenced(true);
561  cFillPic->getSlice(0)->setPOC(iLostPoc);
562  cFillPic->setReconMark(true);
563  cFillPic->setOutputMark(true);
564  if(m_pocRandomAccess == MAX_INT)
565  {
566    m_pocRandomAccess = iLostPoc;
567  }
568}
569
570
571Void TDecTop::xActivateParameterSets()
572{
573  m_parameterSetManagerDecoder.applyPrefetchedPS();
574
575  TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
576  assert (pps != 0);
577
578  TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId());
579  assert (sps != 0);
580#if VIDYO_VPS_INTEGRATION
581  TComVPS *vps = m_parameterSetManagerDecoder.getVPS(sps->getVPSId());
582  assert (vps != 0);
583#if !QC_REM_IDV_B0046
584  if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA )
585#else
586  if( (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA) && !sps->getViewId() )
587#endif
588    // VPS can only be activated on IDR or CRA...
589    getTAppDecTop()->getVPSAccess()->setActiveVPSId( sps->getVPSId() );
590#endif
591  m_apcSlicePilot->setPPS(pps);
592  m_apcSlicePilot->setSPS(sps);
593#if QC_MVHEVC_B0046
594  TComVPS *vps = m_parameterSetManagerDecoder.getVPS(sps->getVPSId());
595#endif
596#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
597  m_apcSlicePilot->setVPS(vps);
598#endif
599  pps->setSPS(sps);
600
601  if(sps->getUseSAO() || sps->getUseALF()|| sps->getScalingListFlag() || sps->getUseDF())
602  {
603    m_apcSlicePilot->setAPS( m_parameterSetManagerDecoder.getAPS(m_apcSlicePilot->getAPSId())  );
604  }
605  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
606
607  for (Int i = 0; i < sps->getMaxCUDepth() - 1; i++)
608  {
609    sps->setAMPAcc( i, sps->getUseAMP() );
610  }
611
612  for (Int i = sps->getMaxCUDepth() - 1; i < sps->getMaxCUDepth(); i++)
613  {
614    sps->setAMPAcc( i, 0 );
615  }
616
617#if !LCU_SYNTAX_ALF
618  // create ALF temporary buffer
619  m_cAdaptiveLoopFilter.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
620#endif
621  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
622  m_cLoopFilter.        create( g_uiMaxCUDepth );
623}
624
625#if SKIPFRAME_BUGFIX
626Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
627#else
628Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int iSkipFrame, Int iPOCLastDisplay )
629#endif
630{
631  TComPic*&   pcPic         = m_pcPic;
632  m_apcSlicePilot->initSlice();
633
634  //!!!KS: DIRTY HACK
635  m_apcSlicePilot->setPPSId(0);
636  m_apcSlicePilot->setPPS(m_parameterSetManagerDecoder.getPrefetchedPPS(0));
637  m_apcSlicePilot->setSPS(m_parameterSetManagerDecoder.getPrefetchedSPS(0));
638#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
639#if QC_MVHEVC_B0046
640  m_apcSlicePilot->setIsDepth(false);
641#endif
642  m_apcSlicePilot->setVPS(m_parameterSetManagerDecoder.getPrefetchedVPS(0));
643#endif
644  m_apcSlicePilot->initTiles();
645#if QC_MVHEVC_B0046
646  m_apcSlicePilot->setViewId( nalu.m_layerId );
647  m_apcSlicePilot->setViewId( nalu.m_layerId );
648  m_apcSlicePilot->setViewOrderIdx(m_apcSlicePilot->getVPS()->getViewId(nalu.m_layerId), nalu.m_layerId);
649  Int iNumDirectRef = m_apcSlicePilot->getVPS()->getNumDirectRefLayer(nalu.m_layerId);
650  m_apcSlicePilot->getSPS()->setNumberOfUsableInterViewRefs(iNumDirectRef);
651  for(Int iNumIvRef = 0; iNumIvRef < iNumDirectRef; iNumIvRef ++)
652  {
653    Int iDeltaLayerId = m_apcSlicePilot->getVPS()->getDirectRefLayerId( nalu.m_layerId, iNumIvRef);
654    m_apcSlicePilot->getSPS()->setUsableInterViewRef(iNumIvRef, (iDeltaLayerId-nalu.m_layerId));
655  }
656#endif
657  if (m_bFirstSliceInPicture)
658  {
659    m_uiSliceIdx     = 0;
660    m_uiLastSliceIdx = 0;
661  }
662  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
663  if (!m_bFirstSliceInPicture)
664  {
665    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
666  }
667
668  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
669  if( m_bFirstSliceInPicture )
670  {
671#if QC_MVHEVC_B0046
672    if( nalu.m_layerId == 0 ) { m_nalUnitTypeBaseView = nalu.m_nalUnitType; }
673    else                     { m_nalUnitTypeBaseView = m_tAppDecTop->getTDecTop( 0, 0 )->getNalUnitTypeBaseView(); }
674#else
675#if VIDYO_VPS_INTEGRATION
676    if( m_apcSlicePilot->getVPS()->getViewId(nalu.m_layerId) == 0 ) { m_nalUnitTypeBaseView = nalu.m_nalUnitType; }
677    else { m_nalUnitTypeBaseView = m_tAppDecTop->getTDecTop( 0, m_apcSlicePilot->getVPS()->getDepthFlag(nalu.m_layerId) )->getNalUnitTypeBaseView(); }
678#else
679    if( nalu.m_viewId == 0 ) { m_nalUnitTypeBaseView = nalu.m_nalUnitType; }
680    else                     { m_nalUnitTypeBaseView = m_tAppDecTop->getTDecTop( 0, nalu.m_isDepth )->getNalUnitTypeBaseView(); }
681#endif
682#endif
683    m_apcSlicePilot->setNalUnitTypeBaseViewMvc( m_nalUnitTypeBaseView );
684  }
685
686#if NAL_REF_FLAG
687  m_apcSlicePilot->setReferenced(nalu.m_nalRefFlag);
688#else
689  m_apcSlicePilot->setReferenced(nalu.m_nalRefIDC != NAL_REF_IDC_PRIORITY_LOWEST);
690#endif
691  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
692
693  // ALF CU parameters should be part of the slice header -> needs to be fixed
694#if LCU_SYNTAX_ALF
695#if MTK_DEPTH_MERGE_TEXTURE_CANDIDATE_C0137
696  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder, m_cGopDecoder.getAlfCuCtrlParam(), m_cGopDecoder.getAlfParamSet(),m_apcSlicePilot->getVPS()->getDepthFlag(nalu.m_layerId));
697#else
698  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder, m_cGopDecoder.getAlfCuCtrlParam(), m_cGopDecoder.getAlfParamSet());
699#endif
700#else
701  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder, m_cGopDecoder.getAlfCuCtrlParam() );
702#endif
703  // byte align
704  {
705    Int numBitsForByteAlignment = nalu.m_Bitstream->getNumBitsUntilByteAligned();
706    if ( numBitsForByteAlignment > 0 )
707    {
708      UInt bitsForByteAlignment;
709      nalu.m_Bitstream->read( numBitsForByteAlignment, bitsForByteAlignment );
710      assert( bitsForByteAlignment == ( ( 1 << numBitsForByteAlignment ) - 1 ) );
711    }
712  }
713
714  // exit when a new picture is found
715  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence)
716  {
717#if START_DECODING_AT_CRA
718    if (m_prevPOC >= m_pocRandomAccess)
719    {
720      m_prevPOC = m_apcSlicePilot->getPOC();
721      return true;
722    }
723    m_prevPOC = m_apcSlicePilot->getPOC();
724#else
725    m_prevPOC = m_apcSlicePilot->getPOC();
726    return true;
727#endif
728  }
729  // actual decoding starts here
730  xActivateParameterSets();
731  m_apcSlicePilot->initTiles();
732
733  if (m_apcSlicePilot->isNextSlice()) 
734  {
735    m_prevPOC = m_apcSlicePilot->getPOC();
736  }
737  m_bFirstSliceInSequence = false;
738  if (m_apcSlicePilot->isNextSlice())
739  {
740    // Skip pictures due to random access
741    if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
742    {
743      return false;
744    }
745  }
746  //detect lost reference picture and insert copy of earlier frame.
747#if START_DECODING_AT_CRA
748  while(m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess) > 0)
749#else
750  while(m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true) > 0)
751#endif
752  {
753    xCreateLostPicture(m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), false)-1);
754  }
755  if (m_bFirstSliceInPicture)
756  {
757    // Buffer initialize for prediction.
758    m_cPrediction.initTempBuff();
759    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
760    //  Get a new picture buffer
761    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
762
763#if INTER_VIEW_VECTOR_SCALING_C0115
764    pcPic->setViewOrderIdx( m_apcSlicePilot->getVPS()->getViewOrderIdx(nalu.m_layerId) );    // will be changed to view_id
765#endif
766    /* transfer any SEI messages that have been received to the picture */
767    pcPic->setSEIs(m_SEIs);
768    m_SEIs = NULL;
769
770    // Recursive structure
771    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
772    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
773    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
774
775    m_cSliceDecoder.create( m_apcSlicePilot, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
776#if DEPTH_MAP_GENERATION
777    UInt uiPdm = ( m_apcSlicePilot->getSPS()->getViewId() ? m_apcSlicePilot->getSPS()->getPredDepthMapGeneration() : m_tAppDecTop->getSPSAccess()->getPdm() );
778    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) );
779    TComDepthMapGenerator* pcDMG0 = m_tAppDecTop->getDecTop0()->getDepthMapGenerator();
780    if( m_apcSlicePilot->getSPS()->getViewId() == 1 && ( pcDMG0->getSubSampExpX() != PDM_SUB_SAMP_EXP_X(uiPdm) || pcDMG0->getSubSampExpY() != PDM_SUB_SAMP_EXP_Y(uiPdm) ) )
781    {
782      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) );
783    }
784#endif
785#if HHI_INTER_VIEW_RESIDUAL_PRED
786    m_cResidualGenerator.create( true, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement );
787#endif
788  }
789
790  //  Set picture slice pointer
791  TComSlice*  pcSlice = m_apcSlicePilot;
792  Bool bNextSlice     = pcSlice->isNextSlice();
793
794  UInt uiCummulativeTileWidth;
795  UInt uiCummulativeTileHeight;
796  UInt i, j, p;
797
798#if !REMOVE_TILE_DEPENDENCE
799  //set the TileBoundaryIndependenceIdr
800  if(pcSlice->getPPS()->getTileBehaviorControlPresentFlag() == 1)
801  {
802    pcPic->getPicSym()->setTileBoundaryIndependenceIdr( pcSlice->getPPS()->getTileBoundaryIndependenceIdr() );
803  }
804  else
805  {
806    pcPic->getPicSym()->setTileBoundaryIndependenceIdr( pcSlice->getPPS()->getSPS()->getTileBoundaryIndependenceIdr() );
807  }
808#endif
809
810  if( pcSlice->getPPS()->getColumnRowInfoPresent() == 1 )
811  {
812    //set NumColumnsMins1 and NumRowsMinus1
813    pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
814    pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
815
816    //create the TComTileArray
817    pcPic->getPicSym()->xCreateTComTileArray();
818
819    if( pcSlice->getPPS()->getUniformSpacingIdr() == 1)
820    {
821      //set the width for each tile
822      for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
823      {
824        for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
825        {
826          pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
827            setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
828            - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
829        }
830      }
831
832      //set the height for each tile
833      for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
834      {
835        for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
836        {
837          pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
838            setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
839            - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
840        }
841      }
842    }
843    else
844    {
845      //set the width for each tile
846      for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
847      {
848        uiCummulativeTileWidth = 0;
849        for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
850        {
851          pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
852          uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
853        }
854        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
855      }
856
857      //set the height for each tile
858      for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
859      {
860        uiCummulativeTileHeight = 0;
861        for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
862        { 
863          pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
864          uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
865        }
866        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
867      }
868    }
869  }
870  else
871  {
872    //set NumColumnsMins1 and NumRowsMinus1
873    pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getSPS()->getNumColumnsMinus1() );
874    pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getSPS()->getNumRowsMinus1() );
875
876    //create the TComTileArray
877    pcPic->getPicSym()->xCreateTComTileArray();
878
879    //automatically set the column and row boundary if UniformSpacingIdr = 1
880    if( pcSlice->getSPS()->getUniformSpacingIdr() == 1 )
881    {
882      //set the width for each tile
883      for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
884      {
885        for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
886        {
887          pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
888            setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
889            - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
890        }
891      }
892
893      //set the height for each tile
894      for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
895      {
896        for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
897        {
898          pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
899            setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
900            - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
901        }
902      }
903    }
904    else
905    {
906      //set the width for each tile
907      for(j=0; j < pcSlice->getSPS()->getNumRowsMinus1()+1; j++)
908      {
909        uiCummulativeTileWidth = 0;
910        for(i=0; i < pcSlice->getSPS()->getNumColumnsMinus1(); i++)
911        {
912          pcPic->getPicSym()->getTComTile(j * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getSPS()->getColumnWidth(i) );
913          uiCummulativeTileWidth += pcSlice->getSPS()->getColumnWidth(i);
914        }
915        pcPic->getPicSym()->getTComTile(j * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
916      }
917
918      //set the height for each tile
919      for(j=0; j < pcSlice->getSPS()->getNumColumnsMinus1()+1; j++)
920      {
921        uiCummulativeTileHeight = 0;
922        for(i=0; i < pcSlice->getSPS()->getNumRowsMinus1(); i++)
923        { 
924          pcPic->getPicSym()->getTComTile(i * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getSPS()->getRowHeight(i) );
925          uiCummulativeTileHeight += pcSlice->getSPS()->getRowHeight(i);
926        }
927        pcPic->getPicSym()->getTComTile(i * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
928      }
929    }
930  }
931
932  pcPic->getPicSym()->xInitTiles();
933
934  //generate the Coding Order Map and Inverse Coding Order Map
935  UInt uiEncCUAddr;
936  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
937  {
938    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
939    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
940  }
941  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
942  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
943
944  //convert the start and end CU addresses of the slice and entropy slice into encoding order
945  pcSlice->setEntropySliceCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getEntropySliceCurStartCUAddr()) );
946  pcSlice->setEntropySliceCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getEntropySliceCurEndCUAddr()) );
947  if(pcSlice->isNextSlice())
948  {
949    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
950    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
951  }
952
953  if (m_bFirstSliceInPicture) 
954  {
955    if(pcPic->getNumAllocatedSlice() != 1)
956    {
957      pcPic->clearSliceBuffer();
958    }
959  }
960  else
961  {
962    pcPic->allocateNewSlice();
963  }
964  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
965  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
966  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
967
968  pcPic->setTLayer(nalu.m_temporalId);
969
970  if (bNextSlice)
971  {
972    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_cListPic); 
973
974    if ( !pcSlice->getPPS()->getEnableTMVPFlag() && pcPic->getTLayer() == 0 )
975    {
976      pcSlice->decodingMarkingForNoTMVP( m_cListPic, pcSlice->getPOC() );
977    }
978
979    // Set reference list
980#if !QC_MVHEVC_B0046
981#if VIDYO_VPS_INTEGRATION
982    pcSlice->setViewId( pcSlice->getVPS()->getViewId(nalu.m_layerId) );
983    pcSlice->setIsDepth( pcSlice->getVPS()->getDepthFlag(nalu.m_layerId) );
984#else
985    pcSlice->setViewId(m_viewId);
986    pcSlice->setIsDepth(m_isDepth);
987#endif
988#endif
989
990#if INTER_VIEW_VECTOR_SCALING_C0115
991#if VIDYO_VPS_INTEGRATION
992    pcSlice->setViewOrderIdx( pcSlice->getVPS()->getViewOrderIdx(nalu.m_layerId) );        // will be changed to view_id
993#else
994    pcSlice->setViewOrderIdx( pcPic->getViewOrderIdx() );
995#endif
996#endif
997
998#if INTER_VIEW_VECTOR_SCALING_C0115
999    pcSlice->setIVScalingFlag( pcSlice->getVPS()->getIVScalingFlag());
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 || OL_QTLIMIT_PREDCODING_B0068
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.