source: SHVCSoftware/branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncTop.cpp @ 377

Last change on this file since 377 was 377, checked in by seregin, 11 years ago

remove REF_IDX_FRAMEWORK macro

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