source: SHVCSoftware/branches/SHM-2.1-multilayers-dev/source/Lib/TLibCommon/TComSlice.cpp @ 254

Last change on this file since 254 was 253, checked in by seregin, 12 years ago

initial multilayer reference implementation

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