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

Last change on this file since 1303 was 1298, checked in by seregin, 10 years ago

port rev 4334

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