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

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

Merged 15.0-dev0@1320.

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