source: 3DVCSoftware/branches/HTM-14.1-update-dev1-RWTH/source/Lib/TLibDecoder/TDecTop.cpp @ 1251

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