source: 3DVCSoftware/branches/HTM-14.1-update-dev4-Qualcomm/source/Lib/TLibDecoder/TDecTop.cpp @ 1320

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