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

Last change on this file since 476 was 476, checked in by mediatek-htm, 11 years ago

Integration of 3D-HEVC merge related coding tools:
Inter-view motion merge candidate
HHI_INTER_VIEW_MOTION_PRED
SAIT_IMPROV_MOTION_PRED_M24829, improved inter-view motion vector prediction
QC_MRG_CANS_B0048 , JCT3V-B0048, B0086, B0069
OL_DISMV_POS_B0069 , different pos for disparity MV candidate, B0069
MTK_INTERVIEW_MERGE_A0049 , second part
QC_AMVP_MRG_UNIFY_IVCAN_C0051
TEXTURE MERGING CANDIDATE , JCT3V-C0137

Notes: Two configurations are added:
PredDepthMapGen : 1
MultiviewMvPred : 7

From: yiwen.chen@… (MediaTek)

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