source: SHVCSoftware/branches/SHM-2.0-dev/source/Lib/TLibEncoder/TEncTop.cpp @ 157

Last change on this file since 157 was 151, checked in by seregin, 12 years ago

compilation error fix

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