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

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

Minor clean ups.

  • Property svn:eol-style set to native
File size: 43.3 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_IV_MERGE
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
394#if H_3D_IV_MERGE
395Void TDecTop::init(TAppDecTop* pcTAppDecTop)
396#else
397Void TDecTop::init()
398#endif
399{
400  // initialize ROM
401#if !H_MV
402  initROM();
403#endif
404  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO
405#if H_3D_IV_MERGE
406    , &m_cDepthMapGenerator
407#endif
408    );
409  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
410  m_cEntropyDecoder.init(&m_cPrediction);
411#if H_3D_IV_MERGE
412  m_tAppDecTop = pcTAppDecTop;
413  m_cDepthMapGenerator.init( &m_cPrediction, m_tAppDecTop->getVPSAccess(), m_tAppDecTop->getSPSAccess(), m_tAppDecTop->getAUPicAccess() );
414#endif
415}
416
417Void TDecTop::deletePicBuffer ( )
418{
419  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
420  Int iSize = Int( m_cListPic.size() );
421 
422  for (Int i = 0; i < iSize; i++ )
423  {
424    TComPic* pcPic = *(iterPic++);
425#if H_MV
426    if( pcPic )
427    {
428#endif
429    pcPic->destroy();
430   
431    delete pcPic;
432    pcPic = NULL;
433#if H_MV
434    }
435#endif
436  }
437 
438  m_cSAO.destroy();
439 
440  m_cLoopFilter.        destroy();
441 
442#if !H_MV
443  // destroy ROM
444  destroyROM();
445#endif
446}
447
448Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
449{
450  Int  numReorderPics[MAX_TLAYER];
451  Window &conformanceWindow = pcSlice->getSPS()->getConformanceWindow();
452  Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window();
453
454  for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
455  {
456    numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer);
457  }
458
459#if L0323_DPB
460  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer())+pcSlice->getSPS()->getNumReorderPics(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
461#else
462  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer())+pcSlice->getSPS()->getNumReorderPics(pcSlice->getTLayer()) + 1; // +1 to have space for the picture currently being decoded
463#endif
464  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
465  {
466    rpcPic = new TComPic();
467   
468    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
469                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
470    rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
471    m_cListPic.pushBack( rpcPic );
472   
473    return;
474  }
475 
476  Bool bBufferIsAvailable = false;
477  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
478  while (iterPic != m_cListPic.end())
479  {
480    rpcPic = *(iterPic++);
481    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
482    {
483      rpcPic->setOutputMark(false);
484      bBufferIsAvailable = true;
485      break;
486    }
487
488    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
489    {
490      rpcPic->setOutputMark(false);
491      rpcPic->setReconMark( false );
492      rpcPic->getPicYuvRec()->setBorderExtension( false );
493      bBufferIsAvailable = true;
494      break;
495    }
496  }
497 
498  if ( !bBufferIsAvailable )
499  {
500    //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer.
501    m_iMaxRefPicNum++;
502    rpcPic = new TComPic();
503    m_cListPic.pushBack( rpcPic );
504  }
505  rpcPic->destroy();
506  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
507                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
508  rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
509}
510
511#if H_MV
512Void TDecTop::endPicDecoding(Int& poc, TComList<TComPic*>*& rpcListPic, std::vector<Int>& targetDecLayerIdSet )
513#else
514Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic)
515#endif
516{
517  if (!m_pcPic)
518  {
519    /* nothing to deblock */
520    return;
521  }
522 
523  TComPic*&   pcPic         = m_pcPic;
524
525  // Execute Deblock + Cleanup
526
527  m_cGopDecoder.filterPicture(pcPic);
528
529  TComSlice::sortPicList( m_cListPic ); // sorting for application output
530  poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
531  rpcListPic          = &m_cListPic; 
532  m_cCuDecoder.destroy();       
533#if H_MV
534  TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer ); 
535  TComSlice::markIvRefPicsAsUnused   ( m_ivPicLists, targetDecLayerIdSet, m_parameterSetManagerDecoder.getActiveVPS(), m_layerId, poc ); 
536#endif
537  m_bFirstSliceInPicture  = true;
538
539  return;
540}
541
542Void TDecTop::xCreateLostPicture(Int iLostPoc) 
543{
544  printf("\ninserting lost poc : %d\n",iLostPoc);
545  TComSlice cFillSlice;
546  cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
547  cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
548  cFillSlice.initSlice();
549  TComPic *cFillPic;
550  xGetNewPicBuffer(&cFillSlice,cFillPic);
551  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
552  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
553  cFillPic->getSlice(0)->initSlice();
554 
555  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
556  Int closestPoc = 1000000;
557  while ( iterPic != m_cListPic.end())
558  {
559    TComPic * rpcPic = *(iterPic++);
560    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())
561    {
562      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
563    }
564  }
565  iterPic = m_cListPic.begin();
566  while ( iterPic != m_cListPic.end())
567  {
568    TComPic *rpcPic = *(iterPic++);
569    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
570    {
571      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
572      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
573      break;
574    }
575  }
576  cFillPic->setCurrSliceIdx(0);
577  for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) 
578  {
579    cFillPic->getCU(i)->initCU(cFillPic,i);
580  }
581  cFillPic->getSlice(0)->setReferenced(true);
582  cFillPic->getSlice(0)->setPOC(iLostPoc);
583  cFillPic->setReconMark(true);
584  cFillPic->setOutputMark(true);
585  if(m_pocRandomAccess == MAX_INT)
586  {
587    m_pocRandomAccess = iLostPoc;
588  }
589}
590
591
592Void TDecTop::xActivateParameterSets()
593{
594  m_parameterSetManagerDecoder.applyPrefetchedPS();
595 
596  TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
597  assert (pps != 0);
598
599  TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId());
600  assert (sps != 0);
601
602  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
603  {
604    printf ("Parameter set activation failed!");
605    assert (0);
606  }
607
608  if( pps->getDependentSliceSegmentsEnabledFlag() )
609  {
610    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
611
612    if (m_cSliceDecoder.getCtxMemSize() != NumCtx)
613    {
614      m_cSliceDecoder.initCtxMem(NumCtx);
615      for ( UInt st = 0; st < NumCtx; st++ )
616      {
617        TDecSbac* ctx = NULL;
618        ctx = new TDecSbac;
619        ctx->init( &m_cBinCABAC );
620        m_cSliceDecoder.setCtxMem( ctx, st );
621      }
622    }
623  }
624
625  m_apcSlicePilot->setPPS(pps);
626  m_apcSlicePilot->setSPS(sps);
627#if H_MV
628  m_apcSlicePilot->setVPS( m_parameterSetManagerDecoder.getActiveVPS() );
629#endif
630  pps->setSPS(sps);
631  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
632  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
633
634  g_bitDepthY     = sps->getBitDepthY();
635  g_bitDepthC     = sps->getBitDepthC();
636  g_uiMaxCUWidth  = sps->getMaxCUWidth();
637  g_uiMaxCUHeight = sps->getMaxCUHeight();
638  g_uiMaxCUDepth  = sps->getMaxCUDepth();
639  g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() );
640
641  for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++)
642  {
643    sps->setAMPAcc( i, sps->getUseAMP() );
644  }
645
646  for (Int i = sps->getLog2DiffMaxMinCodingBlockSize(); i < sps->getMaxCUDepth(); i++)
647  {
648    sps->setAMPAcc( i, 0 );
649  }
650
651  m_cSAO.destroy();
652  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() );
653  m_cLoopFilter.create( sps->getMaxCUDepth() );
654}
655
656#if H_MV
657Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool newLayerFlag )
658{
659  assert( nalu.m_layerId == m_layerId ); 
660
661#else
662Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
663{
664#endif
665  TComPic*&   pcPic         = m_pcPic;
666  m_apcSlicePilot->initSlice();
667
668  if (m_bFirstSliceInPicture)
669  {
670    m_uiSliceIdx     = 0;
671  }
672  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
673  if (!m_bFirstSliceInPicture)
674  {
675    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
676  }
677
678  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
679  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
680                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
681                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
682                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
683                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
684  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
685 
686  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
687  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
688
689#if H_MV
690  m_apcSlicePilot->setLayerId( nalu.m_layerId );
691#endif
692  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
693
694#if H_MV 
695  TComVPS* vps     = m_apcSlicePilot->getVPS();
696  Int layerIdInVps = vps->getLayerIdInVps( nalu.m_layerId ); 
697  setViewId   ( vps->getViewId   ( layerIdInVps )      ); 
698#if H_3D
699  setViewIndex( vps->getViewIndex( layerIdInVps )      ); 
700  setIsDepth  ( vps->getDepthId  ( layerIdInVps ) == 1 ); 
701  m_ivPicLists->setVPS( vps ); 
702#endif
703#endif
704    // Skip pictures due to random access
705    if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
706    {
707      return false;
708    }
709    // Skip TFD pictures associated with BLA/BLANT pictures
710    if (isSkipPictureForBLA(iPOCLastDisplay))
711    {
712      return false;
713    }
714
715  //we should only get a different poc for a new picture (with CTU address==0)
716  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (!m_apcSlicePilot->getSliceCurStartCUAddr()==0))
717  {
718    printf ("Warning, the first slice of a picture might have been lost!\n");
719  }
720  // exit when a new picture is found
721  if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence )
722  {
723    if (m_prevPOC >= m_pocRandomAccess)
724    {
725      m_prevPOC = m_apcSlicePilot->getPOC();
726      return true;
727    }
728    m_prevPOC = m_apcSlicePilot->getPOC();
729  }
730#if H_MV
731  if ( newLayerFlag )
732  {
733    return false; 
734  }
735#endif
736  // actual decoding starts here
737  xActivateParameterSets();
738
739  if (m_apcSlicePilot->isNextSlice()) 
740  {
741    m_prevPOC = m_apcSlicePilot->getPOC();
742  }
743  m_bFirstSliceInSequence = false;
744  //detect lost reference picture and insert copy of earlier frame.
745  Int lostPoc;
746  while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
747  {
748    xCreateLostPicture(lostPoc-1);
749  }
750  if (m_bFirstSliceInPicture)
751  {
752    // Buffer initialize for prediction.
753    m_cPrediction.initTempBuff();
754    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
755#if H_MV
756    m_apcSlicePilot->createAndApplyIvReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer ); 
757#endif
758    //  Get a new picture buffer
759    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
760
761    // transfer any SEI messages that have been received to the picture
762    pcPic->setSEIs(m_SEIs);
763    m_SEIs.clear();
764
765    // Recursive structure
766    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
767    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
768    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
769
770    m_cSliceDecoder.create();
771#if H_3D_IV_MERGE
772    UInt uiPdm = ( m_apcSlicePilot->getSPS()->getViewIndex() ? m_apcSlicePilot->getSPS()->getPredDepthMapGeneration() : m_tAppDecTop->getSPSAccess()->getPdm() );
773    m_cDepthMapGenerator.create( true, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_bitDepthY, PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
774    TComDepthMapGenerator* pcDMG0 = m_tAppDecTop->getDecTop0()->getDepthMapGenerator();
775    if( m_apcSlicePilot->getSPS()->getViewIndex() == 1 && ( pcDMG0->getSubSampExpX() != PDM_SUB_SAMP_EXP_X(uiPdm) || pcDMG0->getSubSampExpY() != PDM_SUB_SAMP_EXP_Y(uiPdm) ) )
776    {
777      pcDMG0->create( true, m_apcSlicePilot->getSPS()->getPicWidthInLumaSamples(), m_apcSlicePilot->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_bitDepthY, PDM_SUB_SAMP_EXP_X(uiPdm), PDM_SUB_SAMP_EXP_Y(uiPdm) );
778    }
779#endif
780  }
781  else
782  {
783    // Check if any new SEI has arrived
784    if(!m_SEIs.empty())
785    {
786      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
787      SEIMessages &picSEI = pcPic->getSEIs();
788      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
789      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
790      deleteSEIs(m_SEIs);
791    }
792  }
793 
794  //  Set picture slice pointer
795  TComSlice*  pcSlice = m_apcSlicePilot;
796  Bool bNextSlice     = pcSlice->isNextSlice();
797
798  UInt uiCummulativeTileWidth;
799  UInt uiCummulativeTileHeight;
800  UInt i, j, p;
801
802  //set NumColumnsMins1 and NumRowsMinus1
803  pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
804  pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
805
806  //create the TComTileArray
807  pcPic->getPicSym()->xCreateTComTileArray();
808
809  if( pcSlice->getPPS()->getUniformSpacingFlag() )
810  {
811    //set the width for each tile
812    for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
813    {
814      for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
815      {
816        pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
817          setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
818          - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
819      }
820    }
821
822    //set the height for each tile
823    for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
824    {
825      for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
826      {
827        pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
828          setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
829          - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
830      }
831    }
832  }
833  else
834  {
835    //set the width for each tile
836    for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
837    {
838      uiCummulativeTileWidth = 0;
839      for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
840      {
841        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
842        uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
843      }
844      pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
845    }
846
847    //set the height for each tile
848    for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
849    {
850      uiCummulativeTileHeight = 0;
851      for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
852      { 
853        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
854        uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
855      }
856      pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
857    }
858  }
859
860  pcPic->getPicSym()->xInitTiles();
861
862  //generate the Coding Order Map and Inverse Coding Order Map
863  UInt uiEncCUAddr;
864  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
865  {
866    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
867    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
868  }
869  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
870  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
871
872  //convert the start and end CU addresses of the slice and dependent slice into encoding order
873  pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) );
874  pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) );
875  if(pcSlice->isNextSlice())
876  {
877    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
878    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
879  }
880
881  if (m_bFirstSliceInPicture) 
882  {
883    if(pcPic->getNumAllocatedSlice() != 1)
884    {
885      pcPic->clearSliceBuffer();
886    }
887  }
888  else
889  {
890    pcPic->allocateNewSlice();
891  }
892  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
893  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
894  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
895
896  pcPic->setTLayer(nalu.m_temporalId);
897
898#if H_MV
899  pcPic->setLayerId( nalu.m_layerId );
900  pcPic->setViewId ( getViewId() );
901#if H_3D
902  pcPic->setViewIndex( getViewIndex() );
903  pcPic->setIsDepth  ( getIsDepth  () );
904#endif
905#endif
906  if (bNextSlice)
907  {
908    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA, m_cListPic );
909    // Set reference list
910#if H_MV   
911    pcSlice->setRefPicList( m_cListPic, m_refPicSetInterLayer, true );   
912#else
913#if FIX1071
914    pcSlice->setRefPicList( m_cListPic, true );
915#else
916    pcSlice->setRefPicList( m_cListPic );
917#endif
918
919#endif
920#if H_3D_IV_MERGE
921    TComPic * const pcTexturePic = m_isDepth ? m_tAppDecTop->getPicFromView(  m_viewIndex, pcSlice->getPOC(), false ) : NULL;
922    assert( !m_isDepth || pcTexturePic != NULL );
923    pcSlice->setTexturePic( pcTexturePic );
924#endif
925    // For generalized B
926    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
927    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
928    {
929      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
930      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
931
932      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
933      {
934        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
935      }
936    }
937    if (!pcSlice->isIntra())
938    {
939      Bool bLowDelay = true;
940      Int  iCurrPOC  = pcSlice->getPOC();
941      Int iRefIdx = 0;
942
943      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
944      {
945        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
946        {
947          bLowDelay = false;
948        }
949      }
950      if (pcSlice->isInterB())
951      {
952        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
953        {
954          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
955          {
956            bLowDelay = false;
957          }
958        }       
959      }
960
961      pcSlice->setCheckLDC(bLowDelay);           
962    }
963
964    //---------------
965    pcSlice->setRefPOCList();
966#if !L0034_COMBINED_LIST_CLEANUP
967    pcSlice->setNoBackPredFlag( false );
968    if ( pcSlice->getSliceType() == B_SLICE )
969    {
970      if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) )
971      {
972        pcSlice->setNoBackPredFlag( true );
973        for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ )
974        {
975          if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) 
976          {
977            pcSlice->setNoBackPredFlag( false );
978            break;
979          }
980        }
981      }
982    }
983#endif
984  }
985
986  pcPic->setCurrSliceIdx(m_uiSliceIdx);
987  if(pcSlice->getSPS()->getScalingListFlag())
988  {
989    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
990    if(pcSlice->getPPS()->getScalingListPresentFlag())
991    {
992      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
993    }
994    pcSlice->getScalingList()->setUseTransformSkip(pcSlice->getPPS()->getUseTransformSkip());
995    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
996    {
997      pcSlice->setDefaultScalingList();
998    }
999    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
1000    m_cTrQuant.setUseScalingList(true);
1001  }
1002  else
1003  {
1004    m_cTrQuant.setFlatScalingList();
1005    m_cTrQuant.setUseScalingList(false);
1006  }
1007
1008  //  Decode a picture
1009  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
1010#if H_3D
1011  if( m_pcCamParsCollector )
1012  {
1013    m_pcCamParsCollector->setSlice( pcSlice );
1014  }
1015#endif
1016  m_bFirstSliceInPicture = false;
1017  m_uiSliceIdx++;
1018
1019  return false;
1020}
1021
1022Void TDecTop::xDecodeVPS()
1023{
1024  TComVPS* vps = new TComVPS();
1025 
1026  m_cEntropyDecoder.decodeVPS( vps );
1027  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
1028}
1029
1030Void TDecTop::xDecodeSPS()
1031{
1032  TComSPS* sps = new TComSPS();
1033#if H_3D
1034  // Preliminary fix. assuming that all sps refer to the same SPS.
1035  // Parsing dependency should be resolved!
1036  TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 ); 
1037  assert( vps != 0 ); 
1038  Int layerIdInVPS = vps->getLayerIdInVps( m_layerId ); 
1039  m_cEntropyDecoder.decodeSPS( sps, vps->getViewIndex( layerIdInVPS ), ( vps->getDepthId( layerIdInVPS ) == 1 ) );
1040#else
1041  m_cEntropyDecoder.decodeSPS( sps );
1042#endif
1043  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
1044}
1045
1046Void TDecTop::xDecodePPS()
1047{
1048  TComPPS* pps = new TComPPS();
1049  m_cEntropyDecoder.decodePPS( pps );
1050  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
1051}
1052
1053Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
1054{
1055  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
1056  {
1057    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1058  }
1059  else
1060  {
1061    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1062    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
1063    if (activeParamSets.size()>0)
1064    {
1065      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
1066      m_parameterSetManagerDecoder.applyPrefetchedPS();
1067      assert(seiAps->activeSeqParamSetId.size()>0);
1068      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
1069      {
1070        printf ("Warning SPS activation with Active parameter set SEI failed");
1071      }
1072    }
1073  }
1074}
1075
1076#if H_MV
1077Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayerFlag)
1078#else
1079Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1080#endif
1081{
1082  // Initialize entropy decoder
1083  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1084  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
1085
1086  switch (nalu.m_nalUnitType)
1087  {
1088    case NAL_UNIT_VPS:
1089      xDecodeVPS();
1090      return false;
1091     
1092    case NAL_UNIT_SPS:
1093      xDecodeSPS();
1094      return false;
1095
1096    case NAL_UNIT_PPS:
1097      xDecodePPS();
1098      return false;
1099     
1100    case NAL_UNIT_PREFIX_SEI:
1101    case NAL_UNIT_SUFFIX_SEI:
1102      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
1103      return false;
1104
1105    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1106    case NAL_UNIT_CODED_SLICE_TRAIL_N:
1107    case NAL_UNIT_CODED_SLICE_TLA_R:
1108    case NAL_UNIT_CODED_SLICE_TSA_N:
1109    case NAL_UNIT_CODED_SLICE_STSA_R:
1110    case NAL_UNIT_CODED_SLICE_STSA_N:
1111    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
1112    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
1113    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1114    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
1115    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
1116    case NAL_UNIT_CODED_SLICE_CRA:
1117    case NAL_UNIT_CODED_SLICE_RADL_N:
1118    case NAL_UNIT_CODED_SLICE_RADL_R:
1119    case NAL_UNIT_CODED_SLICE_RASL_N:
1120    case NAL_UNIT_CODED_SLICE_RASL_R:
1121#if H_MV
1122      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, newLayerFlag);
1123#else
1124      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1125#endif
1126      break;
1127    default:
1128      assert (1);
1129  }
1130
1131  return false;
1132}
1133
1134/** Function for checking if picture should be skipped because of association with a previous BLA picture
1135 * \param iPOCLastDisplay POC of last picture displayed
1136 * \returns true if the picture should be skipped
1137 * This function skips all TFD pictures that follow a BLA picture
1138 * in decoding order and precede it in output order.
1139 */
1140Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
1141{
1142  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))
1143  {
1144    iPOCLastDisplay++;
1145    return true;
1146  }
1147  return false;
1148}
1149
1150/** Function for checking if picture should be skipped because of random access
1151 * \param iSkipFrame skip frame counter
1152 * \param iPOCLastDisplay POC of last picture displayed
1153 * \returns true if the picture shold be skipped in the random access.
1154 * This function checks the skipping of pictures in the case of -s option random access.
1155 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1156 * It also checks the type of Nal unit type at the random access point.
1157 * 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.
1158 * If the random access point is IDR all pictures after the random access point are decoded.
1159 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
1160 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
1161 * access point there is no guarantee that the decoder will not crash.
1162 */
1163Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
1164{
1165  if (iSkipFrame) 
1166  {
1167    iSkipFrame--;   // decrement the counter
1168    return true;
1169  }
1170  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1171  {
1172    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
1173        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1174        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1175        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
1176    {
1177      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
1178      m_pocRandomAccess = m_apcSlicePilot->getPOC();
1179    }
1180    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
1181    {
1182      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1183    }
1184    else 
1185    {
1186      static Bool warningMessage = false;
1187      if(!warningMessage)
1188      {
1189        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1190        warningMessage = true;
1191      }
1192      return true;
1193    }
1194  }
1195  // skip the reordered pictures, if necessary
1196  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))
1197  {
1198    iPOCLastDisplay++;
1199    return true;
1200  }
1201  // if we reach here, then the picture is not skipped.
1202  return false; 
1203}
1204
1205#if H_MV
1206TComPic* TDecTop::getPic( Int poc )
1207{
1208  xGetPic( m_layerId, poc ); 
1209  TComList<TComPic*>* listPic = getListPic();
1210  TComPic* pcPic = NULL;
1211  for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++)
1212  {
1213    if( (*it)->getPOC() == poc )
1214    {
1215      pcPic = *it ;
1216      break ;
1217    }
1218  }
1219  return pcPic;
1220}
1221
1222TComPic* TDecTop::xGetPic( Int layerId, Int poc )
1223{ 
1224  return m_ivPicLists->getPic( layerId, poc ) ;
1225}
1226
1227#endif
1228//! \}
Note: See TracBrowser for help on using the repository browser.