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

Last change on this file since 504 was 504, checked in by zhang, 11 years ago

Merge Dev2.a to Dev2 and simulation results updated

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