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

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

Merged HTM-16.0-dev1@1395.

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