source: 3DVCSoftware/branches/HTM-11.1-dev0/source/Lib/TLibDecoder/TDecTop.cpp @ 1417

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

Cleanup part 7.

  • Property svn:eol-style set to native
File size: 55.9 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 *
[872]6* Copyright (c) 2010-2014, 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  for( UInt uiId = 0; uiId < MAX_NUM_LAYERS; uiId++ )
[2]54  {
[608]55    m_aaiCodedOffset      [ uiId ] = new Int [ MAX_NUM_LAYERS ];
56    m_aaiCodedScale       [ uiId ] = new Int [ MAX_NUM_LAYERS ];
[2]57  }
[296]58
[608]59  xCreateLUTs( (UInt)MAX_NUM_LAYERS, (UInt)MAX_NUM_LAYERS, m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
[296]60  m_iLog2Precision   = LOG2_DISP_PREC_LUT;
61  m_uiBitDepthForLUT = 8; // fixed
[872]62  m_receivedIdc = NULL; 
63  m_vps         = NULL; 
[2]64}
65
66CamParsCollector::~CamParsCollector()
67{
[608]68  for( UInt uiId = 0; uiId < MAX_NUM_LAYERS; uiId++ )
[2]69  {
70    delete [] m_aaiCodedOffset      [ uiId ];
71    delete [] m_aaiCodedScale       [ uiId ];
72  }
73  delete [] m_aaiCodedOffset;
74  delete [] m_aaiCodedScale;
[296]75
[608]76  xDeleteArray( m_adBaseViewShiftLUT, MAX_NUM_LAYERS, MAX_NUM_LAYERS, 2 );
77  xDeleteArray( m_aiBaseViewShiftLUT, MAX_NUM_LAYERS, MAX_NUM_LAYERS, 2 );
[872]78  xDeleteArray( m_receivedIdc, m_uiMaxViewIndex + 1 );
[2]79}
80
[872]81
[2]82Void
[872]83CamParsCollector::init( FILE* pCodedScaleOffsetFile, TComVPS* vps)
84{
85  assert( !isInitialized() ); // Only one initialization currently supported
86  m_bInitialized            = true;
87  m_vps                     = vps; 
88  m_bCamParsVaryOverTime    = false; 
89  m_pCodedScaleOffsetFile   = pCodedScaleOffsetFile;
90  m_lastPoc                 = -1;   
91  m_firstReceivedPoc        = -2; 
92
93  m_uiMaxViewIndex            = -1; 
94  for (Int i = 0; i <= vps->getMaxLayersMinus1(); i++)
95  {
96    Int curViewIdx = m_vps->getViewIndex( m_vps->getLayerIdInNuh( i )); 
97    m_bCamParsVaryOverTime = m_bCamParsVaryOverTime || vps->hasCamParInSliceHeader( curViewIdx );
98    m_uiMaxViewIndex = std::max( m_uiMaxViewIndex, curViewIdx  ) ; 
99  }
100
101  assert( m_receivedIdc == NULL ); 
102  m_receivedIdc = new Int*[ m_uiMaxViewIndex + 1]; 
103  for (Int i = 0; i <= m_uiMaxViewIndex; i++)
104  {
105    m_receivedIdc[i] = new Int[ m_uiMaxViewIndex + 1 ]; 
106  }
107
108  xResetReceivedIdc( true ); 
109
110  for (Int viewIndex = 0; viewIndex <= m_uiMaxViewIndex ; viewIndex++ )
111  {
112    if (m_vps->getCamParPresent( viewIndex ) )
113    {   
114      if( !m_vps->hasCamParInSliceHeader( viewIndex ) ) 
115      {
116        for (Int baseViewIndex = 0; baseViewIndex < viewIndex ; baseViewIndex++ )
117        { 
118          m_receivedIdc   [ baseViewIndex ][ viewIndex ] = -1; 
119          m_aaiCodedScale [ baseViewIndex ][ viewIndex ] = m_vps->getCodedScale    (viewIndex) [ baseViewIndex ];
120          m_aaiCodedOffset[ baseViewIndex ][ viewIndex ] = m_vps->getCodedOffset   (viewIndex) [ baseViewIndex ];
121
122          m_receivedIdc   [ viewIndex ][ baseViewIndex ] = -1; 
123          m_aaiCodedScale [ viewIndex ][ baseViewIndex ] = m_vps->getInvCodedScale (viewIndex) [ baseViewIndex ];
124          m_aaiCodedOffset[ viewIndex ][ baseViewIndex ] = m_vps->getInvCodedOffset(viewIndex) [ baseViewIndex ];
125          xInitLUTs( baseViewIndex, viewIndex, m_aaiCodedScale[ baseViewIndex ][ viewIndex ], m_aaiCodedOffset[ baseViewIndex ][ viewIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
126          xInitLUTs( viewIndex, baseViewIndex, m_aaiCodedScale[ viewIndex ][ baseViewIndex ], m_aaiCodedOffset[ viewIndex ][ baseViewIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
127        }
128      }
129    }
130  }
131}
132
133Void
134CamParsCollector::xResetReceivedIdc( Bool overWriteFlag )
135{
136  for (Int i = 0; i <= m_uiMaxViewIndex; i++)
137  { 
138    for (Int j = 0; j <= m_uiMaxViewIndex; j++)
139    {
140      if ( overWriteFlag ||  ( m_receivedIdc[i][j] != -1 ) )
141      {
142        m_receivedIdc[i][j] = 0; 
143      }     
144    }
145  }
146}
[2]147
[872]148
[2]149Void
[296]150CamParsCollector::xCreateLUTs( UInt uiNumberSourceViews, UInt uiNumberTargetViews, Double****& radLUT, Int****& raiLUT)
151{
152
[608]153  uiNumberSourceViews = std::max( (UInt) 1, uiNumberSourceViews );
154  uiNumberTargetViews = std::max( (UInt) 1, uiNumberTargetViews );
[296]155
156  radLUT         = new Double***[ uiNumberSourceViews ];
157  raiLUT         = new Int   ***[ uiNumberSourceViews ];
158
159  for( UInt uiSourceView = 0; uiSourceView < uiNumberSourceViews; uiSourceView++ )
160  {
161    radLUT        [ uiSourceView ] = new Double**[ uiNumberTargetViews ];
162    raiLUT        [ uiSourceView ] = new Int   **[ uiNumberTargetViews ];
163
164    for( UInt uiTargetView = 0; uiTargetView < uiNumberTargetViews; uiTargetView++ )
165    {
166      radLUT        [ uiSourceView ][ uiTargetView ]      = new Double*[ 2 ];
167      radLUT        [ uiSourceView ][ uiTargetView ][ 0 ] = new Double [ 257 ];
168      radLUT        [ uiSourceView ][ uiTargetView ][ 1 ] = new Double [ 257 ];
169
170      raiLUT        [ uiSourceView ][ uiTargetView ]      = new Int*   [ 2 ];
171      raiLUT        [ uiSourceView ][ uiTargetView ][ 0 ] = new Int    [ 257 ];
172      raiLUT        [ uiSourceView ][ uiTargetView ][ 1 ] = new Int    [ 257 ];
173    }
174  }
175}
176
177Void
178  CamParsCollector::xInitLUTs( UInt uiSourceView, UInt uiTargetView, Int iScale, Int iOffset, Double****& radLUT, Int****& raiLUT)
179{
[872]180  Int     iLog2DivLuma   = m_uiBitDepthForLUT + m_vps->getCamParPrecision() + 1 - m_iLog2Precision;   AOF( iLog2DivLuma > 0 );
[296]181  Int     iLog2DivChroma = iLog2DivLuma + 1;
182
183  iOffset <<= m_uiBitDepthForLUT;
184
185  Double dScale  = (Double) iScale  / (( Double ) ( 1 << iLog2DivLuma ));
186  Double dOffset = (Double) iOffset / (( Double ) ( 1 << iLog2DivLuma ));
187
188  // offsets including rounding offsets
189  Int64 iOffsetLuma   = iOffset + ( ( 1 << iLog2DivLuma   ) >> 1 );
190  Int64 iOffsetChroma = iOffset + ( ( 1 << iLog2DivChroma ) >> 1 );
191
192
193  for( UInt uiDepthValue = 0; uiDepthValue < 256; uiDepthValue++ )
194  {
195
196    // real-valued look-up tables
197    Double  dShiftLuma      = ( (Double)uiDepthValue * dScale + dOffset ) * Double( 1 << m_iLog2Precision );
198    Double  dShiftChroma    = dShiftLuma / 2;
199    radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = dShiftLuma;
200    radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = dShiftChroma;
201
202    // integer-valued look-up tables
203    Int64   iTempScale      = (Int64)uiDepthValue * iScale;
204    Int64   iShiftLuma      = ( iTempScale + iOffsetLuma   ) >> iLog2DivLuma;
205    Int64   iShiftChroma    = ( iTempScale + iOffsetChroma ) >> iLog2DivChroma;
206    raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = (Int)iShiftLuma;
207    raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = (Int)iShiftChroma;
208  }
209
210  radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 256 ] = radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 255 ];
211  radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 256 ] = radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 255 ];
212  raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 256 ] = raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 255 ];
213  raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 256 ] = raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 255 ];
214}
215
216Void
[2]217CamParsCollector::uninit()
218{
219  m_bInitialized = false;
220}
221
222Void
223CamParsCollector::setSlice( TComSlice* pcSlice )
224{
225  if( pcSlice == 0 )
226  {
[872]227    xOutput( m_lastPoc );
228    return;
229  }
230
231  if ( pcSlice->getIsDepth())
232  {
233    return;
234  }
235
236  Int curPoc = pcSlice->getPOC();
237  if( m_firstReceivedPoc == -2 )
238  {
239    m_firstReceivedPoc = curPoc; 
240  }
241
242  Bool newPocFlag = ( m_lastPoc != curPoc ); 
243
244  if ( newPocFlag )
245  {   
246    if( m_lastPoc != -1 )
247    {
248      xOutput( m_lastPoc );
249    }
250
251    xResetReceivedIdc( false ); 
252    m_lastPoc = pcSlice->getPOC();
253  }
254
255  UInt uiViewIndex          = pcSlice->getViewIndex(); 
256  if( m_vps->getCamParPresent( uiViewIndex ) )
257  {   
258    if( m_vps->hasCamParInSliceHeader( uiViewIndex ) ) // check consistency of slice parameters here
259    {   
260      for( UInt uiBaseViewIndex = 0; uiBaseViewIndex < uiViewIndex; uiBaseViewIndex++ )
261      {       
262        if ( m_receivedIdc[ uiViewIndex ][ uiBaseViewIndex ] != 0 )
263        {     
264          AOF( m_aaiCodedScale [ uiViewIndex ][ uiBaseViewIndex ] == pcSlice->getInvCodedScale () [ uiBaseViewIndex ] );
265          AOF( m_aaiCodedOffset[ uiViewIndex ][ uiBaseViewIndex ] == pcSlice->getInvCodedOffset() [ uiBaseViewIndex ] );
266        }
267        else
268        {         
269          m_receivedIdc   [ uiViewIndex ][ uiBaseViewIndex ]  = 1; 
270          m_aaiCodedScale [ uiViewIndex ][ uiBaseViewIndex ]  = pcSlice->getInvCodedScale () [ uiBaseViewIndex ];
271          m_aaiCodedOffset[ uiViewIndex ][ uiBaseViewIndex ]  = pcSlice->getInvCodedOffset() [ uiBaseViewIndex ];
272          xInitLUTs( uiViewIndex, uiBaseViewIndex, m_aaiCodedScale[ uiViewIndex ][ uiBaseViewIndex ], m_aaiCodedOffset[ uiViewIndex ][ uiBaseViewIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT);
273        }
274        if ( m_receivedIdc[ uiBaseViewIndex ][ uiViewIndex ] != 0 )
275        {     
276          AOF( m_aaiCodedScale [ uiBaseViewIndex ][ uiViewIndex ] == pcSlice->getCodedScale    () [ uiBaseViewIndex ] );
277          AOF( m_aaiCodedOffset[ uiBaseViewIndex ][ uiViewIndex ] == pcSlice->getCodedOffset   () [ uiBaseViewIndex ] );
278        }
279        else
280        {       
281          m_receivedIdc   [ uiBaseViewIndex ][ uiViewIndex ]  = 1; 
282          m_aaiCodedScale [ uiBaseViewIndex ][ uiViewIndex ]  = pcSlice->getCodedScale    () [ uiBaseViewIndex ];
283          m_aaiCodedOffset[ uiBaseViewIndex ][ uiViewIndex ]  = pcSlice->getCodedOffset   () [ uiBaseViewIndex ];
284          xInitLUTs( uiBaseViewIndex, uiViewIndex, m_aaiCodedScale[ uiBaseViewIndex ][ uiViewIndex ], m_aaiCodedOffset[ uiBaseViewIndex ][ uiViewIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT);
285        }
286      }
287    }
288  }
289}
290
291
[773]292#if H_3D_IV_MERGE
[724]293Void
294CamParsCollector::copyCamParamForSlice( TComSlice* pcSlice )
295{
296  if( m_bCamParsVaryOverTime )
297  {
298    pcSlice->setCamparaSlice( m_aaiCodedScale, m_aaiCodedOffset );
299  }
300}
301#endif
302
[2]303
304Void
305CamParsCollector::xOutput( Int iPOC )
306{
307  if( m_pCodedScaleOffsetFile )
308  {
[872]309    if( iPOC == m_firstReceivedPoc )
[2]310    {
[608]311      fprintf( m_pCodedScaleOffsetFile, "#  ViewIndex       ViewId\n" );
[2]312      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------\n" );
[608]313      for( UInt uiViewIndex = 0; uiViewIndex <= m_uiMaxViewIndex; uiViewIndex++ )
[2]314      {
[872]315        fprintf( m_pCodedScaleOffsetFile, "%12d %12d\n", uiViewIndex, m_vps->getViewIdVal( uiViewIndex ) );
[2]316      }
317      fprintf( m_pCodedScaleOffsetFile, "\n\n");
318      fprintf( m_pCodedScaleOffsetFile, "# StartFrame     EndFrame   TargetView     BaseView   CodedScale  CodedOffset    Precision\n" );
319      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------ ------------ ------------ ------------ ------------ ------------\n" );
320    }
[872]321    if( iPOC == m_firstReceivedPoc || m_bCamParsVaryOverTime  )
[2]322    {
323      Int iS = iPOC;
324      Int iE = ( m_bCamParsVaryOverTime ? iPOC : ~( 1 << 31 ) );
[608]325      for( UInt uiViewIndex = 0; uiViewIndex <= m_uiMaxViewIndex; uiViewIndex++ )
[2]326      {
[608]327        for( UInt uiBaseIndex = 0; uiBaseIndex <= m_uiMaxViewIndex; uiBaseIndex++ )
[2]328        {
[608]329          if( uiViewIndex != uiBaseIndex )
[2]330          {
[872]331            if ( m_receivedIdc[uiBaseIndex][uiViewIndex] != 0 )
332            {           
333              fprintf( m_pCodedScaleOffsetFile, "%12d %12d %12d %12d %12d %12d %12d\n",
334                iS, iE, uiViewIndex, uiBaseIndex, m_aaiCodedScale[ uiBaseIndex ][ uiViewIndex ], m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ], m_vps->getCamParPrecision() );
335            }           
[2]336          }
337        }
338      }
339    }
340  }
341}
[608]342#endif
[2]343TDecTop::TDecTop()
344{
[56]345  m_pcPic = 0;
[2]346  m_iMaxRefPicNum = 0;
347#if ENC_DEC_TRACE
[608]348#if H_MV
349  if ( g_hTrace == NULL )
350  {
351#endif
352  g_hTrace = fopen( "TraceDec.txt", "wb" );
[2]353  g_bJustDoIt = g_bEncDecTraceDisable;
354  g_nSymbolCounter = 0;
[608]355#if H_MV
356  }
[2]357#endif
[608]358#endif
[655]359  m_associatedIRAPType = NAL_UNIT_INVALID;
[56]360  m_pocCRA = 0;
[608]361  m_pocRandomAccess = MAX_INT; 
[56]362  m_prevPOC                = MAX_INT;
[2]363  m_bFirstSliceInPicture    = true;
364  m_bFirstSliceInSequence   = true;
[655]365  m_prevSliceSkipped = false;
366  m_skippedPOC = 0;
[964]367#if SETTING_NO_OUT_PIC_PRIOR
368  m_bFirstSliceInBitstream  = true;
369  m_lastPOCNoOutputPriorPics = -1;
370  m_craNoRaslOutputFlag = false;
371  m_isNoOutputPriorPics = false;
372#endif
[973]373#if H_MV
[964]374  m_isLastNALWasEos = false;
[608]375  m_layerId = 0;
376  m_viewId = 0;
377#if H_3D
378  m_viewIndex = 0; 
379  m_isDepth = false;
[57]380  m_pcCamParsCollector = 0;
[210]381#endif
[973]382#if H_MV
[964]383  m_targetOptLayerSetIdx = -1; 
[608]384#endif
[964]385#endif
[2]386}
387
388TDecTop::~TDecTop()
389{
390#if ENC_DEC_TRACE
[608]391  fclose( g_hTrace );
[2]392#endif
393}
394
395Void TDecTop::create()
396{
397  m_cGopDecoder.create();
398  m_apcSlicePilot = new TComSlice;
[608]399  m_uiSliceIdx = 0;
[2]400}
401
402Void TDecTop::destroy()
403{
404  m_cGopDecoder.destroy();
[56]405 
[2]406  delete m_apcSlicePilot;
407  m_apcSlicePilot = NULL;
[56]408 
[2]409  m_cSliceDecoder.destroy();
410}
411
[608]412Void TDecTop::init()
[2]413{
414  // initialize ROM
[608]415#if !H_MV
[56]416  initROM();
[5]417#endif
[608]418  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO );
[2]419  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
420  m_cEntropyDecoder.init(&m_cPrediction);
421}
422
423Void TDecTop::deletePicBuffer ( )
424{
425  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
426  Int iSize = Int( m_cListPic.size() );
[56]427 
[2]428  for (Int i = 0; i < iSize; i++ )
429  {
[608]430    TComPic* pcPic = *(iterPic++);
431#if H_MV
432    if( pcPic )
[56]433    {
[608]434#endif
435    pcPic->destroy();
[56]436   
[608]437    delete pcPic;
438    pcPic = NULL;
439#if H_MV
[56]440    }
[608]441#endif
[2]442  }
[56]443 
[2]444  m_cSAO.destroy();
[56]445 
[2]446  m_cLoopFilter.        destroy();
[56]447 
[608]448#if !H_MV
[2]449  // destroy ROM
[608]450  destroyROM();
451#endif
[2]452}
453
[608]454Void TDecTop::xGetNewPicBuffer ( TComSlice* pcSlice, TComPic*& rpcPic )
[56]455{
[608]456  Int  numReorderPics[MAX_TLAYER];
457  Window &conformanceWindow = pcSlice->getSPS()->getConformanceWindow();
458  Window defaultDisplayWindow = pcSlice->getSPS()->getVuiParametersPresentFlag() ? pcSlice->getSPS()->getVuiParameters()->getDefaultDisplayWindow() : Window();
[56]459
[622]460#if H_MV
461    assert( conformanceWindow   .getScaledFlag() ); 
462    assert( defaultDisplayWindow.getScaledFlag() );
463#endif
[608]464  for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++) 
[56]465  {
[884]466#if H_MV
[872]467    numReorderPics[temporalLayer] = ( getLayerId() == 0 ) ? pcSlice->getSPS()->getNumReorderPics(temporalLayer) : pcSlice->getVPS()->getNumReorderPics(temporalLayer);
468#else
[608]469    numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer);
[872]470#endif
[56]471  }
[884]472#if H_MV
[872]473  if ( getLayerId() == 0 )
474  { 
475    m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer());
476  }
477  else
478  {
479    m_iMaxRefPicNum = pcSlice->getVPS()->getMaxDecPicBuffering(pcSlice->getTLayer());
480#if H_MV_HLS7_GEN
481    TComVPS* vps         = pcSlice->getVPS();
482    TComDpbSize* dpbSize = vps->getDpbSize(); 
[964]483    Int lsIdx            = vps->olsIdxToLsIdx( getTargetOutputLayerSetIdx()); // Is this correct, seems to be missing in spec?
[872]484    Int layerIdx         = vps->getIdxInLayerSet     ( lsIdx, getLayerId() ); 
485    Int subDpbIdx        = dpbSize->getSubDpbAssigned( lsIdx, layerIdx ); 
486    m_iMaxRefPicNum      = dpbSize->getMaxVpsDecPicBufferingMinus1(getTargetOutputLayerSetIdx(), subDpbIdx , vps->getSubLayersVpsMaxMinus1( vps->getLayerIdInVps( getLayerId() ) ) + 1 ) + 1 ; 
487#endif   
488  }
489#else
[608]490  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
[872]491#endif
[2]492  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
493  {
[56]494    rpcPic = new TComPic();
495   
[608]496    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
497                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
[2]498    m_cListPic.pushBack( rpcPic );
[56]499   
[2]500    return;
501  }
[56]502 
[2]503  Bool bBufferIsAvailable = false;
504  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
505  while (iterPic != m_cListPic.end())
506  {
507    rpcPic = *(iterPic++);
[56]508    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
[2]509    {
[56]510      rpcPic->setOutputMark(false);
[973]511#if H_MV
[964]512      rpcPic->setPicOutputFlag(false); 
513#endif
[2]514      bBufferIsAvailable = true;
515      break;
516    }
[56]517
518    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
519    {
520      rpcPic->setOutputMark(false);
[973]521#if H_MV
[964]522      rpcPic->setPicOutputFlag(false); 
523#endif
[56]524      rpcPic->setReconMark( false );
525      rpcPic->getPicYuvRec()->setBorderExtension( false );
526      bBufferIsAvailable = true;
527      break;
528    }
[2]529  }
[56]530 
[2]531  if ( !bBufferIsAvailable )
532  {
[56]533    //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer.
534    m_iMaxRefPicNum++;
535    rpcPic = new TComPic();
536    m_cListPic.pushBack( rpcPic );
[2]537  }
[608]538  rpcPic->destroy();
539  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
540                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
[2]541}
542
[608]543#if H_MV
544Void TDecTop::endPicDecoding(Int& poc, TComList<TComPic*>*& rpcListPic, std::vector<Int>& targetDecLayerIdSet )
545#else
546Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic)
547#endif
[56]548{
549  if (!m_pcPic)
550  {
551    /* nothing to deblock */
552    return;
553  }
554 
555  TComPic*&   pcPic         = m_pcPic;
[2]556
[608]557  // Execute Deblock + Cleanup
[56]558
[608]559  m_cGopDecoder.filterPicture(pcPic);
[56]560
561  TComSlice::sortPicList( m_cListPic ); // sorting for application output
[608]562  poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
[56]563  rpcListPic          = &m_cListPic; 
564  m_cCuDecoder.destroy();       
[608]565#if H_MV
[622]566  TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
[608]567  TComSlice::markCurrPic( pcPic ); 
568#endif
[56]569  m_bFirstSliceInPicture  = true;
570
571  return;
572}
573
[964]574#if SETTING_NO_OUT_PIC_PRIOR
575Void TDecTop::checkNoOutputPriorPics (TComList<TComPic*>*& rpcListPic)
576{
577  if (!rpcListPic || !m_isNoOutputPriorPics) return;
578
579  TComList<TComPic*>::iterator  iterPic   = rpcListPic->begin();
580
581  while (iterPic != rpcListPic->end())
582  {
583    TComPic*& pcPicTmp = *(iterPic++);
584    if (m_lastPOCNoOutputPriorPics != pcPicTmp->getPOC())
585    {
586      pcPicTmp->setOutputMark(false);
[973]587#if H_MV
[964]588      pcPicTmp->setPicOutputFlag(false); 
589#endif
590    }
591  }
592}
593#endif
594
[56]595Void TDecTop::xCreateLostPicture(Int iLostPoc) 
[2]596{
[56]597  printf("\ninserting lost poc : %d\n",iLostPoc);
598  TComSlice cFillSlice;
599  cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
600  cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
601  cFillSlice.initSlice();
602  TComPic *cFillPic;
603  xGetNewPicBuffer(&cFillSlice,cFillPic);
604  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
605  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
606  cFillPic->getSlice(0)->initSlice();
607 
608  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
609  Int closestPoc = 1000000;
610  while ( iterPic != m_cListPic.end())
[2]611  {
[56]612    TComPic * rpcPic = *(iterPic++);
613    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]614    {
[56]615      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
616    }
617  }
618  iterPic = m_cListPic.begin();
619  while ( iterPic != m_cListPic.end())
620  {
621    TComPic *rpcPic = *(iterPic++);
622    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
623    {
624      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
625      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
[2]626      break;
627    }
628  }
[56]629  cFillPic->setCurrSliceIdx(0);
630  for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) 
[2]631  {
[56]632    cFillPic->getCU(i)->initCU(cFillPic,i);
[2]633  }
[56]634  cFillPic->getSlice(0)->setReferenced(true);
635  cFillPic->getSlice(0)->setPOC(iLostPoc);
636  cFillPic->setReconMark(true);
637  cFillPic->setOutputMark(true);
638  if(m_pocRandomAccess == MAX_INT)
639  {
640    m_pocRandomAccess = iLostPoc;
641  }
[2]642}
643
[56]644
645Void TDecTop::xActivateParameterSets()
[2]646{
[56]647  m_parameterSetManagerDecoder.applyPrefetchedPS();
[608]648 
[56]649  TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
650  assert (pps != 0);
651
652  TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId());
653  assert (sps != 0);
[608]654
[622]655#if H_MV
656  TComVPS* vps = m_parameterSetManagerDecoder.getVPS(sps->getVPSId());
657  assert (vps != 0); 
[964]658  if (!m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP(), m_layerId ) )
[622]659#else
[608]660  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
[622]661#endif
[608]662  {
663    printf ("Parameter set activation failed!");
664    assert (0);
665  }
666
[973]667#if H_MV
[964]668  sps->inferSpsMaxDecPicBufferingMinus1( vps, m_targetOptLayerSetIdx, getLayerId(), false ); 
669  vps->inferDbpSizeLayerSetZero( sps, false ); 
670  // When the value of vps_num_rep_formats_minus1 in the active VPS is equal to 0
671  if ( vps->getVpsNumRepFormatsMinus1() == 0 )
672  {
673    //, it is a requirement of bitstream conformance that the value of update_rep_format_flag shall be equal to 0.
674    assert( sps->getUpdateRepFormatFlag() == false ); 
675  }
676  sps->checkRpsMaxNumPics( vps, getLayerId() ); 
677  if( m_layerId > 0 )
678  {
679    sps->setTemporalIdNestingFlag( (sps->getMaxTLayers() > 1) ? vps->getTemporalNestingFlag() : true );
680  }
681#endif
682
[608]683  if( pps->getDependentSliceSegmentsEnabledFlag() )
684  {
685    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
686
687    if (m_cSliceDecoder.getCtxMemSize() != NumCtx)
688    {
689      m_cSliceDecoder.initCtxMem(NumCtx);
690      for ( UInt st = 0; st < NumCtx; st++ )
691      {
692        TDecSbac* ctx = NULL;
693        ctx = new TDecSbac;
694        ctx->init( &m_cBinCABAC );
695        m_cSliceDecoder.setCtxMem( ctx, st );
696      }
697    }
698  }
699
[56]700  m_apcSlicePilot->setPPS(pps);
701  m_apcSlicePilot->setSPS(sps);
[608]702#if H_MV
[622]703  m_apcSlicePilot->setVPS(vps); 
[738]704  // The nuh_layer_id value of the NAL unit containing the PPS that is activated for a layer layerA with nuh_layer_id equal to nuhLayerIdA shall be equal to 0, or nuhLayerIdA, or the nuh_layer_id of a direct or indirect reference layer of layerA.
705  assert( pps->getLayerId() == m_layerId || pps->getLayerId( ) == 0 || vps->getInDirectDependencyFlag( m_layerId, pps->getLayerId() ) );   
706  // The nuh_layer_id value of the NAL unit containing the SPS that is activated for a layer layerA with nuh_layer_id equal to nuhLayerIdA shall be equal to 0, or nuhLayerIdA, or the nuh_layer_id of a direct or indirect reference layer of layerA.
707  assert( sps->getLayerId() == m_layerId || sps->getLayerId( ) == 0 || vps->getInDirectDependencyFlag( m_layerId, sps->getLayerId() ) );
[622]708  sps->inferRepFormat  ( vps , m_layerId ); 
709  sps->inferScalingList( m_parameterSetManagerDecoder.getActiveSPS( sps->getSpsScalingListRefLayerId() ) ); 
[210]710#endif
[56]711  pps->setSPS(sps);
[608]712  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
[56]713  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
714
[608]715  g_bitDepthY     = sps->getBitDepthY();
716  g_bitDepthC     = sps->getBitDepthC();
717  g_uiMaxCUWidth  = sps->getMaxCUWidth();
718  g_uiMaxCUHeight = sps->getMaxCUHeight();
719  g_uiMaxCUDepth  = sps->getMaxCUDepth();
720  g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() );
721
722  for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++)
[2]723  {
[56]724    sps->setAMPAcc( i, sps->getUseAMP() );
[2]725  }
[56]726
[608]727  for (Int i = sps->getLog2DiffMaxMinCodingBlockSize(); i < sps->getMaxCUDepth(); i++)
[56]728  {
729    sps->setAMPAcc( i, 0 );
730  }
731
[608]732  m_cSAO.destroy();
[872]733  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() );
[608]734  m_cLoopFilter.create( sps->getMaxCUDepth() );
[2]735}
[56]736
[608]737#if H_MV
[738]738Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool newLayerFlag, Bool& sliceSkippedFlag  )
[608]739{
740  assert( nalu.m_layerId == m_layerId ); 
741#else
[56]742Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
[2]743{
[608]744#endif
[2]745  TComPic*&   pcPic         = m_pcPic;
[56]746  m_apcSlicePilot->initSlice();
[2]747
[56]748  if (m_bFirstSliceInPicture)
[2]749  {
[56]750    m_uiSliceIdx     = 0;
[2]751  }
[872]752  else
[56]753  {
754    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
755  }
[872]756  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
[2]757
[56]758  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
[608]759  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
760                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
761                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
762                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
763                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
764  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
765 
766  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
[56]767  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
[42]768
[608]769#if H_MV
[622]770  m_apcSlicePilot->setRefPicSetInterLayer( & m_refPicSetInterLayer0, &m_refPicSetInterLayer1 ); 
[608]771  m_apcSlicePilot->setLayerId( nalu.m_layerId );
[964]772  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder, m_targetOptLayerSetIdx );
773#endif
[655]774  // set POC for dependent slices in skipped pictures
775  if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped) 
776  {
777    m_apcSlicePilot->setPOC(m_skippedPOC);
778  }
779
780  m_apcSlicePilot->setAssociatedIRAPPOC(m_pocCRA);
781  m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType);
782
[608]783#if H_MV 
784  TComVPS* vps     = m_apcSlicePilot->getVPS();
[622]785  Int layerId  = nalu.m_layerId;   
786  setViewId   ( vps->getViewId   ( layerId )      ); 
787#if H_3D
788  setViewIndex( vps->getViewIndex( layerId )      ); 
789  setIsDepth  ( vps->getDepthId  ( layerId ) == 1 ); 
790  m_ivPicLists->setVPS( vps ); 
791#endif
[608]792#endif
[738]793
[964]794#if SETTING_NO_OUT_PIC_PRIOR
795  //For inference of NoOutputOfPriorPicsFlag
796  if (m_apcSlicePilot->getRapPicFlag())
797  {
798    if ((m_apcSlicePilot->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_apcSlicePilot->getNalUnitType() <= NAL_UNIT_CODED_SLICE_IDR_N_LP) || 
799        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_bFirstSliceInSequence) ||
800        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getHandleCraAsBlaFlag()))
801    {
802      m_apcSlicePilot->setNoRaslOutputFlag(true);
803    }
804    //the inference for NoOutputPriorPicsFlag
805    if (!m_bFirstSliceInBitstream && m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag())
806    {
807      if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
808      {
809        m_apcSlicePilot->setNoOutputPriorPicsFlag(true);
810      }
811    }
812    else
813    {
814      m_apcSlicePilot->setNoOutputPriorPicsFlag(false);
815    }
816
817    if(m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
818    {
819      m_craNoRaslOutputFlag = m_apcSlicePilot->getNoRaslOutputFlag();
820    }
821  }
822  if (m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoOutputPriorPicsFlag())
823  {
824    m_lastPOCNoOutputPriorPics = m_apcSlicePilot->getPOC();
825    m_isNoOutputPriorPics = true;
826  }
827  else
828  {
829    m_isNoOutputPriorPics = false;
830  }
831
832  //For inference of PicOutputFlag
833  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R)
834  {
835    if ( m_craNoRaslOutputFlag )
836    {
837      m_apcSlicePilot->setPicOutputFlag(false);
838    }
839  }
840#endif
841
842#if FIX_POC_CRA_NORASL_OUTPUT
843  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_craNoRaslOutputFlag) //Reset POC MSB when CRA has NoRaslOutputFlag equal to 1
844  {
845    Int iMaxPOClsb = 1 << m_apcSlicePilot->getSPS()->getBitsForPOC();
846    m_apcSlicePilot->setPOC( m_apcSlicePilot->getPOC() & (iMaxPOClsb - 1) );
847  }
848#endif
[773]849#if H_MV
[738]850    xCeckNoClrasOutput();
851#endif
[608]852    // Skip pictures due to random access
853    if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
[56]854    {
[655]855    m_prevSliceSkipped = true;
856    m_skippedPOC = m_apcSlicePilot->getPOC();
[773]857#if H_MV
858    sliceSkippedFlag = true; 
[738]859#endif
[608]860      return false;
[56]861    }
[608]862    // Skip TFD pictures associated with BLA/BLANT pictures
863    if (isSkipPictureForBLA(iPOCLastDisplay))
864    {
[655]865    m_prevSliceSkipped = true;
866    m_skippedPOC = m_apcSlicePilot->getPOC();
[773]867#if H_MV
868    sliceSkippedFlag = true; 
[738]869#endif
[608]870      return false;
871    }
872
[655]873  // clear previous slice skipped flag
874  m_prevSliceSkipped = false;
875
[608]876  //we should only get a different poc for a new picture (with CTU address==0)
[964]877  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (m_apcSlicePilot->getSliceCurStartCUAddr()!=0))
[608]878  {
879    printf ("Warning, the first slice of a picture might have been lost!\n");
[56]880  }
881  // exit when a new picture is found
[608]882  if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence )
[56]883  {
884    if (m_prevPOC >= m_pocRandomAccess)
885    {
886      m_prevPOC = m_apcSlicePilot->getPOC();
887      return true;
888    }
889    m_prevPOC = m_apcSlicePilot->getPOC();
890  }
[608]891#if H_MV
892  if ( newLayerFlag )
893  {
894    return false; 
895  }
896#if ENC_DEC_TRACE
897#if H_MV_ENC_DEC_TRAC
898  // parse remainder of SH
899   g_disableHLSTrace = false; 
900#endif
901#endif
902#endif
[56]903  // actual decoding starts here
[622]904#if H_MV
905   // This part needs further testing !
906   if ( m_apcSlicePilot->getPocResetFlag() )
907   {   
908     xResetPocInPicBuffer();
909   }
910#endif
[56]911  xActivateParameterSets();
912
913  if (m_apcSlicePilot->isNextSlice()) 
914  {
915    m_prevPOC = m_apcSlicePilot->getPOC();
916  }
917  m_bFirstSliceInSequence = false;
[964]918#if SETTING_NO_OUT_PIC_PRIOR 
919  m_bFirstSliceInBitstream  = false;
920#endif
[56]921  //detect lost reference picture and insert copy of earlier frame.
[608]922  Int lostPoc;
923  while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
[56]924  {
[608]925    xCreateLostPicture(lostPoc-1);
[56]926  }
[2]927  if (m_bFirstSliceInPicture)
928  {
[56]929    // Buffer initialize for prediction.
930    m_cPrediction.initTempBuff();
931    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
[608]932#if H_MV
[622]933    m_apcSlicePilot->createInterLayerReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
[608]934#endif
[56]935    //  Get a new picture buffer
936    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
[2]937
[655]938    Bool isField = false;
939    Bool isTff = false;
940   
941    if(!m_SEIs.empty())
942    {
943      // Check if any new Picture Timing SEI has arrived
944      SEIMessages pictureTimingSEIs = extractSeisByType (m_SEIs, SEI::PICTURE_TIMING);
945      if (pictureTimingSEIs.size()>0)
946      {
947        SEIPictureTiming* pictureTiming = (SEIPictureTiming*) *(pictureTimingSEIs.begin());
948        isField = (pictureTiming->m_picStruct == 1) || (pictureTiming->m_picStruct == 2);
949        isTff =  (pictureTiming->m_picStruct == 1);
950      }
951    }
952   
953    //Set Field/Frame coding mode
954    m_pcPic->setField(isField);
955    m_pcPic->setTopField(isTff);
956   
[608]957    // transfer any SEI messages that have been received to the picture
[56]958    pcPic->setSEIs(m_SEIs);
[608]959    m_SEIs.clear();
[42]960
[56]961    // Recursive structure
962    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
963    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
964    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
[42]965
[608]966    m_cSliceDecoder.create();
967  }
968  else
969  {
970    // Check if any new SEI has arrived
971    if(!m_SEIs.empty())
[56]972    {
[608]973      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
974      SEIMessages &picSEI = pcPic->getSEIs();
975      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
976      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
977      deleteSEIs(m_SEIs);
[56]978    }
979  }
[608]980 
[56]981  //  Set picture slice pointer
982  TComSlice*  pcSlice = m_apcSlicePilot;
983  Bool bNextSlice     = pcSlice->isNextSlice();
[2]984
[56]985  UInt uiCummulativeTileWidth;
986  UInt uiCummulativeTileHeight;
987  UInt i, j, p;
988
[608]989  //set NumColumnsMins1 and NumRowsMinus1
990  pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
991  pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
[2]992
[608]993  //create the TComTileArray
994  pcPic->getPicSym()->xCreateTComTileArray();
995
996  if( pcSlice->getPPS()->getUniformSpacingFlag() )
[56]997  {
[608]998    //set the width for each tile
999    for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
[56]1000    {
[608]1001      for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
[2]1002      {
[608]1003        pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
1004          setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
1005          - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
[2]1006      }
[608]1007    }
[2]1008
[608]1009    //set the height for each tile
1010    for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
[2]1011    {
[608]1012      for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
[2]1013      {
[608]1014        pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
1015          setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
1016          - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
[2]1017      }
[56]1018    }
1019  }
1020  else
1021  {
[608]1022    //set the width for each tile
1023    for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
[56]1024    {
[608]1025      uiCummulativeTileWidth = 0;
1026      for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
[2]1027      {
[608]1028        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
1029        uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
[2]1030      }
[608]1031      pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
1032    }
[56]1033
[608]1034    //set the height for each tile
1035    for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
[56]1036    {
[608]1037      uiCummulativeTileHeight = 0;
1038      for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
1039      { 
1040        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
1041        uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
[56]1042      }
[608]1043      pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
[56]1044    }
1045  }
[2]1046
[56]1047  pcPic->getPicSym()->xInitTiles();
[2]1048
[56]1049  //generate the Coding Order Map and Inverse Coding Order Map
1050  UInt uiEncCUAddr;
1051  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
1052  {
1053    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
1054    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
1055  }
1056  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
1057  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
1058
[608]1059  //convert the start and end CU addresses of the slice and dependent slice into encoding order
1060  pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) );
1061  pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) );
[56]1062  if(pcSlice->isNextSlice())
1063  {
1064    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
1065    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
1066  }
1067
1068  if (m_bFirstSliceInPicture) 
1069  {
1070    if(pcPic->getNumAllocatedSlice() != 1)
1071    {
1072      pcPic->clearSliceBuffer();
1073    }
1074  }
1075  else
1076  {
1077    pcPic->allocateNewSlice();
1078  }
1079  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
1080  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
1081  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
1082
1083  pcPic->setTLayer(nalu.m_temporalId);
1084
[608]1085#if H_MV
1086  pcPic->setLayerId( nalu.m_layerId );
1087  pcPic->setViewId ( getViewId() );
1088#if H_3D
1089  pcPic->setViewIndex( getViewIndex() );
1090  pcPic->setIsDepth  ( getIsDepth  () );
1091#endif
1092#endif
[56]1093  if (bNextSlice)
1094  {
[655]1095    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_associatedIRAPType, m_cListPic );
[608]1096    // Set reference list
1097#if H_MV   
[622]1098    std::vector< TComPic* > tempRefPicLists[2];
1099    std::vector< Bool     > usedAsLongTerm [2];
1100    Int       numPocTotalCurr;
1101
1102    pcSlice->getTempRefPicLists( m_cListPic, m_refPicSetInterLayer0, m_refPicSetInterLayer1, tempRefPicLists, usedAsLongTerm, numPocTotalCurr);
1103    pcSlice->setRefPicList     ( tempRefPicLists, usedAsLongTerm, numPocTotalCurr, true ); 
[608]1104#if H_3D_ARP
[724]1105    pcSlice->setARPStepNum(m_ivPicLists);
[608]1106    if( pcSlice->getARPStepNum() > 1 )
[56]1107    {
[622]1108      // GT: This seems to be broken, not all nuh_layer_ids are necessarily present
[608]1109      for(Int iLayerId = 0; iLayerId < nalu.m_layerId; iLayerId ++ )
1110      {
1111        Int  iViewIdx =   pcSlice->getVPS()->getViewIndex(iLayerId);
1112        Bool bIsDepth = ( pcSlice->getVPS()->getDepthId  ( iLayerId ) == 1 );
1113        if( iViewIdx<getViewIndex() && !bIsDepth )
1114        {
1115          pcSlice->setBaseViewRefPicList( m_ivPicLists->getPicList( iLayerId ), iViewIdx );
1116        }
1117      }
[56]1118    }
[77]1119#endif
1120#else
[608]1121    pcSlice->setRefPicList( m_cListPic, true );
[21]1122#endif
1123
[608]1124#if H_3D
1125    pcSlice->setIvPicLists( m_ivPicLists );         
[655]1126#if H_3D_IV_MERGE
1127#if H_3D_FCO
1128    //assert( !getIsDepth() );
1129#else
[608]1130    assert( !getIsDepth() || ( pcSlice->getTexturePic() != 0 ) );
[655]1131#endif
[608]1132#endif   
[210]1133#endif
[56]1134    // For generalized B
1135    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
1136    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
1137    {
1138      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
1139      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
[2]1140
[56]1141      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
1142      {
1143        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
1144      }
1145    }
[608]1146    if (!pcSlice->isIntra())
[56]1147    {
1148      Bool bLowDelay = true;
1149      Int  iCurrPOC  = pcSlice->getPOC();
1150      Int iRefIdx = 0;
1151
1152      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
1153      {
1154        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
[21]1155        {
[56]1156          bLowDelay = false;
[21]1157        }
[2]1158      }
[608]1159      if (pcSlice->isInterB())
[56]1160      {
[608]1161        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
[56]1162        {
[608]1163          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
1164          {
1165            bLowDelay = false;
1166          }
1167        }       
[56]1168      }
[2]1169
[56]1170      pcSlice->setCheckLDC(bLowDelay);           
1171    }
1172
1173    //---------------
[608]1174    pcSlice->setRefPOCList();
1175#if  H_3D_TMVP
1176    if(pcSlice->getLayerId())
1177      pcSlice->generateAlterRefforTMVP();
[313]1178#endif
[56]1179  }
1180
1181  pcPic->setCurrSliceIdx(m_uiSliceIdx);
1182  if(pcSlice->getSPS()->getScalingListFlag())
1183  {
[608]1184    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
1185    if(pcSlice->getPPS()->getScalingListPresentFlag())
[56]1186    {
[608]1187      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
[56]1188    }
[608]1189    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
1190    {
1191      pcSlice->setDefaultScalingList();
1192    }
1193    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
[56]1194    m_cTrQuant.setUseScalingList(true);
1195  }
1196  else
1197  {
1198    m_cTrQuant.setFlatScalingList();
1199    m_cTrQuant.setUseScalingList(false);
1200  }
[2]1201
[773]1202#if H_3D_IV_MERGE
[724]1203  if( pcSlice->getIsDepth() && m_pcCamParsCollector )
1204  {
1205    m_pcCamParsCollector->copyCamParamForSlice( pcSlice );
1206  }
1207#endif
1208
[56]1209  //  Decode a picture
[608]1210  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
1211#if H_3D
[57]1212  if( m_pcCamParsCollector )
1213  {
1214    m_pcCamParsCollector->setSlice( pcSlice );
1215  }
[758]1216#endif
[56]1217  m_bFirstSliceInPicture = false;
1218  m_uiSliceIdx++;
1219
1220  return false;
1221}
1222
[77]1223Void TDecTop::xDecodeVPS()
1224{
1225  TComVPS* vps = new TComVPS();
1226 
1227  m_cEntropyDecoder.decodeVPS( vps );
1228  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
1229}
[56]1230
1231Void TDecTop::xDecodeSPS()
1232{
1233  TComSPS* sps = new TComSPS();
[608]1234#if H_MV
1235  sps->setLayerId( getLayerId() ); 
1236#endif
1237#if H_3D
[964]1238  // Preliminary fix. assuming that all sps refer to the same VPS.
[608]1239  // Parsing dependency should be resolved!
1240  TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 ); 
[964]1241  assert( vps != 0 );
[622]1242  m_cEntropyDecoder.decodeSPS( sps, vps->getViewIndex( m_layerId ), ( vps->getDepthId( m_layerId ) == 1 ) );
1243#else
[56]1244  m_cEntropyDecoder.decodeSPS( sps );
[42]1245#endif
[56]1246  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
1247}
[2]1248
[56]1249Void TDecTop::xDecodePPS()
1250{
1251  TComPPS* pps = new TComPPS();
[622]1252#if H_MV
1253  pps->setLayerId( getLayerId() ); 
1254#endif
[773]1255#if H_3D
[758]1256  // Assuming that all PPS indirectly refer to the same VPS via different SPS
1257  // There is no parsing dependency in decoding DLT in PPS.
1258  // The VPS information passed to decodePPS() is used to arrange the decoded DLT tables to their corresponding layers.
1259  // This is equivalent to the process of
1260  //   Step 1) decoding DLT tables based on the number of depth layers, and
1261  //   Step 2) mapping DLT tables to the depth layers
[773]1262  // as described in the 3D-HEVC WD.
[758]1263  TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 );
1264  m_cEntropyDecoder.decodePPS( pps, vps );
1265#else
[608]1266  m_cEntropyDecoder.decodePPS( pps );
[758]1267#endif
[56]1268  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
1269}
[2]1270
[608]1271Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
[56]1272{
[608]1273  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
1274  {
[622]1275#if H_MV
1276    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS( m_layerId ) );
1277#else
[608]1278    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
[622]1279#endif
[608]1280  }
1281  else
1282  {
[622]1283#if H_MV
1284    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS( m_layerId ) );
1285#else
[608]1286    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
[622]1287#endif
[608]1288    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
1289    if (activeParamSets.size()>0)
1290    {
1291      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
1292      m_parameterSetManagerDecoder.applyPrefetchedPS();
[964]1293      assert(seiAps->activeSeqParameterSetId.size()>0);
[622]1294#if H_MV
[964]1295      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParameterSetId[0], m_layerId ))
[622]1296#else
[964]1297      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParameterSetId[0] ))
[622]1298#endif
[608]1299      {
1300        printf ("Warning SPS activation with Active parameter set SEI failed");
1301      }
1302    }
1303  }
[56]1304}
[2]1305
[608]1306#if H_MV
[738]1307Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayerFlag, Bool& sliceSkippedFlag )
1308#else
[56]1309Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
[608]1310#endif
[56]1311{
1312  // Initialize entropy decoder
1313  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1314  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
[2]1315
[56]1316  switch (nalu.m_nalUnitType)
1317  {
[77]1318    case NAL_UNIT_VPS:
1319      xDecodeVPS();
[973]1320#if H_MV
[964]1321      m_isLastNALWasEos = false;
1322#endif
[77]1323      return false;
[608]1324     
[56]1325    case NAL_UNIT_SPS:
1326      xDecodeSPS();
1327      return false;
1328
1329    case NAL_UNIT_PPS:
1330      xDecodePPS();
1331      return false;
[608]1332     
1333    case NAL_UNIT_PREFIX_SEI:
1334    case NAL_UNIT_SUFFIX_SEI:
[973]1335#if H_MV
[964]1336      if ( nalu.m_nalUnitType == NAL_UNIT_SUFFIX_SEI )
1337      {
1338        assert( m_isLastNALWasEos == false );
1339      }
1340#endif
[608]1341      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
[56]1342      return false;
1343
[608]1344    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1345    case NAL_UNIT_CODED_SLICE_TRAIL_N:
[872]1346    case NAL_UNIT_CODED_SLICE_TSA_R:
[608]1347    case NAL_UNIT_CODED_SLICE_TSA_N:
1348    case NAL_UNIT_CODED_SLICE_STSA_R:
1349    case NAL_UNIT_CODED_SLICE_STSA_N:
1350    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
1351    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
1352    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1353    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
1354    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
[56]1355    case NAL_UNIT_CODED_SLICE_CRA:
[608]1356    case NAL_UNIT_CODED_SLICE_RADL_N:
1357    case NAL_UNIT_CODED_SLICE_RADL_R:
1358    case NAL_UNIT_CODED_SLICE_RASL_N:
1359    case NAL_UNIT_CODED_SLICE_RASL_R:
[973]1360#if H_MV
[964]1361      if (nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_N ||
1362          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_N ||
1363          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_N ||
1364          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
1365          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N )
1366      {
1367        assert( m_isLastNALWasEos == false );
1368      }
1369      else
1370      {
1371        m_isLastNALWasEos = false;
1372      }
[973]1373
[738]1374      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, newLayerFlag, sliceSkippedFlag );
1375#else
[56]1376      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
[608]1377#endif
[2]1378      break;
[872]1379    case NAL_UNIT_EOS:
[973]1380#if H_MV
[964]1381      assert( m_isLastNALWasEos == false );
1382      //Check layer id of the nalu. if it is not 0, give a warning message and just return without doing anything.
1383      if (nalu.m_layerId > 0)
1384      {
1385        printf( "\nThis bitstream has EOS with non-zero layer id.\n" );
1386        return false;
1387      }
1388      m_isLastNALWasEos = true;
1389#endif
[872]1390      m_associatedIRAPType = NAL_UNIT_INVALID;
1391      m_pocCRA = 0;
1392      m_pocRandomAccess = MAX_INT;
1393      m_prevPOC = MAX_INT;
1394      m_bFirstSliceInPicture = true;
1395      m_bFirstSliceInSequence = true;
1396      m_prevSliceSkipped = false;
1397      m_skippedPOC = 0;
1398      return false;
1399     
1400    case NAL_UNIT_ACCESS_UNIT_DELIMITER:
1401      // TODO: process AU delimiter
1402      return false;
1403     
1404    case NAL_UNIT_EOB:
1405      return false;
1406     
[964]1407    case NAL_UNIT_FILLER_DATA:
1408#if H_MV
1409      assert( m_isLastNALWasEos == false );
1410#endif
1411      return false;
[872]1412     
1413    case NAL_UNIT_RESERVED_VCL_N10:
1414    case NAL_UNIT_RESERVED_VCL_R11:
1415    case NAL_UNIT_RESERVED_VCL_N12:
1416    case NAL_UNIT_RESERVED_VCL_R13:
1417    case NAL_UNIT_RESERVED_VCL_N14:
1418    case NAL_UNIT_RESERVED_VCL_R15:
1419     
1420    case NAL_UNIT_RESERVED_IRAP_VCL22:
1421    case NAL_UNIT_RESERVED_IRAP_VCL23:
1422     
1423    case NAL_UNIT_RESERVED_VCL24:
1424    case NAL_UNIT_RESERVED_VCL25:
1425    case NAL_UNIT_RESERVED_VCL26:
1426    case NAL_UNIT_RESERVED_VCL27:
1427    case NAL_UNIT_RESERVED_VCL28:
1428    case NAL_UNIT_RESERVED_VCL29:
1429    case NAL_UNIT_RESERVED_VCL30:
1430    case NAL_UNIT_RESERVED_VCL31:
1431     
1432    case NAL_UNIT_RESERVED_NVCL41:
1433    case NAL_UNIT_RESERVED_NVCL42:
1434    case NAL_UNIT_RESERVED_NVCL43:
1435    case NAL_UNIT_RESERVED_NVCL44:
1436    case NAL_UNIT_RESERVED_NVCL45:
1437    case NAL_UNIT_RESERVED_NVCL46:
1438    case NAL_UNIT_RESERVED_NVCL47:
1439    case NAL_UNIT_UNSPECIFIED_48:
1440    case NAL_UNIT_UNSPECIFIED_49:
1441    case NAL_UNIT_UNSPECIFIED_50:
1442    case NAL_UNIT_UNSPECIFIED_51:
1443    case NAL_UNIT_UNSPECIFIED_52:
1444    case NAL_UNIT_UNSPECIFIED_53:
1445    case NAL_UNIT_UNSPECIFIED_54:
1446    case NAL_UNIT_UNSPECIFIED_55:
1447    case NAL_UNIT_UNSPECIFIED_56:
1448    case NAL_UNIT_UNSPECIFIED_57:
1449    case NAL_UNIT_UNSPECIFIED_58:
1450    case NAL_UNIT_UNSPECIFIED_59:
1451    case NAL_UNIT_UNSPECIFIED_60:
1452    case NAL_UNIT_UNSPECIFIED_61:
1453    case NAL_UNIT_UNSPECIFIED_62:
1454    case NAL_UNIT_UNSPECIFIED_63:
[2]1455    default:
[872]1456      assert (0);
[2]1457  }
1458
1459  return false;
1460}
1461
[608]1462/** Function for checking if picture should be skipped because of association with a previous BLA picture
1463 * \param iPOCLastDisplay POC of last picture displayed
1464 * \returns true if the picture should be skipped
1465 * This function skips all TFD pictures that follow a BLA picture
1466 * in decoding order and precede it in output order.
1467 */
1468Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
[210]1469{
[655]1470  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) && 
1471       m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
[608]1472  {
1473    iPOCLastDisplay++;
1474    return true;
1475  }
1476  return false;
[210]1477}
1478
[2]1479/** Function for checking if picture should be skipped because of random access
1480 * \param iSkipFrame skip frame counter
1481 * \param iPOCLastDisplay POC of last picture displayed
1482 * \returns true if the picture shold be skipped in the random access.
1483 * This function checks the skipping of pictures in the case of -s option random access.
1484 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1485 * It also checks the type of Nal unit type at the random access point.
[608]1486 * 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]1487 * If the random access point is IDR all pictures after the random access point are decoded.
[608]1488 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
1489 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
[2]1490 * access point there is no guarantee that the decoder will not crash.
1491 */
1492Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
1493{
[56]1494  if (iSkipFrame) 
[2]1495  {
1496    iSkipFrame--;   // decrement the counter
1497    return true;
1498  }
[773]1499#if H_MV
[738]1500  else if ( !m_layerInitilizedFlag[ m_layerId ] ) // start of random access point, m_pocRandomAccess has not been set yet.
1501#else
[56]1502  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
[738]1503#endif
[2]1504  {
[608]1505    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
1506        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1507        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1508        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
[2]1509    {
[738]1510
[773]1511#if H_MV
[738]1512      if ( xAllRefLayersInitilized() )
1513      {
1514        m_layerInitilizedFlag[ m_layerId ] = true; 
1515        m_pocRandomAccess = m_apcSlicePilot->getPOC();
1516      }
1517      else
1518      {
1519        return true; 
1520      }
1521#else
[608]1522      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
1523      m_pocRandomAccess = m_apcSlicePilot->getPOC();
[738]1524#endif
[2]1525    }
[608]1526    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
[2]1527    {
[773]1528#if H_MV
[738]1529      if ( xAllRefLayersInitilized() )
1530      {
1531        m_layerInitilizedFlag[ m_layerId ] = true; 
[773]1532        m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1533      }
1534      else 
1535      {
[738]1536        return true; 
1537      }
1538#else
1539      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1540#endif
1541    }
1542    else 
1543    {
[773]1544#if H_MV
[738]1545      static Bool warningMessage[MAX_NUM_LAYERS];
1546      static Bool warningInitFlag = false;
1547     
1548      if (!warningInitFlag)
1549      {
1550        for ( Int i = 0; i < MAX_NUM_LAYERS; i++)
1551        {
1552          warningMessage[i] = true; 
1553        }
1554        warningInitFlag = true; 
1555      }
1556
1557      if ( warningMessage[getLayerId()] )
1558      {
1559        printf("\nLayer%3d   No valid random access point. VCL NAL units of this layer are discarded until next layer initialization picture. ", getLayerId() ); 
1560        warningMessage[m_layerId] = false; 
1561      }
1562#else
[608]1563      static Bool warningMessage = false;
[56]1564      if(!warningMessage)
1565      {
1566        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1567        warningMessage = true;
1568      }
[738]1569#endif
[56]1570      return true;
[2]1571    }
1572  }
[608]1573  // skip the reordered pictures, if necessary
1574  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]1575  {
1576    iPOCLastDisplay++;
1577    return true;
1578  }
[773]1579#if H_MV
[738]1580  return !m_layerInitilizedFlag[ getLayerId() ]; 
1581#else
[2]1582  // if we reach here, then the picture is not skipped.
[56]1583  return false; 
[738]1584#endif
[2]1585}
[56]1586
[608]1587#if H_MV
1588TComPic* TDecTop::getPic( Int poc )
[56]1589{
[608]1590  xGetPic( m_layerId, poc ); 
1591  TComList<TComPic*>* listPic = getListPic();
1592  TComPic* pcPic = NULL;
1593  for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++)
1594  {
1595    if( (*it)->getPOC() == poc )
1596    {
1597      pcPic = *it ;
1598      break ;
1599    }
1600  }
1601  return pcPic;
[56]1602}
[2]1603
[608]1604TComPic* TDecTop::xGetPic( Int layerId, Int poc )
1605{ 
1606  return m_ivPicLists->getPic( layerId, poc ) ;
1607}
1608
[622]1609Void TDecTop::xResetPocInPicBuffer()
1610{
1611  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
1612  while (iterPic != m_cListPic.end())
1613  {
1614    TComPic* pic = *(iterPic++);
1615    if ( pic->getReconMark() )
1616    {
1617      for( Int i = 0; i < pic->getNumAllocatedSlice(); i++)
1618      {
1619        TComSlice* slice = pic->getSlice( i ); 
1620        slice->setPOC ( slice->getPOC() - m_apcSlicePilot->getPocBeforeReset() );           
1621      }         
1622    }     
1623  }
1624}
[738]1625
[773]1626#if H_MV
[738]1627Void TDecTop::xCeckNoClrasOutput()
1628{
1629  // This part needs further testing!
1630  if ( getLayerId() == 0 )
1631  {   
1632    NalUnitType nut = m_apcSlicePilot->getNalUnitType(); 
1633
1634    Bool isBLA =  ( nut == NAL_UNIT_CODED_SLICE_BLA_W_LP  )  || ( nut == NAL_UNIT_CODED_SLICE_BLA_N_LP ) || ( nut == NAL_UNIT_CODED_SLICE_BLA_W_RADL ); 
1635    Bool isIDR  = ( nut == NAL_UNIT_CODED_SLICE_IDR_W_RADL ) || ( nut == NAL_UNIT_CODED_SLICE_IDR_N_LP ); 
1636    Bool noClrasOutputFlag  = isBLA || ( isIDR  &&  m_apcSlicePilot->getCrossLayerBlaFlag() ); 
1637
1638    if ( noClrasOutputFlag ) 
1639    {
1640      for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++)
1641      {
1642        m_layerInitilizedFlag[i] = false; 
1643      } 
1644    }
1645  }
1646}
1647
1648Bool TDecTop::xAllRefLayersInitilized()
1649{
1650  Bool allRefLayersInitilizedFlag = true; 
1651  TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 ); 
1652  for (Int i = 0; i < vps->getNumDirectRefLayers( getLayerId()  ); i++ )
1653  {
1654    Int refLayerId = vps->getRefLayerId( m_layerId, i ); 
1655    allRefLayersInitilizedFlag = allRefLayersInitilizedFlag && m_layerInitilizedFlag[ refLayerId ]; 
1656  }
1657
1658  return allRefLayersInitilizedFlag;
1659}
[608]1660#endif
[738]1661#endif
[56]1662//! \}
Note: See TracBrowser for help on using the repository browser.