source: 3DVCSoftware/branches/HTM-14.1-update-dev3-Samsung-Qualcomm/source/Lib/TLibDecoder/TDecTop.cpp @ 1210

Last change on this file since 1210 was 1210, checked in by samsung-htm, 9 years ago

Alignment and reactivation of NBDV

  • new macro NH_3D_NBDV for NBDV
  • Property svn:eol-style set to native
File size: 57.0 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 NH_3D_NBDV
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  m_cEntropyDecoder.decodePPS( pps );
1326
1327  m_parameterSetManager.storePPS( pps, naluData);
1328}
1329
1330#if NH_MV
1331Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay, Bool newLayerFlag, Bool& sliceSkippedFlag )
1332#else
1333Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1334#endif
1335{
1336#if !NH_MV
1337  // ignore all NAL units of layers > 0
1338  if (nalu.m_nuhLayerId > 0)
1339  {
1340    fprintf (stderr, "Warning: found NAL unit with nuh_layer_id equal to %d. Ignoring.\n", nalu.m_nuhLayerId);
1341    return false;
1342  }
1343#endif
1344  // Initialize entropy decoder
1345  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1346  m_cEntropyDecoder.setBitstream      (&(nalu.getBitstream()));
1347
1348  switch (nalu.m_nalUnitType)
1349  {
1350    case NAL_UNIT_VPS:
1351      xDecodeVPS(nalu.getBitstream().getFifo());
1352#if NH_MV
1353      m_isLastNALWasEos = false;
1354#endif
1355      return false;
1356
1357    case NAL_UNIT_SPS:
1358      xDecodeSPS(nalu.getBitstream().getFifo());
1359      return false;
1360
1361    case NAL_UNIT_PPS:
1362      xDecodePPS(nalu.getBitstream().getFifo());
1363      return false;
1364
1365    case NAL_UNIT_PREFIX_SEI:
1366      // Buffer up prefix SEI messages until SPS of associated VCL is known.
1367      m_prefixSEINALUs.push_back(new InputNALUnit(nalu));
1368      return false;
1369
1370    case NAL_UNIT_SUFFIX_SEI:
1371#if NH_MV
1372      if ( nalu.m_nalUnitType == NAL_UNIT_SUFFIX_SEI )
1373      {
1374        assert( m_isLastNALWasEos == false );
1375      }
1376#endif
1377      if (m_pcPic)
1378      {
1379#if NH_MV
1380        m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_pcPic->getSEIs(), nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS( getLayerId() ), m_pDecodedSEIOutputStream );
1381#else
1382        m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_pcPic->getSEIs(), nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS(), m_pDecodedSEIOutputStream );
1383#endif
1384      }
1385      else
1386      {
1387        printf ("Note: received suffix SEI but no picture currently active.\n");
1388      }
1389      return false;
1390
1391    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1392    case NAL_UNIT_CODED_SLICE_TRAIL_N:
1393    case NAL_UNIT_CODED_SLICE_TSA_R:
1394    case NAL_UNIT_CODED_SLICE_TSA_N:
1395    case NAL_UNIT_CODED_SLICE_STSA_R:
1396    case NAL_UNIT_CODED_SLICE_STSA_N:
1397    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
1398    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
1399    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1400    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
1401    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
1402    case NAL_UNIT_CODED_SLICE_CRA:
1403    case NAL_UNIT_CODED_SLICE_RADL_N:
1404    case NAL_UNIT_CODED_SLICE_RADL_R:
1405    case NAL_UNIT_CODED_SLICE_RASL_N:
1406    case NAL_UNIT_CODED_SLICE_RASL_R:
1407#if NH_MV
1408      if (nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_N ||
1409          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_N ||
1410          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_N ||
1411          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
1412          nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N )
1413      {
1414        assert( m_isLastNALWasEos == false );
1415      }
1416      else
1417      {
1418        m_isLastNALWasEos = false;
1419      }
1420      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay, newLayerFlag, sliceSkippedFlag );
1421#else
1422      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1423#endif
1424      break;
1425
1426    case NAL_UNIT_EOS:
1427#if NH_MV
1428      assert( m_isLastNALWasEos == false );
1429      //Check layer id of the nalu. if it is not 0, give a warning message and just return without doing anything.
1430      if (nalu.m_nuhLayerId > 0)
1431      {
1432        printf( "\nThis bitstream has EOS with non-zero layer id.\n" );
1433        return false;
1434      }
1435      m_isLastNALWasEos = true;
1436#endif
1437      m_associatedIRAPType = NAL_UNIT_INVALID;
1438      m_pocCRA = 0;
1439      m_pocRandomAccess = MAX_INT;
1440      m_prevPOC = MAX_INT;
1441      m_prevSliceSkipped = false;
1442      m_skippedPOC = 0;
1443      return false;
1444
1445    case NAL_UNIT_ACCESS_UNIT_DELIMITER:
1446      {
1447        AUDReader audReader;
1448        UInt picType;
1449        audReader.parseAccessUnitDelimiter(&(nalu.getBitstream()),picType);
1450        printf ("Note: found NAL_UNIT_ACCESS_UNIT_DELIMITER\n");
1451      return false;
1452      }
1453
1454    case NAL_UNIT_EOB:
1455      return false;
1456
1457    case NAL_UNIT_FILLER_DATA:
1458      {
1459        FDReader fdReader;
1460        UInt size;
1461        fdReader.parseFillerData(&(nalu.getBitstream()),size);
1462        printf ("Note: found NAL_UNIT_FILLER_DATA with %u bytes payload.\n", size);
1463#if NH_MV
1464      assert( m_isLastNALWasEos == false );
1465#endif
1466      return false;
1467      }
1468
1469    case NAL_UNIT_RESERVED_VCL_N10:
1470    case NAL_UNIT_RESERVED_VCL_R11:
1471    case NAL_UNIT_RESERVED_VCL_N12:
1472    case NAL_UNIT_RESERVED_VCL_R13:
1473    case NAL_UNIT_RESERVED_VCL_N14:
1474    case NAL_UNIT_RESERVED_VCL_R15:
1475
1476    case NAL_UNIT_RESERVED_IRAP_VCL22:
1477    case NAL_UNIT_RESERVED_IRAP_VCL23:
1478
1479    case NAL_UNIT_RESERVED_VCL24:
1480    case NAL_UNIT_RESERVED_VCL25:
1481    case NAL_UNIT_RESERVED_VCL26:
1482    case NAL_UNIT_RESERVED_VCL27:
1483    case NAL_UNIT_RESERVED_VCL28:
1484    case NAL_UNIT_RESERVED_VCL29:
1485    case NAL_UNIT_RESERVED_VCL30:
1486    case NAL_UNIT_RESERVED_VCL31:
1487      printf ("Note: found reserved VCL NAL unit.\n");
1488      xParsePrefixSEIsForUnknownVCLNal();
1489      return false;
1490
1491    case NAL_UNIT_RESERVED_NVCL41:
1492    case NAL_UNIT_RESERVED_NVCL42:
1493    case NAL_UNIT_RESERVED_NVCL43:
1494    case NAL_UNIT_RESERVED_NVCL44:
1495    case NAL_UNIT_RESERVED_NVCL45:
1496    case NAL_UNIT_RESERVED_NVCL46:
1497    case NAL_UNIT_RESERVED_NVCL47:
1498      printf ("Note: found reserved NAL unit.\n");
1499      return false;
1500    case NAL_UNIT_UNSPECIFIED_48:
1501    case NAL_UNIT_UNSPECIFIED_49:
1502    case NAL_UNIT_UNSPECIFIED_50:
1503    case NAL_UNIT_UNSPECIFIED_51:
1504    case NAL_UNIT_UNSPECIFIED_52:
1505    case NAL_UNIT_UNSPECIFIED_53:
1506    case NAL_UNIT_UNSPECIFIED_54:
1507    case NAL_UNIT_UNSPECIFIED_55:
1508    case NAL_UNIT_UNSPECIFIED_56:
1509    case NAL_UNIT_UNSPECIFIED_57:
1510    case NAL_UNIT_UNSPECIFIED_58:
1511    case NAL_UNIT_UNSPECIFIED_59:
1512    case NAL_UNIT_UNSPECIFIED_60:
1513    case NAL_UNIT_UNSPECIFIED_61:
1514    case NAL_UNIT_UNSPECIFIED_62:
1515    case NAL_UNIT_UNSPECIFIED_63:
1516      printf ("Note: found unspecified NAL unit.\n");
1517      return false;
1518    default:
1519      assert (0);
1520      break;
1521  }
1522
1523  return false;
1524}
1525
1526/** Function for checking if picture should be skipped because of association with a previous BLA picture
1527 * \param iPOCLastDisplay POC of last picture displayed
1528 * \returns true if the picture should be skipped
1529 * This function skips all TFD pictures that follow a BLA picture
1530 * in decoding order and precede it in output order.
1531 */
1532Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
1533{
1534  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) &&
1535       m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
1536  {
1537    iPOCLastDisplay++;
1538    return true;
1539  }
1540  return false;
1541}
1542
1543/** Function for checking if picture should be skipped because of random access
1544 * \param iSkipFrame skip frame counter
1545 * \param iPOCLastDisplay POC of last picture displayed
1546 * \returns true if the picture shold be skipped in the random access.
1547 * This function checks the skipping of pictures in the case of -s option random access.
1548 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1549 * It also checks the type of Nal unit type at the random access point.
1550 * 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.
1551 * If the random access point is IDR all pictures after the random access point are decoded.
1552 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
1553 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
1554 * access point there is no guarantee that the decoder will not crash.
1555 */
1556#if NH_MV
1557Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay, const TComVPS* vps)
1558#else
1559Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay )
1560#endif
1561{
1562  if (iSkipFrame)
1563  {
1564    iSkipFrame--;   // decrement the counter
1565    return true;
1566  }
1567#if NH_MV
1568  else if ( !m_layerInitilizedFlag[ m_layerId ] ) // start of random access point, m_pocRandomAccess has not been set yet.
1569#else
1570  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1571#endif
1572  {
1573    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
1574        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1575        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1576        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
1577    {
1578
1579#if NH_MV
1580      if ( xAllRefLayersInitilized( vps ) )
1581      {
1582        m_layerInitilizedFlag[ m_layerId ] = true; 
1583        m_pocRandomAccess = m_apcSlicePilot->getPOC();
1584      }
1585      else
1586      {
1587        return true; 
1588      }
1589#else
1590      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
1591      m_pocRandomAccess = m_apcSlicePilot->getPOC();
1592#endif
1593    }
1594    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
1595    {
1596#if NH_MV
1597      if ( xAllRefLayersInitilized( vps) )
1598      {
1599        m_layerInitilizedFlag[ m_layerId ] = true; 
1600        m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1601      }
1602      else 
1603      {
1604        return true; 
1605      }
1606#else
1607      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1608#endif
1609    }
1610    else
1611    {
1612#if NH_MV
1613      static Bool warningMessage[MAX_NUM_LAYERS];
1614      static Bool warningInitFlag = false;
1615     
1616      if (!warningInitFlag)
1617      {
1618        for ( Int i = 0; i < MAX_NUM_LAYERS; i++)
1619        {
1620          warningMessage[i] = true; 
1621        }
1622        warningInitFlag = true; 
1623      }
1624
1625      if ( warningMessage[getLayerId()] )
1626      {
1627        printf("\nLayer%3d   No valid random access point. VCL NAL units of this layer are discarded until next layer initialization picture. ", getLayerId() ); 
1628        warningMessage[m_layerId] = false; 
1629      }
1630#else
1631      if(!m_warningMessageSkipPicture)
1632      {
1633        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1634        m_warningMessageSkipPicture = true;
1635      }
1636#endif
1637      return true;
1638    }
1639  }
1640  // skip the reordered pictures, if necessary
1641  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))
1642  {
1643    iPOCLastDisplay++;
1644    return true;
1645  }
1646  // if we reach here, then the picture is not skipped.
1647#if NH_MV
1648  return !m_layerInitilizedFlag[ getLayerId() ]; 
1649#else
1650  return false;
1651#endif
1652}
1653#if NH_MV
1654TComPic* TDecTop::getPic( Int poc )
1655{
1656  xGetPic( m_layerId, poc ); 
1657  TComList<TComPic*>* listPic = getListPic();
1658  TComPic* pcPic = NULL;
1659  for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++)
1660  {
1661    if( (*it)->getPOC() == poc )
1662    {
1663      pcPic = *it ;
1664      break ;
1665    }
1666  }
1667  return pcPic;
1668}
1669
1670TComPic* TDecTop::xGetPic( Int layerId, Int poc )
1671{ 
1672  return m_ivPicLists->getPic( layerId, poc ) ;
1673}
1674
1675Void TDecTop::xResetPocInPicBuffer()
1676{
1677  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
1678  while (iterPic != m_cListPic.end())
1679  {
1680    TComPic* pic = *(iterPic++);
1681    if ( pic->getReconMark() )
1682    {
1683      for( Int i = 0; i < pic->getNumAllocatedSlice(); i++)
1684      {
1685        TComSlice* slice = pic->getSlice( i ); 
1686        slice->setPOC ( slice->getPOC() - m_apcSlicePilot->getPocBeforeReset() );           
1687      }         
1688    }     
1689  }
1690}
1691
1692Void TDecTop::xCeckNoClrasOutput()
1693{
1694  // This part needs further testing!
1695  if ( getLayerId() == 0 )
1696  {   
1697    NalUnitType nut = m_apcSlicePilot->getNalUnitType(); 
1698
1699    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 ); 
1700    Bool isIDR  = ( nut == NAL_UNIT_CODED_SLICE_IDR_W_RADL ) || ( nut == NAL_UNIT_CODED_SLICE_IDR_N_LP ); 
1701    Bool noClrasOutputFlag  = isBLA || ( isIDR  &&  m_apcSlicePilot->getCrossLayerBlaFlag() ); 
1702
1703    if ( noClrasOutputFlag ) 
1704    {
1705      for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++)
1706      {
1707        m_layerInitilizedFlag[i] = false; 
1708      } 
1709    }
1710  }
1711}
1712
1713Bool TDecTop::xAllRefLayersInitilized( const TComVPS* vps )
1714{
1715  Bool allRefLayersInitilizedFlag = true;   
1716  for (Int i = 0; i < vps->getNumDirectRefLayers( getLayerId()  ); i++ )
1717  {
1718    Int refLayerId = vps->getIdDirectRefLayer( m_layerId, i ); 
1719    allRefLayersInitilizedFlag = allRefLayersInitilizedFlag && m_layerInitilizedFlag[ refLayerId ]; 
1720  }
1721
1722  return allRefLayersInitilizedFlag;
1723}
1724
1725
1726Void TDecTop::initFromActiveVps( const TComVPS* vps )
1727{
1728  if ( m_targetOlsIdx == -1 )
1729  {
1730    // Not normative! Corresponds to specification by "External Means". (Should be set equal to 0, when no external means available. )
1731    m_targetOlsIdx = vps->getVpsNumLayerSetsMinus1(); 
1732  }
1733#if NH_3D
1734  // Set profile
1735  Int lsIdx = vps->olsIdxToLsIdx( m_targetOlsIdx );
1736  Int lIdx = -1; 
1737  for (Int j = 0; j < vps->getNumLayersInIdList( lsIdx ); j++ )
1738  {
1739    if ( vps->getLayerSetLayerIdList( lsIdx, j ) == getLayerId() )
1740    {
1741      lIdx = j; 
1742      break; 
1743    }       
1744  }
1745  assert( lIdx != -1 ); 
1746
1747  Int profileIdc = vps->getPTL( vps->getProfileTierLevelIdx( m_targetOlsIdx, lIdx ) )->getGeneralPTL()->getProfileIdc();
1748  assert( profileIdc == 1 || profileIdc == 6 || profileIdc == 8 ); 
1749  m_profileIdc = profileIdc;   
1750#endif
1751}
1752#endif
1753
1754//! \}
Note: See TracBrowser for help on using the repository browser.