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

Last change on this file since 296 was 296, checked in by tech, 11 years ago

Reintegrated branch 5.1-dev0 rev. 295.

  • Property svn:eol-style set to native
File size: 49.0 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 H3D_IVRP
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 H3D_IVRP
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 H3D_IVRP
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 H3D_IVRP
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  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer())+pcSlice->getSPS()->getNumReorderPics(pcSlice->getTLayer()) + 1; // +1 to have space for the picture currently being decoded
528
529#if DEPTH_MAP_GENERATION
530  UInt uiPdm                  = ( pcSlice->getSPS()->getViewId() ? pcSlice->getSPS()->getPredDepthMapGeneration() : m_tAppDecTop->getSPSAccess()->getPdm() );
531  Bool bNeedPrdDepthMapBuffer = ( !pcSlice->getSPS()->isDepth() && uiPdm > 0 );
532#endif
533
534  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
535  {
536    rpcPic = new TComPic();
537   
538    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true);
539   
540#if DEPTH_MAP_GENERATION
541    if( bNeedPrdDepthMapBuffer )
542    {
543      rpcPic->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
544    }
545#endif
546   
547    m_cListPic.pushBack( rpcPic );
548   
549    return;
550  }
551 
552  Bool bBufferIsAvailable = false;
553  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
554  while (iterPic != m_cListPic.end())
555  {
556    rpcPic = *(iterPic++);
557    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
558    {
559      rpcPic->setOutputMark(false);
560      bBufferIsAvailable = true;
561      break;
562    }
563
564    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
565    {
566      rpcPic->setOutputMark(false);
567      rpcPic->setReconMark( false );
568      rpcPic->getPicYuvRec()->setBorderExtension( false );
569      bBufferIsAvailable = true;
570      break;
571    }
572  }
573 
574  if ( !bBufferIsAvailable )
575  {
576    //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer.
577    m_iMaxRefPicNum++;
578    rpcPic = new TComPic();
579    m_cListPic.pushBack( rpcPic );
580  }
581  rpcPic->destroy(); 
582  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true);
583#if DEPTH_MAP_GENERATION
584  if( bNeedPrdDepthMapBuffer && !rpcPic->getPredDepthMap() )
585  {
586    rpcPic->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
587  }
588#endif
589}
590
591Void TDecTop::executeDeblockAndAlf(UInt& ruiPOC, TComList<TComPic*>*& rpcListPic, Int& iSkipFrame, Int& iPOCLastDisplay)
592{
593  if (!m_pcPic)
594  {
595    /* nothing to deblock */
596    return;
597  }
598 
599  TComPic*&   pcPic         = m_pcPic;
600
601  // Execute Deblock and ALF only + Cleanup
602
603  m_cGopDecoder.decompressGop(NULL, pcPic, true);
604
605  TComSlice::sortPicList( m_cListPic ); // sorting for application output
606  ruiPOC              = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
607  rpcListPic          = &m_cListPic; 
608  m_cCuDecoder.destroy();       
609  m_bFirstSliceInPicture  = true;
610
611  return;
612}
613
614Void TDecTop::xCreateLostPicture(Int iLostPoc) 
615{
616  printf("\ninserting lost poc : %d\n",iLostPoc);
617  TComSlice cFillSlice;
618  cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
619  cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
620  cFillSlice.initSlice();
621  cFillSlice.initTiles();
622  TComPic *cFillPic;
623  xGetNewPicBuffer(&cFillSlice,cFillPic);
624  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
625  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
626  cFillPic->getSlice(0)->initSlice();
627  cFillPic->getSlice(0)->initTiles();
628
629 
630 
631  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
632  Int closestPoc = 1000000;
633  while ( iterPic != m_cListPic.end())
634  {
635    TComPic * rpcPic = *(iterPic++);
636    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())
637    {
638      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
639    }
640  }
641  iterPic = m_cListPic.begin();
642  while ( iterPic != m_cListPic.end())
643  {
644    TComPic *rpcPic = *(iterPic++);
645    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
646    {
647      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
648      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
649      break;
650    }
651  }
652  cFillPic->setCurrSliceIdx(0);
653  for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) 
654  {
655    cFillPic->getCU(i)->initCU(cFillPic,i);
656  }
657  cFillPic->getSlice(0)->setReferenced(true);
658  cFillPic->getSlice(0)->setPOC(iLostPoc);
659  cFillPic->setReconMark(true);
660  cFillPic->setOutputMark(true);
661  if(m_pocRandomAccess == MAX_INT)
662  {
663    m_pocRandomAccess = iLostPoc;
664  }
665}
666
667
668Void TDecTop::xActivateParameterSets()
669{
670  m_parameterSetManagerDecoder.applyPrefetchedPS();
671
672  TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
673  assert (pps != 0);
674
675  TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId());
676  assert (sps != 0);
677#if VIDYO_VPS_INTEGRATION
678  TComVPS *vps = m_parameterSetManagerDecoder.getVPS(sps->getVPSId());
679  assert (vps != 0);
680#if !QC_REM_IDV_B0046
681  if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA )
682#else
683  if( (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA) && !sps->getViewId() )
684#endif
685    // VPS can only be activated on IDR or CRA...
686    getTAppDecTop()->getVPSAccess()->setActiveVPSId( sps->getVPSId() );
687#endif
688  m_apcSlicePilot->setPPS(pps);
689  m_apcSlicePilot->setSPS(sps);
690#if QC_MVHEVC_B0046
691  TComVPS *vps = m_parameterSetManagerDecoder.getVPS(sps->getVPSId());
692#endif
693#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
694  m_apcSlicePilot->setVPS(vps);
695#endif
696  pps->setSPS(sps);
697
698  if(sps->getUseSAO() || sps->getUseALF()|| sps->getScalingListFlag() || sps->getUseDF())
699  {
700    m_apcSlicePilot->setAPS( m_parameterSetManagerDecoder.getAPS(m_apcSlicePilot->getAPSId())  );
701  }
702  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
703
704  for (Int i = 0; i < sps->getMaxCUDepth() - 1; i++)
705  {
706    sps->setAMPAcc( i, sps->getUseAMP() );
707  }
708
709  for (Int i = sps->getMaxCUDepth() - 1; i < sps->getMaxCUDepth(); i++)
710  {
711    sps->setAMPAcc( i, 0 );
712  }
713
714  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
715  m_cLoopFilter.        create( g_uiMaxCUDepth );
716}
717
718Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
719{
720  TComPic*&   pcPic         = m_pcPic;
721  m_apcSlicePilot->initSlice();
722
723  //!!!KS: DIRTY HACK
724  m_apcSlicePilot->setPPSId(0);
725  m_apcSlicePilot->setPPS(m_parameterSetManagerDecoder.getPrefetchedPPS(0));
726  m_apcSlicePilot->setSPS(m_parameterSetManagerDecoder.getPrefetchedSPS(0));
727#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
728#if QC_MVHEVC_B0046
729  m_apcSlicePilot->setIsDepth(false);
730#endif
731  m_apcSlicePilot->setVPS(m_parameterSetManagerDecoder.getPrefetchedVPS(0));
732#endif
733  m_apcSlicePilot->initTiles();
734#if QC_MVHEVC_B0046
735  m_apcSlicePilot->setViewId( nalu.m_layerId );
736  m_apcSlicePilot->setViewId( nalu.m_layerId );
737  m_apcSlicePilot->setViewOrderIdx(m_apcSlicePilot->getVPS()->getViewId(nalu.m_layerId), nalu.m_layerId);
738  Int iNumDirectRef = m_apcSlicePilot->getVPS()->getNumDirectRefLayer(nalu.m_layerId);
739  m_apcSlicePilot->getSPS()->setNumberOfUsableInterViewRefs(iNumDirectRef);
740  for(Int iNumIvRef = 0; iNumIvRef < iNumDirectRef; iNumIvRef ++)
741  {
742    Int iDeltaLayerId = m_apcSlicePilot->getVPS()->getDirectRefLayerId( nalu.m_layerId, iNumIvRef);
743    m_apcSlicePilot->getSPS()->setUsableInterViewRef(iNumIvRef, (iDeltaLayerId-nalu.m_layerId));
744  }
745#endif
746  if (m_bFirstSliceInPicture)
747  {
748    m_uiSliceIdx     = 0;
749    m_uiLastSliceIdx = 0;
750  }
751  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
752  if (!m_bFirstSliceInPicture)
753  {
754    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
755  }
756
757  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
758  if( m_bFirstSliceInPicture )
759  {
760#if QC_MVHEVC_B0046
761    if( nalu.m_layerId == 0 ) { m_nalUnitTypeBaseView = nalu.m_nalUnitType; }
762    else                     { m_nalUnitTypeBaseView = m_tAppDecTop->getTDecTop( 0, 0 )->getNalUnitTypeBaseView(); }
763#else
764#if VIDYO_VPS_INTEGRATION
765    if( m_apcSlicePilot->getVPS()->getViewId(nalu.m_layerId) == 0 ) { m_nalUnitTypeBaseView = nalu.m_nalUnitType; }
766    else { m_nalUnitTypeBaseView = m_tAppDecTop->getTDecTop( 0, m_apcSlicePilot->getVPS()->getDepthFlag(nalu.m_layerId) )->getNalUnitTypeBaseView(); }
767#else
768    if( nalu.m_viewId == 0 ) { m_nalUnitTypeBaseView = nalu.m_nalUnitType; }
769    else                     { m_nalUnitTypeBaseView = m_tAppDecTop->getTDecTop( 0, nalu.m_isDepth )->getNalUnitTypeBaseView(); }
770#endif
771#endif
772    m_apcSlicePilot->setNalUnitTypeBaseViewMvc( m_nalUnitTypeBaseView );
773  }
774
775  m_apcSlicePilot->setReferenced(nalu.m_nalRefFlag);
776  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
777
778  // ALF CU parameters should be part of the slice header -> needs to be fixed
779#if MTK_DEPTH_MERGE_TEXTURE_CANDIDATE_C0137
780  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder, m_cGopDecoder.getAlfCuCtrlParam(), m_cGopDecoder.getAlfParamSet(),m_apcSlicePilot->getVPS()->getDepthFlag(nalu.m_layerId));
781#else
782  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder, m_cGopDecoder.getAlfCuCtrlParam(), m_cGopDecoder.getAlfParamSet());
783#endif
784  // byte align
785  {
786    Int numBitsForByteAlignment = nalu.m_Bitstream->getNumBitsUntilByteAligned();
787    if ( numBitsForByteAlignment > 0 )
788    {
789      UInt bitsForByteAlignment;
790      nalu.m_Bitstream->read( numBitsForByteAlignment, bitsForByteAlignment );
791      assert( bitsForByteAlignment == ( ( 1 << numBitsForByteAlignment ) - 1 ) );
792    }
793  }
794
795  // exit when a new picture is found
796  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence)
797  {
798    if (m_prevPOC >= m_pocRandomAccess)
799    {
800      m_prevPOC = m_apcSlicePilot->getPOC();
801      return true;
802    }
803    m_prevPOC = m_apcSlicePilot->getPOC();
804  }
805  // actual decoding starts here
806  xActivateParameterSets();
807  m_apcSlicePilot->initTiles();
808
809  if (m_apcSlicePilot->isNextSlice()) 
810  {
811    m_prevPOC = m_apcSlicePilot->getPOC();
812  }
813  m_bFirstSliceInSequence = false;
814  if (m_apcSlicePilot->isNextSlice())
815  {
816    // Skip pictures due to random access
817    if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
818    {
819      return false;
820    }
821  }
822  //detect lost reference picture and insert copy of earlier frame.
823  while(m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess) > 0)
824  {
825    xCreateLostPicture(m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), false)-1);
826  }
827  if (m_bFirstSliceInPicture)
828  {
829    // Buffer initialize for prediction.
830    m_cPrediction.initTempBuff();
831    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
832    //  Get a new picture buffer
833    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
834
835#if INTER_VIEW_VECTOR_SCALING_C0115
836    pcPic->setViewOrderIdx( m_apcSlicePilot->getVPS()->getViewOrderIdx(nalu.m_layerId) );    // will be changed to view_id
837#endif
838    /* transfer any SEI messages that have been received to the picture */
839    pcPic->setSEIs(m_SEIs);
840    m_SEIs = NULL;
841
842    // Recursive structure
843    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
844    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
845    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
846
847    m_cSliceDecoder.create( m_apcSlicePilot, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
848#if DEPTH_MAP_GENERATION
849    UInt uiPdm = ( m_apcSlicePilot->getSPS()->getViewId() ? m_apcSlicePilot->getSPS()->getPredDepthMapGeneration() : m_tAppDecTop->getSPSAccess()->getPdm() );
850    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) );
851    TComDepthMapGenerator* pcDMG0 = m_tAppDecTop->getDecTop0()->getDepthMapGenerator();
852    if( m_apcSlicePilot->getSPS()->getViewId() == 1 && ( pcDMG0->getSubSampExpX() != PDM_SUB_SAMP_EXP_X(uiPdm) || pcDMG0->getSubSampExpY() != PDM_SUB_SAMP_EXP_Y(uiPdm) ) )
853    {
854      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) );
855    }
856#endif
857#if H3D_IVRP
858    m_cResidualGenerator.create( true, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement );
859#endif
860  }
861
862  //  Set picture slice pointer
863  TComSlice*  pcSlice = m_apcSlicePilot;
864  Bool bNextSlice     = pcSlice->isNextSlice();
865
866  UInt uiCummulativeTileWidth;
867  UInt uiCummulativeTileHeight;
868  UInt i, j, p;
869
870
871  if( pcSlice->getPPS()->getColumnRowInfoPresent() == 1 )
872  {
873    //set NumColumnsMins1 and NumRowsMinus1
874    pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
875    pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
876
877    //create the TComTileArray
878    pcPic->getPicSym()->xCreateTComTileArray();
879
880    if( pcSlice->getPPS()->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->getPPS()->getNumRowsMinus1()+1; j++)
908      {
909        uiCummulativeTileWidth = 0;
910        for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
911        {
912          pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
913          uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
914        }
915        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
916      }
917
918      //set the height for each tile
919      for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
920      {
921        uiCummulativeTileHeight = 0;
922        for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
923        { 
924          pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
925          uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
926        }
927        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
928      }
929    }
930  }
931  else
932  {
933    //set NumColumnsMins1 and NumRowsMinus1
934    pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getSPS()->getNumColumnsMinus1() );
935    pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getSPS()->getNumRowsMinus1() );
936
937    //create the TComTileArray
938    pcPic->getPicSym()->xCreateTComTileArray();
939
940    //automatically set the column and row boundary if UniformSpacingIdr = 1
941    if( pcSlice->getSPS()->getUniformSpacingIdr() == 1 )
942    {
943      //set the width for each tile
944      for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
945      {
946        for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
947        {
948          pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
949            setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
950            - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
951        }
952      }
953
954      //set the height for each tile
955      for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
956      {
957        for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
958        {
959          pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
960            setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
961            - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
962        }
963      }
964    }
965    else
966    {
967      //set the width for each tile
968      for(j=0; j < pcSlice->getSPS()->getNumRowsMinus1()+1; j++)
969      {
970        uiCummulativeTileWidth = 0;
971        for(i=0; i < pcSlice->getSPS()->getNumColumnsMinus1(); i++)
972        {
973          pcPic->getPicSym()->getTComTile(j * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getSPS()->getColumnWidth(i) );
974          uiCummulativeTileWidth += pcSlice->getSPS()->getColumnWidth(i);
975        }
976        pcPic->getPicSym()->getTComTile(j * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
977      }
978
979      //set the height for each tile
980      for(j=0; j < pcSlice->getSPS()->getNumColumnsMinus1()+1; j++)
981      {
982        uiCummulativeTileHeight = 0;
983        for(i=0; i < pcSlice->getSPS()->getNumRowsMinus1(); i++)
984        { 
985          pcPic->getPicSym()->getTComTile(i * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getSPS()->getRowHeight(i) );
986          uiCummulativeTileHeight += pcSlice->getSPS()->getRowHeight(i);
987        }
988        pcPic->getPicSym()->getTComTile(i * (pcSlice->getSPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
989      }
990    }
991  }
992
993  pcPic->getPicSym()->xInitTiles();
994
995  //generate the Coding Order Map and Inverse Coding Order Map
996  UInt uiEncCUAddr;
997  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
998  {
999    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
1000    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
1001  }
1002  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
1003  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
1004
1005  //convert the start and end CU addresses of the slice and entropy slice into encoding order
1006  pcSlice->setEntropySliceCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getEntropySliceCurStartCUAddr()) );
1007  pcSlice->setEntropySliceCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getEntropySliceCurEndCUAddr()) );
1008  if(pcSlice->isNextSlice())
1009  {
1010    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
1011    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
1012  }
1013
1014  if (m_bFirstSliceInPicture) 
1015  {
1016    if(pcPic->getNumAllocatedSlice() != 1)
1017    {
1018      pcPic->clearSliceBuffer();
1019    }
1020  }
1021  else
1022  {
1023    pcPic->allocateNewSlice();
1024  }
1025  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
1026  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
1027  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
1028
1029  pcPic->setTLayer(nalu.m_temporalId);
1030
1031  if (bNextSlice)
1032  {
1033    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_cListPic); 
1034
1035    if ( !pcSlice->getPPS()->getEnableTMVPFlag() && pcPic->getTLayer() == 0 )
1036    {
1037      pcSlice->decodingMarkingForNoTMVP( m_cListPic, pcSlice->getPOC() );
1038    }
1039
1040    // Set reference list
1041#if !QC_MVHEVC_B0046
1042#if VIDYO_VPS_INTEGRATION
1043    pcSlice->setViewId( pcSlice->getVPS()->getViewId(nalu.m_layerId) );
1044    pcSlice->setIsDepth( pcSlice->getVPS()->getDepthFlag(nalu.m_layerId) );
1045#else
1046    pcSlice->setViewId(m_viewId);
1047    pcSlice->setIsDepth(m_isDepth);
1048#endif
1049#endif
1050
1051#if INTER_VIEW_VECTOR_SCALING_C0115
1052#if VIDYO_VPS_INTEGRATION
1053    pcSlice->setViewOrderIdx( pcSlice->getVPS()->getViewOrderIdx(nalu.m_layerId) );        // will be changed to view_id
1054#else
1055    pcSlice->setViewOrderIdx( pcPic->getViewOrderIdx() );
1056#endif
1057#endif
1058
1059#if INTER_VIEW_VECTOR_SCALING_C0115
1060    pcSlice->setIVScalingFlag( pcSlice->getVPS()->getIVScalingFlag());
1061#endif
1062
1063    assert( m_tAppDecTop != NULL );
1064    TComPic * const pcTexturePic = m_isDepth ? m_tAppDecTop->getPicFromView(  m_viewId, pcSlice->getPOC(), false ) : NULL;
1065
1066#if FLEX_CODING_ORDER_M23723
1067    if (pcTexturePic != NULL)
1068    {
1069      assert( !m_isDepth || pcTexturePic != NULL );
1070      pcSlice->setTexturePic( pcTexturePic );
1071    }
1072#else
1073    assert( !m_isDepth || pcTexturePic != NULL );
1074    pcSlice->setTexturePic( pcTexturePic );
1075#endif
1076
1077
1078    std::vector<TComPic*> apcInterViewRefPics = m_tAppDecTop->getInterViewRefPics( m_viewId, pcSlice->getPOC(), m_isDepth, pcSlice->getSPS() );
1079    pcSlice->setRefPicListMvc( m_cListPic, apcInterViewRefPics );
1080
1081    // For generalized B
1082    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
1083    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
1084    {
1085      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
1086      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
1087
1088      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
1089      {
1090        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
1091      }
1092    }
1093    if (pcSlice->isInterB())
1094    {
1095      Bool bLowDelay = true;
1096      Int  iCurrPOC  = pcSlice->getPOC();
1097      Int iRefIdx = 0;
1098
1099      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
1100      {
1101        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
1102        {
1103          bLowDelay = false;
1104        }
1105      }
1106      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
1107      {
1108        if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
1109        {
1110          bLowDelay = false;
1111        }
1112      }
1113
1114      pcSlice->setCheckLDC(bLowDelay);           
1115    }
1116
1117    //---------------
1118    pcSlice->setRefPOCnViewListsMvc();
1119
1120    if(!pcSlice->getRefPicListModificationFlagLC())
1121    {
1122      pcSlice->generateCombinedList();
1123    }
1124
1125    if( pcSlice->getRefPicListCombinationFlag() && pcSlice->getPPS()->getWPBiPredIdc()==1 && pcSlice->getSliceType()==B_SLICE )
1126    {
1127      pcSlice->setWpParamforLC();
1128    }
1129    pcSlice->setNoBackPredFlag( false );
1130    if ( pcSlice->getSliceType() == B_SLICE && !pcSlice->getRefPicListCombinationFlag())
1131    {
1132      if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) )
1133      {
1134        pcSlice->setNoBackPredFlag( true );
1135        for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ )
1136        {
1137          if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) 
1138          {
1139            pcSlice->setNoBackPredFlag( false );
1140            break;
1141          }
1142        }
1143      }
1144    }
1145  }
1146
1147  pcPic->setCurrSliceIdx(m_uiSliceIdx);
1148  if(pcSlice->getSPS()->getScalingListFlag())
1149  {
1150    if(pcSlice->getAPS()->getScalingListEnabled())
1151    {
1152      pcSlice->setScalingList ( pcSlice->getAPS()->getScalingList()  );
1153      if(pcSlice->getScalingList()->getScalingListPresentFlag())
1154      {
1155        pcSlice->setDefaultScalingList();
1156      }
1157      m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
1158    }
1159    m_cTrQuant.setUseScalingList(true);
1160  }
1161  else
1162  {
1163    m_cTrQuant.setFlatScalingList();
1164    m_cTrQuant.setUseScalingList(false);
1165  }
1166
1167#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
1168  if( m_parameterSetManagerDecoder.getPrefetchedSPS(0)->getUseDMM() && g_aacWedgeLists.empty() )
1169  {
1170    initWedgeLists();
1171  }
1172#endif
1173
1174#if MERL_VSP_C0152 // set BW LUT
1175  if( m_pcCamParsCollector ) // Initialize the LUT elements
1176  {
1177    m_pcCamParsCollector->setSlice( pcSlice );
1178  }
1179  if( pcSlice->getViewId() !=0 )
1180  {
1181    TComPic* pcBaseTxtPic = m_tAppDecTop->getPicFromView(  0, pcSlice->getPOC(), false );  // get base view reconstructed texture
1182    TComPic* pcBaseDepthPic = m_tAppDecTop->getPicFromView(  0, pcSlice->getPOC(), true ); // get base view reconstructed depth
1183     pcSlice->setRefPicBaseTxt(pcBaseTxtPic);
1184     pcSlice->setRefPicBaseDepth(pcBaseDepthPic);
1185  }
1186  getTAppDecTop()->setBWVSPLUT( pcSlice, pcSlice->getViewId(),  pcSlice->getPOC() ); // get the LUT for backward warping
1187#endif
1188
1189  //  Decode a picture
1190  m_cGopDecoder.decompressGop(nalu.m_Bitstream, pcPic, false);
1191
1192#if QC_IV_AS_LT_B0046
1193  std::vector<TComPic*> apcInterViewRefPics = m_tAppDecTop->getInterViewRefPics( m_viewId, pcSlice->getPOC(), m_isDepth, pcSlice->getSPS() );
1194  for( Int k = 0; k < apcInterViewRefPics.size(); k++ )
1195  {
1196    TComPic*  pcPicIv = apcInterViewRefPics[k];
1197    pcPicIv->setIsLongTerm( 0 );
1198  }
1199#endif
1200  if( m_pcCamParsCollector )
1201  {
1202    m_pcCamParsCollector->setSlice( pcSlice );
1203  }
1204
1205  m_bFirstSliceInPicture = false;
1206  m_uiSliceIdx++;
1207
1208  return false;
1209}
1210
1211#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
1212Void TDecTop::xDecodeVPS()
1213{
1214  TComVPS* vps = new TComVPS();
1215 
1216  m_cEntropyDecoder.decodeVPS( vps );
1217  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
1218#if !QC_MVHEVC_B0046
1219  getTAppDecTop()->getVPSAccess()->addVPS( vps );
1220#endif
1221}
1222#endif
1223
1224Void TDecTop::xDecodeSPS()
1225{
1226  TComSPS* sps = new TComSPS();
1227  TComRPSList* rps = new TComRPSList();
1228  sps->setRPSList(rps);
1229#if HHI_MPI || OL_QTLIMIT_PREDCODING_B0068
1230  m_cEntropyDecoder.decodeSPS( sps, m_isDepth );
1231#else
1232  m_cEntropyDecoder.decodeSPS( sps );
1233#endif
1234  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
1235  m_cAdaptiveLoopFilter.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
1236}
1237
1238Void TDecTop::xDecodePPS()
1239{
1240  TComPPS* pps = new TComPPS();
1241  m_cEntropyDecoder.decodePPS( pps, &m_parameterSetManagerDecoder );
1242  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
1243
1244  //!!!KS: Activate parameter sets for parsing APS (unless dependency is resolved)
1245  m_apcSlicePilot->setPPSId(pps->getPPSId());
1246  xActivateParameterSets();
1247  m_apcSlicePilot->initTiles();
1248}
1249
1250Void TDecTop::xDecodeAPS()
1251{
1252  TComAPS  *aps = new TComAPS();
1253  allocAPS (aps);
1254  decodeAPS(aps);
1255  m_parameterSetManagerDecoder.storePrefetchedAPS(aps);
1256}
1257
1258Void TDecTop::xDecodeSEI()
1259{
1260  m_SEIs = new SEImessages;
1261  m_cEntropyDecoder.decodeSEI(*m_SEIs);
1262}
1263
1264Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1265{
1266  // Initialize entropy decoder
1267  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1268  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
1269
1270  switch (nalu.m_nalUnitType)
1271  {
1272#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
1273    case NAL_UNIT_VPS:
1274      xDecodeVPS();
1275      return false;
1276#endif
1277    case NAL_UNIT_SPS:
1278      xDecodeSPS();
1279      return false;
1280
1281    case NAL_UNIT_PPS:
1282      xDecodePPS();
1283      return false;
1284    case NAL_UNIT_APS:
1285      xDecodeAPS();
1286      return false;
1287
1288    case NAL_UNIT_SEI:
1289      xDecodeSEI();
1290      return false;
1291
1292    case NAL_UNIT_CODED_SLICE:
1293    case NAL_UNIT_CODED_SLICE_IDR:
1294#if !QC_REM_IDV_B0046
1295    case NAL_UNIT_CODED_SLICE_IDV:
1296#endif
1297    case NAL_UNIT_CODED_SLICE_CRA:
1298    case NAL_UNIT_CODED_SLICE_TLA:
1299      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1300      break;
1301    default:
1302      assert (1);
1303  }
1304
1305  return false;
1306}
1307
1308#if QC_MVHEVC_B0046
1309Void TDecTop::xCopyVPS( TComVPS* pVPSV0 )
1310{
1311  m_parameterSetManagerDecoder.storePrefetchedVPS(pVPSV0); 
1312}
1313
1314Void TDecTop::xCopySPS( TComSPS* pSPSV0 )
1315{
1316  TComSPS* sps = new TComSPS();
1317  sps = pSPSV0;
1318  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
1319  m_cAdaptiveLoopFilter.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
1320}
1321
1322Void TDecTop::xCopyPPS(TComPPS* pPPSV0 )
1323{
1324  m_parameterSetManagerDecoder.storePrefetchedPPS( pPPSV0 );
1325
1326  //!!!KS: Activate parameter sets for parsing APS (unless dependency is resolved)
1327  m_apcSlicePilot->setPPSId(pPPSV0->getPPSId());
1328  xActivateParameterSets();
1329  m_apcSlicePilot->initTiles();
1330}
1331#endif
1332/** Function for checking if picture should be skipped because of random access
1333 * \param iSkipFrame skip frame counter
1334 * \param iPOCLastDisplay POC of last picture displayed
1335 * \returns true if the picture shold be skipped in the random access.
1336 * This function checks the skipping of pictures in the case of -s option random access.
1337 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1338 * It also checks the type of Nal unit type at the random access point.
1339 * If the random access point is CRA, pictures with POC equal to or greater than the CRA POC are decoded.
1340 * If the random access point is IDR all pictures after the random access point are decoded.
1341 * If the random access point is not IDR or CRA, a warning is issues, and decoding of pictures with POC
1342 * equal to or greater than the random access point POC is attempted. For non IDR/CRA random
1343 * access point there is no guarantee that the decoder will not crash.
1344 */
1345Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
1346{
1347  if (iSkipFrame) 
1348  {
1349    iSkipFrame--;   // decrement the counter
1350    return true;
1351  }
1352  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1353  {
1354    if( m_apcSlicePilot->getNalUnitTypeBaseViewMvc() == NAL_UNIT_CODED_SLICE_CRA )
1355    {
1356      m_pocRandomAccess = m_apcSlicePilot->getPOC(); // set the POC random access since we need to skip the reordered pictures in CRA.
1357    }
1358    else if( m_apcSlicePilot->getNalUnitTypeBaseViewMvc() == NAL_UNIT_CODED_SLICE_IDR )
1359    {
1360      m_pocRandomAccess = 0; // no need to skip the reordered pictures in IDR, they are decodable.
1361    }
1362    else 
1363    {
1364      static bool warningMessage = false;
1365      if(!warningMessage)
1366      {
1367        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1368        warningMessage = true;
1369      }
1370      return true;
1371    }
1372  }
1373  else if (m_apcSlicePilot->getPOC() < m_pocRandomAccess)  // skip the reordered pictures if necessary
1374  {
1375    iPOCLastDisplay++;
1376    return true;
1377  }
1378  // if we reach here, then the picture is not skipped.
1379  return false; 
1380}
1381
1382Void TDecTop::allocAPS (TComAPS* pAPS)
1383{
1384  // we don't know the SPS before it has been activated. These fields could exist
1385  // depending on the corresponding flags in the APS, but SAO/ALF allocation functions will
1386  // have to be moved for that
1387  pAPS->createScalingList();
1388  pAPS->createSaoParam();
1389  m_cSAO.allocSaoParam(pAPS->getSaoParam());
1390  pAPS->createAlfParam();
1391}
1392
1393//! \}
Note: See TracBrowser for help on using the repository browser.