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

Last change on this file since 1274 was 1274, checked in by tech, 9 years ago

Merged HTM-14.1-update-dev3@1273.

  • Property svn:eol-style set to native
File size: 56.7 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 NH_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 NH_3D_NBDV
1152    pcSlice->setDefaultRefView();
1153#endif
1154#if NH_3D_ARP
1155    pcSlice->setARPStepNum(m_ivPicLists);
1156#endif
1157#else
1158    pcSlice->setRefPicList( m_cListPic, true );
1159#endif
1160
1161#if NH_3D
1162    pcSlice->checkInCompPredRefLayers(); 
1163#if NH_3D_IV_MERGE
1164#if H_3D_FCO
1165    //assert( !getIsDepth() );
1166#else
1167    assert( !getIsDepth() || ( pcSlice->getTexturePic() != 0 ) );
1168#endif
1169#endif   
1170#endif
1171#if NH_MV
1172    if( m_layerId > 0 && !pcSlice->isIntra() && pcSlice->getEnableTMVPFlag() )
1173    {
1174      TComPic* refPic = pcSlice->getRefPic(RefPicList(1 - pcSlice->getColFromL0Flag()), pcSlice->getColRefIdx());
1175
1176      assert ( refPic );
1177      assert ( refPic->getPicSym()->getSlice(0)->getAvailableForTMVPRefFlag() == true );
1178    }
1179#endif
1180
1181    // For generalized B
1182    // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
1183    if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
1184    {
1185      Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
1186      pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
1187
1188      for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
1189      {
1190        pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
1191      }
1192    }
1193    if (!pcSlice->isIntra())
1194    {
1195      Bool bLowDelay = true;
1196      Int  iCurrPOC  = pcSlice->getPOC();
1197      Int iRefIdx = 0;
1198
1199      for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
1200      {
1201        if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
1202        {
1203          bLowDelay = false;
1204        }
1205      }
1206      if (pcSlice->isInterB())
1207      {
1208        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
1209        {
1210          if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
1211          {
1212            bLowDelay = false;
1213          }
1214        }
1215      }
1216
1217      pcSlice->setCheckLDC(bLowDelay);
1218    }
1219
1220    //---------------
1221    pcSlice->setRefPOCList();
1222#if  NH_3D_TMVP
1223    if(pcSlice->getLayerId())
1224    {
1225      pcSlice->generateAlterRefforTMVP();
1226    }
1227#endif
1228  }
1229
1230  m_pcPic->setCurrSliceIdx(m_uiSliceIdx);
1231  if(pcSlice->getSPS()->getScalingListFlag())
1232  {
1233    TComScalingList scalingList;
1234    if(pcSlice->getPPS()->getScalingListPresentFlag())
1235    {
1236      scalingList = pcSlice->getPPS()->getScalingList();
1237    }
1238    else if (pcSlice->getSPS()->getScalingListPresentFlag())
1239    {
1240      scalingList = pcSlice->getSPS()->getScalingList();
1241    }
1242    else
1243    {
1244      scalingList.setDefaultScalingList();
1245    }
1246    m_cTrQuant.setScalingListDec(scalingList);
1247    m_cTrQuant.setUseScalingList(true);
1248  }
1249  else
1250  {
1251    const Int maxLog2TrDynamicRange[MAX_NUM_CHANNEL_TYPE] =
1252    {
1253        pcSlice->getSPS()->getMaxLog2TrDynamicRange(CHANNEL_TYPE_LUMA),
1254        pcSlice->getSPS()->getMaxLog2TrDynamicRange(CHANNEL_TYPE_CHROMA)
1255    };
1256    m_cTrQuant.setFlatScalingList(maxLog2TrDynamicRange, pcSlice->getSPS()->getBitDepths());
1257    m_cTrQuant.setUseScalingList(false);
1258  }
1259
1260#if NH_3D_IV_MERGE
1261#if H_3D_FCO
1262  if( !pcSlice->getIsDepth() && m_pcCamParsCollector )
1263#else
1264  if( pcSlice->getIsDepth() && m_pcCamParsCollector )
1265#endif
1266  {
1267    m_pcCamParsCollector->copyCamParamForSlice( pcSlice );
1268  }
1269#endif
1270  //  Decode a picture
1271  m_cGopDecoder.decompressSlice(&(nalu.getBitstream()), m_pcPic);
1272
1273#if NH_3D
1274  if( m_pcCamParsCollector )
1275  {
1276    m_pcCamParsCollector->setSlice( pcSlice );
1277  }
1278#endif
1279
1280  m_bFirstSliceInPicture = false;
1281  m_uiSliceIdx++;
1282
1283  return false;
1284}
1285
1286Void TDecTop::xDecodeVPS(const std::vector<UChar> &naluData)
1287{
1288  TComVPS* vps = new TComVPS();
1289
1290  m_cEntropyDecoder.decodeVPS( vps );
1291  m_parameterSetManager.storeVPS(vps, naluData);
1292}
1293
1294Void TDecTop::xDecodeSPS(const std::vector<UChar> &naluData)
1295{
1296  TComSPS* sps = new TComSPS();
1297#if NH_MV
1298  sps->setLayerId( getLayerId() ); 
1299#endif
1300#if O0043_BEST_EFFORT_DECODING
1301  sps->setForceDecodeBitDepth(m_forceDecodeBitDepth);
1302#endif
1303#if NH_3D
1304  // GT: Please don't add parsing dependency of SPS from VPS here again!!!
1305#endif
1306  m_cEntropyDecoder.decodeSPS( sps );
1307  m_parameterSetManager.storeSPS(sps, naluData);
1308}
1309
1310Void TDecTop::xDecodePPS(const std::vector<UChar> &naluData)
1311{
1312  TComPPS* pps = new TComPPS();
1313#if NH_MV
1314  pps->setLayerId( getLayerId() ); 
1315#endif
1316#if H_3D
1317  // GT: Please don't add parsing dependency of SPS from VPS here again!!!
1318#endif
1319  m_cEntropyDecoder.decodePPS( pps );
1320
1321  m_parameterSetManager.storePPS( pps, naluData);
1322}
1323
1324#if NH_MV
1325Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayerFlag, Bool& sliceSkippedFlag )
1326#else
1327Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1328#endif
1329{
1330#if !NH_MV
1331  // ignore all NAL units of layers > 0
1332  if (nalu.m_nuhLayerId > 0)
1333  {
1334    fprintf (stderr, "Warning: found NAL unit with nuh_layer_id equal to %d. Ignoring.\n", nalu.m_nuhLayerId);
1335    return false;
1336  }
1337#endif
1338  // Initialize entropy decoder
1339  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1340  m_cEntropyDecoder.setBitstream      (&(nalu.getBitstream()));
1341
1342  switch (nalu.m_nalUnitType)
1343  {
1344    case NAL_UNIT_VPS:
1345      xDecodeVPS(nalu.getBitstream().getFifo());
1346#if NH_MV
1347      m_isLastNALWasEos = false;
1348#endif
1349      return false;
1350
1351    case NAL_UNIT_SPS:
1352      xDecodeSPS(nalu.getBitstream().getFifo());
1353      return false;
1354
1355    case NAL_UNIT_PPS:
1356      xDecodePPS(nalu.getBitstream().getFifo());
1357      return false;
1358
1359    case NAL_UNIT_PREFIX_SEI:
1360      // Buffer up prefix SEI messages until SPS of associated VCL is known.
1361      m_prefixSEINALUs.push_back(new InputNALUnit(nalu));
1362      return false;
1363
1364    case NAL_UNIT_SUFFIX_SEI:
1365#if NH_MV
1366      if ( nalu.m_nalUnitType == NAL_UNIT_SUFFIX_SEI )
1367      {
1368        assert( m_isLastNALWasEos == false );
1369      }
1370#endif
1371      if (m_pcPic)
1372      {
1373#if NH_MV
1374        m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_pcPic->getSEIs(), nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS( getLayerId() ), m_pDecodedSEIOutputStream );
1375#else
1376        m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_pcPic->getSEIs(), nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS(), m_pDecodedSEIOutputStream );
1377#endif
1378      }
1379      else
1380      {
1381        printf ("Note: received suffix SEI but no picture currently active.\n");
1382      }
1383      return false;
1384
1385    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1386    case NAL_UNIT_CODED_SLICE_TRAIL_N:
1387    case NAL_UNIT_CODED_SLICE_TSA_R:
1388    case NAL_UNIT_CODED_SLICE_TSA_N:
1389    case NAL_UNIT_CODED_SLICE_STSA_R:
1390    case NAL_UNIT_CODED_SLICE_STSA_N:
1391    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
1392    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
1393    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1394    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
1395    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
1396    case NAL_UNIT_CODED_SLICE_CRA:
1397    case NAL_UNIT_CODED_SLICE_RADL_N:
1398    case NAL_UNIT_CODED_SLICE_RADL_R:
1399    case NAL_UNIT_CODED_SLICE_RASL_N:
1400    case NAL_UNIT_CODED_SLICE_RASL_R:
1401#if NH_MV
1402      if (nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_N ||
1403          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_N ||
1404          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_N ||
1405          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
1406          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N )
1407      {
1408        assert( m_isLastNALWasEos == false );
1409      }
1410      else
1411      {
1412        m_isLastNALWasEos = false;
1413      }
1414      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, newLayerFlag, sliceSkippedFlag );
1415#else
1416      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1417#endif
1418      break;
1419
1420    case NAL_UNIT_EOS:
1421#if NH_MV
1422      assert( m_isLastNALWasEos == false );
1423      //Check layer id of the nalu. if it is not 0, give a warning message and just return without doing anything.
1424      if (nalu.m_nuhLayerId > 0)
1425      {
1426        printf( "\nThis bitstream has EOS with non-zero layer id.\n" );
1427        return false;
1428      }
1429      m_isLastNALWasEos = true;
1430#endif
1431      m_associatedIRAPType = NAL_UNIT_INVALID;
1432      m_pocCRA = 0;
1433      m_pocRandomAccess = MAX_INT;
1434      m_prevPOC = MAX_INT;
1435      m_prevSliceSkipped = false;
1436      m_skippedPOC = 0;
1437      return false;
1438
1439    case NAL_UNIT_ACCESS_UNIT_DELIMITER:
1440      {
1441        AUDReader audReader;
1442        UInt picType;
1443        audReader.parseAccessUnitDelimiter(&(nalu.getBitstream()),picType);
1444        printf ("Note: found NAL_UNIT_ACCESS_UNIT_DELIMITER\n");
1445      return false;
1446      }
1447
1448    case NAL_UNIT_EOB:
1449      return false;
1450
1451    case NAL_UNIT_FILLER_DATA:
1452      {
1453        FDReader fdReader;
1454        UInt size;
1455        fdReader.parseFillerData(&(nalu.getBitstream()),size);
1456        printf ("Note: found NAL_UNIT_FILLER_DATA with %u bytes payload.\n", size);
1457#if NH_MV
1458      assert( m_isLastNALWasEos == false );
1459#endif
1460      return false;
1461      }
1462
1463    case NAL_UNIT_RESERVED_VCL_N10:
1464    case NAL_UNIT_RESERVED_VCL_R11:
1465    case NAL_UNIT_RESERVED_VCL_N12:
1466    case NAL_UNIT_RESERVED_VCL_R13:
1467    case NAL_UNIT_RESERVED_VCL_N14:
1468    case NAL_UNIT_RESERVED_VCL_R15:
1469
1470    case NAL_UNIT_RESERVED_IRAP_VCL22:
1471    case NAL_UNIT_RESERVED_IRAP_VCL23:
1472
1473    case NAL_UNIT_RESERVED_VCL24:
1474    case NAL_UNIT_RESERVED_VCL25:
1475    case NAL_UNIT_RESERVED_VCL26:
1476    case NAL_UNIT_RESERVED_VCL27:
1477    case NAL_UNIT_RESERVED_VCL28:
1478    case NAL_UNIT_RESERVED_VCL29:
1479    case NAL_UNIT_RESERVED_VCL30:
1480    case NAL_UNIT_RESERVED_VCL31:
1481      printf ("Note: found reserved VCL NAL unit.\n");
1482      xParsePrefixSEIsForUnknownVCLNal();
1483      return false;
1484
1485    case NAL_UNIT_RESERVED_NVCL41:
1486    case NAL_UNIT_RESERVED_NVCL42:
1487    case NAL_UNIT_RESERVED_NVCL43:
1488    case NAL_UNIT_RESERVED_NVCL44:
1489    case NAL_UNIT_RESERVED_NVCL45:
1490    case NAL_UNIT_RESERVED_NVCL46:
1491    case NAL_UNIT_RESERVED_NVCL47:
1492      printf ("Note: found reserved NAL unit.\n");
1493      return false;
1494    case NAL_UNIT_UNSPECIFIED_48:
1495    case NAL_UNIT_UNSPECIFIED_49:
1496    case NAL_UNIT_UNSPECIFIED_50:
1497    case NAL_UNIT_UNSPECIFIED_51:
1498    case NAL_UNIT_UNSPECIFIED_52:
1499    case NAL_UNIT_UNSPECIFIED_53:
1500    case NAL_UNIT_UNSPECIFIED_54:
1501    case NAL_UNIT_UNSPECIFIED_55:
1502    case NAL_UNIT_UNSPECIFIED_56:
1503    case NAL_UNIT_UNSPECIFIED_57:
1504    case NAL_UNIT_UNSPECIFIED_58:
1505    case NAL_UNIT_UNSPECIFIED_59:
1506    case NAL_UNIT_UNSPECIFIED_60:
1507    case NAL_UNIT_UNSPECIFIED_61:
1508    case NAL_UNIT_UNSPECIFIED_62:
1509    case NAL_UNIT_UNSPECIFIED_63:
1510      printf ("Note: found unspecified NAL unit.\n");
1511      return false;
1512    default:
1513      assert (0);
1514      break;
1515  }
1516
1517  return false;
1518}
1519
1520/** Function for checking if picture should be skipped because of association with a previous BLA picture
1521 * \param iPOCLastDisplay POC of last picture displayed
1522 * \returns true if the picture should be skipped
1523 * This function skips all TFD pictures that follow a BLA picture
1524 * in decoding order and precede it in output order.
1525 */
1526Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
1527{
1528  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) &&
1529       m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
1530  {
1531    iPOCLastDisplay++;
1532    return true;
1533  }
1534  return false;
1535}
1536
1537/** Function for checking if picture should be skipped because of random access
1538 * \param iSkipFrame skip frame counter
1539 * \param iPOCLastDisplay POC of last picture displayed
1540 * \returns true if the picture shold be skipped in the random access.
1541 * This function checks the skipping of pictures in the case of -s option random access.
1542 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1543 * It also checks the type of Nal unit type at the random access point.
1544 * 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.
1545 * If the random access point is IDR all pictures after the random access point are decoded.
1546 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
1547 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
1548 * access point there is no guarantee that the decoder will not crash.
1549 */
1550#if NH_MV
1551Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay, const TComVPS* vps)
1552#else
1553Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay )
1554#endif
1555{
1556  if (iSkipFrame)
1557  {
1558    iSkipFrame--;   // decrement the counter
1559    return true;
1560  }
1561#if NH_MV
1562  else if ( !m_layerInitilizedFlag[ m_layerId ] ) // start of random access point, m_pocRandomAccess has not been set yet.
1563#else
1564  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1565#endif
1566  {
1567    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
1568        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1569        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1570        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
1571    {
1572
1573#if NH_MV
1574      if ( xAllRefLayersInitilized( vps ) )
1575      {
1576        m_layerInitilizedFlag[ m_layerId ] = true; 
1577        m_pocRandomAccess = m_apcSlicePilot->getPOC();
1578      }
1579      else
1580      {
1581        return true; 
1582      }
1583#else
1584      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
1585      m_pocRandomAccess = m_apcSlicePilot->getPOC();
1586#endif
1587    }
1588    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
1589    {
1590#if NH_MV
1591      if ( xAllRefLayersInitilized( vps) )
1592      {
1593        m_layerInitilizedFlag[ m_layerId ] = true; 
1594        m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1595      }
1596      else 
1597      {
1598        return true; 
1599      }
1600#else
1601      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1602#endif
1603    }
1604    else
1605    {
1606#if NH_MV
1607      static Bool warningMessage[MAX_NUM_LAYERS];
1608      static Bool warningInitFlag = false;
1609     
1610      if (!warningInitFlag)
1611      {
1612        for ( Int i = 0; i < MAX_NUM_LAYERS; i++)
1613        {
1614          warningMessage[i] = true; 
1615        }
1616        warningInitFlag = true; 
1617      }
1618
1619      if ( warningMessage[getLayerId()] )
1620      {
1621        printf("\nLayer%3d   No valid random access point. VCL NAL units of this layer are discarded until next layer initialization picture. ", getLayerId() ); 
1622        warningMessage[m_layerId] = false; 
1623      }
1624#else
1625      if(!m_warningMessageSkipPicture)
1626      {
1627        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1628        m_warningMessageSkipPicture = true;
1629      }
1630#endif
1631      return true;
1632    }
1633  }
1634  // skip the reordered pictures, if necessary
1635  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))
1636  {
1637    iPOCLastDisplay++;
1638    return true;
1639  }
1640  // if we reach here, then the picture is not skipped.
1641#if NH_MV
1642  return !m_layerInitilizedFlag[ getLayerId() ]; 
1643#else
1644  return false;
1645#endif
1646}
1647#if NH_MV
1648TComPic* TDecTop::getPic( Int poc )
1649{
1650  xGetPic( m_layerId, poc ); 
1651  TComList<TComPic*>* listPic = getListPic();
1652  TComPic* pcPic = NULL;
1653  for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++)
1654  {
1655    if( (*it)->getPOC() == poc )
1656    {
1657      pcPic = *it ;
1658      break ;
1659    }
1660  }
1661  return pcPic;
1662}
1663
1664TComPic* TDecTop::xGetPic( Int layerId, Int poc )
1665{ 
1666  return m_ivPicLists->getPic( layerId, poc ) ;
1667}
1668
1669Void TDecTop::xResetPocInPicBuffer()
1670{
1671  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
1672  while (iterPic != m_cListPic.end())
1673  {
1674    TComPic* pic = *(iterPic++);
1675    if ( pic->getReconMark() )
1676    {
1677      for( Int i = 0; i < pic->getNumAllocatedSlice(); i++)
1678      {
1679        TComSlice* slice = pic->getSlice( i ); 
1680        slice->setPOC ( slice->getPOC() - m_apcSlicePilot->getPocBeforeReset() );           
1681      }         
1682    }     
1683  }
1684}
1685
1686Void TDecTop::xCeckNoClrasOutput()
1687{
1688  // This part needs further testing!
1689  if ( getLayerId() == 0 )
1690  {   
1691    NalUnitType nut = m_apcSlicePilot->getNalUnitType(); 
1692
1693    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 ); 
1694    Bool isIDR  = ( nut == NAL_UNIT_CODED_SLICE_IDR_W_RADL ) || ( nut == NAL_UNIT_CODED_SLICE_IDR_N_LP ); 
1695    Bool noClrasOutputFlag  = isBLA || ( isIDR  &&  m_apcSlicePilot->getCrossLayerBlaFlag() ); 
1696
1697    if ( noClrasOutputFlag ) 
1698    {
1699      for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++)
1700      {
1701        m_layerInitilizedFlag[i] = false; 
1702      } 
1703    }
1704  }
1705}
1706
1707Bool TDecTop::xAllRefLayersInitilized( const TComVPS* vps )
1708{
1709  Bool allRefLayersInitilizedFlag = true;   
1710  for (Int i = 0; i < vps->getNumDirectRefLayers( getLayerId()  ); i++ )
1711  {
1712    Int refLayerId = vps->getIdDirectRefLayer( m_layerId, i ); 
1713    allRefLayersInitilizedFlag = allRefLayersInitilizedFlag && m_layerInitilizedFlag[ refLayerId ]; 
1714  }
1715
1716  return allRefLayersInitilizedFlag;
1717}
1718
1719
1720Void TDecTop::initFromActiveVps( const TComVPS* vps )
1721{
1722  if ( m_targetOlsIdx == -1 )
1723  {
1724    // Not normative! Corresponds to specification by "External Means". (Should be set equal to 0, when no external means available. )
1725    m_targetOlsIdx = vps->getVpsNumLayerSetsMinus1(); 
1726  }
1727#if NH_3D
1728  // Set profile
1729  Int lsIdx = vps->olsIdxToLsIdx( m_targetOlsIdx );
1730  Int lIdx = -1; 
1731  for (Int j = 0; j < vps->getNumLayersInIdList( lsIdx ); j++ )
1732  {
1733    if ( vps->getLayerSetLayerIdList( lsIdx, j ) == getLayerId() )
1734    {
1735      lIdx = j; 
1736      break; 
1737    }       
1738  }
1739  assert( lIdx != -1 ); 
1740
1741  Int profileIdc = vps->getPTL( vps->getProfileTierLevelIdx( m_targetOlsIdx, lIdx ) )->getGeneralPTL()->getProfileIdc();
1742  assert( profileIdc == 1 || profileIdc == 6 || profileIdc == 8 ); 
1743  m_profileIdc = profileIdc;   
1744#endif
1745}
1746#endif
1747
1748//! \}
Note: See TracBrowser for help on using the repository browser.