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

Last change on this file since 491 was 491, checked in by tech, 11 years ago
  • Started integrating changes in decoding process
  • Fixed encoder help output
  • Property svn:eol-style set to native
File size: 41.8 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::markCurrPic( pcPic ); 
521  TComSlice::markIvRefPicsAsUnused   ( m_ivPicLists, targetDecLayerIdSet, m_parameterSetManagerDecoder.getActiveVPS(), m_layerId, poc ); 
522#endif
523  m_bFirstSliceInPicture  = true;
524
525  return;
526}
527
528Void TDecTop::xCreateLostPicture(Int iLostPoc) 
529{
530  printf("\ninserting lost poc : %d\n",iLostPoc);
531  TComSlice cFillSlice;
532  cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
533  cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
534  cFillSlice.initSlice();
535  TComPic *cFillPic;
536  xGetNewPicBuffer(&cFillSlice,cFillPic);
537  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
538  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
539  cFillPic->getSlice(0)->initSlice();
540 
541  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
542  Int closestPoc = 1000000;
543  while ( iterPic != m_cListPic.end())
544  {
545    TComPic * rpcPic = *(iterPic++);
546    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())
547    {
548      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
549    }
550  }
551  iterPic = m_cListPic.begin();
552  while ( iterPic != m_cListPic.end())
553  {
554    TComPic *rpcPic = *(iterPic++);
555    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
556    {
557      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
558      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
559      break;
560    }
561  }
562  cFillPic->setCurrSliceIdx(0);
563  for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) 
564  {
565    cFillPic->getCU(i)->initCU(cFillPic,i);
566  }
567  cFillPic->getSlice(0)->setReferenced(true);
568  cFillPic->getSlice(0)->setPOC(iLostPoc);
569  cFillPic->setReconMark(true);
570  cFillPic->setOutputMark(true);
571  if(m_pocRandomAccess == MAX_INT)
572  {
573    m_pocRandomAccess = iLostPoc;
574  }
575}
576
577
578Void TDecTop::xActivateParameterSets()
579{
580  m_parameterSetManagerDecoder.applyPrefetchedPS();
581 
582  TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
583  assert (pps != 0);
584
585  TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId());
586  assert (sps != 0);
587
588  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
589  {
590    printf ("Parameter set activation failed!");
591    assert (0);
592  }
593
594  if( pps->getDependentSliceSegmentsEnabledFlag() )
595  {
596    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
597
598    if (m_cSliceDecoder.getCtxMemSize() != NumCtx)
599    {
600      m_cSliceDecoder.initCtxMem(NumCtx);
601      for ( UInt st = 0; st < NumCtx; st++ )
602      {
603        TDecSbac* ctx = NULL;
604        ctx = new TDecSbac;
605        ctx->init( &m_cBinCABAC );
606        m_cSliceDecoder.setCtxMem( ctx, st );
607      }
608    }
609  }
610
611  m_apcSlicePilot->setPPS(pps);
612  m_apcSlicePilot->setSPS(sps);
613#if H_MV
614  m_apcSlicePilot->setVPS( m_parameterSetManagerDecoder.getActiveVPS() );
615#endif
616  pps->setSPS(sps);
617  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
618  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
619
620  g_bitDepthY     = sps->getBitDepthY();
621  g_bitDepthC     = sps->getBitDepthC();
622  g_uiMaxCUWidth  = sps->getMaxCUWidth();
623  g_uiMaxCUHeight = sps->getMaxCUHeight();
624  g_uiMaxCUDepth  = sps->getMaxCUDepth();
625  g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() );
626
627  for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++)
628  {
629    sps->setAMPAcc( i, sps->getUseAMP() );
630  }
631
632  for (Int i = sps->getLog2DiffMaxMinCodingBlockSize(); i < sps->getMaxCUDepth(); i++)
633  {
634    sps->setAMPAcc( i, 0 );
635  }
636
637  m_cSAO.destroy();
638  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() );
639  m_cLoopFilter.create( sps->getMaxCUDepth() );
640}
641
642#if H_MV
643Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool newLayerFlag )
644{
645  assert( nalu.m_layerId == m_layerId ); 
646
647#else
648Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
649{
650#endif
651  TComPic*&   pcPic         = m_pcPic;
652  m_apcSlicePilot->initSlice();
653
654  if (m_bFirstSliceInPicture)
655  {
656    m_uiSliceIdx     = 0;
657  }
658  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
659  if (!m_bFirstSliceInPicture)
660  {
661    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
662  }
663
664  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
665  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
666                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
667                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
668                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
669                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
670  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
671 
672  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
673  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
674
675#if H_MV
676  m_apcSlicePilot->setRefPicSetInterLayer( & m_refPicSetInterLayer ); 
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#endif
723  // actual decoding starts here
724  xActivateParameterSets();
725
726  if (m_apcSlicePilot->isNextSlice()) 
727  {
728    m_prevPOC = m_apcSlicePilot->getPOC();
729  }
730  m_bFirstSliceInSequence = false;
731  //detect lost reference picture and insert copy of earlier frame.
732  Int lostPoc;
733  while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
734  {
735    xCreateLostPicture(lostPoc-1);
736  }
737  if (m_bFirstSliceInPicture)
738  {
739    // Buffer initialize for prediction.
740    m_cPrediction.initTempBuff();
741    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
742#if H_MV
743    m_apcSlicePilot->createAndApplyIvReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer ); 
744#endif
745    //  Get a new picture buffer
746    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
747
748    // transfer any SEI messages that have been received to the picture
749    pcPic->setSEIs(m_SEIs);
750    m_SEIs.clear();
751
752    // Recursive structure
753    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
754    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
755    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
756
757    m_cSliceDecoder.create();
758  }
759  else
760  {
761    // Check if any new SEI has arrived
762    if(!m_SEIs.empty())
763    {
764      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
765      SEIMessages &picSEI = pcPic->getSEIs();
766      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
767      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
768      deleteSEIs(m_SEIs);
769    }
770  }
771 
772  //  Set picture slice pointer
773  TComSlice*  pcSlice = m_apcSlicePilot;
774  Bool bNextSlice     = pcSlice->isNextSlice();
775
776  UInt uiCummulativeTileWidth;
777  UInt uiCummulativeTileHeight;
778  UInt i, j, p;
779
780  //set NumColumnsMins1 and NumRowsMinus1
781  pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
782  pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
783
784  //create the TComTileArray
785  pcPic->getPicSym()->xCreateTComTileArray();
786
787  if( pcSlice->getPPS()->getUniformSpacingFlag() )
788  {
789    //set the width for each tile
790    for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
791    {
792      for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
793      {
794        pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
795          setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
796          - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
797      }
798    }
799
800    //set the height for each tile
801    for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
802    {
803      for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
804      {
805        pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
806          setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
807          - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
808      }
809    }
810  }
811  else
812  {
813    //set the width for each tile
814    for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
815    {
816      uiCummulativeTileWidth = 0;
817      for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
818      {
819        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
820        uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
821      }
822      pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
823    }
824
825    //set the height for each tile
826    for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
827    {
828      uiCummulativeTileHeight = 0;
829      for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
830      { 
831        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
832        uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
833      }
834      pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
835    }
836  }
837
838  pcPic->getPicSym()->xInitTiles();
839
840  //generate the Coding Order Map and Inverse Coding Order Map
841  UInt uiEncCUAddr;
842  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
843  {
844    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
845    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
846  }
847  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
848  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
849
850  //convert the start and end CU addresses of the slice and dependent slice into encoding order
851  pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) );
852  pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) );
853  if(pcSlice->isNextSlice())
854  {
855    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
856    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
857  }
858
859  if (m_bFirstSliceInPicture) 
860  {
861    if(pcPic->getNumAllocatedSlice() != 1)
862    {
863      pcPic->clearSliceBuffer();
864    }
865  }
866  else
867  {
868    pcPic->allocateNewSlice();
869  }
870  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
871  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
872  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
873
874  pcPic->setTLayer(nalu.m_temporalId);
875
876#if H_MV
877  pcPic->setLayerId( nalu.m_layerId );
878  pcPic->setViewId ( getViewId() );
879#if H_3D
880  pcPic->setViewIndex( getViewIndex() );
881  pcPic->setIsDepth  ( getIsDepth  () );
882#endif
883#endif
884  if (bNextSlice)
885  {
886    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA, m_cListPic );
887    // Set reference list
888#if H_MV   
889    pcSlice->setRefPicList( m_cListPic, m_refPicSetInterLayer, true );   
890#else
891#if FIX1071
892    pcSlice->setRefPicList( m_cListPic, true );
893#else
894    pcSlice->setRefPicList( m_cListPic );
895#endif
896
897#endif
898    // For generalized B
899    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
900    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
901    {
902      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
903      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
904
905      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
906      {
907        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
908      }
909    }
910    if (!pcSlice->isIntra())
911    {
912      Bool bLowDelay = true;
913      Int  iCurrPOC  = pcSlice->getPOC();
914      Int iRefIdx = 0;
915
916      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
917      {
918        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
919        {
920          bLowDelay = false;
921        }
922      }
923      if (pcSlice->isInterB())
924      {
925        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
926        {
927          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
928          {
929            bLowDelay = false;
930          }
931        }       
932      }
933
934      pcSlice->setCheckLDC(bLowDelay);           
935    }
936
937    //---------------
938    pcSlice->setRefPOCList();
939#if !L0034_COMBINED_LIST_CLEANUP
940    pcSlice->setNoBackPredFlag( false );
941    if ( pcSlice->getSliceType() == B_SLICE )
942    {
943      if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) )
944      {
945        pcSlice->setNoBackPredFlag( true );
946        for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ )
947        {
948          if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) 
949          {
950            pcSlice->setNoBackPredFlag( false );
951            break;
952          }
953        }
954      }
955    }
956#endif
957  }
958
959  pcPic->setCurrSliceIdx(m_uiSliceIdx);
960  if(pcSlice->getSPS()->getScalingListFlag())
961  {
962    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
963    if(pcSlice->getPPS()->getScalingListPresentFlag())
964    {
965      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
966    }
967    pcSlice->getScalingList()->setUseTransformSkip(pcSlice->getPPS()->getUseTransformSkip());
968    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
969    {
970      pcSlice->setDefaultScalingList();
971    }
972    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
973    m_cTrQuant.setUseScalingList(true);
974  }
975  else
976  {
977    m_cTrQuant.setFlatScalingList();
978    m_cTrQuant.setUseScalingList(false);
979  }
980
981  //  Decode a picture
982  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
983#if H_3D
984  if( m_pcCamParsCollector )
985  {
986    m_pcCamParsCollector->setSlice( pcSlice );
987  }
988#endif
989  m_bFirstSliceInPicture = false;
990  m_uiSliceIdx++;
991
992  return false;
993}
994
995Void TDecTop::xDecodeVPS()
996{
997  TComVPS* vps = new TComVPS();
998 
999  m_cEntropyDecoder.decodeVPS( vps );
1000  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
1001}
1002
1003Void TDecTop::xDecodeSPS()
1004{
1005  TComSPS* sps = new TComSPS();
1006#if H_MV
1007  sps->setLayerId( getLayerId() ); 
1008#endif
1009#if H_3D
1010  // Preliminary fix. assuming that all sps refer to the same VPS.
1011  // Parsing dependency should be resolved!
1012  TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 ); 
1013  assert( vps != 0 ); 
1014  Int layerIdInVPS = vps->getLayerIdInVps( m_layerId ); 
1015  m_cEntropyDecoder.decodeSPS( sps, vps->getViewIndex( layerIdInVPS ), ( vps->getDepthId( layerIdInVPS ) == 1 ) );
1016#else
1017  m_cEntropyDecoder.decodeSPS( sps );
1018#endif
1019  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
1020}
1021
1022Void TDecTop::xDecodePPS()
1023{
1024  TComPPS* pps = new TComPPS();
1025  m_cEntropyDecoder.decodePPS( pps );
1026  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
1027}
1028
1029Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
1030{
1031  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
1032  {
1033    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1034  }
1035  else
1036  {
1037    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1038    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
1039    if (activeParamSets.size()>0)
1040    {
1041      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
1042      m_parameterSetManagerDecoder.applyPrefetchedPS();
1043      assert(seiAps->activeSeqParamSetId.size()>0);
1044      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
1045      {
1046        printf ("Warning SPS activation with Active parameter set SEI failed");
1047      }
1048    }
1049  }
1050}
1051
1052#if H_MV
1053Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayerFlag)
1054#else
1055Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1056#endif
1057{
1058  // Initialize entropy decoder
1059  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1060  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
1061
1062  switch (nalu.m_nalUnitType)
1063  {
1064    case NAL_UNIT_VPS:
1065      xDecodeVPS();
1066      return false;
1067     
1068    case NAL_UNIT_SPS:
1069      xDecodeSPS();
1070      return false;
1071
1072    case NAL_UNIT_PPS:
1073      xDecodePPS();
1074      return false;
1075     
1076    case NAL_UNIT_PREFIX_SEI:
1077    case NAL_UNIT_SUFFIX_SEI:
1078      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
1079      return false;
1080
1081    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1082    case NAL_UNIT_CODED_SLICE_TRAIL_N:
1083    case NAL_UNIT_CODED_SLICE_TLA_R:
1084    case NAL_UNIT_CODED_SLICE_TSA_N:
1085    case NAL_UNIT_CODED_SLICE_STSA_R:
1086    case NAL_UNIT_CODED_SLICE_STSA_N:
1087    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
1088    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
1089    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1090    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
1091    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
1092    case NAL_UNIT_CODED_SLICE_CRA:
1093    case NAL_UNIT_CODED_SLICE_RADL_N:
1094    case NAL_UNIT_CODED_SLICE_RADL_R:
1095    case NAL_UNIT_CODED_SLICE_RASL_N:
1096    case NAL_UNIT_CODED_SLICE_RASL_R:
1097#if H_MV
1098      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, newLayerFlag);
1099#else
1100      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1101#endif
1102      break;
1103    default:
1104      assert (1);
1105  }
1106
1107  return false;
1108}
1109
1110/** Function for checking if picture should be skipped because of association with a previous BLA picture
1111 * \param iPOCLastDisplay POC of last picture displayed
1112 * \returns true if the picture should be skipped
1113 * This function skips all TFD pictures that follow a BLA picture
1114 * in decoding order and precede it in output order.
1115 */
1116Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
1117{
1118  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))
1119  {
1120    iPOCLastDisplay++;
1121    return true;
1122  }
1123  return false;
1124}
1125
1126/** Function for checking if picture should be skipped because of random access
1127 * \param iSkipFrame skip frame counter
1128 * \param iPOCLastDisplay POC of last picture displayed
1129 * \returns true if the picture shold be skipped in the random access.
1130 * This function checks the skipping of pictures in the case of -s option random access.
1131 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1132 * It also checks the type of Nal unit type at the random access point.
1133 * 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.
1134 * If the random access point is IDR all pictures after the random access point are decoded.
1135 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
1136 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
1137 * access point there is no guarantee that the decoder will not crash.
1138 */
1139Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
1140{
1141  if (iSkipFrame) 
1142  {
1143    iSkipFrame--;   // decrement the counter
1144    return true;
1145  }
1146  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1147  {
1148    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
1149        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1150        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1151        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
1152    {
1153      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
1154      m_pocRandomAccess = m_apcSlicePilot->getPOC();
1155    }
1156    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
1157    {
1158      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1159    }
1160    else 
1161    {
1162      static Bool warningMessage = false;
1163      if(!warningMessage)
1164      {
1165        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1166        warningMessage = true;
1167      }
1168      return true;
1169    }
1170  }
1171  // skip the reordered pictures, if necessary
1172  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))
1173  {
1174    iPOCLastDisplay++;
1175    return true;
1176  }
1177  // if we reach here, then the picture is not skipped.
1178  return false; 
1179}
1180
1181#if H_MV
1182TComPic* TDecTop::getPic( Int poc )
1183{
1184  xGetPic( m_layerId, poc ); 
1185  TComList<TComPic*>* listPic = getListPic();
1186  TComPic* pcPic = NULL;
1187  for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++)
1188  {
1189    if( (*it)->getPOC() == poc )
1190    {
1191      pcPic = *it ;
1192      break ;
1193    }
1194  }
1195  return pcPic;
1196}
1197
1198TComPic* TDecTop::xGetPic( Int layerId, Int poc )
1199{ 
1200  return m_ivPicLists->getPic( layerId, poc ) ;
1201}
1202
1203#endif
1204//! \}
Note: See TracBrowser for help on using the repository browser.