source: SHVCSoftware/branches/SHM-1.0-dev/source/Lib/TLibEncoder/TEncTop.cpp @ 26

Last change on this file since 26 was 25, checked in by qualcomm, 13 years ago

L0336: motion field mapping of inter-layer reference picture from Qualcomm, cjianle@…

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