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

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