source: 3DVCSoftware/branches/HTM-DEV-0.3-dev0/source/Lib/TLibCommon/TComSlice.cpp @ 498

Last change on this file since 498 was 498, checked in by tech, 12 years ago

Further fixes and new nonctc cfg files.

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