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

Last change on this file since 499 was 499, checked in by zhang, 11 years ago

Changes include: DV-MVP(H_3D_IDV), TMVP merging candidate(H_3D_TMVP, target reference index changes, scaling based on view order index) and cleanups (H_3D_CLEANUPS)

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