source: SHVCSoftware/branches/SHM-3.0-dev/source/Lib/TLibEncoder/TEncTop.cpp @ 982

Last change on this file since 982 was 334, checked in by ericsson, 11 years ago

Initial reference picture list construction N0316 (Ericsson), N0082(Sony)

#define RPL_INIT_N0316_N0082 N0316, N0082: initial reference picture list construction
#define FINAL_RPL_CHANGE_N0082
N0082: final ref picture list change (encoder change)

  • Property svn:eol-style set to native
File size: 40.5 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license. 
5 *
6 * Copyright (c) 2010-2013, ITU/ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file     TEncTop.cpp
35    \brief    encoder class
36*/
37
38#include "TLibCommon/CommonDef.h"
39#include "TEncTop.h"
40#include "TEncPic.h"
41#if FAST_BIT_EST
42#include "TLibCommon/ContextModel.h"
43#endif
44
45//! \ingroup TLibEncoder
46//! \{
47#if SVC_EXTENSION 
48Int TEncTop::m_iSPSIdCnt = 0;
49Int TEncTop::m_iPPSIdCnt = 0;
50TComVPS TEncCfg::m_cVPS;
51#endif
52
53// ====================================================================================================================
54// Constructor / destructor / create / destroy
55// ====================================================================================================================
56
57TEncTop::TEncTop()
58{
59  m_iPOCLast          = -1;
60  m_iNumPicRcvd       =  0;
61  m_uiNumAllPicCoded  =  0;
62  m_pppcRDSbacCoder   =  NULL;
63  m_pppcBinCoderCABAC =  NULL;
64  m_cRDGoOnSbacCoder.init( &m_cRDGoOnBinCoderCABAC );
65#if ENC_DEC_TRACE
66  g_hTrace = fopen( "TraceEnc.txt", "wb" );
67  g_bJustDoIt = g_bEncDecTraceDisable;
68  g_nSymbolCounter = 0;
69#endif
70
71  m_iMaxRefPicNum     = 0;
72
73#if FAST_BIT_EST
74  ContextModel::buildNextStateTable();
75#endif
76
77  m_pcSbacCoders           = NULL;
78  m_pcBinCoderCABACs       = NULL;
79  m_ppppcRDSbacCoders      = NULL;
80  m_ppppcBinCodersCABAC    = NULL;
81  m_pcRDGoOnSbacCoders     = NULL;
82  m_pcRDGoOnBinCodersCABAC = NULL;
83  m_pcBitCounters          = NULL;
84  m_pcRdCosts              = NULL;
85#if REF_IDX_FRAMEWORK
86  memset(m_cIlpPic, 0, sizeof(m_cIlpPic));
87#endif
88#if REF_IDX_MFM
89  m_bMFMEnabledFlag = false;
90#endif
91#if SCALED_REF_LAYER_OFFSETS
92  m_numScaledRefLayerOffsets = 0;
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  // destroy ROM
292  destroyROM();
293#endif
294#if REF_IDX_FRAMEWORK
295  for(Int i=0; i<MAX_NUM_REF; i++)
296  {
297    if(m_cIlpPic[i])
298    {
299      m_cIlpPic[i]->destroy();
300      delete m_cIlpPic[i];
301      m_cIlpPic[i] = NULL;
302    }
303  }   
304#endif
305  return;
306}
307
308Void TEncTop::init()
309{
310  // initialize SPS
311  xInitSPS();
312 
313  /* set the VPS profile information */
314  *m_cVPS.getPTL() = *m_cSPS.getPTL();
315  m_cVPS.getTimingInfo()->setTimingInfoPresentFlag       ( false );
316  // initialize PPS
317  m_cPPS.setSPS(&m_cSPS);
318  xInitPPS();
319  xInitRPS();
320
321  xInitPPSforTiles();
322
323  // initialize processing unit classes
324  m_cGOPEncoder.  init( this );
325  m_cSliceEncoder.init( this );
326  m_cCuEncoder.   init( this );
327 
328  // initialize transform & quantization class
329  m_pcCavlcCoder = getCavlcCoder();
330 
331  m_cTrQuant.init( 1 << m_uiQuadtreeTULog2MaxSize,
332                  m_useRDOQ, 
333                  m_useRDOQTS,
334                  true 
335                  ,m_useTransformSkipFast
336#if ADAPTIVE_QP_SELECTION                 
337                  , m_bUseAdaptQpSelect
338#endif
339                  );
340 
341  // initialize encoder search class
342  m_cSearch.init( this, &m_cTrQuant, m_iSearchRange, m_bipredSearchRange, m_iFastSearch, 0, &m_cEntropyCoder, &m_cRdCost, getRDSbacCoder(), getRDGoOnSbacCoder() );
343
344  m_iMaxRefPicNum = 0;
345#if SVC_EXTENSION
346  m_iSPSIdCnt ++;
347  m_iPPSIdCnt ++;
348#endif
349#if REF_IDX_FRAMEWORK
350  xInitILRP();
351#endif
352}
353
354// ====================================================================================================================
355// Public member functions
356// ====================================================================================================================
357
358Void TEncTop::deletePicBuffer()
359{
360  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
361  Int iSize = Int( m_cListPic.size() );
362 
363  for ( Int i = 0; i < iSize; i++ )
364  {
365    TComPic* pcPic = *(iterPic++);
366   
367    pcPic->destroy();
368    delete pcPic;
369    pcPic = NULL;
370  }
371}
372
373/**
374 - Application has picture buffer list with size of GOP + 1
375 - Picture buffer list acts like as ring buffer
376 - End of the list has the latest picture
377 .
378 \param   flush               cause encoder to encode a partial GOP
379 \param   pcPicYuvOrg         original YUV picture
380 \retval  rcListPicYuvRecOut  list of reconstruction YUV pictures
381 \retval  rcListBitstreamOut  list of output bitstreams
382 \retval  iNumEncoded         number of encoded pictures
383 */
384#if SVC_EXTENSION
385Void TEncTop::encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP )
386{
387  // compress GOP
388#if RATE_CONTROL_LAMBDA_DOMAIN
389#if !RC_SHVC_HARMONIZATION
390  if ( m_RCEnableRateControl )
391  {
392    m_cRateCtrl.initRCGOP( m_iNumPicRcvd );
393  }
394#endif
395#endif
396
397  // compress GOP
398  m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut);
399
400#if RATE_CONTROL_LAMBDA_DOMAIN
401#if !RC_SHVC_HARMONIZATION
402  if ( m_RCEnableRateControl )
403  {
404    m_cRateCtrl.destroyRCGOP();
405  }
406#endif
407#endif
408 
409  m_uiNumAllPicCoded ++;
410}
411
412Void TEncTop::encodePrep( TComPicYuv* pcPicYuvOrg )
413{
414  if (pcPicYuvOrg) 
415  {
416    // get original YUV
417    TComPic* pcPicCurr = NULL;
418    xGetNewPicBuffer( pcPicCurr );
419    pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() );
420
421    // compute image characteristics
422    if ( getUseAdaptiveQP() )
423    {
424      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) );
425    }
426  }
427}
428#else
429Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded )
430{
431  if (pcPicYuvOrg) {
432    // get original YUV
433    TComPic* pcPicCurr = NULL;
434    xGetNewPicBuffer( pcPicCurr );
435    pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() );
436
437    // compute image characteristics
438    if ( getUseAdaptiveQP() )
439    {
440      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) );
441    }
442  }
443 
444  if (!m_iNumPicRcvd || (!flush && m_iPOCLast != 0 && m_iNumPicRcvd != m_iGOPSize && m_iGOPSize))
445  {
446    iNumEncoded = 0;
447    return;
448  }
449 
450#if RATE_CONTROL_LAMBDA_DOMAIN
451  if ( m_RCEnableRateControl )
452  {
453    m_cRateCtrl.initRCGOP( m_iNumPicRcvd );
454  }
455#endif
456
457  // compress GOP
458  m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut);
459
460#if RATE_CONTROL_LAMBDA_DOMAIN
461  if ( m_RCEnableRateControl )
462  {
463    m_cRateCtrl.destroyRCGOP();
464  }
465#endif
466 
467  iNumEncoded         = m_iNumPicRcvd;
468  m_iNumPicRcvd       = 0;
469  m_uiNumAllPicCoded += iNumEncoded;
470}
471#endif
472
473// ====================================================================================================================
474// Protected member functions
475// ====================================================================================================================
476
477/**
478 - Application has picture buffer list with size of GOP + 1
479 - Picture buffer list acts like as ring buffer
480 - End of the list has the latest picture
481 .
482 \retval rpcPic obtained picture buffer
483 */
484Void TEncTop::xGetNewPicBuffer ( TComPic*& rpcPic )
485{
486  TComSlice::sortPicList(m_cListPic);
487 
488  if (m_cListPic.size() >= (UInt)(m_iGOPSize + getMaxDecPicBuffering(MAX_TLAYER-1) + 2) )
489  {
490    TComList<TComPic*>::iterator iterPic  = m_cListPic.begin();
491    Int iSize = Int( m_cListPic.size() );
492    for ( Int i = 0; i < iSize; i++ )
493    {
494      rpcPic = *(iterPic++);
495      if(rpcPic->getSlice(0)->isReferenced() == false)
496      {
497        break;
498      }
499    }
500  }
501  else
502  {
503    if ( getUseAdaptiveQP() )
504    {
505      TEncPic* pcEPic = new TEncPic;
506
507#if SVC_EXTENSION //Temporal solution, should be modified
508      if(m_layerId > 0)
509      {
510        for(UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ )
511        {
512          const Window scalEL = getSPS()->getScaledRefLayerWindow(i);
513          Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
514
515#if VPS_EXTN_DIRECT_REF_LAYERS
516          TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( i );
517#else
518          TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 );
519#endif
520          if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets )
521          {
522            pcEPic->setSpatialEnhLayerFlag( i, true );
523
524            //only for scalable extension
525            assert( m_cVPS.getScalabilityMask(1) == true );
526          }
527        }
528      }
529#endif
530
531#if SVC_UPSAMPLING
532      pcEPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 ,
533                      m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics, &m_cSPS);
534#else
535      pcEPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 ,
536                      m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics);
537#endif
538      rpcPic = pcEPic;
539    }
540    else
541    {
542      rpcPic = new TComPic;
543
544#if SVC_EXTENSION //Temporal solution, should be modified
545      if(m_layerId > 0)
546      {
547        for(UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ )
548        {
549          const Window scalEL = getSPS()->getScaledRefLayerWindow(i);
550          Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
551
552#if VPS_EXTN_DIRECT_REF_LAYERS
553          TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( i );
554#else
555          TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 );
556#endif
557          if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets )
558          {
559            rpcPic->setSpatialEnhLayerFlag( i, true );
560
561            //only for scalable extension
562            assert( m_cVPS.getScalabilityMask(1) == true );
563          }
564        }
565      }
566#endif
567
568#if SVC_UPSAMPLING
569      rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
570                      m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics, &m_cSPS);
571#else
572      rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
573                      m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics);
574#endif
575    }
576
577    if (getUseSAO())
578    {
579      rpcPic->getPicSym()->allocSaoParam(&m_cEncSAO);
580    }
581    m_cListPic.pushBack( rpcPic );
582  }
583  rpcPic->setReconMark (false);
584 
585  m_iPOCLast++;
586  m_iNumPicRcvd++;
587 
588  rpcPic->getSlice(0)->setPOC( m_iPOCLast );
589  // mark it should be extended
590  rpcPic->getPicYuvRec()->setBorderExtension(false);
591}
592
593Void TEncTop::xInitSPS()
594{
595#if SVC_EXTENSION
596  m_cSPS.setLayerId(m_layerId);
597#endif
598#if REF_IDX_MFM
599#if !M0457_COL_PICTURE_SIGNALING
600  m_cSPS.setMFMEnabledFlag(m_bMFMEnabledFlag);
601#endif
602#endif
603#if SCALED_REF_LAYER_OFFSETS
604  m_cSPS.setNumScaledRefLayerOffsets(m_numScaledRefLayerOffsets);
605  for(Int i = 0; i < m_cSPS.getNumScaledRefLayerOffsets(); i++)
606  {
607    m_cSPS.getScaledRefLayerWindow(i) = m_scaledRefLayerWindow[i];
608  }
609#endif
610  ProfileTierLevel& profileTierLevel = *m_cSPS.getPTL()->getGeneralPTL();
611  profileTierLevel.setLevelIdc(m_level);
612  profileTierLevel.setTierFlag(m_levelTier);
613  profileTierLevel.setProfileIdc(m_profile);
614  profileTierLevel.setProfileCompatibilityFlag(m_profile, 1);
615  profileTierLevel.setProgressiveSourceFlag(m_progressiveSourceFlag);
616  profileTierLevel.setInterlacedSourceFlag(m_interlacedSourceFlag);
617  profileTierLevel.setNonPackedConstraintFlag(m_nonPackedConstraintFlag);
618  profileTierLevel.setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag);
619 
620  if (m_profile == Profile::MAIN10 && g_bitDepthY == 8 && g_bitDepthC == 8)
621  {
622    /* The above constraint is equal to Profile::MAIN */
623    profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN, 1);
624  }
625  if (m_profile == Profile::MAIN)
626  {
627    /* A Profile::MAIN10 decoder can always decode Profile::MAIN */
628    profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN10, 1);
629  }
630  /* XXX: should Main be marked as compatible with still picture? */
631  /* XXX: may be a good idea to refactor the above into a function
632   * that chooses the actual compatibility based upon options */
633
634  m_cSPS.setPicWidthInLumaSamples         ( m_iSourceWidth      );
635  m_cSPS.setPicHeightInLumaSamples        ( m_iSourceHeight     );
636  m_cSPS.setConformanceWindow             ( m_conformanceWindow );
637  m_cSPS.setMaxCUWidth    ( g_uiMaxCUWidth      );
638  m_cSPS.setMaxCUHeight   ( g_uiMaxCUHeight     );
639  m_cSPS.setMaxCUDepth    ( g_uiMaxCUDepth      );
640
641  Int minCUSize = m_cSPS.getMaxCUWidth() >> ( m_cSPS.getMaxCUDepth()-g_uiAddCUDepth );
642  Int log2MinCUSize = 0;
643  while(minCUSize > 1)
644  {
645    minCUSize >>= 1;
646    log2MinCUSize++;
647  }
648
649  m_cSPS.setLog2MinCodingBlockSize(log2MinCUSize);
650  m_cSPS.setLog2DiffMaxMinCodingBlockSize(m_cSPS.getMaxCUDepth()-g_uiAddCUDepth);
651#if SVC_EXTENSION
652  m_cSPS.setSPSId         ( m_iSPSIdCnt       );
653#endif
654 
655  m_cSPS.setPCMLog2MinSize (m_uiPCMLog2MinSize);
656  m_cSPS.setUsePCM        ( m_usePCM           );
657  m_cSPS.setPCMLog2MaxSize( m_pcmLog2MaxSize  );
658
659  m_cSPS.setQuadtreeTULog2MaxSize( m_uiQuadtreeTULog2MaxSize );
660  m_cSPS.setQuadtreeTULog2MinSize( m_uiQuadtreeTULog2MinSize );
661  m_cSPS.setQuadtreeTUMaxDepthInter( m_uiQuadtreeTUMaxDepthInter    );
662  m_cSPS.setQuadtreeTUMaxDepthIntra( m_uiQuadtreeTUMaxDepthIntra    );
663 
664  m_cSPS.setTMVPFlagsPresent(false);
665  m_cSPS.setUseLossless   ( m_useLossless  );
666
667  m_cSPS.setMaxTrSize   ( 1 << m_uiQuadtreeTULog2MaxSize );
668 
669  Int i;
670 
671  for (i = 0; i < g_uiMaxCUDepth-g_uiAddCUDepth; i++ )
672  {
673    m_cSPS.setAMPAcc( i, m_useAMP );
674    //m_cSPS.setAMPAcc( i, 1 );
675  }
676
677  m_cSPS.setUseAMP ( m_useAMP );
678
679  for (i = g_uiMaxCUDepth-g_uiAddCUDepth; i < g_uiMaxCUDepth; i++ )
680  {
681    m_cSPS.setAMPAcc(i, 0);
682  }
683
684  m_cSPS.setBitDepthY( g_bitDepthY );
685  m_cSPS.setBitDepthC( g_bitDepthC );
686
687  m_cSPS.setQpBDOffsetY ( 6*(g_bitDepthY - 8) );
688  m_cSPS.setQpBDOffsetC ( 6*(g_bitDepthC - 8) );
689
690  m_cSPS.setUseSAO( m_bUseSAO );
691
692  m_cSPS.setMaxTLayers( m_maxTempLayer );
693  m_cSPS.setTemporalIdNestingFlag( ( m_maxTempLayer == 1 ) ? true : false );
694  for ( i = 0; i < m_cSPS.getMaxTLayers(); i++ )
695  {
696    m_cSPS.setMaxDecPicBuffering(m_maxDecPicBuffering[i], i);
697    m_cSPS.setNumReorderPics(m_numReorderPics[i], i);
698  }
699  m_cSPS.setPCMBitDepthLuma (g_uiPCMBitDepthLuma);
700  m_cSPS.setPCMBitDepthChroma (g_uiPCMBitDepthChroma);
701  m_cSPS.setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag );
702
703  m_cSPS.setScalingListFlag ( (m_useScalingListId == 0) ? 0 : 1 );
704
705  m_cSPS.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing );
706
707  m_cSPS.setVuiParametersPresentFlag(getVuiParametersPresentFlag());
708  if (m_cSPS.getVuiParametersPresentFlag())
709  {
710    TComVUI* pcVUI = m_cSPS.getVuiParameters();
711    pcVUI->setAspectRatioInfoPresentFlag(getAspectRatioIdc() != -1);
712    pcVUI->setAspectRatioIdc(getAspectRatioIdc());
713    pcVUI->setSarWidth(getSarWidth());
714    pcVUI->setSarHeight(getSarHeight());
715    pcVUI->setOverscanInfoPresentFlag(getOverscanInfoPresentFlag());
716    pcVUI->setOverscanAppropriateFlag(getOverscanAppropriateFlag());
717    pcVUI->setVideoSignalTypePresentFlag(getVideoSignalTypePresentFlag());
718    pcVUI->setVideoFormat(getVideoFormat());
719    pcVUI->setVideoFullRangeFlag(getVideoFullRangeFlag());
720    pcVUI->setColourDescriptionPresentFlag(getColourDescriptionPresentFlag());
721    pcVUI->setColourPrimaries(getColourPrimaries());
722    pcVUI->setTransferCharacteristics(getTransferCharacteristics());
723    pcVUI->setMatrixCoefficients(getMatrixCoefficients());
724    pcVUI->setChromaLocInfoPresentFlag(getChromaLocInfoPresentFlag());
725    pcVUI->setChromaSampleLocTypeTopField(getChromaSampleLocTypeTopField());
726    pcVUI->setChromaSampleLocTypeBottomField(getChromaSampleLocTypeBottomField());
727    pcVUI->setNeutralChromaIndicationFlag(getNeutralChromaIndicationFlag());
728    pcVUI->setDefaultDisplayWindow(getDefaultDisplayWindow());
729    pcVUI->setFrameFieldInfoPresentFlag(getFrameFieldInfoPresentFlag());
730    pcVUI->setFieldSeqFlag(false);
731    pcVUI->setHrdParametersPresentFlag(false);
732    pcVUI->getTimingInfo()->setPocProportionalToTimingFlag(getPocProportionalToTimingFlag());
733    pcVUI->getTimingInfo()->setNumTicksPocDiffOneMinus1   (getNumTicksPocDiffOneMinus1()   );
734    pcVUI->setBitstreamRestrictionFlag(getBitstreamRestrictionFlag());
735    pcVUI->setTilesFixedStructureFlag(getTilesFixedStructureFlag());
736    pcVUI->setMotionVectorsOverPicBoundariesFlag(getMotionVectorsOverPicBoundariesFlag());
737    pcVUI->setMinSpatialSegmentationIdc(getMinSpatialSegmentationIdc());
738    pcVUI->setMaxBytesPerPicDenom(getMaxBytesPerPicDenom());
739    pcVUI->setMaxBitsPerMinCuDenom(getMaxBitsPerMinCuDenom());
740    pcVUI->setLog2MaxMvLengthHorizontal(getLog2MaxMvLengthHorizontal());
741    pcVUI->setLog2MaxMvLengthVertical(getLog2MaxMvLengthVertical());
742  }
743}
744
745Void TEncTop::xInitPPS()
746{
747  m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred );
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#if RATE_CONTROL_LAMBDA_DOMAIN
788  if ( m_RCEnableRateControl )
789  {
790    m_cPPS.setUseDQP(true);
791    m_cPPS.setMaxCuDQPDepth( 0 );
792    m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) );
793  } 
794#endif
795
796  m_cPPS.setChromaCbQpOffset( m_chromaCbQpOffset );
797  m_cPPS.setChromaCrQpOffset( m_chromaCrQpOffset );
798
799  m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams);
800  m_cPPS.setEntropyCodingSyncEnabledFlag( m_iWaveFrontSynchro > 0 );
801  m_cPPS.setTilesEnabledFlag( (m_iNumColumnsMinus1 > 0 || m_iNumRowsMinus1 > 0) );
802  m_cPPS.setUseWP( m_useWeightedPred );
803  m_cPPS.setWPBiPred( m_useWeightedBiPred );
804  m_cPPS.setOutputFlagPresentFlag( false );
805  m_cPPS.setSignHideFlag(getSignHideFlag());
806  if ( getDeblockingFilterMetric() )
807  {
808    m_cPPS.setDeblockingFilterControlPresentFlag (true);
809    m_cPPS.setDeblockingFilterOverrideEnabledFlag(true);
810    m_cPPS.setPicDisableDeblockingFilterFlag(false);
811    m_cPPS.setDeblockingFilterBetaOffsetDiv2(0);
812    m_cPPS.setDeblockingFilterTcOffsetDiv2(0);
813  } 
814  else
815  {
816  m_cPPS.setDeblockingFilterControlPresentFlag (m_DeblockingFilterControlPresent );
817  }
818  m_cPPS.setLog2ParallelMergeLevelMinus2   (m_log2ParallelMergeLevelMinus2 );
819  m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG);
820  m_cPPS.setLoopFilterAcrossSlicesEnabledFlag( m_bLFCrossSliceBoundaryFlag );
821  Int histogram[MAX_NUM_REF + 1];
822  for( Int i = 0; i <= MAX_NUM_REF; i++ )
823  {
824    histogram[i]=0;
825  }
826  for( Int i = 0; i < getGOPSize(); i++ )
827  {
828    assert(getGOPEntry(i).m_numRefPicsActive >= 0 && getGOPEntry(i).m_numRefPicsActive <= MAX_NUM_REF);
829    histogram[getGOPEntry(i).m_numRefPicsActive]++;
830  }
831  Int maxHist=-1;
832  Int bestPos=0;
833  for( Int i = 0; i <= MAX_NUM_REF; i++ )
834  {
835    if(histogram[i]>maxHist)
836    {
837      maxHist=histogram[i];
838      bestPos=i;
839    }
840  }
841  assert(bestPos <= 15);
842  m_cPPS.setNumRefIdxL0DefaultActive(bestPos);
843  m_cPPS.setNumRefIdxL1DefaultActive(bestPos);
844  m_cPPS.setTransquantBypassEnableFlag(getTransquantBypassEnableFlag());
845  m_cPPS.setUseTransformSkip( m_useTransformSkip );
846  if (m_sliceSegmentMode)
847  {
848    m_cPPS.setDependentSliceSegmentsEnabledFlag( true );
849  }
850  if( m_cPPS.getDependentSliceSegmentsEnabledFlag() )
851  {
852    Int NumCtx = m_cPPS.getEntropyCodingSyncEnabledFlag()?2:1;
853    m_cSliceEncoder.initCtxMem( NumCtx );
854    for ( UInt st = 0; st < NumCtx; st++ )
855    {
856      TEncSbac* ctx = NULL;
857      ctx = new TEncSbac;
858      ctx->init( &m_cBinCoderCABAC );
859      m_cSliceEncoder.setCtxMem( ctx, st );
860    }
861  }
862#if REF_IDX_FRAMEWORK
863  if (!m_layerId)
864  {
865    m_cPPS.setListsModificationPresentFlag(false);
866  }
867  else
868  {
869    m_cPPS.setListsModificationPresentFlag(true);
870  }
871#endif
872#if SVC_EXTENSION
873  m_cPPS.setPPSId         ( m_iPPSIdCnt         );
874  m_cPPS.setSPSId         ( m_iSPSIdCnt         );
875#endif
876}
877
878//Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file.
879Void TEncTop::xInitRPS()
880{
881  TComReferencePictureSet*      rps;
882 
883  m_cSPS.createRPSList(getGOPSize()+m_extraRPSs);
884  TComRPSList* rpsList = m_cSPS.getRPSList();
885
886  for( Int i = 0; i < getGOPSize()+m_extraRPSs; i++) 
887  {
888#if FINAL_RPL_CHANGE_N0082
889    GOPEntry ge = m_ppcTEncTop[m_cSPS.getLayerId()]->getGOPEntry(i);
890#else
891    GOPEntry ge = getGOPEntry(i);
892#endif
893    rps = rpsList->getReferencePictureSet(i);
894    rps->setNumberOfPictures(ge.m_numRefPics);
895    rps->setNumRefIdc(ge.m_numRefIdc);
896    Int numNeg = 0;
897    Int numPos = 0;
898    for( Int j = 0; j < ge.m_numRefPics; j++)
899    {
900      rps->setDeltaPOC(j,ge.m_referencePics[j]);
901      rps->setUsed(j,ge.m_usedByCurrPic[j]);
902      if(ge.m_referencePics[j]>0)
903      {
904        numPos++;
905      }
906      else
907      {
908        numNeg++;
909      }
910    }
911    rps->setNumberOfNegativePictures(numNeg);
912    rps->setNumberOfPositivePictures(numPos);
913
914    // handle inter RPS intialization from the config file.
915#if AUTO_INTER_RPS
916    rps->setInterRPSPrediction(ge.m_interRPSPrediction > 0);  // not very clean, converting anything > 0 to true.
917    rps->setDeltaRIdxMinus1(0);                               // index to the Reference RPS is always the previous one.
918    TComReferencePictureSet*     RPSRef = rpsList->getReferencePictureSet(i-1);  // get the reference RPS
919
920    if (ge.m_interRPSPrediction == 2)  // Automatic generation of the inter RPS idc based on the RIdx provided.
921    {
922      Int deltaRPS = getGOPEntry(i-1).m_POC - ge.m_POC;  // the ref POC - current POC
923      Int numRefDeltaPOC = RPSRef->getNumberOfPictures();
924
925      rps->setDeltaRPS(deltaRPS);           // set delta RPS
926      rps->setNumRefIdc(numRefDeltaPOC+1);  // set the numRefIdc to the number of pictures in the reference RPS + 1.
927      Int count=0;
928      for (Int j = 0; j <= numRefDeltaPOC; j++ ) // cycle through pics in reference RPS.
929      {
930        Int RefDeltaPOC = (j<numRefDeltaPOC)? RPSRef->getDeltaPOC(j): 0;  // if it is the last decoded picture, set RefDeltaPOC = 0
931        rps->setRefIdc(j, 0);
932        for (Int k = 0; k < rps->getNumberOfPictures(); k++ )  // cycle through pics in current RPS.
933        {
934          if (rps->getDeltaPOC(k) == ( RefDeltaPOC + deltaRPS))  // if the current RPS has a same picture as the reference RPS.
935          {
936              rps->setRefIdc(j, (rps->getUsed(k)?1:2));
937              count++;
938              break;
939          }
940        }
941      }
942      if (count != rps->getNumberOfPictures())
943      {
944        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");
945        rps->setInterRPSPrediction(0);
946      }
947    }
948    else if (ge.m_interRPSPrediction == 1)  // inter RPS idc based on the RefIdc values provided in config file.
949    {
950      rps->setDeltaRPS(ge.m_deltaRPS);
951      rps->setNumRefIdc(ge.m_numRefIdc);
952      for (Int j = 0; j < ge.m_numRefIdc; j++ )
953      {
954        rps->setRefIdc(j, ge.m_refIdc[j]);
955      }
956#if WRITE_BACK
957      // the folowing code overwrite the deltaPOC and Used by current values read from the config file with the ones
958      // computed from the RefIdc.  A warning is printed if they are not identical.
959      numNeg = 0;
960      numPos = 0;
961      TComReferencePictureSet      RPSTemp;  // temporary variable
962
963      for (Int j = 0; j < ge.m_numRefIdc; j++ )
964      {
965        if (ge.m_refIdc[j])
966        {
967          Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0);
968          RPSTemp.setDeltaPOC((numNeg+numPos),deltaPOC);
969          RPSTemp.setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0);
970          if (deltaPOC<0)
971          {
972            numNeg++;
973          }
974          else
975          {
976            numPos++;
977          }
978        }
979      }
980      if (numNeg != rps->getNumberOfNegativePictures())
981      {
982        printf("Warning: number of negative pictures in RPS is different between intra and inter RPS specified in the config file.\n");
983        rps->setNumberOfNegativePictures(numNeg);
984        rps->setNumberOfPositivePictures(numNeg+numPos);
985      }
986      if (numPos != rps->getNumberOfPositivePictures())
987      {
988        printf("Warning: number of positive pictures in RPS is different between intra and inter RPS specified in the config file.\n");
989        rps->setNumberOfPositivePictures(numPos);
990        rps->setNumberOfPositivePictures(numNeg+numPos);
991      }
992      RPSTemp.setNumberOfPictures(numNeg+numPos);
993      RPSTemp.setNumberOfNegativePictures(numNeg);
994      RPSTemp.sortDeltaPOC();     // sort the created delta POC before comparing
995      // check if Delta POC and Used are the same
996      // print warning if they are not.
997      for (Int j = 0; j < ge.m_numRefIdc; j++ )
998      {
999        if (RPSTemp.getDeltaPOC(j) != rps->getDeltaPOC(j))
1000        {
1001          printf("Warning: delta POC is different between intra RPS and inter RPS specified in the config file.\n");
1002          rps->setDeltaPOC(j,RPSTemp.getDeltaPOC(j));
1003        }
1004        if (RPSTemp.getUsed(j) != rps->getUsed(j))
1005        {
1006          printf("Warning: Used by Current in RPS is different between intra and inter RPS specified in the config file.\n");
1007          rps->setUsed(j,RPSTemp.getUsed(j));
1008        }
1009      }
1010#endif
1011    }
1012#else
1013    rps->setInterRPSPrediction(ge.m_interRPSPrediction);
1014    if (ge.m_interRPSPrediction)
1015    {
1016      rps->setDeltaRIdxMinus1(0);
1017      rps->setDeltaRPS(ge.m_deltaRPS);
1018      rps->setNumRefIdc(ge.m_numRefIdc);
1019      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1020      {
1021        rps->setRefIdc(j, ge.m_refIdc[j]);
1022      }
1023#if WRITE_BACK
1024      // the folowing code overwrite the deltaPOC and Used by current values read from the config file with the ones
1025      // computed from the RefIdc.  This is not necessary if both are identical. Currently there is no check to see if they are identical.
1026      numNeg = 0;
1027      numPos = 0;
1028      TComReferencePictureSet*     RPSRef = m_RPSList.getReferencePictureSet(i-1);
1029
1030      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1031      {
1032        if (ge.m_refIdc[j])
1033        {
1034          Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0);
1035          rps->setDeltaPOC((numNeg+numPos),deltaPOC);
1036          rps->setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0);
1037          if (deltaPOC<0)
1038          {
1039            numNeg++;
1040          }
1041          else
1042          {
1043            numPos++;
1044          }
1045        }
1046      }
1047      rps->setNumberOfNegativePictures(numNeg);
1048      rps->setNumberOfPositivePictures(numPos);
1049      rps->sortDeltaPOC();
1050#endif
1051    }
1052#endif //INTER_RPS_AUTO
1053  }
1054 
1055}
1056
1057   // This is a function that
1058   // determines what Reference Picture Set to use
1059   // for a specific slice (with POC = POCCurr)
1060Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid )
1061{
1062  slice->setRPSidx(GOPid);
1063
1064  for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++)
1065  {   
1066    if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0)
1067    {
1068      Int POCIndex = POCCurr%m_uiIntraPeriod;
1069      if(POCIndex == 0)
1070      {
1071        POCIndex = m_uiIntraPeriod;
1072      }
1073      if(POCIndex == m_GOPList[extraNum].m_POC)
1074      {
1075        slice->setRPSidx(extraNum);
1076      }
1077    }
1078    else
1079    {
1080      if(POCCurr==m_GOPList[extraNum].m_POC)
1081      {
1082        slice->setRPSidx(extraNum);
1083      }
1084    }
1085  }
1086
1087  slice->setRPS(getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx()));
1088  slice->getRPS()->setNumberOfPictures(slice->getRPS()->getNumberOfNegativePictures()+slice->getRPS()->getNumberOfPositivePictures());
1089
1090}
1091
1092Int TEncTop::getReferencePictureSetIdxForSOP(TComSlice* slice, Int POCCurr, Int GOPid )
1093{
1094  int rpsIdx = GOPid;
1095
1096  for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++)
1097  {   
1098    if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0)
1099    {
1100      Int POCIndex = POCCurr%m_uiIntraPeriod;
1101      if(POCIndex == 0)
1102      {
1103        POCIndex = m_uiIntraPeriod;
1104      }
1105      if(POCIndex == m_GOPList[extraNum].m_POC)
1106      {
1107        rpsIdx = extraNum;
1108      }
1109    }
1110    else
1111    {
1112      if(POCCurr==m_GOPList[extraNum].m_POC)
1113      {
1114        rpsIdx = extraNum;
1115      }
1116    }
1117  }
1118
1119  return rpsIdx;
1120}
1121
1122Void  TEncTop::xInitPPSforTiles()
1123{
1124  m_cPPS.setUniformSpacingFlag( m_iUniformSpacingIdr );
1125  m_cPPS.setNumColumnsMinus1( m_iNumColumnsMinus1 );
1126  m_cPPS.setNumRowsMinus1( m_iNumRowsMinus1 );
1127  if( m_iUniformSpacingIdr == 0 )
1128  {
1129    m_cPPS.setColumnWidth( m_puiColumnWidth );
1130    m_cPPS.setRowHeight( m_puiRowHeight );
1131  }
1132  m_cPPS.setLoopFilterAcrossTilesEnabledFlag( m_loopFilterAcrossTilesEnabledFlag );
1133
1134  // # substreams is "per tile" when tiles are independent.
1135  if (m_iWaveFrontSynchro
1136    )
1137  {
1138    m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams * (m_iNumColumnsMinus1+1));
1139  }
1140}
1141
1142Void  TEncCfg::xCheckGSParameters()
1143{
1144  Int   iWidthInCU = ( m_iSourceWidth%g_uiMaxCUWidth ) ? m_iSourceWidth/g_uiMaxCUWidth + 1 : m_iSourceWidth/g_uiMaxCUWidth;
1145  Int   iHeightInCU = ( m_iSourceHeight%g_uiMaxCUHeight ) ? m_iSourceHeight/g_uiMaxCUHeight + 1 : m_iSourceHeight/g_uiMaxCUHeight;
1146  UInt  uiCummulativeColumnWidth = 0;
1147  UInt  uiCummulativeRowHeight = 0;
1148
1149  //check the column relative parameters
1150  if( m_iNumColumnsMinus1 >= (1<<(LOG2_MAX_NUM_COLUMNS_MINUS1+1)) )
1151  {
1152    printf( "The number of columns is larger than the maximum allowed number of columns.\n" );
1153    exit( EXIT_FAILURE );
1154  }
1155
1156  if( m_iNumColumnsMinus1 >= iWidthInCU )
1157  {
1158    printf( "The current picture can not have so many columns.\n" );
1159    exit( EXIT_FAILURE );
1160  }
1161
1162  if( m_iNumColumnsMinus1 && m_iUniformSpacingIdr==0 )
1163  {
1164    for(Int i=0; i<m_iNumColumnsMinus1; i++)
1165    {
1166      uiCummulativeColumnWidth += m_puiColumnWidth[i];
1167    }
1168
1169    if( uiCummulativeColumnWidth >= iWidthInCU )
1170    {
1171      printf( "The width of the column is too large.\n" );
1172      exit( EXIT_FAILURE );
1173    }
1174  }
1175
1176  //check the row relative parameters
1177  if( m_iNumRowsMinus1 >= (1<<(LOG2_MAX_NUM_ROWS_MINUS1+1)) )
1178  {
1179    printf( "The number of rows is larger than the maximum allowed number of rows.\n" );
1180    exit( EXIT_FAILURE );
1181  }
1182
1183  if( m_iNumRowsMinus1 >= iHeightInCU )
1184  {
1185    printf( "The current picture can not have so many rows.\n" );
1186    exit( EXIT_FAILURE );
1187  }
1188
1189  if( m_iNumRowsMinus1 && m_iUniformSpacingIdr==0 )
1190  {
1191    for(Int i=0; i<m_iNumRowsMinus1; i++)
1192    {
1193      uiCummulativeRowHeight += m_puiRowHeight[i];
1194    }
1195
1196    if( uiCummulativeRowHeight >= iHeightInCU )
1197    {
1198      printf( "The height of the row is too large.\n" );
1199      exit( EXIT_FAILURE );
1200    }
1201  }
1202}
1203
1204#if SVC_EXTENSION
1205#if VPS_EXTN_DIRECT_REF_LAYERS
1206TEncTop* TEncTop::getRefLayerEnc( UInt refLayerIdc )
1207{
1208  if( m_ppcTEncTop[m_layerId]->getNumDirectRefLayers() <= 0 )
1209  {
1210    return (TEncTop *)getLayerEnc( 0 );
1211  }
1212
1213  return (TEncTop *)getLayerEnc( m_cVPS.getRefLayerId( m_layerId, refLayerIdc ) );
1214}
1215#endif
1216
1217#if REF_IDX_FRAMEWORK
1218Void TEncTop::xInitILRP()
1219{
1220  if(m_layerId>0)
1221  {
1222    g_bitDepthY     = m_cSPS.getBitDepthY();
1223    g_bitDepthC     = m_cSPS.getBitDepthC();
1224    g_uiMaxCUWidth  = m_cSPS.getMaxCUWidth();
1225    g_uiMaxCUHeight = m_cSPS.getMaxCUHeight();
1226    g_uiMaxCUDepth  = m_cSPS.getMaxCUDepth();
1227    g_uiAddCUDepth  = max (0, m_cSPS.getLog2MinCodingBlockSize() - (Int)m_cSPS.getQuadtreeTULog2MinSize() );
1228
1229    Int  numReorderPics[MAX_TLAYER];
1230    Window &conformanceWindow = m_cSPS.getConformanceWindow();
1231    Window defaultDisplayWindow = m_cSPS.getVuiParametersPresentFlag() ? m_cSPS.getVuiParameters()->getDefaultDisplayWindow() : Window();
1232
1233    if (m_cIlpPic[0] == NULL)
1234    {
1235      for (Int j=0; j < MAX_LAYERS /*MAX_NUM_REF*/; j++) // consider to set to NumDirectRefLayers[LayerIdInVps[nuh_layer_id]]
1236      {
1237        m_cIlpPic[j] = new  TComPic;
1238#if SVC_UPSAMPLING
1239        m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, &m_cSPS, true);
1240#else
1241        m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
1242#endif
1243        for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++)
1244        {
1245          m_cIlpPic[j]->getPicSym()->getCU(i)->initCU(m_cIlpPic[j], i);
1246        }
1247      }
1248    }
1249  }
1250}
1251
1252Void TEncTop::setILRPic(TComPic *pcPic)
1253{
1254  for( Int i = 0; i < pcPic->getSlice(0)->getActiveNumILRRefIdx(); i++ )
1255  {
1256    Int refLayerIdc = pcPic->getSlice(0)->getInterLayerPredLayerIdc(i);
1257
1258    if(m_cIlpPic[refLayerIdc])
1259    {
1260      m_cIlpPic[refLayerIdc]->copyUpsampledPictureYuv(pcPic->getFullPelBaseRec(refLayerIdc), m_cIlpPic[refLayerIdc]->getPicYuvRec());
1261      m_cIlpPic[refLayerIdc]->getSlice(0)->setPOC(pcPic->getPOC());
1262      m_cIlpPic[refLayerIdc]->setLayerId(pcPic->getSlice(0)->getBaseColPic(refLayerIdc)->getLayerId()); //set reference layerId
1263      m_cIlpPic[refLayerIdc]->getPicYuvRec()->setBorderExtension(false);
1264      m_cIlpPic[refLayerIdc]->getPicYuvRec()->extendPicBorder();
1265    }
1266  }
1267}
1268#endif
1269#endif
1270//! \}
Note: See TracBrowser for help on using the repository browser.