source: SHVCSoftware/branches/SHM-dev/source/Lib/TLibEncoder/TEncTop.cpp @ 1311

Last change on this file since 1311 was 1309, checked in by seregin, 9 years ago

port rev 4380

  • Property svn:eol-style set to native
File size: 54.4 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license.
5 *
6 * Copyright (c) 2010-2015, 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     TEncTop.cpp
35    \brief    encoder class
36*/
37
38#include "TLibCommon/CommonDef.h"
39#include "TEncTop.h"
40#include "TEncPic.h"
41#include "TLibCommon/TComChromaFormat.h"
42#if FAST_BIT_EST
43#include "TLibCommon/ContextModel.h"
44#endif
45
46//! \ingroup TLibEncoder
47//! \{
48#if SVC_EXTENSION 
49Int TEncTop::m_iSPSIdCnt = 0;
50Int TEncTop::m_iPPSIdCnt = 0;
51TComVPS TEncCfg::m_cVPS;
52#endif
53
54// ====================================================================================================================
55// Constructor / destructor / create / destroy
56// ====================================================================================================================
57
58TEncTop::TEncTop()
59{
60  m_iPOCLast          = -1;
61  m_iNumPicRcvd       =  0;
62  m_uiNumAllPicCoded  =  0;
63  m_pppcRDSbacCoder   =  NULL;
64  m_pppcBinCoderCABAC =  NULL;
65  m_cRDGoOnSbacCoder.init( &m_cRDGoOnBinCoderCABAC );
66#if ENC_DEC_TRACE
67  if (g_hTrace == NULL)
68  {
69    g_hTrace = fopen( "TraceEnc.txt", "wb" );
70  }
71  g_bJustDoIt = g_bEncDecTraceDisable;
72  g_nSymbolCounter = 0;
73#endif
74
75  m_iMaxRefPicNum     = 0;
76
77#if FAST_BIT_EST
78  ContextModel::buildNextStateTable();
79#endif
80
81#if SVC_EXTENSION
82  memset( m_cIlpPic, 0, sizeof(m_cIlpPic) );
83  m_bMFMEnabledFlag = false;
84  m_numRefLayerLocationOffsets = 0;
85  m_pocAdjustmentValue     = 0;
86#if NO_CLRAS_OUTPUT_FLAG
87  m_noClrasOutputFlag          = false;
88  m_layerInitializedFlag       = false;
89  m_firstPicInLayerDecodedFlag = false;
90  m_noOutputOfPriorPicsFlags   = false;
91#endif
92  m_pocDecrementedInDPBFlag    = false;
93#endif //SVC_EXTENSION
94}
95
96TEncTop::~TEncTop()
97{
98#if ENC_DEC_TRACE
99  if (g_hTrace != stdout)
100  {
101    fclose( g_hTrace );
102  }
103#endif
104}
105
106Void TEncTop::create ()
107{
108#if !SVC_EXTENSION
109  // initialize global variables
110  initROM();
111#endif
112
113  // create processing unit classes
114#if SVC_EXTENSION
115  m_cGOPEncoder.        create( m_layerId );
116#else
117  m_cGOPEncoder.        create( );
118#endif
119  m_cSliceEncoder.      create( getSourceWidth(), getSourceHeight(), m_chromaFormatIDC, m_maxCUWidth, m_maxCUHeight, m_maxTotalCUDepth );
120  m_cCuEncoder.         create( m_maxTotalCUDepth, m_maxCUWidth, m_maxCUHeight, m_chromaFormatIDC );
121  if (m_bUseSAO)
122  {
123    m_cEncSAO.create( getSourceWidth(), getSourceHeight(), m_chromaFormatIDC, m_maxCUWidth, m_maxCUHeight, m_maxTotalCUDepth, m_saoOffsetBitShift[CHANNEL_TYPE_LUMA], m_saoOffsetBitShift[CHANNEL_TYPE_CHROMA] );
124#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
125    m_cEncSAO.createEncData(getSaoCtuBoundary());
126#else
127    m_cEncSAO.createEncData();
128#endif
129  }
130#if ADAPTIVE_QP_SELECTION
131  if (m_bUseAdaptQpSelect)
132  {
133    m_cTrQuant.initSliceQpDelta();
134  }
135#endif
136
137  m_cLoopFilter.create( m_maxTotalCUDepth );
138
139  if ( m_RCEnableRateControl )
140  {
141    m_cRateCtrl.init( m_framesToBeEncoded, m_RCTargetBitrate, m_iFrameRate, m_iGOPSize, m_iSourceWidth, m_iSourceHeight,
142        m_maxCUWidth, m_maxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList );
143  }
144
145  m_pppcRDSbacCoder = new TEncSbac** [m_maxTotalCUDepth+1];
146#if FAST_BIT_EST
147  m_pppcBinCoderCABAC = new TEncBinCABACCounter** [m_maxTotalCUDepth+1];
148#else
149  m_pppcBinCoderCABAC = new TEncBinCABAC** [m_maxTotalCUDepth+1];
150#endif
151
152  for ( Int iDepth = 0; iDepth < m_maxTotalCUDepth+1; iDepth++ )
153  {
154    m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM];
155#if FAST_BIT_EST
156    m_pppcBinCoderCABAC[iDepth] = new TEncBinCABACCounter* [CI_NUM];
157#else
158    m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM];
159#endif
160
161    for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
162    {
163      m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac;
164#if FAST_BIT_EST
165      m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABACCounter;
166#else
167      m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC;
168#endif
169      m_pppcRDSbacCoder   [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] );
170    }
171  }
172
173#if LAYER_CTB
174  memcpy(g_auiLayerZscanToRaster[m_layerId], g_auiZscanToRaster, sizeof( g_auiZscanToRaster ) );
175  memcpy(g_auiLayerRasterToZscan[m_layerId], g_auiRasterToZscan, sizeof( g_auiRasterToZscan ) );
176  memcpy(g_auiLayerRasterToPelX[m_layerId],  g_auiRasterToPelX,  sizeof( g_auiRasterToPelX ) );
177  memcpy(g_auiLayerRasterToPelY[m_layerId],  g_auiRasterToPelY,  sizeof( g_auiRasterToPelY ) );
178#endif
179}
180
181Void TEncTop::destroy ()
182{
183  // destroy processing unit classes
184  m_cGOPEncoder.        destroy();
185  m_cSliceEncoder.      destroy();
186  m_cCuEncoder.         destroy();
187  m_cEncSAO.            destroyEncData();
188  m_cEncSAO.            destroy();
189  m_cLoopFilter.        destroy();
190  m_cRateCtrl.          destroy();
191  Int iDepth;
192  for ( iDepth = 0; iDepth < m_maxTotalCUDepth+1; iDepth++ )
193  {
194    for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
195    {
196      delete m_pppcRDSbacCoder[iDepth][iCIIdx];
197      delete m_pppcBinCoderCABAC[iDepth][iCIIdx];
198    }
199  }
200
201  for ( iDepth = 0; iDepth < m_maxTotalCUDepth+1; iDepth++ )
202  {
203    delete [] m_pppcRDSbacCoder[iDepth];
204    delete [] m_pppcBinCoderCABAC[iDepth];
205  }
206
207  delete [] m_pppcRDSbacCoder;
208  delete [] m_pppcBinCoderCABAC;
209 
210#if SVC_EXTENSION
211  for(Int i=0; i<MAX_NUM_REF; i++)
212  {
213    if(m_cIlpPic[i])
214    {
215      m_cIlpPic[i]->destroy();
216      delete m_cIlpPic[i];
217      m_cIlpPic[i] = NULL;
218    }
219  }
220#else
221  // destroy ROM
222  destroyROM();
223#endif
224  return;
225}
226
227Void TEncTop::init(Bool isFieldCoding)
228{
229  // initialize SPS
230  xInitSPS();
231  xInitVPS();
232
233  m_cRdCost.setCostMode(m_costMode);
234
235  // initialize PPS
236  xInitPPS();
237  xInitRPS(isFieldCoding);
238
239  xInitPPSforTiles();
240
241  // initialize processing unit classes
242  m_cGOPEncoder.  init( this );
243  m_cSliceEncoder.init( this );
244  m_cCuEncoder.   init( this );
245
246  // initialize transform & quantization class
247  m_pcCavlcCoder = getCavlcCoder();
248
249  m_cTrQuant.init( 1 << m_uiQuadtreeTULog2MaxSize,
250                   m_useRDOQ,
251                   m_useRDOQTS,
252#if T0196_SELECTIVE_RDOQ
253                   m_useSelectiveRDOQ,
254#endif
255                   true
256                  ,m_useTransformSkipFast
257#if ADAPTIVE_QP_SELECTION
258                  ,m_bUseAdaptQpSelect
259#endif
260                  );
261
262  // initialize encoder search class
263  m_cSearch.init( this, &m_cTrQuant, m_iSearchRange, m_bipredSearchRange, m_iFastSearch, m_maxCUWidth, m_maxCUHeight, m_maxTotalCUDepth, &m_cEntropyCoder, &m_cRdCost, getRDSbacCoder(), getRDGoOnSbacCoder() );
264
265  m_iMaxRefPicNum = 0;
266
267  xInitScalingLists();
268
269#if SVC_EXTENSION
270  m_iSPSIdCnt ++;
271  m_iPPSIdCnt ++;
272  xInitILRP();
273#endif
274}
275
276Void TEncTop::xInitScalingLists()
277{
278  // Initialise scaling lists
279  // The encoder will only use the SPS scaling lists. The PPS will never be marked present.
280  const Int maxLog2TrDynamicRange[MAX_NUM_CHANNEL_TYPE] =
281  {
282      m_cSPS.getMaxLog2TrDynamicRange(CHANNEL_TYPE_LUMA),
283      m_cSPS.getMaxLog2TrDynamicRange(CHANNEL_TYPE_CHROMA)
284  };
285  if(getUseScalingListId() == SCALING_LIST_OFF)
286  {
287#if SVC_EXTENSION
288    getTrQuant()->setFlatScalingList( maxLog2TrDynamicRange, m_cVPS.getBitDepths(&m_cSPS, m_layerId) );
289#else
290    getTrQuant()->setFlatScalingList(maxLog2TrDynamicRange, m_cSPS.getBitDepths());
291#endif
292    getTrQuant()->setUseScalingList(false);
293    m_cSPS.setScalingListPresentFlag(false);
294    m_cPPS.setScalingListPresentFlag(false);
295  }
296  else if(getUseScalingListId() == SCALING_LIST_DEFAULT)
297  {
298#if SVC_EXTENSION
299    // inferring of the scaling list can be moved to the config file
300    UInt refLayerId = 0;
301    if( m_layerId > 0 && !m_cVPS.getNonHEVCBaseLayerFlag() && m_cVPS.getRecursiveRefLayerFlag( m_layerId, refLayerId ) )
302    {
303      m_cSPS.setInferScalingListFlag( true );
304      m_cSPS.setScalingListRefLayerId( refLayerId );
305      m_cSPS.setScalingListPresentFlag( false );
306      m_cPPS.setInferScalingListFlag( false );
307      m_cPPS.setScalingListPresentFlag( false );
308
309      // infer the scaling list from the reference layer
310      getTrQuant()->setScalingList( &m_ppcTEncTop[m_cVPS.getLayerIdxInVps(refLayerId)]->getSPS()->getScalingList(), maxLog2TrDynamicRange, m_cVPS.getBitDepths(&m_cSPS, m_layerId) );
311    }
312    else
313    {
314#endif
315    m_cSPS.getScalingList().setDefaultScalingList ();
316    m_cSPS.setScalingListPresentFlag(false);
317    m_cPPS.setScalingListPresentFlag(false);
318
319#if SVC_EXTENSION
320    getTrQuant()->setScalingList(&(m_cSPS.getScalingList()), maxLog2TrDynamicRange, m_cVPS.getBitDepths(&m_cSPS, m_layerId));
321#else
322    getTrQuant()->setScalingList(&(m_cSPS.getScalingList()), maxLog2TrDynamicRange, m_cSPS.getBitDepths());
323#endif
324#if SVC_EXTENSION
325    }
326#endif
327    getTrQuant()->setUseScalingList(true);
328  }
329  else if(getUseScalingListId() == SCALING_LIST_FILE_READ)
330  {
331#if SVC_EXTENSION
332    // inferring of the scaling list can be moved to the config file
333    UInt refLayerId = 0;
334    if( m_layerId > 0 && !m_cVPS.getNonHEVCBaseLayerFlag() && m_cVPS.getRecursiveRefLayerFlag( m_layerId, refLayerId ) )
335    {
336      m_cSPS.setInferScalingListFlag( true );
337      m_cSPS.setScalingListRefLayerId( refLayerId );
338      m_cSPS.setScalingListPresentFlag( false );
339      m_cPPS.setInferScalingListFlag( false );
340      m_cPPS.setScalingListPresentFlag( false );
341
342      // infer the scaling list from the reference layer
343      getTrQuant()->setScalingList( &m_ppcTEncTop[m_cVPS.getLayerIdxInVps(refLayerId)]->getSPS()->getScalingList(), maxLog2TrDynamicRange, m_cVPS.getBitDepths(&m_cSPS, m_layerId) );
344    }
345    else
346    {
347#endif
348    m_cSPS.getScalingList().setDefaultScalingList ();
349    if(m_cSPS.getScalingList().xParseScalingList(getScalingListFile()))
350    {
351      Bool bParsedScalingList=false; // Use of boolean so that assertion outputs useful string
352      assert(bParsedScalingList);
353      exit(1);
354    }
355    m_cSPS.getScalingList().checkDcOfMatrix();
356    m_cSPS.setScalingListPresentFlag(m_cSPS.getScalingList().checkDefaultScalingList());
357    m_cPPS.setScalingListPresentFlag(false);
358    getTrQuant()->setScalingList(&(m_cSPS.getScalingList()), maxLog2TrDynamicRange, m_cSPS.getBitDepths());
359#if SVC_EXTENSION
360    }
361#endif
362    getTrQuant()->setUseScalingList(true);
363  }
364  else
365  {
366    printf("error : ScalingList == %d not supported\n",getUseScalingListId());
367    assert(0);
368  }
369
370  if (getUseScalingListId() != SCALING_LIST_OFF)
371  {
372    // Prepare delta's:
373    for(UInt sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
374    {
375      const Int predListStep = (sizeId == SCALING_LIST_32x32? (SCALING_LIST_NUM/NUMBER_OF_PREDICTION_MODES) : 1); // if 32x32, skip over chroma entries.
376
377      for(UInt listId = 0; listId < SCALING_LIST_NUM; listId+=predListStep)
378      {
379        m_cSPS.getScalingList().checkPredMode( sizeId, listId );
380      }
381    }
382  }
383}
384
385// ====================================================================================================================
386// Public member functions
387// ====================================================================================================================
388
389Void TEncTop::deletePicBuffer()
390{
391  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
392  Int iSize = Int( m_cListPic.size() );
393
394  for ( Int i = 0; i < iSize; i++ )
395  {
396    TComPic* pcPic = *(iterPic++);
397
398    pcPic->destroy();
399    delete pcPic;
400    pcPic = NULL;
401  }
402}
403
404/**
405 - Application has picture buffer list with size of GOP + 1
406 - Picture buffer list acts like as ring buffer
407 - End of the list has the latest picture
408 .
409 \param   flush               cause encoder to encode a partial GOP
410 \param   pcPicYuvOrg         original YUV picture
411 \param   pcPicYuvTrueOrg     
412 \param   snrCSC
413 \retval  rcListPicYuvRecOut  list of reconstruction YUV pictures
414 \retval  accessUnitsOut      list of output access units
415 \retval  iNumEncoded         number of encoded pictures
416 */
417#if SVC_EXTENSION
418Void TEncTop::encode( TComPicYuv* pcPicYuvOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP )
419{
420  // compress GOP
421#if !RC_SHVC_HARMONIZATION
422  if ( m_RCEnableRateControl )
423  {
424    m_cRateCtrl.initRCGOP( m_iNumPicRcvd );
425  }
426#endif
427
428  // compress GOP
429  m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false, snrCSC, m_printFrameMSE);
430
431#if !RC_SHVC_HARMONIZATION
432  if ( m_RCEnableRateControl )
433  {
434    m_cRateCtrl.destroyRCGOP();
435  }
436#endif
437 
438  m_uiNumAllPicCoded ++;
439}
440
441Void TEncTop::encodePrep( TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg )
442{
443  if (pcPicYuvOrg != NULL)
444  {
445    // get original YUV
446    TComPic* pcPicCurr = NULL;
447    xGetNewPicBuffer( pcPicCurr );
448    pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() );
449    pcPicYuvTrueOrg->copyToPic( pcPicCurr->getPicYuvTrueOrg() );
450
451    // compute image characteristics
452    if ( getUseAdaptiveQP() )
453    {
454      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) );
455    }
456  }
457}
458#else
459Void TEncTop::encode( Bool flush, TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded )
460{
461  if (pcPicYuvOrg != NULL)
462  {
463    // get original YUV
464    TComPic* pcPicCurr = NULL;
465
466    xGetNewPicBuffer( pcPicCurr );
467    pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() );
468    pcPicYuvTrueOrg->copyToPic( pcPicCurr->getPicYuvTrueOrg() );
469
470    // compute image characteristics
471    if ( getUseAdaptiveQP() )
472    {
473      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) );
474    }
475  }
476
477  if ((m_iNumPicRcvd == 0) || (!flush && (m_iPOCLast != 0) && (m_iNumPicRcvd != m_iGOPSize) && (m_iGOPSize != 0)))
478  {
479    iNumEncoded = 0;
480    return;
481  }
482
483  if ( m_RCEnableRateControl )
484  {
485    m_cRateCtrl.initRCGOP( m_iNumPicRcvd );
486  }
487
488  // compress GOP
489  m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false, snrCSC, m_printFrameMSE);
490
491  if ( m_RCEnableRateControl )
492  {
493    m_cRateCtrl.destroyRCGOP();
494  }
495
496  iNumEncoded         = m_iNumPicRcvd;
497  m_iNumPicRcvd       = 0;
498  m_uiNumAllPicCoded += iNumEncoded;
499}
500#endif
501
502/**------------------------------------------------
503 Separate interlaced frame into two fields
504 -------------------------------------------------**/
505Void separateFields(Pel* org, Pel* dstField, UInt stride, UInt width, UInt height, Bool isTop)
506{
507  if (!isTop)
508  {
509    org += stride;
510  }
511  for (Int y = 0; y < height>>1; y++)
512  {
513    for (Int x = 0; x < width; x++)
514    {
515      dstField[x] = org[x];
516    }
517
518    dstField += stride;
519    org += stride*2;
520  }
521
522}
523
524#if SVC_EXTENSION
525Void TEncTop::encodePrep( TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, Bool isTff )
526{
527  for (Int fieldNum=0; fieldNum<2; fieldNum++)
528  {
529    if (pcPicYuvOrg)
530    {
531      /* -- field initialization -- */
532      const Bool isTopField=isTff==(fieldNum==0);
533
534      TComPic *pcField;
535      xGetNewPicBuffer( pcField );
536      pcField->setReconMark (false);                     // where is this normally?
537           
538      pcField->getSlice(0)->setPOC( m_iPOCLast );        // superfluous?
539      pcField->getPicYuvRec()->setBorderExtension(false);// where is this normally?
540
541      pcField->setTopField(isTopField);                  // interlaced requirement
542
543      for (UInt componentIndex = 0; componentIndex < pcPicYuvOrg->getNumberValidComponents(); componentIndex++)
544      {
545        const ComponentID component = ComponentID(componentIndex);
546        const UInt stride = pcPicYuvOrg->getStride(component);
547
548        separateFields((pcPicYuvOrg->getBuf(component) + pcPicYuvOrg->getMarginX(component) + (pcPicYuvOrg->getMarginY(component) * stride)),
549                       pcField->getPicYuvOrg()->getAddr(component),
550                       pcPicYuvOrg->getStride(component),
551                       pcPicYuvOrg->getWidth(component),
552                       pcPicYuvOrg->getHeight(component),
553                       isTopField);
554
555        separateFields((pcPicYuvTrueOrg->getBuf(component) + pcPicYuvTrueOrg->getMarginX(component) + (pcPicYuvTrueOrg->getMarginY(component) * stride)),
556                       pcField->getPicYuvTrueOrg()->getAddr(component),
557                       pcPicYuvTrueOrg->getStride(component),
558                       pcPicYuvTrueOrg->getWidth(component),
559                       pcPicYuvTrueOrg->getHeight(component),
560                       isTopField);
561      }
562
563      // compute image characteristics
564      if ( getUseAdaptiveQP() )
565      {
566        m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcField ) );
567      }
568    }
569  }
570}
571
572Void TEncTop::encode( TComPicYuv* pcPicYuvOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP, Bool isTff )
573{
574  for (Int fieldNum=0; fieldNum<2; fieldNum++)
575  {
576    if (pcPicYuvOrg)
577    {
578      if (fieldNum==1)                                   // where is this normally?
579      {
580        TComPicYuv* rpcPicYuvRec;
581
582        // org. buffer
583        if ( rcListPicYuvRecOut.size() >= (UInt)m_iGOPSize+1 ) // need to maintain field 0 in list of RecOuts while processing field 1. Hence +1 on m_iGOPSize.
584        {
585          rpcPicYuvRec = rcListPicYuvRecOut.popFront();
586        }
587        else
588        {
589          rpcPicYuvRec = new TComPicYuv;
590          rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, m_maxCUWidth, m_maxCUHeight, m_maxTotalCUDepth, true);
591        }
592        rcListPicYuvRecOut.pushBack( rpcPicYuvRec );
593      }
594    }
595
596    // compress GOP
597    m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff, snrCSC, m_printFrameMSE);
598  }
599
600  m_uiNumAllPicCoded ++;
601}
602#else
603Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Bool isTff)
604{
605  iNumEncoded = 0;
606
607  for (Int fieldNum=0; fieldNum<2; fieldNum++)
608  {
609    if (pcPicYuvOrg)
610    {
611
612      /* -- field initialization -- */
613      const Bool isTopField=isTff==(fieldNum==0);
614
615      TComPic *pcField;
616      xGetNewPicBuffer( pcField );
617      pcField->setReconMark (false);                     // where is this normally?
618
619      if (fieldNum==1)                                   // where is this normally?
620      {
621        TComPicYuv* rpcPicYuvRec;
622
623        // org. buffer
624        if ( rcListPicYuvRecOut.size() >= (UInt)m_iGOPSize+1 ) // need to maintain field 0 in list of RecOuts while processing field 1. Hence +1 on m_iGOPSize.
625        {
626          rpcPicYuvRec = rcListPicYuvRecOut.popFront();
627        }
628        else
629        {
630          rpcPicYuvRec = new TComPicYuv;
631          rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, m_maxCUWidth, m_maxCUHeight, m_maxTotalCUDepth, true);
632        }
633        rcListPicYuvRecOut.pushBack( rpcPicYuvRec );
634      }
635
636      pcField->getSlice(0)->setPOC( m_iPOCLast );        // superfluous?
637      pcField->getPicYuvRec()->setBorderExtension(false);// where is this normally?
638
639      pcField->setTopField(isTopField);                  // interlaced requirement
640
641      for (UInt componentIndex = 0; componentIndex < pcPicYuvOrg->getNumberValidComponents(); componentIndex++)
642      {
643        const ComponentID component = ComponentID(componentIndex);
644        const UInt stride = pcPicYuvOrg->getStride(component);
645
646        separateFields((pcPicYuvOrg->getBuf(component) + pcPicYuvOrg->getMarginX(component) + (pcPicYuvOrg->getMarginY(component) * stride)),
647                       pcField->getPicYuvOrg()->getAddr(component),
648                       pcPicYuvOrg->getStride(component),
649                       pcPicYuvOrg->getWidth(component),
650                       pcPicYuvOrg->getHeight(component),
651                       isTopField);
652
653        separateFields((pcPicYuvTrueOrg->getBuf(component) + pcPicYuvTrueOrg->getMarginX(component) + (pcPicYuvTrueOrg->getMarginY(component) * stride)),
654                       pcField->getPicYuvTrueOrg()->getAddr(component),
655                       pcPicYuvTrueOrg->getStride(component),
656                       pcPicYuvTrueOrg->getWidth(component),
657                       pcPicYuvTrueOrg->getHeight(component),
658                       isTopField);
659      }
660
661      // compute image characteristics
662      if ( getUseAdaptiveQP() )
663      {
664        m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcField ) );
665      }
666    }
667
668    if ( m_iNumPicRcvd && ((flush&&fieldNum==1) || (m_iPOCLast/2)==0 || m_iNumPicRcvd==m_iGOPSize ) )
669    {
670      // compress GOP
671      m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff, snrCSC, m_printFrameMSE);
672
673      iNumEncoded += m_iNumPicRcvd;
674      m_uiNumAllPicCoded += m_iNumPicRcvd;
675      m_iNumPicRcvd = 0;
676    }
677  }
678}
679#endif
680
681// ====================================================================================================================
682// Protected member functions
683// ====================================================================================================================
684
685/**
686 - Application has picture buffer list with size of GOP + 1
687 - Picture buffer list acts like as ring buffer
688 - End of the list has the latest picture
689 .
690 \retval rpcPic obtained picture buffer
691 */
692Void TEncTop::xGetNewPicBuffer ( TComPic*& rpcPic )
693{
694  // At this point, the SPS and PPS can be considered activated - they are copied to the new TComPic.
695
696  TComSlice::sortPicList(m_cListPic);
697
698
699  if (m_cListPic.size() >= (UInt)(m_iGOPSize + getMaxDecPicBuffering(MAX_TLAYER-1) + 2) )
700  {
701    TComList<TComPic*>::iterator iterPic  = m_cListPic.begin();
702    Int iSize = Int( m_cListPic.size() );
703    for ( Int i = 0; i < iSize; i++ )
704    {
705      rpcPic = *(iterPic++);
706      if(rpcPic->getSlice(0)->isReferenced() == false)
707      {
708        break;
709      }
710    }
711  }
712  else
713  {
714    if ( getUseAdaptiveQP() )
715    {
716      TEncPic* pcEPic = new TEncPic;
717
718#if SVC_EXTENSION //Temporal solution, should be modified
719      if( m_layerId > 0 )
720      {
721        for( UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ )
722        {
723          const Window scalEL = m_cPPS.getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
724          const Window altRL = m_cPPS.getRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
725          Bool equalOffsets = scalEL.hasEqualOffset(altRL);
726          Bool zeroPhase = m_cPPS.hasZeroResamplingPhase(m_cVPS.getRefLayerId(m_layerId, i));
727
728          TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( i );
729
730          UInt refLayerId = m_cVPS.getRefLayerId(m_layerId, i);
731
732          const Int bitDepthLuma = m_cVPS.getBitDepth(CHANNEL_TYPE_LUMA, &m_cSPS, m_layerId);
733          const Int bitDepthChroma = m_cVPS.getBitDepth(CHANNEL_TYPE_CHROMA, &m_cSPS, m_layerId);
734          const Int refBitDepthLuma = m_cVPS.getBitDepth(CHANNEL_TYPE_LUMA, pcEncTopBase->getSPS(), refLayerId);
735          const Int refBitDepthChroma = m_cVPS.getBitDepth(CHANNEL_TYPE_CHROMA, pcEncTopBase->getSPS(), refLayerId);
736
737          Bool sameBitDepths = ( bitDepthLuma == refBitDepthLuma ) && ( bitDepthChroma == refBitDepthChroma );
738
739          if( m_iSourceWidth == pcEncTopBase->getSourceWidth() && m_iSourceHeight == pcEncTopBase->getSourceHeight() && equalOffsets && zeroPhase )
740          {
741            pcEPic->setEqualPictureSizeAndOffsetFlag( i, true );
742          }
743
744          if( !pcEPic->equalPictureSizeAndOffsetFlag(i) || !sameBitDepths
745#if CGS_3D_ASYMLUT
746            || m_cPPS.getCGSFlag() > 0
747#endif
748#if LAYER_CTB
749            || pcEncTopBase->getSPS()->getMaxCUWidth() != m_cSPS.getMaxCUWidth() || pcEncTopBase->getSPS()->getMaxCUHeight() != m_cSPS.getMaxCUHeight() || pcEncTopBase->getSPS()->getMaxCUDepth() != m_cSPS.getMaxCUDepth()
750#endif
751            )
752          {
753            pcEPic->setSpatialEnhLayerFlag( i, true );
754
755            //only for scalable extension
756            assert( m_cVPS.getScalabilityMask( SCALABILITY_ID ) == true );
757          }
758        }
759      }
760
761      pcEPic->create( m_cVPS, m_cSPS, m_cPPS, m_cPPS.getMaxCuDQPDepth()+1, false, m_layerId);
762#else  //SVC_EXTENSION
763      pcEPic->create( m_cSPS, m_cPPS, m_cPPS.getMaxCuDQPDepth()+1, false);
764#endif //SVC_EXTENSION
765      rpcPic = pcEPic;
766    }
767    else
768    {
769      rpcPic = new TComPic;
770
771#if SVC_EXTENSION //Temporal solution, should be modified
772      if( m_layerId > 0 )
773      {
774        for( UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ )
775        {
776          const Window scalEL = m_cPPS.getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
777          const Window altRL = m_cPPS.getRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
778          Bool equalOffsets = scalEL.hasEqualOffset(altRL);
779          Bool zeroPhase = m_cPPS.hasZeroResamplingPhase(m_cVPS.getRefLayerId(m_layerId, i));
780
781          TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( i );
782
783          UInt refLayerId = m_cVPS.getRefLayerId(m_layerId, i);
784
785          const Int bitDepthLuma = m_cVPS.getBitDepth(CHANNEL_TYPE_LUMA, &m_cSPS, m_layerId);
786          const Int bitDepthChroma = m_cVPS.getBitDepth(CHANNEL_TYPE_CHROMA, &m_cSPS, m_layerId);
787          const Int refBitDepthLuma = m_cVPS.getBitDepth(CHANNEL_TYPE_LUMA, pcEncTopBase->getSPS(), refLayerId);
788          const Int refBitDepthChroma = m_cVPS.getBitDepth(CHANNEL_TYPE_CHROMA, pcEncTopBase->getSPS(), refLayerId);
789
790          Bool sameBitDepths = ( bitDepthLuma == refBitDepthLuma ) && ( bitDepthChroma == refBitDepthChroma );
791
792          if( m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !sameBitDepths
793            || !equalOffsets
794            || !zeroPhase
795#if CGS_3D_ASYMLUT
796            || m_cPPS.getCGSFlag() > 0
797#endif
798#if LAYER_CTB
799            || pcEncTopBase->getSPS()->getMaxCUWidth() != m_cSPS.getMaxCUWidth() || pcEncTopBase->getSPS()->getMaxCUHeight() != m_cSPS.getMaxCUHeight() || pcEncTopBase->getSPS()->getMaxCUDepth() != m_cSPS.getMaxCUDepth()
800#endif
801            )
802          {
803            rpcPic->setSpatialEnhLayerFlag( i, true );
804
805            //only for scalable extension
806            assert( m_cVPS.getScalabilityMask( SCALABILITY_ID ) == true );
807          }
808        }
809      }
810
811      rpcPic->create( m_cVPS, m_cSPS, m_cPPS, false, m_layerId );
812#else  //SVC_EXTENSION
813      rpcPic->create( m_cSPS, m_cPPS, false );
814#endif //SVC_EXTENSION
815    }
816
817    m_cListPic.pushBack( rpcPic );
818  }
819  rpcPic->setReconMark (false);
820
821  m_iPOCLast++;
822  m_iNumPicRcvd++;
823
824  rpcPic->getSlice(0)->setPOC( m_iPOCLast );
825  // mark it should be extended
826  rpcPic->getPicYuvRec()->setBorderExtension(false);
827}
828
829Void TEncTop::xInitVPS()
830{
831  // The SPS must have already been set up.
832  // set the VPS profile information.
833#if SVC_EXTENSION
834  m_cVPS.setVpsVuiPresentFlag( true );
835#else
836  *m_cVPS.getPTL() = *m_cSPS.getPTL();
837  m_cVPS.setMaxOpSets(1);
838#endif
839  m_cVPS.getTimingInfo()->setTimingInfoPresentFlag       ( false );
840  m_cVPS.setNumHrdParameters( 0 );
841
842  m_cVPS.createHrdParamBuffer();
843  for( UInt i = 0; i < m_cVPS.getNumHrdParameters(); i ++ )
844  {
845    m_cVPS.setHrdOpSetIdx( 0, i );
846    m_cVPS.setCprmsPresentFlag( false, i );
847    // Set up HrdParameters here.
848  }
849}
850
851Void TEncTop::xInitSPS()
852{
853#if SVC_EXTENSION
854  m_cSPS.setExtensionFlag( m_layerId > 0 ? true : false );
855  m_cSPS.setNumDirectRefLayers(m_numDirectRefLayers);
856
857  if( !m_numDirectRefLayers && m_numAddLayerSets )
858  {
859    m_cSPS.setLayerId(0); // layer ID 0 for independent layers
860  }
861  else
862  {
863    m_cSPS.setLayerId(m_layerId);
864  }
865#endif //SVC_EXTENSION
866
867  ProfileTierLevel& profileTierLevel = *m_cSPS.getPTL()->getGeneralPTL();
868  profileTierLevel.setLevelIdc(m_level);
869  profileTierLevel.setTierFlag(m_levelTier);
870  profileTierLevel.setProfileIdc(m_profile);
871  profileTierLevel.setProfileCompatibilityFlag(m_profile, 1);
872  profileTierLevel.setProgressiveSourceFlag(m_progressiveSourceFlag);
873  profileTierLevel.setInterlacedSourceFlag(m_interlacedSourceFlag);
874  profileTierLevel.setNonPackedConstraintFlag(m_nonPackedConstraintFlag);
875  profileTierLevel.setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag);
876  profileTierLevel.setBitDepthConstraint(m_bitDepthConstraintValue);
877  profileTierLevel.setChromaFormatConstraint(m_chromaFormatConstraintValue);
878  profileTierLevel.setIntraConstraintFlag(m_intraConstraintFlag);
879  profileTierLevel.setLowerBitRateConstraintFlag(m_lowerBitRateConstraintFlag);
880
881  if ((m_profile == Profile::MAIN10) && (m_bitDepth[CHANNEL_TYPE_LUMA] == 8) && (m_bitDepth[CHANNEL_TYPE_CHROMA] == 8))
882  {
883    /* The above constraint is equal to Profile::MAIN */
884    profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN, 1);
885  }
886  if (m_profile == Profile::MAIN)
887  {
888    /* A Profile::MAIN10 decoder can always decode Profile::MAIN */
889    profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN10, 1);
890  }
891  /* XXX: should Main be marked as compatible with still picture? */
892  /* XXX: may be a good idea to refactor the above into a function
893   * that chooses the actual compatibility based upon options */
894
895  m_cSPS.setPicWidthInLumaSamples  ( m_iSourceWidth      );
896  m_cSPS.setPicHeightInLumaSamples ( m_iSourceHeight     );
897  m_cSPS.setConformanceWindow      ( m_conformanceWindow );
898  m_cSPS.setMaxCUWidth             ( m_maxCUWidth        );
899  m_cSPS.setMaxCUHeight            ( m_maxCUHeight       );
900  m_cSPS.setMaxTotalCUDepth        ( m_maxTotalCUDepth   );
901  m_cSPS.setChromaFormatIdc( m_chromaFormatIDC);
902  m_cSPS.setLog2DiffMaxMinCodingBlockSize(m_log2DiffMaxMinCodingBlockSize);
903
904  Int minCUSize = m_cSPS.getMaxCUWidth() >> ( m_cSPS.getLog2DiffMaxMinCodingBlockSize() );
905  Int log2MinCUSize = 0;
906  while(minCUSize > 1)
907  {
908    minCUSize >>= 1;
909    log2MinCUSize++;
910  }
911
912  m_cSPS.setLog2MinCodingBlockSize(log2MinCUSize);
913 
914#if SVC_EXTENSION
915  m_cSPS.setSPSId         ( m_iSPSIdCnt       );
916#endif
917 
918  m_cSPS.setPCMLog2MinSize (m_uiPCMLog2MinSize);
919  m_cSPS.setUsePCM        ( m_usePCM           );
920  m_cSPS.setPCMLog2MaxSize( m_pcmLog2MaxSize  );
921
922  m_cSPS.setQuadtreeTULog2MaxSize( m_uiQuadtreeTULog2MaxSize );
923  m_cSPS.setQuadtreeTULog2MinSize( m_uiQuadtreeTULog2MinSize );
924  m_cSPS.setQuadtreeTUMaxDepthInter( m_uiQuadtreeTUMaxDepthInter    );
925  m_cSPS.setQuadtreeTUMaxDepthIntra( m_uiQuadtreeTUMaxDepthIntra    );
926
927  m_cSPS.setTMVPFlagsPresent((getTMVPModeId() == 2 || getTMVPModeId() == 1));
928
929  m_cSPS.setMaxTrSize   ( 1 << m_uiQuadtreeTULog2MaxSize );
930
931  m_cSPS.setUseAMP ( m_useAMP );
932
933  for (UInt channelType = 0; channelType < MAX_NUM_CHANNEL_TYPE; channelType++)
934  {
935#if SVC_EXTENSION
936    m_cSPS.setBitDepth    (ChannelType(channelType), m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_cVPS.getLayerIdxInVps( m_layerId ) ) )->getBitDepthVps(ChannelType(channelType))            );   
937#if O0043_BEST_EFFORT_DECODING
938    m_cSPS.setStreamBitDepth(ChannelType(channelType), m_bitDepth[channelType] );
939#endif
940    m_cSPS.setQpBDOffset  (ChannelType(channelType), (6 * (m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_cVPS.getLayerIdxInVps( m_layerId ) ) )->getBitDepthVps(ChannelType(channelType)) - 8)));
941#else
942    m_cSPS.setBitDepth      (ChannelType(channelType), m_bitDepth[channelType] );
943#if O0043_BEST_EFFORT_DECODING
944    m_cSPS.setStreamBitDepth(ChannelType(channelType), m_bitDepth[channelType] );
945#endif
946    m_cSPS.setQpBDOffset  (ChannelType(channelType), (6 * (m_bitDepth[channelType] - 8)));
947#endif
948    m_cSPS.setPCMBitDepth (ChannelType(channelType), m_PCMBitDepth[channelType]         );
949  }
950
951  m_cSPS.setUseExtendedPrecision(m_useExtendedPrecision);
952  m_cSPS.setUseHighPrecisionPredictionWeighting(m_useHighPrecisionPredictionWeighting);
953
954  m_cSPS.setUseSAO( m_bUseSAO );
955  m_cSPS.setUseResidualRotation(m_useResidualRotation);
956  m_cSPS.setUseSingleSignificanceMapContext(m_useSingleSignificanceMapContext);
957  m_cSPS.setUseGolombRiceParameterAdaptation(m_useGolombRiceParameterAdaptation);
958  m_cSPS.setAlignCABACBeforeBypass(m_alignCABACBeforeBypass);
959
960  for (UInt signallingModeIndex = 0; signallingModeIndex < NUMBER_OF_RDPCM_SIGNALLING_MODES; signallingModeIndex++)
961  {
962    m_cSPS.setUseResidualDPCM(RDPCMSignallingMode(signallingModeIndex), m_useResidualDPCM[signallingModeIndex]);
963  }
964
965  m_cSPS.setMaxTLayers( m_maxTempLayer );
966  m_cSPS.setTemporalIdNestingFlag( ( m_maxTempLayer == 1 ) ? true : false );
967
968  for (Int i = 0; i < min(m_cSPS.getMaxTLayers(),(UInt) MAX_TLAYER); i++ )
969  {
970#if SVC_EXTENSION
971    assert( i < MAX_TLAYER );
972#endif
973    m_cSPS.setMaxDecPicBuffering(m_maxDecPicBuffering[i], i);
974    m_cSPS.setNumReorderPics(m_numReorderPics[i], i);
975  }
976
977  m_cSPS.setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag );
978  m_cSPS.setDisableIntraReferenceSmoothing( m_disableIntraReferenceSmoothing );
979  m_cSPS.setScalingListFlag ( (m_useScalingListId == SCALING_LIST_OFF) ? 0 : 1 );
980  m_cSPS.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing );
981  m_cSPS.setVuiParametersPresentFlag(getVuiParametersPresentFlag());
982
983  if (m_cSPS.getVuiParametersPresentFlag())
984  {
985    TComVUI* pcVUI = m_cSPS.getVuiParameters();
986    pcVUI->setAspectRatioInfoPresentFlag(getAspectRatioInfoPresentFlag());
987    pcVUI->setAspectRatioIdc(getAspectRatioIdc());
988    pcVUI->setSarWidth(getSarWidth());
989    pcVUI->setSarHeight(getSarHeight());
990    pcVUI->setOverscanInfoPresentFlag(getOverscanInfoPresentFlag());
991    pcVUI->setOverscanAppropriateFlag(getOverscanAppropriateFlag());
992    pcVUI->setVideoSignalTypePresentFlag(getVideoSignalTypePresentFlag());
993    pcVUI->setVideoFormat(getVideoFormat());
994    pcVUI->setVideoFullRangeFlag(getVideoFullRangeFlag());
995    pcVUI->setColourDescriptionPresentFlag(getColourDescriptionPresentFlag());
996    pcVUI->setColourPrimaries(getColourPrimaries());
997    pcVUI->setTransferCharacteristics(getTransferCharacteristics());
998    pcVUI->setMatrixCoefficients(getMatrixCoefficients());
999    pcVUI->setChromaLocInfoPresentFlag(getChromaLocInfoPresentFlag());
1000    pcVUI->setChromaSampleLocTypeTopField(getChromaSampleLocTypeTopField());
1001    pcVUI->setChromaSampleLocTypeBottomField(getChromaSampleLocTypeBottomField());
1002    pcVUI->setNeutralChromaIndicationFlag(getNeutralChromaIndicationFlag());
1003    pcVUI->setDefaultDisplayWindow(getDefaultDisplayWindow());
1004    pcVUI->setFrameFieldInfoPresentFlag(getFrameFieldInfoPresentFlag());
1005    pcVUI->setFieldSeqFlag(false);
1006    pcVUI->setHrdParametersPresentFlag(false);
1007    pcVUI->getTimingInfo()->setPocProportionalToTimingFlag(getPocProportionalToTimingFlag());
1008    pcVUI->getTimingInfo()->setNumTicksPocDiffOneMinus1   (getNumTicksPocDiffOneMinus1()   );
1009    pcVUI->setBitstreamRestrictionFlag(getBitstreamRestrictionFlag());
1010    pcVUI->setTilesFixedStructureFlag(getTilesFixedStructureFlag());
1011    pcVUI->setMotionVectorsOverPicBoundariesFlag(getMotionVectorsOverPicBoundariesFlag());
1012    pcVUI->setMinSpatialSegmentationIdc(getMinSpatialSegmentationIdc());
1013    pcVUI->setMaxBytesPerPicDenom(getMaxBytesPerPicDenom());
1014    pcVUI->setMaxBitsPerMinCuDenom(getMaxBitsPerMinCuDenom());
1015    pcVUI->setLog2MaxMvLengthHorizontal(getLog2MaxMvLengthHorizontal());
1016    pcVUI->setLog2MaxMvLengthVertical(getLog2MaxMvLengthVertical());
1017  }
1018  m_cSPS.setNumLongTermRefPicSPS(NUM_LONG_TERM_REF_PIC_SPS);
1019  assert (NUM_LONG_TERM_REF_PIC_SPS <= MAX_NUM_LONG_TERM_REF_PICS);
1020  for (Int k = 0; k < NUM_LONG_TERM_REF_PIC_SPS; k++)
1021  {
1022    m_cSPS.setLtRefPicPocLsbSps(k, 0);
1023    m_cSPS.setUsedByCurrPicLtSPSFlag(k, 0);
1024  }
1025  if( getPictureTimingSEIEnabled() || getDecodingUnitInfoSEIEnabled() )
1026  {
1027    Bool useDUParameters = (getSliceMode() > 0) || (getSliceSegmentMode() > 0);
1028    m_cSPS.setHrdParameters( getFrameRate(), useDUParameters, getTargetBitrate(), ( getIntraPeriod() > 0 ) );
1029  }
1030  if( getBufferingPeriodSEIEnabled() || getPictureTimingSEIEnabled() || getDecodingUnitInfoSEIEnabled() )
1031  {
1032    m_cSPS.getVuiParameters()->setHrdParametersPresentFlag( true );
1033  }
1034}
1035
1036Void TEncTop::xInitPPS()
1037{
1038  m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred );
1039  Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false;
1040
1041  if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP())
1042  {
1043    bUseDQP = true;
1044  }
1045
1046  if (m_costMode==COST_SEQUENCE_LEVEL_LOSSLESS || m_costMode==COST_LOSSLESS_CODING)
1047  {
1048    bUseDQP=false;
1049  }
1050
1051
1052  if ( m_RCEnableRateControl )
1053  {
1054    m_cPPS.setUseDQP(true);
1055    m_cPPS.setMaxCuDQPDepth( 0 );
1056  }
1057  else if(bUseDQP)
1058  {
1059    m_cPPS.setUseDQP(true);
1060    m_cPPS.setMaxCuDQPDepth( m_iMaxCuDQPDepth );
1061  }
1062  else
1063  {
1064    m_cPPS.setUseDQP(false);
1065    m_cPPS.setMaxCuDQPDepth( 0 );
1066  }
1067
1068  if ( m_maxCUChromaQpAdjustmentDepth >= 0 )
1069  {
1070    m_cPPS.setMaxCuChromaQpAdjDepth(m_maxCUChromaQpAdjustmentDepth);
1071    m_cPPS.setChromaQpAdjTableAt(1, 6, 6);
1072    /* todo, insert table entries from command line (NB, 0 should not be touched) */
1073  }
1074  else
1075  {
1076    m_cPPS.setMaxCuChromaQpAdjDepth(0);
1077    m_cPPS.clearChromaQpAdjTable();
1078  }
1079
1080  m_cPPS.setQpOffset(COMPONENT_Cb, m_chromaCbQpOffset );
1081  m_cPPS.setQpOffset(COMPONENT_Cr, m_chromaCrQpOffset );
1082
1083  m_cPPS.setEntropyCodingSyncEnabledFlag( m_iWaveFrontSynchro > 0 );
1084  m_cPPS.setTilesEnabledFlag( (m_iNumColumnsMinus1 > 0 || m_iNumRowsMinus1 > 0) );
1085  m_cPPS.setUseWP( m_useWeightedPred );
1086  m_cPPS.setWPBiPred( m_useWeightedBiPred );
1087  m_cPPS.setUseCrossComponentPrediction(m_useCrossComponentPrediction);
1088  m_cPPS.setSaoOffsetBitShift(CHANNEL_TYPE_LUMA,   m_saoOffsetBitShift[CHANNEL_TYPE_LUMA  ]);
1089  m_cPPS.setSaoOffsetBitShift(CHANNEL_TYPE_CHROMA, m_saoOffsetBitShift[CHANNEL_TYPE_CHROMA]);
1090  m_cPPS.setOutputFlagPresentFlag( false );
1091  m_cPPS.setSignHideFlag(getSignHideFlag());
1092  if ( getDeblockingFilterMetric() )
1093  {
1094    m_cPPS.setDeblockingFilterControlPresentFlag (true);
1095    m_cPPS.setDeblockingFilterOverrideEnabledFlag(true);
1096    m_cPPS.setPicDisableDeblockingFilterFlag(false);
1097    m_cPPS.setDeblockingFilterBetaOffsetDiv2(0);
1098    m_cPPS.setDeblockingFilterTcOffsetDiv2(0);
1099  }
1100  else
1101  {
1102    m_cPPS.setDeblockingFilterControlPresentFlag (m_DeblockingFilterControlPresent );
1103
1104    if (m_cPPS.getDeblockingFilterControlPresentFlag())
1105    {
1106      m_cPPS.setDeblockingFilterOverrideEnabledFlag( !getLoopFilterOffsetInPPS() );
1107      m_cPPS.setPicDisableDeblockingFilterFlag( getLoopFilterDisable() );
1108    }
1109  }
1110
1111  if (m_cPPS.getDeblockingFilterControlPresentFlag() && ! m_cPPS.getPicDisableDeblockingFilterFlag())
1112  {
1113    m_cPPS.setDeblockingFilterBetaOffsetDiv2( getLoopFilterBetaOffset() );
1114    m_cPPS.setDeblockingFilterTcOffsetDiv2( getLoopFilterTcOffset() );
1115  }
1116  m_cPPS.setLog2ParallelMergeLevelMinus2   (m_log2ParallelMergeLevelMinus2 );
1117  m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG);
1118  m_cPPS.setLoopFilterAcrossSlicesEnabledFlag( m_bLFCrossSliceBoundaryFlag );
1119
1120
1121  Int histogram[MAX_NUM_REF + 1];
1122  for( Int i = 0; i <= MAX_NUM_REF; i++ )
1123  {
1124    histogram[i]=0;
1125  }
1126  for( Int i = 0; i < getGOPSize(); i++)
1127  {
1128    assert(getGOPEntry(i).m_numRefPicsActive >= 0 && getGOPEntry(i).m_numRefPicsActive <= MAX_NUM_REF);
1129    histogram[getGOPEntry(i).m_numRefPicsActive]++;
1130  }
1131
1132  Int maxHist=-1;
1133  Int bestPos=0;
1134  for( Int i = 0; i <= MAX_NUM_REF; i++ )
1135  {
1136    if(histogram[i]>maxHist)
1137    {
1138      maxHist=histogram[i];
1139      bestPos=i;
1140    }
1141  }
1142  assert(bestPos <= 15);
1143  m_cPPS.setNumRefIdxL0DefaultActive(bestPos);
1144  m_cPPS.setNumRefIdxL1DefaultActive(bestPos);
1145  m_cPPS.setTransquantBypassEnableFlag(getTransquantBypassEnableFlag());
1146  m_cPPS.setUseTransformSkip( m_useTransformSkip );
1147  m_cPPS.setTransformSkipLog2MaxSize( m_transformSkipLog2MaxSize  );
1148
1149  if (m_sliceSegmentMode != NO_SLICES)
1150  {
1151    m_cPPS.setDependentSliceSegmentsEnabledFlag( true );
1152  }
1153 
1154#if SVC_EXTENSION
1155  m_cPPS.setLayerId( m_layerId );
1156
1157  if( !m_numDirectRefLayers && m_numAddLayerSets )
1158  {
1159    m_cPPS.setLayerId(0); // layer ID 0 for independent layers
1160  }
1161
1162  if( m_layerId > 0 )
1163  {
1164    m_cPPS.setListsModificationPresentFlag(true);
1165    m_cPPS.setExtensionFlag(true);
1166  }
1167  else
1168  {
1169    m_cPPS.setListsModificationPresentFlag(false);
1170    m_cPPS.setExtensionFlag(false);
1171  }
1172
1173  m_cPPS.setPPSId( m_iPPSIdCnt );
1174  m_cPPS.setSPSId( m_iSPSIdCnt );
1175
1176  if( m_crossLayerBLAFlag )
1177  {
1178    m_cPPS.setNumExtraSliceHeaderBits( 3 );
1179  }
1180
1181  m_cPPS.setNumRefLayerLocationOffsets(m_numRefLayerLocationOffsets);
1182  for(Int i = 0; i < m_cPPS.getNumRefLayerLocationOffsets(); i++)
1183  {
1184    m_cPPS.setRefLocationOffsetLayerId(i, m_refLocationOffsetLayerId[i]);
1185    m_cPPS.getScaledRefLayerWindow(i) = m_scaledRefLayerWindow[i];
1186    m_cPPS.getRefLayerWindow(i) = m_refLayerWindow[i];
1187    m_cPPS.setScaledRefLayerOffsetPresentFlag( i, m_scaledRefLayerOffsetPresentFlag[i] );
1188    m_cPPS.setRefRegionOffsetPresentFlag( i, m_refRegionOffsetPresentFlag[i] );
1189    m_cPPS.setResamplePhaseSetPresentFlag( i, m_resamplePhaseSetPresentFlag[i] );
1190    m_cPPS.setPhaseHorLuma( m_refLocationOffsetLayerId[i], m_phaseHorLuma[i] );
1191    m_cPPS.setPhaseVerLuma( m_refLocationOffsetLayerId[i], m_phaseVerLuma[i] );
1192    m_cPPS.setPhaseHorChroma( m_refLocationOffsetLayerId[i], m_phaseHorChroma[i] );
1193    m_cPPS.setPhaseVerChroma( m_refLocationOffsetLayerId[i], m_phaseVerChroma[i] );
1194  }
1195#if CGS_3D_ASYMLUT
1196  m_cPPS.setCGSFlag( m_nCGSFlag );
1197#endif
1198  m_cPPS.setPocResetInfoPresentFlag( true );
1199  m_cPPS.setExtensionFlag( true );
1200  m_cPPS.setSliceHeaderExtensionPresentFlag( true );
1201#endif //SVC_EXTENSION
1202}
1203
1204//Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file.
1205Void TEncTop::xInitRPS(Bool isFieldCoding)
1206{
1207  TComReferencePictureSet*      rps;
1208
1209  m_cSPS.createRPSList(getGOPSize() + m_extraRPSs + 1);
1210  TComRPSList* rpsList = m_cSPS.getRPSList();
1211
1212  for( Int i = 0; i < getGOPSize()+m_extraRPSs; i++)
1213  {
1214    GOPEntry ge = getGOPEntry(i);
1215    rps = rpsList->getReferencePictureSet(i);
1216    rps->setNumberOfPictures(ge.m_numRefPics);
1217    rps->setNumRefIdc(ge.m_numRefIdc);
1218    Int numNeg = 0;
1219    Int numPos = 0;
1220    for( Int j = 0; j < ge.m_numRefPics; j++)
1221    {
1222      rps->setDeltaPOC(j,ge.m_referencePics[j]);
1223      rps->setUsed(j,ge.m_usedByCurrPic[j]);
1224      if(ge.m_referencePics[j]>0)
1225      {
1226        numPos++;
1227      }
1228      else
1229      {
1230        numNeg++;
1231      }
1232    }
1233    rps->setNumberOfNegativePictures(numNeg);
1234    rps->setNumberOfPositivePictures(numPos);
1235
1236    // handle inter RPS intialization from the config file.
1237    rps->setInterRPSPrediction(ge.m_interRPSPrediction > 0);  // not very clean, converting anything > 0 to true.
1238    rps->setDeltaRIdxMinus1(0);                               // index to the Reference RPS is always the previous one.
1239    TComReferencePictureSet*     RPSRef = i>0 ? rpsList->getReferencePictureSet(i-1): NULL;  // get the reference RPS
1240
1241    if (ge.m_interRPSPrediction == 2)  // Automatic generation of the inter RPS idc based on the RIdx provided.
1242    {
1243      assert (RPSRef!=NULL);
1244      Int deltaRPS = getGOPEntry(i-1).m_POC - ge.m_POC;  // the ref POC - current POC
1245      Int numRefDeltaPOC = RPSRef->getNumberOfPictures();
1246
1247      rps->setDeltaRPS(deltaRPS);           // set delta RPS
1248      rps->setNumRefIdc(numRefDeltaPOC+1);  // set the numRefIdc to the number of pictures in the reference RPS + 1.
1249      Int count=0;
1250      for (Int j = 0; j <= numRefDeltaPOC; j++ ) // cycle through pics in reference RPS.
1251      {
1252        Int RefDeltaPOC = (j<numRefDeltaPOC)? RPSRef->getDeltaPOC(j): 0;  // if it is the last decoded picture, set RefDeltaPOC = 0
1253        rps->setRefIdc(j, 0);
1254        for (Int k = 0; k < rps->getNumberOfPictures(); k++ )  // cycle through pics in current RPS.
1255        {
1256          if (rps->getDeltaPOC(k) == ( RefDeltaPOC + deltaRPS))  // if the current RPS has a same picture as the reference RPS.
1257          {
1258              rps->setRefIdc(j, (rps->getUsed(k)?1:2));
1259              count++;
1260              break;
1261          }
1262        }
1263      }
1264      if (count != rps->getNumberOfPictures())
1265      {
1266        printf("Warning: Unable fully predict all delta POCs using the reference RPS index given in the config file.  Setting Inter RPS to false for this RPS.\n");
1267        rps->setInterRPSPrediction(0);
1268      }
1269    }
1270    else if (ge.m_interRPSPrediction == 1)  // inter RPS idc based on the RefIdc values provided in config file.
1271    {
1272      assert (RPSRef!=NULL);
1273      rps->setDeltaRPS(ge.m_deltaRPS);
1274      rps->setNumRefIdc(ge.m_numRefIdc);
1275      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1276      {
1277        rps->setRefIdc(j, ge.m_refIdc[j]);
1278      }
1279#if WRITE_BACK
1280      // the following code overwrite the deltaPOC and Used by current values read from the config file with the ones
1281      // computed from the RefIdc.  A warning is printed if they are not identical.
1282      numNeg = 0;
1283      numPos = 0;
1284      TComReferencePictureSet      RPSTemp;  // temporary variable
1285
1286      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1287      {
1288        if (ge.m_refIdc[j])
1289        {
1290          Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0);
1291          RPSTemp.setDeltaPOC((numNeg+numPos),deltaPOC);
1292          RPSTemp.setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0);
1293          if (deltaPOC<0)
1294          {
1295            numNeg++;
1296          }
1297          else
1298          {
1299            numPos++;
1300          }
1301        }
1302      }
1303      if (numNeg != rps->getNumberOfNegativePictures())
1304      {
1305        printf("Warning: number of negative pictures in RPS is different between intra and inter RPS specified in the config file.\n");
1306        rps->setNumberOfNegativePictures(numNeg);
1307        rps->setNumberOfPictures(numNeg+numPos);
1308      }
1309      if (numPos != rps->getNumberOfPositivePictures())
1310      {
1311        printf("Warning: number of positive pictures in RPS is different between intra and inter RPS specified in the config file.\n");
1312        rps->setNumberOfPositivePictures(numPos);
1313        rps->setNumberOfPictures(numNeg+numPos);
1314      }
1315      RPSTemp.setNumberOfPictures(numNeg+numPos);
1316      RPSTemp.setNumberOfNegativePictures(numNeg);
1317      RPSTemp.sortDeltaPOC();     // sort the created delta POC before comparing
1318      // check if Delta POC and Used are the same
1319      // print warning if they are not.
1320      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1321      {
1322        if (RPSTemp.getDeltaPOC(j) != rps->getDeltaPOC(j))
1323        {
1324          printf("Warning: delta POC is different between intra RPS and inter RPS specified in the config file.\n");
1325          rps->setDeltaPOC(j,RPSTemp.getDeltaPOC(j));
1326        }
1327        if (RPSTemp.getUsed(j) != rps->getUsed(j))
1328        {
1329          printf("Warning: Used by Current in RPS is different between intra and inter RPS specified in the config file.\n");
1330          rps->setUsed(j,RPSTemp.getUsed(j));
1331        }
1332      }
1333#endif
1334    }
1335  }
1336  //In case of field coding, we need to set special parameters for the first bottom field of the sequence, since it is not specified in the cfg file.
1337  //The position = GOPSize + extraRPSs which is (a priori) unused is reserved for this field in the RPS.
1338  if (isFieldCoding)
1339  {
1340    rps = rpsList->getReferencePictureSet(getGOPSize()+m_extraRPSs);
1341    rps->setNumberOfPictures(1);
1342    rps->setNumberOfNegativePictures(1);
1343    rps->setNumberOfPositivePictures(0);
1344    rps->setNumberOfLongtermPictures(0);
1345    rps->setDeltaPOC(0,-1);
1346    rps->setPOC(0,0);
1347    rps->setUsed(0,true);
1348    rps->setInterRPSPrediction(false);
1349    rps->setDeltaRIdxMinus1(0);
1350    rps->setDeltaRPS(0);
1351    rps->setNumRefIdc(0);
1352  }
1353}
1354
1355   // This is a function that
1356   // determines what Reference Picture Set to use
1357   // for a specific slice (with POC = POCCurr)
1358Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid )
1359{
1360  slice->setRPSidx(GOPid);
1361
1362  for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++)
1363  {
1364    if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0)
1365    {
1366      Int POCIndex = POCCurr%m_uiIntraPeriod;
1367      if(POCIndex == 0)
1368      {
1369        POCIndex = m_uiIntraPeriod;
1370      }
1371      if(POCIndex == m_GOPList[extraNum].m_POC)
1372      {
1373        slice->setRPSidx(extraNum);
1374      }
1375    }
1376    else
1377    {
1378      if(POCCurr==m_GOPList[extraNum].m_POC)
1379      {
1380        slice->setRPSidx(extraNum);
1381      }
1382    }
1383  }
1384
1385  if(POCCurr == 1 && slice->getPic()->isField())
1386  {
1387    slice->setRPSidx(m_iGOPSize+m_extraRPSs);
1388  }
1389
1390  TComReferencePictureSet *rps=slice->getLocalRPS();
1391  (*rps) = *(slice->getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx()));
1392  slice->setRPS(rps);
1393  slice->getRPS()->setNumberOfPictures(slice->getRPS()->getNumberOfNegativePictures()+slice->getRPS()->getNumberOfPositivePictures());
1394}
1395
1396Int TEncTop::getReferencePictureSetIdxForSOP(Int POCCurr, Int GOPid )
1397{
1398  Int rpsIdx = GOPid;
1399
1400  for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++)
1401  {
1402    if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0)
1403    {
1404      Int POCIndex = POCCurr%m_uiIntraPeriod;
1405      if(POCIndex == 0)
1406      {
1407        POCIndex = m_uiIntraPeriod;
1408      }
1409      if(POCIndex == m_GOPList[extraNum].m_POC)
1410      {
1411        rpsIdx = extraNum;
1412      }
1413    }
1414    else
1415    {
1416      if(POCCurr==m_GOPList[extraNum].m_POC)
1417      {
1418        rpsIdx = extraNum;
1419      }
1420    }
1421  }
1422
1423  return rpsIdx;
1424}
1425
1426Void  TEncTop::xInitPPSforTiles()
1427{
1428  m_cPPS.setTileUniformSpacingFlag( m_tileUniformSpacingFlag );
1429  m_cPPS.setNumTileColumnsMinus1( m_iNumColumnsMinus1 );
1430  m_cPPS.setNumTileRowsMinus1( m_iNumRowsMinus1 );
1431  if( !m_tileUniformSpacingFlag )
1432  {
1433    m_cPPS.setTileColumnWidth( m_tileColumnWidth );
1434    m_cPPS.setTileRowHeight( m_tileRowHeight );
1435  }
1436  m_cPPS.setLoopFilterAcrossTilesEnabledFlag( m_loopFilterAcrossTilesEnabledFlag );
1437
1438  // # substreams is "per tile" when tiles are independent.
1439}
1440
1441Void  TEncCfg::xCheckGSParameters()
1442{
1443  Int   iWidthInCU = ( m_iSourceWidth%m_maxCUWidth ) ? m_iSourceWidth/m_maxCUWidth + 1 : m_iSourceWidth/m_maxCUWidth;
1444  Int   iHeightInCU = ( m_iSourceHeight%m_maxCUHeight ) ? m_iSourceHeight/m_maxCUHeight + 1 : m_iSourceHeight/m_maxCUHeight;
1445  UInt  uiCummulativeColumnWidth = 0;
1446  UInt  uiCummulativeRowHeight = 0;
1447
1448  //check the column relative parameters
1449  if( m_iNumColumnsMinus1 >= (1<<(LOG2_MAX_NUM_COLUMNS_MINUS1+1)) )
1450  {
1451    printf( "The number of columns is larger than the maximum allowed number of columns.\n" );
1452    exit( EXIT_FAILURE );
1453  }
1454
1455  if( m_iNumColumnsMinus1 >= iWidthInCU )
1456  {
1457    printf( "The current picture can not have so many columns.\n" );
1458    exit( EXIT_FAILURE );
1459  }
1460
1461  if( m_iNumColumnsMinus1 && !m_tileUniformSpacingFlag )
1462  {
1463    for(Int i=0; i<m_iNumColumnsMinus1; i++)
1464    {
1465      uiCummulativeColumnWidth += m_tileColumnWidth[i];
1466    }
1467
1468    if( uiCummulativeColumnWidth >= iWidthInCU )
1469    {
1470      printf( "The width of the column is too large.\n" );
1471      exit( EXIT_FAILURE );
1472    }
1473  }
1474
1475  //check the row relative parameters
1476  if( m_iNumRowsMinus1 >= (1<<(LOG2_MAX_NUM_ROWS_MINUS1+1)) )
1477  {
1478    printf( "The number of rows is larger than the maximum allowed number of rows.\n" );
1479    exit( EXIT_FAILURE );
1480  }
1481
1482  if( m_iNumRowsMinus1 >= iHeightInCU )
1483  {
1484    printf( "The current picture can not have so many rows.\n" );
1485    exit( EXIT_FAILURE );
1486  }
1487
1488  if( m_iNumRowsMinus1 && !m_tileUniformSpacingFlag )
1489  {
1490    for(Int i=0; i<m_iNumRowsMinus1; i++)
1491    {
1492      uiCummulativeRowHeight += m_tileRowHeight[i];
1493    }
1494
1495    if( uiCummulativeRowHeight >= iHeightInCU )
1496    {
1497      printf( "The height of the row is too large.\n" );
1498      exit( EXIT_FAILURE );
1499    }
1500  }
1501}
1502
1503#if SVC_EXTENSION
1504TEncTop* TEncTop::getRefLayerEnc( UInt refLayerIdx )
1505{
1506  if( m_ppcTEncTop[m_cVPS.getLayerIdxInVps(m_layerId)]->getNumDirectRefLayers() <= 0 )
1507  {
1508    return (TEncTop *)getLayerEnc( 0 );
1509  }
1510
1511  return (TEncTop *)getLayerEnc( m_cVPS.getLayerIdxInVps(m_cVPS.getRefLayerId( m_layerId, refLayerIdx )) );
1512}
1513
1514Void TEncTop::xInitILRP()
1515{
1516  if( m_layerId > 0 )
1517  {
1518    if( m_cIlpPic[0] == NULL )
1519    {
1520      for (Int j=0; j < m_numDirectRefLayers; j++)
1521      {
1522        m_cIlpPic[j] = new TComPic;
1523        m_cIlpPic[j]->create(m_cVPS, m_cSPS, m_cPPS, true, m_layerId);
1524        for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCtusInFrame(); i++)
1525        {
1526          m_cIlpPic[j]->getPicSym()->getCtu(i)->initCtu(m_cIlpPic[j], i);
1527        }
1528      }
1529    }
1530
1531    if( m_cVPS.getNumRefLayers( m_layerId ) == 0 )
1532    {
1533      UInt layerIdx = m_cVPS.getLayerIdxInVps( m_layerId );
1534      RepFormat* repFmt = m_cVPS.getVpsRepFormat(m_cVPS.getVpsRepFormatIdx(layerIdx));
1535     
1536      if( m_cPPS.getLayerId() == 0 && 
1537          m_cSPS.getLayerId() == 0 &&
1538          repFmt->getChromaFormatVpsIdc() == m_cSPS.getChromaFormatIdc() &&
1539          repFmt->getSeparateColourPlaneVpsFlag() == 0 &&
1540          repFmt->getPicHeightVpsInLumaSamples() == m_cSPS.getPicHeightInLumaSamples() &&
1541          repFmt->getPicWidthVpsInLumaSamples()  == m_cSPS.getPicWidthInLumaSamples() &&
1542          repFmt->getBitDepthVpsLuma()   == m_cSPS.getBitDepth(CHANNEL_TYPE_LUMA) &&
1543          repFmt->getBitDepthVpsChroma() == m_cSPS.getBitDepth(CHANNEL_TYPE_CHROMA) &&
1544          repFmt->getConformanceWindowVps().getWindowLeftOffset()   == m_cSPS.getConformanceWindow().getWindowLeftOffset() &&
1545          repFmt->getConformanceWindowVps().getWindowRightOffset()  == m_cSPS.getConformanceWindow().getWindowRightOffset() &&
1546          repFmt->getConformanceWindowVps().getWindowTopOffset()    == m_cSPS.getConformanceWindow().getWindowTopOffset() &&
1547          repFmt->getConformanceWindowVps().getWindowBottomOffset() == m_cSPS.getConformanceWindow().getWindowBottomOffset() )
1548      {
1549        m_cVPS.setBaseLayerPSCompatibilityFlag(layerIdx, 1);
1550      }
1551      else
1552      {
1553        m_cVPS.setBaseLayerPSCompatibilityFlag(layerIdx, 0);
1554      }
1555    }
1556  }
1557}
1558
1559Window TEncTop::getScaledRefLayerWindowForLayer(Int layerId)
1560{
1561  for (Int i = 0; i < m_numRefLayerLocationOffsets; i++)
1562  {
1563    if (layerId == m_refLocationOffsetLayerId[i])
1564    {
1565      return m_scaledRefLayerWindow[i];
1566    }
1567  }
1568
1569  return Window();
1570}
1571
1572Window TEncTop::getRefLayerWindowForLayer(Int layerId)
1573{
1574  for (Int i = 0; i < m_numRefLayerLocationOffsets; i++)
1575  {
1576    if (layerId == m_refLayerId[i])
1577    {
1578      return m_refLayerWindow[i];
1579    }
1580  }
1581
1582  return Window();
1583}
1584#endif //SVC_EXTENSION
1585//! \}
Note: See TracBrowser for help on using the repository browser.