source: SHVCSoftware/branches/SHM-5.0-dev/source/Lib/TLibCommon/TComSlice.cpp @ 555

Last change on this file since 555 was 552, checked in by seregin, 12 years ago

JCTVC-P0048: Remove profile_ref_minus1 from VPS extension with macro P0048_REMOVE_PROFILE_REF. Patch was provided by Tomoyuki Yamamoto <yamamoto.tomoyuki@…>

Changes

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