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

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

Further fixes.

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