source: 3DVCSoftware/trunk/source/Lib/TLibEncoder/TEncTop.cpp @ 608

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

Merged DEV-2.0-dev0@604.

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