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

Last change on this file since 1263 was 1260, checked in by seregin, 9 years ago

port rev 4257

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