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

Last change on this file since 575 was 569, checked in by qualcomm, 12 years ago

JCTVC-P0130: Absence of discardable pictures in RPS (Macro: DISCARDABLE_PIC_RPS)

Added conditions/asserts to ensure that pictures that belong to the temporal RPS or the inter-layer RPS have discardable_flag equal to 0.

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