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

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

NH_3D_FIX_TICKET_101 Camera parameters for depth layers.

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