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

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

Merged 15.1-dev0-NICT@1355.

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