source: SHVCSoftware/branches/0.1.1-bugfix/source/Lib/TLibEncoder/TEncTop.cpp @ 1497

Last change on this file since 1497 was 6, checked in by seregin, 12 years ago

Correct IntraBL cost and fix for couple of compiler warnings.

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