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

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

Minor clean ups.

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