source: 3DVCSoftware/branches/HTM-8.2-dev2-Qualcomm/source/Lib/TLibDecoder/TDecTop.cpp @ 1071

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

JCT3V-F0125

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