source: 3DVCSoftware/branches/HTM-8.2-dev0-MediaTek/source/Lib/TLibDecoder/TDecTop.cpp @ 629

Last change on this file since 629 was 629, checked in by chang, 12 years ago

Added H_3D_FCO for flexible coding order (FCO).
The results can be seen under codingresults/3D_8.1_vs_fco_only.xls.
The configuration files for FCO are located at cfg/3D-HEVC/NonCTC/fco.

  • Property svn:eol-style set to native
File size: 45.2 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
284Bool
285CamParsCollector::xIsComplete()
286{
[608]287  for( UInt uiView = 0; uiView <= m_uiMaxViewIndex; uiView++ )
[2]288  {
[608]289    if( m_bViewReceived[ uiView ] == 0 )
[2]290    {
291      return false;
292    }
293  }
294  return true;
295}
296
297Void
298CamParsCollector::xOutput( Int iPOC )
299{
300  if( m_pCodedScaleOffsetFile )
301  {
302    if( iPOC == 0 )
303    {
[608]304      fprintf( m_pCodedScaleOffsetFile, "#  ViewIndex       ViewId\n" );
[2]305      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------\n" );
[608]306      for( UInt uiViewIndex = 0; uiViewIndex <= m_uiMaxViewIndex; uiViewIndex++ )
[2]307      {
[608]308        fprintf( m_pCodedScaleOffsetFile, "%12d %12d\n", uiViewIndex, m_aiViewId[ uiViewIndex ] );
[2]309      }
310      fprintf( m_pCodedScaleOffsetFile, "\n\n");
311      fprintf( m_pCodedScaleOffsetFile, "# StartFrame     EndFrame   TargetView     BaseView   CodedScale  CodedOffset    Precision\n" );
312      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------ ------------ ------------ ------------ ------------ ------------\n" );
313    }
314    if( iPOC == 0 || m_bCamParsVaryOverTime )
315    {
316      Int iS = iPOC;
317      Int iE = ( m_bCamParsVaryOverTime ? iPOC : ~( 1 << 31 ) );
[608]318      for( UInt uiViewIndex = 0; uiViewIndex <= m_uiMaxViewIndex; uiViewIndex++ )
[2]319      {
[608]320        for( UInt uiBaseIndex = 0; uiBaseIndex <= m_uiMaxViewIndex; uiBaseIndex++ )
[2]321        {
[608]322          if( uiViewIndex != uiBaseIndex )
[2]323          {
324            fprintf( m_pCodedScaleOffsetFile, "%12d %12d %12d %12d %12d %12d %12d\n",
[608]325              iS, iE, uiViewIndex, uiBaseIndex, m_aaiCodedScale[ uiBaseIndex ][ uiViewIndex ], m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ], m_uiCamParsCodedPrecision );
[2]326          }
327        }
328      }
329    }
330  }
331}
[608]332#endif
[2]333TDecTop::TDecTop()
334{
[56]335  m_pcPic = 0;
[2]336  m_iMaxRefPicNum = 0;
337#if ENC_DEC_TRACE
[608]338#if H_MV
339  if ( g_hTrace == NULL )
340  {
341#endif
342  g_hTrace = fopen( "TraceDec.txt", "wb" );
[2]343  g_bJustDoIt = g_bEncDecTraceDisable;
344  g_nSymbolCounter = 0;
[608]345#if H_MV
346  }
[2]347#endif
[608]348#endif
[56]349  m_pocCRA = 0;
[608]350  m_prevRAPisBLA = false;
351  m_pocRandomAccess = MAX_INT; 
[56]352  m_prevPOC                = MAX_INT;
[2]353  m_bFirstSliceInPicture    = true;
354  m_bFirstSliceInSequence   = true;
[608]355#if H_MV
356  m_layerId = 0;
357  m_viewId = 0;
358#if H_3D
359  m_viewIndex = 0; 
360  m_isDepth = false;
[57]361  m_pcCamParsCollector = 0;
[210]362#endif
[608]363#endif
[2]364}
365
366TDecTop::~TDecTop()
367{
368#if ENC_DEC_TRACE
[608]369  fclose( g_hTrace );
[2]370#endif
371}
372
373Void TDecTop::create()
374{
375  m_cGopDecoder.create();
376  m_apcSlicePilot = new TComSlice;
[608]377  m_uiSliceIdx = 0;
[2]378}
379
380Void TDecTop::destroy()
381{
382  m_cGopDecoder.destroy();
[56]383 
[2]384  delete m_apcSlicePilot;
385  m_apcSlicePilot = NULL;
[56]386 
[2]387  m_cSliceDecoder.destroy();
388}
389
[608]390Void TDecTop::init()
[2]391{
392  // initialize ROM
[608]393#if !H_MV
[56]394  initROM();
[5]395#endif
[608]396  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO );
[2]397  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
398  m_cEntropyDecoder.init(&m_cPrediction);
399}
400
401Void TDecTop::deletePicBuffer ( )
402{
403  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
404  Int iSize = Int( m_cListPic.size() );
[56]405 
[2]406  for (Int i = 0; i < iSize; i++ )
407  {
[608]408    TComPic* pcPic = *(iterPic++);
409#if H_MV
410    if( pcPic )
[56]411    {
[608]412#endif
413    pcPic->destroy();
[56]414   
[608]415    delete pcPic;
416    pcPic = NULL;
417#if H_MV
[56]418    }
[608]419#endif
[2]420  }
[56]421 
[2]422  m_cSAO.destroy();
[56]423 
[2]424  m_cLoopFilter.        destroy();
[56]425 
[608]426#if !H_MV
[2]427  // destroy ROM
[608]428  destroyROM();
429#endif
[2]430}
431
[608]432Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
[56]433{
[608]434  Int  numReorderPics[MAX_TLAYER];
435  Window &conformanceWindow = pcSlice->getSPS()->getConformanceWindow();
436  Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window();
[56]437
[622]438#if H_MV5
439#if H_MV
440    assert( conformanceWindow   .getScaledFlag() ); 
441    assert( defaultDisplayWindow.getScaledFlag() );
442#endif
443#endif
[608]444  for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
[56]445  {
[608]446    numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer);
[56]447  }
448
[608]449  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
[2]450  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
451  {
[56]452    rpcPic = new TComPic();
453   
[608]454    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
455                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
456    rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
[2]457    m_cListPic.pushBack( rpcPic );
[56]458   
[2]459    return;
460  }
[56]461 
[2]462  Bool bBufferIsAvailable = false;
463  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
464  while (iterPic != m_cListPic.end())
465  {
466    rpcPic = *(iterPic++);
[56]467    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
[2]468    {
[56]469      rpcPic->setOutputMark(false);
[2]470      bBufferIsAvailable = true;
471      break;
472    }
[56]473
474    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
475    {
476      rpcPic->setOutputMark(false);
477      rpcPic->setReconMark( false );
478      rpcPic->getPicYuvRec()->setBorderExtension( false );
479      bBufferIsAvailable = true;
480      break;
481    }
[2]482  }
[56]483 
[2]484  if ( !bBufferIsAvailable )
485  {
[56]486    //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer.
487    m_iMaxRefPicNum++;
488    rpcPic = new TComPic();
489    m_cListPic.pushBack( rpcPic );
[2]490  }
[608]491  rpcPic->destroy();
492  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
493                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
494  rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
[2]495}
496
[608]497#if H_MV
498Void TDecTop::endPicDecoding(Int& poc, TComList<TComPic*>*& rpcListPic, std::vector<Int>& targetDecLayerIdSet )
499#else
500Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic)
501#endif
[56]502{
503  if (!m_pcPic)
504  {
505    /* nothing to deblock */
506    return;
507  }
508 
509  TComPic*&   pcPic         = m_pcPic;
[2]510
[608]511  // Execute Deblock + Cleanup
[56]512
[608]513  m_cGopDecoder.filterPicture(pcPic);
[56]514
515  TComSlice::sortPicList( m_cListPic ); // sorting for application output
[608]516  poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
[56]517  rpcListPic          = &m_cListPic; 
518  m_cCuDecoder.destroy();       
[608]519#if H_MV
[622]520#if H_MV5
521  TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
522#else
[608]523  TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer ); 
[622]524#endif
[608]525  TComSlice::markCurrPic( pcPic ); 
526  TComSlice::markIvRefPicsAsUnused   ( m_ivPicLists, targetDecLayerIdSet, m_parameterSetManagerDecoder.getActiveVPS(), m_layerId, poc ); 
527#endif
[56]528  m_bFirstSliceInPicture  = true;
529
530  return;
531}
532
533Void TDecTop::xCreateLostPicture(Int iLostPoc) 
[2]534{
[56]535  printf("\ninserting lost poc : %d\n",iLostPoc);
536  TComSlice cFillSlice;
537  cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
538  cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
539  cFillSlice.initSlice();
540  TComPic *cFillPic;
541  xGetNewPicBuffer(&cFillSlice,cFillPic);
542  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
543  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
544  cFillPic->getSlice(0)->initSlice();
545 
546  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
547  Int closestPoc = 1000000;
548  while ( iterPic != m_cListPic.end())
[2]549  {
[56]550    TComPic * rpcPic = *(iterPic++);
551    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]552    {
[56]553      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
554    }
555  }
556  iterPic = m_cListPic.begin();
557  while ( iterPic != m_cListPic.end())
558  {
559    TComPic *rpcPic = *(iterPic++);
560    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
561    {
562      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
563      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
[2]564      break;
565    }
566  }
[56]567  cFillPic->setCurrSliceIdx(0);
568  for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) 
[2]569  {
[56]570    cFillPic->getCU(i)->initCU(cFillPic,i);
[2]571  }
[56]572  cFillPic->getSlice(0)->setReferenced(true);
573  cFillPic->getSlice(0)->setPOC(iLostPoc);
574  cFillPic->setReconMark(true);
575  cFillPic->setOutputMark(true);
576  if(m_pocRandomAccess == MAX_INT)
577  {
578    m_pocRandomAccess = iLostPoc;
579  }
[2]580}
581
[56]582
583Void TDecTop::xActivateParameterSets()
[2]584{
[56]585  m_parameterSetManagerDecoder.applyPrefetchedPS();
[608]586 
[56]587  TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
588  assert (pps != 0);
589
590  TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId());
591  assert (sps != 0);
[608]592
[622]593#if H_MV5
594#if H_MV
595  TComVPS* vps = m_parameterSetManagerDecoder.getVPS(sps->getVPSId());
596  assert (vps != 0); 
597  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP(), m_layerId ) )
598#else
[608]599  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
[622]600#endif
601#else
602  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
603#endif
[608]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
[56]626  m_apcSlicePilot->setPPS(pps);
627  m_apcSlicePilot->setSPS(sps);
[608]628#if H_MV
[622]629#if H_MV5
630  m_apcSlicePilot->setVPS(vps); 
631  sps->inferRepFormat  ( vps , m_layerId ); 
632  sps->inferScalingList( m_parameterSetManagerDecoder.getActiveSPS( sps->getSpsScalingListRefLayerId() ) ); 
633#else
[608]634  m_apcSlicePilot->setVPS( m_parameterSetManagerDecoder.getActiveVPS() );
[210]635#endif
[622]636#endif
[56]637  pps->setSPS(sps);
[608]638  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
[56]639  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
640
[608]641  g_bitDepthY     = sps->getBitDepthY();
642  g_bitDepthC     = sps->getBitDepthC();
643  g_uiMaxCUWidth  = sps->getMaxCUWidth();
644  g_uiMaxCUHeight = sps->getMaxCUHeight();
645  g_uiMaxCUDepth  = sps->getMaxCUDepth();
646  g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() );
647
648  for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++)
[2]649  {
[56]650    sps->setAMPAcc( i, sps->getUseAMP() );
[2]651  }
[56]652
[608]653  for (Int i = sps->getLog2DiffMaxMinCodingBlockSize(); i < sps->getMaxCUDepth(); i++)
[56]654  {
655    sps->setAMPAcc( i, 0 );
656  }
657
[608]658  m_cSAO.destroy();
659  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() );
660  m_cLoopFilter.create( sps->getMaxCUDepth() );
[2]661}
[56]662
[608]663#if H_MV
664Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool newLayerFlag )
665{
666  assert( nalu.m_layerId == m_layerId ); 
667
668#else
[56]669Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
[2]670{
[608]671#endif
[2]672  TComPic*&   pcPic         = m_pcPic;
[56]673  m_apcSlicePilot->initSlice();
[2]674
[56]675  if (m_bFirstSliceInPicture)
[2]676  {
[56]677    m_uiSliceIdx     = 0;
[2]678  }
[56]679  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
680  if (!m_bFirstSliceInPicture)
681  {
682    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
683  }
[2]684
[56]685  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
[608]686  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
687                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
688                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
689                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
690                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
691  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
692 
693  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
[56]694  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
[42]695
[608]696#if H_MV
[622]697#if H_MV5
698  m_apcSlicePilot->setRefPicSetInterLayer( & m_refPicSetInterLayer0, &m_refPicSetInterLayer1 ); 
699#else
[608]700  m_apcSlicePilot->setRefPicSetInterLayer( & m_refPicSetInterLayer ); 
[622]701#endif
[608]702  m_apcSlicePilot->setLayerId( nalu.m_layerId );
[42]703#endif
[608]704  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder);
705
706#if H_MV 
707  TComVPS* vps     = m_apcSlicePilot->getVPS();
[622]708#if H_MV5
709  Int layerId  = nalu.m_layerId;   
710  setViewId   ( vps->getViewId   ( layerId )      ); 
711#if H_3D
712  setViewIndex( vps->getViewIndex( layerId )      ); 
713  setIsDepth  ( vps->getDepthId  ( layerId ) == 1 ); 
714  m_ivPicLists->setVPS( vps ); 
715#endif
716#else
[608]717  Int layerIdInVps = vps->getLayerIdInVps( nalu.m_layerId ); 
718  setViewId   ( vps->getViewId   ( layerIdInVps )      ); 
719#if H_3D
720  setViewIndex( vps->getViewIndex( layerIdInVps )      ); 
721  setIsDepth  ( vps->getDepthId  ( layerIdInVps ) == 1 ); 
722  m_ivPicLists->setVPS( vps ); 
723#endif
724#endif
[622]725#endif
[608]726    // Skip pictures due to random access
727    if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
[56]728    {
[608]729      return false;
[56]730    }
[608]731    // Skip TFD pictures associated with BLA/BLANT pictures
732    if (isSkipPictureForBLA(iPOCLastDisplay))
733    {
734      return false;
735    }
736
737  //we should only get a different poc for a new picture (with CTU address==0)
738  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (!m_apcSlicePilot->getSliceCurStartCUAddr()==0))
739  {
740    printf ("Warning, the first slice of a picture might have been lost!\n");
[56]741  }
742  // exit when a new picture is found
[608]743  if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence )
[56]744  {
745    if (m_prevPOC >= m_pocRandomAccess)
746    {
747      m_prevPOC = m_apcSlicePilot->getPOC();
748      return true;
749    }
750    m_prevPOC = m_apcSlicePilot->getPOC();
751  }
[608]752#if H_MV
753  if ( newLayerFlag )
754  {
755    return false; 
756  }
757#if ENC_DEC_TRACE
758#if H_MV_ENC_DEC_TRAC
759  // parse remainder of SH
760   g_disableHLSTrace = false; 
761#endif
762#endif
763#endif
[56]764  // actual decoding starts here
[622]765#if H_MV5
766#if H_MV
767   // This part needs further testing !
768   if ( m_apcSlicePilot->getPocResetFlag() )
769   {   
770     xResetPocInPicBuffer();
771   }
772#endif
773#endif
[56]774  xActivateParameterSets();
775
776  if (m_apcSlicePilot->isNextSlice()) 
777  {
778    m_prevPOC = m_apcSlicePilot->getPOC();
779  }
780  m_bFirstSliceInSequence = false;
781  //detect lost reference picture and insert copy of earlier frame.
[608]782  Int lostPoc;
783  while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
[56]784  {
[608]785    xCreateLostPicture(lostPoc-1);
[56]786  }
[2]787  if (m_bFirstSliceInPicture)
788  {
[56]789    // Buffer initialize for prediction.
790    m_cPrediction.initTempBuff();
791    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
[608]792#if H_MV
[622]793#if H_MV5
794    m_apcSlicePilot->createInterLayerReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
795#else
[608]796    m_apcSlicePilot->createAndApplyIvReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer ); 
797#endif
[622]798#endif
[56]799    //  Get a new picture buffer
800    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
[2]801
[608]802    // transfer any SEI messages that have been received to the picture
[56]803    pcPic->setSEIs(m_SEIs);
[608]804    m_SEIs.clear();
[42]805
[56]806    // Recursive structure
807    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
808    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
809    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
[42]810
[608]811    m_cSliceDecoder.create();
812  }
813  else
814  {
815    // Check if any new SEI has arrived
816    if(!m_SEIs.empty())
[56]817    {
[608]818      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
819      SEIMessages &picSEI = pcPic->getSEIs();
820      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
821      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
822      deleteSEIs(m_SEIs);
[56]823    }
824  }
[608]825 
[56]826  //  Set picture slice pointer
827  TComSlice*  pcSlice = m_apcSlicePilot;
828  Bool bNextSlice     = pcSlice->isNextSlice();
[2]829
[56]830  UInt uiCummulativeTileWidth;
831  UInt uiCummulativeTileHeight;
832  UInt i, j, p;
833
[608]834  //set NumColumnsMins1 and NumRowsMinus1
835  pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
836  pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
[2]837
[608]838  //create the TComTileArray
839  pcPic->getPicSym()->xCreateTComTileArray();
840
841  if( pcSlice->getPPS()->getUniformSpacingFlag() )
[56]842  {
[608]843    //set the width for each tile
844    for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
[56]845    {
[608]846      for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
[2]847      {
[608]848        pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
849          setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
850          - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
[2]851      }
[608]852    }
[2]853
[608]854    //set the height for each tile
855    for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
[2]856    {
[608]857      for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
[2]858      {
[608]859        pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
860          setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
861          - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
[2]862      }
[56]863    }
864  }
865  else
866  {
[608]867    //set the width for each tile
868    for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
[56]869    {
[608]870      uiCummulativeTileWidth = 0;
871      for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
[2]872      {
[608]873        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
874        uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
[2]875      }
[608]876      pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
877    }
[56]878
[608]879    //set the height for each tile
880    for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
[56]881    {
[608]882      uiCummulativeTileHeight = 0;
883      for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
884      { 
885        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
886        uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
[56]887      }
[608]888      pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
[56]889    }
890  }
[2]891
[56]892  pcPic->getPicSym()->xInitTiles();
[2]893
[56]894  //generate the Coding Order Map and Inverse Coding Order Map
895  UInt uiEncCUAddr;
896  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
897  {
898    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
899    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
900  }
901  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
902  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
903
[608]904  //convert the start and end CU addresses of the slice and dependent slice into encoding order
905  pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) );
906  pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) );
[56]907  if(pcSlice->isNextSlice())
908  {
909    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
910    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
911  }
912
913  if (m_bFirstSliceInPicture) 
914  {
915    if(pcPic->getNumAllocatedSlice() != 1)
916    {
917      pcPic->clearSliceBuffer();
918    }
919  }
920  else
921  {
922    pcPic->allocateNewSlice();
923  }
924  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
925  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
926  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
927
928  pcPic->setTLayer(nalu.m_temporalId);
929
[608]930#if H_MV
931  pcPic->setLayerId( nalu.m_layerId );
932  pcPic->setViewId ( getViewId() );
933#if H_3D
934  pcPic->setViewIndex( getViewIndex() );
935  pcPic->setIsDepth  ( getIsDepth  () );
936#endif
937#endif
[56]938  if (bNextSlice)
939  {
[608]940    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA, m_cListPic );
941    // Set reference list
942#if H_MV   
[622]943#if H_MV5
944    std::vector< TComPic* > tempRefPicLists[2];
945    std::vector< Bool     > usedAsLongTerm [2];
946    Int       numPocTotalCurr;
947
948    pcSlice->getTempRefPicLists( m_cListPic, m_refPicSetInterLayer0, m_refPicSetInterLayer1, tempRefPicLists, usedAsLongTerm, numPocTotalCurr);
949    pcSlice->setRefPicList     ( tempRefPicLists, usedAsLongTerm, numPocTotalCurr, true ); 
950#else
[608]951    pcSlice->setRefPicList( m_cListPic, m_refPicSetInterLayer, true );   
[622]952#endif
[608]953#if H_3D_ARP
954    pcSlice->setARPStepNum();
955    if( pcSlice->getARPStepNum() > 1 )
[56]956    {
[622]957      // GT: This seems to be broken, not all nuh_layer_ids are necessarily present
[608]958      for(Int iLayerId = 0; iLayerId < nalu.m_layerId; iLayerId ++ )
959      {
960        Int  iViewIdx =   pcSlice->getVPS()->getViewIndex(iLayerId);
961        Bool bIsDepth = ( pcSlice->getVPS()->getDepthId  ( iLayerId ) == 1 );
962        if( iViewIdx<getViewIndex() && !bIsDepth )
963        {
964          pcSlice->setBaseViewRefPicList( m_ivPicLists->getPicList( iLayerId ), iViewIdx );
965        }
966      }
[56]967    }
[77]968#endif
969#else
[608]970#if FIX1071
971    pcSlice->setRefPicList( m_cListPic, true );
972#else
973    pcSlice->setRefPicList( m_cListPic );
[21]974#endif
975
[296]976#endif
977
[608]978#if H_3D
979    pcSlice->setIvPicLists( m_ivPicLists );         
[629]980#if H_3D_IV_MERGE
981#if H_3D_FCO
982    //assert( !getIsDepth() );
983#else
[608]984    assert( !getIsDepth() || ( pcSlice->getTexturePic() != 0 ) );
[629]985#endif
[608]986#endif   
[210]987#endif
[56]988    // For generalized B
989    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
990    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
991    {
992      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
993      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
[2]994
[56]995      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
996      {
997        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
998      }
999    }
[608]1000    if (!pcSlice->isIntra())
[56]1001    {
1002      Bool bLowDelay = true;
1003      Int  iCurrPOC  = pcSlice->getPOC();
1004      Int iRefIdx = 0;
1005
1006      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
1007      {
1008        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
[21]1009        {
[56]1010          bLowDelay = false;
[21]1011        }
[2]1012      }
[608]1013      if (pcSlice->isInterB())
[56]1014      {
[608]1015        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
[56]1016        {
[608]1017          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
1018          {
1019            bLowDelay = false;
1020          }
1021        }       
[56]1022      }
[2]1023
[56]1024      pcSlice->setCheckLDC(bLowDelay);           
1025    }
1026
1027    //---------------
[608]1028    pcSlice->setRefPOCList();
1029#if  H_3D_TMVP
1030    if(pcSlice->getLayerId())
1031      pcSlice->generateAlterRefforTMVP();
[313]1032#endif
[56]1033  }
1034
1035  pcPic->setCurrSliceIdx(m_uiSliceIdx);
1036  if(pcSlice->getSPS()->getScalingListFlag())
1037  {
[608]1038    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
1039    if(pcSlice->getPPS()->getScalingListPresentFlag())
[56]1040    {
[608]1041      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
[56]1042    }
[608]1043    pcSlice->getScalingList()->setUseTransformSkip(pcSlice->getPPS()->getUseTransformSkip());
1044    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
1045    {
1046      pcSlice->setDefaultScalingList();
1047    }
1048    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
[56]1049    m_cTrQuant.setUseScalingList(true);
1050  }
1051  else
1052  {
1053    m_cTrQuant.setFlatScalingList();
1054    m_cTrQuant.setUseScalingList(false);
1055  }
[2]1056
[56]1057  //  Decode a picture
[608]1058  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
1059#if H_3D
[57]1060  if( m_pcCamParsCollector )
1061  {
1062    m_pcCamParsCollector->setSlice( pcSlice );
1063  }
[608]1064#endif
[56]1065  m_bFirstSliceInPicture = false;
1066  m_uiSliceIdx++;
1067
1068  return false;
1069}
1070
[77]1071Void TDecTop::xDecodeVPS()
1072{
1073  TComVPS* vps = new TComVPS();
1074 
1075  m_cEntropyDecoder.decodeVPS( vps );
1076  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
1077}
[56]1078
1079Void TDecTop::xDecodeSPS()
1080{
1081  TComSPS* sps = new TComSPS();
[608]1082#if H_MV
1083  sps->setLayerId( getLayerId() ); 
1084#endif
1085#if H_3D
1086  // Preliminary fix. assuming that all sps refer to the same SPS.
1087  // Parsing dependency should be resolved!
1088  TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 ); 
1089  assert( vps != 0 ); 
[622]1090#if H_MV5
1091  m_cEntropyDecoder.decodeSPS( sps, vps->getViewIndex( m_layerId ), ( vps->getDepthId( m_layerId ) == 1 ) );
1092#else
[608]1093  Int layerIdInVPS = vps->getLayerIdInVps( m_layerId ); 
1094  m_cEntropyDecoder.decodeSPS( sps, vps->getViewIndex( layerIdInVPS ), ( vps->getDepthId( layerIdInVPS ) == 1 ) );
[622]1095#endif
[42]1096#else
[56]1097  m_cEntropyDecoder.decodeSPS( sps );
[42]1098#endif
[56]1099  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
1100}
[2]1101
[56]1102Void TDecTop::xDecodePPS()
1103{
1104  TComPPS* pps = new TComPPS();
[622]1105#if H_MV5
1106#if H_MV
1107  pps->setLayerId( getLayerId() ); 
1108#endif
1109#endif
[608]1110  m_cEntropyDecoder.decodePPS( pps );
[56]1111  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
1112}
[2]1113
[608]1114Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
[56]1115{
[608]1116  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
1117  {
[622]1118#if H_MV5
1119#if H_MV
1120    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS( m_layerId ) );
1121#else
[608]1122    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
[622]1123#endif
1124#else
1125    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() ); 
1126#endif
[608]1127  }
1128  else
1129  {
[622]1130#if H_MV5
1131#if H_MV
1132    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS( m_layerId ) );
1133#else
[608]1134    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
[622]1135#endif
1136#else
1137    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1138#endif
[608]1139    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
1140    if (activeParamSets.size()>0)
1141    {
1142      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
1143      m_parameterSetManagerDecoder.applyPrefetchedPS();
1144      assert(seiAps->activeSeqParamSetId.size()>0);
[622]1145#if H_MV5
1146#if H_MV
1147      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0], m_layerId ))
1148#else
[608]1149      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
[622]1150#endif
1151#else
1152      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParamSetId[0] ))
1153#endif
[608]1154      {
1155        printf ("Warning SPS activation with Active parameter set SEI failed");
1156      }
1157    }
1158  }
[56]1159}
[2]1160
[608]1161#if H_MV
1162Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayerFlag)
1163#else
[56]1164Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
[608]1165#endif
[56]1166{
1167  // Initialize entropy decoder
1168  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1169  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
[2]1170
[56]1171  switch (nalu.m_nalUnitType)
1172  {
[77]1173    case NAL_UNIT_VPS:
1174      xDecodeVPS();
1175      return false;
[608]1176     
[56]1177    case NAL_UNIT_SPS:
1178      xDecodeSPS();
1179      return false;
1180
1181    case NAL_UNIT_PPS:
1182      xDecodePPS();
1183      return false;
[608]1184     
1185    case NAL_UNIT_PREFIX_SEI:
1186    case NAL_UNIT_SUFFIX_SEI:
1187      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
[56]1188      return false;
1189
[608]1190    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1191    case NAL_UNIT_CODED_SLICE_TRAIL_N:
1192    case NAL_UNIT_CODED_SLICE_TLA_R:
1193    case NAL_UNIT_CODED_SLICE_TSA_N:
1194    case NAL_UNIT_CODED_SLICE_STSA_R:
1195    case NAL_UNIT_CODED_SLICE_STSA_N:
1196    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
1197    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
1198    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1199    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
1200    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
[56]1201    case NAL_UNIT_CODED_SLICE_CRA:
[608]1202    case NAL_UNIT_CODED_SLICE_RADL_N:
1203    case NAL_UNIT_CODED_SLICE_RADL_R:
1204    case NAL_UNIT_CODED_SLICE_RASL_N:
1205    case NAL_UNIT_CODED_SLICE_RASL_R:
1206#if H_MV
1207      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, newLayerFlag);
1208#else
[56]1209      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
[608]1210#endif
[2]1211      break;
1212    default:
1213      assert (1);
1214  }
1215
1216  return false;
1217}
1218
[608]1219/** Function for checking if picture should be skipped because of association with a previous BLA picture
1220 * \param iPOCLastDisplay POC of last picture displayed
1221 * \returns true if the picture should be skipped
1222 * This function skips all TFD pictures that follow a BLA picture
1223 * in decoding order and precede it in output order.
1224 */
1225Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
[210]1226{
[608]1227  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))
1228  {
1229    iPOCLastDisplay++;
1230    return true;
1231  }
1232  return false;
[210]1233}
1234
[2]1235/** Function for checking if picture should be skipped because of random access
1236 * \param iSkipFrame skip frame counter
1237 * \param iPOCLastDisplay POC of last picture displayed
1238 * \returns true if the picture shold be skipped in the random access.
1239 * This function checks the skipping of pictures in the case of -s option random access.
1240 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1241 * It also checks the type of Nal unit type at the random access point.
[608]1242 * 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]1243 * If the random access point is IDR all pictures after the random access point are decoded.
[608]1244 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
1245 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
[2]1246 * access point there is no guarantee that the decoder will not crash.
1247 */
1248Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
1249{
[56]1250  if (iSkipFrame) 
[2]1251  {
1252    iSkipFrame--;   // decrement the counter
1253    return true;
1254  }
[56]1255  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
[2]1256  {
[608]1257    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
1258        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1259        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1260        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
[2]1261    {
[608]1262      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
1263      m_pocRandomAccess = m_apcSlicePilot->getPOC();
[2]1264    }
[608]1265    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
[2]1266    {
[608]1267      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
[2]1268    }
[56]1269    else 
[2]1270    {
[608]1271      static Bool warningMessage = false;
[56]1272      if(!warningMessage)
1273      {
1274        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1275        warningMessage = true;
1276      }
1277      return true;
[2]1278    }
1279  }
[608]1280  // skip the reordered pictures, if necessary
1281  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]1282  {
1283    iPOCLastDisplay++;
1284    return true;
1285  }
1286  // if we reach here, then the picture is not skipped.
[56]1287  return false; 
[2]1288}
[56]1289
[608]1290#if H_MV
1291TComPic* TDecTop::getPic( Int poc )
[56]1292{
[608]1293  xGetPic( m_layerId, poc ); 
1294  TComList<TComPic*>* listPic = getListPic();
1295  TComPic* pcPic = NULL;
1296  for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++)
1297  {
1298    if( (*it)->getPOC() == poc )
1299    {
1300      pcPic = *it ;
1301      break ;
1302    }
1303  }
1304  return pcPic;
[56]1305}
[2]1306
[608]1307TComPic* TDecTop::xGetPic( Int layerId, Int poc )
1308{ 
1309  return m_ivPicLists->getPic( layerId, poc ) ;
1310}
1311
[622]1312#if H_MV5
1313Void TDecTop::xResetPocInPicBuffer()
1314{
1315  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
1316  while (iterPic != m_cListPic.end())
1317  {
1318    TComPic* pic = *(iterPic++);
1319    if ( pic->getReconMark() )
1320    {
1321      for( Int i = 0; i < pic->getNumAllocatedSlice(); i++)
1322      {
1323        TComSlice* slice = pic->getSlice( i ); 
1324        slice->setPOC ( slice->getPOC() - m_apcSlicePilot->getPocBeforeReset() );           
1325      }         
1326    }     
1327  }
1328}
[608]1329#endif
[622]1330#endif
[56]1331//! \}
Note: See TracBrowser for help on using the repository browser.