source: 3DVCSoftware/branches/HTM-14.1-update-dev2-Orange/source/Lib/TLibDecoder/TDecTop.cpp @ 1256

Last change on this file since 1256 was 1225, checked in by sharpjp-htm, 10 years ago

Migration of illumination compensation(NH_3D_IC) and small fix(H_MV_ENC_DEC_TRAC_FIX)

  • Property svn:eol-style set to native
File size: 57.2 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-2015, 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#if NH_MV
41ParameterSetManager TDecTop::m_parameterSetManager;
42#endif
43
44//! \ingroup TLibDecoder
45//! \{
46
47#if NH_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_vps->getNumViews() );
79}
80
81
82Void
83CamParsCollector::init( const 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_lastPoc                 = -1;   
90  m_firstReceivedPoc        = -2; 
91
92  for (Int i = 0; i <= vps->getMaxLayersMinus1(); i++)
93  {
94    Int curViewIdxInVps = m_vps->getVoiInVps( m_vps->getViewIndex( m_vps->getLayerIdInNuh( i ) ) ) ; 
95    m_bCamParsVaryOverTime = m_bCamParsVaryOverTime || vps->getCpInSliceSegmentHeaderFlag( curViewIdxInVps );   
96  }
97
98  assert( m_receivedIdc == NULL ); 
99  m_receivedIdc = new Int*[ m_vps->getNumViews() ]; 
100  for (Int i = 0; i < m_vps->getNumViews(); i++)
101  {
102    m_receivedIdc[i] = new Int[ m_vps->getNumViews() ]; 
103  }
104
105  xResetReceivedIdc( true ); 
106
107  for (Int voiInVps = 0; voiInVps < m_vps->getNumViews(); voiInVps++ )
108  {
109    if( !m_vps->getCpInSliceSegmentHeaderFlag( voiInVps ) ) 
110    {
111      for (Int baseVoiInVps = 0; baseVoiInVps < m_vps->getNumViews(); baseVoiInVps++ )
112      { 
113        if( m_vps->getCpPresentFlag( voiInVps, baseVoiInVps ) )
114        {
115          m_receivedIdc   [ baseVoiInVps ][ voiInVps ] = -1; 
116          m_aaiCodedScale [ baseVoiInVps ][ voiInVps ] = m_vps->getCodedScale    (voiInVps) [ baseVoiInVps ];
117          m_aaiCodedOffset[ baseVoiInVps ][ voiInVps ] = m_vps->getCodedOffset   (voiInVps) [ baseVoiInVps ];
118
119          m_receivedIdc   [ voiInVps ][ baseVoiInVps ] = -1; 
120          m_aaiCodedScale [ voiInVps ][ baseVoiInVps ] = m_vps->getInvCodedScale (voiInVps) [ baseVoiInVps ];
121          m_aaiCodedOffset[ voiInVps ][ baseVoiInVps ] = m_vps->getInvCodedOffset(voiInVps) [ baseVoiInVps ];
122          xInitLUTs( baseVoiInVps, voiInVps, m_aaiCodedScale[ baseVoiInVps ][ voiInVps ], m_aaiCodedOffset[ baseVoiInVps ][ voiInVps ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
123          xInitLUTs( voiInVps, baseVoiInVps, m_aaiCodedScale[ voiInVps ][ baseVoiInVps ], m_aaiCodedOffset[ voiInVps ][ baseVoiInVps ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
124        }
125      }
126    }
127  }
128}
129
130
131
132
133Void
134CamParsCollector::xResetReceivedIdc( Bool overWriteFlag )
135{
136  for (Int i = 0; i < m_vps->getNumViews(); i++)
137  { 
138    for (Int j = 0; j < m_vps->getNumViews(); 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->getCpPrecision() + 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 !H_3D_FCO
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 voiInVps          = m_vps->getVoiInVps(pcSlice->getViewIndex()); 
258  if( m_vps->getCpInSliceSegmentHeaderFlag( voiInVps ) ) // check consistency of slice parameters here
259  {   
260    for( Int baseVoiInVps = 0; baseVoiInVps < m_vps->getNumViews(); baseVoiInVps++ )
261    {       
262      if ( m_vps->getCpPresentFlag( voiInVps, baseVoiInVps ) )
263      {
264        if ( m_receivedIdc[ voiInVps ][ baseVoiInVps ] != 0 )
265        {     
266          AOF( m_aaiCodedScale [ voiInVps ][ baseVoiInVps ] == pcSlice->getInvCodedScale () [ baseVoiInVps ] );
267          AOF( m_aaiCodedOffset[ voiInVps ][ baseVoiInVps ] == pcSlice->getInvCodedOffset() [ baseVoiInVps ] );
268        }
269        else
270        {         
271          m_receivedIdc   [ voiInVps ][ baseVoiInVps ]  = 1; 
272          m_aaiCodedScale [ voiInVps ][ baseVoiInVps ]  = pcSlice->getInvCodedScale () [ baseVoiInVps ];
273          m_aaiCodedOffset[ voiInVps ][ baseVoiInVps ]  = pcSlice->getInvCodedOffset() [ baseVoiInVps ];
274          xInitLUTs( voiInVps, baseVoiInVps, m_aaiCodedScale[ voiInVps ][ baseVoiInVps ], m_aaiCodedOffset[ voiInVps ][ baseVoiInVps ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT);
275        }
276        if ( m_receivedIdc[ baseVoiInVps ][ voiInVps ] != 0 )
277        {     
278          AOF( m_aaiCodedScale [ baseVoiInVps ][ voiInVps ] == pcSlice->getCodedScale    () [ baseVoiInVps ] );
279          AOF( m_aaiCodedOffset[ baseVoiInVps ][ voiInVps ] == pcSlice->getCodedOffset   () [ baseVoiInVps ] );
280        }
281        else
282        {       
283          m_receivedIdc   [ baseVoiInVps ][ voiInVps ]  = 1; 
284          m_aaiCodedScale [ baseVoiInVps ][ voiInVps ]  = pcSlice->getCodedScale    () [ baseVoiInVps ];
285          m_aaiCodedOffset[ baseVoiInVps ][ voiInVps ]  = pcSlice->getCodedOffset   () [ baseVoiInVps ];
286          xInitLUTs( baseVoiInVps, voiInVps, m_aaiCodedScale[ baseVoiInVps ][ voiInVps ], m_aaiCodedOffset[ baseVoiInVps ][ voiInVps ], 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, "#ViewOrderIdx     ViewIdVal\n" );
314      fprintf( m_pCodedScaleOffsetFile, "#------------ -------------\n" );
315     
316      for( UInt voiInVps = 0; voiInVps < m_vps->getNumViews(); voiInVps++ )
317      {
318        fprintf( m_pCodedScaleOffsetFile, "%13d %13d\n", m_vps->getViewOIdxList( voiInVps ), m_vps->getViewIdVal( m_vps->getViewOIdxList( voiInVps ) ) );
319      }
320      fprintf( m_pCodedScaleOffsetFile, "\n\n");
321      fprintf( m_pCodedScaleOffsetFile, "# StartFrame     EndFrame    TargetVOI      BaseVOI   CodedScale  CodedOffset    Precision\n" );
322      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------ ------------ ------------ ------------ ------------ ------------\n" );
323    }
324    if( iPOC == m_firstReceivedPoc || m_bCamParsVaryOverTime  )
325    {
326      Int iS = iPOC;
327      Int iE = ( m_bCamParsVaryOverTime ? iPOC : ~( 1 << 31 ) );
328      for( UInt voiInVps = 0; voiInVps < m_vps->getNumViews(); voiInVps++ )
329      {
330        for( UInt baseVoiInVps = 0; baseVoiInVps < m_vps->getNumViews(); baseVoiInVps++ )
331        {
332          if( voiInVps != baseVoiInVps )
333          {
334            if ( m_receivedIdc[baseVoiInVps][voiInVps] != 0 )
335            {           
336              fprintf( m_pCodedScaleOffsetFile, "%12d %12d %12d %12d %12d %12d %12d\n",
337                iS, iE, m_vps->getViewOIdxList( voiInVps ), m_vps->getViewOIdxList( baseVoiInVps ), 
338                m_aaiCodedScale [ baseVoiInVps ][ voiInVps ], 
339                m_aaiCodedOffset[ baseVoiInVps ][ voiInVps ], m_vps->getCpPrecision() );
340            }           
341          }
342        }
343      }
344    }
345  }
346}
347#endif
348
349
350TDecTop::TDecTop()
351  : m_iMaxRefPicNum(0)
352  , m_associatedIRAPType(NAL_UNIT_INVALID)
353  , m_pocCRA(0)
354  , m_pocRandomAccess(MAX_INT)
355  , m_cListPic()
356#if !NH_MV
357  , m_parameterSetManager()
358#endif
359  , m_apcSlicePilot(NULL)
360  , m_SEIs()
361  , m_cPrediction()
362  , m_cTrQuant()
363  , m_cGopDecoder()
364  , m_cSliceDecoder()
365  , m_cCuDecoder()
366  , m_cEntropyDecoder()
367  , m_cCavlcDecoder()
368  , m_cSbacDecoder()
369  , m_cBinCABAC()
370  , m_seiReader()
371  , m_cLoopFilter()
372  , m_cSAO()
373  , m_pcPic(NULL)
374  , m_prevPOC(MAX_INT)
375  , m_prevTid0POC(0)
376  , m_bFirstSliceInPicture(true)
377  , m_bFirstSliceInSequence(true)
378  , m_prevSliceSkipped(false)
379  , m_skippedPOC(0)
380  , m_bFirstSliceInBitstream(true)
381  , m_lastPOCNoOutputPriorPics(-1)
382  , m_isNoOutputPriorPics(false)
383  , m_craNoRaslOutputFlag(false)
384#if O0043_BEST_EFFORT_DECODING
385  , m_forceDecodeBitDepth(8)
386#endif
387  , m_pDecodedSEIOutputStream(NULL)
388  , m_warningMessageSkipPicture(false)
389  , m_prefixSEINALUs()
390{
391#if ENC_DEC_TRACE
392#if NH_MV
393  if ( g_hTrace == NULL )
394  {
395#endif
396  if (g_hTrace == NULL)
397  {
398    g_hTrace = fopen( "TraceDec.txt", "wb" );
399  }
400  g_bJustDoIt = g_bEncDecTraceDisable;
401  g_nSymbolCounter = 0;
402#if NH_MV
403  }
404#endif
405#endif
406#if NH_MV
407  m_isLastNALWasEos = false;
408  m_layerId = 0;
409  m_viewId = 0;
410#if NH_3D
411  m_viewIndex = 0; 
412  m_isDepth = false;
413  m_pcCamParsCollector = 0;
414#endif
415#if NH_MV
416  m_targetOlsIdx = -1; 
417#endif
418#endif
419
420}
421
422TDecTop::~TDecTop()
423{
424#if ENC_DEC_TRACE
425#if H_MV_ENC_DEC_TRAC_FIX
426  if (g_hTrace != stdout && g_hTrace != NULL)
427#else
428  if (g_hTrace != stdout)
429#endif
430  {
431    fclose( g_hTrace );
432#if H_MV_ENC_DEC_TRAC_FIX
433    g_hTrace = NULL;
434#endif
435  }
436#endif
437  while (!m_prefixSEINALUs.empty())
438  {
439    delete m_prefixSEINALUs.front();
440    m_prefixSEINALUs.pop_front();
441  }
442}
443
444Void TDecTop::create()
445{
446  m_cGopDecoder.create();
447  m_apcSlicePilot = new TComSlice;
448  m_uiSliceIdx = 0;
449}
450
451Void TDecTop::destroy()
452{
453  m_cGopDecoder.destroy();
454
455  delete m_apcSlicePilot;
456  m_apcSlicePilot = NULL;
457
458  m_cSliceDecoder.destroy();
459}
460
461Void TDecTop::init()
462{
463  // initialize ROM
464#if !NH_MV
465  initROM();
466#endif
467#if NH_MV
468  m_cCavlcDecoder.setDecTop( this ); 
469#endif
470  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
471  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
472  m_cEntropyDecoder.init(&m_cPrediction);
473}
474
475Void TDecTop::deletePicBuffer ( )
476{
477  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
478  Int iSize = Int( m_cListPic.size() );
479
480  for (Int i = 0; i < iSize; i++ )
481  {
482    TComPic* pcPic = *(iterPic++);
483#if NH_MV
484    if( pcPic )
485    {
486#endif
487    pcPic->destroy();
488
489    delete pcPic;
490    pcPic = NULL;
491#if NH_MV
492    }
493#endif
494  }
495
496  m_cSAO.destroy();
497
498  m_cLoopFilter.        destroy();
499
500#if !NH_MV
501  // destroy ROM
502  destroyROM();
503#endif
504}
505
506Void TDecTop::xGetNewPicBuffer ( const TComSPS &sps, const TComPPS &pps, TComPic*& rpcPic, const UInt temporalLayer )
507{
508#if NH_MV
509  if ( getLayerId() == 0 )
510  { 
511    m_iMaxRefPicNum = sps.getMaxDecPicBuffering(temporalLayer);     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
512  }
513  else
514  {
515    //GTCIC
516    //m_iMaxRefPicNum = pcSlice->getVPS()->getMaxDecPicBuffering(pcSlice->getTLayer());   
517#if H_MV_HLS7_GEN
518    TComVPS* vps         = pcSlice->getVPS();
519    TComDpbSize* dpbSize = vps->getDpbSize(); 
520    Int lsIdx            = vps->olsIdxToLsIdx( getTargetOutputLayerSetIdx()); // Is this correct, seems to be missing in spec?
521    Int layerIdx         = vps->getIdxInLayerSet     ( lsIdx, getLayerId() ); 
522    Int subDpbIdx        = dpbSize->getSubDpbAssigned( lsIdx, layerIdx ); 
523    m_iMaxRefPicNum      = dpbSize->getMaxVpsDecPicBufferingMinus1(getTargetOutputLayerSetIdx(), subDpbIdx , vps->getSubLayersVpsMaxMinus1( vps->getLayerIdInVps( getLayerId() ) ) + 1 ) + 1 ; 
524#endif   
525  }
526#else
527  m_iMaxRefPicNum = sps.getMaxDecPicBuffering(temporalLayer);     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
528#endif
529  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
530  {
531    rpcPic = new TComPic();
532
533    rpcPic->create ( sps, pps, true);
534
535    m_cListPic.pushBack( rpcPic );
536
537    return;
538  }
539
540  Bool bBufferIsAvailable = false;
541  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
542  while (iterPic != m_cListPic.end())
543  {
544    rpcPic = *(iterPic++);
545    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
546    {
547      rpcPic->setOutputMark(false);
548#if NH_MV
549      rpcPic->setPicOutputFlag(false); 
550#endif
551      bBufferIsAvailable = true;
552      break;
553    }
554
555    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
556    {
557      rpcPic->setOutputMark(false);
558#if NH_MV
559      rpcPic->setPicOutputFlag(false); 
560#endif
561      rpcPic->setReconMark( false );
562      rpcPic->getPicYuvRec()->setBorderExtension( false );
563      bBufferIsAvailable = true;
564      break;
565    }
566  }
567
568  if ( !bBufferIsAvailable )
569  {
570    //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer.
571    m_iMaxRefPicNum++;
572    rpcPic = new TComPic();
573    m_cListPic.pushBack( rpcPic );
574  }
575  rpcPic->destroy();
576  rpcPic->create ( sps, pps, true);
577}
578#if NH_MV
579Void TDecTop::endPicDecoding(Int& poc, TComList<TComPic*>*& rpcListPic, std::vector<Int>& targetDecLayerIdSet )
580#else
581Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic)
582#endif
583{
584  if (!m_pcPic)
585  {
586    /* nothing to deblock */
587    return;
588  }
589
590  TComPic*   pcPic         = m_pcPic;
591
592  // Execute Deblock + Cleanup
593
594  m_cGopDecoder.filterPicture(pcPic);
595
596  TComSlice::sortPicList( m_cListPic ); // sorting for application output
597  poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
598  rpcListPic          = &m_cListPic;
599  m_cCuDecoder.destroy();
600#if NH_MV
601  TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
602  TComSlice::markCurrPic( pcPic ); 
603#endif
604  m_bFirstSliceInPicture  = true;
605
606  return;
607}
608
609Void TDecTop::checkNoOutputPriorPics (TComList<TComPic*>* pcListPic)
610{
611  if (!pcListPic || !m_isNoOutputPriorPics)
612  {
613    return;
614  }
615
616  TComList<TComPic*>::iterator  iterPic   = pcListPic->begin();
617
618  while (iterPic != pcListPic->end())
619  {
620    TComPic* pcPicTmp = *(iterPic++);
621    if (m_lastPOCNoOutputPriorPics != pcPicTmp->getPOC())
622    {
623      pcPicTmp->setOutputMark(false);
624#if NH_MV
625      pcPicTmp->setPicOutputFlag(false); 
626#endif
627    }
628  }
629}
630
631Void TDecTop::xCreateLostPicture(Int iLostPoc)
632{
633  printf("\ninserting lost poc : %d\n",iLostPoc);
634  TComPic *cFillPic;
635  xGetNewPicBuffer(*(m_parameterSetManager.getFirstSPS()), *(m_parameterSetManager.getFirstPPS()), cFillPic, 0);
636  cFillPic->getSlice(0)->initSlice();
637
638  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
639  Int closestPoc = 1000000;
640  while ( iterPic != m_cListPic.end())
641  {
642    TComPic * rpcPic = *(iterPic++);
643    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())
644    {
645      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
646    }
647  }
648  iterPic = m_cListPic.begin();
649  while ( iterPic != m_cListPic.end())
650  {
651    TComPic *rpcPic = *(iterPic++);
652    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
653    {
654      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
655      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
656      break;
657    }
658  }
659  cFillPic->setCurrSliceIdx(0);
660  for(Int ctuRsAddr=0; ctuRsAddr<cFillPic->getNumberOfCtusInFrame(); ctuRsAddr++)
661  {
662    cFillPic->getCtu(ctuRsAddr)->initCtu(cFillPic, ctuRsAddr);
663  }
664  cFillPic->getSlice(0)->setReferenced(true);
665  cFillPic->getSlice(0)->setPOC(iLostPoc);
666  xUpdatePreviousTid0POC(cFillPic->getSlice(0));
667  cFillPic->setReconMark(true);
668  cFillPic->setOutputMark(true);
669  if(m_pocRandomAccess == MAX_INT)
670  {
671    m_pocRandomAccess = iLostPoc;
672  }
673}
674
675
676Void TDecTop::xActivateParameterSets()
677{
678  if (m_bFirstSliceInPicture)
679  {
680    const TComPPS *pps = m_parameterSetManager.getPPS(m_apcSlicePilot->getPPSId()); // this is a temporary PPS object. Do not store this value
681    assert (pps != 0);
682
683    const TComSPS *sps = m_parameterSetManager.getSPS(pps->getSPSId());             // this is a temporary SPS object. Do not store this value
684    assert (sps != 0);
685
686    m_parameterSetManager.clearSPSChangedFlag(sps->getSPSId());
687    m_parameterSetManager.clearPPSChangedFlag(pps->getPPSId());
688#if NH_MV
689    const TComVPS* vps = m_parameterSetManager.getVPS(sps->getVPSId());
690    assert (vps != 0); 
691    if (!m_parameterSetManager.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP(), m_layerId ) )
692#else
693    if (false == m_parameterSetManager.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
694#endif
695    {
696      printf ("Parameter set activation failed!");
697      assert (0);
698    }
699
700#if NH_MV
701  // When the value of vps_num_rep_formats_minus1 in the active VPS is equal to 0
702  if ( vps->getVpsNumRepFormatsMinus1() == 0 )
703  {
704    //, it is a requirement of bitstream conformance that the value of update_rep_format_flag shall be equal to 0.
705    assert( sps->getUpdateRepFormatFlag() == false ); 
706  }
707  sps->checkRpsMaxNumPics( vps, getLayerId() ); 
708
709  // It is a requirement of bitstream conformance that, when the SPS is referred to by
710  // any current picture that belongs to an independent non-base layer, the value of
711  // MultiLayerExtSpsFlag derived from the SPS shall be equal to 0.
712
713  if ( m_layerId > 0 && vps->getNumRefLayers( m_layerId ) == 0 )
714  { 
715    assert( sps->getMultiLayerExtSpsFlag() == 0 ); 
716  }
717#endif
718
719    xParsePrefixSEImessages();
720
721#if RExt__HIGH_BIT_DEPTH_SUPPORT==0
722    if (sps->getSpsRangeExtension().getExtendedPrecisionProcessingFlag() || sps->getBitDepth(CHANNEL_TYPE_LUMA)>12 || sps->getBitDepth(CHANNEL_TYPE_CHROMA)>12 )
723    {
724      printf("High bit depth support must be enabled at compile-time in order to decode this bitstream\n");
725      assert (0);
726      exit(1);
727    }
728#endif
729
730    // NOTE: globals were set up here originally. You can now use:
731    // g_uiMaxCUDepth = sps->getMaxTotalCUDepth();
732    // g_uiAddCUDepth = sps->getMaxTotalCUDepth() - sps->getLog2DiffMaxMinCodingBlockSize()
733
734    //  Get a new picture buffer. This will also set up m_pcPic, and therefore give us a SPS and PPS pointer that we can use.
735    xGetNewPicBuffer (*(sps), *(pps), m_pcPic, m_apcSlicePilot->getTLayer());
736    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
737#if NH_MV
738    m_apcSlicePilot->createInterLayerReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
739#endif
740
741    // make the slice-pilot a real slice, and set up the slice-pilot for the next slice
742    assert(m_pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
743    m_apcSlicePilot = m_pcPic->getPicSym()->swapSliceObject(m_apcSlicePilot, m_uiSliceIdx);
744
745    // we now have a real slice:
746    TComSlice *pSlice = m_pcPic->getSlice(m_uiSliceIdx);
747
748    // Update the PPS and SPS pointers with the ones of the picture.
749    pps=pSlice->getPPS();
750    sps=pSlice->getSPS();
751
752#if NH_MV
753    vps=pSlice->getVPS(); 
754    // 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.
755    assert( pps->getLayerId() == m_layerId || pps->getLayerId( ) == 0 || vps->getDependencyFlag( m_layerId, pps->getLayerId() ) );   
756    // 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.
757    assert( sps->getLayerId() == m_layerId || sps->getLayerId( ) == 0 || vps->getDependencyFlag( m_layerId, sps->getLayerId() ) );
758#endif
759
760#if NH_3D
761    if ( !m_pcCamParsCollector->isInitialized() )
762    {
763      m_pcCamParsCollector->init( vps );
764    }
765#endif
766    // Initialise the various objects for the new set of settings
767    m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxTotalCUDepth(), pps->getPpsRangeExtension().getLog2SaoOffsetScale(CHANNEL_TYPE_LUMA), pps->getPpsRangeExtension().getLog2SaoOffsetScale(CHANNEL_TYPE_CHROMA) );
768    m_cLoopFilter.create( sps->getMaxTotalCUDepth() );
769    m_cPrediction.initTempBuff(sps->getChromaFormatIdc());
770
771
772    Bool isField = false;
773    Bool isTopField = false;
774
775    if(!m_SEIs.empty())
776    {
777      // Check if any new Picture Timing SEI has arrived
778      SEIMessages pictureTimingSEIs = getSeisByType(m_SEIs, SEI::PICTURE_TIMING);
779      if (pictureTimingSEIs.size()>0)
780      {
781        SEIPictureTiming* pictureTiming = (SEIPictureTiming*) *(pictureTimingSEIs.begin());
782        isField    = (pictureTiming->m_picStruct == 1) || (pictureTiming->m_picStruct == 2) || (pictureTiming->m_picStruct == 9) || (pictureTiming->m_picStruct == 10) || (pictureTiming->m_picStruct == 11) || (pictureTiming->m_picStruct == 12);
783        isTopField = (pictureTiming->m_picStruct == 1) || (pictureTiming->m_picStruct == 9) || (pictureTiming->m_picStruct == 11);
784      }
785    }
786
787    //Set Field/Frame coding mode
788    m_pcPic->setField(isField);
789    m_pcPic->setTopField(isTopField);
790
791    // transfer any SEI messages that have been received to the picture
792    m_pcPic->setSEIs(m_SEIs);
793    m_SEIs.clear();
794
795    // Recursive structure
796    m_cCuDecoder.create ( sps->getMaxTotalCUDepth(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getChromaFormatIdc() );
797    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
798    m_cTrQuant.init     ( sps->getMaxTrSize() );
799
800    m_cSliceDecoder.create();
801  }
802  else
803  {
804    // make the slice-pilot a real slice, and set up the slice-pilot for the next slice
805    m_pcPic->allocateNewSlice();
806    assert(m_pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
807    m_apcSlicePilot = m_pcPic->getPicSym()->swapSliceObject(m_apcSlicePilot, m_uiSliceIdx);
808
809    TComSlice *pSlice = m_pcPic->getSlice(m_uiSliceIdx); // we now have a real slice.
810
811    const TComSPS *sps = pSlice->getSPS();
812    const TComPPS *pps = pSlice->getPPS();
813
814    // check that the current active PPS has not changed...
815    if (m_parameterSetManager.getSPSChangedFlag(sps->getSPSId()) )
816    {
817      printf("Error - a new SPS has been decoded while processing a picture\n");
818      exit(1);
819    }
820    if (m_parameterSetManager.getPPSChangedFlag(pps->getPPSId()) )
821    {
822      printf("Error - a new PPS has been decoded while processing a picture\n");
823      exit(1);
824    }
825
826    xParsePrefixSEImessages();
827
828    // Check if any new SEI has arrived
829     if(!m_SEIs.empty())
830     {
831       // Currently only decoding Unit SEI message occurring between VCL NALUs copied
832       SEIMessages &picSEI = m_pcPic->getSEIs();
833       SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
834       picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
835       deleteSEIs(m_SEIs);
836     }
837  }
838}
839Void TDecTop::xParsePrefixSEIsForUnknownVCLNal()
840{
841  while (!m_prefixSEINALUs.empty())
842  {
843    // do nothing?
844    printf("Discarding Prefix SEI associated with unknown VCL NAL unit.\n");
845    delete m_prefixSEINALUs.front();
846  }
847  // TODO: discard following suffix SEIs as well?
848}
849
850
851Void TDecTop::xParsePrefixSEImessages()
852{
853  while (!m_prefixSEINALUs.empty())
854  {
855    InputNALUnit &nalu=*m_prefixSEINALUs.front();
856#if NH_MV
857    m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_SEIs, nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS( getLayerId() ), m_pDecodedSEIOutputStream );
858#else
859    m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_SEIs, nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS(), m_pDecodedSEIOutputStream );
860#endif
861    delete m_prefixSEINALUs.front();
862    m_prefixSEINALUs.pop_front();
863  }
864}
865
866
867#if NH_MV
868Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay, Bool newLayerFlag, Bool& sliceSkippedFlag  )
869{
870  assert( nalu.m_nuhLayerId == m_layerId ); 
871#else
872Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
873{
874#endif
875  m_apcSlicePilot->initSlice(); // the slice pilot is an object to prepare for a new slice
876                                // it is not associated with picture, sps or pps structures.
877
878  if (m_bFirstSliceInPicture)
879  {
880    m_uiSliceIdx = 0;
881  }
882  else
883  {
884    m_apcSlicePilot->copySliceInfo( m_pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
885  }
886  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
887
888  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
889  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
890                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
891                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
892                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
893                           m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
894  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
895  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
896  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
897
898#if ENC_DEC_TRACE
899  const UInt64 originalSymbolCount = g_nSymbolCounter;
900#endif
901
902#if NH_MV
903  m_apcSlicePilot->setRefPicSetInterLayer( & m_refPicSetInterLayer0, &m_refPicSetInterLayer1 ); 
904  m_apcSlicePilot->setLayerId( nalu.m_nuhLayerId );
905#endif
906
907  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManager, m_prevTid0POC);
908
909  // set POC for dependent slices in skipped pictures
910  if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped)
911  {
912    m_apcSlicePilot->setPOC(m_skippedPOC);
913  }
914
915  xUpdatePreviousTid0POC(m_apcSlicePilot);
916
917  m_apcSlicePilot->setAssociatedIRAPPOC(m_pocCRA);
918  m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType);
919#if NH_MV 
920  const TComVPS* vps     = m_apcSlicePilot->getVPS();
921  Int layerId            = nalu.m_nuhLayerId;   
922  setViewId   ( vps->getViewId   ( layerId )      ); 
923#if NH_3D
924  setViewIndex( vps->getViewIndex( layerId )      ); 
925  setIsDepth  ( vps->getDepthId  ( layerId ) == 1 ); 
926  m_ivPicLists->setVPS( vps ); 
927#endif
928#endif
929
930  //For inference of NoOutputOfPriorPicsFlag
931  if (m_apcSlicePilot->getRapPicFlag())
932  {
933    if ((m_apcSlicePilot->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_apcSlicePilot->getNalUnitType() <= NAL_UNIT_CODED_SLICE_IDR_N_LP) || 
934        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_bFirstSliceInSequence) ||
935        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getHandleCraAsBlaFlag()))
936    {
937      m_apcSlicePilot->setNoRaslOutputFlag(true);
938    }
939    //the inference for NoOutputPriorPicsFlag
940    if (!m_bFirstSliceInBitstream && m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag())
941    {
942      if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
943      {
944        m_apcSlicePilot->setNoOutputPriorPicsFlag(true);
945      }
946    }
947    else
948    {
949      m_apcSlicePilot->setNoOutputPriorPicsFlag(false);
950    }
951
952    if(m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
953    {
954      m_craNoRaslOutputFlag = m_apcSlicePilot->getNoRaslOutputFlag();
955    }
956  }
957  if (m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoOutputPriorPicsFlag())
958  {
959    m_lastPOCNoOutputPriorPics = m_apcSlicePilot->getPOC();
960    m_isNoOutputPriorPics = true;
961  }
962  else
963  {
964    m_isNoOutputPriorPics = false;
965  }
966
967  //For inference of PicOutputFlag
968  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R)
969  {
970    if ( m_craNoRaslOutputFlag )
971    {
972      m_apcSlicePilot->setPicOutputFlag(false);
973    }
974  }
975
976  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_craNoRaslOutputFlag) //Reset POC MSB when CRA has NoRaslOutputFlag equal to 1
977  {
978    TComPPS *pps = m_parameterSetManager.getPPS(m_apcSlicePilot->getPPSId());
979    assert (pps != 0);
980    TComSPS *sps = m_parameterSetManager.getSPS(pps->getSPSId());
981    assert (sps != 0);
982    Int iMaxPOClsb = 1 << sps->getBitsForPOC();
983    m_apcSlicePilot->setPOC( m_apcSlicePilot->getPOC() & (iMaxPOClsb - 1) );
984    xUpdatePreviousTid0POC(m_apcSlicePilot);
985  }
986#if NH_MV
987    xCeckNoClrasOutput();
988#endif
989
990  // Skip pictures due to random access
991
992#if NH_MV
993  if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay, vps))
994#else
995  if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
996#endif
997  {
998    m_prevSliceSkipped = true;
999    m_skippedPOC = m_apcSlicePilot->getPOC();
1000#if NH_MV
1001    sliceSkippedFlag = true; 
1002#endif
1003    return false;
1004  }
1005  // Skip TFD pictures associated with BLA/BLANT pictures
1006  if (isSkipPictureForBLA(iPOCLastDisplay))
1007  {
1008    m_prevSliceSkipped = true;
1009    m_skippedPOC = m_apcSlicePilot->getPOC();
1010#if NH_MV
1011    sliceSkippedFlag = true; 
1012#endif
1013    return false;
1014  }
1015
1016  // clear previous slice skipped flag
1017  m_prevSliceSkipped = false;
1018
1019  //we should only get a different poc for a new picture (with CTU address==0)
1020  if (!m_apcSlicePilot->getDependentSliceSegmentFlag() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (m_apcSlicePilot->getSliceCurStartCtuTsAddr() != 0))
1021  {
1022    printf ("Warning, the first slice of a picture might have been lost!\n");
1023  }
1024
1025  // exit when a new picture is found
1026  if (!m_apcSlicePilot->getDependentSliceSegmentFlag() && (m_apcSlicePilot->getSliceCurStartCtuTsAddr() == 0 && !m_bFirstSliceInPicture) )
1027  {
1028    if (m_prevPOC >= m_pocRandomAccess)
1029    {
1030      m_prevPOC = m_apcSlicePilot->getPOC();
1031#if ENC_DEC_TRACE
1032      //rewind the trace counter since we didn't actually decode the slice
1033      g_nSymbolCounter = originalSymbolCount;
1034#endif
1035      return true;
1036    }
1037    m_prevPOC = m_apcSlicePilot->getPOC();
1038  }
1039#if NH_MV
1040  if ( newLayerFlag )
1041  {
1042    return false; 
1043  }
1044#if ENC_DEC_TRACE
1045#if H_MV_ENC_DEC_TRAC
1046  // parse remainder of SH
1047   g_disableHLSTrace = false; 
1048#endif
1049#endif
1050#endif
1051
1052#if NH_MV
1053   // This part needs further testing !
1054   if ( m_apcSlicePilot->getPocResetFlag() )
1055   {   
1056     xResetPocInPicBuffer();
1057   }
1058
1059   if ( m_apcSlicePilot->getTLayer() == 0 && m_apcSlicePilot->getEnableTMVPFlag() == 0 )
1060  {
1061    //update all pics in the DPB such that they cannot be used for TMPV ref
1062    TComList<TComPic*>::iterator  iterRefPic = m_cListPic.begin(); 
1063    while( iterRefPic != m_cListPic.end() )
1064    {
1065      TComPic *refPic = *iterRefPic;
1066      if( ( refPic->getLayerId() == m_apcSlicePilot->getLayerId() ) && refPic->getReconMark() )
1067      {
1068        for(Int i = refPic->getNumAllocatedSlice()-1; i >= 0; i--)
1069        {
1070
1071          TComSlice *refSlice = refPic->getSlice(i);
1072          refSlice->setAvailableForTMVPRefFlag( false );
1073        }
1074      }
1075      iterRefPic++;
1076    }
1077  }
1078  m_apcSlicePilot->setAvailableForTMVPRefFlag( true );
1079#endif
1080
1081  //detect lost reference picture and insert copy of earlier frame.
1082  {
1083    Int lostPoc;
1084    while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
1085    {
1086      xCreateLostPicture(lostPoc-1);
1087    }
1088  }
1089
1090  if (!m_apcSlicePilot->getDependentSliceSegmentFlag())
1091  {
1092    m_prevPOC = m_apcSlicePilot->getPOC();
1093  }
1094
1095  // actual decoding starts here
1096  xActivateParameterSets();
1097
1098  m_bFirstSliceInSequence = false;
1099  m_bFirstSliceInBitstream  = false;
1100
1101
1102  TComSlice* pcSlice = m_pcPic->getPicSym()->getSlice(m_uiSliceIdx);
1103
1104  // When decoding the slice header, the stored start and end addresses were actually RS addresses, not TS addresses.
1105  // Now, having set up the maps, convert them to the correct form.
1106  pcSlice->setSliceSegmentCurStartCtuTsAddr( m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceSegmentCurStartCtuTsAddr()) );
1107  pcSlice->setSliceSegmentCurEndCtuTsAddr( m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceSegmentCurEndCtuTsAddr()) );
1108  if(!pcSlice->getDependentSliceSegmentFlag())
1109  {
1110    pcSlice->setSliceCurStartCtuTsAddr(m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceCurStartCtuTsAddr()));
1111    pcSlice->setSliceCurEndCtuTsAddr(m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceCurEndCtuTsAddr()));
1112  }
1113
1114  m_pcPic->setTLayer(nalu.m_temporalId);
1115
1116#if NH_MV
1117  //Check Multiview Main profile constraint in G.11.1.1
1118  //  When ViewOrderIdx[ i ] derived according to any active VPS is equal to 1
1119  //  for the layer with nuh_layer_id equal to i in subBitstream,
1120  //  inter_view_mv_vert_constraint_flag shall be equal to 1
1121  //  in the sps_multilayer_extension( ) syntax structure in each active SPS for that layer.
1122  if( pcSlice->getSPS()->getPTL()->getGeneralPTL()->getProfileIdc()==Profile::MULTIVIEWMAIN
1123      &&
1124      pcSlice->getVPS()->getViewOrderIdx(pcSlice->getVPS()->getLayerIdInNuh(getLayerId()))==1 
1125     )
1126  {
1127    assert( pcSlice->getSPS()->getInterViewMvVertConstraintFlag()==1 );
1128  }
1129#endif
1130#if NH_MV
1131  m_pcPic->setLayerId( nalu.m_nuhLayerId );
1132  m_pcPic->setViewId ( getViewId() );
1133#if NH_3D
1134  m_pcPic->setViewIndex( getViewIndex() );
1135  m_pcPic->setIsDepth  ( getIsDepth  () );
1136  pcSlice->setIvPicLists( m_ivPicLists );         
1137#endif
1138#endif
1139
1140  if (!pcSlice->getDependentSliceSegmentFlag())
1141  {
1142    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_associatedIRAPType, m_cListPic );
1143    // Set reference list
1144#if NH_MV   
1145    std::vector< TComPic* > tempRefPicLists[2];
1146    std::vector< Bool     > usedAsLongTerm [2];
1147    Int       numPocTotalCurr;
1148
1149    pcSlice->getTempRefPicLists( m_cListPic, m_refPicSetInterLayer0, m_refPicSetInterLayer1, tempRefPicLists, usedAsLongTerm, numPocTotalCurr);
1150    pcSlice->setRefPicList     ( tempRefPicLists, usedAsLongTerm, numPocTotalCurr, true ); 
1151#if H_3D
1152    pcSlice->setDefaultRefView();
1153#endif
1154#if H_3D_ARP
1155    pcSlice->setARPStepNum(m_ivPicLists);
1156    if( pcSlice->getARPStepNum() > 1 )
1157    {
1158      // GT: This seems to be broken, not all nuh_layer_ids are necessarily present
1159      for(Int iLayerId = 0; iLayerId < nalu.m_nuhLayerId; iLayerId ++ )
1160      {
1161        Int  iViewIdx =   pcSlice->getVPS()->getViewIndex(iLayerId);
1162        Bool bIsDepth = ( pcSlice->getVPS()->getDepthId  ( iLayerId ) == 1 );
1163        if( iViewIdx<getViewIndex() && !bIsDepth )
1164        {
1165          pcSlice->setBaseViewRefPicList( m_ivPicLists->getPicList( iLayerId ), iViewIdx );
1166        }
1167      }
1168    }
1169#endif
1170#else
1171    pcSlice->setRefPicList( m_cListPic, true );
1172#endif
1173
1174#if NH_3D
1175    pcSlice->checkInCompPredRefLayers(); 
1176#if H_3D_IV_MERGE
1177#if H_3D_FCO
1178    //assert( !getIsDepth() );
1179#else
1180    assert( !getIsDepth() || ( pcSlice->getTexturePic() != 0 ) );
1181#endif
1182#endif   
1183#endif
1184#if NH_MV
1185    if( m_layerId > 0 && !pcSlice->isIntra() && pcSlice->getEnableTMVPFlag() )
1186    {
1187      TComPic* refPic = pcSlice->getRefPic(RefPicList(1 - pcSlice->getColFromL0Flag()), pcSlice->getColRefIdx());
1188
1189      assert ( refPic );
1190      assert ( refPic->getPicSym()->getSlice(0)->getAvailableForTMVPRefFlag() == true );
1191    }
1192#endif
1193
1194    // For generalized B
1195    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
1196    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
1197    {
1198      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
1199      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
1200
1201      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
1202      {
1203        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
1204      }
1205    }
1206    if (!pcSlice->isIntra())
1207    {
1208      Bool bLowDelay = true;
1209      Int  iCurrPOC  = pcSlice->getPOC();
1210      Int iRefIdx = 0;
1211
1212      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
1213      {
1214        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
1215        {
1216          bLowDelay = false;
1217        }
1218      }
1219      if (pcSlice->isInterB())
1220      {
1221        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
1222        {
1223          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
1224          {
1225            bLowDelay = false;
1226          }
1227        }
1228      }
1229
1230      pcSlice->setCheckLDC(bLowDelay);
1231    }
1232
1233    //---------------
1234    pcSlice->setRefPOCList();
1235#if  NH_3D_TMVP
1236    if(pcSlice->getLayerId())
1237    {
1238      pcSlice->generateAlterRefforTMVP();
1239    }
1240#endif
1241  }
1242
1243  m_pcPic->setCurrSliceIdx(m_uiSliceIdx);
1244  if(pcSlice->getSPS()->getScalingListFlag())
1245  {
1246    TComScalingList scalingList;
1247    if(pcSlice->getPPS()->getScalingListPresentFlag())
1248    {
1249      scalingList = pcSlice->getPPS()->getScalingList();
1250    }
1251    else if (pcSlice->getSPS()->getScalingListPresentFlag())
1252    {
1253      scalingList = pcSlice->getSPS()->getScalingList();
1254    }
1255    else
1256    {
1257      scalingList.setDefaultScalingList();
1258    }
1259    m_cTrQuant.setScalingListDec(scalingList);
1260    m_cTrQuant.setUseScalingList(true);
1261  }
1262  else
1263  {
1264    const Int maxLog2TrDynamicRange[MAX_NUM_CHANNEL_TYPE] =
1265    {
1266        pcSlice->getSPS()->getMaxLog2TrDynamicRange(CHANNEL_TYPE_LUMA),
1267        pcSlice->getSPS()->getMaxLog2TrDynamicRange(CHANNEL_TYPE_CHROMA)
1268    };
1269    m_cTrQuant.setFlatScalingList(maxLog2TrDynamicRange, pcSlice->getSPS()->getBitDepths());
1270    m_cTrQuant.setUseScalingList(false);
1271  }
1272
1273#if H_3D_IV_MERGE
1274#if H_3D_FCO
1275  if( !pcSlice->getIsDepth() && m_pcCamParsCollector )
1276#else
1277  if( pcSlice->getIsDepth() && m_pcCamParsCollector )
1278#endif
1279  {
1280    m_pcCamParsCollector->copyCamParamForSlice( pcSlice );
1281  }
1282#endif
1283  //  Decode a picture
1284  m_cGopDecoder.decompressSlice(&(nalu.getBitstream()), m_pcPic);
1285
1286#if NH_3D
1287  if( m_pcCamParsCollector )
1288  {
1289    m_pcCamParsCollector->setSlice( pcSlice );
1290  }
1291#endif
1292
1293  m_bFirstSliceInPicture = false;
1294  m_uiSliceIdx++;
1295
1296  return false;
1297}
1298
1299Void TDecTop::xDecodeVPS(const std::vector<UChar> &naluData)
1300{
1301  TComVPS* vps = new TComVPS();
1302
1303  m_cEntropyDecoder.decodeVPS( vps );
1304  m_parameterSetManager.storeVPS(vps, naluData);
1305}
1306
1307Void TDecTop::xDecodeSPS(const std::vector<UChar> &naluData)
1308{
1309  TComSPS* sps = new TComSPS();
1310#if NH_MV
1311  sps->setLayerId( getLayerId() ); 
1312#endif
1313#if O0043_BEST_EFFORT_DECODING
1314  sps->setForceDecodeBitDepth(m_forceDecodeBitDepth);
1315#endif
1316#if NH_3D
1317  // GT: Please don't add parsing dependency of SPS from VPS here again!!!
1318#endif
1319  m_cEntropyDecoder.decodeSPS( sps );
1320  m_parameterSetManager.storeSPS(sps, naluData);
1321}
1322
1323Void TDecTop::xDecodePPS(const std::vector<UChar> &naluData)
1324{
1325  TComPPS* pps = new TComPPS();
1326#if NH_MV
1327  pps->setLayerId( getLayerId() ); 
1328#endif
1329#if H_3D
1330  // GT: Please don't add parsing dependency of SPS from VPS here again!!!
1331#endif
1332  m_cEntropyDecoder.decodePPS( pps );
1333
1334  m_parameterSetManager.storePPS( pps, naluData);
1335}
1336
1337#if NH_MV
1338Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayerFlag, Bool& sliceSkippedFlag )
1339#else
1340Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1341#endif
1342{
1343#if !NH_MV
1344  // ignore all NAL units of layers > 0
1345  if (nalu.m_nuhLayerId > 0)
1346  {
1347    fprintf (stderr, "Warning: found NAL unit with nuh_layer_id equal to %d. Ignoring.\n", nalu.m_nuhLayerId);
1348    return false;
1349  }
1350#endif
1351  // Initialize entropy decoder
1352  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1353  m_cEntropyDecoder.setBitstream      (&(nalu.getBitstream()));
1354
1355  switch (nalu.m_nalUnitType)
1356  {
1357    case NAL_UNIT_VPS:
1358      xDecodeVPS(nalu.getBitstream().getFifo());
1359#if NH_MV
1360      m_isLastNALWasEos = false;
1361#endif
1362      return false;
1363
1364    case NAL_UNIT_SPS:
1365      xDecodeSPS(nalu.getBitstream().getFifo());
1366      return false;
1367
1368    case NAL_UNIT_PPS:
1369      xDecodePPS(nalu.getBitstream().getFifo());
1370      return false;
1371
1372    case NAL_UNIT_PREFIX_SEI:
1373      // Buffer up prefix SEI messages until SPS of associated VCL is known.
1374      m_prefixSEINALUs.push_back(new InputNALUnit(nalu));
1375      return false;
1376
1377    case NAL_UNIT_SUFFIX_SEI:
1378#if NH_MV
1379      if ( nalu.m_nalUnitType == NAL_UNIT_SUFFIX_SEI )
1380      {
1381        assert( m_isLastNALWasEos == false );
1382      }
1383#endif
1384      if (m_pcPic)
1385      {
1386#if NH_MV
1387        m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_pcPic->getSEIs(), nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS( getLayerId() ), m_pDecodedSEIOutputStream );
1388#else
1389        m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_pcPic->getSEIs(), nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS(), m_pDecodedSEIOutputStream );
1390#endif
1391      }
1392      else
1393      {
1394        printf ("Note: received suffix SEI but no picture currently active.\n");
1395      }
1396      return false;
1397
1398    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1399    case NAL_UNIT_CODED_SLICE_TRAIL_N:
1400    case NAL_UNIT_CODED_SLICE_TSA_R:
1401    case NAL_UNIT_CODED_SLICE_TSA_N:
1402    case NAL_UNIT_CODED_SLICE_STSA_R:
1403    case NAL_UNIT_CODED_SLICE_STSA_N:
1404    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
1405    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
1406    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1407    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
1408    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
1409    case NAL_UNIT_CODED_SLICE_CRA:
1410    case NAL_UNIT_CODED_SLICE_RADL_N:
1411    case NAL_UNIT_CODED_SLICE_RADL_R:
1412    case NAL_UNIT_CODED_SLICE_RASL_N:
1413    case NAL_UNIT_CODED_SLICE_RASL_R:
1414#if NH_MV
1415      if (nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_N ||
1416          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_N ||
1417          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_N ||
1418          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
1419          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N )
1420      {
1421        assert( m_isLastNALWasEos == false );
1422      }
1423      else
1424      {
1425        m_isLastNALWasEos = false;
1426      }
1427      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, newLayerFlag, sliceSkippedFlag );
1428#else
1429      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1430#endif
1431      break;
1432
1433    case NAL_UNIT_EOS:
1434#if NH_MV
1435      assert( m_isLastNALWasEos == false );
1436      //Check layer id of the nalu. if it is not 0, give a warning message and just return without doing anything.
1437      if (nalu.m_nuhLayerId > 0)
1438      {
1439        printf( "\nThis bitstream has EOS with non-zero layer id.\n" );
1440        return false;
1441      }
1442      m_isLastNALWasEos = true;
1443#endif
1444      m_associatedIRAPType = NAL_UNIT_INVALID;
1445      m_pocCRA = 0;
1446      m_pocRandomAccess = MAX_INT;
1447      m_prevPOC = MAX_INT;
1448      m_prevSliceSkipped = false;
1449      m_skippedPOC = 0;
1450      return false;
1451
1452    case NAL_UNIT_ACCESS_UNIT_DELIMITER:
1453      {
1454        AUDReader audReader;
1455        UInt picType;
1456        audReader.parseAccessUnitDelimiter(&(nalu.getBitstream()),picType);
1457        printf ("Note: found NAL_UNIT_ACCESS_UNIT_DELIMITER\n");
1458      return false;
1459      }
1460
1461    case NAL_UNIT_EOB:
1462      return false;
1463
1464    case NAL_UNIT_FILLER_DATA:
1465      {
1466        FDReader fdReader;
1467        UInt size;
1468        fdReader.parseFillerData(&(nalu.getBitstream()),size);
1469        printf ("Note: found NAL_UNIT_FILLER_DATA with %u bytes payload.\n", size);
1470#if NH_MV
1471      assert( m_isLastNALWasEos == false );
1472#endif
1473      return false;
1474      }
1475
1476    case NAL_UNIT_RESERVED_VCL_N10:
1477    case NAL_UNIT_RESERVED_VCL_R11:
1478    case NAL_UNIT_RESERVED_VCL_N12:
1479    case NAL_UNIT_RESERVED_VCL_R13:
1480    case NAL_UNIT_RESERVED_VCL_N14:
1481    case NAL_UNIT_RESERVED_VCL_R15:
1482
1483    case NAL_UNIT_RESERVED_IRAP_VCL22:
1484    case NAL_UNIT_RESERVED_IRAP_VCL23:
1485
1486    case NAL_UNIT_RESERVED_VCL24:
1487    case NAL_UNIT_RESERVED_VCL25:
1488    case NAL_UNIT_RESERVED_VCL26:
1489    case NAL_UNIT_RESERVED_VCL27:
1490    case NAL_UNIT_RESERVED_VCL28:
1491    case NAL_UNIT_RESERVED_VCL29:
1492    case NAL_UNIT_RESERVED_VCL30:
1493    case NAL_UNIT_RESERVED_VCL31:
1494      printf ("Note: found reserved VCL NAL unit.\n");
1495      xParsePrefixSEIsForUnknownVCLNal();
1496      return false;
1497
1498    case NAL_UNIT_RESERVED_NVCL41:
1499    case NAL_UNIT_RESERVED_NVCL42:
1500    case NAL_UNIT_RESERVED_NVCL43:
1501    case NAL_UNIT_RESERVED_NVCL44:
1502    case NAL_UNIT_RESERVED_NVCL45:
1503    case NAL_UNIT_RESERVED_NVCL46:
1504    case NAL_UNIT_RESERVED_NVCL47:
1505      printf ("Note: found reserved NAL unit.\n");
1506      return false;
1507    case NAL_UNIT_UNSPECIFIED_48:
1508    case NAL_UNIT_UNSPECIFIED_49:
1509    case NAL_UNIT_UNSPECIFIED_50:
1510    case NAL_UNIT_UNSPECIFIED_51:
1511    case NAL_UNIT_UNSPECIFIED_52:
1512    case NAL_UNIT_UNSPECIFIED_53:
1513    case NAL_UNIT_UNSPECIFIED_54:
1514    case NAL_UNIT_UNSPECIFIED_55:
1515    case NAL_UNIT_UNSPECIFIED_56:
1516    case NAL_UNIT_UNSPECIFIED_57:
1517    case NAL_UNIT_UNSPECIFIED_58:
1518    case NAL_UNIT_UNSPECIFIED_59:
1519    case NAL_UNIT_UNSPECIFIED_60:
1520    case NAL_UNIT_UNSPECIFIED_61:
1521    case NAL_UNIT_UNSPECIFIED_62:
1522    case NAL_UNIT_UNSPECIFIED_63:
1523      printf ("Note: found unspecified NAL unit.\n");
1524      return false;
1525    default:
1526      assert (0);
1527      break;
1528  }
1529
1530  return false;
1531}
1532
1533/** Function for checking if picture should be skipped because of association with a previous BLA picture
1534 * \param iPOCLastDisplay POC of last picture displayed
1535 * \returns true if the picture should be skipped
1536 * This function skips all TFD pictures that follow a BLA picture
1537 * in decoding order and precede it in output order.
1538 */
1539Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
1540{
1541  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) &&
1542       m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
1543  {
1544    iPOCLastDisplay++;
1545    return true;
1546  }
1547  return false;
1548}
1549
1550/** Function for checking if picture should be skipped because of random access
1551 * \param iSkipFrame skip frame counter
1552 * \param iPOCLastDisplay POC of last picture displayed
1553 * \returns true if the picture shold be skipped in the random access.
1554 * This function checks the skipping of pictures in the case of -s option random access.
1555 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1556 * It also checks the type of Nal unit type at the random access point.
1557 * 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.
1558 * If the random access point is IDR all pictures after the random access point are decoded.
1559 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
1560 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
1561 * access point there is no guarantee that the decoder will not crash.
1562 */
1563#if NH_MV
1564Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay, const TComVPS* vps)
1565#else
1566Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay )
1567#endif
1568{
1569  if (iSkipFrame)
1570  {
1571    iSkipFrame--;   // decrement the counter
1572    return true;
1573  }
1574#if NH_MV
1575  else if ( !m_layerInitilizedFlag[ m_layerId ] ) // start of random access point, m_pocRandomAccess has not been set yet.
1576#else
1577  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1578#endif
1579  {
1580    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
1581        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1582        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1583        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
1584    {
1585
1586#if NH_MV
1587      if ( xAllRefLayersInitilized( vps ) )
1588      {
1589        m_layerInitilizedFlag[ m_layerId ] = true; 
1590        m_pocRandomAccess = m_apcSlicePilot->getPOC();
1591      }
1592      else
1593      {
1594        return true; 
1595      }
1596#else
1597      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
1598      m_pocRandomAccess = m_apcSlicePilot->getPOC();
1599#endif
1600    }
1601    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
1602    {
1603#if NH_MV
1604      if ( xAllRefLayersInitilized( vps) )
1605      {
1606        m_layerInitilizedFlag[ m_layerId ] = true; 
1607        m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1608      }
1609      else 
1610      {
1611        return true; 
1612      }
1613#else
1614      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1615#endif
1616    }
1617    else
1618    {
1619#if NH_MV
1620      static Bool warningMessage[MAX_NUM_LAYERS];
1621      static Bool warningInitFlag = false;
1622     
1623      if (!warningInitFlag)
1624      {
1625        for ( Int i = 0; i < MAX_NUM_LAYERS; i++)
1626        {
1627          warningMessage[i] = true; 
1628        }
1629        warningInitFlag = true; 
1630      }
1631
1632      if ( warningMessage[getLayerId()] )
1633      {
1634        printf("\nLayer%3d   No valid random access point. VCL NAL units of this layer are discarded until next layer initialization picture. ", getLayerId() ); 
1635        warningMessage[m_layerId] = false; 
1636      }
1637#else
1638      if(!m_warningMessageSkipPicture)
1639      {
1640        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1641        m_warningMessageSkipPicture = true;
1642      }
1643#endif
1644      return true;
1645    }
1646  }
1647  // skip the reordered pictures, if necessary
1648  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))
1649  {
1650    iPOCLastDisplay++;
1651    return true;
1652  }
1653  // if we reach here, then the picture is not skipped.
1654#if NH_MV
1655  return !m_layerInitilizedFlag[ getLayerId() ]; 
1656#else
1657  return false;
1658#endif
1659}
1660#if NH_MV
1661TComPic* TDecTop::getPic( Int poc )
1662{
1663  xGetPic( m_layerId, poc ); 
1664  TComList<TComPic*>* listPic = getListPic();
1665  TComPic* pcPic = NULL;
1666  for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++)
1667  {
1668    if( (*it)->getPOC() == poc )
1669    {
1670      pcPic = *it ;
1671      break ;
1672    }
1673  }
1674  return pcPic;
1675}
1676
1677TComPic* TDecTop::xGetPic( Int layerId, Int poc )
1678{ 
1679  return m_ivPicLists->getPic( layerId, poc ) ;
1680}
1681
1682Void TDecTop::xResetPocInPicBuffer()
1683{
1684  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
1685  while (iterPic != m_cListPic.end())
1686  {
1687    TComPic* pic = *(iterPic++);
1688    if ( pic->getReconMark() )
1689    {
1690      for( Int i = 0; i < pic->getNumAllocatedSlice(); i++)
1691      {
1692        TComSlice* slice = pic->getSlice( i ); 
1693        slice->setPOC ( slice->getPOC() - m_apcSlicePilot->getPocBeforeReset() );           
1694      }         
1695    }     
1696  }
1697}
1698
1699Void TDecTop::xCeckNoClrasOutput()
1700{
1701  // This part needs further testing!
1702  if ( getLayerId() == 0 )
1703  {   
1704    NalUnitType nut = m_apcSlicePilot->getNalUnitType(); 
1705
1706    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 ); 
1707    Bool isIDR  = ( nut == NAL_UNIT_CODED_SLICE_IDR_W_RADL ) || ( nut == NAL_UNIT_CODED_SLICE_IDR_N_LP ); 
1708    Bool noClrasOutputFlag  = isBLA || ( isIDR  &&  m_apcSlicePilot->getCrossLayerBlaFlag() ); 
1709
1710    if ( noClrasOutputFlag ) 
1711    {
1712      for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++)
1713      {
1714        m_layerInitilizedFlag[i] = false; 
1715      } 
1716    }
1717  }
1718}
1719
1720Bool TDecTop::xAllRefLayersInitilized( const TComVPS* vps )
1721{
1722  Bool allRefLayersInitilizedFlag = true;   
1723  for (Int i = 0; i < vps->getNumDirectRefLayers( getLayerId()  ); i++ )
1724  {
1725    Int refLayerId = vps->getIdDirectRefLayer( m_layerId, i ); 
1726    allRefLayersInitilizedFlag = allRefLayersInitilizedFlag && m_layerInitilizedFlag[ refLayerId ]; 
1727  }
1728
1729  return allRefLayersInitilizedFlag;
1730}
1731
1732
1733Void TDecTop::initFromActiveVps( const TComVPS* vps )
1734{
1735  if ( m_targetOlsIdx == -1 )
1736  {
1737    // Not normative! Corresponds to specification by "External Means". (Should be set equal to 0, when no external means available. )
1738    m_targetOlsIdx = vps->getVpsNumLayerSetsMinus1(); 
1739  }
1740#if NH_3D
1741  // Set profile
1742  Int lsIdx = vps->olsIdxToLsIdx( m_targetOlsIdx );
1743  Int lIdx = -1; 
1744  for (Int j = 0; j < vps->getNumLayersInIdList( lsIdx ); j++ )
1745  {
1746    if ( vps->getLayerSetLayerIdList( lsIdx, j ) == getLayerId() )
1747    {
1748      lIdx = j; 
1749      break; 
1750    }       
1751  }
1752  assert( lIdx != -1 ); 
1753
1754  Int profileIdc = vps->getPTL( vps->getProfileTierLevelIdx( m_targetOlsIdx, lIdx ) )->getGeneralPTL()->getProfileIdc();
1755  assert( profileIdc == 1 || profileIdc == 6 || profileIdc == 8 ); 
1756  m_profileIdc = profileIdc;   
1757#endif
1758}
1759#endif
1760
1761//! \}
Note: See TracBrowser for help on using the repository browser.