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

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

remove ILP_RAP macro

  • Property svn:eol-style set to native
File size: 104.5 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 SVC_EXTENSION    // 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 !P0307_REMOVE_VPS_VUI_OFFSET
2061#if VPS_VUI_OFFSET
2062, m_vpsVuiOffset (0)
2063#endif
2064#endif
2065#if P0307_VPS_NON_VUI_EXTENSION
2066, m_vpsNonVuiExtLength (0)
2067#endif
2068{
2069  for( Int i = 0; i < MAX_TLAYER; i++)
2070  {
2071    m_numReorderPics[i] = 0;
2072    m_uiMaxDecPicBuffering[i] = 1; 
2073    m_uiMaxLatencyIncrease[i] = 0;
2074  }
2075#if VPS_EXTN_MASK_AND_DIM_INFO
2076  m_avcBaseLayerFlag = false;
2077  m_splittingFlag = false;
2078  ::memset(m_scalabilityMask, 0, sizeof(m_scalabilityMask));
2079  ::memset(m_dimensionIdLen, 0, sizeof(m_dimensionIdLen));
2080  m_nuhLayerIdPresentFlag = false;
2081  ::memset(m_layerIdInNuh, 0, sizeof(m_layerIdInNuh));
2082  ::memset(m_dimensionId, 0, sizeof(m_dimensionId));
2083
2084  m_numScalabilityTypes = 0;
2085  ::memset(m_layerIdInVps, 0, sizeof(m_layerIdInVps));
2086#endif
2087#if VPS_EXTN_PROFILE_INFO
2088  ::memset(m_profilePresentFlag, 0, sizeof(m_profilePresentFlag));
2089#if !P0048_REMOVE_PROFILE_REF
2090  ::memset(m_profileLayerSetRef, 0, sizeof(m_profileLayerSetRef));
2091#endif
2092#endif
2093#if VPS_EXTN_OP_LAYER_SETS
2094  ::memset(m_layerIdIncludedFlag, 0, sizeof(m_layerIdIncludedFlag));
2095  // Consider dynamic allocation for outputLayerSetIdx and outputLayerFlag
2096  ::memset(m_outputLayerSetIdx, 0, sizeof(m_outputLayerSetIdx));
2097  ::memset(m_outputLayerFlag, 0, sizeof(m_outputLayerFlag));
2098#endif
2099#if VPS_EXTN_DIRECT_REF_LAYERS
2100  ::memset(m_directDependencyFlag, 0, sizeof(m_directDependencyFlag));
2101  ::memset(m_numDirectRefLayers,   0, sizeof(m_numDirectRefLayers  ));
2102  ::memset(m_refLayerId,           0, sizeof(m_refLayerId          ));
2103#if M0457_PREDICTION_INDICATIONS
2104  m_directDepTypeLen = 2;
2105  ::memset(m_directDependencyType, 0, sizeof(m_directDependencyType));
2106#endif
2107#endif
2108#if DERIVE_LAYER_ID_LIST_VARIABLES
2109  ::memset(m_layerSetLayerIdList,  0, sizeof(m_layerSetLayerIdList));
2110  ::memset(m_numLayerInIdList,     0, sizeof(m_numLayerInIdList   )); 
2111#endif
2112  ::memset(m_profileLevelTierIdx,  0, sizeof(m_profileLevelTierIdx));
2113#if JCTVC_M0458_INTERLAYER_RPS_SIG
2114  m_maxOneActiveRefLayerFlag = true;
2115#endif
2116#if O0062_POC_LSB_NOT_PRESENT_FLAG
2117  ::memset(m_pocLsbNotPresentFlag, 0, sizeof(m_pocLsbNotPresentFlag));
2118#endif
2119#if O0223_PICTURE_TYPES_ALIGN_FLAG
2120  m_crossLayerPictureTypeAlignFlag = true;
2121#endif
2122#if N0147_IRAP_ALIGN_FLAG
2123  m_crossLayerIrapAlignFlag = true;
2124#endif
2125#if JCTVC_M0203_INTERLAYER_PRED_IDC
2126#if N0120_MAX_TID_REF_PRESENT_FLAG
2127  m_maxTidRefPresentFlag = true;
2128#endif
2129  for( Int i = 0; i < MAX_VPS_LAYER_ID_PLUS1 - 1; i++)
2130  {
2131#if O0225_MAX_TID_FOR_REF_LAYERS
2132    for( Int j = 0; j < MAX_VPS_LAYER_ID_PLUS1; j++)
2133    {
2134      m_maxTidIlRefPicsPlus1[i][j] = m_uiMaxTLayers + 1;
2135    }
2136#else
2137    m_maxTidIlRefPicsPlus1[i] = m_uiMaxTLayers + 1;
2138#endif
2139  }
2140#endif
2141#if VPS_VUI_TILES_NOT_IN_USE__FLAG
2142  m_tilesNotInUseFlag = true;
2143  ::memset(m_tilesInUseFlag,  0, sizeof(m_tilesInUseFlag));
2144  ::memset(m_loopFilterNotAcrossTilesFlag,  0, sizeof(m_loopFilterNotAcrossTilesFlag));
2145#endif
2146#if TILE_BOUNDARY_ALIGNED_FLAG
2147  ::memset(m_tileBoundariesAlignedFlag,  0, sizeof(m_tileBoundariesAlignedFlag));
2148#endif
2149#if VPS_VUI_WPP_NOT_IN_USE__FLAG
2150  m_wppNotInUseFlag = true;
2151  ::memset(m_wppInUseFlag,  0, sizeof(m_wppInUseFlag));
2152#endif
2153#if N0160_VUI_EXT_ILP_REF
2154  m_ilpRestrictedRefLayersFlag = false;
2155  ::memset(m_minSpatialSegmentOffsetPlus1,  0, sizeof(m_minSpatialSegmentOffsetPlus1));
2156  ::memset(m_ctuBasedOffsetEnabledFlag,     0, sizeof(m_ctuBasedOffsetEnabledFlag));
2157  ::memset(m_minHorizontalCtuOffsetPlus1,   0, sizeof(m_minHorizontalCtuOffsetPlus1));
2158#endif
2159#if VPS_VUI_VIDEO_SIGNAL
2160  m_vidSigPresentVpsFlag=true;
2161  m_vpsVidSigInfo=1;
2162  ::memset( m_vpsVidSigIdx, 0, sizeof(m_vpsVidSigIdx) );
2163  m_vpsVidSigIdx[0]=0;
2164  for (Int i=0; i < 16; i++)
2165  {
2166    m_vpsVidFormat[i] = 5;
2167    m_vpsFullRangeFlag[i] = false;
2168    m_vpsColorPrimaries[i] = 2;
2169    m_vpsTransChar[i] = 2;
2170    m_vpsMatCoeff[i] = 2;
2171  }
2172#endif
2173#if VPS_VUI_BITRATE_PICRATE 
2174  ::memset(m_bitRatePresentFlag, 0, sizeof(m_bitRatePresentFlag));
2175  ::memset(m_picRatePresentFlag, 0, sizeof(m_picRatePresentFlag));
2176  ::memset(m_avgBitRate        , 0, sizeof(m_avgBitRate)        );
2177  ::memset(m_maxBitRate        , 0, sizeof(m_maxBitRate)        );
2178  ::memset(m_constPicRateIdc   , 0, sizeof(m_constPicRateIdc)   );
2179  ::memset(m_avgPicRate        , 0, sizeof(m_avgPicRate)        );
2180#endif
2181#if REPN_FORMAT_IN_VPS
2182  ::memset( m_vpsRepFormatIdx, 0, sizeof(m_vpsRepFormatIdx) );
2183#endif
2184#if VIEW_ID_RELATED_SIGNALING
2185  ::memset(m_viewIdVal, 0, sizeof(m_viewIdVal));
2186#endif
2187#if O0092_0094_DEPENDENCY_CONSTRAINT
2188  for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++)
2189  {
2190    m_numberRefLayers[i] = 0;
2191    for (Int j = 0; j < MAX_NUM_LAYER_IDS; j++)
2192    {
2193      m_recursiveRefLayerFlag[i][j] = 0;
2194    }
2195  }
2196#endif
2197#if VPS_DPB_SIZE_TABLE
2198  ::memset( m_subLayerFlagInfoPresentFlag,  0, sizeof(m_subLayerFlagInfoPresentFlag ) );
2199  ::memset( m_subLayerDpbInfoPresentFlag,   0, sizeof(m_subLayerDpbInfoPresentFlag )  );
2200  ::memset( m_maxVpsDecPicBufferingMinus1,  0, sizeof(m_maxVpsDecPicBufferingMinus1 ) );
2201  ::memset( m_maxVpsNumReorderPics,         0, sizeof(m_maxVpsNumReorderPics )        );
2202  ::memset( m_maxVpsLatencyIncreasePlus1,   0, sizeof(m_maxVpsLatencyIncreasePlus1 )  );
2203  ::memset( m_numSubDpbs                ,   0, sizeof(m_numSubDpbs)                   );
2204#endif
2205}
2206#else
2207TComVPS::TComVPS()
2208: m_VPSId                     (  0)
2209, m_uiMaxTLayers              (  1)
2210, m_uiMaxLayers               (  1)
2211, m_bTemporalIdNestingFlag    (false)
2212, m_numHrdParameters          (  0)
2213, m_maxNuhReservedZeroLayerId (  0)
2214, m_hrdParameters             (NULL)
2215, m_hrdOpSetIdx               (NULL)
2216, m_cprmsPresentFlag          (NULL)
2217{
2218  for( Int i = 0; i < MAX_TLAYER; i++)
2219  {
2220    m_numReorderPics[i] = 0;
2221    m_uiMaxDecPicBuffering[i] = 1; 
2222    m_uiMaxLatencyIncrease[i] = 0;
2223  }
2224}
2225#endif //SVC_EXTENSION
2226
2227TComVPS::~TComVPS()
2228{
2229  if( m_hrdParameters    != NULL )     delete[] m_hrdParameters;
2230  if( m_hrdOpSetIdx      != NULL )     delete[] m_hrdOpSetIdx;
2231  if( m_cprmsPresentFlag != NULL )     delete[] m_cprmsPresentFlag;
2232}
2233#if DERIVE_LAYER_ID_LIST_VARIABLES
2234Void TComVPS::deriveLayerIdListVariables()
2235{
2236  // For layer 0
2237  setNumLayersInIdList(0, 1);
2238  setLayerSetLayerIdList(0, 0, 0);
2239
2240  // For other layers
2241  Int i, m, n;
2242  for( i = 1; i <= getNumLayerSets() - 1; i++ )
2243  {
2244    n = 0;
2245    for( m = 0; m <= this->getMaxLayerId(); m++)
2246    {
2247      if(this->getLayerIdIncludedFlag(i, m))
2248      {
2249        setLayerSetLayerIdList(i, n, m);
2250        n++;
2251      }
2252    }
2253    setNumLayersInIdList(i, n);
2254  }
2255}
2256#endif
2257#if VPS_DPB_SIZE_TABLE
2258Void TComVPS::deriveNumberOfSubDpbs()
2259{
2260  // Derive number of sub-DPBs
2261  // For output layer set 0
2262  setNumSubDpbs(0, 1);
2263  // For other output layer sets
2264  for( Int i = 1; i < getNumOutputLayerSets(); i++)
2265  {
2266    setNumSubDpbs( i, getNumLayersInIdList( getOutputLayerSetIdx(i)) );
2267  }
2268}
2269#endif
2270#if VPS_VUI_TILES_NOT_IN_USE__FLAG
2271Void TComVPS::setTilesNotInUseFlag(Bool x)
2272{
2273  m_tilesNotInUseFlag = x;
2274  if (m_tilesNotInUseFlag)
2275  {
2276    for (int i = 0; i < getMaxLayers(); i++)
2277    {
2278      m_tilesInUseFlag[i] = m_loopFilterNotAcrossTilesFlag[i] = m_tilesNotInUseFlag;
2279    }
2280  }
2281#if TILE_BOUNDARY_ALIGNED_FLAG 
2282  if (m_tilesNotInUseFlag)
2283  {
2284    for (int i = 1; i < getMaxLayers(); i++)
2285    {
2286      for(int j = 0; j < getNumDirectRefLayers(getLayerIdInNuh(i)); j++)
2287      {
2288        setTileBoundariesAlignedFlag(i, j, m_tilesNotInUseFlag);
2289      }
2290    }
2291  }
2292#endif
2293}
2294#endif
2295#if VPS_VUI_WPP_NOT_IN_USE__FLAG
2296Void TComVPS::setWppNotInUseFlag(Bool x)
2297{
2298  m_wppNotInUseFlag = x;
2299  if (m_wppNotInUseFlag)
2300  {
2301    for (int i = 0; i < getMaxLayers(); i++)
2302    {
2303      m_wppInUseFlag[i] = m_wppNotInUseFlag;
2304    }
2305  }
2306}
2307#endif
2308#if O0092_0094_DEPENDENCY_CONSTRAINT
2309Void TComVPS::setRefLayersFlags(Int currLayerId)
2310{
2311  for (Int i = 0; i < getNumDirectRefLayers(currLayerId); i++)
2312  {
2313    UInt refLayerId = getRefLayerId(currLayerId, i);
2314    setRecursiveRefLayerFlag(currLayerId, refLayerId, true);
2315    for (Int k = 0; k < MAX_NUM_LAYER_IDS; k++)
2316    {
2317      setRecursiveRefLayerFlag(currLayerId, k, (getRecursiveRefLayerFlag(currLayerId, k) | getRecursiveRefLayerFlag(refLayerId, k)));
2318    }
2319  }
2320}
2321
2322Void TComVPS::setNumRefLayers(Int currLayerId)
2323{
2324  for (Int i = 0; i <= getMaxLayers(); i++)
2325  {
2326    UInt iNuhLId = getLayerIdInNuh(i);
2327    setRefLayersFlags(iNuhLId);
2328    for (UInt j = 0; j < MAX_NUM_LAYER_IDS; j++)
2329    {
2330      m_numberRefLayers[iNuhLId] += (getRecursiveRefLayerFlag(iNuhLId, j) == true ? 1 : 0);
2331    }
2332  }
2333}
2334#endif
2335
2336#if VIEW_ID_RELATED_SIGNALING
2337Int TComVPS::getNumViews()
2338{
2339  Int numViews = 1; 
2340  for( Int i = 0; i <= getMaxLayers() - 1; i++ )
2341  {
2342    Int lId = getLayerIdInNuh( i ); 
2343    if ( i > 0 && ( getViewIndex( lId ) != getScalabilityId( i - 1, VIEW_ORDER_INDEX ) ) )
2344    {
2345      numViews++; 
2346    }   
2347  }
2348
2349  return numViews;
2350}
2351Int TComVPS::getScalabilityId( Int layerIdInVps, ScalabilityType scalType )
2352{
2353  return getScalabilityMask( scalType ) ? getDimensionId( layerIdInVps, scalTypeToScalIdx( scalType ) ) : 0;
2354} 
2355Int TComVPS::scalTypeToScalIdx( ScalabilityType scalType )
2356{
2357  assert( scalType >= 0 && scalType <= MAX_VPS_NUM_SCALABILITY_TYPES ); 
2358  assert( scalType == MAX_VPS_NUM_SCALABILITY_TYPES || getScalabilityMask( scalType ) );
2359  Int scalIdx = 0; 
2360  for( Int curScalType = 0; curScalType < scalType; curScalType++ )
2361  {
2362    scalIdx += ( getScalabilityMask( curScalType ) ? 1 : 0 );
2363
2364  }
2365
2366  return scalIdx; 
2367}
2368#endif
2369// ------------------------------------------------------------------------------------------------
2370// Sequence parameter set (SPS)
2371// ------------------------------------------------------------------------------------------------
2372
2373TComSPS::TComSPS()
2374: m_SPSId                     (  0)
2375, m_VPSId                     (  0)
2376, m_chromaFormatIdc           (CHROMA_420)
2377, m_uiMaxTLayers              (  1)
2378// Structure
2379, m_picWidthInLumaSamples     (352)
2380, m_picHeightInLumaSamples    (288)
2381, m_log2MinCodingBlockSize    (  0)
2382, m_log2DiffMaxMinCodingBlockSize (0)
2383, m_uiMaxCUWidth              ( 32)
2384, m_uiMaxCUHeight             ( 32)
2385, m_uiMaxCUDepth              (  3)
2386, m_bLongTermRefsPresent      (false)
2387, m_uiQuadtreeTULog2MaxSize   (  0)
2388, m_uiQuadtreeTULog2MinSize   (  0)
2389, m_uiQuadtreeTUMaxDepthInter (  0)
2390, m_uiQuadtreeTUMaxDepthIntra (  0)
2391// Tool list
2392, m_usePCM                   (false)
2393, m_pcmLog2MaxSize            (  5)
2394, m_uiPCMLog2MinSize          (  7)
2395, m_bitDepthY                 (  8)
2396, m_bitDepthC                 (  8)
2397, m_qpBDOffsetY               (  0)
2398, m_qpBDOffsetC               (  0)
2399, m_useLossless               (false)
2400, m_uiPCMBitDepthLuma         (  8)
2401, m_uiPCMBitDepthChroma       (  8)
2402, m_bPCMFilterDisableFlag     (false)
2403, m_uiBitsForPOC              (  8)
2404, m_numLongTermRefPicSPS    (  0) 
2405, m_uiMaxTrSize               ( 32)
2406, m_bUseSAO                   (false) 
2407, m_bTemporalIdNestingFlag    (false)
2408, m_scalingListEnabledFlag    (false)
2409, m_useStrongIntraSmoothing   (false)
2410, m_vuiParametersPresentFlag  (false)
2411, m_vuiParameters             ()
2412#if SVC_EXTENSION
2413#if M0463_VUI_EXT_ILP_REF
2414, m_interViewMvVertConstraintFlag (false)
2415, m_numIlpRestrictedRefLayers ( 0 )
2416#endif
2417, m_layerId                   ( 0 )
2418, m_numScaledRefLayerOffsets  ( 0 )
2419#if REPN_FORMAT_IN_VPS
2420, m_updateRepFormatFlag       (false)
2421#if O0096_REP_FORMAT_INDEX
2422, m_updateRepFormatIndex      (0)
2423#endif
2424#endif
2425#if SCALINGLIST_INFERRING
2426, m_inferScalingListFlag ( false )
2427, m_scalingListRefLayerId ( 0 )
2428#endif
2429#endif //SVC_EXTENSION
2430{
2431  for ( Int i = 0; i < MAX_TLAYER; i++ )
2432  {
2433    m_uiMaxLatencyIncrease[i] = 0;
2434    m_uiMaxDecPicBuffering[i] = 1;
2435    m_numReorderPics[i]       = 0;
2436  }
2437  m_scalingList = new TComScalingList;
2438  ::memset(m_ltRefPicPocLsbSps, 0, sizeof(m_ltRefPicPocLsbSps));
2439  ::memset(m_usedByCurrPicLtSPSFlag, 0, sizeof(m_usedByCurrPicLtSPSFlag));
2440#if M0463_VUI_EXT_ILP_REF
2441  for (Int i = 0; i < MAX_LAYERS; i++ )
2442  {
2443    m_minSpatialSegmentOffsetPlus1[ i ] = 0;
2444    m_ctuBasedOffsetEnabledFlag   [ i ] = false;
2445    m_minHorizontalCtuOffsetPlus1 [ i ] = 0;
2446  }
2447#endif
2448}
2449
2450TComSPS::~TComSPS()
2451{
2452#if SCALINGLIST_INFERRING
2453  if( !m_inferScalingListFlag )
2454#endif
2455  delete m_scalingList;
2456  m_RPSList.destroy();
2457}
2458
2459Void  TComSPS::createRPSList( Int numRPS )
2460{ 
2461  m_RPSList.destroy();
2462  m_RPSList.create(numRPS);
2463}
2464
2465Void TComSPS::setHrdParameters( UInt frameRate, UInt numDU, UInt bitRate, Bool randomAccess )
2466{
2467  if( !getVuiParametersPresentFlag() )
2468  {
2469    return;
2470  }
2471
2472  TComVUI *vui = getVuiParameters();
2473  TComHRD *hrd = vui->getHrdParameters();
2474
2475  TimingInfo *timingInfo = vui->getTimingInfo();
2476#if TIMING_INFO_NONZERO_LAYERID_SPS
2477  if( getLayerId() > 0 )
2478  {
2479    timingInfo->setTimingInfoPresentFlag( false );
2480  }
2481  else
2482  {
2483#endif
2484    timingInfo->setTimingInfoPresentFlag( true );
2485    switch( frameRate )
2486    {
2487    case 24:
2488      timingInfo->setNumUnitsInTick( 1125000 );    timingInfo->setTimeScale    ( 27000000 );
2489      break;
2490    case 25:
2491      timingInfo->setNumUnitsInTick( 1080000 );    timingInfo->setTimeScale    ( 27000000 );
2492      break;
2493    case 30:
2494      timingInfo->setNumUnitsInTick( 900900 );     timingInfo->setTimeScale    ( 27000000 );
2495      break;
2496    case 50:
2497      timingInfo->setNumUnitsInTick( 540000 );     timingInfo->setTimeScale    ( 27000000 );
2498      break;
2499    case 60:
2500      timingInfo->setNumUnitsInTick( 450450 );     timingInfo->setTimeScale    ( 27000000 );
2501      break;
2502    default:
2503      timingInfo->setNumUnitsInTick( 1001 );       timingInfo->setTimeScale    ( 60000 );
2504      break;
2505    }
2506
2507    Bool rateCnt = ( bitRate > 0 );
2508    hrd->setNalHrdParametersPresentFlag( rateCnt );
2509    hrd->setVclHrdParametersPresentFlag( rateCnt );
2510
2511    hrd->setSubPicCpbParamsPresentFlag( ( numDU > 1 ) );
2512
2513    if( hrd->getSubPicCpbParamsPresentFlag() )
2514    {
2515      hrd->setTickDivisorMinus2( 100 - 2 );                          //
2516      hrd->setDuCpbRemovalDelayLengthMinus1( 7 );                    // 8-bit precision ( plus 1 for last DU in AU )
2517      hrd->setSubPicCpbParamsInPicTimingSEIFlag( true );
2518      hrd->setDpbOutputDelayDuLengthMinus1( 5 + 7 );                 // With sub-clock tick factor of 100, at least 7 bits to have the same value as AU dpb delay
2519    }
2520    else
2521    {
2522      hrd->setSubPicCpbParamsInPicTimingSEIFlag( false ); 
2523    }
2524
2525    hrd->setBitRateScale( 4 );                                       // in units of 2~( 6 + 4 ) = 1,024 bps
2526    hrd->setCpbSizeScale( 6 );                                       // in units of 2~( 4 + 4 ) = 1,024 bit
2527    hrd->setDuCpbSizeScale( 6 );                                       // in units of 2~( 4 + 4 ) = 1,024 bit
2528 
2529    hrd->setInitialCpbRemovalDelayLengthMinus1(15);                  // assuming 0.5 sec, log2( 90,000 * 0.5 ) = 16-bit
2530    if( randomAccess )
2531    {
2532      hrd->setCpbRemovalDelayLengthMinus1(5);                        // 32 = 2^5 (plus 1)
2533      hrd->setDpbOutputDelayLengthMinus1 (5);                        // 32 + 3 = 2^6
2534    }
2535    else
2536    {
2537      hrd->setCpbRemovalDelayLengthMinus1(9);                        // max. 2^10
2538      hrd->setDpbOutputDelayLengthMinus1 (9);                        // max. 2^10
2539    }
2540
2541/*
2542     Note: only the case of "vps_max_temporal_layers_minus1 = 0" is supported.
2543*/
2544    Int i, j;
2545    UInt birateValue, cpbSizeValue;
2546    UInt ducpbSizeValue;
2547    UInt duBitRateValue = 0;
2548
2549    for( i = 0; i < MAX_TLAYER; i ++ )
2550    {
2551      hrd->setFixedPicRateFlag( i, 1 );
2552      hrd->setPicDurationInTcMinus1( i, 0 );
2553      hrd->setLowDelayHrdFlag( i, 0 );
2554      hrd->setCpbCntMinus1( i, 0 );
2555
2556      birateValue  = bitRate;
2557      cpbSizeValue = bitRate;                                     // 1 second
2558      ducpbSizeValue = bitRate/numDU;
2559      duBitRateValue = bitRate;
2560      for( j = 0; j < ( hrd->getCpbCntMinus1( i ) + 1 ); j ++ )
2561      {
2562        hrd->setBitRateValueMinus1( i, j, 0, ( birateValue  - 1 ) );
2563        hrd->setCpbSizeValueMinus1( i, j, 0, ( cpbSizeValue - 1 ) );
2564        hrd->setDuCpbSizeValueMinus1( i, j, 0, ( ducpbSizeValue - 1 ) );
2565        hrd->setCbrFlag( i, j, 0, ( j == 0 ) );
2566
2567        hrd->setBitRateValueMinus1( i, j, 1, ( birateValue  - 1) );
2568        hrd->setCpbSizeValueMinus1( i, j, 1, ( cpbSizeValue - 1 ) );
2569        hrd->setDuCpbSizeValueMinus1( i, j, 1, ( ducpbSizeValue - 1 ) );
2570        hrd->setDuBitRateValueMinus1( i, j, 1, ( duBitRateValue - 1 ) );
2571        hrd->setCbrFlag( i, j, 1, ( j == 0 ) );
2572      }
2573    }
2574#if TIMING_INFO_NONZERO_LAYERID_SPS
2575  }
2576#endif
2577}
2578const Int TComSPS::m_winUnitX[]={1,2,2,1};
2579const Int TComSPS::m_winUnitY[]={1,2,1,1};
2580
2581#if O0098_SCALED_REF_LAYER_ID
2582Window& TComSPS::getScaledRefLayerWindowForLayer(Int layerId)
2583{
2584  static Window win;
2585
2586  for (Int i = 0; i < m_numScaledRefLayerOffsets; i++)
2587  {
2588    if (layerId == m_scaledRefLayerId[i])
2589    {
2590      return m_scaledRefLayerWindow[i];
2591    }
2592  }
2593
2594  win.resetWindow();  // scaled reference layer offsets are inferred to be zero when not present
2595  return win;
2596}
2597#endif
2598
2599TComPPS::TComPPS()
2600: m_PPSId                       (0)
2601, m_SPSId                       (0)
2602, m_picInitQPMinus26            (0)
2603, m_useDQP                      (false)
2604, m_bConstrainedIntraPred       (false)
2605, m_bSliceChromaQpFlag          (false)
2606, m_pcSPS                       (NULL)
2607, m_uiMaxCuDQPDepth             (0)
2608, m_uiMinCuDQPSize              (0)
2609, m_chromaCbQpOffset            (0)
2610, m_chromaCrQpOffset            (0)
2611, m_numRefIdxL0DefaultActive    (1)
2612, m_numRefIdxL1DefaultActive    (1)
2613, m_TransquantBypassEnableFlag  (false)
2614, m_useTransformSkip             (false)
2615, m_dependentSliceSegmentsEnabledFlag    (false)
2616, m_tilesEnabledFlag               (false)
2617, m_entropyCodingSyncEnabledFlag   (false)
2618, m_loopFilterAcrossTilesEnabledFlag  (true)
2619, m_uniformSpacingFlag           (0)
2620, m_iNumColumnsMinus1            (0)
2621, m_puiColumnWidth               (NULL)
2622, m_iNumRowsMinus1               (0)
2623, m_puiRowHeight                 (NULL)
2624, m_iNumSubstreams             (1)
2625, m_signHideFlag(0)
2626, m_cabacInitPresentFlag        (false)
2627, m_encCABACTableIdx            (I_SLICE)
2628, m_sliceHeaderExtensionPresentFlag    (false)
2629, m_loopFilterAcrossSlicesEnabledFlag (false)
2630, m_listsModificationPresentFlag(  0)
2631, m_numExtraSliceHeaderBits(0)
2632#if SCALINGLIST_INFERRING
2633, m_inferScalingListFlag ( false )
2634, m_scalingListRefLayerId ( 0 )
2635#endif
2636{
2637  m_scalingList = new TComScalingList;
2638}
2639
2640TComPPS::~TComPPS()
2641{
2642  if( m_iNumColumnsMinus1 > 0 && m_uniformSpacingFlag == 0 )
2643  {
2644    if (m_puiColumnWidth) delete [] m_puiColumnWidth; 
2645    m_puiColumnWidth = NULL;
2646  }
2647  if( m_iNumRowsMinus1 > 0 && m_uniformSpacingFlag == 0 )
2648  {
2649    if (m_puiRowHeight) delete [] m_puiRowHeight;
2650    m_puiRowHeight = NULL;
2651  }
2652
2653#if SCALINGLIST_INFERRING
2654  if( !m_inferScalingListFlag )
2655#endif
2656  delete m_scalingList;
2657}
2658
2659TComReferencePictureSet::TComReferencePictureSet()
2660: m_numberOfPictures (0)
2661, m_numberOfNegativePictures (0)
2662, m_numberOfPositivePictures (0)
2663, m_numberOfLongtermPictures (0)
2664, m_interRPSPrediction (0) 
2665, m_deltaRIdxMinus1 (0)   
2666, m_deltaRPS (0) 
2667, m_numRefIdc (0) 
2668{
2669  ::memset( m_deltaPOC, 0, sizeof(m_deltaPOC) );
2670  ::memset( m_POC, 0, sizeof(m_POC) );
2671  ::memset( m_used, 0, sizeof(m_used) );
2672  ::memset( m_refIdc, 0, sizeof(m_refIdc) );
2673}
2674
2675TComReferencePictureSet::~TComReferencePictureSet()
2676{
2677}
2678
2679Void TComReferencePictureSet::setUsed(Int bufferNum, Bool used)
2680{
2681  m_used[bufferNum] = used;
2682}
2683
2684Void TComReferencePictureSet::setDeltaPOC(Int bufferNum, Int deltaPOC)
2685{
2686  m_deltaPOC[bufferNum] = deltaPOC;
2687}
2688
2689Void TComReferencePictureSet::setNumberOfPictures(Int numberOfPictures)
2690{
2691  m_numberOfPictures = numberOfPictures;
2692}
2693
2694Int TComReferencePictureSet::getUsed(Int bufferNum)
2695{
2696  return m_used[bufferNum];
2697}
2698
2699Int TComReferencePictureSet::getDeltaPOC(Int bufferNum)
2700{
2701  return m_deltaPOC[bufferNum];
2702}
2703
2704Int TComReferencePictureSet::getNumberOfPictures()
2705{
2706  return m_numberOfPictures;
2707}
2708
2709Int TComReferencePictureSet::getPOC(Int bufferNum)
2710{
2711  return m_POC[bufferNum];
2712}
2713
2714Void TComReferencePictureSet::setPOC(Int bufferNum, Int POC)
2715{
2716  m_POC[bufferNum] = POC;
2717}
2718
2719Bool TComReferencePictureSet::getCheckLTMSBPresent(Int bufferNum)
2720{
2721  return m_bCheckLTMSB[bufferNum];
2722}
2723
2724Void TComReferencePictureSet::setCheckLTMSBPresent(Int bufferNum, Bool b)
2725{
2726  m_bCheckLTMSB[bufferNum] = b;
2727}
2728
2729/** set the reference idc value at uiBufferNum entry to the value of iRefIdc
2730 * \param uiBufferNum
2731 * \param iRefIdc
2732 * \returns Void
2733 */
2734Void TComReferencePictureSet::setRefIdc(Int bufferNum, Int refIdc)
2735{
2736  m_refIdc[bufferNum] = refIdc;
2737}
2738
2739/** get the reference idc value at uiBufferNum
2740 * \param uiBufferNum
2741 * \returns Int
2742 */
2743Int  TComReferencePictureSet::getRefIdc(Int bufferNum)
2744{
2745  return m_refIdc[bufferNum];
2746}
2747
2748/** Sorts the deltaPOC and Used by current values in the RPS based on the deltaPOC values.
2749 *  deltaPOC values are sorted with -ve values before the +ve values.  -ve values are in decreasing order.
2750 *  +ve values are in increasing order.
2751 * \returns Void
2752 */
2753Void TComReferencePictureSet::sortDeltaPOC()
2754{
2755  // sort in increasing order (smallest first)
2756  for(Int j=1; j < getNumberOfPictures(); j++)
2757  { 
2758    Int deltaPOC = getDeltaPOC(j);
2759    Bool used = getUsed(j);
2760    for (Int k=j-1; k >= 0; k--)
2761    {
2762      Int temp = getDeltaPOC(k);
2763      if (deltaPOC < temp)
2764      {
2765        setDeltaPOC(k+1, temp);
2766        setUsed(k+1, getUsed(k));
2767        setDeltaPOC(k, deltaPOC);
2768        setUsed(k, used);
2769      }
2770    }
2771  }
2772  // flip the negative values to largest first
2773  Int numNegPics = getNumberOfNegativePictures();
2774  for(Int j=0, k=numNegPics-1; j < numNegPics>>1; j++, k--)
2775  { 
2776    Int deltaPOC = getDeltaPOC(j);
2777    Bool used = getUsed(j);
2778    setDeltaPOC(j, getDeltaPOC(k));
2779    setUsed(j, getUsed(k));
2780    setDeltaPOC(k, deltaPOC);
2781    setUsed(k, used);
2782  }
2783}
2784
2785/** Prints the deltaPOC and RefIdc (if available) values in the RPS.
2786 *  A "*" is added to the deltaPOC value if it is Used bu current.
2787 * \returns Void
2788 */
2789Void TComReferencePictureSet::printDeltaPOC()
2790{
2791  printf("DeltaPOC = { ");
2792  for(Int j=0; j < getNumberOfPictures(); j++)
2793  {
2794    printf("%d%s ", getDeltaPOC(j), (getUsed(j)==1)?"*":"");
2795  } 
2796  if (getInterRPSPrediction()) 
2797  {
2798    printf("}, RefIdc = { ");
2799    for(Int j=0; j < getNumRefIdc(); j++)
2800    {
2801      printf("%d ", getRefIdc(j));
2802    } 
2803  }
2804  printf("}\n");
2805}
2806
2807TComRPSList::TComRPSList()
2808:m_referencePictureSets (NULL)
2809{
2810}
2811
2812TComRPSList::~TComRPSList()
2813{
2814}
2815
2816Void TComRPSList::create( Int numberOfReferencePictureSets)
2817{
2818  m_numberOfReferencePictureSets = numberOfReferencePictureSets;
2819  m_referencePictureSets = new TComReferencePictureSet[numberOfReferencePictureSets];
2820}
2821
2822Void TComRPSList::destroy()
2823{
2824  if (m_referencePictureSets)
2825  {
2826    delete [] m_referencePictureSets;
2827  }
2828  m_numberOfReferencePictureSets = 0;
2829  m_referencePictureSets = NULL;
2830}
2831
2832
2833
2834TComReferencePictureSet* TComRPSList::getReferencePictureSet(Int referencePictureSetNum)
2835{
2836  return &m_referencePictureSets[referencePictureSetNum];
2837}
2838
2839Int TComRPSList::getNumberOfReferencePictureSets()
2840{
2841  return m_numberOfReferencePictureSets;
2842}
2843
2844Void TComRPSList::setNumberOfReferencePictureSets(Int numberOfReferencePictureSets)
2845{
2846  m_numberOfReferencePictureSets = numberOfReferencePictureSets;
2847}
2848
2849TComRefPicListModification::TComRefPicListModification()
2850: m_bRefPicListModificationFlagL0 (false)
2851, m_bRefPicListModificationFlagL1 (false)
2852{
2853  ::memset( m_RefPicSetIdxL0, 0, sizeof(m_RefPicSetIdxL0) );
2854  ::memset( m_RefPicSetIdxL1, 0, sizeof(m_RefPicSetIdxL1) );
2855}
2856
2857TComRefPicListModification::~TComRefPicListModification()
2858{
2859}
2860
2861TComScalingList::TComScalingList()
2862{
2863  init();
2864}
2865
2866TComScalingList::~TComScalingList()
2867{
2868  destroy();
2869}
2870
2871/** set default quantization matrix to array
2872*/
2873Void TComSlice::setDefaultScalingList()
2874{
2875  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
2876  {
2877    for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++)
2878    {
2879      getScalingList()->processDefaultMatrix(sizeId, listId);
2880    }
2881  }
2882}
2883/** check if use default quantization matrix
2884 * \returns true if use default quantization matrix in all size
2885*/
2886Bool TComSlice::checkDefaultScalingList()
2887{
2888  UInt defaultCounter=0;
2889
2890  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
2891  {
2892    for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++)
2893    {
2894      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
2895     && ((sizeId < SCALING_LIST_16x16) || (getScalingList()->getScalingListDC(sizeId,listId) == 16))) // check DC value
2896      {
2897        defaultCounter++;
2898      }
2899    }
2900  }
2901  return (defaultCounter == (SCALING_LIST_NUM * SCALING_LIST_SIZE_NUM - 4)) ? false : true; // -4 for 32x32
2902}
2903
2904/** get scaling matrix from RefMatrixID
2905 * \param sizeId size index
2906 * \param Index of input matrix
2907 * \param Index of reference matrix
2908 */
2909Void TComScalingList::processRefMatrix( UInt sizeId, UInt listId , UInt refListId )
2910{
2911  ::memcpy(getScalingListAddress(sizeId, listId),((listId == refListId)? getScalingListDefaultAddress(sizeId, refListId): getScalingListAddress(sizeId, refListId)),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
2912}
2913
2914/** parse syntax infomation
2915 *  \param pchFile syntax infomation
2916 *  \returns false if successful
2917 */
2918Bool TComScalingList::xParseScalingList(Char* pchFile)
2919{
2920  FILE *fp;
2921  Char line[1024];
2922  UInt sizeIdc,listIdc;
2923  UInt i,size = 0;
2924  Int *src=0,data;
2925  Char *ret;
2926  UInt  retval;
2927
2928  if((fp = fopen(pchFile,"r")) == (FILE*)NULL)
2929  {
2930    printf("can't open file %s :: set Default Matrix\n",pchFile);
2931    return true;
2932  }
2933
2934  for(sizeIdc = 0; sizeIdc < SCALING_LIST_SIZE_NUM; sizeIdc++)
2935  {
2936    size = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeIdc]);
2937    for(listIdc = 0; listIdc < g_scalingListNum[sizeIdc]; listIdc++)
2938    {
2939      src = getScalingListAddress(sizeIdc, listIdc);
2940
2941      fseek(fp,0,0);
2942      do 
2943      {
2944        ret = fgets(line, 1024, fp);
2945        if ((ret==NULL)||(strstr(line, MatrixType[sizeIdc][listIdc])==NULL && feof(fp)))
2946        {
2947          printf("Error: can't read Matrix :: set Default Matrix\n");
2948          return true;
2949        }
2950      }
2951      while (strstr(line, MatrixType[sizeIdc][listIdc]) == NULL);
2952      for (i=0; i<size; i++)
2953      {
2954        retval = fscanf(fp, "%d,", &data);
2955        if (retval!=1)
2956        {
2957          printf("Error: can't read Matrix :: set Default Matrix\n");
2958          return true;
2959        }
2960        src[i] = data;
2961      }
2962      //set DC value for default matrix check
2963      setScalingListDC(sizeIdc,listIdc,src[0]);
2964
2965      if(sizeIdc > SCALING_LIST_8x8)
2966      {
2967        fseek(fp,0,0);
2968        do 
2969        {
2970          ret = fgets(line, 1024, fp);
2971          if ((ret==NULL)||(strstr(line, MatrixType_DC[sizeIdc][listIdc])==NULL && feof(fp)))
2972          {
2973            printf("Error: can't read DC :: set Default Matrix\n");
2974            return true;
2975          }
2976        }
2977        while (strstr(line, MatrixType_DC[sizeIdc][listIdc]) == NULL);
2978        retval = fscanf(fp, "%d,", &data);
2979        if (retval!=1)
2980        {
2981          printf("Error: can't read Matrix :: set Default Matrix\n");
2982          return true;
2983        }
2984        //overwrite DC value when size of matrix is larger than 16x16
2985        setScalingListDC(sizeIdc,listIdc,data);
2986      }
2987    }
2988  }
2989  fclose(fp);
2990  return false;
2991}
2992
2993/** initialization process of quantization matrix array
2994 */
2995Void TComScalingList::init()
2996{
2997  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
2998  {
2999    for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++)
3000    {
3001      m_scalingListCoef[sizeId][listId] = new Int [min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])];
3002    }
3003  }
3004  m_scalingListCoef[SCALING_LIST_32x32][3] = m_scalingListCoef[SCALING_LIST_32x32][1]; // copy address for 32x32
3005}
3006
3007/** destroy quantization matrix array
3008 */
3009Void TComScalingList::destroy()
3010{
3011  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
3012  {
3013    for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++)
3014    {
3015      if(m_scalingListCoef[sizeId][listId]) delete [] m_scalingListCoef[sizeId][listId];
3016    }
3017  }
3018}
3019
3020/** get default address of quantization matrix
3021 * \param sizeId size index
3022 * \param listId list index
3023 * \returns pointer of quantization matrix
3024 */
3025Int* TComScalingList::getScalingListDefaultAddress(UInt sizeId, UInt listId)
3026{
3027  Int *src = 0;
3028  switch(sizeId)
3029  {
3030    case SCALING_LIST_4x4:
3031      src = g_quantTSDefault4x4;
3032      break;
3033    case SCALING_LIST_8x8:
3034      src = (listId<3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
3035      break;
3036    case SCALING_LIST_16x16:
3037      src = (listId<3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
3038      break;
3039    case SCALING_LIST_32x32:
3040      src = (listId<1) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
3041      break;
3042    default:
3043      assert(0);
3044      src = NULL;
3045      break;
3046  }
3047  return src;
3048}
3049
3050/** process of default matrix
3051 * \param sizeId size index
3052 * \param Index of input matrix
3053 */
3054Void TComScalingList::processDefaultMatrix(UInt sizeId, UInt listId)
3055{
3056  ::memcpy(getScalingListAddress(sizeId, listId),getScalingListDefaultAddress(sizeId,listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
3057  setScalingListDC(sizeId,listId,SCALING_LIST_DC);
3058}
3059
3060/** check DC value of matrix for default matrix signaling
3061 */
3062Void TComScalingList::checkDcOfMatrix()
3063{
3064  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
3065  {
3066    for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++)
3067    {
3068      //check default matrix?
3069      if(getScalingListDC(sizeId,listId) == 0)
3070      {
3071        processDefaultMatrix(sizeId, listId);
3072      }
3073    }
3074  }
3075}
3076
3077ParameterSetManager::ParameterSetManager()
3078#if SVC_EXTENSION
3079: m_spsMap(MAX_NUM_SPS)
3080, m_ppsMap(MAX_NUM_PPS)
3081, m_activeSPSId(-1)
3082, m_activePPSId(-1)
3083#else
3084: m_vpsMap(MAX_NUM_VPS)
3085, m_spsMap(MAX_NUM_SPS)
3086, m_ppsMap(MAX_NUM_PPS)
3087, m_activeVPSId(-1)
3088, m_activeSPSId(-1)
3089, m_activePPSId(-1)
3090#endif
3091{
3092}
3093
3094
3095ParameterSetManager::~ParameterSetManager()
3096{
3097}
3098
3099//! activate a SPS from a active parameter sets SEI message
3100//! \returns true, if activation is successful
3101Bool ParameterSetManager::activateSPSWithSEI(Int spsId)
3102{
3103  TComSPS *sps = m_spsMap.getPS(spsId);
3104  if (sps)
3105  {
3106    Int vpsId = sps->getVPSId();
3107    if (m_vpsMap.getPS(vpsId))
3108    {
3109      m_activeVPSId = vpsId;
3110      m_activeSPSId = spsId;
3111      return true;
3112    }
3113    else
3114    {
3115      printf("Warning: tried to activate SPS using an Active parameter sets SEI message. Referenced VPS does not exist.");
3116    }
3117  }
3118  else
3119  {
3120    printf("Warning: tried to activate non-existing SPS using an Active parameter sets SEI message.");
3121  }
3122  return false;
3123}
3124
3125//! activate a PPS and depending on isIDR parameter also SPS and VPS
3126//! \returns true, if activation is successful
3127Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIRAP)
3128{
3129  TComPPS *pps = m_ppsMap.getPS(ppsId);
3130  if (pps)
3131  {
3132    Int spsId = pps->getSPSId();
3133    if (!isIRAP && (spsId != m_activeSPSId))
3134    {
3135      printf("Warning: tried to activate PPS referring to a inactive SPS at non-IRAP.");
3136      return false;
3137    }
3138    TComSPS *sps = m_spsMap.getPS(spsId);
3139    if (sps)
3140    {
3141      Int vpsId = sps->getVPSId();
3142      if (!isIRAP && (vpsId != m_activeVPSId))
3143      {
3144        printf("Warning: tried to activate PPS referring to a inactive VPS at non-IRAP.");
3145        return false;
3146      }
3147      if (m_vpsMap.getPS(vpsId))
3148      {
3149        m_activePPSId = ppsId;
3150        m_activeVPSId = vpsId;
3151        m_activeSPSId = spsId;
3152
3153        return true;
3154      }
3155      else
3156      {
3157        printf("Warning: tried to activate PPS that refers to a non-existing VPS.");
3158      }
3159    }
3160    else
3161    {
3162      printf("Warning: tried to activate a PPS that refers to a non-existing SPS.");
3163    }
3164  }
3165  else
3166  {
3167    printf("Warning: tried to activate non-existing PPS.");
3168  }
3169  return false;
3170}
3171
3172ProfileTierLevel::ProfileTierLevel()
3173  : m_profileSpace    (0)
3174  , m_tierFlag        (false)
3175  , m_profileIdc      (0)
3176  , m_levelIdc        (0)
3177, m_progressiveSourceFlag  (false)
3178, m_interlacedSourceFlag   (false)
3179, m_nonPackedConstraintFlag(false)
3180, m_frameOnlyConstraintFlag(false)
3181{
3182  ::memset(m_profileCompatibilityFlag, 0, sizeof(m_profileCompatibilityFlag));
3183}
3184#if VPS_EXTN_PROFILE_INFO
3185Void ProfileTierLevel::copyProfileInfo(ProfileTierLevel *ptl)
3186{
3187  this->setProfileSpace          ( ptl->getProfileSpace()      );
3188  this->setTierFlag              ( ptl->getTierFlag()          );
3189  this->setProfileIdc            ( ptl->getProfileIdc()        );
3190  for(Int j = 0; j < 32; j++)
3191  {
3192    this->setProfileCompatibilityFlag(j, ptl->getProfileCompatibilityFlag(j));
3193  }
3194  this->setProgressiveSourceFlag  ( ptl->getProgressiveSourceFlag()  );
3195  this->setInterlacedSourceFlag   ( ptl->getInterlacedSourceFlag()   );
3196  this->setNonPackedConstraintFlag( ptl->getNonPackedConstraintFlag());
3197  this->setFrameOnlyConstraintFlag( ptl->getFrameOnlyConstraintFlag()); 
3198}
3199#endif
3200
3201TComPTL::TComPTL()
3202{
3203  ::memset(m_subLayerProfilePresentFlag, 0, sizeof(m_subLayerProfilePresentFlag));
3204  ::memset(m_subLayerLevelPresentFlag,   0, sizeof(m_subLayerLevelPresentFlag  ));
3205}
3206#if VPS_EXTN_PROFILE_INFO
3207Void TComPTL::copyProfileInfo(TComPTL *ptl)
3208{
3209  // Copy all information related to general profile
3210  this->getGeneralPTL()->copyProfileInfo(ptl->getGeneralPTL());
3211}
3212#endif
3213
3214#if SVC_EXTENSION
3215#if AVC_SYNTAX
3216Void TComSlice::initBaseLayerRPL( TComSlice *pcSlice )
3217{
3218// 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
3219  setPOC( pcSlice->getPOC() );
3220  if( pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA )
3221  {
3222    setSliceType( I_SLICE );
3223  }
3224  else
3225  {
3226    setSliceType( pcSlice->getSliceType() );
3227  }
3228
3229  if( this->isIntra() )
3230  {
3231    return;
3232  }
3233
3234  //initialize reference POC of BL
3235  for( Int iRefPicList = 0; iRefPicList < 2; iRefPicList++ )
3236  {
3237    RefPicList eRefPicList = RefPicList( iRefPicList );
3238
3239    assert( pcSlice->getNumRefIdx( eRefPicList) >= 0 );
3240    setNumRefIdx( eRefPicList, pcSlice->getNumRefIdx( eRefPicList ) - 1 );
3241    assert( getNumRefIdx( eRefPicList) <= MAX_NUM_REF);
3242
3243    for(Int refIdx = 0; refIdx < getNumRefIdx( eRefPicList ); refIdx++) 
3244    {
3245      setRefPOC( pcSlice->getRefPic( eRefPicList, refIdx )->getPOC(), eRefPicList, refIdx );
3246      setRefPic( pcSlice->getRefPic( eRefPicList, refIdx ), eRefPicList, refIdx );
3247      /*
3248      // should be set if the base layer has its own instance of the reference picture lists, currently EL RPL is reused.
3249      getRefPic( eRefPicList, refIdx )->setLayerId( 0 );
3250      getRefPic( eRefPicList, refIdx )->setIsLongTerm( pcSlice->getRefPic( eRefPicList, refIdx )->getIsLongTerm() );     
3251      */
3252
3253    }
3254  } 
3255  return;
3256}
3257#endif
3258
3259Bool TComSlice::setBaseColPic(  TComList<TComPic*>& rcListPic, UInt refLayerIdc )
3260{ 
3261  if(m_layerId == 0)
3262  {
3263    memset( m_pcBaseColPic, 0, sizeof( m_pcBaseColPic ) );
3264    return false;
3265  }       
3266#if POC_RESET_FLAG
3267  TComPic* pic = xGetRefPic( rcListPic, m_bPocResetFlag ? 0 : m_iPOC );
3268
3269  if( pic )
3270  {
3271    setBaseColPic(refLayerIdc, pic );
3272  }
3273  else
3274  {
3275    return false;
3276  }
3277 
3278  return true;
3279#else
3280  setBaseColPic(refLayerIdc, xGetRefPic(rcListPic, getPOC())); 
3281#endif
3282}
3283
3284#if MFM_ENCCONSTRAINT
3285TComPic* TComSlice::getBaseColPic(  TComList<TComPic*>& rcListPic )
3286{
3287#if POC_RESET_FLAG
3288  return xGetRefPic( rcListPic, m_bPocResetFlag ? 0 : m_iPOC );
3289#else
3290  return xGetRefPic( rcListPic, m_iPOC );
3291#endif
3292}
3293#endif
3294
3295#if REF_IDX_MFM
3296Void TComSlice::setRefPOCListILP( TComPic** ilpPic, TComPic** pcRefPicRL )
3297{
3298  for( UInt i = 0; i < m_activeNumILRRefIdx; i++ )
3299  {
3300    UInt refLayerIdc = m_interLayerPredLayerIdc[i];
3301
3302    TComPic* pcRefPicBL = pcRefPicRL[refLayerIdc];
3303    //set reference picture POC of each ILP reference
3304    Int thePoc = ilpPic[refLayerIdc]->getPOC(); 
3305    assert(thePoc >= 0);
3306    assert(thePoc == pcRefPicBL->getPOC());
3307
3308    ilpPic[refLayerIdc]->getSlice(0)->setBaseColPic( refLayerIdc, pcRefPicBL );
3309
3310    //copy reference pictures marking from the reference layer
3311    ilpPic[refLayerIdc]->getSlice(0)->copySliceInfo(pcRefPicBL->getSlice(0));
3312
3313    for( Int refList = 0; refList < 2; refList++ )
3314    {
3315      RefPicList refPicList = RefPicList( refList );
3316
3317      //set reference POC of ILP
3318      ilpPic[refLayerIdc]->getSlice(0)->setNumRefIdx(refPicList, pcRefPicBL->getSlice(0)->getNumRefIdx(refPicList));
3319      assert(ilpPic[refLayerIdc]->getSlice(0)->getNumRefIdx(refPicList) >= 0);
3320      assert(ilpPic[refLayerIdc]->getSlice(0)->getNumRefIdx(refPicList) <= MAX_NUM_REF);
3321
3322      //initialize reference POC of ILP
3323      for(Int refIdx = 0; refIdx < pcRefPicBL->getSlice(0)->getNumRefIdx(refPicList); refIdx++)
3324      {
3325        ilpPic[refLayerIdc]->getSlice(0)->setRefPOC(pcRefPicBL->getSlice(0)->getRefPOC(refPicList, refIdx), refPicList, refIdx);
3326        ilpPic[refLayerIdc]->getSlice(0)->setRefPic(pcRefPicBL->getSlice(0)->getRefPic(refPicList, refIdx), refPicList, refIdx);
3327      }
3328
3329      for(Int refIdx = pcRefPicBL->getSlice(0)->getNumRefIdx(refPicList); refIdx < MAX_NUM_REF; refIdx++) 
3330      { 
3331        ilpPic[refLayerIdc]->getSlice(0)->setRefPOC(0, refPicList, refIdx); 
3332        ilpPic[refLayerIdc]->getSlice(0)->setRefPic(NULL, refPicList, refIdx); 
3333      }
3334    }
3335  }
3336  return;
3337}
3338#endif
3339
3340Void TComSlice::setILRPic(TComPic **pcIlpPic)
3341{
3342  for( Int i = 0; i < m_activeNumILRRefIdx; i++ )
3343  {
3344    Int refLayerIdc = m_interLayerPredLayerIdc[i];
3345
3346    if( pcIlpPic[refLayerIdc] )
3347    {
3348      pcIlpPic[refLayerIdc]->copyUpsampledPictureYuv( m_pcPic->getFullPelBaseRec( refLayerIdc ), pcIlpPic[refLayerIdc]->getPicYuvRec() );
3349      pcIlpPic[refLayerIdc]->getSlice(0)->setPOC( m_iPOC );
3350      pcIlpPic[refLayerIdc]->setLayerId( m_pcBaseColPic[refLayerIdc]->getLayerId() ); //set reference layerId
3351      pcIlpPic[refLayerIdc]->getPicYuvRec()->setBorderExtension( false );
3352      pcIlpPic[refLayerIdc]->getPicYuvRec()->extendPicBorder();
3353      for (Int j=0; j<pcIlpPic[refLayerIdc]->getPicSym()->getNumberOfCUsInFrame(); j++)    // set reference CU layerId
3354      {
3355        pcIlpPic[refLayerIdc]->getPicSym()->getCU(j)->setLayerId( pcIlpPic[refLayerIdc]->getLayerId() );
3356      }
3357    }
3358  }
3359}
3360
3361#endif //SVC_EXTENSION
3362
3363//! \}
Note: See TracBrowser for help on using the repository browser.