source: 3DVCSoftware/branches/HTM-DEV-0.3-dev2a/source/Lib/TLibDecoder/TDecTop.cpp @ 465

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

Fixed some minor memory leaks.

  • Property svn:eol-style set to native
File size: 42.4 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-2013, 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#if H_3D_ARP
40#include "../../App/TAppDecoder/TAppDecTop.h"
41#endif
42#include "TDecTop.h"
43
44#if H_MV
45ParameterSetManagerDecoder TDecTop::m_parameterSetManagerDecoder;
46#endif
47//! \ingroup TLibDecoder
48//! \{
49
50#if H_3D
51CamParsCollector::CamParsCollector()
52: m_bInitialized( false )
53{
54  m_aaiCodedOffset         = new Int* [ MAX_NUM_LAYERS ];
55  m_aaiCodedScale          = new Int* [ MAX_NUM_LAYERS ];
56  m_aiViewId               = new Int  [ MAX_NUM_LAYERS ];
57#if !H_3D_FIX 
58  m_aiLayerIdx             = new Int  [ MAX_NUM_LAYERS ];
59#endif
60
61  m_bViewReceived          = new Bool [ MAX_NUM_LAYERS ];
62  for( UInt uiId = 0; uiId < MAX_NUM_LAYERS; uiId++ )
63  {
64    m_aaiCodedOffset      [ uiId ] = new Int [ MAX_NUM_LAYERS ];
65    m_aaiCodedScale       [ uiId ] = new Int [ MAX_NUM_LAYERS ];
66  }
67
68  xCreateLUTs( (UInt)MAX_NUM_LAYERS, (UInt)MAX_NUM_LAYERS, m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
69  m_iLog2Precision   = LOG2_DISP_PREC_LUT;
70  m_uiBitDepthForLUT = 8; // fixed
71}
72
73CamParsCollector::~CamParsCollector()
74{
75  for( UInt uiId = 0; uiId < MAX_NUM_LAYERS; uiId++ )
76  {
77    delete [] m_aaiCodedOffset      [ uiId ];
78    delete [] m_aaiCodedScale       [ uiId ];
79  }
80  delete [] m_aaiCodedOffset;
81  delete [] m_aaiCodedScale;
82  delete [] m_aiViewId; 
83  delete [] m_bViewReceived;
84
85  xDeleteArray( m_adBaseViewShiftLUT, MAX_NUM_LAYERS, MAX_NUM_LAYERS, 2 );
86  xDeleteArray( m_aiBaseViewShiftLUT, MAX_NUM_LAYERS, MAX_NUM_LAYERS, 2 );
87}
88
89Void
90CamParsCollector::init( FILE* pCodedScaleOffsetFile )
91{
92  m_bInitialized            = true;
93  m_pCodedScaleOffsetFile   = pCodedScaleOffsetFile;
94  m_uiCamParsCodedPrecision = 0;
95  m_bCamParsVaryOverTime    = false;
96  m_iLastViewIndex             = -1;
97  m_iLastPOC                = -1;
98  m_uiMaxViewIndex             = 0;
99}
100
101Void
102CamParsCollector::xCreateLUTs( UInt uiNumberSourceViews, UInt uiNumberTargetViews, Double****& radLUT, Int****& raiLUT)
103{
104
105  uiNumberSourceViews = std::max( (UInt) 1, uiNumberSourceViews );
106  uiNumberTargetViews = std::max( (UInt) 1, uiNumberTargetViews );
107
108  radLUT         = new Double***[ uiNumberSourceViews ];
109  raiLUT         = new Int   ***[ uiNumberSourceViews ];
110
111  for( UInt uiSourceView = 0; uiSourceView < uiNumberSourceViews; uiSourceView++ )
112  {
113    radLUT        [ uiSourceView ] = new Double**[ uiNumberTargetViews ];
114    raiLUT        [ uiSourceView ] = new Int   **[ uiNumberTargetViews ];
115
116    for( UInt uiTargetView = 0; uiTargetView < uiNumberTargetViews; uiTargetView++ )
117    {
118      radLUT        [ uiSourceView ][ uiTargetView ]      = new Double*[ 2 ];
119      radLUT        [ uiSourceView ][ uiTargetView ][ 0 ] = new Double [ 257 ];
120      radLUT        [ uiSourceView ][ uiTargetView ][ 1 ] = new Double [ 257 ];
121
122      raiLUT        [ uiSourceView ][ uiTargetView ]      = new Int*   [ 2 ];
123      raiLUT        [ uiSourceView ][ uiTargetView ][ 0 ] = new Int    [ 257 ];
124      raiLUT        [ uiSourceView ][ uiTargetView ][ 1 ] = new Int    [ 257 ];
125    }
126  }
127}
128
129Void
130  CamParsCollector::xInitLUTs( UInt uiSourceView, UInt uiTargetView, Int iScale, Int iOffset, Double****& radLUT, Int****& raiLUT)
131{
132  Int     iLog2DivLuma   = m_uiBitDepthForLUT + m_uiCamParsCodedPrecision + 1 - m_iLog2Precision;   AOF( iLog2DivLuma > 0 );
133  Int     iLog2DivChroma = iLog2DivLuma + 1;
134
135  iOffset <<= m_uiBitDepthForLUT;
136
137  Double dScale  = (Double) iScale  / (( Double ) ( 1 << iLog2DivLuma ));
138  Double dOffset = (Double) iOffset / (( Double ) ( 1 << iLog2DivLuma ));
139
140  // offsets including rounding offsets
141  Int64 iOffsetLuma   = iOffset + ( ( 1 << iLog2DivLuma   ) >> 1 );
142  Int64 iOffsetChroma = iOffset + ( ( 1 << iLog2DivChroma ) >> 1 );
143
144
145  for( UInt uiDepthValue = 0; uiDepthValue < 256; uiDepthValue++ )
146  {
147
148    // real-valued look-up tables
149    Double  dShiftLuma      = ( (Double)uiDepthValue * dScale + dOffset ) * Double( 1 << m_iLog2Precision );
150    Double  dShiftChroma    = dShiftLuma / 2;
151    radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = dShiftLuma;
152    radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = dShiftChroma;
153
154    // integer-valued look-up tables
155    Int64   iTempScale      = (Int64)uiDepthValue * iScale;
156    Int64   iShiftLuma      = ( iTempScale + iOffsetLuma   ) >> iLog2DivLuma;
157    Int64   iShiftChroma    = ( iTempScale + iOffsetChroma ) >> iLog2DivChroma;
158    raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = (Int)iShiftLuma;
159    raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = (Int)iShiftChroma;
160  }
161
162  radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 256 ] = radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 255 ];
163  radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 256 ] = radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 255 ];
164  raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 256 ] = raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 255 ];
165  raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 256 ] = raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 255 ];
166}
167
168Void
169CamParsCollector::uninit()
170{
171  m_bInitialized = false;
172}
173
174Void
175CamParsCollector::setSlice( TComSlice* pcSlice )
176{
177
178  if( pcSlice == 0 )
179  {
180    AOF( xIsComplete() );
181    if( m_bCamParsVaryOverTime || m_iLastPOC == 0 )
182    {
183      xOutput( m_iLastPOC );
184    }
185    return;
186  }
187 
188  if ( pcSlice->getIsDepth())
189  {
190    return;
191  }
192
193  Bool  bFirstAU          = ( pcSlice->getPOC()     == 0 );
194  Bool  bFirstSliceInAU   = ( pcSlice->getPOC()     != Int ( m_iLastPOC ) );
195  Bool  bFirstSliceInView = ( pcSlice->getViewIndex()  != UInt( m_iLastViewIndex ) || bFirstSliceInAU );
196
197  AOT(  bFirstSliceInAU  &&   pcSlice->getViewIndex()  != 0 );
198  AOT( !bFirstSliceInAU  &&   pcSlice->getViewIndex()   < UInt( m_iLastViewIndex ) );
199 
200  AOT( !bFirstSliceInAU  &&   pcSlice->getViewIndex()   > UInt( m_iLastViewIndex + 1 ) );
201 
202  AOT( !bFirstAU         &&   pcSlice->getViewIndex()   > m_uiMaxViewIndex );
203
204  if ( !bFirstSliceInView )
205  {
206    if( m_bCamParsVaryOverTime ) // check consistency of slice parameters here
207    {
208      UInt uiViewIndex = pcSlice->getViewIndex();
209      for( UInt uiBaseViewIndex = 0; uiBaseViewIndex < uiViewIndex; uiBaseViewIndex++ )
210      {
211        AOF( m_aaiCodedScale [ uiBaseViewIndex ][ uiViewIndex ] == pcSlice->getCodedScale    () [ uiBaseViewIndex ] );
212        AOF( m_aaiCodedOffset[ uiBaseViewIndex ][ uiViewIndex ] == pcSlice->getCodedOffset   () [ uiBaseViewIndex ] );
213        AOF( m_aaiCodedScale [ uiViewIndex ][ uiBaseViewIndex ] == pcSlice->getInvCodedScale () [ uiBaseViewIndex ] );
214        AOF( m_aaiCodedOffset[ uiViewIndex ][ uiBaseViewIndex ] == pcSlice->getInvCodedOffset() [ uiBaseViewIndex ] );
215      }
216    }
217    return;
218  }
219
220  if( bFirstSliceInAU )
221  {
222    if( !bFirstAU )
223    {
224      AOF( xIsComplete() );
225      xOutput( m_iLastPOC );
226    }
227    ::memset( m_bViewReceived, false, MAX_NUM_LAYERS * sizeof( Bool ) );
228  }
229
230  UInt uiViewIndex                       = pcSlice->getViewIndex();
231  m_bViewReceived[ uiViewIndex ]         = true;
232  if( bFirstAU )
233  {
234    m_uiMaxViewIndex                     = std::max( m_uiMaxViewIndex, uiViewIndex );
235    m_aiViewId[ uiViewIndex ]            = pcSlice->getViewId();
236    if( uiViewIndex == 1 )
237    {
238      m_uiCamParsCodedPrecision       = pcSlice->getSPS()->getCamParPrecision     ();
239      m_bCamParsVaryOverTime          = pcSlice->getSPS()->hasCamParInSliceHeader ();
240    }
241    else if( uiViewIndex > 1 )
242    {
243      AOF( m_uiCamParsCodedPrecision == pcSlice->getSPS()->getCamParPrecision     () );
244      AOF( m_bCamParsVaryOverTime    == pcSlice->getSPS()->hasCamParInSliceHeader () );
245    }
246    for( UInt uiBaseIndex = 0; uiBaseIndex < uiViewIndex; uiBaseIndex++ )
247    {
248      if( m_bCamParsVaryOverTime )
249      {
250        m_aaiCodedScale [ uiBaseIndex ][ uiViewIndex ]  = pcSlice->getCodedScale    () [ uiBaseIndex ];
251        m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ]  = pcSlice->getCodedOffset   () [ uiBaseIndex ];
252        m_aaiCodedScale [ uiViewIndex ][ uiBaseIndex ]  = pcSlice->getInvCodedScale () [ uiBaseIndex ];
253        m_aaiCodedOffset[ uiViewIndex ][ uiBaseIndex ]  = pcSlice->getInvCodedOffset() [ uiBaseIndex ];
254        xInitLUTs( uiBaseIndex, uiViewIndex, m_aaiCodedScale[ uiBaseIndex ][ uiViewIndex ], m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT);
255        xInitLUTs( uiViewIndex, uiBaseIndex, m_aaiCodedScale[ uiViewIndex ][ uiBaseIndex ], m_aaiCodedOffset[ uiViewIndex ][ uiBaseIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT);
256      }
257      else
258      {
259        m_aaiCodedScale [ uiBaseIndex ][ uiViewIndex ]  = pcSlice->getSPS()->getCodedScale    () [ uiBaseIndex ];
260        m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ]  = pcSlice->getSPS()->getCodedOffset   () [ uiBaseIndex ];
261        m_aaiCodedScale [ uiViewIndex ][ uiBaseIndex ]  = pcSlice->getSPS()->getInvCodedScale () [ uiBaseIndex ];
262        m_aaiCodedOffset[ uiViewIndex ][ uiBaseIndex ]  = pcSlice->getSPS()->getInvCodedOffset() [ uiBaseIndex ];
263        xInitLUTs( uiBaseIndex, uiViewIndex, m_aaiCodedScale[ uiBaseIndex ][ uiViewIndex ], m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
264        xInitLUTs( uiViewIndex, uiBaseIndex, m_aaiCodedScale[ uiViewIndex ][ uiBaseIndex ], m_aaiCodedOffset[ uiViewIndex ][ uiBaseIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
265      }
266    }
267  }
268  else
269  {
270    AOF( m_aiViewId[ uiViewIndex ] == pcSlice->getViewId() );
271    if( m_bCamParsVaryOverTime )
272    {
273      for( UInt uiBaseIndex = 0; uiBaseIndex < uiViewIndex; uiBaseIndex++ )
274      {
275        m_aaiCodedScale [ uiBaseIndex ][ uiViewIndex ]  = pcSlice->getCodedScale    () [ uiBaseIndex ];
276        m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ]  = pcSlice->getCodedOffset   () [ uiBaseIndex ];
277        m_aaiCodedScale [ uiViewIndex ][ uiBaseIndex ]  = pcSlice->getInvCodedScale () [ uiBaseIndex ];
278        m_aaiCodedOffset[ uiViewIndex ][ uiBaseIndex ]  = pcSlice->getInvCodedOffset() [ uiBaseIndex ];
279
280        xInitLUTs( uiBaseIndex, uiViewIndex, m_aaiCodedScale[ uiBaseIndex ][ uiViewIndex ], m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
281        xInitLUTs( uiViewIndex, uiBaseIndex, m_aaiCodedScale[ uiViewIndex ][ uiBaseIndex ], m_aaiCodedOffset[ uiViewIndex ][ uiBaseIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
282      }
283    }
284  }
285 
286  m_iLastViewIndex = (Int)pcSlice->getViewIndex(); 
287  m_iLastPOC       = (Int)pcSlice->getPOC();
288}
289
290Bool
291CamParsCollector::xIsComplete()
292{
293  for( UInt uiView = 0; uiView <= m_uiMaxViewIndex; uiView++ )
294  {
295    if( m_bViewReceived[ uiView ] == 0 )
296    {
297      return false;
298    }
299  }
300  return true;
301}
302
303Void
304CamParsCollector::xOutput( Int iPOC )
305{
306  if( m_pCodedScaleOffsetFile )
307  {
308    if( iPOC == 0 )
309    {
310      fprintf( m_pCodedScaleOffsetFile, "#  ViewIndex       ViewId\n" );
311      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------\n" );
312      for( UInt uiViewIndex = 0; uiViewIndex <= m_uiMaxViewIndex; uiViewIndex++ )
313      {
314        fprintf( m_pCodedScaleOffsetFile, "%12d %12d\n", uiViewIndex, m_aiViewId[ uiViewIndex ] );
315      }
316      fprintf( m_pCodedScaleOffsetFile, "\n\n");
317      fprintf( m_pCodedScaleOffsetFile, "# StartFrame     EndFrame   TargetView     BaseView   CodedScale  CodedOffset    Precision\n" );
318      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------ ------------ ------------ ------------ ------------ ------------\n" );
319    }
320    if( iPOC == 0 || m_bCamParsVaryOverTime )
321    {
322      Int iS = iPOC;
323      Int iE = ( m_bCamParsVaryOverTime ? iPOC : ~( 1 << 31 ) );
324      for( UInt uiViewIndex = 0; uiViewIndex <= m_uiMaxViewIndex; uiViewIndex++ )
325      {
326        for( UInt uiBaseIndex = 0; uiBaseIndex <= m_uiMaxViewIndex; uiBaseIndex++ )
327        {
328          if( uiViewIndex != uiBaseIndex )
329          {
330            fprintf( m_pCodedScaleOffsetFile, "%12d %12d %12d %12d %12d %12d %12d\n",
331              iS, iE, uiViewIndex, uiBaseIndex, m_aaiCodedScale[ uiBaseIndex ][ uiViewIndex ], m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ], m_uiCamParsCodedPrecision );
332          }
333        }
334      }
335    }
336  }
337}
338#endif
339TDecTop::TDecTop()
340{
341  m_pcPic = 0;
342  m_iMaxRefPicNum = 0;
343#if ENC_DEC_TRACE
344#if H_MV
345  if ( g_hTrace == NULL )
346  {
347#endif
348  g_hTrace = fopen( "TraceDec.txt", "wb" );
349  g_bJustDoIt = g_bEncDecTraceDisable;
350  g_nSymbolCounter = 0;
351#if H_MV
352  }
353#endif
354#endif
355  m_pocCRA = 0;
356  m_prevRAPisBLA = false;
357  m_pocRandomAccess = MAX_INT; 
358  m_prevPOC                = MAX_INT;
359  m_bFirstSliceInPicture    = true;
360  m_bFirstSliceInSequence   = true;
361#if H_MV
362  m_layerId = 0;
363  m_viewId = 0;
364#if H_3D
365  m_viewIndex = 0; 
366  m_isDepth = false;
367  m_pcCamParsCollector = 0;
368#endif
369#endif
370}
371
372TDecTop::~TDecTop()
373{
374#if ENC_DEC_TRACE
375  fclose( g_hTrace );
376#endif
377}
378
379Void TDecTop::create()
380{
381  m_cGopDecoder.create();
382  m_apcSlicePilot = new TComSlice;
383  m_uiSliceIdx = 0;
384}
385
386Void TDecTop::destroy()
387{
388  m_cGopDecoder.destroy();
389 
390  delete m_apcSlicePilot;
391  m_apcSlicePilot = NULL;
392 
393  m_cSliceDecoder.destroy();
394}
395
396Void TDecTop::init()
397{
398  // initialize ROM
399#if !H_MV
400  initROM();
401#endif
402  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
403  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
404  m_cEntropyDecoder.init(&m_cPrediction);
405}
406
407Void TDecTop::deletePicBuffer ( )
408{
409  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
410  Int iSize = Int( m_cListPic.size() );
411 
412  for (Int i = 0; i < iSize; i++ )
413  {
414    TComPic* pcPic = *(iterPic++);
415#if H_MV
416    if( pcPic )
417    {
418#endif
419    pcPic->destroy();
420   
421    delete pcPic;
422    pcPic = NULL;
423#if H_MV
424    }
425#endif
426  }
427 
428  m_cSAO.destroy();
429 
430  m_cLoopFilter.        destroy();
431 
432#if !H_MV
433  // destroy ROM
434  destroyROM();
435#endif
436}
437
438Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
439{
440  Int  numReorderPics[MAX_TLAYER];
441  Window &conformanceWindow = pcSlice->getSPS()->getConformanceWindow();
442  Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window();
443
444  for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
445  {
446    numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer);
447  }
448
449#if L0323_DPB
450  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer())+pcSlice->getSPS()->getNumReorderPics(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
451#else
452  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer())+pcSlice->getSPS()->getNumReorderPics(pcSlice->getTLayer()) + 1; // +1 to have space for the picture currently being decoded
453#endif
454  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
455  {
456    rpcPic = new TComPic();
457   
458    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
459                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
460    rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
461    m_cListPic.pushBack( rpcPic );
462   
463    return;
464  }
465 
466  Bool bBufferIsAvailable = false;
467  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
468  while (iterPic != m_cListPic.end())
469  {
470    rpcPic = *(iterPic++);
471    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
472    {
473      rpcPic->setOutputMark(false);
474      bBufferIsAvailable = true;
475      break;
476    }
477
478    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
479    {
480      rpcPic->setOutputMark(false);
481      rpcPic->setReconMark( false );
482      rpcPic->getPicYuvRec()->setBorderExtension( false );
483      bBufferIsAvailable = true;
484      break;
485    }
486  }
487 
488  if ( !bBufferIsAvailable )
489  {
490    //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer.
491    m_iMaxRefPicNum++;
492    rpcPic = new TComPic();
493    m_cListPic.pushBack( rpcPic );
494  }
495  rpcPic->destroy();
496  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
497                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
498  rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
499}
500
501#if H_MV
502Void TDecTop::endPicDecoding(Int& poc, TComList<TComPic*>*& rpcListPic, std::vector<Int>& targetDecLayerIdSet )
503#else
504Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic)
505#endif
506{
507  if (!m_pcPic)
508  {
509    /* nothing to deblock */
510    return;
511  }
512 
513  TComPic*&   pcPic         = m_pcPic;
514
515  // Execute Deblock + Cleanup
516
517  m_cGopDecoder.filterPicture(pcPic);
518
519  TComSlice::sortPicList( m_cListPic ); // sorting for application output
520  poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
521  rpcListPic          = &m_cListPic; 
522  m_cCuDecoder.destroy();       
523#if H_MV
524  TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer ); 
525  TComSlice::markIvRefPicsAsUnused   ( m_ivPicLists, targetDecLayerIdSet, m_parameterSetManagerDecoder.getActiveVPS(), m_layerId, poc ); 
526#endif
527  m_bFirstSliceInPicture  = true;
528
529  return;
530}
531
532Void TDecTop::xCreateLostPicture(Int iLostPoc) 
533{
534  printf("\ninserting lost poc : %d\n",iLostPoc);
535  TComSlice cFillSlice;
536  cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
537  cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
538  cFillSlice.initSlice();
539  TComPic *cFillPic;
540  xGetNewPicBuffer(&cFillSlice,cFillPic);
541  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
542  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
543  cFillPic->getSlice(0)->initSlice();
544 
545  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
546  Int closestPoc = 1000000;
547  while ( iterPic != m_cListPic.end())
548  {
549    TComPic * rpcPic = *(iterPic++);
550    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())
551    {
552      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
553    }
554  }
555  iterPic = m_cListPic.begin();
556  while ( iterPic != m_cListPic.end())
557  {
558    TComPic *rpcPic = *(iterPic++);
559    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
560    {
561      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
562      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
563      break;
564    }
565  }
566  cFillPic->setCurrSliceIdx(0);
567  for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) 
568  {
569    cFillPic->getCU(i)->initCU(cFillPic,i);
570  }
571  cFillPic->getSlice(0)->setReferenced(true);
572  cFillPic->getSlice(0)->setPOC(iLostPoc);
573  cFillPic->setReconMark(true);
574  cFillPic->setOutputMark(true);
575  if(m_pocRandomAccess == MAX_INT)
576  {
577    m_pocRandomAccess = iLostPoc;
578  }
579}
580
581
582Void TDecTop::xActivateParameterSets()
583{
584  m_parameterSetManagerDecoder.applyPrefetchedPS();
585 
586  TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
587  assert (pps != 0);
588
589  TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId());
590  assert (sps != 0);
591
592  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
593  {
594    printf ("Parameter set activation failed!");
595    assert (0);
596  }
597
598  if( pps->getDependentSliceSegmentsEnabledFlag() )
599  {
600    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
601
602    if (m_cSliceDecoder.getCtxMemSize() != NumCtx)
603    {
604      m_cSliceDecoder.initCtxMem(NumCtx);
605      for ( UInt st = 0; st < NumCtx; st++ )
606      {
607        TDecSbac* ctx = NULL;
608        ctx = new TDecSbac;
609        ctx->init( &m_cBinCABAC );
610        m_cSliceDecoder.setCtxMem( ctx, st );
611      }
612    }
613  }
614
615  m_apcSlicePilot->setPPS(pps);
616  m_apcSlicePilot->setSPS(sps);
617#if H_MV
618  m_apcSlicePilot->setVPS( m_parameterSetManagerDecoder.getActiveVPS() );
619#endif
620  pps->setSPS(sps);
621  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
622  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
623
624  g_bitDepthY     = sps->getBitDepthY();
625  g_bitDepthC     = sps->getBitDepthC();
626  g_uiMaxCUWidth  = sps->getMaxCUWidth();
627  g_uiMaxCUHeight = sps->getMaxCUHeight();
628  g_uiMaxCUDepth  = sps->getMaxCUDepth();
629  g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() );
630
631  for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++)
632  {
633    sps->setAMPAcc( i, sps->getUseAMP() );
634  }
635
636  for (Int i = sps->getLog2DiffMaxMinCodingBlockSize(); i < sps->getMaxCUDepth(); i++)
637  {
638    sps->setAMPAcc( i, 0 );
639  }
640
641  m_cSAO.destroy();
642  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() );
643  m_cLoopFilter.create( sps->getMaxCUDepth() );
644}
645
646#if H_MV
647Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool newLayerFlag )
648{
649  assert( nalu.m_layerId == m_layerId ); 
650
651#else
652Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
653{
654#endif
655  TComPic*&   pcPic         = m_pcPic;
656  m_apcSlicePilot->initSlice();
657
658  if (m_bFirstSliceInPicture)
659  {
660    m_uiSliceIdx     = 0;
661  }
662  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
663  if (!m_bFirstSliceInPicture)
664  {
665    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
666  }
667
668  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
669  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
670                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
671                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
672                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
673                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
674  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
675 
676  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
677  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
678
679#if H_MV
680  m_apcSlicePilot->setLayerId( nalu.m_layerId );
681#endif
682  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
683
684#if H_MV 
685  TComVPS* vps     = m_apcSlicePilot->getVPS();
686  Int layerIdInVps = vps->getLayerIdInVps( nalu.m_layerId ); 
687  setViewId   ( vps->getViewId   ( layerIdInVps )      ); 
688#if H_3D
689  setViewIndex( vps->getViewIndex( layerIdInVps )      ); 
690  setIsDepth  ( vps->getDepthId  ( layerIdInVps ) == 1 ); 
691  m_ivPicLists->setVPS( vps ); 
692#endif
693#endif
694    // Skip pictures due to random access
695    if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
696    {
697      return false;
698    }
699    // Skip TFD pictures associated with BLA/BLANT pictures
700    if (isSkipPictureForBLA(iPOCLastDisplay))
701    {
702      return false;
703    }
704
705  //we should only get a different poc for a new picture (with CTU address==0)
706  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (!m_apcSlicePilot->getSliceCurStartCUAddr()==0))
707  {
708    printf ("Warning, the first slice of a picture might have been lost!\n");
709  }
710  // exit when a new picture is found
711  if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence )
712  {
713    if (m_prevPOC >= m_pocRandomAccess)
714    {
715      m_prevPOC = m_apcSlicePilot->getPOC();
716      return true;
717    }
718    m_prevPOC = m_apcSlicePilot->getPOC();
719  }
720#if H_MV
721  if ( newLayerFlag )
722  {
723    return false; 
724  }
725#endif
726  // actual decoding starts here
727  xActivateParameterSets();
728
729  if (m_apcSlicePilot->isNextSlice()) 
730  {
731    m_prevPOC = m_apcSlicePilot->getPOC();
732  }
733  m_bFirstSliceInSequence = false;
734  //detect lost reference picture and insert copy of earlier frame.
735  Int lostPoc;
736  while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
737  {
738    xCreateLostPicture(lostPoc-1);
739  }
740  if (m_bFirstSliceInPicture)
741  {
742    // Buffer initialize for prediction.
743    m_cPrediction.initTempBuff();
744    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
745#if H_MV
746    m_apcSlicePilot->createAndApplyIvReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer ); 
747#endif
748    //  Get a new picture buffer
749    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
750
751    // transfer any SEI messages that have been received to the picture
752    pcPic->setSEIs(m_SEIs);
753    m_SEIs.clear();
754
755    // Recursive structure
756    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
757    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
758    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
759
760    m_cSliceDecoder.create();
761  }
762  else
763  {
764    // Check if any new SEI has arrived
765    if(!m_SEIs.empty())
766    {
767      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
768      SEIMessages &picSEI = pcPic->getSEIs();
769      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
770      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
771      deleteSEIs(m_SEIs);
772    }
773  }
774 
775  //  Set picture slice pointer
776  TComSlice*  pcSlice = m_apcSlicePilot;
777  Bool bNextSlice     = pcSlice->isNextSlice();
778
779  UInt uiCummulativeTileWidth;
780  UInt uiCummulativeTileHeight;
781  UInt i, j, p;
782
783  //set NumColumnsMins1 and NumRowsMinus1
784  pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
785  pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
786
787  //create the TComTileArray
788  pcPic->getPicSym()->xCreateTComTileArray();
789
790  if( pcSlice->getPPS()->getUniformSpacingFlag() )
791  {
792    //set the width for each tile
793    for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
794    {
795      for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
796      {
797        pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
798          setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
799          - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
800      }
801    }
802
803    //set the height for each tile
804    for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
805    {
806      for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
807      {
808        pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
809          setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
810          - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
811      }
812    }
813  }
814  else
815  {
816    //set the width for each tile
817    for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
818    {
819      uiCummulativeTileWidth = 0;
820      for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
821      {
822        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
823        uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
824      }
825      pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
826    }
827
828    //set the height for each tile
829    for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
830    {
831      uiCummulativeTileHeight = 0;
832      for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
833      { 
834        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
835        uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
836      }
837      pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
838    }
839  }
840
841  pcPic->getPicSym()->xInitTiles();
842
843  //generate the Coding Order Map and Inverse Coding Order Map
844  UInt uiEncCUAddr;
845  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
846  {
847    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
848    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
849  }
850  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
851  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
852
853  //convert the start and end CU addresses of the slice and dependent slice into encoding order
854  pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) );
855  pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) );
856  if(pcSlice->isNextSlice())
857  {
858    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
859    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
860  }
861
862  if (m_bFirstSliceInPicture) 
863  {
864    if(pcPic->getNumAllocatedSlice() != 1)
865    {
866      pcPic->clearSliceBuffer();
867    }
868  }
869  else
870  {
871    pcPic->allocateNewSlice();
872  }
873  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
874  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
875  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
876
877  pcPic->setTLayer(nalu.m_temporalId);
878
879#if H_MV
880  pcPic->setLayerId( nalu.m_layerId );
881  pcPic->setViewId ( getViewId() );
882#if H_3D
883  pcPic->setViewIndex( getViewIndex() );
884  pcPic->setIsDepth  ( getIsDepth  () );
885#endif
886#endif
887  if (bNextSlice)
888  {
889    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA, m_cListPic );
890    // Set reference list
891#if H_MV   
892    pcSlice->setRefPicList( m_cListPic, m_refPicSetInterLayer, true );   
893#if H_3D_ARP
894    pcSlice->setARPStepNum();
895    if( pcSlice->getARPStepNum() > 1 )
896    {
897      for(Int iLayerId = 0; iLayerId < nalu.m_layerId; iLayerId ++ )
898      {
899        Int  iViewIdx =   pcSlice->getVPS()->getViewIndex(iLayerId);
900        Bool bIsDepth = ( pcSlice->getVPS()->getDepthId  ( iLayerId ) == 1 );
901        if( iViewIdx<getViewIndex() && !bIsDepth )
902        {
903          //GT (IVREFS): m_tAppDecTop is not needed any more. Reference pictures can be obtained from m_ivPicLists. Should be fixed later.
904          pcSlice->setBaseViewRefPicList( m_tAppDecTop->getTDecTop(iLayerId)->getListPic(), iViewIdx );
905        }
906      }
907    }
908#endif
909#else
910#if FIX1071
911    pcSlice->setRefPicList( m_cListPic, true );
912#else
913    pcSlice->setRefPicList( m_cListPic );
914#endif
915
916#endif
917    // For generalized B
918    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
919    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
920    {
921      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
922      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
923
924      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
925      {
926        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
927      }
928    }
929    if (!pcSlice->isIntra())
930    {
931      Bool bLowDelay = true;
932      Int  iCurrPOC  = pcSlice->getPOC();
933      Int iRefIdx = 0;
934
935      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
936      {
937        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
938        {
939          bLowDelay = false;
940        }
941      }
942      if (pcSlice->isInterB())
943      {
944        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
945        {
946          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
947          {
948            bLowDelay = false;
949          }
950        }       
951      }
952
953      pcSlice->setCheckLDC(bLowDelay);           
954    }
955
956    //---------------
957    pcSlice->setRefPOCList();
958#if !L0034_COMBINED_LIST_CLEANUP
959    pcSlice->setNoBackPredFlag( false );
960    if ( pcSlice->getSliceType() == B_SLICE )
961    {
962      if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) )
963      {
964        pcSlice->setNoBackPredFlag( true );
965        for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ )
966        {
967          if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) 
968          {
969            pcSlice->setNoBackPredFlag( false );
970            break;
971          }
972        }
973      }
974    }
975#endif
976  }
977
978  pcPic->setCurrSliceIdx(m_uiSliceIdx);
979  if(pcSlice->getSPS()->getScalingListFlag())
980  {
981    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
982    if(pcSlice->getPPS()->getScalingListPresentFlag())
983    {
984      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
985    }
986    pcSlice->getScalingList()->setUseTransformSkip(pcSlice->getPPS()->getUseTransformSkip());
987    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
988    {
989      pcSlice->setDefaultScalingList();
990    }
991    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
992    m_cTrQuant.setUseScalingList(true);
993  }
994  else
995  {
996    m_cTrQuant.setFlatScalingList();
997    m_cTrQuant.setUseScalingList(false);
998  }
999
1000  //  Decode a picture
1001  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
1002#if H_3D
1003  if( m_pcCamParsCollector )
1004  {
1005    m_pcCamParsCollector->setSlice( pcSlice );
1006  }
1007#endif
1008  m_bFirstSliceInPicture = false;
1009  m_uiSliceIdx++;
1010
1011  return false;
1012}
1013
1014Void TDecTop::xDecodeVPS()
1015{
1016  TComVPS* vps = new TComVPS();
1017 
1018  m_cEntropyDecoder.decodeVPS( vps );
1019  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
1020}
1021
1022Void TDecTop::xDecodeSPS()
1023{
1024  TComSPS* sps = new TComSPS();
1025#if H_3D
1026  // Preliminary fix. assuming that all sps refer to the same SPS.
1027  // Parsing dependency should be resolved!
1028  TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 ); 
1029  assert( vps != 0 ); 
1030  Int layerIdInVPS = vps->getLayerIdInVps( m_layerId ); 
1031  m_cEntropyDecoder.decodeSPS( sps, vps->getViewIndex( layerIdInVPS ), ( vps->getDepthId( layerIdInVPS ) == 1 ) );
1032#else
1033  m_cEntropyDecoder.decodeSPS( sps );
1034#endif
1035  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
1036}
1037
1038Void TDecTop::xDecodePPS()
1039{
1040  TComPPS* pps = new TComPPS();
1041  m_cEntropyDecoder.decodePPS( pps );
1042  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
1043}
1044
1045Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
1046{
1047  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
1048  {
1049    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1050  }
1051  else
1052  {
1053    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1054    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
1055    if (activeParamSets.size()>0)
1056    {
1057      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
1058      m_parameterSetManagerDecoder.applyPrefetchedPS();
1059      assert(seiAps->activeSeqParamSetId.size()>0);
1060      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
1061      {
1062        printf ("Warning SPS activation with Active parameter set SEI failed");
1063      }
1064    }
1065  }
1066}
1067
1068#if H_MV
1069Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayerFlag)
1070#else
1071Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1072#endif
1073{
1074  // Initialize entropy decoder
1075  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1076  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
1077
1078  switch (nalu.m_nalUnitType)
1079  {
1080    case NAL_UNIT_VPS:
1081      xDecodeVPS();
1082      return false;
1083     
1084    case NAL_UNIT_SPS:
1085      xDecodeSPS();
1086      return false;
1087
1088    case NAL_UNIT_PPS:
1089      xDecodePPS();
1090      return false;
1091     
1092    case NAL_UNIT_PREFIX_SEI:
1093    case NAL_UNIT_SUFFIX_SEI:
1094      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
1095      return false;
1096
1097    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1098    case NAL_UNIT_CODED_SLICE_TRAIL_N:
1099    case NAL_UNIT_CODED_SLICE_TLA_R:
1100    case NAL_UNIT_CODED_SLICE_TSA_N:
1101    case NAL_UNIT_CODED_SLICE_STSA_R:
1102    case NAL_UNIT_CODED_SLICE_STSA_N:
1103    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
1104    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
1105    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1106    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
1107    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
1108    case NAL_UNIT_CODED_SLICE_CRA:
1109    case NAL_UNIT_CODED_SLICE_RADL_N:
1110    case NAL_UNIT_CODED_SLICE_RADL_R:
1111    case NAL_UNIT_CODED_SLICE_RASL_N:
1112    case NAL_UNIT_CODED_SLICE_RASL_R:
1113#if H_MV
1114      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, newLayerFlag);
1115#else
1116      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1117#endif
1118      break;
1119    default:
1120      assert (1);
1121  }
1122
1123  return false;
1124}
1125
1126/** Function for checking if picture should be skipped because of association with a previous BLA picture
1127 * \param iPOCLastDisplay POC of last picture displayed
1128 * \returns true if the picture should be skipped
1129 * This function skips all TFD pictures that follow a BLA picture
1130 * in decoding order and precede it in output order.
1131 */
1132Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
1133{
1134  if (m_prevRAPisBLA && m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
1135  {
1136    iPOCLastDisplay++;
1137    return true;
1138  }
1139  return false;
1140}
1141
1142/** Function for checking if picture should be skipped because of random access
1143 * \param iSkipFrame skip frame counter
1144 * \param iPOCLastDisplay POC of last picture displayed
1145 * \returns true if the picture shold be skipped in the random access.
1146 * This function checks the skipping of pictures in the case of -s option random access.
1147 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1148 * It also checks the type of Nal unit type at the random access point.
1149 * If the random access point is CRA/CRANT/BLA/BLANT, TFD pictures with POC less than the POC of the random access point are skipped.
1150 * If the random access point is IDR all pictures after the random access point are decoded.
1151 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
1152 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
1153 * access point there is no guarantee that the decoder will not crash.
1154 */
1155Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
1156{
1157  if (iSkipFrame) 
1158  {
1159    iSkipFrame--;   // decrement the counter
1160    return true;
1161  }
1162  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1163  {
1164    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
1165        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1166        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1167        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
1168    {
1169      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
1170      m_pocRandomAccess = m_apcSlicePilot->getPOC();
1171    }
1172    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
1173    {
1174      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1175    }
1176    else 
1177    {
1178      static Bool warningMessage = false;
1179      if(!warningMessage)
1180      {
1181        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1182        warningMessage = true;
1183      }
1184      return true;
1185    }
1186  }
1187  // skip the reordered pictures, if necessary
1188  else if (m_apcSlicePilot->getPOC() < m_pocRandomAccess && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
1189  {
1190    iPOCLastDisplay++;
1191    return true;
1192  }
1193  // if we reach here, then the picture is not skipped.
1194  return false; 
1195}
1196
1197#if H_MV
1198TComPic* TDecTop::getPic( Int poc )
1199{
1200  xGetPic( m_layerId, poc ); 
1201  TComList<TComPic*>* listPic = getListPic();
1202  TComPic* pcPic = NULL;
1203  for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++)
1204  {
1205    if( (*it)->getPOC() == poc )
1206    {
1207      pcPic = *it ;
1208      break ;
1209    }
1210  }
1211  return pcPic;
1212}
1213
1214TComPic* TDecTop::xGetPic( Int layerId, Int poc )
1215{ 
1216  return m_ivPicLists->getPic( layerId, poc ) ;
1217}
1218
1219#endif
1220//! \}
Note: See TracBrowser for help on using the repository browser.