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

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

Merged HTM-DEV-0.3-dev1 Rev. 520.

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