source: 3DVCSoftware/branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncTop.cpp @ 637

Last change on this file since 637 was 637, checked in by kwu-htm, 12 years ago

Clean up and revised according to the guideline.

  • Property svn:eol-style set to native
File size: 42.3 KB
RevLine 
[5]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
[56]4 * granted under this license. 
[5]5 *
[608]6 * Copyright (c) 2010-2013, ITU/ISO/IEC
[5]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.
[56]17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
[5]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 */
[2]33
34/** \file     TEncTop.cpp
35    \brief    encoder class
36*/
37
[56]38#include "TLibCommon/CommonDef.h"
[2]39#include "TEncTop.h"
[56]40#include "TEncPic.h"
41#if FAST_BIT_EST
42#include "TLibCommon/ContextModel.h"
43#endif
[608]44#if H_MV
45#include "../../App/TAppEncoder/TAppEncTop.h"
46#endif
[2]47
[56]48//! \ingroup TLibEncoder
49//! \{
50
[2]51// ====================================================================================================================
52// Constructor / destructor / create / destroy
53// ====================================================================================================================
54
55TEncTop::TEncTop()
56{
57  m_iPOCLast          = -1;
58  m_iNumPicRcvd       =  0;
59  m_uiNumAllPicCoded  =  0;
60  m_pppcRDSbacCoder   =  NULL;
61  m_pppcBinCoderCABAC =  NULL;
62  m_cRDGoOnSbacCoder.init( &m_cRDGoOnBinCoderCABAC );
63#if ENC_DEC_TRACE
64  g_hTrace = fopen( "TraceEnc.txt", "wb" );
65  g_bJustDoIt = g_bEncDecTraceDisable;
66  g_nSymbolCounter = 0;
67#endif
[56]68
69  m_iMaxRefPicNum     = 0;
70
71#if FAST_BIT_EST
72  ContextModel::buildNextStateTable();
73#endif
74
75  m_pcSbacCoders           = NULL;
76  m_pcBinCoderCABACs       = NULL;
77  m_ppppcRDSbacCoders      = NULL;
78  m_ppppcBinCodersCABAC    = NULL;
79  m_pcRDGoOnSbacCoders     = NULL;
80  m_pcRDGoOnBinCodersCABAC = NULL;
81  m_pcBitCounters          = NULL;
82  m_pcRdCosts              = NULL;
[608]83#if H_MV
84  m_ivPicLists = NULL;
85#endif
[2]86}
87
88TEncTop::~TEncTop()
89{
90#if ENC_DEC_TRACE
91  fclose( g_hTrace );
92#endif
93}
94
95Void TEncTop::create ()
96{
[608]97#if !H_MV
[2]98  // initialize global variables
[608]99  initROM();
100#endif
101 
[2]102  // create processing unit classes
[608]103  m_cGOPEncoder.        create();
[2]104  m_cSliceEncoder.      create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
105  m_cCuEncoder.         create( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
106  if (m_bUseSAO)
107  {
[443]108    m_cEncSAO.setSaoLcuBoundary(getSaoLcuBoundary());
109    m_cEncSAO.setSaoLcuBasedOptimization(getSaoLcuBasedOptimization());
[56]110    m_cEncSAO.setMaxNumOffsetsPerPic(getMaxNumOffsetsPerPic());
[608]111    m_cEncSAO.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight );
[2]112    m_cEncSAO.createEncBuffer();
113  }
[56]114#if ADAPTIVE_QP_SELECTION
115  if (m_bUseAdaptQpSelect)
116  {
117    m_cTrQuant.initSliceQpDelta();
118  }
[2]119#endif
120  m_cLoopFilter.        create( g_uiMaxCUDepth );
121
[608]122#if RATE_CONTROL_LAMBDA_DOMAIN
123  if ( m_RCEnableRateControl )
[2]124  {
[635]125#if KWU_RC_MADPRED_E0227
[608]126    m_cRateCtrl.init( m_framesToBeEncoded, m_RCTargetBitrate, m_iFrameRate, m_iGOPSize, m_iSourceWidth, m_iSourceHeight,
[635]127      g_uiMaxCUWidth, g_uiMaxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList, getLayerId() );
128#else
129    m_cRateCtrl.init( m_framesToBeEncoded, m_RCTargetBitrate, m_iFrameRate, m_iGOPSize, m_iSourceWidth, m_iSourceHeight,
[608]130                      g_uiMaxCUWidth, g_uiMaxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList );
[635]131#endif
[2]132  }
[608]133#else
[637]134#if KWU_FIX_URQ
[635]135  if(m_enableRateCtrl)
[637]136#endif
[635]137    m_cRateCtrl.create(getIntraPeriod(), getGOPSize(), getFrameRate(), getTargetBitrate(), getQP(), getNumLCUInUnit(), getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight);
[608]138#endif
[2]139  // if SBAC-based RD optimization is used
140  if( m_bUseSBACRD )
141  {
[56]142    m_pppcRDSbacCoder = new TEncSbac** [g_uiMaxCUDepth+1];
143#if FAST_BIT_EST
144    m_pppcBinCoderCABAC = new TEncBinCABACCounter** [g_uiMaxCUDepth+1];
145#else
146    m_pppcBinCoderCABAC = new TEncBinCABAC** [g_uiMaxCUDepth+1];
147#endif
148   
149    for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
[2]150    {
151      m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM];
[56]152#if FAST_BIT_EST
153      m_pppcBinCoderCABAC[iDepth] = new TEncBinCABACCounter* [CI_NUM];
154#else
[2]155      m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM];
[56]156#endif
157     
[2]158      for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
159      {
160        m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac;
[56]161#if FAST_BIT_EST
162        m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABACCounter;
163#else
[2]164        m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC;
[56]165#endif
[2]166        m_pppcRDSbacCoder   [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] );
167      }
168    }
169  }
170}
171
[56]172/**
173 - Allocate coders required for wavefront for the nominated number of substreams.
174 .
175 \param iNumSubstreams Determines how much information to allocate.
176 */
177Void TEncTop::createWPPCoders(Int iNumSubstreams)
178{
179  if (m_pcSbacCoders != NULL)
[608]180  {
[56]181    return; // already generated.
[608]182  }
[56]183
184  m_iNumSubstreams         = iNumSubstreams;
185  m_pcSbacCoders           = new TEncSbac       [iNumSubstreams];
186  m_pcBinCoderCABACs       = new TEncBinCABAC   [iNumSubstreams];
187  m_pcRDGoOnSbacCoders     = new TEncSbac       [iNumSubstreams];
188  m_pcRDGoOnBinCodersCABAC = new TEncBinCABAC   [iNumSubstreams];
189  m_pcBitCounters          = new TComBitCounter [iNumSubstreams];
190  m_pcRdCosts              = new TComRdCost     [iNumSubstreams];
191
192  for ( UInt ui = 0 ; ui < iNumSubstreams; ui++ )
193  {
194    m_pcRDGoOnSbacCoders[ui].init( &m_pcRDGoOnBinCodersCABAC[ui] );
195    m_pcSbacCoders[ui].init( &m_pcBinCoderCABACs[ui] );
196  }
197  if( m_bUseSBACRD )
198  {
199    m_ppppcRDSbacCoders      = new TEncSbac***    [iNumSubstreams];
200    m_ppppcBinCodersCABAC    = new TEncBinCABAC***[iNumSubstreams];
201    for ( UInt ui = 0 ; ui < iNumSubstreams ; ui++ )
202    {
203      m_ppppcRDSbacCoders[ui]  = new TEncSbac** [g_uiMaxCUDepth+1];
204      m_ppppcBinCodersCABAC[ui]= new TEncBinCABAC** [g_uiMaxCUDepth+1];
205     
206      for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
207      {
208        m_ppppcRDSbacCoders[ui][iDepth]  = new TEncSbac*     [CI_NUM];
209        m_ppppcBinCodersCABAC[ui][iDepth]= new TEncBinCABAC* [CI_NUM];
210
211        for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
212        {
213          m_ppppcRDSbacCoders  [ui][iDepth][iCIIdx] = new TEncSbac;
214          m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx] = new TEncBinCABAC;
215          m_ppppcRDSbacCoders  [ui][iDepth][iCIIdx]->init( m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx] );
216        }
217      }
218    }
219  }
220}
221
[2]222Void TEncTop::destroy ()
223{
224  // destroy processing unit classes
[56]225  m_cGOPEncoder.        destroy();
[2]226  m_cSliceEncoder.      destroy();
227  m_cCuEncoder.         destroy();
228  if (m_cSPS.getUseSAO())
229  {
230    m_cEncSAO.destroy();
[56]231    m_cEncSAO.destroyEncBuffer();
[2]232  }
233  m_cLoopFilter.        destroy();
[637]234  m_cRateCtrl.          destroy();
[2]235  // SBAC RD
236  if( m_bUseSBACRD )
237  {
238    Int iDepth;
239    for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
240    {
241      for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
242      {
243        delete m_pppcRDSbacCoder[iDepth][iCIIdx];
244        delete m_pppcBinCoderCABAC[iDepth][iCIIdx];
245      }
246    }
[56]247   
[2]248    for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
249    {
250      delete [] m_pppcRDSbacCoder[iDepth];
251      delete [] m_pppcBinCoderCABAC[iDepth];
252    }
[56]253   
[2]254    delete [] m_pppcRDSbacCoder;
255    delete [] m_pppcBinCoderCABAC;
[56]256
257    for ( UInt ui = 0; ui < m_iNumSubstreams; ui++ )
258    {
259      for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
260      {
261        for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
262        {
263          delete m_ppppcRDSbacCoders  [ui][iDepth][iCIIdx];
264          delete m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx];
265        }
266      }
267
268      for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
269      {
270        delete [] m_ppppcRDSbacCoders  [ui][iDepth];
271        delete [] m_ppppcBinCodersCABAC[ui][iDepth];
272      }
273      delete[] m_ppppcRDSbacCoders  [ui];
274      delete[] m_ppppcBinCodersCABAC[ui];
275    }
276    delete[] m_ppppcRDSbacCoders;
277    delete[] m_ppppcBinCodersCABAC;
[2]278  }
[56]279  delete[] m_pcSbacCoders;
280  delete[] m_pcBinCoderCABACs;
281  delete[] m_pcRDGoOnSbacCoders; 
282  delete[] m_pcRDGoOnBinCodersCABAC;
283  delete[] m_pcBitCounters;
284  delete[] m_pcRdCosts;
285 
[608]286#if !H_MV
287    // destroy ROM
[56]288  destroyROM();
[608]289#endif
290
[2]291  return;
292}
293
[635]294#if KWU_RC_MADPRED_E0227
295Void TEncTop::init(TAppEncTop* pcTAppEncTop)
296#else
[608]297Void TEncTop::init()
[635]298#endif
[2]299{
300  // initialize SPS
301  xInitSPS();
[56]302 
[608]303  /* set the VPS profile information */
304#if H_MV
305  // This seems to be incorrect, but irrelevant for the MV-HEVC
306  *(m_cVPS->getPTL()) = *m_cSPS.getPTL();
307  m_cVPS->getTimingInfo()->setTimingInfoPresentFlag       ( false );
308#else
309  *m_cVPS.getPTL() = *m_cSPS.getPTL();
310  m_cVPS.getTimingInfo()->setTimingInfoPresentFlag       ( false );
311#endif
[2]312  // initialize PPS
[56]313  m_cPPS.setSPS(&m_cSPS);
[2]314  xInitPPS();
[56]315  xInitRPS();
[2]316
[56]317  xInitPPSforTiles();
318
[2]319  // initialize processing unit classes
[56]320  m_cGOPEncoder.  init( this );
[2]321  m_cSliceEncoder.init( this );
322  m_cCuEncoder.   init( this );
[56]323 
[635]324#if KWU_RC_MADPRED_E0227
325  m_pcTAppEncTop = pcTAppEncTop;
326#endif
[2]327  // initialize transform & quantization class
328  m_pcCavlcCoder = getCavlcCoder();
[56]329 
[608]330  m_cTrQuant.init( 1 << m_uiQuadtreeTULog2MaxSize,
331                  m_useRDOQ, 
332                  m_useRDOQTS,
333                  true 
334                  ,m_useTransformSkipFast
[56]335#if ADAPTIVE_QP_SELECTION                 
336                  , m_bUseAdaptQpSelect
[2]337#endif
[56]338                  );
339 
[2]340  // initialize encoder search class
341  m_cSearch.init( this, &m_cTrQuant, m_iSearchRange, m_bipredSearchRange, m_iFastSearch, 0, &m_cEntropyCoder, &m_cRdCost, getRDSbacCoder(), getRDGoOnSbacCoder() );
[56]342
343  m_iMaxRefPicNum = 0;
[2]344}
345
346// ====================================================================================================================
347// Public member functions
348// ====================================================================================================================
349
[608]350#if H_MV
351Void TEncTop::initNewPic( TComPicYuv* pcPicYuvOrg )
[56]352{
353  TComPic* pcPicCurr = NULL;
354
355  // get original YUV
356  xGetNewPicBuffer( pcPicCurr );
357  pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() );
358
359  // compute image characteristics
360  if ( getUseAdaptiveQP() )
361  {
362    m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) );
363  }
[608]364#if H_MV
365  pcPicCurr->setLayerId( getLayerId()); 
366#endif
367#if H_3D
368  pcPicCurr->setScaleOffset( m_aaiCodedScale, m_aaiCodedOffset );
369#endif
[56]370}
[608]371#endif
[2]372Void TEncTop::deletePicBuffer()
373{
374  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
375  Int iSize = Int( m_cListPic.size() );
[56]376 
[2]377  for ( Int i = 0; i < iSize; i++ )
378  {
379    TComPic* pcPic = *(iterPic++);
[56]380   
[2]381    pcPic->destroy();
382    delete pcPic;
383    pcPic = NULL;
384  }
385}
386
387/**
388 - Application has picture buffer list with size of GOP + 1
389 - Picture buffer list acts like as ring buffer
390 - End of the list has the latest picture
391 .
[608]392 \param   flush               cause encoder to encode a partial GOP
[2]393 \param   pcPicYuvOrg         original YUV picture
394 \retval  rcListPicYuvRecOut  list of reconstruction YUV pictures
395 \retval  rcListBitstreamOut  list of output bitstreams
396 \retval  iNumEncoded         number of encoded pictures
397 */
[608]398#if H_MV
399Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded , Int gopId )
400{
401#else
402Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded )
403{
404#endif
405#if H_3D
406  TComPic* picLastCoded = getPic( getGOPEncoder()->getPocLastCoded() );
407  if( picLastCoded )
408  {
409#if MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170
410    picLastCoded->compressMotion(1); 
411#else
412    picLastCoded->compressMotion(); 
413#endif
414  }
415#endif
416#if H_MV
[56]417  if( gopId == 0)
[2]418  {
[56]419    m_cGOPEncoder.initGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut); 
[608]420#else
421  if (pcPicYuvOrg) {
422    // get original YUV
423    TComPic* pcPicCurr = NULL;
424    xGetNewPicBuffer( pcPicCurr );
425    pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() );
426
427    // compute image characteristics
428    if ( getUseAdaptiveQP() )
429    {
430      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) );
431    }
[2]432  }
[608]433 
434  if (!m_iNumPicRcvd || (!flush && m_iPOCLast != 0 && m_iNumPicRcvd != m_iGOPSize && m_iGOPSize))
[2]435  {
[608]436    iNumEncoded = 0;
437    return;
[2]438  }
[608]439#endif
[56]440 
[608]441#if RATE_CONTROL_LAMBDA_DOMAIN
442  if ( m_RCEnableRateControl )
[2]443  {
[608]444    m_cRateCtrl.initRCGOP( m_iNumPicRcvd );
[2]445  }
[608]446#endif
[2]447
[608]448#if H_MV
449  }
450  m_cGOPEncoder.compressPicInGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, gopId );
[2]451
[608]452  if( gopId + 1 == m_cGOPEncoder.getGOPSize() )
[2]453  {
[608]454#else
455  // compress GOP
456  m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut);
[5]457#endif
[2]458
[608]459#if RATE_CONTROL_LAMBDA_DOMAIN
460  if ( m_RCEnableRateControl )
[2]461  {
[608]462    m_cRateCtrl.destroyRCGOP();
[2]463  }
[608]464#endif
465 
466  iNumEncoded         = m_iNumPicRcvd;
467  m_iNumPicRcvd       = 0;
468  m_uiNumAllPicCoded += iNumEncoded;
469#if H_MV
[2]470}
[608]471#endif
472}
[2]473
474// ====================================================================================================================
475// Protected member functions
476// ====================================================================================================================
477
478/**
479 - Application has picture buffer list with size of GOP + 1
480 - Picture buffer list acts like as ring buffer
481 - End of the list has the latest picture
482 .
483 \retval rpcPic obtained picture buffer
484 */
485Void TEncTop::xGetNewPicBuffer ( TComPic*& rpcPic )
486{
487  TComSlice::sortPicList(m_cListPic);
[56]488 
489  if (m_cListPic.size() >= (UInt)(m_iGOPSize + getMaxDecPicBuffering(MAX_TLAYER-1) + 2) )
[2]490  {
[56]491    TComList<TComPic*>::iterator iterPic  = m_cListPic.begin();
492    Int iSize = Int( m_cListPic.size() );
493    for ( Int i = 0; i < iSize; i++ )
494    {
[608]495      rpcPic = *(iterPic++);
[56]496      if(rpcPic->getSlice(0)->isReferenced() == false)
[608]497      {
498        break;
499      }
[56]500    }
[2]501  }
502  else
503  {
[608]504    if ( getUseAdaptiveQP() )
505    {
506      TEncPic* pcEPic = new TEncPic;
507      pcEPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 ,
508                      m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics);
509      rpcPic = pcEPic;
510    }
511    else
512    {
513      rpcPic = new TComPic;
514
515      rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
516                      m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics);
517    }
518    if (getUseSAO())
519    {
520      rpcPic->getPicSym()->allocSaoParam(&m_cEncSAO);
521    }
[56]522    m_cListPic.pushBack( rpcPic );
[2]523  }
524  rpcPic->setReconMark (false);
[56]525 
[2]526  m_iPOCLast++;
527  m_iNumPicRcvd++;
[56]528 
[2]529  rpcPic->getSlice(0)->setPOC( m_iPOCLast );
530  // mark it should be extended
531  rpcPic->getPicYuvRec()->setBorderExtension(false);
[622]532
533#if H_MV
[608]534  rpcPic->getPicYuvOrg()->setBorderExtension(false);
[622]535#endif
[2]536}
537
538Void TEncTop::xInitSPS()
539{
[608]540#if H_MV
541  m_cSPS.setSPSId( getLayerIdInVps() );
542  m_cSPS.setLayerId( getLayerId() );
543#endif
544  ProfileTierLevel& profileTierLevel = *m_cSPS.getPTL()->getGeneralPTL();
545  profileTierLevel.setLevelIdc(m_level);
546  profileTierLevel.setTierFlag(m_levelTier);
547  profileTierLevel.setProfileIdc(m_profile);
548  profileTierLevel.setProfileCompatibilityFlag(m_profile, 1);
549  profileTierLevel.setProgressiveSourceFlag(m_progressiveSourceFlag);
550  profileTierLevel.setInterlacedSourceFlag(m_interlacedSourceFlag);
551  profileTierLevel.setNonPackedConstraintFlag(m_nonPackedConstraintFlag);
552  profileTierLevel.setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag);
553 
554  if (m_profile == Profile::MAIN10 && g_bitDepthY == 8 && g_bitDepthC == 8)
555  {
556    /* The above constraint is equal to Profile::MAIN */
557    profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN, 1);
558  }
559  if (m_profile == Profile::MAIN)
560  {
561    /* A Profile::MAIN10 decoder can always decode Profile::MAIN */
562    profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN10, 1);
563  }
564  /* XXX: should Main be marked as compatible with still picture? */
565  /* XXX: may be a good idea to refactor the above into a function
566   * that chooses the actual compatibility based upon options */
567
[622]568#if H_MV5
569#if H_MV 
570  m_cSPS.setUpdateRepFormatFlag           ( m_layerId == 0 );   
571  m_cSPS.setSpsInferScalingListFlag       ( m_layerId > 0 && m_cVPS->getInDirectDependencyFlag( getLayerIdInVps(), 0 ) ); 
572  m_cSPS.setSpsScalingListRefLayerId      ( 0              ); 
573#endif
574#endif
[56]575  m_cSPS.setPicWidthInLumaSamples         ( m_iSourceWidth      );
576  m_cSPS.setPicHeightInLumaSamples        ( m_iSourceHeight     );
[608]577  m_cSPS.setConformanceWindow             ( m_conformanceWindow );
[2]578  m_cSPS.setMaxCUWidth    ( g_uiMaxCUWidth      );
579  m_cSPS.setMaxCUHeight   ( g_uiMaxCUHeight     );
580  m_cSPS.setMaxCUDepth    ( g_uiMaxCUDepth      );
[608]581
582  Int minCUSize = m_cSPS.getMaxCUWidth() >> ( m_cSPS.getMaxCUDepth()-g_uiAddCUDepth );
583  Int log2MinCUSize = 0;
584  while(minCUSize > 1)
585  {
586    minCUSize >>= 1;
587    log2MinCUSize++;
588  }
589
590  m_cSPS.setLog2MinCodingBlockSize(log2MinCUSize);
591  m_cSPS.setLog2DiffMaxMinCodingBlockSize(m_cSPS.getMaxCUDepth()-g_uiAddCUDepth);
[56]592 
593  m_cSPS.setPCMLog2MinSize (m_uiPCMLog2MinSize);
594  m_cSPS.setUsePCM        ( m_usePCM           );
595  m_cSPS.setPCMLog2MaxSize( m_pcmLog2MaxSize  );
[2]596
597  m_cSPS.setQuadtreeTULog2MaxSize( m_uiQuadtreeTULog2MaxSize );
598  m_cSPS.setQuadtreeTULog2MinSize( m_uiQuadtreeTULog2MinSize );
599  m_cSPS.setQuadtreeTUMaxDepthInter( m_uiQuadtreeTUMaxDepthInter    );
600  m_cSPS.setQuadtreeTUMaxDepthIntra( m_uiQuadtreeTUMaxDepthIntra    );
[56]601 
[608]602  m_cSPS.setTMVPFlagsPresent(false);
[56]603  m_cSPS.setUseLossless   ( m_useLossless  );
[608]604
[56]605  m_cSPS.setMaxTrSize   ( 1 << m_uiQuadtreeTULog2MaxSize );
606 
607  Int i;
608 
[608]609  for (i = 0; i < g_uiMaxCUDepth-g_uiAddCUDepth; i++ )
[56]610  {
611    m_cSPS.setAMPAcc( i, m_useAMP );
612    //m_cSPS.setAMPAcc( i, 1 );
613  }
[2]614
[56]615  m_cSPS.setUseAMP ( m_useAMP );
[2]616
[608]617#if H_3D_QTLPC
618  m_cSPS.setUseQTL( m_bUseQTL );
619  m_cSPS.setUsePC ( m_bUsePC  );
620#endif
621
622  for (i = g_uiMaxCUDepth-g_uiAddCUDepth; i < g_uiMaxCUDepth; i++ )
[56]623  {
624    m_cSPS.setAMPAcc(i, 0);
625  }
626
[608]627  m_cSPS.setBitDepthY( g_bitDepthY );
628  m_cSPS.setBitDepthC( g_bitDepthC );
[2]629
[608]630  m_cSPS.setQpBDOffsetY ( 6*(g_bitDepthY - 8) );
631  m_cSPS.setQpBDOffsetC ( 6*(g_bitDepthC - 8) );
632
[56]633  m_cSPS.setUseSAO( m_bUseSAO );
[2]634
[56]635  m_cSPS.setMaxTLayers( m_maxTempLayer );
[608]636  m_cSPS.setTemporalIdNestingFlag( ( m_maxTempLayer == 1 ) ? true : false );
[56]637  for ( i = 0; i < m_cSPS.getMaxTLayers(); i++ )
638  {
639    m_cSPS.setMaxDecPicBuffering(m_maxDecPicBuffering[i], i);
640    m_cSPS.setNumReorderPics(m_numReorderPics[i], i);
641  }
642  m_cSPS.setPCMBitDepthLuma (g_uiPCMBitDepthLuma);
643  m_cSPS.setPCMBitDepthChroma (g_uiPCMBitDepthChroma);
644  m_cSPS.setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag );
[42]645
[56]646  m_cSPS.setScalingListFlag ( (m_useScalingListId == 0) ? 0 : 1 );
647
[608]648  m_cSPS.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing );
[210]649
[608]650  m_cSPS.setVuiParametersPresentFlag(getVuiParametersPresentFlag());
651  if (m_cSPS.getVuiParametersPresentFlag())
[56]652  {
[608]653    TComVUI* pcVUI = m_cSPS.getVuiParameters();
654    pcVUI->setAspectRatioInfoPresentFlag(getAspectRatioIdc() != -1);
655    pcVUI->setAspectRatioIdc(getAspectRatioIdc());
656    pcVUI->setSarWidth(getSarWidth());
657    pcVUI->setSarHeight(getSarHeight());
658    pcVUI->setOverscanInfoPresentFlag(getOverscanInfoPresentFlag());
659    pcVUI->setOverscanAppropriateFlag(getOverscanAppropriateFlag());
660    pcVUI->setVideoSignalTypePresentFlag(getVideoSignalTypePresentFlag());
661    pcVUI->setVideoFormat(getVideoFormat());
662    pcVUI->setVideoFullRangeFlag(getVideoFullRangeFlag());
663    pcVUI->setColourDescriptionPresentFlag(getColourDescriptionPresentFlag());
664    pcVUI->setColourPrimaries(getColourPrimaries());
665    pcVUI->setTransferCharacteristics(getTransferCharacteristics());
666    pcVUI->setMatrixCoefficients(getMatrixCoefficients());
667    pcVUI->setChromaLocInfoPresentFlag(getChromaLocInfoPresentFlag());
668    pcVUI->setChromaSampleLocTypeTopField(getChromaSampleLocTypeTopField());
669    pcVUI->setChromaSampleLocTypeBottomField(getChromaSampleLocTypeBottomField());
670    pcVUI->setNeutralChromaIndicationFlag(getNeutralChromaIndicationFlag());
671    pcVUI->setDefaultDisplayWindow(getDefaultDisplayWindow());
672    pcVUI->setFrameFieldInfoPresentFlag(getFrameFieldInfoPresentFlag());
673    pcVUI->setFieldSeqFlag(false);
674    pcVUI->setHrdParametersPresentFlag(false);
675    pcVUI->getTimingInfo()->setPocProportionalToTimingFlag(getPocProportionalToTimingFlag());
676    pcVUI->getTimingInfo()->setNumTicksPocDiffOneMinus1   (getNumTicksPocDiffOneMinus1()   );
677    pcVUI->setBitstreamRestrictionFlag(getBitstreamRestrictionFlag());
678    pcVUI->setTilesFixedStructureFlag(getTilesFixedStructureFlag());
679    pcVUI->setMotionVectorsOverPicBoundariesFlag(getMotionVectorsOverPicBoundariesFlag());
680    pcVUI->setMinSpatialSegmentationIdc(getMinSpatialSegmentationIdc());
681    pcVUI->setMaxBytesPerPicDenom(getMaxBytesPerPicDenom());
682    pcVUI->setMaxBitsPerMinCuDenom(getMaxBitsPerMinCuDenom());
683    pcVUI->setLog2MaxMvLengthHorizontal(getLog2MaxMvLengthHorizontal());
684    pcVUI->setLog2MaxMvLengthVertical(getLog2MaxMvLengthVertical());
[2]685  }
[608]686#if H_3D
687  if ( !m_isDepth )
[2]688  {
[608]689    m_cSPS.initCamParaSPS           ( m_viewIndex, m_uiCamParPrecision, m_bCamParInSliceHeader, m_aaiCodedScale, m_aaiCodedOffset );
690  }
[210]691#endif
[56]692}
[2]693
[56]694Void TEncTop::xInitPPS()
695{
[608]696#if H_MV
[622]697#if H_MV5
698  m_cPPS.setLayerId( getLayerId() );
699  if( getVPS()->getNumDirectRefLayers( getLayerId() ) > 0 )
700#else
[608]701  if( getVPS()->getNumDirectRefLayers( getLayerIdInVps() ) > 0 )
[622]702#endif
[608]703  {
704    m_cPPS.setListsModificationPresentFlag( true );
705  }
706  m_cPPS.setPPSId( getLayerIdInVps() );
707  m_cPPS.setSPSId( getLayerIdInVps() );
708#endif
[56]709  m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred );
710  Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false;
[2]711
[56]712  Int lowestQP = - m_cSPS.getQpBDOffsetY();
713
714  if(getUseLossless())
[2]715  {
[56]716    if ((getMaxCuDQPDepth() == 0) && (getMaxDeltaQP() == 0 ) && (getQP() == lowestQP) )
717    {
718      bUseDQP = false;
719    }
720    else
721    {
722      bUseDQP = true;
723    }
[2]724  }
[56]725  else
726  {
727    if(bUseDQP == false)
728    {
729      if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP())
730      {
731        bUseDQP = true;
732      }
733    }
734  }
735
736  if(bUseDQP)
737  {
738    m_cPPS.setUseDQP(true);
739    m_cPPS.setMaxCuDQPDepth( m_iMaxCuDQPDepth );
740    m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) );
741  }
742  else
743  {
744    m_cPPS.setUseDQP(false);
745    m_cPPS.setMaxCuDQPDepth( 0 );
746    m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) );
747  }
[2]748
[608]749#if RATE_CONTROL_LAMBDA_DOMAIN
750  if ( m_RCEnableRateControl )
751  {
752    m_cPPS.setUseDQP(true);
753    m_cPPS.setMaxCuDQPDepth( 0 );
754    m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) );
[637]755  }
756#endif
757#if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_FIX_URQ
[635]758  if ( m_enableRateCtrl )
759  {
760    m_cPPS.setUseDQP(true);
761    m_cPPS.setMaxCuDQPDepth( 0 );
762    m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) );
763  } 
[608]764#endif
[2]765
[608]766  m_cPPS.setChromaCbQpOffset( m_chromaCbQpOffset );
767  m_cPPS.setChromaCrQpOffset( m_chromaCrQpOffset );
768
[56]769  m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams);
[608]770  m_cPPS.setEntropyCodingSyncEnabledFlag( m_iWaveFrontSynchro > 0 );
771  m_cPPS.setTilesEnabledFlag( (m_iNumColumnsMinus1 > 0 || m_iNumRowsMinus1 > 0) );
772  m_cPPS.setUseWP( m_useWeightedPred );
773  m_cPPS.setWPBiPred( m_useWeightedBiPred );
[56]774  m_cPPS.setOutputFlagPresentFlag( false );
[608]775#if H_MV
[622]776#if H_MV5
777  m_cPPS.setNumExtraSliceHeaderBits( 2 ); 
778#else
[608]779  m_cPPS.setNumExtraSliceHeaderBits( 1 ); 
780#endif
[622]781#endif
[56]782  m_cPPS.setSignHideFlag(getSignHideFlag());
[608]783  m_cPPS.setDeblockingFilterControlPresentFlag (m_DeblockingFilterControlPresent );
784  m_cPPS.setLog2ParallelMergeLevelMinus2   (m_log2ParallelMergeLevelMinus2 );
[56]785  m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG);
[608]786  m_cPPS.setLoopFilterAcrossSlicesEnabledFlag( m_bLFCrossSliceBoundaryFlag );
787  Int histogram[MAX_NUM_REF + 1];
788  for( Int i = 0; i <= MAX_NUM_REF; i++ )
789  {
790    histogram[i]=0;
791  }
792  for( Int i = 0; i < getGOPSize(); i++ )
793  {
794    assert(getGOPEntry(i).m_numRefPicsActive >= 0 && getGOPEntry(i).m_numRefPicsActive <= MAX_NUM_REF);
795    histogram[getGOPEntry(i).m_numRefPicsActive]++;
796  }
797  Int maxHist=-1;
798  Int bestPos=0;
799  for( Int i = 0; i <= MAX_NUM_REF; i++ )
800  {
801    if(histogram[i]>maxHist)
802    {
803      maxHist=histogram[i];
804      bestPos=i;
805    }
806  }
807  assert(bestPos <= 15);
808  m_cPPS.setNumRefIdxL0DefaultActive(bestPos);
809  m_cPPS.setNumRefIdxL1DefaultActive(bestPos);
810  m_cPPS.setTransquantBypassEnableFlag(getTransquantBypassEnableFlag());
811  m_cPPS.setUseTransformSkip( m_useTransformSkip );
812  if (m_sliceSegmentMode)
813  {
814    m_cPPS.setDependentSliceSegmentsEnabledFlag( true );
815  }
816  if( m_cPPS.getDependentSliceSegmentsEnabledFlag() )
817  {
818    Int NumCtx = m_cPPS.getEntropyCodingSyncEnabledFlag()?2:1;
819    m_cSliceEncoder.initCtxMem( NumCtx );
820    for ( UInt st = 0; st < NumCtx; st++ )
821    {
822      TEncSbac* ctx = NULL;
823      ctx = new TEncSbac;
824      ctx->init( &m_cBinCoderCABAC );
825      m_cSliceEncoder.setCtxMem( ctx, st );
826    }
827  }
828#if H_3D
829  if( m_cSPS.hasCamParInSliceHeader() )
830  {
831    m_cPPS.setSliceHeaderExtensionPresentFlag( true ); 
832  }
[42]833#endif
[2]834}
835
[56]836//Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file.
837Void TEncTop::xInitRPS()
[2]838{
[56]839  TComReferencePictureSet*      rps;
840 
[608]841  m_cSPS.createRPSList(getGOPSize()+m_extraRPSs);
842  TComRPSList* rpsList = m_cSPS.getRPSList();
843
[56]844  for( Int i = 0; i < getGOPSize()+m_extraRPSs; i++) 
845  {
[608]846    GOPEntry ge = getGOPEntry(i);
847    rps = rpsList->getReferencePictureSet(i);
[56]848    rps->setNumberOfPictures(ge.m_numRefPics);
849    rps->setNumRefIdc(ge.m_numRefIdc);
850    Int numNeg = 0;
851    Int numPos = 0;
852    for( Int j = 0; j < ge.m_numRefPics; j++)
[2]853    {
[56]854      rps->setDeltaPOC(j,ge.m_referencePics[j]);
855      rps->setUsed(j,ge.m_usedByCurrPic[j]);
856      if(ge.m_referencePics[j]>0)
857      {
858        numPos++;
859      }
860      else
861      {
862        numNeg++;
863      }
[2]864    }
[56]865    rps->setNumberOfNegativePictures(numNeg);
866    rps->setNumberOfPositivePictures(numPos);
[608]867
868    // handle inter RPS intialization from the config file.
869#if AUTO_INTER_RPS
870    rps->setInterRPSPrediction(ge.m_interRPSPrediction > 0);  // not very clean, converting anything > 0 to true.
871    rps->setDeltaRIdxMinus1(0);                               // index to the Reference RPS is always the previous one.
872    TComReferencePictureSet*     RPSRef = rpsList->getReferencePictureSet(i-1);  // get the reference RPS
873
874    if (ge.m_interRPSPrediction == 2)  // Automatic generation of the inter RPS idc based on the RIdx provided.
875    {
876      Int deltaRPS = getGOPEntry(i-1).m_POC - ge.m_POC;  // the ref POC - current POC
877      Int numRefDeltaPOC = RPSRef->getNumberOfPictures();
878
879      rps->setDeltaRPS(deltaRPS);           // set delta RPS
880      rps->setNumRefIdc(numRefDeltaPOC+1);  // set the numRefIdc to the number of pictures in the reference RPS + 1.
881      Int count=0;
882      for (Int j = 0; j <= numRefDeltaPOC; j++ ) // cycle through pics in reference RPS.
883      {
884        Int RefDeltaPOC = (j<numRefDeltaPOC)? RPSRef->getDeltaPOC(j): 0;  // if it is the last decoded picture, set RefDeltaPOC = 0
885        rps->setRefIdc(j, 0);
886        for (Int k = 0; k < rps->getNumberOfPictures(); k++ )  // cycle through pics in current RPS.
887        {
888          if (rps->getDeltaPOC(k) == ( RefDeltaPOC + deltaRPS))  // if the current RPS has a same picture as the reference RPS.
889          {
890              rps->setRefIdc(j, (rps->getUsed(k)?1:2));
891              count++;
892              break;
893          }
894        }
895      }
896      if (count != rps->getNumberOfPictures())
897      {
898        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");
899        rps->setInterRPSPrediction(0);
900      }
901    }
902    else if (ge.m_interRPSPrediction == 1)  // inter RPS idc based on the RefIdc values provided in config file.
903    {
904      rps->setDeltaRPS(ge.m_deltaRPS);
905      rps->setNumRefIdc(ge.m_numRefIdc);
906      for (Int j = 0; j < ge.m_numRefIdc; j++ )
907      {
908        rps->setRefIdc(j, ge.m_refIdc[j]);
909      }
910#if WRITE_BACK
911      // the folowing code overwrite the deltaPOC and Used by current values read from the config file with the ones
912      // computed from the RefIdc.  A warning is printed if they are not identical.
913      numNeg = 0;
914      numPos = 0;
915      TComReferencePictureSet      RPSTemp;  // temporary variable
916
917      for (Int j = 0; j < ge.m_numRefIdc; j++ )
918      {
919        if (ge.m_refIdc[j])
920        {
921          Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0);
922          RPSTemp.setDeltaPOC((numNeg+numPos),deltaPOC);
923          RPSTemp.setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0);
924          if (deltaPOC<0)
925          {
926            numNeg++;
927          }
928          else
929          {
930            numPos++;
931          }
932        }
933      }
934      if (numNeg != rps->getNumberOfNegativePictures())
935      {
936        printf("Warning: number of negative pictures in RPS is different between intra and inter RPS specified in the config file.\n");
937        rps->setNumberOfNegativePictures(numNeg);
938        rps->setNumberOfPositivePictures(numNeg+numPos);
939      }
940      if (numPos != rps->getNumberOfPositivePictures())
941      {
942        printf("Warning: number of positive pictures in RPS is different between intra and inter RPS specified in the config file.\n");
943        rps->setNumberOfPositivePictures(numPos);
944        rps->setNumberOfPositivePictures(numNeg+numPos);
945      }
946      RPSTemp.setNumberOfPictures(numNeg+numPos);
947      RPSTemp.setNumberOfNegativePictures(numNeg);
948      RPSTemp.sortDeltaPOC();     // sort the created delta POC before comparing
949      // check if Delta POC and Used are the same
950      // print warning if they are not.
951      for (Int j = 0; j < ge.m_numRefIdc; j++ )
952      {
953        if (RPSTemp.getDeltaPOC(j) != rps->getDeltaPOC(j))
954        {
955          printf("Warning: delta POC is different between intra RPS and inter RPS specified in the config file.\n");
956          rps->setDeltaPOC(j,RPSTemp.getDeltaPOC(j));
957        }
958        if (RPSTemp.getUsed(j) != rps->getUsed(j))
959        {
960          printf("Warning: Used by Current in RPS is different between intra and inter RPS specified in the config file.\n");
961          rps->setUsed(j,RPSTemp.getUsed(j));
962        }
963      }
964#endif
965    }
966#else
[56]967    rps->setInterRPSPrediction(ge.m_interRPSPrediction);
968    if (ge.m_interRPSPrediction)
[2]969    {
[608]970      rps->setDeltaRIdxMinus1(0);
[56]971      rps->setDeltaRPS(ge.m_deltaRPS);
972      rps->setNumRefIdc(ge.m_numRefIdc);
973      for (Int j = 0; j < ge.m_numRefIdc; j++ )
974      {
975        rps->setRefIdc(j, ge.m_refIdc[j]);
976      }
977#if WRITE_BACK
978      // the folowing code overwrite the deltaPOC and Used by current values read from the config file with the ones
979      // computed from the RefIdc.  This is not necessary if both are identical. Currently there is no check to see if they are identical.
980      numNeg = 0;
981      numPos = 0;
[608]982      TComReferencePictureSet*     RPSRef = m_RPSList.getReferencePictureSet(i-1);
983
[56]984      for (Int j = 0; j < ge.m_numRefIdc; j++ )
985      {
986        if (ge.m_refIdc[j])
987        {
988          Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0);
989          rps->setDeltaPOC((numNeg+numPos),deltaPOC);
990          rps->setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0);
991          if (deltaPOC<0)
992          {
993            numNeg++;
994          }
995          else
996          {
997            numPos++;
998          }
999        }
1000      }
1001      rps->setNumberOfNegativePictures(numNeg);
1002      rps->setNumberOfPositivePictures(numPos);
1003      rps->sortDeltaPOC();
1004#endif
[2]1005    }
[608]1006#endif //INTER_RPS_AUTO
[56]1007  }
1008 
1009}
[2]1010
[56]1011   // This is a function that
1012   // determines what Reference Picture Set to use
1013   // for a specific slice (with POC = POCCurr)
[608]1014Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid )
[56]1015{
[608]1016#if H_MV
1017  if( slice->getRapPicFlag() == true && getLayerId() > 0 && POCCurr == 0 )
[56]1018  {
1019    TComReferencePictureSet* rps = slice->getLocalRPS();
1020    rps->setNumberOfNegativePictures(0);
1021    rps->setNumberOfPositivePictures(0);
1022    rps->setNumberOfLongtermPictures(0);
1023    rps->setNumberOfPictures(0);
1024    slice->setRPS(rps);
1025  }
1026  else
1027  {
[608]1028#endif
1029  slice->setRPSidx(GOPid);
[2]1030
[608]1031  for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++)
1032  {   
1033    if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0)
1034    {
1035      Int POCIndex = POCCurr%m_uiIntraPeriod;
1036      if(POCIndex == 0)
[56]1037      {
[608]1038        POCIndex = m_uiIntraPeriod;
[56]1039      }
[608]1040      if(POCIndex == m_GOPList[extraNum].m_POC)
[56]1041      {
[608]1042        slice->setRPSidx(extraNum);
[56]1043      }
1044    }
[608]1045    else
1046    {
1047      if(POCCurr==m_GOPList[extraNum].m_POC)
1048      {
1049        slice->setRPSidx(extraNum);
1050      }
1051    }
1052  }
[2]1053
[608]1054  slice->setRPS(getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx()));
1055  slice->getRPS()->setNumberOfPictures(slice->getRPS()->getNumberOfNegativePictures()+slice->getRPS()->getNumberOfPositivePictures());
1056#if H_MV
[56]1057  }
[608]1058#endif
1059
[2]1060}
1061
[608]1062Int TEncTop::getReferencePictureSetIdxForSOP(TComSlice* slice, Int POCCurr, Int GOPid )
[2]1063{
[608]1064  int rpsIdx = GOPid;
[2]1065
[608]1066  for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++)
1067  {   
1068    if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0)
[2]1069    {
[608]1070      Int POCIndex = POCCurr%m_uiIntraPeriod;
1071      if(POCIndex == 0)
[2]1072      {
[608]1073        POCIndex = m_uiIntraPeriod;
[2]1074      }
[608]1075      if(POCIndex == m_GOPList[extraNum].m_POC)
[2]1076      {
[608]1077        rpsIdx = extraNum;
[2]1078      }
1079    }
[608]1080    else
[56]1081    {
[608]1082      if(POCCurr==m_GOPList[extraNum].m_POC)
[56]1083      {
[608]1084        rpsIdx = extraNum;
[56]1085      }
1086    }
[2]1087  }
[56]1088
[608]1089  return rpsIdx;
[56]1090}
1091
1092Void  TEncTop::xInitPPSforTiles()
1093{
[608]1094  m_cPPS.setUniformSpacingFlag( m_iUniformSpacingIdr );
1095  m_cPPS.setNumColumnsMinus1( m_iNumColumnsMinus1 );
1096  m_cPPS.setNumRowsMinus1( m_iNumRowsMinus1 );
1097  if( m_iUniformSpacingIdr == 0 )
1098  {
1099    m_cPPS.setColumnWidth( m_puiColumnWidth );
1100    m_cPPS.setRowHeight( m_puiRowHeight );
1101  }
1102  m_cPPS.setLoopFilterAcrossTilesEnabledFlag( m_loopFilterAcrossTilesEnabledFlag );
[56]1103
[608]1104  // # substreams is "per tile" when tiles are independent.
1105  if (m_iWaveFrontSynchro
1106    )
1107  {
1108    m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams * (m_iNumColumnsMinus1+1));
1109  }
[2]1110}
1111
[56]1112Void  TEncCfg::xCheckGSParameters()
[2]1113{
[56]1114  Int   iWidthInCU = ( m_iSourceWidth%g_uiMaxCUWidth ) ? m_iSourceWidth/g_uiMaxCUWidth + 1 : m_iSourceWidth/g_uiMaxCUWidth;
1115  Int   iHeightInCU = ( m_iSourceHeight%g_uiMaxCUHeight ) ? m_iSourceHeight/g_uiMaxCUHeight + 1 : m_iSourceHeight/g_uiMaxCUHeight;
1116  UInt  uiCummulativeColumnWidth = 0;
1117  UInt  uiCummulativeRowHeight = 0;
1118
1119  //check the column relative parameters
1120  if( m_iNumColumnsMinus1 >= (1<<(LOG2_MAX_NUM_COLUMNS_MINUS1+1)) )
[2]1121  {
[56]1122    printf( "The number of columns is larger than the maximum allowed number of columns.\n" );
1123    exit( EXIT_FAILURE );
[2]1124  }
[56]1125
1126  if( m_iNumColumnsMinus1 >= iWidthInCU )
[2]1127  {
[56]1128    printf( "The current picture can not have so many columns.\n" );
1129    exit( EXIT_FAILURE );
[2]1130  }
[56]1131
1132  if( m_iNumColumnsMinus1 && m_iUniformSpacingIdr==0 )
[2]1133  {
[56]1134    for(Int i=0; i<m_iNumColumnsMinus1; i++)
[608]1135    {
[56]1136      uiCummulativeColumnWidth += m_puiColumnWidth[i];
[608]1137    }
[56]1138
1139    if( uiCummulativeColumnWidth >= iWidthInCU )
1140    {
1141      printf( "The width of the column is too large.\n" );
1142      exit( EXIT_FAILURE );
1143    }
[2]1144  }
[56]1145
1146  //check the row relative parameters
1147  if( m_iNumRowsMinus1 >= (1<<(LOG2_MAX_NUM_ROWS_MINUS1+1)) )
[2]1148  {
[56]1149    printf( "The number of rows is larger than the maximum allowed number of rows.\n" );
1150    exit( EXIT_FAILURE );
[2]1151  }
[56]1152
1153  if( m_iNumRowsMinus1 >= iHeightInCU )
[2]1154  {
[56]1155    printf( "The current picture can not have so many rows.\n" );
1156    exit( EXIT_FAILURE );
[2]1157  }
1158
[56]1159  if( m_iNumRowsMinus1 && m_iUniformSpacingIdr==0 )
1160  {
1161    for(Int i=0; i<m_iNumRowsMinus1; i++)
1162      uiCummulativeRowHeight += m_puiRowHeight[i];
1163
1164    if( uiCummulativeRowHeight >= iHeightInCU )
1165    {
1166      printf( "The height of the row is too large.\n" );
1167      exit( EXIT_FAILURE );
1168    }
1169  }
[2]1170}
[608]1171#if H_MV
1172Void TEncTop::printSummary( Int numAllPicCoded )
[56]1173{
[608]1174  assert (numAllPicCoded == m_cAnalyzeAll.getNumPic());
[2]1175
[56]1176  //--CFG_KDY
1177  m_cAnalyzeAll.setFrmRate( getFrameRate() );
1178  m_cAnalyzeI.setFrmRate( getFrameRate() );
1179  m_cAnalyzeP.setFrmRate( getFrameRate() );
1180  m_cAnalyzeB.setFrmRate( getFrameRate() );
[2]1181
[56]1182  //-- all
[608]1183  printf( "\n\nSUMMARY ------------------------------------------- LayerId %2d\n", m_layerId );
1184
[56]1185  m_cAnalyzeAll.printOut('a');
[2]1186
[56]1187  printf( "\n\nI Slices--------------------------------------------------------\n" );
1188  m_cAnalyzeI.printOut('i');
1189
1190  printf( "\n\nP Slices--------------------------------------------------------\n" );
1191  m_cAnalyzeP.printOut('p');
1192
1193  printf( "\n\nB Slices--------------------------------------------------------\n" );
1194  m_cAnalyzeB.printOut('b');
1195
[608]1196#if _SUMMARY_OUT_
1197  m_cAnalyzeAll.printSummaryOut();
1198#endif
1199#if _SUMMARY_PIC_
1200  m_cAnalyzeI.printSummary('I');
1201  m_cAnalyzeP.printSummary('P');
1202  m_cAnalyzeB.printSummary('B');
1203#endif
[2]1204}
[56]1205
[608]1206Int TEncTop::getFrameId(Int iGOPid) 
1207{
1208  if(m_iPOCLast == 0)
1209  {
1210    return(0 );
1211  }
1212  else
1213  {
1214    return m_iPOCLast -m_iNumPicRcvd+ getGOPEntry(iGOPid).m_POC ;
1215  }
1216}
1217
1218TComPic* TEncTop::getPic( Int poc )
1219{
1220  TComList<TComPic*>* listPic = getListPic();
1221  TComPic* pcPic = NULL;
1222  for(TComList<TComPic*>::iterator it=listPic->begin(); it!=listPic->end(); it++)
1223  {
1224    if( (*it)->getPOC() == poc )
1225    {
1226      pcPic = *it ;
1227      break ;
1228    }
1229  }
1230  return pcPic;
1231}
1232#endif
1233
1234#if H_3D_VSO
1235Void TEncTop::setupRenModel( Int iPoc, Int iEncViewIdx, Int iEncContent, Int iHorOffset )
1236{
1237  TRenModel* rendererModel = m_cRdCost.getRenModel(); 
1238  rendererModel->setupPart( iHorOffset, std::min( (Int) g_uiMaxCUHeight, (Int) ( m_iSourceHeight - iHorOffset ) )) ; 
1239 
1240  Int iEncViewSIdx = m_cameraParameters->getBaseId2SortedId()[ iEncViewIdx ];
1241
1242  // setup base views
1243  Int iNumOfBV = m_renderModelParameters->getNumOfBaseViewsForView( iEncViewSIdx, iEncContent );
1244
1245  for (Int iCurView = 0; iCurView < iNumOfBV; iCurView++ )
1246  {
1247    Int iBaseViewSIdx;
1248    Int iVideoDistMode;
1249    Int iDepthDistMode;
1250
1251    m_renderModelParameters->getBaseViewData( iEncViewSIdx, iEncContent, iCurView, iBaseViewSIdx, iVideoDistMode, iDepthDistMode );
1252
1253    AOT( iVideoDistMode < 0 || iVideoDistMode > 2 );
1254
1255    Int iBaseViewIdx = m_cameraParameters->getBaseSortedId2Id()[ iBaseViewSIdx ];
1256
1257    TComPicYuv* pcPicYuvVideoRec  = m_ivPicLists->getPicYuv( iBaseViewIdx, false, iPoc, true  );
1258    TComPicYuv* pcPicYuvDepthRec  = m_ivPicLists->getPicYuv( iBaseViewIdx, true , iPoc, true  );
1259    TComPicYuv* pcPicYuvVideoOrg  = m_ivPicLists->getPicYuv( iBaseViewIdx, false, iPoc, false );
1260    TComPicYuv* pcPicYuvDepthOrg  = m_ivPicLists->getPicYuv( iBaseViewIdx, true , iPoc, false );   
1261
1262    TComPicYuv* pcPicYuvVideoRef  = ( iVideoDistMode == 2 ) ? pcPicYuvVideoOrg  : NULL;
1263    TComPicYuv* pcPicYuvDepthRef  = ( iDepthDistMode == 2 ) ? pcPicYuvDepthOrg  : NULL;
1264
1265    TComPicYuv* pcPicYuvVideoTest = ( iVideoDistMode == 0 ) ? pcPicYuvVideoOrg  : pcPicYuvVideoRec;
1266    TComPicYuv* pcPicYuvDepthTest = ( iDepthDistMode == 0 ) ? pcPicYuvDepthOrg  : pcPicYuvDepthRec;
1267
1268    AOT( (iVideoDistMode == 2) != (pcPicYuvVideoRef != NULL) );
1269    AOT( (iDepthDistMode == 2) != (pcPicYuvDepthRef != NULL) );
1270    AOT( pcPicYuvDepthTest == NULL );
1271    AOT( pcPicYuvVideoTest == NULL );
1272
1273    rendererModel->setBaseView( iBaseViewSIdx, pcPicYuvVideoTest, pcPicYuvDepthTest, pcPicYuvVideoRef, pcPicYuvDepthRef );
1274  }
1275
1276  rendererModel->setErrorMode( iEncViewSIdx, iEncContent, 0 );
1277  // setup virtual views
1278  Int iNumOfSV  = m_renderModelParameters->getNumOfModelsForView( iEncViewSIdx, iEncContent );
1279  for (Int iCurView = 0; iCurView < iNumOfSV; iCurView++ )
1280  {
1281    Int iOrgRefBaseViewSIdx;
1282    Int iLeftBaseViewSIdx;
1283    Int iRightBaseViewSIdx;
1284    Int iSynthViewRelNum;
1285    Int iModelNum;
1286    Int iBlendMode;
1287    m_renderModelParameters->getSingleModelData(iEncViewSIdx, iEncContent, iCurView, iModelNum, iBlendMode,iLeftBaseViewSIdx, iRightBaseViewSIdx, iOrgRefBaseViewSIdx, iSynthViewRelNum );
1288
1289    Int iLeftBaseViewIdx    = -1;
1290    Int iRightBaseViewIdx   = -1;
1291
1292    TComPicYuv* pcPicYuvOrgRef  = NULL;
1293    Int**      ppiShiftLUTLeft  = NULL;
1294    Int**      ppiShiftLUTRight = NULL;
1295    Int**      ppiBaseShiftLUTLeft  = NULL;
1296    Int**      ppiBaseShiftLUTRight = NULL;
1297
1298
1299    Int        iDistToLeft      = -1;
1300
1301    Int iSynthViewIdx = m_cameraParameters->synthRelNum2Idx( iSynthViewRelNum );
1302
1303    if ( iLeftBaseViewSIdx != -1 )
1304    {
1305      iLeftBaseViewIdx   = m_cameraParameters->getBaseSortedId2Id()   [ iLeftBaseViewSIdx ];
1306      ppiShiftLUTLeft    = m_cameraParameters->getSynthViewShiftLUTI()[ iLeftBaseViewIdx  ][ iSynthViewIdx  ];
1307    }
1308
1309    if ( iRightBaseViewSIdx != -1 )
1310    {
1311      iRightBaseViewIdx  = m_cameraParameters->getBaseSortedId2Id()   [iRightBaseViewSIdx ];
1312      ppiShiftLUTRight   = m_cameraParameters->getSynthViewShiftLUTI()[ iRightBaseViewIdx ][ iSynthViewIdx ];
1313    }
1314
1315    if ( iRightBaseViewSIdx != -1 && iLeftBaseViewSIdx != -1 )
1316    {
1317      iDistToLeft          = m_cameraParameters->getRelDistLeft(  iSynthViewIdx , iLeftBaseViewIdx, iRightBaseViewIdx);
1318      ppiBaseShiftLUTLeft  = m_cameraParameters->getBaseViewShiftLUTI() [ iLeftBaseViewIdx  ][ iRightBaseViewIdx ];
1319      ppiBaseShiftLUTRight = m_cameraParameters->getBaseViewShiftLUTI() [ iRightBaseViewIdx ][ iLeftBaseViewIdx  ];
1320
1321    }
1322
1323    if ( iOrgRefBaseViewSIdx != -1 )
1324    {
1325      pcPicYuvOrgRef = m_ivPicLists->getPicYuv(  m_cameraParameters->getBaseSortedId2Id()[ iOrgRefBaseViewSIdx ] , false, iPoc, false );
1326      AOF ( pcPicYuvOrgRef );
1327    }
1328
1329    rendererModel->setSingleModel( iModelNum, ppiShiftLUTLeft, ppiBaseShiftLUTLeft, ppiShiftLUTRight, ppiBaseShiftLUTRight, iDistToLeft, pcPicYuvOrgRef );
1330  }
1331}
1332#endif
[56]1333//! \}
Note: See TracBrowser for help on using the repository browser.