source: 3DVCSoftware/branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncTop.cpp @ 635

Last change on this file since 635 was 635, checked in by kwu-htm, 11 years ago

"JCT3V-E0227 : Inter-view MAD prediction for 3D multi-view video" is integrated by KWU. Configuration has changed by adding rate control for URQ and the integrated view-wise target bitrate allocation and inter-view MAD prediction.

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