source: 3DVCSoftware/branches/HTM-15.2-dev/source/Lib/TLibDecoder/TDecTop.cpp @ 1373

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

Macro fixes.

  • Property svn:eol-style set to native
File size: 119.1 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license.
5 *
6 * Copyright (c) 2010-2015, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TDecTop.cpp
35    \brief    decoder class
36*/
37#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#if NH_MV_SEI
690    m_seiReader.setLayerId ( newPic->getLayerId      ( ) );
691    m_seiReader.setDecOrder( newPic->getDecodingOrder( ) );
692#endif
693#endif
694
695    xParsePrefixSEImessages();
696
697#if RExt__HIGH_BIT_DEPTH_SUPPORT==0
698    if (sps->getSpsRangeExtension().getExtendedPrecisionProcessingFlag() || sps->getBitDepth(CHANNEL_TYPE_LUMA)>12 || sps->getBitDepth(CHANNEL_TYPE_CHROMA)>12 )
699    {
700      printf("High bit depth support must be enabled at compile-time in order to decode this bitstream\n");
701      assert (0);
702      exit(1);
703    }
704#endif
705
706    // NOTE: globals were set up here originally. You can now use:
707    // g_uiMaxCUDepth = sps->getMaxTotalCUDepth();
708    // g_uiAddCUDepth = sps->getMaxTotalCUDepth() - sps->getLog2DiffMaxMinCodingBlockSize()
709
710    //  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.
711#if !NH_MV
712    xGetNewPicBuffer (*(sps), *(pps), m_pcPic, m_apcSlicePilot->getTLayer());
713
714    m_apcSlicePilot->applyReferencePictureSet(m_cListPic, m_apcSlicePilot->getRPS());
715#else
716    m_pcPic = newPic;
717#endif
718
719    // make the slice-pilot a real slice, and set up the slice-pilot for the next slice
720    assert(m_pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
721    m_apcSlicePilot = m_pcPic->getPicSym()->swapSliceObject(m_apcSlicePilot, m_uiSliceIdx);
722
723    // we now have a real slice:
724    TComSlice *pSlice = m_pcPic->getSlice(m_uiSliceIdx);
725
726    // Update the PPS and SPS pointers with the ones of the picture.
727    pps=pSlice->getPPS();
728    sps=pSlice->getSPS();
729
730#if NH_MV
731    pSlice->setPic( m_pcPic );
732    vps=pSlice->getVPS();
733    // 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.
734    assert( pps->getLayerId() == m_layerId || pps->getLayerId( ) == 0 || vps->getDependencyFlag( m_layerId, pps->getLayerId() ) );
735    // 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.
736    assert( sps->getLayerId() == m_layerId || sps->getLayerId( ) == 0 || vps->getDependencyFlag( m_layerId, sps->getLayerId() ) );
737#endif
738
739#if NH_3D
740    if ( !m_pcCamParsCollector->isInitialized() )
741    {
742      m_pcCamParsCollector->init( vps );
743    }
744#endif
745    // Initialise the various objects for the new set of settings
746    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) );
747    m_cLoopFilter.create( sps->getMaxTotalCUDepth() );
748    m_cPrediction.initTempBuff(sps->getChromaFormatIdc());
749
750
751    Bool isField = false;
752    Bool isTopField = false;
753
754    if(!m_SEIs.empty())
755    {
756      // Check if any new Picture Timing SEI has arrived
757      SEIMessages pictureTimingSEIs = getSeisByType(m_SEIs, SEI::PICTURE_TIMING);
758      if (pictureTimingSEIs.size()>0)
759      {
760        SEIPictureTiming* pictureTiming = (SEIPictureTiming*) *(pictureTimingSEIs.begin());
761        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);
762        isTopField = (pictureTiming->m_picStruct == 1) || (pictureTiming->m_picStruct == 9) || (pictureTiming->m_picStruct == 11);
763      }
764    }
765
766    //Set Field/Frame coding mode
767    m_pcPic->setField(isField);
768    m_pcPic->setTopField(isTopField);
769
770    // transfer any SEI messages that have been received to the picture
771    m_pcPic->setSEIs(m_SEIs);
772    m_SEIs.clear();
773
774    // Recursive structure
775    m_cCuDecoder.create ( sps->getMaxTotalCUDepth(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getChromaFormatIdc() );
776    m_cCuDecoder.init   ( &m_cEntropyDecoder, &m_cTrQuant, &m_cPrediction );
777    m_cTrQuant.init     ( sps->getMaxTrSize() );
778
779    m_cSliceDecoder.create();
780  }
781  else
782  {
783#if NH_MV
784    assert( m_pcPic != NULL );
785    assert( newPic  == NULL );
786#endif
787    // make the slice-pilot a real slice, and set up the slice-pilot for the next slice
788    m_pcPic->allocateNewSlice();
789    assert(m_pcPic->getNumAllocatedSlice() == (m_uiSliceIdx + 1));
790    m_apcSlicePilot = m_pcPic->getPicSym()->swapSliceObject(m_apcSlicePilot, m_uiSliceIdx);
791
792    TComSlice *pSlice = m_pcPic->getSlice(m_uiSliceIdx); // we now have a real slice.
793
794    const TComSPS *sps = pSlice->getSPS();
795    const TComPPS *pps = pSlice->getPPS();
796
797    // check that the current active PPS has not changed...
798    if (m_parameterSetManager.getSPSChangedFlag(sps->getSPSId()) )
799    {
800      printf("Error - a new SPS has been decoded while processing a picture\n");
801      exit(1);
802    }
803    if (m_parameterSetManager.getPPSChangedFlag(pps->getPPSId()) )
804    {
805      printf("Error - a new PPS has been decoded while processing a picture\n");
806      exit(1);
807    }
808
809    xParsePrefixSEImessages();
810
811    // Check if any new SEI has arrived
812    if(!m_SEIs.empty())
813    {
814      // Currently only decoding Unit SEI message occurring between VCL NALUs copied
815      SEIMessages &picSEI = m_pcPic->getSEIs();
816      SEIMessages decodingUnitInfos = extractSeisByType (m_SEIs, SEI::DECODING_UNIT_INFO);
817      picSEI.insert(picSEI.end(), decodingUnitInfos.begin(), decodingUnitInfos.end());
818      deleteSEIs(m_SEIs);
819    }
820  }
821}
822
823Void TDecTop::xParsePrefixSEIsForUnknownVCLNal()
824{
825  while (!m_prefixSEINALUs.empty())
826  {
827    // do nothing?
828    printf("Discarding Prefix SEI associated with unknown VCL NAL unit.\n");
829    delete m_prefixSEINALUs.front();
830  }
831  // TODO: discard following suffix SEIs as well?
832}
833
834
835Void TDecTop::xParsePrefixSEImessages()
836{
837  while (!m_prefixSEINALUs.empty())
838  {
839    InputNALUnit &nalu=*m_prefixSEINALUs.front();
840#if NH_MV
841#if NH_MV_LAYERS_NOT_PRESENT_SEI
842    m_seiReader.parseSEImessage(&(nalu.getBitstream()), m_SEIs, nalu.m_nalUnitType, m_parameterSetManager.getActiveVPS(), m_parameterSetManager.getActiveSPS(getLayerId()), m_pDecodedSEIOutputStream);
843#else
844    m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_SEIs, nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS( getLayerId() ), m_pDecodedSEIOutputStream );
845#endif
846#else
847    m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_SEIs, nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS(), m_pDecodedSEIOutputStream );
848#endif
849    delete m_prefixSEINALUs.front();
850    m_prefixSEINALUs.pop_front();
851  }
852}
853
854#if !NH_MV
855Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
856{
857  m_apcSlicePilot->initSlice(); // the slice pilot is an object to prepare for a new slice
858  // it is not associated with picture, sps or pps structures.
859  if (m_bFirstSliceInPicture)
860  {
861#else
862Void TDecTop::decodeSliceHeader(InputNALUnit &nalu )
863{
864  // Initialize entropy decoder
865  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
866  m_cEntropyDecoder.setBitstream      (&(nalu.getBitstream()));
867
868  assert( nalu.m_nuhLayerId == m_layerId );
869  m_apcSlicePilot->initSlice(); // the slice pilot is an object to prepare for a new slice
870  // it is not associated with picture, sps or pps structures.
871  m_apcSlicePilot->setLayerId( nalu.m_nuhLayerId );
872  m_cEntropyDecoder.decodeFirstSliceSegmentInPicFlag( m_apcSlicePilot );
873  if ( m_apcSlicePilot->getFirstSliceSegementInPicFlag() )
874  {
875#endif
876    m_uiSliceIdx = 0;
877  }
878  else
879  {
880    m_apcSlicePilot->copySliceInfo( m_pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
881  }
882  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
883
884  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
885  Bool nonReferenceFlag = (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_N ||
886    m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N   ||
887    m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N  ||
888    m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N  ||
889    m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N);
890  m_apcSlicePilot->setTemporalLayerNonReferenceFlag(nonReferenceFlag);
891#if !NH_MV
892  m_apcSlicePilot->setReferenced(true); // Putting this as true ensures that picture is referenced the first time it is in an RPS
893#endif
894  m_apcSlicePilot->setTLayerInfo(nalu.m_temporalId);
895#if NH_MV
896  m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManager );
897#else
898#if ENC_DEC_TRACE
899  const UInt64 originalSymbolCount = g_nSymbolCounter;
900#endif
901    m_cEntropyDecoder.decodeSliceHeader (m_apcSlicePilot, &m_parameterSetManager, m_prevTid0POC);
902#endif
903
904#if NH_MV
905}
906#else
907  // set POC for dependent slices in skipped pictures
908  if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped)
909  {
910    m_apcSlicePilot->setPOC(m_skippedPOC);
911  }
912
913  xUpdatePreviousTid0POC(m_apcSlicePilot);
914  m_apcSlicePilot->setAssociatedIRAPPOC(m_pocCRA);
915  m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType);
916
917
918  //For inference of NoOutputOfPriorPicsFlag
919  if (m_apcSlicePilot->getRapPicFlag())
920  {
921      if ((m_apcSlicePilot->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_apcSlicePilot->getNalUnitType() <= NAL_UNIT_CODED_SLICE_IDR_N_LP) ||
922        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_bFirstSliceInSequence) ||
923        (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_apcSlicePilot->getHandleCraAsBlaFlag()))
924      {
925        m_apcSlicePilot->setNoRaslOutputFlag(true);
926      }
927    //the inference for NoOutputPriorPicsFlag
928    if (!m_bFirstSliceInBitstream && m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoRaslOutputFlag())
929    {
930      if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
931      {
932        m_apcSlicePilot->setNoOutputPriorPicsFlag(true);
933      }
934    }
935    else
936    {
937      m_apcSlicePilot->setNoOutputPriorPicsFlag(false);
938    }
939
940    if(m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA)
941    {
942      m_craNoRaslOutputFlag = m_apcSlicePilot->getNoRaslOutputFlag();
943    }
944  }
945  if (m_apcSlicePilot->getRapPicFlag() && m_apcSlicePilot->getNoOutputPriorPicsFlag())
946  {
947    m_lastPOCNoOutputPriorPics = m_apcSlicePilot->getPOC();
948    m_isNoOutputPriorPics = true;
949  }
950  else
951  {
952    m_isNoOutputPriorPics = false;
953  }
954
955  //For inference of PicOutputFlag
956  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R)
957  {
958    if ( m_craNoRaslOutputFlag )
959    {
960      m_apcSlicePilot->setPicOutputFlag(false);
961    }
962  }
963
964  if (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA && m_craNoRaslOutputFlag) //Reset POC MSB when CRA has NoRaslOutputFlag equal to 1
965  {
966    TComPPS *pps = m_parameterSetManager.getPPS(m_apcSlicePilot->getPPSId());
967    assert (pps != 0);
968    TComSPS *sps = m_parameterSetManager.getSPS(pps->getSPSId());
969    assert (sps != 0);
970    Int iMaxPOClsb = 1 << sps->getBitsForPOC();
971    m_apcSlicePilot->setPOC( m_apcSlicePilot->getPOC() & (iMaxPOClsb - 1) );
972    xUpdatePreviousTid0POC(m_apcSlicePilot);
973  }
974
975  // Skip pictures due to random access
976  if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
977  {
978    m_prevSliceSkipped = true;
979    m_skippedPOC = m_apcSlicePilot->getPOC();
980    return false;
981  }
982  // Skip TFD pictures associated with BLA/BLANT pictures
983  if (isSkipPictureForBLA(iPOCLastDisplay))
984  {
985    m_prevSliceSkipped = true;
986    m_skippedPOC = m_apcSlicePilot->getPOC();
987    return false;
988  }
989
990  // clear previous slice skipped flag
991  m_prevSliceSkipped = false;
992
993  //we should only get a different poc for a new picture (with CTU address==0)
994  if (!m_apcSlicePilot->getDependentSliceSegmentFlag() && m_apcSlicePilot->getPOC()!=m_prevPOC && !m_bFirstSliceInSequence && (m_apcSlicePilot->getSliceCurStartCtuTsAddr() != 0))
995  {
996    printf ("Warning, the first slice of a picture might have been lost!\n");
997  }
998
999  // exit when a new picture is found
1000  if (!m_apcSlicePilot->getDependentSliceSegmentFlag() && (m_apcSlicePilot->getSliceCurStartCtuTsAddr() == 0 && !m_bFirstSliceInPicture) )
1001  {
1002    if (m_prevPOC >= m_pocRandomAccess)
1003    {
1004      m_prevPOC = m_apcSlicePilot->getPOC();
1005
1006#if ENC_DEC_TRACE
1007      //rewind the trace counter since we didn't actually decode the slice
1008      g_nSymbolCounter = originalSymbolCount;
1009#endif
1010      return true;
1011    }
1012    m_prevPOC = m_apcSlicePilot->getPOC();
1013  }
1014
1015  //detect lost reference picture and insert copy of earlier frame.
1016  {
1017    Int lostPoc;
1018    while((lostPoc=m_apcSlicePilot->checkThatAllRefPicsAreAvailable(m_cListPic, m_apcSlicePilot->getRPS(), true, m_pocRandomAccess)) > 0)
1019    {
1020      xCreateLostPicture(lostPoc-1);
1021    }
1022  }
1023
1024  if (!m_apcSlicePilot->getDependentSliceSegmentFlag())
1025  {
1026    m_prevPOC = m_apcSlicePilot->getPOC();
1027  }
1028  // actual decoding starts here
1029  xActivateParameterSets();
1030
1031  m_bFirstSliceInSequence = false;
1032  m_bFirstSliceInBitstream  = false;
1033
1034
1035  TComSlice* pcSlice = m_pcPic->getPicSym()->getSlice(m_uiSliceIdx);
1036
1037#endif
1038
1039#if NH_MV
1040Void TDecTop::decodeSliceSegment(InputNALUnit &nalu )
1041{
1042  TComSlice* pcSlice = m_pcPic->getPicSym()->getSlice(m_uiSliceIdx);
1043
1044  if ( m_pcPic->getHasGeneratedRefPics() )
1045  {
1046    if ( pcSlice->getFirstSliceSegementInPicFlag() )
1047    {
1048      std::cout << std:: setfill(' ')
1049        << "Layer "  << std::setw(2) << m_pcPic->getLayerId()
1050        << "   POC " << std::setw(4) << m_pcPic->getPOC()
1051        << " Reference pictures missing. Skipping picture." << std::endl;
1052    }
1053  }
1054  else
1055  {
1056    //Check Multiview Main profile constraint in G.11.1.1
1057    //  When ViewOrderIdx[ i ] derived according to any active VPS is equal to 1
1058    //  for the layer with nuh_layer_id equal to i in subBitstream,
1059    //  inter_view_mv_vert_constraint_flag shall be equal to 1
1060    //  in the sps_multilayer_extension( ) syntax structure in each active SPS for that layer.
1061    if( pcSlice->getSPS()->getPTL()->getGeneralPTL()->getProfileIdc()==Profile::MULTIVIEWMAIN
1062      &&
1063      pcSlice->getVPS()->getViewOrderIdx(pcSlice->getVPS()->getLayerIdInNuh(getLayerId()))==1
1064      )
1065    {
1066      assert( pcSlice->getSPS()->getInterViewMvVertConstraintFlag()==1 );
1067    }
1068
1069    m_pcPic->setLayerId( nalu.m_nuhLayerId );
1070    m_pcPic->setViewId ( getViewId() );
1071#if NH_3D
1072    m_pcPic->setViewIndex( getViewIndex() );
1073    m_pcPic->setIsDepth  ( getIsDepth  () );
1074    pcSlice->setIvPicLists( m_dpb );
1075#endif
1076#endif
1077
1078    // When decoding the slice header, the stored start and end addresses were actually RS addresses, not TS addresses.
1079    // Now, having set up the maps, convert them to the correct form.
1080    pcSlice->setSliceSegmentCurStartCtuTsAddr( m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceSegmentCurStartCtuTsAddr()) );
1081    pcSlice->setSliceSegmentCurEndCtuTsAddr( m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceSegmentCurEndCtuTsAddr()) );
1082    if(!pcSlice->getDependentSliceSegmentFlag())
1083    {
1084      pcSlice->setSliceCurStartCtuTsAddr(m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceCurStartCtuTsAddr()));
1085      pcSlice->setSliceCurEndCtuTsAddr(m_pcPic->getPicSym()->getCtuRsToTsAddrMap(pcSlice->getSliceCurEndCtuTsAddr()));
1086    }
1087
1088    m_pcPic->setTLayer(nalu.m_temporalId);
1089
1090
1091    if (!pcSlice->getDependentSliceSegmentFlag())
1092    {
1093#if !NH_MV
1094      pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_associatedIRAPType, m_cListPic );
1095      // Set reference list
1096      pcSlice->setRefPicList( m_cListPic, true );
1097#else
1098      if (pcSlice->getSliceType() != I_SLICE )
1099      {
1100        if( m_decProcPocAndRps == ANNEX_F )
1101        {
1102          pcSlice->f834decProcForRefPicListConst();
1103        }
1104        else if ( m_decProcPocAndRps == CLAUSE_8 )
1105        {
1106          pcSlice->cl834DecProcForRefPicListConst();
1107        }
1108        else
1109        {
1110          assert( false );
1111        }
1112      }
1113#if NH_3D_NBDV
1114      pcSlice->setDefaultRefView();
1115#endif
1116#if NH_3D_ARP
1117      pcSlice->setPocsInCurrRPSs();
1118      pcSlice->setARPStepNum(m_dpb);
1119#endif
1120#endif
1121
1122      // For generalized B
1123      // note: maybe not existed case (always L0 is copied to L1 if L1 is empty)
1124      if (pcSlice->isInterB() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0)
1125      {
1126        Int iNumRefIdx = pcSlice->getNumRefIdx(REF_PIC_LIST_0);
1127        pcSlice->setNumRefIdx        ( REF_PIC_LIST_1, iNumRefIdx );
1128
1129        for (Int iRefIdx = 0; iRefIdx < iNumRefIdx; iRefIdx++)
1130        {
1131          pcSlice->setRefPic(pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx), REF_PIC_LIST_1, iRefIdx);
1132        }
1133      }
1134      if (!pcSlice->isIntra())
1135      {
1136        Bool bLowDelay = true;
1137        Int  iCurrPOC  = pcSlice->getPOC();
1138        Int iRefIdx = 0;
1139
1140        for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++)
1141        {
1142          if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC )
1143          {
1144            bLowDelay = false;
1145          }
1146        }
1147        if (pcSlice->isInterB())
1148        {
1149          for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++)
1150          {
1151            if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC )
1152            {
1153              bLowDelay = false;
1154            }
1155          }
1156        }
1157
1158        pcSlice->setCheckLDC(bLowDelay);
1159      }
1160
1161      //---------------
1162      pcSlice->setRefPOCList();
1163#if  NH_3D_TMVP
1164      if(pcSlice->getLayerId())
1165      {
1166        pcSlice->generateAlterRefforTMVP();
1167      }
1168#endif
1169    }
1170
1171    m_pcPic->setCurrSliceIdx(m_uiSliceIdx);
1172    if(pcSlice->getSPS()->getScalingListFlag())
1173    {
1174      TComScalingList scalingList;
1175      if(pcSlice->getPPS()->getScalingListPresentFlag())
1176      {
1177        scalingList = pcSlice->getPPS()->getScalingList();
1178      }
1179      else if (pcSlice->getSPS()->getScalingListPresentFlag())
1180      {
1181        scalingList = pcSlice->getSPS()->getScalingList();
1182      }
1183      else
1184      {
1185        scalingList.setDefaultScalingList();
1186      }
1187      m_cTrQuant.setScalingListDec(scalingList);
1188      m_cTrQuant.setUseScalingList(true);
1189    }
1190    else
1191    {
1192      const Int maxLog2TrDynamicRange[MAX_NUM_CHANNEL_TYPE] =
1193      {
1194        pcSlice->getSPS()->getMaxLog2TrDynamicRange(CHANNEL_TYPE_LUMA),
1195        pcSlice->getSPS()->getMaxLog2TrDynamicRange(CHANNEL_TYPE_CHROMA)
1196      };
1197      m_cTrQuant.setFlatScalingList(maxLog2TrDynamicRange, pcSlice->getSPS()->getBitDepths());
1198      m_cTrQuant.setUseScalingList(false);
1199    }
1200
1201#if NH_3D
1202    if ( decProcAnnexI() )
1203    {
1204      pcSlice->checkInCompPredRefLayers();
1205    }
1206#endif
1207
1208    //  Decode a picture
1209    m_cGopDecoder.decompressSlice(&(nalu.getBitstream()), m_pcPic);
1210
1211#if NH_3D
1212    if( m_pcCamParsCollector )
1213    {
1214      m_pcCamParsCollector->setSlice( pcSlice );
1215    }
1216#endif
1217
1218#if !NH_MV
1219    m_bFirstSliceInPicture = false;
1220#else
1221  }
1222#endif
1223  m_uiSliceIdx++;
1224
1225#if !NH_MV
1226  return false;
1227#endif
1228}
1229
1230
1231Void TDecTop::xDecodeVPS(const std::vector<UChar> &naluData)
1232{
1233  TComVPS* vps = new TComVPS();
1234
1235  m_cEntropyDecoder.decodeVPS( vps );
1236  m_parameterSetManager.storeVPS(vps, naluData);
1237}
1238
1239Void TDecTop::xDecodeSPS(const std::vector<UChar> &naluData)
1240{
1241  TComSPS* sps = new TComSPS();
1242#if NH_MV
1243  sps->setLayerId( getLayerId() );
1244#endif
1245#if O0043_BEST_EFFORT_DECODING
1246  sps->setForceDecodeBitDepth(m_forceDecodeBitDepth);
1247#endif
1248#if NH_3D
1249  // GT: Please don't add parsing dependency of SPS from VPS here again!!!
1250#endif
1251  m_cEntropyDecoder.decodeSPS( sps );
1252  m_parameterSetManager.storeSPS(sps, naluData);
1253}
1254
1255Void TDecTop::xDecodePPS(const std::vector<UChar> &naluData)
1256{
1257  TComPPS* pps = new TComPPS();
1258#if NH_MV
1259  pps->setLayerId( getLayerId() );
1260#endif
1261#if NH_3D_DLT
1262  // create mapping from depth layer indexes to layer ids
1263  Int j=0;
1264  for( Int i=0; i<=m_parameterSetManager.getFirstVPS()->getMaxLayersMinus1(); i++ )
1265  {
1266    Int layerId = m_parameterSetManager.getFirstVPS()->getLayerIdInNuh(i);
1267    if( m_parameterSetManager.getFirstVPS()->getDepthId(layerId) )
1268      pps->getDLT()->setDepthIdxToLayerId(j++, layerId);
1269  }
1270#endif
1271  m_cEntropyDecoder.decodePPS( pps );
1272
1273  m_parameterSetManager.storePPS( pps, naluData);
1274}
1275
1276#if NH_MV
1277Bool TDecTop::decodeNonVclNalu(InputNALUnit& nalu )
1278#else
1279Bool TDecTop::decode(InputNALUnit& nalu, Int& iSkipFrame, Int& iPOCLastDisplay)
1280#endif
1281{
1282#if !NH_MV
1283  // ignore all NAL units of layers > 0
1284  if (nalu.m_nuhLayerId > 0)
1285  {
1286    fprintf (stderr, "Warning: found NAL unit with nuh_layer_id equal to %d. Ignoring.\n", nalu.m_nuhLayerId);
1287    return false;
1288  }
1289#endif
1290  // Initialize entropy decoder
1291  m_cEntropyDecoder.setEntropyDecoder (&m_cCavlcDecoder);
1292  m_cEntropyDecoder.setBitstream      (&(nalu.getBitstream()));
1293
1294  switch (nalu.m_nalUnitType)
1295  {
1296    case NAL_UNIT_VPS:
1297      xDecodeVPS(nalu.getBitstream().getFifo());
1298      return false;
1299
1300    case NAL_UNIT_SPS:
1301      xDecodeSPS(nalu.getBitstream().getFifo());
1302      return false;
1303
1304    case NAL_UNIT_PPS:
1305      xDecodePPS(nalu.getBitstream().getFifo());
1306      return false;
1307
1308    case NAL_UNIT_PREFIX_SEI:
1309      // Buffer up prefix SEI messages until SPS of associated VCL is known.
1310      m_prefixSEINALUs.push_back(new InputNALUnit(nalu));
1311      return false;
1312
1313    case NAL_UNIT_SUFFIX_SEI:
1314      if (m_pcPic)
1315      {
1316#if NH_MV
1317#if NH_MV_LAYERS_NOT_PRESENT_SEI
1318      m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_pcPic->getSEIs(), nalu.m_nalUnitType, m_parameterSetManager.getActiveVPS(), m_parameterSetManager.getActiveSPS(getLayerId()), m_pDecodedSEIOutputStream);
1319#else
1320      m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_pcPic->getSEIs(), nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS( getLayerId() ), m_pDecodedSEIOutputStream );
1321#endif
1322#else
1323        m_seiReader.parseSEImessage( &(nalu.getBitstream()), m_pcPic->getSEIs(), nalu.m_nalUnitType, m_parameterSetManager.getActiveSPS(), m_pDecodedSEIOutputStream );
1324#endif
1325      }
1326      else
1327      {
1328        printf ("Note: received suffix SEI but no picture currently active.\n");
1329      }
1330      return false;
1331
1332    case NAL_UNIT_CODED_SLICE_TRAIL_R:
1333    case NAL_UNIT_CODED_SLICE_TRAIL_N:
1334    case NAL_UNIT_CODED_SLICE_TSA_R:
1335    case NAL_UNIT_CODED_SLICE_TSA_N:
1336    case NAL_UNIT_CODED_SLICE_STSA_R:
1337    case NAL_UNIT_CODED_SLICE_STSA_N:
1338    case NAL_UNIT_CODED_SLICE_BLA_W_LP:
1339    case NAL_UNIT_CODED_SLICE_BLA_W_RADL:
1340    case NAL_UNIT_CODED_SLICE_BLA_N_LP:
1341    case NAL_UNIT_CODED_SLICE_IDR_W_RADL:
1342    case NAL_UNIT_CODED_SLICE_IDR_N_LP:
1343    case NAL_UNIT_CODED_SLICE_CRA:
1344    case NAL_UNIT_CODED_SLICE_RADL_N:
1345    case NAL_UNIT_CODED_SLICE_RADL_R:
1346    case NAL_UNIT_CODED_SLICE_RASL_N:
1347    case NAL_UNIT_CODED_SLICE_RASL_R:
1348#if NH_MV
1349      assert( false );
1350      return 1;
1351#else
1352      return xDecodeSlice(nalu, iSkipFrame, iPOCLastDisplay);
1353#endif
1354      break;
1355
1356    case NAL_UNIT_EOS:
1357#if !NH_MV
1358      m_associatedIRAPType = NAL_UNIT_INVALID;
1359      m_pocCRA = 0;
1360      m_pocRandomAccess = MAX_INT;
1361      m_prevPOC = MAX_INT;
1362      m_prevSliceSkipped = false;
1363      m_skippedPOC = 0;
1364#endif
1365      return false;
1366
1367    case NAL_UNIT_ACCESS_UNIT_DELIMITER:
1368      {
1369        AUDReader audReader;
1370        UInt picType;
1371        audReader.parseAccessUnitDelimiter(&(nalu.getBitstream()),picType);
1372        printf ("Note: found NAL_UNIT_ACCESS_UNIT_DELIMITER\n");
1373      return false;
1374      }
1375
1376    case NAL_UNIT_EOB:
1377      return false;
1378
1379    case NAL_UNIT_FILLER_DATA:
1380      {
1381        FDReader fdReader;
1382        UInt size;
1383        fdReader.parseFillerData(&(nalu.getBitstream()),size);
1384        printf ("Note: found NAL_UNIT_FILLER_DATA with %u bytes payload.\n", size);
1385      return false;
1386      }
1387
1388    case NAL_UNIT_RESERVED_VCL_N10:
1389    case NAL_UNIT_RESERVED_VCL_R11:
1390    case NAL_UNIT_RESERVED_VCL_N12:
1391    case NAL_UNIT_RESERVED_VCL_R13:
1392    case NAL_UNIT_RESERVED_VCL_N14:
1393    case NAL_UNIT_RESERVED_VCL_R15:
1394
1395    case NAL_UNIT_RESERVED_IRAP_VCL22:
1396    case NAL_UNIT_RESERVED_IRAP_VCL23:
1397
1398    case NAL_UNIT_RESERVED_VCL24:
1399    case NAL_UNIT_RESERVED_VCL25:
1400    case NAL_UNIT_RESERVED_VCL26:
1401    case NAL_UNIT_RESERVED_VCL27:
1402    case NAL_UNIT_RESERVED_VCL28:
1403    case NAL_UNIT_RESERVED_VCL29:
1404    case NAL_UNIT_RESERVED_VCL30:
1405    case NAL_UNIT_RESERVED_VCL31:
1406      printf ("Note: found reserved VCL NAL unit.\n");
1407      xParsePrefixSEIsForUnknownVCLNal();
1408      return false;
1409
1410    case NAL_UNIT_RESERVED_NVCL41:
1411    case NAL_UNIT_RESERVED_NVCL42:
1412    case NAL_UNIT_RESERVED_NVCL43:
1413    case NAL_UNIT_RESERVED_NVCL44:
1414    case NAL_UNIT_RESERVED_NVCL45:
1415    case NAL_UNIT_RESERVED_NVCL46:
1416    case NAL_UNIT_RESERVED_NVCL47:
1417      printf ("Note: found reserved NAL unit.\n");
1418      return false;
1419    case NAL_UNIT_UNSPECIFIED_48:
1420    case NAL_UNIT_UNSPECIFIED_49:
1421    case NAL_UNIT_UNSPECIFIED_50:
1422    case NAL_UNIT_UNSPECIFIED_51:
1423    case NAL_UNIT_UNSPECIFIED_52:
1424    case NAL_UNIT_UNSPECIFIED_53:
1425    case NAL_UNIT_UNSPECIFIED_54:
1426    case NAL_UNIT_UNSPECIFIED_55:
1427    case NAL_UNIT_UNSPECIFIED_56:
1428    case NAL_UNIT_UNSPECIFIED_57:
1429    case NAL_UNIT_UNSPECIFIED_58:
1430    case NAL_UNIT_UNSPECIFIED_59:
1431    case NAL_UNIT_UNSPECIFIED_60:
1432    case NAL_UNIT_UNSPECIFIED_61:
1433    case NAL_UNIT_UNSPECIFIED_62:
1434    case NAL_UNIT_UNSPECIFIED_63:
1435      printf ("Note: found unspecified NAL unit.\n");
1436      return false;
1437    default:
1438      assert (0);
1439      break;
1440  }
1441
1442  return false;
1443}
1444
1445#if !NH_MV
1446/** Function for checking if picture should be skipped because of association with a previous BLA picture
1447 * \param iPOCLastDisplay POC of last picture displayed
1448 * \returns true if the picture should be skipped
1449 * This function skips all TFD pictures that follow a BLA picture
1450 * in decoding order and precede it in output order.
1451 */
1452Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
1453{
1454  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) &&
1455       m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
1456  {
1457    iPOCLastDisplay++;
1458    return true;
1459  }
1460  return false;
1461}
1462
1463/** Function for checking if picture should be skipped because of random access
1464 * \param iSkipFrame skip frame counter
1465 * \param iPOCLastDisplay POC of last picture displayed
1466 * \returns true if the picture shold be skipped in the random access.
1467 * This function checks the skipping of pictures in the case of -s option random access.
1468 * All pictures prior to the random access point indicated by the counter iSkipFrame are skipped.
1469 * It also checks the type of Nal unit type at the random access point.
1470 * 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.
1471 * If the random access point is IDR all pictures after the random access point are decoded.
1472 * If the random access point is none of the above, a warning is issues, and decoding of pictures with POC
1473 * equal to or greater than the random access point POC is attempted. For non IDR/CRA/BLA random
1474 * access point there is no guarantee that the decoder will not crash.
1475 */
1476Bool TDecTop::isRandomAccessSkipPicture(Int& iSkipFrame,  Int& iPOCLastDisplay )
1477{
1478  if (iSkipFrame)
1479  {
1480    iSkipFrame--;   // decrement the counter
1481    return true;
1482  }
1483  else if (m_pocRandomAccess == MAX_INT) // start of random access point, m_pocRandomAccess has not been set yet.
1484  {
1485    if (   m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA
1486        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1487        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1488        || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL )
1489    {
1490
1491      // set the POC random access since we need to skip the reordered pictures in the case of CRA/CRANT/BLA/BLANT.
1492      m_pocRandomAccess = m_apcSlicePilot->getPOC();
1493    }
1494    else if ( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
1495    {
1496      m_pocRandomAccess = -MAX_INT; // no need to skip the reordered pictures in IDR, they are decodable.
1497    }
1498    else
1499    {
1500      if(!m_warningMessageSkipPicture)
1501      {
1502        printf("\nWarning: this is not a valid random access point and the data is discarded until the first CRA picture");
1503        m_warningMessageSkipPicture = true;
1504      }
1505      return true;
1506    }
1507  }
1508  // skip the reordered pictures, if necessary
1509  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))
1510  {
1511    iPOCLastDisplay++;
1512    return true;
1513  }
1514  // if we reach here, then the picture is not skipped.
1515  return false;
1516}
1517
1518#else
1519
1520Int TDecTop::preDecodePoc( Bool firstPicInLayerDecodedFlag, Bool isFstPicOfAllLayOfPocResetPer, Bool isPocResettingPicture )
1521{
1522  //Output of this process is PicOrderCntVal, the picture order count of the current picture.
1523  //  Picture order counts are used to identify pictures, for deriving motion parameters in merge mode and
1524  //  motion vector prediction and for decoder conformance checking (see clause F.13.5).
1525
1526  //  Each coded picture is associated with a picture order count variable, denoted as PicOrderCntVal.
1527
1528  TComSlice* slice = m_apcSlicePilot;
1529  const Int nuhLayerId   = slice->getLayerId();
1530  const TComVPS*   vps   = slice->getVPS();
1531  const TComSPS*   sps   = slice->getSPS();
1532
1533  Int pocDecrementedInDpbFlag = m_pocDecrementedInDpbFlag[ nuhLayerId ];
1534
1535  if ( isFstPicOfAllLayOfPocResetPer )
1536  {
1537    //  When the current picture is the first picture among all layers of a POC resetting period,
1538    //  the variable PocDecrementedInDPBFlag[ i ] is set equal to 0 for each value of i in the range of 0 to 62, inclusive.
1539    pocDecrementedInDpbFlag = false;
1540  }
1541
1542  //  The variable pocResettingFlag is derived as follows:
1543  Bool pocResettingFlag;
1544  if ( isPocResettingPicture )
1545  {
1546    //-  If the current picture is a POC resetting picture, the following applies:
1547    if( vps->getVpsPocLsbAlignedFlag()  )
1548    {
1549      //  -  If vps_poc_lsb_aligned_flag is equal to 0, pocResettingFlag is set equal to 1.
1550      pocResettingFlag = true;
1551    }
1552    else if ( pocDecrementedInDpbFlag )
1553    {
1554      //  -  Otherwise, if PocDecrementedInDPBFlag[ nuh_layer_id ] is equal to 1, pocResettingFlag is set equal to 0.
1555      pocResettingFlag = false;
1556    }
1557    else
1558    {
1559      //  -  Otherwise, pocResettingFlag is set equal to 1.
1560      pocResettingFlag = true;
1561    }
1562  }
1563  else
1564  {
1565    //  -  Otherwise, pocResettingFlag is set equal to 0.
1566    pocResettingFlag = false;
1567  }
1568
1569  Int picOrderCntMsb;
1570  Int picOrderCntVal;
1571
1572  //  Depending on pocResettingFlag, the following applies:
1573  if ( pocResettingFlag )
1574  {
1575    //-  The PicOrderCntVal of the current picture is derived as follows:
1576    if( slice->getPocResetIdc()  ==  1 )
1577    {
1578      picOrderCntVal = slice->getSlicePicOrderCntLsb();
1579    }
1580    else if (slice->getPocResetIdc()  ==  2 )
1581    {
1582      picOrderCntVal = 0;
1583    }
1584    else
1585    {
1586      picOrderCntMsb = xGetCurrMsb( slice->getSlicePicOrderCntLsb(), slice->getFullPocResetFlag() ? 0 : slice->getPocLsbVal(), 0, sps->getMaxPicOrderCntLsb() );
1587      picOrderCntVal = picOrderCntMsb + slice->getSlicePicOrderCntLsb();
1588    }
1589  }
1590  else
1591  {
1592    //-  Otherwise (pocResettingFlag is equal to 0), the following applies:
1593    //-  The PicOrderCntVal of the current picture is derived as follows:
1594
1595    if( slice->getPocMsbCycleValPresentFlag() )
1596    {
1597      picOrderCntMsb = slice->getPocMsbCycleVal() * sps->getMaxPicOrderCntLsb();
1598    }
1599    else if( !firstPicInLayerDecodedFlag  ||
1600      slice->getNalUnitType()  ==  NAL_UNIT_CODED_SLICE_IDR_N_LP || slice->getNalUnitType() ==  NAL_UNIT_CODED_SLICE_IDR_W_RADL )
1601    {
1602      picOrderCntMsb = 0; //     (F 62)
1603    }
1604    else
1605    {
1606      Int prevPicOrderCntLsb = m_prevPicOrderCnt & ( sps->getMaxPicOrderCntLsb() - 1 );
1607      Int prevPicOrderCntMsb = m_prevPicOrderCnt - prevPicOrderCntLsb;
1608      picOrderCntMsb = xGetCurrMsb( slice->getSlicePicOrderCntLsb(), prevPicOrderCntLsb, prevPicOrderCntMsb, sps->getMaxPicOrderCntLsb() );
1609    }
1610    picOrderCntVal = picOrderCntMsb + slice->getSlicePicOrderCntLsb();
1611  }
1612  return picOrderCntVal;
1613}
1614
1615Void TDecTop::inferPocResetPeriodId()
1616{
1617  // Infer PocResetPeriodId
1618  // When not present, the value of poc_reset_period_id is inferred as follows:
1619
1620  if ( !m_apcSlicePilot->getHasPocResetPeriodIdPresent() )
1621  {
1622    if ( m_lastPresentPocResetIdc[ m_apcSlicePilot->getLayerId() ] != MIN_INT )
1623    {
1624      // - If the previous picture picA that has poc_reset_period_id present in the slice segment header is present in the same layer
1625      //   of the bitstream as the current picture, the value of poc_reset_period_id is inferred to be equal to the value of the
1626      //   poc_reset_period_id of picA.
1627
1628      m_apcSlicePilot->setPocResetPeriodId( m_lastPresentPocResetIdc[ m_apcSlicePilot->getLayerId() ] );
1629    }
1630    else
1631    {
1632      //- Otherwise, the value of poc_reset_period_id is inferred to be equal to 0.
1633      m_apcSlicePilot->setPocResetPeriodId( 0 );
1634    }
1635  }
1636  else
1637  {
1638    m_lastPresentPocResetIdc[ m_apcSlicePilot->getLayerId() ] = m_apcSlicePilot->getPocResetPeriodId();
1639  }
1640}
1641
1642
1643Void TDecTop::decodePocAndRps( )
1644{
1645  assert( m_uiSliceIdx == 0 );
1646  Int nuhLayerId = m_pcPic->getLayerId();
1647  if ( m_decProcPocAndRps == CLAUSE_8 )
1648  {
1649    // 8.1.3 Decoding process for a coded picture with nuh_layer_id equal to 0
1650
1651    // Variables and functions relating to picture order count are derived as
1652    // specified in clause 8.3.1. This needs to be invoked only for the first slice
1653    // segment of a picture.
1654    x831DecProcForPicOrderCount( );
1655
1656    // The decoding process for RPS in clause 8.3.2 is invoked, wherein reference
1657    // pictures may be marked as "unused for reference" or "used for long-term
1658    // reference". This needs to be invoked only for the first slice segment of a
1659    // picture.
1660    x832DecProcForRefPicSet    (  false );
1661  }
1662  else if( m_decProcPocAndRps == ANNEX_F )
1663  {
1664    // F.8.1.3 Common decoding process for a coded picture
1665
1666    if (nuhLayerId == 0 )
1667    {
1668      // F.8.1.4 Decoding process for a coded picture with nuh_layer_id equal to
1669      // --> 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
1670
1671      // Variables and functions relating to picture order count are derived as
1672      // specified in clause 8.3.1. This needs to be invoked only for the first slice
1673      // segment of a picture.
1674      xF831DecProcForPicOrderCount( );
1675
1676      // The decoding process for RPS in clause 8.3.2 is invoked, wherein reference
1677      // pictures may be marked as "unused for reference" or "used for long-term
1678      // reference". This needs to be invoked only for the first slice segment of a
1679      // picture.
1680      xF832DecProcForRefPicSet( );
1681    }
1682    else
1683    {
1684      // F.8.1.5 Decoding process for starting the decoding of a coded picture with
1685      // nuh_layer_id greater than 0
1686
1687      // Variables and functions relating to picture order count are derived in clause F.8.3.1.
1688      // This needs to be invoked only for the first slice segment of a picture. It is a requirement
1689      // of bitstream conformance that PicOrderCntVal of each picture in an access unit shall have the
1690      // same value during and at the end of decoding of the access unit
1691      xF831DecProcForPicOrderCount( );
1692
1693      // The decoding process for RPS in clause F.8.3.2 is invoked, wherein only reference pictures with
1694      // nuh_layer_id equal to that of CurrPic may be marked as "unused for reference" or "used for
1695      // long-term reference" and any picture with a different value of nuh_layer_id is not marked.
1696      // This needs to be invoked only for the first slice segment of a picture.
1697      xF832DecProcForRefPicSet( );
1698    }
1699  }
1700  else
1701  {
1702    assert( false );
1703  }
1704}
1705
1706Void TDecTop::genUnavailableRefPics( )
1707{
1708  assert( m_uiSliceIdx == 0 );
1709  Int nuhLayerId = m_pcPic->getLayerId();
1710  if ( m_decProcPocAndRps == CLAUSE_8 )
1711  {
1712    // 8.1.3 Decoding process for a coded picture with nuh_layer_id equal to 0
1713
1714    if ( m_pcPic->isBla() || ( m_pcPic->isCra() && m_pcPic->getNoRaslOutputFlag() ) )
1715    {
1716      // When the current picture is a BLA picture or is a CRA picture
1717      // with NoRaslOutputFlag equal to 1, the decoding process for generating
1718      // unavailable reference pictures specified in clause 8.3.3 is invoked,
1719      // which needs to be invoked only for the first slice segment of a picture.
1720      x8331GenDecProcForGenUnavilRefPics();
1721    }
1722  }
1723  else if( m_decProcPocAndRps == ANNEX_F )
1724  {
1725    // F.8.1.3 Common decoding process for a coded picture
1726
1727    if (nuhLayerId == 0 )
1728    {
1729      // F.8.1.4 Decoding process for a coded picture with nuh_layer_id equal to
1730      // --> 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
1731
1732      if ( m_pcPic->isBla() || ( m_pcPic->isCra() && m_pcPic->getNoRaslOutputFlag() ) )
1733      {
1734        // When the current picture is a BLA picture or is a CRA picture
1735        // with NoRaslOutputFlag equal to 1, the decoding process for generating
1736        // unavailable reference pictures specified in clause 8.3.3 is invoked,
1737        // which needs to be invoked only for the first slice segment of a picture.
1738        xF833DecProcForGenUnavRefPics();
1739      }
1740#if NH_MV_FIX_INIT_NUM_ACTIVE_REF_LAYER_PICS
1741      TComDecodedRps* decRps = m_pcPic->getDecodedRps();
1742      decRps->m_numActiveRefLayerPics0 = 0;
1743      decRps->m_numActiveRefLayerPics1 = 0;
1744#endif
1745    }
1746    else
1747    {
1748      // F.8.1.5 Decoding process for starting the decoding of a coded picture with
1749      // nuh_layer_id greater than 0
1750
1751      if ( !m_firstPicInLayerDecodedFlag[ nuhLayerId ] )
1752      {
1753        // When FirstPicInLayerDecodedFlag[ nuh_layer_id ] is equal to 0, the decoding process for generating
1754        // unavailable reference pictures for pictures first in decoding order within a layer specified in
1755        // clause F.8.1.7 is invoked, which needs to be invoked only for the first slice segment of a picture.
1756        xF817DecProcForGenUnavRefPicForPicsFrstInDecOrderInLay();
1757      }
1758
1759      if ( m_firstPicInLayerDecodedFlag[ nuhLayerId ] && ( m_pcPic->isIrap() && m_pcPic->getNoRaslOutputFlag() ) )
1760      {
1761        // When FirstPicInLayerDecodedFlag[ nuh_layer_id ] is equal to 1 and the current picture is an IRAP
1762        // picture with NoRaslOutputFlag equal to 1, the decoding process for generating unavailable reference
1763        // pictures specified in clause F.8.3.3 is invoked, which needs to be invoked only for the first slice
1764        // segment of a picture.
1765        xF833DecProcForGenUnavRefPics();
1766      }
1767
1768      if ( decProcAnnexG() )
1769      {
1770        // G.1.2 --> G.1.3
1771        xG813DecProcForInterLayerRefPicSet();
1772      }
1773      else
1774      {
1775#if NH_MV_FIX_INIT_NUM_ACTIVE_REF_LAYER_PICS
1776        TComDecodedRps* decRps = m_pcPic->getDecodedRps(); 
1777        decRps->m_numActiveRefLayerPics0 = 0;
1778        decRps->m_numActiveRefLayerPics1 = 0;     
1779#endif
1780      }
1781    }
1782  }
1783  else
1784  {
1785    assert( false );
1786  }
1787
1788  xCheckUnavailableRefPics();
1789}
1790Void TDecTop::executeLoopFilters( )
1791{
1792  assert( m_pcPic != NULL );
1793  if ( !m_pcPic->getHasGeneratedRefPics() && !m_pcPic->getIsGenerated() )
1794  {
1795    m_cGopDecoder.filterPicture( m_pcPic );
1796  }
1797  m_cCuDecoder.destroy();
1798}
1799
1800Void TDecTop::finalizePic()
1801{
1802  if( m_pcPic->isIrap() )
1803  {
1804    m_prevIrapPoc           = m_pcPic->getPOC();
1805    m_prevIrapDecodingOrder = m_pcPic->getDecodingOrder();
1806  }
1807  if( m_pcPic->isStsa() )
1808  {
1809    m_prevStsaDecOrder      = m_pcPic->getDecodingOrder();
1810    m_prevStsaTemporalId    = m_pcPic->getTemporalId()   ;
1811  }
1812}
1813
1814
1815Void TDecTop::initFromActiveVps( const TComVPS* vps )
1816{
1817  setViewId   ( vps->getViewId   ( getLayerId() )      );
1818#if NH_3D
1819  setViewIndex( vps->getViewIndex( getLayerId() )      );
1820  setIsDepth  ( vps->getDepthId  ( getLayerId() ) == 1 );
1821#endif
1822
1823  if ( !vps->getVpsExtensionFlag() )
1824  {
1825    m_decodingProcess = CLAUSE_8;
1826    m_isInOwnTargetDecLayerIdList = ( getLayerId() ==  0 );
1827  }
1828  else
1829  {
1830    if ( m_targetOlsIdx == -1 )
1831    {
1832      // Corresponds to specification by "External Means". (Should be set equal to 0, when no external means available. )
1833      m_targetOlsIdx = vps->getVpsNumLayerSetsMinus1();
1834    }
1835
1836    Int targetDecLayerSetIdx = vps->olsIdxToLsIdx( m_targetOlsIdx );
1837
1838    if ( targetDecLayerSetIdx <= vps->getVpsNumLayerSetsMinus1() && vps->getVpsBaseLayerInternalFlag() )
1839    {
1840      m_smallestLayerId = 0;
1841    }
1842    else if ( targetDecLayerSetIdx <= vps->getVpsNumLayerSetsMinus1() && !vps->getVpsBaseLayerInternalFlag() )
1843    {
1844      m_smallestLayerId = 0;
1845    }
1846    else if ( targetDecLayerSetIdx > vps->getVpsNumLayerSetsMinus1() && vps->getNumLayersInIdList( targetDecLayerSetIdx) == 1 )
1847    {
1848
1849      // m_smallestLayerId = 0;
1850      // For now don't do change of layer id here.
1851      m_smallestLayerId = vps->getTargetDecLayerIdList( targetDecLayerSetIdx )[ 0 ];
1852    }
1853    else
1854    {
1855      m_smallestLayerId = vps->getTargetDecLayerIdList( targetDecLayerSetIdx )[ 0 ];
1856    }
1857
1858
1859    // Set profile
1860    Int lsIdx = vps->olsIdxToLsIdx( m_targetOlsIdx );
1861    Int lIdx = -1;
1862    for (Int j = 0; j < vps->getNumLayersInIdList( lsIdx ) ; j++ )
1863    {
1864      if ( vps->getLayerSetLayerIdList( lsIdx, j ) == getLayerId() )
1865      {
1866        lIdx = j;
1867        break;
1868      }
1869    }
1870    m_isInOwnTargetDecLayerIdList = (lIdx != -1);
1871
1872    if ( m_isInOwnTargetDecLayerIdList )
1873    {
1874      Int profileIdc = vps->getPTL( vps->getProfileTierLevelIdx( m_targetOlsIdx, lIdx ) )->getGeneralPTL()->getProfileIdc();
1875      assert( profileIdc == 1 || profileIdc == 6 || profileIdc == 8 );
1876
1877      if (  profileIdc == 6 )
1878      {
1879        m_decodingProcess = ANNEX_G;
1880      }
1881      else if (profileIdc == 7 )
1882      {
1883        m_decodingProcess = ANNEX_H;
1884      }
1885      else if (profileIdc == 8 )
1886      {
1887        m_decodingProcess = ANNEX_I;
1888      }
1889    }
1890  }
1891}
1892
1893
1894Bool TDecTop::getFirstSliceSegementInPicFlag()
1895{
1896  return m_apcSlicePilot->getFirstSliceSegementInPicFlag();
1897}
1898
1899Void TDecTop::x831DecProcForPicOrderCount()
1900{
1901  /////////////////////////////////////////////////////
1902  // 8.3.1 Decoding process for picture order count //
1903  /////////////////////////////////////////////////////
1904
1905  //  Output of this process is PicOrderCntVal, the picture order count of the current picture.
1906  //  Picture order counts are used to identify pictures, for deriving motion parameters in merge mode and
1907  //  motion vector prediction, and for decoder conformance checking (see clause C.5).
1908  //  Each coded picture is associated with a picture order count variable, denoted as PicOrderCntVal.
1909
1910  const TComSlice* curSlice = m_pcPic->getSlice(0);
1911
1912  Int prevPicOrderCntLsb = MIN_INT;
1913  Int prevPicOrderCntMsb = MIN_INT;
1914  if (!(m_pcPic->isIrap() && m_pcPic->getNoRaslOutputFlag() )  )
1915  {
1916    //  When the current picture is not an IRAP picture with NoRaslOutputFlag equal to 1,
1917    //  the variables prevPicOrderCntLsb and prevPicOrderCntMsb are derived as follows:
1918
1919    //  -  Let prevTid0Pic be the previous picture in decoding order that has TemporalId equal to 0 and that is not a RASL picture,
1920    //     a RADL picture or an SLNR picture.
1921
1922    //  -  The variable prevPicOrderCntLsb is set equal to slice_pic_order_cnt_lsb of prevTid0Pic.
1923    prevPicOrderCntLsb = m_prevTid0PicSlicePicOrderCntLsb;
1924
1925    //  -  The variable prevPicOrderCntMsb is set equal to PicOrderCntMsb of prevTid0Pic.
1926    prevPicOrderCntMsb = m_prevTid0PicPicOrderCntMsb;
1927  }
1928
1929  //  The variable PicOrderCntMsb of the current picture is derived as follows:
1930
1931  Int slicePicOrderCntLsb = curSlice->getSlicePicOrderCntLsb();
1932
1933  Int picOrderCntMsb;
1934
1935  if (m_pcPic->isIrap() && m_pcPic->getNoRaslOutputFlag()  )
1936  {
1937    //-  If the current picture is an IRAP picture with NoRaslOutputFlag equal to 1, PicOrderCntMsb is set equal to 0.
1938    picOrderCntMsb = 0;
1939  }
1940  else
1941  {
1942    Int maxPicOrderCntLsb   = curSlice->getSPS()->getMaxPicOrderCntLsb();
1943
1944  //  -  Otherwise, PicOrderCntMsb is derived as follows:
1945
1946    if( ( slicePicOrderCntLsb < prevPicOrderCntLsb )  &&
1947      ( ( prevPicOrderCntLsb - slicePicOrderCntLsb )  >=  ( maxPicOrderCntLsb / 2 ) ) )
1948    {
1949      picOrderCntMsb = prevPicOrderCntMsb + maxPicOrderCntLsb;   // (8 1)
1950    }
1951    else if( (slicePicOrderCntLsb > prevPicOrderCntLsb )  &&
1952    ( ( slicePicOrderCntLsb - prevPicOrderCntLsb ) > ( maxPicOrderCntLsb / 2 ) ) )
1953    {
1954      picOrderCntMsb = prevPicOrderCntMsb - maxPicOrderCntLsb;
1955    }
1956    else
1957    {
1958      picOrderCntMsb = prevPicOrderCntMsb;
1959    }
1960  }
1961
1962  //PicOrderCntVal is derived as follows:
1963  Int picOrderCntVal = picOrderCntMsb + slicePicOrderCntLsb; //   (8 2)
1964
1965  //  NOTE 1 - All IDR pictures will have PicOrderCntVal equal to 0 since slice_pic_order_cnt_lsb is inferred to be 0 for IDR
1966  //  pictures and prevPicOrderCntLsb and prevPicOrderCntMsb are both set equal to 0.
1967
1968  m_pcPic->getSlice(0)->setPOC( picOrderCntVal );
1969
1970  // Update prevTid0Pic
1971  //   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.
1972  if( curSlice->getTemporalId() == 0  && !m_pcPic->isRasl() && !m_pcPic->isRadl() && !m_pcPic->isSlnr() )
1973  {
1974    m_prevTid0PicSlicePicOrderCntLsb = slicePicOrderCntLsb;
1975    m_prevTid0PicPicOrderCntMsb      = picOrderCntMsb;
1976  }
1977}
1978
1979Void TDecTop::xF831DecProcForPicOrderCount()
1980{
1981  //Output of this process is PicOrderCntVal, the picture order count of the current picture.
1982  //  Picture order counts are used to identify pictures, for deriving motion parameters in merge mode and
1983  //  motion vector prediction and for decoder conformance checking (see clause F.13.5).
1984
1985  //  Each coded picture is associated with a picture order count variable, denoted as PicOrderCntVal.
1986
1987  const TComSlice* slice = m_pcPic->getSlice(0);
1988  const Int nuhLayerId   = m_pcPic->getLayerId();
1989  const TComVPS*   vps   = slice->getVPS();
1990  const TComSPS*   sps   = slice->getSPS();
1991  if ( m_pcPic->getIsFstPicOfAllLayOfPocResetPer() )
1992  {
1993    //  When the current picture is the first picture among all layers of a POC resetting period,
1994    //  the variable PocDecrementedInDPBFlag[ i ] is set equal to 0 for each value of i in the range of 0 to 62, inclusive.
1995    for (Int i = 0; i <= 62; i++)
1996    {
1997      m_pocDecrementedInDpbFlag[ i ] = 0;
1998    }
1999  }
2000
2001  //  The variable pocResettingFlag is derived as follows:
2002  Bool pocResettingFlag;
2003  if (m_pcPic->getIsPocResettingPic() )
2004  {
2005    //-  If the current picture is a POC resetting picture, the following applies:
2006    if( vps->getVpsPocLsbAlignedFlag()  )
2007    {
2008      //  -  If vps_poc_lsb_aligned_flag is equal to 0, pocResettingFlag is set equal to 1.
2009      pocResettingFlag = true;
2010    }
2011    else if ( m_pocDecrementedInDpbFlag[ nuhLayerId ] )
2012    {
2013      //  -  Otherwise, if PocDecrementedInDPBFlag[ nuh_layer_id ] is equal to 1, pocResettingFlag is set equal to 0.
2014      pocResettingFlag = false;
2015    }
2016    else
2017    {
2018      //  -  Otherwise, pocResettingFlag is set equal to 1.
2019      pocResettingFlag = true;
2020    }
2021  }
2022  else
2023  {
2024    //  -  Otherwise, pocResettingFlag is set equal to 0.
2025    pocResettingFlag = false;
2026  }
2027
2028  //  The list affectedLayerList is derived as follows:
2029  std::vector<Int> affectedLayerList;
2030  if (! vps->getVpsPocLsbAlignedFlag() )
2031  {
2032    //-  If vps_poc_lsb_aligned_flag is equal to 0, affectedLayerList consists of the nuh_layer_id of the current picture.
2033    affectedLayerList.push_back( nuhLayerId );
2034  }
2035  else
2036  {
2037    //  -  Otherwise, affectedLayerList consists of the nuh_layer_id of the current picture and the nuh_layer_id values
2038    //     equal to IdPredictedLayer[ currNuhLayerId ][ j ] for all values of j in the range of 0 to NumPredictedLayers[ currNuhLayerId ] - 1,
2039    //     inclusive, where currNuhLayerId is the nuh_layer_id value of the current picture.
2040    affectedLayerList.push_back( nuhLayerId );
2041    Int currNuhLayerId = nuhLayerId;
2042    for (Int j = 0; j <= vps->getNumPredictedLayers( currNuhLayerId )-1; j++ )
2043    {
2044      affectedLayerList.push_back( vps->getIdPredictedLayer(currNuhLayerId, j ) );
2045    }
2046  }
2047
2048  Int picOrderCntMsb;
2049  Int picOrderCntVal;
2050
2051  //  Depending on pocResettingFlag, the following applies:
2052  if ( pocResettingFlag )
2053  {
2054    //-  If pocResettingFlag is equal to 1, the following applies:
2055    if ( m_firstPicInLayerDecodedFlag[ nuhLayerId ] )
2056    {
2057      //-  The variables pocMsbDelta, pocLsbDelta and DeltaPocVal are derived as follows:
2058      Int pocMsbDelta;
2059      Int pocLsbDelta;
2060      Int deltaPocVal;
2061
2062      {
2063        Int pocLsbVal;
2064        Int prevPicOrderCntLsb;
2065        Int prevPicOrderCntMsb;
2066
2067        if( slice->getPocResetIdc() ==  3 )
2068        {
2069          pocLsbVal = slice->getPocLsbVal();
2070        }
2071        else
2072        {
2073          pocLsbVal = slice->getSlicePicOrderCntLsb();
2074        }
2075
2076        if( slice->getPocMsbCycleValPresentFlag() )
2077        {
2078          pocMsbDelta = slice->getPocMsbCycleVal() * sps->getMaxPicOrderCntLsb();   // (F 60)
2079        }
2080        else
2081        {
2082          prevPicOrderCntLsb = m_prevPicOrderCnt & ( sps->getMaxPicOrderCntLsb() - 1 );
2083          prevPicOrderCntMsb = m_prevPicOrderCnt - prevPicOrderCntLsb;
2084
2085          pocMsbDelta = xGetCurrMsb( pocLsbVal, prevPicOrderCntLsb, prevPicOrderCntMsb, sps->getMaxPicOrderCntLsb() );
2086        }
2087
2088        if( slice->getPocResetIdc() == 2 ||  ( slice->getPocResetIdc() == 3  &&  slice->getFullPocResetFlag() ) )
2089        {
2090          pocLsbDelta = pocLsbVal;
2091        }
2092        else
2093        {
2094          pocLsbDelta = 0;
2095        }
2096        deltaPocVal = pocMsbDelta + pocLsbDelta;
2097      }
2098
2099      //-  The PicOrderCntVal of each picture that has nuh_layer_id value nuhLayerId for which PocDecrementedInDPBFlag[ nuhLayerId ] is equal to 0
2100      //   and that is equal to any value in affectedLayerList is decremented by DeltaPocVal.
2101      for (Int i = 0; i < (Int) affectedLayerList.size(); i++ )
2102      {
2103        if ( !m_pocDecrementedInDpbFlag[ affectedLayerList[i] ] )
2104        {
2105          m_dpb->decrementPocsInSubDpb( affectedLayerList[i], deltaPocVal );
2106        }
2107      }
2108
2109      //-  PocDecrementedInDPBFlag[ nuhLayerId ] is set equal to 1 for each value of nuhLayerId included in affectedLayerList.
2110      for (Int i = 0; i < (Int) affectedLayerList.size(); i++ )
2111      {
2112        m_pocDecrementedInDpbFlag[ affectedLayerList[i] ] = true;
2113      }
2114    }
2115
2116    //-  The PicOrderCntVal of the current picture is derived as follows:
2117    if( slice->getPocResetIdc()  ==  1 )
2118    {
2119      picOrderCntVal = slice->getSlicePicOrderCntLsb();
2120    }
2121    else if (slice->getPocResetIdc()  ==  2 )
2122    {
2123      picOrderCntVal = 0;
2124    }
2125    else
2126    {
2127       picOrderCntMsb = xGetCurrMsb( slice->getSlicePicOrderCntLsb(), slice->getFullPocResetFlag() ? 0 : slice->getPocLsbVal(), 0, sps->getMaxPicOrderCntLsb() );
2128       picOrderCntVal = picOrderCntMsb + slice->getSlicePicOrderCntLsb();
2129    }
2130  }
2131  else
2132  {
2133    //-  Otherwise (pocResettingFlag is equal to 0), the following applies:
2134    //-  The PicOrderCntVal of the current picture is derived as follows:
2135
2136    if( slice->getPocMsbCycleValPresentFlag() )
2137    {
2138      picOrderCntMsb = slice->getPocMsbCycleVal() * sps->getMaxPicOrderCntLsb();
2139    }
2140    else if( !m_firstPicInLayerDecodedFlag[ nuhLayerId ]  ||
2141    slice->getNalUnitType()  ==  NAL_UNIT_CODED_SLICE_IDR_N_LP || slice->getNalUnitType() ==  NAL_UNIT_CODED_SLICE_IDR_W_RADL )
2142    {
2143      picOrderCntMsb = 0; //     (F 62)
2144    }
2145    else
2146    {
2147        Int prevPicOrderCntLsb = m_prevPicOrderCnt & ( sps->getMaxPicOrderCntLsb() - 1 );
2148        Int prevPicOrderCntMsb = m_prevPicOrderCnt - prevPicOrderCntLsb;
2149        picOrderCntMsb = xGetCurrMsb( slice->getSlicePicOrderCntLsb(), prevPicOrderCntLsb, prevPicOrderCntMsb, sps->getMaxPicOrderCntLsb() );
2150    }
2151    picOrderCntVal = picOrderCntMsb + slice->getSlicePicOrderCntLsb();
2152  }
2153
2154  m_pcPic->getSlice(0)->setPOC( picOrderCntVal );
2155
2156  for (Int lId = 0; lId < (Int) affectedLayerList.size(); lId++ )
2157  {
2158    //  The value of PrevPicOrderCnt[ lId ] for each of the lId values included in affectedLayerList is derived as follows:
2159
2160    if (!m_pcPic->isRasl() && !m_pcPic->isRadl() && !m_pcPic->isSlnr() && slice->getTemporalId() == 0 && !slice->getDiscardableFlag() )
2161    {
2162      //-  If the current picture is not a RASL picture, a RADL picture or a sub-layer non-reference picture, and the current picture
2163      //   has TemporalId equal to 0 and discardable_flag equal to 0, PrevPicOrderCnt[ lId ] is set equal to PicOrderCntVal.
2164      m_prevPicOrderCnt = picOrderCntVal;
2165    }
2166    else if ( slice->getPocResetIdc() == 3 &&  (
2167      ( !m_firstPicInLayerDecodedFlag[ nuhLayerId ]) ||
2168      ( m_firstPicInLayerDecodedFlag[ nuhLayerId ] && m_pcPic->getIsPocResettingPic() )
2169      ) )
2170    {
2171      //  -  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 ):
2172      //     -  FirstPicInLayerDecodedFlag[ nuh_layer_id ] is equal to 0.
2173      //     -  FirstPicInLayerDecodedFlag[ nuh_layer_id ] is equal to 1 and the current picture is a POC resetting picture.
2174      m_prevPicOrderCnt = ( slice->getFullPocResetFlag() ? 0 : slice->getPocLsbVal() );
2175    }
2176  }
2177}
2178
2179Int TDecTop::xGetCurrMsb( Int cl, Int pl, Int pm, Int ml )
2180{
2181  Int currMsb;
2182  if ((pl - cl) >= (ml/ 2))
2183  {
2184    currMsb = pm + ml;
2185  }
2186  else if ( (cl - pl) > (ml / 2))
2187  {
2188    currMsb = pm - ml;
2189  }
2190  else
2191  {
2192    currMsb = pm;
2193  }
2194
2195  return currMsb;
2196}
2197
2198
2199
2200Void TDecTop::x832DecProcForRefPicSet(  Bool annexFModifications )
2201{
2202  ///////////////////////////////////////////////////////////////////////////////////////
2203  // 8.3.2 8.3.2 Decoding process for reference picture set
2204  ///////////////////////////////////////////////////////////////////////////////////////
2205
2206  TComSlice* slice = m_pcPic->getSlice( 0 );
2207  const TComSPS* sps = slice->getSPS();
2208  //  This process is invoked once per picture, after decoding of a slice header but prior to the decoding of any coding unit and prior
2209  //  to the decoding process for reference picture list construction for the slice as specified in clause 8.3.3.
2210  //  This process may result in one or more reference pictures in the DPB being marked as "unused for reference" or
2211  //  "used for long-term reference".
2212
2213  // The variable currPicLayerId is set equal to nuh_layer_id of the current picture.
2214  Int currPicLayerId = m_pcPic->getLayerId();
2215  Int picOrderCntVal = m_pcPic->getPOC();
2216
2217  if (m_pcPic->isIrap() && m_pcPic->getNoRaslOutputFlag()  )
2218  {
2219    // When the current picture is an IRAP picture with NoRaslOutputFlag equal to 1,
2220    // all reference pictures with nuh_layer_id equal to currPicLayerId currently in the
2221    // DPB (if any) are marked as "unused for reference".
2222    m_dpb->markSubDpbAsUnusedForReference( currPicLayerId );
2223  }
2224  // Short-term reference pictures are identified by their PicOrderCntVal values. Long-term reference pictures are identified either by
2225  // their PicOrderCntVal values or their slice_pic_order_cnt_lsb values.
2226
2227  // Five lists of picture order count values are constructed to derive the RPS. These five lists are PocStCurrBefore,
2228  // PocStCurrAfter, PocStFoll, PocLtCurr and PocLtFoll, with NumPocStCurrBefore, NumPocStCurrAfter, NumPocStFoll,
2229  // NumPocLtCurr and NumPocLtFoll number of elements, respectively. The five lists and the five variables are derived as follows:
2230
2231  TComDecodedRps* decRps = m_pcPic->getDecodedRps();
2232
2233  std::vector<Int>& pocStCurrBefore = decRps->m_pocStCurrBefore;
2234  std::vector<Int>& pocStCurrAfter  = decRps->m_pocStCurrAfter;
2235  std::vector<Int>& pocStFoll       = decRps->m_pocStFoll;
2236  std::vector<Int>& pocLtCurr       = decRps->m_pocLtCurr;
2237  std::vector<Int>& pocLtFoll       = decRps->m_pocLtFoll;
2238
2239  Int& numPocStCurrBefore = decRps->m_numPocStCurrBefore;
2240  Int& numPocStCurrAfter  = decRps->m_numPocStCurrAfter;
2241  Int& numPocStFoll       = decRps->m_numPocStFoll;
2242  Int& numPocLtCurr       = decRps->m_numPocLtCurr;
2243  Int& numPocLtFoll       = decRps->m_numPocLtFoll;
2244
2245  std::vector<Int> currDeltaPocMsbPresentFlag, follDeltaPocMsbPresentFlag;
2246
2247  if (m_pcPic->isIdr() )
2248  {
2249    // - If the current picture is an IDR picture, PocStCurrBefore, PocStCurrAfter, PocStFoll,
2250    //   PocLtCurr and PocLtFoll are all set to be empty, and NumPocStCurrBefore,
2251    //   NumPocStCurrAfter, NumPocStFoll, NumPocLtCurr and NumPocLtFoll are all set equal to 0.
2252
2253    pocStCurrBefore.clear();
2254    pocStCurrAfter .clear();
2255    pocStFoll      .clear();
2256    pocLtCurr      .clear();
2257    pocLtFoll      .clear();
2258    numPocStCurrBefore = 0;
2259    numPocStCurrAfter  = 0;
2260    numPocStFoll       = 0;
2261    numPocLtCurr       = 0;
2262    numPocLtFoll       = 0;
2263  }
2264  else
2265  {
2266    const TComStRefPicSet* stRps  = slice->getStRps( slice->getCurrRpsIdx() );
2267    // -  Otherwise, the following applies:
2268
2269    Int j = 0;
2270    Int k = 0;
2271    for( Int i = 0; i < stRps->getNumNegativePicsVar() ; i++ )
2272    {
2273      if( stRps->getUsedByCurrPicS0Var( i  ) )
2274      {
2275        pocStCurrBefore.push_back( picOrderCntVal + stRps->getDeltaPocS0Var( i ) ); j++;
2276      }
2277      else
2278      {
2279        pocStFoll      .push_back( picOrderCntVal + stRps->getDeltaPocS0Var( i ) ); k++;
2280      }
2281    }
2282    numPocStCurrBefore = j;
2283
2284    j = 0;
2285    for (Int i = 0; i < stRps->getNumPositivePicsVar(); i++ )
2286    {
2287      if (stRps->getUsedByCurrPicS1Var( i ) )
2288      {
2289        pocStCurrAfter.push_back( picOrderCntVal + stRps->getDeltaPocS1Var( i ) ); j++;
2290      }
2291      else
2292      {
2293        pocStFoll     .push_back( picOrderCntVal + stRps->getDeltaPocS1Var( i ) ); k++;
2294      }
2295    }
2296    numPocStCurrAfter = j;
2297    numPocStFoll = k; //    (8 5)
2298
2299
2300    j = 0;
2301    k = 0;
2302    for( Int i = 0; i < slice->getNumLongTermSps( ) + slice->getNumLongTermPics(); i++ )
2303    {
2304      Int pocLt = slice->getPocLsbLtVar( i );
2305      if( slice->getDeltaPocMsbPresentFlag( i ) )
2306      {
2307        pocLt  +=  picOrderCntVal - slice->getDeltaPocMsbCycleLtVar( i ) * sps->getMaxPicOrderCntLsb() -
2308          ( picOrderCntVal & ( sps->getMaxPicOrderCntLsb() - 1 ) );
2309      }
2310
2311      if( slice->getUsedByCurrPicLtVar(i))
2312      {
2313        pocLtCurr.push_back( pocLt );
2314        currDeltaPocMsbPresentFlag.push_back( slice->getDeltaPocMsbPresentFlag( i ) ); j++;
2315      }
2316      else
2317      {
2318        pocLtFoll.push_back( pocLt );
2319        follDeltaPocMsbPresentFlag.push_back( slice->getDeltaPocMsbPresentFlag( i ) ); k++;
2320      }
2321    }
2322    numPocLtCurr = j;
2323    numPocLtFoll = k;
2324  }
2325
2326  assert(numPocStCurrAfter  == pocStCurrAfter   .size() );
2327  assert(numPocStCurrBefore == pocStCurrBefore  .size() );
2328  assert(numPocStFoll       == pocStFoll        .size() );
2329  assert(numPocLtCurr       == pocLtCurr        .size() );
2330  assert(numPocLtFoll       == pocLtFoll        .size() );
2331
2332  // where PicOrderCntVal is the picture order count of the current picture as specified in clause 8.3.1.
2333
2334  //   NOTE 2 - A value of CurrRpsIdx in the range of 0 to num_short_term_ref_pic_sets - 1, inclusive,
2335  //   indicates that a candidate short-term RPS from the active SPS for the current layer is being used,
2336  //   where CurrRpsIdx is the index of the candidate short-term RPS into the list of candidate short-term RPSs signalled
2337  //   in the active SPS for the current layer. CurrRpsIdx equal to num_short_term_ref_pic_sets indicates that
2338  //   the short-term RPS of the current picture is directly signalled in the slice header.
2339
2340  for (Int i = 0; i <= numPocLtCurr - 1; i++  )
2341  {
2342      // For each i in the range of 0 to NumPocLtCurr - 1, inclusive, when CurrDeltaPocMsbPresentFlag[ i ] is equal to 1,
2343      // it is a requirement of bitstream conformance that the following conditions apply:
2344    if ( currDeltaPocMsbPresentFlag[i] )
2345    {
2346      // -  There shall be no j in the range of 0 to NumPocStCurrBefore - 1, inclusive,
2347      //    for which PocLtCurr[ i ] is equal to PocStCurrBefore[ j ].
2348      for (Int j = 0; j <= numPocStCurrBefore - 1; j++ )
2349      {
2350        assert(!( pocLtCurr[ i ] == pocStCurrBefore[ j ] ) );
2351      }
2352
2353      // -  There shall be no j in the range of 0 to NumPocStCurrAfter - 1, inclusive,
2354      //    for which PocLtCurr[ i ] is equal to PocStCurrAfter[ j ].
2355      for (Int j = 0; j <= numPocStCurrAfter - 1; j++ )
2356      {
2357        assert(!( pocLtCurr[ i ] == pocStCurrAfter[ j ] ) );
2358      }
2359
2360      // -  There shall be no j in the range of 0 to NumPocStFoll - 1, inclusive,
2361      //    for which PocLtCurr[ i ] is equal to PocStFoll[ j ].
2362      for (Int j = 0; j <= numPocStFoll - 1; j++ )
2363      {
2364        assert(!( pocLtCurr[ i ] == pocStFoll[ j ] ) );
2365      }
2366
2367      // -  There shall be no j in the range of 0 to NumPocLtCurr - 1, inclusive,
2368      //    where j is not equal to i, for which PocLtCurr[ i ] is equal to PocLtCurr[ j ].
2369      for (Int j = 0; j <= numPocLtCurr - 1; j++ )
2370      {
2371        if ( i != j )
2372        {
2373          assert(!( pocLtCurr[ i ] == pocLtCurr[ j ] ) );
2374        }
2375      }
2376    }
2377  }
2378
2379  for (Int i = 0; i <= numPocLtFoll - 1; i++  )
2380  {
2381    // For each i in the range of 0 to NumPocLtFoll - 1, inclusive, when FollDeltaPocMsbPresentFlag[ i ] is equal to 1,
2382    // it is a requirement of bitstream conformance that the following conditions apply:
2383    if ( follDeltaPocMsbPresentFlag[i] )
2384    {
2385      // -  There shall be no j in the range of 0 to NumPocStCurrBefore - 1, inclusive,
2386      //    for which PocLtFoll[ i ] is equal to PocStCurrBefore[ j ].
2387      for (Int j = 0; j <= numPocStCurrBefore - 1; j++ )
2388      {
2389        assert(!( pocLtFoll[ i ] == pocStCurrBefore[ j ] ) );
2390      }
2391
2392      // -  There shall be no j in the range of 0 to NumPocStCurrAfter - 1, inclusive,
2393      //    for which PocLtFoll[ i ] is equal to PocStCurrAfter[ j ].
2394      for (Int j = 0; j <= numPocStCurrAfter - 1; j++ )
2395      {
2396        assert(!( pocLtFoll[ i ] == pocStCurrAfter[ j ] ) );
2397      }
2398
2399      // -  There shall be no j in the range of 0 to NumPocStFoll - 1, inclusive,
2400      //    for which PocLtFoll[ i ] is equal to PocStFoll[ j ].
2401      for (Int j = 0; j <= numPocStFoll - 1; j++ )
2402      {
2403        assert(!( pocLtFoll[ i ] == pocStFoll[ j ] ) );
2404      }
2405
2406      // -  There shall be no j in the range of 0 to NumPocLtFoll - 1, inclusive,
2407      //    where j is not equal to i, for which PocLtFoll[ i ] is equal to PocLtFoll[ j ].
2408      for (Int j = 0; j <= numPocLtFoll - 1; j++ )
2409      {
2410        if (j != i)
2411        {
2412          assert(!( pocLtFoll[ i ] == pocLtFoll[ j ] ) );
2413        }
2414      }
2415
2416      // -  There shall be no j in the range of 0 to NumPocLtCurr - 1, inclusive,
2417      //    for which PocLtFoll[ i ] is equal to PocLtCurr[ j ].
2418      for (Int j = 0; j <= numPocLtCurr - 1; j++ )
2419      {
2420        assert(!( pocLtFoll[ i ] == pocLtCurr[ j ] ) );
2421      }
2422    }
2423  }
2424
2425  Int maxPicOrderCntLsb = sps->getMaxPicOrderCntLsb();
2426  for (Int i = 0; i <= numPocLtCurr - 1; i++  )
2427  {
2428    // For each i in the range of 0 to NumPocLtCurr - 1, inclusive, when CurrDeltaPocMsbPresentFlag[ i ] is equal to 0,
2429    // it is a requirement of bitstream conformance that the following conditions apply:
2430    if ( currDeltaPocMsbPresentFlag[ i ] == 0  )
2431    {
2432      // -  There shall be no j in the range of 0 to NumPocStCurrBefore - 1, inclusive,
2433      //    for which PocLtCurr[ i ] is equal to ( PocStCurrBefore[ j ] & ( MaxPicOrderCntLsb - 1 ) ).
2434      for (Int j = 0; j <= numPocStCurrBefore - 1; j++ )
2435      {
2436        assert(!( pocLtCurr[ i ] == ( pocStCurrBefore[ j ] & ( maxPicOrderCntLsb - 1 ) ) ) );
2437      }
2438
2439      // -  There shall be no j in the range of 0 to NumPocStCurrAfter - 1, inclusive,
2440      //    for which PocLtCurr[ i ] is equal to ( PocStCurrAfter[ j ] & ( MaxPicOrderCntLsb - 1 ) ).
2441      for (Int j = 0; j <= numPocStCurrAfter - 1; j++ )
2442      {
2443        assert(!( pocLtCurr[ i ] == ( pocStCurrAfter[ j ] & ( maxPicOrderCntLsb - 1 ) ) ) );
2444      }
2445
2446      // -  There shall be no j in the range of 0 to NumPocStFoll - 1, inclusive,
2447      //    for which PocLtCurr[ i ] is equal to ( PocStFoll[ j ] & ( MaxPicOrderCntLsb - 1 ) ).
2448      for (Int j = 0; j <= numPocStFoll - 1; j++ )
2449      {
2450        assert(!( pocLtCurr[ i ] == ( pocStFoll[ j ] & ( maxPicOrderCntLsb - 1 ) ) ) );
2451      }
2452
2453      // -  There shall be no j in the range of 0 to NumPocLtCurr - 1, inclusive,
2454      //    where j is not equal to i, for which PocLtCurr[ i ] is equal to ( PocLtCurr[ j ] & ( MaxPicOrderCntLsb - 1 ) ).
2455      for (Int j = 0; j <= numPocLtCurr - 1; j++ )
2456      {
2457        if (j != i)
2458        {
2459          assert(!( pocLtCurr[ i ] == ( pocLtCurr[ j ] & ( maxPicOrderCntLsb - 1 ) ) ) );
2460        }
2461      }
2462    }
2463  }
2464
2465  for (Int i = 0; i <= numPocLtFoll - 1; i++  )
2466  {
2467    // For each i in the range of 0 to NumPocLtFoll - 1, inclusive, when FollDeltaPocMsbPresentFlag[ i ] is equal to 0,
2468    // it is a requirement of bitstream conformance that the following conditions apply:
2469    if ( follDeltaPocMsbPresentFlag[ i ] == 0  )
2470    {
2471      // -  There shall be no j in the range of 0 to NumPocStCurrBefore - 1, inclusive,
2472      //    for which PocLtFoll[ i ] is equal to ( PocStCurrBefore[ j ] & ( MaxPicOrderCntLsb - 1 ) ).
2473      for (Int j = 0; j <= numPocStCurrBefore - 1; j++ )
2474      {
2475        assert(!( pocLtFoll[ i ] == ( pocStCurrBefore[ j ] & ( maxPicOrderCntLsb - 1 ) ) ) );
2476      }
2477
2478      // -  There shall be no j in the range of 0 to NumPocStCurrAfter - 1, inclusive,
2479      //    for which PocLtFoll[ i ] is equal to ( PocStCurrAfter[ j ] & ( MaxPicOrderCntLsb - 1 ) ).
2480      for (Int j = 0; j <= numPocStCurrAfter - 1; j++ )
2481      {
2482        assert(!( pocLtFoll[ i ] == ( pocStCurrAfter[ j ] & ( maxPicOrderCntLsb - 1 ) ) ) );
2483      }
2484
2485      // -  There shall be no j in the range of 0 to NumPocStFoll - 1, inclusive,
2486      //    for which PocLtFoll[ i ] is equal to ( PocStFoll[ j ] & ( MaxPicOrderCntLsb - 1 ) ).
2487      for (Int j = 0; j <= numPocStFoll - 1; j++ )
2488      {
2489        assert(!( pocLtFoll[ i ] == ( pocStFoll[ j ] & ( maxPicOrderCntLsb - 1 ) ) ) );
2490      }
2491
2492      // -  There shall be no j in the range of 0 to NumPocLtFoll - 1, inclusive,
2493      //    where j is not equal to i, for which PocLtFoll[ i ] is equal to ( PocLtFoll[ j ] & ( MaxPicOrderCntLsb - 1 ) ).
2494      for (Int j = 0; j <= numPocLtFoll - 1; j++ )
2495      {
2496        if (j != i)
2497        {
2498          assert(!( pocLtFoll[ i ] == ( pocLtFoll[ j ] & ( maxPicOrderCntLsb - 1 ) ) ) );
2499        }
2500      }
2501
2502      // -  There shall be no j in the range of 0 to NumPocLtCurr - 1, inclusive,
2503      //    for which PocLtFoll[ i ] is equal to ( PocLtCurr[ j ] & ( MaxPicOrderCntLsb - 1 ) ).
2504      for (Int j = 0; j <= numPocLtCurr - 1; j++ )
2505      {
2506        assert(!( pocLtFoll[ i ] == ( pocLtCurr[ j ] & ( maxPicOrderCntLsb - 1 ) ) ) );
2507      }
2508    }
2509  }
2510
2511  if ( !annexFModifications )
2512  {
2513    // The variable NumPicTotalCurr is derived as specified in clause 7.4.7.2.
2514
2515    // It is a requirement of bitstream conformance that the following applies to the value of NumPicTotalCurr:
2516    if ( m_pcPic->isBla() || m_pcPic->isCra() )
2517    {
2518      // -  If the current picture is a BLA or CRA picture, the value of NumPicTotalCurr shall be equal to 0.
2519      assert( slice->getNumPicTotalCurr() == 0 );
2520    }
2521    else
2522    {
2523      // -  Otherwise,
2524      if ( slice->isInterP() || slice->isInterB() )
2525      {
2526        // when the current picture contains a P or B slice, the value of NumPicTotalCurr shall not be equal to 0.
2527        assert( slice->getNumPicTotalCurr() != 0 );
2528      }
2529    }
2530  }
2531
2532  // The RPS of the current picture consists of five RPS lists; RefPicSetStCurrBefore, RefPicSetStCurrAfter, RefPicSetStFoll,
2533  // RefPicSetLtCurr and RefPicSetLtFoll. RefPicSetStCurrBefore, RefPicSetStCurrAfter and RefPicSetStFoll are collectively
2534  // referred to as the short-term RPS. RefPicSetLtCurr and RefPicSetLtFoll are collectively referred to as the long-term RPS.
2535
2536  std::vector<TComPic*>& refPicSetStCurrBefore = decRps->m_refPicSetStCurrBefore;
2537  std::vector<TComPic*>& refPicSetStCurrAfter  = decRps->m_refPicSetStCurrAfter ;
2538  std::vector<TComPic*>& refPicSetStFoll       = decRps->m_refPicSetStFoll      ;
2539  std::vector<TComPic*>& refPicSetLtCurr       = decRps->m_refPicSetLtCurr      ;
2540  std::vector<TComPic*>& refPicSetLtFoll       = decRps->m_refPicSetLtFoll      ;
2541
2542  std::vector<TComPic*>** refPicSetsCurr       = decRps->m_refPicSetsCurr       ;
2543  std::vector<TComPic*>** refPicSetsLt         = decRps->m_refPicSetsLt         ;
2544  std::vector<TComPic*>** refPicSetsAll        = decRps->m_refPicSetsAll        ;
2545  //   NOTE 3 - RefPicSetStCurrBefore, RefPicSetStCurrAfter and RefPicSetLtCurr contain all reference pictures that may be
2546  //   used for inter prediction of the current picture and one or more pictures that follow the current picture in decoding order.
2547  //   RefPicSetStFoll and RefPicSetLtFoll consist of all reference pictures that are not used for inter prediction of the current
2548  //   picture but may be used in inter prediction for one or more pictures that follow the current picture in decoding order.
2549
2550  // The derivation process for the RPS and picture marking are performed according to the following ordered steps:
2551  // 1.  The following applies:
2552
2553  TComSubDpb* dpb = m_dpb->getSubDpb( getLayerId(), false );
2554  assert( refPicSetLtCurr.empty() );
2555  for( Int i = 0; i < numPocLtCurr; i++ )
2556  {
2557    if( !currDeltaPocMsbPresentFlag[ i ] )
2558    {
2559      refPicSetLtCurr.push_back( dpb->getPicFromLsb( pocLtCurr[ i ], maxPicOrderCntLsb ) );
2560    }
2561    else
2562    {
2563      refPicSetLtCurr.push_back(dpb->getPic( pocLtCurr[ i ] ));
2564    }
2565  }
2566
2567  assert( refPicSetLtFoll.empty() );
2568  for( Int i = 0; i < numPocLtFoll; i++ )
2569  {
2570   if( !follDeltaPocMsbPresentFlag[ i ] )
2571   {
2572     refPicSetLtFoll.push_back(dpb->getPicFromLsb(pocLtFoll[ i ], maxPicOrderCntLsb ));
2573   }
2574   else
2575   {
2576     refPicSetLtFoll.push_back(dpb->getPic( pocLtFoll[ i ] ));
2577   }
2578  }
2579
2580  // 2.  All reference pictures that are included in RefPicSetLtCurr or RefPicSetLtFoll and have nuh_layer_id equal
2581  //     to currPicLayerId are marked as "used for long-term reference".
2582  for (Int i = 0; i < numPocLtCurr; i++)
2583  {
2584    if ( refPicSetLtCurr[i] != NULL )
2585    {
2586      refPicSetLtCurr[i]->markAsUsedForLongTermReference();
2587    }
2588  }
2589
2590  for (Int i = 0; i < numPocLtFoll; i++)
2591  {
2592    if ( refPicSetLtFoll[i] != NULL )
2593    {
2594      refPicSetLtFoll[i]->markAsUsedForLongTermReference();
2595    }
2596  }
2597
2598  // 3.  The following applies:
2599  assert( refPicSetStCurrBefore.empty() );
2600  for( Int i = 0; i < numPocStCurrBefore; i++ )
2601  {
2602    refPicSetStCurrBefore.push_back(dpb->getShortTermRefPic( pocStCurrBefore[ i ] ));
2603  }
2604
2605  assert( refPicSetStCurrAfter.empty() );
2606  for( Int i = 0; i < numPocStCurrAfter; i++ )
2607  {
2608    refPicSetStCurrAfter.push_back(dpb->getShortTermRefPic( pocStCurrAfter[ i ] ));
2609  }
2610
2611  assert( refPicSetStFoll.empty() );
2612  for( Int i = 0; i < numPocStFoll; i++ )
2613  {
2614    refPicSetStFoll.push_back(dpb->getShortTermRefPic( pocStFoll[ i ] ));
2615  }
2616
2617  // 4.  All reference pictures in the DPB that are not included in RefPicSetLtCurr, RefPicSetLtFoll, RefPicSetStCurrBefore,
2618  //     RefPicSetStCurrAfter, or RefPicSetStFoll and have nuh_layer_id equal to currPicLayerId are marked as "unused for reference".
2619  TComSubDpb picsToMark = (*dpb);
2620  for (Int j = 0; j < 5; j++ )
2621  {
2622    picsToMark.removePics( *refPicSetsAll[j] );
2623  }
2624  picsToMark.markAllAsUnusedForReference();
2625
2626  //     NOTE 4 - There may be one or more entries in the RPS lists that are equal to "no reference picture" because
2627  //     the corresponding pictures are not present in the DPB. Entries in RefPicSetStFoll or RefPicSetLtFoll that are equal
2628  //     to "no reference picture" should be ignored. An unintentional picture loss should be inferred for each entry in
2629  //     RefPicSetStCurrBefore, RefPicSetStCurrAfter, or RefPicSetLtCurr that is equal to "no reference picture".
2630
2631  //     NOTE 5 - A picture cannot be included in more than one of the five RPS lists.
2632
2633
2634  // It is a requirement of bitstream conformance that the RPS is restricted as follows:
2635
2636
2637#if NH_MV_FIX_NO_REF_PICS_CHECK
2638  if ( !annexFModifications || m_firstPicInLayerDecodedFlag[ m_pcPic->getLayerId() ] )
2639  {
2640#endif
2641    for (Int j = 0; j < 3; j++ )
2642    {
2643      // -  There shall be no entry in RefPicSetStCurrBefore, RefPicSetStCurrAfter or RefPicSetLtCurr
2644      //    for which one or more of the following are true:
2645
2646      std::vector<TComPic*>* currSet = refPicSetsCurr[j];
2647      for (Int i = 0; i < currSet->size(); i++)
2648      {
2649        TComPic* pic = (*currSet)[i];
2650
2651        // -  The entry is equal to "no reference picture".
2652        assert( ! (pic == NULL ) );
2653
2654        // -  The entry is an SLNR picture and has TemporalId equal to that of the current picture.
2655        assert( !( pic->isSlnr() && pic->getTemporalId() == m_pcPic->getTemporalId() ) );
2656
2657        // -  The entry is a picture that has TemporalId greater than that of the current picture.
2658        assert( !(  pic->getTemporalId() > m_pcPic->getTemporalId() ) );
2659      }
2660    }
2661#if NH_MV_FIX_NO_REF_PICS_CHECK
2662  }
2663#endif
2664
2665  //  -  There shall be no entry in RefPicSetLtCurr or RefPicSetLtFoll for which the
2666  //     difference between the picture order count value of the current picture and the picture order count
2667  //     value of the entry is greater than or equal to 2^24.
2668  for (Int j = 0; j < 2; j++ )
2669  {
2670    std::vector<TComPic*>* ltSet = refPicSetsLt[j];
2671    for (Int i = 0; i < ltSet->size(); i++)
2672    {
2673      TComPic* pic = (*ltSet)[i];
2674      if( pic != NULL )
2675      {
2676        assert(!( abs( m_pcPic->getPOC() - pic->getPOC() ) >= (1 << 24) ));
2677      }
2678    }
2679  }
2680
2681  //   -  When the current picture is a temporal sub-layer access (TSA) picture, there shall be no picture
2682  //      included in the RPS with TemporalId greater than or equal to the TemporalId of the current picture.
2683  if (m_pcPic->isTsa() )
2684  {
2685    for (Int j = 0; j < 5; j++ )
2686    {
2687      std::vector<TComPic*>* aSet = refPicSetsAll[j];
2688      for (Int i = 0; i < aSet->size(); i++)
2689      {
2690        TComPic* pic = (*aSet)[i];
2691        if( pic != NULL )
2692        {
2693          assert( ! (pic->getTemporalId() >= m_pcPic->getTemporalId() ) );
2694        }
2695      }
2696    }
2697  }
2698
2699  //   -  When the current picture is a step-wise temporal sub-layer access (STSA) picture,
2700  //      there shall be no picture included in RefPicSetStCurrBefore, RefPicSetStCurrAfter or RefPicSetLtCurr that has
2701  //      TemporalId equal to that of the current picture.
2702  if (m_pcPic->isStsa() )
2703  {
2704    for (Int j = 0; j < 3; j++ )
2705    {
2706      std::vector<TComPic*>* cSet = refPicSetsCurr[j];
2707      for (Int i = 0; i < cSet->size(); i++)
2708      {
2709        TComPic* pic = (*cSet)[i];
2710        if( pic != NULL )
2711        {
2712          assert( ! (pic->getTemporalId() == m_pcPic->getTemporalId() ) );
2713        }
2714      }
2715    }
2716  }
2717
2718  //   -  When the current picture is a picture that follows, in decoding order, an STSA picture
2719  //      that has TemporalId equal to that of the current picture, there shall be no picture that has
2720  //      TemporalId equal to that of the current picture included in RefPicSetStCurrBefore, RefPicSetStCurrAfter
2721  //      or RefPicSetLtCurr that precedes the STSA picture in decoding order.
2722  if ( m_pcPic->getDecodingOrder() > m_prevStsaDecOrder && m_pcPic->getTemporalId() == m_prevStsaTemporalId  )
2723  {
2724    for (Int j = 0; j < 3; j++ )
2725    {
2726      std::vector<TComPic*>* cSet = refPicSetsCurr[j];
2727      for (Int i = 0; i < cSet->size(); i++)
2728      {
2729        TComPic* pic = (*cSet)[i];
2730        if( pic != NULL )
2731        {
2732          assert( ! (pic->getTemporalId() == m_pcPic->getTemporalId() && pic->getDecodingOrder() < m_prevStsaDecOrder  ) );
2733        }
2734      }
2735    }
2736  }
2737
2738  //   -  When the current picture is a CRA picture, there shall be no picture included in the RPS that
2739  //      precedes, in output order or decoding order, any preceding IRAP picture in decoding order (when present).
2740  if ( m_pcPic->isCra() )
2741  {
2742    for (Int j = 0; j < 5; j++ )
2743    {
2744      std::vector<TComPic*>* aSet = refPicSetsAll[j];
2745      for (Int i = 0; i < aSet->size(); i++)
2746      {
2747        // TBD check whether it sufficient to test only the last IRAP
2748        TComPic* pic = (*aSet)[i];
2749        if( pic != NULL )
2750        {
2751          assert( ! (pic->getPOC()           < m_prevIrapPoc           ) );
2752          assert( ! (pic->getDecodingOrder() < m_prevIrapDecodingOrder ) );
2753        }
2754      }
2755    }
2756  }
2757
2758  Bool isTrailingPicture = ( !m_pcPic->isIrap() ) && ( m_pcPic->getPOC() > m_prevIrapPoc );
2759  //   -  When the current picture is a trailing picture, there shall be no picture in RefPicSetStCurrBefore,
2760  //      RefPicSetStCurrAfter or RefPicSetLtCurr that was generated by the decoding process for generating unavailable
2761  //      reference pictures as specified in clause 8.3.3.
2762  if ( isTrailingPicture )
2763  {
2764    for (Int j = 0; j < 3; j++ )
2765    {
2766      std::vector<TComPic*>* cSet = refPicSetsCurr[j];
2767      for (Int i = 0; i < cSet->size(); i++)
2768      {
2769        TComPic* pic = (*cSet)[i];
2770        if( pic != NULL )
2771        {
2772          assert( ! (pic->getIsGeneratedCl833() ) );
2773        }
2774      }
2775    }
2776  }
2777
2778  //   -  When the current picture is a trailing picture, there shall be no picture in the RPS that precedes the
2779  //      associated IRAP picture in output order or decoding order.
2780  if ( isTrailingPicture )
2781  {
2782    for (Int j = 0; j < 5; j++ )
2783    {
2784      std::vector<TComPic*>* aSet = refPicSetsAll[j];
2785      for (Int i = 0; i < aSet->size(); i++)
2786      {
2787        // TBD check whether it sufficient to test only the last IRAP
2788         TComPic* pic = (*aSet)[i];
2789        if( pic != NULL )
2790        {
2791          assert( ! (pic->getPOC()           < m_prevIrapPoc           ) );
2792          assert( ! (pic->getDecodingOrder() < m_prevIrapDecodingOrder ) );
2793        }
2794      }
2795    }
2796  }
2797
2798  //   -  When the current picture is a RADL picture, there shall be no picture included in RefPicSetStCurrBefore,
2799  //      RefPicSetStCurrAfter or RefPicSetLtCurr that is any of the following:
2800  if ( m_pcPic->isRadl() )
2801  {
2802    for (Int j = 0; j < 3; j++ )
2803    {
2804      std::vector<TComPic*>* cSet = refPicSetsCurr[j];
2805      for (Int i = 0; i < cSet->size(); i++)
2806      {
2807        TComPic* pic = (*cSet)[i];
2808        if( pic != NULL )
2809        {
2810          // -  A RASL picture
2811          assert( ! (pic->isRasl() ) );
2812          // -  A picture that was generated by the decoding process for generating unavailable reference pictures
2813          //    as specified in clause 8.3.3
2814          assert( ! (pic->getIsGeneratedCl833() ) );
2815          // -  A picture that precedes the associated IRAP picture in decoding order
2816          assert( ! (pic->getDecodingOrder() < m_prevIrapDecodingOrder ) );
2817        }
2818      }
2819    }
2820  }
2821
2822
2823  if ( sps->getTemporalIdNestingFlag() )
2824  {
2825    // -  When sps_temporal_id_nesting_flag is equal to 1, the following applies:
2826    //    -  Let tIdA be the value of TemporalId of the current picture picA.
2827    TComPic* picA = m_pcPic;
2828    Int      tIdA = picA->getTemporalId();
2829    //   -  Any picture picB with TemporalId equal to tIdB that is less than or equal to tIdA shall not be included in
2830    //      RefPicSetStCurrBefore, RefPicSetStCurrAfter or RefPicSetLtCurr of picA when there exists a picture picC that
2831    //      has TemporalId less than tIdB, follows picB in decoding order, and precedes picA in decoding order.
2832    for (Int j = 0; j < 3; j++ )
2833    {
2834      std::vector<TComPic*>* cSet = refPicSetsCurr[j];
2835      for (Int i = 0; i < cSet->size(); i++)
2836      {
2837        TComPic* picB = (*cSet)[i];
2838        if( picB != NULL )
2839        {
2840          Int tIdB = picB->getTemporalId();
2841
2842          if (tIdB <= tIdA)
2843          {
2844            for ( TComSubDpb::iterator itP = dpb->begin(); itP != dpb->end(); itP++ )
2845            {
2846              TComPic* picC = (*itP);
2847              assert(! ( picC->getTemporalId() < tIdB && picC->getDecodingOrder() > picB->getDecodingOrder() && picC->getDecodingOrder() < picA->getDecodingOrder()  )  );
2848            }
2849          }
2850        }
2851      }
2852    }
2853  }
2854}
2855
2856
2857Void TDecTop::xF832DecProcForRefPicSet()
2858{
2859  ///////////////////////////////////////////////////////////////////////////////////////
2860  // F.8.3.2 Decoding process for reference picture set
2861  ///////////////////////////////////////////////////////////////////////////////////////
2862
2863  // The specifications in clause 8.3.2 apply with the following changes:
2864  // -  The references to clauses 7.4.7.2, 8.3.1, 8.3.3 and 8.3.4 are replaced with references to
2865  //    clauses F.7.4.7.2, F.8.3.1, F.8.3.3 and F.8.3.4, respectively.
2866
2867  x832DecProcForRefPicSet( true );
2868
2869  // -  The following specifications are added:
2870  if (m_pcPic->isIrap() && m_pcPic->getLayerId() == m_smallestLayerId )
2871  {
2872    // -  When the current picture is an IRAP picture with nuh_layer_id equal to SmallestLayerId,
2873    //    all reference pictures with any value of nuh_layer_id currently in the DPB (if any) are marked
2874    //    as "unused for reference" when at least one of the following conditions is true:
2875
2876    if ( m_pcPic->getNoClrasOutputFlag() || m_pcPic->getActivatesNewVps() )
2877    {
2878      // -  The current picture has NoClrasOutputFlag is equal to 1.
2879      // -  The current picture activates a new VPS.
2880      m_dpb->markAllSubDpbAsUnusedForReference( );
2881    }
2882  }
2883
2884  // -  It is a requirement of bitstream conformance that the RPS is restricted as follows:
2885  // -  When the current picture is a CRA picture, there shall be no picture in RefPicSetStCurrBefore, RefPicSetStCurrAfter
2886  //    or RefPicSetLtCurr.
2887
2888  std::vector<TComPic*>** refPicSetsCurr       = m_pcPic->getDecodedRps()->m_refPicSetsCurr;
2889
2890  if ( m_pcPic->isCra() )
2891  {
2892    for (Int j = 0; j < 3; j++ )
2893    {
2894      std::vector<TComPic*>* cSet = refPicSetsCurr[j];
2895      assert ( cSet->size() == 0 );
2896    }
2897  }
2898
2899  // -  The constraints specified in clause 8.3.2 on the value of NumPicTotalCurr are replaced with the following:
2900  //    -  It is a requirement of bitstream conformance that the following applies to the value of NumPicTotalCurr:
2901  Int numPicTotalCurr = m_pcPic->getSlice(0)->getNumPicTotalCurr();
2902  Int currPicLayerId  = m_pcPic->getLayerId();
2903  const TComVPS* vps  = m_pcPic->getSlice(0)->getVPS();
2904
2905  if ( ( m_pcPic->isBla() || m_pcPic->isCra() ) && (  (currPicLayerId == 0 ) || ( vps->getNumDirectRefLayers( currPicLayerId ) == 0 ) ) )
2906  {
2907    assert( numPicTotalCurr == 0 );
2908    // -  If the current picture is a BLA or CRA picture and either currPicLayerId is equal to 0 or
2909    //     NumDirectRefLayers[ currPicLayerId ] is equal to 0, the value of NumPicTotalCurr shall be equal to 0.
2910  }
2911  else
2912  {
2913    // TBD: check all slices
2914    if ( m_pcPic->getSlice(0)->getSliceType() == P_SLICE  ||  m_pcPic->getSlice(0)->getSliceType() == B_SLICE )
2915    {
2916      // -  Otherwise, when the current picture contains a P or B slice, the value of NumPicTotalCurr shall not be equal to 0.
2917      assert( numPicTotalCurr != 0 );
2918    }
2919  }
2920}
2921
2922
2923Void TDecTop::xG813DecProcForInterLayerRefPicSet()
2924{
2925  ////////////////////////////////////////////////////////////////////
2926  // G.8.1.3 Decoding process for inter-layer reference picture set //
2927  ////////////////////////////////////////////////////////////////////
2928
2929  // Outputs of this process are updated lists of inter-layer reference pictures RefPicSetInterLayer0 and RefPicSetInterLayer1
2930  // and the variables NumActiveRefLayerPics0 and NumActiveRefLayerPics1.
2931
2932  TComDecodedRps* decRps = m_pcPic->getDecodedRps();
2933  TComSlice* slice       = m_pcPic->getSlice( 0 );
2934  const TComVPS* vps     =  slice->getVPS();
2935
2936  Int&                   numActiveRefLayerPics0 = decRps->m_numActiveRefLayerPics0;
2937  Int&                   numActiveRefLayerPics1 = decRps->m_numActiveRefLayerPics1;
2938
2939  std::vector<TComPic*>& refPicSetInterLayer0   = decRps->m_refPicSetInterLayer0;
2940  std::vector<TComPic*>& refPicSetInterLayer1   = decRps->m_refPicSetInterLayer1;
2941
2942  // The variable currLayerId is set equal to nuh_layer_id of the current picture.
2943  Int currLayerId = getLayerId();
2944
2945  // The lists RefPicSetInterLayer0 and RefPicSetInterLayer1 are first emptied, NumActiveRefLayerPics0 and NumActiveRefLayerPics1
2946  // are set equal to 0 and the following applies:
2947
2948  refPicSetInterLayer0.clear();
2949  refPicSetInterLayer1.clear();
2950
2951  numActiveRefLayerPics0 = 0;
2952  numActiveRefLayerPics1 = 0;
2953
2954  Int viewIdCurrLayerId  = vps->getViewId( currLayerId );
2955  Int viewId0            = vps->getViewId( 0   );
2956
2957  for( Int i = 0; i < slice->getNumActiveRefLayerPics(); i++ )
2958  {
2959    Int viewIdRefPicLayerIdi = vps->getViewId( slice->getRefPicLayerId( i ) );
2960
2961    Bool refPicSet0Flag =
2962      ( ( viewIdCurrLayerId <=  viewId0  &&  viewIdCurrLayerId <=  viewIdRefPicLayerIdi )  ||
2963      ( viewIdCurrLayerId >=  viewId0  &&  viewIdCurrLayerId >=  viewIdRefPicLayerIdi ) );
2964
2965    TComPic* picX = m_dpb->getAu(slice->getPOC(), false )->getPic( slice->getRefPicLayerId( i ) );
2966    if ( picX != NULL )
2967    {
2968      // there is a picture picX in the DPB that is in the same access unit as the current picture and has
2969      // nuh_layer_id equal to RefPicLayerId[ i ]
2970
2971      if ( refPicSet0Flag )
2972      {
2973        refPicSetInterLayer0.push_back( picX );
2974        refPicSetInterLayer0[ numActiveRefLayerPics0++ ]->markAsUsedForLongTermReference();
2975      }
2976      else
2977      {
2978        refPicSetInterLayer1.push_back( picX );
2979        refPicSetInterLayer1[ numActiveRefLayerPics1++ ]->markAsUsedForLongTermReference();
2980      }
2981
2982      // There shall be no picture that has discardable_flag equal to 1 in RefPicSetInterLayer0 or RefPicSetInterLayer1.
2983      assert( ! picX->getSlice(0)->getDiscardableFlag() );
2984
2985      // If the current picture is a RADL picture, there shall be no entry in RefPicSetInterLayer0 or RefPicSetInterLayer1
2986      // that is a RASL picture.
2987      if ( m_pcPic->isRadl() )
2988      {
2989        assert( ! picX->isRasl() );
2990      }
2991    }
2992    else
2993    {
2994      if( refPicSet0Flag )
2995      {
2996        refPicSetInterLayer0.push_back( NULL ); // "no reference picture" (G 1)
2997        numActiveRefLayerPics0++;
2998      }
2999      else
3000      {
3001        refPicSetInterLayer1.push_back( NULL ); // "no reference picture";
3002        numActiveRefLayerPics1++;
3003      }
3004      // There shall be no entry equal to "no reference picture" in RefPicSetInterLayer0 or RefPicSetInterLayer1.
3005      assert( false );
3006    }
3007  }
3008}
3009
3010
3011Void TDecTop::x8331GenDecProcForGenUnavilRefPics()
3012{
3013  ///////////////////////////////////////////////////////////////////////////////////////
3014  // 8.3.3.1  General decoding process for generating unavailable reference pictures ////
3015  ///////////////////////////////////////////////////////////////////////////////////////
3016
3017  // This process is invoked once per coded picture when the current picture is a
3018  // BLA picture or is a CRA picture with NoRaslOutputFlag equal to 1.
3019
3020  assert( m_pcPic->isBla() || (m_pcPic->isCra() && m_pcPic->getNoRaslOutputFlag() ) );
3021  TComDecodedRps* decRps = m_pcPic->getDecodedRps();
3022
3023  std::vector<TComPic*>& refPicSetStFoll      = decRps->m_refPicSetStFoll;
3024  std::vector<TComPic*>& refPicSetLtFoll      = decRps->m_refPicSetLtFoll;
3025
3026  const std::vector<Int>& pocStFoll             = decRps->m_pocStFoll;
3027  const std::vector<Int>& pocLtFoll             = decRps->m_pocLtFoll;
3028
3029  const Int               numPocStFoll          = decRps->m_numPocStFoll;
3030  const Int               numPocLtFoll          = decRps->m_numPocLtFoll;
3031
3032  // When this process is invoked, the following applies:
3033  for ( Int i = 0 ; i <= numPocStFoll - 1; i++ )
3034  {
3035    if ( refPicSetStFoll[ i ] == NULL )
3036    {
3037      //-  For each RefPicSetStFoll[ i ], with i in the range of 0 to NumPocStFoll - 1, inclusive, that is equal
3038      //   to "no reference picture", a picture is generated as specified in clause 8.3.3.2, and the following applies:
3039      TComPic* genPic = x8332GenOfOneUnavailPic( true );
3040
3041      // -  The value of PicOrderCntVal for the generated picture is set equal to PocStFoll[ i ].
3042      genPic->getSlice(0)->setPOC( pocStFoll[ i ] );
3043
3044      //-  The value of PicOutputFlag for the generated picture is set equal to 0.
3045      genPic->setPicOutputFlag( false );
3046
3047      // -  The generated picture is marked as "used for short-term reference".
3048      genPic->markAsUsedForShortTermReference();
3049
3050      // -  RefPicSetStFoll[ i ] is set to be the generated reference picture.
3051      refPicSetStFoll[ i ] = genPic;
3052
3053      // -  The value of nuh_layer_id for the generated picture is set equal to nuh_layer_id of the current picture.
3054      genPic->setLayerId( m_pcPic-> getLayerId() );
3055
3056      // Insert to DPB
3057      m_dpb->addNewPic( genPic );
3058    }
3059  }
3060
3061  for ( Int i = 0 ; i <= numPocLtFoll - 1; i++ )
3062  {
3063    if ( refPicSetLtFoll[ i ] == NULL )
3064    {
3065      //-  For each RefPicSetLtFoll[ i ], with i in the range of 0 to NumPocLtFoll - 1, inclusive, that is equal to
3066      //   "no reference picture", a picture is generated as specified in clause 8.3.3.2, and the following applies:
3067      TComPic* genPic = x8332GenOfOneUnavailPic( true );
3068
3069      //-  The value of PicOrderCntVal for the generated picture is set equal to PocLtFoll[ i ].
3070      genPic->getSlice(0)->setPOC( pocStFoll[ i ] );
3071
3072      //  -  The value of slice_pic_order_cnt_lsb for the generated picture is inferred to be equal to ( PocLtFoll[ i ] & ( MaxPicOrderCntLsb - 1 ) ).
3073      genPic->getSlice(0)->setSlicePicOrderCntLsb( ( pocLtFoll[ i ] & ( m_pcPic->getSlice(0)->getSPS()->getMaxPicOrderCntLsb() - 1 ) ) );
3074
3075      //  -  The value of PicOutputFlag for the generated picture is set equal to 0.
3076      genPic->setPicOutputFlag( false );
3077
3078      //  -  The generated picture is marked as "used for long-term reference".
3079      genPic->markAsUsedForLongTermReference();
3080
3081      //  -  RefPicSetLtFoll[ i ] is set to be the generated reference picture.
3082      refPicSetLtFoll[ i ] = genPic;
3083
3084      //  -  The value of nuh_layer_id for the generated picture is set equal to nuh_layer_id of the current picture.
3085      genPic->setLayerId( m_pcPic-> getLayerId() );
3086
3087      // Insert to DPB
3088      m_dpb->addNewPic( genPic );
3089    }
3090  }
3091}
3092
3093
3094TComPic* TDecTop::x8332GenOfOneUnavailPic( Bool calledFromCl8331 )
3095{
3096  ///////////////////////////////////////////////////////////////////////////////////////
3097  // 8.3.3.2 Generation of one unavailable picture
3098  ///////////////////////////////////////////////////////////////////////////////////////
3099
3100  TComPic* genPic = new TComPic;
3101  genPic->create( *m_pcPic->getSlice(0)->getSPS(), *m_pcPic->getSlice(0)->getPPS(), true );
3102  genPic->setIsGenerated( true );
3103  genPic->setIsGeneratedCl833( calledFromCl8331 );
3104  return genPic;
3105}
3106
3107
3108Void TDecTop::xF817DecProcForGenUnavRefPicForPicsFrstInDecOrderInLay()
3109{
3110  ///////////////////////////////////////////////////////////////////////////////////////
3111  // F.8.1.7 Decoding process for generating unavailable reference pictures for pictures
3112  //         first in decoding order within a layer
3113  ///////////////////////////////////////////////////////////////////////////////////////
3114
3115  //  This process is invoked for a picture with nuh_layer_id equal to layerId, when FirstPicInLayerDecodedFlag[layerId ] is equal to 0.
3116  assert( !m_firstPicInLayerDecodedFlag[ getLayerId() ] );
3117
3118
3119  TComDecodedRps* decRps = m_pcPic->getDecodedRps();
3120
3121  std::vector<TComPic*>& refPicSetStCurrBefore = decRps->m_refPicSetStCurrBefore;
3122  std::vector<TComPic*>& refPicSetStCurrAfter  = decRps->m_refPicSetStCurrAfter;
3123  std::vector<TComPic*>& refPicSetStFoll       = decRps->m_refPicSetStFoll;
3124  std::vector<TComPic*>& refPicSetLtCurr       = decRps->m_refPicSetLtCurr;
3125  std::vector<TComPic*>& refPicSetLtFoll       = decRps->m_refPicSetLtFoll;
3126
3127
3128  const std::vector<Int>& pocStCurrBefore      = decRps->m_pocStCurrBefore;
3129  const std::vector<Int>& pocStCurrAfter       = decRps->m_pocStCurrAfter;
3130  const std::vector<Int>& pocStFoll            = decRps->m_pocStFoll;
3131  const std::vector<Int>& pocLtCurr            = decRps->m_pocLtCurr;
3132  const std::vector<Int>& pocLtFoll            = decRps->m_pocLtFoll;
3133
3134  const Int numPocStCurrBefore                 = decRps->m_numPocStCurrBefore;
3135  const Int numPocStCurrAfter                  = decRps->m_numPocStCurrAfter;
3136  const Int numPocStFoll                       = decRps->m_numPocStFoll;
3137  const Int numPocLtCurr                       = decRps->m_numPocLtCurr;
3138  const Int numPocLtFoll                       = decRps->m_numPocLtFoll;
3139
3140  Int nuhLayerId = m_pcPic-> getLayerId();
3141  for ( Int i = 0 ; i <= numPocStCurrBefore - 1; i++ )
3142  {
3143    if ( refPicSetStCurrBefore[ i ] == NULL )
3144    {
3145      //-  For each RefPicSetStCurrBefore[ i ], with i in the range of 0 to NumPocStCurrBefore - 1, inclusive, that is
3146      //  equal to "no reference picture", a picture is generated as specified in clause 8.3.3.2 and the following applies:
3147      TComPic* genPic = x8332GenOfOneUnavailPic( false );
3148
3149      //-  The value of PicOrderCntVal for the generated picture is set equal to PocStCurrBefore[ i ].
3150      genPic->getSlice(0)->setPOC( pocStCurrBefore[ i ] );
3151
3152      //  -  The value of PicOutputFlag for the generated picture is set equal to 0.
3153      genPic->setPicOutputFlag( false );
3154
3155      //  -  The generated picture is marked as "used for short-term reference".
3156      genPic->markAsUsedForShortTermReference();
3157
3158      //  -  RefPicSetStCurrBefore[ i ] is set to be the generated reference picture.
3159      refPicSetStCurrBefore[ i ] = genPic;
3160
3161      //  -  The value of nuh_layer_id for the generated picture is set equal to nuh_layer_id.
3162      genPic->setLayerId( nuhLayerId );
3163
3164      // Insert to DPB
3165      m_dpb->addNewPic( genPic );
3166    }
3167  }
3168
3169  for ( Int i = 0 ; i <= numPocStCurrAfter - 1; i++ )
3170  {
3171    if ( refPicSetStCurrAfter[ i ] == NULL )
3172    {
3173      //  -  For each RefPicSetStCurrAfter[ i ], with i in the range of 0 to NumPocStCurrAfter - 1, inclusive, that is equal
3174      //     to "no reference picture", a picture is generated as specified in clause 8.3.3.2 and the following applies:
3175      TComPic* genPic = x8332GenOfOneUnavailPic( false );
3176
3177      //  -  The value of PicOrderCntVal for the generated picture is set equal to PocStCurrAfter[ i ].
3178      genPic->getSlice(0)->setPOC( pocStCurrAfter[ i ] );
3179
3180      //  -  The value of PicOutputFlag for the generated picture is set equal to 0.
3181      genPic->setPicOutputFlag( false );
3182
3183      //  -  The generated picture is marked as "used for short-term reference".
3184      genPic->markAsUsedForShortTermReference();
3185
3186      //  -  RefPicSetStCurrAfter[ i ] is set to be the generated reference picture.
3187      refPicSetStCurrAfter[ i ] = genPic;
3188
3189      //  -  The value of nuh_layer_id for the generated picture is set equal to nuh_layer_id.
3190      genPic->setLayerId( nuhLayerId );
3191
3192      // Insert to DPB
3193      m_dpb->addNewPic( genPic );
3194
3195    }
3196  }
3197
3198  for ( Int i = 0 ; i <= numPocStFoll - 1; i++ )
3199  {
3200    if ( refPicSetStFoll[ i ] == NULL )
3201    {
3202      //  -  For each RefPicSetStFoll[ i ], with i in the range of 0 to NumPocStFoll - 1, inclusive, that is equal to "no
3203      //     reference picture", a picture is generated as specified in clause 8.3.3.2 and the following applies:
3204      TComPic* genPic = x8332GenOfOneUnavailPic( false );
3205
3206      //  -  The value of PicOrderCntVal for the generated picture is set equal to PocStFoll[ i ].
3207      genPic->getSlice(0)->setPOC( pocStFoll[ i ] );
3208
3209      //  -  The value of PicOutputFlag for the generated picture is set equal to 0.
3210      genPic->setPicOutputFlag( false );
3211
3212      //  -  The generated picture is marked as "used for short-term reference".
3213      genPic->markAsUsedForShortTermReference();
3214
3215      //  -  RefPicSetStFoll[ i ] is set to be the generated reference picture.
3216      refPicSetStFoll[ i ] = genPic;
3217
3218      //  -  The value of nuh_layer_id for the generated picture is set equal to nuh_layer_id.
3219      genPic->setLayerId( nuhLayerId );
3220
3221      // Insert to DPB
3222      m_dpb->addNewPic( genPic );
3223    }
3224  }
3225
3226  Int maxPicOrderCntLsb = m_pcPic->getSlice(0)->getSPS()->getMaxPicOrderCntLsb();
3227  for ( Int i = 0 ; i <= numPocLtCurr - 1; i++ )
3228  {
3229    if ( refPicSetLtCurr[ i ] == NULL )
3230    {
3231      //  -  For each RefPicSetLtCurr[ i ], with i in the range of 0 to NumPocLtCurr - 1, inclusive, that is equal to "no
3232      //     reference picture", a picture is generated as specified in clause 8.3.3.2 and the following applies:
3233      TComPic* genPic = x8332GenOfOneUnavailPic( false );
3234
3235      //  -  The value of PicOrderCntVal for the generated picture is set equal to PocLtCurr[ i ].
3236      genPic->getSlice(0)->setPOC( pocLtCurr[ i ] );
3237
3238      //  -  The value of slice_pic_order_cnt_lsb for the generated picture is inferred to be equal to ( PocLtCurr[ i ] & (
3239      //     MaxPicOrderCntLsb - 1 ) ).
3240      genPic->getSlice(0)->setSlicePicOrderCntLsb( ( pocLtCurr[ i ] & ( maxPicOrderCntLsb - 1 ) ) );
3241
3242      //  -  The value of PicOutputFlag for the generated picture is set equal to 0.
3243      genPic->setPicOutputFlag( false );
3244
3245      //  -  The generated picture is marked as "used for long-term reference".
3246      genPic->markAsUsedForLongTermReference();
3247
3248      //  -  RefPicSetLtCurr[ i ] is set to be the generated reference picture.
3249      refPicSetLtCurr[ i ] = genPic;
3250
3251      //  -  The value of nuh_layer_id for the generated picture is set equal to nuh_layer_id.
3252      genPic->setLayerId( nuhLayerId );
3253
3254      // Insert to DPB
3255      m_dpb->addNewPic( genPic );
3256    }
3257  }
3258
3259  for ( Int i = 0 ; i <= numPocLtFoll - 1; i++ )
3260  {
3261    if ( refPicSetLtFoll[ i ] == NULL )
3262    {
3263      //  -  For each RefPicSetLtFoll[ i ], with i in the range of 0 to NumPocLtFoll - 1, inclusive, that is equal to "no
3264      //     reference picture", a picture is generated as specified in clause 8.3.3.2 and the following applies:
3265      TComPic* genPic = x8332GenOfOneUnavailPic( false );
3266
3267      //  -  The value of PicOrderCntVal for the generated picture is set equal to PocLtFoll[ i ].
3268      genPic->getSlice(0)->setPOC( pocLtFoll[ i ] );
3269
3270      //  -  The value of slice_pic_order_cnt_lsb for the generated picture is inferred to be equal to ( PocLtCurr[ i ] & (
3271      //     MaxPicOrderCntLsb - 1 ) ).
3272      genPic->getSlice(0)->setSlicePicOrderCntLsb( ( pocLtCurr[ i ] & ( maxPicOrderCntLsb - 1 ) ) );
3273
3274      //  -  The value of PicOutputFlag for the generated picture is set equal to 0.
3275      genPic->setPicOutputFlag( false );
3276
3277      //  -  The generated picture is marked as "used for long-term reference".
3278      genPic->markAsUsedForLongTermReference();
3279
3280      //  -  RefPicSetLtFoll[ i ] is set to be the generated reference picture.
3281      refPicSetLtFoll[ i ] = genPic;
3282
3283      //  -  The value of nuh_layer_id for the generated picture is set equal to nuh_layer_id.
3284      genPic->setLayerId( nuhLayerId );
3285
3286      // Insert to DPB
3287      m_dpb->addNewPic( genPic );
3288    }
3289  }
3290}
3291
3292Void TDecTop::xF833DecProcForGenUnavRefPics()
3293{
3294  ///////////////////////////////////////////////////////////////////////////////////////
3295  // F.8.3.3 Decoding process for generating unavailable reference picture
3296  ///////////////////////////////////////////////////////////////////////////////////////
3297
3298  x8331GenDecProcForGenUnavilRefPics();
3299}
3300
3301Void TDecTop::xCheckUnavailableRefPics()
3302{
3303  std::vector<TComPic*>** refPicSetsCurr       = m_pcPic->getDecodedRps()->m_refPicSetsCurr;
3304
3305  Bool hasGeneratedRefPic = false;
3306  for (Int j = 0; j < 3; j++ )
3307  {
3308    std::vector<TComPic*>* cSet = refPicSetsCurr[j];
3309    for (Int i = 0 ; i < cSet->size();  i++ )
3310    {
3311      assert( (*cSet)[i] != NULL );
3312      if ((*cSet)[i]->getIsGenerated() )
3313      {
3314        hasGeneratedRefPic = true;
3315      }
3316    }
3317  }
3318  m_pcPic->setHasGeneratedRefPics( hasGeneratedRefPic );
3319}
3320
3321#endif
3322
3323//! \}
Note: See TracBrowser for help on using the repository browser.