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

Last change on this file since 576 was 576, checked in by qualcomm, 11 years ago

JCTVC-P0306: On ue(v) coding of syntax elements in VPS extn (MACRO: VPS_EXTN_UEV_CODING)

Some syntax elements in the VPS extn. are ue(v)-coded instead of u(v)-coded, and some syntax elements are not signaled or coded with u(v).

From: Adarsh K. Ramasubramonian <aramasub@…>

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