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

Last change on this file since 648 was 648, checked in by tech, 11 years ago

Macro removal part H_MV5.

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