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

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