source: 3DVCSoftware/branches/HTM-5.1-dev0-MERL-Mediatek-Fix/source/Lib/TLibDecoder/TDecTop.cpp @ 1417

Last change on this file since 1417 was 280, checked in by tech, 12 years ago

Integration of branch dev 2.

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