source: 3DVCSoftware/branches/HTM-15.1-dev0/source/Lib/TLibDecoder/TDecTop.cpp @ 1328

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

Integrated general SEI changes and following SEIs:

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