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

Last change on this file since 521 was 521, checked in by tech, 11 years ago

Integrated following changes:

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