source: 3DVCSoftware/branches/HTM-16.0-MV-draft-5/source/Lib/TLibDecoder/TDecTop.cpp @ 1417

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

Removed 3D.

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