source: 3DVCSoftware/branches/HTM-12.0-dev1/source/Lib/TLibDecoder/TDecTop.cpp @ 1054

Last change on this file since 1054 was 1054, checked in by tech, 10 years ago

Integration of various MV-HEVC HLS changes.

  • Property svn:eol-style set to native
File size: 56.8 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 !LGE_FCO_I0116
232  if ( pcSlice->getIsDepth())
233  {
234    return;
235  }
236#endif
237
238  Int curPoc = pcSlice->getPOC();
239  if( m_firstReceivedPoc == -2 )
240  {
241    m_firstReceivedPoc = curPoc; 
242  }
243
244  Bool newPocFlag = ( m_lastPoc != curPoc ); 
245
246  if ( newPocFlag )
247  {   
248    if( m_lastPoc != -1 )
249    {
250      xOutput( m_lastPoc );
251    }
252
253    xResetReceivedIdc( false ); 
254    m_lastPoc = pcSlice->getPOC();
255  }
256
257  UInt uiViewIndex          = pcSlice->getViewIndex(); 
258  if( m_vps->getCamParPresent( uiViewIndex ) )
259  {   
260    if( m_vps->hasCamParInSliceHeader( uiViewIndex ) ) // check consistency of slice parameters here
261    {   
262      for( UInt uiBaseViewIndex = 0; uiBaseViewIndex < uiViewIndex; uiBaseViewIndex++ )
263      {       
264        if ( m_receivedIdc[ uiViewIndex ][ uiBaseViewIndex ] != 0 )
265        {     
266          AOF( m_aaiCodedScale [ uiViewIndex ][ uiBaseViewIndex ] == pcSlice->getInvCodedScale () [ uiBaseViewIndex ] );
267          AOF( m_aaiCodedOffset[ uiViewIndex ][ uiBaseViewIndex ] == pcSlice->getInvCodedOffset() [ uiBaseViewIndex ] );
268        }
269        else
270        {         
271          m_receivedIdc   [ uiViewIndex ][ uiBaseViewIndex ]  = 1; 
272          m_aaiCodedScale [ uiViewIndex ][ uiBaseViewIndex ]  = pcSlice->getInvCodedScale () [ uiBaseViewIndex ];
273          m_aaiCodedOffset[ uiViewIndex ][ uiBaseViewIndex ]  = pcSlice->getInvCodedOffset() [ uiBaseViewIndex ];
274          xInitLUTs( uiViewIndex, uiBaseViewIndex, m_aaiCodedScale[ uiViewIndex ][ uiBaseViewIndex ], m_aaiCodedOffset[ uiViewIndex ][ uiBaseViewIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT);
275        }
276        if ( m_receivedIdc[ uiBaseViewIndex ][ uiViewIndex ] != 0 )
277        {     
278          AOF( m_aaiCodedScale [ uiBaseViewIndex ][ uiViewIndex ] == pcSlice->getCodedScale    () [ uiBaseViewIndex ] );
279          AOF( m_aaiCodedOffset[ uiBaseViewIndex ][ uiViewIndex ] == pcSlice->getCodedOffset   () [ uiBaseViewIndex ] );
280        }
281        else
282        {       
283          m_receivedIdc   [ uiBaseViewIndex ][ uiViewIndex ]  = 1; 
284          m_aaiCodedScale [ uiBaseViewIndex ][ uiViewIndex ]  = pcSlice->getCodedScale    () [ uiBaseViewIndex ];
285          m_aaiCodedOffset[ uiBaseViewIndex ][ uiViewIndex ]  = pcSlice->getCodedOffset   () [ uiBaseViewIndex ];
286          xInitLUTs( uiBaseViewIndex, uiViewIndex, m_aaiCodedScale[ uiBaseViewIndex ][ uiViewIndex ], m_aaiCodedOffset[ uiBaseViewIndex ][ uiViewIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT);
287        }
288      }
289    }
290  }
291}
292
293
294#if H_3D_IV_MERGE
295Void
296CamParsCollector::copyCamParamForSlice( TComSlice* pcSlice )
297{
298  if( m_bCamParsVaryOverTime )
299  {
300    pcSlice->setCamparaSlice( m_aaiCodedScale, m_aaiCodedOffset );
301  }
302}
303#endif
304
305
306Void
307CamParsCollector::xOutput( Int iPOC )
308{
309  if( m_pCodedScaleOffsetFile )
310  {
311    if( iPOC == m_firstReceivedPoc )
312    {
313      fprintf( m_pCodedScaleOffsetFile, "#  ViewIndex       ViewId\n" );
314      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------\n" );
315      for( UInt uiViewIndex = 0; uiViewIndex <= m_uiMaxViewIndex; uiViewIndex++ )
316      {
317        fprintf( m_pCodedScaleOffsetFile, "%12d %12d\n", uiViewIndex, m_vps->getViewIdVal( uiViewIndex ) );
318      }
319      fprintf( m_pCodedScaleOffsetFile, "\n\n");
320      fprintf( m_pCodedScaleOffsetFile, "# StartFrame     EndFrame   TargetView     BaseView   CodedScale  CodedOffset    Precision\n" );
321      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------ ------------ ------------ ------------ ------------ ------------\n" );
322    }
323    if( iPOC == m_firstReceivedPoc || m_bCamParsVaryOverTime  )
324    {
325      Int iS = iPOC;
326      Int iE = ( m_bCamParsVaryOverTime ? iPOC : ~( 1 << 31 ) );
327      for( UInt uiViewIndex = 0; uiViewIndex <= m_uiMaxViewIndex; uiViewIndex++ )
328      {
329        for( UInt uiBaseIndex = 0; uiBaseIndex <= m_uiMaxViewIndex; uiBaseIndex++ )
330        {
331          if( uiViewIndex != uiBaseIndex )
332          {
333            if ( m_receivedIdc[uiBaseIndex][uiViewIndex] != 0 )
334            {           
335              fprintf( m_pCodedScaleOffsetFile, "%12d %12d %12d %12d %12d %12d %12d\n",
336                iS, iE, uiViewIndex, uiBaseIndex, m_aaiCodedScale[ uiBaseIndex ][ uiViewIndex ], m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ], m_vps->getCamParPrecision() );
337            }           
338          }
339        }
340      }
341    }
342  }
343}
344#endif
345TDecTop::TDecTop()
346{
347  m_pcPic = 0;
348  m_iMaxRefPicNum = 0;
349#if ENC_DEC_TRACE
350#if H_MV
351  if ( g_hTrace == NULL )
352  {
353#endif
354  g_hTrace = fopen( "TraceDec.txt", "wb" );
355  g_bJustDoIt = g_bEncDecTraceDisable;
356  g_nSymbolCounter = 0;
357#if H_MV
358  }
359#endif
360#endif
361  m_associatedIRAPType = NAL_UNIT_INVALID;
362  m_pocCRA = 0;
363  m_pocRandomAccess = MAX_INT; 
364  m_prevPOC                = MAX_INT;
365  m_bFirstSliceInPicture    = true;
366  m_bFirstSliceInSequence   = true;
367  m_prevSliceSkipped = false;
368  m_skippedPOC = 0;
369#if SETTING_NO_OUT_PIC_PRIOR
370  m_bFirstSliceInBitstream  = true;
371  m_lastPOCNoOutputPriorPics = -1;
372  m_craNoRaslOutputFlag = false;
373  m_isNoOutputPriorPics = false;
374#endif
375#if H_MV
376  m_isLastNALWasEos = false;
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
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
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
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#endif
571  m_bFirstSliceInPicture  = true;
572
573  return;
574}
575
576#if SETTING_NO_OUT_PIC_PRIOR
577Void TDecTop::checkNoOutputPriorPics (TComList<TComPic*>*& rpcListPic)
578{
579  if (!rpcListPic || !m_isNoOutputPriorPics) return;
580
581  TComList<TComPic*>::iterator  iterPic   = rpcListPic->begin();
582
583  while (iterPic != rpcListPic->end())
584  {
585    TComPic*& pcPicTmp = *(iterPic++);
586    if (m_lastPOCNoOutputPriorPics != pcPicTmp->getPOC())
587    {
588      pcPicTmp->setOutputMark(false);
589#if H_MV
590      pcPicTmp->setPicOutputFlag(false); 
591#endif
592    }
593  }
594}
595#endif
596
597Void TDecTop::xCreateLostPicture(Int iLostPoc) 
598{
599  printf("\ninserting lost poc : %d\n",iLostPoc);
600  TComSlice cFillSlice;
601  cFillSlice.setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
602  cFillSlice.setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
603  cFillSlice.initSlice();
604  TComPic *cFillPic;
605  xGetNewPicBuffer(&cFillSlice,cFillPic);
606  cFillPic->getSlice(0)->setSPS( m_parameterSetManagerDecoder.getFirstSPS() );
607  cFillPic->getSlice(0)->setPPS( m_parameterSetManagerDecoder.getFirstPPS() );
608  cFillPic->getSlice(0)->initSlice();
609 
610  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
611  Int closestPoc = 1000000;
612  while ( iterPic != m_cListPic.end())
613  {
614    TComPic * rpcPic = *(iterPic++);
615    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())
616    {
617      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
618    }
619  }
620  iterPic = m_cListPic.begin();
621  while ( iterPic != m_cListPic.end())
622  {
623    TComPic *rpcPic = *(iterPic++);
624    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
625    {
626      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
627      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
628      break;
629    }
630  }
631  cFillPic->setCurrSliceIdx(0);
632  for(Int i=0; i<cFillPic->getNumCUsInFrame(); i++) 
633  {
634    cFillPic->getCU(i)->initCU(cFillPic,i);
635  }
636  cFillPic->getSlice(0)->setReferenced(true);
637  cFillPic->getSlice(0)->setPOC(iLostPoc);
638  cFillPic->setReconMark(true);
639  cFillPic->setOutputMark(true);
640  if(m_pocRandomAccess == MAX_INT)
641  {
642    m_pocRandomAccess = iLostPoc;
643  }
644}
645
646
647Void TDecTop::xActivateParameterSets()
648{
649  m_parameterSetManagerDecoder.applyPrefetchedPS();
650 
651  TComPPS *pps = m_parameterSetManagerDecoder.getPPS(m_apcSlicePilot->getPPSId());
652  assert (pps != 0);
653
654  TComSPS *sps = m_parameterSetManagerDecoder.getSPS(pps->getSPSId());
655  assert (sps != 0);
656
657#if H_MV
658  TComVPS* vps = m_parameterSetManagerDecoder.getVPS(sps->getVPSId());
659  assert (vps != 0); 
660  if (!m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP(), m_layerId ) )
661#else
662  if (false == m_parameterSetManagerDecoder.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
663#endif
664  {
665    printf ("Parameter set activation failed!");
666    assert (0);
667  }
668
669#if H_MV
670  sps->inferSpsMaxDecPicBufferingMinus1( vps, m_targetOptLayerSetIdx, getLayerId(), false ); 
671#if !H_MV_HLS10_ADD_LAYERSETS
672  vps->inferDbpSizeLayerSetZero( sps, false ); 
673#endif
674  // When the value of vps_num_rep_formats_minus1 in the active VPS is equal to 0
675  if ( vps->getVpsNumRepFormatsMinus1() == 0 )
676  {
677    //, it is a requirement of bitstream conformance that the value of update_rep_format_flag shall be equal to 0.
678    assert( sps->getUpdateRepFormatFlag() == false ); 
679  }
680  sps->checkRpsMaxNumPics( vps, getLayerId() ); 
681#if H_MV_HLS10_MULTILAYERSPS
682
683  if( sps->getLayerId() != 0 )
684  {
685    sps->inferSpsMaxSubLayersMinus1( true, vps ); 
686  }
687
688#if H_MV_HLS10_MULTILAYERSPS
689  // It is a requirement of bitstream conformance that, when the SPS is referred to by
690  // any current picture that belongs to an independent non-base layer, the value of
691  // MultiLayerExtSpsFlag derived from the SPS shall be equal to 0.
692
693  if ( m_layerId > 0 && vps->getNumRefLayers( m_layerId ) == 0 )
694  { 
695    assert( sps->getMultiLayerExtSpsFlag() == 0 ); 
696  }
697#endif
698
699  if( sps->getMultiLayerExtSpsFlag() )
700  {
701    sps->setTemporalIdNestingFlag( (sps->getMaxTLayers() > 1) ? vps->getTemporalNestingFlag() : true );
702  }
703#else
704  if( m_layerId > 0 )
705  {
706    sps->setTemporalIdNestingFlag( (sps->getMaxTLayers() > 1) ? vps->getTemporalNestingFlag() : true );
707  }
708#endif
709#endif
710
711  if( pps->getDependentSliceSegmentsEnabledFlag() )
712  {
713    Int NumCtx = pps->getEntropyCodingSyncEnabledFlag()?2:1;
714
715    if (m_cSliceDecoder.getCtxMemSize() != NumCtx)
716    {
717      m_cSliceDecoder.initCtxMem(NumCtx);
718      for ( UInt st = 0; st < NumCtx; st++ )
719      {
720        TDecSbac* ctx = NULL;
721        ctx = new TDecSbac;
722        ctx->init( &m_cBinCABAC );
723        m_cSliceDecoder.setCtxMem( ctx, st );
724      }
725    }
726  }
727
728  m_apcSlicePilot->setPPS(pps);
729  m_apcSlicePilot->setSPS(sps);
730#if H_MV
731  m_apcSlicePilot->setVPS(vps); 
732  // 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.
733  assert( pps->getLayerId() == m_layerId || pps->getLayerId( ) == 0 || vps->getInDirectDependencyFlag( m_layerId, pps->getLayerId() ) );   
734  // 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.
735  assert( sps->getLayerId() == m_layerId || sps->getLayerId( ) == 0 || vps->getInDirectDependencyFlag( m_layerId, sps->getLayerId() ) );
736  sps->inferRepFormat  ( vps , m_layerId ); 
737  sps->inferScalingList( m_parameterSetManagerDecoder.getActiveSPS( sps->getSpsScalingListRefLayerId() ) ); 
738
739#endif
740  pps->setSPS(sps);
741  pps->setNumSubstreams(pps->getEntropyCodingSyncEnabledFlag() ? ((sps->getPicHeightInLumaSamples() + sps->getMaxCUHeight() - 1) / sps->getMaxCUHeight()) * (pps->getNumColumnsMinus1() + 1) : 1);
742  pps->setMinCuDQPSize( sps->getMaxCUWidth() >> ( pps->getMaxCuDQPDepth()) );
743
744  g_bitDepthY     = sps->getBitDepthY();
745  g_bitDepthC     = sps->getBitDepthC();
746  g_uiMaxCUWidth  = sps->getMaxCUWidth();
747  g_uiMaxCUHeight = sps->getMaxCUHeight();
748  g_uiMaxCUDepth  = sps->getMaxCUDepth();
749  g_uiAddCUDepth  = max (0, sps->getLog2MinCodingBlockSize() - (Int)sps->getQuadtreeTULog2MinSize() );
750
751  for (Int i = 0; i < sps->getLog2DiffMaxMinCodingBlockSize(); i++)
752  {
753    sps->setAMPAcc( i, sps->getUseAMP() );
754  }
755
756  for (Int i = sps->getLog2DiffMaxMinCodingBlockSize(); i < sps->getMaxCUDepth(); i++)
757  {
758    sps->setAMPAcc( i, 0 );
759  }
760
761  m_cSAO.destroy();
762  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() );
763  m_cLoopFilter.create( sps->getMaxCUDepth() );
764}
765
766#if H_MV
767Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool newLayerFlag, Bool& sliceSkippedFlag  )
768{
769  assert( nalu.m_layerId == m_layerId ); 
770#else
771Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
772{
773#endif
774  TComPic*&   pcPic         = m_pcPic;
775  m_apcSlicePilot->initSlice();
776
777  if (m_bFirstSliceInPicture)
778  {
779    m_uiSliceIdx     = 0;
780  }
781  else
782  {
783    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
784  }
785  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
786
787  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
788  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
789                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
790                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
791                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
792                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
793  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
794 
795  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
796  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
797
798#if H_MV
799  m_apcSlicePilot->setRefPicSetInterLayer( & m_refPicSetInterLayer0, &m_refPicSetInterLayer1 ); 
800  m_apcSlicePilot->setLayerId( nalu.m_layerId );
801  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManagerDecoder, m_targetOptLayerSetIdx );
802#endif
803  // set POC for dependent slices in skipped pictures
804  if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped) 
805  {
806    m_apcSlicePilot->setPOC(m_skippedPOC);
807  }
808
809  m_apcSlicePilot->setAssociatedIRAPPOC(m_pocCRA);
810  m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType);
811
812#if H_MV 
813  TComVPS* vps     = m_apcSlicePilot->getVPS();
814  Int layerId  = nalu.m_layerId;   
815  setViewId   ( vps->getViewId   ( layerId )      ); 
816#if H_3D
817  setViewIndex( vps->getViewIndex( layerId )      ); 
818  setIsDepth  ( vps->getDepthId  ( layerId ) == 1 ); 
819  m_ivPicLists->setVPS( vps ); 
820#endif
821#endif
822
823#if SETTING_NO_OUT_PIC_PRIOR
824  //For inference of NoOutputOfPriorPicsFlag
825  if (m_apcSlicePilot->getRapPicFlag())
826  {
827    if ((m_apcSlicePilot->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_apcSlicePilot->getNalUnitType() <= NAL_UNIT_CODED_SLICE_IDR_N_LP) || 
828        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_bFirstSliceInSequence) ||
829        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getHandleCraAsBlaFlag()))
830    {
831      m_apcSlicePilot->setNoRaslOutputFlag(true);
832    }
833    //the inference for NoOutputPriorPicsFlag
834    if (!m_bFirstSliceInBitstream && m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag())
835    {
836      if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
837      {
838        m_apcSlicePilot->setNoOutputPriorPicsFlag(true);
839      }
840    }
841    else
842    {
843      m_apcSlicePilot->setNoOutputPriorPicsFlag(false);
844    }
845
846    if(m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
847    {
848      m_craNoRaslOutputFlag = m_apcSlicePilot->getNoRaslOutputFlag();
849    }
850  }
851  if (m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoOutputPriorPicsFlag())
852  {
853    m_lastPOCNoOutputPriorPics = m_apcSlicePilot->getPOC();
854    m_isNoOutputPriorPics = true;
855  }
856  else
857  {
858    m_isNoOutputPriorPics = false;
859  }
860
861  //For inference of PicOutputFlag
862  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R)
863  {
864    if ( m_craNoRaslOutputFlag )
865    {
866      m_apcSlicePilot->setPicOutputFlag(false);
867    }
868  }
869#endif
870
871#if FIX_POC_CRA_NORASL_OUTPUT
872  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_craNoRaslOutputFlag) //Reset POC MSB when CRA has NoRaslOutputFlag equal to 1
873  {
874    Int iMaxPOClsb = 1 << m_apcSlicePilot->getSPS()->getBitsForPOC();
875    m_apcSlicePilot->setPOC( m_apcSlicePilot->getPOC() & (iMaxPOClsb - 1) );
876  }
877#endif
878#if H_MV
879    xCeckNoClrasOutput();
880#endif
881    // Skip pictures due to random access
882    if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
883    {
884    m_prevSliceSkipped = true;
885    m_skippedPOC = m_apcSlicePilot->getPOC();
886#if H_MV
887    sliceSkippedFlag = true; 
888#endif
889      return false;
890    }
891    // Skip TFD pictures associated with BLA/BLANT pictures
892    if (isSkipPictureForBLA(iPOCLastDisplay))
893    {
894    m_prevSliceSkipped = true;
895    m_skippedPOC = m_apcSlicePilot->getPOC();
896#if H_MV
897    sliceSkippedFlag = true; 
898#endif
899      return false;
900    }
901
902  // clear previous slice skipped flag
903  m_prevSliceSkipped = false;
904
905  //we should only get a different poc for a new picture (with CTU address==0)
906  if (m_apcSlicePilot->isNextSlice() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (m_apcSlicePilot->getSliceCurStartCUAddr()!=0))
907  {
908    printf ("Warning, the first slice of a picture might have been lost!\n");
909  }
910  // exit when a new picture is found
911  if (m_apcSlicePilot->isNextSlice() && (m_apcSlicePilot->getSliceCurStartCUAddr() == 0 && !m_bFirstSliceInPicture) && !m_bFirstSliceInSequence )
912  {
913    if (m_prevPOC >= m_pocRandomAccess)
914    {
915      m_prevPOC = m_apcSlicePilot->getPOC();
916      return true;
917    }
918    m_prevPOC = m_apcSlicePilot->getPOC();
919  }
920#if H_MV
921  if ( newLayerFlag )
922  {
923    return false; 
924  }
925#if ENC_DEC_TRACE
926#if H_MV_ENC_DEC_TRAC
927  // parse remainder of SH
928   g_disableHLSTrace = false; 
929#endif
930#endif
931#endif
932  // actual decoding starts here
933#if H_MV
934   // This part needs further testing !
935   if ( m_apcSlicePilot->getPocResetFlag() )
936   {   
937     xResetPocInPicBuffer();
938   }
939#endif
940  xActivateParameterSets();
941
942  if (m_apcSlicePilot->isNextSlice()) 
943  {
944    m_prevPOC = m_apcSlicePilot->getPOC();
945  }
946  m_bFirstSliceInSequence = false;
947#if SETTING_NO_OUT_PIC_PRIOR 
948  m_bFirstSliceInBitstream  = false;
949#endif
950  //detect lost reference picture and insert copy of earlier frame.
951  Int lostPoc;
952  while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
953  {
954    xCreateLostPicture(lostPoc-1);
955  }
956  if (m_bFirstSliceInPicture)
957  {
958    // Buffer initialize for prediction.
959    m_cPrediction.initTempBuff();
960    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
961#if H_MV
962    m_apcSlicePilot->createInterLayerReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
963#endif
964    //  Get a new picture buffer
965    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
966
967    Bool isField = false;
968    Bool isTff = false;
969   
970    if(!m_SEIs.empty())
971    {
972      // Check if any new Picture Timing SEI has arrived
973      SEIMessages pictureTimingSEIs = extractSeisByType (m_SEIs, SEI::PICTURE_TIMING);
974      if (pictureTimingSEIs.size()>0)
975      {
976        SEIPictureTiming* pictureTiming = (SEIPictureTiming*) *(pictureTimingSEIs.begin());
977        isField = (pictureTiming->m_picStruct == 1) || (pictureTiming->m_picStruct == 2);
978        isTff =  (pictureTiming->m_picStruct == 1);
979      }
980    }
981   
982    //Set Field/Frame coding mode
983    m_pcPic->setField(isField);
984    m_pcPic->setTopField(isTff);
985   
986    // transfer any SEI messages that have been received to the picture
987    pcPic->setSEIs(m_SEIs);
988    m_SEIs.clear();
989
990    // Recursive structure
991    m_cCuDecoder.create ( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
992    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
993    m_cTrQuant.init     ( g_uiMaxCUWidth, g_uiMaxCUHeight, m_apcSlicePilot->getSPS()->getMaxTrSize());
994
995    m_cSliceDecoder.create();
996  }
997  else
998  {
999    // Check if any new SEI has arrived
1000    if(!m_SEIs.empty())
1001    {
1002      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
1003      SEIMessages &picSEI = pcPic->getSEIs();
1004      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
1005      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
1006      deleteSEIs(m_SEIs);
1007    }
1008  }
1009 
1010  //  Set picture slice pointer
1011  TComSlice*  pcSlice = m_apcSlicePilot;
1012  Bool bNextSlice     = pcSlice->isNextSlice();
1013
1014  UInt uiCummulativeTileWidth;
1015  UInt uiCummulativeTileHeight;
1016  UInt i, j, p;
1017
1018  //set NumColumnsMins1 and NumRowsMinus1
1019  pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() );
1020  pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() );
1021
1022  //create the TComTileArray
1023  pcPic->getPicSym()->xCreateTComTileArray();
1024
1025  if( pcSlice->getPPS()->getUniformSpacingFlag() )
1026  {
1027    //set the width for each tile
1028    for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++)
1029    {
1030      for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++)
1031      {
1032        pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->
1033          setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) 
1034          - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) );
1035      }
1036    }
1037
1038    //set the height for each tile
1039    for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++)
1040    {
1041      for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++)
1042      {
1043        pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->
1044          setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) 
1045          - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) );   
1046      }
1047    }
1048  }
1049  else
1050  {
1051    //set the width for each tile
1052    for(j=0; j < pcSlice->getPPS()->getNumRowsMinus1()+1; j++)
1053    {
1054      uiCummulativeTileWidth = 0;
1055      for(i=0; i < pcSlice->getPPS()->getNumColumnsMinus1(); i++)
1056      {
1057        pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcSlice->getPPS()->getColumnWidth(i) );
1058        uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(i);
1059      }
1060      pcPic->getPicSym()->getTComTile(j * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + i)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth );
1061    }
1062
1063    //set the height for each tile
1064    for(j=0; j < pcSlice->getPPS()->getNumColumnsMinus1()+1; j++)
1065    {
1066      uiCummulativeTileHeight = 0;
1067      for(i=0; i < pcSlice->getPPS()->getNumRowsMinus1(); i++)
1068      { 
1069        pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcSlice->getPPS()->getRowHeight(i) );
1070        uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(i);
1071      }
1072      pcPic->getPicSym()->getTComTile(i * (pcSlice->getPPS()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight );
1073    }
1074  }
1075
1076  pcPic->getPicSym()->xInitTiles();
1077
1078  //generate the Coding Order Map and Inverse Coding Order Map
1079  UInt uiEncCUAddr;
1080  for(i=0, uiEncCUAddr=0; i<pcPic->getPicSym()->getNumberOfCUsInFrame(); i++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr))
1081  {
1082    pcPic->getPicSym()->setCUOrderMap(i, uiEncCUAddr);
1083    pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, i);
1084  }
1085  pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
1086  pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame());
1087
1088  //convert the start and end CU addresses of the slice and dependent slice into encoding order
1089  pcSlice->setSliceSegmentCurStartCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurStartCUAddr()) );
1090  pcSlice->setSliceSegmentCurEndCUAddr( pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceSegmentCurEndCUAddr()) );
1091  if(pcSlice->isNextSlice())
1092  {
1093    pcSlice->setSliceCurStartCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurStartCUAddr()));
1094    pcSlice->setSliceCurEndCUAddr(pcPic->getPicSym()->getPicSCUEncOrder(pcSlice->getSliceCurEndCUAddr()));
1095  }
1096
1097  if (m_bFirstSliceInPicture) 
1098  {
1099    if(pcPic->getNumAllocatedSlice() != 1)
1100    {
1101      pcPic->clearSliceBuffer();
1102    }
1103  }
1104  else
1105  {
1106    pcPic->allocateNewSlice();
1107  }
1108  assert(pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
1109  m_apcSlicePilot = pcPic->getPicSym()->getSlice(m_uiSliceIdx); 
1110  pcPic->getPicSym()->setSlice(pcSlice, m_uiSliceIdx);
1111
1112  pcPic->setTLayer(nalu.m_temporalId);
1113
1114#if H_MV
1115  pcPic->setLayerId( nalu.m_layerId );
1116  pcPic->setViewId ( getViewId() );
1117#if H_3D
1118  pcPic->setViewIndex( getViewIndex() );
1119  pcPic->setIsDepth  ( getIsDepth  () );
1120#endif
1121#endif
1122  if (bNextSlice)
1123  {
1124    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_associatedIRAPType, m_cListPic );
1125    // Set reference list
1126#if H_MV   
1127    std::vector< TComPic* > tempRefPicLists[2];
1128    std::vector< Bool     > usedAsLongTerm [2];
1129    Int       numPocTotalCurr;
1130
1131    pcSlice->getTempRefPicLists( m_cListPic, m_refPicSetInterLayer0, m_refPicSetInterLayer1, tempRefPicLists, usedAsLongTerm, numPocTotalCurr);
1132    pcSlice->setRefPicList     ( tempRefPicLists, usedAsLongTerm, numPocTotalCurr, true ); 
1133#if H_3D_ARP
1134    pcSlice->setARPStepNum(m_ivPicLists);
1135    if( pcSlice->getARPStepNum() > 1 )
1136    {
1137      // GT: This seems to be broken, not all nuh_layer_ids are necessarily present
1138      for(Int iLayerId = 0; iLayerId < nalu.m_layerId; iLayerId ++ )
1139      {
1140        Int  iViewIdx =   pcSlice->getVPS()->getViewIndex(iLayerId);
1141        Bool bIsDepth = ( pcSlice->getVPS()->getDepthId  ( iLayerId ) == 1 );
1142        if( iViewIdx<getViewIndex() && !bIsDepth )
1143        {
1144          pcSlice->setBaseViewRefPicList( m_ivPicLists->getPicList( iLayerId ), iViewIdx );
1145        }
1146      }
1147    }
1148#endif
1149#else
1150    pcSlice->setRefPicList( m_cListPic, true );
1151#endif
1152
1153#if H_3D
1154    pcSlice->setIvPicLists( m_ivPicLists );         
1155#if H_3D_IV_MERGE
1156#if H_3D_FCO
1157    //assert( !getIsDepth() );
1158#else
1159    assert( !getIsDepth() || ( pcSlice->getTexturePic() != 0 ) );
1160#endif
1161#endif   
1162#endif
1163    // For generalized B
1164    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
1165    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
1166    {
1167      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
1168      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
1169
1170      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
1171      {
1172        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
1173      }
1174    }
1175    if (!pcSlice->isIntra())
1176    {
1177      Bool bLowDelay = true;
1178      Int  iCurrPOC  = pcSlice->getPOC();
1179      Int iRefIdx = 0;
1180
1181      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
1182      {
1183        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
1184        {
1185          bLowDelay = false;
1186        }
1187      }
1188      if (pcSlice->isInterB())
1189      {
1190        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
1191        {
1192          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
1193          {
1194            bLowDelay = false;
1195          }
1196        }       
1197      }
1198
1199      pcSlice->setCheckLDC(bLowDelay);           
1200    }
1201
1202    //---------------
1203    pcSlice->setRefPOCList();
1204#if  H_3D_TMVP
1205    if(pcSlice->getLayerId())
1206      pcSlice->generateAlterRefforTMVP();
1207#endif
1208  }
1209
1210  pcPic->setCurrSliceIdx(m_uiSliceIdx);
1211  if(pcSlice->getSPS()->getScalingListFlag())
1212  {
1213    pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList()  );
1214    if(pcSlice->getPPS()->getScalingListPresentFlag())
1215    {
1216      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
1217    }
1218    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
1219    {
1220      pcSlice->setDefaultScalingList();
1221    }
1222    m_cTrQuant.setScalingListDec(pcSlice->getScalingList());
1223    m_cTrQuant.setUseScalingList(true);
1224  }
1225  else
1226  {
1227    m_cTrQuant.setFlatScalingList();
1228    m_cTrQuant.setUseScalingList(false);
1229  }
1230
1231#if H_3D_IV_MERGE
1232#if LGE_FCO_I0116
1233  if( !pcSlice->getIsDepth() && m_pcCamParsCollector )
1234#else
1235  if( pcSlice->getIsDepth() && m_pcCamParsCollector )
1236#endif
1237  {
1238    m_pcCamParsCollector->copyCamParamForSlice( pcSlice );
1239  }
1240#endif
1241
1242  //  Decode a picture
1243  m_cGopDecoder.decompressSlice(nalu.m_Bitstream, pcPic);
1244#if H_3D
1245  if( m_pcCamParsCollector )
1246  {
1247    m_pcCamParsCollector->setSlice( pcSlice );
1248  }
1249#endif
1250  m_bFirstSliceInPicture = false;
1251  m_uiSliceIdx++;
1252
1253  return false;
1254}
1255
1256Void TDecTop::xDecodeVPS()
1257{
1258  TComVPS* vps = new TComVPS();
1259 
1260  m_cEntropyDecoder.decodeVPS( vps );
1261  m_parameterSetManagerDecoder.storePrefetchedVPS(vps); 
1262}
1263
1264Void TDecTop::xDecodeSPS()
1265{
1266  TComSPS* sps = new TComSPS();
1267#if H_MV
1268  sps->setLayerId( getLayerId() ); 
1269#endif
1270#if H_3D
1271  // Preliminary fix. assuming that all sps refer to the same VPS.
1272  // Parsing dependency should be resolved!
1273  TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 ); 
1274  assert( vps != 0 );
1275  m_cEntropyDecoder.decodeSPS( sps, vps->getViewIndex( m_layerId ), ( vps->getDepthId( m_layerId ) == 1 ) );
1276#else
1277  m_cEntropyDecoder.decodeSPS( sps );
1278#endif
1279  m_parameterSetManagerDecoder.storePrefetchedSPS(sps);
1280}
1281
1282Void TDecTop::xDecodePPS()
1283{
1284  TComPPS* pps = new TComPPS();
1285#if H_MV
1286  pps->setLayerId( getLayerId() ); 
1287#endif
1288#if H_3D
1289  // Assuming that all PPS indirectly refer to the same VPS via different SPS
1290  // There is no parsing dependency in decoding DLT in PPS.
1291  // The VPS information passed to decodePPS() is used to arrange the decoded DLT tables to their corresponding layers.
1292  // This is equivalent to the process of
1293  //   Step 1) decoding DLT tables based on the number of depth layers, and
1294  //   Step 2) mapping DLT tables to the depth layers
1295  // as described in the 3D-HEVC WD.
1296  TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 );
1297  m_cEntropyDecoder.decodePPS( pps, vps );
1298#else
1299  m_cEntropyDecoder.decodePPS( pps );
1300#endif
1301  m_parameterSetManagerDecoder.storePrefetchedPPS( pps );
1302}
1303
1304Void TDecTop::xDecodeSEI( TComInputBitstream* bs, const NalUnitType nalUnitType )
1305{
1306  if(nalUnitType == NAL_UNIT_SUFFIX_SEI)
1307  {
1308#if H_MV
1309    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS( m_layerId ) );
1310#else
1311    m_seiReader.parseSEImessage( bs, m_pcPic->getSEIs(), nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1312#endif
1313  }
1314  else
1315  {
1316#if H_MV
1317    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS( m_layerId ) );
1318#else
1319    m_seiReader.parseSEImessage( bs, m_SEIs, nalUnitType, m_parameterSetManagerDecoder.getActiveSPS() );
1320#endif
1321    SEIMessages activeParamSets = getSeisByType(m_SEIs, SEI::ACTIVE_PARAMETER_SETS);
1322    if (activeParamSets.size()>0)
1323    {
1324      SEIActiveParameterSets *seiAps = (SEIActiveParameterSets*)(*activeParamSets.begin());
1325      m_parameterSetManagerDecoder.applyPrefetchedPS();
1326      assert(seiAps->activeSeqParameterSetId.size()>0);
1327#if H_MV
1328      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParameterSetId[0], m_layerId ))
1329#else
1330      if (! m_parameterSetManagerDecoder.activateSPSWithSEI(seiAps->activeSeqParameterSetId[0] ))
1331#endif
1332      {
1333        printf ("Warning SPS activation with Active parameter set SEI failed");
1334      }
1335    }
1336  }
1337}
1338
1339#if H_MV
1340Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayerFlag, Bool& sliceSkippedFlag )
1341#else
1342Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1343#endif
1344{
1345  // Initialize entropy decoder
1346  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1347  m_cEntropyDecoder.setBitstream      (nalu.m_Bitstream);
1348
1349  switch (nalu.m_nalUnitType)
1350  {
1351    case NAL_UNIT_VPS:
1352      xDecodeVPS();
1353#if H_MV
1354      m_isLastNALWasEos = false;
1355#endif
1356      return false;
1357     
1358    case NAL_UNIT_SPS:
1359      xDecodeSPS();
1360      return false;
1361
1362    case NAL_UNIT_PPS:
1363      xDecodePPS();
1364      return false;
1365     
1366    case NAL_UNIT_PREFIX_SEI:
1367    case NAL_UNIT_SUFFIX_SEI:
1368#if H_MV
1369      if ( nalu.m_nalUnitType == NAL_UNIT_SUFFIX_SEI )
1370      {
1371        assert( m_isLastNALWasEos == false );
1372      }
1373#endif
1374      xDecodeSEI( nalu.m_Bitstream, nalu.m_nalUnitType );
1375      return false;
1376
1377    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1378    case NAL_UNIT_CODED_SLICE_TRAIL_N:
1379    case NAL_UNIT_CODED_SLICE_TSA_R:
1380    case NAL_UNIT_CODED_SLICE_TSA_N:
1381    case NAL_UNIT_CODED_SLICE_STSA_R:
1382    case NAL_UNIT_CODED_SLICE_STSA_N:
1383    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
1384    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
1385    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1386    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
1387    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
1388    case NAL_UNIT_CODED_SLICE_CRA:
1389    case NAL_UNIT_CODED_SLICE_RADL_N:
1390    case NAL_UNIT_CODED_SLICE_RADL_R:
1391    case NAL_UNIT_CODED_SLICE_RASL_N:
1392    case NAL_UNIT_CODED_SLICE_RASL_R:
1393#if H_MV
1394      if (nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_N ||
1395          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_N ||
1396          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_N ||
1397          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
1398          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N )
1399      {
1400        assert( m_isLastNALWasEos == false );
1401      }
1402      else
1403      {
1404        m_isLastNALWasEos = false;
1405      }
1406
1407      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, newLayerFlag, sliceSkippedFlag );
1408#else
1409      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1410#endif
1411      break;
1412    case NAL_UNIT_EOS:
1413#if H_MV
1414      assert( m_isLastNALWasEos == false );
1415      //Check layer id of the nalu. if it is not 0, give a warning message and just return without doing anything.
1416      if (nalu.m_layerId > 0)
1417      {
1418        printf( "\nThis bitstream has EOS with non-zero layer id.\n" );
1419        return false;
1420      }
1421      m_isLastNALWasEos = true;
1422#endif
1423      m_associatedIRAPType = NAL_UNIT_INVALID;
1424      m_pocCRA = 0;
1425      m_pocRandomAccess = MAX_INT;
1426      m_prevPOC = MAX_INT;
1427      m_bFirstSliceInPicture = true;
1428      m_bFirstSliceInSequence = true;
1429      m_prevSliceSkipped = false;
1430      m_skippedPOC = 0;
1431      return false;
1432     
1433    case NAL_UNIT_ACCESS_UNIT_DELIMITER:
1434      // TODO: process AU delimiter
1435      return false;
1436     
1437    case NAL_UNIT_EOB:
1438      return false;
1439     
1440    case NAL_UNIT_FILLER_DATA:
1441#if H_MV
1442      assert( m_isLastNALWasEos == false );
1443#endif
1444      return false;
1445     
1446    case NAL_UNIT_RESERVED_VCL_N10:
1447    case NAL_UNIT_RESERVED_VCL_R11:
1448    case NAL_UNIT_RESERVED_VCL_N12:
1449    case NAL_UNIT_RESERVED_VCL_R13:
1450    case NAL_UNIT_RESERVED_VCL_N14:
1451    case NAL_UNIT_RESERVED_VCL_R15:
1452     
1453    case NAL_UNIT_RESERVED_IRAP_VCL22:
1454    case NAL_UNIT_RESERVED_IRAP_VCL23:
1455     
1456    case NAL_UNIT_RESERVED_VCL24:
1457    case NAL_UNIT_RESERVED_VCL25:
1458    case NAL_UNIT_RESERVED_VCL26:
1459    case NAL_UNIT_RESERVED_VCL27:
1460    case NAL_UNIT_RESERVED_VCL28:
1461    case NAL_UNIT_RESERVED_VCL29:
1462    case NAL_UNIT_RESERVED_VCL30:
1463    case NAL_UNIT_RESERVED_VCL31:
1464     
1465    case NAL_UNIT_RESERVED_NVCL41:
1466    case NAL_UNIT_RESERVED_NVCL42:
1467    case NAL_UNIT_RESERVED_NVCL43:
1468    case NAL_UNIT_RESERVED_NVCL44:
1469    case NAL_UNIT_RESERVED_NVCL45:
1470    case NAL_UNIT_RESERVED_NVCL46:
1471    case NAL_UNIT_RESERVED_NVCL47:
1472    case NAL_UNIT_UNSPECIFIED_48:
1473    case NAL_UNIT_UNSPECIFIED_49:
1474    case NAL_UNIT_UNSPECIFIED_50:
1475    case NAL_UNIT_UNSPECIFIED_51:
1476    case NAL_UNIT_UNSPECIFIED_52:
1477    case NAL_UNIT_UNSPECIFIED_53:
1478    case NAL_UNIT_UNSPECIFIED_54:
1479    case NAL_UNIT_UNSPECIFIED_55:
1480    case NAL_UNIT_UNSPECIFIED_56:
1481    case NAL_UNIT_UNSPECIFIED_57:
1482    case NAL_UNIT_UNSPECIFIED_58:
1483    case NAL_UNIT_UNSPECIFIED_59:
1484    case NAL_UNIT_UNSPECIFIED_60:
1485    case NAL_UNIT_UNSPECIFIED_61:
1486    case NAL_UNIT_UNSPECIFIED_62:
1487    case NAL_UNIT_UNSPECIFIED_63:
1488    default:
1489      assert (0);
1490  }
1491
1492  return false;
1493}
1494
1495/** Function for checking if picture should be skipped because of association with a previous BLA picture
1496 * \param iPOCLastDisplay POC of last picture displayed
1497 * \returns true if the picture should be skipped
1498 * This function skips all TFD pictures that follow a BLA picture
1499 * in decoding order and precede it in output order.
1500 */
1501Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
1502{
1503  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) && 
1504       m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
1505  {
1506    iPOCLastDisplay++;
1507    return true;
1508  }
1509  return false;
1510}
1511
1512/** Function for checking if picture should be skipped because of random access
1513 * \param iSkipFrame skip frame counter
1514 * \param iPOCLastDisplay POC of last picture displayed
1515 * \returns true if the picture shold be skipped in the random access.
1516 * This function checks the skipping of pictures in the case of -s option random access.
1517 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1518 * It also checks the type of Nal unit type at the random access point.
1519 * 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.
1520 * If the random access point is IDR all pictures after the random access point are decoded.
1521 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
1522 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
1523 * access point there is no guarantee that the decoder will not crash.
1524 */
1525Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay)
1526{
1527  if (iSkipFrame) 
1528  {
1529    iSkipFrame--;   // decrement the counter
1530    return true;
1531  }
1532#if H_MV
1533  else if ( !m_layerInitilizedFlag[ m_layerId ] ) // start of random access point, m_pocRandomAccess has not been set yet.
1534#else
1535  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1536#endif
1537  {
1538    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
1539        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1540        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1541        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
1542    {
1543
1544#if H_MV
1545      if ( xAllRefLayersInitilized() )
1546      {
1547        m_layerInitilizedFlag[ m_layerId ] = true; 
1548        m_pocRandomAccess = m_apcSlicePilot->getPOC();
1549      }
1550      else
1551      {
1552        return true; 
1553      }
1554#else
1555      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
1556      m_pocRandomAccess = m_apcSlicePilot->getPOC();
1557#endif
1558    }
1559    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
1560    {
1561#if H_MV
1562      if ( xAllRefLayersInitilized() )
1563      {
1564        m_layerInitilizedFlag[ m_layerId ] = true; 
1565        m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1566      }
1567      else 
1568      {
1569        return true; 
1570      }
1571#else
1572      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1573#endif
1574    }
1575    else 
1576    {
1577#if H_MV
1578      static Bool warningMessage[MAX_NUM_LAYERS];
1579      static Bool warningInitFlag = false;
1580     
1581      if (!warningInitFlag)
1582      {
1583        for ( Int i = 0; i < MAX_NUM_LAYERS; i++)
1584        {
1585          warningMessage[i] = true; 
1586        }
1587        warningInitFlag = true; 
1588      }
1589
1590      if ( warningMessage[getLayerId()] )
1591      {
1592        printf("\nLayer%3d   No valid random access point. VCL NAL units of this layer are discarded until next layer initialization picture. ", getLayerId() ); 
1593        warningMessage[m_layerId] = false; 
1594      }
1595#else
1596      static Bool warningMessage = false;
1597      if(!warningMessage)
1598      {
1599        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1600        warningMessage = true;
1601      }
1602#endif
1603      return true;
1604    }
1605  }
1606  // skip the reordered pictures, if necessary
1607  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))
1608  {
1609    iPOCLastDisplay++;
1610    return true;
1611  }
1612#if H_MV
1613  return !m_layerInitilizedFlag[ getLayerId() ]; 
1614#else
1615  // if we reach here, then the picture is not skipped.
1616  return false; 
1617#endif
1618}
1619
1620#if H_MV
1621TComPic* TDecTop::getPic( Int poc )
1622{
1623  xGetPic( m_layerId, poc ); 
1624  TComList<TComPic*>* listPic = getListPic();
1625  TComPic* pcPic = NULL;
1626  for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++)
1627  {
1628    if( (*it)->getPOC() == poc )
1629    {
1630      pcPic = *it ;
1631      break ;
1632    }
1633  }
1634  return pcPic;
1635}
1636
1637TComPic* TDecTop::xGetPic( Int layerId, Int poc )
1638{ 
1639  return m_ivPicLists->getPic( layerId, poc ) ;
1640}
1641
1642Void TDecTop::xResetPocInPicBuffer()
1643{
1644  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
1645  while (iterPic != m_cListPic.end())
1646  {
1647    TComPic* pic = *(iterPic++);
1648    if ( pic->getReconMark() )
1649    {
1650      for( Int i = 0; i < pic->getNumAllocatedSlice(); i++)
1651      {
1652        TComSlice* slice = pic->getSlice( i ); 
1653        slice->setPOC ( slice->getPOC() - m_apcSlicePilot->getPocBeforeReset() );           
1654      }         
1655    }     
1656  }
1657}
1658
1659#if H_MV
1660Void TDecTop::xCeckNoClrasOutput()
1661{
1662  // This part needs further testing!
1663  if ( getLayerId() == 0 )
1664  {   
1665    NalUnitType nut = m_apcSlicePilot->getNalUnitType(); 
1666
1667    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 ); 
1668    Bool isIDR  = ( nut == NAL_UNIT_CODED_SLICE_IDR_W_RADL ) || ( nut == NAL_UNIT_CODED_SLICE_IDR_N_LP ); 
1669    Bool noClrasOutputFlag  = isBLA || ( isIDR  &&  m_apcSlicePilot->getCrossLayerBlaFlag() ); 
1670
1671    if ( noClrasOutputFlag ) 
1672    {
1673      for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++)
1674      {
1675        m_layerInitilizedFlag[i] = false; 
1676      } 
1677    }
1678  }
1679}
1680
1681Bool TDecTop::xAllRefLayersInitilized()
1682{
1683  Bool allRefLayersInitilizedFlag = true; 
1684  TComVPS* vps = m_parameterSetManagerDecoder.getPrefetchedVPS( 0 ); 
1685  for (Int i = 0; i < vps->getNumDirectRefLayers( getLayerId()  ); i++ )
1686  {
1687#if H_MV_HLS10_REF_PRED_LAYERS
1688    Int refLayerId = vps->getIdDirectRefLayer( m_layerId, i ); 
1689#else
1690    Int refLayerId = vps->getRefLayerId( m_layerId, i ); 
1691#endif
1692    allRefLayersInitilizedFlag = allRefLayersInitilizedFlag && m_layerInitilizedFlag[ refLayerId ]; 
1693  }
1694
1695  return allRefLayersInitilizedFlag;
1696}
1697#endif
1698#endif
1699//! \}
Note: See TracBrowser for help on using the repository browser.