source: 3DVCSoftware/trunk/source/Lib/TLibDecoder/TDecTop.cpp @ 1405

Last change on this file since 1405 was 1405, checked in by tech, 8 years ago

Merged HTM-16.1-dev@1404.

  • Property svn:eol-style set to native
File size: 118.7 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license.
5 *
6 * Copyright (c) 2010-2016, 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#include "NALread.h"
38#include "TDecTop.h"
39#if NH_MV
40ParameterSetManager TDecTop::m_parameterSetManager;
41#endif
42
43//! \ingroup TLibDecoder
44//! \{
45
46#if NH_3D
47CamParsCollector::CamParsCollector()
48: m_bInitialized( false )
49{
50  m_aaiCodedOffset         = new Int* [ MAX_NUM_LAYERS ];
51  m_aaiCodedScale          = new Int* [ MAX_NUM_LAYERS ];
52  for( UInt uiId = 0; uiId < MAX_NUM_LAYERS; uiId++ )
53  {
54    m_aaiCodedOffset      [ uiId ] = new Int [ MAX_NUM_LAYERS ];
55    m_aaiCodedScale       [ uiId ] = new Int [ MAX_NUM_LAYERS ];
56  }
57
58  xCreateLUTs( (UInt)MAX_NUM_LAYERS, (UInt)MAX_NUM_LAYERS, m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
59  m_iLog2Precision   = LOG2_DISP_PREC_LUT;
60  m_uiBitDepthForLUT = 8; // fixed
61  m_receivedIdc = NULL;
62  m_vps         = NULL;
63}
64
65CamParsCollector::~CamParsCollector()
66{
67  for( UInt uiId = 0; uiId < MAX_NUM_LAYERS; uiId++ )
68  {
69    delete [] m_aaiCodedOffset      [ uiId ];
70    delete [] m_aaiCodedScale       [ uiId ];
71  }
72  delete [] m_aaiCodedOffset;
73  delete [] m_aaiCodedScale;
74
75  xDeleteArray( m_adBaseViewShiftLUT, MAX_NUM_LAYERS, MAX_NUM_LAYERS, 2 );
76  xDeleteArray( m_aiBaseViewShiftLUT, MAX_NUM_LAYERS, MAX_NUM_LAYERS, 2 );
77  if ( m_receivedIdc != NULL )
78  {
79    xDeleteArray( m_receivedIdc, m_vps->getNumViews() );
80  }
81}
82
83
84Void
85CamParsCollector::init( const TComVPS* vps)
86{
87  assert( !isInitialized() ); // Only one initialization currently supported
88  m_bInitialized            = true;
89  m_vps                     = vps;
90  m_bCamParsVaryOverTime    = false;
91  m_lastPoc                 = -1;
92  m_firstReceivedPoc        = -2;
93
94  for (Int i = 0; i <= vps->getMaxLayersMinus1(); i++)
95  {
96    Int curViewIdxInVps = m_vps->getVoiInVps( m_vps->getViewIndex( m_vps->getLayerIdInNuh( i ) ) ) ;
97    m_bCamParsVaryOverTime = m_bCamParsVaryOverTime || vps->getCpInSliceSegmentHeaderFlag( curViewIdxInVps );
98  }
99
100  assert( m_receivedIdc == NULL );
101  m_receivedIdc = new Int*[ m_vps->getNumViews() ];
102  for (Int i = 0; i < m_vps->getNumViews(); i++)
103  {
104    m_receivedIdc[i] = new Int[ m_vps->getNumViews() ];
105  }
106
107  xResetReceivedIdc( true );
108
109  for (Int voiInVps = 0; voiInVps < m_vps->getNumViews(); voiInVps++ )
110  {
111    if( !m_vps->getCpInSliceSegmentHeaderFlag( voiInVps ) )
112    {
113      for (Int baseVoiInVps = 0; baseVoiInVps < m_vps->getNumViews(); baseVoiInVps++ )
114      {
115        if( m_vps->getCpPresentFlag( voiInVps, baseVoiInVps ) )
116        {
117          m_receivedIdc   [ baseVoiInVps ][ voiInVps ] = -1;
118          m_aaiCodedScale [ baseVoiInVps ][ voiInVps ] = m_vps->getCodedScale    (voiInVps) [ baseVoiInVps ];
119          m_aaiCodedOffset[ baseVoiInVps ][ voiInVps ] = m_vps->getCodedOffset   (voiInVps) [ baseVoiInVps ];
120
121          m_receivedIdc   [ voiInVps ][ baseVoiInVps ] = -1;
122          m_aaiCodedScale [ voiInVps ][ baseVoiInVps ] = m_vps->getInvCodedScale (voiInVps) [ baseVoiInVps ];
123          m_aaiCodedOffset[ voiInVps ][ baseVoiInVps ] = m_vps->getInvCodedOffset(voiInVps) [ baseVoiInVps ];
124          xInitLUTs( baseVoiInVps, voiInVps, m_aaiCodedScale[ baseVoiInVps ][ voiInVps ], m_aaiCodedOffset[ baseVoiInVps ][ voiInVps ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
125          xInitLUTs( voiInVps, baseVoiInVps, m_aaiCodedScale[ voiInVps ][ baseVoiInVps ], m_aaiCodedOffset[ voiInVps ][ baseVoiInVps ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
126        }
127      }
128    }
129  }
130}
131
132Void
133CamParsCollector::xResetReceivedIdc( Bool overWriteFlag )
134{
135  for (Int i = 0; i < m_vps->getNumViews(); i++)
136  {
137    for (Int j = 0; j < m_vps->getNumViews(); j++)
138    {
139      if ( overWriteFlag ||  ( m_receivedIdc[i][j] != -1 ) )
140      {
141        m_receivedIdc[i][j] = 0;
142      }
143    }
144  }
145}
146
147
148Void
149CamParsCollector::xCreateLUTs( UInt uiNumberSourceViews, UInt uiNumberTargetViews, Double****& radLUT, Int****& raiLUT)
150{
151
152  uiNumberSourceViews = std::max( (UInt) 1, uiNumberSourceViews );
153  uiNumberTargetViews = std::max( (UInt) 1, uiNumberTargetViews );
154
155  radLUT         = new Double***[ uiNumberSourceViews ];
156  raiLUT         = new Int   ***[ uiNumberSourceViews ];
157
158  for( UInt uiSourceView = 0; uiSourceView < uiNumberSourceViews; uiSourceView++ )
159  {
160    radLUT        [ uiSourceView ] = new Double**[ uiNumberTargetViews ];
161    raiLUT        [ uiSourceView ] = new Int   **[ uiNumberTargetViews ];
162
163    for( UInt uiTargetView = 0; uiTargetView < uiNumberTargetViews; uiTargetView++ )
164    {
165      radLUT        [ uiSourceView ][ uiTargetView ]      = new Double*[ 2 ];
166      radLUT        [ uiSourceView ][ uiTargetView ][ 0 ] = new Double [ 257 ];
167      radLUT        [ uiSourceView ][ uiTargetView ][ 1 ] = new Double [ 257 ];
168
169      raiLUT        [ uiSourceView ][ uiTargetView ]      = new Int*   [ 2 ];
170      raiLUT        [ uiSourceView ][ uiTargetView ][ 0 ] = new Int    [ 257 ];
171      raiLUT        [ uiSourceView ][ uiTargetView ][ 1 ] = new Int    [ 257 ];
172    }
173  }
174}
175
176Void
177  CamParsCollector::xInitLUTs( UInt uiSourceView, UInt uiTargetView, Int iScale, Int iOffset, Double****& radLUT, Int****& raiLUT)
178{
179  Int     iLog2DivLuma   = m_uiBitDepthForLUT + m_vps->getCpPrecision() + 1 - m_iLog2Precision;   AOF( iLog2DivLuma > 0 );
180  Int     iLog2DivChroma = iLog2DivLuma + 1;
181
182  iOffset <<= m_uiBitDepthForLUT;
183
184  Double dScale  = (Double) iScale  / (( Double ) ( 1 << iLog2DivLuma ));
185  Double dOffset = (Double) iOffset / (( Double ) ( 1 << iLog2DivLuma ));
186
187  // offsets including rounding offsets
188  Int64 iOffsetLuma   = iOffset + ( ( 1 << iLog2DivLuma   ) >> 1 );
189  Int64 iOffsetChroma = iOffset + ( ( 1 << iLog2DivChroma ) >> 1 );
190
191
192  for( UInt uiDepthValue = 0; uiDepthValue < 256; uiDepthValue++ )
193  {
194
195    // real-valued look-up tables
196    Double  dShiftLuma      = ( (Double)uiDepthValue * dScale + dOffset ) * Double( 1 << m_iLog2Precision );
197    Double  dShiftChroma    = dShiftLuma / 2;
198    radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = dShiftLuma;
199    radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = dShiftChroma;
200
201    // integer-valued look-up tables
202    Int64   iTempScale      = (Int64)uiDepthValue * iScale;
203    Int64   iShiftLuma      = ( iTempScale + iOffsetLuma   ) >> iLog2DivLuma;
204    Int64   iShiftChroma    = ( iTempScale + iOffsetChroma ) >> iLog2DivChroma;
205    raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ uiDepthValue ] = (Int)iShiftLuma;
206    raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ uiDepthValue ] = (Int)iShiftChroma;
207  }
208
209  radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 256 ] = radLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 255 ];
210  radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 256 ] = radLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 255 ];
211  raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 256 ] = raiLUT[ uiSourceView ][ uiTargetView ][ 0 ][ 255 ];
212  raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 256 ] = raiLUT[ uiSourceView ][ uiTargetView ][ 1 ][ 255 ];
213}
214
215Void
216CamParsCollector::uninit()
217{
218  m_bInitialized = false;
219}
220
221Void CamParsCollector::setSlice( const TComSlice* pcSlice )
222{
223  if( pcSlice == 0 )
224  {
225    xOutput( m_lastPoc );
226    return;
227  }
228
229#if !H_3D_FCO
230  if ( pcSlice->getIsDepth())
231  {
232    return;
233  }
234#endif
235
236  Int curPoc = pcSlice->getPOC();
237  if( m_firstReceivedPoc == -2 )
238  {
239    m_firstReceivedPoc = curPoc;
240  }
241
242  Bool newPocFlag = ( m_lastPoc != curPoc );
243
244  if ( newPocFlag )
245  {
246    if( m_lastPoc != -1 )
247    {
248      xOutput( m_lastPoc );
249    }
250
251    xResetReceivedIdc( false );
252    m_lastPoc = pcSlice->getPOC();
253  }
254
255  UInt voiInVps          = m_vps->getVoiInVps(pcSlice->getViewIndex());
256  if( m_vps->getCpInSliceSegmentHeaderFlag( voiInVps ) ) // check consistency of slice parameters here
257  {
258    for( Int baseVoiInVps = 0; baseVoiInVps < m_vps->getNumViews(); baseVoiInVps++ )
259    {
260      if ( m_vps->getCpPresentFlag( voiInVps, baseVoiInVps ) )
261      {
262        if ( m_receivedIdc[ voiInVps ][ baseVoiInVps ] != 0 )
263        {
264          AOF( m_aaiCodedScale [ voiInVps ][ baseVoiInVps ] == pcSlice->getInvCodedScale () [ baseVoiInVps ] );
265          AOF( m_aaiCodedOffset[ voiInVps ][ baseVoiInVps ] == pcSlice->getInvCodedOffset() [ baseVoiInVps ] );
266        }
267        else
268        {
269          m_receivedIdc   [ voiInVps ][ baseVoiInVps ]  = 1;
270          m_aaiCodedScale [ voiInVps ][ baseVoiInVps ]  = pcSlice->getInvCodedScale () [ baseVoiInVps ];
271          m_aaiCodedOffset[ voiInVps ][ baseVoiInVps ]  = pcSlice->getInvCodedOffset() [ baseVoiInVps ];
272          xInitLUTs( voiInVps, baseVoiInVps, m_aaiCodedScale[ voiInVps ][ baseVoiInVps ], m_aaiCodedOffset[ voiInVps ][ baseVoiInVps ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT);
273        }
274        if ( m_receivedIdc[ baseVoiInVps ][ voiInVps ] != 0 )
275        {
276          AOF( m_aaiCodedScale [ baseVoiInVps ][ voiInVps ] == pcSlice->getCodedScale    () [ baseVoiInVps ] );
277          AOF( m_aaiCodedOffset[ baseVoiInVps ][ voiInVps ] == pcSlice->getCodedOffset   () [ baseVoiInVps ] );
278        }
279        else
280        {
281          m_receivedIdc   [ baseVoiInVps ][ voiInVps ]  = 1;
282          m_aaiCodedScale [ baseVoiInVps ][ voiInVps ]  = pcSlice->getCodedScale    () [ baseVoiInVps ];
283          m_aaiCodedOffset[ baseVoiInVps ][ voiInVps ]  = pcSlice->getCodedOffset   () [ baseVoiInVps ];
284          xInitLUTs( baseVoiInVps, voiInVps, m_aaiCodedScale[ baseVoiInVps ][ voiInVps ], m_aaiCodedOffset[ baseVoiInVps ][ voiInVps ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT);
285        }
286      }
287    }
288  }
289}
290
291Void
292CamParsCollector::xOutput( Int iPOC )
293{
294  if( m_pCodedScaleOffsetFile )
295  {
296    if( iPOC == m_firstReceivedPoc )
297    {
298      fprintf( m_pCodedScaleOffsetFile, "#ViewOrderIdx     ViewIdVal\n" );
299      fprintf( m_pCodedScaleOffsetFile, "#------------ -------------\n" );
300
301      for( UInt voiInVps = 0; voiInVps < m_vps->getNumViews(); voiInVps++ )
302      {
303        fprintf( m_pCodedScaleOffsetFile, "%13d %13d\n", m_vps->getViewOIdxList( voiInVps ), m_vps->getViewIdVal( m_vps->getViewOIdxList( voiInVps ) ) );
304      }
305      fprintf( m_pCodedScaleOffsetFile, "\n\n");
306      fprintf( m_pCodedScaleOffsetFile, "# StartFrame     EndFrame    TargetVOI      BaseVOI   CodedScale  CodedOffset    Precision\n" );
307      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------ ------------ ------------ ------------ ------------ ------------\n" );
308    }
309    if( iPOC == m_firstReceivedPoc || m_bCamParsVaryOverTime  )
310    {
311      Int iS = iPOC;
312      Int iE = ( m_bCamParsVaryOverTime ? iPOC : ~( 1 << 31 ) );
313      for( UInt voiInVps = 0; voiInVps < m_vps->getNumViews(); voiInVps++ )
314      {
315        for( UInt baseVoiInVps = 0; baseVoiInVps < m_vps->getNumViews(); baseVoiInVps++ )
316        {
317          if( voiInVps != baseVoiInVps )
318          {
319            if ( m_receivedIdc[baseVoiInVps][voiInVps] != 0 )
320            {
321              fprintf( m_pCodedScaleOffsetFile, "%12d %12d %12d %12d %12d %12d %12d\n",
322                iS, iE, m_vps->getViewOIdxList( voiInVps ), m_vps->getViewOIdxList( baseVoiInVps ),
323                m_aaiCodedScale [ baseVoiInVps ][ voiInVps ],
324                m_aaiCodedOffset[ baseVoiInVps ][ voiInVps ], m_vps->getCpPrecision() );
325            }
326          }
327        }
328      }
329    }
330  }
331}
332#endif
333
334
335TDecTop::TDecTop()
336  : m_iMaxRefPicNum(0)
337#if !NH_MV
338  , m_associatedIRAPType(NAL_UNIT_INVALID)
339  , m_pocCRA(0)
340  , m_pocRandomAccess(MAX_INT)
341  , m_cListPic()
342  , m_parameterSetManager()
343#endif
344  , m_apcSlicePilot(NULL)
345  , m_SEIs()
346  , m_cPrediction()
347  , m_cTrQuant()
348  , m_cGopDecoder()
349  , m_cSliceDecoder()
350  , m_cCuDecoder()
351  , m_cEntropyDecoder()
352  , m_cCavlcDecoder()
353  , m_cSbacDecoder()
354  , m_cBinCABAC()
355  , m_seiReader()
356  , m_cLoopFilter()
357  , m_cSAO()
358  , m_pcPic(NULL)
359#if !NH_MV
360  , m_prevPOC(MAX_INT)
361  , m_prevTid0POC(0)
362  , m_bFirstSliceInPicture(true)
363  , m_bFirstSliceInSequence(true)
364  , m_prevSliceSkipped(false)
365  , m_skippedPOC(0)
366  , m_bFirstSliceInBitstream(true)
367  , m_lastPOCNoOutputPriorPics(-1)
368  , m_isNoOutputPriorPics(false)
369  , m_craNoRaslOutputFlag(false)
370#endif
371#if O0043_BEST_EFFORT_DECODING
372  , m_forceDecodeBitDepth(8)
373#endif
374  , m_pDecodedSEIOutputStream(NULL)
375#if !NH_MV
376  , m_warningMessageSkipPicture(false)
377#endif
378  , m_prefixSEINALUs()
379{
380#if !NH_MV
381#if ENC_DEC_TRACE
382  if (g_hTrace == NULL)
383  {
384    g_hTrace = fopen( "TraceDec.txt", "wb" );
385  }
386  g_bJustDoIt = g_bEncDecTraceDisable;
387  g_nSymbolCounter = 0;
388#endif
389#endif
390
391#if NH_MV
392  m_layerId                       = 0;
393  m_viewId                        = 0;
394
395#if NH_3D
396  m_viewIndex                     = 0;
397  m_isDepth                       = false;
398  m_pcCamParsCollector            = 0;
399#endif
400
401  m_decodingProcess               = CLAUSE_8;
402  m_targetOlsIdx                  = -1;
403  m_smallestLayerId               = -1;
404  m_isInOwnTargetDecLayerIdList   = 0;
405  m_prevPicOrderCnt               = 0;
406  m_pocDecrementedInDpbFlag       = NULL;
407  m_firstPicInLayerDecodedFlag    = NULL;
408  m_lastPresentPocResetIdc        = NULL;
409
410  m_prevIrapPoc                   = MIN_INT;
411  m_prevIrapDecodingOrder         = MIN_INT;
412  m_prevStsaDecOrder              = MIN_INT;
413  m_prevStsaTemporalId            = MIN_INT;
414#endif
415}
416
417TDecTop::~TDecTop()
418{
419#if ENC_DEC_TRACE
420#if NH_MV
421  if (g_hTrace != stdout && g_hTrace != NULL)
422  {
423    fclose( g_hTrace );
424    g_hTrace = NULL;
425  }
426#else
427  if (g_hTrace != stdout)
428  {
429    fclose( g_hTrace );
430  }
431#endif
432#endif
433  while (!m_prefixSEINALUs.empty())
434  {
435    delete m_prefixSEINALUs.front();
436    m_prefixSEINALUs.pop_front();
437  }
438}
439
440Void TDecTop::create()
441{
442  m_cGopDecoder.create();
443  m_apcSlicePilot = new TComSlice;
444  m_uiSliceIdx = 0;
445}
446
447Void TDecTop::destroy()
448{
449
450#if NH_MV
451  m_cSAO.destroy();
452  m_cLoopFilter.        destroy();
453#endif
454
455  m_cGopDecoder.destroy();
456
457  delete m_apcSlicePilot;
458  m_apcSlicePilot = NULL;
459
460  m_cSliceDecoder.destroy();
461}
462
463Void TDecTop::init()
464{
465  // initialize ROM
466#if !NH_MV
467  initROM();
468#endif
469#if NH_MV
470  m_cCavlcDecoder.setDecTop( this );
471#endif
472  m_cGopDecoder.init( &m_cEntropyDecoder, &m_cSbacDecoder, &m_cBinCABAC, &m_cCavlcDecoder, &m_cSliceDecoder, &m_cLoopFilter, &m_cSAO);
473  m_cSliceDecoder.init( &m_cEntropyDecoder, &m_cCuDecoder );
474  m_cEntropyDecoder.init(&m_cPrediction);
475}
476
477#if !NH_MV
478Void TDecTop::deletePicBuffer ( )
479{
480
481  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
482  Int iSize = Int( m_cListPic.size() );
483
484  for (Int i = 0; i < iSize; i++ )
485  {
486    TComPic* pcPic = *(iterPic++);
487    pcPic->destroy();
488
489    delete pcPic;
490    pcPic = NULL;
491  }
492
493  m_cSAO.destroy();
494
495  m_cLoopFilter.        destroy();
496
497  // destroy ROM
498  destroyROM();
499}
500
501Void TDecTop::xGetNewPicBuffer ( const TComSPS &sps, const TComPPS &pps, TComPic*& rpcPic, const UInt temporalLayer )
502{
503  m_iMaxRefPicNum = sps.getMaxDecPicBuffering(temporalLayer);     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
504  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
505  {
506    rpcPic = new TComPic();
507
508    rpcPic->create ( sps, pps, true);
509
510    m_cListPic.pushBack( rpcPic );
511
512    return;
513  }
514
515  Bool bBufferIsAvailable = false;
516  TComList<TComPic*>::iterator  iterPic   = m_cListPic.begin();
517  while (iterPic != m_cListPic.end())
518  {
519    rpcPic = *(iterPic++);
520    if ( rpcPic->getReconMark() == false && rpcPic->getOutputMark() == false)
521    {
522      rpcPic->setOutputMark(false);
523      bBufferIsAvailable = true;
524      break;
525    }
526
527    if ( rpcPic->getSlice( 0 )->isReferenced() == false  && rpcPic->getOutputMark() == false)
528    {
529      rpcPic->setOutputMark(false);
530      rpcPic->setReconMark( false );
531      rpcPic->getPicYuvRec()->setBorderExtension( false );
532      bBufferIsAvailable = true;
533      break;
534    }
535  }
536
537  if ( !bBufferIsAvailable )
538  {
539    //There is no room for this picture, either because of faulty encoder or dropped NAL. Extend the buffer.
540    m_iMaxRefPicNum++;
541    rpcPic = new TComPic();
542    m_cListPic.pushBack( rpcPic );
543  }
544  rpcPic->destroy();
545  rpcPic->create ( sps, pps, true);
546}
547
548Void TDecTop::executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic)
549{
550  if (!m_pcPic)
551  {
552    /* nothing to deblock */
553    return;
554  }
555
556  TComPic*   pcPic         = m_pcPic;
557
558  // Execute Deblock + Cleanup
559
560  m_cGopDecoder.filterPicture(pcPic);
561
562  TComSlice::sortPicList( m_cListPic ); // sorting for application output
563  poc                 = pcPic->getSlice(m_uiSliceIdx-1)->getPOC();
564  rpcListPic          = &m_cListPic;
565  m_cCuDecoder.destroy();
566  m_bFirstSliceInPicture  = true;
567  return;
568}
569
570Void TDecTop::checkNoOutputPriorPics (TComList<TComPic*>* pcListPic)
571{
572  if (!pcListPic || !m_isNoOutputPriorPics)
573  {
574    return;
575  }
576
577  TComList<TComPic*>::iterator  iterPic   = pcListPic->begin();
578
579  while (iterPic != pcListPic->end())
580  {
581    TComPic* pcPicTmp = *(iterPic++);
582    if (m_lastPOCNoOutputPriorPics != pcPicTmp->getPOC())
583    {
584      pcPicTmp->setOutputMark(false);
585    }
586  }
587}
588
589Void TDecTop::xCreateLostPicture(Int iLostPoc)
590{
591  printf("\ninserting lost poc : %d\n",iLostPoc);
592  TComPic *cFillPic;
593  xGetNewPicBuffer(*(m_parameterSetManager.getFirstSPS()), *(m_parameterSetManager.getFirstPPS()), cFillPic, 0);
594  cFillPic->getSlice(0)->initSlice();
595
596  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
597  Int closestPoc = 1000000;
598  while ( iterPic != m_cListPic.end())
599  {
600    TComPic * rpcPic = *(iterPic++);
601    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())
602    {
603      closestPoc=abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc);
604    }
605  }
606  iterPic = m_cListPic.begin();
607  while ( iterPic != m_cListPic.end())
608  {
609    TComPic *rpcPic = *(iterPic++);
610    if(abs(rpcPic->getPicSym()->getSlice(0)->getPOC() -iLostPoc)==closestPoc&&rpcPic->getPicSym()->getSlice(0)->getPOC()!=m_apcSlicePilot->getPOC())
611    {
612      printf("copying picture %d to %d (%d)\n",rpcPic->getPicSym()->getSlice(0)->getPOC() ,iLostPoc,m_apcSlicePilot->getPOC());
613      rpcPic->getPicYuvRec()->copyToPic(cFillPic->getPicYuvRec());
614      break;
615    }
616  }
617  cFillPic->setCurrSliceIdx(0);
618  for(Int ctuRsAddr=0; ctuRsAddr<cFillPic->getNumberOfCtusInFrame(); ctuRsAddr++)
619  {
620    cFillPic->getCtu(ctuRsAddr)->initCtu(cFillPic, ctuRsAddr);
621  }
622  cFillPic->getSlice(0)->setReferenced(true);
623  cFillPic->getSlice(0)->setPOC(iLostPoc);
624  xUpdatePreviousTid0POC(cFillPic->getSlice(0));
625  cFillPic->setReconMark(true);
626  cFillPic->setOutputMark(true);
627  if(m_pocRandomAccess == MAX_INT)
628  {
629    m_pocRandomAccess = iLostPoc;
630  }
631}
632#endif
633
634
635#if NH_MV
636Void TDecTop::activatePSsAndInitPicOrSlice( TComPic* newPic )
637{
638  if ( m_apcSlicePilot->getFirstSliceSegementInPicFlag() )
639  {
640    assert( newPic != NULL );
641
642#else
643Void TDecTop::xActivateParameterSets()
644{
645  if (m_bFirstSliceInPicture)
646  {
647#endif
648    const TComPPS *pps = m_parameterSetManager.getPPS(m_apcSlicePilot->getPPSId()); // this is a temporary PPS object. Do not store this value
649    assert (pps != 0);
650
651    const TComSPS *sps = m_parameterSetManager.getSPS(pps->getSPSId());             // this is a temporary SPS object. Do not store this value
652    assert (sps != 0);
653
654    m_parameterSetManager.clearSPSChangedFlag(sps->getSPSId());
655    m_parameterSetManager.clearPPSChangedFlag(pps->getPPSId());
656#if NH_MV
657    const TComVPS* vps = m_parameterSetManager.getVPS(sps->getVPSId());
658    assert (vps != 0);
659    // TBD: check the condition on m_firstPicInLayerDecodedFlag
660    if (!m_parameterSetManager.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP() || !m_firstPicInLayerDecodedFlag[m_layerId] , m_layerId ) )
661#else
662    if (false == m_parameterSetManager.activatePPS(m_apcSlicePilot->getPPSId(),m_apcSlicePilot->isIRAP()))
663#endif
664    {
665      printf ("Parameter set activation failed!");
666      assert (0);
667    }
668
669#if NH_MV
670    if ( decProcAnnexG() )
671    {
672      // When the value of vps_num_rep_formats_minus1 in the active VPS is equal to 0
673      if ( vps->getVpsNumRepFormatsMinus1() == 0 )
674      {
675        //, it is a requirement of bitstream conformance that the value of update_rep_format_flag shall be equal to 0.
676        assert( sps->getUpdateRepFormatFlag() == false );
677      }
678      sps->checkRpsMaxNumPics( vps, getLayerId() );
679
680      // It is a requirement of bitstream conformance that, when the SPS is referred to by
681      // any current picture that belongs to an independent non-base layer, the value of
682      // MultiLayerExtSpsFlag derived from the SPS shall be equal to 0.
683
684      if ( m_layerId > 0 && vps->getNumRefLayers( m_layerId ) == 0 )
685      {
686        assert( sps->getMultiLayerExtSpsFlag() == 0 );
687      }
688    }
689    m_seiReader.setLayerId ( newPic->getLayerId      ( ) );
690    m_seiReader.setDecOrder( newPic->getDecodingOrder( ) );
691#endif
692
693    xParsePrefixSEImessages();
694
695#if RExt__HIGH_BIT_DEPTH_SUPPORT==0
696    if (sps->getSpsRangeExtension().getExtendedPrecisionProcessingFlag() || sps->getBitDepth(CHANNEL_TYPE_LUMA)>12 || sps->getBitDepth(CHANNEL_TYPE_CHROMA)>12 )
697    {
698      printf("High bit depth support must be enabled at compile-time in order to decode this bitstream\n");
699      assert (0);
700      exit(1);
701    }
702#endif
703
704    // NOTE: globals were set up here originally. You can now use:
705    // g_uiMaxCUDepth = sps->getMaxTotalCUDepth();
706    // g_uiAddCUDepth = sps->getMaxTotalCUDepth() - sps->getLog2DiffMaxMinCodingBlockSize()
707
708    //  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.
709#if !NH_MV
710    xGetNewPicBuffer (*(sps), *(pps), m_pcPic, m_apcSlicePilot->getTLayer());
711
712    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
713#else
714    m_pcPic = newPic;
715#endif
716
717    // make the slice-pilot a real slice, and set up the slice-pilot for the next slice
718    assert(m_pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
719    m_apcSlicePilot = m_pcPic->getPicSym()->swapSliceObject(m_apcSlicePilot, m_uiSliceIdx);
720
721    // we now have a real slice:
722    TComSlice *pSlice = m_pcPic->getSlice(m_uiSliceIdx);
723
724    // Update the PPS and SPS pointers with the ones of the picture.
725    pps=pSlice->getPPS();
726    sps=pSlice->getSPS();
727
728#if NH_MV
729    pSlice->setPic( m_pcPic );
730    vps=pSlice->getVPS();
731    // 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.
732    assert( pps->getLayerId() == m_layerId || pps->getLayerId( ) == 0 || vps->getDependencyFlag( m_layerId, pps->getLayerId() ) );
733    // 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.
734    assert( sps->getLayerId() == m_layerId || sps->getLayerId( ) == 0 || vps->getDependencyFlag( m_layerId, sps->getLayerId() ) );
735#endif
736
737#if NH_3D
738    if ( !m_pcCamParsCollector->isInitialized() )
739    {
740      m_pcCamParsCollector->init( vps );
741    }
742#endif
743    // Initialise the various objects for the new set of settings
744    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) );
745    m_cLoopFilter.create( sps->getMaxTotalCUDepth() );
746    m_cPrediction.initTempBuff(sps->getChromaFormatIdc());
747
748
749    Bool isField = false;
750    Bool isTopField = false;
751
752    if(!m_SEIs.empty())
753    {
754      // Check if any new Picture Timing SEI has arrived
755      SEIMessages pictureTimingSEIs = getSeisByType(m_SEIs, SEI::PICTURE_TIMING);
756      if (pictureTimingSEIs.size()>0)
757      {
758        SEIPictureTiming* pictureTiming = (SEIPictureTiming*) *(pictureTimingSEIs.begin());
759        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);
760        isTopField = (pictureTiming->m_picStruct == 1) || (pictureTiming->m_picStruct == 9) || (pictureTiming->m_picStruct == 11);
761      }
762    }
763
764    //Set Field/Frame coding mode
765    m_pcPic->setField(isField);
766    m_pcPic->setTopField(isTopField);
767
768    // transfer any SEI messages that have been received to the picture
769    m_pcPic->setSEIs(m_SEIs);
770    m_SEIs.clear();
771
772    // Recursive structure
773    m_cCuDecoder.create ( sps->getMaxTotalCUDepth(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getChromaFormatIdc() );
774    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
775    m_cTrQuant.init     ( sps->getMaxTrSize() );
776
777    m_cSliceDecoder.create();
778  }
779  else
780  {
781#if NH_MV
782    assert( m_pcPic != NULL );
783    assert( newPic  == NULL );
784#endif
785    // make the slice-pilot a real slice, and set up the slice-pilot for the next slice
786    m_pcPic->allocateNewSlice();
787    assert(m_pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
788    m_apcSlicePilot = m_pcPic->getPicSym()->swapSliceObject(m_apcSlicePilot, m_uiSliceIdx);
789
790    TComSlice *pSlice = m_pcPic->getSlice(m_uiSliceIdx); // we now have a real slice.
791
792    const TComSPS *sps = pSlice->getSPS();
793    const TComPPS *pps = pSlice->getPPS();
794
795    // check that the current active PPS has not changed...
796    if (m_parameterSetManager.getSPSChangedFlag(sps->getSPSId()) )
797    {
798      printf("Error - a new SPS has been decoded while processing a picture\n");
799      exit(1);
800    }
801    if (m_parameterSetManager.getPPSChangedFlag(pps->getPPSId()) )
802    {
803      printf("Error - a new PPS has been decoded while processing a picture\n");
804      exit(1);
805    }
806
807    xParsePrefixSEImessages();
808
809    // Check if any new SEI has arrived
810    if(!m_SEIs.empty())
811    {
812      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
813      SEIMessages &picSEI = m_pcPic->getSEIs();
814      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
815      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
816      deleteSEIs(m_SEIs);
817    }
818  }
819}
820
821Void TDecTop::xParsePrefixSEIsForUnknownVCLNal()
822{
823  while (!m_prefixSEINALUs.empty())
824  {
825    // do nothing?
826    printf("Discarding Prefix SEI associated with unknown VCL NAL unit.\n");
827    delete m_prefixSEINALUs.front();
828  }
829  // TODO: discard following suffix SEIs as well?
830}
831
832
833Void TDecTop::xParsePrefixSEImessages()
834{
835  while (!m_prefixSEINALUs.empty())
836  {
837    InputNALUnit &nalu=*m_prefixSEINALUs.front();
838#if NH_MV
839    m_seiReader.parseSEImessage(&(nalu.getBitstream()), m_SEIs, nalu.m_nalUnitType, m_parameterSetManager.getActiveVPS(), m_parameterSetManager.getActiveSPS(getLayerId()), m_pDecodedSEIOutputStream);
840#else
841    m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_SEIs, nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS(), m_pDecodedSEIOutputStream );
842#endif
843    delete m_prefixSEINALUs.front();
844    m_prefixSEINALUs.pop_front();
845  }
846}
847
848#if !NH_MV
849Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
850{
851  m_apcSlicePilot->initSlice(); // the slice pilot is an object to prepare for a new slice
852  // it is not associated with picture, sps or pps structures.
853  if (m_bFirstSliceInPicture)
854  {
855#else
856Void TDecTop::decodeSliceHeader(InputNALUnit &nalu )
857{
858  // Initialize entropy decoder
859  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
860  m_cEntropyDecoder.setBitstream      (&(nalu.getBitstream()));
861
862  assert( nalu.m_nuhLayerId == m_layerId );
863  m_apcSlicePilot->initSlice(); // the slice pilot is an object to prepare for a new slice
864  // it is not associated with picture, sps or pps structures.
865  m_apcSlicePilot->setLayerId( nalu.m_nuhLayerId );
866  m_cEntropyDecoder.decodeFirstSliceSegmentInPicFlag( m_apcSlicePilot );
867  if ( m_apcSlicePilot->getFirstSliceSegementInPicFlag() )
868  {
869#endif
870    m_uiSliceIdx = 0;
871  }
872  else
873  {
874    m_apcSlicePilot->copySliceInfo( m_pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
875  }
876  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
877
878  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
879  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
880    m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
881    m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
882    m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
883    m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
884  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
885#if !NH_MV
886  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
887#endif
888  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
889#if NH_MV
890  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManager );
891#else
892#if ENC_DEC_TRACE
893  const UInt64 originalSymbolCount = g_nSymbolCounter;
894#endif
895    m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManager, m_prevTid0POC);
896#endif
897
898#if NH_MV
899}
900#else
901  // set POC for dependent slices in skipped pictures
902  if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped)
903  {
904    m_apcSlicePilot->setPOC(m_skippedPOC);
905  }
906
907  xUpdatePreviousTid0POC(m_apcSlicePilot);
908  m_apcSlicePilot->setAssociatedIRAPPOC(m_pocCRA);
909  m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType);
910
911
912  //For inference of NoOutputOfPriorPicsFlag
913  if (m_apcSlicePilot->getRapPicFlag())
914  {
915      if ((m_apcSlicePilot->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_apcSlicePilot->getNalUnitType() <= NAL_UNIT_CODED_SLICE_IDR_N_LP) ||
916        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_bFirstSliceInSequence) ||
917        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getHandleCraAsBlaFlag()))
918      {
919        m_apcSlicePilot->setNoRaslOutputFlag(true);
920      }
921    //the inference for NoOutputPriorPicsFlag
922    if (!m_bFirstSliceInBitstream && m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag())
923    {
924      if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
925      {
926        m_apcSlicePilot->setNoOutputPriorPicsFlag(true);
927      }
928    }
929    else
930    {
931      m_apcSlicePilot->setNoOutputPriorPicsFlag(false);
932    }
933
934    if(m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
935    {
936      m_craNoRaslOutputFlag = m_apcSlicePilot->getNoRaslOutputFlag();
937    }
938  }
939  if (m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoOutputPriorPicsFlag())
940  {
941    m_lastPOCNoOutputPriorPics = m_apcSlicePilot->getPOC();
942    m_isNoOutputPriorPics = true;
943  }
944  else
945  {
946    m_isNoOutputPriorPics = false;
947  }
948
949  //For inference of PicOutputFlag
950  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R)
951  {
952    if ( m_craNoRaslOutputFlag )
953    {
954      m_apcSlicePilot->setPicOutputFlag(false);
955    }
956  }
957
958  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_craNoRaslOutputFlag) //Reset POC MSB when CRA has NoRaslOutputFlag equal to 1
959  {
960    TComPPS *pps = m_parameterSetManager.getPPS(m_apcSlicePilot->getPPSId());
961    assert (pps != 0);
962    TComSPS *sps = m_parameterSetManager.getSPS(pps->getSPSId());
963    assert (sps != 0);
964    Int iMaxPOClsb = 1 << sps->getBitsForPOC();
965    m_apcSlicePilot->setPOC( m_apcSlicePilot->getPOC() & (iMaxPOClsb - 1) );
966    xUpdatePreviousTid0POC(m_apcSlicePilot);
967  }
968
969  // Skip pictures due to random access
970  if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
971  {
972    m_prevSliceSkipped = true;
973    m_skippedPOC = m_apcSlicePilot->getPOC();
974    return false;
975  }
976  // Skip TFD pictures associated with BLA/BLANT pictures
977  if (isSkipPictureForBLA(iPOCLastDisplay))
978  {
979    m_prevSliceSkipped = true;
980    m_skippedPOC = m_apcSlicePilot->getPOC();
981    return false;
982  }
983
984  // clear previous slice skipped flag
985  m_prevSliceSkipped = false;
986
987  //we should only get a different poc for a new picture (with CTU address==0)
988  if (!m_apcSlicePilot->getDependentSliceSegmentFlag() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (m_apcSlicePilot->getSliceCurStartCtuTsAddr() != 0))
989  {
990    printf ("Warning, the first slice of a picture might have been lost!\n");
991  }
992
993  // exit when a new picture is found
994  if (!m_apcSlicePilot->getDependentSliceSegmentFlag() && (m_apcSlicePilot->getSliceCurStartCtuTsAddr() == 0 && !m_bFirstSliceInPicture) )
995  {
996    if (m_prevPOC >= m_pocRandomAccess)
997    {
998      m_prevPOC = m_apcSlicePilot->getPOC();
999
1000#if ENC_DEC_TRACE
1001      //rewind the trace counter since we didn't actually decode the slice
1002      g_nSymbolCounter = originalSymbolCount;
1003#endif
1004      return true;
1005    }
1006    m_prevPOC = m_apcSlicePilot->getPOC();
1007  }
1008
1009  //detect lost reference picture and insert copy of earlier frame.
1010  {
1011    Int lostPoc;
1012    while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
1013    {
1014      xCreateLostPicture(lostPoc-1);
1015    }
1016  }
1017
1018  if (!m_apcSlicePilot->getDependentSliceSegmentFlag())
1019  {
1020    m_prevPOC = m_apcSlicePilot->getPOC();
1021  }
1022  // actual decoding starts here
1023  xActivateParameterSets();
1024
1025  m_bFirstSliceInSequence = false;
1026  m_bFirstSliceInBitstream  = false;
1027
1028
1029  TComSlice* pcSlice = m_pcPic->getPicSym()->getSlice(m_uiSliceIdx);
1030
1031#endif
1032
1033#if NH_MV
1034Void TDecTop::decodeSliceSegment(InputNALUnit &nalu )
1035{
1036  TComSlice* pcSlice = m_pcPic->getPicSym()->getSlice(m_uiSliceIdx);
1037
1038  if ( m_pcPic->getHasGeneratedRefPics() )
1039  {
1040    if ( pcSlice->getFirstSliceSegementInPicFlag() )
1041    {
1042      std::cout << std:: setfill(' ')
1043        << "Layer "  << std::setw(2) << m_pcPic->getLayerId()
1044        << "   POC " << std::setw(4) << m_pcPic->getPOC()
1045        << " Reference pictures missing. Skipping picture." << std::endl;
1046    }
1047  }
1048  else
1049  {
1050    //Check Multiview Main profile constraint in G.11.1.1
1051    //  When ViewOrderIdx[ i ] derived according to any active VPS is equal to 1
1052    //  for the layer with nuh_layer_id equal to i in subBitstream,
1053    //  inter_view_mv_vert_constraint_flag shall be equal to 1
1054    //  in the sps_multilayer_extension( ) syntax structure in each active SPS for that layer.
1055    if( pcSlice->getSPS()->getPTL()->getGeneralPTL()->getProfileIdc()==Profile::MULTIVIEWMAIN
1056      &&
1057      pcSlice->getVPS()->getViewOrderIdx(pcSlice->getVPS()->getLayerIdInNuh(getLayerId()))==1
1058      )
1059    {
1060      assert( pcSlice->getSPS()->getInterViewMvVertConstraintFlag()==1 );
1061    }
1062
1063    m_pcPic->setLayerId( nalu.m_nuhLayerId );
1064    m_pcPic->setViewId ( getViewId() );
1065#if NH_3D || NH_3D_VSO
1066    m_pcPic->setViewIndex( getViewIndex() );
1067    m_pcPic->setIsDepth  ( getIsDepth  () );
1068    pcSlice->setIvPicLists( m_dpb );
1069#endif
1070#endif
1071
1072    // When decoding the slice header, the stored start and end addresses were actually RS addresses, not TS addresses.
1073    // Now, having set up the maps, convert them to the correct form.
1074    pcSlice->setSliceSegmentCurStartCtuTsAddr( m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceSegmentCurStartCtuTsAddr()) );
1075    pcSlice->setSliceSegmentCurEndCtuTsAddr( m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceSegmentCurEndCtuTsAddr()) );
1076    if(!pcSlice->getDependentSliceSegmentFlag())
1077    {
1078      pcSlice->setSliceCurStartCtuTsAddr(m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceCurStartCtuTsAddr()));
1079      pcSlice->setSliceCurEndCtuTsAddr(m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceCurEndCtuTsAddr()));
1080    }
1081
1082    m_pcPic->setTLayer(nalu.m_temporalId);
1083
1084
1085    if (!pcSlice->getDependentSliceSegmentFlag())
1086    {
1087#if !NH_MV
1088      pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_associatedIRAPType, m_cListPic );
1089      // Set reference list
1090      pcSlice->setRefPicList( m_cListPic, true );
1091#else
1092      if (pcSlice->getSliceType() != I_SLICE )
1093      {
1094        if( m_decProcPocAndRps == ANNEX_F )
1095        {
1096          pcSlice->f834decProcForRefPicListConst();
1097        }
1098        else if ( m_decProcPocAndRps == CLAUSE_8 )
1099        {
1100          pcSlice->cl834DecProcForRefPicListConst();
1101        }
1102        else
1103        {
1104          assert( false );
1105        }
1106      }
1107#if NH_3D_NBDV
1108      pcSlice->setDefaultRefView();
1109#endif
1110#if NH_3D_ARP
1111      pcSlice->setPocsInCurrRPSs();
1112      pcSlice->setARPStepNum(m_dpb);
1113#endif
1114#endif
1115
1116      // For generalized B
1117      // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
1118      if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
1119      {
1120        Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
1121        pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
1122
1123        for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
1124        {
1125          pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
1126        }
1127      }
1128      if (!pcSlice->isIntra())
1129      {
1130        Bool bLowDelay = true;
1131        Int  iCurrPOC  = pcSlice->getPOC();
1132        Int iRefIdx = 0;
1133
1134        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
1135        {
1136          if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
1137          {
1138            bLowDelay = false;
1139          }
1140        }
1141        if (pcSlice->isInterB())
1142        {
1143          for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
1144          {
1145            if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
1146            {
1147              bLowDelay = false;
1148            }
1149          }
1150        }
1151
1152        pcSlice->setCheckLDC(bLowDelay);
1153      }
1154
1155      //---------------
1156      pcSlice->setRefPOCList();
1157#if  NH_3D_TMVP
1158      if(pcSlice->getLayerId())
1159      {
1160        pcSlice->generateAlterRefforTMVP();
1161      }
1162#endif
1163    }
1164
1165    m_pcPic->setCurrSliceIdx(m_uiSliceIdx);
1166    if(pcSlice->getSPS()->getScalingListFlag())
1167    {
1168      TComScalingList scalingList;
1169      if(pcSlice->getPPS()->getScalingListPresentFlag())
1170      {
1171        scalingList = pcSlice->getPPS()->getScalingList();
1172      }
1173      else if (pcSlice->getSPS()->getScalingListPresentFlag())
1174      {
1175        scalingList = pcSlice->getSPS()->getScalingList();
1176      }
1177      else
1178      {
1179        scalingList.setDefaultScalingList();
1180      }
1181      m_cTrQuant.setScalingListDec(scalingList);
1182      m_cTrQuant.setUseScalingList(true);
1183    }
1184    else
1185    {
1186      const Int maxLog2TrDynamicRange[MAX_NUM_CHANNEL_TYPE] =
1187      {
1188        pcSlice->getSPS()->getMaxLog2TrDynamicRange(CHANNEL_TYPE_LUMA),
1189        pcSlice->getSPS()->getMaxLog2TrDynamicRange(CHANNEL_TYPE_CHROMA)
1190      };
1191      m_cTrQuant.setFlatScalingList(maxLog2TrDynamicRange, pcSlice->getSPS()->getBitDepths());
1192      m_cTrQuant.setUseScalingList(false);
1193    }
1194
1195#if NH_3D
1196    if ( decProcAnnexI() )
1197    {
1198      pcSlice->checkInCompPredRefLayers();
1199    }
1200#endif
1201
1202    //  Decode a picture
1203    m_cGopDecoder.decompressSlice(&(nalu.getBitstream()), m_pcPic);
1204
1205#if NH_3D
1206    if( m_pcCamParsCollector )
1207    {
1208      m_pcCamParsCollector->setSlice( pcSlice );
1209    }
1210#endif
1211
1212#if !NH_MV
1213    m_bFirstSliceInPicture = false;
1214#else
1215  }
1216#endif
1217  m_uiSliceIdx++;
1218
1219#if !NH_MV
1220  return false;
1221#endif
1222}
1223
1224
1225Void TDecTop::xDecodeVPS(const std::vector<UChar> &naluData)
1226{
1227  TComVPS* vps = new TComVPS();
1228
1229  m_cEntropyDecoder.decodeVPS( vps );
1230  m_parameterSetManager.storeVPS(vps, naluData);
1231}
1232
1233Void TDecTop::xDecodeSPS(const std::vector<UChar> &naluData)
1234{
1235  TComSPS* sps = new TComSPS();
1236#if NH_MV
1237  sps->setLayerId( getLayerId() );
1238#endif
1239#if O0043_BEST_EFFORT_DECODING
1240  sps->setForceDecodeBitDepth(m_forceDecodeBitDepth);
1241#endif
1242#if NH_3D
1243  // GT: Please don't add parsing dependency of SPS from VPS here again!!!
1244#endif
1245  m_cEntropyDecoder.decodeSPS( sps );
1246  m_parameterSetManager.storeSPS(sps, naluData);
1247}
1248
1249Void TDecTop::xDecodePPS(const std::vector<UChar> &naluData)
1250{
1251  TComPPS* pps = new TComPPS();
1252#if NH_MV
1253  pps->setLayerId( getLayerId() );
1254#endif
1255#if NH_3D_DLT
1256  // create mapping from depth layer indexes to layer ids
1257  Int j=0;
1258  for( Int i=0; i<=m_parameterSetManager.getFirstVPS()->getMaxLayersMinus1(); i++ )
1259  {
1260    Int layerId = m_parameterSetManager.getFirstVPS()->getLayerIdInNuh(i);
1261    if( m_parameterSetManager.getFirstVPS()->getDepthId(layerId) )
1262      pps->getDLT()->setDepthIdxToLayerId(j++, layerId);
1263  }
1264#endif
1265  m_cEntropyDecoder.decodePPS( pps );
1266
1267  m_parameterSetManager.storePPS( pps, naluData);
1268}
1269
1270#if NH_MV
1271Bool TDecTop::decodeNonVclNalu(InputNALUnit& nalu )
1272#else
1273Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1274#endif
1275{
1276#if !NH_MV
1277  // ignore all NAL units of layers > 0
1278  if (nalu.m_nuhLayerId > 0)
1279  {
1280    fprintf (stderr, "Warning: found NAL unit with nuh_layer_id equal to %d. Ignoring.\n", nalu.m_nuhLayerId);
1281    return false;
1282  }
1283#endif
1284  // Initialize entropy decoder
1285  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1286  m_cEntropyDecoder.setBitstream      (&(nalu.getBitstream()));
1287
1288  switch (nalu.m_nalUnitType)
1289  {
1290    case NAL_UNIT_VPS:
1291      xDecodeVPS(nalu.getBitstream().getFifo());
1292      return false;
1293
1294    case NAL_UNIT_SPS:
1295      xDecodeSPS(nalu.getBitstream().getFifo());
1296      return false;
1297
1298    case NAL_UNIT_PPS:
1299      xDecodePPS(nalu.getBitstream().getFifo());
1300      return false;
1301
1302    case NAL_UNIT_PREFIX_SEI:
1303      // Buffer up prefix SEI messages until SPS of associated VCL is known.
1304      m_prefixSEINALUs.push_back(new InputNALUnit(nalu));
1305      return false;
1306
1307    case NAL_UNIT_SUFFIX_SEI:
1308      if (m_pcPic)
1309      {
1310#if NH_MV
1311      m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_pcPic->getSEIs(), nalu.m_nalUnitType, m_parameterSetManager.getActiveVPS(), m_parameterSetManager.getActiveSPS(getLayerId()), m_pDecodedSEIOutputStream);
1312#else
1313        m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_pcPic->getSEIs(), nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS(), m_pDecodedSEIOutputStream );
1314#endif
1315      }
1316      else
1317      {
1318        printf ("Note: received suffix SEI but no picture currently active.\n");
1319      }
1320      return false;
1321
1322    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1323    case NAL_UNIT_CODED_SLICE_TRAIL_N:
1324    case NAL_UNIT_CODED_SLICE_TSA_R:
1325    case NAL_UNIT_CODED_SLICE_TSA_N:
1326    case NAL_UNIT_CODED_SLICE_STSA_R:
1327    case NAL_UNIT_CODED_SLICE_STSA_N:
1328    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
1329    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
1330    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1331    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
1332    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
1333    case NAL_UNIT_CODED_SLICE_CRA:
1334    case NAL_UNIT_CODED_SLICE_RADL_N:
1335    case NAL_UNIT_CODED_SLICE_RADL_R:
1336    case NAL_UNIT_CODED_SLICE_RASL_N:
1337    case NAL_UNIT_CODED_SLICE_RASL_R:
1338#if NH_MV
1339      assert( false );
1340      return 1;
1341#else
1342      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1343#endif
1344      break;
1345
1346    case NAL_UNIT_EOS:
1347#if !NH_MV
1348      m_associatedIRAPType = NAL_UNIT_INVALID;
1349      m_pocCRA = 0;
1350      m_pocRandomAccess = MAX_INT;
1351      m_prevPOC = MAX_INT;
1352      m_prevSliceSkipped = false;
1353      m_skippedPOC = 0;
1354#endif
1355      return false;
1356
1357    case NAL_UNIT_ACCESS_UNIT_DELIMITER:
1358      {
1359        AUDReader audReader;
1360        UInt picType;
1361        audReader.parseAccessUnitDelimiter(&(nalu.getBitstream()),picType);
1362        printf ("Note: found NAL_UNIT_ACCESS_UNIT_DELIMITER\n");
1363      return false;
1364      }
1365
1366    case NAL_UNIT_EOB:
1367      return false;
1368
1369    case NAL_UNIT_FILLER_DATA:
1370      {
1371        FDReader fdReader;
1372        UInt size;
1373        fdReader.parseFillerData(&(nalu.getBitstream()),size);
1374        printf ("Note: found NAL_UNIT_FILLER_DATA with %u bytes payload.\n", size);
1375      return false;
1376      }
1377
1378    case NAL_UNIT_RESERVED_VCL_N10:
1379    case NAL_UNIT_RESERVED_VCL_R11:
1380    case NAL_UNIT_RESERVED_VCL_N12:
1381    case NAL_UNIT_RESERVED_VCL_R13:
1382    case NAL_UNIT_RESERVED_VCL_N14:
1383    case NAL_UNIT_RESERVED_VCL_R15:
1384
1385    case NAL_UNIT_RESERVED_IRAP_VCL22:
1386    case NAL_UNIT_RESERVED_IRAP_VCL23:
1387
1388    case NAL_UNIT_RESERVED_VCL24:
1389    case NAL_UNIT_RESERVED_VCL25:
1390    case NAL_UNIT_RESERVED_VCL26:
1391    case NAL_UNIT_RESERVED_VCL27:
1392    case NAL_UNIT_RESERVED_VCL28:
1393    case NAL_UNIT_RESERVED_VCL29:
1394    case NAL_UNIT_RESERVED_VCL30:
1395    case NAL_UNIT_RESERVED_VCL31:
1396      printf ("Note: found reserved VCL NAL unit.\n");
1397      xParsePrefixSEIsForUnknownVCLNal();
1398      return false;
1399
1400    case NAL_UNIT_RESERVED_NVCL41:
1401    case NAL_UNIT_RESERVED_NVCL42:
1402    case NAL_UNIT_RESERVED_NVCL43:
1403    case NAL_UNIT_RESERVED_NVCL44:
1404    case NAL_UNIT_RESERVED_NVCL45:
1405    case NAL_UNIT_RESERVED_NVCL46:
1406    case NAL_UNIT_RESERVED_NVCL47:
1407      printf ("Note: found reserved NAL unit.\n");
1408      return false;
1409    case NAL_UNIT_UNSPECIFIED_48:
1410    case NAL_UNIT_UNSPECIFIED_49:
1411    case NAL_UNIT_UNSPECIFIED_50:
1412    case NAL_UNIT_UNSPECIFIED_51:
1413    case NAL_UNIT_UNSPECIFIED_52:
1414    case NAL_UNIT_UNSPECIFIED_53:
1415    case NAL_UNIT_UNSPECIFIED_54:
1416    case NAL_UNIT_UNSPECIFIED_55:
1417    case NAL_UNIT_UNSPECIFIED_56:
1418    case NAL_UNIT_UNSPECIFIED_57:
1419    case NAL_UNIT_UNSPECIFIED_58:
1420    case NAL_UNIT_UNSPECIFIED_59:
1421    case NAL_UNIT_UNSPECIFIED_60:
1422    case NAL_UNIT_UNSPECIFIED_61:
1423    case NAL_UNIT_UNSPECIFIED_62:
1424    case NAL_UNIT_UNSPECIFIED_63:
1425      printf ("Note: found unspecified NAL unit.\n");
1426      return false;
1427    default:
1428      assert (0);
1429      break;
1430  }
1431
1432  return false;
1433}
1434
1435#if !NH_MV
1436/** Function for checking if picture should be skipped because of association with a previous BLA picture
1437 * \param iPOCLastDisplay POC of last picture displayed
1438 * \returns true if the picture should be skipped
1439 * This function skips all TFD pictures that follow a BLA picture
1440 * in decoding order and precede it in output order.
1441 */
1442Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
1443{
1444  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) &&
1445       m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
1446  {
1447    iPOCLastDisplay++;
1448    return true;
1449  }
1450  return false;
1451}
1452
1453/** Function for checking if picture should be skipped because of random access
1454 * \param iSkipFrame skip frame counter
1455 * \param iPOCLastDisplay POC of last picture displayed
1456 * \returns true if the picture shold be skipped in the random access.
1457 * This function checks the skipping of pictures in the case of -s option random access.
1458 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1459 * It also checks the type of Nal unit type at the random access point.
1460 * 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.
1461 * If the random access point is IDR all pictures after the random access point are decoded.
1462 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
1463 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
1464 * access point there is no guarantee that the decoder will not crash.
1465 */
1466Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay )
1467{
1468  if (iSkipFrame)
1469  {
1470    iSkipFrame--;   // decrement the counter
1471    return true;
1472  }
1473  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1474  {
1475    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
1476        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1477        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1478        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
1479    {
1480
1481      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
1482      m_pocRandomAccess = m_apcSlicePilot->getPOC();
1483    }
1484    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
1485    {
1486      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1487    }
1488    else
1489    {
1490      if(!m_warningMessageSkipPicture)
1491      {
1492        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1493        m_warningMessageSkipPicture = true;
1494      }
1495      return true;
1496    }
1497  }
1498  // skip the reordered pictures, if necessary
1499  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))
1500  {
1501    iPOCLastDisplay++;
1502    return true;
1503  }
1504  // if we reach here, then the picture is not skipped.
1505  return false;
1506}
1507
1508#else
1509
1510Int TDecTop::preDecodePoc( Bool firstPicInLayerDecodedFlag, Bool isFstPicOfAllLayOfPocResetPer, Bool isPocResettingPicture )
1511{
1512  //Output of this process is PicOrderCntVal, the picture order count of the current picture.
1513  //  Picture order counts are used to identify pictures, for deriving motion parameters in merge mode and
1514  //  motion vector prediction and for decoder conformance checking (see clause F.13.5).
1515
1516  //  Each coded picture is associated with a picture order count variable, denoted as PicOrderCntVal.
1517
1518  TComSlice* slice = m_apcSlicePilot;
1519  const Int nuhLayerId   = slice->getLayerId();
1520  const TComVPS*   vps   = slice->getVPS();
1521  const TComSPS*   sps   = slice->getSPS();
1522
1523  Int pocDecrementedInDpbFlag = m_pocDecrementedInDpbFlag[ nuhLayerId ];
1524
1525  if ( isFstPicOfAllLayOfPocResetPer )
1526  {
1527    //  When the current picture is the first picture among all layers of a POC resetting period,
1528    //  the variable PocDecrementedInDPBFlag[ i ] is set equal to 0 for each value of i in the range of 0 to 62, inclusive.
1529    pocDecrementedInDpbFlag = false;
1530  }
1531
1532  //  The variable pocResettingFlag is derived as follows:
1533  Bool pocResettingFlag;
1534  if ( isPocResettingPicture )
1535  {
1536    //-  If the current picture is a POC resetting picture, the following applies:
1537    if( vps->getVpsPocLsbAlignedFlag()  )
1538    {
1539      //  -  If vps_poc_lsb_aligned_flag is equal to 0, pocResettingFlag is set equal to 1.
1540      pocResettingFlag = true;
1541    }
1542    else if ( pocDecrementedInDpbFlag )
1543    {
1544      //  -  Otherwise, if PocDecrementedInDPBFlag[ nuh_layer_id ] is equal to 1, pocResettingFlag is set equal to 0.
1545      pocResettingFlag = false;
1546    }
1547    else
1548    {
1549      //  -  Otherwise, pocResettingFlag is set equal to 1.
1550      pocResettingFlag = true;
1551    }
1552  }
1553  else
1554  {
1555    //  -  Otherwise, pocResettingFlag is set equal to 0.
1556    pocResettingFlag = false;
1557  }
1558
1559  Int picOrderCntMsb;
1560  Int picOrderCntVal;
1561
1562  //  Depending on pocResettingFlag, the following applies:
1563  if ( pocResettingFlag )
1564  {
1565    //-  The PicOrderCntVal of the current picture is derived as follows:
1566    if( slice->getPocResetIdc()  ==  1 )
1567    {
1568      picOrderCntVal = slice->getSlicePicOrderCntLsb();
1569    }
1570    else if (slice->getPocResetIdc()  ==  2 )
1571    {
1572      picOrderCntVal = 0;
1573    }
1574    else
1575    {
1576      picOrderCntMsb = xGetCurrMsb( slice->getSlicePicOrderCntLsb(), slice->getFullPocResetFlag() ? 0 : slice->getPocLsbVal(), 0, sps->getMaxPicOrderCntLsb() );
1577      picOrderCntVal = picOrderCntMsb + slice->getSlicePicOrderCntLsb();
1578    }
1579  }
1580  else
1581  {
1582    //-  Otherwise (pocResettingFlag is equal to 0), the following applies:
1583    //-  The PicOrderCntVal of the current picture is derived as follows:
1584
1585    if( slice->getPocMsbCycleValPresentFlag() )
1586    {
1587      picOrderCntMsb = slice->getPocMsbCycleVal() * sps->getMaxPicOrderCntLsb();
1588    }
1589    else if( !firstPicInLayerDecodedFlag  ||
1590      slice->getNalUnitType()  ==  NAL_UNIT_CODED_SLICE_IDR_N_LP || slice->getNalUnitType() ==  NAL_UNIT_CODED_SLICE_IDR_W_RADL )
1591    {
1592      picOrderCntMsb = 0; //     (F 62)
1593    }
1594    else
1595    {
1596      Int prevPicOrderCntLsb = m_prevPicOrderCnt & ( sps->getMaxPicOrderCntLsb() - 1 );
1597      Int prevPicOrderCntMsb = m_prevPicOrderCnt - prevPicOrderCntLsb;
1598      picOrderCntMsb = xGetCurrMsb( slice->getSlicePicOrderCntLsb(), prevPicOrderCntLsb, prevPicOrderCntMsb, sps->getMaxPicOrderCntLsb() );
1599    }
1600    picOrderCntVal = picOrderCntMsb + slice->getSlicePicOrderCntLsb();
1601  }
1602  return picOrderCntVal;
1603}
1604
1605Void TDecTop::inferPocResetPeriodId()
1606{
1607  // Infer PocResetPeriodId
1608  // When not present, the value of poc_reset_period_id is inferred as follows:
1609
1610  if ( !m_apcSlicePilot->getHasPocResetPeriodIdPresent() )
1611  {
1612    if ( m_lastPresentPocResetIdc[ m_apcSlicePilot->getLayerId() ] != MIN_INT )
1613    {
1614      // - If the previous picture picA that has poc_reset_period_id present in the slice segment header is present in the same layer
1615      //   of the bitstream as the current picture, the value of poc_reset_period_id is inferred to be equal to the value of the
1616      //   poc_reset_period_id of picA.
1617
1618      m_apcSlicePilot->setPocResetPeriodId( m_lastPresentPocResetIdc[ m_apcSlicePilot->getLayerId() ] );
1619    }
1620    else
1621    {
1622      //- Otherwise, the value of poc_reset_period_id is inferred to be equal to 0.
1623      m_apcSlicePilot->setPocResetPeriodId( 0 );
1624    }
1625  }
1626  else
1627  {
1628    m_lastPresentPocResetIdc[ m_apcSlicePilot->getLayerId() ] = m_apcSlicePilot->getPocResetPeriodId();
1629  }
1630}
1631
1632
1633Void TDecTop::decodePocAndRps( )
1634{
1635  assert( m_uiSliceIdx == 0 );
1636  Int nuhLayerId = m_pcPic->getLayerId();
1637  if ( m_decProcPocAndRps == CLAUSE_8 )
1638  {
1639    // 8.1.3 Decoding process for a coded picture with nuh_layer_id equal to 0
1640
1641    // Variables and functions relating to picture order count are derived as
1642    // specified in clause 8.3.1. This needs to be invoked only for the first slice
1643    // segment of a picture.
1644    x831DecProcForPicOrderCount( );
1645
1646    // The decoding process for RPS in clause 8.3.2 is invoked, wherein reference
1647    // pictures may be marked as "unused for reference" or "used for long-term
1648    // reference". This needs to be invoked only for the first slice segment of a
1649    // picture.
1650    x832DecProcForRefPicSet    (  false );
1651  }
1652  else if( m_decProcPocAndRps == ANNEX_F )
1653  {
1654    // F.8.1.3 Common decoding process for a coded picture
1655
1656    if (nuhLayerId == 0 )
1657    {
1658      // F.8.1.4 Decoding process for a coded picture with nuh_layer_id equal to
1659      // --> Clause 8.1.3 is invoked with replacments of 8.3.1, 8.3.2, and 8.3.3 by F.8.3.1, 8.3.2, and 8.3.3
1660
1661      // Variables and functions relating to picture order count are derived as
1662      // specified in clause 8.3.1. This needs to be invoked only for the first slice
1663      // segment of a picture.
1664      xF831DecProcForPicOrderCount( );
1665
1666      // The decoding process for RPS in clause 8.3.2 is invoked, wherein reference
1667      // pictures may be marked as "unused for reference" or "used for long-term
1668      // reference". This needs to be invoked only for the first slice segment of a
1669      // picture.
1670      xF832DecProcForRefPicSet( );
1671    }
1672    else
1673    {
1674      // F.8.1.5 Decoding process for starting the decoding of a coded picture with
1675      // nuh_layer_id greater than 0
1676
1677      // Variables and functions relating to picture order count are derived in clause F.8.3.1.
1678      // This needs to be invoked only for the first slice segment of a picture. It is a requirement
1679      // of bitstream conformance that PicOrderCntVal of each picture in an access unit shall have the
1680      // same value during and at the end of decoding of the access unit
1681      xF831DecProcForPicOrderCount( );
1682
1683      // The decoding process for RPS in clause F.8.3.2 is invoked, wherein only reference pictures with
1684      // nuh_layer_id equal to that of CurrPic may be marked as "unused for reference" or "used for
1685      // long-term reference" and any picture with a different value of nuh_layer_id is not marked.
1686      // This needs to be invoked only for the first slice segment of a picture.
1687      xF832DecProcForRefPicSet( );
1688    }
1689  }
1690  else
1691  {
1692    assert( false );
1693  }
1694}
1695
1696Void TDecTop::genUnavailableRefPics( )
1697{
1698  assert( m_uiSliceIdx == 0 );
1699  Int nuhLayerId = m_pcPic->getLayerId();
1700  if ( m_decProcPocAndRps == CLAUSE_8 )
1701  {
1702    // 8.1.3 Decoding process for a coded picture with nuh_layer_id equal to 0
1703
1704    if ( m_pcPic->isBla() || ( m_pcPic->isCra() && m_pcPic->getNoRaslOutputFlag() ) )
1705    {
1706      // When the current picture is a BLA picture or is a CRA picture
1707      // with NoRaslOutputFlag equal to 1, the decoding process for generating
1708      // unavailable reference pictures specified in clause 8.3.3 is invoked,
1709      // which needs to be invoked only for the first slice segment of a picture.
1710      x8331GenDecProcForGenUnavilRefPics();
1711    }
1712  }
1713  else if( m_decProcPocAndRps == ANNEX_F )
1714  {
1715    // F.8.1.3 Common decoding process for a coded picture
1716
1717    if (nuhLayerId == 0 )
1718    {
1719      // F.8.1.4 Decoding process for a coded picture with nuh_layer_id equal to
1720      // --> Clause 8.1.3 is invoked with replacments of 8.3.1, 8.3.2, and 8.3.3 by F.8.3.1, 8.3.2, and 8.3.3
1721
1722      if ( m_pcPic->isBla() || ( m_pcPic->isCra() && m_pcPic->getNoRaslOutputFlag() ) )
1723      {
1724        // When the current picture is a BLA picture or is a CRA picture
1725        // with NoRaslOutputFlag equal to 1, the decoding process for generating
1726        // unavailable reference pictures specified in clause 8.3.3 is invoked,
1727        // which needs to be invoked only for the first slice segment of a picture.
1728        xF833DecProcForGenUnavRefPics();
1729      }
1730#if NH_MV_FIX_INIT_NUM_ACTIVE_REF_LAYER_PICS
1731      TComDecodedRps* decRps = m_pcPic->getDecodedRps();
1732      decRps->m_numActiveRefLayerPics0 = 0;
1733      decRps->m_numActiveRefLayerPics1 = 0;
1734#endif
1735    }
1736    else
1737    {
1738      // F.8.1.5 Decoding process for starting the decoding of a coded picture with
1739      // nuh_layer_id greater than 0
1740
1741      if ( !m_firstPicInLayerDecodedFlag[ nuhLayerId ] )
1742      {
1743        // When FirstPicInLayerDecodedFlag[ nuh_layer_id ] is equal to 0, the decoding process for generating
1744        // unavailable reference pictures for pictures first in decoding order within a layer specified in
1745        // clause F.8.1.7 is invoked, which needs to be invoked only for the first slice segment of a picture.
1746        xF817DecProcForGenUnavRefPicForPicsFrstInDecOrderInLay();
1747      }
1748
1749      if ( m_firstPicInLayerDecodedFlag[ nuhLayerId ] && ( m_pcPic->isIrap() && m_pcPic->getNoRaslOutputFlag() ) )
1750      {
1751        // When FirstPicInLayerDecodedFlag[ nuh_layer_id ] is equal to 1 and the current picture is an IRAP
1752        // picture with NoRaslOutputFlag equal to 1, the decoding process for generating unavailable reference
1753        // pictures specified in clause F.8.3.3 is invoked, which needs to be invoked only for the first slice
1754        // segment of a picture.
1755        xF833DecProcForGenUnavRefPics();
1756      }
1757
1758      if ( decProcAnnexG() )
1759      {
1760        // G.1.2 --> G.1.3
1761        xG813DecProcForInterLayerRefPicSet();
1762      }
1763      else
1764      {
1765#if NH_MV_FIX_INIT_NUM_ACTIVE_REF_LAYER_PICS
1766        TComDecodedRps* decRps = m_pcPic->getDecodedRps(); 
1767        decRps->m_numActiveRefLayerPics0 = 0;
1768        decRps->m_numActiveRefLayerPics1 = 0;     
1769#endif
1770      }
1771    }
1772  }
1773  else
1774  {
1775    assert( false );
1776  }
1777
1778  xCheckUnavailableRefPics();
1779}
1780Void TDecTop::executeLoopFilters( )
1781{
1782  assert( m_pcPic != NULL );
1783  if ( !m_pcPic->getHasGeneratedRefPics() && !m_pcPic->getIsGenerated() )
1784  {
1785    m_cGopDecoder.filterPicture( m_pcPic );
1786  }
1787  m_cCuDecoder.destroy();
1788}
1789
1790Void TDecTop::finalizePic()
1791{
1792  if( m_pcPic->isIrap() )
1793  {
1794    m_prevIrapPoc           = m_pcPic->getPOC();
1795    m_prevIrapDecodingOrder = m_pcPic->getDecodingOrder();
1796  }
1797  if( m_pcPic->isStsa() )
1798  {
1799    m_prevStsaDecOrder      = m_pcPic->getDecodingOrder();
1800    m_prevStsaTemporalId    = m_pcPic->getTemporalId()   ;
1801  }
1802}
1803
1804
1805Void TDecTop::initFromActiveVps( const TComVPS* vps )
1806{
1807  setViewId   ( vps->getViewId   ( getLayerId() )      );
1808#if NH_3D
1809  setViewIndex( vps->getViewIndex( getLayerId() )      );
1810  setIsDepth  ( vps->getDepthId  ( getLayerId() ) == 1 );
1811#endif
1812
1813  if ( !vps->getVpsExtensionFlag() )
1814  {
1815    m_decodingProcess = CLAUSE_8;
1816    m_isInOwnTargetDecLayerIdList = ( getLayerId() ==  0 );
1817  }
1818  else
1819  {
1820    if ( m_targetOlsIdx == -1 )
1821    {
1822      // Corresponds to specification by "External Means". (Should be set equal to 0, when no external means available. )
1823      m_targetOlsIdx = vps->getVpsNumLayerSetsMinus1();
1824    }
1825
1826    Int targetDecLayerSetIdx = vps->olsIdxToLsIdx( m_targetOlsIdx );
1827
1828    if ( targetDecLayerSetIdx <= vps->getVpsNumLayerSetsMinus1() && vps->getVpsBaseLayerInternalFlag() )
1829    {
1830      m_smallestLayerId = 0;
1831    }
1832    else if ( targetDecLayerSetIdx <= vps->getVpsNumLayerSetsMinus1() && !vps->getVpsBaseLayerInternalFlag() )
1833    {
1834      m_smallestLayerId = 0;
1835    }
1836    else if ( targetDecLayerSetIdx > vps->getVpsNumLayerSetsMinus1() && vps->getNumLayersInIdList( targetDecLayerSetIdx) == 1 )
1837    {
1838
1839      // m_smallestLayerId = 0;
1840      // For now don't do change of layer id here.
1841      m_smallestLayerId = vps->getTargetDecLayerIdList( targetDecLayerSetIdx )[ 0 ];
1842    }
1843    else
1844    {
1845      m_smallestLayerId = vps->getTargetDecLayerIdList( targetDecLayerSetIdx )[ 0 ];
1846    }
1847
1848
1849    // Set profile
1850    Int lsIdx = vps->olsIdxToLsIdx( m_targetOlsIdx );
1851    Int lIdx = -1;
1852    for (Int j = 0; j < vps->getNumLayersInIdList( lsIdx ) ; j++ )
1853    {
1854      if ( vps->getLayerSetLayerIdList( lsIdx, j ) == getLayerId() )
1855      {
1856        lIdx = j;
1857        break;
1858      }
1859    }
1860    m_isInOwnTargetDecLayerIdList = (lIdx != -1);
1861
1862    if ( m_isInOwnTargetDecLayerIdList )
1863    {
1864      Int profileIdc = vps->getPTL( vps->getProfileTierLevelIdx( m_targetOlsIdx, lIdx ) )->getGeneralPTL()->getProfileIdc();
1865      assert( profileIdc == 1 || profileIdc == 6 || profileIdc == 8 );
1866
1867      if (  profileIdc == 6 )
1868      {
1869        m_decodingProcess = ANNEX_G;
1870      }
1871      else if (profileIdc == 7 )
1872      {
1873        m_decodingProcess = ANNEX_H;
1874      }
1875      else if (profileIdc == 8 )
1876      {
1877        m_decodingProcess = ANNEX_I;
1878      }
1879    }
1880  }
1881}
1882
1883
1884Bool TDecTop::getFirstSliceSegementInPicFlag()
1885{
1886  return m_apcSlicePilot->getFirstSliceSegementInPicFlag();
1887}
1888
1889Void TDecTop::x831DecProcForPicOrderCount()
1890{
1891  /////////////////////////////////////////////////////
1892  // 8.3.1 Decoding process for picture order count //
1893  /////////////////////////////////////////////////////
1894
1895  //  Output of this process is PicOrderCntVal, the picture order count of the current picture.
1896  //  Picture order counts are used to identify pictures, for deriving motion parameters in merge mode and
1897  //  motion vector prediction, and for decoder conformance checking (see clause C.5).
1898  //  Each coded picture is associated with a picture order count variable, denoted as PicOrderCntVal.
1899
1900  const TComSlice* curSlice = m_pcPic->getSlice(0);
1901
1902  Int prevPicOrderCntLsb = MIN_INT;
1903  Int prevPicOrderCntMsb = MIN_INT;
1904  if (!(m_pcPic->isIrap() && m_pcPic->getNoRaslOutputFlag() )  )
1905  {
1906    //  When the current picture is not an IRAP picture with NoRaslOutputFlag equal to 1,
1907    //  the variables prevPicOrderCntLsb and prevPicOrderCntMsb are derived as follows:
1908
1909    //  -  Let prevTid0Pic be the previous picture in decoding order that has TemporalId equal to 0 and that is not a RASL picture,
1910    //     a RADL picture or an SLNR picture.
1911
1912    //  -  The variable prevPicOrderCntLsb is set equal to slice_pic_order_cnt_lsb of prevTid0Pic.
1913    prevPicOrderCntLsb = m_prevTid0PicSlicePicOrderCntLsb;
1914
1915    //  -  The variable prevPicOrderCntMsb is set equal to PicOrderCntMsb of prevTid0Pic.
1916    prevPicOrderCntMsb = m_prevTid0PicPicOrderCntMsb;
1917  }
1918
1919  //  The variable PicOrderCntMsb of the current picture is derived as follows:
1920
1921  Int slicePicOrderCntLsb = curSlice->getSlicePicOrderCntLsb();
1922
1923  Int picOrderCntMsb;
1924
1925  if (m_pcPic->isIrap() && m_pcPic->getNoRaslOutputFlag()  )
1926  {
1927    //-  If the current picture is an IRAP picture with NoRaslOutputFlag equal to 1, PicOrderCntMsb is set equal to 0.
1928    picOrderCntMsb = 0;
1929  }
1930  else
1931  {
1932    Int maxPicOrderCntLsb   = curSlice->getSPS()->getMaxPicOrderCntLsb();
1933
1934  //  -  Otherwise, PicOrderCntMsb is derived as follows:
1935
1936    if( ( slicePicOrderCntLsb < prevPicOrderCntLsb )  &&
1937      ( ( prevPicOrderCntLsb - slicePicOrderCntLsb )  >=  ( maxPicOrderCntLsb / 2 ) ) )
1938    {
1939      picOrderCntMsb = prevPicOrderCntMsb + maxPicOrderCntLsb;   // (8 1)
1940    }
1941    else if( (slicePicOrderCntLsb > prevPicOrderCntLsb )  &&
1942    ( ( slicePicOrderCntLsb - prevPicOrderCntLsb ) > ( maxPicOrderCntLsb / 2 ) ) )
1943    {
1944      picOrderCntMsb = prevPicOrderCntMsb - maxPicOrderCntLsb;
1945    }
1946    else
1947    {
1948      picOrderCntMsb = prevPicOrderCntMsb;
1949    }
1950  }
1951
1952  //PicOrderCntVal is derived as follows:
1953  Int picOrderCntVal = picOrderCntMsb + slicePicOrderCntLsb; //   (8 2)
1954
1955  //  NOTE 1 - All IDR pictures will have PicOrderCntVal equal to 0 since slice_pic_order_cnt_lsb is inferred to be 0 for IDR
1956  //  pictures and prevPicOrderCntLsb and prevPicOrderCntMsb are both set equal to 0.
1957
1958  m_pcPic->getSlice(0)->setPOC( picOrderCntVal );
1959
1960  // Update prevTid0Pic
1961  //   Let prevTid0Pic be the previous picture in decoding order that has TemporalId equal to 0 and that is not a RASL picture, a RADL picture or an SLNR picture.
1962  if( curSlice->getTemporalId() == 0  && !m_pcPic->isRasl() && !m_pcPic->isRadl() && !m_pcPic->isSlnr() )
1963  {
1964    m_prevTid0PicSlicePicOrderCntLsb = slicePicOrderCntLsb;
1965    m_prevTid0PicPicOrderCntMsb      = picOrderCntMsb;
1966  }
1967}
1968
1969Void TDecTop::xF831DecProcForPicOrderCount()
1970{
1971  //Output of this process is PicOrderCntVal, the picture order count of the current picture.
1972  //  Picture order counts are used to identify pictures, for deriving motion parameters in merge mode and
1973  //  motion vector prediction and for decoder conformance checking (see clause F.13.5).
1974
1975  //  Each coded picture is associated with a picture order count variable, denoted as PicOrderCntVal.
1976
1977  const TComSlice* slice = m_pcPic->getSlice(0);
1978  const Int nuhLayerId   = m_pcPic->getLayerId();
1979  const TComVPS*   vps   = slice->getVPS();
1980  const TComSPS*   sps   = slice->getSPS();
1981  if ( m_pcPic->getIsFstPicOfAllLayOfPocResetPer() )
1982  {
1983    //  When the current picture is the first picture among all layers of a POC resetting period,
1984    //  the variable PocDecrementedInDPBFlag[ i ] is set equal to 0 for each value of i in the range of 0 to 62, inclusive.
1985    for (Int i = 0; i <= 62; i++)
1986    {
1987      m_pocDecrementedInDpbFlag[ i ] = 0;
1988    }
1989  }
1990
1991  //  The variable pocResettingFlag is derived as follows:
1992  Bool pocResettingFlag;
1993  if (m_pcPic->getIsPocResettingPic() )
1994  {
1995    //-  If the current picture is a POC resetting picture, the following applies:
1996    if( vps->getVpsPocLsbAlignedFlag()  )
1997    {
1998      //  -  If vps_poc_lsb_aligned_flag is equal to 0, pocResettingFlag is set equal to 1.
1999      pocResettingFlag = true;
2000    }
2001    else if ( m_pocDecrementedInDpbFlag[ nuhLayerId ] )
2002    {
2003      //  -  Otherwise, if PocDecrementedInDPBFlag[ nuh_layer_id ] is equal to 1, pocResettingFlag is set equal to 0.
2004      pocResettingFlag = false;
2005    }
2006    else
2007    {
2008      //  -  Otherwise, pocResettingFlag is set equal to 1.
2009      pocResettingFlag = true;
2010    }
2011  }
2012  else
2013  {
2014    //  -  Otherwise, pocResettingFlag is set equal to 0.
2015    pocResettingFlag = false;
2016  }
2017
2018  //  The list affectedLayerList is derived as follows:
2019  std::vector<Int> affectedLayerList;
2020  if (! vps->getVpsPocLsbAlignedFlag() )
2021  {
2022    //-  If vps_poc_lsb_aligned_flag is equal to 0, affectedLayerList consists of the nuh_layer_id of the current picture.
2023    affectedLayerList.push_back( nuhLayerId );
2024  }
2025  else
2026  {
2027    //  -  Otherwise, affectedLayerList consists of the nuh_layer_id of the current picture and the nuh_layer_id values
2028    //     equal to IdPredictedLayer[ currNuhLayerId ][ j ] for all values of j in the range of 0 to NumPredictedLayers[ currNuhLayerId ] - 1,
2029    //     inclusive, where currNuhLayerId is the nuh_layer_id value of the current picture.
2030    affectedLayerList.push_back( nuhLayerId );
2031    Int currNuhLayerId = nuhLayerId;
2032    for (Int j = 0; j <= vps->getNumPredictedLayers( currNuhLayerId )-1; j++ )
2033    {
2034      affectedLayerList.push_back( vps->getIdPredictedLayer(currNuhLayerId, j ) );
2035    }
2036  }
2037
2038  Int picOrderCntMsb;
2039  Int picOrderCntVal;
2040
2041  //  Depending on pocResettingFlag, the following applies:
2042  if ( pocResettingFlag )
2043  {
2044    //-  If pocResettingFlag is equal to 1, the following applies:
2045    if ( m_firstPicInLayerDecodedFlag[ nuhLayerId ] )
2046    {
2047      //-  The variables pocMsbDelta, pocLsbDelta and DeltaPocVal are derived as follows:
2048      Int pocMsbDelta;
2049      Int pocLsbDelta;
2050      Int deltaPocVal;
2051
2052      {
2053        Int pocLsbVal;
2054        Int prevPicOrderCntLsb;
2055        Int prevPicOrderCntMsb;
2056
2057        if( slice->getPocResetIdc() ==  3 )
2058        {
2059          pocLsbVal = slice->getPocLsbVal();
2060        }
2061        else
2062        {
2063          pocLsbVal = slice->getSlicePicOrderCntLsb();
2064        }
2065
2066        if( slice->getPocMsbCycleValPresentFlag() )
2067        {
2068          pocMsbDelta = slice->getPocMsbCycleVal() * sps->getMaxPicOrderCntLsb();   // (F 60)
2069        }
2070        else
2071        {
2072          prevPicOrderCntLsb = m_prevPicOrderCnt & ( sps->getMaxPicOrderCntLsb() - 1 );
2073          prevPicOrderCntMsb = m_prevPicOrderCnt - prevPicOrderCntLsb;
2074
2075          pocMsbDelta = xGetCurrMsb( pocLsbVal, prevPicOrderCntLsb, prevPicOrderCntMsb, sps->getMaxPicOrderCntLsb() );
2076        }
2077
2078        if( slice->getPocResetIdc() == 2 ||  ( slice->getPocResetIdc() == 3  &&  slice->getFullPocResetFlag() ) )
2079        {
2080          pocLsbDelta = pocLsbVal;
2081        }
2082        else
2083        {
2084          pocLsbDelta = 0;
2085        }
2086        deltaPocVal = pocMsbDelta + pocLsbDelta;
2087      }
2088
2089      //-  The PicOrderCntVal of each picture that has nuh_layer_id value nuhLayerId for which PocDecrementedInDPBFlag[ nuhLayerId ] is equal to 0
2090      //   and that is equal to any value in affectedLayerList is decremented by DeltaPocVal.
2091      for (Int i = 0; i < (Int) affectedLayerList.size(); i++ )
2092      {
2093        if ( !m_pocDecrementedInDpbFlag[ affectedLayerList[i] ] )
2094        {
2095          m_dpb->decrementPocsInSubDpb( affectedLayerList[i], deltaPocVal );
2096        }
2097      }
2098
2099      //-  PocDecrementedInDPBFlag[ nuhLayerId ] is set equal to 1 for each value of nuhLayerId included in affectedLayerList.
2100      for (Int i = 0; i < (Int) affectedLayerList.size(); i++ )
2101      {
2102        m_pocDecrementedInDpbFlag[ affectedLayerList[i] ] = true;
2103      }
2104    }
2105
2106    //-  The PicOrderCntVal of the current picture is derived as follows:
2107    if( slice->getPocResetIdc()  ==  1 )
2108    {
2109      picOrderCntVal = slice->getSlicePicOrderCntLsb();
2110    }
2111    else if (slice->getPocResetIdc()  ==  2 )
2112    {
2113      picOrderCntVal = 0;
2114    }
2115    else
2116    {
2117       picOrderCntMsb = xGetCurrMsb( slice->getSlicePicOrderCntLsb(), slice->getFullPocResetFlag() ? 0 : slice->getPocLsbVal(), 0, sps->getMaxPicOrderCntLsb() );
2118       picOrderCntVal = picOrderCntMsb + slice->getSlicePicOrderCntLsb();
2119    }
2120  }
2121  else
2122  {
2123    //-  Otherwise (pocResettingFlag is equal to 0), the following applies:
2124    //-  The PicOrderCntVal of the current picture is derived as follows:
2125
2126    if( slice->getPocMsbCycleValPresentFlag() )
2127    {
2128      picOrderCntMsb = slice->getPocMsbCycleVal() * sps->getMaxPicOrderCntLsb();
2129    }
2130    else if( !m_firstPicInLayerDecodedFlag[ nuhLayerId ]  ||
2131    slice->getNalUnitType()  ==  NAL_UNIT_CODED_SLICE_IDR_N_LP || slice->getNalUnitType() ==  NAL_UNIT_CODED_SLICE_IDR_W_RADL )
2132    {
2133      picOrderCntMsb = 0; //     (F 62)
2134    }
2135    else
2136    {
2137        Int prevPicOrderCntLsb = m_prevPicOrderCnt & ( sps->getMaxPicOrderCntLsb() - 1 );
2138        Int prevPicOrderCntMsb = m_prevPicOrderCnt - prevPicOrderCntLsb;
2139        picOrderCntMsb = xGetCurrMsb( slice->getSlicePicOrderCntLsb(), prevPicOrderCntLsb, prevPicOrderCntMsb, sps->getMaxPicOrderCntLsb() );
2140    }
2141    picOrderCntVal = picOrderCntMsb + slice->getSlicePicOrderCntLsb();
2142  }
2143
2144  m_pcPic->getSlice(0)->setPOC( picOrderCntVal );
2145
2146  for (Int lId = 0; lId < (Int) affectedLayerList.size(); lId++ )
2147  {
2148    //  The value of PrevPicOrderCnt[ lId ] for each of the lId values included in affectedLayerList is derived as follows:
2149
2150    if (!m_pcPic->isRasl() && !m_pcPic->isRadl() && !m_pcPic->isSlnr() && slice->getTemporalId() == 0 && !slice->getDiscardableFlag() )
2151    {
2152      //-  If the current picture is not a RASL picture, a RADL picture or a sub-layer non-reference picture, and the current picture
2153      //   has TemporalId equal to 0 and discardable_flag equal to 0, PrevPicOrderCnt[ lId ] is set equal to PicOrderCntVal.
2154      m_prevPicOrderCnt = picOrderCntVal;
2155    }
2156    else if ( slice->getPocResetIdc() == 3 &&  (
2157      ( !m_firstPicInLayerDecodedFlag[ nuhLayerId ]) ||
2158      ( m_firstPicInLayerDecodedFlag[ nuhLayerId ] && m_pcPic->getIsPocResettingPic() )
2159      ) )
2160    {
2161      //  -  Otherwise, when poc_reset_idc is equal to 3 and one of the following conditions is true, PrevPicOrderCnt[ lId ] is set equal to ( full_poc_reset_flag ? 0 : poc_lsb_val ):
2162      //     -  FirstPicInLayerDecodedFlag[ nuh_layer_id ] is equal to 0.
2163      //     -  FirstPicInLayerDecodedFlag[ nuh_layer_id ] is equal to 1 and the current picture is a POC resetting picture.
2164      m_prevPicOrderCnt = ( slice->getFullPocResetFlag() ? 0 : slice->getPocLsbVal() );
2165    }
2166  }
2167}
2168
2169Int TDecTop::xGetCurrMsb( Int cl, Int pl, Int pm, Int ml )
2170{
2171  Int currMsb;
2172  if ((pl - cl) >= (ml/ 2))
2173  {
2174    currMsb = pm + ml;
2175  }
2176  else if ( (cl - pl) > (ml / 2))
2177  {
2178    currMsb = pm - ml;
2179  }
2180  else
2181  {
2182    currMsb = pm;
2183  }
2184
2185  return currMsb;
2186}
2187
2188
2189
2190Void TDecTop::x832DecProcForRefPicSet(  Bool annexFModifications )
2191{
2192  ///////////////////////////////////////////////////////////////////////////////////////
2193  // 8.3.2 8.3.2 Decoding process for reference picture set
2194  ///////////////////////////////////////////////////////////////////////////////////////
2195
2196  TComSlice* slice = m_pcPic->getSlice( 0 );
2197  const TComSPS* sps = slice->getSPS();
2198  //  This process is invoked once per picture, after decoding of a slice header but prior to the decoding of any coding unit and prior
2199  //  to the decoding process for reference picture list construction for the slice as specified in clause 8.3.3.
2200  //  This process may result in one or more reference pictures in the DPB being marked as "unused for reference" or
2201  //  "used for long-term reference".
2202
2203  // The variable currPicLayerId is set equal to nuh_layer_id of the current picture.
2204  Int currPicLayerId = m_pcPic->getLayerId();
2205  Int picOrderCntVal = m_pcPic->getPOC();
2206
2207  if (m_pcPic->isIrap() && m_pcPic->getNoRaslOutputFlag()  )
2208  {
2209    // When the current picture is an IRAP picture with NoRaslOutputFlag equal to 1,
2210    // all reference pictures with nuh_layer_id equal to currPicLayerId currently in the
2211    // DPB (if any) are marked as "unused for reference".
2212    m_dpb->markSubDpbAsUnusedForReference( currPicLayerId );
2213  }
2214  // Short-term reference pictures are identified by their PicOrderCntVal values. Long-term reference pictures are identified either by
2215  // their PicOrderCntVal values or their slice_pic_order_cnt_lsb values.
2216
2217  // Five lists of picture order count values are constructed to derive the RPS. These five lists are PocStCurrBefore,
2218  // PocStCurrAfter, PocStFoll, PocLtCurr and PocLtFoll, with NumPocStCurrBefore, NumPocStCurrAfter, NumPocStFoll,
2219  // NumPocLtCurr and NumPocLtFoll number of elements, respectively. The five lists and the five variables are derived as follows:
2220
2221  TComDecodedRps* decRps = m_pcPic->getDecodedRps();
2222
2223  std::vector<Int>& pocStCurrBefore = decRps->m_pocStCurrBefore;
2224  std::vector<Int>& pocStCurrAfter  = decRps->m_pocStCurrAfter;
2225  std::vector<Int>& pocStFoll       = decRps->m_pocStFoll;
2226  std::vector<Int>& pocLtCurr       = decRps->m_pocLtCurr;
2227  std::vector<Int>& pocLtFoll       = decRps->m_pocLtFoll;
2228
2229  Int& numPocStCurrBefore = decRps->m_numPocStCurrBefore;
2230  Int& numPocStCurrAfter  = decRps->m_numPocStCurrAfter;
2231  Int& numPocStFoll       = decRps->m_numPocStFoll;
2232  Int& numPocLtCurr       = decRps->m_numPocLtCurr;
2233  Int& numPocLtFoll       = decRps->m_numPocLtFoll;
2234
2235  std::vector<Int> currDeltaPocMsbPresentFlag, follDeltaPocMsbPresentFlag;
2236
2237  if (m_pcPic->isIdr() )
2238  {
2239    // - If the current picture is an IDR picture, PocStCurrBefore, PocStCurrAfter, PocStFoll,
2240    //   PocLtCurr and PocLtFoll are all set to be empty, and NumPocStCurrBefore,
2241    //   NumPocStCurrAfter, NumPocStFoll, NumPocLtCurr and NumPocLtFoll are all set equal to 0.
2242
2243    pocStCurrBefore.clear();
2244    pocStCurrAfter .clear();
2245    pocStFoll      .clear();
2246    pocLtCurr      .clear();
2247    pocLtFoll      .clear();
2248    numPocStCurrBefore = 0;
2249    numPocStCurrAfter  = 0;
2250    numPocStFoll       = 0;
2251    numPocLtCurr       = 0;
2252    numPocLtFoll       = 0;
2253  }
2254  else
2255  {
2256    const TComStRefPicSet* stRps  = slice->getStRps( slice->getCurrRpsIdx() );
2257    // -  Otherwise, the following applies:
2258
2259    Int j = 0;
2260    Int k = 0;
2261    for( Int i = 0; i < stRps->getNumNegativePicsVar() ; i++ )
2262    {
2263      if( stRps->getUsedByCurrPicS0Var( i  ) )
2264      {
2265        pocStCurrBefore.push_back( picOrderCntVal + stRps->getDeltaPocS0Var( i ) ); j++;
2266      }
2267      else
2268      {
2269        pocStFoll      .push_back( picOrderCntVal + stRps->getDeltaPocS0Var( i ) ); k++;
2270      }
2271    }
2272    numPocStCurrBefore = j;
2273
2274    j = 0;
2275    for (Int i = 0; i < stRps->getNumPositivePicsVar(); i++ )
2276    {
2277      if (stRps->getUsedByCurrPicS1Var( i ) )
2278      {
2279        pocStCurrAfter.push_back( picOrderCntVal + stRps->getDeltaPocS1Var( i ) ); j++;
2280      }
2281      else
2282      {
2283        pocStFoll     .push_back( picOrderCntVal + stRps->getDeltaPocS1Var( i ) ); k++;
2284      }
2285    }
2286    numPocStCurrAfter = j;
2287    numPocStFoll = k; //    (8 5)
2288
2289
2290    j = 0;
2291    k = 0;
2292    for( Int i = 0; i < slice->getNumLongTermSps( ) + slice->getNumLongTermPics(); i++ )
2293    {
2294      Int pocLt = slice->getPocLsbLtVar( i );
2295      if( slice->getDeltaPocMsbPresentFlag( i ) )
2296      {
2297        pocLt  +=  picOrderCntVal - slice->getDeltaPocMsbCycleLtVar( i ) * sps->getMaxPicOrderCntLsb() -
2298          ( picOrderCntVal & ( sps->getMaxPicOrderCntLsb() - 1 ) );
2299      }
2300
2301      if( slice->getUsedByCurrPicLtVar(i))
2302      {
2303        pocLtCurr.push_back( pocLt );
2304        currDeltaPocMsbPresentFlag.push_back( slice->getDeltaPocMsbPresentFlag( i ) ); j++;
2305      }
2306      else
2307      {
2308        pocLtFoll.push_back( pocLt );
2309        follDeltaPocMsbPresentFlag.push_back( slice->getDeltaPocMsbPresentFlag( i ) ); k++;
2310      }
2311    }
2312    numPocLtCurr = j;
2313    numPocLtFoll = k;
2314  }
2315
2316  assert(numPocStCurrAfter  == pocStCurrAfter   .size() );
2317  assert(numPocStCurrBefore == pocStCurrBefore  .size() );
2318  assert(numPocStFoll       == pocStFoll        .size() );
2319  assert(numPocLtCurr       == pocLtCurr        .size() );
2320  assert(numPocLtFoll       == pocLtFoll        .size() );
2321
2322  // where PicOrderCntVal is the picture order count of the current picture as specified in clause 8.3.1.
2323
2324  //   NOTE 2 - A value of CurrRpsIdx in the range of 0 to num_short_term_ref_pic_sets - 1, inclusive,
2325  //   indicates that a candidate short-term RPS from the active SPS for the current layer is being used,
2326  //   where CurrRpsIdx is the index of the candidate short-term RPS into the list of candidate short-term RPSs signalled
2327  //   in the active SPS for the current layer. CurrRpsIdx equal to num_short_term_ref_pic_sets indicates that
2328  //   the short-term RPS of the current picture is directly signalled in the slice header.
2329
2330  for (Int i = 0; i <= numPocLtCurr - 1; i++  )
2331  {
2332      // For each i in the range of 0 to NumPocLtCurr - 1, inclusive, when CurrDeltaPocMsbPresentFlag[ i ] is equal to 1,
2333      // it is a requirement of bitstream conformance that the following conditions apply:
2334    if ( currDeltaPocMsbPresentFlag[i] )
2335    {
2336      // -  There shall be no j in the range of 0 to NumPocStCurrBefore - 1, inclusive,
2337      //    for which PocLtCurr[ i ] is equal to PocStCurrBefore[ j ].
2338      for (Int j = 0; j <= numPocStCurrBefore - 1; j++ )
2339      {
2340        assert(!( pocLtCurr[ i ] == pocStCurrBefore[ j ] ) );
2341      }
2342
2343      // -  There shall be no j in the range of 0 to NumPocStCurrAfter - 1, inclusive,
2344      //    for which PocLtCurr[ i ] is equal to PocStCurrAfter[ j ].
2345      for (Int j = 0; j <= numPocStCurrAfter - 1; j++ )
2346      {
2347        assert(!( pocLtCurr[ i ] == pocStCurrAfter[ j ] ) );
2348      }
2349
2350      // -  There shall be no j in the range of 0 to NumPocStFoll - 1, inclusive,
2351      //    for which PocLtCurr[ i ] is equal to PocStFoll[ j ].
2352      for (Int j = 0; j <= numPocStFoll - 1; j++ )
2353      {
2354        assert(!( pocLtCurr[ i ] == pocStFoll[ j ] ) );
2355      }
2356
2357      // -  There shall be no j in the range of 0 to NumPocLtCurr - 1, inclusive,
2358      //    where j is not equal to i, for which PocLtCurr[ i ] is equal to PocLtCurr[ j ].
2359      for (Int j = 0; j <= numPocLtCurr - 1; j++ )
2360      {
2361        if ( i != j )
2362        {
2363          assert(!( pocLtCurr[ i ] == pocLtCurr[ j ] ) );
2364        }
2365      }
2366    }
2367  }
2368
2369  for (Int i = 0; i <= numPocLtFoll - 1; i++  )
2370  {
2371    // For each i in the range of 0 to NumPocLtFoll - 1, inclusive, when FollDeltaPocMsbPresentFlag[ i ] is equal to 1,
2372    // it is a requirement of bitstream conformance that the following conditions apply:
2373    if ( follDeltaPocMsbPresentFlag[i] )
2374    {
2375      // -  There shall be no j in the range of 0 to NumPocStCurrBefore - 1, inclusive,
2376      //    for which PocLtFoll[ i ] is equal to PocStCurrBefore[ j ].
2377      for (Int j = 0; j <= numPocStCurrBefore - 1; j++ )
2378      {
2379        assert(!( pocLtFoll[ i ] == pocStCurrBefore[ j ] ) );
2380      }
2381
2382      // -  There shall be no j in the range of 0 to NumPocStCurrAfter - 1, inclusive,
2383      //    for which PocLtFoll[ i ] is equal to PocStCurrAfter[ j ].
2384      for (Int j = 0; j <= numPocStCurrAfter - 1; j++ )
2385      {
2386        assert(!( pocLtFoll[ i ] == pocStCurrAfter[ j ] ) );
2387      }
2388
2389      // -  There shall be no j in the range of 0 to NumPocStFoll - 1, inclusive,
2390      //    for which PocLtFoll[ i ] is equal to PocStFoll[ j ].
2391      for (Int j = 0; j <= numPocStFoll - 1; j++ )
2392      {
2393        assert(!( pocLtFoll[ i ] == pocStFoll[ j ] ) );
2394      }
2395
2396      // -  There shall be no j in the range of 0 to NumPocLtFoll - 1, inclusive,
2397      //    where j is not equal to i, for which PocLtFoll[ i ] is equal to PocLtFoll[ j ].
2398      for (Int j = 0; j <= numPocLtFoll - 1; j++ )
2399      {
2400        if (j != i)
2401        {
2402          assert(!( pocLtFoll[ i ] == pocLtFoll[ j ] ) );
2403        }
2404      }
2405
2406      // -  There shall be no j in the range of 0 to NumPocLtCurr - 1, inclusive,
2407      //    for which PocLtFoll[ i ] is equal to PocLtCurr[ j ].
2408      for (Int j = 0; j <= numPocLtCurr - 1; j++ )
2409      {
2410        assert(!( pocLtFoll[ i ] == pocLtCurr[ j ] ) );
2411      }
2412    }
2413  }
2414
2415  Int maxPicOrderCntLsb = sps->getMaxPicOrderCntLsb();
2416  for (Int i = 0; i <= numPocLtCurr - 1; i++  )
2417  {
2418    // For each i in the range of 0 to NumPocLtCurr - 1, inclusive, when CurrDeltaPocMsbPresentFlag[ i ] is equal to 0,
2419    // it is a requirement of bitstream conformance that the following conditions apply:
2420    if ( currDeltaPocMsbPresentFlag[ i ] == 0  )
2421    {
2422      // -  There shall be no j in the range of 0 to NumPocStCurrBefore - 1, inclusive,
2423      //    for which PocLtCurr[ i ] is equal to ( PocStCurrBefore[ j ] & ( MaxPicOrderCntLsb - 1 ) ).
2424      for (Int j = 0; j <= numPocStCurrBefore - 1; j++ )
2425      {
2426        assert(!( pocLtCurr[ i ] == ( pocStCurrBefore[ j ] & ( maxPicOrderCntLsb - 1 ) ) ) );
2427      }
2428
2429      // -  There shall be no j in the range of 0 to NumPocStCurrAfter - 1, inclusive,
2430      //    for which PocLtCurr[ i ] is equal to ( PocStCurrAfter[ j ] & ( MaxPicOrderCntLsb - 1 ) ).
2431      for (Int j = 0; j <= numPocStCurrAfter - 1; j++ )
2432      {
2433        assert(!( pocLtCurr[ i ] == ( pocStCurrAfter[ j ] & ( maxPicOrderCntLsb - 1 ) ) ) );
2434      }
2435
2436      // -  There shall be no j in the range of 0 to NumPocStFoll - 1, inclusive,
2437      //    for which PocLtCurr[ i ] is equal to ( PocStFoll[ j ] & ( MaxPicOrderCntLsb - 1 ) ).
2438      for (Int j = 0; j <= numPocStFoll - 1; j++ )
2439      {
2440        assert(!( pocLtCurr[ i ] == ( pocStFoll[ j ] & ( maxPicOrderCntLsb - 1 ) ) ) );
2441      }
2442
2443      // -  There shall be no j in the range of 0 to NumPocLtCurr - 1, inclusive,
2444      //    where j is not equal to i, for which PocLtCurr[ i ] is equal to ( PocLtCurr[ j ] & ( MaxPicOrderCntLsb - 1 ) ).
2445      for (Int j = 0; j <= numPocLtCurr - 1; j++ )
2446      {
2447        if (j != i)
2448        {
2449          assert(!( pocLtCurr[ i ] == ( pocLtCurr[ j ] & ( maxPicOrderCntLsb - 1 ) ) ) );
2450        }
2451      }
2452    }
2453  }
2454
2455  for (Int i = 0; i <= numPocLtFoll - 1; i++  )
2456  {
2457    // For each i in the range of 0 to NumPocLtFoll - 1, inclusive, when FollDeltaPocMsbPresentFlag[ i ] is equal to 0,
2458    // it is a requirement of bitstream conformance that the following conditions apply:
2459    if ( follDeltaPocMsbPresentFlag[ i ] == 0  )
2460    {
2461      // -  There shall be no j in the range of 0 to NumPocStCurrBefore - 1, inclusive,
2462      //    for which PocLtFoll[ i ] is equal to ( PocStCurrBefore[ j ] & ( MaxPicOrderCntLsb - 1 ) ).
2463      for (Int j = 0; j <= numPocStCurrBefore - 1; j++ )
2464      {
2465        assert(!( pocLtFoll[ i ] == ( pocStCurrBefore[ j ] & ( maxPicOrderCntLsb - 1 ) ) ) );
2466      }
2467
2468      // -  There shall be no j in the range of 0 to NumPocStCurrAfter - 1, inclusive,
2469      //    for which PocLtFoll[ i ] is equal to ( PocStCurrAfter[ j ] & ( MaxPicOrderCntLsb - 1 ) ).
2470      for (Int j = 0; j <= numPocStCurrAfter - 1; j++ )
2471      {
2472        assert(!( pocLtFoll[ i ] == ( pocStCurrAfter[ j ] & ( maxPicOrderCntLsb - 1 ) ) ) );
2473      }
2474
2475      // -  There shall be no j in the range of 0 to NumPocStFoll - 1, inclusive,
2476      //    for which PocLtFoll[ i ] is equal to ( PocStFoll[ j ] & ( MaxPicOrderCntLsb - 1 ) ).
2477      for (Int j = 0; j <= numPocStFoll - 1; j++ )
2478      {
2479        assert(!( pocLtFoll[ i ] == ( pocStFoll[ j ] & ( maxPicOrderCntLsb - 1 ) ) ) );
2480      }
2481
2482      // -  There shall be no j in the range of 0 to NumPocLtFoll - 1, inclusive,
2483      //    where j is not equal to i, for which PocLtFoll[ i ] is equal to ( PocLtFoll[ j ] & ( MaxPicOrderCntLsb - 1 ) ).
2484      for (Int j = 0; j <= numPocLtFoll - 1; j++ )
2485      {
2486        if (j != i)
2487        {
2488          assert(!( pocLtFoll[ i ] == ( pocLtFoll[ j ] & ( maxPicOrderCntLsb - 1 ) ) ) );
2489        }
2490      }
2491
2492      // -  There shall be no j in the range of 0 to NumPocLtCurr - 1, inclusive,
2493      //    for which PocLtFoll[ i ] is equal to ( PocLtCurr[ j ] & ( MaxPicOrderCntLsb - 1 ) ).
2494      for (Int j = 0; j <= numPocLtCurr - 1; j++ )
2495      {
2496        assert(!( pocLtFoll[ i ] == ( pocLtCurr[ j ] & ( maxPicOrderCntLsb - 1 ) ) ) );
2497      }
2498    }
2499  }
2500
2501  if ( !annexFModifications )
2502  {
2503    // The variable NumPicTotalCurr is derived as specified in clause 7.4.7.2.
2504
2505    // It is a requirement of bitstream conformance that the following applies to the value of NumPicTotalCurr:
2506    if ( m_pcPic->isBla() || m_pcPic->isCra() )
2507    {
2508      // -  If the current picture is a BLA or CRA picture, the value of NumPicTotalCurr shall be equal to 0.
2509      assert( slice->getNumPicTotalCurr() == 0 );
2510    }
2511    else
2512    {
2513      // -  Otherwise,
2514      if ( slice->isInterP() || slice->isInterB() )
2515      {
2516        // when the current picture contains a P or B slice, the value of NumPicTotalCurr shall not be equal to 0.
2517        assert( slice->getNumPicTotalCurr() != 0 );
2518      }
2519    }
2520  }
2521
2522  // The RPS of the current picture consists of five RPS lists; RefPicSetStCurrBefore, RefPicSetStCurrAfter, RefPicSetStFoll,
2523  // RefPicSetLtCurr and RefPicSetLtFoll. RefPicSetStCurrBefore, RefPicSetStCurrAfter and RefPicSetStFoll are collectively
2524  // referred to as the short-term RPS. RefPicSetLtCurr and RefPicSetLtFoll are collectively referred to as the long-term RPS.
2525
2526  std::vector<TComPic*>& refPicSetStCurrBefore = decRps->m_refPicSetStCurrBefore;
2527  std::vector<TComPic*>& refPicSetStCurrAfter  = decRps->m_refPicSetStCurrAfter ;
2528  std::vector<TComPic*>& refPicSetStFoll       = decRps->m_refPicSetStFoll      ;
2529  std::vector<TComPic*>& refPicSetLtCurr       = decRps->m_refPicSetLtCurr      ;
2530  std::vector<TComPic*>& refPicSetLtFoll       = decRps->m_refPicSetLtFoll      ;
2531
2532  std::vector<TComPic*>** refPicSetsCurr       = decRps->m_refPicSetsCurr       ;
2533  std::vector<TComPic*>** refPicSetsLt         = decRps->m_refPicSetsLt         ;
2534  std::vector<TComPic*>** refPicSetsAll        = decRps->m_refPicSetsAll        ;
2535  //   NOTE 3 - RefPicSetStCurrBefore, RefPicSetStCurrAfter and RefPicSetLtCurr contain all reference pictures that may be
2536  //   used for inter prediction of the current picture and one or more pictures that follow the current picture in decoding order.
2537  //   RefPicSetStFoll and RefPicSetLtFoll consist of all reference pictures that are not used for inter prediction of the current
2538  //   picture but may be used in inter prediction for one or more pictures that follow the current picture in decoding order.
2539
2540  // The derivation process for the RPS and picture marking are performed according to the following ordered steps:
2541  // 1.  The following applies:
2542
2543  TComSubDpb* dpb = m_dpb->getSubDpb( getLayerId(), false );
2544  assert( refPicSetLtCurr.empty() );
2545  for( Int i = 0; i < numPocLtCurr; i++ )
2546  {
2547    if( !currDeltaPocMsbPresentFlag[ i ] )
2548    {
2549      refPicSetLtCurr.push_back( dpb->getPicFromLsb( pocLtCurr[ i ], maxPicOrderCntLsb ) );
2550    }
2551    else
2552    {
2553      refPicSetLtCurr.push_back(dpb->getPic( pocLtCurr[ i ] ));
2554    }
2555  }
2556
2557  assert( refPicSetLtFoll.empty() );
2558  for( Int i = 0; i < numPocLtFoll; i++ )
2559  {
2560   if( !follDeltaPocMsbPresentFlag[ i ] )
2561   {
2562     refPicSetLtFoll.push_back(dpb->getPicFromLsb(pocLtFoll[ i ], maxPicOrderCntLsb ));
2563   }
2564   else
2565   {
2566     refPicSetLtFoll.push_back(dpb->getPic( pocLtFoll[ i ] ));
2567   }
2568  }
2569
2570  // 2.  All reference pictures that are included in RefPicSetLtCurr or RefPicSetLtFoll and have nuh_layer_id equal
2571  //     to currPicLayerId are marked as "used for long-term reference".
2572  for (Int i = 0; i < numPocLtCurr; i++)
2573  {
2574    if ( refPicSetLtCurr[i] != NULL )
2575    {
2576      refPicSetLtCurr[i]->markAsUsedForLongTermReference();
2577    }
2578  }
2579
2580  for (Int i = 0; i < numPocLtFoll; i++)
2581  {
2582    if ( refPicSetLtFoll[i] != NULL )
2583    {
2584      refPicSetLtFoll[i]->markAsUsedForLongTermReference();
2585    }
2586  }
2587
2588  // 3.  The following applies:
2589  assert( refPicSetStCurrBefore.empty() );
2590  for( Int i = 0; i < numPocStCurrBefore; i++ )
2591  {
2592    refPicSetStCurrBefore.push_back(dpb->getShortTermRefPic( pocStCurrBefore[ i ] ));
2593  }
2594
2595  assert( refPicSetStCurrAfter.empty() );
2596  for( Int i = 0; i < numPocStCurrAfter; i++ )
2597  {
2598    refPicSetStCurrAfter.push_back(dpb->getShortTermRefPic( pocStCurrAfter[ i ] ));
2599  }
2600
2601  assert( refPicSetStFoll.empty() );
2602  for( Int i = 0; i < numPocStFoll; i++ )
2603  {
2604    refPicSetStFoll.push_back(dpb->getShortTermRefPic( pocStFoll[ i ] ));
2605  }
2606
2607  // 4.  All reference pictures in the DPB that are not included in RefPicSetLtCurr, RefPicSetLtFoll, RefPicSetStCurrBefore,
2608  //     RefPicSetStCurrAfter, or RefPicSetStFoll and have nuh_layer_id equal to currPicLayerId are marked as "unused for reference".
2609  TComSubDpb picsToMark = (*dpb);
2610  for (Int j = 0; j < 5; j++ )
2611  {
2612    picsToMark.removePics( *refPicSetsAll[j] );
2613  }
2614  picsToMark.markAllAsUnusedForReference();
2615
2616  //     NOTE 4 - There may be one or more entries in the RPS lists that are equal to "no reference picture" because
2617  //     the corresponding pictures are not present in the DPB. Entries in RefPicSetStFoll or RefPicSetLtFoll that are equal
2618  //     to "no reference picture" should be ignored. An unintentional picture loss should be inferred for each entry in
2619  //     RefPicSetStCurrBefore, RefPicSetStCurrAfter, or RefPicSetLtCurr that is equal to "no reference picture".
2620
2621  //     NOTE 5 - A picture cannot be included in more than one of the five RPS lists.
2622
2623
2624  // It is a requirement of bitstream conformance that the RPS is restricted as follows:
2625
2626
2627#if NH_MV_FIX_NO_REF_PICS_CHECK
2628  if ( !annexFModifications || m_firstPicInLayerDecodedFlag[ m_pcPic->getLayerId() ] )
2629  {
2630#endif
2631    for (Int j = 0; j < 3; j++ )
2632    {
2633      // -  There shall be no entry in RefPicSetStCurrBefore, RefPicSetStCurrAfter or RefPicSetLtCurr
2634      //    for which one or more of the following are true:
2635
2636      std::vector<TComPic*>* currSet = refPicSetsCurr[j];
2637      for (Int i = 0; i < currSet->size(); i++)
2638      {
2639        TComPic* pic = (*currSet)[i];
2640
2641        // -  The entry is equal to "no reference picture".
2642        assert( ! (pic == NULL ) );
2643
2644        // -  The entry is an SLNR picture and has TemporalId equal to that of the current picture.
2645        assert( !( pic->isSlnr() && pic->getTemporalId() == m_pcPic->getTemporalId() ) );
2646
2647        // -  The entry is a picture that has TemporalId greater than that of the current picture.
2648        assert( !(  pic->getTemporalId() > m_pcPic->getTemporalId() ) );
2649      }
2650    }
2651#if NH_MV_FIX_NO_REF_PICS_CHECK
2652  }
2653#endif
2654
2655  //  -  There shall be no entry in RefPicSetLtCurr or RefPicSetLtFoll for which the
2656  //     difference between the picture order count value of the current picture and the picture order count
2657  //     value of the entry is greater than or equal to 2^24.
2658  for (Int j = 0; j < 2; j++ )
2659  {
2660    std::vector<TComPic*>* ltSet = refPicSetsLt[j];
2661    for (Int i = 0; i < ltSet->size(); i++)
2662    {
2663      TComPic* pic = (*ltSet)[i];
2664      if( pic != NULL )
2665      {
2666        assert(!( abs( m_pcPic->getPOC() - pic->getPOC() ) >= (1 << 24) ));
2667      }
2668    }
2669  }
2670
2671  //   -  When the current picture is a temporal sub-layer access (TSA) picture, there shall be no picture
2672  //      included in the RPS with TemporalId greater than or equal to the TemporalId of the current picture.
2673  if (m_pcPic->isTsa() )
2674  {
2675    for (Int j = 0; j < 5; j++ )
2676    {
2677      std::vector<TComPic*>* aSet = refPicSetsAll[j];
2678      for (Int i = 0; i < aSet->size(); i++)
2679      {
2680        TComPic* pic = (*aSet)[i];
2681        if( pic != NULL )
2682        {
2683          assert( ! (pic->getTemporalId() >= m_pcPic->getTemporalId() ) );
2684        }
2685      }
2686    }
2687  }
2688
2689  //   -  When the current picture is a step-wise temporal sub-layer access (STSA) picture,
2690  //      there shall be no picture included in RefPicSetStCurrBefore, RefPicSetStCurrAfter or RefPicSetLtCurr that has
2691  //      TemporalId equal to that of the current picture.
2692  if (m_pcPic->isStsa() )
2693  {
2694    for (Int j = 0; j < 3; j++ )
2695    {
2696      std::vector<TComPic*>* cSet = refPicSetsCurr[j];
2697      for (Int i = 0; i < cSet->size(); i++)
2698      {
2699        TComPic* pic = (*cSet)[i];
2700        if( pic != NULL )
2701        {
2702          assert( ! (pic->getTemporalId() == m_pcPic->getTemporalId() ) );
2703        }
2704      }
2705    }
2706  }
2707
2708  //   -  When the current picture is a picture that follows, in decoding order, an STSA picture
2709  //      that has TemporalId equal to that of the current picture, there shall be no picture that has
2710  //      TemporalId equal to that of the current picture included in RefPicSetStCurrBefore, RefPicSetStCurrAfter
2711  //      or RefPicSetLtCurr that precedes the STSA picture in decoding order.
2712  if ( m_pcPic->getDecodingOrder() > m_prevStsaDecOrder && m_pcPic->getTemporalId() == m_prevStsaTemporalId  )
2713  {
2714    for (Int j = 0; j < 3; j++ )
2715    {
2716      std::vector<TComPic*>* cSet = refPicSetsCurr[j];
2717      for (Int i = 0; i < cSet->size(); i++)
2718      {
2719        TComPic* pic = (*cSet)[i];
2720        if( pic != NULL )
2721        {
2722          assert( ! (pic->getTemporalId() == m_pcPic->getTemporalId() && pic->getDecodingOrder() < m_prevStsaDecOrder  ) );
2723        }
2724      }
2725    }
2726  }
2727
2728  //   -  When the current picture is a CRA picture, there shall be no picture included in the RPS that
2729  //      precedes, in output order or decoding order, any preceding IRAP picture in decoding order (when present).
2730  if ( m_pcPic->isCra() )
2731  {
2732    for (Int j = 0; j < 5; j++ )
2733    {
2734      std::vector<TComPic*>* aSet = refPicSetsAll[j];
2735      for (Int i = 0; i < aSet->size(); i++)
2736      {
2737        // TBD check whether it sufficient to test only the last IRAP
2738        TComPic* pic = (*aSet)[i];
2739        if( pic != NULL )
2740        {
2741          assert( ! (pic->getPOC()           < m_prevIrapPoc           ) );
2742          assert( ! (pic->getDecodingOrder() < m_prevIrapDecodingOrder ) );
2743        }
2744      }
2745    }
2746  }
2747
2748  Bool isTrailingPicture = ( !m_pcPic->isIrap() ) && ( m_pcPic->getPOC() > m_prevIrapPoc );
2749  //   -  When the current picture is a trailing picture, there shall be no picture in RefPicSetStCurrBefore,
2750  //      RefPicSetStCurrAfter or RefPicSetLtCurr that was generated by the decoding process for generating unavailable
2751  //      reference pictures as specified in clause 8.3.3.
2752  if ( isTrailingPicture )
2753  {
2754    for (Int j = 0; j < 3; j++ )
2755    {
2756      std::vector<TComPic*>* cSet = refPicSetsCurr[j];
2757      for (Int i = 0; i < cSet->size(); i++)
2758      {
2759        TComPic* pic = (*cSet)[i];
2760        if( pic != NULL )
2761        {
2762          assert( ! (pic->getIsGeneratedCl833() ) );
2763        }
2764      }
2765    }
2766  }
2767
2768  //   -  When the current picture is a trailing picture, there shall be no picture in the RPS that precedes the
2769  //      associated IRAP picture in output order or decoding order.
2770  if ( isTrailingPicture )
2771  {
2772    for (Int j = 0; j < 5; j++ )
2773    {
2774      std::vector<TComPic*>* aSet = refPicSetsAll[j];
2775      for (Int i = 0; i < aSet->size(); i++)
2776      {
2777        // TBD check whether it sufficient to test only the last IRAP
2778         TComPic* pic = (*aSet)[i];
2779        if( pic != NULL )
2780        {
2781          assert( ! (pic->getPOC()           < m_prevIrapPoc           ) );
2782          assert( ! (pic->getDecodingOrder() < m_prevIrapDecodingOrder ) );
2783        }
2784      }
2785    }
2786  }
2787
2788  //   -  When the current picture is a RADL picture, there shall be no picture included in RefPicSetStCurrBefore,
2789  //      RefPicSetStCurrAfter or RefPicSetLtCurr that is any of the following:
2790  if ( m_pcPic->isRadl() )
2791  {
2792    for (Int j = 0; j < 3; j++ )
2793    {
2794      std::vector<TComPic*>* cSet = refPicSetsCurr[j];
2795      for (Int i = 0; i < cSet->size(); i++)
2796      {
2797        TComPic* pic = (*cSet)[i];
2798        if( pic != NULL )
2799        {
2800          // -  A RASL picture
2801          assert( ! (pic->isRasl() ) );
2802          // -  A picture that was generated by the decoding process for generating unavailable reference pictures
2803          //    as specified in clause 8.3.3
2804          assert( ! (pic->getIsGeneratedCl833() ) );
2805          // -  A picture that precedes the associated IRAP picture in decoding order
2806          assert( ! (pic->getDecodingOrder() < m_prevIrapDecodingOrder ) );
2807        }
2808      }
2809    }
2810  }
2811
2812
2813  if ( sps->getTemporalIdNestingFlag() )
2814  {
2815    // -  When sps_temporal_id_nesting_flag is equal to 1, the following applies:
2816    //    -  Let tIdA be the value of TemporalId of the current picture picA.
2817    TComPic* picA = m_pcPic;
2818    Int      tIdA = picA->getTemporalId();
2819    //   -  Any picture picB with TemporalId equal to tIdB that is less than or equal to tIdA shall not be included in
2820    //      RefPicSetStCurrBefore, RefPicSetStCurrAfter or RefPicSetLtCurr of picA when there exists a picture picC that
2821    //      has TemporalId less than tIdB, follows picB in decoding order, and precedes picA in decoding order.
2822    for (Int j = 0; j < 3; j++ )
2823    {
2824      std::vector<TComPic*>* cSet = refPicSetsCurr[j];
2825      for (Int i = 0; i < cSet->size(); i++)
2826      {
2827        TComPic* picB = (*cSet)[i];
2828        if( picB != NULL )
2829        {
2830          Int tIdB = picB->getTemporalId();
2831
2832          if (tIdB <= tIdA)
2833          {
2834            for ( TComSubDpb::iterator itP = dpb->begin(); itP != dpb->end(); itP++ )
2835            {
2836              TComPic* picC = (*itP);
2837              assert(! ( picC->getTemporalId() < tIdB && picC->getDecodingOrder() > picB->getDecodingOrder() && picC->getDecodingOrder() < picA->getDecodingOrder()  )  );
2838            }
2839          }
2840        }
2841      }
2842    }
2843  }
2844}
2845
2846
2847Void TDecTop::xF832DecProcForRefPicSet()
2848{
2849  ///////////////////////////////////////////////////////////////////////////////////////
2850  // F.8.3.2 Decoding process for reference picture set
2851  ///////////////////////////////////////////////////////////////////////////////////////
2852
2853  // The specifications in clause 8.3.2 apply with the following changes:
2854  // -  The references to clauses 7.4.7.2, 8.3.1, 8.3.3 and 8.3.4 are replaced with references to
2855  //    clauses F.7.4.7.2, F.8.3.1, F.8.3.3 and F.8.3.4, respectively.
2856
2857  x832DecProcForRefPicSet( true );
2858
2859  // -  The following specifications are added:
2860  if (m_pcPic->isIrap() && m_pcPic->getLayerId() == m_smallestLayerId )
2861  {
2862    // -  When the current picture is an IRAP picture with nuh_layer_id equal to SmallestLayerId,
2863    //    all reference pictures with any value of nuh_layer_id currently in the DPB (if any) are marked
2864    //    as "unused for reference" when at least one of the following conditions is true:
2865
2866    if ( m_pcPic->getNoClrasOutputFlag() || m_pcPic->getActivatesNewVps() )
2867    {
2868      // -  The current picture has NoClrasOutputFlag is equal to 1.
2869      // -  The current picture activates a new VPS.
2870      m_dpb->markAllSubDpbAsUnusedForReference( );
2871    }
2872  }
2873
2874  // -  It is a requirement of bitstream conformance that the RPS is restricted as follows:
2875  // -  When the current picture is a CRA picture, there shall be no picture in RefPicSetStCurrBefore, RefPicSetStCurrAfter
2876  //    or RefPicSetLtCurr.
2877
2878  std::vector<TComPic*>** refPicSetsCurr       = m_pcPic->getDecodedRps()->m_refPicSetsCurr;
2879
2880  if ( m_pcPic->isCra() )
2881  {
2882    for (Int j = 0; j < 3; j++ )
2883    {
2884      std::vector<TComPic*>* cSet = refPicSetsCurr[j];
2885      assert ( cSet->size() == 0 );
2886    }
2887  }
2888
2889  // -  The constraints specified in clause 8.3.2 on the value of NumPicTotalCurr are replaced with the following:
2890  //    -  It is a requirement of bitstream conformance that the following applies to the value of NumPicTotalCurr:
2891  Int numPicTotalCurr = m_pcPic->getSlice(0)->getNumPicTotalCurr();
2892  Int currPicLayerId  = m_pcPic->getLayerId();
2893  const TComVPS* vps  = m_pcPic->getSlice(0)->getVPS();
2894
2895  if ( ( m_pcPic->isBla() || m_pcPic->isCra() ) && (  (currPicLayerId == 0 ) || ( vps->getNumDirectRefLayers( currPicLayerId ) == 0 ) ) )
2896  {
2897    assert( numPicTotalCurr == 0 );
2898    // -  If the current picture is a BLA or CRA picture and either currPicLayerId is equal to 0 or
2899    //     NumDirectRefLayers[ currPicLayerId ] is equal to 0, the value of NumPicTotalCurr shall be equal to 0.
2900  }
2901  else
2902  {
2903    // TBD: check all slices
2904    if ( m_pcPic->getSlice(0)->getSliceType() == P_SLICE  ||  m_pcPic->getSlice(0)->getSliceType() == B_SLICE )
2905    {
2906      // -  Otherwise, when the current picture contains a P or B slice, the value of NumPicTotalCurr shall not be equal to 0.
2907      assert( numPicTotalCurr != 0 );
2908    }
2909  }
2910}
2911
2912
2913Void TDecTop::xG813DecProcForInterLayerRefPicSet()
2914{
2915  ////////////////////////////////////////////////////////////////////
2916  // G.8.1.3 Decoding process for inter-layer reference picture set //
2917  ////////////////////////////////////////////////////////////////////
2918
2919  // Outputs of this process are updated lists of inter-layer reference pictures RefPicSetInterLayer0 and RefPicSetInterLayer1
2920  // and the variables NumActiveRefLayerPics0 and NumActiveRefLayerPics1.
2921
2922  TComDecodedRps* decRps = m_pcPic->getDecodedRps();
2923  TComSlice* slice       = m_pcPic->getSlice( 0 );
2924  const TComVPS* vps     =  slice->getVPS();
2925
2926  Int&                   numActiveRefLayerPics0 = decRps->m_numActiveRefLayerPics0;
2927  Int&                   numActiveRefLayerPics1 = decRps->m_numActiveRefLayerPics1;
2928
2929  std::vector<TComPic*>& refPicSetInterLayer0   = decRps->m_refPicSetInterLayer0;
2930  std::vector<TComPic*>& refPicSetInterLayer1   = decRps->m_refPicSetInterLayer1;
2931
2932  // The variable currLayerId is set equal to nuh_layer_id of the current picture.
2933  Int currLayerId = getLayerId();
2934
2935  // The lists RefPicSetInterLayer0 and RefPicSetInterLayer1 are first emptied, NumActiveRefLayerPics0 and NumActiveRefLayerPics1
2936  // are set equal to 0 and the following applies:
2937
2938  refPicSetInterLayer0.clear();
2939  refPicSetInterLayer1.clear();
2940
2941  numActiveRefLayerPics0 = 0;
2942  numActiveRefLayerPics1 = 0;
2943
2944  Int viewIdCurrLayerId  = vps->getViewId( currLayerId );
2945  Int viewId0            = vps->getViewId( 0   );
2946
2947  for( Int i = 0; i < slice->getNumActiveRefLayerPics(); i++ )
2948  {
2949    Int viewIdRefPicLayerIdi = vps->getViewId( slice->getRefPicLayerId( i ) );
2950
2951    Bool refPicSet0Flag =
2952      ( ( viewIdCurrLayerId <=  viewId0  &&  viewIdCurrLayerId <=  viewIdRefPicLayerIdi )  ||
2953      ( viewIdCurrLayerId >=  viewId0  &&  viewIdCurrLayerId >=  viewIdRefPicLayerIdi ) );
2954
2955    TComPic* picX = m_dpb->getAu(slice->getPOC(), false )->getPic( slice->getRefPicLayerId( i ) );
2956    if ( picX != NULL )
2957    {
2958      // there is a picture picX in the DPB that is in the same access unit as the current picture and has
2959      // nuh_layer_id equal to RefPicLayerId[ i ]
2960
2961      if ( refPicSet0Flag )
2962      {
2963        refPicSetInterLayer0.push_back( picX );
2964        refPicSetInterLayer0[ numActiveRefLayerPics0++ ]->markAsUsedForLongTermReference();
2965      }
2966      else
2967      {
2968        refPicSetInterLayer1.push_back( picX );
2969        refPicSetInterLayer1[ numActiveRefLayerPics1++ ]->markAsUsedForLongTermReference();
2970      }
2971
2972      // There shall be no picture that has discardable_flag equal to 1 in RefPicSetInterLayer0 or RefPicSetInterLayer1.
2973      assert( ! picX->getSlice(0)->getDiscardableFlag() );
2974
2975      // If the current picture is a RADL picture, there shall be no entry in RefPicSetInterLayer0 or RefPicSetInterLayer1
2976      // that is a RASL picture.
2977      if ( m_pcPic->isRadl() )
2978      {
2979        assert( ! picX->isRasl() );
2980      }
2981    }
2982    else
2983    {
2984      if( refPicSet0Flag )
2985      {
2986        refPicSetInterLayer0.push_back( NULL ); // "no reference picture" (G 1)
2987        numActiveRefLayerPics0++;
2988      }
2989      else
2990      {
2991        refPicSetInterLayer1.push_back( NULL ); // "no reference picture";
2992        numActiveRefLayerPics1++;
2993      }
2994      // There shall be no entry equal to "no reference picture" in RefPicSetInterLayer0 or RefPicSetInterLayer1.
2995      assert( false );
2996    }
2997  }
2998}
2999
3000
3001Void TDecTop::x8331GenDecProcForGenUnavilRefPics()
3002{
3003  ///////////////////////////////////////////////////////////////////////////////////////
3004  // 8.3.3.1  General decoding process for generating unavailable reference pictures ////
3005  ///////////////////////////////////////////////////////////////////////////////////////
3006
3007  // This process is invoked once per coded picture when the current picture is a
3008  // BLA picture or is a CRA picture with NoRaslOutputFlag equal to 1.
3009
3010  assert( m_pcPic->isBla() || (m_pcPic->isCra() && m_pcPic->getNoRaslOutputFlag() ) );
3011  TComDecodedRps* decRps = m_pcPic->getDecodedRps();
3012
3013  std::vector<TComPic*>& refPicSetStFoll      = decRps->m_refPicSetStFoll;
3014  std::vector<TComPic*>& refPicSetLtFoll      = decRps->m_refPicSetLtFoll;
3015
3016  const std::vector<Int>& pocStFoll             = decRps->m_pocStFoll;
3017  const std::vector<Int>& pocLtFoll             = decRps->m_pocLtFoll;
3018
3019  const Int               numPocStFoll          = decRps->m_numPocStFoll;
3020  const Int               numPocLtFoll          = decRps->m_numPocLtFoll;
3021
3022  // When this process is invoked, the following applies:
3023  for ( Int i = 0 ; i <= numPocStFoll - 1; i++ )
3024  {
3025    if ( refPicSetStFoll[ i ] == NULL )
3026    {
3027      //-  For each RefPicSetStFoll[ i ], with i in the range of 0 to NumPocStFoll - 1, inclusive, that is equal
3028      //   to "no reference picture", a picture is generated as specified in clause 8.3.3.2, and the following applies:
3029      TComPic* genPic = x8332GenOfOneUnavailPic( true );
3030
3031      // -  The value of PicOrderCntVal for the generated picture is set equal to PocStFoll[ i ].
3032      genPic->getSlice(0)->setPOC( pocStFoll[ i ] );
3033
3034      //-  The value of PicOutputFlag for the generated picture is set equal to 0.
3035      genPic->setPicOutputFlag( false );
3036
3037      // -  The generated picture is marked as "used for short-term reference".
3038      genPic->markAsUsedForShortTermReference();
3039
3040      // -  RefPicSetStFoll[ i ] is set to be the generated reference picture.
3041      refPicSetStFoll[ i ] = genPic;
3042
3043      // -  The value of nuh_layer_id for the generated picture is set equal to nuh_layer_id of the current picture.
3044      genPic->setLayerId( m_pcPic-> getLayerId() );
3045
3046      // Insert to DPB
3047      m_dpb->addNewPic( genPic );
3048    }
3049  }
3050
3051  for ( Int i = 0 ; i <= numPocLtFoll - 1; i++ )
3052  {
3053    if ( refPicSetLtFoll[ i ] == NULL )
3054    {
3055      //-  For each RefPicSetLtFoll[ i ], with i in the range of 0 to NumPocLtFoll - 1, inclusive, that is equal to
3056      //   "no reference picture", a picture is generated as specified in clause 8.3.3.2, and the following applies:
3057      TComPic* genPic = x8332GenOfOneUnavailPic( true );
3058
3059      //-  The value of PicOrderCntVal for the generated picture is set equal to PocLtFoll[ i ].
3060      genPic->getSlice(0)->setPOC( pocStFoll[ i ] );
3061
3062      //  -  The value of slice_pic_order_cnt_lsb for the generated picture is inferred to be equal to ( PocLtFoll[ i ] & ( MaxPicOrderCntLsb - 1 ) ).
3063      genPic->getSlice(0)->setSlicePicOrderCntLsb( ( pocLtFoll[ i ] & ( m_pcPic->getSlice(0)->getSPS()->getMaxPicOrderCntLsb() - 1 ) ) );
3064
3065      //  -  The value of PicOutputFlag for the generated picture is set equal to 0.
3066      genPic->setPicOutputFlag( false );
3067
3068      //  -  The generated picture is marked as "used for long-term reference".
3069      genPic->markAsUsedForLongTermReference();
3070
3071      //  -  RefPicSetLtFoll[ i ] is set to be the generated reference picture.
3072      refPicSetLtFoll[ i ] = genPic;
3073
3074      //  -  The value of nuh_layer_id for the generated picture is set equal to nuh_layer_id of the current picture.
3075      genPic->setLayerId( m_pcPic-> getLayerId() );
3076
3077      // Insert to DPB
3078      m_dpb->addNewPic( genPic );
3079    }
3080  }
3081}
3082
3083
3084TComPic* TDecTop::x8332GenOfOneUnavailPic( Bool calledFromCl8331 )
3085{
3086  ///////////////////////////////////////////////////////////////////////////////////////
3087  // 8.3.3.2 Generation of one unavailable picture
3088  ///////////////////////////////////////////////////////////////////////////////////////
3089
3090  TComPic* genPic = new TComPic;
3091  genPic->create( *m_pcPic->getSlice(0)->getSPS(), *m_pcPic->getSlice(0)->getPPS(), true );
3092  genPic->setIsGenerated( true );
3093  genPic->setIsGeneratedCl833( calledFromCl8331 );
3094  return genPic;
3095}
3096
3097
3098Void TDecTop::xF817DecProcForGenUnavRefPicForPicsFrstInDecOrderInLay()
3099{
3100  ///////////////////////////////////////////////////////////////////////////////////////
3101  // F.8.1.7 Decoding process for generating unavailable reference pictures for pictures
3102  //         first in decoding order within a layer
3103  ///////////////////////////////////////////////////////////////////////////////////////
3104
3105  //  This process is invoked for a picture with nuh_layer_id equal to layerId, when FirstPicInLayerDecodedFlag[layerId ] is equal to 0.
3106  assert( !m_firstPicInLayerDecodedFlag[ getLayerId() ] );
3107
3108
3109  TComDecodedRps* decRps = m_pcPic->getDecodedRps();
3110
3111  std::vector<TComPic*>& refPicSetStCurrBefore = decRps->m_refPicSetStCurrBefore;
3112  std::vector<TComPic*>& refPicSetStCurrAfter  = decRps->m_refPicSetStCurrAfter;
3113  std::vector<TComPic*>& refPicSetStFoll       = decRps->m_refPicSetStFoll;
3114  std::vector<TComPic*>& refPicSetLtCurr       = decRps->m_refPicSetLtCurr;
3115  std::vector<TComPic*>& refPicSetLtFoll       = decRps->m_refPicSetLtFoll;
3116
3117
3118  const std::vector<Int>& pocStCurrBefore      = decRps->m_pocStCurrBefore;
3119  const std::vector<Int>& pocStCurrAfter       = decRps->m_pocStCurrAfter;
3120  const std::vector<Int>& pocStFoll            = decRps->m_pocStFoll;
3121  const std::vector<Int>& pocLtCurr            = decRps->m_pocLtCurr;
3122  const std::vector<Int>& pocLtFoll            = decRps->m_pocLtFoll;
3123
3124  const Int numPocStCurrBefore                 = decRps->m_numPocStCurrBefore;
3125  const Int numPocStCurrAfter                  = decRps->m_numPocStCurrAfter;
3126  const Int numPocStFoll                       = decRps->m_numPocStFoll;
3127  const Int numPocLtCurr                       = decRps->m_numPocLtCurr;
3128  const Int numPocLtFoll                       = decRps->m_numPocLtFoll;
3129
3130  Int nuhLayerId = m_pcPic-> getLayerId();
3131  for ( Int i = 0 ; i <= numPocStCurrBefore - 1; i++ )
3132  {
3133    if ( refPicSetStCurrBefore[ i ] == NULL )
3134    {
3135      //-  For each RefPicSetStCurrBefore[ i ], with i in the range of 0 to NumPocStCurrBefore - 1, inclusive, that is
3136      //  equal to "no reference picture", a picture is generated as specified in clause 8.3.3.2 and the following applies:
3137      TComPic* genPic = x8332GenOfOneUnavailPic( false );
3138
3139      //-  The value of PicOrderCntVal for the generated picture is set equal to PocStCurrBefore[ i ].
3140      genPic->getSlice(0)->setPOC( pocStCurrBefore[ i ] );
3141
3142      //  -  The value of PicOutputFlag for the generated picture is set equal to 0.
3143      genPic->setPicOutputFlag( false );
3144
3145      //  -  The generated picture is marked as "used for short-term reference".
3146      genPic->markAsUsedForShortTermReference();
3147
3148      //  -  RefPicSetStCurrBefore[ i ] is set to be the generated reference picture.
3149      refPicSetStCurrBefore[ i ] = genPic;
3150
3151      //  -  The value of nuh_layer_id for the generated picture is set equal to nuh_layer_id.
3152      genPic->setLayerId( nuhLayerId );
3153
3154      // Insert to DPB
3155      m_dpb->addNewPic( genPic );
3156    }
3157  }
3158
3159  for ( Int i = 0 ; i <= numPocStCurrAfter - 1; i++ )
3160  {
3161    if ( refPicSetStCurrAfter[ i ] == NULL )
3162    {
3163      //  -  For each RefPicSetStCurrAfter[ i ], with i in the range of 0 to NumPocStCurrAfter - 1, inclusive, that is equal
3164      //     to "no reference picture", a picture is generated as specified in clause 8.3.3.2 and the following applies:
3165      TComPic* genPic = x8332GenOfOneUnavailPic( false );
3166
3167      //  -  The value of PicOrderCntVal for the generated picture is set equal to PocStCurrAfter[ i ].
3168      genPic->getSlice(0)->setPOC( pocStCurrAfter[ i ] );
3169
3170      //  -  The value of PicOutputFlag for the generated picture is set equal to 0.
3171      genPic->setPicOutputFlag( false );
3172
3173      //  -  The generated picture is marked as "used for short-term reference".
3174      genPic->markAsUsedForShortTermReference();
3175
3176      //  -  RefPicSetStCurrAfter[ i ] is set to be the generated reference picture.
3177      refPicSetStCurrAfter[ i ] = genPic;
3178
3179      //  -  The value of nuh_layer_id for the generated picture is set equal to nuh_layer_id.
3180      genPic->setLayerId( nuhLayerId );
3181
3182      // Insert to DPB
3183      m_dpb->addNewPic( genPic );
3184
3185    }
3186  }
3187
3188  for ( Int i = 0 ; i <= numPocStFoll - 1; i++ )
3189  {
3190    if ( refPicSetStFoll[ i ] == NULL )
3191    {
3192      //  -  For each RefPicSetStFoll[ i ], with i in the range of 0 to NumPocStFoll - 1, inclusive, that is equal to "no
3193      //     reference picture", a picture is generated as specified in clause 8.3.3.2 and the following applies:
3194      TComPic* genPic = x8332GenOfOneUnavailPic( false );
3195
3196      //  -  The value of PicOrderCntVal for the generated picture is set equal to PocStFoll[ i ].
3197      genPic->getSlice(0)->setPOC( pocStFoll[ i ] );
3198
3199      //  -  The value of PicOutputFlag for the generated picture is set equal to 0.
3200      genPic->setPicOutputFlag( false );
3201
3202      //  -  The generated picture is marked as "used for short-term reference".
3203      genPic->markAsUsedForShortTermReference();
3204
3205      //  -  RefPicSetStFoll[ i ] is set to be the generated reference picture.
3206      refPicSetStFoll[ i ] = genPic;
3207
3208      //  -  The value of nuh_layer_id for the generated picture is set equal to nuh_layer_id.
3209      genPic->setLayerId( nuhLayerId );
3210
3211      // Insert to DPB
3212      m_dpb->addNewPic( genPic );
3213    }
3214  }
3215
3216  Int maxPicOrderCntLsb = m_pcPic->getSlice(0)->getSPS()->getMaxPicOrderCntLsb();
3217  for ( Int i = 0 ; i <= numPocLtCurr - 1; i++ )
3218  {
3219    if ( refPicSetLtCurr[ i ] == NULL )
3220    {
3221      //  -  For each RefPicSetLtCurr[ i ], with i in the range of 0 to NumPocLtCurr - 1, inclusive, that is equal to "no
3222      //     reference picture", a picture is generated as specified in clause 8.3.3.2 and the following applies:
3223      TComPic* genPic = x8332GenOfOneUnavailPic( false );
3224
3225      //  -  The value of PicOrderCntVal for the generated picture is set equal to PocLtCurr[ i ].
3226      genPic->getSlice(0)->setPOC( pocLtCurr[ i ] );
3227
3228      //  -  The value of slice_pic_order_cnt_lsb for the generated picture is inferred to be equal to ( PocLtCurr[ i ] & (
3229      //     MaxPicOrderCntLsb - 1 ) ).
3230      genPic->getSlice(0)->setSlicePicOrderCntLsb( ( pocLtCurr[ i ] & ( maxPicOrderCntLsb - 1 ) ) );
3231
3232      //  -  The value of PicOutputFlag for the generated picture is set equal to 0.
3233      genPic->setPicOutputFlag( false );
3234
3235      //  -  The generated picture is marked as "used for long-term reference".
3236      genPic->markAsUsedForLongTermReference();
3237
3238      //  -  RefPicSetLtCurr[ i ] is set to be the generated reference picture.
3239      refPicSetLtCurr[ i ] = genPic;
3240
3241      //  -  The value of nuh_layer_id for the generated picture is set equal to nuh_layer_id.
3242      genPic->setLayerId( nuhLayerId );
3243
3244      // Insert to DPB
3245      m_dpb->addNewPic( genPic );
3246    }
3247  }
3248
3249  for ( Int i = 0 ; i <= numPocLtFoll - 1; i++ )
3250  {
3251    if ( refPicSetLtFoll[ i ] == NULL )
3252    {
3253      //  -  For each RefPicSetLtFoll[ i ], with i in the range of 0 to NumPocLtFoll - 1, inclusive, that is equal to "no
3254      //     reference picture", a picture is generated as specified in clause 8.3.3.2 and the following applies:
3255      TComPic* genPic = x8332GenOfOneUnavailPic( false );
3256
3257      //  -  The value of PicOrderCntVal for the generated picture is set equal to PocLtFoll[ i ].
3258      genPic->getSlice(0)->setPOC( pocLtFoll[ i ] );
3259
3260      //  -  The value of slice_pic_order_cnt_lsb for the generated picture is inferred to be equal to ( PocLtCurr[ i ] & (
3261      //     MaxPicOrderCntLsb - 1 ) ).
3262      genPic->getSlice(0)->setSlicePicOrderCntLsb( ( pocLtCurr[ i ] & ( maxPicOrderCntLsb - 1 ) ) );
3263
3264      //  -  The value of PicOutputFlag for the generated picture is set equal to 0.
3265      genPic->setPicOutputFlag( false );
3266
3267      //  -  The generated picture is marked as "used for long-term reference".
3268      genPic->markAsUsedForLongTermReference();
3269
3270      //  -  RefPicSetLtFoll[ i ] is set to be the generated reference picture.
3271      refPicSetLtFoll[ i ] = genPic;
3272
3273      //  -  The value of nuh_layer_id for the generated picture is set equal to nuh_layer_id.
3274      genPic->setLayerId( nuhLayerId );
3275
3276      // Insert to DPB
3277      m_dpb->addNewPic( genPic );
3278    }
3279  }
3280}
3281
3282Void TDecTop::xF833DecProcForGenUnavRefPics()
3283{
3284  ///////////////////////////////////////////////////////////////////////////////////////
3285  // F.8.3.3 Decoding process for generating unavailable reference picture
3286  ///////////////////////////////////////////////////////////////////////////////////////
3287
3288  x8331GenDecProcForGenUnavilRefPics();
3289}
3290
3291Void TDecTop::xCheckUnavailableRefPics()
3292{
3293  std::vector<TComPic*>** refPicSetsCurr       = m_pcPic->getDecodedRps()->m_refPicSetsCurr;
3294
3295  Bool hasGeneratedRefPic = false;
3296  for (Int j = 0; j < 3; j++ )
3297  {
3298    std::vector<TComPic*>* cSet = refPicSetsCurr[j];
3299    for (Int i = 0 ; i < cSet->size();  i++ )
3300    {
3301      assert( (*cSet)[i] != NULL );
3302      if ((*cSet)[i]->getIsGenerated() )
3303      {
3304        hasGeneratedRefPic = true;
3305      }
3306    }
3307  }
3308  m_pcPic->setHasGeneratedRefPics( hasGeneratedRefPic );
3309}
3310
3311#endif
3312
3313//! \}
Note: See TracBrowser for help on using the repository browser.