source: 3DVCSoftware/trunk/source/Lib/TLibDecoder/TDecTop.cpp @ 964

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