source: SHVCSoftware/branches/HM-10.0-dev-SHM/source/Lib/TLibEncoder/TEncTop.cpp @ 105

Last change on this file since 105 was 75, checked in by seregin, 12 years ago

remove m_bIsILR flag

File size: 37.0 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
45//! \ingroup TLibEncoder
46//! \{
47#if SVC_EXTENSION 
48Int TEncTop::m_iSPSIdCnt = 0;
49Int TEncTop::m_iPPSIdCnt = 0;
50#endif
51
52// ====================================================================================================================
53// Constructor / destructor / create / destroy
54// ====================================================================================================================
55
56TEncTop::TEncTop()
57{
58  m_iPOCLast          = -1;
59  m_iNumPicRcvd       =  0;
60  m_uiNumAllPicCoded  =  0;
61  m_pppcRDSbacCoder   =  NULL;
62  m_pppcBinCoderCABAC =  NULL;
63  m_cRDGoOnSbacCoder.init( &m_cRDGoOnBinCoderCABAC );
64#if ENC_DEC_TRACE
65  g_hTrace = fopen( "TraceEnc.txt", "wb" );
66  g_bJustDoIt = g_bEncDecTraceDisable;
67  g_nSymbolCounter = 0;
68#endif
69
70  m_iMaxRefPicNum     = 0;
71
72#if FAST_BIT_EST
73  ContextModel::buildNextStateTable();
74#endif
75
76  m_pcSbacCoders           = NULL;
77  m_pcBinCoderCABACs       = NULL;
78  m_ppppcRDSbacCoders      = NULL;
79  m_ppppcBinCodersCABAC    = NULL;
80  m_pcRDGoOnSbacCoders     = NULL;
81  m_pcRDGoOnBinCodersCABAC = NULL;
82  m_pcBitCounters          = NULL;
83  m_pcRdCosts              = NULL;
84#if REF_IDX_FRAMEWORK
85  memset(m_cIlpPic, 0, sizeof(m_cIlpPic));
86#endif
87#if REF_IDX_MFM
88  m_bMFMEnabledFlag = false;
89#endif
90}
91
92TEncTop::~TEncTop()
93{
94#if ENC_DEC_TRACE
95  fclose( g_hTrace );
96#endif
97}
98
99Void TEncTop::create ()
100{
101#if !SVC_EXTENSION
102  // initialize global variables
103  initROM();
104#endif
105 
106  // create processing unit classes
107#if SVC_EXTENSION
108  m_cGOPEncoder.        create( m_layerId );
109#else
110  m_cGOPEncoder.        create();
111#endif
112  m_cSliceEncoder.      create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
113  m_cCuEncoder.         create( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
114  if (m_bUseSAO)
115  {
116    m_cEncSAO.setSaoLcuBoundary(getSaoLcuBoundary());
117    m_cEncSAO.setSaoLcuBasedOptimization(getSaoLcuBasedOptimization());
118    m_cEncSAO.setMaxNumOffsetsPerPic(getMaxNumOffsetsPerPic());
119    m_cEncSAO.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight );
120    m_cEncSAO.createEncBuffer();
121  }
122#if ADAPTIVE_QP_SELECTION
123  if (m_bUseAdaptQpSelect)
124  {
125    m_cTrQuant.initSliceQpDelta();
126  }
127#endif
128  m_cLoopFilter.        create( g_uiMaxCUDepth );
129 
130#if RATE_CONTROL_LAMBDA_DOMAIN
131  if ( m_RCEnableRateControl )
132  {
133    m_cRateCtrl.init( m_framesToBeEncoded, m_RCTargetBitrate, m_iFrameRate, m_iGOPSize, m_iSourceWidth, m_iSourceHeight,
134                      g_uiMaxCUWidth, g_uiMaxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList );
135  }
136#else
137  m_cRateCtrl.create(getIntraPeriod(), getGOPSize(), getFrameRate(), getTargetBitrate(), getQP(), getNumLCUInUnit(), getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight);
138#endif
139  // if SBAC-based RD optimization is used
140  if( m_bUseSBACRD )
141  {
142    m_pppcRDSbacCoder = new TEncSbac** [g_uiMaxCUDepth+1];
143#if FAST_BIT_EST
144    m_pppcBinCoderCABAC = new TEncBinCABACCounter** [g_uiMaxCUDepth+1];
145#else
146    m_pppcBinCoderCABAC = new TEncBinCABAC** [g_uiMaxCUDepth+1];
147#endif
148   
149    for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
150    {
151      m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM];
152#if FAST_BIT_EST
153      m_pppcBinCoderCABAC[iDepth] = new TEncBinCABACCounter* [CI_NUM];
154#else
155      m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM];
156#endif
157     
158      for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
159      {
160        m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac;
161#if FAST_BIT_EST
162        m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABACCounter;
163#else
164        m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC;
165#endif
166        m_pppcRDSbacCoder   [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] );
167      }
168    }
169  }
170}
171
172/**
173 - Allocate coders required for wavefront for the nominated number of substreams.
174 .
175 \param iNumSubstreams Determines how much information to allocate.
176 */
177Void TEncTop::createWPPCoders(Int iNumSubstreams)
178{
179  if (m_pcSbacCoders != NULL)
180  {
181    return; // already generated.
182  }
183
184  m_iNumSubstreams         = iNumSubstreams;
185  m_pcSbacCoders           = new TEncSbac       [iNumSubstreams];
186  m_pcBinCoderCABACs       = new TEncBinCABAC   [iNumSubstreams];
187  m_pcRDGoOnSbacCoders     = new TEncSbac       [iNumSubstreams];
188  m_pcRDGoOnBinCodersCABAC = new TEncBinCABAC   [iNumSubstreams];
189  m_pcBitCounters          = new TComBitCounter [iNumSubstreams];
190  m_pcRdCosts              = new TComRdCost     [iNumSubstreams];
191
192  for ( UInt ui = 0 ; ui < iNumSubstreams; ui++ )
193  {
194    m_pcRDGoOnSbacCoders[ui].init( &m_pcRDGoOnBinCodersCABAC[ui] );
195    m_pcSbacCoders[ui].init( &m_pcBinCoderCABACs[ui] );
196  }
197  if( m_bUseSBACRD )
198  {
199    m_ppppcRDSbacCoders      = new TEncSbac***    [iNumSubstreams];
200    m_ppppcBinCodersCABAC    = new TEncBinCABAC***[iNumSubstreams];
201    for ( UInt ui = 0 ; ui < iNumSubstreams ; ui++ )
202    {
203      m_ppppcRDSbacCoders[ui]  = new TEncSbac** [g_uiMaxCUDepth+1];
204      m_ppppcBinCodersCABAC[ui]= new TEncBinCABAC** [g_uiMaxCUDepth+1];
205     
206      for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
207      {
208        m_ppppcRDSbacCoders[ui][iDepth]  = new TEncSbac*     [CI_NUM];
209        m_ppppcBinCodersCABAC[ui][iDepth]= new TEncBinCABAC* [CI_NUM];
210
211        for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
212        {
213          m_ppppcRDSbacCoders  [ui][iDepth][iCIIdx] = new TEncSbac;
214          m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx] = new TEncBinCABAC;
215          m_ppppcRDSbacCoders  [ui][iDepth][iCIIdx]->init( m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx] );
216        }
217      }
218    }
219  }
220}
221
222Void TEncTop::destroy ()
223{
224  // destroy processing unit classes
225  m_cGOPEncoder.        destroy();
226  m_cSliceEncoder.      destroy();
227  m_cCuEncoder.         destroy();
228  if (m_cSPS.getUseSAO())
229  {
230    m_cEncSAO.destroy();
231    m_cEncSAO.destroyEncBuffer();
232  }
233  m_cLoopFilter.        destroy();
234  m_cRateCtrl.          destroy();
235  // SBAC RD
236  if( m_bUseSBACRD )
237  {
238    Int iDepth;
239    for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
240    {
241      for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
242      {
243        delete m_pppcRDSbacCoder[iDepth][iCIIdx];
244        delete m_pppcBinCoderCABAC[iDepth][iCIIdx];
245      }
246    }
247   
248    for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
249    {
250      delete [] m_pppcRDSbacCoder[iDepth];
251      delete [] m_pppcBinCoderCABAC[iDepth];
252    }
253   
254    delete [] m_pppcRDSbacCoder;
255    delete [] m_pppcBinCoderCABAC;
256
257    for ( UInt ui = 0; ui < m_iNumSubstreams; ui++ )
258    {
259      for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
260      {
261        for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
262        {
263          delete m_ppppcRDSbacCoders  [ui][iDepth][iCIIdx];
264          delete m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx];
265        }
266      }
267
268      for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
269      {
270        delete [] m_ppppcRDSbacCoders  [ui][iDepth];
271        delete [] m_ppppcBinCodersCABAC[ui][iDepth];
272      }
273      delete[] m_ppppcRDSbacCoders  [ui];
274      delete[] m_ppppcBinCodersCABAC[ui];
275    }
276    delete[] m_ppppcRDSbacCoders;
277    delete[] m_ppppcBinCodersCABAC;
278  }
279  delete[] m_pcSbacCoders;
280  delete[] m_pcBinCoderCABACs;
281  delete[] m_pcRDGoOnSbacCoders; 
282  delete[] m_pcRDGoOnBinCodersCABAC;
283  delete[] m_pcBitCounters;
284  delete[] m_pcRdCosts;
285 
286#if !SVC_EXTENSION
287  // destroy ROM
288  destroyROM();
289#endif
290#if REF_IDX_FRAMEWORK
291  for(Int i=0; i<MAX_NUM_REF; i++)
292  {
293    if(m_cIlpPic[i])
294    {
295      //m_cIlpPic[i]->setPicYuvRec(NULL);
296      m_cIlpPic[i]->destroy();
297      delete m_cIlpPic[i];
298      m_cIlpPic[i] = NULL;
299    }
300  }   
301#endif
302  return;
303}
304
305Void TEncTop::init()
306{
307  // initialize SPS
308  xInitSPS();
309 
310  /* set the VPS profile information */
311  *m_cVPS.getPTL() = *m_cSPS.getPTL();
312#if L0043_TIMING_INFO
313  m_cVPS.getTimingInfo()->setTimingInfoPresentFlag       ( false );
314#endif
315  // initialize PPS
316  m_cPPS.setSPS(&m_cSPS);
317  xInitPPS();
318  xInitRPS();
319
320  xInitPPSforTiles();
321
322  // initialize processing unit classes
323  m_cGOPEncoder.  init( this );
324  m_cSliceEncoder.init( this );
325  m_cCuEncoder.   init( this );
326 
327  // initialize transform & quantization class
328  m_pcCavlcCoder = getCavlcCoder();
329 
330  m_cTrQuant.init( 1 << m_uiQuadtreeTULog2MaxSize,
331                  m_useRDOQ, 
332                  m_useRDOQTS,
333                  true 
334                  ,m_useTransformSkipFast
335#if ADAPTIVE_QP_SELECTION                 
336                  , m_bUseAdaptQpSelect
337#endif
338                  );
339 
340  // initialize encoder search class
341  m_cSearch.init( this, &m_cTrQuant, m_iSearchRange, m_bipredSearchRange, m_iFastSearch, 0, &m_cEntropyCoder, &m_cRdCost, getRDSbacCoder(), getRDGoOnSbacCoder() );
342
343  m_iMaxRefPicNum = 0;
344#if SVC_EXTENSION
345  m_iSPSIdCnt ++;
346  m_iPPSIdCnt ++;
347#endif
348#if REF_IDX_FRAMEWORK
349  xInitILRP();
350#endif
351}
352
353// ====================================================================================================================
354// Public member functions
355// ====================================================================================================================
356
357Void TEncTop::deletePicBuffer()
358{
359  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
360  Int iSize = Int( m_cListPic.size() );
361 
362  for ( Int i = 0; i < iSize; i++ )
363  {
364    TComPic* pcPic = *(iterPic++);
365   
366    pcPic->destroy();
367    delete pcPic;
368    pcPic = NULL;
369  }
370}
371
372/**
373 - Application has picture buffer list with size of GOP + 1
374 - Picture buffer list acts like as ring buffer
375 - End of the list has the latest picture
376 .
377 \param   flush               cause encoder to encode a partial GOP
378 \param   pcPicYuvOrg         original YUV picture
379 \retval  rcListPicYuvRecOut  list of reconstruction YUV pictures
380 \retval  rcListBitstreamOut  list of output bitstreams
381 \retval  iNumEncoded         number of encoded pictures
382 */
383#if SVC_EXTENSION
384Void TEncTop::encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP )
385{
386  // compress GOP
387#if RATE_CONTROL_LAMBDA_DOMAIN
388  if ( m_RCEnableRateControl )
389  {
390    m_cRateCtrl.initRCGOP( m_iNumPicRcvd );
391  }
392#endif
393
394  // compress GOP
395  m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut);
396
397#if RATE_CONTROL_LAMBDA_DOMAIN
398  if ( m_RCEnableRateControl )
399  {
400    m_cRateCtrl.destroyRCGOP();
401  }
402#endif
403 
404  m_uiNumAllPicCoded ++;
405}
406
407Void TEncTop::encodePrep( TComPicYuv* pcPicYuvOrg )
408{
409  if (pcPicYuvOrg) 
410  {
411    // get original YUV
412    TComPic* pcPicCurr = NULL;
413    xGetNewPicBuffer( pcPicCurr );
414    pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() );
415
416    // compute image characteristics
417    if ( getUseAdaptiveQP() )
418    {
419      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) );
420    }
421  }
422}
423#else
424Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded )
425{
426  if (pcPicYuvOrg) {
427    // get original YUV
428    TComPic* pcPicCurr = NULL;
429    xGetNewPicBuffer( pcPicCurr );
430    pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() );
431
432    // compute image characteristics
433    if ( getUseAdaptiveQP() )
434    {
435      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) );
436    }
437  }
438 
439  if (!m_iNumPicRcvd || (!flush && m_iPOCLast != 0 && m_iNumPicRcvd != m_iGOPSize && m_iGOPSize))
440  {
441    iNumEncoded = 0;
442    return;
443  }
444 
445#if RATE_CONTROL_LAMBDA_DOMAIN
446  if ( m_RCEnableRateControl )
447  {
448    m_cRateCtrl.initRCGOP( m_iNumPicRcvd );
449  }
450#endif
451
452  // compress GOP
453  m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut);
454
455#if RATE_CONTROL_LAMBDA_DOMAIN
456  if ( m_RCEnableRateControl )
457  {
458    m_cRateCtrl.destroyRCGOP();
459  }
460#endif
461 
462  iNumEncoded         = m_iNumPicRcvd;
463  m_iNumPicRcvd       = 0;
464  m_uiNumAllPicCoded += iNumEncoded;
465}
466#endif
467
468// ====================================================================================================================
469// Protected member functions
470// ====================================================================================================================
471
472/**
473 - Application has picture buffer list with size of GOP + 1
474 - Picture buffer list acts like as ring buffer
475 - End of the list has the latest picture
476 .
477 \retval rpcPic obtained picture buffer
478 */
479Void TEncTop::xGetNewPicBuffer ( TComPic*& rpcPic )
480{
481  TComSlice::sortPicList(m_cListPic);
482 
483  if (m_cListPic.size() >= (UInt)(m_iGOPSize + getMaxDecPicBuffering(MAX_TLAYER-1) + 2) )
484  {
485    TComList<TComPic*>::iterator iterPic  = m_cListPic.begin();
486    Int iSize = Int( m_cListPic.size() );
487    for ( Int i = 0; i < iSize; i++ )
488    {
489      rpcPic = *(iterPic++);
490      if(rpcPic->getSlice(0)->isReferenced() == false)
491      {
492        break;
493      }
494    }
495  }
496  else
497  {
498    if ( getUseAdaptiveQP() )
499    {
500      TEncPic* pcEPic = new TEncPic;
501#if SVC_EXTENSION //Temporal solution, should be modified
502      if(m_layerId > 0)
503      {
504        TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 );
505        if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() )
506        {
507          pcEPic->setSpatialEnhLayerFlag( true );
508        }
509      }
510#endif
511
512#if SVC_UPSAMPLING
513      pcEPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 ,
514                      m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics, &m_cSPS);
515#else
516      pcEPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 ,
517                      m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics);
518#endif
519      rpcPic = pcEPic;
520    }
521    else
522    {
523      rpcPic = new TComPic;
524
525#if SVC_EXTENSION //Temporal solution, should be modified
526      if(m_layerId > 0)
527      {
528        TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 );
529        if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() )
530        {
531          rpcPic->setSpatialEnhLayerFlag( true );
532        }
533      }
534#endif
535
536#if SVC_UPSAMPLING
537      rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
538                      m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics, &m_cSPS);
539#else
540      rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
541                      m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics);
542#endif
543    }
544    if (getUseSAO())
545    {
546      rpcPic->getPicSym()->allocSaoParam(&m_cEncSAO);
547    }
548    m_cListPic.pushBack( rpcPic );
549  }
550  rpcPic->setReconMark (false);
551 
552  m_iPOCLast++;
553  m_iNumPicRcvd++;
554 
555  rpcPic->getSlice(0)->setPOC( m_iPOCLast );
556  // mark it should be extended
557  rpcPic->getPicYuvRec()->setBorderExtension(false);
558}
559
560Void TEncTop::xInitSPS()
561{
562#if SVC_EXTENSION
563  m_cSPS.setLayerId(m_layerId);
564#endif
565#if REF_IDX_MFM
566  m_cSPS.setMFMEnabledFlag(m_bMFMEnabledFlag);
567#endif
568  ProfileTierLevel& profileTierLevel = *m_cSPS.getPTL()->getGeneralPTL();
569  profileTierLevel.setLevelIdc(m_level);
570  profileTierLevel.setTierFlag(m_levelTier);
571  profileTierLevel.setProfileIdc(m_profile);
572  profileTierLevel.setProfileCompatibilityFlag(m_profile, 1);
573#if L0046_CONSTRAINT_FLAGS
574  profileTierLevel.setProgressiveSourceFlag(m_progressiveSourceFlag);
575  profileTierLevel.setInterlacedSourceFlag(m_interlacedSourceFlag);
576  profileTierLevel.setNonPackedConstraintFlag(m_nonPackedConstraintFlag);
577  profileTierLevel.setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag);
578#endif
579 
580  if (m_profile == Profile::MAIN10 && g_bitDepthY == 8 && g_bitDepthC == 8)
581  {
582    /* The above constraint is equal to Profile::MAIN */
583    profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN, 1);
584  }
585  if (m_profile == Profile::MAIN)
586  {
587    /* A Profile::MAIN10 decoder can always decode Profile::MAIN */
588    profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN10, 1);
589  }
590  /* XXX: should Main be marked as compatible with still picture? */
591  /* XXX: may be a good idea to refactor the above into a function
592   * that chooses the actual compatibility based upon options */
593
594  m_cSPS.setPicWidthInLumaSamples         ( m_iSourceWidth      );
595  m_cSPS.setPicHeightInLumaSamples        ( m_iSourceHeight     );
596  m_cSPS.setConformanceWindow             ( m_conformanceWindow );
597  m_cSPS.setMaxCUWidth    ( g_uiMaxCUWidth      );
598  m_cSPS.setMaxCUHeight   ( g_uiMaxCUHeight     );
599  m_cSPS.setMaxCUDepth    ( g_uiMaxCUDepth      );
600  m_cSPS.setMinTrDepth    ( 0                   );
601  m_cSPS.setMaxTrDepth    ( 1                   );
602#if SVC_EXTENSION
603  m_cSPS.setSPSId         ( m_iSPSIdCnt       );
604#endif
605 
606  m_cSPS.setPCMLog2MinSize (m_uiPCMLog2MinSize);
607  m_cSPS.setUsePCM        ( m_usePCM           );
608  m_cSPS.setPCMLog2MaxSize( m_pcmLog2MaxSize  );
609
610  m_cSPS.setQuadtreeTULog2MaxSize( m_uiQuadtreeTULog2MaxSize );
611  m_cSPS.setQuadtreeTULog2MinSize( m_uiQuadtreeTULog2MinSize );
612  m_cSPS.setQuadtreeTUMaxDepthInter( m_uiQuadtreeTUMaxDepthInter    );
613  m_cSPS.setQuadtreeTUMaxDepthIntra( m_uiQuadtreeTUMaxDepthIntra    );
614 
615  m_cSPS.setTMVPFlagsPresent(false);
616  m_cSPS.setUseLossless   ( m_useLossless  );
617
618  m_cSPS.setMaxTrSize   ( 1 << m_uiQuadtreeTULog2MaxSize );
619 
620  m_cSPS.setUseLComb    ( m_bUseLComb           );
621 
622  Int i;
623 
624  for (i = 0; i < g_uiMaxCUDepth-g_uiAddCUDepth; i++ )
625  {
626    m_cSPS.setAMPAcc( i, m_useAMP );
627    //m_cSPS.setAMPAcc( i, 1 );
628  }
629
630  m_cSPS.setUseAMP ( m_useAMP );
631
632  for (i = g_uiMaxCUDepth-g_uiAddCUDepth; i < g_uiMaxCUDepth; i++ )
633  {
634    m_cSPS.setAMPAcc(i, 0);
635  }
636
637  m_cSPS.setBitDepthY( g_bitDepthY );
638  m_cSPS.setBitDepthC( g_bitDepthC );
639
640  m_cSPS.setQpBDOffsetY ( 6*(g_bitDepthY - 8) );
641  m_cSPS.setQpBDOffsetC ( 6*(g_bitDepthC - 8) );
642
643  m_cSPS.setUseSAO( m_bUseSAO );
644
645  m_cSPS.setMaxTLayers( m_maxTempLayer );
646  m_cSPS.setTemporalIdNestingFlag( ( m_maxTempLayer == 1 ) ? true : false );
647  for ( i = 0; i < m_cSPS.getMaxTLayers(); i++ )
648  {
649    m_cSPS.setMaxDecPicBuffering(m_maxDecPicBuffering[i], i);
650    m_cSPS.setNumReorderPics(m_numReorderPics[i], i);
651  }
652  m_cSPS.setPCMBitDepthLuma (g_uiPCMBitDepthLuma);
653  m_cSPS.setPCMBitDepthChroma (g_uiPCMBitDepthChroma);
654  m_cSPS.setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag );
655
656  m_cSPS.setScalingListFlag ( (m_useScalingListId == 0) ? 0 : 1 );
657
658  m_cSPS.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing );
659
660  m_cSPS.setVuiParametersPresentFlag(getVuiParametersPresentFlag());
661  if (m_cSPS.getVuiParametersPresentFlag())
662  {
663    TComVUI* pcVUI = m_cSPS.getVuiParameters();
664    pcVUI->setAspectRatioInfoPresentFlag(getAspectRatioIdc() != -1);
665    pcVUI->setAspectRatioIdc(getAspectRatioIdc());
666    pcVUI->setSarWidth(getSarWidth());
667    pcVUI->setSarHeight(getSarHeight());
668    pcVUI->setOverscanInfoPresentFlag(getOverscanInfoPresentFlag());
669    pcVUI->setOverscanAppropriateFlag(getOverscanAppropriateFlag());
670    pcVUI->setVideoSignalTypePresentFlag(getVideoSignalTypePresentFlag());
671    pcVUI->setVideoFormat(getVideoFormat());
672    pcVUI->setVideoFullRangeFlag(getVideoFullRangeFlag());
673    pcVUI->setColourDescriptionPresentFlag(getColourDescriptionPresentFlag());
674    pcVUI->setColourPrimaries(getColourPrimaries());
675    pcVUI->setTransferCharacteristics(getTransferCharacteristics());
676    pcVUI->setMatrixCoefficients(getMatrixCoefficients());
677    pcVUI->setChromaLocInfoPresentFlag(getChromaLocInfoPresentFlag());
678    pcVUI->setChromaSampleLocTypeTopField(getChromaSampleLocTypeTopField());
679    pcVUI->setChromaSampleLocTypeBottomField(getChromaSampleLocTypeBottomField());
680    pcVUI->setNeutralChromaIndicationFlag(getNeutralChromaIndicationFlag());
681    pcVUI->setDefaultDisplayWindow(getDefaultDisplayWindow());
682    pcVUI->setFrameFieldInfoPresentFlag(getFrameFieldInfoPresentFlag());
683    pcVUI->setFieldSeqFlag(false);
684    pcVUI->setHrdParametersPresentFlag(false);
685#if L0043_TIMING_INFO
686    pcVUI->getTimingInfo()->setPocProportionalToTimingFlag(getPocProportionalToTimingFlag());
687    pcVUI->getTimingInfo()->setNumTicksPocDiffOneMinus1   (getNumTicksPocDiffOneMinus1()   );
688#else
689    pcVUI->setPocProportionalToTimingFlag(getPocProportionalToTimingFlag());
690    pcVUI->setNumTicksPocDiffOneMinus1   (getNumTicksPocDiffOneMinus1()   );
691#endif
692    pcVUI->setBitstreamRestrictionFlag(getBitstreamRestrictionFlag());
693    pcVUI->setTilesFixedStructureFlag(getTilesFixedStructureFlag());
694    pcVUI->setMotionVectorsOverPicBoundariesFlag(getMotionVectorsOverPicBoundariesFlag());
695    pcVUI->setMinSpatialSegmentationIdc(getMinSpatialSegmentationIdc());
696    pcVUI->setMaxBytesPerPicDenom(getMaxBytesPerPicDenom());
697    pcVUI->setMaxBitsPerMinCuDenom(getMaxBitsPerMinCuDenom());
698    pcVUI->setLog2MaxMvLengthHorizontal(getLog2MaxMvLengthHorizontal());
699    pcVUI->setLog2MaxMvLengthVertical(getLog2MaxMvLengthVertical());
700  }
701}
702
703Void TEncTop::xInitPPS()
704{
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  m_cPPS.setDeblockingFilterControlPresentFlag (m_DeblockingFilterControlPresent );
765  m_cPPS.setLog2ParallelMergeLevelMinus2   (m_log2ParallelMergeLevelMinus2 );
766  m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG);
767  m_cPPS.setLoopFilterAcrossSlicesEnabledFlag( m_bLFCrossSliceBoundaryFlag );
768  Int histogram[MAX_NUM_REF + 1];
769  for( Int i = 0; i <= MAX_NUM_REF; i++ )
770  {
771    histogram[i]=0;
772  }
773  for( Int i = 0; i < getGOPSize(); i++ )
774  {
775    assert(getGOPEntry(i).m_numRefPicsActive >= 0 && getGOPEntry(i).m_numRefPicsActive <= MAX_NUM_REF);
776    histogram[getGOPEntry(i).m_numRefPicsActive]++;
777  }
778  Int maxHist=-1;
779  Int bestPos=0;
780  for( Int i = 0; i <= MAX_NUM_REF; i++ )
781  {
782    if(histogram[i]>maxHist)
783    {
784      maxHist=histogram[i];
785      bestPos=i;
786    }
787  }
788#if L0323_LIMIT_DEFAULT_LIST_SIZE
789  assert(bestPos <= 15);
790#endif
791  m_cPPS.setNumRefIdxL0DefaultActive(bestPos);
792  m_cPPS.setNumRefIdxL1DefaultActive(bestPos);
793  m_cPPS.setTransquantBypassEnableFlag(getTransquantBypassEnableFlag());
794  m_cPPS.setUseTransformSkip( m_useTransformSkip );
795  if (m_sliceSegmentMode)
796  {
797    m_cPPS.setDependentSliceSegmentsEnabledFlag( true );
798  }
799  if( m_cPPS.getDependentSliceSegmentsEnabledFlag() )
800  {
801    Int NumCtx = m_cPPS.getEntropyCodingSyncEnabledFlag()?2:1;
802    m_cSliceEncoder.initCtxMem( NumCtx );
803    for ( UInt st = 0; st < NumCtx; st++ )
804    {
805      TEncSbac* ctx = NULL;
806      ctx = new TEncSbac;
807      ctx->init( &m_cBinCoderCABAC );
808      m_cSliceEncoder.setCtxMem( ctx, st );
809    }
810  }
811#if SVC_EXTENSION
812  m_cPPS.setPPSId         ( m_iPPSIdCnt         );
813  m_cPPS.setSPSId         ( m_iSPSIdCnt         );
814#endif
815}
816
817//Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file.
818Void TEncTop::xInitRPS()
819{
820  TComReferencePictureSet*      rps;
821 
822  m_cSPS.createRPSList(getGOPSize()+m_extraRPSs);
823  TComRPSList* rpsList = m_cSPS.getRPSList();
824
825  for( Int i = 0; i < getGOPSize()+m_extraRPSs; i++) 
826  {
827    GOPEntry ge = getGOPEntry(i);
828    rps = rpsList->getReferencePictureSet(i);
829    rps->setNumberOfPictures(ge.m_numRefPics);
830    rps->setNumRefIdc(ge.m_numRefIdc);
831    Int numNeg = 0;
832    Int numPos = 0;
833    for( Int j = 0; j < ge.m_numRefPics; j++)
834    {
835      rps->setDeltaPOC(j,ge.m_referencePics[j]);
836      rps->setUsed(j,ge.m_usedByCurrPic[j]);
837      if(ge.m_referencePics[j]>0)
838      {
839        numPos++;
840      }
841      else
842      {
843        numNeg++;
844      }
845    }
846    rps->setNumberOfNegativePictures(numNeg);
847    rps->setNumberOfPositivePictures(numPos);
848
849    // handle inter RPS intialization from the config file.
850#if AUTO_INTER_RPS
851    rps->setInterRPSPrediction(ge.m_interRPSPrediction > 0);  // not very clean, converting anything > 0 to true.
852    rps->setDeltaRIdxMinus1(0);                               // index to the Reference RPS is always the previous one.
853    TComReferencePictureSet*     RPSRef = rpsList->getReferencePictureSet(i-1);  // get the reference RPS
854
855    if (ge.m_interRPSPrediction == 2)  // Automatic generation of the inter RPS idc based on the RIdx provided.
856    {
857      Int deltaRPS = getGOPEntry(i-1).m_POC - ge.m_POC;  // the ref POC - current POC
858      Int numRefDeltaPOC = RPSRef->getNumberOfPictures();
859
860      rps->setDeltaRPS(deltaRPS);           // set delta RPS
861      rps->setNumRefIdc(numRefDeltaPOC+1);  // set the numRefIdc to the number of pictures in the reference RPS + 1.
862      Int count=0;
863      for (Int j = 0; j <= numRefDeltaPOC; j++ ) // cycle through pics in reference RPS.
864      {
865        Int RefDeltaPOC = (j<numRefDeltaPOC)? RPSRef->getDeltaPOC(j): 0;  // if it is the last decoded picture, set RefDeltaPOC = 0
866        rps->setRefIdc(j, 0);
867        for (Int k = 0; k < rps->getNumberOfPictures(); k++ )  // cycle through pics in current RPS.
868        {
869          if (rps->getDeltaPOC(k) == ( RefDeltaPOC + deltaRPS))  // if the current RPS has a same picture as the reference RPS.
870          {
871              rps->setRefIdc(j, (rps->getUsed(k)?1:2));
872              count++;
873              break;
874          }
875        }
876      }
877      if (count != rps->getNumberOfPictures())
878      {
879        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");
880        rps->setInterRPSPrediction(0);
881      }
882    }
883    else if (ge.m_interRPSPrediction == 1)  // inter RPS idc based on the RefIdc values provided in config file.
884    {
885      rps->setDeltaRPS(ge.m_deltaRPS);
886      rps->setNumRefIdc(ge.m_numRefIdc);
887      for (Int j = 0; j < ge.m_numRefIdc; j++ )
888      {
889        rps->setRefIdc(j, ge.m_refIdc[j]);
890      }
891#if WRITE_BACK
892      // the folowing code overwrite the deltaPOC and Used by current values read from the config file with the ones
893      // computed from the RefIdc.  A warning is printed if they are not identical.
894      numNeg = 0;
895      numPos = 0;
896      TComReferencePictureSet      RPSTemp;  // temporary variable
897
898      for (Int j = 0; j < ge.m_numRefIdc; j++ )
899      {
900        if (ge.m_refIdc[j])
901        {
902          Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0);
903          RPSTemp.setDeltaPOC((numNeg+numPos),deltaPOC);
904          RPSTemp.setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0);
905          if (deltaPOC<0)
906          {
907            numNeg++;
908          }
909          else
910          {
911            numPos++;
912          }
913        }
914      }
915      if (numNeg != rps->getNumberOfNegativePictures())
916      {
917        printf("Warning: number of negative pictures in RPS is different between intra and inter RPS specified in the config file.\n");
918        rps->setNumberOfNegativePictures(numNeg);
919        rps->setNumberOfPositivePictures(numNeg+numPos);
920      }
921      if (numPos != rps->getNumberOfPositivePictures())
922      {
923        printf("Warning: number of positive pictures in RPS is different between intra and inter RPS specified in the config file.\n");
924        rps->setNumberOfPositivePictures(numPos);
925        rps->setNumberOfPositivePictures(numNeg+numPos);
926      }
927      RPSTemp.setNumberOfPictures(numNeg+numPos);
928      RPSTemp.setNumberOfNegativePictures(numNeg);
929      RPSTemp.sortDeltaPOC();     // sort the created delta POC before comparing
930      // check if Delta POC and Used are the same
931      // print warning if they are not.
932      for (Int j = 0; j < ge.m_numRefIdc; j++ )
933      {
934        if (RPSTemp.getDeltaPOC(j) != rps->getDeltaPOC(j))
935        {
936          printf("Warning: delta POC is different between intra RPS and inter RPS specified in the config file.\n");
937          rps->setDeltaPOC(j,RPSTemp.getDeltaPOC(j));
938        }
939        if (RPSTemp.getUsed(j) != rps->getUsed(j))
940        {
941          printf("Warning: Used by Current in RPS is different between intra and inter RPS specified in the config file.\n");
942          rps->setUsed(j,RPSTemp.getUsed(j));
943        }
944      }
945#endif
946    }
947#else
948    rps->setInterRPSPrediction(ge.m_interRPSPrediction);
949    if (ge.m_interRPSPrediction)
950    {
951      rps->setDeltaRIdxMinus1(0);
952      rps->setDeltaRPS(ge.m_deltaRPS);
953      rps->setNumRefIdc(ge.m_numRefIdc);
954      for (Int j = 0; j < ge.m_numRefIdc; j++ )
955      {
956        rps->setRefIdc(j, ge.m_refIdc[j]);
957      }
958#if WRITE_BACK
959      // the folowing code overwrite the deltaPOC and Used by current values read from the config file with the ones
960      // computed from the RefIdc.  This is not necessary if both are identical. Currently there is no check to see if they are identical.
961      numNeg = 0;
962      numPos = 0;
963      TComReferencePictureSet*     RPSRef = m_RPSList.getReferencePictureSet(i-1);
964
965      for (Int j = 0; j < ge.m_numRefIdc; j++ )
966      {
967        if (ge.m_refIdc[j])
968        {
969          Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0);
970          rps->setDeltaPOC((numNeg+numPos),deltaPOC);
971          rps->setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0);
972          if (deltaPOC<0)
973          {
974            numNeg++;
975          }
976          else
977          {
978            numPos++;
979          }
980        }
981      }
982      rps->setNumberOfNegativePictures(numNeg);
983      rps->setNumberOfPositivePictures(numPos);
984      rps->sortDeltaPOC();
985#endif
986    }
987#endif //INTER_RPS_AUTO
988  }
989 
990}
991
992   // This is a function that
993   // determines what Reference Picture Set to use
994   // for a specific slice (with POC = POCCurr)
995Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid )
996{
997  slice->setRPSidx(GOPid);
998
999  for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++)
1000  {   
1001    if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0)
1002    {
1003      Int POCIndex = POCCurr%m_uiIntraPeriod;
1004      if(POCIndex == 0)
1005      {
1006        POCIndex = m_uiIntraPeriod;
1007      }
1008      if(POCIndex == m_GOPList[extraNum].m_POC)
1009      {
1010        slice->setRPSidx(extraNum);
1011      }
1012    }
1013    else
1014    {
1015      if(POCCurr==m_GOPList[extraNum].m_POC)
1016      {
1017        slice->setRPSidx(extraNum);
1018      }
1019    }
1020  }
1021
1022  slice->setRPS(getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx()));
1023  slice->getRPS()->setNumberOfPictures(slice->getRPS()->getNumberOfNegativePictures()+slice->getRPS()->getNumberOfPositivePictures());
1024
1025}
1026
1027Void  TEncTop::xInitPPSforTiles()
1028{
1029  m_cPPS.setUniformSpacingFlag( m_iUniformSpacingIdr );
1030  m_cPPS.setNumColumnsMinus1( m_iNumColumnsMinus1 );
1031  m_cPPS.setNumRowsMinus1( m_iNumRowsMinus1 );
1032  if( m_iUniformSpacingIdr == 0 )
1033  {
1034    m_cPPS.setColumnWidth( m_puiColumnWidth );
1035    m_cPPS.setRowHeight( m_puiRowHeight );
1036  }
1037  m_cPPS.setLoopFilterAcrossTilesEnabledFlag( m_loopFilterAcrossTilesEnabledFlag );
1038
1039  // # substreams is "per tile" when tiles are independent.
1040  if (m_iWaveFrontSynchro
1041    )
1042  {
1043    m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams * (m_iNumColumnsMinus1+1));
1044  }
1045}
1046
1047Void  TEncCfg::xCheckGSParameters()
1048{
1049  Int   iWidthInCU = ( m_iSourceWidth%g_uiMaxCUWidth ) ? m_iSourceWidth/g_uiMaxCUWidth + 1 : m_iSourceWidth/g_uiMaxCUWidth;
1050  Int   iHeightInCU = ( m_iSourceHeight%g_uiMaxCUHeight ) ? m_iSourceHeight/g_uiMaxCUHeight + 1 : m_iSourceHeight/g_uiMaxCUHeight;
1051  UInt  uiCummulativeColumnWidth = 0;
1052  UInt  uiCummulativeRowHeight = 0;
1053
1054  //check the column relative parameters
1055  if( m_iNumColumnsMinus1 >= (1<<(LOG2_MAX_NUM_COLUMNS_MINUS1+1)) )
1056  {
1057    printf( "The number of columns is larger than the maximum allowed number of columns.\n" );
1058    exit( EXIT_FAILURE );
1059  }
1060
1061  if( m_iNumColumnsMinus1 >= iWidthInCU )
1062  {
1063    printf( "The current picture can not have so many columns.\n" );
1064    exit( EXIT_FAILURE );
1065  }
1066
1067  if( m_iNumColumnsMinus1 && m_iUniformSpacingIdr==0 )
1068  {
1069    for(Int i=0; i<m_iNumColumnsMinus1; i++)
1070    {
1071      uiCummulativeColumnWidth += m_puiColumnWidth[i];
1072    }
1073
1074    if( uiCummulativeColumnWidth >= iWidthInCU )
1075    {
1076      printf( "The width of the column is too large.\n" );
1077      exit( EXIT_FAILURE );
1078    }
1079  }
1080
1081  //check the row relative parameters
1082  if( m_iNumRowsMinus1 >= (1<<(LOG2_MAX_NUM_ROWS_MINUS1+1)) )
1083  {
1084    printf( "The number of rows is larger than the maximum allowed number of rows.\n" );
1085    exit( EXIT_FAILURE );
1086  }
1087
1088  if( m_iNumRowsMinus1 >= iHeightInCU )
1089  {
1090    printf( "The current picture can not have so many rows.\n" );
1091    exit( EXIT_FAILURE );
1092  }
1093
1094  if( m_iNumRowsMinus1 && m_iUniformSpacingIdr==0 )
1095  {
1096    for(Int i=0; i<m_iNumRowsMinus1; i++)
1097    {
1098      uiCummulativeRowHeight += m_puiRowHeight[i];
1099    }
1100
1101    if( uiCummulativeRowHeight >= iHeightInCU )
1102    {
1103      printf( "The height of the row is too large.\n" );
1104      exit( EXIT_FAILURE );
1105    }
1106  }
1107}
1108
1109#if REF_IDX_FRAMEWORK
1110Void TEncTop::xInitILRP()
1111{
1112  if(m_layerId>0)
1113  {
1114    Int  numReorderPics[MAX_TLAYER];
1115    Window &conformanceWindow = m_cSPS.getConformanceWindow();
1116    Window defaultDisplayWindow = m_cSPS.getVuiParametersPresentFlag() ? m_cSPS.getVuiParameters()->getDefaultDisplayWindow() : Window();
1117
1118    if (m_cIlpPic[0] == NULL)
1119    {
1120      for (Int j=0; j<1/*MAX_NUM_REF*/; j++)
1121      {
1122        m_cIlpPic[j] = new  TComPic;
1123        //m_cIlpPic[j]->createWithOutYuv(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, &m_cSPS, true);
1124#if SVC_UPSAMPLING
1125        m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, &m_cSPS, true);
1126#else
1127        m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
1128#endif
1129        for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++)
1130        {
1131          m_cIlpPic[j]->getPicSym()->getCU(i)->initCU(m_cIlpPic[j], i);
1132        }
1133      }
1134    }
1135  }
1136}
1137
1138Void TEncTop::setILRPic(TComPic *pcPic)
1139{
1140  if(m_cIlpPic[0])
1141  {
1142    //m_cIlpPic[0]->setPicYuvRec(pcPic->getFullPelBaseRec());
1143    m_cIlpPic[0]->copyUpsampledPictureYuv(pcPic->getFullPelBaseRec(), m_cIlpPic[0]->getPicYuvRec());
1144    m_cIlpPic[0]->getSlice(0)->setPOC(pcPic->getPOC());
1145    m_cIlpPic[0]->setLayerId(0); //set reference layerId
1146    m_cIlpPic[0]->getPicYuvRec()->setBorderExtension(false);
1147    m_cIlpPic[0]->getPicYuvRec()->extendPicBorder();
1148  }
1149}
1150#endif
1151//! \}
Note: See TracBrowser for help on using the repository browser.