source: SHVCSoftware/branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComSlice.cpp @ 108

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

Rename VPS syntax elements (MACRO: VPS_RENAME)

Rename variables vps_max_nuh_reserved_zero_layer_id and vps_max_op_sets_minus1 to vps_max_layer_id and vps_num_layer_sets_minus1.

From: Adarsh K. Ramasubramonian <aramasub@…>

File size: 77.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
48  ParameterSetMap<TComVPS> ParameterSetManager::m_vpsMap(MAX_NUM_VPS);
49  Int 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 )
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_bRefPicListModificationFlagLC ( false )
68, m_bRefPicListCombinationFlag    ( false )
69, m_bCheckLDC                     ( false )
70, m_iSliceQpDelta                 ( 0 )
71, m_iSliceQpDeltaCb               ( 0 )
72, m_iSliceQpDeltaCr               ( 0 )
73, m_iDepth                        ( 0 )
74, m_bRefenced                     ( false )
75, m_pcSPS                         ( NULL )
76, m_pcPPS                         ( NULL )
77, m_pcPic                         ( NULL )
78, m_colFromL0Flag                 ( 1 )
79, m_colRefIdx                     ( 0 )
80#if SAO_CHROMA_LAMBDA
81, m_dLambdaLuma( 0.0 )
82, m_dLambdaChroma( 0.0 )
83#else
84, m_dLambda                       ( 0.0 )
85#endif
86, m_bNoBackPredFlag               ( false )
87, m_uiTLayer                      ( 0 )
88#if SVC_EXTENSION
89, m_layerId                     ( 0 )
90, m_pcBaseColPic                  ( NULL )
91#endif
92, m_bTLayerSwitchingFlag          ( false )
93, m_sliceMode                   ( 0 )
94, m_sliceArgument               ( 0 )
95, m_sliceCurStartCUAddr         ( 0 )
96, m_sliceCurEndCUAddr           ( 0 )
97, m_sliceIdx                    ( 0 )
98, m_sliceSegmentMode            ( 0 )
99, m_sliceSegmentArgument        ( 0 )
100, m_sliceSegmentCurStartCUAddr  ( 0 )
101, m_sliceSegmentCurEndCUAddr    ( 0 )
102, m_nextSlice                    ( false )
103, m_nextSliceSegment             ( false )
104, m_sliceBits                   ( 0 )
105, m_sliceSegmentBits         ( 0 )
106, m_bFinalized                    ( false )
107, m_uiTileOffstForMultES          ( 0 )
108, m_puiSubstreamSizes             ( NULL )
109, m_cabacInitFlag                 ( false )
110, m_bLMvdL1Zero                   ( false )
111, m_numEntryPointOffsets          ( 0 )
112, m_temporalLayerNonReferenceFlag ( false )
113, m_enableTMVPFlag                ( true )
114{
115  m_aiNumRefIdx[0] = m_aiNumRefIdx[1] = m_aiNumRefIdx[2] = 0;
116 
117#if REF_LIST_BUGFIX
118  m_aiNumILRRefIdx = 0;
119#endif
120  initEqualRef();
121 
122  for(Int iNumCount = 0; iNumCount < MAX_NUM_REF_LC; iNumCount++)
123  {
124    m_iRefIdxOfLC[REF_PIC_LIST_0][iNumCount]=-1;
125    m_iRefIdxOfLC[REF_PIC_LIST_1][iNumCount]=-1;
126    m_eListIdFromIdxOfLC[iNumCount]=0;
127    m_iRefIdxFromIdxOfLC[iNumCount]=0;
128    m_iRefIdxOfL0FromRefIdxOfL1[iNumCount] = -1;
129    m_iRefIdxOfL1FromRefIdxOfL0[iNumCount] = -1;
130  }   
131  for(Int iNumCount = 0; iNumCount < MAX_NUM_REF; iNumCount++)
132  {
133    m_apcRefPicList [0][iNumCount] = NULL;
134    m_apcRefPicList [1][iNumCount] = NULL;
135    m_aiRefPOCList  [0][iNumCount] = 0;
136    m_aiRefPOCList  [1][iNumCount] = 0;
137  }
138  resetWpScaling(m_weightPredTable);
139  initWpAcDcParam();
140  m_saoEnabledFlag = false;
141}
142
143TComSlice::~TComSlice()
144{
145  delete[] m_puiSubstreamSizes;
146  m_puiSubstreamSizes = NULL;
147}
148
149
150#if SVC_EXTENSION
151Void TComSlice::initSlice( UInt layerId )
152#else
153Void TComSlice::initSlice()
154#endif
155{
156#if SVC_EXTENSION
157  m_layerId = layerId;
158#endif
159  m_aiNumRefIdx[0]      = 0;
160  m_aiNumRefIdx[1]      = 0;
161#if REF_LIST_BUGFIX
162  if(layerId)
163  {
164    m_aiNumILRRefIdx      = 1;  // to be set to NumDirectRefLayers[LayerIdInVps[nuh_layer_id]]
165  }
166  else
167  {
168    m_aiNumILRRefIdx = 0;
169  }
170#endif
171  m_colFromL0Flag = 1;
172 
173  m_colRefIdx = 0;
174  initEqualRef();
175  m_bNoBackPredFlag = false;
176  m_bRefPicListCombinationFlag = false;
177  m_bRefPicListModificationFlagLC = false;
178  m_bCheckLDC = false;
179  m_iSliceQpDeltaCb = 0;
180  m_iSliceQpDeltaCr = 0;
181
182  m_aiNumRefIdx[REF_PIC_LIST_C]      = 0;
183
184  m_maxNumMergeCand = MRG_MAX_NUM_CANDS;
185
186  m_bFinalized=false;
187
188  m_tileByteLocation.clear();
189  m_cabacInitFlag        = false;
190  m_numEntryPointOffsets = 0;
191  m_enableTMVPFlag = true;
192}
193
194Bool TComSlice::getRapPicFlag()
195{
196  return getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR
197      || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP
198      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
199      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT
200      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA
201      || getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA;
202}
203
204/**
205 - allocate table to contain substream sizes to be written to the slice header.
206 .
207 \param uiNumSubstreams Number of substreams -- the allocation will be this value - 1.
208 */
209Void  TComSlice::allocSubstreamSizes(UInt uiNumSubstreams)
210{
211  delete[] m_puiSubstreamSizes;
212  m_puiSubstreamSizes = new UInt[uiNumSubstreams > 0 ? uiNumSubstreams-1 : 0];
213}
214
215Void  TComSlice::sortPicList        (TComList<TComPic*>& rcListPic)
216{
217  TComPic*    pcPicExtract;
218  TComPic*    pcPicInsert;
219 
220  TComList<TComPic*>::iterator    iterPicExtract;
221  TComList<TComPic*>::iterator    iterPicExtract_1;
222  TComList<TComPic*>::iterator    iterPicInsert;
223 
224  for (Int i = 1; i < (Int)(rcListPic.size()); i++)
225  {
226    iterPicExtract = rcListPic.begin();
227    for (Int j = 0; j < i; j++) iterPicExtract++;
228    pcPicExtract = *(iterPicExtract);
229    pcPicExtract->setCurrSliceIdx(0);
230   
231    iterPicInsert = rcListPic.begin();
232    while (iterPicInsert != iterPicExtract)
233    {
234      pcPicInsert = *(iterPicInsert);
235      pcPicInsert->setCurrSliceIdx(0);
236      if (pcPicInsert->getPOC() >= pcPicExtract->getPOC())
237      {
238        break;
239      }
240     
241      iterPicInsert++;
242    }
243   
244    iterPicExtract_1 = iterPicExtract;    iterPicExtract_1++;
245   
246    //  swap iterPicExtract and iterPicInsert, iterPicExtract = curr. / iterPicInsert = insertion position
247    rcListPic.insert (iterPicInsert, iterPicExtract, iterPicExtract_1);
248    rcListPic.erase  (iterPicExtract);
249  }
250}
251
252TComPic* TComSlice::xGetRefPic (TComList<TComPic*>& rcListPic,
253                                Int                 poc)
254{
255  TComList<TComPic*>::iterator  iterPic = rcListPic.begin(); 
256  TComPic*                      pcPic = *(iterPic);
257  while ( iterPic != rcListPic.end() )
258  {
259    if(pcPic->getPOC() == poc)
260    {
261      break;
262    }
263    iterPic++;
264    pcPic = *(iterPic);
265  }
266  return  pcPic;
267}
268
269
270TComPic* TComSlice::xGetLongTermRefPic (TComList<TComPic*>& rcListPic,
271                                        Int                 poc)
272{
273  TComList<TComPic*>::iterator  iterPic = rcListPic.begin(); 
274  TComPic*                      pcPic = *(iterPic);
275  TComPic*                      pcStPic = pcPic;
276  while ( iterPic != rcListPic.end() )
277  {
278    pcPic = *(iterPic);
279    if(pcPic && (pcPic->getPOC()%(1<<getSPS()->getBitsForPOC())) == (poc%(1<<getSPS()->getBitsForPOC())))
280    {
281      if(pcPic->getIsLongTerm())
282      {
283        return pcPic;
284      }
285      else
286      {
287        pcStPic = pcPic;
288      }
289      break;
290    }
291
292    iterPic++;
293  }
294  return  pcStPic;
295}
296
297Void TComSlice::setRefPOCList       ()
298{
299  for (Int iDir = 0; iDir < 2; iDir++)
300  {
301    for (Int iNumRefIdx = 0; iNumRefIdx < m_aiNumRefIdx[iDir]; iNumRefIdx++)
302    {
303      m_aiRefPOCList[iDir][iNumRefIdx] = m_apcRefPicList[iDir][iNumRefIdx]->getPOC();
304    }
305  }
306
307}
308
309Void TComSlice::generateCombinedList()
310{
311  if(m_aiNumRefIdx[REF_PIC_LIST_C] > 0)
312  {
313    m_aiNumRefIdx[REF_PIC_LIST_C]=0;
314    for(Int iNumCount = 0; iNumCount < MAX_NUM_REF_LC; iNumCount++)
315    {
316      m_iRefIdxOfLC[REF_PIC_LIST_0][iNumCount]=-1;
317      m_iRefIdxOfLC[REF_PIC_LIST_1][iNumCount]=-1;
318      m_eListIdFromIdxOfLC[iNumCount]=0;
319      m_iRefIdxFromIdxOfLC[iNumCount]=0;
320      m_iRefIdxOfL0FromRefIdxOfL1[iNumCount] = -1;
321      m_iRefIdxOfL1FromRefIdxOfL0[iNumCount] = -1;
322    }
323
324    for (Int iNumRefIdx = 0; iNumRefIdx < MAX_NUM_REF; iNumRefIdx++)
325    {
326      if(iNumRefIdx < m_aiNumRefIdx[REF_PIC_LIST_0])
327      {
328        Bool bTempRefIdxInL2 = true;
329        for ( Int iRefIdxLC = 0; iRefIdxLC < m_aiNumRefIdx[REF_PIC_LIST_C]; iRefIdxLC++ )
330        {
331          if ( m_apcRefPicList[REF_PIC_LIST_0][iNumRefIdx]->getPOC() == m_apcRefPicList[m_eListIdFromIdxOfLC[iRefIdxLC]][m_iRefIdxFromIdxOfLC[iRefIdxLC]]->getPOC() )
332          {
333            m_iRefIdxOfL1FromRefIdxOfL0[iNumRefIdx] = m_iRefIdxFromIdxOfLC[iRefIdxLC];
334            m_iRefIdxOfL0FromRefIdxOfL1[m_iRefIdxFromIdxOfLC[iRefIdxLC]] = iNumRefIdx;
335            bTempRefIdxInL2 = false;
336            break;
337          }
338        }
339
340        if(bTempRefIdxInL2 == true)
341        { 
342          m_eListIdFromIdxOfLC[m_aiNumRefIdx[REF_PIC_LIST_C]] = REF_PIC_LIST_0;
343          m_iRefIdxFromIdxOfLC[m_aiNumRefIdx[REF_PIC_LIST_C]] = iNumRefIdx;
344          m_iRefIdxOfLC[REF_PIC_LIST_0][iNumRefIdx] = m_aiNumRefIdx[REF_PIC_LIST_C]++;
345        }
346      }
347
348      if(iNumRefIdx < m_aiNumRefIdx[REF_PIC_LIST_1])
349      {
350        Bool bTempRefIdxInL2 = true;
351        for ( Int iRefIdxLC = 0; iRefIdxLC < m_aiNumRefIdx[REF_PIC_LIST_C]; iRefIdxLC++ )
352        {
353          if ( m_apcRefPicList[REF_PIC_LIST_1][iNumRefIdx]->getPOC() == m_apcRefPicList[m_eListIdFromIdxOfLC[iRefIdxLC]][m_iRefIdxFromIdxOfLC[iRefIdxLC]]->getPOC() )
354          {
355            m_iRefIdxOfL0FromRefIdxOfL1[iNumRefIdx] = m_iRefIdxFromIdxOfLC[iRefIdxLC];
356            m_iRefIdxOfL1FromRefIdxOfL0[m_iRefIdxFromIdxOfLC[iRefIdxLC]] = iNumRefIdx;
357            bTempRefIdxInL2 = false;
358            break;
359          }
360        }
361        if(bTempRefIdxInL2 == true)
362        {
363          m_eListIdFromIdxOfLC[m_aiNumRefIdx[REF_PIC_LIST_C]] = REF_PIC_LIST_1;
364          m_iRefIdxFromIdxOfLC[m_aiNumRefIdx[REF_PIC_LIST_C]] = iNumRefIdx;
365          m_iRefIdxOfLC[REF_PIC_LIST_1][iNumRefIdx] = m_aiNumRefIdx[REF_PIC_LIST_C]++;
366        }
367      }
368    }
369  }
370}
371
372Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic)
373{
374#if REF_IDX_FRAMEWORK
375  if( m_eSliceType == I_SLICE || ( getSPS()->getLayerId() && 
376      (getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA) &&
377      (getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) ) )
378#else
379  if (m_eSliceType == I_SLICE)
380#endif
381  {
382    ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
383    ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
384   
385    return;
386  }
387 
388  m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
389  m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
390
391  TComPic*  pcRefPic= NULL;
392  TComPic*  RefPicSetStCurr0[16];
393  TComPic*  RefPicSetStCurr1[16];
394  TComPic*  RefPicSetLtCurr[16];
395  UInt NumPocStCurr0 = 0;
396  UInt NumPocStCurr1 = 0;
397  UInt NumPocLtCurr = 0;
398  Int i;
399
400  for(i=0; i < m_pcRPS->getNumberOfNegativePictures(); i++)
401  {
402    if(m_pcRPS->getUsed(i))
403    {
404      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
405      pcRefPic->setIsLongTerm(0);
406      pcRefPic->getPicYuvRec()->extendPicBorder();
407      RefPicSetStCurr0[NumPocStCurr0] = pcRefPic;
408      NumPocStCurr0++;
409      pcRefPic->setCheckLTMSBPresent(false); 
410    }
411  }
412  for(; i < m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures(); i++)
413  {
414    if(m_pcRPS->getUsed(i))
415    {
416      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
417      pcRefPic->setIsLongTerm(0);
418      pcRefPic->getPicYuvRec()->extendPicBorder();
419      RefPicSetStCurr1[NumPocStCurr1] = pcRefPic;
420      NumPocStCurr1++;
421      pcRefPic->setCheckLTMSBPresent(false); 
422    }
423  }
424  for(i = m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()+m_pcRPS->getNumberOfLongtermPictures()-1; i > m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()-1 ; i--)
425  {
426    if(m_pcRPS->getUsed(i))
427    {
428      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i));
429      pcRefPic->setIsLongTerm(1);
430      pcRefPic->getPicYuvRec()->extendPicBorder();
431      RefPicSetLtCurr[NumPocLtCurr] = pcRefPic;
432      NumPocLtCurr++;
433    }
434    if(pcRefPic==NULL) 
435    {
436      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i));
437    }
438    pcRefPic->setCheckLTMSBPresent(m_pcRPS->getCheckLTMSBPresent(i)); 
439  }
440
441  // ref_pic_list_init
442  TComPic*  rpsCurrList0[MAX_NUM_REF+1];
443  TComPic*  rpsCurrList1[MAX_NUM_REF+1];
444  Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr;
445
446  {
447    Int cIdx = 0;
448    for ( i=0; i<NumPocStCurr0; i++, cIdx++)
449    {
450      rpsCurrList0[cIdx] = RefPicSetStCurr0[i];
451    }
452    for ( i=0; i<NumPocStCurr1; i++, cIdx++)
453    {
454      rpsCurrList0[cIdx] = RefPicSetStCurr1[i];
455    }
456    for ( i=0; i<NumPocLtCurr;  i++, cIdx++)
457    {
458      rpsCurrList0[cIdx] = RefPicSetLtCurr[i];
459    }
460  }
461
462  if (m_eSliceType==B_SLICE)
463  {
464    Int cIdx = 0;
465    for ( i=0; i<NumPocStCurr1; i++, cIdx++)
466    {
467      rpsCurrList1[cIdx] = RefPicSetStCurr1[i];
468    }
469    for ( i=0; i<NumPocStCurr0; i++, cIdx++)
470    {
471      rpsCurrList1[cIdx] = RefPicSetStCurr0[i];
472    }
473    for ( i=0; i<NumPocLtCurr;  i++, cIdx++)
474    {
475      rpsCurrList1[cIdx] = RefPicSetLtCurr[i];
476    }
477  }
478
479  ::memset(m_bIsUsedAsLongTerm, 0, sizeof(m_bIsUsedAsLongTerm));
480
481  for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[0]-1); rIdx ++)
482  {
483    m_apcRefPicList[0][rIdx] = m_RefPicListModification.getRefPicListModificationFlagL0() ? rpsCurrList0[ m_RefPicListModification.getRefPicSetIdxL0(rIdx) ] : rpsCurrList0[rIdx % numPocTotalCurr];
484    m_bIsUsedAsLongTerm[0][rIdx] = m_RefPicListModification.getRefPicListModificationFlagL0() ? (m_RefPicListModification.getRefPicSetIdxL0(rIdx) >= (NumPocStCurr0 + NumPocStCurr1))
485                                  : ((rIdx % numPocTotalCurr) >= (NumPocStCurr0 + NumPocStCurr1));
486  }
487  if ( m_eSliceType == P_SLICE )
488  {
489    m_aiNumRefIdx[1] = 0;
490    ::memset( m_apcRefPicList[1], 0, sizeof(m_apcRefPicList[1]));
491  }
492  else
493  {
494    for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[1]-1); rIdx ++)
495    {
496      m_apcRefPicList[1][rIdx] = m_RefPicListModification.getRefPicListModificationFlagL1() ? rpsCurrList1[ m_RefPicListModification.getRefPicSetIdxL1(rIdx) ] : rpsCurrList1[rIdx % numPocTotalCurr];
497      m_bIsUsedAsLongTerm[1][rIdx] = m_RefPicListModification.getRefPicListModificationFlagL1() ?
498                                  (m_RefPicListModification.getRefPicSetIdxL1(rIdx) >= (NumPocStCurr0 + NumPocStCurr1)): ((rIdx % numPocTotalCurr) >= (NumPocStCurr0 + NumPocStCurr1));
499    }
500  }
501}
502
503#if REF_LIST_BUGFIX
504Void TComSlice::setRefPicListModificationSvc()
505{
506  if( !this->getPPS()->getListsModificationPresentFlag()) 
507  {
508    return;
509  }
510
511  if(this->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA && this->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA)
512    return;
513
514  TComRefPicListModification* refPicListModification = this->getRefPicListModification();
515  Int numberOfRpsCurrTempList = this->getNumRpsCurrTempList();  // total number of ref pics in listTemp0 including inter-layer ref pics
516
517  assert(m_aiNumRefIdx[REF_PIC_LIST_0] > 1);
518  assert(m_aiNumRefIdx[REF_PIC_LIST_1] > 1);
519
520  //set L0 inter-layer reference picture modification
521  Bool hasModification = (m_aiNumRefIdx[REF_PIC_LIST_0] == numberOfRpsCurrTempList) ? false : true;
522  refPicListModification->setRefPicListModificationFlagL0(hasModification);
523  if(hasModification)
524  { 
525    for(Int i = 0; i < min(m_aiNumRefIdx[REF_PIC_LIST_0], numberOfRpsCurrTempList); i++)
526    {
527      refPicListModification->setRefPicSetIdxL0(i, i);
528    }
529    if(m_aiNumRefIdx[REF_PIC_LIST_0] > numberOfRpsCurrTempList)
530    {
531        // repeat last ref pic when the number of active ref idx are more than RPS entries
532      for (Int i = numberOfRpsCurrTempList; i < m_aiNumRefIdx[REF_PIC_LIST_0]; i ++)
533      {
534        refPicListModification->setRefPicSetIdxL0(i, numberOfRpsCurrTempList - 1);
535      }
536    }
537    else
538    {
539      for(Int i = m_aiNumILRRefIdx; i > 0; i-- )
540      {
541        refPicListModification->setRefPicSetIdxL0(m_aiNumRefIdx[REF_PIC_LIST_0] - i, numberOfRpsCurrTempList - i);
542      }
543    }
544  }
545
546  //set L1 inter-layer reference picture modification
547  hasModification = (m_aiNumRefIdx[REF_PIC_LIST_1] == numberOfRpsCurrTempList) ? false : true;
548  refPicListModification->setRefPicListModificationFlagL1(hasModification);
549  if(hasModification)
550  { 
551    for(Int i = 0; i < min(m_aiNumRefIdx[REF_PIC_LIST_1], numberOfRpsCurrTempList); i++)
552    {
553      refPicListModification->setRefPicSetIdxL1(i, i);
554    }
555    if(m_aiNumRefIdx[REF_PIC_LIST_1] > numberOfRpsCurrTempList)
556    {
557      for (Int i = numberOfRpsCurrTempList; i < m_aiNumRefIdx[REF_PIC_LIST_1]; i ++)
558      {
559        // repeat last ref pic when the number of active ref idx are more than RPS entries
560        refPicListModification->setRefPicSetIdxL1(i, numberOfRpsCurrTempList - 1); 
561      }
562    }
563    else
564    {
565      for(Int i = m_aiNumILRRefIdx; i > 0; i-- )
566      {
567        refPicListModification->setRefPicSetIdxL1(m_aiNumRefIdx[REF_PIC_LIST_1] - i, numberOfRpsCurrTempList - i);
568      }
569    }
570  }
571  return;
572}
573
574Void TComSlice::setRefPicListSvc( TComList<TComPic*>& rcListPic, TComPic** ilpPic )
575{
576  assert(getLayerId() > 0);
577
578  m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
579  m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
580
581  TComPic*  pcRefPic= NULL;
582  TComPic*  RefPicSetStCurr0[16];
583  TComPic*  RefPicSetStCurr1[16];
584  TComPic*  RefPicSetLtCurr[16];
585  UInt NumPocStCurr0 = 0;
586  UInt NumPocStCurr1 = 0;
587  UInt NumPocLtCurr = 0;
588  Int i;
589
590  //temporal reference pictures
591  if( !(getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA && getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) )
592  { 
593    for(i=0; i < m_pcRPS->getNumberOfNegativePictures(); i++)
594    {
595      if(m_pcRPS->getUsed(i))
596      {
597        pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
598        pcRefPic->setIsLongTerm(0);
599        pcRefPic->getPicYuvRec()->extendPicBorder();
600        RefPicSetStCurr0[NumPocStCurr0] = pcRefPic;
601        NumPocStCurr0++;
602        pcRefPic->setCheckLTMSBPresent(false); 
603      }
604    }
605    for(; i < m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures(); i++)
606    {
607      if(m_pcRPS->getUsed(i))
608      {
609        pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
610        pcRefPic->setIsLongTerm(0);
611        pcRefPic->getPicYuvRec()->extendPicBorder();
612        RefPicSetStCurr1[NumPocStCurr1] = pcRefPic;
613        NumPocStCurr1++;
614        pcRefPic->setCheckLTMSBPresent(false); 
615      }
616    }
617    for(i = m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()+m_pcRPS->getNumberOfLongtermPictures()-1; i > m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()-1 ; i--)
618    {
619      if(m_pcRPS->getUsed(i))
620      {
621        pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i));
622        pcRefPic->setIsLongTerm(1);
623        pcRefPic->getPicYuvRec()->extendPicBorder();
624        RefPicSetLtCurr[NumPocLtCurr] = pcRefPic;
625        NumPocLtCurr++;
626      }
627      if(pcRefPic==NULL) 
628      {
629        pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i));
630      }
631      pcRefPic->setCheckLTMSBPresent(m_pcRPS->getCheckLTMSBPresent(i)); 
632    }
633  }
634
635  //inter-layer reference picture
636#if REF_IDX_MFM
637  assert(m_aiNumILRRefIdx == 1);
638  if(!(getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA && getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) && getSPS()->getMFMEnabledFlag())
639  { 
640    ilpPic[0]->copyUpsampledMvField(getBaseColPic());
641  }
642  else
643  {
644    ilpPic[0]->initUpsampledMvField();
645  }
646#endif
647  ilpPic[0]->setIsLongTerm(1);
648
649  // ref_pic_list_init
650  UInt cIdx = 0;
651  UInt num_ref_idx_l0_active_minus1 = m_aiNumRefIdx[0] - 1;
652  UInt num_ref_idx_l1_active_minus1 = m_aiNumRefIdx[1] - 1;
653  TComPic*  refPicListTemp0[MAX_NUM_REF+1];
654  TComPic*  refPicListTemp1[MAX_NUM_REF+1];
655  Int  numRpsCurrTempList0, numRpsCurrTempList1;
656
657  numRpsCurrTempList0 = numRpsCurrTempList1 = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr + m_aiNumILRRefIdx;
658  if (numRpsCurrTempList0 <= num_ref_idx_l0_active_minus1)
659  {
660    numRpsCurrTempList0 = num_ref_idx_l0_active_minus1 + 1;
661  }
662  if (numRpsCurrTempList1 <= num_ref_idx_l1_active_minus1)
663  {
664    numRpsCurrTempList1 = num_ref_idx_l1_active_minus1 + 1;
665  }
666
667  assert(numRpsCurrTempList0 <= MAX_NUM_REF);
668  assert(numRpsCurrTempList1 <= MAX_NUM_REF);
669
670  cIdx = 0;
671  while (cIdx < numRpsCurrTempList0)
672  { 
673    for ( i=0; i<NumPocStCurr0 && cIdx<numRpsCurrTempList0; cIdx++,i++) 
674      refPicListTemp0[cIdx] = RefPicSetStCurr0[ i ];   
675    for ( i=0; i<NumPocStCurr1 && cIdx<numRpsCurrTempList0; cIdx++,i++) 
676      refPicListTemp0[cIdx] = RefPicSetStCurr1[ i ]; 
677    for ( i=0; i<NumPocLtCurr && cIdx<numRpsCurrTempList0; cIdx++,i++) 
678      refPicListTemp0[cIdx] = RefPicSetLtCurr[ i ];
679    for ( i=0; i<m_aiNumILRRefIdx && cIdx<numRpsCurrTempList0; cIdx++,i++)
680      refPicListTemp0[cIdx] = ilpPic[ i ];
681  }
682  cIdx = 0;
683  while (cIdx<numRpsCurrTempList1 && m_eSliceType==B_SLICE)
684  { 
685    for ( i=0; i<NumPocStCurr1 && cIdx<numRpsCurrTempList1; cIdx++,i++) 
686      refPicListTemp1[cIdx] = RefPicSetStCurr1[ i ];
687    for ( i=0; i<NumPocStCurr0 && cIdx<numRpsCurrTempList1; cIdx++,i++) 
688      refPicListTemp1[cIdx] = RefPicSetStCurr0[ i ]; 
689    for ( i=0; i<NumPocLtCurr && cIdx<numRpsCurrTempList1; cIdx++,i++) 
690      refPicListTemp1[cIdx] = RefPicSetLtCurr[ i ];
691    for ( i=0; i<m_aiNumILRRefIdx && cIdx<numRpsCurrTempList1; cIdx++,i++)
692      refPicListTemp1[cIdx] = ilpPic[ i ];
693  }
694  ::memset(m_bIsUsedAsLongTerm, 0, sizeof(m_bIsUsedAsLongTerm));
695  for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[0]-1); rIdx ++)
696  {
697    m_apcRefPicList[0][rIdx] = m_RefPicListModification.getRefPicListModificationFlagL0() ? refPicListTemp0[ m_RefPicListModification.getRefPicSetIdxL0(rIdx) ] : refPicListTemp0[rIdx % numRpsCurrTempList0];
698    m_bIsUsedAsLongTerm[0][rIdx] = m_RefPicListModification.getRefPicListModificationFlagL0() ? (m_RefPicListModification.getRefPicSetIdxL0(rIdx) >= (NumPocStCurr0 + NumPocStCurr1))
699      : ((rIdx % numRpsCurrTempList0) >= (NumPocStCurr0 + NumPocStCurr1));
700  }
701  if ( m_eSliceType == P_SLICE )
702  {
703    m_aiNumRefIdx[1] = 0;
704    ::memset( m_apcRefPicList[1], 0, sizeof(m_apcRefPicList[1]));
705  }
706  else
707  {
708    for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[1]-1); rIdx ++)
709    {
710      m_apcRefPicList[1][rIdx] = m_RefPicListModification.getRefPicListModificationFlagL1() ? refPicListTemp1[ m_RefPicListModification.getRefPicSetIdxL1(rIdx) ] : refPicListTemp1[rIdx % numRpsCurrTempList1];
711      m_bIsUsedAsLongTerm[1][rIdx] = m_RefPicListModification.getRefPicListModificationFlagL1() ?
712        (m_RefPicListModification.getRefPicSetIdxL1(rIdx) >= (NumPocStCurr0 + NumPocStCurr1)): ((rIdx % numRpsCurrTempList1) >= (NumPocStCurr0 + NumPocStCurr1));
713    }
714  }
715
716  return;
717}
718#endif
719
720Int TComSlice::getNumRpsCurrTempList()
721{
722  Int numRpsCurrTempList = 0;
723
724#if REF_IDX_FRAMEWORK
725  if( m_eSliceType == I_SLICE || ( getSPS()->getLayerId() && 
726    (getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA) &&
727    (getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) ) )
728#else
729  if (m_eSliceType == I_SLICE) 
730#endif
731  {
732#if REF_LIST_BUGFIX
733    return m_aiNumILRRefIdx;
734#else
735    return 0;
736#endif
737  }
738  for(UInt i=0; i < m_pcRPS->getNumberOfNegativePictures()+ m_pcRPS->getNumberOfPositivePictures() + m_pcRPS->getNumberOfLongtermPictures(); i++)
739  {
740    if(m_pcRPS->getUsed(i))
741    {
742      numRpsCurrTempList++;
743    }
744  }
745#if REF_LIST_BUGFIX
746  if(getLayerId())
747  {
748    numRpsCurrTempList += getNumILRRefIdx();
749  }
750#endif
751
752  return numRpsCurrTempList;
753}
754
755Void TComSlice::initEqualRef()
756{
757  for (Int iDir = 0; iDir < 2; iDir++)
758  {
759    for (Int iRefIdx1 = 0; iRefIdx1 < MAX_NUM_REF; iRefIdx1++)
760    {
761      for (Int iRefIdx2 = iRefIdx1; iRefIdx2 < MAX_NUM_REF; iRefIdx2++)
762      {
763        m_abEqualRef[iDir][iRefIdx1][iRefIdx2] = m_abEqualRef[iDir][iRefIdx2][iRefIdx1] = (iRefIdx1 == iRefIdx2? true : false);
764      }
765    }
766  }
767}
768
769Void TComSlice::checkColRefIdx(UInt curSliceIdx, TComPic* pic)
770{
771  Int i;
772  TComSlice* curSlice = pic->getSlice(curSliceIdx);
773  Int currColRefPOC =  curSlice->getRefPOC( RefPicList(1-curSlice->getColFromL0Flag()), curSlice->getColRefIdx());
774  TComSlice* preSlice;
775  Int preColRefPOC;
776  for(i=curSliceIdx-1; i>=0; i--)
777  {
778    preSlice = pic->getSlice(i);
779    if(preSlice->getSliceType() != I_SLICE)
780    {
781      preColRefPOC  = preSlice->getRefPOC( RefPicList(1-preSlice->getColFromL0Flag()), preSlice->getColRefIdx());
782      if(currColRefPOC != preColRefPOC)
783      {
784        printf("Collocated_ref_idx shall always be the same for all slices of a coded picture!\n");
785        exit(EXIT_FAILURE);
786      }
787      else
788      {
789        break;
790      }
791    }
792  }
793}
794
795Void TComSlice::checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, Bool& prevRAPisBLA)
796{
797  for(Int i = 0; i < pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures(); i++)
798  {
799    if(pocCRA < MAX_UINT && getPOC() > pocCRA)
800    {
801      assert(getPOC()+pReferencePictureSet->getDeltaPOC(i) >= pocCRA);
802    }
803  }
804  for(Int i = pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures(); i < pReferencePictureSet->getNumberOfPictures(); i++)
805  {
806    if(pocCRA < MAX_UINT && getPOC() > pocCRA)
807    {
808      assert(pReferencePictureSet->getPOC(i) >= pocCRA);
809    }
810  }
811  if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP ) // IDR picture found
812  {
813    pocCRA = getPOC();
814    prevRAPisBLA = false;
815  }
816  else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found
817  {
818    pocCRA = getPOC();
819    prevRAPisBLA = false;
820  }
821  else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA
822         || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT
823         || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP ) // BLA picture found
824  {
825    pocCRA = getPOC();
826    prevRAPisBLA = true;
827  }
828}
829
830/** Function for marking the reference pictures when an IDR/CRA/CRANT/BLA/BLANT is encountered.
831 * \param pocCRA POC of the CRA/CRANT/BLA/BLANT picture
832 * \param bRefreshPending flag indicating if a deferred decoding refresh is pending
833 * \param rcListPic reference to the reference picture list
834 * This function marks the reference pictures as "unused for reference" in the following conditions.
835 * If the nal_unit_type is IDR/BLA/BLANT, all pictures in the reference picture list 
836 * are marked as "unused for reference"
837 *    If the nal_unit_type is BLA/BLANT, set the pocCRA to the temporal reference of the current picture.
838 * Otherwise
839 *    If the bRefreshPending flag is true (a deferred decoding refresh is pending) and the current
840 *    temporal reference is greater than the temporal reference of the latest CRA/CRANT/BLA/BLANT picture (pocCRA),
841 *    mark all reference pictures except the latest CRA/CRANT/BLA/BLANT picture as "unused for reference" and set
842 *    the bRefreshPending flag to false.
843 *    If the nal_unit_type is CRA/CRANT, set the bRefreshPending flag to true and pocCRA to the temporal
844 *    reference of the current picture.
845 * Note that the current picture is already placed in the reference list and its marking is not changed.
846 * If the current picture has a nal_ref_idc that is not 0, it will remain marked as "used for reference".
847 */
848Void TComSlice::decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic)
849{
850  TComPic*                 rpcPic;
851  Int pocCurr = getPOC(); 
852
853  if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA
854    || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT
855    || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
856    || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR
857    || getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )  // IDR or BLA picture
858  {
859    // mark all pictures as not used for reference
860    TComList<TComPic*>::iterator        iterPic       = rcListPic.begin();
861    while (iterPic != rcListPic.end())
862    {
863      rpcPic = *(iterPic);
864      rpcPic->setCurrSliceIdx(0);
865      if (rpcPic->getPOC() != pocCurr) rpcPic->getSlice(0)->setReferenced(false);
866      iterPic++;
867    }
868    if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA
869      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLANT
870      || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP )
871    {
872      pocCRA = pocCurr;
873    }
874  }
875  else // CRA or No DR
876  {
877    if (bRefreshPending==true && pocCurr > pocCRA) // CRA reference marking pending
878    {
879      TComList<TComPic*>::iterator        iterPic       = rcListPic.begin();
880      while (iterPic != rcListPic.end())
881      {
882        rpcPic = *(iterPic);
883        if (rpcPic->getPOC() != pocCurr && rpcPic->getPOC() != pocCRA) rpcPic->getSlice(0)->setReferenced(false);
884        iterPic++;
885      }
886      bRefreshPending = false; 
887    }
888    if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found
889    {
890      bRefreshPending = true; 
891      pocCRA = pocCurr;
892    }
893  }
894}
895
896Void TComSlice::copySliceInfo(TComSlice *pSrc)
897{
898  assert( pSrc != NULL );
899
900  Int i, j, k;
901
902  m_iPOC                 = pSrc->m_iPOC;
903  m_eNalUnitType         = pSrc->m_eNalUnitType;
904  m_eSliceType           = pSrc->m_eSliceType;
905  m_iSliceQp             = pSrc->m_iSliceQp;
906#if ADAPTIVE_QP_SELECTION
907  m_iSliceQpBase         = pSrc->m_iSliceQpBase;
908#endif
909  m_deblockingFilterDisable   = pSrc->m_deblockingFilterDisable;
910  m_deblockingFilterOverrideFlag = pSrc->m_deblockingFilterOverrideFlag;
911  m_deblockingFilterBetaOffsetDiv2 = pSrc->m_deblockingFilterBetaOffsetDiv2;
912  m_deblockingFilterTcOffsetDiv2 = pSrc->m_deblockingFilterTcOffsetDiv2;
913 
914  for (i = 0; i < 3; i++)
915  {
916    m_aiNumRefIdx[i]     = pSrc->m_aiNumRefIdx[i];
917  }
918
919  for (i = 0; i < 2; i++)
920  {
921    for (j = 0; j < MAX_NUM_REF_LC; j++)
922    {
923       m_iRefIdxOfLC[i][j]  = pSrc->m_iRefIdxOfLC[i][j];
924    }
925  }
926  for (i = 0; i < MAX_NUM_REF_LC; i++)
927  {
928    m_eListIdFromIdxOfLC[i] = pSrc->m_eListIdFromIdxOfLC[i];
929    m_iRefIdxFromIdxOfLC[i] = pSrc->m_iRefIdxFromIdxOfLC[i];
930    m_iRefIdxOfL1FromRefIdxOfL0[i] = pSrc->m_iRefIdxOfL1FromRefIdxOfL0[i];
931    m_iRefIdxOfL0FromRefIdxOfL1[i] = pSrc->m_iRefIdxOfL0FromRefIdxOfL1[i];
932  }
933  m_bRefPicListModificationFlagLC = pSrc->m_bRefPicListModificationFlagLC;
934  m_bRefPicListCombinationFlag    = pSrc->m_bRefPicListCombinationFlag;
935  m_bCheckLDC             = pSrc->m_bCheckLDC;
936  m_iSliceQpDelta        = pSrc->m_iSliceQpDelta;
937  m_iSliceQpDeltaCb      = pSrc->m_iSliceQpDeltaCb;
938  m_iSliceQpDeltaCr      = pSrc->m_iSliceQpDeltaCr;
939  for (i = 0; i < 2; i++)
940  {
941    for (j = 0; j < MAX_NUM_REF; j++)
942    {
943      m_apcRefPicList[i][j]  = pSrc->m_apcRefPicList[i][j];
944      m_aiRefPOCList[i][j]   = pSrc->m_aiRefPOCList[i][j];
945    }
946  }
947  for (i = 0; i < 2; i++)
948  {
949    for (j = 0; j < MAX_NUM_REF + 1; j++)
950    {
951      m_bIsUsedAsLongTerm[i][j] = pSrc->m_bIsUsedAsLongTerm[i][j];
952    }
953  }
954  m_iDepth               = pSrc->m_iDepth;
955
956  // referenced slice
957  m_bRefenced            = pSrc->m_bRefenced;
958
959  // access channel
960  m_pcSPS                = pSrc->m_pcSPS;
961  m_pcPPS                = pSrc->m_pcPPS;
962  m_pcRPS                = pSrc->m_pcRPS;
963  m_iLastIDR             = pSrc->m_iLastIDR;
964
965  m_pcPic                = pSrc->m_pcPic;
966
967  m_colFromL0Flag        = pSrc->m_colFromL0Flag;
968  m_colRefIdx            = pSrc->m_colRefIdx;
969#if SAO_CHROMA_LAMBDA
970  m_dLambdaLuma          = pSrc->m_dLambdaLuma;
971  m_dLambdaChroma        = pSrc->m_dLambdaChroma;
972#else
973  m_dLambda              = pSrc->m_dLambda;
974#endif
975  for (i = 0; i < 2; i++)
976  {
977    for (j = 0; j < MAX_NUM_REF; j++)
978    {
979      for (k =0; k < MAX_NUM_REF; k++)
980      {
981        m_abEqualRef[i][j][k] = pSrc->m_abEqualRef[i][j][k];
982      }
983    }
984  }
985
986  m_bNoBackPredFlag      = pSrc->m_bNoBackPredFlag;
987  m_uiTLayer                      = pSrc->m_uiTLayer;
988  m_bTLayerSwitchingFlag          = pSrc->m_bTLayerSwitchingFlag;
989
990  m_sliceMode                   = pSrc->m_sliceMode;
991  m_sliceArgument               = pSrc->m_sliceArgument;
992  m_sliceCurStartCUAddr         = pSrc->m_sliceCurStartCUAddr;
993  m_sliceCurEndCUAddr           = pSrc->m_sliceCurEndCUAddr;
994  m_sliceIdx                    = pSrc->m_sliceIdx;
995  m_sliceSegmentMode            = pSrc->m_sliceSegmentMode;
996  m_sliceSegmentArgument        = pSrc->m_sliceSegmentArgument; 
997  m_sliceSegmentCurStartCUAddr  = pSrc->m_sliceSegmentCurStartCUAddr;
998  m_sliceSegmentCurEndCUAddr    = pSrc->m_sliceSegmentCurEndCUAddr;
999  m_nextSlice                    = pSrc->m_nextSlice;
1000  m_nextSliceSegment             = pSrc->m_nextSliceSegment;
1001  for ( Int e=0 ; e<2 ; e++ )
1002  {
1003    for ( Int n=0 ; n<MAX_NUM_REF ; n++ )
1004    {
1005      memcpy(m_weightPredTable[e][n], pSrc->m_weightPredTable[e][n], sizeof(wpScalingParam)*3 );
1006    }
1007  }
1008  m_saoEnabledFlag = pSrc->m_saoEnabledFlag; 
1009  m_saoEnabledFlagChroma = pSrc->m_saoEnabledFlagChroma;
1010  m_cabacInitFlag                = pSrc->m_cabacInitFlag;
1011  m_numEntryPointOffsets  = pSrc->m_numEntryPointOffsets;
1012
1013  m_bLMvdL1Zero = pSrc->m_bLMvdL1Zero;
1014  m_LFCrossSliceBoundaryFlag = pSrc->m_LFCrossSliceBoundaryFlag;
1015  m_enableTMVPFlag                = pSrc->m_enableTMVPFlag;
1016  m_maxNumMergeCand               = pSrc->m_maxNumMergeCand;
1017}
1018
1019Int TComSlice::m_prevPOC = 0;
1020/** Function for setting the slice's temporal layer ID and corresponding temporal_layer_switching_point_flag.
1021 * \param uiTLayer Temporal layer ID of the current slice
1022 * The decoder calls this function to set temporal_layer_switching_point_flag for each temporal layer based on
1023 * the SPS's temporal_id_nesting_flag and the parsed PPS.  Then, current slice's temporal layer ID and
1024 * temporal_layer_switching_point_flag is set accordingly.
1025 */
1026Void TComSlice::setTLayerInfo( UInt uiTLayer )
1027{
1028  m_uiTLayer = uiTLayer;
1029}
1030
1031/** Function for checking if this is a switching-point
1032*/
1033Bool TComSlice::isTemporalLayerSwitchingPoint( TComList<TComPic*>& rcListPic )
1034{
1035  TComPic* rpcPic;
1036  // loop through all pictures in the reference picture buffer
1037  TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1038  while ( iterPic != rcListPic.end())
1039  {
1040    rpcPic = *(iterPic++);
1041    if(rpcPic->getSlice(0)->isReferenced() && rpcPic->getPOC() != getPOC())
1042    {
1043      if(rpcPic->getTLayer() >= getTLayer())
1044      {
1045        return false;
1046      }
1047    }
1048  }
1049  return true;
1050}
1051
1052/** Function for checking if this is a STSA candidate
1053 */
1054Bool TComSlice::isStepwiseTemporalLayerSwitchingPointCandidate( TComList<TComPic*>& rcListPic )
1055{
1056    TComPic* rpcPic;
1057   
1058    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1059    while ( iterPic != rcListPic.end())
1060    {
1061        rpcPic = *(iterPic++);
1062        if(rpcPic->getSlice(0)->isReferenced() &&  (rpcPic->getUsedByCurr()==true) && rpcPic->getPOC() != getPOC())
1063        {
1064            if(rpcPic->getTLayer() >= getTLayer())
1065            {
1066                return false;
1067            }
1068        }
1069    }
1070    return true;
1071}
1072
1073/** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet.
1074*/
1075Void TComSlice::applyReferencePictureSet( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet)
1076{
1077  TComPic* rpcPic;
1078  Int i, isReference;
1079
1080  Int j = 0;
1081  // loop through all pictures in the reference picture buffer
1082  TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1083  while ( iterPic != rcListPic.end())
1084  {
1085    j++;
1086    rpcPic = *(iterPic++);
1087
1088    isReference = 0;
1089    // loop through all pictures in the Reference Picture Set
1090    // to see if the picture should be kept as reference picture
1091    for(i=0;i<pReferencePictureSet->getNumberOfPositivePictures()+pReferencePictureSet->getNumberOfNegativePictures();i++)
1092    {
1093      if(!rpcPic->getIsLongTerm() && rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i))
1094      {
1095        isReference = 1;
1096        rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i));
1097        rpcPic->setIsLongTerm(0);
1098      }
1099    }
1100    for(;i<pReferencePictureSet->getNumberOfPictures();i++)
1101    {
1102      if(pReferencePictureSet->getCheckLTMSBPresent(i)==true)
1103      {
1104        if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()) == pReferencePictureSet->getPOC(i))
1105        {
1106          isReference = 1;
1107          rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i));
1108        }
1109      }
1110      else 
1111      {
1112        if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC())) == pReferencePictureSet->getPOC(i)%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC()))
1113        {
1114          isReference = 1;
1115          rpcPic->setUsedByCurr(pReferencePictureSet->getUsed(i));
1116        }
1117      }
1118
1119    }
1120    // mark the picture as "unused for reference" if it is not in
1121    // the Reference Picture Set
1122    if(rpcPic->getPicSym()->getSlice(0)->getPOC() != this->getPOC() && isReference == 0)   
1123    {           
1124      rpcPic->getSlice( 0 )->setReferenced( false );   
1125      rpcPic->setIsLongTerm(0);
1126    }
1127    //check that pictures of higher temporal layers are not used
1128    assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getUsedByCurr()==0||rpcPic->getTLayer()<=this->getTLayer());
1129    //check that pictures of higher or equal temporal layer are not in the RPS if the current picture is a TSA picture
1130    if(this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TLA || this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N)
1131    {
1132      assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getTLayer()<this->getTLayer());
1133    }
1134    //check that pictures marked as temporal layer non-reference pictures are not used for reference
1135    if(rpcPic->getPicSym()->getSlice(0)->getPOC() != this->getPOC() && rpcPic->getTLayer()==this->getTLayer())
1136    {
1137      assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getUsedByCurr()==0||rpcPic->getSlice( 0 )->getTemporalLayerNonReferenceFlag()==false);
1138    }
1139  }
1140}
1141
1142/** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet.
1143*/
1144Int TComSlice::checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess)
1145{
1146  TComPic* rpcPic;
1147  Int i, isAvailable, j;
1148  Int atLeastOneLost = 0;
1149  Int atLeastOneRemoved = 0;
1150  Int iPocLost = 0;
1151
1152  // loop through all long-term pictures in the Reference Picture Set
1153  // to see if the picture should be kept as reference picture
1154  for(i=pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures();i<pReferencePictureSet->getNumberOfPictures();i++)
1155  {
1156    j = 0;
1157    isAvailable = 0;
1158    // loop through all pictures in the reference picture buffer
1159    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1160    while ( iterPic != rcListPic.end())
1161    {
1162      j++;
1163      rpcPic = *(iterPic++);
1164      if(pReferencePictureSet->getCheckLTMSBPresent(i)==true)
1165      {
1166        if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()) == pReferencePictureSet->getPOC(i) && rpcPic->getSlice(0)->isReferenced())
1167        {
1168          isAvailable = 1;
1169        }
1170      }
1171      else 
1172      {
1173        if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC())) == pReferencePictureSet->getPOC(i)%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC()) && rpcPic->getSlice(0)->isReferenced())
1174        {
1175          isAvailable = 1;
1176        }
1177      }
1178    }
1179    // if there was no such long-term check the short terms
1180    if(!isAvailable)
1181    {
1182      iterPic = rcListPic.begin();
1183      while ( iterPic != rcListPic.end())
1184      {
1185        j++;
1186        rpcPic = *(iterPic++);
1187
1188        if((rpcPic->getPicSym()->getSlice(0)->getPOC()%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC())) == (this->getPOC() + pReferencePictureSet->getDeltaPOC(i))%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC()) && rpcPic->getSlice(0)->isReferenced())
1189        {
1190          isAvailable = 1;
1191          rpcPic->setIsLongTerm(1);
1192          break;
1193        }
1194      }
1195    }
1196    // report that a picture is lost if it is in the Reference Picture Set
1197    // but not available as reference picture
1198    if(isAvailable == 0)   
1199    {           
1200      if (this->getPOC() + pReferencePictureSet->getDeltaPOC(i) >= pocRandomAccess)
1201      {
1202        if(!pReferencePictureSet->getUsed(i) )
1203        {
1204          if(printErrors)
1205          {
1206            printf("\nLong-term reference picture with POC = %3d seems to have been removed or not correctly decoded.", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
1207          }
1208          atLeastOneRemoved = 1;
1209        }
1210        else
1211        {
1212          if(printErrors)
1213          {
1214            printf("\nLong-term reference picture with POC = %3d is lost or not correctly decoded!", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
1215          }
1216          atLeastOneLost = 1;
1217          iPocLost=this->getPOC() + pReferencePictureSet->getDeltaPOC(i);
1218        }
1219      }
1220    }
1221  } 
1222  // loop through all short-term pictures in the Reference Picture Set
1223  // to see if the picture should be kept as reference picture
1224  for(i=0;i<pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures();i++)
1225  {
1226    j = 0;
1227    isAvailable = 0;
1228    // loop through all pictures in the reference picture buffer
1229    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1230    while ( iterPic != rcListPic.end())
1231    {
1232      j++;
1233      rpcPic = *(iterPic++);
1234
1235      if(!rpcPic->getIsLongTerm() && rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i) && rpcPic->getSlice(0)->isReferenced())
1236      {
1237        isAvailable = 1;
1238      }
1239    }
1240    // report that a picture is lost if it is in the Reference Picture Set
1241    // but not available as reference picture
1242    if(isAvailable == 0)   
1243    {           
1244      if (this->getPOC() + pReferencePictureSet->getDeltaPOC(i) >= pocRandomAccess)
1245      {
1246        if(!pReferencePictureSet->getUsed(i) )
1247        {
1248          if(printErrors)
1249            printf("\nShort-term reference picture with POC = %3d seems to have been removed or not correctly decoded.", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
1250          atLeastOneRemoved = 1;
1251        }
1252        else
1253        {
1254          if(printErrors)
1255            printf("\nShort-term reference picture with POC = %3d is lost or not correctly decoded!", this->getPOC() + pReferencePictureSet->getDeltaPOC(i));
1256          atLeastOneLost = 1;
1257          iPocLost=this->getPOC() + pReferencePictureSet->getDeltaPOC(i);
1258        }
1259      }
1260    }
1261  }   
1262  if(atLeastOneLost)
1263  {
1264    return iPocLost+1;
1265  }
1266  if(atLeastOneRemoved)
1267  {
1268    return -2;
1269  }
1270  else
1271  {
1272    return 0;
1273  }
1274}
1275
1276/** Function for constructing an explicit Reference Picture Set out of the available pictures in a referenced Reference Picture Set
1277*/
1278Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet)
1279{
1280  TComPic* rpcPic;
1281  Int i, j;
1282  Int k = 0;
1283  Int nrOfNegativePictures = 0;
1284  Int nrOfPositivePictures = 0;
1285  TComReferencePictureSet* pcRPS = this->getLocalRPS();
1286
1287  // loop through all pictures in the Reference Picture Set
1288  for(i=0;i<pReferencePictureSet->getNumberOfPictures();i++)
1289  {
1290    j = 0;
1291    // loop through all pictures in the reference picture buffer
1292    TComList<TComPic*>::iterator iterPic = rcListPic.begin();
1293    while ( iterPic != rcListPic.end())
1294    {
1295      j++;
1296      rpcPic = *(iterPic++);
1297
1298      if(rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getPOC() + pReferencePictureSet->getDeltaPOC(i) && rpcPic->getSlice(0)->isReferenced())
1299      {
1300        // This picture exists as a reference picture
1301        // and should be added to the explicit Reference Picture Set
1302        pcRPS->setDeltaPOC(k, pReferencePictureSet->getDeltaPOC(i));
1303        pcRPS->setUsed(k, pReferencePictureSet->getUsed(i));
1304        if(pcRPS->getDeltaPOC(k) < 0)
1305        {
1306          nrOfNegativePictures++;
1307        }
1308        else
1309        {
1310          nrOfPositivePictures++;
1311        }
1312        k++;
1313      }
1314    }
1315  }
1316  pcRPS->setNumberOfNegativePictures(nrOfNegativePictures);
1317  pcRPS->setNumberOfPositivePictures(nrOfPositivePictures);
1318  pcRPS->setNumberOfPictures(nrOfNegativePictures+nrOfPositivePictures);
1319  // This is a simplistic inter rps example. A smarter encoder will look for a better reference RPS to do the
1320  // inter RPS prediction with.  Here we just use the reference used by pReferencePictureSet.
1321  // If pReferencePictureSet is not inter_RPS_predicted, then inter_RPS_prediction is for the current RPS also disabled.
1322  if (!pReferencePictureSet->getInterRPSPrediction())
1323  {
1324    pcRPS->setInterRPSPrediction(false);
1325    pcRPS->setNumRefIdc(0);
1326  }
1327  else
1328  {
1329    Int rIdx =  this->getRPSidx() - pReferencePictureSet->getDeltaRIdxMinus1() - 1;
1330    Int deltaRPS = pReferencePictureSet->getDeltaRPS();
1331    TComReferencePictureSet* pcRefRPS = this->getSPS()->getRPSList()->getReferencePictureSet(rIdx);
1332    Int iRefPics = pcRefRPS->getNumberOfPictures();
1333    Int iNewIdc=0;
1334    for(i=0; i<= iRefPics; i++) 
1335    {
1336      Int deltaPOC = ((i != iRefPics)? pcRefRPS->getDeltaPOC(i) : 0);  // check if the reference abs POC is >= 0
1337      Int iRefIdc = 0;
1338      for (j=0; j < pcRPS->getNumberOfPictures(); j++) // loop through the  pictures in the new RPS
1339      {
1340        if ( (deltaPOC + deltaRPS) == pcRPS->getDeltaPOC(j))
1341        {
1342          if (pcRPS->getUsed(j))
1343          {
1344            iRefIdc = 1;
1345          }
1346          else
1347          {
1348            iRefIdc = 2;
1349          }
1350        }
1351      }
1352      pcRPS->setRefIdc(i, iRefIdc);
1353      iNewIdc++;
1354    }
1355    pcRPS->setInterRPSPrediction(true);
1356    pcRPS->setNumRefIdc(iNewIdc);
1357    pcRPS->setDeltaRPS(deltaRPS); 
1358    pcRPS->setDeltaRIdxMinus1(pReferencePictureSet->getDeltaRIdxMinus1() + this->getSPS()->getRPSList()->getNumberOfReferencePictureSets() - this->getRPSidx());
1359  }
1360
1361  this->setRPS(pcRPS);
1362  this->setRPSidx(-1);
1363}
1364
1365/** get AC and DC values for weighted pred
1366 * \param *wp
1367 * \returns Void
1368 */
1369Void  TComSlice::getWpAcDcParam(wpACDCParam *&wp)
1370{
1371  wp = m_weightACDCParam;
1372}
1373
1374/** init AC and DC values for weighted pred
1375 * \returns Void
1376 */
1377Void  TComSlice::initWpAcDcParam()
1378{
1379  for(Int iComp = 0; iComp < 3; iComp++ )
1380  {
1381    m_weightACDCParam[iComp].iAC = 0;
1382    m_weightACDCParam[iComp].iDC = 0;
1383  }
1384}
1385
1386/** get WP tables for weighted pred
1387 * \param RefPicList
1388 * \param iRefIdx
1389 * \param *&wpScalingParam
1390 * \returns Void
1391 */
1392Void  TComSlice::getWpScaling( RefPicList e, Int iRefIdx, wpScalingParam *&wp )
1393{
1394  wp = m_weightPredTable[e][iRefIdx];
1395}
1396
1397/** reset Default WP tables settings : no weight.
1398 * \param wpScalingParam
1399 * \returns Void
1400 */
1401Void  TComSlice::resetWpScaling(wpScalingParam  wp[2][MAX_NUM_REF][3])
1402{
1403  for ( Int e=0 ; e<2 ; e++ )
1404  {
1405    for ( Int i=0 ; i<MAX_NUM_REF ; i++ )
1406    {
1407      for ( Int yuv=0 ; yuv<3 ; yuv++ )
1408      {
1409        wpScalingParam  *pwp = &(wp[e][i][yuv]);
1410        pwp->bPresentFlag      = false;
1411        pwp->uiLog2WeightDenom = 0;
1412        pwp->uiLog2WeightDenom = 0;
1413        pwp->iWeight           = 1;
1414        pwp->iOffset           = 0;
1415      }
1416    }
1417  }
1418}
1419
1420/** init WP table
1421 * \returns Void
1422 */
1423Void  TComSlice::initWpScaling()
1424{
1425  initWpScaling(m_weightPredTable);
1426}
1427
1428/** set WP tables
1429 * \param wpScalingParam
1430 * \returns Void
1431 */
1432Void  TComSlice::initWpScaling(wpScalingParam  wp[2][MAX_NUM_REF][3])
1433{
1434  for ( Int e=0 ; e<2 ; e++ )
1435  {
1436    for ( Int i=0 ; i<MAX_NUM_REF ; i++ )
1437    {
1438      for ( Int yuv=0 ; yuv<3 ; yuv++ )
1439      {
1440        wpScalingParam  *pwp = &(wp[e][i][yuv]);
1441        if ( !pwp->bPresentFlag ) {
1442          // Inferring values not present :
1443          pwp->iWeight = (1 << pwp->uiLog2WeightDenom);
1444          pwp->iOffset = 0;
1445        }
1446
1447        pwp->w      = pwp->iWeight;
1448        Int bitDepth = yuv ? g_bitDepthC : g_bitDepthY;
1449        pwp->o      = pwp->iOffset << (bitDepth-8);
1450        pwp->shift  = pwp->uiLog2WeightDenom;
1451        pwp->round  = (pwp->uiLog2WeightDenom>=1) ? (1 << (pwp->uiLog2WeightDenom-1)) : (0);
1452      }
1453    }
1454  }
1455}
1456
1457// ------------------------------------------------------------------------------------------------
1458// Video parameter set (VPS)
1459// ------------------------------------------------------------------------------------------------
1460TComVPS::TComVPS()
1461: m_VPSId                     (  0)
1462, m_uiMaxTLayers              (  1)
1463, m_uiMaxLayers               (  1)
1464, m_bTemporalIdNestingFlag    (false)
1465, m_numHrdParameters          (  0)
1466#if !VPS_RENAME
1467, m_maxNuhReservedZeroLayerId (  0)
1468#endif
1469, m_hrdParameters             (NULL)
1470, m_hrdOpSetIdx               (NULL)
1471, m_cprmsPresentFlag          (NULL)
1472#if VPS_RENAME
1473, m_maxLayerId                (0)
1474, m_numLayerSets              (0)
1475#endif
1476{
1477
1478  for( Int i = 0; i < MAX_TLAYER; i++)
1479  {
1480    m_numReorderPics[i] = 0;
1481    m_uiMaxDecPicBuffering[i] = 0; 
1482    m_uiMaxLatencyIncrease[i] = 0;
1483  }
1484}
1485
1486TComVPS::~TComVPS()
1487{
1488  if( m_hrdParameters    != NULL )     delete m_hrdParameters;
1489  if( m_hrdOpSetIdx      != NULL )     delete m_hrdOpSetIdx;
1490  if( m_cprmsPresentFlag != NULL )     delete m_cprmsPresentFlag;
1491}
1492
1493// ------------------------------------------------------------------------------------------------
1494// Sequence parameter set (SPS)
1495// ------------------------------------------------------------------------------------------------
1496
1497TComSPS::TComSPS()
1498: m_SPSId                     (  0)
1499, m_VPSId                     (  0)
1500, m_chromaFormatIdc           (CHROMA_420)
1501, m_uiMaxTLayers              (  1)
1502// Structure
1503, m_picWidthInLumaSamples     (352)
1504, m_picHeightInLumaSamples    (288)
1505, m_uiMaxCUWidth              ( 32)
1506, m_uiMaxCUHeight             ( 32)
1507, m_uiMaxCUDepth              (  3)
1508, m_uiMinTrDepth              (  0)
1509, m_uiMaxTrDepth              (  1)
1510, m_bLongTermRefsPresent      (false)
1511, m_uiQuadtreeTULog2MaxSize   (  0)
1512, m_uiQuadtreeTULog2MinSize   (  0)
1513, m_uiQuadtreeTUMaxDepthInter (  0)
1514, m_uiQuadtreeTUMaxDepthIntra (  0)
1515// Tool list
1516, m_usePCM                   (false)
1517, m_pcmLog2MaxSize            (  5)
1518, m_uiPCMLog2MinSize          (  7)
1519, m_bUseLComb                 (false)
1520, m_bitDepthY                 (  8)
1521, m_bitDepthC                 (  8)
1522, m_qpBDOffsetY               (  0)
1523, m_qpBDOffsetC               (  0)
1524, m_useLossless               (false)
1525, m_uiPCMBitDepthLuma         (  8)
1526, m_uiPCMBitDepthChroma       (  8)
1527, m_bPCMFilterDisableFlag     (false)
1528, m_uiBitsForPOC              (  8)
1529, m_numLongTermRefPicSPS    (  0) 
1530, m_uiMaxTrSize               ( 32)
1531, m_bUseSAO                   (false) 
1532, m_bTemporalIdNestingFlag    (false)
1533, m_scalingListEnabledFlag    (false)
1534, m_useStrongIntraSmoothing   (false)
1535, m_vuiParametersPresentFlag  (false)
1536, m_vuiParameters             ()
1537#if SVC_EXTENSION
1538, m_layerId(0)
1539#endif
1540{
1541  for ( Int i = 0; i < MAX_TLAYER; i++ )
1542  {
1543    m_uiMaxLatencyIncrease[i] = 0;
1544    m_uiMaxDecPicBuffering[i] = 0;
1545    m_numReorderPics[i]       = 0;
1546  }
1547  m_scalingList = new TComScalingList;
1548  ::memset(m_ltRefPicPocLsbSps, 0, sizeof(m_ltRefPicPocLsbSps));
1549  ::memset(m_usedByCurrPicLtSPSFlag, 0, sizeof(m_usedByCurrPicLtSPSFlag));
1550}
1551
1552TComSPS::~TComSPS()
1553{
1554  delete m_scalingList;
1555  m_RPSList.destroy();
1556}
1557
1558Void  TComSPS::createRPSList( Int numRPS )
1559{ 
1560  m_RPSList.destroy();
1561  m_RPSList.create(numRPS);
1562}
1563Void TComSPS::setHrdParameters( UInt frameRate, UInt numDU, UInt bitRate, Bool randomAccess )
1564{
1565  if( !getVuiParametersPresentFlag() )
1566  {
1567    return;
1568  }
1569
1570  TComVUI *vui = getVuiParameters();
1571  TComHRD *hrd = vui->getHrdParameters();
1572
1573#if L0043_TIMING_INFO
1574  TimingInfo *timingInfo = vui->getTimingInfo();
1575  timingInfo->setTimingInfoPresentFlag( true );
1576  switch( frameRate )
1577  {
1578  case 24:
1579    timingInfo->setNumUnitsInTick( 1125000 );    timingInfo->setTimeScale    ( 27000000 );
1580    break;
1581  case 25:
1582    timingInfo->setNumUnitsInTick( 1080000 );    timingInfo->setTimeScale    ( 27000000 );
1583    break;
1584  case 30:
1585    timingInfo->setNumUnitsInTick( 900900 );     timingInfo->setTimeScale    ( 27000000 );
1586    break;
1587  case 50:
1588    timingInfo->setNumUnitsInTick( 540000 );     timingInfo->setTimeScale    ( 27000000 );
1589    break;
1590  case 60:
1591    timingInfo->setNumUnitsInTick( 450450 );     timingInfo->setTimeScale    ( 27000000 );
1592    break;
1593  default:
1594    timingInfo->setNumUnitsInTick( 1001 );       timingInfo->setTimeScale    ( 60000 );
1595    break;
1596  }
1597#else
1598  hrd->setTimingInfoPresentFlag( true );
1599  switch( frameRate )
1600  {
1601  case 24:
1602    hrd->setNumUnitsInTick( 1125000 );    hrd->setTimeScale    ( 27000000 );
1603    break;
1604  case 25:
1605    hrd->setNumUnitsInTick( 1080000 );    hrd->setTimeScale    ( 27000000 );
1606    break;
1607  case 30:
1608    hrd->setNumUnitsInTick( 900900 );     hrd->setTimeScale    ( 27000000 );
1609    break;
1610  case 50:
1611    hrd->setNumUnitsInTick( 540000 );     hrd->setTimeScale    ( 27000000 );
1612    break;
1613  case 60:
1614    hrd->setNumUnitsInTick( 450450 );     hrd->setTimeScale    ( 27000000 );
1615    break;
1616  default:
1617    hrd->setNumUnitsInTick( 1001 );       hrd->setTimeScale    ( 60000 );
1618    break;
1619  }
1620#endif
1621
1622  Bool rateCnt = ( bitRate > 0 );
1623  hrd->setNalHrdParametersPresentFlag( rateCnt );
1624  hrd->setVclHrdParametersPresentFlag( rateCnt );
1625
1626  hrd->setSubPicCpbParamsPresentFlag( ( numDU > 1 ) );
1627
1628  if( hrd->getSubPicCpbParamsPresentFlag() )
1629  {
1630    hrd->setTickDivisorMinus2( 100 - 2 );                          //
1631    hrd->setDuCpbRemovalDelayLengthMinus1( 7 );                    // 8-bit precision ( plus 1 for last DU in AU )
1632    hrd->setSubPicCpbParamsInPicTimingSEIFlag( true );
1633#if L0044_DU_DPB_OUTPUT_DELAY_HRD
1634    hrd->setDpbOutputDelayDuLengthMinus1( 5 + 7 );                 // With sub-clock tick factor of 100, at least 7 bits to have the same value as AU dpb delay
1635#endif
1636  }
1637  else
1638  {
1639    hrd->setSubPicCpbParamsInPicTimingSEIFlag( false ); 
1640  }
1641
1642  hrd->setBitRateScale( 4 );                                       // in units of 2~( 6 + 4 ) = 1,024 bps
1643  hrd->setCpbSizeScale( 6 );                                       // in units of 2~( 4 + 4 ) = 1,024 bit
1644  hrd->setDuCpbSizeScale( 6 );                                       // in units of 2~( 4 + 4 ) = 1,024 bit
1645 
1646  hrd->setInitialCpbRemovalDelayLengthMinus1(15);                  // assuming 0.5 sec, log2( 90,000 * 0.5 ) = 16-bit
1647  if( randomAccess )
1648  {
1649    hrd->setCpbRemovalDelayLengthMinus1(5);                        // 32 = 2^5 (plus 1)
1650    hrd->setDpbOutputDelayLengthMinus1 (5);                        // 32 + 3 = 2^6
1651  }
1652  else
1653  {
1654    hrd->setCpbRemovalDelayLengthMinus1(9);                        // max. 2^10
1655    hrd->setDpbOutputDelayLengthMinus1 (9);                        // max. 2^10
1656  }
1657
1658/*
1659   Note: only the case of "vps_max_temporal_layers_minus1 = 0" is supported.
1660*/
1661  Int i, j;
1662  UInt birateValue, cpbSizeValue;
1663  UInt ducpbSizeValue;
1664#if L0363_DU_BIT_RATE
1665  UInt duBitRateValue = 0;
1666#endif
1667
1668  for( i = 0; i < MAX_TLAYER; i ++ )
1669  {
1670    hrd->setFixedPicRateFlag( i, 1 );
1671    hrd->setPicDurationInTcMinus1( i, 0 );
1672    hrd->setLowDelayHrdFlag( i, 0 );
1673    hrd->setCpbCntMinus1( i, 0 );
1674
1675    birateValue  = bitRate;
1676    cpbSizeValue = bitRate;                                     // 1 second
1677    ducpbSizeValue = bitRate/numDU;
1678#if L0363_DU_BIT_RATE
1679    duBitRateValue = bitRate;
1680#endif
1681    for( j = 0; j < ( hrd->getCpbCntMinus1( i ) + 1 ); j ++ )
1682    {
1683      hrd->setBitRateValueMinus1( i, j, 0, ( birateValue  - 1 ) );
1684      hrd->setCpbSizeValueMinus1( i, j, 0, ( cpbSizeValue - 1 ) );
1685      hrd->setDuCpbSizeValueMinus1( i, j, 0, ( ducpbSizeValue - 1 ) );
1686      hrd->setCbrFlag( i, j, 0, ( j == 0 ) );
1687
1688      hrd->setBitRateValueMinus1( i, j, 1, ( birateValue  - 1) );
1689      hrd->setCpbSizeValueMinus1( i, j, 1, ( cpbSizeValue - 1 ) );
1690      hrd->setDuCpbSizeValueMinus1( i, j, 1, ( ducpbSizeValue - 1 ) );
1691#if L0363_DU_BIT_RATE
1692      hrd->setDuBitRateValueMinus1( i, j, 1, ( duBitRateValue - 1 ) );
1693#endif
1694      hrd->setCbrFlag( i, j, 1, ( j == 0 ) );
1695    }
1696  }
1697}
1698const Int TComSPS::m_winUnitX[]={1,2,2,1};
1699const Int TComSPS::m_winUnitY[]={1,2,1,1};
1700
1701TComPPS::TComPPS()
1702: m_PPSId                       (0)
1703, m_SPSId                       (0)
1704, m_picInitQPMinus26            (0)
1705, m_useDQP                      (false)
1706, m_bConstrainedIntraPred       (false)
1707, m_bSliceChromaQpFlag          (false)
1708, m_pcSPS                       (NULL)
1709, m_uiMaxCuDQPDepth             (0)
1710, m_uiMinCuDQPSize              (0)
1711, m_chromaCbQpOffset            (0)
1712, m_chromaCrQpOffset            (0)
1713, m_numRefIdxL0DefaultActive    (1)
1714, m_numRefIdxL1DefaultActive    (1)
1715, m_TransquantBypassEnableFlag  (false)
1716, m_useTransformSkip             (false)
1717, m_dependentSliceSegmentsEnabledFlag    (false)
1718, m_tilesEnabledFlag               (false)
1719, m_entropyCodingSyncEnabledFlag   (false)
1720, m_loopFilterAcrossTilesEnabledFlag  (true)
1721, m_uniformSpacingFlag           (0)
1722, m_iNumColumnsMinus1            (0)
1723, m_puiColumnWidth               (NULL)
1724, m_iNumRowsMinus1               (0)
1725, m_puiRowHeight                 (NULL)
1726, m_iNumSubstreams             (1)
1727, m_signHideFlag(0)
1728, m_cabacInitPresentFlag        (false)
1729, m_encCABACTableIdx            (I_SLICE)
1730, m_sliceHeaderExtensionPresentFlag    (false)
1731, m_loopFilterAcrossSlicesEnabledFlag (false)
1732, m_listsModificationPresentFlag(  0)
1733, m_numExtraSliceHeaderBits(0)
1734{
1735  m_scalingList = new TComScalingList;
1736}
1737
1738TComPPS::~TComPPS()
1739{
1740  if( m_iNumColumnsMinus1 > 0 && m_uniformSpacingFlag == 0 )
1741  {
1742    if (m_puiColumnWidth) delete [] m_puiColumnWidth; 
1743    m_puiColumnWidth = NULL;
1744  }
1745  if( m_iNumRowsMinus1 > 0 && m_uniformSpacingFlag == 0 )
1746  {
1747    if (m_puiRowHeight) delete [] m_puiRowHeight;
1748    m_puiRowHeight = NULL;
1749  }
1750  delete m_scalingList;
1751}
1752
1753TComReferencePictureSet::TComReferencePictureSet()
1754: m_numberOfPictures (0)
1755, m_numberOfNegativePictures (0)
1756, m_numberOfPositivePictures (0)
1757, m_numberOfLongtermPictures (0)
1758, m_interRPSPrediction (0) 
1759, m_deltaRIdxMinus1 (0)   
1760, m_deltaRPS (0) 
1761, m_numRefIdc (0) 
1762{
1763  ::memset( m_deltaPOC, 0, sizeof(m_deltaPOC) );
1764  ::memset( m_POC, 0, sizeof(m_POC) );
1765  ::memset( m_used, 0, sizeof(m_used) );
1766  ::memset( m_refIdc, 0, sizeof(m_refIdc) );
1767}
1768
1769TComReferencePictureSet::~TComReferencePictureSet()
1770{
1771}
1772
1773Void TComReferencePictureSet::setUsed(Int bufferNum, Bool used)
1774{
1775  m_used[bufferNum] = used;
1776}
1777
1778Void TComReferencePictureSet::setDeltaPOC(Int bufferNum, Int deltaPOC)
1779{
1780  m_deltaPOC[bufferNum] = deltaPOC;
1781}
1782
1783Void TComReferencePictureSet::setNumberOfPictures(Int numberOfPictures)
1784{
1785  m_numberOfPictures = numberOfPictures;
1786}
1787
1788Int TComReferencePictureSet::getUsed(Int bufferNum)
1789{
1790  return m_used[bufferNum];
1791}
1792
1793Int TComReferencePictureSet::getDeltaPOC(Int bufferNum)
1794{
1795  return m_deltaPOC[bufferNum];
1796}
1797
1798Int TComReferencePictureSet::getNumberOfPictures()
1799{
1800  return m_numberOfPictures;
1801}
1802
1803Int TComReferencePictureSet::getPOC(Int bufferNum)
1804{
1805  return m_POC[bufferNum];
1806}
1807Void TComReferencePictureSet::setPOC(Int bufferNum, Int POC)
1808{
1809  m_POC[bufferNum] = POC;
1810}
1811Bool TComReferencePictureSet::getCheckLTMSBPresent(Int bufferNum)
1812{
1813  return m_bCheckLTMSB[bufferNum];
1814}
1815Void TComReferencePictureSet::setCheckLTMSBPresent(Int bufferNum, Bool b)
1816{
1817  m_bCheckLTMSB[bufferNum] = b;
1818}
1819
1820/** set the reference idc value at uiBufferNum entry to the value of iRefIdc
1821 * \param uiBufferNum
1822 * \param iRefIdc
1823 * \returns Void
1824 */
1825Void TComReferencePictureSet::setRefIdc(Int bufferNum, Int refIdc)
1826{
1827  m_refIdc[bufferNum] = refIdc;
1828}
1829
1830/** get the reference idc value at uiBufferNum
1831 * \param uiBufferNum
1832 * \returns Int
1833 */
1834Int  TComReferencePictureSet::getRefIdc(Int bufferNum)
1835{
1836  return m_refIdc[bufferNum];
1837}
1838
1839/** Sorts the deltaPOC and Used by current values in the RPS based on the deltaPOC values.
1840 *  deltaPOC values are sorted with -ve values before the +ve values.  -ve values are in decreasing order.
1841 *  +ve values are in increasing order.
1842 * \returns Void
1843 */
1844Void TComReferencePictureSet::sortDeltaPOC()
1845{
1846  // sort in increasing order (smallest first)
1847  for(Int j=1; j < getNumberOfPictures(); j++)
1848  { 
1849    Int deltaPOC = getDeltaPOC(j);
1850    Bool used = getUsed(j);
1851    for (Int k=j-1; k >= 0; k--)
1852    {
1853      Int temp = getDeltaPOC(k);
1854      if (deltaPOC < temp)
1855      {
1856        setDeltaPOC(k+1, temp);
1857        setUsed(k+1, getUsed(k));
1858        setDeltaPOC(k, deltaPOC);
1859        setUsed(k, used);
1860      }
1861    }
1862  }
1863  // flip the negative values to largest first
1864  Int numNegPics = getNumberOfNegativePictures();
1865  for(Int j=0, k=numNegPics-1; j < numNegPics>>1; j++, k--)
1866  { 
1867    Int deltaPOC = getDeltaPOC(j);
1868    Bool used = getUsed(j);
1869    setDeltaPOC(j, getDeltaPOC(k));
1870    setUsed(j, getUsed(k));
1871    setDeltaPOC(k, deltaPOC);
1872    setUsed(k, used);
1873  }
1874}
1875
1876/** Prints the deltaPOC and RefIdc (if available) values in the RPS.
1877 *  A "*" is added to the deltaPOC value if it is Used bu current.
1878 * \returns Void
1879 */
1880Void TComReferencePictureSet::printDeltaPOC()
1881{
1882  printf("DeltaPOC = { ");
1883  for(Int j=0; j < getNumberOfPictures(); j++)
1884  {
1885    printf("%d%s ", getDeltaPOC(j), (getUsed(j)==1)?"*":"");
1886  } 
1887  if (getInterRPSPrediction()) 
1888  {
1889    printf("}, RefIdc = { ");
1890    for(Int j=0; j < getNumRefIdc(); j++)
1891    {
1892      printf("%d ", getRefIdc(j));
1893    } 
1894  }
1895  printf("}\n");
1896}
1897
1898TComRPSList::TComRPSList()
1899:m_referencePictureSets (NULL)
1900{
1901}
1902
1903TComRPSList::~TComRPSList()
1904{
1905}
1906
1907Void TComRPSList::create( Int numberOfReferencePictureSets)
1908{
1909  m_numberOfReferencePictureSets = numberOfReferencePictureSets;
1910  m_referencePictureSets = new TComReferencePictureSet[numberOfReferencePictureSets];
1911}
1912
1913Void TComRPSList::destroy()
1914{
1915  if (m_referencePictureSets)
1916  {
1917    delete [] m_referencePictureSets;
1918  }
1919  m_numberOfReferencePictureSets = 0;
1920  m_referencePictureSets = NULL;
1921}
1922
1923
1924
1925TComReferencePictureSet* TComRPSList::getReferencePictureSet(Int referencePictureSetNum)
1926{
1927  return &m_referencePictureSets[referencePictureSetNum];
1928}
1929
1930Int TComRPSList::getNumberOfReferencePictureSets()
1931{
1932  return m_numberOfReferencePictureSets;
1933}
1934
1935Void TComRPSList::setNumberOfReferencePictureSets(Int numberOfReferencePictureSets)
1936{
1937  m_numberOfReferencePictureSets = numberOfReferencePictureSets;
1938}
1939
1940TComRefPicListModification::TComRefPicListModification()
1941: m_bRefPicListModificationFlagL0 (false)
1942, m_bRefPicListModificationFlagL1 (false)
1943{
1944  ::memset( m_RefPicSetIdxL0, 0, sizeof(m_RefPicSetIdxL0) );
1945  ::memset( m_RefPicSetIdxL1, 0, sizeof(m_RefPicSetIdxL1) );
1946}
1947
1948TComRefPicListModification::~TComRefPicListModification()
1949{
1950}
1951
1952TComScalingList::TComScalingList()
1953{
1954  m_useTransformSkip = false;
1955  init();
1956}
1957TComScalingList::~TComScalingList()
1958{
1959  destroy();
1960}
1961
1962/** set default quantization matrix to array
1963*/
1964Void TComSlice::setDefaultScalingList()
1965{
1966  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
1967  {
1968    for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++)
1969    {
1970      getScalingList()->processDefaultMarix(sizeId, listId);
1971    }
1972  }
1973}
1974/** check if use default quantization matrix
1975 * \returns true if use default quantization matrix in all size
1976*/
1977Bool TComSlice::checkDefaultScalingList()
1978{
1979  UInt defaultCounter=0;
1980
1981  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
1982  {
1983    for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++)
1984    {
1985      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
1986     && ((sizeId < SCALING_LIST_16x16) || (getScalingList()->getScalingListDC(sizeId,listId) == 16))) // check DC value
1987      {
1988        defaultCounter++;
1989      }
1990    }
1991  }
1992  return (defaultCounter == (SCALING_LIST_NUM * SCALING_LIST_SIZE_NUM - 4)) ? false : true; // -4 for 32x32
1993}
1994/** get scaling matrix from RefMatrixID
1995 * \param sizeId size index
1996 * \param Index of input matrix
1997 * \param Index of reference matrix
1998 */
1999Void TComScalingList::processRefMatrix( UInt sizeId, UInt listId , UInt refListId )
2000{
2001  ::memcpy(getScalingListAddress(sizeId, listId),((listId == refListId)? getScalingListDefaultAddress(sizeId, refListId): getScalingListAddress(sizeId, refListId)),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
2002}
2003/** parse syntax infomation
2004 *  \param pchFile syntax infomation
2005 *  \returns false if successful
2006 */
2007Bool TComScalingList::xParseScalingList(Char* pchFile)
2008{
2009  FILE *fp;
2010  Char line[1024];
2011  UInt sizeIdc,listIdc;
2012  UInt i,size = 0;
2013  Int *src=0,data;
2014  Char *ret;
2015  UInt  retval;
2016
2017  if((fp = fopen(pchFile,"r")) == (FILE*)NULL)
2018  {
2019    printf("can't open file %s :: set Default Matrix\n",pchFile);
2020    return true;
2021  }
2022
2023  for(sizeIdc = 0; sizeIdc < SCALING_LIST_SIZE_NUM; sizeIdc++)
2024  {
2025    size = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeIdc]);
2026    for(listIdc = 0; listIdc < g_scalingListNum[sizeIdc]; listIdc++)
2027    {
2028      src = getScalingListAddress(sizeIdc, listIdc);
2029
2030      fseek(fp,0,0);
2031      do 
2032      {
2033        ret = fgets(line, 1024, fp);
2034        if ((ret==NULL)||(strstr(line, MatrixType[sizeIdc][listIdc])==NULL && feof(fp)))
2035        {
2036          printf("Error: can't read Matrix :: set Default Matrix\n");
2037          return true;
2038        }
2039      }
2040      while (strstr(line, MatrixType[sizeIdc][listIdc]) == NULL);
2041      for (i=0; i<size; i++)
2042      {
2043        retval = fscanf(fp, "%d,", &data);
2044        if (retval!=1)
2045        {
2046          printf("Error: can't read Matrix :: set Default Matrix\n");
2047          return true;
2048        }
2049        src[i] = data;
2050      }
2051      //set DC value for default matrix check
2052      setScalingListDC(sizeIdc,listIdc,src[0]);
2053
2054      if(sizeIdc > SCALING_LIST_8x8)
2055      {
2056        fseek(fp,0,0);
2057        do 
2058        {
2059          ret = fgets(line, 1024, fp);
2060          if ((ret==NULL)||(strstr(line, MatrixType_DC[sizeIdc][listIdc])==NULL && feof(fp)))
2061          {
2062            printf("Error: can't read DC :: set Default Matrix\n");
2063            return true;
2064          }
2065        }
2066        while (strstr(line, MatrixType_DC[sizeIdc][listIdc]) == NULL);
2067        retval = fscanf(fp, "%d,", &data);
2068        if (retval!=1)
2069        {
2070          printf("Error: can't read Matrix :: set Default Matrix\n");
2071          return true;
2072        }
2073        //overwrite DC value when size of matrix is larger than 16x16
2074        setScalingListDC(sizeIdc,listIdc,data);
2075      }
2076    }
2077  }
2078  fclose(fp);
2079  return false;
2080}
2081
2082/** initialization process of quantization matrix array
2083 */
2084Void TComScalingList::init()
2085{
2086  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
2087  {
2088    for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++)
2089    {
2090      m_scalingListCoef[sizeId][listId] = new Int [min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])];
2091    }
2092  }
2093  m_scalingListCoef[SCALING_LIST_32x32][3] = m_scalingListCoef[SCALING_LIST_32x32][1]; // copy address for 32x32
2094}
2095/** destroy quantization matrix array
2096 */
2097Void TComScalingList::destroy()
2098{
2099  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
2100  {
2101    for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++)
2102    {
2103      if(m_scalingListCoef[sizeId][listId]) delete [] m_scalingListCoef[sizeId][listId];
2104    }
2105  }
2106}
2107/** get default address of quantization matrix
2108 * \param sizeId size index
2109 * \param listId list index
2110 * \returns pointer of quantization matrix
2111 */
2112Int* TComScalingList::getScalingListDefaultAddress(UInt sizeId, UInt listId)
2113{
2114  Int *src = 0;
2115  switch(sizeId)
2116  {
2117    case SCALING_LIST_4x4:
2118      src = g_quantTSDefault4x4;
2119      break;
2120    case SCALING_LIST_8x8:
2121      src = (listId<3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
2122      break;
2123    case SCALING_LIST_16x16:
2124      src = (listId<3) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
2125      break;
2126    case SCALING_LIST_32x32:
2127      src = (listId<1) ? g_quantIntraDefault8x8 : g_quantInterDefault8x8;
2128      break;
2129    default:
2130      assert(0);
2131      src = NULL;
2132      break;
2133  }
2134  return src;
2135}
2136/** process of default matrix
2137 * \param sizeId size index
2138 * \param Index of input matrix
2139 */
2140Void TComScalingList::processDefaultMarix(UInt sizeId, UInt listId)
2141{
2142  ::memcpy(getScalingListAddress(sizeId, listId),getScalingListDefaultAddress(sizeId,listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
2143  setScalingListDC(sizeId,listId,SCALING_LIST_DC);
2144}
2145/** check DC value of matrix for default matrix signaling
2146 */
2147Void TComScalingList::checkDcOfMatrix()
2148{
2149  for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
2150  {
2151    for(UInt listId = 0; listId < g_scalingListNum[sizeId]; listId++)
2152    {
2153      //check default matrix?
2154      if(getScalingListDC(sizeId,listId) == 0)
2155      {
2156        processDefaultMarix(sizeId, listId);
2157      }
2158    }
2159  }
2160}
2161
2162ParameterSetManager::ParameterSetManager()
2163#if SVC_EXTENSION
2164: m_spsMap(MAX_NUM_SPS)
2165, m_ppsMap(MAX_NUM_PPS)
2166, m_activeSPSId(-1)
2167, m_activePPSId(-1)
2168#else
2169: m_vpsMap(MAX_NUM_VPS)
2170, m_spsMap(MAX_NUM_SPS)
2171, m_ppsMap(MAX_NUM_PPS)
2172, m_activeVPSId(-1)
2173, m_activeSPSId(-1)
2174, m_activePPSId(-1)
2175#endif
2176{
2177}
2178
2179
2180ParameterSetManager::~ParameterSetManager()
2181{
2182}
2183
2184//! activate a SPS from a active parameter sets SEI message
2185//! \returns true, if activation is successful
2186Bool ParameterSetManager::activateSPSWithSEI(Int spsId)
2187{
2188  TComSPS *sps = m_spsMap.getPS(spsId);
2189  if (sps)
2190  {
2191    Int vpsId = sps->getVPSId();
2192    if (m_vpsMap.getPS(vpsId))
2193    {
2194      m_activeVPSId = vpsId;
2195      m_activeSPSId = spsId;
2196      return true;
2197    }
2198    else
2199    {
2200      printf("Warning: tried to activate SPS using an Active parameter sets SEI message. Referenced VPS does not exist.");
2201    }
2202  }
2203  else
2204  {
2205    printf("Warning: tried to activate non-existing SPS using an Active parameter sets SEI message.");
2206  }
2207  return false;
2208}
2209
2210//! activate a PPS and depending on isIDR parameter also SPS and VPS
2211//! \returns true, if activation is successful
2212Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIDR)
2213{
2214  TComPPS *pps = m_ppsMap.getPS(ppsId);
2215  if (pps)
2216  {
2217    Int spsId = pps->getSPSId();
2218    if (!isIDR && (spsId != m_activeSPSId))
2219    {
2220      printf("Warning: tried to activate PPS referring to a inactive SPS at non-IDR.");
2221      return false;
2222    }
2223    TComSPS *sps = m_spsMap.getPS(spsId);
2224    if (sps)
2225    {
2226      Int vpsId = sps->getVPSId();
2227      if (!isIDR && (vpsId != m_activeVPSId))
2228      {
2229        printf("Warning: tried to activate PPS referring to a inactive VPS at non-IDR.");
2230        return false;
2231      }
2232      if (m_vpsMap.getPS(vpsId))
2233      {
2234        m_activePPSId = ppsId;
2235        m_activeVPSId = vpsId;
2236        m_activeSPSId = spsId;
2237        return true;
2238      }
2239      else
2240      {
2241        printf("Warning: tried to activate PPS that refers to a non-existing VPS.");
2242      }
2243    }
2244    else
2245    {
2246      printf("Warning: tried to activate a PPS that refers to a non-existing SPS.");
2247    }
2248  }
2249  else
2250  {
2251    printf("Warning: tried to activate non-existing PPS.");
2252  }
2253  return false;
2254}
2255
2256ProfileTierLevel::ProfileTierLevel()
2257  : m_profileSpace    (0)
2258  , m_tierFlag        (false)
2259  , m_profileIdc      (0)
2260  , m_levelIdc        (0)
2261#if L0046_CONSTRAINT_FLAGS
2262, m_progressiveSourceFlag  (false)
2263, m_interlacedSourceFlag   (false)
2264, m_nonPackedConstraintFlag(false)
2265, m_frameOnlyConstraintFlag(false)
2266#endif
2267{
2268  ::memset(m_profileCompatibilityFlag, 0, sizeof(m_profileCompatibilityFlag));
2269}
2270
2271TComPTL::TComPTL()
2272{
2273  ::memset(m_subLayerProfilePresentFlag, 0, sizeof(m_subLayerProfilePresentFlag));
2274  ::memset(m_subLayerLevelPresentFlag,   0, sizeof(m_subLayerLevelPresentFlag  ));
2275}
2276#if SIGNAL_BITRATE_PICRATE_IN_VPS
2277TComBitRatePicRateInfo::TComBitRatePicRateInfo()
2278{
2279  ::memset(m_bitRateInfoPresentFlag, 0, sizeof(m_bitRateInfoPresentFlag));
2280  ::memset(m_picRateInfoPresentFlag, 0, sizeof(m_picRateInfoPresentFlag));
2281  ::memset(m_avgBitRate,             0, sizeof(m_avgBitRate));
2282  ::memset(m_maxBitRate,             0, sizeof(m_maxBitRate));
2283  ::memset(m_constantPicRateIdc,     0, sizeof(m_constantPicRateIdc));
2284  ::memset(m_avgPicRate,             0, sizeof(m_avgPicRate));
2285}
2286#endif
2287
2288#if SVC_EXTENSION
2289#if AVC_SYNTAX
2290Void TComSlice::initBaseLayerRPL( TComSlice *pcSlice )
2291{
2292// 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
2293  setPOC( pcSlice->getPOC() );
2294  if( pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA )
2295  {
2296    setSliceType( I_SLICE );
2297  }
2298  else
2299  {
2300    setSliceType( pcSlice->getSliceType() );
2301  }
2302
2303  if( this->isIntra() )
2304  {
2305    return;
2306  }
2307
2308  //initialize reference POC of BL
2309  for( Int iRefPicList = 0; iRefPicList < 2; iRefPicList++ )
2310  {
2311    RefPicList eRefPicList = RefPicList( iRefPicList );
2312
2313    assert( pcSlice->getNumRefIdx( eRefPicList) >= 0 );
2314    setNumRefIdx( eRefPicList, pcSlice->getNumRefIdx( eRefPicList ) - 1 );
2315    assert( getNumRefIdx( eRefPicList) <= MAX_NUM_REF);
2316
2317    for(Int refIdx = 0; refIdx < getNumRefIdx( eRefPicList ); refIdx++) 
2318    {
2319      setRefPOC( pcSlice->getRefPic( eRefPicList, refIdx )->getPOC(), eRefPicList, refIdx );
2320      setRefPic( pcSlice->getRefPic( eRefPicList, refIdx ), eRefPicList, refIdx );
2321      /*
2322      // should be set if the base layer has its own instance of the reference picture lists, currently EL RPL is reused.
2323      getRefPic( eRefPicList, refIdx )->setLayerId( 0 );
2324      getRefPic( eRefPicList, refIdx )->setIsLongTerm( pcSlice->getRefPic( eRefPicList, refIdx )->getIsLongTerm() );     
2325      */
2326
2327    }
2328  } 
2329  return;
2330}
2331#endif
2332
2333Void TComSlice::setBaseColPic(  TComList<TComPic*>& rcListPic, UInt layerID )
2334{ 
2335  if (layerID == 0)
2336  {
2337    m_pcBaseColPic = NULL;
2338    return;
2339  }       
2340  setBaseColPic(xGetRefPic(rcListPic, getPOC())); 
2341}
2342#endif
2343
2344#if REF_IDX_FRAMEWORK
2345Void TComSlice::addRefPicList( TComPic **pIlpPicList, Int iRefPicNum, Int iInsertOffset )
2346{
2347  if(getSPS()->getLayerId() && m_eSliceType != I_SLICE)
2348  {
2349#if REF_IDX_MFM
2350    assert(iRefPicNum == 1);
2351#if RAP_MFM_INIT
2352    if(!(getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA && getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) && getSPS()->getMFMEnabledFlag())
2353#else
2354    if( getPOC() != 0 )
2355#endif
2356    { 
2357      pIlpPicList[0]->copyUpsampledMvField(getBaseColPic());
2358    }
2359#if RAP_MFM_INIT
2360    else
2361    {
2362      pIlpPicList[0]->initUpsampledMvField();
2363    }
2364#endif
2365#endif
2366    //add to list 0;
2367    Int iOffset;
2368    m_aiNumRefIdx[REF_PIC_LIST_0] += iInsertOffset;
2369    iOffset = m_aiNumRefIdx[REF_PIC_LIST_0];
2370    for (Int i=0; i<iRefPicNum; i++)
2371    {
2372      pIlpPicList[i]->setIsLongTerm(1);  //mark ilp as long-term reference
2373      m_bIsUsedAsLongTerm[REF_PIC_LIST_0][iOffset + i] = 1; //mark ilp as long-term reference
2374      m_apcRefPicList[REF_PIC_LIST_0][iOffset + i] = pIlpPicList[i]; 
2375      m_aiNumRefIdx[REF_PIC_LIST_0]++;
2376      //m_aiNumRefIdx[REF_PIC_LIST_C]++;
2377    }
2378    if(m_eSliceType == B_SLICE)
2379    {
2380      m_aiNumRefIdx[REF_PIC_LIST_1] += iInsertOffset;
2381      iOffset = m_aiNumRefIdx[REF_PIC_LIST_1];
2382      for (Int i=0; i<iRefPicNum; i++)
2383      {
2384        pIlpPicList[i]->setIsLongTerm(1);  //mark ilp as long-term reference
2385        m_bIsUsedAsLongTerm[REF_PIC_LIST_1][iOffset + i] = 1; //mark ilp as long-term reference
2386        m_apcRefPicList[REF_PIC_LIST_1][iOffset + i] = pIlpPicList[i]; 
2387        m_aiNumRefIdx[REF_PIC_LIST_1]++;
2388        //m_aiNumRefIdx[REF_PIC_LIST_C]++;
2389      }
2390    }
2391  }
2392}
2393
2394#if REF_IDX_MFM
2395Void TComSlice::setRefPOCListILP( TComPic** ilpPic, TComPic *pcRefPicBL )
2396{
2397  //set reference picture POC of each ILP reference
2398  Int thePoc = ilpPic[0]->getPOC(); 
2399  assert(thePoc >= 0); 
2400  assert(thePoc == pcRefPicBL->getPOC());
2401
2402#if REUSE_MVSCALE || REUSE_BLKMAPPING
2403  ilpPic[0]->getSlice(0)->setBaseColPic( pcRefPicBL );
2404#endif
2405
2406  //copy reference pictures marking from the reference layer
2407  ilpPic[0]->getSlice(0)->copySliceInfo(pcRefPicBL->getSlice(0));
2408 
2409  for( Int refList = 0; refList < 2; refList++ )
2410  {
2411    RefPicList refPicList = RefPicList( refList );
2412   
2413    //set reference POC of ILP
2414    ilpPic[0]->getSlice(0)->setNumRefIdx(refPicList, pcRefPicBL->getSlice(0)->getNumRefIdx(refPicList));
2415    assert(ilpPic[0]->getSlice(0)->getNumRefIdx(refPicList) >= 0);
2416    assert(ilpPic[0]->getSlice(0)->getNumRefIdx(refPicList) <= MAX_NUM_REF);
2417
2418    //initialize reference POC of ILP
2419    for(Int refIdx = 0; refIdx < pcRefPicBL->getSlice(0)->getNumRefIdx(refPicList); refIdx++)
2420    {
2421      ilpPic[0]->getSlice(0)->setRefPOC(pcRefPicBL->getSlice(0)->getRefPOC(refPicList, refIdx), refPicList, refIdx);
2422      ilpPic[0]->getSlice(0)->setRefPic(pcRefPicBL->getSlice(0)->getRefPic(refPicList, refIdx), refPicList, refIdx);
2423    }
2424
2425    for(Int refIdx = pcRefPicBL->getSlice(0)->getNumRefIdx(refPicList); refIdx < MAX_NUM_REF; refIdx++) 
2426    { 
2427      ilpPic[0]->getSlice(0)->setRefPOC(0, refPicList, refIdx); 
2428      ilpPic[0]->getSlice(0)->setRefPic(NULL, refPicList, refIdx); 
2429    }
2430  }
2431  return;
2432}
2433#endif
2434
2435
2436#endif
2437//! \}
Note: See TracBrowser for help on using the repository browser.