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

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