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

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

Merged HTM-DEV-0.3-dev1 Rev. 520.

  • 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#if H_3D
920    pcSlice->setPicLists( m_ivPicLists );
921#endif
922
923#if H_3D_GEN
924    pcSlice->setIvPicLists( m_ivPicLists );         
925#if H_3D_IV_MERGE   
926    assert( !getIsDepth() || ( pcSlice->getTexturePic() != 0 ) );
927#endif   
928#endif
929    // For generalized B
930    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
931    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
932    {
933      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
934      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
935
936      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
937      {
938        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
939      }
940    }
941    if (!pcSlice->isIntra())
942    {
943      Bool bLowDelay = true;
944      Int  iCurrPOC  = pcSlice->getPOC();
945      Int iRefIdx = 0;
946
947      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
948      {
949        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
950        {
951          bLowDelay = false;
952        }
953      }
954      if (pcSlice->isInterB())
955      {
956        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
957        {
958          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
959          {
960            bLowDelay = false;
961          }
962        }       
963      }
964
965      pcSlice->setCheckLDC(bLowDelay);           
966    }
967
968    //---------------
969    pcSlice->setRefPOCList();
970#if !L0034_COMBINED_LIST_CLEANUP
971    pcSlice->setNoBackPredFlag( false );
972    if ( pcSlice->getSliceType() == B_SLICE )
973    {
974      if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) )
975      {
976        pcSlice->setNoBackPredFlag( true );
977        for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ )
978        {
979          if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) 
980          {
981            pcSlice->setNoBackPredFlag( false );
982            break;
983          }
984        }
985      }
986    }
987#endif
988#if  H_3D_TMVP
989    if(pcSlice->getLayerId())
990      pcSlice->generateAlterRefforTMVP();
991#endif
992  }
993
994  pcPic->setCurrSliceIdx(m_uiSliceIdx);
995  if(pcSlice->getSPS()->getScalingListFlag())
996  {
997    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
998    if(pcSlice->getPPS()->getScalingListPresentFlag())
999    {
1000      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
1001    }
1002    pcSlice->getScalingList()->setUseTransformSkip(pcSlice->getPPS()->getUseTransformSkip());
1003    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
1004    {
1005      pcSlice->setDefaultScalingList();
1006    }
1007    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
1008    m_cTrQuant.setUseScalingList(true);
1009  }
1010  else
1011  {
1012    m_cTrQuant.setFlatScalingList();
1013    m_cTrQuant.setUseScalingList(false);
1014  }
1015
1016  //  Decode a picture
1017  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
1018#if H_3D
1019  if( m_pcCamParsCollector )
1020  {
1021    m_pcCamParsCollector->setSlice( pcSlice );
1022  }
1023#endif
1024  m_bFirstSliceInPicture = false;
1025  m_uiSliceIdx++;
1026
1027  return false;
1028}
1029
1030Void TDecTop::xDecodeVPS()
1031{
1032  TComVPS* vps = new TComVPS();
1033 
1034  m_cEntropyDecoder.decodeVPS( vps );
1035  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
1036}
1037
1038Void TDecTop::xDecodeSPS()
1039{
1040  TComSPS* sps = new TComSPS();
1041#if H_3D
1042  // Preliminary fix. assuming that all sps refer to the same SPS.
1043  // Parsing dependency should be resolved!
1044  TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 ); 
1045  assert( vps != 0 ); 
1046  Int layerIdInVPS = vps->getLayerIdInVps( m_layerId ); 
1047  m_cEntropyDecoder.decodeSPS( sps, vps->getViewIndex( layerIdInVPS ), ( vps->getDepthId( layerIdInVPS ) == 1 ) );
1048#else
1049  m_cEntropyDecoder.decodeSPS( sps );
1050#endif
1051  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
1052}
1053
1054Void TDecTop::xDecodePPS()
1055{
1056  TComPPS* pps = new TComPPS();
1057  m_cEntropyDecoder.decodePPS( pps );
1058  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
1059}
1060
1061Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
1062{
1063  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
1064  {
1065    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1066  }
1067  else
1068  {
1069    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1070    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
1071    if (activeParamSets.size()>0)
1072    {
1073      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
1074      m_parameterSetManagerDecoder.applyPrefetchedPS();
1075      assert(seiAps->activeSeqParamSetId.size()>0);
1076      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
1077      {
1078        printf ("Warning SPS activation with Active parameter set SEI failed");
1079      }
1080    }
1081  }
1082}
1083
1084#if H_MV
1085Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayerFlag)
1086#else
1087Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1088#endif
1089{
1090  // Initialize entropy decoder
1091  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1092  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
1093
1094  switch (nalu.m_nalUnitType)
1095  {
1096    case NAL_UNIT_VPS:
1097      xDecodeVPS();
1098      return false;
1099     
1100    case NAL_UNIT_SPS:
1101      xDecodeSPS();
1102      return false;
1103
1104    case NAL_UNIT_PPS:
1105      xDecodePPS();
1106      return false;
1107     
1108    case NAL_UNIT_PREFIX_SEI:
1109    case NAL_UNIT_SUFFIX_SEI:
1110      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
1111      return false;
1112
1113    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1114    case NAL_UNIT_CODED_SLICE_TRAIL_N:
1115    case NAL_UNIT_CODED_SLICE_TLA_R:
1116    case NAL_UNIT_CODED_SLICE_TSA_N:
1117    case NAL_UNIT_CODED_SLICE_STSA_R:
1118    case NAL_UNIT_CODED_SLICE_STSA_N:
1119    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
1120    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
1121    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1122    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
1123    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
1124    case NAL_UNIT_CODED_SLICE_CRA:
1125    case NAL_UNIT_CODED_SLICE_RADL_N:
1126    case NAL_UNIT_CODED_SLICE_RADL_R:
1127    case NAL_UNIT_CODED_SLICE_RASL_N:
1128    case NAL_UNIT_CODED_SLICE_RASL_R:
1129#if H_MV
1130      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, newLayerFlag);
1131#else
1132      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1133#endif
1134      break;
1135    default:
1136      assert (1);
1137  }
1138
1139  return false;
1140}
1141
1142/** Function for checking if picture should be skipped because of association with a previous BLA picture
1143 * \param iPOCLastDisplay POC of last picture displayed
1144 * \returns true if the picture should be skipped
1145 * This function skips all TFD pictures that follow a BLA picture
1146 * in decoding order and precede it in output order.
1147 */
1148Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
1149{
1150  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))
1151  {
1152    iPOCLastDisplay++;
1153    return true;
1154  }
1155  return false;
1156}
1157
1158/** Function for checking if picture should be skipped because of random access
1159 * \param iSkipFrame skip frame counter
1160 * \param iPOCLastDisplay POC of last picture displayed
1161 * \returns true if the picture shold be skipped in the random access.
1162 * This function checks the skipping of pictures in the case of -s option random access.
1163 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1164 * It also checks the type of Nal unit type at the random access point.
1165 * 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.
1166 * If the random access point is IDR all pictures after the random access point are decoded.
1167 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
1168 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
1169 * access point there is no guarantee that the decoder will not crash.
1170 */
1171Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
1172{
1173  if (iSkipFrame) 
1174  {
1175    iSkipFrame--;   // decrement the counter
1176    return true;
1177  }
1178  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1179  {
1180    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
1181        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1182        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1183        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
1184    {
1185      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
1186      m_pocRandomAccess = m_apcSlicePilot->getPOC();
1187    }
1188    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
1189    {
1190      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1191    }
1192    else 
1193    {
1194      static Bool warningMessage = false;
1195      if(!warningMessage)
1196      {
1197        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1198        warningMessage = true;
1199      }
1200      return true;
1201    }
1202  }
1203  // skip the reordered pictures, if necessary
1204  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))
1205  {
1206    iPOCLastDisplay++;
1207    return true;
1208  }
1209  // if we reach here, then the picture is not skipped.
1210  return false; 
1211}
1212
1213#if H_MV
1214TComPic* TDecTop::getPic( Int poc )
1215{
1216  xGetPic( m_layerId, poc ); 
1217  TComList<TComPic*>* listPic = getListPic();
1218  TComPic* pcPic = NULL;
1219  for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++)
1220  {
1221    if( (*it)->getPOC() == poc )
1222    {
1223      pcPic = *it ;
1224      break ;
1225    }
1226  }
1227  return pcPic;
1228}
1229
1230TComPic* TDecTop::xGetPic( Int layerId, Int poc )
1231{ 
1232  return m_ivPicLists->getPic( layerId, poc ) ;
1233}
1234
1235#endif
1236//! \}
Note: See TracBrowser for help on using the repository browser.