source: 3DVCSoftware/branches/HTM-DEV-0.3-dev1/source/Lib/TLibEncoder/TEncTop.cpp @ 471

Last change on this file since 471 was 446, checked in by tech, 12 years ago

Added missing parts.

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