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

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

Implementation of ARP from QC

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