source: SHVCSoftware/branches/SHM-6-dev/source/Lib/TLibCommon/TComSlice.cpp @ 750

Last change on this file since 750 was 737, checked in by seregin, 11 years ago

fix reading width and height from rep format for AVC BL

  • Property svn:eol-style set to native
File size: 120.8 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-2014, 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     TComSlice.cpp
35    \brief    slice header and SPS class
36*/
37
38#include "CommonDef.h"
39#include "TComSlice.h"
40#include "TComPic.h"
41#include "TLibEncoder/TEncSbac.h"
42#include "TLibDecoder/TDecSbac.h"
43
44//! \ingroup TLibCommon
45//! \{
46
47#if SVC_EXTENSION
48ParameterSetMap<TComVPS> ParameterSetManager::m_vpsMap(MAX_NUM_VPS);
49Int ParameterSetManager::m_activeVPSId = -1;
50#endif
51
52TComSlice::TComSlice()
53: m_iPPSId                        ( -1 )
54, m_iPOC                          ( 0 )
55, m_iLastIDR                      ( 0 )
56, m_eNalUnitType                  ( NAL_UNIT_CODED_SLICE_IDR_W_RADL )
57, m_eSliceType                    ( I_SLICE )
58, m_iSliceQp                      ( 0 )
59, m_dependentSliceSegmentFlag            ( false )
60#if ADAPTIVE_QP_SELECTION
61, m_iSliceQpBase                  ( 0 )
62#endif
63, m_deblockingFilterDisable        ( false )
64, m_deblockingFilterOverrideFlag   ( false )
65, m_deblockingFilterBetaOffsetDiv2 ( 0 )
66, m_deblockingFilterTcOffsetDiv2   ( 0 )
67, m_bCheckLDC                     ( false )
68, m_iSliceQpDelta                 ( 0 )
69, m_iSliceQpDeltaCb               ( 0 )
70, m_iSliceQpDeltaCr               ( 0 )
71, m_iDepth                        ( 0 )
72, m_bRefenced                     ( false )
73, m_pcSPS                         ( NULL )
74, m_pcPPS                         ( NULL )
75, m_pcPic                         ( NULL )
76, m_colFromL0Flag                 ( 1 )
77#if SETTING_NO_OUT_PIC_PRIOR
78, m_noOutputPriorPicsFlag         ( false )
79, m_noRaslOutputFlag              ( false )
80, m_handleCraAsBlaFlag            ( false )
81#endif
82, m_colRefIdx                     ( 0 )
83, m_uiTLayer                      ( 0 )
84, m_bTLayerSwitchingFlag          ( false )
85, m_sliceMode                   ( 0 )
86, m_sliceArgument               ( 0 )
87, m_sliceCurStartCUAddr         ( 0 )
88, m_sliceCurEndCUAddr           ( 0 )
89, m_sliceIdx                    ( 0 )
90, m_sliceSegmentMode            ( 0 )
91, m_sliceSegmentArgument        ( 0 )
92, m_sliceSegmentCurStartCUAddr  ( 0 )
93, m_sliceSegmentCurEndCUAddr    ( 0 )
94, m_nextSlice                    ( false )
95, m_nextSliceSegment             ( false )
96, m_sliceBits                   ( 0 )
97, m_sliceSegmentBits         ( 0 )
98, m_bFinalized                    ( false )
99, m_uiTileOffstForMultES          ( 0 )
100, m_puiSubstreamSizes             ( NULL )
101, m_cabacInitFlag                 ( false )
102, m_bLMvdL1Zero                   ( false )
103, m_numEntryPointOffsets          ( 0 )
104, m_temporalLayerNonReferenceFlag ( false )
105, m_enableTMVPFlag                ( true )
106#if SVC_EXTENSION
107, m_layerId                     ( 0 )
108#if REF_IDX_MFM
109, m_bMFMEnabledFlag               ( false )
110#endif
111#if POC_RESET_FLAG
112, m_bPocResetFlag                 ( false )
113#endif
114, m_bDiscardableFlag              ( false )
115#if O0149_CROSS_LAYER_BLA_FLAG
116, m_bCrossLayerBLAFlag            ( false )
117#endif
118#if POC_RESET_IDC_SIGNALLING
119, m_pocResetIdc                   ( 0 )
120, m_pocResetPeriodId              ( 0 )
121, m_fullPocResetFlag              ( false )
122, m_pocLsbVal                     ( 0 )
123, m_pocMsbVal                     ( 0 )
124, m_pocMsbValRequiredFlag         ( false )
125, m_pocMsbValPresentFlag          ( false )
126#endif
127#endif //SVC_EXTENSION
128{
129  m_aiNumRefIdx[0] = m_aiNumRefIdx[1] = 0;
130
131#if SVC_EXTENSION
132  memset( m_pcBaseColPic, 0, sizeof( m_pcBaseColPic ) );
133  m_activeNumILRRefIdx        = 0; 
134  m_interLayerPredEnabledFlag = 0;
135  ::memset( m_interLayerPredLayerIdc, 0, sizeof(m_interLayerPredLayerIdc) );
136#if P0312_VERT_PHASE_ADJ
137  ::memset( m_vertPhasePositionFlag, 0, sizeof(m_vertPhasePositionFlag) );
138#endif
139#endif //SVC_EXTENSION
140
141  initEqualRef();
142 
143  for (Int component = 0; component < 3; component++)
144  {
145    m_lambdas[component] = 0.0;
146  }
147 
148  for ( Int idx = 0; idx < MAX_NUM_REF; idx++ )
149  {
150    m_list1IdxToList0Idx[idx] = -1;
151  }
152  for(Int iNumCount = 0; iNumCount < MAX_NUM_REF; iNumCount++)
153  {
154    m_apcRefPicList [0][iNumCount] = NULL;
155    m_apcRefPicList [1][iNumCount] = NULL;
156    m_aiRefPOCList  [0][iNumCount] = 0;
157    m_aiRefPOCList  [1][iNumCount] = 0;
158  }
159  resetWpScaling();
160  initWpAcDcParam();
161  m_saoEnabledFlag = false;
162  m_saoEnabledFlagChroma = false;
163}
164
165TComSlice::~TComSlice()
166{
167  delete[] m_puiSubstreamSizes;
168  m_puiSubstreamSizes = NULL;
169}
170
171
172#if SVC_EXTENSION
173Void TComSlice::initSlice( UInt layerId )
174#else
175Void TComSlice::initSlice()
176#endif
177{
178#if SVC_EXTENSION
179  m_layerId = layerId;
180  m_activeNumILRRefIdx        = 0;
181  m_interLayerPredEnabledFlag = 0;
182#endif
183  m_aiNumRefIdx[0]      = 0;
184  m_aiNumRefIdx[1]      = 0;
185 
186  m_colFromL0Flag = 1;
187 
188  m_colRefIdx = 0;
189  initEqualRef();
190  m_bCheckLDC = false;
191  m_iSliceQpDeltaCb = 0;
192  m_iSliceQpDeltaCr = 0;
193
194  m_maxNumMergeCand = MRG_MAX_NUM_CANDS;
195
196  m_bFinalized=false;
197
198  m_tileByteLocation.clear();
199  m_cabacInitFlag        = false;
200  m_numEntryPointOffsets = 0;
201  m_enableTMVPFlag = true;
202}
203
204Bool TComSlice::getRapPicFlag()
205{
206  return getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL
207      || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP
208      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
209      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
210      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
211      || getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA;
212}
213#if NO_OUTPUT_OF_PRIOR_PICS
214Bool TComSlice::getBlaPicFlag       ()
215{
216    return  getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
217    || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
218    || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP;
219}
220Bool TComSlice::getCraPicFlag       ()
221{
222    return getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA;
223}
224#endif
225
226/**
227 - allocate table to contain substream sizes to be written to the slice header.
228 .
229 \param uiNumSubstreams Number of substreams -- the allocation will be this value - 1.
230 */
231Void  TComSlice::allocSubstreamSizes(UInt uiNumSubstreams)
232{
233  delete[] m_puiSubstreamSizes;
234  m_puiSubstreamSizes = new UInt[uiNumSubstreams > 0 ? uiNumSubstreams-1 : 0];
235}
236
237Void  TComSlice::sortPicList(TComList<TComPic*>& rcListPic)
238{
239  TComPic*    pcPicExtract;
240  TComPic*    pcPicInsert;
241 
242  TComList<TComPic*>::iterator    iterPicExtract;
243  TComList<TComPic*>::iterator    iterPicExtract_1;
244  TComList<TComPic*>::iterator    iterPicInsert;
245 
246  for (Int i = 1; i < (Int)(rcListPic.size()); i++)
247  {
248    iterPicExtract = rcListPic.begin();
249    for (Int j = 0; j < i; j++) iterPicExtract++;
250    pcPicExtract = *(iterPicExtract);
251    pcPicExtract->setCurrSliceIdx(0);
252   
253    iterPicInsert = rcListPic.begin();
254    while (iterPicInsert != iterPicExtract)
255    {
256      pcPicInsert = *(iterPicInsert);
257      pcPicInsert->setCurrSliceIdx(0);
258      if (pcPicInsert->getPOC() >= pcPicExtract->getPOC())
259      {
260        break;
261      }
262     
263      iterPicInsert++;
264    }
265   
266    iterPicExtract_1 = iterPicExtract;    iterPicExtract_1++;
267   
268    //  swap iterPicExtract and iterPicInsert, iterPicExtract = curr. / iterPicInsert = insertion position
269    rcListPic.insert (iterPicInsert, iterPicExtract, iterPicExtract_1);
270    rcListPic.erase  (iterPicExtract);
271  }
272}
273
274TComPic* TComSlice::xGetRefPic (TComList<TComPic*>& rcListPic,
275                                Int                 poc)
276{
277  TComList<TComPic*>::iterator  iterPic = rcListPic.begin(); 
278  TComPic*                      pcPic = *(iterPic);
279  while ( iterPic != rcListPic.end() )
280  {
281    if(pcPic->getPOC() == poc)
282    {
283      break;
284    }
285    iterPic++;
286#if SVC_EXTENSION
287    // return NULL, if picture with requested POC is not in the list, otherwise iterator goes outside of the list
288    if( iterPic == rcListPic.end() )
289    {
290      return NULL;
291    }
292#endif
293    pcPic = *(iterPic);
294  }
295#if POC_RESET_FLAG
296  assert( pcPic->getSlice(0)->isReferenced() );
297#endif
298  return  pcPic;
299}
300
301
302TComPic* TComSlice::xGetLongTermRefPic(TComList<TComPic*>& rcListPic, Int poc, Bool pocHasMsb)
303{
304  TComList<TComPic*>::iterator  iterPic = rcListPic.begin(); 
305  TComPic*                      pcPic = *(iterPic);
306  TComPic*                      pcStPic = pcPic;
307 
308  Int pocCycle = 1 << getSPS()->getBitsForPOC();
309  if (!pocHasMsb)
310  {
311    poc = poc & (pocCycle - 1);
312  }
313 
314  while ( iterPic != rcListPic.end() )
315  {
316    pcPic = *(iterPic);
317    if (pcPic && pcPic->getPOC()!=this->getPOC() && pcPic->getSlice( 0 )->isReferenced())
318    {
319      Int picPoc = pcPic->getPOC();
320      if (!pocHasMsb)
321      {
322        picPoc = picPoc & (pocCycle - 1);
323      }
324     
325#if POC_RESET_RPS
326      if( ((!pocHasMsb) && ((poc & (pocCycle-1)) == picPoc)) || ( pocHasMsb && (poc == picPoc)) )
327#else
328      if (poc == picPoc)
329#endif
330      {
331       if (pcPic->getIsLongTerm())
332      {
333        return pcPic;
334      }
335      else
336      {
337        pcStPic = pcPic;
338      }
339      break;
340    }
341    }
342
343    iterPic++;
344  }
345 
346  return  pcStPic;
347}
348
349Void TComSlice::setRefPOCList()
350{
351  for (Int iDir = 0; iDir < 2; iDir++)
352  {
353    for (Int iNumRefIdx = 0; iNumRefIdx < m_aiNumRefIdx[iDir]; iNumRefIdx++)
354    {
355      m_aiRefPOCList[iDir][iNumRefIdx] = m_apcRefPicList[iDir][iNumRefIdx]->getPOC();
356    }
357  }
358
359}
360
361Void TComSlice::setList1IdxToList0Idx()
362{
363  Int idxL0, idxL1;
364  for ( idxL1 = 0; idxL1 < getNumRefIdx( REF_PIC_LIST_1 ); idxL1++ )
365  {
366    m_list1IdxToList0Idx[idxL1] = -1;
367    for ( idxL0 = 0; idxL0 < getNumRefIdx( REF_PIC_LIST_0 ); idxL0++ )
368    {
369      if ( m_apcRefPicList[REF_PIC_LIST_0][idxL0]->getPOC() == m_apcRefPicList[REF_PIC_LIST_1][idxL1]->getPOC() )
370      {
371        m_list1IdxToList0Idx[idxL1] = idxL0;
372        break;
373      }
374    }
375  }
376}
377
378#if SVC_EXTENSION
379Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr, TComPic** ilpPic)
380#else
381Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr )
382#endif
383{
384  if (!checkNumPocTotalCurr)
385  {
386    if (m_eSliceType == I_SLICE)
387    {
388      ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
389      ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
390     
391      return;
392    }
393 
394    m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
395    m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
396  }
397
398  TComPic*  pcRefPic= NULL;
399  TComPic*  RefPicSetStCurr0[16];
400  TComPic*  RefPicSetStCurr1[16];
401  TComPic*  RefPicSetLtCurr[16];
402  UInt NumPocStCurr0 = 0;
403  UInt NumPocStCurr1 = 0;
404  UInt NumPocLtCurr = 0;
405  Int i;
406
407#if SVC_EXTENSION
408  if( m_layerId == 0 || ( m_layerId > 0 && ( m_activeNumILRRefIdx == 0 || !((getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP) && (getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA)) ) ) )
409  {
410#endif
411  for(i=0; i < m_pcRPS->getNumberOfNegativePictures(); i++)
412  {
413    if(m_pcRPS->getUsed(i))
414    {
415      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
416      pcRefPic->setIsLongTerm(0);
417      pcRefPic->getPicYuvRec()->extendPicBorder();
418      RefPicSetStCurr0[NumPocStCurr0] = pcRefPic;
419      NumPocStCurr0++;
420      pcRefPic->setCheckLTMSBPresent(false); 
421    }
422  }
423 
424  for(; i < m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures(); i++)
425  {
426    if(m_pcRPS->getUsed(i))
427    {
428      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
429      pcRefPic->setIsLongTerm(0);
430      pcRefPic->getPicYuvRec()->extendPicBorder();
431      RefPicSetStCurr1[NumPocStCurr1] = pcRefPic;
432      NumPocStCurr1++;
433      pcRefPic->setCheckLTMSBPresent(false); 
434    }
435  }
436 
437  for(i = m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()+m_pcRPS->getNumberOfLongtermPictures()-1; i > m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()-1 ; i--)
438  {
439    if(m_pcRPS->getUsed(i))
440    {
441      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
442      pcRefPic->setIsLongTerm(1);
443      pcRefPic->getPicYuvRec()->extendPicBorder();
444      RefPicSetLtCurr[NumPocLtCurr] = pcRefPic;
445      NumPocLtCurr++;
446    }
447    if(pcRefPic==NULL) 
448    {
449      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
450    }
451    pcRefPic->setCheckLTMSBPresent(m_pcRPS->getCheckLTMSBPresent(i)); 
452  }
453#if SVC_EXTENSION
454  }
455#endif
456
457#if SVC_EXTENSION
458  for( i = 0; i < m_activeNumILRRefIdx; i++ )
459  {
460    UInt refLayerIdc = m_interLayerPredLayerIdc[i];
461    //inter-layer reference picture
462#if O0225_MAX_TID_FOR_REF_LAYERS
463    Int maxTidIlRefPicsPlus1 = ( m_layerId > 0 && m_activeNumILRRefIdx > 0)? m_pcVPS->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId(),m_layerId) : 0;
464#else
465    Int maxTidIlRefPicsPlus1 = ( m_layerId > 0 && m_activeNumILRRefIdx > 0)? m_pcVPS->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId()) : 0;
466#endif
467    if( m_layerId > 0 && m_activeNumILRRefIdx > 0 && ( ( (Int)(ilpPic[refLayerIdc]->getSlice(0)->getTLayer())<=  maxTidIlRefPicsPlus1-1) || (maxTidIlRefPicsPlus1==0 && ilpPic[refLayerIdc]->getSlice(0)->getRapPicFlag()) )  ) 
468    {
469#if REF_IDX_MFM
470      if(!(m_eNalUnitType >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_eNalUnitType <= NAL_UNIT_CODED_SLICE_CRA) && getMFMEnabledFlag())
471      { 
472        ilpPic[refLayerIdc]->copyUpsampledMvField( refLayerIdc, m_pcBaseColPic[refLayerIdc] );
473      }
474      else
475      {
476        ilpPic[refLayerIdc]->initUpsampledMvField();
477      }
478#endif
479      ilpPic[refLayerIdc]->setIsLongTerm(1);
480    }
481  }
482#endif
483  // ref_pic_list_init
484  TComPic*  rpsCurrList0[MAX_NUM_REF+1];
485  TComPic*  rpsCurrList1[MAX_NUM_REF+1];
486#if SVC_EXTENSION
487  Int numInterLayerRPSPics = 0;
488#if M0040_ADAPTIVE_RESOLUTION_CHANGE
489  if( m_layerId > 0 && m_activeNumILRRefIdx > 0 )
490#else
491  if( m_layerId > 0 )
492#endif
493  {
494    for( i=0; i < m_pcVPS->getNumDirectRefLayers( m_layerId ); i++ )
495    {
496#if O0225_MAX_TID_FOR_REF_LAYERS
497      Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[i]->getSlice(0)->getLayerId(),m_layerId);
498#else
499      Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[i]->getSlice(0)->getLayerId());
500#endif
501      if( ((Int)(ilpPic[i]->getSlice(0)->getTLayer())<= maxTidIlRefPicsPlus1-1) || (maxTidIlRefPicsPlus1==0 && ilpPic[i]->getSlice(0)->getRapPicFlag() ) )
502      {
503        numInterLayerRPSPics++;
504#if DISCARDABLE_PIC_RPS
505        assert( ilpPic[i]->getSlice(0)->getDiscardableFlag() == 0 );    // Inter-layer RPS shall not contain picture with discardable_flag = 1.
506#endif
507      }
508    }
509    if (numInterLayerRPSPics < m_activeNumILRRefIdx)
510    {
511      m_activeNumILRRefIdx = numInterLayerRPSPics;
512    }
513#if MAX_ONE_RESAMPLING_DIRECT_LAYERS
514#if SCALABILITY_MASK_E0104
515    if( m_pcVPS->getScalabilityMask(2) )
516#else
517    if( m_pcVPS->getScalabilityMask(1) )
518#endif
519    {
520      Int numResampler = 0;
521#if MOTION_RESAMPLING_CONSTRAINT
522      Int numMotionResamplers = 0;
523      Int refResamplingLayer[MAX_LAYERS];
524      memset( refResamplingLayer, 0, sizeof( refResamplingLayer ) );
525#endif
526#if !RESAMPLING_CONSTRAINT_BUG_FIX
527      const Window &scalEL = getSPS()->getScaledRefLayerWindow(m_interLayerPredLayerIdc[i]);
528      Int scalingOffset = ((scalEL.getWindowLeftOffset()   == 0 ) && 
529                           (scalEL.getWindowRightOffset()  == 0 ) && 
530                           (scalEL.getWindowTopOffset()    == 0 ) && 
531                           (scalEL.getWindowBottomOffset() == 0 ) 
532                          );
533#endif
534
535      for( i=0; i < m_activeNumILRRefIdx; i++ )
536      {
537        UInt refLayerIdc = m_interLayerPredLayerIdc[i];
538        UInt refLayerId = m_pcVPS->getRefLayerId( m_layerId, refLayerIdc );
539#if RESAMPLING_CONSTRAINT_BUG_FIX
540#if O0098_SCALED_REF_LAYER_ID
541        const Window &scalEL = getSPS()->getScaledRefLayerWindowForLayer(refLayerId);
542#else
543        const Window &scalEL = getSPS()->getScaledRefLayerWindow(m_interLayerPredLayerIdc[i]);
544#endif
545        Int scalingOffset = ((scalEL.getWindowLeftOffset()   == 0 ) && 
546                             (scalEL.getWindowRightOffset()  == 0 ) && 
547                             (scalEL.getWindowTopOffset()    == 0 ) && 
548                             (scalEL.getWindowBottomOffset() == 0 ) 
549                            );
550#endif
551#if O0194_DIFFERENT_BITDEPTH_EL_BL
552        Bool sameBitDepths = ( g_bitDepthYLayer[m_layerId] == g_bitDepthYLayer[refLayerId] ) && ( g_bitDepthCLayer[m_layerId] == g_bitDepthCLayer[refLayerId] );
553
554        if( !( g_posScalingFactor[refLayerIdc][0] == 65536 && g_posScalingFactor[refLayerIdc][1] == 65536 ) || !scalingOffset || !sameBitDepths
555#if Q0048_CGS_3D_ASYMLUT
556          || getPPS()->getCGSFlag()
557#endif
558          ) // ratio 1x
559#else
560        if(!( g_posScalingFactor[refLayerIdc][0] == 65536 && g_posScalingFactor[refLayerIdc][1] == 65536 ) || (!scalingOffset)) // ratio 1x
561#endif
562        {
563#if MOTION_RESAMPLING_CONSTRAINT
564          UInt predType = m_pcVPS->getDirectDependencyType( m_layerId, refLayerId ) + 1;
565
566          if( predType & 0x1 )
567          {
568            numResampler++;
569            refResamplingLayer[i] = refLayerIdc + 1;
570          }
571
572          if( predType & 0x2 )
573          {
574            numMotionResamplers++;
575            refResamplingLayer[i] -= refLayerIdc + 1;
576          }
577#else
578          numResampler++;
579#endif
580        }
581      }
582     
583      // When both picture sample values and picture motion field resampling processes are invoked for decoding of a particular picture, they shall be applied to the same reference layer picture.
584      if( m_activeNumILRRefIdx > 1 && numResampler > 0 )
585      {
586        for( i=0; i < m_activeNumILRRefIdx; i++ )
587        {
588          assert( refResamplingLayer[i] >= 0 && "Motion and sample inter-layer prediction shall be from the same layer" );
589        }
590      }
591
592      // Bitstream constraint for SHVC: The picture resampling process as specified in subclause G.8.1.4.1 shall not be invoked more than once for decoding of each particular picture.
593      assert(numResampler <= 1);
594#if MOTION_RESAMPLING_CONSTRAINT
595      assert( numMotionResamplers <= 1  && "Up to 1 motion resampling is allowed" );
596#endif
597    }
598#endif
599  }
600  Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr + m_activeNumILRRefIdx;
601#else //SVC_EXTENSION
602  Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr;
603#endif //SVC_EXTENSION
604
605  if (checkNumPocTotalCurr)
606  {
607    // The variable NumPocTotalCurr is derived as specified in subclause 7.4.7.2. It is a requirement of bitstream conformance that the following applies to the value of NumPocTotalCurr:
608#if SVC_EXTENSION    // inter-layer prediction is allowed for BLA, CRA pictures of nuh_layer_id>0
609    // - If the current picture is a BLA or CRA picture with nuh_layer_id equal to 0, the value of NumPocTotalCurr shall be equal to 0.
610    // - Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
611    if (getRapPicFlag() && getLayerId()==0)
612#else
613    // - If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
614    // - Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
615    if (getRapPicFlag())
616#endif
617    {
618      assert(numPocTotalCurr == 0);
619    }
620
621    if (m_eSliceType == I_SLICE)
622    {
623      ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
624      ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
625
626      return;
627    }
628
629    assert(numPocTotalCurr > 0);
630
631    m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
632    m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
633  }
634
635    Int cIdx = 0;
636    for ( i=0; i<NumPocStCurr0; i++, cIdx++)
637    {
638      rpsCurrList0[cIdx] = RefPicSetStCurr0[i];
639    }
640#if SVC_EXTENSION
641#if RPL_INIT_N0316_N0082
642    if( m_layerId > 0 )
643    {     
644      for( i = 0; i < m_activeNumILRRefIdx && cIdx < numPocTotalCurr; cIdx ++, i ++)     
645      {
646        Int refLayerIdc = m_interLayerPredLayerIdc[i];
647#if O0225_MAX_TID_FOR_REF_LAYERS
648        Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId(),m_layerId);
649#else
650        Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId());
651#endif
652        if( ((Int)(ilpPic[refLayerIdc]->getSlice(0)->getTLayer())<=maxTidIlRefPicsPlus1-1) || (maxTidIlRefPicsPlus1==0 && ilpPic[refLayerIdc]->getSlice(0)->getRapPicFlag()) )
653        {
654          rpsCurrList0[cIdx] = ilpPic[refLayerIdc];
655        }
656      }
657    }
658#endif
659#endif //SVC_EXTENSION
660    for ( i=0; i<NumPocStCurr1; i++, cIdx++)
661    {
662      rpsCurrList0[cIdx] = RefPicSetStCurr1[i];
663    }
664    for ( i=0; i<NumPocLtCurr;  i++, cIdx++)
665    {
666      rpsCurrList0[cIdx] = RefPicSetLtCurr[i];
667    }   
668#if !RPL_INIT_N0316_N0082
669#if SVC_EXTENSION
670    if( m_layerId > 0 )
671    {
672      for( i = 0; i < m_activeNumILRRefIdx && cIdx < numPocTotalCurr; cIdx ++, i ++)     
673      {
674        Int refLayerIdc = m_interLayerPredLayerIdc[i];
675#if O0225_MAX_TID_FOR_REF_LAYERS
676        Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId(),m_layerId);
677#else
678        Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId());
679#endif
680        if( ((Int)(ilpPic[refLayerIdc]->getSlice(0)->getTLayer())<=maxTidIlRefPicsPlus1-1) || (maxTidIlRefPicsPlus1==0 && ilpPic[refLayerIdc]->getSlice(0)->getRapPicFlag()) )
681        {
682          rpsCurrList0[cIdx] = ilpPic[refLayerIdc];
683        }
684      }
685    }
686#endif
687#endif
688  assert(cIdx == numPocTotalCurr);
689
690  if (m_eSliceType==B_SLICE)
691  {
692    cIdx = 0;
693    for ( i=0; i<NumPocStCurr1; i++, cIdx++)
694    {
695      rpsCurrList1[cIdx] = RefPicSetStCurr1[i];
696    }
697    for ( i=0; i<NumPocStCurr0; i++, cIdx++)
698    {
699      rpsCurrList1[cIdx] = RefPicSetStCurr0[i];
700    }
701    for ( i=0; i<NumPocLtCurr;  i++, cIdx++)
702    {
703      rpsCurrList1[cIdx] = RefPicSetLtCurr[i];
704    }   
705
706#if SVC_EXTENSION
707    if( m_layerId > 0 )
708    {
709      for( i = 0; i < m_activeNumILRRefIdx && cIdx < numPocTotalCurr; cIdx ++, i ++)
710      {
711        Int refLayerIdc = m_interLayerPredLayerIdc[i];
712#if O0225_MAX_TID_FOR_REF_LAYERS
713        Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId(),m_layerId);
714#else
715        Int maxTidIlRefPicsPlus1 = getVPS()->getMaxTidIlRefPicsPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId());
716#endif
717        if( ((Int)(ilpPic[refLayerIdc]->getSlice(0)->getTLayer())<=maxTidIlRefPicsPlus1-1) || (maxTidIlRefPicsPlus1==0 && ilpPic[refLayerIdc]->getSlice(0)->getRapPicFlag()) )
718        {
719          rpsCurrList1[cIdx] = ilpPic[refLayerIdc];
720        }
721      }
722    }
723#endif //SVC_EXTENSION
724
725    assert(cIdx == numPocTotalCurr);
726  }
727
728  ::memset(m_bIsUsedAsLongTerm, 0, sizeof(m_bIsUsedAsLongTerm));
729
730  for (Int rIdx = 0; rIdx < m_aiNumRefIdx[0]; rIdx ++)
731  {
732    cIdx = m_RefPicListModification.getRefPicListModificationFlagL0() ? m_RefPicListModification.getRefPicSetIdxL0(rIdx) : rIdx % numPocTotalCurr;
733    assert(cIdx >= 0 && cIdx < numPocTotalCurr);
734    m_apcRefPicList[0][rIdx] = rpsCurrList0[ cIdx ];
735#if RPL_INIT_N0316_N0082
736    m_bIsUsedAsLongTerm[0][rIdx] = ( cIdx >= NumPocStCurr0 && cIdx < NumPocStCurr0 + m_activeNumILRRefIdx ) || ( cIdx >= NumPocStCurr0 + NumPocStCurr1 + m_activeNumILRRefIdx );
737#else
738    m_bIsUsedAsLongTerm[0][rIdx] = ( cIdx >= NumPocStCurr0 + NumPocStCurr1 );
739#endif
740  }
741  if ( m_eSliceType != B_SLICE )
742  {
743    m_aiNumRefIdx[1] = 0;
744    ::memset( m_apcRefPicList[1], 0, sizeof(m_apcRefPicList[1]));
745  }
746  else
747  {
748    for (Int rIdx = 0; rIdx < m_aiNumRefIdx[1]; rIdx ++)
749    {
750      cIdx = m_RefPicListModification.getRefPicListModificationFlagL1() ? m_RefPicListModification.getRefPicSetIdxL1(rIdx) : rIdx % numPocTotalCurr;
751      assert(cIdx >= 0 && cIdx < numPocTotalCurr);
752      m_apcRefPicList[1][rIdx] = rpsCurrList1[ cIdx ];
753      m_bIsUsedAsLongTerm[1][rIdx] = ( cIdx >= NumPocStCurr0 + NumPocStCurr1 );
754    }
755  }
756}
757
758#if SVC_EXTENSION
759Void TComSlice::setRefPicListModificationSvc()
760{
761  if( !m_pcPPS->getListsModificationPresentFlag()) 
762  {
763    return;
764  }
765
766  if(m_eNalUnitType >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_eNalUnitType <= NAL_UNIT_CODED_SLICE_CRA)
767  {
768    return;
769  }
770
771  TComRefPicListModification* refPicListModification = &m_RefPicListModification;
772  Int numberOfRpsCurrTempList = this->getNumRpsCurrTempList();  // total number of ref pics in listTemp0 including inter-layer ref pics
773#if RPL_INIT_N0316_N0082
774  Int numberOfPocBeforeCurr = this->getNumNegativeRpsCurrTempList();  // number of negative temporal ref pics
775#endif
776
777#if N0147_IRAP_ALIGN_FLAG
778  assert(m_aiNumRefIdx[REF_PIC_LIST_0] > 0);
779  assert(m_aiNumRefIdx[REF_PIC_LIST_1] > 0);
780#else
781  assert(m_aiNumRefIdx[REF_PIC_LIST_0] > 1);
782  assert(m_aiNumRefIdx[REF_PIC_LIST_1] > 1);
783#endif
784
785  //set L0 inter-layer reference picture modification
786#if RPL_INIT_N0316_N0082
787  Bool hasModification = (m_aiNumRefIdx[REF_PIC_LIST_0] >= (numberOfPocBeforeCurr + m_activeNumILRRefIdx)) ? false : true;
788#else
789  Bool hasModification = (m_aiNumRefIdx[REF_PIC_LIST_0] == numberOfRpsCurrTempList) ? false : true;
790#endif
791#if N0147_IRAP_ALIGN_FLAG
792  hasModification = hasModification && ( m_aiNumRefIdx[REF_PIC_LIST_0] > 1 );
793#endif
794  refPicListModification->setRefPicListModificationFlagL0(hasModification);
795  if(hasModification)
796  { 
797    for(Int i = 0; i < min(m_aiNumRefIdx[REF_PIC_LIST_0], numberOfRpsCurrTempList); i++)
798    {
799      refPicListModification->setRefPicSetIdxL0(i, i);
800    }
801
802    if(m_aiNumRefIdx[REF_PIC_LIST_0] > numberOfRpsCurrTempList)
803    {
804      // repeat last ref pic when the number of active ref idx are more than RPS entries
805      for (Int i = numberOfRpsCurrTempList; i < m_aiNumRefIdx[REF_PIC_LIST_0]; i ++)
806      {
807        refPicListModification->setRefPicSetIdxL0(i, numberOfRpsCurrTempList - 1);
808      }
809    }
810    else
811    {
812      // number of ILRPs included into the reference picture list with the list modification
813      Int includeNumILRP = min( max(1, m_aiNumRefIdx[REF_PIC_LIST_0]-numberOfPocBeforeCurr), m_activeNumILRRefIdx);
814
815      for(Int i = includeNumILRP; i > 0; i-- )
816      {
817#if RPL_INIT_N0316_N0082
818        if((numberOfPocBeforeCurr) >= m_aiNumRefIdx[REF_PIC_LIST_0])
819        {
820          refPicListModification->setRefPicSetIdxL0(m_aiNumRefIdx[REF_PIC_LIST_0] - i, numberOfPocBeforeCurr + includeNumILRP - i);
821        }
822        else
823        {
824          refPicListModification->setRefPicSetIdxL0(m_aiNumRefIdx[REF_PIC_LIST_0] - i, numberOfPocBeforeCurr + includeNumILRP - i);
825          for (Int j = numberOfPocBeforeCurr; j < (m_aiNumRefIdx[REF_PIC_LIST_0] - i); j++)
826          {
827            assert( j + includeNumILRP < numberOfRpsCurrTempList );
828            refPicListModification->setRefPicSetIdxL0(j, j + includeNumILRP);
829          }
830        }
831#else
832        refPicListModification->setRefPicSetIdxL0(m_aiNumRefIdx[REF_PIC_LIST_0] - i, numberOfRpsCurrTempList - i);
833#endif
834      }
835    }
836  }
837
838  //set L1 inter-layer reference picture modification
839  hasModification = (m_aiNumRefIdx[REF_PIC_LIST_1] >= numberOfRpsCurrTempList) ? false : true;
840#if N0147_IRAP_ALIGN_FLAG
841  hasModification = hasModification && ( m_aiNumRefIdx[REF_PIC_LIST_1] > 1 );
842#endif
843
844  refPicListModification->setRefPicListModificationFlagL1(hasModification);
845  if(hasModification)
846  { 
847    for(Int i = 0; i < min(m_aiNumRefIdx[REF_PIC_LIST_1], numberOfRpsCurrTempList); i++)
848    {
849      refPicListModification->setRefPicSetIdxL1(i, i);
850    }
851    if(m_aiNumRefIdx[REF_PIC_LIST_1] > numberOfRpsCurrTempList)
852    {
853      for (Int i = numberOfRpsCurrTempList; i < m_aiNumRefIdx[REF_PIC_LIST_1]; i ++)
854      {
855        // repeat last ref pic when the number of active ref idx are more than RPS entries
856        refPicListModification->setRefPicSetIdxL1(i, numberOfRpsCurrTempList - 1); 
857      }
858    }
859    else
860    {
861      Int includeNumILRP = min(m_aiNumRefIdx[REF_PIC_LIST_1], m_activeNumILRRefIdx);
862
863      for(Int i = includeNumILRP; i > 0; i-- )
864      {
865        refPicListModification->setRefPicSetIdxL1(m_aiNumRefIdx[REF_PIC_LIST_1] - i, numberOfRpsCurrTempList - i);
866      }
867    }
868  }
869  return;
870}
871#endif
872#if RPL_INIT_N0316_N0082
873Int TComSlice::getNumNegativeRpsCurrTempList()
874{
875  if( m_eSliceType == I_SLICE ) 
876  {
877    return 0;
878  }
879
880  Int numPocBeforeCurr = 0;
881  for( UInt i = 0; i < m_pcRPS->getNumberOfNegativePictures(); i++ )
882  {
883    if(m_pcRPS->getUsed(i))
884    {
885      numPocBeforeCurr++;
886    }
887  }
888
889  return numPocBeforeCurr;
890}
891#endif
892Int TComSlice::getNumRpsCurrTempList()
893{
894  Int numRpsCurrTempList = 0;
895
896#if SVC_EXTENSION
897  if( m_eSliceType == I_SLICE || ( m_layerId && 
898    (m_eNalUnitType >= NAL_UNIT_CODED_SLICE_BLA_W_LP) &&
899    (m_eNalUnitType <= NAL_UNIT_CODED_SLICE_CRA) ) )
900#else
901  if (m_eSliceType == I_SLICE) 
902#endif
903  {
904#if SVC_EXTENSION
905    return m_activeNumILRRefIdx;
906#else
907    return 0;
908#endif
909  }
910  for(UInt i=0; i < m_pcRPS->getNumberOfNegativePictures()+ m_pcRPS->getNumberOfPositivePictures() + m_pcRPS->getNumberOfLongtermPictures(); i++)
911  {
912    if(m_pcRPS->getUsed(i))
913    {
914      numRpsCurrTempList++;
915    }
916  }
917#if SVC_EXTENSION
918  if( m_layerId > 0 )
919  {
920    numRpsCurrTempList += m_activeNumILRRefIdx;
921  }
922#endif
923
924  return numRpsCurrTempList;
925}
926
927Void TComSlice::initEqualRef()
928{
929  for (Int iDir = 0; iDir < 2; iDir++)
930  {
931    for (Int iRefIdx1 = 0; iRefIdx1 < MAX_NUM_REF; iRefIdx1++)
932    {
933      for (Int iRefIdx2 = iRefIdx1; iRefIdx2 < MAX_NUM_REF; iRefIdx2++)
934      {
935        m_abEqualRef[iDir][iRefIdx1][iRefIdx2] = m_abEqualRef[iDir][iRefIdx2][iRefIdx1] = (iRefIdx1 == iRefIdx2? true : false);
936      }
937    }
938  }
939}
940
941Void TComSlice::checkColRefIdx(UInt curSliceIdx, TComPic* pic)
942{
943  Int i;
944  TComSlice* curSlice = pic->getSlice(curSliceIdx);
945  Int currColRefPOC =  curSlice->getRefPOC( RefPicList(1-curSlice->getColFromL0Flag()), curSlice->getColRefIdx());
946  TComSlice* preSlice;
947  Int preColRefPOC;
948  for(i=curSliceIdx-1; i>=0; i--)
949  {
950    preSlice = pic->getSlice(i);
951    if(preSlice->getSliceType() != I_SLICE)
952    {
953      preColRefPOC  = preSlice->getRefPOC( RefPicList(1-preSlice->getColFromL0Flag()), preSlice->getColRefIdx());
954      if(currColRefPOC != preColRefPOC)
955      {
956        printf("Collocated_ref_idx shall always be the same for all slices of a coded picture!\n");
957        exit(EXIT_FAILURE);
958      }
959      else
960      {
961        break;
962      }
963    }
964  }
965}
966
967Void TComSlice::checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, NalUnitType& associatedIRAPType, TComList<TComPic *>& rcListPic)
968{
969  for(Int i = 0; i < pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures(); i++)
970  {
971    if(pocCRA < MAX_UINT && getPOC() > pocCRA)
972    {
973      assert(getPOC()+pReferencePictureSet->getDeltaPOC(i) >= pocCRA);
974    }
975  }
976  for(Int i = pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures(); i < pReferencePictureSet->getNumberOfPictures(); i++)
977  {
978    if(pocCRA < MAX_UINT && getPOC() > pocCRA)
979    {
980      if (!pReferencePictureSet->getCheckLTMSBPresent(i))
981      {
982        assert(xGetLongTermRefPic(rcListPic, pReferencePictureSet->getPOC(i), false)->getPOC() >= pocCRA);
983      }
984      else
985      {
986      assert(pReferencePictureSet->getPOC(i) >= pocCRA);
987    }
988  }
989  }
990  if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP ) // IDR picture found
991  {
992    pocCRA = getPOC();
993    associatedIRAPType = getNalUnitType();
994  }
995  else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found
996  {
997    pocCRA = getPOC();
998    associatedIRAPType = getNalUnitType();
999  }
1000  else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1001         || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
1002         || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP ) // BLA picture found
1003  {
1004    pocCRA = getPOC();
1005    associatedIRAPType = getNalUnitType();
1006  }
1007}
1008
1009/** Function for marking the reference pictures when an IDR/CRA/CRANT/BLA/BLANT is encountered.
1010 * \param pocCRA POC of the CRA/CRANT/BLA/BLANT picture
1011 * \param bRefreshPending flag indicating if a deferred decoding refresh is pending
1012 * \param rcListPic reference to the reference picture list
1013 * This function marks the reference pictures as "unused for reference" in the following conditions.
1014 * If the nal_unit_type is IDR/BLA/BLANT, all pictures in the reference picture list 
1015 * are marked as "unused for reference"
1016 *    If the nal_unit_type is BLA/BLANT, set the pocCRA to the temporal reference of the current picture.
1017 * Otherwise
1018 *    If the bRefreshPending flag is true (a deferred decoding refresh is pending) and the current
1019 *    temporal reference is greater than the temporal reference of the latest CRA/CRANT/BLA/BLANT picture (pocCRA),
1020 *    mark all reference pictures except the latest CRA/CRANT/BLA/BLANT picture as "unused for reference" and set
1021 *    the bRefreshPending flag to false.
1022 *    If the nal_unit_type is CRA/CRANT, set the bRefreshPending flag to true and pocCRA to the temporal
1023 *    reference of the current picture.
1024 * Note that the current picture is already placed in the reference list and its marking is not changed.
1025 * If the current picture has a nal_ref_idc that is not 0, it will remain marked as "used for reference".
1026 */
1027#if NO_CLRAS_OUTPUT_FLAG
1028Void TComSlice::decodingRefreshMarking( TComList<TComPic*>& rcListPic, Bool noClrasOutputFlag )
1029{
1030  if( !isIRAP() )
1031  {
1032    return;
1033  }
1034
1035  Int pocCurr = getPOC();
1036  TComPic* rpcPic = NULL;
1037
1038  // When the current picture is an IRAP picture with nuh_layer_id equal to 0 and NoClrasOutputFlag is equal to 1,
1039  // all reference pictures with any value of nuh_layer_id currently in the DPB (if any) are marked as "unused for reference".
1040  if( m_layerId == 0 && noClrasOutputFlag )
1041  {
1042    // mark all pictures for all layers as not used for reference
1043    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1044    while( iterPic != rcListPic.end() )
1045    {
1046      rpcPic = *(iterPic);
1047      if( rpcPic->getPOC() != pocCurr )
1048      {
1049        rpcPic->getSlice(0)->setReferenced(false);
1050      }
1051      iterPic++;
1052    }
1053  }
1054
1055  // When the current picture is an IRAP picture with NoRaslOutputFlag equal to 1,
1056  // all reference pictures with nuh_layer_id equal to currPicLayerId currently in the DPB (if any) are marked as "unused for reference".
1057  if( m_noRaslOutputFlag )
1058  {
1059    // mark all pictures of a current layer as not used for reference
1060    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1061    while( iterPic != rcListPic.end() )
1062    {
1063      rpcPic = *(iterPic);
1064      if( rpcPic->getPOC() != pocCurr && rpcPic->getLayerId() == m_layerId )
1065      {
1066        rpcPic->getSlice(0)->setReferenced(false);
1067      }
1068      iterPic++;
1069    }
1070  }
1071}
1072
1073Void TComSlice::decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic, Bool noClrasOutputFlag)
1074#else
1075Void TComSlice::decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic)
1076#endif
1077{
1078  TComPic*                 rpcPic;
1079#if !FIX1172
1080  setAssociatedIRAPPOC(pocCRA);
1081#endif
1082  Int pocCurr = getPOC(); 
1083
1084  if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1085    || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
1086    || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
1087    || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL
1088    || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )  // IDR or BLA picture
1089  {
1090    // mark all pictures as not used for reference
1091    TComList<TComPic*>::iterator        iterPic       = rcListPic.begin();
1092    while (iterPic != rcListPic.end())
1093    {
1094      rpcPic = *(iterPic);
1095      rpcPic->setCurrSliceIdx(0);
1096#if NO_CLRAS_OUTPUT_FLAG
1097      if (noClrasOutputFlag)
1098      {
1099        if (rpcPic->getPOC() != pocCurr) rpcPic->getSlice(0)->setReferenced(false);  // all layers
1100      }
1101      else
1102      {
1103        if (rpcPic->getPOC() != pocCurr && rpcPic->getLayerId() == m_layerId) rpcPic->getSlice(0)->setReferenced(false);  // only current layer
1104      }
1105#else
1106      if (rpcPic->getPOC() != pocCurr) rpcPic->getSlice(0)->setReferenced(false);
1107#endif
1108      iterPic++;
1109    }
1110    if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
1111      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
1112      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
1113    {
1114      pocCRA = pocCurr;
1115    }
1116#if EFFICIENT_FIELD_IRAP
1117    bRefreshPending = true;
1118#endif
1119  }
1120  else // CRA or No DR
1121  {
1122#if EFFICIENT_FIELD_IRAP
1123    if(getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_IDR_N_LP || getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL)
1124    {
1125      if (bRefreshPending==true && pocCurr > m_iLastIDR) // IDR reference marking pending
1126      {
1127        TComList<TComPic*>::iterator        iterPic       = rcListPic.begin();
1128        while (iterPic != rcListPic.end())
1129        {
1130          rpcPic = *(iterPic);
1131          if (rpcPic->getPOC() != pocCurr && rpcPic->getPOC() != m_iLastIDR)
1132          {
1133            rpcPic->getSlice(0)->setReferenced(false);
1134          }
1135          iterPic++;
1136        }
1137        bRefreshPending = false; 
1138      }
1139    }
1140    else
1141    {
1142#endif
1143    if (bRefreshPending==true && pocCurr > pocCRA) // CRA reference marking pending
1144    {
1145      TComList<TComPic*>::iterator        iterPic       = rcListPic.begin();
1146      while (iterPic != rcListPic.end())
1147      {
1148        rpcPic = *(iterPic);
1149        if (rpcPic->getPOC() != pocCurr && rpcPic->getPOC() != pocCRA)
1150        {
1151          rpcPic->getSlice(0)->setReferenced(false);
1152        }
1153        iterPic++;
1154      }
1155      bRefreshPending = false; 
1156    }
1157#if EFFICIENT_FIELD_IRAP
1158    }
1159#endif
1160    if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found
1161    {
1162      bRefreshPending = true; 
1163      pocCRA = pocCurr;
1164    }
1165  }
1166}
1167
1168Void TComSlice::copySliceInfo(TComSlice *pSrc)
1169{
1170  assert( pSrc != NULL );
1171
1172  Int i, j, k;
1173
1174  m_iPOC                 = pSrc->m_iPOC;
1175  m_eNalUnitType         = pSrc->m_eNalUnitType;
1176  m_eSliceType           = pSrc->m_eSliceType;
1177  m_iSliceQp             = pSrc->m_iSliceQp;
1178#if ADAPTIVE_QP_SELECTION
1179  m_iSliceQpBase         = pSrc->m_iSliceQpBase;
1180#endif
1181  m_deblockingFilterDisable   = pSrc->m_deblockingFilterDisable;
1182  m_deblockingFilterOverrideFlag = pSrc->m_deblockingFilterOverrideFlag;
1183  m_deblockingFilterBetaOffsetDiv2 = pSrc->m_deblockingFilterBetaOffsetDiv2;
1184  m_deblockingFilterTcOffsetDiv2 = pSrc->m_deblockingFilterTcOffsetDiv2;
1185 
1186  for (i = 0; i < 2; i++)
1187  {
1188    m_aiNumRefIdx[i]     = pSrc->m_aiNumRefIdx[i];
1189  }
1190
1191  for (i = 0; i < MAX_NUM_REF; i++)
1192  {
1193    m_list1IdxToList0Idx[i] = pSrc->m_list1IdxToList0Idx[i];
1194  } 
1195  m_bCheckLDC             = pSrc->m_bCheckLDC;
1196  m_iSliceQpDelta        = pSrc->m_iSliceQpDelta;
1197  m_iSliceQpDeltaCb      = pSrc->m_iSliceQpDeltaCb;
1198  m_iSliceQpDeltaCr      = pSrc->m_iSliceQpDeltaCr;
1199  for (i = 0; i < 2; i++)
1200  {
1201    for (j = 0; j < MAX_NUM_REF; j++)
1202    {
1203      m_apcRefPicList[i][j]  = pSrc->m_apcRefPicList[i][j];
1204      m_aiRefPOCList[i][j]   = pSrc->m_aiRefPOCList[i][j];
1205    }
1206  }
1207  for (i = 0; i < 2; i++)
1208  {
1209    for (j = 0; j < MAX_NUM_REF + 1; j++)
1210    {
1211      m_bIsUsedAsLongTerm[i][j] = pSrc->m_bIsUsedAsLongTerm[i][j];
1212    }
1213  }
1214  m_iDepth               = pSrc->m_iDepth;
1215
1216  // referenced slice
1217  m_bRefenced            = pSrc->m_bRefenced;
1218
1219  // access channel
1220#if SVC_EXTENSION
1221  m_pcVPS                = pSrc->m_pcVPS;
1222  m_layerId              = pSrc->m_layerId;
1223  m_activeNumILRRefIdx         = pSrc->m_activeNumILRRefIdx;
1224  m_interLayerPredEnabledFlag  = pSrc->m_interLayerPredEnabledFlag;
1225  memcpy( m_interLayerPredLayerIdc, pSrc->m_interLayerPredLayerIdc, sizeof( m_interLayerPredLayerIdc ) );
1226#if P0312_VERT_PHASE_ADJ
1227  memcpy( m_vertPhasePositionFlag, pSrc->m_vertPhasePositionFlag, sizeof( m_vertPhasePositionFlag ) );
1228#endif
1229#endif
1230  m_pcSPS                = pSrc->m_pcSPS;
1231  m_pcPPS                = pSrc->m_pcPPS;
1232  m_pcRPS                = pSrc->m_pcRPS;
1233  m_iLastIDR             = pSrc->m_iLastIDR;
1234
1235  m_pcPic                = pSrc->m_pcPic;
1236
1237  m_colFromL0Flag        = pSrc->m_colFromL0Flag;
1238  m_colRefIdx            = pSrc->m_colRefIdx;
1239  setLambdas(pSrc->getLambdas());
1240  for (i = 0; i < 2; i++)
1241  {
1242    for (j = 0; j < MAX_NUM_REF; j++)
1243    {
1244      for (k =0; k < MAX_NUM_REF; k++)
1245      {
1246        m_abEqualRef[i][j][k] = pSrc->m_abEqualRef[i][j][k];
1247      }
1248    }
1249  }
1250
1251  m_uiTLayer                      = pSrc->m_uiTLayer;
1252  m_bTLayerSwitchingFlag          = pSrc->m_bTLayerSwitchingFlag;
1253
1254  m_sliceMode                   = pSrc->m_sliceMode;
1255  m_sliceArgument               = pSrc->m_sliceArgument;
1256  m_sliceCurStartCUAddr         = pSrc->m_sliceCurStartCUAddr;
1257  m_sliceCurEndCUAddr           = pSrc->m_sliceCurEndCUAddr;
1258  m_sliceIdx                    = pSrc->m_sliceIdx;
1259  m_sliceSegmentMode            = pSrc->m_sliceSegmentMode;
1260  m_sliceSegmentArgument        = pSrc->m_sliceSegmentArgument; 
1261  m_sliceSegmentCurStartCUAddr  = pSrc->m_sliceSegmentCurStartCUAddr;
1262  m_sliceSegmentCurEndCUAddr    = pSrc->m_sliceSegmentCurEndCUAddr;
1263  m_nextSlice                    = pSrc->m_nextSlice;
1264  m_nextSliceSegment             = pSrc->m_nextSliceSegment;
1265  for ( Int e=0 ; e<2 ; e++ )
1266  {
1267    for ( Int n=0 ; n<MAX_NUM_REF ; n++ )
1268    {
1269      memcpy(m_weightPredTable[e][n], pSrc->m_weightPredTable[e][n], sizeof(wpScalingParam)*3 );
1270    }
1271  }
1272  m_saoEnabledFlag = pSrc->m_saoEnabledFlag; 
1273  m_saoEnabledFlagChroma = pSrc->m_saoEnabledFlagChroma;
1274  m_cabacInitFlag                = pSrc->m_cabacInitFlag;
1275  m_numEntryPointOffsets  = pSrc->m_numEntryPointOffsets;
1276
1277  m_bLMvdL1Zero = pSrc->m_bLMvdL1Zero;
1278  m_LFCrossSliceBoundaryFlag = pSrc->m_LFCrossSliceBoundaryFlag;
1279  m_enableTMVPFlag                = pSrc->m_enableTMVPFlag;
1280  m_maxNumMergeCand               = pSrc->m_maxNumMergeCand;
1281}
1282
1283Int TComSlice::m_prevTid0POC = 0;
1284
1285/** Function for setting the slice's temporal layer ID and corresponding temporal_layer_switching_point_flag.
1286 * \param uiTLayer Temporal layer ID of the current slice
1287 * The decoder calls this function to set temporal_layer_switching_point_flag for each temporal layer based on
1288 * the SPS's temporal_id_nesting_flag and the parsed PPS.  Then, current slice's temporal layer ID and
1289 * temporal_layer_switching_point_flag is set accordingly.
1290 */
1291Void TComSlice::setTLayerInfo( UInt uiTLayer )
1292{
1293  m_uiTLayer = uiTLayer;
1294}
1295
1296/** Function for checking if this is a switching-point
1297*/
1298Bool TComSlice::isTemporalLayerSwitchingPoint( TComList<TComPic*>& rcListPic )
1299{
1300  TComPic* rpcPic;
1301  // loop through all pictures in the reference picture buffer
1302  TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1303  while ( iterPic != rcListPic.end())
1304  {
1305    rpcPic = *(iterPic++);
1306    if(rpcPic->getSlice(0)->isReferenced() && rpcPic->getPOC() != getPOC())
1307    {
1308      if(rpcPic->getTLayer() >= getTLayer())
1309      {
1310        return false;
1311      }
1312    }
1313  }
1314  return true;
1315}
1316
1317/** Function for checking if this is a STSA candidate
1318 */
1319Bool TComSlice::isStepwiseTemporalLayerSwitchingPointCandidate( TComList<TComPic*>& rcListPic )
1320{
1321    TComPic* rpcPic;
1322   
1323    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1324    while ( iterPic != rcListPic.end())
1325    {
1326        rpcPic = *(iterPic++);
1327        if(rpcPic->getSlice(0)->isReferenced() &&  (rpcPic->getUsedByCurr()==true) && rpcPic->getPOC() != getPOC())
1328        {
1329            if(rpcPic->getTLayer() >= getTLayer())
1330            {
1331                return false;
1332            }
1333        }
1334    }
1335    return true;
1336}
1337
1338
1339Void TComSlice::checkLeadingPictureRestrictions(TComList<TComPic*>& rcListPic)
1340{
1341  TComPic* rpcPic;
1342
1343  Int nalUnitType = this->getNalUnitType();
1344
1345  // When a picture is a leading picture, it shall be a RADL or RASL picture.
1346  if(this->getAssociatedIRAPPOC() > this->getPOC())
1347  {
1348    // Do not check IRAP pictures since they may get a POC lower than their associated IRAP
1349    if(nalUnitType < NAL_UNIT_CODED_SLICE_BLA_W_LP ||
1350       nalUnitType > NAL_UNIT_RESERVED_IRAP_VCL23)
1351    {
1352      assert(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
1353             nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R ||
1354             nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
1355             nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R);
1356    }
1357  }
1358
1359  // When a picture is a trailing picture, it shall not be a RADL or RASL picture.
1360  if(this->getAssociatedIRAPPOC() < this->getPOC())
1361  {
1362    assert(nalUnitType != NAL_UNIT_CODED_SLICE_RASL_N &&
1363           nalUnitType != NAL_UNIT_CODED_SLICE_RASL_R &&
1364           nalUnitType != NAL_UNIT_CODED_SLICE_RADL_N &&
1365           nalUnitType != NAL_UNIT_CODED_SLICE_RADL_R);
1366  }
1367
1368  // No RASL pictures shall be present in the bitstream that are associated
1369  // with a BLA picture having nal_unit_type equal to BLA_W_RADL or BLA_N_LP.
1370  if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
1371     nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R)
1372  {
1373    assert(this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_BLA_W_RADL &&
1374           this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_BLA_N_LP);
1375  }
1376
1377  // No RASL pictures shall be present in the bitstream that are associated with
1378  // an IDR picture.
1379  if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
1380     nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R)
1381  {
1382    assert(this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_IDR_N_LP   &&
1383           this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_IDR_W_RADL);
1384  }
1385
1386  // No RADL pictures shall be present in the bitstream that are associated with
1387  // a BLA picture having nal_unit_type equal to BLA_N_LP or that are associated
1388  // with an IDR picture having nal_unit_type equal to IDR_N_LP.
1389  if(nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
1390     nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R)
1391  {
1392    assert(this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_BLA_N_LP   &&
1393           this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_IDR_N_LP);
1394  }
1395
1396  // loop through all pictures in the reference picture buffer
1397  TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1398  while ( iterPic != rcListPic.end())
1399  {
1400    rpcPic = *(iterPic++);
1401#if BUGFIX_INTRAPERIOD
1402    if(!rpcPic->getReconMark())
1403    {
1404      continue;
1405    }
1406#endif
1407    if (rpcPic->getPOC() == this->getPOC())
1408    {
1409      continue;
1410    }
1411
1412    // Any picture that has PicOutputFlag equal to 1 that precedes an IRAP picture
1413    // in decoding order shall precede the IRAP picture in output order.
1414    // (Note that any picture following in output order would be present in the DPB)
1415#if !SETTING_NO_OUT_PIC_PRIOR
1416    if(rpcPic->getSlice(0)->getPicOutputFlag() == 1)
1417#else
1418    if(rpcPic->getSlice(0)->getPicOutputFlag() == 1 && !this->getNoOutputPriorPicsFlag())
1419#endif
1420    {
1421      if(nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP    ||
1422         nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP    ||
1423         nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL  ||
1424         nalUnitType == NAL_UNIT_CODED_SLICE_CRA         ||
1425         nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP    ||
1426         nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL)
1427      {
1428        assert(rpcPic->getPOC() < this->getPOC());
1429      }
1430    }
1431
1432    // Any picture that has PicOutputFlag equal to 1 that precedes an IRAP picture
1433    // in decoding order shall precede any RADL picture associated with the IRAP
1434    // picture in output order.
1435    if(rpcPic->getSlice(0)->getPicOutputFlag() == 1)
1436    {
1437      if((nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
1438          nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R))
1439      {
1440        // rpcPic precedes the IRAP in decoding order
1441        if(this->getAssociatedIRAPPOC() > rpcPic->getSlice(0)->getAssociatedIRAPPOC())
1442        {
1443          // rpcPic must not be the IRAP picture
1444          if(this->getAssociatedIRAPPOC() != rpcPic->getPOC())
1445          {
1446            assert(rpcPic->getPOC() < this->getPOC());
1447          }
1448        }
1449      }
1450    }
1451
1452    // When a picture is a leading picture, it shall precede, in decoding order,
1453    // all trailing pictures that are associated with the same IRAP picture.
1454    if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
1455       nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R ||
1456       nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
1457       nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R)
1458    {
1459      if(rpcPic->getSlice(0)->getAssociatedIRAPPOC() == this->getAssociatedIRAPPOC())
1460      {
1461        // rpcPic is a picture that preceded the leading in decoding order since it exist in the DPB
1462        // rpcPic would violate the constraint if it was a trailing picture
1463        assert(rpcPic->getPOC() <= this->getAssociatedIRAPPOC());
1464      }
1465    }
1466
1467    // Any RASL picture associated with a CRA or BLA picture shall precede any
1468    // RADL picture associated with the CRA or BLA picture in output order
1469    if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
1470       nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R)
1471    { 
1472      if((this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_BLA_N_LP   ||
1473          this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_BLA_W_LP   ||
1474          this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL ||
1475          this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_CRA)       &&
1476          this->getAssociatedIRAPPOC() == rpcPic->getSlice(0)->getAssociatedIRAPPOC())
1477      {
1478        if(rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N ||
1479           rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_R)
1480        {
1481          assert(rpcPic->getPOC() > this->getPOC());
1482        }
1483      }
1484    }
1485
1486    // Any RASL picture associated with a CRA picture shall follow, in output
1487    // order, any IRAP picture that precedes the CRA picture in decoding order.
1488    if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
1489       nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R)
1490    {
1491      if(this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_CRA)
1492      {
1493        if(rpcPic->getSlice(0)->getPOC() < this->getAssociatedIRAPPOC() &&
1494           (rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP   ||
1495            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP   ||
1496            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL ||
1497            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP   ||
1498            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL ||
1499            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA))
1500        {
1501          assert(this->getPOC() > rpcPic->getSlice(0)->getPOC());
1502        }
1503      }
1504    }
1505  }
1506}
1507
1508
1509
1510/** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet.
1511*/
1512Void TComSlice::applyReferencePictureSet( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet)
1513{
1514  TComPic* rpcPic;
1515  Int i, isReference;
1516
1517#if !ALIGNED_BUMPING
1518  checkLeadingPictureRestrictions(rcListPic);
1519#endif
1520
1521  // loop through all pictures in the reference picture buffer
1522  TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1523  while ( iterPic != rcListPic.end())
1524  {
1525    rpcPic = *(iterPic++);
1526
1527    if(!rpcPic->getSlice( 0 )->isReferenced())
1528    {
1529      continue;
1530    }
1531
1532    isReference = 0;
1533    // loop through all pictures in the Reference Picture Set
1534    // to see if the picture should be kept as reference picture
1535    for(i=0;i<pReferencePictureSet->getNumberOfPositivePictures()+pReferencePictureSet->getNumberOfNegativePictures();i++)
1536    {
1537      if(!rpcPic->getIsLongTerm() && rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i))
1538      {
1539        isReference = 1;
1540        rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i));
1541        rpcPic->setIsLongTerm(0);
1542      }
1543    }
1544    for(;i<pReferencePictureSet->getNumberOfPictures();i++)
1545    {
1546      if(pReferencePictureSet->getCheckLTMSBPresent(i)==true)
1547      {
1548        if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()) == pReferencePictureSet->getPOC(i))
1549        {
1550          isReference = 1;
1551          rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i));
1552        }
1553      }
1554      else 
1555      {
1556        Int pocCycle = 1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC();
1557        Int curPoc = rpcPic->getPicSym()->getSlice(0)->getPOC() & (pocCycle-1);
1558        Int refPoc = pReferencePictureSet->getPOC(i) & (pocCycle-1);
1559        if(rpcPic->getIsLongTerm() && curPoc == refPoc)
1560        {
1561          isReference = 1;
1562          rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i));
1563        }
1564      }
1565
1566    }
1567#if DISCARDABLE_PIC_RPS
1568    if( isReference ) // Current picture is in the temporal RPS
1569    {
1570      assert( rpcPic->getSlice(0)->getDiscardableFlag() == 0 ); // Temporal RPS shall not contain picture with discardable_flag equal to 1
1571    }
1572#endif
1573    // mark the picture as "unused for reference" if it is not in
1574    // the Reference Picture Set
1575    if(rpcPic->getPicSym()->getSlice(0)->getPOC() != this->getPOC() && isReference == 0)   
1576    {           
1577      rpcPic->getSlice( 0 )->setReferenced( false );   
1578      rpcPic->setUsedByCurr(0);
1579      rpcPic->setIsLongTerm(0);
1580    }
1581    //check that pictures of higher temporal layers are not used
1582    assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getUsedByCurr()==0||rpcPic->getTLayer()<=this->getTLayer());
1583    //check that pictures of higher or equal temporal layer are not in the RPS if the current picture is a TSA picture
1584    if(this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R || this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N)
1585    {
1586      assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getTLayer()<this->getTLayer());
1587    }
1588    //check that pictures marked as temporal layer non-reference pictures are not used for reference
1589    if(rpcPic->getPicSym()->getSlice(0)->getPOC() != this->getPOC() && rpcPic->getTLayer()==this->getTLayer())
1590    {
1591      assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getUsedByCurr()==0||rpcPic->getSlice( 0 )->getTemporalLayerNonReferenceFlag()==false);
1592    }
1593  }
1594}
1595
1596/** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet.
1597*/
1598#if ALLOW_RECOVERY_POINT_AS_RAP
1599Int TComSlice::checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess, Bool bUseRecoveryPoint)
1600#else
1601Int TComSlice::checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess)
1602#endif
1603{
1604#if ALLOW_RECOVERY_POINT_AS_RAP
1605  Int atLeastOneUnabledByRecoveryPoint = 0;
1606  Int atLeastOneFlushedByPreviousIDR = 0;
1607#endif
1608  TComPic* rpcPic;
1609  Int i, isAvailable;
1610  Int atLeastOneLost = 0;
1611  Int atLeastOneRemoved = 0;
1612  Int iPocLost = 0;
1613
1614  // loop through all long-term pictures in the Reference Picture Set
1615  // to see if the picture should be kept as reference picture
1616  for(i=pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures();i<pReferencePictureSet->getNumberOfPictures();i++)
1617  {
1618    isAvailable = 0;
1619    // loop through all pictures in the reference picture buffer
1620    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1621    while ( iterPic != rcListPic.end())
1622    {
1623      rpcPic = *(iterPic++);
1624      if(pReferencePictureSet->getCheckLTMSBPresent(i)==true)
1625      {
1626        if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()) == pReferencePictureSet->getPOC(i) && rpcPic->getSlice(0)->isReferenced())
1627        {
1628#if ALLOW_RECOVERY_POINT_AS_RAP
1629          if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess)
1630          {
1631            isAvailable = 0;
1632          }
1633          else
1634          {
1635          isAvailable = 1;
1636        }
1637#else
1638          isAvailable = 1;
1639#endif
1640        }
1641      }
1642      else 
1643      {
1644        Int pocCycle = 1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC();
1645        Int curPoc = rpcPic->getPicSym()->getSlice(0)->getPOC() & (pocCycle-1);
1646        Int refPoc = pReferencePictureSet->getPOC(i) & (pocCycle-1);
1647        if(rpcPic->getIsLongTerm() && curPoc == refPoc && rpcPic->getSlice(0)->isReferenced())
1648        {
1649#if ALLOW_RECOVERY_POINT_AS_RAP
1650          if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess)
1651          {
1652            isAvailable = 0;
1653          }
1654          else
1655          {
1656          isAvailable = 1;
1657        }
1658#else
1659          isAvailable = 1;
1660#endif
1661        }
1662      }
1663    }
1664    // if there was no such long-term check the short terms
1665    if(!isAvailable)
1666    {
1667      iterPic = rcListPic.begin();
1668      while ( iterPic != rcListPic.end())
1669      {
1670        rpcPic = *(iterPic++);
1671
1672        Int pocCycle = 1 << rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC();
1673        Int curPoc = rpcPic->getPicSym()->getSlice(0)->getPOC();
1674        Int refPoc = pReferencePictureSet->getPOC(i);
1675        if (!pReferencePictureSet->getCheckLTMSBPresent(i))
1676        {
1677          curPoc = curPoc & (pocCycle - 1);
1678          refPoc = refPoc & (pocCycle - 1);
1679        }
1680       
1681        if (rpcPic->getSlice(0)->isReferenced() && curPoc == refPoc)
1682        {
1683#if ALLOW_RECOVERY_POINT_AS_RAP
1684          if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess)
1685          {
1686            isAvailable = 0;
1687          }
1688          else
1689          {
1690          isAvailable = 1;
1691          rpcPic->setIsLongTerm(1);
1692          break;
1693        }
1694#else
1695          isAvailable = 1;
1696          rpcPic->setIsLongTerm(1);
1697          break;
1698#endif
1699        }
1700      }
1701    }
1702    // report that a picture is lost if it is in the Reference Picture Set
1703    // but not available as reference picture
1704    if(isAvailable == 0)   
1705    {           
1706      if (this->getPOC() + pReferencePictureSet->getDeltaPOC(i) >= pocRandomAccess)
1707      {
1708        if(!pReferencePictureSet->getUsed(i) )
1709        {
1710          if(printErrors)
1711          {
1712            printf("\nLong-term reference picture with POC = %3d seems to have been removed or not correctly decoded.", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
1713          }
1714          atLeastOneRemoved = 1;
1715        }
1716        else
1717        {
1718          if(printErrors)
1719          {
1720            printf("\nLong-term reference picture with POC = %3d is lost or not correctly decoded!", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
1721          }
1722          atLeastOneLost = 1;
1723          iPocLost=this->getPOC() + pReferencePictureSet->getDeltaPOC(i);
1724        }
1725      }
1726#if ALLOW_RECOVERY_POINT_AS_RAP
1727      else if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess)
1728      {
1729        atLeastOneUnabledByRecoveryPoint = 1;
1730      }
1731      else if(bUseRecoveryPoint && (this->getAssociatedIRAPType()==NAL_UNIT_CODED_SLICE_IDR_N_LP || this->getAssociatedIRAPType()==NAL_UNIT_CODED_SLICE_IDR_W_RADL))
1732      {
1733        atLeastOneFlushedByPreviousIDR = 1;
1734      }
1735#endif
1736    }
1737  } 
1738  // loop through all short-term pictures in the Reference Picture Set
1739  // to see if the picture should be kept as reference picture
1740  for(i=0;i<pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures();i++)
1741  {
1742    isAvailable = 0;
1743    // loop through all pictures in the reference picture buffer
1744    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1745    while ( iterPic != rcListPic.end())
1746    {
1747      rpcPic = *(iterPic++);
1748
1749      if(!rpcPic->getIsLongTerm() && rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i) && rpcPic->getSlice(0)->isReferenced())
1750      {
1751#if ALLOW_RECOVERY_POINT_AS_RAP
1752        if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess)
1753        {
1754          isAvailable = 0;
1755        }
1756        else
1757        {
1758        isAvailable = 1;
1759      }
1760#else
1761        isAvailable = 1;
1762#endif
1763      }
1764    }
1765    // report that a picture is lost if it is in the Reference Picture Set
1766    // but not available as reference picture
1767    if(isAvailable == 0)   
1768    {           
1769      if (this->getPOC() + pReferencePictureSet->getDeltaPOC(i) >= pocRandomAccess)
1770      {
1771        if(!pReferencePictureSet->getUsed(i) )
1772        {
1773          if(printErrors)
1774          {
1775            printf("\nShort-term reference picture with POC = %3d seems to have been removed or not correctly decoded.", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
1776          }
1777          atLeastOneRemoved = 1;
1778        }
1779        else
1780        {
1781          if(printErrors)
1782          {
1783            printf("\nShort-term reference picture with POC = %3d is lost or not correctly decoded!", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
1784          }
1785          atLeastOneLost = 1;
1786          iPocLost=this->getPOC() + pReferencePictureSet->getDeltaPOC(i);
1787        }
1788      }
1789#if ALLOW_RECOVERY_POINT_AS_RAP
1790      else if(bUseRecoveryPoint && this->getPOC() > pocRandomAccess)
1791      {
1792        atLeastOneUnabledByRecoveryPoint = 1;
1793      }
1794      else if(bUseRecoveryPoint && (this->getAssociatedIRAPType()==NAL_UNIT_CODED_SLICE_IDR_N_LP || this->getAssociatedIRAPType()==NAL_UNIT_CODED_SLICE_IDR_W_RADL))
1795      {
1796        atLeastOneFlushedByPreviousIDR = 1;
1797      }
1798#endif
1799    }
1800    }
1801#if ALLOW_RECOVERY_POINT_AS_RAP
1802  if(atLeastOneUnabledByRecoveryPoint || atLeastOneFlushedByPreviousIDR)
1803  {
1804    return -1;
1805  }   
1806#endif
1807  if(atLeastOneLost)
1808  {
1809    return iPocLost+1;
1810  }
1811  if(atLeastOneRemoved)
1812  {
1813    return -2;
1814  }
1815  else
1816  {
1817    return 0;
1818  }
1819}
1820
1821/** Function for constructing an explicit Reference Picture Set out of the available pictures in a referenced Reference Picture Set
1822*/
1823#if ALLOW_RECOVERY_POINT_AS_RAP
1824Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP, Int pocRandomAccess, Bool bUseRecoveryPoint)
1825#else
1826Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP)
1827#endif
1828{
1829  TComPic* rpcPic;
1830  Int i, j;
1831  Int k = 0;
1832  Int nrOfNegativePictures = 0;
1833  Int nrOfPositivePictures = 0;
1834  TComReferencePictureSet* pcRPS = this->getLocalRPS();
1835
1836  // loop through all pictures in the Reference Picture Set
1837  for(i=0;i<pReferencePictureSet->getNumberOfPictures();i++)
1838  {
1839    j = 0;
1840    // loop through all pictures in the reference picture buffer
1841    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1842    while ( iterPic != rcListPic.end())
1843    {
1844      j++;
1845      rpcPic = *(iterPic++);
1846
1847      if(rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i) && rpcPic->getSlice(0)->isReferenced())
1848      {
1849        // This picture exists as a reference picture
1850        // and should be added to the explicit Reference Picture Set
1851        pcRPS->setDeltaPOC(k, pReferencePictureSet->getDeltaPOC(i));
1852        pcRPS->setUsed(k, pReferencePictureSet->getUsed(i) && (!isRAP));
1853#if ALLOW_RECOVERY_POINT_AS_RAP
1854        pcRPS->setUsed(k, pcRPS->getUsed(k) && !(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess) ); 
1855#endif
1856        if(pcRPS->getDeltaPOC(k) < 0)
1857        {
1858          nrOfNegativePictures++;
1859        }
1860        else
1861        {
1862          nrOfPositivePictures++;
1863        }
1864        k++;
1865      }
1866    }
1867  }
1868#if EFFICIENT_FIELD_IRAP
1869  Bool useNewRPS = false;
1870  // if current picture is complimentary field associated to IRAP, add the IRAP to its RPS.
1871  if(m_pcPic->isField())
1872  {
1873    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1874    while ( iterPic != rcListPic.end())
1875    {
1876      rpcPic = *(iterPic++);
1877      if(rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getAssociatedIRAPPOC() && this->getAssociatedIRAPPOC() == this->getPOC()+1)
1878      {
1879        pcRPS->setDeltaPOC(k, 1);
1880        pcRPS->setUsed(k, true);
1881        nrOfPositivePictures++;
1882        k ++;
1883        useNewRPS = true;
1884      }
1885    }
1886  }
1887#endif
1888  pcRPS->setNumberOfNegativePictures(nrOfNegativePictures);
1889  pcRPS->setNumberOfPositivePictures(nrOfPositivePictures);
1890  pcRPS->setNumberOfPictures(nrOfNegativePictures+nrOfPositivePictures);
1891  // This is a simplistic inter rps example. A smarter encoder will look for a better reference RPS to do the
1892  // inter RPS prediction with.  Here we just use the reference used by pReferencePictureSet.
1893  // If pReferencePictureSet is not inter_RPS_predicted, then inter_RPS_prediction is for the current RPS also disabled.
1894  if (!pReferencePictureSet->getInterRPSPrediction()
1895#if EFFICIENT_FIELD_IRAP
1896    || useNewRPS
1897#endif
1898    )
1899  {
1900    pcRPS->setInterRPSPrediction(false);
1901    pcRPS->setNumRefIdc(0);
1902  }
1903  else
1904  {
1905    Int rIdx =  this->getRPSidx() - pReferencePictureSet->getDeltaRIdxMinus1() - 1;
1906    Int deltaRPS = pReferencePictureSet->getDeltaRPS();
1907    TComReferencePictureSet* pcRefRPS = this->getSPS()->getRPSList()->getReferencePictureSet(rIdx);
1908    Int iRefPics = pcRefRPS->getNumberOfPictures();
1909    Int iNewIdc=0;
1910    for(i=0; i<= iRefPics; i++) 
1911    {
1912      Int deltaPOC = ((i != iRefPics)? pcRefRPS->getDeltaPOC(i) : 0);  // check if the reference abs POC is >= 0
1913      Int iRefIdc = 0;
1914      for (j=0; j < pcRPS->getNumberOfPictures(); j++) // loop through the  pictures in the new RPS
1915      {
1916        if ( (deltaPOC + deltaRPS) == pcRPS->getDeltaPOC(j))
1917        {
1918          if (pcRPS->getUsed(j))
1919          {
1920            iRefIdc = 1;
1921          }
1922          else
1923          {
1924            iRefIdc = 2;
1925          }
1926        }
1927      }
1928      pcRPS->setRefIdc(i, iRefIdc);
1929      iNewIdc++;
1930    }
1931    pcRPS->setInterRPSPrediction(true);
1932    pcRPS->setNumRefIdc(iNewIdc);
1933    pcRPS->setDeltaRPS(deltaRPS); 
1934    pcRPS->setDeltaRIdxMinus1(pReferencePictureSet->getDeltaRIdxMinus1() + this->getSPS()->getRPSList()->getNumberOfReferencePictureSets() - this->getRPSidx());
1935  }
1936
1937  this->setRPS(pcRPS);
1938  this->setRPSidx(-1);
1939}
1940
1941/** get AC and DC values for weighted pred
1942 * \param *wp
1943 * \returns Void
1944 */
1945Void  TComSlice::getWpAcDcParam(wpACDCParam *&wp)
1946{
1947  wp = m_weightACDCParam;
1948}
1949
1950/** init AC and DC values for weighted pred
1951 * \returns Void
1952 */
1953Void  TComSlice::initWpAcDcParam()
1954{
1955  for(Int iComp = 0; iComp < 3; iComp++ )
1956  {
1957    m_weightACDCParam[iComp].iAC = 0;
1958    m_weightACDCParam[iComp].iDC = 0;
1959  }
1960}
1961
1962/** get WP tables for weighted pred
1963 * \param RefPicList
1964 * \param iRefIdx
1965 * \param *&wpScalingParam
1966 * \returns Void
1967 */
1968Void  TComSlice::getWpScaling( RefPicList e, Int iRefIdx, wpScalingParam *&wp )
1969{
1970  wp = m_weightPredTable[e][iRefIdx];
1971}
1972
1973/** reset Default WP tables settings : no weight.
1974 * \param wpScalingParam
1975 * \returns Void
1976 */
1977Void  TComSlice::resetWpScaling()
1978{
1979  for ( Int e=0 ; e<2 ; e++ )
1980  {
1981    for ( Int i=0 ; i<MAX_NUM_REF ; i++ )
1982    {
1983      for ( Int yuv=0 ; yuv<3 ; yuv++ )
1984      {
1985        wpScalingParam  *pwp = &(m_weightPredTable[e][i][yuv]);
1986        pwp->bPresentFlag      = false;
1987        pwp->uiLog2WeightDenom = 0;
1988        pwp->uiLog2WeightDenom = 0;
1989        pwp->iWeight           = 1;
1990        pwp->iOffset           = 0;
1991      }
1992    }
1993  }
1994}
1995
1996/** init WP table
1997 * \returns Void
1998 */
1999Void  TComSlice::initWpScaling()
2000{
2001  for ( Int e=0 ; e<2 ; e++ )
2002  {
2003    for ( Int i=0 ; i<MAX_NUM_REF ; i++ )
2004    {
2005      for ( Int yuv=0 ; yuv<3 ; yuv++ )
2006      {
2007        wpScalingParam  *pwp = &(m_weightPredTable[e][i][yuv]);
2008        if ( !pwp->bPresentFlag ) 
2009        {
2010          // Inferring values not present :
2011          pwp->iWeight = (1 << pwp->uiLog2WeightDenom);
2012          pwp->iOffset = 0;
2013        }
2014
2015        pwp->w      = pwp->iWeight;
2016        Int bitDepth = yuv ? g_bitDepthC : g_bitDepthY;
2017        pwp->o      = pwp->iOffset << (bitDepth-8);
2018        pwp->shift  = pwp->uiLog2WeightDenom;
2019        pwp->round  = (pwp->uiLog2WeightDenom>=1) ? (1 << (pwp->uiLog2WeightDenom-1)) : (0);
2020      }
2021    }
2022  }
2023}
2024
2025#if REPN_FORMAT_IN_VPS
2026UInt TComSlice::getPicWidthInLumaSamples()
2027{
2028  TComSPS *sps = getSPS();
2029  TComVPS *vps = getVPS();
2030  UInt retVal, layerId = getLayerId();
2031#if O0096_REP_FORMAT_INDEX
2032  if ( layerId == 0 )
2033  {
2034    if( vps->getAvcBaseLayerFlag() )
2035    {
2036      retVal = vps->getVpsRepFormat(layerId)->getPicWidthVpsInLumaSamples();
2037    }
2038    else
2039    {
2040      retVal = sps->getPicWidthInLumaSamples();
2041    }
2042  }
2043  else
2044  {
2045    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : layerId) )->getPicWidthVpsInLumaSamples();
2046  }
2047#else
2048  if( ( layerId == 0 ) || sps->getUpdateRepFormatFlag() )
2049  {
2050    retVal = sps->getPicWidthInLumaSamples();
2051  }
2052  else
2053  {
2054    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getPicWidthVpsInLumaSamples();
2055  }
2056#endif
2057  return retVal;
2058}
2059UInt TComSlice::getPicHeightInLumaSamples()
2060{
2061  TComSPS *sps = getSPS();
2062  TComVPS *vps = getVPS();
2063  UInt retVal, layerId = getLayerId();
2064#if O0096_REP_FORMAT_INDEX
2065  if( layerId == 0 )
2066  {
2067    if( vps->getAvcBaseLayerFlag() )
2068    {
2069      retVal = vps->getVpsRepFormat(layerId)->getPicHeightVpsInLumaSamples();
2070    }
2071    else
2072    {
2073      retVal = sps->getPicHeightInLumaSamples();
2074    }
2075  }
2076  else
2077  {
2078    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : layerId) )->getPicHeightVpsInLumaSamples();
2079  }
2080#else
2081  if( ( layerId == 0 ) || sps->getUpdateRepFormatFlag() )
2082  {
2083    retVal = sps->getPicHeightInLumaSamples();
2084  }
2085  else
2086  {
2087    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getPicHeightVpsInLumaSamples();
2088  }
2089#endif
2090  return retVal;
2091}
2092#if AUXILIARY_PICTURES
2093ChromaFormat TComSlice::getChromaFormatIdc()
2094#else
2095UInt TComSlice::getChromaFormatIdc()
2096#endif
2097{
2098  TComSPS *sps = getSPS();
2099  TComVPS *vps = getVPS();
2100#if AUXILIARY_PICTURES
2101  ChromaFormat retVal;
2102  UInt layerId = getLayerId();
2103#else
2104  UInt retVal, layerId = getLayerId();
2105#endif
2106#if O0096_REP_FORMAT_INDEX
2107  if( layerId == 0 )
2108  {
2109    if( vps->getAvcBaseLayerFlag() )
2110    {
2111      retVal = vps->getVpsRepFormat(layerId)->getChromaFormatVpsIdc();
2112    }
2113    else
2114    {
2115      retVal = sps->getChromaFormatIdc();
2116    }
2117  }
2118  else
2119  {
2120    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : layerId) )->getChromaFormatVpsIdc();
2121  }
2122#else
2123  if( ( layerId == 0 ) || sps->getUpdateRepFormatFlag() )
2124  {
2125    retVal = sps->getChromaFormatIdc();
2126  }
2127  else
2128  {
2129    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getChromaFormatVpsIdc();
2130  }
2131#endif
2132  return retVal;
2133}
2134UInt TComSlice::getBitDepthY()
2135{
2136  TComSPS *sps = getSPS();
2137  TComVPS *vps = getVPS();
2138  UInt retVal, layerId = getLayerId();
2139#if O0096_REP_FORMAT_INDEX
2140  if( layerId == 0 )
2141  {
2142    retVal = sps->getBitDepthY();
2143  }
2144  else
2145  {
2146    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : layerId) )->getBitDepthVpsLuma();
2147  }
2148#else
2149  if( ( layerId == 0 ) || sps->getUpdateRepFormatFlag() )
2150  {
2151    retVal = sps->getBitDepthY();
2152  }
2153  else
2154  {
2155    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getBitDepthVpsLuma();
2156  }
2157#endif
2158  return retVal;
2159}
2160UInt TComSlice::getBitDepthC()
2161{
2162  TComSPS *sps = getSPS();
2163  TComVPS *vps = getVPS();
2164  UInt retVal, layerId = getLayerId();
2165#if O0096_REP_FORMAT_INDEX
2166  if( layerId == 0 )
2167  {
2168    retVal = sps->getBitDepthC();
2169  }
2170  else
2171  {
2172    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : layerId) )->getBitDepthVpsChroma();
2173  }
2174#else
2175  if( ( layerId == 0 ) || sps->getUpdateRepFormatFlag() )
2176  {
2177    retVal = sps->getBitDepthC();
2178  }
2179  else
2180  {
2181    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(layerId) )->getBitDepthVpsChroma();
2182  }
2183#endif
2184  return retVal;
2185}
2186Int TComSlice::getQpBDOffsetY()
2187{
2188  return (getBitDepthY() - 8) * 6;
2189}
2190Int TComSlice::getQpBDOffsetC()
2191{
2192  return (getBitDepthC() - 8) * 6;
2193}
2194
2195RepFormat::RepFormat()
2196#if AUXILIARY_PICTURES
2197: m_chromaFormatVpsIdc          (CHROMA_420)
2198#else
2199: m_chromaFormatVpsIdc          (0)
2200#endif
2201, m_separateColourPlaneVpsFlag  (false)
2202, m_picWidthVpsInLumaSamples    (0)
2203, m_picHeightVpsInLumaSamples   (0)
2204, m_bitDepthVpsLuma             (0)
2205, m_bitDepthVpsChroma           (0)
2206{}
2207#if RESOLUTION_BASED_DPB
2208Void RepFormat::init()
2209{
2210  m_chromaFormatVpsIdc          = CHROMA_420;
2211  m_separateColourPlaneVpsFlag  = false;
2212  m_picWidthVpsInLumaSamples    = 0;
2213  m_picHeightVpsInLumaSamples   = 0;
2214  m_bitDepthVpsLuma             = 0;
2215  m_bitDepthVpsChroma           = 0;
2216}
2217#endif
2218#endif
2219
2220// ------------------------------------------------------------------------------------------------
2221// Video parameter set (VPS)
2222// ------------------------------------------------------------------------------------------------
2223#if SVC_EXTENSION
2224TComVPS::TComVPS()
2225: m_VPSId                     (  0)
2226, m_uiMaxTLayers              (  1)
2227, m_uiMaxLayers               (  1)
2228, m_bTemporalIdNestingFlag    (false)
2229, m_numHrdParameters          (  0)
2230#if !VPS_RENAME
2231, m_maxNuhReservedZeroLayerId (  0)
2232#endif
2233, m_hrdParameters             (NULL)
2234, m_hrdOpSetIdx               (NULL)
2235, m_cprmsPresentFlag          (NULL)
2236#if VPS_RENAME
2237, m_maxLayerId                (0)
2238, m_numLayerSets              (0)
2239#endif
2240#if VPS_EXTN_OP_LAYER_SETS
2241, m_numOutputLayerSets        (0) 
2242#endif
2243, m_numProfileTierLevel       (0)
2244#if !VPS_EXTN_UEV_CODING
2245, m_moreOutputLayerSetsThanDefaultFlag (false)
2246#endif
2247, m_numAddOutputLayerSets     (0)
2248#if P0295_DEFAULT_OUT_LAYER_IDC
2249, m_defaultTargetOutputLayerIdc     (0)
2250#else
2251#if O0109_DEFAULT_ONE_OUT_LAYER_IDC
2252, m_defaultOneTargetOutputLayerIdc     (0)
2253#else
2254, m_defaultOneTargetOutputLayerFlag    (false)
2255#endif
2256#endif
2257#if VPS_VUI_BITRATE_PICRATE
2258, m_bitRatePresentVpsFlag     (false)
2259, m_picRatePresentVpsFlag     (false)
2260#endif
2261#if REPN_FORMAT_IN_VPS
2262#if Q0195_REP_FORMAT_CLEANUP
2263, m_repFormatIdxPresentFlag   (false)
2264#else
2265, m_repFormatIdxPresentFlag   (true)
2266#endif
2267, m_vpsNumRepFormats          (1)
2268#endif
2269#if VIEW_ID_RELATED_SIGNALING
2270#if O0109_VIEW_ID_LEN
2271, m_viewIdLen                (0)
2272#else
2273, m_viewIdLenMinus1           (0)
2274#endif
2275#endif
2276#if !P0307_REMOVE_VPS_VUI_OFFSET
2277#if VPS_VUI_OFFSET
2278, m_vpsVuiOffset (0)
2279#endif
2280#endif
2281#if P0307_VPS_NON_VUI_EXTENSION
2282, m_vpsNonVuiExtLength (0)
2283#endif
2284{
2285  for( Int i = 0; i < MAX_TLAYER; i++)
2286  {
2287    m_numReorderPics[i] = 0;
2288    m_uiMaxDecPicBuffering[i] = 1; 
2289    m_uiMaxLatencyIncrease[i] = 0;
2290  }
2291#if VPS_EXTN_MASK_AND_DIM_INFO
2292  m_avcBaseLayerFlag = false;
2293  m_splittingFlag = false;
2294  ::memset(m_scalabilityMask, 0, sizeof(m_scalabilityMask));
2295  ::memset(m_dimensionIdLen, 0, sizeof(m_dimensionIdLen));
2296  m_nuhLayerIdPresentFlag = false;
2297  ::memset(m_layerIdInNuh, 0, sizeof(m_layerIdInNuh));
2298  ::memset(m_dimensionId, 0, sizeof(m_dimensionId));
2299
2300  m_numScalabilityTypes = 0;
2301  ::memset(m_layerIdInVps, 0, sizeof(m_layerIdInVps));
2302#endif
2303#if VPS_EXTN_PROFILE_INFO
2304  ::memset(m_profilePresentFlag, 0, sizeof(m_profilePresentFlag));
2305#if !P0048_REMOVE_PROFILE_REF
2306  ::memset(m_profileLayerSetRef, 0, sizeof(m_profileLayerSetRef));
2307#endif
2308#endif
2309#if VPS_EXTN_OP_LAYER_SETS
2310  ::memset(m_layerIdIncludedFlag, 0, sizeof(m_layerIdIncludedFlag));
2311  // Consider dynamic allocation for outputLayerSetIdx and outputLayerFlag
2312  ::memset(m_outputLayerSetIdx, 0, sizeof(m_outputLayerSetIdx));
2313  ::memset(m_outputLayerFlag, 0, sizeof(m_outputLayerFlag));
2314#endif
2315#if VPS_EXTN_DIRECT_REF_LAYERS
2316  ::memset(m_directDependencyFlag, 0, sizeof(m_directDependencyFlag));
2317  ::memset(m_numDirectRefLayers,   0, sizeof(m_numDirectRefLayers  ));
2318  ::memset(m_refLayerId,           0, sizeof(m_refLayerId          ));
2319  m_directDepTypeLen = 2;
2320  ::memset(m_directDependencyType, 0, sizeof(m_directDependencyType));
2321#endif
2322#if DERIVE_LAYER_ID_LIST_VARIABLES
2323  ::memset(m_layerSetLayerIdList,  0, sizeof(m_layerSetLayerIdList));
2324  ::memset(m_numLayerInIdList,     0, sizeof(m_numLayerInIdList   )); 
2325#endif
2326  ::memset(m_profileLevelTierIdx,  0, sizeof(m_profileLevelTierIdx));
2327  m_maxOneActiveRefLayerFlag = true;
2328#if O0062_POC_LSB_NOT_PRESENT_FLAG
2329  ::memset(m_pocLsbNotPresentFlag, 0, sizeof(m_pocLsbNotPresentFlag));
2330#endif
2331#if O0223_PICTURE_TYPES_ALIGN_FLAG
2332  m_crossLayerPictureTypeAlignFlag = true;
2333#endif
2334#if N0147_IRAP_ALIGN_FLAG
2335  m_crossLayerIrapAlignFlag = true;
2336#endif
2337#if P0068_CROSS_LAYER_ALIGNED_IDR_ONLY_FOR_IRAP_FLAG
2338  m_crossLayerAlignedIdrOnlyFlag = false;
2339#endif
2340#if N0120_MAX_TID_REF_PRESENT_FLAG
2341  m_maxTidRefPresentFlag = true;
2342#endif
2343  for( Int i = 0; i < MAX_VPS_LAYER_ID_PLUS1 - 1; i++)
2344  {
2345#if O0225_MAX_TID_FOR_REF_LAYERS
2346    for( Int j = 0; j < MAX_VPS_LAYER_ID_PLUS1; j++)
2347    {
2348      m_maxTidIlRefPicsPlus1[i][j] = m_uiMaxTLayers + 1;
2349    }
2350#else
2351    m_maxTidIlRefPicsPlus1[i] = m_uiMaxTLayers + 1;
2352#endif
2353  }
2354#if VPS_VUI_TILES_NOT_IN_USE__FLAG
2355  m_tilesNotInUseFlag = true;
2356  ::memset(m_tilesInUseFlag,  0, sizeof(m_tilesInUseFlag));
2357  ::memset(m_loopFilterNotAcrossTilesFlag,  0, sizeof(m_loopFilterNotAcrossTilesFlag));
2358#endif
2359#if TILE_BOUNDARY_ALIGNED_FLAG
2360  ::memset(m_tileBoundariesAlignedFlag,  0, sizeof(m_tileBoundariesAlignedFlag));
2361#endif
2362#if VPS_VUI_WPP_NOT_IN_USE__FLAG
2363  m_wppNotInUseFlag = true;
2364  ::memset(m_wppInUseFlag,  0, sizeof(m_wppInUseFlag));
2365#endif
2366#if N0160_VUI_EXT_ILP_REF
2367  m_ilpRestrictedRefLayersFlag = false;
2368  ::memset(m_minSpatialSegmentOffsetPlus1,  0, sizeof(m_minSpatialSegmentOffsetPlus1));
2369  ::memset(m_ctuBasedOffsetEnabledFlag,     0, sizeof(m_ctuBasedOffsetEnabledFlag));
2370  ::memset(m_minHorizontalCtuOffsetPlus1,   0, sizeof(m_minHorizontalCtuOffsetPlus1));
2371#endif
2372#if VPS_VUI_VIDEO_SIGNAL
2373  m_vidSigPresentVpsFlag=true;
2374  m_vpsVidSigInfo=1;
2375  ::memset( m_vpsVidSigIdx, 0, sizeof(m_vpsVidSigIdx) );
2376  m_vpsVidSigIdx[0]=0;
2377  for (Int i=0; i < 16; i++)
2378  {
2379    m_vpsVidFormat[i] = 5;
2380    m_vpsFullRangeFlag[i] = false;
2381    m_vpsColorPrimaries[i] = 2;
2382    m_vpsTransChar[i] = 2;
2383    m_vpsMatCoeff[i] = 2;
2384  }
2385#endif
2386#if VPS_VUI_BITRATE_PICRATE 
2387  ::memset(m_bitRatePresentFlag, 0, sizeof(m_bitRatePresentFlag));
2388  ::memset(m_picRatePresentFlag, 0, sizeof(m_picRatePresentFlag));
2389  ::memset(m_avgBitRate        , 0, sizeof(m_avgBitRate)        );
2390  ::memset(m_maxBitRate        , 0, sizeof(m_maxBitRate)        );
2391  ::memset(m_constPicRateIdc   , 0, sizeof(m_constPicRateIdc)   );
2392  ::memset(m_avgPicRate        , 0, sizeof(m_avgPicRate)        );
2393#endif
2394#if REPN_FORMAT_IN_VPS
2395  ::memset( m_vpsRepFormatIdx, 0, sizeof(m_vpsRepFormatIdx) );
2396#endif
2397#if VIEW_ID_RELATED_SIGNALING
2398  ::memset(m_viewIdVal, 0, sizeof(m_viewIdVal));
2399#endif
2400#if O0092_0094_DEPENDENCY_CONSTRAINT
2401  for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++)
2402  {
2403    m_numberRefLayers[i] = 0;
2404    for (Int j = 0; j < MAX_NUM_LAYER_IDS; j++)
2405    {
2406      m_recursiveRefLayerFlag[i][j] = 0;
2407    }
2408  }
2409#endif
2410#if VPS_DPB_SIZE_TABLE
2411  ::memset( m_subLayerFlagInfoPresentFlag,  0, sizeof(m_subLayerFlagInfoPresentFlag ) );
2412  ::memset( m_subLayerDpbInfoPresentFlag,   0, sizeof(m_subLayerDpbInfoPresentFlag )  );
2413  ::memset( m_maxVpsDecPicBufferingMinus1,  0, sizeof(m_maxVpsDecPicBufferingMinus1 ) );
2414#if RESOLUTION_BASED_DPB
2415  ::memset( m_maxVpsLayerDecPicBuffMinus1,  0, sizeof(m_maxVpsLayerDecPicBuffMinus1 ) );
2416#endif
2417  ::memset( m_maxVpsNumReorderPics,         0, sizeof(m_maxVpsNumReorderPics )        );
2418  ::memset( m_maxVpsLatencyIncreasePlus1,   0, sizeof(m_maxVpsLatencyIncreasePlus1 )  );
2419  ::memset( m_numSubDpbs                ,   0, sizeof(m_numSubDpbs)                   );
2420#endif
2421}
2422#else
2423TComVPS::TComVPS()
2424: m_VPSId                     (  0)
2425, m_uiMaxTLayers              (  1)
2426, m_uiMaxLayers               (  1)
2427, m_bTemporalIdNestingFlag    (false)
2428, m_numHrdParameters          (  0)
2429, m_maxNuhReservedZeroLayerId (  0)
2430, m_hrdParameters             (NULL)
2431, m_hrdOpSetIdx               (NULL)
2432, m_cprmsPresentFlag          (NULL)
2433{
2434  for( Int i = 0; i < MAX_TLAYER; i++)
2435  {
2436    m_numReorderPics[i] = 0;
2437    m_uiMaxDecPicBuffering[i] = 1; 
2438    m_uiMaxLatencyIncrease[i] = 0;
2439  }
2440}
2441#endif //SVC_EXTENSION
2442
2443TComVPS::~TComVPS()
2444{
2445  if( m_hrdParameters    != NULL )     delete[] m_hrdParameters;
2446  if( m_hrdOpSetIdx      != NULL )     delete[] m_hrdOpSetIdx;
2447  if( m_cprmsPresentFlag != NULL )     delete[] m_cprmsPresentFlag;
2448}
2449#if DERIVE_LAYER_ID_LIST_VARIABLES
2450Void TComVPS::deriveLayerIdListVariables()
2451{
2452  // For layer 0
2453  m_numLayerInIdList[0] = 1;
2454  m_layerSetLayerIdList[0][0] = 0;
2455 
2456  // For other layers
2457  Int i, m, n;
2458  for( i = 1; i < m_numLayerSets; i++ )
2459  {
2460    n = 0;
2461    for( m = 0; m <= m_maxLayerId; m++)
2462    {
2463      if( m_layerIdIncludedFlag[i][m] )
2464      {
2465        m_layerSetLayerIdList[i][n++] = m;
2466      }
2467    }
2468    m_numLayerInIdList[i] = n;
2469  }
2470}
2471#endif
2472#if !RESOLUTION_BASED_DPB
2473#if VPS_DPB_SIZE_TABLE
2474Void TComVPS::deriveNumberOfSubDpbs()
2475{
2476  // Derive number of sub-DPBs
2477#if CHANGE_NUMSUBDPB_IDX
2478  // For layer set 0
2479  setNumSubDpbs(0, 1);
2480  // For other layer sets
2481  for( Int i = 1; i < getNumLayerSets(); i++)
2482  {
2483    setNumSubDpbs( i, getNumLayersInIdList( i ) );
2484  }
2485#else
2486  // For output layer set 0
2487  setNumSubDpbs(0, 1);
2488  // For other output layer sets
2489  for( Int i = 1; i < getNumOutputLayerSets(); i++)
2490  {
2491    setNumSubDpbs( i, getNumLayersInIdList( getOutputLayerSetIdx(i)) );
2492  }
2493#endif
2494}
2495#endif
2496#endif
2497#if VPS_VUI_TILES_NOT_IN_USE__FLAG
2498Void TComVPS::setTilesNotInUseFlag(Bool x)
2499{
2500  m_tilesNotInUseFlag = x;
2501  if (m_tilesNotInUseFlag)
2502  {
2503    for (int i = 0; i < getMaxLayers(); i++)
2504    {
2505      m_tilesInUseFlag[i] = m_loopFilterNotAcrossTilesFlag[i] = m_tilesNotInUseFlag;
2506    }
2507  }
2508#if TILE_BOUNDARY_ALIGNED_FLAG 
2509  if (m_tilesNotInUseFlag)
2510  {
2511    for (int i = 1; i < getMaxLayers(); i++)
2512    {
2513      for(int j = 0; j < getNumDirectRefLayers(getLayerIdInNuh(i)); j++)
2514      {
2515        setTileBoundariesAlignedFlag(i, j, m_tilesNotInUseFlag);
2516      }
2517    }
2518  }
2519#endif
2520}
2521#endif
2522#if VPS_VUI_WPP_NOT_IN_USE__FLAG
2523Void TComVPS::setWppNotInUseFlag(Bool x)
2524{
2525  m_wppNotInUseFlag = x;
2526  if (m_wppNotInUseFlag)
2527  {
2528    for (int i = 0; i < getMaxLayers(); i++)
2529    {
2530      m_wppInUseFlag[i] = m_wppNotInUseFlag;
2531    }
2532  }
2533}
2534#endif
2535#if O0092_0094_DEPENDENCY_CONSTRAINT
2536Void TComVPS::setRefLayersFlags(Int currLayerId)
2537{
2538  for (Int i = 0; i < m_numDirectRefLayers[currLayerId]; i++)
2539  {
2540    UInt refLayerId = getRefLayerId(currLayerId, i);
2541    m_recursiveRefLayerFlag[currLayerId][refLayerId] = true;
2542    for (Int k = 0; k < MAX_NUM_LAYER_IDS; k++)
2543    {
2544      m_recursiveRefLayerFlag[currLayerId][k] = m_recursiveRefLayerFlag[currLayerId][k] | m_recursiveRefLayerFlag[refLayerId][k];
2545    }
2546  }
2547}
2548
2549Void TComVPS::setNumRefLayers()
2550{
2551  memset( m_numberRefLayers, 0, sizeof( m_numberRefLayers ) );
2552
2553  for (Int i = 0; i < m_uiMaxLayers; i++)
2554  {
2555    UInt iNuhLId = m_layerIdInNuh[i];
2556    setRefLayersFlags(iNuhLId);
2557    for (UInt j = 0; j < MAX_NUM_LAYER_IDS; j++)
2558    {
2559      m_numberRefLayers[iNuhLId] += (m_recursiveRefLayerFlag[iNuhLId][j] == true ? 1 : 0);
2560    }
2561  }
2562}
2563#endif
2564
2565#if VIEW_ID_RELATED_SIGNALING
2566Int TComVPS::getNumViews()
2567{
2568  Int numViews = 1; 
2569  for( Int i = 0; i <= getMaxLayers() - 1; i++ )
2570  {
2571    Int lId = getLayerIdInNuh( i ); 
2572    if ( i > 0 && ( getViewIndex( lId ) != getScalabilityId( i - 1, VIEW_ORDER_INDEX ) ) )
2573    {
2574      numViews++; 
2575    }   
2576  }
2577
2578  return numViews;
2579}
2580Int TComVPS::getScalabilityId( Int layerIdInVps, ScalabilityType scalType )
2581{
2582  return getScalabilityMask( scalType ) ? getDimensionId( layerIdInVps, scalTypeToScalIdx( scalType ) ) : 0;
2583} 
2584Int TComVPS::scalTypeToScalIdx( ScalabilityType scalType )
2585{
2586  assert( scalType >= 0 && scalType <= MAX_VPS_NUM_SCALABILITY_TYPES ); 
2587  assert( scalType == MAX_VPS_NUM_SCALABILITY_TYPES || getScalabilityMask( scalType ) );
2588  Int scalIdx = 0; 
2589  for( Int curScalType = 0; curScalType < scalType; curScalType++ )
2590  {
2591    scalIdx += ( getScalabilityMask( curScalType ) ? 1 : 0 );
2592
2593  }
2594
2595  return scalIdx; 
2596}
2597#endif
2598#if VPS_DPB_SIZE_TABLE
2599Void TComVPS::determineSubDpbInfoFlags()
2600{
2601  for(Int i = 1; i < getNumOutputLayerSets(); i++)
2602  {
2603    Int layerSetIdxForOutputLayerSet = getOutputLayerSetIdx( i );
2604    // For each output layer set, set the DPB size for each layer and the reorder/latency value the maximum for all layers
2605    Bool checkFlagOuter = false;      // Used to calculate sub_layer_flag_info_present_flag
2606    Bool checkFlagInner[MAX_TLAYER];  // Used to calculate sub_layer_dpb_info_present_flag
2607
2608    for(Int j = 0; j < getMaxTLayers(); j++)
2609    {
2610      // --------------------------------------------------------
2611      // To determine value of m_subLayerDpbInfoPresentFlag
2612      // --------------------------------------------------------
2613      if( j == 0 )  // checkFlagInner[0] is always 1
2614      {
2615        checkFlagInner[j] = true;     // Always signal sub-layer DPB information for the first sub-layer
2616      }
2617      else
2618      {
2619        checkFlagInner[j] = false;    // Initialize to be false. If the values of the current sub-layers matches with the earlier sub-layer,
2620                                      // then will be continue to be false - i.e. the j-th sub-layer DPB info is not signaled
2621        checkFlagInner[j] |= ( getMaxVpsNumReorderPics(i, j) != getMaxVpsNumReorderPics(i, j - 1) );
2622#if CHANGE_NUMSUBDPB_IDX
2623        for(Int subDpbIdx = 0; subDpbIdx < getNumSubDpbs(layerSetIdxForOutputLayerSet) && !checkFlagInner[j]; subDpbIdx++)  // If checkFlagInner[j] is true, break and signal the values
2624#else
2625        for(Int k = 0; k < getNumSubDpbs(i) && !checkFlagInner[j]; k++)  // If checkFlagInner[j] is true, break and signal the values
2626#endif
2627        {
2628          checkFlagInner[j] |= ( getMaxVpsDecPicBufferingMinus1(i, subDpbIdx, j - 1) != getMaxVpsDecPicBufferingMinus1(i, subDpbIdx, j) );
2629        }
2630#if RESOLUTION_BASED_DPB
2631        for(Int layerIdx = 0; layerIdx < this->getNumLayersInIdList(layerSetIdxForOutputLayerSet) && !checkFlagInner[j]; layerIdx++)  // If checkFlagInner[j] is true, break and signal the values
2632        {
2633          checkFlagInner[j] |= ( getMaxVpsLayerDecPicBuffMinus1(i, layerIdx, j - 1) != getMaxVpsLayerDecPicBuffMinus1(i, layerIdx, j) );
2634        }
2635#endif
2636      }
2637      // If checkFlagInner[j] = true, then some value needs to be signalled for the j-th sub-layer
2638      setSubLayerDpbInfoPresentFlag( i, j, checkFlagInner[j] );
2639    }
2640
2641    // --------------------------------------------------------
2642    // To determine value of m_subLayerFlagInfoPresentFlag
2643    // --------------------------------------------------------
2644
2645    for(Int j = 1; j < getMaxTLayers(); j++) // Check if DPB info of any of non-zero sub-layers is signaled. If so set flag to one
2646    {
2647      if( getSubLayerDpbInfoPresentFlag(i, j) )
2648      {
2649        checkFlagOuter = true;
2650        break;
2651      }
2652    }
2653    setSubLayerFlagInfoPresentFlag( i, checkFlagOuter );
2654  }
2655}
2656#endif
2657#if RESOLUTION_BASED_DPB
2658Void TComVPS::assignSubDpbIndices()
2659{
2660  RepFormat layerRepFormat  [MAX_LAYERS];
2661  RepFormat subDpbRepFormat [MAX_LAYERS];
2662
2663  for(Int lsIdx = 0; lsIdx < this->getNumLayerSets(); lsIdx++)
2664  {
2665    for(Int j = 0; j < MAX_LAYERS; j++)
2666    {
2667      layerRepFormat [j].init();
2668      subDpbRepFormat[j].init();
2669    }
2670
2671    // Assign resolution, bit-depth, colour format for each layer in the layer set
2672    for(Int i = 0; i < this->getNumLayersInIdList( lsIdx ); i++)
2673    {
2674      Int layerIdxInVps = this->getLayerIdInVps( this->getLayerSetLayerIdList(lsIdx, i) );
2675      Int repFormatIdx  = this->getVpsRepFormatIdx( layerIdxInVps );
2676      RepFormat* repFormat = this->getVpsRepFormat( repFormatIdx );
2677
2678      // Assign the rep_format() to the layer
2679      layerRepFormat[i] = *repFormat;
2680    }
2681
2682    // ----------------------------------------
2683    // Sub-DPB assignment
2684    // ----------------------------------------
2685    // For the base layer
2686    m_subDpbAssigned[lsIdx][0] = 0;
2687    subDpbRepFormat[0] = layerRepFormat[0];
2688
2689    // Sub-DPB counter
2690    Int subDpbCtr = 1;
2691
2692    for(Int i = 1; i < this->getNumLayersInIdList( lsIdx ); i++)
2693    {
2694      Bool newSubDpbFlag = true;
2695      for(Int j = 0; (j < subDpbCtr) && (newSubDpbFlag); j++)
2696      {
2697        if( RepFormat::checkSameSubDpb( layerRepFormat[i], subDpbRepFormat[j] ) )
2698        {
2699          // Belong to i-th sub-DPB
2700          m_subDpbAssigned[lsIdx][i] = j;
2701          newSubDpbFlag = false;
2702        }
2703      }
2704      if( newSubDpbFlag )
2705      {
2706        // New sub-DPB
2707        subDpbRepFormat[subDpbCtr] = layerRepFormat[i];
2708        m_subDpbAssigned[lsIdx][i] = subDpbCtr;
2709        subDpbCtr++;                                    // Increment # subDpbs
2710      }
2711    }
2712    m_numSubDpbs[lsIdx] = subDpbCtr;
2713  }
2714}
2715Int  TComVPS::findLayerIdxInLayerSet ( Int lsIdx, Int nuhLayerId )
2716{
2717  for(Int i = 0; i < this->getNumLayersInIdList(lsIdx); i++)
2718  {
2719    if( this->getLayerSetLayerIdList( lsIdx, i) == nuhLayerId )
2720    {
2721      return i;
2722    }
2723  }
2724  return -1;  // Layer not found
2725}
2726#endif
2727#if O0164_MULTI_LAYER_HRD
2728Void TComVPS::setBspHrdParameters( UInt hrdIdx, UInt frameRate, UInt numDU, UInt bitRate, Bool randomAccess )
2729{
2730  if( !getVpsVuiBspHrdPresentFlag() )
2731  {
2732    return;
2733  }
2734
2735  TComHRD *hrd = getBspHrd(hrdIdx);
2736
2737  Bool rateCnt = ( bitRate > 0 );
2738  hrd->setNalHrdParametersPresentFlag( rateCnt );
2739  hrd->setVclHrdParametersPresentFlag( rateCnt );
2740
2741  hrd->setSubPicCpbParamsPresentFlag( ( numDU > 1 ) );
2742
2743  if( hrd->getSubPicCpbParamsPresentFlag() )
2744  {
2745    hrd->setTickDivisorMinus2( 100 - 2 );                          //
2746    hrd->setDuCpbRemovalDelayLengthMinus1( 7 );                    // 8-bit precision ( plus 1 for last DU in AU )
2747    hrd->setSubPicCpbParamsInPicTimingSEIFlag( true );
2748    hrd->setDpbOutputDelayDuLengthMinus1( 5 + 7 );                 // With sub-clock tick factor of 100, at least 7 bits to have the same value as AU dpb delay
2749  }
2750  else
2751  {
2752    hrd->setSubPicCpbParamsInPicTimingSEIFlag( false ); 
2753  }
2754
2755  hrd->setBitRateScale( 4 );                                       // in units of 2~( 6 + 4 ) = 1,024 bps
2756  hrd->setCpbSizeScale( 6 );                                       // in units of 2~( 4 + 4 ) = 1,024 bit
2757  hrd->setDuCpbSizeScale( 6 );                                       // in units of 2~( 4 + 4 ) = 1,024 bit
2758
2759  hrd->setInitialCpbRemovalDelayLengthMinus1(15);                  // assuming 0.5 sec, log2( 90,000 * 0.5 ) = 16-bit
2760  if( randomAccess )
2761  {
2762    hrd->setCpbRemovalDelayLengthMinus1(5);                        // 32 = 2^5 (plus 1)
2763    hrd->setDpbOutputDelayLengthMinus1 (5);                        // 32 + 3 = 2^6
2764  }
2765  else
2766  {
2767    hrd->setCpbRemovalDelayLengthMinus1(9);                        // max. 2^10
2768    hrd->setDpbOutputDelayLengthMinus1 (9);                        // max. 2^10
2769  }
2770
2771  /*
2772  Note: only the case of "vps_max_temporal_layers_minus1 = 0" is supported.
2773  */
2774  Int i, j;
2775  UInt birateValue, cpbSizeValue;
2776  UInt ducpbSizeValue;
2777  UInt duBitRateValue = 0;
2778
2779  for( i = 0; i < MAX_TLAYER; i ++ )
2780  {
2781    hrd->setFixedPicRateFlag( i, 1 );
2782    hrd->setPicDurationInTcMinus1( i, 0 );
2783    hrd->setLowDelayHrdFlag( i, 0 );
2784    hrd->setCpbCntMinus1( i, 0 );
2785
2786    birateValue  = bitRate;
2787    cpbSizeValue = bitRate;                                     // 1 second
2788    ducpbSizeValue = bitRate/numDU;
2789    duBitRateValue = bitRate;
2790    for( j = 0; j < ( hrd->getCpbCntMinus1( i ) + 1 ); j ++ )
2791    {
2792      hrd->setBitRateValueMinus1( i, j, 0, ( birateValue  - 1 ) );
2793      hrd->setCpbSizeValueMinus1( i, j, 0, ( cpbSizeValue - 1 ) );
2794      hrd->setDuCpbSizeValueMinus1( i, j, 0, ( ducpbSizeValue - 1 ) );
2795      hrd->setCbrFlag( i, j, 0, ( j == 0 ) );
2796
2797      hrd->setBitRateValueMinus1( i, j, 1, ( birateValue  - 1) );
2798      hrd->setCpbSizeValueMinus1( i, j, 1, ( cpbSizeValue - 1 ) );
2799      hrd->setDuCpbSizeValueMinus1( i, j, 1, ( ducpbSizeValue - 1 ) );
2800      hrd->setDuBitRateValueMinus1( i, j, 1, ( duBitRateValue - 1 ) );
2801      hrd->setCbrFlag( i, j, 1, ( j == 0 ) );
2802    }
2803  }
2804}
2805#endif
2806#if RESOLUTION_BASED_DPB
2807// RepFormat Assignment operator
2808RepFormat& RepFormat::operator= (const RepFormat &other)
2809{
2810  if( this != &other)
2811  {
2812    m_chromaAndBitDepthVpsPresentFlag = other.m_chromaAndBitDepthVpsPresentFlag;
2813    m_chromaFormatVpsIdc              = other.m_chromaFormatVpsIdc;
2814    m_separateColourPlaneVpsFlag      = other.m_separateColourPlaneVpsFlag;
2815    m_picWidthVpsInLumaSamples        = other.m_picWidthVpsInLumaSamples;
2816    m_picHeightVpsInLumaSamples       = other.m_picHeightVpsInLumaSamples;
2817    m_bitDepthVpsLuma                 = other.m_bitDepthVpsLuma;
2818    m_bitDepthVpsChroma               = other.m_bitDepthVpsChroma;
2819  }
2820  return *this;
2821}
2822
2823// Check whether x and y share the same resolution, chroma format and bit-depth.
2824Bool RepFormat::checkSameSubDpb(const RepFormat &x, const RepFormat &y)
2825{
2826  return (    (x.m_chromaFormatVpsIdc              == y.m_chromaFormatVpsIdc)
2827          &&  (x.m_picWidthVpsInLumaSamples        == y.m_picWidthVpsInLumaSamples)
2828          &&  (x.m_picHeightVpsInLumaSamples       == y.m_picHeightVpsInLumaSamples)
2829          &&  (x.m_bitDepthVpsLuma                 == y.m_bitDepthVpsLuma)
2830          &&  (x.m_bitDepthVpsChroma               == y.m_bitDepthVpsChroma)
2831          );
2832}
2833#endif
2834// ------------------------------------------------------------------------------------------------
2835// Sequence parameter set (SPS)
2836// ------------------------------------------------------------------------------------------------
2837
2838TComSPS::TComSPS()
2839: m_SPSId                     (  0)
2840, m_VPSId                     (  0)
2841, m_chromaFormatIdc           (CHROMA_420)
2842, m_uiMaxTLayers              (  1)
2843// Structure
2844, m_picWidthInLumaSamples     (352)
2845, m_picHeightInLumaSamples    (288)
2846, m_log2MinCodingBlockSize    (  0)
2847, m_log2DiffMaxMinCodingBlockSize (0)
2848, m_uiMaxCUWidth              ( 32)
2849, m_uiMaxCUHeight             ( 32)
2850, m_uiMaxCUDepth              (  3)
2851, m_bLongTermRefsPresent      (false)
2852, m_uiQuadtreeTULog2MaxSize   (  0)
2853, m_uiQuadtreeTULog2MinSize   (  0)
2854, m_uiQuadtreeTUMaxDepthInter (  0)
2855, m_uiQuadtreeTUMaxDepthIntra (  0)
2856// Tool list
2857, m_usePCM                   (false)
2858, m_pcmLog2MaxSize            (  5)
2859, m_uiPCMLog2MinSize          (  7)
2860, m_bitDepthY                 (  8)
2861, m_bitDepthC                 (  8)
2862, m_qpBDOffsetY               (  0)
2863, m_qpBDOffsetC               (  0)
2864, m_uiPCMBitDepthLuma         (  8)
2865, m_uiPCMBitDepthChroma       (  8)
2866, m_bPCMFilterDisableFlag     (false)
2867, m_uiBitsForPOC              (  8)
2868, m_numLongTermRefPicSPS    (  0) 
2869, m_uiMaxTrSize               ( 32)
2870, m_bUseSAO                   (false) 
2871, m_bTemporalIdNestingFlag    (false)
2872, m_scalingListEnabledFlag    (false)
2873, m_useStrongIntraSmoothing   (false)
2874, m_vuiParametersPresentFlag  (false)
2875, m_vuiParameters             ()
2876#if SVC_EXTENSION
2877, m_layerId                   ( 0 )
2878, m_numScaledRefLayerOffsets  ( 0 )
2879#if REPN_FORMAT_IN_VPS
2880, m_updateRepFormatFlag       (false)
2881#if O0096_REP_FORMAT_INDEX
2882, m_updateRepFormatIndex      (0)
2883#endif
2884#endif
2885#if SCALINGLIST_INFERRING
2886, m_inferScalingListFlag ( false )
2887, m_scalingListRefLayerId ( 0 )
2888#endif
2889#endif //SVC_EXTENSION
2890{
2891  for ( Int i = 0; i < MAX_TLAYER; i++ )
2892  {
2893    m_uiMaxLatencyIncrease[i] = 0;
2894    m_uiMaxDecPicBuffering[i] = 1;
2895    m_numReorderPics[i]       = 0;
2896  }
2897  m_scalingList = new TComScalingList;
2898  ::memset(m_ltRefPicPocLsbSps, 0, sizeof(m_ltRefPicPocLsbSps));
2899  ::memset(m_usedByCurrPicLtSPSFlag, 0, sizeof(m_usedByCurrPicLtSPSFlag));
2900
2901#if P0312_VERT_PHASE_ADJ
2902  ::memset(m_vertPhasePositionEnableFlag, 0, sizeof(m_vertPhasePositionEnableFlag));
2903#endif
2904}
2905
2906TComSPS::~TComSPS()
2907{
2908#if SCALINGLIST_INFERRING
2909  if( !m_inferScalingListFlag )
2910#endif
2911  delete m_scalingList;
2912  m_RPSList.destroy();
2913}
2914
2915Void  TComSPS::createRPSList( Int numRPS )
2916{ 
2917  m_RPSList.destroy();
2918  m_RPSList.create(numRPS);
2919}
2920
2921Void TComSPS::setHrdParameters( UInt frameRate, UInt numDU, UInt bitRate, Bool randomAccess )
2922{
2923  if( !getVuiParametersPresentFlag() )
2924  {
2925    return;
2926  }
2927
2928  TComVUI *vui = getVuiParameters();
2929  TComHRD *hrd = vui->getHrdParameters();
2930
2931  TimingInfo *timingInfo = vui->getTimingInfo();
2932#if TIMING_INFO_NONZERO_LAYERID_SPS
2933  if( getLayerId() > 0 )
2934  {
2935    timingInfo->setTimingInfoPresentFlag( false );
2936  }
2937  else
2938  {
2939#endif
2940    timingInfo->setTimingInfoPresentFlag( true );
2941    switch( frameRate )
2942    {
2943    case 24:
2944      timingInfo->setNumUnitsInTick( 1125000 );    timingInfo->setTimeScale    ( 27000000 );
2945      break;
2946    case 25:
2947      timingInfo->setNumUnitsInTick( 1080000 );    timingInfo->setTimeScale    ( 27000000 );
2948      break;
2949    case 30:
2950      timingInfo->setNumUnitsInTick( 900900 );     timingInfo->setTimeScale    ( 27000000 );
2951      break;
2952    case 50:
2953      timingInfo->setNumUnitsInTick( 540000 );     timingInfo->setTimeScale    ( 27000000 );
2954      break;
2955    case 60:
2956      timingInfo->setNumUnitsInTick( 450450 );     timingInfo->setTimeScale    ( 27000000 );
2957      break;
2958    default:
2959      timingInfo->setNumUnitsInTick( 1001 );       timingInfo->setTimeScale    ( 60000 );
2960      break;
2961    }
2962
2963    Bool rateCnt = ( bitRate > 0 );
2964    hrd->setNalHrdParametersPresentFlag( rateCnt );
2965    hrd->setVclHrdParametersPresentFlag( rateCnt );
2966
2967    hrd->setSubPicCpbParamsPresentFlag( ( numDU > 1 ) );
2968
2969    if( hrd->getSubPicCpbParamsPresentFlag() )
2970    {
2971      hrd->setTickDivisorMinus2( 100 - 2 );                          //
2972      hrd->setDuCpbRemovalDelayLengthMinus1( 7 );                    // 8-bit precision ( plus 1 for last DU in AU )
2973      hrd->setSubPicCpbParamsInPicTimingSEIFlag( true );
2974      hrd->setDpbOutputDelayDuLengthMinus1( 5 + 7 );                 // With sub-clock tick factor of 100, at least 7 bits to have the same value as AU dpb delay
2975    }
2976    else
2977    {
2978      hrd->setSubPicCpbParamsInPicTimingSEIFlag( false ); 
2979    }
2980
2981    hrd->setBitRateScale( 4 );                                       // in units of 2~( 6 + 4 ) = 1,024 bps
2982    hrd->setCpbSizeScale( 6 );                                       // in units of 2~( 4 + 4 ) = 1,024 bit
2983    hrd->setDuCpbSizeScale( 6 );                                       // in units of 2~( 4 + 4 ) = 1,024 bit
2984 
2985    hrd->setInitialCpbRemovalDelayLengthMinus1(15);                  // assuming 0.5 sec, log2( 90,000 * 0.5 ) = 16-bit
2986    if( randomAccess )
2987    {
2988      hrd->setCpbRemovalDelayLengthMinus1(5);                        // 32 = 2^5 (plus 1)
2989      hrd->setDpbOutputDelayLengthMinus1 (5);                        // 32 + 3 = 2^6
2990    }
2991    else
2992    {
2993      hrd->setCpbRemovalDelayLengthMinus1(9);                        // max. 2^10
2994      hrd->setDpbOutputDelayLengthMinus1 (9);                        // max. 2^10
2995    }
2996
2997/*
2998     Note: only the case of "vps_max_temporal_layers_minus1 = 0" is supported.
2999*/
3000    Int i, j;
3001    UInt birateValue, cpbSizeValue;
3002    UInt ducpbSizeValue;
3003    UInt duBitRateValue = 0;
3004
3005    for( i = 0; i < MAX_TLAYER; i ++ )
3006    {
3007      hrd->setFixedPicRateFlag( i, 1 );
3008      hrd->setPicDurationInTcMinus1( i, 0 );
3009      hrd->setLowDelayHrdFlag( i, 0 );
3010      hrd->setCpbCntMinus1( i, 0 );
3011
3012      birateValue  = bitRate;
3013      cpbSizeValue = bitRate;                                     // 1 second
3014      ducpbSizeValue = bitRate/numDU;
3015      duBitRateValue = bitRate;
3016      for( j = 0; j < ( hrd->getCpbCntMinus1( i ) + 1 ); j ++ )
3017      {
3018        hrd->setBitRateValueMinus1( i, j, 0, ( birateValue  - 1 ) );
3019        hrd->setCpbSizeValueMinus1( i, j, 0, ( cpbSizeValue - 1 ) );
3020        hrd->setDuCpbSizeValueMinus1( i, j, 0, ( ducpbSizeValue - 1 ) );
3021        hrd->setCbrFlag( i, j, 0, ( j == 0 ) );
3022
3023        hrd->setBitRateValueMinus1( i, j, 1, ( birateValue  - 1) );
3024        hrd->setCpbSizeValueMinus1( i, j, 1, ( cpbSizeValue - 1 ) );
3025        hrd->setDuCpbSizeValueMinus1( i, j, 1, ( ducpbSizeValue - 1 ) );
3026        hrd->setDuBitRateValueMinus1( i, j, 1, ( duBitRateValue - 1 ) );
3027        hrd->setCbrFlag( i, j, 1, ( j == 0 ) );
3028      }
3029    }
3030#if TIMING_INFO_NONZERO_LAYERID_SPS
3031  }
3032#endif
3033}
3034const Int TComSPS::m_winUnitX[]={1,2,2,1};
3035const Int TComSPS::m_winUnitY[]={1,2,1,1};
3036
3037#if O0098_SCALED_REF_LAYER_ID
3038Window& TComSPS::getScaledRefLayerWindowForLayer(Int layerId)
3039{
3040  static Window win;
3041
3042  for (Int i = 0; i < m_numScaledRefLayerOffsets; i++)
3043  {
3044    if (layerId == m_scaledRefLayerId[i])
3045    {
3046      return m_scaledRefLayerWindow[i];
3047    }
3048  }
3049
3050  win.resetWindow();  // scaled reference layer offsets are inferred to be zero when not present
3051  return win;
3052}
3053#endif
3054
3055TComPPS::TComPPS()
3056: m_PPSId                       (0)
3057, m_SPSId                       (0)
3058, m_picInitQPMinus26            (0)
3059, m_useDQP                      (false)
3060, m_bConstrainedIntraPred       (false)
3061, m_bSliceChromaQpFlag          (false)
3062, m_pcSPS                       (NULL)
3063, m_uiMaxCuDQPDepth             (0)
3064, m_uiMinCuDQPSize              (0)
3065, m_chromaCbQpOffset            (0)
3066, m_chromaCrQpOffset            (0)
3067, m_numRefIdxL0DefaultActive    (1)
3068, m_numRefIdxL1DefaultActive    (1)
3069, m_TransquantBypassEnableFlag  (false)
3070, m_useTransformSkip             (false)
3071, m_dependentSliceSegmentsEnabledFlag    (false)
3072, m_tilesEnabledFlag               (false)
3073, m_entropyCodingSyncEnabledFlag   (false)
3074, m_loopFilterAcrossTilesEnabledFlag  (true)
3075, m_uniformSpacingFlag           (0)
3076, m_iNumColumnsMinus1            (0)
3077, m_puiColumnWidth               (NULL)
3078, m_iNumRowsMinus1               (0)
3079, m_puiRowHeight                 (NULL)
3080, m_iNumSubstreams             (1)
3081, m_signHideFlag(0)
3082, m_cabacInitPresentFlag        (false)
3083, m_encCABACTableIdx            (I_SLICE)
3084, m_sliceHeaderExtensionPresentFlag    (false)
3085, m_loopFilterAcrossSlicesEnabledFlag (false)
3086, m_listsModificationPresentFlag(  0)
3087, m_numExtraSliceHeaderBits(0)
3088#if SCALINGLIST_INFERRING
3089, m_inferScalingListFlag ( false )
3090, m_scalingListRefLayerId ( 0 )
3091#endif
3092#if POC_RESET_IDC
3093, m_pocResetInfoPresentFlag   (false)
3094#endif
3095{
3096  m_scalingList = new TComScalingList;
3097}
3098
3099TComPPS::~TComPPS()
3100{
3101  if( m_iNumColumnsMinus1 > 0 && m_uniformSpacingFlag == 0 )
3102  {
3103    if (m_puiColumnWidth) delete [] m_puiColumnWidth; 
3104    m_puiColumnWidth = NULL;
3105  }
3106  if( m_iNumRowsMinus1 > 0 && m_uniformSpacingFlag == 0 )
3107  {
3108    if (m_puiRowHeight) delete [] m_puiRowHeight;
3109    m_puiRowHeight = NULL;
3110  }
3111
3112#if SCALINGLIST_INFERRING
3113  if( !m_inferScalingListFlag )
3114#endif
3115  delete m_scalingList;
3116}
3117
3118TComReferencePictureSet::TComReferencePictureSet()
3119: m_numberOfPictures (0)
3120, m_numberOfNegativePictures (0)
3121, m_numberOfPositivePictures (0)
3122, m_numberOfLongtermPictures (0)
3123, m_interRPSPrediction (0) 
3124, m_deltaRIdxMinus1 (0)   
3125, m_deltaRPS (0) 
3126, m_numRefIdc (0) 
3127{
3128  ::memset( m_deltaPOC, 0, sizeof(m_deltaPOC) );
3129  ::memset( m_POC, 0, sizeof(m_POC) );
3130  ::memset( m_used, 0, sizeof(m_used) );
3131  ::memset( m_refIdc, 0, sizeof(m_refIdc) );
3132}
3133
3134TComReferencePictureSet::~TComReferencePictureSet()
3135{
3136}
3137
3138Void TComReferencePictureSet::setUsed(Int bufferNum, Bool used)
3139{
3140  m_used[bufferNum] = used;
3141}
3142
3143Void TComReferencePictureSet::setDeltaPOC(Int bufferNum, Int deltaPOC)
3144{
3145  m_deltaPOC[bufferNum] = deltaPOC;
3146}
3147
3148Void TComReferencePictureSet::setNumberOfPictures(Int numberOfPictures)
3149{
3150  m_numberOfPictures = numberOfPictures;
3151}
3152
3153Int TComReferencePictureSet::getUsed(Int bufferNum)
3154{
3155  return m_used[bufferNum];
3156}
3157
3158Int TComReferencePictureSet::getDeltaPOC(Int bufferNum)
3159{
3160  return m_deltaPOC[bufferNum];
3161}
3162
3163Int TComReferencePictureSet::getNumberOfPictures()
3164{
3165  return m_numberOfPictures;
3166}
3167
3168Int TComReferencePictureSet::getPOC(Int bufferNum)
3169{
3170  return m_POC[bufferNum];
3171}
3172
3173Void TComReferencePictureSet::setPOC(Int bufferNum, Int POC)
3174{
3175  m_POC[bufferNum] = POC;
3176}
3177
3178Bool TComReferencePictureSet::getCheckLTMSBPresent(Int bufferNum)
3179{
3180  return m_bCheckLTMSB[bufferNum];
3181}
3182
3183Void TComReferencePictureSet::setCheckLTMSBPresent(Int bufferNum, Bool b)
3184{
3185  m_bCheckLTMSB[bufferNum] = b;
3186}
3187
3188/** set the reference idc value at uiBufferNum entry to the value of iRefIdc
3189 * \param uiBufferNum
3190 * \param iRefIdc
3191 * \returns Void
3192 */
3193Void TComReferencePictureSet::setRefIdc(Int bufferNum, Int refIdc)
3194{
3195  m_refIdc[bufferNum] = refIdc;
3196}
3197
3198/** get the reference idc value at uiBufferNum
3199 * \param uiBufferNum
3200 * \returns Int
3201 */
3202Int  TComReferencePictureSet::getRefIdc(Int bufferNum)
3203{
3204  return m_refIdc[bufferNum];
3205}
3206
3207/** Sorts the deltaPOC and Used by current values in the RPS based on the deltaPOC values.
3208 *  deltaPOC values are sorted with -ve values before the +ve values.  -ve values are in decreasing order.
3209 *  +ve values are in increasing order.
3210 * \returns Void
3211 */
3212Void TComReferencePictureSet::sortDeltaPOC()
3213{
3214  // sort in increasing order (smallest first)
3215  for(Int j=1; j < getNumberOfPictures(); j++)
3216  { 
3217    Int deltaPOC = getDeltaPOC(j);
3218    Bool used = getUsed(j);
3219    for (Int k=j-1; k >= 0; k--)
3220    {
3221      Int temp = getDeltaPOC(k);
3222      if (deltaPOC < temp)
3223      {
3224        setDeltaPOC(k+1, temp);
3225        setUsed(k+1, getUsed(k));
3226        setDeltaPOC(k, deltaPOC);
3227        setUsed(k, used);
3228      }
3229    }
3230  }
3231  // flip the negative values to largest first
3232  Int numNegPics = getNumberOfNegativePictures();
3233  for(Int j=0, k=numNegPics-1; j < numNegPics>>1; j++, k--)
3234  { 
3235    Int deltaPOC = getDeltaPOC(j);
3236    Bool used = getUsed(j);
3237    setDeltaPOC(j, getDeltaPOC(k));
3238    setUsed(j, getUsed(k));
3239    setDeltaPOC(k, deltaPOC);
3240    setUsed(k, used);
3241  }
3242}
3243
3244/** Prints the deltaPOC and RefIdc (if available) values in the RPS.
3245 *  A "*" is added to the deltaPOC value if it is Used bu current.
3246 * \returns Void
3247 */
3248Void TComReferencePictureSet::printDeltaPOC()
3249{
3250  printf("DeltaPOC = { ");
3251  for(Int j=0; j < getNumberOfPictures(); j++)
3252  {
3253    printf("%d%s ", getDeltaPOC(j), (getUsed(j)==1)?"*":"");
3254  } 
3255  if (getInterRPSPrediction()) 
3256  {
3257    printf("}, RefIdc = { ");
3258    for(Int j=0; j < getNumRefIdc(); j++)
3259    {
3260      printf("%d ", getRefIdc(j));
3261    } 
3262  }
3263  printf("}\n");
3264}
3265
3266TComRPSList::TComRPSList()
3267:m_referencePictureSets (NULL)
3268{
3269}
3270
3271TComRPSList::~TComRPSList()
3272{
3273}
3274
3275Void TComRPSList::create( Int numberOfReferencePictureSets)
3276{
3277  m_numberOfReferencePictureSets = numberOfReferencePictureSets;
3278  m_referencePictureSets = new TComReferencePictureSet[numberOfReferencePictureSets];
3279}
3280
3281Void TComRPSList::destroy()
3282{
3283  if (m_referencePictureSets)
3284  {
3285    delete [] m_referencePictureSets;
3286  }
3287  m_numberOfReferencePictureSets = 0;
3288  m_referencePictureSets = NULL;
3289}
3290
3291
3292
3293TComReferencePictureSet* TComRPSList::getReferencePictureSet(Int referencePictureSetNum)
3294{
3295  return &m_referencePictureSets[referencePictureSetNum];
3296}
3297
3298Int TComRPSList::getNumberOfReferencePictureSets()
3299{
3300  return m_numberOfReferencePictureSets;
3301}
3302
3303Void TComRPSList::setNumberOfReferencePictureSets(Int numberOfReferencePictureSets)
3304{
3305  m_numberOfReferencePictureSets = numberOfReferencePictureSets;
3306}
3307
3308TComRefPicListModification::TComRefPicListModification()
3309: m_bRefPicListModificationFlagL0 (false)
3310, m_bRefPicListModificationFlagL1 (false)
3311{
3312  ::memset( m_RefPicSetIdxL0, 0, sizeof(m_RefPicSetIdxL0) );
3313  ::memset( m_RefPicSetIdxL1, 0, sizeof(m_RefPicSetIdxL1) );
3314}
3315
3316TComRefPicListModification::~TComRefPicListModification()
3317{
3318}
3319
3320TComScalingList::TComScalingList()
3321{
3322  init();
3323}
3324
3325TComScalingList::~TComScalingList()
3326{
3327  destroy();
3328}
3329
3330/** set default quantization matrix to array
3331*/
3332Void TComSlice::setDefaultScalingList()
3333{
3334  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
3335  {
3336    for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++)
3337    {
3338      getScalingList()->processDefaultMatrix(sizeId, listId);
3339    }
3340  }
3341}
3342/** check if use default quantization matrix
3343 * \returns true if use default quantization matrix in all size
3344*/
3345Bool TComSlice::checkDefaultScalingList()
3346{
3347  UInt defaultCounter=0;
3348
3349  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
3350  {
3351    for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++)
3352    {
3353      if( !memcmp(getScalingList()->getScalingListAddress(sizeId,listId), getScalingList()->getScalingListDefaultAddress(sizeId, listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])) // check value of matrix
3354     && ((sizeId < SCALING_LIST_16x16) || (getScalingList()->getScalingListDC(sizeId,listId) == 16))) // check DC value
3355      {
3356        defaultCounter++;
3357      }
3358    }
3359  }
3360  return (defaultCounter == (SCALING_LIST_NUM * SCALING_LIST_SIZE_NUM - 4)) ? false : true; // -4 for 32x32
3361}
3362
3363/** get scaling matrix from RefMatrixID
3364 * \param sizeId size index
3365 * \param Index of input matrix
3366 * \param Index of reference matrix
3367 */
3368Void TComScalingList::processRefMatrix( UInt sizeId, UInt listId , UInt refListId )
3369{
3370  ::memcpy(getScalingListAddress(sizeId, listId),((listId == refListId)? getScalingListDefaultAddress(sizeId, refListId): getScalingListAddress(sizeId, refListId)),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
3371}
3372
3373/** parse syntax infomation
3374 *  \param pchFile syntax infomation
3375 *  \returns false if successful
3376 */
3377Bool TComScalingList::xParseScalingList(Char* pchFile)
3378{
3379  FILE *fp;
3380  Char line[1024];
3381  UInt sizeIdc,listIdc;
3382  UInt i,size = 0;
3383  Int *src=0,data;
3384  Char *ret;
3385  UInt  retval;
3386
3387  if((fp = fopen(pchFile,"r")) == (FILE*)NULL)
3388  {
3389    printf("can't open file %s :: set Default Matrix\n",pchFile);
3390    return true;
3391  }
3392
3393  for(sizeIdc = 0; sizeIdc < SCALING_LIST_SIZE_NUM; sizeIdc++)
3394  {
3395    size = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeIdc]);
3396    for(listIdc = 0; listIdc < g_scalingListNum[sizeIdc]; listIdc++)
3397    {
3398      src = getScalingListAddress(sizeIdc, listIdc);
3399
3400      fseek(fp,0,0);
3401      do 
3402      {
3403        ret = fgets(line, 1024, fp);
3404        if ((ret==NULL)||(strstr(line, MatrixType[sizeIdc][listIdc])==NULL && feof(fp)))
3405        {
3406          printf("Error: can't read Matrix :: set Default Matrix\n");
3407          return true;
3408        }
3409      }
3410      while (strstr(line, MatrixType[sizeIdc][listIdc]) == NULL);
3411      for (i=0; i<size; i++)
3412      {
3413        retval = fscanf(fp, "%d,", &data);
3414        if (retval!=1)
3415        {
3416          printf("Error: can't read Matrix :: set Default Matrix\n");
3417          return true;
3418        }
3419        src[i] = data;
3420      }
3421      //set DC value for default matrix check
3422      setScalingListDC(sizeIdc,listIdc,src[0]);
3423
3424      if(sizeIdc > SCALING_LIST_8x8)
3425      {
3426        fseek(fp,0,0);
3427        do 
3428        {
3429          ret = fgets(line, 1024, fp);
3430          if ((ret==NULL)||(strstr(line, MatrixType_DC[sizeIdc][listIdc])==NULL && feof(fp)))
3431          {
3432            printf("Error: can't read DC :: set Default Matrix\n");
3433            return true;
3434          }
3435        }
3436        while (strstr(line, MatrixType_DC[sizeIdc][listIdc]) == NULL);
3437        retval = fscanf(fp, "%d,", &data);
3438        if (retval!=1)
3439        {
3440          printf("Error: can't read Matrix :: set Default Matrix\n");
3441          return true;
3442        }
3443        //overwrite DC value when size of matrix is larger than 16x16
3444        setScalingListDC(sizeIdc,listIdc,data);
3445      }
3446    }
3447  }
3448  fclose(fp);
3449  return false;
3450}
3451
3452/** initialization process of quantization matrix array
3453 */
3454Void TComScalingList::init()
3455{
3456  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
3457  {
3458    for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++)
3459    {
3460      m_scalingListCoef[sizeId][listId] = new Int [min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])];
3461    }
3462  }
3463  m_scalingListCoef[SCALING_LIST_32x32][3] = m_scalingListCoef[SCALING_LIST_32x32][1]; // copy address for 32x32
3464}
3465
3466/** destroy quantization matrix array
3467 */
3468Void TComScalingList::destroy()
3469{
3470  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
3471  {
3472    for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++)
3473    {
3474      if(m_scalingListCoef[sizeId][listId]) delete [] m_scalingListCoef[sizeId][listId];
3475    }
3476  }
3477}
3478
3479/** get default address of quantization matrix
3480 * \param sizeId size index
3481 * \param listId list index
3482 * \returns pointer of quantization matrix
3483 */
3484Int* TComScalingList::getScalingListDefaultAddress(UInt sizeId, UInt listId)
3485{
3486  Int *src = 0;
3487  switch(sizeId)
3488  {
3489    case SCALING_LIST_4x4:
3490      src = g_quantTSDefault4x4;
3491      break;
3492    case SCALING_LIST_8x8:
3493      src = (listId<3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
3494      break;
3495    case SCALING_LIST_16x16:
3496      src = (listId<3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
3497      break;
3498    case SCALING_LIST_32x32:
3499      src = (listId<1) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
3500      break;
3501    default:
3502      assert(0);
3503      src = NULL;
3504      break;
3505  }
3506  return src;
3507}
3508
3509/** process of default matrix
3510 * \param sizeId size index
3511 * \param Index of input matrix
3512 */
3513Void TComScalingList::processDefaultMatrix(UInt sizeId, UInt listId)
3514{
3515  ::memcpy(getScalingListAddress(sizeId, listId),getScalingListDefaultAddress(sizeId,listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
3516  setScalingListDC(sizeId,listId,SCALING_LIST_DC);
3517}
3518
3519/** check DC value of matrix for default matrix signaling
3520 */
3521Void TComScalingList::checkDcOfMatrix()
3522{
3523  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
3524  {
3525    for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++)
3526    {
3527      //check default matrix?
3528      if(getScalingListDC(sizeId,listId) == 0)
3529      {
3530        processDefaultMatrix(sizeId, listId);
3531      }
3532    }
3533  }
3534}
3535
3536ParameterSetManager::ParameterSetManager()
3537#if SVC_EXTENSION
3538: m_spsMap(MAX_NUM_SPS)
3539, m_ppsMap(MAX_NUM_PPS)
3540, m_activeSPSId(-1)
3541, m_activePPSId(-1)
3542#else
3543: m_vpsMap(MAX_NUM_VPS)
3544, m_spsMap(MAX_NUM_SPS)
3545, m_ppsMap(MAX_NUM_PPS)
3546, m_activeVPSId(-1)
3547, m_activeSPSId(-1)
3548, m_activePPSId(-1)
3549#endif
3550{
3551}
3552
3553
3554ParameterSetManager::~ParameterSetManager()
3555{
3556}
3557
3558//! activate a SPS from a active parameter sets SEI message
3559//! \returns true, if activation is successful
3560Bool ParameterSetManager::activateSPSWithSEI(Int spsId)
3561{
3562  TComSPS *sps = m_spsMap.getPS(spsId);
3563  if (sps)
3564  {
3565    Int vpsId = sps->getVPSId();
3566    if (m_vpsMap.getPS(vpsId))
3567    {
3568      m_activeVPSId = vpsId;
3569      m_activeSPSId = spsId;
3570      return true;
3571    }
3572    else
3573    {
3574      printf("Warning: tried to activate SPS using an Active parameter sets SEI message. Referenced VPS does not exist.");
3575    }
3576  }
3577  else
3578  {
3579    printf("Warning: tried to activate non-existing SPS using an Active parameter sets SEI message.");
3580  }
3581  return false;
3582}
3583
3584//! activate a PPS and depending on isIDR parameter also SPS and VPS
3585//! \returns true, if activation is successful
3586Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP)
3587{
3588  TComPPS *pps = m_ppsMap.getPS(ppsId);
3589  if (pps)
3590  {
3591    Int spsId = pps->getSPSId();
3592    if (!isIRAP && (spsId != m_activeSPSId))
3593    {
3594      printf("Warning: tried to activate PPS referring to a inactive SPS at non-IRAP.");
3595      return false;
3596    }
3597    TComSPS *sps = m_spsMap.getPS(spsId);
3598    if (sps)
3599    {
3600      Int vpsId = sps->getVPSId();
3601      if (!isIRAP && (vpsId != m_activeVPSId))
3602      {
3603        printf("Warning: tried to activate PPS referring to a inactive VPS at non-IRAP.");
3604        return false;
3605      }
3606      if (m_vpsMap.getPS(vpsId))
3607      {
3608        m_activePPSId = ppsId;
3609        m_activeVPSId = vpsId;
3610        m_activeSPSId = spsId;
3611
3612        return true;
3613      }
3614      else
3615      {
3616        printf("Warning: tried to activate PPS that refers to a non-existing VPS.");
3617      }
3618    }
3619    else
3620    {
3621      printf("Warning: tried to activate a PPS that refers to a non-existing SPS.");
3622    }
3623  }
3624  else
3625  {
3626    printf("Warning: tried to activate non-existing PPS.");
3627  }
3628  return false;
3629}
3630
3631ProfileTierLevel::ProfileTierLevel()
3632  : m_profileSpace    (0)
3633  , m_tierFlag        (false)
3634  , m_profileIdc      (0)
3635  , m_levelIdc        (0)
3636, m_progressiveSourceFlag  (false)
3637, m_interlacedSourceFlag   (false)
3638, m_nonPackedConstraintFlag(false)
3639, m_frameOnlyConstraintFlag(false)
3640{
3641  ::memset(m_profileCompatibilityFlag, 0, sizeof(m_profileCompatibilityFlag));
3642}
3643#if VPS_EXTN_PROFILE_INFO
3644Void ProfileTierLevel::copyProfileInfo(ProfileTierLevel *ptl)
3645{
3646  this->setProfileSpace          ( ptl->getProfileSpace()      );
3647  this->setTierFlag              ( ptl->getTierFlag()          );
3648  this->setProfileIdc            ( ptl->getProfileIdc()        );
3649  for(Int j = 0; j < 32; j++)
3650  {
3651    this->setProfileCompatibilityFlag(j, ptl->getProfileCompatibilityFlag(j));
3652  }
3653  this->setProgressiveSourceFlag  ( ptl->getProgressiveSourceFlag()  );
3654  this->setInterlacedSourceFlag   ( ptl->getInterlacedSourceFlag()   );
3655  this->setNonPackedConstraintFlag( ptl->getNonPackedConstraintFlag());
3656  this->setFrameOnlyConstraintFlag( ptl->getFrameOnlyConstraintFlag()); 
3657}
3658#endif
3659
3660TComPTL::TComPTL()
3661{
3662  ::memset(m_subLayerProfilePresentFlag, 0, sizeof(m_subLayerProfilePresentFlag));
3663  ::memset(m_subLayerLevelPresentFlag,   0, sizeof(m_subLayerLevelPresentFlag  ));
3664}
3665#if VPS_EXTN_PROFILE_INFO
3666Void TComPTL::copyProfileInfo(TComPTL *ptl)
3667{
3668  // Copy all information related to general profile
3669  this->getGeneralPTL()->copyProfileInfo(ptl->getGeneralPTL());
3670}
3671#endif
3672
3673#if SVC_EXTENSION
3674#if AVC_SYNTAX
3675Void TComSlice::initBaseLayerRPL( TComSlice *pcSlice )
3676{
3677// Assumed that RPL of the base layer is same to the EL, otherwise this information should be also dumped and read from the metadata file
3678  setPOC( pcSlice->getPOC() );
3679  if( pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA )
3680  {
3681    setSliceType( I_SLICE );
3682  }
3683  else
3684  {
3685    setSliceType( pcSlice->getSliceType() );
3686  }
3687
3688  if( this->isIntra() )
3689  {
3690    return;
3691  }
3692
3693  //initialize reference POC of BL
3694  for( Int iRefPicList = 0; iRefPicList < 2; iRefPicList++ )
3695  {
3696    RefPicList eRefPicList = RefPicList( iRefPicList );
3697
3698    assert( pcSlice->getNumRefIdx( eRefPicList) >= 0 );
3699    setNumRefIdx( eRefPicList, pcSlice->getNumRefIdx( eRefPicList ) - 1 );
3700    assert( getNumRefIdx( eRefPicList) <= MAX_NUM_REF);
3701
3702    for(Int refIdx = 0; refIdx < getNumRefIdx( eRefPicList ); refIdx++) 
3703    {
3704      setRefPOC( pcSlice->getRefPic( eRefPicList, refIdx )->getPOC(), eRefPicList, refIdx );
3705      setRefPic( pcSlice->getRefPic( eRefPicList, refIdx ), eRefPicList, refIdx );
3706      /*
3707      // should be set if the base layer has its own instance of the reference picture lists, currently EL RPL is reused.
3708      getRefPic( eRefPicList, refIdx )->setLayerId( 0 );
3709      getRefPic( eRefPicList, refIdx )->setIsLongTerm( pcSlice->getRefPic( eRefPicList, refIdx )->getIsLongTerm() );     
3710      */
3711
3712    }
3713  } 
3714  return;
3715}
3716#endif
3717
3718Bool TComSlice::setBaseColPic(  TComList<TComPic*>& rcListPic, UInt refLayerIdc )
3719{ 
3720  if(m_layerId == 0)
3721  {
3722    memset( m_pcBaseColPic, 0, sizeof( m_pcBaseColPic ) );
3723    return false;
3724  }       
3725#if POC_RESET_FLAG
3726  TComPic* pic = xGetRefPic( rcListPic, m_bPocResetFlag ? 0 : m_iPOC );
3727
3728  if( pic )
3729  {
3730    setBaseColPic(refLayerIdc, pic );
3731  }
3732  else
3733  {
3734    return false;
3735  }
3736 
3737  return true;
3738#else
3739  setBaseColPic(refLayerIdc, xGetRefPic(rcListPic, getPOC())); 
3740#endif
3741}
3742
3743#if MFM_ENCCONSTRAINT
3744TComPic* TComSlice::getBaseColPic(  TComList<TComPic*>& rcListPic )
3745{
3746#if POC_RESET_FLAG
3747  return xGetRefPic( rcListPic, m_bPocResetFlag ? 0 : m_iPOC );
3748#else
3749  return xGetRefPic( rcListPic, m_iPOC );
3750#endif
3751}
3752#endif
3753
3754#if REF_IDX_MFM
3755Void TComSlice::setRefPOCListILP( TComPic** ilpPic, TComPic** pcRefPicRL )
3756{
3757  for( UInt i = 0; i < m_activeNumILRRefIdx; i++ )
3758  {
3759    UInt refLayerIdc = m_interLayerPredLayerIdc[i];
3760
3761    TComPic* pcRefPicBL = pcRefPicRL[refLayerIdc];
3762
3763    //set reference picture POC of each ILP reference
3764    Int thePoc = ilpPic[refLayerIdc]->getPOC(); 
3765    assert(thePoc == pcRefPicBL->getPOC());
3766
3767    ilpPic[refLayerIdc]->getSlice(0)->setBaseColPic( refLayerIdc, pcRefPicBL );
3768
3769    //copy layer id from the reference layer   
3770    ilpPic[refLayerIdc]->setLayerId( pcRefPicBL->getLayerId() );
3771
3772    //copy slice type from the reference layer
3773    ilpPic[refLayerIdc]->getSlice(0)->setSliceType( pcRefPicBL->getSlice(0)->getSliceType() );
3774
3775    //copy "used for reference"
3776    ilpPic[refLayerIdc]->getSlice(0)->setReferenced( pcRefPicBL->getSlice(0)->isReferenced() );
3777
3778    for( Int refList = 0; refList < 2; refList++ )
3779    {
3780      RefPicList refPicList = RefPicList( refList );
3781
3782      //set reference POC of ILP
3783      ilpPic[refLayerIdc]->getSlice(0)->setNumRefIdx(refPicList, pcRefPicBL->getSlice(0)->getNumRefIdx(refPicList));
3784      assert(ilpPic[refLayerIdc]->getSlice(0)->getNumRefIdx(refPicList) >= 0);
3785      assert(ilpPic[refLayerIdc]->getSlice(0)->getNumRefIdx(refPicList) <= MAX_NUM_REF);
3786
3787      //initialize reference POC of ILP
3788      for(Int refIdx = 0; refIdx < pcRefPicBL->getSlice(0)->getNumRefIdx(refPicList); refIdx++)
3789      {
3790        ilpPic[refLayerIdc]->getSlice(0)->setRefPOC(pcRefPicBL->getSlice(0)->getRefPOC(refPicList, refIdx), refPicList, refIdx);
3791        ilpPic[refLayerIdc]->getSlice(0)->setRefPic(pcRefPicBL->getSlice(0)->getRefPic(refPicList, refIdx), refPicList, refIdx);
3792      }
3793
3794      for(Int refIdx = pcRefPicBL->getSlice(0)->getNumRefIdx(refPicList); refIdx < MAX_NUM_REF; refIdx++) 
3795      { 
3796        ilpPic[refLayerIdc]->getSlice(0)->setRefPOC(0, refPicList, refIdx); 
3797        ilpPic[refLayerIdc]->getSlice(0)->setRefPic(NULL, refPicList, refIdx); 
3798      }
3799
3800      //copy reference pictures' marking from the reference layer
3801      for(Int j = 0; j < MAX_NUM_REF + 1; j++)
3802      {
3803        ilpPic[refLayerIdc]->getSlice(0)->setIsUsedAsLongTerm(refList, j, pcRefPicBL->getSlice(0)->getIsUsedAsLongTerm(refList, j));
3804      }
3805    }
3806  }
3807  return;
3808}
3809#endif
3810
3811Void TComSlice::setILRPic(TComPic **pcIlpPic)
3812{
3813  for( Int i = 0; i < m_activeNumILRRefIdx; i++ )
3814  {
3815    Int refLayerIdc = m_interLayerPredLayerIdc[i];
3816
3817    if( pcIlpPic[refLayerIdc] )
3818    {
3819      pcIlpPic[refLayerIdc]->copyUpsampledPictureYuv( m_pcPic->getFullPelBaseRec( refLayerIdc ), pcIlpPic[refLayerIdc]->getPicYuvRec() );
3820      pcIlpPic[refLayerIdc]->getSlice(0)->setPOC( m_iPOC );
3821      pcIlpPic[refLayerIdc]->setLayerId( m_pcBaseColPic[refLayerIdc]->getLayerId() ); //set reference layerId
3822      pcIlpPic[refLayerIdc]->getPicYuvRec()->setBorderExtension( false );
3823      pcIlpPic[refLayerIdc]->getPicYuvRec()->extendPicBorder();
3824      for (Int j=0; j<pcIlpPic[refLayerIdc]->getPicSym()->getNumberOfCUsInFrame(); j++)    // set reference CU layerId
3825      {
3826        pcIlpPic[refLayerIdc]->getPicSym()->getCU(j)->setLayerId( pcIlpPic[refLayerIdc]->getLayerId() );
3827      }
3828    }
3829  }
3830}
3831
3832#endif //SVC_EXTENSION
3833
3834//! \}
Note: See TracBrowser for help on using the repository browser.